@tambo-ai/react 0.67.1 → 0.69.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -5
- package/dist/context-helpers/context-helpers.test.js +16 -4
- package/dist/context-helpers/context-helpers.test.js.map +1 -1
- package/dist/context-helpers/current-interactables-context-helper.d.ts +2 -2
- package/dist/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
- package/dist/context-helpers/current-interactables-context-helper.js +31 -12
- package/dist/context-helpers/current-interactables-context-helper.js.map +1 -1
- package/dist/context-helpers/registry.d.ts +2 -2
- package/dist/context-helpers/registry.d.ts.map +1 -1
- package/dist/context-helpers/registry.js.map +1 -1
- package/dist/context-helpers/types.d.ts +2 -2
- package/dist/context-helpers/types.d.ts.map +1 -1
- package/dist/context-helpers/types.js.map +1 -1
- package/dist/hoc/with-tambo-interactable.d.ts +50 -4
- package/dist/hoc/with-tambo-interactable.d.ts.map +1 -1
- package/dist/hoc/with-tambo-interactable.js +20 -5
- package/dist/hoc/with-tambo-interactable.js.map +1 -1
- package/dist/hooks/use-component-state.d.ts +3 -8
- package/dist/hooks/use-component-state.d.ts.map +1 -1
- package/dist/hooks/use-component-state.js +8 -0
- package/dist/hooks/use-component-state.js.map +1 -1
- package/dist/hooks/use-component-state.test.js +37 -0
- package/dist/hooks/use-component-state.test.js.map +1 -1
- package/dist/hooks/use-message-images.test.js +174 -37
- package/dist/hooks/use-message-images.test.js.map +1 -1
- package/dist/hooks/use-tambo-threads.js +1 -1
- package/dist/hooks/use-tambo-threads.js.map +1 -1
- package/dist/hooks/use-tambo-voice.d.ts +1 -1
- package/dist/hooks/use-tambo-voice.js +1 -1
- package/dist/hooks/use-tambo-voice.js.map +1 -1
- package/dist/hooks/use-tambo-voice.test.d.ts +2 -0
- package/dist/hooks/use-tambo-voice.test.d.ts.map +1 -0
- package/dist/hooks/use-tambo-voice.test.js +239 -0
- package/dist/hooks/use-tambo-voice.test.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/elicitation.d.ts.map +1 -1
- package/dist/mcp/elicitation.js +12 -0
- package/dist/mcp/elicitation.js.map +1 -1
- package/dist/mcp/elicitation.test.js +8 -1
- package/dist/mcp/elicitation.test.js.map +1 -1
- package/dist/mcp/mcp-client.d.ts +6 -10
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js.map +1 -1
- package/dist/mcp/mcp-constants.d.ts +19 -0
- package/dist/mcp/mcp-constants.d.ts.map +1 -0
- package/dist/mcp/mcp-constants.js +21 -0
- package/dist/mcp/mcp-constants.js.map +1 -0
- package/dist/mcp/mcp-hooks.d.ts +21 -40
- package/dist/mcp/mcp-hooks.d.ts.map +1 -1
- package/dist/mcp/mcp-hooks.js +130 -39
- package/dist/mcp/mcp-hooks.js.map +1 -1
- package/dist/mcp/mcp-hooks.test.js +431 -5
- package/dist/mcp/mcp-hooks.test.js.map +1 -1
- package/dist/mcp/tambo-mcp-provider.d.ts +7 -0
- package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/dist/mcp/tambo-mcp-provider.js +205 -155
- package/dist/mcp/tambo-mcp-provider.js.map +1 -1
- package/dist/mcp/tambo-mcp-provider.test.js +37 -0
- package/dist/mcp/tambo-mcp-provider.test.js.map +1 -1
- package/dist/model/component-metadata.d.ts +54 -21
- package/dist/model/component-metadata.d.ts.map +1 -1
- package/dist/model/component-metadata.js.map +1 -1
- package/dist/model/tambo-interactable.d.ts +13 -5
- package/dist/model/tambo-interactable.d.ts.map +1 -1
- package/dist/model/tambo-interactable.js.map +1 -1
- package/dist/providers/__tests__/thread-input-resource-resolution.test.d.ts +2 -0
- package/dist/providers/__tests__/thread-input-resource-resolution.test.d.ts.map +1 -0
- package/dist/providers/__tests__/thread-input-resource-resolution.test.js +592 -0
- package/dist/providers/__tests__/thread-input-resource-resolution.test.js.map +1 -0
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/tambo-client-provider.d.ts +8 -0
- package/dist/providers/tambo-client-provider.d.ts.map +1 -1
- package/dist/providers/tambo-client-provider.js +10 -11
- package/dist/providers/tambo-client-provider.js.map +1 -1
- package/dist/providers/tambo-client-provider.test.d.ts +2 -0
- package/dist/providers/tambo-client-provider.test.d.ts.map +1 -0
- package/dist/providers/tambo-client-provider.test.js +208 -0
- package/dist/providers/tambo-client-provider.test.js.map +1 -0
- package/dist/providers/tambo-context-attachment-provider.d.ts +34 -92
- package/dist/providers/tambo-context-attachment-provider.d.ts.map +1 -1
- package/dist/providers/tambo-context-attachment-provider.js +62 -105
- package/dist/providers/tambo-context-attachment-provider.js.map +1 -1
- package/dist/providers/tambo-context-attachment-provider.test.js +229 -463
- package/dist/providers/tambo-context-attachment-provider.test.js.map +1 -1
- package/dist/providers/tambo-interactable-provider-partial-updates.test.js +22 -21
- package/dist/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.d.ts +5 -2
- package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/dist/providers/tambo-interactable-provider.js +126 -17
- package/dist/providers/tambo-interactable-provider.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.test.js +242 -0
- package/dist/providers/tambo-interactable-provider.test.js.map +1 -1
- package/dist/providers/tambo-interactables-additional-context.test.js +2 -5
- package/dist/providers/tambo-interactables-additional-context.test.js.map +1 -1
- package/dist/providers/tambo-provider.d.ts +2 -3
- package/dist/providers/tambo-provider.d.ts.map +1 -1
- package/dist/providers/tambo-provider.js +6 -5
- package/dist/providers/tambo-provider.js.map +1 -1
- package/dist/providers/tambo-registry-provider.test.js +16 -0
- package/dist/providers/tambo-registry-provider.test.js.map +1 -1
- package/dist/providers/tambo-registry-schema-compat.test.js +31 -0
- package/dist/providers/tambo-registry-schema-compat.test.js.map +1 -1
- package/dist/providers/tambo-thread-input-provider.d.ts +1 -1
- package/dist/providers/tambo-thread-input-provider.d.ts.map +1 -1
- package/dist/providers/tambo-thread-input-provider.js +26 -4
- package/dist/providers/tambo-thread-input-provider.js.map +1 -1
- package/dist/providers/tambo-thread-provider-initial-messages.test.js +84 -2
- package/dist/providers/tambo-thread-provider-initial-messages.test.js.map +1 -1
- package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
- package/dist/providers/tambo-thread-provider.js +53 -42
- package/dist/providers/tambo-thread-provider.js.map +1 -1
- package/dist/providers/tambo-thread-provider.test.js +368 -262
- package/dist/providers/tambo-thread-provider.test.js.map +1 -1
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +2 -1
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/json-schema.d.ts +7 -0
- package/dist/schema/json-schema.d.ts.map +1 -1
- package/dist/schema/json-schema.js +40 -29
- package/dist/schema/json-schema.js.map +1 -1
- package/dist/schema/json-schema.test.d.ts +2 -0
- package/dist/schema/json-schema.test.d.ts.map +1 -0
- package/dist/schema/json-schema.test.js +204 -0
- package/dist/schema/json-schema.test.js.map +1 -0
- package/dist/schema/schema.test.js +237 -0
- package/dist/schema/schema.test.js.map +1 -1
- package/dist/schema/standard-schema.d.ts +1 -0
- package/dist/schema/standard-schema.d.ts.map +1 -1
- package/dist/schema/standard-schema.js +18 -13
- package/dist/schema/standard-schema.js.map +1 -1
- package/dist/schema/standard-schema.test.d.ts +2 -0
- package/dist/schema/standard-schema.test.d.ts.map +1 -0
- package/dist/schema/standard-schema.test.js +165 -0
- package/dist/schema/standard-schema.test.js.map +1 -0
- package/dist/schema/validate.test.js +149 -0
- package/dist/schema/validate.test.js.map +1 -1
- package/dist/schema/zod.d.ts +7 -4
- package/dist/schema/zod.d.ts.map +1 -1
- package/dist/schema/zod.js +65 -22
- package/dist/schema/zod.js.map +1 -1
- package/dist/schema/zod.test.js +112 -0
- package/dist/schema/zod.test.js.map +1 -1
- package/dist/setupTests.js +3 -0
- package/dist/setupTests.js.map +1 -1
- package/dist/testing/tools.d.ts +4 -1
- package/dist/testing/tools.d.ts.map +1 -1
- package/dist/testing/tools.js +6 -1
- package/dist/testing/tools.js.map +1 -1
- package/dist/util/generate-component.d.ts.map +1 -1
- package/dist/util/generate-component.js +18 -3
- package/dist/util/generate-component.js.map +1 -1
- package/dist/util/generate-component.test.d.ts +2 -0
- package/dist/util/generate-component.test.d.ts.map +1 -0
- package/dist/util/generate-component.test.js +340 -0
- package/dist/util/generate-component.test.js.map +1 -0
- package/dist/util/is-promise.d.ts +9 -0
- package/dist/util/is-promise.d.ts.map +1 -0
- package/dist/util/is-promise.js +20 -0
- package/dist/util/is-promise.js.map +1 -0
- package/dist/util/is-promise.test.d.ts +2 -0
- package/dist/util/is-promise.test.d.ts.map +1 -0
- package/dist/util/is-promise.test.js +48 -0
- package/dist/util/is-promise.test.js.map +1 -0
- package/dist/util/message-builder.d.ts +3 -1
- package/dist/util/message-builder.d.ts.map +1 -1
- package/dist/util/message-builder.js +20 -3
- package/dist/util/message-builder.js.map +1 -1
- package/dist/util/message-builder.test.js +269 -0
- package/dist/util/message-builder.test.js.map +1 -1
- package/dist/util/query-utils.test.d.ts +2 -0
- package/dist/util/query-utils.test.d.ts.map +1 -0
- package/dist/util/query-utils.test.js +382 -0
- package/dist/util/query-utils.test.js.map +1 -0
- package/dist/util/registry-validators.d.ts.map +1 -1
- package/dist/util/registry-validators.js +7 -0
- package/dist/util/registry-validators.js.map +1 -1
- package/dist/util/registry-validators.test.js +57 -0
- package/dist/util/registry-validators.test.js.map +1 -1
- package/dist/util/registry.d.ts.map +1 -1
- package/dist/util/registry.js +9 -0
- package/dist/util/registry.js.map +1 -1
- package/dist/util/registry.test.js +323 -1
- package/dist/util/registry.test.js.map +1 -1
- package/dist/util/resource-content-resolver.d.ts +20 -0
- package/dist/util/resource-content-resolver.d.ts.map +1 -0
- package/dist/util/resource-content-resolver.js +93 -0
- package/dist/util/resource-content-resolver.js.map +1 -0
- package/dist/util/resource-content-resolver.test.d.ts +2 -0
- package/dist/util/resource-content-resolver.test.d.ts.map +1 -0
- package/dist/util/resource-content-resolver.test.js +254 -0
- package/dist/util/resource-content-resolver.test.js.map +1 -0
- package/dist/util/resource-validators.test.d.ts +2 -0
- package/dist/util/resource-validators.test.d.ts.map +1 -0
- package/dist/util/resource-validators.test.js +90 -0
- package/dist/util/resource-validators.test.js.map +1 -0
- package/dist/util/tool-caller.d.ts +2 -2
- package/dist/util/tool-caller.d.ts.map +1 -1
- package/dist/util/tool-caller.js +8 -8
- package/dist/util/tool-caller.js.map +1 -1
- package/dist/util/validate-component-name.test.d.ts +2 -0
- package/dist/util/validate-component-name.test.d.ts.map +1 -0
- package/dist/util/validate-component-name.test.js +35 -0
- package/dist/util/validate-component-name.test.js.map +1 -0
- package/esm/context-helpers/context-helpers.test.js +16 -4
- package/esm/context-helpers/context-helpers.test.js.map +1 -1
- package/esm/context-helpers/current-interactables-context-helper.d.ts +2 -2
- package/esm/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
- package/esm/context-helpers/current-interactables-context-helper.js +31 -12
- package/esm/context-helpers/current-interactables-context-helper.js.map +1 -1
- package/esm/context-helpers/registry.d.ts +2 -2
- package/esm/context-helpers/registry.d.ts.map +1 -1
- package/esm/context-helpers/registry.js.map +1 -1
- package/esm/context-helpers/types.d.ts +2 -2
- package/esm/context-helpers/types.d.ts.map +1 -1
- package/esm/context-helpers/types.js.map +1 -1
- package/esm/hoc/with-tambo-interactable.d.ts +50 -4
- package/esm/hoc/with-tambo-interactable.d.ts.map +1 -1
- package/esm/hoc/with-tambo-interactable.js +20 -5
- package/esm/hoc/with-tambo-interactable.js.map +1 -1
- package/esm/hooks/use-component-state.d.ts +3 -8
- package/esm/hooks/use-component-state.d.ts.map +1 -1
- package/esm/hooks/use-component-state.js +8 -0
- package/esm/hooks/use-component-state.js.map +1 -1
- package/esm/hooks/use-component-state.test.js +37 -0
- package/esm/hooks/use-component-state.test.js.map +1 -1
- package/esm/hooks/use-message-images.test.js +174 -37
- package/esm/hooks/use-message-images.test.js.map +1 -1
- package/esm/hooks/use-tambo-threads.js +1 -1
- package/esm/hooks/use-tambo-threads.js.map +1 -1
- package/esm/hooks/use-tambo-voice.d.ts +1 -1
- package/esm/hooks/use-tambo-voice.js +1 -1
- package/esm/hooks/use-tambo-voice.js.map +1 -1
- package/esm/hooks/use-tambo-voice.test.d.ts +2 -0
- package/esm/hooks/use-tambo-voice.test.d.ts.map +1 -0
- package/esm/hooks/use-tambo-voice.test.js +234 -0
- package/esm/hooks/use-tambo-voice.test.js.map +1 -0
- package/esm/index.d.ts +2 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/mcp/elicitation.d.ts.map +1 -1
- package/esm/mcp/elicitation.js +12 -0
- package/esm/mcp/elicitation.js.map +1 -1
- package/esm/mcp/elicitation.test.js +8 -1
- package/esm/mcp/elicitation.test.js.map +1 -1
- package/esm/mcp/mcp-client.d.ts +6 -10
- package/esm/mcp/mcp-client.d.ts.map +1 -1
- package/esm/mcp/mcp-client.js.map +1 -1
- package/esm/mcp/mcp-constants.d.ts +19 -0
- package/esm/mcp/mcp-constants.d.ts.map +1 -0
- package/esm/mcp/mcp-constants.js +18 -0
- package/esm/mcp/mcp-constants.js.map +1 -0
- package/esm/mcp/mcp-hooks.d.ts +21 -40
- package/esm/mcp/mcp-hooks.d.ts.map +1 -1
- package/esm/mcp/mcp-hooks.js +97 -40
- package/esm/mcp/mcp-hooks.js.map +1 -1
- package/esm/mcp/mcp-hooks.test.js +431 -5
- package/esm/mcp/mcp-hooks.test.js.map +1 -1
- package/esm/mcp/tambo-mcp-provider.d.ts +7 -0
- package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/esm/mcp/tambo-mcp-provider.js +204 -154
- package/esm/mcp/tambo-mcp-provider.js.map +1 -1
- package/esm/mcp/tambo-mcp-provider.test.js +37 -0
- package/esm/mcp/tambo-mcp-provider.test.js.map +1 -1
- package/esm/model/component-metadata.d.ts +54 -21
- package/esm/model/component-metadata.d.ts.map +1 -1
- package/esm/model/component-metadata.js.map +1 -1
- package/esm/model/tambo-interactable.d.ts +13 -5
- package/esm/model/tambo-interactable.d.ts.map +1 -1
- package/esm/model/tambo-interactable.js.map +1 -1
- package/esm/providers/__tests__/thread-input-resource-resolution.test.d.ts +2 -0
- package/esm/providers/__tests__/thread-input-resource-resolution.test.d.ts.map +1 -0
- package/esm/providers/__tests__/thread-input-resource-resolution.test.js +587 -0
- package/esm/providers/__tests__/thread-input-resource-resolution.test.js.map +1 -0
- package/esm/providers/index.d.ts +1 -1
- package/esm/providers/index.d.ts.map +1 -1
- package/esm/providers/index.js.map +1 -1
- package/esm/providers/tambo-client-provider.d.ts +8 -0
- package/esm/providers/tambo-client-provider.d.ts.map +1 -1
- package/esm/providers/tambo-client-provider.js +11 -12
- package/esm/providers/tambo-client-provider.js.map +1 -1
- package/esm/providers/tambo-client-provider.test.d.ts +2 -0
- package/esm/providers/tambo-client-provider.test.d.ts.map +1 -0
- package/esm/providers/tambo-client-provider.test.js +203 -0
- package/esm/providers/tambo-client-provider.test.js.map +1 -0
- package/esm/providers/tambo-context-attachment-provider.d.ts +34 -92
- package/esm/providers/tambo-context-attachment-provider.d.ts.map +1 -1
- package/esm/providers/tambo-context-attachment-provider.js +63 -106
- package/esm/providers/tambo-context-attachment-provider.js.map +1 -1
- package/esm/providers/tambo-context-attachment-provider.test.js +230 -464
- package/esm/providers/tambo-context-attachment-provider.test.js.map +1 -1
- package/esm/providers/tambo-interactable-provider-partial-updates.test.js +22 -21
- package/esm/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.d.ts +5 -2
- package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/esm/providers/tambo-interactable-provider.js +126 -17
- package/esm/providers/tambo-interactable-provider.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.test.js +242 -0
- package/esm/providers/tambo-interactable-provider.test.js.map +1 -1
- package/esm/providers/tambo-interactables-additional-context.test.js +2 -5
- package/esm/providers/tambo-interactables-additional-context.test.js.map +1 -1
- package/esm/providers/tambo-provider.d.ts +2 -3
- package/esm/providers/tambo-provider.d.ts.map +1 -1
- package/esm/providers/tambo-provider.js +6 -5
- package/esm/providers/tambo-provider.js.map +1 -1
- package/esm/providers/tambo-registry-provider.test.js +16 -0
- package/esm/providers/tambo-registry-provider.test.js.map +1 -1
- package/esm/providers/tambo-registry-schema-compat.test.js +31 -0
- package/esm/providers/tambo-registry-schema-compat.test.js.map +1 -1
- package/esm/providers/tambo-thread-input-provider.d.ts +1 -1
- package/esm/providers/tambo-thread-input-provider.d.ts.map +1 -1
- package/esm/providers/tambo-thread-input-provider.js +26 -4
- package/esm/providers/tambo-thread-input-provider.js.map +1 -1
- package/esm/providers/tambo-thread-provider-initial-messages.test.js +84 -2
- package/esm/providers/tambo-thread-provider-initial-messages.test.js.map +1 -1
- package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
- package/esm/providers/tambo-thread-provider.js +53 -42
- package/esm/providers/tambo-thread-provider.js.map +1 -1
- package/esm/providers/tambo-thread-provider.test.js +368 -262
- package/esm/providers/tambo-thread-provider.test.js.map +1 -1
- package/esm/schema/index.d.ts +1 -1
- package/esm/schema/index.d.ts.map +1 -1
- package/esm/schema/index.js +1 -1
- package/esm/schema/index.js.map +1 -1
- package/esm/schema/json-schema.d.ts +7 -0
- package/esm/schema/json-schema.d.ts.map +1 -1
- package/esm/schema/json-schema.js +11 -1
- package/esm/schema/json-schema.js.map +1 -1
- package/esm/schema/json-schema.test.d.ts +2 -0
- package/esm/schema/json-schema.test.d.ts.map +1 -0
- package/esm/schema/json-schema.test.js +202 -0
- package/esm/schema/json-schema.test.js.map +1 -0
- package/esm/schema/schema.test.js +238 -1
- package/esm/schema/schema.test.js.map +1 -1
- package/esm/schema/standard-schema.d.ts +1 -0
- package/esm/schema/standard-schema.d.ts.map +1 -1
- package/esm/schema/standard-schema.js +18 -13
- package/esm/schema/standard-schema.js.map +1 -1
- package/esm/schema/standard-schema.test.d.ts +2 -0
- package/esm/schema/standard-schema.test.d.ts.map +1 -0
- package/esm/schema/standard-schema.test.js +130 -0
- package/esm/schema/standard-schema.test.js.map +1 -0
- package/esm/schema/validate.test.js +149 -0
- package/esm/schema/validate.test.js.map +1 -1
- package/esm/schema/zod.d.ts +7 -4
- package/esm/schema/zod.d.ts.map +1 -1
- package/esm/schema/zod.js +65 -22
- package/esm/schema/zod.js.map +1 -1
- package/esm/schema/zod.test.js +113 -1
- package/esm/schema/zod.test.js.map +1 -1
- package/esm/setupTests.js +3 -0
- package/esm/setupTests.js.map +1 -1
- package/esm/testing/tools.d.ts +4 -1
- package/esm/testing/tools.d.ts.map +1 -1
- package/esm/testing/tools.js +6 -1
- package/esm/testing/tools.js.map +1 -1
- package/esm/util/generate-component.d.ts.map +1 -1
- package/esm/util/generate-component.js +18 -3
- package/esm/util/generate-component.js.map +1 -1
- package/esm/util/generate-component.test.d.ts +2 -0
- package/esm/util/generate-component.test.d.ts.map +1 -0
- package/esm/util/generate-component.test.js +302 -0
- package/esm/util/generate-component.test.js.map +1 -0
- package/esm/util/is-promise.d.ts +9 -0
- package/esm/util/is-promise.d.ts.map +1 -0
- package/esm/util/is-promise.js +17 -0
- package/esm/util/is-promise.js.map +1 -0
- package/esm/util/is-promise.test.d.ts +2 -0
- package/esm/util/is-promise.test.d.ts.map +1 -0
- package/esm/util/is-promise.test.js +46 -0
- package/esm/util/is-promise.test.js.map +1 -0
- package/esm/util/message-builder.d.ts +3 -1
- package/esm/util/message-builder.d.ts.map +1 -1
- package/esm/util/message-builder.js +20 -3
- package/esm/util/message-builder.js.map +1 -1
- package/esm/util/message-builder.test.js +269 -0
- package/esm/util/message-builder.test.js.map +1 -1
- package/esm/util/query-utils.test.d.ts +2 -0
- package/esm/util/query-utils.test.d.ts.map +1 -0
- package/esm/util/query-utils.test.js +380 -0
- package/esm/util/query-utils.test.js.map +1 -0
- package/esm/util/registry-validators.d.ts.map +1 -1
- package/esm/util/registry-validators.js +7 -0
- package/esm/util/registry-validators.js.map +1 -1
- package/esm/util/registry-validators.test.js +57 -0
- package/esm/util/registry-validators.test.js.map +1 -1
- package/esm/util/registry.d.ts.map +1 -1
- package/esm/util/registry.js +9 -0
- package/esm/util/registry.js.map +1 -1
- package/esm/util/registry.test.js +324 -2
- package/esm/util/registry.test.js.map +1 -1
- package/esm/util/resource-content-resolver.d.ts +20 -0
- package/esm/util/resource-content-resolver.d.ts.map +1 -0
- package/esm/util/resource-content-resolver.js +89 -0
- package/esm/util/resource-content-resolver.js.map +1 -0
- package/esm/util/resource-content-resolver.test.d.ts +2 -0
- package/esm/util/resource-content-resolver.test.d.ts.map +1 -0
- package/esm/util/resource-content-resolver.test.js +252 -0
- package/esm/util/resource-content-resolver.test.js.map +1 -0
- package/esm/util/resource-validators.test.d.ts +2 -0
- package/esm/util/resource-validators.test.d.ts.map +1 -0
- package/esm/util/resource-validators.test.js +88 -0
- package/esm/util/resource-validators.test.js.map +1 -0
- package/esm/util/tool-caller.d.ts +2 -2
- package/esm/util/tool-caller.d.ts.map +1 -1
- package/esm/util/tool-caller.js +8 -8
- package/esm/util/tool-caller.js.map +1 -1
- package/esm/util/validate-component-name.test.d.ts +2 -0
- package/esm/util/validate-component-name.test.d.ts.map +1 -0
- package/esm/util/validate-component-name.test.js +33 -0
- package/esm/util/validate-component-name.test.js.map +1 -0
- package/package.json +15 -23
- package/dist/schema/alias.d.ts +0 -3
- package/dist/schema/alias.d.ts.map +0 -1
- package/dist/schema/alias.js +0 -6
- package/dist/schema/alias.js.map +0 -1
- package/esm/schema/alias.d.ts +0 -3
- package/esm/schema/alias.d.ts.map +0 -1
- package/esm/schema/alias.js +0 -13
- package/esm/schema/alias.js.map +0 -1
|
@@ -1,110 +1,52 @@
|
|
|
1
|
-
import type { Suggestion } from "@tambo-ai/typescript-sdk/resources/beta/threads/suggestions";
|
|
2
1
|
import React from "react";
|
|
3
2
|
/**
|
|
4
|
-
* Represents a context attachment that
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @property {string}
|
|
8
|
-
* @property {
|
|
9
|
-
* @property {
|
|
10
|
-
* @
|
|
11
|
-
* ```tsx
|
|
12
|
-
* const context: ContextAttachment = {
|
|
13
|
-
* name: "Button.tsx",
|
|
14
|
-
* icon: <FileIcon />,
|
|
15
|
-
* metadata: { filePath: "/src/components/Button.tsx" }
|
|
16
|
-
* };
|
|
17
|
-
* ```
|
|
3
|
+
* Represents a context attachment that will be sent with the next user message.
|
|
4
|
+
* These are automatically registered as context helpers and will be included in
|
|
5
|
+
* the additionalContext when the next message is sent.
|
|
6
|
+
* @property {string} id - Unique identifier for this context attachment
|
|
7
|
+
* @property {string} [displayName] - Optional display name for UI rendering
|
|
8
|
+
* @property {string} context - The context value that will be used in additionalContext
|
|
9
|
+
* @property {string} [type] - Optional type identifier for grouping/rendering multiple contexts of the same type
|
|
18
10
|
*/
|
|
19
11
|
export interface ContextAttachment {
|
|
20
12
|
id: string;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
displayName?: string;
|
|
14
|
+
context: string;
|
|
15
|
+
type?: string;
|
|
24
16
|
}
|
|
25
17
|
/**
|
|
26
|
-
*
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Context state interface for managing context attachments and custom suggestions.
|
|
31
|
-
* @property {ContextAttachment[]} attachments - Array of active context attachments (badges above message input)
|
|
32
|
-
* @property {(context: Omit<ContextAttachment, "id">) => void} addContextAttachment - Add a new context attachment
|
|
18
|
+
* Context state interface for managing context attachments.
|
|
19
|
+
* @property {ContextAttachment[]} attachments - Array of active context attachments
|
|
20
|
+
* @property {(contextAttachment: Omit<ContextAttachment, "id">) => ContextAttachment} addContextAttachment - Add a new context attachment, returns the attachment
|
|
33
21
|
* @property {(id: string) => void} removeContextAttachment - Remove a context attachment by ID
|
|
34
|
-
* @property {() => void} clearContextAttachments - Remove all context attachments
|
|
35
|
-
* @property {Suggestion[] | null} customSuggestions - Custom suggestions to display instead of auto-generated ones
|
|
36
|
-
* @property {(suggestions: Suggestion[] | null) => void} setCustomSuggestions - Set or clear custom suggestions
|
|
22
|
+
* @property {() => void} clearContextAttachments - Remove all context attachments
|
|
37
23
|
*/
|
|
38
24
|
export interface ContextAttachmentState {
|
|
39
25
|
attachments: ContextAttachment[];
|
|
40
|
-
addContextAttachment: (
|
|
26
|
+
addContextAttachment: (contextAttachment: Omit<ContextAttachment, "id">) => ContextAttachment;
|
|
41
27
|
removeContextAttachment: (id: string) => void;
|
|
42
28
|
clearContextAttachments: () => void;
|
|
43
|
-
customSuggestions: Suggestion[] | null;
|
|
44
|
-
setCustomSuggestions: (suggestions: Suggestion[] | null) => void;
|
|
45
29
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Props for the TamboContextAttachmentProvider.
|
|
48
|
-
* @property {(context: ContextAttachment) => Promise<ContextHelperData> | ContextHelperData} [getContextHelperData] - Optional function to customize the data sent to the AI for each context. If not provided, uses a default structure with the context name and instruction.
|
|
49
|
-
* @example
|
|
50
|
-
* ```tsx
|
|
51
|
-
* <TamboContextAttachmentProvider
|
|
52
|
-
* getContextHelperData={(context) => ({
|
|
53
|
-
* selectedFile: {
|
|
54
|
-
* name: context.name,
|
|
55
|
-
* path: context.metadata?.filePath,
|
|
56
|
-
* instruction: "Focus on this file"
|
|
57
|
-
* }
|
|
58
|
-
* })}
|
|
59
|
-
* >
|
|
60
|
-
* {children}
|
|
61
|
-
* </TamboContextAttachmentProvider>
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
30
|
export interface TamboContextAttachmentProviderProps {
|
|
65
31
|
children?: React.ReactNode;
|
|
66
|
-
getContextHelperData?: (context: ContextAttachment) => Promise<ContextHelperData> | ContextHelperData;
|
|
67
32
|
}
|
|
68
33
|
/**
|
|
69
|
-
* Provider that
|
|
70
|
-
* **When to use:**
|
|
34
|
+
* Provider that manages context attachments for the next user message.
|
|
71
35
|
* - **Included by default** in TamboProvider - no need to wrap separately
|
|
72
36
|
* - Use `useTamboContextAttachment()` hook to manage context attachments
|
|
73
37
|
* **What it does:**
|
|
74
|
-
* -
|
|
75
|
-
* -
|
|
76
|
-
* -
|
|
77
|
-
* -
|
|
78
|
-
*
|
|
38
|
+
* - Stores context attachments that will be sent with the next message
|
|
39
|
+
* - Automatically registers/deregisters context helpers for each attachment
|
|
40
|
+
* - Context helpers are automatically collected during message submission
|
|
41
|
+
* - Context attachments are cleared after message submission (one-time use)
|
|
42
|
+
*
|
|
43
|
+
* **Note:** Context attachments are automatically included in additionalContext when
|
|
44
|
+
* the next message is sent. They are cleared after submission.
|
|
79
45
|
* @param props - The props for the TamboContextAttachmentProvider
|
|
80
46
|
* @param props.children - The children to wrap
|
|
81
|
-
* @param props.getContextHelperData - The function to get the context helper data
|
|
82
47
|
* @returns The TamboContextAttachmentProvider component
|
|
83
|
-
* @example
|
|
84
|
-
* Basic usage - already included in TamboProvider
|
|
85
|
-
* ```tsx
|
|
86
|
-
* <TamboProvider apiKey="...">
|
|
87
|
-
* <App />
|
|
88
|
-
* </TamboProvider>
|
|
89
|
-
* ```
|
|
90
|
-
* @example
|
|
91
|
-
* Using TamboProvider with custom context data
|
|
92
|
-
* ```tsx
|
|
93
|
-
* <TamboProvider
|
|
94
|
-
* apiKey="..."
|
|
95
|
-
* getContextHelperData={(context) => ({
|
|
96
|
-
* selectedComponent: {
|
|
97
|
-
* name: context.name,
|
|
98
|
-
* filePath: context.metadata?.path,
|
|
99
|
-
* instruction: "Edit this component"
|
|
100
|
-
* }
|
|
101
|
-
* })}
|
|
102
|
-
* >
|
|
103
|
-
* <App />
|
|
104
|
-
* </TamboProvider>
|
|
105
|
-
* ```
|
|
106
48
|
*/
|
|
107
|
-
export declare function TamboContextAttachmentProvider({ children,
|
|
49
|
+
export declare function TamboContextAttachmentProvider({ children, }: TamboContextAttachmentProviderProps): React.JSX.Element;
|
|
108
50
|
/**
|
|
109
51
|
* Hook to access context attachment state and methods.
|
|
110
52
|
* **Must be used within a `TamboProvider`** - throws an error otherwise.
|
|
@@ -112,20 +54,20 @@ export declare function TamboContextAttachmentProvider({ children, getContextHel
|
|
|
112
54
|
* @returns The context attachment state and methods
|
|
113
55
|
* @example
|
|
114
56
|
* ```tsx
|
|
115
|
-
* const
|
|
57
|
+
* const { addContextAttachment, attachments, clearContextAttachments } = useTamboContextAttachment();
|
|
116
58
|
*
|
|
117
|
-
* // Add a context
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
59
|
+
* // Add a context attachment for the next message
|
|
60
|
+
* const attachment = addContextAttachment({
|
|
61
|
+
* context: "The contents of File.txt",
|
|
62
|
+
* displayName: "File.txt", // optional
|
|
63
|
+
* type: "file" // optional
|
|
122
64
|
* });
|
|
123
65
|
*
|
|
124
|
-
* // Remove a context
|
|
125
|
-
*
|
|
66
|
+
* // Remove a context attachment
|
|
67
|
+
* removeContextAttachment(attachment.id);
|
|
126
68
|
*
|
|
127
|
-
* //
|
|
128
|
-
*
|
|
69
|
+
* // Clear all context attachments
|
|
70
|
+
* clearContextAttachments();
|
|
129
71
|
* ```
|
|
130
72
|
*/
|
|
131
73
|
export declare function useTamboContextAttachment(): ContextAttachmentState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-context-attachment-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-context-attachment-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"tambo-context-attachment-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-context-attachment-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAON,MAAM,OAAO,CAAC;AAGf;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE,iBAAiB,EAAE,CAAC;IACjC,oBAAoB,EAAE,CACpB,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,KAC7C,iBAAiB,CAAC;IACvB,uBAAuB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,uBAAuB,EAAE,MAAM,IAAI,CAAC;CACrC;AAMD,MAAM,WAAW,mCAAmC;IAClD,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAID;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,8BAA8B,CAAC,EAC7C,QAAQ,GACT,EAAE,mCAAmC,qBAuFrC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,yBAAyB,2BAQxC"}
|
|
@@ -39,116 +39,76 @@ exports.useTamboContextAttachment = useTamboContextAttachment;
|
|
|
39
39
|
const react_1 = __importStar(require("react"));
|
|
40
40
|
const tambo_context_helpers_provider_1 = require("./tambo-context-helpers-provider");
|
|
41
41
|
const ContextAttachmentContext = (0, react_1.createContext)(null);
|
|
42
|
+
const CONTEXT_ATTACHMENTS_HELPER_KEY = "contextAttachments";
|
|
42
43
|
/**
|
|
43
|
-
* Provider that
|
|
44
|
-
* **When to use:**
|
|
44
|
+
* Provider that manages context attachments for the next user message.
|
|
45
45
|
* - **Included by default** in TamboProvider - no need to wrap separately
|
|
46
46
|
* - Use `useTamboContextAttachment()` hook to manage context attachments
|
|
47
47
|
* **What it does:**
|
|
48
|
-
* -
|
|
49
|
-
* -
|
|
50
|
-
* -
|
|
51
|
-
* -
|
|
52
|
-
*
|
|
48
|
+
* - Stores context attachments that will be sent with the next message
|
|
49
|
+
* - Automatically registers/deregisters context helpers for each attachment
|
|
50
|
+
* - Context helpers are automatically collected during message submission
|
|
51
|
+
* - Context attachments are cleared after message submission (one-time use)
|
|
52
|
+
*
|
|
53
|
+
* **Note:** Context attachments are automatically included in additionalContext when
|
|
54
|
+
* the next message is sent. They are cleared after submission.
|
|
53
55
|
* @param props - The props for the TamboContextAttachmentProvider
|
|
54
56
|
* @param props.children - The children to wrap
|
|
55
|
-
* @param props.getContextHelperData - The function to get the context helper data
|
|
56
57
|
* @returns The TamboContextAttachmentProvider component
|
|
57
|
-
* @example
|
|
58
|
-
* Basic usage - already included in TamboProvider
|
|
59
|
-
* ```tsx
|
|
60
|
-
* <TamboProvider apiKey="...">
|
|
61
|
-
* <App />
|
|
62
|
-
* </TamboProvider>
|
|
63
|
-
* ```
|
|
64
|
-
* @example
|
|
65
|
-
* Using TamboProvider with custom context data
|
|
66
|
-
* ```tsx
|
|
67
|
-
* <TamboProvider
|
|
68
|
-
* apiKey="..."
|
|
69
|
-
* getContextHelperData={(context) => ({
|
|
70
|
-
* selectedComponent: {
|
|
71
|
-
* name: context.name,
|
|
72
|
-
* filePath: context.metadata?.path,
|
|
73
|
-
* instruction: "Edit this component"
|
|
74
|
-
* }
|
|
75
|
-
* })}
|
|
76
|
-
* >
|
|
77
|
-
* <App />
|
|
78
|
-
* </TamboProvider>
|
|
79
|
-
* ```
|
|
80
58
|
*/
|
|
81
|
-
function TamboContextAttachmentProvider({ children,
|
|
82
|
-
const [attachments, setAttachments] = (0, react_1.useState)([]);
|
|
83
|
-
const [customSuggestions, setCustomSuggestions] = (0, react_1.useState)(null);
|
|
59
|
+
function TamboContextAttachmentProvider({ children, }) {
|
|
84
60
|
const { addContextHelper, removeContextHelper } = (0, tambo_context_helpers_provider_1.useTamboContextHelpers)();
|
|
85
|
-
|
|
86
|
-
const registeredIdsRef = (0, react_1.useRef)(new Set());
|
|
87
|
-
const prevGetContextHelperDataRef = (0, react_1.useRef)();
|
|
88
|
-
// Sync context helpers with attachments using useEffect
|
|
61
|
+
const [attachments, setAttachments] = (0, react_1.useState)([]);
|
|
89
62
|
(0, react_1.useEffect)(() => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
registeredIds.forEach((id) => {
|
|
94
|
-
if (!currentIds.includes(id)) {
|
|
95
|
-
removeContextHelper(id);
|
|
96
|
-
registeredIds.delete(id);
|
|
63
|
+
addContextHelper(CONTEXT_ATTACHMENTS_HELPER_KEY, () => {
|
|
64
|
+
if (attachments.length === 0) {
|
|
65
|
+
return null;
|
|
97
66
|
}
|
|
67
|
+
return attachments.map((attachment) => ({
|
|
68
|
+
id: attachment.id,
|
|
69
|
+
displayName: attachment.displayName,
|
|
70
|
+
context: attachment.context,
|
|
71
|
+
type: attachment.type,
|
|
72
|
+
}));
|
|
98
73
|
});
|
|
99
|
-
const getDataChanged = prevGetContextHelperDataRef.current !== getContextHelperData;
|
|
100
|
-
// Add or replace context helpers for attachments
|
|
101
|
-
attachments.forEach((context) => {
|
|
102
|
-
if (getDataChanged || !registeredIds.has(context.id)) {
|
|
103
|
-
addContextHelper(context.id, async () => {
|
|
104
|
-
if (getContextHelperData) {
|
|
105
|
-
return await getContextHelperData(context);
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
selectedComponent: {
|
|
109
|
-
name: context.name,
|
|
110
|
-
instruction: "This is a Tambo interactable component that is currently selected and visible on the dashboard. You can read its current props and state, and update it by modifying its props. If multiple components are attached, you can interact with and modify any of them. Use the auto-registered interactable component tools (like get_interactable_component_by_id and update_interactable_component_<id>) to view and update the component's state.",
|
|
111
|
-
...(context.metadata ?? {}),
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
});
|
|
115
|
-
registeredIds.add(context.id);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
prevGetContextHelperDataRef.current = getContextHelperData;
|
|
119
|
-
}, [
|
|
120
|
-
attachments,
|
|
121
|
-
addContextHelper,
|
|
122
|
-
removeContextHelper,
|
|
123
|
-
getContextHelperData,
|
|
124
|
-
]);
|
|
125
|
-
// Cleanup: remove all context helpers on unmount
|
|
126
|
-
(0, react_1.useEffect)(() => {
|
|
127
|
-
const registeredIds = registeredIdsRef.current;
|
|
128
74
|
return () => {
|
|
129
|
-
|
|
130
|
-
removeContextHelper(id);
|
|
131
|
-
});
|
|
132
|
-
registeredIds.clear();
|
|
75
|
+
removeContextHelper(CONTEXT_ATTACHMENTS_HELPER_KEY);
|
|
133
76
|
};
|
|
134
|
-
}, [removeContextHelper]);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
77
|
+
}, [attachments, addContextHelper, removeContextHelper]);
|
|
78
|
+
/**
|
|
79
|
+
* Adds a new context attachment that will be included with the next user message.
|
|
80
|
+
* The attachment is automatically registered as part of the merged context helper.
|
|
81
|
+
* @param contextAttachment - The context attachment input (context, optional displayName, optional type)
|
|
82
|
+
* @returns The created ContextAttachment object with a unique ID
|
|
83
|
+
* @example
|
|
84
|
+
* ```tsx
|
|
85
|
+
* const attachment = addContextAttachment({
|
|
86
|
+
* context: "The contents of File.txt",
|
|
87
|
+
* displayName: "File.txt",
|
|
88
|
+
* type: "file"
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
const addContextAttachment = (0, react_1.useCallback)((contextAttachment) => {
|
|
93
|
+
const id = crypto.randomUUID();
|
|
94
|
+
const attachment = {
|
|
95
|
+
id,
|
|
96
|
+
displayName: contextAttachment.displayName,
|
|
97
|
+
context: contextAttachment.context,
|
|
98
|
+
type: contextAttachment.type,
|
|
99
|
+
};
|
|
100
|
+
setAttachments((prev) => [...prev, attachment]);
|
|
101
|
+
return attachment;
|
|
146
102
|
}, []);
|
|
147
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Removes a context attachment by its ID.
|
|
105
|
+
*/
|
|
148
106
|
const removeContextAttachment = (0, react_1.useCallback)((id) => {
|
|
149
107
|
setAttachments((prev) => prev.filter((c) => c.id !== id));
|
|
150
108
|
}, []);
|
|
151
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Removes all context attachments at once.
|
|
111
|
+
*/
|
|
152
112
|
const clearContextAttachments = (0, react_1.useCallback)(() => {
|
|
153
113
|
setAttachments([]);
|
|
154
114
|
}, []);
|
|
@@ -157,14 +117,11 @@ function TamboContextAttachmentProvider({ children, getContextHelperData, }) {
|
|
|
157
117
|
addContextAttachment,
|
|
158
118
|
removeContextAttachment,
|
|
159
119
|
clearContextAttachments,
|
|
160
|
-
customSuggestions,
|
|
161
|
-
setCustomSuggestions,
|
|
162
120
|
}), [
|
|
163
121
|
attachments,
|
|
164
122
|
addContextAttachment,
|
|
165
123
|
removeContextAttachment,
|
|
166
124
|
clearContextAttachments,
|
|
167
|
-
customSuggestions,
|
|
168
125
|
]);
|
|
169
126
|
return (react_1.default.createElement(ContextAttachmentContext.Provider, { value: value }, children));
|
|
170
127
|
}
|
|
@@ -175,20 +132,20 @@ function TamboContextAttachmentProvider({ children, getContextHelperData, }) {
|
|
|
175
132
|
* @returns The context attachment state and methods
|
|
176
133
|
* @example
|
|
177
134
|
* ```tsx
|
|
178
|
-
* const
|
|
135
|
+
* const { addContextAttachment, attachments, clearContextAttachments } = useTamboContextAttachment();
|
|
179
136
|
*
|
|
180
|
-
* // Add a context
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
137
|
+
* // Add a context attachment for the next message
|
|
138
|
+
* const attachment = addContextAttachment({
|
|
139
|
+
* context: "The contents of File.txt",
|
|
140
|
+
* displayName: "File.txt", // optional
|
|
141
|
+
* type: "file" // optional
|
|
185
142
|
* });
|
|
186
143
|
*
|
|
187
|
-
* // Remove a context
|
|
188
|
-
*
|
|
144
|
+
* // Remove a context attachment
|
|
145
|
+
* removeContextAttachment(attachment.id);
|
|
189
146
|
*
|
|
190
|
-
* //
|
|
191
|
-
*
|
|
147
|
+
* // Clear all context attachments
|
|
148
|
+
* clearContextAttachments();
|
|
192
149
|
* ```
|
|
193
150
|
*/
|
|
194
151
|
function useTamboContextAttachment() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-context-attachment-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-context-attachment-provider.tsx"],"names":[],"mappings":"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","sourcesContent":["\"use client\";\n\nimport type { Suggestion } from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nimport React, {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useTamboContextHelpers } from \"./tambo-context-helpers-provider\";\n\n/**\n * Represents a context attachment that can be displayed in MessageInputContexts.\n * Context attachments appear as badges above the message input and provide additional\n * information to the AI about what to focus on.\n * @property {string} name - Display name shown in the badge\n * @property {React.ReactNode} [icon] - Optional icon to display in the badge\n * @property {Record<string, unknown>} [metadata] - Additional data passed to the AI\n * @example\n * ```tsx\n * const context: ContextAttachment = {\n * name: \"Button.tsx\",\n * icon: <FileIcon />,\n * metadata: { filePath: \"/src/components/Button.tsx\" }\n * };\n * ```\n */\nexport interface ContextAttachment {\n id: string;\n name: string;\n icon?: React.ReactNode;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Represents the data structure returned by a context helper\n */\nexport type ContextHelperData = Record<string, unknown>;\n\n/**\n * Context state interface for managing context attachments and custom suggestions.\n * @property {ContextAttachment[]} attachments - Array of active context attachments (badges above message input)\n * @property {(context: Omit<ContextAttachment, \"id\">) => void} addContextAttachment - Add a new context attachment\n * @property {(id: string) => void} removeContextAttachment - Remove a context attachment by ID\n * @property {() => void} clearContextAttachments - Remove all context attachments - This is used to clear the context when the user submits a message\n * @property {Suggestion[] | null} customSuggestions - Custom suggestions to display instead of auto-generated ones\n * @property {(suggestions: Suggestion[] | null) => void} setCustomSuggestions - Set or clear custom suggestions\n */\nexport interface ContextAttachmentState {\n attachments: ContextAttachment[];\n addContextAttachment: (context: Omit<ContextAttachment, \"id\">) => void;\n removeContextAttachment: (id: string) => void;\n clearContextAttachments: () => void;\n customSuggestions: Suggestion[] | null;\n setCustomSuggestions: (suggestions: Suggestion[] | null) => void;\n}\n\nconst ContextAttachmentContext = createContext<ContextAttachmentState | null>(\n null,\n);\n\n/**\n * Props for the TamboContextAttachmentProvider.\n * @property {(context: ContextAttachment) => Promise<ContextHelperData> | ContextHelperData} [getContextHelperData] - Optional function to customize the data sent to the AI for each context. If not provided, uses a default structure with the context name and instruction.\n * @example\n * ```tsx\n * <TamboContextAttachmentProvider\n * getContextHelperData={(context) => ({\n * selectedFile: {\n * name: context.name,\n * path: context.metadata?.filePath,\n * instruction: \"Focus on this file\"\n * }\n * })}\n * >\n * {children}\n * </TamboContextAttachmentProvider>\n * ```\n */\nexport interface TamboContextAttachmentProviderProps {\n children?: React.ReactNode;\n getContextHelperData?: (\n context: ContextAttachment,\n ) => Promise<ContextHelperData> | ContextHelperData;\n}\n\n/**\n * Provider that enables context attachment features and custom suggestions in MessageInput.\n * **When to use:**\n * - **Included by default** in TamboProvider - no need to wrap separately\n * - Use `useTamboContextAttachment()` hook to manage context attachments\n * **What it does:**\n * - Manages context items that appear as badges above MessageInput\n * - Syncs context data with Tambo's AI for better responses\n * - Manages custom suggestions that replace auto-generated suggestions\n * - Allows components to add/remove contexts via `useTamboContextAttachment()`\n * - Allows components to set custom suggestions via `setCustomSuggestions()`\n * @param props - The props for the TamboContextAttachmentProvider\n * @param props.children - The children to wrap\n * @param props.getContextHelperData - The function to get the context helper data\n * @returns The TamboContextAttachmentProvider component\n * @example\n * Basic usage - already included in TamboProvider\n * ```tsx\n * <TamboProvider apiKey=\"...\">\n * <App />\n * </TamboProvider>\n * ```\n * @example\n * Using TamboProvider with custom context data\n * ```tsx\n * <TamboProvider\n * apiKey=\"...\"\n * getContextHelperData={(context) => ({\n * selectedComponent: {\n * name: context.name,\n * filePath: context.metadata?.path,\n * instruction: \"Edit this component\"\n * }\n * })}\n * >\n * <App />\n * </TamboProvider>\n * ```\n */\nexport function TamboContextAttachmentProvider({\n children,\n getContextHelperData,\n}: TamboContextAttachmentProviderProps) {\n const [attachments, setAttachments] = useState<ContextAttachment[]>([]);\n const [customSuggestions, setCustomSuggestions] = useState<\n Suggestion[] | null\n >(null);\n const { addContextHelper, removeContextHelper } = useTamboContextHelpers();\n\n // Track which context helpers have been registered to avoid duplicates\n const registeredIdsRef = useRef<Set<string>>(new Set());\n const prevGetContextHelperDataRef = useRef<typeof getContextHelperData>();\n\n // Sync context helpers with attachments using useEffect\n useEffect(() => {\n const currentIds = attachments.map((a) => a.id);\n const registeredIds = registeredIdsRef.current;\n\n // Remove context helpers that are no longer in attachments\n registeredIds.forEach((id) => {\n if (!currentIds.includes(id)) {\n removeContextHelper(id);\n registeredIds.delete(id);\n }\n });\n\n const getDataChanged =\n prevGetContextHelperDataRef.current !== getContextHelperData;\n\n // Add or replace context helpers for attachments\n attachments.forEach((context) => {\n if (getDataChanged || !registeredIds.has(context.id)) {\n addContextHelper(context.id, async (): Promise<ContextHelperData> => {\n if (getContextHelperData) {\n return await getContextHelperData(context);\n }\n return {\n selectedComponent: {\n name: context.name,\n instruction:\n \"This is a Tambo interactable component that is currently selected and visible on the dashboard. You can read its current props and state, and update it by modifying its props. If multiple components are attached, you can interact with and modify any of them. Use the auto-registered interactable component tools (like get_interactable_component_by_id and update_interactable_component_<id>) to view and update the component's state.\",\n ...(context.metadata ?? {}),\n },\n };\n });\n registeredIds.add(context.id);\n }\n });\n\n prevGetContextHelperDataRef.current = getContextHelperData;\n }, [\n attachments,\n addContextHelper,\n removeContextHelper,\n getContextHelperData,\n ]);\n\n // Cleanup: remove all context helpers on unmount\n useEffect(() => {\n const registeredIds = registeredIdsRef.current;\n return () => {\n registeredIds.forEach((id) => {\n removeContextHelper(id);\n });\n registeredIds.clear();\n };\n }, [removeContextHelper]);\n\n const addContextAttachment = useCallback(\n (context: Omit<ContextAttachment, \"id\">) => {\n setAttachments((prev) => {\n if (prev.some((c) => c.name === context.name)) return prev;\n\n if (typeof crypto === \"undefined\" || !(\"randomUUID\" in crypto)) {\n throw new Error(\n \"crypto.randomUUID() is not available. This usually happens when using an IP address instead of 'localhost' in development. Use 'localhost' or a secure context (HTTPS) to enable crypto APIs.\",\n );\n }\n\n const newId = crypto.randomUUID();\n const newContext = { ...context, id: newId };\n return [...prev, newContext];\n });\n },\n [],\n );\n\n // This is used to remove a context when the user clicks the remove button\n const removeContextAttachment = useCallback((id: string) => {\n setAttachments((prev) => prev.filter((c) => c.id !== id));\n }, []);\n\n // This is used to clear the context when the user submits a message\n const clearContextAttachments = useCallback(() => {\n setAttachments([]);\n }, []);\n\n const value = useMemo(\n () => ({\n attachments,\n addContextAttachment,\n removeContextAttachment,\n clearContextAttachments,\n customSuggestions,\n setCustomSuggestions,\n }),\n [\n attachments,\n addContextAttachment,\n removeContextAttachment,\n clearContextAttachments,\n customSuggestions,\n ],\n );\n\n return (\n <ContextAttachmentContext.Provider value={value}>\n {children}\n </ContextAttachmentContext.Provider>\n );\n}\n\n/**\n * Hook to access context attachment state and methods.\n * **Must be used within a `TamboProvider`** - throws an error otherwise.\n * @throws {Error} If used outside of TamboProvider\n * @returns The context attachment state and methods\n * @example\n * ```tsx\n * const contextAttachment = useTamboContextAttachment();\n *\n * // Add a context\n * contextAttachment.addContextAttachment({\n * name: \"Button.tsx\",\n * icon: <FileIcon />,\n * metadata: { path: \"/src/Button.tsx\" }\n * });\n *\n * // Remove a context\n * contextAttachment.removeContextAttachment(contextId);\n *\n * // Set custom suggestions\n * contextAttachment.setCustomSuggestions([{ id: \"1\", title: \"Add Feature\" }]);\n * ```\n */\nexport function useTamboContextAttachment() {\n const context = useContext(ContextAttachmentContext);\n if (!context) {\n throw new Error(\n \"useTamboContextAttachment must be used within a TamboContextAttachmentProvider\",\n );\n }\n return context;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tambo-context-attachment-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-context-attachment-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEb,wEAyFC;AAyBD,8DAQC;AA9LD,+CAOe;AACf,qFAA0E;AAkC1E,MAAM,wBAAwB,GAAG,IAAA,qBAAa,EAC5C,IAAI,CACL,CAAC;AAMF,MAAM,8BAA8B,GAAG,oBAAoB,CAAC;AAE5D;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,8BAA8B,CAAC,EAC7C,QAAQ,GAC4B;IACpC,MAAM,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,GAAG,IAAA,uDAAsB,GAAE,CAAC;IAC3E,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAAsB,EAAE,CAAC,CAAC;IAExE,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,gBAAgB,CAAC,8BAA8B,EAAE,GAAG,EAAE;YACpD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC7B,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;gBACtC,EAAE,EAAE,UAAU,CAAC,EAAE;gBACjB,WAAW,EAAE,UAAU,CAAC,WAAW;gBACnC,OAAO,EAAE,UAAU,CAAC,OAAO;gBAC3B,IAAI,EAAE,UAAU,CAAC,IAAI;aACtB,CAAC,CAAC,CAAC;QACN,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,mBAAmB,CAAC,8BAA8B,CAAC,CAAC;QACtD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,WAAW,EAAE,gBAAgB,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAEzD;;;;;;;;;;;;;OAaG;IACH,MAAM,oBAAoB,GAAG,IAAA,mBAAW,EACtC,CAAC,iBAAgD,EAAqB,EAAE;QACtE,MAAM,EAAE,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QAC/B,MAAM,UAAU,GAAsB;YACpC,EAAE;YACF,WAAW,EAAE,iBAAiB,CAAC,WAAW;YAC1C,OAAO,EAAE,iBAAiB,CAAC,OAAO;YAClC,IAAI,EAAE,iBAAiB,CAAC,IAAI;SAC7B,CAAC;QACF,cAAc,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;QAEhD,OAAO,UAAU,CAAC;IACpB,CAAC,EACD,EAAE,CACH,CAAC;IAEF;;OAEG;IACH,MAAM,uBAAuB,GAAG,IAAA,mBAAW,EAAC,CAAC,EAAU,EAAE,EAAE;QACzD,cAAc,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAC5D,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP;;OAEG;IACH,MAAM,uBAAuB,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC/C,cAAc,CAAC,EAAE,CAAC,CAAC;IACrB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,KAAK,GAAG,IAAA,eAAO,EACnB,GAAG,EAAE,CAAC,CAAC;QACL,WAAW;QACX,oBAAoB;QACpB,uBAAuB;QACvB,uBAAuB;KACxB,CAAC,EACF;QACE,WAAW;QACX,oBAAoB;QACpB,uBAAuB;QACvB,uBAAuB;KACxB,CACF,CAAC;IAEF,OAAO,CACL,8BAAC,wBAAwB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAC5C,QAAQ,CACyB,CACrC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,yBAAyB;IACvC,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,wBAAwB,CAAC,CAAC;IACrD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,gFAAgF,CACjF,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["\"use client\";\n\nimport React, {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { useTamboContextHelpers } from \"./tambo-context-helpers-provider\";\n\n/**\n * Represents a context attachment that will be sent with the next user message.\n * These are automatically registered as context helpers and will be included in\n * the additionalContext when the next message is sent.\n * @property {string} id - Unique identifier for this context attachment\n * @property {string} [displayName] - Optional display name for UI rendering\n * @property {string} context - The context value that will be used in additionalContext\n * @property {string} [type] - Optional type identifier for grouping/rendering multiple contexts of the same type\n */\nexport interface ContextAttachment {\n id: string;\n displayName?: string;\n context: string;\n type?: string;\n}\n\n/**\n * Context state interface for managing context attachments.\n * @property {ContextAttachment[]} attachments - Array of active context attachments\n * @property {(contextAttachment: Omit<ContextAttachment, \"id\">) => ContextAttachment} addContextAttachment - Add a new context attachment, returns the attachment\n * @property {(id: string) => void} removeContextAttachment - Remove a context attachment by ID\n * @property {() => void} clearContextAttachments - Remove all context attachments\n */\nexport interface ContextAttachmentState {\n attachments: ContextAttachment[];\n addContextAttachment: (\n contextAttachment: Omit<ContextAttachment, \"id\">,\n ) => ContextAttachment;\n removeContextAttachment: (id: string) => void;\n clearContextAttachments: () => void;\n}\n\nconst ContextAttachmentContext = createContext<ContextAttachmentState | null>(\n null,\n);\n\nexport interface TamboContextAttachmentProviderProps {\n children?: React.ReactNode;\n}\n\nconst CONTEXT_ATTACHMENTS_HELPER_KEY = \"contextAttachments\";\n\n/**\n * Provider that manages context attachments for the next user message.\n * - **Included by default** in TamboProvider - no need to wrap separately\n * - Use `useTamboContextAttachment()` hook to manage context attachments\n * **What it does:**\n * - Stores context attachments that will be sent with the next message\n * - Automatically registers/deregisters context helpers for each attachment\n * - Context helpers are automatically collected during message submission\n * - Context attachments are cleared after message submission (one-time use)\n *\n * **Note:** Context attachments are automatically included in additionalContext when\n * the next message is sent. They are cleared after submission.\n * @param props - The props for the TamboContextAttachmentProvider\n * @param props.children - The children to wrap\n * @returns The TamboContextAttachmentProvider component\n */\nexport function TamboContextAttachmentProvider({\n children,\n}: TamboContextAttachmentProviderProps) {\n const { addContextHelper, removeContextHelper } = useTamboContextHelpers();\n const [attachments, setAttachments] = useState<ContextAttachment[]>([]);\n\n useEffect(() => {\n addContextHelper(CONTEXT_ATTACHMENTS_HELPER_KEY, () => {\n if (attachments.length === 0) {\n return null;\n }\n\n return attachments.map((attachment) => ({\n id: attachment.id,\n displayName: attachment.displayName,\n context: attachment.context,\n type: attachment.type,\n }));\n });\n\n return () => {\n removeContextHelper(CONTEXT_ATTACHMENTS_HELPER_KEY);\n };\n }, [attachments, addContextHelper, removeContextHelper]);\n\n /**\n * Adds a new context attachment that will be included with the next user message.\n * The attachment is automatically registered as part of the merged context helper.\n * @param contextAttachment - The context attachment input (context, optional displayName, optional type)\n * @returns The created ContextAttachment object with a unique ID\n * @example\n * ```tsx\n * const attachment = addContextAttachment({\n * context: \"The contents of File.txt\",\n * displayName: \"File.txt\",\n * type: \"file\"\n * });\n * ```\n */\n const addContextAttachment = useCallback(\n (contextAttachment: Omit<ContextAttachment, \"id\">): ContextAttachment => {\n const id = crypto.randomUUID();\n const attachment: ContextAttachment = {\n id,\n displayName: contextAttachment.displayName,\n context: contextAttachment.context,\n type: contextAttachment.type,\n };\n setAttachments((prev) => [...prev, attachment]);\n\n return attachment;\n },\n [],\n );\n\n /**\n * Removes a context attachment by its ID.\n */\n const removeContextAttachment = useCallback((id: string) => {\n setAttachments((prev) => prev.filter((c) => c.id !== id));\n }, []);\n\n /**\n * Removes all context attachments at once.\n */\n const clearContextAttachments = useCallback(() => {\n setAttachments([]);\n }, []);\n\n const value = useMemo(\n () => ({\n attachments,\n addContextAttachment,\n removeContextAttachment,\n clearContextAttachments,\n }),\n [\n attachments,\n addContextAttachment,\n removeContextAttachment,\n clearContextAttachments,\n ],\n );\n\n return (\n <ContextAttachmentContext.Provider value={value}>\n {children}\n </ContextAttachmentContext.Provider>\n );\n}\n\n/**\n * Hook to access context attachment state and methods.\n * **Must be used within a `TamboProvider`** - throws an error otherwise.\n * @throws {Error} If used outside of TamboProvider\n * @returns The context attachment state and methods\n * @example\n * ```tsx\n * const { addContextAttachment, attachments, clearContextAttachments } = useTamboContextAttachment();\n *\n * // Add a context attachment for the next message\n * const attachment = addContextAttachment({\n * context: \"The contents of File.txt\",\n * displayName: \"File.txt\", // optional\n * type: \"file\" // optional\n * });\n *\n * // Remove a context attachment\n * removeContextAttachment(attachment.id);\n *\n * // Clear all context attachments\n * clearContextAttachments();\n * ```\n */\nexport function useTamboContextAttachment() {\n const context = useContext(ContextAttachmentContext);\n if (!context) {\n throw new Error(\n \"useTamboContextAttachment must be used within a TamboContextAttachmentProvider\",\n );\n }\n return context;\n}\n"]}
|