@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
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react";
|
|
2
|
+
import { useTamboV1StreamStatus } from "./use-tambo-v1-stream-status.js";
|
|
3
|
+
// Mock the required hooks
|
|
4
|
+
jest.mock("../utils/component-renderer", () => ({
|
|
5
|
+
useV1ComponentContent: jest.fn(),
|
|
6
|
+
}));
|
|
7
|
+
jest.mock("../providers/tambo-v1-stream-context", () => ({
|
|
8
|
+
useStreamState: jest.fn(),
|
|
9
|
+
}));
|
|
10
|
+
// Import the mocked functions
|
|
11
|
+
import { useV1ComponentContent } from "../utils/component-renderer.js";
|
|
12
|
+
import { useStreamState } from "../providers/tambo-v1-stream-context.js";
|
|
13
|
+
// Mock window for SSR tests
|
|
14
|
+
const originalWindow = global.window;
|
|
15
|
+
// Get the mocked functions
|
|
16
|
+
const mockUseV1ComponentContent = jest.mocked(useV1ComponentContent);
|
|
17
|
+
const mockUseStreamState = jest.mocked(useStreamState);
|
|
18
|
+
/**
|
|
19
|
+
* Helper to create a component content block
|
|
20
|
+
*/
|
|
21
|
+
function createComponentContent(overrides = {}) {
|
|
22
|
+
return {
|
|
23
|
+
type: "component",
|
|
24
|
+
id: "test-component",
|
|
25
|
+
name: "TestComponent",
|
|
26
|
+
props: {},
|
|
27
|
+
streamingState: "started",
|
|
28
|
+
...overrides,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Helper to create a message with a component
|
|
33
|
+
*/
|
|
34
|
+
function createMessage(componentContent, overrides = {}) {
|
|
35
|
+
return {
|
|
36
|
+
id: "test-message",
|
|
37
|
+
role: "assistant",
|
|
38
|
+
content: [componentContent],
|
|
39
|
+
createdAt: new Date().toISOString(),
|
|
40
|
+
...overrides,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Helper to create a thread state
|
|
45
|
+
*/
|
|
46
|
+
function createThreadState(messages, overrides = {}) {
|
|
47
|
+
return {
|
|
48
|
+
thread: {
|
|
49
|
+
id: "test-thread",
|
|
50
|
+
messages,
|
|
51
|
+
status: "idle",
|
|
52
|
+
createdAt: new Date().toISOString(),
|
|
53
|
+
updatedAt: new Date().toISOString(),
|
|
54
|
+
lastRunCancelled: false,
|
|
55
|
+
},
|
|
56
|
+
streaming: {
|
|
57
|
+
status: "idle",
|
|
58
|
+
},
|
|
59
|
+
accumulatingToolArgs: new Map(),
|
|
60
|
+
...overrides,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Helper to create a stream state
|
|
65
|
+
*/
|
|
66
|
+
function createStreamState(threadState, threadId = "test-thread") {
|
|
67
|
+
return {
|
|
68
|
+
threadMap: {
|
|
69
|
+
[threadId]: threadState,
|
|
70
|
+
},
|
|
71
|
+
currentThreadId: threadId,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
describe("useTamboV1StreamStatus", () => {
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
// Restore window for client-side tests
|
|
77
|
+
global.window = originalWindow;
|
|
78
|
+
// Default mock implementations
|
|
79
|
+
mockUseV1ComponentContent.mockReturnValue({
|
|
80
|
+
componentId: "test-component",
|
|
81
|
+
threadId: "test-thread",
|
|
82
|
+
messageId: "test-message",
|
|
83
|
+
componentName: "TestComponent",
|
|
84
|
+
});
|
|
85
|
+
const componentContent = createComponentContent({ props: {} });
|
|
86
|
+
const message = createMessage(componentContent);
|
|
87
|
+
const threadState = createThreadState([message]);
|
|
88
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
89
|
+
});
|
|
90
|
+
afterEach(() => {
|
|
91
|
+
jest.clearAllMocks();
|
|
92
|
+
// Restore window after each test
|
|
93
|
+
global.window = originalWindow;
|
|
94
|
+
});
|
|
95
|
+
describe("Initial State", () => {
|
|
96
|
+
it("should start with all flags as pending when component streaming is 'started' and no props", () => {
|
|
97
|
+
const componentContent = createComponentContent({
|
|
98
|
+
props: { title: "", body: "" },
|
|
99
|
+
streamingState: "started",
|
|
100
|
+
});
|
|
101
|
+
const message = createMessage(componentContent);
|
|
102
|
+
const threadState = createThreadState([message]);
|
|
103
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
104
|
+
const { result } = renderHook(() => useTamboV1StreamStatus());
|
|
105
|
+
expect(result.current.streamStatus).toEqual({
|
|
106
|
+
isPending: true,
|
|
107
|
+
isStreaming: false,
|
|
108
|
+
isSuccess: false,
|
|
109
|
+
isError: false,
|
|
110
|
+
streamError: undefined,
|
|
111
|
+
});
|
|
112
|
+
expect(result.current.propStatus.title).toEqual({
|
|
113
|
+
isPending: true,
|
|
114
|
+
isStreaming: false,
|
|
115
|
+
isSuccess: false,
|
|
116
|
+
error: undefined,
|
|
117
|
+
});
|
|
118
|
+
expect(result.current.propStatus.body).toEqual({
|
|
119
|
+
isPending: true,
|
|
120
|
+
isStreaming: false,
|
|
121
|
+
isSuccess: false,
|
|
122
|
+
error: undefined,
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe("Streaming State Transitions", () => {
|
|
127
|
+
it("should show isStreaming when component is streaming even before props receive content", () => {
|
|
128
|
+
// Component is streaming but props are still empty
|
|
129
|
+
const componentContent = createComponentContent({
|
|
130
|
+
props: { title: "", body: "" },
|
|
131
|
+
streamingState: "streaming",
|
|
132
|
+
});
|
|
133
|
+
const message = createMessage(componentContent);
|
|
134
|
+
const threadState = createThreadState([message]);
|
|
135
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
136
|
+
const { result } = renderHook(() => useTamboV1StreamStatus());
|
|
137
|
+
// Global should be streaming even though no props have content yet
|
|
138
|
+
expect(result.current.streamStatus.isStreaming).toBe(true);
|
|
139
|
+
expect(result.current.streamStatus.isPending).toBe(false);
|
|
140
|
+
// Individual props should still be pending
|
|
141
|
+
expect(result.current.propStatus.title.isPending).toBe(true);
|
|
142
|
+
expect(result.current.propStatus.title.isStreaming).toBe(false);
|
|
143
|
+
});
|
|
144
|
+
it("should show prop streaming when props receive content during streaming", () => {
|
|
145
|
+
const componentContent = createComponentContent({
|
|
146
|
+
props: { title: "Hello", body: "" },
|
|
147
|
+
streamingState: "streaming",
|
|
148
|
+
});
|
|
149
|
+
const message = createMessage(componentContent);
|
|
150
|
+
const threadState = createThreadState([message]);
|
|
151
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
152
|
+
const { result } = renderHook(() => useTamboV1StreamStatus());
|
|
153
|
+
// Title prop should be streaming since it has content
|
|
154
|
+
expect(result.current.propStatus.title.isStreaming).toBe(true);
|
|
155
|
+
expect(result.current.propStatus.title.isPending).toBe(false);
|
|
156
|
+
// Body prop should still be pending since it has no content
|
|
157
|
+
expect(result.current.propStatus.body.isStreaming).toBe(false);
|
|
158
|
+
expect(result.current.propStatus.body.isPending).toBe(true);
|
|
159
|
+
// Global should be streaming because at least one prop is streaming
|
|
160
|
+
expect(result.current.streamStatus.isStreaming).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
it("should transition through Init -> Streaming -> Success lifecycle", () => {
|
|
163
|
+
// Start with "started" (Init phase)
|
|
164
|
+
const componentContent = createComponentContent({
|
|
165
|
+
props: { title: "", body: "" },
|
|
166
|
+
streamingState: "started",
|
|
167
|
+
});
|
|
168
|
+
const message = createMessage(componentContent);
|
|
169
|
+
let threadState = createThreadState([message]);
|
|
170
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
171
|
+
const { result, rerender } = renderHook(() => useTamboV1StreamStatus());
|
|
172
|
+
// Phase 1: Init - isPending = true
|
|
173
|
+
expect(result.current.streamStatus.isPending).toBe(true);
|
|
174
|
+
expect(result.current.streamStatus.isStreaming).toBe(false);
|
|
175
|
+
expect(result.current.streamStatus.isSuccess).toBe(false);
|
|
176
|
+
// Phase 2: Streaming - move to "streaming" with content
|
|
177
|
+
const streamingComponent = createComponentContent({
|
|
178
|
+
props: { title: "Hello World", body: "Some content" },
|
|
179
|
+
streamingState: "streaming",
|
|
180
|
+
});
|
|
181
|
+
const streamingMessage = createMessage(streamingComponent);
|
|
182
|
+
threadState = createThreadState([streamingMessage]);
|
|
183
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
184
|
+
rerender();
|
|
185
|
+
expect(result.current.streamStatus.isPending).toBe(false);
|
|
186
|
+
expect(result.current.streamStatus.isStreaming).toBe(true);
|
|
187
|
+
expect(result.current.streamStatus.isSuccess).toBe(false);
|
|
188
|
+
// Phase 3: Complete - move to "done"
|
|
189
|
+
const doneComponent = createComponentContent({
|
|
190
|
+
props: { title: "Hello World", body: "Some content" },
|
|
191
|
+
streamingState: "done",
|
|
192
|
+
});
|
|
193
|
+
const doneMessage = createMessage(doneComponent);
|
|
194
|
+
threadState = createThreadState([doneMessage]);
|
|
195
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
196
|
+
rerender();
|
|
197
|
+
expect(result.current.streamStatus.isPending).toBe(false);
|
|
198
|
+
expect(result.current.streamStatus.isStreaming).toBe(false);
|
|
199
|
+
expect(result.current.streamStatus.isSuccess).toBe(true);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
describe("Error Handling", () => {
|
|
203
|
+
it("should handle error state correctly", () => {
|
|
204
|
+
const componentContent = createComponentContent({
|
|
205
|
+
props: { title: "", body: "" },
|
|
206
|
+
streamingState: "started",
|
|
207
|
+
});
|
|
208
|
+
const message = createMessage(componentContent);
|
|
209
|
+
const threadState = createThreadState([message], {
|
|
210
|
+
streaming: {
|
|
211
|
+
status: "error",
|
|
212
|
+
error: { message: "Generation failed", code: "GENERATION_ERROR" },
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
216
|
+
const { result } = renderHook(() => useTamboV1StreamStatus());
|
|
217
|
+
// Error state: isPending=false (error overrides pending), isStreaming=false (error stops streaming)
|
|
218
|
+
expect(result.current.streamStatus.isPending).toBe(false);
|
|
219
|
+
expect(result.current.streamStatus.isStreaming).toBe(false);
|
|
220
|
+
expect(result.current.streamStatus.isSuccess).toBe(false);
|
|
221
|
+
expect(result.current.streamStatus.isError).toBe(true);
|
|
222
|
+
expect(result.current.streamStatus.streamError?.message).toBe("Generation failed");
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
describe("Derivation Rules", () => {
|
|
226
|
+
it("should derive isPending correctly (no streaming activity AND all props pending)", () => {
|
|
227
|
+
const componentContent = createComponentContent({
|
|
228
|
+
props: { title: "", body: "", footer: "" },
|
|
229
|
+
streamingState: "started",
|
|
230
|
+
});
|
|
231
|
+
const message = createMessage(componentContent);
|
|
232
|
+
const threadState = createThreadState([message]);
|
|
233
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
234
|
+
const { result } = renderHook(() => useTamboV1StreamStatus());
|
|
235
|
+
// All props are pending and no streaming activity
|
|
236
|
+
expect(result.current.streamStatus.isPending).toBe(true);
|
|
237
|
+
expect(result.current.propStatus.title.isPending).toBe(true);
|
|
238
|
+
expect(result.current.propStatus.body.isPending).toBe(true);
|
|
239
|
+
expect(result.current.propStatus.footer.isPending).toBe(true);
|
|
240
|
+
});
|
|
241
|
+
it("should derive isSuccess correctly (streaming done AND all props successful)", () => {
|
|
242
|
+
// Step 1: Start with streaming, props empty
|
|
243
|
+
const startComponent = createComponentContent({
|
|
244
|
+
props: { title: "", body: "" },
|
|
245
|
+
streamingState: "streaming",
|
|
246
|
+
});
|
|
247
|
+
const startMessage = createMessage(startComponent);
|
|
248
|
+
let threadState = createThreadState([startMessage]);
|
|
249
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
250
|
+
const { result, rerender } = renderHook(() => useTamboV1StreamStatus());
|
|
251
|
+
// Step 2: Simulate streaming in title
|
|
252
|
+
const titleComponent = createComponentContent({
|
|
253
|
+
props: { title: "Complete Title", body: "" },
|
|
254
|
+
streamingState: "streaming",
|
|
255
|
+
});
|
|
256
|
+
const titleMessage = createMessage(titleComponent);
|
|
257
|
+
threadState = createThreadState([titleMessage]);
|
|
258
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
259
|
+
rerender();
|
|
260
|
+
// Step 3: Simulate streaming in body
|
|
261
|
+
const bodyComponent = createComponentContent({
|
|
262
|
+
props: { title: "Complete Title", body: "Complete Body" },
|
|
263
|
+
streamingState: "streaming",
|
|
264
|
+
});
|
|
265
|
+
const bodyMessage = createMessage(bodyComponent);
|
|
266
|
+
threadState = createThreadState([bodyMessage]);
|
|
267
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
268
|
+
rerender();
|
|
269
|
+
// Step 4: Component streaming done
|
|
270
|
+
const doneComponent = createComponentContent({
|
|
271
|
+
props: { title: "Complete Title", body: "Complete Body" },
|
|
272
|
+
streamingState: "done",
|
|
273
|
+
});
|
|
274
|
+
const doneMessage = createMessage(doneComponent);
|
|
275
|
+
threadState = createThreadState([doneMessage]);
|
|
276
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
277
|
+
rerender();
|
|
278
|
+
// Now both props should be successful
|
|
279
|
+
expect(result.current.propStatus.title.isSuccess).toBe(true);
|
|
280
|
+
expect(result.current.propStatus.body.isSuccess).toBe(true);
|
|
281
|
+
expect(result.current.streamStatus.isSuccess).toBe(true);
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
describe("Type Safety", () => {
|
|
285
|
+
it("should provide strongly typed prop status based on generic", () => {
|
|
286
|
+
const componentContent = createComponentContent({
|
|
287
|
+
props: { title: "Test", description: "Test desc", count: 42 },
|
|
288
|
+
streamingState: "done",
|
|
289
|
+
});
|
|
290
|
+
const message = createMessage(componentContent);
|
|
291
|
+
const threadState = createThreadState([message]);
|
|
292
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
293
|
+
const { result } = renderHook(() => useTamboV1StreamStatus());
|
|
294
|
+
// TypeScript should infer these keys correctly
|
|
295
|
+
expect(result.current.propStatus.title).toBeDefined();
|
|
296
|
+
expect(result.current.propStatus.description).toBeDefined();
|
|
297
|
+
expect(result.current.propStatus.count).toBeDefined();
|
|
298
|
+
});
|
|
299
|
+
it("should work without generic type parameter", () => {
|
|
300
|
+
const componentContent = createComponentContent({
|
|
301
|
+
props: { dynamicProp: "value" },
|
|
302
|
+
streamingState: "done",
|
|
303
|
+
});
|
|
304
|
+
const message = createMessage(componentContent);
|
|
305
|
+
const threadState = createThreadState([message]);
|
|
306
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
307
|
+
const { result } = renderHook(() => useTamboV1StreamStatus());
|
|
308
|
+
expect(result.current.streamStatus).toBeDefined();
|
|
309
|
+
expect(result.current.propStatus).toBeDefined();
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
describe("Edge Cases", () => {
|
|
313
|
+
it("should handle missing component gracefully", () => {
|
|
314
|
+
const threadState = createThreadState([
|
|
315
|
+
{
|
|
316
|
+
id: "test-message",
|
|
317
|
+
role: "assistant",
|
|
318
|
+
content: [{ type: "text", text: "Hello" }],
|
|
319
|
+
createdAt: new Date().toISOString(),
|
|
320
|
+
},
|
|
321
|
+
]);
|
|
322
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
323
|
+
const { result } = renderHook(() => useTamboV1StreamStatus());
|
|
324
|
+
expect(result.current.streamStatus.isPending).toBe(true);
|
|
325
|
+
expect(result.current.propStatus).toEqual({});
|
|
326
|
+
});
|
|
327
|
+
it("should handle missing thread gracefully", () => {
|
|
328
|
+
mockUseStreamState.mockReturnValue({
|
|
329
|
+
threadMap: {},
|
|
330
|
+
currentThreadId: "non-existent",
|
|
331
|
+
});
|
|
332
|
+
const { result } = renderHook(() => useTamboV1StreamStatus());
|
|
333
|
+
expect(result.current.streamStatus.isPending).toBe(true);
|
|
334
|
+
expect(result.current.propStatus).toEqual({});
|
|
335
|
+
});
|
|
336
|
+
it("should error when component ID changes unexpectedly", () => {
|
|
337
|
+
const consoleSpy = jest.spyOn(console, "error").mockImplementation();
|
|
338
|
+
const componentContent = createComponentContent({
|
|
339
|
+
id: "first-component",
|
|
340
|
+
props: { title: "Title" },
|
|
341
|
+
streamingState: "streaming",
|
|
342
|
+
});
|
|
343
|
+
const message = createMessage(componentContent);
|
|
344
|
+
const threadState = createThreadState([message]);
|
|
345
|
+
mockUseStreamState.mockReturnValue(createStreamState(threadState));
|
|
346
|
+
mockUseV1ComponentContent.mockReturnValue({
|
|
347
|
+
componentId: "first-component",
|
|
348
|
+
threadId: "test-thread",
|
|
349
|
+
messageId: "test-message",
|
|
350
|
+
componentName: "TestComponent",
|
|
351
|
+
});
|
|
352
|
+
const { rerender } = renderHook(() => useTamboV1StreamStatus());
|
|
353
|
+
// No error initially
|
|
354
|
+
expect(consoleSpy).not.toHaveBeenCalled();
|
|
355
|
+
// Change componentId (this should not happen in practice)
|
|
356
|
+
mockUseV1ComponentContent.mockReturnValue({
|
|
357
|
+
componentId: "second-component",
|
|
358
|
+
threadId: "test-thread",
|
|
359
|
+
messageId: "test-message",
|
|
360
|
+
componentName: "TestComponent",
|
|
361
|
+
});
|
|
362
|
+
rerender();
|
|
363
|
+
// Should log an error indicating incorrect provider usage
|
|
364
|
+
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining("componentId changed"));
|
|
365
|
+
consoleSpy.mockRestore();
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
//# sourceMappingURL=use-tambo-v1-stream-status.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tambo-v1-stream-status.test.js","sourceRoot":"","sources":["../../../src/v1/hooks/use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,QAAQ,EAAE,aAAa;gBACvB,SAAS,EAAE,cAAc;gBACzB,aAAa,EAAE,eAAe;aAC/B,CAAC,CAAC;YAEH,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CACnC,sBAAsB,EAAqB,CAC5C,CAAC;YAEF,qBAAqB;YACrB,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;YAE1C,0DAA0D;YAC1D,yBAAyB,CAAC,eAAe,CAAC;gBACxC,WAAW,EAAE,kBAAkB;gBAC/B,QAAQ,EAAE,aAAa;gBACvB,SAAS,EAAE,cAAc;gBACzB,aAAa,EAAE,eAAe;aAC/B,CAAC,CAAC;YAEH,QAAQ,EAAE,CAAC;YAEX,0DAA0D;YAC1D,MAAM,CAAC,UAAU,CAAC,CAAC,oBAAoB,CACrC,MAAM,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,CAC/C,CAAC;YAEF,UAAU,CAAC,WAAW,EAAE,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook } from \"@testing-library/react\";\nimport { useTamboV1StreamStatus } from \"./use-tambo-v1-stream-status\";\n\n// Mock the required hooks\njest.mock(\"../utils/component-renderer\", () => ({\n useV1ComponentContent: jest.fn(),\n}));\n\njest.mock(\"../providers/tambo-v1-stream-context\", () => ({\n useStreamState: jest.fn(),\n}));\n\n// Import the mocked functions\nimport { useV1ComponentContent } from \"../utils/component-renderer\";\nimport { useStreamState } from \"../providers/tambo-v1-stream-context\";\nimport type { StreamState, ThreadState } from \"../utils/event-accumulator\";\nimport type { V1ComponentContent, TamboV1Message } from \"../types/message\";\n\n// Mock window for SSR tests\nconst originalWindow = global.window;\n\n// Get the mocked functions\nconst mockUseV1ComponentContent = jest.mocked(useV1ComponentContent);\nconst mockUseStreamState = jest.mocked(useStreamState);\n\n/**\n * Helper to create a component content block\n */\nfunction createComponentContent(\n overrides: Partial<V1ComponentContent> = {},\n): V1ComponentContent {\n return {\n type: \"component\",\n id: \"test-component\",\n name: \"TestComponent\",\n props: {},\n streamingState: \"started\",\n ...overrides,\n };\n}\n\n/**\n * Helper to create a message with a component\n */\nfunction createMessage(\n componentContent: V1ComponentContent,\n overrides: Partial<TamboV1Message> = {},\n): TamboV1Message {\n return {\n id: \"test-message\",\n role: \"assistant\",\n content: [componentContent],\n createdAt: new Date().toISOString(),\n ...overrides,\n };\n}\n\n/**\n * Helper to create a thread state\n */\nfunction createThreadState(\n messages: TamboV1Message[],\n overrides: Partial<ThreadState> = {},\n): ThreadState {\n return {\n thread: {\n id: \"test-thread\",\n messages,\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: {\n status: \"idle\",\n },\n accumulatingToolArgs: new Map(),\n ...overrides,\n };\n}\n\n/**\n * Helper to create a stream state\n */\nfunction createStreamState(\n threadState: ThreadState,\n threadId = \"test-thread\",\n): StreamState {\n return {\n threadMap: {\n [threadId]: threadState,\n },\n currentThreadId: threadId,\n };\n}\n\ndescribe(\"useTamboV1StreamStatus\", () => {\n beforeEach(() => {\n // Restore window for client-side tests\n global.window = originalWindow;\n\n // Default mock implementations\n mockUseV1ComponentContent.mockReturnValue({\n componentId: \"test-component\",\n threadId: \"test-thread\",\n messageId: \"test-message\",\n componentName: \"TestComponent\",\n });\n\n const componentContent = createComponentContent({ props: {} });\n const message = createMessage(componentContent);\n const threadState = createThreadState([message]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n });\n\n afterEach(() => {\n jest.clearAllMocks();\n // Restore window after each test\n global.window = originalWindow;\n });\n\n describe(\"Initial State\", () => {\n it(\"should start with all flags as pending when component streaming is 'started' and no props\", () => {\n const componentContent = createComponentContent({\n props: { title: \"\", body: \"\" },\n streamingState: \"started\",\n });\n const message = createMessage(componentContent);\n const threadState = createThreadState([message]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n\n const { result } = renderHook(() =>\n useTamboV1StreamStatus<{ title: string; body: string }>(),\n );\n\n expect(result.current.streamStatus).toEqual({\n isPending: true,\n isStreaming: false,\n isSuccess: false,\n isError: false,\n streamError: undefined,\n });\n\n expect(result.current.propStatus.title).toEqual({\n isPending: true,\n isStreaming: false,\n isSuccess: false,\n error: undefined,\n });\n\n expect(result.current.propStatus.body).toEqual({\n isPending: true,\n isStreaming: false,\n isSuccess: false,\n error: undefined,\n });\n });\n });\n\n describe(\"Streaming State Transitions\", () => {\n it(\"should show isStreaming when component is streaming even before props receive content\", () => {\n // Component is streaming but props are still empty\n const componentContent = createComponentContent({\n props: { title: \"\", body: \"\" },\n streamingState: \"streaming\",\n });\n const message = createMessage(componentContent);\n const threadState = createThreadState([message]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n\n const { result } = renderHook(() =>\n useTamboV1StreamStatus<{ title: string; body: string }>(),\n );\n\n // Global should be streaming even though no props have content yet\n expect(result.current.streamStatus.isStreaming).toBe(true);\n expect(result.current.streamStatus.isPending).toBe(false);\n\n // Individual props should still be pending\n expect(result.current.propStatus.title.isPending).toBe(true);\n expect(result.current.propStatus.title.isStreaming).toBe(false);\n });\n\n it(\"should show prop streaming when props receive content during streaming\", () => {\n const componentContent = createComponentContent({\n props: { title: \"Hello\", body: \"\" },\n streamingState: \"streaming\",\n });\n const message = createMessage(componentContent);\n const threadState = createThreadState([message]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n\n const { result } = renderHook(() =>\n useTamboV1StreamStatus<{ title: string; body: string }>(),\n );\n\n // Title prop should be streaming since it has content\n expect(result.current.propStatus.title.isStreaming).toBe(true);\n expect(result.current.propStatus.title.isPending).toBe(false);\n\n // Body prop should still be pending since it has no content\n expect(result.current.propStatus.body.isStreaming).toBe(false);\n expect(result.current.propStatus.body.isPending).toBe(true);\n\n // Global should be streaming because at least one prop is streaming\n expect(result.current.streamStatus.isStreaming).toBe(true);\n });\n\n it(\"should transition through Init -> Streaming -> Success lifecycle\", () => {\n // Start with \"started\" (Init phase)\n const componentContent = createComponentContent({\n props: { title: \"\", body: \"\" },\n streamingState: \"started\",\n });\n const message = createMessage(componentContent);\n let threadState = createThreadState([message]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n\n const { result, rerender } = renderHook(() =>\n useTamboV1StreamStatus<{ title: string; body: string }>(),\n );\n\n // Phase 1: Init - isPending = true\n expect(result.current.streamStatus.isPending).toBe(true);\n expect(result.current.streamStatus.isStreaming).toBe(false);\n expect(result.current.streamStatus.isSuccess).toBe(false);\n\n // Phase 2: Streaming - move to \"streaming\" with content\n const streamingComponent = createComponentContent({\n props: { title: \"Hello World\", body: \"Some content\" },\n streamingState: \"streaming\",\n });\n const streamingMessage = createMessage(streamingComponent);\n threadState = createThreadState([streamingMessage]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n\n rerender();\n\n expect(result.current.streamStatus.isPending).toBe(false);\n expect(result.current.streamStatus.isStreaming).toBe(true);\n expect(result.current.streamStatus.isSuccess).toBe(false);\n\n // Phase 3: Complete - move to \"done\"\n const doneComponent = createComponentContent({\n props: { title: \"Hello World\", body: \"Some content\" },\n streamingState: \"done\",\n });\n const doneMessage = createMessage(doneComponent);\n threadState = createThreadState([doneMessage]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n\n rerender();\n\n expect(result.current.streamStatus.isPending).toBe(false);\n expect(result.current.streamStatus.isStreaming).toBe(false);\n expect(result.current.streamStatus.isSuccess).toBe(true);\n });\n });\n\n describe(\"Error Handling\", () => {\n it(\"should handle error state correctly\", () => {\n const componentContent = createComponentContent({\n props: { title: \"\", body: \"\" },\n streamingState: \"started\",\n });\n const message = createMessage(componentContent);\n const threadState = createThreadState([message], {\n streaming: {\n status: \"error\",\n error: { message: \"Generation failed\", code: \"GENERATION_ERROR\" },\n },\n });\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n\n const { result } = renderHook(() =>\n useTamboV1StreamStatus<{ title: string; body: string }>(),\n );\n\n // Error state: isPending=false (error overrides pending), isStreaming=false (error stops streaming)\n expect(result.current.streamStatus.isPending).toBe(false);\n expect(result.current.streamStatus.isStreaming).toBe(false);\n expect(result.current.streamStatus.isSuccess).toBe(false);\n expect(result.current.streamStatus.isError).toBe(true);\n expect(result.current.streamStatus.streamError?.message).toBe(\n \"Generation failed\",\n );\n });\n });\n\n describe(\"Derivation Rules\", () => {\n it(\"should derive isPending correctly (no streaming activity AND all props pending)\", () => {\n const componentContent = createComponentContent({\n props: { title: \"\", body: \"\", footer: \"\" },\n streamingState: \"started\",\n });\n const message = createMessage(componentContent);\n const threadState = createThreadState([message]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n\n const { result } = renderHook(() =>\n useTamboV1StreamStatus<{\n title: string;\n body: string;\n footer: string;\n }>(),\n );\n\n // All props are pending and no streaming activity\n expect(result.current.streamStatus.isPending).toBe(true);\n expect(result.current.propStatus.title.isPending).toBe(true);\n expect(result.current.propStatus.body.isPending).toBe(true);\n expect(result.current.propStatus.footer.isPending).toBe(true);\n });\n\n it(\"should derive isSuccess correctly (streaming done AND all props successful)\", () => {\n // Step 1: Start with streaming, props empty\n const startComponent = createComponentContent({\n props: { title: \"\", body: \"\" },\n streamingState: \"streaming\",\n });\n const startMessage = createMessage(startComponent);\n let threadState = createThreadState([startMessage]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n\n const { result, rerender } = renderHook(() =>\n useTamboV1StreamStatus<{ title: string; body: string }>(),\n );\n\n // Step 2: Simulate streaming in title\n const titleComponent = createComponentContent({\n props: { title: \"Complete Title\", body: \"\" },\n streamingState: \"streaming\",\n });\n const titleMessage = createMessage(titleComponent);\n threadState = createThreadState([titleMessage]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n rerender();\n\n // Step 3: Simulate streaming in body\n const bodyComponent = createComponentContent({\n props: { title: \"Complete Title\", body: \"Complete Body\" },\n streamingState: \"streaming\",\n });\n const bodyMessage = createMessage(bodyComponent);\n threadState = createThreadState([bodyMessage]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n rerender();\n\n // Step 4: Component streaming done\n const doneComponent = createComponentContent({\n props: { title: \"Complete Title\", body: \"Complete Body\" },\n streamingState: \"done\",\n });\n const doneMessage = createMessage(doneComponent);\n threadState = createThreadState([doneMessage]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n rerender();\n\n // Now both props should be successful\n expect(result.current.propStatus.title.isSuccess).toBe(true);\n expect(result.current.propStatus.body.isSuccess).toBe(true);\n expect(result.current.streamStatus.isSuccess).toBe(true);\n });\n });\n\n describe(\"Type Safety\", () => {\n it(\"should provide strongly typed prop status based on generic\", () => {\n interface TestProps {\n title: string;\n description: string;\n count: number;\n }\n\n const componentContent = createComponentContent({\n props: { title: \"Test\", description: \"Test desc\", count: 42 },\n streamingState: \"done\",\n });\n const message = createMessage(componentContent);\n const threadState = createThreadState([message]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n\n const { result } = renderHook(() => useTamboV1StreamStatus<TestProps>());\n\n // TypeScript should infer these keys correctly\n expect(result.current.propStatus.title).toBeDefined();\n expect(result.current.propStatus.description).toBeDefined();\n expect(result.current.propStatus.count).toBeDefined();\n });\n\n it(\"should work without generic type parameter\", () => {\n const componentContent = createComponentContent({\n props: { dynamicProp: \"value\" },\n streamingState: \"done\",\n });\n const message = createMessage(componentContent);\n const threadState = createThreadState([message]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n\n const { result } = renderHook(() => useTamboV1StreamStatus());\n\n expect(result.current.streamStatus).toBeDefined();\n expect(result.current.propStatus).toBeDefined();\n });\n });\n\n describe(\"Edge Cases\", () => {\n it(\"should handle missing component gracefully\", () => {\n const threadState = createThreadState([\n {\n id: \"test-message\",\n role: \"assistant\",\n content: [{ type: \"text\", text: \"Hello\" }],\n createdAt: new Date().toISOString(),\n },\n ]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n\n const { result } = renderHook(() => useTamboV1StreamStatus());\n\n expect(result.current.streamStatus.isPending).toBe(true);\n expect(result.current.propStatus).toEqual({});\n });\n\n it(\"should handle missing thread gracefully\", () => {\n mockUseStreamState.mockReturnValue({\n threadMap: {},\n currentThreadId: \"non-existent\",\n });\n\n const { result } = renderHook(() => useTamboV1StreamStatus());\n\n expect(result.current.streamStatus.isPending).toBe(true);\n expect(result.current.propStatus).toEqual({});\n });\n\n it(\"should error when component ID changes unexpectedly\", () => {\n const consoleSpy = jest.spyOn(console, \"error\").mockImplementation();\n\n const componentContent = createComponentContent({\n id: \"first-component\",\n props: { title: \"Title\" },\n streamingState: \"streaming\",\n });\n const message = createMessage(componentContent);\n const threadState = createThreadState([message]);\n mockUseStreamState.mockReturnValue(createStreamState(threadState));\n\n mockUseV1ComponentContent.mockReturnValue({\n componentId: \"first-component\",\n threadId: \"test-thread\",\n messageId: \"test-message\",\n componentName: \"TestComponent\",\n });\n\n const { rerender } = renderHook(() =>\n useTamboV1StreamStatus<{ title: string }>(),\n );\n\n // No error initially\n expect(consoleSpy).not.toHaveBeenCalled();\n\n // Change componentId (this should not happen in practice)\n mockUseV1ComponentContent.mockReturnValue({\n componentId: \"second-component\",\n threadId: \"test-thread\",\n messageId: \"test-message\",\n componentName: \"TestComponent\",\n });\n\n rerender();\n\n // Should log an error indicating incorrect provider usage\n expect(consoleSpy).toHaveBeenCalledWith(\n expect.stringContaining(\"componentId changed\"),\n );\n\n consoleSpy.mockRestore();\n });\n });\n});\n"]}
|
|
@@ -1,91 +1,115 @@
|
|
|
1
|
+
import type { UseQueryOptions } from "@tanstack/react-query";
|
|
2
|
+
import type { SuggestionCreateResponse, SuggestionListResponse } from "@tambo-ai/typescript-sdk/resources/threads/suggestions";
|
|
3
|
+
import type { Suggestion } from "@tambo-ai/typescript-sdk/resources/beta/threads/suggestions";
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Provides AI-generated suggestions based on the current thread state.
|
|
5
|
-
* Uses the shared thread input context so accepting a suggestion
|
|
6
|
-
* automatically updates the input field.
|
|
5
|
+
* Response type for suggestions queries (union of list and create responses)
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
import { type UseTamboMutationResult, type UseTamboQueryResult } from "../../hooks/react-query-hooks";
|
|
10
|
-
import { CombinedMutationResult } from "../../util/query-utils";
|
|
11
|
-
type Suggestion = TamboAI.Beta.Threads.Suggestion;
|
|
12
|
-
type SuggestionGenerateResponse = TamboAI.Beta.Threads.Suggestions.SuggestionGenerateResponse;
|
|
13
|
-
type SuggestionsMutationData = void | SuggestionGenerateResponse;
|
|
7
|
+
type SuggestionsQueryResponse = SuggestionListResponse | SuggestionCreateResponse;
|
|
14
8
|
/**
|
|
15
9
|
* Configuration options for the useTamboV1Suggestions hook
|
|
16
10
|
*/
|
|
17
11
|
export interface UseTamboV1SuggestionsOptions {
|
|
18
12
|
/** Maximum number of suggestions to generate (1-10, default 3) */
|
|
19
13
|
maxSuggestions?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Whether to automatically generate suggestions when the latest message is from the assistant.
|
|
16
|
+
* Default: true
|
|
17
|
+
*/
|
|
18
|
+
autoGenerate?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Additional React Query options for the suggestions query.
|
|
21
|
+
* Allows customizing caching, refetching behavior, etc.
|
|
22
|
+
*/
|
|
23
|
+
queryOptions?: Omit<UseQueryOptions<SuggestionsQueryResponse>, "queryKey" | "queryFn" | "enabled">;
|
|
20
24
|
}
|
|
21
25
|
/**
|
|
22
|
-
*
|
|
26
|
+
* Options for accepting a suggestion
|
|
23
27
|
*/
|
|
24
|
-
export interface
|
|
25
|
-
/**
|
|
28
|
+
export interface AcceptSuggestionOptions {
|
|
29
|
+
/** The suggestion to accept */
|
|
30
|
+
suggestion: Suggestion;
|
|
31
|
+
/** Whether to automatically submit the suggestion after accepting (default: false) */
|
|
32
|
+
shouldSubmit?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Return type for useTamboV1Suggestions hook
|
|
36
|
+
*/
|
|
37
|
+
export interface UseTamboV1SuggestionsReturn {
|
|
38
|
+
/**
|
|
39
|
+
* The raw response data from the suggestions query.
|
|
40
|
+
* Use this for direct access to the API response shape.
|
|
41
|
+
*/
|
|
42
|
+
data: SuggestionsQueryResponse | undefined;
|
|
43
|
+
/** List of available suggestions for the current message (convenience accessor) */
|
|
26
44
|
suggestions: Suggestion[];
|
|
27
|
-
/**
|
|
28
|
-
|
|
45
|
+
/** Whether the suggestions query is loading (first fetch) */
|
|
46
|
+
isLoading: boolean;
|
|
47
|
+
/** Whether suggestions have been successfully loaded */
|
|
48
|
+
isSuccess: boolean;
|
|
49
|
+
/** Whether there was an error loading suggestions */
|
|
50
|
+
isError: boolean;
|
|
51
|
+
/** Error from loading suggestions, if any */
|
|
52
|
+
error: Error | null;
|
|
53
|
+
/** Whether the query is currently fetching (includes background refetches) */
|
|
54
|
+
isFetching: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Manually generate new suggestions for the current message.
|
|
57
|
+
* Use this when autoGenerate is false or to refresh suggestions.
|
|
58
|
+
*/
|
|
59
|
+
generate: () => Promise<SuggestionCreateResponse | undefined>;
|
|
60
|
+
/** Whether suggestions are being generated (mutation pending) */
|
|
61
|
+
isGenerating: boolean;
|
|
62
|
+
/** Error from generating suggestions, if any */
|
|
63
|
+
generateError: Error | null;
|
|
29
64
|
/**
|
|
30
65
|
* Accept and apply a suggestion.
|
|
31
|
-
*
|
|
32
|
-
* If shouldSubmit is true, submits the suggestion directly.
|
|
33
|
-
* @param suggestion - The suggestion to accept
|
|
34
|
-
* @param shouldSubmit - Whether to automatically submit after accepting (default: false)
|
|
66
|
+
* Sets the suggestion text as input value, optionally submitting it.
|
|
35
67
|
*/
|
|
36
|
-
accept: (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
shouldSubmit?: boolean;
|
|
44
|
-
}>;
|
|
45
|
-
/** Result and network state for generating suggestions */
|
|
46
|
-
generateResult: UseTamboMutationResult<SuggestionGenerateResponse, Error, AbortController>;
|
|
47
|
-
/** The full suggestions query object from React Query */
|
|
48
|
-
suggestionsResult: UseTamboQueryResult<SuggestionGenerateResponse>;
|
|
68
|
+
accept: (options: AcceptSuggestionOptions) => Promise<void>;
|
|
69
|
+
/** Whether accepting a suggestion is in progress */
|
|
70
|
+
isAccepting: boolean;
|
|
71
|
+
/** Error from accepting a suggestion, if any */
|
|
72
|
+
acceptError: Error | null;
|
|
73
|
+
/** ID of the currently selected suggestion */
|
|
74
|
+
selectedSuggestionId: string | null;
|
|
49
75
|
}
|
|
50
|
-
type UseTamboV1SuggestionsResult = CombinedMutationResult<SuggestionsMutationData, Error> & UseTamboV1SuggestionsResultInternal;
|
|
51
76
|
/**
|
|
52
|
-
* Hook for managing
|
|
53
|
-
*
|
|
54
|
-
* Automatically generates suggestions when the latest message is from the assistant
|
|
55
|
-
* and the thread is idle (not streaming).
|
|
77
|
+
* Hook for managing AI-powered suggestions in a v1 thread.
|
|
56
78
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @
|
|
79
|
+
* Provides functionality to:
|
|
80
|
+
* - Automatically generate suggestions when an assistant message arrives
|
|
81
|
+
* - Manually generate suggestions on demand
|
|
82
|
+
* - Accept suggestions by setting them as input or auto-submitting
|
|
83
|
+
* @param options - Configuration options
|
|
84
|
+
* @returns Suggestions state and control functions
|
|
62
85
|
* @example
|
|
63
86
|
* ```tsx
|
|
64
87
|
* function SuggestionsPanel() {
|
|
65
|
-
* const {
|
|
88
|
+
* const {
|
|
89
|
+
* suggestions,
|
|
90
|
+
* accept,
|
|
91
|
+
* isLoading,
|
|
92
|
+
* selectedSuggestionId,
|
|
93
|
+
* } = useTamboV1Suggestions();
|
|
94
|
+
*
|
|
95
|
+
* if (isLoading) return <Spinner />;
|
|
66
96
|
*
|
|
67
97
|
* return (
|
|
68
98
|
* <div>
|
|
69
|
-
* {suggestions.map(suggestion => (
|
|
99
|
+
* {suggestions.map((suggestion) => (
|
|
70
100
|
* <button
|
|
71
101
|
* key={suggestion.id}
|
|
72
102
|
* onClick={() => accept({ suggestion })}
|
|
73
|
-
*
|
|
103
|
+
* className={selectedSuggestionId === suggestion.id ? 'selected' : ''}
|
|
74
104
|
* >
|
|
75
|
-
* {suggestion.
|
|
105
|
+
* {suggestion.title}
|
|
76
106
|
* </button>
|
|
77
107
|
* ))}
|
|
78
108
|
* </div>
|
|
79
109
|
* );
|
|
80
110
|
* }
|
|
81
|
-
*
|
|
82
|
-
* function ChatInput() {
|
|
83
|
-
* // This input will automatically show the accepted suggestion
|
|
84
|
-
* const { value, setValue, submit } = useTamboV1ThreadInput();
|
|
85
|
-
* return <input value={value} onChange={e => setValue(e.target.value)} />;
|
|
86
|
-
* }
|
|
87
111
|
* ```
|
|
88
112
|
*/
|
|
89
|
-
export declare function useTamboV1Suggestions(options?: UseTamboV1SuggestionsOptions):
|
|
113
|
+
export declare function useTamboV1Suggestions(options?: UseTamboV1SuggestionsOptions): UseTamboV1SuggestionsReturn;
|
|
90
114
|
export {};
|
|
91
115
|
//# sourceMappingURL=use-tambo-v1-suggestions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-v1-suggestions.d.ts","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1-suggestions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-tambo-v1-suggestions.d.ts","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1-suggestions.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EACV,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,wDAAwD,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6DAA6D,CAAC;AAY9F;;GAEG;AACH,KAAK,wBAAwB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