@tambo-ai/react 0.75.0 → 1.0.0-rc.4
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/dist/hoc/with-tambo-interactable.d.ts.map +1 -1
- package/dist/hoc/with-tambo-interactable.js +13 -13
- package/dist/hoc/with-tambo-interactable.js.map +1 -1
- package/dist/hoc/with-tambo-interactable.test.js +3 -3
- package/dist/hoc/with-tambo-interactable.test.js.map +1 -1
- package/dist/index.d.ts +7 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -59
- package/dist/index.js.map +1 -1
- package/dist/mcp/mcp-hooks.js +5 -5
- package/dist/mcp/mcp-hooks.js.map +1 -1
- package/dist/model/component-metadata.d.ts +4 -4
- package/dist/model/component-metadata.js.map +1 -1
- package/dist/providers/tambo-client-provider.d.ts +6 -0
- package/dist/providers/tambo-client-provider.d.ts.map +1 -1
- package/dist/providers/tambo-client-provider.js +4 -2
- package/dist/providers/tambo-client-provider.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.d.ts +1 -1
- package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js +2 -10
- package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
- package/dist/providers/tambo-interactables-additional-context.test.js +3 -19
- package/dist/providers/tambo-interactables-additional-context.test.js.map +1 -1
- package/dist/providers/tambo-mcp-token-provider.d.ts +8 -17
- package/dist/providers/tambo-mcp-token-provider.d.ts.map +1 -1
- package/dist/providers/tambo-mcp-token-provider.js +20 -97
- package/dist/providers/tambo-mcp-token-provider.js.map +1 -1
- package/dist/testing/tools.d.ts +3 -3
- package/dist/testing/tools.d.ts.map +1 -1
- package/dist/testing/tools.js.map +1 -1
- package/dist/util/registry-validators.js +1 -1
- package/dist/util/registry-validators.js.map +1 -1
- package/dist/v1/__tests__/v1-interactables.test.js +1 -1
- package/dist/v1/__tests__/v1-interactables.test.js.map +1 -1
- package/dist/v1/components/v1-component-renderer.d.ts +9 -9
- package/dist/v1/components/v1-component-renderer.d.ts.map +1 -1
- package/dist/v1/components/v1-component-renderer.js +13 -13
- package/dist/v1/components/v1-component-renderer.js.map +1 -1
- package/dist/v1/components/v1-component-renderer.test.js +15 -15
- package/dist/v1/components/v1-component-renderer.test.js.map +1 -1
- package/{esm/hooks/use-current-message.d.ts → dist/v1/hooks/use-tambo-current-message.d.ts} +30 -9
- package/dist/v1/hooks/use-tambo-current-message.d.ts.map +1 -0
- package/dist/{hooks/use-current-message.js → v1/hooks/use-tambo-current-message.js} +13 -8
- package/dist/v1/hooks/use-tambo-current-message.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-auth-state.d.ts +5 -5
- package/dist/v1/hooks/use-tambo-v1-auth-state.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-auth-state.js +8 -8
- package/dist/v1/hooks/use-tambo-v1-auth-state.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-auth-state.test.js +12 -12
- package/dist/v1/hooks/use-tambo-v1-auth-state.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-component-state.d.ts +7 -6
- package/dist/v1/hooks/use-tambo-v1-component-state.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-component-state.js +50 -24
- package/dist/v1/hooks/use-tambo-v1-component-state.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-component-state.test.js +60 -35
- package/dist/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-messages.d.ts +9 -9
- package/dist/v1/hooks/use-tambo-v1-messages.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-messages.js +4 -4
- package/dist/v1/hooks/use-tambo-v1-messages.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-messages.test.js +7 -7
- package/dist/v1/hooks/use-tambo-v1-messages.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.d.ts +3 -3
- package/dist/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.js +20 -22
- package/dist/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.test.js +51 -51
- 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 +5 -5
- package/dist/v1/hooks/use-tambo-v1-stream-status.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-stream-status.js +12 -14
- package/dist/v1/hooks/use-tambo-v1-stream-status.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-stream-status.test.js +19 -19
- package/dist/v1/hooks/use-tambo-v1-stream-status.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-suggestions.d.ts +7 -7
- package/dist/v1/hooks/use-tambo-v1-suggestions.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-suggestions.js +9 -9
- package/dist/v1/hooks/use-tambo-v1-suggestions.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-suggestions.test.js +44 -44
- package/dist/v1/hooks/use-tambo-v1-suggestions.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-input.d.ts +3 -3
- package/dist/v1/hooks/use-tambo-v1-thread-input.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-input.js +4 -4
- package/dist/v1/hooks/use-tambo-v1-thread-input.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-input.test.js +29 -29
- 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 +4 -4
- package/dist/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-list.js +5 -5
- package/dist/v1/hooks/use-tambo-v1-thread-list.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.js +13 -17
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread.d.ts +3 -3
- package/dist/v1/hooks/use-tambo-v1-thread.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread.js +4 -4
- package/dist/v1/hooks/use-tambo-v1-thread.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread.test.js +5 -5
- package/dist/v1/hooks/use-tambo-v1-thread.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1.d.ts +16 -7
- package/dist/v1/hooks/use-tambo-v1.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1.js +41 -10
- package/dist/v1/hooks/use-tambo-v1.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1.test.js +176 -48
- package/dist/v1/hooks/use-tambo-v1.test.js.map +1 -1
- package/dist/v1/index.d.ts +31 -27
- package/dist/v1/index.d.ts.map +1 -1
- package/dist/v1/index.js +45 -35
- package/dist/v1/index.js.map +1 -1
- package/dist/v1/providers/tambo-v1-provider.d.ts +20 -20
- package/dist/v1/providers/tambo-v1-provider.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-provider.js +32 -32
- package/dist/v1/providers/tambo-v1-provider.js.map +1 -1
- package/dist/v1/providers/tambo-v1-provider.test.js +22 -22
- package/dist/v1/providers/tambo-v1-provider.test.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stream-context.d.ts +15 -15
- package/dist/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-stream-context.js +17 -17
- package/dist/v1/providers/tambo-v1-stream-context.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stream-context.test.js +9 -9
- package/dist/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stub-provider.d.ts +9 -9
- package/dist/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-stub-provider.js +7 -7
- package/dist/v1/providers/tambo-v1-stub-provider.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stub-provider.test.js +25 -25
- package/dist/v1/providers/tambo-v1-stub-provider.test.js.map +1 -1
- package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts +9 -9
- package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-thread-input-provider.js +16 -16
- package/dist/v1/providers/tambo-v1-thread-input-provider.js.map +1 -1
- package/dist/v1/types/auth.d.ts +2 -2
- package/dist/v1/types/auth.d.ts.map +1 -1
- package/dist/v1/types/auth.js.map +1 -1
- package/dist/v1/types/component.d.ts +3 -3
- package/dist/v1/types/component.d.ts.map +1 -1
- package/dist/v1/types/component.js +2 -2
- package/dist/v1/types/component.js.map +1 -1
- package/dist/v1/types/event.d.ts +1 -1
- package/dist/v1/types/event.js +1 -1
- package/dist/v1/types/event.js.map +1 -1
- package/dist/v1/types/message.d.ts +17 -24
- package/dist/v1/types/message.d.ts.map +1 -1
- package/dist/v1/types/message.js +1 -1
- package/dist/v1/types/message.js.map +1 -1
- package/dist/v1/types/thread.d.ts +10 -8
- package/dist/v1/types/thread.d.ts.map +1 -1
- package/dist/v1/types/thread.js +1 -1
- package/dist/v1/types/thread.js.map +1 -1
- package/dist/v1/types/tool-choice.d.ts +1 -1
- package/dist/v1/types/tool-choice.js.map +1 -1
- package/dist/v1/utils/component-renderer.d.ts +11 -5
- package/dist/v1/utils/component-renderer.d.ts.map +1 -1
- package/dist/v1/utils/component-renderer.js +16 -7
- package/dist/v1/utils/component-renderer.js.map +1 -1
- package/dist/v1/utils/component-renderer.test.js +7 -7
- package/dist/v1/utils/component-renderer.test.js.map +1 -1
- package/dist/v1/utils/event-accumulator.d.ts +13 -13
- package/dist/v1/utils/event-accumulator.d.ts.map +1 -1
- package/dist/v1/utils/event-accumulator.js +26 -15
- package/dist/v1/utils/event-accumulator.js.map +1 -1
- package/dist/v1/utils/event-accumulator.test.js +54 -19
- package/dist/v1/utils/event-accumulator.test.js.map +1 -1
- package/dist/v1/utils/registry-conversion.d.ts +18 -18
- package/dist/v1/utils/registry-conversion.js +23 -23
- package/dist/v1/utils/registry-conversion.js.map +1 -1
- package/dist/v1/utils/stream-handler.d.ts +1 -1
- package/dist/v1/utils/stream-handler.js +1 -1
- package/dist/v1/utils/stream-handler.js.map +1 -1
- package/dist/v1/utils/thread-utils.d.ts +2 -2
- package/dist/v1/utils/thread-utils.d.ts.map +1 -1
- package/dist/v1/utils/thread-utils.js.map +1 -1
- package/dist/v1/utils/tool-call-tracker.d.ts +1 -1
- package/dist/v1/utils/tool-call-tracker.js +1 -1
- package/dist/v1/utils/tool-call-tracker.js.map +1 -1
- package/dist/v1/utils/tool-executor.d.ts +1 -1
- package/dist/v1/utils/tool-executor.js +2 -2
- package/dist/v1/utils/tool-executor.js.map +1 -1
- package/esm/hoc/with-tambo-interactable.d.ts.map +1 -1
- package/esm/hoc/with-tambo-interactable.js +13 -13
- package/esm/hoc/with-tambo-interactable.js.map +1 -1
- package/esm/hoc/with-tambo-interactable.test.js +1 -1
- package/esm/hoc/with-tambo-interactable.test.js.map +1 -1
- package/esm/index.d.ts +7 -25
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +7 -21
- package/esm/index.js.map +1 -1
- package/esm/mcp/mcp-hooks.js +1 -1
- package/esm/mcp/mcp-hooks.js.map +1 -1
- package/esm/model/component-metadata.d.ts +4 -4
- package/esm/model/component-metadata.js.map +1 -1
- package/esm/providers/tambo-client-provider.d.ts +6 -0
- package/esm/providers/tambo-client-provider.d.ts.map +1 -1
- package/esm/providers/tambo-client-provider.js +4 -2
- package/esm/providers/tambo-client-provider.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.d.ts +1 -1
- package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js +2 -10
- package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
- package/esm/providers/tambo-interactables-additional-context.test.js +3 -19
- package/esm/providers/tambo-interactables-additional-context.test.js.map +1 -1
- package/esm/providers/tambo-mcp-token-provider.d.ts +8 -17
- package/esm/providers/tambo-mcp-token-provider.d.ts.map +1 -1
- package/esm/providers/tambo-mcp-token-provider.js +20 -97
- package/esm/providers/tambo-mcp-token-provider.js.map +1 -1
- package/esm/testing/tools.d.ts +3 -3
- package/esm/testing/tools.d.ts.map +1 -1
- package/esm/testing/tools.js.map +1 -1
- package/esm/util/registry-validators.js +1 -1
- package/esm/util/registry-validators.js.map +1 -1
- package/esm/v1/__tests__/v1-interactables.test.js +1 -1
- package/esm/v1/__tests__/v1-interactables.test.js.map +1 -1
- package/esm/v1/components/v1-component-renderer.d.ts +9 -9
- package/esm/v1/components/v1-component-renderer.d.ts.map +1 -1
- package/esm/v1/components/v1-component-renderer.js +12 -12
- package/esm/v1/components/v1-component-renderer.js.map +1 -1
- package/esm/v1/components/v1-component-renderer.test.js +16 -16
- package/esm/v1/components/v1-component-renderer.test.js.map +1 -1
- package/{dist/hooks/use-current-message.d.ts → esm/v1/hooks/use-tambo-current-message.d.ts} +30 -9
- package/esm/v1/hooks/use-tambo-current-message.d.ts.map +1 -0
- package/esm/{hooks/use-current-message.js → v1/hooks/use-tambo-current-message.js} +13 -8
- package/esm/v1/hooks/use-tambo-current-message.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-auth-state.d.ts +5 -5
- package/esm/v1/hooks/use-tambo-v1-auth-state.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-auth-state.js +8 -8
- package/esm/v1/hooks/use-tambo-v1-auth-state.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-auth-state.test.js +14 -14
- package/esm/v1/hooks/use-tambo-v1-auth-state.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-component-state.d.ts +7 -6
- package/esm/v1/hooks/use-tambo-v1-component-state.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-component-state.js +50 -24
- package/esm/v1/hooks/use-tambo-v1-component-state.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-component-state.test.js +62 -37
- package/esm/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-messages.d.ts +9 -9
- package/esm/v1/hooks/use-tambo-v1-messages.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-messages.js +3 -3
- package/esm/v1/hooks/use-tambo-v1-messages.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-messages.test.js +9 -9
- package/esm/v1/hooks/use-tambo-v1-messages.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.d.ts +3 -3
- package/esm/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.js +21 -23
- package/esm/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.test.js +54 -54
- 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 +5 -5
- package/esm/v1/hooks/use-tambo-v1-stream-status.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-stream-status.js +12 -14
- package/esm/v1/hooks/use-tambo-v1-stream-status.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-stream-status.test.js +21 -21
- package/esm/v1/hooks/use-tambo-v1-stream-status.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-suggestions.d.ts +7 -7
- package/esm/v1/hooks/use-tambo-v1-suggestions.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-suggestions.js +11 -11
- package/esm/v1/hooks/use-tambo-v1-suggestions.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-suggestions.test.js +48 -48
- package/esm/v1/hooks/use-tambo-v1-suggestions.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-input.d.ts +3 -3
- package/esm/v1/hooks/use-tambo-v1-thread-input.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-input.js +3 -3
- package/esm/v1/hooks/use-tambo-v1-thread-input.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-input.test.js +32 -32
- 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 +4 -4
- package/esm/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-list.js +6 -6
- package/esm/v1/hooks/use-tambo-v1-thread-list.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.js +15 -19
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread.d.ts +3 -3
- package/esm/v1/hooks/use-tambo-v1-thread.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread.js +4 -4
- package/esm/v1/hooks/use-tambo-v1-thread.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread.test.js +6 -6
- package/esm/v1/hooks/use-tambo-v1-thread.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1.d.ts +16 -7
- package/esm/v1/hooks/use-tambo-v1.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1.js +43 -12
- package/esm/v1/hooks/use-tambo-v1.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1.test.js +178 -50
- package/esm/v1/hooks/use-tambo-v1.test.js.map +1 -1
- package/esm/v1/index.d.ts +31 -27
- package/esm/v1/index.d.ts.map +1 -1
- package/esm/v1/index.js +38 -33
- package/esm/v1/index.js.map +1 -1
- package/esm/v1/providers/tambo-v1-provider.d.ts +20 -20
- package/esm/v1/providers/tambo-v1-provider.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-provider.js +32 -32
- package/esm/v1/providers/tambo-v1-provider.js.map +1 -1
- package/esm/v1/providers/tambo-v1-provider.test.js +23 -23
- package/esm/v1/providers/tambo-v1-provider.test.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.d.ts +15 -15
- package/esm/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.js +17 -17
- package/esm/v1/providers/tambo-v1-stream-context.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.test.js +10 -10
- package/esm/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stub-provider.d.ts +9 -9
- package/esm/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-stub-provider.js +9 -9
- package/esm/v1/providers/tambo-v1-stub-provider.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stub-provider.test.js +28 -28
- package/esm/v1/providers/tambo-v1-stub-provider.test.js.map +1 -1
- package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts +9 -9
- package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-thread-input-provider.js +15 -15
- package/esm/v1/providers/tambo-v1-thread-input-provider.js.map +1 -1
- package/esm/v1/types/auth.d.ts +2 -2
- package/esm/v1/types/auth.d.ts.map +1 -1
- package/esm/v1/types/auth.js.map +1 -1
- package/esm/v1/types/component.d.ts +3 -3
- package/esm/v1/types/component.d.ts.map +1 -1
- package/esm/v1/types/component.js +2 -2
- package/esm/v1/types/component.js.map +1 -1
- package/esm/v1/types/event.d.ts +1 -1
- package/esm/v1/types/event.js +1 -1
- package/esm/v1/types/event.js.map +1 -1
- package/esm/v1/types/message.d.ts +17 -24
- package/esm/v1/types/message.d.ts.map +1 -1
- package/esm/v1/types/message.js +1 -1
- package/esm/v1/types/message.js.map +1 -1
- package/esm/v1/types/thread.d.ts +10 -8
- package/esm/v1/types/thread.d.ts.map +1 -1
- package/esm/v1/types/thread.js +1 -1
- package/esm/v1/types/thread.js.map +1 -1
- package/esm/v1/types/tool-choice.d.ts +1 -1
- package/esm/v1/types/tool-choice.js.map +1 -1
- package/esm/v1/utils/component-renderer.d.ts +11 -5
- package/esm/v1/utils/component-renderer.d.ts.map +1 -1
- package/esm/v1/utils/component-renderer.js +13 -5
- package/esm/v1/utils/component-renderer.js.map +1 -1
- package/esm/v1/utils/component-renderer.test.js +8 -8
- package/esm/v1/utils/component-renderer.test.js.map +1 -1
- package/esm/v1/utils/event-accumulator.d.ts +13 -13
- package/esm/v1/utils/event-accumulator.d.ts.map +1 -1
- package/esm/v1/utils/event-accumulator.js +26 -15
- package/esm/v1/utils/event-accumulator.js.map +1 -1
- package/esm/v1/utils/event-accumulator.test.js +54 -19
- package/esm/v1/utils/event-accumulator.test.js.map +1 -1
- package/esm/v1/utils/registry-conversion.d.ts +18 -18
- package/esm/v1/utils/registry-conversion.js +23 -23
- package/esm/v1/utils/registry-conversion.js.map +1 -1
- package/esm/v1/utils/stream-handler.d.ts +1 -1
- package/esm/v1/utils/stream-handler.js +1 -1
- package/esm/v1/utils/stream-handler.js.map +1 -1
- package/esm/v1/utils/thread-utils.d.ts +2 -2
- package/esm/v1/utils/thread-utils.d.ts.map +1 -1
- package/esm/v1/utils/thread-utils.js.map +1 -1
- package/esm/v1/utils/tool-call-tracker.d.ts +1 -1
- package/esm/v1/utils/tool-call-tracker.js +1 -1
- package/esm/v1/utils/tool-call-tracker.js.map +1 -1
- package/esm/v1/utils/tool-executor.d.ts +1 -1
- package/esm/v1/utils/tool-executor.js +2 -2
- package/esm/v1/utils/tool-executor.js.map +1 -1
- package/package.json +4 -9
- package/dist/hooks/index.d.ts +0 -9
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -34
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/use-component-state.d.ts +0 -30
- package/dist/hooks/use-component-state.d.ts.map +0 -1
- package/dist/hooks/use-component-state.js +0 -139
- package/dist/hooks/use-component-state.js.map +0 -1
- package/dist/hooks/use-component-state.test.d.ts +0 -2
- package/dist/hooks/use-component-state.test.d.ts.map +0 -1
- package/dist/hooks/use-component-state.test.js +0 -406
- package/dist/hooks/use-component-state.test.js.map +0 -1
- package/dist/hooks/use-current-message.d.ts.map +0 -1
- package/dist/hooks/use-current-message.js.map +0 -1
- package/dist/hooks/use-current-message.test.d.ts +0 -2
- package/dist/hooks/use-current-message.test.d.ts.map +0 -1
- package/dist/hooks/use-current-message.test.js +0 -269
- package/dist/hooks/use-current-message.test.js.map +0 -1
- package/dist/hooks/use-streaming-props.d.ts +0 -11
- package/dist/hooks/use-streaming-props.d.ts.map +0 -1
- package/dist/hooks/use-streaming-props.js +0 -37
- package/dist/hooks/use-streaming-props.js.map +0 -1
- package/dist/hooks/use-suggestions.d.ts +0 -46
- package/dist/hooks/use-suggestions.d.ts.map +0 -1
- package/dist/hooks/use-suggestions.js +0 -118
- package/dist/hooks/use-suggestions.js.map +0 -1
- package/dist/hooks/use-suggestions.test.d.ts +0 -2
- package/dist/hooks/use-suggestions.test.d.ts.map +0 -1
- package/dist/hooks/use-suggestions.test.js +0 -247
- package/dist/hooks/use-suggestions.test.js.map +0 -1
- package/dist/hooks/use-tambo-stream-status.d.ts +0 -90
- package/dist/hooks/use-tambo-stream-status.d.ts.map +0 -1
- package/dist/hooks/use-tambo-stream-status.js +0 -213
- package/dist/hooks/use-tambo-stream-status.js.map +0 -1
- package/dist/hooks/use-tambo-stream-status.test.d.ts +0 -2
- package/dist/hooks/use-tambo-stream-status.test.d.ts.map +0 -1
- package/dist/hooks/use-tambo-stream-status.test.js +0 -378
- package/dist/hooks/use-tambo-stream-status.test.js.map +0 -1
- package/dist/hooks/use-tambo-threads.d.ts +0 -158
- package/dist/hooks/use-tambo-threads.d.ts.map +0 -1
- package/dist/hooks/use-tambo-threads.js +0 -45
- package/dist/hooks/use-tambo-threads.js.map +0 -1
- package/dist/hooks/use-tambo-threads.test.d.ts +0 -2
- package/dist/hooks/use-tambo-threads.test.d.ts.map +0 -1
- package/dist/hooks/use-tambo-threads.test.js +0 -214
- package/dist/hooks/use-tambo-threads.test.js.map +0 -1
- package/dist/model/generate-component-response.d.ts +0 -37
- package/dist/model/generate-component-response.d.ts.map +0 -1
- package/dist/model/generate-component-response.js +0 -29
- package/dist/model/generate-component-response.js.map +0 -1
- package/dist/model/tambo-thread.d.ts +0 -15
- package/dist/model/tambo-thread.d.ts.map +0 -1
- package/dist/model/tambo-thread.js +0 -3
- package/dist/model/tambo-thread.js.map +0 -1
- package/dist/providers/__tests__/thread-input-resource-resolution.test.d.ts +0 -2
- package/dist/providers/__tests__/thread-input-resource-resolution.test.d.ts.map +0 -1
- package/dist/providers/__tests__/thread-input-resource-resolution.test.js +0 -592
- package/dist/providers/__tests__/thread-input-resource-resolution.test.js.map +0 -1
- package/dist/providers/index.d.ts +0 -13
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/providers/index.js +0 -41
- package/dist/providers/index.js.map +0 -1
- package/dist/providers/tambo-component-provider.d.ts +0 -23
- package/dist/providers/tambo-component-provider.d.ts.map +0 -1
- package/dist/providers/tambo-component-provider.js +0 -88
- package/dist/providers/tambo-component-provider.js.map +0 -1
- package/dist/providers/tambo-prop-stream-provider/index.d.ts +0 -19
- package/dist/providers/tambo-prop-stream-provider/index.d.ts.map +0 -1
- package/dist/providers/tambo-prop-stream-provider/index.js +0 -43
- package/dist/providers/tambo-prop-stream-provider/index.js.map +0 -1
- package/dist/providers/tambo-prop-stream-provider/pending.d.ts +0 -12
- package/dist/providers/tambo-prop-stream-provider/pending.d.ts.map +0 -1
- package/dist/providers/tambo-prop-stream-provider/pending.js +0 -31
- package/dist/providers/tambo-prop-stream-provider/pending.js.map +0 -1
- package/dist/providers/tambo-prop-stream-provider/provider.d.ts +0 -17
- package/dist/providers/tambo-prop-stream-provider/provider.d.ts.map +0 -1
- package/dist/providers/tambo-prop-stream-provider/provider.js +0 -107
- package/dist/providers/tambo-prop-stream-provider/provider.js.map +0 -1
- package/dist/providers/tambo-prop-stream-provider/streaming.d.ts +0 -12
- package/dist/providers/tambo-prop-stream-provider/streaming.d.ts.map +0 -1
- package/dist/providers/tambo-prop-stream-provider/streaming.js +0 -28
- package/dist/providers/tambo-prop-stream-provider/streaming.js.map +0 -1
- package/dist/providers/tambo-prop-stream-provider/success.d.ts +0 -12
- package/dist/providers/tambo-prop-stream-provider/success.d.ts.map +0 -1
- package/dist/providers/tambo-prop-stream-provider/success.js +0 -28
- package/dist/providers/tambo-prop-stream-provider/success.js.map +0 -1
- package/dist/providers/tambo-prop-stream-provider/types.d.ts +0 -25
- package/dist/providers/tambo-prop-stream-provider/types.d.ts.map +0 -1
- package/dist/providers/tambo-prop-stream-provider/types.js +0 -6
- package/dist/providers/tambo-prop-stream-provider/types.js.map +0 -1
- package/dist/providers/tambo-prop-stream-provider.test.d.ts +0 -2
- package/dist/providers/tambo-prop-stream-provider.test.d.ts.map +0 -1
- package/dist/providers/tambo-prop-stream-provider.test.js +0 -275
- package/dist/providers/tambo-prop-stream-provider.test.js.map +0 -1
- package/dist/providers/tambo-provider.d.ts +0 -53
- package/dist/providers/tambo-provider.d.ts.map +0 -1
- package/dist/providers/tambo-provider.js +0 -133
- package/dist/providers/tambo-provider.js.map +0 -1
- package/dist/providers/tambo-stubs.d.ts +0 -89
- package/dist/providers/tambo-stubs.d.ts.map +0 -1
- package/dist/providers/tambo-stubs.js +0 -279
- package/dist/providers/tambo-stubs.js.map +0 -1
- package/dist/providers/tambo-stubs.test.d.ts +0 -2
- package/dist/providers/tambo-stubs.test.d.ts.map +0 -1
- package/dist/providers/tambo-stubs.test.js +0 -97
- package/dist/providers/tambo-stubs.test.js.map +0 -1
- package/dist/providers/tambo-thread-input-provider.d.ts +0 -65
- package/dist/providers/tambo-thread-input-provider.d.ts.map +0 -1
- package/dist/providers/tambo-thread-input-provider.js +0 -179
- package/dist/providers/tambo-thread-input-provider.js.map +0 -1
- package/dist/providers/tambo-thread-provider-initial-messages.test.d.ts +0 -2
- package/dist/providers/tambo-thread-provider-initial-messages.test.d.ts.map +0 -1
- package/dist/providers/tambo-thread-provider-initial-messages.test.js +0 -278
- package/dist/providers/tambo-thread-provider-initial-messages.test.js.map +0 -1
- package/dist/providers/tambo-thread-provider.d.ts +0 -126
- package/dist/providers/tambo-thread-provider.d.ts.map +0 -1
- package/dist/providers/tambo-thread-provider.js +0 -931
- package/dist/providers/tambo-thread-provider.js.map +0 -1
- package/dist/providers/tambo-thread-provider.test.d.ts +0 -2
- package/dist/providers/tambo-thread-provider.test.d.ts.map +0 -1
- package/dist/providers/tambo-thread-provider.test.js +0 -1591
- package/dist/providers/tambo-thread-provider.test.js.map +0 -1
- package/dist/util/generate-component.d.ts +0 -12
- package/dist/util/generate-component.d.ts.map +0 -1
- package/dist/util/generate-component.js +0 -58
- package/dist/util/generate-component.js.map +0 -1
- package/dist/util/generate-component.test.d.ts +0 -2
- package/dist/util/generate-component.test.d.ts.map +0 -1
- package/dist/util/generate-component.test.js +0 -340
- package/dist/util/generate-component.test.js.map +0 -1
- package/esm/hooks/index.d.ts +0 -9
- package/esm/hooks/index.d.ts.map +0 -1
- package/esm/hooks/index.js +0 -10
- package/esm/hooks/index.js.map +0 -1
- package/esm/hooks/use-component-state.d.ts +0 -30
- package/esm/hooks/use-component-state.d.ts.map +0 -1
- package/esm/hooks/use-component-state.js +0 -136
- package/esm/hooks/use-component-state.js.map +0 -1
- package/esm/hooks/use-component-state.test.d.ts +0 -2
- package/esm/hooks/use-component-state.test.d.ts.map +0 -1
- package/esm/hooks/use-component-state.test.js +0 -401
- package/esm/hooks/use-component-state.test.js.map +0 -1
- package/esm/hooks/use-current-message.d.ts.map +0 -1
- package/esm/hooks/use-current-message.js.map +0 -1
- package/esm/hooks/use-current-message.test.d.ts +0 -2
- package/esm/hooks/use-current-message.test.d.ts.map +0 -1
- package/esm/hooks/use-current-message.test.js +0 -264
- package/esm/hooks/use-current-message.test.js.map +0 -1
- package/esm/hooks/use-streaming-props.d.ts +0 -11
- package/esm/hooks/use-streaming-props.d.ts.map +0 -1
- package/esm/hooks/use-streaming-props.js +0 -34
- package/esm/hooks/use-streaming-props.js.map +0 -1
- package/esm/hooks/use-suggestions.d.ts +0 -46
- package/esm/hooks/use-suggestions.d.ts.map +0 -1
- package/esm/hooks/use-suggestions.js +0 -115
- package/esm/hooks/use-suggestions.js.map +0 -1
- package/esm/hooks/use-suggestions.test.d.ts +0 -2
- package/esm/hooks/use-suggestions.test.d.ts.map +0 -1
- package/esm/hooks/use-suggestions.test.js +0 -245
- package/esm/hooks/use-suggestions.test.js.map +0 -1
- package/esm/hooks/use-tambo-stream-status.d.ts +0 -90
- package/esm/hooks/use-tambo-stream-status.d.ts.map +0 -1
- package/esm/hooks/use-tambo-stream-status.js +0 -210
- package/esm/hooks/use-tambo-stream-status.js.map +0 -1
- package/esm/hooks/use-tambo-stream-status.test.d.ts +0 -2
- package/esm/hooks/use-tambo-stream-status.test.d.ts.map +0 -1
- package/esm/hooks/use-tambo-stream-status.test.js +0 -376
- package/esm/hooks/use-tambo-stream-status.test.js.map +0 -1
- package/esm/hooks/use-tambo-threads.d.ts +0 -158
- package/esm/hooks/use-tambo-threads.d.ts.map +0 -1
- package/esm/hooks/use-tambo-threads.js +0 -42
- package/esm/hooks/use-tambo-threads.js.map +0 -1
- package/esm/hooks/use-tambo-threads.test.d.ts +0 -2
- package/esm/hooks/use-tambo-threads.test.d.ts.map +0 -1
- package/esm/hooks/use-tambo-threads.test.js +0 -212
- package/esm/hooks/use-tambo-threads.test.js.map +0 -1
- package/esm/model/generate-component-response.d.ts +0 -37
- package/esm/model/generate-component-response.d.ts.map +0 -1
- package/esm/model/generate-component-response.js +0 -25
- package/esm/model/generate-component-response.js.map +0 -1
- package/esm/model/tambo-thread.d.ts +0 -15
- package/esm/model/tambo-thread.d.ts.map +0 -1
- package/esm/model/tambo-thread.js +0 -2
- package/esm/model/tambo-thread.js.map +0 -1
- package/esm/providers/__tests__/thread-input-resource-resolution.test.d.ts +0 -2
- package/esm/providers/__tests__/thread-input-resource-resolution.test.d.ts.map +0 -1
- package/esm/providers/__tests__/thread-input-resource-resolution.test.js +0 -587
- package/esm/providers/__tests__/thread-input-resource-resolution.test.js.map +0 -1
- package/esm/providers/index.d.ts +0 -13
- package/esm/providers/index.d.ts.map +0 -1
- package/esm/providers/index.js +0 -11
- package/esm/providers/index.js.map +0 -1
- package/esm/providers/tambo-component-provider.d.ts +0 -23
- package/esm/providers/tambo-component-provider.d.ts.map +0 -1
- package/esm/providers/tambo-component-provider.js +0 -50
- package/esm/providers/tambo-component-provider.js.map +0 -1
- package/esm/providers/tambo-prop-stream-provider/index.d.ts +0 -19
- package/esm/providers/tambo-prop-stream-provider/index.d.ts.map +0 -1
- package/esm/providers/tambo-prop-stream-provider/index.js +0 -22
- package/esm/providers/tambo-prop-stream-provider/index.js.map +0 -1
- package/esm/providers/tambo-prop-stream-provider/pending.d.ts +0 -12
- package/esm/providers/tambo-prop-stream-provider/pending.d.ts.map +0 -1
- package/esm/providers/tambo-prop-stream-provider/pending.js +0 -24
- package/esm/providers/tambo-prop-stream-provider/pending.js.map +0 -1
- package/esm/providers/tambo-prop-stream-provider/provider.d.ts +0 -17
- package/esm/providers/tambo-prop-stream-provider/provider.d.ts.map +0 -1
- package/esm/providers/tambo-prop-stream-provider/provider.js +0 -70
- package/esm/providers/tambo-prop-stream-provider/provider.js.map +0 -1
- package/esm/providers/tambo-prop-stream-provider/streaming.d.ts +0 -12
- package/esm/providers/tambo-prop-stream-provider/streaming.d.ts.map +0 -1
- package/esm/providers/tambo-prop-stream-provider/streaming.js +0 -21
- package/esm/providers/tambo-prop-stream-provider/streaming.js.map +0 -1
- package/esm/providers/tambo-prop-stream-provider/success.d.ts +0 -12
- package/esm/providers/tambo-prop-stream-provider/success.d.ts.map +0 -1
- package/esm/providers/tambo-prop-stream-provider/success.js +0 -21
- package/esm/providers/tambo-prop-stream-provider/success.js.map +0 -1
- package/esm/providers/tambo-prop-stream-provider/types.d.ts +0 -25
- package/esm/providers/tambo-prop-stream-provider/types.d.ts.map +0 -1
- package/esm/providers/tambo-prop-stream-provider/types.js +0 -3
- package/esm/providers/tambo-prop-stream-provider/types.js.map +0 -1
- package/esm/providers/tambo-prop-stream-provider.test.d.ts +0 -2
- package/esm/providers/tambo-prop-stream-provider.test.d.ts.map +0 -1
- package/esm/providers/tambo-prop-stream-provider.test.js +0 -270
- package/esm/providers/tambo-prop-stream-provider.test.js.map +0 -1
- package/esm/providers/tambo-provider.d.ts +0 -53
- package/esm/providers/tambo-provider.d.ts.map +0 -1
- package/esm/providers/tambo-provider.js +0 -94
- package/esm/providers/tambo-provider.js.map +0 -1
- package/esm/providers/tambo-stubs.d.ts +0 -89
- package/esm/providers/tambo-stubs.d.ts.map +0 -1
- package/esm/providers/tambo-stubs.js +0 -242
- package/esm/providers/tambo-stubs.js.map +0 -1
- package/esm/providers/tambo-stubs.test.d.ts +0 -2
- package/esm/providers/tambo-stubs.test.d.ts.map +0 -1
- package/esm/providers/tambo-stubs.test.js +0 -62
- package/esm/providers/tambo-stubs.test.js.map +0 -1
- package/esm/providers/tambo-thread-input-provider.d.ts +0 -65
- package/esm/providers/tambo-thread-input-provider.d.ts.map +0 -1
- package/esm/providers/tambo-thread-input-provider.js +0 -141
- package/esm/providers/tambo-thread-input-provider.js.map +0 -1
- package/esm/providers/tambo-thread-provider-initial-messages.test.d.ts +0 -2
- package/esm/providers/tambo-thread-provider-initial-messages.test.d.ts.map +0 -1
- package/esm/providers/tambo-thread-provider-initial-messages.test.js +0 -273
- package/esm/providers/tambo-thread-provider-initial-messages.test.js.map +0 -1
- package/esm/providers/tambo-thread-provider.d.ts +0 -126
- package/esm/providers/tambo-thread-provider.d.ts.map +0 -1
- package/esm/providers/tambo-thread-provider.js +0 -891
- package/esm/providers/tambo-thread-provider.js.map +0 -1
- package/esm/providers/tambo-thread-provider.test.d.ts +0 -2
- package/esm/providers/tambo-thread-provider.test.d.ts.map +0 -1
- package/esm/providers/tambo-thread-provider.test.js +0 -1553
- package/esm/providers/tambo-thread-provider.test.js.map +0 -1
- package/esm/util/generate-component.d.ts +0 -12
- package/esm/util/generate-component.d.ts.map +0 -1
- package/esm/util/generate-component.js +0 -52
- package/esm/util/generate-component.js.map +0 -1
- package/esm/util/generate-component.test.d.ts +0 -2
- package/esm/util/generate-component.test.d.ts.map +0 -1
- package/esm/util/generate-component.test.js +0 -302
- package/esm/util/generate-component.test.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-mcp-token-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-mcp-token-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,
|
|
1
|
+
{"version":3,"file":"tambo-mcp-token-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-mcp-token-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,KAAK,iBAAiB,EAMvB,MAAM,OAAO,CAAC;AAGf,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B;;;OAGG;IACH,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC;AAMD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAsB7D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAC3B,aAAa,MAAM,KAClB,yBA+CF,CAAC"}
|
|
@@ -37,21 +37,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
37
37
|
exports.useTamboMcpToken = exports.TamboMcpTokenProvider = void 0;
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const tambo_client_provider_1 = require("./tambo-client-provider");
|
|
40
|
-
const tambo_thread_provider_1 = require("./tambo-thread-provider");
|
|
41
40
|
const TamboMcpTokenContext = (0, react_1.createContext)(undefined);
|
|
42
41
|
/**
|
|
43
42
|
* Provider for managing the MCP access token that is returned by the Tambo API.
|
|
44
43
|
* This token is used to authenticate with the internal Tambo MCP server.
|
|
45
44
|
*
|
|
46
|
-
* Token
|
|
47
|
-
*
|
|
48
|
-
* - Returns null if no thread or thread has no token
|
|
49
|
-
*
|
|
50
|
-
* Token fetching:
|
|
51
|
-
* - Thread-specific token: always fetched when switching to thread without token
|
|
52
|
-
* - Tokens are fetched regardless of client-side MCP server configuration
|
|
53
|
-
* to support server-side MCP servers that are not visible to the provider
|
|
54
|
-
* - Threadless tokens must be fetched by individual hooks/callbacks using contextKey
|
|
45
|
+
* Exposes the base URL and a null token by default. Token fetching is handled
|
|
46
|
+
* by the useTamboMcpToken hook which supports contextKey-based token retrieval.
|
|
55
47
|
* @internal
|
|
56
48
|
* @param props - The provider props
|
|
57
49
|
* @param props.children - The children to wrap
|
|
@@ -64,71 +56,17 @@ const TamboMcpTokenProvider = ({ children, }) => {
|
|
|
64
56
|
}
|
|
65
57
|
const { client } = clientContext;
|
|
66
58
|
const tamboBaseUrl = client.baseURL;
|
|
67
|
-
|
|
68
|
-
const threadContext = (0, react_1.useContext)(tambo_thread_provider_1.TamboThreadContext);
|
|
69
|
-
const currentThread = threadContext?.currentThread ?? null;
|
|
70
|
-
const currentThreadId = threadContext?.currentThreadId ?? null;
|
|
71
|
-
const setThreadMap = (0, react_1.useMemo)(() => threadContext?.setThreadMap ?? (() => { }), [threadContext?.setThreadMap]);
|
|
72
|
-
// Track previous thread ID to detect thread switches
|
|
73
|
-
const previousThreadId = (0, react_1.useRef)(null);
|
|
74
|
-
// Return the current thread's token or null
|
|
75
|
-
const selectedToken = (0, react_1.useMemo)(() => {
|
|
76
|
-
return currentThread?.mcpAccessToken ?? null;
|
|
77
|
-
}, [currentThread]);
|
|
78
|
-
// Fetch thread-specific token when switching to a thread without one
|
|
79
|
-
// Always fetch to support server-side MCP servers (not just client-side)
|
|
80
|
-
// Skip PLACEHOLDER_THREAD - never send it to the server
|
|
81
|
-
(0, react_1.useEffect)(() => {
|
|
82
|
-
const hasThreadChanged = previousThreadId.current !== currentThreadId;
|
|
83
|
-
previousThreadId.current = currentThreadId;
|
|
84
|
-
const isPlaceholderThread = currentThreadId === tambo_thread_provider_1.PLACEHOLDER_THREAD.id;
|
|
85
|
-
const shouldFetchThreadToken = hasThreadChanged &&
|
|
86
|
-
currentThreadId &&
|
|
87
|
-
!isPlaceholderThread &&
|
|
88
|
-
currentThread &&
|
|
89
|
-
!currentThread.mcpAccessToken;
|
|
90
|
-
if (shouldFetchThreadToken) {
|
|
91
|
-
const fetchThreadToken = async () => {
|
|
92
|
-
try {
|
|
93
|
-
const response = await client.beta.auth.getMcpToken({
|
|
94
|
-
threadId: currentThreadId,
|
|
95
|
-
});
|
|
96
|
-
if (response.mcpAccessToken) {
|
|
97
|
-
// Update thread in threadMap with new token
|
|
98
|
-
setThreadMap((prev) => {
|
|
99
|
-
const thread = prev[currentThreadId];
|
|
100
|
-
if (thread) {
|
|
101
|
-
return {
|
|
102
|
-
...prev,
|
|
103
|
-
[currentThreadId]: {
|
|
104
|
-
...thread,
|
|
105
|
-
mcpAccessToken: response.mcpAccessToken,
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
return prev;
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
console.error(`Failed to fetch MCP token for thread ${currentThreadId}:`, error);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
void fetchThreadToken();
|
|
118
|
-
}
|
|
119
|
-
}, [currentThreadId, currentThread, client, setThreadMap]);
|
|
120
|
-
const value = (0, react_1.useMemo)(() => ({ mcpAccessToken: selectedToken, tamboBaseUrl }), [selectedToken, tamboBaseUrl]);
|
|
59
|
+
const value = (0, react_1.useMemo)(() => ({ mcpAccessToken: null, tamboBaseUrl }), [tamboBaseUrl]);
|
|
121
60
|
return (react_1.default.createElement(TamboMcpTokenContext.Provider, { value: value }, children));
|
|
122
61
|
};
|
|
123
62
|
exports.TamboMcpTokenProvider = TamboMcpTokenProvider;
|
|
124
63
|
/**
|
|
125
|
-
* Hook to access the current MCP access token with optional
|
|
64
|
+
* Hook to access the current MCP access token with optional token fetching.
|
|
126
65
|
*
|
|
127
|
-
* Token
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* @param contextKey - Optional context key for fetching threadless tokens when not in a thread
|
|
66
|
+
* Token fetching logic:
|
|
67
|
+
* - If contextKey is provided → fetches a token using that contextKey
|
|
68
|
+
* - Otherwise → returns null
|
|
69
|
+
* @param contextKey - Optional context key for fetching tokens
|
|
132
70
|
* @returns The current MCP access token and base URL
|
|
133
71
|
*/
|
|
134
72
|
const useTamboMcpToken = (contextKey) => {
|
|
@@ -141,45 +79,30 @@ const useTamboMcpToken = (contextKey) => {
|
|
|
141
79
|
throw new Error("useTamboMcpToken must be used within a TamboClientProvider");
|
|
142
80
|
}
|
|
143
81
|
const { client } = clientContext;
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
// State for threadless token
|
|
147
|
-
const [threadlessToken, setThreadlessToken] = (0, react_1.useState)(null);
|
|
82
|
+
// State for fetched token
|
|
83
|
+
const [fetchedToken, setFetchedToken] = (0, react_1.useState)(null);
|
|
148
84
|
const hasAttemptedFetch = (0, react_1.useRef)(false);
|
|
149
|
-
// Determine if we should fetch a
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
(!currentThreadId || isPlaceholderThread) &&
|
|
153
|
-
!context.mcpAccessToken &&
|
|
154
|
-
!threadlessToken &&
|
|
155
|
-
!hasAttemptedFetch.current;
|
|
156
|
-
// Fetch threadless token when needed
|
|
85
|
+
// Determine if we should fetch a token
|
|
86
|
+
const shouldFetch = contextKey && !fetchedToken && !hasAttemptedFetch.current;
|
|
87
|
+
// Fetch token when needed
|
|
157
88
|
(0, react_1.useEffect)(() => {
|
|
158
|
-
if (
|
|
89
|
+
if (shouldFetch) {
|
|
159
90
|
hasAttemptedFetch.current = true;
|
|
160
|
-
const
|
|
91
|
+
const fetchToken = async () => {
|
|
161
92
|
try {
|
|
162
93
|
const response = await client.beta.auth.getMcpToken({ contextKey });
|
|
163
94
|
if (response.mcpAccessToken) {
|
|
164
|
-
|
|
95
|
+
setFetchedToken(response.mcpAccessToken);
|
|
165
96
|
}
|
|
166
97
|
}
|
|
167
98
|
catch (error) {
|
|
168
|
-
console.error("Failed to fetch
|
|
99
|
+
console.error("Failed to fetch MCP token:", error);
|
|
169
100
|
}
|
|
170
101
|
};
|
|
171
|
-
void
|
|
172
|
-
}
|
|
173
|
-
}, [shouldFetchThreadless, client, contextKey]);
|
|
174
|
-
// Reset threadless token when switching to a real thread
|
|
175
|
-
(0, react_1.useEffect)(() => {
|
|
176
|
-
if (currentThreadId && currentThreadId !== tambo_thread_provider_1.PLACEHOLDER_THREAD.id) {
|
|
177
|
-
setThreadlessToken(null);
|
|
178
|
-
hasAttemptedFetch.current = false;
|
|
102
|
+
void fetchToken();
|
|
179
103
|
}
|
|
180
|
-
}, [
|
|
181
|
-
|
|
182
|
-
const selectedToken = context.mcpAccessToken ?? threadlessToken;
|
|
104
|
+
}, [shouldFetch, client, contextKey]);
|
|
105
|
+
const selectedToken = fetchedToken;
|
|
183
106
|
return {
|
|
184
107
|
mcpAccessToken: selectedToken,
|
|
185
108
|
tamboBaseUrl: context.tamboBaseUrl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-mcp-token-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-mcp-token-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAQe;AAEf,mEAA6D;AAC7D,mEAGiC;AAejC,MAAM,oBAAoB,GAAG,IAAA,qBAAa,EAExC,SAAS,CAAC,CAAC;AAEb;;;;;;;;;;;;;;;;;GAiBG;AACI,MAAM,qBAAqB,GAAgC,CAAC,EACjE,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,aAAa,GAAG,IAAA,kBAAU,EAAC,0CAAkB,CAAC,CAAC;IACrD,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CACb,iEAAiE,CAClE,CAA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AAC,CAAC;oBAC9C,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;gBAChE,CAAC;YACH,CAAC,CAAC;YACF,KAAK,oBAAoB,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC,EAAE,CAAC,qBAAqB,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IAEhD,yDAAyD;IACzD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,eAAe,IAAI,eAAe,KAAK,0CAAkB,CAAC,EAAE,EAAE,CAAC;YACjE,kBAAkB,CAAC,IAAI,CAAC,CAAC;YACzB,iBAAiB,CAAC,OAAO,GAAG,KAAK,CAAC;QACpC,CAAC;IACH,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IAEtB,+DAA+D;IAC/D,MAAM,aAAa,GAAG,OAAO,CAAC,cAAc,IAAI,eAAe,CAAC;IAEhE,OAAO;QACL,cAAc,EAAE,aAAa;QAC7B,YAAY,EAAE,OAAO,CAAC,YAAY;KACnC,CAAC;AACJ,CAAC,CAAC;AAnEW,QAAA,gBAAgB,oBAmE3B","sourcesContent":["\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { TamboThread } from \"../model/tambo-thread\";\nimport { TamboClientContext } from \"./tambo-client-provider\";\nimport {\n PLACEHOLDER_THREAD,\n TamboThreadContext,\n} from \"./tambo-thread-provider\";\n\nexport interface TamboMcpTokenContextProps {\n /**\n * The current MCP access token for the internal Tambo MCP server.\n * Prefers thread-specific token over threadless token.\n */\n mcpAccessToken: string | null;\n /**\n * The base URL for the Tambo API (used to construct the MCP server URL)\n * Returns undefined if the client is not yet initialized\n */\n tamboBaseUrl: string | undefined;\n}\n\nconst TamboMcpTokenContext = createContext<\n TamboMcpTokenContextProps | undefined\n>(undefined);\n\n/**\n * Provider for managing the MCP access token that is returned by the Tambo API.\n * This token is used to authenticate with the internal Tambo MCP server.\n *\n * Token selection logic:\n * - Returns the current thread's mcpAccessToken if available\n * - Returns null if no thread or thread has no token\n *\n * Token fetching:\n * - Thread-specific token: always fetched when switching to thread without token\n * - Tokens are fetched regardless of client-side MCP server configuration\n * to support server-side MCP servers that are not visible to the provider\n * - Threadless tokens must be fetched by individual hooks/callbacks using contextKey\n * @internal\n * @param props - The provider props\n * @param props.children - The children to wrap\n * @returns The TamboMcpTokenProvider component\n */\nexport const TamboMcpTokenProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const clientContext = useContext(TamboClientContext);\n if (!clientContext) {\n throw new Error(\n \"TamboMcpTokenProvider must be used within a TamboClientProvider\",\n );\n }\n const { client } = clientContext;\n const tamboBaseUrl = client.baseURL;\n\n // Optional thread context - may not be available in all contexts\n const threadContext = useContext(TamboThreadContext);\n const currentThread = threadContext?.currentThread ?? null;\n const currentThreadId = threadContext?.currentThreadId ?? null;\n const setThreadMap = useMemo(\n () => threadContext?.setThreadMap ?? (() => {}),\n [threadContext?.setThreadMap],\n );\n\n // Track previous thread ID to detect thread switches\n const previousThreadId = useRef<string | null>(null);\n\n // Return the current thread's token or null\n const selectedToken = useMemo(() => {\n return currentThread?.mcpAccessToken ?? null;\n }, [currentThread]);\n\n // Fetch thread-specific token when switching to a thread without one\n // Always fetch to support server-side MCP servers (not just client-side)\n // Skip PLACEHOLDER_THREAD - never send it to the server\n useEffect(() => {\n const hasThreadChanged = previousThreadId.current !== currentThreadId;\n previousThreadId.current = currentThreadId;\n\n const isPlaceholderThread = currentThreadId === PLACEHOLDER_THREAD.id;\n const shouldFetchThreadToken =\n hasThreadChanged &&\n currentThreadId &&\n !isPlaceholderThread &&\n currentThread &&\n !currentThread.mcpAccessToken;\n\n if (shouldFetchThreadToken) {\n const fetchThreadToken = async () => {\n try {\n const response = await client.beta.auth.getMcpToken({\n threadId: currentThreadId,\n });\n if (response.mcpAccessToken) {\n // Update thread in threadMap with new token\n setThreadMap((prev: Record<string, TamboThread>) => {\n const thread = prev[currentThreadId];\n if (thread) {\n return {\n ...prev,\n [currentThreadId]: {\n ...thread,\n mcpAccessToken: response.mcpAccessToken,\n },\n };\n }\n return prev;\n });\n }\n } catch (error) {\n console.error(\n `Failed to fetch MCP token for thread ${currentThreadId}:`,\n error,\n );\n }\n };\n void fetchThreadToken();\n }\n }, [currentThreadId, currentThread, client, setThreadMap]);\n\n const value = useMemo(\n () => ({ mcpAccessToken: selectedToken, tamboBaseUrl }),\n [selectedToken, tamboBaseUrl],\n );\n\n return (\n <TamboMcpTokenContext.Provider value={value}>\n {children}\n </TamboMcpTokenContext.Provider>\n );\n};\n\n/**\n * Hook to access the current MCP access token with optional threadless token fetching.\n *\n * Token selection logic:\n * 1. If current thread has mcpAccessToken → use thread-specific token\n * 2. Else if contextKey provided and no thread (or placeholder thread) → fetch and use threadless token\n * 3. Else → null\n * @param contextKey - Optional context key for fetching threadless tokens when not in a thread\n * @returns The current MCP access token and base URL\n */\nexport const useTamboMcpToken = (\n contextKey?: string,\n): TamboMcpTokenContextProps => {\n const context = useContext(TamboMcpTokenContext);\n if (context === undefined) {\n throw new Error(\n \"useTamboMcpToken must be used within a TamboMcpTokenProvider\",\n );\n }\n\n const clientContext = useContext(TamboClientContext);\n if (!clientContext) {\n throw new Error(\n \"useTamboMcpToken must be used within a TamboClientProvider\",\n );\n }\n const { client } = clientContext;\n\n const threadContext = useContext(TamboThreadContext);\n const currentThreadId = threadContext?.currentThreadId ?? null;\n\n // State for threadless token\n const [threadlessToken, setThreadlessToken] = useState<string | null>(null);\n const hasAttemptedFetch = useRef(false);\n\n // Determine if we should fetch a threadless token\n const isPlaceholderThread = currentThreadId === PLACEHOLDER_THREAD.id;\n const shouldFetchThreadless =\n contextKey &&\n (!currentThreadId || isPlaceholderThread) &&\n !context.mcpAccessToken &&\n !threadlessToken &&\n !hasAttemptedFetch.current;\n\n // Fetch threadless token when needed\n useEffect(() => {\n if (shouldFetchThreadless) {\n hasAttemptedFetch.current = true;\n const fetchThreadlessToken = async () => {\n try {\n const response = await client.beta.auth.getMcpToken({ contextKey });\n if (response.mcpAccessToken) {\n setThreadlessToken(response.mcpAccessToken);\n }\n } catch (error) {\n console.error(\"Failed to fetch threadless MCP token:\", error);\n }\n };\n void fetchThreadlessToken();\n }\n }, [shouldFetchThreadless, client, contextKey]);\n\n // Reset threadless token when switching to a real thread\n useEffect(() => {\n if (currentThreadId && currentThreadId !== PLACEHOLDER_THREAD.id) {\n setThreadlessToken(null);\n hasAttemptedFetch.current = false;\n }\n }, [currentThreadId]);\n\n // Return thread token if available, otherwise threadless token\n const selectedToken = context.mcpAccessToken ?? threadlessToken;\n\n return {\n mcpAccessToken: selectedToken,\n tamboBaseUrl: context.tamboBaseUrl,\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"tambo-mcp-token-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-mcp-token-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAQe;AACf,mEAA6D;AAc7D,MAAM,oBAAoB,GAAG,IAAA,qBAAa,EAExC,SAAS,CAAC,CAAC;AAEb;;;;;;;;;;GAUG;AACI,MAAM,qBAAqB,GAAgC,CAAC,EACjE,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,aAAa,GAAG,IAAA,kBAAU,EAAC,0CAAkB,CAAC,CAAC;IACrD,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CACb,iEAAiE,CAClE,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC;IACjC,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC;IAEpC,MAAM,KAAK,GAAG,IAAA,eAAO,EACnB,GAAG,EAAE,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,EAC9C,CA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E,CAAC;wBAC5B,eAAe,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;oBAC3C,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;gBACrD,CAAC;YACH,CAAC,CAAC;YACF,KAAK,UAAU,EAAE,CAAC;QACpB,CAAC;IACH,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IAEtC,MAAM,aAAa,GAAG,YAAY,CAAC;IAEnC,OAAO;QACL,cAAc,EAAE,aAAa;QAC7B,YAAY,EAAE,OAAO,CAAC,YAAY;KACnC,CAAC;AACJ,CAAC,CAAC;AAjDW,QAAA,gBAAgB,oBAiD3B","sourcesContent":["\"use client\";\nimport React, {\n createContext,\n type PropsWithChildren,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { TamboClientContext } from \"./tambo-client-provider\";\n\nexport interface TamboMcpTokenContextProps {\n /**\n * The current MCP access token for the internal Tambo MCP server.\n */\n mcpAccessToken: string | null;\n /**\n * The base URL for the Tambo API (used to construct the MCP server URL)\n * Returns undefined if the client is not yet initialized\n */\n tamboBaseUrl: string | undefined;\n}\n\nconst TamboMcpTokenContext = createContext<\n TamboMcpTokenContextProps | undefined\n>(undefined);\n\n/**\n * Provider for managing the MCP access token that is returned by the Tambo API.\n * This token is used to authenticate with the internal Tambo MCP server.\n *\n * Exposes the base URL and a null token by default. Token fetching is handled\n * by the useTamboMcpToken hook which supports contextKey-based token retrieval.\n * @internal\n * @param props - The provider props\n * @param props.children - The children to wrap\n * @returns The TamboMcpTokenProvider component\n */\nexport const TamboMcpTokenProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const clientContext = useContext(TamboClientContext);\n if (!clientContext) {\n throw new Error(\n \"TamboMcpTokenProvider must be used within a TamboClientProvider\",\n );\n }\n const { client } = clientContext;\n const tamboBaseUrl = client.baseURL;\n\n const value = useMemo(\n () => ({ mcpAccessToken: null, tamboBaseUrl }),\n [tamboBaseUrl],\n );\n\n return (\n <TamboMcpTokenContext.Provider value={value}>\n {children}\n </TamboMcpTokenContext.Provider>\n );\n};\n\n/**\n * Hook to access the current MCP access token with optional token fetching.\n *\n * Token fetching logic:\n * - If contextKey is provided → fetches a token using that contextKey\n * - Otherwise → returns null\n * @param contextKey - Optional context key for fetching tokens\n * @returns The current MCP access token and base URL\n */\nexport const useTamboMcpToken = (\n contextKey?: string,\n): TamboMcpTokenContextProps => {\n const context = useContext(TamboMcpTokenContext);\n if (context === undefined) {\n throw new Error(\n \"useTamboMcpToken must be used within a TamboMcpTokenProvider\",\n );\n }\n\n const clientContext = useContext(TamboClientContext);\n if (!clientContext) {\n throw new Error(\n \"useTamboMcpToken must be used within a TamboClientProvider\",\n );\n }\n const { client } = clientContext;\n\n // State for fetched token\n const [fetchedToken, setFetchedToken] = useState<string | null>(null);\n const hasAttemptedFetch = useRef(false);\n\n // Determine if we should fetch a token\n const shouldFetch = contextKey && !fetchedToken && !hasAttemptedFetch.current;\n\n // Fetch token when needed\n useEffect(() => {\n if (shouldFetch) {\n hasAttemptedFetch.current = true;\n const fetchToken = async () => {\n try {\n const response = await client.beta.auth.getMcpToken({ contextKey });\n if (response.mcpAccessToken) {\n setFetchedToken(response.mcpAccessToken);\n }\n } catch (error) {\n console.error(\"Failed to fetch MCP token:\", error);\n }\n };\n void fetchToken();\n }\n }, [shouldFetch, client, contextKey]);\n\n const selectedToken = fetchedToken;\n\n return {\n mcpAccessToken: selectedToken,\n tamboBaseUrl: context.tamboBaseUrl,\n };\n};\n"]}
|
package/dist/testing/tools.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TamboComponent, TamboTool } from "../
|
|
1
|
+
import { TamboComponent, TamboTool } from "../model/component-metadata";
|
|
2
2
|
/**
|
|
3
3
|
* Serializes the registry for testing purposes.
|
|
4
4
|
* Converts Standard Schema validators to JSON Schema format.
|
|
@@ -8,12 +8,12 @@ import { TamboComponent, TamboTool } from "../providers";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function serializeRegistry(mockRegistry: TamboComponent[]): {
|
|
10
10
|
props: import("json-schema").JSONSchema7 | undefined;
|
|
11
|
-
contextTools: import("
|
|
11
|
+
contextTools: import("../model/component-metadata").ComponentContextToolMetadata[] | undefined;
|
|
12
12
|
name: string;
|
|
13
13
|
description: string;
|
|
14
14
|
propsDefinition?: any;
|
|
15
15
|
loadingComponent?: import("react").ComponentType<any>;
|
|
16
|
-
annotations?: import("
|
|
16
|
+
annotations?: import("../model/component-metadata").ToolAnnotations;
|
|
17
17
|
}[];
|
|
18
18
|
interface CreateMockToolOptions {
|
|
19
19
|
inputSchema: TamboTool["inputSchema"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/testing/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/testing/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAIxE;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,cAAc,EAAE;;;;;;;;IAiB/D;AAED,UAAU,qBAAqB;IAC7B,WAAW,EAAE,SAAS,CAAC,aAAa,CAAC,CAAC;IACtC,YAAY,CAAC,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAGD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,eAAe,EAAE,SAAS,CAAC,aAAa,CAAC,GAAG,qBAAqB,GAChE,SAAS,CAoCX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/testing/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AAS;gBACxC,CAAC,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,QAAQ,EAAE;gBACxC,CAAC,CAAC,EAAE,CAAC;SACR,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,yBAAyB;QACtC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;QAC5C,WAAW,EAAE,eAAe;QAC5B,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE;KACjD,CAAC;AACJ,CAAC","sourcesContent":["import { TamboComponent, TamboTool } from \"../
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/testing/tools.ts"],"names":[],"mappings":";;AAWA,8CAiBC;AAgBD,wCAsCC;AAjFD,sCAAqE;AACrE,+CAA6D;AAE7D;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAAC,YAA8B;IAC9D,OAAO,YAAY,CAAC,GAAG,CACrB,CAAC,EACC,SAAS,EAAE,UAAU,EACrB,WAAW,EACX,eAAe,EACf,GAAG,cAAc,EAClB,EAAE,EAAE,CAAC,CAAC;QACL,GAAG,cAAc;QACjB,KAAK,EAAE,IAAA,yBAAgB,EAAC,WAAW,CAAC;YAClC,CAAC,CAAC,IAAA,+BAAsB,EAAC,WAAW,CAAC;YACrC,CAAC,CAAC,WAAW;QACf,YAAY,EAAE,eAAe,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAC1C,IAAA,oCAAyB,EAAC,IAAI,CAAC,CAChC;KACF,CAAC,CACH,CAAC;AACJ,CAAC;AAQD,mDAAmD;AACnD;;;;;;GAMG;AACH,SAAgB,cAAc,CAC5B,eAAiE;IAEjE,qCAAqC;IACrC,MAAM,sBAAsB,GAAG,CAC7B,GAAY,EACkB,EAAE;QAChC,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;YACvB,GAAG,KAAK,IAAI;YACZ,aAAa,IAAI,GAAG;YACpB,GAAG,CAAC,WAAW,IAAI,IAAI,CACxB,CAAC;IACJ,CAAC,CAAC;IAEF,IAAI,sBAAsB,CAAC,eAAe,CAAC,EAAE,CAAC;QAC5C,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,WAAW,EAAE,yBAAyB;YACtC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;YAC5C,WAAW,EAAE,eAAe,CAAC,WAAW;YACxC,YAAY,EAAE,eAAe,CAAC,YAAY,IAAI;gBAC5C,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE,EAAE;aACf;YACD,GAAG,CAAC,eAAe,CAAC,QAAQ,KAAK,SAAS;gBACxC,CAAC,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,QAAQ,EAAE;gBACxC,CAAC,CAAC,EAAE,CAAC;SACR,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,yBAAyB;QACtC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;QAC5C,WAAW,EAAE,eAAe;QAC5B,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE;KACjD,CAAC;AACJ,CAAC","sourcesContent":["import { TamboComponent, TamboTool } from \"../model/component-metadata\";\nimport { isStandardSchema, safeSchemaToJsonSchema } from \"../schema\";\nimport { mapTamboToolToContextTool } from \"../util/registry\";\n\n/**\n * Serializes the registry for testing purposes.\n * Converts Standard Schema validators to JSON Schema format.\n * Uses the same logic as production code via mapTamboToolToContextTool.\n * @param mockRegistry - The registry to serialize\n * @returns The serialized registry with JSON Schema representations\n */\nexport function serializeRegistry(mockRegistry: TamboComponent[]) {\n return mockRegistry.map(\n ({\n component: _component,\n propsSchema,\n associatedTools,\n ...componentEntry\n }) => ({\n ...componentEntry,\n props: isStandardSchema(propsSchema)\n ? safeSchemaToJsonSchema(propsSchema)\n : propsSchema,\n contextTools: associatedTools?.map((tool) =>\n mapTamboToolToContextTool(tool),\n ),\n }),\n );\n}\n\ninterface CreateMockToolOptions {\n inputSchema: TamboTool[\"inputSchema\"];\n outputSchema?: TamboTool[\"outputSchema\"];\n maxCalls?: number;\n}\n\n// Helper to create a minimal TamboTool for testing\n/**\n * Creates a mock TamboTool with the given input schema for testing purposes.\n * Accepts either an inputSchema directly or an options object with inputSchema and outputSchema.\n * @param schemaOrOptions - The input schema or options object\n * @returns A mock TamboTool instance\n * @internal\n */\nexport function createMockTool(\n schemaOrOptions: TamboTool[\"inputSchema\"] | CreateMockToolOptions,\n): TamboTool {\n // Check if options object was passed\n const hasInputSchemaProperty = (\n obj: unknown,\n ): obj is CreateMockToolOptions => {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n \"inputSchema\" in obj &&\n obj.inputSchema != null\n );\n };\n\n if (hasInputSchemaProperty(schemaOrOptions)) {\n return {\n name: \"mockTool\",\n description: \"A mock tool for testing\",\n tool: jest.fn().mockImplementation(() => {}),\n inputSchema: schemaOrOptions.inputSchema,\n outputSchema: schemaOrOptions.outputSchema ?? {\n type: \"object\",\n properties: {},\n },\n ...(schemaOrOptions.maxCalls !== undefined\n ? { maxCalls: schemaOrOptions.maxCalls }\n : {}),\n };\n }\n\n return {\n name: \"mockTool\",\n description: \"A mock tool for testing\",\n tool: jest.fn().mockImplementation(() => {}),\n inputSchema: schemaOrOptions,\n outputSchema: { type: \"object\", properties: {} },\n };\n}\n"]}
|
|
@@ -59,7 +59,7 @@ function validateTool(tool) {
|
|
|
59
59
|
if ("toolSchema" in tool) {
|
|
60
60
|
throw new Error(`Tool "${toolName}" uses deprecated "toolSchema" property. ` +
|
|
61
61
|
`Migrate to "inputSchema" and "outputSchema" properties. ` +
|
|
62
|
-
`See migration guide: https://docs.tambo.co/reference/react-sdk/migration
|
|
62
|
+
`See migration guide: https://docs.tambo.co/reference/react-sdk/migration`);
|
|
63
63
|
}
|
|
64
64
|
// Validate required properties exist
|
|
65
65
|
if (!("name" in tool) || typeof tool.name !== "string") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry-validators.js","sourceRoot":"","sources":["../../src/util/registry-validators.ts"],"names":[],"mappings":";;AAwDA,oCAyEC;AAgDD,kEA+BC;AAUD,0DAgBC;AAxOD,sCAKmB;AACnB,uEAA4D;AAE5D;;;;GAIG;AACH,SAAS,cAAc,CAAC,MAAmB;IACzC,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,CAAC;AACrE,CAAC;AAED;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,MAAe,EAAE,OAAe;IAC1D,IAAI,UAAuB,CAAC;IAE5B,IAAI,IAAA,yBAAgB,EAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,UAAU,GAAG,IAAA,2BAAkB,EAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;QAAC,MAAM,CAAC;YACP,6DAA6D;YAC7D,OAAO;QACT,CAAC;IACH,CAAC;SAAM,IAAI,IAAA,4BAAmB,EAAC,MAAM,CAAC,EAAE,CAAC;QACvC,UAAU,GAAG,MAAM,CAAC;IACtB,CAAC;SAAM,CAAC;QACN,sCAAsC;QACtC,OAAO;IACT,CAAC;IAED,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,GAAG,OAAO,qDAAqD;YAC7D,mBAAmB,UAAU,CAAC,IAAI,IAAI,SAAS,KAAK;YACpD,yDAAyD,CAC5D,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,IAAa;IACxC,6CAA6C;IAC7C,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtC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CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,aAAa,aAAa,wBAAwB,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,wBAAwB,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC","sourcesContent":["import type { JSONSchema7 } from \"json-schema\";\nimport type { TamboComponent, TamboTool } from \"../model/component-metadata\";\nimport {\n assertNoRecordSchema,\n isStandardSchema,\n looksLikeJSONSchema,\n schemaToJsonSchema,\n} from \"../schema\";\nimport { assertValidName } from \"./validate-component-name\";\n\n/**\n * Checks if a JSON Schema represents an object type.\n * @param schema - The JSON Schema to check\n * @returns True if the schema is an object type\n */\nfunction isObjectSchema(schema: JSONSchema7): boolean {\n return schema.type === \"object\" || schema.properties !== undefined;\n}\n\n/**\n * Validates that a schema is an object type.\n * Throws an error if it's not.\n * @param schema - The schema to validate (Standard Schema or JSON Schema)\n * @param context - Description of where the schema is used (for error messages)\n */\nfunction assertObjectSchema(schema: unknown, context: string): void {\n let jsonSchema: JSONSchema7;\n\n if (isStandardSchema(schema)) {\n try {\n jsonSchema = schemaToJsonSchema(schema);\n } catch {\n // If conversion fails, we can't validate - let it fail later\n return;\n }\n } else if (looksLikeJSONSchema(schema)) {\n jsonSchema = schema;\n } else {\n // Unknown schema type, can't validate\n return;\n }\n\n if (!isObjectSchema(jsonSchema)) {\n throw new Error(\n `${context} must be an object schema (e.g., z.object({...})). ` +\n `Received type: \"${jsonSchema.type ?? \"unknown\"}\". ` +\n `Tool parameters are passed as a single object argument.`,\n );\n }\n}\n\n/**\n * Validates a tool before registration.\n * Throws an error if the tool is invalid.\n * @param tool - The tool to validate\n */\nexport function validateTool(tool: unknown): asserts tool is TamboTool {\n // Basic runtime type checks before narrowing\n if (!tool || typeof tool !== \"object\") {\n throw new Error(\"Tool must be an object\");\n }\n\n // Extract name for error messages (before we know it's valid)\n const toolName =\n \"name\" in tool && typeof tool.name === \"string\" ? tool.name : \"<unknown>\";\n\n // Check for deprecated toolSchema - throw error with migration instructions\n if (\"toolSchema\" in tool) {\n throw new Error(\n `Tool \"${toolName}\" uses deprecated \"toolSchema\" property. ` +\n `Migrate to \"inputSchema\" and \"outputSchema\" properties. ` +\n `See migration guide: https://docs.tambo.co/reference/react-sdk/migration/toolschema`,\n );\n }\n\n // Validate required properties exist\n if (!(\"name\" in tool) || typeof tool.name !== \"string\") {\n throw new Error(\"Tool must have a 'name' property of type string\");\n }\n\n if (!(\"description\" in tool) || typeof tool.description !== \"string\") {\n throw new Error(\n `Tool \"${tool.name}\" must have a 'description' property of type string`,\n );\n }\n\n if (!(\"tool\" in tool) || typeof tool.tool !== \"function\") {\n throw new Error(\n `Tool \"${tool.name}\" must have a 'tool' property of type function`,\n );\n }\n\n if (!(\"inputSchema\" in tool)) {\n throw new Error(`Tool \"${tool.name}\" must have an 'inputSchema' property`);\n }\n\n if (!(\"outputSchema\" in tool)) {\n throw new Error(`Tool \"${tool.name}\" must have an 'outputSchema' property`);\n }\n\n // Validate tool name format\n assertValidName(tool.name, \"tool\");\n\n // Validate tool schemas - inputSchema must be an object schema\n if (tool.inputSchema) {\n assertObjectSchema(tool.inputSchema, `inputSchema of tool \"${tool.name}\"`);\n assertNoRecordSchema(\n tool.inputSchema,\n `inputSchema of tool \"${tool.name}\"`,\n );\n }\n\n // Validate maxCalls if provided - must be a positive integer\n if (\n \"maxCalls\" in tool &&\n tool.maxCalls !== undefined &&\n tool.maxCalls !== null\n ) {\n const maxCalls = tool.maxCalls;\n if (\n typeof maxCalls !== \"number\" ||\n !Number.isInteger(maxCalls) ||\n maxCalls < 0\n ) {\n throw new Error(\n `maxCalls for tool \"${tool.name}\" must be a positive integer`,\n );\n }\n }\n}\n\n/**\n * Converts a props schema to a serialized JSON Schema format.\n * @param propsDefinition - Deprecated: legacy props definition (will log warning)\n * @param propsSchema - The props schema (Standard Schema or JSON Schema)\n * @param name - Component/tool name for error messages\n * @returns Serialized JSON Schema object\n */\nfunction getSerializedProps(\n propsDefinition: unknown,\n propsSchema: unknown,\n name: string,\n): Record<string, unknown> {\n if (propsDefinition) {\n console.warn(`propsDefinition is deprecated. Use propsSchema instead.`);\n return propsDefinition as Record<string, unknown>;\n }\n\n // Check for Standard Schema (Zod, Valibot, ArkType, etc.)\n if (isStandardSchema(propsSchema)) {\n try {\n return schemaToJsonSchema(propsSchema) as Record<string, unknown>;\n } catch (error) {\n console.error(\n `Error converting ${name} props schema to JSON Schema:`,\n error,\n );\n throw new Error(\n `Error converting ${name} props schema to JSON Schema: ${error}`,\n );\n }\n }\n\n // Check for JSON Schema\n if (looksLikeJSONSchema(propsSchema)) {\n return propsSchema as Record<string, unknown>;\n }\n\n throw new Error(`Invalid props schema for ${name}`);\n}\n\n/**\n * Validates a component and prepares its props for registration.\n * Throws an error if the component is invalid.\n * @param component - The component to validate and prepare\n * @returns Object containing the serialized props\n */\nexport function validateAndPrepareComponent(component: TamboComponent): {\n props: Record<string, unknown>;\n} {\n const { name, propsSchema, propsDefinition } = component;\n\n // Validate component name\n assertValidName(name, \"component\");\n\n // Validate that at least one props definition is provided\n if (!propsSchema && !propsDefinition) {\n throw new Error(\n `Component ${name} must have either propsSchema (recommended) or propsDefinition defined`,\n );\n }\n\n // Validate that only one props definition is provided\n if (propsSchema && propsDefinition) {\n throw new Error(\n `Component ${name} cannot have both propsSchema and propsDefinition defined. Use only one. We recommend using propsSchema.`,\n );\n }\n\n // Validate that the propsSchema does not include record types\n if (propsSchema) {\n assertNoRecordSchema(propsSchema, `propsSchema of component \"${name}\"`);\n }\n\n // Convert propsSchema to JSON Schema if it exists\n const props = getSerializedProps(propsDefinition, propsSchema, name);\n\n return { props };\n}\n\n/**\n * Validates a tool association between a component and tool.\n * Throws an error if the association is invalid.\n * @param componentName - The component name\n * @param toolName - The tool name\n * @param componentExists - Whether the component exists in the registry\n * @param toolExists - Whether the tool exists in the registry\n */\nexport function validateToolAssociation(\n componentName: string,\n toolName: string,\n componentExists: boolean,\n toolExists: boolean,\n): void {\n // Validate component and tool names\n assertValidName(componentName, \"component\");\n assertValidName(toolName, \"tool\");\n\n if (!componentExists) {\n throw new Error(`Component ${componentName} not found in registry`);\n }\n if (!toolExists) {\n throw new Error(`Tool ${toolName} not found in registry`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"registry-validators.js","sourceRoot":"","sources":["../../src/util/registry-validators.ts"],"names":[],"mappings":";;AAwDA,oCAyEC;AAgDD,kEA+BC;AAUD,0DAgBC;AAxOD,sCAKmB;AACnB,uEAA4D;AAE5D;;;;GAIG;AACH,SAAS,cAAc,CAAC,MAAmB;IACzC,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,CAAC;AACrE,CAAC;AAED;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,MAAe,EAAE,OAAe;IAC1D,IAAI,UAAuB,CAAC;IAE5B,IAAI,IAAA,yBAAgB,EAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,UAAU,GAAG,IAAA,2BAAkB,EAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;QAAC,MAAM,CAAC;YACP,6DAA6D;YAC7D,OAAO;QACT,CAAC;IACH,CAAC;SAAM,IAAI,IAAA,4BAAmB,EAAC,MAAM,CAAC,EAAE,CAAC;QACvC,UAAU,GAAG,MAAM,CAAC;IACtB,CAAC;SAAM,CAAC;QACN,sCAAsC;QACtC,OAAO;IACT,CAAC;IAED,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,GAAG,OAAO,qDAAqD;YAC7D,mBAAmB,UAAU,CAAC,IAAI,IAAI,SAAS,KAAK;YACpD,yDAAyD,CAC5D,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,IAAa;IACxC,6CAA6C;IAC7C,IAAI,C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AA,yCAAe,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAElC,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,aAAa,aAAa,wBAAwB,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,wBAAwB,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC","sourcesContent":["import type { JSONSchema7 } from \"json-schema\";\nimport type { TamboComponent, TamboTool } from \"../model/component-metadata\";\nimport {\n assertNoRecordSchema,\n isStandardSchema,\n looksLikeJSONSchema,\n schemaToJsonSchema,\n} from \"../schema\";\nimport { assertValidName } from \"./validate-component-name\";\n\n/**\n * Checks if a JSON Schema represents an object type.\n * @param schema - The JSON Schema to check\n * @returns True if the schema is an object type\n */\nfunction isObjectSchema(schema: JSONSchema7): boolean {\n return schema.type === \"object\" || schema.properties !== undefined;\n}\n\n/**\n * Validates that a schema is an object type.\n * Throws an error if it's not.\n * @param schema - The schema to validate (Standard Schema or JSON Schema)\n * @param context - Description of where the schema is used (for error messages)\n */\nfunction assertObjectSchema(schema: unknown, context: string): void {\n let jsonSchema: JSONSchema7;\n\n if (isStandardSchema(schema)) {\n try {\n jsonSchema = schemaToJsonSchema(schema);\n } catch {\n // If conversion fails, we can't validate - let it fail later\n return;\n }\n } else if (looksLikeJSONSchema(schema)) {\n jsonSchema = schema;\n } else {\n // Unknown schema type, can't validate\n return;\n }\n\n if (!isObjectSchema(jsonSchema)) {\n throw new Error(\n `${context} must be an object schema (e.g., z.object({...})). ` +\n `Received type: \"${jsonSchema.type ?? \"unknown\"}\". ` +\n `Tool parameters are passed as a single object argument.`,\n );\n }\n}\n\n/**\n * Validates a tool before registration.\n * Throws an error if the tool is invalid.\n * @param tool - The tool to validate\n */\nexport function validateTool(tool: unknown): asserts tool is TamboTool {\n // Basic runtime type checks before narrowing\n if (!tool || typeof tool !== \"object\") {\n throw new Error(\"Tool must be an object\");\n }\n\n // Extract name for error messages (before we know it's valid)\n const toolName =\n \"name\" in tool && typeof tool.name === \"string\" ? tool.name : \"<unknown>\";\n\n // Check for deprecated toolSchema - throw error with migration instructions\n if (\"toolSchema\" in tool) {\n throw new Error(\n `Tool \"${toolName}\" uses deprecated \"toolSchema\" property. ` +\n `Migrate to \"inputSchema\" and \"outputSchema\" properties. ` +\n `See migration guide: https://docs.tambo.co/reference/react-sdk/migration`,\n );\n }\n\n // Validate required properties exist\n if (!(\"name\" in tool) || typeof tool.name !== \"string\") {\n throw new Error(\"Tool must have a 'name' property of type string\");\n }\n\n if (!(\"description\" in tool) || typeof tool.description !== \"string\") {\n throw new Error(\n `Tool \"${tool.name}\" must have a 'description' property of type string`,\n );\n }\n\n if (!(\"tool\" in tool) || typeof tool.tool !== \"function\") {\n throw new Error(\n `Tool \"${tool.name}\" must have a 'tool' property of type function`,\n );\n }\n\n if (!(\"inputSchema\" in tool)) {\n throw new Error(`Tool \"${tool.name}\" must have an 'inputSchema' property`);\n }\n\n if (!(\"outputSchema\" in tool)) {\n throw new Error(`Tool \"${tool.name}\" must have an 'outputSchema' property`);\n }\n\n // Validate tool name format\n assertValidName(tool.name, \"tool\");\n\n // Validate tool schemas - inputSchema must be an object schema\n if (tool.inputSchema) {\n assertObjectSchema(tool.inputSchema, `inputSchema of tool \"${tool.name}\"`);\n assertNoRecordSchema(\n tool.inputSchema,\n `inputSchema of tool \"${tool.name}\"`,\n );\n }\n\n // Validate maxCalls if provided - must be a positive integer\n if (\n \"maxCalls\" in tool &&\n tool.maxCalls !== undefined &&\n tool.maxCalls !== null\n ) {\n const maxCalls = tool.maxCalls;\n if (\n typeof maxCalls !== \"number\" ||\n !Number.isInteger(maxCalls) ||\n maxCalls < 0\n ) {\n throw new Error(\n `maxCalls for tool \"${tool.name}\" must be a positive integer`,\n );\n }\n }\n}\n\n/**\n * Converts a props schema to a serialized JSON Schema format.\n * @param propsDefinition - Deprecated: legacy props definition (will log warning)\n * @param propsSchema - The props schema (Standard Schema or JSON Schema)\n * @param name - Component/tool name for error messages\n * @returns Serialized JSON Schema object\n */\nfunction getSerializedProps(\n propsDefinition: unknown,\n propsSchema: unknown,\n name: string,\n): Record<string, unknown> {\n if (propsDefinition) {\n console.warn(`propsDefinition is deprecated. Use propsSchema instead.`);\n return propsDefinition as Record<string, unknown>;\n }\n\n // Check for Standard Schema (Zod, Valibot, ArkType, etc.)\n if (isStandardSchema(propsSchema)) {\n try {\n return schemaToJsonSchema(propsSchema) as Record<string, unknown>;\n } catch (error) {\n console.error(\n `Error converting ${name} props schema to JSON Schema:`,\n error,\n );\n throw new Error(\n `Error converting ${name} props schema to JSON Schema: ${error}`,\n );\n }\n }\n\n // Check for JSON Schema\n if (looksLikeJSONSchema(propsSchema)) {\n return propsSchema as Record<string, unknown>;\n }\n\n throw new Error(`Invalid props schema for ${name}`);\n}\n\n/**\n * Validates a component and prepares its props for registration.\n * Throws an error if the component is invalid.\n * @param component - The component to validate and prepare\n * @returns Object containing the serialized props\n */\nexport function validateAndPrepareComponent(component: TamboComponent): {\n props: Record<string, unknown>;\n} {\n const { name, propsSchema, propsDefinition } = component;\n\n // Validate component name\n assertValidName(name, \"component\");\n\n // Validate that at least one props definition is provided\n if (!propsSchema && !propsDefinition) {\n throw new Error(\n `Component ${name} must have either propsSchema (recommended) or propsDefinition defined`,\n );\n }\n\n // Validate that only one props definition is provided\n if (propsSchema && propsDefinition) {\n throw new Error(\n `Component ${name} cannot have both propsSchema and propsDefinition defined. Use only one. We recommend using propsSchema.`,\n );\n }\n\n // Validate that the propsSchema does not include record types\n if (propsSchema) {\n assertNoRecordSchema(propsSchema, `propsSchema of component \"${name}\"`);\n }\n\n // Convert propsSchema to JSON Schema if it exists\n const props = getSerializedProps(propsDefinition, propsSchema, name);\n\n return { props };\n}\n\n/**\n * Validates a tool association between a component and tool.\n * Throws an error if the association is invalid.\n * @param componentName - The component name\n * @param toolName - The tool name\n * @param componentExists - Whether the component exists in the registry\n * @param toolExists - Whether the tool exists in the registry\n */\nexport function validateToolAssociation(\n componentName: string,\n toolName: string,\n componentExists: boolean,\n toolExists: boolean,\n): void {\n // Validate component and tool names\n assertValidName(componentName, \"component\");\n assertValidName(toolName, \"tool\");\n\n if (!componentExists) {\n throw new Error(`Component ${componentName} not found in registry`);\n }\n if (!toolExists) {\n throw new Error(`Tool ${toolName} not found in registry`);\n }\n}\n"]}
|
|
@@ -40,7 +40,7 @@ function createMockRegistry() {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
* Wrapper that provides the minimal
|
|
43
|
+
* Wrapper that provides the minimal provider tree for interactables:
|
|
44
44
|
* TamboRegistryContext > TamboContextHelpersProvider > TamboInteractableProvider
|
|
45
45
|
*/
|
|
46
46
|
function V1InteractableWrapper({ children, registry, }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v1-interactables.test.js","sourceRoot":"","sources":["../../../src/v1/__tests__/v1-interactables.test.tsx"],"names":[],"mappings":";;;;;AAAA,kDAAyE;AACzE,kDAA0B;AAC1B,+BAA2B;AAC3B,+EAA0E;AAC1E,6FAAmF;AACnF,mGAAwF;AACxF,qFAGiD;AACjD,mGAA6F;AAC7F,6FAAwF;AAExF,uDAAuD;AACvD,SAAS,kBAAkB;IACzB,MAAM,YAAY,GAA4B,EAAE,CAAC;IACjD,OAAO;QACL,KAAK,EAAE;YACL,aAAa,EAAE,EAAE;YACjB,YAAY;YACZ,yBAAyB,EAAE,EAAE;YAC7B,cAAc,EAAE,EAAE;YAClB,SAAS,EAAE,EAAE;YACb,cAAc,EAAE,IAAI;YACpB,sBAAsB,EAAE,SAAS;YACjC,iBAAiB,EAAE,IAAI,CAAC,EAAE,EAAE;YAC5B,YAAY,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,IAAsB,EAAE,EAAE;gBAC/C,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;YACjC,CAAC,C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AAC,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"]}
|
|
1
|
+
{"version":3,"file":"v1-interactables.test.js","sourceRoot":"","sources":["../../../src/v1/__tests__/v1-interactables.test.tsx"],"names":[],"mappings":";;;;;AAAA,kDAAyE;AACzE,kDAA0B;AAC1B,+BAA2B;AAC3B,+EAA0E;AAC1E,6FAAmF;AACnF,mGAAwF;AACxF,qFAGiD;AACjD,mGAA6F;AAC7F,6FAAwF;AAExF,uDAAuD;AACvD,SAAS,kBAAkB;IACzB,MAAM,YAAY,GAA4B,EAAE,CAAC;IACjD,OAAO;QACL,KAAK,EAAE;YACL,aAAa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BAAC,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 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"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { type FC } from "react";
|
|
2
|
-
import type {
|
|
3
|
-
export interface
|
|
2
|
+
import type { TamboComponentContent } from "../types/message";
|
|
3
|
+
export interface ComponentRendererProps {
|
|
4
4
|
/**
|
|
5
|
-
* The component content block from a
|
|
5
|
+
* The component content block from a message
|
|
6
6
|
*/
|
|
7
|
-
content:
|
|
7
|
+
content: TamboComponentContent;
|
|
8
8
|
/**
|
|
9
9
|
* The thread ID the component belongs to
|
|
10
10
|
*/
|
|
@@ -25,15 +25,15 @@ export interface V1ComponentRendererProps {
|
|
|
25
25
|
* The component instance is preserved across re-renders as long as React's
|
|
26
26
|
* reconciliation keeps this wrapper mounted (use content.id as key).
|
|
27
27
|
*
|
|
28
|
-
* Wraps the rendered component with
|
|
29
|
-
* like
|
|
30
|
-
* @returns The rendered component wrapped in
|
|
28
|
+
* Wraps the rendered component with ComponentContentProvider so that hooks
|
|
29
|
+
* like useTamboComponentState can access component context.
|
|
30
|
+
* @returns The rendered component wrapped in ComponentContentProvider, or fallback if not found
|
|
31
31
|
* @example
|
|
32
32
|
* ```tsx
|
|
33
33
|
* function MessageContent({ content }: { content: Content }) {
|
|
34
34
|
* if (content.type === 'component') {
|
|
35
35
|
* return (
|
|
36
|
-
* <
|
|
36
|
+
* <ComponentRenderer
|
|
37
37
|
* key={content.id}
|
|
38
38
|
* content={content}
|
|
39
39
|
* fallback={<div>Unknown component: {content.name}</div>}
|
|
@@ -44,5 +44,5 @@ export interface V1ComponentRendererProps {
|
|
|
44
44
|
* }
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
|
-
export declare const
|
|
47
|
+
export declare const ComponentRenderer: FC<ComponentRendererProps>;
|
|
48
48
|
//# sourceMappingURL=v1-component-renderer.d.ts.map
|
|
@@ -1 +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,
|
|
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,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAG9D,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,OAAO,EAAE,qBAAqB,CAAC;IAE/B;;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,iBAAiB,EAAE,EAAE,CAAC,sBAAsB,CAoFxD,CAAC"}
|
|
@@ -34,17 +34,17 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
};
|
|
35
35
|
})();
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.
|
|
37
|
+
exports.ComponentRenderer = void 0;
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* Component Renderer
|
|
40
40
|
*
|
|
41
41
|
* A wrapper component that renders a component from the registry based on
|
|
42
42
|
* component content block data. Uses React's normal reconciliation to maintain
|
|
43
43
|
* component identity - as long as the key stays stable, the component instance
|
|
44
44
|
* is preserved.
|
|
45
45
|
*
|
|
46
|
-
* Wraps the component with
|
|
47
|
-
*
|
|
46
|
+
* Wraps the component with ComponentContentProvider so that hooks like
|
|
47
|
+
* useTamboComponentState can access component context.
|
|
48
48
|
*/
|
|
49
49
|
const partial_json_1 = require("partial-json");
|
|
50
50
|
const react_1 = __importStar(require("react"));
|
|
@@ -60,15 +60,15 @@ const component_renderer_1 = require("../utils/component-renderer");
|
|
|
60
60
|
* The component instance is preserved across re-renders as long as React's
|
|
61
61
|
* reconciliation keeps this wrapper mounted (use content.id as key).
|
|
62
62
|
*
|
|
63
|
-
* Wraps the rendered component with
|
|
64
|
-
* like
|
|
65
|
-
* @returns The rendered component wrapped in
|
|
63
|
+
* Wraps the rendered component with ComponentContentProvider so that hooks
|
|
64
|
+
* like useTamboComponentState can access component context.
|
|
65
|
+
* @returns The rendered component wrapped in ComponentContentProvider, or fallback if not found
|
|
66
66
|
* @example
|
|
67
67
|
* ```tsx
|
|
68
68
|
* function MessageContent({ content }: { content: Content }) {
|
|
69
69
|
* if (content.type === 'component') {
|
|
70
70
|
* return (
|
|
71
|
-
* <
|
|
71
|
+
* <ComponentRenderer
|
|
72
72
|
* key={content.id}
|
|
73
73
|
* content={content}
|
|
74
74
|
* fallback={<div>Unknown component: {content.name}</div>}
|
|
@@ -79,7 +79,7 @@ const component_renderer_1 = require("../utils/component-renderer");
|
|
|
79
79
|
* }
|
|
80
80
|
* ```
|
|
81
81
|
*/
|
|
82
|
-
const
|
|
82
|
+
const ComponentRenderer = ({ content, threadId, messageId, fallback = null, }) => {
|
|
83
83
|
const registry = (0, react_1.useContext)(tambo_registry_provider_1.TamboRegistryContext);
|
|
84
84
|
// Memoize the rendered element - only recreates when props change
|
|
85
85
|
const element = (0, react_1.useMemo)(() => {
|
|
@@ -107,7 +107,7 @@ const V1ComponentRenderer = ({ content, threadId, messageId, fallback = null, })
|
|
|
107
107
|
return react_1.default.createElement(registeredComponent.component, validatedProps);
|
|
108
108
|
}
|
|
109
109
|
catch (error) {
|
|
110
|
-
console.error("[
|
|
110
|
+
console.error("[ComponentRenderer] Failed to render component", {
|
|
111
111
|
threadId,
|
|
112
112
|
messageId,
|
|
113
113
|
componentId: content.id,
|
|
@@ -130,8 +130,8 @@ const V1ComponentRenderer = ({ content, threadId, messageId, fallback = null, })
|
|
|
130
130
|
if (element === null) {
|
|
131
131
|
return react_1.default.createElement(react_1.default.Fragment, null, fallback);
|
|
132
132
|
}
|
|
133
|
-
// Wrap with provider so hooks like
|
|
134
|
-
return (react_1.default.createElement(component_renderer_1.
|
|
133
|
+
// Wrap with provider so hooks like useTamboComponentState work
|
|
134
|
+
return (react_1.default.createElement(component_renderer_1.ComponentContentProvider, { componentId: content.id, threadId: threadId, messageId: messageId, componentName: content.name }, element));
|
|
135
135
|
};
|
|
136
|
-
exports.
|
|
136
|
+
exports.ComponentRenderer = ComponentRenderer;
|
|
137
137
|
//# sourceMappingURL=v1-component-renderer.js.map
|
|
@@ -1 +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,
|
|
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,oEAAuE;AAwBvE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACI,MAAM,iBAAiB,GAA+B,CAAC,EAC5D,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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cAAc,EAAE,OAAO,CAAC,cAAc;gBACtC,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,KAAK;aACN,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,EAAE;QACD,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,IAAI;QACZ,OAAO,CAAC,KAAK;QACb,OAAO,CAAC,cAAc;QACtB,SAAS;QACT,QAAQ;QACR,QAAQ,CAAC,aAAa;KACvB,CAAC,CAAC;IAEH,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,OAAO,8DAAG,QAAQ,CAAI,CAAC;IACzB,CAAC;IAED,+DAA+D;IAC/D,OAAO,CACL,8BAAC,6CAAwB,IACvB,WAAW,EAAE,OAAO,CAAC,EAAE,EACvB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,OAAO,CAAC,IAAI,IAE1B,OAAO,CACiB,CAC5B,CAAC;AACJ,CAAC,CAAC;AApFW,QAAA,iBAAiB,qBAoF5B","sourcesContent":["\"use client\";\n\n/**\n * 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 ComponentContentProvider so that hooks like\n * useTamboComponentState 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 { TamboComponentContent } from \"../types/message\";\nimport { ComponentContentProvider } from \"../utils/component-renderer\";\n\nexport interface ComponentRendererProps {\n /**\n * The component content block from a message\n */\n content: TamboComponentContent;\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 ComponentContentProvider so that hooks\n * like useTamboComponentState can access component context.\n * @returns The rendered component wrapped in ComponentContentProvider, or fallback if not found\n * @example\n * ```tsx\n * function MessageContent({ content }: { content: Content }) {\n * if (content.type === 'component') {\n * return (\n * <ComponentRenderer\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 ComponentRenderer: FC<ComponentRendererProps> = ({\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(\"[ComponentRenderer] 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 useTamboComponentState work\n return (\n <ComponentContentProvider\n componentId={content.id}\n threadId={threadId}\n messageId={messageId}\n componentName={content.name}\n >\n {element}\n </ComponentContentProvider>\n );\n};\n"]}
|