@tambo-ai/react 0.29.1 → 0.30.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 (81) hide show
  1. package/dist/hooks/use-component-state.d.ts.map +1 -1
  2. package/dist/hooks/use-component-state.js +1 -0
  3. package/dist/hooks/use-component-state.js.map +1 -1
  4. package/dist/hooks/use-current-message.d.ts.map +1 -1
  5. package/dist/hooks/use-current-message.js +1 -0
  6. package/dist/hooks/use-current-message.js.map +1 -1
  7. package/dist/hooks/use-streaming-props.d.ts.map +1 -1
  8. package/dist/hooks/use-streaming-props.js +1 -0
  9. package/dist/hooks/use-streaming-props.js.map +1 -1
  10. package/dist/hooks/use-suggestions.d.ts.map +1 -1
  11. package/dist/hooks/use-suggestions.js +1 -0
  12. package/dist/hooks/use-suggestions.js.map +1 -1
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +2 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/providers/__tests__/tambo-stubs.test.d.ts +2 -0
  18. package/dist/providers/__tests__/tambo-stubs.test.d.ts.map +1 -0
  19. package/dist/providers/__tests__/tambo-stubs.test.js +93 -0
  20. package/dist/providers/__tests__/tambo-stubs.test.js.map +1 -0
  21. package/dist/providers/index.d.ts +1 -0
  22. package/dist/providers/index.d.ts.map +1 -1
  23. package/dist/providers/index.js +3 -1
  24. package/dist/providers/index.js.map +1 -1
  25. package/dist/providers/tambo-client-provider.d.ts +1 -0
  26. package/dist/providers/tambo-client-provider.d.ts.map +1 -1
  27. package/dist/providers/tambo-client-provider.js +6 -5
  28. package/dist/providers/tambo-client-provider.js.map +1 -1
  29. package/dist/providers/tambo-provider.d.ts +8 -0
  30. package/dist/providers/tambo-provider.d.ts.map +1 -1
  31. package/dist/providers/tambo-provider.js +4 -3
  32. package/dist/providers/tambo-provider.js.map +1 -1
  33. package/dist/providers/tambo-registry-provider.d.ts +1 -0
  34. package/dist/providers/tambo-registry-provider.d.ts.map +1 -1
  35. package/dist/providers/tambo-registry-provider.js +4 -4
  36. package/dist/providers/tambo-registry-provider.js.map +1 -1
  37. package/dist/providers/tambo-stubs.d.ts +85 -0
  38. package/dist/providers/tambo-stubs.d.ts.map +1 -0
  39. package/dist/providers/tambo-stubs.js +248 -0
  40. package/dist/providers/tambo-stubs.js.map +1 -0
  41. package/esm/hooks/use-component-state.d.ts.map +1 -1
  42. package/esm/hooks/use-component-state.js +1 -0
  43. package/esm/hooks/use-component-state.js.map +1 -1
  44. package/esm/hooks/use-current-message.d.ts.map +1 -1
  45. package/esm/hooks/use-current-message.js +1 -0
  46. package/esm/hooks/use-current-message.js.map +1 -1
  47. package/esm/hooks/use-streaming-props.d.ts.map +1 -1
  48. package/esm/hooks/use-streaming-props.js +1 -0
  49. package/esm/hooks/use-streaming-props.js.map +1 -1
  50. package/esm/hooks/use-suggestions.d.ts.map +1 -1
  51. package/esm/hooks/use-suggestions.js +1 -0
  52. package/esm/hooks/use-suggestions.js.map +1 -1
  53. package/esm/index.d.ts +1 -1
  54. package/esm/index.d.ts.map +1 -1
  55. package/esm/index.js +1 -1
  56. package/esm/index.js.map +1 -1
  57. package/esm/providers/__tests__/tambo-stubs.test.d.ts +2 -0
  58. package/esm/providers/__tests__/tambo-stubs.test.d.ts.map +1 -0
  59. package/esm/providers/__tests__/tambo-stubs.test.js +58 -0
  60. package/esm/providers/__tests__/tambo-stubs.test.js.map +1 -0
  61. package/esm/providers/index.d.ts +1 -0
  62. package/esm/providers/index.d.ts.map +1 -1
  63. package/esm/providers/index.js +1 -0
  64. package/esm/providers/index.js.map +1 -1
  65. package/esm/providers/tambo-client-provider.d.ts +1 -0
  66. package/esm/providers/tambo-client-provider.d.ts.map +1 -1
  67. package/esm/providers/tambo-client-provider.js +2 -1
  68. package/esm/providers/tambo-client-provider.js.map +1 -1
  69. package/esm/providers/tambo-provider.d.ts +8 -0
  70. package/esm/providers/tambo-provider.d.ts.map +1 -1
  71. package/esm/providers/tambo-provider.js +1 -1
  72. package/esm/providers/tambo-provider.js.map +1 -1
  73. package/esm/providers/tambo-registry-provider.d.ts +1 -0
  74. package/esm/providers/tambo-registry-provider.d.ts.map +1 -1
  75. package/esm/providers/tambo-registry-provider.js +1 -1
  76. package/esm/providers/tambo-registry-provider.js.map +1 -1
  77. package/esm/providers/tambo-stubs.d.ts +85 -0
  78. package/esm/providers/tambo-stubs.d.ts.map +1 -0
  79. package/esm/providers/tambo-stubs.js +211 -0
  80. package/esm/providers/tambo-stubs.js.map +1 -0
  81. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAA4E;AAC5E,mEAMiC;AACjC,yEAIoC;AACpC,uEAGmC;AACnC,mEAKiC;AAEjC;;;;;;;;;;;;GAYG;AACI,MAAM,aAAa,GAMtB,CAAC,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,UAAU,EACV,WAAW,EACX,KAAK,EACL,SAAS,GACV,EAAE,EAAE;IACH,iCAAiC;IACjC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,CACL,8BAAC,2CAAmB,IAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW;QAExB,8BAAC,+CAAqB,IAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK;YACzD,8BAAC,2CAAmB,IAAC,SAAS,EAAE,SAAS;gBACvC,8BAAC,iDAAsB;oBACrB,8BAAC,sBAAsB,QAAE,QAAQ,CAA0B,CACpC,CACL,CACA,CACJ,CACvB,CAAC;AACJ,CAAC,CAAC;AAnCW,QAAA,aAAa,iBAmCxB;AAKW,QAAA,YAAY,GAAG,IAAA,qBAAa,EACvC,EAAuB,CACxB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,sBAAsB,GAAgC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC3E,MAAM,OAAO,GAAG,IAAA,sCAAc,GAAE,CAAC;IACjC,MAAM,MAAM,GAAG,IAAA,sCAAc,GAAE,CAAC;IAChC,MAAM,WAAW,GAAG,IAAA,2CAAmB,GAAE,CAAC;IAC1C,MAAM,iBAAiB,GAAG,IAAA,4CAAiB,GAAE,CAAC;IAE9C,OAAO,CACL,8BAAC,oBAAY,CAAC,QAAQ,IACpB,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,GAAG,iBAAiB;YACpB,GAAG,OAAO;SACX,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACI,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,IAAA,kBAAU,EAAC,oBAAY,CAAC,CAAC;AAClC,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB","sourcesContent":["\"use client\";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useTamboClient,\n useTamboQueryClient,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport {\n TamboThreadContextProps,\n TamboThreadProvider,\n TamboThreadProviderProps,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/**\n * The TamboProvider gives full access to the whole Tambo API. This includes the\n * TamboAI client, the component registry, and the current thread context.\n * @param props - The props for the TamboProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.components - The components to register\n * @param props.environment - The environment to use for the Tambo API\n * @param props.tools - The tools to register\n * @param props.streaming - Whether to stream the response by default. Defaults to true.\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n components,\n environment,\n tools,\n streaming,\n}) => {\n // Should only be used in browser\n if (typeof window === \"undefined\") {\n console.error(\"TamboProvider must be used within a browser\");\n }\n\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n >\n <TamboRegistryProvider components={components} tools={tools}>\n <TamboThreadProvider streaming={streaming}>\n <TamboComponentProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboComponentProvider>\n </TamboThreadProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboComponentContextProps;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, and TamboComponent providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nconst TamboCompositeProvider: React.FC<PropsWithChildren> = ({ children }) => {\n const threads = useTamboThread();\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const componentRegistry = useTamboComponent();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n ...componentRegistry,\n ...threads,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\n/**\n * The useTambo hook provides access to the Tambo API. This is the primary entrypoint\n * for the Tambo React SDK.\n *\n * This includes the TamboAI client, the component registry, and the current thread context.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
