@tambo-ai/react 0.73.0 → 0.74.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 +12 -12
- package/dist/hooks/use-component-state.d.ts +1 -1
- package/dist/hooks/use-component-state.js.map +1 -1
- package/dist/hooks/use-streaming-props.d.ts +1 -1
- package/dist/hooks/use-streaming-props.js +1 -1
- package/dist/hooks/use-streaming-props.js.map +1 -1
- package/dist/hooks/use-tambo-stream-status.d.ts +1 -1
- package/dist/hooks/use-tambo-stream-status.js +1 -1
- package/dist/hooks/use-tambo-stream-status.js.map +1 -1
- package/dist/mcp/mcp-hooks.d.ts +4 -0
- package/dist/mcp/mcp-hooks.d.ts.map +1 -1
- package/dist/mcp/mcp-hooks.js +4 -0
- package/dist/mcp/mcp-hooks.js.map +1 -1
- package/dist/providers/tambo-interactable-provider-partial-updates.test.js +3 -3
- package/dist/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.js +2 -2
- package/dist/providers/tambo-interactable-provider.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.test.js +3 -3
- package/dist/providers/tambo-interactable-provider.test.js.map +1 -1
- package/dist/providers/tambo-provider.d.ts +3 -0
- package/dist/providers/tambo-provider.d.ts.map +1 -1
- package/dist/providers/tambo-provider.js +3 -0
- package/dist/providers/tambo-provider.js.map +1 -1
- package/dist/providers/tambo-thread-input-provider.d.ts.map +1 -1
- package/dist/providers/tambo-thread-input-provider.js +1 -0
- package/dist/providers/tambo-thread-input-provider.js.map +1 -1
- package/dist/util/resource-content-resolver.d.ts.map +1 -1
- package/dist/util/resource-content-resolver.js +2 -0
- package/dist/util/resource-content-resolver.js.map +1 -1
- package/dist/v1/__tests__/v1-interactables.test.d.ts +2 -0
- package/dist/v1/__tests__/v1-interactables.test.d.ts.map +1 -0
- package/dist/v1/__tests__/v1-interactables.test.js +135 -0
- package/dist/v1/__tests__/v1-interactables.test.js.map +1 -0
- package/dist/v1/components/v1-component-renderer.d.ts +48 -0
- package/dist/v1/components/v1-component-renderer.d.ts.map +1 -0
- package/dist/v1/components/v1-component-renderer.js +137 -0
- package/dist/v1/components/v1-component-renderer.js.map +1 -0
- package/dist/v1/components/v1-component-renderer.test.d.ts +2 -0
- package/dist/v1/components/v1-component-renderer.test.d.ts.map +1 -0
- package/dist/v1/components/v1-component-renderer.test.js +270 -0
- package/dist/v1/components/v1-component-renderer.test.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-component-state.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-component-state.js +2 -25
- package/dist/v1/hooks/use-tambo-v1-component-state.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-component-state.test.js +2 -1
- package/dist/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-messages.test.js +25 -1
- package/dist/v1/hooks/use-tambo-v1-messages.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.d.ts +18 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.js +204 -17
- package/dist/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.test.js +261 -7
- package/dist/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-stream-status.d.ts +90 -0
- package/dist/v1/hooks/use-tambo-v1-stream-status.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-stream-status.js +179 -0
- package/dist/v1/hooks/use-tambo-v1-stream-status.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-stream-status.test.d.ts +2 -0
- package/dist/v1/hooks/use-tambo-v1-stream-status.test.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-stream-status.test.js +371 -0
- package/dist/v1/hooks/use-tambo-v1-stream-status.test.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.d.ts +78 -54
- package/dist/v1/hooks/use-tambo-v1-suggestions.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-suggestions.js +153 -87
- package/dist/v1/hooks/use-tambo-v1-suggestions.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-suggestions.test.js +213 -134
- package/dist/v1/hooks/use-tambo-v1-suggestions.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-input.test.js +148 -13
- package/dist/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-list.d.ts +8 -21
- package/dist/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-list.js +11 -10
- package/dist/v1/hooks/use-tambo-v1-thread-list.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.js +37 -2
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread.d.ts +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread.js +2 -7
- package/dist/v1/hooks/use-tambo-v1-thread.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread.test.js +2 -0
- package/dist/v1/hooks/use-tambo-v1-thread.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1.d.ts +12 -28
- package/dist/v1/hooks/use-tambo-v1.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1.js +164 -31
- package/dist/v1/hooks/use-tambo-v1.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1.test.js +891 -18
- package/dist/v1/hooks/use-tambo-v1.test.js.map +1 -1
- package/dist/v1/index.d.ts +7 -1
- package/dist/v1/index.d.ts.map +1 -1
- package/dist/v1/index.js +18 -1
- package/dist/v1/index.js.map +1 -1
- package/dist/v1/providers/tambo-v1-provider.d.ts +16 -6
- package/dist/v1/providers/tambo-v1-provider.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-provider.js +14 -19
- package/dist/v1/providers/tambo-v1-provider.js.map +1 -1
- package/dist/v1/providers/tambo-v1-provider.test.js +34 -20
- package/dist/v1/providers/tambo-v1-provider.test.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stream-context.d.ts +3 -3
- package/dist/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-stream-context.js +60 -12
- package/dist/v1/providers/tambo-v1-stream-context.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stream-context.test.js +49 -20
- package/dist/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-stub-provider.js +2 -0
- package/dist/v1/providers/tambo-v1-stub-provider.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stub-provider.test.js +7 -6
- package/dist/v1/providers/tambo-v1-stub-provider.test.js.map +1 -1
- package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts +1 -6
- package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-thread-input-provider.js +14 -12
- package/dist/v1/providers/tambo-v1-thread-input-provider.js.map +1 -1
- package/dist/v1/types/event.d.ts +9 -1
- package/dist/v1/types/event.d.ts.map +1 -1
- package/dist/v1/types/event.js.map +1 -1
- package/dist/v1/types/event.test.js +5 -1
- package/dist/v1/types/event.test.js.map +1 -1
- package/dist/v1/types/message.d.ts +65 -7
- package/dist/v1/types/message.d.ts.map +1 -1
- package/dist/v1/types/message.js.map +1 -1
- package/dist/v1/types/thread.d.ts +4 -0
- package/dist/v1/types/thread.d.ts.map +1 -1
- package/dist/v1/types/thread.js.map +1 -1
- package/dist/v1/utils/event-accumulator.d.ts +40 -4
- package/dist/v1/utils/event-accumulator.d.ts.map +1 -1
- package/dist/v1/utils/event-accumulator.js +444 -35
- package/dist/v1/utils/event-accumulator.js.map +1 -1
- package/dist/v1/utils/event-accumulator.test.js +1041 -28
- package/dist/v1/utils/event-accumulator.test.js.map +1 -1
- package/dist/v1/utils/registry-conversion.d.ts +9 -9
- package/dist/v1/utils/registry-conversion.d.ts.map +1 -1
- package/dist/v1/utils/registry-conversion.js +10 -11
- package/dist/v1/utils/registry-conversion.js.map +1 -1
- package/dist/v1/utils/registry-conversion.test.js +39 -11
- package/dist/v1/utils/registry-conversion.test.js.map +1 -1
- package/dist/v1/utils/thread-utils.d.ts +16 -0
- package/dist/v1/utils/thread-utils.d.ts.map +1 -0
- package/dist/v1/utils/thread-utils.js +34 -0
- package/dist/v1/utils/thread-utils.js.map +1 -0
- package/dist/v1/utils/tool-executor.d.ts.map +1 -1
- package/dist/v1/utils/tool-executor.js +2 -0
- package/dist/v1/utils/tool-executor.js.map +1 -1
- package/dist/v1/utils/tool-executor.test.js +5 -0
- package/dist/v1/utils/tool-executor.test.js.map +1 -1
- package/esm/context-helpers/context-helpers-provider.test.js +2 -2
- package/esm/context-helpers/context-helpers.test.js +1 -1
- package/esm/context-helpers/current-interactables-context-helper.d.ts +1 -1
- package/esm/context-helpers/current-page-context-helper.d.ts +1 -1
- package/esm/context-helpers/current-time-context-helper.d.ts +1 -1
- package/esm/context-helpers/index.d.ts +4 -4
- package/esm/context-helpers/index.js +4 -4
- package/esm/hoc/with-tambo-interactable.d.ts +1 -1
- package/esm/hoc/with-tambo-interactable.js +2 -2
- package/esm/hoc/with-tambo-interactable.test.js +3 -3
- package/esm/hooks/index.d.ts +8 -8
- package/esm/hooks/index.js +8 -8
- package/esm/hooks/react-query-hooks.js +1 -1
- package/esm/hooks/use-component-state.d.ts +1 -1
- package/esm/hooks/use-component-state.js +3 -3
- package/esm/hooks/use-component-state.js.map +1 -1
- package/esm/hooks/use-component-state.test.js +5 -5
- package/esm/hooks/use-current-message.d.ts +1 -1
- package/esm/hooks/use-current-message.test.js +1 -1
- package/esm/hooks/use-message-images.test.js +1 -1
- package/esm/hooks/use-streaming-props.d.ts +1 -1
- package/esm/hooks/use-streaming-props.js +1 -1
- package/esm/hooks/use-streaming-props.js.map +1 -1
- package/esm/hooks/use-suggestions.d.ts +2 -2
- package/esm/hooks/use-suggestions.js +10 -10
- package/esm/hooks/use-suggestions.test.js +7 -7
- package/esm/hooks/use-tambo-stream-status.d.ts +1 -1
- package/esm/hooks/use-tambo-stream-status.js +4 -4
- package/esm/hooks/use-tambo-stream-status.js.map +1 -1
- package/esm/hooks/use-tambo-stream-status.test.js +4 -4
- package/esm/hooks/use-tambo-threads.js +3 -3
- package/esm/hooks/use-tambo-threads.test.js +3 -3
- package/esm/hooks/use-tambo-voice.js +2 -2
- package/esm/hooks/use-tambo-voice.test.js +3 -3
- package/esm/index.d.ts +22 -22
- package/esm/index.js +15 -15
- package/esm/mcp/elicitation.d.ts +1 -1
- package/esm/mcp/elicitation.test.js +1 -1
- package/esm/mcp/index.d.ts +7 -7
- package/esm/mcp/index.js +3 -3
- package/esm/mcp/mcp-client.d.ts +1 -1
- package/esm/mcp/mcp-client.js +1 -1
- package/esm/mcp/mcp-client.test.js +1 -1
- package/esm/mcp/mcp-hooks.d.ts +5 -1
- package/esm/mcp/mcp-hooks.d.ts.map +1 -1
- package/esm/mcp/mcp-hooks.js +8 -4
- package/esm/mcp/mcp-hooks.js.map +1 -1
- package/esm/mcp/mcp-hooks.test.js +6 -6
- package/esm/mcp/tambo-mcp-provider.d.ts +4 -4
- package/esm/mcp/tambo-mcp-provider.js +7 -7
- package/esm/mcp/tambo-mcp-provider.test.js +5 -5
- package/esm/mcp/use-mcp-servers.test.js +4 -4
- package/esm/model/generate-component-response.d.ts +1 -1
- package/esm/model/tambo-interactable.d.ts +1 -1
- package/esm/model/tambo-thread.d.ts +1 -1
- package/esm/providers/__tests__/thread-input-resource-resolution.test.js +3 -3
- package/esm/providers/hooks/use-tambo-session-token.test.js +1 -1
- package/esm/providers/index.d.ts +12 -12
- package/esm/providers/index.js +10 -10
- package/esm/providers/tambo-client-provider.js +1 -1
- package/esm/providers/tambo-client-provider.test.js +2 -2
- package/esm/providers/tambo-component-provider.d.ts +1 -1
- package/esm/providers/tambo-component-provider.js +2 -2
- package/esm/providers/tambo-context-attachment-provider.js +1 -1
- package/esm/providers/tambo-context-attachment-provider.test.js +2 -2
- package/esm/providers/tambo-context-helpers-provider.d.ts +1 -1
- package/esm/providers/tambo-context-helpers-provider.js +1 -1
- package/esm/providers/tambo-context-helpers-provider.test.js +2 -2
- package/esm/providers/tambo-interactable-provider-partial-updates.test.js +4 -4
- package/esm/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.d.ts +5 -5
- package/esm/providers/tambo-interactable-provider.js +6 -6
- package/esm/providers/tambo-interactable-provider.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.test.js +4 -4
- package/esm/providers/tambo-interactable-provider.test.js.map +1 -1
- package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js +4 -4
- package/esm/providers/tambo-interactables-additional-context.test.js +4 -4
- package/esm/providers/tambo-mcp-token-provider.js +2 -2
- package/esm/providers/tambo-prop-stream-provider/index.d.ts +8 -8
- package/esm/providers/tambo-prop-stream-provider/index.js +9 -9
- package/esm/providers/tambo-prop-stream-provider/pending.d.ts +1 -1
- package/esm/providers/tambo-prop-stream-provider/pending.js +2 -2
- package/esm/providers/tambo-prop-stream-provider/provider.d.ts +1 -1
- package/esm/providers/tambo-prop-stream-provider/provider.js +2 -2
- package/esm/providers/tambo-prop-stream-provider/streaming.d.ts +1 -1
- package/esm/providers/tambo-prop-stream-provider/streaming.js +2 -2
- package/esm/providers/tambo-prop-stream-provider/success.d.ts +1 -1
- package/esm/providers/tambo-prop-stream-provider/success.js +2 -2
- package/esm/providers/tambo-prop-stream-provider/types.d.ts +1 -1
- package/esm/providers/tambo-prop-stream-provider.test.js +4 -4
- package/esm/providers/tambo-provider.d.ts +10 -7
- package/esm/providers/tambo-provider.d.ts.map +1 -1
- package/esm/providers/tambo-provider.js +13 -10
- package/esm/providers/tambo-provider.js.map +1 -1
- package/esm/providers/tambo-registry-provider.d.ts +3 -3
- package/esm/providers/tambo-registry-provider.js +3 -3
- package/esm/providers/tambo-registry-provider.test.js +2 -2
- package/esm/providers/tambo-registry-schema-compat.test.js +2 -2
- package/esm/providers/tambo-stubs.d.ts +4 -4
- package/esm/providers/tambo-stubs.js +9 -9
- package/esm/providers/tambo-stubs.test.js +2 -2
- package/esm/providers/tambo-thread-input-provider.d.ts +2 -2
- package/esm/providers/tambo-thread-input-provider.d.ts.map +1 -1
- package/esm/providers/tambo-thread-input-provider.js +11 -10
- package/esm/providers/tambo-thread-input-provider.js.map +1 -1
- package/esm/providers/tambo-thread-provider-initial-messages.test.js +6 -6
- package/esm/providers/tambo-thread-provider.d.ts +2 -2
- package/esm/providers/tambo-thread-provider.js +8 -8
- package/esm/providers/tambo-thread-provider.test.js +7 -7
- package/esm/schema/index.d.ts +4 -4
- package/esm/schema/index.js +4 -4
- package/esm/schema/json-schema.test.js +1 -1
- package/esm/schema/schema.d.ts +1 -1
- package/esm/schema/schema.js +2 -2
- package/esm/schema/schema.test.js +3 -3
- package/esm/schema/standard-schema.test.js +1 -1
- package/esm/schema/validate.js +2 -2
- package/esm/schema/validate.test.js +1 -1
- package/esm/testing/tools.d.ts +3 -3
- package/esm/testing/tools.js +2 -2
- package/esm/util/content-parts.test.js +1 -1
- package/esm/util/generate-component.d.ts +2 -2
- package/esm/util/generate-component.js +4 -4
- package/esm/util/generate-component.test.js +2 -2
- package/esm/util/is-promise.test.js +1 -1
- package/esm/util/mcp-server-utils.d.ts +1 -1
- package/esm/util/mcp-server-utils.js +1 -1
- package/esm/util/mcp-server-utils.test.js +2 -2
- package/esm/util/message-builder.d.ts +1 -1
- package/esm/util/message-builder.test.js +1 -1
- package/esm/util/query-utils.test.js +1 -1
- package/esm/util/registry-validators.d.ts +1 -1
- package/esm/util/registry-validators.js +2 -2
- package/esm/util/registry-validators.test.js +1 -1
- package/esm/util/registry.d.ts +1 -1
- package/esm/util/registry.js +1 -1
- package/esm/util/registry.test.js +2 -2
- package/esm/util/resource-content-resolver.d.ts +2 -2
- package/esm/util/resource-content-resolver.d.ts.map +1 -1
- package/esm/util/resource-content-resolver.js +3 -1
- package/esm/util/resource-content-resolver.js.map +1 -1
- package/esm/util/resource-content-resolver.test.js +3 -3
- package/esm/util/resource-validators.d.ts +1 -1
- package/esm/util/resource-validators.test.js +1 -1
- package/esm/util/tool-caller.d.ts +1 -1
- package/esm/util/tool-caller.js +1 -1
- package/esm/util/validate-component-name.test.js +1 -1
- package/esm/v1/__tests__/v1-interactables.test.d.ts +2 -0
- package/esm/v1/__tests__/v1-interactables.test.d.ts.map +1 -0
- package/esm/v1/__tests__/v1-interactables.test.js +130 -0
- package/esm/v1/__tests__/v1-interactables.test.js.map +1 -0
- package/esm/v1/components/v1-component-renderer.d.ts +48 -0
- package/esm/v1/components/v1-component-renderer.d.ts.map +1 -0
- package/esm/v1/components/v1-component-renderer.js +100 -0
- package/esm/v1/components/v1-component-renderer.js.map +1 -0
- package/esm/v1/components/v1-component-renderer.test.d.ts +2 -0
- package/esm/v1/components/v1-component-renderer.test.d.ts.map +1 -0
- package/esm/v1/components/v1-component-renderer.test.js +265 -0
- package/esm/v1/components/v1-component-renderer.test.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-component-state.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-component-state.js +4 -27
- package/esm/v1/hooks/use-tambo-v1-component-state.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-component-state.test.js +6 -5
- package/esm/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-messages.d.ts +1 -1
- package/esm/v1/hooks/use-tambo-v1-messages.js +1 -1
- package/esm/v1/hooks/use-tambo-v1-messages.test.js +27 -3
- package/esm/v1/hooks/use-tambo-v1-messages.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.d.ts +20 -2
- package/esm/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.js +213 -26
- package/esm/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.test.js +266 -12
- package/esm/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-stream-status.d.ts +90 -0
- package/esm/v1/hooks/use-tambo-v1-stream-status.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-stream-status.js +176 -0
- package/esm/v1/hooks/use-tambo-v1-stream-status.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-stream-status.test.d.ts +2 -0
- package/esm/v1/hooks/use-tambo-v1-stream-status.test.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-stream-status.test.js +369 -0
- package/esm/v1/hooks/use-tambo-v1-stream-status.test.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.d.ts +78 -54
- package/esm/v1/hooks/use-tambo-v1-suggestions.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-suggestions.js +157 -91
- package/esm/v1/hooks/use-tambo-v1-suggestions.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-suggestions.test.js +218 -139
- package/esm/v1/hooks/use-tambo-v1-suggestions.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-input.d.ts +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-input.js +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-input.test.js +151 -16
- package/esm/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-list.d.ts +8 -21
- package/esm/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-list.js +12 -11
- package/esm/v1/hooks/use-tambo-v1-thread-list.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.js +39 -4
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread.d.ts +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread.js +3 -8
- package/esm/v1/hooks/use-tambo-v1-thread.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread.test.js +4 -2
- package/esm/v1/hooks/use-tambo-v1-thread.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1.d.ts +15 -31
- package/esm/v1/hooks/use-tambo-v1.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1.js +134 -34
- package/esm/v1/hooks/use-tambo-v1.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1.test.js +862 -19
- package/esm/v1/hooks/use-tambo-v1.test.js.map +1 -1
- package/esm/v1/index.d.ts +28 -22
- package/esm/v1/index.d.ts.map +1 -1
- package/esm/v1/index.js +30 -18
- package/esm/v1/index.js.map +1 -1
- package/esm/v1/providers/tambo-v1-provider.d.ts +21 -11
- package/esm/v1/providers/tambo-v1-provider.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-provider.js +20 -25
- package/esm/v1/providers/tambo-v1-provider.js.map +1 -1
- package/esm/v1/providers/tambo-v1-provider.test.js +40 -26
- package/esm/v1/providers/tambo-v1-provider.test.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.d.ts +4 -4
- package/esm/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.js +62 -14
- package/esm/v1/providers/tambo-v1-stream-context.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.test.js +50 -21
- package/esm/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stub-provider.d.ts +3 -3
- package/esm/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-stub-provider.js +7 -5
- package/esm/v1/providers/tambo-v1-stub-provider.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stub-provider.test.js +12 -11
- package/esm/v1/providers/tambo-v1-stub-provider.test.js.map +1 -1
- package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts +3 -8
- package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-thread-input-provider.js +18 -16
- package/esm/v1/providers/tambo-v1-thread-input-provider.js.map +1 -1
- package/esm/v1/types/event.d.ts +9 -1
- package/esm/v1/types/event.d.ts.map +1 -1
- package/esm/v1/types/event.js.map +1 -1
- package/esm/v1/types/event.test.js +6 -2
- package/esm/v1/types/event.test.js.map +1 -1
- package/esm/v1/types/message.d.ts +65 -7
- package/esm/v1/types/message.d.ts.map +1 -1
- package/esm/v1/types/message.js.map +1 -1
- package/esm/v1/types/thread.d.ts +5 -1
- package/esm/v1/types/thread.d.ts.map +1 -1
- package/esm/v1/types/thread.js.map +1 -1
- package/esm/v1/utils/component-renderer.test.js +1 -1
- package/esm/v1/utils/event-accumulator.d.ts +41 -5
- package/esm/v1/utils/event-accumulator.d.ts.map +1 -1
- package/esm/v1/utils/event-accumulator.js +444 -36
- package/esm/v1/utils/event-accumulator.js.map +1 -1
- package/esm/v1/utils/event-accumulator.test.js +1042 -29
- package/esm/v1/utils/event-accumulator.test.js.map +1 -1
- package/esm/v1/utils/json-patch.test.js +1 -1
- package/esm/v1/utils/registry-conversion.d.ts +9 -9
- package/esm/v1/utils/registry-conversion.d.ts.map +1 -1
- package/esm/v1/utils/registry-conversion.js +11 -12
- package/esm/v1/utils/registry-conversion.js.map +1 -1
- package/esm/v1/utils/registry-conversion.test.js +40 -12
- package/esm/v1/utils/registry-conversion.test.js.map +1 -1
- package/esm/v1/utils/stream-handler.test.js +1 -1
- package/esm/v1/utils/thread-utils.d.ts +16 -0
- package/esm/v1/utils/thread-utils.d.ts.map +1 -0
- package/esm/v1/utils/thread-utils.js +31 -0
- package/esm/v1/utils/thread-utils.js.map +1 -0
- package/esm/v1/utils/tool-call-tracker.d.ts +1 -1
- package/esm/v1/utils/tool-executor.d.ts +1 -1
- package/esm/v1/utils/tool-executor.d.ts.map +1 -1
- package/esm/v1/utils/tool-executor.js +2 -0
- package/esm/v1/utils/tool-executor.js.map +1 -1
- package/esm/v1/utils/tool-executor.test.js +6 -1
- package/esm/v1/utils/tool-executor.test.js.map +1 -1
- package/package.json +11 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-v1-messages.test.js","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1-messages.test.tsx"],"names":[],"mappings":";;;;;AAAA,sCAKqB;AACrB,kDAAyD;AACzD,kDAA0B;AAC1B,kFAG8C;AAC9C,mEAA6D;AAE7D,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,SAAS,WAAW,CAAC,EAAE,QAAQ,EAAiC;QAC9D,OAAO,8BAAC,+CAAqB,QAAE,QAAQ,CAAyB,CAAC;IACnE,CAAC;IAED,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;QAC5D,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,kBAAU,EAC3B,GAAG,EAAE,CAAC,CAAC;YACL,QAAQ,EAAE,IAAA,0CAAkB,EAAC,YAAY,CAAC;YAC1C,QAAQ,EAAE,IAAA,2CAAiB,GAAE;SAC9B,CAAC,EACF,EAAE,OAAO,EAAE,WAAW,EAAE,CACzB,CAAC;QAEF,0BAA0B;QAC1B,IAAA,WAAG,EAAC,GAAG,EAAE;YACP,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,CAAC;QAC3E,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACrD,MAAM,CAAC,MAAM,CAAC,OAAO,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AC;IACxE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kEAAkE,EAAE,GAAG,EAAE;QAC1E,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,kBAAU,EAC3B,GAAG,EAAE,CAAC,IAAA,0CAAkB,EAAC,oBAAoB,CAAC,EAC9C;YACE,OAAO,EAAE,WAAW;SACrB,CACF,CAAC;QAEF,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC5C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import {\n EventType,\n type TextMessageStartEvent,\n type TextMessageContentEvent,\n type TextMessageEndEvent,\n} from \"@ag-ui/core\";\nimport { renderHook, act } from \"@testing-library/react\";\nimport React from \"react\";\nimport {\n TamboV1StreamProvider,\n useStreamDispatch,\n} from \"../providers/tambo-v1-stream-context\";\nimport { useTamboV1Messages } from \"./use-tambo-v1-messages\";\n\ndescribe(\"useTamboV1Messages\", () => {\n function TestWrapper({ children }: { children: React.ReactNode }) {\n return <TamboV1StreamProvider>{children}</TamboV1StreamProvider>;\n }\n\n it(\"returns empty messages when thread has no messages\", () => {\n const { result } = renderHook(\n () => ({\n messages: useTamboV1Messages(\"thread_123\"),\n dispatch: useStreamDispatch(),\n }),\n { wrapper: TestWrapper },\n );\n\n // Initialize thread first\n act(() => {\n result.current.dispatch({ type: \"INIT_THREAD\", threadId: \"thread_123\" });\n });\n\n expect(result.current.messages.messages).toEqual([]);\n expect(result.current.messages.hasMessages).toBe(false);\n expect(result.current.messages.messageCount).toBe(0);\n expect(result.current.messages.lastMessage).toBeUndefined();\n expect(result.current.messages.userMessages).toEqual([]);\n expect(result.current.messages.assistantMessages).toEqual([]);\n });\n\n it(\"returns messages after events are dispatched\", () => {\n const { result } = renderHook(\n () => ({\n messages: useTamboV1Messages(\"thread_123\"),\n dispatch: useStreamDispatch(),\n }),\n { wrapper: TestWrapper },\n );\n\n // Initialize thread first\n act(() => {\n result.current.dispatch({ type: \"INIT_THREAD\", threadId: \"thread_123\" });\n });\n\n // Simulate a text message being received\n act(() => {\n result.current.dispatch({\n type: \"EVENT\",\n event: {\n type: EventType.TEXT_MESSAGE_START,\n messageId: \"msg_1\",\n role: \"assistant\",\n } as TextMessageStartEvent,\n threadId: \"thread_123\",\n });\n });\n\n act(() => {\n result.current.dispatch({\n type: \"EVENT\",\n event: {\n type: EventType.TEXT_MESSAGE_CONTENT,\n messageId: \"msg_1\",\n delta: \"Hello\",\n } as TextMessageContentEvent,\n threadId: \"thread_123\",\n });\n });\n\n act(() => {\n result.current.dispatch({\n type: \"EVENT\",\n event: {\n type: EventType.TEXT_MESSAGE_END,\n messageId: \"msg_1\",\n } as TextMessageEndEvent,\n threadId: \"thread_123\",\n });\n });\n\n expect(result.current.messages.messages.length).toBe(1);\n expect(result.current.messages.hasMessages).toBe(true);\n expect(result.current.messages.messageCount).toBe(1);\n expect(result.current.messages.lastMessage?.id).toBe(\"msg_1\");\n expect(result.current.messages.lastMessage?.role).toBe(\"assistant\");\n expect(result.current.messages.assistantMessages.length).toBe(1);\n expect(result.current.messages.userMessages.length).toBe(0);\n });\n\n it(\"filters user and assistant messages correctly\", () => {\n const { result } = renderHook(\n () => ({\n messages: useTamboV1Messages(\"thread_123\"),\n dispatch: useStreamDispatch(),\n }),\n { wrapper: TestWrapper },\n );\n\n // Initialize thread first\n act(() => {\n result.current.dispatch({ type: \"INIT_THREAD\", threadId: \"thread_123\" });\n });\n\n // Add user message\n act(() => {\n result.current.dispatch({\n type: \"EVENT\",\n event: {\n type: EventType.TEXT_MESSAGE_START,\n messageId: \"msg_user\",\n role: \"user\",\n } as TextMessageStartEvent,\n threadId: \"thread_123\",\n });\n });\n\n act(() => {\n result.current.dispatch({\n type: \"EVENT\",\n event: {\n type: EventType.TEXT_MESSAGE_END,\n messageId: \"msg_user\",\n } as TextMessageEndEvent,\n threadId: \"thread_123\",\n });\n });\n\n // Add assistant message\n act(() => {\n result.current.dispatch({\n type: \"EVENT\",\n event: {\n type: EventType.TEXT_MESSAGE_START,\n messageId: \"msg_assistant\",\n role: \"assistant\",\n } as TextMessageStartEvent,\n threadId: \"thread_123\",\n });\n });\n\n act(() => {\n result.current.dispatch({\n type: \"EVENT\",\n event: {\n type: EventType.TEXT_MESSAGE_END,\n messageId: \"msg_assistant\",\n } as TextMessageEndEvent,\n threadId: \"thread_123\",\n });\n });\n\n expect(result.current.messages.messageCount).toBe(2);\n expect(result.current.messages.userMessages.length).toBe(1);\n expect(result.current.messages.userMessages[0].id).toBe(\"msg_user\");\n expect(result.current.messages.assistantMessages.length).toBe(1);\n expect(result.current.messages.assistantMessages[0].id).toBe(\n \"msg_assistant\",\n );\n expect(result.current.messages.lastMessage?.id).toBe(\"msg_assistant\");\n });\n\n it(\"returns empty messages when threadId does not exist in threadMap\", () => {\n const { result } = renderHook(\n () => useTamboV1Messages(\"nonexistent_thread\"),\n {\n wrapper: TestWrapper,\n },\n );\n\n expect(result.current.messages).toEqual([]);\n expect(result.current.hasMessages).toBe(false);\n expect(result.current.messageCount).toBe(0);\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"use-tambo-v1-messages.test.js","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1-messages.test.tsx"],"names":[],"mappings":";;;;;AAAA,sCAKqB;AACrB,uDAAyE;AACzE,kDAAyD;AACzD,kDAA0B;AAC1B,kFAG8C;AAC9C,mEAA6D;AAE7D,sFAAsF;AACtF,IAAI,CAAC,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE,CAAC,CAAC;IACxD,cAAc,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;Q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,CAAC,EAAE,CAAC,CAAC,IAAI,CAC1D,eAAe,CAChB,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kEAAkE,EAAE,GAAG,EAAE;QAC1E,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,kBAAU,EAC3B,GAAG,EAAE,CAAC,IAAA,0CAAkB,EAAC,oBAAoB,CAAC,EAC9C;YACE,OAAO,EAAE,WAAW;SACrB,CACF,CAAC;QAEF,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC5C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import {\n EventType,\n type TextMessageStartEvent,\n type TextMessageContentEvent,\n type TextMessageEndEvent,\n} from \"@ag-ui/core\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { renderHook, act } from \"@testing-library/react\";\nimport React from \"react\";\nimport {\n TamboV1StreamProvider,\n useStreamDispatch,\n} from \"../providers/tambo-v1-stream-context\";\nimport { useTamboV1Messages } from \"./use-tambo-v1-messages\";\n\n// Mock useTamboClient and useTamboQueryClient to avoid TamboClientProvider dependency\njest.mock(\"../../providers/tambo-client-provider\", () => ({\n useTamboClient: jest.fn(() => ({\n threads: {\n messages: {\n list: jest.fn().mockResolvedValue({ messages: [], hasMore: false }),\n },\n },\n })),\n useTamboQueryClient: jest.fn(),\n}));\n\nimport { useTamboQueryClient } from \"../../providers/tambo-client-provider\";\n\ndescribe(\"useTamboV1Messages\", () => {\n let queryClient: QueryClient;\n\n beforeEach(() => {\n queryClient = new QueryClient({\n defaultOptions: {\n queries: { retry: false },\n },\n });\n // Configure mock to return the test's queryClient\n jest.mocked(useTamboQueryClient).mockReturnValue(queryClient);\n });\n\n function TestWrapper({ children }: { children: React.ReactNode }) {\n return (\n <QueryClientProvider client={queryClient}>\n <TamboV1StreamProvider>{children}</TamboV1StreamProvider>\n </QueryClientProvider>\n );\n }\n\n it(\"returns empty messages when thread has no messages\", () => {\n const { result } = renderHook(\n () => ({\n messages: useTamboV1Messages(\"thread_123\"),\n dispatch: useStreamDispatch(),\n }),\n { wrapper: TestWrapper },\n );\n\n // Initialize thread first\n act(() => {\n result.current.dispatch({ type: \"INIT_THREAD\", threadId: \"thread_123\" });\n });\n\n expect(result.current.messages.messages).toEqual([]);\n expect(result.current.messages.hasMessages).toBe(false);\n expect(result.current.messages.messageCount).toBe(0);\n expect(result.current.messages.lastMessage).toBeUndefined();\n expect(result.current.messages.userMessages).toEqual([]);\n expect(result.current.messages.assistantMessages).toEqual([]);\n });\n\n it(\"returns messages after events are dispatched\", () => {\n const { result } = renderHook(\n () => ({\n messages: useTamboV1Messages(\"thread_123\"),\n dispatch: useStreamDispatch(),\n }),\n { wrapper: TestWrapper },\n );\n\n // Initialize thread first\n act(() => {\n result.current.dispatch({ type: \"INIT_THREAD\", threadId: \"thread_123\" });\n });\n\n // Simulate a text message being received\n act(() => {\n result.current.dispatch({\n type: \"EVENT\",\n event: {\n type: EventType.TEXT_MESSAGE_START,\n messageId: \"msg_1\",\n role: \"assistant\",\n } as TextMessageStartEvent,\n threadId: \"thread_123\",\n });\n });\n\n act(() => {\n result.current.dispatch({\n type: \"EVENT\",\n event: {\n type: EventType.TEXT_MESSAGE_CONTENT,\n messageId: \"msg_1\",\n delta: \"Hello\",\n } as TextMessageContentEvent,\n threadId: \"thread_123\",\n });\n });\n\n act(() => {\n result.current.dispatch({\n type: \"EVENT\",\n event: {\n type: EventType.TEXT_MESSAGE_END,\n messageId: \"msg_1\",\n } as TextMessageEndEvent,\n threadId: \"thread_123\",\n });\n });\n\n expect(result.current.messages.messages.length).toBe(1);\n expect(result.current.messages.hasMessages).toBe(true);\n expect(result.current.messages.messageCount).toBe(1);\n expect(result.current.messages.lastMessage?.id).toBe(\"msg_1\");\n expect(result.current.messages.lastMessage?.role).toBe(\"assistant\");\n expect(result.current.messages.assistantMessages.length).toBe(1);\n expect(result.current.messages.userMessages.length).toBe(0);\n });\n\n it(\"filters user and assistant messages correctly\", () => {\n const { result } = renderHook(\n () => ({\n messages: useTamboV1Messages(\"thread_123\"),\n dispatch: useStreamDispatch(),\n }),\n { wrapper: TestWrapper },\n );\n\n // Initialize thread first\n act(() => {\n result.current.dispatch({ type: \"INIT_THREAD\", threadId: \"thread_123\" });\n });\n\n // Add user message\n act(() => {\n result.current.dispatch({\n type: \"EVENT\",\n event: {\n type: EventType.TEXT_MESSAGE_START,\n messageId: \"msg_user\",\n role: \"user\",\n } as TextMessageStartEvent,\n threadId: \"thread_123\",\n });\n });\n\n act(() => {\n result.current.dispatch({\n type: \"EVENT\",\n event: {\n type: EventType.TEXT_MESSAGE_END,\n messageId: \"msg_user\",\n } as TextMessageEndEvent,\n threadId: \"thread_123\",\n });\n });\n\n // Add assistant message\n act(() => {\n result.current.dispatch({\n type: \"EVENT\",\n event: {\n type: EventType.TEXT_MESSAGE_START,\n messageId: \"msg_assistant\",\n role: \"assistant\",\n } as TextMessageStartEvent,\n threadId: \"thread_123\",\n });\n });\n\n act(() => {\n result.current.dispatch({\n type: \"EVENT\",\n event: {\n type: EventType.TEXT_MESSAGE_END,\n messageId: \"msg_assistant\",\n } as TextMessageEndEvent,\n threadId: \"thread_123\",\n });\n });\n\n expect(result.current.messages.messageCount).toBe(2);\n expect(result.current.messages.userMessages.length).toBe(1);\n expect(result.current.messages.userMessages[0].id).toBe(\"msg_user\");\n expect(result.current.messages.assistantMessages.length).toBe(1);\n expect(result.current.messages.assistantMessages[0].id).toBe(\n \"msg_assistant\",\n );\n expect(result.current.messages.lastMessage?.id).toBe(\"msg_assistant\");\n });\n\n it(\"returns empty messages when threadId does not exist in threadMap\", () => {\n const { result } = renderHook(\n () => useTamboV1Messages(\"nonexistent_thread\"),\n {\n wrapper: TestWrapper,\n },\n );\n\n expect(result.current.messages).toEqual([]);\n expect(result.current.hasMessages).toBe(false);\n expect(result.current.messageCount).toBe(0);\n });\n});\n"]}
|
|
@@ -10,6 +10,12 @@ export interface SendMessageOptions {
|
|
|
10
10
|
* The message to send
|
|
11
11
|
*/
|
|
12
12
|
message: InputMessage;
|
|
13
|
+
/**
|
|
14
|
+
* User message text for optimistic display.
|
|
15
|
+
* If provided, synthetic AG-UI events will be dispatched to show
|
|
16
|
+
* the user message in the thread immediately after getting the threadId.
|
|
17
|
+
*/
|
|
18
|
+
userMessageText?: string;
|
|
13
19
|
/**
|
|
14
20
|
* Enable debug logging for the stream
|
|
15
21
|
*/
|
|
@@ -24,6 +30,16 @@ export interface CreateRunStreamParams {
|
|
|
24
30
|
message: InputMessage;
|
|
25
31
|
registry: TamboRegistry;
|
|
26
32
|
userKey: string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Previous run ID for continuing a thread with existing messages.
|
|
35
|
+
* Required when threadId is provided and the thread has previous runs.
|
|
36
|
+
*/
|
|
37
|
+
previousRunId: string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Additional context gathered from context helpers (including interactables).
|
|
40
|
+
* Merged into the message's additionalContext before sending.
|
|
41
|
+
*/
|
|
42
|
+
additionalContext?: Record<string, unknown>;
|
|
27
43
|
}
|
|
28
44
|
/**
|
|
29
45
|
* Stream types from the SDK
|
|
@@ -92,6 +108,8 @@ export declare function createRunStream(params: CreateRunStreamParams): Promise<
|
|
|
92
108
|
*/
|
|
93
109
|
export declare function useTamboV1SendMessage(threadId?: string): import("@tanstack/react-query").UseMutationResult<{
|
|
94
110
|
threadId: string | undefined;
|
|
111
|
+
preMutationMessageCount: number;
|
|
112
|
+
threadAlreadyHasTitle: boolean;
|
|
95
113
|
}, Error, SendMessageOptions, unknown>;
|
|
96
114
|
export {};
|
|
97
115
|
//# sourceMappingURL=use-tambo-v1-send-message.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-v1-send-message.d.ts","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1-send-message.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-tambo-v1-send-message.d.ts","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1-send-message.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yCAAyC,CAAC;AAMtE,OAAO,EAEL,KAAK,oBAAoB,IAAI,aAAa,EAC3C,MAAM,yCAAyC,CAAC;AAOjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAwKrD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC;IAEtB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,OAAO,EAAE,YAAY,CAAC;IACtB,QAAQ,EAAE,aAAa,CAAC;IACxB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B;;;OAGG;IACH,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C;AAED;;GAEG;AACH,KAAK,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAC7D,KAAK,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,SAAS,GAAG,YAAY,CAAC;IACjC,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AA6ED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC,CAgDhC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,CAAC,EAAE,MAAM;;;;uCA4MtD"}
|
|
@@ -8,18 +8,141 @@ exports.useTamboV1SendMessage = useTamboV1SendMessage;
|
|
|
8
8
|
*
|
|
9
9
|
* React Query mutation hook for sending messages and handling streaming responses.
|
|
10
10
|
*/
|
|
11
|
-
const react_query_1 = require("@tanstack/react-query");
|
|
12
11
|
const react_1 = require("react");
|
|
13
12
|
const core_1 = require("@ag-ui/core");
|
|
14
13
|
const event_1 = require("../types/event");
|
|
15
14
|
const tambo_client_provider_1 = require("../../providers/tambo-client-provider");
|
|
15
|
+
const react_query_hooks_1 = require("../../hooks/react-query-hooks");
|
|
16
16
|
const tambo_registry_provider_1 = require("../../providers/tambo-registry-provider");
|
|
17
17
|
const tambo_v1_stream_context_1 = require("../providers/tambo-v1-stream-context");
|
|
18
18
|
const tambo_v1_provider_1 = require("../providers/tambo-v1-provider");
|
|
19
|
+
const tambo_context_helpers_provider_1 = require("../../providers/tambo-context-helpers-provider");
|
|
20
|
+
const event_accumulator_1 = require("../utils/event-accumulator");
|
|
19
21
|
const registry_conversion_1 = require("../utils/registry-conversion");
|
|
20
22
|
const stream_handler_1 = require("../utils/stream-handler");
|
|
21
23
|
const tool_executor_1 = require("../utils/tool-executor");
|
|
22
24
|
const tool_call_tracker_1 = require("../utils/tool-call-tracker");
|
|
25
|
+
/**
|
|
26
|
+
* Dispatches synthetic AG-UI events to show a user message in the thread.
|
|
27
|
+
* @param dispatch - Stream state dispatcher
|
|
28
|
+
* @param targetThreadId - Thread to add the message to
|
|
29
|
+
* @param messageId - Stable ID for the user message
|
|
30
|
+
* @param messageText - Text content of the message
|
|
31
|
+
*/
|
|
32
|
+
function dispatchUserMessage(dispatch, targetThreadId, messageId, messageText) {
|
|
33
|
+
dispatch({
|
|
34
|
+
type: "EVENT",
|
|
35
|
+
threadId: targetThreadId,
|
|
36
|
+
event: {
|
|
37
|
+
type: core_1.EventType.TEXT_MESSAGE_START,
|
|
38
|
+
messageId,
|
|
39
|
+
role: "user",
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
dispatch({
|
|
43
|
+
type: "EVENT",
|
|
44
|
+
threadId: targetThreadId,
|
|
45
|
+
event: {
|
|
46
|
+
type: core_1.EventType.TEXT_MESSAGE_CONTENT,
|
|
47
|
+
messageId,
|
|
48
|
+
delta: messageText,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
dispatch({
|
|
52
|
+
type: "EVENT",
|
|
53
|
+
threadId: targetThreadId,
|
|
54
|
+
event: {
|
|
55
|
+
type: core_1.EventType.TEXT_MESSAGE_END,
|
|
56
|
+
messageId,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Dispatches synthetic events for tool results as optimistic local state.
|
|
62
|
+
* The server doesn't echo these back for client-side tools.
|
|
63
|
+
* @param dispatch - Stream state dispatcher
|
|
64
|
+
* @param targetThreadId - Thread to add results to
|
|
65
|
+
* @param toolResults - Tool execution results to dispatch
|
|
66
|
+
*/
|
|
67
|
+
function dispatchToolResults(dispatch, targetThreadId, toolResults) {
|
|
68
|
+
if (toolResults.length === 0)
|
|
69
|
+
return;
|
|
70
|
+
const toolResultMessageId = `msg_tool_result_${Date.now()}`;
|
|
71
|
+
dispatch({
|
|
72
|
+
type: "EVENT",
|
|
73
|
+
threadId: targetThreadId,
|
|
74
|
+
event: {
|
|
75
|
+
type: core_1.EventType.TEXT_MESSAGE_START,
|
|
76
|
+
messageId: toolResultMessageId,
|
|
77
|
+
role: "user",
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
for (const result of toolResults) {
|
|
81
|
+
dispatch({
|
|
82
|
+
type: "EVENT",
|
|
83
|
+
threadId: targetThreadId,
|
|
84
|
+
event: {
|
|
85
|
+
type: core_1.EventType.TOOL_CALL_RESULT,
|
|
86
|
+
toolCallId: result.toolUseId,
|
|
87
|
+
messageId: toolResultMessageId,
|
|
88
|
+
content: result.content
|
|
89
|
+
.filter((c) => c.type === "text")
|
|
90
|
+
.map((c) => c.text)
|
|
91
|
+
.join("") || JSON.stringify(result.content),
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
dispatch({
|
|
96
|
+
type: "EVENT",
|
|
97
|
+
threadId: targetThreadId,
|
|
98
|
+
event: {
|
|
99
|
+
type: core_1.EventType.TEXT_MESSAGE_END,
|
|
100
|
+
messageId: toolResultMessageId,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Checks whether a thread name should be auto-generated based on config
|
|
106
|
+
* and the current thread state.
|
|
107
|
+
* @param threadId - The thread ID (undefined or placeholder means no)
|
|
108
|
+
* @param threadAlreadyHasTitle - Whether the thread already has a title
|
|
109
|
+
* @param preMutationMessageCount - Message count before the current mutation
|
|
110
|
+
* @param autoGenerateNameThreshold - Minimum message count to trigger generation
|
|
111
|
+
* @returns Whether to generate a thread name
|
|
112
|
+
*/
|
|
113
|
+
function shouldGenerateThreadName(threadId, threadAlreadyHasTitle, preMutationMessageCount, autoGenerateNameThreshold) {
|
|
114
|
+
return (!threadAlreadyHasTitle &&
|
|
115
|
+
!!threadId &&
|
|
116
|
+
!(0, event_accumulator_1.isPlaceholderThreadId)(threadId) &&
|
|
117
|
+
// +2 accounts for the user message and assistant response just added
|
|
118
|
+
preMutationMessageCount + 2 >= autoGenerateNameThreshold);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Generates a thread name via the beta API, dispatches the title update,
|
|
122
|
+
* and invalidates the thread list cache. Errors are logged, never thrown.
|
|
123
|
+
* @param client - The Tambo API client
|
|
124
|
+
* @param dispatch - Stream state dispatcher
|
|
125
|
+
* @param queryClient - React Query client for cache invalidation
|
|
126
|
+
* @param threadId - The thread to generate a name for
|
|
127
|
+
*/
|
|
128
|
+
async function generateThreadName(client, dispatch, queryClient, threadId) {
|
|
129
|
+
try {
|
|
130
|
+
const threadWithName = await client.beta.threads.generateName(threadId);
|
|
131
|
+
if (threadWithName.name) {
|
|
132
|
+
dispatch({
|
|
133
|
+
type: "UPDATE_THREAD_TITLE",
|
|
134
|
+
threadId,
|
|
135
|
+
title: threadWithName.name,
|
|
136
|
+
});
|
|
137
|
+
await queryClient.invalidateQueries({
|
|
138
|
+
queryKey: ["v1-threads", "list"],
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
console.error("[useTamboV1SendMessage] Failed to auto-generate thread name:", error);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
23
146
|
/**
|
|
24
147
|
* Executes pending tools and returns a continuation stream.
|
|
25
148
|
*
|
|
@@ -27,27 +150,29 @@ const tool_call_tracker_1 = require("../utils/tool-call-tracker");
|
|
|
27
150
|
* the tools and returns the new stream for the caller to process. This enables
|
|
28
151
|
* the flat loop pattern that correctly handles multi-round tool execution.
|
|
29
152
|
* @param params - The parameters for tool execution
|
|
30
|
-
* @returns The continuation stream
|
|
153
|
+
* @returns The continuation stream and tool results for optimistic local state updates
|
|
31
154
|
*/
|
|
32
155
|
async function executeToolsAndContinue(params) {
|
|
33
|
-
const { event, toolTracker, registry, client, threadId, runId, userKey } = params;
|
|
34
|
-
const
|
|
156
|
+
const { event, toolTracker, registry, client, threadId, runId, userKey, additionalContext, } = params;
|
|
157
|
+
const pendingToolCallIds = event.value.pendingToolCalls.map((tc) => tc.toolCallId);
|
|
35
158
|
const toolCallsToExecute = toolTracker.getToolCallsById(pendingToolCallIds);
|
|
36
159
|
// Execute tools
|
|
37
160
|
const toolResults = await (0, tool_executor_1.executeAllPendingTools)(toolCallsToExecute, registry.toolRegistry);
|
|
38
161
|
// Clear executed tool calls before continuing
|
|
39
162
|
toolTracker.clearToolCalls(pendingToolCallIds);
|
|
40
|
-
// Return the continuation stream
|
|
41
|
-
|
|
163
|
+
// Return the continuation stream and tool results
|
|
164
|
+
const stream = await client.threads.runs.run(threadId, {
|
|
42
165
|
message: {
|
|
43
166
|
role: "user",
|
|
44
167
|
content: toolResults,
|
|
168
|
+
additionalContext,
|
|
45
169
|
},
|
|
46
170
|
previousRunId: runId,
|
|
47
171
|
availableComponents: (0, registry_conversion_1.toAvailableComponents)(registry.componentList),
|
|
48
172
|
tools: (0, registry_conversion_1.toAvailableTools)(registry.toolRegistry),
|
|
49
173
|
userKey,
|
|
50
174
|
});
|
|
175
|
+
return { stream, toolResults };
|
|
51
176
|
}
|
|
52
177
|
/**
|
|
53
178
|
* Creates a run stream by calling the appropriate API method.
|
|
@@ -58,24 +183,35 @@ async function executeToolsAndContinue(params) {
|
|
|
58
183
|
* @returns The stream and initial thread ID (undefined if creating new thread)
|
|
59
184
|
*/
|
|
60
185
|
async function createRunStream(params) {
|
|
61
|
-
const { client, threadId, message, registry, userKey } = params;
|
|
186
|
+
const { client, threadId, message, registry, userKey, previousRunId, additionalContext, } = params;
|
|
187
|
+
// Merge helper context with any caller-provided additionalContext on the message
|
|
188
|
+
const mergedContext = additionalContext || message.additionalContext
|
|
189
|
+
? {
|
|
190
|
+
...(message.additionalContext ?? {}),
|
|
191
|
+
...additionalContext,
|
|
192
|
+
}
|
|
193
|
+
: undefined;
|
|
194
|
+
const messageWithContext = mergedContext
|
|
195
|
+
? { ...message, additionalContext: mergedContext }
|
|
196
|
+
: message;
|
|
62
197
|
// Convert registry components/tools to v1 API format
|
|
63
198
|
const availableComponents = (0, registry_conversion_1.toAvailableComponents)(registry.componentList);
|
|
64
199
|
const availableTools = (0, registry_conversion_1.toAvailableTools)(registry.toolRegistry);
|
|
65
200
|
if (threadId) {
|
|
66
201
|
// Run on existing thread
|
|
67
202
|
const stream = await client.threads.runs.run(threadId, {
|
|
68
|
-
message,
|
|
203
|
+
message: messageWithContext,
|
|
69
204
|
availableComponents,
|
|
70
205
|
tools: availableTools,
|
|
71
206
|
userKey,
|
|
207
|
+
previousRunId,
|
|
72
208
|
});
|
|
73
209
|
return { stream, initialThreadId: threadId };
|
|
74
210
|
}
|
|
75
211
|
else {
|
|
76
212
|
// Create new thread
|
|
77
213
|
const stream = await client.threads.runs.create({
|
|
78
|
-
message,
|
|
214
|
+
message: messageWithContext,
|
|
79
215
|
availableComponents,
|
|
80
216
|
tools: availableTools,
|
|
81
217
|
thread: userKey ? { userKey } : undefined,
|
|
@@ -131,23 +267,58 @@ async function createRunStream(params) {
|
|
|
131
267
|
function useTamboV1SendMessage(threadId) {
|
|
132
268
|
const client = (0, tambo_client_provider_1.useTamboClient)();
|
|
133
269
|
const dispatch = (0, tambo_v1_stream_context_1.useStreamDispatch)();
|
|
134
|
-
const
|
|
270
|
+
const streamState = (0, tambo_v1_stream_context_1.useStreamState)();
|
|
271
|
+
const { userKey, autoGenerateThreadName = true, autoGenerateNameThreshold = 3, } = (0, tambo_v1_provider_1.useTamboV1Config)();
|
|
135
272
|
const registry = (0, react_1.useContext)(tambo_registry_provider_1.TamboRegistryContext);
|
|
136
|
-
const queryClient = (0,
|
|
273
|
+
const queryClient = (0, tambo_client_provider_1.useTamboQueryClient)();
|
|
274
|
+
const { getAdditionalContext } = (0, tambo_context_helpers_provider_1.useTamboContextHelpers)();
|
|
137
275
|
if (!registry) {
|
|
138
276
|
throw new Error("useTamboV1SendMessage must be used within TamboRegistryProvider");
|
|
139
277
|
}
|
|
140
|
-
|
|
278
|
+
// Placeholder ID isn't a valid API thread ID - treat as new thread creation
|
|
279
|
+
const isNewThread = (0, event_accumulator_1.isPlaceholderThreadId)(threadId);
|
|
280
|
+
const apiThreadId = isNewThread ? undefined : threadId;
|
|
281
|
+
// Get previousRunId from the thread's streaming state (if thread exists and has messages)
|
|
282
|
+
const threadState = apiThreadId
|
|
283
|
+
? streamState.threadMap[apiThreadId]
|
|
284
|
+
: undefined;
|
|
285
|
+
const previousRunId = threadState?.streaming.runId;
|
|
286
|
+
return (0, react_query_hooks_1.useTamboMutation)({
|
|
141
287
|
mutationFn: async (options) => {
|
|
142
|
-
const { message, debug = false } = options;
|
|
288
|
+
const { message, userMessageText, debug = false } = options;
|
|
289
|
+
// Capture pre-mutation state for auto thread name generation
|
|
290
|
+
const existingThread = streamState.threadMap[apiThreadId ?? ""];
|
|
291
|
+
const preMutationMessageCount = existingThread?.thread.messages.length ?? 0;
|
|
292
|
+
const threadAlreadyHasTitle = !!existingThread?.thread.title;
|
|
143
293
|
const toolTracker = new tool_call_tracker_1.ToolCallTracker();
|
|
294
|
+
// Generate a stable message ID for the user message
|
|
295
|
+
const userMessageId = userMessageText
|
|
296
|
+
? `user_msg_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`
|
|
297
|
+
: undefined;
|
|
298
|
+
// Add user message immediately for instant feedback
|
|
299
|
+
// Use threadId (which could be temp_xxx for new threads) for display
|
|
300
|
+
if (threadId && userMessageText && userMessageId) {
|
|
301
|
+
dispatchUserMessage(dispatch, threadId, userMessageId, userMessageText);
|
|
302
|
+
}
|
|
303
|
+
// Gather additional context from all registered context helpers.
|
|
304
|
+
// TODO: This snapshot is captured once and reused for the entire multi-round
|
|
305
|
+
// tool loop. If interactables change during streaming (e.g. user interactions),
|
|
306
|
+
// continuations will send stale context. Re-gather before each continuation
|
|
307
|
+
// if freshness matters.
|
|
308
|
+
const helperContexts = await getAdditionalContext();
|
|
309
|
+
const additionalContext = {};
|
|
310
|
+
for (const helperContext of helperContexts) {
|
|
311
|
+
additionalContext[helperContext.name] = helperContext.context;
|
|
312
|
+
}
|
|
144
313
|
// Create the run stream
|
|
145
314
|
const { stream, initialThreadId } = await createRunStream({
|
|
146
315
|
client,
|
|
147
|
-
threadId,
|
|
316
|
+
threadId: apiThreadId,
|
|
148
317
|
message,
|
|
149
318
|
registry,
|
|
150
319
|
userKey,
|
|
320
|
+
previousRunId,
|
|
321
|
+
additionalContext,
|
|
151
322
|
});
|
|
152
323
|
let actualThreadId = initialThreadId;
|
|
153
324
|
let runId;
|
|
@@ -166,6 +337,12 @@ function useTamboV1SendMessage(threadId) {
|
|
|
166
337
|
if (event.type === core_1.EventType.RUN_STARTED) {
|
|
167
338
|
runId = event.runId;
|
|
168
339
|
actualThreadId ??= event.threadId;
|
|
340
|
+
// For threads with no ID at all: add user message now that we have the real threadId
|
|
341
|
+
// Note: temp thread migration (temp_xxx -> real ID) is handled automatically
|
|
342
|
+
// by the reducer when it sees RUN_STARTED with a different threadId
|
|
343
|
+
if (!threadId && userMessageText && userMessageId) {
|
|
344
|
+
dispatchUserMessage(dispatch, actualThreadId, userMessageId, userMessageText);
|
|
345
|
+
}
|
|
169
346
|
}
|
|
170
347
|
else if (!actualThreadId) {
|
|
171
348
|
throw new Error(`Expected first event to be RUN_STARTED with threadId, got: ${event.type}`);
|
|
@@ -190,7 +367,7 @@ function useTamboV1SendMessage(threadId) {
|
|
|
190
367
|
if (!runId || !actualThreadId) {
|
|
191
368
|
throw new Error("Cannot continue run after awaiting_input: missing runId or threadId");
|
|
192
369
|
}
|
|
193
|
-
|
|
370
|
+
const { stream: continuationStream, toolResults } = await executeToolsAndContinue({
|
|
194
371
|
event: pendingAwaitingInput,
|
|
195
372
|
toolTracker,
|
|
196
373
|
registry,
|
|
@@ -198,9 +375,16 @@ function useTamboV1SendMessage(threadId) {
|
|
|
198
375
|
threadId: actualThreadId,
|
|
199
376
|
runId,
|
|
200
377
|
userKey,
|
|
378
|
+
additionalContext,
|
|
201
379
|
});
|
|
380
|
+
dispatchToolResults(dispatch, actualThreadId, toolResults);
|
|
381
|
+
currentStream = continuationStream;
|
|
202
382
|
}
|
|
203
|
-
return {
|
|
383
|
+
return {
|
|
384
|
+
threadId: actualThreadId,
|
|
385
|
+
preMutationMessageCount,
|
|
386
|
+
threadAlreadyHasTitle,
|
|
387
|
+
};
|
|
204
388
|
}
|
|
205
389
|
catch (error) {
|
|
206
390
|
// Dispatch a synthetic RUN_ERROR event to clean up thread state
|
|
@@ -221,10 +405,13 @@ function useTamboV1SendMessage(threadId) {
|
|
|
221
405
|
}
|
|
222
406
|
},
|
|
223
407
|
onSuccess: async (result) => {
|
|
224
|
-
// Invalidate thread queries to refetch updated state
|
|
225
408
|
await queryClient.invalidateQueries({
|
|
226
409
|
queryKey: ["v1-threads", result.threadId],
|
|
227
410
|
});
|
|
411
|
+
if (autoGenerateThreadName &&
|
|
412
|
+
shouldGenerateThreadName(result.threadId, result.threadAlreadyHasTitle, result.preMutationMessageCount, autoGenerateNameThreshold)) {
|
|
413
|
+
await generateThreadName(client, dispatch, queryClient, result.threadId);
|
|
414
|
+
}
|
|
228
415
|
},
|
|
229
416
|
onError: (error) => {
|
|
230
417
|
console.error("[useTamboV1SendMessage] Mutation failed:", error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-v1-send-message.js","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1-send-message.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAmIb,0CA6BC;AA8CD,sDAwHC;AApUD;;;;GAIG;AAEH,uDAAoE;AACpE,iCAAmC;AACnC,sCAA4D;AAC5D,0CAAgF;AAGhF,iFAAuE;AACvE,qFAGiD;AACjD,kFAAyE;AACzE,sEAAkE;AAElE,sEAGsC;AACtC,4DAA4D;AAC5D,0DAAgE;AAChE,kEAA6D;AAuD7D;;;;;;;;GAQG;AACH,KAAK,UAAU,uBAAuB,CACpC,MAA0B;IAE1B,MAAM,EAAE,K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,CAAC,0CAA0C,EAAE,KAAK,CAAC,CAAC;QACnE,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["\"use client\";\n\n/**\n * Send Message Hook for v1 API\n *\n * React Query mutation hook for sending messages and handling streaming responses.\n */\n\nimport { useMutation, useQueryClient } from \"@tanstack/react-query\";\nimport { useContext } from \"react\";\nimport { EventType, type RunErrorEvent } from \"@ag-ui/core\";\nimport { asTamboCustomEvent, type RunAwaitingInputEvent } from \"../types/event\";\nimport type TamboAI from \"@tambo-ai/typescript-sdk\";\nimport type { Stream } from \"@tambo-ai/typescript-sdk/core/streaming\";\nimport { useTamboClient } from \"../../providers/tambo-client-provider\";\nimport {\n TamboRegistryContext,\n type TamboRegistryContext as TamboRegistry,\n} from \"../../providers/tambo-registry-provider\";\nimport { useStreamDispatch } from \"../providers/tambo-v1-stream-context\";\nimport { useTamboV1Config } from \"../providers/tambo-v1-provider\";\nimport type { InputMessage } from \"../types/message\";\nimport {\n toAvailableComponents,\n toAvailableTools,\n} from \"../utils/registry-conversion\";\nimport { handleEventStream } from \"../utils/stream-handler\";\nimport { executeAllPendingTools } from \"../utils/tool-executor\";\nimport { ToolCallTracker } from \"../utils/tool-call-tracker\";\n\n/**\n * Options for sending a message\n */\nexport interface SendMessageOptions {\n /**\n * The message to send\n */\n message: InputMessage;\n\n /**\n * Enable debug logging for the stream\n */\n debug?: boolean;\n}\n\n/**\n * Parameters for creating a run stream\n */\nexport interface CreateRunStreamParams {\n client: TamboAI;\n threadId: string | undefined;\n message: InputMessage;\n registry: TamboRegistry;\n userKey: string | undefined;\n}\n\n/**\n * Stream types from the SDK\n */\ntype RunStream = Stream<TamboAI.Threads.Runs.RunRunResponse>;\ntype CreateStream = Stream<TamboAI.Threads.Runs.RunCreateResponse>;\n\n/**\n * Result from creating a run stream\n */\nexport interface CreateRunStreamResult {\n stream: RunStream | CreateStream;\n initialThreadId: string | undefined;\n}\n\n/**\n * Parameters for executing tools and continuing the run\n */\ninterface ExecuteToolsParams {\n event: RunAwaitingInputEvent;\n toolTracker: ToolCallTracker;\n registry: TamboRegistry;\n client: TamboAI;\n threadId: string;\n runId: string;\n userKey: string | undefined;\n}\n\n/**\n * Executes pending tools and returns a continuation stream.\n *\n * This function does NOT process the continuation stream - it just executes\n * the tools and returns the new stream for the caller to process. This enables\n * the flat loop pattern that correctly handles multi-round tool execution.\n * @param params - The parameters for tool execution\n * @returns The continuation stream to process\n */\nasync function executeToolsAndContinue(\n params: ExecuteToolsParams,\n): Promise<RunStream> {\n const { event, toolTracker, registry, client, threadId, runId, userKey } =\n params;\n\n const { pendingToolCallIds } = event.value;\n const toolCallsToExecute = toolTracker.getToolCallsById(pendingToolCallIds);\n\n // Execute tools\n const toolResults = await executeAllPendingTools(\n toolCallsToExecute,\n registry.toolRegistry,\n );\n\n // Clear executed tool calls before continuing\n toolTracker.clearToolCalls(pendingToolCallIds);\n\n // Return the continuation stream (caller will process it)\n return await client.threads.runs.run(threadId, {\n message: {\n role: \"user\",\n content: toolResults,\n },\n previousRunId: runId,\n availableComponents: toAvailableComponents(registry.componentList),\n tools: toAvailableTools(registry.toolRegistry),\n userKey,\n });\n}\n\n/**\n * Creates a run stream by calling the appropriate API method.\n *\n * If threadId is provided, runs on existing thread via client.threads.runs.run().\n * If no threadId, creates new thread via client.threads.runs.create().\n * @param params - The parameters for creating the run stream\n * @returns The stream and initial thread ID (undefined if creating new thread)\n */\nexport async function createRunStream(\n params: CreateRunStreamParams,\n): Promise<CreateRunStreamResult> {\n const { client, threadId, message, registry, userKey } = params;\n\n // Convert registry components/tools to v1 API format\n const availableComponents = toAvailableComponents(registry.componentList);\n const availableTools = toAvailableTools(registry.toolRegistry);\n\n if (threadId) {\n // Run on existing thread\n const stream = await client.threads.runs.run(threadId, {\n message,\n availableComponents,\n tools: availableTools,\n userKey,\n });\n return { stream, initialThreadId: threadId };\n } else {\n // Create new thread\n const stream = await client.threads.runs.create({\n message,\n availableComponents,\n tools: availableTools,\n thread: userKey ? { userKey } : undefined,\n });\n // threadId will be extracted from first event (RUN_STARTED)\n return { stream, initialThreadId: undefined };\n }\n}\n\n/**\n * Hook to send a message and handle streaming responses.\n *\n * This hook handles two scenarios:\n * - If threadId provided: runs on existing thread via client.threads.runs.run()\n * - If no threadId: creates new thread via client.threads.runs.create()\n *\n * The hook:\n * - Sends a user message to the API\n * - Streams AG-UI events in real-time\n * - Dispatches events to the stream reducer\n * - Extracts threadId from events when creating new thread\n * - Handles tool execution (Phase 6)\n * - Invalidates thread queries on completion\n * @param threadId - Optional thread ID to send message to. If not provided, creates new thread\n * @returns React Query mutation object with threadId in mutation result\n * @example\n * ```tsx\n * function ChatInput({ threadId }: { threadId?: string }) {\n * const sendMessage = useTamboV1SendMessage(threadId);\n *\n * const handleSubmit = async (text: string) => {\n * const result = await sendMessage.mutateAsync({\n * message: {\n * role: \"user\",\n * content: [{ type: \"text\", text }],\n * },\n * });\n *\n * // If threadId wasn't provided, a new thread was created\n * if (!threadId) {\n * console.log(\"Created thread:\", result.threadId);\n * }\n * };\n *\n * return (\n * <div>\n * <input onSubmit={handleSubmit} />\n * {sendMessage.isPending && <Spinner />}\n * </div>\n * );\n * }\n * ```\n */\nexport function useTamboV1SendMessage(threadId?: string) {\n const client = useTamboClient();\n const dispatch = useStreamDispatch();\n const { userKey } = useTamboV1Config();\n const registry = useContext(TamboRegistryContext);\n const queryClient = useQueryClient();\n\n if (!registry) {\n throw new Error(\n \"useTamboV1SendMessage must be used within TamboRegistryProvider\",\n );\n }\n\n return useMutation({\n mutationFn: async (options: SendMessageOptions) => {\n const { message, debug = false } = options;\n\n const toolTracker = new ToolCallTracker();\n\n // Create the run stream\n const { stream, initialThreadId } = await createRunStream({\n client,\n threadId,\n message,\n registry,\n userKey,\n });\n\n let actualThreadId = initialThreadId;\n let runId: string | undefined;\n let currentStream: CreateRunStreamResult[\"stream\"] = stream;\n\n try {\n // Outer loop handles stream replacement for multi-round tool execution.\n // When we hit awaiting_input, we execute tools, get a new stream, and continue.\n // This flat loop pattern correctly handles tool→AI→tool→AI chains.\n while (true) {\n let pendingAwaitingInput: RunAwaitingInputEvent | undefined;\n\n // Process current stream until completion or awaiting_input\n for await (const event of handleEventStream(currentStream, {\n debug,\n })) {\n // Extract threadId and runId from RUN_STARTED event\n if (event.type === EventType.RUN_STARTED) {\n runId = event.runId;\n actualThreadId ??= event.threadId;\n } else if (!actualThreadId) {\n throw new Error(\n `Expected first event to be RUN_STARTED with threadId, got: ${event.type}`,\n );\n }\n\n toolTracker.handleEvent(event);\n dispatch({ type: \"EVENT\", event, threadId: actualThreadId });\n\n // Check for awaiting_input - if found, break to execute tools\n if (event.type === EventType.CUSTOM) {\n const customEvent = asTamboCustomEvent(event);\n if (customEvent?.name === \"tambo.run.awaiting_input\") {\n pendingAwaitingInput = customEvent;\n break; // Exit stream loop to handle tool execution\n }\n }\n }\n\n // If stream finished without awaiting_input, we're done\n if (!pendingAwaitingInput) {\n break;\n }\n\n // Execute tools and get continuation stream\n // These checks should never fail since awaiting_input comes after RUN_STARTED\n if (!runId || !actualThreadId) {\n throw new Error(\n \"Cannot continue run after awaiting_input: missing runId or threadId\",\n );\n }\n\n currentStream = await executeToolsAndContinue({\n event: pendingAwaitingInput,\n toolTracker,\n registry,\n client,\n threadId: actualThreadId,\n runId,\n userKey,\n });\n }\n\n return { threadId: actualThreadId };\n } catch (error) {\n // Dispatch a synthetic RUN_ERROR event to clean up thread state\n // This ensures the thread doesn't stay stuck in \"streaming\" status\n if (actualThreadId) {\n const errorMessage =\n error instanceof Error ? error.message : \"Unknown streaming error\";\n const errorEvent: RunErrorEvent = {\n type: EventType.RUN_ERROR,\n message: errorMessage,\n };\n dispatch({\n type: \"EVENT\",\n event: errorEvent,\n threadId: actualThreadId,\n });\n }\n throw error;\n }\n },\n onSuccess: async (result) => {\n // Invalidate thread queries to refetch updated state\n await queryClient.invalidateQueries({\n queryKey: [\"v1-threads\", result.threadId],\n });\n },\n onError: (error) => {\n console.error(\"[useTamboV1SendMessage] Mutation failed:\", error);\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-tambo-v1-send-message.js","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1-send-message.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAgVb,0CAkDC;AA8CD,sDA4MC;AA1nBD;;;;GAIG;AAEH,iCAA0C;AAC1C,sCAA4D;AAC5D,0CAAgF;AAGhF,iFAG+C;AAC/C,qEAAiE;AACjE,qFAGiD;AACjD,kFAG8C;AAC9C,sEAAkE;AAClE,mGAAwF;AAExF,kEAGoC;AACpC,sEAGsC;AACtC,4DAA4D;AAC5D,0DAAgE;AAEhE,kEAA6D;AAE7D;;;;;;GAMG;AACH,SAAS,mBAAmB,CAC1B,QAAsC,EACtC,cAAsB,EACtB,SAAiB,EACjB,WAAmB;IAEnB,QAAQ,CAAC;QACP,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,cAAc;QACxB,KAAK,EAAE;YACL,IAAI,EAAE,gBAAS,CAAC,kBAAkB;YAClC,SAAS;YACT,IAAI,EAAE,MAAe;SACtB;KACF,CAAC,CAAC;IAEH,QAAQ,CAAC;QACP,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,cAAc;QACxB,KAAK,EAAE;YACL,IAAI,EAAE,gBAAS,CAAC,oBAAoB;YACpC,SAAS;YACT,KAAK,EAAE,WAAW;SACnB;KACF,CAAC,CAAC;IAEH,QAAQ,CAAC;QACP,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,cAAc;QACxB,KAAK,EAAE;YACL,IAAI,EAAE,gBAAS,CAAC,gBAAgB;YAChC,SAAS;SACV;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,SAAS,mBAAmB,CAC1B,QAAsC,EACtC,cAAsB,EACtB,WAAgC;IAEhC,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAErC,MAAM,mBAAmB,GAAG,mBAAmB,IAAI,CAAC,GAAG,EAAE,EAAE,CAA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AC;gBACf,gEAAgE;gBAChE,mEAAmE;gBACnE,IAAI,cAAc,EAAE,CAAC;oBACnB,MAAM,YAAY,GAChB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,yBAAyB,CAAC;oBACrE,MAAM,UAAU,GAAkB;wBAChC,IAAI,EAAE,gBAAS,CAAC,SAAS;wBACzB,OAAO,EAAE,YAAY;qBACtB,CAAC;oBACF,QAAQ,CAAC;wBACP,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE,UAAU;wBACjB,QAAQ,EAAE,cAAc;qBACzB,CAAC,CAAC;gBACL,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QACD,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAC1B,MAAM,WAAW,CAAC,iBAAiB,CAAC;gBAClC,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC;aAC1C,CAAC,CAAC;YAEH,IACE,sBAAsB;gBACtB,wBAAwB,CACtB,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,qBAAqB,EAC5B,MAAM,CAAC,uBAAuB,EAC9B,yBAAyB,CAC1B,EACD,CAAC;gBACD,MAAM,kBAAkB,CACtB,MAAM,EACN,QAAQ,EACR,WAAW,EACX,MAAM,CAAC,QAAQ,CAChB,CAAC;YACJ,CAAC;QACH,CAAC;QACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACjB,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,KAAK,CAAC,CAAC;QACnE,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["\"use client\";\n\n/**\n * Send Message Hook for v1 API\n *\n * React Query mutation hook for sending messages and handling streaming responses.\n */\n\nimport React, { useContext } from \"react\";\nimport { EventType, type RunErrorEvent } from \"@ag-ui/core\";\nimport { asTamboCustomEvent, type RunAwaitingInputEvent } from \"../types/event\";\nimport type TamboAI from \"@tambo-ai/typescript-sdk\";\nimport type { Stream } from \"@tambo-ai/typescript-sdk/core/streaming\";\nimport {\n useTamboClient,\n useTamboQueryClient,\n} from \"../../providers/tambo-client-provider\";\nimport { useTamboMutation } from \"../../hooks/react-query-hooks\";\nimport {\n TamboRegistryContext,\n type TamboRegistryContext as TamboRegistry,\n} from \"../../providers/tambo-registry-provider\";\nimport {\n useStreamDispatch,\n useStreamState,\n} from \"../providers/tambo-v1-stream-context\";\nimport { useTamboV1Config } from \"../providers/tambo-v1-provider\";\nimport { useTamboContextHelpers } from \"../../providers/tambo-context-helpers-provider\";\nimport type { InputMessage } from \"../types/message\";\nimport {\n isPlaceholderThreadId,\n type StreamAction,\n} from \"../utils/event-accumulator\";\nimport {\n toAvailableComponents,\n toAvailableTools,\n} from \"../utils/registry-conversion\";\nimport { handleEventStream } from \"../utils/stream-handler\";\nimport { executeAllPendingTools } from \"../utils/tool-executor\";\nimport type { ToolResultContent } from \"@tambo-ai/typescript-sdk/resources/threads/threads\";\nimport { ToolCallTracker } from \"../utils/tool-call-tracker\";\n\n/**\n * Dispatches synthetic AG-UI events to show a user message in the thread.\n * @param dispatch - Stream state dispatcher\n * @param targetThreadId - Thread to add the message to\n * @param messageId - Stable ID for the user message\n * @param messageText - Text content of the message\n */\nfunction dispatchUserMessage(\n dispatch: React.Dispatch<StreamAction>,\n targetThreadId: string,\n messageId: string,\n messageText: string,\n): void {\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TEXT_MESSAGE_START,\n messageId,\n role: \"user\" as const,\n },\n });\n\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TEXT_MESSAGE_CONTENT,\n messageId,\n delta: messageText,\n },\n });\n\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TEXT_MESSAGE_END,\n messageId,\n },\n });\n}\n\n/**\n * Dispatches synthetic events for tool results as optimistic local state.\n * The server doesn't echo these back for client-side tools.\n * @param dispatch - Stream state dispatcher\n * @param targetThreadId - Thread to add results to\n * @param toolResults - Tool execution results to dispatch\n */\nfunction dispatchToolResults(\n dispatch: React.Dispatch<StreamAction>,\n targetThreadId: string,\n toolResults: ToolResultContent[],\n): void {\n if (toolResults.length === 0) return;\n\n const toolResultMessageId = `msg_tool_result_${Date.now()}`;\n\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TEXT_MESSAGE_START,\n messageId: toolResultMessageId,\n role: \"user\" as const,\n },\n });\n\n for (const result of toolResults) {\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TOOL_CALL_RESULT,\n toolCallId: result.toolUseId,\n messageId: toolResultMessageId,\n content:\n result.content\n .filter((c) => c.type === \"text\")\n .map((c) => (c as { type: \"text\"; text: string }).text)\n .join(\"\") || JSON.stringify(result.content),\n },\n });\n }\n\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TEXT_MESSAGE_END,\n messageId: toolResultMessageId,\n },\n });\n}\n\n/**\n * Checks whether a thread name should be auto-generated based on config\n * and the current thread state.\n * @param threadId - The thread ID (undefined or placeholder means no)\n * @param threadAlreadyHasTitle - Whether the thread already has a title\n * @param preMutationMessageCount - Message count before the current mutation\n * @param autoGenerateNameThreshold - Minimum message count to trigger generation\n * @returns Whether to generate a thread name\n */\nfunction shouldGenerateThreadName(\n threadId: string | undefined,\n threadAlreadyHasTitle: boolean,\n preMutationMessageCount: number,\n autoGenerateNameThreshold: number,\n): threadId is string {\n return (\n !threadAlreadyHasTitle &&\n !!threadId &&\n !isPlaceholderThreadId(threadId) &&\n // +2 accounts for the user message and assistant response just added\n preMutationMessageCount + 2 >= autoGenerateNameThreshold\n );\n}\n\n/**\n * Generates a thread name via the beta API, dispatches the title update,\n * and invalidates the thread list cache. Errors are logged, never thrown.\n * @param client - The Tambo API client\n * @param dispatch - Stream state dispatcher\n * @param queryClient - React Query client for cache invalidation\n * @param threadId - The thread to generate a name for\n */\nasync function generateThreadName(\n client: TamboAI,\n dispatch: React.Dispatch<StreamAction>,\n queryClient: ReturnType<typeof useTamboQueryClient>,\n threadId: string,\n): Promise<void> {\n try {\n const threadWithName = await client.beta.threads.generateName(threadId);\n if (threadWithName.name) {\n dispatch({\n type: \"UPDATE_THREAD_TITLE\",\n threadId,\n title: threadWithName.name,\n });\n await queryClient.invalidateQueries({\n queryKey: [\"v1-threads\", \"list\"],\n });\n }\n } catch (error) {\n console.error(\n \"[useTamboV1SendMessage] Failed to auto-generate thread name:\",\n error,\n );\n }\n}\n\n/**\n * Options for sending a message\n */\nexport interface SendMessageOptions {\n /**\n * The message to send\n */\n message: InputMessage;\n\n /**\n * User message text for optimistic display.\n * If provided, synthetic AG-UI events will be dispatched to show\n * the user message in the thread immediately after getting the threadId.\n */\n userMessageText?: string;\n\n /**\n * Enable debug logging for the stream\n */\n debug?: boolean;\n}\n\n/**\n * Parameters for creating a run stream\n */\nexport interface CreateRunStreamParams {\n client: TamboAI;\n threadId: string | undefined;\n message: InputMessage;\n registry: TamboRegistry;\n userKey: string | undefined;\n /**\n * Previous run ID for continuing a thread with existing messages.\n * Required when threadId is provided and the thread has previous runs.\n */\n previousRunId: string | undefined;\n /**\n * Additional context gathered from context helpers (including interactables).\n * Merged into the message's additionalContext before sending.\n */\n additionalContext?: Record<string, unknown>;\n}\n\n/**\n * Stream types from the SDK\n */\ntype RunStream = Stream<TamboAI.Threads.Runs.RunRunResponse>;\ntype CreateStream = Stream<TamboAI.Threads.Runs.RunCreateResponse>;\n\n/**\n * Result from creating a run stream\n */\nexport interface CreateRunStreamResult {\n stream: RunStream | CreateStream;\n initialThreadId: string | undefined;\n}\n\n/**\n * Parameters for executing tools and continuing the run\n */\ninterface ExecuteToolsParams {\n event: RunAwaitingInputEvent;\n toolTracker: ToolCallTracker;\n registry: TamboRegistry;\n client: TamboAI;\n threadId: string;\n runId: string;\n userKey: string | undefined;\n additionalContext?: Record<string, unknown>;\n}\n\n/**\n * Result from executing tools and continuing the run\n */\ninterface ExecuteToolsResult {\n stream: RunStream;\n toolResults: ToolResultContent[];\n}\n\n/**\n * Executes pending tools and returns a continuation stream.\n *\n * This function does NOT process the continuation stream - it just executes\n * the tools and returns the new stream for the caller to process. This enables\n * the flat loop pattern that correctly handles multi-round tool execution.\n * @param params - The parameters for tool execution\n * @returns The continuation stream and tool results for optimistic local state updates\n */\nasync function executeToolsAndContinue(\n params: ExecuteToolsParams,\n): Promise<ExecuteToolsResult> {\n const {\n event,\n toolTracker,\n registry,\n client,\n threadId,\n runId,\n userKey,\n additionalContext,\n } = params;\n\n const pendingToolCallIds = event.value.pendingToolCalls.map(\n (tc) => tc.toolCallId,\n );\n const toolCallsToExecute = toolTracker.getToolCallsById(pendingToolCallIds);\n\n // Execute tools\n const toolResults = await executeAllPendingTools(\n toolCallsToExecute,\n registry.toolRegistry,\n );\n\n // Clear executed tool calls before continuing\n toolTracker.clearToolCalls(pendingToolCallIds);\n\n // Return the continuation stream and tool results\n const stream = await client.threads.runs.run(threadId, {\n message: {\n role: \"user\",\n content: toolResults,\n additionalContext,\n },\n previousRunId: runId,\n availableComponents: toAvailableComponents(registry.componentList),\n tools: toAvailableTools(registry.toolRegistry),\n userKey,\n });\n\n return { stream, toolResults };\n}\n\n/**\n * Creates a run stream by calling the appropriate API method.\n *\n * If threadId is provided, runs on existing thread via client.threads.runs.run().\n * If no threadId, creates new thread via client.threads.runs.create().\n * @param params - The parameters for creating the run stream\n * @returns The stream and initial thread ID (undefined if creating new thread)\n */\nexport async function createRunStream(\n params: CreateRunStreamParams,\n): Promise<CreateRunStreamResult> {\n const {\n client,\n threadId,\n message,\n registry,\n userKey,\n previousRunId,\n additionalContext,\n } = params;\n\n // Merge helper context with any caller-provided additionalContext on the message\n const mergedContext =\n additionalContext || message.additionalContext\n ? {\n ...((message.additionalContext as Record<string, unknown>) ?? {}),\n ...additionalContext,\n }\n : undefined;\n const messageWithContext: InputMessage = mergedContext\n ? { ...message, additionalContext: mergedContext }\n : message;\n\n // Convert registry components/tools to v1 API format\n const availableComponents = toAvailableComponents(registry.componentList);\n const availableTools = toAvailableTools(registry.toolRegistry);\n\n if (threadId) {\n // Run on existing thread\n const stream = await client.threads.runs.run(threadId, {\n message: messageWithContext,\n availableComponents,\n tools: availableTools,\n userKey,\n previousRunId,\n });\n return { stream, initialThreadId: threadId };\n } else {\n // Create new thread\n const stream = await client.threads.runs.create({\n message: messageWithContext,\n availableComponents,\n tools: availableTools,\n thread: userKey ? { userKey } : undefined,\n });\n // threadId will be extracted from first event (RUN_STARTED)\n return { stream, initialThreadId: undefined };\n }\n}\n\n/**\n * Hook to send a message and handle streaming responses.\n *\n * This hook handles two scenarios:\n * - If threadId provided: runs on existing thread via client.threads.runs.run()\n * - If no threadId: creates new thread via client.threads.runs.create()\n *\n * The hook:\n * - Sends a user message to the API\n * - Streams AG-UI events in real-time\n * - Dispatches events to the stream reducer\n * - Extracts threadId from events when creating new thread\n * - Handles tool execution (Phase 6)\n * - Invalidates thread queries on completion\n * @param threadId - Optional thread ID to send message to. If not provided, creates new thread\n * @returns React Query mutation object with threadId in mutation result\n * @example\n * ```tsx\n * function ChatInput({ threadId }: { threadId?: string }) {\n * const sendMessage = useTamboV1SendMessage(threadId);\n *\n * const handleSubmit = async (text: string) => {\n * const result = await sendMessage.mutateAsync({\n * message: {\n * role: \"user\",\n * content: [{ type: \"text\", text }],\n * },\n * });\n *\n * // If threadId wasn't provided, a new thread was created\n * if (!threadId) {\n * console.log(\"Created thread:\", result.threadId);\n * }\n * };\n *\n * return (\n * <div>\n * <input onSubmit={handleSubmit} />\n * {sendMessage.isPending && <Spinner />}\n * </div>\n * );\n * }\n * ```\n */\nexport function useTamboV1SendMessage(threadId?: string) {\n const client = useTamboClient();\n const dispatch = useStreamDispatch();\n const streamState = useStreamState();\n const {\n userKey,\n autoGenerateThreadName = true,\n autoGenerateNameThreshold = 3,\n } = useTamboV1Config();\n const registry = useContext(TamboRegistryContext);\n const queryClient = useTamboQueryClient();\n const { getAdditionalContext } = useTamboContextHelpers();\n\n if (!registry) {\n throw new Error(\n \"useTamboV1SendMessage must be used within TamboRegistryProvider\",\n );\n }\n\n // Placeholder ID isn't a valid API thread ID - treat as new thread creation\n const isNewThread = isPlaceholderThreadId(threadId);\n const apiThreadId = isNewThread ? undefined : threadId;\n\n // Get previousRunId from the thread's streaming state (if thread exists and has messages)\n const threadState = apiThreadId\n ? streamState.threadMap[apiThreadId]\n : undefined;\n const previousRunId = threadState?.streaming.runId;\n\n return useTamboMutation({\n mutationFn: async (options: SendMessageOptions) => {\n const { message, userMessageText, debug = false } = options;\n\n // Capture pre-mutation state for auto thread name generation\n const existingThread = streamState.threadMap[apiThreadId ?? \"\"];\n const preMutationMessageCount =\n existingThread?.thread.messages.length ?? 0;\n const threadAlreadyHasTitle = !!existingThread?.thread.title;\n\n const toolTracker = new ToolCallTracker();\n\n // Generate a stable message ID for the user message\n const userMessageId = userMessageText\n ? `user_msg_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`\n : undefined;\n\n // Add user message immediately for instant feedback\n // Use threadId (which could be temp_xxx for new threads) for display\n if (threadId && userMessageText && userMessageId) {\n dispatchUserMessage(dispatch, threadId, userMessageId, userMessageText);\n }\n\n // Gather additional context from all registered context helpers.\n // TODO: This snapshot is captured once and reused for the entire multi-round\n // tool loop. If interactables change during streaming (e.g. user interactions),\n // continuations will send stale context. Re-gather before each continuation\n // if freshness matters.\n const helperContexts = await getAdditionalContext();\n const additionalContext: Record<string, unknown> = {};\n for (const helperContext of helperContexts) {\n additionalContext[helperContext.name] = helperContext.context;\n }\n\n // Create the run stream\n const { stream, initialThreadId } = await createRunStream({\n client,\n threadId: apiThreadId,\n message,\n registry,\n userKey,\n previousRunId,\n additionalContext,\n });\n\n let actualThreadId = initialThreadId;\n let runId: string | undefined;\n let currentStream: CreateRunStreamResult[\"stream\"] = stream;\n\n try {\n // Outer loop handles stream replacement for multi-round tool execution.\n // When we hit awaiting_input, we execute tools, get a new stream, and continue.\n // This flat loop pattern correctly handles tool→AI→tool→AI chains.\n while (true) {\n let pendingAwaitingInput: RunAwaitingInputEvent | undefined;\n\n // Process current stream until completion or awaiting_input\n for await (const event of handleEventStream(currentStream, {\n debug,\n })) {\n // Extract threadId and runId from RUN_STARTED event\n if (event.type === EventType.RUN_STARTED) {\n runId = event.runId;\n actualThreadId ??= event.threadId;\n\n // For threads with no ID at all: add user message now that we have the real threadId\n // Note: temp thread migration (temp_xxx -> real ID) is handled automatically\n // by the reducer when it sees RUN_STARTED with a different threadId\n if (!threadId && userMessageText && userMessageId) {\n dispatchUserMessage(\n dispatch,\n actualThreadId,\n userMessageId,\n userMessageText,\n );\n }\n } else if (!actualThreadId) {\n throw new Error(\n `Expected first event to be RUN_STARTED with threadId, got: ${event.type}`,\n );\n }\n\n toolTracker.handleEvent(event);\n dispatch({ type: \"EVENT\", event, threadId: actualThreadId });\n\n // Check for awaiting_input - if found, break to execute tools\n if (event.type === EventType.CUSTOM) {\n const customEvent = asTamboCustomEvent(event);\n if (customEvent?.name === \"tambo.run.awaiting_input\") {\n pendingAwaitingInput = customEvent;\n break; // Exit stream loop to handle tool execution\n }\n }\n }\n\n // If stream finished without awaiting_input, we're done\n if (!pendingAwaitingInput) {\n break;\n }\n\n // Execute tools and get continuation stream\n // These checks should never fail since awaiting_input comes after RUN_STARTED\n if (!runId || !actualThreadId) {\n throw new Error(\n \"Cannot continue run after awaiting_input: missing runId or threadId\",\n );\n }\n\n const { stream: continuationStream, toolResults } =\n await executeToolsAndContinue({\n event: pendingAwaitingInput,\n toolTracker,\n registry,\n client,\n threadId: actualThreadId,\n runId,\n userKey,\n additionalContext,\n });\n\n dispatchToolResults(dispatch, actualThreadId, toolResults);\n\n currentStream = continuationStream;\n }\n\n return {\n threadId: actualThreadId,\n preMutationMessageCount,\n threadAlreadyHasTitle,\n };\n } catch (error) {\n // Dispatch a synthetic RUN_ERROR event to clean up thread state\n // This ensures the thread doesn't stay stuck in \"streaming\" status\n if (actualThreadId) {\n const errorMessage =\n error instanceof Error ? error.message : \"Unknown streaming error\";\n const errorEvent: RunErrorEvent = {\n type: EventType.RUN_ERROR,\n message: errorMessage,\n };\n dispatch({\n type: \"EVENT\",\n event: errorEvent,\n threadId: actualThreadId,\n });\n }\n throw error;\n }\n },\n onSuccess: async (result) => {\n await queryClient.invalidateQueries({\n queryKey: [\"v1-threads\", result.threadId],\n });\n\n if (\n autoGenerateThreadName &&\n shouldGenerateThreadName(\n result.threadId,\n result.threadAlreadyHasTitle,\n result.preMutationMessageCount,\n autoGenerateNameThreshold,\n )\n ) {\n await generateThreadName(\n client,\n dispatch,\n queryClient,\n result.threadId,\n );\n }\n },\n onError: (error) => {\n console.error(\"[useTamboV1SendMessage] Mutation failed:\", error);\n },\n });\n}\n"]}
|