@@ -26,19 +26,25 @@ Available tools/functions:
2626
2727`
2828
29- type RunToolsWithJavascriptArgs struct {
30- Script string `json:"script"`
29+ func Wrap (toolsets []tools.ToolSet ) tools.ToolSet {
30+ return & codeModeTool {
31+ toolsets : toolsets ,
32+ }
3133}
3234
33- type tool struct {
35+ type codeModeTool struct {
3436 toolsets []tools.ToolSet
3537}
3638
37- func (c * tool ) Instructions () string {
39+ type RunToolsWithJavascriptArgs struct {
40+ Script string `json:"script" jsonschema:"Script to execute"`
41+ }
42+
43+ func (c * codeModeTool ) Instructions () string {
3844 return ""
3945}
4046
41- func (c * tool ) Tools (ctx context.Context ) ([]tools.Tool , error ) {
47+ func (c * codeModeTool ) Tools (ctx context.Context ) ([]tools.Tool , error ) {
4248 var functionsDoc []string
4349
4450 for _ , toolset := range c .toolsets {
@@ -55,19 +61,7 @@ func (c *tool) Tools(ctx context.Context) ([]tools.Tool, error) {
5561 return []tools.Tool {{
5662 Name : "run_tools_with_javascript" ,
5763 Description : prompt + strings .Join (functionsDoc , "\n " ),
58- Annotations : tools.ToolAnnotations {
59- Title : "Run tools with Javascript" ,
60- },
61- Parameters : tools.FunctionParameters {
62- Type : "object" ,
63- Required : []string {"script" },
64- Properties : map [string ]any {
65- "script" : map [string ]any {
66- "type" : "string" ,
67- "description" : "script to execute" ,
68- },
69- },
70- },
64+ Parameters : tools .MustSchemaFor [RunToolsWithJavascriptArgs ](),
7165 Handler : func (ctx context.Context , toolCall tools.ToolCall ) (* tools.ToolCallResult , error ) {
7266 var args RunToolsWithJavascriptArgs
7367 if err := json .Unmarshal ([]byte (toolCall .Function .Arguments ), & args ); err != nil {
@@ -83,10 +77,13 @@ func (c *tool) Tools(ctx context.Context) ([]tools.Tool, error) {
8377 Output : output ,
8478 }, nil
8579 },
80+ Annotations : tools.ToolAnnotations {
81+ Title : "Run tools with Javascript" ,
82+ },
8683 }}, nil
8784}
8885
89- func (c * tool ) Start (ctx context.Context ) error {
86+ func (c * codeModeTool ) Start (ctx context.Context ) error {
9087 for _ , t := range c .toolsets {
9188 if err := t .Start (ctx ); err != nil {
9289 return err
@@ -96,7 +93,7 @@ func (c *tool) Start(ctx context.Context) error {
9693 return nil
9794}
9895
99- func (c * tool ) Stop () error {
96+ func (c * codeModeTool ) Stop () error {
10097 var errs []error
10198
10299 for _ , t := range c .toolsets {
@@ -108,16 +105,10 @@ func (c *tool) Stop() error {
108105 return errors .Join (errs ... )
109106}
110107
111- func (c * tool ) SetElicitationHandler (handler tools.ElicitationHandler ) {
108+ func (c * codeModeTool ) SetElicitationHandler (handler tools.ElicitationHandler ) {
112109 // No-op, this tool does not use elicitation
113110}
114111
115- func (c * tool ) SetOAuthSuccessHandler (handler func ()) {
112+ func (c * codeModeTool ) SetOAuthSuccessHandler (handler func ()) {
116113 // No-op, this tool does not use OAuth
117114}
118-
119- func Wrap (toolsets []tools.ToolSet ) tools.ToolSet {
120- return & tool {
121- toolsets : toolsets ,
122- }
123- }
0 commit comments