-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathCliExecutionRequest.cs
More file actions
85 lines (66 loc) · 2.54 KB
/
Copy pathCliExecutionRequest.cs
File metadata and controls
85 lines (66 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System.Text;
using WebCodeCli.Domain.Domain.Model;
namespace WebCodeCli.Domain.Domain.Service.Adapters;
public class CliExecutionRequest
{
public string SessionId { get; set; } = string.Empty;
public string ToolId { get; set; } = string.Empty;
public string PromptText { get; set; } = string.Empty;
public CliSessionContext SessionContext { get; set; } = new();
public List<CliExecutionAttachment> NativeAttachments { get; set; } = new();
public List<CliExecutionAttachment> ReferenceAttachments { get; set; } = new();
public List<MessageSubmissionWarning> Warnings { get; set; } = new();
public CliExecutionRequest WithSessionContext(CliSessionContext sessionContext)
{
return new CliExecutionRequest
{
SessionId = SessionId,
ToolId = ToolId,
PromptText = PromptText,
SessionContext = sessionContext,
NativeAttachments = [.. NativeAttachments],
ReferenceAttachments = [.. ReferenceAttachments],
Warnings = [.. Warnings]
};
}
public string BuildPromptText()
{
if (ReferenceAttachments.Count == 0)
{
return PromptText;
}
var builder = new StringBuilder();
builder.AppendLine("[WEBCODE_REFERENCE_ATTACHMENTS]");
foreach (var attachment in ReferenceAttachments)
{
builder.Append("- displayName: ").AppendLine(GetDisplayName(attachment));
builder.Append(" kind: ").AppendLine(attachment.Kind.ToString());
builder.Append(" path: ").AppendLine(GetReferencePath(attachment));
}
builder.Append("[/WEBCODE_REFERENCE_ATTACHMENTS]");
if (!string.IsNullOrWhiteSpace(PromptText))
{
builder.AppendLine();
builder.AppendLine();
builder.Append(PromptText);
}
return builder.ToString();
}
private static string GetDisplayName(CliExecutionAttachment attachment)
{
if (!string.IsNullOrWhiteSpace(attachment.DisplayName))
{
return attachment.DisplayName;
}
var referencePath = GetReferencePath(attachment);
return string.IsNullOrWhiteSpace(referencePath) ? "(unnamed attachment)" : referencePath;
}
private static string GetReferencePath(CliExecutionAttachment attachment)
{
if (!string.IsNullOrWhiteSpace(attachment.WorkspaceRelativePath))
{
return attachment.WorkspaceRelativePath;
}
return attachment.AbsolutePath;
}
}