@copilotkit/runtime 1.55.3 → 1.56.1

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 (169) hide show
  1. package/dist/agent/converters/tanstack.cjs.map +1 -1
  2. package/dist/agent/converters/tanstack.d.cts +6 -19
  3. package/dist/agent/converters/tanstack.d.cts.map +1 -1
  4. package/dist/agent/converters/tanstack.d.mts +6 -19
  5. package/dist/agent/converters/tanstack.d.mts.map +1 -1
  6. package/dist/agent/converters/tanstack.mjs.map +1 -1
  7. package/dist/agent/index.cjs +16 -2
  8. package/dist/agent/index.cjs.map +1 -1
  9. package/dist/agent/index.d.cts +12 -1
  10. package/dist/agent/index.d.cts.map +1 -1
  11. package/dist/agent/index.d.mts +12 -1
  12. package/dist/agent/index.d.mts.map +1 -1
  13. package/dist/agent/index.mjs +16 -2
  14. package/dist/agent/index.mjs.map +1 -1
  15. package/dist/index.cjs +1 -1
  16. package/dist/index.d.cts +3 -2
  17. package/dist/index.d.mts +3 -2
  18. package/dist/index.mjs +1 -1
  19. package/dist/lib/index.cjs +1 -1
  20. package/dist/lib/index.d.cts +2 -1
  21. package/dist/lib/index.d.cts.map +1 -1
  22. package/dist/lib/index.d.mts +2 -1
  23. package/dist/lib/index.d.mts.map +1 -1
  24. package/dist/lib/index.mjs +1 -1
  25. package/dist/lib/integrations/node-http/index.cjs +4 -1
  26. package/dist/lib/integrations/node-http/index.cjs.map +1 -1
  27. package/dist/lib/integrations/node-http/index.d.cts.map +1 -1
  28. package/dist/lib/integrations/node-http/index.d.mts.map +1 -1
  29. package/dist/lib/integrations/node-http/index.mjs +4 -1
  30. package/dist/lib/integrations/node-http/index.mjs.map +1 -1
  31. package/dist/lib/integrations/shared.cjs +1 -1
  32. package/dist/lib/integrations/shared.d.cts +1 -1
  33. package/dist/lib/integrations/shared.d.mts +1 -1
  34. package/dist/lib/integrations/shared.mjs +1 -1
  35. package/dist/lib/runtime/copilot-runtime.cjs +25 -5
  36. package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
  37. package/dist/lib/runtime/copilot-runtime.d.cts +15 -3
  38. package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
  39. package/dist/lib/runtime/copilot-runtime.d.mts +15 -3
  40. package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
  41. package/dist/lib/runtime/copilot-runtime.mjs +25 -5
  42. package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
  43. package/dist/lib/runtime/mcp-tools-utils.cjs +21 -4
  44. package/dist/lib/runtime/mcp-tools-utils.cjs.map +1 -1
  45. package/dist/lib/runtime/mcp-tools-utils.d.cts.map +1 -1
  46. package/dist/lib/runtime/mcp-tools-utils.d.mts.map +1 -1
  47. package/dist/lib/runtime/mcp-tools-utils.mjs +21 -4
  48. package/dist/lib/runtime/mcp-tools-utils.mjs.map +1 -1
  49. package/dist/package.cjs +6 -5
  50. package/dist/package.mjs +6 -5
  51. package/dist/service-adapters/anthropic/anthropic-adapter.cjs +11 -3
  52. package/dist/service-adapters/anthropic/anthropic-adapter.cjs.map +1 -1
  53. package/dist/service-adapters/anthropic/anthropic-adapter.d.cts +6 -0
  54. package/dist/service-adapters/anthropic/anthropic-adapter.d.cts.map +1 -1
  55. package/dist/service-adapters/anthropic/anthropic-adapter.d.mts +6 -0
  56. package/dist/service-adapters/anthropic/anthropic-adapter.d.mts.map +1 -1
  57. package/dist/service-adapters/anthropic/anthropic-adapter.mjs +11 -3
  58. package/dist/service-adapters/anthropic/anthropic-adapter.mjs.map +1 -1
  59. package/dist/service-adapters/anthropic/utils.cjs +27 -1
  60. package/dist/service-adapters/anthropic/utils.cjs.map +1 -1
  61. package/dist/service-adapters/anthropic/utils.mjs +27 -1
  62. package/dist/service-adapters/anthropic/utils.mjs.map +1 -1
  63. package/dist/service-adapters/langchain/utils.cjs +1 -1
  64. package/dist/service-adapters/langchain/utils.cjs.map +1 -1
  65. package/dist/service-adapters/langchain/utils.mjs +1 -1
  66. package/dist/service-adapters/langchain/utils.mjs.map +1 -1
  67. package/dist/service-adapters/openai/openai-adapter.cjs +3 -2
  68. package/dist/service-adapters/openai/openai-adapter.cjs.map +1 -1
  69. package/dist/service-adapters/openai/openai-adapter.d.cts +6 -0
  70. package/dist/service-adapters/openai/openai-adapter.d.cts.map +1 -1
  71. package/dist/service-adapters/openai/openai-adapter.d.mts +6 -0
  72. package/dist/service-adapters/openai/openai-adapter.d.mts.map +1 -1
  73. package/dist/service-adapters/openai/openai-adapter.mjs +4 -3
  74. package/dist/service-adapters/openai/openai-adapter.mjs.map +1 -1
  75. package/dist/service-adapters/openai/openai-assistant-adapter.cjs +8 -9
  76. package/dist/service-adapters/openai/openai-assistant-adapter.cjs.map +1 -1
  77. package/dist/service-adapters/openai/openai-assistant-adapter.d.cts.map +1 -1
  78. package/dist/service-adapters/openai/openai-assistant-adapter.d.mts.map +1 -1
  79. package/dist/service-adapters/openai/openai-assistant-adapter.mjs +9 -10
  80. package/dist/service-adapters/openai/openai-assistant-adapter.mjs.map +1 -1
  81. package/dist/service-adapters/openai/utils.cjs +53 -0
  82. package/dist/service-adapters/openai/utils.cjs.map +1 -1
  83. package/dist/service-adapters/openai/utils.mjs +51 -1
  84. package/dist/service-adapters/openai/utils.mjs.map +1 -1
  85. package/dist/v2/index.cjs +1 -0
  86. package/dist/v2/index.d.cts +3 -3
  87. package/dist/v2/index.d.mts +3 -3
  88. package/dist/v2/index.mjs +2 -2
  89. package/dist/v2/runtime/core/middleware-sse-parser.cjs +5 -2
  90. package/dist/v2/runtime/core/middleware-sse-parser.cjs.map +1 -1
  91. package/dist/v2/runtime/core/middleware-sse-parser.mjs +5 -2
  92. package/dist/v2/runtime/core/middleware-sse-parser.mjs.map +1 -1
  93. package/dist/v2/runtime/core/runtime.cjs +25 -0
  94. package/dist/v2/runtime/core/runtime.cjs.map +1 -1
  95. package/dist/v2/runtime/core/runtime.d.cts +53 -4
  96. package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
  97. package/dist/v2/runtime/core/runtime.d.mts +53 -4
  98. package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
  99. package/dist/v2/runtime/core/runtime.mjs +26 -2
  100. package/dist/v2/runtime/core/runtime.mjs.map +1 -1
  101. package/dist/v2/runtime/handlers/get-runtime-info.cjs +18 -10
  102. package/dist/v2/runtime/handlers/get-runtime-info.cjs.map +1 -1
  103. package/dist/v2/runtime/handlers/get-runtime-info.mjs +19 -11
  104. package/dist/v2/runtime/handlers/get-runtime-info.mjs.map +1 -1
  105. package/dist/v2/runtime/handlers/handle-connect.cjs +1 -1
  106. package/dist/v2/runtime/handlers/handle-connect.cjs.map +1 -1
  107. package/dist/v2/runtime/handlers/handle-connect.mjs +1 -1
  108. package/dist/v2/runtime/handlers/handle-connect.mjs.map +1 -1
  109. package/dist/v2/runtime/handlers/handle-run.cjs +8 -2
  110. package/dist/v2/runtime/handlers/handle-run.cjs.map +1 -1
  111. package/dist/v2/runtime/handlers/handle-run.mjs +8 -2
  112. package/dist/v2/runtime/handlers/handle-run.mjs.map +1 -1
  113. package/dist/v2/runtime/handlers/handle-stop.cjs +2 -1
  114. package/dist/v2/runtime/handlers/handle-stop.cjs.map +1 -1
  115. package/dist/v2/runtime/handlers/handle-stop.mjs +2 -1
  116. package/dist/v2/runtime/handlers/handle-stop.mjs.map +1 -1
  117. package/dist/v2/runtime/handlers/intelligence/thread-names.cjs +1 -1
  118. package/dist/v2/runtime/handlers/intelligence/thread-names.cjs.map +1 -1
  119. package/dist/v2/runtime/handlers/intelligence/thread-names.mjs +1 -1
  120. package/dist/v2/runtime/handlers/intelligence/thread-names.mjs.map +1 -1
  121. package/dist/v2/runtime/handlers/shared/agent-utils.cjs +3 -2
  122. package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -1
  123. package/dist/v2/runtime/handlers/shared/agent-utils.mjs +3 -2
  124. package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -1
  125. package/dist/v2/runtime/handlers/shared/sse-response.cjs +40 -1
  126. package/dist/v2/runtime/handlers/shared/sse-response.cjs.map +1 -1
  127. package/dist/v2/runtime/handlers/shared/sse-response.mjs +40 -1
  128. package/dist/v2/runtime/handlers/shared/sse-response.mjs.map +1 -1
  129. package/dist/v2/runtime/handlers/sse/run.cjs +3 -1
  130. package/dist/v2/runtime/handlers/sse/run.cjs.map +1 -1
  131. package/dist/v2/runtime/handlers/sse/run.mjs +3 -1
  132. package/dist/v2/runtime/handlers/sse/run.mjs.map +1 -1
  133. package/dist/v2/runtime/index.d.cts +1 -1
  134. package/dist/v2/runtime/index.d.mts +1 -1
  135. package/package.json +7 -6
  136. package/src/agent/__tests__/capabilities.test.ts +81 -0
  137. package/src/agent/__tests__/provider-id-collision.test.ts +195 -0
  138. package/src/agent/converters/tanstack.ts +15 -7
  139. package/src/agent/index.ts +52 -11
  140. package/src/lib/integrations/node-http/__tests__/request-duck-type.test.ts +66 -0
  141. package/src/lib/integrations/node-http/index.ts +15 -1
  142. package/src/lib/runtime/__tests__/mcp-tools-utils.test.ts +30 -1
  143. package/src/lib/runtime/__tests__/on-after-request.test.ts +122 -0
  144. package/src/lib/runtime/__tests__/v1-agent-factory.test.ts +109 -0
  145. package/src/lib/runtime/copilot-runtime.ts +54 -5
  146. package/src/lib/runtime/mcp-tools-utils.ts +41 -6
  147. package/src/service-adapters/anthropic/anthropic-adapter.ts +22 -2
  148. package/src/service-adapters/anthropic/utils.ts +60 -1
  149. package/src/service-adapters/langchain/utils.ts +1 -1
  150. package/src/service-adapters/openai/__tests__/openai-v5-compat.test.ts +177 -0
  151. package/src/service-adapters/openai/openai-adapter.ts +17 -2
  152. package/src/service-adapters/openai/openai-assistant-adapter.ts +7 -9
  153. package/src/service-adapters/openai/utils.ts +100 -0
  154. package/src/v2/runtime/__tests__/agents-factory.test.ts +136 -0
  155. package/src/v2/runtime/__tests__/debug-sse-response.test.ts +302 -0
  156. package/src/v2/runtime/__tests__/get-runtime-info.test.ts +134 -1
  157. package/src/v2/runtime/__tests__/middleware-sse-parser.test.ts +50 -0
  158. package/src/v2/runtime/core/middleware-sse-parser.ts +12 -2
  159. package/src/v2/runtime/core/runtime.ts +90 -2
  160. package/src/v2/runtime/handlers/get-runtime-info.ts +33 -8
  161. package/src/v2/runtime/handlers/handle-connect.ts +1 -1
  162. package/src/v2/runtime/handlers/handle-run.ts +16 -2
  163. package/src/v2/runtime/handlers/handle-stop.ts +2 -1
  164. package/src/v2/runtime/handlers/intelligence/thread-names.ts +1 -1
  165. package/src/v2/runtime/handlers/shared/agent-utils.ts +3 -2
  166. package/src/v2/runtime/handlers/shared/sse-response.ts +69 -0
  167. package/src/v2/runtime/handlers/sse/run.ts +9 -0
  168. package/tests/service-adapters/anthropic/anthropic-adapter.test.ts +268 -0
  169. package/tests/service-adapters/anthropic/utils-token-trimming.test.ts +301 -0
@@ -1,9 +1,10 @@
1
1
 
