@tambo-ai/react 0.66.1 → 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 (159) 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 +3 -0
  15. package/dist/hooks/use-current-message.d.ts.map +1 -1
  16. package/dist/hooks/use-current-message.js +6 -5
  17. package/dist/hooks/use-current-message.js.map +1 -1
  18. package/dist/hooks/use-current-message.test.js +5 -0
  19. package/dist/hooks/use-current-message.test.js.map +1 -1
  20. package/dist/model/component-metadata.d.ts +2 -2
  21. package/dist/model/component-metadata.d.ts.map +1 -1
  22. package/dist/model/component-metadata.js.map +1 -1
  23. package/dist/model/tambo-interactable.d.ts +6 -0
  24. package/dist/model/tambo-interactable.d.ts.map +1 -1
  25. package/dist/model/tambo-interactable.js.map +1 -1
  26. package/dist/providers/tambo-interactable-provider-partial-updates.test.js +87 -87
  27. package/dist/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
  28. package/dist/providers/tambo-interactable-provider.d.ts +1 -0
  29. package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
  30. package/dist/providers/tambo-interactable-provider.js +83 -47
  31. package/dist/providers/tambo-interactable-provider.js.map +1 -1
  32. package/dist/providers/tambo-interactable-provider.test.d.ts +2 -0
  33. package/dist/providers/tambo-interactable-provider.test.d.ts.map +1 -0
  34. package/dist/providers/tambo-interactable-provider.test.js +62 -0
  35. package/dist/providers/tambo-interactable-provider.test.js.map +1 -0
  36. package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js +8 -8
  37. package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
  38. package/dist/providers/tambo-interactables-additional-context.test.js +10 -10
  39. package/dist/providers/tambo-interactables-additional-context.test.js.map +1 -1
  40. package/dist/providers/tambo-registry-provider.test.js +28 -18
  41. package/dist/providers/tambo-registry-provider.test.js.map +1 -1
  42. package/dist/providers/tambo-registry-schema-compat.test.js +57 -28
  43. package/dist/providers/tambo-registry-schema-compat.test.js.map +1 -1
  44. package/dist/providers/tambo-thread-provider.test.js +21 -19
  45. package/dist/providers/tambo-thread-provider.test.js.map +1 -1
  46. package/dist/schema/alias.d.ts +3 -0
  47. package/dist/schema/alias.d.ts.map +1 -0
  48. package/dist/schema/alias.js +6 -0
  49. package/dist/schema/alias.js.map +1 -0
  50. package/dist/schema/json-schema.js +29 -29
  51. package/dist/schema/json-schema.js.map +1 -1
  52. package/dist/schema/schema.d.ts.map +1 -1
  53. package/dist/schema/schema.js +20 -9
  54. package/dist/schema/schema.js.map +1 -1
  55. package/dist/schema/schema.test.js +291 -3
  56. package/dist/schema/schema.test.js.map +1 -1
  57. package/dist/schema/standard-schema.js +8 -8
  58. package/dist/schema/standard-schema.js.map +1 -1
  59. package/dist/schema/validate.test.js +31 -31
  60. package/dist/schema/validate.test.js.map +1 -1
  61. package/dist/schema/zod.d.ts +1 -1
  62. package/dist/schema/zod.d.ts.map +1 -1
  63. package/dist/schema/zod.js +27 -26
  64. package/dist/schema/zod.js.map +1 -1
  65. package/dist/schema/zod.test.d.ts +2 -0
  66. package/dist/schema/zod.test.d.ts.map +1 -0
  67. package/dist/schema/zod.test.js +551 -0
  68. package/dist/schema/zod.test.js.map +1 -0
  69. package/dist/util/registry-validators.d.ts.map +1 -1
  70. package/dist/util/registry-validators.js +40 -0
  71. package/dist/util/registry-validators.js.map +1 -1
  72. package/dist/util/registry-validators.test.js +69 -0
  73. package/dist/util/registry-validators.test.js.map +1 -1
  74. package/dist/util/registry.d.ts +1 -5
  75. package/dist/util/registry.d.ts.map +1 -1
  76. package/dist/util/registry.js +1 -5
  77. package/dist/util/registry.js.map +1 -1
  78. package/dist/util/registry.test.js +80 -67
  79. package/dist/util/registry.test.js.map +1 -1
  80. package/esm/context-helpers/current-interactables-context-helper.d.ts +2 -2
  81. package/esm/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
  82. package/esm/context-helpers/current-interactables-context-helper.js +17 -23
  83. package/esm/context-helpers/current-interactables-context-helper.js.map +1 -1
  84. package/esm/hoc/with-tambo-interactable.d.ts.map +1 -1
  85. package/esm/hoc/with-tambo-interactable.js +0 -1
  86. package/esm/hoc/with-tambo-interactable.js.map +1 -1
  87. package/esm/hooks/use-component-state.d.ts +16 -1
  88. package/esm/hooks/use-component-state.d.ts.map +1 -1
  89. package/esm/hooks/use-component-state.js +74 -14
  90. package/esm/hooks/use-component-state.js.map +1 -1
  91. package/esm/hooks/use-component-state.test.js +40 -1
  92. package/esm/hooks/use-component-state.test.js.map +1 -1
  93. package/esm/hooks/use-current-message.d.ts +3 -0
  94. package/esm/hooks/use-current-message.d.ts.map +1 -1
  95. package/esm/hooks/use-current-message.js +2 -1
  96. package/esm/hooks/use-current-message.js.map +1 -1
  97. package/esm/hooks/use-current-message.test.js +5 -0
  98. package/esm/hooks/use-current-message.test.js.map +1 -1
  99. package/esm/model/component-metadata.d.ts +2 -2
  100. package/esm/model/component-metadata.d.ts.map +1 -1
  101. package/esm/model/component-metadata.js.map +1 -1
  102. package/esm/model/tambo-interactable.d.ts +6 -0
  103. package/esm/model/tambo-interactable.d.ts.map +1 -1
  104. package/esm/model/tambo-interactable.js.map +1 -1
  105. package/esm/providers/tambo-interactable-provider-partial-updates.test.js +1 -1
  106. package/esm/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
  107. package/esm/providers/tambo-interactable-provider.d.ts +1 -0
  108. package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
  109. package/esm/providers/tambo-interactable-provider.js +55 -19
  110. package/esm/providers/tambo-interactable-provider.js.map +1 -1
  111. package/esm/providers/tambo-interactable-provider.test.d.ts +2 -0
  112. package/esm/providers/tambo-interactable-provider.test.d.ts.map +1 -0
  113. package/esm/providers/tambo-interactable-provider.test.js +57 -0
  114. package/esm/providers/tambo-interactable-provider.test.js.map +1 -0
  115. package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js +1 -1
  116. package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
  117. package/esm/providers/tambo-interactables-additional-context.test.js +1 -1
  118. package/esm/providers/tambo-interactables-additional-context.test.js.map +1 -1
  119. package/esm/providers/tambo-registry-provider.test.js +16 -6
  120. package/esm/providers/tambo-registry-provider.test.js.map +1 -1
  121. package/esm/providers/tambo-registry-schema-compat.test.js +57 -28
  122. package/esm/providers/tambo-registry-schema-compat.test.js.map +1 -1
  123. package/esm/providers/tambo-thread-provider.test.js +8 -6
  124. package/esm/providers/tambo-thread-provider.test.js.map +1 -1
  125. package/esm/schema/alias.d.ts +3 -0
  126. package/esm/schema/alias.d.ts.map +1 -0
  127. package/esm/schema/alias.js +13 -0
  128. package/esm/schema/alias.js.map +1 -0
  129. package/esm/schema/json-schema.js +1 -1
  130. package/esm/schema/json-schema.js.map +1 -1
  131. package/esm/schema/schema.d.ts.map +1 -1
  132. package/esm/schema/schema.js +20 -9
  133. package/esm/schema/schema.js.map +1 -1
  134. package/esm/schema/schema.test.js +258 -3
  135. package/esm/schema/schema.test.js.map +1 -1
  136. package/esm/schema/standard-schema.js +1 -1
  137. package/esm/schema/standard-schema.js.map +1 -1
  138. package/esm/schema/validate.test.js +1 -1
  139. package/esm/schema/validate.test.js.map +1 -1
  140. package/esm/schema/zod.d.ts +1 -1
  141. package/esm/schema/zod.d.ts.map +1 -1
  142. package/esm/schema/zod.js +27 -26
  143. package/esm/schema/zod.js.map +1 -1
  144. package/esm/schema/zod.test.d.ts +2 -0
  145. package/esm/schema/zod.test.d.ts.map +1 -0
  146. package/esm/schema/zod.test.js +516 -0
  147. package/esm/schema/zod.test.js.map +1 -0
  148. package/esm/util/registry-validators.d.ts.map +1 -1
  149. package/esm/util/registry-validators.js +40 -0
  150. package/esm/util/registry-validators.js.map +1 -1
  151. package/esm/util/registry-validators.test.js +69 -0
  152. package/esm/util/registry-validators.test.js.map +1 -1
  153. package/esm/util/registry.d.ts +1 -5
  154. package/esm/util/registry.d.ts.map +1 -1
  155. package/esm/util/registry.js +1 -5
  156. package/esm/util/registry.js.map +1 -1
  157. package/esm/util/registry.test.js +80 -67
  158. package/esm/util/registry.test.js.map +1 -1
  159. package/package.json +2 -3
