@tambo-ai/react 0.69.1 → 0.71.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/hooks/use-tambo-threads.test.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +4 -5
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +4 -5
- package/dist/mcp/index.js.map +1 -1
- package/dist/model/component-metadata.d.ts +88 -241
- package/dist/model/component-metadata.d.ts.map +1 -1
- package/dist/model/component-metadata.js.map +1 -1
- package/dist/model/mcp-server-info.d.ts +3 -3
- package/dist/model/mcp-server-info.js.map +1 -1
- package/dist/providers/hooks/use-tambo-session-token.test.js.map +1 -1
- package/dist/providers/tambo-component-provider.d.ts +2 -2
- package/dist/providers/tambo-component-provider.d.ts.map +1 -1
- package/dist/providers/tambo-component-provider.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.d.ts +1 -1
- package/dist/providers/tambo-registry-provider.d.ts +4 -4
- package/dist/providers/tambo-registry-provider.d.ts.map +1 -1
- package/dist/providers/tambo-registry-provider.js +11 -8
- package/dist/providers/tambo-registry-provider.js.map +1 -1
- package/dist/providers/tambo-registry-provider.test.js +31 -0
- package/dist/providers/tambo-registry-provider.test.js.map +1 -1
- package/dist/providers/tambo-registry-schema-compat.test.js +42 -52
- package/dist/providers/tambo-registry-schema-compat.test.js.map +1 -1
- package/dist/providers/tambo-stubs.d.ts +2 -2
- package/dist/providers/tambo-stubs.d.ts.map +1 -1
- package/dist/providers/tambo-stubs.js.map +1 -1
- package/dist/providers/tambo-thread-provider-initial-messages.test.js.map +1 -1
- package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
- package/dist/providers/tambo-thread-provider.js +107 -141
- package/dist/providers/tambo-thread-provider.js.map +1 -1
- package/dist/providers/tambo-thread-provider.test.js +274 -445
- package/dist/providers/tambo-thread-provider.test.js.map +1 -1
- package/dist/schema/index.d.ts +1 -2
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +1 -5
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/schema.d.ts +7 -24
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/schema.js +34 -105
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/schema.test.js +26 -124
- package/dist/schema/schema.test.js.map +1 -1
- package/dist/testing/tools.d.ts +2 -12
- package/dist/testing/tools.d.ts.map +1 -1
- package/dist/testing/tools.js +1 -20
- package/dist/testing/tools.js.map +1 -1
- package/dist/testing/types.d.ts +2 -2
- package/dist/testing/types.d.ts.map +1 -1
- package/dist/testing/types.js.map +1 -1
- package/dist/util/registry-validators.d.ts +2 -2
- package/dist/util/registry-validators.d.ts.map +1 -1
- package/dist/util/registry-validators.js +37 -17
- package/dist/util/registry-validators.js.map +1 -1
- package/dist/util/registry-validators.test.js +64 -25
- package/dist/util/registry-validators.test.js.map +1 -1
- package/dist/util/registry.d.ts +4 -10
- package/dist/util/registry.d.ts.map +1 -1
- package/dist/util/registry.js +6 -22
- package/dist/util/registry.js.map +1 -1
- package/dist/util/registry.test.js +1 -47
- package/dist/util/registry.test.js.map +1 -1
- package/dist/util/tool-caller.d.ts +2 -2
- package/dist/util/tool-caller.d.ts.map +1 -1
- package/dist/util/tool-caller.js +5 -12
- package/dist/util/tool-caller.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-messages.d.ts +58 -0
- package/dist/v1/hooks/use-tambo-v1-messages.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-messages.js +54 -0
- package/dist/v1/hooks/use-tambo-v1-messages.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-messages.test.d.ts +2 -0
- package/dist/v1/hooks/use-tambo-v1-messages.test.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-messages.test.js +137 -0
- package/dist/v1/hooks/use-tambo-v1-messages.test.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.d.ts +96 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.js +227 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.test.d.ts +2 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.test.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.test.js +827 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.d.ts +61 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.js +56 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.d.ts +2 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.js +98 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread.d.ts +37 -0
- package/dist/v1/hooks/use-tambo-v1-thread.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread.js +49 -0
- package/dist/v1/hooks/use-tambo-v1-thread.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread.test.d.ts +2 -0
- package/dist/v1/hooks/use-tambo-v1-thread.test.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread.test.js +83 -0
- package/dist/v1/hooks/use-tambo-v1-thread.test.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1.d.ts +107 -0
- package/dist/v1/hooks/use-tambo-v1.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1.js +87 -0
- package/dist/v1/hooks/use-tambo-v1.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1.test.d.ts +2 -0
- package/dist/v1/hooks/use-tambo-v1.test.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1.test.js +150 -0
- package/dist/v1/hooks/use-tambo-v1.test.js.map +1 -0
- package/dist/v1/index.d.ts +73 -0
- package/dist/v1/index.d.ts.map +1 -0
- package/dist/v1/index.js +106 -0
- package/dist/v1/index.js.map +1 -0
- package/dist/v1/providers/tambo-v1-provider.d.ts +91 -0
- package/dist/v1/providers/tambo-v1-provider.d.ts.map +1 -0
- package/dist/v1/providers/tambo-v1-provider.js +110 -0
- package/dist/v1/providers/tambo-v1-provider.js.map +1 -0
- package/dist/v1/providers/tambo-v1-provider.test.d.ts +2 -0
- package/dist/v1/providers/tambo-v1-provider.test.d.ts.map +1 -0
- package/dist/v1/providers/tambo-v1-provider.test.js +123 -0
- package/dist/v1/providers/tambo-v1-provider.test.js.map +1 -0
- package/dist/v1/providers/tambo-v1-stream-context.d.ts +136 -0
- package/dist/v1/providers/tambo-v1-stream-context.d.ts.map +1 -0
- package/dist/v1/providers/tambo-v1-stream-context.js +230 -0
- package/dist/v1/providers/tambo-v1-stream-context.js.map +1 -0
- package/dist/v1/providers/tambo-v1-stream-context.test.d.ts +2 -0
- package/dist/v1/providers/tambo-v1-stream-context.test.d.ts.map +1 -0
- package/dist/v1/providers/tambo-v1-stream-context.test.js +85 -0
- package/dist/v1/providers/tambo-v1-stream-context.test.js.map +1 -0
- package/dist/v1/types/component.d.ts +50 -0
- package/dist/v1/types/component.d.ts.map +1 -0
- package/dist/v1/types/component.js +14 -0
- package/dist/v1/types/component.js.map +1 -0
- package/dist/v1/types/event.d.ts +72 -0
- package/dist/v1/types/event.d.ts.map +1 -0
- package/dist/v1/types/event.js +54 -0
- package/dist/v1/types/event.js.map +1 -0
- package/dist/v1/types/event.test.d.ts +2 -0
- package/dist/v1/types/event.test.d.ts.map +1 -0
- package/dist/v1/types/event.test.js +70 -0
- package/dist/v1/types/event.test.js.map +1 -0
- package/dist/v1/types/message.d.ts +35 -0
- package/dist/v1/types/message.d.ts.map +1 -0
- package/dist/v1/types/message.js +10 -0
- package/dist/v1/types/message.js.map +1 -0
- package/dist/v1/types/thread.d.ts +52 -0
- package/dist/v1/types/thread.d.ts.map +1 -0
- package/dist/v1/types/thread.js +9 -0
- package/dist/v1/types/thread.js.map +1 -0
- package/dist/v1/utils/event-accumulator.d.ts +100 -0
- package/dist/v1/utils/event-accumulator.d.ts.map +1 -0
- package/dist/v1/utils/event-accumulator.js +715 -0
- package/dist/v1/utils/event-accumulator.js.map +1 -0
- package/dist/v1/utils/event-accumulator.test.d.ts +2 -0
- package/dist/v1/utils/event-accumulator.test.d.ts.map +1 -0
- package/dist/v1/utils/event-accumulator.test.js +1010 -0
- package/dist/v1/utils/event-accumulator.test.js.map +1 -0
- package/dist/v1/utils/json-patch.d.ts +18 -0
- package/dist/v1/utils/json-patch.d.ts.map +1 -0
- package/dist/v1/utils/json-patch.js +35 -0
- package/dist/v1/utils/json-patch.js.map +1 -0
- package/dist/v1/utils/json-patch.test.d.ts +2 -0
- package/dist/v1/utils/json-patch.test.d.ts.map +1 -0
- package/dist/v1/utils/json-patch.test.js +28 -0
- package/dist/v1/utils/json-patch.test.js.map +1 -0
- package/dist/v1/utils/registry-conversion.d.ts +53 -0
- package/dist/v1/utils/registry-conversion.d.ts.map +1 -0
- package/dist/v1/utils/registry-conversion.js +114 -0
- package/dist/v1/utils/registry-conversion.js.map +1 -0
- package/dist/v1/utils/registry-conversion.test.d.ts +2 -0
- package/dist/v1/utils/registry-conversion.test.d.ts.map +1 -0
- package/dist/v1/utils/registry-conversion.test.js +179 -0
- package/dist/v1/utils/registry-conversion.test.js.map +1 -0
- package/dist/v1/utils/stream-handler.d.ts +45 -0
- package/dist/v1/utils/stream-handler.d.ts.map +1 -0
- package/dist/v1/utils/stream-handler.js +47 -0
- package/dist/v1/utils/stream-handler.js.map +1 -0
- package/dist/v1/utils/stream-handler.test.d.ts +2 -0
- package/dist/v1/utils/stream-handler.test.d.ts.map +1 -0
- package/dist/v1/utils/stream-handler.test.js +74 -0
- package/dist/v1/utils/stream-handler.test.js.map +1 -0
- package/dist/v1/utils/tool-call-tracker.d.ts +41 -0
- package/dist/v1/utils/tool-call-tracker.d.ts.map +1 -0
- package/dist/v1/utils/tool-call-tracker.js +90 -0
- package/dist/v1/utils/tool-call-tracker.js.map +1 -0
- package/dist/v1/utils/tool-executor.d.ts +33 -0
- package/dist/v1/utils/tool-executor.d.ts.map +1 -0
- package/dist/v1/utils/tool-executor.js +103 -0
- package/dist/v1/utils/tool-executor.js.map +1 -0
- package/dist/v1/utils/tool-executor.test.d.ts +2 -0
- package/dist/v1/utils/tool-executor.test.d.ts.map +1 -0
- package/dist/v1/utils/tool-executor.test.js +222 -0
- package/dist/v1/utils/tool-executor.test.js.map +1 -0
- package/esm/hooks/use-tambo-threads.test.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/mcp/index.d.ts +4 -5
- package/esm/mcp/index.d.ts.map +1 -1
- package/esm/mcp/index.js +4 -5
- package/esm/mcp/index.js.map +1 -1
- package/esm/model/component-metadata.d.ts +88 -241
- package/esm/model/component-metadata.d.ts.map +1 -1
- package/esm/model/component-metadata.js.map +1 -1
- package/esm/model/mcp-server-info.d.ts +3 -3
- package/esm/model/mcp-server-info.js.map +1 -1
- package/esm/providers/hooks/use-tambo-session-token.test.js.map +1 -1
- package/esm/providers/tambo-component-provider.d.ts +2 -2
- package/esm/providers/tambo-component-provider.d.ts.map +1 -1
- package/esm/providers/tambo-component-provider.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.d.ts +1 -1
- package/esm/providers/tambo-registry-provider.d.ts +4 -4
- package/esm/providers/tambo-registry-provider.d.ts.map +1 -1
- package/esm/providers/tambo-registry-provider.js +11 -8
- package/esm/providers/tambo-registry-provider.js.map +1 -1
- package/esm/providers/tambo-registry-provider.test.js +31 -0
- package/esm/providers/tambo-registry-provider.test.js.map +1 -1
- package/esm/providers/tambo-registry-schema-compat.test.js +42 -52
- package/esm/providers/tambo-registry-schema-compat.test.js.map +1 -1
- package/esm/providers/tambo-stubs.d.ts +2 -2
- package/esm/providers/tambo-stubs.d.ts.map +1 -1
- package/esm/providers/tambo-stubs.js.map +1 -1
- package/esm/providers/tambo-thread-provider-initial-messages.test.js.map +1 -1
- package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
- package/esm/providers/tambo-thread-provider.js +107 -141
- package/esm/providers/tambo-thread-provider.js.map +1 -1
- package/esm/providers/tambo-thread-provider.test.js +241 -445
- package/esm/providers/tambo-thread-provider.test.js.map +1 -1
- package/esm/schema/index.d.ts +1 -2
- package/esm/schema/index.d.ts.map +1 -1
- package/esm/schema/index.js +1 -2
- package/esm/schema/index.js.map +1 -1
- package/esm/schema/schema.d.ts +7 -24
- package/esm/schema/schema.d.ts.map +1 -1
- package/esm/schema/schema.js +34 -103
- package/esm/schema/schema.js.map +1 -1
- package/esm/schema/schema.test.js +27 -125
- package/esm/schema/schema.test.js.map +1 -1
- package/esm/testing/tools.d.ts +2 -12
- package/esm/testing/tools.d.ts.map +1 -1
- package/esm/testing/tools.js +2 -20
- package/esm/testing/tools.js.map +1 -1
- package/esm/testing/types.d.ts +2 -2
- package/esm/testing/types.d.ts.map +1 -1
- package/esm/testing/types.js.map +1 -1
- package/esm/util/registry-validators.d.ts +2 -2
- package/esm/util/registry-validators.d.ts.map +1 -1
- package/esm/util/registry-validators.js +38 -18
- package/esm/util/registry-validators.js.map +1 -1
- package/esm/util/registry-validators.test.js +64 -25
- package/esm/util/registry-validators.test.js.map +1 -1
- package/esm/util/registry.d.ts +4 -10
- package/esm/util/registry.d.ts.map +1 -1
- package/esm/util/registry.js +7 -22
- package/esm/util/registry.js.map +1 -1
- package/esm/util/registry.test.js +3 -49
- package/esm/util/registry.test.js.map +1 -1
- package/esm/util/tool-caller.d.ts +2 -2
- package/esm/util/tool-caller.d.ts.map +1 -1
- package/esm/util/tool-caller.js +5 -12
- package/esm/util/tool-caller.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-messages.d.ts +58 -0
- package/esm/v1/hooks/use-tambo-v1-messages.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-messages.js +51 -0
- package/esm/v1/hooks/use-tambo-v1-messages.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-messages.test.d.ts +2 -0
- package/esm/v1/hooks/use-tambo-v1-messages.test.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-messages.test.js +132 -0
- package/esm/v1/hooks/use-tambo-v1-messages.test.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.d.ts +96 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.js +223 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.test.d.ts +2 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.test.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.test.js +822 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.d.ts +61 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.js +53 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.d.ts +2 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.js +93 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread.d.ts +37 -0
- package/esm/v1/hooks/use-tambo-v1-thread.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread.js +46 -0
- package/esm/v1/hooks/use-tambo-v1-thread.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread.test.d.ts +2 -0
- package/esm/v1/hooks/use-tambo-v1-thread.test.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread.test.js +78 -0
- package/esm/v1/hooks/use-tambo-v1-thread.test.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1.d.ts +107 -0
- package/esm/v1/hooks/use-tambo-v1.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1.js +84 -0
- package/esm/v1/hooks/use-tambo-v1.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1.test.d.ts +2 -0
- package/esm/v1/hooks/use-tambo-v1.test.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1.test.js +145 -0
- package/esm/v1/hooks/use-tambo-v1.test.js.map +1 -0
- package/esm/v1/index.d.ts +73 -0
- package/esm/v1/index.d.ts.map +1 -0
- package/esm/v1/index.js +83 -0
- package/esm/v1/index.js.map +1 -0
- package/esm/v1/providers/tambo-v1-provider.d.ts +91 -0
- package/esm/v1/providers/tambo-v1-provider.d.ts.map +1 -0
- package/esm/v1/providers/tambo-v1-provider.js +74 -0
- package/esm/v1/providers/tambo-v1-provider.js.map +1 -0
- package/esm/v1/providers/tambo-v1-provider.test.d.ts +2 -0
- package/esm/v1/providers/tambo-v1-provider.test.d.ts.map +1 -0
- package/esm/v1/providers/tambo-v1-provider.test.js +118 -0
- package/esm/v1/providers/tambo-v1-provider.test.js.map +1 -0
- package/esm/v1/providers/tambo-v1-stream-context.d.ts +136 -0
- package/esm/v1/providers/tambo-v1-stream-context.d.ts.map +1 -0
- package/esm/v1/providers/tambo-v1-stream-context.js +191 -0
- package/esm/v1/providers/tambo-v1-stream-context.js.map +1 -0
- package/esm/v1/providers/tambo-v1-stream-context.test.d.ts +2 -0
- package/esm/v1/providers/tambo-v1-stream-context.test.d.ts.map +1 -0
- package/esm/v1/providers/tambo-v1-stream-context.test.js +80 -0
- package/esm/v1/providers/tambo-v1-stream-context.test.js.map +1 -0
- package/esm/v1/types/component.d.ts +50 -0
- package/esm/v1/types/component.d.ts.map +1 -0
- package/esm/v1/types/component.js +13 -0
- package/esm/v1/types/component.js.map +1 -0
- package/esm/v1/types/event.d.ts +72 -0
- package/esm/v1/types/event.d.ts.map +1 -0
- package/esm/v1/types/event.js +50 -0
- package/esm/v1/types/event.js.map +1 -0
- package/esm/v1/types/event.test.d.ts +2 -0
- package/esm/v1/types/event.test.d.ts.map +1 -0
- package/esm/v1/types/event.test.js +68 -0
- package/esm/v1/types/event.test.js.map +1 -0
- package/esm/v1/types/message.d.ts +35 -0
- package/esm/v1/types/message.d.ts.map +1 -0
- package/esm/v1/types/message.js +9 -0
- package/esm/v1/types/message.js.map +1 -0
- package/esm/v1/types/thread.d.ts +52 -0
- package/esm/v1/types/thread.d.ts.map +1 -0
- package/esm/v1/types/thread.js +8 -0
- package/esm/v1/types/thread.js.map +1 -0
- package/esm/v1/utils/event-accumulator.d.ts +100 -0
- package/esm/v1/utils/event-accumulator.d.ts.map +1 -0
- package/esm/v1/utils/event-accumulator.js +708 -0
- package/esm/v1/utils/event-accumulator.js.map +1 -0
- package/esm/v1/utils/event-accumulator.test.d.ts +2 -0
- package/esm/v1/utils/event-accumulator.test.d.ts.map +1 -0
- package/esm/v1/utils/event-accumulator.test.js +1008 -0
- package/esm/v1/utils/event-accumulator.test.js.map +1 -0
- package/esm/v1/utils/json-patch.d.ts +18 -0
- package/esm/v1/utils/json-patch.d.ts.map +1 -0
- package/esm/v1/utils/json-patch.js +32 -0
- package/esm/v1/utils/json-patch.js.map +1 -0
- package/esm/v1/utils/json-patch.test.d.ts +2 -0
- package/esm/v1/utils/json-patch.test.d.ts.map +1 -0
- package/esm/v1/utils/json-patch.test.js +26 -0
- package/esm/v1/utils/json-patch.test.js.map +1 -0
- package/esm/v1/utils/registry-conversion.d.ts +53 -0
- package/esm/v1/utils/registry-conversion.d.ts.map +1 -0
- package/esm/v1/utils/registry-conversion.js +108 -0
- package/esm/v1/utils/registry-conversion.js.map +1 -0
- package/esm/v1/utils/registry-conversion.test.d.ts +2 -0
- package/esm/v1/utils/registry-conversion.test.d.ts.map +1 -0
- package/esm/v1/utils/registry-conversion.test.js +177 -0
- package/esm/v1/utils/registry-conversion.test.js.map +1 -0
- package/esm/v1/utils/stream-handler.d.ts +45 -0
- package/esm/v1/utils/stream-handler.d.ts.map +1 -0
- package/esm/v1/utils/stream-handler.js +44 -0
- package/esm/v1/utils/stream-handler.js.map +1 -0
- package/esm/v1/utils/stream-handler.test.d.ts +2 -0
- package/esm/v1/utils/stream-handler.test.d.ts.map +1 -0
- package/esm/v1/utils/stream-handler.test.js +72 -0
- package/esm/v1/utils/stream-handler.test.js.map +1 -0
- package/esm/v1/utils/tool-call-tracker.d.ts +41 -0
- package/esm/v1/utils/tool-call-tracker.d.ts.map +1 -0
- package/esm/v1/utils/tool-call-tracker.js +86 -0
- package/esm/v1/utils/tool-call-tracker.js.map +1 -0
- package/esm/v1/utils/tool-executor.d.ts +33 -0
- package/esm/v1/utils/tool-executor.d.ts.map +1 -0
- package/esm/v1/utils/tool-executor.js +99 -0
- package/esm/v1/utils/tool-executor.js.map +1 -0
- package/esm/v1/utils/tool-executor.test.d.ts +2 -0
- package/esm/v1/utils/tool-executor.test.d.ts.map +1 -0
- package/esm/v1/utils/tool-executor.test.js +220 -0
- package/esm/v1/utils/tool-executor.test.js.map +1 -0
- package/package.json +20 -9
- package/dist/schema/zod.d.ts +0 -57
- package/dist/schema/zod.d.ts.map +0 -1
- package/dist/schema/zod.js +0 -191
- package/dist/schema/zod.js.map +0 -1
- package/dist/schema/zod.test.d.ts +0 -2
- package/dist/schema/zod.test.d.ts.map +0 -1
- package/dist/schema/zod.test.js +0 -663
- package/dist/schema/zod.test.js.map +0 -1
- package/esm/schema/zod.d.ts +0 -57
- package/esm/schema/zod.d.ts.map +0 -1
- package/esm/schema/zod.js +0 -180
- package/esm/schema/zod.js.map +0 -1
- package/esm/schema/zod.test.d.ts +0 -2
- package/esm/schema/zod.test.d.ts.map +0 -1
- package/esm/schema/zod.test.js +0 -628
- package/esm/schema/zod.test.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-conversion.test.js","sourceRoot":"","sources":["../../../src/v1/utils/registry-conversion.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;QACpC,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;YAC/C,MAAM,SAAS,GAAmB;gBAChC,IAAI,EAAE,aAAa;gBACnB,WAAW,EAAE,8BAA8B;gBAC3C,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI;gBACrB,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;oBACpB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;oBAChB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;iBACxB,CAAC;aACH,CAAC;YAEF,MAAM,MAAM,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAAC;YAE/C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACxC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;YAChE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC;YACzC,MAAM,CAAE,MAAM,CAAC,WAAuC,CAAC,IAAI,CAAC,CAAC,IAAI,CAC/D,QAAQ,CACT,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;YAC5C,MAAM,SAAS,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AAE;oBACP,IAAI,EAAE,SAAS;oBACf,WAAW,EAAE,gBAAgB;oBAC7B,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI;iBACC;aAC1B,CAAC;YAEF,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;YAEvC,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAC/B,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrC,MAAM,CAAC,OAAO,CAAC,CAAC,oBAAoB,CAClC,MAAM,CAAC,gBAAgB,CAAC,yBAAyB,CAAC,CACnD,CAAC;YAEF,OAAO,CAAC,WAAW,EAAE,CAAC;QACxB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\nimport type { TamboComponent, TamboTool } from \"../../model/component-metadata\";\nimport {\n toAvailableComponent,\n toAvailableComponents,\n toAvailableTool,\n toAvailableTools,\n} from \"./registry-conversion\";\n\ndescribe(\"registry-conversion\", () => {\n describe(\"toAvailableComponent\", () => {\n it(\"converts a component with propsSchema\", () => {\n const component: TamboComponent = {\n name: \"WeatherCard\",\n description: \"Displays weather information\",\n component: () => null,\n propsSchema: z.object({\n city: z.string(),\n temperature: z.number(),\n }),\n };\n\n const result = toAvailableComponent(component);\n\n expect(result.name).toBe(\"WeatherCard\");\n expect(result.description).toBe(\"Displays weather information\");\n expect(result.propsSchema).toBeDefined();\n expect((result.propsSchema as Record<string, unknown>).type).toBe(\n \"object\",\n );\n });\n\n it(\"throws when propsSchema is missing\", () => {\n const component = {\n name: \"BadComponent\",\n description: \"Missing schema\",\n component: () => null,\n } as TamboComponent;\n\n expect(() => toAvailableComponent(component)).toThrow(\n 'Component \"BadComponent\" missing propsSchema',\n );\n });\n });\n\n describe(\"toAvailableComponents\", () => {\n it(\"converts a Record of components\", () => {\n const components: Record<string, TamboComponent> = {\n Card: {\n name: \"Card\",\n description: \"A card component\",\n component: () => null,\n propsSchema: z.object({ title: z.string() }),\n },\n Button: {\n name: \"Button\",\n description: \"A button component\",\n component: () => null,\n propsSchema: z.object({ label: z.string() }),\n },\n };\n\n const result = toAvailableComponents(components);\n\n expect(result).toHaveLength(2);\n expect(result.map((c) => c.name)).toContain(\"Card\");\n expect(result.map((c) => c.name)).toContain(\"Button\");\n });\n\n it(\"converts a Map of components\", () => {\n const components = new Map<string, TamboComponent>([\n [\n \"Card\",\n {\n name: \"Card\",\n description: \"A card\",\n component: () => null,\n propsSchema: z.object({ title: z.string() }),\n },\n ],\n ]);\n\n const result = toAvailableComponents(components);\n\n expect(result).toHaveLength(1);\n expect(result[0].name).toBe(\"Card\");\n });\n\n it(\"skips invalid components and logs warning\", () => {\n const warnSpy = jest.spyOn(console, \"warn\").mockImplementation(() => {});\n\n const components: Record<string, TamboComponent> = {\n Valid: {\n name: \"Valid\",\n description: \"Valid component\",\n component: () => null,\n propsSchema: z.object({ x: z.string() }),\n },\n Invalid: {\n name: \"Invalid\",\n description: \"Missing schema\",\n component: () => null,\n } as TamboComponent,\n };\n\n const result = toAvailableComponents(components);\n\n expect(result).toHaveLength(1);\n expect(result[0].name).toBe(\"Valid\");\n expect(warnSpy).toHaveBeenCalledWith(\n expect.stringContaining('Skipping component \"Invalid\"'),\n );\n\n warnSpy.mockRestore();\n });\n });\n\n describe(\"toAvailableTool\", () => {\n it(\"converts a tool with inputSchema\", () => {\n const tool: TamboTool = {\n name: \"get_weather\",\n description: \"Gets weather for a city\",\n tool: async () => ({ temp: 72 }),\n inputSchema: z.object({ city: z.string() }),\n outputSchema: z.any(),\n };\n\n const result = toAvailableTool(tool);\n\n expect(result.name).toBe(\"get_weather\");\n expect(result.description).toBe(\"Gets weather for a city\");\n expect(result.inputSchema).toBeDefined();\n expect((result.inputSchema as Record<string, unknown>).type).toBe(\n \"object\",\n );\n });\n\n it(\"throws when schema is missing\", () => {\n const tool = {\n name: \"bad_tool\",\n description: \"Missing schema\",\n tool: async () => ({}),\n } as unknown as TamboTool;\n\n expect(() => toAvailableTool(tool)).toThrow(\n 'Tool \"bad_tool\" missing inputSchema or toolSchema',\n );\n });\n });\n\n describe(\"toAvailableTools\", () => {\n it(\"converts a Record of tools\", () => {\n const tools: Record<string, TamboTool> = {\n search: {\n name: \"search\",\n description: \"Search the web\",\n tool: async () => [],\n inputSchema: z.object({ query: z.string() }),\n outputSchema: z.any(),\n },\n calculate: {\n name: \"calculate\",\n description: \"Calculate expression\",\n tool: async () => 0,\n inputSchema: z.object({ expr: z.string() }),\n outputSchema: z.any(),\n },\n };\n\n const result = toAvailableTools(tools);\n\n expect(result).toHaveLength(2);\n expect(result.map((t) => t.name)).toContain(\"search\");\n expect(result.map((t) => t.name)).toContain(\"calculate\");\n });\n\n it(\"converts a Map of tools\", () => {\n const tools = new Map<string, TamboTool>([\n [\n \"fetch\",\n {\n name: \"fetch\",\n description: \"Fetch data\",\n tool: async () => null,\n inputSchema: z.object({ url: z.string() }),\n outputSchema: z.any(),\n },\n ],\n ]);\n\n const result = toAvailableTools(tools);\n\n expect(result).toHaveLength(1);\n expect(result[0].name).toBe(\"fetch\");\n });\n\n it(\"skips invalid tools and logs warning\", () => {\n const warnSpy = jest.spyOn(console, \"warn\").mockImplementation(() => {});\n\n const tools: Record<string, TamboTool> = {\n valid: {\n name: \"valid\",\n description: \"Valid tool\",\n tool: async () => null,\n inputSchema: z.object({ x: z.number() }),\n outputSchema: z.any(),\n },\n invalid: {\n name: \"invalid\",\n description: \"Missing schema\",\n tool: async () => null,\n } as unknown as TamboTool,\n };\n\n const result = toAvailableTools(tools);\n\n expect(result).toHaveLength(1);\n expect(result[0].name).toBe(\"valid\");\n expect(warnSpy).toHaveBeenCalledWith(\n expect.stringContaining('Skipping tool \"invalid\"'),\n );\n\n warnSpy.mockRestore();\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream Handler for v1 Streaming API
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for handling event streams from the TypeScript SDK.
|
|
5
|
+
* The SDK's client.threads.runs.run() already returns an async iterable,
|
|
6
|
+
* so this module just adds optional debug logging.
|
|
7
|
+
*/
|
|
8
|
+
import type { AGUIEvent } from "@ag-ui/core";
|
|
9
|
+
/**
|
|
10
|
+
* Options for stream handling.
|
|
11
|
+
*/
|
|
12
|
+
export interface StreamHandlerOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Enable debug logging (development mode only).
|
|
15
|
+
* Logs all events to console.
|
|
16
|
+
*/
|
|
17
|
+
debug?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Handle an event stream from the TypeScript SDK and yield AG-UI event types.
|
|
21
|
+
*
|
|
22
|
+
* The TypeScript SDK's client.threads.runs.run() and client.threads.runs.create()
|
|
23
|
+
* return async iterables that yield events compatible with AG-UI's AGUIEvent.
|
|
24
|
+
* This function wraps the stream to add optional debug logging and ensures
|
|
25
|
+
* proper typing.
|
|
26
|
+
*
|
|
27
|
+
* Note: SDK events have `type: string` rather than `type: EventType` enum,
|
|
28
|
+
* but the values are compatible with AG-UI event types.
|
|
29
|
+
* @param stream - Async iterable of events from SDK
|
|
30
|
+
* @param options - Optional configuration for stream handling
|
|
31
|
+
* @yields {AGUIEvent} AG-UI event types from the stream
|
|
32
|
+
* @returns Async iterable of AG-UI event types
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const stream = await client.threads.runs.run(threadId, {
|
|
36
|
+
* message: { role: "user", content: [{ type: "text", text: "hello" }] },
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* for await (const event of handleEventStream(stream, { debug: true })) {
|
|
40
|
+
* dispatch({ type: 'EVENT', event }); // Send to reducer
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function handleEventStream(stream: AsyncIterable<unknown>, options?: StreamHandlerOptions): AsyncIterable<AGUIEvent>;
|
|
45
|
+
//# sourceMappingURL=stream-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-handler.d.ts","sourceRoot":"","sources":["../../../src/v1/utils/stream-handler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAuB,iBAAiB,CACtC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE,oBAAoB,GAC7B,aAAa,CAAC,SAAS,CAAC,CAY1B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream Handler for v1 Streaming API
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for handling event streams from the TypeScript SDK.
|
|
5
|
+
* The SDK's client.threads.runs.run() already returns an async iterable,
|
|
6
|
+
* so this module just adds optional debug logging.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Handle an event stream from the TypeScript SDK and yield AG-UI event types.
|
|
10
|
+
*
|
|
11
|
+
* The TypeScript SDK's client.threads.runs.run() and client.threads.runs.create()
|
|
12
|
+
* return async iterables that yield events compatible with AG-UI's AGUIEvent.
|
|
13
|
+
* This function wraps the stream to add optional debug logging and ensures
|
|
14
|
+
* proper typing.
|
|
15
|
+
*
|
|
16
|
+
* Note: SDK events have `type: string` rather than `type: EventType` enum,
|
|
17
|
+
* but the values are compatible with AG-UI event types.
|
|
18
|
+
* @param stream - Async iterable of events from SDK
|
|
19
|
+
* @param options - Optional configuration for stream handling
|
|
20
|
+
* @yields {AGUIEvent} AG-UI event types from the stream
|
|
21
|
+
* @returns Async iterable of AG-UI event types
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const stream = await client.threads.runs.run(threadId, {
|
|
25
|
+
* message: { role: "user", content: [{ type: "text", text: "hello" }] },
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* for await (const event of handleEventStream(stream, { debug: true })) {
|
|
29
|
+
* dispatch({ type: 'EVENT', event }); // Send to reducer
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export async function* handleEventStream(stream, options) {
|
|
34
|
+
const { debug = false } = options ?? {};
|
|
35
|
+
for await (const event of stream) {
|
|
36
|
+
if (debug && process.env.NODE_ENV !== "production") {
|
|
37
|
+
// eslint-disable-next-line no-console
|
|
38
|
+
console.log("[StreamHandler] Event:", event);
|
|
39
|
+
}
|
|
40
|
+
// SDK events are compatible with AG-UI AGUIEvent discriminated union
|
|
41
|
+
yield event;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=stream-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-handler.js","sourceRoot":"","sources":["../../../src/v1/utils/stream-handler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAeH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,iBAAiB,CACtC,MAA8B,EAC9B,OAA8B;IAE9B,MAAM,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAExC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACjC,IAAI,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;YACnD,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;QAC/C,CAAC;QAED,qEAAqE;QACrE,MAAM,KAAkB,CAAC;IAC3B,CAAC;AACH,CAAC","sourcesContent":["/**\n * Stream Handler for v1 Streaming API\n *\n * Provides utilities for handling event streams from the TypeScript SDK.\n * The SDK's client.threads.runs.run() already returns an async iterable,\n * so this module just adds optional debug logging.\n */\n\nimport type { AGUIEvent } from \"@ag-ui/core\";\n\n/**\n * Options for stream handling.\n */\nexport interface StreamHandlerOptions {\n /**\n * Enable debug logging (development mode only).\n * Logs all events to console.\n */\n debug?: boolean;\n}\n\n/**\n * Handle an event stream from the TypeScript SDK and yield AG-UI event types.\n *\n * The TypeScript SDK's client.threads.runs.run() and client.threads.runs.create()\n * return async iterables that yield events compatible with AG-UI's AGUIEvent.\n * This function wraps the stream to add optional debug logging and ensures\n * proper typing.\n *\n * Note: SDK events have `type: string` rather than `type: EventType` enum,\n * but the values are compatible with AG-UI event types.\n * @param stream - Async iterable of events from SDK\n * @param options - Optional configuration for stream handling\n * @yields {AGUIEvent} AG-UI event types from the stream\n * @returns Async iterable of AG-UI event types\n * @example\n * ```typescript\n * const stream = await client.threads.runs.run(threadId, {\n * message: { role: \"user\", content: [{ type: \"text\", text: \"hello\" }] },\n * });\n *\n * for await (const event of handleEventStream(stream, { debug: true })) {\n * dispatch({ type: 'EVENT', event }); // Send to reducer\n * }\n * ```\n */\nexport async function* handleEventStream(\n stream: AsyncIterable<unknown>,\n options?: StreamHandlerOptions,\n): AsyncIterable<AGUIEvent> {\n const { debug = false } = options ?? {};\n\n for await (const event of stream) {\n if (debug && process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line no-console\n console.log(\"[StreamHandler] Event:\", event);\n }\n\n // SDK events are compatible with AG-UI AGUIEvent discriminated union\n yield event as AGUIEvent;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-handler.test.d.ts","sourceRoot":"","sources":["../../../src/v1/utils/stream-handler.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { EventType } from "@ag-ui/core";
|
|
2
|
+
import { handleEventStream } from "./stream-handler";
|
|
3
|
+
describe("handleEventStream", () => {
|
|
4
|
+
it("yields events from the stream", async () => {
|
|
5
|
+
const mockEvents = [
|
|
6
|
+
{ type: EventType.RUN_STARTED, runId: "run_1", threadId: "thread_1" },
|
|
7
|
+
{
|
|
8
|
+
type: EventType.TEXT_MESSAGE_START,
|
|
9
|
+
messageId: "msg_1",
|
|
10
|
+
role: "assistant",
|
|
11
|
+
},
|
|
12
|
+
{ type: EventType.RUN_FINISHED, runId: "run_1", threadId: "thread_1" },
|
|
13
|
+
];
|
|
14
|
+
async function* mockStream() {
|
|
15
|
+
for (const event of mockEvents) {
|
|
16
|
+
yield event;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const result = [];
|
|
20
|
+
for await (const event of handleEventStream(mockStream())) {
|
|
21
|
+
result.push(event);
|
|
22
|
+
}
|
|
23
|
+
expect(result).toHaveLength(3);
|
|
24
|
+
expect(result[0]).toEqual(mockEvents[0]);
|
|
25
|
+
expect(result[1]).toEqual(mockEvents[1]);
|
|
26
|
+
expect(result[2]).toEqual(mockEvents[2]);
|
|
27
|
+
});
|
|
28
|
+
it("handles empty stream", async () => {
|
|
29
|
+
async function* emptyStream() {
|
|
30
|
+
// yields nothing
|
|
31
|
+
}
|
|
32
|
+
const result = [];
|
|
33
|
+
for await (const event of handleEventStream(emptyStream())) {
|
|
34
|
+
result.push(event);
|
|
35
|
+
}
|
|
36
|
+
expect(result).toHaveLength(0);
|
|
37
|
+
});
|
|
38
|
+
it("logs events when debug is enabled in non-production", async () => {
|
|
39
|
+
const originalEnv = process.env.NODE_ENV;
|
|
40
|
+
process.env.NODE_ENV = "development";
|
|
41
|
+
const logSpy = jest.spyOn(console, "log").mockImplementation(() => { });
|
|
42
|
+
const mockEvents = [{ type: EventType.RUN_STARTED, runId: "run_1" }];
|
|
43
|
+
async function* mockStream() {
|
|
44
|
+
for (const event of mockEvents) {
|
|
45
|
+
yield event;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const result = [];
|
|
49
|
+
for await (const event of handleEventStream(mockStream(), {
|
|
50
|
+
debug: true,
|
|
51
|
+
})) {
|
|
52
|
+
result.push(event);
|
|
53
|
+
}
|
|
54
|
+
expect(logSpy).toHaveBeenCalledWith("[StreamHandler] Event:", expect.objectContaining({ type: EventType.RUN_STARTED }));
|
|
55
|
+
logSpy.mockRestore();
|
|
56
|
+
process.env.NODE_ENV = originalEnv;
|
|
57
|
+
});
|
|
58
|
+
it("does not log when debug is false", async () => {
|
|
59
|
+
const logSpy = jest.spyOn(console, "log").mockImplementation(() => { });
|
|
60
|
+
async function* mockStream() {
|
|
61
|
+
yield { type: EventType.RUN_STARTED };
|
|
62
|
+
}
|
|
63
|
+
for await (const _event of handleEventStream(mockStream(), {
|
|
64
|
+
debug: false,
|
|
65
|
+
})) {
|
|
66
|
+
// consume stream
|
|
67
|
+
}
|
|
68
|
+
expect(logSpy).not.toHaveBeenCalled();
|
|
69
|
+
logSpy.mockRestore();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=stream-handler.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-handler.test.js","sourceRoot":"","sources":["../../../src/v1/utils/stream-handler.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;QAC7C,MAAM,UAAU,GAAG;YACjB,EAAE,IAAI,EAAE,SAAS,CAAC,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE;YACrE;gBACE,IAAI,EAAE,SAAS,CAAC,kBAAkB;gBAClC,SAAS,EAAE,OAAO;gBAClB,IAAI,EAAE,WAAW;aAClB;YACD,E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,EAAE,SAAS,CAAC,WAAW,EAAE,CAAC;QACxC,CAAC;QAED,IAAI,KAAK,EAAE,MAAM,MAAM,IAAI,iBAAiB,CAAC,UAAU,EAAE,EAAE;YACzD,KAAK,EAAE,KAAK;SACb,CAAC,EAAE,CAAC;YACH,iBAAiB;QACnB,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACtC,MAAM,CAAC,WAAW,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { EventType } from \"@ag-ui/core\";\nimport { handleEventStream } from \"./stream-handler\";\n\ndescribe(\"handleEventStream\", () => {\n it(\"yields events from the stream\", async () => {\n const mockEvents = [\n { type: EventType.RUN_STARTED, runId: \"run_1\", threadId: \"thread_1\" },\n {\n type: EventType.TEXT_MESSAGE_START,\n messageId: \"msg_1\",\n role: \"assistant\",\n },\n { type: EventType.RUN_FINISHED, runId: \"run_1\", threadId: \"thread_1\" },\n ];\n\n async function* mockStream() {\n for (const event of mockEvents) {\n yield event;\n }\n }\n\n const result: unknown[] = [];\n for await (const event of handleEventStream(mockStream())) {\n result.push(event);\n }\n\n expect(result).toHaveLength(3);\n expect(result[0]).toEqual(mockEvents[0]);\n expect(result[1]).toEqual(mockEvents[1]);\n expect(result[2]).toEqual(mockEvents[2]);\n });\n\n it(\"handles empty stream\", async () => {\n async function* emptyStream() {\n // yields nothing\n }\n\n const result: unknown[] = [];\n for await (const event of handleEventStream(emptyStream())) {\n result.push(event);\n }\n\n expect(result).toHaveLength(0);\n });\n\n it(\"logs events when debug is enabled in non-production\", async () => {\n const originalEnv = process.env.NODE_ENV;\n process.env.NODE_ENV = \"development\";\n const logSpy = jest.spyOn(console, \"log\").mockImplementation(() => {});\n\n const mockEvents = [{ type: EventType.RUN_STARTED, runId: \"run_1\" }];\n\n async function* mockStream() {\n for (const event of mockEvents) {\n yield event;\n }\n }\n\n const result: unknown[] = [];\n for await (const event of handleEventStream(mockStream(), {\n debug: true,\n })) {\n result.push(event);\n }\n\n expect(logSpy).toHaveBeenCalledWith(\n \"[StreamHandler] Event:\",\n expect.objectContaining({ type: EventType.RUN_STARTED }),\n );\n\n logSpy.mockRestore();\n process.env.NODE_ENV = originalEnv;\n });\n\n it(\"does not log when debug is false\", async () => {\n const logSpy = jest.spyOn(console, \"log\").mockImplementation(() => {});\n\n async function* mockStream() {\n yield { type: EventType.RUN_STARTED };\n }\n\n for await (const _event of handleEventStream(mockStream(), {\n debug: false,\n })) {\n // consume stream\n }\n\n expect(logSpy).not.toHaveBeenCalled();\n logSpy.mockRestore();\n });\n});\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Call Tracker for v1 API
|
|
3
|
+
*
|
|
4
|
+
* Tracks tool calls during streaming, accumulating arguments until complete.
|
|
5
|
+
* Used by the send message hook to collect tool call state for execution.
|
|
6
|
+
*/
|
|
7
|
+
import { type AGUIEvent } from "@ag-ui/core";
|
|
8
|
+
import type { PendingToolCall } from "./tool-executor";
|
|
9
|
+
/**
|
|
10
|
+
* Tracks tool calls during streaming, accumulating arguments until complete.
|
|
11
|
+
*
|
|
12
|
+
* Tool calls arrive as a sequence of events:
|
|
13
|
+
* 1. TOOL_CALL_START - initializes the tool call with name
|
|
14
|
+
* 2. TOOL_CALL_ARGS (multiple) - streams JSON argument fragments
|
|
15
|
+
* 3. TOOL_CALL_END - marks the tool call as complete, triggers JSON parsing
|
|
16
|
+
*
|
|
17
|
+
* This class accumulates these events and provides the complete tool call
|
|
18
|
+
* data when requested for execution.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ToolCallTracker {
|
|
21
|
+
private pendingToolCalls;
|
|
22
|
+
private accumulatingArgs;
|
|
23
|
+
/**
|
|
24
|
+
* Handles a streaming event, tracking tool call state as needed.
|
|
25
|
+
* @param event - The streaming event to process
|
|
26
|
+
* @throws {Error} If JSON parsing fails on TOOL_CALL_END (fail-fast, no silent fallback)
|
|
27
|
+
*/
|
|
28
|
+
handleEvent(event: AGUIEvent): void;
|
|
29
|
+
/**
|
|
30
|
+
* Gets tool calls for the given IDs, filtered to only those that exist.
|
|
31
|
+
* @param toolCallIds - IDs of tool calls to retrieve
|
|
32
|
+
* @returns Map of tool call ID to pending tool call
|
|
33
|
+
*/
|
|
34
|
+
getToolCallsById(toolCallIds: string[]): Map<string, PendingToolCall>;
|
|
35
|
+
/**
|
|
36
|
+
* Clears tracked tool calls for the given IDs.
|
|
37
|
+
* @param toolCallIds - IDs of tool calls to clear
|
|
38
|
+
*/
|
|
39
|
+
clearToolCalls(toolCallIds: string[]): void;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=tool-call-tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-call-tracker.d.ts","sourceRoot":"","sources":["../../../src/v1/utils/tool-call-tracker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,gBAAgB,CAAsC;IAC9D,OAAO,CAAC,gBAAgB,CAA6B;IAErD;;;;OAIG;IACH,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAyCnC;;;;OAIG;IACH,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC;IAWrE;;;OAGG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI;CAM5C"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Call Tracker for v1 API
|
|
3
|
+
*
|
|
4
|
+
* Tracks tool calls during streaming, accumulating arguments until complete.
|
|
5
|
+
* Used by the send message hook to collect tool call state for execution.
|
|
6
|
+
*/
|
|
7
|
+
import { EventType } from "@ag-ui/core";
|
|
8
|
+
/**
|
|
9
|
+
* Tracks tool calls during streaming, accumulating arguments until complete.
|
|
10
|
+
*
|
|
11
|
+
* Tool calls arrive as a sequence of events:
|
|
12
|
+
* 1. TOOL_CALL_START - initializes the tool call with name
|
|
13
|
+
* 2. TOOL_CALL_ARGS (multiple) - streams JSON argument fragments
|
|
14
|
+
* 3. TOOL_CALL_END - marks the tool call as complete, triggers JSON parsing
|
|
15
|
+
*
|
|
16
|
+
* This class accumulates these events and provides the complete tool call
|
|
17
|
+
* data when requested for execution.
|
|
18
|
+
*/
|
|
19
|
+
export class ToolCallTracker {
|
|
20
|
+
pendingToolCalls = new Map();
|
|
21
|
+
accumulatingArgs = new Map();
|
|
22
|
+
/**
|
|
23
|
+
* Handles a streaming event, tracking tool call state as needed.
|
|
24
|
+
* @param event - The streaming event to process
|
|
25
|
+
* @throws {Error} If JSON parsing fails on TOOL_CALL_END (fail-fast, no silent fallback)
|
|
26
|
+
*/
|
|
27
|
+
handleEvent(event) {
|
|
28
|
+
switch (event.type) {
|
|
29
|
+
case EventType.TOOL_CALL_START:
|
|
30
|
+
this.pendingToolCalls.set(event.toolCallId, {
|
|
31
|
+
name: event.toolCallName,
|
|
32
|
+
input: {},
|
|
33
|
+
});
|
|
34
|
+
this.accumulatingArgs.set(event.toolCallId, "");
|
|
35
|
+
break;
|
|
36
|
+
case EventType.TOOL_CALL_ARGS: {
|
|
37
|
+
const current = this.accumulatingArgs.get(event.toolCallId);
|
|
38
|
+
this.accumulatingArgs.set(event.toolCallId, (current ?? "") + event.delta);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
case EventType.TOOL_CALL_END: {
|
|
42
|
+
const jsonStr = this.accumulatingArgs.get(event.toolCallId);
|
|
43
|
+
const toolCall = this.pendingToolCalls.get(event.toolCallId);
|
|
44
|
+
if (toolCall && jsonStr) {
|
|
45
|
+
try {
|
|
46
|
+
toolCall.input = JSON.parse(jsonStr);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
// Fail-fast: don't silently continue with empty input
|
|
50
|
+
throw new Error(`Failed to parse tool call arguments for ${event.toolCallId}: ${error instanceof Error ? error.message : "Unknown error"}. JSON: ${jsonStr.slice(0, 100)}${jsonStr.length > 100 ? "..." : ""}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
default:
|
|
56
|
+
// Other event types are ignored - only tool call events are tracked
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Gets tool calls for the given IDs, filtered to only those that exist.
|
|
62
|
+
* @param toolCallIds - IDs of tool calls to retrieve
|
|
63
|
+
* @returns Map of tool call ID to pending tool call
|
|
64
|
+
*/
|
|
65
|
+
getToolCallsById(toolCallIds) {
|
|
66
|
+
const result = new Map();
|
|
67
|
+
for (const id of toolCallIds) {
|
|
68
|
+
const toolCall = this.pendingToolCalls.get(id);
|
|
69
|
+
if (toolCall) {
|
|
70
|
+
result.set(id, toolCall);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Clears tracked tool calls for the given IDs.
|
|
77
|
+
* @param toolCallIds - IDs of tool calls to clear
|
|
78
|
+
*/
|
|
79
|
+
clearToolCalls(toolCallIds) {
|
|
80
|
+
for (const id of toolCallIds) {
|
|
81
|
+
this.pendingToolCalls.delete(id);
|
|
82
|
+
this.accumulatingArgs.delete(id);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=tool-call-tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-call-tracker.js","sourceRoot":"","sources":["../../../src/v1/utils/tool-call-tracker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAA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C,OAAO,KAAK,EAAE,CAAC;wBACf,sDAAsD;wBACtD,MAAM,IAAI,KAAK,CACb,2CAA2C,KAAK,CAAC,UAAU,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,WAAW,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAC/L,CAAC;oBACJ,CAAC;gBACH,CAAC;gBACD,MAAM;YACR,CAAC;YAED;gBACE,oEAAoE;gBACpE,MAAM;QACV,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,WAAqB;QACpC,MAAM,MAAM,GAAG,IAAI,GAAG,EAA2B,CAAC;QAClD,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE,CAAC;YAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC/C,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;OAGG;IACH,cAAc,CAAC,WAAqB;QAClC,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE,CAAC;YAC7B,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACjC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;CACF","sourcesContent":["/**\n * Tool Call Tracker for v1 API\n *\n * Tracks tool calls during streaming, accumulating arguments until complete.\n * Used by the send message hook to collect tool call state for execution.\n */\n\nimport { EventType, type AGUIEvent } from \"@ag-ui/core\";\nimport type { PendingToolCall } from \"./tool-executor\";\n\n/**\n * Tracks tool calls during streaming, accumulating arguments until complete.\n *\n * Tool calls arrive as a sequence of events:\n * 1. TOOL_CALL_START - initializes the tool call with name\n * 2. TOOL_CALL_ARGS (multiple) - streams JSON argument fragments\n * 3. TOOL_CALL_END - marks the tool call as complete, triggers JSON parsing\n *\n * This class accumulates these events and provides the complete tool call\n * data when requested for execution.\n */\nexport class ToolCallTracker {\n private pendingToolCalls = new Map<string, PendingToolCall>();\n private accumulatingArgs = new Map<string, string>();\n\n /**\n * Handles a streaming event, tracking tool call state as needed.\n * @param event - The streaming event to process\n * @throws {Error} If JSON parsing fails on TOOL_CALL_END (fail-fast, no silent fallback)\n */\n handleEvent(event: AGUIEvent): void {\n switch (event.type) {\n case EventType.TOOL_CALL_START:\n this.pendingToolCalls.set(event.toolCallId, {\n name: event.toolCallName,\n input: {},\n });\n this.accumulatingArgs.set(event.toolCallId, \"\");\n break;\n\n case EventType.TOOL_CALL_ARGS: {\n const current = this.accumulatingArgs.get(event.toolCallId);\n this.accumulatingArgs.set(\n event.toolCallId,\n (current ?? \"\") + event.delta,\n );\n break;\n }\n\n case EventType.TOOL_CALL_END: {\n const jsonStr = this.accumulatingArgs.get(event.toolCallId);\n const toolCall = this.pendingToolCalls.get(event.toolCallId);\n if (toolCall && jsonStr) {\n try {\n toolCall.input = JSON.parse(jsonStr) as Record<string, unknown>;\n } catch (error) {\n // Fail-fast: don't silently continue with empty input\n throw new Error(\n `Failed to parse tool call arguments for ${event.toolCallId}: ${error instanceof Error ? error.message : \"Unknown error\"}. JSON: ${jsonStr.slice(0, 100)}${jsonStr.length > 100 ? \"...\" : \"\"}`,\n );\n }\n }\n break;\n }\n\n default:\n // Other event types are ignored - only tool call events are tracked\n break;\n }\n }\n\n /**\n * Gets tool calls for the given IDs, filtered to only those that exist.\n * @param toolCallIds - IDs of tool calls to retrieve\n * @returns Map of tool call ID to pending tool call\n */\n getToolCallsById(toolCallIds: string[]): Map<string, PendingToolCall> {\n const result = new Map<string, PendingToolCall>();\n for (const id of toolCallIds) {\n const toolCall = this.pendingToolCalls.get(id);\n if (toolCall) {\n result.set(id, toolCall);\n }\n }\n return result;\n }\n\n /**\n * Clears tracked tool calls for the given IDs.\n * @param toolCallIds - IDs of tool calls to clear\n */\n clearToolCalls(toolCallIds: string[]): void {\n for (const id of toolCallIds) {\n this.pendingToolCalls.delete(id);\n this.accumulatingArgs.delete(id);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Executor for v1 API
|
|
3
|
+
*
|
|
4
|
+
* Handles automatic execution of client-side tools when the model
|
|
5
|
+
* requests them via `tambo.run.awaiting_input` events.
|
|
6
|
+
*/
|
|
7
|
+
import type { TamboTool } from "../../model/component-metadata";
|
|
8
|
+
import type { ToolResultContent } from "@tambo-ai/typescript-sdk/resources/threads/threads";
|
|
9
|
+
/**
|
|
10
|
+
* Pending tool call from the stream accumulator
|
|
11
|
+
*/
|
|
12
|
+
export interface PendingToolCall {
|
|
13
|
+
name: string;
|
|
14
|
+
input: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Execute a single client-side tool and return the result.
|
|
18
|
+
* @param tool - The tool definition from the registry
|
|
19
|
+
* @param toolCallId - The ID of the tool call to respond to
|
|
20
|
+
* @param args - The parsed arguments for the tool
|
|
21
|
+
* @returns ToolResultContent with the execution result or error
|
|
22
|
+
*/
|
|
23
|
+
export declare function executeClientTool(tool: TamboTool, toolCallId: string, args: Record<string, unknown>): Promise<ToolResultContent>;
|
|
24
|
+
/**
|
|
25
|
+
* Execute all pending tool calls and return their results.
|
|
26
|
+
* Tools are executed sequentially to avoid race conditions when
|
|
27
|
+
* tools may have side effects that depend on each other.
|
|
28
|
+
* @param toolCalls - Map of tool call IDs to their call details
|
|
29
|
+
* @param registry - Registry of tool names to their definitions (Map or Record)
|
|
30
|
+
* @returns Array of ToolResultContent for all executed tools
|
|
31
|
+
*/
|
|
32
|
+
export declare function executeAllPendingTools(toolCalls: Map<string, PendingToolCall>, registry: Map<string, TamboTool> | Record<string, TamboTool>): Promise<ToolResultContent[]>;
|
|
33
|
+
//# sourceMappingURL=tool-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-executor.d.ts","sourceRoot":"","sources":["../../../src/v1/utils/tool-executor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,KAAK,EACV,iBAAiB,EAGlB,MAAM,oDAAoD,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,SAAS,EACf,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,iBAAiB,CAAC,CAgD5B;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,EACvC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAC3D,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAgC9B"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Executor for v1 API
|
|
3
|
+
*
|
|
4
|
+
* Handles automatic execution of client-side tools when the model
|
|
5
|
+
* requests them via `tambo.run.awaiting_input` events.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Execute a single client-side tool and return the result.
|
|
9
|
+
* @param tool - The tool definition from the registry
|
|
10
|
+
* @param toolCallId - The ID of the tool call to respond to
|
|
11
|
+
* @param args - The parsed arguments for the tool
|
|
12
|
+
* @returns ToolResultContent with the execution result or error
|
|
13
|
+
*/
|
|
14
|
+
export async function executeClientTool(tool, toolCallId, args) {
|
|
15
|
+
try {
|
|
16
|
+
const result = await tool.tool(args);
|
|
17
|
+
// Transform result to content if transformer provided
|
|
18
|
+
let content;
|
|
19
|
+
if (tool.transformToContent) {
|
|
20
|
+
// transformToContent may return content parts in beta format
|
|
21
|
+
// Convert to v1 format (TextContent | ResourceContent)
|
|
22
|
+
const transformed = await tool.transformToContent(result);
|
|
23
|
+
content = transformed.map((part) => {
|
|
24
|
+
if (part.type === "text" && "text" in part && part.text) {
|
|
25
|
+
return { type: "text", text: part.text };
|
|
26
|
+
}
|
|
27
|
+
// For other types, stringify as text
|
|
28
|
+
return {
|
|
29
|
+
type: "text",
|
|
30
|
+
text: JSON.stringify(part),
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// Default: stringify result as text
|
|
36
|
+
content = [
|
|
37
|
+
{
|
|
38
|
+
type: "text",
|
|
39
|
+
text: typeof result === "string" ? result : JSON.stringify(result),
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
type: "tool_result",
|
|
45
|
+
toolUseId: toolCallId,
|
|
46
|
+
content,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return {
|
|
51
|
+
type: "tool_result",
|
|
52
|
+
toolUseId: toolCallId,
|
|
53
|
+
content: [
|
|
54
|
+
{
|
|
55
|
+
type: "text",
|
|
56
|
+
text: error instanceof Error ? error.message : "Tool execution failed",
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Execute all pending tool calls and return their results.
|
|
64
|
+
* Tools are executed sequentially to avoid race conditions when
|
|
65
|
+
* tools may have side effects that depend on each other.
|
|
66
|
+
* @param toolCalls - Map of tool call IDs to their call details
|
|
67
|
+
* @param registry - Registry of tool names to their definitions (Map or Record)
|
|
68
|
+
* @returns Array of ToolResultContent for all executed tools
|
|
69
|
+
*/
|
|
70
|
+
export async function executeAllPendingTools(toolCalls, registry) {
|
|
71
|
+
const results = [];
|
|
72
|
+
// Normalize registry to allow lookup regardless of Map or Record
|
|
73
|
+
const getTool = (name) => {
|
|
74
|
+
if (registry instanceof Map) {
|
|
75
|
+
return registry.get(name);
|
|
76
|
+
}
|
|
77
|
+
return registry[name];
|
|
78
|
+
};
|
|
79
|
+
for (const [toolCallId, { name, input }] of toolCalls) {
|
|
80
|
+
const tool = getTool(name);
|
|
81
|
+
if (!tool) {
|
|
82
|
+
results.push({
|
|
83
|
+
type: "tool_result",
|
|
84
|
+
toolUseId: toolCallId,
|
|
85
|
+
content: [
|
|
86
|
+
{
|
|
87
|
+
type: "text",
|
|
88
|
+
text: `Tool "${name}" not found in registry`,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const result = await executeClientTool(tool, toolCallId, input);
|
|
95
|
+
results.push(result);
|
|
96
|
+
}
|
|
97
|
+
return results;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=tool-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-executor.js","sourceRoot":"","sources":["../../../src/v1/utils/tool-executor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiBH;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAe,EACf,UAAkB,EAClB,IAA6B;IAE7B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAErC,sDAAsD;QACtD,IAAI,OAA0C,CAAC;QAC/C,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,6DAA6D;YAC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;IAExC,iEAAiE;IACjE,MAAM,OAAO,GAAG,CAAC,IAAY,EAAyB,EAAE;QACtD,IAAI,QAAQ,YAAY,GAAG,EAAE,CAAC;YAC5B,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC,CAAC;IAEF,KAAK,MAAM,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,IAAI,SAAS,EAAE,CAAC;QACtD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,CAAC,IAAI,CAAC;gBACX,IAAI,EAAE,aAAa;gBACnB,SAAS,EAAE,UAAU;gBACrB,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,SAAS,IAAI,yBAAyB;qBAC7C;iBACF;aACF,CAAC,CAAC;YACH,SAAS;QACX,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["/**\n * Tool Executor for v1 API\n *\n * Handles automatic execution of client-side tools when the model\n * requests them via `tambo.run.awaiting_input` events.\n */\n\nimport type { TamboTool } from \"../../model/component-metadata\";\nimport type {\n ToolResultContent,\n TextContent,\n ResourceContent,\n} from \"@tambo-ai/typescript-sdk/resources/threads/threads\";\n\n/**\n * Pending tool call from the stream accumulator\n */\nexport interface PendingToolCall {\n name: string;\n input: Record<string, unknown>;\n}\n\n/**\n * Execute a single client-side tool and return the result.\n * @param tool - The tool definition from the registry\n * @param toolCallId - The ID of the tool call to respond to\n * @param args - The parsed arguments for the tool\n * @returns ToolResultContent with the execution result or error\n */\nexport async function executeClientTool(\n tool: TamboTool,\n toolCallId: string,\n args: Record<string, unknown>,\n): Promise<ToolResultContent> {\n try {\n const result = await tool.tool(args);\n\n // Transform result to content if transformer provided\n let content: (TextContent | ResourceContent)[];\n if (tool.transformToContent) {\n // transformToContent may return content parts in beta format\n // Convert to v1 format (TextContent | ResourceContent)\n const transformed = await tool.transformToContent(result);\n content = transformed.map((part) => {\n if (part.type === \"text\" && \"text\" in part && part.text) {\n return { type: \"text\" as const, text: part.text };\n }\n // For other types, stringify as text\n return {\n type: \"text\" as const,\n text: JSON.stringify(part),\n };\n });\n } else {\n // Default: stringify result as text\n content = [\n {\n type: \"text\" as const,\n text: typeof result === \"string\" ? result : JSON.stringify(result),\n },\n ];\n }\n\n return {\n type: \"tool_result\",\n toolUseId: toolCallId,\n content,\n };\n } catch (error) {\n return {\n type: \"tool_result\",\n toolUseId: toolCallId,\n content: [\n {\n type: \"text\" as const,\n text:\n error instanceof Error ? error.message : \"Tool execution failed\",\n },\n ],\n };\n }\n}\n\n/**\n * Execute all pending tool calls and return their results.\n * Tools are executed sequentially to avoid race conditions when\n * tools may have side effects that depend on each other.\n * @param toolCalls - Map of tool call IDs to their call details\n * @param registry - Registry of tool names to their definitions (Map or Record)\n * @returns Array of ToolResultContent for all executed tools\n */\nexport async function executeAllPendingTools(\n toolCalls: Map<string, PendingToolCall>,\n registry: Map<string, TamboTool> | Record<string, TamboTool>,\n): Promise<ToolResultContent[]> {\n const results: ToolResultContent[] = [];\n\n // Normalize registry to allow lookup regardless of Map or Record\n const getTool = (name: string): TamboTool | undefined => {\n if (registry instanceof Map) {\n return registry.get(name);\n }\n return registry[name];\n };\n\n for (const [toolCallId, { name, input }] of toolCalls) {\n const tool = getTool(name);\n if (!tool) {\n results.push({\n type: \"tool_result\",\n toolUseId: toolCallId,\n content: [\n {\n type: \"text\" as const,\n text: `Tool \"${name}\" not found in registry`,\n },\n ],\n });\n continue;\n }\n\n const result = await executeClientTool(tool, toolCallId, input);\n results.push(result);\n }\n\n return results;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-executor.test.d.ts","sourceRoot":"","sources":["../../../src/v1/utils/tool-executor.test.ts"],"names":[],"mappings":""}
|