@copilotkit/runtime 2.0.0-rc.40 → 2.0.0-rc.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/agent.cjs.map +1 -1
- package/dist/agent.d.cts +2 -2
- package/dist/agent.d.mts +2 -2
- package/dist/agent.mjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/runtime/core/debug-event-bus.cjs +4 -2
- package/dist/runtime/core/debug-event-bus.cjs.map +1 -1
- package/dist/runtime/core/debug-event-bus.d.cts +4 -0
- package/dist/runtime/core/debug-event-bus.d.cts.map +1 -1
- package/dist/runtime/core/debug-event-bus.d.mts +4 -0
- package/dist/runtime/core/debug-event-bus.d.mts.map +1 -1
- package/dist/runtime/core/debug-event-bus.mjs +5 -3
- package/dist/runtime/core/debug-event-bus.mjs.map +1 -1
- package/dist/runtime/core/fetch-handler.cjs +8 -7
- package/dist/runtime/core/fetch-handler.cjs.map +1 -1
- package/dist/runtime/core/fetch-handler.d.cts.map +1 -1
- package/dist/runtime/core/fetch-handler.d.mts.map +1 -1
- package/dist/runtime/core/fetch-handler.mjs +3 -2
- package/dist/runtime/core/fetch-handler.mjs.map +1 -1
- package/dist/runtime/core/logger.cjs +20 -1
- package/dist/runtime/core/logger.cjs.map +1 -1
- package/dist/runtime/core/logger.d.cts +9 -5
- package/dist/runtime/core/logger.d.cts.map +1 -1
- package/dist/runtime/core/logger.d.mts +9 -5
- package/dist/runtime/core/logger.d.mts.map +1 -1
- package/dist/runtime/core/logger.mjs +20 -2
- package/dist/runtime/core/logger.mjs.map +1 -1
- package/dist/runtime/core/middleware-sse-parser.cjs +3 -3
- package/dist/runtime/core/middleware-sse-parser.cjs.map +1 -1
- package/dist/runtime/core/middleware-sse-parser.d.cts.map +1 -1
- package/dist/runtime/core/middleware-sse-parser.d.mts.map +1 -1
- package/dist/runtime/core/middleware-sse-parser.mjs +2 -2
- package/dist/runtime/core/middleware-sse-parser.mjs.map +1 -1
- package/dist/runtime/core/middleware.cjs +5 -4
- package/dist/runtime/core/middleware.cjs.map +1 -1
- package/dist/runtime/core/middleware.mjs +4 -3
- package/dist/runtime/core/middleware.mjs.map +1 -1
- package/dist/runtime/core/package-info.cjs +1 -1
- package/dist/runtime/core/package-info.mjs +1 -1
- package/dist/runtime/core/runtime.cjs +11 -9
- package/dist/runtime/core/runtime.cjs.map +1 -1
- package/dist/runtime/core/runtime.d.cts +19 -1
- package/dist/runtime/core/runtime.d.cts.map +1 -1
- package/dist/runtime/core/runtime.d.mts +19 -1
- package/dist/runtime/core/runtime.d.mts.map +1 -1
- package/dist/runtime/core/runtime.mjs +11 -9
- package/dist/runtime/core/runtime.mjs.map +1 -1
- package/dist/runtime/endpoints/auto-start-channels.cjs +3 -3
- package/dist/runtime/endpoints/auto-start-channels.cjs.map +1 -1
- package/dist/runtime/endpoints/auto-start-channels.mjs +2 -2
- package/dist/runtime/endpoints/auto-start-channels.mjs.map +1 -1
- package/dist/runtime/endpoints/node-fetch-handler.cjs +3 -3
- package/dist/runtime/endpoints/node-fetch-handler.cjs.map +1 -1
- package/dist/runtime/endpoints/node-fetch-handler.d.cts +2 -1
- package/dist/runtime/endpoints/node-fetch-handler.d.cts.map +1 -1
- package/dist/runtime/endpoints/node-fetch-handler.d.mts +2 -1
- package/dist/runtime/endpoints/node-fetch-handler.d.mts.map +1 -1
- package/dist/runtime/endpoints/node-fetch-handler.mjs +2 -2
- package/dist/runtime/endpoints/node-fetch-handler.mjs.map +1 -1
- package/dist/runtime/endpoints/node.cjs +4 -2
- package/dist/runtime/endpoints/node.cjs.map +1 -1
- package/dist/runtime/endpoints/node.d.cts.map +1 -1
- package/dist/runtime/endpoints/node.d.mts.map +1 -1
- package/dist/runtime/endpoints/node.mjs +4 -2
- package/dist/runtime/endpoints/node.mjs.map +1 -1
- package/dist/runtime/handlers/get-runtime-info.cjs +5 -1
- package/dist/runtime/handlers/get-runtime-info.cjs.map +1 -1
- package/dist/runtime/handlers/get-runtime-info.mjs +5 -1
- package/dist/runtime/handlers/get-runtime-info.mjs.map +1 -1
- package/dist/runtime/handlers/handle-connect.cjs +3 -8
- package/dist/runtime/handlers/handle-connect.cjs.map +1 -1
- package/dist/runtime/handlers/handle-connect.mjs +3 -8
- package/dist/runtime/handlers/handle-connect.mjs.map +1 -1
- package/dist/runtime/handlers/handle-run.cjs +4 -9
- package/dist/runtime/handlers/handle-run.cjs.map +1 -1
- package/dist/runtime/handlers/handle-run.mjs +4 -9
- package/dist/runtime/handlers/handle-run.mjs.map +1 -1
- package/dist/runtime/handlers/handle-stop.cjs +2 -1
- package/dist/runtime/handlers/handle-stop.cjs.map +1 -1
- package/dist/runtime/handlers/handle-stop.mjs +2 -1
- package/dist/runtime/handlers/handle-stop.mjs.map +1 -1
- package/dist/runtime/handlers/handle-suggest.cjs +3 -1
- package/dist/runtime/handlers/handle-suggest.cjs.map +1 -1
- package/dist/runtime/handlers/handle-suggest.mjs +3 -1
- package/dist/runtime/handlers/handle-suggest.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/annotate.cjs +6 -5
- package/dist/runtime/handlers/intelligence/annotate.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/annotate.mjs +4 -3
- package/dist/runtime/handlers/intelligence/annotate.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/connect.cjs +6 -2
- package/dist/runtime/handlers/intelligence/connect.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/connect.mjs +6 -2
- package/dist/runtime/handlers/intelligence/connect.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/memories.cjs +20 -14
- package/dist/runtime/handlers/intelligence/memories.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/memories.mjs +11 -5
- package/dist/runtime/handlers/intelligence/memories.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/run.cjs +15 -13
- package/dist/runtime/handlers/intelligence/run.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/run.mjs +14 -12
- package/dist/runtime/handlers/intelligence/run.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/thread-names.cjs +6 -4
- package/dist/runtime/handlers/intelligence/thread-names.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/thread-names.mjs +3 -1
- package/dist/runtime/handlers/intelligence/thread-names.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/threads.cjs +30 -20
- package/dist/runtime/handlers/intelligence/threads.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/threads.mjs +13 -3
- package/dist/runtime/handlers/intelligence/threads.mjs.map +1 -1
- package/dist/runtime/handlers/shared/agent-utils.cjs +26 -25
- package/dist/runtime/handlers/shared/agent-utils.cjs.map +1 -1
- package/dist/runtime/handlers/shared/agent-utils.mjs +27 -26
- package/dist/runtime/handlers/shared/agent-utils.mjs.map +1 -1
- package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs +3 -2
- package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -1
- package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs +3 -2
- package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -1
- package/dist/runtime/handlers/shared/sse-response.cjs +5 -14
- package/dist/runtime/handlers/shared/sse-response.cjs.map +1 -1
- package/dist/runtime/handlers/shared/sse-response.mjs +5 -14
- package/dist/runtime/handlers/shared/sse-response.mjs.map +1 -1
- package/dist/runtime/handlers/shared/thread-access.cjs +3 -2
- package/dist/runtime/handlers/shared/thread-access.cjs.map +1 -1
- package/dist/runtime/handlers/shared/thread-access.d.cts.map +1 -1
- package/dist/runtime/handlers/shared/thread-access.d.mts.map +1 -1
- package/dist/runtime/handlers/shared/thread-access.mjs +3 -2
- package/dist/runtime/handlers/shared/thread-access.mjs.map +1 -1
- package/dist/runtime/handlers/sse/connect.cjs +2 -0
- package/dist/runtime/handlers/sse/connect.cjs.map +1 -1
- package/dist/runtime/handlers/sse/connect.mjs +2 -0
- package/dist/runtime/handlers/sse/connect.mjs.map +1 -1
- package/dist/runtime/handlers/sse/run.cjs +5 -2
- package/dist/runtime/handlers/sse/run.cjs.map +1 -1
- package/dist/runtime/handlers/sse/run.mjs +5 -2
- package/dist/runtime/handlers/sse/run.mjs.map +1 -1
- package/dist/runtime/index.d.cts +1 -0
- package/dist/runtime/index.d.mts +1 -0
- package/dist/runtime/intelligence-platform/analytics-context.cjs +3 -3
- package/dist/runtime/intelligence-platform/analytics-context.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/analytics-context.mjs +2 -2
- package/dist/runtime/intelligence-platform/analytics-context.mjs.map +1 -1
- package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs +3 -2
- package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs +2 -1
- package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs.map +1 -1
- package/dist/runtime/runner/intelligence.cjs +9 -7
- package/dist/runtime/runner/intelligence.cjs.map +1 -1
- package/dist/runtime/runner/intelligence.d.cts +4 -0
- package/dist/runtime/runner/intelligence.d.cts.map +1 -1
- package/dist/runtime/runner/intelligence.d.mts +4 -0
- package/dist/runtime/runner/intelligence.d.mts.map +1 -1
- package/dist/runtime/runner/intelligence.mjs +8 -6
- package/dist/runtime/runner/intelligence.mjs.map +1 -1
- package/dist/runtime/telemetry/disclosure.cjs +2 -2
- package/dist/runtime/telemetry/disclosure.cjs.map +1 -1
- package/dist/runtime/telemetry/disclosure.mjs +3 -3
- package/dist/runtime/telemetry/disclosure.mjs.map +1 -1
- package/package.json +7 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-runtime-info.cjs","names":["isIntelligenceRuntime","PlatformRequestError","resolveAgents","VERSION","hasLearningContainerConfiguration","isA2UIEnabled","isTelemetryDisabled","supportsLocalThreadEndpoints","isThreadOperationAvailable"],"sources":["../../../src/runtime/handlers/get-runtime-info.ts"],"sourcesContent":["import type { AgentCapabilities } from \"@ag-ui/core\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { hasLearningContainerConfiguration } from \"../core/learning\";\nimport {\n isA2UIEnabled,\n isIntelligenceRuntime,\n resolveAgents,\n} from \"../core/runtime\";\nimport type {\n AgentDescription,\n RuntimeInfo,\n RuntimeEntitlementResponse,\n ThreadEndpointRuntimeInfo,\n} from \"@copilotkit/shared\";\nimport type { RuntimeLicenseStatus } from \"@copilotkit/shared\";\nimport type { LicenseChecker } from \"@copilotkit/license-verifier\";\nimport { VERSION } from \"../core/runtime\";\nimport { PlatformRequestError } from \"../intelligence-platform/client\";\nimport { isTelemetryDisabled } from \"../telemetry/telemetry-client\";\nimport { supportsLocalThreadEndpoints } from \"../runner/agent-runner\";\nimport { isThreadOperationAvailable } from \"./shared/thread-access\";\n\nfunction resolveLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n): RuntimeLicenseStatus {\n if (!licenseChecker) return \"none\";\n const status = licenseChecker.getStatus();\n if (status.warningSeverity === \"none\") return \"valid\";\n if (status.error === \"expired\") return \"expired\";\n if (status.warningSeverity === \"warning\") return \"expiring\";\n if (status.error) return \"invalid\";\n if (status.warningSeverity === \"info\") return \"none\";\n return \"unknown\";\n}\n\n/**\n * Map the structured entitlement authority onto the legacy status consumed by\n * older Core, React, and Angular thread surfaces. A ready managed entitlement\n * is authoritative in both directions. Otherwise, preserve the legacy\n * self-hosted license fallback. A retryable lookup without that fallback\n * remains unknown until it resolves.\n */\nfunction resolveCompatibilityLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n runtimeEntitlements: RuntimeEntitlementResponse | undefined,\n): RuntimeLicenseStatus {\n if (runtimeEntitlements?.status === \"ready\") {\n if (\n runtimeEntitlements.entitlement.source === \"managedOrgSubscription\" ||\n runtimeEntitlements.entitlement.source ===\n \"awsMarketplaceDeploymentLicense\"\n ) {\n return runtimeEntitlements.entitlement.active ? \"valid\" : \"none\";\n }\n\n if (runtimeEntitlements.entitlement.active) {\n return \"valid\";\n }\n }\n\n const legacyLicenseStatus = resolveLicenseStatus(licenseChecker);\n if (\n legacyLicenseStatus === \"none\" &&\n runtimeEntitlements?.status !== \"ready\" &&\n runtimeEntitlements?.error.retryable\n ) {\n return \"unknown\";\n }\n\n return legacyLicenseStatus;\n}\n\ninterface HandleGetRuntimeInfoParameters {\n runtime: CopilotRuntimeLike;\n request: Request;\n threadEndpointsEnabled?: boolean;\n singleRouteResourceOperationsEnabled?: boolean;\n}\n\n/**\n * Resolve structured Runtime entitlements for configured Intelligence runtimes.\n *\n * Dependency failures are deliberately converted to a stable unavailable\n * diagnostic so `/info` remains an availability endpoint. The underlying\n * error is not exposed because it may contain upstream response details.\n */\nasync function resolveRuntimeEntitlements(\n runtime: CopilotRuntimeLike,\n): Promise<RuntimeEntitlementResponse | undefined> {\n if (!isIntelligenceRuntime(runtime)) {\n return undefined;\n }\n\n try {\n return await runtime.intelligence.getRuntimeEntitlements();\n } catch (error) {\n if (error instanceof PlatformRequestError && error.retryable === false) {\n return {\n status: \"misconfigured\",\n error: {\n code: \"runtime_entitlements_misconfigured\",\n message: \"Runtime entitlement lookup is misconfigured\",\n retryable: false,\n },\n };\n }\n\n return {\n status: \"unavailable\",\n error: {\n code: \"runtime_entitlements_unavailable\",\n message: \"Runtime entitlement lookup failed\",\n retryable: true,\n },\n };\n }\n}\n\nexport async function handleGetRuntimeInfo({\n runtime,\n request,\n threadEndpointsEnabled = true,\n singleRouteResourceOperationsEnabled = false,\n}: HandleGetRuntimeInfoParameters) {\n try {\n const runtimeEntitlementsPromise = resolveRuntimeEntitlements(runtime);\n const webEnabled =\n !isIntelligenceRuntime(runtime) || runtime.identifyUser !== undefined;\n const agents = webEnabled\n ? await resolveAgents(runtime.agents, request)\n : {};\n\n const agentEntries = await Promise.all(\n Object.entries(agents).map(async ([name, agent]) => {\n let capabilities: AgentCapabilities | undefined;\n try {\n capabilities = agent.getCapabilities\n ? await agent.getCapabilities()\n : undefined;\n } catch (error) {\n // Per-agent isolation: a single agent failing to report capabilities\n // must not take down the entire /info endpoint.\n console.warn(\n `Failed to fetch capabilities for agent \"${name}\":`,\n error instanceof Error ? error.message : error,\n );\n capabilities = undefined;\n }\n\n const description: AgentDescription = {\n name,\n description: agent.description,\n className: agent.constructor.name,\n ...(capabilities ? { capabilities } : {}),\n };\n\n return [name, description] as const;\n }),\n );\n\n const agentsDict: Record<string, AgentDescription> =\n Object.fromEntries(agentEntries);\n const runtimeEntitlements = await runtimeEntitlementsPromise;\n // Verified on first use, not at construction (see getLicenseChecker).\n const licenseChecker = isIntelligenceRuntime(runtime)\n ? await runtime.getLicenseChecker?.()\n : undefined;\n\n const runtimeInfo: RuntimeInfo = {\n version: VERSION,\n agents: agentsDict,\n audioFileTranscriptionEnabled:\n webEnabled && !!runtime.transcriptionService,\n mode: runtime.mode,\n threadEndpoints: resolveThreadEndpointInfo(\n runtime,\n threadEndpointsEnabled && webEnabled,\n ),\n ...(singleRouteResourceOperationsEnabled\n ? {\n singleRoute: {\n resourceOperations: true,\n threadEndpoints: resolveThreadEndpointInfo(runtime, webEnabled),\n },\n }\n : {}),\n // Advertised unconditionally. Multi-route runtimes expose the dedicated\n // POST /agent/:agentId/suggest path; single-route clients fall back to a\n // client-side run (they don't construct the single-route envelope for\n // suggest). The flag lets multi-route clients detect the stateless path.\n suggestions: webEnabled,\n ...(isIntelligenceRuntime(runtime) && webEnabled\n ? {\n intelligence: {\n wsUrl: runtime.intelligence.ɵgetClientWsUrl(),\n },\n inspectorMetadata: true,\n ...(hasLearningContainerConfiguration(runtime)\n ? { inspectorLearning: true }\n : {}),\n }\n : {}),\n // Legacy flat flag, kept for older clients. The `a2ui` object below is\n // the source of truth: it preserves the per-agent scoping that this\n // boolean discards (see CopilotKit/CopilotKit#5369). Both go through the\n // shared isA2UIEnabled() predicate so an explicit `enabled: false`\n // disables a2ui here exactly as it does on the run path.\n a2uiEnabled: webEnabled && isA2UIEnabled(runtime.a2ui),\n ...(webEnabled && isA2UIEnabled(runtime.a2ui)\n ? {\n a2ui: {\n enabled: true,\n ...(runtime.a2ui.agents ? { agents: runtime.a2ui.agents } : {}),\n },\n }\n : {}),\n openGenerativeUIEnabled: webEnabled && !!runtime.openGenerativeUI,\n ...(isIntelligenceRuntime(runtime)\n ? {\n licenseStatus: resolveCompatibilityLicenseStatus(\n licenseChecker,\n runtimeEntitlements,\n ),\n }\n : {}),\n ...(runtimeEntitlements ? { runtimeEntitlements } : {}),\n telemetryDisabled: isTelemetryDisabled(),\n };\n\n return new Response(JSON.stringify(runtimeInfo), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (error) {\n return new Response(\n JSON.stringify({\n error: \"Failed to retrieve runtime information\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n\nfunction resolveThreadEndpointInfo(\n runtime: CopilotRuntimeLike,\n threadEndpointsEnabled: boolean,\n): ThreadEndpointRuntimeInfo {\n // A local route is advertised only when the Thread access policy lets it\n // serve requests: without identity, list is refused by default while\n // reading a Thread by id is not.\n const available = (operation: \"list\" | \"read\") =>\n threadEndpointsEnabled &&\n (isIntelligenceRuntime(runtime) ||\n (supportsLocalThreadEndpoints(runtime.runner) &&\n isThreadOperationAvailable(runtime, operation)));\n const managedThreadMetadata =\n threadEndpointsEnabled && isIntelligenceRuntime(runtime);\n\n return {\n list: available(\"list\"),\n inspect: available(\"read\"),\n mutations: managedThreadMetadata,\n realtimeMetadata: managedThreadMetadata,\n };\n}\n"],"mappings":";;;;;;;;AAsBA,SAAS,qBACP,gBACsB;AACtB,KAAI,CAAC,eAAgB,QAAO;CAC5B,MAAM,SAAS,eAAe,WAAW;AACzC,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,KAAI,OAAO,UAAU,UAAW,QAAO;AACvC,KAAI,OAAO,oBAAoB,UAAW,QAAO;AACjD,KAAI,OAAO,MAAO,QAAO;AACzB,KAAI,OAAO,oBAAoB,OAAQ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KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;;;AAIL,SAAS,0BACP,SACA,wBAC2B;CAI3B,MAAM,aAAa,cACjB,2BACCN,sCAAsB,QAAQ,IAC5BO,kDAA6B,QAAQ,OAAO,IAC3CC,iDAA2B,SAAS,UAAU;CACpD,MAAM,wBACJ,0BAA0BR,sCAAsB,QAAQ;AAE1D,QAAO;EACL,MAAM,UAAU,OAAO;EACvB,SAAS,UAAU,OAAO;EAC1B,WAAW;EACX,kBAAkB;EACnB"}
|
|
1
|
+
{"version":3,"file":"get-runtime-info.cjs","names":["isIntelligenceRuntime","PlatformRequestError","resolveAgents","VERSION","hasLearningContainerConfiguration","isA2UIEnabled","isTelemetryDisabled","supportsLocalThreadEndpoints","isThreadOperationAvailable"],"sources":["../../../src/runtime/handlers/get-runtime-info.ts"],"sourcesContent":["import { getRuntimeLogger } from \"../core/logger\";\nimport type { AgentCapabilities } from \"@ag-ui/core\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { hasLearningContainerConfiguration } from \"../core/learning\";\nimport {\n isA2UIEnabled,\n isIntelligenceRuntime,\n resolveAgents,\n} from \"../core/runtime\";\nimport type {\n AgentDescription,\n RuntimeInfo,\n RuntimeEntitlementResponse,\n ThreadEndpointRuntimeInfo,\n} from \"@copilotkit/shared\";\nimport type { RuntimeLicenseStatus } from \"@copilotkit/shared\";\nimport type { LicenseChecker } from \"@copilotkit/license-verifier\";\nimport { VERSION } from \"../core/runtime\";\nimport { PlatformRequestError } from \"../intelligence-platform/client\";\nimport { isTelemetryDisabled } from \"../telemetry/telemetry-client\";\nimport { supportsLocalThreadEndpoints } from \"../runner/agent-runner\";\nimport { isThreadOperationAvailable } from \"./shared/thread-access\";\n\nfunction resolveLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n): RuntimeLicenseStatus {\n if (!licenseChecker) return \"none\";\n const status = licenseChecker.getStatus();\n if (status.warningSeverity === \"none\") return \"valid\";\n if (status.error === \"expired\") return \"expired\";\n if (status.warningSeverity === \"warning\") return \"expiring\";\n if (status.error) return \"invalid\";\n if (status.warningSeverity === \"info\") return \"none\";\n return \"unknown\";\n}\n\n/**\n * Map the structured entitlement authority onto the legacy status consumed by\n * older Core, React, and Angular thread surfaces. A ready managed entitlement\n * is authoritative in both directions. Otherwise, preserve the legacy\n * self-hosted license fallback. A retryable lookup without that fallback\n * remains unknown until it resolves.\n */\nfunction resolveCompatibilityLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n runtimeEntitlements: RuntimeEntitlementResponse | undefined,\n): RuntimeLicenseStatus {\n if (runtimeEntitlements?.status === \"ready\") {\n if (\n runtimeEntitlements.entitlement.source === \"managedOrgSubscription\" ||\n runtimeEntitlements.entitlement.source ===\n \"awsMarketplaceDeploymentLicense\"\n ) {\n return runtimeEntitlements.entitlement.active ? \"valid\" : \"none\";\n }\n\n if (runtimeEntitlements.entitlement.active) {\n return \"valid\";\n }\n }\n\n const legacyLicenseStatus = resolveLicenseStatus(licenseChecker);\n if (\n legacyLicenseStatus === \"none\" &&\n runtimeEntitlements?.status !== \"ready\" &&\n runtimeEntitlements?.error.retryable\n ) {\n return \"unknown\";\n }\n\n return legacyLicenseStatus;\n}\n\ninterface HandleGetRuntimeInfoParameters {\n runtime: CopilotRuntimeLike;\n request: Request;\n threadEndpointsEnabled?: boolean;\n singleRouteResourceOperationsEnabled?: boolean;\n}\n\n/**\n * Resolve structured Runtime entitlements for configured Intelligence runtimes.\n *\n * Dependency failures are deliberately converted to a stable unavailable\n * diagnostic so `/info` remains an availability endpoint. The underlying\n * error is not exposed because it may contain upstream response details.\n */\nasync function resolveRuntimeEntitlements(\n runtime: CopilotRuntimeLike,\n): Promise<RuntimeEntitlementResponse | undefined> {\n if (!isIntelligenceRuntime(runtime)) {\n return undefined;\n }\n\n try {\n return await runtime.intelligence.getRuntimeEntitlements();\n } catch (error) {\n if (error instanceof PlatformRequestError && error.retryable === false) {\n return {\n status: \"misconfigured\",\n error: {\n code: \"runtime_entitlements_misconfigured\",\n message: \"Runtime entitlement lookup is misconfigured\",\n retryable: false,\n },\n };\n }\n\n return {\n status: \"unavailable\",\n error: {\n code: \"runtime_entitlements_unavailable\",\n message: \"Runtime entitlement lookup failed\",\n retryable: true,\n },\n };\n }\n}\n\nexport async function handleGetRuntimeInfo({\n runtime,\n request,\n threadEndpointsEnabled = true,\n singleRouteResourceOperationsEnabled = false,\n}: HandleGetRuntimeInfoParameters) {\n try {\n const runtimeEntitlementsPromise = resolveRuntimeEntitlements(runtime);\n const webEnabled =\n !isIntelligenceRuntime(runtime) || runtime.identifyUser !== undefined;\n const agents = webEnabled\n ? await resolveAgents(runtime.agents, request)\n : {};\n\n const agentEntries = await Promise.all(\n Object.entries(agents).map(async ([name, agent]) => {\n let capabilities: AgentCapabilities | undefined;\n try {\n capabilities = agent.getCapabilities\n ? await agent.getCapabilities()\n : undefined;\n } catch (error) {\n // Per-agent isolation: a single agent failing to report capabilities\n // must not take down the entire /info endpoint.\n getRuntimeLogger(runtime).warn(\n { err: error, agentId: name },\n `Failed to fetch capabilities for agent \"${name}\"`,\n );\n capabilities = undefined;\n }\n\n const description: AgentDescription = {\n name,\n description: agent.description,\n className: agent.constructor.name,\n ...(capabilities ? { capabilities } : {}),\n };\n\n return [name, description] as const;\n }),\n );\n\n const agentsDict: Record<string, AgentDescription> =\n Object.fromEntries(agentEntries);\n const runtimeEntitlements = await runtimeEntitlementsPromise;\n // Verified on first use, not at construction (see getLicenseChecker).\n const licenseChecker = isIntelligenceRuntime(runtime)\n ? await runtime.getLicenseChecker?.()\n : undefined;\n\n const runtimeInfo: RuntimeInfo = {\n version: VERSION,\n agents: agentsDict,\n audioFileTranscriptionEnabled:\n webEnabled && !!runtime.transcriptionService,\n mode: runtime.mode,\n threadEndpoints: resolveThreadEndpointInfo(\n runtime,\n threadEndpointsEnabled && webEnabled,\n ),\n ...(singleRouteResourceOperationsEnabled\n ? {\n singleRoute: {\n resourceOperations: true,\n threadEndpoints: resolveThreadEndpointInfo(runtime, webEnabled),\n },\n }\n : {}),\n // Advertised unconditionally. Multi-route runtimes expose the dedicated\n // POST /agent/:agentId/suggest path; single-route clients fall back to a\n // client-side run (they don't construct the single-route envelope for\n // suggest). The flag lets multi-route clients detect the stateless path.\n suggestions: webEnabled,\n ...(isIntelligenceRuntime(runtime) && webEnabled\n ? {\n intelligence: {\n wsUrl: runtime.intelligence.ɵgetClientWsUrl(),\n },\n inspectorMetadata: true,\n ...(hasLearningContainerConfiguration(runtime)\n ? { inspectorLearning: true }\n : {}),\n }\n : {}),\n // Legacy flat flag, kept for older clients. The `a2ui` object below is\n // the source of truth: it preserves the per-agent scoping that this\n // boolean discards (see CopilotKit/CopilotKit#5369). Both go through the\n // shared isA2UIEnabled() predicate so an explicit `enabled: false`\n // disables a2ui here exactly as it does on the run path.\n a2uiEnabled: webEnabled && isA2UIEnabled(runtime.a2ui),\n ...(webEnabled && isA2UIEnabled(runtime.a2ui)\n ? {\n a2ui: {\n enabled: true,\n ...(runtime.a2ui.agents ? { agents: runtime.a2ui.agents } : {}),\n },\n }\n : {}),\n openGenerativeUIEnabled: webEnabled && !!runtime.openGenerativeUI,\n ...(isIntelligenceRuntime(runtime)\n ? {\n licenseStatus: resolveCompatibilityLicenseStatus(\n licenseChecker,\n runtimeEntitlements,\n ),\n }\n : {}),\n ...(runtimeEntitlements ? { runtimeEntitlements } : {}),\n telemetryDisabled: isTelemetryDisabled(),\n };\n\n return new Response(JSON.stringify(runtimeInfo), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (error) {\n return new Response(\n JSON.stringify({\n error: \"Failed to retrieve runtime information\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n\nfunction resolveThreadEndpointInfo(\n runtime: CopilotRuntimeLike,\n threadEndpointsEnabled: boolean,\n): ThreadEndpointRuntimeInfo {\n // A local route is advertised only when the Thread access policy lets it\n // serve requests: without identity, list is refused by default while\n // reading a Thread by id is not.\n const available = (operation: \"list\" | \"read\") =>\n threadEndpointsEnabled &&\n (isIntelligenceRuntime(runtime) ||\n (supportsLocalThreadEndpoints(runtime.runner) &&\n isThreadOperationAvailable(runtime, operation)));\n const managedThreadMetadata =\n threadEndpointsEnabled && isIntelligenceRuntime(runtime);\n\n return {\n list: available(\"list\"),\n inspect: available(\"read\"),\n mutations: managedThreadMetadata,\n realtimeMetadata: managedThreadMetadata,\n };\n}\n"],"mappings":";;;;;;;;;AAuBA,SAAS,qBACP,gBACsB;AACtB,KAAI,CAAC,eAAgB,QAAO;CAC5B,MAAM,SAAS,eAAe,WAAW;AACzC,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,KAAI,OAAO,UAAU,UAAW,QAAO;AACvC,KAAI,OAAO,oBAAoB,UAAW,QAAO;AACjD,KAAI,OAAO,MAAO,QAAO;AACzB,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,QAAO;;;;;;;;;AAUT,SAAS,kCACP,gBACA,qBACsB;AACtB,KAAI,qBAAqB,WAAW,SAAS;AAC3C,MACE,oBAAoB,YAAY,WAAW,4BAC3C,oBAAoB,YAAY,WAC9B,kCAEF,QAAO,oBAAoB,YAAY,SAAS,UAAU;AAG5D,MAAI,oBAAoB,YAAY,OAClC,QAAO;;CAIX,MAAM,sBAAsB,qBAAqB,eAAe;AAChE,KACE,wBAAwB,UACxB,qBAAqB,WAAW,WAChC,qBAAqB,MAAM,UAE3B,QAAO;AAGT,QAAO;;;;;;;;;AAiBT,eAAe,2BACb,SACiD;AACjD,KAAI,CAACA,sCAAsB,QAAQ,CACjC;AAGF,KAAI;AACF,SAAO,MAAM,QAAQ,aAAa,wBAAwB;UACnD,OAAO;AACd,MAAI,iBAAiBC,uCAAwB,MAAM,cAAc,MAC/D,QAAO;GACL,Q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|
|
2
3
|
import { hasLearningContainerConfiguration } from "../core/learning.mjs";
|
|
3
4
|
import { PlatformRequestError } from "../intelligence-platform/client.mjs";
|
|
@@ -72,7 +73,10 @@ async function handleGetRuntimeInfo({ runtime, request, threadEndpointsEnabled =
|
|
|
72
73
|
try {
|
|
73
74
|
capabilities = agent.getCapabilities ? await agent.getCapabilities() : void 0;
|
|
74
75
|
} catch (error) {
|
|
75
|
-
|
|
76
|
+
getRuntimeLogger(runtime).warn({
|
|
77
|
+
err: error,
|
|
78
|
+
agentId: name
|
|
79
|
+
}, `Failed to fetch capabilities for agent "${name}"`);
|
|
76
80
|
capabilities = void 0;
|
|
77
81
|
}
|
|
78
82
|
return [name, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-runtime-info.mjs","names":[],"sources":["../../../src/runtime/handlers/get-runtime-info.ts"],"sourcesContent":["import type { AgentCapabilities } from \"@ag-ui/core\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { hasLearningContainerConfiguration } from \"../core/learning\";\nimport {\n isA2UIEnabled,\n isIntelligenceRuntime,\n resolveAgents,\n} from \"../core/runtime\";\nimport type {\n AgentDescription,\n RuntimeInfo,\n RuntimeEntitlementResponse,\n ThreadEndpointRuntimeInfo,\n} from \"@copilotkit/shared\";\nimport type { RuntimeLicenseStatus } from \"@copilotkit/shared\";\nimport type { LicenseChecker } from \"@copilotkit/license-verifier\";\nimport { VERSION } from \"../core/runtime\";\nimport { PlatformRequestError } from \"../intelligence-platform/client\";\nimport { isTelemetryDisabled } from \"../telemetry/telemetry-client\";\nimport { supportsLocalThreadEndpoints } from \"../runner/agent-runner\";\nimport { isThreadOperationAvailable } from \"./shared/thread-access\";\n\nfunction resolveLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n): RuntimeLicenseStatus {\n if (!licenseChecker) return \"none\";\n const status = licenseChecker.getStatus();\n if (status.warningSeverity === \"none\") return \"valid\";\n if (status.error === \"expired\") return \"expired\";\n if (status.warningSeverity === \"warning\") return \"expiring\";\n if (status.error) return \"invalid\";\n if (status.warningSeverity === \"info\") return \"none\";\n return \"unknown\";\n}\n\n/**\n * Map the structured entitlement authority onto the legacy status consumed by\n * older Core, React, and Angular thread surfaces. A ready managed entitlement\n * is authoritative in both directions. Otherwise, preserve the legacy\n * self-hosted license fallback. A retryable lookup without that fallback\n * remains unknown until it resolves.\n */\nfunction resolveCompatibilityLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n runtimeEntitlements: RuntimeEntitlementResponse | undefined,\n): RuntimeLicenseStatus {\n if (runtimeEntitlements?.status === \"ready\") {\n if (\n runtimeEntitlements.entitlement.source === \"managedOrgSubscription\" ||\n runtimeEntitlements.entitlement.source ===\n \"awsMarketplaceDeploymentLicense\"\n ) {\n return runtimeEntitlements.entitlement.active ? \"valid\" : \"none\";\n }\n\n if (runtimeEntitlements.entitlement.active) {\n return \"valid\";\n }\n }\n\n const legacyLicenseStatus = resolveLicenseStatus(licenseChecker);\n if (\n legacyLicenseStatus === \"none\" &&\n runtimeEntitlements?.status !== \"ready\" &&\n runtimeEntitlements?.error.retryable\n ) {\n return \"unknown\";\n }\n\n return legacyLicenseStatus;\n}\n\ninterface HandleGetRuntimeInfoParameters {\n runtime: CopilotRuntimeLike;\n request: Request;\n threadEndpointsEnabled?: boolean;\n singleRouteResourceOperationsEnabled?: boolean;\n}\n\n/**\n * Resolve structured Runtime entitlements for configured Intelligence runtimes.\n *\n * Dependency failures are deliberately converted to a stable unavailable\n * diagnostic so `/info` remains an availability endpoint. The underlying\n * error is not exposed because it may contain upstream response details.\n */\nasync function resolveRuntimeEntitlements(\n runtime: CopilotRuntimeLike,\n): Promise<RuntimeEntitlementResponse | undefined> {\n if (!isIntelligenceRuntime(runtime)) {\n return undefined;\n }\n\n try {\n return await runtime.intelligence.getRuntimeEntitlements();\n } catch (error) {\n if (error instanceof PlatformRequestError && error.retryable === false) {\n return {\n status: \"misconfigured\",\n error: {\n code: \"runtime_entitlements_misconfigured\",\n message: \"Runtime entitlement lookup is misconfigured\",\n retryable: false,\n },\n };\n }\n\n return {\n status: \"unavailable\",\n error: {\n code: \"runtime_entitlements_unavailable\",\n message: \"Runtime entitlement lookup failed\",\n retryable: true,\n },\n };\n }\n}\n\nexport async function handleGetRuntimeInfo({\n runtime,\n request,\n threadEndpointsEnabled = true,\n singleRouteResourceOperationsEnabled = false,\n}: HandleGetRuntimeInfoParameters) {\n try {\n const runtimeEntitlementsPromise = resolveRuntimeEntitlements(runtime);\n const webEnabled =\n !isIntelligenceRuntime(runtime) || runtime.identifyUser !== undefined;\n const agents = webEnabled\n ? await resolveAgents(runtime.agents, request)\n : {};\n\n const agentEntries = await Promise.all(\n Object.entries(agents).map(async ([name, agent]) => {\n let capabilities: AgentCapabilities | undefined;\n try {\n capabilities = agent.getCapabilities\n ? await agent.getCapabilities()\n : undefined;\n } catch (error) {\n // Per-agent isolation: a single agent failing to report capabilities\n // must not take down the entire /info endpoint.\n console.warn(\n `Failed to fetch capabilities for agent \"${name}\":`,\n error instanceof Error ? error.message : error,\n );\n capabilities = undefined;\n }\n\n const description: AgentDescription = {\n name,\n description: agent.description,\n className: agent.constructor.name,\n ...(capabilities ? { capabilities } : {}),\n };\n\n return [name, description] as const;\n }),\n );\n\n const agentsDict: Record<string, AgentDescription> =\n Object.fromEntries(agentEntries);\n const runtimeEntitlements = await runtimeEntitlementsPromise;\n // Verified on first use, not at construction (see getLicenseChecker).\n const licenseChecker = isIntelligenceRuntime(runtime)\n ? await runtime.getLicenseChecker?.()\n : undefined;\n\n const runtimeInfo: RuntimeInfo = {\n version: VERSION,\n agents: agentsDict,\n audioFileTranscriptionEnabled:\n webEnabled && !!runtime.transcriptionService,\n mode: runtime.mode,\n threadEndpoints: resolveThreadEndpointInfo(\n runtime,\n threadEndpointsEnabled && webEnabled,\n ),\n ...(singleRouteResourceOperationsEnabled\n ? {\n singleRoute: {\n resourceOperations: true,\n threadEndpoints: resolveThreadEndpointInfo(runtime, webEnabled),\n },\n }\n : {}),\n // Advertised unconditionally. Multi-route runtimes expose the dedicated\n // POST /agent/:agentId/suggest path; single-route clients fall back to a\n // client-side run (they don't construct the single-route envelope for\n // suggest). The flag lets multi-route clients detect the stateless path.\n suggestions: webEnabled,\n ...(isIntelligenceRuntime(runtime) && webEnabled\n ? {\n intelligence: {\n wsUrl: runtime.intelligence.ɵgetClientWsUrl(),\n },\n inspectorMetadata: true,\n ...(hasLearningContainerConfiguration(runtime)\n ? { inspectorLearning: true }\n : {}),\n }\n : {}),\n // Legacy flat flag, kept for older clients. The `a2ui` object below is\n // the source of truth: it preserves the per-agent scoping that this\n // boolean discards (see CopilotKit/CopilotKit#5369). Both go through the\n // shared isA2UIEnabled() predicate so an explicit `enabled: false`\n // disables a2ui here exactly as it does on the run path.\n a2uiEnabled: webEnabled && isA2UIEnabled(runtime.a2ui),\n ...(webEnabled && isA2UIEnabled(runtime.a2ui)\n ? {\n a2ui: {\n enabled: true,\n ...(runtime.a2ui.agents ? { agents: runtime.a2ui.agents } : {}),\n },\n }\n : {}),\n openGenerativeUIEnabled: webEnabled && !!runtime.openGenerativeUI,\n ...(isIntelligenceRuntime(runtime)\n ? {\n licenseStatus: resolveCompatibilityLicenseStatus(\n licenseChecker,\n runtimeEntitlements,\n ),\n }\n : {}),\n ...(runtimeEntitlements ? { runtimeEntitlements } : {}),\n telemetryDisabled: isTelemetryDisabled(),\n };\n\n return new Response(JSON.stringify(runtimeInfo), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (error) {\n return new Response(\n JSON.stringify({\n error: \"Failed to retrieve runtime information\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n\nfunction resolveThreadEndpointInfo(\n runtime: CopilotRuntimeLike,\n threadEndpointsEnabled: boolean,\n): ThreadEndpointRuntimeInfo {\n // A local route is advertised only when the Thread access policy lets it\n // serve requests: without identity, list is refused by default while\n // reading a Thread by id is not.\n const available = (operation: \"list\" | \"read\") =>\n threadEndpointsEnabled &&\n (isIntelligenceRuntime(runtime) ||\n (supportsLocalThreadEndpoints(runtime.runner) &&\n isThreadOperationAvailable(runtime, operation)));\n const managedThreadMetadata =\n threadEndpointsEnabled && isIntelligenceRuntime(runtime);\n\n return {\n list: available(\"list\"),\n inspect: available(\"read\"),\n mutations: managedThreadMetadata,\n realtimeMetadata: managedThreadMetadata,\n };\n}\n"],"mappings":";;;;;;;;AAsBA,SAAS,qBACP,gBACsB;AACtB,KAAI,CAAC,eAAgB,QAAO;CAC5B,MAAM,SAAS,eAAe,WAAW;AACzC,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,KAAI,OAAO,UAAU,UAAW,QAAO;AACvC,KAAI,OAAO,oBAAoB,UAAW,QAAO;AACjD,KAAI,OAAO,MAAO,QAAO;AACzB,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,QAAO;;;;;;;;;AAUT,SAAS,kCACP,gBACA,qBACsB;AACtB,KAAI,qBAAqB,WAAW,SAAS;AAC3C,MACE,oBAAoB,YAAY,WAAW,4BAC3C,oBAAoB,YAAY,WAC9B,kCAEF,QAAO,oBAAoB,YAAY,SAAS,UAAU;AAG5D,MAAI,oBAAoB,YAAY,OAClC,QAAO;;CAIX,MAAM,sBAAsB,qBAAqB,eAAe;AAChE,KACE,wBAAwB,UACxB,qBAAqB,WAAW,WAChC,qBAAqB,MAAM,UAE3B,QAAO;AAGT,QAAO;;;;;;;;;AAiBT,eAAe,2BACb,SACiD;AACjD,KAAI,CAAC,sBAAsB,QAAQ,CACjC;AAGF,KAAI;AACF,SAAO,MAAM,QAAQ,aAAa,wBAAwB;UACnD,OAAO;AACd,MAAI,iBAAiB,wBAAwB,MAAM,cAAc,MAC/D,QAAO;GACL,QAAQ;GACR,OAAO;IACL,MAAM;IACN,SAAS;IACT,WAAW;IACZ;GACF;AAGH,SAAO;GACL,QAAQ;GACR,OAAO;IACL,MAAM;IACN,SAAS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;IACP,GACD,EAAE;GAMN,aAAa,cAAc,cAAc,QAAQ,KAAK;GACtD,GAAI,cAAc,cAAc,QAAQ,KAAK,GACzC,EACE,MAAM;IACJ,SAAS;IACT,GAAI,QAAQ,KAAK,SAAS,EAAE,QAAQ,QAAQ,KAAK,QAAQ,GAAG,EAAE;IAC/D,EACF,GACD,EAAE;GACN,yBAAyB,cAAc,CAAC,CAAC,QAAQ;GACjD,GAAI,sBAAsB,QAAQ,GAC9B,EACE,eAAe,kCACb,gBACA,oBACD,EACF,GACD,EAAE;GACN,GAAI,sBAAsB,EAAE,qBAAqB,GAAG,EAAE;GACtD,mBAAmB,qBAAqB;GACzC;AAED,SAAO,IAAI,SAAS,KAAK,UAAU,YAAY,EAAE;GAC/C,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CAAC;UACK,OAAO;AACd,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;;;AAIL,SAAS,0BACP,SACA,wBAC2B;CAI3B,MAAM,aAAa,cACjB,2BACC,sBAAsB,QAAQ,IAC5B,6BAA6B,QAAQ,OAAO,IAC3C,2BAA2B,SAAS,UAAU;CACpD,MAAM,wBACJ,0BAA0B,sBAAsB,QAAQ;AAE1D,QAAO;EACL,MAAM,UAAU,OAAO;EACvB,SAAS,UAAU,OAAO;EAC1B,WAAW;EACX,kBAAkB;EACnB"}
|
|
1
|
+
{"version":3,"file":"get-runtime-info.mjs","names":[],"sources":["../../../src/runtime/handlers/get-runtime-info.ts"],"sourcesContent":["import { getRuntimeLogger } from \"../core/logger\";\nimport type { AgentCapabilities } from \"@ag-ui/core\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { hasLearningContainerConfiguration } from \"../core/learning\";\nimport {\n isA2UIEnabled,\n isIntelligenceRuntime,\n resolveAgents,\n} from \"../core/runtime\";\nimport type {\n AgentDescription,\n RuntimeInfo,\n RuntimeEntitlementResponse,\n ThreadEndpointRuntimeInfo,\n} from \"@copilotkit/shared\";\nimport type { RuntimeLicenseStatus } from \"@copilotkit/shared\";\nimport type { LicenseChecker } from \"@copilotkit/license-verifier\";\nimport { VERSION } from \"../core/runtime\";\nimport { PlatformRequestError } from \"../intelligence-platform/client\";\nimport { isTelemetryDisabled } from \"../telemetry/telemetry-client\";\nimport { supportsLocalThreadEndpoints } from \"../runner/agent-runner\";\nimport { isThreadOperationAvailable } from \"./shared/thread-access\";\n\nfunction resolveLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n): RuntimeLicenseStatus {\n if (!licenseChecker) return \"none\";\n const status = licenseChecker.getStatus();\n if (status.warningSeverity === \"none\") return \"valid\";\n if (status.error === \"expired\") return \"expired\";\n if (status.warningSeverity === \"warning\") return \"expiring\";\n if (status.error) return \"invalid\";\n if (status.warningSeverity === \"info\") return \"none\";\n return \"unknown\";\n}\n\n/**\n * Map the structured entitlement authority onto the legacy status consumed by\n * older Core, React, and Angular thread surfaces. A ready managed entitlement\n * is authoritative in both directions. Otherwise, preserve the legacy\n * self-hosted license fallback. A retryable lookup without that fallback\n * remains unknown until it resolves.\n */\nfunction resolveCompatibilityLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n runtimeEntitlements: RuntimeEntitlementResponse | undefined,\n): RuntimeLicenseStatus {\n if (runtimeEntitlements?.status === \"ready\") {\n if (\n runtimeEntitlements.entitlement.source === \"managedOrgSubscription\" ||\n runtimeEntitlements.entitlement.source ===\n \"awsMarketplaceDeploymentLicense\"\n ) {\n return runtimeEntitlements.entitlement.active ? \"valid\" : \"none\";\n }\n\n if (runtimeEntitlements.entitlement.active) {\n return \"valid\";\n }\n }\n\n const legacyLicenseStatus = resolveLicenseStatus(licenseChecker);\n if (\n legacyLicenseStatus === \"none\" &&\n runtimeEntitlements?.status !== \"ready\" &&\n runtimeEntitlements?.error.retryable\n ) {\n return \"unknown\";\n }\n\n return legacyLicenseStatus;\n}\n\ninterface HandleGetRuntimeInfoParameters {\n runtime: CopilotRuntimeLike;\n request: Request;\n threadEndpointsEnabled?: boolean;\n singleRouteResourceOperationsEnabled?: boolean;\n}\n\n/**\n * Resolve structured Runtime entitlements for configured Intelligence runtimes.\n *\n * Dependency failures are deliberately converted to a stable unavailable\n * diagnostic so `/info` remains an availability endpoint. The underlying\n * error is not exposed because it may contain upstream response details.\n */\nasync function resolveRuntimeEntitlements(\n runtime: CopilotRuntimeLike,\n): Promise<RuntimeEntitlementResponse | undefined> {\n if (!isIntelligenceRuntime(runtime)) {\n return undefined;\n }\n\n try {\n return await runtime.intelligence.getRuntimeEntitlements();\n } catch (error) {\n if (error instanceof PlatformRequestError && error.retryable === false) {\n return {\n status: \"misconfigured\",\n error: {\n code: \"runtime_entitlements_misconfigured\",\n message: \"Runtime entitlement lookup is misconfigured\",\n retryable: false,\n },\n };\n }\n\n return {\n status: \"unavailable\",\n error: {\n code: \"runtime_entitlements_unavailable\",\n message: \"Runtime entitlement lookup failed\",\n retryable: true,\n },\n };\n }\n}\n\nexport async function handleGetRuntimeInfo({\n runtime,\n request,\n threadEndpointsEnabled = true,\n singleRouteResourceOperationsEnabled = false,\n}: HandleGetRuntimeInfoParameters) {\n try {\n const runtimeEntitlementsPromise = resolveRuntimeEntitlements(runtime);\n const webEnabled =\n !isIntelligenceRuntime(runtime) || runtime.identifyUser !== undefined;\n const agents = webEnabled\n ? await resolveAgents(runtime.agents, request)\n : {};\n\n const agentEntries = await Promise.all(\n Object.entries(agents).map(async ([name, agent]) => {\n let capabilities: AgentCapabilities | undefined;\n try {\n capabilities = agent.getCapabilities\n ? await agent.getCapabilities()\n : undefined;\n } catch (error) {\n // Per-agent isolation: a single agent failing to report capabilities\n // must not take down the entire /info endpoint.\n getRuntimeLogger(runtime).warn(\n { err: error, agentId: name },\n `Failed to fetch capabilities for agent \"${name}\"`,\n );\n capabilities = undefined;\n }\n\n const description: AgentDescription = {\n name,\n description: agent.description,\n className: agent.constructor.name,\n ...(capabilities ? { capabilities } : {}),\n };\n\n return [name, description] as const;\n }),\n );\n\n const agentsDict: Record<string, AgentDescription> =\n Object.fromEntries(agentEntries);\n const runtimeEntitlements = await runtimeEntitlementsPromise;\n // Verified on first use, not at construction (see getLicenseChecker).\n const licenseChecker = isIntelligenceRuntime(runtime)\n ? await runtime.getLicenseChecker?.()\n : undefined;\n\n const runtimeInfo: RuntimeInfo = {\n version: VERSION,\n agents: agentsDict,\n audioFileTranscriptionEnabled:\n webEnabled && !!runtime.transcriptionService,\n mode: runtime.mode,\n threadEndpoints: resolveThreadEndpointInfo(\n runtime,\n threadEndpointsEnabled && webEnabled,\n ),\n ...(singleRouteResourceOperationsEnabled\n ? {\n singleRoute: {\n resourceOperations: true,\n threadEndpoints: resolveThreadEndpointInfo(runtime, webEnabled),\n },\n }\n : {}),\n // Advertised unconditionally. Multi-route runtimes expose the dedicated\n // POST /agent/:agentId/suggest path; single-route clients fall back to a\n // client-side run (they don't construct the single-route envelope for\n // suggest). The flag lets multi-route clients detect the stateless path.\n suggestions: webEnabled,\n ...(isIntelligenceRuntime(runtime) && webEnabled\n ? {\n intelligence: {\n wsUrl: runtime.intelligence.ɵgetClientWsUrl(),\n },\n inspectorMetadata: true,\n ...(hasLearningContainerConfiguration(runtime)\n ? { inspectorLearning: true }\n : {}),\n }\n : {}),\n // Legacy flat flag, kept for older clients. The `a2ui` object below is\n // the source of truth: it preserves the per-agent scoping that this\n // boolean discards (see CopilotKit/CopilotKit#5369). Both go through the\n // shared isA2UIEnabled() predicate so an explicit `enabled: false`\n // disables a2ui here exactly as it does on the run path.\n a2uiEnabled: webEnabled && isA2UIEnabled(runtime.a2ui),\n ...(webEnabled && isA2UIEnabled(runtime.a2ui)\n ? {\n a2ui: {\n enabled: true,\n ...(runtime.a2ui.agents ? { agents: runtime.a2ui.agents } : {}),\n },\n }\n : {}),\n openGenerativeUIEnabled: webEnabled && !!runtime.openGenerativeUI,\n ...(isIntelligenceRuntime(runtime)\n ? {\n licenseStatus: resolveCompatibilityLicenseStatus(\n licenseChecker,\n runtimeEntitlements,\n ),\n }\n : {}),\n ...(runtimeEntitlements ? { runtimeEntitlements } : {}),\n telemetryDisabled: isTelemetryDisabled(),\n };\n\n return new Response(JSON.stringify(runtimeInfo), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (error) {\n return new Response(\n JSON.stringify({\n error: \"Failed to retrieve runtime information\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n\nfunction resolveThreadEndpointInfo(\n runtime: CopilotRuntimeLike,\n threadEndpointsEnabled: boolean,\n): ThreadEndpointRuntimeInfo {\n // A local route is advertised only when the Thread access policy lets it\n // serve requests: without identity, list is refused by default while\n // reading a Thread by id is not.\n const available = (operation: \"list\" | \"read\") =>\n threadEndpointsEnabled &&\n (isIntelligenceRuntime(runtime) ||\n (supportsLocalThreadEndpoints(runtime.runner) &&\n isThreadOperationAvailable(runtime, operation)));\n const managedThreadMetadata =\n threadEndpointsEnabled && isIntelligenceRuntime(runtime);\n\n return {\n list: available(\"list\"),\n inspect: available(\"read\"),\n mutations: managedThreadMetadata,\n realtimeMetadata: managedThreadMetadata,\n };\n}\n"],"mappings":";;;;;;;;;AAuBA,SAAS,qBACP,gBACsB;AACtB,KAAI,CAAC,eAAgB,QAAO;CAC5B,MAAM,SAAS,eAAe,WAAW;AACzC,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,KAAI,OAAO,UAAU,UAAW,QAAO;AACvC,KAAI,OAAO,oBAAoB,UAAW,QAAO;AACjD,KAAI,OAAO,MAAO,QAAO;AACzB,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,QAAO;;;;;;;;;AAUT,SAAS,kCACP,gBACA,qBACsB;AACtB,KAAI,qBAAqB,WAAW,SAAS;AAC3C,MACE,oBAAoB,YAAY,WA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BAAoB;GAChD,CACF;;;AAIL,SAAS,0BACP,SACA,wBAC2B;CAI3B,MAAM,aAAa,cACjB,2BACC,sBAAsB,QAAQ,IAC5B,6BAA6B,QAAQ,OAAO,IAC3C,2BAA2B,SAAS,UAAU;CACpD,MAAM,wBACJ,0BAA0B,sBAAsB,QAAQ;AAE1D,QAAO;EACL,MAAM,UAAU,OAAO;EACvB,SAAS,UAAU,OAAO;EAC1B,WAAW;EACX,kBAAkB;EACnB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_logger = require('../core/logger.cjs');
|
|
1
2
|
const require_thread_access = require('./shared/thread-access.cjs');
|
|
2
3
|
const require_telemetry_client = require('../telemetry/telemetry-client.cjs');
|
|
3
4
|
const require_runtime = require('../core/runtime.cjs');
|
|
@@ -17,7 +18,7 @@ async function handleConnectAgent({ runtime, request, agentId }) {
|
|
|
17
18
|
try {
|
|
18
19
|
const agent = await require_agent_utils.cloneAgentForRequest(runtime, agentId, request);
|
|
19
20
|
if (agent instanceof Response) return agent;
|
|
20
|
-
const connectRequest = await require_agent_utils.parseConnectRequest(request.clone());
|
|
21
|
+
const connectRequest = await require_agent_utils.parseConnectRequest(request.clone(), require_logger.getRuntimeLogger(runtime));
|
|
21
22
|
if (connectRequest instanceof Response) return connectRequest;
|
|
22
23
|
if (require_runtime.isIntelligenceRuntime(runtime)) return require_connect.handleIntelligenceConnect({
|
|
23
24
|
runtime,
|
|
@@ -40,13 +41,7 @@ async function handleConnectAgent({ runtime, request, agentId }) {
|
|
|
40
41
|
agent
|
|
41
42
|
});
|
|
42
43
|
} catch (error) {
|
|
43
|
-
|
|
44
|
-
console.error("Error stack:", error instanceof Error ? error.stack : "No stack trace");
|
|
45
|
-
console.error("Error details:", {
|
|
46
|
-
name: error instanceof Error ? error.name : "Unknown",
|
|
47
|
-
message: error instanceof Error ? error.message : String(error),
|
|
48
|
-
cause: error instanceof Error ? error.cause : void 0
|
|
49
|
-
});
|
|
44
|
+
require_logger.getRuntimeLogger(runtime).error({ err: error }, "Error running agent");
|
|
50
45
|
return new Response(JSON.stringify({
|
|
51
46
|
error: "Failed to run agent",
|
|
52
47
|
message: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-connect.cjs","names":["telemetry","cloneAgentForRequest","parseConnectRequest","isIntelligenceRuntime","handleIntelligenceConnect","resolveLocalThreadOwner","handleSseConnect"],"sources":["../../../src/runtime/handlers/handle-connect.ts"],"sourcesContent":["import { handleIntelligenceConnect } from \"./intelligence/connect\";\nimport { handleSseConnect } from \"./sse/connect\";\nimport { resolveLocalThreadOwner } from \"./shared/thread-access\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport type { RunAgentParameters as ConnectAgentParameters } from \"./shared/agent-utils\";\nimport {\n parseConnectRequest,\n cloneAgentForRequest,\n} from \"./shared/agent-utils\";\n\nexport async function handleConnectAgent({\n runtime,\n request,\n agentId,\n}: ConnectAgentParameters) {\n const publicApiKey = request.headers.get(\"x-copilotcloud-public-api-key\");\n void (runtime.telemetry ?? telemetry).capture(\n \"oss.runtime.copilot_request_created\",\n {\n // Connect carries no run input, so there are no forwarded guardrails\n // to read — the v1 middleware this replaced reported false here too.\n \"cloud.guardrails.enabled\": false,\n requestType: \"connect\",\n \"cloud.api_key_provided\": !!publicApiKey,\n ...(publicApiKey ? { \"cloud.public_api_key\": publicApiKey } : {}),\n },\n );\n\n try {\n // Runs on BOTH branches deliberately: this is the only place the connect\n // path validates that `agentId` exists, returning a 404 `Response` for an\n // unknown agent. The intelligence branch below never re-checks the id (it\n // hands `agentId` straight to `ɵconnectThread`), so this clone/resolve must\n // happen before the branch split or unknown agents would slip through. The\n // SSE branch additionally uses the returned clone's `agent.headers`.\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n // Parse a clone, so `identifyUser` can still read the original body.\n const connectRequest = await parseConnectRequest(request.clone());\n if (connectRequest instanceof Response) {\n return connectRequest;\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceConnect({\n runtime,\n request,\n agentId,\n threadId: connectRequest.input.threadId,\n });\n }\n\n // Replay only the caller's own thread; another identity's thread replays\n // like an unknown one.\n const ownerId = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"connect\",\n });\n if (ownerId instanceof Response) return ownerId;\n\n return handleSseConnect({\n runtime,\n request,\n agentId,\n threadId: connectRequest.input.threadId,\n ownerId,\n // Pass the per-request clone so its server-configured `agent.headers` are\n // folded into the merged header set threaded into `runner.connect`. That\n // merge is forward-looking plumbing — no shipped runner consumes\n // connect-path headers yet; see the note in `sse/connect.ts`.\n agent,\n });\n } catch (error) {\n
|
|
1
|
+
{"version":3,"file":"handle-connect.cjs","names":["telemetry","cloneAgentForRequest","parseConnectRequest","getRuntimeLogger","isIntelligenceRuntime","handleIntelligenceConnect","resolveLocalThreadOwner","handleSseConnect"],"sources":["../../../src/runtime/handlers/handle-connect.ts"],"sourcesContent":["import { handleIntelligenceConnect } from \"./intelligence/connect\";\nimport { handleSseConnect } from \"./sse/connect\";\nimport { resolveLocalThreadOwner } from \"./shared/thread-access\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { getRuntimeLogger } from \"../core/logger\";\nimport { telemetry } from \"../telemetry\";\nimport type { RunAgentParameters as ConnectAgentParameters } from \"./shared/agent-utils\";\nimport {\n parseConnectRequest,\n cloneAgentForRequest,\n} from \"./shared/agent-utils\";\n\nexport async function handleConnectAgent({\n runtime,\n request,\n agentId,\n}: ConnectAgentParameters) {\n const publicApiKey = request.headers.get(\"x-copilotcloud-public-api-key\");\n void (runtime.telemetry ?? telemetry).capture(\n \"oss.runtime.copilot_request_created\",\n {\n // Connect carries no run input, so there are no forwarded guardrails\n // to read — the v1 middleware this replaced reported false here too.\n \"cloud.guardrails.enabled\": false,\n requestType: \"connect\",\n \"cloud.api_key_provided\": !!publicApiKey,\n ...(publicApiKey ? { \"cloud.public_api_key\": publicApiKey } : {}),\n },\n );\n\n try {\n // Runs on BOTH branches deliberately: this is the only place the connect\n // path validates that `agentId` exists, returning a 404 `Response` for an\n // unknown agent. The intelligence branch below never re-checks the id (it\n // hands `agentId` straight to `ɵconnectThread`), so this clone/resolve must\n // happen before the branch split or unknown agents would slip through. The\n // SSE branch additionally uses the returned clone's `agent.headers`.\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n // Parse a clone, so `identifyUser` can still read the original body.\n const connectRequest = await parseConnectRequest(\n request.clone(),\n getRuntimeLogger(runtime),\n );\n if (connectRequest instanceof Response) {\n return connectRequest;\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceConnect({\n runtime,\n request,\n agentId,\n threadId: connectRequest.input.threadId,\n });\n }\n\n // Replay only the caller's own thread; another identity's thread replays\n // like an unknown one.\n const ownerId = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"connect\",\n });\n if (ownerId instanceof Response) return ownerId;\n\n return handleSseConnect({\n runtime,\n request,\n agentId,\n threadId: connectRequest.input.threadId,\n ownerId,\n // Pass the per-request clone so its server-configured `agent.headers` are\n // folded into the merged header set threaded into `runner.connect`. That\n // merge is forward-looking plumbing — no shipped runner consumes\n // connect-path headers yet; see the note in `sse/connect.ts`.\n agent,\n });\n } catch (error) {\n getRuntimeLogger(runtime).error({ err: error }, \"Error running agent\");\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":";;;;;;;;;AAYA,eAAsB,mBAAmB,EACvC,SACA,SACA,WACyB;CACzB,MAAM,eAAe,QAAQ,QAAQ,IAAI,gCAAgC;AACzE,EAAM,QAAQ,aAAaA,kCAAW,QACpC,uCACA;EAGE,4BAA4B;EAC5B,aAAa;EACb,0BAA0B,CAAC,CAAC;EAC5B,GAAI,eAAe,EAAE,wBAAwB,cAAc,GAAG,EAAE;EACjE,CACF;AAED,KAAI;EAOF,MAAM,QAAQ,MAAMC,yCAAqB,SAAS,SAAS,QAAQ;AACnE,MAAI,iBAAiB,SACnB,QAAO;EAIT,MAAM,iBAAiB,MAAMC,wCAC3B,QAAQ,OAAO,EACfC,gCAAiB,QAAQ,CAC1B;AACD,MAAI,0BAA0B,SAC5B,QAAO;AAGT,MAAIC,sCAAsB,QAAQ,CAChC,QAAOC,0CAA0B;GAC/B;GACA;GACA;GACA,UAAU,eAAe,MAAM;GAChC,CAAC;EAKJ,MAAM,UAAU,MAAMC,8CAAwB;GAC5C;GACA;GACA,WAAW;GACZ,CAAC;AACF,MAAI,mBAAmB,SAAU,QAAO;AAExC,SAAOC,mCAAiB;GACtB;GACA;GACA;GACA,UAAU,eAAe,MAAM;GAC/B;GAKA;GACD,CAAC;UACK,OAAO;AACd,kCAAiB,QAAQ,CAAC,MAAM,EAAE,KAAK,OAAO,EAAE,sBAAsB;AAEtE,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,3 +1,4 @@
|
|
|
1
|
+
import { getRuntimeLogger } from "../core/logger.mjs";
|
|
1
2
|
import { resolveLocalThreadOwner } from "./shared/thread-access.mjs";
|
|
2
3
|
import telemetry from "../telemetry/telemetry-client.mjs";
|
|
3
4
|
import { isIntelligenceRuntime } from "../core/runtime.mjs";
|
|
@@ -17,7 +18,7 @@ async function handleConnectAgent({ runtime, request, agentId }) {
|
|
|
17
18
|
try {
|
|
18
19
|
const agent = await cloneAgentForRequest(runtime, agentId, request);
|
|
19
20
|
if (agent instanceof Response) return agent;
|
|
20
|
-
const connectRequest = await parseConnectRequest(request.clone());
|
|
21
|
+
const connectRequest = await parseConnectRequest(request.clone(), getRuntimeLogger(runtime));
|
|
21
22
|
if (connectRequest instanceof Response) return connectRequest;
|
|
22
23
|
if (isIntelligenceRuntime(runtime)) return handleIntelligenceConnect({
|
|
23
24
|
runtime,
|
|
@@ -40,13 +41,7 @@ async function handleConnectAgent({ runtime, request, agentId }) {
|
|
|
40
41
|
agent
|
|
41
42
|
});
|
|
42
43
|
} catch (error) {
|
|
43
|
-
|
|
44
|
-
console.error("Error stack:", error instanceof Error ? error.stack : "No stack trace");
|
|
45
|
-
console.error("Error details:", {
|
|
46
|
-
name: error instanceof Error ? error.name : "Unknown",
|
|
47
|
-
message: error instanceof Error ? error.message : String(error),
|
|
48
|
-
cause: error instanceof Error ? error.cause : void 0
|
|
49
|
-
});
|
|
44
|
+
getRuntimeLogger(runtime).error({ err: error }, "Error running agent");
|
|
50
45
|
return new Response(JSON.stringify({
|
|
51
46
|
error: "Failed to run agent",
|
|
52
47
|
message: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-connect.mjs","names":[],"sources":["../../../src/runtime/handlers/handle-connect.ts"],"sourcesContent":["import { handleIntelligenceConnect } from \"./intelligence/connect\";\nimport { handleSseConnect } from \"./sse/connect\";\nimport { resolveLocalThreadOwner } from \"./shared/thread-access\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport type { RunAgentParameters as ConnectAgentParameters } from \"./shared/agent-utils\";\nimport {\n parseConnectRequest,\n cloneAgentForRequest,\n} from \"./shared/agent-utils\";\n\nexport async function handleConnectAgent({\n runtime,\n request,\n agentId,\n}: ConnectAgentParameters) {\n const publicApiKey = request.headers.get(\"x-copilotcloud-public-api-key\");\n void (runtime.telemetry ?? telemetry).capture(\n \"oss.runtime.copilot_request_created\",\n {\n // Connect carries no run input, so there are no forwarded guardrails\n // to read — the v1 middleware this replaced reported false here too.\n \"cloud.guardrails.enabled\": false,\n requestType: \"connect\",\n \"cloud.api_key_provided\": !!publicApiKey,\n ...(publicApiKey ? { \"cloud.public_api_key\": publicApiKey } : {}),\n },\n );\n\n try {\n // Runs on BOTH branches deliberately: this is the only place the connect\n // path validates that `agentId` exists, returning a 404 `Response` for an\n // unknown agent. The intelligence branch below never re-checks the id (it\n // hands `agentId` straight to `ɵconnectThread`), so this clone/resolve must\n // happen before the branch split or unknown agents would slip through. The\n // SSE branch additionally uses the returned clone's `agent.headers`.\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n // Parse a clone, so `identifyUser` can still read the original body.\n const connectRequest = await parseConnectRequest(request.clone());\n if (connectRequest instanceof Response) {\n return connectRequest;\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceConnect({\n runtime,\n request,\n agentId,\n threadId: connectRequest.input.threadId,\n });\n }\n\n // Replay only the caller's own thread; another identity's thread replays\n // like an unknown one.\n const ownerId = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"connect\",\n });\n if (ownerId instanceof Response) return ownerId;\n\n return handleSseConnect({\n runtime,\n request,\n agentId,\n threadId: connectRequest.input.threadId,\n ownerId,\n // Pass the per-request clone so its server-configured `agent.headers` are\n // folded into the merged header set threaded into `runner.connect`. That\n // merge is forward-looking plumbing — no shipped runner consumes\n // connect-path headers yet; see the note in `sse/connect.ts`.\n agent,\n });\n } catch (error) {\n
|
|
1
|
+
{"version":3,"file":"handle-connect.mjs","names":[],"sources":["../../../src/runtime/handlers/handle-connect.ts"],"sourcesContent":["import { handleIntelligenceConnect } from \"./intelligence/connect\";\nimport { handleSseConnect } from \"./sse/connect\";\nimport { resolveLocalThreadOwner } from \"./shared/thread-access\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { getRuntimeLogger } from \"../core/logger\";\nimport { telemetry } from \"../telemetry\";\nimport type { RunAgentParameters as ConnectAgentParameters } from \"./shared/agent-utils\";\nimport {\n parseConnectRequest,\n cloneAgentForRequest,\n} from \"./shared/agent-utils\";\n\nexport async function handleConnectAgent({\n runtime,\n request,\n agentId,\n}: ConnectAgentParameters) {\n const publicApiKey = request.headers.get(\"x-copilotcloud-public-api-key\");\n void (runtime.telemetry ?? telemetry).capture(\n \"oss.runtime.copilot_request_created\",\n {\n // Connect carries no run input, so there are no forwarded guardrails\n // to read — the v1 middleware this replaced reported false here too.\n \"cloud.guardrails.enabled\": false,\n requestType: \"connect\",\n \"cloud.api_key_provided\": !!publicApiKey,\n ...(publicApiKey ? { \"cloud.public_api_key\": publicApiKey } : {}),\n },\n );\n\n try {\n // Runs on BOTH branches deliberately: this is the only place the connect\n // path validates that `agentId` exists, returning a 404 `Response` for an\n // unknown agent. The intelligence branch below never re-checks the id (it\n // hands `agentId` straight to `ɵconnectThread`), so this clone/resolve must\n // happen before the branch split or unknown agents would slip through. The\n // SSE branch additionally uses the returned clone's `agent.headers`.\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n // Parse a clone, so `identifyUser` can still read the original body.\n const connectRequest = await parseConnectRequest(\n request.clone(),\n getRuntimeLogger(runtime),\n );\n if (connectRequest instanceof Response) {\n return connectRequest;\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceConnect({\n runtime,\n request,\n agentId,\n threadId: connectRequest.input.threadId,\n });\n }\n\n // Replay only the caller's own thread; another identity's thread replays\n // like an unknown one.\n const ownerId = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"connect\",\n });\n if (ownerId instanceof Response) return ownerId;\n\n return handleSseConnect({\n runtime,\n request,\n agentId,\n threadId: connectRequest.input.threadId,\n ownerId,\n // Pass the per-request clone so its server-configured `agent.headers` are\n // folded into the merged header set threaded into `runner.connect`. That\n // merge is forward-looking plumbing — no shipped runner consumes\n // connect-path headers yet; see the note in `sse/connect.ts`.\n agent,\n });\n } catch (error) {\n getRuntimeLogger(runtime).error({ err: error }, \"Error running agent\");\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":";;;;;;;;;AAYA,eAAsB,mBAAmB,EACvC,SACA,SACA,WACyB;CACzB,MAAM,eAAe,QAAQ,QAAQ,IAAI,gCAAgC;AACzE,EAAM,QAAQ,aAAa,WAAW,QACpC,uCACA;EAGE,4BAA4B;EAC5B,aAAa;EACb,0BAA0B,CAAC,CAAC;EAC5B,GAAI,eAAe,EAAE,wBAAwB,cAAc,GAAG,EAAE;EACjE,CACF;AAED,KAAI;EAOF,MAAM,QAAQ,MAAM,qBAAqB,SAAS,SAAS,QAAQ;AACnE,MAAI,iBAAiB,SACnB,QAAO;EAIT,MAAM,iBAAiB,MAAM,oBAC3B,QAAQ,OAAO,EACf,iBAAiB,QAAQ,CAC1B;AACD,MAAI,0BAA0B,SAC5B,QAAO;AAGT,MAAI,sBAAsB,QAAQ,CAChC,QAAO,0BAA0B;GAC/B;GACA;GACA;GACA,UAAU,eAAe,MAAM;GAChC,CAAC;EAKJ,MAAM,UAAU,MAAM,wBAAwB;GAC5C;GACA;GACA,WAAW;GACZ,CAAC;AACF,MAAI,mBAAmB,SAAU,QAAO;AAExC,SAAO,iBAAiB;GACtB;GACA;GACA;GACA,UAAU,eAAe,MAAM;GAC/B;GAKA;GACD,CAAC;UACK,OAAO;AACd,mBAAiB,QAAQ,CAAC,MAAM,EAAE,KAAK,OAAO,EAAE,sBAAsB;AAEtE,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,3 +1,4 @@
|
|
|
1
|
+
const require_logger = require('../core/logger.cjs');
|
|
1
2
|
const require_agent_runner = require('../runner/agent-runner.cjs');
|
|
2
3
|
const require_analytics_context = require('../intelligence-platform/analytics-context.cjs');
|
|
3
4
|
const require_thread_access = require('./shared/thread-access.cjs');
|
|
@@ -24,7 +25,7 @@ async function handleRunAgent({ runtime, request, agentId }) {
|
|
|
24
25
|
const agent = await require_agent_utils.cloneAgentForRequest(runtime, agentId, request);
|
|
25
26
|
if (agent instanceof Response) return agent;
|
|
26
27
|
agent.agentId = agentId;
|
|
27
|
-
const parsed = await require_agent_utils.parseRunRequest(request.clone());
|
|
28
|
+
const parsed = await require_agent_utils.parseRunRequest(request.clone(), require_logger.getRuntimeLogger(runtime));
|
|
28
29
|
if (parsed instanceof Response) return parsed;
|
|
29
30
|
const { input, analyticsContext } = require_analytics_context.takeAnalyticsContext(parsed);
|
|
30
31
|
let ownerId;
|
|
@@ -78,7 +79,7 @@ async function handleRunAgent({ runtime, request, agentId }) {
|
|
|
78
79
|
input,
|
|
79
80
|
agentId,
|
|
80
81
|
debug: runtime.debug,
|
|
81
|
-
|
|
82
|
+
debugLogger: runtime.debugLogger,
|
|
82
83
|
startTime,
|
|
83
84
|
ownerId
|
|
84
85
|
});
|
|
@@ -91,13 +92,7 @@ async function handleRunAgent({ runtime, request, agentId }) {
|
|
|
91
92
|
phase: "common",
|
|
92
93
|
startTime
|
|
93
94
|
});
|
|
94
|
-
|
|
95
|
-
console.error("Error stack:", error instanceof Error ? error.stack : "No stack trace");
|
|
96
|
-
console.error("Error details:", {
|
|
97
|
-
name: error instanceof Error ? error.name : "Unknown",
|
|
98
|
-
message: error instanceof Error ? error.message : String(error),
|
|
99
|
-
cause: error instanceof Error ? error.cause : void 0
|
|
100
|
-
});
|
|
95
|
+
require_logger.getRuntimeLogger(runtime).error({ err: error }, "Error running agent");
|
|
101
96
|
return new Response(JSON.stringify({
|
|
102
97
|
error: "Failed to run agent",
|
|
103
98
|
message: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-run.cjs","names":["telemetry","readGuardrailsEnabled","cloneAgentForRequest","parseRunRequest","takeAnalyticsContext","isIntelligenceRuntime","resolveLocalThreadOwner","enforcesThreadOwnership","threadAccessDeniedResponse","attachIntelligenceEnterpriseLearning","handleIntelligenceRun","handleSseRun"],"sources":["../../../src/runtime/handlers/handle-run.ts"],"sourcesContent":["import { readCopilotKitUIEnvelope } from \"@copilotkit/shared\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport { readGuardrailsEnabled } from \"./shared/cloud-telemetry\";\nimport type { RunAgentParameters } from \"./shared/agent-utils\";\nimport {\n attachIntelligenceEnterpriseLearning,\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { takeAnalyticsContext } from \"../intelligence-platform/analytics-context\";\nimport { handleSseRun } from \"./sse/run\";\nimport { getRuntimeErrorReporter } from \"../core/runtime-error-reporter\";\nimport { enforcesThreadOwnership } from \"../runner/agent-runner\";\nimport {\n resolveLocalThreadOwner,\n threadAccessDeniedResponse,\n} from \"./shared/thread-access\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n const startTime = Date.now();\n const publicApiKey = request.headers.get(\"x-copilotcloud-public-api-key\");\n void (runtime.telemetry ?? telemetry).capture(\n \"oss.runtime.copilot_request_created\",\n {\n \"cloud.guardrails.enabled\": await readGuardrailsEnabled(request),\n requestType: \"run\",\n \"cloud.api_key_provided\": !!publicApiKey,\n ...(publicApiKey ? { \"cloud.public_api_key\": publicApiKey } : {}),\n },\n );\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n // Ensure the clone carries the registry key so InMemoryAgentRunner can\n // tag historic runs with the correct agentId for filtering.\n agent.agentId = agentId;\n\n // Parse the body before configuring middleware: middleware configuration\n // needs the A2UI catalog signal the React provider forwards (see\n // `a2uiCatalogAvailable` below). Middleware is applied to the agent here;\n // the run itself is kicked off later, so this is safe. The body is read\n // from a clone, so `identifyUser` can still read the original request.\n const parsed = await parseRunRequest(request.clone());\n if (parsed instanceof Response) {\n return parsed;\n }\n // An app's analytics context is for Intelligence's lock request alone, so\n // it is taken off the input before anything hands that input to an agent.\n const { input, analyticsContext } = takeAnalyticsContext(parsed);\n\n // A thread belongs to the identity of its first run. Running needs no\n // configured identity (anonymous runs keep working), but nobody may add to\n // a thread that another identity owns.\n let ownerId: string | undefined;\n if (!isIntelligenceRuntime(runtime)) {\n const owner = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"run\",\n });\n if (owner instanceof Response) return owner;\n if (\n enforcesThreadOwnership(runtime.runner) &&\n !(await runtime.runner.isThreadAccessible(input.threadId, {\n ownerId: owner,\n }))\n ) {\n return threadAccessDeniedResponse();\n }\n ownerId = owner;\n }\n\n // `<CopilotKit a2ui={{ catalog }}>` forwards this flag on every run. Its\n // presence alone is enough to turn A2UI on end-to-end — no runtime-side\n // `a2ui` config required.\n const providerA2UIHasCatalog =\n (input.forwardedProps as Record<string, unknown> | undefined)\n ?.a2uiCatalogAvailable === true;\n // The generative UI envelope (`forwardedProps.copilotkit.ui`) picks the\n // transport of this run.\n const providerGenerativeUITransport = readCopilotKitUIEnvelope(\n input.forwardedProps,\n )?.metadata.extensions.copilotkit_transport;\n\n configureAgentForRequest({\n runtime,\n request,\n agentId,\n agent,\n providerA2UIHasCatalog,\n providerGenerativeUITransport,\n isMcpProxyRequest: Object.prototype.hasOwnProperty.call(\n input.forwardedProps ?? {},\n \"__proxiedMCPRequest\",\n ),\n });\n const memoryResponse = await attachIntelligenceEnterpriseLearning({\n runtime,\n request,\n agent,\n });\n if (memoryResponse instanceof Response) return memoryResponse;\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 analyticsContext,\n startTime,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug: runtime.debug,\n
|
|
1
|
+
{"version":3,"file":"handle-run.cjs","names":["telemetry","readGuardrailsEnabled","cloneAgentForRequest","parseRunRequest","getRuntimeLogger","takeAnalyticsContext","isIntelligenceRuntime","resolveLocalThreadOwner","enforcesThreadOwnership","threadAccessDeniedResponse","attachIntelligenceEnterpriseLearning","handleIntelligenceRun","handleSseRun"],"sources":["../../../src/runtime/handlers/handle-run.ts"],"sourcesContent":["import { readCopilotKitUIEnvelope } from \"@copilotkit/shared\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { getRuntimeLogger } from \"../core/logger\";\nimport { telemetry } from \"../telemetry\";\nimport { readGuardrailsEnabled } from \"./shared/cloud-telemetry\";\nimport type { RunAgentParameters } from \"./shared/agent-utils\";\nimport {\n attachIntelligenceEnterpriseLearning,\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { takeAnalyticsContext } from \"../intelligence-platform/analytics-context\";\nimport { handleSseRun } from \"./sse/run\";\nimport { getRuntimeErrorReporter } from \"../core/runtime-error-reporter\";\nimport { enforcesThreadOwnership } from \"../runner/agent-runner\";\nimport {\n resolveLocalThreadOwner,\n threadAccessDeniedResponse,\n} from \"./shared/thread-access\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n const startTime = Date.now();\n const publicApiKey = request.headers.get(\"x-copilotcloud-public-api-key\");\n void (runtime.telemetry ?? telemetry).capture(\n \"oss.runtime.copilot_request_created\",\n {\n \"cloud.guardrails.enabled\": await readGuardrailsEnabled(request),\n requestType: \"run\",\n \"cloud.api_key_provided\": !!publicApiKey,\n ...(publicApiKey ? { \"cloud.public_api_key\": publicApiKey } : {}),\n },\n );\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n // Ensure the clone carries the registry key so InMemoryAgentRunner can\n // tag historic runs with the correct agentId for filtering.\n agent.agentId = agentId;\n\n // Parse the body before configuring middleware: middleware configuration\n // needs the A2UI catalog signal the React provider forwards (see\n // `a2uiCatalogAvailable` below). Middleware is applied to the agent here;\n // the run itself is kicked off later, so this is safe. The body is read\n // from a clone, so `identifyUser` can still read the original request.\n const parsed = await parseRunRequest(\n request.clone(),\n getRuntimeLogger(runtime),\n );\n if (parsed instanceof Response) {\n return parsed;\n }\n // An app's analytics context is for Intelligence's lock request alone, so\n // it is taken off the input before anything hands that input to an agent.\n const { input, analyticsContext } = takeAnalyticsContext(parsed);\n\n // A thread belongs to the identity of its first run. Running needs no\n // configured identity (anonymous runs keep working), but nobody may add to\n // a thread that another identity owns.\n let ownerId: string | undefined;\n if (!isIntelligenceRuntime(runtime)) {\n const owner = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"run\",\n });\n if (owner instanceof Response) return owner;\n if (\n enforcesThreadOwnership(runtime.runner) &&\n !(await runtime.runner.isThreadAccessible(input.threadId, {\n ownerId: owner,\n }))\n ) {\n return threadAccessDeniedResponse();\n }\n ownerId = owner;\n }\n\n // `<CopilotKit a2ui={{ catalog }}>` forwards this flag on every run. Its\n // presence alone is enough to turn A2UI on end-to-end — no runtime-side\n // `a2ui` config required.\n const providerA2UIHasCatalog =\n (input.forwardedProps as Record<string, unknown> | undefined)\n ?.a2uiCatalogAvailable === true;\n // The generative UI envelope (`forwardedProps.copilotkit.ui`) picks the\n // transport of this run.\n const providerGenerativeUITransport = readCopilotKitUIEnvelope(\n input.forwardedProps,\n )?.metadata.extensions.copilotkit_transport;\n\n configureAgentForRequest({\n runtime,\n request,\n agentId,\n agent,\n providerA2UIHasCatalog,\n providerGenerativeUITransport,\n isMcpProxyRequest: Object.prototype.hasOwnProperty.call(\n input.forwardedProps ?? {},\n \"__proxiedMCPRequest\",\n ),\n });\n const memoryResponse = await attachIntelligenceEnterpriseLearning({\n runtime,\n request,\n agent,\n });\n if (memoryResponse instanceof Response) return memoryResponse;\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 analyticsContext,\n startTime,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug: runtime.debug,\n debugLogger: runtime.debugLogger,\n startTime,\n ownerId,\n });\n } catch (error) {\n getRuntimeErrorReporter(runtime)?.report({\n request,\n error,\n operation: \"agent.run\",\n agentId,\n phase: \"common\",\n startTime,\n });\n getRuntimeLogger(runtime).error({ err: error }, \"Error running agent\");\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":";;;;;;;;;;;;;;AAsBA,eAAsB,eAAe,EACnC,SACA,SACA,WACqB;CACrB,MAAM,YAAY,KAAK,KAAK;CAC5B,MAAM,eAAe,QAAQ,QAAQ,IAAI,gCAAgC;AACzE,EAAM,QAAQ,aAAaA,kCAAW,QACpC,uCACA;EACE,4BAA4B,MAAMC,8CAAsB,QAAQ;EAChE,aAAa;EACb,0BAA0B,CAAC,CAAC;EAC5B,GAAI,eAAe,EAAE,wBAAwB,cAAc,GAAG,EAAE;EACjE,CACF;AAED,KAAI;EACF,MAAM,QAAQ,MAAMC,yCAAqB,SAAS,SAAS,QAAQ;AACnE,MAAI,iBAAiB,SACnB,QAAO;AAKT,QAAM,UAAU;EAOhB,MAAM,SAAS,MAAMC,oCACnB,QAAQ,OAAO,EACfC,gCAAiB,QAAQ,CAC1B;AACD,MAAI,k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AAsB;AAEtE,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,3 +1,4 @@
|
|
|
1
|
+
import { getRuntimeLogger } from "../core/logger.mjs";
|
|
1
2
|
import { enforcesThreadOwnership } from "../runner/agent-runner.mjs";
|
|
2
3
|
import { takeAnalyticsContext } from "../intelligence-platform/analytics-context.mjs";
|
|
3
4
|
import { resolveLocalThreadOwner, threadAccessDeniedResponse } from "./shared/thread-access.mjs";
|
|
@@ -24,7 +25,7 @@ async function handleRunAgent({ runtime, request, agentId }) {
|
|
|
24
25
|
const agent = await cloneAgentForRequest(runtime, agentId, request);
|
|
25
26
|
if (agent instanceof Response) return agent;
|
|
26
27
|
agent.agentId = agentId;
|
|
27
|
-
const parsed = await parseRunRequest(request.clone());
|
|
28
|
+
const parsed = await parseRunRequest(request.clone(), getRuntimeLogger(runtime));
|
|
28
29
|
if (parsed instanceof Response) return parsed;
|
|
29
30
|
const { input, analyticsContext } = takeAnalyticsContext(parsed);
|
|
30
31
|
let ownerId;
|
|
@@ -78,7 +79,7 @@ async function handleRunAgent({ runtime, request, agentId }) {
|
|
|
78
79
|
input,
|
|
79
80
|
agentId,
|
|
80
81
|
debug: runtime.debug,
|
|
81
|
-
|
|
82
|
+
debugLogger: runtime.debugLogger,
|
|
82
83
|
startTime,
|
|
83
84
|
ownerId
|
|
84
85
|
});
|
|
@@ -91,13 +92,7 @@ async function handleRunAgent({ runtime, request, agentId }) {
|
|
|
91
92
|
phase: "common",
|
|
92
93
|
startTime
|
|
93
94
|
});
|
|
94
|
-
|
|
95
|
-
console.error("Error stack:", error instanceof Error ? error.stack : "No stack trace");
|
|
96
|
-
console.error("Error details:", {
|
|
97
|
-
name: error instanceof Error ? error.name : "Unknown",
|
|
98
|
-
message: error instanceof Error ? error.message : String(error),
|
|
99
|
-
cause: error instanceof Error ? error.cause : void 0
|
|
100
|
-
});
|
|
95
|
+
getRuntimeLogger(runtime).error({ err: error }, "Error running agent");
|
|
101
96
|
return new Response(JSON.stringify({
|
|
102
97
|
error: "Failed to run agent",
|
|
103
98
|
message: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-run.mjs","names":[],"sources":["../../../src/runtime/handlers/handle-run.ts"],"sourcesContent":["import { readCopilotKitUIEnvelope } from \"@copilotkit/shared\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport { readGuardrailsEnabled } from \"./shared/cloud-telemetry\";\nimport type { RunAgentParameters } from \"./shared/agent-utils\";\nimport {\n attachIntelligenceEnterpriseLearning,\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { takeAnalyticsContext } from \"../intelligence-platform/analytics-context\";\nimport { handleSseRun } from \"./sse/run\";\nimport { getRuntimeErrorReporter } from \"../core/runtime-error-reporter\";\nimport { enforcesThreadOwnership } from \"../runner/agent-runner\";\nimport {\n resolveLocalThreadOwner,\n threadAccessDeniedResponse,\n} from \"./shared/thread-access\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n const startTime = Date.now();\n const publicApiKey = request.headers.get(\"x-copilotcloud-public-api-key\");\n void (runtime.telemetry ?? telemetry).capture(\n \"oss.runtime.copilot_request_created\",\n {\n \"cloud.guardrails.enabled\": await readGuardrailsEnabled(request),\n requestType: \"run\",\n \"cloud.api_key_provided\": !!publicApiKey,\n ...(publicApiKey ? { \"cloud.public_api_key\": publicApiKey } : {}),\n },\n );\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n // Ensure the clone carries the registry key so InMemoryAgentRunner can\n // tag historic runs with the correct agentId for filtering.\n agent.agentId = agentId;\n\n // Parse the body before configuring middleware: middleware configuration\n // needs the A2UI catalog signal the React provider forwards (see\n // `a2uiCatalogAvailable` below). Middleware is applied to the agent here;\n // the run itself is kicked off later, so this is safe. The body is read\n // from a clone, so `identifyUser` can still read the original request.\n const parsed = await parseRunRequest(request.clone());\n if (parsed instanceof Response) {\n return parsed;\n }\n // An app's analytics context is for Intelligence's lock request alone, so\n // it is taken off the input before anything hands that input to an agent.\n const { input, analyticsContext } = takeAnalyticsContext(parsed);\n\n // A thread belongs to the identity of its first run. Running needs no\n // configured identity (anonymous runs keep working), but nobody may add to\n // a thread that another identity owns.\n let ownerId: string | undefined;\n if (!isIntelligenceRuntime(runtime)) {\n const owner = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"run\",\n });\n if (owner instanceof Response) return owner;\n if (\n enforcesThreadOwnership(runtime.runner) &&\n !(await runtime.runner.isThreadAccessible(input.threadId, {\n ownerId: owner,\n }))\n ) {\n return threadAccessDeniedResponse();\n }\n ownerId = owner;\n }\n\n // `<CopilotKit a2ui={{ catalog }}>` forwards this flag on every run. Its\n // presence alone is enough to turn A2UI on end-to-end — no runtime-side\n // `a2ui` config required.\n const providerA2UIHasCatalog =\n (input.forwardedProps as Record<string, unknown> | undefined)\n ?.a2uiCatalogAvailable === true;\n // The generative UI envelope (`forwardedProps.copilotkit.ui`) picks the\n // transport of this run.\n const providerGenerativeUITransport = readCopilotKitUIEnvelope(\n input.forwardedProps,\n )?.metadata.extensions.copilotkit_transport;\n\n configureAgentForRequest({\n runtime,\n request,\n agentId,\n agent,\n providerA2UIHasCatalog,\n providerGenerativeUITransport,\n isMcpProxyRequest: Object.prototype.hasOwnProperty.call(\n input.forwardedProps ?? {},\n \"__proxiedMCPRequest\",\n ),\n });\n const memoryResponse = await attachIntelligenceEnterpriseLearning({\n runtime,\n request,\n agent,\n });\n if (memoryResponse instanceof Response) return memoryResponse;\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 analyticsContext,\n startTime,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug: runtime.debug,\n
|
|
1
|
+
{"version":3,"file":"handle-run.mjs","names":[],"sources":["../../../src/runtime/handlers/handle-run.ts"],"sourcesContent":["import { readCopilotKitUIEnvelope } from \"@copilotkit/shared\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport { getRuntimeLogger } from \"../core/logger\";\nimport { telemetry } from \"../telemetry\";\nimport { readGuardrailsEnabled } from \"./shared/cloud-telemetry\";\nimport type { RunAgentParameters } from \"./shared/agent-utils\";\nimport {\n attachIntelligenceEnterpriseLearning,\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { takeAnalyticsContext } from \"../intelligence-platform/analytics-context\";\nimport { handleSseRun } from \"./sse/run\";\nimport { getRuntimeErrorReporter } from \"../core/runtime-error-reporter\";\nimport { enforcesThreadOwnership } from \"../runner/agent-runner\";\nimport {\n resolveLocalThreadOwner,\n threadAccessDeniedResponse,\n} from \"./shared/thread-access\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n const startTime = Date.now();\n const publicApiKey = request.headers.get(\"x-copilotcloud-public-api-key\");\n void (runtime.telemetry ?? telemetry).capture(\n \"oss.runtime.copilot_request_created\",\n {\n \"cloud.guardrails.enabled\": await readGuardrailsEnabled(request),\n requestType: \"run\",\n \"cloud.api_key_provided\": !!publicApiKey,\n ...(publicApiKey ? { \"cloud.public_api_key\": publicApiKey } : {}),\n },\n );\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n // Ensure the clone carries the registry key so InMemoryAgentRunner can\n // tag historic runs with the correct agentId for filtering.\n agent.agentId = agentId;\n\n // Parse the body before configuring middleware: middleware configuration\n // needs the A2UI catalog signal the React provider forwards (see\n // `a2uiCatalogAvailable` below). Middleware is applied to the agent here;\n // the run itself is kicked off later, so this is safe. The body is read\n // from a clone, so `identifyUser` can still read the original request.\n const parsed = await parseRunRequest(\n request.clone(),\n getRuntimeLogger(runtime),\n );\n if (parsed instanceof Response) {\n return parsed;\n }\n // An app's analytics context is for Intelligence's lock request alone, so\n // it is taken off the input before anything hands that input to an agent.\n const { input, analyticsContext } = takeAnalyticsContext(parsed);\n\n // A thread belongs to the identity of its first run. Running needs no\n // configured identity (anonymous runs keep working), but nobody may add to\n // a thread that another identity owns.\n let ownerId: string | undefined;\n if (!isIntelligenceRuntime(runtime)) {\n const owner = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"run\",\n });\n if (owner instanceof Response) return owner;\n if (\n enforcesThreadOwnership(runtime.runner) &&\n !(await runtime.runner.isThreadAccessible(input.threadId, {\n ownerId: owner,\n }))\n ) {\n return threadAccessDeniedResponse();\n }\n ownerId = owner;\n }\n\n // `<CopilotKit a2ui={{ catalog }}>` forwards this flag on every run. Its\n // presence alone is enough to turn A2UI on end-to-end — no runtime-side\n // `a2ui` config required.\n const providerA2UIHasCatalog =\n (input.forwardedProps as Record<string, unknown> | undefined)\n ?.a2uiCatalogAvailable === true;\n // The generative UI envelope (`forwardedProps.copilotkit.ui`) picks the\n // transport of this run.\n const providerGenerativeUITransport = readCopilotKitUIEnvelope(\n input.forwardedProps,\n )?.metadata.extensions.copilotkit_transport;\n\n configureAgentForRequest({\n runtime,\n request,\n agentId,\n agent,\n providerA2UIHasCatalog,\n providerGenerativeUITransport,\n isMcpProxyRequest: Object.prototype.hasOwnProperty.call(\n input.forwardedProps ?? {},\n \"__proxiedMCPRequest\",\n ),\n });\n const memoryResponse = await attachIntelligenceEnterpriseLearning({\n runtime,\n request,\n agent,\n });\n if (memoryResponse instanceof Response) return memoryResponse;\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 analyticsContext,\n startTime,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug: runtime.debug,\n debugLogger: runtime.debugLogger,\n startTime,\n ownerId,\n });\n } catch (error) {\n getRuntimeErrorReporter(runtime)?.report({\n request,\n error,\n operation: \"agent.run\",\n agentId,\n phase: \"common\",\n startTime,\n });\n getRuntimeLogger(runtime).error({ err: error }, \"Error running agent\");\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":";;;;;;;;;;;;;;AAsBA,eAAsB,eAAe,EACnC,SACA,SACA,WACqB;CACrB,MAAM,YAAY,KAAK,KAAK;CAC5B,MAAM,eAAe,QAAQ,QAAQ,IAAI,gCAAgC;AACzE,EAAM,QAAQ,aAAa,WAAW,QACpC,uCACA;EACE,4BAA4B,MAAM,sBAAsB,QAAQ;EAChE,aAAa;EACb,0BAA0B,CAAC,CAAC;EAC5B,GAAI,eAAe,EAAE,wBAAwB,cAAc,GAAG,EAAE;EACjE,CACF;AAED,KAAI;EACF,MAAM,QAAQ,MAAM,qBAAqB,SAAS,SAAS,QAAQ;AACnE,MAAI,iBAAiB,SACnB,QAAO;AAKT,QAAM,UAAU;EAOhB,MAAM,SAAS,MAAM,gBACnB,QAAQ,OAAO,EACf,iBAAiB,QAAQ,CAC1B;AACD,MAAI,kBAAkB,SACpB,QA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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,3 +1,4 @@
|
|
|
1
|
+
const require_logger = require('../core/logger.cjs');
|
|
1
2
|
const require_json_response = require('./shared/json-response.cjs');
|
|
2
3
|
const require_intelligence_utils = require('./shared/intelligence-utils.cjs');
|
|
3
4
|
const require_resolve_intelligence_user = require('./shared/resolve-intelligence-user.cjs');
|
|
@@ -85,7 +86,7 @@ async function handleStopAgent({ runtime, request, agentId, threadId }) {
|
|
|
85
86
|
headers: { "Content-Type": "application/json" }
|
|
86
87
|
});
|
|
87
88
|
} catch (error) {
|
|
88
|
-
|
|
89
|
+
require_logger.getRuntimeLogger(runtime).error({ err: error }, "Error stopping agent run");
|
|
89
90
|
return new Response(JSON.stringify({
|
|
90
91
|
error: "Failed to stop agent",
|
|
91
92
|
message: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-stop.cjs","names":["isHandlerResponse","isIntelligenceRuntime","resolveLocalThreadOwner","resolveIntelligenceUser","getPlatformErrorStatus","resolveAgents","EventType"],"sources":["../../../src/runtime/handlers/handle-stop.ts"],"sourcesContent":["import type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { isIntelligenceRuntime, resolveAgents } from \"../core/runtime\";\nimport { EventType } from \"@ag-ui/client\";\nimport { resolveIntelligenceUser } from \"./shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"./shared/json-response\";\nimport { getPlatformErrorStatus } from \"./shared/intelligence-utils\";\nimport { resolveLocalThreadOwner } from \"./shared/thread-access\";\n\ninterface StopAgentParameters {\n request: Request;\n runtime: CopilotRuntimeLike;\n agentId: string;\n threadId: string;\n}\n\n/** Read `{ runId? }` from a stop request body; a 400 Response when the body is not a valid scope. */\nasync function parseStopScope(\n request: Request,\n): Promise<{ runId?: string } | Response> {\n try {\n const raw = await request.text();\n const body: unknown = raw.trim() ? JSON.parse(raw) : {};\n if (typeof body !== \"object\" || body === null || Array.isArray(body)) {\n return Response.json({ error: \"Invalid stop request\" }, { status: 400 });\n }\n // Only `runId` is allowed. A misspelt key must not fall through to a\n // thread-wide stop, because a stop cannot be undone.\n if (Object.keys(body).some((key) => key !== \"runId\")) {\n return Response.json({ error: \"Invalid stop request\" }, { status: 400 });\n }\n if (!(\"runId\" in body)) return {};\n if (typeof body.runId !== \"string\" || !body.runId.trim()) {\n return Response.json({ error: \"Invalid runId\" }, { status: 400 });\n }\n return { runId: body.runId };\n } catch {\n return Response.json({ error: \"Invalid stop request\" }, { status: 400 });\n }\n}\n\n/** Stop an active run after applying the runtime's application identity policy. */\nexport async function handleStopAgent({\n runtime,\n request,\n agentId,\n threadId,\n}: StopAgentParameters): Promise<Response> {\n try {\n // Parse the optional run scope for every runtime kind, from a clone so an\n // identity callback can still read the original body. No body or `{}`\n // keeps the thread-wide stop existing clients rely on.\n const scope = await parseStopScope(request.clone());\n if (isHandlerResponse(scope)) return scope;\n const { runId } = scope;\n let stopThreadId = threadId;\n let ownerId: string | undefined;\n if (!isIntelligenceRuntime(runtime)) {\n // A run on another identity's thread reports \"no active run\".\n const owner = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"stop\",\n });\n if (isHandlerResponse(owner)) return owner;\n ownerId = owner;\n } else {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n try {\n const thread = await runtime.intelligence.getThread({\n threadId,\n userId: user.id,\n });\n if (!thread || typeof thread.id !== \"string\" || !thread.id.trim()) {\n return Response.json(\n { error: \"Invalid thread response\" },\n { status: 502 },\n );\n }\n if (thread.agentId !== undefined && thread.agentId !== agentId) {\n return Response.json(\n { error: \"Thread access denied\" },\n { status: 403 },\n );\n }\n stopThreadId = thread.id;\n } catch (error) {\n const status = getPlatformErrorStatus(error);\n return Response.json(\n { error: \"Thread access denied\" },\n { status: status && status >= 400 && status < 500 ? status : 502 },\n );\n }\n }\n const agents = await resolveAgents(runtime.agents, request);\n\n if (!agents[agentId]) {\n return new Response(\n JSON.stringify({\n error: \"Agent not found\",\n message: `Agent '${agentId}' does not exist`,\n }),\n {\n status: 404,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n const stopped = await runtime.runner.stop({\n threadId: stopThreadId,\n ...(runId === undefined ? {} : { runId }),\n ...(ownerId === undefined ? {} : { ownerId }),\n });\n\n if (!stopped) {\n return new Response(\n JSON.stringify({\n stopped: false,\n message:\n runId === undefined\n ? `No active run for thread '${threadId}'.`\n : `Run '${runId}' is not the active run for thread '${threadId}'.`,\n }),\n {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n return new Response(\n JSON.stringify({\n stopped: true,\n interrupt: {\n type: EventType.RUN_ERROR,\n message: \"Run stopped by user\",\n code: \"STOPPED\",\n },\n }),\n {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n } catch (error) {\n
|
|
1
|
+
{"version":3,"file":"handle-stop.cjs","names":["isHandlerResponse","isIntelligenceRuntime","resolveLocalThreadOwner","resolveIntelligenceUser","getPlatformErrorStatus","resolveAgents","EventType"],"sources":["../../../src/runtime/handlers/handle-stop.ts"],"sourcesContent":["import type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { isIntelligenceRuntime, resolveAgents } from \"../core/runtime\";\nimport { getRuntimeLogger } from \"../core/logger\";\nimport { EventType } from \"@ag-ui/client\";\nimport { resolveIntelligenceUser } from \"./shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"./shared/json-response\";\nimport { getPlatformErrorStatus } from \"./shared/intelligence-utils\";\nimport { resolveLocalThreadOwner } from \"./shared/thread-access\";\n\ninterface StopAgentParameters {\n request: Request;\n runtime: CopilotRuntimeLike;\n agentId: string;\n threadId: string;\n}\n\n/** Read `{ runId? }` from a stop request body; a 400 Response when the body is not a valid scope. */\nasync function parseStopScope(\n request: Request,\n): Promise<{ runId?: string } | Response> {\n try {\n const raw = await request.text();\n const body: unknown = raw.trim() ? JSON.parse(raw) : {};\n if (typeof body !== \"object\" || body === null || Array.isArray(body)) {\n return Response.json({ error: \"Invalid stop request\" }, { status: 400 });\n }\n // Only `runId` is allowed. A misspelt key must not fall through to a\n // thread-wide stop, because a stop cannot be undone.\n if (Object.keys(body).some((key) => key !== \"runId\")) {\n return Response.json({ error: \"Invalid stop request\" }, { status: 400 });\n }\n if (!(\"runId\" in body)) return {};\n if (typeof body.runId !== \"string\" || !body.runId.trim()) {\n return Response.json({ error: \"Invalid runId\" }, { status: 400 });\n }\n return { runId: body.runId };\n } catch {\n return Response.json({ error: \"Invalid stop request\" }, { status: 400 });\n }\n}\n\n/** Stop an active run after applying the runtime's application identity policy. */\nexport async function handleStopAgent({\n runtime,\n request,\n agentId,\n threadId,\n}: StopAgentParameters): Promise<Response> {\n try {\n // Parse the optional run scope for every runtime kind, from a clone so an\n // identity callback can still read the original body. No body or `{}`\n // keeps the thread-wide stop existing clients rely on.\n const scope = await parseStopScope(request.clone());\n if (isHandlerResponse(scope)) return scope;\n const { runId } = scope;\n let stopThreadId = threadId;\n let ownerId: string | undefined;\n if (!isIntelligenceRuntime(runtime)) {\n // A run on another identity's thread reports \"no active run\".\n const owner = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"stop\",\n });\n if (isHandlerResponse(owner)) return owner;\n ownerId = owner;\n } else {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n try {\n const thread = await runtime.intelligence.getThread({\n threadId,\n userId: user.id,\n });\n if (!thread || typeof thread.id !== \"string\" || !thread.id.trim()) {\n return Response.json(\n { error: \"Invalid thread response\" },\n { status: 502 },\n );\n }\n if (thread.agentId !== undefined && thread.agentId !== agentId) {\n return Response.json(\n { error: \"Thread access denied\" },\n { status: 403 },\n );\n }\n stopThreadId = thread.id;\n } catch (error) {\n const status = getPlatformErrorStatus(error);\n return Response.json(\n { error: \"Thread access denied\" },\n { status: status && status >= 400 && status < 500 ? status : 502 },\n );\n }\n }\n const agents = await resolveAgents(runtime.agents, request);\n\n if (!agents[agentId]) {\n return new Response(\n JSON.stringify({\n error: \"Agent not found\",\n message: `Agent '${agentId}' does not exist`,\n }),\n {\n status: 404,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n const stopped = await runtime.runner.stop({\n threadId: stopThreadId,\n ...(runId === undefined ? {} : { runId }),\n ...(ownerId === undefined ? {} : { ownerId }),\n });\n\n if (!stopped) {\n return new Response(\n JSON.stringify({\n stopped: false,\n message:\n runId === undefined\n ? `No active run for thread '${threadId}'.`\n : `Run '${runId}' is not the active run for thread '${threadId}'.`,\n }),\n {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n return new Response(\n JSON.stringify({\n stopped: true,\n interrupt: {\n type: EventType.RUN_ERROR,\n message: \"Run stopped by user\",\n code: \"STOPPED\",\n },\n }),\n {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n } catch (error) {\n getRuntimeLogger(runtime).error({ err: error }, \"Error stopping agent run\");\n\n return new Response(\n JSON.stringify({\n error: \"Failed to stop 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":";;;;;;;;;;AAiBA,eAAe,eACb,SACwC;AACxC,KAAI;EACF,MAAM,MAAM,MAAM,QAAQ,MAAM;EAChC,MAAM,OAAgB,IAAI,MAAM,GAAG,KAAK,MAAM,IAAI,GAAG,EAAE;AACvD,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,MAAM,QAAQ,KAAK,CAClE,QAAO,SAAS,KAAK,EAAE,OAAO,wBAAwB,EAAE,EAAE,QAAQ,KAAK,CAAC;AAI1E,MAAI,OAAO,KAAK,KAAK,CAAC,MAAM,QAAQ,QAAQ,QAAQ,CAClD,QAAO,SAAS,K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,MAAM;AAC5C,WAAO,SAAS,KACd,EAAE,OAAO,wBAAwB,EACjC,EAAE,QAAQ,UAAU,UAAU,OAAO,SAAS,MAAM,SAAS,KAAK,CACnE;;;AAKL,MAAI,EAFW,MAAMC,8BAAc,QAAQ,QAAQ,QAAQ,EAE/C,SACV,QAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,UAAU,QAAQ;GAC5B,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;AASH,MAAI,CANY,MAAM,QAAQ,OAAO,KAAK;GACxC,UAAU;GACV,GAAI,UAAU,SAAY,EAAE,GAAG,EAAE,OAAO;GACxC,GAAI,YAAY,SAAY,EAAE,GAAG,EAAE,SAAS;GAC7C,CAAC,CAGA,QAAO,IAAI,SACT,KAAK,UAAU;GACb,SAAS;GACT,SACE,UAAU,SACN,6BAA6B,SAAS,MACtC,QAAQ,MAAM,sCAAsC,SAAS;GACpE,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;AAGH,SAAO,IAAI,SACT,KAAK,UAAU;GACb,SAAS;GACT,WAAW;IACT,MAAMC,wBAAU;IAChB,SAAS;IACT,MAAM;IACP;GACF,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;UACM,OAAO;AACd,kCAAiB,QAAQ,CAAC,MAAM,EAAE,KAAK,OAAO,EAAE,2BAA2B;AAE3E,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,3 +1,4 @@
|
|
|
1
|
+
import { getRuntimeLogger } from "../core/logger.mjs";
|
|
1
2
|
import { isHandlerResponse } from "./shared/json-response.mjs";
|
|
2
3
|
import { getPlatformErrorStatus } from "./shared/intelligence-utils.mjs";
|
|
3
4
|
import { resolveIntelligenceUser } from "./shared/resolve-intelligence-user.mjs";
|
|
@@ -85,7 +86,7 @@ async function handleStopAgent({ runtime, request, agentId, threadId }) {
|
|
|
85
86
|
headers: { "Content-Type": "application/json" }
|
|
86
87
|
});
|
|
87
88
|
} catch (error) {
|
|
88
|
-
|
|
89
|
+
getRuntimeLogger(runtime).error({ err: error }, "Error stopping agent run");
|
|
89
90
|
return new Response(JSON.stringify({
|
|
90
91
|
error: "Failed to stop agent",
|
|
91
92
|
message: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-stop.mjs","names":[],"sources":["../../../src/runtime/handlers/handle-stop.ts"],"sourcesContent":["import type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { isIntelligenceRuntime, resolveAgents } from \"../core/runtime\";\nimport { EventType } from \"@ag-ui/client\";\nimport { resolveIntelligenceUser } from \"./shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"./shared/json-response\";\nimport { getPlatformErrorStatus } from \"./shared/intelligence-utils\";\nimport { resolveLocalThreadOwner } from \"./shared/thread-access\";\n\ninterface StopAgentParameters {\n request: Request;\n runtime: CopilotRuntimeLike;\n agentId: string;\n threadId: string;\n}\n\n/** Read `{ runId? }` from a stop request body; a 400 Response when the body is not a valid scope. */\nasync function parseStopScope(\n request: Request,\n): Promise<{ runId?: string } | Response> {\n try {\n const raw = await request.text();\n const body: unknown = raw.trim() ? JSON.parse(raw) : {};\n if (typeof body !== \"object\" || body === null || Array.isArray(body)) {\n return Response.json({ error: \"Invalid stop request\" }, { status: 400 });\n }\n // Only `runId` is allowed. A misspelt key must not fall through to a\n // thread-wide stop, because a stop cannot be undone.\n if (Object.keys(body).some((key) => key !== \"runId\")) {\n return Response.json({ error: \"Invalid stop request\" }, { status: 400 });\n }\n if (!(\"runId\" in body)) return {};\n if (typeof body.runId !== \"string\" || !body.runId.trim()) {\n return Response.json({ error: \"Invalid runId\" }, { status: 400 });\n }\n return { runId: body.runId };\n } catch {\n return Response.json({ error: \"Invalid stop request\" }, { status: 400 });\n }\n}\n\n/** Stop an active run after applying the runtime's application identity policy. */\nexport async function handleStopAgent({\n runtime,\n request,\n agentId,\n threadId,\n}: StopAgentParameters): Promise<Response> {\n try {\n // Parse the optional run scope for every runtime kind, from a clone so an\n // identity callback can still read the original body. No body or `{}`\n // keeps the thread-wide stop existing clients rely on.\n const scope = await parseStopScope(request.clone());\n if (isHandlerResponse(scope)) return scope;\n const { runId } = scope;\n let stopThreadId = threadId;\n let ownerId: string | undefined;\n if (!isIntelligenceRuntime(runtime)) {\n // A run on another identity's thread reports \"no active run\".\n const owner = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"stop\",\n });\n if (isHandlerResponse(owner)) return owner;\n ownerId = owner;\n } else {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n try {\n const thread = await runtime.intelligence.getThread({\n threadId,\n userId: user.id,\n });\n if (!thread || typeof thread.id !== \"string\" || !thread.id.trim()) {\n return Response.json(\n { error: \"Invalid thread response\" },\n { status: 502 },\n );\n }\n if (thread.agentId !== undefined && thread.agentId !== agentId) {\n return Response.json(\n { error: \"Thread access denied\" },\n { status: 403 },\n );\n }\n stopThreadId = thread.id;\n } catch (error) {\n const status = getPlatformErrorStatus(error);\n return Response.json(\n { error: \"Thread access denied\" },\n { status: status && status >= 400 && status < 500 ? status : 502 },\n );\n }\n }\n const agents = await resolveAgents(runtime.agents, request);\n\n if (!agents[agentId]) {\n return new Response(\n JSON.stringify({\n error: \"Agent not found\",\n message: `Agent '${agentId}' does not exist`,\n }),\n {\n status: 404,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n const stopped = await runtime.runner.stop({\n threadId: stopThreadId,\n ...(runId === undefined ? {} : { runId }),\n ...(ownerId === undefined ? {} : { ownerId }),\n });\n\n if (!stopped) {\n return new Response(\n JSON.stringify({\n stopped: false,\n message:\n runId === undefined\n ? `No active run for thread '${threadId}'.`\n : `Run '${runId}' is not the active run for thread '${threadId}'.`,\n }),\n {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n return new Response(\n JSON.stringify({\n stopped: true,\n interrupt: {\n type: EventType.RUN_ERROR,\n message: \"Run stopped by user\",\n code: \"STOPPED\",\n },\n }),\n {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n } catch (error) {\n
|
|
1
|
+
{"version":3,"file":"handle-stop.mjs","names":[],"sources":["../../../src/runtime/handlers/handle-stop.ts"],"sourcesContent":["import type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { isIntelligenceRuntime, resolveAgents } from \"../core/runtime\";\nimport { getRuntimeLogger } from \"../core/logger\";\nimport { EventType } from \"@ag-ui/client\";\nimport { resolveIntelligenceUser } from \"./shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"./shared/json-response\";\nimport { getPlatformErrorStatus } from \"./shared/intelligence-utils\";\nimport { resolveLocalThreadOwner } from \"./shared/thread-access\";\n\ninterface StopAgentParameters {\n request: Request;\n runtime: CopilotRuntimeLike;\n agentId: string;\n threadId: string;\n}\n\n/** Read `{ runId? }` from a stop request body; a 400 Response when the body is not a valid scope. */\nasync function parseStopScope(\n request: Request,\n): Promise<{ runId?: string } | Response> {\n try {\n const raw = await request.text();\n const body: unknown = raw.trim() ? JSON.parse(raw) : {};\n if (typeof body !== \"object\" || body === null || Array.isArray(body)) {\n return Response.json({ error: \"Invalid stop request\" }, { status: 400 });\n }\n // Only `runId` is allowed. A misspelt key must not fall through to a\n // thread-wide stop, because a stop cannot be undone.\n if (Object.keys(body).some((key) => key !== \"runId\")) {\n return Response.json({ error: \"Invalid stop request\" }, { status: 400 });\n }\n if (!(\"runId\" in body)) return {};\n if (typeof body.runId !== \"string\" || !body.runId.trim()) {\n return Response.json({ error: \"Invalid runId\" }, { status: 400 });\n }\n return { runId: body.runId };\n } catch {\n return Response.json({ error: \"Invalid stop request\" }, { status: 400 });\n }\n}\n\n/** Stop an active run after applying the runtime's application identity policy. */\nexport async function handleStopAgent({\n runtime,\n request,\n agentId,\n threadId,\n}: StopAgentParameters): Promise<Response> {\n try {\n // Parse the optional run scope for every runtime kind, from a clone so an\n // identity callback can still read the original body. No body or `{}`\n // keeps the thread-wide stop existing clients rely on.\n const scope = await parseStopScope(request.clone());\n if (isHandlerResponse(scope)) return scope;\n const { runId } = scope;\n let stopThreadId = threadId;\n let ownerId: string | undefined;\n if (!isIntelligenceRuntime(runtime)) {\n // A run on another identity's thread reports \"no active run\".\n const owner = await resolveLocalThreadOwner({\n runtime,\n request,\n operation: \"stop\",\n });\n if (isHandlerResponse(owner)) return owner;\n ownerId = owner;\n } else {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n try {\n const thread = await runtime.intelligence.getThread({\n threadId,\n userId: user.id,\n });\n if (!thread || typeof thread.id !== \"string\" || !thread.id.trim()) {\n return Response.json(\n { error: \"Invalid thread response\" },\n { status: 502 },\n );\n }\n if (thread.agentId !== undefined && thread.agentId !== agentId) {\n return Response.json(\n { error: \"Thread access denied\" },\n { status: 403 },\n );\n }\n stopThreadId = thread.id;\n } catch (error) {\n const status = getPlatformErrorStatus(error);\n return Response.json(\n { error: \"Thread access denied\" },\n { status: status && status >= 400 && status < 500 ? status : 502 },\n );\n }\n }\n const agents = await resolveAgents(runtime.agents, request);\n\n if (!agents[agentId]) {\n return new Response(\n JSON.stringify({\n error: \"Agent not found\",\n message: `Agent '${agentId}' does not exist`,\n }),\n {\n status: 404,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n const stopped = await runtime.runner.stop({\n threadId: stopThreadId,\n ...(runId === undefined ? {} : { runId }),\n ...(ownerId === undefined ? {} : { ownerId }),\n });\n\n if (!stopped) {\n return new Response(\n JSON.stringify({\n stopped: false,\n message:\n runId === undefined\n ? `No active run for thread '${threadId}'.`\n : `Run '${runId}' is not the active run for thread '${threadId}'.`,\n }),\n {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n return new Response(\n JSON.stringify({\n stopped: true,\n interrupt: {\n type: EventType.RUN_ERROR,\n message: \"Run stopped by user\",\n code: \"STOPPED\",\n },\n }),\n {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n } catch (error) {\n getRuntimeLogger(runtime).error({ err: error }, \"Error stopping agent run\");\n\n return new Response(\n JSON.stringify({\n error: \"Failed to stop 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":";;;;;;;;;;AAiBA,eAAe,eACb,SACwC;AACxC,KAAI;EACF,MAAM,MAAM,MAAM,QAAQ,MAAM;EAChC,MAAM,OAAgB,IAAI,MAAM,GAAG,KAAK,MAAM,IAAI,GAAG,EAAE;AACvD,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,MAAM,QAAQ,KAAK,CAClE,QAAO,SAAS,KAAK,EAAE,OAAO,wBAAwB,EAAE,EAAE,QAAQ,KAAK,CAAC;AAI1E,MAAI,OAAO,KAAK,KAAK,CAAC,MAAM,QAAQ,QAAQ,QAAQ,CAClD,QAAO,SAAS,KAAK,EAAE,OAAO,wBAAwB,EAAE,EAAE,QAAQ,KAAK,CAAC;AAE1E,MAAI,EAAE,WAAW,MAAO,QAAO,EAAE;AACjC,MAAI,OAAO,KAAK,UAAU,YAAY,CAAC,KAAK,MAAM,MAAM,CACtD,QAAO,SAAS,KAAK,EAAE,OAAO,iBAAiB,EAAE,EAAE,QAAQ,KAAK,CAAC;AAEnE,SAAO,EAAE,OAAO,KAAK,OAAO;SACtB;AACN,SAAO,SAAS,KAAK,EAAE,OAAO,wBAAwB,EAAE,EAAE,QAAQ,KAAK,CAAC;;;;AAK5E,eAAsB,gBAAgB,EACpC,SACA,SACA,SACA,YACyC;AACzC,KAAI;EAIF,MAAM,QAAQ,MAAM,eAAe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AAG,EAAE,SAAS;GAC7C,CAAC,CAGA,QAAO,IAAI,SACT,KAAK,UAAU;GACb,SAAS;GACT,SACE,UAAU,SACN,6BAA6B,SAAS,MACtC,QAAQ,MAAM,sCAAsC,SAAS;GACpE,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;AAGH,SAAO,IAAI,SACT,KAAK,UAAU;GACb,SAAS;GACT,WAAW;IACT,MAAM,UAAU;IAChB,SAAS;IACT,MAAM;IACP;GACF,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;UACM,OAAO;AACd,mBAAiB,QAAQ,CAAC,MAAM,EAAE,KAAK,OAAO,EAAE,2BAA2B;AAE3E,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,4 +1,5 @@
|
|
|
1
1
|
const require_header_utils = require('./header-utils.cjs');
|
|
2
|
+
const require_logger = require('../core/logger.cjs');
|
|
2
3
|
const require_analytics_context = require('../intelligence-platform/analytics-context.cjs');
|
|
3
4
|
const require_agent_utils = require('./shared/agent-utils.cjs');
|
|
4
5
|
const require_sse_response = require('./shared/sse-response.cjs');
|
|
@@ -43,7 +44,7 @@ async function handleSuggestAgent({ runtime, request, agentId }) {
|
|
|
43
44
|
const agent = await require_agent_utils.cloneAgentForRequest(runtime, agentId, request);
|
|
44
45
|
if (agent instanceof Response) return agent;
|
|
45
46
|
agent.agentId = agentId;
|
|
46
|
-
const parsed = await require_agent_utils.parseRunRequest(request);
|
|
47
|
+
const parsed = await require_agent_utils.parseRunRequest(request, require_logger.getRuntimeLogger(runtime));
|
|
47
48
|
if (parsed instanceof Response) return parsed;
|
|
48
49
|
const { input } = require_analytics_context.takeAnalyticsContext(parsed);
|
|
49
50
|
const headerCarryingAgent = agent;
|
|
@@ -55,6 +56,7 @@ async function handleSuggestAgent({ runtime, request, agentId }) {
|
|
|
55
56
|
request,
|
|
56
57
|
agentId,
|
|
57
58
|
captureTelemetry: false,
|
|
59
|
+
logger: require_logger.getRuntimeLogger(runtime),
|
|
58
60
|
keepAliveIntervalSeconds: runtime.sseKeepAliveIntervalSeconds,
|
|
59
61
|
observableFactory: () => new rxjs.Observable((subscriber) => {
|
|
60
62
|
const finalizer = (0, _copilotkit_shared.createRunEventFinalizer)();
|