@copilotkit/runtime 1.56.2 → 1.56.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/graphql/resolvers/copilot.resolver.cjs +2 -1
- package/dist/graphql/resolvers/copilot.resolver.cjs.map +1 -1
- package/dist/graphql/resolvers/copilot.resolver.mjs +2 -1
- package/dist/graphql/resolvers/copilot.resolver.mjs.map +1 -1
- package/dist/graphql/resolvers/resolve-message-id.cjs +19 -0
- package/dist/graphql/resolvers/resolve-message-id.cjs.map +1 -0
- package/dist/graphql/resolvers/resolve-message-id.mjs +18 -0
- package/dist/graphql/resolvers/resolve-message-id.mjs.map +1 -0
- package/dist/lib/runtime/copilot-runtime.cjs +4 -2
- package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.mjs +4 -2
- package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
- package/dist/package.cjs +2 -2
- package/dist/package.mjs +2 -2
- package/dist/v2/runtime/core/debug-event-bus.cjs +36 -0
- package/dist/v2/runtime/core/debug-event-bus.cjs.map +1 -0
- package/dist/v2/runtime/core/debug-event-bus.d.cts +19 -0
- package/dist/v2/runtime/core/debug-event-bus.d.cts.map +1 -0
- package/dist/v2/runtime/core/debug-event-bus.d.mts +19 -0
- package/dist/v2/runtime/core/debug-event-bus.d.mts.map +1 -0
- package/dist/v2/runtime/core/debug-event-bus.mjs +35 -0
- package/dist/v2/runtime/core/debug-event-bus.mjs.map +1 -0
- package/dist/v2/runtime/core/fetch-handler.cjs +6 -0
- package/dist/v2/runtime/core/fetch-handler.cjs.map +1 -1
- package/dist/v2/runtime/core/fetch-handler.d.cts.map +1 -1
- package/dist/v2/runtime/core/fetch-handler.d.mts.map +1 -1
- package/dist/v2/runtime/core/fetch-handler.mjs +6 -0
- package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -1
- package/dist/v2/runtime/core/fetch-router.cjs +1 -0
- package/dist/v2/runtime/core/fetch-router.cjs.map +1 -1
- package/dist/v2/runtime/core/fetch-router.mjs +1 -0
- package/dist/v2/runtime/core/fetch-router.mjs.map +1 -1
- package/dist/v2/runtime/core/hooks.cjs.map +1 -1
- package/dist/v2/runtime/core/hooks.d.cts +2 -0
- package/dist/v2/runtime/core/hooks.d.cts.map +1 -1
- package/dist/v2/runtime/core/hooks.d.mts +2 -0
- package/dist/v2/runtime/core/hooks.d.mts.map +1 -1
- package/dist/v2/runtime/core/hooks.mjs.map +1 -1
- package/dist/v2/runtime/core/runtime.cjs +5 -0
- package/dist/v2/runtime/core/runtime.cjs.map +1 -1
- package/dist/v2/runtime/core/runtime.d.cts +5 -0
- package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
- package/dist/v2/runtime/core/runtime.d.mts +5 -0
- package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
- package/dist/v2/runtime/core/runtime.mjs +5 -0
- package/dist/v2/runtime/core/runtime.mjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-connect.cjs +2 -0
- package/dist/v2/runtime/handlers/handle-connect.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-connect.mjs +2 -0
- package/dist/v2/runtime/handlers/handle-connect.mjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-debug-events.cjs +33 -0
- package/dist/v2/runtime/handlers/handle-debug-events.cjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-debug-events.mjs +32 -0
- package/dist/v2/runtime/handlers/handle-debug-events.mjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-run.cjs +1 -0
- package/dist/v2/runtime/handlers/handle-run.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-run.mjs +1 -0
- package/dist/v2/runtime/handlers/handle-run.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/connect.cjs +32 -2
- package/dist/v2/runtime/handlers/intelligence/connect.cjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/connect.mjs +31 -2
- package/dist/v2/runtime/handlers/intelligence/connect.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs +5 -1
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs +5 -1
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/sse-response.cjs +21 -1
- package/dist/v2/runtime/handlers/shared/sse-response.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/sse-response.mjs +21 -1
- package/dist/v2/runtime/handlers/shared/sse-response.mjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/connect.cjs +3 -1
- package/dist/v2/runtime/handlers/sse/connect.cjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/connect.mjs +3 -1
- package/dist/v2/runtime/handlers/sse/connect.mjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/run.cjs +3 -1
- package/dist/v2/runtime/handlers/sse/run.cjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/run.mjs +3 -1
- package/dist/v2/runtime/handlers/sse/run.mjs.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.cjs +2 -7
- package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.cts +1 -4
- package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.mts +1 -4
- package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.mjs +2 -7
- package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
- package/dist/v2/runtime/runner/intelligence.cjs +17 -5
- package/dist/v2/runtime/runner/intelligence.cjs.map +1 -1
- package/dist/v2/runtime/runner/intelligence.d.cts +1 -0
- package/dist/v2/runtime/runner/intelligence.d.cts.map +1 -1
- package/dist/v2/runtime/runner/intelligence.d.mts +1 -0
- package/dist/v2/runtime/runner/intelligence.d.mts.map +1 -1
- package/dist/v2/runtime/runner/intelligence.mjs +17 -5
- package/dist/v2/runtime/runner/intelligence.mjs.map +1 -1
- package/package.json +3 -3
- package/src/agents/langgraph/__tests__/event-source.test.ts +256 -0
- package/src/graphql/resolvers/__tests__/resolve-message-id.test.ts +25 -0
- package/src/graphql/resolvers/copilot.resolver.ts +2 -1
- package/src/graphql/resolvers/resolve-message-id.ts +14 -0
- package/src/lib/runtime/__tests__/handle-service-adapter.test.ts +108 -0
- package/src/lib/runtime/__tests__/retry-utils.test.ts +137 -0
- package/src/lib/runtime/agent-integrations/langgraph/__tests__/dispatch-event-filtering.test.ts +190 -0
- package/src/lib/runtime/copilot-runtime.ts +20 -4
- package/src/lib/runtime/retry-utils.ts +41 -1
- package/src/v2/runtime/__tests__/fetch-router.test.ts +22 -0
- package/src/v2/runtime/__tests__/handle-connect.test.ts +58 -5
- package/src/v2/runtime/__tests__/handle-run.test.ts +31 -4
- package/src/v2/runtime/__tests__/handle-threads.test.ts +66 -4
- package/src/v2/runtime/__tests__/integration/node-servers.integration.test.ts +19 -0
- package/src/v2/runtime/__tests__/integration/suites/debug-events.suite.ts +253 -0
- package/src/v2/runtime/__tests__/runtime.test.ts +3 -1
- package/src/v2/runtime/core/__tests__/debug-event-bus.test.ts +156 -0
- package/src/v2/runtime/core/debug-event-bus.ts +45 -0
- package/src/v2/runtime/core/fetch-handler.ts +4 -0
- package/src/v2/runtime/core/fetch-router.ts +11 -0
- package/src/v2/runtime/core/hooks.ts +2 -1
- package/src/v2/runtime/core/runtime.ts +12 -0
- package/src/v2/runtime/handlers/__tests__/handle-debug-events.test.ts +176 -0
- package/src/v2/runtime/handlers/handle-connect.ts +2 -0
- package/src/v2/runtime/handlers/handle-debug-events.ts +52 -0
- package/src/v2/runtime/handlers/handle-run.ts +1 -0
- package/src/v2/runtime/handlers/intelligence/connect.ts +58 -1
- package/src/v2/runtime/handlers/shared/resolve-intelligence-user.ts +4 -1
- package/src/v2/runtime/handlers/shared/sse-response.ts +46 -0
- package/src/v2/runtime/handlers/sse/__tests__/sse-connect-agent-id.test.ts +71 -0
- package/src/v2/runtime/handlers/sse/connect.ts +6 -0
- package/src/v2/runtime/handlers/sse/run.ts +4 -0
- package/src/v2/runtime/intelligence-platform/__tests__/client.test.ts +13 -11
- package/src/v2/runtime/intelligence-platform/client.ts +3 -11
- package/src/v2/runtime/runner/__tests__/intelligence-runner.test.ts +51 -1
- package/src/v2/runtime/runner/intelligence.ts +27 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.cts","names":[],"sources":["../../../../src/v2/runtime/core/runtime.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.cts","names":[],"sources":["../../../../src/v2/runtime/core/runtime.ts"],"mappings":";;;;;;;;;;;;;;cAgCa,OAAA;AAAA,UAEH,mCAAA;EAFwB;EAIhC,MAAA;AAAA;AAAA,KAGU,mBAAA,GAAsB,eAAA;EALxB,uFAOR,OAAA;AAAA;AAAA,UAGe,aAAA;EART;EAUN,OAAA,EAAS,mBAAA;AAAA;AAAA,UAGM,uBAAA,SAAgC,mCAAA;AAAA,KAErC,sBAAA,aAAmC,uBAAA;AAAA,UAErC,yBAAA;EAToB;;;;EAc5B,IAAA,GAAO,mCAAA,GAAsC,oBAAA;EATN;EAWvC,OAAA,GAAU,aAAA;EAXqC;EAa/C,gBAAA,GAAmB,sBAAA;AAAA;;;;UAMJ,mBAAA;EAfP;EAiBR,OAAA,EAAS,OAAA;AAAA;;;;;KAOC,aAAA,IACV,GAAA,EAAK,mBAAA,KACF,YAAA,CAAa,cAAA,CAAe,MAAA,SAAe,aAAA;;;;;;;KAQpC,YAAA,GACR,YAAA,CAAa,cAAA,CAAe,MAAA,SAAe,aAAA,MAC3C,aAAA;;;;AArBJ;;iBA4BsB,aAAA,CACpB,MAAA,EAAQ,YAAA,EACR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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,aAAA,CAAA,GAAa,aAAA;EAAA,IAIb,KAAA,CAAA,GAAS,mBAAA;EAAA,IAIT,WAAA,CAAA,GAAe,oBAAA;AAAA"}
|
|
@@ -2,6 +2,7 @@ import "reflect-metadata";
|
|
|
2
2
|
import { AfterRequestMiddleware, BeforeRequestMiddleware } from "./middleware.mjs";
|
|
3
3
|
import { CopilotRuntimeLogger } from "../../../lib/logger.mjs";
|
|
4
4
|
import { TranscriptionService } from "../transcription-service/transcription-service.mjs";
|
|
5
|
+
import { DebugEventBus } from "./debug-event-bus.mjs";
|
|
5
6
|
import { AgentRunner } from "../runner/agent-runner.mjs";
|
|
6
7
|
import { CopilotKitIntelligence } from "../intelligence-platform/client.mjs";
|
|
7
8
|
import "../intelligence-platform/index.mjs";
|
|
@@ -93,6 +94,7 @@ interface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {
|
|
|
93
94
|
}
|
|
94
95
|
interface CopilotRuntimeUser {
|
|
95
96
|
id: string;
|
|
97
|
+
name: string;
|
|
96
98
|
}
|
|
97
99
|
type IdentifyUserCallback = (request: Request) => MaybePromise<CopilotRuntimeUser>;
|
|
98
100
|
interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {
|
|
@@ -133,6 +135,7 @@ interface CopilotRuntimeLike {
|
|
|
133
135
|
identifyUser?: IdentifyUserCallback;
|
|
134
136
|
mode: RuntimeMode;
|
|
135
137
|
licenseChecker?: LicenseChecker;
|
|
138
|
+
debugEventBus?: DebugEventBus;
|
|
136
139
|
debug: ResolvedDebugConfig;
|
|
137
140
|
debugLogger?: CopilotRuntimeLogger;
|
|
138
141
|
}
|
|
@@ -159,6 +162,7 @@ declare abstract class BaseCopilotRuntime implements CopilotRuntimeLike {
|
|
|
159
162
|
mcpApps: CopilotRuntimeOptions["mcpApps"];
|
|
160
163
|
openGenerativeUI: CopilotRuntimeOptions["openGenerativeUI"];
|
|
161
164
|
licenseChecker?: LicenseChecker;
|
|
165
|
+
readonly debugEventBus?: DebugEventBus;
|
|
162
166
|
debug: ResolvedDebugConfig;
|
|
163
167
|
debugLogger?: CopilotRuntimeLogger;
|
|
164
168
|
abstract readonly intelligence?: CopilotKitIntelligence;
|
|
@@ -208,6 +212,7 @@ declare class CopilotRuntime implements CopilotRuntimeLike {
|
|
|
208
212
|
get lockHeartbeatIntervalSeconds(): number | undefined;
|
|
209
213
|
get mode(): RuntimeMode;
|
|
210
214
|
get licenseChecker(): LicenseChecker;
|
|
215
|
+
get debugEventBus(): DebugEventBus;
|
|
211
216
|
get debug(): ResolvedDebugConfig;
|
|
212
217
|
get debugLogger(): CopilotRuntimeLogger | undefined;
|
|
213
218
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../../../../src/v2/runtime/core/runtime.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../../../../src/v2/runtime/core/runtime.ts"],"mappings":";;;;;;;;;;;;;;;cAgCa,OAAA;AAAA,UAEH,mCAAA;EAFG;EAIX,MAAA;AAAA;AAAA,K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AAA;EAAA,IAIT,WAAA,CAAA,GAAe,oBAAA;AAAA"}
|
|
@@ -2,6 +2,7 @@ import "reflect-metadata";
|
|
|
2
2
|
import { __toESM } from "../../../_virtual/_rolldown/runtime.mjs";
|
|
3
3
|
import { require_package } from "../../../package.mjs";
|
|
4
4
|
import { createLogger } from "../../../lib/logger.mjs";
|
|
5
|
+
import { DebugEventBus } from "./debug-event-bus.mjs";
|
|
5
6
|
import { InMemoryAgentRunner } from "../runner/in-memory.mjs";
|
|
6
7
|
import { IntelligenceAgentRunner } from "../runner/intelligence.mjs";
|
|
7
8
|
import { RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, resolveDebugConfig } from "@copilotkit/shared";
|
|
@@ -33,6 +34,7 @@ var BaseCopilotRuntime = class {
|
|
|
33
34
|
this.mcpApps = mcpApps;
|
|
34
35
|
this.openGenerativeUI = openGenerativeUI;
|
|
35
36
|
this.runner = runner;
|
|
37
|
+
if (process.env.NODE_ENV !== "production") this.debugEventBus = new DebugEventBus();
|
|
36
38
|
this.debug = resolveDebugConfig(options.debug);
|
|
37
39
|
if (this.debug.enabled) this.debugLogger = createLogger({
|
|
38
40
|
level: "debug",
|
|
@@ -133,6 +135,9 @@ var CopilotRuntime = class {
|
|
|
133
135
|
get licenseChecker() {
|
|
134
136
|
return this.delegate.licenseChecker;
|
|
135
137
|
}
|
|
138
|
+
get debugEventBus() {
|
|
139
|
+
return this.delegate.debugEventBus;
|
|
140
|
+
}
|
|
136
141
|
get debug() {
|
|
137
142
|
return this.delegate.debug;
|
|
138
143
|
}
|
|
@@ -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 {\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,aAAa,qBAAqB;GACrD,gBAAgB,QAAQ;GACxB,a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I,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"}
|
|
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 { DebugEventBus } from \"./debug-event-bus\";\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 name: 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 debugEventBus?: DebugEventBus;\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 readonly debugEventBus?: DebugEventBus;\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\n if (process.env.NODE_ENV !== \"production\") {\n this.debugEventBus = new DebugEventBus();\n }\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 debugEventBus() {\n return this.delegate.debugEventBus;\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":";;;;;;;;;;;;AAgCA,MAAa,UAAUA,uBAAI;;;;;;AAgE3B,eAAsB,cACpB,QACA,SACwC;AACxC,KAAI,OAAO,WAAW,Y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BAAgB;AAClB,SAAO,KAAK,SAAS;;CAGvB,IAAI,QAA6B;AAC/B,SAAO,KAAK,SAAS;;CAGvB,IAAI,cAAgD;AAClD,SAAO,KAAK,SAAS"}
|
|
@@ -22,11 +22,13 @@ async function handleConnectAgent({ runtime, request, agentId }) {
|
|
|
22
22
|
runtime,
|
|
23
23
|
request,
|
|
24
24
|
threadId: connectRequest.input.threadId,
|
|
25
|
+
runId: connectRequest.input.runId,
|
|
25
26
|
lastSeenEventId: connectRequest.lastSeenEventId
|
|
26
27
|
});
|
|
27
28
|
return require_connect$1.handleSseConnect({
|
|
28
29
|
runtime,
|
|
29
30
|
request,
|
|
31
|
+
agentId,
|
|
30
32
|
threadId: connectRequest.input.threadId
|
|
31
33
|
});
|
|
32
34
|
} catch (error) {
|
|
@@ -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, 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"}
|
|
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 runId: connectRequest.input.runId,\n lastSeenEventId: connectRequest.lastSeenEventId,\n });\n }\n\n return handleSseConnect({\n runtime,\n request,\n agentId,\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,OAAO,eAAe,MAAM;GAC5B,iBAAiB,eAAe;GACjC,CAAC;AAGJ,SAAOC,mCAAiB;GACtB;GACA;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"}
|
|
@@ -22,11 +22,13 @@ async function handleConnectAgent({ runtime, request, agentId }) {
|
|
|
22
22
|
runtime,
|
|
23
23
|
request,
|
|
24
24
|
threadId: connectRequest.input.threadId,
|
|
25
|
+
runId: connectRequest.input.runId,
|
|
25
26
|
lastSeenEventId: connectRequest.lastSeenEventId
|
|
26
27
|
});
|
|
27
28
|
return handleSseConnect({
|
|
28
29
|
runtime,
|
|
29
30
|
request,
|
|
31
|
+
agentId,
|
|
30
32
|
threadId: connectRequest.input.threadId
|
|
31
33
|
});
|
|
32
34
|
} catch (error) {
|
|
@@ -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, 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"}
|
|
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 runId: connectRequest.input.runId,\n lastSeenEventId: connectRequest.lastSeenEventId,\n });\n }\n\n return handleSseConnect({\n runtime,\n request,\n agentId,\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,OAAO,eAAe,MAAM;GAC5B,iBAAiB,eAAe;GACjC,CAAC;AAGJ,SAAO,iBAAiB;GACtB;GACA;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"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require("reflect-metadata");
|
|
2
|
+
|
|
3
|
+
//#region src/v2/runtime/handlers/handle-debug-events.ts
|
|
4
|
+
function handleDebugEvents({ runtime, request }) {
|
|
5
|
+
if (process.env.NODE_ENV === "production") return new Response("Not Found", { status: 404 });
|
|
6
|
+
if (!runtime.debugEventBus) return new Response("Debug event bus not available", { status: 503 });
|
|
7
|
+
const bus = runtime.debugEventBus;
|
|
8
|
+
const encoder = new TextEncoder();
|
|
9
|
+
const stream = new TransformStream();
|
|
10
|
+
const writer = stream.writable.getWriter();
|
|
11
|
+
writer.write(encoder.encode(": connected\n\n")).catch(() => {});
|
|
12
|
+
const unsubscribe = bus.subscribe((envelope) => {
|
|
13
|
+
if (request.signal.aborted) return;
|
|
14
|
+
const line = `data: ${JSON.stringify(envelope)}\n\n`;
|
|
15
|
+
writer.write(encoder.encode(line)).catch(() => {});
|
|
16
|
+
});
|
|
17
|
+
request.signal.addEventListener("abort", () => {
|
|
18
|
+
unsubscribe();
|
|
19
|
+
writer.close().catch(() => {});
|
|
20
|
+
});
|
|
21
|
+
return new Response(stream.readable, {
|
|
22
|
+
status: 200,
|
|
23
|
+
headers: {
|
|
24
|
+
"Content-Type": "text/event-stream",
|
|
25
|
+
"Cache-Control": "no-cache",
|
|
26
|
+
Connection: "keep-alive"
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.handleDebugEvents = handleDebugEvents;
|
|
33
|
+
//# sourceMappingURL=handle-debug-events.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-debug-events.cjs","names":[],"sources":["../../../../src/v2/runtime/handlers/handle-debug-events.ts"],"sourcesContent":["import { CopilotRuntimeLike } from \"../core/runtime\";\nimport { DebugEventEnvelope } from \"@copilotkit/shared\";\n\ninterface HandleDebugEventsParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\nexport function handleDebugEvents({\n runtime,\n request,\n}: HandleDebugEventsParams): Response {\n if (process.env.NODE_ENV === \"production\") {\n return new Response(\"Not Found\", { status: 404 });\n }\n\n if (!runtime.debugEventBus) {\n return new Response(\"Debug event bus not available\", { status: 503 });\n }\n\n const bus = runtime.debugEventBus;\n const encoder = new TextEncoder();\n const stream = new TransformStream();\n const writer = stream.writable.getWriter();\n\n // Send an SSE comment immediately to flush response headers to the client.\n // Without this, some frameworks buffer the response until actual data is written,\n // leaving the client stuck in \"connecting\" state.\n writer.write(encoder.encode(\": connected\\n\\n\")).catch(() => {});\n\n const unsubscribe = bus.subscribe((envelope: DebugEventEnvelope) => {\n if (request.signal.aborted) return;\n const line = `data: ${JSON.stringify(envelope)}\\n\\n`;\n writer.write(encoder.encode(line)).catch(() => {\n // Client disconnected, will be cleaned up by abort handler.\n });\n });\n\n request.signal.addEventListener(\"abort\", () => {\n unsubscribe();\n writer.close().catch(() => {});\n });\n\n return new Response(stream.readable, {\n status: 200,\n headers: {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n },\n });\n}\n"],"mappings":";;;AAQA,SAAgB,kBAAkB,EAChC,SACA,WACoC;AACpC,KAAI,QAAQ,IAAI,aAAa,aAC3B,QAAO,IAAI,SAAS,aAAa,EAAE,QAAQ,KAAK,CAAC;AAGnD,KAAI,CAAC,QAAQ,cACX,QAAO,IAAI,SAAS,iCAAiC,EAAE,QAAQ,KAAK,CAAC;CAGvE,MAAM,MAAM,QAAQ;CACpB,MAAM,UAAU,IAAI,aAAa;CACjC,MAAM,SAAS,IAAI,iBAAiB;CACpC,MAAM,SAAS,OAAO,SAAS,WAAW;AAK1C,QAAO,MAAM,QAAQ,OAAO,kBAAkB,CAAC,CAAC,YAAY,GAAG;CAE/D,MAAM,cAAc,IAAI,WAAW,aAAiC;AAClE,MAAI,QAAQ,OAAO,QAAS;EAC5B,MAAM,OAAO,SAAS,KAAK,UAAU,SAAS,CAAC;AAC/C,SAAO,MAAM,QAAQ,OAAO,KAAK,CAAC,CAAC,YAAY,GAE7C;GACF;AAEF,SAAQ,OAAO,iBAAiB,eAAe;AAC7C,eAAa;AACb,SAAO,OAAO,CAAC,YAAY,GAAG;GAC9B;AAEF,QAAO,IAAI,SAAS,OAAO,UAAU;EACnC,QAAQ;EACR,SAAS;GACP,gBAAgB;GAChB,iBAAiB;GACjB,YAAY;GACb;EACF,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
//#region src/v2/runtime/handlers/handle-debug-events.ts
|
|
3
|
+
function handleDebugEvents({ runtime, request }) {
|
|
4
|
+
if (process.env.NODE_ENV === "production") return new Response("Not Found", { status: 404 });
|
|
5
|
+
if (!runtime.debugEventBus) return new Response("Debug event bus not available", { status: 503 });
|
|
6
|
+
const bus = runtime.debugEventBus;
|
|
7
|
+
const encoder = new TextEncoder();
|
|
8
|
+
const stream = new TransformStream();
|
|
9
|
+
const writer = stream.writable.getWriter();
|
|
10
|
+
writer.write(encoder.encode(": connected\n\n")).catch(() => {});
|
|
11
|
+
const unsubscribe = bus.subscribe((envelope) => {
|
|
12
|
+
if (request.signal.aborted) return;
|
|
13
|
+
const line = `data: ${JSON.stringify(envelope)}\n\n`;
|
|
14
|
+
writer.write(encoder.encode(line)).catch(() => {});
|
|
15
|
+
});
|
|
16
|
+
request.signal.addEventListener("abort", () => {
|
|
17
|
+
unsubscribe();
|
|
18
|
+
writer.close().catch(() => {});
|
|
19
|
+
});
|
|
20
|
+
return new Response(stream.readable, {
|
|
21
|
+
status: 200,
|
|
22
|
+
headers: {
|
|
23
|
+
"Content-Type": "text/event-stream",
|
|
24
|
+
"Cache-Control": "no-cache",
|
|
25
|
+
Connection: "keep-alive"
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { handleDebugEvents };
|
|
32
|
+
//# sourceMappingURL=handle-debug-events.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-debug-events.mjs","names":[],"sources":["../../../../src/v2/runtime/handlers/handle-debug-events.ts"],"sourcesContent":["import { CopilotRuntimeLike } from \"../core/runtime\";\nimport { DebugEventEnvelope } from \"@copilotkit/shared\";\n\ninterface HandleDebugEventsParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\nexport function handleDebugEvents({\n runtime,\n request,\n}: HandleDebugEventsParams): Response {\n if (process.env.NODE_ENV === \"production\") {\n return new Response(\"Not Found\", { status: 404 });\n }\n\n if (!runtime.debugEventBus) {\n return new Response(\"Debug event bus not available\", { status: 503 });\n }\n\n const bus = runtime.debugEventBus;\n const encoder = new TextEncoder();\n const stream = new TransformStream();\n const writer = stream.writable.getWriter();\n\n // Send an SSE comment immediately to flush response headers to the client.\n // Without this, some frameworks buffer the response until actual data is written,\n // leaving the client stuck in \"connecting\" state.\n writer.write(encoder.encode(\": connected\\n\\n\")).catch(() => {});\n\n const unsubscribe = bus.subscribe((envelope: DebugEventEnvelope) => {\n if (request.signal.aborted) return;\n const line = `data: ${JSON.stringify(envelope)}\\n\\n`;\n writer.write(encoder.encode(line)).catch(() => {\n // Client disconnected, will be cleaned up by abort handler.\n });\n });\n\n request.signal.addEventListener(\"abort\", () => {\n unsubscribe();\n writer.close().catch(() => {});\n });\n\n return new Response(stream.readable, {\n status: 200,\n headers: {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n },\n });\n}\n"],"mappings":";;AAQA,SAAgB,kBAAkB,EAChC,SACA,WACoC;AACpC,KAAI,QAAQ,IAAI,aAAa,aAC3B,QAAO,IAAI,SAAS,aAAa,EAAE,QAAQ,KAAK,CAAC;AAGnD,KAAI,CAAC,QAAQ,cACX,QAAO,IAAI,SAAS,iCAAiC,EAAE,QAAQ,KAAK,CAAC;CAGvE,MAAM,MAAM,QAAQ;CACpB,MAAM,UAAU,IAAI,aAAa;CACjC,MAAM,SAAS,IAAI,iBAAiB;CACpC,MAAM,SAAS,OAAO,SAAS,WAAW;AAK1C,QAAO,MAAM,QAAQ,OAAO,kBAAkB,CAAC,CAAC,YAAY,GAAG;CAE/D,MAAM,cAAc,IAAI,WAAW,aAAiC;AAClE,MAAI,QAAQ,OAAO,QAAS;EAC5B,MAAM,OAAO,SAAS,KAAK,UAAU,SAAS,CAAC;AAC/C,SAAO,MAAM,QAAQ,OAAO,KAAK,CAAC,CAAC,YAAY,GAE7C;GACF;AAEF,SAAQ,OAAO,iBAAiB,eAAe;AAC7C,eAAa;AACb,SAAO,OAAO,CAAC,YAAY,GAAG;GAC9B;AAEF,QAAO,IAAI,SAAS,OAAO,UAAU;EACnC,QAAQ;EACR,SAAS;GACP,gBAAgB;GAChB,iBAAiB;GACjB,YAAY;GACb;EACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-run.cjs","names":["cloneAgentForRequest","parseRunRequest","isIntelligenceRuntime","handleIntelligenceRun","handleSseRun"],"sources":["../../../../src/v2/runtime/handlers/handle-run.ts"],"sourcesContent":["import { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport {\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n RunAgentParameters,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { handleSseRun } from \"./sse/run\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n telemetry.capture(\"oss.runtime.copilot_request_created\", {\n \"cloud.guardrails.enabled\": false,\n requestType: \"run\",\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 configureAgentForRequest({ runtime, request, agentId, agent });\n\n if (\n runtime.licenseChecker &&\n !runtime.licenseChecker.checkFeature(\"agents\")\n ) {\n console.warn(\n '[CopilotKit Runtime] Warning: \"agents\" feature is not licensed. Visit copilotkit.ai/pricing',\n );\n }\n\n const input = await parseRunRequest(request);\n if (input instanceof Response) {\n return input;\n }\n\n agent.setMessages(input.messages);\n agent.setState(input.state);\n agent.threadId = input.threadId;\n\n if (runtime.debug?.lifecycle && runtime.debugLogger) {\n runtime.debugLogger.debug(\n { agentName: agentId, threadId: input.threadId },\n \"Agent run started\",\n );\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n debug: runtime.debug,\n logger: runtime.debugLogger,\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":";;;;;;;;AAWA,eAAsB,eAAe,EACnC,SACA,SACA,WACqB;AACrB,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;AAGT,+CAAyB;GAAE;GAAS;GAAS;GAAS;GAAO,CAAC;AAE9D,MACE,QAAQ,kBACR,CAAC,QAAQ,eAAe,aAAa,SAAS,CAE9C,SAAQ,KACN,gGACD;EAGH,MAAM,QAAQ,MAAMC,oCAAgB,QAAQ;AAC5C,MAAI,iBAAiB,SACnB,QAAO;AAGT,QAAM,YAAY,MAAM,SAAS;AACjC,QAAM,SAAS,MAAM,MAAM;AAC3B,QAAM,WAAW,MAAM;AAEvB,MAAI,QAAQ,OAAO,aAAa,QAAQ,YACtC,SAAQ,YAAY,MAClB;GAAE,WAAW;GAAS,UAAU,MAAM;GAAU,EAChD,oBACD;AAGH,MAAIC,sCAAsB,QAAQ,CAChC,QAAOC,kCAAsB;GAC3B;GACA;GACA;GACA;GACA;GACD,CAAC;AAGJ,SAAOC,2BAAa;GAClB;GACA;GACA;GACA;GACA,OAAO,QAAQ;GACf,QAAQ,QAAQ;GACjB,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-run.cjs","names":["cloneAgentForRequest","parseRunRequest","isIntelligenceRuntime","handleIntelligenceRun","handleSseRun"],"sources":["../../../../src/v2/runtime/handlers/handle-run.ts"],"sourcesContent":["import { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport {\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n RunAgentParameters,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { handleSseRun } from \"./sse/run\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n telemetry.capture(\"oss.runtime.copilot_request_created\", {\n \"cloud.guardrails.enabled\": false,\n requestType: \"run\",\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 configureAgentForRequest({ runtime, request, agentId, agent });\n\n if (\n runtime.licenseChecker &&\n !runtime.licenseChecker.checkFeature(\"agents\")\n ) {\n console.warn(\n '[CopilotKit Runtime] Warning: \"agents\" feature is not licensed. Visit copilotkit.ai/pricing',\n );\n }\n\n const input = await parseRunRequest(request);\n if (input instanceof Response) {\n return input;\n }\n\n agent.setMessages(input.messages);\n agent.setState(input.state);\n agent.threadId = input.threadId;\n\n if (runtime.debug?.lifecycle && runtime.debugLogger) {\n runtime.debugLogger.debug(\n { agentName: agentId, threadId: input.threadId },\n \"Agent run started\",\n );\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug: runtime.debug,\n logger: runtime.debugLogger,\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":";;;;;;;;AAWA,eAAsB,eAAe,EACnC,SACA,SACA,WACqB;AACrB,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;AAGT,+CAAyB;GAAE;GAAS;GAAS;GAAS;GAAO,CAAC;AAE9D,MACE,QAAQ,kBACR,CAAC,QAAQ,eAAe,aAAa,SAAS,CAE9C,SAAQ,KACN,gGACD;EAGH,MAAM,QAAQ,MAAMC,oCAAgB,QAAQ;AAC5C,MAAI,iBAAiB,SACnB,QAAO;AAGT,QAAM,YAAY,MAAM,SAAS;AACjC,QAAM,SAAS,MAAM,MAAM;AAC3B,QAAM,WAAW,MAAM;AAEvB,MAAI,QAAQ,OAAO,aAAa,QAAQ,YACtC,SAAQ,YAAY,MAClB;GAAE,WAAW;GAAS,UAAU,MAAM;GAAU,EAChD,oBACD;AAGH,MAAIC,sCAAsB,QAAQ,CAChC,QAAOC,kCAAsB;GAC3B;GACA;GACA;GACA;GACA;GACD,CAAC;AAGJ,SAAOC,2BAAa;GAClB;GACA;GACA;GACA;GACA;GACA,OAAO,QAAQ;GACf,QAAQ,QAAQ;GACjB,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-run.mjs","names":[],"sources":["../../../../src/v2/runtime/handlers/handle-run.ts"],"sourcesContent":["import { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport {\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n RunAgentParameters,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { handleSseRun } from \"./sse/run\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n telemetry.capture(\"oss.runtime.copilot_request_created\", {\n \"cloud.guardrails.enabled\": false,\n requestType: \"run\",\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 configureAgentForRequest({ runtime, request, agentId, agent });\n\n if (\n runtime.licenseChecker &&\n !runtime.licenseChecker.checkFeature(\"agents\")\n ) {\n console.warn(\n '[CopilotKit Runtime] Warning: \"agents\" feature is not licensed. Visit copilotkit.ai/pricing',\n );\n }\n\n const input = await parseRunRequest(request);\n if (input instanceof Response) {\n return input;\n }\n\n agent.setMessages(input.messages);\n agent.setState(input.state);\n agent.threadId = input.threadId;\n\n if (runtime.debug?.lifecycle && runtime.debugLogger) {\n runtime.debugLogger.debug(\n { agentName: agentId, threadId: input.threadId },\n \"Agent run started\",\n );\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n debug: runtime.debug,\n logger: runtime.debugLogger,\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":";;;;;;;;AAWA,eAAsB,eAAe,EACnC,SACA,SACA,WACqB;AACrB,WAAU,QAAQ,uCAAuC;EACvD,4BAA4B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EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
|
|
1
|
+
{"version":3,"file":"handle-run.mjs","names":[],"sources":["../../../../src/v2/runtime/handlers/handle-run.ts"],"sourcesContent":["import { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport {\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n RunAgentParameters,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { handleSseRun } from \"./sse/run\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n telemetry.capture(\"oss.runtime.copilot_request_created\", {\n \"cloud.guardrails.enabled\": false,\n requestType: \"run\",\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 configureAgentForRequest({ runtime, request, agentId, agent });\n\n if (\n runtime.licenseChecker &&\n !runtime.licenseChecker.checkFeature(\"agents\")\n ) {\n console.warn(\n '[CopilotKit Runtime] Warning: \"agents\" feature is not licensed. Visit copilotkit.ai/pricing',\n );\n }\n\n const input = await parseRunRequest(request);\n if (input instanceof Response) {\n return input;\n }\n\n agent.setMessages(input.messages);\n agent.setState(input.state);\n agent.threadId = input.threadId;\n\n if (runtime.debug?.lifecycle && runtime.debugLogger) {\n runtime.debugLogger.debug(\n { agentName: agentId, threadId: input.threadId },\n \"Agent run started\",\n );\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug: runtime.debug,\n logger: runtime.debugLogger,\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":";;;;;;;;AAWA,eAAsB,eAAe,EACnC,SACA,SACA,WACqB;AACrB,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;AAGT,2BAAyB;GAAE;GAAS;GAAS;GAAS;GAAO,CAAC;AAE9D,MACE,QAAQ,kBACR,CAAC,QAAQ,eAAe,aAAa,SAAS,CAE9C,SAAQ,KACN,gGACD;EAGH,MAAM,QAAQ,MAAM,gBAAgB,QAAQ;AAC5C,MAAI,iBAAiB,SACnB,QAAO;AAGT,QAAM,YAAY,MAAM,SAAS;AACjC,QAAM,SAAS,MAAM,MAAM;AAC3B,QAAM,WAAW,MAAM;AAEvB,MAAI,QAAQ,OAAO,aAAa,QAAQ,YACtC,SAAQ,YAAY,MAClB;GAAE,WAAW;GAAS,UAAU,MAAM;GAAU,EAChD,oBACD;AAGH,MAAI,sBAAsB,QAAQ,CAChC,QAAO,sBAAsB;GAC3B;GACA;GACA;GACA;GACA;GACD,CAAC;AAGJ,SAAO,aAAa;GAClB;GACA;GACA;GACA;GACA;GACA,OAAO,QAAQ;GACf,QAAQ,QAAQ;GACjB,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,10 +1,39 @@
|
|
|
1
1
|
require("reflect-metadata");
|
|
2
|
+
const require_runtime = require('../../../../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_json_response = require('../shared/json-response.cjs');
|
|
3
4
|
const require_intelligence_utils = require('../shared/intelligence-utils.cjs');
|
|
4
5
|
const require_resolve_intelligence_user = require('../shared/resolve-intelligence-user.cjs');
|
|
6
|
+
let _ag_ui_client = require("@ag-ui/client");
|
|
5
7
|
|
|
6
8
|
//#region src/v2/runtime/handlers/intelligence/connect.ts
|
|
7
|
-
|
|
9
|
+
function stampCanonicalConnectEvent(event, threadId, runId) {
|
|
10
|
+
const { thread_id: _threadId, run_id: _runId, ...eventRecord } = event;
|
|
11
|
+
if (event.type === _ag_ui_client.EventType.RUN_STARTED) {
|
|
12
|
+
const runStarted = eventRecord;
|
|
13
|
+
return {
|
|
14
|
+
...runStarted,
|
|
15
|
+
threadId,
|
|
16
|
+
runId,
|
|
17
|
+
input: {
|
|
18
|
+
...runStarted.input ?? {},
|
|
19
|
+
threadId,
|
|
20
|
+
runId
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
...eventRecord,
|
|
26
|
+
threadId,
|
|
27
|
+
runId
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function stampCanonicalConnectPlan(result, threadId, runId) {
|
|
31
|
+
return {
|
|
32
|
+
...result,
|
|
33
|
+
events: result.events.map((event) => stampCanonicalConnectEvent(event, threadId, runId))
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async function handleIntelligenceConnect({ runtime, request, threadId, runId, lastSeenEventId }) {
|
|
8
37
|
if (!runtime.intelligence) return Response.json({
|
|
9
38
|
error: "Intelligence not configured",
|
|
10
39
|
message: "Intelligence mode requires a CopilotKitIntelligence"
|
|
@@ -18,10 +47,11 @@ async function handleIntelligenceConnect({ runtime, request, threadId, lastSeenE
|
|
|
18
47
|
const result = await runtime.intelligence.ɵconnectThread({
|
|
19
48
|
threadId,
|
|
20
49
|
userId: user.id,
|
|
50
|
+
runId,
|
|
21
51
|
lastSeenEventId
|
|
22
52
|
});
|
|
23
53
|
if (result === null) return new Response(null, { status: 204 });
|
|
24
|
-
return Response.json(result, { headers: {
|
|
54
|
+
return Response.json(stampCanonicalConnectPlan(result, threadId, runId), { headers: {
|
|
25
55
|
"Cache-Control": "no-cache",
|
|
26
56
|
Connection: "keep-alive"
|
|
27
57
|
} });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.cjs","names":["resolveIntelligenceUser","isHandlerResponse","isPlatformNotFoundError"],"sources":["../../../../../src/v2/runtime/handlers/intelligence/connect.ts"],"sourcesContent":["import { CopilotIntelligenceRuntimeLike } from \"../../core/runtime\";\nimport { isPlatformNotFoundError } from \"../shared/intelligence-utils\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"../shared/json-response\";\n\ninterface HandleIntelligenceConnectParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n threadId: string;\n lastSeenEventId: string | null;\n}\n\nexport async function handleIntelligenceConnect({\n runtime,\n request,\n threadId,\n lastSeenEventId,\n}: HandleIntelligenceConnectParams): Promise<Response> {\n if (!runtime.intelligence) {\n return Response.json(\n {\n error: \"Intelligence not configured\",\n message: \"Intelligence mode requires a CopilotKitIntelligence\",\n },\n { status: 500 },\n );\n }\n\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) {\n return user;\n }\n\n const result = await runtime.intelligence.ɵconnectThread({\n threadId,\n userId: user.id,\n lastSeenEventId,\n });\n\n if (result === null) {\n return new Response(null, {\n status: 204,\n });\n }\n\n return Response.json(result, {\n headers: { \"Cache-Control\": \"no-cache\", Connection: \"keep-alive\" },\n });\n } catch (error) {\n if (isPlatformNotFoundError(error)) {\n return new Response(null, {\n status: 204,\n });\n }\n\n console.error(\"Connect plan not available:\", error);\n return Response.json(\n {\n error: \"Connect plan not available\",\n },\n { status: 404 },\n );\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"connect.cjs","names":["EventType","resolveIntelligenceUser","isHandlerResponse","isPlatformNotFoundError"],"sources":["../../../../../src/v2/runtime/handlers/intelligence/connect.ts"],"sourcesContent":["import { BaseEvent, EventType, RunStartedEvent } from \"@ag-ui/client\";\nimport { CopilotIntelligenceRuntimeLike } from \"../../core/runtime\";\nimport type {\n ConnectThreadBootstrapResponse,\n ConnectThreadLiveResponse,\n} from \"../../intelligence-platform/client\";\nimport { isPlatformNotFoundError } from \"../shared/intelligence-utils\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"../shared/json-response\";\n\ninterface HandleIntelligenceConnectParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n threadId: string;\n runId: string;\n lastSeenEventId: string | null;\n}\n\nfunction stampCanonicalConnectEvent(\n event: BaseEvent,\n threadId: string,\n runId: string,\n): BaseEvent {\n const {\n thread_id: _threadId,\n run_id: _runId,\n ...eventRecord\n } = event as BaseEvent & {\n thread_id?: unknown;\n run_id?: unknown;\n };\n\n if (event.type === EventType.RUN_STARTED) {\n const runStarted = eventRecord as RunStartedEvent;\n\n return {\n ...runStarted,\n threadId,\n runId,\n input: {\n ...(runStarted.input ?? {}),\n threadId,\n runId,\n },\n } as RunStartedEvent;\n }\n\n return {\n ...eventRecord,\n threadId,\n runId,\n } as BaseEvent;\n}\n\nfunction stampCanonicalConnectPlan(\n result: ConnectThreadBootstrapResponse | ConnectThreadLiveResponse,\n threadId: string,\n runId: string,\n) {\n return {\n ...result,\n events: result.events.map((event) =>\n stampCanonicalConnectEvent(event, threadId, runId),\n ),\n };\n}\n\nexport async function handleIntelligenceConnect({\n runtime,\n request,\n threadId,\n runId,\n lastSeenEventId,\n}: HandleIntelligenceConnectParams): Promise<Response> {\n if (!runtime.intelligence) {\n return Response.json(\n {\n error: \"Intelligence not configured\",\n message: \"Intelligence mode requires a CopilotKitIntelligence\",\n },\n { status: 500 },\n );\n }\n\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) {\n return user;\n }\n\n const result = await runtime.intelligence.ɵconnectThread({\n threadId,\n userId: user.id,\n runId,\n lastSeenEventId,\n });\n\n if (result === null) {\n return new Response(null, {\n status: 204,\n });\n }\n\n return Response.json(stampCanonicalConnectPlan(result, threadId, runId), {\n headers: { \"Cache-Control\": \"no-cache\", Connection: \"keep-alive\" },\n });\n } catch (error) {\n if (isPlatformNotFoundError(error)) {\n return new Response(null, {\n status: 204,\n });\n }\n\n console.error(\"Connect plan not available:\", error);\n return Response.json(\n {\n error: \"Connect plan not available\",\n },\n { status: 404 },\n );\n }\n}\n"],"mappings":";;;;;;;;AAkBA,SAAS,2BACP,OACA,UACA,OACW;CACX,MAAM,EACJ,WAAW,WACX,QAAQ,QACR,GAAG,gBACD;AAKJ,KAAI,MAAM,SAASA,wBAAU,aAAa;EACxC,MAAM,aAAa;AAEnB,SAAO;GACL,GAAG;GACH;GACA;GACA,OAAO;IACL,GAAI,WAAW,SAAS,EAAE;IAC1B;IACA;IACD;GACF;;AAGH,QAAO;EACL,GAAG;EACH;EACA;EACD;;AAGH,SAAS,0BACP,QACA,UACA,OACA;AACA,QAAO;EACL,GAAG;EACH,QAAQ,OAAO,OAAO,KAAK,UACzB,2BAA2B,OAAO,UAAU,MAAM,CACnD;EACF;;AAGH,eAAsB,0BAA0B,EAC9C,SACA,SACA,UACA,OACA,mBACqD;AACrD,KAAI,CAAC,QAAQ,aACX,QAAO,SAAS,KACd;EACE,OAAO;EACP,SAAS;EACV,EACD,EAAE,QAAQ,KAAK,CAChB;AAGH,KAAI;EACF,MAAM,OAAO,MAAMC,0DAAwB;GAAE;GAAS;GAAS,CAAC;AAChE,MAAIC,wCAAkB,KAAK,CACzB,QAAO;EAGT,MAAM,SAAS,MAAM,QAAQ,aAAa,eAAe;GACvD;GACA,QAAQ,KAAK;GACb;GACA;GACD,CAAC;AAEF,MAAI,WAAW,KACb,QAAO,IAAI,SAAS,MAAM,EACxB,QAAQ,KACT,CAAC;AAGJ,SAAO,SAAS,KAAK,0BAA0B,QAAQ,UAAU,MAAM,EAAE,EACvE,SAAS;GAAE,iBAAiB;GAAY,YAAY;GAAc,EACnE,CAAC;UACK,OAAO;AACd,MAAIC,mDAAwB,MAAM,CAChC,QAAO,IAAI,SAAS,MAAM,EACxB,QAAQ,KACT,CAAC;AAGJ,UAAQ,MAAM,+BAA+B,MAAM;AACnD,SAAO,SAAS,KACd,EACE,OAAO,8BACR,EACD,EAAE,QAAQ,KAAK,CAChB"}
|
|
@@ -2,9 +2,37 @@ import "reflect-metadata";
|
|
|
2
2
|
import { isHandlerResponse } from "../shared/json-response.mjs";
|
|
3
3
|
import { isPlatformNotFoundError } from "../shared/intelligence-utils.mjs";
|
|
4
4
|
import { resolveIntelligenceUser } from "../shared/resolve-intelligence-user.mjs";
|
|
5
|
+
import { EventType } from "@ag-ui/client";
|
|
5
6
|
|
|
6
7
|
//#region src/v2/runtime/handlers/intelligence/connect.ts
|
|
7
|
-
|
|
8
|
+
function stampCanonicalConnectEvent(event, threadId, runId) {
|
|
9
|
+
const { thread_id: _threadId, run_id: _runId, ...eventRecord } = event;
|
|
10
|
+
if (event.type === EventType.RUN_STARTED) {
|
|
11
|
+
const runStarted = eventRecord;
|
|
12
|
+
return {
|
|
13
|
+
...runStarted,
|
|
14
|
+
threadId,
|
|
15
|
+
runId,
|
|
16
|
+
input: {
|
|
17
|
+
...runStarted.input ?? {},
|
|
18
|
+
threadId,
|
|
19
|
+
runId
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
...eventRecord,
|
|
25
|
+
threadId,
|
|
26
|
+
runId
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function stampCanonicalConnectPlan(result, threadId, runId) {
|
|
30
|
+
return {
|
|
31
|
+
...result,
|
|
32
|
+
events: result.events.map((event) => stampCanonicalConnectEvent(event, threadId, runId))
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function handleIntelligenceConnect({ runtime, request, threadId, runId, lastSeenEventId }) {
|
|
8
36
|
if (!runtime.intelligence) return Response.json({
|
|
9
37
|
error: "Intelligence not configured",
|
|
10
38
|
message: "Intelligence mode requires a CopilotKitIntelligence"
|
|
@@ -18,10 +46,11 @@ async function handleIntelligenceConnect({ runtime, request, threadId, lastSeenE
|
|
|
18
46
|
const result = await runtime.intelligence.ɵconnectThread({
|
|
19
47
|
threadId,
|
|
20
48
|
userId: user.id,
|
|
49
|
+
runId,
|
|
21
50
|
lastSeenEventId
|
|
22
51
|
});
|
|
23
52
|
if (result === null) return new Response(null, { status: 204 });
|
|
24
|
-
return Response.json(result, { headers: {
|
|
53
|
+
return Response.json(stampCanonicalConnectPlan(result, threadId, runId), { headers: {
|
|
25
54
|
"Cache-Control": "no-cache",
|
|
26
55
|
Connection: "keep-alive"
|
|
27
56
|
} });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/intelligence/connect.ts"],"sourcesContent":["import { CopilotIntelligenceRuntimeLike } from \"../../core/runtime\";\nimport { isPlatformNotFoundError } from \"../shared/intelligence-utils\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"../shared/json-response\";\n\ninterface HandleIntelligenceConnectParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n threadId: string;\n lastSeenEventId: string | null;\n}\n\nexport async function handleIntelligenceConnect({\n runtime,\n request,\n threadId,\n lastSeenEventId,\n}: HandleIntelligenceConnectParams): Promise<Response> {\n if (!runtime.intelligence) {\n return Response.json(\n {\n error: \"Intelligence not configured\",\n message: \"Intelligence mode requires a CopilotKitIntelligence\",\n },\n { status: 500 },\n );\n }\n\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) {\n return user;\n }\n\n const result = await runtime.intelligence.ɵconnectThread({\n threadId,\n userId: user.id,\n lastSeenEventId,\n });\n\n if (result === null) {\n return new Response(null, {\n status: 204,\n });\n }\n\n return Response.json(result, {\n headers: { \"Cache-Control\": \"no-cache\", Connection: \"keep-alive\" },\n });\n } catch (error) {\n if (isPlatformNotFoundError(error)) {\n return new Response(null, {\n status: 204,\n });\n }\n\n console.error(\"Connect plan not available:\", error);\n return Response.json(\n {\n error: \"Connect plan not available\",\n },\n { status: 404 },\n );\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"connect.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/intelligence/connect.ts"],"sourcesContent":["import { BaseEvent, EventType, RunStartedEvent } from \"@ag-ui/client\";\nimport { CopilotIntelligenceRuntimeLike } from \"../../core/runtime\";\nimport type {\n ConnectThreadBootstrapResponse,\n ConnectThreadLiveResponse,\n} from \"../../intelligence-platform/client\";\nimport { isPlatformNotFoundError } from \"../shared/intelligence-utils\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"../shared/json-response\";\n\ninterface HandleIntelligenceConnectParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n threadId: string;\n runId: string;\n lastSeenEventId: string | null;\n}\n\nfunction stampCanonicalConnectEvent(\n event: BaseEvent,\n threadId: string,\n runId: string,\n): BaseEvent {\n const {\n thread_id: _threadId,\n run_id: _runId,\n ...eventRecord\n } = event as BaseEvent & {\n thread_id?: unknown;\n run_id?: unknown;\n };\n\n if (event.type === EventType.RUN_STARTED) {\n const runStarted = eventRecord as RunStartedEvent;\n\n return {\n ...runStarted,\n threadId,\n runId,\n input: {\n ...(runStarted.input ?? {}),\n threadId,\n runId,\n },\n } as RunStartedEvent;\n }\n\n return {\n ...eventRecord,\n threadId,\n runId,\n } as BaseEvent;\n}\n\nfunction stampCanonicalConnectPlan(\n result: ConnectThreadBootstrapResponse | ConnectThreadLiveResponse,\n threadId: string,\n runId: string,\n) {\n return {\n ...result,\n events: result.events.map((event) =>\n stampCanonicalConnectEvent(event, threadId, runId),\n ),\n };\n}\n\nexport async function handleIntelligenceConnect({\n runtime,\n request,\n threadId,\n runId,\n lastSeenEventId,\n}: HandleIntelligenceConnectParams): Promise<Response> {\n if (!runtime.intelligence) {\n return Response.json(\n {\n error: \"Intelligence not configured\",\n message: \"Intelligence mode requires a CopilotKitIntelligence\",\n },\n { status: 500 },\n );\n }\n\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) {\n return user;\n }\n\n const result = await runtime.intelligence.ɵconnectThread({\n threadId,\n userId: user.id,\n runId,\n lastSeenEventId,\n });\n\n if (result === null) {\n return new Response(null, {\n status: 204,\n });\n }\n\n return Response.json(stampCanonicalConnectPlan(result, threadId, runId), {\n headers: { \"Cache-Control\": \"no-cache\", Connection: \"keep-alive\" },\n });\n } catch (error) {\n if (isPlatformNotFoundError(error)) {\n return new Response(null, {\n status: 204,\n });\n }\n\n console.error(\"Connect plan not available:\", error);\n return Response.json(\n {\n error: \"Connect plan not available\",\n },\n { status: 404 },\n );\n }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9
9
|
const user = await runtime.identifyUser(request);
|
|
10
10
|
if (!require_intelligence_utils.isValidIdentifier(user?.id)) return require_json_response.errorResponse("identifyUser must return a valid user id", 400);
|
|
11
|
-
|
|
11
|
+
if (typeof user?.name !== "string" || user.name.trim().length === 0) return require_json_response.errorResponse("identifyUser must return a valid user name", 400);
|
|
12
|
+
return {
|
|
13
|
+
id: user.id,
|
|
14
|
+
name: user.name
|
|
15
|
+
};
|
|
12
16
|
} catch (error) {
|
|
13
17
|
console.error("Error identifying intelligence user:", error);
|
|
14
18
|
return require_json_response.errorResponse("Failed to identify user", 500);
|
|
@@ -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 {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeUser,\n} from \"../../core/runtime\";\nimport { errorResponse } from \"./json-response\";\nimport { isValidIdentifier } from \"./intelligence-utils\";\n\nexport async function resolveIntelligenceUser(params: {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n}): Promise<CopilotRuntimeUser | Response> {\n const { runtime, request } = params;\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\n return { id: user.id };\n } catch (error) {\n console.error(\"Error identifying intelligence user:\", error);\n return errorResponse(\"Failed to identify user\", 500);\n }\n}\n"],"mappings":";;;;;AAOA,eAAsB,wBAAwB,QAGH;CACzC,MAAM,EAAE,SAAS,YAAY;AAE7B,KAAI;EACF,MAAM,OAAO,MAAM,QAAQ,aAAa,QAAQ;AAChD,MAAI,CAACA,6CAAkB,MAAM,GAAG,CAC9B,QAAOC,oCAAc,4CAA4C,IAAI;
|
|
1
|
+
{"version":3,"file":"resolve-intelligence-user.cjs","names":["isValidIdentifier","errorResponse"],"sources":["../../../../../src/v2/runtime/handlers/shared/resolve-intelligence-user.ts"],"sourcesContent":["import {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeUser,\n} from \"../../core/runtime\";\nimport { errorResponse } from \"./json-response\";\nimport { isValidIdentifier } from \"./intelligence-utils\";\n\nexport async function resolveIntelligenceUser(params: {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n}): Promise<CopilotRuntimeUser | Response> {\n const { runtime, request } = params;\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 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,eAAsB,wBAAwB,QAGH;CACzC,MAAM,EAAE,SAAS,YAAY;AAE7B,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"}
|
|
@@ -8,7 +8,11 @@ async function resolveIntelligenceUser(params) {
|
|
|
8
8
|
try {
|
|
9
9
|
const user = await runtime.identifyUser(request);
|
|
10
10
|
if (!isValidIdentifier(user?.id)) return errorResponse("identifyUser must return a valid user id", 400);
|
|
11
|
-
|
|
11
|
+
if (typeof user?.name !== "string" || user.name.trim().length === 0) return errorResponse("identifyUser must return a valid user name", 400);
|
|
12
|
+
return {
|
|
13
|
+
id: user.id,
|
|
14
|
+
name: user.name
|
|
15
|
+
};
|
|
12
16
|
} catch (error) {
|
|
13
17
|
console.error("Error identifying intelligence user:", error);
|
|
14
18
|
return errorResponse("Failed to identify user", 500);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-intelligence-user.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/shared/resolve-intelligence-user.ts"],"sourcesContent":["import {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeUser,\n} from \"../../core/runtime\";\nimport { errorResponse } from \"./json-response\";\nimport { isValidIdentifier } from \"./intelligence-utils\";\n\nexport async function resolveIntelligenceUser(params: {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n}): Promise<CopilotRuntimeUser | Response> {\n const { runtime, request } = params;\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\n return { id: user.id };\n } catch (error) {\n console.error(\"Error identifying intelligence user:\", error);\n return errorResponse(\"Failed to identify user\", 500);\n }\n}\n"],"mappings":";;;;;AAOA,eAAsB,wBAAwB,QAGH;CACzC,MAAM,EAAE,SAAS,YAAY;AAE7B,KAAI;EACF,MAAM,OAAO,MAAM,QAAQ,aAAa,QAAQ;AAChD,MAAI,CAAC,kBAAkB,MAAM,GAAG,CAC9B,QAAO,cAAc,4CAA4C,IAAI;
|
|
1
|
+
{"version":3,"file":"resolve-intelligence-user.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/shared/resolve-intelligence-user.ts"],"sourcesContent":["import {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeUser,\n} from \"../../core/runtime\";\nimport { errorResponse } from \"./json-response\";\nimport { isValidIdentifier } from \"./intelligence-utils\";\n\nexport async function resolveIntelligenceUser(params: {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n}): Promise<CopilotRuntimeUser | Response> {\n const { runtime, request } = params;\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 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,eAAsB,wBAAwB,QAGH;CACzC,MAAM,EAAE,SAAS,YAAY;AAE7B,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"}
|