@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/utils/index.js
DELETED
|
@@ -1,964 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/utils/index.ts
|
|
21
|
-
var utils_exports = {};
|
|
22
|
-
__export(utils_exports, {
|
|
23
|
-
BANNER_ERROR_NAMES: () => BANNER_ERROR_NAMES,
|
|
24
|
-
COPILOT_CLOUD_ERROR_NAMES: () => COPILOT_CLOUD_ERROR_NAMES,
|
|
25
|
-
ConfigurationError: () => ConfigurationError,
|
|
26
|
-
ConsoleColors: () => ConsoleColors,
|
|
27
|
-
ConsoleStyles: () => ConsoleStyles,
|
|
28
|
-
CopilotKitAgentDiscoveryError: () => CopilotKitAgentDiscoveryError,
|
|
29
|
-
CopilotKitApiDiscoveryError: () => CopilotKitApiDiscoveryError,
|
|
30
|
-
CopilotKitError: () => CopilotKitError,
|
|
31
|
-
CopilotKitErrorCode: () => CopilotKitErrorCode,
|
|
32
|
-
CopilotKitLowLevelError: () => CopilotKitLowLevelError,
|
|
33
|
-
CopilotKitMisuseError: () => CopilotKitMisuseError,
|
|
34
|
-
CopilotKitRemoteEndpointDiscoveryError: () => CopilotKitRemoteEndpointDiscoveryError,
|
|
35
|
-
CopilotKitVersionMismatchError: () => CopilotKitVersionMismatchError,
|
|
36
|
-
ERROR_CONFIG: () => ERROR_CONFIG,
|
|
37
|
-
ERROR_NAMES: () => ERROR_NAMES,
|
|
38
|
-
ErrorVisibility: () => ErrorVisibility,
|
|
39
|
-
MissingPublicApiKeyError: () => MissingPublicApiKeyError,
|
|
40
|
-
ResolvedCopilotKitError: () => ResolvedCopilotKitError,
|
|
41
|
-
Severity: () => Severity,
|
|
42
|
-
UpgradeRequiredError: () => UpgradeRequiredError,
|
|
43
|
-
actionParametersToJsonSchema: () => actionParametersToJsonSchema,
|
|
44
|
-
convertJsonSchemaToZodSchema: () => convertJsonSchemaToZodSchema,
|
|
45
|
-
dataToUUID: () => dataToUUID,
|
|
46
|
-
ensureStructuredError: () => ensureStructuredError,
|
|
47
|
-
executeConditions: () => executeConditions,
|
|
48
|
-
getPossibleVersionMismatch: () => getPossibleVersionMismatch,
|
|
49
|
-
getZodParameters: () => getZodParameters,
|
|
50
|
-
isMacOS: () => isMacOS,
|
|
51
|
-
isStructuredCopilotKitError: () => isStructuredCopilotKitError,
|
|
52
|
-
isValidUUID: () => isValidUUID,
|
|
53
|
-
jsonSchemaToActionParameters: () => jsonSchemaToActionParameters,
|
|
54
|
-
logCopilotKitPlatformMessage: () => logCopilotKitPlatformMessage,
|
|
55
|
-
logStyled: () => logStyled,
|
|
56
|
-
parseJson: () => parseJson,
|
|
57
|
-
publicApiKeyRequired: () => publicApiKeyRequired,
|
|
58
|
-
randomId: () => randomId,
|
|
59
|
-
randomUUID: () => randomUUID,
|
|
60
|
-
readBody: () => readBody,
|
|
61
|
-
styledConsole: () => styledConsole,
|
|
62
|
-
tryMap: () => tryMap
|
|
63
|
-
});
|
|
64
|
-
module.exports = __toCommonJS(utils_exports);
|
|
65
|
-
|
|
66
|
-
// src/utils/conditions.ts
|
|
67
|
-
function executeConditions({
|
|
68
|
-
conditions,
|
|
69
|
-
value
|
|
70
|
-
}) {
|
|
71
|
-
if (!(conditions == null ? void 0 : conditions.length))
|
|
72
|
-
return true;
|
|
73
|
-
return conditions.every((condition) => executeCondition(condition, value));
|
|
74
|
-
}
|
|
75
|
-
function executeCondition(condition, value) {
|
|
76
|
-
const targetValue = condition.path ? getValueFromPath(value, condition.path) : value;
|
|
77
|
-
switch (condition.rule) {
|
|
78
|
-
case "AND":
|
|
79
|
-
return condition.conditions.every(
|
|
80
|
-
(c) => executeCondition(c, value)
|
|
81
|
-
);
|
|
82
|
-
case "OR":
|
|
83
|
-
return condition.conditions.some(
|
|
84
|
-
(c) => executeCondition(c, value)
|
|
85
|
-
);
|
|
86
|
-
case "NOT":
|
|
87
|
-
return !condition.conditions.every(
|
|
88
|
-
(c) => executeCondition(c, value)
|
|
89
|
-
);
|
|
90
|
-
case "EQUALS":
|
|
91
|
-
return targetValue === condition.value;
|
|
92
|
-
case "NOT_EQUALS":
|
|
93
|
-
return targetValue !== condition.value;
|
|
94
|
-
case "GREATER_THAN":
|
|
95
|
-
return targetValue > condition.value;
|
|
96
|
-
case "LESS_THAN":
|
|
97
|
-
return targetValue < condition.value;
|
|
98
|
-
case "CONTAINS":
|
|
99
|
-
return Array.isArray(targetValue) && targetValue.includes(condition.value);
|
|
100
|
-
case "NOT_CONTAINS":
|
|
101
|
-
return Array.isArray(targetValue) && !targetValue.includes(condition.value);
|
|
102
|
-
case "MATCHES":
|
|
103
|
-
return new RegExp(condition.value).test(
|
|
104
|
-
String(targetValue)
|
|
105
|
-
);
|
|
106
|
-
case "STARTS_WITH":
|
|
107
|
-
return String(targetValue).startsWith(
|
|
108
|
-
condition.value
|
|
109
|
-
);
|
|
110
|
-
case "ENDS_WITH":
|
|
111
|
-
return String(targetValue).endsWith(
|
|
112
|
-
condition.value
|
|
113
|
-
);
|
|
114
|
-
case "EXISTS":
|
|
115
|
-
return targetValue !== void 0 && targetValue !== null;
|
|
116
|
-
case "NOT_EXISTS":
|
|
117
|
-
return targetValue === void 0 || targetValue === null;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function getValueFromPath(obj, path) {
|
|
121
|
-
return path.split(".").reduce((acc, part) => acc == null ? void 0 : acc[part], obj);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// src/utils/console-styling.ts
|
|
125
|
-
var ConsoleColors = {
|
|
126
|
-
/** Primary brand blue - for titles and links */
|
|
127
|
-
primary: "#007acc",
|
|
128
|
-
/** Success green - for positive messaging */
|
|
129
|
-
success: "#22c55e",
|
|
130
|
-
/** Purple - for feature highlights */
|
|
131
|
-
feature: "#a855f7",
|
|
132
|
-
/** Red - for calls-to-action */
|
|
133
|
-
cta: "#ef4444",
|
|
134
|
-
/** Cyan - for closing statements */
|
|
135
|
-
info: "#06b6d4",
|
|
136
|
-
/** Inherit console default - for body text */
|
|
137
|
-
inherit: "inherit",
|
|
138
|
-
/** Warning style */
|
|
139
|
-
warning: "#f59e0b"
|
|
140
|
-
};
|
|
141
|
-
var ConsoleStyles = {
|
|
142
|
-
/** Large header style */
|
|
143
|
-
header: `color: ${ConsoleColors.warning}; font-weight: bold; font-size: 16px;`,
|
|
144
|
-
/** Section header style */
|
|
145
|
-
section: `color: ${ConsoleColors.success}; font-weight: bold;`,
|
|
146
|
-
/** Feature highlight style */
|
|
147
|
-
highlight: `color: ${ConsoleColors.feature}; font-weight: bold;`,
|
|
148
|
-
/** Call-to-action style */
|
|
149
|
-
cta: `color: ${ConsoleColors.success}; font-weight: bold;`,
|
|
150
|
-
/** Info style */
|
|
151
|
-
info: `color: ${ConsoleColors.info}; font-weight: bold;`,
|
|
152
|
-
/** Link style */
|
|
153
|
-
link: `color: ${ConsoleColors.primary}; text-decoration: underline;`,
|
|
154
|
-
/** Body text - inherits console theme */
|
|
155
|
-
body: `color: ${ConsoleColors.inherit};`,
|
|
156
|
-
/** Warning style */
|
|
157
|
-
warning: `color: ${ConsoleColors.cta}; font-weight: bold;`
|
|
158
|
-
};
|
|
159
|
-
function logCopilotKitPlatformMessage() {
|
|
160
|
-
console.log(
|
|
161
|
-
`%cCopilotKit Warning%c
|
|
162
|
-
|
|
163
|
-
useCopilotChatHeadless_c provides full compatibility with CopilotKit's newly released Headless UI feature set. To enable this premium feature, add your public license key, available for free at:
|
|
164
|
-
|
|
165
|
-
%chttps://cloud.copilotkit.ai%c
|
|
166
|
-
|
|
167
|
-
Alternatively, useCopilotChat is available for basic programmatic control, and does not require an API key.
|
|
168
|
-
|
|
169
|
-
To learn more about premium features, read the documentation here:
|
|
170
|
-
|
|
171
|
-
%chttps://docs.copilotkit.ai/premium%c`,
|
|
172
|
-
ConsoleStyles.header,
|
|
173
|
-
ConsoleStyles.body,
|
|
174
|
-
ConsoleStyles.cta,
|
|
175
|
-
ConsoleStyles.body,
|
|
176
|
-
ConsoleStyles.link,
|
|
177
|
-
ConsoleStyles.body
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
function publicApiKeyRequired(feature) {
|
|
181
|
-
console.log(
|
|
182
|
-
`
|
|
183
|
-
%cCopilotKit Warning%c
|
|
184
|
-
|
|
185
|
-
In order to use ${feature}, you need to add your CopilotKit API key, available for free at https://cloud.copilotkit.ai.
|
|
186
|
-
`.trim(),
|
|
187
|
-
ConsoleStyles.header,
|
|
188
|
-
ConsoleStyles.body
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
function logStyled(template, styles) {
|
|
192
|
-
console.log(template, ...styles);
|
|
193
|
-
}
|
|
194
|
-
var styledConsole = {
|
|
195
|
-
/** Log a success message */
|
|
196
|
-
success: (message) => logStyled(`%c\u2705 ${message}`, [ConsoleStyles.section]),
|
|
197
|
-
/** Log an info message */
|
|
198
|
-
info: (message) => logStyled(`%c\u2139\uFE0F ${message}`, [ConsoleStyles.info]),
|
|
199
|
-
/** Log a feature highlight */
|
|
200
|
-
feature: (message) => logStyled(`%c\u2728 ${message}`, [ConsoleStyles.highlight]),
|
|
201
|
-
/** Log a call-to-action */
|
|
202
|
-
cta: (message) => logStyled(`%c\u{1F680} ${message}`, [ConsoleStyles.cta]),
|
|
203
|
-
/** Log the CopilotKit platform promotion */
|
|
204
|
-
logCopilotKitPlatformMessage,
|
|
205
|
-
/** Log a `publicApiKeyRequired` warning */
|
|
206
|
-
publicApiKeyRequired
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
// src/utils/errors.ts
|
|
210
|
-
var import_graphql = require("graphql");
|
|
211
|
-
|
|
212
|
-
// package.json
|
|
213
|
-
var version = "1.51.5-next.0";
|
|
214
|
-
|
|
215
|
-
// src/index.ts
|
|
216
|
-
var COPILOTKIT_VERSION = version;
|
|
217
|
-
|
|
218
|
-
// src/utils/errors.ts
|
|
219
|
-
var Severity = /* @__PURE__ */ ((Severity2) => {
|
|
220
|
-
Severity2["CRITICAL"] = "critical";
|
|
221
|
-
Severity2["WARNING"] = "warning";
|
|
222
|
-
Severity2["INFO"] = "info";
|
|
223
|
-
return Severity2;
|
|
224
|
-
})(Severity || {});
|
|
225
|
-
var ErrorVisibility = /* @__PURE__ */ ((ErrorVisibility2) => {
|
|
226
|
-
ErrorVisibility2["BANNER"] = "banner";
|
|
227
|
-
ErrorVisibility2["TOAST"] = "toast";
|
|
228
|
-
ErrorVisibility2["SILENT"] = "silent";
|
|
229
|
-
ErrorVisibility2["DEV_ONLY"] = "dev_only";
|
|
230
|
-
return ErrorVisibility2;
|
|
231
|
-
})(ErrorVisibility || {});
|
|
232
|
-
var ERROR_NAMES = {
|
|
233
|
-
COPILOT_ERROR: "CopilotError",
|
|
234
|
-
COPILOT_API_DISCOVERY_ERROR: "CopilotApiDiscoveryError",
|
|
235
|
-
COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR: "CopilotKitRemoteEndpointDiscoveryError",
|
|
236
|
-
COPILOT_KIT_AGENT_DISCOVERY_ERROR: "CopilotKitAgentDiscoveryError",
|
|
237
|
-
COPILOT_KIT_LOW_LEVEL_ERROR: "CopilotKitLowLevelError",
|
|
238
|
-
COPILOT_KIT_VERSION_MISMATCH_ERROR: "CopilotKitVersionMismatchError",
|
|
239
|
-
RESOLVED_COPILOT_KIT_ERROR: "ResolvedCopilotKitError",
|
|
240
|
-
CONFIGURATION_ERROR: "ConfigurationError",
|
|
241
|
-
MISSING_PUBLIC_API_KEY_ERROR: "MissingPublicApiKeyError",
|
|
242
|
-
UPGRADE_REQUIRED_ERROR: "UpgradeRequiredError"
|
|
243
|
-
};
|
|
244
|
-
var BANNER_ERROR_NAMES = [
|
|
245
|
-
ERROR_NAMES.CONFIGURATION_ERROR,
|
|
246
|
-
ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR,
|
|
247
|
-
ERROR_NAMES.UPGRADE_REQUIRED_ERROR,
|
|
248
|
-
ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR,
|
|
249
|
-
ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR,
|
|
250
|
-
ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR
|
|
251
|
-
];
|
|
252
|
-
var COPILOT_CLOUD_ERROR_NAMES = BANNER_ERROR_NAMES;
|
|
253
|
-
var CopilotKitErrorCode = /* @__PURE__ */ ((CopilotKitErrorCode2) => {
|
|
254
|
-
CopilotKitErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
255
|
-
CopilotKitErrorCode2["NOT_FOUND"] = "NOT_FOUND";
|
|
256
|
-
CopilotKitErrorCode2["AGENT_NOT_FOUND"] = "AGENT_NOT_FOUND";
|
|
257
|
-
CopilotKitErrorCode2["API_NOT_FOUND"] = "API_NOT_FOUND";
|
|
258
|
-
CopilotKitErrorCode2["REMOTE_ENDPOINT_NOT_FOUND"] = "REMOTE_ENDPOINT_NOT_FOUND";
|
|
259
|
-
CopilotKitErrorCode2["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
|
|
260
|
-
CopilotKitErrorCode2["MISUSE"] = "MISUSE";
|
|
261
|
-
CopilotKitErrorCode2["UNKNOWN"] = "UNKNOWN";
|
|
262
|
-
CopilotKitErrorCode2["VERSION_MISMATCH"] = "VERSION_MISMATCH";
|
|
263
|
-
CopilotKitErrorCode2["CONFIGURATION_ERROR"] = "CONFIGURATION_ERROR";
|
|
264
|
-
CopilotKitErrorCode2["MISSING_PUBLIC_API_KEY_ERROR"] = "MISSING_PUBLIC_API_KEY_ERROR";
|
|
265
|
-
CopilotKitErrorCode2["UPGRADE_REQUIRED_ERROR"] = "UPGRADE_REQUIRED_ERROR";
|
|
266
|
-
return CopilotKitErrorCode2;
|
|
267
|
-
})(CopilotKitErrorCode || {});
|
|
268
|
-
var BASE_URL = "https://docs.copilotkit.ai";
|
|
269
|
-
var getSeeMoreMarkdown = (link) => `See more: [${link}](${link})`;
|
|
270
|
-
var ERROR_CONFIG = {
|
|
271
|
-
["NETWORK_ERROR" /* NETWORK_ERROR */]: {
|
|
272
|
-
statusCode: 503,
|
|
273
|
-
troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
|
|
274
|
-
visibility: "banner" /* BANNER */,
|
|
275
|
-
severity: "critical" /* CRITICAL */
|
|
276
|
-
},
|
|
277
|
-
["NOT_FOUND" /* NOT_FOUND */]: {
|
|
278
|
-
statusCode: 404,
|
|
279
|
-
troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
|
|
280
|
-
visibility: "banner" /* BANNER */,
|
|
281
|
-
severity: "critical" /* CRITICAL */
|
|
282
|
-
},
|
|
283
|
-
["AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */]: {
|
|
284
|
-
statusCode: 500,
|
|
285
|
-
troubleshootingUrl: `${BASE_URL}/coagents/troubleshooting/common-issues#i-am-getting-agent-not-found-error`,
|
|
286
|
-
visibility: "banner" /* BANNER */,
|
|
287
|
-
severity: "critical" /* CRITICAL */
|
|
288
|
-
},
|
|
289
|
-
["API_NOT_FOUND" /* API_NOT_FOUND */]: {
|
|
290
|
-
statusCode: 404,
|
|
291
|
-
troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
|
|
292
|
-
visibility: "banner" /* BANNER */,
|
|
293
|
-
severity: "critical" /* CRITICAL */
|
|
294
|
-
},
|
|
295
|
-
["REMOTE_ENDPOINT_NOT_FOUND" /* REMOTE_ENDPOINT_NOT_FOUND */]: {
|
|
296
|
-
statusCode: 404,
|
|
297
|
-
troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-copilotkits-remote-endpoint-not-found-error`,
|
|
298
|
-
visibility: "banner" /* BANNER */,
|
|
299
|
-
severity: "critical" /* CRITICAL */
|
|
300
|
-
},
|
|
301
|
-
["AUTHENTICATION_ERROR" /* AUTHENTICATION_ERROR */]: {
|
|
302
|
-
statusCode: 401,
|
|
303
|
-
troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#authentication-errors`,
|
|
304
|
-
visibility: "banner" /* BANNER */,
|
|
305
|
-
severity: "critical" /* CRITICAL */
|
|
306
|
-
},
|
|
307
|
-
["MISUSE" /* MISUSE */]: {
|
|
308
|
-
statusCode: 400,
|
|
309
|
-
troubleshootingUrl: null,
|
|
310
|
-
visibility: "dev_only" /* DEV_ONLY */,
|
|
311
|
-
severity: "warning" /* WARNING */
|
|
312
|
-
},
|
|
313
|
-
["UNKNOWN" /* UNKNOWN */]: {
|
|
314
|
-
statusCode: 500,
|
|
315
|
-
visibility: "toast" /* TOAST */,
|
|
316
|
-
severity: "critical" /* CRITICAL */
|
|
317
|
-
},
|
|
318
|
-
["CONFIGURATION_ERROR" /* CONFIGURATION_ERROR */]: {
|
|
319
|
-
statusCode: 400,
|
|
320
|
-
troubleshootingUrl: null,
|
|
321
|
-
severity: "warning" /* WARNING */,
|
|
322
|
-
visibility: "banner" /* BANNER */
|
|
323
|
-
},
|
|
324
|
-
["MISSING_PUBLIC_API_KEY_ERROR" /* MISSING_PUBLIC_API_KEY_ERROR */]: {
|
|
325
|
-
statusCode: 400,
|
|
326
|
-
troubleshootingUrl: null,
|
|
327
|
-
severity: "critical" /* CRITICAL */,
|
|
328
|
-
visibility: "banner" /* BANNER */
|
|
329
|
-
},
|
|
330
|
-
["UPGRADE_REQUIRED_ERROR" /* UPGRADE_REQUIRED_ERROR */]: {
|
|
331
|
-
statusCode: 402,
|
|
332
|
-
troubleshootingUrl: null,
|
|
333
|
-
severity: "warning" /* WARNING */,
|
|
334
|
-
visibility: "banner" /* BANNER */
|
|
335
|
-
},
|
|
336
|
-
["VERSION_MISMATCH" /* VERSION_MISMATCH */]: {
|
|
337
|
-
statusCode: 400,
|
|
338
|
-
troubleshootingUrl: null,
|
|
339
|
-
visibility: "dev_only" /* DEV_ONLY */,
|
|
340
|
-
severity: "info" /* INFO */
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
var CopilotKitError = class extends import_graphql.GraphQLError {
|
|
344
|
-
constructor({
|
|
345
|
-
message = "Unknown error occurred",
|
|
346
|
-
code,
|
|
347
|
-
severity,
|
|
348
|
-
visibility
|
|
349
|
-
}) {
|
|
350
|
-
const name = ERROR_NAMES.COPILOT_ERROR;
|
|
351
|
-
const config = ERROR_CONFIG[code];
|
|
352
|
-
const { statusCode } = config;
|
|
353
|
-
const resolvedVisibility = visibility ?? config.visibility ?? "toast" /* TOAST */;
|
|
354
|
-
const resolvedSeverity = severity ?? ("severity" in config ? config.severity : void 0);
|
|
355
|
-
super(message, {
|
|
356
|
-
extensions: {
|
|
357
|
-
name,
|
|
358
|
-
statusCode,
|
|
359
|
-
code,
|
|
360
|
-
visibility: resolvedVisibility,
|
|
361
|
-
severity: resolvedSeverity,
|
|
362
|
-
troubleshootingUrl: "troubleshootingUrl" in config ? config.troubleshootingUrl : null,
|
|
363
|
-
originalError: {
|
|
364
|
-
message,
|
|
365
|
-
stack: new Error().stack
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
this.code = code;
|
|
370
|
-
this.name = name;
|
|
371
|
-
this.statusCode = statusCode;
|
|
372
|
-
this.severity = resolvedSeverity;
|
|
373
|
-
this.visibility = resolvedVisibility;
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
var CopilotKitMisuseError = class extends CopilotKitError {
|
|
377
|
-
constructor({
|
|
378
|
-
message,
|
|
379
|
-
code = "MISUSE" /* MISUSE */
|
|
380
|
-
}) {
|
|
381
|
-
const docsLink = "troubleshootingUrl" in ERROR_CONFIG[code] && ERROR_CONFIG[code].troubleshootingUrl ? getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl) : null;
|
|
382
|
-
const finalMessage = docsLink ? `${message}.
|
|
383
|
-
|
|
384
|
-
${docsLink}` : message;
|
|
385
|
-
super({ message: finalMessage, code });
|
|
386
|
-
this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
var getVersionMismatchErrorMessage = ({
|
|
390
|
-
reactCoreVersion,
|
|
391
|
-
runtimeVersion,
|
|
392
|
-
runtimeClientGqlVersion
|
|
393
|
-
}) => `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.`;
|
|
394
|
-
var CopilotKitVersionMismatchError = class extends CopilotKitError {
|
|
395
|
-
constructor({
|
|
396
|
-
reactCoreVersion,
|
|
397
|
-
runtimeVersion,
|
|
398
|
-
runtimeClientGqlVersion
|
|
399
|
-
}) {
|
|
400
|
-
const code = "VERSION_MISMATCH" /* VERSION_MISMATCH */;
|
|
401
|
-
super({
|
|
402
|
-
message: getVersionMismatchErrorMessage({
|
|
403
|
-
reactCoreVersion,
|
|
404
|
-
runtimeVersion,
|
|
405
|
-
runtimeClientGqlVersion
|
|
406
|
-
}),
|
|
407
|
-
code
|
|
408
|
-
});
|
|
409
|
-
this.name = ERROR_NAMES.COPILOT_KIT_VERSION_MISMATCH_ERROR;
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
var CopilotKitApiDiscoveryError = class extends CopilotKitError {
|
|
413
|
-
constructor(params = {}) {
|
|
414
|
-
const url = params.url ?? "";
|
|
415
|
-
let operationSuffix = "";
|
|
416
|
-
if (url == null ? void 0 : url.includes("/info"))
|
|
417
|
-
operationSuffix = `when fetching CopilotKit info`;
|
|
418
|
-
else if (url.includes("/actions/execute"))
|
|
419
|
-
operationSuffix = `when attempting to execute actions.`;
|
|
420
|
-
else if (url.includes("/agents/state"))
|
|
421
|
-
operationSuffix = `when attempting to get agent state.`;
|
|
422
|
-
else if (url.includes("/agents/execute"))
|
|
423
|
-
operationSuffix = `when attempting to execute agent(s).`;
|
|
424
|
-
const message = params.message ?? (params.url ? `Failed to find CopilotKit API endpoint at url ${params.url} ${operationSuffix}` : `Failed to find CopilotKit API endpoint.`);
|
|
425
|
-
const code = params.code ?? "API_NOT_FOUND" /* API_NOT_FOUND */;
|
|
426
|
-
const errorMessage = `${message}.
|
|
427
|
-
|
|
428
|
-
${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;
|
|
429
|
-
super({ message: errorMessage, code });
|
|
430
|
-
this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
var CopilotKitRemoteEndpointDiscoveryError = class extends CopilotKitApiDiscoveryError {
|
|
434
|
-
constructor(params) {
|
|
435
|
-
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");
|
|
436
|
-
const code = "REMOTE_ENDPOINT_NOT_FOUND" /* REMOTE_ENDPOINT_NOT_FOUND */;
|
|
437
|
-
super({ message, code });
|
|
438
|
-
this.name = ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR;
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
var CopilotKitAgentDiscoveryError = class extends CopilotKitError {
|
|
442
|
-
constructor(params) {
|
|
443
|
-
const { agentName, availableAgents } = params;
|
|
444
|
-
const code = "AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */;
|
|
445
|
-
const seeMore = getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl);
|
|
446
|
-
let message;
|
|
447
|
-
if (availableAgents.length) {
|
|
448
|
-
const agentList = availableAgents.map((agent) => agent.name).join(", ");
|
|
449
|
-
if (agentName) {
|
|
450
|
-
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.
|
|
451
|
-
|
|
452
|
-
${seeMore}`;
|
|
453
|
-
} else {
|
|
454
|
-
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.
|
|
455
|
-
|
|
456
|
-
${seeMore}`;
|
|
457
|
-
}
|
|
458
|
-
} else {
|
|
459
|
-
message = `${agentName ? `Agent '${agentName}'` : "The requested agent"} was not found. Please set up at least one agent before proceeding. ${seeMore}`;
|
|
460
|
-
}
|
|
461
|
-
super({ message, code });
|
|
462
|
-
this.name = ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR;
|
|
463
|
-
}
|
|
464
|
-
};
|
|
465
|
-
var CopilotKitLowLevelError = class extends CopilotKitError {
|
|
466
|
-
constructor({
|
|
467
|
-
error,
|
|
468
|
-
url,
|
|
469
|
-
message
|
|
470
|
-
}) {
|
|
471
|
-
let code = "NETWORK_ERROR" /* NETWORK_ERROR */;
|
|
472
|
-
const errorCode = error.code;
|
|
473
|
-
const errorMessage = message ?? resolveLowLevelErrorMessage({ errorCode, url });
|
|
474
|
-
super({ message: errorMessage, code });
|
|
475
|
-
this.name = ERROR_NAMES.COPILOT_KIT_LOW_LEVEL_ERROR;
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
var ResolvedCopilotKitError = class extends CopilotKitError {
|
|
479
|
-
constructor({
|
|
480
|
-
status,
|
|
481
|
-
message,
|
|
482
|
-
code,
|
|
483
|
-
isRemoteEndpoint,
|
|
484
|
-
url
|
|
485
|
-
}) {
|
|
486
|
-
let resolvedCode = code;
|
|
487
|
-
if (!resolvedCode) {
|
|
488
|
-
switch (status) {
|
|
489
|
-
case 400:
|
|
490
|
-
throw new CopilotKitApiDiscoveryError({ message, url });
|
|
491
|
-
case 404:
|
|
492
|
-
throw isRemoteEndpoint ? new CopilotKitRemoteEndpointDiscoveryError({ message, url }) : new CopilotKitApiDiscoveryError({ message, url });
|
|
493
|
-
default:
|
|
494
|
-
resolvedCode = "UNKNOWN" /* UNKNOWN */;
|
|
495
|
-
break;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
super({ message, code: resolvedCode });
|
|
499
|
-
this.name = ERROR_NAMES.RESOLVED_COPILOT_KIT_ERROR;
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
var ConfigurationError = class extends CopilotKitError {
|
|
503
|
-
constructor(message) {
|
|
504
|
-
super({ message, code: "CONFIGURATION_ERROR" /* CONFIGURATION_ERROR */ });
|
|
505
|
-
this.name = ERROR_NAMES.CONFIGURATION_ERROR;
|
|
506
|
-
this.severity = "warning" /* WARNING */;
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
var MissingPublicApiKeyError = class extends ConfigurationError {
|
|
510
|
-
constructor(message) {
|
|
511
|
-
super(message);
|
|
512
|
-
this.name = ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR;
|
|
513
|
-
this.severity = "critical" /* CRITICAL */;
|
|
514
|
-
}
|
|
515
|
-
};
|
|
516
|
-
var UpgradeRequiredError = class extends ConfigurationError {
|
|
517
|
-
constructor(message) {
|
|
518
|
-
super(message);
|
|
519
|
-
this.name = ERROR_NAMES.UPGRADE_REQUIRED_ERROR;
|
|
520
|
-
this.severity = "warning" /* WARNING */;
|
|
521
|
-
}
|
|
522
|
-
};
|
|
523
|
-
function isStructuredCopilotKitError(error) {
|
|
524
|
-
var _a;
|
|
525
|
-
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;
|
|
526
|
-
}
|
|
527
|
-
function ensureStructuredError(error, converter) {
|
|
528
|
-
return isStructuredCopilotKitError(error) ? error : converter(error);
|
|
529
|
-
}
|
|
530
|
-
async function getPossibleVersionMismatch({
|
|
531
|
-
runtimeVersion,
|
|
532
|
-
runtimeClientGqlVersion
|
|
533
|
-
}) {
|
|
534
|
-
if (!runtimeVersion || runtimeVersion === "" || !runtimeClientGqlVersion)
|
|
535
|
-
return;
|
|
536
|
-
if (COPILOTKIT_VERSION !== runtimeVersion || COPILOTKIT_VERSION !== runtimeClientGqlVersion || runtimeVersion !== runtimeClientGqlVersion) {
|
|
537
|
-
return {
|
|
538
|
-
runtimeVersion,
|
|
539
|
-
runtimeClientGqlVersion,
|
|
540
|
-
reactCoreVersion: COPILOTKIT_VERSION,
|
|
541
|
-
message: getVersionMismatchErrorMessage({
|
|
542
|
-
runtimeVersion,
|
|
543
|
-
runtimeClientGqlVersion,
|
|
544
|
-
reactCoreVersion: COPILOTKIT_VERSION
|
|
545
|
-
})
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
return;
|
|
549
|
-
}
|
|
550
|
-
var resolveLowLevelErrorMessage = ({
|
|
551
|
-
errorCode,
|
|
552
|
-
url
|
|
553
|
-
}) => {
|
|
554
|
-
const troubleshootingLink = ERROR_CONFIG["NETWORK_ERROR" /* NETWORK_ERROR */].troubleshootingUrl;
|
|
555
|
-
const genericMessage = (description = `Failed to fetch from url ${url}.`) => `${description}.
|
|
556
|
-
|
|
557
|
-
Possible reasons:
|
|
558
|
-
- -The server may have an error preventing it from returning a response (Check the server logs for more info).
|
|
559
|
-
- -The server might be down or unreachable
|
|
560
|
-
- -There might be a network issue (e.g., DNS failure, connection timeout)
|
|
561
|
-
- -The URL might be incorrect
|
|
562
|
-
- -The server is not running on the specified port
|
|
563
|
-
|
|
564
|
-
${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
565
|
-
if (url.includes("/info"))
|
|
566
|
-
return genericMessage(
|
|
567
|
-
`Failed to fetch CopilotKit agents/action information from url ${url}.`
|
|
568
|
-
);
|
|
569
|
-
if (url.includes("/actions/execute"))
|
|
570
|
-
return genericMessage(`Fetch call to ${url} to execute actions failed.`);
|
|
571
|
-
if (url.includes("/agents/state"))
|
|
572
|
-
return genericMessage(`Fetch call to ${url} to get agent state failed.`);
|
|
573
|
-
if (url.includes("/agents/execute"))
|
|
574
|
-
return genericMessage(`Fetch call to ${url} to execute agent(s) failed.`);
|
|
575
|
-
switch (errorCode) {
|
|
576
|
-
case "ECONNREFUSED":
|
|
577
|
-
return `Connection to ${url} was refused. Ensure the server is running and accessible.
|
|
578
|
-
|
|
579
|
-
${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
580
|
-
case "ENOTFOUND":
|
|
581
|
-
return `The server on ${url} could not be found. Check the URL or your network configuration.
|
|
582
|
-
|
|
583
|
-
${getSeeMoreMarkdown(ERROR_CONFIG["NOT_FOUND" /* NOT_FOUND */].troubleshootingUrl)}`;
|
|
584
|
-
case "ETIMEDOUT":
|
|
585
|
-
return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.
|
|
586
|
-
|
|
587
|
-
${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
588
|
-
default:
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
};
|
|
592
|
-
|
|
593
|
-
// src/utils/json-schema.ts
|
|
594
|
-
var import_zod = require("zod");
|
|
595
|
-
function actionParametersToJsonSchema(actionParameters) {
|
|
596
|
-
let parameters = {};
|
|
597
|
-
for (let parameter of actionParameters || []) {
|
|
598
|
-
parameters[parameter.name] = convertAttribute(parameter);
|
|
599
|
-
}
|
|
600
|
-
let requiredParameterNames = [];
|
|
601
|
-
for (let arg of actionParameters || []) {
|
|
602
|
-
if (arg.required !== false) {
|
|
603
|
-
requiredParameterNames.push(arg.name);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
return {
|
|
607
|
-
type: "object",
|
|
608
|
-
properties: parameters,
|
|
609
|
-
required: requiredParameterNames
|
|
610
|
-
};
|
|
611
|
-
}
|
|
612
|
-
function jsonSchemaToActionParameters(jsonSchema) {
|
|
613
|
-
if (jsonSchema.type !== "object" || !jsonSchema.properties) {
|
|
614
|
-
return [];
|
|
615
|
-
}
|
|
616
|
-
const parameters = [];
|
|
617
|
-
const requiredFields = jsonSchema.required || [];
|
|
618
|
-
for (const [name, schema] of Object.entries(jsonSchema.properties)) {
|
|
619
|
-
const parameter = convertJsonSchemaToParameter(
|
|
620
|
-
name,
|
|
621
|
-
schema,
|
|
622
|
-
requiredFields.includes(name)
|
|
623
|
-
);
|
|
624
|
-
parameters.push(parameter);
|
|
625
|
-
}
|
|
626
|
-
return parameters;
|
|
627
|
-
}
|
|
628
|
-
function convertJsonSchemaToParameter(name, schema, isRequired) {
|
|
629
|
-
const baseParameter = {
|
|
630
|
-
name,
|
|
631
|
-
description: schema.description
|
|
632
|
-
};
|
|
633
|
-
if (!isRequired) {
|
|
634
|
-
baseParameter.required = false;
|
|
635
|
-
}
|
|
636
|
-
switch (schema.type) {
|
|
637
|
-
case "string":
|
|
638
|
-
return {
|
|
639
|
-
...baseParameter,
|
|
640
|
-
type: "string",
|
|
641
|
-
...schema.enum && { enum: schema.enum }
|
|
642
|
-
};
|
|
643
|
-
case "number":
|
|
644
|
-
case "boolean":
|
|
645
|
-
return {
|
|
646
|
-
...baseParameter,
|
|
647
|
-
type: schema.type
|
|
648
|
-
};
|
|
649
|
-
case "object":
|
|
650
|
-
if (schema.properties) {
|
|
651
|
-
const attributes = [];
|
|
652
|
-
const requiredFields = schema.required || [];
|
|
653
|
-
for (const [propName, propSchema] of Object.entries(
|
|
654
|
-
schema.properties
|
|
655
|
-
)) {
|
|
656
|
-
attributes.push(
|
|
657
|
-
convertJsonSchemaToParameter(
|
|
658
|
-
propName,
|
|
659
|
-
propSchema,
|
|
660
|
-
requiredFields.includes(propName)
|
|
661
|
-
)
|
|
662
|
-
);
|
|
663
|
-
}
|
|
664
|
-
return {
|
|
665
|
-
...baseParameter,
|
|
666
|
-
type: "object",
|
|
667
|
-
attributes
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
return {
|
|
671
|
-
...baseParameter,
|
|
672
|
-
type: "object"
|
|
673
|
-
};
|
|
674
|
-
case "array":
|
|
675
|
-
if (schema.items.type === "object" && "properties" in schema.items) {
|
|
676
|
-
const attributes = [];
|
|
677
|
-
const requiredFields = schema.items.required || [];
|
|
678
|
-
for (const [propName, propSchema] of Object.entries(
|
|
679
|
-
schema.items.properties || {}
|
|
680
|
-
)) {
|
|
681
|
-
attributes.push(
|
|
682
|
-
convertJsonSchemaToParameter(
|
|
683
|
-
propName,
|
|
684
|
-
propSchema,
|
|
685
|
-
requiredFields.includes(propName)
|
|
686
|
-
)
|
|
687
|
-
);
|
|
688
|
-
}
|
|
689
|
-
return {
|
|
690
|
-
...baseParameter,
|
|
691
|
-
type: "object[]",
|
|
692
|
-
attributes
|
|
693
|
-
};
|
|
694
|
-
} else if (schema.items.type === "array") {
|
|
695
|
-
throw new Error("Nested arrays are not supported");
|
|
696
|
-
} else {
|
|
697
|
-
return {
|
|
698
|
-
...baseParameter,
|
|
699
|
-
type: `${schema.items.type}[]`
|
|
700
|
-
};
|
|
701
|
-
}
|
|
702
|
-
default:
|
|
703
|
-
return {
|
|
704
|
-
...baseParameter,
|
|
705
|
-
type: "string"
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
function convertAttribute(attribute) {
|
|
710
|
-
var _a, _b, _c;
|
|
711
|
-
switch (attribute.type) {
|
|
712
|
-
case "string":
|
|
713
|
-
return {
|
|
714
|
-
type: "string",
|
|
715
|
-
description: attribute.description,
|
|
716
|
-
...attribute.enum && { enum: attribute.enum }
|
|
717
|
-
};
|
|
718
|
-
case "number":
|
|
719
|
-
case "boolean":
|
|
720
|
-
return {
|
|
721
|
-
type: attribute.type,
|
|
722
|
-
description: attribute.description
|
|
723
|
-
};
|
|
724
|
-
case "object":
|
|
725
|
-
case "object[]":
|
|
726
|
-
const properties = (_a = attribute.attributes) == null ? void 0 : _a.reduce(
|
|
727
|
-
(acc, attr) => {
|
|
728
|
-
acc[attr.name] = convertAttribute(attr);
|
|
729
|
-
return acc;
|
|
730
|
-
},
|
|
731
|
-
{}
|
|
732
|
-
);
|
|
733
|
-
const required = (_b = attribute.attributes) == null ? void 0 : _b.filter((attr) => attr.required !== false).map((attr) => attr.name);
|
|
734
|
-
if (attribute.type === "object[]") {
|
|
735
|
-
return {
|
|
736
|
-
type: "array",
|
|
737
|
-
items: {
|
|
738
|
-
type: "object",
|
|
739
|
-
...properties && { properties },
|
|
740
|
-
...required && required.length > 0 && { required }
|
|
741
|
-
},
|
|
742
|
-
description: attribute.description
|
|
743
|
-
};
|
|
744
|
-
}
|
|
745
|
-
return {
|
|
746
|
-
type: "object",
|
|
747
|
-
description: attribute.description,
|
|
748
|
-
...properties && { properties },
|
|
749
|
-
...required && required.length > 0 && { required }
|
|
750
|
-
};
|
|
751
|
-
default:
|
|
752
|
-
if ((_c = attribute.type) == null ? void 0 : _c.endsWith("[]")) {
|
|
753
|
-
const itemType = attribute.type.slice(0, -2);
|
|
754
|
-
return {
|
|
755
|
-
type: "array",
|
|
756
|
-
items: { type: itemType },
|
|
757
|
-
description: attribute.description
|
|
758
|
-
};
|
|
759
|
-
}
|
|
760
|
-
return {
|
|
761
|
-
type: "string",
|
|
762
|
-
description: attribute.description
|
|
763
|
-
};
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
function convertJsonSchemaToZodSchema(jsonSchema, required) {
|
|
767
|
-
if (jsonSchema.type === "object") {
|
|
768
|
-
const spec = {};
|
|
769
|
-
if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
|
|
770
|
-
return !required ? import_zod.z.object(spec).optional() : import_zod.z.object(spec);
|
|
771
|
-
}
|
|
772
|
-
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
773
|
-
spec[key] = convertJsonSchemaToZodSchema(
|
|
774
|
-
value,
|
|
775
|
-
jsonSchema.required ? jsonSchema.required.includes(key) : false
|
|
776
|
-
);
|
|
777
|
-
}
|
|
778
|
-
let schema = import_zod.z.object(spec).describe(jsonSchema.description);
|
|
779
|
-
return required ? schema : schema.optional();
|
|
780
|
-
} else if (jsonSchema.type === "string") {
|
|
781
|
-
let schema = import_zod.z.string().describe(jsonSchema.description);
|
|
782
|
-
return required ? schema : schema.optional();
|
|
783
|
-
} else if (jsonSchema.type === "number") {
|
|
784
|
-
let schema = import_zod.z.number().describe(jsonSchema.description);
|
|
785
|
-
return required ? schema : schema.optional();
|
|
786
|
-
} else if (jsonSchema.type === "boolean") {
|
|
787
|
-
let schema = import_zod.z.boolean().describe(jsonSchema.description);
|
|
788
|
-
return required ? schema : schema.optional();
|
|
789
|
-
} else if (jsonSchema.type === "array") {
|
|
790
|
-
let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
|
|
791
|
-
let schema = import_zod.z.array(itemSchema).describe(jsonSchema.description);
|
|
792
|
-
return required ? schema : schema.optional();
|
|
793
|
-
}
|
|
794
|
-
throw new Error("Invalid JSON schema");
|
|
795
|
-
}
|
|
796
|
-
function getZodParameters(parameters) {
|
|
797
|
-
if (!parameters)
|
|
798
|
-
return import_zod.z.object({});
|
|
799
|
-
const jsonParams = actionParametersToJsonSchema(parameters);
|
|
800
|
-
return convertJsonSchemaToZodSchema(jsonParams, true);
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
// src/utils/random-id.ts
|
|
804
|
-
var import_uuid = require("uuid");
|
|
805
|
-
function randomId() {
|
|
806
|
-
return "ck-" + (0, import_uuid.v4)();
|
|
807
|
-
}
|
|
808
|
-
function randomUUID() {
|
|
809
|
-
return (0, import_uuid.v4)();
|
|
810
|
-
}
|
|
811
|
-
function toSerializable(value) {
|
|
812
|
-
if (typeof value === "function") {
|
|
813
|
-
return value.toString();
|
|
814
|
-
}
|
|
815
|
-
if (Array.isArray(value)) {
|
|
816
|
-
return value.map(toSerializable);
|
|
817
|
-
}
|
|
818
|
-
if (value !== null && typeof value === "object") {
|
|
819
|
-
const result = {};
|
|
820
|
-
for (const key of Object.keys(value)) {
|
|
821
|
-
result[key] = toSerializable(value[key]);
|
|
822
|
-
}
|
|
823
|
-
return result;
|
|
824
|
-
}
|
|
825
|
-
return value;
|
|
826
|
-
}
|
|
827
|
-
function dataToUUID(input, namespace) {
|
|
828
|
-
const BASE_NAMESPACE = "e4b01160-ff74-4c6e-9b27-d53cd930fe8e";
|
|
829
|
-
const boundNamespace = namespace ? (0, import_uuid.v5)(namespace, BASE_NAMESPACE) : BASE_NAMESPACE;
|
|
830
|
-
const stringInput = typeof input === "string" ? input : JSON.stringify(toSerializable(input));
|
|
831
|
-
return (0, import_uuid.v5)(stringInput, boundNamespace);
|
|
832
|
-
}
|
|
833
|
-
function isValidUUID(uuid) {
|
|
834
|
-
return (0, import_uuid.validate)(uuid);
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
// src/utils/requests.ts
|
|
838
|
-
async function readBody(r) {
|
|
839
|
-
const method = "method" in r ? r.method.toUpperCase() : void 0;
|
|
840
|
-
if (method === "GET" || method === "HEAD") {
|
|
841
|
-
return void 0;
|
|
842
|
-
}
|
|
843
|
-
if (!("body" in r) || r.body == null) {
|
|
844
|
-
return void 0;
|
|
845
|
-
}
|
|
846
|
-
try {
|
|
847
|
-
return await r.clone().json();
|
|
848
|
-
} catch {
|
|
849
|
-
try {
|
|
850
|
-
const text = await r.clone().text();
|
|
851
|
-
const trimmed = text.trim();
|
|
852
|
-
if (trimmed.length === 0)
|
|
853
|
-
return text;
|
|
854
|
-
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
855
|
-
try {
|
|
856
|
-
return JSON.parse(trimmed);
|
|
857
|
-
} catch {
|
|
858
|
-
return text;
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
return text;
|
|
862
|
-
} catch {
|
|
863
|
-
try {
|
|
864
|
-
const c = r.clone();
|
|
865
|
-
const stream = c.body ?? null;
|
|
866
|
-
if (!stream)
|
|
867
|
-
return void 0;
|
|
868
|
-
const reader = stream.getReader();
|
|
869
|
-
const decoder = new TextDecoder();
|
|
870
|
-
let out = "";
|
|
871
|
-
while (true) {
|
|
872
|
-
const { done, value } = await reader.read();
|
|
873
|
-
if (done)
|
|
874
|
-
break;
|
|
875
|
-
if (typeof value === "string") {
|
|
876
|
-
out += value;
|
|
877
|
-
} else {
|
|
878
|
-
out += decoder.decode(value, { stream: true });
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
out += decoder.decode();
|
|
882
|
-
const trimmed = out.trim();
|
|
883
|
-
if (trimmed.length === 0)
|
|
884
|
-
return out;
|
|
885
|
-
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
886
|
-
try {
|
|
887
|
-
return JSON.parse(trimmed);
|
|
888
|
-
} catch {
|
|
889
|
-
return out;
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
return out;
|
|
893
|
-
} catch {
|
|
894
|
-
return void 0;
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
// src/utils/index.ts
|
|
901
|
-
function parseJson(json, fallback = "unset") {
|
|
902
|
-
try {
|
|
903
|
-
return JSON.parse(json);
|
|
904
|
-
} catch (e) {
|
|
905
|
-
return fallback === "unset" ? null : fallback;
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
function tryMap(items, callback) {
|
|
909
|
-
return items.reduce((acc, item, index, array) => {
|
|
910
|
-
try {
|
|
911
|
-
acc.push(callback(item, index, array));
|
|
912
|
-
} catch (error) {
|
|
913
|
-
console.error(error);
|
|
914
|
-
}
|
|
915
|
-
return acc;
|
|
916
|
-
}, []);
|
|
917
|
-
}
|
|
918
|
-
function isMacOS() {
|
|
919
|
-
return /Mac|iMac|Macintosh/i.test(navigator.userAgent);
|
|
920
|
-
}
|
|
921
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
922
|
-
0 && (module.exports = {
|
|
923
|
-
BANNER_ERROR_NAMES,
|
|
924
|
-
COPILOT_CLOUD_ERROR_NAMES,
|
|
925
|
-
ConfigurationError,
|
|
926
|
-
ConsoleColors,
|
|
927
|
-
ConsoleStyles,
|
|
928
|
-
CopilotKitAgentDiscoveryError,
|
|
929
|
-
CopilotKitApiDiscoveryError,
|
|
930
|
-
CopilotKitError,
|
|
931
|
-
CopilotKitErrorCode,
|
|
932
|
-
CopilotKitLowLevelError,
|
|
933
|
-
CopilotKitMisuseError,
|
|
934
|
-
CopilotKitRemoteEndpointDiscoveryError,
|
|
935
|
-
CopilotKitVersionMismatchError,
|
|
936
|
-
ERROR_CONFIG,
|
|
937
|
-
ERROR_NAMES,
|
|
938
|
-
ErrorVisibility,
|
|
939
|
-
MissingPublicApiKeyError,
|
|
940
|
-
ResolvedCopilotKitError,
|
|
941
|
-
Severity,
|
|
942
|
-
UpgradeRequiredError,
|
|
943
|
-
actionParametersToJsonSchema,
|
|
944
|
-
convertJsonSchemaToZodSchema,
|
|
945
|
-
dataToUUID,
|
|
946
|
-
ensureStructuredError,
|
|
947
|
-
executeConditions,
|
|
948
|
-
getPossibleVersionMismatch,
|
|
949
|
-
getZodParameters,
|
|
950
|
-
isMacOS,
|
|
951
|
-
isStructuredCopilotKitError,
|
|
952
|
-
isValidUUID,
|
|
953
|
-
jsonSchemaToActionParameters,
|
|
954
|
-
logCopilotKitPlatformMessage,
|
|
955
|
-
logStyled,
|
|
956
|
-
parseJson,
|
|
957
|
-
publicApiKeyRequired,
|
|
958
|
-
randomId,
|
|
959
|
-
randomUUID,
|
|
960
|
-
readBody,
|
|
961
|
-
styledConsole,
|
|
962
|
-
tryMap
|
|
963
|
-
});
|
|
964
|
-
//# sourceMappingURL=index.js.map
|