1
+ {"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;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AEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AApBW,QAAA,sBAAsB,0BAoBjC;AAEF;;;;;;GAMG;AACI,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,IAAA,kBAAU,EAAC,oBAAY,CAAC,CAAC;AAClC,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB","sourcesContent":["\"use client\";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useTamboClient,\n useTamboQueryClient,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport {\n TamboThreadContextProps,\n TamboThreadProvider,\n TamboThreadProviderProps,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/**\n * The TamboProvider gives full access to the whole Tambo API. This includes the\n * TamboAI client, the component registry, and the current thread context.\n * @param props - The props for the TamboProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.components - The components to register\n * @param props.environment - The environment to use for the Tambo API\n * @param props.tools - The tools to register\n * @param props.streaming - Whether to stream the response by default. Defaults to true.\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n components,\n environment,\n tools,\n streaming,\n}) => {\n // Should only be used in browser\n if (typeof window === \"undefined\") {\n console.error(\"TamboProvider must be used within a browser\");\n }\n\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n >\n <TamboRegistryProvider components={components} tools={tools}>\n <TamboThreadProvider streaming={streaming}>\n <TamboComponentProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboComponentProvider>\n </TamboThreadProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboComponentContextProps;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, and TamboComponent providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nexport const TamboCompositeProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const threads = useTamboThread();\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const componentRegistry = useTamboComponent();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n ...componentRegistry,\n ...threads,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\n/**\n * The useTambo hook provides access to the Tambo API. This is the primary entrypoint\n * for the Tambo React SDK.\n *\n * This includes the TamboAI client, the component registry, and the current thread context.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
@@ -9,6 +9,7 @@ export interface TamboRegistryContext {
9
9
  registerTools: (tools: TamboTool[]) => void;
10
10
  addToolAssociation: (componentName: string, tool: TamboTool) => void;
11
11
  }
12
+ export declare const TamboRegistryContext: React.Context<TamboRegistryContext>;
12
13
  export interface TamboRegistryProviderProps {
13
14
  /** The components to register */
14
15
  components?: TamboComponent[];
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-registry-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAGf,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,SAAS,EACV,MAAM,6BAA6B,CAAC;AAErC,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,iBAAiB,CAAC;IACjC,Y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IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACxC,aAAa,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;IAC5C,kBAAkB,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;CACtE;AAED,eAAO,MAAM,oBAAoB,qCAoB/B,CAAC;AAEH,MAAM,WAAW,0BAA0B;IACzC,iCAAiC;IACjC,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,4BAA4B;IAC5B,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAC1C,iBAAiB,CAAC,0BAA0B,CAAC,CAiI9C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,4BAE5B,CAAC"}
@@ -37,11 +37,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.useTamboRegistry = exports.TamboRegistryProvider = void 0;
40
+ exports.useTamboRegistry = exports.TamboRegistryProvider = exports.TamboRegistryContext = void 0;
41
41
  const react_1 = __importStar(require("react"));
42
42
  const zod_1 = require("zod");
43
43
  const zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
44
- const TamboRegistryContext = (0, react_1.createContext)({
44
+ exports.TamboRegistryContext = (0, react_1.createContext)({
45
45
  componentList: {},
46
46
  toolRegistry: {},
47
47
  componentToolAssociations: {},
@@ -155,7 +155,7 @@ const TamboRegistryProvider = ({ children, components: userComponents, tools: us
155
155
  registerTools,
156
156
  addToolAssociation,
157
157
  };
158
- return (react_1.default.createElement(TamboRegistryContext.Provider, { value: value }, children));
158
+ return (react_1.default.createElement(exports.TamboRegistryContext.Provider, { value: value }, children));
159
159
  };
160
160
  exports.TamboRegistryProvider = TamboRegistryProvider;
161
161
  /**
@@ -164,7 +164,7 @@ exports.TamboRegistryProvider = TamboRegistryProvider;
164
164
  * @returns The component registry
165
165
  */
166
166
  const useTamboRegistry = () => {
167
- return (0, react_1.useContext)(TamboRegistryContext);
167
+ return (0, react_1.useContext)(exports.TamboRegistryContext);
168
168
  };
169
169
  exports.useTamboRegistry = useTamboRegistry;
170
170
  function getSerializedProps(propsDefinition, propsSchema, name) {
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-registry-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAOe;AACf,6BAAgC;AAChC,4EAAiD;AAiBjD,MAAM,oBAAoB,GAAG,IAAA,qBAAa,EAAuB;IAC/D,aAAa,EAAE,EAAE;IACjB,YAAY,EAAE,EAAE;IAChB,yBAAyB,EAAE,EAAE;IAC7B;;OAEG;IACH,iBAAiB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC3B;;OAEG;IACH,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;IACtB;;OAEG;IACH,aAAa,EAAE,GAAG,EAAE,GAAE,CAAC;IACvB;;OAEG;IACH,kBAAkB,EAAE,GAAG,EAAE,GAAE,CAAC;CAC7B,CAAC,CAAC;AASH;;;;;;;;GAQG;AACI,MAAM,qBAAqB,GAE9B,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE;IACjE,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,IAAA,gBAAQ,EAAoB,EAAE,CAAC,CAAC;IAC1E,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,IAAA,gBAAQ,EAC9C,EAAE,CACH,CAAC;IACF,MAAM,CAAC,yBAAyB,EAAE,4BAA4B,CAAC,GAAG,IAAA,gBAAQ,EAExE,EAAE,CAAC,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,oBAAoB,IAAI,+BAA+B,EACvD,KAAK,CACN,CAAC;QACJ,CAAC;IACH,CAAC;IACD,qFAAqF;IACrF,IAAI,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;QAC9B,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,WAAgB;IACpC,OAAO,CACL,WAAW;QACX,OAAO,WAAW,KAAK,QAAQ;QAC/B,WAAW,CAAC,IAAI,KAAK,QAAQ;QAC7B,WAAW,CAAC,UAAU,CACvB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,IAAI,GAAG,YAAY,eAAS,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,6CAA6C;IAC7C,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI;QACZ,OAAQ,GAAW,CAAC,SAAS,KAAK,UAAU;QAC5C,OAAQ,GAAW,CAAC,IAAI,KAAK,QAAQ,CACtC,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport { ZodSchema } from \"zod\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport {\n ComponentRegistry,\n TamboComponent,\n TamboTool,\n} from \"../model/component-metadata\";\n\nexport interface TamboRegistryContext {\n componentList: ComponentRegistry;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n}\n\nconst TamboRegistryContext = createContext<TamboRegistryContext>({\n componentList: {},\n toolRegistry: {},\n componentToolAssociations: {},\n /**\n *\n */\n registerComponent: () => {},\n /**\n *\n */\n registerTool: () => {},\n /**\n *\n */\n registerTools: () => {},\n /**\n *\n */\n addToolAssociation: () => {},\n});\n\nexport interface TamboRegistryProviderProps {\n /** The components to register */\n components?: TamboComponent[];\n /** The tools to register */\n tools?: TamboTool[];\n}\n\n/**\n * The TamboRegistryProvider is a React provider that provides a component\n * registry to the descendants of the provider.\n * @param props - The props for the TamboRegistryProvider\n * @param props.children - The children to wrap\n * @param props.components - The components to register\n * @param props.tools - The tools to register\n * @returns The TamboRegistryProvider component\n */\nexport const TamboRegistryProvider: React.FC<\n PropsWithChildren<TamboRegistryProviderProps>\n> = ({ children, components: userComponents, tools: userTools }) => {\n const [componentList, setComponentList] = useState<ComponentRegistry>({});\n const [toolRegistry, setToolRegistry] = useState<Record<string, TamboTool>>(\n {},\n );\n const [componentToolAssociations, setComponentToolAssociations] = useState<\n Record<string, string[]>\n >({});\n\n const registerTool = useCallback(\n (tool: TamboTool, warnOnOverwrite = true) => {\n setToolRegistry((prev) => {\n if (prev[tool.name] && warnOnOverwrite) {\n console.warn(`Overwriting tool ${tool.name}`);\n }\n return {\n ...prev,\n [tool.name]: tool,\n };\n });\n },\n [],\n );\n\n const registerTools = useCallback(\n (tools: TamboTool[], warnOnOverwrite = true) => {\n tools.forEach((tool) => registerTool(tool, warnOnOverwrite));\n },\n [registerTool],\n );\n\n const addToolAssociation = useCallback(\n (componentName: string, tool: TamboTool) => {\n if (!componentList[componentName]) {\n throw new Error(`Component ${componentName} not found in registry`);\n }\n setComponentToolAssociations((prev) => ({\n ...prev,\n [componentName]: [...(prev[componentName] || []), tool.name],\n }));\n },\n [componentList],\n );\n\n const registerComponent = useCallback(\n (options: TamboComponent, warnOnOverwrite = true) => {\n const {\n name,\n description,\n component,\n propsSchema,\n propsDefinition,\n loadingComponent,\n associatedTools,\n } = options;\n\n // Validate that at least one props definition is provided\n if (!propsSchema && !propsDefinition) {\n throw new Error(\n `Component ${name} must have either propsSchema (recommended) or propsDefinition defined`,\n );\n }\n\n // Validate that only one props definition is provided\n if (propsSchema && propsDefinition) {\n throw new Error(\n `Component ${name} cannot have both propsSchema and propsDefinition defined. Use only one. We recommend using propsSchema.`,\n );\n }\n\n // Convert propsSchema to JSON Schema if it exists\n const props = getSerializedProps(propsDefinition, propsSchema, name);\n\n setComponentList((prev) => {\n if (prev[name] && warnOnOverwrite) {\n console.warn(`overwriting component ${name}`);\n }\n return {\n ...prev,\n [name]: {\n component,\n loadingComponent,\n name,\n description,\n props,\n contextTools: [],\n },\n };\n });\n if (associatedTools) {\n registerTools(associatedTools);\n setComponentToolAssociations((prev) => ({\n ...prev,\n [name]: associatedTools.map((tool) => tool.name),\n }));\n }\n },\n [registerTools],\n );\n useEffect(() => {\n if (userComponents) {\n userComponents.forEach((component) => {\n registerComponent(component, false);\n });\n }\n }, [registerComponent, userComponents]);\n\n useEffect(() => {\n if (userTools) {\n registerTools(userTools, false);\n }\n }, [registerTools, userTools]);\n\n const value = {\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n };\n\n return (\n <TamboRegistryContext.Provider value={value}>\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * The useTamboRegistry hook provides access to the component registry\n * to the descendants of the TamboRegistryProvider.\n * @returns The component registry\n */\nexport const useTamboRegistry = () => {\n return useContext(TamboRegistryContext);\n};\nfunction getSerializedProps(\n propsDefinition: any,\n propsSchema: any,\n name: string,\n) {\n if (propsDefinition) {\n console.warn(`propsDefinition is deprecated. Use propsSchema instead.`);\n return propsDefinition;\n }\n\n if (isZodSchema(propsSchema)) {\n try {\n return zodToJsonSchema(propsSchema);\n } catch (error) {\n console.error(\n `Error converting ${name} props schema to JSON Schema:`,\n error,\n );\n }\n }\n // try to roughly detect JSONSchema, should always be an object with a properties key\n if (isJSONSchema(propsSchema)) {\n return propsSchema;\n }\n\n throw new Error(`Invalid props schema for ${name}`);\n}\n\n/**\n * Checks if the propsSchema is a JSON Schema. This is a rough check, and the\n * server will provide the definitive check.\n * @param propsSchema - The props schema to check\n * @returns True if the props schema is a JSON Schema, false otherwise\n */\nfunction isJSONSchema(propsSchema: any) {\n return (\n propsSchema &&\n typeof propsSchema === \"object\" &&\n propsSchema.type === \"object\" &&\n propsSchema.properties\n );\n}\n\n/**\n * Since we require a certain zod version, we need to check if the object is a ZodSchema\n * @param obj - The object to check\n * @returns True if the object is a ZodSchema, false otherwise\n */\nfunction isZodSchema(obj: unknown): obj is ZodSchema {\n if (obj instanceof ZodSchema) {\n return true;\n }\n // try to detect if the object is a ZodSchema\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n typeof (obj as any).safeParse === \"function\" &&\n typeof (obj as any)._def === \"object\"\n );\n}\n"]}
1
+ {"version":3,"file":"tambo-registry-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAOe;AACf,6BAAgC;AAChC,4EAAiD;AAiBpC,QAAA,oBAAoB,GAAG,IAAA,qBAAa,EAAuB;IACtE,aAAa,EAAE,EAAE;IACjB,YAAY,EAAE,EAAE;IAChB,yBAAyB,EAAE,EAAE;IAC7B;;OAEG;IACH,iBAAiB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC3B;;OAEG;IACH,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;IACtB;;OAEG;IACH,aAAa,EAAE,GAAG,EAAE,GAAE,CAAC;IACvB;;OAEG;IACH,kBAAkB,EAAE,GAAG,EAAE,GAAE,CAAC;CAC7B,CAAC,CAAC;AASH;;;;;;;;GAQG;AACI,MAAM,qBAAqB,GAE9B,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE;IACjE,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,IAAA,gBAAQ,EAAoB,EA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AAC;IAED,IAAI,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,OAAO,IAAA,4BAAe,EAAC,WAAW,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,oBAAoB,IAAI,+BAA+B,EACvD,KAAK,CACN,CAAC;QACJ,CAAC;IACH,CAAC;IACD,qFAAqF;IACrF,IAAI,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;QAC9B,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,WAAgB;IACpC,OAAO,CACL,WAAW;QACX,OAAO,WAAW,KAAK,QAAQ;QAC/B,WAAW,CAAC,IAAI,KAAK,QAAQ;QAC7B,WAAW,CAAC,UAAU,CACvB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,IAAI,GAAG,YAAY,eAAS,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,6CAA6C;IAC7C,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI;QACZ,OAAQ,GAAW,CAAC,SAAS,KAAK,UAAU;QAC5C,OAAQ,GAAW,CAAC,IAAI,KAAK,QAAQ,CACtC,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport { ZodSchema } from \"zod\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport {\n ComponentRegistry,\n TamboComponent,\n TamboTool,\n} from \"../model/component-metadata\";\n\nexport interface TamboRegistryContext {\n componentList: ComponentRegistry;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n}\n\nexport const TamboRegistryContext = createContext<TamboRegistryContext>({\n componentList: {},\n toolRegistry: {},\n componentToolAssociations: {},\n /**\n *\n */\n registerComponent: () => {},\n /**\n *\n */\n registerTool: () => {},\n /**\n *\n */\n registerTools: () => {},\n /**\n *\n */\n addToolAssociation: () => {},\n});\n\nexport interface TamboRegistryProviderProps {\n /** The components to register */\n components?: TamboComponent[];\n /** The tools to register */\n tools?: TamboTool[];\n}\n\n/**\n * The TamboRegistryProvider is a React provider that provides a component\n * registry to the descendants of the provider.\n * @param props - The props for the TamboRegistryProvider\n * @param props.children - The children to wrap\n * @param props.components - The components to register\n * @param props.tools - The tools to register\n * @returns The TamboRegistryProvider component\n */\nexport const TamboRegistryProvider: React.FC<\n PropsWithChildren<TamboRegistryProviderProps>\n> = ({ children, components: userComponents, tools: userTools }) => {\n const [componentList, setComponentList] = useState<ComponentRegistry>({});\n const [toolRegistry, setToolRegistry] = useState<Record<string, TamboTool>>(\n {},\n );\n const [componentToolAssociations, setComponentToolAssociations] = useState<\n Record<string, string[]>\n >({});\n\n const registerTool = useCallback(\n (tool: TamboTool, warnOnOverwrite = true) => {\n setToolRegistry((prev) => {\n if (prev[tool.name] && warnOnOverwrite) {\n console.warn(`Overwriting tool ${tool.name}`);\n }\n return {\n ...prev,\n [tool.name]: tool,\n };\n });\n },\n [],\n );\n\n const registerTools = useCallback(\n (tools: TamboTool[], warnOnOverwrite = true) => {\n tools.forEach((tool) => registerTool(tool, warnOnOverwrite));\n },\n [registerTool],\n );\n\n const addToolAssociation = useCallback(\n (componentName: string, tool: TamboTool) => {\n if (!componentList[componentName]) {\n throw new Error(`Component ${componentName} not found in registry`);\n }\n setComponentToolAssociations((prev) => ({\n ...prev,\n [componentName]: [...(prev[componentName] || []), tool.name],\n }));\n },\n [componentList],\n );\n\n const registerComponent = useCallback(\n (options: TamboComponent, warnOnOverwrite = true) => {\n const {\n name,\n description,\n component,\n propsSchema,\n propsDefinition,\n loadingComponent,\n associatedTools,\n } = options;\n\n // Validate that at least one props definition is provided\n if (!propsSchema && !propsDefinition) {\n throw new Error(\n `Component ${name} must have either propsSchema (recommended) or propsDefinition defined`,\n );\n }\n\n // Validate that only one props definition is provided\n if (propsSchema && propsDefinition) {\n throw new Error(\n `Component ${name} cannot have both propsSchema and propsDefinition defined. Use only one. We recommend using propsSchema.`,\n );\n }\n\n // Convert propsSchema to JSON Schema if it exists\n const props = getSerializedProps(propsDefinition, propsSchema, name);\n\n setComponentList((prev) => {\n if (prev[name] && warnOnOverwrite) {\n console.warn(`overwriting component ${name}`);\n }\n return {\n ...prev,\n [name]: {\n component,\n loadingComponent,\n name,\n description,\n props,\n contextTools: [],\n },\n };\n });\n if (associatedTools) {\n registerTools(associatedTools);\n setComponentToolAssociations((prev) => ({\n ...prev,\n [name]: associatedTools.map((tool) => tool.name),\n }));\n }\n },\n [registerTools],\n );\n useEffect(() => {\n if (userComponents) {\n userComponents.forEach((component) => {\n registerComponent(component, false);\n });\n }\n }, [registerComponent, userComponents]);\n\n useEffect(() => {\n if (userTools) {\n registerTools(userTools, false);\n }\n }, [registerTools, userTools]);\n\n const value = {\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n };\n\n return (\n <TamboRegistryContext.Provider value={value}>\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * The useTamboRegistry hook provides access to the component registry\n * to the descendants of the TamboRegistryProvider.\n * @returns The component registry\n */\nexport const useTamboRegistry = () => {\n return useContext(TamboRegistryContext);\n};\nfunction getSerializedProps(\n propsDefinition: any,\n propsSchema: any,\n name: string,\n) {\n if (propsDefinition) {\n console.warn(`propsDefinition is deprecated. Use propsSchema instead.`);\n return propsDefinition;\n }\n\n if (isZodSchema(propsSchema)) {\n try {\n return zodToJsonSchema(propsSchema);\n } catch (error) {\n console.error(\n `Error converting ${name} props schema to JSON Schema:`,\n error,\n );\n }\n }\n // try to roughly detect JSONSchema, should always be an object with a properties key\n if (isJSONSchema(propsSchema)) {\n return propsSchema;\n }\n\n throw new Error(`Invalid props schema for ${name}`);\n}\n\n/**\n * Checks if the propsSchema is a JSON Schema. This is a rough check, and the\n * server will provide the definitive check.\n * @param propsSchema - The props schema to check\n * @returns True if the props schema is a JSON Schema, false otherwise\n */\nfunction isJSONSchema(propsSchema: any) {\n return (\n propsSchema &&\n typeof propsSchema === \"object\" &&\n propsSchema.type === \"object\" &&\n propsSchema.properties\n );\n}\n\n/**\n * Since we require a certain zod version, we need to check if the object is a ZodSchema\n * @param obj - The object to check\n * @returns True if the object is a ZodSchema, false otherwise\n */\nfunction isZodSchema(obj: unknown): obj is ZodSchema {\n if (obj instanceof ZodSchema) {\n return true;\n }\n // try to detect if the object is a ZodSchema\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n typeof (obj as any).safeParse === \"function\" &&\n typeof (obj as any)._def === \"object\"\n );\n}\n"]}
@@ -0,0 +1,85 @@
1
+ import TamboAI from "@tambo-ai/typescript-sdk";
2
+ import React, { PropsWithChildren } from "react";
3
+ import { TamboComponent, TamboTool } from "../model/component-metadata";
4
+ import { TamboThread } from "../model/tambo-thread";
5
+ import { type TamboContextProps } from "./tambo-provider";
6
+ /**
7
+ * TamboStubProvider props - includes all the data that would normally be inferred
8
+ */
9
+ export interface TamboStubProviderProps extends Partial<TamboContextProps> {
10
+ /** Required: The thread data to display */
11
+ thread: TamboThread;
12
+ /** Optional: Components registry - defaults to empty */
13
+ components?: TamboComponent[];
14
+ /** Optional: Tools registry - defaults to empty */
15
+ tools?: TamboTool[];
16
+ /** Optional: Threads data to populate thread list - overrides useTamboThreadList() */
17
+ threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;
18
+ /** Optional: Project ID to use for query cache - defaults to thread.projectId */
19
+ projectId?: string;
20
+ /** Optional: Context key for thread list queries */
21
+ contextKey?: string;
22
+ }
23
+ /**
24
+ * The TamboStubProvider provides a way to use the Tambo API with static/stub data.
25
+ * This is useful for testing, samples, and static UI development.
26
+ *
27
+ * Unlike TamboProvider, all data must be provided as props rather than being inferred.
28
+ * @example
29
+ * ```tsx
30
+ * import { TamboStubProvider } from '@tambo-ai/react-sdk';
31
+ *
32
+ * const exampleThread = {
33
+ * id: "example-thread",
34
+ * messages: [
35
+ * {
36
+ * id: "msg-1",
37
+ * role: "user",
38
+ * content: [{ type: "text", text: "Hello!" }],
39
+ * createdAt: new Date().toISOString(),
40
+ * threadId: "example-thread",
41
+ * componentState: {},
42
+ * },
43
+ * {
44
+ * id: "msg-2",
45
+ * role: "assistant",
46
+ * content: [{ type: "text", text: "Hi there!" }],
47
+ * createdAt: new Date().toISOString(),
48
+ * threadId: "example-thread",
49
+ * componentState: {},
50
+ * }
51
+ * ],
52
+ * createdAt: new Date().toISOString(),
53
+ * projectId: "example-project",
54
+ * updatedAt: new Date().toISOString(),
55
+ * metadata: {},
56
+ * };
57
+ *
58
+ * const exampleThreadList = [exampleThread];
59
+ *
60
+ * function MyComponent() {
61
+ * return (
62
+ * <TamboStubProvider
63
+ * thread={exampleThread}
64
+ * components={[]}
65
+ * tools={[]}
66
+ * threads={exampleThreadList}
67
+ * projectId="example-project"
68
+ * >
69
+ * <MessageThreadFull />
70
+ * </TamboStubProvider>
71
+ * );
72
+ * }
73
+ * ```
74
+ * @param props - The props for the TamboStubProvider
75
+ * @param props.children - The children to wrap
76
+ * @param props.thread - The thread data to display
77
+ * @param props.components - Optional components registry
78
+ * @param props.tools - Optional tools registry
79
+ * @param props.threads - Optional threads data to populate thread list (overrides useTamboThreadList)
80
+ * @param props.projectId - Optional project ID for query cache (defaults to thread.projectId)
81
+ * @param props.contextKey - Optional context key for thread list queries
82
+ * @returns The TamboStubProvider component
83
+ */
84
+ export declare const TamboStubProvider: React.FC<PropsWithChildren<TamboStubProviderProps>>;
85
+ //# sourceMappingURL=tambo-stubs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-stubs.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAE/C,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAMpD,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,kBAAkB,CAAC;AAO1B;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,OAAO,CAAC,iBAAiB,CAAC;IACxE,2CAA2C;IAC3C,MAAM,EAAE,WAAW,CAAC;IACpB,wDAAwD;IACxD,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,mDAAmD;IACnD,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;IACpB,sFAAsF;IACtF,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC9D,iFAAiF;IACjF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAmID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CACtC,iBAAiB,CAAC,sBAAsB,CAAC,CAkH1C,CAAC"}
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+ "use client";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.TamboStubProvider = void 0;
38
+ const react_query_1 = require("@tanstack/react-query");
39
+ const react_1 = __importStar(require("react"));
40
+ const generate_component_response_1 = require("../model/generate-component-response");
41
+ const tambo_client_provider_1 = require("./tambo-client-provider");
42
+ const tambo_component_provider_1 = require("./tambo-component-provider");
43
+ const tambo_provider_1 = require("./tambo-provider");
44
+ const tambo_registry_provider_1 = require("./tambo-registry-provider");
45
+ const tambo_thread_provider_1 = require("./tambo-thread-provider");
46
+ /**
47
+ * Stub client provider that accepts a client and queryClient as props
48
+ * @returns The TamboStubClientProvider component
49
+ */
50
+ const TamboStubClientProvider = ({ children, client, queryClient, threads, projectId, contextKey }) => {
51
+ // Prepopulate the query cache with threads data if provided
52
+ (0, react_1.useEffect)(() => {
53
+ if (threads) {
54
+ // Set the project ID in the cache
55
+ queryClient.setQueryData(["projectId"], projectId);
56
+ // Set the threads data in the cache using the same query key pattern as useTamboThreadList
57
+ queryClient.setQueryData(["threads", projectId, contextKey], threads);
58
+ }
59
+ }, [threads, projectId, contextKey, queryClient]);
60
+ return (react_1.default.createElement(tambo_client_provider_1.TamboClientContext.Provider, { value: { client, queryClient } }, children));
61
+ };
62
+ /**
63
+ * Stub registry provider that accepts componentList, toolRegistry, and componentToolAssociations as props
64
+ * @returns The TamboStubRegistryProvider component
65
+ */
66
+ const TamboStubRegistryProvider = ({ children, componentList, toolRegistry, componentToolAssociations, registerComponent, registerTool, registerTools, addToolAssociation, }) => {
67
+ return (react_1.default.createElement(tambo_registry_provider_1.TamboRegistryContext.Provider, { value: {
68
+ componentList,
69
+ toolRegistry,
70
+ componentToolAssociations,
71
+ registerComponent,
72
+ registerTool,
73
+ registerTools,
74
+ addToolAssociation,
75
+ } }, children));
76
+ };
77
+ /**
78
+ * Stub thread provider that accepts all thread context props
79
+ * @returns The TamboStubThreadProvider component
80
+ */
81
+ const TamboStubThreadProvider = ({ children, ...threadContextProps }) => {
82
+ return (react_1.default.createElement(tambo_thread_provider_1.TamboThreadContext.Provider, { value: threadContextProps }, children));
83
+ };
84
+ /**
85
+ * Default no-op functions that throw errors - used when callbacks are not provided
86
+ * @returns The default callbacks
87
+ */
88
+ const createDefaultCallbacks = () => ({
89
+ switchCurrentThread: () => {
90
+ throw new Error("switchCurrentThread not implemented in stub");
91
+ },
92
+ startNewThread: () => {
93
+ throw new Error("startNewThread not implemented in stub");
94
+ },
95
+ updateThreadName: () => {
96
+ throw new Error("updateThreadName not implemented in stub");
97
+ },
98
+ generateThreadName: () => {
99
+ throw new Error("generateThreadName not implemented in stub");
100
+ },
101
+ addThreadMessage: () => {
102
+ throw new Error("addThreadMessage not implemented in stub");
103
+ },
104
+ updateThreadMessage: () => {
105
+ throw new Error("updateThreadMessage not implemented in stub");
106
+ },
107
+ setInputValue: () => {
108
+ throw new Error("setInputValue not implemented in stub");
109
+ },
110
+ sendThreadMessage: () => {
111
+ throw new Error("sendThreadMessage not implemented in stub");
112
+ },
113
+ registerComponent: () => {
114
+ throw new Error("registerComponent not implemented in stub");
115
+ },
116
+ registerTool: () => {
117
+ throw new Error("registerTool not implemented in stub");
118
+ },
119
+ registerTools: () => {
120
+ throw new Error("registerTools not implemented in stub");
121
+ },
122
+ addToolAssociation: () => {
123
+ throw new Error("addToolAssociation not implemented in stub");
124
+ },
125
+ });
126
+ /**
127
+ * The TamboStubProvider provides a way to use the Tambo API with static/stub data.
128
+ * This is useful for testing, samples, and static UI development.
129
+ *
130
+ * Unlike TamboProvider, all data must be provided as props rather than being inferred.
131
+ * @example
132
+ * ```tsx
133
+ * import { TamboStubProvider } from '@tambo-ai/react-sdk';
134
+ *
135
+ * const exampleThread = {
136
+ * id: "example-thread",
137
+ * messages: [
138
+ * {
139
+ * id: "msg-1",
140
+ * role: "user",
141
+ * content: [{ type: "text", text: "Hello!" }],
142
+ * createdAt: new Date().toISOString(),
143
+ * threadId: "example-thread",
144
+ * componentState: {},
145
+ * },
146
+ * {
147
+ * id: "msg-2",
148
+ * role: "assistant",
149
+ * content: [{ type: "text", text: "Hi there!" }],
150
+ * createdAt: new Date().toISOString(),
151
+ * threadId: "example-thread",
152
+ * componentState: {},
153
+ * }
154
+ * ],
155
+ * createdAt: new Date().toISOString(),
156
+ * projectId: "example-project",
157
+ * updatedAt: new Date().toISOString(),
158
+ * metadata: {},
159
+ * };
160
+ *
161
+ * const exampleThreadList = [exampleThread];
162
+ *
163
+ * function MyComponent() {
164
+ * return (
165
+ * <TamboStubProvider
166
+ * thread={exampleThread}
167
+ * components={[]}
168
+ * tools={[]}
169
+ * threads={exampleThreadList}
170
+ * projectId="example-project"
171
+ * >
172
+ * <MessageThreadFull />
173
+ * </TamboStubProvider>
174
+ * );
175
+ * }
176
+ * ```
177
+ * @param props - The props for the TamboStubProvider
178
+ * @param props.children - The children to wrap
179
+ * @param props.thread - The thread data to display
180
+ * @param props.components - Optional components registry
181
+ * @param props.tools - Optional tools registry
182
+ * @param props.threads - Optional threads data to populate thread list (overrides useTamboThreadList)
183
+ * @param props.projectId - Optional project ID for query cache (defaults to thread.projectId)
184
+ * @param props.contextKey - Optional context key for thread list queries
185
+ * @returns The TamboStubProvider component
186
+ */
187
+ const TamboStubProvider = ({ children, thread, components = [], tools = [], threads, projectId, contextKey, ...overrides }) => {
188
+ const defaults = createDefaultCallbacks();
189
+ // Create stub client and queryClient
190
+ const stubClient = {};
191
+ const stubQueryClient = new react_query_1.QueryClient();
192
+ // Use provided projectId or fall back to thread's projectId
193
+ const resolvedProjectId = projectId ?? thread.projectId;
194
+ // Build component registry from components prop
195
+ const componentList = components.reduce((acc, component) => {
196
+ acc[component.name] = {
197
+ component: component.component,
198
+ loadingComponent: component.loadingComponent,
199
+ name: component.name,
200
+ description: component.description,
201
+ props: component.propsDefinition ?? {},
202
+ contextTools: [],
203
+ };
204
+ return acc;
205
+ }, {});
206
+ // Build tool registry from tools prop
207
+ const toolRegistry = tools.reduce((acc, tool) => {
208
+ acc[tool.name] = tool;
209
+ return acc;
210
+ }, {});
211
+ // Build tool associations from components
212
+ const componentToolAssociations = components.reduce((acc, component) => {
213
+ if (component.associatedTools) {
214
+ acc[component.name] = component.associatedTools.map((tool) => tool.name);
215
+ }
216
+ return acc;
217
+ }, {});
218
+ // Merge defaults with provided overrides
219
+ const threadContextProps = {
220
+ thread,
221
+ switchCurrentThread: overrides.switchCurrentThread ?? defaults.switchCurrentThread,
222
+ startNewThread: overrides.startNewThread ?? defaults.startNewThread,
223
+ updateThreadName: overrides.updateThreadName ?? defaults.updateThreadName,
224
+ generateThreadName: overrides.generateThreadName ?? defaults.generateThreadName,
225
+ addThreadMessage: overrides.addThreadMessage ?? defaults.addThreadMessage,
226
+ updateThreadMessage: overrides.updateThreadMessage ?? defaults.updateThreadMessage,
227
+ inputValue: overrides.inputValue ?? "",
228
+ streaming: overrides.streaming ?? true,
229
+ setInputValue: overrides.setInputValue ?? defaults.setInputValue,
230
+ sendThreadMessage: overrides.sendThreadMessage ?? defaults.sendThreadMessage,
231
+ generationStage: overrides.generationStage ?? generate_component_response_1.GenerationStage.IDLE,
232
+ generationStatusMessage: overrides.generationStatusMessage ?? "",
233
+ isIdle: overrides.isIdle ?? true,
234
+ };
235
+ const componentContextProps = {
236
+ registerComponent: overrides.registerComponent ?? defaults.registerComponent,
237
+ registerTool: overrides.registerTool ?? defaults.registerTool,
238
+ registerTools: overrides.registerTools ?? defaults.registerTools,
239
+ addToolAssociation: overrides.addToolAssociation ?? defaults.addToolAssociation,
240
+ };
241
+ return (react_1.default.createElement(TamboStubClientProvider, { client: stubClient, queryClient: stubQueryClient, threads: threads, projectId: resolvedProjectId, contextKey: contextKey },
242
+ react_1.default.createElement(TamboStubRegistryProvider, { componentList: componentList, toolRegistry: toolRegistry, componentToolAssociations: componentToolAssociations, registerComponent: componentContextProps.registerComponent, registerTool: componentContextProps.registerTool, registerTools: componentContextProps.registerTools, addToolAssociation: componentContextProps.addToolAssociation },
243
+ react_1.default.createElement(TamboStubThreadProvider, { ...threadContextProps },
244
+ react_1.default.createElement(tambo_component_provider_1.TamboComponentProvider, null,
245
+ react_1.default.createElement(tambo_provider_1.TamboCompositeProvider, null, children))))));
246
+ };
247
+ exports.TamboStubProvider = TamboStubProvider;
248
+ //# sourceMappingURL=tambo-stubs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-stubs.js","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,uDAAoD;AACpD,+CAA4D;AAE5D,sFAAuE;AAEvE,mEAA6D;AAC7D,yEAGoC;AACpC,qDAG0B;AAC1B,uEAAiE;AACjE,mEAGiC;AAoBjC;;;GAGG;AACH,MAAM,uBAAuB,GAQzB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,EA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AAS,CAAC,kBAAkB,IAAI,QAAQ,CAAC,kBAAkB;KAC9D,CAAC;IAEF,OAAO,CACL,8BAAC,uBAAuB,IACtB,MAAM,EAAE,UAAU,EAClB,WAAW,EAAE,eAAe,EAC5B,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,iBAAiB,EAC5B,UAAU,EAAE,UAAU;QAEtB,8BAAC,yBAAyB,IACxB,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY,EAC1B,yBAAyB,EAAE,yBAAyB,EACpD,iBAAiB,EAAE,qBAAqB,CAAC,iBAAiB,EAC1D,YAAY,EAAE,qBAAqB,CAAC,YAAY,EAChD,aAAa,EAAE,qBAAqB,CAAC,aAAa,EAClD,kBAAkB,EAAE,qBAAqB,CAAC,kBAAkB;YAE5D,8BAAC,uBAAuB,OAAK,kBAAkB;gBAC7C,8BAAC,iDAAsB;oBACrB,8BAAC,uCAAsB,QAAE,QAAQ,CAA0B,CACpC,CACD,CACA,CACJ,CAC3B,CAAC;AACJ,CAAC,CAAC;AAnHW,QAAA,iBAAiB,qBAmH5B","sourcesContent":["\"use client\";\nimport TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport React, { PropsWithChildren, useEffect } from \"react\";\nimport { TamboComponent, TamboTool } from \"../model/component-metadata\";\nimport { GenerationStage } from \"../model/generate-component-response\";\nimport { TamboThread } from \"../model/tambo-thread\";\nimport { TamboClientContext } from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n} from \"./tambo-component-provider\";\nimport {\n TamboCompositeProvider,\n type TamboContextProps,\n} from \"./tambo-provider\";\nimport { TamboRegistryContext } from \"./tambo-registry-provider\";\nimport {\n TamboThreadContext,\n TamboThreadContextProps,\n} from \"./tambo-thread-provider\";\n\n/**\n * TamboStubProvider props - includes all the data that would normally be inferred\n */\nexport interface TamboStubProviderProps extends Partial<TamboContextProps> {\n /** Required: The thread data to display */\n thread: TamboThread;\n /** Optional: Components registry - defaults to empty */\n components?: TamboComponent[];\n /** Optional: Tools registry - defaults to empty */\n tools?: TamboTool[];\n /** Optional: Threads data to populate thread list - overrides useTamboThreadList() */\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n /** Optional: Project ID to use for query cache - defaults to thread.projectId */\n projectId?: string;\n /** Optional: Context key for thread list queries */\n contextKey?: string;\n}\n\n/**\n * Stub client provider that accepts a client and queryClient as props\n * @returns The TamboStubClientProvider component\n */\nconst TamboStubClientProvider: React.FC<\n PropsWithChildren<{\n client: TamboAI;\n queryClient: QueryClient;\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n projectId?: string;\n contextKey?: string;\n }>\n> = ({ children, client, queryClient, threads, projectId, contextKey }) => {\n // Prepopulate the query cache with threads data if provided\n useEffect(() => {\n if (threads) {\n // Set the project ID in the cache\n queryClient.setQueryData([\"projectId\"], projectId);\n\n // Set the threads data in the cache using the same query key pattern as useTamboThreadList\n queryClient.setQueryData([\"threads\", projectId, contextKey], threads);\n }\n }, [threads, projectId, contextKey, queryClient]);\n\n return (\n <TamboClientContext.Provider value={{ client, queryClient }}>\n {children}\n </TamboClientContext.Provider>\n );\n};\n\n/**\n * Stub registry provider that accepts componentList, toolRegistry, and componentToolAssociations as props\n * @returns The TamboStubRegistryProvider component\n */\nconst TamboStubRegistryProvider: React.FC<\n PropsWithChildren<{\n componentList: Record<string, any>;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n }>\n> = ({\n children,\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n}) => {\n return (\n <TamboRegistryContext.Provider\n value={{\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n }}\n >\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * Stub thread provider that accepts all thread context props\n * @returns The TamboStubThreadProvider component\n */\nconst TamboStubThreadProvider: React.FC<\n PropsWithChildren<TamboThreadContextProps>\n> = ({ children, ...threadContextProps }) => {\n return (\n <TamboThreadContext.Provider value={threadContextProps}>\n {children}\n </TamboThreadContext.Provider>\n );\n};\n\n/**\n * Default no-op functions that throw errors - used when callbacks are not provided\n * @returns The default callbacks\n */\nconst createDefaultCallbacks = () => ({\n switchCurrentThread: () => {\n throw new Error(\"switchCurrentThread not implemented in stub\");\n },\n startNewThread: () => {\n throw new Error(\"startNewThread not implemented in stub\");\n },\n updateThreadName: () => {\n throw new Error(\"updateThreadName not implemented in stub\");\n },\n generateThreadName: () => {\n throw new Error(\"generateThreadName not implemented in stub\");\n },\n addThreadMessage: () => {\n throw new Error(\"addThreadMessage not implemented in stub\");\n },\n updateThreadMessage: () => {\n throw new Error(\"updateThreadMessage not implemented in stub\");\n },\n setInputValue: () => {\n throw new Error(\"setInputValue not implemented in stub\");\n },\n sendThreadMessage: () => {\n throw new Error(\"sendThreadMessage not implemented in stub\");\n },\n registerComponent: () => {\n throw new Error(\"registerComponent not implemented in stub\");\n },\n registerTool: () => {\n throw new Error(\"registerTool not implemented in stub\");\n },\n registerTools: () => {\n throw new Error(\"registerTools not implemented in stub\");\n },\n addToolAssociation: () => {\n throw new Error(\"addToolAssociation not implemented in stub\");\n },\n});\n\n/**\n * The TamboStubProvider provides a way to use the Tambo API with static/stub data.\n * This is useful for testing, samples, and static UI development.\n *\n * Unlike TamboProvider, all data must be provided as props rather than being inferred.\n * @example\n * ```tsx\n * import { TamboStubProvider } from '@tambo-ai/react-sdk';\n *\n * const exampleThread = {\n * id: \"example-thread\",\n * messages: [\n * {\n * id: \"msg-1\",\n * role: \"user\",\n * content: [{ type: \"text\", text: \"Hello!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * },\n * {\n * id: \"msg-2\",\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hi there!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * }\n * ],\n * createdAt: new Date().toISOString(),\n * projectId: \"example-project\",\n * updatedAt: new Date().toISOString(),\n * metadata: {},\n * };\n *\n * const exampleThreadList = [exampleThread];\n *\n * function MyComponent() {\n * return (\n * <TamboStubProvider\n * thread={exampleThread}\n * components={[]}\n * tools={[]}\n * threads={exampleThreadList}\n * projectId=\"example-project\"\n * >\n * <MessageThreadFull />\n * </TamboStubProvider>\n * );\n * }\n * ```\n * @param props - The props for the TamboStubProvider\n * @param props.children - The children to wrap\n * @param props.thread - The thread data to display\n * @param props.components - Optional components registry\n * @param props.tools - Optional tools registry\n * @param props.threads - Optional threads data to populate thread list (overrides useTamboThreadList)\n * @param props.projectId - Optional project ID for query cache (defaults to thread.projectId)\n * @param props.contextKey - Optional context key for thread list queries\n * @returns The TamboStubProvider component\n */\nexport const TamboStubProvider: React.FC<\n PropsWithChildren<TamboStubProviderProps>\n> = ({\n children,\n thread,\n components = [],\n tools = [],\n threads,\n projectId,\n contextKey,\n ...overrides\n}) => {\n const defaults = createDefaultCallbacks();\n\n // Create stub client and queryClient\n const stubClient = {} as TamboAI;\n const stubQueryClient = new QueryClient();\n\n // Use provided projectId or fall back to thread's projectId\n const resolvedProjectId = projectId ?? thread.projectId;\n\n // Build component registry from components prop\n const componentList = components.reduce(\n (acc, component) => {\n acc[component.name] = {\n component: component.component,\n loadingComponent: component.loadingComponent,\n name: component.name,\n description: component.description,\n props: component.propsDefinition ?? {},\n contextTools: [],\n };\n return acc;\n },\n {} as Record<string, any>,\n );\n\n // Build tool registry from tools prop\n const toolRegistry = tools.reduce(\n (acc, tool) => {\n acc[tool.name] = tool;\n return acc;\n },\n {} as Record<string, TamboTool>,\n );\n\n // Build tool associations from components\n const componentToolAssociations = components.reduce(\n (acc, component) => {\n if (component.associatedTools) {\n acc[component.name] = component.associatedTools.map(\n (tool) => tool.name,\n );\n }\n return acc;\n },\n {} as Record<string, string[]>,\n );\n\n // Merge defaults with provided overrides\n const threadContextProps: TamboThreadContextProps = {\n thread,\n switchCurrentThread:\n overrides.switchCurrentThread ?? defaults.switchCurrentThread,\n startNewThread: overrides.startNewThread ?? defaults.startNewThread,\n updateThreadName: overrides.updateThreadName ?? defaults.updateThreadName,\n generateThreadName:\n overrides.generateThreadName ?? defaults.generateThreadName,\n addThreadMessage: overrides.addThreadMessage ?? defaults.addThreadMessage,\n updateThreadMessage:\n overrides.updateThreadMessage ?? defaults.updateThreadMessage,\n inputValue: overrides.inputValue ?? \"\",\n streaming: overrides.streaming ?? true,\n setInputValue: overrides.setInputValue ?? defaults.setInputValue,\n sendThreadMessage:\n overrides.sendThreadMessage ?? defaults.sendThreadMessage,\n generationStage: overrides.generationStage ?? GenerationStage.IDLE,\n generationStatusMessage: overrides.generationStatusMessage ?? \"\",\n isIdle: overrides.isIdle ?? true,\n };\n\n const componentContextProps: TamboComponentContextProps = {\n registerComponent:\n overrides.registerComponent ?? defaults.registerComponent,\n registerTool: overrides.registerTool ?? defaults.registerTool,\n registerTools: overrides.registerTools ?? defaults.registerTools,\n addToolAssociation:\n overrides.addToolAssociation ?? defaults.addToolAssociation,\n };\n\n return (\n <TamboStubClientProvider\n client={stubClient}\n queryClient={stubQueryClient}\n threads={threads}\n projectId={resolvedProjectId}\n contextKey={contextKey}\n >\n <TamboStubRegistryProvider\n componentList={componentList}\n toolRegistry={toolRegistry}\n componentToolAssociations={componentToolAssociations}\n registerComponent={componentContextProps.registerComponent}\n registerTool={componentContextProps.registerTool}\n registerTools={componentContextProps.registerTools}\n addToolAssociation={componentContextProps.addToolAssociation}\n >\n <TamboStubThreadProvider {...threadContextProps}>\n <TamboComponentProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboComponentProvider>\n </TamboStubThreadProvider>\n </TamboStubRegistryProvider>\n </TamboStubClientProvider>\n );\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"use-component-state.d.ts","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":"AAQA,UAAU,kBAAkB;IAC1B,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,KAAK,iBAAiB,CAAC,CAAC,IAAI;IAC1B,YAAY,EAAE,CAAC;IACf,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI;IAC/B,IAAI,EAAE,kBAAkB;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,SAAS,EAClD,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,CAAC,EAChB,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AACpC,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,CAAC,EACf,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"use-component-state.d.ts","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":"AASA,UAAU,kBAAkB;IAC1B,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,KAAK,iBAAiB,CAAC,CAAC,IAAI;IAC1B,YAAY,EAAE,CAAC;IACf,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI;IAC/B,IAAI,EAAE,kBAAkB;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,SAAS,EAClD,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,CAAC,EAChB,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AACpC,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,CAAC,EACf,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,CAAC,CAAC,CAAC,CAAC"}
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useCallback, useEffect, useState } from "react";
2
3
  import { useDebouncedCallback } from "use-debounce";
3
4
  import { useTamboClient, useTamboThread } from "../providers";
@@ -1 +1 @@
1
- {"version":3,"file":"use-component-state.js","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EACL,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAmD/B,+CAA+C;AAC/C,MAAM,UAAU,sBAAsB,CACpC,OAAe,EACf,YAAgB,EAChB,YAAY,GAAG,GAAG;IAElB,MAAM,EAAE,SAAS,EAAE,GAAG,sBAAsB,EAAE,CAAC;IAC/C,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,CAAC;IACzD,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,OAAO,GAAG,sBAAsB,EAAE,CAAC;IACzC,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC;IAE3B,2BAA2B;IAC3B,MAAM,CAAC,kBAAkB,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC;IAC1D,sBAAsB;IACtB,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAC1C,kBAAkB,CACnB,CAAC;IACF,wBAAwB;IACxB,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG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CAAC","sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport { useDebouncedCallback } from \"use-debounce\";\nimport { useTamboClient, useTamboThread } from \"../providers\";\nimport {\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./use-current-message\";\n// Define metadata interface for better extensibility\ninterface ComponentStateMeta {\n isPending: boolean;\n}\n\ntype StateUpdateResult<T> = [\n currentState: T,\n setState: (newState: T) => void,\n meta: ComponentStateMeta,\n];\n\n/**\n * A React hook that provides state management and passes user updates to Tambo.\n * Benefits: Passes user changes to AI, and when threads are returned, state is preserved.\n * @param keyName - The unique key to identify this state within the message's componentState object\n * @param initialValue - Optional initial value for the state, used if no value exists in the message\n * @param debounceTime - Optional debounce time in milliseconds (default: 300ms) to limit API calls\n * @returns A tuple containing:\n * - The current state value\n * - A setter function to update the state (updates UI immediately, debounces server sync)\n * - A metadata object with properties like isPending to track sync status\n * @example\n * // Basic usage\n * const [count, setCount, { isPending }] = useTamboComponentState(\"counter\", 0);\n *\n * // Usage with object state\n * const [formState, setFormState] = useTamboComponentState(\"myForm\", {\n * name: \"\",\n * email: \"\",\n * message: \"\"\n * });\n *\n * // Handling form input\n * const handleChange = (e) => {\n * setFormState({\n * ...formState,\n * [e.target.name]: e.target.value\n * });\n * };\n */\nexport function useTamboComponentState<S = undefined>(\n keyName: string,\n initialValue?: S,\n debounceTime?: number,\n): StateUpdateResult<S | undefined>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue: S,\n debounceTime?: number,\n): StateUpdateResult<S>;\n// eslint-disable-next-line jsdoc/require-jsdoc\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue?: S,\n debounceTime = 500,\n): StateUpdateResult<S> {\n const { messageId } = useTamboMessageContext();\n const { updateThreadMessage, thread } = useTamboThread();\n const client = useTamboClient();\n const message = useTamboCurrentMessage();\n const threadId = thread.id;\n\n // Initial value management\n const [cachedInitialValue] = useState(() => initialValue);\n // UI state management\n const [localState, setLocalState] = useState<S | undefined>(\n cachedInitialValue,\n );\n // Synchronization state\n const [isPending, setIsPending] = useState(false);\n // Track the last user-initiated value instead of a simple boolean flag\n const [lastUserValue, setLastUserValue] = useState<S | null>(null);\n const [haveInitialized, setHaveInitialized] = useState(false);\n\n // Determine if we need to initialize state\n const shouldInitialize =\n !haveInitialized &&\n message &&\n cachedInitialValue !== undefined &&\n (!message.componentState || !(keyName in message.componentState));\n\n // Sync local state with message state on initial load and when message changes\n useEffect(() => {\n if (message?.componentState && keyName in message.componentState) {\n const messageState = message.componentState[keyName] as S;\n\n // Only update local state if we haven't had any user changes yet\n if (lastUserValue === null) {\n setLocalState(messageState);\n }\n }\n // Otherwise fall back to initial value if we have one and no user changes\n else if (\n cachedInitialValue !== undefined &&\n !localState &&\n lastUserValue === null\n ) {\n setLocalState(cachedInitialValue);\n }\n }, [\n keyName,\n message?.componentState,\n cachedInitialValue,\n lastUserValue,\n localState,\n ]);\n\n // Create debounced save function for efficient server synchronization\n const debouncedServerWrite = useDebouncedCallback(async (newValue: S) => {\n setIsPending(true);\n try {\n const componentStateUpdate = {\n state: { [keyName]: newValue },\n };\n\n await client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n );\n } catch (err) {\n console.error(\n `Failed to save component state for key \"${keyName}\":`,\n err,\n );\n } finally {\n setIsPending(false);\n }\n }, debounceTime);\n\n // Initialize state on first render if needed\n const initializeState = useCallback(async () => {\n if (!message) {\n console.warn(\n `Cannot initialize state for missing message ${messageId} with key \"${keyName}\"`,\n );\n return;\n }\n\n try {\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: cachedInitialValue,\n },\n };\n\n const componentStateUpdate = {\n state: { [keyName]: cachedInitialValue },\n };\n\n await Promise.all([\n updateThreadMessage(messageId, messageUpdate, false),\n client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n ),\n ]);\n } catch (err) {\n console.warn(\n `Failed to initialize component state for key \"${keyName}\":`,\n err,\n );\n }\n }, [\n cachedInitialValue,\n client.beta.threads.messages,\n keyName,\n message,\n messageId,\n threadId,\n updateThreadMessage,\n ]);\n\n // Send initial state when component mounts\n useEffect(() => {\n if (shouldInitialize) {\n initializeState();\n setHaveInitialized(true);\n }\n }, [initializeState, shouldInitialize]);\n\n // setValue function for updating state\n // Updates local state immediately and schedules debounced server sync\n const setValue = useCallback(\n (newValue: S) => {\n // Track this as a user-initiated update\n setLastUserValue(newValue);\n setLocalState(newValue);\n\n // Only trigger server updates if we have a message\n if (message) {\n debouncedServerWrite(newValue);\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: newValue,\n },\n };\n\n updateThreadMessage(messageId, messageUpdate, false);\n } else {\n console.warn(\n `Cannot update server for missing message ${messageId} with key \"${keyName}\"`,\n );\n }\n },\n [message, debouncedServerWrite, keyName, updateThreadMessage, messageId],\n );\n\n // Ensure pending changes are flushed on unmount\n useEffect(() => {\n return () => {\n debouncedServerWrite.flush();\n };\n }, [debouncedServerWrite]);\n\n // Return the local state for immediate UI rendering\n return [localState as S, setValue, { isPending }];\n}\n"]}
1
+ {"version":3,"file":"use-component-state.js","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EACL,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAmD/B,+CAA+C;AAC/C,MAAM,UAAU,sBAAsB,CACpC,OAAe,EACf,YAAgB,EAChB,YAAY,GAAG,GAAG;IAElB,MAAM,EAAE,SAAS,EAAE,GAAG,sBAAsB,EAAE,CAAC;IAC/C,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE,GAAG,cAAc,E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AAc,OAAO,GAAG,CAC9E,CAAC;QACJ,CAAC;IACH,CAAC,EACD,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,mBAAmB,EAAE,SAAS,CAAC,CACzE,CAAC;IAEF,gDAAgD;IAChD,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE;YACV,oBAAoB,CAAC,KAAK,EAAE,CAAC;QAC/B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAE3B,oDAAoD;IACpD,OAAO,CAAC,UAAe,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useState } from \"react\";\nimport { useDebouncedCallback } from \"use-debounce\";\nimport { useTamboClient, useTamboThread } from \"../providers\";\nimport {\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./use-current-message\";\n// Define metadata interface for better extensibility\ninterface ComponentStateMeta {\n isPending: boolean;\n}\n\ntype StateUpdateResult<T> = [\n currentState: T,\n setState: (newState: T) => void,\n meta: ComponentStateMeta,\n];\n\n/**\n * A React hook that provides state management and passes user updates to Tambo.\n * Benefits: Passes user changes to AI, and when threads are returned, state is preserved.\n * @param keyName - The unique key to identify this state within the message's componentState object\n * @param initialValue - Optional initial value for the state, used if no value exists in the message\n * @param debounceTime - Optional debounce time in milliseconds (default: 300ms) to limit API calls\n * @returns A tuple containing:\n * - The current state value\n * - A setter function to update the state (updates UI immediately, debounces server sync)\n * - A metadata object with properties like isPending to track sync status\n * @example\n * // Basic usage\n * const [count, setCount, { isPending }] = useTamboComponentState(\"counter\", 0);\n *\n * // Usage with object state\n * const [formState, setFormState] = useTamboComponentState(\"myForm\", {\n * name: \"\",\n * email: \"\",\n * message: \"\"\n * });\n *\n * // Handling form input\n * const handleChange = (e) => {\n * setFormState({\n * ...formState,\n * [e.target.name]: e.target.value\n * });\n * };\n */\nexport function useTamboComponentState<S = undefined>(\n keyName: string,\n initialValue?: S,\n debounceTime?: number,\n): StateUpdateResult<S | undefined>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue: S,\n debounceTime?: number,\n): StateUpdateResult<S>;\n// eslint-disable-next-line jsdoc/require-jsdoc\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue?: S,\n debounceTime = 500,\n): StateUpdateResult<S> {\n const { messageId } = useTamboMessageContext();\n const { updateThreadMessage, thread } = useTamboThread();\n const client = useTamboClient();\n const message = useTamboCurrentMessage();\n const threadId = thread.id;\n\n // Initial value management\n const [cachedInitialValue] = useState(() => initialValue);\n // UI state management\n const [localState, setLocalState] = useState<S | undefined>(\n cachedInitialValue,\n );\n // Synchronization state\n const [isPending, setIsPending] = useState(false);\n // Track the last user-initiated value instead of a simple boolean flag\n const [lastUserValue, setLastUserValue] = useState<S | null>(null);\n const [haveInitialized, setHaveInitialized] = useState(false);\n\n // Determine if we need to initialize state\n const shouldInitialize =\n !haveInitialized &&\n message &&\n cachedInitialValue !== undefined &&\n (!message.componentState || !(keyName in message.componentState));\n\n // Sync local state with message state on initial load and when message changes\n useEffect(() => {\n if (message?.componentState && keyName in message.componentState) {\n const messageState = message.componentState[keyName] as S;\n\n // Only update local state if we haven't had any user changes yet\n if (lastUserValue === null) {\n setLocalState(messageState);\n }\n }\n // Otherwise fall back to initial value if we have one and no user changes\n else if (\n cachedInitialValue !== undefined &&\n !localState &&\n lastUserValue === null\n ) {\n setLocalState(cachedInitialValue);\n }\n }, [\n keyName,\n message?.componentState,\n cachedInitialValue,\n lastUserValue,\n localState,\n ]);\n\n // Create debounced save function for efficient server synchronization\n const debouncedServerWrite = useDebouncedCallback(async (newValue: S) => {\n setIsPending(true);\n try {\n const componentStateUpdate = {\n state: { [keyName]: newValue },\n };\n\n await client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n );\n } catch (err) {\n console.error(\n `Failed to save component state for key \"${keyName}\":`,\n err,\n );\n } finally {\n setIsPending(false);\n }\n }, debounceTime);\n\n // Initialize state on first render if needed\n const initializeState = useCallback(async () => {\n if (!message) {\n console.warn(\n `Cannot initialize state for missing message ${messageId} with key \"${keyName}\"`,\n );\n return;\n }\n\n try {\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: cachedInitialValue,\n },\n };\n\n const componentStateUpdate = {\n state: { [keyName]: cachedInitialValue },\n };\n\n await Promise.all([\n updateThreadMessage(messageId, messageUpdate, false),\n client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n ),\n ]);\n } catch (err) {\n console.warn(\n `Failed to initialize component state for key \"${keyName}\":`,\n err,\n );\n }\n }, [\n cachedInitialValue,\n client.beta.threads.messages,\n keyName,\n message,\n messageId,\n threadId,\n updateThreadMessage,\n ]);\n\n // Send initial state when component mounts\n useEffect(() => {\n if (shouldInitialize) {\n initializeState();\n setHaveInitialized(true);\n }\n }, [initializeState, shouldInitialize]);\n\n // setValue function for updating state\n // Updates local state immediately and schedules debounced server sync\n const setValue = useCallback(\n (newValue: S) => {\n // Track this as a user-initiated update\n setLastUserValue(newValue);\n setLocalState(newValue);\n\n // Only trigger server updates if we have a message\n if (message) {\n debouncedServerWrite(newValue);\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: newValue,\n },\n };\n\n updateThreadMessage(messageId, messageUpdate, false);\n } else {\n console.warn(\n `Cannot update server for missing message ${messageId} with key \"${keyName}\"`,\n );\n }\n },\n [message, debouncedServerWrite, keyName, updateThreadMessage, messageId],\n );\n\n // Ensure pending changes are flushed on unmount\n useEffect(() => {\n return () => {\n debouncedServerWrite.flush();\n };\n }, [debouncedServerWrite]);\n\n // Return the local state for immediate UI rendering\n return [localState as S, setValue, { isPending }];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"use-current-message.d.ts","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,iBAAiB,EAAc,MAAM,OAAO,CAAC;AAG5E,UAAU,wBAAwB;IAChC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;CACnB;AAMD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CACzC,iBAAiB,CAAC,wBAAwB,CAAC,CAU5C,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,qBAOlB;AACD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,gCAQlC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,mDASlC,CAAC"}
1
+ {"version":3,"file":"use-current-message.d.ts","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAiB,iBAAiB,EAAc,MAAM,OAAO,CAAC;AAG5E,UAAU,wBAAwB;IAChC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;CACnB;AAMD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CACzC,iBAAiB,CAAC,wBAAwB,CAAC,CAU5C,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,qBAOlB;AACD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,gCAQlC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,mDASlC,CAAC"}
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import React, { createContext, useContext } from "react";
2
3
  import { useTamboThread } from "../providers";
3
4
  const TamboMessageContext = createContext({
@@ -1 +1 @@
1
- {"version":3,"file":"use-current-message.js","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAqB,UAAU,EAAE,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAY9C,MAAM,mBAAmB,GAAG,aAAa,CAA2B;IAClE,SAAS,EAAE,EAAE;CACd,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAE7B,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;IAC9B,gFAAgF;IAChF,2EAA2E;IAC3E,6EAA6E;IAC7E,OAAO,CACL,oBAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,SAAS,IAC/D,QAAQ,CACoB,CAChC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B,CAC1C,QAAyB,EACzB,QAAgB,EAChB,SAAiB;IAEjB,OAAO,CACL,oBAAC,oBAAoB,IAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,IAC3D,QAAQ,CACY,CACxB,CAAC;AACJ,CAAC;AACD;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,OAAO,GAAG,UAAU,CAAC,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;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,sBAAsB,EAAE,CAAC;IACzD,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,CAAC;IACpC,IAAI,MAAM,CAAC,EAAE,IAAI,QAAQ,IAAI,MAAM,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,sBAAsB,MAAM,CAAC,EAAE,QAAQ,QAAQ,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC;IAChE,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import React, { createContext, PropsWithChildren, useContext } from \"react\";\nimport { useTamboThread } from \"../providers\";\n\ninterface TamboMessageContextProps {\n /**\n * The threadId of the thread\n * @deprecated Use the thread object from the TamboThreadProvider instead\n */\n threadId?: string;\n /** The messageId of the message */\n messageId: string;\n}\n\nconst TamboMessageContext = createContext<TamboMessageContextProps>({\n messageId: \"\",\n});\n\n/**\n * Wraps all components, so that they can find what thread and message they are in\n * @param props - props for the TamboMessageProvider\n * @param props.children - The children to wrap\n * @param props.messageId - The messageId of the message\n * @returns The wrapped component\n */\nexport const TamboMessageProvider: React.FC<\n PropsWithChildren<TamboMessageContextProps>\n> = ({ children, messageId }) => {\n // Use a unique key={...} to force a re-render when the messageId 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={{ messageId }} key={messageId}>\n {children}\n </TamboMessageContext.Provider>\n );\n};\n\n/**\n * Wraps a component with a ComponentMessageProvider - this allows the provider\n * to be used outside of a TSX file\n * @param children - The children to wrap\n * @param threadId - The threadId of the thread\n * @param messageId - The messageId of the message\n * @returns The wrapped component\n */\nexport function wrapWithTamboMessageProvider(\n children: React.ReactNode,\n threadId: string,\n messageId: string,\n) {\n return (\n <TamboMessageProvider threadId={threadId} messageId={messageId}>\n {children}\n </TamboMessageProvider>\n );\n}\n/**\n * Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the threadId and messageId\n * @returns The threadId and messageId\n */\nexport const useTamboMessageContext = () => {\n const context = useContext(TamboMessageContext);\n if (!context) {\n throw new Error(\n \"useTamboMessageContext must be used within a TamboMessageProvider\",\n );\n }\n return context;\n};\n\n/**\n * Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the current message. The current thread will be fetched from the server, if\n * it is not already in the cache.\n * @returns The current message that is used to render the component\n */\nexport const useTamboCurrentMessage = () => {\n const { messageId, threadId } = useTamboMessageContext();\n const { thread } = useTamboThread();\n if (thread.id && threadId && thread.id !== threadId) {\n console.warn(`Thread ID mismatch ${thread.id} !== ${threadId}`);\n }\n\n const message = thread.messages.find((m) => m.id === messageId);\n return message;\n};\n"]}
1
+ {"version":3,"file":"use-current-message.js","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAE,aAAa,EAAqB,UAAU,EAAE,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAY9C,MAAM,mBAAmB,GAAG,aAAa,CAA2B;IAClE,SAAS,EAAE,EAAE;CACd,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAE7B,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;IAC9B,gFAAgF;IAChF,2EAA2E;IAC3E,6EAA6E;IAC7E,OAAO,CACL,oBAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,SAAS,IAC/D,QAAQ,CACoB,CAChC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B,CAC1C,QAAyB,EACzB,QAAgB,EAChB,SAAiB;IAEjB,OAAO,CACL,oBAAC,oBAAoB,IAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,IAC3D,QAAQ,CACY,CACxB,CAAC;AACJ,CAAC;AACD;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,OAAO,GAAG,UAAU,CAAC,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;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,sBAAsB,EAAE,CAAC;IACzD,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,CAAC;IACpC,IAAI,MAAM,CAAC,EAAE,IAAI,QAAQ,IAAI,MAAM,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,sBAAsB,MAAM,CAAC,EAAE,QAAQ,QAAQ,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC;IAChE,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["\"use client\";\nimport React, { createContext, PropsWithChildren, useContext } from \"react\";\nimport { useTamboThread } from \"../providers\";\n\ninterface TamboMessageContextProps {\n /**\n * The threadId of the thread\n * @deprecated Use the thread object from the TamboThreadProvider instead\n */\n threadId?: string;\n /** The messageId of the message */\n messageId: string;\n}\n\nconst TamboMessageContext = createContext<TamboMessageContextProps>({\n messageId: \"\",\n});\n\n/**\n * Wraps all components, so that they can find what thread and message they are in\n * @param props - props for the TamboMessageProvider\n * @param props.children - The children to wrap\n * @param props.messageId - The messageId of the message\n * @returns The wrapped component\n */\nexport const TamboMessageProvider: React.FC<\n PropsWithChildren<TamboMessageContextProps>\n> = ({ children, messageId }) => {\n // Use a unique key={...} to force a re-render when the messageId 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={{ messageId }} key={messageId}>\n {children}\n </TamboMessageContext.Provider>\n );\n};\n\n/**\n * Wraps a component with a ComponentMessageProvider - this allows the provider\n * to be used outside of a TSX file\n * @param children - The children to wrap\n * @param threadId - The threadId of the thread\n * @param messageId - The messageId of the message\n * @returns The wrapped component\n */\nexport function wrapWithTamboMessageProvider(\n children: React.ReactNode,\n threadId: string,\n messageId: string,\n) {\n return (\n <TamboMessageProvider threadId={threadId} messageId={messageId}>\n {children}\n </TamboMessageProvider>\n );\n}\n/**\n * Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the threadId and messageId\n * @returns The threadId and messageId\n */\nexport const useTamboMessageContext = () => {\n const context = useContext(TamboMessageContext);\n if (!context) {\n throw new Error(\n \"useTamboMessageContext must be used within a TamboMessageProvider\",\n );\n }\n return context;\n};\n\n/**\n * Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the current message. The current thread will be fetched from the server, if\n * it is not already in the cache.\n * @returns The current message that is used to render the component\n */\nexport const useTamboCurrentMessage = () => {\n const { messageId, threadId } = useTamboMessageContext();\n const { thread } = useTamboThread();\n if (thread.id && threadId && thread.id !== threadId) {\n console.warn(`Thread ID mismatch ${thread.id} !== ${threadId}`);\n }\n\n const message = thread.messages.find((m) => m.id === messageId);\n return message;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"use-streaming-props.d.ts","sourceRoot":"","sources":["../../src/hooks/use-streaming-props.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAClE,YAAY,EAAE,CAAC,GAAG,SAAS,EAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAC5B,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC,QAwB3B"}
1
+ {"version":3,"file":"use-streaming-props.d.ts","sourceRoot":"","sources":["../../src/hooks/use-streaming-props.tsx"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAClE,YAAY,EAAE,CAAC,GAAG,SAAS,EAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAC5B,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC,QAwB3B"}