@copilotkit/runtime 1.81.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 (156) hide show
  1. package/dist/agent/index.cjs +18 -10
  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 +18 -10
  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 +4 -1
  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 +4 -1
  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 +2 -1
  40. package/dist/v2/runtime/core/channel-manager.cjs.map +1 -1
  41. package/dist/v2/runtime/core/channel-manager.mjs +2 -1
  42. package/dist/v2/runtime/core/channel-manager.mjs.map +1 -1
  43. package/dist/v2/runtime/core/fetch-handler.cjs +3 -3
  44. package/dist/v2/runtime/core/fetch-handler.cjs.map +1 -1
  45. package/dist/v2/runtime/core/fetch-handler.mjs +3 -3
  46. package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -1
  47. package/dist/v2/runtime/core/package-info.cjs +1 -1
  48. package/dist/v2/runtime/core/package-info.mjs +1 -1
  49. package/dist/v2/runtime/core/runtime.cjs +12 -2
  50. package/dist/v2/runtime/core/runtime.cjs.map +1 -1
  51. package/dist/v2/runtime/core/runtime.d.cts +40 -1
  52. package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
  53. package/dist/v2/runtime/core/runtime.d.mts +40 -1
  54. package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
  55. package/dist/v2/runtime/core/runtime.mjs +12 -2
  56. package/dist/v2/runtime/core/runtime.mjs.map +1 -1
  57. package/dist/v2/runtime/handlers/get-runtime-info.cjs +6 -6
  58. package/dist/v2/runtime/handlers/get-runtime-info.cjs.map +1 -1
  59. package/dist/v2/runtime/handlers/get-runtime-info.mjs +6 -6
  60. package/dist/v2/runtime/handlers/get-runtime-info.mjs.map +1 -1
  61. package/dist/v2/runtime/handlers/handle-connect.cjs +9 -1
  62. package/dist/v2/runtime/handlers/handle-connect.cjs.map +1 -1
  63. package/dist/v2/runtime/handlers/handle-connect.mjs +9 -1
  64. package/dist/v2/runtime/handlers/handle-connect.mjs.map +1 -1
  65. package/dist/v2/runtime/handlers/handle-inspector-learning.cjs +1 -1
  66. package/dist/v2/runtime/handlers/handle-inspector-learning.mjs +1 -1
  67. package/dist/v2/runtime/handlers/handle-run.cjs +16 -2
  68. package/dist/v2/runtime/handlers/handle-run.cjs.map +1 -1
  69. package/dist/v2/runtime/handlers/handle-run.mjs +16 -2
  70. package/dist/v2/runtime/handlers/handle-run.mjs.map +1 -1
  71. package/dist/v2/runtime/handlers/handle-stop.cjs +14 -3
  72. package/dist/v2/runtime/handlers/handle-stop.cjs.map +1 -1
  73. package/dist/v2/runtime/handlers/handle-stop.mjs +14 -3
  74. package/dist/v2/runtime/handlers/handle-stop.mjs.map +1 -1
  75. package/dist/v2/runtime/handlers/handle-trajectory-connect.cjs +1 -1
  76. package/dist/v2/runtime/handlers/handle-trajectory-connect.mjs +1 -1
  77. package/dist/v2/runtime/handlers/intelligence/annotate.cjs +2 -2
  78. package/dist/v2/runtime/handlers/intelligence/annotate.mjs +2 -2
  79. package/dist/v2/runtime/handlers/intelligence/memories.cjs +1 -1
  80. package/dist/v2/runtime/handlers/intelligence/memories.mjs +1 -1
  81. package/dist/v2/runtime/handlers/intelligence/run.cjs +7 -4
  82. package/dist/v2/runtime/handlers/intelligence/run.cjs.map +1 -1
  83. package/dist/v2/runtime/handlers/intelligence/run.mjs +7 -4
  84. package/dist/v2/runtime/handlers/intelligence/run.mjs.map +1 -1
  85. package/dist/v2/runtime/handlers/intelligence/threads.cjs +137 -31
  86. package/dist/v2/runtime/handlers/intelligence/threads.cjs.map +1 -1
  87. package/dist/v2/runtime/handlers/intelligence/threads.mjs +138 -32
  88. package/dist/v2/runtime/handlers/intelligence/threads.mjs.map +1 -1
  89. package/dist/v2/runtime/handlers/shared/agent-utils.cjs +3 -3
  90. package/dist/v2/runtime/handlers/shared/agent-utils.mjs +3 -3
  91. package/dist/v2/runtime/handlers/shared/mcp-apps-servers.cjs +2 -1
  92. package/dist/v2/runtime/handlers/shared/mcp-apps-servers.cjs.map +1 -1
  93. package/dist/v2/runtime/handlers/shared/mcp-apps-servers.mjs +3 -1
  94. package/dist/v2/runtime/handlers/shared/mcp-apps-servers.mjs.map +1 -1
  95. package/dist/v2/runtime/handlers/shared/platform-error.cjs +1 -1
  96. package/dist/v2/runtime/handlers/shared/platform-error.mjs +1 -1
  97. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs +22 -3
  98. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -1
  99. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs +22 -4
  100. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -1
  101. package/dist/v2/runtime/handlers/shared/sse-response.cjs +20 -3
  102. package/dist/v2/runtime/handlers/shared/sse-response.cjs.map +1 -1
  103. package/dist/v2/runtime/handlers/shared/sse-response.mjs +20 -3
  104. package/dist/v2/runtime/handlers/shared/sse-response.mjs.map +1 -1
  105. package/dist/v2/runtime/handlers/shared/thread-access.cjs +138 -0
  106. package/dist/v2/runtime/handlers/shared/thread-access.cjs.map +1 -0
  107. package/dist/v2/runtime/handlers/shared/thread-access.d.cts +29 -0
  108. package/dist/v2/runtime/handlers/shared/thread-access.d.cts.map +1 -0
  109. package/dist/v2/runtime/handlers/shared/thread-access.d.mts +29 -0
  110. package/dist/v2/runtime/handlers/shared/thread-access.d.mts.map +1 -0
  111. package/dist/v2/runtime/handlers/shared/thread-access.mjs +133 -0
  112. package/dist/v2/runtime/handlers/shared/thread-access.mjs.map +1 -0
  113. package/dist/v2/runtime/handlers/sse/connect.cjs +2 -1
  114. package/dist/v2/runtime/handlers/sse/connect.cjs.map +1 -1
  115. package/dist/v2/runtime/handlers/sse/connect.mjs +2 -1
  116. package/dist/v2/runtime/handlers/sse/connect.mjs.map +1 -1
  117. package/dist/v2/runtime/handlers/sse/run.cjs +23 -6
  118. package/dist/v2/runtime/handlers/sse/run.cjs.map +1 -1
  119. package/dist/v2/runtime/handlers/sse/run.mjs +23 -6
  120. package/dist/v2/runtime/handlers/sse/run.mjs.map +1 -1
  121. package/dist/v2/runtime/index.d.cts +3 -2
  122. package/dist/v2/runtime/index.d.cts.map +1 -1
  123. package/dist/v2/runtime/index.d.mts +3 -2
  124. package/dist/v2/runtime/index.d.mts.map +1 -1
  125. package/dist/v2/runtime/intelligence-platform/client.cjs +17 -4
  126. package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
  127. package/dist/v2/runtime/intelligence-platform/client.d.cts +9 -37
  128. package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
  129. package/dist/v2/runtime/intelligence-platform/client.d.mts +9 -37
  130. package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
  131. package/dist/v2/runtime/intelligence-platform/client.mjs +17 -4
  132. package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
  133. package/dist/v2/runtime/runner/agent-runner.cjs +55 -0
  134. package/dist/v2/runtime/runner/agent-runner.cjs.map +1 -1
  135. package/dist/v2/runtime/runner/agent-runner.d.cts +90 -6
  136. package/dist/v2/runtime/runner/agent-runner.d.cts.map +1 -1
  137. package/dist/v2/runtime/runner/agent-runner.d.mts +90 -6
  138. package/dist/v2/runtime/runner/agent-runner.d.mts.map +1 -1
  139. package/dist/v2/runtime/runner/agent-runner.mjs +50 -1
  140. package/dist/v2/runtime/runner/agent-runner.mjs.map +1 -1
  141. package/dist/v2/runtime/runner/in-memory.cjs +205 -25
  142. package/dist/v2/runtime/runner/in-memory.cjs.map +1 -1
  143. package/dist/v2/runtime/runner/in-memory.d.cts +112 -15
  144. package/dist/v2/runtime/runner/in-memory.d.cts.map +1 -1
  145. package/dist/v2/runtime/runner/in-memory.d.mts +112 -15
  146. package/dist/v2/runtime/runner/in-memory.d.mts.map +1 -1
  147. package/dist/v2/runtime/runner/in-memory.mjs +206 -27
  148. package/dist/v2/runtime/runner/in-memory.mjs.map +1 -1
  149. package/dist/v2/runtime/runner/index.d.cts +2 -2
  150. package/dist/v2/runtime/runner/index.d.mts +2 -2
  151. package/dist/v2/runtime/runner/index.mjs +2 -2
  152. package/dist/v2/runtime/telemetry/telemetry-client.cjs +1 -1
  153. package/dist/v2/runtime/telemetry/telemetry-client.cjs.map +1 -1
  154. package/dist/v2/runtime/telemetry/telemetry-client.mjs +1 -1
  155. package/dist/v2/runtime/telemetry/telemetry-client.mjs.map +1 -1
  156. package/package.json +6 -6
@@ -1,9 +1,10 @@
1
1
  import "reflect-metadata";
2
2
  import { supportsLocalThreadEndpoints } from "../../runner/agent-runner.mjs";
3
- import { isIntelligenceRuntime } from "../../core/runtime.mjs";
4
3
  import { errorResponse, isHandlerResponse } from "../shared/json-response.mjs";
5
- import { isValidIdentifier } from "../shared/intelligence-utils.mjs";
4
+ import { getPlatformErrorStatus, isValidIdentifier } from "../shared/intelligence-utils.mjs";
6
5
  import { resolveIntelligenceUser } from "../shared/resolve-intelligence-user.mjs";
6
+ import { resolveLocalThreadOwner } from "../shared/thread-access.mjs";
7
+ import { isIntelligenceRuntime } from "../../core/runtime.mjs";
7
8
  import { platformErrorResponse } from "../shared/platform-error.mjs";
8
9
  import { logger } from "@copilotkit/shared";
9
10
 
@@ -36,6 +37,42 @@ async function resolveThreadMutationContext(runtime, request) {
36
37
  agentId
37
38
  };
38
39
  }
