Skip to content

Commit 9e770b9

Browse files
Merge pull request #749 from ibuildthecloud/move-metadata
chore: move metadata field to tooldef struct
2 parents 4c16a4c + 26476d2 commit 9e770b9

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

pkg/types/tool.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,16 @@ func (p Parameters) ToolRefNames() []string {
157157

158158
type ToolDef struct {
159159
Parameters `json:",inline"`
160-
Instructions string `json:"instructions,omitempty"`
161-
BuiltinFunc BuiltinFunc `json:"-"`
160+
Instructions string `json:"instructions,omitempty"`
161+
BuiltinFunc BuiltinFunc `json:"-"`
162+
MetaData map[string]string `json:"metaData,omitempty"`
162163
}
163164

164165
type Tool struct {
165166
ToolDef `json:",inline"`
166167

167168
ID string `json:"id,omitempty"`
168169
ToolMapping map[string][]ToolReference `json:"toolMapping,omitempty"`
169-
MetaData map[string]string `json:"metaData,omitempty"`
170170
LocalTools map[string]string `json:"localTools,omitempty"`
171171
Source ToolSource `json:"source,omitempty"`
172172
WorkingDir string `json:"workingDir,omitempty"`
@@ -489,6 +489,21 @@ func (t ToolDef) String() string {
489489
_, _ = fmt.Fprintln(buf, t.Instructions)
490490
}
491491

492+
if t.Name != "" {
493+
keys := maps.Keys(t.MetaData)
494+
sort.Strings(keys)
495+
for _, key := range keys {
496+
buf.WriteString("---\n")
497+
buf.WriteString("!metadata:")
498+
buf.WriteString(t.Name)
499+
buf.WriteString(":")
500+
buf.WriteString(key)
501+
buf.WriteString("\n")
502+
buf.WriteString(t.MetaData[key])
503+
buf.WriteString("\n")
504+
}
505+
}
506+
492507
return buf.String()
493508
}
494509

pkg/types/tool_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ func TestToolDef_String(t *testing.T) {
3636
ExportCredentials: []string{"ExportCredential1", "ExportCredential2"},
3737
Type: ToolTypeContext,
3838
},
39+
MetaData: map[string]string{
40+
"package.json": `{
41+
// blah blah some ugly JSON
42+
}
43+
`,
44+
"requirements.txt": `requests=5`,
45+
},
3946
Instructions: "This is a sample instruction",
4047
}
4148

@@ -68,6 +75,15 @@ Share Credential: ExportCredential2
6875
Chat: true
6976
7077
This is a sample instruction
78+
---
79+
!metadata:Tool Sample:package.json
80+
{
81+
// blah blah some ugly JSON
82+
}
83+
84+
---
85+
!metadata:Tool Sample:requirements.txt
86+
requests=5
7187
`).Equal(t, tool.String())
7288
}
7389

0 commit comments

Comments
 (0)