(tabId string)
| 48 | } |
| 49 | |
| 50 | func GetWebNavigateToolDefinition(tabId string) uctypes.ToolDefinition { |
| 51 | |
| 52 | return uctypes.ToolDefinition{ |
| 53 | Name: "web_navigate", |
| 54 | DisplayName: "Navigate Web Widget", |
| 55 | Description: "Navigate a web browser widget to a new URL", |
| 56 | ToolLogName: "web:navigate", |
| 57 | Strict: true, |
| 58 | InputSchema: map[string]any{ |
| 59 | "type": "object", |
| 60 | "properties": map[string]any{ |
| 61 | "widget_id": map[string]any{ |
| 62 | "type": "string", |
| 63 | "description": "8-character widget ID of the web browser widget", |
| 64 | }, |
| 65 | "url": map[string]any{ |
| 66 | "type": "string", |
| 67 | "description": "URL to navigate to", |
| 68 | }, |
| 69 | }, |
| 70 | "required": []string{"widget_id", "url"}, |
| 71 | "additionalProperties": false, |
| 72 | }, |
| 73 | ToolCallDesc: func(input any, output any, toolUseData *uctypes.UIMessageDataToolUse) string { |
| 74 | parsed, err := parseWebNavigateInput(input) |
| 75 | if err != nil { |
| 76 | return fmt.Sprintf("error parsing input: %v", err) |
| 77 | } |
| 78 | return fmt.Sprintf("navigating web widget %s to %q", parsed.WidgetId, parsed.Url) |
| 79 | }, |
| 80 | ToolAnyCallback: func(input any, toolUseData *uctypes.UIMessageDataToolUse) (any, error) { |
| 81 | parsed, err := parseWebNavigateInput(input) |
| 82 | if err != nil { |
| 83 | return nil, err |
| 84 | } |
| 85 | |
| 86 | ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second) |
| 87 | defer cancelFn() |
| 88 | |
| 89 | fullBlockId, err := wcore.ResolveBlockIdFromPrefix(ctx, tabId, parsed.WidgetId) |
| 90 | if err != nil { |
| 91 | return nil, err |
| 92 | } |
| 93 | |
| 94 | blockORef := waveobj.MakeORef(waveobj.OType_Block, fullBlockId) |
| 95 | meta := map[string]any{ |
| 96 | "url": parsed.Url, |
| 97 | } |
| 98 | |
| 99 | err = wstore.UpdateObjectMeta(ctx, blockORef, meta, false) |
| 100 | if err != nil { |
| 101 | return nil, fmt.Errorf("failed to update web block URL: %w", err) |
| 102 | } |
| 103 | |
| 104 | wcore.SendWaveObjUpdate(blockORef) |
| 105 | return true, nil |
| 106 | }, |
| 107 | } |
no test coverage detected