@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":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAA4E;AAC5E,kEAA6D;AAE7D,mEAKiC;AACjC,yEAIoC;AACpC,2FAI6C;AAC7C,qFAK0C;AAC1C,+EAGuC;AACvC,yEAAmE;AACnE,uEAGmC;AACnC,+EAAyE;AACzE,mEAMiC;AAEjC
|
|
1
|
+
{"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAA4E;AAC5E,kEAA6D;AAE7D,mEAKiC;AACjC,yEAIoC;AACpC,2FAI6C;AAC7C,qFAK0C;AAC1C,+EAGuC;AACvC,yEAAmE;AACnE,uEAGmC;AACnC,+EAAyE;AACzE,mEAMiC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,MAAM,aAAa,GAOtB,CAAC,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAAS,EACT,UAAU,EACV,WAAW,EACX,KAAK,EACL,UAAU,EACV,SAAS,EACT,sBAAsB,EACtB,yBAAyB,EACzB,cAAc,EACd,UAAU,EACV,eAAe,EACf,sBAAsB,EACtB,WAAW,EACX,aAAa,EACb,SAAS,GACV,EAAE,EAAE;IACH,OAAO,CACL,8BAAC,2CAAmB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AC;IAC/D,MAAM,iBAAiB,GAAG,IAAA,4CAAiB,GAAE,CAAC;IAC9C,MAAM,sBAAsB,GAAG,IAAA,kDAAoB,GAAE,CAAC;IACtD,MAAM,cAAc,GAAG,IAAA,uDAAsB,GAAE,CAAC;IAChD,MAAM,iBAAiB,GAAG,IAAA,6DAAyB,GAAE,CAAC;IAEtD,OAAO,CACL,8BAAC,oBAAY,CAAC,QAAQ,IACpB,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,eAAe;YACf,GAAG,iBAAiB;YACpB,GAAG,OAAO;YACV,GAAG,sBAAsB;YACzB,GAAG,cAAc;YACjB,GAAG,iBAAiB;SACrB,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AAhCW,QAAA,sBAAsB,0BAgCjC;AAEF;;;;;;;GAOG;AACI,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,IAAA,kBAAU,EAAC,oBAAY,CAAC,CAAC;AAClC,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB","sourcesContent":["\"use client\";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport { TamboMcpProvider } from \"../mcp/tambo-mcp-provider\";\nimport { TamboInteractableContext } from \"../model/tambo-interactable\";\nimport {\n TamboClientContext,\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n ContextAttachmentState,\n TamboContextAttachmentProvider,\n useTamboContextAttachment,\n} from \"./tambo-context-attachment-provider\";\nimport {\n TamboContextHelpersContextProps,\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n useTamboContextHelpers,\n} from \"./tambo-context-helpers-provider\";\nimport {\n TamboInteractableProvider,\n useTamboInteractable,\n} from \"./tambo-interactable-provider\";\nimport { TamboMcpTokenProvider } from \"./tambo-mcp-token-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport { TamboThreadInputProvider } from \"./tambo-thread-input-provider\";\nimport {\n TamboGenerationStageContextProps,\n TamboThreadContextProps,\n TamboThreadProvider,\n TamboThreadProviderProps,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/**\n * The TamboProvider gives full access to the whole Tambo API. This includes the\n * TamboAI client, the component registry, the current thread context, and interactable components.\n * @param props - The props for the TamboProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.components - The components to register\n * @param props.environment - The environment to use for the Tambo API\n * @param props.tools - The tools to register\n * @param props.mcpServers - The MCP servers to register (metadata only - use TamboMcpProvider for connections)\n * @param props.streaming - Whether to stream the response by default. Defaults to true.\n * @param props.autoGenerateThreadName - Whether to automatically generate thread names. Defaults to true.\n * @param props.autoGenerateNameThreshold - The message count threshold at which the thread name will be auto-generated. Defaults to 3.\n * @param props.contextHelpers - Configuration for which context helpers are enabled/disabled\n * @param props.userToken - The user's OAuth token (access or ID) used to identify the user and exchange for a Tambo session token\n * @param props.contextKey - Optional context key passed to thread input provider for scoping threads\n * @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called\n * @param props.initialMessages - Initial messages to be included in new threads\n * @param props.getResource - Optional getResource function for registry resources\n * @param props.listResources - Optional listResources function for registry resources\n * @param props.resources - Optional static resources for the registry\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps &\n TamboContextHelpersProviderProps\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n userToken,\n components,\n environment,\n tools,\n mcpServers,\n streaming,\n autoGenerateThreadName,\n autoGenerateNameThreshold,\n contextHelpers,\n contextKey,\n initialMessages,\n onCallUnregisteredTool,\n getResource,\n listResources,\n resources,\n}) => {\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n userToken={userToken}\n >\n <TamboRegistryProvider\n components={components}\n tools={tools}\n mcpServers={mcpServers}\n onCallUnregisteredTool={onCallUnregisteredTool}\n getResource={getResource}\n listResources={listResources}\n resources={resources}\n >\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboThreadProvider\n contextKey={contextKey}\n streaming={streaming}\n autoGenerateThreadName={autoGenerateThreadName}\n autoGenerateNameThreshold={autoGenerateNameThreshold}\n initialMessages={initialMessages}\n >\n <TamboMcpTokenProvider>\n <TamboMcpProvider contextKey={contextKey}>\n <TamboContextAttachmentProvider>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboThreadInputProvider>\n <TamboCompositeProvider>\n {children}\n </TamboCompositeProvider>\n </TamboThreadInputProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboContextAttachmentProvider>\n </TamboMcpProvider>\n </TamboMcpTokenProvider>\n </TamboThreadProvider>\n </TamboContextHelpersProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\n\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboGenerationStageContextProps &\n TamboComponentContextProps &\n TamboInteractableContext &\n TamboContextHelpersContextProps &\n ContextAttachmentState;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, TamboComponent, and TamboInteractable providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nexport const TamboCompositeProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const threads = useTamboThread();\n const clientContext = useContext(TamboClientContext);\n if (!clientContext) {\n throw new Error(\n \"TamboCompositeProvider must be used within a TamboClientProvider\",\n );\n }\n const { client, queryClient, isUpdatingToken } = clientContext;\n const componentRegistry = useTamboComponent();\n const interactableComponents = useTamboInteractable();\n const contextHelpers = useTamboContextHelpers();\n const contextAttachment = useTamboContextAttachment();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n isUpdatingToken,\n ...componentRegistry,\n ...threads,\n ...interactableComponents,\n ...contextHelpers,\n ...contextAttachment,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\n/**\n * The useTambo hook provides access to the Tambo API. This is the primary entrypoint\n * for the Tambo React SDK.\n *\n * This includes the TamboAI client, the component registry, the current thread context,\n * and interactable component management.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-thread-input-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-thread-input-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAIlB,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAoB,MAAM,6BAA6B,CAAC;AAa5E;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;AAEX,MAAM,WAAW,4BAA6B,SAAQ,IAAI,CACxD,sBAAsB,CACpB,IAAI,EACJ,KAAK,EACH;IACE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACzC,GACD,SAAS,CACZ,EACD,QAAQ,GAAG,aAAa,CACzB;IACC,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IACxD;;;OAGG;IACH,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE;QACjB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACxC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACxC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpB,8BAA8B;IAC9B,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,yBAAyB;IACzB,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,0BAA0B;IAC1B,SAAS,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,4BAA4B;IAC5B,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,8BAA8B;IAC9B,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB;AAED,eAAO,MAAM,uBAAuB,yDAExB,CAAC;AAEb;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"tambo-thread-input-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-thread-input-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAIlB,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAoB,MAAM,6BAA6B,CAAC;AAa5E;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;AAEX,MAAM,WAAW,4BAA6B,SAAQ,IAAI,CACxD,sBAAsB,CACpB,IAAI,EACJ,KAAK,EACH;IACE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC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147
147
|
]);
|
|
148
148
|
const { mutateAsync: submitAsync, mutate: _unusedSubmit, ...mutationState } = (0, react_query_hooks_1.useTamboMutation)({
|
|
149
|
+
mutationKey: ["thread-input", thread.id],
|
|
149
150
|
mutationFn: submit,
|
|
150
151
|
});
|
|
151
152
|
const value = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-thread-input-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-thread-input-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAMe;AACf,kEAGoC;AACpC,oEAA4E;AAC5E,kEAA+D;AAC/D,oEAA+D;AAC/D,4DAAwD;AACxD,6DAA8D;AAC9D,iFAG2C;AAC3C,+EAAqE;AACrE,uEAA6D;AAC7D,mEAAyD;AAEzD;;;;GAIG;AACU,QAAA,oBAAoB,GAAG;IAClC,KAAK,EAAE,yBAAyB;IAChC,OAAO,EAAE,6CAA6C;IACtD,MAAM,EAAE,gCAAgC;IACxC,UAAU,EAAE,wBAAwB;CAC5B,CAAC;AA6CE,QAAA,uBAAuB,GAAG,IAAA,qBAAa,EAElD,SAAS,CAAC,CAAC;AAEb;;;;;;;GAOG;AACI,MAAM,wBAAwB,GAAgC,CAAC,EACpE,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,UAAU,EAAE,GAAG,IAAA,sCAAc,GAAE,CAAC;IACnE,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,IAAA,gBAAQ,EAAC,EAAE,CAAC,CAAC;IACjD,MAAM,UAAU,GAAG,IAAA,qCAAgB,GAAE,CAAC;IACtC,MAAM,UAAU,GAAG,IAAA,uCAAkB,GAAE,CAAC;IACxC,MAAM,EAAE,cAAc,EAAE,GAAG,IAAA,0CAAgB,GAAE,CAAC;IAC9C,MAAM,EAAE,2BAA2B,EAAE,GAAG,IAAA,kDAAoB,GAAE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WithChildren,\n useCallback,\n useContext,\n useState,\n} from \"react\";\nimport {\n useTamboMutation,\n UseTamboMutationResult,\n} from \"../hooks/react-query-hooks\";\nimport { StagedImage, useMessageImages } from \"../hooks/use-message-images\";\nimport { useTamboMcpServers } from \"../mcp/tambo-mcp-provider\";\nimport { ThreadInputError } from \"../model/thread-input-error\";\nimport { validateInput } from \"../model/validate-input\";\nimport { buildMessageContent } from \"../util/message-builder\";\nimport {\n extractResourceUris,\n resolveResourceContents,\n} from \"../util/resource-content-resolver\";\nimport { useTamboInteractable } from \"./tambo-interactable-provider\";\nimport { useTamboRegistry } from \"./tambo-registry-provider\";\nimport { useTamboThread } from \"./tambo-thread-provider\";\n\n/**\n * Error messages for various input-related error scenarios\n * These messages are used to provide user-friendly error feedback\n * @readonly\n */\nexport const INPUT_ERROR_MESSAGES = {\n EMPTY: \"Message cannot be empty\",\n NETWORK: \"Network error. Please check your connection\",\n SERVER: \"Server error. Please try again\",\n VALIDATION: \"Invalid message format\",\n} as const;\n\nexport interface TamboThreadInputContextProps extends Omit<\n UseTamboMutationResult<\n void,\n Error,\n | {\n contextKey?: string;\n streamResponse?: boolean;\n forceToolChoice?: string;\n additionalContext?: Record<string, any>;\n }\n | undefined\n >,\n \"mutate\" | \"mutateAsync\"\n> {\n /** Current value of the input field */\n value: string;\n /**\n * Function to update the input value\n * @param value - New value for the input field\n */\n setValue: (value: React.SetStateAction<string>) => void;\n /**\n * Function to submit the current input value\n * @param options - Submission options\n */\n submit: (options?: {\n streamResponse?: boolean;\n forceToolChoice?: string;\n additionalContext?: Record<string, any>;\n resourceNames?: Record<string, string>;\n }) => Promise<void>;\n /** Currently staged images */\n images: StagedImage[];\n /** Add a single image */\n addImage: (file: File) => Promise<void>;\n /** Add multiple images */\n addImages: (files: File[]) => Promise<void>;\n /** Remove an image by id */\n removeImage: (id: string) => void;\n /** Clear all staged images */\n clearImages: () => void;\n}\n\nexport const TamboThreadInputContext = createContext<\n TamboThreadInputContextProps | undefined\n>(undefined);\n\n/**\n * Provider that manages shared thread input state across all components\n * This ensures that useTamboThreadInput, useTamboSuggestions, and components\n * all share the same input state\n * @param props - The props for the TamboThreadInputProvider\n * @param props.children - The children to render.\n * @returns The thread input context\n */\nexport const TamboThreadInputProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const { thread, sendThreadMessage, contextKey } = useTamboThread();\n const [inputValue, setInputValue] = useState(\"\");\n const imageState = useMessageImages();\n const mcpServers = useTamboMcpServers();\n const { resourceSource } = useTamboRegistry();\n const { clearInteractableSelections } = useTamboInteractable();\n const submit = useCallback(\n async ({\n streamResponse,\n forceToolChoice,\n additionalContext,\n resourceNames = {},\n }: {\n streamResponse?: boolean;\n forceToolChoice?: string;\n additionalContext?: Record<string, any>;\n resourceNames?: Record<string, string>;\n } = {}) => {\n // Validate text input if present\n if (inputValue?.trim()) {\n const validation = validateInput(inputValue);\n if (!validation.isValid) {\n throw new ThreadInputError(\n `Cannot submit message: ${validation.error ?? INPUT_ERROR_MESSAGES.VALIDATION}`,\n { cause: validation.error },\n );\n }\n }\n\n // Check if we have content to send\n if (!inputValue.trim() && imageState.images.length === 0) {\n throw new ThreadInputError(INPUT_ERROR_MESSAGES.EMPTY, {\n cause: \"No text or images to send\",\n });\n }\n\n // Extract resource URIs from the input text and resolve content for client-side resources\n // (registry and client-side MCP servers). Internal Tambo server resources are skipped\n // since the backend can resolve them.\n const resourceUris = extractResourceUris(inputValue);\n const resolvedContent = await resolveResourceContents(\n resourceUris,\n mcpServers,\n resourceSource ?? undefined,\n );\n\n // Build message content with text, images, resource names, and resolved content\n const messageContent = buildMessageContent(\n inputValue,\n imageState.images,\n resourceNames,\n resolvedContent,\n );\n\n try {\n await sendThreadMessage(inputValue || \"Image message\", {\n threadId: thread.id,\n contextKey,\n streamResponse: streamResponse,\n forceToolChoice: forceToolChoice,\n additionalContext: additionalContext,\n content: messageContent,\n });\n clearInteractableSelections();\n } catch (error: unknown) {\n // Handle image-related errors with friendly messages\n if (imageState.images.length > 0) {\n const errorMessage =\n error instanceof Error ? error.message.toLowerCase() : \"\";\n\n // Backend not yet supporting image content type\n if (errorMessage.includes(\"unknown content part type: image\")) {\n throw new ThreadInputError(\n \"Image attachments are not yet supported by the backend. This feature is coming soon.\",\n { cause: error },\n );\n }\n\n // Handle specific model vision support errors\n // OpenAI errors\n if (\n errorMessage.includes(\n \"does not support image message content types\",\n ) ||\n (errorMessage.includes(\"invalid model\") &&\n errorMessage.includes(\n \"image_url is only supported by certain models\",\n ))\n ) {\n throw new ThreadInputError(\n \"This model doesn't support images. Please use GPT-4o, GPT-4 Turbo, or other vision-capable models.\",\n { cause: error },\n );\n }\n\n // Anthropic Claude errors\n if (\n errorMessage.includes(\"does not support image\") ||\n errorMessage.includes(\"vision not supported\")\n ) {\n throw new ThreadInputError(\n \"This Claude model doesn't support images. Please use Claude 3.5 Sonnet, Claude 3 Opus, or other vision-capable models.\",\n { cause: error },\n );\n }\n\n // Generic image/vision errors\n if (\n errorMessage.includes(\"image\") ||\n errorMessage.includes(\"vision\")\n ) {\n throw new ThreadInputError(\n \"This model doesn't support image attachments. Please use a vision-capable model.\",\n { cause: error },\n );\n }\n }\n\n throw error;\n }\n\n // Clear text after successful submission\n setInputValue(\"\");\n },\n [\n inputValue,\n sendThreadMessage,\n thread.id,\n contextKey,\n imageState,\n mcpServers,\n resourceSource,\n clearInteractableSelections,\n ],\n );\n\n const {\n mutateAsync: submitAsync,\n mutate: _unusedSubmit,\n ...mutationState\n } = useTamboMutation({\n mutationFn: submit,\n });\n\n const value = {\n ...mutationState,\n value: inputValue,\n setValue: setInputValue,\n submit: submitAsync,\n images: imageState.images,\n addImage: imageState.addImage,\n addImages: imageState.addImages,\n removeImage: imageState.removeImage,\n clearImages: imageState.clearImages,\n };\n\n return (\n <TamboThreadInputContext.Provider value={value}>\n {children}\n </TamboThreadInputContext.Provider>\n );\n};\n\n/**\n * Hook to access the shared thread input state\n * contextKey parameter is not passed here anymore. Instead, use the contextKey prop in the TamboProvider.\n * @returns The thread input context\n */\nexport const useTamboThreadInput = () => {\n const context = useContext(TamboThreadInputContext);\n if (!context) {\n throw new Error(\n \"useTamboThreadInput must be used within a TamboThreadInputProvider\",\n );\n }\n\n return context;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"tambo-thread-input-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-thread-input-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAMe;AACf,kEAGoC;AACpC,oEAA4E;AAC5E,kEAA+D;AAC/D,oEAA+D;AAC/D,4DAAwD;AACxD,6DAA8D;AAC9D,iFAG2C;AAC3C,+EAAqE;AACrE,uEAA6D;AAC7D,mEAAyD;AAEzD;;;;GAIG;AACU,QAAA,oBAAoB,GAAG;IAClC,KAAK,EAAE,yBAAyB;IAChC,OAAO,EAAE,6CAA6C;IACtD,MAAM,EAAE,gCAAgC;IACxC,UAAU,EAAE,wBAAwB;CAC5B,CAAC;AA6CE,QAAA,uBAAuB,GAAG,IAAA,qBAAa,EAElD,SAAS,CAAC,CAAC;AAEb;;;;;;;GAOG;AACI,MAAM,wBAAwB,GAAgC,CAAC,EACpE,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,UAAU,EAAE,GAAG,IAAA,sCAAc,GAAE,CAAC;IACnE,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,IAAA,gBAAQ,EAAC,EAAE,CAAC,CAAC;IACjD,MAAM,UAAU,GAAG,IAAA,qCAAgB,GAAE,CAAC;IACtC,MAAM,UAAU,GAAG,IAAA,uCAAkB,GAAE,CAAC;IACxC,MAAM,EAAE,cAAc,EAAE,GAAG,IAAA,0CAAgB,GAAE,CAAC;IAC9C,MAAM,EAAE,2BAA2B,EAAE,GAAG,IAAA,kDAAoB,GAAE,CAAC;IAC/D,MAAM,MAAM,GAAG,IAAA,mBAAW,EACxB,KAAK,EAAE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Children,\n useCallback,\n useContext,\n useState,\n} from \"react\";\nimport {\n useTamboMutation,\n UseTamboMutationResult,\n} from \"../hooks/react-query-hooks\";\nimport { StagedImage, useMessageImages } from \"../hooks/use-message-images\";\nimport { useTamboMcpServers } from \"../mcp/tambo-mcp-provider\";\nimport { ThreadInputError } from \"../model/thread-input-error\";\nimport { validateInput } from \"../model/validate-input\";\nimport { buildMessageContent } from \"../util/message-builder\";\nimport {\n extractResourceUris,\n resolveResourceContents,\n} from \"../util/resource-content-resolver\";\nimport { useTamboInteractable } from \"./tambo-interactable-provider\";\nimport { useTamboRegistry } from \"./tambo-registry-provider\";\nimport { useTamboThread } from \"./tambo-thread-provider\";\n\n/**\n * Error messages for various input-related error scenarios\n * These messages are used to provide user-friendly error feedback\n * @readonly\n */\nexport const INPUT_ERROR_MESSAGES = {\n EMPTY: \"Message cannot be empty\",\n NETWORK: \"Network error. Please check your connection\",\n SERVER: \"Server error. Please try again\",\n VALIDATION: \"Invalid message format\",\n} as const;\n\nexport interface TamboThreadInputContextProps extends Omit<\n UseTamboMutationResult<\n void,\n Error,\n | {\n contextKey?: string;\n streamResponse?: boolean;\n forceToolChoice?: string;\n additionalContext?: Record<string, any>;\n }\n | undefined\n >,\n \"mutate\" | \"mutateAsync\"\n> {\n /** Current value of the input field */\n value: string;\n /**\n * Function to update the input value\n * @param value - New value for the input field\n */\n setValue: (value: React.SetStateAction<string>) => void;\n /**\n * Function to submit the current input value\n * @param options - Submission options\n */\n submit: (options?: {\n streamResponse?: boolean;\n forceToolChoice?: string;\n additionalContext?: Record<string, any>;\n resourceNames?: Record<string, string>;\n }) => Promise<void>;\n /** Currently staged images */\n images: StagedImage[];\n /** Add a single image */\n addImage: (file: File) => Promise<void>;\n /** Add multiple images */\n addImages: (files: File[]) => Promise<void>;\n /** Remove an image by id */\n removeImage: (id: string) => void;\n /** Clear all staged images */\n clearImages: () => void;\n}\n\nexport const TamboThreadInputContext = createContext<\n TamboThreadInputContextProps | undefined\n>(undefined);\n\n/**\n * Provider that manages shared thread input state across all components\n * This ensures that useTamboThreadInput, useTamboSuggestions, and components\n * all share the same input state\n * @param props - The props for the TamboThreadInputProvider\n * @param props.children - The children to render.\n * @returns The thread input context\n */\nexport const TamboThreadInputProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const { thread, sendThreadMessage, contextKey } = useTamboThread();\n const [inputValue, setInputValue] = useState(\"\");\n const imageState = useMessageImages();\n const mcpServers = useTamboMcpServers();\n const { resourceSource } = useTamboRegistry();\n const { clearInteractableSelections } = useTamboInteractable();\n const submit = useCallback(\n async ({\n streamResponse,\n forceToolChoice,\n additionalContext,\n resourceNames = {},\n }: {\n streamResponse?: boolean;\n forceToolChoice?: string;\n additionalContext?: Record<string, any>;\n resourceNames?: Record<string, string>;\n } = {}) => {\n // Validate text input if present\n if (inputValue?.trim()) {\n const validation = validateInput(inputValue);\n if (!validation.isValid) {\n throw new ThreadInputError(\n `Cannot submit message: ${validation.error ?? INPUT_ERROR_MESSAGES.VALIDATION}`,\n { cause: validation.error },\n );\n }\n }\n\n // Check if we have content to send\n if (!inputValue.trim() && imageState.images.length === 0) {\n throw new ThreadInputError(INPUT_ERROR_MESSAGES.EMPTY, {\n cause: \"No text or images to send\",\n });\n }\n\n // Extract resource URIs from the input text and resolve content for client-side resources\n // (registry and client-side MCP servers). Internal Tambo server resources are skipped\n // since the backend can resolve them.\n const resourceUris = extractResourceUris(inputValue);\n const resolvedContent = await resolveResourceContents(\n resourceUris,\n mcpServers,\n resourceSource ?? undefined,\n );\n\n // Build message content with text, images, resource names, and resolved content\n const messageContent = buildMessageContent(\n inputValue,\n imageState.images,\n resourceNames,\n resolvedContent,\n );\n\n try {\n await sendThreadMessage(inputValue || \"Image message\", {\n threadId: thread.id,\n contextKey,\n streamResponse: streamResponse,\n forceToolChoice: forceToolChoice,\n additionalContext: additionalContext,\n content: messageContent,\n });\n clearInteractableSelections();\n } catch (error: unknown) {\n // Handle image-related errors with friendly messages\n if (imageState.images.length > 0) {\n const errorMessage =\n error instanceof Error ? error.message.toLowerCase() : \"\";\n\n // Backend not yet supporting image content type\n if (errorMessage.includes(\"unknown content part type: image\")) {\n throw new ThreadInputError(\n \"Image attachments are not yet supported by the backend. This feature is coming soon.\",\n { cause: error },\n );\n }\n\n // Handle specific model vision support errors\n // OpenAI errors\n if (\n errorMessage.includes(\n \"does not support image message content types\",\n ) ||\n (errorMessage.includes(\"invalid model\") &&\n errorMessage.includes(\n \"image_url is only supported by certain models\",\n ))\n ) {\n throw new ThreadInputError(\n \"This model doesn't support images. Please use GPT-4o, GPT-4 Turbo, or other vision-capable models.\",\n { cause: error },\n );\n }\n\n // Anthropic Claude errors\n if (\n errorMessage.includes(\"does not support image\") ||\n errorMessage.includes(\"vision not supported\")\n ) {\n throw new ThreadInputError(\n \"This Claude model doesn't support images. Please use Claude 3.5 Sonnet, Claude 3 Opus, or other vision-capable models.\",\n { cause: error },\n );\n }\n\n // Generic image/vision errors\n if (\n errorMessage.includes(\"image\") ||\n errorMessage.includes(\"vision\")\n ) {\n throw new ThreadInputError(\n \"This model doesn't support image attachments. Please use a vision-capable model.\",\n { cause: error },\n );\n }\n }\n\n throw error;\n }\n\n // Clear text after successful submission\n setInputValue(\"\");\n },\n [\n inputValue,\n sendThreadMessage,\n thread.id,\n contextKey,\n imageState,\n mcpServers,\n resourceSource,\n clearInteractableSelections,\n ],\n );\n\n const {\n mutateAsync: submitAsync,\n mutate: _unusedSubmit,\n ...mutationState\n } = useTamboMutation({\n mutationKey: [\"thread-input\", thread.id],\n mutationFn: submit,\n });\n\n const value = {\n ...mutationState,\n value: inputValue,\n setValue: setInputValue,\n submit: submitAsync,\n images: imageState.images,\n addImage: imageState.addImage,\n addImages: imageState.addImages,\n removeImage: imageState.removeImage,\n clearImages: imageState.clearImages,\n };\n\n return (\n <TamboThreadInputContext.Provider value={value}>\n {children}\n </TamboThreadInputContext.Provider>\n );\n};\n\n/**\n * Hook to access the shared thread input state\n * contextKey parameter is not passed here anymore. Instead, use the contextKey prop in the TamboProvider.\n * @returns The thread input context\n */\nexport const useTamboThreadInput = () => {\n const context = useContext(TamboThreadInputContext);\n if (!context) {\n throw new Error(\n \"useTamboThreadInput must be used within a TamboThreadInputProvider\",\n );\n }\n\n return context;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-content-resolver.d.ts","sourceRoot":"","sources":["../../src/util/resource-content-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAE7E,OAAO,KAAK,EAAsB,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"resource-content-resolver.d.ts","sourceRoot":"","sources":["../../src/util/resource-content-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAE7E,OAAO,KAAK,EAAsB,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAY7D;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CAC3C,YAAY,EAAE,MAAM,EAAE,EACtB,UAAU,EAAE,SAAS,EAAE,EACvB,cAAc,EAAE,cAAc,GAAG,SAAS,GACzC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAyE1C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAI1D"}
|
|
@@ -6,6 +6,8 @@ const mcp_constants_1 = require("../mcp/mcp-constants");
|
|
|
6
6
|
/**
|
|
7
7
|
* Type guard for narrowing McpServer to a connected server.
|
|
8
8
|
* A connected server has a non-null client.
|
|
9
|
+
* @param server - The MCP server to check
|
|
10
|
+
* @returns True if the server is connected, false otherwise
|
|
9
11
|
*/
|
|
10
12
|
function isConnectedMcpServer(server) {
|
|
11
13
|
return "client" in server && server.client != null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-content-resolver.js","sourceRoot":"","sources":["../../src/util/resource-content-resolver.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"resource-content-resolver.js","sourceRoot":"","sources":["../../src/util/resource-content-resolver.ts"],"names":[],"mappings":";;AAwBA,0DA6EC;AAOD,kDAIC;AA/GD,wDAAuE;AAIvE;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,MAAiB;IAC7C,OAAO,QAAQ,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC;AACrD,CAAC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,uBAAuB,CAC3C,YAAsB,EACtB,UAAuB,EACvB,cAA0C;IAE1C,MAAM,OAAO,GAAG,IAAI,GAAG,EAA8B,CAAC;IAEtD,MAAM,aAAa,GAAG,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;QAC3D,mCAAmC;QACnC,sFAAsF;QACtF,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5C,IAAI,UAAU,KAAK,CAAC,CAAC;YAAE,OAAO;QAE9B,MAAM,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;QACnD,MAAM,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;QAEtD,IAAI,CAAC;YACH,+DAA+D;YAC/D,8EAA8E;YAC9E,IAAI,SAAS,KAAK,mCAAmB,EAAE,CAAC;gBACtC,IAAI,CAAC,cAAc,EAAE,CAAC;oBACpB,OAAO,CAAC,IAAI,CACV,8DAA8D,WAAW,EAAE,CAC5E,CAAC;oBACF,OAAO;gBACT,CAAC;gBACD,MAAM,eAAe,GAAG,MAAM,cAAc,CA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CAAC,CAAC;IAEH,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACjC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,IAAY;IAC9C,MAAM,OAAO,GAAG,yBAAyB,CAAC;IAC1C,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACnD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,IAAI,GAAG,EAAE,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import type { ReadResourceResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport { REGISTRY_SERVER_KEY, ServerType } from \"../mcp/mcp-constants\";\nimport type { ConnectedMcpServer, McpServer } from \"../mcp/tambo-mcp-provider\";\nimport type { ResourceSource } from \"../model/resource-info\";\n\n/**\n * Type guard for narrowing McpServer to a connected server.\n * A connected server has a non-null client.\n * @param server - The MCP server to check\n * @returns True if the server is connected, false otherwise\n */\nfunction isConnectedMcpServer(server: McpServer): server is ConnectedMcpServer {\n return \"client\" in server && server.client != null;\n}\n\n/**\n * Resolves content for client-side resources (MCP and registry).\n * Server-side (internal Tambo) resources are skipped - the backend can resolve them.\n * @param resourceUris - Prefixed URIs (e.g., \"linear:file://foo\", \"registry:file://bar\", \"tambo-abc:test://resource\")\n * @param mcpServers - Active MCP servers including virtual registry server\n * @param resourceSource - Registry resource source (listResources/getResource)\n * @returns Map of prefixedUri -> ReadResourceResult for resolved resources.\n * Resources that failed to fetch or are internal server resources won't be in the map.\n */\nexport async function resolveResourceContents(\n resourceUris: string[],\n mcpServers: McpServer[],\n resourceSource: ResourceSource | undefined,\n): Promise<Map<string, ReadResourceResult>> {\n const results = new Map<string, ReadResourceResult>();\n\n const fetchPromises = resourceUris.map(async (prefixedUri) => {\n // Parse serverKey and original URI\n // Format: serverKey:originalUri (e.g., \"linear:file://foo\", \"registry:docs://readme\")\n const colonIndex = prefixedUri.indexOf(\":\");\n if (colonIndex === -1) return;\n\n const serverKey = prefixedUri.slice(0, colonIndex);\n const originalUri = prefixedUri.slice(colonIndex + 1);\n\n try {\n // Handle registry resources directly - no server lookup needed\n // Registry resources are local to the browser and resolved via resourceSource\n if (serverKey === REGISTRY_SERVER_KEY) {\n if (!resourceSource) {\n console.warn(\n `No resource source available to resolve registry resource: ${prefixedUri}`,\n );\n return;\n }\n const registryContent = await resourceSource.getResource(originalUri);\n if (registryContent) {\n results.set(prefixedUri, registryContent);\n }\n return;\n }\n\n // For non-registry resources, find the server by serverKey\n const server = mcpServers.find((s) => s.serverKey === serverKey);\n if (!server) {\n console.warn(`No server found for resource: ${prefixedUri}`);\n return;\n }\n\n switch (server.serverType) {\n case ServerType.TAMBO_INTERNAL:\n // Skip internal server resources - backend can resolve these\n return;\n\n case ServerType.TAMBO_REGISTRY:\n // Should not reach here since we handle registry above, but keep for safety\n return;\n\n case ServerType.BROWSER_SIDE: {\n // Client-side MCP resource\n if (!isConnectedMcpServer(server)) {\n console.warn(\n `MCP server not connected for resource: ${prefixedUri}`,\n );\n return;\n }\n const mcpContent = (await server.client.client.readResource({\n uri: originalUri,\n })) as ReadResourceResult | null;\n if (mcpContent) {\n results.set(prefixedUri, mcpContent);\n }\n return;\n }\n }\n } catch (error) {\n // Graceful fallback - log warning and continue without content\n console.warn(\n `Failed to fetch resource content for ${prefixedUri}:`,\n error,\n );\n }\n });\n\n await Promise.all(fetchPromises);\n return results;\n}\n\n/**\n * Extracts resource URIs from text using the `@serverKey:uri` pattern.\n * @param text - Text potentially containing resource references\n * @returns Array of prefixed resource URIs (e.g., [\"linear:file://foo\", \"registry:file://bar\"])\n */\nexport function extractResourceUris(text: string): string[] {\n const pattern = /@([a-zA-Z0-9-]+):(\\S+)/g;\n const matches = Array.from(text.matchAll(pattern));\n return matches.map(([, serverKey, uri]) => `${serverKey}:${uri}`);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v1-interactables.test.d.ts","sourceRoot":"","sources":["../../../src/v1/__tests__/v1-interactables.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = require("@testing-library/react");
|
|
7
|
+
const react_2 = __importDefault(require("react"));
|
|
8
|
+
const v3_1 = require("zod/v3");
|
|
9
|
+
const with_tambo_interactable_1 = require("../../hoc/with-tambo-interactable");
|
|
10
|
+
const tambo_interactable_provider_1 = require("../../providers/tambo-interactable-provider");
|
|
11
|
+
const tambo_context_helpers_provider_1 = require("../../providers/tambo-context-helpers-provider");
|
|
12
|
+
const tambo_registry_provider_1 = require("../../providers/tambo-registry-provider");
|
|
13
|
+
const tambo_context_helpers_provider_2 = require("../../providers/tambo-context-helpers-provider");
|
|
14
|
+
const tambo_interactable_provider_2 = require("../../providers/tambo-interactable-provider");
|
|
15
|
+
// Minimal registry mock that captures registered tools
|
|
16
|
+
function createMockRegistry() {
|
|
17
|
+
const toolRegistry = {};
|
|
18
|
+
return {
|
|
19
|
+
value: {
|
|
20
|
+
componentList: {},
|
|
21
|
+
toolRegistry,
|
|
22
|
+
componentToolAssociations: {},
|
|
23
|
+
mcpServerInfos: [],
|
|
24
|
+
resources: [],
|
|
25
|
+
resourceSource: null,
|
|
26
|
+
onCallUnregisteredTool: undefined,
|
|
27
|
+
registerComponent: jest.fn(),
|
|
28
|
+
registerTool: jest.fn((tool) => {
|
|
29
|
+
toolRegistry[tool.name] = tool;
|
|
30
|
+
}),
|
|
31
|
+
registerTools: jest.fn(),
|
|
32
|
+
addToolAssociation: jest.fn(),
|
|
33
|
+
registerMcpServer: jest.fn(),
|
|
34
|
+
registerMcpServers: jest.fn(),
|
|
35
|
+
registerResource: jest.fn(),
|
|
36
|
+
registerResources: jest.fn(),
|
|
37
|
+
registerResourceSource: jest.fn(),
|
|
38
|
+
},
|
|
39
|
+
getRegisteredToolNames: () => Object.keys(toolRegistry),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Wrapper that provides the minimal V1-compatible provider tree for interactables:
|
|
44
|
+
* TamboRegistryContext > TamboContextHelpersProvider > TamboInteractableProvider
|
|
45
|
+
*/
|
|
46
|
+
function V1InteractableWrapper({ children, registry, }) {
|
|
47
|
+
return (react_2.default.createElement(tambo_registry_provider_1.TamboRegistryContext.Provider, { value: registry },
|
|
48
|
+
react_2.default.createElement(tambo_context_helpers_provider_2.TamboContextHelpersProvider, null,
|
|
49
|
+
react_2.default.createElement(tambo_interactable_provider_2.TamboInteractableProvider, null, children))));
|
|
50
|
+
}
|
|
51
|
+
describe("V1 Interactables Integration", () => {
|
|
52
|
+
it("registers update_component_props and update_component_state tools when an interactable is added", () => {
|
|
53
|
+
const mockRegistry = createMockRegistry();
|
|
54
|
+
const { result } = (0, react_1.renderHook)(() => (0, tambo_interactable_provider_1.useTamboInteractable)(), {
|
|
55
|
+
wrapper: ({ children }) => (react_2.default.createElement(V1InteractableWrapper, { registry: mockRegistry.value }, children)),
|
|
56
|
+
});
|
|
57
|
+
(0, react_1.act)(() => {
|
|
58
|
+
result.current.addInteractableComponent({
|
|
59
|
+
name: "TestWidget",
|
|
60
|
+
description: "A test widget",
|
|
61
|
+
component: () => react_2.default.createElement("div", null, "widget"),
|
|
62
|
+
props: { label: "hello" },
|
|
63
|
+
propsSchema: v3_1.z.object({ label: v3_1.z.string() }),
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
const toolNames = mockRegistry.getRegisteredToolNames();
|
|
67
|
+
expect(toolNames.some((n) => n.startsWith("update_component_props_TestWidget"))).toBe(true);
|
|
68
|
+
expect(toolNames.some((n) => n.startsWith("update_component_state_TestWidget"))).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
it("registers interactables context helper that includes component info", async () => {
|
|
71
|
+
const mockRegistry = createMockRegistry();
|
|
72
|
+
const { result } = (0, react_1.renderHook)(() => ({
|
|
73
|
+
interactable: (0, tambo_interactable_provider_1.useTamboInteractable)(),
|
|
74
|
+
helpers: (0, tambo_context_helpers_provider_1.useTamboContextHelpers)(),
|
|
75
|
+
}), {
|
|
76
|
+
wrapper: ({ children }) => (react_2.default.createElement(V1InteractableWrapper, { registry: mockRegistry.value }, children)),
|
|
77
|
+
});
|
|
78
|
+
// Add an interactable component
|
|
79
|
+
(0, react_1.act)(() => {
|
|
80
|
+
result.current.interactable.addInteractableComponent({
|
|
81
|
+
name: "InfoCard",
|
|
82
|
+
description: "An info card",
|
|
83
|
+
component: () => react_2.default.createElement("div", null, "card"),
|
|
84
|
+
props: { title: "Test" },
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
// Get additional context - should include interactable info
|
|
88
|
+
const contexts = await (0, react_1.act)(async () => {
|
|
89
|
+
return await result.current.helpers.getAdditionalContext();
|
|
90
|
+
});
|
|
91
|
+
const interactablesContext = contexts.find((c) => c.name === "interactables");
|
|
92
|
+
expect(interactablesContext).toBeDefined();
|
|
93
|
+
expect(interactablesContext?.context).toBeDefined();
|
|
94
|
+
});
|
|
95
|
+
it("renders an interactable component via withTamboInteractable HOC", () => {
|
|
96
|
+
const mockRegistry = createMockRegistry();
|
|
97
|
+
const Card = ({ title }) => (react_2.default.createElement("div", { "data-testid": "card-title" }, title));
|
|
98
|
+
const InteractableCard = (0, with_tambo_interactable_1.withTamboInteractable)(Card, {
|
|
99
|
+
componentName: "Card",
|
|
100
|
+
description: "A card component",
|
|
101
|
+
propsSchema: v3_1.z.object({ title: v3_1.z.string() }),
|
|
102
|
+
});
|
|
103
|
+
(0, react_1.render)(react_2.default.createElement(V1InteractableWrapper, { registry: mockRegistry.value },
|
|
104
|
+
react_2.default.createElement(InteractableCard, { title: "Hello V1" })));
|
|
105
|
+
expect(react_1.screen.getByTestId("card-title")).toHaveTextContent("Hello V1");
|
|
106
|
+
});
|
|
107
|
+
it("updates component props via the interactable provider", () => {
|
|
108
|
+
const mockRegistry = createMockRegistry();
|
|
109
|
+
const Counter = ({ count }) => (react_2.default.createElement("div", { "data-testid": "count" }, count));
|
|
110
|
+
const InteractableCounter = (0, with_tambo_interactable_1.withTamboInteractable)(Counter, {
|
|
111
|
+
componentName: "Counter",
|
|
112
|
+
description: "A counter",
|
|
113
|
+
propsSchema: v3_1.z.object({ count: v3_1.z.number() }),
|
|
114
|
+
});
|
|
115
|
+
// Inner component that triggers prop updates
|
|
116
|
+
function TestHarness() {
|
|
117
|
+
const { interactableComponents, updateInteractableComponentProps } = (0, tambo_interactable_provider_1.useTamboInteractable)();
|
|
118
|
+
const component = interactableComponents[0];
|
|
119
|
+
return (react_2.default.createElement("div", null,
|
|
120
|
+
react_2.default.createElement(InteractableCounter, { count: 0 }),
|
|
121
|
+
component && (react_2.default.createElement("button", { "data-testid": "update-btn", onClick: () => updateInteractableComponentProps(component.id, { count: 42 }) }, "Update"))));
|
|
122
|
+
}
|
|
123
|
+
(0, react_1.render)(react_2.default.createElement(V1InteractableWrapper, { registry: mockRegistry.value },
|
|
124
|
+
react_2.default.createElement(TestHarness, null)));
|
|
125
|
+
// Initial render
|
|
126
|
+
expect(react_1.screen.getByTestId("count")).toHaveTextContent("0");
|
|
127
|
+
// Update props via the interactable provider
|
|
128
|
+
(0, react_1.act)(() => {
|
|
129
|
+
react_1.screen.getByTestId("update-btn").click();
|
|
130
|
+
});
|
|
131
|
+
// The interactable should reflect updated props
|
|
132
|
+
expect(react_1.screen.getByTestId("count")).toHaveTextContent("42");
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
//# sourceMappingURL=v1-interactables.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v1-interactables.test.js","sourceR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,CAAC,CAAC,CAAC,CAAC;YAE5C,OAAO,CACL;gBACE,8BAAC,mBAAmB,IAAC,KAAK,EAAE,CAAC,GAAI;gBAChC,SAAS,IAAI,CACZ,yDACc,YAAY,EACxB,OAAO,EAAE,GAAG,EAAE,CACZ,gCAAgC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,aAIxD,CACV,CACG,CACP,CAAC;QACJ,CAAC;QAED,IAAA,cAAM,EACJ,8BAAC,qBAAqB,IAAC,QAAQ,EAAE,YAAY,CAAC,KAAK;YACjD,8BAAC,WAAW,OAAG,CACO,CACzB,CAAC;QAEF,iBAAiB;QACjB,MAAM,CAAC,cAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;QAE3D,6CAA6C;QAC7C,IAAA,WAAG,EAAC,GAAG,EAAE;YACP,cAAM,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,KAAK,EAAE,CAAC;QAC3C,CAAC,CAAC,CAAC;QAEH,gDAAgD;QAChD,MAAM,CAAC,cAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { act, render, renderHook, screen } from \"@testing-library/react\";\nimport React from \"react\";\nimport { z } from \"zod/v3\";\nimport { withTamboInteractable } from \"../../hoc/with-tambo-interactable\";\nimport { useTamboInteractable } from \"../../providers/tambo-interactable-provider\";\nimport { useTamboContextHelpers } from \"../../providers/tambo-context-helpers-provider\";\nimport {\n TamboRegistryContext,\n type TamboRegistryContext as TamboRegistryContextType,\n} from \"../../providers/tambo-registry-provider\";\nimport { TamboContextHelpersProvider } from \"../../providers/tambo-context-helpers-provider\";\nimport { TamboInteractableProvider } from \"../../providers/tambo-interactable-provider\";\n\n// Minimal registry mock that captures registered tools\nfunction createMockRegistry() {\n const toolRegistry: Record<string, unknown> = {};\n return {\n value: {\n componentList: {},\n toolRegistry,\n componentToolAssociations: {},\n mcpServerInfos: [],\n resources: [],\n resourceSource: null,\n onCallUnregisteredTool: undefined,\n registerComponent: jest.fn(),\n registerTool: jest.fn((tool: { name: string }) => {\n toolRegistry[tool.name] = tool;\n }),\n registerTools: jest.fn(),\n addToolAssociation: jest.fn(),\n registerMcpServer: jest.fn(),\n registerMcpServers: jest.fn(),\n registerResource: jest.fn(),\n registerResources: jest.fn(),\n registerResourceSource: jest.fn(),\n } as unknown as TamboRegistryContextType,\n getRegisteredToolNames: () => Object.keys(toolRegistry),\n };\n}\n\n/**\n * Wrapper that provides the minimal V1-compatible provider tree for interactables:\n * TamboRegistryContext > TamboContextHelpersProvider > TamboInteractableProvider\n */\nfunction V1InteractableWrapper({\n children,\n registry,\n}: {\n children: React.ReactNode;\n registry: TamboRegistryContextType;\n}) {\n return (\n <TamboRegistryContext.Provider value={registry}>\n <TamboContextHelpersProvider>\n <TamboInteractableProvider>{children}</TamboInteractableProvider>\n </TamboContextHelpersProvider>\n </TamboRegistryContext.Provider>\n );\n}\n\ndescribe(\"V1 Interactables Integration\", () => {\n it(\"registers update_component_props and update_component_state tools when an interactable is added\", () => {\n const mockRegistry = createMockRegistry();\n\n const { result } = renderHook(() => useTamboInteractable(), {\n wrapper: ({ children }) => (\n <V1InteractableWrapper registry={mockRegistry.value}>\n {children}\n </V1InteractableWrapper>\n ),\n });\n\n act(() => {\n result.current.addInteractableComponent({\n name: \"TestWidget\",\n description: \"A test widget\",\n component: () => <div>widget</div>,\n props: { label: \"hello\" },\n propsSchema: z.object({ label: z.string() }),\n });\n });\n\n const toolNames = mockRegistry.getRegisteredToolNames();\n expect(\n toolNames.some((n) => n.startsWith(\"update_component_props_TestWidget\")),\n ).toBe(true);\n expect(\n toolNames.some((n) => n.startsWith(\"update_component_state_TestWidget\")),\n ).toBe(true);\n });\n\n it(\"registers interactables context helper that includes component info\", async () => {\n const mockRegistry = createMockRegistry();\n\n const { result } = renderHook(\n () => ({\n interactable: useTamboInteractable(),\n helpers: useTamboContextHelpers(),\n }),\n {\n wrapper: ({ children }) => (\n <V1InteractableWrapper registry={mockRegistry.value}>\n {children}\n </V1InteractableWrapper>\n ),\n },\n );\n\n // Add an interactable component\n act(() => {\n result.current.interactable.addInteractableComponent({\n name: \"InfoCard\",\n description: \"An info card\",\n component: () => <div>card</div>,\n props: { title: \"Test\" },\n });\n });\n\n // Get additional context - should include interactable info\n const contexts = await act(async () => {\n return await result.current.helpers.getAdditionalContext();\n });\n\n const interactablesContext = contexts.find(\n (c) => c.name === \"interactables\",\n );\n expect(interactablesContext).toBeDefined();\n expect(interactablesContext?.context).toBeDefined();\n });\n\n it(\"renders an interactable component via withTamboInteractable HOC\", () => {\n const mockRegistry = createMockRegistry();\n\n interface CardProps {\n title: string;\n }\n\n const Card: React.FC<CardProps> = ({ title }) => (\n <div data-testid=\"card-title\">{title}</div>\n );\n\n const InteractableCard = withTamboInteractable(Card, {\n componentName: \"Card\",\n description: \"A card component\",\n propsSchema: z.object({ title: z.string() }),\n });\n\n render(\n <V1InteractableWrapper registry={mockRegistry.value}>\n <InteractableCard title=\"Hello V1\" />\n </V1InteractableWrapper>,\n );\n\n expect(screen.getByTestId(\"card-title\")).toHaveTextContent(\"Hello V1\");\n });\n\n it(\"updates component props via the interactable provider\", () => {\n const mockRegistry = createMockRegistry();\n\n interface CounterProps {\n count: number;\n }\n\n const Counter: React.FC<CounterProps> = ({ count }) => (\n <div data-testid=\"count\">{count}</div>\n );\n\n const InteractableCounter = withTamboInteractable(Counter, {\n componentName: \"Counter\",\n description: \"A counter\",\n propsSchema: z.object({ count: z.number() }),\n });\n\n // Inner component that triggers prop updates\n function TestHarness() {\n const { interactableComponents, updateInteractableComponentProps } =\n useTamboInteractable();\n const component = interactableComponents[0];\n\n return (\n <div>\n <InteractableCounter count={0} />\n {component && (\n <button\n data-testid=\"update-btn\"\n onClick={() =>\n updateInteractableComponentProps(component.id, { count: 42 })\n }\n >\n Update\n </button>\n )}\n </div>\n );\n }\n\n render(\n <V1InteractableWrapper registry={mockRegistry.value}>\n <TestHarness />\n </V1InteractableWrapper>,\n );\n\n // Initial render\n expect(screen.getByTestId(\"count\")).toHaveTextContent(\"0\");\n\n // Update props via the interactable provider\n act(() => {\n screen.getByTestId(\"update-btn\").click();\n });\n\n // The interactable should reflect updated props\n expect(screen.getByTestId(\"count\")).toHaveTextContent(\"42\");\n });\n});\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React, { type FC } from "react";
|
|
2
|
+
import type { V1ComponentContent } from "../types/message";
|
|
3
|
+
export interface V1ComponentRendererProps {
|
|
4
|
+
/**
|
|
5
|
+
* The component content block from a v1 message
|
|
6
|
+
*/
|
|
7
|
+
content: V1ComponentContent;
|
|
8
|
+
/**
|
|
9
|
+
* The thread ID the component belongs to
|
|
10
|
+
*/
|
|
11
|
+
threadId: string;
|
|
12
|
+
/**
|
|
13
|
+
* The message ID the component belongs to
|
|
14
|
+
*/
|
|
15
|
+
messageId: string;
|
|
16
|
+
/**
|
|
17
|
+
* Optional fallback to render if component is not found in registry
|
|
18
|
+
*/
|
|
19
|
+
fallback?: React.ReactNode;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Renders a component from the registry based on component content block data.
|
|
23
|
+
*
|
|
24
|
+
* Use this component in your message renderer to display AI-generated components.
|
|
25
|
+
* The component instance is preserved across re-renders as long as React's
|
|
26
|
+
* reconciliation keeps this wrapper mounted (use content.id as key).
|
|
27
|
+
*
|
|
28
|
+
* Wraps the rendered component with V1ComponentContentProvider so that hooks
|
|
29
|
+
* like useTamboV1ComponentState can access component context.
|
|
30
|
+
* @returns The rendered component wrapped in V1ComponentContentProvider, or fallback if not found
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* function MessageContent({ content }: { content: Content }) {
|
|
34
|
+
* if (content.type === 'component') {
|
|
35
|
+
* return (
|
|
36
|
+
* <V1ComponentRenderer
|
|
37
|
+
* key={content.id}
|
|
38
|
+
* content={content}
|
|
39
|
+
* fallback={<div>Unknown component: {content.name}</div>}
|
|
40
|
+
* />
|
|
41
|
+
* );
|
|
42
|
+
* }
|
|
43
|
+
* // ... handle other content types
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare const V1ComponentRenderer: FC<V1ComponentRendererProps>;
|
|
48
|
+
//# sourceMappingURL=v1-component-renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v1-component-renderer.d.ts","sourceRoot":"","sources":["../../../src/v1/components/v1-component-renderer.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,EAAE,KAAK,EAAE,EAAuB,MAAM,OAAO,CAAC;AAK5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG3D,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,OAAO,EAAE,kBAAkB,CAAC;IAE5B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,mBAAmB,EAAE,EAAE,CAAC,wBAAwB,CAoF5D,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.V1ComponentRenderer = void 0;
|
|
38
|
+
/**
|
|
39
|
+
* V1 Component Renderer
|
|
40
|
+
*
|
|
41
|
+
* A wrapper component that renders a component from the registry based on
|
|
42
|
+
* component content block data. Uses React's normal reconciliation to maintain
|
|
43
|
+
* component identity - as long as the key stays stable, the component instance
|
|
44
|
+
* is preserved.
|
|
45
|
+
*
|
|
46
|
+
* Wraps the component with V1ComponentContentProvider so that hooks like
|
|
47
|
+
* useTamboV1ComponentState can access component context.
|
|
48
|
+
*/
|
|
49
|
+
const partial_json_1 = require("partial-json");
|
|
50
|
+
const react_1 = __importStar(require("react"));
|
|
51
|
+
const tambo_registry_provider_1 = require("../../providers/tambo-registry-provider");
|
|
52
|
+
const schema_1 = require("../../schema");
|
|
53
|
+
const is_promise_1 = require("../../util/is-promise");
|
|
54
|
+
const registry_1 = require("../../util/registry");
|
|
55
|
+
const component_renderer_1 = require("../utils/component-renderer");
|
|
56
|
+
/**
|
|
57
|
+
* Renders a component from the registry based on component content block data.
|
|
58
|
+
*
|
|
59
|
+
* Use this component in your message renderer to display AI-generated components.
|
|
60
|
+
* The component instance is preserved across re-renders as long as React's
|
|
61
|
+
* reconciliation keeps this wrapper mounted (use content.id as key).
|
|
62
|
+
*
|
|
63
|
+
* Wraps the rendered component with V1ComponentContentProvider so that hooks
|
|
64
|
+
* like useTamboV1ComponentState can access component context.
|
|
65
|
+
* @returns The rendered component wrapped in V1ComponentContentProvider, or fallback if not found
|
|
66
|
+
* @example
|
|
67
|
+
* ```tsx
|
|
68
|
+
* function MessageContent({ content }: { content: Content }) {
|
|
69
|
+
* if (content.type === 'component') {
|
|
70
|
+
* return (
|
|
71
|
+
* <V1ComponentRenderer
|
|
72
|
+
* key={content.id}
|
|
73
|
+
* content={content}
|
|
74
|
+
* fallback={<div>Unknown component: {content.name}</div>}
|
|
75
|
+
* />
|
|
76
|
+
* );
|
|
77
|
+
* }
|
|
78
|
+
* // ... handle other content types
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
const V1ComponentRenderer = ({ content, threadId, messageId, fallback = null, }) => {
|
|
83
|
+
const registry = (0, react_1.useContext)(tambo_registry_provider_1.TamboRegistryContext);
|
|
84
|
+
// Memoize the rendered element - only recreates when props change
|
|
85
|
+
const element = (0, react_1.useMemo)(() => {
|
|
86
|
+
try {
|
|
87
|
+
const registeredComponent = (0, registry_1.getComponentFromRegistry)(content.name, registry.componentList);
|
|
88
|
+
// Parse props (handles partial JSON during streaming)
|
|
89
|
+
const propsJson = JSON.stringify(content.props ?? {});
|
|
90
|
+
const parsedProps = (0, partial_json_1.parse)(propsJson);
|
|
91
|
+
let validatedProps = parsedProps;
|
|
92
|
+
// Validate props if schema is present
|
|
93
|
+
if ((0, schema_1.isStandardSchema)(registeredComponent.props)) {
|
|
94
|
+
const result = registeredComponent.props["~standard"].validate(parsedProps);
|
|
95
|
+
if ((0, is_promise_1.isPromise)(result)) {
|
|
96
|
+
// Async validation not supported - skip validation
|
|
97
|
+
console.warn(`Async schema validation not supported for component ${content.name}`);
|
|
98
|
+
}
|
|
99
|
+
else if ("value" in result) {
|
|
100
|
+
validatedProps = result.value;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Validation failed - log warning but still render with raw props
|
|
104
|
+
console.warn(`Props validation failed for component ${content.name}:`, result.issues?.[0]?.message);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return react_1.default.createElement(registeredComponent.component, validatedProps);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
console.error("[V1ComponentRenderer] Failed to render component", {
|
|
111
|
+
threadId,
|
|
112
|
+
messageId,
|
|
113
|
+
componentId: content.id,
|
|
114
|
+
componentName: content.name,
|
|
115
|
+
streamingState: content.streamingState,
|
|
116
|
+
props: content.props,
|
|
117
|
+
error,
|
|
118
|
+
});
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}, [
|
|
122
|
+
content.id,
|
|
123
|
+
content.name,
|
|
124
|
+
content.props,
|
|
125
|
+
content.streamingState,
|
|
126
|
+
messageId,
|
|
127
|
+
threadId,
|
|
128
|
+
registry.componentList,
|
|
129
|
+
]);
|
|
130
|
+
if (element === null) {
|
|
131
|
+
return react_1.default.createElement(react_1.default.Fragment, null, fallback);
|
|
132
|
+
}
|
|
133
|
+
// Wrap with provider so hooks like useTamboV1ComponentState work
|
|
134
|
+
return (react_1.default.createElement(component_renderer_1.V1ComponentContentProvider, { componentId: content.id, threadId: threadId, messageId: messageId, componentName: content.name }, element));
|
|
135
|
+
};
|
|
136
|
+
exports.V1ComponentRenderer = V1ComponentRenderer;
|
|
137
|
+
//# sourceMappingURL=v1-component-renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v1-component-renderer.js","sourceRoot":"","sources":["../../../src/v1/components/v1-component-renderer.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb;;;;;;;;;;GAUG;AAEH,+CAAqC;AACrC,+CAA4D;AAC5D,qFAA+E;AAC/E,yCAAgD;AAChD,sDAAkD;AAClD,kDAA+D;AAE/D,oEAAyE;AAwBzE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACI,MAAM,mBAAmB,GAAiC,CAAC,EAChE,OAAO,EACP,QAAQ,EACR,SAAS,EACT,QAAQ,GAAG,IAAI,GAChB,EAAE,EAAE;IACH,MAAM,QAAQ,GAAG,IAAA,kBAAU,EAAC,8CAAoB,CAAC,CAAC;IAElD,kEAAkE;IAClE,MAAM,OAAO,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QAC3B,IAAI,CAAC;YACH,MAAM,mBAAmB,GAAG,IAAA,mCAAwB,EAClD,OAAO,CAAC,IAAI,EACZ,QAAQ,CAAC,aAAa,CACvB,CAAC;YAEF,sDAAsD;YACtD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;YACtD,MAAM,WAAW,GAAG,IAAA,oBAAK,EAAC,SAAS,CAAC,CAAC;YAErC,IAAI,cAAc,GAA4B,WAG7C,CAAC;YAEF,sCAAsC;YACtC,IAAI,IAAA,yBAAgB,EAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;gBAChD,MAAM,MAAM,GACV,mBAAmB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;gBAE/D,IAAI,IAAA,sBAAS,EAAC,MAAM,CAAC,EAAE,CAAC;oBACtB,mDAAmD;oBACn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mB,CAC9B,CAAC;AACJ,CAAC,CAAC;AApFW,QAAA,mBAAmB,uBAoF9B","sourcesContent":["\"use client\";\n\n/**\n * V1 Component Renderer\n *\n * A wrapper component that renders a component from the registry based on\n * component content block data. Uses React's normal reconciliation to maintain\n * component identity - as long as the key stays stable, the component instance\n * is preserved.\n *\n * Wraps the component with V1ComponentContentProvider so that hooks like\n * useTamboV1ComponentState can access component context.\n */\n\nimport { parse } from \"partial-json\";\nimport React, { type FC, useMemo, useContext } from \"react\";\nimport { TamboRegistryContext } from \"../../providers/tambo-registry-provider\";\nimport { isStandardSchema } from \"../../schema\";\nimport { isPromise } from \"../../util/is-promise\";\nimport { getComponentFromRegistry } from \"../../util/registry\";\nimport type { V1ComponentContent } from \"../types/message\";\nimport { V1ComponentContentProvider } from \"../utils/component-renderer\";\n\nexport interface V1ComponentRendererProps {\n /**\n * The component content block from a v1 message\n */\n content: V1ComponentContent;\n\n /**\n * The thread ID the component belongs to\n */\n threadId: string;\n\n /**\n * The message ID the component belongs to\n */\n messageId: string;\n\n /**\n * Optional fallback to render if component is not found in registry\n */\n fallback?: React.ReactNode;\n}\n\n/**\n * Renders a component from the registry based on component content block data.\n *\n * Use this component in your message renderer to display AI-generated components.\n * The component instance is preserved across re-renders as long as React's\n * reconciliation keeps this wrapper mounted (use content.id as key).\n *\n * Wraps the rendered component with V1ComponentContentProvider so that hooks\n * like useTamboV1ComponentState can access component context.\n * @returns The rendered component wrapped in V1ComponentContentProvider, or fallback if not found\n * @example\n * ```tsx\n * function MessageContent({ content }: { content: Content }) {\n * if (content.type === 'component') {\n * return (\n * <V1ComponentRenderer\n * key={content.id}\n * content={content}\n * fallback={<div>Unknown component: {content.name}</div>}\n * />\n * );\n * }\n * // ... handle other content types\n * }\n * ```\n */\nexport const V1ComponentRenderer: FC<V1ComponentRendererProps> = ({\n content,\n threadId,\n messageId,\n fallback = null,\n}) => {\n const registry = useContext(TamboRegistryContext);\n\n // Memoize the rendered element - only recreates when props change\n const element = useMemo(() => {\n try {\n const registeredComponent = getComponentFromRegistry(\n content.name,\n registry.componentList,\n );\n\n // Parse props (handles partial JSON during streaming)\n const propsJson = JSON.stringify(content.props ?? {});\n const parsedProps = parse(propsJson);\n\n let validatedProps: Record<string, unknown> = parsedProps as Record<\n string,\n unknown\n >;\n\n // Validate props if schema is present\n if (isStandardSchema(registeredComponent.props)) {\n const result =\n registeredComponent.props[\"~standard\"].validate(parsedProps);\n\n if (isPromise(result)) {\n // Async validation not supported - skip validation\n console.warn(\n `Async schema validation not supported for component ${content.name}`,\n );\n } else if (\"value\" in result) {\n validatedProps = result.value as Record<string, unknown>;\n } else {\n // Validation failed - log warning but still render with raw props\n console.warn(\n `Props validation failed for component ${content.name}:`,\n result.issues?.[0]?.message,\n );\n }\n }\n\n return React.createElement(registeredComponent.component, validatedProps);\n } catch (error) {\n console.error(\"[V1ComponentRenderer] Failed to render component\", {\n threadId,\n messageId,\n componentId: content.id,\n componentName: content.name,\n streamingState: content.streamingState,\n props: content.props,\n error,\n });\n return null;\n }\n }, [\n content.id,\n content.name,\n content.props,\n content.streamingState,\n messageId,\n threadId,\n registry.componentList,\n ]);\n\n if (element === null) {\n return <>{fallback}</>;\n }\n\n // Wrap with provider so hooks like useTamboV1ComponentState work\n return (\n <V1ComponentContentProvider\n componentId={content.id}\n threadId={threadId}\n messageId={messageId}\n componentName={content.name}\n >\n {element}\n </V1ComponentContentProvider>\n );\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v1-component-renderer.test.d.ts","sourceRoot":"","sources":["../../../src/v1/components/v1-component-renderer.test.tsx"],"names":[],"mappings":""}
|