@tambo-ai/react 0.66.2 → 0.67.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 (71) hide show
  1. package/dist/context-helpers/current-interactables-context-helper.d.ts +2 -2
  2. package/dist/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
  3. package/dist/context-helpers/current-interactables-context-helper.js +17 -23
  4. package/dist/context-helpers/current-interactables-context-helper.js.map +1 -1
  5. package/dist/hoc/with-tambo-interactable.d.ts.map +1 -1
  6. package/dist/hoc/with-tambo-interactable.js +0 -1
  7. package/dist/hoc/with-tambo-interactable.js.map +1 -1
  8. package/dist/hooks/use-component-state.d.ts +16 -1
  9. package/dist/hooks/use-component-state.d.ts.map +1 -1
  10. package/dist/hooks/use-component-state.js +72 -12
  11. package/dist/hooks/use-component-state.js.map +1 -1
  12. package/dist/hooks/use-component-state.test.js +42 -0
  13. package/dist/hooks/use-component-state.test.js.map +1 -1
  14. package/dist/hooks/use-current-message.d.ts +1 -0
  15. package/dist/hooks/use-current-message.d.ts.map +1 -1
  16. package/dist/hooks/use-current-message.js +5 -5
  17. package/dist/hooks/use-current-message.js.map +1 -1
  18. package/dist/model/tambo-interactable.d.ts +6 -0
  19. package/dist/model/tambo-interactable.d.ts.map +1 -1
  20. package/dist/model/tambo-interactable.js.map +1 -1
  21. package/dist/providers/tambo-interactable-provider.d.ts +1 -0
  22. package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
  23. package/dist/providers/tambo-interactable-provider.js +37 -7
  24. package/dist/providers/tambo-interactable-provider.js.map +1 -1
  25. package/dist/providers/tambo-interactable-provider.test.d.ts +2 -0
  26. package/dist/providers/tambo-interactable-provider.test.d.ts.map +1 -0
  27. package/dist/providers/tambo-interactable-provider.test.js +62 -0
  28. package/dist/providers/tambo-interactable-provider.test.js.map +1 -0
  29. package/dist/schema/zod.d.ts.map +1 -1
  30. package/dist/schema/zod.js +3 -3
  31. package/dist/schema/zod.js.map +1 -1
  32. package/dist/schema/zod.test.d.ts +2 -0
  33. package/dist/schema/zod.test.d.ts.map +1 -0
  34. package/dist/schema/zod.test.js +551 -0
  35. package/dist/schema/zod.test.js.map +1 -0
  36. package/esm/context-helpers/current-interactables-context-helper.d.ts +2 -2
  37. package/esm/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
  38. package/esm/context-helpers/current-interactables-context-helper.js +17 -23
  39. package/esm/context-helpers/current-interactables-context-helper.js.map +1 -1
  40. package/esm/hoc/with-tambo-interactable.d.ts.map +1 -1
  41. package/esm/hoc/with-tambo-interactable.js +0 -1
  42. package/esm/hoc/with-tambo-interactable.js.map +1 -1
  43. package/esm/hooks/use-component-state.d.ts +16 -1
  44. package/esm/hooks/use-component-state.d.ts.map +1 -1
  45. package/esm/hooks/use-component-state.js +74 -14
  46. package/esm/hooks/use-component-state.js.map +1 -1
  47. package/esm/hooks/use-component-state.test.js +40 -1
  48. package/esm/hooks/use-component-state.test.js.map +1 -1
  49. package/esm/hooks/use-current-message.d.ts +1 -0
  50. package/esm/hooks/use-current-message.d.ts.map +1 -1
  51. package/esm/hooks/use-current-message.js +1 -1
  52. package/esm/hooks/use-current-message.js.map +1 -1
  53. package/esm/model/tambo-interactable.d.ts +6 -0
  54. package/esm/model/tambo-interactable.d.ts.map +1 -1
  55. package/esm/model/tambo-interactable.js.map +1 -1
  56. package/esm/providers/tambo-interactable-provider.d.ts +1 -0
  57. package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
  58. package/esm/providers/tambo-interactable-provider.js +38 -8
  59. package/esm/providers/tambo-interactable-provider.js.map +1 -1
  60. package/esm/providers/tambo-interactable-provider.test.d.ts +2 -0
  61. package/esm/providers/tambo-interactable-provider.test.d.ts.map +1 -0
  62. package/esm/providers/tambo-interactable-provider.test.js +57 -0
  63. package/esm/providers/tambo-interactable-provider.test.js.map +1 -0
  64. package/esm/schema/zod.d.ts.map +1 -1
  65. package/esm/schema/zod.js +3 -3
  66. package/esm/schema/zod.js.map +1 -1
  67. package/esm/schema/zod.test.d.ts +2 -0
  68. package/esm/schema/zod.test.d.ts.map +1 -0
  69. package/esm/schema/zod.test.js +516 -0
  70. package/esm/schema/zod.test.js.map +1 -0
  71. package/package.json +2 -2
@@ -34,10 +34,10 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  };
35
35
  })();
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.useTamboCurrentComponent = exports.useTamboCurrentMessage = exports.TamboMessageProvider = void 0;
37
+ exports.useTamboCurrentComponent = exports.useTamboCurrentMessage = exports.TamboMessageProvider = exports.TamboMessageContext = void 0;
38
38
  exports.wrapWithTamboMessageProvider = wrapWithTamboMessageProvider;
39
39
  const react_1 = __importStar(require("react"));
40
- const TamboMessageContext = (0, react_1.createContext)(null);
40
+ exports.TamboMessageContext = (0, react_1.createContext)(null);
41
41
  /**
42
42
  * Wraps all components, so that they can find what message they are in.
43
43
  * Also supports optional interactable metadata for components wrapped with withInteractable.
@@ -55,7 +55,7 @@ const TamboMessageProvider = ({ children, message, interactableMetadata, }) => {
55
55
  // Use a unique key={...} to force a re-render when the message changes - this
56
56
  // make sure that if the rendered component is swapped into a tree (like if
57
57
  // you always show the last rendered component) then the state/etc is correct
58
- return (react_1.default.createElement(TamboMessageContext.Provider, { value: enhancedMessage, key: message.id }, children));
58
+ return (react_1.default.createElement(exports.TamboMessageContext.Provider, { value: enhancedMessage, key: message.id }, children));
59
59
  };
60
60
  exports.TamboMessageProvider = TamboMessageProvider;
61
61
  /**
@@ -75,7 +75,7 @@ function wrapWithTamboMessageProvider(children, message, interactableMetadata) {
75
75
  * @returns The current message that is used to render the component
76
76
  */
