@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod.test.js","sourceRoot":"","sources":["../../src/schema/zod.test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1E,uFAAuF;AACvF,+EAA+E;AAC/E,6EAA6E;AAC7E,iEAAiE;AACjE,SAAS,UAAU,CAAC,KAAc,EAAE,GAAW;IAC7C,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAE/B,SAAS,aAAa,CAAC,CAAU;QAC/B,IAAI,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QAClE,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;QACvC,OAAO,KAAK,KAAK,MAAM,CAAC,SAAS,IA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I,EAAE,QAAQ;oBACd,UAAU,EAAE;wBACV,IAAI,EAAE;4BACJ,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,eAAe;yBAC7B;qBACF;iBACF,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import * as z3 from \"zod/v3\";\nimport * as z4 from \"zod/v4\";\nimport { handleZodSchemaToJson, isZod3Schema, isZod4Schema } from \"./zod\";\n\n// Test helper: assumes `value` is JSON-serializable (plain objects/arrays/primitives).\n// Conservative helper: returns true if any object in the tree has an own `key`\n// property at any depth. This lets us assert against JSON Schema `$ref` keys\n// structurally (not via incidental substrings in string values).\nfunction hasKeyDeep(value: unknown, key: string): boolean {\n const seen = new Set<object>();\n\n function isPlainObject(v: unknown): v is Record<string, unknown> {\n if (!v || typeof v !== \"object\" || Array.isArray(v)) return false;\n const proto = Object.getPrototypeOf(v);\n return proto === Object.prototype || proto === null;\n }\n\n function visit(node: unknown): boolean {\n if (!node || typeof node !== \"object\") return false;\n if (seen.has(node)) return false;\n seen.add(node);\n\n if (Array.isArray(node)) {\n return node.some(visit);\n }\n\n if (!isPlainObject(node)) return false;\n\n if (Object.prototype.hasOwnProperty.call(node, key)) return true;\n return Object.values(node).some(visit);\n }\n\n return visit(value);\n}\n\nfunction resolveJsonPointer(doc: unknown, pointer: string): unknown {\n if (!pointer.startsWith(\"#\")) return undefined;\n if (pointer === \"#\") return doc;\n if (!pointer.startsWith(\"#/\")) return undefined;\n\n return pointer\n .slice(2)\n .split(\"/\")\n .map((segment) => segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\"))\n .reduce<unknown>((current, segment) => {\n if (!current || typeof current !== \"object\") return undefined;\n\n if (Array.isArray(current)) {\n const index = Number(segment);\n if (!Number.isInteger(index)) return undefined;\n return current[index];\n }\n\n return (current as Record<string, unknown>)[segment];\n }, doc);\n}\n\nfunction createRecursiveZod4NodeSchema(): z4.ZodTypeAny {\n // Placeholder schema so we can self-reference via `z4.lazy` without\n // fighting ESLint `prefer-const`.\n let nodeSchema: z4.ZodTypeAny = z4.any();\n nodeSchema = z4.object({ next: z4.lazy(() => nodeSchema).optional() });\n return nodeSchema;\n}\n\ndescribe(\"zod schema utilities\", () => {\n describe(\"isZod3Schema\", () => {\n it(\"returns true for Zod 3 schemas\", () => {\n const schema = z3.object({ name: z3.string() });\n expect(isZod3Schema(schema)).toBe(true);\n expect(isZod4Schema(schema)).toBe(false);\n });\n\n it(\"returns true for Zod 4 schemas (they also have _def)\", () => {\n // Note: Zod 4 schemas have both _def and _zod, so isZod3Schema returns true.\n // This is fine because handleZodSchemaToJson checks isZod4Schema first.\n const schema = z4.object({ name: z4.string() });\n expect(isZod4Schema(schema)).toBe(true);\n expect(isZod3Schema(schema)).toBe(false);\n });\n\n it(\"returns false for non-Zod values\", () => {\n expect(isZod3Schema({})).toBe(false);\n expect(isZod3Schema(null)).toBe(false);\n expect(isZod3Schema(\"string\")).toBe(false);\n });\n });\n\n describe(\"isZod4Schema\", () => {\n it(\"returns true for Zod 4 schemas\", () => {\n const schema = z4.object({ name: z4.string() });\n expect(isZod4Schema(schema)).toBe(true);\n });\n\n it(\"returns false for Zod 3 schemas\", () => {\n const schema = z3.object({ name: z3.string() });\n expect(isZod4Schema(schema)).toBe(false);\n });\n\n it(\"returns false for non-Zod values\", () => {\n expect(isZod4Schema({})).toBe(false);\n expect(isZod4Schema(null)).toBe(false);\n expect(isZod4Schema(\"string\")).toBe(false);\n });\n });\n\n describe(\"handleZodSchemaToJson\", () => {\n describe(\"basic conversion\", () => {\n it(\"converts Zod 3 schema to JSON Schema\", () => {\n const schema = z3.object({\n name: z3.string(),\n age: z3.number(),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n age: { type: \"number\" },\n },\n });\n });\n\n it(\"converts Zod 4 schema to JSON Schema\", () => {\n const schema = z4.object({\n name: z4.string(),\n age: z4.number(),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n age: { type: \"number\" },\n },\n });\n });\n });\n\n describe(\"reused schemas - no $ref references\", () => {\n it(\"inlines reused Zod 3 schemas without any $ref in output\", () => {\n // Define a shared schema that will be reused\n const dataSchema = z3.object({\n name: z3.string(),\n value: z3.number(),\n });\n\n // Use the same schema in multiple places\n const props = z3.object({\n data: z3.array(dataSchema),\n historicalData: z3.array(dataSchema),\n });\n\n const result = handleZodSchemaToJson(props);\n\n // Ensure there are no JSON Schema `$ref` keys anywhere in the produced schema.\n expect(hasKeyDeep(result, \"$ref\")).toBe(false);\n\n // Both arrays should have the full schema inline\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n data: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n value: { type: \"number\" },\n },\n },\n },\n historicalData: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n value: { type: \"number\" },\n },\n },\n },\n },\n });\n });\n\n it(\"inlines reused Zod 4 schemas without any $ref in output\", () => {\n // Define a shared schema that will be reused\n const dataSchema = z4.object({\n name: z4.string(),\n value: z4.number(),\n });\n\n // Use the same schema in multiple places\n const props = z4.object({\n data: z4.array(dataSchema),\n historicalData: z4.array(dataSchema),\n });\n\n const result = handleZodSchemaToJson(props);\n\n expect(hasKeyDeep(result, \"$ref\")).toBe(false);\n\n // Both arrays should have the full schema inline\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n data: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n value: { type: \"number\" },\n },\n },\n },\n historicalData: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n value: { type: \"number\" },\n },\n },\n },\n },\n });\n });\n\n it(\"handles deeply nested reused Zod 3 schemas without any $ref\", () => {\n const addressSchema = z3.object({\n street: z3.string(),\n city: z3.string(),\n });\n\n const personSchema = z3.object({\n name: z3.string(),\n homeAddress: addressSchema,\n workAddress: addressSchema,\n });\n\n const result = handleZodSchemaToJson(personSchema);\n\n expect(hasKeyDeep(result, \"$ref\")).toBe(false);\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n homeAddress: {\n type: \"object\",\n properties: {\n street: { type: \"string\" },\n city: { type: \"string\" },\n },\n },\n workAddress: {\n type: \"object\",\n properties: {\n street: { type: \"string\" },\n city: { type: \"string\" },\n },\n },\n },\n });\n });\n\n it(\"handles deeply nested reused Zod 4 schemas without any $ref\", () => {\n const addressSchema = z4.object({\n street: z4.string(),\n city: z4.string(),\n });\n\n const personSchema = z4.object({\n name: z4.string(),\n homeAddress: addressSchema,\n workAddress: addressSchema,\n });\n\n const result = handleZodSchemaToJson(personSchema);\n\n expect(hasKeyDeep(result, \"$ref\")).toBe(false);\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n homeAddress: {\n type: \"object\",\n properties: {\n street: { type: \"string\" },\n city: { type: \"string\" },\n },\n },\n workAddress: {\n type: \"object\",\n properties: {\n street: { type: \"string\" },\n city: { type: \"string\" },\n },\n },\n },\n });\n });\n\n it(\"handles triple-nested reused Zod 4 schemas without any $ref\", () => {\n const pointSchema = z4.object({\n x: z4.number(),\n y: z4.number(),\n });\n\n const lineSchema = z4.object({\n start: pointSchema,\n end: pointSchema,\n });\n\n const shapeSchema = z4.object({\n outline: z4.array(lineSchema),\n boundingBox: z4.object({\n topLeft: pointSchema,\n bottomRight: pointSchema,\n }),\n });\n\n const result = handleZodSchemaToJson(shapeSchema);\n\n expect(result).toMatchInlineSnapshot(`\n {\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"properties\": {\n \"boundingBox\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"bottomRight\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"x\": {\n \"type\": \"number\",\n },\n \"y\": {\n \"type\": \"number\",\n },\n },\n \"required\": [\n \"x\",\n \"y\",\n ],\n \"type\": \"object\",\n },\n \"topLeft\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"x\": {\n \"type\": \"number\",\n },\n \"y\": {\n \"type\": \"number\",\n },\n },\n \"required\": [\n \"x\",\n \"y\",\n ],\n \"type\": \"object\",\n },\n },\n \"required\": [\n \"topLeft\",\n \"bottomRight\",\n ],\n \"type\": \"object\",\n },\n \"outline\": {\n \"items\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"end\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"x\": {\n \"type\": \"number\",\n },\n \"y\": {\n \"type\": \"number\",\n },\n },\n \"required\": [\n \"x\",\n \"y\",\n ],\n \"type\": \"object\",\n },\n \"start\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"x\": {\n \"type\": \"number\",\n },\n \"y\": {\n \"type\": \"number\",\n },\n },\n \"required\": [\n \"x\",\n \"y\",\n ],\n \"type\": \"object\",\n },\n },\n \"required\": [\n \"start\",\n \"end\",\n ],\n \"type\": \"object\",\n },\n \"type\": \"array\",\n },\n },\n \"required\": [\n \"outline\",\n \"boundingBox\",\n ],\n \"type\": \"object\",\n }\n `);\n expect(hasKeyDeep(result, \"$ref\")).toBe(false);\n });\n });\n\n describe(\"recursive schemas\", () => {\n it(\"represents Zod 4 recursive schemas using $ref\", () => {\n const nodeSchema = createRecursiveZod4NodeSchema();\n const result = handleZodSchemaToJson(nodeSchema);\n const schema = result as Record<string, unknown>;\n const properties = schema.properties as\n | Record<string, unknown>\n | undefined;\n const next = properties?.next as Record<string, unknown> | undefined;\n const ref = next?.$ref;\n\n expect(hasKeyDeep(result, \"$ref\")).toBe(true);\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n next: {\n $ref: expect.stringMatching(/^#(\\/.*)?$/),\n },\n },\n });\n expect(ref).toEqual(expect.stringMatching(/^#(\\/.*)?$/));\n\n const resolved =\n typeof ref === \"string\" ? resolveJsonPointer(result, ref) : undefined;\n expect(resolved).toBe(result);\n expect(resolved).toMatchObject({\n type: \"object\",\n });\n });\n });\n\n describe(\"complex schemas\", () => {\n it(\"handles optional fields in Zod 3\", () => {\n const schema = z3.object({\n required: z3.string(),\n optional: z3.string().optional(),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n required: { type: \"string\" },\n optional: { type: \"string\" },\n },\n required: [\"required\"],\n });\n });\n\n it(\"handles optional fields in Zod 4\", () => {\n const schema = z4.object({\n required: z4.string(),\n optional: z4.string().optional(),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n required: { type: \"string\" },\n optional: { type: \"string\" },\n },\n required: [\"required\"],\n });\n });\n\n it(\"handles enums in Zod 3\", () => {\n const schema = z3.object({\n status: z3.enum([\"active\", \"inactive\", \"pending\"]),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n status: {\n type: \"string\",\n enum: [\"active\", \"inactive\", \"pending\"],\n },\n },\n });\n });\n\n it(\"handles enums in Zod 4\", () => {\n const schema = z4.object({\n status: z4.enum([\"active\", \"inactive\", \"pending\"]),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n status: {\n type: \"string\",\n enum: [\"active\", \"inactive\", \"pending\"],\n },\n },\n });\n });\n\n it(\"handles descriptions in Zod 3\", () => {\n const schema = z3.object({\n name: z3.string().describe(\"The user name\"),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n name: {\n type: \"string\",\n description: \"The user name\",\n },\n },\n });\n });\n\n it(\"handles descriptions in Zod 4\", () => {\n const schema = z4.object({\n name: z4.string().describe(\"The user name\"),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n name: {\n type: \"string\",\n description: \"The user name\",\n },\n },\n });\n });\n });\n });\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"registry-validators.d.ts","sourceRoot":"","sources":["../../src/util/registry-validators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AAWrC;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,uBAAuB,GAAG,IAAI,CAqB5E;AA0CD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,cAAc,GAAG;IACtE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC,CA6BA;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,OAAO,EACxB,UAAU,EAAE,OAAO,GAClB,IAAI,CAWN"}
1
+ {"version":3,"file":"registry-validators.d.ts","sourceRoot":"","sources":["../../src/util/registry-validators.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AAoDrC;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,uBAAuB,GAAG,IAAI,CAuB5E;AA0CD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,cAAc,GAAG;IACtE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC,CA6BA;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,OAAO,EACxB,UAAU,EAAE,OAAO,GAClB,IAAI,CAWN"}
@@ -1,6 +1,44 @@
1
1
  import { assertNoRecordSchema, getZodFunctionArgs, isStandardSchema, looksLikeJSONSchema, schemaToJsonSchema, } from "../schema";
2
2
  import { isZodFunctionSchema } from "../schema/zod";
3
3
  import { assertValidName } from "./validate-component-name";
4
+ /**
5
+ * Checks if a JSON Schema represents an object type.
6
+ * @param schema - The JSON Schema to check
7
+ * @returns True if the schema is an object type
8
+ */
9
+ function isObjectSchema(schema) {
10
+ return schema.type === "object" || schema.properties !== undefined;
11
+ }
12
+ /**
13
+ * Validates that a schema is an object type.
14
+ * Throws an error if it's not.
15
+ * @param schema - The schema to validate (Standard Schema or JSON Schema)
16
+ * @param context - Description of where the schema is used (for error messages)
17
+ */
18
+ function assertObjectSchema(schema, context) {
19
+ let jsonSchema;
20
+ if (isStandardSchema(schema)) {
21
+ try {
22
+ jsonSchema = schemaToJsonSchema(schema);
23
+ }
24
+ catch {
25
+ // If conversion fails, we can't validate - let it fail later
26
+ return;
27
+ }
28
+ }
29
+ else if (looksLikeJSONSchema(schema)) {
30
+ jsonSchema = schema;
31
+ }
32
+ else {
33
+ // Unknown schema type, can't validate
34
+ return;
35
+ }
36
+ if (!isObjectSchema(jsonSchema)) {
37
+ throw new Error(`${context} must be an object schema (e.g., z.object({...})). ` +
38
+ `Received type: "${jsonSchema.type ?? "unknown"}". ` +
39
+ `Tool parameters are passed as a single object argument.`);
40
+ }
41
+ }
4
42
  /**
5
43
  * Validates a tool before registration.
6
44
  * Throws an error if the tool is invalid.
@@ -12,6 +50,8 @@ export function validateTool(tool) {
12
50
  // Validate tool schemas
13
51
  // 1. check inputSchema
14
52
  if ("inputSchema" in tool && tool.inputSchema) {
53
+ // inputSchema must be an object schema
54
+ assertObjectSchema(tool.inputSchema, `inputSchema of tool "${tool.name}"`);
15
55
  assertNoRecordSchema(tool.inputSchema, `inputSchema of tool "${tool.name}"`);
16
56
  }
17
57
  // 2. check deprecated toolSchema
@@ -1 +1 @@
1
- {"version":3,"file":"registry-validators.js","sourceRoot":"","sources":["../../src/util/registry-validators.ts"],"names":[],"mappings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AoC;IACpC,eAAe,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;IAC5C,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAElC,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,aAAa,aAAa,wBAAwB,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,wBAAwB,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC","sourcesContent":["import type {\n TamboComponent,\n TamboTool,\n TamboToolWithToolSchema,\n} from \"../model/component-metadata\";\nimport {\n assertNoRecordSchema,\n getZodFunctionArgs,\n isStandardSchema,\n looksLikeJSONSchema,\n schemaToJsonSchema,\n} from \"../schema\";\nimport { isZodFunctionSchema } from \"../schema/zod\";\nimport { assertValidName } from \"./validate-component-name\";\n\n/**\n * Validates a tool before registration.\n * Throws an error if the tool is invalid.\n * @param tool - The tool to validate\n */\nexport function validateTool(tool: TamboTool | TamboToolWithToolSchema): void {\n // Validate tool name\n assertValidName(tool.name, \"tool\");\n\n // Validate tool schemas\n // 1. check inputSchema\n if (\"inputSchema\" in tool && tool.inputSchema) {\n assertNoRecordSchema(\n tool.inputSchema,\n `inputSchema of tool \"${tool.name}\"`,\n );\n }\n // 2. check deprecated toolSchema\n else if (\"toolSchema\" in tool && tool.toolSchema) {\n let inputSchema = tool.toolSchema;\n // toolSchema may sometimes be a zod function schema, extract args if so\n if (isZodFunctionSchema(tool.toolSchema)) {\n inputSchema = getZodFunctionArgs(tool.toolSchema);\n }\n assertNoRecordSchema(inputSchema, `toolSchema of tool \"${tool.name}\"`);\n }\n}\n\n/**\n * Converts a props schema to a serialized JSON Schema format.\n * @param propsDefinition - Deprecated: legacy props definition (will log warning)\n * @param propsSchema - The props schema (Standard Schema or JSON Schema)\n * @param name - Component/tool name for error messages\n * @returns Serialized JSON Schema object\n */\nfunction getSerializedProps(\n propsDefinition: unknown,\n propsSchema: unknown,\n name: string,\n): Record<string, unknown> {\n if (propsDefinition) {\n console.warn(`propsDefinition is deprecated. Use propsSchema instead.`);\n return propsDefinition as Record<string, unknown>;\n }\n\n // Check for Standard Schema (Zod, Valibot, ArkType, etc.)\n if (isStandardSchema(propsSchema)) {\n try {\n return schemaToJsonSchema(propsSchema) as Record<string, unknown>;\n } catch (error) {\n console.error(\n `Error converting ${name} props schema to JSON Schema:`,\n error,\n );\n throw new Error(\n `Error converting ${name} props schema to JSON Schema: ${error}`,\n );\n }\n }\n\n // Check for JSON Schema\n if (looksLikeJSONSchema(propsSchema)) {\n return propsSchema as Record<string, unknown>;\n }\n\n throw new Error(`Invalid props schema for ${name}`);\n}\n\n/**\n * Validates a component and prepares its props for registration.\n * Throws an error if the component is invalid.\n * @param component - The component to validate and prepare\n * @returns Object containing the serialized props\n */\nexport function validateAndPrepareComponent(component: TamboComponent): {\n props: Record<string, unknown>;\n} {\n const { name, propsSchema, propsDefinition } = component;\n\n // Validate component name\n assertValidName(name, \"component\");\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 // Validate that the propsSchema does not include record types\n if (propsSchema) {\n assertNoRecordSchema(propsSchema, `propsSchema of component \"${name}\"`);\n }\n\n // Convert propsSchema to JSON Schema if it exists\n const props = getSerializedProps(propsDefinition, propsSchema, name);\n\n return { props };\n}\n\n/**\n * Validates a tool association between a component and tool.\n * Throws an error if the association is invalid.\n * @param componentName - The component name\n * @param toolName - The tool name\n * @param componentExists - Whether the component exists in the registry\n * @param toolExists - Whether the tool exists in the registry\n */\nexport function validateToolAssociation(\n componentName: string,\n toolName: string,\n componentExists: boolean,\n toolExists: boolean,\n): void {\n // Validate component and tool names\n assertValidName(componentName, \"component\");\n assertValidName(toolName, \"tool\");\n\n if (!componentExists) {\n throw new Error(`Component ${componentName} not found in registry`);\n }\n if (!toolExists) {\n throw new Error(`Tool ${toolName} not found in registry`);\n }\n}\n"]}
1
+ {"version":3,"file":"registry-validators.js","sourceRoot":"","sources":["../../src/util/registry-validators.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D;;;;GAIG;AACH,SAAS,cAAc,CAAC,MAAmB;IACzC,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,CAAC;AACrE,CAAC;AAED;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,MAAe,EAAE,OAAe;IAC1D,IAAI,UAAuB,CAAC;IAE5B,IAAI,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,UAAU,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;QAAC,MAAM,CAAC;YACP,6DAA6D;YAC7D,OAAO;QACT,CAAC;IACH,CAAC;SAAM,IAAI,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC;QACvC,UAAU,GAAG,MAAM,CAAC;IACtB,CAAC;SAAM,CAAC;QACN,sCAAsC;QACtC,OAAO;IACT,CAAC;IAED,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,GAAG,OAAO,qDAAqD;YAC7D,mBAAmB,UAAU,CAAC,IAAI,IAAI,SAAS,KAAK;YACpD,yDAAyD,CAC5D,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH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,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,aAAa,aAAa,wBAAwB,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,wBAAwB,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC","sourcesContent":["import type { JSONSchema7 } from \"json-schema\";\nimport type {\n TamboComponent,\n TamboTool,\n TamboToolWithToolSchema,\n} from \"../model/component-metadata\";\nimport {\n assertNoRecordSchema,\n getZodFunctionArgs,\n isStandardSchema,\n looksLikeJSONSchema,\n schemaToJsonSchema,\n} from \"../schema\";\nimport { isZodFunctionSchema } from \"../schema/zod\";\nimport { assertValidName } from \"./validate-component-name\";\n\n/**\n * Checks if a JSON Schema represents an object type.\n * @param schema - The JSON Schema to check\n * @returns True if the schema is an object type\n */\nfunction isObjectSchema(schema: JSONSchema7): boolean {\n return schema.type === \"object\" || schema.properties !== undefined;\n}\n\n/**\n * Validates that a schema is an object type.\n * Throws an error if it's not.\n * @param schema - The schema to validate (Standard Schema or JSON Schema)\n * @param context - Description of where the schema is used (for error messages)\n */\nfunction assertObjectSchema(schema: unknown, context: string): void {\n let jsonSchema: JSONSchema7;\n\n if (isStandardSchema(schema)) {\n try {\n jsonSchema = schemaToJsonSchema(schema);\n } catch {\n // If conversion fails, we can't validate - let it fail later\n return;\n }\n } else if (looksLikeJSONSchema(schema)) {\n jsonSchema = schema;\n } else {\n // Unknown schema type, can't validate\n return;\n }\n\n if (!isObjectSchema(jsonSchema)) {\n throw new Error(\n `${context} must be an object schema (e.g., z.object({...})). ` +\n `Received type: \"${jsonSchema.type ?? \"unknown\"}\". ` +\n `Tool parameters are passed as a single object argument.`,\n );\n }\n}\n\n/**\n * Validates a tool before registration.\n * Throws an error if the tool is invalid.\n * @param tool - The tool to validate\n */\nexport function validateTool(tool: TamboTool | TamboToolWithToolSchema): void {\n // Validate tool name\n assertValidName(tool.name, \"tool\");\n\n // Validate tool schemas\n // 1. check inputSchema\n if (\"inputSchema\" in tool && tool.inputSchema) {\n // inputSchema must be an object schema\n assertObjectSchema(tool.inputSchema, `inputSchema of tool \"${tool.name}\"`);\n assertNoRecordSchema(\n tool.inputSchema,\n `inputSchema of tool \"${tool.name}\"`,\n );\n }\n // 2. check deprecated toolSchema\n else if (\"toolSchema\" in tool && tool.toolSchema) {\n let inputSchema = tool.toolSchema;\n // toolSchema may sometimes be a zod function schema, extract args if so\n if (isZodFunctionSchema(tool.toolSchema)) {\n inputSchema = getZodFunctionArgs(tool.toolSchema);\n }\n assertNoRecordSchema(inputSchema, `toolSchema of tool \"${tool.name}\"`);\n }\n}\n\n/**\n * Converts a props schema to a serialized JSON Schema format.\n * @param propsDefinition - Deprecated: legacy props definition (will log warning)\n * @param propsSchema - The props schema (Standard Schema or JSON Schema)\n * @param name - Component/tool name for error messages\n * @returns Serialized JSON Schema object\n */\nfunction getSerializedProps(\n propsDefinition: unknown,\n propsSchema: unknown,\n name: string,\n): Record<string, unknown> {\n if (propsDefinition) {\n console.warn(`propsDefinition is deprecated. Use propsSchema instead.`);\n return propsDefinition as Record<string, unknown>;\n }\n\n // Check for Standard Schema (Zod, Valibot, ArkType, etc.)\n if (isStandardSchema(propsSchema)) {\n try {\n return schemaToJsonSchema(propsSchema) as Record<string, unknown>;\n } catch (error) {\n console.error(\n `Error converting ${name} props schema to JSON Schema:`,\n error,\n );\n throw new Error(\n `Error converting ${name} props schema to JSON Schema: ${error}`,\n );\n }\n }\n\n // Check for JSON Schema\n if (looksLikeJSONSchema(propsSchema)) {\n return propsSchema as Record<string, unknown>;\n }\n\n throw new Error(`Invalid props schema for ${name}`);\n}\n\n/**\n * Validates a component and prepares its props for registration.\n * Throws an error if the component is invalid.\n * @param component - The component to validate and prepare\n * @returns Object containing the serialized props\n */\nexport function validateAndPrepareComponent(component: TamboComponent): {\n props: Record<string, unknown>;\n} {\n const { name, propsSchema, propsDefinition } = component;\n\n // Validate component name\n assertValidName(name, \"component\");\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 // Validate that the propsSchema does not include record types\n if (propsSchema) {\n assertNoRecordSchema(propsSchema, `propsSchema of component \"${name}\"`);\n }\n\n // Convert propsSchema to JSON Schema if it exists\n const props = getSerializedProps(propsDefinition, propsSchema, name);\n\n return { props };\n}\n\n/**\n * Validates a tool association between a component and tool.\n * Throws an error if the association is invalid.\n * @param componentName - The component name\n * @param toolName - The tool name\n * @param componentExists - Whether the component exists in the registry\n * @param toolExists - Whether the tool exists in the registry\n */\nexport function validateToolAssociation(\n componentName: string,\n toolName: string,\n componentExists: boolean,\n toolExists: boolean,\n): void {\n // Validate component and tool names\n assertValidName(componentName, \"component\");\n assertValidName(toolName, \"tool\");\n\n if (!componentExists) {\n throw new Error(`Component ${componentName} not found in registry`);\n }\n if (!toolExists) {\n throw new Error(`Tool ${toolName} not found in registry`);\n }\n}\n"]}
@@ -77,6 +77,75 @@ describe("validateTool", () => {
77
77
  };
78
78
  expect(() => validateTool(tool)).not.toThrow();
79
79
  });
80
+ it("should throw when inputSchema is not an object schema (string)", () => {
81
+ const tool = {
82
+ name: "tool-with-string-schema",
83
+ description: "A tool with invalid schema",
84
+ tool: () => "result",
85
+ inputSchema: z.string(),
86
+ outputSchema: z.string(),
87
+ };
88
+ expect(() => validateTool(tool)).toThrow('inputSchema of tool "tool-with-string-schema" must be an object schema');
89
+ });
90
+ it("should throw when inputSchema is not an object schema (number)", () => {
91
+ const tool = {
92
+ name: "tool-with-number-schema",
93
+ description: "A tool with invalid schema",
94
+ tool: () => "result",
95
+ inputSchema: z.number(),
96
+ outputSchema: z.string(),
97
+ };
98
+ expect(() => validateTool(tool)).toThrow('inputSchema of tool "tool-with-number-schema" must be an object schema');
99
+ });
100
+ it("should throw when inputSchema is not an object schema (array)", () => {
101
+ const tool = {
102
+ name: "tool-with-array-schema",
103
+ description: "A tool with invalid schema",
104
+ tool: () => "result",
105
+ inputSchema: z.array(z.string()),
106
+ outputSchema: z.string(),
107
+ };
108
+ expect(() => validateTool(tool)).toThrow('inputSchema of tool "tool-with-array-schema" must be an object schema');
109
+ });
110
+ it("should throw when inputSchema JSON Schema is not an object type", () => {
111
+ const tool = {
112
+ name: "tool-with-json-string-schema",
113
+ description: "A tool with invalid JSON schema",
114
+ tool: () => "result",
115
+ inputSchema: { type: "string" },
116
+ outputSchema: { type: "string" },
117
+ };
118
+ expect(() => validateTool(tool)).toThrow('inputSchema of tool "tool-with-json-string-schema" must be an object schema');
119
+ });
120
+ it("should accept JSON Schema with object type", () => {
121
+ const tool = {
122
+ name: "tool-with-json-object-schema",
123
+ description: "A tool with valid JSON schema",
124
+ tool: () => "result",
125
+ inputSchema: {
126
+ type: "object",
127
+ properties: {
128
+ query: { type: "string" },
129
+ },
130
+ },
131
+ outputSchema: { type: "string" },
132
+ };
133
+ expect(() => validateTool(tool)).not.toThrow();
134
+ });
135
+ it("should accept JSON Schema with properties but no explicit type", () => {
136
+ const tool = {
137
+ name: "tool-with-implicit-object-schema",
138
+ description: "A tool with implicit object schema",
139
+ tool: () => "result",
140
+ inputSchema: {
141
+ properties: {
142
+ query: { type: "string" },
143
+ },
144
+ },
145
+ outputSchema: { type: "string" },
146
+ };
147
+ expect(() => validateTool(tool)).not.toThrow();
148
+ });
80
149
  });
