@copilotkit/runtime 1.77.0 → 1.77.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/dist/_virtual/_rolldown/runtime.mjs +1 -25
- package/dist/lib/runtime/copilot-runtime.cjs +1 -0
- package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.cts +1 -0
- package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.mts +1 -0
- package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.mjs +1 -0
- package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
- package/dist/lib/telemetry-client.cjs +1 -1
- package/dist/lib/telemetry-client.mjs +1 -1
- package/dist/package.cjs +5 -5
- package/dist/package.mjs +5 -5
- package/dist/v2/runtime/core/channel-manager.cjs +15 -15
- package/dist/v2/runtime/core/channel-manager.cjs.map +1 -1
- package/dist/v2/runtime/core/channel-manager.d.cts.map +1 -1
- package/dist/v2/runtime/core/channel-manager.d.mts.map +1 -1
- package/dist/v2/runtime/core/channel-manager.mjs +15 -15
- package/dist/v2/runtime/core/channel-manager.mjs.map +1 -1
- package/dist/v2/runtime/core/package-info.cjs +10 -0
- package/dist/v2/runtime/core/package-info.cjs.map +1 -0
- package/dist/v2/runtime/core/package-info.mjs +8 -0
- package/dist/v2/runtime/core/package-info.mjs.map +1 -0
- package/dist/v2/runtime/core/runtime.cjs +4 -4
- package/dist/v2/runtime/core/runtime.cjs.map +1 -1
- package/dist/v2/runtime/core/runtime.d.cts +7 -1
- package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
- package/dist/v2/runtime/core/runtime.d.mts +7 -1
- package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
- package/dist/v2/runtime/core/runtime.mjs +4 -5
- package/dist/v2/runtime/core/runtime.mjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-trajectory-connect.cjs +1 -1
- package/dist/v2/runtime/handlers/handle-trajectory-connect.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-trajectory-connect.mjs +1 -1
- package/dist/v2/runtime/handlers/handle-trajectory-connect.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/memories.cjs +5 -17
- package/dist/v2/runtime/handlers/intelligence/memories.cjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/memories.mjs +5 -17
- package/dist/v2/runtime/handlers/intelligence/memories.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/run.cjs +43 -16
- package/dist/v2/runtime/handlers/intelligence/run.cjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/run.mjs +43 -16
- package/dist/v2/runtime/handlers/intelligence/run.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/threads.cjs +4 -3
- package/dist/v2/runtime/handlers/intelligence/threads.cjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/threads.mjs +4 -3
- package/dist/v2/runtime/handlers/intelligence/threads.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/mcp-apps-servers.cjs +1 -2
- package/dist/v2/runtime/handlers/shared/mcp-apps-servers.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/mcp-apps-servers.mjs +1 -2
- package/dist/v2/runtime/handlers/shared/mcp-apps-servers.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/platform-error.cjs +40 -0
- package/dist/v2/runtime/handlers/shared/platform-error.cjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/platform-error.mjs +40 -0
- package/dist/v2/runtime/handlers/shared/platform-error.mjs.map +1 -0
- package/dist/v2/runtime/intelligence-platform/client.cjs +59 -17
- package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.cts +21 -0
- package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.mts +21 -0
- package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.mjs +59 -17
- package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
- package/dist/v2/runtime/intelligence-platform/thread-lock-heartbeat.cjs +143 -0
- package/dist/v2/runtime/intelligence-platform/thread-lock-heartbeat.cjs.map +1 -0
- package/dist/v2/runtime/intelligence-platform/thread-lock-heartbeat.mjs +142 -0
- package/dist/v2/runtime/intelligence-platform/thread-lock-heartbeat.mjs.map +1 -0
- package/dist/v2/runtime/intelligence-platform/trajectories.cjs +19 -3
- package/dist/v2/runtime/intelligence-platform/trajectories.cjs.map +1 -1
- package/dist/v2/runtime/intelligence-platform/trajectories.d.cts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/trajectories.d.mts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/trajectories.mjs +19 -3
- package/dist/v2/runtime/intelligence-platform/trajectories.mjs.map +1 -1
- package/dist/v2/runtime/runner/intelligence.cjs +8 -1
- package/dist/v2/runtime/runner/intelligence.cjs.map +1 -1
- package/dist/v2/runtime/runner/intelligence.d.cts +12 -0
- package/dist/v2/runtime/runner/intelligence.d.cts.map +1 -1
- package/dist/v2/runtime/runner/intelligence.d.mts +12 -0
- package/dist/v2/runtime/runner/intelligence.d.mts.map +1 -1
- package/dist/v2/runtime/runner/intelligence.mjs +8 -1
- package/dist/v2/runtime/runner/intelligence.mjs.map +1 -1
- package/dist/v2/runtime/telemetry/telemetry-client.cjs +3 -4
- package/dist/v2/runtime/telemetry/telemetry-client.cjs.map +1 -1
- package/dist/v2/runtime/telemetry/telemetry-client.d.cts.map +1 -1
- package/dist/v2/runtime/telemetry/telemetry-client.d.mts.map +1 -1
- package/dist/v2/runtime/telemetry/telemetry-client.mjs +3 -5
- package/dist/v2/runtime/telemetry/telemetry-client.mjs.map +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { PlatformRequestError } from "../../intelligence-platform/client.mjs";
|
|
3
|
+
import { errorResponse } from "./json-response.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/v2/runtime/handlers/shared/platform-error.ts
|
|
6
|
+
/**
|
|
7
|
+
* Map a thrown error from a platform call onto a `Response`.
|
|
8
|
+
*
|
|
9
|
+
* Extracted from the memory handlers, which had it first and alone; the thread
|
|
10
|
+
* handlers flattened every failure to 500, so a "this does not exist yet" was
|
|
11
|
+
* indistinguishable from "the platform is down". One copy, because two would
|
|
12
|
+
* drift the moment either grew a case.
|
|
13
|
+
*
|
|
14
|
+
* Forward only client-actionable **4xx** statuses verbatim (404 missing or
|
|
15
|
+
* wrong-scope, 409 conflict, 422 unprocessable) so a consumer can branch on
|
|
16
|
+
* them — a flat 500 erases that distinction. A platform **5xx**, or any non-4xx
|
|
17
|
+
* or malformed status, means this runtime is healthy but its dependency failed,
|
|
18
|
+
* so it surfaces as `502 Bad Gateway` rather than echoing the upstream status as
|
|
19
|
+
* if the runtime itself broke. That also avoids a `RangeError` from
|
|
20
|
+
* `new Response(..., { status })` on an out-of-range status. Anything that is
|
|
21
|
+
* not a platform error at all stays 500.
|
|
22
|
+
*
|
|
23
|
+
* A platform **401** is also 502: it rejects the runtime's own credentials
|
|
24
|
+
* (e.g. a rotated API key), not the end user, so forwarding it would tell the
|
|
25
|
+
* browser the user is unauthenticated for a fault only the server can fix. A
|
|
26
|
+
* **403** is different: the platform uses it to deny this user an action (e.g.
|
|
27
|
+
* a write to read-only memory), so it is forwarded like any other 4xx.
|
|
28
|
+
*/
|
|
29
|
+
function platformErrorResponse(error, message) {
|
|
30
|
+
if (error instanceof PlatformRequestError) {
|
|
31
|
+
const { status } = error;
|
|
32
|
+
if (Number.isInteger(status) && status >= 400 && status <= 499 && status !== 401) return errorResponse(message, status);
|
|
33
|
+
return errorResponse(message, 502);
|
|
34
|
+
}
|
|
35
|
+
return errorResponse(message, 500);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { platformErrorResponse };
|
|
40
|
+
//# sourceMappingURL=platform-error.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-error.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/shared/platform-error.ts"],"sourcesContent":["import { PlatformRequestError } from \"../../intelligence-platform/client\";\nimport { errorResponse } from \"./json-response\";\n\n/**\n * Map a thrown error from a platform call onto a `Response`.\n *\n * Extracted from the memory handlers, which had it first and alone; the thread\n * handlers flattened every failure to 500, so a \"this does not exist yet\" was\n * indistinguishable from \"the platform is down\". One copy, because two would\n * drift the moment either grew a case.\n *\n * Forward only client-actionable **4xx** statuses verbatim (404 missing or\n * wrong-scope, 409 conflict, 422 unprocessable) so a consumer can branch on\n * them — a flat 500 erases that distinction. A platform **5xx**, or any non-4xx\n * or malformed status, means this runtime is healthy but its dependency failed,\n * so it surfaces as `502 Bad Gateway` rather than echoing the upstream status as\n * if the runtime itself broke. That also avoids a `RangeError` from\n * `new Response(..., { status })` on an out-of-range status. Anything that is\n * not a platform error at all stays 500.\n *\n * A platform **401** is also 502: it rejects the runtime's own credentials\n * (e.g. a rotated API key), not the end user, so forwarding it would tell the\n * browser the user is unauthenticated for a fault only the server can fix. A\n * **403** is different: the platform uses it to deny this user an action (e.g.\n * a write to read-only memory), so it is forwarded like any other 4xx.\n */\nexport function platformErrorResponse(\n error: unknown,\n message: string,\n): Response {\n if (error instanceof PlatformRequestError) {\n const { status } = error;\n if (\n Number.isInteger(status) &&\n status >= 400 &&\n status <= 499 &&\n status !== 401\n ) {\n return errorResponse(message, status);\n }\n return errorResponse(message, 502);\n }\n return errorResponse(message, 500);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,sBACd,OACA,SACU;AACV,KAAI,iBAAiB,sBAAsB;EACzC,MAAM,EAAE,WAAW;AACnB,MACE,OAAO,UAAU,OAAO,IACxB,UAAU,OACV,UAAU,OACV,WAAW,IAEX,QAAO,cAAc,SAAS,OAAO;AAEvC,SAAO,cAAc,SAAS,IAAI;;AAEpC,QAAO,cAAc,SAAS,IAAI"}
|
|
@@ -146,6 +146,24 @@ var PlatformRequestError = class extends Error {
|
|
|
146
146
|
this.name = "PlatformRequestError";
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* Read the platform's `retryable` hint from an error response body. The
|
|
151
|
+
* platform sends `{ error: { code, message, category, retryable } }`; anything
|
|
152
|
+
* else (non-JSON, proxies, older platforms) yields `undefined`.
|
|
153
|
+
*/
|
|
154
|
+
function readErrorBodyRetryable(text) {
|
|
155
|
+
if (!text) return void 0;
|
|
156
|
+
try {
|
|
157
|
+
const body = JSON.parse(text);
|
|
158
|
+
if (typeof body !== "object" || body === null) return void 0;
|
|
159
|
+
const error = body.error;
|
|
160
|
+
if (typeof error !== "object" || error === null) return void 0;
|
|
161
|
+
const retryable = error.retryable;
|
|
162
|
+
return typeof retryable === "boolean" ? retryable : void 0;
|
|
163
|
+
} catch {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
149
167
|
/** Copy a public Runtime entitlement so callers cannot mutate cached authority. */
|
|
150
168
|
function cloneRuntimeEntitlementResponse(response) {
|
|
151
169
|
if (response.status === "ready") return {
|
|
@@ -628,24 +646,34 @@ var CopilotKitIntelligence = class {
|
|
|
628
646
|
}
|
|
629
647
|
/** Mint a browser capture grant using only the Runtime's project and user. */
|
|
630
648
|
async ɵconnectTrajectory(params) {
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
649
|
+
let response;
|
|
650
|
+
try {
|
|
651
|
+
response = await fetch(`${this.#apiUrl}/api/trajectories/join`, {
|
|
652
|
+
method: "POST",
|
|
653
|
+
headers: {
|
|
654
|
+
Authorization: `Bearer ${this.#apiKey}`,
|
|
655
|
+
"Content-Type": "application/json"
|
|
656
|
+
},
|
|
657
|
+
body: JSON.stringify({
|
|
658
|
+
trajectoryId: params.trajectoryId,
|
|
659
|
+
appUserId: params.user.id
|
|
660
|
+
}),
|
|
661
|
+
signal: params.signal,
|
|
662
|
+
redirect: "error"
|
|
663
|
+
});
|
|
664
|
+
} catch (error) {
|
|
665
|
+
if (!params.signal?.aborted) _copilotkit_shared.logger.warn({
|
|
666
|
+
error: error instanceof Error ? error.name : typeof error,
|
|
667
|
+
causeCode: networkErrorCode(error instanceof Error ? error.cause : void 0),
|
|
668
|
+
host: urlHost(this.#apiUrl)
|
|
669
|
+
}, "Could not reach Intelligence to connect a Trajectory");
|
|
670
|
+
throw error;
|
|
671
|
+
}
|
|
644
672
|
const payload = await response.json().catch(() => void 0);
|
|
645
673
|
if (!response.ok) throw require_trajectories.trajectoryResponseError(payload, response.status, this.#apiKey);
|
|
646
674
|
return require_trajectories.parseTrajectoryConnectionGrant(payload, params.trajectoryId, this.ɵgetClientWsUrl());
|
|
647
675
|
}
|
|
648
|
-
async #request(method, path, body, extraHeaders) {
|
|
676
|
+
async #request(method, path, body, extraHeaders, signal) {
|
|
649
677
|
const url = `${this.#apiUrl}${path}`;
|
|
650
678
|
const headers = {
|
|
651
679
|
Authorization: `Bearer ${this.#apiKey}`,
|
|
@@ -655,7 +683,8 @@ var CopilotKitIntelligence = class {
|
|
|
655
683
|
const response = await fetch(url, {
|
|
656
684
|
method,
|
|
657
685
|
headers,
|
|
658
|
-
body: body ? JSON.stringify(body) : void 0
|
|
686
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
687
|
+
signal
|
|
659
688
|
});
|
|
660
689
|
if (!response.ok) {
|
|
661
690
|
const text = await response.text().catch(() => "");
|
|
@@ -664,7 +693,7 @@ var CopilotKitIntelligence = class {
|
|
|
664
693
|
body: text,
|
|
665
694
|
path
|
|
666
695
|
}, "Intelligence platform request failed");
|
|
667
|
-
throw new PlatformRequestError(`Intelligence platform error ${response.status}: ${text || response.statusText}`, response.status);
|
|
696
|
+
throw new PlatformRequestError(`Intelligence platform error ${response.status}: ${text || response.statusText}`, response.status, readErrorBodyRetryable(text));
|
|
668
697
|
}
|
|
669
698
|
const text = await response.text();
|
|
670
699
|
if (!text) return;
|
|
@@ -1030,7 +1059,7 @@ var CopilotKitIntelligence = class {
|
|
|
1030
1059
|
runId: params.runId,
|
|
1031
1060
|
ttlSeconds: params.ttlSeconds,
|
|
1032
1061
|
...params.lockKeyPrefix !== void 0 ? { lockKeyPrefix: params.lockKeyPrefix } : {}
|
|
1033
|
-
});
|
|
1062
|
+
}, void 0, params.signal);
|
|
1034
1063
|
}
|
|
1035
1064
|
async ɵgetActiveJoinCode(params) {
|
|
1036
1065
|
const qs = new URLSearchParams({ userId: params.userId }).toString();
|
|
@@ -1095,6 +1124,19 @@ function deriveRunnerWsUrl(wsUrl) {
|
|
|
1095
1124
|
if (wsUrl.endsWith("/channels")) return `${wsUrl.slice(0, -9)}/runner`;
|
|
1096
1125
|
return `${wsUrl}/runner`;
|
|
1097
1126
|
}
|
|
1127
|
+
/** A system error code such as ECONNREFUSED, or undefined for anything else. */
|
|
1128
|
+
function networkErrorCode(cause) {
|
|
1129
|
+
const code = typeof cause === "object" && cause !== null && "code" in cause ? cause.code : void 0;
|
|
1130
|
+
return typeof code === "string" && /^[A-Z][A-Z0-9_]{0,63}$/.test(code) ? code : void 0;
|
|
1131
|
+
}
|
|
1132
|
+
/** The host of a URL without its credentials, path or query. */
|
|
1133
|
+
function urlHost(url) {
|
|
1134
|
+
try {
|
|
1135
|
+
return new URL(url).host;
|
|
1136
|
+
} catch {
|
|
1137
|
+
return;
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1098
1140
|
function deriveClientWsUrl(wsUrl) {
|
|
1099
1141
|
if (wsUrl.endsWith("/client")) return wsUrl;
|
|
1100
1142
|
if (wsUrl.endsWith("/runner")) return `${wsUrl.slice(0, -7)}/client`;
|