@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
package/esm/schema/zod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,QAAQ,EACR,aAAa,EACb,OAAO,EACP,UAAU,EACX,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,YAAY,EACZ,QAAQ,EAET,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,QAAQ,EACR,aAAa,EACb,OAAO,EACP,UAAU,EACX,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,YAAY,EACZ,QAAQ,EAET,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,CAQjE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,YAAY,CAoB5E;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,iKAElD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,yEAWjD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,OAWpD;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,OAkBpD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,OAAO,CAE/D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,QAAQ,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,OAAO,GAAG,QAAQ,CAczE"}
|
package/esm/schema/zod.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { toJSONSchema as zod4ToJSONSchema, } from "zod/v4/core";
|
|
2
|
-
import { z } from "zodInternalAlias";
|
|
3
2
|
/**
|
|
4
3
|
* @returns True if the schema is a Zod 3 function schema
|
|
5
4
|
*/
|
|
6
5
|
export function isZod3FunctionSchema(schema) {
|
|
7
|
-
if (!
|
|
6
|
+
if (!isZodSchema(schema))
|
|
8
7
|
return false;
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
return ("_def" in schema &&
|
|
9
|
+
"typeName" in schema._def &&
|
|
10
|
+
schema._def.typeName === "ZodFunction");
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* @returns True if the schema is a Zod 4 function schema
|
|
@@ -92,38 +92,21 @@ export function handleZodSchemaToJson(schema) {
|
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
// Zod 3 schemas have _def with typeName and ~standard with vendor "zod"
|
|
96
|
-
// Use looseObject to allow any _def shape (different for each type)
|
|
97
|
-
const zod3SchemaType = z.object({
|
|
98
|
-
_def: z.looseObject({
|
|
99
|
-
typeName: z.string().optional(),
|
|
100
|
-
}),
|
|
101
|
-
"~standard": z.looseObject({
|
|
102
|
-
vendor: z.literal("zod"),
|
|
103
|
-
}),
|
|
104
|
-
});
|
|
105
95
|
/**
|
|
106
96
|
* Checks if a schema is probably a Zod 3 schema.
|
|
107
97
|
* @param schema - The schema to check
|
|
108
98
|
* @returns True if the schema looks like a Zod 3 schema
|
|
109
99
|
*/
|
|
110
100
|
export function isZod3Schema(schema) {
|
|
111
|
-
return
|
|
101
|
+
return isZodSchema(schema) && "_def" in schema;
|
|
112
102
|
}
|
|
113
|
-
const zod4SchemaType = z.object({
|
|
114
|
-
def: z.object(),
|
|
115
|
-
_zod: z.looseObject({
|
|
116
|
-
def: z.looseObject({}),
|
|
117
|
-
}),
|
|
118
|
-
"~standard": z.looseObject({}),
|
|
119
|
-
});
|
|
120
103
|
/**
|
|
121
104
|
* Detects if a schema is Zod 4 by checking for def.type property.
|
|
122
105
|
* Zod 4 uses `def.type` with lowercase type names like "object", "string".
|
|
123
106
|
* @returns True if the schema appears to be Zod 4 style
|
|
124
107
|
*/
|
|
125
108
|
export function isZod4Schema(schema) {
|
|
126
|
-
return
|
|
109
|
+
return isZodSchema(schema) && "_zod" in schema;
|
|
127
110
|
}
|
|
128
111
|
/**
|
|
129
112
|
* Checks if a schema is a Zod schema
|
|
@@ -131,6 +114,24 @@ export function isZod4Schema(schema) {
|
|
|
131
114
|
* @returns True if the schema is a Zod schema
|
|
132
115
|
*/
|
|
133
116
|
export function isZodSchema(schema) {
|
|
134
|
-
|
|
117
|
+
// schema must be { ~standard: { vendor: "zod" } }
|
|
118
|
+
if (typeof schema !== "object")
|
|
119
|
+
return false;
|
|
120
|
+
if (!schema)
|
|
121
|
+
return false;
|
|
122
|
+
if (!("~standard" in schema))
|
|
123
|
+
return false;
|
|
124
|
+
if (!schema["~standard"])
|
|
125
|
+
return false;
|
|
126
|
+
if (typeof schema["~standard"] !== "object")
|
|
127
|
+
return false;
|
|
128
|
+
if (!("vendor" in schema["~standard"]))
|
|
129
|
+
return false;
|
|
130
|
+
if (schema["~standard"].vendor !== "zod")
|
|
131
|
+
return false;
|
|
132
|
+
// Require at least one internal marker to reduce false positives
|
|
133
|
+
const looksLikeV3 = "_def" in schema;
|
|
134
|
+
const looksLikeV4 = "_zod" in schema || "def" in schema;
|
|
135
|
+
return looksLikeV3 || looksLikeV4;
|
|
135
136
|
}
|
|
136
137
|
//# sourceMappingURL=zod.js.map
|
package/esm/schema/zod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,YAAY,IAAI,gBAAgB,GACjC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/schema/zod.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,YAAY,IAAI,gBAAgB,GACjC,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAe;IAEf,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;I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AAC;IAC7C,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC1B,IAAI,CAAC,CAAC,WAAW,IAAI,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IAC3C,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,IAAI,OAAO,MAAM,CAAC,WAAW,CAAC,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC1D,IAAI,CAAC,CAAC,QAAQ,IAAI,MAAM,CAAC,WAAW,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACrD,IAAI,MAAM,CAAC,WAAW,CAAC,CAAC,MAAM,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAEvD,iEAAiE;IACjE,MAAM,WAAW,GAAG,MAAM,IAAI,MAAM,CAAC;IACrC,MAAM,WAAW,GAAG,MAAM,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,CAAC;IACxD,OAAO,WAAW,IAAI,WAAW,CAAC;AACpC,CAAC","sourcesContent":["import {\n ZodFunction,\n ZodTuple,\n ZodTupleItems,\n ZodType,\n ZodTypeAny,\n} from \"zod/v3\";\nimport {\n $ZodFunction,\n $ZodType,\n toJSONSchema as zod4ToJSONSchema,\n} from \"zod/v4/core\";\n\n/**\n * @returns True if the schema is a Zod 3 function schema\n */\nexport function isZod3FunctionSchema(\n schema: unknown,\n): schema is ZodFunction<ZodTuple<ZodTupleItems, any>, ZodTypeAny> {\n if (!isZodSchema(schema)) return false;\n\n return (\n \"_def\" in schema &&\n \"typeName\" in schema._def &&\n schema._def.typeName === \"ZodFunction\"\n );\n}\n\n/**\n * @returns True if the schema is a Zod 4 function schema\n */\nexport function isZod4FunctionSchema(schema: unknown): schema is $ZodFunction {\n if (!isZod4Schema(schema)) {\n return false;\n }\n\n // $ZodFunctions in zod 4.0 most certainly do have .def.type === \"function\"\n // but the type definitions do not reflect this because $ZodFunction does not\n // extend $ZodType. This is corrected in zod 4.1, but zod 3 does not include\n // the types for 4.1 yet (and might not ever).\n // See: https://github.com/colinhacks/zod/blob/463f03eb8183dcdcdf735b180f2bf40883e66220/packages/zod/src/v4/core/function.ts#L48\n if (\"def\" in schema && typeof schema.def !== \"object\" && schema.def) {\n if ((schema.def as { type: string })?.type === \"function\") {\n return true;\n }\n }\n\n // We're casting as string here because zod 4.0 types don't include \"function\"\n // literal in the union for `_zod.def.type`. The optional chaining is because\n // _zod does not exist on zod 4 objects from zod 3.\n return (schema._zod?.def?.type as string) === \"function\";\n}\n\n/**\n * Checks if a schema is a Zod function schema (Zod 3 or Zod 4).\n * @param schema - The schema to check\n * @returns True if the schema is a Zod function schema\n */\nexport function isZodFunctionSchema(schema: unknown) {\n return isZod3FunctionSchema(schema) || isZod4FunctionSchema(schema);\n}\n\n/**\n * Extracts the args schema from a Zod function schema.\n * @param schema - The Zod function schema\n * @returns The args schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionArgs(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.args;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4.0\n return schema?.def?.input ?? schema._zod?.def?.input;\n }\n\n throw new Error(\"Unable to determine parameters from zod function schema\");\n}\n\n/**\n * Extracts the return schema from a Zod 3 or Zod 4 function schema.\n * @param schema - The Zod function schema\n * @returns The return schema, or undefined if not a Zod function schema\n */\nexport function getZodFunctionReturns(schema: unknown) {\n if (isZod3FunctionSchema(schema)) {\n return schema._def.returns;\n }\n\n if (isZod4FunctionSchema(schema)) {\n // @ts-expect-error -- Error in Zod types for v3 vs v4\n return schema._zod.def.output;\n }\n\n throw new Error(\"Unable to determine return type from zod function schema\");\n}\n\n/**\n * Handles conversion of Zod schemas to JSON Schema.\n * Supports both Zod 3 (via zod-to-json-schema) and Zod 4 (native).\n * @param schema - The Zod schema to convert\n * @returns The JSON Schema representation\n */\nexport function handleZodSchemaToJson(schema: unknown) {\n // If Zod4 schema detected, use the toJSONSchema function from \"zod/v4/core\"\n if (isZod4Schema(schema)) return zod4ToJSONSchema(schema);\n\n try {\n // Dynamic require for optional peer dependency\n // eslint-disable-next-line @typescript-eslint/no-require-imports -- need require because zod-to-json-schema may be missing\n const { zodToJsonSchema } = require(\"zod-to-json-schema\");\n return zodToJsonSchema(schema);\n } catch (error) {\n throw new Error(\n \"Zod 3 requires 'zod-to-json-schema' package for JSON Schema conversion. \" +\n \"Install it with: npm install zod-to-json-schema\",\n {\n cause: error,\n },\n );\n }\n}\n\n/**\n * Checks if a schema is probably a Zod 3 schema.\n * @param schema - The schema to check\n * @returns True if the schema looks like a Zod 3 schema\n */\nexport function isZod3Schema(schema: unknown): schema is ZodType {\n return isZodSchema(schema) && \"_def\" in schema;\n}\n\n/**\n * Detects if a schema is Zod 4 by checking for def.type property.\n * Zod 4 uses `def.type` with lowercase type names like \"object\", \"string\".\n * @returns True if the schema appears to be Zod 4 style\n */\nexport function isZod4Schema(schema: unknown): schema is $ZodType {\n return isZodSchema(schema) && \"_zod\" in schema;\n}\n\n/**\n * Checks if a schema is a Zod schema\n * @param schema - The schema to check\n * @returns True if the schema is a Zod schema\n */\nexport function isZodSchema(schema: unknown): schema is ZodType | $ZodType {\n // schema must be { ~standard: { vendor: \"zod\" } }\n if (typeof schema !== \"object\") return false;\n if (!schema) return false;\n if (!(\"~standard\" in schema)) return false;\n if (!schema[\"~standard\"]) return false;\n if (typeof schema[\"~standard\"] !== \"object\") return false;\n if (!(\"vendor\" in schema[\"~standard\"])) return false;\n if (schema[\"~standard\"].vendor !== \"zod\") return false;\n\n // Require at least one internal marker to reduce false positives\n const looksLikeV3 = \"_def\" in schema;\n const looksLikeV4 = \"_zod\" in schema || \"def\" in schema;\n return looksLikeV3 || looksLikeV4;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry-validators.d.ts","sourceRoot":"","sources":["../../src/util/registry-validators.ts"],"names":[],"mappings":"
|
|
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":"
|
|
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,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1B,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAEnC,0DAA0D;IAC1D,IAAI,CAAC,WAAW,IAAI,CAAC,eAAe,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACb,aAAa,IAAI,wEAAwE,CAC1F,CAAC;IACJ,CAAC;IAED,sDAAsD;IACtD,IAAI,WAAW,IAAI,eAAe,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACb,aAAa,IAAI,0GAA0G,CAC5H,CAAC;IACJ,CAAC;IAED,8DAA8D;IAC9D,IAAI,WAAW,EAAE,CAAC;QAChB,oBAAoB,CAAC,WAAW,EAAE,6BAA6B,IAAI,GAAG,CAAC,CAAC;IAC1E,CAAC;IAED,kDAAkD;IAClD,MAAM,KAAK,GAAG,kBAAkB,CAAC,eAAe,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;IAErE,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACrC,aAAqB,EACrB,QAAgB,EAChB,eAAwB,EACxB,UAAmB;IAEnB,oCAAoC;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 { 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":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AC,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,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,IAA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IAEH,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,MAAM,CAAC,GAAG,EAAE,CACV,uBAAuB,CAAC,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,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"]}
|
package/esm/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,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;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GACjC,mBAAmB,iBAAiB,EACpC,cAAc,iBAAiB,EAC/B,kBAAkB,qBAAqB,KACtC,OAAO,CAAC,kBAAkB,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
|
|
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;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GACjC,mBAAmB,iBAAiB,EACpC,cAAc,iBAAiB,EAC/B,kBAAkB,qBAAqB,KACtC,OAAO,CAAC,kBAAkB,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/esm/util/registry.js
CHANGED
|
@@ -109,11 +109,7 @@ export const mapTamboToolToContextTool = (tool) => {
|
|
|
109
109
|
* import { z } from "zod/v4";
|
|
110
110
|
*
|
|
111
111
|
* const myTool = defineTamboTool({
|
|
112
|
-
*
|
|
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
|
package/esm/util/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/util/registry.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,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CACtC,aAAqB,EACrB,iBAAoC,EACf,EAAE;IACvB,MAAM,cAAc,GAAG,iBAAiB,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;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"]}
|