@copilotkit/runtime 1.82.0 → 1.83.0

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.
Files changed (144) hide show
  1. package/dist/agent/index.cjs +8 -3
  2. package/dist/agent/index.cjs.map +1 -1
  3. package/dist/agent/index.d.cts +41 -1
  4. package/dist/agent/index.d.cts.map +1 -1
  5. package/dist/agent/index.d.mts +42 -2
  6. package/dist/agent/index.d.mts.map +1 -1
  7. package/dist/agent/index.mjs +8 -3
  8. package/dist/agent/index.mjs.map +1 -1
  9. package/dist/agent/url-download.cjs +504 -0
  10. package/dist/agent/url-download.cjs.map +1 -0
  11. package/dist/agent/url-download.d.cts +80 -0
  12. package/dist/agent/url-download.d.cts.map +1 -0
  13. package/dist/agent/url-download.d.mts +80 -0
  14. package/dist/agent/url-download.d.mts.map +1 -0
  15. package/dist/agent/url-download.mjs +501 -0
  16. package/dist/agent/url-download.mjs.map +1 -0
  17. package/dist/lib/runtime/copilot-runtime.cjs +2 -1
  18. package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
  19. package/dist/lib/runtime/copilot-runtime.d.cts +5 -0
  20. package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
  21. package/dist/lib/runtime/copilot-runtime.d.mts +5 -0
  22. package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
  23. package/dist/lib/runtime/copilot-runtime.mjs +2 -1
  24. package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
  25. package/dist/lib/runtime/telemetry-agent-runner.cjs +3 -0
  26. package/dist/lib/runtime/telemetry-agent-runner.cjs.map +1 -1
  27. package/dist/lib/runtime/telemetry-agent-runner.d.cts +7 -1
  28. package/dist/lib/runtime/telemetry-agent-runner.d.cts.map +1 -1
  29. package/dist/lib/runtime/telemetry-agent-runner.d.mts +7 -1
  30. package/dist/lib/runtime/telemetry-agent-runner.d.mts.map +1 -1
  31. package/dist/lib/runtime/telemetry-agent-runner.mjs +3 -0
  32. package/dist/lib/runtime/telemetry-agent-runner.mjs.map +1 -1
  33. package/dist/package.cjs +1 -1
  34. package/dist/package.mjs +1 -1
  35. package/dist/v2/index.cjs +12 -3
  36. package/dist/v2/index.d.cts +5 -3
  37. package/dist/v2/index.d.mts +5 -3
  38. package/dist/v2/index.mjs +6 -5
  39. package/dist/v2/runtime/core/channel-manager.cjs +1 -1
  40. package/dist/v2/runtime/core/channel-manager.mjs +1 -1
  41. package/dist/v2/runtime/core/fetch-handler.cjs +2 -2
  42. package/dist/v2/runtime/core/fetch-handler.cjs.map +1 -1
  43. package/dist/v2/runtime/core/fetch-handler.mjs +2 -2
  44. package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -1
  45. package/dist/v2/runtime/core/package-info.cjs +1 -1
  46. package/dist/v2/runtime/core/package-info.mjs +1 -1
  47. package/dist/v2/runtime/core/runtime.cjs +12 -2
  48. package/dist/v2/runtime/core/runtime.cjs.map +1 -1
  49. package/dist/v2/runtime/core/runtime.d.cts +40 -1
  50. package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
  51. package/dist/v2/runtime/core/runtime.d.mts +40 -1
  52. package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
  53. package/dist/v2/runtime/core/runtime.mjs +12 -2
  54. package/dist/v2/runtime/core/runtime.mjs.map +1 -1
  55. package/dist/v2/runtime/handlers/get-runtime-info.cjs +6 -6
  56. package/dist/v2/runtime/handlers/get-runtime-info.cjs.map +1 -1
  57. package/dist/v2/runtime/handlers/get-runtime-info.mjs +6 -6
  58. package/dist/v2/runtime/handlers/get-runtime-info.mjs.map +1 -1
  59. package/dist/v2/runtime/handlers/handle-connect.cjs +9 -1
  60. package/dist/v2/runtime/handlers/handle-connect.cjs.map +1 -1
  61. package/dist/v2/runtime/handlers/handle-connect.mjs +9 -1
  62. package/dist/v2/runtime/handlers/handle-connect.mjs.map +1 -1
  63. package/dist/v2/runtime/handlers/handle-inspector-learning.cjs +1 -1
  64. package/dist/v2/runtime/handlers/handle-inspector-learning.mjs +1 -1
  65. package/dist/v2/runtime/handlers/handle-run.cjs +16 -2
  66. package/dist/v2/runtime/handlers/handle-run.cjs.map +1 -1
  67. package/dist/v2/runtime/handlers/handle-run.mjs +16 -2
  68. package/dist/v2/runtime/handlers/handle-run.mjs.map +1 -1
  69. package/dist/v2/runtime/handlers/handle-stop.cjs +14 -3
  70. package/dist/v2/runtime/handlers/handle-stop.cjs.map +1 -1
  71. package/dist/v2/runtime/handlers/handle-stop.mjs +14 -3
  72. package/dist/v2/runtime/handlers/handle-stop.mjs.map +1 -1
  73. package/dist/v2/runtime/handlers/handle-trajectory-connect.cjs +1 -1
  74. package/dist/v2/runtime/handlers/handle-trajectory-connect.mjs +1 -1
  75. package/dist/v2/runtime/handlers/intelligence/annotate.cjs +2 -2
  76. package/dist/v2/runtime/handlers/intelligence/annotate.mjs +2 -2
  77. package/dist/v2/runtime/handlers/intelligence/memories.cjs +1 -1
  78. package/dist/v2/runtime/handlers/intelligence/memories.mjs +1 -1
  79. package/dist/v2/runtime/handlers/intelligence/run.cjs +4 -4
  80. package/dist/v2/runtime/handlers/intelligence/run.mjs +4 -4
  81. package/dist/v2/runtime/handlers/intelligence/threads.cjs +137 -31
  82. package/dist/v2/runtime/handlers/intelligence/threads.cjs.map +1 -1
  83. package/dist/v2/runtime/handlers/intelligence/threads.mjs +138 -32
  84. package/dist/v2/runtime/handlers/intelligence/threads.mjs.map +1 -1
  85. package/dist/v2/runtime/handlers/shared/agent-utils.cjs +3 -3
  86. package/dist/v2/runtime/handlers/shared/agent-utils.mjs +3 -3
  87. package/dist/v2/runtime/handlers/shared/platform-error.cjs +1 -1
  88. package/dist/v2/runtime/handlers/shared/platform-error.mjs +1 -1
  89. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs +22 -3
  90. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -1
  91. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs +22 -4
  92. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -1
  93. package/dist/v2/runtime/handlers/shared/sse-response.cjs +19 -2
  94. package/dist/v2/runtime/handlers/shared/sse-response.cjs.map +1 -1
  95. package/dist/v2/runtime/handlers/shared/sse-response.mjs +19 -2
  96. package/dist/v2/runtime/handlers/shared/sse-response.mjs.map +1 -1
  97. package/dist/v2/runtime/handlers/shared/thread-access.cjs +138 -0
  98. package/dist/v2/runtime/handlers/shared/thread-access.cjs.map +1 -0
  99. package/dist/v2/runtime/handlers/shared/thread-access.d.cts +29 -0
  100. package/dist/v2/runtime/handlers/shared/thread-access.d.cts.map +1 -0
  101. package/dist/v2/runtime/handlers/shared/thread-access.d.mts +29 -0
  102. package/dist/v2/runtime/handlers/shared/thread-access.d.mts.map +1 -0
  103. package/dist/v2/runtime/handlers/shared/thread-access.mjs +133 -0
  104. package/dist/v2/runtime/handlers/shared/thread-access.mjs.map +1 -0
  105. package/dist/v2/runtime/handlers/sse/connect.cjs +2 -1
  106. package/dist/v2/runtime/handlers/sse/connect.cjs.map +1 -1
  107. package/dist/v2/runtime/handlers/sse/connect.mjs +2 -1
  108. package/dist/v2/runtime/handlers/sse/connect.mjs.map +1 -1
  109. package/dist/v2/runtime/handlers/sse/run.cjs +23 -6
  110. package/dist/v2/runtime/handlers/sse/run.cjs.map +1 -1
  111. package/dist/v2/runtime/handlers/sse/run.mjs +23 -6
  112. package/dist/v2/runtime/handlers/sse/run.mjs.map +1 -1
  113. package/dist/v2/runtime/index.d.cts +3 -2
  114. package/dist/v2/runtime/index.d.cts.map +1 -1
  115. package/dist/v2/runtime/index.d.mts +3 -2
  116. package/dist/v2/runtime/index.d.mts.map +1 -1
  117. package/dist/v2/runtime/intelligence-platform/client.cjs +16 -4
  118. package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
  119. package/dist/v2/runtime/intelligence-platform/client.d.cts +4 -37
  120. package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
  121. package/dist/v2/runtime/intelligence-platform/client.d.mts +4 -37
  122. package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
  123. package/dist/v2/runtime/intelligence-platform/client.mjs +16 -4
  124. package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
  125. package/dist/v2/runtime/runner/agent-runner.cjs +55 -0
  126. package/dist/v2/runtime/runner/agent-runner.cjs.map +1 -1
  127. package/dist/v2/runtime/runner/agent-runner.d.cts +90 -6
  128. package/dist/v2/runtime/runner/agent-runner.d.cts.map +1 -1
  129. package/dist/v2/runtime/runner/agent-runner.d.mts +90 -6
  130. package/dist/v2/runtime/runner/agent-runner.d.mts.map +1 -1
  131. package/dist/v2/runtime/runner/agent-runner.mjs +50 -1
  132. package/dist/v2/runtime/runner/agent-runner.mjs.map +1 -1
  133. package/dist/v2/runtime/runner/in-memory.cjs +205 -25
  134. package/dist/v2/runtime/runner/in-memory.cjs.map +1 -1
  135. package/dist/v2/runtime/runner/in-memory.d.cts +112 -15
  136. package/dist/v2/runtime/runner/in-memory.d.cts.map +1 -1
  137. package/dist/v2/runtime/runner/in-memory.d.mts +112 -15
  138. package/dist/v2/runtime/runner/in-memory.d.mts.map +1 -1
  139. package/dist/v2/runtime/runner/in-memory.mjs +206 -27
  140. package/dist/v2/runtime/runner/in-memory.mjs.map +1 -1
  141. package/dist/v2/runtime/runner/index.d.cts +2 -2
  142. package/dist/v2/runtime/runner/index.d.mts +2 -2
  143. package/dist/v2/runtime/runner/index.mjs +2 -2
  144. package/package.json +6 -6