81
150
  describe("validateAndPrepareComponent", () => {
82
151
  it("should validate component with propsSchema", () => {
@@ -1 +1 @@
1
- {"version":3,"file":"registry-validators.test.js","sourceRoot":"","sources":["../../src/util/registry-validators.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAM3B,OAAO,EACL,2BAA2B,EAC3B,YAAY,EACZ,uBAAuB,GACxB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from \"../model/component-metadata\";\nimport {\n validateAndPrepareComponent,\n validateTool,\n validateToolAssociation,\n} from \"./registry-validators\";\n\ndescribe(\"validateTool\", () => {\n it(\"should validate tool with valid name\", () => {\n const tool: TamboToolWithToolSchema = {\n name: \"valid-tool-name\",\n description: \"A valid tool\",\n tool: () => \"result\",\n toolSchema: z.function().args().returns(z.string()),\n };\n\n expect(() => validateTool(tool)).not.toThrow();\n });\n\n it(\"should throw when tool name contains invalid characters\", () => {\n const tool: TamboToolWithToolSchema = {\n name: \"invalid tool name\",\n description: \"A tool\",\n tool: () => \"result\",\n toolSchema: z.function().args().returns(z.string()),\n };\n\n expect(() => validateTool(tool)).toThrow(\n 'tool \"invalid tool name\" must only contain letters, numbers, underscores, and hyphens.',\n );\n });\n\n it(\"should throw when tool name contains special characters\", () => {\n const tool: TamboToolWithToolSchema = {\n name: \"tool@name\",\n description: \"A tool\",\n tool: () => \"result\",\n toolSchema: z.function().args().returns(z.string()),\n };\n\n expect(() => validateTool(tool)).toThrow(\n 'tool \"tool@name\" must only contain letters, numbers, underscores, and hyphens.',\n );\n });\n\n it(\"should validate tool with valid Zod schema\", () => {\n const tool: TamboToolWithToolSchema = {\n name: \"valid-tool\",\n description: \"A tool\",\n tool: () => \"result\",\n toolSchema: z.function().args().returns(z.string()),\n };\n\n expect(() => validateTool(tool)).not.toThrow();\n });\n\n it(\"should throw when tool schema contains z.record()\", () => {\n const tool: TamboToolWithToolSchema = {\n name: \"invalid-tool\",\n description: \"A tool\",\n tool: () => \"result\",\n toolSchema: z\n .function()\n .args(\n z.object({\n metadata: z.record(z.string()),\n }),\n )\n .returns(z.string()),\n };\n\n expect(() => validateTool(tool)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in toolSchema of tool \"invalid-tool\".',\n );\n });\n\n it(\"should allow tool with JSON Schema (non-Zod)\", () => {\n const tool: TamboToolWithToolSchema = {\n name: \"tool-with-json-schema\",\n description: \"A tool\",\n tool: () => \"result\",\n toolSchema: {\n type: \"object\",\n properties: {\n query: { type: \"string\" },\n },\n },\n };\n\n expect(() => validateTool(tool)).not.toThrow();\n });\n\n it(\"should validate tool with inputSchema (new interface)\", () => {\n const tool: TamboTool = {\n name: \"tool-with-input-schema\",\n description: \"A tool with input schema\",\n tool: (input: { query: string }) => input.query,\n inputSchema: z.object({\n query: z.string(),\n }),\n outputSchema: z.string(),\n };\n\n expect(() => validateTool(tool)).not.toThrow();\n });\n});\n\ndescribe(\"validateAndPrepareComponent\", () => {\n it(\"should validate component with propsSchema\", () => {\n const component: TamboComponent = {\n name: \"valid-component\",\n description: \"A valid component\",\n component: () => null,\n propsSchema: z.object({\n title: z.string(),\n count: z.number(),\n }),\n };\n\n const result = validateAndPrepareComponent(component);\n\n expect(result.props).toBeDefined();\n expect(result.props.type).toBe(\"object\");\n expect(result.props.properties).toBeDefined();\n });\n\n it(\"should validate component with propsDefinition\", () => {\n const component: TamboComponent = {\n name: \"valid-component\",\n description: \"A valid component\",\n component: () => null,\n propsDefinition: {\n type: \"object\",\n properties: {\n title: { type: \"string\" },\n },\n },\n };\n\n const result = validateAndPrepareComponent(component);\n\n expect(result.props).toEqual(component.propsDefinition);\n });\n\n it(\"should throw when component name contains invalid characters\", () => {\n const component: TamboComponent = {\n name: \"invalid component name\",\n description: \"A component\",\n component: () => null,\n propsSchema: z.object({}),\n };\n\n expect(() => validateAndPrepareComponent(component)).toThrow(\n 'component \"invalid component name\" must only contain letters, numbers, underscores, and hyphens.',\n );\n });\n\n it(\"should throw when neither propsSchema nor propsDefinition is provided\", () => {\n const component: TamboComponent = {\n name: \"component-without-props\",\n description: \"A component\",\n component: () => null,\n };\n\n expect(() => validateAndPrepareComponent(component)).toThrow(\n \"Component component-without-props must have either propsSchema (recommended) or propsDefinition defined\",\n );\n });\n\n it(\"should throw when both propsSchema and propsDefinition are provided\", () => {\n const component: TamboComponent = {\n name: \"component-with-both\",\n description: \"A component\",\n component: () => null,\n propsSchema: z.object({}),\n propsDefinition: {\n type: \"object\",\n properties: {},\n },\n };\n\n expect(() => validateAndPrepareComponent(component)).toThrow(\n \"Component component-with-both cannot have both propsSchema and propsDefinition defined. Use only one. We recommend using propsSchema.\",\n );\n });\n\n it(\"should throw when propsSchema contains z.record()\", () => {\n const component: TamboComponent = {\n name: \"component-with-record\",\n description: \"A component\",\n component: () => null,\n propsSchema: z.object({\n metadata: z.record(z.string()),\n }),\n };\n\n expect(() => validateAndPrepareComponent(component)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in propsSchema of component \"component-with-record\".',\n );\n });\n\n it(\"should convert Zod schema to JSON Schema\", () => {\n const component: TamboComponent = {\n name: \"component-with-zod\",\n description: \"A component\",\n component: () => null,\n propsSchema: z.object({\n title: z.string().describe(\"The title\"),\n count: z.number().int().min(0),\n tags: z.array(z.string()),\n }),\n };\n\n const result = validateAndPrepareComponent(component);\n\n expect(result.props).toBeDefined();\n expect(result.props.type).toBe(\"object\");\n expect((result.props as any).properties).toBeDefined();\n expect((result.props as any).properties.title).toBeDefined();\n expect((result.props as any).properties.count).toBeDefined();\n expect((result.props as any).properties.tags).toBeDefined();\n });\n\n it(\"should handle complex Zod schema\", () => {\n const component: TamboComponent = {\n name: \"component-complex\",\n description: \"A component\",\n component: () => null,\n propsSchema: z.object({\n user: z.object({\n name: z.string(),\n age: z.number(),\n }),\n items: z.array(\n z.object({\n id: z.string(),\n value: z.number(),\n }),\n ),\n }),\n };\n\n const result = validateAndPrepareComponent(component);\n\n expect(result.props).toBeDefined();\n expect(result.props.type).toBe(\"object\");\n });\n\n it(\"should allow JSON Schema (non-Zod) without validation\", () => {\n const component: TamboComponent = {\n name: \"component-json-schema\",\n description: \"A component\",\n component: () => null,\n propsSchema: {\n type: \"object\",\n properties: {\n title: { type: \"string\" },\n },\n },\n };\n\n const result = validateAndPrepareComponent(component);\n\n expect(result.props).toEqual(component.propsSchema);\n });\n});\n\ndescribe(\"validateToolAssociation\", () => {\n it(\"should validate valid tool association\", () => {\n expect(() =>\n validateToolAssociation(\"valid-component\", \"valid-tool\", true, true),\n ).not.toThrow();\n });\n\n it(\"should throw when component name is invalid\", () => {\n expect(() =>\n validateToolAssociation(\"invalid component\", \"valid-tool\", true, true),\n ).toThrow(\n 'component \"invalid component\" must only contain letters, numbers, underscores, and hyphens.',\n );\n });\n\n it(\"should throw when tool name is invalid\", () => {\n expect(() =>\n validateToolAssociation(\"valid-component\", \"invalid tool\", true, true),\n ).toThrow(\n 'tool \"invalid tool\" must only contain letters, numbers, underscores, and hyphens.',\n );\n });\n\n it(\"should throw when component does not exist\", () => {\n expect(() =>\n validateToolAssociation(\"missing-component\", \"valid-tool\", false, true),\n ).toThrow(\"Component missing-component not found in registry\");\n });\n\n it(\"should throw when tool does not exist\", () => {\n expect(() =>\n validateToolAssociation(\"valid-component\", \"missing-tool\", true, false),\n ).toThrow(\"Tool missing-tool not found in registry\");\n });\n\n it(\"should throw when both component and tool do not exist\", () => {\n expect(() => {\n validateToolAssociation(\n \"missing-component\",\n \"missing-tool\",\n false,\n false,\n );\n }).toThrow(\"Component missing-component not found in registry\");\n });\n\n it(\"should validate with valid names containing underscores and hyphens\", () => {\n expect(() =>\n validateToolAssociation(\"my_component-123\", \"my_tool-456\", true, true),\n ).not.toThrow();\n });\n});\n"]}
1
+ {"version":3,"file":"registry-validators.test.js","sourceRoot":"","sources":["../../src/util/registry-validators.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAM3B,OAAO,EACL,2BAA2B,EAC3B,YAAY,EACZ,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAE/B,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,MAAM,IAAI,GAA4B;YACpC,IAAI,EAAE,iBAAiB;YACvB,WAAW,EAAE,cAAc;YAC3B,IAAI,EAAE,GAAG,EAAE,CAAC,QAAQ;YACpB,UAAU,EAAE,CAAC,CAAC,QAAQ,EAAE,CAA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AAC,OAAO,CACP,mFAAmF,CACpF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,CAAC,GAAG,EAAE,CACV,uBAAuB,CAAC,mBAAmB,EAAE,YAAY,EAAE,KAAK,EAAE,IAAI,CAAC,CACxE,CAAC,OAAO,CAAC,mDAAmD,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,CAAC,GAAG,EAAE,CACV,uBAAuB,CAAC,iBAAiB,EAAE,cAAc,EAAE,IAAI,EAAE,KAAK,CAAC,CACxE,CAAC,OAAO,CAAC,yCAAyC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;QAChE,MAAM,CAAC,GAAG,EAAE;YACV,uBAAuB,CACrB,mBAAmB,EACnB,cAAc,EACd,KAAK,EACL,KAAK,CACN,CAAC;QACJ,CAAC,CAAC,CAAC,OAAO,CAAC,mDAAmD,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qEAAqE,EAAE,GAAG,EAAE;QAC7E,MAAM,CAAC,GAAG,EAAE,CACV,uBAAuB,CAAC,kBAAkB,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,CAAC,CACvE,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { z } from \"zod/v3\";\nimport type {\n TamboComponent,\n TamboTool,\n TamboToolWithToolSchema,\n} from \"../model/component-metadata\";\nimport {\n validateAndPrepareComponent,\n validateTool,\n validateToolAssociation,\n} from \"./registry-validators\";\n\ndescribe(\"validateTool\", () => {\n it(\"should validate tool with valid name\", () => {\n const tool: TamboToolWithToolSchema = {\n name: \"valid-tool-name\",\n description: \"A valid tool\",\n tool: () => \"result\",\n toolSchema: z.function().args().returns(z.string()),\n };\n\n expect(() => validateTool(tool)).not.toThrow();\n });\n\n it(\"should throw when tool name contains invalid characters\", () => {\n const tool: TamboToolWithToolSchema = {\n name: \"invalid tool name\",\n description: \"A tool\",\n tool: () => \"result\",\n toolSchema: z.function().args().returns(z.string()),\n };\n\n expect(() => validateTool(tool)).toThrow(\n 'tool \"invalid tool name\" must only contain letters, numbers, underscores, and hyphens.',\n );\n });\n\n it(\"should throw when tool name contains special characters\", () => {\n const tool: TamboToolWithToolSchema = {\n name: \"tool@name\",\n description: \"A tool\",\n tool: () => \"result\",\n toolSchema: z.function().args().returns(z.string()),\n };\n\n expect(() => validateTool(tool)).toThrow(\n 'tool \"tool@name\" must only contain letters, numbers, underscores, and hyphens.',\n );\n });\n\n it(\"should validate tool with valid Zod schema\", () => {\n const tool: TamboToolWithToolSchema = {\n name: \"valid-tool\",\n description: \"A tool\",\n tool: () => \"result\",\n toolSchema: z.function().args().returns(z.string()),\n };\n\n expect(() => validateTool(tool)).not.toThrow();\n });\n\n it(\"should throw when tool schema contains z.record()\", () => {\n const tool: TamboToolWithToolSchema = {\n name: \"invalid-tool\",\n description: \"A tool\",\n tool: () => \"result\",\n toolSchema: z\n .function()\n .args(\n z.object({\n metadata: z.record(z.string()),\n }),\n )\n .returns(z.string()),\n };\n\n expect(() => validateTool(tool)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in toolSchema of tool \"invalid-tool\".',\n );\n });\n\n it(\"should allow tool with JSON Schema (non-Zod)\", () => {\n const tool: TamboToolWithToolSchema = {\n name: \"tool-with-json-schema\",\n description: \"A tool\",\n tool: () => \"result\",\n toolSchema: {\n type: \"object\",\n properties: {\n query: { type: \"string\" },\n },\n },\n };\n\n expect(() => validateTool(tool)).not.toThrow();\n });\n\n it(\"should validate tool with inputSchema (new interface)\", () => {\n const tool: TamboTool = {\n name: \"tool-with-input-schema\",\n description: \"A tool with input schema\",\n tool: (input: { query: string }) => input.query,\n inputSchema: z.object({\n query: z.string(),\n }),\n outputSchema: z.string(),\n };\n\n expect(() => validateTool(tool)).not.toThrow();\n });\n\n it(\"should throw when inputSchema is not an object schema (string)\", () => {\n const tool: TamboTool = {\n name: \"tool-with-string-schema\",\n description: \"A tool with invalid schema\",\n tool: () => \"result\",\n inputSchema: z.string(),\n outputSchema: z.string(),\n };\n\n expect(() => validateTool(tool)).toThrow(\n 'inputSchema of tool \"tool-with-string-schema\" must be an object schema',\n );\n });\n\n it(\"should throw when inputSchema is not an object schema (number)\", () => {\n const tool: TamboTool = {\n name: \"tool-with-number-schema\",\n description: \"A tool with invalid schema\",\n tool: () => \"result\",\n inputSchema: z.number(),\n outputSchema: z.string(),\n };\n\n expect(() => validateTool(tool)).toThrow(\n 'inputSchema of tool \"tool-with-number-schema\" must be an object schema',\n );\n });\n\n it(\"should throw when inputSchema is not an object schema (array)\", () => {\n const tool: TamboTool = {\n name: \"tool-with-array-schema\",\n description: \"A tool with invalid schema\",\n tool: () => \"result\",\n inputSchema: z.array(z.string()),\n outputSchema: z.string(),\n };\n\n expect(() => validateTool(tool)).toThrow(\n 'inputSchema of tool \"tool-with-array-schema\" must be an object schema',\n );\n });\n\n it(\"should throw when inputSchema JSON Schema is not an object type\", () => {\n const tool: TamboTool = {\n name: \"tool-with-json-string-schema\",\n description: \"A tool with invalid JSON schema\",\n tool: () => \"result\",\n inputSchema: { type: \"string\" },\n outputSchema: { type: \"string\" },\n };\n\n expect(() => validateTool(tool)).toThrow(\n 'inputSchema of tool \"tool-with-json-string-schema\" must be an object schema',\n );\n });\n\n it(\"should accept JSON Schema with object type\", () => {\n const tool: TamboTool = {\n name: \"tool-with-json-object-schema\",\n description: \"A tool with valid JSON schema\",\n tool: () => \"result\",\n inputSchema: {\n type: \"object\",\n properties: {\n query: { type: \"string\" },\n },\n },\n outputSchema: { type: \"string\" },\n };\n\n expect(() => validateTool(tool)).not.toThrow();\n });\n\n it(\"should accept JSON Schema with properties but no explicit type\", () => {\n const tool: TamboTool = {\n name: \"tool-with-implicit-object-schema\",\n description: \"A tool with implicit object schema\",\n tool: () => \"result\",\n inputSchema: {\n properties: {\n query: { type: \"string\" },\n },\n },\n outputSchema: { type: \"string\" },\n };\n\n expect(() => validateTool(tool)).not.toThrow();\n });\n});\n\ndescribe(\"validateAndPrepareComponent\", () => {\n it(\"should validate component with propsSchema\", () => {\n const component: TamboComponent = {\n name: \"valid-component\",\n description: \"A valid component\",\n component: () => null,\n propsSchema: z.object({\n title: z.string(),\n count: z.number(),\n }),\n };\n\n const result = validateAndPrepareComponent(component);\n\n expect(result.props).toBeDefined();\n expect(result.props.type).toBe(\"object\");\n expect(result.props.properties).toBeDefined();\n });\n\n it(\"should validate component with propsDefinition\", () => {\n const component: TamboComponent = {\n name: \"valid-component\",\n description: \"A valid component\",\n component: () => null,\n propsDefinition: {\n type: \"object\",\n properties: {\n title: { type: \"string\" },\n },\n },\n };\n\n const result = validateAndPrepareComponent(component);\n\n expect(result.props).toEqual(component.propsDefinition);\n });\n\n it(\"should throw when component name contains invalid characters\", () => {\n const component: TamboComponent = {\n name: \"invalid component name\",\n description: \"A component\",\n component: () => null,\n propsSchema: z.object({}),\n };\n\n expect(() => validateAndPrepareComponent(component)).toThrow(\n 'component \"invalid component name\" must only contain letters, numbers, underscores, and hyphens.',\n );\n });\n\n it(\"should throw when neither propsSchema nor propsDefinition is provided\", () => {\n const component: TamboComponent = {\n name: \"component-without-props\",\n description: \"A component\",\n component: () => null,\n };\n\n expect(() => validateAndPrepareComponent(component)).toThrow(\n \"Component component-without-props must have either propsSchema (recommended) or propsDefinition defined\",\n );\n });\n\n it(\"should throw when both propsSchema and propsDefinition are provided\", () => {\n const component: TamboComponent = {\n name: \"component-with-both\",\n description: \"A component\",\n component: () => null,\n propsSchema: z.object({}),\n propsDefinition: {\n type: \"object\",\n properties: {},\n },\n };\n\n expect(() => validateAndPrepareComponent(component)).toThrow(\n \"Component component-with-both cannot have both propsSchema and propsDefinition defined. Use only one. We recommend using propsSchema.\",\n );\n });\n\n it(\"should throw when propsSchema contains z.record()\", () => {\n const component: TamboComponent = {\n name: \"component-with-record\",\n description: \"A component\",\n component: () => null,\n propsSchema: z.object({\n metadata: z.record(z.string()),\n }),\n };\n\n expect(() => validateAndPrepareComponent(component)).toThrow(\n 'Record types (objects with dynamic keys) are not supported in propsSchema of component \"component-with-record\".',\n );\n });\n\n it(\"should convert Zod schema to JSON Schema\", () => {\n const component: TamboComponent = {\n name: \"component-with-zod\",\n description: \"A component\",\n component: () => null,\n propsSchema: z.object({\n title: z.string().describe(\"The title\"),\n count: z.number().int().min(0),\n tags: z.array(z.string()),\n }),\n };\n\n const result = validateAndPrepareComponent(component);\n\n expect(result.props).toBeDefined();\n expect(result.props.type).toBe(\"object\");\n expect((result.props as any).properties).toBeDefined();\n expect((result.props as any).properties.title).toBeDefined();\n expect((result.props as any).properties.count).toBeDefined();\n expect((result.props as any).properties.tags).toBeDefined();\n });\n\n it(\"should handle complex Zod schema\", () => {\n const component: TamboComponent = {\n name: \"component-complex\",\n description: \"A component\",\n component: () => null,\n propsSchema: z.object({\n user: z.object({\n name: z.string(),\n age: z.number(),\n }),\n items: z.array(\n z.object({\n id: z.string(),\n value: z.number(),\n }),\n ),\n }),\n };\n\n const result = validateAndPrepareComponent(component);\n\n expect(result.props).toBeDefined();\n expect(result.props.type).toBe(\"object\");\n });\n\n it(\"should allow JSON Schema (non-Zod) without validation\", () => {\n const component: TamboComponent = {\n name: \"component-json-schema\",\n description: \"A component\",\n component: () => null,\n propsSchema: {\n type: \"object\",\n properties: {\n title: { type: \"string\" },\n },\n },\n };\n\n const result = validateAndPrepareComponent(component);\n\n expect(result.props).toEqual(component.propsSchema);\n });\n});\n\ndescribe(\"validateToolAssociation\", () => {\n it(\"should validate valid tool association\", () => {\n expect(() =>\n validateToolAssociation(\"valid-component\", \"valid-tool\", true, true),\n ).not.toThrow();\n });\n\n it(\"should throw when component name is invalid\", () => {\n expect(() =>\n validateToolAssociation(\"invalid component\", \"valid-tool\", true, true),\n ).toThrow(\n 'component \"invalid component\" must only contain letters, numbers, underscores, and hyphens.',\n );\n });\n\n it(\"should throw when tool name is invalid\", () => {\n expect(() =>\n validateToolAssociation(\"valid-component\", \"invalid tool\", true, true),\n ).toThrow(\n 'tool \"invalid tool\" must only contain letters, numbers, underscores, and hyphens.',\n );\n });\n\n it(\"should throw when component does not exist\", () => {\n expect(() =>\n validateToolAssociation(\"missing-component\", \"valid-tool\", false, true),\n ).toThrow(\"Component missing-component not found in registry\");\n });\n\n it(\"should throw when tool does not exist\", () => {\n expect(() =>\n validateToolAssociation(\"valid-component\", \"missing-tool\", true, false),\n ).toThrow(\"Tool missing-tool not found in registry\");\n });\n\n it(\"should throw when both component and tool do not exist\", () => {\n expect(() => {\n validateToolAssociation(\n \"missing-component\",\n \"missing-tool\",\n false,\n false,\n );\n }).toThrow(\"Component missing-component not found in registry\");\n });\n\n it(\"should validate with valid names containing underscores and hyphens\", () => {\n expect(() =>\n validateToolAssociation(\"my_component-123\", \"my_tool-456\", true, true),\n ).not.toThrow();\n });\n});\n"]}
@@ -51,11 +51,7 @@ export declare const mapTamboToolToContextTool: (tool: TamboTool | TamboToolWith
51
51
  * import { z } from "zod/v4";
52
52
  *
53
53
  * const myTool = defineTamboTool({
54
- * inputSchema: z.tuple([z.string()]),
55
- * outputSchema: z.number(),
56
- * tool: yourToolFunction,
57
- * // ^-- (input: [string]) => number | Promise<number>
58
- * // Types are inferred from and must match inputSchema/outputSchema definitions
54
+ * // ...
59
55
  * });
60
56
  * ```
61
57
  * @param tool The tool definition to register
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/util/registry.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,SAAS,EACT,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AASrC;;;;;;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AAC,SAAS,GAAG,uBAAuB,CAAC,EAKvC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GACnC,WAAW,mBAAmB,KAC7B,OAYF,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,SAAS,GAAG,uBAAuB,GACxC,SAAS,CAYX;AAED;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GACnC,eAAe,MAAM,EACrB,mBAAmB,iBAAiB,KACnC,mBAUF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GACpC,MAAM,SAAS,GAAG,uBAAuB,KACxC,4BAQF,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,UAAU,EAAE,YAExB,CAAC"}
@@ -109,11 +109,7 @@ export const mapTamboToolToContextTool = (tool) => {
109
109
  * import { z } from "zod/v4";
110
110
  *
111
111
  * const myTool = defineTamboTool({
112
- * inputSchema: z.tuple([z.string()]),
113
- * outputSchema: z.number(),
114
- * tool: yourToolFunction,
115
- * // ^-- (input: [string]) => number | Promise<number>
116
- * // Types are inferred from and must match inputSchema/outputSchema definitions
112
+ * // ...
117
113
  * });
118
114
  * ```
119
115
  * @param tool The tool definition to register
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/util/registry.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,WAAW,CAAC;AAEnB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,iBAAoC,EACpC,YAA+B,EAC/B,gBAAuC,EACT,EAAE;IAChC,MAAM,mBAAmB,GAAiC,EAAE,CAAC;IAE7D,KAAK,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACvE,MAAM,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esContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport {\n ComponentContextToolMetadata,\n ComponentRegistry,\n DefineToolFn,\n RegisteredComponent,\n TamboTool,\n TamboToolAssociations,\n TamboToolRegistry,\n TamboToolWithToolSchema,\n} from \"../model/component-metadata\";\nimport {\n getParametersFromToolSchema,\n getZodFunctionArgs,\n getZodFunctionReturns,\n isStandardSchema,\n schemaToJsonSchema,\n} from \"../schema\";\n\n/**\n * Get all the available components from the component registry\n * @param componentRegistry - The component registry\n * @param toolRegistry - The tool registry\n * @param toolAssociations - The tool associations\n * @returns The available components\n */\nexport const getAvailableComponents = (\n componentRegistry: ComponentRegistry,\n toolRegistry: TamboToolRegistry,\n toolAssociations: TamboToolAssociations,\n): TamboAI.AvailableComponent[] => {\n const availableComponents: TamboAI.AvailableComponent[] = [];\n\n for (const [name, componentEntry] of Object.entries(componentRegistry)) {\n const associatedToolNames = toolAssociations[name] || [];\n\n const contextTools = associatedToolNames\n .map((toolName) => {\n const tool = toolRegistry[toolName];\n if (!tool) return null;\n return mapTamboToolToContextTool(tool);\n })\n .filter((tool): tool is ComponentContextToolMetadata => tool !== null);\n\n availableComponents.push({\n name: componentEntry.name,\n description: componentEntry.description,\n props: componentEntry.props,\n contextTools,\n });\n }\n\n return availableComponents;\n};\n\n/**\n * Get tools from tool registry that are not associated with any component\n * @param toolRegistry - The tool registry\n * @param toolAssociations - The tool associations\n * @returns The tools that are not associated with any component\n */\nexport const getUnassociatedTools = (\n toolRegistry: TamboToolRegistry,\n toolAssociations: TamboToolAssociations,\n): (TamboTool | TamboToolWithToolSchema)[] => {\n return Object.values(toolRegistry).filter((tool) => {\n // Check if the tool's name appears in any of the tool association arrays\n return !Object.values(toolAssociations).flat().includes(tool.name);\n });\n};\n\n/**\n * Helper function to convert component props from Standard Schema or JSON Schema\n * @param component - The component to convert\n * @returns The converted props as JSON Schema\n */\nexport const convertPropsToJsonSchema = (\n component: RegisteredComponent,\n): unknown => {\n if (!component.props) {\n return component.props;\n }\n\n // Check if props is a Standard Schema (Zod, Valibot, ArkType, etc.)\n if (isStandardSchema(component.props)) {\n return schemaToJsonSchema(component.props);\n }\n\n // Already JSON Schema or unknown format - return as-is\n return component.props;\n};\n\n/**\n * Adapt a Tambo tool defined with function schema to a standard Tambo tool\n * @param tool - The Tambo tool with function schema\n * @returns The adapted Tambo tool\n */\nexport function adaptToolFromFnSchema(\n tool: TamboTool | TamboToolWithToolSchema,\n): TamboTool {\n if (!(\"toolSchema\" in tool)) {\n return tool;\n }\n\n return {\n name: tool.name,\n description: tool.description,\n tool: tool.tool,\n inputSchema: getZodFunctionArgs(tool.toolSchema),\n outputSchema: getZodFunctionReturns(tool.toolSchema),\n };\n}\n\n/**\n * Get a component by name from the component registry\n * @param componentName - The name of the component to get\n * @param componentRegistry - The component registry\n * @returns The component registration information\n */\nexport const getComponentFromRegistry = (\n componentName: string,\n componentRegistry: ComponentRegistry,\n): RegisteredComponent => {\n const componentEntry = componentRegistry[componentName];\n\n if (!componentEntry) {\n throw new Error(\n `Tambo tried to use Component ${componentName}, but it was not found.`,\n );\n }\n\n return componentEntry;\n};\n\n/**\n * Map a Tambo tool to a context tool\n * @param tool - The tool to map (supports both new inputSchema and deprecated toolSchema interfaces)\n * @returns The context tool\n */\nexport const mapTamboToolToContextTool = (\n tool: TamboTool | TamboToolWithToolSchema,\n): ComponentContextToolMetadata => {\n const parameters = getParametersFromToolSchema(tool);\n\n return {\n name: tool.name,\n description: tool.description,\n parameters,\n };\n};\n\n/**\n * Provides type safety for defining a Tambo Tool.\n *\n * Tambo uses the [standard-schema.dev](https://standard-schema.dev) spec which means you can use any Standard Schema\n * compliant validator (Zod, Valibot, ArkType, etc.). This ensures the tool function args and output types are correctly\n * inferred from the provided schemas.\n * @example\n * ```typescript\n * import { z } from \"zod/v4\";\n *\n * const myTool = defineTamboTool({\n * inputSchema: z.tuple([z.string()]),\n * outputSchema: z.number(),\n * tool: yourToolFunction,\n * // ^-- (input: [string]) => number | Promise<number>\n * // Types are inferred from and must match inputSchema/outputSchema definitions\n * });\n * ```\n * @param tool The tool definition to register\n * @returns The registered tool definition\n */\nexport const defineTool: DefineToolFn = (tool: any) => {\n return tool;\n};\n"]}
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/util/registry.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,WAAW,CAAC;AAEnB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,iBAAoC,EACpC,YAA+B,EAC/B,gBAAuC,EACT,EAAE;IAChC,MAAM,mBAAmB,GAAiC,EAAE,CAAC;IAE7D,KAAK,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACvE,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAEzD,MAAM,YAAY,GAAG,mBAAmB;aACrC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;YAChB,MAAM,IAAI,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;YACpC,IAAI,CAAC,IAAI;gBAAE,OAAO,IAAI,CAAC;YACvB,OAAO,yBAAyB,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC,CAAC;aACD,MAAM,CAAC,CAAC,IAAI,EAAwC,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QAEzE,mBAAmB,CAAC,IAAI,CAAC;YACvB,IAAI,EAAE,cAAc,CAAC,IAAI;YACzB,WAAW,EAAE,cAAc,CAAC,WAAW;YACvC,KAAK,EAAE,cAAc,CAAC,KAAK;YAC3B,YAAY;SACb,CAAC,CAAC;IACL,CAAC;IAED,OAAO,mBAAmB,CAAC;AAC7B,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA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C,aAAa,CAAC,CAAC;IAExD,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,gCAAgC,aAAa,yBAAyB,CACvE,CAAC;IACJ,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,IAAyC,EACX,EAAE;IAChC,MAAM,UAAU,GAAG,2BAA2B,CAAC,IAAI,CAAC,CAAC;IAErD,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU;KACX,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,UAAU,GAAiB,CAAC,IAAS,EAAE,EAAE;IACpD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport {\n ComponentContextToolMetadata,\n ComponentRegistry,\n DefineToolFn,\n RegisteredComponent,\n TamboTool,\n TamboToolAssociations,\n TamboToolRegistry,\n TamboToolWithToolSchema,\n} from \"../model/component-metadata\";\nimport {\n getParametersFromToolSchema,\n getZodFunctionArgs,\n getZodFunctionReturns,\n isStandardSchema,\n schemaToJsonSchema,\n} from \"../schema\";\n\n/**\n * Get all the available components from the component registry\n * @param componentRegistry - The component registry\n * @param toolRegistry - The tool registry\n * @param toolAssociations - The tool associations\n * @returns The available components\n */\nexport const getAvailableComponents = (\n componentRegistry: ComponentRegistry,\n toolRegistry: TamboToolRegistry,\n toolAssociations: TamboToolAssociations,\n): TamboAI.AvailableComponent[] => {\n const availableComponents: TamboAI.AvailableComponent[] = [];\n\n for (const [name, componentEntry] of Object.entries(componentRegistry)) {\n const associatedToolNames = toolAssociations[name] || [];\n\n const contextTools = associatedToolNames\n .map((toolName) => {\n const tool = toolRegistry[toolName];\n if (!tool) return null;\n return mapTamboToolToContextTool(tool);\n })\n .filter((tool): tool is ComponentContextToolMetadata => tool !== null);\n\n availableComponents.push({\n name: componentEntry.name,\n description: componentEntry.description,\n props: componentEntry.props,\n contextTools,\n });\n }\n\n return availableComponents;\n};\n\n/**\n * Get tools from tool registry that are not associated with any component\n * @param toolRegistry - The tool registry\n * @param toolAssociations - The tool associations\n * @returns The tools that are not associated with any component\n */\nexport const getUnassociatedTools = (\n toolRegistry: TamboToolRegistry,\n toolAssociations: TamboToolAssociations,\n): (TamboTool | TamboToolWithToolSchema)[] => {\n return Object.values(toolRegistry).filter((tool) => {\n // Check if the tool's name appears in any of the tool association arrays\n return !Object.values(toolAssociations).flat().includes(tool.name);\n });\n};\n\n/**\n * Helper function to convert component props from Standard Schema or JSON Schema\n * @param component - The component to convert\n * @returns The converted props as JSON Schema\n */\nexport const convertPropsToJsonSchema = (\n component: RegisteredComponent,\n): unknown => {\n if (!component.props) {\n return component.props;\n }\n\n // Check if props is a Standard Schema (Zod, Valibot, ArkType, etc.)\n if (isStandardSchema(component.props)) {\n return schemaToJsonSchema(component.props);\n }\n\n // Already JSON Schema or unknown format - return as-is\n return component.props;\n};\n\n/**\n * Adapt a Tambo tool defined with function schema to a standard Tambo tool\n * @param tool - The Tambo tool with function schema\n * @returns The adapted Tambo tool\n */\nexport function adaptToolFromFnSchema(\n tool: TamboTool | TamboToolWithToolSchema,\n): TamboTool {\n if (!(\"toolSchema\" in tool)) {\n return tool;\n }\n\n return {\n name: tool.name,\n description: tool.description,\n tool: tool.tool,\n inputSchema: getZodFunctionArgs(tool.toolSchema),\n outputSchema: getZodFunctionReturns(tool.toolSchema),\n };\n}\n\n/**\n * Get a component by name from the component registry\n * @param componentName - The name of the component to get\n * @param componentRegistry - The component registry\n * @returns The component registration information\n */\nexport const getComponentFromRegistry = (\n componentName: string,\n componentRegistry: ComponentRegistry,\n): RegisteredComponent => {\n const componentEntry = componentRegistry[componentName];\n\n if (!componentEntry) {\n throw new Error(\n `Tambo tried to use Component ${componentName}, but it was not found.`,\n );\n }\n\n return componentEntry;\n};\n\n/**\n * Map a Tambo tool to a context tool\n * @param tool - The tool to map (supports both new inputSchema and deprecated toolSchema interfaces)\n * @returns The context tool\n */\nexport const mapTamboToolToContextTool = (\n tool: TamboTool | TamboToolWithToolSchema,\n): ComponentContextToolMetadata => {\n const parameters = getParametersFromToolSchema(tool);\n\n return {\n name: tool.name,\n description: tool.description,\n parameters,\n };\n};\n\n/**\n * Provides type safety for defining a Tambo Tool.\n *\n * Tambo uses the [standard-schema.dev](https://standard-schema.dev) spec which means you can use any Standard Schema\n * compliant validator (Zod, Valibot, ArkType, etc.). This ensures the tool function args and output types are correctly\n * inferred from the provided schemas.\n * @example\n * ```typescript\n * import { z } from \"zod/v4\";\n *\n * const myTool = defineTamboTool({\n * // ...\n * });\n * ```\n * @param tool The tool definition to register\n * @returns The registered tool definition\n */\nexport const defineTool: DefineToolFn = (tool: any) => {\n return tool;\n};\n"]}