@copilotkit/shared 0.0.0-feat-dynamic-copilotcloud-qa-20250117190454
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/CHANGELOG.md +978 -0
- package/README.md +46 -0
- package/dist/chunk-6QGXWNS5.mjs +34 -0
- package/dist/chunk-6QGXWNS5.mjs.map +1 -0
- package/dist/chunk-BANDZXMP.mjs +1 -0
- package/dist/chunk-BANDZXMP.mjs.map +1 -0
- package/dist/chunk-CYDWEPFL.mjs +1 -0
- package/dist/chunk-CYDWEPFL.mjs.map +1 -0
- package/dist/chunk-FCCOSO5L.mjs +1 -0
- package/dist/chunk-FCCOSO5L.mjs.map +1 -0
- package/dist/chunk-GYZIHHE6.mjs +13 -0
- package/dist/chunk-GYZIHHE6.mjs.map +1 -0
- package/dist/chunk-IAFBVORQ.mjs +1 -0
- package/dist/chunk-IAFBVORQ.mjs.map +1 -0
- package/dist/chunk-JP2M4U4G.mjs +112 -0
- package/dist/chunk-JP2M4U4G.mjs.map +1 -0
- package/dist/chunk-MSUB6DGR.mjs +1 -0
- package/dist/chunk-MSUB6DGR.mjs.map +1 -0
- package/dist/chunk-NAFEBKSO.mjs +1 -0
- package/dist/chunk-NAFEBKSO.mjs.map +1 -0
- package/dist/chunk-P7STFMPO.mjs +1 -0
- package/dist/chunk-P7STFMPO.mjs.map +1 -0
- package/dist/chunk-QFITLWYZ.mjs +96 -0
- package/dist/chunk-QFITLWYZ.mjs.map +1 -0
- package/dist/chunk-RIPX6APP.mjs +10 -0
- package/dist/chunk-RIPX6APP.mjs.map +1 -0
- package/dist/constants/index.d.ts +6 -0
- package/dist/constants/index.js +40 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/index.mjs +13 -0
- package/dist/constants/index.mjs.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +285 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +42 -0
- package/dist/index.mjs.map +1 -0
- package/dist/telemetry/events.d.ts +39 -0
- package/dist/telemetry/events.js +19 -0
- package/dist/telemetry/events.js.map +1 -0
- package/dist/telemetry/events.mjs +1 -0
- package/dist/telemetry/events.mjs.map +1 -0
- package/dist/telemetry/index.d.ts +3 -0
- package/dist/telemetry/index.js +144 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/index.mjs +9 -0
- package/dist/telemetry/index.mjs.map +1 -0
- package/dist/telemetry/security-check.d.ts +2 -0
- package/dist/telemetry/security-check.js +2 -0
- package/dist/telemetry/security-check.js.map +1 -0
- package/dist/telemetry/security-check.mjs +1 -0
- package/dist/telemetry/security-check.mjs.map +1 -0
- package/dist/telemetry/telemetry-client.d.ts +33 -0
- package/dist/telemetry/telemetry-client.js +142 -0
- package/dist/telemetry/telemetry-client.js.map +1 -0
- package/dist/telemetry/telemetry-client.mjs +8 -0
- package/dist/telemetry/telemetry-client.mjs.map +1 -0
- package/dist/telemetry/utils.d.ts +8 -0
- package/dist/telemetry/utils.js +69 -0
- package/dist/telemetry/utils.js.map +1 -0
- package/dist/telemetry/utils.mjs +9 -0
- package/dist/telemetry/utils.mjs.map +1 -0
- package/dist/types/action.d.ts +58 -0
- package/dist/types/action.js +19 -0
- package/dist/types/action.js.map +1 -0
- package/dist/types/action.mjs +2 -0
- package/dist/types/action.mjs.map +1 -0
- package/dist/types/copilot-cloud-config.d.ts +13 -0
- package/dist/types/copilot-cloud-config.js +19 -0
- package/dist/types/copilot-cloud-config.js.map +1 -0
- package/dist/types/copilot-cloud-config.mjs +2 -0
- package/dist/types/copilot-cloud-config.mjs.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +6 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/openai-assistant.d.ts +53 -0
- package/dist/types/openai-assistant.js +19 -0
- package/dist/types/openai-assistant.js.map +1 -0
- package/dist/types/openai-assistant.mjs +2 -0
- package/dist/types/openai-assistant.mjs.map +1 -0
- package/dist/types/utility.d.ts +3 -0
- package/dist/types/utility.js +19 -0
- package/dist/types/utility.js.map +1 -0
- package/dist/types/utility.mjs +2 -0
- package/dist/types/utility.mjs.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +147 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +14 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils/json-schema.d.ts +32 -0
- package/dist/utils/json-schema.js +137 -0
- package/dist/utils/json-schema.js.map +1 -0
- package/dist/utils/json-schema.mjs +9 -0
- package/dist/utils/json-schema.mjs.map +1 -0
- package/dist/utils/json-schema.test.d.ts +2 -0
- package/dist/utils/json-schema.test.js +173 -0
- package/dist/utils/json-schema.test.js.map +1 -0
- package/dist/utils/json-schema.test.mjs +140 -0
- package/dist/utils/json-schema.test.mjs.map +1 -0
- package/dist/utils/random-id.d.ts +3 -0
- package/dist/utils/random-id.js +34 -0
- package/dist/utils/random-id.js.map +1 -0
- package/dist/utils/random-id.mjs +7 -0
- package/dist/utils/random-id.mjs.map +1 -0
- package/jest.config.js +5 -0
- package/package.json +64 -0
- package/src/constants/index.ts +4 -0
- package/src/index.ts +7 -0
- package/src/telemetry/events.ts +35 -0
- package/src/telemetry/index.ts +1 -0
- package/src/telemetry/security-check.ts +0 -0
- package/src/telemetry/telemetry-client.ts +126 -0
- package/src/telemetry/utils.ts +39 -0
- package/src/types/action.ts +128 -0
- package/src/types/copilot-cloud-config.ts +11 -0
- package/src/types/index.ts +4 -0
- package/src/types/openai-assistant.ts +62 -0
- package/src/types/utility.ts +1 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/json-schema.test.ts +169 -0
- package/src/utils/json-schema.ts +154 -0
- package/src/utils/random-id.ts +5 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +16 -0
- package/typedoc.json +4 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export interface FunctionDefinition {
|
|
2
|
+
/**
|
|
3
|
+
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
|
|
4
|
+
* underscores and dashes, with a maximum length of 64.
|
|
5
|
+
*/
|
|
6
|
+
name: string;
|
|
7
|
+
/**
|
|
8
|
+
* The parameters the functions accepts, described as a JSON Schema object. See the
|
|
9
|
+
* [guide](/docs/guides/gpt/function-calling) for examples, and the
|
|
10
|
+
* [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
|
|
11
|
+
* documentation about the format.
|
|
12
|
+
*
|
|
13
|
+
* To describe a function that accepts no parameters, provide the value
|
|
14
|
+
* `{"type": "object", "properties": {}}`.
|
|
15
|
+
*/
|
|
16
|
+
parameters: Record<string, unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* A description of what the function does, used by the model to choose when and
|
|
19
|
+
* how to call the function.
|
|
20
|
+
*/
|
|
21
|
+
description?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ToolDefinition {
|
|
25
|
+
type: "function";
|
|
26
|
+
function: FunctionDefinition;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface FunctionCallHandlerArguments {
|
|
30
|
+
messages: any[];
|
|
31
|
+
name: string;
|
|
32
|
+
args: any;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type FunctionCallHandler = (args: FunctionCallHandlerArguments) => Promise<any>;
|
|
36
|
+
|
|
37
|
+
export type CoAgentStateRenderHandlerArguments = {
|
|
38
|
+
name: string;
|
|
39
|
+
nodeName: string;
|
|
40
|
+
state: any;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type CoAgentStateRenderHandler = (args: CoAgentStateRenderHandlerArguments) => Promise<any>;
|
|
44
|
+
|
|
45
|
+
export type AssistantMessage = {
|
|
46
|
+
id: string;
|
|
47
|
+
role: "assistant";
|
|
48
|
+
content: Array<{
|
|
49
|
+
type: "text";
|
|
50
|
+
text: {
|
|
51
|
+
value: string;
|
|
52
|
+
};
|
|
53
|
+
}>;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type JSONValue =
|
|
57
|
+
| null
|
|
58
|
+
| string
|
|
59
|
+
| number
|
|
60
|
+
| boolean
|
|
61
|
+
| { [x: string]: JSONValue }
|
|
62
|
+
| Array<JSONValue>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { convertJsonSchemaToZodSchema } from "../utils/json-schema";
|
|
3
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
4
|
+
|
|
5
|
+
describe("convertJsonSchemaToZodSchema", () => {
|
|
6
|
+
it("should convert a simple JSON schema to a Zod schema", () => {
|
|
7
|
+
const jsonSchema = {
|
|
8
|
+
type: "object",
|
|
9
|
+
properties: {
|
|
10
|
+
name: { type: "string" },
|
|
11
|
+
age: { type: "number" },
|
|
12
|
+
},
|
|
13
|
+
required: ["name", "age"],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const expectedSchema = z.object({
|
|
17
|
+
name: z.string(),
|
|
18
|
+
age: z.number(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
22
|
+
const resultSchemaJson = zodToJsonSchema(result);
|
|
23
|
+
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
24
|
+
|
|
25
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should convert a JSON schema with nested objects to a Zod schema", () => {
|
|
29
|
+
const jsonSchema = {
|
|
30
|
+
type: "object",
|
|
31
|
+
properties: {
|
|
32
|
+
name: { type: "string" },
|
|
33
|
+
address: {
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: {
|
|
36
|
+
street: { type: "string" },
|
|
37
|
+
city: { type: "string" },
|
|
38
|
+
},
|
|
39
|
+
required: ["street", "city"],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
required: ["name", "address"],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const expectedSchema = z.object({
|
|
46
|
+
name: z.string(),
|
|
47
|
+
address: z.object({
|
|
48
|
+
street: z.string(),
|
|
49
|
+
city: z.string(),
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
54
|
+
const resultSchemaJson = zodToJsonSchema(result);
|
|
55
|
+
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
56
|
+
|
|
57
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should convert a JSON schema with arrays to a Zod schema", () => {
|
|
61
|
+
const jsonSchema = {
|
|
62
|
+
type: "object",
|
|
63
|
+
properties: {
|
|
64
|
+
names: {
|
|
65
|
+
type: "array",
|
|
66
|
+
items: { type: "string" },
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
required: ["names"],
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const expectedSchema = z.object({
|
|
73
|
+
names: z.array(z.string()),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
77
|
+
const resultSchemaJson = zodToJsonSchema(result);
|
|
78
|
+
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
79
|
+
|
|
80
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should convert a JSON schema with optional properties to a Zod schema", () => {
|
|
84
|
+
const jsonSchema = {
|
|
85
|
+
type: "object",
|
|
86
|
+
properties: {
|
|
87
|
+
name: { type: "string" },
|
|
88
|
+
age: { type: "number", required: false },
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const expectedSchema = z
|
|
93
|
+
.object({
|
|
94
|
+
name: z.string().optional(),
|
|
95
|
+
age: z.number().optional(),
|
|
96
|
+
})
|
|
97
|
+
.optional();
|
|
98
|
+
|
|
99
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, false);
|
|
100
|
+
|
|
101
|
+
console.log(convertJsonSchemaToZodSchema(jsonSchema, false));
|
|
102
|
+
|
|
103
|
+
const resultSchemaJson = zodToJsonSchema(result);
|
|
104
|
+
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
105
|
+
|
|
106
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("should convert a JSON schema with different types to a Zod schema", () => {
|
|
110
|
+
const jsonSchema = {
|
|
111
|
+
type: "object",
|
|
112
|
+
properties: {
|
|
113
|
+
name: { type: "string" },
|
|
114
|
+
age: { type: "number" },
|
|
115
|
+
isAdmin: { type: "boolean" },
|
|
116
|
+
},
|
|
117
|
+
required: ["name", "age", "isAdmin"],
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const expectedSchema = z.object({
|
|
121
|
+
name: z.string(),
|
|
122
|
+
age: z.number(),
|
|
123
|
+
isAdmin: z.boolean(),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
127
|
+
const resultSchemaJson = zodToJsonSchema(result);
|
|
128
|
+
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
129
|
+
|
|
130
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("should handle edge case where JSON schema has no properties", () => {
|
|
134
|
+
const jsonSchema = {
|
|
135
|
+
type: "object",
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const expectedSchema = z.object({});
|
|
139
|
+
|
|
140
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
141
|
+
const resultSchemaJson = zodToJsonSchema(result);
|
|
142
|
+
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
143
|
+
|
|
144
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("should handle edge case where JSON schema has no required properties", () => {
|
|
148
|
+
const jsonSchema = {
|
|
149
|
+
type: "object",
|
|
150
|
+
properties: {
|
|
151
|
+
name: { type: "string" },
|
|
152
|
+
age: { type: "number" },
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const expectedSchema = z
|
|
157
|
+
.object({
|
|
158
|
+
name: z.string().optional(),
|
|
159
|
+
age: z.number().optional(),
|
|
160
|
+
})
|
|
161
|
+
.optional();
|
|
162
|
+
|
|
163
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, false);
|
|
164
|
+
const resultSchemaJson = zodToJsonSchema(result);
|
|
165
|
+
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
166
|
+
|
|
167
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Parameter } from "../types";
|
|
3
|
+
|
|
4
|
+
export type JSONSchemaString = {
|
|
5
|
+
type: "string";
|
|
6
|
+
description?: string;
|
|
7
|
+
enum?: string[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type JSONSchemaNumber = {
|
|
11
|
+
type: "number";
|
|
12
|
+
description?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type JSONSchemaBoolean = {
|
|
16
|
+
type: "boolean";
|
|
17
|
+
description?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type JSONSchemaObject = {
|
|
21
|
+
type: "object";
|
|
22
|
+
properties?: Record<string, JSONSchema>;
|
|
23
|
+
required?: string[];
|
|
24
|
+
description?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type JSONSchemaArray = {
|
|
28
|
+
type: "array";
|
|
29
|
+
items: JSONSchema;
|
|
30
|
+
description?: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type JSONSchema =
|
|
34
|
+
| JSONSchemaString
|
|
35
|
+
| JSONSchemaNumber
|
|
36
|
+
| JSONSchemaBoolean
|
|
37
|
+
| JSONSchemaObject
|
|
38
|
+
| JSONSchemaArray;
|
|
39
|
+
|
|
40
|
+
export function actionParametersToJsonSchema(actionParameters: Parameter[]): JSONSchema {
|
|
41
|
+
// Create the parameters object based on the argumentAnnotations
|
|
42
|
+
let parameters: { [key: string]: any } = {};
|
|
43
|
+
for (let parameter of actionParameters || []) {
|
|
44
|
+
parameters[parameter.name] = convertAttribute(parameter);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let requiredParameterNames: string[] = [];
|
|
48
|
+
for (let arg of actionParameters || []) {
|
|
49
|
+
if (arg.required !== false) {
|
|
50
|
+
requiredParameterNames.push(arg.name);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Create the ChatCompletionFunctions object
|
|
55
|
+
return {
|
|
56
|
+
type: "object",
|
|
57
|
+
properties: parameters,
|
|
58
|
+
required: requiredParameterNames,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function convertAttribute(attribute: Parameter): JSONSchema {
|
|
63
|
+
switch (attribute.type) {
|
|
64
|
+
case "string":
|
|
65
|
+
return {
|
|
66
|
+
type: "string",
|
|
67
|
+
description: attribute.description,
|
|
68
|
+
...(attribute.enum && { enum: attribute.enum }),
|
|
69
|
+
};
|
|
70
|
+
case "number":
|
|
71
|
+
case "boolean":
|
|
72
|
+
return {
|
|
73
|
+
type: attribute.type,
|
|
74
|
+
description: attribute.description,
|
|
75
|
+
};
|
|
76
|
+
case "object":
|
|
77
|
+
case "object[]":
|
|
78
|
+
const properties = attribute.attributes?.reduce(
|
|
79
|
+
(acc, attr) => {
|
|
80
|
+
acc[attr.name] = convertAttribute(attr);
|
|
81
|
+
return acc;
|
|
82
|
+
},
|
|
83
|
+
{} as Record<string, any>,
|
|
84
|
+
);
|
|
85
|
+
const required = attribute.attributes
|
|
86
|
+
?.filter((attr) => attr.required !== false)
|
|
87
|
+
.map((attr) => attr.name);
|
|
88
|
+
if (attribute.type === "object[]") {
|
|
89
|
+
return {
|
|
90
|
+
type: "array",
|
|
91
|
+
items: {
|
|
92
|
+
type: "object",
|
|
93
|
+
...(properties && { properties }),
|
|
94
|
+
...(required && required.length > 0 && { required }),
|
|
95
|
+
},
|
|
96
|
+
description: attribute.description,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
type: "object",
|
|
101
|
+
description: attribute.description,
|
|
102
|
+
...(properties && { properties }),
|
|
103
|
+
...(required && required.length > 0 && { required }),
|
|
104
|
+
};
|
|
105
|
+
default:
|
|
106
|
+
// Handle arrays of primitive types and undefined attribute.type
|
|
107
|
+
if (attribute.type?.endsWith("[]")) {
|
|
108
|
+
const itemType = attribute.type.slice(0, -2);
|
|
109
|
+
return {
|
|
110
|
+
type: "array",
|
|
111
|
+
items: { type: itemType as any },
|
|
112
|
+
description: attribute.description,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// Fallback for undefined type or any other unexpected type
|
|
116
|
+
return {
|
|
117
|
+
type: "string",
|
|
118
|
+
description: attribute.description,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function convertJsonSchemaToZodSchema(jsonSchema: any, required: boolean): z.ZodSchema {
|
|
124
|
+
if (jsonSchema.type === "object") {
|
|
125
|
+
const spec: { [key: string]: z.ZodSchema } = {};
|
|
126
|
+
|
|
127
|
+
if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
|
|
128
|
+
return !required ? z.object(spec).optional() : z.object(spec);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
132
|
+
spec[key] = convertJsonSchemaToZodSchema(
|
|
133
|
+
value,
|
|
134
|
+
jsonSchema.required ? jsonSchema.required.includes(key) : false,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
let schema = z.object(spec).describe(jsonSchema.description);
|
|
138
|
+
return required ? schema : schema.optional();
|
|
139
|
+
} else if (jsonSchema.type === "string") {
|
|
140
|
+
let schema = z.string().describe(jsonSchema.description);
|
|
141
|
+
return required ? schema : schema.optional();
|
|
142
|
+
} else if (jsonSchema.type === "number") {
|
|
143
|
+
let schema = z.number().describe(jsonSchema.description);
|
|
144
|
+
return required ? schema : schema.optional();
|
|
145
|
+
} else if (jsonSchema.type === "boolean") {
|
|
146
|
+
let schema = z.boolean().describe(jsonSchema.description);
|
|
147
|
+
return required ? schema : schema.optional();
|
|
148
|
+
} else if (jsonSchema.type === "array") {
|
|
149
|
+
let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
|
|
150
|
+
let schema = z.array(itemSchema).describe(jsonSchema.description);
|
|
151
|
+
return required ? schema : schema.optional();
|
|
152
|
+
}
|
|
153
|
+
throw new Error("Invalid JSON schema");
|
|
154
|
+
}
|
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig, Options } from "tsup";
|
|
2
|
+
|
|
3
|
+
export default defineConfig((options: Options) => ({
|
|
4
|
+
entry: ["src/**/*.{ts,tsx}"],
|
|
5
|
+
format: ["esm", "cjs"],
|
|
6
|
+
dts: true,
|
|
7
|
+
minify: false,
|
|
8
|
+
external: [],
|
|
9
|
+
sourcemap: true,
|
|
10
|
+
exclude: [
|
|
11
|
+
"**/*.test.ts", // Exclude TypeScript test files
|
|
12
|
+
"**/*.test.tsx", // Exclude TypeScript React test files
|
|
13
|
+
"**/__tests__/*", // Exclude any files inside a __tests__ directory
|
|
14
|
+
],
|
|
15
|
+
...options,
|
|
16
|
+
}));
|
package/typedoc.json
ADDED