@copilotkit/runtime 1.55.0-next.8 → 1.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/dist/agent/index.cjs +101 -12
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts.map +1 -1
- package/dist/agent/index.d.mts.map +1 -1
- package/dist/agent/index.mjs +102 -13
- package/dist/agent/index.mjs.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.cjs.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts +4 -841
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.mts +4 -841
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.mts.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.mjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.cjs +3 -2
- package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.cts +1 -1
- package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.mts +3 -3
- package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.mjs +3 -2
- package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
- package/dist/package.cjs +70 -47
- package/dist/package.mjs +70 -47
- package/dist/v2/express.cjs +8 -0
- package/dist/v2/express.d.cts +5 -0
- package/dist/v2/express.d.mts +5 -0
- package/dist/v2/express.mjs +5 -0
- package/dist/v2/hono.cjs +9 -0
- package/dist/v2/hono.d.cts +5 -0
- package/dist/v2/hono.d.mts +5 -0
- package/dist/v2/hono.mjs +5 -0
- package/dist/v2/index.cjs +8 -3
- package/dist/v2/index.d.cts +8 -5
- package/dist/v2/index.d.mts +8 -5
- package/dist/v2/index.mjs +5 -4
- package/dist/v2/node.cjs +8 -0
- package/dist/v2/node.d.cts +5 -0
- package/dist/v2/node.d.mts +5 -0
- package/dist/v2/node.mjs +5 -0
- package/dist/v2/runtime/core/fetch-cors.cjs +72 -0
- package/dist/v2/runtime/core/fetch-cors.cjs.map +1 -0
- package/dist/v2/runtime/core/fetch-cors.d.cts +20 -0
- package/dist/v2/runtime/core/fetch-cors.d.cts.map +1 -0
- package/dist/v2/runtime/core/fetch-cors.d.mts +20 -0
- package/dist/v2/runtime/core/fetch-cors.d.mts.map +1 -0
- package/dist/v2/runtime/core/fetch-cors.mjs +70 -0
- package/dist/v2/runtime/core/fetch-cors.mjs.map +1 -0
- package/dist/v2/runtime/core/fetch-handler.cjs +232 -0
- package/dist/v2/runtime/core/fetch-handler.cjs.map +1 -0
- package/dist/v2/runtime/core/fetch-handler.d.cts +40 -0
- package/dist/v2/runtime/core/fetch-handler.d.cts.map +1 -0
- package/dist/v2/runtime/core/fetch-handler.d.mts +40 -0
- package/dist/v2/runtime/core/fetch-handler.d.mts.map +1 -0
- package/dist/v2/runtime/core/fetch-handler.mjs +231 -0
- package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -0
- package/dist/v2/runtime/core/fetch-router.cjs +68 -0
- package/dist/v2/runtime/core/fetch-router.cjs.map +1 -0
- package/dist/v2/runtime/core/fetch-router.mjs +67 -0
- package/dist/v2/runtime/core/fetch-router.mjs.map +1 -0
- package/dist/v2/runtime/core/hooks.cjs +29 -0
- package/dist/v2/runtime/core/hooks.cjs.map +1 -0
- package/dist/v2/runtime/core/hooks.d.cts +78 -0
- package/dist/v2/runtime/core/hooks.d.cts.map +1 -0
- package/dist/v2/runtime/core/hooks.d.mts +78 -0
- package/dist/v2/runtime/core/hooks.d.mts.map +1 -0
- package/dist/v2/runtime/core/hooks.mjs +25 -0
- package/dist/v2/runtime/core/hooks.mjs.map +1 -0
- package/dist/v2/runtime/{middleware-sse-parser.cjs → core/middleware-sse-parser.cjs} +2 -2
- package/dist/v2/runtime/core/middleware-sse-parser.cjs.map +1 -0
- package/dist/v2/runtime/{middleware-sse-parser.d.cts → core/middleware-sse-parser.d.cts} +1 -1
- package/dist/v2/runtime/core/middleware-sse-parser.d.cts.map +1 -0
- package/dist/v2/runtime/{middleware-sse-parser.d.mts → core/middleware-sse-parser.d.mts} +1 -1
- package/dist/v2/runtime/core/middleware-sse-parser.d.mts.map +1 -0
- package/dist/v2/runtime/{middleware-sse-parser.mjs → core/middleware-sse-parser.mjs} +1 -1
- package/dist/v2/runtime/core/middleware-sse-parser.mjs.map +1 -0
- package/dist/v2/runtime/{middleware.cjs → core/middleware.cjs} +2 -2
- package/dist/v2/runtime/core/middleware.cjs.map +1 -0
- package/dist/v2/runtime/{middleware.d.cts → core/middleware.d.cts} +1 -1
- package/dist/v2/runtime/core/middleware.d.cts.map +1 -0
- package/dist/v2/runtime/{middleware.d.mts → core/middleware.d.mts} +1 -1
- package/dist/v2/runtime/core/middleware.d.mts.map +1 -0
- package/dist/v2/runtime/{middleware.mjs → core/middleware.mjs} +1 -1
- package/dist/v2/runtime/core/middleware.mjs.map +1 -0
- package/dist/v2/runtime/{runtime.cjs → core/runtime.cjs} +35 -10
- package/dist/v2/runtime/core/runtime.cjs.map +1 -0
- package/dist/v2/runtime/{runtime.d.cts → core/runtime.d.cts} +41 -7
- package/dist/v2/runtime/core/runtime.d.cts.map +1 -0
- package/dist/v2/runtime/{runtime.d.mts → core/runtime.d.mts} +42 -8
- package/dist/v2/runtime/core/runtime.d.mts.map +1 -0
- package/dist/v2/runtime/{runtime.mjs → core/runtime.mjs} +36 -11
- package/dist/v2/runtime/core/runtime.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/express-fetch-bridge.cjs +83 -0
- package/dist/v2/runtime/endpoints/express-fetch-bridge.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/express-fetch-bridge.mjs +82 -0
- package/dist/v2/runtime/endpoints/express-fetch-bridge.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/express-single.cjs +35 -181
- package/dist/v2/runtime/endpoints/express-single.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/express-single.d.cts +35 -2
- package/dist/v2/runtime/endpoints/express-single.d.cts.map +1 -1
- package/dist/v2/runtime/endpoints/express-single.d.mts +35 -2
- package/dist/v2/runtime/endpoints/express-single.d.mts.map +1 -1
- package/dist/v2/runtime/endpoints/express-single.mjs +35 -178
- package/dist/v2/runtime/endpoints/express-single.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/express.cjs +41 -195
- package/dist/v2/runtime/endpoints/express.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/express.d.cts +26 -4
- package/dist/v2/runtime/endpoints/express.d.cts.map +1 -1
- package/dist/v2/runtime/endpoints/express.d.mts +26 -4
- package/dist/v2/runtime/endpoints/express.d.mts.map +1 -1
- package/dist/v2/runtime/endpoints/express.mjs +41 -195
- package/dist/v2/runtime/endpoints/express.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/hono-single.cjs +11 -123
- package/dist/v2/runtime/endpoints/hono-single.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/hono-single.d.cts +14 -11
- package/dist/v2/runtime/endpoints/hono-single.d.cts.map +1 -1
- package/dist/v2/runtime/endpoints/hono-single.d.mts +14 -11
- package/dist/v2/runtime/endpoints/hono-single.d.mts.map +1 -1
- package/dist/v2/runtime/endpoints/hono-single.mjs +11 -123
- package/dist/v2/runtime/endpoints/hono-single.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/hono.cjs +23 -237
- package/dist/v2/runtime/endpoints/hono.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/hono.d.cts +29 -120
- package/dist/v2/runtime/endpoints/hono.d.cts.map +1 -1
- package/dist/v2/runtime/endpoints/hono.d.mts +29 -120
- package/dist/v2/runtime/endpoints/hono.d.mts.map +1 -1
- package/dist/v2/runtime/endpoints/hono.mjs +22 -238
- package/dist/v2/runtime/endpoints/hono.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/index.d.cts +2 -2
- package/dist/v2/runtime/endpoints/index.d.mts +2 -2
- package/dist/v2/runtime/endpoints/node-fetch-handler.cjs +26 -0
- package/dist/v2/runtime/endpoints/node-fetch-handler.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/node-fetch-handler.d.cts +12 -0
- package/dist/v2/runtime/endpoints/node-fetch-handler.d.cts.map +1 -0
- package/dist/v2/runtime/endpoints/node-fetch-handler.d.mts +12 -0
- package/dist/v2/runtime/endpoints/node-fetch-handler.d.mts.map +1 -0
- package/dist/v2/runtime/endpoints/node-fetch-handler.mjs +24 -0
- package/dist/v2/runtime/endpoints/node-fetch-handler.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/node.cjs +30 -0
- package/dist/v2/runtime/endpoints/node.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/node.d.cts +27 -0
- package/dist/v2/runtime/endpoints/node.d.cts.map +1 -0
- package/dist/v2/runtime/endpoints/node.d.mts +27 -0
- package/dist/v2/runtime/endpoints/node.d.mts.map +1 -0
- package/dist/v2/runtime/endpoints/node.mjs +30 -0
- package/dist/v2/runtime/endpoints/node.mjs.map +1 -0
- package/dist/v2/runtime/express.d.cts +3 -0
- package/dist/v2/runtime/express.d.mts +3 -0
- package/dist/v2/runtime/handlers/get-runtime-info.cjs +2 -1
- package/dist/v2/runtime/handlers/get-runtime-info.cjs.map +1 -1
- package/dist/v2/runtime/handlers/get-runtime-info.mjs +2 -1
- package/dist/v2/runtime/handlers/get-runtime-info.mjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-connect.cjs +6 -3
- package/dist/v2/runtime/handlers/handle-connect.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-connect.mjs +6 -3
- package/dist/v2/runtime/handlers/handle-connect.mjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-run.cjs +6 -3
- package/dist/v2/runtime/handlers/handle-run.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-run.mjs +6 -3
- package/dist/v2/runtime/handlers/handle-run.mjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-stop.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-stop.mjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-transcribe.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-transcribe.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/connect.cjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/connect.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/run.cjs +22 -1
- package/dist/v2/runtime/handlers/intelligence/run.cjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/run.mjs +22 -1
- package/dist/v2/runtime/handlers/intelligence/run.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/thread-names.cjs +1 -1
- package/dist/v2/runtime/handlers/intelligence/thread-names.cjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/thread-names.mjs +1 -1
- package/dist/v2/runtime/handlers/intelligence/thread-names.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs +21 -6
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs +21 -6
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/json-response.cjs +4 -1
- package/dist/v2/runtime/handlers/shared/json-response.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/json-response.mjs +4 -1
- package/dist/v2/runtime/handlers/shared/json-response.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/connect.cjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/connect.mjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/run.cjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/run.mjs.map +1 -1
- package/dist/v2/runtime/hono.d.cts +3 -0
- package/dist/v2/runtime/hono.d.mts +3 -0
- package/dist/v2/runtime/index.d.cts +16 -4
- package/dist/v2/runtime/index.d.cts.map +1 -0
- package/dist/v2/runtime/index.d.mts +16 -4
- package/dist/v2/runtime/index.d.mts.map +1 -0
- package/dist/v2/runtime/intelligence-platform/client.cjs +10 -1
- package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.cts +22 -0
- package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.mts +22 -0
- package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.mjs +10 -1
- package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
- package/dist/v2/runtime/node.d.cts +3 -0
- package/dist/v2/runtime/node.d.mts +3 -0
- package/dist/v2/runtime/open-generative-ui-middleware.cjs +282 -0
- package/dist/v2/runtime/open-generative-ui-middleware.cjs.map +1 -0
- package/dist/v2/runtime/open-generative-ui-middleware.mjs +280 -0
- package/dist/v2/runtime/open-generative-ui-middleware.mjs.map +1 -0
- package/dist/v2/runtime/runner/intelligence.cjs +4 -4
- package/dist/v2/runtime/runner/intelligence.cjs.map +1 -1
- package/dist/v2/runtime/runner/intelligence.d.cts +6 -2
- package/dist/v2/runtime/runner/intelligence.d.cts.map +1 -1
- package/dist/v2/runtime/runner/intelligence.d.mts +6 -2
- package/dist/v2/runtime/runner/intelligence.d.mts.map +1 -1
- package/dist/v2/runtime/runner/intelligence.mjs +4 -4
- package/dist/v2/runtime/runner/intelligence.mjs.map +1 -1
- package/dist/v2/runtime/telemetry/telemetry-client.cjs +37 -0
- package/dist/v2/runtime/telemetry/telemetry-client.cjs.map +1 -1
- package/dist/v2/runtime/telemetry/telemetry-client.mjs +36 -0
- package/dist/v2/runtime/telemetry/telemetry-client.mjs.map +1 -1
- package/dist/v2/runtime/telemetry/utils.cjs +15 -0
- package/dist/v2/runtime/telemetry/utils.cjs.map +1 -0
- package/dist/v2/runtime/telemetry/utils.mjs +14 -0
- package/dist/v2/runtime/telemetry/utils.mjs.map +1 -0
- package/package.json +81 -48
- package/src/agent/__tests__/multimodal.test.ts +176 -0
- package/src/agent/index.ts +130 -19
- package/src/lib/runtime/agent-integrations/langgraph/agent.ts +3 -3
- package/src/lib/runtime/copilot-runtime.ts +1 -0
- package/src/v2/express.ts +1 -0
- package/src/v2/hono.ts +1 -0
- package/src/v2/node.ts +1 -0
- package/src/v2/runtime/__tests__/backward-compat.test.ts +261 -0
- package/src/v2/runtime/__tests__/code-review-fixes.test.ts +500 -0
- package/src/v2/runtime/__tests__/cors-credentials.test.ts +2 -2
- package/src/v2/runtime/__tests__/express-adapter.test.ts +188 -0
- package/src/v2/runtime/__tests__/express-body-order.test.ts +1 -1
- package/src/v2/runtime/__tests__/express-fetch-bridge.test.ts +344 -0
- package/src/v2/runtime/__tests__/express-single-sse.test.ts +1 -1
- package/src/v2/runtime/__tests__/fetch-cors.test.ts +205 -0
- package/src/v2/runtime/__tests__/fetch-handler-validation.test.ts +372 -0
- package/src/v2/runtime/__tests__/fetch-handler.test.ts +456 -0
- package/src/v2/runtime/__tests__/fetch-router.test.ts +132 -0
- package/src/v2/runtime/__tests__/get-runtime-info.test.ts +4 -1
- package/src/v2/runtime/__tests__/handle-connect.test.ts +15 -13
- package/src/v2/runtime/__tests__/handle-run.test.ts +21 -17
- package/src/v2/runtime/__tests__/handle-threads.test.ts +1 -1
- package/src/v2/runtime/__tests__/handle-transcribe.test.ts +1 -1
- package/src/v2/runtime/__tests__/hono-adapter.test.ts +150 -0
- package/src/v2/runtime/__tests__/hooks-edge-cases.test.ts +457 -0
- package/src/v2/runtime/__tests__/hooks.test.ts +557 -0
- package/src/v2/runtime/__tests__/integration/bun/bun-servers.integration.test.ts +27 -0
- package/src/v2/runtime/__tests__/integration/bun/elysia-multi.ts +32 -0
- package/src/v2/runtime/__tests__/integration/bun/elysia-single.ts +33 -0
- package/src/v2/runtime/__tests__/integration/bun/hono-bun-multi.ts +25 -0
- package/src/v2/runtime/__tests__/integration/bun/hono-bun-single.ts +32 -0
- package/src/v2/runtime/__tests__/integration/helpers/create-test-runtime.ts +15 -0
- package/src/v2/runtime/__tests__/integration/helpers/sse-reader.ts +45 -0
- package/src/v2/runtime/__tests__/integration/helpers/test-agent.ts +58 -0
- package/src/v2/runtime/__tests__/integration/node-servers.integration.test.ts +39 -0
- package/src/v2/runtime/__tests__/integration/servers/express-multi.ts +35 -0
- package/src/v2/runtime/__tests__/integration/servers/express-single.ts +36 -0
- package/src/v2/runtime/__tests__/integration/servers/fetch-direct.ts +39 -0
- package/src/v2/runtime/__tests__/integration/servers/hono-multi.ts +30 -0
- package/src/v2/runtime/__tests__/integration/servers/hono-single.ts +37 -0
- package/src/v2/runtime/__tests__/integration/servers/node-multi.ts +45 -0
- package/src/v2/runtime/__tests__/integration/servers/node-single.ts +46 -0
- package/src/v2/runtime/__tests__/integration/servers/types.ts +18 -0
- package/src/v2/runtime/__tests__/integration/suites/multi-endpoint.suite.ts +358 -0
- package/src/v2/runtime/__tests__/integration/suites/single-endpoint.suite.ts +363 -0
- package/src/v2/runtime/__tests__/middleware-express.test.ts +25 -23
- package/src/v2/runtime/__tests__/middleware-single-express.test.ts +25 -23
- package/src/v2/runtime/__tests__/middleware-single.test.ts +1 -1
- package/src/v2/runtime/__tests__/middleware-sse-parser.test.ts +1 -1
- package/src/v2/runtime/__tests__/middleware.test.ts +1 -2
- package/src/v2/runtime/__tests__/node-fetch-handler.test.ts +157 -0
- package/src/v2/runtime/__tests__/open-generative-ui-middleware.e2e.test.ts +728 -0
- package/src/v2/runtime/__tests__/router-edge-cases.test.ts +217 -0
- package/src/v2/runtime/__tests__/routing-express.test.ts +1 -1
- package/src/v2/runtime/__tests__/routing-single-express.test.ts +1 -1
- package/src/v2/runtime/__tests__/routing-single.test.ts +1 -1
- package/src/v2/runtime/__tests__/routing.test.ts +1 -1
- package/src/v2/runtime/__tests__/runtime.test.ts +110 -1
- package/src/v2/runtime/__tests__/telemetry.test.ts +62 -1
- package/src/v2/runtime/core/fetch-cors.ts +136 -0
- package/src/v2/runtime/core/fetch-handler.ts +415 -0
- package/src/v2/runtime/core/fetch-router.ts +112 -0
- package/src/v2/runtime/core/hooks.ts +151 -0
- package/src/v2/runtime/{runtime.ts → core/runtime.ts} +79 -10
- package/src/v2/runtime/endpoints/express-fetch-bridge.ts +137 -0
- package/src/v2/runtime/endpoints/express-single.ts +42 -219
- package/src/v2/runtime/endpoints/express.ts +128 -230
- package/src/v2/runtime/endpoints/hono-single.ts +19 -171
- package/src/v2/runtime/endpoints/hono.ts +45 -270
- package/src/v2/runtime/endpoints/node-fetch-handler.ts +48 -0
- package/src/v2/runtime/endpoints/node.ts +28 -0
- package/src/v2/runtime/handlers/get-runtime-info.ts +3 -2
- package/src/v2/runtime/handlers/handle-connect.ts +7 -4
- package/src/v2/runtime/handlers/handle-run.ts +7 -4
- package/src/v2/runtime/handlers/handle-stop.ts +1 -1
- package/src/v2/runtime/handlers/handle-transcribe.ts +1 -1
- package/src/v2/runtime/handlers/intelligence/connect.ts +1 -1
- package/src/v2/runtime/handlers/intelligence/run.ts +31 -1
- package/src/v2/runtime/handlers/intelligence/thread-names.ts +2 -2
- package/src/v2/runtime/handlers/intelligence/threads.ts +1 -1
- package/src/v2/runtime/handlers/shared/agent-utils.ts +29 -10
- package/src/v2/runtime/handlers/shared/json-response.ts +4 -1
- package/src/v2/runtime/handlers/shared/resolve-intelligence-user.ts +1 -1
- package/src/v2/runtime/handlers/sse/connect.ts +1 -1
- package/src/v2/runtime/handlers/sse/run.ts +1 -1
- package/src/v2/runtime/hono.ts +2 -0
- package/src/v2/runtime/index.ts +27 -1
- package/src/v2/runtime/intelligence-platform/client.ts +50 -1
- package/src/v2/runtime/node.ts +6 -0
- package/src/v2/runtime/open-generative-ui-middleware.ts +373 -0
- package/src/v2/runtime/runner/intelligence.ts +14 -4
- package/src/v2/runtime/telemetry/telemetry-client.ts +56 -0
- package/src/v2/runtime/telemetry/utils.ts +15 -0
- package/tsdown.config.ts +8 -1
- package/vitest.config.mjs +2 -5
- package/.eslintrc.js +0 -7
- package/dist/v2/runtime/endpoints/express-utils.cjs +0 -119
- package/dist/v2/runtime/endpoints/express-utils.cjs.map +0 -1
- package/dist/v2/runtime/endpoints/express-utils.mjs +0 -117
- package/dist/v2/runtime/endpoints/express-utils.mjs.map +0 -1
- package/dist/v2/runtime/handlers/intelligence/threads.cjs +0 -159
- package/dist/v2/runtime/handlers/intelligence/threads.cjs.map +0 -1
- package/dist/v2/runtime/handlers/intelligence/threads.mjs +0 -154
- package/dist/v2/runtime/handlers/intelligence/threads.mjs.map +0 -1
- package/dist/v2/runtime/middleware-sse-parser.cjs.map +0 -1
- package/dist/v2/runtime/middleware-sse-parser.d.cts.map +0 -1
- package/dist/v2/runtime/middleware-sse-parser.d.mts.map +0 -1
- package/dist/v2/runtime/middleware-sse-parser.mjs.map +0 -1
- package/dist/v2/runtime/middleware.cjs.map +0 -1
- package/dist/v2/runtime/middleware.d.cts.map +0 -1
- package/dist/v2/runtime/middleware.d.mts.map +0 -1
- package/dist/v2/runtime/middleware.mjs.map +0 -1
- package/dist/v2/runtime/runtime.cjs.map +0 -1
- package/dist/v2/runtime/runtime.d.cts.map +0 -1
- package/dist/v2/runtime/runtime.d.mts.map +0 -1
- package/dist/v2/runtime/runtime.mjs.map +0 -1
- package/src/v2/runtime/__tests__/express-abort-signal.test.ts +0 -25
- package/src/v2/runtime/endpoints/express-utils.ts +0 -182
- package/src/v2/runtime/handler.ts +0 -3
- /package/src/v2/runtime/{middleware-sse-parser.ts → core/middleware-sse-parser.ts} +0 -0
- /package/src/v2/runtime/{middleware.ts → core/middleware.ts} +0 -0
|
@@ -1,24 +1,8 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { handleGetRuntimeInfo } from "../handlers/get-runtime-info";
|
|
7
|
-
import { handleTranscribe } from "../handlers/handle-transcribe";
|
|
8
|
-
import { logger, getLicenseWarningHeader } from "@copilotkit/shared";
|
|
9
|
-
import {
|
|
10
|
-
callBeforeRequestMiddleware,
|
|
11
|
-
callAfterRequestMiddleware,
|
|
12
|
-
} from "../middleware";
|
|
13
|
-
import { handleConnectAgent } from "../handlers/handle-connect";
|
|
14
|
-
import { handleStopAgent } from "../handlers/handle-stop";
|
|
15
|
-
import {
|
|
16
|
-
handleListThreads,
|
|
17
|
-
handleSubscribeToThreads,
|
|
18
|
-
handleUpdateThread,
|
|
19
|
-
handleArchiveThread,
|
|
20
|
-
handleDeleteThread,
|
|
21
|
-
} from "../handlers/handle-threads";
|
|
2
|
+
import type { CopilotRuntimeLike } from "../core/runtime";
|
|
3
|
+
import { createCopilotRuntimeHandler } from "../core/fetch-handler";
|
|
4
|
+
import type { CopilotCorsConfig } from "../core/fetch-cors";
|
|
5
|
+
import type { CopilotRuntimeHooks } from "../core/hooks";
|
|
22
6
|
|
|
23
7
|
/**
|
|
24
8
|
* CORS configuration for CopilotKit endpoints.
|
|
@@ -47,268 +31,59 @@ export interface CopilotEndpointCorsConfig {
|
|
|
47
31
|
interface CopilotEndpointParams {
|
|
48
32
|
runtime: CopilotRuntimeLike;
|
|
49
33
|
basePath: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Endpoint mode.
|
|
37
|
+
* - `"multi-route"` (default): separate routes for each operation
|
|
38
|
+
* - `"single-route"`: single POST endpoint with JSON envelope dispatch
|
|
39
|
+
*/
|
|
40
|
+
mode?: "multi-route" | "single-route";
|
|
41
|
+
|
|
50
42
|
/**
|
|
51
43
|
* Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.
|
|
52
44
|
* To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.
|
|
53
45
|
*/
|
|
54
46
|
cors?: CopilotEndpointCorsConfig;
|
|
47
|
+
/**
|
|
48
|
+
* Lifecycle hooks for request processing.
|
|
49
|
+
*/
|
|
50
|
+
hooks?: CopilotRuntimeHooks;
|
|
55
51
|
}
|
|
52
|
+
/** @deprecated Use `createCopilotHonoHandler` instead. */
|
|
53
|
+
export const createCopilotEndpoint = createCopilotHonoHandler;
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
type CopilotEndpointContext = {
|
|
59
|
-
Variables: {
|
|
60
|
-
modifiedRequest?: Request;
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export function createCopilotEndpoint({
|
|
55
|
+
export function createCopilotHonoHandler({
|
|
65
56
|
runtime,
|
|
66
57
|
basePath,
|
|
58
|
+
mode = "multi-route",
|
|
67
59
|
cors: corsConfig,
|
|
60
|
+
hooks,
|
|
68
61
|
}: CopilotEndpointParams) {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
endpointTypes: [],
|
|
77
|
-
endpointsAmount: 0,
|
|
78
|
-
agentsAmount: Object.keys(agents).length,
|
|
79
|
-
"cloud.api_key_provided": false,
|
|
80
|
-
});
|
|
81
|
-
})
|
|
82
|
-
.catch(() => {
|
|
83
|
-
// Silently fail - telemetry should not break the application
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
return app
|
|
87
|
-
.basePath(basePath)
|
|
88
|
-
.use(
|
|
89
|
-
"*",
|
|
90
|
-
cors({
|
|
91
|
-
origin: corsConfig?.origin ?? "*",
|
|
92
|
-
allowMethods: [
|
|
93
|
-
"GET",
|
|
94
|
-
"HEAD",
|
|
95
|
-
"PUT",
|
|
96
|
-
"POST",
|
|
97
|
-
"DELETE",
|
|
98
|
-
"PATCH",
|
|
99
|
-
"OPTIONS",
|
|
100
|
-
],
|
|
101
|
-
allowHeaders: ["*"],
|
|
102
|
-
credentials: corsConfig?.credentials ?? false,
|
|
103
|
-
}),
|
|
104
|
-
)
|
|
105
|
-
.use("*", async (c, next) => {
|
|
106
|
-
const request = c.req.raw;
|
|
107
|
-
const path = c.req.path;
|
|
108
|
-
|
|
109
|
-
try {
|
|
110
|
-
const maybeModifiedRequest = await callBeforeRequestMiddleware({
|
|
111
|
-
runtime,
|
|
112
|
-
request,
|
|
113
|
-
path,
|
|
114
|
-
});
|
|
115
|
-
if (maybeModifiedRequest) {
|
|
116
|
-
c.set("modifiedRequest", maybeModifiedRequest);
|
|
117
|
-
}
|
|
118
|
-
} catch (error) {
|
|
119
|
-
logger.error(
|
|
120
|
-
{ err: error, url: request.url, path },
|
|
121
|
-
"Error running before request middleware",
|
|
122
|
-
);
|
|
123
|
-
if (error instanceof Response) {
|
|
124
|
-
return error;
|
|
125
|
-
}
|
|
126
|
-
throw error;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const warning = getLicenseWarningHeader(runtime.licenseChecker);
|
|
130
|
-
if (warning) c.header(warning.key, warning.value);
|
|
131
|
-
|
|
132
|
-
await next();
|
|
133
|
-
})
|
|
134
|
-
.use("*", async (c, next) => {
|
|
135
|
-
await next();
|
|
136
|
-
|
|
137
|
-
const response = c.res.clone();
|
|
138
|
-
const path = c.req.path;
|
|
62
|
+
const handler = createCopilotRuntimeHandler({
|
|
63
|
+
runtime,
|
|
64
|
+
basePath,
|
|
65
|
+
mode,
|
|
66
|
+
cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,
|
|
67
|
+
hooks,
|
|
68
|
+
});
|
|
139
69
|
|
|
140
|
-
|
|
141
|
-
callAfterRequestMiddleware({
|
|
142
|
-
runtime,
|
|
143
|
-
response,
|
|
144
|
-
path,
|
|
145
|
-
}).catch((error) => {
|
|
146
|
-
logger.error(
|
|
147
|
-
{ err: error, url: c.req.url, path },
|
|
148
|
-
"Error running after request middleware",
|
|
149
|
-
);
|
|
150
|
-
});
|
|
151
|
-
})
|
|
152
|
-
.post("/agent/:agentId/run", async (c) => {
|
|
153
|
-
const agentId = c.req.param("agentId");
|
|
154
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
70
|
+
const app = new Hono();
|
|
155
71
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
runtime,
|
|
159
|
-
request,
|
|
160
|
-
agentId,
|
|
161
|
-
});
|
|
162
|
-
} catch (error) {
|
|
163
|
-
logger.error(
|
|
164
|
-
{ err: error, url: request.url, path: c.req.path },
|
|
165
|
-
"Error running request handler",
|
|
166
|
-
);
|
|
167
|
-
throw error;
|
|
168
|
-
}
|
|
169
|
-
})
|
|
170
|
-
.post("/agent/:agentId/connect", async (c) => {
|
|
171
|
-
const agentId = c.req.param("agentId");
|
|
172
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
173
|
-
|
|
174
|
-
try {
|
|
175
|
-
return await handleConnectAgent({
|
|
176
|
-
runtime,
|
|
177
|
-
request,
|
|
178
|
-
agentId,
|
|
179
|
-
});
|
|
180
|
-
} catch (error) {
|
|
181
|
-
logger.error(
|
|
182
|
-
{ err: error, url: request.url, path: c.req.path },
|
|
183
|
-
"Error running request handler",
|
|
184
|
-
);
|
|
185
|
-
throw error;
|
|
186
|
-
}
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
.post("/agent/:agentId/stop/:threadId", async (c) => {
|
|
190
|
-
const agentId = c.req.param("agentId");
|
|
191
|
-
const threadId = c.req.param("threadId");
|
|
192
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
193
|
-
|
|
194
|
-
try {
|
|
195
|
-
return await handleStopAgent({
|
|
196
|
-
runtime,
|
|
197
|
-
request,
|
|
198
|
-
agentId,
|
|
199
|
-
threadId,
|
|
200
|
-
});
|
|
201
|
-
} catch (error) {
|
|
202
|
-
logger.error(
|
|
203
|
-
{ err: error, url: request.url, path: c.req.path },
|
|
204
|
-
"Error running request handler",
|
|
205
|
-
);
|
|
206
|
-
throw error;
|
|
207
|
-
}
|
|
208
|
-
})
|
|
209
|
-
.get("/info", async (c) => {
|
|
210
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
211
|
-
|
|
212
|
-
try {
|
|
213
|
-
return await handleGetRuntimeInfo({
|
|
214
|
-
runtime,
|
|
215
|
-
request,
|
|
216
|
-
});
|
|
217
|
-
} catch (error) {
|
|
218
|
-
logger.error(
|
|
219
|
-
{ err: error, url: request.url, path: c.req.path },
|
|
220
|
-
"Error running request handler",
|
|
221
|
-
);
|
|
222
|
-
throw error;
|
|
223
|
-
}
|
|
224
|
-
})
|
|
225
|
-
.post("/transcribe", async (c) => {
|
|
226
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
227
|
-
|
|
228
|
-
try {
|
|
229
|
-
return await handleTranscribe({
|
|
230
|
-
runtime,
|
|
231
|
-
request,
|
|
232
|
-
});
|
|
233
|
-
} catch (error) {
|
|
234
|
-
logger.error(
|
|
235
|
-
{ err: error, url: request.url, path: c.req.path },
|
|
236
|
-
"Error running request handler",
|
|
237
|
-
);
|
|
238
|
-
throw error;
|
|
239
|
-
}
|
|
240
|
-
})
|
|
241
|
-
.get("/threads", async (c) => {
|
|
242
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
243
|
-
|
|
244
|
-
try {
|
|
245
|
-
return await handleListThreads({ runtime, request });
|
|
246
|
-
} catch (error) {
|
|
247
|
-
logger.error(
|
|
248
|
-
{ err: error, url: request.url, path: c.req.path },
|
|
249
|
-
"Error running request handler",
|
|
250
|
-
);
|
|
251
|
-
throw error;
|
|
252
|
-
}
|
|
253
|
-
})
|
|
254
|
-
.post("/threads/subscribe", async (c) => {
|
|
255
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
256
|
-
|
|
257
|
-
try {
|
|
258
|
-
return await handleSubscribeToThreads({ runtime, request });
|
|
259
|
-
} catch (error) {
|
|
260
|
-
logger.error(
|
|
261
|
-
{ err: error, url: request.url, path: c.req.path },
|
|
262
|
-
"Error running request handler",
|
|
263
|
-
);
|
|
264
|
-
throw error;
|
|
265
|
-
}
|
|
266
|
-
})
|
|
267
|
-
.patch("/threads/:threadId", async (c) => {
|
|
268
|
-
const threadId = c.req.param("threadId");
|
|
269
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
270
|
-
|
|
271
|
-
try {
|
|
272
|
-
return await handleUpdateThread({ runtime, request, threadId });
|
|
273
|
-
} catch (error) {
|
|
274
|
-
logger.error(
|
|
275
|
-
{ err: error, url: request.url, path: c.req.path },
|
|
276
|
-
"Error running request handler",
|
|
277
|
-
);
|
|
278
|
-
throw error;
|
|
279
|
-
}
|
|
280
|
-
})
|
|
281
|
-
.post("/threads/:threadId/archive", async (c) => {
|
|
282
|
-
const threadId = c.req.param("threadId");
|
|
283
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
284
|
-
|
|
285
|
-
try {
|
|
286
|
-
return await handleArchiveThread({ runtime, request, threadId });
|
|
287
|
-
} catch (error) {
|
|
288
|
-
logger.error(
|
|
289
|
-
{ err: error, url: request.url, path: c.req.path },
|
|
290
|
-
"Error running request handler",
|
|
291
|
-
);
|
|
292
|
-
throw error;
|
|
293
|
-
}
|
|
294
|
-
})
|
|
295
|
-
.delete("/threads/:threadId", async (c) => {
|
|
296
|
-
const threadId = c.req.param("threadId");
|
|
297
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
298
|
-
|
|
299
|
-
try {
|
|
300
|
-
return await handleDeleteThread({ runtime, request, threadId });
|
|
301
|
-
} catch (error) {
|
|
302
|
-
logger.error(
|
|
303
|
-
{ err: error, url: request.url, path: c.req.path },
|
|
304
|
-
"Error running request handler",
|
|
305
|
-
);
|
|
306
|
-
throw error;
|
|
307
|
-
}
|
|
308
|
-
})
|
|
309
|
-
.notFound((c) => {
|
|
310
|
-
return c.json({ error: "Not found" }, 404);
|
|
311
|
-
});
|
|
72
|
+
return app.basePath(basePath).all("*", async (c) => handler(c.req.raw));
|
|
73
|
+
}
|
|
312
74
|
|
|
313
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.
|
|
77
|
+
*/
|
|
78
|
+
export function toFetchCorsConfig(
|
|
79
|
+
config: CopilotEndpointCorsConfig,
|
|
80
|
+
): CopilotCorsConfig {
|
|
81
|
+
const origin = config.origin;
|
|
82
|
+
return {
|
|
83
|
+
origin:
|
|
84
|
+
typeof origin === "function"
|
|
85
|
+
? (reqOrigin: string) => origin(reqOrigin, undefined) ?? null
|
|
86
|
+
: origin,
|
|
87
|
+
credentials: config.credentials,
|
|
88
|
+
};
|
|
314
89
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Node ↔ Fetch bridge for CopilotKit runtime.
|
|
3
|
+
*
|
|
4
|
+
* Wraps a `CopilotRuntimeFetchHandler` as a Node HTTP handler using
|
|
5
|
+
* `@remix-run/node-fetch-server` for reliable streaming and conversion.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createServer } from "node:http";
|
|
10
|
+
* import { createCopilotRuntimeHandler } from "@copilotkit/runtime/v2";
|
|
11
|
+
* import { createCopilotNodeHandler } from "@copilotkit/runtime/v2/node";
|
|
12
|
+
*
|
|
13
|
+
* const handler = createCopilotRuntimeHandler({ runtime, basePath: "/api/copilotkit", cors: true });
|
|
14
|
+
* const nodeHandler = createCopilotNodeHandler(handler);
|
|
15
|
+
* createServer(nodeHandler).listen(3000);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
20
|
+
import { createRequest, sendResponse } from "@remix-run/node-fetch-server";
|
|
21
|
+
import type { CopilotRuntimeFetchHandler } from "../core/fetch-handler";
|
|
22
|
+
import { logger } from "@copilotkit/shared";
|
|
23
|
+
|
|
24
|
+
export type NodeFetchHandler = (
|
|
25
|
+
req: IncomingMessage,
|
|
26
|
+
res: ServerResponse,
|
|
27
|
+
) => Promise<void>;
|
|
28
|
+
|
|
29
|
+
export function createCopilotNodeHandler(
|
|
30
|
+
handler: CopilotRuntimeFetchHandler,
|
|
31
|
+
): NodeFetchHandler {
|
|
32
|
+
return async (req: IncomingMessage, res: ServerResponse) => {
|
|
33
|
+
try {
|
|
34
|
+
const fetchReq = createRequest(req, res);
|
|
35
|
+
const fetchRes = await handler(fetchReq);
|
|
36
|
+
await sendResponse(res, fetchRes);
|
|
37
|
+
} catch (err: unknown) {
|
|
38
|
+
logger.error({ err }, "Error in Node fetch handler");
|
|
39
|
+
if (!res.headersSent) {
|
|
40
|
+
res.statusCode = 500;
|
|
41
|
+
res.end("Internal Server Error");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @deprecated Use `createCopilotNodeHandler` instead. */
|
|
48
|
+
export const createNodeFetchHandler = createCopilotNodeHandler;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createCopilotRuntimeHandler } from "../core/fetch-handler";
|
|
2
|
+
import type { CopilotRuntimeHandlerOptions } from "../core/fetch-handler";
|
|
3
|
+
import { createCopilotNodeHandler } from "./node-fetch-handler";
|
|
4
|
+
import type { NodeFetchHandler } from "./node-fetch-handler";
|
|
5
|
+
/**
|
|
6
|
+
* Convenience wrapper for creating a Node.js HTTP request listener
|
|
7
|
+
* from CopilotKit runtime handler options.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createServer } from "node:http";
|
|
12
|
+
* import { CopilotRuntime } from "@copilotkit/runtime/v2";
|
|
13
|
+
* import { createCopilotNodeListener } from "@copilotkit/runtime/v2/node";
|
|
14
|
+
*
|
|
15
|
+
* const listener = createCopilotNodeListener({
|
|
16
|
+
* runtime: new CopilotRuntime({ agents: { ... } }),
|
|
17
|
+
* basePath: "/api/copilotkit",
|
|
18
|
+
* cors: true,
|
|
19
|
+
* });
|
|
20
|
+
* createServer(listener).listen(3000);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function createCopilotNodeListener(
|
|
24
|
+
options: CopilotRuntimeHandlerOptions,
|
|
25
|
+
): NodeFetchHandler {
|
|
26
|
+
const handler = createCopilotRuntimeHandler(options);
|
|
27
|
+
return createCopilotNodeHandler(handler);
|
|
28
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { CopilotRuntimeLike, isIntelligenceRuntime } from "../runtime";
|
|
1
|
+
import { CopilotRuntimeLike, isIntelligenceRuntime } from "../core/runtime";
|
|
2
2
|
import {
|
|
3
3
|
AgentDescription,
|
|
4
4
|
RuntimeInfo,
|
|
5
5
|
type RuntimeLicenseStatus,
|
|
6
6
|
} from "@copilotkit/shared";
|
|
7
|
-
import { VERSION } from "../runtime";
|
|
7
|
+
import { VERSION } from "../core/runtime";
|
|
8
8
|
|
|
9
9
|
function resolveLicenseStatus(
|
|
10
10
|
runtime: CopilotRuntimeLike,
|
|
@@ -55,6 +55,7 @@ export async function handleGetRuntimeInfo({
|
|
|
55
55
|
}
|
|
56
56
|
: {}),
|
|
57
57
|
a2uiEnabled: !!runtime.a2ui,
|
|
58
|
+
openGenerativeUIEnabled: !!runtime.openGenerativeUI,
|
|
58
59
|
...(isIntelligenceRuntime(runtime)
|
|
59
60
|
? { licenseStatus: resolveLicenseStatus(runtime) }
|
|
60
61
|
: {}),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { handleIntelligenceConnect } from "./intelligence/connect";
|
|
2
2
|
import { handleSseConnect } from "./sse/connect";
|
|
3
|
-
import { isIntelligenceRuntime } from "../runtime";
|
|
3
|
+
import { isIntelligenceRuntime } from "../core/runtime";
|
|
4
4
|
import { telemetry } from "../telemetry";
|
|
5
5
|
import {
|
|
6
6
|
parseConnectRequest,
|
|
@@ -65,12 +65,15 @@ export async function handleConnectAgent({
|
|
|
65
65
|
cause: error instanceof Error ? error.cause : undefined,
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
return Response
|
|
69
|
-
{
|
|
68
|
+
return new Response(
|
|
69
|
+
JSON.stringify({
|
|
70
70
|
error: "Failed to run agent",
|
|
71
71
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
72
|
+
}),
|
|
73
|
+
{
|
|
74
|
+
status: 500,
|
|
75
|
+
headers: { "Content-Type": "application/json" },
|
|
72
76
|
},
|
|
73
|
-
{ status: 500 },
|
|
74
77
|
);
|
|
75
78
|
}
|
|
76
79
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isIntelligenceRuntime } from "../runtime";
|
|
1
|
+
import { isIntelligenceRuntime } from "../core/runtime";
|
|
2
2
|
import { telemetry } from "../telemetry";
|
|
3
3
|
import {
|
|
4
4
|
cloneAgentForRequest,
|
|
@@ -78,12 +78,15 @@ export async function handleRunAgent({
|
|
|
78
78
|
cause: error instanceof Error ? error.cause : undefined,
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
-
return Response
|
|
82
|
-
{
|
|
81
|
+
return new Response(
|
|
82
|
+
JSON.stringify({
|
|
83
83
|
error: "Failed to run agent",
|
|
84
84
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
85
|
+
}),
|
|
86
|
+
{
|
|
87
|
+
status: 500,
|
|
88
|
+
headers: { "Content-Type": "application/json" },
|
|
85
89
|
},
|
|
86
|
-
{ status: 500 },
|
|
87
90
|
);
|
|
88
91
|
}
|
|
89
92
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CopilotIntelligenceRuntimeLike } from "../../runtime";
|
|
1
|
+
import { CopilotIntelligenceRuntimeLike } from "../../core/runtime";
|
|
2
2
|
import { isPlatformNotFoundError } from "../shared/intelligence-utils";
|
|
3
3
|
import { resolveIntelligenceUser } from "../shared/resolve-intelligence-user";
|
|
4
4
|
import { isHandlerResponse } from "../shared/json-response";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractAgent, Message, RunAgentInput } from "@ag-ui/client";
|
|
2
|
-
import { CopilotIntelligenceRuntimeLike } from "../../runtime";
|
|
2
|
+
import { CopilotIntelligenceRuntimeLike } from "../../core/runtime";
|
|
3
3
|
import { generateThreadNameForNewThread } from "./thread-names";
|
|
4
4
|
import { logger } from "@copilotkit/shared";
|
|
5
5
|
import { telemetry } from "../../telemetry";
|
|
@@ -73,6 +73,10 @@ export async function handleIntelligenceRun({
|
|
|
73
73
|
threadId: input.threadId,
|
|
74
74
|
runId: input.runId,
|
|
75
75
|
userId,
|
|
76
|
+
...(runtime.lockKeyPrefix !== undefined
|
|
77
|
+
? { lockKeyPrefix: runtime.lockKeyPrefix }
|
|
78
|
+
: {}),
|
|
79
|
+
ttlSeconds: runtime.lockTtlSeconds,
|
|
76
80
|
});
|
|
77
81
|
joinToken = lockResult.joinToken;
|
|
78
82
|
joinCode = lockResult.joinCode;
|
|
@@ -121,6 +125,30 @@ export async function handleIntelligenceRun({
|
|
|
121
125
|
|
|
122
126
|
telemetry.capture("oss.runtime.agent_execution_stream_started", {});
|
|
123
127
|
|
|
128
|
+
// Start heartbeat timer to renew the thread lock.
|
|
129
|
+
let heartbeatTimer: ReturnType<typeof setInterval> | undefined;
|
|
130
|
+
heartbeatTimer = setInterval(() => {
|
|
131
|
+
runtime.intelligence
|
|
132
|
+
.ɵrenewThreadLock({
|
|
133
|
+
threadId: input.threadId,
|
|
134
|
+
runId: input.runId,
|
|
135
|
+
ttlSeconds: runtime.lockTtlSeconds,
|
|
136
|
+
...(runtime.lockKeyPrefix !== undefined
|
|
137
|
+
? { lockKeyPrefix: runtime.lockKeyPrefix }
|
|
138
|
+
: {}),
|
|
139
|
+
})
|
|
140
|
+
.catch((err) => {
|
|
141
|
+
logger.error("Failed to renew thread lock:", err);
|
|
142
|
+
});
|
|
143
|
+
}, runtime.lockHeartbeatIntervalSeconds * 1_000);
|
|
144
|
+
|
|
145
|
+
const clearHeartbeat = () => {
|
|
146
|
+
if (heartbeatTimer !== undefined) {
|
|
147
|
+
clearInterval(heartbeatTimer);
|
|
148
|
+
heartbeatTimer = undefined;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
124
152
|
runtime.runner
|
|
125
153
|
.run({
|
|
126
154
|
threadId: input.threadId,
|
|
@@ -133,12 +161,14 @@ export async function handleIntelligenceRun({
|
|
|
133
161
|
})
|
|
134
162
|
.subscribe({
|
|
135
163
|
error: (error) => {
|
|
164
|
+
clearHeartbeat();
|
|
136
165
|
telemetry.capture("oss.runtime.agent_execution_stream_errored", {
|
|
137
166
|
error: error instanceof Error ? error.message : String(error),
|
|
138
167
|
});
|
|
139
168
|
logger.error("Error running agent:", error);
|
|
140
169
|
},
|
|
141
170
|
complete: () => {
|
|
171
|
+
clearHeartbeat();
|
|
142
172
|
telemetry.capture("oss.runtime.agent_execution_stream_ended", {});
|
|
143
173
|
},
|
|
144
174
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AbstractAgent, Message, RunAgentInput } from "@ag-ui/client";
|
|
2
2
|
import { logger } from "@copilotkit/shared";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
|
-
import { CopilotIntelligenceRuntimeLike } from "../../runtime";
|
|
4
|
+
import { CopilotIntelligenceRuntimeLike } from "../../core/runtime";
|
|
5
5
|
import {
|
|
6
6
|
cloneAgentForRequest,
|
|
7
7
|
configureAgentForRequest,
|
|
@@ -130,7 +130,7 @@ async function runTitleGenerationAttempt(params: {
|
|
|
130
130
|
|
|
131
131
|
agent.setMessages(messages);
|
|
132
132
|
agent.setState({});
|
|
133
|
-
agent.threadId =
|
|
133
|
+
agent.threadId = randomUUID();
|
|
134
134
|
const { newMessages } = await agent.runAgent({
|
|
135
135
|
messages,
|
|
136
136
|
state: {},
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
CopilotIntelligenceRuntimeLike,
|
|
3
3
|
CopilotRuntimeLike,
|
|
4
4
|
isIntelligenceRuntime,
|
|
5
|
-
} from "../../runtime";
|
|
5
|
+
} from "../../core/runtime";
|
|
6
6
|
import { logger } from "@copilotkit/shared";
|
|
7
7
|
import { errorResponse, isHandlerResponse } from "../shared/json-response";
|
|
8
8
|
import { isValidIdentifier } from "../shared/intelligence-utils";
|
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
} from "@ag-ui/client";
|
|
6
6
|
import { A2UIMiddleware } from "@ag-ui/a2ui-middleware";
|
|
7
7
|
import { MCPAppsMiddleware } from "@ag-ui/mcp-apps-middleware";
|
|
8
|
-
import { CopilotRuntimeLike } from "../../runtime";
|
|
8
|
+
import { CopilotRuntimeLike } from "../../core/runtime";
|
|
9
|
+
import { OpenGenerativeUIMiddleware } from "../../open-generative-ui-middleware";
|
|
9
10
|
import { extractForwardableHeaders } from "../header-utils";
|
|
10
11
|
import { logger } from "@copilotkit/shared";
|
|
11
12
|
|
|
@@ -31,12 +32,15 @@ export async function cloneAgentForRequest(
|
|
|
31
32
|
const agents = await runtime.agents;
|
|
32
33
|
|
|
33
34
|
if (!agents[agentId]) {
|
|
34
|
-
return Response
|
|
35
|
-
{
|
|
35
|
+
return new Response(
|
|
36
|
+
JSON.stringify({
|
|
36
37
|
error: "Agent not found",
|
|
37
38
|
message: `Agent '${agentId}' does not exist`,
|
|
39
|
+
}),
|
|
40
|
+
{
|
|
41
|
+
status: 404,
|
|
42
|
+
headers: { "Content-Type": "application/json" },
|
|
38
43
|
},
|
|
39
|
-
{ status: 404 },
|
|
40
44
|
);
|
|
41
45
|
}
|
|
42
46
|
|
|
@@ -74,6 +78,15 @@ export function configureAgentForRequest(params: {
|
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
80
|
|
|
81
|
+
if (runtime.openGenerativeUI) {
|
|
82
|
+
const config = runtime.openGenerativeUI;
|
|
83
|
+
const targetAgents = typeof config === "object" ? config.agents : undefined;
|
|
84
|
+
const shouldApply = !targetAgents || targetAgents.includes(agentId);
|
|
85
|
+
if (shouldApply && typeof agent.use === "function") {
|
|
86
|
+
agent.use(new OpenGenerativeUIMiddleware());
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
77
90
|
if (agent.headers) {
|
|
78
91
|
agent.headers = {
|
|
79
92
|
...agent.headers,
|
|
@@ -90,12 +103,15 @@ export async function parseRunRequest(
|
|
|
90
103
|
return RunAgentInputSchema.parse(requestBody);
|
|
91
104
|
} catch (error) {
|
|
92
105
|
logger.error("Invalid run request body:", error);
|
|
93
|
-
return Response
|
|
94
|
-
{
|
|
106
|
+
return new Response(
|
|
107
|
+
JSON.stringify({
|
|
95
108
|
error: "Invalid request body",
|
|
96
109
|
details: error instanceof Error ? error.message : String(error),
|
|
110
|
+
}),
|
|
111
|
+
{
|
|
112
|
+
status: 400,
|
|
113
|
+
headers: { "Content-Type": "application/json" },
|
|
97
114
|
},
|
|
98
|
-
{ status: 400 },
|
|
99
115
|
);
|
|
100
116
|
}
|
|
101
117
|
}
|
|
@@ -125,12 +141,15 @@ export async function parseConnectRequest(request: Request): Promise<
|
|
|
125
141
|
return { input, lastSeenEventId };
|
|
126
142
|
} catch (error) {
|
|
127
143
|
logger.error("Invalid connect request body:", error);
|
|
128
|
-
return Response
|
|
129
|
-
{
|
|
144
|
+
return new Response(
|
|
145
|
+
JSON.stringify({
|
|
130
146
|
error: "Invalid request body",
|
|
131
147
|
details: error instanceof Error ? error.message : String(error),
|
|
148
|
+
}),
|
|
149
|
+
{
|
|
150
|
+
status: 400,
|
|
151
|
+
headers: { "Content-Type": "application/json" },
|
|
132
152
|
},
|
|
133
|
-
{ status: 400 },
|
|
134
153
|
);
|
|
135
154
|
}
|
|
136
155
|
}
|