@copilotkit/shared 2.0.0-rc.8 → 2.0.0-rc.9
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/README.md +3 -14
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +12 -95
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/standard-schema.cjs +7 -7
- package/dist/standard-schema.cjs.map +1 -1
- package/dist/standard-schema.d.cts +7 -16
- package/dist/standard-schema.d.cts.map +1 -1
- package/dist/standard-schema.d.mts +7 -16
- package/dist/standard-schema.d.mts.map +1 -1
- package/dist/standard-schema.mjs +7 -7
- package/dist/standard-schema.mjs.map +1 -1
- package/dist/telemetry/telemetry-disabled.cjs +0 -5
- package/dist/telemetry/telemetry-disabled.cjs.map +1 -1
- package/dist/telemetry/telemetry-disabled.d.cts +0 -5
- package/dist/telemetry/telemetry-disabled.d.cts.map +1 -1
- package/dist/telemetry/telemetry-disabled.d.mts +0 -5
- package/dist/telemetry/telemetry-disabled.d.mts.map +1 -1
- package/dist/telemetry/telemetry-disabled.mjs +0 -5
- package/dist/telemetry/telemetry-disabled.mjs.map +1 -1
- package/dist/utils/index.d.cts +1 -1
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/json-schema.cjs +0 -79
- package/dist/utils/json-schema.cjs.map +1 -1
- package/dist/utils/json-schema.d.cts +1 -4
- package/dist/utils/json-schema.d.cts.map +1 -1
- package/dist/utils/json-schema.d.mts +1 -4
- package/dist/utils/json-schema.d.mts.map +1 -1
- package/dist/utils/json-schema.mjs +1 -78
- package/dist/utils/json-schema.mjs.map +1 -1
- package/package.json +7 -28
- package/src/__tests__/root-entry-browser-safety.test.ts +5 -7
- package/src/__tests__/standard-schema.test.ts +38 -103
- package/src/index.ts +3 -16
- package/src/standard-schema.ts +9 -27
- package/src/telemetry/telemetry-disabled.ts +0 -5
- package/src/utils/__tests__/json-schema.test.ts +3 -479
- package/src/utils/json-schema.ts +1 -152
- package/tsdown.config.ts +2 -10
- package/dist/event-transforms/index.cjs +0 -15
- package/dist/event-transforms/index.d.cts +0 -4
- package/dist/event-transforms/index.d.mts +0 -4
- package/dist/event-transforms/index.mjs +0 -5
- package/dist/event-transforms/open-generative-ui-middleware.cjs +0 -286
- package/dist/event-transforms/open-generative-ui-middleware.cjs.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.d.cts +0 -60
- package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.d.mts +0 -60
- package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.mjs +0 -283
- package/dist/event-transforms/open-generative-ui-middleware.mjs.map +0 -1
- package/dist/event-transforms/recorded-events.cjs +0 -59
- package/dist/event-transforms/recorded-events.cjs.map +0 -1
- package/dist/event-transforms/recorded-events.d.cts +0 -23
- package/dist/event-transforms/recorded-events.d.cts.map +0 -1
- package/dist/event-transforms/recorded-events.d.mts +0 -23
- package/dist/event-transforms/recorded-events.d.mts.map +0 -1
- package/dist/event-transforms/recorded-events.mjs +0 -58
- package/dist/event-transforms/recorded-events.mjs.map +0 -1
- package/dist/telemetry/events.d.cts +0 -72
- package/dist/telemetry/events.d.cts.map +0 -1
- package/dist/telemetry/events.d.mts +0 -72
- package/dist/telemetry/events.d.mts.map +0 -1
- package/dist/telemetry/index.cjs +0 -18
- package/dist/telemetry/index.d.cts +0 -5
- package/dist/telemetry/index.d.mts +0 -5
- package/dist/telemetry/index.mjs +0 -6
- package/dist/telemetry/telemetry-client.cjs +0 -165
- package/dist/telemetry/telemetry-client.cjs.map +0 -1
- package/dist/telemetry/telemetry-client.d.cts +0 -87
- package/dist/telemetry/telemetry-client.d.cts.map +0 -1
- package/dist/telemetry/telemetry-client.d.mts +0 -87
- package/dist/telemetry/telemetry-client.d.mts.map +0 -1
- package/dist/telemetry/telemetry-client.mjs +0 -164
- package/dist/telemetry/telemetry-client.mjs.map +0 -1
- package/dist/telemetry/utils.cjs +0 -14
- package/dist/telemetry/utils.cjs.map +0 -1
- package/dist/telemetry/utils.mjs +0 -13
- package/dist/telemetry/utils.mjs.map +0 -1
- package/src/__tests__/zod-regression.test.ts +0 -319
- package/src/event-transforms/index.ts +0 -5
- package/src/event-transforms/open-generative-ui-middleware.ts +0 -392
- package/src/event-transforms/recorded-events.test.ts +0 -166
- package/src/event-transforms/recorded-events.ts +0 -74
- package/src/telemetry/events.ts +0 -68
- package/src/telemetry/index.ts +0 -9
- package/src/telemetry/telemetry-blank-license-identity.test.ts +0 -128
- package/src/telemetry/telemetry-client.test.ts +0 -798
- package/src/telemetry/telemetry-client.ts +0 -328
- package/src/telemetry/utils.ts +0 -15
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
1
|
//#region src/utils/json-schema.ts
|
|
4
2
|
function actionParametersToJsonSchema(actionParameters) {
|
|
5
3
|
let parameters = {};
|
|
@@ -130,82 +128,7 @@ function convertAttribute(attribute) {
|
|
|
130
128
|
};
|
|
131
129
|
}
|
|
132
130
|
}
|
|
133
|
-
function convertJsonSchemaToZodSchema(jsonSchema, required, definitions, visitedRefs) {
|
|
134
|
-
if (jsonSchema.$ref && definitions) {
|
|
135
|
-
const refPath = jsonSchema.$ref.replace(/^#\/\$defs\/|^#\/definitions\//, "");
|
|
136
|
-
const refs = visitedRefs ?? /* @__PURE__ */ new Set();
|
|
137
|
-
if (refs.has(refPath)) {
|
|
138
|
-
console.warn(`[CopilotKit] Circular $ref detected for "${refPath}" — falling back to z.any()`);
|
|
139
|
-
let schema = z.any();
|
|
140
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
141
|
-
return required ? schema : schema.optional();
|
|
142
|
-
}
|
|
143
|
-
const resolved = definitions[refPath];
|
|
144
|
-
if (resolved) {
|
|
145
|
-
const nextRefs = new Set(refs);
|
|
146
|
-
nextRefs.add(refPath);
|
|
147
|
-
return convertJsonSchemaToZodSchema(resolved, required, definitions, nextRefs);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const defs = definitions ?? jsonSchema.$defs ?? jsonSchema.definitions;
|
|
151
|
-
if (Array.isArray(jsonSchema.type)) {
|
|
152
|
-
const types = jsonSchema.type;
|
|
153
|
-
const hasNull = types.includes("null");
|
|
154
|
-
const nonNullTypes = types.filter((t) => t !== "null");
|
|
155
|
-
const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : "string";
|
|
156
|
-
const innerSchema = convertJsonSchemaToZodSchema({
|
|
157
|
-
...jsonSchema,
|
|
158
|
-
type: resolvedType
|
|
159
|
-
}, true, defs, visitedRefs);
|
|
160
|
-
let schema = hasNull ? z.union([innerSchema, z.null()]) : innerSchema;
|
|
161
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
162
|
-
return required ? schema : schema.optional();
|
|
163
|
-
}
|
|
164
|
-
const unionVariants = jsonSchema.anyOf ?? jsonSchema.oneOf;
|
|
165
|
-
if (Array.isArray(unionVariants) && unionVariants.length > 0) {
|
|
166
|
-
if (unionVariants.length === 1) return convertJsonSchemaToZodSchema(unionVariants[0], required, defs, visitedRefs);
|
|
167
|
-
const schemas = unionVariants.map((v) => convertJsonSchemaToZodSchema(v, true, defs, visitedRefs));
|
|
168
|
-
let schema = z.union(schemas);
|
|
169
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
170
|
-
return required ? schema : schema.optional();
|
|
171
|
-
}
|
|
172
|
-
if (jsonSchema.type === "object") {
|
|
173
|
-
const spec = {};
|
|
174
|
-
if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) return !required ? z.object(spec).optional() : z.object(spec);
|
|
175
|
-
for (const [key, value] of Object.entries(jsonSchema.properties)) spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false, defs, visitedRefs);
|
|
176
|
-
let schema = z.object(spec).describe(jsonSchema.description);
|
|
177
|
-
return required ? schema : schema.optional();
|
|
178
|
-
} else if (jsonSchema.type === "string") {
|
|
179
|
-
if (jsonSchema.enum && jsonSchema.enum.length > 0) {
|
|
180
|
-
let schema = z.enum(jsonSchema.enum).describe(jsonSchema.description);
|
|
181
|
-
return required ? schema : schema.optional();
|
|
182
|
-
}
|
|
183
|
-
let schema = z.string().describe(jsonSchema.description);
|
|
184
|
-
return required ? schema : schema.optional();
|
|
185
|
-
} else if (jsonSchema.type === "number" || jsonSchema.type === "integer") {
|
|
186
|
-
let schema = z.number().describe(jsonSchema.description);
|
|
187
|
-
return required ? schema : schema.optional();
|
|
188
|
-
} else if (jsonSchema.type === "boolean") {
|
|
189
|
-
let schema = z.boolean().describe(jsonSchema.description);
|
|
190
|
-
return required ? schema : schema.optional();
|
|
191
|
-
} else if (jsonSchema.type === "array") {
|
|
192
|
-
let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true, defs, visitedRefs);
|
|
193
|
-
let schema = z.array(itemSchema).describe(jsonSchema.description);
|
|
194
|
-
return required ? schema : schema.optional();
|
|
195
|
-
} else if (jsonSchema.type === "null") {
|
|
196
|
-
let schema = z.null().describe(jsonSchema.description);
|
|
197
|
-
return required ? schema : schema.optional();
|
|
198
|
-
}
|
|
199
|
-
console.warn(`[CopilotKit] Unsupported JSON schema type "${jsonSchema.type ?? "unknown"}" — falling back to z.any()`);
|
|
200
|
-
let schema = z.any();
|
|
201
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
202
|
-
return required ? schema : schema.optional();
|
|
203
|
-
}
|
|
204
|
-
function getZodParameters(parameters) {
|
|
205
|
-
if (!parameters) return z.object({});
|
|
206
|
-
return convertJsonSchemaToZodSchema(actionParametersToJsonSchema(parameters), true);
|
|
207
|
-
}
|
|
208
131
|
|
|
209
132
|
//#endregion
|
|
210
|
-
export { actionParametersToJsonSchema,
|
|
133
|
+
export { actionParametersToJsonSchema, jsonSchemaToActionParameters };
|
|
211
134
|
//# sourceMappingURL=json-schema.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.mjs","names":[],"sources":["../../src/utils/json-schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { Parameter } from \"../types\";\n\nexport type JSONSchemaString = {\n type: \"string\";\n description?: string;\n enum?: string[];\n};\n\nexport type JSONSchemaNumber = {\n type: \"number\";\n description?: string;\n};\n\nexport type JSONSchemaBoolean = {\n type: \"boolean\";\n description?: string;\n};\n\nexport type JSONSchemaObject = {\n type: \"object\";\n properties?: Record<string, JSONSchema>;\n required?: string[];\n description?: string;\n};\n\nexport type JSONSchemaArray = {\n type: \"array\";\n items: JSONSchema;\n description?: string;\n};\n\nexport type JSONSchema =\n | JSONSchemaString\n | JSONSchemaNumber\n | JSONSchemaBoolean\n | JSONSchemaObject\n | JSONSchemaArray;\n\nexport function actionParametersToJsonSchema(\n actionParameters: Parameter[],\n): JSONSchema {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of actionParameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of actionParameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n return {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n };\n}\n\n// Convert JSONSchema to Parameter[]\nexport function jsonSchemaToActionParameters(\n jsonSchema: JSONSchema,\n): Parameter[] {\n if (jsonSchema.type !== \"object\" || !jsonSchema.properties) {\n return [];\n }\n\n const parameters: Parameter[] = [];\n const requiredFields = jsonSchema.required || [];\n\n for (const [name, schema] of Object.entries(jsonSchema.properties)) {\n const parameter = convertJsonSchemaToParameter(\n name,\n schema,\n requiredFields.includes(name),\n );\n parameters.push(parameter);\n }\n\n return parameters;\n}\n\n// Convert JSONSchema property to Parameter\nfunction convertJsonSchemaToParameter(\n name: string,\n schema: JSONSchema,\n isRequired: boolean,\n): Parameter {\n const baseParameter: Parameter = {\n name,\n description: schema.description,\n };\n\n if (!isRequired) {\n baseParameter.required = false;\n }\n\n // Handle null-union types like [\"string\", \"null\"] by picking the non-null type\n if (Array.isArray(schema.type)) {\n const types = schema.type as string[];\n const hasNull = types.includes(\"null\");\n const nonNullTypes = types.filter((t: string) => t !== \"null\");\n const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : \"string\";\n return convertJsonSchemaToParameter(\n name,\n { ...schema, type: resolvedType } as JSONSchema,\n hasNull ? false : isRequired,\n );\n }\n\n switch (schema.type) {\n case \"string\":\n return {\n ...baseParameter,\n type: \"string\",\n ...(schema.enum && { enum: schema.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n ...baseParameter,\n type: schema.type,\n };\n case \"object\":\n if (schema.properties) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.required || [];\n\n for (const [propName, propSchema] of Object.entries(\n schema.properties,\n )) {\n attributes.push(\n convertJsonSchemaToParameter(\n propName,\n propSchema,\n requiredFields.includes(propName),\n ),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object\",\n attributes,\n };\n }\n return {\n ...baseParameter,\n type: \"object\",\n };\n case \"array\":\n if (schema.items.type === \"object\" && \"properties\" in schema.items) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.items.required || [];\n\n for (const [propName, propSchema] of Object.entries(\n schema.items.properties || {},\n )) {\n attributes.push(\n convertJsonSchemaToParameter(\n propName,\n propSchema,\n requiredFields.includes(propName),\n ),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object[]\",\n attributes,\n };\n } else if (schema.items.type === \"array\") {\n throw new Error(\"Nested arrays are not supported\");\n } else {\n return {\n ...baseParameter,\n type: `${schema.items.type}[]`,\n };\n }\n default:\n return {\n ...baseParameter,\n type: \"string\",\n };\n }\n}\n\nfunction convertAttribute(attribute: Parameter): JSONSchema {\n switch (attribute.type) {\n case \"string\":\n return {\n type: \"string\",\n description: attribute.description,\n ...(attribute.enum && { enum: attribute.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n type: attribute.type,\n description: attribute.description,\n };\n case \"object\":\n case \"object[]\":\n const properties = attribute.attributes?.reduce(\n (acc, attr) => {\n acc[attr.name] = convertAttribute(attr);\n return acc;\n },\n {} as Record<string, any>,\n );\n const required = attribute.attributes\n ?.filter((attr) => attr.required !== false)\n .map((attr) => attr.name);\n if (attribute.type === \"object[]\") {\n return {\n type: \"array\",\n items: {\n type: \"object\",\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n },\n description: attribute.description,\n };\n }\n return {\n type: \"object\",\n description: attribute.description,\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n };\n default:\n // Handle arrays of primitive types and undefined attribute.type\n if (attribute.type?.endsWith(\"[]\")) {\n const itemType = attribute.type.slice(0, -2);\n return {\n type: \"array\",\n items: { type: itemType as any },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n\nexport function convertJsonSchemaToZodSchema(\n jsonSchema: any,\n required: boolean,\n definitions?: Record<string, any>,\n visitedRefs?: Set<string>,\n): z.ZodSchema {\n // Resolve $ref references\n if (jsonSchema.$ref && definitions) {\n const refPath = jsonSchema.$ref.replace(\n /^#\\/\\$defs\\/|^#\\/definitions\\//,\n \"\",\n );\n\n // Detect circular $ref cycles\n const refs = visitedRefs ?? new Set<string>();\n if (refs.has(refPath)) {\n console.warn(\n `[CopilotKit] Circular $ref detected for \"${refPath}\" — falling back to z.any()`,\n );\n let schema = z.any();\n if (jsonSchema.description) {\n schema = schema.describe(jsonSchema.description);\n }\n return required ? schema : schema.optional();\n }\n\n const resolved = definitions[refPath];\n if (resolved) {\n // Clone the set so sibling branches don't see each other's visited refs\n const nextRefs = new Set(refs);\n nextRefs.add(refPath);\n return convertJsonSchemaToZodSchema(\n resolved,\n required,\n definitions,\n nextRefs,\n );\n }\n }\n\n // Collect top-level definitions for $ref resolution\n const defs = definitions ?? jsonSchema.$defs ?? jsonSchema.definitions;\n\n // Handle null-union types like [\"string\", \"null\"]\n if (Array.isArray(jsonSchema.type)) {\n const types = jsonSchema.type as string[];\n const hasNull = types.includes(\"null\");\n const nonNullTypes = types.filter((t: string) => t !== \"null\");\n const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : \"string\";\n const innerSchema = convertJsonSchemaToZodSchema(\n { ...jsonSchema, type: resolvedType },\n true,\n defs,\n visitedRefs,\n );\n let schema = hasNull ? z.union([innerSchema, z.null()]) : innerSchema;\n if (jsonSchema.description) {\n schema = schema.describe(jsonSchema.description);\n }\n return required ? schema : schema.optional();\n }\n\n // Handle anyOf / oneOf as z.union\n const unionVariants = jsonSchema.anyOf ?? jsonSchema.oneOf;\n if (Array.isArray(unionVariants) && unionVariants.length > 0) {\n if (unionVariants.length === 1) {\n return convertJsonSchemaToZodSchema(\n unionVariants[0],\n required,\n defs,\n visitedRefs,\n );\n }\n const schemas = unionVariants.map((v: any) =>\n convertJsonSchemaToZodSchema(v, true, defs, visitedRefs),\n );\n let schema = z.union(\n schemas as [z.ZodSchema, z.ZodSchema, ...z.ZodSchema[]],\n );\n if (jsonSchema.description) {\n schema = schema.describe(jsonSchema.description);\n }\n return required ? schema : schema.optional();\n }\n\n if (jsonSchema.type === \"object\") {\n const spec: { [key: string]: z.ZodSchema } = {};\n\n if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {\n return !required ? z.object(spec).optional() : z.object(spec);\n }\n\n for (const [key, value] of Object.entries(jsonSchema.properties)) {\n spec[key] = convertJsonSchemaToZodSchema(\n value,\n jsonSchema.required ? jsonSchema.required.includes(key) : false,\n defs,\n visitedRefs,\n );\n }\n let schema = z.object(spec).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"string\") {\n if (jsonSchema.enum && jsonSchema.enum.length > 0) {\n let schema = z\n .enum(jsonSchema.enum as [string, ...string[]])\n .describe(jsonSchema.description);\n return required ? schema : schema.optional();\n }\n let schema = z.string().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"number\" || jsonSchema.type === \"integer\") {\n let schema = z.number().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"boolean\") {\n let schema = z.boolean().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"array\") {\n let itemSchema = convertJsonSchemaToZodSchema(\n jsonSchema.items,\n true,\n defs,\n visitedRefs,\n );\n let schema = z.array(itemSchema).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"null\") {\n let schema = z.null().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n }\n\n // Fallback: accept any value rather than throwing\n console.warn(\n `[CopilotKit] Unsupported JSON schema type \"${jsonSchema.type ?? \"unknown\"}\" — falling back to z.any()`,\n );\n let schema = z.any();\n if (jsonSchema.description) {\n schema = schema.describe(jsonSchema.description);\n }\n return required ? schema : schema.optional();\n}\n\nexport function getZodParameters<T extends [] | Parameter[] | undefined>(\n parameters: T,\n): any {\n if (!parameters) return z.object({});\n const jsonParams = actionParametersToJsonSchema(parameters);\n return convertJsonSchemaToZodSchema(jsonParams, true);\n}\n"],"mappings":";;;AAuCA,SAAgB,6BACd,kBACY;CAEZ,IAAI,aAAqC,EAAE;AAC3C,MAAK,IAAI,aAAa,oBAAoB,EAAE,CAC1C,YAAW,UAAU,QAAQ,iBAAiB,UAAU;CAG1D,IAAI,yBAAmC,EAAE;AACzC,MAAK,IAAI,OAAO,oBAAoB,EAAE,CACpC,KAAI,IAAI,aAAa,MACnB,wBAAuB,KAAK,IAAI,KAAK;AAKzC,QAAO;EACL,MAAM;EAC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,EAAE,SAAS,CAAC,SAAS,WAAW,YAAY;AACzD,SAAO,WAAW,SAAS,OAAO,UAAU;YACnC,WAAW,SAAS,SAAS;EACtC,IAAI,aAAa,6BACf,WAAW,OACX,MACA,MACA,YACD;EACD,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC,SAAS,WAAW,YAAY;AACjE,SAAO,WAAW,SAAS,OAAO,UAAU;YACnC,WAAW,SAAS,QAAQ;EACrC,IAAI,SAAS,EAAE,MAAM,CAAC,SAAS,WAAW,YAAY;AACtD,SAAO,WAAW,SAAS,OAAO,UAAU;;AAI9C,SAAQ,KACN,8CAA8C,WAAW,QAAQ,UAAU,6BAC5E;CACD,IAAI,SAAS,EAAE,KAAK;AACpB,KAAI,WAAW,YACb,UAAS,OAAO,SAAS,WAAW,YAAY;AAElD,QAAO,WAAW,SAAS,OAAO,UAAU;;AAG9C,SAAgB,iBACd,YACK;AACL,KAAI,CAAC,WAAY,QAAO,EAAE,OAAO,EAAE,CAAC;AAEpC,QAAO,6BADY,6BAA6B,WAAW,EACX,KAAK"}
|
|
1
|
+
{"version":3,"file":"json-schema.mjs","names":[],"sources":["../../src/utils/json-schema.ts"],"sourcesContent":["import type { Parameter } from \"../types\";\n\nexport type JSONSchemaString = {\n type: \"string\";\n description?: string;\n enum?: string[];\n};\n\nexport type JSONSchemaNumber = {\n type: \"number\";\n description?: string;\n};\n\nexport type JSONSchemaBoolean = {\n type: \"boolean\";\n description?: string;\n};\n\nexport type JSONSchemaObject = {\n type: \"object\";\n properties?: Record<string, JSONSchema>;\n required?: string[];\n description?: string;\n};\n\nexport type JSONSchemaArray = {\n type: \"array\";\n items: JSONSchema;\n description?: string;\n};\n\nexport type JSONSchema =\n | JSONSchemaString\n | JSONSchemaNumber\n | JSONSchemaBoolean\n | JSONSchemaObject\n | JSONSchemaArray;\n\nexport function actionParametersToJsonSchema(\n actionParameters: Parameter[],\n): JSONSchema {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of actionParameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of actionParameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n return {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n };\n}\n\n// Convert JSONSchema to Parameter[]\nexport function jsonSchemaToActionParameters(\n jsonSchema: JSONSchema,\n): Parameter[] {\n if (jsonSchema.type !== \"object\" || !jsonSchema.properties) {\n return [];\n }\n\n const parameters: Parameter[] = [];\n const requiredFields = jsonSchema.required || [];\n\n for (const [name, schema] of Object.entries(jsonSchema.properties)) {\n const parameter = convertJsonSchemaToParameter(\n name,\n schema,\n requiredFields.includes(name),\n );\n parameters.push(parameter);\n }\n\n return parameters;\n}\n\n// Convert JSONSchema property to Parameter\nfunction convertJsonSchemaToParameter(\n name: string,\n schema: JSONSchema,\n isRequired: boolean,\n): Parameter {\n const baseParameter: Parameter = {\n name,\n description: schema.description,\n };\n\n if (!isRequired) {\n baseParameter.required = false;\n }\n\n // Handle null-union types like [\"string\", \"null\"] by picking the non-null type\n if (Array.isArray(schema.type)) {\n const types = schema.type as string[];\n const hasNull = types.includes(\"null\");\n const nonNullTypes = types.filter((t: string) => t !== \"null\");\n const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : \"string\";\n return convertJsonSchemaToParameter(\n name,\n { ...schema, type: resolvedType } as JSONSchema,\n hasNull ? false : isRequired,\n );\n }\n\n switch (schema.type) {\n case \"string\":\n return {\n ...baseParameter,\n type: \"string\",\n ...(schema.enum && { enum: schema.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n ...baseParameter,\n type: schema.type,\n };\n case \"object\":\n if (schema.properties) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.required || [];\n\n for (const [propName, propSchema] of Object.entries(\n schema.properties,\n )) {\n attributes.push(\n convertJsonSchemaToParameter(\n propName,\n propSchema,\n requiredFields.includes(propName),\n ),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object\",\n attributes,\n };\n }\n return {\n ...baseParameter,\n type: \"object\",\n };\n case \"array\":\n if (schema.items.type === \"object\" && \"properties\" in schema.items) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.items.required || [];\n\n for (const [propName, propSchema] of Object.entries(\n schema.items.properties || {},\n )) {\n attributes.push(\n convertJsonSchemaToParameter(\n propName,\n propSchema,\n requiredFields.includes(propName),\n ),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object[]\",\n attributes,\n };\n } else if (schema.items.type === \"array\") {\n throw new Error(\"Nested arrays are not supported\");\n } else {\n return {\n ...baseParameter,\n type: `${schema.items.type}[]`,\n };\n }\n default:\n return {\n ...baseParameter,\n type: \"string\",\n };\n }\n}\n\nfunction convertAttribute(attribute: Parameter): JSONSchema {\n switch (attribute.type) {\n case \"string\":\n return {\n type: \"string\",\n description: attribute.description,\n ...(attribute.enum && { enum: attribute.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n type: attribute.type,\n description: attribute.description,\n };\n case \"object\":\n case \"object[]\":\n const properties = attribute.attributes?.reduce(\n (acc, attr) => {\n acc[attr.name] = convertAttribute(attr);\n return acc;\n },\n {} as Record<string, any>,\n );\n const required = attribute.attributes\n ?.filter((attr) => attr.required !== false)\n .map((attr) => attr.name);\n if (attribute.type === \"object[]\") {\n return {\n type: \"array\",\n items: {\n type: \"object\",\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n },\n description: attribute.description,\n };\n }\n return {\n type: \"object\",\n description: attribute.description,\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n };\n default:\n // Handle arrays of primitive types and undefined attribute.type\n if (attribute.type?.endsWith(\"[]\")) {\n const itemType = attribute.type.slice(0, -2);\n return {\n type: \"array\",\n items: { type: itemType as any },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n"],"mappings":";AAsC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3B,OAAI,UAAU,SAAS,WACrB,QAAO;IACL,MAAM;IACN,OAAO;KACL,MAAM;KACN,GAAI,cAAc,EAAE,YAAY;KAChC,GAAI,YAAY,SAAS,SAAS,KAAK,EAAE,UAAU;KACpD;IACD,aAAa,UAAU;IACxB;AAEH,UAAO;IACL,MAAM;IACN,aAAa,UAAU;IACvB,GAAI,cAAc,EAAE,YAAY;IAChC,GAAI,YAAY,SAAS,SAAS,KAAK,EAAE,UAAU;IACpD;EACH;AAEE,OAAI,UAAU,MAAM,SAAS,KAAK,CAEhC,QAAO;IACL,MAAM;IACN,OAAO,EAAE,MAHM,UAAU,KAAK,MAAM,GAAG,GAAG,EAGV;IAChC,aAAa,UAAU;IACxB;AAGH,UAAO;IACL,MAAM;IACN,aAAa,UAAU;IACxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotkit/shared",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
],
|
|
17
17
|
"homepage": "https://github.com/CopilotKit/CopilotKit",
|
|
18
18
|
"license": "MIT",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=20"
|
|
21
|
+
},
|
|
19
22
|
"repository": {
|
|
20
23
|
"type": "git",
|
|
21
24
|
"url": "https://github.com/CopilotKit/CopilotKit.git"
|
|
@@ -32,43 +35,19 @@
|
|
|
32
35
|
"import": "./dist/index.mjs",
|
|
33
36
|
"require": "./dist/index.cjs"
|
|
34
37
|
},
|
|
35
|
-
"./event-transforms": {
|
|
36
|
-
"import": "./dist/event-transforms/index.mjs",
|
|
37
|
-
"require": "./dist/event-transforms/index.cjs"
|
|
38
|
-
},
|
|
39
|
-
"./telemetry": {
|
|
40
|
-
"import": "./dist/telemetry/index.mjs",
|
|
41
|
-
"require": "./dist/telemetry/index.cjs"
|
|
42
|
-
},
|
|
43
38
|
"./package.json": "./package.json"
|
|
44
39
|
},
|
|
45
|
-
"typesVersions": {
|
|
46
|
-
"*": {
|
|
47
|
-
"telemetry": [
|
|
48
|
-
"./dist/telemetry/index.d.cts"
|
|
49
|
-
],
|
|
50
|
-
"event-transforms": [
|
|
51
|
-
"./dist/event-transforms/index.d.cts"
|
|
52
|
-
]
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
40
|
"publishConfig": {
|
|
56
41
|
"access": "public"
|
|
57
42
|
},
|
|
58
43
|
"dependencies": {
|
|
59
|
-
"@ag-ui/a2ui-middleware": "0.0.10",
|
|
60
44
|
"@ag-ui/client": "1.0.2",
|
|
61
45
|
"@copilotkit/license-verifier": "~0.5.0",
|
|
62
|
-
"@segment/analytics-node": "^2.1.2",
|
|
63
46
|
"@standard-schema/spec": "^1.0.0",
|
|
64
|
-
"
|
|
65
|
-
"partial-json": "^0.1.7",
|
|
66
|
-
"rxjs": "7.8.1",
|
|
67
|
-
"zod": "^3.23.3"
|
|
47
|
+
"partial-json": "^0.1.7"
|
|
68
48
|
},
|
|
69
49
|
"devDependencies": {
|
|
70
50
|
"@ag-ui/core": "1.0.2",
|
|
71
|
-
"@types/clarinet": "^0.12.3",
|
|
72
51
|
"@valibot/to-json-schema": "^1.5.0",
|
|
73
52
|
"arktype": "^2.1.29",
|
|
74
53
|
"eslint": "^8.56.0",
|
|
@@ -76,11 +55,11 @@
|
|
|
76
55
|
"typescript": "^5.2.3",
|
|
77
56
|
"valibot": "^1.2.0",
|
|
78
57
|
"vitest": "^3.2.4",
|
|
79
|
-
"zod
|
|
58
|
+
"zod": "^4.2.0",
|
|
80
59
|
"tsconfig": "1.4.12"
|
|
81
60
|
},
|
|
82
61
|
"peerDependencies": {
|
|
83
|
-
"@ag-ui/core": "
|
|
62
|
+
"@ag-ui/core": "^1.0.2"
|
|
84
63
|
},
|
|
85
64
|
"scripts": {
|
|
86
65
|
"build": "tsdown",
|
|
@@ -80,12 +80,10 @@ describe("root entry browser safety (#4151)", () => {
|
|
|
80
80
|
expect(offenders).toEqual([]);
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
it("
|
|
84
|
-
// Guards the test itself: the walker has to be able to see the
|
|
85
|
-
// asserting the absence of above.
|
|
86
|
-
const reachable = collectRuntimeDependencies(
|
|
87
|
-
|
|
88
|
-
);
|
|
89
|
-
expect(reachable).toContain("@segment/analytics-node");
|
|
83
|
+
it("sees value imports of bare packages", () => {
|
|
84
|
+
// Guards the test itself: the walker has to be able to see the kind of
|
|
85
|
+
// edge it is asserting the absence of above.
|
|
86
|
+
const reachable = collectRuntimeDependencies(join(SRC, "index.ts"));
|
|
87
|
+
expect(reachable).toContain("partial-json");
|
|
90
88
|
});
|
|
91
89
|
});
|
|
@@ -3,26 +3,26 @@ import { z } from "zod";
|
|
|
3
3
|
import * as v from "valibot";
|
|
4
4
|
import { toStandardJsonSchema } from "@valibot/to-json-schema";
|
|
5
5
|
import { type } from "arktype";
|
|
6
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
7
6
|
import { schemaToJsonSchema, ɵanySchema } from "../standard-schema";
|
|
8
7
|
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
9
8
|
|
|
10
9
|
describe("schemaToJsonSchema", () => {
|
|
11
|
-
describe("Zod schemas (
|
|
10
|
+
describe("Zod 4 schemas (native ~standard.jsonSchema)", () => {
|
|
12
11
|
it("converts a simple zod object schema", () => {
|
|
13
12
|
const schema = z.object({
|
|
14
|
-
name: z.string(),
|
|
13
|
+
name: z.string().describe("Full name"),
|
|
15
14
|
age: z.number(),
|
|
16
15
|
});
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
expect(schemaToJsonSchema(schema)).toEqual({
|
|
18
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
19
|
+
type: "object",
|
|
20
|
+
properties: {
|
|
21
|
+
name: { type: "string", description: "Full name" },
|
|
22
|
+
age: { type: "number" },
|
|
23
|
+
},
|
|
24
|
+
required: ["name", "age"],
|
|
25
|
+
});
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
it("converts a zod schema with optional fields", () => {
|
|
@@ -31,12 +31,27 @@ describe("schemaToJsonSchema", () => {
|
|
|
31
31
|
units: z.enum(["celsius", "fahrenheit"]).optional(),
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
const result = schemaToJsonSchema(schema
|
|
34
|
+
const result = schemaToJsonSchema(schema);
|
|
35
35
|
|
|
36
36
|
expect(result).toHaveProperty("type", "object");
|
|
37
37
|
expect(result).toHaveProperty("properties.city.type", "string");
|
|
38
|
-
expect(result
|
|
39
|
-
|
|
38
|
+
expect(result).toHaveProperty("properties.units.enum", [
|
|
39
|
+
"celsius",
|
|
40
|
+
"fahrenheit",
|
|
41
|
+
]);
|
|
42
|
+
expect(result.required).toEqual(["city"]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("describes the input side, so fields with defaults are optional", () => {
|
|
46
|
+
const schema = z.object({
|
|
47
|
+
query: z.string(),
|
|
48
|
+
page: z.number().default(1),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const result = schemaToJsonSchema(schema);
|
|
52
|
+
|
|
53
|
+
expect(result.required).toEqual(["query"]);
|
|
54
|
+
expect(result).toHaveProperty("properties.page.default", 1);
|
|
40
55
|
});
|
|
41
56
|
|
|
42
57
|
it("has vendor 'zod' on ~standard", () => {
|
|
@@ -131,10 +146,9 @@ describe("schemaToJsonSchema", () => {
|
|
|
131
146
|
expect(result.required).toContain("age");
|
|
132
147
|
});
|
|
133
148
|
|
|
134
|
-
it("converts
|
|
149
|
+
it("converts a single-field arktype schema", () => {
|
|
135
150
|
const schema = type({ query: "string" });
|
|
136
151
|
|
|
137
|
-
// No zodToJsonSchema option needed — arktype uses Standard JSON Schema V1 natively
|
|
138
152
|
const result = schemaToJsonSchema(schema);
|
|
139
153
|
|
|
140
154
|
expect(result).toHaveProperty("type", "object");
|
|
@@ -179,38 +193,9 @@ describe("schemaToJsonSchema", () => {
|
|
|
179
193
|
$target: "draft-07",
|
|
180
194
|
});
|
|
181
195
|
});
|
|
182
|
-
|
|
183
|
-
it("prefers ~standard.jsonSchema over zodToJsonSchema fallback", () => {
|
|
184
|
-
const mockSchema = {
|
|
185
|
-
"~standard": {
|
|
186
|
-
version: 1,
|
|
187
|
-
vendor: "zod",
|
|
188
|
-
validate: (value: unknown) => ({ value }),
|
|
189
|
-
jsonSchema: {
|
|
190
|
-
input: () => ({
|
|
191
|
-
type: "object",
|
|
192
|
-
properties: { fromJsonSchema: { type: "boolean" } },
|
|
193
|
-
}),
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
const zodFallback = () => ({
|
|
199
|
-
type: "object",
|
|
200
|
-
properties: { fromZodFallback: { type: "boolean" } },
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
const result = schemaToJsonSchema(mockSchema, {
|
|
204
|
-
zodToJsonSchema: zodFallback,
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
// Should use ~standard.jsonSchema, not the zod fallback
|
|
208
|
-
expect(result).toHaveProperty("properties.fromJsonSchema");
|
|
209
|
-
expect(result).not.toHaveProperty("properties.fromZodFallback");
|
|
210
|
-
});
|
|
211
196
|
});
|
|
212
197
|
|
|
213
|
-
describe("
|
|
198
|
+
describe("schemas exposing a toJSONSchema() method", () => {
|
|
214
199
|
it("calls toJSONSchema() when the method exists on the schema", () => {
|
|
215
200
|
const expectedOutput = {
|
|
216
201
|
type: "object",
|
|
@@ -231,7 +216,7 @@ describe("schemaToJsonSchema", () => {
|
|
|
231
216
|
expect(result).toEqual(expectedOutput);
|
|
232
217
|
});
|
|
233
218
|
|
|
234
|
-
it("uses toJSONSchema()
|
|
219
|
+
it("uses toJSONSchema() with no options", () => {
|
|
235
220
|
const mockZod4Schema: StandardSchemaV1 = {
|
|
236
221
|
"~standard": {
|
|
237
222
|
version: 1,
|
|
@@ -249,32 +234,6 @@ describe("schemaToJsonSchema", () => {
|
|
|
249
234
|
expect(result).toHaveProperty("properties.city.type", "string");
|
|
250
235
|
});
|
|
251
236
|
|
|
252
|
-
it("prefers toJSONSchema() over zodToJsonSchema fallback for Zod v4", () => {
|
|
253
|
-
const mockZod4Schema: StandardSchemaV1 = {
|
|
254
|
-
"~standard": {
|
|
255
|
-
version: 1,
|
|
256
|
-
vendor: "zod",
|
|
257
|
-
validate: (value: unknown) => ({ value }),
|
|
258
|
-
},
|
|
259
|
-
toJSONSchema: () => ({
|
|
260
|
-
type: "object",
|
|
261
|
-
properties: { fromNative: { type: "boolean" } },
|
|
262
|
-
}),
|
|
263
|
-
} as any;
|
|
264
|
-
|
|
265
|
-
const zodFallback = () => ({
|
|
266
|
-
type: "object",
|
|
267
|
-
properties: { fromFallback: { type: "boolean" } },
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
const result = schemaToJsonSchema(mockZod4Schema, {
|
|
271
|
-
zodToJsonSchema: zodFallback,
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
expect(result).toHaveProperty("properties.fromNative");
|
|
275
|
-
expect(result).not.toHaveProperty("properties.fromFallback");
|
|
276
|
-
});
|
|
277
|
-
|
|
278
237
|
it("prefers ~standard.jsonSchema over toJSONSchema()", () => {
|
|
279
238
|
const mockSchema = {
|
|
280
239
|
"~standard": {
|
|
@@ -303,7 +262,7 @@ describe("schemaToJsonSchema", () => {
|
|
|
303
262
|
});
|
|
304
263
|
|
|
305
264
|
describe("Error handling", () => {
|
|
306
|
-
it("throws when schema has no jsonSchema support
|
|
265
|
+
it("throws when schema has no jsonSchema support", () => {
|
|
307
266
|
const mockSchema: StandardSchemaV1 = {
|
|
308
267
|
"~standard": {
|
|
309
268
|
version: 1,
|
|
@@ -318,22 +277,10 @@ describe("schemaToJsonSchema", () => {
|
|
|
318
277
|
expect(() => schemaToJsonSchema(mockSchema)).toThrow(/unknown-lib/);
|
|
319
278
|
});
|
|
320
279
|
|
|
321
|
-
it("
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
vendor: "some-other-lib",
|
|
326
|
-
validate: (value: unknown) => ({ value }),
|
|
327
|
-
},
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
expect(() => schemaToJsonSchema(mockSchema)).toThrow(
|
|
331
|
-
/no zodToJsonSchema fallback/,
|
|
332
|
-
);
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
it("uses zodToJsonSchema fallback for zod vendor schemas", () => {
|
|
336
|
-
const mockZodSchema: StandardSchemaV1 = {
|
|
280
|
+
it("rejects a Zod 3 schema and names the supported Zod version", () => {
|
|
281
|
+
// Zod 3 implements Standard Schema validation only: no
|
|
282
|
+
// `~standard.jsonSchema` and no `toJSONSchema()` method.
|
|
283
|
+
const zod3Like: StandardSchemaV1 = {
|
|
337
284
|
"~standard": {
|
|
338
285
|
version: 1,
|
|
339
286
|
vendor: "zod",
|
|
@@ -341,19 +288,7 @@ describe("schemaToJsonSchema", () => {
|
|
|
341
288
|
},
|
|
342
289
|
};
|
|
343
290
|
|
|
344
|
-
|
|
345
|
-
type: "object",
|
|
346
|
-
properties: { test: { type: "string" } },
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
const result = schemaToJsonSchema(mockZodSchema, {
|
|
350
|
-
zodToJsonSchema: fallback,
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
expect(result).toEqual({
|
|
354
|
-
type: "object",
|
|
355
|
-
properties: { test: { type: "string" } },
|
|
356
|
-
});
|
|
291
|
+
expect(() => schemaToJsonSchema(zod3Like)).toThrow(/Zod 4\.2\+/);
|
|
357
292
|
});
|
|
358
293
|
});
|
|
359
294
|
});
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
export * from "./types";
|
|
2
2
|
export * from "./utils";
|
|
3
3
|
export * from "./constants";
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// Node
|
|
7
|
-
// resolve the whole module graph before they tree-shake, so re-exporting
|
|
8
|
-
// that module here made every browser build of a dependent package print
|
|
9
|
-
// "Module ... has been externalized for browser compatibility" warnings,
|
|
10
|
-
// even when the consumer never touched telemetry (#4151). Only the
|
|
11
|
-
// browser-safe telemetry surface is re-exported from this entry. Server
|
|
12
|
-
// code that needs the client imports it from `@copilotkit/shared/telemetry`.
|
|
13
|
-
// This mirrors the license-verifier note below.
|
|
4
|
+
// Only browser-safe telemetry helpers live here. The runtime owns its
|
|
5
|
+
// telemetry client (`packages/runtime/src/runtime/telemetry`), so this package
|
|
6
|
+
// imports no Node-only analytics SDK (#4151).
|
|
14
7
|
export { isTelemetryDisabled } from "./telemetry/telemetry-disabled";
|
|
15
8
|
export * from "./telemetry/sampling";
|
|
16
9
|
// Pure string classification with no imports, so it carries no runtime edge
|
|
@@ -23,12 +16,6 @@ export {
|
|
|
23
16
|
parseAndWarnTelemetryId,
|
|
24
17
|
} from "./telemetry/lambda-client";
|
|
25
18
|
export type { LambdaSendOptions } from "./telemetry/lambda-client";
|
|
26
|
-
// Types only: erased at build time, so they add no runtime edge to
|
|
27
|
-
// `telemetry-client.ts` and therefore none to @segment/analytics-node.
|
|
28
|
-
export type {
|
|
29
|
-
TelemetryCapture,
|
|
30
|
-
TelemetryIdentity,
|
|
31
|
-
} from "./telemetry/telemetry-client";
|
|
32
19
|
export * from "./debug";
|
|
33
20
|
export * from "./standard-schema";
|
|
34
21
|
export * from "./attachments";
|
package/src/standard-schema.ts
CHANGED
|
@@ -27,18 +27,6 @@ export const ɵanySchema: StandardSchemaV1<unknown, unknown> = {
|
|
|
27
27
|
export type InferSchemaOutput<S> =
|
|
28
28
|
S extends StandardSchemaV1<any, infer O> ? O : never;
|
|
29
29
|
|
|
30
|
-
export interface SchemaToJsonSchemaOptions {
|
|
31
|
-
/**
|
|
32
|
-
* Injected `zodToJsonSchema` function so that `shared` does not depend on
|
|
33
|
-
* `zod-to-json-schema`. Required when the schema is a Zod v3 schema that
|
|
34
|
-
* does not implement Standard JSON Schema V1.
|
|
35
|
-
*/
|
|
36
|
-
zodToJsonSchema?: (
|
|
37
|
-
schema: unknown,
|
|
38
|
-
options?: { $refStrategy?: string },
|
|
39
|
-
) => Record<string, unknown>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
30
|
/**
|
|
43
31
|
* Check whether a schema implements the Standard JSON Schema V1 protocol.
|
|
44
32
|
*/
|
|
@@ -63,35 +51,29 @@ function hasStandardJsonSchema(
|
|
|
63
51
|
* Strategy:
|
|
64
52
|
* 1. If the schema implements Standard JSON Schema V1 (`~standard.jsonSchema`),
|
|
65
53
|
* call `schema['~standard'].jsonSchema.input({ target: 'draft-07' })`.
|
|
66
|
-
* 2
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
54
|
+
* Zod 4.2+, ArkType 2.1.28+ and Valibot (via `toStandardJsonSchema`) do.
|
|
55
|
+
* 2. If the schema exposes a `toJSONSchema()` method, call it directly.
|
|
56
|
+
* 3. Otherwise throw a descriptive error. Zod 3 schemas land here: they
|
|
57
|
+
* implement Standard Schema validation but cannot describe themselves as
|
|
58
|
+
* JSON Schema.
|
|
70
59
|
*/
|
|
71
60
|
export function schemaToJsonSchema(
|
|
72
61
|
schema: StandardSchemaV1,
|
|
73
|
-
options?: SchemaToJsonSchemaOptions,
|
|
74
62
|
): Record<string, unknown> {
|
|
75
63
|
// 1. Standard JSON Schema V1
|
|
76
64
|
if (hasStandardJsonSchema(schema)) {
|
|
77
65
|
return schema["~standard"].jsonSchema.input({ target: "draft-07" });
|
|
78
66
|
}
|
|
79
67
|
|
|
80
|
-
// 2.
|
|
68
|
+
// 2. Native toJSONSchema() method
|
|
81
69
|
if (typeof (schema as any).toJSONSchema === "function") {
|
|
82
70
|
return (schema as any).toJSONSchema() as Record<string, unknown>;
|
|
83
71
|
}
|
|
84
72
|
|
|
85
|
-
// 3. Zod v3 fallback
|
|
86
73
|
const vendor = schema["~standard"].vendor;
|
|
87
|
-
if (vendor === "zod" && options?.zodToJsonSchema) {
|
|
88
|
-
return options.zodToJsonSchema(schema, { $refStrategy: "none" });
|
|
89
|
-
}
|
|
90
|
-
|
|
91
74
|
throw new Error(
|
|
92
|
-
`Cannot convert schema to JSON Schema. The schema (vendor: "${vendor}") does not implement Standard JSON Schema V1 ` +
|
|
93
|
-
`
|
|
94
|
-
`
|
|
95
|
-
`or pass a zodToJsonSchema function in options.`,
|
|
75
|
+
`Cannot convert schema to JSON Schema. The schema (vendor: "${vendor}") does not implement Standard JSON Schema V1. ` +
|
|
76
|
+
`Use a library that does: Zod 4.2+ (Zod 3 is not supported), Valibot v1+ wrapped with ` +
|
|
77
|
+
`toStandardJsonSchema() from @valibot/to-json-schema, or ArkType v2.1.28+.`,
|
|
96
78
|
);
|
|
97
79
|
}
|
|
@@ -5,11 +5,6 @@ import { processEnv } from "../utils/process-env";
|
|
|
5
5
|
* Users can opt out by setting:
|
|
6
6
|
* - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1
|
|
7
7
|
* - DO_NOT_TRACK=true or DO_NOT_TRACK=1
|
|
8
|
-
*
|
|
9
|
-
* Lives in its own module so that the browser-facing root entry can
|
|
10
|
-
* re-export it without pulling in `telemetry-client.ts`, whose
|
|
11
|
-
* `@segment/analytics-node` import drags Node built-ins into browser
|
|
12
|
-
* bundler module graphs. See the note in `../index.ts`.
|
|
13
8
|
*/
|
|
14
9
|
export function isTelemetryDisabled(): boolean {
|
|
15
10
|
const env = processEnv();
|