@@ -1 +1 @@
1
- {"version":3,"file":"registry.test.js","sourceRoot":"","sources":["../../src/util/registry.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,2CAA6B;AAC7B,2CAA6B;AAC7B,2CAA6B;AAC7B,4CAAgF;AAChF,yCAAuD;AAEvD,QAAQ,CAAC,6DAA6D,EAAE,GAAG,EAAE;IAC3E,QAAQ,CAAC,wDAAwD,EAAE,GAAG,EAAE;QACtE,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;YAC5C,MAAM,IAAI,GAAG,IAAA,oCAA4B,EACvC,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CACxE,CAAC;YACF,MAAM,MAAM,GAAG,IAAA,oCAAyB,EAAC,IAAI,CAAC,CAAC;YAC/C,mEAAmE;YACnE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,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E,CAAC,CAAC,MAAM,EAAE;aAChB,CAAC,CACH,CAAC;YACF,MAAM,MAAM,GAAG,IAAA,oCAAyB,EAAC,IAAI,CAAC,CAAC;YAC/C,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAC1C,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAChD,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,eAAe,EAAE,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;YACnD,MAAM,MAAM,GAAgB;gBAC1B,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBACxB,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;iBACxB;aACF,CAAC;YACF,MAAM,IAAI,GAAG,IAAA,sBAAc,EAAC,MAAM,CAAC,CAAC;YACpC,MAAM,MAAM,GAAG,IAAA,oCAAyB,EAAC,IAAI,CAAC,CAAC;YAC/C,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAC1C,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAChD,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,eAAe,EAAE,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Tests for getParametersFromToolSchema via mapTamboToolToContextTool.\n *\n * These tests verify that tool schemas are correctly converted to parameter specifications:\n *\n * **New interface (inputSchema)**:\n * - inputSchema should be an object schema (Zod object, Valibot object, JSON Schema object)\n * - Returns a single \"input\" parameter representing the full object schema\n * - Tool function receives single object argument: tool({ name: \"...\", age: 30 })\n *\n * **Deprecated interface (toolSchema)**:\n * - toolSchema uses z.function().args(...) pattern\n * - Returns positional parameters: param1, param2, etc.\n * - Tool function receives spread arguments: tool(value1, value2)\n */\nimport type { JSONSchema7 } from \"json-schema\";\nimport * as v from \"valibot\";\nimport * as z3 from \"zod/v3\";\nimport * as z4 from \"zod/v4\";\nimport { createMockTool, createMockToolWithToolSchema } from \"../testing/tools\";\nimport { mapTamboToolToContextTool } from \"./registry\";\n\ndescribe(\"getParametersFromToolSchema (via mapTamboToolToContextTool)\", () => {\n describe(\"Deprecated toolSchema interface (Zod function schemas)\", () => {\n it(\"should handle tool with toolSchema\", () => {\n const tool = createMockToolWithToolSchema(\n z3.function().args(z3.string().describe(\"The name\")).returns(z3.void()),\n );\n const result = mapTamboToolToContextTool(tool);\n // Should have at least one parameter (either extracted or wrapped)\n expect(result.parameters.length).toBeGreaterThanOrEqual(1);\n expect(result.name).toBe(\"testTool\");\n expect(result.description).toBe(\"A test tool\");\n });\n\n it(\"should handle toolSchema with multiple args\", () => {\n const tool = createMockToolWithToolSchema(\n z3\n .function()\n .args(\n z3.string().describe(\"First name\"),\n z3.number().describe(\"Age\"),\n z3.boolean().describe(\"Is active\"),\n )\n .returns(z3.void()),\n );\n const result = mapTamboToolToContextTool(tool);\n // Should have parameters (extraction depends on JSON Schema conversion)\n expect(result.parameters.length).toBeGreaterThanOrEqual(1);\n });\n });\n\n describe(\"New inputSchema interface (object schemas)\", () => {\n describe(\"Zod 4 object schemas\", () => {\n it(\"should return single input param with object schema\", () => {\n const tool = createMockTool({\n inputSchema: z4.object({\n name: z4.string().describe(\"User name\"),\n age: z4.number().describe(\"User age\"),\n }),\n outputSchema: z4.boolean(),\n });\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(1);\n expect(result.parameters[0].name).toBe(\"input\");\n expect(result.parameters[0].type).toBe(\"object\");\n expect(result.parameters).toMatchSnapshot();\n });\n\n it(\"should handle complex nested objects\", () => {\n const tool = createMockTool({\n inputSchema: z4.object({\n point: z4.object({ x: z4.number(), y: z4.number() }),\n tags: z4.array(z4.string()),\n color: z4.enum([\"red\", \"green\", \"blue\"]),\n }),\n outputSchema: z4.void(),\n });\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(1);\n expect(result.parameters[0].name).toBe(\"input\");\n expect(result.parameters).toMatchSnapshot();\n });\n });\n\n describe(\"Zod 3 object schemas\", () => {\n it(\"should return single input param with object schema\", () => {\n const tool = createMockTool({\n inputSchema: z3.object({\n name: z3.string(),\n age: z3.number(),\n }),\n outputSchema: z3.boolean(),\n });\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(1);\n expect(result.parameters[0].name).toBe(\"input\");\n expect(result.parameters).toMatchSnapshot();\n });\n });\n\n describe(\"Valibot object schemas\", () => {\n it(\"should return single input param with object schema\", () => {\n const tool = createMockTool({\n inputSchema: v.object({\n name: v.string(),\n age: v.number(),\n }),\n outputSchema: v.boolean(),\n });\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(1);\n expect(result.parameters[0].name).toBe(\"input\");\n expect(result.parameters).toMatchSnapshot();\n });\n\n it(\"should handle complex nested objects\", () => {\n const tool = createMockTool({\n inputSchema: v.object({\n point: v.pipe(\n v.object({ x: v.number(), y: v.number() }),\n v.description(\"Point\"),\n ),\n tags: v.array(v.string()),\n color: v.picklist([\"red\", \"green\", \"blue\"]),\n }),\n outputSchema: v.undefined(),\n });\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(1);\n expect(result.parameters[0].name).toBe(\"input\");\n expect(result.parameters).toMatchSnapshot();\n });\n });\n\n describe(\"JSON Schema object schemas\", () => {\n it(\"should return single input param with object schema\", () => {\n const schema: JSONSchema7 = {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n age: { type: \"number\" },\n },\n required: [\"name\"],\n description: \"User data\",\n };\n const tool = createMockTool({ inputSchema: schema, outputSchema: {} });\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(1);\n expect(result.parameters[0].name).toBe(\"input\");\n expect(result.parameters[0].type).toBe(\"object\");\n expect(result.parameters[0].description).toBe(\"User data\");\n expect(result.parameters).toMatchSnapshot();\n });\n });\n });\n\n describe(\"Direct schema (shorthand for inputSchema)\", () => {\n it(\"should accept Zod 4 object schema directly\", () => {\n const tool = createMockTool(\n z4.object({\n name: z4.string(),\n age: z4.number(),\n }),\n );\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(1);\n expect(result.parameters[0].name).toBe(\"input\");\n expect(result.parameters).toMatchSnapshot();\n });\n\n it(\"should accept Zod 3 object schema directly\", () => {\n const tool = createMockTool(\n z3.object({\n name: z3.string(),\n age: z3.number(),\n }),\n );\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(1);\n expect(result.parameters[0].name).toBe(\"input\");\n expect(result.parameters).toMatchSnapshot();\n });\n\n it(\"should accept Valibot object schema directly\", () => {\n const tool = createMockTool(\n v.object({\n name: v.string(),\n age: v.number(),\n }),\n );\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(1);\n expect(result.parameters[0].name).toBe(\"input\");\n expect(result.parameters).toMatchSnapshot();\n });\n\n it(\"should accept JSON Schema object directly\", () => {\n const schema: JSONSchema7 = {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n age: { type: \"number\" },\n },\n };\n const tool = createMockTool(schema);\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(1);\n expect(result.parameters[0].name).toBe(\"input\");\n expect(result.parameters).toMatchSnapshot();\n });\n });\n});\n"]}
1
+ {"version":3,"file":"registry.test.js","sourceRoot":"","sources":["../../src/util/registry.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,2CAA6B;AAC7B,2CAA6B;AAC7B,4CAAgF;AAChF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AI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBACxB,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;iBACxB;aACF,CAAC;YACF,MAAM,IAAI,GAAG,IAAA,sBAAc,EAAC,MAAM,CAAC,CAAC;YACpC,MAAM,MAAM,GAAG,IAAA,oCAAyB,EAAC,IAAI,CAAC,CAAC;YAC/C,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAE1C,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;YACnE,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC;YAEjE,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;YAChC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAEvC,MAAM,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;YAC/B,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAEtC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,eAAe,EAAE,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Tests for getParametersFromToolSchema via mapTamboToolToContextTool.\n *\n * These tests verify that tool schemas are correctly converted to parameter specifications:\n *\n * **New interface (inputSchema)**:\n * - inputSchema should be an object schema (Zod object, Valibot object, JSON Schema object)\n * - Returns an array of parameters extracted from the object's properties\n * - Tool function receives single object argument: tool({ name: \"...\", age: 30 })\n *\n * **Deprecated interface (toolSchema)**:\n * - toolSchema uses z.function().args(...) pattern\n * - Returns positional parameters: param1, param2, etc.\n * - Tool function receives spread arguments: tool(value1, value2)\n */\nimport type { JSONSchema7 } from \"json-schema\";\nimport * as z3 from \"zod/v3\";\nimport * as z4 from \"zod/v4\";\nimport { createMockTool, createMockToolWithToolSchema } from \"../testing/tools\";\nimport { mapTamboToolToContextTool } from \"./registry\";\n\ndescribe(\"getParametersFromToolSchema (via mapTamboToolToContextTool)\", () => {\n describe(\"Deprecated toolSchema interface (Zod function schemas)\", () => {\n it(\"should handle tool with toolSchema\", () => {\n const tool = createMockToolWithToolSchema(\n z3.function().args(z3.string().describe(\"The name\")).returns(z3.void()),\n );\n const result = mapTamboToolToContextTool(tool);\n // Should have at least one parameter (either extracted or wrapped)\n expect(result.parameters.length).toBeGreaterThanOrEqual(1);\n expect(result.name).toBe(\"testTool\");\n expect(result.description).toBe(\"A test tool\");\n });\n\n it(\"should handle toolSchema with multiple args\", () => {\n const tool = createMockToolWithToolSchema(\n z3\n .function()\n .args(\n z3.string().describe(\"First name\"),\n z3.number().describe(\"Age\"),\n z3.boolean().describe(\"Is active\"),\n )\n .returns(z3.void()),\n );\n const result = mapTamboToolToContextTool(tool);\n // Should have parameters (extraction depends on JSON Schema conversion)\n expect(result.parameters.length).toBeGreaterThanOrEqual(1);\n });\n });\n\n describe(\"New inputSchema interface (object schemas)\", () => {\n describe(\"Zod 4 object schemas\", () => {\n it(\"should extract parameters from object schema properties\", () => {\n const tool = createMockTool({\n inputSchema: z4.object({\n name: z4.string().describe(\"User name\"),\n age: z4.number().describe(\"User age\"),\n }),\n outputSchema: z4.boolean(),\n });\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(2);\n\n // Parameters should be extracted from object properties\n const nameParam = result.parameters.find((p) => p.name === \"name\");\n const ageParam = result.parameters.find((p) => p.name === \"age\");\n\n expect(nameParam).toBeDefined();\n expect(nameParam?.type).toBe(\"string\");\n expect(nameParam?.description).toBe(\"User name\");\n expect(nameParam?.isRequired).toBe(true);\n\n expect(ageParam).toBeDefined();\n expect(ageParam?.type).toBe(\"number\");\n expect(ageParam?.description).toBe(\"User age\");\n expect(ageParam?.isRequired).toBe(true);\n\n expect(result.parameters).toMatchSnapshot();\n });\n\n it(\"should handle complex nested objects\", () => {\n const tool = createMockTool({\n inputSchema: z4.object({\n point: z4.object({ x: z4.number(), y: z4.number() }),\n tags: z4.array(z4.string()),\n color: z4.enum([\"red\", \"green\", \"blue\"]),\n }),\n outputSchema: z4.void(),\n });\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(3);\n\n const pointParam = result.parameters.find((p) => p.name === \"point\");\n const tagsParam = result.parameters.find((p) => p.name === \"tags\");\n const colorParam = result.parameters.find((p) => p.name === \"color\");\n\n expect(pointParam).toBeDefined();\n expect(pointParam?.type).toBe(\"object\");\n\n expect(tagsParam).toBeDefined();\n expect(tagsParam?.type).toBe(\"array\");\n\n expect(colorParam).toBeDefined();\n expect(colorParam?.type).toBe(\"string\");\n\n expect(result.parameters).toMatchSnapshot();\n });\n });\n\n describe(\"Zod 3 object schemas\", () => {\n it(\"should extract parameters from object schema properties\", () => {\n const tool = createMockTool({\n inputSchema: z3.object({\n name: z3.string().describe(\"User name\"),\n age: z3.number().describe(\"User age\"),\n }),\n outputSchema: z3.boolean(),\n });\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(2);\n\n const nameParam = result.parameters.find((p) => p.name === \"name\");\n const ageParam = result.parameters.find((p) => p.name === \"age\");\n\n expect(nameParam).toBeDefined();\n expect(nameParam?.type).toBe(\"string\");\n expect(nameParam?.isRequired).toBe(true);\n\n expect(ageParam).toBeDefined();\n expect(ageParam?.type).toBe(\"number\");\n expect(ageParam?.isRequired).toBe(true);\n\n expect(result.parameters).toMatchSnapshot();\n });\n });\n\n describe(\"JSON Schema object schemas\", () => {\n it(\"should extract parameters from object schema properties\", () => {\n const schema: JSONSchema7 = {\n type: \"object\",\n properties: {\n name: { type: \"string\", description: \"User name\" },\n age: { type: \"number\", description: \"User age\" },\n },\n required: [\"name\"],\n description: \"User data\",\n };\n const tool = createMockTool({ inputSchema: schema, outputSchema: {} });\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(2);\n\n const nameParam = result.parameters.find((p) => p.name === \"name\");\n const ageParam = result.parameters.find((p) => p.name === \"age\");\n\n expect(nameParam).toBeDefined();\n expect(nameParam?.type).toBe(\"string\");\n expect(nameParam?.description).toBe(\"User name\");\n expect(nameParam?.isRequired).toBe(true);\n\n expect(ageParam).toBeDefined();\n expect(ageParam?.type).toBe(\"number\");\n expect(ageParam?.description).toBe(\"User age\");\n expect(ageParam?.isRequired).toBe(false);\n\n expect(result.parameters).toMatchSnapshot();\n });\n\n it(\"should handle empty object schema\", () => {\n const schema: JSONSchema7 = {\n type: \"object\",\n properties: {},\n };\n const tool = createMockTool({ inputSchema: schema, outputSchema: {} });\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(0);\n });\n });\n });\n\n describe(\"Direct schema (shorthand for inputSchema)\", () => {\n it(\"should accept Zod 4 object schema directly and extract parameters\", () => {\n const tool = createMockTool(\n z4.object({\n name: z4.string(),\n age: z4.number(),\n }),\n );\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(2);\n\n const nameParam = result.parameters.find((p) => p.name === \"name\");\n const ageParam = result.parameters.find((p) => p.name === \"age\");\n\n expect(nameParam).toBeDefined();\n expect(nameParam?.type).toBe(\"string\");\n\n expect(ageParam).toBeDefined();\n expect(ageParam?.type).toBe(\"number\");\n\n expect(result.parameters).toMatchSnapshot();\n });\n\n it(\"should accept Zod 3 object schema directly and extract parameters\", () => {\n const tool = createMockTool(\n z3.object({\n name: z3.string(),\n age: z3.number(),\n }),\n );\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(2);\n\n const nameParam = result.parameters.find((p) => p.name === \"name\");\n const ageParam = result.parameters.find((p) => p.name === \"age\");\n\n expect(nameParam).toBeDefined();\n expect(ageParam).toBeDefined();\n\n expect(result.parameters).toMatchSnapshot();\n });\n\n it(\"should accept JSON Schema object directly and extract parameters\", () => {\n const schema: JSONSchema7 = {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n age: { type: \"number\" },\n },\n };\n const tool = createMockTool(schema);\n const result = mapTamboToolToContextTool(tool);\n expect(result.parameters).toHaveLength(2);\n\n const nameParam = result.parameters.find((p) => p.name === \"name\");\n const ageParam = result.parameters.find((p) => p.name === \"age\");\n\n expect(nameParam).toBeDefined();\n expect(nameParam?.type).toBe(\"string\");\n\n expect(ageParam).toBeDefined();\n expect(ageParam?.type).toBe(\"number\");\n\n expect(result.parameters).toMatchSnapshot();\n });\n });\n});\n"]}
@@ -21,8 +21,8 @@ export declare const currentInteractablesContextHelper: ContextHelperFn;
21
21
  /**
22
22
  * Creates an interactables context helper with access to the current components.
23
23
  * This is used internally by TamboInteractableProvider.
24
- * @param getComponents Function to get current interactable components
24
+ * @param components Array of interactable components
25
25
  * @returns Context helper function
26
26
  */
