From 26476d27a34513b123301ba382e07372d1bc6a18 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Thu, 8 Aug 2024 12:43:50 -0700 Subject: [PATCH] chore: move metadata field to tooldef struct --- pkg/types/tool.go | 21 ++++++++++++++++++--- pkg/types/tool_test.go | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/pkg/types/tool.go b/pkg/types/tool.go index 61a67fa4..bb49e6f1 100644 --- a/pkg/types/tool.go +++ b/pkg/types/tool.go @@ -157,8 +157,9 @@ func (p Parameters) ToolRefNames() []string { type ToolDef struct { Parameters `json:",inline"` - Instructions string `json:"instructions,omitempty"` - BuiltinFunc BuiltinFunc `json:"-"` + Instructions string `json:"instructions,omitempty"` + BuiltinFunc BuiltinFunc `json:"-"` + MetaData map[string]string `json:"metaData,omitempty"` } type Tool struct { @@ -166,7 +167,6 @@ type Tool struct { ID string `json:"id,omitempty"` ToolMapping map[string][]ToolReference `json:"toolMapping,omitempty"` - MetaData map[string]string `json:"metaData,omitempty"` LocalTools map[string]string `json:"localTools,omitempty"` Source ToolSource `json:"source,omitempty"` WorkingDir string `json:"workingDir,omitempty"` @@ -489,6 +489,21 @@ func (t ToolDef) String() string { _, _ = fmt.Fprintln(buf, t.Instructions) } + if t.Name != "" { + keys := maps.Keys(t.MetaData) + sort.Strings(keys) + for _, key := range keys { + buf.WriteString("---\n") + buf.WriteString("!metadata:") + buf.WriteString(t.Name) + buf.WriteString(":") + buf.WriteString(key) + buf.WriteString("\n") + buf.WriteString(t.MetaData[key]) + buf.WriteString("\n") + } + } + return buf.String() } diff --git a/pkg/types/tool_test.go b/pkg/types/tool_test.go index a47014a1..e95c2248 100644 --- a/pkg/types/tool_test.go +++ b/pkg/types/tool_test.go @@ -36,6 +36,13 @@ func TestToolDef_String(t *testing.T) { ExportCredentials: []string{"ExportCredential1", "ExportCredential2"}, Type: ToolTypeContext, }, + MetaData: map[string]string{ + "package.json": `{ +// blah blah some ugly JSON +} +`, + "requirements.txt": `requests=5`, + }, Instructions: "This is a sample instruction", } @@ -68,6 +75,15 @@ Share Credential: ExportCredential2 Chat: true This is a sample instruction +--- +!metadata:Tool Sample:package.json +{ +// blah blah some ugly JSON +} + +--- +!metadata:Tool Sample:requirements.txt +requests=5 `).Equal(t, tool.String()) }