2
2
  import { AfterRequestMiddleware, BeforeRequestMiddleware } from "./middleware.cjs";
3
+ import { CopilotRuntimeLogger } from "../../../lib/logger.cjs";
3
4
  import { TranscriptionService } from "../transcription-service/transcription-service.cjs";
4
5
  import { AgentRunner } from "../runner/agent-runner.cjs";
5
6
  import { CopilotKitIntelligence } from "../intelligence-platform/client.cjs";
6
- import { MaybePromise, NonEmptyRecord, RuntimeMode } from "@copilotkit/shared";
7
+ import { DebugConfig, MaybePromise, NonEmptyRecord, ResolvedDebugConfig, RuntimeMode } from "@copilotkit/shared";
7
8
  import { LicenseChecker } from "@copilotkit/license-verifier";
8
9
  import { AbstractAgent } from "@ag-ui/client";
9
10
  import { MCPClientConfig } from "@ag-ui/mcp-apps-middleware";
@@ -35,9 +36,49 @@ interface CopilotRuntimeMiddlewares {
35
36
  /** Auto-apply OpenGenerativeUIMiddleware to agents at run time. */
36
37
  openGenerativeUI?: OpenGenerativeUIConfig;
37
38
  }
39
+ /**
40
+ * Context passed to agent factory functions for per-request agent resolution.
41
+ */
42
+ interface AgentFactoryContext {
43
+ /** The incoming HTTP request. */
44
+ request: Request;
45
+ }
46
+ /**
47
+ * A function that dynamically creates agents on a per-request basis.
48
+ * Useful for multi-tenant scenarios or request-scoped agent configuration.
49
+ */
50
+ type AgentsFactory = (ctx: AgentFactoryContext) => MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;
51
+ /**
52
+ * Agents can be provided as:
53
+ * - A static record of agents
54
+ * - A Promise that resolves to a record of agents
55
+ * - A factory function that receives request context and returns agents (or a Promise of agents)
56
+ */
57
+ type AgentsConfig = MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>> | AgentsFactory;
58
+ /**
59
+ * Resolve an AgentsConfig value to a concrete record of agents.
60
+ * If the config is a factory function, it is called with the given request context.
61
+ * Otherwise it is awaited directly (static record or Promise).
62
+ */
63
+ declare function resolveAgents(agents: AgentsConfig, request?: Request): Promise<Record<string, AbstractAgent>>;
38
64
  interface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {
39
- /** Map of available agents (loaded lazily is fine). */
40
- agents: MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;
65
+ /**
66
+ * Map of available agents, or a factory function for per-request agent resolution.
67
+ *
68
+ * Static record:
69
+ * ```ts
70
+ * agents: { support: new SupportAgent(), technical: new TechnicalAgent() }
71
+ * ```
72
+ *
73
+ * Factory function (called per-request):
74
+ * ```ts
75
+ * agents: ({ request }) => {
76
+ * const tenantId = request.headers.get("x-tenant-id");
77
+ * return { default: createAgentForTenant(tenantId) };
78
+ * }
79
+ * ```
80
+ */
81
+ agents: AgentsConfig;
41
82
  /** Optional transcription service for audio processing. */
42
83
  transcriptionService?: TranscriptionService;
43
84
  /** Optional *before* middleware – callback function or webhook URL. */
@@ -46,6 +87,8 @@ interface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {
46
87
  afterRequestMiddleware?: AfterRequestMiddleware;
47
88
  /** Signed license token for server-side feature verification. Falls back to COPILOTKIT_LICENSE_TOKEN env var. */
48
89
  licenseToken?: string;
90
+ /** Enable debug logging for the event pipeline. */
91
+ debug?: DebugConfig;
49
92
  }
50
93
  interface CopilotRuntimeUser {
51
94
  id: string;
@@ -89,6 +132,8 @@ interface CopilotRuntimeLike {
89
132
  identifyUser?: IdentifyUserCallback;
90
133
  mode: RuntimeMode;
91
134
  licenseChecker?: LicenseChecker;
135
+ debug: ResolvedDebugConfig;
136
+ debugLogger?: CopilotRuntimeLogger;
92
137
  }
93
138
  interface CopilotSseRuntimeLike extends CopilotRuntimeLike {
94
139
  intelligence?: undefined;
@@ -113,6 +158,8 @@ declare abstract class BaseCopilotRuntime implements CopilotRuntimeLike {
113
158
  mcpApps: CopilotRuntimeOptions["mcpApps"];
114
159
  openGenerativeUI: CopilotRuntimeOptions["openGenerativeUI"];
115
160
  licenseChecker?: LicenseChecker;
161
+ debug: ResolvedDebugConfig;
162
+ debugLogger?: CopilotRuntimeLogger;
116
163
  abstract readonly intelligence?: CopilotKitIntelligence;
117
164
  abstract readonly mode: RuntimeMode;
118
165
  constructor(options: BaseCopilotRuntimeOptions, runner: AgentRunner);
@@ -160,7 +207,9 @@ declare class CopilotRuntime implements CopilotRuntimeLike {
160
207
  get lockHeartbeatIntervalSeconds(): number | undefined;
161
208
  get mode(): RuntimeMode;
162
209
  get licenseChecker(): LicenseChecker;
210
+ get debug(): ResolvedDebugConfig;
211
+ get debugLogger(): CopilotRuntimeLogger | undefined;
163
212
  }
164
213
  //#endregion
165
- export { CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, OpenGenerativeUIConfig, OpenGenerativeUIOptions, VERSION, isIntelligenceRuntime };
214
+ export { AgentFactoryContext, AgentsConfig, AgentsFactory, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, OpenGenerativeUIConfig, OpenGenerativeUIOptions, VERSION, isIntelligenceRuntime, resolveAgents };
166
215
  //# sourceMappingURL=runtime.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.cts","names":[],"sources":["../../../../src/v2/runtime/core/runtime.ts"],"mappings":";;;;;;;;;;;;cAyBa,OAAA;AAAA,UAEH,mCAAA;EAFG;EAIX,MAAA;AAAA;AAAA,KAGU,mBAAA,GAAsB,eAAA;EAPA,uFAShC,OAAA;AAAA;AAAA,UAGe,aAAA;EARf;EAUA,OAAA,EAAS,mBAAA;AAAA;AAAA,UAGM,uBAAA,SAAgC,mCAAA;AAAA,KAErC,sBAAA,aAAmC,uBAAA;AAAA,UAErC,yBAAA;EATO;;;;EAcf,IAAA,GAAO,mCAAA,GAAsC,oBAAA;EAT9B;EAWf,OAAA,GAAU,aAAA;;EAEV,gBAAA,GAAmB,sBAAA;AAAA;AAAA,UAGX,yBAAA,SAAkC,yBAAA;EAdV;EAgBhC,MAAA,EAAQ,YAAA,CAAa,cAAA,CAAe,MAAA,SAAe,aAAA;EAhBN;EAkB7C,oBAAA,GAAuB,oBAAA;EAhBf;EAkBR,uBAAA,GAA0B,uBAAA;;EAE1B,sBAAA,GAAyB,sBAAA;EAfoB;EAiB7C,YAAA;AAAA;AAAA,UAGe,kBAAA;EACf,EAAA;AAAA;AAAA,KAGU,oBAAA,IACV,OAAA,EAAS,OAAA,KACN,YAAA,CAAa,kBAAA;AAAA,UAED,wBAAA,SAAiC,yBAAA;EA1BhD;EA4BA,MAAA,GAAS,WAAA;EACT,YAAA;EACA,mBAAA;AAAA;AAAA,UAGe,iCAAA,SAA0C,yBAAA;EA5BjD;EA8BR,YAAA,EAAc,sBAAA;;EAEd,YAAA,EAAc,oBAAA;EA9BsB;EAgCpC,mB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A,EAAS,wBAAA;AAAA;AAAA,cAKV,0BAAA,SACH,kBAAA,YACG,8BAAA;EAAA,SAEF,YAAA,EAAc,sBAAA;EAAA,SACd,YAAA,EAAc,oBAAA;EAAA,SACd,mBAAA;EAAA,SACA,cAAA;EAAA,SACA,aAAA;EAAA,SACA,4BAAA;EAAA,SACA,IAAA;EA1HgD;EAAA,gBA6HzC,oBAAA;EA7HkE;EAAA,gBA+HlE,8BAAA;cAEJ,OAAA,EAAS,iCAAA;AAAA;AAAA,iBAgCP,qBAAA,CACd,OAAA,EAAS,kBAAA,GACR,OAAA,IAAW,8BAAA;;;;;cAQD,cAAA,YAA0B,kBAAA;EAAA,QAC7B,QAAA;cAEI,OAAA,EAAS,qBAAA;EAAA,IAMjB,MAAA,CAAA,GAAU,qBAAA;EAAA,IAIV,oBAAA,CAAA,GAAwB,qBAAA;EAAA,IAIxB,uBAAA,CAAA,GAA2B,qBAAA;EAAA,IAI3B,sBAAA,CAAA,GAA0B,qBAAA;EAAA,IAI1B,MAAA,CAAA,GAAU,WAAA;EAAA,IAIV,IAAA,CAAA,GAAQ,qBAAA;EAAA,IAIR,OAAA,CAAA,GAAW,qBAAA;EAAA,IAIX,gBAAA,CAAA,GAAoB,qBAAA;EAAA,IAIpB,YAAA,CAAA,GAAgB,sBAAA;EAAA,IAIhB,mBAAA,CAAA;EAAA,IAMA,YAAA,CAAA,GAAgB,oBAAA;EAAA,IAMhB,cAAA,CAAA;EAAA,IAMA,aAAA,CAAA;EAAA,IAMA,4BAAA,CAAA;EAAA,IAMA,IAAA,CAAA,GAAQ,WAAA;EAAA,IAIR,cAAA,CAAA,GAAc,cAAA;EAAA,IAId,KAAA,CAAA,GAAS,mBAAA;EAAA,IAIT,WAAA,CAAA,GAAe,oBAAA;AAAA"}
@@ -1,10 +1,11 @@
1
1
  import "reflect-metadata";
2
2
  import { AfterRequestMiddleware, BeforeRequestMiddleware } from "./middleware.mjs";
3
+ import { CopilotRuntimeLogger } from "../../../lib/logger.mjs";
3
4
  import { TranscriptionService } from "../transcription-service/transcription-service.mjs";
4
5
  import { AgentRunner } from "../runner/agent-runner.mjs";
5
6
  import { CopilotKitIntelligence } from "../intelligence-platform/client.mjs";
6
7
  import "../intelligence-platform/index.mjs";
7
- import { MaybePromise, NonEmptyRecord, RuntimeMode } from "@copilotkit/shared";
8
+ import { DebugConfig, MaybePromise, NonEmptyRecord, ResolvedDebugConfig, RuntimeMode } from "@copilotkit/shared";
8
9
  import { LicenseChecker } from "@copilotkit/license-verifier";
9
10
  import { AbstractAgent } from "@ag-ui/client";
10
11
  import { A2UIMiddlewareConfig } from "@ag-ui/a2ui-middleware";
@@ -36,9 +37,49 @@ interface CopilotRuntimeMiddlewares {
36
37
  /** Auto-apply OpenGenerativeUIMiddleware to agents at run time. */
37
38
  openGenerativeUI?: OpenGenerativeUIConfig;
38
39
  }
40
+ /**
41
+ * Context passed to agent factory functions for per-request agent resolution.
42
+ */
43
+ interface AgentFactoryContext {
44
+ /** The incoming HTTP request. */
45
+ request: Request;
46
+ }
47
+ /**
48
+ * A function that dynamically creates agents on a per-request basis.
49
+ * Useful for multi-tenant scenarios or request-scoped agent configuration.
50
+ */
51
+ type AgentsFactory = (ctx: AgentFactoryContext) => MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;
52
+ /**
53
+ * Agents can be provided as:
54
+ * - A static record of agents
55
+ * - A Promise that resolves to a record of agents
56
+ * - A factory function that receives request context and returns agents (or a Promise of agents)
57
+ */
58
+ type AgentsConfig = MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>> | AgentsFactory;
59
+ /**
60
+ * Resolve an AgentsConfig value to a concrete record of agents.
61
+ * If the config is a factory function, it is called with the given request context.
62
+ * Otherwise it is awaited directly (static record or Promise).
63
+ */
64
+ declare function resolveAgents(agents: AgentsConfig, request?: Request): Promise<Record<string, AbstractAgent>>;
39
65
  interface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {
40
- /** Map of available agents (loaded lazily is fine). */
41
- agents: MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;
66
+ /**
67
+ * Map of available agents, or a factory function for per-request agent resolution.
68
+ *
69
+ * Static record:
70
+ * ```ts
71
+ * agents: { support: new SupportAgent(), technical: new TechnicalAgent() }
72
+ * ```
73
+ *
74
+ * Factory function (called per-request):
75
+ * ```ts
76
+ * agents: ({ request }) => {
77
+ * const tenantId = request.headers.get("x-tenant-id");
78
+ * return { default: createAgentForTenant(tenantId) };
79
+ * }
80
+ * ```
81
+ */
82
+ agents: AgentsConfig;
42
83
  /** Optional transcription service for audio processing. */
43
84
  transcriptionService?: TranscriptionService;
44
85
  /** Optional *before* middleware – callback function or webhook URL. */
@@ -47,6 +88,8 @@ interface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {
47
88
  afterRequestMiddleware?: AfterRequestMiddleware;
48
89
  /** Signed license token for server-side feature verification. Falls back to COPILOTKIT_LICENSE_TOKEN env var. */
49
90
  licenseToken?: string;
91
+ /** Enable debug logging for the event pipeline. */
92
+ debug?: DebugConfig;
50
93
  }
51
94
  interface CopilotRuntimeUser {
52
95
  id: string;
@@ -90,6 +133,8 @@ interface CopilotRuntimeLike {
90
133
  identifyUser?: IdentifyUserCallback;
91
134
  mode: RuntimeMode;
92
135
  licenseChecker?: LicenseChecker;
136
+ debug: ResolvedDebugConfig;
137
+ debugLogger?: CopilotRuntimeLogger;
93
138
  }
94
139
  interface CopilotSseRuntimeLike extends CopilotRuntimeLike {
95
140
  intelligence?: undefined;
@@ -114,6 +159,8 @@ declare abstract class BaseCopilotRuntime implements CopilotRuntimeLike {
114
159
  mcpApps: CopilotRuntimeOptions["mcpApps"];
115
160
  openGenerativeUI: CopilotRuntimeOptions["openGenerativeUI"];
116
161
  licenseChecker?: LicenseChecker;
162
+ debug: ResolvedDebugConfig;
163
+ debugLogger?: CopilotRuntimeLogger;
117
164
  abstract readonly intelligence?: CopilotKitIntelligence;
118
165
  abstract readonly mode: RuntimeMode;
119
166
  constructor(options: BaseCopilotRuntimeOptions, runner: AgentRunner);
@@ -161,7 +208,9 @@ declare class CopilotRuntime implements CopilotRuntimeLike {
161
208
  get lockHeartbeatIntervalSeconds(): number | undefined;
162
209
  get mode(): RuntimeMode;
163
210
  get licenseChecker(): LicenseChecker;
211
+ get debug(): ResolvedDebugConfig;
212
+ get debugLogger(): CopilotRuntimeLogger | undefined;
164
213
  }
165
214
  //#endregion
166
- export { CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, OpenGenerativeUIConfig, OpenGenerativeUIOptions, VERSION, isIntelligenceRuntime };
215
+ export { AgentFactoryContext, AgentsConfig, AgentsFactory, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, OpenGenerativeUIConfig, OpenGenerativeUIOptions, VERSION, isIntelligenceRuntime, resolveAgents };
167
216
  //# sourceMappingURL=runtime.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.mts","names":[],"sources":["../../../../src/v2/runtime/core/runtime.ts"],"mappings":";;;;;;;;;;;;;cAyBa,OAAA;AAAA,UAEH,mCAAA;;EAER,MAAA;AAAA;AAAA,KAGU,mBAAA,GAAsB,eAAA;EAPA,uFAShC,OAAA;AAAA;AAAA,UAGe,aAAA;;EAEf,OAAA,EAAS,mBAAA;AAAA;AAAA,UAGM,uBAAA,SAAgC,mCAAA;AAAA,KAErC,sBAAA,aAAmC,uBAAA;AAAA,UAErC,yBAAA;EAZD;AAGT;;;EAcE,IAAA,GAA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;EAAA,IAI3B,sBAAA,CAAA,GAA0B,qBAAA;EAAA,IAI1B,MAAA,CAAA,GAAU,WAAA;EAAA,IAIV,IAAA,CAAA,GAAQ,qBAAA;EAAA,IAIR,OAAA,CAAA,GAAW,qBAAA;EAAA,IAIX,gBAAA,CAAA,GAAoB,qBAAA;EAAA,IAIpB,YAAA,CAAA,GAAgB,sBAAA;EAAA,IAIhB,mBAAA,CAAA;EAAA,IAMA,YAAA,CAAA,GAAgB,oBAAA;EAAA,IAMhB,cAAA,CAAA;EAAA,IAMA,aAAA,CAAA;EAAA,IAMA,4BAAA,CAAA;EAAA,IAMA,IAAA,CAAA,GAAQ,WAAA;EAAA,IAIR,cAAA,CAAA,GAAc,cAAA;EAAA,IAId,KAAA,CAAA,GAAS,mBAAA;EAAA,IAIT,WAAA,CAAA,GAAe,oBAAA;AAAA"}
@@ -1,14 +1,27 @@
1
1
  import "reflect-metadata";
2
2
  import { __toESM } from "../../../_virtual/_rolldown/runtime.mjs";
3
3
  import { require_package } from "../../../package.mjs";
4
+ import { createLogger } from "../../../lib/logger.mjs";
4
5
  import { InMemoryAgentRunner } from "../runner/in-memory.mjs";
5
6
  import { IntelligenceAgentRunner } from "../runner/intelligence.mjs";
6
- import { RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE } from "@copilotkit/shared";
7
+ import { RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, resolveDebugConfig } from "@copilotkit/shared";
7
8
  import { createLicenseChecker } from "@copilotkit/license-verifier";
8
9
 
9
10
  //#region src/v2/runtime/core/runtime.ts
10
11
  var import_package = /* @__PURE__ */ __toESM(require_package());
11
12
  const VERSION = import_package.default.version;
13
+ /**
14
+ * Resolve an AgentsConfig value to a concrete record of agents.
15
+ * If the config is a factory function, it is called with the given request context.
16
+ * Otherwise it is awaited directly (static record or Promise).
17
+ */
18
+ async function resolveAgents(agents, request) {
19
+ if (typeof agents === "function") {
20
+ if (!request) throw new Error("Agent factory function requires a request context, but none was provided.");
21
+ return agents({ request });
22
+ }
23
+ return agents;
24
+ }
12
25
  var BaseCopilotRuntime = class {
13
26
  constructor(options, runner) {
14
27
  const { agents, transcriptionService, beforeRequestMiddleware, afterRequestMiddleware, a2ui, mcpApps, openGenerativeUI } = options;
@@ -20,6 +33,11 @@ var BaseCopilotRuntime = class {
20
33
  this.mcpApps = mcpApps;
21
34
  this.openGenerativeUI = openGenerativeUI;
22
35
  this.runner = runner;
36
+ this.debug = resolveDebugConfig(options.debug);
37
+ if (this.debug.enabled) this.debugLogger = createLogger({
38
+ level: "debug",
39
+ component: "copilotkit-debug"
40
+ });
23
41
  }
24
42
  };
25
43
  var CopilotSseRuntime = class extends BaseCopilotRuntime {
@@ -115,8 +133,14 @@ var CopilotRuntime = class {
115
133
  get licenseChecker() {
116
134
  return this.delegate.licenseChecker;
117
135
  }
136
+ get debug() {
137
+ return this.delegate.debug;
138
+ }
139
+ get debugLogger() {
140
+ return this.delegate.debugLogger;
141
+ }
118
142
  };
119
143
 
120
144
  //#endregion
121
- export { CopilotIntelligenceRuntime, CopilotRuntime, CopilotSseRuntime, VERSION, isIntelligenceRuntime };
145
+ export { CopilotIntelligenceRuntime, CopilotRuntime, CopilotSseRuntime, VERSION, isIntelligenceRuntime, resolveAgents };
122
146
  //# sourceMappingURL=runtime.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.mjs","names":["pkg"],"sources":["../../../../src/v2/runtime/core/runtime.ts"],"sourcesContent":["import {\n MaybePromise,\n NonEmptyRecord,\n RuntimeMode,\n RUNTIME_MODE_SSE,\n RUNTIME_MODE_INTELLIGENCE,\n} from \"@copilotkit/shared\";\nimport {\n createLicenseChecker,\n type LicenseChecker,\n} from \"@copilotkit/license-verifier\";\nimport { AbstractAgent } from \"@ag-ui/client\";\nimport type { MCPClientConfig } from \"@ag-ui/mcp-apps-middleware\";\nimport { A2UIMiddlewareConfig } from \"@ag-ui/a2ui-middleware\";\nimport pkg from \"../../../../package.json\";\nimport type {\n BeforeRequestMiddleware,\n AfterRequestMiddleware,\n} from \"./middleware\";\nimport { TranscriptionService } from \"../transcription-service/transcription-service\";\nimport { AgentRunner } from \"../runner/agent-runner\";\nimport { InMemoryAgentRunner } from \"../runner/in-memory\";\nimport { IntelligenceAgentRunner } from \"../runner/intelligence\";\nimport { CopilotKitIntelligence } from \"../intelligence-platform\";\n\nexport const VERSION = pkg.version;\n\ninterface BaseCopilotRuntimeMiddlewareOptions {\n /** If set, middleware only applies to these named agents. Applies to all agents if omitted. */\n agents?: string[];\n}\n\nexport type McpAppsServerConfig = MCPClientConfig & {\n /** Agent to bind this server to. If omitted, the server is available to all agents. */\n agentId?: string;\n};\n\nexport interface McpAppsConfig {\n /** List of MCP server configurations. */\n servers: McpAppsServerConfig[];\n}\n\nexport interface OpenGenerativeUIOptions extends BaseCopilotRuntimeMiddlewareOptions {}\n\nexport type OpenGenerativeUIConfig = boolean | OpenGenerativeUIOptions;\n\ninterface CopilotRuntimeMiddlewares {\n /**\n * Auto-apply A2UIMiddleware to agents at run time.\n * Pass an object to enable and customise behaviour, or omit to disable.\n */\n a2ui?: BaseCopilotRuntimeMiddlewareOptions & A2UIMiddlewareConfig;\n /** Auto-apply MCPAppsMiddleware to agents at run time. */\n mcpApps?: McpAppsConfig;\n /** Auto-apply OpenGenerativeUIMiddleware to agents at run time. */\n openGenerativeUI?: OpenGenerativeUIConfig;\n}\n\ninterface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {\n /** Map of available agents (loaded lazily is fine). */\n agents: MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;\n /** Optional transcription service for audio processing. */\n transcriptionService?: TranscriptionService;\n /** Optional *before* middleware – callback function or webhook URL. */\n beforeRequestMiddleware?: BeforeRequestMiddleware;\n /** Optional *after* middleware – callback function or webhook URL. */\n afterRequestMiddleware?: AfterRequestMiddleware;\n /** Signed license token for server-side feature verification. Falls back to COPILOTKIT_LICENSE_TOKEN env var. */\n licenseToken?: string;\n}\n\nexport interface CopilotRuntimeUser {\n id: string;\n}\n\nexport type IdentifyUserCallback = (\n request: Request,\n) => MaybePromise<CopilotRuntimeUser>;\n\nexport interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** The runner to use for running agents in SSE mode. */\n runner?: AgentRunner;\n intelligence?: undefined;\n generateThreadNames?: undefined;\n}\n\nexport interface CopilotIntelligenceRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** Configures Intelligence mode for durable threads and realtime events. */\n intelligence: CopilotKitIntelligence;\n /** Resolves the authenticated user for intelligence requests. */\n identifyUser: IdentifyUserCallback;\n /** Auto-generate short names for newly created threads. */\n generateThreadNames?: boolean;\n /** Max delay (ms) for WebSocket reconnect backoff. @default 10_000 */\n maxReconnectMs?: number;\n /** Max delay (ms) for channel rejoin backoff. @default 30_000 */\n maxRejoinMs?: number;\n /** Lock TTL in seconds. Clamped to a maximum of 3600 (1 hour). @default 20 */\n lockTtlSeconds?: number;\n /** Custom Redis key prefix for the thread lock. */\n lockKeyPrefix?: string;\n /** Interval in seconds at which the runtime renews the thread lock. Clamped to a maximum of 3000 (50 minutes). @default 15 */\n lockHeartbeatIntervalSeconds?: number;\n}\n\nexport type CopilotRuntimeOptions =\n | CopilotSseRuntimeOptions\n | CopilotIntelligenceRuntimeOptions;\n\nexport interface CopilotRuntimeLike {\n agents: CopilotRuntimeOptions[\"agents\"];\n transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n runner: AgentRunner;\n a2ui: CopilotRuntimeOptions[\"a2ui\"];\n mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n openGenerativeUI: CopilotRuntimeOptions[\"openGenerativeUI\"];\n intelligence?: CopilotKitIntelligence;\n identifyUser?: IdentifyUserCallback;\n mode: RuntimeMode;\n licenseChecker?: LicenseChecker;\n}\n\nexport interface CopilotSseRuntimeLike extends CopilotRuntimeLike {\n intelligence?: undefined;\n mode: RUNTIME_MODE_SSE;\n}\n\nexport interface CopilotIntelligenceRuntimeLike extends CopilotRuntimeLike {\n intelligence: CopilotKitIntelligence;\n identifyUser: IdentifyUserCallback;\n generateThreadNames: boolean;\n lockTtlSeconds: number;\n lockKeyPrefix?: string;\n lockHeartbeatIntervalSeconds: number;\n mode: RUNTIME_MODE_INTELLIGENCE;\n}\n\nabstract class BaseCopilotRuntime implements CopilotRuntimeLike {\n public agents: CopilotRuntimeOptions[\"agents\"];\n public transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n public beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n public afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n public runner: AgentRunner;\n public a2ui: CopilotRuntimeOptions[\"a2ui\"];\n public mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n public openGenerativeUI: CopilotRuntimeOptions[\"openGenerativeUI\"];\n public licenseChecker?: LicenseChecker;\n\n abstract readonly intelligence?: CopilotKitIntelligence;\n abstract readonly mode: RuntimeMode;\n\n constructor(options: BaseCopilotRuntimeOptions, runner: AgentRunner) {\n const {\n agents,\n transcriptionService,\n beforeRequestMiddleware,\n afterRequestMiddleware,\n a2ui,\n mcpApps,\n openGenerativeUI,\n } = options;\n\n this.agents = agents;\n this.transcriptionService = transcriptionService;\n this.beforeRequestMiddleware = beforeRequestMiddleware;\n this.afterRequestMiddleware = afterRequestMiddleware;\n this.a2ui = a2ui || undefined;\n this.mcpApps = mcpApps;\n this.openGenerativeUI = openGenerativeUI;\n this.runner = runner;\n }\n}\n\nexport class CopilotSseRuntime\n extends BaseCopilotRuntime\n implements CopilotSseRuntimeLike\n{\n readonly intelligence = undefined;\n readonly mode = RUNTIME_MODE_SSE;\n\n constructor(options: CopilotSseRuntimeOptions) {\n super(options, options.runner ?? new InMemoryAgentRunner());\n }\n}\n\nexport class CopilotIntelligenceRuntime\n extends BaseCopilotRuntime\n implements CopilotIntelligenceRuntimeLike\n{\n readonly intelligence: CopilotKitIntelligence;\n readonly identifyUser: IdentifyUserCallback;\n readonly generateThreadNames: boolean;\n readonly lockTtlSeconds: number;\n readonly lockKeyPrefix?: string;\n readonly lockHeartbeatIntervalSeconds: number;\n readonly mode = RUNTIME_MODE_INTELLIGENCE;\n\n /** Maximum allowed lock TTL in seconds (1 hour). */\n static readonly MAX_LOCK_TTL_SECONDS = 3_600;\n /** Maximum allowed heartbeat interval in seconds (50 minutes). */\n static readonly MAX_HEARTBEAT_INTERVAL_SECONDS = 3_000;\n\n constructor(options: CopilotIntelligenceRuntimeOptions) {\n super(\n options,\n new IntelligenceAgentRunner({\n url: options.intelligence.ɵgetRunnerWsUrl(),\n authToken: options.intelligence.ɵgetRunnerAuthToken(),\n maxReconnectMs: options.maxReconnectMs,\n maxRejoinMs: options.maxRejoinMs,\n }),\n );\n this.intelligence = options.intelligence;\n this.identifyUser = options.identifyUser;\n this.generateThreadNames = options.generateThreadNames ?? true;\n this.licenseChecker = createLicenseChecker(options.licenseToken);\n this.lockTtlSeconds = Math.min(\n options.lockTtlSeconds ?? 20,\n CopilotIntelligenceRuntime.MAX_LOCK_TTL_SECONDS,\n );\n this.lockKeyPrefix = options.lockKeyPrefix;\n this.lockHeartbeatIntervalSeconds = Math.min(\n options.lockHeartbeatIntervalSeconds ?? 15,\n CopilotIntelligenceRuntime.MAX_HEARTBEAT_INTERVAL_SECONDS,\n );\n }\n}\n\nfunction hasIntelligenceOptions(\n options: CopilotRuntimeOptions,\n): options is CopilotIntelligenceRuntimeOptions {\n return \"intelligence\" in options && !!options.intelligence;\n}\n\nexport function isIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): runtime is CopilotIntelligenceRuntimeLike {\n return runtime.mode === RUNTIME_MODE_INTELLIGENCE && !!runtime.intelligence;\n}\n\n/**\n * Compatibility shim that preserves the legacy `CopilotRuntime` entrypoint.\n * New code should prefer `CopilotSseRuntime` or `CopilotIntelligenceRuntime`.\n */\nexport class CopilotRuntime implements CopilotRuntimeLike {\n private delegate: CopilotRuntimeLike;\n\n constructor(options: CopilotRuntimeOptions) {\n this.delegate = hasIntelligenceOptions(options)\n ? new CopilotIntelligenceRuntime(options)\n : new CopilotSseRuntime(options);\n }\n\n get agents(): CopilotRuntimeOptions[\"agents\"] {\n return this.delegate.agents;\n }\n\n get transcriptionService(): CopilotRuntimeOptions[\"transcriptionService\"] {\n return this.delegate.transcriptionService;\n }\n\n get beforeRequestMiddleware(): CopilotRuntimeOptions[\"beforeRequestMiddleware\"] {\n return this.delegate.beforeRequestMiddleware;\n }\n\n get afterRequestMiddleware(): CopilotRuntimeOptions[\"afterRequestMiddleware\"] {\n return this.delegate.afterRequestMiddleware;\n }\n\n get runner(): AgentRunner {\n return this.delegate.runner;\n }\n\n get a2ui(): CopilotRuntimeOptions[\"a2ui\"] {\n return this.delegate.a2ui;\n }\n\n get mcpApps(): CopilotRuntimeOptions[\"mcpApps\"] {\n return this.delegate.mcpApps;\n }\n\n get openGenerativeUI(): CopilotRuntimeOptions[\"openGenerativeUI\"] {\n return this.delegate.openGenerativeUI;\n }\n\n get intelligence(): CopilotKitIntelligence | undefined {\n return this.delegate.intelligence;\n }\n\n get generateThreadNames(): boolean | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.generateThreadNames\n : undefined;\n }\n\n get identifyUser(): IdentifyUserCallback | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.identifyUser\n : undefined;\n }\n\n get lockTtlSeconds(): number | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.lockTtlSeconds\n : undefined;\n }\n\n get lockKeyPrefix(): string | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.lockKeyPrefix\n : undefined;\n }\n\n get lockHeartbeatIntervalSeconds(): number | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.lockHeartbeatIntervalSeconds\n : undefined;\n }\n\n get mode(): Runtime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E,IAAa,iBAAb,MAA0D;CAGxD,YAAY,SAAgC;AAC1C,OAAK,WAAW,uBAAuB,QAAQ,GAC3C,IAAI,2BAA2B,QAAQ,GACvC,IAAI,kBAAkB,QAAQ;;CAGpC,IAAI,SAA0C;AAC5C,SAAO,KAAK,SAAS;;CAGvB,IAAI,uBAAsE;AACxE,SAAO,KAAK,SAAS;;CAGvB,IAAI,0BAA4E;AAC9E,SAAO,KAAK,SAAS;;CAGvB,IAAI,yBAA0E;AAC5E,SAAO,KAAK,SAAS;;CAGvB,IAAI,SAAsB;AACxB,SAAO,KAAK,SAAS;;CAGvB,IAAI,OAAsC;AACxC,SAAO,KAAK,SAAS;;CAGvB,IAAI,UAA4C;AAC9C,SAAO,KAAK,SAAS;;CAGvB,IAAI,mBAA8D;AAChE,SAAO,KAAK,SAAS;;CAGvB,IAAI,eAAmD;AACrD,SAAO,KAAK,SAAS;;CAGvB,IAAI,sBAA2C;AAC7C,SAAO,sBAAsB,KAAK,SAAS,GACvC,KAAK,SAAS,sBACd;;CAGN,IAAI,eAAiD;AACnD,SAAO,sBAAsB,KAAK,SAAS,GACvC,KAAK,SAAS,eACd;;CAGN,IAAI,iBAAqC;AACvC,SAAO,sBAAsB,KAAK,SAAS,GACvC,KAAK,SAAS,iBACd;;CAGN,IAAI,gBAAoC;AACtC,SAAO,sBAAsB,KAAK,SAAS,GACvC,KAAK,SAAS,gBACd;;CAGN,IAAI,+BAAmD;AACrD,SAAO,sBAAsB,KAAK,SAAS,GACvC,KAAK,SAAS,+BACd;;CAGN,IAAI,OAAoB;AACtB,SAAO,KAAK,SAAS;;CAGvB,IAAI,iBAAiB;AACnB,SAAO,KAAK,SAAS"}
1
+ {"version":3,"file":"runtime.mjs","names":["pkg"],"sources":["../../../../src/v2/runtime/core/runtime.ts"],"sourcesContent":["import {\n MaybePromise,\n NonEmptyRecord,\n RuntimeMode,\n RUNTIME_MODE_SSE,\n RUNTIME_MODE_INTELLIGENCE,\n} from \"@copilotkit/shared\";\nimport {\n createLicenseChecker,\n type LicenseChecker,\n} from \"@copilotkit/license-verifier\";\nimport {\n type ResolvedDebugConfig,\n resolveDebugConfig,\n type DebugConfig,\n} from \"@copilotkit/shared\";\nimport { AbstractAgent } from \"@ag-ui/client\";\nimport type { MCPClientConfig } from \"@ag-ui/mcp-apps-middleware\";\nimport { A2UIMiddlewareConfig } from \"@ag-ui/a2ui-middleware\";\nimport pkg from \"../../../../package.json\";\nimport type {\n BeforeRequestMiddleware,\n AfterRequestMiddleware,\n} from \"./middleware\";\nimport { createLogger, type CopilotRuntimeLogger } from \"../../../lib/logger\";\nimport { TranscriptionService } from \"../transcription-service/transcription-service\";\nimport { AgentRunner } from \"../runner/agent-runner\";\nimport { InMemoryAgentRunner } from \"../runner/in-memory\";\nimport { IntelligenceAgentRunner } from \"../runner/intelligence\";\nimport { CopilotKitIntelligence } from \"../intelligence-platform\";\n\nexport const VERSION = pkg.version;\n\ninterface BaseCopilotRuntimeMiddlewareOptions {\n /** If set, middleware only applies to these named agents. Applies to all agents if omitted. */\n agents?: string[];\n}\n\nexport type McpAppsServerConfig = MCPClientConfig & {\n /** Agent to bind this server to. If omitted, the server is available to all agents. */\n agentId?: string;\n};\n\nexport interface McpAppsConfig {\n /** List of MCP server configurations. */\n servers: McpAppsServerConfig[];\n}\n\nexport interface OpenGenerativeUIOptions extends BaseCopilotRuntimeMiddlewareOptions {}\n\nexport type OpenGenerativeUIConfig = boolean | OpenGenerativeUIOptions;\n\ninterface CopilotRuntimeMiddlewares {\n /**\n * Auto-apply A2UIMiddleware to agents at run time.\n * Pass an object to enable and customise behaviour, or omit to disable.\n */\n a2ui?: BaseCopilotRuntimeMiddlewareOptions & A2UIMiddlewareConfig;\n /** Auto-apply MCPAppsMiddleware to agents at run time. */\n mcpApps?: McpAppsConfig;\n /** Auto-apply OpenGenerativeUIMiddleware to agents at run time. */\n openGenerativeUI?: OpenGenerativeUIConfig;\n}\n\n/**\n * Context passed to agent factory functions for per-request agent resolution.\n */\nexport interface AgentFactoryContext {\n /** The incoming HTTP request. */\n request: Request;\n}\n\n/**\n * A function that dynamically creates agents on a per-request basis.\n * Useful for multi-tenant scenarios or request-scoped agent configuration.\n */\nexport type AgentsFactory = (\n ctx: AgentFactoryContext,\n) => MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;\n\n/**\n * Agents can be provided as:\n * - A static record of agents\n * - A Promise that resolves to a record of agents\n * - A factory function that receives request context and returns agents (or a Promise of agents)\n */\nexport type AgentsConfig =\n | MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>\n | AgentsFactory;\n\n/**\n * Resolve an AgentsConfig value to a concrete record of agents.\n * If the config is a factory function, it is called with the given request context.\n * Otherwise it is awaited directly (static record or Promise).\n */\nexport async function resolveAgents(\n agents: AgentsConfig,\n request?: Request,\n): Promise<Record<string, AbstractAgent>> {\n if (typeof agents === \"function\") {\n if (!request) {\n throw new Error(\n \"Agent factory function requires a request context, but none was provided.\",\n );\n }\n return agents({ request });\n }\n return agents;\n}\n\ninterface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {\n /**\n * Map of available agents, or a factory function for per-request agent resolution.\n *\n * Static record:\n * ```ts\n * agents: { support: new SupportAgent(), technical: new TechnicalAgent() }\n * ```\n *\n * Factory function (called per-request):\n * ```ts\n * agents: ({ request }) => {\n * const tenantId = request.headers.get(\"x-tenant-id\");\n * return { default: createAgentForTenant(tenantId) };\n * }\n * ```\n */\n agents: AgentsConfig;\n /** Optional transcription service for audio processing. */\n transcriptionService?: TranscriptionService;\n /** Optional *before* middleware – callback function or webhook URL. */\n beforeRequestMiddleware?: BeforeRequestMiddleware;\n /** Optional *after* middleware – callback function or webhook URL. */\n afterRequestMiddleware?: AfterRequestMiddleware;\n /** Signed license token for server-side feature verification. Falls back to COPILOTKIT_LICENSE_TOKEN env var. */\n licenseToken?: string;\n /** Enable debug logging for the event pipeline. */\n debug?: DebugConfig;\n}\n\nexport interface CopilotRuntimeUser {\n id: string;\n}\n\nexport type IdentifyUserCallback = (\n request: Request,\n) => MaybePromise<CopilotRuntimeUser>;\n\nexport interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** The runner to use for running agents in SSE mode. */\n runner?: AgentRunner;\n intelligence?: undefined;\n generateThreadNames?: undefined;\n}\n\nexport interface CopilotIntelligenceRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** Configures Intelligence mode for durable threads and realtime events. */\n intelligence: CopilotKitIntelligence;\n /** Resolves the authenticated user for intelligence requests. */\n identifyUser: IdentifyUserCallback;\n /** Auto-generate short names for newly created threads. */\n generateThreadNames?: boolean;\n /** Max delay (ms) for WebSocket reconnect backoff. @default 10_000 */\n maxReconnectMs?: number;\n /** Max delay (ms) for channel rejoin backoff. @default 30_000 */\n maxRejoinMs?: number;\n /** Lock TTL in seconds. Clamped to a maximum of 3600 (1 hour). @default 20 */\n lockTtlSeconds?: number;\n /** Custom Redis key prefix for the thread lock. */\n lockKeyPrefix?: string;\n /** Interval in seconds at which the runtime renews the thread lock. Clamped to a maximum of 3000 (50 minutes). @default 15 */\n lockHeartbeatIntervalSeconds?: number;\n}\n\nexport type CopilotRuntimeOptions =\n | CopilotSseRuntimeOptions\n | CopilotIntelligenceRuntimeOptions;\n\nexport interface CopilotRuntimeLike {\n agents: CopilotRuntimeOptions[\"agents\"];\n transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n runner: AgentRunner;\n a2ui: CopilotRuntimeOptions[\"a2ui\"];\n mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n openGenerativeUI: CopilotRuntimeOptions[\"openGenerativeUI\"];\n intelligence?: CopilotKitIntelligence;\n identifyUser?: IdentifyUserCallback;\n mode: RuntimeMode;\n licenseChecker?: LicenseChecker;\n debug: ResolvedDebugConfig;\n debugLogger?: CopilotRuntimeLogger;\n}\n\nexport interface CopilotSseRuntimeLike extends CopilotRuntimeLike {\n intelligence?: undefined;\n mode: RUNTIME_MODE_SSE;\n}\n\nexport interface CopilotIntelligenceRuntimeLike extends CopilotRuntimeLike {\n intelligence: CopilotKitIntelligence;\n identifyUser: IdentifyUserCallback;\n generateThreadNames: boolean;\n lockTtlSeconds: number;\n lockKeyPrefix?: string;\n lockHeartbeatIntervalSeconds: number;\n mode: RUNTIME_MODE_INTELLIGENCE;\n}\n\nabstract class BaseCopilotRuntime implements CopilotRuntimeLike {\n public agents: CopilotRuntimeOptions[\"agents\"];\n public transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n public beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n public afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n public runner: AgentRunner;\n public a2ui: CopilotRuntimeOptions[\"a2ui\"];\n public mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n public openGenerativeUI: CopilotRuntimeOptions[\"openGenerativeUI\"];\n public licenseChecker?: LicenseChecker;\n public debug: ResolvedDebugConfig;\n public debugLogger?: CopilotRuntimeLogger;\n\n abstract readonly intelligence?: CopilotKitIntelligence;\n abstract readonly mode: RuntimeMode;\n\n constructor(options: BaseCopilotRuntimeOptions, runner: AgentRunner) {\n const {\n agents,\n transcriptionService,\n beforeRequestMiddleware,\n afterRequestMiddleware,\n a2ui,\n mcpApps,\n openGenerativeUI,\n } = options;\n\n this.agents = agents;\n this.transcriptionService = transcriptionService;\n this.beforeRequestMiddleware = beforeRequestMiddleware;\n this.afterRequestMiddleware = afterRequestMiddleware;\n this.a2ui = a2ui || undefined;\n this.mcpApps = mcpApps;\n this.openGenerativeUI = openGenerativeUI;\n this.runner = runner;\n this.debug = resolveDebugConfig(options.debug);\n if (this.debug.enabled) {\n this.debugLogger = createLogger({\n level: \"debug\",\n component: \"copilotkit-debug\",\n });\n }\n }\n}\n\nexport class CopilotSseRuntime\n extends BaseCopilotRuntime\n implements CopilotSseRuntimeLike\n{\n readonly intelligence = undefined;\n readonly mode = RUNTIME_MODE_SSE;\n\n constructor(options: CopilotSseRuntimeOptions) {\n super(options, options.runner ?? new InMemoryAgentRunner());\n }\n}\n\nexport class CopilotIntelligenceRuntime\n extends BaseCopilotRuntime\n implements CopilotIntelligenceRuntimeLike\n{\n readonly intelligence: CopilotKitIntelligence;\n readonly identifyUser: IdentifyUserCallback;\n readonly generateThreadNames: boolean;\n readonly lockTtlSeconds: number;\n readonly lockKeyPrefix?: string;\n readonly lockHeartbeatIntervalSeconds: number;\n readonly mode = RUNTIME_MODE_INTELLIGENCE;\n\n /** Maximum allowed lock TTL in seconds (1 hour). */\n static readonly MAX_LOCK_TTL_SECONDS = 3_600;\n /** Maximum allowed heartbeat interval in seconds (50 minutes). */\n static readonly MAX_HEARTBEAT_INTERVAL_SECONDS = 3_000;\n\n constructor(options: CopilotIntelligenceRuntimeOptions) {\n super(\n options,\n new IntelligenceAgentRunner({\n url: options.intelligence.ɵgetRunnerWsUrl(),\n authToken: options.intelligence.ɵgetRunnerAuthToken(),\n maxReconnectMs: options.maxReconnectMs,\n maxRejoinMs: options.maxRejoinMs,\n }),\n );\n this.intelligence = options.intelligence;\n this.identifyUser = options.identifyUser;\n this.generateThreadNames = options.generateThreadNames ?? true;\n this.licenseChecker = createLicenseChecker(options.licenseToken);\n this.lockTtlSeconds = Math.min(\n options.lockTtlSeconds ?? 20,\n CopilotIntelligenceRuntime.MAX_LOCK_TTL_SECONDS,\n );\n this.lockKeyPrefix = options.lockKeyPrefix;\n this.lockHeartbeatIntervalSeconds = Math.min(\n options.lockHeartbeatIntervalSeconds ?? 15,\n CopilotIntelligenceRuntime.MAX_HEARTBEAT_INTERVAL_SECONDS,\n );\n }\n}\n\nfunction hasIntelligenceOptions(\n options: CopilotRuntimeOptions,\n): options is CopilotIntelligenceRuntimeOptions {\n return \"intelligence\" in options && !!options.intelligence;\n}\n\nexport function isIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): runtime is CopilotIntelligenceRuntimeLike {\n return runtime.mode === RUNTIME_MODE_INTELLIGENCE && !!runtime.intelligence;\n}\n\n/**\n * Compatibility shim that preserves the legacy `CopilotRuntime` entrypoint.\n * New code should prefer `CopilotSseRuntime` or `CopilotIntelligenceRuntime`.\n */\nexport class CopilotRuntime implements CopilotRuntimeLike {\n private delegate: CopilotRuntimeLike;\n\n constructor(options: CopilotRuntimeOptions) {\n this.delegate = hasIntelligenceOptions(options)\n ? new CopilotIntelligenceRuntime(options)\n : new CopilotSseRuntime(options);\n }\n\n get agents(): CopilotRuntimeOptions[\"agents\"] {\n return this.delegate.agents;\n }\n\n get transcriptionService(): CopilotRuntimeOptions[\"transcriptionService\"] {\n return this.delegate.transcriptionService;\n }\n\n get beforeRequestMiddleware(): CopilotRuntimeOptions[\"beforeRequestMiddleware\"] {\n return this.delegate.beforeRequestMiddleware;\n }\n\n get afterRequestMiddleware(): CopilotRuntimeOptions[\"afterRequestMiddleware\"] {\n return this.delegate.afterRequestMiddleware;\n }\n\n get runner(): AgentRunner {\n return this.delegate.runner;\n }\n\n get a2ui(): CopilotRuntimeOptions[\"a2ui\"] {\n return this.delegate.a2ui;\n }\n\n get mcpApps(): CopilotRuntimeOptions[\"mcpApps\"] {\n return this.delegate.mcpApps;\n }\n\n get openGenerativeUI(): CopilotRuntimeOptions[\"openGenerativeUI\"] {\n return this.delegate.openGenerativeUI;\n }\n\n get intelligence(): CopilotKitIntelligence | undefined {\n return this.delegate.intelligence;\n }\n\n get generateThreadNames(): boolean | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.generateThreadNames\n : undefined;\n }\n\n get identifyUser(): IdentifyUserCallback | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.identifyUser\n : undefined;\n }\n\n get lockTtlSeconds(): number | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.lockTtlSeconds\n : undefined;\n }\n\n get lockKeyPrefix(): string | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.lockKeyPrefix\n : undefined;\n }\n\n get lockHeartbeatIntervalSeconds(): number | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.lockHeartbeatIntervalSeconds\n : undefined;\n }\n\n get mode(): RuntimeMode {\n return this.delegate.mode;\n }\n\n get licenseChecker() {\n return this.delegate.licenseChecker;\n }\n\n get debug(): ResolvedDebugConfig {\n return this.delegate.debug;\n }\n\n get debugLogger(): CopilotRuntimeLogger | undefined {\n return this.delegate.debugLogger;\n }\n}\n"],"mappings":";;;;;;;;;;;AA+BA,MAAa,UAAUA,uBAAI;;;;;;AAgE3B,eAAsB,cACpB,QACA,SACwC;AACxC,KAAI,OAAO,WAAW,YAAY;AAChC,MAAI,CAAC,QACH,OAAM,IAAI,MACR,4EACD;AAEH,SAAO,OAAO,EAAE,SAAS,CAAC;;AAE5B,QAAO;;AAuGT,IAAe,qBAAf,MAAgE;CAgB9D,YAAY,SAAoC,QAAqB;EACnE,MAAM,EACJ,QACA,sBACA,yBACA,wBACA,MACA,SACA,qBACE;AAEJ,OAAK,SAAS;AACd,OAAK,uBAAuB;AAC5B,OAAK,0BAA0B;AAC/B,OAAK,yBAAyB;AAC9B,OAAK,OAAO,QAAQ;AACpB,OAAK,UAAU;AACf,OAAK,mBAAmB;AACxB,OAAK,SAAS;AACd,OAAK,QAAQ,mBAAmB,QAAQ,MAAM;AAC9C,MAAI,KAAK,MAAM,QACb,MAAK,cAAc,aAAa;GAC9B,OAAO;GACP,WAAW;GACZ,CAAC;;;AAKR,IAAa,oBAAb,cACU,mBAEV;CAIE,YAAY,SAAmC;AAC7C,QAAM,SAAS,QAAQ,UAAU,IAAI,qBAAqB,CAAC;sBAJrC;cACR;;;AAOlB,IAAa,6BAAb,MAAa,mCACH,mBAEV;;8BAUyC;;;wCAEU;;CAEjD,YAAY,SAA4C;AACtD,QACE,SACA,IAAI,wBAAwB;GAC1B,KAAK,QAAQ,aAAa,iBAAiB;GAC3C,WAAW,QAAQ,aA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,SAAS,GACvC,KAAK,SAAS,eACd;;CAGN,IAAI,iBAAqC;AACvC,SAAO,sBAAsB,KAAK,SAAS,GACvC,KAAK,SAAS,iBACd;;CAGN,IAAI,gBAAoC;AACtC,SAAO,sBAAsB,KAAK,SAAS,GACvC,KAAK,SAAS,gBACd;;CAGN,IAAI,+BAAmD;AACrD,SAAO,sBAAsB,KAAK,SAAS,GACvC,KAAK,SAAS,+BACd;;CAGN,IAAI,OAAoB;AACtB,SAAO,KAAK,SAAS;;CAGvB,IAAI,iBAAiB;AACnB,SAAO,KAAK,SAAS;;CAGvB,IAAI,QAA6B;AAC/B,SAAO,KAAK,SAAS;;CAGvB,IAAI,cAAgD;AAClD,SAAO,KAAK,SAAS"}
@@ -12,19 +12,27 @@ function resolveLicenseStatus(runtime) {
12
12
  if (status.warningSeverity === "info") return "none";
13
13
  return "unknown";
14
14
  }
15
- async function handleGetRuntimeInfo({ runtime }) {
15
+ async function handleGetRuntimeInfo({ runtime, request }) {
16
16
  try {
17
- const agents = await runtime.agents;
17
+ const agents = await require_runtime.resolveAgents(runtime.agents, request);
18
+ const agentEntries = await Promise.all(Object.entries(agents).map(async ([name, agent]) => {
19
+ let capabilities;
20
+ try {
21
+ capabilities = agent.getCapabilities ? await agent.getCapabilities() : void 0;
22
+ } catch (error) {
23
+ console.warn(`Failed to fetch capabilities for agent "${name}":`, error instanceof Error ? error.message : error);
24
+ capabilities = void 0;
25
+ }
26
+ return [name, {
27
+ name,
28
+ description: agent.description,
29
+ className: agent.constructor.name,
30
+ ...capabilities ? { capabilities } : {}
31
+ }];
32
+ }));
18
33
  const runtimeInfo = {
19
34
  version: require_runtime.VERSION,
20
- agents: Object.entries(agents).reduce((acc, [name, agent]) => {
21
- acc[name] = {
22
- name,
23
- description: agent.description,
24
- className: agent.constructor.name
25
- };
26
- return acc;
27
- }, {}),
35
+ agents: Object.fromEntries(agentEntries),
28
36
  audioFileTranscriptionEnabled: !!runtime.transcriptionService,
29
37
  mode: runtime.mode,
30
38
  ...require_runtime.isIntelligenceRuntime(runtime) ? { intelligence: { wsUrl: runtime.intelligence.ɵgetClientWsUrl() } } : {},
@@ -1 +1 @@
1
- {"version":3,"file":"get-runtime-info.cjs","names":["VERSION","isIntelligenceRuntime"],"sources":["../../../../src/v2/runtime/handlers/get-runtime-info.ts"],"sourcesContent":["import { CopilotRuntimeLike, isIntelligenceRuntime } from \"../core/runtime\";\nimport {\n AgentDescription,\n RuntimeInfo,\n type RuntimeLicenseStatus,\n} from \"@copilotkit/shared\";\nimport { VERSION } from \"../core/runtime\";\n\nfunction resolveLicenseStatus(\n runtime: CopilotRuntimeLike,\n): RuntimeLicenseStatus {\n if (!runtime.licenseChecker) return \"none\";\n const status = runtime.licenseChecker.getStatus();\n if (status.warningSeverity === \"none\") return \"valid\";\n if (status.error === \"expired\") return \"expired\";\n if (status.warningSeverity === \"warning\") return \"expiring\";\n if (status.error) return \"invalid\";\n if (status.warningSeverity === \"info\") return \"none\";\n return \"unknown\";\n}\n\ninterface HandleGetRuntimeInfoParameters {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\nexport async function handleGetRuntimeInfo({\n runtime,\n}: HandleGetRuntimeInfoParameters) {\n try {\n const agents = await runtime.agents;\n\n const agentsDict = Object.entries(agents).reduce(\n (acc, [name, agent]) => {\n acc[name] = {\n name,\n description: agent.description,\n className: agent.constructor.name,\n };\n return acc;\n },\n {} as Record<string, AgentDescription>,\n );\n\n const runtimeInfo: RuntimeInfo = {\n version: VERSION,\n agents: agentsDict,\n audioFileTranscriptionEnabled: !!runtime.transcriptionService,\n mode: runtime.mode,\n ...(isIntelligenceRuntime(runtime)\n ? {\n intelligence: {\n wsUrl: runtime.intelligence.ɵgetClientWsUrl(),\n },\n }\n : {}),\n a2uiEnabled: !!runtime.a2ui,\n openGenerativeUIEnabled: !!runtime.openGenerativeUI,\n ...(isIntelligenceRuntime(runtime)\n ? { licenseStatus: resolveLicenseStatus(runtime) }\n : {}),\n };\n\n return new Response(JSON.stringify(runtimeInfo), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (error) {\n return new Response(\n JSON.stringify({\n error: \"Failed to retrieve runtime information\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;AAQA,SAAS,qBACP,SACsB;AACtB,KAAI,CAAC,QAAQ,eAAgB,QAAO;CACpC,MAAM,SAAS,QAAQ,eAAe,WAAW;AACjD,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,KAAI,OAAO,UAAU,UAAW,QAAO;AACvC,KAAI,OAAO,oBAAoB,UAAW,QAAO;AACjD,KAAI,OAAO,MAAO,QAAO;AACzB,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,QAAO;;AAQT,eAAsB,qBAAqB,EACzC,WACiC;AACjC,KAAI;EACF,MAAM,SAAS,MAAM,QAAQ;EAc7B,MAAM,cAA2B;GAC/B,SAASA;GACT,QAdiB,OAAO,QAAQ,OAAO,CAAC,QACvC,KAAK,CAAC,MAAM,WAAW;AACtB,QAAI,QAAQ;KACV;KACA,aAAa,MAAM;KACnB,WAAW,MAAM,YAAY;KAC9B;AACD,WAAO;MAET,EAAE,CACH;GAKC,+BAA+B,CAAC,CAAC,QAAQ;GACzC,MAAM,QAAQ;GACd,GAAIC,sCAAsB,QAAQ,GAC9B,EACE,cAAc,EACZ,OAAO,QAAQ,aAAa,iBAAiB,EAC9C,EACF,GACD,EAAE;GACN,aAAa,CAAC,CAAC,QAAQ;GACvB,yBAAyB,CAAC,CAAC,QAAQ;GACnC,GAAIA,sCAAsB,QAAQ,GAC9B,EAAE,eAAe,qBAAqB,QAAQ,EAAE,GAChD,EAAE;GACP;AAED,SAAO,IAAI,SAAS,KAAK,UAAU,YAAY,EAAE;GAC/C,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CAAC;UACK,OAAO;AACd,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
1
+ {"version":3,"file":"get-runtime-info.cjs","names":["resolveAgents","VERSION","isIntelligenceRuntime"],"sources":["../../../../src/v2/runtime/handlers/get-runtime-info.ts"],"sourcesContent":["import type { AgentCapabilities } from \"@ag-ui/core\";\nimport {\n CopilotRuntimeLike,\n isIntelligenceRuntime,\n resolveAgents,\n} from \"../core/runtime\";\nimport {\n AgentDescription,\n RuntimeInfo,\n type RuntimeLicenseStatus,\n} from \"@copilotkit/shared\";\nimport { VERSION } from \"../core/runtime\";\n\nfunction resolveLicenseStatus(\n runtime: CopilotRuntimeLike,\n): RuntimeLicenseStatus {\n if (!runtime.licenseChecker) return \"none\";\n const status = runtime.licenseChecker.getStatus();\n if (status.warningSeverity === \"none\") return \"valid\";\n if (status.error === \"expired\") return \"expired\";\n if (status.warningSeverity === \"warning\") return \"expiring\";\n if (status.error) return \"invalid\";\n if (status.warningSeverity === \"info\") return \"none\";\n return \"unknown\";\n}\n\ninterface HandleGetRuntimeInfoParameters {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\nexport async function handleGetRuntimeInfo({\n runtime,\n request,\n}: HandleGetRuntimeInfoParameters) {\n try {\n const agents = await resolveAgents(runtime.agents, request);\n\n const agentEntries = await Promise.all(\n Object.entries(agents).map(async ([name, agent]) => {\n let capabilities: AgentCapabilities | undefined;\n try {\n capabilities = agent.getCapabilities\n ? await agent.getCapabilities()\n : undefined;\n } catch (error) {\n // Per-agent isolation: a single agent failing to report capabilities\n // must not take down the entire /info endpoint.\n console.warn(\n `Failed to fetch capabilities for agent \"${name}\":`,\n error instanceof Error ? error.message : error,\n );\n capabilities = undefined;\n }\n\n const description: AgentDescription = {\n name,\n description: agent.description,\n className: agent.constructor.name,\n ...(capabilities ? { capabilities } : {}),\n };\n\n return [name, description] as const;\n }),\n );\n\n const agentsDict: Record<string, AgentDescription> =\n Object.fromEntries(agentEntries);\n\n const runtimeInfo: RuntimeInfo = {\n version: VERSION,\n agents: agentsDict,\n audioFileTranscriptionEnabled: !!runtime.transcriptionService,\n mode: runtime.mode,\n ...(isIntelligenceRuntime(runtime)\n ? {\n intelligence: {\n wsUrl: runtime.intelligence.ɵgetClientWsUrl(),\n },\n }\n : {}),\n a2uiEnabled: !!runtime.a2ui,\n openGenerativeUIEnabled: !!runtime.openGenerativeUI,\n ...(isIntelligenceRuntime(runtime)\n ? { licenseStatus: resolveLicenseStatus(runtime) }\n : {}),\n };\n\n return new Response(JSON.stringify(runtimeInfo), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (error) {\n return new Response(\n JSON.stringify({\n error: \"Failed to retrieve runtime information\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;AAaA,SAAS,qBACP,SACsB;AACtB,KAAI,CAAC,QAAQ,eAAgB,QAAO;CACpC,MAAM,SAAS,QAAQ,eAAe,WAAW;AACjD,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,KAAI,OAAO,UAAU,UAAW,QAAO;AACvC,KAAI,OAAO,oBAAoB,UAAW,QAAO;AACjD,KAAI,OAAO,MAAO,QAAO;AACzB,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,QAAO;;AAQT,eAAsB,qBAAqB,EACzC,SACA,WACiC;AACjC,KAAI;EACF,MAAM,SAAS,MAAMA,8BAAc,QAAQ,QAAQ,QAAQ;EAE3D,MAAM,eAAe,MAAM,QAAQ,IACjC,OAAO,QAAQ,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,WAAW;GAClD,IAAI;AACJ,OAAI;AACF,mBAAe,MAAM,kBACjB,MAAM,MAAM,iBAAiB,GAC7B;YACG,OAAO;AAGd,YAAQ,KACN,2CAA2C,KAAK,KAChD,iBAAiB,QAAQ,MAAM,UAAU,MAC1C;AACD,mBAAe;;AAUjB,UAAO,CAAC,MAP8B;IACpC;IACA,aAAa,MAAM;IACnB,WAAW,MAAM,YAAY;IAC7B,GAAI,eAAe,EAAE,cAAc,GAAG,EAAE;IACzC,CAEyB;IAC1B,CACH;EAKD,MAAM,cAA2B;GAC/B,SAASC;GACT,QAJA,OAAO,YAAY,aAAa;GAKhC,+BAA+B,CAAC,CAAC,QAAQ;GACzC,MAAM,QAAQ;GACd,GAAIC,sCAAsB,QAAQ,GAC9B,EACE,cAAc,EACZ,OAAO,QAAQ,aAAa,iBAAiB,EAC9C,EACF,GACD,EAAE;GACN,aAAa,CAAC,CAAC,QAAQ;GACvB,yBAAyB,CAAC,CAAC,QAAQ;GACnC,GAAIA,sCAAsB,QAAQ,GAC9B,EAAE,eAAe,qBAAqB,QAAQ,EAAE,GAChD,EAAE;GACP;AAED,SAAO,IAAI,SAAS,KAAK,UAAU,YAAY,EAAE;GAC/C,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CAAC;UACK,OAAO;AACd,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
@@ -1,5 +1,5 @@
1
1
  import "reflect-metadata";
2
- import { VERSION, isIntelligenceRuntime } from "../core/runtime.mjs";
2
+ import { VERSION, isIntelligenceRuntime, resolveAgents } from "../core/runtime.mjs";
3
3
 
4
4
  //#region src/v2/runtime/handlers/get-runtime-info.ts
5
5
  function resolveLicenseStatus(runtime) {
@@ -12,19 +12,27 @@ function resolveLicenseStatus(runtime) {
12
12
  if (status.warningSeverity === "info") return "none";
13
13
  return "unknown";
14
14
  }
15
- async function handleGetRuntimeInfo({ runtime }) {
15
+ async function handleGetRuntimeInfo({ runtime, request }) {
16
16
  try {
17
- const agents = await runtime.agents;
17
+ const agents = await resolveAgents(runtime.agents, request);
18
+ const agentEntries = await Promise.all(Object.entries(agents).map(async ([name, agent]) => {
19
+ let capabilities;
20
+ try {
21
+ capabilities = agent.getCapabilities ? await agent.getCapabilities() : void 0;
22
+ } catch (error) {
23
+ console.warn(`Failed to fetch capabilities for agent "${name}":`, error instanceof Error ? error.message : error);
24
+ capabilities = void 0;
25
+ }
26
+ return [name, {
27
+ name,
28
+ description: agent.description,
29
+ className: agent.constructor.name,
30
+ ...capabilities ? { capabilities } : {}
31
+ }];
32
+ }));
18
33
  const runtimeInfo = {
19
34
  version: VERSION,
20
- agents: Object.entries(agents).reduce((acc, [name, agent]) => {
21
- acc[name] = {
22
- name,
23
- description: agent.description,
24
- className: agent.constructor.name
25
- };
26
- return acc;
27
- }, {}),
35
+ agents: Object.fromEntries(agentEntries),
28
36
  audioFileTranscriptionEnabled: !!runtime.transcriptionService,
29
37
  mode: runtime.mode,
30
38
  ...isIntelligenceRuntime(runtime) ? { intelligence: { wsUrl: runtime.intelligence.ɵgetClientWsUrl() } } : {},
@@ -1 +1 @@
1
- {"version":3,"file":"get-runtime-info.mjs","names":[],"sources":["../../../../src/v2/runtime/handlers/get-runtime-info.ts"],"sourcesContent":["import { CopilotRuntimeLike, isIntelligenceRuntime } from \"../core/runtime\";\nimport {\n AgentDescription,\n RuntimeInfo,\n type RuntimeLicenseStatus,\n} from \"@copilotkit/shared\";\nimport { VERSION } from \"../core/runtime\";\n\nfunction resolveLicenseStatus(\n runtime: CopilotRuntimeLike,\n): RuntimeLicenseStatus {\n if (!runtime.licenseChecker) return \"none\";\n const status = runtime.licenseChecker.getStatus();\n if (status.warningSeverity === \"none\") return \"valid\";\n if (status.error === \"expired\") return \"expired\";\n if (status.warningSeverity === \"warning\") return \"expiring\";\n if (status.error) return \"invalid\";\n if (status.warningSeverity === \"info\") return \"none\";\n return \"unknown\";\n}\n\ninterface HandleGetRuntimeInfoParameters {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\nexport async function handleGetRuntimeInfo({\n runtime,\n}: HandleGetRuntimeInfoParameters) {\n try {\n const agents = await runtime.agents;\n\n const agentsDict = Object.entries(agents).reduce(\n (acc, [name, agent]) => {\n acc[name] = {\n name,\n description: agent.description,\n className: agent.constructor.name,\n };\n return acc;\n },\n {} as Record<string, AgentDescription>,\n );\n\n const runtimeInfo: RuntimeInfo = {\n version: VERSION,\n agents: agentsDict,\n audioFileTranscriptionEnabled: !!runtime.transcriptionService,\n mode: runtime.mode,\n ...(isIntelligenceRuntime(runtime)\n ? {\n intelligence: {\n wsUrl: runtime.intelligence.ɵgetClientWsUrl(),\n },\n }\n : {}),\n a2uiEnabled: !!runtime.a2ui,\n openGenerativeUIEnabled: !!runtime.openGenerativeUI,\n ...(isIntelligenceRuntime(runtime)\n ? { licenseStatus: resolveLicenseStatus(runtime) }\n : {}),\n };\n\n return new Response(JSON.stringify(runtimeInfo), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (error) {\n return new Response(\n JSON.stringify({\n error: \"Failed to retrieve runtime information\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;AAQA,SAAS,qBACP,SACsB;AACtB,KAAI,CAAC,QAAQ,eAAgB,QAAO;CACpC,MAAM,SAAS,QAAQ,eAAe,WAAW;AACjD,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,KAAI,OAAO,UAAU,UAAW,QAAO;AACvC,KAAI,OAAO,oBAAoB,UAAW,QAAO;AACjD,KAAI,OAAO,MAAO,QAAO;AACzB,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,QAAO;;AAQT,eAAsB,qBAAqB,EACzC,WACiC;AACjC,KAAI;EACF,MAAM,SAAS,MAAM,QAAQ;EAc7B,MAAM,cAA2B;GAC/B,SAAS;GACT,QAdiB,OAAO,QAAQ,OAAO,CAAC,QACvC,KAAK,CAAC,MAAM,WAAW;AACtB,QAAI,QAAQ;KACV;KACA,aAAa,MAAM;KACnB,WAAW,MAAM,YAAY;KAC9B;AACD,WAAO;MAET,EAAE,CACH;GAKC,+BAA+B,CAAC,CAAC,QAAQ;GACzC,MAAM,QAAQ;GACd,GAAI,sBAAsB,QAAQ,GAC9B,EACE,cAAc,EACZ,OAAO,QAAQ,aAAa,iBAAiB,EAC9C,EACF,GACD,EAAE;GACN,aAAa,CAAC,CAAC,QAAQ;GACvB,yBAAyB,CAAC,CAAC,QAAQ;GACnC,GAAI,sBAAsB,QAAQ,GAC9B,EAAE,eAAe,qBAAqB,QAAQ,EAAE,GAChD,EAAE;GACP;AAED,SAAO,IAAI,SAAS,KAAK,UAAU,YAAY,EAAE;GAC/C,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CAAC;UACK,OAAO;AACd,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
1
+ {"version":3,"file":"get-runtime-info.mjs","names":[],"sources":["../../../../src/v2/runtime/handlers/get-runtime-info.ts"],"sourcesContent":["import type { AgentCapabilities } from \"@ag-ui/core\";\nimport {\n CopilotRuntimeLike,\n isIntelligenceRuntime,\n resolveAgents,\n} from \"../core/runtime\";\nimport {\n AgentDescription,\n RuntimeInfo,\n type RuntimeLicenseStatus,\n} from \"@copilotkit/shared\";\nimport { VERSION } from \"../core/runtime\";\n\nfunction resolveLicenseStatus(\n runtime: CopilotRuntimeLike,\n): RuntimeLicenseStatus {\n if (!runtime.licenseChecker) return \"none\";\n const status = runtime.licenseChecker.getStatus();\n if (status.warningSeverity === \"none\") return \"valid\";\n if (status.error === \"expired\") return \"expired\";\n if (status.warningSeverity === \"warning\") return \"expiring\";\n if (status.error) return \"invalid\";\n if (status.warningSeverity === \"info\") return \"none\";\n return \"unknown\";\n}\n\ninterface HandleGetRuntimeInfoParameters {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\nexport async function handleGetRuntimeInfo({\n runtime,\n request,\n}: HandleGetRuntimeInfoParameters) {\n try {\n const agents = await resolveAgents(runtime.agents, request);\n\n const agentEntries = await Promise.all(\n Object.entries(agents).map(async ([name, agent]) => {\n let capabilities: AgentCapabilities | undefined;\n try {\n capabilities = agent.getCapabilities\n ? await agent.getCapabilities()\n : undefined;\n } catch (error) {\n // Per-agent isolation: a single agent failing to report capabilities\n // must not take down the entire /info endpoint.\n console.warn(\n `Failed to fetch capabilities for agent \"${name}\":`,\n error instanceof Error ? error.message : error,\n );\n capabilities = undefined;\n }\n\n const description: AgentDescription = {\n name,\n description: agent.description,\n className: agent.constructor.name,\n ...(capabilities ? { capabilities } : {}),\n };\n\n return [name, description] as const;\n }),\n );\n\n const agentsDict: Record<string, AgentDescription> =\n Object.fromEntries(agentEntries);\n\n const runtimeInfo: RuntimeInfo = {\n version: VERSION,\n agents: agentsDict,\n audioFileTranscriptionEnabled: !!runtime.transcriptionService,\n mode: runtime.mode,\n ...(isIntelligenceRuntime(runtime)\n ? {\n intelligence: {\n wsUrl: runtime.intelligence.ɵgetClientWsUrl(),\n },\n }\n : {}),\n a2uiEnabled: !!runtime.a2ui,\n openGenerativeUIEnabled: !!runtime.openGenerativeUI,\n ...(isIntelligenceRuntime(runtime)\n ? { licenseStatus: resolveLicenseStatus(runtime) }\n : {}),\n };\n\n return new Response(JSON.stringify(runtimeInfo), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (error) {\n return new Response(\n JSON.stringify({\n error: \"Failed to retrieve runtime information\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;AAaA,SAAS,qBACP,SACsB;AACtB,KAAI,CAAC,QAAQ,eAAgB,QAAO;CACpC,MAAM,SAAS,QAAQ,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K,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
@@ -14,7 +14,7 @@ async function handleConnectAgent({ runtime, request, agentId }) {
14
14
  ...request.headers.get("x-copilotcloud-public-api-key") ? { "cloud.public_api_key": request.headers.get("x-copilotcloud-public-api-key") } : {}
15
15
  });
16
16
  try {
17
- const agent = await require_agent_utils.cloneAgentForRequest(runtime, agentId);
17
+ const agent = await require_agent_utils.cloneAgentForRequest(runtime, agentId, request);
18
18
  if (agent instanceof Response) return agent;
19
19
  const connectRequest = await require_agent_utils.parseConnectRequest(request);
20
20
  if (connectRequest instanceof Response) return connectRequest;
@@ -1 +1 @@
1
- {"version":3,"file":"handle-connect.cjs","names":["cloneAgentForRequest","parseConnectRequest","isIntelligenceRuntime","handleIntelligenceConnect","handleSseConnect"],"sources":["../../../../src/v2/runtime/handlers/handle-connect.ts"],"sourcesContent":["import { handleIntelligenceConnect } from \"./intelligence/connect\";\nimport { handleSseConnect } from \"./sse/connect\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport {\n parseConnectRequest,\n RunAgentParameters as ConnectAgentParameters,\n cloneAgentForRequest,\n} from \"./shared/agent-utils\";\n\nexport async function handleConnectAgent({\n runtime,\n request,\n agentId,\n}: ConnectAgentParameters) {\n telemetry.capture(\"oss.runtime.copilot_request_created\", {\n \"cloud.guardrails.enabled\": false,\n requestType: \"connect\",\n \"cloud.api_key_provided\": !!request.headers.get(\n \"x-copilotcloud-public-api-key\",\n ),\n ...(request.headers.get(\"x-copilotcloud-public-api-key\")\n ? {\n \"cloud.public_api_key\": request.headers.get(\n \"x-copilotcloud-public-api-key\",\n )!,\n }\n : {}),\n });\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId);\n if (agent instanceof Response) {\n return agent;\n }\n\n const connectRequest = await parseConnectRequest(request);\n if (connectRequest instanceof Response) {\n return connectRequest;\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceConnect({\n runtime,\n request,\n threadId: connectRequest.input.threadId,\n lastSeenEventId: connectRequest.lastSeenEventId,\n });\n }\n\n return handleSseConnect({\n runtime,\n request,\n threadId: connectRequest.input.threadId,\n });\n } catch (error) {\n console.error(\"Error running agent:\", error);\n console.error(\n \"Error stack:\",\n error instanceof Error ? error.stack : \"No stack trace\",\n );\n console.error(\"Error details:\", {\n name: error instanceof Error ? error.name : \"Unknown\",\n message: error instanceof Error ? error.message : String(error),\n cause: error instanceof Error ? error.cause : undefined,\n });\n\n return new Response(\n JSON.stringify({\n error: \"Failed to run agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;;;;;AAUA,eAAsB,mBAAmB,EACvC,SACA,SACA,WACyB;AACzB,kCAAU,QAAQ,uCAAuC;EACvD,4BAA4B;EAC5B,aAAa;EACb,0BAA0B,CAAC,CAAC,QAAQ,QAAQ,IAC1C,gCACD;EACD,GAAI,QAAQ,QAAQ,IAAI,gCAAgC,GACpD,EACE,wBAAwB,QAAQ,QAAQ,IACtC,gCACD,EACF,GACD,EAAE;EACP,CAAC;AAEF,KAAI;EACF,MAAM,QAAQ,MAAMA,yCAAqB,SAAS,QAAQ;AAC1D,MAAI,iBAAiB,SACnB,QAAO;EAGT,MAAM,iBAAiB,MAAMC,wCAAoB,QAAQ;AACzD,MAAI,0BAA0B,SAC5B,QAAO;AAGT,MAAIC,sCAAsB,QAAQ,CAChC,QAAOC,0CAA0B;GAC/B;GACA;GACA,UAAU,eAAe,MAAM;GAC/B,iBAAiB,eAAe;GACjC,CAAC;AAGJ,SAAOC,mCAAiB;GACtB;GACA;GACA,UAAU,eAAe,MAAM;GAChC,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,wBAAwB,MAAM;AAC5C,UAAQ,MACN,gBACA,iBAAiB,QAAQ,MAAM,QAAQ,iBACxC;AACD,UAAQ,MAAM,kBAAkB;GAC9B,MAAM,iBAAiB,QAAQ,MAAM,OAAO;GAC5C,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;GAC/D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ;GAC/C,CAAC;AAEF,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
1
+ {"version":3,"file":"handle-connect.cjs","names":["cloneAgentForRequest","parseConnectRequest","isIntelligenceRuntime","handleIntelligenceConnect","handleSseConnect"],"sources":["../../../../src/v2/runtime/handlers/handle-connect.ts"],"sourcesContent":["import { handleIntelligenceConnect } from \"./intelligence/connect\";\nimport { handleSseConnect } from \"./sse/connect\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport {\n parseConnectRequest,\n RunAgentParameters as ConnectAgentParameters,\n cloneAgentForRequest,\n} from \"./shared/agent-utils\";\n\nexport async function handleConnectAgent({\n runtime,\n request,\n agentId,\n}: ConnectAgentParameters) {\n telemetry.capture(\"oss.runtime.copilot_request_created\", {\n \"cloud.guardrails.enabled\": false,\n requestType: \"connect\",\n \"cloud.api_key_provided\": !!request.headers.get(\n \"x-copilotcloud-public-api-key\",\n ),\n ...(request.headers.get(\"x-copilotcloud-public-api-key\")\n ? {\n \"cloud.public_api_key\": request.headers.get(\n \"x-copilotcloud-public-api-key\",\n )!,\n }\n : {}),\n });\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n const connectRequest = await parseConnectRequest(request);\n if (connectRequest instanceof Response) {\n return connectRequest;\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceConnect({\n runtime,\n request,\n threadId: connectRequest.input.threadId,\n lastSeenEventId: connectRequest.lastSeenEventId,\n });\n }\n\n return handleSseConnect({\n runtime,\n request,\n threadId: connectRequest.input.threadId,\n });\n } catch (error) {\n console.error(\"Error running agent:\", error);\n console.error(\n \"Error stack:\",\n error instanceof Error ? error.stack : \"No stack trace\",\n );\n console.error(\"Error details:\", {\n name: error instanceof Error ? error.name : \"Unknown\",\n message: error instanceof Error ? error.message : String(error),\n cause: error instanceof Error ? error.cause : undefined,\n });\n\n return new Response(\n JSON.stringify({\n error: \"Failed to run agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;;;;;AAUA,eAAsB,mBAAmB,EACvC,SACA,SACA,WACyB;AACzB,kCAAU,QAAQ,uCAAuC;EACvD,4BAA4B;EAC5B,aAAa;EACb,0BAA0B,CAAC,CAAC,QAAQ,QAAQ,IAC1C,gCACD;EACD,GAAI,QAAQ,QAAQ,IAAI,gCAAgC,GACpD,EACE,wBAAwB,QAAQ,QAAQ,IACtC,gCACD,EACF,GACD,EAAE;EACP,CAAC;AAEF,KAAI;EACF,MAAM,QAAQ,MAAMA,yCAAqB,SAAS,SAAS,QAAQ;AACnE,MAAI,iBAAiB,SACnB,QAAO;EAGT,MAAM,iBAAiB,MAAMC,wCAAoB,QAAQ;AACzD,MAAI,0BAA0B,SAC5B,QAAO;AAGT,MAAIC,sCAAsB,QAAQ,CAChC,QAAOC,0CAA0B;GAC/B;GACA;GACA,UAAU,eAAe,MAAM;GAC/B,iBAAiB,eAAe;GACjC,CAAC;AAGJ,SAAOC,mCAAiB;GACtB;GACA;GACA,UAAU,eAAe,MAAM;GAChC,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,wBAAwB,MAAM;AAC5C,UAAQ,MACN,gBACA,iBAAiB,QAAQ,MAAM,QAAQ,iBACxC;AACD,UAAQ,MAAM,kBAAkB;GAC9B,MAAM,iBAAiB,QAAQ,MAAM,OAAO;GAC5C,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;GAC/D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ;GAC/C,CAAC;AAEF,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
@@ -14,7 +14,7 @@ async function handleConnectAgent({ runtime, request, agentId }) {
14
14
  ...request.headers.get("x-copilotcloud-public-api-key") ? { "cloud.public_api_key": request.headers.get("x-copilotcloud-public-api-key") } : {}
15
15
  });
16
16
  try {
17
- const agent = await cloneAgentForRequest(runtime, agentId);
17
+ const agent = await cloneAgentForRequest(runtime, agentId, request);
18
18
  if (agent instanceof Response) return agent;
19
19
  const connectRequest = await parseConnectRequest(request);
20
20
  if (connectRequest instanceof Response) return connectRequest;
@@ -1 +1 @@
1
- {"version":3,"file":"handle-connect.mjs","names":[],"sources":["../../../../src/v2/runtime/handlers/handle-connect.ts"],"sourcesContent":["import { handleIntelligenceConnect } from \"./intelligence/connect\";\nimport { handleSseConnect } from \"./sse/connect\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport {\n parseConnectRequest,\n RunAgentParameters as ConnectAgentParameters,\n cloneAgentForRequest,\n} from \"./shared/agent-utils\";\n\nexport async function handleConnectAgent({\n runtime,\n request,\n agentId,\n}: ConnectAgentParameters) {\n telemetry.capture(\"oss.runtime.copilot_request_created\", {\n \"cloud.guardrails.enabled\": false,\n requestType: \"connect\",\n \"cloud.api_key_provided\": !!request.headers.get(\n \"x-copilotcloud-public-api-key\",\n ),\n ...(request.headers.get(\"x-copilotcloud-public-api-key\")\n ? {\n \"cloud.public_api_key\": request.headers.get(\n \"x-copilotcloud-public-api-key\",\n )!,\n }\n : {}),\n });\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId);\n if (agent instanceof Response) {\n return agent;\n }\n\n const connectRequest = await parseConnectRequest(request);\n if (connectRequest instanceof Response) {\n return connectRequest;\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceConnect({\n runtime,\n request,\n threadId: connectRequest.input.threadId,\n lastSeenEventId: connectRequest.lastSeenEventId,\n });\n }\n\n return handleSseConnect({\n runtime,\n request,\n threadId: connectRequest.input.threadId,\n });\n } catch (error) {\n console.error(\"Error running agent:\", error);\n console.error(\n \"Error stack:\",\n error instanceof Error ? error.stack : \"No stack trace\",\n );\n console.error(\"Error details:\", {\n name: error instanceof Error ? error.name : \"Unknown\",\n message: error instanceof Error ? error.message : String(error),\n cause: error instanceof Error ? error.cause : undefined,\n });\n\n return new Response(\n JSON.stringify({\n error: \"Failed to run agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;;;;;AAUA,eAAsB,mBAAmB,EACvC,SACA,SACA,WACyB;AACzB,WAAU,QAAQ,uCAAuC;EACvD,4BAA4B;EAC5B,aAAa;EACb,0BAA0B,CAAC,CAAC,QAAQ,QAAQ,IAC1C,gCACD;EACD,GAAI,QAAQ,QAAQ,IAAI,gCAAgC,GACpD,EACE,wBAAwB,QAAQ,QAAQ,IACtC,gCACD,EACF,GACD,EAAE;EACP,CAAC;AAEF,KAAI;EACF,MAAM,QAAQ,MAAM,qBAAqB,SAAS,QAAQ;AAC1D,MAAI,iBAAiB,SACnB,QAAO;EAGT,MAAM,iBAAiB,MAAM,oBAAoB,QAAQ;AACzD,MAAI,0BAA0B,SAC5B,QAAO;AAGT,MAAI,sBAAsB,QAAQ,CAChC,QAAO,0BAA0B;GAC/B;GACA;GACA,UAAU,eAAe,MAAM;GAC/B,iBAAiB,eAAe;GACjC,CAAC;AAGJ,SAAO,iBAAiB;GACtB;GACA;GACA,UAAU,eAAe,MAAM;GAChC,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,wBAAwB,MAAM;AAC5C,UAAQ,MACN,gBACA,iBAAiB,QAAQ,MAAM,QAAQ,iBACxC;AACD,UAAQ,MAAM,kBAAkB;GAC9B,MAAM,iBAAiB,QAAQ,MAAM,OAAO;GAC5C,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;GAC/D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ;GAC/C,CAAC;AAEF,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
1
+ {"version":3,"file":"handle-connect.mjs","names":[],"sources":["../../../../src/v2/runtime/handlers/handle-connect.ts"],"sourcesContent":["import { handleIntelligenceConnect } from \"./intelligence/connect\";\nimport { handleSseConnect } from \"./sse/connect\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport {\n parseConnectRequest,\n RunAgentParameters as ConnectAgentParameters,\n cloneAgentForRequest,\n} from \"./shared/agent-utils\";\n\nexport async function handleConnectAgent({\n runtime,\n request,\n agentId,\n}: ConnectAgentParameters) {\n telemetry.capture(\"oss.runtime.copilot_request_created\", {\n \"cloud.guardrails.enabled\": false,\n requestType: \"connect\",\n \"cloud.api_key_provided\": !!request.headers.get(\n \"x-copilotcloud-public-api-key\",\n ),\n ...(request.headers.get(\"x-copilotcloud-public-api-key\")\n ? {\n \"cloud.public_api_key\": request.headers.get(\n \"x-copilotcloud-public-api-key\",\n )!,\n }\n : {}),\n });\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n const connectRequest = await parseConnectRequest(request);\n if (connectRequest instanceof Response) {\n return connectRequest;\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceConnect({\n runtime,\n request,\n threadId: connectRequest.input.threadId,\n lastSeenEventId: connectRequest.lastSeenEventId,\n });\n }\n\n return handleSseConnect({\n runtime,\n request,\n threadId: connectRequest.input.threadId,\n });\n } catch (error) {\n console.error(\"Error running agent:\", error);\n console.error(\n \"Error stack:\",\n error instanceof Error ? error.stack : \"No stack trace\",\n );\n console.error(\"Error details:\", {\n name: error instanceof Error ? error.name : \"Unknown\",\n message: error instanceof Error ? error.message : String(error),\n cause: error instanceof Error ? error.cause : undefined,\n });\n\n return new Response(\n JSON.stringify({\n error: \"Failed to run agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;;;;;AAUA,eAAsB,mBAAmB,EACvC,SACA,SACA,WACyB;AACzB,WAAU,QAAQ,uCAAuC;EACvD,4BAA4B;EAC5B,aAAa;EACb,0BAA0B,CAAC,CAAC,QAAQ,QAAQ,IAC1C,gCACD;EACD,GAAI,QAAQ,QAAQ,IAAI,gCAAgC,GACpD,EACE,wBAAwB,QAAQ,QAAQ,IACtC,gCACD,EACF,GACD,EAAE;EACP,CAAC;AAEF,KAAI;EACF,MAAM,QAAQ,MAAM,qBAAqB,SAAS,SAAS,QAAQ;AACnE,MAAI,iBAAiB,SACnB,QAAO;EAGT,MAAM,iBAAiB,MAAM,oBAAoB,QAAQ;AACzD,MAAI,0BAA0B,SAC5B,QAAO;AAGT,MAAI,sBAAsB,QAAQ,CAChC,QAAO,0BAA0B;GAC/B;GACA;GACA,UAAU,eAAe,MAAM;GAC/B,iBAAiB,eAAe;GACjC,CAAC;AAGJ,SAAO,iBAAiB;GACtB;GACA;GACA,UAAU,eAAe,MAAM;GAChC,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,wBAAwB,MAAM;AAC5C,UAAQ,MACN,gBACA,iBAAiB,QAAQ,MAAM,QAAQ,iBACxC;AACD,UAAQ,MAAM,kBAAkB;GAC9B,MAAM,iBAAiB,QAAQ,MAAM,OAAO;GAC5C,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;GAC/D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ;GAC/C,CAAC;AAEF,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
@@ -14,7 +14,7 @@ async function handleRunAgent({ runtime, request, agentId }) {
14
14
  ...request.headers.get("x-copilotcloud-public-api-key") ? { "cloud.public_api_key": request.headers.get("x-copilotcloud-public-api-key") } : {}
15
15
  });
16
16
  try {
17
- const agent = await require_agent_utils.cloneAgentForRequest(runtime, agentId);
17
+ const agent = await require_agent_utils.cloneAgentForRequest(runtime, agentId, request);
18
18
  if (agent instanceof Response) return agent;
19
19
  require_agent_utils.configureAgentForRequest({
20
20
  runtime,
@@ -28,6 +28,10 @@ async function handleRunAgent({ runtime, request, agentId }) {
28
28
  agent.setMessages(input.messages);
29
29
  agent.setState(input.state);
30
30
  agent.threadId = input.threadId;
31
+ if (runtime.debug?.lifecycle && runtime.debugLogger) runtime.debugLogger.debug({
32
+ agentName: agentId,
33
+ threadId: input.threadId
34
+ }, "Agent run started");
31
35
  if (require_runtime.isIntelligenceRuntime(runtime)) return require_run.handleIntelligenceRun({
32
36
  runtime,
33
37
  request,
@@ -39,7 +43,9 @@ async function handleRunAgent({ runtime, request, agentId }) {
39
43
  runtime,
40
44
  request,
41
45
  agent,
42
- input
46
+ input,
47
+ debug: runtime.debug,
48
+ logger: runtime.debugLogger
43
49
  });
44
50
  } catch (error) {
45
51
  console.error("Error running agent:", error);