@@ -0,0 +1,133 @@
1
+ import "reflect-metadata";
2
+ import { enforcesThreadOwnership, supportsLocalThreadEndpoints } from "../../runner/agent-runner.mjs";
3
+ import { errorResponse } from "./json-response.mjs";
4
+ import { hasIdentifyUser, resolveIntelligenceUser } from "./resolve-intelligence-user.mjs";
5
+
6
+ //#region src/v2/runtime/handlers/shared/thread-access.ts
7
+ /** The one place that sets the default Thread access mode. */
8
+ const DEFAULT_THREAD_ACCESS = "owner";
9
+ /** Owner id of a Thread created without identity. */
10
+ const ANONYMOUS_THREAD_OWNER = "";
11
+ /**
12
+ * THE anonymous-Thread policy: which operations a caller without identity
13
+ * (no `identifyUser`) may perform, per access mode. Every such operation
14
+ * still reaches only anonymous Threads, never a Thread an identified user
15
+ * owns. To tighten the default, change the `owner` row; nothing else encodes
16
+ * this policy.
17
+ *
18
+ * Callers identified by `identifyUser` are not in this table: every operation
19
+ * is allowed and reaches only their own Threads.
20
+ */
21
+ const ANONYMOUS_THREAD_ACCESS = {
22
+ owner: {
23
+ list: false,
24
+ clear: false,
25
+ read: true,
26
+ connect: true,
27
+ run: true,
28
+ stop: true,
29
+ isRunning: true
30
+ },
31
+ open: {
32
+ list: true,
33
+ clear: true,
34
+ read: true,
35
+ connect: true,
36
+ run: true,
37
+ stop: true,
38
+ isRunning: true
39
+ }
40
+ };
41
+ const THREAD_ACCESS_NOT_CONFIGURED_MESSAGE = "Listing and clearing threads need a caller identity. Pass `identifyUser: (request) => ({ id, name })` to CopilotRuntime so each user lists and clears only their own threads, or pass `threads: { access: \"open\" }` to let every caller share threads created without identity (insecure for multi-user deployments).";
42
+ /**
43
+ * The configuration error for `identifyUser` with a runner that cannot keep
44
+ * users apart. Every Thread operation is refused rather than served unscoped.
45
+ */
46
+ function threadOwnershipUnsupportedMessage(runner) {
47
+ return `identifyUser is set, but the runner ${runner.constructor?.name || "the configured runner"} does not enforce thread ownership: it has no isThreadAccessible method. Thread routes, run, connect and stop are refused so that no user can reach another user's threads. Use InMemoryAgentRunner or SqliteAgentRunner, or implement isThreadAccessible and honor ownerId in run, connect, stop and isRunning.`;
48
+ }
49
+ /**
50
+ * Log once, at runtime construction, when `identifyUser` is set but the runner
51
+ * does not enforce thread ownership. Requests then fail with the same message.
52
+ */
53
+ function warnIfThreadOwnershipUnenforced(runtime) {
54
+ if (hasIdentifyUser(runtime) && !enforcesThreadOwnership(runtime.runner)) console.warn(`[CopilotKit] ${threadOwnershipUnsupportedMessage(runtime.runner)}`);
55
+ }
56
+ /**
57
+ * The access mode `threads` selects. Throws on anything but an object whose
58
+ * `access` is `"owner"`, `"open"` or omitted: a typo must not silently fall
59
+ * back to the default.
60
+ */
61
+ function resolveThreadAccessMode(config) {
62
+ if (config === void 0) return DEFAULT_THREAD_ACCESS;
63
+ if (typeof config !== "object" || config === null) throw new Error("`threads` must be an object, such as `{ access: \"owner\" }`; got " + JSON.stringify(config));
64
+ const access = config.access;
65
+ if (access === void 0) return DEFAULT_THREAD_ACCESS;
66
+ if (access !== "owner" && access !== "open") throw new Error(`threads.access must be "owner" or "open"; got ${JSON.stringify(access)}`);
67
+ return access;
68
+ }
69
+ let threadListRefusalWarned = false;
70
+ /**
71
+ * Log once per process, at runtime construction, when the configuration
72
+ * refuses the Thread list and clear routes, so operators see why those
73
+ * requests get 403.
74
+ */
75
+ function warnIfThreadListRefused(runtime) {
76
+ if (threadListRefusalWarned) return;
77
+ if (!supportsLocalThreadEndpoints(runtime.runner)) return;
78
+ if (isThreadOperationAvailable(runtime, "list")) return;
79
+ threadListRefusalWarned = true;
80
+ console.warn(`[CopilotKit] ${THREAD_ACCESS_NOT_CONFIGURED_MESSAGE} Until then, GET /threads and POST /threads/clear return HTTP 403.`);
81
+ }
82
+ /**
83
+ * True when `operation` can serve requests on this runtime at all: always
84
+ * with `identifyUser` (scoped to the caller), otherwise per
85
+ * {@link ANONYMOUS_THREAD_ACCESS}.
86
+ */
87
+ function isThreadOperationAvailable(runtime, operation) {
88
+ if (hasIdentifyUser(runtime)) return enforcesThreadOwnership(runtime.runner);
89
+ return ANONYMOUS_THREAD_ACCESS[runtime.threadAccess ?? DEFAULT_THREAD_ACCESS][operation];
90
+ }
91
+ /**
92
+ * Resolves the owner id that a local Thread request acts as, or the error
93
+ * Response that refuses it. Every local Thread handler goes through here.
94
+ *
95
+ * - With `identifyUser`: the identified user's id. Refused when the runner
96
+ * cannot enforce owners, or when identification fails.
97
+ * - Without it: the anonymous owner, when {@link ANONYMOUS_THREAD_ACCESS}
98
+ * allows `operation` in the configured mode; otherwise a 403 that names the
99
+ * options to set.
100
+ */
101
+ async function resolveLocalThreadOwner(params) {
102
+ const { runtime, request, operation } = params;
103
+ if (hasIdentifyUser(runtime)) {
104
+ if (!enforcesThreadOwnership(runtime.runner)) return Response.json({
105
+ error: "thread_ownership_unsupported",
106
+ message: threadOwnershipUnsupportedMessage(runtime.runner)
107
+ }, { status: 500 });
108
+ const user = await resolveIntelligenceUser({
109
+ runtime,
110
+ request
111
+ });
112
+ return user instanceof Response ? user : user.id;
113
+ }
114
+ if (!isThreadOperationAvailable(runtime, operation)) return Response.json({
115
+ error: "thread_access_not_configured",
116
+ message: THREAD_ACCESS_NOT_CONFIGURED_MESSAGE
117
+ }, { status: 403 });
118
+ return ANONYMOUS_THREAD_OWNER;
119
+ }
120
+ /**
121
+ * The response to a run on a Thread that another identity owns, whether the
122
+ * handler's check or the runner refused it. It is the same 404 and body as an
123
+ * unknown Thread on the inspect routes, so it does not say that the Thread
124
+ * belongs to someone. A run on an unknown Thread id creates the Thread, so a
125
+ * refusal still shows that the id is taken; it never shows by whom.
126
+ */
127
+ function threadAccessDeniedResponse() {
128
+ return errorResponse("Thread not found", 404);
129
+ }
130
+
131
+ //#endregion
132
+ export { isThreadOperationAvailable, resolveLocalThreadOwner, resolveThreadAccessMode, threadAccessDeniedResponse, warnIfThreadListRefused, warnIfThreadOwnershipUnenforced };
133
+ //# sourceMappingURL=thread-access.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thread-access.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/shared/thread-access.ts"],"sourcesContent":["import type { CopilotRuntimeLike } from \"../../core/runtime\";\nimport type { AgentRunner } from \"../../runner/agent-runner\";\nimport {\n enforcesThreadOwnership,\n supportsLocalThreadEndpoints,\n} from \"../../runner/agent-runner\";\nimport { errorResponse } from \"./json-response\";\nimport {\n hasIdentifyUser,\n resolveIntelligenceUser,\n} from \"./resolve-intelligence-user\";\n\n/**\n * How local (non-Intelligence) Threads are shared among callers that\n * `identifyUser` does not identify. The full policy is\n * {@link ANONYMOUS_THREAD_ACCESS}.\n *\n * - `\"owner\"` (default): a Thread created without identity is a capability.\n * Whoever holds its id may read, connect to, continue and stop it, but\n * nobody may list or bulk-clear such Threads.\n * - `\"open\"`: every caller without identity shares those Threads, list and\n * clear included, as in earlier releases. Insecure for any deployment that\n * more than one person can reach.\n *\n * Neither mode loosens identity: with `identifyUser`, every operation reaches\n * only the caller's own Threads, and a Thread that an identified user created\n * is never reachable by an anonymous caller or another identity.\n */\nexport type ThreadAccessMode = \"owner\" | \"open\";\n\nexport interface ThreadsConfig {\n /** @default \"owner\" */\n access?: ThreadAccessMode;\n}\n\n/** The one place that sets the default Thread access mode. */\nexport const DEFAULT_THREAD_ACCESS: ThreadAccessMode = \"owner\";\n\n/** Owner id of a Thread created without identity. */\nexport const ANONYMOUS_THREAD_OWNER = \"\";\n\n/**\n * Every operation on a local Thread. `read` covers\n * `/threads/:id/{messages,events,state}`; `stop` covers a stop by Thread and a\n * stop by run id. `isRunning` has no route; runners check it the same way.\n */\nexport type ThreadOperation =\n | \"list\"\n | \"clear\"\n | \"read\"\n | \"connect\"\n | \"run\"\n | \"stop\"\n | \"isRunning\";\n\n/**\n * THE anonymous-Thread policy: which operations a caller without identity\n * (no `identifyUser`) may perform, per access mode. Every such operation\n * still reaches only anonymous Threads, never a Thread an identified user\n * owns. To tighten the default, change the `owner` row; nothing else encodes\n * this policy.\n *\n * Callers identified by `identifyUser` are not in this table: every operation\n * is allowed and reaches only their own Threads.\n */\nexport const ANONYMOUS_THREAD_ACCESS: Readonly<\n Record<ThreadAccessMode, Readonly<Record<ThreadOperation, boolean>>>\n> = {\n // A Thread id works as a capability for the Thread it names. Enumerating or\n // wiping every anonymous Thread needs identity or an explicit opt-in.\n owner: {\n list: false,\n clear: false,\n read: true,\n connect: true,\n run: true,\n stop: true,\n isRunning: true,\n },\n open: {\n list: true,\n clear: true,\n read: true,\n connect: true,\n run: true,\n stop: true,\n isRunning: true,\n },\n};\n\nexport const THREAD_ACCESS_NOT_CONFIGURED_MESSAGE =\n \"Listing and clearing threads need a caller identity. Pass `identifyUser: (request) => ({ id, name })` \" +\n \"to CopilotRuntime so each user lists and clears only their own threads, or pass \" +\n '`threads: { access: \"open\" }` to let every caller share threads created without identity ' +\n \"(insecure for multi-user deployments).\";\n\n/**\n * The configuration error for `identifyUser` with a runner that cannot keep\n * users apart. Every Thread operation is refused rather than served unscoped.\n */\nexport function threadOwnershipUnsupportedMessage(runner: AgentRunner): string {\n const name = runner.constructor?.name || \"the configured runner\";\n return (\n `identifyUser is set, but the runner ${name} does not enforce thread ownership: ` +\n \"it has no isThreadAccessible method. Thread routes, run, connect and stop are refused \" +\n \"so that no user can reach another user's threads. Use InMemoryAgentRunner or \" +\n \"SqliteAgentRunner, or implement isThreadAccessible and honor ownerId in run, connect, \" +\n \"stop and isRunning.\"\n );\n}\n\n/**\n * Log once, at runtime construction, when `identifyUser` is set but the runner\n * does not enforce thread ownership. Requests then fail with the same message.\n */\nexport function warnIfThreadOwnershipUnenforced(\n runtime: CopilotRuntimeLike,\n): void {\n if (hasIdentifyUser(runtime) && !enforcesThreadOwnership(runtime.runner)) {\n console.warn(\n `[CopilotKit] ${threadOwnershipUnsupportedMessage(runtime.runner)}`,\n );\n }\n}\n\n/**\n * The access mode `threads` selects. Throws on anything but an object whose\n * `access` is `\"owner\"`, `\"open\"` or omitted: a typo must not silently fall\n * back to the default.\n */\nexport function resolveThreadAccessMode(\n config: ThreadsConfig | undefined,\n): ThreadAccessMode {\n if (config === undefined) return DEFAULT_THREAD_ACCESS;\n if (typeof config !== \"object\" || config === null) {\n throw new Error(\n '`threads` must be an object, such as `{ access: \"owner\" }`; got ' +\n JSON.stringify(config),\n );\n }\n const access: unknown = config.access;\n if (access === undefined) return DEFAULT_THREAD_ACCESS;\n if (access !== \"owner\" && access !== \"open\") {\n throw new Error(\n `threads.access must be \"owner\" or \"open\"; got ${JSON.stringify(access)}`,\n );\n }\n return access;\n}\n\nlet threadListRefusalWarned = false;\n\n/** Re-arm the once-per-process startup warnings. Internal: for tests. */\nexport function ɵresetThreadAccessWarnings(): void {\n threadListRefusalWarned = false;\n}\n\n/**\n * Log once per process, at runtime construction, when the configuration\n * refuses the Thread list and clear routes, so operators see why those\n * requests get 403.\n */\nexport function warnIfThreadListRefused(runtime: CopilotRuntimeLike): void {\n if (threadListRefusalWarned) return;\n if (!supportsLocalThreadEndpoints(runtime.runner)) return;\n if (isThreadOperationAvailable(runtime, \"list\")) return;\n threadListRefusalWarned = true;\n console.warn(\n `[CopilotKit] ${THREAD_ACCESS_NOT_CONFIGURED_MESSAGE} Until then, ` +\n \"GET /threads and POST /threads/clear return HTTP 403.\",\n );\n}\n\n/**\n * True when `operation` can serve requests on this runtime at all: always\n * with `identifyUser` (scoped to the caller), otherwise per\n * {@link ANONYMOUS_THREAD_ACCESS}.\n */\nexport function isThreadOperationAvailable(\n runtime: CopilotRuntimeLike,\n operation: ThreadOperation,\n): boolean {\n // The same identity test as resolveLocalThreadOwner, so a non-function\n // value is no identity everywhere and never opens list or clear.\n if (hasIdentifyUser(runtime)) {\n return enforcesThreadOwnership(runtime.runner);\n }\n return ANONYMOUS_THREAD_ACCESS[runtime.threadAccess ?? DEFAULT_THREAD_ACCESS][\n operation\n ];\n}\n\n/**\n * Resolves the owner id that a local Thread request acts as, or the error\n * Response that refuses it. Every local Thread handler goes through here.\n *\n * - With `identifyUser`: the identified user's id. Refused when the runner\n * cannot enforce owners, or when identification fails.\n * - Without it: the anonymous owner, when {@link ANONYMOUS_THREAD_ACCESS}\n * allows `operation` in the configured mode; otherwise a 403 that names the\n * options to set.\n */\nexport async function resolveLocalThreadOwner(params: {\n runtime: CopilotRuntimeLike;\n request: Request;\n operation: ThreadOperation;\n}): Promise<string | Response> {\n const { runtime, request, operation } = params;\n if (hasIdentifyUser(runtime)) {\n // Never serve an identified request through a runner that cannot keep\n // users apart: refuse it with the configuration error instead.\n if (!enforcesThreadOwnership(runtime.runner)) {\n return Response.json(\n {\n error: \"thread_ownership_unsupported\",\n message: threadOwnershipUnsupportedMessage(runtime.runner),\n },\n { status: 500 },\n );\n }\n const user = await resolveIntelligenceUser({ runtime, request });\n return user instanceof Response ? user : user.id;\n }\n if (!isThreadOperationAvailable(runtime, operation)) {\n return Response.json(\n {\n error: \"thread_access_not_configured\",\n message: THREAD_ACCESS_NOT_CONFIGURED_MESSAGE,\n },\n { status: 403 },\n );\n }\n return ANONYMOUS_THREAD_OWNER;\n}\n\n/**\n * The response to a run on a Thread that another identity owns, whether the\n * handler's check or the runner refused it. It is the same 404 and body as an\n * unknown Thread on the inspect routes, so it does not say that the Thread\n * belongs to someone. A run on an unknown Thread id creates the Thread, so a\n * refusal still shows that the id is taken; it never shows by whom.\n */\nexport function threadAccessDeniedResponse(): Response {\n return errorResponse(\"Thread not found\", 404);\n}\n"],"mappings":";;;;;;;AAoCA,MAAa,wBAA0C;;AAGvD,MAAa,yBAAyB;;;;;;;;;;;AA0BtC,MAAa,0BAET;CAGF,OAAO;EACL,MAAM;EACN,OAAO;EACP,MAAM;EACN,SAAS;EACT,KAAK;EACL,MAAM;EACN,WAAW;EACZ;CACD,MAAM;EACJ,MAAM;EACN,OAAO;EACP,MAAM;EACN,SAAS;EACT,KAAK;EACL,MAAM;EACN,WAAW;EACZ;CACF;AAED,MAAa,uCACX;;;;;AASF,SAAgB,kCAAkC,QAA6B;AAE7E,QACE,uCAFW,OAAO,aAAa,QAAQ,wBAEK;;;;;;AAYhD,SAAgB,gCACd,SACM;AACN,KAAI,gBAAgB,QAAQ,IAAI,CAAC,wBAAwB,QAAQ,OAAO,CACtE,SAAQ,KACN,gBAAgB,kCAAkC,QAAQ,OAAO,GAClE;;;;;;;AASL,SAAgB,wBACd,QACkB;AAClB,KAAI,WAAW,OAAW,QAAO;AACjC,KAAI,OAAO,WAAW,YAAY,WAAW,KAC3C,OAAM,IAAI,MACR,uEACE,KAAK,UAAU,OAAO,CACzB;CAEH,MAAM,SAAkB,OAAO;AAC/B,KAAI,WAAW,OAAW,QAAO;AACjC,KAAI,WAAW,WAAW,WAAW,OACnC,OAAM,IAAI,MACR,iDAAiD,KAAK,UAAU,OAAO,GACxE;AAEH,QAAO;;AAGT,IAAI,0BAA0B;;;;;;AAY9B,SAAgB,wBAAwB,SAAmC;AACzE,KAAI,wBAAyB;AAC7B,KAAI,CAAC,6BAA6B,QAAQ,OAAO,CAAE;AACnD,KAAI,2BAA2B,SAAS,OAAO,CAAE;AACjD,2BAA0B;AAC1B,SAAQ,KACN,gBAAgB,qCAAqC,oEAEtD;;;;;;;AAQH,SAAgB,2BACd,SACA,WACS;AAGT,KAAI,gBAAgB,QAAQ,CAC1B,QAAO,wBAAwB,QAAQ,OAAO;AAEhD,QAAO,wBAAwB,QAAQ,gBAAgB,uBACrD;;;;;;;;;;;;AAcJ,eAAsB,wBAAwB,QAIf;CAC7B,MAAM,EAAE,SAAS,SAAS,cAAc;AACxC,KAAI,gBAAgB,QAAQ,EAAE;AAG5B,MAAI,CAAC,wBAAwB,QAAQ,OAAO,CAC1C,QAAO,SAAS,KACd;GACE,OAAO;GACP,SAAS,kCAAkC,QAAQ,OAAO;GAC3D,EACD,EAAE,QAAQ,KAAK,CAChB;EAEH,MAAM,OAAO,MAAM,wBAAwB;GAAE;GAAS;GAAS,CAAC;AAChE,SAAO,gBAAgB,WAAW,OAAO,KAAK;;AAEhD,KAAI,CAAC,2BAA2B,SAAS,UAAU,CACjD,QAAO,SAAS,KACd;EACE,OAAO;EACP,SAAS;EACV,EACD,EAAE,QAAQ,KAAK,CAChB;AAEH,QAAO;;;;;;;;;AAUT,SAAgB,6BAAuC;AACrD,QAAO,cAAc,oBAAoB,IAAI"}
@@ -3,7 +3,7 @@ const require_header_utils = require('../header-utils.cjs');
3
3
  const require_sse_response = require('../shared/sse-response.cjs');
