@tambo-ai/react 0.49.0 → 0.53.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.
Files changed (141) hide show
  1. package/dist/hooks/__tests__/use-component-state.test.js +4 -1
  2. package/dist/hooks/__tests__/use-component-state.test.js.map +1 -1
  3. package/dist/hooks/__tests__/use-message-images.test.d.ts +2 -0
  4. package/dist/hooks/__tests__/use-message-images.test.d.ts.map +1 -0
  5. package/dist/hooks/__tests__/use-message-images.test.js +66 -0
  6. package/dist/hooks/__tests__/use-message-images.test.js.map +1 -0
  7. package/dist/hooks/__tests__/use-tambo-threads.test.js +1 -1
  8. package/dist/hooks/__tests__/use-tambo-threads.test.js.map +1 -1
  9. package/dist/hooks/use-component-state.js +3 -3
  10. package/dist/hooks/use-component-state.js.map +1 -1
  11. package/dist/hooks/use-message-images.d.ts +25 -0
  12. package/dist/hooks/use-message-images.d.ts.map +1 -0
  13. package/dist/hooks/use-message-images.js +66 -0
  14. package/dist/hooks/use-message-images.js.map +1 -0
  15. package/dist/hooks/use-suggestions.js +4 -2
  16. package/dist/hooks/use-suggestions.js.map +1 -1
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +3 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/mcp/__tests__/mcp-client.test.d.ts +2 -0
  22. package/dist/mcp/__tests__/mcp-client.test.d.ts.map +1 -0
  23. package/dist/mcp/__tests__/mcp-client.test.js +502 -0
  24. package/dist/mcp/__tests__/mcp-client.test.js.map +1 -0
  25. package/dist/mcp/mcp-client.d.ts +77 -3
  26. package/dist/mcp/mcp-client.d.ts.map +1 -1
  27. package/dist/mcp/mcp-client.js +184 -19
  28. package/dist/mcp/mcp-client.js.map +1 -1
  29. package/dist/mcp/tambo-mcp-provider.d.ts +1 -0
  30. package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
  31. package/dist/mcp/tambo-mcp-provider.js +1 -0
  32. package/dist/mcp/tambo-mcp-provider.js.map +1 -1
  33. package/dist/model/tambo-interactable.d.ts +1 -1
  34. package/dist/model/tambo-interactable.d.ts.map +1 -1
  35. package/dist/model/tambo-interactable.js.map +1 -1
  36. package/dist/providers/__tests__/tambo-interactable-provider-partial-updates.test.d.ts +2 -0
  37. package/dist/providers/__tests__/tambo-interactable-provider-partial-updates.test.d.ts.map +1 -0
  38. package/dist/providers/__tests__/tambo-interactable-provider-partial-updates.test.js +677 -0
  39. package/dist/providers/__tests__/tambo-interactable-provider-partial-updates.test.js.map +1 -0
  40. package/dist/providers/__tests__/tambo-stubs.test.js +6 -2
  41. package/dist/providers/__tests__/tambo-stubs.test.js.map +1 -1
  42. package/dist/providers/__tests__/tambo-thread-provider.test.js +14 -14
  43. package/dist/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
  44. package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
  45. package/dist/providers/tambo-interactable-provider.js +26 -24
  46. package/dist/providers/tambo-interactable-provider.js.map +1 -1
  47. package/dist/providers/tambo-provider.d.ts +1 -0
  48. package/dist/providers/tambo-provider.d.ts.map +1 -1
  49. package/dist/providers/tambo-provider.js +1 -0
  50. package/dist/providers/tambo-provider.js.map +1 -1
  51. package/dist/providers/tambo-thread-input-provider.d.ts +11 -0
  52. package/dist/providers/tambo-thread-input-provider.d.ts.map +1 -1
  53. package/dist/providers/tambo-thread-input-provider.js +63 -12
  54. package/dist/providers/tambo-thread-input-provider.js.map +1 -1
  55. package/dist/providers/tambo-thread-provider.d.ts +1 -0
  56. package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
  57. package/dist/providers/tambo-thread-provider.js +9 -5
  58. package/dist/providers/tambo-thread-provider.js.map +1 -1
  59. package/dist/setupTests.d.ts +0 -1
  60. package/dist/setupTests.d.ts.map +1 -1
  61. package/dist/setupTests.js +0 -1
  62. package/dist/setupTests.js.map +1 -1
  63. package/dist/util/__tests__/message-builder.test.d.ts +2 -0
  64. package/dist/util/__tests__/message-builder.test.d.ts.map +1 -0
  65. package/dist/util/__tests__/message-builder.test.js +191 -0
  66. package/dist/util/__tests__/message-builder.test.js.map +1 -0
  67. package/dist/util/message-builder.d.ts +10 -0
  68. package/dist/util/message-builder.d.ts.map +1 -0
  69. package/dist/util/message-builder.js +31 -0
  70. package/dist/util/message-builder.js.map +1 -0
  71. package/esm/hooks/__tests__/use-component-state.test.js +4 -1
  72. package/esm/hooks/__tests__/use-component-state.test.js.map +1 -1
  73. package/esm/hooks/__tests__/use-message-images.test.d.ts +2 -0
  74. package/esm/hooks/__tests__/use-message-images.test.d.ts.map +1 -0
  75. package/esm/hooks/__tests__/use-message-images.test.js +64 -0
  76. package/esm/hooks/__tests__/use-message-images.test.js.map +1 -0
  77. package/esm/hooks/__tests__/use-tambo-threads.test.js +1 -1
  78. package/esm/hooks/__tests__/use-tambo-threads.test.js.map +1 -1
  79. package/esm/hooks/use-component-state.js +3 -3
  80. package/esm/hooks/use-component-state.js.map +1 -1
  81. package/esm/hooks/use-message-images.d.ts +25 -0
  82. package/esm/hooks/use-message-images.d.ts.map +1 -0
  83. package/esm/hooks/use-message-images.js +63 -0
  84. package/esm/hooks/use-message-images.js.map +1 -0
  85. package/esm/hooks/use-suggestions.js +4 -2
  86. package/esm/hooks/use-suggestions.js.map +1 -1
  87. package/esm/index.d.ts +1 -0
  88. package/esm/index.d.ts.map +1 -1
  89. package/esm/index.js +1 -0
  90. package/esm/index.js.map +1 -1
  91. package/esm/mcp/__tests__/mcp-client.test.d.ts +2 -0
  92. package/esm/mcp/__tests__/mcp-client.test.d.ts.map +1 -0
  93. package/esm/mcp/__tests__/mcp-client.test.js +500 -0
  94. package/esm/mcp/__tests__/mcp-client.test.js.map +1 -0
  95. package/esm/mcp/mcp-client.d.ts +77 -3
  96. package/esm/mcp/mcp-client.d.ts.map +1 -1
  97. package/esm/mcp/mcp-client.js +184 -19
  98. package/esm/mcp/mcp-client.js.map +1 -1
  99. package/esm/mcp/tambo-mcp-provider.d.ts +1 -0
  100. package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
  101. package/esm/mcp/tambo-mcp-provider.js +1 -0
  102. package/esm/mcp/tambo-mcp-provider.js.map +1 -1
  103. package/esm/model/tambo-interactable.d.ts +1 -1
  104. package/esm/model/tambo-interactable.d.ts.map +1 -1
  105. package/esm/model/tambo-interactable.js.map +1 -1
  106. package/esm/providers/__tests__/tambo-interactable-provider-partial-updates.test.d.ts +2 -0
  107. package/esm/providers/__tests__/tambo-interactable-provider-partial-updates.test.d.ts.map +1 -0
  108. package/esm/providers/__tests__/tambo-interactable-provider-partial-updates.test.js +672 -0
  109. package/esm/providers/__tests__/tambo-interactable-provider-partial-updates.test.js.map +1 -0
  110. package/esm/providers/__tests__/tambo-stubs.test.js +6 -2
  111. package/esm/providers/__tests__/tambo-stubs.test.js.map +1 -1
  112. package/esm/providers/__tests__/tambo-thread-provider.test.js +14 -14
  113. package/esm/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
  114. package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
  115. package/esm/providers/tambo-interactable-provider.js +26 -24
  116. package/esm/providers/tambo-interactable-provider.js.map +1 -1
  117. package/esm/providers/tambo-provider.d.ts +1 -0
  118. package/esm/providers/tambo-provider.d.ts.map +1 -1
  119. package/esm/providers/tambo-provider.js +1 -0
  120. package/esm/providers/tambo-provider.js.map +1 -1
  121. package/esm/providers/tambo-thread-input-provider.d.ts +11 -0
  122. package/esm/providers/tambo-thread-input-provider.d.ts.map +1 -1
  123. package/esm/providers/tambo-thread-input-provider.js +63 -12
  124. package/esm/providers/tambo-thread-input-provider.js.map +1 -1
  125. package/esm/providers/tambo-thread-provider.d.ts +1 -0
  126. package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
  127. package/esm/providers/tambo-thread-provider.js +9 -5
  128. package/esm/providers/tambo-thread-provider.js.map +1 -1
  129. package/esm/setupTests.d.ts +0 -1
  130. package/esm/setupTests.d.ts.map +1 -1
  131. package/esm/setupTests.js +0 -1
  132. package/esm/setupTests.js.map +1 -1
  133. package/esm/util/__tests__/message-builder.test.d.ts +2 -0
  134. package/esm/util/__tests__/message-builder.test.d.ts.map +1 -0
  135. package/esm/util/__tests__/message-builder.test.js +189 -0
  136. package/esm/util/__tests__/message-builder.test.js.map +1 -0
  137. package/esm/util/message-builder.d.ts +10 -0
  138. package/esm/util/message-builder.d.ts.map +1 -0
  139. package/esm/util/message-builder.js +28 -0
  140. package/esm/util/message-builder.js.map +1 -0
  141. package/package.json +7 -7
