@copilotkit/runtime 2.0.0-rc.30 → 2.0.0-rc.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/agent/converters/aisdk.cjs +17 -0
- package/dist/agent/converters/aisdk.cjs.map +1 -1
- package/dist/agent/converters/aisdk.d.cts.map +1 -1
- package/dist/agent/converters/aisdk.d.mts.map +1 -1
- package/dist/agent/converters/aisdk.mjs +18 -2
- package/dist/agent/converters/aisdk.mjs.map +1 -1
- package/dist/agent/index.cjs +15 -4
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +2 -2
- package/dist/agent/index.d.cts.map +1 -1
- package/dist/agent/index.d.mts +2 -2
- package/dist/agent/index.d.mts.map +1 -1
- package/dist/agent/index.mjs +16 -5
- package/dist/agent/index.mjs.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/runtime/core/channel-manager.cjs +10 -1
- package/dist/runtime/core/channel-manager.cjs.map +1 -1
- package/dist/runtime/core/channel-manager.mjs +10 -1
- package/dist/runtime/core/channel-manager.mjs.map +1 -1
- package/dist/runtime/core/package-info.cjs +1 -1
- package/dist/runtime/core/package-info.mjs +1 -1
- package/dist/runtime/handlers/handle-run.cjs +5 -2
- package/dist/runtime/handlers/handle-run.cjs.map +1 -1
- package/dist/runtime/handlers/handle-run.mjs +5 -2
- package/dist/runtime/handlers/handle-run.mjs.map +1 -1
- package/dist/runtime/handlers/handle-suggest.cjs +4 -2
- package/dist/runtime/handlers/handle-suggest.cjs.map +1 -1
- package/dist/runtime/handlers/handle-suggest.mjs +4 -2
- package/dist/runtime/handlers/handle-suggest.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/run.cjs +24 -17
- package/dist/runtime/handlers/intelligence/run.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/run.mjs +24 -17
- package/dist/runtime/handlers/intelligence/run.mjs.map +1 -1
- package/dist/runtime/index.d.cts +1 -1
- package/dist/runtime/index.d.mts +1 -1
- package/dist/runtime/intelligence-platform/analytics-context.cjs +84 -0
- package/dist/runtime/intelligence-platform/analytics-context.cjs.map +1 -0
- package/dist/runtime/intelligence-platform/analytics-context.mjs +83 -0
- package/dist/runtime/intelligence-platform/analytics-context.mjs.map +1 -0
- package/dist/runtime/intelligence-platform/client.cjs +27 -0
- package/dist/runtime/intelligence-platform/client.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/client.d.cts +23 -0
- package/dist/runtime/intelligence-platform/client.d.cts.map +1 -1
- package/dist/runtime/intelligence-platform/client.d.mts +23 -0
- package/dist/runtime/intelligence-platform/client.d.mts.map +1 -1
- package/dist/runtime/intelligence-platform/client.mjs +27 -0
- package/dist/runtime/intelligence-platform/client.mjs.map +1 -1
- package/dist/runtime/intelligence-platform/stop-run.cjs +50 -0
- package/dist/runtime/intelligence-platform/stop-run.cjs.map +1 -0
- package/dist/runtime/intelligence-platform/stop-run.mjs +50 -0
- package/dist/runtime/intelligence-platform/stop-run.mjs.map +1 -0
- package/dist/runtime/runner/agent-runner.cjs.map +1 -1
- package/dist/runtime/runner/agent-runner.d.cts +9 -0
- package/dist/runtime/runner/agent-runner.d.cts.map +1 -1
- package/dist/runtime/runner/agent-runner.d.mts +9 -0
- package/dist/runtime/runner/agent-runner.d.mts.map +1 -1
- package/dist/runtime/runner/agent-runner.mjs.map +1 -1
- package/dist/runtime/runner/index.d.cts +1 -1
- package/dist/runtime/runner/index.d.mts +1 -1
- package/dist/runtime/runner/index.mjs +1 -1
- package/dist/runtime/runner/intelligence.cjs +50 -5
- package/dist/runtime/runner/intelligence.cjs.map +1 -1
- package/dist/runtime/runner/intelligence.d.cts +8 -1
- package/dist/runtime/runner/intelligence.d.cts.map +1 -1
- package/dist/runtime/runner/intelligence.d.mts +8 -1
- package/dist/runtime/runner/intelligence.d.mts.map +1 -1
- package/dist/runtime/runner/intelligence.mjs +50 -6
- package/dist/runtime/runner/intelligence.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
let phoenix = require("phoenix");
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/intelligence-platform/stop-run.ts
|
|
4
|
+
/** The thread channel command a browser's Stop sends. */
|
|
5
|
+
const STOP_RUN_EVENT = "stop_run";
|
|
6
|
+
/**
|
|
7
|
+
* Sends `stop_run` for one run on its thread's client channel, the message a
|
|
8
|
+
* browser's Stop sends, and resolves once Intelligence acknowledges it.
|
|
9
|
+
*
|
|
10
|
+
* Intelligence answers by storing the stop for the run and relaying it to the
|
|
11
|
+
* run's runner. The join token is single use, so the socket is closed after
|
|
12
|
+
* the one command and never reconnects.
|
|
13
|
+
*
|
|
14
|
+
* @throws when the socket, the join or the command is refused or unanswered,
|
|
15
|
+
* or when `signal` aborts.
|
|
16
|
+
*/
|
|
17
|
+
function sendStopRun(params) {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
if (params.signal?.aborted) {
|
|
20
|
+
reject(/* @__PURE__ */ new Error("Stopped before the stop could be sent"));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const socket = new phoenix.Socket(params.url, { params: { join_token: params.joinToken } });
|
|
24
|
+
const channel = socket.channel(`thread:${params.threadId}`, {
|
|
25
|
+
stream_mode: "run",
|
|
26
|
+
run_id: params.runId
|
|
27
|
+
});
|
|
28
|
+
let settled = false;
|
|
29
|
+
const finish = (error) => {
|
|
30
|
+
if (settled) return;
|
|
31
|
+
settled = true;
|
|
32
|
+
params.signal?.removeEventListener("abort", onAbort);
|
|
33
|
+
channel.leave();
|
|
34
|
+
socket.disconnect();
|
|
35
|
+
if (error) reject(error);
|
|
36
|
+
else resolve();
|
|
37
|
+
};
|
|
38
|
+
const onAbort = () => finish(/* @__PURE__ */ new Error("Stopped waiting for Intelligence to record the stop"));
|
|
39
|
+
params.signal?.addEventListener("abort", onAbort, { once: true });
|
|
40
|
+
socket.onError(() => finish(/* @__PURE__ */ new Error("Could not reach Intelligence to record the stop")));
|
|
41
|
+
channel.join().receive("ok", () => {
|
|
42
|
+
channel.push(STOP_RUN_EVENT, { run_id: params.runId }).receive("ok", () => finish()).receive("error", () => finish(/* @__PURE__ */ new Error("Intelligence refused the stop"))).receive("timeout", () => finish(/* @__PURE__ */ new Error("Intelligence did not answer the stop")));
|
|
43
|
+
}).receive("error", () => finish(/* @__PURE__ */ new Error("Intelligence refused the thread channel"))).receive("timeout", () => finish(/* @__PURE__ */ new Error("Intelligence did not answer the thread channel")));
|
|
44
|
+
socket.connect();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
exports.sendStopRun = sendStopRun;
|
|
50
|
+
//# sourceMappingURL=stop-run.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stop-run.cjs","names":["Socket"],"sources":["../../../src/runtime/intelligence-platform/stop-run.ts"],"sourcesContent":["import { Socket } from \"phoenix\";\n\n/** The thread channel command a browser's Stop sends. */\nconst STOP_RUN_EVENT = \"stop_run\";\n\n/**\n * Sends `stop_run` for one run on its thread's client channel, the message a\n * browser's Stop sends, and resolves once Intelligence acknowledges it.\n *\n * Intelligence answers by storing the stop for the run and relaying it to the\n * run's runner. The join token is single use, so the socket is closed after\n * the one command and never reconnects.\n *\n * @throws when the socket, the join or the command is refused or unanswered,\n * or when `signal` aborts.\n */\nexport function sendStopRun(params: {\n /** The Intelligence client websocket URL (`.../client`). */\n url: string;\n /** A fresh thread join token, as `POST /api/threads/:id/connect` mints it. */\n joinToken: string;\n threadId: string;\n runId: string;\n signal?: AbortSignal;\n}): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n if (params.signal?.aborted) {\n reject(new Error(\"Stopped before the stop could be sent\"));\n return;\n }\n const socket = new Socket(params.url, {\n params: { join_token: params.joinToken },\n });\n const channel = socket.channel(`thread:${params.threadId}`, {\n stream_mode: \"run\",\n run_id: params.runId,\n });\n\n let settled = false;\n const finish = (error?: Error) => {\n if (settled) return;\n settled = true;\n params.signal?.removeEventListener(\"abort\", onAbort);\n channel.leave();\n socket.disconnect();\n if (error) reject(error);\n else resolve();\n };\n const onAbort = () =>\n finish(new Error(\"Stopped waiting for Intelligence to record the stop\"));\n params.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\n socket.onError(() =>\n finish(new Error(\"Could not reach Intelligence to record the stop\")),\n );\n channel\n .join()\n .receive(\"ok\", () => {\n channel\n .push(STOP_RUN_EVENT, { run_id: params.runId })\n .receive(\"ok\", () => finish())\n .receive(\"error\", () =>\n finish(new Error(\"Intelligence refused the stop\")),\n )\n .receive(\"timeout\", () =>\n finish(new Error(\"Intelligence did not answer the stop\")),\n );\n })\n .receive(\"error\", () =>\n finish(new Error(\"Intelligence refused the thread channel\")),\n )\n .receive(\"timeout\", () =>\n finish(new Error(\"Intelligence did not answer the thread channel\")),\n );\n socket.connect();\n });\n}\n"],"mappings":";;;;AAGA,MAAM,iBAAiB;;;;;;;;;;;;AAavB,SAAgB,YAAY,QAQV;AAChB,QAAO,IAAI,SAAe,SAAS,WAAW;AAC5C,MAAI,OAAO,QAAQ,SAAS;AAC1B,0BAAO,IAAI,MAAM,wCAAwC,CAAC;AAC1D;;EAEF,MAAM,SAAS,IAAIA,eAAO,OAAO,KAAK,EACpC,QAAQ,EAAE,YAAY,OAAO,WAAW,EACzC,CAAC;EACF,MAAM,UAAU,OAAO,QAAQ,UAAU,OAAO,YAAY;GAC1D,aAAa;GACb,QAAQ,OAAO;GAChB,CAAC;EAEF,IAAI,UAAU;EACd,MAAM,UAAU,UAAkB;AAChC,OAAI,QAAS;AACb,aAAU;AACV,UAAO,QAAQ,oBAAoB,SAAS,QAAQ;AACpD,WAAQ,OAAO;AACf,UAAO,YAAY;AACnB,OAAI,MAAO,QAAO,MAAM;OACnB,UAAS;;EAEhB,MAAM,gBACJ,uBAAO,IAAI,MAAM,sDAAsD,CAAC;AAC1E,SAAO,QAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjE,SAAO,cACL,uBAAO,IAAI,MAAM,kDAAkD,CAAC,CACrE;AACD,UACG,MAAM,CACN,QAAQ,YAAY;AACnB,WACG,KAAK,gBAAgB,EAAE,QAAQ,OAAO,OAAO,CAAC,CAC9C,QAAQ,YAAY,QAAQ,CAAC,CAC7B,QAAQ,eACP,uBAAO,IAAI,MAAM,gCAAgC,CAAC,CACnD,CACA,QAAQ,iBACP,uBAAO,IAAI,MAAM,uCAAuC,CAAC,CAC1D;IACH,CACD,QAAQ,eACP,uBAAO,IAAI,MAAM,0CAA0C,CAAC,CAC7D,CACA,QAAQ,iBACP,uBAAO,IAAI,MAAM,iDAAiD,CAAC,CACpE;AACH,SAAO,SAAS;GAChB"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Socket } from "phoenix";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/intelligence-platform/stop-run.ts
|
|
4
|
+
/** The thread channel command a browser's Stop sends. */
|
|
5
|
+
const STOP_RUN_EVENT = "stop_run";
|
|
6
|
+
/**
|
|
7
|
+
* Sends `stop_run` for one run on its thread's client channel, the message a
|
|
8
|
+
* browser's Stop sends, and resolves once Intelligence acknowledges it.
|
|
9
|
+
*
|
|
10
|
+
* Intelligence answers by storing the stop for the run and relaying it to the
|
|
11
|
+
* run's runner. The join token is single use, so the socket is closed after
|
|
12
|
+
* the one command and never reconnects.
|
|
13
|
+
*
|
|
14
|
+
* @throws when the socket, the join or the command is refused or unanswered,
|
|
15
|
+
* or when `signal` aborts.
|
|
16
|
+
*/
|
|
17
|
+
function sendStopRun(params) {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
if (params.signal?.aborted) {
|
|
20
|
+
reject(/* @__PURE__ */ new Error("Stopped before the stop could be sent"));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const socket = new Socket(params.url, { params: { join_token: params.joinToken } });
|
|
24
|
+
const channel = socket.channel(`thread:${params.threadId}`, {
|
|
25
|
+
stream_mode: "run",
|
|
26
|
+
run_id: params.runId
|
|
27
|
+
});
|
|
28
|
+
let settled = false;
|
|
29
|
+
const finish = (error) => {
|
|
30
|
+
if (settled) return;
|
|
31
|
+
settled = true;
|
|
32
|
+
params.signal?.removeEventListener("abort", onAbort);
|
|
33
|
+
channel.leave();
|
|
34
|
+
socket.disconnect();
|
|
35
|
+
if (error) reject(error);
|
|
36
|
+
else resolve();
|
|
37
|
+
};
|
|
38
|
+
const onAbort = () => finish(/* @__PURE__ */ new Error("Stopped waiting for Intelligence to record the stop"));
|
|
39
|
+
params.signal?.addEventListener("abort", onAbort, { once: true });
|
|
40
|
+
socket.onError(() => finish(/* @__PURE__ */ new Error("Could not reach Intelligence to record the stop")));
|
|
41
|
+
channel.join().receive("ok", () => {
|
|
42
|
+
channel.push(STOP_RUN_EVENT, { run_id: params.runId }).receive("ok", () => finish()).receive("error", () => finish(/* @__PURE__ */ new Error("Intelligence refused the stop"))).receive("timeout", () => finish(/* @__PURE__ */ new Error("Intelligence did not answer the stop")));
|
|
43
|
+
}).receive("error", () => finish(/* @__PURE__ */ new Error("Intelligence refused the thread channel"))).receive("timeout", () => finish(/* @__PURE__ */ new Error("Intelligence did not answer the thread channel")));
|
|
44
|
+
socket.connect();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { sendStopRun };
|
|
50
|
+
//# sourceMappingURL=stop-run.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stop-run.mjs","names":[],"sources":["../../../src/runtime/intelligence-platform/stop-run.ts"],"sourcesContent":["import { Socket } from \"phoenix\";\n\n/** The thread channel command a browser's Stop sends. */\nconst STOP_RUN_EVENT = \"stop_run\";\n\n/**\n * Sends `stop_run` for one run on its thread's client channel, the message a\n * browser's Stop sends, and resolves once Intelligence acknowledges it.\n *\n * Intelligence answers by storing the stop for the run and relaying it to the\n * run's runner. The join token is single use, so the socket is closed after\n * the one command and never reconnects.\n *\n * @throws when the socket, the join or the command is refused or unanswered,\n * or when `signal` aborts.\n */\nexport function sendStopRun(params: {\n /** The Intelligence client websocket URL (`.../client`). */\n url: string;\n /** A fresh thread join token, as `POST /api/threads/:id/connect` mints it. */\n joinToken: string;\n threadId: string;\n runId: string;\n signal?: AbortSignal;\n}): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n if (params.signal?.aborted) {\n reject(new Error(\"Stopped before the stop could be sent\"));\n return;\n }\n const socket = new Socket(params.url, {\n params: { join_token: params.joinToken },\n });\n const channel = socket.channel(`thread:${params.threadId}`, {\n stream_mode: \"run\",\n run_id: params.runId,\n });\n\n let settled = false;\n const finish = (error?: Error) => {\n if (settled) return;\n settled = true;\n params.signal?.removeEventListener(\"abort\", onAbort);\n channel.leave();\n socket.disconnect();\n if (error) reject(error);\n else resolve();\n };\n const onAbort = () =>\n finish(new Error(\"Stopped waiting for Intelligence to record the stop\"));\n params.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\n socket.onError(() =>\n finish(new Error(\"Could not reach Intelligence to record the stop\")),\n );\n channel\n .join()\n .receive(\"ok\", () => {\n channel\n .push(STOP_RUN_EVENT, { run_id: params.runId })\n .receive(\"ok\", () => finish())\n .receive(\"error\", () =>\n finish(new Error(\"Intelligence refused the stop\")),\n )\n .receive(\"timeout\", () =>\n finish(new Error(\"Intelligence did not answer the stop\")),\n );\n })\n .receive(\"error\", () =>\n finish(new Error(\"Intelligence refused the thread channel\")),\n )\n .receive(\"timeout\", () =>\n finish(new Error(\"Intelligence did not answer the thread channel\")),\n );\n socket.connect();\n });\n}\n"],"mappings":";;;;AAGA,MAAM,iBAAiB;;;;;;;;;;;;AAavB,SAAgB,YAAY,QAQV;AAChB,QAAO,IAAI,SAAe,SAAS,WAAW;AAC5C,MAAI,OAAO,QAAQ,SAAS;AAC1B,0BAAO,IAAI,MAAM,wCAAwC,CAAC;AAC1D;;EAEF,MAAM,SAAS,IAAI,OAAO,OAAO,KAAK,EACpC,QAAQ,EAAE,YAAY,OAAO,WAAW,EACzC,CAAC;EACF,MAAM,UAAU,OAAO,QAAQ,UAAU,OAAO,YAAY;GAC1D,aAAa;GACb,QAAQ,OAAO;GAChB,CAAC;EAEF,IAAI,UAAU;EACd,MAAM,UAAU,UAAkB;AAChC,OAAI,QAAS;AACb,aAAU;AACV,UAAO,QAAQ,oBAAoB,SAAS,QAAQ;AACpD,WAAQ,OAAO;AACf,UAAO,YAAY;AACnB,OAAI,MAAO,QAAO,MAAM;OACnB,UAAS;;EAEhB,MAAM,gBACJ,uBAAO,IAAI,MAAM,sDAAsD,CAAC;AAC1E,SAAO,QAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjE,SAAO,cACL,uBAAO,IAAI,MAAM,kDAAkD,CAAC,CACrE;AACD,UACG,MAAM,CACN,QAAQ,YAAY;AACnB,WACG,KAAK,gBAAgB,EAAE,QAAQ,OAAO,OAAO,CAAC,CAC9C,QAAQ,YAAY,QAAQ,CAAC,CAC7B,QAAQ,eACP,uBAAO,IAAI,MAAM,gCAAgC,CAAC,CACnD,CACA,QAAQ,iBACP,uBAAO,IAAI,MAAM,uCAAuC,CAAC,CAC1D;IACH,CACD,QAAQ,eACP,uBAAO,IAAI,MAAM,0CAA0C,CAAC,CAC7D,CACA,QAAQ,iBACP,uBAAO,IAAI,MAAM,iDAAiD,CAAC,CACpE;AACH,SAAO,SAAS;GAChB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-runner.cjs","names":["THREAD_ALREADY_RUNNING_ERROR_CODE"],"sources":["../../../src/runtime/runner/agent-runner.ts"],"sourcesContent":["import type {\n AbstractAgent,\n BaseEvent,\n Message,\n RunAgentInput,\n} from \"@ag-ui/client\";\nimport type { Observable } from \"rxjs\";\nimport { THREAD_ALREADY_RUNNING_ERROR_CODE } from \"@copilotkit/shared\";\n\n/**\n * Thrown by a runner when the thread already has a run in flight. The SSE\n * handler sends it to the client as a `RUN_ERROR` with\n * {@link THREAD_ALREADY_RUNNING_ERROR_CODE}, matched on `code` so a copy of\n * this class from another package version still counts.\n */\nexport class ThreadAlreadyRunningError extends Error {\n readonly code = THREAD_ALREADY_RUNNING_ERROR_CODE;\n\n constructor() {\n super(\"Thread already running\");\n this.name = \"ThreadAlreadyRunningError\";\n }\n}\n\n/** `code` of {@link ThreadAccessDeniedError}, also sent on the SSE `RUN_ERROR`. */\nexport const THREAD_ACCESS_DENIED_ERROR_CODE = \"THREAD_ACCESS_DENIED\";\n\n/**\n * Thrown by a runner when a run targets a Thread that another identity owns.\n *\n * Defense in depth: the run handler checks `isThreadAccessible` first and\n * refuses with an HTTP error, so the runner throws this only when another\n * identity claims the Thread between that check and the run, or for direct\n * runner callers. A synchronous throw from `run()` is still mapped to the\n * HTTP error; a later one reaches the client as a `RUN_ERROR` with\n * {@link THREAD_ACCESS_DENIED_ERROR_CODE}. Neither is reported as an agent\n * failure. Matched on `code`, so a copy of this class from another package\n * version still counts.\n */\nexport class ThreadAccessDeniedError extends Error {\n readonly code = THREAD_ACCESS_DENIED_ERROR_CODE;\n\n constructor() {\n super(\"Thread access denied\");\n this.name = \"ThreadAccessDeniedError\";\n }\n}\n\n/** True for a {@link ThreadAccessDeniedError}, from any package version. */\nexport function isThreadAccessDeniedError(error: unknown): boolean {\n return (\n error instanceof Error &&\n (error as { code?: unknown }).code === THREAD_ACCESS_DENIED_ERROR_CODE\n );\n}\n\n/**\n * Owner of a Thread created, or reached, by a runner call that names no owner:\n * a run, connect, stop or isRunning without `ownerId`, or a Thread endpoint call\n * without a scope. Such calls come only from trusted server-side code (for\n * example a Channel listener), and they act as this one server identity.\n *\n * No HTTP caller can act as it: request identities are `\"\"` (anonymous) or an\n * id that `identifyUser` returned, and a valid id cannot hold a NUL character.\n * So an omitted owner never means \"every Thread\", and a Thread created\n * server-side is never reachable by an anonymous caller.\n */\nexport const ɵSERVER_THREAD_OWNER = \"\\u0000server\";\n\n/** The owner a runner call acts as: `ownerId`, or the server owner when omitted. */\nexport function ɵresolveThreadOwner(ownerId: string | undefined): string {\n return ownerId ?? ɵSERVER_THREAD_OWNER;\n}\n\nexport interface AgentRunnerRunRequest {\n threadId: string;\n /** Backend execution ID supplied by Intelligence for imported non-UUID sessions. */\n backendThreadId?: string;\n agent: AbstractAgent;\n input: RunAgentInput;\n persistedInputMessages?: Message[];\n /** Short-lived token scoped to this runner invocation. */\n authToken?: string;\n /**\n * Identity the run acts as. A runner that tracks owners records it on the\n * Thread's first run and refuses a run from any other identity. `\"\"` is the\n * anonymous owner. When omitted, the run acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n}\n\nexport interface AgentRunnerConnectRequest {\n threadId: string;\n agentId?: string;\n headers?: Record<string, string>;\n joinCode?: string;\n /**\n * Caller identity. A Thread owned by another identity is treated as unknown.\n * When omitted, the call acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n}\n\nexport interface AgentRunnerIsRunningRequest {\n threadId: string;\n /**\n * Caller identity. A Thread owned by another identity reports \"not running\".\n * When omitted, the call acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n}\n\nexport interface AgentRunnerStopRequest {\n threadId: string;\n /** When present, stop only this exact run and never a newer run on the Thread. */\n runId?: string;\n /**\n * Caller identity. A run on a Thread owned by another identity is not\n * stopped. When omitted, the call acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n}\n\nexport interface LocalThreadEndpointRecord {\n id: string;\n name: string | null;\n agentId: string;\n organizationId: string;\n createdById: string;\n archived: boolean;\n createdAt: string;\n updatedAt: string;\n}\n\n/**\n * Limits a local Thread endpoint call to the Threads of one owner. `\"\"` is the\n * anonymous owner. A call without a scope acts as\n * {@link ɵSERVER_THREAD_OWNER}: it sees only Threads created server-side, never\n * every Thread.\n */\nexport interface LocalThreadEndpointScope {\n ownerId: string;\n}\n\nexport interface LocalThreadEndpointRunner extends AgentRunner {\n readonly ɵsupportsLocalThreadEndpoints: true;\n listThreads(scope?: LocalThreadEndpointScope): LocalThreadEndpointRecord[];\n getThreadMessages(\n threadId: string,\n scope?: LocalThreadEndpointScope,\n ): Message[];\n getThreadEvents(\n threadId: string,\n scope?: LocalThreadEndpointScope,\n ): BaseEvent[];\n getThreadState(\n threadId: string,\n scope?: LocalThreadEndpointScope,\n ): Record<string, unknown> | null;\n clearThreads(scope?: LocalThreadEndpointScope): void;\n /** See {@link ThreadOwnershipRunner.isThreadAccessible}. */\n isThreadAccessible(\n threadId: string,\n scope: LocalThreadEndpointScope,\n ): boolean;\n}\n\nexport function supportsLocalThreadEndpoints(\n runner: AgentRunner,\n): runner is LocalThreadEndpointRunner {\n return runner.ɵsupportsLocalThreadEndpoints === true;\n}\n\n/**\n * A runner that records each Thread's owner and enforces it. Implementing\n * `isThreadAccessible` is the promise that `run`, `connect`, `stop` and\n * `isRunning` honor `ownerId` the same way: a call never reaches a Thread that\n * another owner holds.\n */\nexport interface ThreadOwnershipRunner extends AgentRunner {\n /** False when the Thread id is held by an owner other than `scope`'s. */\n isThreadAccessible(\n threadId: string,\n scope: LocalThreadEndpointScope,\n ): boolean | Promise<boolean>;\n}\n\n/**\n * True when `runner` enforces Thread owners. Checks the method itself, so a\n * runner built against an older interface (one that sets the endpoint flag\n * but has no `isThreadAccessible`) is not taken to enforce them.\n */\nexport function enforcesThreadOwnership(\n runner: AgentRunner,\n): runner is ThreadOwnershipRunner {\n return typeof runner.isThreadAccessible === \"function\";\n}\n\nexport abstract class AgentRunner {\n readonly ɵsupportsLocalThreadEndpoints?: boolean;\n\n /** See {@link ThreadOwnershipRunner}. Optional: not every runner tracks owners. */\n isThreadAccessible?(\n threadId: string,\n scope: LocalThreadEndpointScope,\n ): boolean | Promise<boolean>;\n\n abstract run(request: AgentRunnerRunRequest): Observable<BaseEvent>;\n abstract connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;\n abstract isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean>;\n abstract stop(request: AgentRunnerStopRequest): Promise<boolean | undefined>;\n}\n"],"mappings":";;;;;;;;;AAeA,IAAa,4BAAb,cAA+C,MAAM;CAGnD,cAAc;AACZ,QAAM,yBAAyB;cAHjBA;AAId,OAAK,OAAO;;;;AAKhB,MAAa,kCAAkC;;;;;;;;;;;;;AAc/C,IAAa,0BAAb,cAA6C,MAAM;CAGjD,cAAc;AACZ,QAAM,uBAAuB;cAHf;AAId,OAAK,OAAO;;;;AAKhB,SAAgB,0BAA0B,OAAyB;AACjE,QACE,iBAAiB,SAChB,MAA6B,SAAS;;;;;;;;;;;;;AAe3C,MAAa,uBAAuB;;AAGpC,SAAgB,oBAAoB,SAAqC;AACvE,QAAO,WAAW;;
|
|
1
|
+
{"version":3,"file":"agent-runner.cjs","names":["THREAD_ALREADY_RUNNING_ERROR_CODE"],"sources":["../../../src/runtime/runner/agent-runner.ts"],"sourcesContent":["import type {\n AbstractAgent,\n BaseEvent,\n Message,\n RunAgentInput,\n} from \"@ag-ui/client\";\nimport type { Observable } from \"rxjs\";\nimport { THREAD_ALREADY_RUNNING_ERROR_CODE } from \"@copilotkit/shared\";\n\n/**\n * Thrown by a runner when the thread already has a run in flight. The SSE\n * handler sends it to the client as a `RUN_ERROR` with\n * {@link THREAD_ALREADY_RUNNING_ERROR_CODE}, matched on `code` so a copy of\n * this class from another package version still counts.\n */\nexport class ThreadAlreadyRunningError extends Error {\n readonly code = THREAD_ALREADY_RUNNING_ERROR_CODE;\n\n constructor() {\n super(\"Thread already running\");\n this.name = \"ThreadAlreadyRunningError\";\n }\n}\n\n/** `code` of {@link ThreadAccessDeniedError}, also sent on the SSE `RUN_ERROR`. */\nexport const THREAD_ACCESS_DENIED_ERROR_CODE = \"THREAD_ACCESS_DENIED\";\n\n/**\n * Thrown by a runner when a run targets a Thread that another identity owns.\n *\n * Defense in depth: the run handler checks `isThreadAccessible` first and\n * refuses with an HTTP error, so the runner throws this only when another\n * identity claims the Thread between that check and the run, or for direct\n * runner callers. A synchronous throw from `run()` is still mapped to the\n * HTTP error; a later one reaches the client as a `RUN_ERROR` with\n * {@link THREAD_ACCESS_DENIED_ERROR_CODE}. Neither is reported as an agent\n * failure. Matched on `code`, so a copy of this class from another package\n * version still counts.\n */\nexport class ThreadAccessDeniedError extends Error {\n readonly code = THREAD_ACCESS_DENIED_ERROR_CODE;\n\n constructor() {\n super(\"Thread access denied\");\n this.name = \"ThreadAccessDeniedError\";\n }\n}\n\n/** True for a {@link ThreadAccessDeniedError}, from any package version. */\nexport function isThreadAccessDeniedError(error: unknown): boolean {\n return (\n error instanceof Error &&\n (error as { code?: unknown }).code === THREAD_ACCESS_DENIED_ERROR_CODE\n );\n}\n\n/**\n * Owner of a Thread created, or reached, by a runner call that names no owner:\n * a run, connect, stop or isRunning without `ownerId`, or a Thread endpoint call\n * without a scope. Such calls come only from trusted server-side code (for\n * example a Channel listener), and they act as this one server identity.\n *\n * No HTTP caller can act as it: request identities are `\"\"` (anonymous) or an\n * id that `identifyUser` returned, and a valid id cannot hold a NUL character.\n * So an omitted owner never means \"every Thread\", and a Thread created\n * server-side is never reachable by an anonymous caller.\n */\nexport const ɵSERVER_THREAD_OWNER = \"\\u0000server\";\n\n/** The owner a runner call acts as: `ownerId`, or the server owner when omitted. */\nexport function ɵresolveThreadOwner(ownerId: string | undefined): string {\n return ownerId ?? ɵSERVER_THREAD_OWNER;\n}\n\nexport interface AgentRunnerRunRequest {\n threadId: string;\n /** Backend execution ID supplied by Intelligence for imported non-UUID sessions. */\n backendThreadId?: string;\n agent: AbstractAgent;\n input: RunAgentInput;\n persistedInputMessages?: Message[];\n /** Short-lived token scoped to this runner invocation. */\n authToken?: string;\n /**\n * Identity the run acts as. A runner that tracks owners records it on the\n * Thread's first run and refuses a run from any other identity. `\"\"` is the\n * anonymous owner. When omitted, the run acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n /**\n * Records a stop of this run with Intelligence. An Intelligence runner calls\n * it when the runtime stops the run itself (not when Intelligence relayed\n * the stop), and sends the run's terminal event only once it settles or a\n * short deadline passes, so Intelligence counts the run as cancelled. The\n * signal aborts when that deadline passes. A failure never stops the run\n * from stopping. Runners that do not deliver to Intelligence ignore it.\n */\n recordStop?: (signal: AbortSignal) => Promise<void>;\n}\n\nexport interface AgentRunnerConnectRequest {\n threadId: string;\n agentId?: string;\n headers?: Record<string, string>;\n joinCode?: string;\n /**\n * Caller identity. A Thread owned by another identity is treated as unknown.\n * When omitted, the call acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n}\n\nexport interface AgentRunnerIsRunningRequest {\n threadId: string;\n /**\n * Caller identity. A Thread owned by another identity reports \"not running\".\n * When omitted, the call acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n}\n\nexport interface AgentRunnerStopRequest {\n threadId: string;\n /** When present, stop only this exact run and never a newer run on the Thread. */\n runId?: string;\n /**\n * Caller identity. A run on a Thread owned by another identity is not\n * stopped. When omitted, the call acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n}\n\nexport interface LocalThreadEndpointRecord {\n id: string;\n name: string | null;\n agentId: string;\n organizationId: string;\n createdById: string;\n archived: boolean;\n createdAt: string;\n updatedAt: string;\n}\n\n/**\n * Limits a local Thread endpoint call to the Threads of one owner. `\"\"` is the\n * anonymous owner. A call without a scope acts as\n * {@link ɵSERVER_THREAD_OWNER}: it sees only Threads created server-side, never\n * every Thread.\n */\nexport interface LocalThreadEndpointScope {\n ownerId: string;\n}\n\nexport interface LocalThreadEndpointRunner extends AgentRunner {\n readonly ɵsupportsLocalThreadEndpoints: true;\n listThreads(scope?: LocalThreadEndpointScope): LocalThreadEndpointRecord[];\n getThreadMessages(\n threadId: string,\n scope?: LocalThreadEndpointScope,\n ): Message[];\n getThreadEvents(\n threadId: string,\n scope?: LocalThreadEndpointScope,\n ): BaseEvent[];\n getThreadState(\n threadId: string,\n scope?: LocalThreadEndpointScope,\n ): Record<string, unknown> | null;\n clearThreads(scope?: LocalThreadEndpointScope): void;\n /** See {@link ThreadOwnershipRunner.isThreadAccessible}. */\n isThreadAccessible(\n threadId: string,\n scope: LocalThreadEndpointScope,\n ): boolean;\n}\n\nexport function supportsLocalThreadEndpoints(\n runner: AgentRunner,\n): runner is LocalThreadEndpointRunner {\n return runner.ɵsupportsLocalThreadEndpoints === true;\n}\n\n/**\n * A runner that records each Thread's owner and enforces it. Implementing\n * `isThreadAccessible` is the promise that `run`, `connect`, `stop` and\n * `isRunning` honor `ownerId` the same way: a call never reaches a Thread that\n * another owner holds.\n */\nexport interface ThreadOwnershipRunner extends AgentRunner {\n /** False when the Thread id is held by an owner other than `scope`'s. */\n isThreadAccessible(\n threadId: string,\n scope: LocalThreadEndpointScope,\n ): boolean | Promise<boolean>;\n}\n\n/**\n * True when `runner` enforces Thread owners. Checks the method itself, so a\n * runner built against an older interface (one that sets the endpoint flag\n * but has no `isThreadAccessible`) is not taken to enforce them.\n */\nexport function enforcesThreadOwnership(\n runner: AgentRunner,\n): runner is ThreadOwnershipRunner {\n return typeof runner.isThreadAccessible === \"function\";\n}\n\nexport abstract class AgentRunner {\n readonly ɵsupportsLocalThreadEndpoints?: boolean;\n\n /** See {@link ThreadOwnershipRunner}. Optional: not every runner tracks owners. */\n isThreadAccessible?(\n threadId: string,\n scope: LocalThreadEndpointScope,\n ): boolean | Promise<boolean>;\n\n abstract run(request: AgentRunnerRunRequest): Observable<BaseEvent>;\n abstract connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;\n abstract isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean>;\n abstract stop(request: AgentRunnerStopRequest): Promise<boolean | undefined>;\n}\n"],"mappings":";;;;;;;;;AAeA,IAAa,4BAAb,cAA+C,MAAM;CAGnD,cAAc;AACZ,QAAM,yBAAyB;cAHjBA;AAId,OAAK,OAAO;;;;AAKhB,MAAa,kCAAkC;;;;;;;;;;;;;AAc/C,IAAa,0BAAb,cAA6C,MAAM;CAGjD,cAAc;AACZ,QAAM,uBAAuB;cAHf;AAId,OAAK,OAAO;;;;AAKhB,SAAgB,0BAA0B,OAAyB;AACjE,QACE,iBAAiB,SAChB,MAA6B,SAAS;;;;;;;;;;;;;AAe3C,MAAa,uBAAuB;;AAGpC,SAAgB,oBAAoB,SAAqC;AACvE,QAAO,WAAW;;AAyGpB,SAAgB,6BACd,QACqC;AACrC,QAAO,OAAO,kCAAkC;;;;;;;AAsBlD,SAAgB,wBACd,QACiC;AACjC,QAAO,OAAO,OAAO,uBAAuB;;AAG9C,IAAsB,cAAtB,MAAkC"}
|
|
@@ -61,6 +61,15 @@ interface AgentRunnerRunRequest {
|
|
|
61
61
|
* anonymous owner. When omitted, the run acts as {@link ɵSERVER_THREAD_OWNER}.
|
|
62
62
|
*/
|
|
63
63
|
ownerId?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Records a stop of this run with Intelligence. An Intelligence runner calls
|
|
66
|
+
* it when the runtime stops the run itself (not when Intelligence relayed
|
|
67
|
+
* the stop), and sends the run's terminal event only once it settles or a
|
|
68
|
+
* short deadline passes, so Intelligence counts the run as cancelled. The
|
|
69
|
+
* signal aborts when that deadline passes. A failure never stops the run
|
|
70
|
+
* from stopping. Runners that do not deliver to Intelligence ignore it.
|
|
71
|
+
*/
|
|
72
|
+
recordStop?: (signal: AbortSignal) => Promise<void>;
|
|
64
73
|
}
|
|
65
74
|
interface AgentRunnerConnectRequest {
|
|
66
75
|
threadId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-runner.d.cts","names":[],"sources":["../../../src/runtime/runner/agent-runner.ts"],"mappings":";;;;;;AAeA;;;;cAAa,yBAAA,SAAkC,KAAA;EAAA,SACpC,IAAA;;;;cASE,+BAAA;;;;;AAcb;;;;;;;;cAAa,uBAAA,SAAgC,KAAA;EAAA,SAClC,IAAA;;;;iBASK,yBAAA,CAA0B,KAAA;AAkB1C;;;;;AAGA;;;;;AAIA;AAPA,cAAa,oBAAA;;iBAGG,mBAAA,CAAoB,OAAA;AAAA,UAInB,qBAAA;EACf,QAAA;
|
|
1
|
+
{"version":3,"file":"agent-runner.d.cts","names":[],"sources":["../../../src/runtime/runner/agent-runner.ts"],"mappings":";;;;;;AAeA;;;;cAAa,yBAAA,SAAkC,KAAA;EAAA,SACpC,IAAA;;;;cASE,+BAAA;;;;;AAcb;;;;;;;;cAAa,uBAAA,SAAgC,KAAA;EAAA,SAClC,IAAA;;;;iBASK,yBAAA,CAA0B,KAAA;AAkB1C;;;;;AAGA;;;;;AAIA;AAPA,cAAa,oBAAA;;iBAGG,mBAAA,CAAoB,OAAA;AAAA,UAInB,qBAAA;EACf,QAAA;EAsBsB;EApBtB,eAAA;EACA,KAAA,EAAO,aAAA;EACP,KAAA,EAAO,aAAA;EACP,sBAAA,GAAyB,OAAA;EAHzB;EAKA,SAAA;EAJO;;;;;EAUP,OAAA;EAAA;;;;;;;AAYF;EAHE,UAAA,IAAc,MAAA,EAAQ,WAAA,KAAgB,OAAA;AAAA;AAAA,UAGvB,yBAAA;EACf,QAAA;EACA,OAAA;EACA,OAAA,GAAU,MAAA;EACV,QAAA;EAAA;;;;EAKA,OAAA;AAAA;AAAA,UAGe,2BAAA;EACf,QAAA;EAKO;AAGT;;;EAHE,OAAA;AAAA;AAAA,UAGe,sBAAA;EACf,QAAA;EAOO;EALP,KAAA;EAQe;;;;EAHf,OAAA;AAAA;AAAA,UAGe,yBAAA;EACf,EAAA;EACA,IAAA;EACA,OAAA;EACA,cAAA;EACA,WAAA;EACA,QAAA;EACA,SAAA;EACA,SAAA;AAAA;;;;AAaF;;;UAJiB,wBAAA;EACf,OAAA;AAAA;AAAA,UAGe,yBAAA,SAAkC,WAAA;EAAA,SACxC,6BAAA;EACT,WAAA,CAAY,KAAA,GAAQ,wBAAA,GAA2B,yBAAA;EAC/C,iBAAA,CACE,QAAA,UACA,KAAA,GAAQ,wBAAA,GACP,OAAA;EACH,eAAA,CACE,QAAA,UACA,KAAA,GAAQ,wBAAA,GACP,SAAA;EACH,cAAA,CACE,QAAA,UACA,KAAA,GAAQ,wBAAA,GACP,MAAA;EACH,YAAA,CAAa,KAAA,GAAQ,wBAAA;EAf4B;EAiBjD,kBAAA,CACE,QAAA,UACA,KAAA,EAAO,wBAAA;AAAA;AAAA,iBAIK,4BAAA,CACd,MAAA,EAAQ,WAAA,GACP,MAAA,IAAU,yBAAA;;;;;;;UAUI,qBAAA,SAA8B,WAAA;EA9BnC;EAgCV,kBAAA,CACE,QAAA,UACA,KAAA,EAAO,wBAAA,aACI,OAAA;AAAA;;;;;;iBAQC,uBAAA,CACd,MAAA,EAAQ,WAAA,GACP,MAAA,IAAU,qBAAA;AAAA,uBAIS,WAAA;EAAA,SACX,6BAAA;EA1CP;EA6CF,kBAAA,CAAA,CACE,QAAA,UACA,KAAA,EAAO,wBAAA,aACI,OAAA;EAAA,SAEJ,GAAA,CAAI,OAAA,EAAS,qBAAA,GAAwB,UAAA,CAAW,SAAA;EAAA,SAChD,OAAA,CAAQ,OAAA,EAAS,yBAAA,GAA4B,UAAA,CAAW,SAAA;EAAA,SACxD,SAAA,CAAU,OAAA,EAAS,2BAAA,GAA8B,OAAA;EAAA,SACjD,IAAA,CAAK,OAAA,EAAS,sBAAA,GAAyB,OAAA;AAAA"}
|
|
@@ -61,6 +61,15 @@ interface AgentRunnerRunRequest {
|
|
|
61
61
|
* anonymous owner. When omitted, the run acts as {@link ɵSERVER_THREAD_OWNER}.
|
|
62
62
|
*/
|
|
63
63
|
ownerId?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Records a stop of this run with Intelligence. An Intelligence runner calls
|
|
66
|
+
* it when the runtime stops the run itself (not when Intelligence relayed
|
|
67
|
+
* the stop), and sends the run's terminal event only once it settles or a
|
|
68
|
+
* short deadline passes, so Intelligence counts the run as cancelled. The
|
|
69
|
+
* signal aborts when that deadline passes. A failure never stops the run
|
|
70
|
+
* from stopping. Runners that do not deliver to Intelligence ignore it.
|
|
71
|
+
*/
|
|
72
|
+
recordStop?: (signal: AbortSignal) => Promise<void>;
|
|
64
73
|
}
|
|
65
74
|
interface AgentRunnerConnectRequest {
|
|
66
75
|
threadId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-runner.d.mts","names":[],"sources":["../../../src/runtime/runner/agent-runner.ts"],"mappings":";;;;;;AAeA;;;;cAAa,yBAAA,SAAkC,KAAA;EAAA,SACpC,IAAA;;;;cASE,+BAAA;;;;;AAcb;;;;;;;;cAAa,uBAAA,SAAgC,KAAA;EAAA,SAClC,IAAA;;;;iBASK,yBAAA,CAA0B,KAAA;AAkB1C;;;;;AAGA;;;;;AAIA;AAPA,cAAa,oBAAA;;iBAGG,mBAAA,CAAoB,OAAA;AAAA,UAInB,qBAAA;EACf,QAAA;
|
|
1
|
+
{"version":3,"file":"agent-runner.d.mts","names":[],"sources":["../../../src/runtime/runner/agent-runner.ts"],"mappings":";;;;;;AAeA;;;;cAAa,yBAAA,SAAkC,KAAA;EAAA,SACpC,IAAA;;;;cASE,+BAAA;;;;;AAcb;;;;;;;;cAAa,uBAAA,SAAgC,KAAA;EAAA,SAClC,IAAA;;;;iBASK,yBAAA,CAA0B,KAAA;AAkB1C;;;;;AAGA;;;;;AAIA;AAPA,cAAa,oBAAA;;iBAGG,mBAAA,CAAoB,OAAA;AAAA,UAInB,qBAAA;EACf,QAAA;EAsBsB;EApBtB,eAAA;EACA,KAAA,EAAO,aAAA;EACP,KAAA,EAAO,aAAA;EACP,sBAAA,GAAyB,OAAA;EAHzB;EAKA,SAAA;EAJO;;;;;EAUP,OAAA;EAAA;;;;;;;AAYF;EAHE,UAAA,IAAc,MAAA,EAAQ,WAAA,KAAgB,OAAA;AAAA;AAAA,UAGvB,yBAAA;EACf,QAAA;EACA,OAAA;EACA,OAAA,GAAU,MAAA;EACV,QAAA;EAAA;;;;EAKA,OAAA;AAAA;AAAA,UAGe,2BAAA;EACf,QAAA;EAKO;AAGT;;;EAHE,OAAA;AAAA;AAAA,UAGe,sBAAA;EACf,QAAA;EAOO;EALP,KAAA;EAQe;;;;EAHf,OAAA;AAAA;AAAA,UAGe,yBAAA;EACf,EAAA;EACA,IAAA;EACA,OAAA;EACA,cAAA;EACA,WAAA;EACA,QAAA;EACA,SAAA;EACA,SAAA;AAAA;;;;AAaF;;;UAJiB,wBAAA;EACf,OAAA;AAAA;AAAA,UAGe,yBAAA,SAAkC,WAAA;EAAA,SACxC,6BAAA;EACT,WAAA,CAAY,KAAA,GAAQ,wBAAA,GAA2B,yBAAA;EAC/C,iBAAA,CACE,QAAA,UACA,KAAA,GAAQ,wBAAA,GACP,OAAA;EACH,eAAA,CACE,QAAA,UACA,KAAA,GAAQ,wBAAA,GACP,SAAA;EACH,cAAA,CACE,QAAA,UACA,KAAA,GAAQ,wBAAA,GACP,MAAA;EACH,YAAA,CAAa,KAAA,GAAQ,wBAAA;EAf4B;EAiBjD,kBAAA,CACE,QAAA,UACA,KAAA,EAAO,wBAAA;AAAA;AAAA,iBAIK,4BAAA,CACd,MAAA,EAAQ,WAAA,GACP,MAAA,IAAU,yBAAA;;;;;;;UAUI,qBAAA,SAA8B,WAAA;EA9BnC;EAgCV,kBAAA,CACE,QAAA,UACA,KAAA,EAAO,wBAAA,aACI,OAAA;AAAA;;;;;;iBAQC,uBAAA,CACd,MAAA,EAAQ,WAAA,GACP,MAAA,IAAU,qBAAA;AAAA,uBAIS,WAAA;EAAA,SACX,6BAAA;EA1CP;EA6CF,kBAAA,CAAA,CACE,QAAA,UACA,KAAA,EAAO,wBAAA,aACI,OAAA;EAAA,SAEJ,GAAA,CAAI,OAAA,EAAS,qBAAA,GAAwB,UAAA,CAAW,SAAA;EAAA,SAChD,OAAA,CAAQ,OAAA,EAAS,yBAAA,GAA4B,UAAA,CAAW,SAAA;EAAA,SACxD,SAAA,CAAU,OAAA,EAAS,2BAAA,GAA8B,OAAA;EAAA,SACjD,IAAA,CAAK,OAAA,EAAS,sBAAA,GAAyB,OAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-runner.mjs","names":[],"sources":["../../../src/runtime/runner/agent-runner.ts"],"sourcesContent":["import type {\n AbstractAgent,\n BaseEvent,\n Message,\n RunAgentInput,\n} from \"@ag-ui/client\";\nimport type { Observable } from \"rxjs\";\nimport { THREAD_ALREADY_RUNNING_ERROR_CODE } from \"@copilotkit/shared\";\n\n/**\n * Thrown by a runner when the thread already has a run in flight. The SSE\n * handler sends it to the client as a `RUN_ERROR` with\n * {@link THREAD_ALREADY_RUNNING_ERROR_CODE}, matched on `code` so a copy of\n * this class from another package version still counts.\n */\nexport class ThreadAlreadyRunningError extends Error {\n readonly code = THREAD_ALREADY_RUNNING_ERROR_CODE;\n\n constructor() {\n super(\"Thread already running\");\n this.name = \"ThreadAlreadyRunningError\";\n }\n}\n\n/** `code` of {@link ThreadAccessDeniedError}, also sent on the SSE `RUN_ERROR`. */\nexport const THREAD_ACCESS_DENIED_ERROR_CODE = \"THREAD_ACCESS_DENIED\";\n\n/**\n * Thrown by a runner when a run targets a Thread that another identity owns.\n *\n * Defense in depth: the run handler checks `isThreadAccessible` first and\n * refuses with an HTTP error, so the runner throws this only when another\n * identity claims the Thread between that check and the run, or for direct\n * runner callers. A synchronous throw from `run()` is still mapped to the\n * HTTP error; a later one reaches the client as a `RUN_ERROR` with\n * {@link THREAD_ACCESS_DENIED_ERROR_CODE}. Neither is reported as an agent\n * failure. Matched on `code`, so a copy of this class from another package\n * version still counts.\n */\nexport class ThreadAccessDeniedError extends Error {\n readonly code = THREAD_ACCESS_DENIED_ERROR_CODE;\n\n constructor() {\n super(\"Thread access denied\");\n this.name = \"ThreadAccessDeniedError\";\n }\n}\n\n/** True for a {@link ThreadAccessDeniedError}, from any package version. */\nexport function isThreadAccessDeniedError(error: unknown): boolean {\n return (\n error instanceof Error &&\n (error as { code?: unknown }).code === THREAD_ACCESS_DENIED_ERROR_CODE\n );\n}\n\n/**\n * Owner of a Thread created, or reached, by a runner call that names no owner:\n * a run, connect, stop or isRunning without `ownerId`, or a Thread endpoint call\n * without a scope. Such calls come only from trusted server-side code (for\n * example a Channel listener), and they act as this one server identity.\n *\n * No HTTP caller can act as it: request identities are `\"\"` (anonymous) or an\n * id that `identifyUser` returned, and a valid id cannot hold a NUL character.\n * So an omitted owner never means \"every Thread\", and a Thread created\n * server-side is never reachable by an anonymous caller.\n */\nexport const ɵSERVER_THREAD_OWNER = \"\\u0000server\";\n\n/** The owner a runner call acts as: `ownerId`, or the server owner when omitted. */\nexport function ɵresolveThreadOwner(ownerId: string | undefined): string {\n return ownerId ?? ɵSERVER_THREAD_OWNER;\n}\n\nexport interface AgentRunnerRunRequest {\n threadId: string;\n /** Backend execution ID supplied by Intelligence for imported non-UUID sessions. */\n backendThreadId?: string;\n agent: AbstractAgent;\n input: RunAgentInput;\n persistedInputMessages?: Message[];\n /** Short-lived token scoped to this runner invocation. */\n authToken?: string;\n /**\n * Identity the run acts as. A runner that tracks owners records it on the\n * Thread's first run and refuses a run from any other identity. `\"\"` is the\n * anonymous owner. When omitted, the run acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n}\n\nexport interface AgentRunnerConnectRequest {\n threadId: string;\n agentId?: string;\n headers?: Record<string, string>;\n joinCode?: string;\n /**\n * Caller identity. A Thread owned by another identity is treated as unknown.\n * When omitted, the call acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n}\n\nexport interface AgentRunnerIsRunningRequest {\n threadId: string;\n /**\n * Caller identity. A Thread owned by another identity reports \"not running\".\n * When omitted, the call acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n}\n\nexport interface AgentRunnerStopRequest {\n threadId: string;\n /** When present, stop only this exact run and never a newer run on the Thread. */\n runId?: string;\n /**\n * Caller identity. A run on a Thread owned by another identity is not\n * stopped. When omitted, the call acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n}\n\nexport interface LocalThreadEndpointRecord {\n id: string;\n name: string | null;\n agentId: string;\n organizationId: string;\n createdById: string;\n archived: boolean;\n createdAt: string;\n updatedAt: string;\n}\n\n/**\n * Limits a local Thread endpoint call to the Threads of one owner. `\"\"` is the\n * anonymous owner. A call without a scope acts as\n * {@link ɵSERVER_THREAD_OWNER}: it sees only Threads created server-side, never\n * every Thread.\n */\nexport interface LocalThreadEndpointScope {\n ownerId: string;\n}\n\nexport interface LocalThreadEndpointRunner extends AgentRunner {\n readonly ɵsupportsLocalThreadEndpoints: true;\n listThreads(scope?: LocalThreadEndpointScope): LocalThreadEndpointRecord[];\n getThreadMessages(\n threadId: string,\n scope?: LocalThreadEndpointScope,\n ): Message[];\n getThreadEvents(\n threadId: string,\n scope?: LocalThreadEndpointScope,\n ): BaseEvent[];\n getThreadState(\n threadId: string,\n scope?: LocalThreadEndpointScope,\n ): Record<string, unknown> | null;\n clearThreads(scope?: LocalThreadEndpointScope): void;\n /** See {@link ThreadOwnershipRunner.isThreadAccessible}. */\n isThreadAccessible(\n threadId: string,\n scope: LocalThreadEndpointScope,\n ): boolean;\n}\n\nexport function supportsLocalThreadEndpoints(\n runner: AgentRunner,\n): runner is LocalThreadEndpointRunner {\n return runner.ɵsupportsLocalThreadEndpoints === true;\n}\n\n/**\n * A runner that records each Thread's owner and enforces it. Implementing\n * `isThreadAccessible` is the promise that `run`, `connect`, `stop` and\n * `isRunning` honor `ownerId` the same way: a call never reaches a Thread that\n * another owner holds.\n */\nexport interface ThreadOwnershipRunner extends AgentRunner {\n /** False when the Thread id is held by an owner other than `scope`'s. */\n isThreadAccessible(\n threadId: string,\n scope: LocalThreadEndpointScope,\n ): boolean | Promise<boolean>;\n}\n\n/**\n * True when `runner` enforces Thread owners. Checks the method itself, so a\n * runner built against an older interface (one that sets the endpoint flag\n * but has no `isThreadAccessible`) is not taken to enforce them.\n */\nexport function enforcesThreadOwnership(\n runner: AgentRunner,\n): runner is ThreadOwnershipRunner {\n return typeof runner.isThreadAccessible === \"function\";\n}\n\nexport abstract class AgentRunner {\n readonly ɵsupportsLocalThreadEndpoints?: boolean;\n\n /** See {@link ThreadOwnershipRunner}. Optional: not every runner tracks owners. */\n isThreadAccessible?(\n threadId: string,\n scope: LocalThreadEndpointScope,\n ): boolean | Promise<boolean>;\n\n abstract run(request: AgentRunnerRunRequest): Observable<BaseEvent>;\n abstract connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;\n abstract isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean>;\n abstract stop(request: AgentRunnerStopRequest): Promise<boolean | undefined>;\n}\n"],"mappings":";;;;;;;;;AAeA,IAAa,4BAAb,cAA+C,MAAM;CAGnD,cAAc;AACZ,QAAM,yBAAyB;cAHjB;AAId,OAAK,OAAO;;;;AAKhB,MAAa,kCAAkC;;;;;;;;;;;;;AAc/C,IAAa,0BAAb,cAA6C,MAAM;CAGjD,cAAc;AACZ,QAAM,uBAAuB;cAHf;AAId,OAAK,OAAO;;;;AAKhB,SAAgB,0BAA0B,OAAyB;AACjE,QACE,iBAAiB,SAChB,MAA6B,SAAS;;;;;;;;;;;;;AAe3C,MAAa,uBAAuB;;AAGpC,SAAgB,oBAAoB,SAAqC;AACvE,QAAO,WAAW;;
|
|
1
|
+
{"version":3,"file":"agent-runner.mjs","names":[],"sources":["../../../src/runtime/runner/agent-runner.ts"],"sourcesContent":["import type {\n AbstractAgent,\n BaseEvent,\n Message,\n RunAgentInput,\n} from \"@ag-ui/client\";\nimport type { Observable } from \"rxjs\";\nimport { THREAD_ALREADY_RUNNING_ERROR_CODE } from \"@copilotkit/shared\";\n\n/**\n * Thrown by a runner when the thread already has a run in flight. The SSE\n * handler sends it to the client as a `RUN_ERROR` with\n * {@link THREAD_ALREADY_RUNNING_ERROR_CODE}, matched on `code` so a copy of\n * this class from another package version still counts.\n */\nexport class ThreadAlreadyRunningError extends Error {\n readonly code = THREAD_ALREADY_RUNNING_ERROR_CODE;\n\n constructor() {\n super(\"Thread already running\");\n this.name = \"ThreadAlreadyRunningError\";\n }\n}\n\n/** `code` of {@link ThreadAccessDeniedError}, also sent on the SSE `RUN_ERROR`. */\nexport const THREAD_ACCESS_DENIED_ERROR_CODE = \"THREAD_ACCESS_DENIED\";\n\n/**\n * Thrown by a runner when a run targets a Thread that another identity owns.\n *\n * Defense in depth: the run handler checks `isThreadAccessible` first and\n * refuses with an HTTP error, so the runner throws this only when another\n * identity claims the Thread between that check and the run, or for direct\n * runner callers. A synchronous throw from `run()` is still mapped to the\n * HTTP error; a later one reaches the client as a `RUN_ERROR` with\n * {@link THREAD_ACCESS_DENIED_ERROR_CODE}. Neither is reported as an agent\n * failure. Matched on `code`, so a copy of this class from another package\n * version still counts.\n */\nexport class ThreadAccessDeniedError extends Error {\n readonly code = THREAD_ACCESS_DENIED_ERROR_CODE;\n\n constructor() {\n super(\"Thread access denied\");\n this.name = \"ThreadAccessDeniedError\";\n }\n}\n\n/** True for a {@link ThreadAccessDeniedError}, from any package version. */\nexport function isThreadAccessDeniedError(error: unknown): boolean {\n return (\n error instanceof Error &&\n (error as { code?: unknown }).code === THREAD_ACCESS_DENIED_ERROR_CODE\n );\n}\n\n/**\n * Owner of a Thread created, or reached, by a runner call that names no owner:\n * a run, connect, stop or isRunning without `ownerId`, or a Thread endpoint call\n * without a scope. Such calls come only from trusted server-side code (for\n * example a Channel listener), and they act as this one server identity.\n *\n * No HTTP caller can act as it: request identities are `\"\"` (anonymous) or an\n * id that `identifyUser` returned, and a valid id cannot hold a NUL character.\n * So an omitted owner never means \"every Thread\", and a Thread created\n * server-side is never reachable by an anonymous caller.\n */\nexport const ɵSERVER_THREAD_OWNER = \"\\u0000server\";\n\n/** The owner a runner call acts as: `ownerId`, or the server owner when omitted. */\nexport function ɵresolveThreadOwner(ownerId: string | undefined): string {\n return ownerId ?? ɵSERVER_THREAD_OWNER;\n}\n\nexport interface AgentRunnerRunRequest {\n threadId: string;\n /** Backend execution ID supplied by Intelligence for imported non-UUID sessions. */\n backendThreadId?: string;\n agent: AbstractAgent;\n input: RunAgentInput;\n persistedInputMessages?: Message[];\n /** Short-lived token scoped to this runner invocation. */\n authToken?: string;\n /**\n * Identity the run acts as. A runner that tracks owners records it on the\n * Thread's first run and refuses a run from any other identity. `\"\"` is the\n * anonymous owner. When omitted, the run acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n /**\n * Records a stop of this run with Intelligence. An Intelligence runner calls\n * it when the runtime stops the run itself (not when Intelligence relayed\n * the stop), and sends the run's terminal event only once it settles or a\n * short deadline passes, so Intelligence counts the run as cancelled. The\n * signal aborts when that deadline passes. A failure never stops the run\n * from stopping. Runners that do not deliver to Intelligence ignore it.\n */\n recordStop?: (signal: AbortSignal) => Promise<void>;\n}\n\nexport interface AgentRunnerConnectRequest {\n threadId: string;\n agentId?: string;\n headers?: Record<string, string>;\n joinCode?: string;\n /**\n * Caller identity. A Thread owned by another identity is treated as unknown.\n * When omitted, the call acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n}\n\nexport interface AgentRunnerIsRunningRequest {\n threadId: string;\n /**\n * Caller identity. A Thread owned by another identity reports \"not running\".\n * When omitted, the call acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n}\n\nexport interface AgentRunnerStopRequest {\n threadId: string;\n /** When present, stop only this exact run and never a newer run on the Thread. */\n runId?: string;\n /**\n * Caller identity. A run on a Thread owned by another identity is not\n * stopped. When omitted, the call acts as {@link ɵSERVER_THREAD_OWNER}.\n */\n ownerId?: string;\n}\n\nexport interface LocalThreadEndpointRecord {\n id: string;\n name: string | null;\n agentId: string;\n organizationId: string;\n createdById: string;\n archived: boolean;\n createdAt: string;\n updatedAt: string;\n}\n\n/**\n * Limits a local Thread endpoint call to the Threads of one owner. `\"\"` is the\n * anonymous owner. A call without a scope acts as\n * {@link ɵSERVER_THREAD_OWNER}: it sees only Threads created server-side, never\n * every Thread.\n */\nexport interface LocalThreadEndpointScope {\n ownerId: string;\n}\n\nexport interface LocalThreadEndpointRunner extends AgentRunner {\n readonly ɵsupportsLocalThreadEndpoints: true;\n listThreads(scope?: LocalThreadEndpointScope): LocalThreadEndpointRecord[];\n getThreadMessages(\n threadId: string,\n scope?: LocalThreadEndpointScope,\n ): Message[];\n getThreadEvents(\n threadId: string,\n scope?: LocalThreadEndpointScope,\n ): BaseEvent[];\n getThreadState(\n threadId: string,\n scope?: LocalThreadEndpointScope,\n ): Record<string, unknown> | null;\n clearThreads(scope?: LocalThreadEndpointScope): void;\n /** See {@link ThreadOwnershipRunner.isThreadAccessible}. */\n isThreadAccessible(\n threadId: string,\n scope: LocalThreadEndpointScope,\n ): boolean;\n}\n\nexport function supportsLocalThreadEndpoints(\n runner: AgentRunner,\n): runner is LocalThreadEndpointRunner {\n return runner.ɵsupportsLocalThreadEndpoints === true;\n}\n\n/**\n * A runner that records each Thread's owner and enforces it. Implementing\n * `isThreadAccessible` is the promise that `run`, `connect`, `stop` and\n * `isRunning` honor `ownerId` the same way: a call never reaches a Thread that\n * another owner holds.\n */\nexport interface ThreadOwnershipRunner extends AgentRunner {\n /** False when the Thread id is held by an owner other than `scope`'s. */\n isThreadAccessible(\n threadId: string,\n scope: LocalThreadEndpointScope,\n ): boolean | Promise<boolean>;\n}\n\n/**\n * True when `runner` enforces Thread owners. Checks the method itself, so a\n * runner built against an older interface (one that sets the endpoint flag\n * but has no `isThreadAccessible`) is not taken to enforce them.\n */\nexport function enforcesThreadOwnership(\n runner: AgentRunner,\n): runner is ThreadOwnershipRunner {\n return typeof runner.isThreadAccessible === \"function\";\n}\n\nexport abstract class AgentRunner {\n readonly ɵsupportsLocalThreadEndpoints?: boolean;\n\n /** See {@link ThreadOwnershipRunner}. Optional: not every runner tracks owners. */\n isThreadAccessible?(\n threadId: string,\n scope: LocalThreadEndpointScope,\n ): boolean | Promise<boolean>;\n\n abstract run(request: AgentRunnerRunRequest): Observable<BaseEvent>;\n abstract connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;\n abstract isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean>;\n abstract stop(request: AgentRunnerStopRequest): Promise<boolean | undefined>;\n}\n"],"mappings":";;;;;;;;;AAeA,IAAa,4BAAb,cAA+C,MAAM;CAGnD,cAAc;AACZ,QAAM,yBAAyB;cAHjB;AAId,OAAK,OAAO;;;;AAKhB,MAAa,kCAAkC;;;;;;;;;;;;;AAc/C,IAAa,0BAAb,cAA6C,MAAM;CAGjD,cAAc;AACZ,QAAM,uBAAuB;cAHf;AAId,OAAK,OAAO;;;;AAKhB,SAAgB,0BAA0B,OAAyB;AACjE,QACE,iBAAiB,SAChB,MAA6B,SAAS;;;;;;;;;;;;;AAe3C,MAAa,uBAAuB;;AAGpC,SAAgB,oBAAoB,SAAqC;AACvE,QAAO,WAAW;;AAyGpB,SAAgB,6BACd,QACqC;AACrC,QAAO,OAAO,kCAAkC;;;;;;;AAsBlD,SAAgB,wBACd,QACiC;AACjC,QAAO,OAAO,OAAO,uBAAuB;;AAG9C,IAAsB,cAAtB,MAAkC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, LocalThreadEndpointRecord, LocalThreadEndpointRunner, LocalThreadEndpointScope, THREAD_ACCESS_DENIED_ERROR_CODE, ThreadAccessDeniedError, ThreadAlreadyRunningError, ThreadOwnershipRunner, enforcesThreadOwnership, isThreadAccessDeniedError, supportsLocalThreadEndpoints, ɵSERVER_THREAD_OWNER, ɵresolveThreadOwner } from "./agent-runner.cjs";
|
|
2
2
|
import { InMemoryAgentRunner, InMemoryAgentRunnerOptions, InMemoryLimits, InMemoryThread, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵOWNER_RETENTION_DEFAULTS, ɵOwnerRetention, ɵestimateBytes, ɵnormalizeLimits } from "./in-memory.cjs";
|
|
3
|
-
import { IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, RunnerStartupBoundary } from "./intelligence.cjs";
|
|
3
|
+
import { IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, RunnerStartupBoundary, STOP_RECORD_DEADLINE_MS } from "./intelligence.cjs";
|
|
4
4
|
import { FinalizeRunOptions, RunEventFinalizer, createRunEventFinalizer, finalizeRunEvents } from "@copilotkit/shared";
|
|
5
5
|
export { type FinalizeRunOptions, type RunEventFinalizer, createRunEventFinalizer, finalizeRunEvents };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, LocalThreadEndpointRecord, LocalThreadEndpointRunner, LocalThreadEndpointScope, THREAD_ACCESS_DENIED_ERROR_CODE, ThreadAccessDeniedError, ThreadAlreadyRunningError, ThreadOwnershipRunner, enforcesThreadOwnership, isThreadAccessDeniedError, supportsLocalThreadEndpoints, ɵSERVER_THREAD_OWNER, ɵresolveThreadOwner } from "./agent-runner.mjs";
|
|
2
2
|
import { InMemoryAgentRunner, InMemoryAgentRunnerOptions, InMemoryLimits, InMemoryThread, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵOWNER_RETENTION_DEFAULTS, ɵOwnerRetention, ɵestimateBytes, ɵnormalizeLimits } from "./in-memory.mjs";
|
|
3
|
-
import { IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, RunnerStartupBoundary } from "./intelligence.mjs";
|
|
3
|
+
import { IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, RunnerStartupBoundary, STOP_RECORD_DEADLINE_MS } from "./intelligence.mjs";
|
|
4
4
|
import { FinalizeRunOptions, RunEventFinalizer, createRunEventFinalizer as createRunEventFinalizer$1, finalizeRunEvents as finalizeRunEvents$1 } from "@copilotkit/shared";
|
|
5
5
|
export { type FinalizeRunOptions, type RunEventFinalizer, createRunEventFinalizer$1 as createRunEventFinalizer, finalizeRunEvents$1 as finalizeRunEvents };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AgentRunner, THREAD_ACCESS_DENIED_ERROR_CODE, ThreadAccessDeniedError, ThreadAlreadyRunningError, enforcesThreadOwnership, isThreadAccessDeniedError, supportsLocalThreadEndpoints, ɵSERVER_THREAD_OWNER, ɵresolveThreadOwner } from "./agent-runner.mjs";
|
|
2
2
|
import { InMemoryAgentRunner, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵOWNER_RETENTION_DEFAULTS, ɵestimateBytes, ɵnormalizeLimits } from "./in-memory.mjs";
|
|
3
|
-
import { IntelligenceAgentRunner } from "./intelligence.mjs";
|
|
3
|
+
import { IntelligenceAgentRunner, STOP_RECORD_DEADLINE_MS } from "./intelligence.mjs";
|
|
4
4
|
import { createRunEventFinalizer as createRunEventFinalizer$1, finalizeRunEvents as finalizeRunEvents$1 } from "@copilotkit/shared";
|
|
5
5
|
|
|
6
6
|
export { createRunEventFinalizer$1 as createRunEventFinalizer, finalizeRunEvents$1 as finalizeRunEvents };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_agent_runner = require('./agent-runner.cjs');
|
|
2
2
|
let _copilotkit_shared = require("@copilotkit/shared");
|
|
3
|
+
let phoenix = require("phoenix");
|
|
3
4
|
let rxjs = require("rxjs");
|
|
4
5
|
let _ag_ui_client = require("@ag-ui/client");
|
|
5
|
-
let phoenix = require("phoenix");
|
|
6
6
|
|
|
7
7
|
//#region src/runtime/runner/intelligence.ts
|
|
8
8
|
const MAX_CONSECUTIVE_SOCKET_ERRORS = 5;
|
|
@@ -12,6 +12,12 @@ const RUNNER_EVENT_BATCH_CAPABILITY = "runner_event_batch_v1";
|
|
|
12
12
|
const MAX_RUNNER_EVENT_BATCH_SIZE = 32;
|
|
13
13
|
const RUNNER_EVENT_BATCH_FLUSH_MS = 5;
|
|
14
14
|
const EVENT_DURABILITY_DEADLINE_MS = 6e4;
|
|
15
|
+
/**
|
|
16
|
+
* How long a runtime-side stop waits for Intelligence to record it before the
|
|
17
|
+
* terminal event is sent anyway. The agent is aborted at once; only the
|
|
18
|
+
* terminal event waits, so a slow or failing record never keeps a run going.
|
|
19
|
+
*/
|
|
20
|
+
const STOP_RECORD_DEADLINE_MS = 2e3;
|
|
15
21
|
var IntelligenceAgentRunner = class extends require_agent_runner.AgentRunner {
|
|
16
22
|
constructor(options) {
|
|
17
23
|
super();
|
|
@@ -156,6 +162,8 @@ var IntelligenceAgentRunner = class extends require_agent_runner.AgentRunner {
|
|
|
156
162
|
completion,
|
|
157
163
|
resolveCompletion,
|
|
158
164
|
stopTimer: null,
|
|
165
|
+
...request.recordStop ? { recordStop: request.recordStop } : {},
|
|
166
|
+
stopRecorded: null,
|
|
159
167
|
pendingEvents: /* @__PURE__ */ new Map(),
|
|
160
168
|
activeEventBatch: null,
|
|
161
169
|
nextEventPushAttempt: 0,
|
|
@@ -200,10 +208,10 @@ var IntelligenceAgentRunner = class extends require_agent_runner.AgentRunner {
|
|
|
200
208
|
if (consecutiveSocketErrors >= MAX_CONSECUTIVE_SOCKET_ERRORS) state.agent?.abortRun();
|
|
201
209
|
});
|
|
202
210
|
channel.on(_copilotkit_shared.AG_UI_CHANNEL_EVENT, (payload) => {
|
|
203
|
-
if (this.isCurrentThreadState(threadId, state) && payload.type === _ag_ui_client.EventType.CUSTOM && payload.name === "stop") this.
|
|
211
|
+
if (this.isCurrentThreadState(threadId, state) && payload.type === _ag_ui_client.EventType.CUSTOM && payload.name === "stop") this.stopRun({
|
|
204
212
|
threadId,
|
|
205
213
|
runId: state.runId
|
|
206
|
-
}).catch((error) => {
|
|
214
|
+
}, { recordWithIntelligence: false }).catch((error) => {
|
|
207
215
|
_copilotkit_shared.logger.error({
|
|
208
216
|
err: error,
|
|
209
217
|
threadId,
|
|
@@ -301,10 +309,14 @@ var IntelligenceAgentRunner = class extends require_agent_runner.AgentRunner {
|
|
|
301
309
|
}
|
|
302
310
|
/** Stops this run and waits until its terminal events have been acknowledged. */
|
|
303
311
|
stop(request) {
|
|
312
|
+
return this.stopRun(request, { recordWithIntelligence: true });
|
|
313
|
+
}
|
|
314
|
+
stopRun(request, options) {
|
|
304
315
|
const state = this.threads.get(request.threadId);
|
|
305
316
|
if (!state || !state.isRunning || state.stopRequested) return Promise.resolve(false);
|
|
306
317
|
if (request.runId !== void 0 && state.runId !== request.runId) return Promise.resolve(false);
|
|
307
318
|
state.stopRequested = true;
|
|
319
|
+
if (options.recordWithIntelligence && state.recordStop) state.stopRecorded = recordStopWithin(state, STOP_RECORD_DEADLINE_MS);
|
|
308
320
|
state.cancelRun();
|
|
309
321
|
state.stopTimer = setTimeout(() => {
|
|
310
322
|
this.failThread(state.threadId, state, /* @__PURE__ */ new Error("Timed out stopping Intelligence run"));
|
|
@@ -334,7 +346,7 @@ var IntelligenceAgentRunner = class extends require_agent_runner.AgentRunner {
|
|
|
334
346
|
return true;
|
|
335
347
|
});
|
|
336
348
|
}
|
|
337
|
-
async executeAgentRun(request, state, threadId,
|
|
349
|
+
async executeAgentRun(request, state, threadId, notifyHandler) {
|
|
338
350
|
const { currentEvents } = state;
|
|
339
351
|
const pushCanonicalEvent = (event) => {
|
|
340
352
|
if (!this.isCurrentThreadState(threadId, state)) return;
|
|
@@ -342,7 +354,7 @@ var IntelligenceAgentRunner = class extends require_agent_runner.AgentRunner {
|
|
|
342
354
|
currentEvents.push(canonicalEvent);
|
|
343
355
|
if (canonicalEvent.type === _ag_ui_client.EventType.RUN_STARTED) state.hasRunStarted = true;
|
|
344
356
|
this.queueRunnerEvent(this.createRunnerEventPayload(canonicalEvent, request, state), state);
|
|
345
|
-
if (canonicalEvent.type === _ag_ui_client.EventType.RUN_ERROR)
|
|
357
|
+
if (canonicalEvent.type === _ag_ui_client.EventType.RUN_STARTED || canonicalEvent.type === _ag_ui_client.EventType.RUN_ERROR) notifyHandler(canonicalEvent);
|
|
346
358
|
};
|
|
347
359
|
const getPersistedInputMessages = () => request.persistedInputMessages ?? request.input.messages;
|
|
348
360
|
const buildRunStartedEvent = (source) => {
|
|
@@ -390,6 +402,7 @@ var IntelligenceAgentRunner = class extends require_agent_runner.AgentRunner {
|
|
|
390
402
|
message: error instanceof Error ? error.message : String(error)
|
|
391
403
|
});
|
|
392
404
|
} finally {
|
|
405
|
+
if (state.stopRecorded) await state.stopRecorded;
|
|
393
406
|
if (!this.isCurrentThreadState(threadId, state)) return;
|
|
394
407
|
ensureRunStarted();
|
|
395
408
|
const appended = (0, _copilotkit_shared.finalizeRunEvents)(currentEvents, {
|
|
@@ -609,7 +622,39 @@ var IntelligenceAgentRunner = class extends require_agent_runner.AgentRunner {
|
|
|
609
622
|
} catch {}
|
|
610
623
|
}
|
|
611
624
|
};
|
|
625
|
+
/**
|
|
626
|
+
* Runs a thread's stop record, bounded by a deadline. Never rejects: a stop
|
|
627
|
+
* that Intelligence could not record still stops the run.
|
|
628
|
+
*/
|
|
629
|
+
function recordStopWithin(state, deadlineMs) {
|
|
630
|
+
const record = state.recordStop;
|
|
631
|
+
if (!record) return Promise.resolve();
|
|
632
|
+
const scope = {
|
|
633
|
+
threadId: state.threadId,
|
|
634
|
+
runId: state.runId
|
|
635
|
+
};
|
|
636
|
+
return new Promise((resolve) => {
|
|
637
|
+
const controller = new AbortController();
|
|
638
|
+
const deadline = setTimeout(() => {
|
|
639
|
+
controller.abort();
|
|
640
|
+
_copilotkit_shared.logger.warn(scope, "Timed out recording the run's stop with Intelligence");
|
|
641
|
+
resolve();
|
|
642
|
+
}, deadlineMs);
|
|
643
|
+
Promise.resolve().then(() => record(controller.signal)).then(() => {
|
|
644
|
+
clearTimeout(deadline);
|
|
645
|
+
resolve();
|
|
646
|
+
}, (error) => {
|
|
647
|
+
clearTimeout(deadline);
|
|
648
|
+
_copilotkit_shared.logger.warn({
|
|
649
|
+
...scope,
|
|
650
|
+
err: error
|
|
651
|
+
}, "Failed to record the run's stop with Intelligence");
|
|
652
|
+
resolve();
|
|
653
|
+
});
|
|
654
|
+
});
|
|
655
|
+
}
|
|
612
656
|
|
|
613
657
|
//#endregion
|
|
614
658
|
exports.IntelligenceAgentRunner = IntelligenceAgentRunner;
|
|
659
|
+
exports.STOP_RECORD_DEADLINE_MS = STOP_RECORD_DEADLINE_MS;
|
|
615
660
|
//# sourceMappingURL=intelligence.cjs.map
|