@copilotkit/runtime 1.54.1 → 1.55.0-next.7
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/.eslintrc.js +4 -4
- package/CHANGELOG.md +113 -113
- package/dist/_virtual/_rolldown/runtime.mjs +25 -1
- package/dist/agent/index.cjs +643 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +263 -0
- package/dist/agent/index.d.cts.map +1 -0
- package/dist/agent/index.d.mts +263 -0
- package/dist/agent/index.d.mts.map +1 -0
- package/dist/agent/index.mjs +635 -0
- package/dist/agent/index.mjs.map +1 -0
- package/dist/graphql/message-conversion/agui-to-gql.cjs.map +1 -1
- package/dist/graphql/message-conversion/agui-to-gql.mjs.map +1 -1
- package/dist/lib/integrations/nextjs/app-router.cjs +2 -2
- package/dist/lib/integrations/nextjs/app-router.cjs.map +1 -1
- package/dist/lib/integrations/nextjs/app-router.mjs +1 -1
- package/dist/lib/integrations/nextjs/app-router.mjs.map +1 -1
- package/dist/lib/integrations/node-http/index.cjs +2 -3
- package/dist/lib/integrations/node-http/index.cjs.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +1 -1
- package/dist/lib/integrations/node-http/index.mjs.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.cjs +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts +2 -2
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.mts +3 -3
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.mts.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.mjs +1 -1
- package/dist/lib/runtime/copilot-runtime.cjs +7 -5
- package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.cts +10 -8
- package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.mts +10 -8
- package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.mjs +7 -5
- package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
- package/dist/lib/runtime/telemetry-agent-runner.cjs +2 -2
- package/dist/lib/runtime/telemetry-agent-runner.cjs.map +1 -1
- package/dist/lib/runtime/telemetry-agent-runner.d.cts +2 -1
- package/dist/lib/runtime/telemetry-agent-runner.d.cts.map +1 -1
- package/dist/lib/runtime/telemetry-agent-runner.d.mts +2 -1
- package/dist/lib/runtime/telemetry-agent-runner.d.mts.map +1 -1
- package/dist/lib/runtime/telemetry-agent-runner.mjs +1 -1
- package/dist/lib/runtime/telemetry-agent-runner.mjs.map +1 -1
- package/dist/lib/telemetry-client.cjs +1 -1
- package/dist/lib/telemetry-client.mjs +1 -1
- package/dist/package.cjs +21 -4
- package/dist/package.mjs +21 -4
- package/dist/service-adapters/anthropic/anthropic-adapter.d.mts +1 -1
- package/dist/v2/index.cjs +41 -15
- package/dist/v2/index.d.cts +14 -2
- package/dist/v2/index.d.mts +14 -2
- package/dist/v2/index.mjs +13 -4
- package/dist/v2/runtime/endpoints/express-single.cjs +190 -0
- package/dist/v2/runtime/endpoints/express-single.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/express-single.d.cts +16 -0
- package/dist/v2/runtime/endpoints/express-single.d.cts.map +1 -0
- package/dist/v2/runtime/endpoints/express-single.d.mts +16 -0
- package/dist/v2/runtime/endpoints/express-single.d.mts.map +1 -0
- package/dist/v2/runtime/endpoints/express-single.mjs +187 -0
- package/dist/v2/runtime/endpoints/express-single.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/express-utils.cjs +119 -0
- package/dist/v2/runtime/endpoints/express-utils.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/express-utils.mjs +117 -0
- package/dist/v2/runtime/endpoints/express-utils.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/express.cjs +217 -0
- package/dist/v2/runtime/endpoints/express.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/express.d.cts +16 -0
- package/dist/v2/runtime/endpoints/express.d.cts.map +1 -0
- package/dist/v2/runtime/endpoints/express.d.mts +16 -0
- package/dist/v2/runtime/endpoints/express.d.mts.map +1 -0
- package/dist/v2/runtime/endpoints/express.mjs +214 -0
- package/dist/v2/runtime/endpoints/express.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/hono-single.cjs +141 -0
- package/dist/v2/runtime/endpoints/hono-single.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/hono-single.d.cts +41 -0
- package/dist/v2/runtime/endpoints/hono-single.d.cts.map +1 -0
- package/dist/v2/runtime/endpoints/hono-single.d.mts +41 -0
- package/dist/v2/runtime/endpoints/hono-single.d.mts.map +1 -0
- package/dist/v2/runtime/endpoints/hono-single.mjs +140 -0
- package/dist/v2/runtime/endpoints/hono-single.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/hono.cjs +248 -0
- package/dist/v2/runtime/endpoints/hono.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/hono.d.cts +164 -0
- package/dist/v2/runtime/endpoints/hono.d.cts.map +1 -0
- package/dist/v2/runtime/endpoints/hono.d.mts +164 -0
- package/dist/v2/runtime/endpoints/hono.d.mts.map +1 -0
- package/dist/v2/runtime/endpoints/hono.mjs +247 -0
- package/dist/v2/runtime/endpoints/hono.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/index.d.cts +5 -0
- package/dist/v2/runtime/endpoints/index.d.mts +5 -0
- package/dist/v2/runtime/endpoints/single-route-helpers.cjs +68 -0
- package/dist/v2/runtime/endpoints/single-route-helpers.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/single-route-helpers.mjs +65 -0
- package/dist/v2/runtime/endpoints/single-route-helpers.mjs.map +1 -0
- package/dist/v2/runtime/handlers/get-runtime-info.cjs +51 -0
- package/dist/v2/runtime/handlers/get-runtime-info.cjs.map +1 -0
- package/dist/v2/runtime/handlers/get-runtime-info.mjs +51 -0
- package/dist/v2/runtime/handlers/get-runtime-info.mjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-connect.cjs +49 -0
- package/dist/v2/runtime/handlers/handle-connect.cjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-connect.mjs +49 -0
- package/dist/v2/runtime/handlers/handle-connect.mjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-run.cjs +61 -0
- package/dist/v2/runtime/handlers/handle-run.cjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-run.mjs +61 -0
- package/dist/v2/runtime/handlers/handle-run.mjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-stop.cjs +47 -0
- package/dist/v2/runtime/handlers/handle-stop.cjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-stop.mjs +46 -0
- package/dist/v2/runtime/handlers/handle-stop.mjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-transcribe.cjs +112 -0
- package/dist/v2/runtime/handlers/handle-transcribe.cjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-transcribe.mjs +111 -0
- package/dist/v2/runtime/handlers/handle-transcribe.mjs.map +1 -0
- package/dist/v2/runtime/handlers/header-utils.cjs +26 -0
- package/dist/v2/runtime/handlers/header-utils.cjs.map +1 -0
- package/dist/v2/runtime/handlers/header-utils.mjs +25 -0
- package/dist/v2/runtime/handlers/header-utils.mjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/connect.cjs +37 -0
- package/dist/v2/runtime/handlers/intelligence/connect.cjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/connect.mjs +37 -0
- package/dist/v2/runtime/handlers/intelligence/connect.mjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/run.cjs +89 -0
- package/dist/v2/runtime/handlers/intelligence/run.cjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/run.mjs +88 -0
- package/dist/v2/runtime/handlers/intelligence/run.mjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/thread-names.cjs +146 -0
- package/dist/v2/runtime/handlers/intelligence/thread-names.cjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/thread-names.mjs +145 -0
- package/dist/v2/runtime/handlers/intelligence/thread-names.mjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/threads.cjs +159 -0
- package/dist/v2/runtime/handlers/intelligence/threads.cjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/threads.mjs +154 -0
- package/dist/v2/runtime/handlers/intelligence/threads.mjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs +74 -0
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs +70 -0
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/intelligence-utils.cjs +21 -0
- package/dist/v2/runtime/handlers/shared/intelligence-utils.cjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/intelligence-utils.mjs +20 -0
- package/dist/v2/runtime/handlers/shared/intelligence-utils.mjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/json-response.cjs +12 -0
- package/dist/v2/runtime/handlers/shared/json-response.cjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/json-response.mjs +10 -0
- package/dist/v2/runtime/handlers/shared/json-response.mjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs +20 -0
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs +20 -0
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/sse-response.cjs +69 -0
- package/dist/v2/runtime/handlers/shared/sse-response.cjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/sse-response.mjs +68 -0
- package/dist/v2/runtime/handlers/shared/sse-response.mjs.map +1 -0
- package/dist/v2/runtime/handlers/sse/connect.cjs +18 -0
- package/dist/v2/runtime/handlers/sse/connect.cjs.map +1 -0
- package/dist/v2/runtime/handlers/sse/connect.mjs +18 -0
- package/dist/v2/runtime/handlers/sse/connect.mjs.map +1 -0
- package/dist/v2/runtime/handlers/sse/run.cjs +18 -0
- package/dist/v2/runtime/handlers/sse/run.cjs.map +1 -0
- package/dist/v2/runtime/handlers/sse/run.mjs +18 -0
- package/dist/v2/runtime/handlers/sse/run.mjs.map +1 -0
- package/dist/v2/runtime/index.d.cts +13 -0
- package/dist/v2/runtime/index.d.mts +14 -0
- package/dist/v2/runtime/intelligence-platform/client.cjs +333 -0
- package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -0
- package/dist/v2/runtime/intelligence-platform/client.d.cts +336 -0
- package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -0
- package/dist/v2/runtime/intelligence-platform/client.d.mts +336 -0
- package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -0
- package/dist/v2/runtime/intelligence-platform/client.mjs +331 -0
- package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -0
- package/dist/v2/runtime/intelligence-platform/index.d.mts +2 -0
- package/dist/v2/runtime/middleware-sse-parser.cjs +138 -0
- package/dist/v2/runtime/middleware-sse-parser.cjs.map +1 -0
- package/dist/v2/runtime/middleware-sse-parser.d.cts +22 -0
- package/dist/v2/runtime/middleware-sse-parser.d.cts.map +1 -0
- package/dist/v2/runtime/middleware-sse-parser.d.mts +22 -0
- package/dist/v2/runtime/middleware-sse-parser.d.mts.map +1 -0
- package/dist/v2/runtime/middleware-sse-parser.mjs +137 -0
- package/dist/v2/runtime/middleware-sse-parser.mjs.map +1 -0
- package/dist/v2/runtime/middleware.cjs +35 -0
- package/dist/v2/runtime/middleware.cjs.map +1 -0
- package/dist/v2/runtime/middleware.d.cts +32 -0
- package/dist/v2/runtime/middleware.d.cts.map +1 -0
- package/dist/v2/runtime/middleware.d.mts +32 -0
- package/dist/v2/runtime/middleware.d.mts.map +1 -0
- package/dist/v2/runtime/middleware.mjs +33 -0
- package/dist/v2/runtime/middleware.mjs.map +1 -0
- package/dist/v2/runtime/runner/agent-runner.cjs +8 -0
- package/dist/v2/runtime/runner/agent-runner.cjs.map +1 -0
- package/dist/v2/runtime/runner/agent-runner.d.cts +32 -0
- package/dist/v2/runtime/runner/agent-runner.d.cts.map +1 -0
- package/dist/v2/runtime/runner/agent-runner.d.mts +32 -0
- package/dist/v2/runtime/runner/agent-runner.d.mts.map +1 -0
- package/dist/v2/runtime/runner/agent-runner.mjs +7 -0
- package/dist/v2/runtime/runner/agent-runner.mjs.map +1 -0
- package/dist/v2/runtime/runner/in-memory.cjs +223 -0
- package/dist/v2/runtime/runner/in-memory.cjs.map +1 -0
- package/dist/v2/runtime/runner/in-memory.d.cts +15 -0
- package/dist/v2/runtime/runner/in-memory.d.cts.map +1 -0
- package/dist/v2/runtime/runner/in-memory.d.mts +15 -0
- package/dist/v2/runtime/runner/in-memory.d.mts.map +1 -0
- package/dist/v2/runtime/runner/in-memory.mjs +222 -0
- package/dist/v2/runtime/runner/in-memory.mjs.map +1 -0
- package/dist/v2/runtime/runner/index.d.cts +6 -0
- package/dist/v2/runtime/runner/index.d.mts +6 -0
- package/dist/v2/runtime/runner/index.mjs +7 -0
- package/dist/v2/runtime/runner/intelligence.cjs +246 -0
- package/dist/v2/runtime/runner/intelligence.cjs.map +1 -0
- package/dist/v2/runtime/runner/intelligence.d.cts +57 -0
- package/dist/v2/runtime/runner/intelligence.d.cts.map +1 -0
- package/dist/v2/runtime/runner/intelligence.d.mts +57 -0
- package/dist/v2/runtime/runner/intelligence.d.mts.map +1 -0
- package/dist/v2/runtime/runner/intelligence.mjs +245 -0
- package/dist/v2/runtime/runner/intelligence.mjs.map +1 -0
- package/dist/v2/runtime/runtime.cjs +101 -0
- package/dist/v2/runtime/runtime.cjs.map +1 -0
- package/dist/v2/runtime/runtime.d.cts +132 -0
- package/dist/v2/runtime/runtime.d.cts.map +1 -0
- package/dist/v2/runtime/runtime.d.mts +133 -0
- package/dist/v2/runtime/runtime.d.mts.map +1 -0
- package/dist/v2/runtime/runtime.mjs +97 -0
- package/dist/v2/runtime/runtime.mjs.map +1 -0
- package/dist/v2/runtime/telemetry/scarf-client.cjs +32 -0
- package/dist/v2/runtime/telemetry/scarf-client.cjs.map +1 -0
- package/dist/v2/runtime/telemetry/scarf-client.mjs +32 -0
- package/dist/v2/runtime/telemetry/scarf-client.mjs.map +1 -0
- package/dist/v2/runtime/telemetry/telemetry-client.cjs +35 -0
- package/dist/v2/runtime/telemetry/telemetry-client.cjs.map +1 -0
- package/dist/v2/runtime/telemetry/telemetry-client.mjs +35 -0
- package/dist/v2/runtime/telemetry/telemetry-client.mjs.map +1 -0
- package/dist/v2/runtime/transcription-service/transcription-service.cjs +8 -0
- package/dist/v2/runtime/transcription-service/transcription-service.cjs.map +1 -0
- package/dist/v2/runtime/transcription-service/transcription-service.d.cts +15 -0
- package/dist/v2/runtime/transcription-service/transcription-service.d.cts.map +1 -0
- package/dist/v2/runtime/transcription-service/transcription-service.d.mts +15 -0
- package/dist/v2/runtime/transcription-service/transcription-service.d.mts.map +1 -0
- package/dist/v2/runtime/transcription-service/transcription-service.mjs +7 -0
- package/dist/v2/runtime/transcription-service/transcription-service.mjs.map +1 -0
- package/package.json +24 -7
- package/src/agent/__tests__/ai-sdk-v6-compat.test.ts +116 -0
- package/src/agent/__tests__/basic-agent.test.ts +1248 -0
- package/src/agent/__tests__/config-tools-execution.test.ts +516 -0
- package/src/agent/__tests__/mcp-clients.test.ts +260 -0
- package/src/agent/__tests__/property-overrides.test.ts +598 -0
- package/src/agent/__tests__/standard-schema-tools.test.ts +313 -0
- package/src/agent/__tests__/standard-schema-types.test.ts +158 -0
- package/src/agent/__tests__/state-tools.test.ts +436 -0
- package/src/agent/__tests__/test-helpers.ts +178 -0
- package/src/agent/__tests__/utils.test.ts +536 -0
- package/src/agent/__tests__/zod-regression.test.ts +350 -0
- package/src/agent/index.ts +1305 -0
- package/src/graphql/message-conversion/agui-to-gql.test.ts +1 -1
- package/src/graphql/message-conversion/agui-to-gql.ts +1 -1
- package/src/graphql/message-conversion/gql-to-agui.ts +1 -1
- package/src/graphql/message-conversion/roundtrip-conversion.test.ts +1 -1
- package/src/lib/integrations/nextjs/app-router.ts +2 -2
- package/src/lib/integrations/node-http/index.ts +2 -2
- package/src/lib/runtime/copilot-runtime.ts +3 -5
- package/src/lib/runtime/telemetry-agent-runner.ts +1 -1
- package/src/service-adapters/conversion.test.ts +1 -1
- package/src/service-adapters/conversion.ts +1 -28
- package/src/v2/index.ts +5 -2
- package/src/v2/runtime/__tests__/cors-credentials.test.ts +320 -0
- package/src/v2/runtime/__tests__/express-abort-signal.test.ts +25 -0
- package/src/v2/runtime/__tests__/express-body-order.test.ts +76 -0
- package/src/v2/runtime/__tests__/express-single-sse.test.ts +122 -0
- package/src/v2/runtime/__tests__/get-runtime-info.test.ts +141 -0
- package/src/v2/runtime/__tests__/handle-connect.test.ts +423 -0
- package/src/v2/runtime/__tests__/handle-run.test.ts +910 -0
- package/src/v2/runtime/__tests__/handle-threads.test.ts +388 -0
- package/src/v2/runtime/__tests__/handle-transcribe.test.ts +301 -0
- package/src/v2/runtime/__tests__/header-utils.test.ts +88 -0
- package/src/v2/runtime/__tests__/in-process-agent-runner-messages.test.ts +230 -0
- package/src/v2/runtime/__tests__/in-process-agent-runner.test.ts +1030 -0
- package/src/v2/runtime/__tests__/middleware-express.test.ts +206 -0
- package/src/v2/runtime/__tests__/middleware-single-express.test.ts +211 -0
- package/src/v2/runtime/__tests__/middleware-single.test.ts +225 -0
- package/src/v2/runtime/__tests__/middleware-sse-parser.test.ts +187 -0
- package/src/v2/runtime/__tests__/middleware.test.ts +251 -0
- package/src/v2/runtime/__tests__/routing-express.test.ts +174 -0
- package/src/v2/runtime/__tests__/routing-single-express.test.ts +168 -0
- package/src/v2/runtime/__tests__/routing-single.test.ts +193 -0
- package/src/v2/runtime/__tests__/routing.test.ts +257 -0
- package/src/v2/runtime/__tests__/runtime.test.ts +123 -0
- package/src/v2/runtime/__tests__/telemetry.test.ts +167 -0
- package/src/v2/runtime/__tests__/thread-names.test.ts +188 -0
- package/src/v2/runtime/endpoints/express-single.ts +231 -0
- package/src/v2/runtime/endpoints/express-utils.ts +182 -0
- package/src/v2/runtime/endpoints/express.ts +275 -0
- package/src/v2/runtime/endpoints/hono-single.ts +212 -0
- package/src/v2/runtime/endpoints/hono.ts +314 -0
- package/src/v2/runtime/endpoints/index.ts +4 -0
- package/src/v2/runtime/endpoints/single-route-helpers.ts +125 -0
- package/src/v2/runtime/express.ts +2 -0
- package/src/v2/runtime/handler.ts +3 -0
- package/src/v2/runtime/handlers/get-runtime-info.ts +79 -0
- package/src/v2/runtime/handlers/handle-connect.ts +76 -0
- package/src/v2/runtime/handlers/handle-run.ts +89 -0
- package/src/v2/runtime/handlers/handle-stop.ts +76 -0
- package/src/v2/runtime/handlers/handle-threads.ts +7 -0
- package/src/v2/runtime/handlers/handle-transcribe.ts +256 -0
- package/src/v2/runtime/handlers/header-utils.ts +24 -0
- package/src/v2/runtime/handlers/intelligence/connect.ts +65 -0
- package/src/v2/runtime/handlers/intelligence/run.ts +152 -0
- package/src/v2/runtime/handlers/intelligence/thread-names.ts +246 -0
- package/src/v2/runtime/handlers/intelligence/threads.ts +233 -0
- package/src/v2/runtime/handlers/shared/agent-utils.ts +136 -0
- package/src/v2/runtime/handlers/shared/intelligence-utils.ts +21 -0
- package/src/v2/runtime/handlers/shared/json-response.ts +6 -0
- package/src/v2/runtime/handlers/shared/resolve-intelligence-user.ts +25 -0
- package/src/v2/runtime/handlers/shared/sse-response.ts +100 -0
- package/src/v2/runtime/handlers/sse/connect.ts +24 -0
- package/src/v2/runtime/handlers/sse/run.ts +27 -0
- package/src/v2/runtime/index.ts +20 -0
- package/src/v2/runtime/intelligence-platform/__tests__/client.test.ts +605 -0
- package/src/v2/runtime/intelligence-platform/client.ts +659 -0
- package/src/v2/runtime/intelligence-platform/index.ts +10 -0
- package/src/v2/runtime/middleware-sse-parser.ts +200 -0
- package/src/v2/runtime/middleware.ts +115 -0
- package/src/v2/runtime/runner/__tests__/finalize-events.test.ts +109 -0
- package/src/v2/runtime/runner/__tests__/in-memory-runner.e2e.test.ts +775 -0
- package/src/v2/runtime/runner/__tests__/in-memory-runner.test.ts +363 -0
- package/src/v2/runtime/runner/__tests__/intelligence-runner.test.ts +981 -0
- package/src/v2/runtime/runner/agent-runner.ts +36 -0
- package/src/v2/runtime/runner/in-memory.ts +381 -0
- package/src/v2/runtime/runner/index.ts +4 -0
- package/src/v2/runtime/runner/intelligence.ts +429 -0
- package/src/v2/runtime/runtime.ts +260 -0
- package/src/v2/runtime/telemetry/events.ts +35 -0
- package/src/v2/runtime/telemetry/index.ts +7 -0
- package/src/v2/runtime/telemetry/scarf-client.ts +39 -0
- package/src/v2/runtime/telemetry/telemetry-client.ts +70 -0
- package/src/v2/runtime/transcription-service/transcription-service.ts +11 -0
- package/tsconfig.json +9 -2
- package/tsdown.config.ts +1 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
|
|
2
|
+
import { CopilotRuntimeLike } from "../runtime.cjs";
|
|
3
|
+
import * as hono_utils_http_status0 from "hono/utils/http-status";
|
|
4
|
+
import * as hono_hono_base0 from "hono/hono-base";
|
|
5
|
+
|
|
6
|
+
//#region src/v2/runtime/endpoints/hono.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* CORS configuration for CopilotKit endpoints.
|
|
9
|
+
* When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.
|
|
10
|
+
*/
|
|
11
|
+
interface CopilotEndpointCorsConfig {
|
|
12
|
+
/**
|
|
13
|
+
* Allowed origin(s) for CORS. Can be:
|
|
14
|
+
* - A string: exact origin (e.g., "https://myapp.com")
|
|
15
|
+
* - An array: list of allowed origins
|
|
16
|
+
* - A function: dynamic origin resolution
|
|
17
|
+
*
|
|
18
|
+
* Note: When credentials is true, origin cannot be "*"
|
|
19
|
+
*/
|
|
20
|
+
origin: string | string[] | ((origin: string, c: any) => string | undefined | null);
|
|
21
|
+
/**
|
|
22
|
+
* Whether to allow credentials (cookies, HTTP authentication).
|
|
23
|
+
* When true, origin must be explicitly specified (not "*").
|
|
24
|
+
*/
|
|
25
|
+
credentials?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface CopilotEndpointParams {
|
|
28
|
+
runtime: CopilotRuntimeLike;
|
|
29
|
+
basePath: string;
|
|
30
|
+
/**
|
|
31
|
+
* Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.
|
|
32
|
+
* To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.
|
|
33
|
+
*/
|
|
34
|
+
cors?: CopilotEndpointCorsConfig;
|
|
35
|
+
}
|
|
36
|
+
type CopilotEndpointContext = {
|
|
37
|
+
Variables: {
|
|
38
|
+
modifiedRequest?: Request;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
declare function createCopilotEndpoint({
|
|
42
|
+
runtime,
|
|
43
|
+
basePath,
|
|
44
|
+
cors: corsConfig
|
|
45
|
+
}: CopilotEndpointParams): hono_hono_base0.HonoBase<CopilotEndpointContext, {
|
|
46
|
+
[x: `${string}/agent/:agentId/run`]: {
|
|
47
|
+
$post: {
|
|
48
|
+
input: {
|
|
49
|
+
param: {
|
|
50
|
+
agentId: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
output: {};
|
|
54
|
+
outputFormat: string;
|
|
55
|
+
status: hono_utils_http_status0.StatusCode;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
} & {
|
|
59
|
+
[x: `${string}/agent/:agentId/connect`]: {
|
|
60
|
+
$post: {
|
|
61
|
+
input: {
|
|
62
|
+
param: {
|
|
63
|
+
agentId: string;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
output: {};
|
|
67
|
+
outputFormat: string;
|
|
68
|
+
status: hono_utils_http_status0.StatusCode;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
} & {
|
|
72
|
+
[x: `${string}/agent/:agentId/stop/:threadId`]: {
|
|
73
|
+
$post: {
|
|
74
|
+
input: {
|
|
75
|
+
param: {
|
|
76
|
+
agentId: string;
|
|
77
|
+
} & {
|
|
78
|
+
threadId: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
output: {};
|
|
82
|
+
outputFormat: string;
|
|
83
|
+
status: hono_utils_http_status0.StatusCode;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
} & {
|
|
87
|
+
[x: `${string}/info`]: {
|
|
88
|
+
$get: {
|
|
89
|
+
input: {};
|
|
90
|
+
output: {};
|
|
91
|
+
outputFormat: string;
|
|
92
|
+
status: hono_utils_http_status0.StatusCode;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
} & {
|
|
96
|
+
[x: `${string}/transcribe`]: {
|
|
97
|
+
$post: {
|
|
98
|
+
input: {};
|
|
99
|
+
output: {};
|
|
100
|
+
outputFormat: string;
|
|
101
|
+
status: hono_utils_http_status0.StatusCode;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
} & {
|
|
105
|
+
[x: `${string}/threads`]: {
|
|
106
|
+
$get: {
|
|
107
|
+
input: {};
|
|
108
|
+
output: {};
|
|
109
|
+
outputFormat: string;
|
|
110
|
+
status: hono_utils_http_status0.StatusCode;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
} & {
|
|
114
|
+
[x: `${string}/threads/subscribe`]: {
|
|
115
|
+
$post: {
|
|
116
|
+
input: {};
|
|
117
|
+
output: {};
|
|
118
|
+
outputFormat: string;
|
|
119
|
+
status: hono_utils_http_status0.StatusCode;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
} & {
|
|
123
|
+
[x: `${string}/threads/:threadId`]: {
|
|
124
|
+
$patch: {
|
|
125
|
+
input: {
|
|
126
|
+
param: {
|
|
127
|
+
threadId: string;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
output: {};
|
|
131
|
+
outputFormat: string;
|
|
132
|
+
status: hono_utils_http_status0.StatusCode;
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
} & {
|
|
136
|
+
[x: `${string}/threads/:threadId/archive`]: {
|
|
137
|
+
$post: {
|
|
138
|
+
input: {
|
|
139
|
+
param: {
|
|
140
|
+
threadId: string;
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
output: {};
|
|
144
|
+
outputFormat: string;
|
|
145
|
+
status: hono_utils_http_status0.StatusCode;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
} & {
|
|
149
|
+
[x: `${string}/threads/:threadId`]: {
|
|
150
|
+
$delete: {
|
|
151
|
+
input: {
|
|
152
|
+
param: {
|
|
153
|
+
threadId: string;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
output: {};
|
|
157
|
+
outputFormat: string;
|
|
158
|
+
status: hono_utils_http_status0.StatusCode;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
}, string, `${string}/threads/:threadId`>;
|
|
162
|
+
//#endregion
|
|
163
|
+
export { CopilotEndpointCorsConfig, createCopilotEndpoint };
|
|
164
|
+
//# sourceMappingURL=hono.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hono.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"mappings":";;;;;;;;;;UA0BiB,yBAAA;EAAyB;;;;;;;;EASxC,MAAA,wBAGM,MAAA,UAAgB,CAAA;EAQd;;;;EAHR,WAAA;AAAA;AAAA,UAGQ,qBAAA;EACR,OAAA,EAAS,kBAAA;EACT,QAAA;EAKgC;;AAAA;;EAAhC,IAAA,GAAO,yBAAA;AAAA;AAAA,KAIJ,sBAAA;EACH,SAAA;IACE,eAAA,GAAkB,OAAA;EAAA;AAAA;AAAA,iBAIN,qBAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA,EAAM;AAAA,GACL,qBAAA,mBAAqB,QAAA,CAAA,sBAAA;EAAA;;;;;;;;;cAAA,uBAAA,CAAA,UAAA;IAAA;EAAA;AAAA;EAAA"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { CopilotRuntimeLike } from "../runtime.mjs";
|
|
3
|
+
import * as hono_utils_http_status0 from "hono/utils/http-status";
|
|
4
|
+
import * as hono_hono_base0 from "hono/hono-base";
|
|
5
|
+
|
|
6
|
+
//#region src/v2/runtime/endpoints/hono.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* CORS configuration for CopilotKit endpoints.
|
|
9
|
+
* When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.
|
|
10
|
+
*/
|
|
11
|
+
interface CopilotEndpointCorsConfig {
|
|
12
|
+
/**
|
|
13
|
+
* Allowed origin(s) for CORS. Can be:
|
|
14
|
+
* - A string: exact origin (e.g., "https://myapp.com")
|
|
15
|
+
* - An array: list of allowed origins
|
|
16
|
+
* - A function: dynamic origin resolution
|
|
17
|
+
*
|
|
18
|
+
* Note: When credentials is true, origin cannot be "*"
|
|
19
|
+
*/
|
|
20
|
+
origin: string | string[] | ((origin: string, c: any) => string | undefined | null);
|
|
21
|
+
/**
|
|
22
|
+
* Whether to allow credentials (cookies, HTTP authentication).
|
|
23
|
+
* When true, origin must be explicitly specified (not "*").
|
|
24
|
+
*/
|
|
25
|
+
credentials?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface CopilotEndpointParams {
|
|
28
|
+
runtime: CopilotRuntimeLike;
|
|
29
|
+
basePath: string;
|
|
30
|
+
/**
|
|
31
|
+
* Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.
|
|
32
|
+
* To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.
|
|
33
|
+
*/
|
|
34
|
+
cors?: CopilotEndpointCorsConfig;
|
|
35
|
+
}
|
|
36
|
+
type CopilotEndpointContext = {
|
|
37
|
+
Variables: {
|
|
38
|
+
modifiedRequest?: Request;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
declare function createCopilotEndpoint({
|
|
42
|
+
runtime,
|
|
43
|
+
basePath,
|
|
44
|
+
cors: corsConfig
|
|
45
|
+
}: CopilotEndpointParams): hono_hono_base0.HonoBase<CopilotEndpointContext, {
|
|
46
|
+
[x: `${string}/agent/:agentId/run`]: {
|
|
47
|
+
$post: {
|
|
48
|
+
input: {
|
|
49
|
+
param: {
|
|
50
|
+
agentId: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
output: {};
|
|
54
|
+
outputFormat: string;
|
|
55
|
+
status: hono_utils_http_status0.StatusCode;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
} & {
|
|
59
|
+
[x: `${string}/agent/:agentId/connect`]: {
|
|
60
|
+
$post: {
|
|
61
|
+
input: {
|
|
62
|
+
param: {
|
|
63
|
+
agentId: string;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
output: {};
|
|
67
|
+
outputFormat: string;
|
|
68
|
+
status: hono_utils_http_status0.StatusCode;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
} & {
|
|
72
|
+
[x: `${string}/agent/:agentId/stop/:threadId`]: {
|
|
73
|
+
$post: {
|
|
74
|
+
input: {
|
|
75
|
+
param: {
|
|
76
|
+
agentId: string;
|
|
77
|
+
} & {
|
|
78
|
+
threadId: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
output: {};
|
|
82
|
+
outputFormat: string;
|
|
83
|
+
status: hono_utils_http_status0.StatusCode;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
} & {
|
|
87
|
+
[x: `${string}/info`]: {
|
|
88
|
+
$get: {
|
|
89
|
+
input: {};
|
|
90
|
+
output: {};
|
|
91
|
+
outputFormat: string;
|
|
92
|
+
status: hono_utils_http_status0.StatusCode;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
} & {
|
|
96
|
+
[x: `${string}/transcribe`]: {
|
|
97
|
+
$post: {
|
|
98
|
+
input: {};
|
|
99
|
+
output: {};
|
|
100
|
+
outputFormat: string;
|
|
101
|
+
status: hono_utils_http_status0.StatusCode;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
} & {
|
|
105
|
+
[x: `${string}/threads`]: {
|
|
106
|
+
$get: {
|
|
107
|
+
input: {};
|
|
108
|
+
output: {};
|
|
109
|
+
outputFormat: string;
|
|
110
|
+
status: hono_utils_http_status0.StatusCode;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
} & {
|
|
114
|
+
[x: `${string}/threads/subscribe`]: {
|
|
115
|
+
$post: {
|
|
116
|
+
input: {};
|
|
117
|
+
output: {};
|
|
118
|
+
outputFormat: string;
|
|
119
|
+
status: hono_utils_http_status0.StatusCode;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
} & {
|
|
123
|
+
[x: `${string}/threads/:threadId`]: {
|
|
124
|
+
$patch: {
|
|
125
|
+
input: {
|
|
126
|
+
param: {
|
|
127
|
+
threadId: string;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
output: {};
|
|
131
|
+
outputFormat: string;
|
|
132
|
+
status: hono_utils_http_status0.StatusCode;
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
} & {
|
|
136
|
+
[x: `${string}/threads/:threadId/archive`]: {
|
|
137
|
+
$post: {
|
|
138
|
+
input: {
|
|
139
|
+
param: {
|
|
140
|
+
threadId: string;
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
output: {};
|
|
144
|
+
outputFormat: string;
|
|
145
|
+
status: hono_utils_http_status0.StatusCode;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
} & {
|
|
149
|
+
[x: `${string}/threads/:threadId`]: {
|
|
150
|
+
$delete: {
|
|
151
|
+
input: {
|
|
152
|
+
param: {
|
|
153
|
+
threadId: string;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
output: {};
|
|
157
|
+
outputFormat: string;
|
|
158
|
+
status: hono_utils_http_status0.StatusCode;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
}, string, `${string}/threads/:threadId`>;
|
|
162
|
+
//#endregion
|
|
163
|
+
export { CopilotEndpointCorsConfig, createCopilotEndpoint };
|
|
164
|
+
//# sourceMappingURL=hono.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hono.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"mappings":";;;;;;;;;;UA0BiB,yBAAA;EAAyB;;;;;;;;EASxC,MAAA,wBAGM,MAAA,UAAgB,CAAA;EAQd;;;;EAHR,WAAA;AAAA;AAAA,UAGQ,qBAAA;EACR,OAAA,EAAS,kBAAA;EACT,QAAA;EAKgC;;AAAA;;EAAhC,IAAA,GAAO,yBAAA;AAAA;AAAA,KAIJ,sBAAA;EACH,SAAA;IACE,eAAA,GAAkB,OAAA;EAAA;AAAA;AAAA,iBAIN,qBAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA,EAAM;AAAA,GACL,qBAAA,mBAAqB,QAAA,CAAA,sBAAA;EAAA;;;;;;;;;cAAA,uBAAA,CAAA,UAAA;IAAA;EAAA;AAAA;EAAA"}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import telemetry from "../telemetry/telemetry-client.mjs";
|
|
3
|
+
import { handleRunAgent } from "../handlers/handle-run.mjs";
|
|
4
|
+
import { handleGetRuntimeInfo } from "../handlers/get-runtime-info.mjs";
|
|
5
|
+
import { handleTranscribe } from "../handlers/handle-transcribe.mjs";
|
|
6
|
+
import { callAfterRequestMiddleware, callBeforeRequestMiddleware } from "../middleware.mjs";
|
|
7
|
+
import { handleConnectAgent } from "../handlers/handle-connect.mjs";
|
|
8
|
+
import { handleStopAgent } from "../handlers/handle-stop.mjs";
|
|
9
|
+
import { handleArchiveThread, handleDeleteThread, handleListThreads, handleSubscribeToThreads, handleUpdateThread } from "../handlers/intelligence/threads.mjs";
|
|
10
|
+
import { getLicenseWarningHeader, logger } from "@copilotkit/shared";
|
|
11
|
+
import { Hono } from "hono";
|
|
12
|
+
import { cors } from "hono/cors";
|
|
13
|
+
|
|
14
|
+
//#region src/v2/runtime/endpoints/hono.ts
|
|
15
|
+
function createCopilotEndpoint({ runtime, basePath, cors: corsConfig }) {
|
|
16
|
+
const app = new Hono();
|
|
17
|
+
Promise.resolve(runtime.agents).then((agents) => {
|
|
18
|
+
telemetry.capture("oss.runtime.instance_created", {
|
|
19
|
+
actionsAmount: 0,
|
|
20
|
+
endpointTypes: [],
|
|
21
|
+
endpointsAmount: 0,
|
|
22
|
+
agentsAmount: Object.keys(agents).length,
|
|
23
|
+
"cloud.api_key_provided": false
|
|
24
|
+
});
|
|
25
|
+
}).catch(() => {});
|
|
26
|
+
return app.basePath(basePath).use("*", cors({
|
|
27
|
+
origin: corsConfig?.origin ?? "*",
|
|
28
|
+
allowMethods: [
|
|
29
|
+
"GET",
|
|
30
|
+
"HEAD",
|
|
31
|
+
"PUT",
|
|
32
|
+
"POST",
|
|
33
|
+
"DELETE",
|
|
34
|
+
"PATCH",
|
|
35
|
+
"OPTIONS"
|
|
36
|
+
],
|
|
37
|
+
allowHeaders: ["*"],
|
|
38
|
+
credentials: corsConfig?.credentials ?? false
|
|
39
|
+
})).use("*", async (c, next) => {
|
|
40
|
+
const request = c.req.raw;
|
|
41
|
+
const path = c.req.path;
|
|
42
|
+
try {
|
|
43
|
+
const maybeModifiedRequest = await callBeforeRequestMiddleware({
|
|
44
|
+
runtime,
|
|
45
|
+
request,
|
|
46
|
+
path
|
|
47
|
+
});
|
|
48
|
+
if (maybeModifiedRequest) c.set("modifiedRequest", maybeModifiedRequest);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
logger.error({
|
|
51
|
+
err: error,
|
|
52
|
+
url: request.url,
|
|
53
|
+
path
|
|
54
|
+
}, "Error running before request middleware");
|
|
55
|
+
if (error instanceof Response) return error;
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
const warning = getLicenseWarningHeader(runtime.licenseChecker);
|
|
59
|
+
if (warning) c.header(warning.key, warning.value);
|
|
60
|
+
await next();
|
|
61
|
+
}).use("*", async (c, next) => {
|
|
62
|
+
await next();
|
|
63
|
+
const response = c.res.clone();
|
|
64
|
+
const path = c.req.path;
|
|
65
|
+
callAfterRequestMiddleware({
|
|
66
|
+
runtime,
|
|
67
|
+
response,
|
|
68
|
+
path
|
|
69
|
+
}).catch((error) => {
|
|
70
|
+
logger.error({
|
|
71
|
+
err: error,
|
|
72
|
+
url: c.req.url,
|
|
73
|
+
path
|
|
74
|
+
}, "Error running after request middleware");
|
|
75
|
+
});
|
|
76
|
+
}).post("/agent/:agentId/run", async (c) => {
|
|
77
|
+
const agentId = c.req.param("agentId");
|
|
78
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
79
|
+
try {
|
|
80
|
+
return await handleRunAgent({
|
|
81
|
+
runtime,
|
|
82
|
+
request,
|
|
83
|
+
agentId
|
|
84
|
+
});
|
|
85
|
+
} catch (error) {
|
|
86
|
+
logger.error({
|
|
87
|
+
err: error,
|
|
88
|
+
url: request.url,
|
|
89
|
+
path: c.req.path
|
|
90
|
+
}, "Error running request handler");
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}).post("/agent/:agentId/connect", async (c) => {
|
|
94
|
+
const agentId = c.req.param("agentId");
|
|
95
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
96
|
+
try {
|
|
97
|
+
return await handleConnectAgent({
|
|
98
|
+
runtime,
|
|
99
|
+
request,
|
|
100
|
+
agentId
|
|
101
|
+
});
|
|
102
|
+
} catch (error) {
|
|
103
|
+
logger.error({
|
|
104
|
+
err: error,
|
|
105
|
+
url: request.url,
|
|
106
|
+
path: c.req.path
|
|
107
|
+
}, "Error running request handler");
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}).post("/agent/:agentId/stop/:threadId", async (c) => {
|
|
111
|
+
const agentId = c.req.param("agentId");
|
|
112
|
+
const threadId = c.req.param("threadId");
|
|
113
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
114
|
+
try {
|
|
115
|
+
return await handleStopAgent({
|
|
116
|
+
runtime,
|
|
117
|
+
request,
|
|
118
|
+
agentId,
|
|
119
|
+
threadId
|
|
120
|
+
});
|
|
121
|
+
} catch (error) {
|
|
122
|
+
logger.error({
|
|
123
|
+
err: error,
|
|
124
|
+
url: request.url,
|
|
125
|
+
path: c.req.path
|
|
126
|
+
}, "Error running request handler");
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}).get("/info", async (c) => {
|
|
130
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
131
|
+
try {
|
|
132
|
+
return await handleGetRuntimeInfo({
|
|
133
|
+
runtime,
|
|
134
|
+
request
|
|
135
|
+
});
|
|
136
|
+
} catch (error) {
|
|
137
|
+
logger.error({
|
|
138
|
+
err: error,
|
|
139
|
+
url: request.url,
|
|
140
|
+
path: c.req.path
|
|
141
|
+
}, "Error running request handler");
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
}).post("/transcribe", async (c) => {
|
|
145
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
146
|
+
try {
|
|
147
|
+
return await handleTranscribe({
|
|
148
|
+
runtime,
|
|
149
|
+
request
|
|
150
|
+
});
|
|
151
|
+
} catch (error) {
|
|
152
|
+
logger.error({
|
|
153
|
+
err: error,
|
|
154
|
+
url: request.url,
|
|
155
|
+
path: c.req.path
|
|
156
|
+
}, "Error running request handler");
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}).get("/threads", async (c) => {
|
|
160
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
161
|
+
try {
|
|
162
|
+
return await handleListThreads({
|
|
163
|
+
runtime,
|
|
164
|
+
request
|
|
165
|
+
});
|
|
166
|
+
} catch (error) {
|
|
167
|
+
logger.error({
|
|
168
|
+
err: error,
|
|
169
|
+
url: request.url,
|
|
170
|
+
path: c.req.path
|
|
171
|
+
}, "Error running request handler");
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
}).post("/threads/subscribe", async (c) => {
|
|
175
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
176
|
+
try {
|
|
177
|
+
return await handleSubscribeToThreads({
|
|
178
|
+
runtime,
|
|
179
|
+
request
|
|
180
|
+
});
|
|
181
|
+
} catch (error) {
|
|
182
|
+
logger.error({
|
|
183
|
+
err: error,
|
|
184
|
+
url: request.url,
|
|
185
|
+
path: c.req.path
|
|
186
|
+
}, "Error running request handler");
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
}).patch("/threads/:threadId", async (c) => {
|
|
190
|
+
const threadId = c.req.param("threadId");
|
|
191
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
192
|
+
try {
|
|
193
|
+
return await handleUpdateThread({
|
|
194
|
+
runtime,
|
|
195
|
+
request,
|
|
196
|
+
threadId
|
|
197
|
+
});
|
|
198
|
+
} catch (error) {
|
|
199
|
+
logger.error({
|
|
200
|
+
err: error,
|
|
201
|
+
url: request.url,
|
|
202
|
+
path: c.req.path
|
|
203
|
+
}, "Error running request handler");
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
}).post("/threads/:threadId/archive", async (c) => {
|
|
207
|
+
const threadId = c.req.param("threadId");
|
|
208
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
209
|
+
try {
|
|
210
|
+
return await handleArchiveThread({
|
|
211
|
+
runtime,
|
|
212
|
+
request,
|
|
213
|
+
threadId
|
|
214
|
+
});
|
|
215
|
+
} catch (error) {
|
|
216
|
+
logger.error({
|
|
217
|
+
err: error,
|
|
218
|
+
url: request.url,
|
|
219
|
+
path: c.req.path
|
|
220
|
+
}, "Error running request handler");
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
}).delete("/threads/:threadId", async (c) => {
|
|
224
|
+
const threadId = c.req.param("threadId");
|
|
225
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
226
|
+
try {
|
|
227
|
+
return await handleDeleteThread({
|
|
228
|
+
runtime,
|
|
229
|
+
request,
|
|
230
|
+
threadId
|
|
231
|
+
});
|
|
232
|
+
} catch (error) {
|
|
233
|
+
logger.error({
|
|
234
|
+
err: error,
|
|
235
|
+
url: request.url,
|
|
236
|
+
path: c.req.path
|
|
237
|
+
}, "Error running request handler");
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
}).notFound((c) => {
|
|
241
|
+
return c.json({ error: "Not found" }, 404);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
//#endregion
|
|
246
|
+
export { createCopilotEndpoint };
|
|
247
|
+
//# sourceMappingURL=hono.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hono.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport { cors } from \"hono/cors\";\nimport { CopilotRuntimeLike } from \"../runtime\";\nimport { telemetry } from \"../telemetry\";\nimport { handleRunAgent } from \"../handlers/handle-run\";\nimport { handleGetRuntimeInfo } from \"../handlers/get-runtime-info\";\nimport { handleTranscribe } from \"../handlers/handle-transcribe\";\nimport { logger, getLicenseWarningHeader } from \"@copilotkit/shared\";\nimport {\n callBeforeRequestMiddleware,\n callAfterRequestMiddleware,\n} from \"../middleware\";\nimport { handleConnectAgent } from \"../handlers/handle-connect\";\nimport { handleStopAgent } from \"../handlers/handle-stop\";\nimport {\n handleListThreads,\n handleSubscribeToThreads,\n handleUpdateThread,\n handleArchiveThread,\n handleDeleteThread,\n} from \"../handlers/handle-threads\";\n\n/**\n * CORS configuration for CopilotKit endpoints.\n * When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.\n */\nexport interface CopilotEndpointCorsConfig {\n /**\n * Allowed origin(s) for CORS. Can be:\n * - A string: exact origin (e.g., \"https://myapp.com\")\n * - An array: list of allowed origins\n * - A function: dynamic origin resolution\n *\n * Note: When credentials is true, origin cannot be \"*\"\n */\n origin:\n | string\n | string[]\n | ((origin: string, c: any) => string | undefined | null);\n /**\n * Whether to allow credentials (cookies, HTTP authentication).\n * When true, origin must be explicitly specified (not \"*\").\n */\n credentials?: boolean;\n}\n\ninterface CopilotEndpointParams {\n runtime: CopilotRuntimeLike;\n basePath: string;\n /**\n * Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.\n * To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.\n */\n cors?: CopilotEndpointCorsConfig;\n}\n\n// Define the context variables type\ntype CopilotEndpointContext = {\n Variables: {\n modifiedRequest?: Request;\n };\n};\n\nexport function createCopilotEndpoint({\n runtime,\n basePath,\n cors: corsConfig,\n}: CopilotEndpointParams) {\n const app = new Hono<CopilotEndpointContext>();\n\n // Fire instance_created telemetry - resolve agents if needed\n Promise.resolve(runtime.agents)\n .then((agents) => {\n telemetry.capture(\"oss.runtime.instance_created\", {\n actionsAmount: 0,\n endpointTypes: [],\n endpointsAmount: 0,\n agentsAmount: Object.keys(agents).length,\n \"cloud.api_key_provided\": false,\n });\n })\n .catch(() => {\n // Silently fail - telemetry should not break the application\n });\n\n return app\n .basePath(basePath)\n .use(\n \"*\",\n cors({\n origin: corsConfig?.origin ?? \"*\",\n allowMethods: [\n \"GET\",\n \"HEAD\",\n \"PUT\",\n \"POST\",\n \"DELETE\",\n \"PATCH\",\n \"OPTIONS\",\n ],\n allowHeaders: [\"*\"],\n credentials: corsConfig?.credentials ?? false,\n }),\n )\n .use(\"*\", async (c, next) => {\n const request = c.req.raw;\n const path = c.req.path;\n\n try {\n const maybeModifiedRequest = await callBeforeRequestMiddleware({\n runtime,\n request,\n path,\n });\n if (maybeModifiedRequest) {\n c.set(\"modifiedRequest\", maybeModifiedRequest);\n }\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path },\n \"Error running before request middleware\",\n );\n if (error instanceof Response) {\n return error;\n }\n throw error;\n }\n\n const warning = getLicenseWarningHeader(runtime.licenseChecker);\n if (warning) c.header(warning.key, warning.value);\n\n await next();\n })\n .use(\"*\", async (c, next) => {\n await next();\n\n const response = c.res.clone();\n const path = c.req.path;\n\n // Non-blocking after middleware\n callAfterRequestMiddleware({\n runtime,\n response,\n path,\n }).catch((error) => {\n logger.error(\n { err: error, url: c.req.url, path },\n \"Error running after request middleware\",\n );\n });\n })\n .post(\"/agent/:agentId/run\", async (c) => {\n const agentId = c.req.param(\"agentId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleRunAgent({\n runtime,\n request,\n agentId,\n });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .post(\"/agent/:agentId/connect\", async (c) => {\n const agentId = c.req.param(\"agentId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleConnectAgent({\n runtime,\n request,\n agentId,\n });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n\n .post(\"/agent/:agentId/stop/:threadId\", async (c) => {\n const agentId = c.req.param(\"agentId\");\n const threadId = c.req.param(\"threadId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleStopAgent({\n runtime,\n request,\n agentId,\n threadId,\n });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .get(\"/info\", async (c) => {\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleGetRuntimeInfo({\n runtime,\n request,\n });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .post(\"/transcribe\", async (c) => {\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleTranscribe({\n runtime,\n request,\n });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .get(\"/threads\", async (c) => {\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleListThreads({ runtime, request });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .post(\"/threads/subscribe\", async (c) => {\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleSubscribeToThreads({ runtime, request });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .patch(\"/threads/:threadId\", async (c) => {\n const threadId = c.req.param(\"threadId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleUpdateThread({ runtime, request, threadId });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .post(\"/threads/:threadId/archive\", async (c) => {\n const threadId = c.req.param(\"threadId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleArchiveThread({ runtime, request, threadId });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .delete(\"/threads/:threadId\", async (c) => {\n const threadId = c.req.param(\"threadId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleDeleteThread({ runtime, request, threadId });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .notFound((c) => {\n return c.json({ error: \"Not found\" }, 404);\n });\n\n // return app;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
import { CopilotEndpointCorsConfig, createCopilotEndpoint } from "./hono.cjs";
|
|
3
|
+
import { createCopilotEndpointSingleRoute } from "./hono-single.cjs";
|
|
4
|
+
import { createCopilotEndpointExpress } from "./express.cjs";
|
|
5
|
+
import { createCopilotEndpointSingleRouteExpress } from "./express-single.cjs";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { CopilotEndpointCorsConfig, createCopilotEndpoint } from "./hono.mjs";
|
|
3
|
+
import { createCopilotEndpointSingleRoute } from "./hono-single.mjs";
|
|
4
|
+
import { createCopilotEndpointExpress } from "./express.mjs";
|
|
5
|
+
import { createCopilotEndpointSingleRouteExpress } from "./express-single.mjs";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require("reflect-metadata");
|
|
2
|
+
|
|
3
|
+
//#region src/v2/runtime/endpoints/single-route-helpers.ts
|
|
4
|
+
const METHOD_NAMES = [
|
|
5
|
+
"agent/run",
|
|
6
|
+
"agent/connect",
|
|
7
|
+
"agent/stop",
|
|
8
|
+
"info",
|
|
9
|
+
"transcribe"
|
|
10
|
+
];
|
|
11
|
+
async function parseMethodCall(request) {
|
|
12
|
+
if (!(request.headers.get("content-type") || "").includes("application/json")) throw createResponseError("Single-route endpoint expects JSON payloads", 415);
|
|
13
|
+
let jsonEnvelope;
|
|
14
|
+
try {
|
|
15
|
+
jsonEnvelope = await request.clone().json();
|
|
16
|
+
} catch (error) {
|
|
17
|
+
throw createResponseError("Invalid JSON payload", 400);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
method: validateMethod(jsonEnvelope.method),
|
|
21
|
+
params: jsonEnvelope.params,
|
|
22
|
+
body: jsonEnvelope.body
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function expectString(params, key) {
|
|
26
|
+
const value = params?.[key];
|
|
27
|
+
if (typeof value === "string" && value.trim().length > 0) return value;
|
|
28
|
+
throw createResponseError(`Missing or invalid parameter '${key}'`, 400);
|
|
29
|
+
}
|
|
30
|
+
function createJsonRequest(base, body) {
|
|
31
|
+
if (body === void 0 || body === null) throw createResponseError("Missing request body for JSON handler", 400);
|
|
32
|
+
const headers = new Headers(base.headers);
|
|
33
|
+
headers.set("content-type", "application/json");
|
|
34
|
+
headers.delete("content-length");
|
|
35
|
+
const serializedBody = serializeJsonBody(body);
|
|
36
|
+
return new Request(base.url, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
headers,
|
|
39
|
+
body: serializedBody,
|
|
40
|
+
signal: base.signal
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function createResponseError(message, status) {
|
|
44
|
+
return new Response(JSON.stringify({
|
|
45
|
+
error: "invalid_request",
|
|
46
|
+
message
|
|
47
|
+
}), {
|
|
48
|
+
status,
|
|
49
|
+
headers: { "Content-Type": "application/json" }
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function validateMethod(method) {
|
|
53
|
+
if (!method) throw createResponseError("Missing method field", 400);
|
|
54
|
+
if (METHOD_NAMES.includes(method)) return method;
|
|
55
|
+
throw createResponseError(`Unsupported method '${method}'`, 400);
|
|
56
|
+
}
|
|
57
|
+
function serializeJsonBody(body) {
|
|
58
|
+
if (typeof body === "string") return body;
|
|
59
|
+
if (body instanceof Blob || body instanceof ArrayBuffer || body instanceof Uint8Array) return body;
|
|
60
|
+
if (body instanceof FormData || body instanceof URLSearchParams) return body;
|
|
61
|
+
return JSON.stringify(body);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
exports.createJsonRequest = createJsonRequest;
|
|
66
|
+
exports.expectString = expectString;
|
|
67
|
+
exports.parseMethodCall = parseMethodCall;
|
|
68
|
+
//# sourceMappingURL=single-route-helpers.cjs.map
|