@@ -38,14 +38,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.useCurrentInteractablesSnapshot = exports.useTamboInteractable = exports.TamboInteractableProvider = void 0;
39
39
  const react_1 = __importStar(require("react"));
40
40
  const zod_1 = require("zod");
41
+ const current_interactables_context_helper_1 = require("../context-helpers/current-interactables-context-helper");
41
42
  const tambo_component_provider_1 = require("./tambo-component-provider");
42
43
  const tambo_context_helpers_provider_1 = require("./tambo-context-helpers-provider");
43
- const current_interactables_context_helper_1 = require("../context-helpers/current-interactables-context-helper");
44
44
  const TamboInteractableContext = (0, react_1.createContext)({
45
45
  interactableComponents: [],
46
46
  addInteractableComponent: () => "",
47
47
  removeInteractableComponent: () => { },
48
- updateInteractableComponentProps: () => { },
48
+ updateInteractableComponentProps: () => "",
49
49
  getInteractableComponent: () => undefined,
50
50
  getInteractableComponentsByName: () => [],
51
51
  clearAllInteractableComponents: () => { },
@@ -166,40 +166,42 @@ const TamboInteractableProvider = ({ children, }) => {
166
166
  }
167
167
  }, [interactableComponents, registerTool]);
168
168
  const updateInteractableComponentProps = (0, react_1.useCallback)((id, newProps) => {
169
- let updateResult = "Updated successfully";
169
+ if (!newProps || Object.keys(newProps).length === 0) {
170
+ return `Warning: No props provided for component with ID ${id}.`;
171
+ }
170
172
  setInteractableComponents((prev) => {
171
- const componentExists = prev.some((c) => c.id === id);
172
- if (!componentExists) {
173
- updateResult = `Error: Component with ID ${id} not found`;
173
+ const component = prev.find((c) => c.id === id);
174
+ if (!component) {
174
175
  return prev;
175
176
  }
176
- const updatedComponents = prev.map((c) => c.id === id ? { ...c, props: { ...c.props, ...newProps } } : c);
177
- // Check if the update actually changed anything
178
- const originalComponent = prev.find((c) => c.id === id);
179
- const updatedComponent = updatedComponents.find((c) => c.id === id);
180
- if (!originalComponent || !updatedComponent) {
181
- updateResult = `Error: Failed to update component with ID ${id}`;
182
- return prev;
183
- }
184
- // Check if props actually changed
185
- const propsChanged = JSON.stringify(originalComponent.props) !==
186
- JSON.stringify(updatedComponent.props);
177
+ // Compare props shallowly
178
+ const propsChanged = Object.entries(newProps).some(([key, value]) => {
179
+ return component.props[key] !== value;
180
+ });
187
181
  if (!propsChanged) {
188
- updateResult = `Warning: No changes detected for component with ID ${id}. The update might not have worked.`;
189
- return prev;
182
+ return prev; // unchanged
190
183
  }
184
+ // Apply partial update
185
+ const updated = {
186
+ ...component,
187
+ props: { ...component.props, ...newProps },
188
+ };
189
+ const updatedComponents = [...prev];
190
+ const idx = prev.findIndex((c) => c.id === id);
191
+ updatedComponents[idx] = updated;
191
192
  return updatedComponents;
192
193
  });
193
- return updateResult;
194
+ return "Updated successfully";
194
195
  }, []);
195
196
  const registerInteractableComponentUpdateTool = (0, react_1.useCallback)((component) => {
196
197
  const schemaForArgs = typeof component.propsSchema === "object" &&
197
- "describe" in component.propsSchema
198
- ? component.propsSchema
198
+ "describe" in component.propsSchema &&
199
+ "partial" in component.propsSchema
200
+ ? component.propsSchema.partial()
199
201
  : zod_1.z.object({});
200
202
  registerTool({
201
203
  name: `update_interactable_component_${component.id}`,
202
- description: `Update the props of interactable component ${component.id} (${component.name})`,
204
+ description: `Update the props of interactable component ${component.id} (${component.name}). You can provide partial props (only the props you want to change) or complete props (all props). Only the props you specify will be updated.`,
203
205
  tool: (componentId, newProps) => {
204
206
  return updateInteractableComponentProps(componentId, newProps);
205
207
  },
@@ -207,7 +209,7 @@ const TamboInteractableProvider = ({ children, }) => {
207
209
  .function()
208
210
  .args(zod_1.z
209
211
  .string()
210
- .describe("The ID of the interactable component to update"), schemaForArgs.describe("The new props to update the component with"))
212
+ .describe("The ID of the interactable component to update"), schemaForArgs.describe("The props to update the component with. You can provide partial props (only the props you want to change) or complete props (all props). Only the props you specify will be updated."))
211
213
  .returns(zod_1.z.string()),
212
214
  });
213
215
  }, [registerTool, updateInteractableComponentProps]);
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-interactable-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-interactable-provider.tsx"],"names":[],"mappings":";AAAA,0DAA0D;AAC1D,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAOe;AACf,6BAAwB;AAKxB,yEAA+D;AAC/D,qFAA0E;AAC1E,kHAA2G;AAE3G,MAAM,wBAAwB,GAAG,IAAA,qBAAa,EAA2B;IACvE,sBAAsB,EAAE,EAAE;IAC1B,wBAAwB,EAAE,GAAG,EAAE,CAAC,EAAE;IAClC,2BAA2B,EAAE,GAAG,EAAE,GAAE,CAAC;IACrC,gCAAgC,EAAE,GAAG,EAAE,GAAE,CAAC;IAC1C,wBAAwB,EAAE,GAAG,EAAE,CAAC,SAAS;IACzC,+BAA+B,EAAE,GAAG,EAAE,CAAC,EAAE;IACzC,8BAA8B,EAAE,GAAG,EAAE,GAAE,CAAC;CACzC,CAAC,CAAC;AAEH;;;;;;;GAOG;AACI,MAAM,yBAAyB,GAAgC,CAAC,EACrE,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,CAAC,sBAAsB,EAAE,yBAAyB,CAAC,GAAG,IAAA,gBAAQ,EAElE,EAAE,CAAC,CAAC;IACN,MAAM,EAAE,YAAY,EAAE,GAAG,IAAA,4CAAiB,GAAE,CAAC;IAC7C,MAAM,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,GAAG,IAAA,uDAAsB,GAAE,CAAC;IAE3E,0CAA0C;IAC1C,MAAM,aAAa,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QACrC,OAA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,QAAQ,IAAC,KAAK,EAAE,KAAK,IAC5C,QAAQ,CACyB,CACrC,CAAC;AACJ,CAAC,CAAC;AA7QW,QAAA,yBAAyB,6BA6QpC;AAEF;;;;GAIG;AACI,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACvC,OAAO,IAAA,kBAAU,EAAC,wBAAwB,CAAC,CAAC;AAC9C,CAAC,CAAC;AAFW,QAAA,oBAAoB,wBAE/B;AAEF;;;;;GAKG;AACI,MAAM,+BAA+B,GAAG,GAAG,EAAE;IAClD,MAAM,EAAE,sBAAsB,EAAE,GAAG,IAAA,4BAAoB,GAAE,CAAC;IAE1D,0DAA0D;IAC1D,MAAM,IAAI,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC9C,GAAG,CAAC;QACJ,KAAK,EAAE,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE;KACtB,CAAC,CAAC,CAAC;IAEJ,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAVW,QAAA,+BAA+B,mCAU1C","sourcesContent":["// react-sdk/src/providers/tambo-interactable-provider.tsx\n\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport { z } from \"zod\";\nimport {\n TamboInteractableComponent,\n type TamboInteractableContext,\n} from \"../model/tambo-interactable\";\nimport { useTamboComponent } from \"./tambo-component-provider\";\nimport { useTamboContextHelpers } from \"./tambo-context-helpers-provider\";\nimport { createInteractablesContextHelper } from \"../context-helpers/current-interactables-context-helper\";\n\nconst TamboInteractableContext = createContext<TamboInteractableContext>({\n interactableComponents: [],\n addInteractableComponent: () => \"\",\n removeInteractableComponent: () => {},\n updateInteractableComponentProps: () => {},\n getInteractableComponent: () => undefined,\n getInteractableComponentsByName: () => [],\n clearAllInteractableComponents: () => {},\n});\n\n/**\n * The TamboInteractableProvider manages a list of components that are currently\n * interactable, allowing tambo to interact with them by updating their props. It also registers tools\n * for Tambo to perform CRUD operations on the components list.\n * @param props - The props for the TamboInteractableProvider\n * @param props.children - The children to wrap\n * @returns The TamboInteractableProvider component\n */\nexport const TamboInteractableProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const [interactableComponents, setInteractableComponents] = useState<\n TamboInteractableComponent[]\n >([]);\n const { registerTool } = useTamboComponent();\n const { addContextHelper, removeContextHelper } = useTamboContextHelpers();\n\n // Create a stable context helper function\n const contextHelper = useCallback(() => {\n return createInteractablesContextHelper(() => interactableComponents)();\n }, [interactableComponents]);\n\n // Register the default interactables context helper\n useEffect(() => {\n addContextHelper(\"interactables\", contextHelper);\n\n return () => {\n removeContextHelper(\"interactables\");\n };\n }, [contextHelper, addContextHelper, removeContextHelper]);\n\n useEffect(() => {\n if (interactableComponents.length > 0) {\n registerTool({\n name: \"get_all_interactable_components\",\n description:\n \"Only use this tool if the user is asking about interactable components.Get all currently interactable components with their details including their current props. These are components that you can interact with on behalf of the user.\",\n tool: () => {\n return {\n components: interactableComponents,\n };\n },\n toolSchema: z.function().returns(\n z.object({\n components: z.array(\n z.object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.any()),\n propsSchema: z.object({}).optional(),\n }),\n ),\n }),\n ),\n });\n\n registerTool({\n name: \"get_interactable_component_by_id\",\n description: \"Get a specific interactable component by its ID\",\n tool: (componentId: string) => {\n const component = interactableComponents.find(\n (c) => c.id === componentId,\n );\n\n if (!component) {\n return {\n success: false,\n error: `Component with ID ${componentId} not found`,\n };\n }\n\n return {\n success: true,\n component: {\n id: component.id,\n componentName: component.name,\n props: component.props,\n },\n };\n },\n toolSchema: z\n .function()\n .args(z.string())\n .returns(\n z.object({\n success: z.boolean(),\n component: z\n .object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.any()),\n })\n .optional(),\n error: z.string().optional(),\n }),\n ),\n });\n\n registerTool({\n name: \"remove_interactable_component\",\n description: \"Remove an interactable component from the system\",\n tool: (componentId: string) => {\n const component = interactableComponents.find(\n (c) => c.id === componentId,\n );\n\n if (!component) {\n return {\n success: false,\n error: `Component with ID ${componentId} not found`,\n };\n }\n\n setInteractableComponents((prev) =>\n prev.filter((c) => c.id !== componentId),\n );\n\n return {\n success: true,\n componentId,\n removedComponent: {\n id: component.id,\n componentName: component.name,\n props: component.props,\n },\n };\n },\n toolSchema: z\n .function()\n .args(z.string())\n .returns(\n z.object({\n success: z.boolean(),\n componentId: z.string(),\n removedComponent: z.object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.any()),\n }),\n error: z.string().optional(),\n }),\n ),\n });\n }\n }, [interactableComponents, registerTool]);\n\n const updateInteractableComponentProps = useCallback(\n (id: string, newProps: Record<string, any>) => {\n let updateResult = \"Updated successfully\";\n\n setInteractableComponents((prev) => {\n const componentExists = prev.some((c) => c.id === id);\n\n if (!componentExists) {\n updateResult = `Error: Component with ID ${id} not found`;\n return prev;\n }\n\n const updatedComponents = prev.map((c) =>\n c.id === id ? { ...c, props: { ...c.props, ...newProps } } : c,\n );\n\n // Check if the update actually changed anything\n const originalComponent = prev.find((c) => c.id === id);\n const updatedComponent = updatedComponents.find((c) => c.id === id);\n\n if (!originalComponent || !updatedComponent) {\n updateResult = `Error: Failed to update component with ID ${id}`;\n return prev;\n }\n\n // Check if props actually changed\n const propsChanged =\n JSON.stringify(originalComponent.props) !==\n JSON.stringify(updatedComponent.props);\n\n if (!propsChanged) {\n updateResult = `Warning: No changes detected for component with ID ${id}. The update might not have worked.`;\n return prev;\n }\n\n return updatedComponents;\n });\n\n return updateResult;\n },\n [],\n );\n\n const registerInteractableComponentUpdateTool = useCallback(\n (component: TamboInteractableComponent) => {\n const schemaForArgs =\n typeof component.propsSchema === \"object\" &&\n \"describe\" in component.propsSchema\n ? component.propsSchema\n : z.object({});\n\n registerTool({\n name: `update_interactable_component_${component.id}`,\n description: `Update the props of interactable component ${component.id} (${component.name})`,\n tool: (componentId: string, newProps: any) => {\n return updateInteractableComponentProps(componentId, newProps);\n },\n toolSchema: z\n .function()\n .args(\n z\n .string()\n .describe(\"The ID of the interactable component to update\"),\n schemaForArgs.describe(\n \"The new props to update the component with\",\n ),\n )\n .returns(z.string()),\n });\n },\n [registerTool, updateInteractableComponentProps],\n );\n\n const addInteractableComponent = useCallback(\n (\n component: Omit<TamboInteractableComponent, \"id\" | \"createdAt\">,\n ): string => {\n const id = `${component.name}-${Math.random().toString(36).slice(2, 11)}`;\n const newComponent: TamboInteractableComponent = {\n ...component,\n id,\n };\n\n registerInteractableComponentUpdateTool(newComponent);\n\n setInteractableComponents((prev) => {\n return [...prev, newComponent];\n });\n\n return id;\n },\n [registerInteractableComponentUpdateTool],\n );\n\n const removeInteractableComponent = useCallback((id: string) => {\n setInteractableComponents((prev) => prev.filter((c) => c.id !== id));\n }, []);\n\n const getInteractableComponent = useCallback(\n (id: string) => {\n return interactableComponents.find((c) => c.id === id);\n },\n [interactableComponents],\n );\n\n const getInteractableComponentsByName = useCallback(\n (componentName: string) => {\n return interactableComponents.filter((c) => c.name === componentName);\n },\n [interactableComponents],\n );\n\n const clearAllInteractableComponents = useCallback(() => {\n setInteractableComponents([]);\n }, []);\n\n const value: TamboInteractableContext = {\n interactableComponents,\n addInteractableComponent,\n removeInteractableComponent,\n updateInteractableComponentProps,\n getInteractableComponent,\n getInteractableComponentsByName,\n clearAllInteractableComponents,\n };\n\n return (\n <TamboInteractableContext.Provider value={value}>\n {children}\n </TamboInteractableContext.Provider>\n );\n};\n\n/**\n * The useTamboInteractable hook provides access to the interactable component\n * management functions.\n * @returns The interactable component management functions\n */\nexport const useTamboInteractable = () => {\n return useContext(TamboInteractableContext);\n};\n\n/**\n * Hook to get a cloned snapshot of the current interactables.\n * Returns a shallow copy of the array with cloned items and props to prevent\n * external mutation from affecting internal state.\n * @returns The current interactables snapshot (cloned).\n */\nexport const useCurrentInteractablesSnapshot = () => {\n const { interactableComponents } = useTamboInteractable();\n\n // Clone the array and each item/props to prevent mutation\n const copy = interactableComponents.map((c) => ({\n ...c,\n props: { ...c.props },\n }));\n\n return copy;\n};\n"]}
1
+ {"version":3,"file":"tambo-interactable-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-interactable-provider.tsx"],"names":[],"mappings":";AAAA,0DAA0D;AAC1D,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAOe;AACf,6BAAwB;AACxB,kHAA2G;AAK3G,yEAA+D;AAC/D,qFAA0E;AAE1E,MAAM,wBAAwB,GAAG,IAAA,qBAAa,EAA2B;IACvE,sBAAsB,EAAE,EAAE;IAC1B,wBAAwB,EAAE,GAAG,EAAE,CAAC,EAAE;IAClC,2BAA2B,EAAE,GAAG,EAAE,GAAE,CAAC;IACrC,gCAAgC,EAAE,GAAG,EAAE,CAAC,EAAE;IAC1C,wBAAwB,EAAE,GAAG,EAAE,CAAC,SAAS;IACzC,+BAA+B,EAAE,GAAG,EAAE,CAAC,EAAE;IACzC,8BAA8B,EAAE,GAAG,EAAE,GAAE,CAAC;CACzC,CAAC,CAAC;AAEH;;;;;;;GAOG;AACI,MAAM,yBAAyB,GAAgC,CAAC,EACrE,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,CAAC,sBAAsB,EAAE,yBAAyB,CAAC,GAAG,IAAA,gBAAQ,EAElE,EAAE,CAAC,CAAC;IACN,MAAM,EAAE,YAAY,EAAE,GAAG,IAAA,4CAAiB,GAAE,CAAC;IAC7C,MAAM,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,GAAG,IAAA,uDAAsB,GAAE,CAAC;IAE3E,0CAA0C;IAC1C,MAAM,aAAa,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QACrC,OAAO,IAAA,uEAAgC,EAAC,GAAG,EAAE,CAAC,sBAAsB,CAAC,EAAE,CAAC;IAC1E,CAAC,EAAE,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAE7B,oDAAoD;IACpD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,gBAAgB,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC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AsB,EAAE,GAAG,IAAA,4BAAoB,GAAE,CAAC;IAC1D,0DAA0D;IAC1D,MAAM,IAAI,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC9C,GAAG,CAAC;QACJ,KAAK,EAAE,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE;KACtB,CAAC,CAAC,CAAC;IAEJ,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AATW,QAAA,+BAA+B,mCAS1C","sourcesContent":["// react-sdk/src/providers/tambo-interactable-provider.tsx\n\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport { z } from \"zod\";\nimport { createInteractablesContextHelper } from \"../context-helpers/current-interactables-context-helper\";\nimport {\n TamboInteractableComponent,\n type TamboInteractableContext,\n} from \"../model/tambo-interactable\";\nimport { useTamboComponent } from \"./tambo-component-provider\";\nimport { useTamboContextHelpers } from \"./tambo-context-helpers-provider\";\n\nconst TamboInteractableContext = createContext<TamboInteractableContext>({\n interactableComponents: [],\n addInteractableComponent: () => \"\",\n removeInteractableComponent: () => {},\n updateInteractableComponentProps: () => \"\",\n getInteractableComponent: () => undefined,\n getInteractableComponentsByName: () => [],\n clearAllInteractableComponents: () => {},\n});\n\n/**\n * The TamboInteractableProvider manages a list of components that are currently\n * interactable, allowing tambo to interact with them by updating their props. It also registers tools\n * for Tambo to perform CRUD operations on the components list.\n * @param props - The props for the TamboInteractableProvider\n * @param props.children - The children to wrap\n * @returns The TamboInteractableProvider component\n */\nexport const TamboInteractableProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const [interactableComponents, setInteractableComponents] = useState<\n TamboInteractableComponent[]\n >([]);\n const { registerTool } = useTamboComponent();\n const { addContextHelper, removeContextHelper } = useTamboContextHelpers();\n\n // Create a stable context helper function\n const contextHelper = useCallback(() => {\n return createInteractablesContextHelper(() => interactableComponents)();\n }, [interactableComponents]);\n\n // Register the default interactables context helper\n useEffect(() => {\n addContextHelper(\"interactables\", contextHelper);\n\n return () => {\n removeContextHelper(\"interactables\");\n };\n }, [contextHelper, addContextHelper, removeContextHelper]);\n\n useEffect(() => {\n if (interactableComponents.length > 0) {\n registerTool({\n name: \"get_all_interactable_components\",\n description:\n \"Only use this tool if the user is asking about interactable components.Get all currently interactable components with their details including their current props. These are components that you can interact with on behalf of the user.\",\n tool: () => {\n return {\n components: interactableComponents,\n };\n },\n toolSchema: z.function().returns(\n z.object({\n components: z.array(\n z.object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.any()),\n propsSchema: z.object({}).optional(),\n }),\n ),\n }),\n ),\n });\n\n registerTool({\n name: \"get_interactable_component_by_id\",\n description: \"Get a specific interactable component by its ID\",\n tool: (componentId: string) => {\n const component = interactableComponents.find(\n (c) => c.id === componentId,\n );\n\n if (!component) {\n return {\n success: false,\n error: `Component with ID ${componentId} not found`,\n };\n }\n\n return {\n success: true,\n component: {\n id: component.id,\n componentName: component.name,\n props: component.props,\n },\n };\n },\n toolSchema: z\n .function()\n .args(z.string())\n .returns(\n z.object({\n success: z.boolean(),\n component: z\n .object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.any()),\n })\n .optional(),\n error: z.string().optional(),\n }),\n ),\n });\n\n registerTool({\n name: \"remove_interactable_component\",\n description: \"Remove an interactable component from the system\",\n tool: (componentId: string) => {\n const component = interactableComponents.find(\n (c) => c.id === componentId,\n );\n\n if (!component) {\n return {\n success: false,\n error: `Component with ID ${componentId} not found`,\n };\n }\n\n setInteractableComponents((prev) =>\n prev.filter((c) => c.id !== componentId),\n );\n\n return {\n success: true,\n componentId,\n removedComponent: {\n id: component.id,\n componentName: component.name,\n props: component.props,\n },\n };\n },\n toolSchema: z\n .function()\n .args(z.string())\n .returns(\n z.object({\n success: z.boolean(),\n componentId: z.string(),\n removedComponent: z.object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.any()),\n }),\n error: z.string().optional(),\n }),\n ),\n });\n }\n }, [interactableComponents, registerTool]);\n\n const updateInteractableComponentProps = useCallback(\n (id: string, newProps: Record<string, any>): string => {\n if (!newProps || Object.keys(newProps).length === 0) {\n return `Warning: No props provided for component with ID ${id}.`;\n }\n\n setInteractableComponents((prev) => {\n const component = prev.find((c) => c.id === id);\n if (!component) {\n return prev;\n }\n\n // Compare props shallowly\n const propsChanged = Object.entries(newProps).some(([key, value]) => {\n return component.props[key] !== value;\n });\n\n if (!propsChanged) {\n return prev; // unchanged\n }\n\n // Apply partial update\n const updated = {\n ...component,\n props: { ...component.props, ...newProps },\n };\n\n const updatedComponents = [...prev];\n const idx = prev.findIndex((c) => c.id === id);\n updatedComponents[idx] = updated;\n\n return updatedComponents;\n });\n\n return \"Updated successfully\";\n },\n [],\n );\n\n const registerInteractableComponentUpdateTool = useCallback(\n (component: TamboInteractableComponent) => {\n const schemaForArgs =\n typeof component.propsSchema === \"object\" &&\n \"describe\" in component.propsSchema &&\n \"partial\" in component.propsSchema\n ? (component.propsSchema as any).partial()\n : z.object({});\n\n registerTool({\n name: `update_interactable_component_${component.id}`,\n description: `Update the props of interactable component ${component.id} (${component.name}). You can provide partial props (only the props you want to change) or complete props (all props). Only the props you specify will be updated.`,\n tool: (componentId: string, newProps: any) => {\n return updateInteractableComponentProps(componentId, newProps);\n },\n toolSchema: z\n .function()\n .args(\n z\n .string()\n .describe(\"The ID of the interactable component to update\"),\n schemaForArgs.describe(\n \"The props to update the component with. You can provide partial props (only the props you want to change) or complete props (all props). Only the props you specify will be updated.\",\n ),\n )\n .returns(z.string()),\n });\n },\n [registerTool, updateInteractableComponentProps],\n );\n\n const addInteractableComponent = useCallback(\n (\n component: Omit<TamboInteractableComponent, \"id\" | \"createdAt\">,\n ): string => {\n const id = `${component.name}-${Math.random().toString(36).slice(2, 11)}`;\n const newComponent: TamboInteractableComponent = {\n ...component,\n id,\n };\n\n registerInteractableComponentUpdateTool(newComponent);\n\n setInteractableComponents((prev) => {\n return [...prev, newComponent];\n });\n\n return id;\n },\n [registerInteractableComponentUpdateTool],\n );\n\n const removeInteractableComponent = useCallback((id: string) => {\n setInteractableComponents((prev) => prev.filter((c) => c.id !== id));\n }, []);\n\n const getInteractableComponent = useCallback(\n (id: string) => {\n return interactableComponents.find((c) => c.id === id);\n },\n [interactableComponents],\n );\n\n const getInteractableComponentsByName = useCallback(\n (componentName: string) => {\n return interactableComponents.filter((c) => c.name === componentName);\n },\n [interactableComponents],\n );\n\n const clearAllInteractableComponents = useCallback(() => {\n setInteractableComponents([]);\n }, []);\n\n const value: TamboInteractableContext = {\n interactableComponents,\n addInteractableComponent,\n removeInteractableComponent,\n updateInteractableComponentProps,\n getInteractableComponent,\n getInteractableComponentsByName,\n clearAllInteractableComponents,\n };\n\n return (\n <TamboInteractableContext.Provider value={value}>\n {children}\n </TamboInteractableContext.Provider>\n );\n};\n\n/**\n * The useTamboInteractable hook provides access to the interactable component\n * management functions.\n * @returns The interactable component management functions\n */\nexport const useTamboInteractable = () => {\n return useContext(TamboInteractableContext);\n};\n\n/**\n * Hook to get a cloned snapshot of the current interactables.\n * Returns a shallow copy of the array with cloned items and props to prevent\n * external mutation from affecting internal state.\n * @returns The current interactables snapshot (cloned).\n */\nexport const useCurrentInteractablesSnapshot = () => {\n const { interactableComponents } = useTamboInteractable();\n // Clone the array and each item/props to prevent mutation\n const copy = interactableComponents.map((c) => ({\n ...c,\n props: { ...c.props },\n }));\n\n return copy;\n};\n"]}
@@ -20,6 +20,7 @@ import { TamboGenerationStageContextProps, TamboThreadContextProps, TamboThreadP
20
20
  * @param props.contextHelpers - Configuration for which context helpers are enabled/disabled
21
21
  * @param props.userToken - The JWT id token to use to identify the user in the Tambo API. (preferred over contextKey)
22
22
  * @param props.contextKey - Optional context key to be used in the thread input provider
23
+ * @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called
23
24
  * @returns The TamboProvider component
24
25
  */
25
26
  export declare const TamboProvider: React.FC<PropsWithChildren<TamboClientProviderProps & TamboRegistryProviderProps & TamboThreadProviderProps & TamboContextHelpersProviderProps & TamboThreadInputProviderProps>>;
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAA6B,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EACL,uBAAuB,EAEvB,wBAAwB,EAIzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,EAG3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,+BAA+B,EAE/B,gCAAgC,EAEjC,MAAM,kCAAkC,CAAC;AAK1C,OAAO,EAEL,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,6BAA6B,EAC9B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,gCAAgC,EAChC,uBAAuB,EAEvB,wBAAwB,EAEzB,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAClC,iBAAiB,CACf,wBAAwB,GACtB,0BAA0B,GAC1B,wBAAwB,GACxB,gCAAgC,GAChC,6BAA6B,CAChC,CA6CF,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,GACrD,uBAAuB,GACvB,gCAAgC,GAChC,0BAA0B,GAC1B,wBAAwB,GACxB,+BAA+B,CAAC;AAElC,eAAO,MAAM,YAAY,kCAExB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA0B9D,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,yBAEpB,CAAC"}
1
+ {"version":3,"file":"tambo-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAA6B,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EACL,uBAAuB,EAEvB,wBAAwB,EAIzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,EAG3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,+BAA+B,EAE/B,gCAAgC,EAEjC,MAAM,kCAAkC,CAAC;AAK1C,OAAO,EAEL,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,6BAA6B,EAC9B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,gCAAgC,EAChC,uBAAuB,EAEvB,wBAAwB,EAEzB,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAClC,iBAAiB,CACf,wBAAwB,GACtB,0BAA0B,GAC1B,wBAAwB,GACxB,gCAAgC,GAChC,6BAA6B,CAChC,CA6CF,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,GACrD,uBAAuB,GACvB,gCAAgC,GAChC,0BAA0B,GAC1B,wBAAwB,GACxB,+BAA+B,CAAC;AAElC,eAAO,MAAM,YAAY,kCAExB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA0B9D,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,yBAEpB,CAAC"}
@@ -57,6 +57,7 @@ const tambo_thread_provider_1 = require("./tambo-thread-provider");
57
57
  * @param props.contextHelpers - Configuration for which context helpers are enabled/disabled
58
58
  * @param props.userToken - The JWT id token to use to identify the user in the Tambo API. (preferred over contextKey)
59
59
  * @param props.contextKey - Optional context key to be used in the thread input provider
60
+ * @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called
60
61
  * @returns The TamboProvider component
61
62
  */
62
63
  const TamboProvider = ({ children, tamboUrl, apiKey, userToken, components, environment, tools, streaming, contextHelpers, contextKey, onCallUnregisteredTool, }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAA4E;AAE5E,mEAOiC;AACjC,yEAIoC;AACpC,qFAK0C;AAC1C,+EAGuC;AACvC,uEAGmC;AACnC,+EAGuC;AACvC,mEAMiC;AAEjC;;;;;;;;;;;;;;;GAeG;AACI,MAAM,aAAa,GAQtB,CAAC,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAAS,EACT,UAAU,EACV,WAAW,EACX,KAAK,EACL,SAAS,EACT,cAAc,EACd,UAAU,EACV,sBAAsB,GACvB,EAAE,EAAE;IACH,iCAAiC;IACjC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,CACL,8BAAC,2CAAmB,IAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS;QAEpB,8BAAC,+CAAqB,IACpB,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,KAAK,EACZ,sBAAsB,EAAE,sBAAsB;YAE9C,8BAAC,4DAA2B,IAAC,cAAc,EAAE,cAAc;gBACzD,8BAAC,2CAAmB,IAAC,SAAS,EAAE,SAAS;oBACvC,8BAAC,sDAAwB,IAAC,UAAU,EAAE,UAAU;wBAC9C,8BAAC,iDAAsB;4BACrB,8BAAC,uDAAyB;gCACxB,8BAAC,8BAAsB,QAAE,QAAQ,CAA0B,CACjC,CACL,CACA,CACP,CACM,CACR,CACJ,CACvB,CAAC;AACJ,CAAC,CAAC;AApDW,QAAA,aAAa,iBAoDxB;AASW,QAAA,YAAY,GAAG,IAAA,qBAAa,EACvC,EAAuB,CACxB,CAAC;AAEF;;;;;;GAMG;AACI,MAAM,sBAAsB,GAAgC,CAAC,EAClE,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,OAAO,GAAG,IAAA,sCAAc,GAAE,CAAC;IACjC,MAAM,MAAM,GAAG,IAAA,sCAAc,GAAE,CAAC;IAChC,MAAM,WAAW,GAAG,IAAA,2CAAmB,GAAE,CAAC;IAC1C,MAAM,eAAe,GAAG,IAAA,+CAAuB,GAAE,CAAC;IAClD,MAAM,iBAAiB,GAAG,IAAA,4CAAiB,GAAE,CAAC;IAC9C,MAAM,sBAAsB,GAAG,IAAA,kDAAoB,GAAE,CAAC;IACtD,MAAM,cAAc,GAAG,IAAA,uDAAsB,GAAE,CAAC;IAEhD,OAAO,CACL,8BAAC,oBAAY,CAAC,QAAQ,IACpB,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,eAAe;YACf,GAAG,iBAAiB;YACpB,GAAG,OAAO;YACV,GAAG,sBAAsB;YACzB,GAAG,cAAc;SAClB,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AA1BW,QAAA,sBAAsB,0BA0BjC;AAEF;;;;;;;GAOG;AACI,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,IAAA,kBAAU,EAAC,oBAAY,CAAC,CAAC;AAClC,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB","sourcesContent":["\"use client\";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport { TamboInteractableContext } from \"../model/tambo-interactable\";\nimport {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useIsTamboTokenUpdating,\n useTamboClient,\n useTamboQueryClient,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n TamboContextHelpersContextProps,\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n useTamboContextHelpers,\n} from \"./tambo-context-helpers-provider\";\nimport {\n TamboInteractableProvider,\n useTamboInteractable,\n} from \"./tambo-interactable-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport {\n TamboThreadInputProvider,\n TamboThreadInputProviderProps,\n} from \"./tambo-thread-input-provider\";\nimport {\n TamboGenerationStageContextProps,\n TamboThreadContextProps,\n TamboThreadProvider,\n TamboThreadProviderProps,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/**\n * The TamboProvider gives full access to the whole Tambo API. This includes the\n * TamboAI client, the component registry, the current thread context, and interactable components.\n * @param props - The props for the TamboProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.components - The components to register\n * @param props.environment - The environment to use for the Tambo API\n * @param props.tools - The tools to register\n * @param props.streaming - Whether to stream the response by default. Defaults to true.\n * @param props.contextHelpers - Configuration for which context helpers are enabled/disabled\n * @param props.userToken - The JWT id token to use to identify the user in the Tambo API. (preferred over contextKey)\n * @param props.contextKey - Optional context key to be used in the thread input provider\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps &\n TamboContextHelpersProviderProps &\n TamboThreadInputProviderProps\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n userToken,\n components,\n environment,\n tools,\n streaming,\n contextHelpers,\n contextKey,\n onCallUnregisteredTool,\n}) => {\n // Should only be used in browser\n if (typeof window === \"undefined\") {\n console.error(\"TamboProvider must be used within a browser\");\n }\n\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n userToken={userToken}\n >\n <TamboRegistryProvider\n components={components}\n tools={tools}\n onCallUnregisteredTool={onCallUnregisteredTool}\n >\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboThreadProvider streaming={streaming}>\n <TamboThreadInputProvider contextKey={contextKey}>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboThreadInputProvider>\n </TamboThreadProvider>\n </TamboContextHelpersProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\n\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboGenerationStageContextProps &\n TamboComponentContextProps &\n TamboInteractableContext &\n TamboContextHelpersContextProps;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, TamboComponent, and TamboInteractable providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nexport const TamboCompositeProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const threads = useTamboThread();\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const isUpdatingToken = useIsTamboTokenUpdating();\n const componentRegistry = useTamboComponent();\n const interactableComponents = useTamboInteractable();\n const contextHelpers = useTamboContextHelpers();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n isUpdatingToken,\n ...componentRegistry,\n ...threads,\n ...interactableComponents,\n ...contextHelpers,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\n/**\n * The useTambo hook provides access to the Tambo API. This is the primary entrypoint\n * for the Tambo React SDK.\n *\n * This includes the TamboAI client, the component registry, the current thread context,\n * and interactable component management.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
1
+ {"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAA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ChC,MAAM,WAAW,GAAG,IAAA,2CAAmB,GAAE,CAAC;IAC1C,MAAM,eAAe,GAAG,IAAA,+CAAuB,GAAE,CAAC;IAClD,MAAM,iBAAiB,GAAG,IAAA,4CAAiB,GAAE,CAAC;IAC9C,MAAM,sBAAsB,GAAG,IAAA,kDAAoB,GAAE,CAAC;IACtD,MAAM,cAAc,GAAG,IAAA,uDAAsB,GAAE,CAAC;IAEhD,OAAO,CACL,8BAAC,oBAAY,CAAC,QAAQ,IACpB,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,eAAe;YACf,GAAG,iBAAiB;YACpB,GAAG,OAAO;YACV,GAAG,sBAAsB;YACzB,GAAG,cAAc;SAClB,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AA1BW,QAAA,sBAAsB,0BA0BjC;AAEF;;;;;;;GAOG;AACI,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,IAAA,kBAAU,EAAC,oBAAY,CAAC,CAAC;AAClC,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB","sourcesContent":["\"use client\";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport { TamboInteractableContext } from \"../model/tambo-interactable\";\nimport {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useIsTamboTokenUpdating,\n useTamboClient,\n useTamboQueryClient,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n TamboContextHelpersContextProps,\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n useTamboContextHelpers,\n} from \"./tambo-context-helpers-provider\";\nimport {\n TamboInteractableProvider,\n useTamboInteractable,\n} from \"./tambo-interactable-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport {\n TamboThreadInputProvider,\n TamboThreadInputProviderProps,\n} from \"./tambo-thread-input-provider\";\nimport {\n TamboGenerationStageContextProps,\n TamboThreadContextProps,\n TamboThreadProvider,\n TamboThreadProviderProps,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/**\n * The TamboProvider gives full access to the whole Tambo API. This includes the\n * TamboAI client, the component registry, the current thread context, and interactable components.\n * @param props - The props for the TamboProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.components - The components to register\n * @param props.environment - The environment to use for the Tambo API\n * @param props.tools - The tools to register\n * @param props.streaming - Whether to stream the response by default. Defaults to true.\n * @param props.contextHelpers - Configuration for which context helpers are enabled/disabled\n * @param props.userToken - The JWT id token to use to identify the user in the Tambo API. (preferred over contextKey)\n * @param props.contextKey - Optional context key to be used in the thread input provider\n * @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps &\n TamboContextHelpersProviderProps &\n TamboThreadInputProviderProps\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n userToken,\n components,\n environment,\n tools,\n streaming,\n contextHelpers,\n contextKey,\n onCallUnregisteredTool,\n}) => {\n // Should only be used in browser\n if (typeof window === \"undefined\") {\n console.error(\"TamboProvider must be used within a browser\");\n }\n\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n userToken={userToken}\n >\n <TamboRegistryProvider\n components={components}\n tools={tools}\n onCallUnregisteredTool={onCallUnregisteredTool}\n >\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboThreadProvider streaming={streaming}>\n <TamboThreadInputProvider contextKey={contextKey}>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboThreadInputProvider>\n </TamboThreadProvider>\n </TamboContextHelpersProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\n\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboGenerationStageContextProps &\n TamboComponentContextProps &\n TamboInteractableContext &\n TamboContextHelpersContextProps;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, TamboComponent, and TamboInteractable providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nexport const TamboCompositeProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const threads = useTamboThread();\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const isUpdatingToken = useIsTamboTokenUpdating();\n const componentRegistry = useTamboComponent();\n const interactableComponents = useTamboInteractable();\n const contextHelpers = useTamboContextHelpers();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n isUpdatingToken,\n ...componentRegistry,\n ...threads,\n ...interactableComponents,\n ...contextHelpers,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\n/**\n * The useTambo hook provides access to the Tambo API. This is the primary entrypoint\n * for the Tambo React SDK.\n *\n * This includes the TamboAI client, the component registry, the current thread context,\n * and interactable component management.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
@@ -1,5 +1,6 @@
1
1
  import React, { PropsWithChildren } from "react";
2
2
  import { UseTamboMutationResult } from "../hooks/react-query-hooks";
3
+ import { StagedImage } from "../hooks/use-message-images";
3
4
  /**
4
5
  * Error messages for various input-related error scenarios
5
6
  * These messages are used to provide user-friendly error feedback
@@ -34,6 +35,16 @@ export interface TamboThreadInputContextProps extends Omit<UseTamboMutationResul
34
35
  forceToolChoice?: string;
35
36
  additionalContext?: Record<string, any>;
36
37
  }) => Promise<void>;
38
+ /** Currently staged images */
39
+ images: StagedImage[];
40
+ /** Add a single image */
41
+ addImage: (file: File) => Promise<void>;
42
+ /** Add multiple images */
43
+ addImages: (files: File[]) => Promise<void>;
44
+ /** Remove an image by id */
45
+ removeImage: (id: string) => void;
46
+ /** Clear all staged images */
47
+ clearImages: () => void;
37
48
  }
38
49
  export declare const TamboThreadInputContext: React.Context<TamboThreadInputContextProps | undefined>;
39
50
  export interface TamboThreadInputProviderProps {
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-thread-input-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-thread-input-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAIlB,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AAKpC;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;AAEX,MAAM,WAAW,4BACf,SAAQ,IAAI,CACV,sBAAsB,CACpB,IAAI,EACJ,KAAK,EACH;IACE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACzC,GACD,SAAS,EACX,OAAO,CACR,EACD,QAAQ,GAAG,aAAa,CACzB;IACD,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;;OAGG;IACH,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE;QACjB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACzC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrB;AAED,eAAO,MAAM,uBAAuB,yDAExB,CAAC;AAEb,MAAM,WAAW,6BAA6B;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,EAAE,KAAK,CAAC,EAAE,CAC7C,iBAAiB,CAAC,6BAA6B,CAAC,CAyDjD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,oCAS/B,CAAC"}
1
+ {"version":3,"file":"tambo-thread-input-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-thread-input-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAIlB,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAoB,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAM5E;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;AAEX,MAAM,WAAW,4BACf,SAAQ,IAAI,CACV,sBAAsB,CACpB,IAAI,EACJ,KAAK,EACH;IACE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACzC,GACD,SAAS,EACX,OAAO,CACR,EACD,QAAQ,GAAG,aAAa,CACzB;IACD,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;;OAGG;IACH,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE;QACjB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACzC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpB,8BAA8B;IAC9B,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,yBAAyB;IACzB,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,0BAA0B;IAC1B,SAAS,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,4BAA4B;IAC5B,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,8BAA8B;IAC9B,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB;AAED,eAAO,MAAM,uBAAuB,yDAExB,CAAC;AAEb,MAAM,WAAW,6BAA6B;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,EAAE,KAAK,CAAC,EAAE,CAC7C,iBAAiB,CAAC,6BAA6B,CAAC,CAuIjD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,oCAS/B,CAAC"}
@@ -37,8 +37,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.useTamboThreadInput = exports.TamboThreadInputProvider = exports.TamboThreadInputContext = exports.INPUT_ERROR_MESSAGES = void 0;
38
38
  const react_1 = __importStar(require("react"));
39
39
  const react_query_hooks_1 = require("../hooks/react-query-hooks");
40
+ const use_message_images_1 = require("../hooks/use-message-images");
40
41
  const thread_input_error_1 = require("../model/thread-input-error");
41
42
  const validate_input_1 = require("../model/validate-input");
43
+ const message_builder_1 = require("../util/message-builder");
42
44
  const tambo_thread_provider_1 = require("./tambo-thread-provider");
43
45
  /**
44
46
  * Error messages for various input-related error scenarios
@@ -64,20 +66,64 @@ exports.TamboThreadInputContext = (0, react_1.createContext)(undefined);
64
66
  const TamboThreadInputProvider = ({ children, contextKey }) => {
65
67
  const { thread, sendThreadMessage } = (0, tambo_thread_provider_1.useTamboThread)();
66
68
  const [inputValue, setInputValue] = (0, react_1.useState)("");
69
+ const imageState = (0, use_message_images_1.useMessageImages)();
67
70
  const submit = (0, react_1.useCallback)(async ({ contextKey: submitContextKey, streamResponse, forceToolChoice, additionalContext, } = {}) => {
68
- const validation = (0, validate_input_1.validateInput)(inputValue);
69
- if (!validation.isValid) {
70
- throw new thread_input_error_1.ThreadInputError(`Cannot submit message: ${validation.error ?? exports.INPUT_ERROR_MESSAGES.VALIDATION}`, { cause: validation.error });
71
+ // Validate text input if present
72
+ if (inputValue?.trim()) {
73
+ const validation = (0, validate_input_1.validateInput)(inputValue);
74
+ if (!validation.isValid) {
75
+ throw new thread_input_error_1.ThreadInputError(`Cannot submit message: ${validation.error ?? exports.INPUT_ERROR_MESSAGES.VALIDATION}`, { cause: validation.error });
76
+ }
71
77
  }
72
- await sendThreadMessage(validation.sanitizedInput, {
73
- threadId: thread.id,
74
- contextKey: submitContextKey ?? contextKey ?? undefined,
75
- streamResponse: streamResponse,
76
- forceToolChoice: forceToolChoice,
77
- additionalContext: additionalContext,
78
- });
79
- setInputValue(""); // Clear local state
80
- }, [inputValue, sendThreadMessage, thread.id, contextKey]);
78
+ // Check if we have content to send
79
+ if (!inputValue.trim() && imageState.images.length === 0) {
80
+ throw new thread_input_error_1.ThreadInputError(exports.INPUT_ERROR_MESSAGES.EMPTY, {
81
+ cause: "No text or images to send",
82
+ });
83
+ }
84
+ // Build message content with text and images
85
+ const messageContent = (0, message_builder_1.buildMessageContent)(inputValue, imageState.images);
86
+ try {
87
+ await sendThreadMessage(inputValue || "Image message", {
88
+ threadId: thread.id,
89
+ contextKey: submitContextKey ?? contextKey ?? undefined,
90
+ streamResponse: streamResponse,
91
+ forceToolChoice: forceToolChoice,
92
+ additionalContext: additionalContext,
93
+ content: messageContent,
94
+ });
95
+ }
96
+ catch (error) {
97
+ // Handle image-related errors with friendly messages
98
+ if (imageState.images.length > 0) {
99
+ const errorMessage = error?.message?.toLowerCase() ?? "";
100
+ // Backend not yet supporting image content type
101
+ if (errorMessage.includes("unknown content part type: image")) {
102
+ throw new thread_input_error_1.ThreadInputError("Image attachments are not yet supported by the backend. This feature is coming soon.", { cause: error });
103
+ }
104
+ // Handle specific model vision support errors
105
+ // OpenAI errors
106
+ if (errorMessage.includes("does not support image message content types") ||
107
+ (errorMessage.includes("invalid model") &&
108
+ errorMessage.includes("image_url is only supported by certain models"))) {
109
+ throw new thread_input_error_1.ThreadInputError("This model doesn't support images. Please use GPT-4o, GPT-4 Turbo, or other vision-capable models.", { cause: error });
110
+ }
111
+ // Anthropic Claude errors
112
+ if (errorMessage.includes("does not support image") ||
113
+ errorMessage.includes("vision not supported")) {
114
+ throw new thread_input_error_1.ThreadInputError("This Claude model doesn't support images. Please use Claude 3.5 Sonnet, Claude 3 Opus, or other vision-capable models.", { cause: error });
115
+ }
116
+ // Generic image/vision errors
117
+ if (errorMessage.includes("image") ||
118
+ errorMessage.includes("vision")) {
119
+ throw new thread_input_error_1.ThreadInputError("This model doesn't support image attachments. Please use a vision-capable model.", { cause: error });
120
+ }
121
+ }
122
+ throw error;
123
+ }
124
+ // Clear text after successful submission
125
+ setInputValue("");
126
+ }, [inputValue, sendThreadMessage, thread.id, contextKey, imageState]);
81
127
  const { mutateAsync: submitAsync, mutate: _unusedSubmit, ...mutationState } = (0, react_query_hooks_1.useTamboMutation)({
82
128
  mutationFn: submit,
83
129
  });
@@ -86,6 +132,11 @@ const TamboThreadInputProvider = ({ children, contextKey }) => {
86
132
  value: inputValue,
87
133
  setValue: setInputValue,
88
134
  submit: submitAsync,
135
+ images: imageState.images,
136
+ addImage: imageState.addImage,
137
+ addImages: imageState.addImages,
138
+ removeImage: imageState.removeImage,
139
+ clearImages: imageState.clearImages,
89
140
  };
90
141
  return (react_1.default.createElement(exports.TamboThreadInputContext.Provider, { value: value }, children));
91
142
  };
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-thread-input-provider.js","sourceRoot":"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EAAE,cAAc;YAC9B,eAAe,EAAE,eAAe;YAChC,iBAAiB,EAAE,iBAAiB;SACrC,CAAC,CAAC;QACH,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,oBAAoB;IACzC,CAAC,EACD,CAAC,UAAU,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,CACvD,CAAC;IAEF,MAAM,EACJ,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,aAAa,EACrB,GAAG,aAAa,EACjB,GAAG,IAAA,oCAAgB,EAAC;QACnB,UAAU,EAAE,MAAM;KACnB,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG;QACZ,GAAG,aAAa;QAChB,KAAK,EAAE,UAAU;QACjB,QAAQ,EAAE,aAAa;QACvB,MAAM,EAAE,WAAW;KACpB,CAAC;IAEF,OAAO,CACL,8BAAC,+BAAuB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAC3C,QAAQ,CACwB,CACpC,CAAC;AACJ,CAAC,CAAC;AA1DW,QAAA,wBAAwB,4BA0DnC;AAEF;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,GAAG,EAAE;IACtC,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,+BAAuB,CAAC,CAAC;IACpD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AATW,QAAA,mBAAmB,uBAS9B","sourcesContent":["\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useState,\n} from \"react\";\nimport {\n useTamboMutation,\n UseTamboMutationResult,\n} from \"../hooks/react-query-hooks\";\nimport { ThreadInputError } from \"../model/thread-input-error\";\nimport { validateInput } from \"../model/validate-input\";\nimport { useTamboThread } from \"./tambo-thread-provider\";\n\n/**\n * Error messages for various input-related error scenarios\n * These messages are used to provide user-friendly error feedback\n * @readonly\n */\nexport const INPUT_ERROR_MESSAGES = {\n EMPTY: \"Message cannot be empty\",\n NETWORK: \"Network error. Please check your connection\",\n SERVER: \"Server error. Please try again\",\n VALIDATION: \"Invalid message format\",\n} as const;\n\nexport interface TamboThreadInputContextProps\n extends Omit<\n UseTamboMutationResult<\n void,\n Error,\n | {\n contextKey?: string;\n streamResponse?: boolean;\n forceToolChoice?: string;\n additionalContext?: Record<string, any>;\n }\n | undefined,\n unknown\n >,\n \"mutate\" | \"mutateAsync\"\n > {\n /** Current value of the input field */\n value: string;\n /**\n * Function to update the input value\n * @param value - New value for the input field\n */\n setValue: (value: string) => void;\n /**\n * Function to submit the current input value\n * @param options - Submission options\n */\n submit: (options?: {\n contextKey?: string;\n streamResponse?: boolean;\n forceToolChoice?: string;\n additionalContext?: Record<string, any>;\n }) => Promise<void>;\n}\n\nexport const TamboThreadInputContext = createContext<\n TamboThreadInputContextProps | undefined\n>(undefined);\n\nexport interface TamboThreadInputProviderProps {\n contextKey?: string;\n}\n\n/**\n * Provider that manages shared thread input state across all components\n * This ensures that useTamboThreadInput, useTamboSuggestions, and components\n * all share the same input state\n * @param props - The props for the TamboThreadInputProvider\n * @param props.contextKey - Optional context key.\n * @param props.children - The children to render.\n * @returns The thread input context\n */\nexport const TamboThreadInputProvider: React.FC<\n PropsWithChildren<TamboThreadInputProviderProps>\n> = ({ children, contextKey }) => {\n const { thread, sendThreadMessage } = useTamboThread();\n const [inputValue, setInputValue] = useState(\"\");\n\n const submit = useCallback(\n async ({\n contextKey: submitContextKey,\n streamResponse,\n forceToolChoice,\n additionalContext,\n }: {\n contextKey?: string;\n streamResponse?: boolean;\n forceToolChoice?: string;\n additionalContext?: Record<string, any>;\n } = {}) => {\n const validation = validateInput(inputValue);\n if (!validation.isValid) {\n throw new ThreadInputError(\n `Cannot submit message: ${validation.error ?? INPUT_ERROR_MESSAGES.VALIDATION}`,\n { cause: validation.error },\n );\n }\n\n await sendThreadMessage(validation.sanitizedInput, {\n threadId: thread.id,\n contextKey: submitContextKey ?? contextKey ?? undefined,\n streamResponse: streamResponse,\n forceToolChoice: forceToolChoice,\n additionalContext: additionalContext,\n });\n setInputValue(\"\"); // Clear local state\n },\n [inputValue, sendThreadMessage, thread.id, contextKey],\n );\n\n const {\n mutateAsync: submitAsync,\n mutate: _unusedSubmit,\n ...mutationState\n } = useTamboMutation({\n mutationFn: submit,\n });\n\n const value = {\n ...mutationState,\n value: inputValue,\n setValue: setInputValue,\n submit: submitAsync,\n };\n\n return (\n <TamboThreadInputContext.Provider value={value}>\n {children}\n </TamboThreadInputContext.Provider>\n );\n};\n\n/**\n * Hook to access the shared thread input state\n * contextKey parameter is not passed here anymore. Instead, use the contextKey prop in the TamboProvider.\n * @returns The thread input context\n */\nexport const useTamboThreadInput = () => {\n const context = useContext(TamboThreadInputContext);\n if (!context) {\n throw new Error(\n \"useTamboThreadInput must be used within a TamboThreadInputProvider\",\n );\n }\n\n return context;\n};\n"]}
1
+ {"version":3,"file":"tambo-thread-input-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-thread-input-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAMe;AACf,kEAGoC;AACpC,oEAA4E;AAC5E,oEAA+D;AAC/D,4DAAwD;AACxD,6DAA8D;AAC9D,mEAAyD;AAEzD;;;;GAIG;AACU,QAAA,oBAAoB,GAAG;IAClC,KAAK,EAAE,yBAAyB;IAChC,OAAO,EAAE,6CAA6C;IACtD,MAAM,EAAE,gCAAgC;IACxC,UAAU,EAAE,wBAAwB;CAC5B,CAAC;AA+CE,QAAA,uBAAuB,GAAG,IAAA,qBAAa,EAElD,SAAS,CAAC,CAAC;AAMb;;;;;;;;GAQG;AACI,MAAM,wBAAwB,GAEjC,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE;IAC/B,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAA,sCAAc,GAA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,aAAa,CAAC,EAAE,CAAC,CAAC;IACpB,CAAC,EACD,CAAC,UAAU,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,EAAE,UAAU,EAAE,UAAU,CAAC,CACnE,CAAC;IAEF,MAAM,EACJ,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,aAAa,EACrB,GAAG,aAAa,EACjB,GAAG,IAAA,oCAAgB,EAAC;QACnB,UAAU,EAAE,MAAM;KACnB,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG;QACZ,GAAG,aAAa;QAChB,KAAK,EAAE,UAAU;QACjB,QAAQ,EAAE,aAAa;QACvB,MAAM,EAAE,WAAW;QACnB,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,SAAS,EAAE,UAAU,CAAC,SAAS;QAC/B,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,WAAW,EAAE,UAAU,CAAC,WAAW;KACpC,CAAC;IAEF,OAAO,CACL,8BAAC,+BAAuB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAC3C,QAAQ,CACwB,CACpC,CAAC;AACJ,CAAC,CAAC;AAxIW,QAAA,wBAAwB,4BAwInC;AAEF;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,GAAG,EAAE;IACtC,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,+BAAuB,CAAC,CAAC;IACpD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AATW,QAAA,mBAAmB,uBAS9B","sourcesContent":["\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useState,\n} from \"react\";\nimport {\n useTamboMutation,\n UseTamboMutationResult,\n} from \"../hooks/react-query-hooks\";\nimport { useMessageImages, StagedImage } from \"../hooks/use-message-images\";\nimport { ThreadInputError } from \"../model/thread-input-error\";\nimport { validateInput } from \"../model/validate-input\";\nimport { buildMessageContent } from \"../util/message-builder\";\nimport { useTamboThread } from \"./tambo-thread-provider\";\n\n/**\n * Error messages for various input-related error scenarios\n * These messages are used to provide user-friendly error feedback\n * @readonly\n */\nexport const INPUT_ERROR_MESSAGES = {\n EMPTY: \"Message cannot be empty\",\n NETWORK: \"Network error. Please check your connection\",\n SERVER: \"Server error. Please try again\",\n VALIDATION: \"Invalid message format\",\n} as const;\n\nexport interface TamboThreadInputContextProps\n extends Omit<\n UseTamboMutationResult<\n void,\n Error,\n | {\n contextKey?: string;\n streamResponse?: boolean;\n forceToolChoice?: string;\n additionalContext?: Record<string, any>;\n }\n | undefined,\n unknown\n >,\n \"mutate\" | \"mutateAsync\"\n > {\n /** Current value of the input field */\n value: string;\n /**\n * Function to update the input value\n * @param value - New value for the input field\n */\n setValue: (value: string) => void;\n /**\n * Function to submit the current input value\n * @param options - Submission options\n */\n submit: (options?: {\n contextKey?: string;\n streamResponse?: boolean;\n forceToolChoice?: string;\n additionalContext?: Record<string, any>;\n }) => Promise<void>;\n /** Currently staged images */\n images: StagedImage[];\n /** Add a single image */\n addImage: (file: File) => Promise<void>;\n /** Add multiple images */\n addImages: (files: File[]) => Promise<void>;\n /** Remove an image by id */\n removeImage: (id: string) => void;\n /** Clear all staged images */\n clearImages: () => void;\n}\n\nexport const TamboThreadInputContext = createContext<\n TamboThreadInputContextProps | undefined\n>(undefined);\n\nexport interface TamboThreadInputProviderProps {\n contextKey?: string;\n}\n\n/**\n * Provider that manages shared thread input state across all components\n * This ensures that useTamboThreadInput, useTamboSuggestions, and components\n * all share the same input state\n * @param props - The props for the TamboThreadInputProvider\n * @param props.contextKey - Optional context key.\n * @param props.children - The children to render.\n * @returns The thread input context\n */\nexport const TamboThreadInputProvider: React.FC<\n PropsWithChildren<TamboThreadInputProviderProps>\n> = ({ children, contextKey }) => {\n const { thread, sendThreadMessage } = useTamboThread();\n const [inputValue, setInputValue] = useState(\"\");\n const imageState = useMessageImages();\n\n const submit = useCallback(\n async ({\n contextKey: submitContextKey,\n streamResponse,\n forceToolChoice,\n additionalContext,\n }: {\n contextKey?: string;\n streamResponse?: boolean;\n forceToolChoice?: string;\n additionalContext?: Record<string, any>;\n } = {}) => {\n // Validate text input if present\n if (inputValue?.trim()) {\n const validation = validateInput(inputValue);\n if (!validation.isValid) {\n throw new ThreadInputError(\n `Cannot submit message: ${validation.error ?? INPUT_ERROR_MESSAGES.VALIDATION}`,\n { cause: validation.error },\n );\n }\n }\n\n // Check if we have content to send\n if (!inputValue.trim() && imageState.images.length === 0) {\n throw new ThreadInputError(INPUT_ERROR_MESSAGES.EMPTY, {\n cause: \"No text or images to send\",\n });\n }\n\n // Build message content with text and images\n const messageContent = buildMessageContent(inputValue, imageState.images);\n\n try {\n await sendThreadMessage(inputValue || \"Image message\", {\n threadId: thread.id,\n contextKey: submitContextKey ?? contextKey ?? undefined,\n streamResponse: streamResponse,\n forceToolChoice: forceToolChoice,\n additionalContext: additionalContext,\n content: messageContent,\n });\n } catch (error: any) {\n // Handle image-related errors with friendly messages\n if (imageState.images.length > 0) {\n const errorMessage = error?.message?.toLowerCase() ?? \"\";\n\n // Backend not yet supporting image content type\n if (errorMessage.includes(\"unknown content part type: image\")) {\n throw new ThreadInputError(\n \"Image attachments are not yet supported by the backend. This feature is coming soon.\",\n { cause: error },\n );\n }\n\n // Handle specific model vision support errors\n // OpenAI errors\n if (\n errorMessage.includes(\n \"does not support image message content types\",\n ) ||\n (errorMessage.includes(\"invalid model\") &&\n errorMessage.includes(\n \"image_url is only supported by certain models\",\n ))\n ) {\n throw new ThreadInputError(\n \"This model doesn't support images. Please use GPT-4o, GPT-4 Turbo, or other vision-capable models.\",\n { cause: error },\n );\n }\n\n // Anthropic Claude errors\n if (\n errorMessage.includes(\"does not support image\") ||\n errorMessage.includes(\"vision not supported\")\n ) {\n throw new ThreadInputError(\n \"This Claude model doesn't support images. Please use Claude 3.5 Sonnet, Claude 3 Opus, or other vision-capable models.\",\n { cause: error },\n );\n }\n\n // Generic image/vision errors\n if (\n errorMessage.includes(\"image\") ||\n errorMessage.includes(\"vision\")\n ) {\n throw new ThreadInputError(\n \"This model doesn't support image attachments. Please use a vision-capable model.\",\n { cause: error },\n );\n }\n }\n\n throw error;\n }\n\n // Clear text after successful submission\n setInputValue(\"\");\n },\n [inputValue, sendThreadMessage, thread.id, contextKey, imageState],\n );\n\n const {\n mutateAsync: submitAsync,\n mutate: _unusedSubmit,\n ...mutationState\n } = useTamboMutation({\n mutationFn: submit,\n });\n\n const value = {\n ...mutationState,\n value: inputValue,\n setValue: setInputValue,\n submit: submitAsync,\n images: imageState.images,\n addImage: imageState.addImage,\n addImages: imageState.addImages,\n removeImage: imageState.removeImage,\n clearImages: imageState.clearImages,\n };\n\n return (\n <TamboThreadInputContext.Provider value={value}>\n {children}\n </TamboThreadInputContext.Provider>\n );\n};\n\n/**\n * Hook to access the shared thread input state\n * contextKey parameter is not passed here anymore. Instead, use the contextKey prop in the TamboProvider.\n * @returns The thread input context\n */\nexport const useTamboThreadInput = () => {\n const context = useContext(TamboThreadInputContext);\n if (!context) {\n throw new Error(\n \"useTamboThreadInput must be used within a TamboThreadInputProvider\",\n );\n }\n\n return context;\n};\n"]}
@@ -51,6 +51,7 @@ export interface TamboThreadContextProps {
51
51
  contextKey?: string;
52
52
  forceToolChoice?: string;
53
53
  additionalContext?: Record<string, any>;
54
+ content?: TamboAI.Beta.Threads.ChatCompletionContentPart[];
54
55
  }) => Promise<TamboThreadMessage>;
55
56
  }
56
57
  export interface CombinedTamboThreadContextProps extends TamboThreadContextProps, TamboGenerationStageContextProps {
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-thread-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-thread-provider.tsx"],"names":[],"mappings":"AACA,OAAO,OAA0B,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,yDAAyD,CAAC;AACjF,OAAO,KAAK,EA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+BAgBjC,CAAC"}
@@ -532,7 +532,7 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
532
532
  ]);
