Skip to content

Commit

Permalink
Merge pull request #807 from thedadams/add-prompt-metadata
Browse files Browse the repository at this point in the history
feat: add ability to include metadata with prompts
  • Loading branch information
thedadams authored Aug 20, 2024
2 parents a387cd8 + 5b7d8b7 commit a7c8e57
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions pkg/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ var tools = map[string]types.Tool{
"message", "The message to display to the user",
"fields", "A comma-separated list of fields to prompt for",
"sensitive", "(true or false) Whether the input should be hidden",
"metadata", "(optional) A JSON object of metadata to attach to the prompt",
),
},
BuiltinFunc: prompt.SysPrompt,
Expand Down
12 changes: 8 additions & 4 deletions pkg/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,29 @@ func sysPromptHTTP(ctx context.Context, envs []string, url string, prompt types.

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

var fields []string
for _, env := range envs {
if url, ok := strings.CutPrefix(env, types.PromptURLEnvVar+"="); ok {
var fields []string
if params.Fields != "" {
fields = strings.Split(params.Fields, ",")
}

httpPrompt := types.Prompt{
Message: params.Message,
Fields: fields,
Sensitive: params.Sensitive == "true",
Metadata: params.Metadata,
}

return sysPromptHTTP(ctx, envs, url, httpPrompt)
}
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/sdkserver/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ func (s *server) prompt(w http.ResponseWriter, r *http.Request) {
}(id)

s.events.C <- event{
Prompt: types.Prompt{
Message: prompt.Message,
Fields: prompt.Fields,
Sensitive: prompt.Sensitive,
},
Prompt: prompt,
Event: gserver.Event{
RunID: id,
Event: runner.Event{
Expand Down
7 changes: 4 additions & 3 deletions pkg/types/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const (
)

type Prompt struct {
Message string `json:"message,omitempty"`
Fields []string `json:"fields,omitempty"`
Sensitive bool `json:"sensitive,omitempty"`
Message string `json:"message,omitempty"`
Fields []string `json:"fields,omitempty"`
Sensitive bool `json:"sensitive,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}

0 comments on commit a7c8e57

Please sign in to comment.