@tambo-ai/react 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hoc/with-tambo-interactable.d.ts.map +1 -1
- package/dist/hoc/with-tambo-interactable.js +11 -2
- package/dist/hoc/with-tambo-interactable.js.map +1 -1
- package/dist/hoc/with-tambo-interactable.test.js +14 -0
- package/dist/hoc/with-tambo-interactable.test.js.map +1 -1
- package/dist/providers/tambo-interactable-provider-partial-updates.test.js +2 -0
- package/dist/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.d.ts +3 -2
- package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/dist/providers/tambo-interactable-provider.js +49 -13
- package/dist/providers/tambo-interactable-provider.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.test.js +165 -1
- package/dist/providers/tambo-interactable-provider.test.js.map +1 -1
- package/dist/providers/tambo-registry-provider.d.ts +1 -0
- package/dist/providers/tambo-registry-provider.d.ts.map +1 -1
- package/dist/providers/tambo-registry-provider.js +19 -0
- package/dist/providers/tambo-registry-provider.js.map +1 -1
- package/dist/providers/tambo-registry-provider.test.js +47 -0
- package/dist/providers/tambo-registry-provider.test.js.map +1 -1
- package/dist/v1/__tests__/v1-interactables.test.js +5 -0
- package/dist/v1/__tests__/v1-interactables.test.js.map +1 -1
- package/dist/v1/components/v1-component-renderer.test.js +1 -0
- package/dist/v1/components/v1-component-renderer.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1.test.js +1 -0
- package/dist/v1/hooks/use-tambo-v1.test.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-stub-provider.js +1 -0
- package/dist/v1/providers/tambo-v1-stub-provider.js.map +1 -1
- package/esm/hoc/with-tambo-interactable.d.ts.map +1 -1
- package/esm/hoc/with-tambo-interactable.js +11 -2
- package/esm/hoc/with-tambo-interactable.js.map +1 -1
- package/esm/hoc/with-tambo-interactable.test.js +14 -0
- package/esm/hoc/with-tambo-interactable.test.js.map +1 -1
- package/esm/providers/tambo-interactable-provider-partial-updates.test.js +2 -0
- package/esm/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.d.ts +3 -2
- package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/esm/providers/tambo-interactable-provider.js +49 -13
- package/esm/providers/tambo-interactable-provider.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.test.js +165 -1
- package/esm/providers/tambo-interactable-provider.test.js.map +1 -1
- package/esm/providers/tambo-registry-provider.d.ts +1 -0
- package/esm/providers/tambo-registry-provider.d.ts.map +1 -1
- package/esm/providers/tambo-registry-provider.js +19 -0
- package/esm/providers/tambo-registry-provider.js.map +1 -1
- package/esm/providers/tambo-registry-provider.test.js +47 -0
- package/esm/providers/tambo-registry-provider.test.js.map +1 -1
- package/esm/v1/__tests__/v1-interactables.test.js +5 -0
- package/esm/v1/__tests__/v1-interactables.test.js.map +1 -1
- package/esm/v1/components/v1-component-renderer.test.js +1 -0
- package/esm/v1/components/v1-component-renderer.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1.test.js +1 -0
- package/esm/v1/hooks/use-tambo-v1.test.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-stub-provider.js +1 -0
- package/esm/v1/providers/tambo-v1-stub-provider.js.map +1 -1
- package/package.json +7 -7
|
@@ -57,6 +57,8 @@ const TamboInteractableContext = (0, react_1.createContext)({
|
|
|
57
57
|
setInteractableSelected: () => { },
|
|
58
58
|
clearInteractableSelections: () => { },
|
|
59
59
|
});
|
|
60
|
+
/** Synthetic owner ID used to track global interactable tools in the registry. */
|
|
61
|
+
const GLOBAL_INTERACTABLE_OWNER = "__interactable_global__";
|
|
60
62
|
/**
|
|
61
63
|
* The TamboInteractableProvider manages a list of components that are currently
|
|
62
64
|
* interactable, allowing tambo to interact with them by updating their props. It also registers tools
|
|
@@ -67,8 +69,29 @@ const TamboInteractableContext = (0, react_1.createContext)({
|
|
|
67
69
|
*/
|
|
68
70
|
const TamboInteractableProvider = ({ children, }) => {
|
|
69
71
|
const [interactableComponents, setInteractableComponents] = (0, react_1.useState)([]);
|
|
70
|
-
const
|
|
72
|
+
const [, setToolComponentOwnership] = (0, react_1.useState)({});
|
|
73
|
+
const { registerTool, unregisterTools } = (0, tambo_registry_provider_1.useTamboRegistry)();
|
|
71
74
|
const { addContextHelper, removeContextHelper } = (0, tambo_context_helpers_provider_1.useTamboContextHelpers)();
|
|
75
|
+
const registerToolForComponent = (0, react_1.useCallback)((componentId, tool) => {
|
|
76
|
+
registerTool(tool);
|
|
77
|
+
setToolComponentOwnership((prev) => {
|
|
78
|
+
const existing = prev[componentId] ?? [];
|
|
79
|
+
if (existing.includes(tool.name))
|
|
80
|
+
return prev;
|
|
81
|
+
return { ...prev, [componentId]: [...existing, tool.name] };
|
|
82
|
+
});
|
|
83
|
+
}, [registerTool]);
|
|
84
|
+
const unregisterToolsForComponent = (0, react_1.useCallback)((componentId) => {
|
|
85
|
+
setToolComponentOwnership((prev) => {
|
|
86
|
+
const toolNames = prev[componentId];
|
|
87
|
+
if (!toolNames || toolNames.length === 0)
|
|
88
|
+
return prev;
|
|
89
|
+
unregisterTools(toolNames);
|
|
90
|
+
const next = { ...prev };
|
|
91
|
+
delete next[componentId];
|
|
92
|
+
return next;
|
|
93
|
+
});
|
|
94
|
+
}, [unregisterTools]);
|
|
72
95
|
// Create a stable context helper function for interactable components
|
|
73
96
|
const interactablesContextHelper = (0, react_1.useMemo)(() => (0, current_interactables_context_helper_1.createInteractablesContextHelper)(interactableComponents), [interactableComponents]);
|
|
74
97
|
// Register the interactables context helper
|
|
@@ -80,7 +103,7 @@ const TamboInteractableProvider = ({ children, }) => {
|
|
|
80
103
|
}, [interactablesContextHelper, addContextHelper, removeContextHelper]);
|
|
81
104
|
(0, react_1.useEffect)(() => {
|
|
82
105
|
if (interactableComponents.length > 0) {
|
|
83
|
-
|
|
106
|
+
registerToolForComponent(GLOBAL_INTERACTABLE_OWNER, {
|
|
84
107
|
name: "get_all_interactable_components",
|
|
85
108
|
description: "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.",
|
|
86
109
|
tool: () => {
|
|
@@ -98,7 +121,7 @@ const TamboInteractableProvider = ({ children, }) => {
|
|
|
98
121
|
})),
|
|
99
122
|
}),
|
|
100
123
|
});
|
|
101
|
-
|
|
124
|
+
registerToolForComponent(GLOBAL_INTERACTABLE_OWNER, {
|
|
102
125
|
name: "get_interactable_component_by_id",
|
|
103
126
|
description: "Get a specific interactable component by its ID",
|
|
104
127
|
tool: ({ componentId }) => {
|
|
@@ -138,7 +161,7 @@ const TamboInteractableProvider = ({ children, }) => {
|
|
|
138
161
|
}),
|
|
139
162
|
]),
|
|
140
163
|
});
|
|
141
|
-
|
|
164
|
+
registerToolForComponent(GLOBAL_INTERACTABLE_OWNER, {
|
|
142
165
|
name: "remove_interactable_component",
|
|
143
166
|
description: "Remove an interactable component from the system",
|
|
144
167
|
tool: ({ componentId }) => {
|
|
@@ -149,6 +172,7 @@ const TamboInteractableProvider = ({ children, }) => {
|
|
|
149
172
|
error: `Component with ID ${componentId} not found`,
|
|
150
173
|
};
|
|
151
174
|
}
|
|
175
|
+
unregisterToolsForComponent(componentId);
|
|
152
176
|
setInteractableComponents((prev) => prev.filter((c) => c.id !== componentId));
|
|
153
177
|
return {
|
|
154
178
|
success: true,
|
|
@@ -180,7 +204,15 @@ const TamboInteractableProvider = ({ children, }) => {
|
|
|
180
204
|
]),
|
|
181
205
|
});
|
|
182
206
|
}
|
|
183
|
-
|
|
207
|
+
else {
|
|
208
|
+
// No interactable components — remove the global tools
|
|
209
|
+
unregisterToolsForComponent(GLOBAL_INTERACTABLE_OWNER);
|
|
210
|
+
}
|
|
211
|
+
}, [
|
|
212
|
+
interactableComponents,
|
|
213
|
+
registerToolForComponent,
|
|
214
|
+
unregisterToolsForComponent,
|
|
215
|
+
]);
|
|
184
216
|
const updateInteractableComponentProps = (0, react_1.useCallback)((id, newProps) => {
|
|
185
217
|
if (!newProps || Object.keys(newProps).length === 0) {
|
|
186
218
|
return `Warning: No props provided for component with ID ${id}.`;
|
|
@@ -262,10 +294,10 @@ const TamboInteractableProvider = ({ children, }) => {
|
|
|
262
294
|
},
|
|
263
295
|
required: ["componentId", "newProps"],
|
|
264
296
|
};
|
|
265
|
-
|
|
297
|
+
registerToolForComponent(component.id, {
|
|
266
298
|
name: `${tamboToolNamePart}${component.id}`,
|
|
267
299
|
description: `Update the props of interactable component ${component.id} (${component.name}). Provide partial props (only props to change).`,
|
|
268
|
-
tool: ({ componentId, newProps }) => {
|
|
300
|
+
tool: ({ componentId, newProps, }) => {
|
|
269
301
|
return updateInteractableComponentProps(componentId, newProps);
|
|
270
302
|
},
|
|
271
303
|
inputSchema,
|
|
@@ -275,7 +307,7 @@ const TamboInteractableProvider = ({ children, }) => {
|
|
|
275
307
|
...component.annotations,
|
|
276
308
|
},
|
|
277
309
|
});
|
|
278
|
-
}, [
|
|
310
|
+
}, [registerToolForComponent, updateInteractableComponentProps]);
|
|
279
311
|
const registerInteractableComponentStateUpdateTool = (0, react_1.useCallback)((component, maxNameLength = 60) => {
|
|
280
312
|
const tamboToolNamePart = `update_component_state_`;
|
|
281
313
|
const availableLength = maxNameLength - tamboToolNamePart.length;
|
|
@@ -307,10 +339,10 @@ const TamboInteractableProvider = ({ children, }) => {
|
|
|
307
339
|
},
|
|
308
340
|
required: ["componentId", "newState"],
|
|
309
341
|
};
|
|
310
|
-
|
|
342
|
+
registerToolForComponent(component.id, {
|
|
311
343
|
name: `${tamboToolNamePart}${component.id}`,
|
|
312
344
|
description: `Update the state of interactable component ${component.id} (${component.name}). You may provide partial state (only keys to change).`,
|
|
313
|
-
tool: ({ componentId, newState }) => {
|
|
345
|
+
tool: ({ componentId, newState, }) => {
|
|
314
346
|
return updateInteractableComponentState(componentId, newState);
|
|
315
347
|
},
|
|
316
348
|
inputSchema,
|
|
@@ -320,7 +352,7 @@ const TamboInteractableProvider = ({ children, }) => {
|
|
|
320
352
|
...component.annotations,
|
|
321
353
|
},
|
|
322
354
|
});
|
|
323
|
-
}, [
|
|
355
|
+
}, [registerToolForComponent, updateInteractableComponentState]);
|
|
324
356
|
const addInteractableComponent = (0, react_1.useCallback)((component) => {
|
|
325
357
|
// Validate component name
|
|
326
358
|
(0, validate_component_name_1.assertValidName)(component.name, "component");
|
|
@@ -343,8 +375,9 @@ const TamboInteractableProvider = ({ children, }) => {
|
|
|
343
375
|
registerInteractableComponentStateUpdateTool,
|
|
344
376
|
]);
|
|
345
377
|
const removeInteractableComponent = (0, react_1.useCallback)((id) => {
|
|
378
|
+
unregisterToolsForComponent(id);
|
|
346
379
|
setInteractableComponents((prev) => prev.filter((c) => c.id !== id));
|
|
347
|
-
}, []);
|
|
380
|
+
}, [unregisterToolsForComponent]);
|
|
348
381
|
const getInteractableComponent = (0, react_1.useCallback)((id) => {
|
|
349
382
|
return interactableComponents.find((c) => c.id === id);
|
|
350
383
|
}, [interactableComponents]);
|
|
@@ -352,8 +385,11 @@ const TamboInteractableProvider = ({ children, }) => {
|
|
|
352
385
|
return interactableComponents.filter((c) => c.name === componentName);
|
|
353
386
|
}, [interactableComponents]);
|
|
354
387
|
const clearAllInteractableComponents = (0, react_1.useCallback)(() => {
|
|
388
|
+
for (const component of interactableComponents) {
|
|
389
|
+
unregisterToolsForComponent(component.id);
|
|
390
|
+
}
|
|
355
391
|
setInteractableComponents([]);
|
|
356
|
-
}, []);
|
|
392
|
+
}, [interactableComponents, unregisterToolsForComponent]);
|
|
357
393
|
const setInteractableStateValue = (0, react_1.useCallback)((componentId, key, value) => {
|
|
358
394
|
setInteractableComponents((prev) => {
|
|
359
395
|
const component = prev.find((c) => c.id === componentId);
|
|
@@ -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,6CAAwC;AAExC,+CAQe;AACf,+BAA2B;AAC3B,kHAA2G;AAK3G,sCAAsE;AACtE,6EAAkE;AAClE,uEAA6D;AAC7D,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;IACxC,oBAAoB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC9B,6BAA6B,EAAE,GAAG,EAAE,CAAC,SAAS;IAC9C,uBAAuB,EAAE,GAAG,EAAE,GAAE,CAAC;IACjC,2BAA2B,EAAE,GAAG,EAAE,GAAE,CAAC;CACtC,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,0CAAgB,GAAE,CAAC;IAC5C,MAAM,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,GAAG,IAAA,uDAAsB,GAAE,CAAC;IAE3E,sEAAsE;IACtE,MAAM,0BAA0B,GAAG,IAAA,eAAO,EACxC,GAAG,EAAE,CAAC,IAAA,uEAAgC,EAAC,sBA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A,yBAAyB,6BA8cpC;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;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 { deepEqual } from \"fast-equals\";\nimport { JSONSchema7 } from \"json-schema\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { z } from \"zod/v3\";\nimport { createInteractablesContextHelper } from \"../context-helpers/current-interactables-context-helper\";\nimport {\n TamboInteractableComponent,\n type TamboInteractableContext,\n} from \"../model/tambo-interactable\";\nimport { makeJsonSchemaPartial, schemaToJsonSchema } from \"../schema\";\nimport { assertValidName } from \"../util/validate-component-name\";\nimport { useTamboRegistry } from \"./tambo-registry-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 setInteractableState: () => {},\n getInteractableComponentState: () => undefined,\n setInteractableSelected: () => {},\n clearInteractableSelections: () => {},\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 } = useTamboRegistry();\n const { addContextHelper, removeContextHelper } = useTamboContextHelpers();\n\n // Create a stable context helper function for interactable components\n const interactablesContextHelper = useMemo(\n () => createInteractablesContextHelper(interactableComponents),\n [interactableComponents],\n );\n\n // Register the interactables context helper\n useEffect(() => {\n addContextHelper(\"interactables\", interactablesContextHelper);\n\n return () => {\n removeContextHelper(\"interactables\");\n };\n }, [interactablesContextHelper, 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 inputSchema: z.object({}),\n outputSchema: z.object({\n components: z.array(\n z.object({\n id: z.string(),\n name: z.string(),\n props: z.record(z.string(), z.any()),\n propsSchema: z.record(z.string(), z.any()).optional(),\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 }) => {\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 } as const;\n }\n\n return {\n success: true,\n component: {\n id: component.id,\n componentName: component.name,\n props: component.props,\n },\n } as const;\n },\n inputSchema: z.object({\n componentId: z.string().describe(\"The ID of the component\"),\n }),\n outputSchema: z.discriminatedUnion(\"success\", [\n z.object({\n success: z.literal(true),\n component: z\n .object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.string(), z.any()),\n })\n .optional(),\n }),\n z.object({\n success: z.literal(false),\n error: z.string(),\n }),\n ]),\n });\n\n registerTool({\n name: \"remove_interactable_component\",\n description: \"Remove an interactable component from the system\",\n tool: ({ componentId }) => {\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 } as const;\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 } as const;\n },\n inputSchema: z.object({\n componentId: z.string().describe(\"The ID of the component\"),\n }),\n outputSchema: z.discriminatedUnion(\"success\", [\n z.object({\n success: z.literal(true),\n componentId: z.string(),\n removedComponent: z.object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.string(), z.any()),\n }),\n }),\n z.object({\n success: z.literal(false),\n error: z.string(),\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 updateInteractableComponentState = useCallback(\n (componentId: string, newState: Record<string, unknown>): string => {\n if (!newState || Object.keys(newState).length === 0) {\n return `Warning: No state values provided for component with ID ${componentId}.`;\n }\n\n setInteractableComponents((components = []) => {\n const component = components.find((c) => c.id === componentId);\n if (!component) return components;\n\n const prevState = component.state ?? {};\n const updatedState = { ...prevState, ...newState };\n if (deepEqual(prevState, updatedState)) return components;\n\n // TODO(lachieh): validate state against schema?\n\n const updated = {\n ...component,\n state: updatedState,\n };\n\n return components.map((c) => (c.id === componentId ? updated : c));\n });\n\n return \"Updated successfully\";\n },\n [],\n );\n\n const registerInteractableComponentPropsUpdateTool = useCallback(\n (component: TamboInteractableComponent, maxNameLength = 60) => {\n const tamboToolNamePart = `update_component_props_`;\n const availableLength = maxNameLength - tamboToolNamePart.length;\n if (component.id.length > availableLength) {\n throw new Error(\n `Interactable component id ${component.id} is too long. It must be less than ${availableLength} characters.`,\n );\n }\n\n // Build newProps schema as JSON Schema\n let newPropsSchema: JSONSchema7;\n if (component.propsSchema) {\n // Convert any supported schema to JSON Schema, then make partial\n const fullSchema = schemaToJsonSchema(component.propsSchema);\n newPropsSchema = makeJsonSchemaPartial(fullSchema);\n } else {\n // No schema - allow any properties\n newPropsSchema = { type: \"object\", additionalProperties: true };\n }\n\n // Build the full input schema as JSON Schema\n const inputSchema: JSONSchema7 = {\n type: \"object\",\n properties: {\n componentId: {\n type: \"string\",\n description: \"The ID of the interactable component to update\",\n },\n newProps: {\n ...newPropsSchema,\n description:\n \"The props to update. Provide only the props you want to change.\",\n },\n },\n required: [\"componentId\", \"newProps\"],\n };\n\n registerTool({\n name: `${tamboToolNamePart}${component.id}`,\n description: `Update the props of interactable component ${component.id} (${component.name}). Provide partial props (only props to change).`,\n tool: ({ componentId, newProps }) => {\n return updateInteractableComponentProps(componentId, newProps);\n },\n inputSchema,\n outputSchema: z.string(),\n annotations: {\n tamboStreamableHint: true,\n ...component.annotations,\n },\n });\n },\n [registerTool, updateInteractableComponentProps],\n );\n\n const registerInteractableComponentStateUpdateTool = useCallback(\n (component: TamboInteractableComponent, maxNameLength = 60) => {\n const tamboToolNamePart = `update_component_state_`;\n const availableLength = maxNameLength - tamboToolNamePart.length;\n if (component.id.length > availableLength) {\n throw new Error(\n `Interactable component id ${component.id} is too long. It must be less than ${availableLength} characters.`,\n );\n }\n\n // Build newState schema as JSON Schema\n let newStateSchema: JSONSchema7 = {\n type: \"object\",\n additionalProperties: true,\n };\n if (component.stateSchema) {\n // Convert any supported schema to JSON Schema, then make partial\n const fullSchema = schemaToJsonSchema(component.stateSchema);\n newStateSchema = makeJsonSchemaPartial(fullSchema);\n }\n\n // Build the full input schema as JSON Schema\n const inputSchema: JSONSchema7 = {\n type: \"object\",\n properties: {\n componentId: {\n type: \"string\",\n description: \"The ID of the interactable component to update\",\n },\n newState: {\n ...newStateSchema,\n description:\n \"The state values to update. Provide only the keys you want to change.\",\n },\n },\n required: [\"componentId\", \"newState\"],\n };\n\n registerTool({\n name: `${tamboToolNamePart}${component.id}`,\n description: `Update the state of interactable component ${component.id} (${component.name}). You may provide partial state (only keys to change).`,\n tool: ({ componentId, newState }) => {\n return updateInteractableComponentState(componentId, newState);\n },\n inputSchema,\n outputSchema: z.string(),\n annotations: {\n tamboStreamableHint: true,\n ...component.annotations,\n },\n });\n },\n [registerTool, updateInteractableComponentState],\n );\n\n const addInteractableComponent = useCallback(\n (\n component: Omit<TamboInteractableComponent, \"id\" | \"createdAt\">,\n ): string => {\n // Validate component name\n assertValidName(component.name, \"component\");\n\n // Add a random part to the component name to make it unique when using multiple instances of the same component.\n const tamboGeneratedNamePart = `-${Math.random().toString(36).slice(2, 5)}`;\n const id = `${component.name}${tamboGeneratedNamePart}`;\n const newComponent: TamboInteractableComponent = {\n ...component,\n id,\n state: component.state ?? {},\n };\n\n registerInteractableComponentPropsUpdateTool(newComponent);\n registerInteractableComponentStateUpdateTool(newComponent);\n\n setInteractableComponents((prev) => {\n return [...prev, newComponent];\n });\n\n return id;\n },\n [\n registerInteractableComponentPropsUpdateTool,\n registerInteractableComponentStateUpdateTool,\n ],\n );\n\n const removeInteractableComponent = useCallback((id: string) => {\n setInteractableComponents((prev) => prev.filter((c) => c.id !== id));\n }, []);\n\n const getInteractableComponent = useCallback(\n <P, S>(id: string): TamboInteractableComponent<P, S> | undefined => {\n return interactableComponents.find((c) => c.id === id) as\n | TamboInteractableComponent<P, S>\n | undefined;\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 setInteractableStateValue = useCallback(\n (componentId: string, key: string, value: unknown) => {\n setInteractableComponents((prev) => {\n const component = prev.find((c) => c.id === componentId);\n if (!component) {\n console.warn(\n `Tried to update state for component ${componentId} but it was not found.`,\n );\n return prev;\n }\n\n const updated = {\n ...component,\n state: {\n ...component.state,\n [key]: value,\n },\n };\n\n const updatedComponents = prev.map((component) => {\n if (component.id === componentId) {\n return updated;\n }\n return component;\n });\n\n return updatedComponents;\n });\n },\n [],\n );\n\n const getInteractableComponentState = useCallback(\n (componentId: string) => {\n const component = interactableComponents.find(\n (c) => c.id === componentId,\n );\n return component?.state;\n },\n [interactableComponents],\n );\n\n const setInteractableSelected = useCallback(\n (componentId: string, isSelected: boolean) => {\n setInteractableComponents((prev) => {\n let found = false;\n const next = prev.map((component) => {\n if (component.id !== componentId) return component;\n found = true;\n return component.isSelected === isSelected\n ? component\n : { ...component, isSelected: isSelected };\n });\n return found ? next : prev;\n });\n },\n [],\n );\n\n const clearInteractableSelections = useCallback(() => {\n setInteractableComponents((prev) => {\n if (!prev.some((c) => c.isSelected)) return prev;\n return prev.map((c) => (c.isSelected ? { ...c, isSelected: false } : c));\n });\n }, []);\n\n const value: TamboInteractableContext = {\n interactableComponents,\n addInteractableComponent,\n removeInteractableComponent,\n updateInteractableComponentProps,\n getInteractableComponent,\n getInteractableComponentsByName,\n clearAllInteractableComponents,\n setInteractableState: setInteractableStateValue,\n getInteractableComponentState,\n setInteractableSelected,\n clearInteractableSelections,\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"]}
|
|
1
|
+
{"version":3,"file":"tambo-interactable-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-interactable-provider.tsx"],"names":[],"mappings":";AAAA,0DAA0D;AAC1D,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,6CAAwC;AAExC,+CAQe;AACf,+BAA2B;AAC3B,kHAA2G;AAM3G,sCAAsE;AACtE,6EAAkE;AAClE,uEAA6D;AAC7D,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;IACxC,oBAAoB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC9B,6BAA6B,EAAE,GAAG,EAAE,CAAC,SAAS;IAC9C,uBAAuB,EAAE,GAAG,EAAE,GAAE,CAAC;IACjC,2BAA2B,EAAE,GA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J,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 { deepEqual } from \"fast-equals\";\nimport { JSONSchema7 } from \"json-schema\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { z } from \"zod/v3\";\nimport { createInteractablesContextHelper } from \"../context-helpers/current-interactables-context-helper\";\nimport type { TamboTool } from \"../model/component-metadata\";\nimport {\n TamboInteractableComponent,\n type TamboInteractableContext,\n} from \"../model/tambo-interactable\";\nimport { makeJsonSchemaPartial, schemaToJsonSchema } from \"../schema\";\nimport { assertValidName } from \"../util/validate-component-name\";\nimport { useTamboRegistry } from \"./tambo-registry-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 setInteractableState: () => {},\n getInteractableComponentState: () => undefined,\n setInteractableSelected: () => {},\n clearInteractableSelections: () => {},\n});\n\n/** Synthetic owner ID used to track global interactable tools in the registry. */\nconst GLOBAL_INTERACTABLE_OWNER = \"__interactable_global__\";\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 [, setToolComponentOwnership] = useState<Record<string, string[]>>({});\n const { registerTool, unregisterTools } = useTamboRegistry();\n const { addContextHelper, removeContextHelper } = useTamboContextHelpers();\n\n const registerToolForComponent = useCallback(\n (componentId: string, tool: TamboTool) => {\n registerTool(tool);\n setToolComponentOwnership((prev) => {\n const existing = prev[componentId] ?? [];\n if (existing.includes(tool.name)) return prev;\n return { ...prev, [componentId]: [...existing, tool.name] };\n });\n },\n [registerTool],\n );\n\n const unregisterToolsForComponent = useCallback(\n (componentId: string) => {\n setToolComponentOwnership((prev) => {\n const toolNames = prev[componentId];\n if (!toolNames || toolNames.length === 0) return prev;\n unregisterTools(toolNames);\n const next = { ...prev };\n delete next[componentId];\n return next;\n });\n },\n [unregisterTools],\n );\n\n // Create a stable context helper function for interactable components\n const interactablesContextHelper = useMemo(\n () => createInteractablesContextHelper(interactableComponents),\n [interactableComponents],\n );\n\n // Register the interactables context helper\n useEffect(() => {\n addContextHelper(\"interactables\", interactablesContextHelper);\n\n return () => {\n removeContextHelper(\"interactables\");\n };\n }, [interactablesContextHelper, addContextHelper, removeContextHelper]);\n\n useEffect(() => {\n if (interactableComponents.length > 0) {\n registerToolForComponent(GLOBAL_INTERACTABLE_OWNER, {\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 inputSchema: z.object({}),\n outputSchema: z.object({\n components: z.array(\n z.object({\n id: z.string(),\n name: z.string(),\n props: z.record(z.string(), z.any()),\n propsSchema: z.record(z.string(), z.any()).optional(),\n }),\n ),\n }),\n });\n\n registerToolForComponent(GLOBAL_INTERACTABLE_OWNER, {\n name: \"get_interactable_component_by_id\",\n description: \"Get a specific interactable component by its ID\",\n tool: ({ componentId }: { 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 } as const;\n }\n\n return {\n success: true,\n component: {\n id: component.id,\n componentName: component.name,\n props: component.props,\n },\n } as const;\n },\n inputSchema: z.object({\n componentId: z.string().describe(\"The ID of the component\"),\n }),\n outputSchema: z.discriminatedUnion(\"success\", [\n z.object({\n success: z.literal(true),\n component: z\n .object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.string(), z.any()),\n })\n .optional(),\n }),\n z.object({\n success: z.literal(false),\n error: z.string(),\n }),\n ]),\n });\n\n registerToolForComponent(GLOBAL_INTERACTABLE_OWNER, {\n name: \"remove_interactable_component\",\n description: \"Remove an interactable component from the system\",\n tool: ({ componentId }: { 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 } as const;\n }\n\n unregisterToolsForComponent(componentId);\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 } as const;\n },\n inputSchema: z.object({\n componentId: z.string().describe(\"The ID of the component\"),\n }),\n outputSchema: z.discriminatedUnion(\"success\", [\n z.object({\n success: z.literal(true),\n componentId: z.string(),\n removedComponent: z.object({\n id: z.string(),\n componentName: z.string(),\n props: z.record(z.string(), z.any()),\n }),\n }),\n z.object({\n success: z.literal(false),\n error: z.string(),\n }),\n ]),\n });\n } else {\n // No interactable components — remove the global tools\n unregisterToolsForComponent(GLOBAL_INTERACTABLE_OWNER);\n }\n }, [\n interactableComponents,\n registerToolForComponent,\n unregisterToolsForComponent,\n ]);\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 updateInteractableComponentState = useCallback(\n (componentId: string, newState: Record<string, unknown>): string => {\n if (!newState || Object.keys(newState).length === 0) {\n return `Warning: No state values provided for component with ID ${componentId}.`;\n }\n\n setInteractableComponents((components = []) => {\n const component = components.find((c) => c.id === componentId);\n if (!component) return components;\n\n const prevState = component.state ?? {};\n const updatedState = { ...prevState, ...newState };\n if (deepEqual(prevState, updatedState)) return components;\n\n // TODO(lachieh): validate state against schema?\n\n const updated = {\n ...component,\n state: updatedState,\n };\n\n return components.map((c) => (c.id === componentId ? updated : c));\n });\n\n return \"Updated successfully\";\n },\n [],\n );\n\n const registerInteractableComponentPropsUpdateTool = useCallback(\n (component: TamboInteractableComponent, maxNameLength = 60) => {\n const tamboToolNamePart = `update_component_props_`;\n const availableLength = maxNameLength - tamboToolNamePart.length;\n if (component.id.length > availableLength) {\n throw new Error(\n `Interactable component id ${component.id} is too long. It must be less than ${availableLength} characters.`,\n );\n }\n\n // Build newProps schema as JSON Schema\n let newPropsSchema: JSONSchema7;\n if (component.propsSchema) {\n // Convert any supported schema to JSON Schema, then make partial\n const fullSchema = schemaToJsonSchema(component.propsSchema);\n newPropsSchema = makeJsonSchemaPartial(fullSchema);\n } else {\n // No schema - allow any properties\n newPropsSchema = { type: \"object\", additionalProperties: true };\n }\n\n // Build the full input schema as JSON Schema\n const inputSchema: JSONSchema7 = {\n type: \"object\",\n properties: {\n componentId: {\n type: \"string\",\n description: \"The ID of the interactable component to update\",\n },\n newProps: {\n ...newPropsSchema,\n description:\n \"The props to update. Provide only the props you want to change.\",\n },\n },\n required: [\"componentId\", \"newProps\"],\n };\n\n registerToolForComponent(component.id, {\n name: `${tamboToolNamePart}${component.id}`,\n description: `Update the props of interactable component ${component.id} (${component.name}). Provide partial props (only props to change).`,\n tool: ({\n componentId,\n newProps,\n }: {\n componentId: string;\n newProps: Record<string, unknown>;\n }) => {\n return updateInteractableComponentProps(componentId, newProps);\n },\n inputSchema,\n outputSchema: z.string(),\n annotations: {\n tamboStreamableHint: true,\n ...component.annotations,\n },\n });\n },\n [registerToolForComponent, updateInteractableComponentProps],\n );\n\n const registerInteractableComponentStateUpdateTool = useCallback(\n (component: TamboInteractableComponent, maxNameLength = 60) => {\n const tamboToolNamePart = `update_component_state_`;\n const availableLength = maxNameLength - tamboToolNamePart.length;\n if (component.id.length > availableLength) {\n throw new Error(\n `Interactable component id ${component.id} is too long. It must be less than ${availableLength} characters.`,\n );\n }\n\n // Build newState schema as JSON Schema\n let newStateSchema: JSONSchema7 = {\n type: \"object\",\n additionalProperties: true,\n };\n if (component.stateSchema) {\n // Convert any supported schema to JSON Schema, then make partial\n const fullSchema = schemaToJsonSchema(component.stateSchema);\n newStateSchema = makeJsonSchemaPartial(fullSchema);\n }\n\n // Build the full input schema as JSON Schema\n const inputSchema: JSONSchema7 = {\n type: \"object\",\n properties: {\n componentId: {\n type: \"string\",\n description: \"The ID of the interactable component to update\",\n },\n newState: {\n ...newStateSchema,\n description:\n \"The state values to update. Provide only the keys you want to change.\",\n },\n },\n required: [\"componentId\", \"newState\"],\n };\n\n registerToolForComponent(component.id, {\n name: `${tamboToolNamePart}${component.id}`,\n description: `Update the state of interactable component ${component.id} (${component.name}). You may provide partial state (only keys to change).`,\n tool: ({\n componentId,\n newState,\n }: {\n componentId: string;\n newState: Record<string, unknown>;\n }) => {\n return updateInteractableComponentState(componentId, newState);\n },\n inputSchema,\n outputSchema: z.string(),\n annotations: {\n tamboStreamableHint: true,\n ...component.annotations,\n },\n });\n },\n [registerToolForComponent, updateInteractableComponentState],\n );\n\n const addInteractableComponent = useCallback(\n (\n component: Omit<TamboInteractableComponent, \"id\" | \"createdAt\">,\n ): string => {\n // Validate component name\n assertValidName(component.name, \"component\");\n\n // Add a random part to the component name to make it unique when using multiple instances of the same component.\n const tamboGeneratedNamePart = `-${Math.random().toString(36).slice(2, 5)}`;\n const id = `${component.name}${tamboGeneratedNamePart}`;\n const newComponent: TamboInteractableComponent = {\n ...component,\n id,\n state: component.state ?? {},\n };\n\n registerInteractableComponentPropsUpdateTool(newComponent);\n registerInteractableComponentStateUpdateTool(newComponent);\n\n setInteractableComponents((prev) => {\n return [...prev, newComponent];\n });\n\n return id;\n },\n [\n registerInteractableComponentPropsUpdateTool,\n registerInteractableComponentStateUpdateTool,\n ],\n );\n\n const removeInteractableComponent = useCallback(\n (id: string) => {\n unregisterToolsForComponent(id);\n setInteractableComponents((prev) => prev.filter((c) => c.id !== id));\n },\n [unregisterToolsForComponent],\n );\n\n const getInteractableComponent = useCallback(\n <P, S>(id: string): TamboInteractableComponent<P, S> | undefined => {\n return interactableComponents.find((c) => c.id === id) as\n | TamboInteractableComponent<P, S>\n | undefined;\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 for (const component of interactableComponents) {\n unregisterToolsForComponent(component.id);\n }\n setInteractableComponents([]);\n }, [interactableComponents, unregisterToolsForComponent]);\n\n const setInteractableStateValue = useCallback(\n (componentId: string, key: string, value: unknown) => {\n setInteractableComponents((prev) => {\n const component = prev.find((c) => c.id === componentId);\n if (!component) {\n console.warn(\n `Tried to update state for component ${componentId} but it was not found.`,\n );\n return prev;\n }\n\n const updated = {\n ...component,\n state: {\n ...component.state,\n [key]: value,\n },\n };\n\n const updatedComponents = prev.map((component) => {\n if (component.id === componentId) {\n return updated;\n }\n return component;\n });\n\n return updatedComponents;\n });\n },\n [],\n );\n\n const getInteractableComponentState = useCallback(\n (componentId: string) => {\n const component = interactableComponents.find(\n (c) => c.id === componentId,\n );\n return component?.state;\n },\n [interactableComponents],\n );\n\n const setInteractableSelected = useCallback(\n (componentId: string, isSelected: boolean) => {\n setInteractableComponents((prev) => {\n let found = false;\n const next = prev.map((component) => {\n if (component.id !== componentId) return component;\n found = true;\n return component.isSelected === isSelected\n ? component\n : { ...component, isSelected: isSelected };\n });\n return found ? next : prev;\n });\n },\n [],\n );\n\n const clearInteractableSelections = useCallback(() => {\n setInteractableComponents((prev) => {\n if (!prev.some((c) => c.isSelected)) return prev;\n return prev.map((c) => (c.isSelected ? { ...c, isSelected: false } : c));\n });\n }, []);\n\n const value: TamboInteractableContext = {\n interactableComponents,\n addInteractableComponent,\n removeInteractableComponent,\n updateInteractableComponentProps,\n getInteractableComponent,\n getInteractableComponentsByName,\n clearAllInteractableComponents,\n setInteractableState: setInteractableStateValue,\n getInteractableComponentState,\n setInteractableSelected,\n clearInteractableSelections,\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"]}
|
|
@@ -19,9 +19,11 @@ jest.mock("./tambo-context-helpers-provider", () => ({
|
|
|
19
19
|
}));
|
|
20
20
|
// Mock the registry provider
|
|
21
21
|
const mockRegisterTool = jest.fn();
|
|
22
|
+
const mockUnregisterTools = jest.fn();
|
|
22
23
|
jest.mock("./tambo-registry-provider", () => ({
|
|
23
24
|
useTamboRegistry: () => ({
|
|
24
25
|
registerTool: mockRegisterTool,
|
|
26
|
+
unregisterTools: mockUnregisterTools,
|
|
25
27
|
}),
|
|
26
28
|
}));
|
|
27
29
|
// Mock the context helper creation
|
|
@@ -77,7 +79,7 @@ describe("TamboInteractableProvider - State Update Tool Registration", () => {
|
|
|
77
79
|
(0, react_1.act)(() => {
|
|
78
80
|
componentId = result.current.addInteractableComponent(component);
|
|
79
81
|
});
|
|
80
|
-
// Should register both update_component_ and update_component_state_ tools
|
|
82
|
+
// Should register both update_component_ and update_component_state_ tools via registerToolForComponent
|
|
81
83
|
const registeredToolNames = mockRegisterTool.mock.calls.map((call) => call[0].name);
|
|
82
84
|
expect(registeredToolNames).toContain(`update_component_props_${componentId}`);
|
|
83
85
|
expect(registeredToolNames).toContain(`update_component_state_${componentId}`);
|
|
@@ -99,6 +101,33 @@ describe("TamboInteractableProvider - State Update Tool Registration", () => {
|
|
|
99
101
|
expect(stateToolCall[0].description).toContain(componentId);
|
|
100
102
|
expect(stateToolCall[0].description).toContain("MyComponent");
|
|
101
103
|
});
|
|
104
|
+
it("should allow props update tool to update component props", () => {
|
|
105
|
+
const { result } = (0, react_1.renderHook)(() => (0, tambo_interactable_provider_1.useTamboInteractable)(), { wrapper });
|
|
106
|
+
const component = {
|
|
107
|
+
name: "TestComponent",
|
|
108
|
+
description: "A test component",
|
|
109
|
+
component: () => react_2.default.createElement("div", null, "Test"),
|
|
110
|
+
props: { title: "original" },
|
|
111
|
+
propsSchema: zod_1.z.object({ title: zod_1.z.string() }),
|
|
112
|
+
};
|
|
113
|
+
let componentId = "";
|
|
114
|
+
(0, react_1.act)(() => {
|
|
115
|
+
componentId = result.current.addInteractableComponent(component);
|
|
116
|
+
});
|
|
117
|
+
// Find the props update tool and call it
|
|
118
|
+
const propsToolCall = mockRegisterTool.mock.calls.find((call) => call[0].name.startsWith("update_component_props_"));
|
|
119
|
+
const toolFn = propsToolCall[0].tool;
|
|
120
|
+
let updateResult = "";
|
|
121
|
+
(0, react_1.act)(() => {
|
|
122
|
+
updateResult = toolFn({
|
|
123
|
+
componentId,
|
|
124
|
+
newProps: { title: "updated" },
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
expect(updateResult).toBe("Updated successfully");
|
|
128
|
+
const comp = result.current.getInteractableComponent(componentId);
|
|
129
|
+
expect(comp?.props.title).toBe("updated");
|
|
130
|
+
});
|
|
102
131
|
it("should allow state update tool to update multiple state values", () => {
|
|
103
132
|
const { result } = (0, react_1.renderHook)(() => (0, tambo_interactable_provider_1.useTamboInteractable)(), { wrapper });
|
|
104
133
|
const component = {
|
|
@@ -347,5 +376,140 @@ describe("TamboInteractableProvider - State Update Tool Registration", () => {
|
|
|
347
376
|
// The newProps property should allow additional properties
|
|
348
377
|
expect(inputSchema.properties.newProps.additionalProperties).toBe(true);
|
|
349
378
|
});
|
|
379
|
+
it("should unregister per-component tools when removing a component", () => {
|
|
380
|
+
const wrapper = ({ children }) => (react_2.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null, children));
|
|
381
|
+
const { result } = (0, react_1.renderHook)(() => (0, tambo_interactable_provider_1.useTamboInteractable)(), { wrapper });
|
|
382
|
+
const component = {
|
|
383
|
+
name: "Cleanup",
|
|
384
|
+
description: "test",
|
|
385
|
+
component: () => null,
|
|
386
|
+
props: { x: 1 },
|
|
387
|
+
};
|
|
388
|
+
let componentId;
|
|
389
|
+
(0, react_1.act)(() => {
|
|
390
|
+
componentId = result.current.addInteractableComponent(component);
|
|
391
|
+
});
|
|
392
|
+
mockUnregisterTools.mockClear();
|
|
393
|
+
(0, react_1.act)(() => {
|
|
394
|
+
result.current.removeInteractableComponent(componentId);
|
|
395
|
+
});
|
|
396
|
+
// Should unregister the per-component tools by name
|
|
397
|
+
expect(mockUnregisterTools).toHaveBeenCalledWith(expect.arrayContaining([
|
|
398
|
+
`update_component_props_${componentId}`,
|
|
399
|
+
`update_component_state_${componentId}`,
|
|
400
|
+
]));
|
|
401
|
+
});
|
|
402
|
+
it("should unregister global tools when all components are removed", () => {
|
|
403
|
+
const wrapper = ({ children }) => (react_2.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null, children));
|
|
404
|
+
const { result } = (0, react_1.renderHook)(() => (0, tambo_interactable_provider_1.useTamboInteractable)(), { wrapper });
|
|
405
|
+
const component = {
|
|
406
|
+
name: "Global",
|
|
407
|
+
description: "test",
|
|
408
|
+
component: () => null,
|
|
409
|
+
props: {},
|
|
410
|
+
};
|
|
411
|
+
let componentId;
|
|
412
|
+
(0, react_1.act)(() => {
|
|
413
|
+
componentId = result.current.addInteractableComponent(component);
|
|
414
|
+
});
|
|
415
|
+
mockUnregisterTools.mockClear();
|
|
416
|
+
(0, react_1.act)(() => {
|
|
417
|
+
result.current.removeInteractableComponent(componentId);
|
|
418
|
+
});
|
|
419
|
+
// Should unregister global interactable tools once list is empty
|
|
420
|
+
expect(mockUnregisterTools).toHaveBeenCalledWith(expect.arrayContaining([
|
|
421
|
+
"get_all_interactable_components",
|
|
422
|
+
"get_interactable_component_by_id",
|
|
423
|
+
"remove_interactable_component",
|
|
424
|
+
]));
|
|
425
|
+
});
|
|
426
|
+
it("should register global tools that return component data", () => {
|
|
427
|
+
const wrapper = ({ children }) => (react_2.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null, children));
|
|
428
|
+
const { result } = (0, react_1.renderHook)(() => (0, tambo_interactable_provider_1.useTamboInteractable)(), { wrapper });
|
|
429
|
+
(0, react_1.act)(() => {
|
|
430
|
+
result.current.addInteractableComponent({
|
|
431
|
+
name: "Widget",
|
|
432
|
+
description: "test widget",
|
|
433
|
+
component: () => null,
|
|
434
|
+
props: { color: "red" },
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
// Find the global get_all tool
|
|
438
|
+
const getAllCall = mockRegisterTool.mock.calls.find((call) => call[0].name === "get_all_interactable_components");
|
|
439
|
+
expect(getAllCall).toBeDefined();
|
|
440
|
+
const getAllResult = getAllCall[0].tool();
|
|
441
|
+
expect(getAllResult.components).toHaveLength(1);
|
|
442
|
+
expect(getAllResult.components[0].name).toBe("Widget");
|
|
443
|
+
});
|
|
444
|
+
it("should register global get_by_id tool that finds a component", () => {
|
|
445
|
+
const wrapper = ({ children }) => (react_2.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null, children));
|
|
446
|
+
const { result } = (0, react_1.renderHook)(() => (0, tambo_interactable_provider_1.useTamboInteractable)(), { wrapper });
|
|
447
|
+
let componentId;
|
|
448
|
+
(0, react_1.act)(() => {
|
|
449
|
+
componentId = result.current.addInteractableComponent({
|
|
450
|
+
name: "Widget",
|
|
451
|
+
description: "test",
|
|
452
|
+
component: () => null,
|
|
453
|
+
props: { x: 1 },
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
const getByIdCall = mockRegisterTool.mock.calls.find((call) => call[0].name === "get_interactable_component_by_id");
|
|
457
|
+
expect(getByIdCall).toBeDefined();
|
|
458
|
+
const found = getByIdCall[0].tool({ componentId: componentId });
|
|
459
|
+
expect(found.success).toBe(true);
|
|
460
|
+
expect(found.component.componentName).toBe("Widget");
|
|
461
|
+
const notFound = getByIdCall[0].tool({ componentId: "nonexistent" });
|
|
462
|
+
expect(notFound.success).toBe(false);
|
|
463
|
+
expect(notFound.error).toContain("not found");
|
|
464
|
+
});
|
|
465
|
+
it("should register global remove tool that removes a component", () => {
|
|
466
|
+
const wrapper = ({ children }) => (react_2.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null, children));
|
|
467
|
+
const { result } = (0, react_1.renderHook)(() => (0, tambo_interactable_provider_1.useTamboInteractable)(), { wrapper });
|
|
468
|
+
let componentId;
|
|
469
|
+
(0, react_1.act)(() => {
|
|
470
|
+
componentId = result.current.addInteractableComponent({
|
|
471
|
+
name: "Widget",
|
|
472
|
+
description: "test",
|
|
473
|
+
component: () => null,
|
|
474
|
+
props: {},
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
const removeCall = mockRegisterTool.mock.calls.find((call) => call[0].name === "remove_interactable_component");
|
|
478
|
+
expect(removeCall).toBeDefined();
|
|
479
|
+
// Remove nonexistent
|
|
480
|
+
const notFound = removeCall[0].tool({ componentId: "nonexistent" });
|
|
481
|
+
expect(notFound.success).toBe(false);
|
|
482
|
+
// Remove existing
|
|
483
|
+
let removeResult;
|
|
484
|
+
(0, react_1.act)(() => {
|
|
485
|
+
removeResult = removeCall[0].tool({ componentId: componentId });
|
|
486
|
+
});
|
|
487
|
+
expect(removeResult.success).toBe(true);
|
|
488
|
+
expect(removeResult.removedComponent.componentName).toBe("Widget");
|
|
489
|
+
});
|
|
490
|
+
it("should unregister all per-component tools when clearing all components", () => {
|
|
491
|
+
const wrapper = ({ children }) => (react_2.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null, children));
|
|
492
|
+
const { result } = (0, react_1.renderHook)(() => (0, tambo_interactable_provider_1.useTamboInteractable)(), { wrapper });
|
|
493
|
+
(0, react_1.act)(() => {
|
|
494
|
+
result.current.addInteractableComponent({
|
|
495
|
+
name: "A",
|
|
496
|
+
description: "test",
|
|
497
|
+
component: () => null,
|
|
498
|
+
props: {},
|
|
499
|
+
});
|
|
500
|
+
result.current.addInteractableComponent({
|
|
501
|
+
name: "B",
|
|
502
|
+
description: "test",
|
|
503
|
+
component: () => null,
|
|
504
|
+
props: {},
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
mockUnregisterTools.mockClear();
|
|
508
|
+
(0, react_1.act)(() => {
|
|
509
|
+
result.current.clearAllInteractableComponents();
|
|
510
|
+
});
|
|
511
|
+
// Should unregister tools for both components
|
|
512
|
+
expect(mockUnregisterTools).toHaveBeenCalled();
|
|
513
|
+
});
|
|
350
514
|
});
|
|
351
515
|
//# sourceMappingURL=tambo-interactable-provider.test.js.map
|