Skip to content

Commit 5c57a4b

Browse files
committed
update tool defs, use widget_id
1 parent a8940cb commit 5c57a4b

3 files changed

Lines changed: 62 additions & 62 deletions

File tree

pkg/aiusechat/tools.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,57 @@ func generateToolsForBlock(block *waveobj.Block) []uctypes.ToolDefinition {
182182

183183
return tools
184184
}
185+
186+
func GetAdderToolDefinition() uctypes.ToolDefinition {
187+
return uctypes.ToolDefinition{
188+
Name: "adder",
189+
DisplayName: "Adder",
190+
Description: "Add an array of numbers together and return their sum",
191+
Strict: true,
192+
InputSchema: map[string]any{
193+
"type": "object",
194+
"properties": map[string]any{
195+
"values": map[string]any{
196+
"type": "array",
197+
"items": map[string]any{
198+
"type": "integer",
199+
},
200+
"description": "Array of numbers to add together",
201+
},
202+
},
203+
"required": []string{"values"},
204+
"additionalProperties": false,
205+
},
206+
ToolAnyCallback: func(input any) (any, error) {
207+
inputMap, ok := input.(map[string]any)
208+
if !ok {
209+
return nil, fmt.Errorf("invalid input format")
210+
}
211+
212+
valuesInterface, ok := inputMap["values"]
213+
if !ok {
214+
return nil, fmt.Errorf("missing values parameter")
215+
}
216+
217+
valuesSlice, ok := valuesInterface.([]any)
218+
if !ok {
219+
return nil, fmt.Errorf("values must be an array")
220+
}
221+
222+
if len(valuesSlice) == 0 {
223+
return 0, nil
224+
}
225+
226+
sum := 0
227+
for i, val := range valuesSlice {
228+
floatVal, ok := val.(float64)
229+
if !ok {
230+
return nil, fmt.Errorf("value at index %d is not a number", i)
231+
}
232+
sum += int(floatVal)
233+
}
234+
235+
return sum, nil
236+
},
237+
}
238+
}

pkg/aiusechat/tools_screenshot.go

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
func resolveBlockIdFromPrefix(tab *waveobj.Tab, blockIdPrefix string) (string, error) {
2121
if len(blockIdPrefix) != 8 {
22-
return "", fmt.Errorf("block ID prefix must be 8 characters")
22+
return "", fmt.Errorf("widget_id must be 8 characters")
2323
}
2424

2525
for _, blockId := range tab.BlockIds {
@@ -28,7 +28,7 @@ func resolveBlockIdFromPrefix(tab *waveobj.Tab, blockIdPrefix string) (string, e
2828
}
2929
}
3030

31-
return "", fmt.Errorf("block not found with prefix %s", blockIdPrefix)
31+
return "", fmt.Errorf("widget_id not found: %q", blockIdPrefix)
3232
}
3333

3434
func makeTabCaptureBlockScreenshot(tabId string) func(any) (string, error) {
@@ -38,9 +38,9 @@ func makeTabCaptureBlockScreenshot(tabId string) func(any) (string, error) {
3838
return "", fmt.Errorf("invalid input format")
3939
}
4040

41-
blockIdPrefix, ok := inputMap["blockid"].(string)
41+
blockIdPrefix, ok := inputMap["widget_id"].(string)
4242
if !ok {
43-
return "", fmt.Errorf("missing or invalid blockid parameter")
43+
return "", fmt.Errorf("missing or invalid widget_id parameter")
4444
}
4545

4646
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
@@ -79,68 +79,14 @@ func GetCaptureScreenshotToolDefinition(tabId string) uctypes.ToolDefinition {
7979
InputSchema: map[string]any{
8080
"type": "object",
8181
"properties": map[string]any{
82-
"blockid": map[string]any{
82+
"widget_id": map[string]any{
8383
"type": "string",
84-
"description": "8-character block ID of the widget to screenshot",
84+
"description": "8-character widget ID of the widget to screenshot",
8585
},
8686
},
87-
"required": []string{"blockid"},
87+
"required": []string{"widget_id"},
8888
"additionalProperties": false,
8989
},
9090
ToolTextCallback: makeTabCaptureBlockScreenshot(tabId),
9191
}
9292
}
93-
94-
func GetAdderToolDefinition() uctypes.ToolDefinition {
95-
return uctypes.ToolDefinition{
96-
Name: "adder",
97-
DisplayName: "Adder",
98-
Description: "Add an array of numbers together and return their sum",
99-
Strict: true,
100-
InputSchema: map[string]any{
101-
"type": "object",
102-
"properties": map[string]any{
103-
"values": map[string]any{
104-
"type": "array",
105-
"items": map[string]any{
106-
"type": "integer",
107-
},
108-
"description": "Array of numbers to add together",
109-
},
110-
},
111-
"required": []string{"values"},
112-
"additionalProperties": false,
113-
},
114-
ToolAnyCallback: func(input any) (any, error) {
115-
inputMap, ok := input.(map[string]any)
116-
if !ok {
117-
return nil, fmt.Errorf("invalid input format")
118-
}
119-
120-
valuesInterface, ok := inputMap["values"]
121-
if !ok {
122-
return nil, fmt.Errorf("missing values parameter")
123-
}
124-
125-
valuesSlice, ok := valuesInterface.([]any)
126-
if !ok {
127-
return nil, fmt.Errorf("values must be an array")
128-
}
129-
130-
if len(valuesSlice) == 0 {
131-
return 0, nil
132-
}
133-
134-
sum := 0
135-
for i, val := range valuesSlice {
136-
floatVal, ok := val.(float64)
137-
if !ok {
138-
return nil, fmt.Errorf("value at index %d is not a number", i)
139-
}
140-
sum += int(floatVal)
141-
}
142-
143-
return sum, nil
144-
},
145-
}
146-
}

pkg/aiusechat/tools_tsunami.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,4 @@ func GetTsunamiSetConfigToolDefinition(block *waveobj.Block, rtInfo *waveobj.Obj
184184
},
185185
ToolAnyCallback: makeTsunamiPostCallback(status, "/api/config"),
186186
}
187-
}
187+
}

0 commit comments

Comments
 (0)