@tambo-ai/react 0.66.1 → 0.66.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/use-current-message.d.ts +2 -0
- package/dist/hooks/use-current-message.d.ts.map +1 -1
- package/dist/hooks/use-current-message.js +1 -0
- package/dist/hooks/use-current-message.js.map +1 -1
- package/dist/hooks/use-current-message.test.js +5 -0
- package/dist/hooks/use-current-message.test.js.map +1 -1
- package/dist/model/component-metadata.d.ts +2 -2
- package/dist/model/component-metadata.d.ts.map +1 -1
- package/dist/model/component-metadata.js.map +1 -1
- package/dist/providers/tambo-interactable-provider-partial-updates.test.js +87 -87
- package/dist/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/dist/providers/tambo-interactable-provider.js +46 -40
- package/dist/providers/tambo-interactable-provider.js.map +1 -1
- package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js +8 -8
- package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
- package/dist/providers/tambo-interactables-additional-context.test.js +10 -10
- package/dist/providers/tambo-interactables-additional-context.test.js.map +1 -1
- package/dist/providers/tambo-registry-provider.test.js +28 -18
- package/dist/providers/tambo-registry-provider.test.js.map +1 -1
- package/dist/providers/tambo-registry-schema-compat.test.js +57 -28
- package/dist/providers/tambo-registry-schema-compat.test.js.map +1 -1
- package/dist/providers/tambo-thread-provider.test.js +21 -19
- package/dist/providers/tambo-thread-provider.test.js.map +1 -1
- package/dist/schema/alias.d.ts +3 -0
- package/dist/schema/alias.d.ts.map +1 -0
- package/dist/schema/alias.js +6 -0
- package/dist/schema/alias.js.map +1 -0
- package/dist/schema/json-schema.js +29 -29
- package/dist/schema/json-schema.js.map +1 -1
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/schema.js +20 -9
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/schema.test.js +291 -3
- package/dist/schema/schema.test.js.map +1 -1
- package/dist/schema/standard-schema.js +8 -8
- package/dist/schema/standard-schema.js.map +1 -1
- package/dist/schema/validate.test.js +31 -31
- package/dist/schema/validate.test.js.map +1 -1
- package/dist/schema/zod.d.ts +1 -1
- package/dist/schema/zod.d.ts.map +1 -1
- package/dist/schema/zod.js +25 -24
- package/dist/schema/zod.js.map +1 -1
- package/dist/util/registry-validators.d.ts.map +1 -1
- package/dist/util/registry-validators.js +40 -0
- package/dist/util/registry-validators.js.map +1 -1
- package/dist/util/registry-validators.test.js +69 -0
- package/dist/util/registry-validators.test.js.map +1 -1
- package/dist/util/registry.d.ts +1 -5
- package/dist/util/registry.d.ts.map +1 -1
- package/dist/util/registry.js +1 -5
- package/dist/util/registry.js.map +1 -1
- package/dist/util/registry.test.js +80 -67
- package/dist/util/registry.test.js.map +1 -1
- package/esm/hooks/use-current-message.d.ts +2 -0
- package/esm/hooks/use-current-message.d.ts.map +1 -1
- package/esm/hooks/use-current-message.js +1 -0
- package/esm/hooks/use-current-message.js.map +1 -1
- package/esm/hooks/use-current-message.test.js +5 -0
- package/esm/hooks/use-current-message.test.js.map +1 -1
- package/esm/model/component-metadata.d.ts +2 -2
- package/esm/model/component-metadata.d.ts.map +1 -1
- package/esm/model/component-metadata.js.map +1 -1
- package/esm/providers/tambo-interactable-provider-partial-updates.test.js +1 -1
- package/esm/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/esm/providers/tambo-interactable-provider.js +17 -11
- package/esm/providers/tambo-interactable-provider.js.map +1 -1
- package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js +1 -1
- package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
- package/esm/providers/tambo-interactables-additional-context.test.js +1 -1
- package/esm/providers/tambo-interactables-additional-context.test.js.map +1 -1
- package/esm/providers/tambo-registry-provider.test.js +16 -6
- package/esm/providers/tambo-registry-provider.test.js.map +1 -1
- package/esm/providers/tambo-registry-schema-compat.test.js +57 -28
- package/esm/providers/tambo-registry-schema-compat.test.js.map +1 -1
- package/esm/providers/tambo-thread-provider.test.js +8 -6
- package/esm/providers/tambo-thread-provider.test.js.map +1 -1
- package/esm/schema/alias.d.ts +3 -0
- package/esm/schema/alias.d.ts.map +1 -0
- package/esm/schema/alias.js +13 -0
- package/esm/schema/alias.js.map +1 -0
- package/esm/schema/json-schema.js +1 -1
- package/esm/schema/json-schema.js.map +1 -1
- package/esm/schema/schema.d.ts.map +1 -1
- package/esm/schema/schema.js +20 -9
- package/esm/schema/schema.js.map +1 -1
- package/esm/schema/schema.test.js +258 -3
- package/esm/schema/schema.test.js.map +1 -1
- package/esm/schema/standard-schema.js +1 -1
- package/esm/schema/standard-schema.js.map +1 -1
- package/esm/schema/validate.test.js +1 -1
- package/esm/schema/validate.test.js.map +1 -1
- package/esm/schema/zod.d.ts +1 -1
- package/esm/schema/zod.d.ts.map +1 -1
- package/esm/schema/zod.js +25 -24
- package/esm/schema/zod.js.map +1 -1
- package/esm/util/registry-validators.d.ts.map +1 -1
- package/esm/util/registry-validators.js +40 -0
- package/esm/util/registry-validators.js.map +1 -1
- package/esm/util/registry-validators.test.js +69 -0
- package/esm/util/registry-validators.test.js.map +1 -1
- package/esm/util/registry.d.ts +1 -5
- package/esm/util/registry.d.ts.map +1 -1
- package/esm/util/registry.js +1 -5
- package/esm/util/registry.js.map +1 -1
- package/esm/util/registry.test.js +80 -67
- package/esm/util/registry.test.js.map +1 -1
- package/package.json +1 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry-validators.test.js","sourceRoot":"","sources":["../../src/util/registry-validators.test.ts"],"names":[],"mappings":";;AAAA,+BAA2B;AAM3B,+DAI+B;AAE/B,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,MAAM,IAAI,GAA4B;YACpC,IAAI,EAAE,iBAAiB;YACvB,WAA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EH,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,MAAM,CAAC,GAAG,EAAE,CACV,IAAA,6CAAuB,EAAC,iBAAiB,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,CAAC,CACvE,CAAC,OAAO,CACP,mFAAmF,CACpF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,CAAC,GAAG,EAAE,CACV,IAAA,6CAAuB,EAAC,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,IAAA,6CAAuB,EAAC,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,IAAA,6CAAuB,EACrB,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,IAAA,6CAAuB,EAAC,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\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,+BAA2B;AAM3B,+DAI+B;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,MAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAC,CAAC,MAAM,EAAE,CAAC;SACpD,CAAC;QAEF,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,kC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AE,cAAc,EAAE,IAAI,EAAE,IAAI,CAAC,CACvE,CAAC,OAAO,CACP,mFAAmF,CACpF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,CAAC,GAAG,EAAE,CACV,IAAA,6CAAuB,EAAC,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,IAAA,6CAAuB,EAAC,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,IAAA,6CAAuB,EACrB,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,IAAA,6CAAuB,EAAC,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"]}
|
package/dist/util/registry.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
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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BAAkB,EAuB5B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAC/B,cAAc,iBAAiB,EAC/B,kBAAkB,qBAAqB,KACtC,CAAC,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"}
|
package/dist/util/registry.js
CHANGED
|
@@ -118,11 +118,7 @@ exports.mapTamboToolToContextTool = mapTamboToolToContextTool;
|
|
|
118
118
|
* import { z } from "zod/v4";
|
|
119
119
|
*
|
|
120
120
|
* const myTool = defineTamboTool({
|
|
121
|
-
*
|
|
122
|
-
* outputSchema: z.number(),
|
|
123
|
-
* tool: yourToolFunction,
|
|
124
|
-
* // ^-- (input: [string]) => number | Promise<number>
|
|
125
|
-
* // Types are inferred from and must match inputSchema/outputSchema definitions
|
|
121
|
+
* // ...
|
|
126
122
|
* });
|
|
127
123
|
* ```
|
|
128
124
|
* @param tool The tool definition to register
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/util/registry.ts"],"names":[],"mappings":";;;AAiGA,sDAcC;AApGD,sCAMmB;AAEnB;;;;;;GAMG;AACI,MAAM,sBAAsB,GAAG,CACpC,iBAAoC,EACpC,YAA+B,EAC/B,gBAAuC,EACT,EAAE;IAChC,MAAM,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AiB,CAAC,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;AAbW,QAAA,wBAAwB,4BAanC;AAEF;;;;GAIG;AACI,MAAM,yBAAyB,GAAG,CACvC,IAAyC,EACX,EAAE;IAChC,MAAM,UAAU,GAAG,IAAA,oCAA2B,EAAC,IAAI,CAAC,CAAC;IAErD,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU;KACX,CAAC;AACJ,CAAC,CAAC;AAVW,QAAA,yBAAyB,6BAUpC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACI,MAAM,UAAU,GAAiB,CAAC,IAAS,EAAE,EAAE;IACpD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAFW,QAAA,UAAU,cAErB","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"]}
|
|
@@ -33,7 +33,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const v = __importStar(require("valibot"));
|
|
37
36
|
const z3 = __importStar(require("zod/v3"));
|
|
38
37
|
const z4 = __importStar(require("zod/v4"));
|
|
39
38
|
const tools_1 = require("../testing/tools");
|
|
@@ -60,7 +59,7 @@ describe("getParametersFromToolSchema (via mapTamboToolToContextTool)", () => {
|
|
|
60
59
|
});
|
|
61
60
|
describe("New inputSchema interface (object schemas)", () => {
|
|
62
61
|
describe("Zod 4 object schemas", () => {
|
|
63
|
-
it("should
|
|
62
|
+
it("should extract parameters from object schema properties", () => {
|
|
64
63
|
const tool = (0, tools_1.createMockTool)({
|
|
65
64
|
inputSchema: z4.object({
|
|
66
65
|
name: z4.string().describe("User name"),
|
|
@@ -69,9 +68,18 @@ describe("getParametersFromToolSchema (via mapTamboToolToContextTool)", () => {
|
|
|
69
68
|
outputSchema: z4.boolean(),
|
|
70
69
|
});
|
|
71
70
|
const result = (0, registry_1.mapTamboToolToContextTool)(tool);
|
|
72
|
-
expect(result.parameters).toHaveLength(
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
expect(result.parameters).toHaveLength(2);
|
|
72
|
+
// Parameters should be extracted from object properties
|
|
73
|
+
const nameParam = result.parameters.find((p) => p.name === "name");
|
|
74
|
+
const ageParam = result.parameters.find((p) => p.name === "age");
|
|
75
|
+
expect(nameParam).toBeDefined();
|
|
76
|
+
expect(nameParam?.type).toBe("string");
|
|
77
|
+
expect(nameParam?.description).toBe("User name");
|
|
78
|
+
expect(nameParam?.isRequired).toBe(true);
|
|
79
|
+
expect(ageParam).toBeDefined();
|
|
80
|
+
expect(ageParam?.type).toBe("number");
|
|
81
|
+
expect(ageParam?.description).toBe("User age");
|
|
82
|
+
expect(ageParam?.isRequired).toBe(true);
|
|
75
83
|
expect(result.parameters).toMatchSnapshot();
|
|
76
84
|
});
|
|
77
85
|
it("should handle complex nested objects", () => {
|
|
@@ -84,108 +92,108 @@ describe("getParametersFromToolSchema (via mapTamboToolToContextTool)", () => {
|
|
|
84
92
|
outputSchema: z4.void(),
|
|
85
93
|
});
|
|
86
94
|
const result = (0, registry_1.mapTamboToolToContextTool)(tool);
|
|
87
|
-
expect(result.parameters).toHaveLength(
|
|
88
|
-
|
|
95
|
+
expect(result.parameters).toHaveLength(3);
|
|
96
|
+
const pointParam = result.parameters.find((p) => p.name === "point");
|
|
97
|
+
const tagsParam = result.parameters.find((p) => p.name === "tags");
|
|
98
|
+
const colorParam = result.parameters.find((p) => p.name === "color");
|
|
99
|
+
expect(pointParam).toBeDefined();
|
|
100
|
+
expect(pointParam?.type).toBe("object");
|
|
101
|
+
expect(tagsParam).toBeDefined();
|
|
102
|
+
expect(tagsParam?.type).toBe("array");
|
|
103
|
+
expect(colorParam).toBeDefined();
|
|
104
|
+
expect(colorParam?.type).toBe("string");
|
|
89
105
|
expect(result.parameters).toMatchSnapshot();
|
|
90
106
|
});
|
|
91
107
|
});
|
|
92
108
|
describe("Zod 3 object schemas", () => {
|
|
93
|
-
it("should
|
|
109
|
+
it("should extract parameters from object schema properties", () => {
|
|
94
110
|
const tool = (0, tools_1.createMockTool)({
|
|
95
111
|
inputSchema: z3.object({
|
|
96
|
-
name: z3.string(),
|
|
97
|
-
age: z3.number(),
|
|
112
|
+
name: z3.string().describe("User name"),
|
|
113
|
+
age: z3.number().describe("User age"),
|
|
98
114
|
}),
|
|
99
115
|
outputSchema: z3.boolean(),
|
|
100
116
|
});
|
|
101
117
|
const result = (0, registry_1.mapTamboToolToContextTool)(tool);
|
|
102
|
-
expect(result.parameters).toHaveLength(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
name: v.string(),
|
|
112
|
-
age: v.number(),
|
|
113
|
-
}),
|
|
114
|
-
outputSchema: v.boolean(),
|
|
115
|
-
});
|
|
116
|
-
const result = (0, registry_1.mapTamboToolToContextTool)(tool);
|
|
117
|
-
expect(result.parameters).toHaveLength(1);
|
|
118
|
-
expect(result.parameters[0].name).toBe("input");
|
|
119
|
-
expect(result.parameters).toMatchSnapshot();
|
|
120
|
-
});
|
|
121
|
-
it("should handle complex nested objects", () => {
|
|
122
|
-
const tool = (0, tools_1.createMockTool)({
|
|
123
|
-
inputSchema: v.object({
|
|
124
|
-
point: v.pipe(v.object({ x: v.number(), y: v.number() }), v.description("Point")),
|
|
125
|
-
tags: v.array(v.string()),
|
|
126
|
-
color: v.picklist(["red", "green", "blue"]),
|
|
127
|
-
}),
|
|
128
|
-
outputSchema: v.undefined(),
|
|
129
|
-
});
|
|
130
|
-
const result = (0, registry_1.mapTamboToolToContextTool)(tool);
|
|
131
|
-
expect(result.parameters).toHaveLength(1);
|
|
132
|
-
expect(result.parameters[0].name).toBe("input");
|
|
118
|
+
expect(result.parameters).toHaveLength(2);
|
|
119
|
+
const nameParam = result.parameters.find((p) => p.name === "name");
|
|
120
|
+
const ageParam = result.parameters.find((p) => p.name === "age");
|
|
121
|
+
expect(nameParam).toBeDefined();
|
|
122
|
+
expect(nameParam?.type).toBe("string");
|
|
123
|
+
expect(nameParam?.isRequired).toBe(true);
|
|
124
|
+
expect(ageParam).toBeDefined();
|
|
125
|
+
expect(ageParam?.type).toBe("number");
|
|
126
|
+
expect(ageParam?.isRequired).toBe(true);
|
|
133
127
|
expect(result.parameters).toMatchSnapshot();
|
|
134
128
|
});
|
|
135
129
|
});
|
|
136
130
|
describe("JSON Schema object schemas", () => {
|
|
137
|
-
it("should
|
|
131
|
+
it("should extract parameters from object schema properties", () => {
|
|
138
132
|
const schema = {
|
|
139
133
|
type: "object",
|
|
140
134
|
properties: {
|
|
141
|
-
name: { type: "string" },
|
|
142
|
-
age: { type: "number" },
|
|
135
|
+
name: { type: "string", description: "User name" },
|
|
136
|
+
age: { type: "number", description: "User age" },
|
|
143
137
|
},
|
|
144
138
|
required: ["name"],
|
|
145
139
|
description: "User data",
|
|
146
140
|
};
|
|
147
141
|
const tool = (0, tools_1.createMockTool)({ inputSchema: schema, outputSchema: {} });
|
|
148
142
|
const result = (0, registry_1.mapTamboToolToContextTool)(tool);
|
|
149
|
-
expect(result.parameters).toHaveLength(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
expect(
|
|
143
|
+
expect(result.parameters).toHaveLength(2);
|
|
144
|
+
const nameParam = result.parameters.find((p) => p.name === "name");
|
|
145
|
+
const ageParam = result.parameters.find((p) => p.name === "age");
|
|
146
|
+
expect(nameParam).toBeDefined();
|
|
147
|
+
expect(nameParam?.type).toBe("string");
|
|
148
|
+
expect(nameParam?.description).toBe("User name");
|
|
149
|
+
expect(nameParam?.isRequired).toBe(true);
|
|
150
|
+
expect(ageParam).toBeDefined();
|
|
151
|
+
expect(ageParam?.type).toBe("number");
|
|
152
|
+
expect(ageParam?.description).toBe("User age");
|
|
153
|
+
expect(ageParam?.isRequired).toBe(false);
|
|
153
154
|
expect(result.parameters).toMatchSnapshot();
|
|
154
155
|
});
|
|
156
|
+
it("should handle empty object schema", () => {
|
|
157
|
+
const schema = {
|
|
158
|
+
type: "object",
|
|
159
|
+
properties: {},
|
|
160
|
+
};
|
|
161
|
+
const tool = (0, tools_1.createMockTool)({ inputSchema: schema, outputSchema: {} });
|
|
162
|
+
const result = (0, registry_1.mapTamboToolToContextTool)(tool);
|
|
163
|
+
expect(result.parameters).toHaveLength(0);
|
|
164
|
+
});
|
|
155
165
|
});
|
|
156
166
|
});
|
|
157
167
|
describe("Direct schema (shorthand for inputSchema)", () => {
|
|
158
|
-
it("should accept Zod 4 object schema directly", () => {
|
|
168
|
+
it("should accept Zod 4 object schema directly and extract parameters", () => {
|
|
159
169
|
const tool = (0, tools_1.createMockTool)(z4.object({
|
|
160
170
|
name: z4.string(),
|
|
161
171
|
age: z4.number(),
|
|
162
172
|
}));
|
|
163
173
|
const result = (0, registry_1.mapTamboToolToContextTool)(tool);
|
|
164
|
-
expect(result.parameters).toHaveLength(
|
|
165
|
-
|
|
174
|
+
expect(result.parameters).toHaveLength(2);
|
|
175
|
+
const nameParam = result.parameters.find((p) => p.name === "name");
|
|
176
|
+
const ageParam = result.parameters.find((p) => p.name === "age");
|
|
177
|
+
expect(nameParam).toBeDefined();
|
|
178
|
+
expect(nameParam?.type).toBe("string");
|
|
179
|
+
expect(ageParam).toBeDefined();
|
|
180
|
+
expect(ageParam?.type).toBe("number");
|
|
166
181
|
expect(result.parameters).toMatchSnapshot();
|
|
167
182
|
});
|
|
168
|
-
it("should accept Zod 3 object schema directly", () => {
|
|
183
|
+
it("should accept Zod 3 object schema directly and extract parameters", () => {
|
|
169
184
|
const tool = (0, tools_1.createMockTool)(z3.object({
|
|
170
185
|
name: z3.string(),
|
|
171
186
|
age: z3.number(),
|
|
172
187
|
}));
|
|
173
188
|
const result = (0, registry_1.mapTamboToolToContextTool)(tool);
|
|
174
|
-
expect(result.parameters).toHaveLength(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const tool = (0, tools_1.createMockTool)(v.object({
|
|
180
|
-
name: v.string(),
|
|
181
|
-
age: v.number(),
|
|
182
|
-
}));
|
|
183
|
-
const result = (0, registry_1.mapTamboToolToContextTool)(tool);
|
|
184
|
-
expect(result.parameters).toHaveLength(1);
|
|
185
|
-
expect(result.parameters[0].name).toBe("input");
|
|
189
|
+
expect(result.parameters).toHaveLength(2);
|
|
190
|
+
const nameParam = result.parameters.find((p) => p.name === "name");
|
|
191
|
+
const ageParam = result.parameters.find((p) => p.name === "age");
|
|
192
|
+
expect(nameParam).toBeDefined();
|
|
193
|
+
expect(ageParam).toBeDefined();
|
|
186
194
|
expect(result.parameters).toMatchSnapshot();
|
|
187
195
|
});
|
|
188
|
-
it("should accept JSON Schema object directly", () => {
|
|
196
|
+
it("should accept JSON Schema object directly and extract parameters", () => {
|
|
189
197
|
const schema = {
|
|
190
198
|
type: "object",
|
|
191
199
|
properties: {
|
|
@@ -195,8 +203,13 @@ describe("getParametersFromToolSchema (via mapTamboToolToContextTool)", () => {
|
|
|
195
203
|
};
|
|
196
204
|
const tool = (0, tools_1.createMockTool)(schema);
|
|
197
205
|
const result = (0, registry_1.mapTamboToolToContextTool)(tool);
|
|
198
|
-
expect(result.parameters).toHaveLength(
|
|
199
|
-
|
|
206
|
+
expect(result.parameters).toHaveLength(2);
|
|
207
|
+
const nameParam = result.parameters.find((p) => p.name === "name");
|
|
208
|
+
const ageParam = result.parameters.find((p) => p.name === "age");
|
|
209
|
+
expect(nameParam).toBeDefined();
|
|
210
|
+
expect(nameParam?.type).toBe("string");
|
|
211
|
+
expect(ageParam).toBeDefined();
|
|
212
|
+
expect(ageParam?.type).toBe("number");
|
|
200
213
|
expect(result.parameters).toMatchSnapshot();
|
|
201
214
|
});
|
|
202
215
|
});
|
|
@@ -1 +1 @@
|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AG,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,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,MAAM,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;YAC3D,MAAM,CAAC,MAAM,CAAC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AC,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"]}
|
|
@@ -44,6 +44,8 @@ export interface TamboCurrentComponent {
|
|
|
44
44
|
interactableId?: string;
|
|
45
45
|
/** Description (only present for components wrapped with withInteractable) */
|
|
46
46
|
description?: string;
|
|
47
|
+
/** Thread ID from the message (only present when the component is part of a thread) */
|
|
48
|
+
threadId?: string;
|
|
47
49
|
}
|
|
48
50
|
/**
|
|
49
51
|
* Hook to access the current component information from the message context.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-current-message.d.ts","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AACA,OAAO,KAAoC,MAAM,OAAO,CAAC;AACzD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,sCAAsC,CAAC;AAI9C,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,OAAO,EAAE,kBAAkB,CAAC;IAC5B,kFAAkF;IAClF,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC,yBAAyB,CAkBpE,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,OAAO,EAAE,kBAAkB,EAC3B,oBAAoB,CAAC,EAAE,oBAAoB,qBAU5C;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,0BAQlC,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,sCAAsC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,kFAAkF;IAClF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,8EAA8E;IAC9E,WAAW,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"use-current-message.d.ts","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AACA,OAAO,KAAoC,MAAM,OAAO,CAAC;AACzD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,sCAAsC,CAAC;AAI9C,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,OAAO,EAAE,kBAAkB,CAAC;IAC5B,kFAAkF;IAClF,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC,yBAAyB,CAkBpE,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,OAAO,EAAE,kBAAkB,EAC3B,oBAAoB,CAAC,EAAE,oBAAoB,qBAU5C;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,0BAQlC,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,sCAAsC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,kFAAkF;IAClF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,8EAA8E;IAC9E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,wBAAwB,QAAO,qBAAqB,GAAG,IAiBnE,CAAC"}
|
|
@@ -77,6 +77,7 @@ export const useTamboCurrentComponent = () => {
|
|
|
77
77
|
props: message.component?.props,
|
|
78
78
|
interactableId: message.interactableMetadata?.id ?? undefined,
|
|
79
79
|
description: message.interactableMetadata?.description ?? undefined,
|
|
80
|
+
threadId: message.threadId,
|
|
80
81
|
};
|
|
81
82
|
};
|
|
82
83
|
//# sourceMappingURL=use-current-message.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-current-message.js","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAMzD,MAAM,mBAAmB,GAAG,aAAa,CAA4B,IAAI,CAAC,CAAC;AAS3E;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAwC,CAAC,EACxE,QAAQ,EACR,OAAO,EACP,oBAAoB,GACrB,EAAE,EAAE;IACH,uDAAuD;IACvD,MAAM,eAAe,GAAuB,oBAAoB;QAC9D,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,oBAAoB,EAAE;QACtC,CAAC,CAAC,OAAO,CAAC;IAEZ,8EAA8E;IAC9E,2EAA2E;IAC3E,6EAA6E;IAC7E,OAAO,CACL,oBAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,IAClE,QAAQ,CACoB,CAChC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B,CAC1C,QAAyB,EACzB,OAA2B,EAC3B,oBAA2C;IAE3C,OAAO,CACL,oBAAC,oBAAoB,IACnB,OAAO,EAAE,OAAO,EAChB,oBAAoB,EAAE,oBAAoB,IAEzC,QAAQ,CACY,CACxB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,OAAO,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;
|
|
1
|
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G,GAAiC,EAAE;IACzE,MAAM,OAAO,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAEhD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,aAAa,EACX,OAAO,CAAC,oBAAoB,EAAE,aAAa;YAC3C,OAAO,CAAC,SAAS,EAAE,aAAa;YAChC,SAAS;QACX,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE,KAAwC;QAClE,cAAc,EAAE,OAAO,CAAC,oBAAoB,EAAE,EAAE,IAAI,SAAS;QAC7D,WAAW,EAAE,OAAO,CAAC,oBAAoB,EAAE,WAAW,IAAI,SAAS;QACnE,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC;AACJ,CAAC,CAAC","sourcesContent":["\"use client\";\nimport React, { createContext, useContext } from \"react\";\nimport {\n InteractableMetadata,\n TamboThreadMessage,\n} from \"../model/generate-component-response\";\n\nconst TamboMessageContext = createContext<TamboThreadMessage | null>(null);\n\nexport interface TamboMessageProviderProps {\n children: React.ReactNode;\n message: TamboThreadMessage;\n /** Optional interactable metadata for components wrapped with withInteractable */\n interactableMetadata?: InteractableMetadata;\n}\n\n/**\n * Wraps all components, so that they can find what message they are in.\n * Also supports optional interactable metadata for components wrapped with withInteractable.\n * @param props - props for the TamboMessageProvider\n * @param props.children - The children to wrap\n * @param props.message - The message object\n * @param props.interactableMetadata - Optional interactable component metadata\n * @returns The wrapped component\n */\nexport const TamboMessageProvider: React.FC<TamboMessageProviderProps> = ({\n children,\n message,\n interactableMetadata,\n}) => {\n // Merge interactable metadata into message if provided\n const enhancedMessage: TamboThreadMessage = interactableMetadata\n ? { ...message, interactableMetadata }\n : message;\n\n // Use a unique key={...} to force a re-render when the message changes - this\n // make sure that if the rendered component is swapped into a tree (like if\n // you always show the last rendered component) then the state/etc is correct\n return (\n <TamboMessageContext.Provider value={enhancedMessage} key={message.id}>\n {children}\n </TamboMessageContext.Provider>\n );\n};\n\n/**\n * Wraps a component with a TamboMessageProvider - this allows the provider\n * to be used outside of a TSX file\n * @param children - The children to wrap\n * @param message - The message object\n * @param interactableMetadata - Optional interactable metadata\n * @returns The wrapped component\n */\nexport function wrapWithTamboMessageProvider(\n children: React.ReactNode,\n message: TamboThreadMessage,\n interactableMetadata?: InteractableMetadata,\n) {\n return (\n <TamboMessageProvider\n message={message}\n interactableMetadata={interactableMetadata}\n >\n {children}\n </TamboMessageProvider>\n );\n}\n\n/**\n * Hook used inside a component wrapped with TamboMessageProvider, to get\n * the current message.\n * @returns The current message that is used to render the component\n */\nexport const useTamboCurrentMessage = () => {\n const message = useContext(TamboMessageContext);\n if (!message) {\n throw new Error(\n \"useTamboCurrentMessage must be used within a TamboMessageProvider\",\n );\n }\n return message;\n};\n\n/**\n * Component info extracted from the current message and interactable context.\n * Provides a unified interface for accessing component metadata.\n */\nexport interface TamboCurrentComponent {\n /** Component name from the message */\n componentName?: string;\n /** Component props from the message */\n props?: Record<string, any>;\n /** Interactable ID (only present for components wrapped with withInteractable) */\n interactableId?: string;\n /** Description (only present for components wrapped with withInteractable) */\n description?: string;\n /** Thread ID from the message (only present when the component is part of a thread) */\n threadId?: string;\n}\n\n/**\n * Hook to access the current component information from the message context.\n * Provides a unified interface for both AI-generated and interactable components.\n *\n * **Use this hook when you need component metadata regardless of the context.**\n * @returns Component info including name, props, and interactable metadata if available, or null if used outside TamboMessageProvider\n * @example\n * ```tsx\n * function MyInlineEditor() {\n * const component = useTamboCurrentComponent();\n *\n * if (!component) return null; // Not inside a component\n *\n * return (\n * <div>\n * Editing: {component.componentName}\n * {component.interactableId && <span>ID: {component.interactableId}</span>}\n * </div>\n * );\n * }\n * ```\n */\nexport const useTamboCurrentComponent = (): TamboCurrentComponent | null => {\n const message = useContext(TamboMessageContext);\n\n if (!message) {\n return null;\n }\n\n return {\n componentName:\n message.interactableMetadata?.componentName ??\n message.component?.componentName ??\n undefined,\n props: message.component?.props as Record<string, any> | undefined,\n interactableId: message.interactableMetadata?.id ?? undefined,\n description: message.interactableMetadata?.description ?? undefined,\n threadId: message.threadId,\n };\n};\n"]}
|
|
@@ -147,6 +147,7 @@ describe("useTamboCurrentComponent", () => {
|
|
|
147
147
|
},
|
|
148
148
|
interactableId: undefined,
|
|
149
149
|
description: undefined,
|
|
150
|
+
threadId: "test-thread-id",
|
|
150
151
|
});
|
|
151
152
|
});
|
|
152
153
|
it("should return interactable metadata when provided", () => {
|
|
@@ -178,6 +179,7 @@ describe("useTamboCurrentComponent", () => {
|
|
|
178
179
|
},
|
|
179
180
|
interactableId: "interactable-456",
|
|
180
181
|
description: "Shows current weather",
|
|
182
|
+
threadId: "test-thread-id",
|
|
181
183
|
});
|
|
182
184
|
});
|
|
183
185
|
it("should prioritize interactableMetadata.componentName over message.component.componentName", () => {
|
|
@@ -216,6 +218,7 @@ describe("useTamboCurrentComponent", () => {
|
|
|
216
218
|
props: undefined,
|
|
217
219
|
interactableId: "interactable-only",
|
|
218
220
|
description: "Interactable only",
|
|
221
|
+
threadId: "test-thread-id",
|
|
219
222
|
});
|
|
220
223
|
});
|
|
221
224
|
it("should handle message with component but no interactable metadata", () => {
|
|
@@ -240,6 +243,7 @@ describe("useTamboCurrentComponent", () => {
|
|
|
240
243
|
},
|
|
241
244
|
interactableId: undefined,
|
|
242
245
|
description: undefined,
|
|
246
|
+
threadId: "test-thread-id",
|
|
243
247
|
});
|
|
244
248
|
});
|
|
245
249
|
it("should return undefined for all fields when message has neither component nor interactable metadata", () => {
|
|
@@ -253,6 +257,7 @@ describe("useTamboCurrentComponent", () => {
|
|
|
253
257
|
props: undefined,
|
|
254
258
|
interactableId: undefined,
|
|
255
259
|
description: undefined,
|
|
260
|
+
threadId: "test-thread-id",
|
|
256
261
|
});
|
|
257
262
|
});
|
|
258
263
|
});
|