@tambo-ai/client 0.0.1
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/LICENSE +21 -0
- package/README.md +100 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/elicitation.d.ts +59 -0
- package/dist/mcp/elicitation.d.ts.map +1 -0
- package/dist/mcp/elicitation.js +27 -0
- package/dist/mcp/elicitation.js.map +1 -0
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +14 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/mcp-client.d.ts +185 -0
- package/dist/mcp/mcp-client.d.ts.map +1 -0
- package/dist/mcp/mcp-client.js +219 -0
- package/dist/mcp/mcp-client.js.map +1 -0
- package/dist/mcp/mcp-constants.d.ts +19 -0
- package/dist/mcp/mcp-constants.d.ts.map +1 -0
- package/dist/mcp/mcp-constants.js +21 -0
- package/dist/mcp/mcp-constants.js.map +1 -0
- package/dist/model/component-metadata.d.ts +390 -0
- package/dist/model/component-metadata.d.ts.map +1 -0
- package/dist/model/component-metadata.js +3 -0
- package/dist/model/component-metadata.js.map +1 -0
- package/dist/model/mcp-server-info.d.ts +72 -0
- package/dist/model/mcp-server-info.d.ts.map +1 -0
- package/dist/model/mcp-server-info.js +29 -0
- package/dist/model/mcp-server-info.js.map +1 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +15 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/json-schema.d.ts +42 -0
- package/dist/schema/json-schema.d.ts.map +1 -0
- package/dist/schema/json-schema.js +114 -0
- package/dist/schema/json-schema.js.map +1 -0
- package/dist/schema/schema.d.ts +49 -0
- package/dist/schema/schema.d.ts.map +1 -0
- package/dist/schema/schema.js +129 -0
- package/dist/schema/schema.js.map +1 -0
- package/dist/schema/standard-schema.d.ts +22 -0
- package/dist/schema/standard-schema.d.ts.map +1 -0
- package/dist/schema/standard-schema.js +42 -0
- package/dist/schema/standard-schema.js.map +1 -0
- package/dist/schema/validate.d.ts +14 -0
- package/dist/schema/validate.d.ts.map +1 -0
- package/dist/schema/validate.js +148 -0
- package/dist/schema/validate.js.map +1 -0
- package/dist/tambo-client.d.ts +292 -0
- package/dist/tambo-client.d.ts.map +1 -0
- package/dist/tambo-client.js +508 -0
- package/dist/tambo-client.js.map +1 -0
- package/dist/tambo-stream.d.ts +112 -0
- package/dist/tambo-stream.d.ts.map +1 -0
- package/dist/tambo-stream.js +345 -0
- package/dist/tambo-stream.js.map +1 -0
- package/dist/types/auth.d.ts +24 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +3 -0
- package/dist/types/auth.js.map +1 -0
- package/dist/types/event.d.ts +89 -0
- package/dist/types/event.d.ts.map +1 -0
- package/dist/types/event.js +57 -0
- package/dist/types/event.js.map +1 -0
- package/dist/types/message.d.ts +122 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/message.js +10 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/thread.d.ts +58 -0
- package/dist/types/thread.d.ts.map +1 -0
- package/dist/types/thread.js +9 -0
- package/dist/types/thread.js.map +1 -0
- package/dist/types/tool-choice.d.ts +8 -0
- package/dist/types/tool-choice.d.ts.map +1 -0
- package/dist/types/tool-choice.js +3 -0
- package/dist/types/tool-choice.js.map +1 -0
- package/dist/utils/event-accumulator.d.ts +165 -0
- package/dist/utils/event-accumulator.d.ts.map +1 -0
- package/dist/utils/event-accumulator.js +1278 -0
- package/dist/utils/event-accumulator.js.map +1 -0
- package/dist/utils/json-patch.d.ts +18 -0
- package/dist/utils/json-patch.d.ts.map +1 -0
- package/dist/utils/json-patch.js +35 -0
- package/dist/utils/json-patch.js.map +1 -0
- package/dist/utils/keyed-throttle.d.ts +42 -0
- package/dist/utils/keyed-throttle.d.ts.map +1 -0
- package/dist/utils/keyed-throttle.js +86 -0
- package/dist/utils/keyed-throttle.js.map +1 -0
- package/dist/utils/registry-conversion.d.ts +53 -0
- package/dist/utils/registry-conversion.d.ts.map +1 -0
- package/dist/utils/registry-conversion.js +115 -0
- package/dist/utils/registry-conversion.js.map +1 -0
- package/dist/utils/send-message.d.ts +140 -0
- package/dist/utils/send-message.d.ts.map +1 -0
- package/dist/utils/send-message.js +183 -0
- package/dist/utils/send-message.js.map +1 -0
- package/dist/utils/stream-handler.d.ts +45 -0
- package/dist/utils/stream-handler.d.ts.map +1 -0
- package/dist/utils/stream-handler.js +47 -0
- package/dist/utils/stream-handler.js.map +1 -0
- package/dist/utils/thread-utils.d.ts +16 -0
- package/dist/utils/thread-utils.d.ts.map +1 -0
- package/dist/utils/thread-utils.js +34 -0
- package/dist/utils/thread-utils.js.map +1 -0
- package/dist/utils/tool-call-tracker.d.ts +74 -0
- package/dist/utils/tool-call-tracker.d.ts.map +1 -0
- package/dist/utils/tool-call-tracker.js +181 -0
- package/dist/utils/tool-call-tracker.js.map +1 -0
- package/dist/utils/tool-executor.d.ts +67 -0
- package/dist/utils/tool-executor.d.ts.map +1 -0
- package/dist/utils/tool-executor.js +160 -0
- package/dist/utils/tool-executor.js.map +1 -0
- package/dist/utils/unstrictify.d.ts +32 -0
- package/dist/utils/unstrictify.d.ts.map +1 -0
- package/dist/utils/unstrictify.js +160 -0
- package/dist/utils/unstrictify.js.map +1 -0
- package/esm/index.d.ts +43 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +78 -0
- package/esm/index.js.map +1 -0
- package/esm/mcp/elicitation.d.ts +59 -0
- package/esm/mcp/elicitation.d.ts.map +1 -0
- package/esm/mcp/elicitation.js +27 -0
- package/esm/mcp/elicitation.js.map +1 -0
- package/esm/mcp/index.d.ts +6 -0
- package/esm/mcp/index.d.ts.map +1 -0
- package/esm/mcp/index.js +14 -0
- package/esm/mcp/index.js.map +1 -0
- package/esm/mcp/mcp-client.d.ts +185 -0
- package/esm/mcp/mcp-client.d.ts.map +1 -0
- package/esm/mcp/mcp-client.js +219 -0
- package/esm/mcp/mcp-client.js.map +1 -0
- package/esm/mcp/mcp-constants.d.ts +19 -0
- package/esm/mcp/mcp-constants.d.ts.map +1 -0
- package/esm/mcp/mcp-constants.js +21 -0
- package/esm/mcp/mcp-constants.js.map +1 -0
- package/esm/model/component-metadata.d.ts +390 -0
- package/esm/model/component-metadata.d.ts.map +1 -0
- package/esm/model/component-metadata.js +3 -0
- package/esm/model/component-metadata.js.map +1 -0
- package/esm/model/mcp-server-info.d.ts +72 -0
- package/esm/model/mcp-server-info.d.ts.map +1 -0
- package/esm/model/mcp-server-info.js +29 -0
- package/esm/model/mcp-server-info.js.map +1 -0
- package/esm/schema/index.d.ts +5 -0
- package/esm/schema/index.d.ts.map +1 -0
- package/esm/schema/index.js +15 -0
- package/esm/schema/index.js.map +1 -0
- package/esm/schema/json-schema.d.ts +42 -0
- package/esm/schema/json-schema.d.ts.map +1 -0
- package/esm/schema/json-schema.js +114 -0
- package/esm/schema/json-schema.js.map +1 -0
- package/esm/schema/schema.d.ts +49 -0
- package/esm/schema/schema.d.ts.map +1 -0
- package/esm/schema/schema.js +129 -0
- package/esm/schema/schema.js.map +1 -0
- package/esm/schema/standard-schema.d.ts +22 -0
- package/esm/schema/standard-schema.d.ts.map +1 -0
- package/esm/schema/standard-schema.js +42 -0
- package/esm/schema/standard-schema.js.map +1 -0
- package/esm/schema/validate.d.ts +14 -0
- package/esm/schema/validate.d.ts.map +1 -0
- package/esm/schema/validate.js +148 -0
- package/esm/schema/validate.js.map +1 -0
- package/esm/tambo-client.d.ts +292 -0
- package/esm/tambo-client.d.ts.map +1 -0
- package/esm/tambo-client.js +508 -0
- package/esm/tambo-client.js.map +1 -0
- package/esm/tambo-stream.d.ts +112 -0
- package/esm/tambo-stream.d.ts.map +1 -0
- package/esm/tambo-stream.js +345 -0
- package/esm/tambo-stream.js.map +1 -0
- package/esm/types/auth.d.ts +24 -0
- package/esm/types/auth.d.ts.map +1 -0
- package/esm/types/auth.js +3 -0
- package/esm/types/auth.js.map +1 -0
- package/esm/types/event.d.ts +89 -0
- package/esm/types/event.d.ts.map +1 -0
- package/esm/types/event.js +57 -0
- package/esm/types/event.js.map +1 -0
- package/esm/types/message.d.ts +122 -0
- package/esm/types/message.d.ts.map +1 -0
- package/esm/types/message.js +10 -0
- package/esm/types/message.js.map +1 -0
- package/esm/types/thread.d.ts +58 -0
- package/esm/types/thread.d.ts.map +1 -0
- package/esm/types/thread.js +9 -0
- package/esm/types/thread.js.map +1 -0
- package/esm/types/tool-choice.d.ts +8 -0
- package/esm/types/tool-choice.d.ts.map +1 -0
- package/esm/types/tool-choice.js +3 -0
- package/esm/types/tool-choice.js.map +1 -0
- package/esm/utils/event-accumulator.d.ts +165 -0
- package/esm/utils/event-accumulator.d.ts.map +1 -0
- package/esm/utils/event-accumulator.js +1278 -0
- package/esm/utils/event-accumulator.js.map +1 -0
- package/esm/utils/json-patch.d.ts +18 -0
- package/esm/utils/json-patch.d.ts.map +1 -0
- package/esm/utils/json-patch.js +35 -0
- package/esm/utils/json-patch.js.map +1 -0
- package/esm/utils/keyed-throttle.d.ts +42 -0
- package/esm/utils/keyed-throttle.d.ts.map +1 -0
- package/esm/utils/keyed-throttle.js +86 -0
- package/esm/utils/keyed-throttle.js.map +1 -0
- package/esm/utils/registry-conversion.d.ts +53 -0
- package/esm/utils/registry-conversion.d.ts.map +1 -0
- package/esm/utils/registry-conversion.js +115 -0
- package/esm/utils/registry-conversion.js.map +1 -0
- package/esm/utils/send-message.d.ts +140 -0
- package/esm/utils/send-message.d.ts.map +1 -0
- package/esm/utils/send-message.js +183 -0
- package/esm/utils/send-message.js.map +1 -0
- package/esm/utils/stream-handler.d.ts +45 -0
- package/esm/utils/stream-handler.d.ts.map +1 -0
- package/esm/utils/stream-handler.js +47 -0
- package/esm/utils/stream-handler.js.map +1 -0
- package/esm/utils/thread-utils.d.ts +16 -0
- package/esm/utils/thread-utils.d.ts.map +1 -0
- package/esm/utils/thread-utils.js +34 -0
- package/esm/utils/thread-utils.js.map +1 -0
- package/esm/utils/tool-call-tracker.d.ts +74 -0
- package/esm/utils/tool-call-tracker.d.ts.map +1 -0
- package/esm/utils/tool-call-tracker.js +181 -0
- package/esm/utils/tool-call-tracker.js.map +1 -0
- package/esm/utils/tool-executor.d.ts +67 -0
- package/esm/utils/tool-executor.d.ts.map +1 -0
- package/esm/utils/tool-executor.js +160 -0
- package/esm/utils/tool-executor.js.map +1 -0
- package/esm/utils/unstrictify.d.ts +32 -0
- package/esm/utils/unstrictify.d.ts.map +1 -0
- package/esm/utils/unstrictify.js +160 -0
- package/esm/utils/unstrictify.js.map +1 -0
- package/package.json +90 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.looksLikeJSONSchema = looksLikeJSONSchema;
|
|
4
|
+
exports.isJsonSchemaTuple = isJsonSchemaTuple;
|
|
5
|
+
exports.getJsonSchemaTupleItems = getJsonSchemaTupleItems;
|
|
6
|
+
exports.makeJsonSchemaPartial = makeJsonSchemaPartial;
|
|
7
|
+
const v4_1 = require("zod/v4");
|
|
8
|
+
const jsonSchemaType = v4_1.z.union([
|
|
9
|
+
v4_1.z.literal("object"),
|
|
10
|
+
v4_1.z.literal("array"),
|
|
11
|
+
v4_1.z.literal("string"),
|
|
12
|
+
v4_1.z.literal("number"),
|
|
13
|
+
v4_1.z.literal("integer"),
|
|
14
|
+
v4_1.z.literal("boolean"),
|
|
15
|
+
v4_1.z.literal("null"),
|
|
16
|
+
v4_1.z.array(v4_1.z.union([
|
|
17
|
+
v4_1.z.literal("object"),
|
|
18
|
+
v4_1.z.literal("array"),
|
|
19
|
+
v4_1.z.literal("string"),
|
|
20
|
+
v4_1.z.literal("number"),
|
|
21
|
+
v4_1.z.literal("integer"),
|
|
22
|
+
v4_1.z.literal("boolean"),
|
|
23
|
+
v4_1.z.literal("null"),
|
|
24
|
+
])),
|
|
25
|
+
]);
|
|
26
|
+
const jsonSchemaTopLevel = v4_1.z
|
|
27
|
+
.looseObject({
|
|
28
|
+
type: jsonSchemaType.optional(),
|
|
29
|
+
properties: v4_1.z.record(v4_1.z.string(), v4_1.z.unknown()).optional(),
|
|
30
|
+
items: v4_1.z.union([v4_1.z.array(v4_1.z.unknown()), v4_1.z.unknown()]).optional(),
|
|
31
|
+
required: v4_1.z.array(v4_1.z.string()).optional(),
|
|
32
|
+
additionalProperties: v4_1.z.union([v4_1.z.boolean(), v4_1.z.unknown()]).optional(),
|
|
33
|
+
enum: v4_1.z.array(v4_1.z.unknown()).optional(),
|
|
34
|
+
const: v4_1.z.unknown().optional(),
|
|
35
|
+
$ref: v4_1.z.string().optional(),
|
|
36
|
+
$id: v4_1.z.string().optional(),
|
|
37
|
+
$schema: v4_1.z.string().optional(),
|
|
38
|
+
title: v4_1.z.string().optional(),
|
|
39
|
+
description: v4_1.z.string().optional(),
|
|
40
|
+
})
|
|
41
|
+
.refine((value) => {
|
|
42
|
+
return (value.type !== undefined ||
|
|
43
|
+
value.properties !== undefined ||
|
|
44
|
+
value.items !== undefined ||
|
|
45
|
+
value.enum !== undefined ||
|
|
46
|
+
value.const !== undefined ||
|
|
47
|
+
value.$ref !== undefined);
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Basic heuristic to check if an object looks like a JSON Schema at the top level.
|
|
51
|
+
*
|
|
52
|
+
* This uses a Zod schema to verify only top-level keys (type, properties, items,
|
|
53
|
+
* etc.). It intentionally does not perform full JSON Schema validation; a more
|
|
54
|
+
* thorough check should be done server-side.
|
|
55
|
+
* @param obj - The value to check
|
|
56
|
+
* @returns True if the value appears to be a JSON Schema
|
|
57
|
+
*/
|
|
58
|
+
function looksLikeJSONSchema(obj) {
|
|
59
|
+
if (obj === null || typeof obj !== "object") {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return jsonSchemaTopLevel.safeParse(obj).success;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Checks if a JSON Schema represents a tuple (array with positional items).
|
|
66
|
+
* Supports both draft-07 (items as array) and draft 2020-12 (prefixItems).
|
|
67
|
+
* @param schema - The JSON Schema to check
|
|
68
|
+
* @returns True if the schema represents a tuple
|
|
69
|
+
*/
|
|
70
|
+
function isJsonSchemaTuple(schema) {
|
|
71
|
+
if (schema.type !== "array") {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
// Draft 2020-12: prefixItems array
|
|
75
|
+
if (schema.prefixItems && Array.isArray(schema.prefixItems)) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
// Draft-07: items as array (not object)
|
|
79
|
+
if (Array.isArray(schema.items)) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Gets the tuple items from a JSON Schema.
|
|
86
|
+
* Supports both draft-07 (items as array) and draft 2020-12 (prefixItems).
|
|
87
|
+
* @param schema - The JSON Schema tuple
|
|
88
|
+
* @returns Array of item schemas, or undefined if not a tuple
|
|
89
|
+
*/
|
|
90
|
+
function getJsonSchemaTupleItems(schema) {
|
|
91
|
+
if (schema.type !== "array") {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
// Draft 2020-12: prefixItems array
|
|
95
|
+
if (schema.prefixItems && Array.isArray(schema.prefixItems)) {
|
|
96
|
+
return schema.prefixItems;
|
|
97
|
+
}
|
|
98
|
+
// Draft-07: items as array
|
|
99
|
+
if (Array.isArray(schema.items)) {
|
|
100
|
+
return schema.items;
|
|
101
|
+
}
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Creates a partial version of a JSON Schema by removing required constraints.
|
|
106
|
+
* This allows LLM to provide only the properties it wants to update.
|
|
107
|
+
* @param schema - The JSON Schema to make partial
|
|
108
|
+
* @returns A new JSON Schema with the required constraint removed
|
|
109
|
+
*/
|
|
110
|
+
function makeJsonSchemaPartial(schema) {
|
|
111
|
+
const { required: _required, ...rest } = schema;
|
|
112
|
+
return rest;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=json-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../../src/schema/json-schema.ts"],"names":[],"mappings":";;AA2DA,kDAMC;AAgBD,8CAkBC;AAQD,0DAkBC;AAQD,sDAGC;AAvID,+BAA2B;AAE3B,MAAM,cAAc,GAAG,MAAC,CAAC,KAAK,CAAC;IAC7B,MAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IACnB,MAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IAClB,MAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IACnB,MAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IACnB,MAAC,CAAC,OAAO,CAAC,SAAS,CAAC;IACpB,MAAC,CAAC,OAAO,CAAC,SAAS,CAAC;IACpB,MAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACjB,MAAC,CAAC,KAAK,CACL,MAAC,CAAC,KAAK,CAAC;QACN,MAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;QACnB,MAAC,CAAC,OAAO,CAAC,OAAO,CAAC;QAClB,MAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;QACnB,MAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;QACnB,MAAC,CAAC,OAAO,CAAC,SAAS,CAAC;QACpB,MAAC,CAAC,OAAO,CAAC,SAAS,CAAC;QACpB,MAAC,CAAC,OAAO,CAAC,MAAM,CAAC;KAClB,CAAC,CACH;CACF,CAAC,CAAC;AAEH,MAAM,kBAAkB,GAAG,MAAC;KACzB,WAAW,CAAC;IACX,IAAI,EAAE,cAAc,CAAC,QAAQ,EAAE;IAC/B,UAAU,EAAE,MAAC,CAAC,MAAM,CAAC,MAAC,CAAC,MAAM,E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AAQ,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IAChD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { JSONSchema7 } from \"json-schema\";\nimport { z } from \"zod/v4\";\n\nconst jsonSchemaType = z.union([\n z.literal(\"object\"),\n z.literal(\"array\"),\n z.literal(\"string\"),\n z.literal(\"number\"),\n z.literal(\"integer\"),\n z.literal(\"boolean\"),\n z.literal(\"null\"),\n z.array(\n z.union([\n z.literal(\"object\"),\n z.literal(\"array\"),\n z.literal(\"string\"),\n z.literal(\"number\"),\n z.literal(\"integer\"),\n z.literal(\"boolean\"),\n z.literal(\"null\"),\n ]),\n ),\n]);\n\nconst jsonSchemaTopLevel = z\n .looseObject({\n type: jsonSchemaType.optional(),\n properties: z.record(z.string(), z.unknown()).optional(),\n items: z.union([z.array(z.unknown()), z.unknown()]).optional(),\n required: z.array(z.string()).optional(),\n additionalProperties: z.union([z.boolean(), z.unknown()]).optional(),\n enum: z.array(z.unknown()).optional(),\n const: z.unknown().optional(),\n $ref: z.string().optional(),\n $id: z.string().optional(),\n $schema: z.string().optional(),\n title: z.string().optional(),\n description: z.string().optional(),\n })\n .refine((value) => {\n return (\n value.type !== undefined ||\n value.properties !== undefined ||\n value.items !== undefined ||\n value.enum !== undefined ||\n value.const !== undefined ||\n value.$ref !== undefined\n );\n });\n\n/**\n * Basic heuristic to check if an object looks like a JSON Schema at the top level.\n *\n * This uses a Zod schema to verify only top-level keys (type, properties, items,\n * etc.). It intentionally does not perform full JSON Schema validation; a more\n * thorough check should be done server-side.\n * @param obj - The value to check\n * @returns True if the value appears to be a JSON Schema\n */\nexport function looksLikeJSONSchema(obj: unknown): obj is JSONSchema7 {\n if (obj === null || typeof obj !== \"object\") {\n return false;\n }\n\n return jsonSchemaTopLevel.safeParse(obj).success;\n}\n\n/**\n * Extended JSON Schema type that includes draft 2020-12 features like prefixItems.\n * The json-schema package types are from draft-07 and don't include prefixItems.\n */\nexport type JSONSchema7Extended = JSONSchema7 & {\n prefixItems?: JSONSchema7[];\n};\n\n/**\n * Checks if a JSON Schema represents a tuple (array with positional items).\n * Supports both draft-07 (items as array) and draft 2020-12 (prefixItems).\n * @param schema - The JSON Schema to check\n * @returns True if the schema represents a tuple\n */\nexport function isJsonSchemaTuple(\n schema: JSONSchema7Extended,\n): schema is JSONSchema7Extended & { type: \"array\" } {\n if (schema.type !== \"array\") {\n return false;\n }\n\n // Draft 2020-12: prefixItems array\n if (schema.prefixItems && Array.isArray(schema.prefixItems)) {\n return true;\n }\n\n // Draft-07: items as array (not object)\n if (Array.isArray(schema.items)) {\n return true;\n }\n\n return false;\n}\n\n/**\n * Gets the tuple items from a JSON Schema.\n * Supports both draft-07 (items as array) and draft 2020-12 (prefixItems).\n * @param schema - The JSON Schema tuple\n * @returns Array of item schemas, or undefined if not a tuple\n */\nexport function getJsonSchemaTupleItems(\n schema: JSONSchema7Extended,\n): JSONSchema7[] | undefined {\n if (schema.type !== \"array\") {\n return undefined;\n }\n\n // Draft 2020-12: prefixItems array\n if (schema.prefixItems && Array.isArray(schema.prefixItems)) {\n return schema.prefixItems;\n }\n\n // Draft-07: items as array\n if (Array.isArray(schema.items)) {\n return schema.items as JSONSchema7[];\n }\n\n return undefined;\n}\n\n/**\n * Creates a partial version of a JSON Schema by removing required constraints.\n * This allows LLM to provide only the properties it wants to update.\n * @param schema - The JSON Schema to make partial\n * @returns A new JSON Schema with the required constraint removed\n */\nexport function makeJsonSchemaPartial(schema: JSONSchema7): JSONSchema7 {\n const { required: _required, ...rest } = schema;\n return rest;\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema utilities for working with Standard Schema and JSON Schema.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a unified interface for handling different schema types
|
|
5
|
+
* used in Tambo components and tools. It uses Standard Schema (https://standardschema.dev/)
|
|
6
|
+
* as the primary interface, which is implemented by Zod 3.24+ and other validation libraries.
|
|
7
|
+
*
|
|
8
|
+
* JSON Schema conversion is handled by `@standard-community/standard-json`.
|
|
9
|
+
* @module schema
|
|
10
|
+
*/
|
|
11
|
+
import type { JSONSchema7 } from "json-schema";
|
|
12
|
+
import { ParameterSpec, SupportedSchema, TamboTool } from "../model/component-metadata.js";
|
|
13
|
+
/**
|
|
14
|
+
* Converts a schema (Standard Schema or JSON Schema) to a JSON Schema object.
|
|
15
|
+
*
|
|
16
|
+
* If the schema is already a JSON Schema, it is returned as-is.
|
|
17
|
+
* For Standard Schema validators (Zod 3.24+, etc.), uses
|
|
18
|
+
* `@standard-community/standard-json` for conversion.
|
|
19
|
+
* @param schema - The schema to convert
|
|
20
|
+
* @returns The JSON Schema representation
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { z } from "zod/v4";
|
|
24
|
+
*
|
|
25
|
+
* // Convert a Zod schema
|
|
26
|
+
* const zodSchema = z.object({ name: z.string() });
|
|
27
|
+
* const jsonSchema = schemaToJsonSchema(zodSchema);
|
|
28
|
+
*
|
|
29
|
+
* // Pass through a JSON Schema
|
|
30
|
+
* const existingJsonSchema = { type: "object", properties: { name: { type: "string" } } };
|
|
31
|
+
* schemaToJsonSchema(existingJsonSchema); // returns the same object
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function schemaToJsonSchema(schema: SupportedSchema): JSONSchema7;
|
|
35
|
+
/**
|
|
36
|
+
* Safely converts a schema to JSON Schema, returning undefined for invalid inputs.
|
|
37
|
+
* @param schema - The schema to convert (may be undefined)
|
|
38
|
+
* @param onError - Optional callback invoked on conversion error
|
|
39
|
+
* @returns The JSON Schema representation, or undefined if conversion fails
|
|
40
|
+
*/
|
|
41
|
+
export declare function safeSchemaToJsonSchema(schema: SupportedSchema | undefined | null, onError?: (error: unknown) => void): JSONSchema7 | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Extracts parameter specifications from a tool's inputSchema.
|
|
44
|
+
* @param tool - The tool containing the schema
|
|
45
|
+
* @returns An array of parameter specifications
|
|
46
|
+
*/
|
|
47
|
+
export declare function getParametersFromToolSchema(tool: TamboTool): ParameterSpec[];
|
|
48
|
+
export type { SupportedSchema };
|
|
49
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/schema/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,EACL,aAAa,EACb,eAAe,EACf,SAAS,EACV,MAAM,6BAA6B,CAAC;AAuBrC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,CAOvE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,eAAe,GAAG,SAAS,GAAG,IAAI,EAC1C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GACjC,WAAW,GAAG,SAAS,CAYzB;AAoCD;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,SAAS,GAAG,aAAa,EAAE,CAe5E;AAED,YAAY,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Schema utilities for working with Standard Schema and JSON Schema.
|
|
4
|
+
*
|
|
5
|
+
* This module provides a unified interface for handling different schema types
|
|
6
|
+
* used in Tambo components and tools. It uses Standard Schema (https://standardschema.dev/)
|
|
7
|
+
* as the primary interface, which is implemented by Zod 3.24+ and other validation libraries.
|
|
8
|
+
*
|
|
9
|
+
* JSON Schema conversion is handled by `@standard-community/standard-json`.
|
|
10
|
+
* @module schema
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.schemaToJsonSchema = schemaToJsonSchema;
|
|
14
|
+
exports.safeSchemaToJsonSchema = safeSchemaToJsonSchema;
|
|
15
|
+
exports.getParametersFromToolSchema = getParametersFromToolSchema;
|
|
16
|
+
const standard_json_1 = require("@standard-community/standard-json");
|
|
17
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
18
|
+
const core_1 = require("zod/v4/core");
|
|
19
|
+
const json_schema_1 = require("./json-schema.js");
|
|
20
|
+
const standard_schema_1 = require("./standard-schema.js");
|
|
21
|
+
/**
|
|
22
|
+
* Register the zod vendor handler for synchronous JSON Schema conversion.
|
|
23
|
+
* This uses Zod 4's native toJSONSchema for Zod 4.x schemas and zod-to-json-schema for Zod 3.x.
|
|
24
|
+
*/
|
|
25
|
+
(0, standard_json_1.loadVendor)("zod", (schema) => {
|
|
26
|
+
// Check if this is a Zod 4 schema (has _zod property)
|
|
27
|
+
if (schema && typeof schema === "object" && "_zod" in schema) {
|
|
28
|
+
// Use Zod 4's native toJSONSchema from zod/v4/core
|
|
29
|
+
// Cast through unknown since the Zod 4 internal types don't match our detection pattern
|
|
30
|
+
return (0, core_1.toJSONSchema)(schema);
|
|
31
|
+
}
|
|
32
|
+
// Fall back to zod-to-json-schema for Zod 3.x
|
|
33
|
+
return (0, zod_to_json_schema_1.zodToJsonSchema)(schema);
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Converts a schema (Standard Schema or JSON Schema) to a JSON Schema object.
|
|
37
|
+
*
|
|
38
|
+
* If the schema is already a JSON Schema, it is returned as-is.
|
|
39
|
+
* For Standard Schema validators (Zod 3.24+, etc.), uses
|
|
40
|
+
* `@standard-community/standard-json` for conversion.
|
|
41
|
+
* @param schema - The schema to convert
|
|
42
|
+
* @returns The JSON Schema representation
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { z } from "zod/v4";
|
|
46
|
+
*
|
|
47
|
+
* // Convert a Zod schema
|
|
48
|
+
* const zodSchema = z.object({ name: z.string() });
|
|
49
|
+
* const jsonSchema = schemaToJsonSchema(zodSchema);
|
|
50
|
+
*
|
|
51
|
+
* // Pass through a JSON Schema
|
|
52
|
+
* const existingJsonSchema = { type: "object", properties: { name: { type: "string" } } };
|
|
53
|
+
* schemaToJsonSchema(existingJsonSchema); // returns the same object
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
function schemaToJsonSchema(schema) {
|
|
57
|
+
// Already a JSON Schema - return as-is
|
|
58
|
+
if (!(0, standard_schema_1.isStandardSchema)(schema)) {
|
|
59
|
+
return schema;
|
|
60
|
+
}
|
|
61
|
+
return standard_json_1.toJsonSchema.sync(schema);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Safely converts a schema to JSON Schema, returning undefined for invalid inputs.
|
|
65
|
+
* @param schema - The schema to convert (may be undefined)
|
|
66
|
+
* @param onError - Optional callback invoked on conversion error
|
|
67
|
+
* @returns The JSON Schema representation, or undefined if conversion fails
|
|
68
|
+
*/
|
|
69
|
+
function safeSchemaToJsonSchema(schema, onError) {
|
|
70
|
+
if (!schema) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
return schemaToJsonSchema(schema);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error("Error converting schema to JSON Schema:", error);
|
|
78
|
+
onError?.(error);
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Creates parameter specs from an input schema.
|
|
84
|
+
* The schema represents the shape of the single object argument to the tool function.
|
|
85
|
+
* @param schema - The input schema (JSON Schema)
|
|
86
|
+
* @returns An array of parameter specifications
|
|
87
|
+
*/
|
|
88
|
+
function createParametersFromSchema(schema) {
|
|
89
|
+
const properties = schema.properties ?? {};
|
|
90
|
+
return Object.entries(properties).map(([key, propSchema]) => ({
|
|
91
|
+
name: key,
|
|
92
|
+
type: propSchema && typeof propSchema === "object" && "type" in propSchema
|
|
93
|
+
? propSchema.type
|
|
94
|
+
: "object",
|
|
95
|
+
description: propSchema &&
|
|
96
|
+
typeof propSchema === "object" &&
|
|
97
|
+
"description" in propSchema
|
|
98
|
+
? (propSchema.description ?? "")
|
|
99
|
+
: "",
|
|
100
|
+
isRequired: Array.isArray(schema.required)
|
|
101
|
+
? schema.required.includes(key)
|
|
102
|
+
: false,
|
|
103
|
+
schema: typeof propSchema === "object" && propSchema !== null
|
|
104
|
+
? propSchema
|
|
105
|
+
: {},
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Extracts parameter specifications from a tool's inputSchema.
|
|
110
|
+
* @param tool - The tool containing the schema
|
|
111
|
+
* @returns An array of parameter specifications
|
|
112
|
+
*/
|
|
113
|
+
function getParametersFromToolSchema(tool) {
|
|
114
|
+
const schema = tool.inputSchema;
|
|
115
|
+
// Convert to JSON Schema if needed
|
|
116
|
+
let jsonSchema;
|
|
117
|
+
if ((0, json_schema_1.looksLikeJSONSchema)(schema)) {
|
|
118
|
+
jsonSchema = schema;
|
|
119
|
+
}
|
|
120
|
+
else if ((0, standard_schema_1.isStandardSchema)(schema)) {
|
|
121
|
+
jsonSchema = schemaToJsonSchema(schema);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
console.warn("Unknown inputSchema type, returning empty parameters");
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
return createParametersFromSchema(jsonSchema);
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema/schema.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAsDH,gDAOC;AAQD,wDAeC;AAyCD,kEAeC;AA1ID,qEAA6E;AAE7E,2DAAqD;AACrD,sCAA+D;AAM/D,+CAAoD;AACpD,uDAAqD;AAErD;;;GAGG;AACH,IAAA,0BAAU,EAAC,KAAK,EAAE,CAAC,MAAe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AU,KAAK,QAAQ,IAAI,MAAM,IAAI,UAAU;YAClE,CAAC,CAAE,UAAU,CAAC,IAAe;YAC7B,CAAC,CAAC,QAAQ;QACd,WAAW,EACT,UAAU;YACV,OAAO,UAAU,KAAK,QAAQ;YAC9B,aAAa,IAAI,UAAU;YACzB,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,IAAI,EAAE,CAAC;YAChC,CAAC,CAAC,EAAE;QACR,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;YACxC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;YAC/B,CAAC,CAAC,KAAK;QACT,MAAM,EACJ,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,IAAI;YACnD,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,EAAE;KACT,CAAyB,CAC7B,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAgB,2BAA2B,CAAC,IAAe;IACzD,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC;IAEhC,mCAAmC;IACnC,IAAI,UAAuB,CAAC;IAC5B,IAAI,IAAA,iCAAmB,EAAC,MAAM,CAAC,EAAE,CAAC;QAChC,UAAU,GAAG,MAAM,CAAC;IACtB,CAAC;SAAM,IAAI,IAAA,kCAAgB,EAAC,MAAM,CAAC,EAAE,CAAC;QACpC,UAAU,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAC;QACrE,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,0BAA0B,CAAC,UAAU,CAAC,CAAC;AAChD,CAAC","sourcesContent":["/**\n * Schema utilities for working with Standard Schema and JSON Schema.\n *\n * This module provides a unified interface for handling different schema types\n * used in Tambo components and tools. It uses Standard Schema (https://standardschema.dev/)\n * as the primary interface, which is implemented by Zod 3.24+ and other validation libraries.\n *\n * JSON Schema conversion is handled by `@standard-community/standard-json`.\n * @module schema\n */\n\nimport { loadVendor, toJsonSchema } from \"@standard-community/standard-json\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { toJSONSchema as zod4ToJSONSchema } from \"zod/v4/core\";\nimport {\n ParameterSpec,\n SupportedSchema,\n TamboTool,\n} from \"../model/component-metadata\";\nimport { looksLikeJSONSchema } from \"./json-schema\";\nimport { isStandardSchema } from \"./standard-schema\";\n\n/**\n * Register the zod vendor handler for synchronous JSON Schema conversion.\n * This uses Zod 4's native toJSONSchema for Zod 4.x schemas and zod-to-json-schema for Zod 3.x.\n */\nloadVendor(\"zod\", (schema: unknown): JSONSchema7 => {\n // Check if this is a Zod 4 schema (has _zod property)\n if (schema && typeof schema === \"object\" && \"_zod\" in schema) {\n // Use Zod 4's native toJSONSchema from zod/v4/core\n // Cast through unknown since the Zod 4 internal types don't match our detection pattern\n return zod4ToJSONSchema(\n schema as unknown as Parameters<typeof zod4ToJSONSchema>[0],\n ) as JSONSchema7;\n }\n // Fall back to zod-to-json-schema for Zod 3.x\n return zodToJsonSchema(\n schema as Parameters<typeof zodToJsonSchema>[0],\n ) as JSONSchema7;\n});\n\n/**\n * Converts a schema (Standard Schema or JSON Schema) to a JSON Schema object.\n *\n * If the schema is already a JSON Schema, it is returned as-is.\n * For Standard Schema validators (Zod 3.24+, etc.), uses\n * `@standard-community/standard-json` for conversion.\n * @param schema - The schema to convert\n * @returns The JSON Schema representation\n * @example\n * ```typescript\n * import { z } from \"zod/v4\";\n *\n * // Convert a Zod schema\n * const zodSchema = z.object({ name: z.string() });\n * const jsonSchema = schemaToJsonSchema(zodSchema);\n *\n * // Pass through a JSON Schema\n * const existingJsonSchema = { type: \"object\", properties: { name: { type: \"string\" } } };\n * schemaToJsonSchema(existingJsonSchema); // returns the same object\n * ```\n */\nexport function schemaToJsonSchema(schema: SupportedSchema): JSONSchema7 {\n // Already a JSON Schema - return as-is\n if (!isStandardSchema(schema)) {\n return schema;\n }\n\n return toJsonSchema.sync(schema) as JSONSchema7;\n}\n\n/**\n * Safely converts a schema to JSON Schema, returning undefined for invalid inputs.\n * @param schema - The schema to convert (may be undefined)\n * @param onError - Optional callback invoked on conversion error\n * @returns The JSON Schema representation, or undefined if conversion fails\n */\nexport function safeSchemaToJsonSchema(\n schema: SupportedSchema | undefined | null,\n onError?: (error: unknown) => void,\n): JSONSchema7 | undefined {\n if (!schema) {\n return undefined;\n }\n\n try {\n return schemaToJsonSchema(schema);\n } catch (error) {\n console.error(\"Error converting schema to JSON Schema:\", error);\n onError?.(error);\n return undefined;\n }\n}\n\n/**\n * Creates parameter specs from an input schema.\n * The schema represents the shape of the single object argument to the tool function.\n * @param schema - The input schema (JSON Schema)\n * @returns An array of parameter specifications\n */\nfunction createParametersFromSchema(schema: JSONSchema7): ParameterSpec[] {\n const properties = schema.properties ?? {};\n\n return Object.entries(properties).map(\n ([key, propSchema]) =>\n ({\n name: key,\n type:\n propSchema && typeof propSchema === \"object\" && \"type\" in propSchema\n ? (propSchema.type as string)\n : \"object\",\n description:\n propSchema &&\n typeof propSchema === \"object\" &&\n \"description\" in propSchema\n ? (propSchema.description ?? \"\")\n : \"\",\n isRequired: Array.isArray(schema.required)\n ? schema.required.includes(key)\n : false,\n schema:\n typeof propSchema === \"object\" && propSchema !== null\n ? propSchema\n : {},\n }) satisfies ParameterSpec,\n );\n}\n\n/**\n * Extracts parameter specifications from a tool's inputSchema.\n * @param tool - The tool containing the schema\n * @returns An array of parameter specifications\n */\nexport function getParametersFromToolSchema(tool: TamboTool): ParameterSpec[] {\n const schema = tool.inputSchema;\n\n // Convert to JSON Schema if needed\n let jsonSchema: JSONSchema7;\n if (looksLikeJSONSchema(schema)) {\n jsonSchema = schema;\n } else if (isStandardSchema(schema)) {\n jsonSchema = schemaToJsonSchema(schema);\n } else {\n console.warn(\"Unknown inputSchema type, returning empty parameters\");\n return [];\n }\n\n return createParametersFromSchema(jsonSchema);\n}\n\nexport type { SupportedSchema };\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
/**
|
|
3
|
+
* Type guard to check if an object implements the Standard Schema interface.
|
|
4
|
+
*
|
|
5
|
+
* Standard Schema compliant validators have a `~standard` property containing
|
|
6
|
+
* metadata about the schema including version, vendor, and validate function.
|
|
7
|
+
* Uses duck typing to avoid cross-version Zod compatibility issues.
|
|
8
|
+
* @param obj - The object to check
|
|
9
|
+
* @returns True if the object implements StandardSchemaV1
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { z } from "zod/v4";
|
|
13
|
+
*
|
|
14
|
+
* const zodSchema = z.object({ name: z.string() });
|
|
15
|
+
* isStandardSchema(zodSchema); // true
|
|
16
|
+
*
|
|
17
|
+
* const jsonSchema = { type: "object", properties: { name: { type: "string" } } };
|
|
18
|
+
* isStandardSchema(jsonSchema); // false
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function isStandardSchema(obj: unknown): obj is StandardSchemaV1;
|
|
22
|
+
//# sourceMappingURL=standard-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard-schema.d.ts","sourceRoot":"","sources":["../../src/schema/standard-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,gBAAgB,CAuBtE"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isStandardSchema = isStandardSchema;
|
|
4
|
+
/**
|
|
5
|
+
* Type guard to check if an object implements the Standard Schema interface.
|
|
6
|
+
*
|
|
7
|
+
* Standard Schema compliant validators have a `~standard` property containing
|
|
8
|
+
* metadata about the schema including version, vendor, and validate function.
|
|
9
|
+
* Uses duck typing to avoid cross-version Zod compatibility issues.
|
|
10
|
+
* @param obj - The object to check
|
|
11
|
+
* @returns True if the object implements StandardSchemaV1
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { z } from "zod/v4";
|
|
15
|
+
*
|
|
16
|
+
* const zodSchema = z.object({ name: z.string() });
|
|
17
|
+
* isStandardSchema(zodSchema); // true
|
|
18
|
+
*
|
|
19
|
+
* const jsonSchema = { type: "object", properties: { name: { type: "string" } } };
|
|
20
|
+
* isStandardSchema(jsonSchema); // false
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function isStandardSchema(obj) {
|
|
24
|
+
if (typeof obj !== "object" || obj === null) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (!("~standard" in obj)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const standard = obj["~standard"];
|
|
31
|
+
if (typeof standard !== "object" || standard === null) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
// Check required Standard Schema v1 properties
|
|
35
|
+
return ("version" in standard &&
|
|
36
|
+
standard.version === 1 &&
|
|
37
|
+
"vendor" in standard &&
|
|
38
|
+
typeof standard.vendor === "string" &&
|
|
39
|
+
"validate" in standard &&
|
|
40
|
+
typeof standard.validate === "function");
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=standard-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard-schema.js","sourceRoot":"","sources":["../../src/schema/standard-schema.ts"],"names":[],"mappings":";;AAqBA,4CAuBC;AA1CD;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,gBAAgB,CAAC,GAAY;IAC3C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC,CAAC,WAAW,IAAI,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC;IAClC,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,+CAA+C;IAC/C,OAAO,CACL,SAAS,IAAI,QAAQ;QACrB,QAAQ,CAAC,OAAO,KAAK,CAAC;QACtB,QAAQ,IAAI,QAAQ;QACpB,OAAO,QAAQ,CAAC,MAAM,KAAK,QAAQ;QACnC,UAAU,IAAI,QAAQ;QACtB,OAAO,QAAQ,CAAC,QAAQ,KAAK,UAAU,CACxC,CAAC;AACJ,CAAC","sourcesContent":["import { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n/**\n * Type guard to check if an object implements the Standard Schema interface.\n *\n * Standard Schema compliant validators have a `~standard` property containing\n * metadata about the schema including version, vendor, and validate function.\n * Uses duck typing to avoid cross-version Zod compatibility issues.\n * @param obj - The object to check\n * @returns True if the object implements StandardSchemaV1\n * @example\n * ```typescript\n * import { z } from \"zod/v4\";\n *\n * const zodSchema = z.object({ name: z.string() });\n * isStandardSchema(zodSchema); // true\n *\n * const jsonSchema = { type: \"object\", properties: { name: { type: \"string\" } } };\n * isStandardSchema(jsonSchema); // false\n * ```\n */\nexport function isStandardSchema(obj: unknown): obj is StandardSchemaV1 {\n if (typeof obj !== \"object\" || obj === null) {\n return false;\n }\n\n if (!(\"~standard\" in obj)) {\n return false;\n }\n\n const standard = obj[\"~standard\"];\n if (typeof standard !== \"object\" || standard === null) {\n return false;\n }\n\n // Check required Standard Schema v1 properties\n return (\n \"version\" in standard &&\n standard.version === 1 &&\n \"vendor\" in standard &&\n typeof standard.vendor === \"string\" &&\n \"validate\" in standard &&\n typeof standard.validate === \"function\"\n );\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that a schema does not contain record types (objects with dynamic keys).
|
|
3
|
+
* Records are not serializable to JSON Schema in a way that the Tambo backend
|
|
4
|
+
* understands, so they are disallowed.
|
|
5
|
+
*
|
|
6
|
+
* This function accepts Standard Schema validators (Zod, Valibot, ArkType, etc.)
|
|
7
|
+
* or JSON Schema objects. It converts them to JSON Schema and checks for record patterns.
|
|
8
|
+
*
|
|
9
|
+
* For tool schemas that are function types, this extracts and validates the input parameters.
|
|
10
|
+
* @param schema - The schema to validate (Standard Schema or JSON Schema)
|
|
11
|
+
* @param contextName - A human-readable label echoed in the error message
|
|
12
|
+
*/
|
|
13
|
+
export declare function assertNoRecordSchema(schema: unknown, contextName?: string): void;
|
|
14
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/schema/validate.ts"],"names":[],"mappings":"AAuIA;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,EACf,WAAW,SAAW,GACrB,IAAI,CAqCN"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertNoRecordSchema = assertNoRecordSchema;
|
|
4
|
+
const schema_1 = require("./schema.js");
|
|
5
|
+
const standard_schema_1 = require("./standard-schema.js");
|
|
6
|
+
/*
|
|
7
|
+
* Check if a JSON Schema represents a record type (map with dynamic keys).
|
|
8
|
+
*
|
|
9
|
+
* For our purposes, any `object` schema with `additionalProperties` defined
|
|
10
|
+
* as a nested schema (not just `true`/`false`) is treated as a record, even
|
|
11
|
+
* if it also declares some explicit `properties`.
|
|
12
|
+
* @param schema - The JSON Schema to check
|
|
13
|
+
* @returns True if the schema represents a record-like type
|
|
14
|
+
*/
|
|
15
|
+
function isRecordJsonSchema(schema) {
|
|
16
|
+
return (schema.type === "object" &&
|
|
17
|
+
typeof schema.additionalProperties === "object" &&
|
|
18
|
+
schema.additionalProperties !== null);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Recursively walks a JSON Schema and throws when it encounters a record type.
|
|
22
|
+
* Records are not supported because they use dynamic keys which don't serialize
|
|
23
|
+
* well for the Tambo backend.
|
|
24
|
+
* @param schema - The JSON Schema to check
|
|
25
|
+
* @param path - Current path in the schema (for error messages)
|
|
26
|
+
* @param contextName - Human-readable context name for error messages
|
|
27
|
+
*/
|
|
28
|
+
function assertNoRecordInJsonSchema(schema, path, contextName) {
|
|
29
|
+
if (isRecordJsonSchema(schema)) {
|
|
30
|
+
const joined = path.length ? path.join(".") : "(root)";
|
|
31
|
+
throw new Error(`Record types (objects with dynamic keys) are not supported in ${contextName}. ` +
|
|
32
|
+
`Found at path "${joined}". ` +
|
|
33
|
+
"Replace it with an object using explicit keys.");
|
|
34
|
+
}
|
|
35
|
+
if (schema.properties) {
|
|
36
|
+
for (const [key, propSchema] of Object.entries(schema.properties)) {
|
|
37
|
+
if (typeof propSchema === "object" && propSchema !== null) {
|
|
38
|
+
assertNoRecordInJsonSchema(propSchema, [...path, key], contextName);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (typeof schema.additionalProperties === "object" &&
|
|
43
|
+
schema.additionalProperties !== null) {
|
|
44
|
+
assertNoRecordInJsonSchema(schema.additionalProperties, [...path, "[*]"], contextName);
|
|
45
|
+
}
|
|
46
|
+
if (schema.items) {
|
|
47
|
+
if (Array.isArray(schema.items)) {
|
|
48
|
+
// Tuple (JSON Schema draft-07): check each item schema
|
|
49
|
+
schema.items.forEach((itemSchema, index) => {
|
|
50
|
+
if (typeof itemSchema === "object" && itemSchema !== null) {
|
|
51
|
+
assertNoRecordInJsonSchema(itemSchema, [...path, `${index}`], contextName);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else if (typeof schema.items === "object") {
|
|
56
|
+
// Array: check the item schema
|
|
57
|
+
assertNoRecordInJsonSchema(schema.items, [...path, "[]"], contextName);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const prefixItems = schema.prefixItems;
|
|
61
|
+
if (Array.isArray(prefixItems)) {
|
|
62
|
+
prefixItems.forEach((itemSchema, index) => {
|
|
63
|
+
if (typeof itemSchema === "object" && itemSchema !== null) {
|
|
64
|
+
assertNoRecordInJsonSchema(itemSchema, [...path, `${index}`], contextName);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (schema.allOf) {
|
|
69
|
+
schema.allOf.forEach((subSchema, index) => {
|
|
70
|
+
if (typeof subSchema === "object" && subSchema !== null) {
|
|
71
|
+
assertNoRecordInJsonSchema(subSchema, [...path, `&${index}`], contextName);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (schema.anyOf) {
|
|
76
|
+
schema.anyOf.forEach((subSchema, index) => {
|
|
77
|
+
if (typeof subSchema === "object" && subSchema !== null) {
|
|
78
|
+
assertNoRecordInJsonSchema(subSchema, [...path, `|${index}`], contextName);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (schema.oneOf) {
|
|
83
|
+
schema.oneOf.forEach((subSchema, index) => {
|
|
84
|
+
if (typeof subSchema === "object" && subSchema !== null) {
|
|
85
|
+
assertNoRecordInJsonSchema(subSchema, [...path, `|${index}`], contextName);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (typeof schema.not === "object" && schema.not !== null) {
|
|
90
|
+
assertNoRecordInJsonSchema(schema.not, [...path, "!"], contextName);
|
|
91
|
+
}
|
|
92
|
+
if (typeof schema.if === "object" && schema.if !== null) {
|
|
93
|
+
assertNoRecordInJsonSchema(schema.if, [...path, "if"], contextName);
|
|
94
|
+
}
|
|
95
|
+
if (typeof schema.then === "object" && schema.then !== null) {
|
|
96
|
+
assertNoRecordInJsonSchema(schema.then, [...path, "then"], contextName);
|
|
97
|
+
}
|
|
98
|
+
if (typeof schema.else === "object" && schema.else !== null) {
|
|
99
|
+
assertNoRecordInJsonSchema(schema.else, [...path, "else"], contextName);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Asserts that a schema does not contain record types (objects with dynamic keys).
|
|
104
|
+
* Records are not serializable to JSON Schema in a way that the Tambo backend
|
|
105
|
+
* understands, so they are disallowed.
|
|
106
|
+
*
|
|
107
|
+
* This function accepts Standard Schema validators (Zod, Valibot, ArkType, etc.)
|
|
108
|
+
* or JSON Schema objects. It converts them to JSON Schema and checks for record patterns.
|
|
109
|
+
*
|
|
110
|
+
* For tool schemas that are function types, this extracts and validates the input parameters.
|
|
111
|
+
* @param schema - The schema to validate (Standard Schema or JSON Schema)
|
|
112
|
+
* @param contextName - A human-readable label echoed in the error message
|
|
113
|
+
*/
|
|
114
|
+
function assertNoRecordSchema(schema, contextName = "schema") {
|
|
115
|
+
if (!schema) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
let jsonSchema;
|
|
119
|
+
try {
|
|
120
|
+
if ((0, standard_schema_1.isStandardSchema)(schema)) {
|
|
121
|
+
// Handle function schemas specially - extract input parameters
|
|
122
|
+
const converted = (0, schema_1.schemaToJsonSchema)(schema);
|
|
123
|
+
// If it's a function schema that couldn't be converted, the input params
|
|
124
|
+
// were extracted in registry.ts, so we can skip validation here
|
|
125
|
+
if (!converted || Object.keys(converted).length === 0) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
jsonSchema = converted;
|
|
129
|
+
}
|
|
130
|
+
else if (typeof schema === "object" &&
|
|
131
|
+
schema !== null &&
|
|
132
|
+
"type" in schema) {
|
|
133
|
+
// Already JSON Schema
|
|
134
|
+
jsonSchema = schema;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
// Unknown schema type - skip validation
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
// If schema conversion fails, skip validation
|
|
143
|
+
// This can happen for function schemas or other special types
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
assertNoRecordInJsonSchema(jsonSchema, [], contextName);
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/schema/validate.ts"],"names":[],"mappings":";;AAmJA,oDAwCC;AA1LD,qCAA8C;AAC9C,uDAAqD;AAErD;;;;;;;;GAQG;AACH,SAAS,kBAAkB,CAAC,MAAmB;IAC7C,OAAO,CACL,MAAM,CAAC,IAAI,KAAK,QAAQ;QACxB,OAAO,MAAM,CAAC,oBAAoB,KAAK,QAAQ;QAC/C,MAAM,CAAC,oBAAoB,KAAK,IAAI,CACrC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,0BAA0B,CACjC,MAAmB,EACnB,IAAc,EACd,WAAmB;IAEnB,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QACvD,MAAM,IAAI,KAAK,CACb,iEAAiE,WAAW,IAAI;YAC9E,kBAAkB,MAAM,KAAK;YAC7B,gDAAgD,CACnD,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACtB,KAAK,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;YAClE,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;gBAC1D,0BAA0B,CAAC,UAAU,EAAE,CAA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AC;gBACtD,OAAO;YACT,CAAC;YAED,UAAU,GAAG,SAAS,CAAC;QACzB,CAAC;aAAM,IACL,OAAO,MAAM,KAAK,QAAQ;YAC1B,MAAM,KAAK,IAAI;YACf,MAAM,IAAI,MAAM,EAChB,CAAC;YACD,sBAAsB;YACtB,UAAU,GAAG,MAAqB,CAAC;QACrC,CAAC;aAAM,CAAC;YACN,wCAAwC;YACxC,OAAO;QACT,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,8CAA8C;QAC9C,8DAA8D;QAC9D,OAAO;IACT,CAAC;IAED,0BAA0B,CAAC,UAAU,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import type { JSONSchema7 } from \"json-schema\";\nimport { schemaToJsonSchema } from \"./schema\";\nimport { isStandardSchema } from \"./standard-schema\";\n\n/*\n * Check if a JSON Schema represents a record type (map with dynamic keys).\n *\n * For our purposes, any `object` schema with `additionalProperties` defined\n * as a nested schema (not just `true`/`false`) is treated as a record, even\n * if it also declares some explicit `properties`.\n * @param schema - The JSON Schema to check\n * @returns True if the schema represents a record-like type\n */\nfunction isRecordJsonSchema(schema: JSONSchema7): boolean {\n return (\n schema.type === \"object\" &&\n typeof schema.additionalProperties === \"object\" &&\n schema.additionalProperties !== null\n );\n}\n\n/**\n * Recursively walks a JSON Schema and throws when it encounters a record type.\n * Records are not supported because they use dynamic keys which don't serialize\n * well for the Tambo backend.\n * @param schema - The JSON Schema to check\n * @param path - Current path in the schema (for error messages)\n * @param contextName - Human-readable context name for error messages\n */\nfunction assertNoRecordInJsonSchema(\n schema: JSONSchema7,\n path: string[],\n contextName: string,\n): void {\n if (isRecordJsonSchema(schema)) {\n const joined = path.length ? path.join(\".\") : \"(root)\";\n throw new Error(\n `Record types (objects with dynamic keys) are not supported in ${contextName}. ` +\n `Found at path \"${joined}\". ` +\n \"Replace it with an object using explicit keys.\",\n );\n }\n if (schema.properties) {\n for (const [key, propSchema] of Object.entries(schema.properties)) {\n if (typeof propSchema === \"object\" && propSchema !== null) {\n assertNoRecordInJsonSchema(propSchema, [...path, key], contextName);\n }\n }\n }\n if (\n typeof schema.additionalProperties === \"object\" &&\n schema.additionalProperties !== null\n ) {\n assertNoRecordInJsonSchema(\n schema.additionalProperties,\n [...path, \"[*]\"],\n contextName,\n );\n }\n if (schema.items) {\n if (Array.isArray(schema.items)) {\n // Tuple (JSON Schema draft-07): check each item schema\n schema.items.forEach((itemSchema, index) => {\n if (typeof itemSchema === \"object\" && itemSchema !== null) {\n assertNoRecordInJsonSchema(\n itemSchema,\n [...path, `${index}`],\n contextName,\n );\n }\n });\n } else if (typeof schema.items === \"object\") {\n // Array: check the item schema\n assertNoRecordInJsonSchema(schema.items, [...path, \"[]\"], contextName);\n }\n }\n const prefixItems = (schema as Record<string, unknown>).prefixItems;\n if (Array.isArray(prefixItems)) {\n prefixItems.forEach((itemSchema, index) => {\n if (typeof itemSchema === \"object\" && itemSchema !== null) {\n assertNoRecordInJsonSchema(\n itemSchema as JSONSchema7,\n [...path, `${index}`],\n contextName,\n );\n }\n });\n }\n if (schema.allOf) {\n schema.allOf.forEach((subSchema, index) => {\n if (typeof subSchema === \"object\" && subSchema !== null) {\n assertNoRecordInJsonSchema(\n subSchema,\n [...path, `&${index}`],\n contextName,\n );\n }\n });\n }\n if (schema.anyOf) {\n schema.anyOf.forEach((subSchema, index) => {\n if (typeof subSchema === \"object\" && subSchema !== null) {\n assertNoRecordInJsonSchema(\n subSchema,\n [...path, `|${index}`],\n contextName,\n );\n }\n });\n }\n if (schema.oneOf) {\n schema.oneOf.forEach((subSchema, index) => {\n if (typeof subSchema === \"object\" && subSchema !== null) {\n assertNoRecordInJsonSchema(\n subSchema,\n [...path, `|${index}`],\n contextName,\n );\n }\n });\n }\n if (typeof schema.not === \"object\" && schema.not !== null) {\n assertNoRecordInJsonSchema(schema.not, [...path, \"!\"], contextName);\n }\n if (typeof schema.if === \"object\" && schema.if !== null) {\n assertNoRecordInJsonSchema(schema.if, [...path, \"if\"], contextName);\n }\n if (typeof schema.then === \"object\" && schema.then !== null) {\n assertNoRecordInJsonSchema(schema.then, [...path, \"then\"], contextName);\n }\n if (typeof schema.else === \"object\" && schema.else !== null) {\n assertNoRecordInJsonSchema(schema.else, [...path, \"else\"], contextName);\n }\n}\n\n/**\n * Asserts that a schema does not contain record types (objects with dynamic keys).\n * Records are not serializable to JSON Schema in a way that the Tambo backend\n * understands, so they are disallowed.\n *\n * This function accepts Standard Schema validators (Zod, Valibot, ArkType, etc.)\n * or JSON Schema objects. It converts them to JSON Schema and checks for record patterns.\n *\n * For tool schemas that are function types, this extracts and validates the input parameters.\n * @param schema - The schema to validate (Standard Schema or JSON Schema)\n * @param contextName - A human-readable label echoed in the error message\n */\nexport function assertNoRecordSchema(\n schema: unknown,\n contextName = \"schema\",\n): void {\n if (!schema) {\n return;\n }\n\n let jsonSchema: JSONSchema7;\n\n try {\n if (isStandardSchema(schema)) {\n // Handle function schemas specially - extract input parameters\n const converted = schemaToJsonSchema(schema);\n\n // If it's a function schema that couldn't be converted, the input params\n // were extracted in registry.ts, so we can skip validation here\n if (!converted || Object.keys(converted).length === 0) {\n return;\n }\n\n jsonSchema = converted;\n } else if (\n typeof schema === \"object\" &&\n schema !== null &&\n \"type\" in schema\n ) {\n // Already JSON Schema\n jsonSchema = schema as JSONSchema7;\n } else {\n // Unknown schema type - skip validation\n return;\n }\n } catch {\n // If schema conversion fails, skip validation\n // This can happen for function schemas or other special types\n return;\n }\n\n assertNoRecordInJsonSchema(jsonSchema, [], contextName);\n}\n"]}
|