Skip to content

Commit a7c8e57

Browse files
authored
Merge pull request #807 from thedadams/add-prompt-metadata
feat: add ability to include metadata with prompts
2 parents a387cd8 + 5b7d8b7 commit a7c8e57

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

pkg/builtin/builtin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ var tools = map[string]types.Tool{
217217
"message", "The message to display to the user",
218218
"fields", "A comma-separated list of fields to prompt for",
219219
"sensitive", "(true or false) Whether the input should be hidden",
220+
"metadata", "(optional) A JSON object of metadata to attach to the prompt",
220221
),
221222
},
222223
BuiltinFunc: prompt.SysPrompt,

pkg/prompt/prompt.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,29 @@ func sysPromptHTTP(ctx context.Context, envs []string, url string, prompt types.
5151

5252
func SysPrompt(ctx context.Context, envs []string, input string, _ chan<- string) (_ string, err error) {
5353
var params struct {
54-
Message string `json:"message,omitempty"`
55-
Fields string `json:"fields,omitempty"`
56-
Sensitive string `json:"sensitive,omitempty"`
54+
Message string `json:"message,omitempty"`
55+
Fields string `json:"fields,omitempty"`
56+
Sensitive string `json:"sensitive,omitempty"`
57+
Metadata map[string]string `json:"metadata,omitempty"`
5758
}
5859
if err := json.Unmarshal([]byte(input), &params); err != nil {
5960
return "", err
6061
}
6162

63+
var fields []string
6264
for _, env := range envs {
6365
if url, ok := strings.CutPrefix(env, types.PromptURLEnvVar+"="); ok {
64-
var fields []string
6566
if params.Fields != "" {
6667
fields = strings.Split(params.Fields, ",")
6768
}
69+
6870
httpPrompt := types.Prompt{
6971
Message: params.Message,
7072
Fields: fields,
7173
Sensitive: params.Sensitive == "true",
74+
Metadata: params.Metadata,
7275
}
76+
7377
return sysPromptHTTP(ctx, envs, url, httpPrompt)
7478
}
7579
}

pkg/sdkserver/prompt.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ func (s *server) prompt(w http.ResponseWriter, r *http.Request) {
7676
}(id)
7777

7878
s.events.C <- event{
79-
Prompt: types.Prompt{
80-
Message: prompt.Message,
81-
Fields: prompt.Fields,
82-
Sensitive: prompt.Sensitive,
83-
},
79+
Prompt: prompt,
8480
Event: gserver.Event{
8581
RunID: id,
8682
Event: runner.Event{

pkg/types/prompt.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const (
66
)
77

88
type Prompt struct {
9-
Message string `json:"message,omitempty"`
10-
Fields []string `json:"fields,omitempty"`
11-
Sensitive bool `json:"sensitive,omitempty"`
9+
Message string `json:"message,omitempty"`
10+
Fields []string `json:"fields,omitempty"`
11+
Sensitive bool `json:"sensitive,omitempty"`
12+
Metadata map[string]string `json:"metadata,omitempty"`
1213
}

0 commit comments

Comments
 (0)