533
533
  const sendThreadMessage = (0, react_1.useCallback)(async (message, options = {}) => {
534
534
  setIgnoreResponse(false);
535
- const { threadId = currentThreadId ?? exports.PLACEHOLDER_THREAD.id, streamResponse = streaming, forceToolChoice, contextKey, additionalContext, } = options;
535
+ const { threadId = currentThreadId ?? exports.PLACEHOLDER_THREAD.id, streamResponse = streaming, forceToolChoice, contextKey, additionalContext, content, } = options;
536
536
  updateThreadStatus(threadId, generate_component_response_1.GenerationStage.FETCHING_CONTEXT);
537
537
  // Get additional context from enabled helpers
538
538
  const helperContexts = await getAdditionalContext();
@@ -544,8 +544,12 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
544
544
  for (const helperContext of helperContexts) {
545
545
  combinedContext[helperContext.name] = helperContext.context;
546
546
  }
547
+ // Use provided content or build simple text message
548
+ const messageContent = content ?? [
549
+ { type: "text", text: message },
550
+ ];
547
551
  addThreadMessage({
548
- content: [{ type: "text", text: message }],
552
+ content: messageContent,
549
553
  renderedComponent: null,
550
554
  role: "user",
551
555
  threadId: threadId,
@@ -560,7 +564,7 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
560
564
  const toolCallCounts = {};
561
565
  const params = {
562
566
  messageToAppend: {
563
- content: [{ type: "text", text: message }],
567
+ content: messageContent,
564
568
  role: "user",
565
569
  additionalContext: combinedContext,
566
570
  },
@@ -591,7 +595,7 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
591
595
  try {
592
596
  advanceResponse = await (threadId === exports.PLACEHOLDER_THREAD.id
593
597
  ? client.beta.threads.advance(params)
594
- : client.beta.threads.advanceById(threadId, params));
598
+ : client.beta.threads.advanceByID(threadId, params));
595
599
  }
596
600
  catch (error) {
597
601
  updateThreadStatus(threadId, generate_component_response_1.GenerationStage.ERROR);
@@ -642,7 +646,7 @@ const TamboThreadProvider = ({ children, streaming = true }) => {
642
646
  tool_call_id: advanceResponse.responseMessageDto.tool_call_id,
643
647
  error: toolCallResponse.error,
644
648
  }, false);
645
- advanceResponse = await client.beta.threads.advanceById(advanceResponse.responseMessageDto.threadId, toolCallResponseParams);
649
+ advanceResponse = await client.beta.threads.advanceByID(advanceResponse.responseMessageDto.threadId, toolCallResponseParams);
646
650
  }
647
651
  }
648
652
  catch (error) {