4
4
 
5
5
  //#region src/v2/runtime/handlers/sse/connect.ts
6
- function handleSseConnect({ runtime, request, agentId, threadId, agent }) {
6
+ function handleSseConnect({ runtime, request, agentId, threadId, agent, ownerId }) {
7
7
  return require_sse_response.createSseEventResponse({
8
8
  request,
9
9
  debugEventBus: runtime.debugEventBus,
@@ -13,6 +13,7 @@ function handleSseConnect({ runtime, request, agentId, threadId, agent }) {
13
13
  observableFactory: () => runtime.runner.connect({
14
14
  threadId,
15
15
  agentId,
16
+ ...ownerId === void 0 ? {} : { ownerId },
16
17
  headers: require_header_utils.mergeForwardableHeaders(agent?.headers, request, runtime.forwardHeadersPolicy ?? require_header_utils.resolveForwardHeadersPolicy(void 0))
17
18
  })
18
19
  });
@@ -1 +1 @@
1
- {"version":3,"file":"connect.cjs","names":["createSseEventResponse","mergeForwardableHeaders","resolveForwardHeadersPolicy"],"sources":["../../../../../src/v2/runtime/handlers/sse/connect.ts"],"sourcesContent":["import type { AbstractAgent } from \"@ag-ui/client\";\nimport type { CopilotRuntimeLike } from \"../../core/runtime\";\nimport { createSseEventResponse } from \"../shared/sse-response\";\nimport {\n mergeForwardableHeaders,\n resolveForwardHeadersPolicy,\n} from \"../header-utils\";\n\n/**\n * `headers` lives on the HTTP-backed agent configs (e.g. `HttpAgent`), not on\n * the base `AbstractAgent`. Mirror the runtime's own optional-headers shape so\n * we can read server-configured headers off the per-request clone without a\n * cast. See `agent-utils.ts`.\n */\ntype AgentWithHeaders = AbstractAgent & {\n headers?: Record<string, string>;\n};\n\ninterface HandleSseConnectParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n agentId: string;\n threadId: string;\n /**\n * The per-request agent clone, carrying any server-configured `agent.headers`\n * (e.g. service-to-service auth). Used only to compute the merged header set\n * threaded into `runner.connect` below — see the note there for why that\n * merge is forward-looking plumbing rather than active outbound auth today.\n */\n agent?: AgentWithHeaders;\n}\n\nexport function handleSseConnect({\n runtime,\n request,\n agentId,\n threadId,\n agent,\n}: HandleSseConnectParams): Response {\n return createSseEventResponse({\n request,\n debugEventBus: runtime.debugEventBus,\n // Forward the real agentId so debug envelopes reflect the agent the\n // route resolved to — not the literal string \"connect\".\n agentId,\n telemetry: runtime.telemetry,\n keepAliveIntervalSeconds: runtime.sseKeepAliveIntervalSeconds,\n observableFactory: () =>\n runtime.runner.connect({\n threadId,\n agentId,\n // Forward-looking plumbing: we compute the merged header set (server\n // `agent.headers` win on collision, case-insensitively; non-colliding\n // inbound headers still forward — see `mergeForwardableHeaders`, #5712)\n // and thread it into `runner.connect`. NO shipped runner consumes the\n // `headers` field of `AgentRunnerConnectRequest` today — every runner\n // (in-memory, intelligence, telemetry, sqlite) reads only `threadId`.\n // The real outbound header forwarding is the /run path, where\n // `cloneAgentForRequest` mutates `agent.headers` directly\n // (agent-utils.ts). This wiring exists so a future outbound-connecting\n // runner can pick the merged headers up without a route change; the\n // collision precedence noted here is purely about that merge, not about\n // middleware/mutation parity with /run.\n headers: mergeForwardableHeaders(\n agent?.headers,\n request,\n // Optional on `CopilotRuntimeLike` (non-breaking minor release);\n // coalesce a policy-less external implementor to the default resolved\n // policy (default-on denylist) instead of dereffing undefined.\n runtime.forwardHeadersPolicy ??\n resolveForwardHeadersPolicy(undefined),\n ),\n }),\n });\n}\n"],"mappings":";;;;;AAgCA,SAAgB,iBAAiB,EAC/B,SACA,SACA,SACA,UACA,SACmC;AACnC,QAAOA,4CAAuB;EAC5B;EACA,eAAe,QAAQ;EAGvB;EACA,WAAW,QAAQ;EACnB,0BAA0B,QAAQ;EAClC,yBACE,QAAQ,OAAO,QAAQ;GACrB;GACA;GAaA,SAASC,6CACP,OAAO,SACP,SAIA,QAAQ,wBACNC,iDAA4B,OAAU,CACzC;GACF,CAAC;EACL,CAAC"}
1
+ {"version":3,"file":"connect.cjs","names":["createSseEventResponse","mergeForwardableHeaders","resolveForwardHeadersPolicy"],"sources":["../../../../../src/v2/runtime/handlers/sse/connect.ts"],"sourcesContent":["import type { AbstractAgent } from \"@ag-ui/client\";\nimport type { CopilotRuntimeLike } from \"../../core/runtime\";\nimport { createSseEventResponse } from \"../shared/sse-response\";\nimport {\n mergeForwardableHeaders,\n resolveForwardHeadersPolicy,\n} from \"../header-utils\";\n\n/**\n * `headers` lives on the HTTP-backed agent configs (e.g. `HttpAgent`), not on\n * the base `AbstractAgent`. Mirror the runtime's own optional-headers shape so\n * we can read server-configured headers off the per-request clone without a\n * cast. See `agent-utils.ts`.\n */\ntype AgentWithHeaders = AbstractAgent & {\n headers?: Record<string, string>;\n};\n\ninterface HandleSseConnectParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n agentId: string;\n threadId: string;\n /**\n * The per-request agent clone, carrying any server-configured `agent.headers`\n * (e.g. service-to-service auth). Used only to compute the merged header set\n * threaded into `runner.connect` below — see the note there for why that\n * merge is forward-looking plumbing rather than active outbound auth today.\n */\n agent?: AgentWithHeaders;\n /** Caller identity; the runner hides threads owned by anyone else. */\n ownerId?: string;\n}\n\nexport function handleSseConnect({\n runtime,\n request,\n agentId,\n threadId,\n agent,\n ownerId,\n}: HandleSseConnectParams): Response {\n return createSseEventResponse({\n request,\n debugEventBus: runtime.debugEventBus,\n // Forward the real agentId so debug envelopes reflect the agent the\n // route resolved to — not the literal string \"connect\".\n agentId,\n telemetry: runtime.telemetry,\n keepAliveIntervalSeconds: runtime.sseKeepAliveIntervalSeconds,\n observableFactory: () =>\n runtime.runner.connect({\n threadId,\n agentId,\n ...(ownerId === undefined ? {} : { ownerId }),\n // Forward-looking plumbing: we compute the merged header set (server\n // `agent.headers` win on collision, case-insensitively; non-colliding\n // inbound headers still forward — see `mergeForwardableHeaders`, #5712)\n // and thread it into `runner.connect`. NO shipped runner consumes the\n // `headers` field of `AgentRunnerConnectRequest` today — every runner\n // (in-memory, intelligence, telemetry, sqlite) ignores it.\n // The real outbound header forwarding is the /run path, where\n // `cloneAgentForRequest` mutates `agent.headers` directly\n // (agent-utils.ts). This wiring exists so a future outbound-connecting\n // runner can pick the merged headers up without a route change; the\n // collision precedence noted here is purely about that merge, not about\n // middleware/mutation parity with /run.\n headers: mergeForwardableHeaders(\n agent?.headers,\n request,\n // Optional on `CopilotRuntimeLike` (non-breaking minor release);\n // coalesce a policy-less external implementor to the default resolved\n // policy (default-on denylist) instead of dereffing undefined.\n runtime.forwardHeadersPolicy ??\n resolveForwardHeadersPolicy(undefined),\n ),\n }),\n });\n}\n"],"mappings":";;;;;AAkCA,SAAgB,iBAAiB,EAC/B,SACA,SACA,SACA,UACA,OACA,WACmC;AACnC,QAAOA,4CAAuB;EAC5B;EACA,eAAe,QAAQ;EAGvB;EACA,WAAW,QAAQ;EACnB,0BAA0B,QAAQ;EAClC,yBACE,QAAQ,OAAO,QAAQ;GACrB;GACA;GACA,GAAI,YAAY,SAAY,EAAE,GAAG,EAAE,SAAS;GAa5C,SAASC,6CACP,OAAO,SACP,SAIA,QAAQ,wBACNC,iDAA4B,OAAU,CACzC;GACF,CAAC;EACL,CAAC"}
@@ -3,7 +3,7 @@ import { mergeForwardableHeaders, resolveForwardHeadersPolicy } from "../header-
3
3
  import { createSseEventResponse } from "../shared/sse-response.mjs";
4
4
 
5
5
  //#region src/v2/runtime/handlers/sse/connect.ts
6
- function handleSseConnect({ runtime, request, agentId, threadId, agent }) {
6
+ function handleSseConnect({ runtime, request, agentId, threadId, agent, ownerId }) {
7
7
  return createSseEventResponse({
8
8
  request,
9
9
  debugEventBus: runtime.debugEventBus,
@@ -13,6 +13,7 @@ function handleSseConnect({ runtime, request, agentId, threadId, agent }) {
13
13
  observableFactory: () => runtime.runner.connect({
14
14
  threadId,
15
15
  agentId,
16
+ ...ownerId === void 0 ? {} : { ownerId },
16
17
  headers: mergeForwardableHeaders(agent?.headers, request, runtime.forwardHeadersPolicy ?? resolveForwardHeadersPolicy(void 0))
17
18
  })
18
19
  });
@@ -1 +1 @@
1
- {"version":3,"file":"connect.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/sse/connect.ts"],"sourcesContent":["import type { AbstractAgent } from \"@ag-ui/client\";\nimport type { CopilotRuntimeLike } from \"../../core/runtime\";\nimport { createSseEventResponse } from \"../shared/sse-response\";\nimport {\n mergeForwardableHeaders,\n resolveForwardHeadersPolicy,\n} from \"../header-utils\";\n\n/**\n * `headers` lives on the HTTP-backed agent configs (e.g. `HttpAgent`), not on\n * the base `AbstractAgent`. Mirror the runtime's own optional-headers shape so\n * we can read server-configured headers off the per-request clone without a\n * cast. See `agent-utils.ts`.\n */\ntype AgentWithHeaders = AbstractAgent & {\n headers?: Record<string, string>;\n};\n\ninterface HandleSseConnectParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n agentId: string;\n threadId: string;\n /**\n * The per-request agent clone, carrying any server-configured `agent.headers`\n * (e.g. service-to-service auth). Used only to compute the merged header set\n * threaded into `runner.connect` below — see the note there for why that\n * merge is forward-looking plumbing rather than active outbound auth today.\n */\n agent?: AgentWithHeaders;\n}\n\nexport function handleSseConnect({\n runtime,\n request,\n agentId,\n threadId,\n agent,\n}: HandleSseConnectParams): Response {\n return createSseEventResponse({\n request,\n debugEventBus: runtime.debugEventBus,\n // Forward the real agentId so debug envelopes reflect the agent the\n // route resolved to — not the literal string \"connect\".\n agentId,\n telemetry: runtime.telemetry,\n keepAliveIntervalSeconds: runtime.sseKeepAliveIntervalSeconds,\n observableFactory: () =>\n runtime.runner.connect({\n threadId,\n agentId,\n // Forward-looking plumbing: we compute the merged header set (server\n // `agent.headers` win on collision, case-insensitively; non-colliding\n // inbound headers still forward — see `mergeForwardableHeaders`, #5712)\n // and thread it into `runner.connect`. NO shipped runner consumes the\n // `headers` field of `AgentRunnerConnectRequest` today — every runner\n // (in-memory, intelligence, telemetry, sqlite) reads only `threadId`.\n // The real outbound header forwarding is the /run path, where\n // `cloneAgentForRequest` mutates `agent.headers` directly\n // (agent-utils.ts). This wiring exists so a future outbound-connecting\n // runner can pick the merged headers up without a route change; the\n // collision precedence noted here is purely about that merge, not about\n // middleware/mutation parity with /run.\n headers: mergeForwardableHeaders(\n agent?.headers,\n request,\n // Optional on `CopilotRuntimeLike` (non-breaking minor release);\n // coalesce a policy-less external implementor to the default resolved\n // policy (default-on denylist) instead of dereffing undefined.\n runtime.forwardHeadersPolicy ??\n resolveForwardHeadersPolicy(undefined),\n ),\n }),\n });\n}\n"],"mappings":";;;;;AAgCA,SAAgB,iBAAiB,EAC/B,SACA,SACA,SACA,UACA,SACmC;AACnC,QAAO,uBAAuB;EAC5B;EACA,eAAe,QAAQ;EAGvB;EACA,WAAW,QAAQ;EACnB,0BAA0B,QAAQ;EAClC,yBACE,QAAQ,OAAO,QAAQ;GACrB;GACA;GAaA,SAAS,wBACP,OAAO,SACP,SAIA,QAAQ,wBACN,4BAA4B,OAAU,CACzC;GACF,CAAC;EACL,CAAC"}
1
+ {"version":3,"file":"connect.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/sse/connect.ts"],"sourcesContent":["import type { AbstractAgent } from \"@ag-ui/client\";\nimport type { CopilotRuntimeLike } from \"../../core/runtime\";\nimport { createSseEventResponse } from \"../shared/sse-response\";\nimport {\n mergeForwardableHeaders,\n resolveForwardHeadersPolicy,\n} from \"../header-utils\";\n\n/**\n * `headers` lives on the HTTP-backed agent configs (e.g. `HttpAgent`), not on\n * the base `AbstractAgent`. Mirror the runtime's own optional-headers shape so\n * we can read server-configured headers off the per-request clone without a\n * cast. See `agent-utils.ts`.\n */\ntype AgentWithHeaders = AbstractAgent & {\n headers?: Record<string, string>;\n};\n\ninterface HandleSseConnectParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n agentId: string;\n threadId: string;\n /**\n * The per-request agent clone, carrying any server-configured `agent.headers`\n * (e.g. service-to-service auth). Used only to compute the merged header set\n * threaded into `runner.connect` below — see the note there for why that\n * merge is forward-looking plumbing rather than active outbound auth today.\n */\n agent?: AgentWithHeaders;\n /** Caller identity; the runner hides threads owned by anyone else. */\n ownerId?: string;\n}\n\nexport function handleSseConnect({\n runtime,\n request,\n agentId,\n threadId,\n agent,\n ownerId,\n}: HandleSseConnectParams): Response {\n return createSseEventResponse({\n request,\n debugEventBus: runtime.debugEventBus,\n // Forward the real agentId so debug envelopes reflect the agent the\n // route resolved to — not the literal string \"connect\".\n agentId,\n telemetry: runtime.telemetry,\n keepAliveIntervalSeconds: runtime.sseKeepAliveIntervalSeconds,\n observableFactory: () =>\n runtime.runner.connect({\n threadId,\n agentId,\n ...(ownerId === undefined ? {} : { ownerId }),\n // Forward-looking plumbing: we compute the merged header set (server\n // `agent.headers` win on collision, case-insensitively; non-colliding\n // inbound headers still forward — see `mergeForwardableHeaders`, #5712)\n // and thread it into `runner.connect`. NO shipped runner consumes the\n // `headers` field of `AgentRunnerConnectRequest` today — every runner\n // (in-memory, intelligence, telemetry, sqlite) ignores it.\n // The real outbound header forwarding is the /run path, where\n // `cloneAgentForRequest` mutates `agent.headers` directly\n // (agent-utils.ts). This wiring exists so a future outbound-connecting\n // runner can pick the merged headers up without a route change; the\n // collision precedence noted here is purely about that merge, not about\n // middleware/mutation parity with /run.\n headers: mergeForwardableHeaders(\n agent?.headers,\n request,\n // Optional on `CopilotRuntimeLike` (non-breaking minor release);\n // coalesce a policy-less external implementor to the default resolved\n // policy (default-on denylist) instead of dereffing undefined.\n runtime.forwardHeadersPolicy ??\n resolveForwardHeadersPolicy(undefined),\n ),\n }),\n });\n}\n"],"mappings":";;;;;AAkCA,SAAgB,iBAAiB,EAC/B,SACA,SACA,SACA,UACA,OACA,WACmC;AACnC,QAAO,uBAAuB;EAC5B;EACA,eAAe,QAAQ;EAGvB;EACA,WAAW,QAAQ;EACnB,0BAA0B,QAAQ;EAClC,yBACE,QAAQ,OAAO,QAAQ;GACrB;GACA;GACA,GAAI,YAAY,SAAY,EAAE,GAAG,EAAE,SAAS;GAa5C,SAAS,wBACP,OAAO,SACP,SAIA,QAAQ,wBACN,4BAA4B,OAAU,CACzC;GACF,CAAC;EACL,CAAC"}
@@ -1,9 +1,27 @@
1
1
  require("reflect-metadata");
2
+ const require_agent_runner = require('../../runner/agent-runner.cjs');
3
+ const require_thread_access = require('../shared/thread-access.cjs');
2
4
  const require_runtime_error_reporter = require('../../core/runtime-error-reporter.cjs');
3
5
  const require_sse_response = require('../shared/sse-response.cjs');
4
6
 
5
7
  //#region src/v2/runtime/handlers/sse/run.ts
6
- function handleSseRun({ runtime, request, agent, input, agentId, debug, logger, startTime }) {
8
+ function handleSseRun({ runtime, request, agent, input, agentId, debug, logger, startTime, ownerId }) {
9
+ let started;
10
+ let startError;
11
+ try {
12
+ started = runtime.runner.run({
13
+ threadId: input.threadId,
14
+ agent,
15
+ input,
16
+ ...ownerId === void 0 ? {} : { ownerId }
17
+ });
18
+ } catch (error) {
19
+ if (require_agent_runner.isThreadAccessDeniedError(error)) {
20
+ console.warn("[CopilotKit] Run refused: the thread belongs to another identity.");
21
+ return require_thread_access.threadAccessDeniedResponse();
22
+ }
23
+ startError = error;
24
+ }
7
25
  return require_sse_response.createSseEventResponse({
8
26
  request,
9
27
  debugEventBus: runtime.debugEventBus,
@@ -15,11 +33,10 @@ function handleSseRun({ runtime, request, agent, input, agentId, debug, logger,
15
33
  telemetry: runtime.telemetry,
16
34
  keepAliveIntervalSeconds: runtime.sseKeepAliveIntervalSeconds,
17
35
  executionSeed: { llmHostClass: agent.modelHostClass ?? "unknown" },
18
- observableFactory: () => runtime.runner.run({
19
- threadId: input.threadId,
20
- agent,
21
- input
22
- })
36
+ observableFactory: () => {
37
+ if (started === void 0) throw startError;
38
+ return started;
39
+ }
23
40
  });
24
41
  }
25
42
 
@@ -1 +1 @@
1
- {"version":3,"file":"run.cjs","names":["createSseEventResponse","getRuntimeErrorReporter"],"sources":["../../../../../src/v2/runtime/handlers/sse/run.ts"],"sourcesContent":["import type { AbstractAgent, RunAgentInput } from \"@ag-ui/client\";\nimport type { ResolvedDebugConfig, ModelHostClass } from \"@copilotkit/shared\";\nimport type { CopilotRuntimeLogger } from \"../../../../v1-deprecated/lib/logger\";\nimport type { CopilotRuntimeLike } from \"../../core/runtime\";\nimport { getRuntimeErrorReporter } from \"../../core/runtime-error-reporter\";\nimport { createSseEventResponse } from \"../shared/sse-response\";\n\ninterface HandleSseRunParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n agent: AbstractAgent;\n input: RunAgentInput;\n agentId: string;\n debug?: ResolvedDebugConfig;\n /** Pre-created logger instance to avoid creating a new pino logger per request. */\n logger?: CopilotRuntimeLogger;\n startTime?: number;\n}\n\nexport function handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug,\n logger,\n startTime,\n}: HandleSseRunParams): Response {\n return createSseEventResponse({\n request,\n debugEventBus: runtime.debugEventBus,\n agentId,\n debug,\n logger,\n runtimeErrorReporter: getRuntimeErrorReporter(runtime),\n startTime,\n telemetry: runtime.telemetry,\n keepAliveIntervalSeconds: runtime.sseKeepAliveIntervalSeconds,\n // Read structurally rather than via `instanceof BuiltInAgent`, which would\n // pull the agent module into this handler. Any agent can opt in by\n // exposing the same property.\n executionSeed: {\n llmHostClass:\n (agent as { modelHostClass?: ModelHostClass }).modelHostClass ??\n \"unknown\",\n },\n observableFactory: () =>\n runtime.runner.run({\n threadId: input.threadId,\n agent,\n input,\n }),\n });\n}\n"],"mappings":";;;;;AAmBA,SAAgB,aAAa,EAC3B,SACA,SACA,OACA,OACA,SACA,OACA,QACA,aAC+B;AAC/B,QAAOA,4CAAuB;EAC5B;EACA,eAAe,QAAQ;EACvB;EACA;EACA;EACA,sBAAsBC,uDAAwB,QAAQ;EACtD;EACA,WAAW,QAAQ;EACnB,0BAA0B,QAAQ;EAIlC,eAAe,EACb,cACG,MAA8C,kBAC/C,WACH;EACD,yBACE,QAAQ,OAAO,IAAI;GACjB,UAAU,MAAM;GAChB;GACA;GACD,CAAC;EACL,CAAC"}
1
+ {"version":3,"file":"run.cjs","names":["isThreadAccessDeniedError","threadAccessDeniedResponse","createSseEventResponse","getRuntimeErrorReporter"],"sources":["../../../../../src/v2/runtime/handlers/sse/run.ts"],"sourcesContent":["import type { AbstractAgent, BaseEvent, RunAgentInput } from \"@ag-ui/client\";\nimport type { Observable } from \"rxjs\";\nimport { isThreadAccessDeniedError } from \"../../runner/agent-runner\";\nimport { threadAccessDeniedResponse } from \"../shared/thread-access\";\nimport type { ResolvedDebugConfig, ModelHostClass } from \"@copilotkit/shared\";\nimport type { CopilotRuntimeLogger } from \"../../../../v1-deprecated/lib/logger\";\nimport type { CopilotRuntimeLike } from \"../../core/runtime\";\nimport { getRuntimeErrorReporter } from \"../../core/runtime-error-reporter\";\nimport { createSseEventResponse } from \"../shared/sse-response\";\n\ninterface HandleSseRunParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n agent: AbstractAgent;\n input: RunAgentInput;\n agentId: string;\n debug?: ResolvedDebugConfig;\n /** Pre-created logger instance to avoid creating a new pino logger per request. */\n logger?: CopilotRuntimeLogger;\n startTime?: number;\n /** Identity the run acts as; the runner records it as the thread owner. */\n ownerId?: string;\n}\n\nexport function handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug,\n logger,\n startTime,\n ownerId,\n}: HandleSseRunParams): Response {\n // Start the run before the stream opens. When another identity claimed the\n // thread after the handler's owner check, the runner refuses at once, and\n // that refusal becomes the same HTTP error as the check's, not a streamed\n // agent failure. Any other start error still reaches the client as a\n // RUN_ERROR on the stream, as before.\n let started: Observable<BaseEvent> | undefined;\n let startError: unknown;\n try {\n started = runtime.runner.run({\n threadId: input.threadId,\n agent,\n input,\n ...(ownerId === undefined ? {} : { ownerId }),\n });\n } catch (error) {\n if (isThreadAccessDeniedError(error)) {\n console.warn(\n \"[CopilotKit] Run refused: the thread belongs to another identity.\",\n );\n return threadAccessDeniedResponse();\n }\n startError = error;\n }\n\n return createSseEventResponse({\n request,\n debugEventBus: runtime.debugEventBus,\n agentId,\n debug,\n logger,\n runtimeErrorReporter: getRuntimeErrorReporter(runtime),\n startTime,\n telemetry: runtime.telemetry,\n keepAliveIntervalSeconds: runtime.sseKeepAliveIntervalSeconds,\n // Read structurally rather than via `instanceof BuiltInAgent`, which would\n // pull the agent module into this handler. Any agent can opt in by\n // exposing the same property.\n executionSeed: {\n llmHostClass:\n (agent as { modelHostClass?: ModelHostClass }).modelHostClass ??\n \"unknown\",\n },\n observableFactory: () => {\n if (started === undefined) throw startError;\n return started;\n },\n });\n}\n"],"mappings":";;;;;;;AAwBA,SAAgB,aAAa,EAC3B,SACA,SACA,OACA,OACA,SACA,OACA,QACA,WACA,WAC+B;CAM/B,IAAI;CACJ,IAAI;AACJ,KAAI;AACF,YAAU,QAAQ,OAAO,IAAI;GAC3B,UAAU,MAAM;GAChB;GACA;GACA,GAAI,YAAY,SAAY,EAAE,GAAG,EAAE,SAAS;GAC7C,CAAC;UACK,OAAO;AACd,MAAIA,+CAA0B,MAAM,EAAE;AACpC,WAAQ,KACN,oEACD;AACD,UAAOC,kDAA4B;;AAErC,eAAa;;AAGf,QAAOC,4CAAuB;EAC5B;EACA,eAAe,QAAQ;EACvB;EACA;EACA;EACA,sBAAsBC,uDAAwB,QAAQ;EACtD;EACA,WAAW,QAAQ;EACnB,0BAA0B,QAAQ;EAIlC,eAAe,EACb,cACG,MAA8C,kBAC/C,WACH;EACD,yBAAyB;AACvB,OAAI,YAAY,OAAW,OAAM;AACjC,UAAO;;EAEV,CAAC"}
@@ -1,9 +1,27 @@
1
1
  import "reflect-metadata";
2
+ import { isThreadAccessDeniedError } from "../../runner/agent-runner.mjs";
3
+ import { threadAccessDeniedResponse } from "../shared/thread-access.mjs";
2
4
  import { getRuntimeErrorReporter } from "../../core/runtime-error-reporter.mjs";
3
5
  import { createSseEventResponse } from "../shared/sse-response.mjs";
4
6
 
5
7
  //#region src/v2/runtime/handlers/sse/run.ts
6
- function handleSseRun({ runtime, request, agent, input, agentId, debug, logger, startTime }) {
8
+ function handleSseRun({ runtime, request, agent, input, agentId, debug, logger, startTime, ownerId }) {
9
+ let started;
10
+ let startError;
11
+ try {
12
+ started = runtime.runner.run({
13
+ threadId: input.threadId,
14
+ agent,
15
+ input,
16
+ ...ownerId === void 0 ? {} : { ownerId }
17
+ });
18
+ } catch (error) {
19
+ if (isThreadAccessDeniedError(error)) {
20
+ console.warn("[CopilotKit] Run refused: the thread belongs to another identity.");
21
+ return threadAccessDeniedResponse();
22
+ }
23
+ startError = error;
24
+ }
7
25
  return createSseEventResponse({
8
26
  request,
9
27
  debugEventBus: runtime.debugEventBus,
@@ -15,11 +33,10 @@ function handleSseRun({ runtime, request, agent, input, agentId, debug, logger,
15
33
  telemetry: runtime.telemetry,
16
34
  keepAliveIntervalSeconds: runtime.sseKeepAliveIntervalSeconds,
17
35
  executionSeed: { llmHostClass: agent.modelHostClass ?? "unknown" },
18
- observableFactory: () => runtime.runner.run({
19
- threadId: input.threadId,
20
- agent,
21
- input
22
- })
36
+ observableFactory: () => {
37
+ if (started === void 0) throw startError;
38
+ return started;
39
+ }
23
40
  });
24
41
  }
25
42
 
@@ -1 +1 @@
1
- {"version":3,"file":"run.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/sse/run.ts"],"sourcesContent":["import type { AbstractAgent, RunAgentInput } from \"@ag-ui/client\";\nimport type { ResolvedDebugConfig, ModelHostClass } from \"@copilotkit/shared\";\nimport type { CopilotRuntimeLogger } from \"../../../../v1-deprecated/lib/logger\";\nimport type { CopilotRuntimeLike } from \"../../core/runtime\";\nimport { getRuntimeErrorReporter } from \"../../core/runtime-error-reporter\";\nimport { createSseEventResponse } from \"../shared/sse-response\";\n\ninterface HandleSseRunParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n agent: AbstractAgent;\n input: RunAgentInput;\n agentId: string;\n debug?: ResolvedDebugConfig;\n /** Pre-created logger instance to avoid creating a new pino logger per request. */\n logger?: CopilotRuntimeLogger;\n startTime?: number;\n}\n\nexport function handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug,\n logger,\n startTime,\n}: HandleSseRunParams): Response {\n return createSseEventResponse({\n request,\n debugEventBus: runtime.debugEventBus,\n agentId,\n debug,\n logger,\n runtimeErrorReporter: getRuntimeErrorReporter(runtime),\n startTime,\n telemetry: runtime.telemetry,\n keepAliveIntervalSeconds: runtime.sseKeepAliveIntervalSeconds,\n // Read structurally rather than via `instanceof BuiltInAgent`, which would\n // pull the agent module into this handler. Any agent can opt in by\n // exposing the same property.\n executionSeed: {\n llmHostClass:\n (agent as { modelHostClass?: ModelHostClass }).modelHostClass ??\n \"unknown\",\n },\n observableFactory: () =>\n runtime.runner.run({\n threadId: input.threadId,\n agent,\n input,\n }),\n });\n}\n"],"mappings":";;;;;AAmBA,SAAgB,aAAa,EAC3B,SACA,SACA,OACA,OACA,SACA,OACA,QACA,aAC+B;AAC/B,QAAO,uBAAuB;EAC5B;EACA,eAAe,QAAQ;EACvB;EACA;EACA;EACA,sBAAsB,wBAAwB,QAAQ;EACtD;EACA,WAAW,QAAQ;EACnB,0BAA0B,QAAQ;EAIlC,eAAe,EACb,cACG,MAA8C,kBAC/C,WACH;EACD,yBACE,QAAQ,OAAO,IAAI;GACjB,UAAU,MAAM;GAChB;GACA;GACD,CAAC;EACL,CAAC"}
1
+ {"version":3,"file":"run.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/sse/run.ts"],"sourcesContent":["import type { AbstractAgent, BaseEvent, RunAgentInput } from \"@ag-ui/client\";\nimport type { Observable } from \"rxjs\";\nimport { isThreadAccessDeniedError } from \"../../runner/agent-runner\";\nimport { threadAccessDeniedResponse } from \"../shared/thread-access\";\nimport type { ResolvedDebugConfig, ModelHostClass } from \"@copilotkit/shared\";\nimport type { CopilotRuntimeLogger } from \"../../../../v1-deprecated/lib/logger\";\nimport type { CopilotRuntimeLike } from \"../../core/runtime\";\nimport { getRuntimeErrorReporter } from \"../../core/runtime-error-reporter\";\nimport { createSseEventResponse } from \"../shared/sse-response\";\n\ninterface HandleSseRunParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n agent: AbstractAgent;\n input: RunAgentInput;\n agentId: string;\n debug?: ResolvedDebugConfig;\n /** Pre-created logger instance to avoid creating a new pino logger per request. */\n logger?: CopilotRuntimeLogger;\n startTime?: number;\n /** Identity the run acts as; the runner records it as the thread owner. */\n ownerId?: string;\n}\n\nexport function handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug,\n logger,\n startTime,\n ownerId,\n}: HandleSseRunParams): Response {\n // Start the run before the stream opens. When another identity claimed the\n // thread after the handler's owner check, the runner refuses at once, and\n // that refusal becomes the same HTTP error as the check's, not a streamed\n // agent failure. Any other start error still reaches the client as a\n // RUN_ERROR on the stream, as before.\n let started: Observable<BaseEvent> | undefined;\n let startError: unknown;\n try {\n started = runtime.runner.run({\n threadId: input.threadId,\n agent,\n input,\n ...(ownerId === undefined ? {} : { ownerId }),\n });\n } catch (error) {\n if (isThreadAccessDeniedError(error)) {\n console.warn(\n \"[CopilotKit] Run refused: the thread belongs to another identity.\",\n );\n return threadAccessDeniedResponse();\n }\n startError = error;\n }\n\n return createSseEventResponse({\n request,\n debugEventBus: runtime.debugEventBus,\n agentId,\n debug,\n logger,\n runtimeErrorReporter: getRuntimeErrorReporter(runtime),\n startTime,\n telemetry: runtime.telemetry,\n keepAliveIntervalSeconds: runtime.sseKeepAliveIntervalSeconds,\n // Read structurally rather than via `instanceof BuiltInAgent`, which would\n // pull the agent module into this handler. Any agent can opt in by\n // exposing the same property.\n executionSeed: {\n llmHostClass:\n (agent as { modelHostClass?: ModelHostClass }).modelHostClass ??\n \"unknown\",\n },\n observableFactory: () => {\n if (started === undefined) throw startError;\n return started;\n },\n });\n}\n"],"mappings":";;;;;;;AAwBA,SAAgB,aAAa,EAC3B,SACA,SACA,OACA,OACA,SACA,OACA,QACA,WACA,WAC+B;CAM/B,IAAI;CACJ,IAAI;AACJ,KAAI;AACF,YAAU,QAAQ,OAAO,IAAI;GAC3B,UAAU,MAAM;GAChB;GACA;GACA,GAAI,YAAY,SAAY,EAAE,GAAG,EAAE,SAAS;GAC7C,CAAC;UACK,OAAO;AACd,MAAI,0BAA0B,MAAM,EAAE;AACpC,WAAQ,KACN,oEACD;AACD,UAAO,4BAA4B;;AAErC,eAAa;;AAGf,QAAO,uBAAuB;EAC5B;EACA,eAAe,QAAQ;EACvB;EACA;EACA;EACA,sBAAsB,wBAAwB,QAAQ;EACtD;EACA,WAAW,QAAQ;EACnB,0BAA0B,QAAQ;EAIlC,eAAe,EACb,cACG,MAA8C,kBAC/C,WACH;EACD,yBAAyB;AACvB,OAAI,YAAY,OAAW,OAAM;AACjC,UAAO;;EAEV,CAAC"}
@@ -1,13 +1,14 @@
1
1
 
2
2
  import { experimental_d_exports } from "./intelligence-platform/experimental.cjs";
3
+ 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 "./runner/agent-runner.cjs";
4
+ import { ThreadAccessMode, ThreadsConfig } from "./handlers/shared/thread-access.cjs";
3
5
  import { TranscribeFileOptions, TranscriptionService } from "./transcription-service/transcription-service.cjs";
4
- import { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, LocalThreadEndpointRecord, LocalThreadEndpointRunner, ThreadAlreadyRunningError, supportsLocalThreadEndpoints } from "./runner/agent-runner.cjs";
5
6
  import { GetLearnedSkillsSnapshotRequest, GetLearnedSkillsSnapshotsRequest, LearnedSkillsBatchResult, LearnedSkillsError, LearnedSkillsErrorCode, LearnedSkillsSnapshotResult } from "./intelligence-platform/learned-skills.cjs";
6
7
  import "./intelligence-platform/index.cjs";
7
8
  import { AgentFactoryContext, AgentsConfig, AgentsFactory, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeConstructor, CopilotRuntimeLike, CopilotRuntimeMemoryConfig, CopilotRuntimeOptions, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, MemoryAccess, MemoryConsumer, MemoryGrant, OpenGenerativeUIConfig, OpenGenerativeUIOptions, RuntimeWithDeclaredChannels, VERSION, isA2UIEnabled, isIntelligenceRuntime, resolveAgents } from "./core/runtime.cjs";
8
9
  import { CopilotRuntimeLearningConfig, CopilotRuntimeLearningContext, CopilotRuntimeUser, GetLearningContainerId, GetTrajectoryLearningContainerIds, LearningContainerSelectorInput, TrajectoryLearningContainerSelectorInput } from "./core/learning.cjs";
9
10
  import { CopilotKitIntelligence, CopilotKitIntelligenceConfig, CreateThreadRequest, ListThreadsResponse, PlatformRequestError, SubscribeToThreadsRequest, SubscribeToThreadsResponse, ThreadSummary, UpdateThreadRequest } from "./intelligence-platform/client.cjs";
10
- import { InMemoryAgentRunner, InMemoryAgentRunnerOptions, InMemoryLimits, InMemoryThread, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵestimateBytes, ɵnormalizeLimits } from "./runner/in-memory.cjs";
11
+ import { InMemoryAgentRunner, InMemoryAgentRunnerOptions, InMemoryLimits, InMemoryThread, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵOWNER_RETENTION_DEFAULTS, ɵOwnerRetention, ɵestimateBytes, ɵnormalizeLimits } from "./runner/in-memory.cjs";
11
12
  import { IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, RunnerStartupBoundary } from "./runner/intelligence.cjs";
12
13
  import { FinalizeRunOptions, RunEventFinalizer, createRunEventFinalizer, finalizeRunEvents } from "./runner/index.cjs";
13
14
  import { ChannelStatus, ChannelsControl } from "./core/channel-manager.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/v2/runtime/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgEY,wBAAA,IAA4B,MAAA;EACtC,OAAA,EAAS,OAAA;AAAA,MACL,OAAA,CAAQ,QAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/v2/runtime/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgEY,wBAAA,IAA4B,MAAA;EACtC,OAAA,EAAS,OAAA;AAAA,MACL,OAAA,CAAQ,QAAA"}
@@ -1,13 +1,14 @@
1
1
 
2
2
  import { experimental_d_exports } from "./intelligence-platform/experimental.mjs";
3
+ 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 "./runner/agent-runner.mjs";
4
+ import { ThreadAccessMode, ThreadsConfig } from "./handlers/shared/thread-access.mjs";
3
5
  import { TranscribeFileOptions, TranscriptionService } from "./transcription-service/transcription-service.mjs";
4
- import { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, LocalThreadEndpointRecord, LocalThreadEndpointRunner, ThreadAlreadyRunningError, supportsLocalThreadEndpoints } from "./runner/agent-runner.mjs";
5
6
  import { GetLearnedSkillsSnapshotRequest, GetLearnedSkillsSnapshotsRequest, LearnedSkillsBatchResult, LearnedSkillsError, LearnedSkillsErrorCode, LearnedSkillsSnapshotResult } from "./intelligence-platform/learned-skills.mjs";
6
7
  import "./intelligence-platform/index.mjs";
7
8
  import { AgentFactoryContext, AgentsConfig, AgentsFactory, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeConstructor, CopilotRuntimeLike, CopilotRuntimeMemoryConfig, CopilotRuntimeOptions, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, MemoryAccess, MemoryConsumer, MemoryGrant, OpenGenerativeUIConfig, OpenGenerativeUIOptions, RuntimeWithDeclaredChannels, VERSION, isA2UIEnabled, isIntelligenceRuntime, resolveAgents } from "./core/runtime.mjs";
8
9
  import { CopilotRuntimeLearningConfig, CopilotRuntimeLearningContext, CopilotRuntimeUser, GetLearningContainerId, GetTrajectoryLearningContainerIds, LearningContainerSelectorInput, TrajectoryLearningContainerSelectorInput } from "./core/learning.mjs";
9
10
  import { CopilotKitIntelligence, CopilotKitIntelligenceConfig, CreateThreadRequest, ListThreadsResponse, PlatformRequestError, SubscribeToThreadsRequest, SubscribeToThreadsResponse, ThreadSummary, UpdateThreadRequest } from "./intelligence-platform/client.mjs";
10
- import { InMemoryAgentRunner, InMemoryAgentRunnerOptions, InMemoryLimits, InMemoryThread, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵestimateBytes, ɵnormalizeLimits } from "./runner/in-memory.mjs";
11
+ import { InMemoryAgentRunner, InMemoryAgentRunnerOptions, InMemoryLimits, InMemoryThread, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵOWNER_RETENTION_DEFAULTS, ɵOwnerRetention, ɵestimateBytes, ɵnormalizeLimits } from "./runner/in-memory.mjs";
11
12
  import { IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, RunnerStartupBoundary } from "./runner/intelligence.mjs";
12
13
  import { FinalizeRunOptions, RunEventFinalizer, createRunEventFinalizer, finalizeRunEvents } from "./runner/index.mjs";
13
14
  import { ChannelStatus, ChannelsControl } from "./core/channel-manager.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/v2/runtime/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgEY,wBAAA,IAA4B,MAAA;EACtC,OAAA,EAAS,OAAA;AAAA,MACL,OAAA,CAAQ,QAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/v2/runtime/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgEY,wBAAA,IAA4B,MAAA;EACtC,OAAA,EAAS,OAAA;AAAA,MACL,OAAA,CAAQ,QAAA"}
@@ -1,9 +1,9 @@
1
1
  require("reflect-metadata");
2
2
  const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
3
- const require_learning = require('../core/learning.cjs');
4
- const require_learned_skills = require('./learned-skills.cjs');
5
3
  const require_learning_management = require('./learning-management.cjs');
4
+ const require_learning = require('../core/learning.cjs');
6
5
  const require_trajectories = require('./trajectories.cjs');
6
+ const require_learned_skills = require('./learned-skills.cjs');
7
7
  let _copilotkit_shared = require("@copilotkit/shared");
8
8
  let zod = require("zod");
9
9
  let crypto = require("crypto");
@@ -226,6 +226,14 @@ function cloneRuntimeEntitlementError(error) {
226
226
  * });
227
227
  * ```
228
228
  */
229
+ /**
230
+ * The thread events and state reads are scoped to one end user. A caller
231
+ * that omits `userId` (a JS caller, or one built against the earlier
232
+ * signature) would otherwise send the literal string "undefined" as the user.
233
+ */
234
+ function requireThreadReadUserId(method, userId) {
235
+ if (typeof userId !== "string" || userId === "") throw new TypeError(`${method} requires a non-empty userId: the id identifyUser returned`);
236
+ }
229
237
  var CopilotKitIntelligence = class {
230
238
  #apiUrl;
231
239
  #runnerWsUrl;
@@ -1119,7 +1127,9 @@ var CopilotKitIntelligence = class {
1119
1127
  * @throws {@link PlatformRequestError} on non-2xx responses.
1120
1128
  */
1121
1129
  async getThreadEvents(params) {
1122
- return this.#request("GET", `/api/_inspect/threads/${encodeURIComponent(params.threadId)}/events`);
1130
+ requireThreadReadUserId("getThreadEvents", params.userId);
1131
+ const qs = new URLSearchParams({ userId: params.userId }).toString();
1132
+ return this.#request("GET", `/api/_inspect/threads/${encodeURIComponent(params.threadId)}/events?${qs}`);
1123
1133
  }
1124
1134
  /**
1125
1135
  * Fetch the current agent state for a thread.
@@ -1135,7 +1145,9 @@ var CopilotKitIntelligence = class {
1135
1145
  * @throws {@link PlatformRequestError} on non-2xx responses.
1136
1146
  */
1137
1147
  async getThreadState(params) {
1138
- return this.#request("GET", `/api/_inspect/threads/${encodeURIComponent(params.threadId)}/state`);
1148
+ requireThreadReadUserId("getThreadState", params.userId);
1149
+ const qs = new URLSearchParams({ userId: params.userId }).toString();
1150
+ return this.#request("GET", `/api/_inspect/threads/${encodeURIComponent(params.threadId)}/state?${qs}`);
1139
1151
  }
1140
1152
  /**
1141
1153
  * Mark a thread as archived.