@copilotkit/shared 1.51.5-next.0 → 1.51.5-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/constants/index.cjs +13 -0
- package/dist/constants/index.cjs.map +1 -0
- package/dist/constants/{index.d.ts → index.d.cts} +3 -1
- package/dist/constants/index.d.cts.map +1 -0
- package/dist/constants/index.d.mts +8 -0
- package/dist/constants/index.d.mts.map +1 -0
- package/dist/constants/index.mjs +8 -12
- package/dist/constants/index.mjs.map +1 -1
- package/dist/index.cjs +64 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +23 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +16 -123
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1017 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +12 -0
- package/dist/package.cjs.map +1 -0
- package/dist/package.mjs +6 -0
- package/dist/package.mjs.map +1 -0
- package/dist/telemetry/events.d.cts +47 -0
- package/dist/telemetry/events.d.cts.map +1 -0
- package/dist/telemetry/events.d.mts +47 -0
- package/dist/telemetry/events.d.mts.map +1 -0
- package/dist/telemetry/index.d.mts +1 -0
- package/dist/telemetry/scarf-client.cjs +29 -0
- package/dist/telemetry/scarf-client.cjs.map +1 -0
- package/dist/telemetry/scarf-client.mjs +27 -5
- package/dist/telemetry/scarf-client.mjs.map +1 -1
- package/dist/telemetry/telemetry-client.cjs +87 -0
- package/dist/telemetry/telemetry-client.cjs.map +1 -0
- package/dist/telemetry/telemetry-client.d.cts +48 -0
- package/dist/telemetry/telemetry-client.d.cts.map +1 -0
- package/dist/telemetry/telemetry-client.d.mts +48 -0
- package/dist/telemetry/telemetry-client.d.mts.map +1 -0
- package/dist/telemetry/telemetry-client.mjs +83 -9
- package/dist/telemetry/telemetry-client.mjs.map +1 -1
- package/dist/telemetry/utils.cjs +16 -0
- package/dist/telemetry/utils.cjs.map +1 -0
- package/dist/telemetry/utils.mjs +14 -8
- package/dist/telemetry/utils.mjs.map +1 -1
- package/dist/types/{action.d.ts → action.d.cts} +32 -32
- package/dist/types/action.d.cts.map +1 -0
- package/dist/types/action.d.mts +59 -0
- package/dist/types/action.d.mts.map +1 -0
- package/dist/types/copilot-cloud-config.d.cts +15 -0
- package/dist/types/copilot-cloud-config.d.cts.map +1 -0
- package/dist/types/copilot-cloud-config.d.mts +15 -0
- package/dist/types/copilot-cloud-config.d.mts.map +1 -0
- package/dist/types/error.d.cts +57 -0
- package/dist/types/error.d.cts.map +1 -0
- package/dist/types/error.d.mts +57 -0
- package/dist/types/error.d.mts.map +1 -0
- package/dist/types/{message.d.ts → message.d.cts} +14 -12
- package/dist/types/message.d.cts.map +1 -0
- package/dist/types/message.d.mts +31 -0
- package/dist/types/message.d.mts.map +1 -0
- package/dist/types/openai-assistant.d.cts +55 -0
- package/dist/types/openai-assistant.d.cts.map +1 -0
- package/dist/types/openai-assistant.d.mts +55 -0
- package/dist/types/openai-assistant.d.mts.map +1 -0
- package/dist/types/utility.d.cts +6 -0
- package/dist/types/utility.d.cts.map +1 -0
- package/dist/types/utility.d.mts +6 -0
- package/dist/types/utility.d.mts.map +1 -0
- package/dist/utils/conditions.cjs +32 -0
- package/dist/utils/conditions.cjs.map +1 -0
- package/dist/utils/{conditions.d.ts → conditions.d.cts} +16 -11
- package/dist/utils/conditions.d.cts.map +1 -0
- package/dist/utils/conditions.d.mts +31 -0
- package/dist/utils/conditions.d.mts.map +1 -0
- package/dist/utils/conditions.mjs +30 -6
- package/dist/utils/conditions.mjs.map +1 -1
- package/dist/utils/console-styling.cjs +91 -0
- package/dist/utils/console-styling.cjs.map +1 -0
- package/dist/utils/console-styling.d.cts +65 -0
- package/dist/utils/console-styling.d.cts.map +1 -0
- package/dist/utils/console-styling.d.mts +65 -0
- package/dist/utils/console-styling.d.mts.map +1 -0
- package/dist/utils/console-styling.mjs +83 -15
- package/dist/utils/console-styling.mjs.map +1 -1
- package/dist/utils/errors.cjs +439 -0
- package/dist/utils/errors.cjs.map +1 -0
- package/dist/utils/{errors.d.ts → errors.d.cts} +188 -156
- package/dist/utils/errors.d.cts.map +1 -0
- package/dist/utils/errors.d.mts +312 -0
- package/dist/utils/errors.d.mts.map +1 -0
- package/dist/utils/errors.mjs +416 -63
- package/dist/utils/errors.mjs.map +1 -1
- package/dist/utils/index.cjs +50 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/{index.d.ts → index.d.cts} +10 -11
- package/dist/utils/index.d.cts.map +1 -0
- package/dist/utils/index.d.mts +31 -0
- package/dist/utils/index.d.mts.map +1 -0
- package/dist/utils/index.mjs +47 -107
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/json-schema.cjs +157 -0
- package/dist/utils/json-schema.cjs.map +1 -0
- package/dist/utils/{json-schema.d.ts → json-schema.d.cts} +19 -17
- package/dist/utils/json-schema.d.cts.map +1 -0
- package/dist/utils/json-schema.d.mts +36 -0
- package/dist/utils/json-schema.d.mts.map +1 -0
- package/dist/utils/json-schema.mjs +152 -12
- package/dist/utils/json-schema.mjs.map +1 -1
- package/dist/utils/random-id.cjs +38 -0
- package/dist/utils/random-id.cjs.map +1 -0
- package/dist/utils/{random-id.d.ts → random-id.d.cts} +3 -1
- package/dist/utils/random-id.d.cts.map +1 -0
- package/dist/utils/random-id.d.mts +8 -0
- package/dist/utils/random-id.d.mts.map +1 -0
- package/dist/utils/random-id.mjs +33 -12
- package/dist/utils/random-id.mjs.map +1 -1
- package/dist/utils/requests.cjs +58 -0
- package/dist/utils/requests.cjs.map +1 -0
- package/dist/utils/{requests.d.ts → requests.d.cts} +3 -1
- package/dist/utils/requests.d.cts.map +1 -0
- package/dist/utils/requests.d.mts +12 -0
- package/dist/utils/requests.d.mts.map +1 -0
- package/dist/utils/requests.mjs +56 -6
- package/dist/utils/requests.mjs.map +1 -1
- package/dist/utils/{types.d.ts → types.d.cts} +9 -7
- package/dist/utils/types.d.cts.map +1 -0
- package/dist/utils/types.d.mts +22 -0
- package/dist/utils/types.d.mts.map +1 -0
- package/package.json +16 -14
- package/tsdown.config.ts +36 -0
- package/vitest.config.mjs +11 -0
- package/dist/chunk-2OJ5OJ2D.mjs +0 -1
- package/dist/chunk-2OJ5OJ2D.mjs.map +0 -1
- package/dist/chunk-3DK3UMRW.mjs +0 -217
- package/dist/chunk-3DK3UMRW.mjs.map +0 -1
- package/dist/chunk-7KOT4KP4.mjs +0 -435
- package/dist/chunk-7KOT4KP4.mjs.map +0 -1
- package/dist/chunk-DE5XAMMI.mjs +0 -110
- package/dist/chunk-DE5XAMMI.mjs.map +0 -1
- package/dist/chunk-FCCOSO5L.mjs +0 -1
- package/dist/chunk-FCCOSO5L.mjs.map +0 -1
- package/dist/chunk-GS5BLXSZ.mjs +0 -41
- package/dist/chunk-GS5BLXSZ.mjs.map +0 -1
- package/dist/chunk-IAFBVORQ.mjs +0 -1
- package/dist/chunk-IAFBVORQ.mjs.map +0 -1
- package/dist/chunk-M2RJI5BZ.mjs +0 -94
- package/dist/chunk-M2RJI5BZ.mjs.map +0 -1
- package/dist/chunk-MSUB6DGR.mjs +0 -1
- package/dist/chunk-MSUB6DGR.mjs.map +0 -1
- package/dist/chunk-N5EP5OD5.mjs +0 -1
- package/dist/chunk-N5EP5OD5.mjs.map +0 -1
- package/dist/chunk-NAFEBKSO.mjs +0 -1
- package/dist/chunk-NAFEBKSO.mjs.map +0 -1
- package/dist/chunk-P7STFMPO.mjs +0 -1
- package/dist/chunk-P7STFMPO.mjs.map +0 -1
- package/dist/chunk-UYARLQNA.mjs +0 -1
- package/dist/chunk-UYARLQNA.mjs.map +0 -1
- package/dist/chunk-V7BSERGI.mjs +0 -62
- package/dist/chunk-V7BSERGI.mjs.map +0 -1
- package/dist/chunk-WAZHII6M.mjs +0 -67
- package/dist/chunk-WAZHII6M.mjs.map +0 -1
- package/dist/chunk-XTHC46M2.mjs +0 -1
- package/dist/chunk-XTHC46M2.mjs.map +0 -1
- package/dist/chunk-ZI7ZVRL3.mjs +0 -38
- package/dist/chunk-ZI7ZVRL3.mjs.map +0 -1
- package/dist/chunk-ZIC6V6S5.mjs +0 -13
- package/dist/chunk-ZIC6V6S5.mjs.map +0 -1
- package/dist/chunk-ZUE2VR7D.mjs +0 -38
- package/dist/chunk-ZUE2VR7D.mjs.map +0 -1
- package/dist/constants/index.js +0 -40
- package/dist/constants/index.js.map +0 -1
- package/dist/index.d.ts +0 -25
- package/dist/index.js +0 -1138
- package/dist/index.js.map +0 -1
- package/dist/telemetry/events.d.ts +0 -45
- package/dist/telemetry/events.js +0 -19
- package/dist/telemetry/events.js.map +0 -1
- package/dist/telemetry/events.mjs +0 -1
- package/dist/telemetry/events.mjs.map +0 -1
- package/dist/telemetry/index.d.ts +0 -3
- package/dist/telemetry/index.js +0 -191
- package/dist/telemetry/index.js.map +0 -1
- package/dist/telemetry/index.mjs +0 -12
- package/dist/telemetry/index.mjs.map +0 -1
- package/dist/telemetry/scarf-client.d.ts +0 -7
- package/dist/telemetry/scarf-client.js +0 -59
- package/dist/telemetry/scarf-client.js.map +0 -1
- package/dist/telemetry/security-check.d.ts +0 -2
- package/dist/telemetry/security-check.js +0 -2
- package/dist/telemetry/security-check.js.map +0 -1
- package/dist/telemetry/security-check.mjs +0 -1
- package/dist/telemetry/security-check.mjs.map +0 -1
- package/dist/telemetry/telemetry-client.d.ts +0 -40
- package/dist/telemetry/telemetry-client.js +0 -189
- package/dist/telemetry/telemetry-client.js.map +0 -1
- package/dist/telemetry/utils.d.ts +0 -8
- package/dist/telemetry/utils.js +0 -73
- package/dist/telemetry/utils.js.map +0 -1
- package/dist/types/action.js +0 -19
- package/dist/types/action.js.map +0 -1
- package/dist/types/action.mjs +0 -2
- package/dist/types/action.mjs.map +0 -1
- package/dist/types/copilot-cloud-config.d.ts +0 -13
- package/dist/types/copilot-cloud-config.js +0 -19
- package/dist/types/copilot-cloud-config.js.map +0 -1
- package/dist/types/copilot-cloud-config.mjs +0 -2
- package/dist/types/copilot-cloud-config.mjs.map +0 -1
- package/dist/types/error.d.ts +0 -55
- package/dist/types/error.js +0 -19
- package/dist/types/error.js.map +0 -1
- package/dist/types/error.mjs +0 -2
- package/dist/types/error.mjs.map +0 -1
- package/dist/types/index.d.ts +0 -7
- package/dist/types/index.js +0 -19
- package/dist/types/index.js.map +0 -1
- package/dist/types/index.mjs +0 -8
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/message.js +0 -19
- package/dist/types/message.js.map +0 -1
- package/dist/types/message.mjs +0 -2
- package/dist/types/message.mjs.map +0 -1
- package/dist/types/openai-assistant.d.ts +0 -53
- package/dist/types/openai-assistant.js +0 -19
- package/dist/types/openai-assistant.js.map +0 -1
- package/dist/types/openai-assistant.mjs +0 -2
- package/dist/types/openai-assistant.mjs.map +0 -1
- package/dist/types/utility.d.ts +0 -6
- package/dist/types/utility.js +0 -19
- package/dist/types/utility.js.map +0 -1
- package/dist/types/utility.mjs +0 -2
- package/dist/types/utility.mjs.map +0 -1
- package/dist/utils/conditions.js +0 -86
- package/dist/utils/conditions.js.map +0 -1
- package/dist/utils/console-styling.d.ts +0 -84
- package/dist/utils/console-styling.js +0 -123
- package/dist/utils/console-styling.js.map +0 -1
- package/dist/utils/errors.js +0 -452
- package/dist/utils/errors.js.map +0 -1
- package/dist/utils/index.js +0 -964
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/json-schema.js +0 -244
- package/dist/utils/json-schema.js.map +0 -1
- package/dist/utils/random-id.js +0 -68
- package/dist/utils/random-id.js.map +0 -1
- package/dist/utils/requests.js +0 -91
- package/dist/utils/requests.js.map +0 -1
- package/dist/utils/types.js +0 -19
- package/dist/utils/types.js.map +0 -1
- package/dist/utils/types.mjs +0 -2
- package/dist/utils/types.mjs.map +0 -1
- package/jest.config.js +0 -5
- package/rollup.config.mjs +0 -54
- package/tsup.config.ts +0 -15
package/dist/chunk-3DK3UMRW.mjs
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
// src/utils/json-schema.ts
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
function actionParametersToJsonSchema(actionParameters) {
|
|
4
|
-
let parameters = {};
|
|
5
|
-
for (let parameter of actionParameters || []) {
|
|
6
|
-
parameters[parameter.name] = convertAttribute(parameter);
|
|
7
|
-
}
|
|
8
|
-
let requiredParameterNames = [];
|
|
9
|
-
for (let arg of actionParameters || []) {
|
|
10
|
-
if (arg.required !== false) {
|
|
11
|
-
requiredParameterNames.push(arg.name);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
type: "object",
|
|
16
|
-
properties: parameters,
|
|
17
|
-
required: requiredParameterNames
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function jsonSchemaToActionParameters(jsonSchema) {
|
|
21
|
-
if (jsonSchema.type !== "object" || !jsonSchema.properties) {
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
const parameters = [];
|
|
25
|
-
const requiredFields = jsonSchema.required || [];
|
|
26
|
-
for (const [name, schema] of Object.entries(jsonSchema.properties)) {
|
|
27
|
-
const parameter = convertJsonSchemaToParameter(
|
|
28
|
-
name,
|
|
29
|
-
schema,
|
|
30
|
-
requiredFields.includes(name)
|
|
31
|
-
);
|
|
32
|
-
parameters.push(parameter);
|
|
33
|
-
}
|
|
34
|
-
return parameters;
|
|
35
|
-
}
|
|
36
|
-
function convertJsonSchemaToParameter(name, schema, isRequired) {
|
|
37
|
-
const baseParameter = {
|
|
38
|
-
name,
|
|
39
|
-
description: schema.description
|
|
40
|
-
};
|
|
41
|
-
if (!isRequired) {
|
|
42
|
-
baseParameter.required = false;
|
|
43
|
-
}
|
|
44
|
-
switch (schema.type) {
|
|
45
|
-
case "string":
|
|
46
|
-
return {
|
|
47
|
-
...baseParameter,
|
|
48
|
-
type: "string",
|
|
49
|
-
...schema.enum && { enum: schema.enum }
|
|
50
|
-
};
|
|
51
|
-
case "number":
|
|
52
|
-
case "boolean":
|
|
53
|
-
return {
|
|
54
|
-
...baseParameter,
|
|
55
|
-
type: schema.type
|
|
56
|
-
};
|
|
57
|
-
case "object":
|
|
58
|
-
if (schema.properties) {
|
|
59
|
-
const attributes = [];
|
|
60
|
-
const requiredFields = schema.required || [];
|
|
61
|
-
for (const [propName, propSchema] of Object.entries(
|
|
62
|
-
schema.properties
|
|
63
|
-
)) {
|
|
64
|
-
attributes.push(
|
|
65
|
-
convertJsonSchemaToParameter(
|
|
66
|
-
propName,
|
|
67
|
-
propSchema,
|
|
68
|
-
requiredFields.includes(propName)
|
|
69
|
-
)
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
...baseParameter,
|
|
74
|
-
type: "object",
|
|
75
|
-
attributes
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
...baseParameter,
|
|
80
|
-
type: "object"
|
|
81
|
-
};
|
|
82
|
-
case "array":
|
|
83
|
-
if (schema.items.type === "object" && "properties" in schema.items) {
|
|
84
|
-
const attributes = [];
|
|
85
|
-
const requiredFields = schema.items.required || [];
|
|
86
|
-
for (const [propName, propSchema] of Object.entries(
|
|
87
|
-
schema.items.properties || {}
|
|
88
|
-
)) {
|
|
89
|
-
attributes.push(
|
|
90
|
-
convertJsonSchemaToParameter(
|
|
91
|
-
propName,
|
|
92
|
-
propSchema,
|
|
93
|
-
requiredFields.includes(propName)
|
|
94
|
-
)
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
...baseParameter,
|
|
99
|
-
type: "object[]",
|
|
100
|
-
attributes
|
|
101
|
-
};
|
|
102
|
-
} else if (schema.items.type === "array") {
|
|
103
|
-
throw new Error("Nested arrays are not supported");
|
|
104
|
-
} else {
|
|
105
|
-
return {
|
|
106
|
-
...baseParameter,
|
|
107
|
-
type: `${schema.items.type}[]`
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
default:
|
|
111
|
-
return {
|
|
112
|
-
...baseParameter,
|
|
113
|
-
type: "string"
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
function convertAttribute(attribute) {
|
|
118
|
-
var _a, _b, _c;
|
|
119
|
-
switch (attribute.type) {
|
|
120
|
-
case "string":
|
|
121
|
-
return {
|
|
122
|
-
type: "string",
|
|
123
|
-
description: attribute.description,
|
|
124
|
-
...attribute.enum && { enum: attribute.enum }
|
|
125
|
-
};
|
|
126
|
-
case "number":
|
|
127
|
-
case "boolean":
|
|
128
|
-
return {
|
|
129
|
-
type: attribute.type,
|
|
130
|
-
description: attribute.description
|
|
131
|
-
};
|
|
132
|
-
case "object":
|
|
133
|
-
case "object[]":
|
|
134
|
-
const properties = (_a = attribute.attributes) == null ? void 0 : _a.reduce(
|
|
135
|
-
(acc, attr) => {
|
|
136
|
-
acc[attr.name] = convertAttribute(attr);
|
|
137
|
-
return acc;
|
|
138
|
-
},
|
|
139
|
-
{}
|
|
140
|
-
);
|
|
141
|
-
const required = (_b = attribute.attributes) == null ? void 0 : _b.filter((attr) => attr.required !== false).map((attr) => attr.name);
|
|
142
|
-
if (attribute.type === "object[]") {
|
|
143
|
-
return {
|
|
144
|
-
type: "array",
|
|
145
|
-
items: {
|
|
146
|
-
type: "object",
|
|
147
|
-
...properties && { properties },
|
|
148
|
-
...required && required.length > 0 && { required }
|
|
149
|
-
},
|
|
150
|
-
description: attribute.description
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
return {
|
|
154
|
-
type: "object",
|
|
155
|
-
description: attribute.description,
|
|
156
|
-
...properties && { properties },
|
|
157
|
-
...required && required.length > 0 && { required }
|
|
158
|
-
};
|
|
159
|
-
default:
|
|
160
|
-
if ((_c = attribute.type) == null ? void 0 : _c.endsWith("[]")) {
|
|
161
|
-
const itemType = attribute.type.slice(0, -2);
|
|
162
|
-
return {
|
|
163
|
-
type: "array",
|
|
164
|
-
items: { type: itemType },
|
|
165
|
-
description: attribute.description
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
return {
|
|
169
|
-
type: "string",
|
|
170
|
-
description: attribute.description
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
function convertJsonSchemaToZodSchema(jsonSchema, required) {
|
|
175
|
-
if (jsonSchema.type === "object") {
|
|
176
|
-
const spec = {};
|
|
177
|
-
if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
|
|
178
|
-
return !required ? z.object(spec).optional() : z.object(spec);
|
|
179
|
-
}
|
|
180
|
-
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
181
|
-
spec[key] = convertJsonSchemaToZodSchema(
|
|
182
|
-
value,
|
|
183
|
-
jsonSchema.required ? jsonSchema.required.includes(key) : false
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
let schema = z.object(spec).describe(jsonSchema.description);
|
|
187
|
-
return required ? schema : schema.optional();
|
|
188
|
-
} else if (jsonSchema.type === "string") {
|
|
189
|
-
let schema = z.string().describe(jsonSchema.description);
|
|
190
|
-
return required ? schema : schema.optional();
|
|
191
|
-
} else if (jsonSchema.type === "number") {
|
|
192
|
-
let schema = z.number().describe(jsonSchema.description);
|
|
193
|
-
return required ? schema : schema.optional();
|
|
194
|
-
} else if (jsonSchema.type === "boolean") {
|
|
195
|
-
let schema = z.boolean().describe(jsonSchema.description);
|
|
196
|
-
return required ? schema : schema.optional();
|
|
197
|
-
} else if (jsonSchema.type === "array") {
|
|
198
|
-
let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
|
|
199
|
-
let schema = z.array(itemSchema).describe(jsonSchema.description);
|
|
200
|
-
return required ? schema : schema.optional();
|
|
201
|
-
}
|
|
202
|
-
throw new Error("Invalid JSON schema");
|
|
203
|
-
}
|
|
204
|
-
function getZodParameters(parameters) {
|
|
205
|
-
if (!parameters)
|
|
206
|
-
return z.object({});
|
|
207
|
-
const jsonParams = actionParametersToJsonSchema(parameters);
|
|
208
|
-
return convertJsonSchemaToZodSchema(jsonParams, true);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export {
|
|
212
|
-
actionParametersToJsonSchema,
|
|
213
|
-
jsonSchemaToActionParameters,
|
|
214
|
-
convertJsonSchemaToZodSchema,
|
|
215
|
-
getZodParameters
|
|
216
|
-
};
|
|
217
|
-
//# sourceMappingURL=chunk-3DK3UMRW.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"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 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): z.ZodSchema {\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 );\n }\n let schema = z.object(spec).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"string\") {\n let schema = z.string().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"number\") {\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(jsonSchema.items, true);\n let schema = z.array(itemSchema).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n }\n throw new Error(\"Invalid JSON schema\");\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":";AAAA,SAAS,SAAS;AAuCX,SAAS,6BACd,kBACY;AAEZ,MAAI,aAAqC,CAAC;AAC1C,WAAS,aAAa,oBAAoB,CAAC,GAAG;AAC5C,eAAW,UAAU,IAAI,IAAI,iBAAiB,SAAS;AAAA,EACzD;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,oBAAoB,CAAC,GAAG;AACtC,QAAI,IAAI,aAAa,OAAO;AAC1B,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,UAAU;AAAA,EACZ;AACF;AAGO,SAAS,6BACd,YACa;AACb,MAAI,WAAW,SAAS,YAAY,CAAC,WAAW,YAAY;AAC1D,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,aAA0B,CAAC;AACjC,QAAM,iBAAiB,WAAW,YAAY,CAAC;AAE/C,aAAW,CAAC,MAAM,MAAM,KAAK,OAAO,QAAQ,WAAW,UAAU,GAAG;AAClE,UAAM,YAAY;AAAA,MAChB;AAAA,MACA;AAAA,MACA,eAAe,SAAS,IAAI;AAAA,IAC9B;AACA,eAAW,KAAK,SAAS;AAAA,EAC3B;AAEA,SAAO;AACT;AAGA,SAAS,6BACP,MACA,QACA,YACW;AACX,QAAM,gBAA2B;AAAA,IAC/B;AAAA,IACA,aAAa,OAAO;AAAA,EACtB;AAEA,MAAI,CAAC,YAAY;AACf,kBAAc,WAAW;AAAA,EAC3B;AAEA,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK;AACH,aAAO;AAAA,QACL,GAAG;AAAA,QACH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O,SAAS,iBACd,YACK;AACL,MAAI,CAAC;AAAY,WAAO,EAAE,OAAO,CAAC,CAAC;AACnC,QAAM,aAAa,6BAA6B,UAAU;AAC1D,SAAO,6BAA6B,YAAY,IAAI;AACtD;","names":[]}
|
package/dist/chunk-7KOT4KP4.mjs
DELETED
|
@@ -1,435 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
version
|
|
3
|
-
} from "./chunk-ZI7ZVRL3.mjs";
|
|
4
|
-
|
|
5
|
-
// src/utils/errors.ts
|
|
6
|
-
import { GraphQLError } from "graphql";
|
|
7
|
-
|
|
8
|
-
// src/utils/index.ts
|
|
9
|
-
function parseJson(json, fallback = "unset") {
|
|
10
|
-
try {
|
|
11
|
-
return JSON.parse(json);
|
|
12
|
-
} catch (e) {
|
|
13
|
-
return fallback === "unset" ? null : fallback;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function tryMap(items, callback) {
|
|
17
|
-
return items.reduce((acc, item, index, array) => {
|
|
18
|
-
try {
|
|
19
|
-
acc.push(callback(item, index, array));
|
|
20
|
-
} catch (error) {
|
|
21
|
-
console.error(error);
|
|
22
|
-
}
|
|
23
|
-
return acc;
|
|
24
|
-
}, []);
|
|
25
|
-
}
|
|
26
|
-
function isMacOS() {
|
|
27
|
-
return /Mac|iMac|Macintosh/i.test(navigator.userAgent);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var COPILOTKIT_VERSION = version;
|
|
32
|
-
|
|
33
|
-
// src/utils/errors.ts
|
|
34
|
-
var Severity = /* @__PURE__ */ ((Severity2) => {
|
|
35
|
-
Severity2["CRITICAL"] = "critical";
|
|
36
|
-
Severity2["WARNING"] = "warning";
|
|
37
|
-
Severity2["INFO"] = "info";
|
|
38
|
-
return Severity2;
|
|
39
|
-
})(Severity || {});
|
|
40
|
-
var ErrorVisibility = /* @__PURE__ */ ((ErrorVisibility2) => {
|
|
41
|
-
ErrorVisibility2["BANNER"] = "banner";
|
|
42
|
-
ErrorVisibility2["TOAST"] = "toast";
|
|
43
|
-
ErrorVisibility2["SILENT"] = "silent";
|
|
44
|
-
ErrorVisibility2["DEV_ONLY"] = "dev_only";
|
|
45
|
-
return ErrorVisibility2;
|
|
46
|
-
})(ErrorVisibility || {});
|
|
47
|
-
var ERROR_NAMES = {
|
|
48
|
-
COPILOT_ERROR: "CopilotError",
|
|
49
|
-
COPILOT_API_DISCOVERY_ERROR: "CopilotApiDiscoveryError",
|
|
50
|
-
COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR: "CopilotKitRemoteEndpointDiscoveryError",
|
|
51
|
-
COPILOT_KIT_AGENT_DISCOVERY_ERROR: "CopilotKitAgentDiscoveryError",
|
|
52
|
-
COPILOT_KIT_LOW_LEVEL_ERROR: "CopilotKitLowLevelError",
|
|
53
|
-
COPILOT_KIT_VERSION_MISMATCH_ERROR: "CopilotKitVersionMismatchError",
|
|
54
|
-
RESOLVED_COPILOT_KIT_ERROR: "ResolvedCopilotKitError",
|
|
55
|
-
CONFIGURATION_ERROR: "ConfigurationError",
|
|
56
|
-
MISSING_PUBLIC_API_KEY_ERROR: "MissingPublicApiKeyError",
|
|
57
|
-
UPGRADE_REQUIRED_ERROR: "UpgradeRequiredError"
|
|
58
|
-
};
|
|
59
|
-
var BANNER_ERROR_NAMES = [
|
|
60
|
-
ERROR_NAMES.CONFIGURATION_ERROR,
|
|
61
|
-
ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR,
|
|
62
|
-
ERROR_NAMES.UPGRADE_REQUIRED_ERROR,
|
|
63
|
-
ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR,
|
|
64
|
-
ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR,
|
|
65
|
-
ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR
|
|
66
|
-
];
|
|
67
|
-
var COPILOT_CLOUD_ERROR_NAMES = BANNER_ERROR_NAMES;
|
|
68
|
-
var CopilotKitErrorCode = /* @__PURE__ */ ((CopilotKitErrorCode2) => {
|
|
69
|
-
CopilotKitErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
70
|
-
CopilotKitErrorCode2["NOT_FOUND"] = "NOT_FOUND";
|
|
71
|
-
CopilotKitErrorCode2["AGENT_NOT_FOUND"] = "AGENT_NOT_FOUND";
|
|
72
|
-
CopilotKitErrorCode2["API_NOT_FOUND"] = "API_NOT_FOUND";
|
|
73
|
-
CopilotKitErrorCode2["REMOTE_ENDPOINT_NOT_FOUND"] = "REMOTE_ENDPOINT_NOT_FOUND";
|
|
74
|
-
CopilotKitErrorCode2["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
|
|
75
|
-
CopilotKitErrorCode2["MISUSE"] = "MISUSE";
|
|
76
|
-
CopilotKitErrorCode2["UNKNOWN"] = "UNKNOWN";
|
|
77
|
-
CopilotKitErrorCode2["VERSION_MISMATCH"] = "VERSION_MISMATCH";
|
|
78
|
-
CopilotKitErrorCode2["CONFIGURATION_ERROR"] = "CONFIGURATION_ERROR";
|
|
79
|
-
CopilotKitErrorCode2["MISSING_PUBLIC_API_KEY_ERROR"] = "MISSING_PUBLIC_API_KEY_ERROR";
|
|
80
|
-
CopilotKitErrorCode2["UPGRADE_REQUIRED_ERROR"] = "UPGRADE_REQUIRED_ERROR";
|
|
81
|
-
return CopilotKitErrorCode2;
|
|
82
|
-
})(CopilotKitErrorCode || {});
|
|
83
|
-
var BASE_URL = "https://docs.copilotkit.ai";
|
|
84
|
-
var getSeeMoreMarkdown = (link) => `See more: [${link}](${link})`;
|
|
85
|
-
var ERROR_CONFIG = {
|
|
86
|
-
["NETWORK_ERROR" /* NETWORK_ERROR */]: {
|
|
87
|
-
statusCode: 503,
|
|
88
|
-
troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
|
|
89
|
-
visibility: "banner" /* BANNER */,
|
|
90
|
-
severity: "critical" /* CRITICAL */
|
|
91
|
-
},
|
|
92
|
-
["NOT_FOUND" /* NOT_FOUND */]: {
|
|
93
|
-
statusCode: 404,
|
|
94
|
-
troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
|
|
95
|
-
visibility: "banner" /* BANNER */,
|
|
96
|
-
severity: "critical" /* CRITICAL */
|
|
97
|
-
},
|
|
98
|
-
["AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */]: {
|
|
99
|
-
statusCode: 500,
|
|
100
|
-
troubleshootingUrl: `${BASE_URL}/coagents/troubleshooting/common-issues#i-am-getting-agent-not-found-error`,
|
|
101
|
-
visibility: "banner" /* BANNER */,
|
|
102
|
-
severity: "critical" /* CRITICAL */
|
|
103
|
-
},
|
|
104
|
-
["API_NOT_FOUND" /* API_NOT_FOUND */]: {
|
|
105
|
-
statusCode: 404,
|
|
106
|
-
troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
|
|
107
|
-
visibility: "banner" /* BANNER */,
|
|
108
|
-
severity: "critical" /* CRITICAL */
|
|
109
|
-
},
|
|
110
|
-
["REMOTE_ENDPOINT_NOT_FOUND" /* REMOTE_ENDPOINT_NOT_FOUND */]: {
|
|
111
|
-
statusCode: 404,
|
|
112
|
-
troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-copilotkits-remote-endpoint-not-found-error`,
|
|
113
|
-
visibility: "banner" /* BANNER */,
|
|
114
|
-
severity: "critical" /* CRITICAL */
|
|
115
|
-
},
|
|
116
|
-
["AUTHENTICATION_ERROR" /* AUTHENTICATION_ERROR */]: {
|
|
117
|
-
statusCode: 401,
|
|
118
|
-
troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#authentication-errors`,
|
|
119
|
-
visibility: "banner" /* BANNER */,
|
|
120
|
-
severity: "critical" /* CRITICAL */
|
|
121
|
-
},
|
|
122
|
-
["MISUSE" /* MISUSE */]: {
|
|
123
|
-
statusCode: 400,
|
|
124
|
-
troubleshootingUrl: null,
|
|
125
|
-
visibility: "dev_only" /* DEV_ONLY */,
|
|
126
|
-
severity: "warning" /* WARNING */
|
|
127
|
-
},
|
|
128
|
-
["UNKNOWN" /* UNKNOWN */]: {
|
|
129
|
-
statusCode: 500,
|
|
130
|
-
visibility: "toast" /* TOAST */,
|
|
131
|
-
severity: "critical" /* CRITICAL */
|
|
132
|
-
},
|
|
133
|
-
["CONFIGURATION_ERROR" /* CONFIGURATION_ERROR */]: {
|
|
134
|
-
statusCode: 400,
|
|
135
|
-
troubleshootingUrl: null,
|
|
136
|
-
severity: "warning" /* WARNING */,
|
|
137
|
-
visibility: "banner" /* BANNER */
|
|
138
|
-
},
|
|
139
|
-
["MISSING_PUBLIC_API_KEY_ERROR" /* MISSING_PUBLIC_API_KEY_ERROR */]: {
|
|
140
|
-
statusCode: 400,
|
|
141
|
-
troubleshootingUrl: null,
|
|
142
|
-
severity: "critical" /* CRITICAL */,
|
|
143
|
-
visibility: "banner" /* BANNER */
|
|
144
|
-
},
|
|
145
|
-
["UPGRADE_REQUIRED_ERROR" /* UPGRADE_REQUIRED_ERROR */]: {
|
|
146
|
-
statusCode: 402,
|
|
147
|
-
troubleshootingUrl: null,
|
|
148
|
-
severity: "warning" /* WARNING */,
|
|
149
|
-
visibility: "banner" /* BANNER */
|
|
150
|
-
},
|
|
151
|
-
["VERSION_MISMATCH" /* VERSION_MISMATCH */]: {
|
|
152
|
-
statusCode: 400,
|
|
153
|
-
troubleshootingUrl: null,
|
|
154
|
-
visibility: "dev_only" /* DEV_ONLY */,
|
|
155
|
-
severity: "info" /* INFO */
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
var CopilotKitError = class extends GraphQLError {
|
|
159
|
-
constructor({
|
|
160
|
-
message = "Unknown error occurred",
|
|
161
|
-
code,
|
|
162
|
-
severity,
|
|
163
|
-
visibility
|
|
164
|
-
}) {
|
|
165
|
-
const name = ERROR_NAMES.COPILOT_ERROR;
|
|
166
|
-
const config = ERROR_CONFIG[code];
|
|
167
|
-
const { statusCode } = config;
|
|
168
|
-
const resolvedVisibility = visibility ?? config.visibility ?? "toast" /* TOAST */;
|
|
169
|
-
const resolvedSeverity = severity ?? ("severity" in config ? config.severity : void 0);
|
|
170
|
-
super(message, {
|
|
171
|
-
extensions: {
|
|
172
|
-
name,
|
|
173
|
-
statusCode,
|
|
174
|
-
code,
|
|
175
|
-
visibility: resolvedVisibility,
|
|
176
|
-
severity: resolvedSeverity,
|
|
177
|
-
troubleshootingUrl: "troubleshootingUrl" in config ? config.troubleshootingUrl : null,
|
|
178
|
-
originalError: {
|
|
179
|
-
message,
|
|
180
|
-
stack: new Error().stack
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
this.code = code;
|
|
185
|
-
this.name = name;
|
|
186
|
-
this.statusCode = statusCode;
|
|
187
|
-
this.severity = resolvedSeverity;
|
|
188
|
-
this.visibility = resolvedVisibility;
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
var CopilotKitMisuseError = class extends CopilotKitError {
|
|
192
|
-
constructor({
|
|
193
|
-
message,
|
|
194
|
-
code = "MISUSE" /* MISUSE */
|
|
195
|
-
}) {
|
|
196
|
-
const docsLink = "troubleshootingUrl" in ERROR_CONFIG[code] && ERROR_CONFIG[code].troubleshootingUrl ? getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl) : null;
|
|
197
|
-
const finalMessage = docsLink ? `${message}.
|
|
198
|
-
|
|
199
|
-
${docsLink}` : message;
|
|
200
|
-
super({ message: finalMessage, code });
|
|
201
|
-
this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
var getVersionMismatchErrorMessage = ({
|
|
205
|
-
reactCoreVersion,
|
|
206
|
-
runtimeVersion,
|
|
207
|
-
runtimeClientGqlVersion
|
|
208
|
-
}) => `Version mismatch detected: @copilotkit/runtime@${runtimeVersion ?? ""} is not compatible with @copilotkit/react-core@${reactCoreVersion} and @copilotkit/runtime-client-gql@${runtimeClientGqlVersion}. Please ensure all installed copilotkit packages are on the same version.`;
|
|
209
|
-
var CopilotKitVersionMismatchError = class extends CopilotKitError {
|
|
210
|
-
constructor({
|
|
211
|
-
reactCoreVersion,
|
|
212
|
-
runtimeVersion,
|
|
213
|
-
runtimeClientGqlVersion
|
|
214
|
-
}) {
|
|
215
|
-
const code = "VERSION_MISMATCH" /* VERSION_MISMATCH */;
|
|
216
|
-
super({
|
|
217
|
-
message: getVersionMismatchErrorMessage({
|
|
218
|
-
reactCoreVersion,
|
|
219
|
-
runtimeVersion,
|
|
220
|
-
runtimeClientGqlVersion
|
|
221
|
-
}),
|
|
222
|
-
code
|
|
223
|
-
});
|
|
224
|
-
this.name = ERROR_NAMES.COPILOT_KIT_VERSION_MISMATCH_ERROR;
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
var CopilotKitApiDiscoveryError = class extends CopilotKitError {
|
|
228
|
-
constructor(params = {}) {
|
|
229
|
-
const url = params.url ?? "";
|
|
230
|
-
let operationSuffix = "";
|
|
231
|
-
if (url == null ? void 0 : url.includes("/info"))
|
|
232
|
-
operationSuffix = `when fetching CopilotKit info`;
|
|
233
|
-
else if (url.includes("/actions/execute"))
|
|
234
|
-
operationSuffix = `when attempting to execute actions.`;
|
|
235
|
-
else if (url.includes("/agents/state"))
|
|
236
|
-
operationSuffix = `when attempting to get agent state.`;
|
|
237
|
-
else if (url.includes("/agents/execute"))
|
|
238
|
-
operationSuffix = `when attempting to execute agent(s).`;
|
|
239
|
-
const message = params.message ?? (params.url ? `Failed to find CopilotKit API endpoint at url ${params.url} ${operationSuffix}` : `Failed to find CopilotKit API endpoint.`);
|
|
240
|
-
const code = params.code ?? "API_NOT_FOUND" /* API_NOT_FOUND */;
|
|
241
|
-
const errorMessage = `${message}.
|
|
242
|
-
|
|
243
|
-
${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;
|
|
244
|
-
super({ message: errorMessage, code });
|
|
245
|
-
this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
var CopilotKitRemoteEndpointDiscoveryError = class extends CopilotKitApiDiscoveryError {
|
|
249
|
-
constructor(params) {
|
|
250
|
-
const message = (params == null ? void 0 : params.message) ?? ((params == null ? void 0 : params.url) ? `Failed to find or contact remote endpoint at url ${params.url}` : "Failed to find or contact remote endpoint");
|
|
251
|
-
const code = "REMOTE_ENDPOINT_NOT_FOUND" /* REMOTE_ENDPOINT_NOT_FOUND */;
|
|
252
|
-
super({ message, code });
|
|
253
|
-
this.name = ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR;
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
var CopilotKitAgentDiscoveryError = class extends CopilotKitError {
|
|
257
|
-
constructor(params) {
|
|
258
|
-
const { agentName, availableAgents } = params;
|
|
259
|
-
const code = "AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */;
|
|
260
|
-
const seeMore = getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl);
|
|
261
|
-
let message;
|
|
262
|
-
if (availableAgents.length) {
|
|
263
|
-
const agentList = availableAgents.map((agent) => agent.name).join(", ");
|
|
264
|
-
if (agentName) {
|
|
265
|
-
message = `Agent '${agentName}' was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.
|
|
266
|
-
|
|
267
|
-
${seeMore}`;
|
|
268
|
-
} else {
|
|
269
|
-
message = `The requested agent was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.
|
|
270
|
-
|
|
271
|
-
${seeMore}`;
|
|
272
|
-
}
|
|
273
|
-
} else {
|
|
274
|
-
message = `${agentName ? `Agent '${agentName}'` : "The requested agent"} was not found. Please set up at least one agent before proceeding. ${seeMore}`;
|
|
275
|
-
}
|
|
276
|
-
super({ message, code });
|
|
277
|
-
this.name = ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR;
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
|
-
var CopilotKitLowLevelError = class extends CopilotKitError {
|
|
281
|
-
constructor({
|
|
282
|
-
error,
|
|
283
|
-
url,
|
|
284
|
-
message
|
|
285
|
-
}) {
|
|
286
|
-
let code = "NETWORK_ERROR" /* NETWORK_ERROR */;
|
|
287
|
-
const errorCode = error.code;
|
|
288
|
-
const errorMessage = message ?? resolveLowLevelErrorMessage({ errorCode, url });
|
|
289
|
-
super({ message: errorMessage, code });
|
|
290
|
-
this.name = ERROR_NAMES.COPILOT_KIT_LOW_LEVEL_ERROR;
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
var ResolvedCopilotKitError = class extends CopilotKitError {
|
|
294
|
-
constructor({
|
|
295
|
-
status,
|
|
296
|
-
message,
|
|
297
|
-
code,
|
|
298
|
-
isRemoteEndpoint,
|
|
299
|
-
url
|
|
300
|
-
}) {
|
|
301
|
-
let resolvedCode = code;
|
|
302
|
-
if (!resolvedCode) {
|
|
303
|
-
switch (status) {
|
|
304
|
-
case 400:
|
|
305
|
-
throw new CopilotKitApiDiscoveryError({ message, url });
|
|
306
|
-
case 404:
|
|
307
|
-
throw isRemoteEndpoint ? new CopilotKitRemoteEndpointDiscoveryError({ message, url }) : new CopilotKitApiDiscoveryError({ message, url });
|
|
308
|
-
default:
|
|
309
|
-
resolvedCode = "UNKNOWN" /* UNKNOWN */;
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
super({ message, code: resolvedCode });
|
|
314
|
-
this.name = ERROR_NAMES.RESOLVED_COPILOT_KIT_ERROR;
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
var ConfigurationError = class extends CopilotKitError {
|
|
318
|
-
constructor(message) {
|
|
319
|
-
super({ message, code: "CONFIGURATION_ERROR" /* CONFIGURATION_ERROR */ });
|
|
320
|
-
this.name = ERROR_NAMES.CONFIGURATION_ERROR;
|
|
321
|
-
this.severity = "warning" /* WARNING */;
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
var MissingPublicApiKeyError = class extends ConfigurationError {
|
|
325
|
-
constructor(message) {
|
|
326
|
-
super(message);
|
|
327
|
-
this.name = ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR;
|
|
328
|
-
this.severity = "critical" /* CRITICAL */;
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
var UpgradeRequiredError = class extends ConfigurationError {
|
|
332
|
-
constructor(message) {
|
|
333
|
-
super(message);
|
|
334
|
-
this.name = ERROR_NAMES.UPGRADE_REQUIRED_ERROR;
|
|
335
|
-
this.severity = "warning" /* WARNING */;
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
function isStructuredCopilotKitError(error) {
|
|
339
|
-
var _a;
|
|
340
|
-
return error instanceof CopilotKitError || error instanceof CopilotKitLowLevelError || (error == null ? void 0 : error.name) && error.name.includes("CopilotKit") || ((_a = error == null ? void 0 : error.extensions) == null ? void 0 : _a.code) !== void 0;
|
|
341
|
-
}
|
|
342
|
-
function ensureStructuredError(error, converter) {
|
|
343
|
-
return isStructuredCopilotKitError(error) ? error : converter(error);
|
|
344
|
-
}
|
|
345
|
-
async function getPossibleVersionMismatch({
|
|
346
|
-
runtimeVersion,
|
|
347
|
-
runtimeClientGqlVersion
|
|
348
|
-
}) {
|
|
349
|
-
if (!runtimeVersion || runtimeVersion === "" || !runtimeClientGqlVersion)
|
|
350
|
-
return;
|
|
351
|
-
if (COPILOTKIT_VERSION !== runtimeVersion || COPILOTKIT_VERSION !== runtimeClientGqlVersion || runtimeVersion !== runtimeClientGqlVersion) {
|
|
352
|
-
return {
|
|
353
|
-
runtimeVersion,
|
|
354
|
-
runtimeClientGqlVersion,
|
|
355
|
-
reactCoreVersion: COPILOTKIT_VERSION,
|
|
356
|
-
message: getVersionMismatchErrorMessage({
|
|
357
|
-
runtimeVersion,
|
|
358
|
-
runtimeClientGqlVersion,
|
|
359
|
-
reactCoreVersion: COPILOTKIT_VERSION
|
|
360
|
-
})
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
var resolveLowLevelErrorMessage = ({
|
|
366
|
-
errorCode,
|
|
367
|
-
url
|
|
368
|
-
}) => {
|
|
369
|
-
const troubleshootingLink = ERROR_CONFIG["NETWORK_ERROR" /* NETWORK_ERROR */].troubleshootingUrl;
|
|
370
|
-
const genericMessage = (description = `Failed to fetch from url ${url}.`) => `${description}.
|
|
371
|
-
|
|
372
|
-
Possible reasons:
|
|
373
|
-
- -The server may have an error preventing it from returning a response (Check the server logs for more info).
|
|
374
|
-
- -The server might be down or unreachable
|
|
375
|
-
- -There might be a network issue (e.g., DNS failure, connection timeout)
|
|
376
|
-
- -The URL might be incorrect
|
|
377
|
-
- -The server is not running on the specified port
|
|
378
|
-
|
|
379
|
-
${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
380
|
-
if (url.includes("/info"))
|
|
381
|
-
return genericMessage(
|
|
382
|
-
`Failed to fetch CopilotKit agents/action information from url ${url}.`
|
|
383
|
-
);
|
|
384
|
-
if (url.includes("/actions/execute"))
|
|
385
|
-
return genericMessage(`Fetch call to ${url} to execute actions failed.`);
|
|
386
|
-
if (url.includes("/agents/state"))
|
|
387
|
-
return genericMessage(`Fetch call to ${url} to get agent state failed.`);
|
|
388
|
-
if (url.includes("/agents/execute"))
|
|
389
|
-
return genericMessage(`Fetch call to ${url} to execute agent(s) failed.`);
|
|
390
|
-
switch (errorCode) {
|
|
391
|
-
case "ECONNREFUSED":
|
|
392
|
-
return `Connection to ${url} was refused. Ensure the server is running and accessible.
|
|
393
|
-
|
|
394
|
-
${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
395
|
-
case "ENOTFOUND":
|
|
396
|
-
return `The server on ${url} could not be found. Check the URL or your network configuration.
|
|
397
|
-
|
|
398
|
-
${getSeeMoreMarkdown(ERROR_CONFIG["NOT_FOUND" /* NOT_FOUND */].troubleshootingUrl)}`;
|
|
399
|
-
case "ETIMEDOUT":
|
|
400
|
-
return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.
|
|
401
|
-
|
|
402
|
-
${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
403
|
-
default:
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
export {
|
|
409
|
-
Severity,
|
|
410
|
-
ErrorVisibility,
|
|
411
|
-
ERROR_NAMES,
|
|
412
|
-
BANNER_ERROR_NAMES,
|
|
413
|
-
COPILOT_CLOUD_ERROR_NAMES,
|
|
414
|
-
CopilotKitErrorCode,
|
|
415
|
-
ERROR_CONFIG,
|
|
416
|
-
CopilotKitError,
|
|
417
|
-
CopilotKitMisuseError,
|
|
418
|
-
CopilotKitVersionMismatchError,
|
|
419
|
-
CopilotKitApiDiscoveryError,
|
|
420
|
-
CopilotKitRemoteEndpointDiscoveryError,
|
|
421
|
-
CopilotKitAgentDiscoveryError,
|
|
422
|
-
CopilotKitLowLevelError,
|
|
423
|
-
ResolvedCopilotKitError,
|
|
424
|
-
ConfigurationError,
|
|
425
|
-
MissingPublicApiKeyError,
|
|
426
|
-
UpgradeRequiredError,
|
|
427
|
-
isStructuredCopilotKitError,
|
|
428
|
-
ensureStructuredError,
|
|
429
|
-
getPossibleVersionMismatch,
|
|
430
|
-
parseJson,
|
|
431
|
-
tryMap,
|
|
432
|
-
isMacOS,
|
|
433
|
-
COPILOTKIT_VERSION
|
|
434
|
-
};
|
|
435
|
-
//# sourceMappingURL=chunk-7KOT4KP4.mjs.map
|