27
- export declare const createInteractablesContextHelper: (getComponents: () => any[]) => ContextHelperFn;
27
+ export declare const createInteractablesContextHelper: (components: any[]) => ContextHelperFn;
28
28
  //# sourceMappingURL=current-interactables-context-helper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"current-interactables-context-helper.d.ts","sourceRoot":"","sources":["../../src/context-helpers/current-interactables-context-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,iCAAiC,EAAE,eAI/C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,GAC3C,eAAe,MAAM,GAAG,EAAE,KACzB,eA2BF,CAAC"}
1
+ {"version":3,"file":"current-interactables-context-helper.d.ts","sourceRoot":"","sources":["../../src/context-helpers/current-interactables-context-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,iCAAiC,EAAE,eAI/C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,GAC3C,YAAY,GAAG,EAAE,KAChB,eAqBF,CAAC"}
@@ -24,33 +24,27 @@ export const currentInteractablesContextHelper = () => {
24
24
  /**
25
25
  * Creates an interactables context helper with access to the current components.
26
26
  * This is used internally by TamboInteractableProvider.
27
- * @param getComponents Function to get current interactable components
27
+ * @param components Array of interactable components
28
28
  * @returns Context helper function
29
29
  */
30
- export const createInteractablesContextHelper = (getComponents) => {
30
+ export const createInteractablesContextHelper = (components) => {
31
31
  return () => {
32
- try {
33
- const components = getComponents();
34
- if (!Array.isArray(components) || components.length === 0) {
35
- return null; // No interactable components on the page
36
- }
37
- return {
38
- description: "These are the interactable components currently visible on the page that you can read and modify. Each component has an id, componentName, current props, and optional schema. You can use tools to update these components on behalf of the user.",
39
- components: components.map((component) => ({
40
- id: component.id,
41
- componentName: component.name,
42
- description: component.description,
43
- props: component.props,
44
- propsSchema: component.propsSchema
45
- ? "Available - use component-specific update tools"
46
- : "Not specified",
47
- })),
48
- };
49
- }
50
- catch (e) {
51
- console.error("currentInteractablesContextHelper failed:", e);
52
- return null;
32
+ if (!Array.isArray(components) || components.length === 0) {
33
+ return null; // No interactable components on the page
53
34
  }
35
+ return {
36
+ description: "These are the interactable components currently visible on the page that you can read and modify. Each component has an id, componentName, current props, current state,and optional schema. You can use tools to update these components on behalf of the user. Don't tell the user the ID of the components, only the name, unless they ask for it.",
37
+ components: components.map((component) => ({
38
+ id: component.id,
39
+ componentName: component.name,
40
+ description: component.description,
41
+ props: component.props,
42
+ propsSchema: component.propsSchema
43
+ ? "Available - use component-specific update tools"
44
+ : "Not specified",
45
+ state: component.state,
46
+ })),
47
+ };
54
48
  };
55
49
  };
56
50
  //# sourceMappingURL=current-interactables-context-helper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"current-interactables-context-helper.js","sourceRoot":"","sources":["../../src/context-helpers/current-interactables-context-helper.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAoB,GAAG,EAAE;IACrE,mFAAmF;IACnF,wEAAwE;IACxE,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAC9C,aAA0B,EACT,EAAE;IACnB,OAAO,GAAG,EAAE;QACV,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;YAEnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC1D,OAAO,IAAI,CAAC,CAAC,yCAAyC;YACxD,CAAC;YAED,OAAO;gBACL,WAAW,EACT,oPAAoP;gBACtP,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;oBACzC,EAAE,EAAE,SAAS,CAAC,EAAE;oBAChB,aAAa,EAAE,SAAS,CAAC,IAAI;oBAC7B,WAAW,EAAE,SAAS,CAAC,WAAW;oBAClC,KAAK,EAAE,SAAS,CAAC,KAAK;oBACtB,WAAW,EAAE,SAAS,CAAC,WAAW;wBAChC,CAAC,CAAC,iDAAiD;wBACnD,CAAC,CAAC,eAAe;iBACpB,CAAC,CAAC;aACJ,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,2CAA2C,EAAE,CAAC,CAAC,CAAC;YAC9D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { ContextHelperFn } from \"./types\";\n\n/**\n * Prebuilt context helper that provides information about all interactable components currently on the page.\n * This gives the AI awareness of what components it can interact with and their current state.\n * @returns an object with description and components, or null to skip including this context.\n * To disable this helper, override it with a function that returns null:\n * @example\n * ```tsx\n * // To disable the default interactables context\n * const { addContextHelper } = useTamboContextHelpers();\n * addContextHelper(\"interactables\", () => null);\n *\n * // To customize the context\n * addContextHelper(\"interactables\", () => ({\n * description: \"Custom description\",\n * components: getCustomComponentsSubset()\n * }));\n * ```\n */\nexport const currentInteractablesContextHelper: ContextHelperFn = () => {\n // This will be provided by the interactable provider when it registers this helper\n // Since we're provider-only now, this function gets replaced at runtime\n return null;\n};\n\n/**\n * Creates an interactables context helper with access to the current components.\n * This is used internally by TamboInteractableProvider.\n * @param getComponents Function to get current interactable components\n * @returns Context helper function\n */\nexport const createInteractablesContextHelper = (\n getComponents: () => any[],\n): ContextHelperFn => {\n return () => {\n try {\n const components = getComponents();\n\n if (!Array.isArray(components) || components.length === 0) {\n return null; // No interactable components on the page\n }\n\n return {\n description:\n \"These are the interactable components currently visible on the page that you can read and modify. Each component has an id, componentName, current props, and optional schema. You can use tools to update these components on behalf of the user.\",\n components: components.map((component) => ({\n id: component.id,\n componentName: component.name,\n description: component.description,\n props: component.props,\n propsSchema: component.propsSchema\n ? \"Available - use component-specific update tools\"\n : \"Not specified\",\n })),\n };\n } catch (e) {\n console.error(\"currentInteractablesContextHelper failed:\", e);\n return null;\n }\n };\n};\n"]}
1
+ {"version":3,"file":"current-interactables-context-helper.js","sourceRoot":"","sources":["../../src/context-helpers/current-interactables-context-helper.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAoB,GAAG,EAAE;IACrE,mFAAmF;IACnF,wEAAwE;IACxE,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAC9C,UAAiB,EACA,EAAE;IACnB,OAAO,GAAG,EAAE;QACV,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1D,OAAO,IAAI,CAAC,CAAC,yCAAyC;QACxD,CAAC;QAED,OAAO;YACL,WAAW,EACT,uVAAuV;YACzV,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;gBACzC,EAAE,EAAE,SAAS,CAAC,EAAE;gBAChB,aAAa,EAAE,SAAS,CAAC,IAAI;gBAC7B,WAAW,EAAE,SAAS,CAAC,WAAW;gBAClC,KAAK,EAAE,SAAS,CAAC,KAAK;gBACtB,WAAW,EAAE,SAAS,CAAC,WAAW;oBAChC,CAAC,CAAC,iDAAiD;oBACnD,CAAC,CAAC,eAAe;gBACnB,KAAK,EAAE,SAAS,CAAC,KAAK;aACvB,CAAC,CAAC;SACJ,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { ContextHelperFn } from \"./types\";\n\n/**\n * Prebuilt context helper that provides information about all interactable components currently on the page.\n * This gives the AI awareness of what components it can interact with and their current state.\n * @returns an object with description and components, or null to skip including this context.\n * To disable this helper, override it with a function that returns null:\n * @example\n * ```tsx\n * // To disable the default interactables context\n * const { addContextHelper } = useTamboContextHelpers();\n * addContextHelper(\"interactables\", () => null);\n *\n * // To customize the context\n * addContextHelper(\"interactables\", () => ({\n * description: \"Custom description\",\n * components: getCustomComponentsSubset()\n * }));\n * ```\n */\nexport const currentInteractablesContextHelper: ContextHelperFn = () => {\n // This will be provided by the interactable provider when it registers this helper\n // Since we're provider-only now, this function gets replaced at runtime\n return null;\n};\n\n/**\n * Creates an interactables context helper with access to the current components.\n * This is used internally by TamboInteractableProvider.\n * @param components Array of interactable components\n * @returns Context helper function\n */\nexport const createInteractablesContextHelper = (\n components: any[],\n): ContextHelperFn => {\n return () => {\n if (!Array.isArray(components) || components.length === 0) {\n return null; // No interactable components on the page\n }\n\n return {\n description:\n \"These are the interactable components currently visible on the page that you can read and modify. Each component has an id, componentName, current props, current state,and optional schema. You can use tools to update these components on behalf of the user. Don't tell the user the ID of the components, only the name, unless they ask for it.\",\n components: components.map((component) => ({\n id: component.id,\n componentName: component.name,\n description: component.description,\n props: component.props,\n propsSchema: component.propsSchema\n ? \"Available - use component-specific update tools\"\n : \"Not specified\",\n state: component.state,\n })),\n };\n };\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"with-tambo-interactable.d.ts","sourceRoot":"","sources":["../../src/hoc/with-tambo-interactable.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAIxE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B;AAED,MAAM,WAAW,0BAA0B;IACzC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mBAAmB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;CACzD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,EACpD,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EACxC,MAAM,EAAE,kBAAkB,4CAgH3B"}
1
+ {"version":3,"file":"with-tambo-interactable.d.ts","sourceRoot":"","sources":["../../src/hoc/with-tambo-interactable.tsx"],"names":[],"mappings":"AACA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAIxE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B;AAED,MAAM,WAAW,0BAA0B;IACzC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mBAAmB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;CACzD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,EACpD,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EACxC,MAAM,EAAE,kBAAkB,4CAgH3B"}
@@ -1,4 +1,3 @@
1
- // react-sdk/src/providers/with-interactable.tsx
2
1
  "use client";
3
2
  import React, { useCallback, useEffect, useRef, useState } from "react";
4
3
  import { TamboMessageProvider } from "../hooks/use-current-message";
@@ -1 +1 @@
1
- {"version":3,"file":"with-tambo-interactable.js","sourceRoot":"","sources":["../../src/hoc/with-tambo-interactable.tsx"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAehF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,qBAAqB,CACnC,gBAAwC,EACxC,MAA0B;IAE1B,MAAM,WAAW,GACf,gBAAgB,CAAC,WAAW,IAAI,gBAAgB,CAAC,IAAI,IAAI,WAAW,CAAC;IAEvE,MAAM,wBAAwB,GAA6C,CACzE,KAAK,EACL,EAAE;QACF,MAAM,EACJ,wBAAwB,EACxB,gCAAgC,EAChC,wBAAwB,GACzB,GAAG,oBAAoB,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gB,OAAM,cAAoB,GAAI,CAC1B,CACxB,CAAC;IACJ,CAAC,CAAC;IAEF,wBAAwB,CAAC,WAAW,GAAG,yBAAyB,WAAW,GAAG,CAAC;IAE/E,OAAO,wBAAwB,CAAC;AAClC,CAAC","sourcesContent":["// react-sdk/src/providers/with-interactable.tsx\n\"use client\";\nimport React, { useCallback, useEffect, useRef, useState } from \"react\";\nimport { TamboMessageProvider } from \"../hooks/use-current-message\";\nimport { TamboThreadMessage } from \"../model/generate-component-response\";\nimport { useTamboInteractable } from \"../providers/tambo-interactable-provider\";\nimport { SupportedSchema } from \"../schema\";\n\nexport interface InteractableConfig {\n componentName: string;\n description: string;\n propsSchema?: SupportedSchema;\n}\n\nexport interface WithTamboInteractableProps {\n interactableId?: string;\n onInteractableReady?: (id: string) => void;\n onPropsUpdate?: (newProps: Record<string, any>) => void;\n}\n\n/**\n * Higher-Order Component that makes any component interactable by tambo.\n * @param WrappedComponent - The component to make interactable\n * @param config - Configuration for the interactable component\n * @returns A new component that is automatically registered as interactable\n * @example\n * ```tsx\n * const MyInteractableNote = withTamboInteractable(MyNote, {\n * componentName: \"MyNote\",\n * description: \"A note component\",\n * propsSchema: z.object({\n * title: z.string(),\n * content: z.string(),\n * }),\n * });\n *\n * // Usage\n * <MyInteractableNote title=\"My Note\" content=\"This is my note\" />\n * ```\n */\nexport function withTamboInteractable<P extends object>(\n WrappedComponent: React.ComponentType<P>,\n config: InteractableConfig,\n) {\n const displayName =\n WrappedComponent.displayName ?? WrappedComponent.name ?? \"Component\";\n\n const TamboInteractableWrapper: React.FC<P & WithTamboInteractableProps> = (\n props,\n ) => {\n const {\n addInteractableComponent,\n updateInteractableComponentProps,\n getInteractableComponent,\n } = useTamboInteractable();\n\n const [interactableId, setInteractableId] = useState<string | null>(null);\n const isInitialized = useRef(false);\n const lastParentProps = useRef<Record<string, any>>({});\n\n // Extract interactable-specific props\n const { onInteractableReady, onPropsUpdate, ...componentProps } = props;\n\n // Get the current interactable component to track prop updates\n const currentInteractable = interactableId\n ? getInteractableComponent(interactableId)\n : null;\n\n // Use the props from the interactable component if available, otherwise use the passed props\n // We need to be careful not to create a loop, so we only use stored props if they're different from passed props\n const effectiveProps = currentInteractable?.props ?? componentProps;\n\n // Memoize the registration function\n const registerComponent = useCallback(() => {\n if (!isInitialized.current) {\n const id = addInteractableComponent({\n name: config.componentName,\n description: config.description,\n component: WrappedComponent,\n props: componentProps,\n propsSchema: config.propsSchema,\n });\n\n setInteractableId(id);\n onInteractableReady?.(id);\n isInitialized.current = true;\n }\n }, [addInteractableComponent, componentProps, onInteractableReady]);\n\n // Register the component as interactable on mount (only once)\n useEffect(() => {\n registerComponent();\n }, [registerComponent]);\n\n // Update the interactable component when props change from parent\n useEffect(() => {\n if (interactableId && isInitialized.current) {\n // Only update if the props are different from what we last sent\n const lastPropsString = JSON.stringify(lastParentProps.current);\n const currentPropsString = JSON.stringify(componentProps);\n\n if (lastPropsString !== currentPropsString) {\n updateInteractableComponentProps(interactableId, componentProps);\n onPropsUpdate?.(componentProps);\n lastParentProps.current = componentProps;\n }\n }\n }, [\n interactableId,\n componentProps,\n updateInteractableComponentProps,\n onPropsUpdate,\n ]);\n\n // If the interactable ID is not yet set, render the component without provider\n if (!interactableId) {\n return <WrappedComponent {...(effectiveProps as P)} />;\n }\n\n // Create a minimal message with interactable metadata\n // This allows useTamboCurrentComponent to work with standalone interactable components\n const minimalMessage: TamboThreadMessage = {\n id: interactableId,\n role: \"assistant\" as const,\n content: [],\n threadId: \"\",\n createdAt: new Date().toISOString(),\n component: {\n componentName: config.componentName,\n componentState: {},\n message: \"\",\n props: effectiveProps,\n },\n componentState: {},\n };\n\n // Wrap with TamboMessageProvider including interactable metadata\n return (\n <TamboMessageProvider\n message={minimalMessage}\n interactableMetadata={{\n id: interactableId,\n componentName: config.componentName,\n description: config.description,\n }}\n >\n <WrappedComponent {...(effectiveProps as P)} />\n </TamboMessageProvider>\n );\n };\n\n TamboInteractableWrapper.displayName = `withTamboInteractable(${displayName})`;\n\n return TamboInteractableWrapper;\n}\n"]}
1
+ {"version":3,"file":"with-tambo-interactable.js","sourceRoot":"","sources":["../../src/hoc/with-tambo-interactable.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAehF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,qBAAqB,CACnC,gBAAwC,EACxC,MAA0B;IAE1B,MAAM,WAAW,GACf,gBAAgB,CAAC,WAAW,IAAI,gBAAgB,CAAC,IAAI,IAAI,WAAW,CAAC;IAEvE,MAAM,wBAAwB,GAA6C,CACzE,KAAK,EACL,EAAE;QACF,MAAM,EACJ,wBAAwB,EACxB,gCAAgC,EAChC,wBAAwB,GACzB,GAAG,oBAAoB,EAAE,CAAC;QAE3B,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;QAC1E,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACpC,MAAM,eAAe,GAAG,MAAM,CAAsB,EAAE,CAAC,CAAC;QAExD,sCAAsC;QACtC,MAAM,EAAE,mBAAmB,EAAE,aAAa,EAAE,GAAG,cAAc,EAAE,GAAG,KAAK,CAAC;QAExE,+DAA+D;QAC/D,MAAM,mBAAmB,GAAG,cAAc;YACxC,CAAC,CAAC,wBAAwB,CAAC,cAAc,CAAC;YAC1C,CAAC,CAAC,IAAI,CAAC;QAET,6FAA6F;QAC7F,iHAAiH;QACjH,MAAM,cAAc,GAAG,mBAAmB,EAAE,KAAK,IAAI,cAAc,CAAC;QAEpE,oCAAoC;QACpC,MAAM,iBAAiB,GAAG,WAAW,CAAC,GAAG,EAAE;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OAAO,oBAAC,gBAAgB,OAAM,cAAoB,GAAI,CAAC;QACzD,CAAC;QAED,sDAAsD;QACtD,uFAAuF;QACvF,MAAM,cAAc,GAAuB;YACzC,EAAE,EAAE,cAAc;YAClB,IAAI,EAAE,WAAoB;YAC1B,OAAO,EAAE,EAAE;YACX,QAAQ,EAAE,EAAE;YACZ,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,SAAS,EAAE;gBACT,aAAa,EAAE,MAAM,CAAC,aAAa;gBACnC,cAAc,EAAE,EAAE;gBAClB,OAAO,EAAE,EAAE;gBACX,KAAK,EAAE,cAAc;aACtB;YACD,cAAc,EAAE,EAAE;SACnB,CAAC;QAEF,iEAAiE;QACjE,OAAO,CACL,oBAAC,oBAAoB,IACnB,OAAO,EAAE,cAAc,EACvB,oBAAoB,EAAE;gBACpB,EAAE,EAAE,cAAc;gBAClB,aAAa,EAAE,MAAM,CAAC,aAAa;gBACnC,WAAW,EAAE,MAAM,CAAC,WAAW;aAChC;YAED,oBAAC,gBAAgB,OAAM,cAAoB,GAAI,CAC1B,CACxB,CAAC;IACJ,CAAC,CAAC;IAEF,wBAAwB,CAAC,WAAW,GAAG,yBAAyB,WAAW,GAAG,CAAC;IAE/E,OAAO,wBAAwB,CAAC;AAClC,CAAC","sourcesContent":["\"use client\";\nimport React, { useCallback, useEffect, useRef, useState } from \"react\";\nimport { TamboMessageProvider } from \"../hooks/use-current-message\";\nimport { TamboThreadMessage } from \"../model/generate-component-response\";\nimport { useTamboInteractable } from \"../providers/tambo-interactable-provider\";\nimport { SupportedSchema } from \"../schema\";\n\nexport interface InteractableConfig {\n componentName: string;\n description: string;\n propsSchema?: SupportedSchema;\n}\n\nexport interface WithTamboInteractableProps {\n interactableId?: string;\n onInteractableReady?: (id: string) => void;\n onPropsUpdate?: (newProps: Record<string, any>) => void;\n}\n\n/**\n * Higher-Order Component that makes any component interactable by tambo.\n * @param WrappedComponent - The component to make interactable\n * @param config - Configuration for the interactable component\n * @returns A new component that is automatically registered as interactable\n * @example\n * ```tsx\n * const MyInteractableNote = withTamboInteractable(MyNote, {\n * componentName: \"MyNote\",\n * description: \"A note component\",\n * propsSchema: z.object({\n * title: z.string(),\n * content: z.string(),\n * }),\n * });\n *\n * // Usage\n * <MyInteractableNote title=\"My Note\" content=\"This is my note\" />\n * ```\n */\nexport function withTamboInteractable<P extends object>(\n WrappedComponent: React.ComponentType<P>,\n config: InteractableConfig,\n) {\n const displayName =\n WrappedComponent.displayName ?? WrappedComponent.name ?? \"Component\";\n\n const TamboInteractableWrapper: React.FC<P & WithTamboInteractableProps> = (\n props,\n ) => {\n const {\n addInteractableComponent,\n updateInteractableComponentProps,\n getInteractableComponent,\n } = useTamboInteractable();\n\n const [interactableId, setInteractableId] = useState<string | null>(null);\n const isInitialized = useRef(false);\n const lastParentProps = useRef<Record<string, any>>({});\n\n // Extract interactable-specific props\n const { onInteractableReady, onPropsUpdate, ...componentProps } = props;\n\n // Get the current interactable component to track prop updates\n const currentInteractable = interactableId\n ? getInteractableComponent(interactableId)\n : null;\n\n // Use the props from the interactable component if available, otherwise use the passed props\n // We need to be careful not to create a loop, so we only use stored props if they're different from passed props\n const effectiveProps = currentInteractable?.props ?? componentProps;\n\n // Memoize the registration function\n const registerComponent = useCallback(() => {\n if (!isInitialized.current) {\n const id = addInteractableComponent({\n name: config.componentName,\n description: config.description,\n component: WrappedComponent,\n props: componentProps,\n propsSchema: config.propsSchema,\n });\n\n setInteractableId(id);\n onInteractableReady?.(id);\n isInitialized.current = true;\n }\n }, [addInteractableComponent, componentProps, onInteractableReady]);\n\n // Register the component as interactable on mount (only once)\n useEffect(() => {\n registerComponent();\n }, [registerComponent]);\n\n // Update the interactable component when props change from parent\n useEffect(() => {\n if (interactableId && isInitialized.current) {\n // Only update if the props are different from what we last sent\n const lastPropsString = JSON.stringify(lastParentProps.current);\n const currentPropsString = JSON.stringify(componentProps);\n\n if (lastPropsString !== currentPropsString) {\n updateInteractableComponentProps(interactableId, componentProps);\n onPropsUpdate?.(componentProps);\n lastParentProps.current = componentProps;\n }\n }\n }, [\n interactableId,\n componentProps,\n updateInteractableComponentProps,\n onPropsUpdate,\n ]);\n\n // If the interactable ID is not yet set, render the component without provider\n if (!interactableId) {\n return <WrappedComponent {...(effectiveProps as P)} />;\n }\n\n // Create a minimal message with interactable metadata\n // This allows useTamboCurrentComponent to work with standalone interactable components\n const minimalMessage: TamboThreadMessage = {\n id: interactableId,\n role: \"assistant\" as const,\n content: [],\n threadId: \"\",\n createdAt: new Date().toISOString(),\n component: {\n componentName: config.componentName,\n componentState: {},\n message: \"\",\n props: effectiveProps,\n },\n componentState: {},\n };\n\n // Wrap with TamboMessageProvider including interactable metadata\n return (\n <TamboMessageProvider\n message={minimalMessage}\n interactableMetadata={{\n id: interactableId,\n componentName: config.componentName,\n description: config.description,\n }}\n >\n <WrappedComponent {...(effectiveProps as P)} />\n </TamboMessageProvider>\n );\n };\n\n TamboInteractableWrapper.displayName = `withTamboInteractable(${displayName})`;\n\n return TamboInteractableWrapper;\n}\n"]}
@@ -1,6 +1,21 @@
1
1
  type StateUpdateResult<T> = [currentState: T, setState: (newState: T) => void];
2
2
  /**
3
- * Like useState, but syncs to the thread message's `componentState`.
3
+ * A React hook that acts like useState, but also automatically updates the thread message's componentState.
4
+ * If used within an interactable component (wrapped with withTamboInteractable), it updates the
5
+ * interactable provider's global state (sent to Tambo on every request) instead of the remote thread message state.
6
+ * For generated components, it updates both the local and remote thread message's componentState.
7
+ *
8
+ * Benefits: Passes user changes to AI, and when threads are returned, state is preserved.
9
+ * Works in both generative and interactable component contexts.
10
+ * @param keyName - The unique key to identify this state value within the message's componentState object
11
+ * @param initialValue - Optional initial value for the state, used if no componentState value exists in the Tambo message containing this hook usage.
12
+ * @param setFromProp - Optional value used to set the state value, only while no componentState value exists in the Tambo message containing this hook usage. Use this to allow streaming updates from a prop to the state value.
13
+ * @param debounceTime - Optional debounce time in milliseconds (default: 500ms) to limit API calls.
14
+ * @returns A tuple containing:
15
+ * - The current state value
16
+ * - A setter function to update the state (updates UI immediately, debounces server sync)
17
+ * @example
18
+ * const [count, setCount] = useTamboComponentState("counter", 0);
4
19
  *
5
20
  * Use `setFromProp` to seed state from streamed props. During streaming,
6
21
  * state updates as new prop values arrive. Once streaming completes,
@@ -1 +1 @@
1
- {"version":3,"file":"use-component-state.d.ts","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":"AAMA,KAAK,iBAAiB,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC;AAE/E;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,SAAS,EAClD,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,CAAC,EAChB,WAAW,CAAC,EAAE,CAAC,EACf,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,WAAW,CAAC,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":"AAOA,KAAK,iBAAiB,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,SAAS,EAClD,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,CAAC,EAChB,WAAW,CAAC,EAAE,CAAC,EACf,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,WAAW,CAAC,EAAE,CAAC,EACf,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,CAAC,CAAC,CAAC,CAAC"}
@@ -1,17 +1,27 @@
1
1
  "use client";
2
- import { useCallback, useEffect, useState } from "react";
2
+ import { useCallback, useContext, useEffect, useState } from "react";
3
3
  import { useDebouncedCallback } from "use-debounce";
4
4
  import { useTamboClient, useTamboThread } from "..";
5
- import { useTamboCurrentMessage } from "./use-current-message";
5
+ import { useTamboInteractable } from "../providers/tambo-interactable-provider";
6
+ import { TamboMessageContext } from "./use-current-message";
6
7
  export function useTamboComponentState(keyName, initialValue, setFromProp, debounceTime = 500) {
7
- const message = useTamboCurrentMessage();
8
+ const message = useContext(TamboMessageContext);
8
9
  const { updateThreadMessage } = useTamboThread();
9
10
  const client = useTamboClient();
11
+ const componentId = message?.interactableMetadata?.id ?? null;
12
+ const { setInteractableState, getInteractableComponentState } = useTamboInteractable();
10
13
  const messageState = message?.componentState?.[keyName];
11
- const [localState, setLocalState] = useState(messageState ?? initialValue);
14
+ const interactableState = componentId
15
+ ? getInteractableComponentState(componentId)?.[keyName]
16
+ : undefined;
17
+ const initialState = interactableState ?? messageState ?? initialValue;
18
+ const [localState, setLocalState] = useState(initialState);
12
19
  const [initializedFromThreadMessage, setInitializedFromThreadMessage] = useState(messageState ? true : false);
13
20
  // Optimistically update the local thread message's componentState
14
21
  const updateLocalThreadMessage = useCallback(async (newState, existingMessage) => {
22
+ if (!existingMessage) {
23
+ return;
24
+ }
15
25
  const updatedMessage = {
16
26
  threadId: existingMessage.threadId,
17
27
  componentState: {
@@ -23,6 +33,9 @@ export function useTamboComponentState(keyName, initialValue, setFromProp, debou
23
33
  }, [updateThreadMessage, keyName]);
24
34
  // Debounced callback to update the remote thread message's componentState
25
35
  const updateRemoteThreadMessage = useDebouncedCallback(async (newState, existingMessage) => {
36
+ if (!existingMessage) {
37
+ return;
38
+ }
26
39
  await client.beta.threads.messages.updateComponentState(existingMessage.id, {
27
40
  id: existingMessage.threadId,
28
41
  state: { [keyName]: newState },
@@ -30,26 +43,73 @@ export function useTamboComponentState(keyName, initialValue, setFromProp, debou
30
43
  }, debounceTime);
31
44
  const setValue = useCallback((newState) => {
32
45
  setLocalState(newState);
33
- void updateLocalThreadMessage(newState, message);
34
- void updateRemoteThreadMessage(newState, message);
35
- }, [message, updateLocalThreadMessage, updateRemoteThreadMessage]);
36
- // Mirror the thread message's componentState value to the local state
46
+ if (componentId) {
47
+ // For interactable components, update the interactable provider's state
48
+ setInteractableState(componentId, keyName, newState);
49
+ }
50
+ else if (message) {
51
+ // For generated components, update both local and remote thread message state
52
+ void updateLocalThreadMessage(newState, message);
53
+ void updateRemoteThreadMessage(newState, message);
54
+ }
55
+ }, [
56
+ message,
57
+ updateLocalThreadMessage,
58
+ updateRemoteThreadMessage,
59
+ setInteractableState,
60
+ componentId,
61
+ keyName,
62
+ ]);
63
+ const existingInteractableState = componentId
64
+ ? getInteractableComponentState(componentId)?.[keyName]
65
+ : undefined;
66
+ const shouldUpdateInteractableInitial = !!componentId &&
67
+ existingInteractableState === undefined &&
68
+ initialValue !== undefined;
69
+ // Set initial value in interactable state if we're in an interactable context and there's no existing state
37
70
  useEffect(() => {
38
- const messageState = message?.componentState?.[keyName];
39
- if (!messageState) {
71
+ if (!shouldUpdateInteractableInitial) {
72
+ return;
73
+ }
74
+ setInteractableState(componentId, keyName, initialValue);
75
+ }, [
76
+ shouldUpdateInteractableInitial,
77
+ componentId,
78
+ keyName,
79
+ initialValue,
80
+ setInteractableState,
81
+ ]);
82
+ const shouldSyncFromMessage = !!message && messageState !== undefined && messageState !== null;
83
+ // Mirror the thread message's componentState value to the local state and interactable state
84
+ useEffect(() => {
85
+ if (!shouldSyncFromMessage) {
40
86
  return;
41
87
  }
42
88
  setInitializedFromThreadMessage(true);
43
- setLocalState(message.componentState?.[keyName]);
44
- }, [message?.componentState?.[keyName], message, keyName]);
89
+ const stateValue = messageState;
90
+ setLocalState(stateValue);
91
+ if (componentId) {
92
+ setInteractableState(componentId, keyName, stateValue);
93
+ }
94
+ }, [
95
+ shouldSyncFromMessage,
96
+ messageState,
97
+ keyName,
98
+ setInteractableState,
99
+ componentId,
100
+ ]);
45
101
  // For editable fields that are set from a prop to allow streaming updates, don't overwrite a fetched state value set from the thread message with prop value on initial load.
46
102
  useEffect(() => {
47
103
  if (setFromProp !== undefined && !initializedFromThreadMessage) {
48
104
  setLocalState(setFromProp);
49
105
  }
50
106
  }, [setFromProp, initializedFromThreadMessage]);
51
- // Ensure pending changes are flushed on unmount
107
+ // Ensure pending changes are flushed on unmount (only for generated components)
52
108
  useEffect(() => {
109
+ // Only flush remote updates for generated components, not interactable components
110
+ if (componentId) {
111
+ return;
112
+ }
53
113
  return () => {
54
114
  async function flushUpdates() {
55
115
  try {
@@ -62,7 +122,7 @@ export function useTamboComponentState(keyName, initialValue, setFromProp, debou
62
122
  // Fire-and-forget cleanup (errors handled inside)
63
123
  void flushUpdates();
64
124
  };
65
- }, [updateRemoteThreadMessage]);
125
+ }, [updateRemoteThreadMessage, componentId]);
66
126
  return [localState, setValue];
67
127
  }
68
128
  //# sourceMappingURL=use-component-state.js.map
@@ -1 +1 @@
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,EAAsB,cAAc,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AA+B/D,MAAM,UAAU,sBAA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,KAAK,YAAY,EAAE,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,yBAAyB,CAAC,CAAC,CAAC;IAEhC,OAAO,CAAC,UAAe,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC","sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useState } from \"react\";\nimport { useDebouncedCallback } from \"use-debounce\";\nimport { TamboThreadMessage, useTamboClient, useTamboThread } from \"..\";\nimport { useTamboCurrentMessage } from \"./use-current-message\";\n\ntype StateUpdateResult<T> = [currentState: T, setState: (newState: T) => void];\n\n/**\n * Like useState, but syncs to the thread message's `componentState`.\n *\n * Use `setFromProp` to seed state from streamed props. During streaming,\n * state updates as new prop values arrive. Once streaming completes,\n * user edits take precedence over the original prop value.\n *\n * Pair with `useTamboStreamStatus` to disable inputs while streaming.\n * @see {@link https://docs.tambo.co/concepts/streaming/streaming-best-practices}\n * @param keyName - Unique key within the message's componentState\n * @param initialValue - Default value if no componentState exists\n * @param setFromProp - Seeds state from props (updates during streaming, then user edits take over)\n * @param debounceTime - Server sync debounce in ms (default: 500)\n * @returns A tuple of [currentState, setState] similar to React's useState\n */\nexport function useTamboComponentState<S = undefined>(\n keyName: string,\n initialValue?: S,\n setFromProp?: S,\n debounceTime?: number,\n): StateUpdateResult<S | undefined>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue: S,\n setFromProp?: S,\n debounceTime?: number,\n): StateUpdateResult<S>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue?: S,\n setFromProp?: S,\n debounceTime = 500,\n): StateUpdateResult<S> {\n const message = useTamboCurrentMessage();\n const { updateThreadMessage } = useTamboThread();\n const client = useTamboClient();\n const messageState = message?.componentState?.[keyName];\n const [localState, setLocalState] = useState<S | undefined>(\n (messageState as S) ?? initialValue,\n );\n const [initializedFromThreadMessage, setInitializedFromThreadMessage] =\n useState(messageState ? true : false);\n\n // Optimistically update the local thread message's componentState\n const updateLocalThreadMessage = useCallback(\n async (newState: S, existingMessage: TamboThreadMessage) => {\n const updatedMessage = {\n threadId: existingMessage.threadId,\n componentState: {\n ...existingMessage.componentState,\n [keyName]: newState,\n },\n };\n await updateThreadMessage(existingMessage.id, updatedMessage, false);\n },\n [updateThreadMessage, keyName],\n );\n\n // Debounced callback to update the remote thread message's componentState\n const updateRemoteThreadMessage = useDebouncedCallback(\n async (newState: S, existingMessage: TamboThreadMessage) => {\n await client.beta.threads.messages.updateComponentState(\n existingMessage.id,\n {\n id: existingMessage.threadId,\n state: { [keyName]: newState },\n },\n );\n },\n debounceTime,\n );\n\n const setValue = useCallback(\n (newState: S) => {\n setLocalState(newState);\n void updateLocalThreadMessage(newState, message);\n void updateRemoteThreadMessage(newState, message);\n },\n [message, updateLocalThreadMessage, updateRemoteThreadMessage],\n );\n\n // Mirror the thread message's componentState value to the local state\n useEffect(() => {\n const messageState = message?.componentState?.[keyName];\n if (!messageState) {\n return;\n }\n setInitializedFromThreadMessage(true);\n setLocalState(message.componentState?.[keyName] as S);\n }, [message?.componentState?.[keyName], message, keyName]);\n\n // For editable fields that are set from a prop to allow streaming updates, don't overwrite a fetched state value set from the thread message with prop value on initial load.\n useEffect(() => {\n if (setFromProp !== undefined && !initializedFromThreadMessage) {\n setLocalState(setFromProp as S);\n }\n }, [setFromProp, initializedFromThreadMessage]);\n\n // Ensure pending changes are flushed on unmount\n useEffect(() => {\n return () => {\n async function flushUpdates() {\n try {\n await updateRemoteThreadMessage.flush();\n } catch (error) {\n console.error(\n \"Failed to flush pending thread message updates:\",\n error,\n );\n }\n }\n // Fire-and-forget cleanup (errors handled inside)\n void flushUpdates();\n };\n }, [updateRemoteThreadMessage]);\n\n return [localState as S, setValue];\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,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACr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IAEhD,gFAAgF;IAChF,SAAS,CAAC,GAAG,EAAE;QACb,kFAAkF;QAClF,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO;QACT,CAAC;QACD,OAAO,GAAG,EAAE;YACV,KAAK,UAAU,YAAY;gBACzB,IAAI,CAAC;oBACH,MAAM,yBAAyB,CAAC,KAAK,EAAE,CAAC;gBAC1C,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CACX,iDAAiD,EACjD,KAAK,CACN,CAAC;gBACJ,CAAC;YACH,CAAC;YACD,kDAAkD;YAClD,KAAK,YAAY,EAAE,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,yBAAyB,EAAE,WAAW,CAAC,CAAC,CAAC;IAE7C,OAAO,CAAC,UAAe,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC","sourcesContent":["\"use client\";\nimport { useCallback, useContext, useEffect, useState } from \"react\";\nimport { useDebouncedCallback } from \"use-debounce\";\nimport { TamboThreadMessage, useTamboClient, useTamboThread } from \"..\";\nimport { useTamboInteractable } from \"../providers/tambo-interactable-provider\";\nimport { TamboMessageContext } from \"./use-current-message\";\n\ntype StateUpdateResult<T> = [currentState: T, setState: (newState: T) => void];\n\n/**\n * A React hook that acts like useState, but also automatically updates the thread message's componentState.\n * If used within an interactable component (wrapped with withTamboInteractable), it updates the\n * interactable provider's global state (sent to Tambo on every request) instead of the remote thread message state.\n * For generated components, it updates both the local and remote thread message's componentState.\n *\n * Benefits: Passes user changes to AI, and when threads are returned, state is preserved.\n * Works in both generative and interactable component contexts.\n * @param keyName - The unique key to identify this state value within the message's componentState object\n * @param initialValue - Optional initial value for the state, used if no componentState value exists in the Tambo message containing this hook usage.\n * @param setFromProp - Optional value used to set the state value, only while no componentState value exists in the Tambo message containing this hook usage. Use this to allow streaming updates from a prop to the state value.\n * @param debounceTime - Optional debounce time in milliseconds (default: 500ms) 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 * @example\n * const [count, setCount] = useTamboComponentState(\"counter\", 0);\n *\n * Use `setFromProp` to seed state from streamed props. During streaming,\n * state updates as new prop values arrive. Once streaming completes,\n * user edits take precedence over the original prop value.\n *\n * Pair with `useTamboStreamStatus` to disable inputs while streaming.\n * @see {@link https://docs.tambo.co/concepts/streaming/streaming-best-practices}\n * @param keyName - Unique key within the message's componentState\n * @param initialValue - Default value if no componentState exists\n * @param setFromProp - Seeds state from props (updates during streaming, then user edits take over)\n * @param debounceTime - Server sync debounce in ms (default: 500)\n * @returns A tuple of [currentState, setState] similar to React's useState\n */\nexport function useTamboComponentState<S = undefined>(\n keyName: string,\n initialValue?: S,\n setFromProp?: S,\n debounceTime?: number,\n): StateUpdateResult<S | undefined>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue: S,\n setFromProp?: S,\n debounceTime?: number,\n): StateUpdateResult<S>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue?: S,\n setFromProp?: S,\n debounceTime = 500,\n): StateUpdateResult<S> {\n const message = useContext(TamboMessageContext);\n const { updateThreadMessage } = useTamboThread();\n const client = useTamboClient();\n const componentId = message?.interactableMetadata?.id ?? null;\n const { setInteractableState, getInteractableComponentState } =\n useTamboInteractable();\n const messageState = message?.componentState?.[keyName];\n const interactableState = componentId\n ? getInteractableComponentState(componentId)?.[keyName]\n : undefined;\n const initialState =\n (interactableState as S) ?? (messageState as S) ?? initialValue;\n const [localState, setLocalState] = useState<S | undefined>(initialState);\n const [initializedFromThreadMessage, setInitializedFromThreadMessage] =\n useState(messageState ? true : false);\n\n // Optimistically update the local thread message's componentState\n const updateLocalThreadMessage = useCallback(\n async (newState: S, existingMessage: TamboThreadMessage | null) => {\n if (!existingMessage) {\n return;\n }\n const updatedMessage = {\n threadId: existingMessage.threadId,\n componentState: {\n ...existingMessage.componentState,\n [keyName]: newState,\n },\n };\n await updateThreadMessage(existingMessage.id, updatedMessage, false);\n },\n [updateThreadMessage, keyName],\n );\n\n // Debounced callback to update the remote thread message's componentState\n const updateRemoteThreadMessage = useDebouncedCallback(\n async (newState: S, existingMessage: TamboThreadMessage | null) => {\n if (!existingMessage) {\n return;\n }\n await client.beta.threads.messages.updateComponentState(\n existingMessage.id,\n {\n id: existingMessage.threadId,\n state: { [keyName]: newState },\n },\n );\n },\n debounceTime,\n );\n\n const setValue = useCallback(\n (newState: S) => {\n setLocalState(newState);\n if (componentId) {\n // For interactable components, update the interactable provider's state\n setInteractableState(componentId, keyName, newState);\n } else if (message) {\n // For generated components, update both local and remote thread message state\n void updateLocalThreadMessage(newState, message);\n void updateRemoteThreadMessage(newState, message);\n }\n },\n [\n message,\n updateLocalThreadMessage,\n updateRemoteThreadMessage,\n setInteractableState,\n componentId,\n keyName,\n ],\n );\n\n const existingInteractableState = componentId\n ? getInteractableComponentState(componentId)?.[keyName]\n : undefined;\n const shouldUpdateInteractableInitial =\n !!componentId &&\n existingInteractableState === undefined &&\n initialValue !== undefined;\n\n // Set initial value in interactable state if we're in an interactable context and there's no existing state\n useEffect(() => {\n if (!shouldUpdateInteractableInitial) {\n return;\n }\n setInteractableState(componentId, keyName, initialValue!);\n }, [\n shouldUpdateInteractableInitial,\n componentId,\n keyName,\n initialValue,\n setInteractableState,\n ]);\n\n const shouldSyncFromMessage =\n !!message && messageState !== undefined && messageState !== null;\n\n // Mirror the thread message's componentState value to the local state and interactable state\n useEffect(() => {\n if (!shouldSyncFromMessage) {\n return;\n }\n setInitializedFromThreadMessage(true);\n const stateValue = messageState as S;\n setLocalState(stateValue);\n if (componentId) {\n setInteractableState(componentId, keyName, stateValue);\n }\n }, [\n shouldSyncFromMessage,\n messageState,\n keyName,\n setInteractableState,\n componentId,\n ]);\n\n // For editable fields that are set from a prop to allow streaming updates, don't overwrite a fetched state value set from the thread message with prop value on initial load.\n useEffect(() => {\n if (setFromProp !== undefined && !initializedFromThreadMessage) {\n setLocalState(setFromProp as S);\n }\n }, [setFromProp, initializedFromThreadMessage]);\n\n // Ensure pending changes are flushed on unmount (only for generated components)\n useEffect(() => {\n // Only flush remote updates for generated components, not interactable components\n if (componentId) {\n return;\n }\n return () => {\n async function flushUpdates() {\n try {\n await updateRemoteThreadMessage.flush();\n } catch (error) {\n console.error(\n \"Failed to flush pending thread message updates:\",\n error,\n );\n }\n }\n // Fire-and-forget cleanup (errors handled inside)\n void flushUpdates();\n };\n }, [updateRemoteThreadMessage, componentId]);\n\n return [localState as S, setValue];\n}\n"]}
@@ -1,8 +1,10 @@
1
1
  import { act, renderHook } from "@testing-library/react";
2
+ import React from "react";
2
3
  import { useTamboClient } from "../providers/tambo-client-provider";
4
+ import { useTamboInteractable } from "../providers/tambo-interactable-provider";
3
5
  import { useTamboThread } from "../providers/tambo-thread-provider";
4
6
  import { useTamboComponentState } from "./use-component-state";
5
- import { useTamboCurrentMessage } from "./use-current-message";
7
+ import { TamboMessageContext, useTamboCurrentMessage, } from "./use-current-message";
6
8
  // Mock the required providers
7
9
  jest.mock("../providers/tambo-client-provider", () => ({
8
10
  useTamboClient: jest.fn(),
@@ -12,6 +14,10 @@ jest.mock("../providers/tambo-thread-provider", () => ({
12
14
  }));
13
15
  jest.mock("./use-current-message", () => ({
14
16
  useTamboCurrentMessage: jest.fn(),
17
+ TamboMessageContext: React.createContext(null),
18
+ }));
19
+ jest.mock("../providers/tambo-interactable-provider", () => ({
20
+ useTamboInteractable: jest.fn(),
15
21
  }));
16
22
  // Create a mock debounced function with flush method
17
23
  const createMockDebouncedFunction = (fn) => {
@@ -40,8 +46,34 @@ describe("useTamboComponentState", () => {
40
46
  });
41
47
  const mockUpdateThreadMessage = jest.fn();
42
48
  const mockUpdateComponentState = jest.fn();
49
+ const mockSetInteractableState = jest.fn();
50
+ const mockGetInteractableComponentState = jest.fn();
51
+ // Track context values for mocking
52
+ let mockMessage = null;
43
53
  beforeEach(() => {
44
54
  jest.clearAllMocks();
55
+ // Reset context values
56
+ mockMessage = createMockMessage();
57
+ // Mock useContext to return appropriate values based on context
58
+ const originalUseContext = React.useContext;
59
+ jest.spyOn(React, "useContext").mockImplementation((context) => {
60
+ if (context === TamboMessageContext) {
61
+ // Return the message from useTamboCurrentMessage mock if available
62
+ try {
63
+ const currentMessageMock = jest.mocked(useTamboCurrentMessage);
64
+ const mockImpl = currentMessageMock.getMockImplementation();
65
+ if (mockImpl) {
66
+ return mockImpl();
67
+ }
68
+ }
69
+ catch {
70
+ // Fallback to mockMessage
71
+ }
72
+ return mockMessage;
73
+ }
74
+ // For other contexts, use the original implementation
75
+ return originalUseContext(context);
76
+ });
45
77
  // Setup default mock for useDebouncedCallback
46
78
  jest
47
79
  .mocked(useDebouncedCallback)
@@ -60,6 +92,13 @@ describe("useTamboComponentState", () => {
60
92
  updateThreadMessage: mockUpdateThreadMessage,
61
93
  });
62
94
  jest.mocked(useTamboCurrentMessage).mockReturnValue(createMockMessage());
95
+ jest.mocked(useTamboInteractable).mockReturnValue({
96
+ setInteractableState: mockSetInteractableState,
97
+ getInteractableComponentState: mockGetInteractableComponentState,
98
+ });
99
+ });
100
+ afterEach(() => {
101
+ jest.restoreAllMocks();
63
102
  });
64
103
  describe("Initial State Management", () => {
65
104
  it("should initialize with initialValue when no componentState exists", () => {