Skip to content

Commit 8a7a225

Browse files
committed
first tsunami data call working!
1 parent e02470e commit 8a7a225

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

pkg/aiusechat/anthropic/anthropic-convertmessage.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ func buildAnthropicHTTPRequest(ctx context.Context, msgs []anthropicInputMessage
115115
for _, tool := range chatOpts.Tools {
116116
toolNames = append(toolNames, tool.Name)
117117
}
118+
for _, tool := range chatOpts.TabTools {
119+
toolNames = append(toolNames, tool.Name)
120+
}
118121
log.Printf("tools: %s\n", strings.Join(toolNames, ", "))
119122
log.Printf("anthropicMsgs JSON:\n%s", jsonStr)
120123
}

pkg/aiusechat/tools.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ package aiusechat
55

66
import (
77
"context"
8+
"encoding/json"
89
"fmt"
10+
"net/http"
911
"strings"
1012
"time"
1113

@@ -177,6 +179,19 @@ func generateToolsForBlock(block *waveobj.Block) []uctypes.ToolDefinition {
177179
switch viewType {
178180
case "web":
179181
tools = append(tools, GetWebNavigateToolDefinition(block))
182+
case "tsunami":
183+
// Check if tsunami widget is running
184+
status := blockcontroller.GetBlockControllerRuntimeStatus(block.OID)
185+
if status != nil && status.ShellProcStatus == blockcontroller.Status_Running && status.TsunamiPort > 0 {
186+
// Check if schemas are available
187+
blockORef := waveobj.MakeORef(waveobj.OType_Block, block.OID)
188+
rtInfo := wstore.GetRTInfo(blockORef)
189+
if rtInfo != nil && rtInfo.TsunamiSchemas != nil {
190+
if tool := GetTsunamiGetDataToolDefinition(block, rtInfo, status); tool != nil {
191+
tools = append(tools, *tool)
192+
}
193+
}
194+
}
180195
}
181196

182197
return tools
@@ -230,6 +245,62 @@ func GetWebNavigateToolDefinition(block *waveobj.Block) uctypes.ToolDefinition {
230245
}
231246
}
232247

248+
func GetTsunamiGetDataToolDefinition(block *waveobj.Block, rtInfo *waveobj.ObjRTInfo, status *blockcontroller.BlockControllerRuntimeStatus) *uctypes.ToolDefinition {
249+
blockIdPrefix := block.OID[:8]
250+
toolName := fmt.Sprintf("tsunami_getdata_%s", blockIdPrefix)
251+
252+
var inputSchema map[string]any
253+
if rtInfo != nil && rtInfo.TsunamiSchemas != nil {
254+
if schemasMap, ok := rtInfo.TsunamiSchemas.(map[string]any); ok {
255+
if dataSchema, exists := schemasMap["data"]; exists {
256+
inputSchema = dataSchema.(map[string]any)
257+
}
258+
}
259+
}
260+
261+
// Return nil if no data schema found
262+
if inputSchema == nil {
263+
return nil
264+
}
265+
266+
return &uctypes.ToolDefinition{
267+
Name: toolName,
268+
InputSchema: inputSchema,
269+
ToolAnyCallback: func(input any) (any, error) {
270+
if status.TsunamiPort == 0 {
271+
return nil, fmt.Errorf("tsunami port not available")
272+
}
273+
274+
url := fmt.Sprintf("http://localhost:%d/api/data", status.TsunamiPort)
275+
276+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
277+
defer cancel()
278+
279+
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
280+
if err != nil {
281+
return nil, fmt.Errorf("failed to create request: %w", err)
282+
}
283+
284+
resp, err := http.DefaultClient.Do(req)
285+
if err != nil {
286+
return nil, fmt.Errorf("failed to make request to tsunami: %w", err)
287+
}
288+
defer resp.Body.Close()
289+
290+
if resp.StatusCode != http.StatusOK {
291+
return nil, fmt.Errorf("tsunami returned status %d", resp.StatusCode)
292+
}
293+
294+
var result any
295+
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
296+
return nil, fmt.Errorf("failed to decode tsunami response: %w", err)
297+
}
298+
299+
return result, nil
300+
},
301+
}
302+
}
303+
233304
func GetAdderToolDefinition() uctypes.ToolDefinition {
234305
return uctypes.ToolDefinition{
235306
Name: "adder",

pkg/wstore/blockrtinfo.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ func SetRTInfo(oref waveobj.ORef, info map[string]any) {
6565
// Convert and set the value
6666
if valueStr, ok := value.(string); ok && fieldValue.Kind() == reflect.String {
6767
fieldValue.SetString(valueStr)
68+
} else if fieldValue.Kind() == reflect.Interface {
69+
// Handle any/interface{} fields
70+
fieldValue.Set(reflect.ValueOf(value))
6871
}
6972
}
7073
}

0 commit comments

Comments
 (0)