40
+ /**
41
+ * The platform's `_inspect` events and state endpoints are scoped by the
42
+ * project key only. Before calling them, confirm the thread is visible to the
43
+ * resolved user through the user-scoped thread lookup, and return its
44
+ * canonical id for the read, so the check and the read name the same thread.
45
+ *
46
+ * Returns the error Response instead when the lookup refuses: the platform's
47
+ * 4xx for a thread the user cannot see (an expected denial, logged as a
48
+ * warning), 502 for a malformed lookup result, and the mapped platform error
49
+ * for anything else (logged as an error).
50
+ */
51
+ async function requireUserThread(runtime, threadId, userId, failure) {
52
+ let thread;
53
+ try {
54
+ thread = await runtime.intelligence.getThread({
55
+ threadId,
56
+ userId
57
+ });
58
+ } catch (error) {
59
+ const status = getPlatformErrorStatus(error);
60
+ if (status !== void 0 && status >= 400 && status < 500 && status !== 401) logger.warn({
61
+ threadId,
62
+ status
63
+ }, "Thread not visible to the user");
64
+ else logger.error({
65
+ err: error,
66
+ threadId
67
+ }, "Error resolving thread");
68
+ return platformErrorResponse(error, failure);
69
+ }
70
+ if (!thread || typeof thread.id !== "string" || !thread.id.trim()) {
71
+ logger.error({ threadId }, "Invalid thread response from getThread");
72
+ return errorResponse("Invalid thread response", 502);
73
+ }
74
+ return { threadId: thread.id };
75
+ }
39
76
  async function handleListThreads({ runtime, request }) {
40
77
  if (isIntelligenceRuntime(runtime)) try {
41
78
  const url = new URL(request.url);
@@ -62,27 +99,54 @@ async function handleListThreads({ runtime, request }) {
62
99
  return errorResponse("Failed to list threads", 500);
63
100
  }
64
101
  if (supportsLocalThreadEndpoints(runtime.runner)) {
65
- const agentId = new URL(request.url).searchParams.get("agentId");
66
- let threads = runtime.runner.listThreads();
67
- if (agentId) threads = threads.filter((t) => t.agentId === agentId);
68
- return Response.json({
69
- threads,
70
- nextCursor: null
102
+ const ownerId = await resolveLocalThreadOwner({
103
+ runtime,
104
+ request,
105
+ operation: "list"
71
106
  });
107
+ if (isHandlerResponse(ownerId)) return ownerId;
108
+ try {
109
+ const agentId = new URL(request.url).searchParams.get("agentId");
110
+ let threads = runtime.runner.listThreads({ ownerId });
111
+ if (agentId) threads = threads.filter((t) => t.agentId === agentId);
112
+ return Response.json({
113
+ threads,
114
+ nextCursor: null
115
+ });
116
+ } catch (error) {
117
+ logger.error({ err: error }, "Error listing threads");
118
+ return errorResponse("Failed to list threads", 500);
119
+ }
72
120
  }
73
121
  return errorResponse("Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.", 422);
74
122
  }
75
123
  /**
76
- * Clears all in-memory thread history for the local-dev InMemory fallback.
124
+ * Clears the caller's in-memory thread history for the local-dev fallback.
77
125
  *
78
126
  * The local-dev fallback exposes this so consumers (e.g. the demo's Clear
79
127
  * button) can wipe in-memory thread history without restarting the runtime.
128
+ * Only the caller's own threads are cleared, and a thread whose run is
129
+ * still active is kept. Without `identifyUser`, the access policy refuses it
130
+ * unless `threads: { access: "open" }` is set.
80
131
  * Intentionally a no-op when CopilotKit Intelligence is configured: real
81
132
  * thread history lives in the database and must not be wiped by a
82
133
  * client-side page load.
83
134
  */
84
- function handleClearThreads({ runtime }) {
85
- if (supportsLocalThreadEndpoints(runtime.runner)) runtime.runner.clearThreads();
135
+ async function handleClearThreads({ runtime, request }) {
136
+ if (supportsLocalThreadEndpoints(runtime.runner)) {
137
+ const ownerId = await resolveLocalThreadOwner({
138
+ runtime,
139
+ request,
140
+ operation: "clear"
141
+ });
142
+ if (isHandlerResponse(ownerId)) return ownerId;
143
+ try {
144
+ runtime.runner.clearThreads({ ownerId });
145
+ } catch (error) {
146
+ logger.error({ err: error }, "Error clearing threads");
147
+ return errorResponse("Failed to clear threads", 500);
148
+ }
149
+ }
86
150
  return new Response(null, { status: 204 });
87
151
  }
88
152
  async function handleUpdateThread({ runtime, request, threadId }) {
@@ -190,7 +254,23 @@ async function handleGetThreadMessages({ runtime, request, threadId }) {
190
254
  return platformErrorResponse(error, "Failed to fetch thread messages");
191
255
  }
192
256
  if (supportsLocalThreadEndpoints(runtime.runner)) {
193
- const mapped = runtime.runner.getThreadMessages(threadId).map((msg) => {
257
+ const ownerId = await resolveLocalThreadOwner({
258
+ runtime,
259
+ request,
260
+ operation: "read"
261
+ });
262
+ if (isHandlerResponse(ownerId)) return ownerId;
263
+ let messages;
264
+ try {
265
+ messages = runtime.runner.getThreadMessages(threadId, { ownerId });
266
+ } catch (error) {
267
+ logger.error({
268
+ err: error,
269
+ threadId
270
+ }, "Error fetching thread messages");
271
+ return errorResponse("Failed to fetch thread messages", 500);
272
+ }
273
+ const mapped = messages.map((msg) => {
194
274
  switch (msg.role) {
195
275
  case "assistant": {
196
276
  const toolCalls = msg.toolCalls ?? [];
@@ -229,7 +309,12 @@ async function handleGetThreadEvents({ runtime, request, threadId }) {
229
309
  request
230
310
  });
231
311
  if (isHandlerResponse(user)) return user;
232
- const data = await runtime.intelligence.getThreadEvents({ threadId });
312
+ const thread = await requireUserThread(runtime, threadId, user.id, "Failed to fetch thread events");
313
+ if (isHandlerResponse(thread)) return thread;
314
+ const data = await runtime.intelligence.getThreadEvents({
315
+ threadId: thread.threadId,
316
+ userId: user.id
317
+ });
233
318
  return Response.json({ events: data.events });
234
319
  } catch (error) {
235
320
  logger.error({
@@ -238,15 +323,23 @@ async function handleGetThreadEvents({ runtime, request, threadId }) {
238
323
  }, "Error fetching thread events");
239
324
  return platformErrorResponse(error, "Failed to fetch thread events");
240
325
  }
241
- if (supportsLocalThreadEndpoints(runtime.runner)) try {
242
- const events = runtime.runner.getThreadEvents(threadId);
243
- return Response.json({ events });
244
- } catch (error) {
245
- logger.error({
246
- err: error,
247
- threadId
248
- }, "Error fetching thread events");
249
- return errorResponse("Failed to fetch thread events", 500);
326
+ if (supportsLocalThreadEndpoints(runtime.runner)) {
327
+ const ownerId = await resolveLocalThreadOwner({
328
+ runtime,
329
+ request,
330
+ operation: "read"
331
+ });
332
+ if (isHandlerResponse(ownerId)) return ownerId;
333
+ try {
334
+ const events = runtime.runner.getThreadEvents(threadId, { ownerId });
335
+ return Response.json({ events });
336
+ } catch (error) {
337
+ logger.error({
338
+ err: error,
339
+ threadId
340
+ }, "Error fetching thread events");
341
+ return errorResponse("Failed to fetch thread events", 500);
342
+ }
250
343
  }
251
344
  return errorResponse("Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.", 422);
252
345
  }
@@ -257,7 +350,12 @@ async function handleGetThreadState({ runtime, request, threadId }) {
257
350
  request
258
351
  });
259
352
  if (isHandlerResponse(user)) return user;
260
- const data = await runtime.intelligence.getThreadState({ threadId });
353
+ const thread = await requireUserThread(runtime, threadId, user.id, "Failed to fetch thread state");
354
+ if (isHandlerResponse(thread)) return thread;
355
+ const data = await runtime.intelligence.getThreadState({
356
+ threadId: thread.threadId,
357
+ userId: user.id
358
+ });
261
359
  const state = data.kind === "snapshot" ? data.state : null;
262
360
  return Response.json({ state });
263
361
  } catch (error) {
@@ -267,15 +365,23 @@ async function handleGetThreadState({ runtime, request, threadId }) {
267
365
  }, "Error fetching thread state");
268
366
  return platformErrorResponse(error, "Failed to fetch thread state");
269
367
  }
270
- if (supportsLocalThreadEndpoints(runtime.runner)) try {
271
- const state = runtime.runner.getThreadState(threadId);
272
- return Response.json({ state });
273
- } catch (error) {
274
- logger.error({
275
- err: error,
276
- threadId
277
- }, "Error fetching thread state");
278
- return errorResponse("Failed to fetch thread state", 500);
368
+ if (supportsLocalThreadEndpoints(runtime.runner)) {
369
+ const ownerId = await resolveLocalThreadOwner({
370
+ runtime,
371
+ request,
372
+ operation: "read"
373
+ });
374
+ if (isHandlerResponse(ownerId)) return ownerId;
375
+ try {
376
+ const state = runtime.runner.getThreadState(threadId, { ownerId });
377
+ return Response.json({ state });
378
+ } catch (error) {
379
+ logger.error({
380
+ err: error,
381
+ threadId
382
+ }, "Error fetching thread state");
383
+ return errorResponse("Failed to fetch thread state", 500);
384
+ }
279
385
  }
280
386
  return errorResponse("Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.", 422);
281
387
  }
@@ -1 +1 @@
1
- {"version":3,"file":"threads.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/intelligence/threads.ts"],"sourcesContent":["import type {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeLike,\n} from \"../../core/runtime\";\nimport { isIntelligenceRuntime } from \"../../core/runtime\";\nimport { logger } from \"@copilotkit/shared\";\nimport { errorResponse, isHandlerResponse } from \"../shared/json-response\";\nimport { isValidIdentifier } from \"../shared/intelligence-utils\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { platformErrorResponse } from \"../shared/platform-error\";\nimport { supportsLocalThreadEndpoints } from \"../../runner/agent-runner\";\n\ninterface ThreadsHandlerParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\ninterface ThreadMutationParams extends ThreadsHandlerParams {\n threadId: string;\n}\n\ninterface ThreadMutationContext {\n userId: string;\n agentId: string;\n body: Record<string, unknown>;\n}\n\nasync function parseJsonBody(\n request: Request,\n): Promise<Record<string, unknown> | Response> {\n try {\n return (await request.json()) as Record<string, unknown>;\n } catch (error) {\n logger.error({ err: error }, \"Malformed JSON in request body\");\n return errorResponse(\"Invalid request body\", 400);\n }\n}\n\nfunction requireIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): CopilotIntelligenceRuntimeLike | Response {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n }\n\n return runtime;\n}\n\nasync function resolveThreadMutationContext(\n runtime: CopilotIntelligenceRuntimeLike,\n request: Request,\n): Promise<ThreadMutationContext | Response> {\n const body = await parseJsonBody(request);\n if (isHandlerResponse(body)) return body;\n\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n\n const agentId = body.agentId;\n if (!isValidIdentifier(agentId)) {\n return errorResponse(\"Valid agentId is required\", 400);\n }\n\n return {\n body,\n userId: user.id,\n agentId,\n };\n}\n\nexport async function handleListThreads({\n runtime,\n request,\n}: ThreadsHandlerParams): Promise<Response> {\n // CopilotKit Intelligence path\n if (isIntelligenceRuntime(runtime)) {\n try {\n const url = new URL(request.url);\n const agentId = url.searchParams.get(\"agentId\");\n const includeArchived =\n url.searchParams.get(\"includeArchived\") === \"true\";\n const limitParam = url.searchParams.get(\"limit\");\n const cursor = url.searchParams.get(\"cursor\");\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n\n if (!isValidIdentifier(agentId)) {\n return errorResponse(\"Valid agentId query param is required\", 400);\n }\n\n const data = await runtime.intelligence.listThreads({\n userId: user.id,\n agentId,\n ...(includeArchived ? { includeArchived: true } : {}),\n ...(limitParam ? { limit: Number(limitParam) } : {}),\n ...(cursor ? { cursor } : {}),\n });\n\n return Response.json(data);\n } catch (error) {\n logger.error({ err: error }, \"Error listing threads\");\n return errorResponse(\"Failed to list threads\", 500);\n }\n }\n\n // Local in-memory fallback — useful for local development without Intelligence\n if (supportsLocalThreadEndpoints(runtime.runner)) {\n const url = new URL(request.url);\n const agentId = url.searchParams.get(\"agentId\");\n let threads = runtime.runner.listThreads();\n if (agentId) {\n threads = threads.filter((t) => t.agentId === agentId);\n }\n return Response.json({ threads, nextCursor: null });\n }\n\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n}\n\n/**\n * Clears all in-memory thread history for the local-dev InMemory fallback.\n *\n * The local-dev fallback exposes this so consumers (e.g. the demo's Clear\n * button) can wipe in-memory thread history without restarting the runtime.\n * Intentionally a no-op when CopilotKit Intelligence is configured: real\n * thread history lives in the database and must not be wiped by a\n * client-side page load.\n */\nexport function handleClearThreads({\n runtime,\n}: ThreadsHandlerParams): Response {\n if (supportsLocalThreadEndpoints(runtime.runner)) {\n runtime.runner.clearThreads();\n }\n return new Response(null, { status: 204 });\n}\n\nexport async function handleUpdateThread({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const mutation = await resolveThreadMutationContext(\n intelligenceRuntime,\n request,\n );\n if (isHandlerResponse(mutation)) return mutation;\n\n // The public SDK accepts trusted updates; browser fields must be allowlisted.\n const updates: Record<string, unknown> = {};\n for (const key of [\"name\", \"archived\"]) {\n if (Object.prototype.hasOwnProperty.call(mutation.body, key)) {\n updates[key] = mutation.body[key];\n }\n }\n\n const thread = await intelligenceRuntime.intelligence.updateThread({\n threadId,\n userId: mutation.userId,\n agentId: mutation.agentId,\n updates,\n });\n\n return Response.json(thread);\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error updating thread\");\n return errorResponse(\"Failed to update thread\", 500);\n }\n}\n\nexport async function handleSubscribeToThreads({\n runtime,\n request,\n}: ThreadsHandlerParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const user = await resolveIntelligenceUser({\n runtime: intelligenceRuntime,\n request,\n });\n if (isHandlerResponse(user)) return user;\n\n const credentials =\n await intelligenceRuntime.intelligence.ɵsubscribeToThreads({\n userId: user.id,\n });\n\n return Response.json({ joinToken: credentials.joinToken });\n } catch (error) {\n logger.error({ err: error }, \"Error subscribing to threads\");\n return errorResponse(\"Failed to subscribe to threads\", 500);\n }\n}\n\nexport async function handleArchiveThread({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const mutation = await resolveThreadMutationContext(\n intelligenceRuntime,\n request,\n );\n if (isHandlerResponse(mutation)) return mutation;\n\n await intelligenceRuntime.intelligence.archiveThread({\n threadId,\n userId: mutation.userId,\n agentId: mutation.agentId,\n });\n\n return Response.json({ threadId, archived: true });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error archiving thread\");\n return errorResponse(\"Failed to archive thread\", 500);\n }\n}\n\nexport async function handleDeleteThread({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const mutation = await resolveThreadMutationContext(\n intelligenceRuntime,\n request,\n );\n if (isHandlerResponse(mutation)) return mutation;\n\n await intelligenceRuntime.intelligence.deleteThread({\n threadId,\n userId: mutation.userId,\n agentId: mutation.agentId,\n });\n\n return Response.json({ threadId, deleted: true });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error deleting thread\");\n return errorResponse(\"Failed to delete thread\", 500);\n }\n}\n\nexport async function handleGetThreadMessages({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n // CopilotKit Intelligence path\n if (isIntelligenceRuntime(runtime)) {\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n\n const data = await runtime.intelligence.getThreadMessages({\n threadId,\n userId: user.id,\n });\n return Response.json(data);\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error fetching thread messages\");\n return platformErrorResponse(error, \"Failed to fetch thread messages\");\n }\n }\n\n // Local in-memory fallback — useful for local development without Intelligence\n if (supportsLocalThreadEndpoints(runtime.runner)) {\n const messages = runtime.runner.getThreadMessages(threadId);\n // Map ag-ui Message objects to the same shape CopilotKit Intelligence\n // returns. Switching on the discriminant `role` lets each branch read\n // the narrowed message arm directly, instead of laundering through\n // `Record<string, unknown>` and chained `as` casts.\n const mapped = messages.map((msg) => {\n switch (msg.role) {\n case \"assistant\": {\n const toolCalls = msg.toolCalls ?? [];\n return {\n id: msg.id,\n role: msg.role,\n ...(msg.content !== undefined ? { content: msg.content } : {}),\n ...(toolCalls.length > 0\n ? {\n toolCalls: toolCalls.map((tc) => ({\n id: tc.id,\n name: tc.function.name,\n args: tc.function.arguments,\n })),\n }\n : {}),\n };\n }\n case \"tool\":\n return {\n id: msg.id,\n role: msg.role,\n content: msg.content,\n toolCallId: msg.toolCallId,\n };\n default:\n return {\n id: msg.id,\n role: msg.role,\n ...(\"content\" in msg && msg.content !== undefined\n ? { content: msg.content }\n : {}),\n };\n }\n });\n return Response.json({ messages: mapped });\n }\n\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n}\n\nexport async function handleGetThreadEvents({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n // CopilotKit Intelligence path. Delegates to the platform's `_inspect`\n // endpoint (Intelligence PR #144). Auth still flows through the standard\n // identifyUser → API key path; threadId scoping happens server-side.\n if (isIntelligenceRuntime(runtime)) {\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n\n const data = await runtime.intelligence.getThreadEvents({ threadId });\n // Strip platform-internal fields (`decodeErrorRowIds`, `truncated`)\n // before returning to the inspector — those describe persistence-side\n // concerns the inspector currently has no UI for. The shape becomes\n // `{ events }`, matching the in-memory branch below.\n return Response.json({ events: data.events });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error fetching thread events\");\n return platformErrorResponse(error, \"Failed to fetch thread events\");\n }\n }\n\n // Local in-memory fallback\n if (supportsLocalThreadEndpoints(runtime.runner)) {\n try {\n const events = runtime.runner.getThreadEvents(threadId);\n return Response.json({ events });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error fetching thread events\");\n return errorResponse(\"Failed to fetch thread events\", 500);\n }\n }\n\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n}\n\nexport async function handleGetThreadState({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n // CopilotKit Intelligence path. Delegates to the platform's `_inspect`\n // state endpoint, which folds STATE_DELTA events onto the latest\n // STATE_SNAPSHOT to return the thread's current state.\n if (isIntelligenceRuntime(runtime)) {\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n\n const data = await runtime.intelligence.getThreadState({ threadId });\n // Flatten the discriminated `ThreadStateResult` to the wire shape the\n // inspector consumes (`{ state: <value> | null }`). Missing snapshot\n // and decode-error both surface as `null`; the inspector renders an\n // empty state branch for null and the platform's decode-error case is\n // already logged platform-side.\n const state = data.kind === \"snapshot\" ? data.state : null;\n return Response.json({ state });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error fetching thread state\");\n return platformErrorResponse(error, \"Failed to fetch thread state\");\n }\n }\n\n if (supportsLocalThreadEndpoints(runtime.runner)) {\n try {\n const state = runtime.runner.getThreadState(threadId);\n return Response.json({ state });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error fetching thread state\");\n return errorResponse(\"Failed to fetch thread state\", 500);\n }\n }\n\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n}\n"],"mappings":";;;;;;;;;;AA2BA,eAAe,cACb,SAC6C;AAC7C,KAAI;AACF,SAAQ,MAAM,QAAQ,MAAM;UACrB,OAAO;AACd,SAAO,MAAM,EAAE,KAAK,OAAO,EAAE,iCAAiC;AAC9D,SAAO,cAAc,wBAAwB,IAAI;;;AAIrD,SAAS,2BACP,SAC2C;AAC3C,KAAI,CAAC,sBAAsB,QAAQ,CACjC,QAAO,cACL,uJACA,IACD;AAGH,QAAO;;AAGT,eAAe,6BACb,SACA,SAC2C;CAC3C,MAAM,OAAO,MAAM,cAAc,QAAQ;AACzC,KAAI,kBAAkB,KAAK,CAAE,QAAO;CAEpC,MAAM,OAAO,MAAM,wBAAwB;EAAE;EAAS;EAAS,CAAC;AAChE,KAAI,kBAAkB,KAAK,CAAE,QAAO;CAEpC,MAAM,UAAU,KAAK;AACrB,KAAI,CAAC,kBAAkB,QAAQ,CAC7B,QAAO,cAAc,6BAA6B,IAAI;AAGxD,QAAO;EACL;EACA,QAAQ,KAAK;EACb;EACD;;AAGH,eAAsB,kBAAkB,EACtC,SACA,WAC0C;AAE1C,KAAI,sBAAsB,QAAQ,CAChC,KAAI;EACF,MAAM,MAAM,IAAI,IAAI,QAAQ,IAAI;EAChC,MAAM,UAAU,IAAI,aAAa,IAAI,UAAU;EAC/C,MAAM,kBACJ,IAAI,aAAa,IAAI,kBAAkB,KAAK;EAC9C,MAAM,aAAa,IAAI,aAAa,IAAI,QAAQ;EAChD,MAAM,SAAS,IAAI,aAAa,IAAI,SAAS;EAC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AwB;GAAE;GAAS;GAAS,CAAC;AAChE,MAAI,kBAAkB,KAAK,CAAE,QAAO;EAEpC,MAAM,OAAO,MAAM,QAAQ,aAAa,eAAe,EAAE,UAAU,CAAC;EAMpE,MAAM,QAAQ,KAAK,SAAS,aAAa,KAAK,QAAQ;AACtD,SAAO,SAAS,KAAK,EAAE,OAAO,CAAC;UACxB,OAAO;AACd,SAAO,MAAM;GAAE,KAAK;GAAO;GAAU,EAAE,8BAA8B;AACrE,SAAO,sBAAsB,OAAO,+BAA+B;;AAIvE,KAAI,6BAA6B,QAAQ,OAAO,CAC9C,KAAI;EACF,MAAM,QAAQ,QAAQ,OAAO,eAAe,SAAS;AACrD,SAAO,SAAS,KAAK,EAAE,OAAO,CAAC;UACxB,OAAO;AACd,SAAO,MAAM;GAAE,KAAK;GAAO;GAAU,EAAE,8BAA8B;AACrE,SAAO,cAAc,gCAAgC,IAAI;;AAI7D,QAAO,cACL,uJACA,IACD"}
1
+ {"version":3,"file":"threads.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/intelligence/threads.ts"],"sourcesContent":["import type {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeLike,\n} from \"../../core/runtime\";\nimport { isIntelligenceRuntime } from \"../../core/runtime\";\nimport { logger } from \"@copilotkit/shared\";\nimport { errorResponse, isHandlerResponse } from \"../shared/json-response\";\nimport {\n getPlatformErrorStatus,\n isValidIdentifier,\n} from \"../shared/intelligence-utils\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { platformErrorResponse } from \"../shared/platform-error\";\nimport { supportsLocalThreadEndpoints } from \"../../runner/agent-runner\";\nimport { resolveLocalThreadOwner } from \"../shared/thread-access\";\n\ninterface ThreadsHandlerParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\ninterface ThreadMutationParams extends ThreadsHandlerParams {\n threadId: string;\n}\n\ninterface ThreadMutationContext {\n userId: string;\n agentId: string;\n body: Record<string, unknown>;\n}\n\nasync function parseJsonBody(\n request: Request,\n): Promise<Record<string, unknown> | Response> {\n try {\n return (await request.json()) as Record<string, unknown>;\n } catch (error) {\n logger.error({ err: error }, \"Malformed JSON in request body\");\n return errorResponse(\"Invalid request body\", 400);\n }\n}\n\nfunction requireIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): CopilotIntelligenceRuntimeLike | Response {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n }\n\n return runtime;\n}\n\nasync function resolveThreadMutationContext(\n runtime: CopilotIntelligenceRuntimeLike,\n request: Request,\n): Promise<ThreadMutationContext | Response> {\n const body = await parseJsonBody(request);\n if (isHandlerResponse(body)) return body;\n\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n\n const agentId = body.agentId;\n if (!isValidIdentifier(agentId)) {\n return errorResponse(\"Valid agentId is required\", 400);\n }\n\n return {\n body,\n userId: user.id,\n agentId,\n };\n}\n\n/**\n * The platform's `_inspect` events and state endpoints are scoped by the\n * project key only. Before calling them, confirm the thread is visible to the\n * resolved user through the user-scoped thread lookup, and return its\n * canonical id for the read, so the check and the read name the same thread.\n *\n * Returns the error Response instead when the lookup refuses: the platform's\n * 4xx for a thread the user cannot see (an expected denial, logged as a\n * warning), 502 for a malformed lookup result, and the mapped platform error\n * for anything else (logged as an error).\n */\nasync function requireUserThread(\n runtime: CopilotIntelligenceRuntimeLike,\n threadId: string,\n userId: string,\n failure: string,\n): Promise<{ threadId: string } | Response> {\n let thread: Awaited<ReturnType<typeof runtime.intelligence.getThread>>;\n try {\n thread = await runtime.intelligence.getThread({ threadId, userId });\n } catch (error) {\n const status = getPlatformErrorStatus(error);\n if (\n status !== undefined &&\n status >= 400 &&\n status < 500 &&\n status !== 401\n ) {\n logger.warn({ threadId, status }, \"Thread not visible to the user\");\n } else {\n logger.error({ err: error, threadId }, \"Error resolving thread\");\n }\n return platformErrorResponse(error, failure);\n }\n if (!thread || typeof thread.id !== \"string\" || !thread.id.trim()) {\n logger.error({ threadId }, \"Invalid thread response from getThread\");\n return errorResponse(\"Invalid thread response\", 502);\n }\n return { threadId: thread.id };\n}\n\nexport async function handleListThreads({\n runtime,\n request,\n}: ThreadsHandlerParams): Promise<Response> {\n // CopilotKit Intelligence path\n if (isIntelligenceRuntime(runtime)) {\n try {\n const url = new URL(request.url);\n const agentId = url.searchParams.get(\"agentId\");\n const includeArchived =\n url.searchParams.get(\"includeArchived\") === \"true\";\n const limitParam = url.searchParams.get(\"limit\");\n const cursor = url.searchParams.get(\"cursor\");\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n\n if (!isValidIdentifier(agentId)) {\n return errorResponse(\"Valid agentId query param is required\", 400);\n }\n\n const data = await runtime.intelligence.listThreads({\n userId: user.id,\n agentId,\n ...(includeArchived ? { includeArchived: true } : {}),\n ...(limitParam ? { limit: Number(limitParam) } : {}),\n ...(cursor ? { cursor } : {}),\n });\n\n return Response.json(data);\n } catch (error) {\n logger.error({ err: error }, \"Error listing threads\");\n return errorResponse(\"Failed to list threads\", 500);\n }\n }\n\n // Local in-memory fallback — useful for local development without Intelligence\n if (supportsLocalThreadEndpoints(runtime.runner)) {\n const ownerId = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"list\",\n });\n if (isHandlerResponse(ownerId)) return ownerId;\n try {\n const url = new URL(request.url);\n const agentId = url.searchParams.get(\"agentId\");\n let threads = runtime.runner.listThreads({ ownerId });\n if (agentId) {\n threads = threads.filter((t) => t.agentId === agentId);\n }\n return Response.json({ threads, nextCursor: null });\n } catch (error) {\n logger.error({ err: error }, \"Error listing threads\");\n return errorResponse(\"Failed to list threads\", 500);\n }\n }\n\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n}\n\n/**\n * Clears the caller's in-memory thread history for the local-dev fallback.\n *\n * The local-dev fallback exposes this so consumers (e.g. the demo's Clear\n * button) can wipe in-memory thread history without restarting the runtime.\n * Only the caller's own threads are cleared, and a thread whose run is\n * still active is kept. Without `identifyUser`, the access policy refuses it\n * unless `threads: { access: \"open\" }` is set.\n * Intentionally a no-op when CopilotKit Intelligence is configured: real\n * thread history lives in the database and must not be wiped by a\n * client-side page load.\n */\nexport async function handleClearThreads({\n runtime,\n request,\n}: ThreadsHandlerParams): Promise<Response> {\n if (supportsLocalThreadEndpoints(runtime.runner)) {\n const ownerId = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"clear\",\n });\n if (isHandlerResponse(ownerId)) return ownerId;\n try {\n runtime.runner.clearThreads({ ownerId });\n } catch (error) {\n logger.error({ err: error }, \"Error clearing threads\");\n return errorResponse(\"Failed to clear threads\", 500);\n }\n }\n return new Response(null, { status: 204 });\n}\n\nexport async function handleUpdateThread({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const mutation = await resolveThreadMutationContext(\n intelligenceRuntime,\n request,\n );\n if (isHandlerResponse(mutation)) return mutation;\n\n // The public SDK accepts trusted updates; browser fields must be allowlisted.\n const updates: Record<string, unknown> = {};\n for (const key of [\"name\", \"archived\"]) {\n if (Object.prototype.hasOwnProperty.call(mutation.body, key)) {\n updates[key] = mutation.body[key];\n }\n }\n\n const thread = await intelligenceRuntime.intelligence.updateThread({\n threadId,\n userId: mutation.userId,\n agentId: mutation.agentId,\n updates,\n });\n\n return Response.json(thread);\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error updating thread\");\n return errorResponse(\"Failed to update thread\", 500);\n }\n}\n\nexport async function handleSubscribeToThreads({\n runtime,\n request,\n}: ThreadsHandlerParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const user = await resolveIntelligenceUser({\n runtime: intelligenceRuntime,\n request,\n });\n if (isHandlerResponse(user)) return user;\n\n const credentials =\n await intelligenceRuntime.intelligence.ɵsubscribeToThreads({\n userId: user.id,\n });\n\n return Response.json({ joinToken: credentials.joinToken });\n } catch (error) {\n logger.error({ err: error }, \"Error subscribing to threads\");\n return errorResponse(\"Failed to subscribe to threads\", 500);\n }\n}\n\nexport async function handleArchiveThread({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const mutation = await resolveThreadMutationContext(\n intelligenceRuntime,\n request,\n );\n if (isHandlerResponse(mutation)) return mutation;\n\n await intelligenceRuntime.intelligence.archiveThread({\n threadId,\n userId: mutation.userId,\n agentId: mutation.agentId,\n });\n\n return Response.json({ threadId, archived: true });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error archiving thread\");\n return errorResponse(\"Failed to archive thread\", 500);\n }\n}\n\nexport async function handleDeleteThread({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) {\n return intelligenceRuntime;\n }\n\n try {\n const mutation = await resolveThreadMutationContext(\n intelligenceRuntime,\n request,\n );\n if (isHandlerResponse(mutation)) return mutation;\n\n await intelligenceRuntime.intelligence.deleteThread({\n threadId,\n userId: mutation.userId,\n agentId: mutation.agentId,\n });\n\n return Response.json({ threadId, deleted: true });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error deleting thread\");\n return errorResponse(\"Failed to delete thread\", 500);\n }\n}\n\nexport async function handleGetThreadMessages({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n // CopilotKit Intelligence path\n if (isIntelligenceRuntime(runtime)) {\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n\n const data = await runtime.intelligence.getThreadMessages({\n threadId,\n userId: user.id,\n });\n return Response.json(data);\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error fetching thread messages\");\n return platformErrorResponse(error, \"Failed to fetch thread messages\");\n }\n }\n\n // Local in-memory fallback — useful for local development without Intelligence\n if (supportsLocalThreadEndpoints(runtime.runner)) {\n const ownerId = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"read\",\n });\n if (isHandlerResponse(ownerId)) return ownerId;\n // Another owner's thread reads exactly like an unknown thread.\n let messages: ReturnType<typeof runtime.runner.getThreadMessages>;\n try {\n messages = runtime.runner.getThreadMessages(threadId, { ownerId });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error fetching thread messages\");\n return errorResponse(\"Failed to fetch thread messages\", 500);\n }\n // Map ag-ui Message objects to the same shape CopilotKit Intelligence\n // returns. Switching on the discriminant `role` lets each branch read\n // the narrowed message arm directly, instead of laundering through\n // `Record<string, unknown>` and chained `as` casts.\n const mapped = messages.map((msg) => {\n switch (msg.role) {\n case \"assistant\": {\n const toolCalls = msg.toolCalls ?? [];\n return {\n id: msg.id,\n role: msg.role,\n ...(msg.content !== undefined ? { content: msg.content } : {}),\n ...(toolCalls.length > 0\n ? {\n toolCalls: toolCalls.map((tc) => ({\n id: tc.id,\n name: tc.function.name,\n args: tc.function.arguments,\n })),\n }\n : {}),\n };\n }\n case \"tool\":\n return {\n id: msg.id,\n role: msg.role,\n content: msg.content,\n toolCallId: msg.toolCallId,\n };\n default:\n return {\n id: msg.id,\n role: msg.role,\n ...(\"content\" in msg && msg.content !== undefined\n ? { content: msg.content }\n : {}),\n };\n }\n });\n return Response.json({ messages: mapped });\n }\n\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n}\n\nexport async function handleGetThreadEvents({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n // CopilotKit Intelligence path. Delegates to the platform's `_inspect`\n // endpoint (Intelligence PR #144). Auth still flows through the standard\n // identifyUser → API key path. `_inspect` is not user-scoped, so the\n // thread is first checked against the user (see `requireUserThread`).\n if (isIntelligenceRuntime(runtime)) {\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n const thread = await requireUserThread(\n runtime,\n threadId,\n user.id,\n \"Failed to fetch thread events\",\n );\n if (isHandlerResponse(thread)) return thread;\n\n const data = await runtime.intelligence.getThreadEvents({\n threadId: thread.threadId,\n userId: user.id,\n });\n // Strip platform-internal fields (`decodeErrorRowIds`, `truncated`)\n // before returning to the inspector — those describe persistence-side\n // concerns the inspector currently has no UI for. The shape becomes\n // `{ events }`, matching the in-memory branch below.\n return Response.json({ events: data.events });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error fetching thread events\");\n return platformErrorResponse(error, \"Failed to fetch thread events\");\n }\n }\n\n // Local in-memory fallback\n if (supportsLocalThreadEndpoints(runtime.runner)) {\n const ownerId = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"read\",\n });\n if (isHandlerResponse(ownerId)) return ownerId;\n try {\n const events = runtime.runner.getThreadEvents(threadId, { ownerId });\n return Response.json({ events });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error fetching thread events\");\n return errorResponse(\"Failed to fetch thread events\", 500);\n }\n }\n\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n}\n\nexport async function handleGetThreadState({\n runtime,\n request,\n threadId,\n}: ThreadMutationParams): Promise<Response> {\n // CopilotKit Intelligence path. Delegates to the platform's `_inspect`\n // state endpoint, which folds STATE_DELTA events onto the latest\n // STATE_SNAPSHOT to return the thread's current state.\n if (isIntelligenceRuntime(runtime)) {\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n const thread = await requireUserThread(\n runtime,\n threadId,\n user.id,\n \"Failed to fetch thread state\",\n );\n if (isHandlerResponse(thread)) return thread;\n\n const data = await runtime.intelligence.getThreadState({\n threadId: thread.threadId,\n userId: user.id,\n });\n // Flatten the discriminated `ThreadStateResult` to the wire shape the\n // inspector consumes (`{ state: <value> | null }`). Missing snapshot\n // and decode-error both surface as `null`; the inspector renders an\n // empty state branch for null and the platform's decode-error case is\n // already logged platform-side.\n const state = data.kind === \"snapshot\" ? data.state : null;\n return Response.json({ state });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error fetching thread state\");\n return platformErrorResponse(error, \"Failed to fetch thread state\");\n }\n }\n\n if (supportsLocalThreadEndpoints(runtime.runner)) {\n const ownerId = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"read\",\n });\n if (isHandlerResponse(ownerId)) return ownerId;\n try {\n const state = runtime.runner.getThreadState(threadId, { ownerId });\n return Response.json({ state });\n } catch (error) {\n logger.error({ err: error, threadId }, \"Error fetching thread state\");\n return errorResponse(\"Failed to fetch thread state\", 500);\n }\n }\n\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n}\n"],"mappings":";;;;;;;;;;;AA+BA,eAAe,cACb,SAC6C;AAC7C,KAAI;AACF,SAAQ,MAAM,QAAQ,MAAM;UACrB,OAAO;AACd,SAAO,MAAM,EAAE,KAAK,OAAO,EAAE,iCAAiC;AAC9D,SAAO,cAAc,wBAAwB,IAAI;;;AAIrD,SAAS,2BACP,SAC2C;AAC3C,KAAI,CAAC,sBAAsB,QAAQ,CACjC,QAAO,cACL,uJACA,IACD;AAGH,QAAO;;AAGT,eAAe,6BACb,SACA,SAC2C;CAC3C,MAAM,OAAO,MAAM,cAAc,QAAQ;AACzC,KAAI,kBAAkB,KAAK,CAAE,QAAO;CAEpC,MAAM,OAAO,MAAM,wBAAwB;EAAE;EAAS;EAAS,CAAC;AAChE,KAAI,kB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AO,sBAAsB,OAAO,+BAA+B;;AAIvE,KAAI,6BAA6B,QAAQ,OAAO,EAAE;EAChD,MAAM,UAAU,MAAM,wBAAwB;GAC5C;GACA;GACA,WAAW;GACZ,CAAC;AACF,MAAI,kBAAkB,QAAQ,CAAE,QAAO;AACvC,MAAI;GACF,MAAM,QAAQ,QAAQ,OAAO,eAAe,UAAU,EAAE,SAAS,CAAC;AAClE,UAAO,SAAS,KAAK,EAAE,OAAO,CAAC;WACxB,OAAO;AACd,UAAO,MAAM;IAAE,KAAK;IAAO;IAAU,EAAE,8BAA8B;AACrE,UAAO,cAAc,gCAAgC,IAAI;;;AAI7D,QAAO,cACL,uJACA,IACD"}
@@ -1,12 +1,12 @@
1
1
  require("reflect-metadata");
2
2
  const require_runtime = require('../../../../_virtual/_rolldown/runtime.cjs');
3
3
  const require_header_utils = require('../header-utils.cjs');
4
- const require_runtime$1 = require('../../core/runtime.cjs');
4
+ const require_json_response = require('./json-response.cjs');
5
5
  const require_client = require('../../intelligence-platform/client.cjs');
6
+ const require_resolve_intelligence_user = require('./resolve-intelligence-user.cjs');
7
+ const require_runtime$1 = require('../../core/runtime.cjs');
6
8
  const require_generative_ui_middleware = require('../../generative-ui/generative-ui-middleware.cjs');
7
9
  const require_mcp_apps_servers = require('./mcp-apps-servers.cjs');
8
- const require_json_response = require('./json-response.cjs');
9
- const require_resolve_intelligence_user = require('./resolve-intelligence-user.cjs');
10
10
  const require_memory_policy = require('./memory-policy.cjs');
11
11
  let _copilotkit_shared = require("@copilotkit/shared");
12
12
  let _ag_ui_mcp_middleware = require("@ag-ui/mcp-middleware");
@@ -1,11 +1,11 @@
1
1
  import "reflect-metadata";
2
2
  import { mergeForwardableHeaders, resolveForwardHeadersPolicy } from "../header-utils.mjs";
3
- import { isA2UIEnabled, isIntelligenceRuntime, resolveAgents } from "../../core/runtime.mjs";
3
+ import { errorResponse } from "./json-response.mjs";
4
4
  import { INTELLIGENCE_MEMORY_GRANT_HEADER, INTELLIGENCE_USER_ID_HEADER } from "../../intelligence-platform/client.mjs";
5
+ import { resolveIntelligenceUser } from "./resolve-intelligence-user.mjs";
6
+ import { isA2UIEnabled, isIntelligenceRuntime, resolveAgents } from "../../core/runtime.mjs";
5
7
  import { GenerativeUIMiddleware } from "../../generative-ui/generative-ui-middleware.mjs";
6
8
  import { resolveMcpAppsServers } from "./mcp-apps-servers.mjs";
7
- import { errorResponse } from "./json-response.mjs";
8
- import { resolveIntelligenceUser } from "./resolve-intelligence-user.mjs";
9
9
  import { grantAllowsMemory, resolveWebMemory } from "./memory-policy.mjs";
10
10
  import { logger } from "@copilotkit/shared";
11
11
  import { MCPMiddleware } from "@ag-ui/mcp-middleware";
@@ -1,4 +1,5 @@
1
1
  require("reflect-metadata");
2
+ const require_mcp_client_cache = require('../../../../lib/runtime/mcp-client-cache.cjs');
2
3
 
3
4
  //#region src/v2/runtime/handlers/shared/mcp-apps-servers.ts
4
5
  const UNSUPPORTED_POLICY_KEYS = ["includeTools", "excludeTools"];
@@ -11,7 +12,7 @@ function resolveMcpAppsServers(servers, agentId) {
11
12
  const violations = [];
12
13
  for (const [index, server] of servers.entries()) {
13
14
  const config = server;
14
- for (const key of UNSUPPORTED_POLICY_KEYS) if (Object.prototype.hasOwnProperty.call(config, key) && config[key] !== void 0) violations.push(`${key} at server[${index}] (${server.serverId ?? server.url})`);
15
+ for (const key of UNSUPPORTED_POLICY_KEYS) if (Object.prototype.hasOwnProperty.call(config, key) && config[key] !== void 0) violations.push(`${key} at server[${index}] (${server.serverId ?? require_mcp_client_cache.describeEndpoint(server.url)})`);
15
16
  }
16
17
  if (violations.length > 0) throw new Error(`Unsupported MCP Apps tool policy: ${violations.join(", ")}. @ag-ui/mcp-apps-middleware owns per-server tool policy, and the release the runtime depends on does not support these keys; see ${MCP_APPS_POLICY_ISSUE}.`);
17
18
  return servers.filter((server) => !server.agentId || server.agentId === agentId).map(({ agentId: _agentId, ...server }) => server);
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-apps-servers.cjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/shared/mcp-apps-servers.ts"],"sourcesContent":["import type { MCPClientConfig } from \"@ag-ui/mcp-apps-middleware\";\nimport type { McpAppsServerConfig } from \"../../core/runtime\";\n\nconst UNSUPPORTED_POLICY_KEYS = [\"includeTools\", \"excludeTools\"] as const;\nconst MCP_APPS_POLICY_ISSUE =\n \"https://github.com/CopilotKit/CopilotKit/issues/5930\";\n\n/**\n * Select the servers for an agent and validate the policy boundary owned by\n * the installed MCP Apps middleware.\n */\nexport function resolveMcpAppsServers(\n servers: readonly McpAppsServerConfig[],\n agentId: string,\n): MCPClientConfig[] {\n const violations: string[] = [];\n\n for (const [index, server] of servers.entries()) {\n const config = server as unknown as Record<string, unknown>;\n for (const key of UNSUPPORTED_POLICY_KEYS) {\n if (\n Object.prototype.hasOwnProperty.call(config, key) &&\n config[key] !== undefined\n ) {\n violations.push(\n `${key} at server[${index}] (${server.serverId ?? server.url})`,\n );\n }\n }\n }\n\n if (violations.length > 0) {\n throw new Error(\n `Unsupported MCP Apps tool policy: ${violations.join(\", \")}. ` +\n `@ag-ui/mcp-apps-middleware owns per-server tool policy, and the ` +\n `release the runtime depends on does not support these keys; see ` +\n `${MCP_APPS_POLICY_ISSUE}.`,\n );\n }\n\n return servers\n .filter((server) => !server.agentId || server.agentId === agentId)\n .map(({ agentId: _agentId, ...server }) => server as MCPClientConfig);\n}\n"],"mappings":";;;AAGA,MAAM,0BAA0B,CAAC,gBAAgB,eAAe;AAChE,MAAM,wBACJ;;;;;AAMF,SAAgB,sBACd,SACA,SACmB;CACnB,MAAM,aAAuB,EAAE;AAE/B,MAAK,MAAM,CAAC,OAAO,WAAW,QAAQ,SAAS,EAAE;EAC/C,MAAM,SAAS;AACf,OAAK,MAAM,OAAO,wBAChB,KACE,OAAO,UAAU,eAAe,KAAK,QAAQ,IAAI,IACjD,OAAO,SAAS,OAEhB,YAAW,KACT,GAAG,IAAI,aAAa,MAAM,KAAK,OAAO,YAAY,OAAO,IAAI,GAC9D;;AAKP,KAAI,WAAW,SAAS,EACtB,OAAM,IAAI,MACR,qCAAqC,WAAW,KAAK,KAAK,CAAC,oIAGtD,sBAAsB,GAC5B;AAGH,QAAO,QACJ,QAAQ,WAAW,CAAC,OAAO,WAAW,OAAO,YAAY,QAAQ,CACjE,KAAK,EAAE,SAAS,UAAU,GAAG,aAAa,OAA0B"}
1
+ {"version":3,"file":"mcp-apps-servers.cjs","names":["describeEndpoint"],"sources":["../../../../../src/v2/runtime/handlers/shared/mcp-apps-servers.ts"],"sourcesContent":["import type { MCPClientConfig } from \"@ag-ui/mcp-apps-middleware\";\nimport type { McpAppsServerConfig } from \"../../core/runtime\";\nimport { describeEndpoint } from \"../../../../v1-deprecated/lib/runtime/mcp-client-cache\";\n\nconst UNSUPPORTED_POLICY_KEYS = [\"includeTools\", \"excludeTools\"] as const;\nconst MCP_APPS_POLICY_ISSUE =\n \"https://github.com/CopilotKit/CopilotKit/issues/5930\";\n\n/**\n * Select the servers for an agent and validate the policy boundary owned by\n * the installed MCP Apps middleware.\n */\nexport function resolveMcpAppsServers(\n servers: readonly McpAppsServerConfig[],\n agentId: string,\n): MCPClientConfig[] {\n const violations: string[] = [];\n\n for (const [index, server] of servers.entries()) {\n const config = server as unknown as Record<string, unknown>;\n for (const key of UNSUPPORTED_POLICY_KEYS) {\n if (\n Object.prototype.hasOwnProperty.call(config, key) &&\n config[key] !== undefined\n ) {\n violations.push(\n `${key} at server[${index}] (${server.serverId ?? describeEndpoint(server.url)})`,\n );\n }\n }\n }\n\n if (violations.length > 0) {\n throw new Error(\n `Unsupported MCP Apps tool policy: ${violations.join(\", \")}. ` +\n `@ag-ui/mcp-apps-middleware owns per-server tool policy, and the ` +\n `release the runtime depends on does not support these keys; see ` +\n `${MCP_APPS_POLICY_ISSUE}.`,\n );\n }\n\n return servers\n .filter((server) => !server.agentId || server.agentId === agentId)\n .map(({ agentId: _agentId, ...server }) => server as MCPClientConfig);\n}\n"],"mappings":";;;;AAIA,MAAM,0BAA0B,CAAC,gBAAgB,eAAe;AAChE,MAAM,wBACJ;;;;;AAMF,SAAgB,sBACd,SACA,SACmB;CACnB,MAAM,aAAuB,EAAE;AAE/B,MAAK,MAAM,CAAC,OAAO,WAAW,QAAQ,SAAS,EAAE;EAC/C,MAAM,SAAS;AACf,OAAK,MAAM,OAAO,wBAChB,KACE,OAAO,UAAU,eAAe,KAAK,QAAQ,IAAI,IACjD,OAAO,SAAS,OAEhB,YAAW,KACT,GAAG,IAAI,aAAa,MAAM,KAAK,OAAO,YAAYA,0CAAiB,OAAO,IAAI,CAAC,GAChF;;AAKP,KAAI,WAAW,SAAS,EACtB,OAAM,IAAI,MACR,qCAAqC,WAAW,KAAK,KAAK,CAAC,oIAGtD,sBAAsB,GAC5B;AAGH,QAAO,QACJ,QAAQ,WAAW,CAAC,OAAO,WAAW,OAAO,YAAY,QAAQ,CACjE,KAAK,EAAE,SAAS,UAAU,GAAG,aAAa,OAA0B"}
@@ -1,4 +1,6 @@
1
1
  import "reflect-metadata";
2
+ import { describeEndpoint } from "../../../../lib/runtime/mcp-client-cache.mjs";
3
+
2
4
  //#region src/v2/runtime/handlers/shared/mcp-apps-servers.ts
3
5
  const UNSUPPORTED_POLICY_KEYS = ["includeTools", "excludeTools"];
4
6
  const MCP_APPS_POLICY_ISSUE = "https://github.com/CopilotKit/CopilotKit/issues/5930";
@@ -10,7 +12,7 @@ function resolveMcpAppsServers(servers, agentId) {
10
12
  const violations = [];
11
13
  for (const [index, server] of servers.entries()) {
12
14
  const config = server;
13
- for (const key of UNSUPPORTED_POLICY_KEYS) if (Object.prototype.hasOwnProperty.call(config, key) && config[key] !== void 0) violations.push(`${key} at server[${index}] (${server.serverId ?? server.url})`);
15
+ for (const key of UNSUPPORTED_POLICY_KEYS) if (Object.prototype.hasOwnProperty.call(config, key) && config[key] !== void 0) violations.push(`${key} at server[${index}] (${server.serverId ?? describeEndpoint(server.url)})`);
14
16
  }
15
17
  if (violations.length > 0) throw new Error(`Unsupported MCP Apps tool policy: ${violations.join(", ")}. @ag-ui/mcp-apps-middleware owns per-server tool policy, and the release the runtime depends on does not support these keys; see ${MCP_APPS_POLICY_ISSUE}.`);
16
18
  return servers.filter((server) => !server.agentId || server.agentId === agentId).map(({ agentId: _agentId, ...server }) => server);
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-apps-servers.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/shared/mcp-apps-servers.ts"],"sourcesContent":["import type { MCPClientConfig } from \"@ag-ui/mcp-apps-middleware\";\nimport type { McpAppsServerConfig } from \"../../core/runtime\";\n\nconst UNSUPPORTED_POLICY_KEYS = [\"includeTools\", \"excludeTools\"] as const;\nconst MCP_APPS_POLICY_ISSUE =\n \"https://github.com/CopilotKit/CopilotKit/issues/5930\";\n\n/**\n * Select the servers for an agent and validate the policy boundary owned by\n * the installed MCP Apps middleware.\n */\nexport function resolveMcpAppsServers(\n servers: readonly McpAppsServerConfig[],\n agentId: string,\n): MCPClientConfig[] {\n const violations: string[] = [];\n\n for (const [index, server] of servers.entries()) {\n const config = server as unknown as Record<string, unknown>;\n for (const key of UNSUPPORTED_POLICY_KEYS) {\n if (\n Object.prototype.hasOwnProperty.call(config, key) &&\n config[key] !== undefined\n ) {\n violations.push(\n `${key} at server[${index}] (${server.serverId ?? server.url})`,\n );\n }\n }\n }\n\n if (violations.length > 0) {\n throw new Error(\n `Unsupported MCP Apps tool policy: ${violations.join(\", \")}. ` +\n `@ag-ui/mcp-apps-middleware owns per-server tool policy, and the ` +\n `release the runtime depends on does not support these keys; see ` +\n `${MCP_APPS_POLICY_ISSUE}.`,\n );\n }\n\n return servers\n .filter((server) => !server.agentId || server.agentId === agentId)\n .map(({ agentId: _agentId, ...server }) => server as MCPClientConfig);\n}\n"],"mappings":";;AAGA,MAAM,0BAA0B,CAAC,gBAAgB,eAAe;AAChE,MAAM,wBACJ;;;;;AAMF,SAAgB,sBACd,SACA,SACmB;CACnB,MAAM,aAAuB,EAAE;AAE/B,MAAK,MAAM,CAAC,OAAO,WAAW,QAAQ,SAAS,EAAE;EAC/C,MAAM,SAAS;AACf,OAAK,MAAM,OAAO,wBAChB,KACE,OAAO,UAAU,eAAe,KAAK,QAAQ,IAAI,IACjD,OAAO,SAAS,OAEhB,YAAW,KACT,GAAG,IAAI,aAAa,MAAM,KAAK,OAAO,YAAY,OAAO,IAAI,GAC9D;;AAKP,KAAI,WAAW,SAAS,EACtB,OAAM,IAAI,MACR,qCAAqC,WAAW,KAAK,KAAK,CAAC,oIAGtD,sBAAsB,GAC5B;AAGH,QAAO,QACJ,QAAQ,WAAW,CAAC,OAAO,WAAW,OAAO,YAAY,QAAQ,CACjE,KAAK,EAAE,SAAS,UAAU,GAAG,aAAa,OAA0B"}
1
+ {"version":3,"file":"mcp-apps-servers.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/shared/mcp-apps-servers.ts"],"sourcesContent":["import type { MCPClientConfig } from \"@ag-ui/mcp-apps-middleware\";\nimport type { McpAppsServerConfig } from \"../../core/runtime\";\nimport { describeEndpoint } from \"../../../../v1-deprecated/lib/runtime/mcp-client-cache\";\n\nconst UNSUPPORTED_POLICY_KEYS = [\"includeTools\", \"excludeTools\"] as const;\nconst MCP_APPS_POLICY_ISSUE =\n \"https://github.com/CopilotKit/CopilotKit/issues/5930\";\n\n/**\n * Select the servers for an agent and validate the policy boundary owned by\n * the installed MCP Apps middleware.\n */\nexport function resolveMcpAppsServers(\n servers: readonly McpAppsServerConfig[],\n agentId: string,\n): MCPClientConfig[] {\n const violations: string[] = [];\n\n for (const [index, server] of servers.entries()) {\n const config = server as unknown as Record<string, unknown>;\n for (const key of UNSUPPORTED_POLICY_KEYS) {\n if (\n Object.prototype.hasOwnProperty.call(config, key) &&\n config[key] !== undefined\n ) {\n violations.push(\n `${key} at server[${index}] (${server.serverId ?? describeEndpoint(server.url)})`,\n );\n }\n }\n }\n\n if (violations.length > 0) {\n throw new Error(\n `Unsupported MCP Apps tool policy: ${violations.join(\", \")}. ` +\n `@ag-ui/mcp-apps-middleware owns per-server tool policy, and the ` +\n `release the runtime depends on does not support these keys; see ` +\n `${MCP_APPS_POLICY_ISSUE}.`,\n );\n }\n\n return servers\n .filter((server) => !server.agentId || server.agentId === agentId)\n .map(({ agentId: _agentId, ...server }) => server as MCPClientConfig);\n}\n"],"mappings":";;;;AAIA,MAAM,0BAA0B,CAAC,gBAAgB,eAAe;AAChE,MAAM,wBACJ;;;;;AAMF,SAAgB,sBACd,SACA,SACmB;CACnB,MAAM,aAAuB,EAAE;AAE/B,MAAK,MAAM,CAAC,OAAO,WAAW,QAAQ,SAAS,EAAE;EAC/C,MAAM,SAAS;AACf,OAAK,MAAM,OAAO,wBAChB,KACE,OAAO,UAAU,eAAe,KAAK,QAAQ,IAAI,IACjD,OAAO,SAAS,OAEhB,YAAW,KACT,GAAG,IAAI,aAAa,MAAM,KAAK,OAAO,YAAY,iBAAiB,OAAO,IAAI,CAAC,GAChF;;AAKP,KAAI,WAAW,SAAS,EACtB,OAAM,IAAI,MACR,qCAAqC,WAAW,KAAK,KAAK,CAAC,oIAGtD,sBAAsB,GAC5B;AAGH,QAAO,QACJ,QAAQ,WAAW,CAAC,OAAO,WAAW,OAAO,YAAY,QAAQ,CACjE,KAAK,EAAE,SAAS,UAAU,GAAG,aAAa,OAA0B"}
@@ -1,6 +1,6 @@
1
1
  require("reflect-metadata");
2
- const require_client = require('../../intelligence-platform/client.cjs');
3
2
  const require_json_response = require('./json-response.cjs');
3
+ const require_client = require('../../intelligence-platform/client.cjs');
4
4
 
5
5
  //#region src/v2/runtime/handlers/shared/platform-error.ts
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  import "reflect-metadata";
2
- import { PlatformRequestError } from "../../intelligence-platform/client.mjs";
3
2
  import { errorResponse } from "./json-response.mjs";
3
+ import { PlatformRequestError } from "../../intelligence-platform/client.mjs";
4
4
 
5
5
  //#region src/v2/runtime/handlers/shared/platform-error.ts
6
6
  /**
@@ -1,9 +1,22 @@
1
1
  require("reflect-metadata");
2
2
  const require_json_response = require('./json-response.cjs');
3
3
  const require_intelligence_utils = require('./intelligence-utils.cjs');
4
+ const require_runtime = require('../../core/runtime.cjs');
4
5
 
5
6
  //#region src/v2/runtime/handlers/shared/resolve-intelligence-user.ts
7
+ /** Narrows a runtime to one that has `identifyUser`. */
8
+ function hasIdentifyUser(runtime) {
9
+ return typeof runtime.identifyUser === "function";
10
+ }
6
11
  const resolvedUsers = /* @__PURE__ */ new WeakMap();
12
+ /**
13
+ * Resolves the request's user through `identifyUser`, once per request, for
14
+ * both runtime kinds: the Intelligence runtime and an SSE runtime with
15
+ * `identifyUser` (local Thread ownership). Only the Intelligence runtime
16
+ * needs the user's `name`; an SSE runtime needs the `id` alone.
17
+ *
18
+ * A callback that throws gets a 500 on every route.
19
+ */
7
20
  async function resolveIntelligenceUser(params) {
8
21
  const { runtime, request } = params;
9
22
  const existing = resolvedUsers.get(request);
@@ -13,20 +26,26 @@ async function resolveIntelligenceUser(params) {
13
26
  return resolution;
14
27
  }
15
28
  async function resolveUser(runtime, request) {
29
+ if (!hasIdentifyUser(runtime)) {
30
+ console.error("Error identifying user: identifyUser is not configured");
31
+ return require_json_response.errorResponse("Failed to identify user", 500);
32
+ }
16
33
  try {
17
34
  const user = await runtime.identifyUser(request);
18
35
  if (!require_intelligence_utils.isValidIdentifier(user?.id)) return require_json_response.errorResponse("identifyUser must return a valid user id", 400);
19
- if (typeof user?.name !== "string" || user.name.trim().length === 0) return require_json_response.errorResponse("identifyUser must return a valid user name", 400);
36
+ const hasName = typeof user?.name === "string" && user.name.trim().length > 0;
37
+ if (!hasName && require_runtime.isIntelligenceRuntime(runtime)) return require_json_response.errorResponse("identifyUser must return a valid user name", 400);
20
38
  return {
21
39
  id: user.id,
22
- name: user.name
40
+ name: hasName ? user.name : user.id
23
41
  };
24
42
  } catch (error) {
25
- console.error("Error identifying intelligence user:", error);
43
+ console.error("Error identifying user:", error);
26
44
  return require_json_response.errorResponse("Failed to identify user", 500);
27
45
  }
28
46
  }
29
47
 
30
48
  //#endregion
49
+ exports.hasIdentifyUser = hasIdentifyUser;
31
50
  exports.resolveIntelligenceUser = resolveIntelligenceUser;
32
51
  //# sourceMappingURL=resolve-intelligence-user.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-intelligence-user.cjs","names":["isValidIdentifier","errorResponse"],"sources":["../../../../../src/v2/runtime/handlers/shared/resolve-intelligence-user.ts"],"sourcesContent":["import type {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeUser,\n} from \"../../core/runtime\";\nimport { errorResponse } from \"./json-response\";\nimport { isValidIdentifier } from \"./intelligence-utils\";\n\nconst resolvedUsers = new WeakMap<\n Request,\n Promise<CopilotRuntimeUser | Response>\n>();\n\nexport async function resolveIntelligenceUser(params: {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n}): Promise<CopilotRuntimeUser | Response> {\n const { runtime, request } = params;\n\n const existing = resolvedUsers.get(request);\n if (existing) return existing;\n\n const resolution = resolveUser(runtime, request);\n resolvedUsers.set(request, resolution);\n return resolution;\n}\n\nasync function resolveUser(\n runtime: CopilotIntelligenceRuntimeLike,\n request: Request,\n): Promise<CopilotRuntimeUser | Response> {\n try {\n const user = await runtime.identifyUser(request);\n if (!isValidIdentifier(user?.id)) {\n return errorResponse(\"identifyUser must return a valid user id\", 400);\n }\n if (typeof user?.name !== \"string\" || user.name.trim().length === 0) {\n return errorResponse(\"identifyUser must return a valid user name\", 400);\n }\n\n return { id: user.id, name: user.name };\n } catch (error) {\n console.error(\"Error identifying intelligence user:\", error);\n return errorResponse(\"Failed to identify user\", 500);\n }\n}\n"],"mappings":";;;;;AAOA,MAAM,gCAAgB,IAAI,SAGvB;AAEH,eAAsB,wBAAwB,QAGH;CACzC,MAAM,EAAE,SAAS,YAAY;CAE7B,MAAM,WAAW,cAAc,IAAI,QAAQ;AAC3C,KAAI,SAAU,QAAO;CAErB,MAAM,aAAa,YAAY,SAAS,QAAQ;AAChD,eAAc,IAAI,SAAS,WAAW;AACtC,QAAO;;AAGT,eAAe,YACb,SACA,SACwC;AACxC,KAAI;EACF,MAAM,OAAO,MAAM,QAAQ,aAAa,QAAQ;AAChD,MAAI,CAACA,6CAAkB,MAAM,GAAG,CAC9B,QAAOC,oCAAc,4CAA4C,IAAI;AAEvE,MAAI,OAAO,MAAM,SAAS,YAAY,KAAK,KAAK,MAAM,CAAC,WAAW,EAChE,QAAOA,oCAAc,8CAA8C,IAAI;AAGzE,SAAO;GAAE,IAAI,KAAK;GAAI,MAAM,KAAK;GAAM;UAChC,OAAO;AACd,UAAQ,MAAM,wCAAwC,MAAM;AAC5D,SAAOA,oCAAc,2BAA2B,IAAI"}
1
+ {"version":3,"file":"resolve-intelligence-user.cjs","names":["errorResponse","isValidIdentifier","isIntelligenceRuntime"],"sources":["../../../../../src/v2/runtime/handlers/shared/resolve-intelligence-user.ts"],"sourcesContent":["import type {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeLike,\n CopilotRuntimeUser,\n IdentifyUserCallback,\n} from \"../../core/runtime\";\nimport { isIntelligenceRuntime } from \"../../core/runtime\";\nimport { errorResponse } from \"./json-response\";\nimport { isValidIdentifier } from \"./intelligence-utils\";\n\n/** A runtime whose `identifyUser` is known to be set. */\nexport type IdentifiedRuntimeLike = CopilotRuntimeLike & {\n identifyUser: IdentifyUserCallback;\n};\n\n/** Narrows a runtime to one that has `identifyUser`. */\nexport function hasIdentifyUser(\n runtime: CopilotRuntimeLike,\n): runtime is IdentifiedRuntimeLike {\n return typeof runtime.identifyUser === \"function\";\n}\n\nconst resolvedUsers = new WeakMap<\n Request,\n Promise<CopilotRuntimeUser | Response>\n>();\n\n/**\n * Resolves the request's user through `identifyUser`, once per request, for\n * both runtime kinds: the Intelligence runtime and an SSE runtime with\n * `identifyUser` (local Thread ownership). Only the Intelligence runtime\n * needs the user's `name`; an SSE runtime needs the `id` alone.\n *\n * A callback that throws gets a 500 on every route.\n */\nexport async function resolveIntelligenceUser(params: {\n runtime: CopilotIntelligenceRuntimeLike | IdentifiedRuntimeLike;\n request: Request;\n}): Promise<CopilotRuntimeUser | Response> {\n const { runtime, request } = params;\n\n const existing = resolvedUsers.get(request);\n if (existing) return existing;\n\n const resolution = resolveUser(runtime, request);\n resolvedUsers.set(request, resolution);\n return resolution;\n}\n\nasync function resolveUser(\n runtime: CopilotRuntimeLike,\n request: Request,\n): Promise<CopilotRuntimeUser | Response> {\n if (!hasIdentifyUser(runtime)) {\n console.error(\"Error identifying user: identifyUser is not configured\");\n return errorResponse(\"Failed to identify user\", 500);\n }\n try {\n const user = await runtime.identifyUser(request);\n if (!isValidIdentifier(user?.id)) {\n return errorResponse(\"identifyUser must return a valid user id\", 400);\n }\n const hasName =\n typeof user?.name === \"string\" && user.name.trim().length > 0;\n if (!hasName && isIntelligenceRuntime(runtime)) {\n return errorResponse(\"identifyUser must return a valid user name\", 400);\n }\n\n return { id: user.id, name: hasName ? user.name : user.id };\n } catch (error) {\n console.error(\"Error identifying user:\", error);\n return errorResponse(\"Failed to identify user\", 500);\n }\n}\n"],"mappings":";;;;;;;AAgBA,SAAgB,gBACd,SACkC;AAClC,QAAO,OAAO,QAAQ,iBAAiB;;AAGzC,MAAM,gCAAgB,IAAI,SAGvB;;;;;;;;;AAUH,eAAsB,wBAAwB,QAGH;CACzC,MAAM,EAAE,SAAS,YAAY;CAE7B,MAAM,WAAW,cAAc,IAAI,QAAQ;AAC3C,KAAI,SAAU,QAAO;CAErB,MAAM,aAAa,YAAY,SAAS,QAAQ;AAChD,eAAc,IAAI,SAAS,WAAW;AACtC,QAAO;;AAGT,eAAe,YACb,SACA,SACwC;AACxC,KAAI,CAAC,gBAAgB,QAAQ,EAAE;AAC7B,UAAQ,MAAM,yDAAyD;AACvE,SAAOA,oCAAc,2BAA2B,IAAI;;AAEtD,KAAI;EACF,MAAM,OAAO,MAAM,QAAQ,aAAa,QAAQ;AAChD,MAAI,CAACC,6CAAkB,MAAM,GAAG,CAC9B,QAAOD,oCAAc,4CAA4C,IAAI;EAEvE,MAAM,UACJ,OAAO,MAAM,SAAS,YAAY,KAAK,KAAK,MAAM,CAAC,SAAS;AAC9D,MAAI,CAAC,WAAWE,sCAAsB,QAAQ,CAC5C,QAAOF,oCAAc,8CAA8C,IAAI;AAGzE,SAAO;GAAE,IAAI,KAAK;GAAI,MAAM,UAAU,KAAK,OAAO,KAAK;GAAI;UACpD,OAAO;AACd,UAAQ,MAAM,2BAA2B,MAAM;AAC/C,SAAOA,oCAAc,2BAA2B,IAAI"}
@@ -1,9 +1,22 @@
1
1
  import "reflect-metadata";
2
2
  import { errorResponse } from "./json-response.mjs";
3
3
  import { isValidIdentifier } from "./intelligence-utils.mjs";
4
+ import { isIntelligenceRuntime } from "../../core/runtime.mjs";
4
5
 
5
6
  //#region src/v2/runtime/handlers/shared/resolve-intelligence-user.ts
7
+ /** Narrows a runtime to one that has `identifyUser`. */
8
+ function hasIdentifyUser(runtime) {
9
+ return typeof runtime.identifyUser === "function";
10
+ }
6
11
  const resolvedUsers = /* @__PURE__ */ new WeakMap();
12
+ /**
13
+ * Resolves the request's user through `identifyUser`, once per request, for
14
+ * both runtime kinds: the Intelligence runtime and an SSE runtime with
15
+ * `identifyUser` (local Thread ownership). Only the Intelligence runtime
16
+ * needs the user's `name`; an SSE runtime needs the `id` alone.
17
+ *
18
+ * A callback that throws gets a 500 on every route.
19
+ */
7
20
  async function resolveIntelligenceUser(params) {
8
21
  const { runtime, request } = params;
9
22
  const existing = resolvedUsers.get(request);
@@ -13,20 +26,25 @@ async function resolveIntelligenceUser(params) {
13
26
  return resolution;
14
27
  }
15
28
  async function resolveUser(runtime, request) {
29
+ if (!hasIdentifyUser(runtime)) {
30
+ console.error("Error identifying user: identifyUser is not configured");
31
+ return errorResponse("Failed to identify user", 500);
32
+ }
16
33
  try {
17
34
  const user = await runtime.identifyUser(request);
18
35
  if (!isValidIdentifier(user?.id)) return errorResponse("identifyUser must return a valid user id", 400);
19
- if (typeof user?.name !== "string" || user.name.trim().length === 0) return errorResponse("identifyUser must return a valid user name", 400);
36
+ const hasName = typeof user?.name === "string" && user.name.trim().length > 0;
37
+ if (!hasName && isIntelligenceRuntime(runtime)) return errorResponse("identifyUser must return a valid user name", 400);
20
38
  return {
21
39
  id: user.id,
22
- name: user.name
40
+ name: hasName ? user.name : user.id
23
41
  };
24
42
  } catch (error) {
25
- console.error("Error identifying intelligence user:", error);
43
+ console.error("Error identifying user:", error);
26
44
  return errorResponse("Failed to identify user", 500);
27
45
  }
28
46
  }
29
47
 
30
48
  //#endregion
31
- export { resolveIntelligenceUser };
49
+ export { hasIdentifyUser, resolveIntelligenceUser };
32
50
  //# sourceMappingURL=resolve-intelligence-user.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-intelligence-user.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/shared/resolve-intelligence-user.ts"],"sourcesContent":["import type {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeUser,\n} from \"../../core/runtime\";\nimport { errorResponse } from \"./json-response\";\nimport { isValidIdentifier } from \"./intelligence-utils\";\n\nconst resolvedUsers = new WeakMap<\n Request,\n Promise<CopilotRuntimeUser | Response>\n>();\n\nexport async function resolveIntelligenceUser(params: {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n}): Promise<CopilotRuntimeUser | Response> {\n const { runtime, request } = params;\n\n const existing = resolvedUsers.get(request);\n if (existing) return existing;\n\n const resolution = resolveUser(runtime, request);\n resolvedUsers.set(request, resolution);\n return resolution;\n}\n\nasync function resolveUser(\n runtime: CopilotIntelligenceRuntimeLike,\n request: Request,\n): Promise<CopilotRuntimeUser | Response> {\n try {\n const user = await runtime.identifyUser(request);\n if (!isValidIdentifier(user?.id)) {\n return errorResponse(\"identifyUser must return a valid user id\", 400);\n }\n if (typeof user?.name !== \"string\" || user.name.trim().length === 0) {\n return errorResponse(\"identifyUser must return a valid user name\", 400);\n }\n\n return { id: user.id, name: user.name };\n } catch (error) {\n console.error(\"Error identifying intelligence user:\", error);\n return errorResponse(\"Failed to identify user\", 500);\n }\n}\n"],"mappings":";;;;;AAOA,MAAM,gCAAgB,IAAI,SAGvB;AAEH,eAAsB,wBAAwB,QAGH;CACzC,MAAM,EAAE,SAAS,YAAY;CAE7B,MAAM,WAAW,cAAc,IAAI,QAAQ;AAC3C,KAAI,SAAU,QAAO;CAErB,MAAM,aAAa,YAAY,SAAS,QAAQ;AAChD,eAAc,IAAI,SAAS,WAAW;AACtC,QAAO;;AAGT,eAAe,YACb,SACA,SACwC;AACxC,KAAI;EACF,MAAM,OAAO,MAAM,QAAQ,aAAa,QAAQ;AAChD,MAAI,CAAC,kBAAkB,MAAM,GAAG,CAC9B,QAAO,cAAc,4CAA4C,IAAI;AAEvE,MAAI,OAAO,MAAM,SAAS,YAAY,KAAK,KAAK,MAAM,CAAC,WAAW,EAChE,QAAO,cAAc,8CAA8C,IAAI;AAGzE,SAAO;GAAE,IAAI,KAAK;GAAI,MAAM,KAAK;GAAM;UAChC,OAAO;AACd,UAAQ,MAAM,wCAAwC,MAAM;AAC5D,SAAO,cAAc,2BAA2B,IAAI"}
1
+ {"version":3,"file":"resolve-intelligence-user.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/shared/resolve-intelligence-user.ts"],"sourcesContent":["import type {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeLike,\n CopilotRuntimeUser,\n IdentifyUserCallback,\n} from \"../../core/runtime\";\nimport { isIntelligenceRuntime } from \"../../core/runtime\";\nimport { errorResponse } from \"./json-response\";\nimport { isValidIdentifier } from \"./intelligence-utils\";\n\n/** A runtime whose `identifyUser` is known to be set. */\nexport type IdentifiedRuntimeLike = CopilotRuntimeLike & {\n identifyUser: IdentifyUserCallback;\n};\n\n/** Narrows a runtime to one that has `identifyUser`. */\nexport function hasIdentifyUser(\n runtime: CopilotRuntimeLike,\n): runtime is IdentifiedRuntimeLike {\n return typeof runtime.identifyUser === \"function\";\n}\n\nconst resolvedUsers = new WeakMap<\n Request,\n Promise<CopilotRuntimeUser | Response>\n>();\n\n/**\n * Resolves the request's user through `identifyUser`, once per request, for\n * both runtime kinds: the Intelligence runtime and an SSE runtime with\n * `identifyUser` (local Thread ownership). Only the Intelligence runtime\n * needs the user's `name`; an SSE runtime needs the `id` alone.\n *\n * A callback that throws gets a 500 on every route.\n */\nexport async function resolveIntelligenceUser(params: {\n runtime: CopilotIntelligenceRuntimeLike | IdentifiedRuntimeLike;\n request: Request;\n}): Promise<CopilotRuntimeUser | Response> {\n const { runtime, request } = params;\n\n const existing = resolvedUsers.get(request);\n if (existing) return existing;\n\n const resolution = resolveUser(runtime, request);\n resolvedUsers.set(request, resolution);\n return resolution;\n}\n\nasync function resolveUser(\n runtime: CopilotRuntimeLike,\n request: Request,\n): Promise<CopilotRuntimeUser | Response> {\n if (!hasIdentifyUser(runtime)) {\n console.error(\"Error identifying user: identifyUser is not configured\");\n return errorResponse(\"Failed to identify user\", 500);\n }\n try {\n const user = await runtime.identifyUser(request);\n if (!isValidIdentifier(user?.id)) {\n return errorResponse(\"identifyUser must return a valid user id\", 400);\n }\n const hasName =\n typeof user?.name === \"string\" && user.name.trim().length > 0;\n if (!hasName && isIntelligenceRuntime(runtime)) {\n return errorResponse(\"identifyUser must return a valid user name\", 400);\n }\n\n return { id: user.id, name: hasName ? user.name : user.id };\n } catch (error) {\n console.error(\"Error identifying user:\", error);\n return errorResponse(\"Failed to identify user\", 500);\n }\n}\n"],"mappings":";;;;;;;AAgBA,SAAgB,gBACd,SACkC;AAClC,QAAO,OAAO,QAAQ,iBAAiB;;AAGzC,MAAM,gCAAgB,IAAI,SAGvB;;;;;;;;;AAUH,eAAsB,wBAAwB,QAGH;CACzC,MAAM,EAAE,SAAS,YAAY;CAE7B,MAAM,WAAW,cAAc,IAAI,QAAQ;AAC3C,KAAI,SAAU,QAAO;CAErB,MAAM,aAAa,YAAY,SAAS,QAAQ;AAChD,eAAc,IAAI,SAAS,WAAW;AACtC,QAAO;;AAGT,eAAe,YACb,SACA,SACwC;AACxC,KAAI,CAAC,gBAAgB,QAAQ,EAAE;AAC7B,UAAQ,MAAM,yDAAyD;AACvE,SAAO,cAAc,2BAA2B,IAAI;;AAEtD,KAAI;EACF,MAAM,OAAO,MAAM,QAAQ,aAAa,QAAQ;AAChD,MAAI,CAAC,kBAAkB,MAAM,GAAG,CAC9B,QAAO,cAAc,4CAA4C,IAAI;EAEvE,MAAM,UACJ,OAAO,MAAM,SAAS,YAAY,KAAK,KAAK,MAAM,CAAC,SAAS;AAC9D,MAAI,CAAC,WAAW,sBAAsB,QAAQ,CAC5C,QAAO,cAAc,8CAA8C,IAAI;AAGzE,SAAO;GAAE,IAAI,KAAK;GAAI,MAAM,UAAU,KAAK,OAAO,KAAK;GAAI;UACpD,OAAO;AACd,UAAQ,MAAM,2BAA2B,MAAM;AAC/C,SAAO,cAAc,2BAA2B,IAAI"}