@tambo-ai/react 0.70.0 → 0.72.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/v1/hooks/use-tambo-v1-component-state.d.ts +44 -0
- package/dist/v1/hooks/use-tambo-v1-component-state.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-component-state.js +134 -0
- package/dist/v1/hooks/use-tambo-v1-component-state.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-component-state.test.d.ts +2 -0
- package/dist/v1/hooks/use-tambo-v1-component-state.test.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-component-state.test.js +292 -0
- package/dist/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-messages.d.ts +58 -0
- package/dist/v1/hooks/use-tambo-v1-messages.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-messages.js +54 -0
- package/dist/v1/hooks/use-tambo-v1-messages.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-messages.test.d.ts +2 -0
- package/dist/v1/hooks/use-tambo-v1-messages.test.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-messages.test.js +137 -0
- package/dist/v1/hooks/use-tambo-v1-messages.test.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.d.ts +96 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.js +227 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.test.d.ts +2 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.test.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.test.js +827 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread-input.d.ts +62 -0
- package/dist/v1/hooks/use-tambo-v1-thread-input.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread-input.js +76 -0
- package/dist/v1/hooks/use-tambo-v1-thread-input.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread-input.test.d.ts +2 -0
- package/dist/v1/hooks/use-tambo-v1-thread-input.test.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread-input.test.js +168 -0
- package/dist/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.d.ts +61 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.js +56 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.d.ts +2 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.js +98 -0
- package/dist/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread.d.ts +37 -0
- package/dist/v1/hooks/use-tambo-v1-thread.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread.js +49 -0
- package/dist/v1/hooks/use-tambo-v1-thread.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread.test.d.ts +2 -0
- package/dist/v1/hooks/use-tambo-v1-thread.test.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1-thread.test.js +83 -0
- package/dist/v1/hooks/use-tambo-v1-thread.test.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1.d.ts +107 -0
- package/dist/v1/hooks/use-tambo-v1.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1.js +87 -0
- package/dist/v1/hooks/use-tambo-v1.js.map +1 -0
- package/dist/v1/hooks/use-tambo-v1.test.d.ts +2 -0
- package/dist/v1/hooks/use-tambo-v1.test.d.ts.map +1 -0
- package/dist/v1/hooks/use-tambo-v1.test.js +150 -0
- package/dist/v1/hooks/use-tambo-v1.test.js.map +1 -0
- package/dist/v1/index.d.ts +65 -16
- package/dist/v1/index.d.ts.map +1 -1
- package/dist/v1/index.js +119 -26
- package/dist/v1/index.js.map +1 -1
- package/dist/v1/providers/tambo-v1-provider.d.ts +133 -0
- package/dist/v1/providers/tambo-v1-provider.d.ts.map +1 -0
- package/dist/v1/providers/tambo-v1-provider.js +131 -0
- package/dist/v1/providers/tambo-v1-provider.js.map +1 -0
- package/dist/v1/providers/tambo-v1-provider.test.d.ts +2 -0
- package/dist/v1/providers/tambo-v1-provider.test.d.ts.map +1 -0
- package/dist/v1/providers/tambo-v1-provider.test.js +181 -0
- package/dist/v1/providers/tambo-v1-provider.test.js.map +1 -0
- package/dist/v1/providers/tambo-v1-stream-context.d.ts +136 -0
- package/dist/v1/providers/tambo-v1-stream-context.d.ts.map +1 -0
- package/dist/v1/providers/tambo-v1-stream-context.js +230 -0
- package/dist/v1/providers/tambo-v1-stream-context.js.map +1 -0
- package/dist/v1/providers/tambo-v1-stream-context.test.d.ts +2 -0
- package/dist/v1/providers/tambo-v1-stream-context.test.d.ts.map +1 -0
- package/dist/v1/providers/tambo-v1-stream-context.test.js +85 -0
- package/dist/v1/providers/tambo-v1-stream-context.test.js.map +1 -0
- package/dist/v1/types/component.d.ts +5 -2
- package/dist/v1/types/component.d.ts.map +1 -1
- package/dist/v1/types/component.js +5 -2
- package/dist/v1/types/component.js.map +1 -1
- package/dist/v1/types/event.d.ts +21 -12
- package/dist/v1/types/event.d.ts.map +1 -1
- package/dist/v1/types/event.js +46 -1
- package/dist/v1/types/event.js.map +1 -1
- package/dist/v1/types/event.test.d.ts +2 -0
- package/dist/v1/types/event.test.d.ts.map +1 -0
- package/dist/v1/types/event.test.js +70 -0
- package/dist/v1/types/event.test.js.map +1 -0
- package/dist/v1/types/message.d.ts +30 -9
- 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 +1 -3
- 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/utils/component-renderer.d.ts +89 -0
- package/dist/v1/utils/component-renderer.d.ts.map +1 -0
- package/dist/v1/utils/component-renderer.js +216 -0
- package/dist/v1/utils/component-renderer.js.map +1 -0
- package/dist/v1/utils/component-renderer.test.d.ts +2 -0
- package/dist/v1/utils/component-renderer.test.d.ts.map +1 -0
- package/dist/v1/utils/component-renderer.test.js +380 -0
- package/dist/v1/utils/component-renderer.test.js.map +1 -0
- package/dist/v1/utils/event-accumulator.d.ts +100 -0
- package/dist/v1/utils/event-accumulator.d.ts.map +1 -0
- package/dist/v1/utils/event-accumulator.js +735 -0
- package/dist/v1/utils/event-accumulator.js.map +1 -0
- package/dist/v1/utils/event-accumulator.test.d.ts +2 -0
- package/dist/v1/utils/event-accumulator.test.d.ts.map +1 -0
- package/dist/v1/utils/event-accumulator.test.js +1205 -0
- package/dist/v1/utils/event-accumulator.test.js.map +1 -0
- package/dist/v1/utils/json-patch.d.ts +18 -0
- package/dist/v1/utils/json-patch.d.ts.map +1 -0
- package/dist/v1/utils/json-patch.js +35 -0
- package/dist/v1/utils/json-patch.js.map +1 -0
- package/dist/v1/utils/json-patch.test.d.ts +2 -0
- package/dist/v1/utils/json-patch.test.d.ts.map +1 -0
- package/dist/v1/utils/json-patch.test.js +28 -0
- package/dist/v1/utils/json-patch.test.js.map +1 -0
- package/dist/v1/utils/registry-conversion.d.ts +53 -0
- package/dist/v1/utils/registry-conversion.d.ts.map +1 -0
- package/dist/v1/utils/registry-conversion.js +114 -0
- package/dist/v1/utils/registry-conversion.js.map +1 -0
- package/dist/v1/utils/registry-conversion.test.d.ts +2 -0
- package/dist/v1/utils/registry-conversion.test.d.ts.map +1 -0
- package/dist/v1/utils/registry-conversion.test.js +179 -0
- package/dist/v1/utils/registry-conversion.test.js.map +1 -0
- package/dist/v1/utils/stream-handler.d.ts +45 -0
- package/dist/v1/utils/stream-handler.d.ts.map +1 -0
- package/dist/v1/utils/stream-handler.js +47 -0
- package/dist/v1/utils/stream-handler.js.map +1 -0
- package/dist/v1/utils/stream-handler.test.d.ts +2 -0
- package/dist/v1/utils/stream-handler.test.d.ts.map +1 -0
- package/dist/v1/utils/stream-handler.test.js +74 -0
- package/dist/v1/utils/stream-handler.test.js.map +1 -0
- package/dist/v1/utils/tool-call-tracker.d.ts +41 -0
- package/dist/v1/utils/tool-call-tracker.d.ts.map +1 -0
- package/dist/v1/utils/tool-call-tracker.js +90 -0
- package/dist/v1/utils/tool-call-tracker.js.map +1 -0
- package/dist/v1/utils/tool-executor.d.ts +33 -0
- package/dist/v1/utils/tool-executor.d.ts.map +1 -0
- package/dist/v1/utils/tool-executor.js +103 -0
- package/dist/v1/utils/tool-executor.js.map +1 -0
- package/dist/v1/utils/tool-executor.test.d.ts +2 -0
- package/dist/v1/utils/tool-executor.test.d.ts.map +1 -0
- package/dist/v1/utils/tool-executor.test.js +222 -0
- package/dist/v1/utils/tool-executor.test.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-component-state.d.ts +44 -0
- package/esm/v1/hooks/use-tambo-v1-component-state.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-component-state.js +131 -0
- package/esm/v1/hooks/use-tambo-v1-component-state.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-component-state.test.d.ts +2 -0
- package/esm/v1/hooks/use-tambo-v1-component-state.test.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-component-state.test.js +290 -0
- package/esm/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-messages.d.ts +58 -0
- package/esm/v1/hooks/use-tambo-v1-messages.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-messages.js +51 -0
- package/esm/v1/hooks/use-tambo-v1-messages.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-messages.test.d.ts +2 -0
- package/esm/v1/hooks/use-tambo-v1-messages.test.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-messages.test.js +132 -0
- package/esm/v1/hooks/use-tambo-v1-messages.test.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.d.ts +96 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.js +223 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.test.d.ts +2 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.test.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.test.js +822 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread-input.d.ts +62 -0
- package/esm/v1/hooks/use-tambo-v1-thread-input.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread-input.js +73 -0
- package/esm/v1/hooks/use-tambo-v1-thread-input.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread-input.test.d.ts +2 -0
- package/esm/v1/hooks/use-tambo-v1-thread-input.test.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread-input.test.js +166 -0
- package/esm/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.d.ts +61 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.js +53 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.d.ts +2 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.js +93 -0
- package/esm/v1/hooks/use-tambo-v1-thread-list.test.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread.d.ts +37 -0
- package/esm/v1/hooks/use-tambo-v1-thread.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread.js +46 -0
- package/esm/v1/hooks/use-tambo-v1-thread.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread.test.d.ts +2 -0
- package/esm/v1/hooks/use-tambo-v1-thread.test.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1-thread.test.js +78 -0
- package/esm/v1/hooks/use-tambo-v1-thread.test.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1.d.ts +107 -0
- package/esm/v1/hooks/use-tambo-v1.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1.js +84 -0
- package/esm/v1/hooks/use-tambo-v1.js.map +1 -0
- package/esm/v1/hooks/use-tambo-v1.test.d.ts +2 -0
- package/esm/v1/hooks/use-tambo-v1.test.d.ts.map +1 -0
- package/esm/v1/hooks/use-tambo-v1.test.js +145 -0
- package/esm/v1/hooks/use-tambo-v1.test.js.map +1 -0
- package/esm/v1/index.d.ts +65 -16
- package/esm/v1/index.d.ts.map +1 -1
- package/esm/v1/index.js +83 -27
- package/esm/v1/index.js.map +1 -1
- package/esm/v1/providers/tambo-v1-provider.d.ts +133 -0
- package/esm/v1/providers/tambo-v1-provider.d.ts.map +1 -0
- package/esm/v1/providers/tambo-v1-provider.js +94 -0
- package/esm/v1/providers/tambo-v1-provider.js.map +1 -0
- package/esm/v1/providers/tambo-v1-provider.test.d.ts +2 -0
- package/esm/v1/providers/tambo-v1-provider.test.d.ts.map +1 -0
- package/esm/v1/providers/tambo-v1-provider.test.js +176 -0
- package/esm/v1/providers/tambo-v1-provider.test.js.map +1 -0
- package/esm/v1/providers/tambo-v1-stream-context.d.ts +136 -0
- package/esm/v1/providers/tambo-v1-stream-context.d.ts.map +1 -0
- package/esm/v1/providers/tambo-v1-stream-context.js +191 -0
- package/esm/v1/providers/tambo-v1-stream-context.js.map +1 -0
- package/esm/v1/providers/tambo-v1-stream-context.test.d.ts +2 -0
- package/esm/v1/providers/tambo-v1-stream-context.test.d.ts.map +1 -0
- package/esm/v1/providers/tambo-v1-stream-context.test.js +80 -0
- package/esm/v1/providers/tambo-v1-stream-context.test.js.map +1 -0
- package/esm/v1/types/component.d.ts +5 -2
- package/esm/v1/types/component.d.ts.map +1 -1
- package/esm/v1/types/component.js +5 -2
- package/esm/v1/types/component.js.map +1 -1
- package/esm/v1/types/event.d.ts +21 -12
- package/esm/v1/types/event.d.ts.map +1 -1
- package/esm/v1/types/event.js +44 -2
- package/esm/v1/types/event.js.map +1 -1
- package/esm/v1/types/event.test.d.ts +2 -0
- package/esm/v1/types/event.test.d.ts.map +1 -0
- package/esm/v1/types/event.test.js +68 -0
- package/esm/v1/types/event.test.js.map +1 -0
- package/esm/v1/types/message.d.ts +30 -9
- 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 +1 -3
- 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/utils/component-renderer.d.ts +89 -0
- package/esm/v1/utils/component-renderer.d.ts.map +1 -0
- package/esm/v1/utils/component-renderer.js +175 -0
- package/esm/v1/utils/component-renderer.js.map +1 -0
- package/esm/v1/utils/component-renderer.test.d.ts +2 -0
- package/esm/v1/utils/component-renderer.test.d.ts.map +1 -0
- package/esm/v1/utils/component-renderer.test.js +375 -0
- package/esm/v1/utils/component-renderer.test.js.map +1 -0
- package/esm/v1/utils/event-accumulator.d.ts +100 -0
- package/esm/v1/utils/event-accumulator.d.ts.map +1 -0
- package/esm/v1/utils/event-accumulator.js +728 -0
- package/esm/v1/utils/event-accumulator.js.map +1 -0
- package/esm/v1/utils/event-accumulator.test.d.ts +2 -0
- package/esm/v1/utils/event-accumulator.test.d.ts.map +1 -0
- package/esm/v1/utils/event-accumulator.test.js +1203 -0
- package/esm/v1/utils/event-accumulator.test.js.map +1 -0
- package/esm/v1/utils/json-patch.d.ts +18 -0
- package/esm/v1/utils/json-patch.d.ts.map +1 -0
- package/esm/v1/utils/json-patch.js +32 -0
- package/esm/v1/utils/json-patch.js.map +1 -0
- package/esm/v1/utils/json-patch.test.d.ts +2 -0
- package/esm/v1/utils/json-patch.test.d.ts.map +1 -0
- package/esm/v1/utils/json-patch.test.js +26 -0
- package/esm/v1/utils/json-patch.test.js.map +1 -0
- package/esm/v1/utils/registry-conversion.d.ts +53 -0
- package/esm/v1/utils/registry-conversion.d.ts.map +1 -0
- package/esm/v1/utils/registry-conversion.js +108 -0
- package/esm/v1/utils/registry-conversion.js.map +1 -0
- package/esm/v1/utils/registry-conversion.test.d.ts +2 -0
- package/esm/v1/utils/registry-conversion.test.d.ts.map +1 -0
- package/esm/v1/utils/registry-conversion.test.js +177 -0
- package/esm/v1/utils/registry-conversion.test.js.map +1 -0
- package/esm/v1/utils/stream-handler.d.ts +45 -0
- package/esm/v1/utils/stream-handler.d.ts.map +1 -0
- package/esm/v1/utils/stream-handler.js +44 -0
- package/esm/v1/utils/stream-handler.js.map +1 -0
- package/esm/v1/utils/stream-handler.test.d.ts +2 -0
- package/esm/v1/utils/stream-handler.test.d.ts.map +1 -0
- package/esm/v1/utils/stream-handler.test.js +72 -0
- package/esm/v1/utils/stream-handler.test.js.map +1 -0
- package/esm/v1/utils/tool-call-tracker.d.ts +41 -0
- package/esm/v1/utils/tool-call-tracker.d.ts.map +1 -0
- package/esm/v1/utils/tool-call-tracker.js +86 -0
- package/esm/v1/utils/tool-call-tracker.js.map +1 -0
- package/esm/v1/utils/tool-executor.d.ts +33 -0
- package/esm/v1/utils/tool-executor.d.ts.map +1 -0
- package/esm/v1/utils/tool-executor.js +99 -0
- package/esm/v1/utils/tool-executor.js.map +1 -0
- package/esm/v1/utils/tool-executor.test.d.ts +2 -0
- package/esm/v1/utils/tool-executor.test.d.ts.map +1 -0
- package/esm/v1/utils/tool-executor.test.js +220 -0
- package/esm/v1/utils/tool-executor.test.js.map +1 -0
- package/package.json +7 -6
- package/dist/v1/types/tool.d.ts +0 -52
- package/dist/v1/types/tool.d.ts.map +0 -1
- package/dist/v1/types/tool.js +0 -11
- package/dist/v1/types/tool.js.map +0 -1
- package/esm/v1/types/tool.d.ts +0 -52
- package/esm/v1/types/tool.d.ts.map +0 -1
- package/esm/v1/types/tool.js +0 -10
- package/esm/v1/types/tool.js.map +0 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@ag-ui/core");
|
|
4
|
+
const event_1 = require("./event");
|
|
5
|
+
describe("isTamboCustomEvent", () => {
|
|
6
|
+
it("returns true for tambo.component.start event", () => {
|
|
7
|
+
const event = {
|
|
8
|
+
type: core_1.EventType.CUSTOM,
|
|
9
|
+
name: "tambo.component.start",
|
|
10
|
+
value: { messageId: "msg1", componentId: "comp1", componentName: "Test" },
|
|
11
|
+
};
|
|
12
|
+
expect((0, event_1.isTamboCustomEvent)(event)).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
it("returns true for tambo.component.props_delta event", () => {
|
|
15
|
+
const event = {
|
|
16
|
+
type: core_1.EventType.CUSTOM,
|
|
17
|
+
name: "tambo.component.props_delta",
|
|
18
|
+
value: { componentId: "comp1", operations: [] },
|
|
19
|
+
};
|
|
20
|
+
expect((0, event_1.isTamboCustomEvent)(event)).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
it("returns true for tambo.component.state_delta event", () => {
|
|
23
|
+
const event = {
|
|
24
|
+
type: core_1.EventType.CUSTOM,
|
|
25
|
+
name: "tambo.component.state_delta",
|
|
26
|
+
value: { componentId: "comp1", operations: [] },
|
|
27
|
+
};
|
|
28
|
+
expect((0, event_1.isTamboCustomEvent)(event)).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
it("returns true for tambo.component.end event", () => {
|
|
31
|
+
const event = {
|
|
32
|
+
type: core_1.EventType.CUSTOM,
|
|
33
|
+
name: "tambo.component.end",
|
|
34
|
+
value: { componentId: "comp1" },
|
|
35
|
+
};
|
|
36
|
+
expect((0, event_1.isTamboCustomEvent)(event)).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
it("returns true for tambo.run.awaiting_input event", () => {
|
|
39
|
+
const event = {
|
|
40
|
+
type: core_1.EventType.CUSTOM,
|
|
41
|
+
name: "tambo.run.awaiting_input",
|
|
42
|
+
value: { pendingToolCallIds: ["tool1"] },
|
|
43
|
+
};
|
|
44
|
+
expect((0, event_1.isTamboCustomEvent)(event)).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
it("returns false for unknown custom event name", () => {
|
|
47
|
+
const event = {
|
|
48
|
+
type: core_1.EventType.CUSTOM,
|
|
49
|
+
name: "unknown.event",
|
|
50
|
+
value: {},
|
|
51
|
+
};
|
|
52
|
+
expect((0, event_1.isTamboCustomEvent)(event)).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
it("returns false when name is undefined", () => {
|
|
55
|
+
const event = {};
|
|
56
|
+
expect((0, event_1.isTamboCustomEvent)(event)).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
it("returns false when name is not a string", () => {
|
|
59
|
+
const event = {
|
|
60
|
+
type: core_1.EventType.CUSTOM,
|
|
61
|
+
name: 123,
|
|
62
|
+
value: {},
|
|
63
|
+
};
|
|
64
|
+
expect((0, event_1.isTamboCustomEvent)(event)).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
it("returns false for empty object", () => {
|
|
67
|
+
expect((0, event_1.isTamboCustomEvent)({})).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=event.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.test.js","sourceRoot":"","sources":["../../../src/v1/types/event.test.ts"],"names":[],"mappings":";;AAAA,sCAAwC;AACxC,mCAA6C;AAE7C,QA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,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACxC,MAAM,CAAC,IAAA,0BAAkB,EAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { EventType } from \"@ag-ui/core\";\nimport { isTamboCustomEvent } from \"./event\";\n\ndescribe(\"isTamboCustomEvent\", () => {\n it(\"returns true for tambo.component.start event\", () => {\n const event = {\n type: EventType.CUSTOM,\n name: \"tambo.component.start\",\n value: { messageId: \"msg1\", componentId: \"comp1\", componentName: \"Test\" },\n };\n expect(isTamboCustomEvent(event)).toBe(true);\n });\n\n it(\"returns true for tambo.component.props_delta event\", () => {\n const event = {\n type: EventType.CUSTOM,\n name: \"tambo.component.props_delta\",\n value: { componentId: \"comp1\", operations: [] },\n };\n expect(isTamboCustomEvent(event)).toBe(true);\n });\n\n it(\"returns true for tambo.component.state_delta event\", () => {\n const event = {\n type: EventType.CUSTOM,\n name: \"tambo.component.state_delta\",\n value: { componentId: \"comp1\", operations: [] },\n };\n expect(isTamboCustomEvent(event)).toBe(true);\n });\n\n it(\"returns true for tambo.component.end event\", () => {\n const event = {\n type: EventType.CUSTOM,\n name: \"tambo.component.end\",\n value: { componentId: \"comp1\" },\n };\n expect(isTamboCustomEvent(event)).toBe(true);\n });\n\n it(\"returns true for tambo.run.awaiting_input event\", () => {\n const event = {\n type: EventType.CUSTOM,\n name: \"tambo.run.awaiting_input\",\n value: { pendingToolCallIds: [\"tool1\"] },\n };\n expect(isTamboCustomEvent(event)).toBe(true);\n });\n\n it(\"returns false for unknown custom event name\", () => {\n const event = {\n type: EventType.CUSTOM,\n name: \"unknown.event\",\n value: {},\n };\n expect(isTamboCustomEvent(event)).toBe(false);\n });\n\n it(\"returns false when name is undefined\", () => {\n const event: { name?: string } = {};\n expect(isTamboCustomEvent(event)).toBe(false);\n });\n\n it(\"returns false when name is not a string\", () => {\n const event = {\n type: EventType.CUSTOM,\n name: 123,\n value: {},\n };\n expect(isTamboCustomEvent(event as unknown as { name?: string })).toBe(\n false,\n );\n });\n\n it(\"returns false for empty object\", () => {\n expect(isTamboCustomEvent({})).toBe(false);\n });\n});\n"]}
|
|
@@ -1,26 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Message and Content Types for v1 API
|
|
3
3
|
*
|
|
4
|
-
* Re-exports message and content types from
|
|
4
|
+
* Re-exports message and content types from `@tambo-ai/typescript-sdk`.
|
|
5
5
|
* Messages use Anthropic-style content blocks pattern where a message
|
|
6
6
|
* contains an array of content blocks (text, tool calls, tool results, components).
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
9
|
-
export type TextContent
|
|
10
|
-
export type ToolUseContent = SDKToolUseContent;
|
|
11
|
-
export type ToolResultContent = SDKToolResultContent;
|
|
12
|
-
export type ComponentContent = SDKComponentContent;
|
|
13
|
-
export type ResourceContent = SDKResourceContent;
|
|
8
|
+
import type { ReactElement } from "react";
|
|
9
|
+
export type { TextContent, ToolUseContent, ToolResultContent, ComponentContent, ResourceContent, } from "@tambo-ai/typescript-sdk/resources/threads/threads";
|
|
14
10
|
export type { InputMessage } from "@tambo-ai/typescript-sdk/resources/threads/runs";
|
|
15
11
|
export type { MessageListResponse, MessageGetResponse, } from "@tambo-ai/typescript-sdk/resources/threads/messages";
|
|
12
|
+
import type { TextContent, ToolUseContent, ToolResultContent, ComponentContent, ResourceContent } from "@tambo-ai/typescript-sdk/resources/threads/threads";
|
|
13
|
+
/**
|
|
14
|
+
* Streaming state for component content blocks.
|
|
15
|
+
* Tracks the lifecycle of component prop/state streaming.
|
|
16
|
+
*/
|
|
17
|
+
export type ComponentStreamingState = "started" | "streaming" | "done";
|
|
18
|
+
/**
|
|
19
|
+
* Extended ComponentContent with streaming state and rendered element.
|
|
20
|
+
* Used by the v1 SDK to track component rendering lifecycle.
|
|
21
|
+
*/
|
|
22
|
+
export interface V1ComponentContent extends ComponentContent {
|
|
23
|
+
/**
|
|
24
|
+
* Current streaming state of this component's props.
|
|
25
|
+
* - 'started': Component block created, awaiting props
|
|
26
|
+
* - 'streaming': Props are being streamed
|
|
27
|
+
* - 'done': Props streaming complete
|
|
28
|
+
*/
|
|
29
|
+
streamingState: ComponentStreamingState;
|
|
30
|
+
/**
|
|
31
|
+
* The rendered React element for this component.
|
|
32
|
+
* undefined if not yet rendered, null if the component couldn't be found in the registry.
|
|
33
|
+
*/
|
|
34
|
+
renderedComponent?: ReactElement | null;
|
|
35
|
+
}
|
|
16
36
|
/**
|
|
17
37
|
* Message role (from SDK)
|
|
18
38
|
*/
|
|
19
39
|
export type MessageRole = "user" | "assistant";
|
|
20
40
|
/**
|
|
21
|
-
* Union type of all content block types
|
|
41
|
+
* Union type of all content block types.
|
|
42
|
+
* Uses V1ComponentContent which includes streaming state and rendered component.
|
|
22
43
|
*/
|
|
23
|
-
export type Content =
|
|
44
|
+
export type Content = TextContent | ToolUseContent | ToolResultContent | V1ComponentContent | ResourceContent;
|
|
24
45
|
/**
|
|
25
46
|
* Message in a thread (simplified from SDK's MessageGetResponse)
|
|
26
47
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/v1/types/message.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/v1/types/message.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAG1C,YAAY,EACV,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,GAChB,MAAM,oDAAoD,CAAC;AAG5D,YAAY,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAEpF,YAAY,EACV,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,qDAAqD,CAAC;AAG7D,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAChB,MAAM,oDAAoD,CAAC;AAE5D;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,CAAC;AAEvE;;;GAGG;AACH,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D;;;;;OAKG;IACH,cAAc,EAAE,uBAAuB,CAAC;IAExC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,OAAO,GACf,WAAW,GACX,cAAc,GACd,iBAAiB,GACjB,kBAAkB,GAClB,eAAe,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;IAEX,uCAAuC;IACvC,IAAI,EAAE,WAAW,CAAC;IAElB,oCAAoC;IACpC,OAAO,EAAE,OAAO,EAAE,CAAC;IAEnB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAElB,uBAAuB;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC"}
|
package/dist/v1/types/message.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Message and Content Types for v1 API
|
|
4
4
|
*
|
|
5
|
-
* Re-exports message and content types from
|
|
5
|
+
* Re-exports message and content types from `@tambo-ai/typescript-sdk`.
|
|
6
6
|
* Messages use Anthropic-style content blocks pattern where a message
|
|
7
7
|
* contains an array of content blocks (text, tool calls, tool results, components).
|
|
8
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/v1/types/message.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * Message and Content Types for v1 API\n *\n * Re-exports message and content types from
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/v1/types/message.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * Message and Content Types for v1 API\n *\n * Re-exports message and content types from `@tambo-ai/typescript-sdk`.\n * Messages use Anthropic-style content blocks pattern where a message\n * contains an array of content blocks (text, tool calls, tool results, components).\n */\n\nimport type { ReactElement } from \"react\";\n\n// Re-export content block types from TypeScript SDK\nexport type {\n TextContent,\n ToolUseContent,\n ToolResultContent,\n ComponentContent,\n ResourceContent,\n} from \"@tambo-ai/typescript-sdk/resources/threads/threads\";\n\n// Re-export message types from TypeScript SDK\nexport type { InputMessage } from \"@tambo-ai/typescript-sdk/resources/threads/runs\";\n\nexport type {\n MessageListResponse,\n MessageGetResponse,\n} from \"@tambo-ai/typescript-sdk/resources/threads/messages\";\n\n// Import for Content union type\nimport type {\n TextContent,\n ToolUseContent,\n ToolResultContent,\n ComponentContent,\n ResourceContent,\n} from \"@tambo-ai/typescript-sdk/resources/threads/threads\";\n\n/**\n * Streaming state for component content blocks.\n * Tracks the lifecycle of component prop/state streaming.\n */\nexport type ComponentStreamingState = \"started\" | \"streaming\" | \"done\";\n\n/**\n * Extended ComponentContent with streaming state and rendered element.\n * Used by the v1 SDK to track component rendering lifecycle.\n */\nexport interface V1ComponentContent extends ComponentContent {\n /**\n * Current streaming state of this component's props.\n * - 'started': Component block created, awaiting props\n * - 'streaming': Props are being streamed\n * - 'done': Props streaming complete\n */\n streamingState: ComponentStreamingState;\n\n /**\n * The rendered React element for this component.\n * undefined if not yet rendered, null if the component couldn't be found in the registry.\n */\n renderedComponent?: ReactElement | null;\n}\n\n/**\n * Message role (from SDK)\n */\nexport type MessageRole = \"user\" | \"assistant\";\n\n/**\n * Union type of all content block types.\n * Uses V1ComponentContent which includes streaming state and rendered component.\n */\nexport type Content =\n | TextContent\n | ToolUseContent\n | ToolResultContent\n | V1ComponentContent\n | ResourceContent;\n\n/**\n * Message in a thread (simplified from SDK's MessageGetResponse)\n */\nexport interface TamboV1Message {\n /** Unique message identifier */\n id: string;\n\n /** Message role (user or assistant) */\n role: MessageRole;\n\n /** Content blocks in the message */\n content: Content[];\n\n /** When the message was created */\n createdAt: string;\n\n /** Message metadata */\n metadata?: Record<string, unknown>;\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Thread Types for v1 API
|
|
3
3
|
*
|
|
4
|
-
* Re-exports thread types from
|
|
4
|
+
* Re-exports thread types from `@tambo-ai/typescript-sdk` and defines
|
|
5
5
|
* React-specific extensions for streaming state management.
|
|
6
6
|
*/
|
|
7
7
|
import type { TamboV1Message } from "./message";
|
|
@@ -19,8 +19,6 @@ export interface TamboV1Thread {
|
|
|
19
19
|
id: string;
|
|
20
20
|
/** Thread title/name */
|
|
21
21
|
title?: string;
|
|
22
|
-
/** Project ID this thread belongs to */
|
|
23
|
-
projectId: string;
|
|
24
22
|
/** Messages in the thread */
|
|
25
23
|
messages: TamboV1Message[];
|
|
26
24
|
/** Current run status */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../../src/v1/types/thread.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGhD,YAAY,EACV,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,oDAAoD,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC;AAEhF;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,+BAA+B;IAC/B,EAAE,EAAE,MAAM,CAAC;IAEX,wBAAwB;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,
|
|
1
|
+
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../../src/v1/types/thread.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGhD,YAAY,EACV,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,oDAAoD,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC;AAEhF;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,+BAA+B;IAC/B,EAAE,EAAE,MAAM,CAAC;IAEX,wBAAwB;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,6BAA6B;IAC7B,QAAQ,EAAE,cAAc,EAAE,CAAC;IAE3B,yBAAyB;IACzB,MAAM,EAAE,SAAS,CAAC;IAElB,sBAAsB;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnC,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;IAElB,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,MAAM,EAAE,SAAS,CAAC;IAElB,mCAAmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,mCAAmC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,6CAA6C;IAC7C,KAAK,CAAC,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACH"}
|
package/dist/v1/types/thread.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Thread Types for v1 API
|
|
4
4
|
*
|
|
5
|
-
* Re-exports thread types from
|
|
5
|
+
* Re-exports thread types from `@tambo-ai/typescript-sdk` and defines
|
|
6
6
|
* React-specific extensions for streaming state management.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread.js","sourceRoot":"","sources":["../../../src/v1/types/thread.ts"],"names":[],"mappings":";AAAA;;;;;GAKG","sourcesContent":["/**\n * Thread Types for v1 API\n *\n * Re-exports thread types from
|
|
1
|
+
{"version":3,"file":"thread.js","sourceRoot":"","sources":["../../../src/v1/types/thread.ts"],"names":[],"mappings":";AAAA;;;;;GAKG","sourcesContent":["/**\n * Thread Types for v1 API\n *\n * Re-exports thread types from `@tambo-ai/typescript-sdk` and defines\n * React-specific extensions for streaming state management.\n */\n\nimport type { TamboV1Message } from \"./message\";\n\n// Re-export thread types from TypeScript SDK\nexport type {\n ThreadCreateResponse,\n ThreadRetrieveResponse,\n ThreadListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/threads/threads\";\n\n/**\n * Run status indicates the current state of the thread\n */\nexport type RunStatus = \"idle\" | \"waiting\" | \"streaming\" | \"complete\" | \"error\";\n\n/**\n * Thread represents a conversation with the AI\n * Extended from SDK's ThreadRetrieveResponse with additional fields for React state\n */\nexport interface TamboV1Thread {\n /** Unique thread identifier */\n id: string;\n\n /** Thread title/name */\n title?: string;\n\n /** Messages in the thread */\n messages: TamboV1Message[];\n\n /** Current run status */\n status: RunStatus;\n\n /** Thread metadata */\n metadata?: Record<string, unknown>;\n\n /** When the thread was created */\n createdAt: string;\n\n /** When the thread was last updated */\n updatedAt: string;\n}\n\n/**\n * Streaming state tracks the progress of an active run\n * This is React-specific and not part of the SDK\n */\nexport interface StreamingState {\n /** Current streaming status */\n status: RunStatus;\n\n /** Active run ID (if streaming) */\n runId?: string;\n\n /** Active message ID being streamed */\n messageId?: string;\n\n /** When the current run started */\n startTime?: number;\n\n /** Error information if status is 'error' */\n error?: {\n message: string;\n code?: string;\n };\n}\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { ComponentRegistry } from "../../model/component-metadata";
|
|
2
|
+
import type { Content, TamboV1Message, V1ComponentContent } from "../types/message";
|
|
3
|
+
/**
|
|
4
|
+
* Context for component content blocks.
|
|
5
|
+
* Provides access to the component ID and thread ID for component state hooks.
|
|
6
|
+
*/
|
|
7
|
+
export interface V1ComponentContentContext {
|
|
8
|
+
/** Component instance ID */
|
|
9
|
+
componentId: string;
|
|
10
|
+
/** Thread ID the component belongs to */
|
|
11
|
+
threadId: string;
|
|
12
|
+
/** Message ID the component belongs to */
|
|
13
|
+
messageId: string;
|
|
14
|
+
/** Component name */
|
|
15
|
+
componentName: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Hook to access the current component content context.
|
|
19
|
+
* Must be used within a rendered component.
|
|
20
|
+
* @returns Component content context
|
|
21
|
+
* @throws {Error} If used outside a rendered component
|
|
22
|
+
*/
|
|
23
|
+
export declare function useV1ComponentContent(): V1ComponentContentContext;
|
|
24
|
+
/**
|
|
25
|
+
* Hook to optionally access the current component content context.
|
|
26
|
+
* Returns null if not within a rendered component.
|
|
27
|
+
* @returns Component content context or null
|
|
28
|
+
*/
|
|
29
|
+
export declare function useV1ComponentContentOptional(): V1ComponentContentContext | null;
|
|
30
|
+
/**
|
|
31
|
+
* Options for rendering a component content block.
|
|
32
|
+
*/
|
|
33
|
+
export interface RenderComponentOptions {
|
|
34
|
+
/** Thread ID for the component context */
|
|
35
|
+
threadId: string;
|
|
36
|
+
/** Message ID the component belongs to */
|
|
37
|
+
messageId: string;
|
|
38
|
+
/** Component registry to look up components */
|
|
39
|
+
componentList: ComponentRegistry;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Check if a content block is a component.
|
|
43
|
+
* @param content - Content block to check
|
|
44
|
+
* @returns True if content is a V1ComponentContent
|
|
45
|
+
*/
|
|
46
|
+
export declare function isComponentContent(content: Content): content is V1ComponentContent;
|
|
47
|
+
/**
|
|
48
|
+
* Render a component content block into a React element.
|
|
49
|
+
*
|
|
50
|
+
* Looks up the component in the registry, creates a React element with props,
|
|
51
|
+
* and wraps it with the component content context provider.
|
|
52
|
+
* @param content - Component content block to render
|
|
53
|
+
* @param options - Rendering options including registry and context info
|
|
54
|
+
* @returns V1ComponentContent with the renderedComponent attached
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* const rendered = renderComponentContent(componentContent, {
|
|
58
|
+
* threadId: 'thread_123',
|
|
59
|
+
* messageId: 'msg_456',
|
|
60
|
+
* componentList: registry.componentList,
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* // Use in JSX:
|
|
64
|
+
* {rendered.renderedComponent}
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function renderComponentContent(content: V1ComponentContent, options: RenderComponentOptions): V1ComponentContent;
|
|
68
|
+
/**
|
|
69
|
+
* Render all component content blocks in a message.
|
|
70
|
+
*
|
|
71
|
+
* Renders component content blocks and attaches renderedComponent.
|
|
72
|
+
* Non-component content blocks are passed through unchanged.
|
|
73
|
+
* @param content - Array of content blocks
|
|
74
|
+
* @param options - Rendering options including registry and context info
|
|
75
|
+
* @returns Array of content with rendered components
|
|
76
|
+
*/
|
|
77
|
+
export declare function renderMessageContent(content: Content[], options: RenderComponentOptions): Content[];
|
|
78
|
+
/**
|
|
79
|
+
* Render all components in a message.
|
|
80
|
+
*
|
|
81
|
+
* Creates a new message object with all component content blocks rendered.
|
|
82
|
+
* @param message - Message to render components for
|
|
83
|
+
* @param options - Rendering options (threadId is extracted from message if not provided)
|
|
84
|
+
* @returns Message with rendered component content
|
|
85
|
+
*/
|
|
86
|
+
export declare function renderMessageComponents(message: TamboV1Message, options: Omit<RenderComponentOptions, "messageId"> & {
|
|
87
|
+
threadId: string;
|
|
88
|
+
}): TamboV1Message;
|
|
89
|
+
//# sourceMappingURL=component-renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-renderer.d.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AAE,MAAM,CAAA;CAAE,GACxE,cAAc,CAUhB"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.useV1ComponentContent = useV1ComponentContent;
|
|
38
|
+
exports.useV1ComponentContentOptional = useV1ComponentContentOptional;
|
|
39
|
+
exports.isComponentContent = isComponentContent;
|
|
40
|
+
exports.renderComponentContent = renderComponentContent;
|
|
41
|
+
exports.renderMessageContent = renderMessageContent;
|
|
42
|
+
exports.renderMessageComponents = renderMessageComponents;
|
|
43
|
+
/**
|
|
44
|
+
* Component Renderer Utility for v1 API
|
|
45
|
+
*
|
|
46
|
+
* Provides utilities for rendering React components from component content blocks.
|
|
47
|
+
* Components are looked up in the registry and wrapped with context providers.
|
|
48
|
+
*/
|
|
49
|
+
const react_1 = __importStar(require("react"));
|
|
50
|
+
/**
|
|
51
|
+
* Props that should be filtered out when rendering components.
|
|
52
|
+
* These could be used for event handler injection or other security concerns.
|
|
53
|
+
*/
|
|
54
|
+
const DANGEROUS_PROP_PATTERNS = [
|
|
55
|
+
/^on[A-Z]/, // Event handlers (onClick, onError, etc.)
|
|
56
|
+
/^dangerouslySetInnerHTML$/,
|
|
57
|
+
];
|
|
58
|
+
const DANGEROUS_PROP_NAMES = new Set(["ref", "key", "children"]);
|
|
59
|
+
/**
|
|
60
|
+
* Sanitize props by removing potentially dangerous properties.
|
|
61
|
+
* Filters out event handlers, refs, and other props that could be abused.
|
|
62
|
+
* @param props - Raw props from the component content
|
|
63
|
+
* @returns Sanitized props safe for spreading to components
|
|
64
|
+
*/
|
|
65
|
+
function sanitizeProps(props) {
|
|
66
|
+
const sanitized = {};
|
|
67
|
+
for (const [key, value] of Object.entries(props)) {
|
|
68
|
+
// Skip dangerous prop names
|
|
69
|
+
if (DANGEROUS_PROP_NAMES.has(key)) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
// Skip props matching dangerous patterns
|
|
73
|
+
if (DANGEROUS_PROP_PATTERNS.some((pattern) => pattern.test(key))) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
sanitized[key] = value;
|
|
77
|
+
}
|
|
78
|
+
return sanitized;
|
|
79
|
+
}
|
|
80
|
+
const ComponentContentContext = (0, react_1.createContext)(null);
|
|
81
|
+
/**
|
|
82
|
+
* Provider for component content context.
|
|
83
|
+
* Wraps rendered components to provide access to component metadata.
|
|
84
|
+
* @returns Provider component with memoized context value
|
|
85
|
+
*/
|
|
86
|
+
function V1ComponentContentProvider({ children, componentId, threadId, messageId, componentName, }) {
|
|
87
|
+
// Memoize context value to prevent unnecessary re-renders of consumers
|
|
88
|
+
const value = (0, react_1.useMemo)(() => ({ componentId, threadId, messageId, componentName }), [componentId, threadId, messageId, componentName]);
|
|
89
|
+
return (react_1.default.createElement(ComponentContentContext.Provider, { value: value }, children));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Hook to access the current component content context.
|
|
93
|
+
* Must be used within a rendered component.
|
|
94
|
+
* @returns Component content context
|
|
95
|
+
* @throws {Error} If used outside a rendered component
|
|
96
|
+
*/
|
|
97
|
+
function useV1ComponentContent() {
|
|
98
|
+
const context = (0, react_1.useContext)(ComponentContentContext);
|
|
99
|
+
if (!context) {
|
|
100
|
+
throw new Error("useV1ComponentContent must be used within a rendered component");
|
|
101
|
+
}
|
|
102
|
+
return context;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Hook to optionally access the current component content context.
|
|
106
|
+
* Returns null if not within a rendered component.
|
|
107
|
+
* @returns Component content context or null
|
|
108
|
+
*/
|
|
109
|
+
function useV1ComponentContentOptional() {
|
|
110
|
+
return (0, react_1.useContext)(ComponentContentContext);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Check if a content block is a component.
|
|
114
|
+
* @param content - Content block to check
|
|
115
|
+
* @returns True if content is a V1ComponentContent
|
|
116
|
+
*/
|
|
117
|
+
function isComponentContent(content) {
|
|
118
|
+
return content.type === "component";
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Render a component content block into a React element.
|
|
122
|
+
*
|
|
123
|
+
* Looks up the component in the registry, creates a React element with props,
|
|
124
|
+
* and wraps it with the component content context provider.
|
|
125
|
+
* @param content - Component content block to render
|
|
126
|
+
* @param options - Rendering options including registry and context info
|
|
127
|
+
* @returns V1ComponentContent with the renderedComponent attached
|
|
128
|
+
* @example
|
|
129
|
+
* ```tsx
|
|
130
|
+
* const rendered = renderComponentContent(componentContent, {
|
|
131
|
+
* threadId: 'thread_123',
|
|
132
|
+
* messageId: 'msg_456',
|
|
133
|
+
* componentList: registry.componentList,
|
|
134
|
+
* });
|
|
135
|
+
*
|
|
136
|
+
* // Use in JSX:
|
|
137
|
+
* {rendered.renderedComponent}
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
function renderComponentContent(content, options) {
|
|
141
|
+
const { threadId, messageId, componentList } = options;
|
|
142
|
+
// Look up component in registry
|
|
143
|
+
const registeredComponent = componentList[content.name];
|
|
144
|
+
if (!registeredComponent) {
|
|
145
|
+
console.warn(`Component "${content.name}" not found in registry`);
|
|
146
|
+
return {
|
|
147
|
+
...content,
|
|
148
|
+
renderedComponent: null,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const Component = registeredComponent.component;
|
|
152
|
+
const LoadingComponent = registeredComponent.loadingComponent;
|
|
153
|
+
// Determine if we should show loading state
|
|
154
|
+
const isStreaming = content.streamingState !== "done";
|
|
155
|
+
// Sanitize props to prevent injection of event handlers or other dangerous props
|
|
156
|
+
const props = sanitizeProps(content.props);
|
|
157
|
+
// Create the component element
|
|
158
|
+
let element;
|
|
159
|
+
if (isStreaming && LoadingComponent) {
|
|
160
|
+
// Show loading component during streaming (with props for partial data display)
|
|
161
|
+
element = (0, react_1.createElement)(LoadingComponent, props);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
// Show main component - props stream in as they're filled out
|
|
165
|
+
element = (0, react_1.createElement)(Component, {
|
|
166
|
+
...props,
|
|
167
|
+
// Pass state as initialState prop only if not already provided
|
|
168
|
+
...(props.initialState === undefined
|
|
169
|
+
? { initialState: content.state }
|
|
170
|
+
: {}),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
// Wrap with component content context
|
|
174
|
+
const wrappedElement = (react_1.default.createElement(V1ComponentContentProvider, { componentId: content.id, threadId: threadId, messageId: messageId, componentName: content.name }, element));
|
|
175
|
+
return {
|
|
176
|
+
...content,
|
|
177
|
+
renderedComponent: wrappedElement,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Render all component content blocks in a message.
|
|
182
|
+
*
|
|
183
|
+
* Renders component content blocks and attaches renderedComponent.
|
|
184
|
+
* Non-component content blocks are passed through unchanged.
|
|
185
|
+
* @param content - Array of content blocks
|
|
186
|
+
* @param options - Rendering options including registry and context info
|
|
187
|
+
* @returns Array of content with rendered components
|
|
188
|
+
*/
|
|
189
|
+
function renderMessageContent(content, options) {
|
|
190
|
+
return content.map((block) => {
|
|
191
|
+
if (isComponentContent(block)) {
|
|
192
|
+
return renderComponentContent(block, options);
|
|
193
|
+
}
|
|
194
|
+
// Pass through non-component content unchanged
|
|
195
|
+
return block;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Render all components in a message.
|
|
200
|
+
*
|
|
201
|
+
* Creates a new message object with all component content blocks rendered.
|
|
202
|
+
* @param message - Message to render components for
|
|
203
|
+
* @param options - Rendering options (threadId is extracted from message if not provided)
|
|
204
|
+
* @returns Message with rendered component content
|
|
205
|
+
*/
|
|
206
|
+
function renderMessageComponents(message, options) {
|
|
207
|
+
const renderedContent = renderMessageContent(message.content, {
|
|
208
|
+
...options,
|
|
209
|
+
messageId: message.id,
|
|
210
|
+
});
|
|
211
|
+
return {
|
|
212
|
+
...message,
|
|
213
|
+
content: renderedContent,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=component-renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-renderer.js","sourceRoot":"","sources":["../../../src/v1/utils/component-renderer.tsx"],"names":[],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yE;IAEzE,MAAM,eAAe,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,EAAE;QAC5D,GAAG,OAAO;QACV,SAAS,EAAE,OAAO,CAAC,EAAE;KACtB,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,OAAO;QACV,OAAO,EAAE,eAAe;KACzB,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\n/**\n * Component Renderer Utility for v1 API\n *\n * Provides utilities for rendering React components from component content blocks.\n * Components are looked up in the registry and wrapped with context providers.\n */\n\nimport React, {\n createContext,\n createElement,\n useContext,\n useMemo,\n type ReactElement,\n} from \"react\";\n\n/**\n * Props that should be filtered out when rendering components.\n * These could be used for event handler injection or other security concerns.\n */\nconst DANGEROUS_PROP_PATTERNS = [\n /^on[A-Z]/, // Event handlers (onClick, onError, etc.)\n /^dangerouslySetInnerHTML$/,\n];\n\nconst DANGEROUS_PROP_NAMES = new Set([\"ref\", \"key\", \"children\"]);\n\n/**\n * Sanitize props by removing potentially dangerous properties.\n * Filters out event handlers, refs, and other props that could be abused.\n * @param props - Raw props from the component content\n * @returns Sanitized props safe for spreading to components\n */\nfunction sanitizeProps(\n props: Record<string, unknown>,\n): Record<string, unknown> {\n const sanitized: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(props)) {\n // Skip dangerous prop names\n if (DANGEROUS_PROP_NAMES.has(key)) {\n continue;\n }\n\n // Skip props matching dangerous patterns\n if (DANGEROUS_PROP_PATTERNS.some((pattern) => pattern.test(key))) {\n continue;\n }\n\n sanitized[key] = value;\n }\n\n return sanitized;\n}\nimport type { ComponentRegistry } from \"../../model/component-metadata\";\nimport type {\n Content,\n TamboV1Message,\n V1ComponentContent,\n} from \"../types/message\";\n\n/**\n * Context for component content blocks.\n * Provides access to the component ID and thread ID for component state hooks.\n */\nexport interface V1ComponentContentContext {\n /** Component instance ID */\n componentId: string;\n /** Thread ID the component belongs to */\n threadId: string;\n /** Message ID the component belongs to */\n messageId: string;\n /** Component name */\n componentName: string;\n}\n\nconst ComponentContentContext = createContext<V1ComponentContentContext | null>(\n null,\n);\n\n/**\n * Provider for component content context.\n * Wraps rendered components to provide access to component metadata.\n * @returns Provider component with memoized context value\n */\nfunction V1ComponentContentProvider({\n children,\n componentId,\n threadId,\n messageId,\n componentName,\n}: V1ComponentContentContext & { children: React.ReactNode }) {\n // Memoize context value to prevent unnecessary re-renders of consumers\n const value = useMemo(\n () => ({ componentId, threadId, messageId, componentName }),\n [componentId, threadId, messageId, componentName],\n );\n\n return (\n <ComponentContentContext.Provider value={value}>\n {children}\n </ComponentContentContext.Provider>\n );\n}\n\n/**\n * Hook to access the current component content context.\n * Must be used within a rendered component.\n * @returns Component content context\n * @throws {Error} If used outside a rendered component\n */\nexport function useV1ComponentContent(): V1ComponentContentContext {\n const context = useContext(ComponentContentContext);\n if (!context) {\n throw new Error(\n \"useV1ComponentContent must be used within a rendered component\",\n );\n }\n return context;\n}\n\n/**\n * Hook to optionally access the current component content context.\n * Returns null if not within a rendered component.\n * @returns Component content context or null\n */\nexport function useV1ComponentContentOptional(): V1ComponentContentContext | null {\n return useContext(ComponentContentContext);\n}\n\n/**\n * Options for rendering a component content block.\n */\nexport interface RenderComponentOptions {\n /** Thread ID for the component context */\n threadId: string;\n /** Message ID the component belongs to */\n messageId: string;\n /** Component registry to look up components */\n componentList: ComponentRegistry;\n}\n\n/**\n * Check if a content block is a component.\n * @param content - Content block to check\n * @returns True if content is a V1ComponentContent\n */\nexport function isComponentContent(\n content: Content,\n): content is V1ComponentContent {\n return content.type === \"component\";\n}\n\n/**\n * Render a component content block into a React element.\n *\n * Looks up the component in the registry, creates a React element with props,\n * and wraps it with the component content context provider.\n * @param content - Component content block to render\n * @param options - Rendering options including registry and context info\n * @returns V1ComponentContent with the renderedComponent attached\n * @example\n * ```tsx\n * const rendered = renderComponentContent(componentContent, {\n * threadId: 'thread_123',\n * messageId: 'msg_456',\n * componentList: registry.componentList,\n * });\n *\n * // Use in JSX:\n * {rendered.renderedComponent}\n * ```\n */\nexport function renderComponentContent(\n content: V1ComponentContent,\n options: RenderComponentOptions,\n): V1ComponentContent {\n const { threadId, messageId, componentList } = options;\n\n // Look up component in registry\n const registeredComponent = componentList[content.name];\n\n if (!registeredComponent) {\n console.warn(`Component \"${content.name}\" not found in registry`);\n return {\n ...content,\n renderedComponent: null,\n };\n }\n\n const Component = registeredComponent.component;\n const LoadingComponent = registeredComponent.loadingComponent;\n\n // Determine if we should show loading state\n const isStreaming = content.streamingState !== \"done\";\n\n // Sanitize props to prevent injection of event handlers or other dangerous props\n const props = sanitizeProps(content.props as Record<string, unknown>);\n\n // Create the component element\n let element: ReactElement;\n\n if (isStreaming && LoadingComponent) {\n // Show loading component during streaming (with props for partial data display)\n element = createElement(LoadingComponent, props);\n } else {\n // Show main component - props stream in as they're filled out\n element = createElement(Component, {\n ...props,\n // Pass state as initialState prop only if not already provided\n ...(props.initialState === undefined\n ? { initialState: content.state }\n : {}),\n });\n }\n\n // Wrap with component content context\n const wrappedElement = (\n <V1ComponentContentProvider\n componentId={content.id}\n threadId={threadId}\n messageId={messageId}\n componentName={content.name}\n >\n {element}\n </V1ComponentContentProvider>\n );\n\n return {\n ...content,\n renderedComponent: wrappedElement,\n };\n}\n\n/**\n * Render all component content blocks in a message.\n *\n * Renders component content blocks and attaches renderedComponent.\n * Non-component content blocks are passed through unchanged.\n * @param content - Array of content blocks\n * @param options - Rendering options including registry and context info\n * @returns Array of content with rendered components\n */\nexport function renderMessageContent(\n content: Content[],\n options: RenderComponentOptions,\n): Content[] {\n return content.map((block) => {\n if (isComponentContent(block)) {\n return renderComponentContent(block, options);\n }\n // Pass through non-component content unchanged\n return block;\n });\n}\n\n/**\n * Render all components in a message.\n *\n * Creates a new message object with all component content blocks rendered.\n * @param message - Message to render components for\n * @param options - Rendering options (threadId is extracted from message if not provided)\n * @returns Message with rendered component content\n */\nexport function renderMessageComponents(\n message: TamboV1Message,\n options: Omit<RenderComponentOptions, \"messageId\"> & { threadId: string },\n): TamboV1Message {\n const renderedContent = renderMessageContent(message.content, {\n ...options,\n messageId: message.id,\n });\n\n return {\n ...message,\n content: renderedContent,\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-renderer.test.d.ts","sourceRoot":"","sources":["../../../src/v1/utils/component-renderer.test.tsx"],"names":[],"mappings":""}
|