77
77
  const useTamboCurrentMessage = () => {
78
- const message = (0, react_1.useContext)(TamboMessageContext);
78
+ const message = (0, react_1.useContext)(exports.TamboMessageContext);
79
79
  if (!message) {
80
80
  throw new Error("useTamboCurrentMessage must be used within a TamboMessageProvider");
81
81
  }
@@ -105,7 +105,7 @@ exports.useTamboCurrentMessage = useTamboCurrentMessage;
105
105
  * ```
106
106
  */
107
107
  const useTamboCurrentComponent = () => {
108
- const message = (0, react_1.useContext)(TamboMessageContext);
108
+ const message = (0, react_1.useContext)(exports.TamboMessageContext);
109
109
  if (!message) {
110
110
  return null;
111
111
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-current-message.js","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDb,oEAaC;AAjED,+CAAyD;AAMzD,MAAM,mBAAmB,GAAG,IAAA,qBAAa,EAA4B,IAAI,CAAC,CAAC;AAS3E;;;;;;;;GAQG;AACI,MAAM,oBAAoB,GAAwC,CAAC,EACxE,QAAQ,EACR,OAAO,EACP,oBAAoB,GACrB,EAAE,EAAE;IACH,uDAAuD;IACvD,MAAM,eAAe,GAAuB,oBAAoB;QAC9D,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,oBAAoB,EAAE;QACtC,CAAC,CAAC,OAAO,CAAC;IAEZ,8EAA8E;IAC9E,2EAA2E;IAC3E,6EAA6E;IAC7E,OAAO,CACL,8BAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,IAClE,QAAQ,CACoB,CAChC,CAAC;AACJ,CAAC,CAAC;AAlBW,QAAA,oBAAoB,wBAkB/B;AAEF;;;;;;;GAOG;AACH,SAAgB,4BAA4B,CAC1C,QAAyB,EACzB,OAA2B,EAC3B,oBAA2C;IAE3C,OAAO,CACL,8BAAC,4BAAoB,IACnB,OAAO,EAAE,OAAO,EAChB,oBAAoB,EAAE,oBAAoB,IAEzC,QAAQ,CACY,CACxB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACI,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,mBAAmB,CAAC,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AARW,QAAA,sBAAsB,0BAQjC;AAmBF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACI,MAAM,wBAAwB,GAAG,GAAiC,EAAE;IACzE,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,mBAAmB,CAAC,CAAC;IAEhD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,aAAa,EACX,OAAO,CAAC,oBAAoB,EAAE,aAAa;YAC3C,OAAO,CAAC,SAAS,EAAE,aAAa;YAChC,SAAS;QACX,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE,KAAwC;QAClE,cAAc,EAAE,OAAO,CAAC,oBAAoB,EAAE,EAAE,IAAI,SAAS;QAC7D,WAAW,EAAE,OAAO,CAAC,oBAAoB,EAAE,WAAW,IAAI,SAAS;QACnE,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,wBAAwB,4BAiBnC","sourcesContent":["\"use client\";\nimport React, { createContext, useContext } from \"react\";\nimport {\n InteractableMetadata,\n TamboThreadMessage,\n} from \"../model/generate-component-response\";\n\nconst TamboMessageContext = createContext<TamboThreadMessage | null>(null);\n\nexport interface TamboMessageProviderProps {\n children: React.ReactNode;\n message: TamboThreadMessage;\n /** Optional interactable metadata for components wrapped with withInteractable */\n interactableMetadata?: InteractableMetadata;\n}\n\n/**\n * Wraps all components, so that they can find what message they are in.\n * Also supports optional interactable metadata for components wrapped with withInteractable.\n * @param props - props for the TamboMessageProvider\n * @param props.children - The children to wrap\n * @param props.message - The message object\n * @param props.interactableMetadata - Optional interactable component metadata\n * @returns The wrapped component\n */\nexport const TamboMessageProvider: React.FC<TamboMessageProviderProps> = ({\n children,\n message,\n interactableMetadata,\n}) => {\n // Merge interactable metadata into message if provided\n const enhancedMessage: TamboThreadMessage = interactableMetadata\n ? { ...message, interactableMetadata }\n : message;\n\n // Use a unique key={...} to force a re-render when the message changes - this\n // make sure that if the rendered component is swapped into a tree (like if\n // you always show the last rendered component) then the state/etc is correct\n return (\n <TamboMessageContext.Provider value={enhancedMessage} key={message.id}>\n {children}\n </TamboMessageContext.Provider>\n );\n};\n\n/**\n * Wraps a component with a TamboMessageProvider - this allows the provider\n * to be used outside of a TSX file\n * @param children - The children to wrap\n * @param message - The message object\n * @param interactableMetadata - Optional interactable metadata\n * @returns The wrapped component\n */\nexport function wrapWithTamboMessageProvider(\n children: React.ReactNode,\n message: TamboThreadMessage,\n interactableMetadata?: InteractableMetadata,\n) {\n return (\n <TamboMessageProvider\n message={message}\n interactableMetadata={interactableMetadata}\n >\n {children}\n </TamboMessageProvider>\n );\n}\n\n/**\n * Hook used inside a component wrapped with TamboMessageProvider, to get\n * the current message.\n * @returns The current message that is used to render the component\n */\nexport const useTamboCurrentMessage = () => {\n const message = useContext(TamboMessageContext);\n if (!message) {\n throw new Error(\n \"useTamboCurrentMessage must be used within a TamboMessageProvider\",\n );\n }\n return message;\n};\n\n/**\n * Component info extracted from the current message and interactable context.\n * Provides a unified interface for accessing component metadata.\n */\nexport interface TamboCurrentComponent {\n /** Component name from the message */\n componentName?: string;\n /** Component props from the message */\n props?: Record<string, any>;\n /** Interactable ID (only present for components wrapped with withInteractable) */\n interactableId?: string;\n /** Description (only present for components wrapped with withInteractable) */\n description?: string;\n /** Thread ID from the message (only present when the component is part of a thread) */\n threadId?: string;\n}\n\n/**\n * Hook to access the current component information from the message context.\n * Provides a unified interface for both AI-generated and interactable components.\n *\n * **Use this hook when you need component metadata regardless of the context.**\n * @returns Component info including name, props, and interactable metadata if available, or null if used outside TamboMessageProvider\n * @example\n * ```tsx\n * function MyInlineEditor() {\n * const component = useTamboCurrentComponent();\n *\n * if (!component) return null; // Not inside a component\n *\n * return (\n * <div>\n * Editing: {component.componentName}\n * {component.interactableId && <span>ID: {component.interactableId}</span>}\n * </div>\n * );\n * }\n * ```\n */\nexport const useTamboCurrentComponent = (): TamboCurrentComponent | null => {\n const message = useContext(TamboMessageContext);\n\n if (!message) {\n return null;\n }\n\n return {\n componentName:\n message.interactableMetadata?.componentName ??\n message.component?.componentName ??\n undefined,\n props: message.component?.props as Record<string, any> | undefined,\n interactableId: message.interactableMetadata?.id ?? undefined,\n description: message.interactableMetadata?.description ?? undefined,\n threadId: message.threadId,\n };\n};\n"]}
1
+ {"version":3,"file":"use-current-message.js","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDb,oEAaC;AAnED,+CAAyD;AAM5C,QAAA,mBAAmB,GAAG,IAAA,qBAAa,EAC9C,IAAI,CACL,CAAC;AASF;;;;;;;;GAQG;AACI,MAAM,oBAAoB,GAAwC,CAAC,EACxE,QAAQ,EACR,OAAO,EACP,oBAAoB,GACrB,EAAE,EAAE;IACH,uDAAuD;IACvD,MAAM,eAAe,GAAuB,oBAAoB;QAC9D,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,oBAAoB,EAAE;QACtC,CAAC,CAAC,OAAO,CAAC;IAEZ,8EAA8E;IAC9E,2EAA2E;IAC3E,6EAA6E;IAC7E,OAAO,CACL,8BAAC,2BAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,IAClE,QAAQ,CACoB,CAChC,CAAC;AACJ,CAAC,CAAC;AAlBW,QAAA,oBAAoB,wBAkB/B;AAEF;;;;;;;GAOG;AACH,SAAgB,4BAA4B,CAC1C,QAAyB,EACzB,OAA2B,EAC3B,oBAA2C;IAE3C,OAAO,CACL,8BAAC,4BAAoB,IACnB,OAAO,EAAE,OAAO,EAChB,oBAAoB,EAAE,oBAAoB,IAEzC,QAAQ,CACY,CACxB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACI,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,2BAAmB,CAAC,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AARW,QAAA,sBAAsB,0BAQjC;AAmBF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACI,MAAM,wBAAwB,GAAG,GAAiC,EAAE;IACzE,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,2BAAmB,CAAC,CAAC;IAEhD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,aAAa,EACX,OAAO,CAAC,oBAAoB,EAAE,aAAa;YAC3C,OAAO,CAAC,SAAS,EAAE,aAAa;YAChC,SAAS;QACX,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE,KAAwC;QAClE,cAAc,EAAE,OAAO,CAAC,oBAAoB,EAAE,EAAE,IAAI,SAAS;QAC7D,WAAW,EAAE,OAAO,CAAC,oBAAoB,EAAE,WAAW,IAAI,SAAS;QACnE,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,wBAAwB,4BAiBnC","sourcesContent":["\"use client\";\nimport React, { createContext, useContext } from \"react\";\nimport {\n InteractableMetadata,\n TamboThreadMessage,\n} from \"../model/generate-component-response\";\n\nexport const TamboMessageContext = createContext<TamboThreadMessage | null>(\n null,\n);\n\nexport interface TamboMessageProviderProps {\n children: React.ReactNode;\n message: TamboThreadMessage;\n /** Optional interactable metadata for components wrapped with withInteractable */\n interactableMetadata?: InteractableMetadata;\n}\n\n/**\n * Wraps all components, so that they can find what message they are in.\n * Also supports optional interactable metadata for components wrapped with withInteractable.\n * @param props - props for the TamboMessageProvider\n * @param props.children - The children to wrap\n * @param props.message - The message object\n * @param props.interactableMetadata - Optional interactable component metadata\n * @returns The wrapped component\n */\nexport const TamboMessageProvider: React.FC<TamboMessageProviderProps> = ({\n children,\n message,\n interactableMetadata,\n}) => {\n // Merge interactable metadata into message if provided\n const enhancedMessage: TamboThreadMessage = interactableMetadata\n ? { ...message, interactableMetadata }\n : message;\n\n // Use a unique key={...} to force a re-render when the message changes - this\n // make sure that if the rendered component is swapped into a tree (like if\n // you always show the last rendered component) then the state/etc is correct\n return (\n <TamboMessageContext.Provider value={enhancedMessage} key={message.id}>\n {children}\n </TamboMessageContext.Provider>\n );\n};\n\n/**\n * Wraps a component with a TamboMessageProvider - this allows the provider\n * to be used outside of a TSX file\n * @param children - The children to wrap\n * @param message - The message object\n * @param interactableMetadata - Optional interactable metadata\n * @returns The wrapped component\n */\nexport function wrapWithTamboMessageProvider(\n children: React.ReactNode,\n message: TamboThreadMessage,\n interactableMetadata?: InteractableMetadata,\n) {\n return (\n <TamboMessageProvider\n message={message}\n interactableMetadata={interactableMetadata}\n >\n {children}\n </TamboMessageProvider>\n );\n}\n\n/**\n * Hook used inside a component wrapped with TamboMessageProvider, to get\n * the current message.\n * @returns The current message that is used to render the component\n */\nexport const useTamboCurrentMessage = () => {\n const message = useContext(TamboMessageContext);\n if (!message) {\n throw new Error(\n \"useTamboCurrentMessage must be used within a TamboMessageProvider\",\n );\n }\n return message;\n};\n\n/**\n * Component info extracted from the current message and interactable context.\n * Provides a unified interface for accessing component metadata.\n */\nexport interface TamboCurrentComponent {\n /** Component name from the message */\n componentName?: string;\n /** Component props from the message */\n props?: Record<string, any>;\n /** Interactable ID (only present for components wrapped with withInteractable) */\n interactableId?: string;\n /** Description (only present for components wrapped with withInteractable) */\n description?: string;\n /** Thread ID from the message (only present when the component is part of a thread) */\n threadId?: string;\n}\n\n/**\n * Hook to access the current component information from the message context.\n * Provides a unified interface for both AI-generated and interactable components.\n *\n * **Use this hook when you need component metadata regardless of the context.**\n * @returns Component info including name, props, and interactable metadata if available, or null if used outside TamboMessageProvider\n * @example\n * ```tsx\n * function MyInlineEditor() {\n * const component = useTamboCurrentComponent();\n *\n * if (!component) return null; // Not inside a component\n *\n * return (\n * <div>\n * Editing: {component.componentName}\n * {component.interactableId && <span>ID: {component.interactableId}</span>}\n * </div>\n * );\n * }\n * ```\n */\nexport const useTamboCurrentComponent = (): TamboCurrentComponent | null => {\n const message = useContext(TamboMessageContext);\n\n if (!message) {\n return null;\n }\n\n return {\n componentName:\n message.interactableMetadata?.componentName ??\n message.component?.componentName ??\n undefined,\n props: message.component?.props as Record<string, any> | undefined,\n interactableId: message.interactableMetadata?.id ?? undefined,\n description: message.interactableMetadata?.description ?? undefined,\n threadId: message.threadId,\n };\n};\n"]}
@@ -4,6 +4,8 @@ export interface TamboInteractableComponent extends TamboComponent {
4
4
  id: string;
5
5
  /** Current props for the component */
6
6
  props: Record<string, any>;
7
+ /** Current state for the component */
8
+ state?: Record<string, unknown>;
7
9
  }
8
10
  export interface TamboInteractableContext {
9
11
  /** List of all interactable components */
@@ -20,5 +22,9 @@ export interface TamboInteractableContext {
20
22
  getInteractableComponentsByName: (componentName: string) => TamboInteractableComponent[];
21
23
  /** Clear all interactable components */
22
24
  clearAllInteractableComponents: () => void;
25
+ /** Set state for a specific interactable component */
26
+ setInteractableState: (componentId: string, key: string, value: unknown) => void;
27
+ /** Get state for a specific interactable component */
28
+ getInteractableComponentState: (componentId: string) => Record<string, unknown> | undefined;
23
29
  }
24
30
  //# sourceMappingURL=tambo-interactable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-interactable.d.ts","sourceRoot":"","sources":["../../src/model/tambo-interactable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,WAAW,0BAA2B,SAAQ,cAAc;IAChE,oDAAoD;IACpD,EAAE,EAAE,MAAM,CAAC;IACX,sCAAsC;IACtC,KAAK,EAAE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AC,0BAA0B,EAAE,IAAI,GAAG,WAAW,CAAC,KAC5D,MAAM,CAAC;IACZ,6CAA6C;IAC7C,2BAA2B,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,+CAA+C;IAC/C,gCAAgC,EAAE,CAChC,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC1B,MAAM,CAAC;IACZ,0CAA0C;IAC1C,wBAAwB,EAAE,CACxB,EAAE,EAAE,MAAM,KACP,0BAA0B,GAAG,SAAS,CAAC;IAC5C,wDAAwD;IACxD,+BAA+B,EAAE,CAC/B,aAAa,EAAE,MAAM,KAClB,0BAA0B,EAAE,CAAC;IAClC,wCAAwC;IACxC,8BAA8B,EAAE,MAAM,IAAI,CAAC;IAC3C,sDAAsD;IACtD,oBAAoB,EAAE,CACpB,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,KACX,IAAI,CAAC;IACV,sDAAsD;IACtD,6BAA6B,EAAE,CAC7B,WAAW,EAAE,MAAM,KAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CAC1C"}
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-interactable.js","sourceRoot":"","sources":["../../src/model/tambo-interactable.ts"],"names":[],"mappings":"","sourcesContent":["import { TamboComponent } from \"./component-metadata\";\n\nexport interface TamboInteractableComponent extends TamboComponent {\n /** Unique identifier for this component instance */\n id: string;\n /** Current props for the component */\n props: Record<string, any>;\n}\n\nexport interface TamboInteractableContext {\n /** List of all interactable components */\n interactableComponents: TamboInteractableComponent[];\n /** Add a new interactable component */\n addInteractableComponent: (\n component: Omit<TamboInteractableComponent, \"id\" | \"createdAt\">,\n ) => string;\n /** Remove an interactable component by ID */\n removeInteractableComponent: (id: string) => void;\n /** Update an interactable component's props */\n updateInteractableComponentProps: (\n id: string,\n newProps: Record<string, any>,\n ) => string;\n /** Get an interactable component by ID */\n getInteractableComponent: (\n id: string,\n ) => TamboInteractableComponent | undefined;\n /** Get all interactable components by component name */\n getInteractableComponentsByName: (\n componentName: string,\n ) => TamboInteractableComponent[];\n /** Clear all interactable components */\n clearAllInteractableComponents: () => void;\n}\n"]}
1
+ {"version":3,"file":"tambo-interactable.js","sourceRoot":"","sources":["../../src/model/tambo-interactable.ts"],"names":[],"mappings":"","sourcesContent":["import { TamboComponent } from \"./component-metadata\";\n\nexport interface TamboInteractableComponent extends TamboComponent {\n /** Unique identifier for this component instance */\n id: string;\n /** Current props for the component */\n props: Record<string, any>;\n /** Current state for the component */\n state?: Record<string, unknown>;\n}\n\nexport interface TamboInteractableContext {\n /** List of all interactable components */\n interactableComponents: TamboInteractableComponent[];\n /** Add a new interactable component */\n addInteractableComponent: (\n component: Omit<TamboInteractableComponent, \"id\" | \"createdAt\">,\n ) => string;\n /** Remove an interactable component by ID */\n removeInteractableComponent: (id: string) => void;\n /** Update an interactable component's props */\n updateInteractableComponentProps: (\n id: string,\n newProps: Record<string, any>,\n ) => string;\n /** Get an interactable component by ID */\n getInteractableComponent: (\n id: string,\n ) => TamboInteractableComponent | undefined;\n /** Get all interactable components by component name */\n getInteractableComponentsByName: (\n componentName: string,\n ) => TamboInteractableComponent[];\n /** Clear all interactable components */\n clearAllInteractableComponents: () => void;\n /** Set state for a specific interactable component */\n setInteractableState: (\n componentId: string,\n key: string,\n value: unknown,\n ) => void;\n /** Get state for a specific interactable component */\n getInteractableComponentState: (\n componentId: string,\n ) => Record<string, unknown> | undefined;\n}\n"]}
@@ -27,6 +27,7 @@ export declare const useCurrentInteractablesSnapshot: () => {
27
27
  [x: string]: any;
28
28
  };
29
29
  id: string;
30
+ state?: Record<string, unknown>;
30
31
  name: string;
31
32
  description: string;
32
33
  component: React.ComponentType<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-interactable-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-interactable-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAGf,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,6BAA6B,CAAC;AAKrC,QAAA,MAAM,wBAAwB,yCAQ5B,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA0RjE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,gCAEhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B;;;;;;;;;;;;GAS3C,CAAC"}
1
+ {"version":3,"file":"tambo-interactable-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-interactable-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAMlB,MAAM,OAAO,CAAC;AAGf,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,6BAA6B,CAAC;AAKrC,QAAA,MAAM,wBAAwB,yCAU5B,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAwUjE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,gCAEhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;GAS3C,CAAC"}
@@ -50,6 +50,8 @@ const TamboInteractableContext = (0, react_1.createContext)({
50
50
  getInteractableComponent: () => undefined,
51
51
  getInteractableComponentsByName: () => [],
52
52
  clearAllInteractableComponents: () => { },
53
+ setInteractableState: () => { },
54
+ getInteractableComponentState: () => undefined,
53
55
  });
54
56
  /**
55
57
  * The TamboInteractableProvider manages a list of components that are currently
@@ -63,17 +65,15 @@ const TamboInteractableProvider = ({ children, }) => {
63
65
  const [interactableComponents, setInteractableComponents] = (0, react_1.useState)([]);
64
66
  const { registerTool } = (0, tambo_component_provider_1.useTamboComponent)();
65
67
  const { addContextHelper, removeContextHelper } = (0, tambo_context_helpers_provider_1.useTamboContextHelpers)();
66
- // Create a stable context helper function
67
- const contextHelper = (0, react_1.useCallback)(() => {
68
- return (0, current_interactables_context_helper_1.createInteractablesContextHelper)(() => interactableComponents)();
69
- }, [interactableComponents]);
70
- // Register the default interactables context helper
68
+ // Create a stable context helper function for interactable components
69
+ const interactablesContextHelper = (0, react_1.useMemo)(() => (0, current_interactables_context_helper_1.createInteractablesContextHelper)(interactableComponents), [interactableComponents]);
70
+ // Register the interactables context helper
71
71
  (0, react_1.useEffect)(() => {
72
- addContextHelper("interactables", contextHelper);
72
+ addContextHelper("interactables", interactablesContextHelper);
73
73
  return () => {
74
74
  removeContextHelper("interactables");
75
75
  };
76
- }, [contextHelper, addContextHelper, removeContextHelper]);
76
+ }, [interactablesContextHelper, addContextHelper, removeContextHelper]);
77
77
  (0, react_1.useEffect)(() => {
78
78
  if (interactableComponents.length > 0) {
79
79
  registerTool({
@@ -240,6 +240,7 @@ const TamboInteractableProvider = ({ children, }) => {
240
240
  const newComponent = {
241
241
  ...component,
242
242
  id,
243
+ state: component.state ?? {},
243
244
  };
244
245
  registerInteractableComponentUpdateTool(newComponent);
245
246
  setInteractableComponents((prev) => {
@@ -259,6 +260,33 @@ const TamboInteractableProvider = ({ children, }) => {
259
260
  const clearAllInteractableComponents = (0, react_1.useCallback)(() => {
260
261
  setInteractableComponents([]);
261
262
  }, []);
263
+ const setInteractableStateValue = (0, react_1.useCallback)((componentId, key, value) => {
264
+ setInteractableComponents((prev) => {
265
+ const component = prev.find((c) => c.id === componentId);
266
+ if (!component) {
267
+ console.warn(`Tried to update state for component ${componentId} but it was not found.`);
268
+ return prev;
269
+ }
270
+ const updated = {
271
+ ...component,
272
+ state: {
273
+ ...(component.state ?? {}),
274
+ [key]: value,
275
+ },
276
+ };
277
+ const updatedComponents = prev.map((component) => {
278
+ if (component.id === componentId) {
279
+ return updated;
280
+ }
281
+ return component;
282
+ });
283
+ return updatedComponents;
284
+ });
285
+ }, []);
286
+ const getInteractableComponentState = (0, react_1.useCallback)((componentId) => {
287
+ const component = interactableComponents.find((c) => c.id === componentId);
288
+ return component?.state;
289
+ }, [interactableComponents]);
262
290
  const value = {
263
291
  interactableComponents,
264
292
  addInteractableComponent,
@@ -267,6 +295,8 @@ const TamboInteractableProvider = ({ children, }) => {
267
295
  getInteractableComponent,
268
296
  getInteractableComponentsByName,
269
297
  clearAllInteractableComponents,
298
+ setInteractableState: setInteractableStateValue,
299
+ getInteractableComponentState,
270
300
  };
271
301
  return (react_1.default.createElement(TamboInteractableContext.Provider, { value: value }, children));
272
302
  };
@@ -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,+BAA2B;AAC3B,kHAA2G;AAK3G,6EAAkE;AAClE,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,IA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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 React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\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 { assertValidName } from \"../util/validate-component-name\";\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 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 registerInteractableComponentUpdateTool = useCallback(\n (component: TamboInteractableComponent, maxNameLength = 60) => {\n const tamboToolNamePart = `update_component_`;\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 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: `${tamboToolNamePart}${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, newProps }) => {\n return updateInteractableComponentProps(componentId, newProps);\n },\n inputSchema: z.object({\n componentId: z\n .string()\n .describe(\"The ID of the interactable component to update\"),\n newProps: 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 outputSchema: z.string(),\n });\n },\n [registerTool, updateInteractableComponentProps],\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 };\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"]}
1
+ {"version":3,"file":"tambo-interactable-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-interactable-provider.tsx"],"names":[],"mappings":";AAAA,0DAA0D;AAC1D,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAQe;AACf,+BAA2B;AAC3B,kHAA2G;AAK3G,6EAAkE;AAClE,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;IACxC,oBAAoB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC9B,6BAA6B,EAAE,GAAG,EAAE,CAAC,SAAS;CAC/C,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,EA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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 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 { assertValidName } from \"../util/validate-component-name\";\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 setInteractableState: () => {},\n getInteractableComponentState: () => undefined,\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 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 registerInteractableComponentUpdateTool = useCallback(\n (component: TamboInteractableComponent, maxNameLength = 60) => {\n const tamboToolNamePart = `update_component_`;\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 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: `${tamboToolNamePart}${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, newProps }) => {\n return updateInteractableComponentProps(componentId, newProps);\n },\n inputSchema: z.object({\n componentId: z\n .string()\n .describe(\"The ID of the interactable component to update\"),\n newProps: 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 outputSchema: z.string(),\n });\n },\n [registerTool, updateInteractableComponentProps],\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 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 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 value: TamboInteractableContext = {\n interactableComponents,\n addInteractableComponent,\n removeInteractableComponent,\n updateInteractableComponentProps,\n getInteractableComponent,\n getInteractableComponentsByName,\n clearAllInteractableComponents,\n setInteractableState: setInteractableStateValue,\n getInteractableComponentState,\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"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tambo-interactable-provider.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-interactable-provider.test.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-interactable-provider.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const react_1 = require("@testing-library/react");
7
+ const react_2 = __importDefault(require("react"));
8
+ const zod_1 = require("zod");
9
+ const tambo_interactable_provider_1 = require("./tambo-interactable-provider");
10
+ // Mock the context helpers
11
+ const mockAddContextHelper = jest.fn();
12
+ const mockRemoveContextHelper = jest.fn();
13
+ jest.mock("./tambo-context-helpers-provider", () => ({
14
+ TamboContextHelpersProvider: ({ children, }) => react_2.default.createElement(react_2.default.Fragment, null, children),
15
+ useTamboContextHelpers: () => ({
16
+ addContextHelper: mockAddContextHelper,
17
+ removeContextHelper: mockRemoveContextHelper,
18
+ }),
19
+ }));
20
+ // Mock the component provider
21
+ const mockRegisterTool = jest.fn();
22
+ jest.mock("./tambo-component-provider", () => ({
23
+ useTamboComponent: () => ({
24
+ registerTool: mockRegisterTool,
25
+ }),
26
+ }));
27
+ // Mock the context helper creation
28
+ jest.mock("../context-helpers/current-interactables-context-helper", () => ({
29
+ createInteractablesContextHelper: () => jest.fn(() => ({
30
+ name: "interactables",
31
+ context: {
32
+ description: "Test interactables context",
33
+ components: [],
34
+ },
35
+ })),
36
+ }));
37
+ describe("TamboInteractableProvider - State Tracking", () => {
38
+ beforeEach(() => {
39
+ jest.clearAllMocks();
40
+ });
41
+ const wrapper = ({ children }) => (react_2.default.createElement(tambo_interactable_provider_1.TamboInteractableProvider, null, children));
42
+ it("should set and get state for a component", () => {
43
+ const { result } = (0, react_1.renderHook)(() => (0, tambo_interactable_provider_1.useTamboInteractable)(), { wrapper });
44
+ const component = {
45
+ name: "TestComponent",
46
+ description: "A test component",
47
+ component: () => react_2.default.createElement("div", null, "Test"),
48
+ props: { title: "Test" },
49
+ propsSchema: zod_1.z.object({ title: zod_1.z.string() }),
50
+ };
51
+ let componentId = "";
52
+ (0, react_1.act)(() => {
53
+ componentId = result.current.addInteractableComponent(component);
54
+ });
55
+ (0, react_1.act)(() => {
56
+ result.current.setInteractableState(componentId, "count", 10);
57
+ });
58
+ const state = result.current.getInteractableComponentState(componentId);
59
+ expect(state).toEqual({ count: 10 });
60
+ });
61
+ });
62
+ //# sourceMappingURL=tambo-interactable-provider.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-interactable-provider.test.js","sourceRoot":"","sources":["../../src/providers/tambo-interactable-provider.test.tsx"],"names":[],"mappings":";;;;;AAAA,kDAAyD;AACzD,kDAA0B;AAC1B,6BAAwB;AAExB,+EAGuC;AAEvC,2BAA2B;AAC3B,MAAM,oBAAoB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACvC,MAAM,uBAAuB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAE1C,IAAI,CAAC,IAAI,CAAC,kCAAkC,EAAE,GAAG,EAAE,CAAC,CAAC;IACnD,2BAA2B,EAAE,CAAC,EAC5B,QAAQ,GAGT,EAAE,EAAE,CAAC,8DAAG,QAAQ,CAAI;IACrB,sBAAsB,EAAE,GAAG,EAAE,CAAC,CAAC;QAC7B,gBAAgB,EAAE,oBAAoB;QACtC,mBAAmB,EAAE,uBAAuB;KAC7C,CAAC;CACH,CAAC,CAAC,CAAC;AAEJ,8BAA8B;AAC9B,MAAM,gBAAgB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAEnC,IAAI,CAAC,IAAI,CAAC,4BAA4B,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7C,iBAAiB,EAAE,GAAG,EAAE,CAAC,CAAC;QACxB,YAAY,EAAE,gBAAgB;KAC/B,CAAC;CACH,CAAC,CAAC,CAAC;AAEJ,mCAAmC;AACnC,IAAI,CAAC,IAAI,CAAC,yDAAyD,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1E,gCAAgC,EAAE,GAAG,EAAE,CACrC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;QACb,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE;YACP,WAAW,EAAE,4BAA4B;YACzC,UAAU,EAAE,EAAE;SACf;KACF,CAAC,CAAC;CACN,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,4CAA4C,EAAE,GAAG,EAAE;IAC1D,UAAU,CAAC,GAAG,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from \"zod\";\nimport { TamboInteractableComponent } from \"../model/tambo-interactable\";\nimport {\n TamboInteractableProvider,\n useTamboInteractable,\n} from \"./tambo-interactable-provider\";\n\n// Mock the context helpers\nconst mockAddContextHelper = jest.fn();\nconst mockRemoveContextHelper = jest.fn();\n\njest.mock(\"./tambo-context-helpers-provider\", () => ({\n TamboContextHelpersProvider: ({\n children,\n }: {\n children: React.ReactNode;\n }) => <>{children}</>,\n useTamboContextHelpers: () => ({\n addContextHelper: mockAddContextHelper,\n removeContextHelper: mockRemoveContextHelper,\n }),\n}));\n\n// Mock the component provider\nconst mockRegisterTool = jest.fn();\n\njest.mock(\"./tambo-component-provider\", () => ({\n useTamboComponent: () => ({\n registerTool: mockRegisterTool,\n }),\n}));\n\n// Mock the context helper creation\njest.mock(\"../context-helpers/current-interactables-context-helper\", () => ({\n createInteractablesContextHelper: () =>\n jest.fn(() => ({\n name: \"interactables\",\n context: {\n description: \"Test interactables context\",\n components: [],\n },\n })),\n}));\n\ndescribe(\"TamboInteractableProvider - State Tracking\", () => {\n beforeEach(() => {\n jest.clearAllMocks();\n });\n\n const wrapper = ({ children }: { children: React.ReactNode }) => (\n <TamboInteractableProvider>{children}</TamboInteractableProvider>\n );\n\n it(\"should set and get state for a component\", () => {\n const { result } = renderHook(() => useTamboInteractable(), { wrapper });\n\n const component: Omit<TamboInteractableComponent, \"id\" | \"createdAt\"> = {\n name: \"TestComponent\",\n description: \"A test component\",\n component: () => <div>Test</div>,\n props: { title: \"Test\" },\n propsSchema: z.object({ title: z.string() }),\n };\n\n let componentId = \"\";\n act(() => {\n componentId = result.current.addInteractableComponent(component);\n });\n\n act(() => {\n result.current.setInteractableState(componentId, \"count\", 10);\n });\n\n const state = result.current.getInteractableComponentState(componentId);\n expect(state).toEqual({ count: 10 });\n });\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,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AQ,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,CAQjE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,YAAY,CAoB5E;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,iKAElD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,yEAWjD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,OAWpD;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,OAmBpD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,OAAO,CAE/D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,QAAQ,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,OAAO,GAAG,QAAQ,CAczE"}
@@ -89,12 +89,12 @@ function getZodFunctionReturns(schema) {
89
89
  function handleZodSchemaToJson(schema) {
90
90
  // If Zod4 schema detected, use the toJSONSchema function from "zod/v4/core"
91
91
  if (isZod4Schema(schema))
92
- return (0, core_1.toJSONSchema)(schema);
92
+ return (0, core_1.toJSONSchema)(schema, { reused: "inline" });
93
93
  try {
94
94
  // Dynamic require for optional peer dependency
95
95
  // eslint-disable-next-line @typescript-eslint/no-require-imports -- need require because zod-to-json-schema may be missing
96
96
  const { zodToJsonSchema } = require("zod-to-json-schema");
97
- return zodToJsonSchema(schema);
97
+ return zodToJsonSchema(schema, { $refStrategy: "none" });
98
98
  }
99
99
  catch (error) {
100
100
  throw new Error("Zod 3 requires 'zod-to-json-schema' package for JSON Schema conversion. " +
@@ -109,7 +109,7 @@ function handleZodSchemaToJson(schema) {
109
109
  * @returns True if the schema looks like a Zod 3 schema
110
110
  */
111
111
  function isZod3Schema(schema) {
112
- return isZodSchema(schema) && "_def" in schema;
112
+ return isZodSchema(schema) && "_def" in schema && !("def" in schema);
113
113
  }
114
114
  /**
115
115
  * Detects if a schema is Zod 4 by checking for def.type property.
@@ -1 +1 @@
1
- {"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":";;AAgBA,oDAUC;AAKD,oDAoBC;AAOD,kDAEC;AAOD,gDAWC;AAOD,sDAWC;AAQD,sDAkBC;AAOD,oCAEC;AAOD,oCAEC;AAOD,kCAcC;AA1JD,sCAIqB;AAErB;;GAEG;AACH,SAAgB,oBAAoB,CAClC,MAAe;IAEf,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IAEvC,OAAO,CACL,MAAM,IAAI,MAAM;QAChB,UAAU,IAAI,MAAM,CAAC,IAAI;QACzB,MAAM,CAAC,IAAI,CAAC,QAAQ,KAAK,aAAa,CACvC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,MAAe;IAClD,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,2EAA2E;IAC3E,6EAA6E;IAC7E,4EAA4E;IAC5E,8CAA8C;IAC9C,gIAAgI;IAChI,IAAI,KAAK,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;QACpE,IAAK,MAAM,CAAC,GAAwB,EAAE,IAAI,KAAK,UAAU,EAAE,CAAC;YAC1D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,8EAA8E;IAC9E,6EAA6E;IAC7E,mDAAmD;IACnD,OAAQ,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,IAAe,KAAK,UAAU,CAAC;AAC3D,CAAC;AAED;;;;GA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ONSchema as zod4ToJSONSchema,\n} from \"zod/v4/core\";\n\n/**\n * @returns True if the schema is a Zod 3 function schema\n */\nexport function isZod3FunctionSchema(\n schema: unknown,\n): schema is ZodFunction<ZodTuple<ZodTupleItems, any>, ZodTypeAny> {\n if (!isZodSchema(schema)) return false;\n\n return (\n \"_def\" in schema &&\n \"typeName\" in schema._def &&\n schema._def.typeName === \"ZodFunction\"\n );\n}\n\n/**\n * @returns True if the schema is a Zod 4 function schema\n */\nexport function isZod4FunctionSchema(schema: unknown): schema is $ZodFunction {\n if (!isZod4Schema(schema)) {\n return false;\n }\n\n // $ZodFunctions in zod 4.0 most certainly do have .def.type === \"function\"\n // but the type definitions do not reflect this because $ZodFunction does not\n // extend $ZodType. This is corrected in zod 4.1, but zod 3 does not include\n // the types for 4.1 yet (and might not ever).\n // See: https://github.com/colinhacks/zod/blob/463f03eb8183dcdcdf735b180f2bf40883e66220/packages/zod/src/v4/core/function.ts#L48\n if (\"def\" in schema && typeof schema.def !== \"object\" && schema.def) {\n if ((schema.def as { type: string })?.type === \"function\") {\n return true;\n }\n }\n\n // We're casting as string here because zod 4.0 types don't include \"function\"\n // literal in the union for `_zod.def.type`. The optional chaining is because\n // _zod does not exist on zod 4 objects from zod 3.\n return (schema._zod?.def?.type as string) === \"function\";\n}\n\n/**\n * Checks if a schema is a Zod function schema (Zod 3 or Zod 4).\n * @param schema - The schema to check\n * @returns True if the schema is a Zod function schema\n */\nexport function isZodFunctionSchema(schema: unknown) {\n return isZod3FunctionSchema(schema) || isZod4FunctionSchema(schema);\n}\n\n/**\n * Extracts the args schema from a Zod function schema.\n * @param schema - The Zod function schema\n * @returns The args schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionArgs(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.args;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4.0\n return schema?.def?.input ?? schema._zod?.def?.input;\n }\n\n throw new Error(\"Unable to determine parameters from zod function schema\");\n}\n\n/**\n * Extracts the return schema from a Zod 3 or Zod 4 function schema.\n * @param schema - The Zod function schema\n * @returns The return schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionReturns(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.returns;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4\n return schema._zod.def.output;\n }\n\n throw new Error(\"Unable to determine return type from zod function schema\");\n}\n\n/**\n * Handles conversion of Zod schemas to JSON Schema.\n * Supports both Zod 3 (via zod-to-json-schema) and Zod 4 (native).\n * @param schema - The Zod schema to convert\n * @returns The JSON Schema representation\n */\nexport function handleZodSchemaToJson(schema: unknown) {\n // If Zod4 schema detected, use the toJSONSchema function from \"zod/v4/core\"\n if (isZod4Schema(schema)) return zod4ToJSONSchema(schema);\n\n try {\n // Dynamic require for optional peer dependency\n // eslint-disable-next-line @typescript-eslint/no-require-imports -- need require because zod-to-json-schema may be missing\n const { zodToJsonSchema } = require(\"zod-to-json-schema\");\n return zodToJsonSchema(schema);\n } catch (error) {\n throw new Error(\n \"Zod 3 requires 'zod-to-json-schema' package for JSON Schema conversion. \" +\n \"Install it with: npm install zod-to-json-schema\",\n {\n cause: error,\n },\n );\n }\n}\n\n/**\n * Checks if a schema is probably a Zod 3 schema.\n * @param schema - The schema to check\n * @returns True if the schema looks like a Zod 3 schema\n */\nexport function isZod3Schema(schema: unknown): schema is ZodType {\n return isZodSchema(schema) && \"_def\" in schema;\n}\n\n/**\n * Detects if a schema is Zod 4 by checking for def.type property.\n * Zod 4 uses `def.type` with lowercase type names like \"object\", \"string\".\n * @returns True if the schema appears to be Zod 4 style\n */\nexport function isZod4Schema(schema: unknown): schema is $ZodType {\n return isZodSchema(schema) && \"_zod\" in schema;\n}\n\n/**\n * Checks if a schema is a Zod schema\n * @param schema - The schema to check\n * @returns True if the schema is a Zod schema\n */\nexport function isZodSchema(schema: unknown): schema is ZodType | $ZodType {\n // schema must be { ~standard: { vendor: \"zod\" } }\n if (typeof schema !== \"object\") return false;\n if (!schema) return false;\n if (!(\"~standard\" in schema)) return false;\n if (!schema[\"~standard\"]) return false;\n if (typeof schema[\"~standard\"] !== \"object\") return false;\n if (!(\"vendor\" in schema[\"~standard\"])) return false;\n if (schema[\"~standard\"].vendor !== \"zod\") return false;\n\n // Require at least one internal marker to reduce false positives\n const looksLikeV3 = \"_def\" in schema;\n const looksLikeV4 = \"_zod\" in schema || \"def\" in schema;\n return looksLikeV3 || looksLikeV4;\n}\n"]}
1
+ {"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":";;AAgBA,oDAUC;AAKD,oDAoBC;AAOD,kDAEC;AAOD,gDAWC;AAOD,sDAWC;AAQD,sDAmBC;AAOD,oCAEC;AAOD,oCAEC;AAOD,kCAcC;AA3JD,sCAIqB;AAErB;;GAEG;AACH,SAAgB,oBAAoB,CAClC,MAAe;IAEf,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IAEvC,OAAO,CACL,MAAM,IAAI,MAAM;QAChB,UAAU,IAAI,MAAM,CAAC,IAAI;QACzB,MAAM,CAAC,IAAI,CAAC,QAAQ,KAAK,aAAa,CACvC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,MAAe;IAClD,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,2EAA2E;IAC3E,6EAA6E;IAC7E,4EAA4E;IAC5E,8CAA8C;IAC9C,gIAAgI;IAChI,IAAI,KAAK,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;QACpE,IAAK,MAAM,CAAC,GAAwB,EAAE,IAAI,KAAK,UAAU,EAAE,CAAC;YAC1D,OAAO,IAAI,CAAC;QACd,CAAC;IAC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AG,MAAM,IAAI,MAAM,CAAC;IACrC,MAAM,WAAW,GAAG,MAAM,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,CAAC;IACxD,OAAO,WAAW,IAAI,WAAW,CAAC;AACpC,CAAC","sourcesContent":["import {\n ZodFunction,\n ZodTuple,\n ZodTupleItems,\n ZodType,\n ZodTypeAny,\n} from \"zod/v3\";\nimport {\n $ZodFunction,\n $ZodType,\n toJSONSchema as zod4ToJSONSchema,\n} from \"zod/v4/core\";\n\n/**\n * @returns True if the schema is a Zod 3 function schema\n */\nexport function isZod3FunctionSchema(\n schema: unknown,\n): schema is ZodFunction<ZodTuple<ZodTupleItems, any>, ZodTypeAny> {\n if (!isZodSchema(schema)) return false;\n\n return (\n \"_def\" in schema &&\n \"typeName\" in schema._def &&\n schema._def.typeName === \"ZodFunction\"\n );\n}\n\n/**\n * @returns True if the schema is a Zod 4 function schema\n */\nexport function isZod4FunctionSchema(schema: unknown): schema is $ZodFunction {\n if (!isZod4Schema(schema)) {\n return false;\n }\n\n // $ZodFunctions in zod 4.0 most certainly do have .def.type === \"function\"\n // but the type definitions do not reflect this because $ZodFunction does not\n // extend $ZodType. This is corrected in zod 4.1, but zod 3 does not include\n // the types for 4.1 yet (and might not ever).\n // See: https://github.com/colinhacks/zod/blob/463f03eb8183dcdcdf735b180f2bf40883e66220/packages/zod/src/v4/core/function.ts#L48\n if (\"def\" in schema && typeof schema.def !== \"object\" && schema.def) {\n if ((schema.def as { type: string })?.type === \"function\") {\n return true;\n }\n }\n\n // We're casting as string here because zod 4.0 types don't include \"function\"\n // literal in the union for `_zod.def.type`. The optional chaining is because\n // _zod does not exist on zod 4 objects from zod 3.\n return (schema._zod?.def?.type as string) === \"function\";\n}\n\n/**\n * Checks if a schema is a Zod function schema (Zod 3 or Zod 4).\n * @param schema - The schema to check\n * @returns True if the schema is a Zod function schema\n */\nexport function isZodFunctionSchema(schema: unknown) {\n return isZod3FunctionSchema(schema) || isZod4FunctionSchema(schema);\n}\n\n/**\n * Extracts the args schema from a Zod function schema.\n * @param schema - The Zod function schema\n * @returns The args schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionArgs(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.args;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4.0\n return schema?.def?.input ?? schema._zod?.def?.input;\n }\n\n throw new Error(\"Unable to determine parameters from zod function schema\");\n}\n\n/**\n * Extracts the return schema from a Zod 3 or Zod 4 function schema.\n * @param schema - The Zod function schema\n * @returns The return schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionReturns(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.returns;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4\n return schema._zod.def.output;\n }\n\n throw new Error(\"Unable to determine return type from zod function schema\");\n}\n\n/**\n * Handles conversion of Zod schemas to JSON Schema.\n * Supports both Zod 3 (via zod-to-json-schema) and Zod 4 (native).\n * @param schema - The Zod schema to convert\n * @returns The JSON Schema representation\n */\nexport function handleZodSchemaToJson(schema: unknown) {\n // If Zod4 schema detected, use the toJSONSchema function from \"zod/v4/core\"\n if (isZod4Schema(schema))\n return zod4ToJSONSchema(schema, { reused: \"inline\" });\n\n try {\n // Dynamic require for optional peer dependency\n // eslint-disable-next-line @typescript-eslint/no-require-imports -- need require because zod-to-json-schema may be missing\n const { zodToJsonSchema } = require(\"zod-to-json-schema\");\n return zodToJsonSchema(schema, { $refStrategy: \"none\" });\n } catch (error) {\n throw new Error(\n \"Zod 3 requires 'zod-to-json-schema' package for JSON Schema conversion. \" +\n \"Install it with: npm install zod-to-json-schema\",\n {\n cause: error,\n },\n );\n }\n}\n\n/**\n * Checks if a schema is probably a Zod 3 schema.\n * @param schema - The schema to check\n * @returns True if the schema looks like a Zod 3 schema\n */\nexport function isZod3Schema(schema: unknown): schema is ZodType {\n return isZodSchema(schema) && \"_def\" in schema && !(\"def\" in schema);\n}\n\n/**\n * Detects if a schema is Zod 4 by checking for def.type property.\n * Zod 4 uses `def.type` with lowercase type names like \"object\", \"string\".\n * @returns True if the schema appears to be Zod 4 style\n */\nexport function isZod4Schema(schema: unknown): schema is $ZodType {\n return isZodSchema(schema) && \"_zod\" in schema;\n}\n\n/**\n * Checks if a schema is a Zod schema\n * @param schema - The schema to check\n * @returns True if the schema is a Zod schema\n */\nexport function isZodSchema(schema: unknown): schema is ZodType | $ZodType {\n // schema must be { ~standard: { vendor: \"zod\" } }\n if (typeof schema !== \"object\") return false;\n if (!schema) return false;\n if (!(\"~standard\" in schema)) return false;\n if (!schema[\"~standard\"]) return false;\n if (typeof schema[\"~standard\"] !== \"object\") return false;\n if (!(\"vendor\" in schema[\"~standard\"])) return false;\n if (schema[\"~standard\"].vendor !== \"zod\") return false;\n\n // Require at least one internal marker to reduce false positives\n const looksLikeV3 = \"_def\" in schema;\n const looksLikeV4 = \"_zod\" in schema || \"def\" in schema;\n return looksLikeV3 || looksLikeV4;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=zod.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod.test.d.ts","sourceRoot":"","sources":["../../src/schema/zod.test.ts"],"names":[],"mappings":""}