@copilotkit/runtime 1.57.2 → 1.57.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/runtime/copilot-runtime.cjs +2 -0
- package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.mjs +2 -0
- package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
- package/dist/package.cjs +52 -19
- package/dist/package.mjs +52 -19
- package/dist/v2/runtime/core/runtime.cjs +4 -1
- package/dist/v2/runtime/core/runtime.cjs.map +1 -1
- package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
- package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
- package/dist/v2/runtime/core/runtime.mjs +4 -1
- package/dist/v2/runtime/core/runtime.mjs.map +1 -1
- package/dist/v2/runtime/handlers/get-runtime-info.cjs +1 -1
- package/dist/v2/runtime/handlers/get-runtime-info.mjs +1 -1
- package/dist/v2/runtime/handlers/handle-connect.cjs +1 -1
- package/dist/v2/runtime/handlers/handle-connect.mjs +1 -1
- package/dist/v2/runtime/handlers/handle-run.cjs +1 -1
- package/dist/v2/runtime/handlers/handle-run.mjs +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -1
- package/dist/v2/runtime/telemetry/telemetry-client.cjs +22 -6
- package/dist/v2/runtime/telemetry/telemetry-client.cjs.map +1 -1
- package/dist/v2/runtime/telemetry/telemetry-client.mjs +27 -11
- package/dist/v2/runtime/telemetry/telemetry-client.mjs.map +1 -1
- package/package.json +8 -18
- package/skills/runtime/SKILL.md +98 -0
- package/skills/runtime/references/agent-runners-custom.md +161 -0
- package/skills/runtime/references/agent-runners-in-memory.md +64 -0
- package/skills/runtime/references/agent-runners-sqlite.md +90 -0
- package/skills/runtime/references/agent-runners.md +304 -0
- package/skills/runtime/references/built-in-agent-factory-modes.md +232 -0
- package/skills/runtime/references/built-in-agent-helper-utilities.md +123 -0
- package/skills/runtime/references/built-in-agent-model-identifiers.md +59 -0
- package/skills/runtime/references/built-in-agent.md +523 -0
- package/skills/runtime/references/intelligence-mode.md +336 -0
- package/skills/runtime/references/middleware.md +376 -0
- package/skills/runtime/references/server-side-tools.md +414 -0
- package/skills/runtime/references/setup-endpoint.md +503 -0
- package/skills/runtime/references/transcription.md +287 -0
- package/skills/runtime/references/wiring-a2a.md +40 -0
- package/skills/runtime/references/wiring-adk.md +45 -0
- package/skills/runtime/references/wiring-ag2.md +41 -0
- package/skills/runtime/references/wiring-agno.md +39 -0
- package/skills/runtime/references/wiring-aws-strands.md +59 -0
- package/skills/runtime/references/wiring-crewai-crews.md +51 -0
- package/skills/runtime/references/wiring-crewai-flows.md +45 -0
- package/skills/runtime/references/wiring-external-agents.md +348 -0
- package/skills/runtime/references/wiring-langgraph.md +50 -0
- package/skills/runtime/references/wiring-llamaindex.md +39 -0
- package/skills/runtime/references/wiring-mastra.md +70 -0
- package/skills/runtime/references/wiring-mcp-apps-middleware.md +68 -0
- package/skills/runtime/references/wiring-ms-agent-framework.md +41 -0
- package/skills/runtime/references/wiring-pydantic-ai.md +45 -0
- package/CHANGELOG.md +0 -3624
- package/__snapshots__/schema/schema.graphql +0 -371
- package/dist/v2/runtime/telemetry/scarf-client.cjs +0 -32
- package/dist/v2/runtime/telemetry/scarf-client.cjs.map +0 -1
- package/dist/v2/runtime/telemetry/scarf-client.mjs +0 -32
- package/dist/v2/runtime/telemetry/scarf-client.mjs.map +0 -1
- package/scripts/generate-gql-schema.ts +0 -16
- package/src/agent/__tests__/agent-test-helpers.ts +0 -476
- package/src/agent/__tests__/agent.test.ts +0 -593
- package/src/agent/__tests__/ai-sdk-v6-compat.test.ts +0 -116
- package/src/agent/__tests__/basic-agent.test.ts +0 -1698
- package/src/agent/__tests__/capabilities.test.ts +0 -81
- package/src/agent/__tests__/config-tools-execution.test.ts +0 -516
- package/src/agent/__tests__/converter-aisdk.test.ts +0 -692
- package/src/agent/__tests__/converter-custom.test.ts +0 -319
- package/src/agent/__tests__/converter-tanstack-input.test.ts +0 -211
- package/src/agent/__tests__/converter-tanstack.test.ts +0 -594
- package/src/agent/__tests__/mcp-clients.test.ts +0 -246
- package/src/agent/__tests__/mcp-servers-integration.test.ts +0 -373
- package/src/agent/__tests__/multimodal-tanstack.test.ts +0 -284
- package/src/agent/__tests__/multimodal.test.ts +0 -176
- package/src/agent/__tests__/property-overrides.test.ts +0 -598
- package/src/agent/__tests__/provider-id-collision.test.ts +0 -195
- package/src/agent/__tests__/standard-schema-tools.test.ts +0 -313
- package/src/agent/__tests__/standard-schema-types.test.ts +0 -158
- package/src/agent/__tests__/state-tools.test.ts +0 -436
- package/src/agent/__tests__/test-helpers.ts +0 -197
- package/src/agent/__tests__/utils.test.ts +0 -536
- package/src/agent/__tests__/zod-regression.test.ts +0 -350
- package/src/agent/converters/aisdk.ts +0 -326
- package/src/agent/converters/index.ts +0 -7
- package/src/agent/converters/tanstack.ts +0 -451
- package/src/agent/index.ts +0 -1743
- package/src/agents/langgraph/__tests__/event-source.test.ts +0 -256
- package/src/agents/langgraph/event-source.ts +0 -365
- package/src/agents/langgraph/events.ts +0 -394
- package/src/graphql/inputs/action.input.ts +0 -16
- package/src/graphql/inputs/agent-session.input.ts +0 -13
- package/src/graphql/inputs/agent-state.input.ts +0 -13
- package/src/graphql/inputs/cloud-guardrails.input.ts +0 -16
- package/src/graphql/inputs/cloud.input.ts +0 -8
- package/src/graphql/inputs/context-property.input.ts +0 -10
- package/src/graphql/inputs/copilot-context.input.ts +0 -10
- package/src/graphql/inputs/custom-property.input.ts +0 -15
- package/src/graphql/inputs/extensions.input.ts +0 -21
- package/src/graphql/inputs/forwarded-parameters.input.ts +0 -22
- package/src/graphql/inputs/frontend.input.ts +0 -14
- package/src/graphql/inputs/generate-copilot-response.input.ts +0 -59
- package/src/graphql/inputs/load-agent-state.input.ts +0 -10
- package/src/graphql/inputs/message.input.ts +0 -110
- package/src/graphql/inputs/meta-event.input.ts +0 -18
- package/src/graphql/message-conversion/agui-to-gql.test.ts +0 -1384
- package/src/graphql/message-conversion/agui-to-gql.ts +0 -384
- package/src/graphql/message-conversion/gql-to-agui.test.ts +0 -1653
- package/src/graphql/message-conversion/gql-to-agui.ts +0 -297
- package/src/graphql/message-conversion/index.ts +0 -2
- package/src/graphql/message-conversion/roundtrip-conversion.test.ts +0 -561
- package/src/graphql/resolvers/__tests__/resolve-message-id.test.ts +0 -25
- package/src/graphql/resolvers/copilot.resolver.ts +0 -785
- package/src/graphql/resolvers/resolve-message-id.ts +0 -14
- package/src/graphql/resolvers/state.resolver.ts +0 -30
- package/src/graphql/types/agents-response.type.ts +0 -19
- package/src/graphql/types/base/index.ts +0 -10
- package/src/graphql/types/converted/index.ts +0 -183
- package/src/graphql/types/copilot-response.type.ts +0 -141
- package/src/graphql/types/enums.ts +0 -38
- package/src/graphql/types/extensions-response.type.ts +0 -23
- package/src/graphql/types/guardrails-result.type.ts +0 -20
- package/src/graphql/types/load-agent-state-response.type.ts +0 -17
- package/src/graphql/types/message-status.type.ts +0 -48
- package/src/graphql/types/meta-events.type.ts +0 -78
- package/src/graphql/types/response-status.type.ts +0 -77
- package/src/index.ts +0 -3
- package/src/langgraph.ts +0 -1
- package/src/lib/__tests__/telemetry-disclosure.test.ts +0 -55
- package/src/lib/cloud/index.ts +0 -4
- package/src/lib/error-messages.ts +0 -211
- package/src/lib/index.ts +0 -52
- package/src/lib/integrations/index.ts +0 -6
- package/src/lib/integrations/nest/index.ts +0 -21
- package/src/lib/integrations/nextjs/app-router.ts +0 -47
- package/src/lib/integrations/nextjs/pages-router.ts +0 -45
- package/src/lib/integrations/node-express/index.ts +0 -21
- package/src/lib/integrations/node-http/__tests__/request-duck-type.test.ts +0 -66
- package/src/lib/integrations/node-http/index.ts +0 -187
- package/src/lib/integrations/node-http/request-handler.ts +0 -128
- package/src/lib/integrations/shared.ts +0 -112
- package/src/lib/logger.ts +0 -31
- package/src/lib/observability.ts +0 -167
- package/src/lib/runtime/__tests__/copilot-runtime-error.test.ts +0 -183
- package/src/lib/runtime/__tests__/handle-service-adapter.test.ts +0 -108
- package/src/lib/runtime/__tests__/mcp-tools-utils.test.ts +0 -499
- package/src/lib/runtime/__tests__/on-after-request.test.ts +0 -122
- package/src/lib/runtime/__tests__/retry-utils.test.ts +0 -137
- package/src/lib/runtime/__tests__/v1-agent-factory.test.ts +0 -109
- package/src/lib/runtime/agent-integrations/langgraph/__tests__/dispatch-event-filtering.test.ts +0 -345
- package/src/lib/runtime/agent-integrations/langgraph/__tests__/run-message-filtering.test.ts +0 -156
- package/src/lib/runtime/agent-integrations/langgraph/agent.ts +0 -263
- package/src/lib/runtime/agent-integrations/langgraph/consts.ts +0 -37
- package/src/lib/runtime/agent-integrations/langgraph/index.ts +0 -2
- package/src/lib/runtime/copilot-runtime.ts +0 -863
- package/src/lib/runtime/mcp-tools-utils.ts +0 -313
- package/src/lib/runtime/retry-utils.ts +0 -141
- package/src/lib/runtime/telemetry-agent-runner.ts +0 -151
- package/src/lib/runtime/types.ts +0 -48
- package/src/lib/runtime/utils.ts +0 -93
- package/src/lib/streaming.ts +0 -220
- package/src/lib/telemetry-client.ts +0 -66
- package/src/lib/telemetry-disclosure.ts +0 -53
- package/src/service-adapters/anthropic/anthropic-adapter.ts +0 -532
- package/src/service-adapters/anthropic/utils.ts +0 -219
- package/src/service-adapters/bedrock/bedrock-adapter.ts +0 -73
- package/src/service-adapters/conversion.test.ts +0 -56
- package/src/service-adapters/conversion.ts +0 -69
- package/src/service-adapters/empty/empty-adapter.ts +0 -38
- package/src/service-adapters/events.ts +0 -337
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +0 -84
- package/src/service-adapters/google/google-genai-adapter.test.ts +0 -151
- package/src/service-adapters/google/google-genai-adapter.ts +0 -95
- package/src/service-adapters/groq/groq-adapter.ts +0 -229
- package/src/service-adapters/index.ts +0 -18
- package/src/service-adapters/langchain/langchain-adapter.ts +0 -113
- package/src/service-adapters/langchain/langserve.ts +0 -88
- package/src/service-adapters/langchain/types.ts +0 -20
- package/src/service-adapters/langchain/utils.ts +0 -330
- package/src/service-adapters/openai/__tests__/openai-v5-compat.test.ts +0 -177
- package/src/service-adapters/openai/openai-adapter.ts +0 -324
- package/src/service-adapters/openai/openai-assistant-adapter.ts +0 -385
- package/src/service-adapters/openai/utils.ts +0 -305
- package/src/service-adapters/service-adapter.ts +0 -50
- package/src/service-adapters/shared/error-utils.ts +0 -64
- package/src/service-adapters/shared/index.ts +0 -2
- package/src/service-adapters/shared/sdk-client-utils.ts +0 -19
- package/src/service-adapters/unify/unify-adapter.ts +0 -165
- package/src/utils/failed-response-status-reasons.ts +0 -70
- package/src/utils/index.ts +0 -1
- package/src/v2/express.ts +0 -1
- package/src/v2/hono.ts +0 -1
- package/src/v2/index.ts +0 -5
- package/src/v2/node.ts +0 -1
- package/src/v2/runtime/__tests__/agents-factory.test.ts +0 -136
- package/src/v2/runtime/__tests__/backward-compat.test.ts +0 -261
- package/src/v2/runtime/__tests__/code-review-fixes.test.ts +0 -500
- package/src/v2/runtime/__tests__/cors-credentials.test.ts +0 -320
- package/src/v2/runtime/__tests__/debug-sse-response.test.ts +0 -302
- package/src/v2/runtime/__tests__/express-adapter.test.ts +0 -188
- package/src/v2/runtime/__tests__/express-body-order.test.ts +0 -76
- package/src/v2/runtime/__tests__/express-fetch-bridge.test.ts +0 -344
- package/src/v2/runtime/__tests__/express-single-sse.test.ts +0 -122
- package/src/v2/runtime/__tests__/express-single-telemetry.integration.test.ts +0 -65
- package/src/v2/runtime/__tests__/express-telemetry.integration.test.ts +0 -101
- package/src/v2/runtime/__tests__/fetch-cors.test.ts +0 -205
- package/src/v2/runtime/__tests__/fetch-handler-validation.test.ts +0 -440
- package/src/v2/runtime/__tests__/fetch-handler.test.ts +0 -456
- package/src/v2/runtime/__tests__/fetch-router.test.ts +0 -276
- package/src/v2/runtime/__tests__/get-runtime-info.test.ts +0 -335
- package/src/v2/runtime/__tests__/handle-connect.test.ts +0 -585
- package/src/v2/runtime/__tests__/handle-run.test.ts +0 -1388
- package/src/v2/runtime/__tests__/handle-threads.test.ts +0 -930
- package/src/v2/runtime/__tests__/handle-transcribe.test.ts +0 -301
- package/src/v2/runtime/__tests__/header-utils.test.ts +0 -88
- package/src/v2/runtime/__tests__/hono-adapter.test.ts +0 -150
- package/src/v2/runtime/__tests__/hono-single-telemetry.integration.test.ts +0 -46
- package/src/v2/runtime/__tests__/hono-telemetry.integration.test.ts +0 -99
- package/src/v2/runtime/__tests__/hooks-edge-cases.test.ts +0 -457
- package/src/v2/runtime/__tests__/hooks.test.ts +0 -557
- package/src/v2/runtime/__tests__/in-process-agent-runner-messages.test.ts +0 -230
- package/src/v2/runtime/__tests__/in-process-agent-runner.test.ts +0 -1030
- package/src/v2/runtime/__tests__/integration/bun/bun-servers.integration.test.ts +0 -27
- package/src/v2/runtime/__tests__/integration/bun/elysia-multi.ts +0 -32
- package/src/v2/runtime/__tests__/integration/bun/elysia-single.ts +0 -33
- package/src/v2/runtime/__tests__/integration/bun/hono-bun-multi.ts +0 -25
- package/src/v2/runtime/__tests__/integration/bun/hono-bun-single.ts +0 -32
- package/src/v2/runtime/__tests__/integration/helpers/create-test-runtime.ts +0 -15
- package/src/v2/runtime/__tests__/integration/helpers/sse-reader.ts +0 -45
- package/src/v2/runtime/__tests__/integration/helpers/test-agent.ts +0 -58
- package/src/v2/runtime/__tests__/integration/node-servers.integration.test.ts +0 -58
- package/src/v2/runtime/__tests__/integration/servers/express-multi.ts +0 -35
- package/src/v2/runtime/__tests__/integration/servers/express-single.ts +0 -36
- package/src/v2/runtime/__tests__/integration/servers/fetch-direct.ts +0 -39
- package/src/v2/runtime/__tests__/integration/servers/hono-multi.ts +0 -30
- package/src/v2/runtime/__tests__/integration/servers/hono-single.ts +0 -37
- package/src/v2/runtime/__tests__/integration/servers/node-multi.ts +0 -45
- package/src/v2/runtime/__tests__/integration/servers/node-single.ts +0 -46
- package/src/v2/runtime/__tests__/integration/servers/types.ts +0 -18
- package/src/v2/runtime/__tests__/integration/suites/debug-events.suite.ts +0 -253
- package/src/v2/runtime/__tests__/integration/suites/multi-endpoint.suite.ts +0 -358
- package/src/v2/runtime/__tests__/integration/suites/single-endpoint.suite.ts +0 -363
- package/src/v2/runtime/__tests__/intelligence-run-telemetry.test.ts +0 -194
- package/src/v2/runtime/__tests__/mcp-apps-middleware-integration.test.ts +0 -275
- package/src/v2/runtime/__tests__/middleware-express.test.ts +0 -208
- package/src/v2/runtime/__tests__/middleware-single-express.test.ts +0 -213
- package/src/v2/runtime/__tests__/middleware-single.test.ts +0 -225
- package/src/v2/runtime/__tests__/middleware-sse-parser.test.ts +0 -237
- package/src/v2/runtime/__tests__/middleware.test.ts +0 -250
- package/src/v2/runtime/__tests__/node-fetch-handler.test.ts +0 -157
- package/src/v2/runtime/__tests__/open-generative-ui-middleware.e2e.test.ts +0 -728
- package/src/v2/runtime/__tests__/router-edge-cases.test.ts +0 -217
- package/src/v2/runtime/__tests__/routing-express.test.ts +0 -174
- package/src/v2/runtime/__tests__/routing-single-express.test.ts +0 -168
- package/src/v2/runtime/__tests__/routing-single.test.ts +0 -193
- package/src/v2/runtime/__tests__/routing.test.ts +0 -257
- package/src/v2/runtime/__tests__/runtime.test.ts +0 -234
- package/src/v2/runtime/__tests__/sse-response-telemetry.test.ts +0 -108
- package/src/v2/runtime/__tests__/telemetry.test.ts +0 -167
- package/src/v2/runtime/__tests__/thread-names.test.ts +0 -188
- package/src/v2/runtime/core/__tests__/debug-event-bus.test.ts +0 -156
- package/src/v2/runtime/core/debug-event-bus.ts +0 -45
- package/src/v2/runtime/core/fetch-cors.ts +0 -136
- package/src/v2/runtime/core/fetch-handler.ts +0 -492
- package/src/v2/runtime/core/fetch-router.ts +0 -203
- package/src/v2/runtime/core/hooks.ts +0 -160
- package/src/v2/runtime/core/middleware-sse-parser.ts +0 -210
- package/src/v2/runtime/core/middleware.ts +0 -115
- package/src/v2/runtime/core/runtime.ts +0 -432
- package/src/v2/runtime/endpoints/express-fetch-bridge.ts +0 -137
- package/src/v2/runtime/endpoints/express-single.ts +0 -54
- package/src/v2/runtime/endpoints/express.ts +0 -179
- package/src/v2/runtime/endpoints/hono-single.ts +0 -60
- package/src/v2/runtime/endpoints/hono.ts +0 -89
- package/src/v2/runtime/endpoints/index.ts +0 -4
- package/src/v2/runtime/endpoints/node-fetch-handler.ts +0 -48
- package/src/v2/runtime/endpoints/node.ts +0 -28
- package/src/v2/runtime/endpoints/single-route-helpers.ts +0 -125
- package/src/v2/runtime/express.ts +0 -2
- package/src/v2/runtime/handlers/__tests__/handle-debug-events.test.ts +0 -176
- package/src/v2/runtime/handlers/get-runtime-info.ts +0 -101
- package/src/v2/runtime/handlers/handle-connect.ts +0 -80
- package/src/v2/runtime/handlers/handle-debug-events.ts +0 -52
- package/src/v2/runtime/handlers/handle-run.ts +0 -111
- package/src/v2/runtime/handlers/handle-stop.ts +0 -77
- package/src/v2/runtime/handlers/handle-threads.ts +0 -11
- package/src/v2/runtime/handlers/handle-transcribe.ts +0 -269
- package/src/v2/runtime/handlers/header-utils.ts +0 -24
- package/src/v2/runtime/handlers/intelligence/connect.ts +0 -102
- package/src/v2/runtime/handlers/intelligence/run.ts +0 -351
- package/src/v2/runtime/handlers/intelligence/thread-names.ts +0 -246
- package/src/v2/runtime/handlers/intelligence/threads.ts +0 -420
- package/src/v2/runtime/handlers/shared/agent-utils.ts +0 -154
- package/src/v2/runtime/handlers/shared/intelligence-utils.ts +0 -41
- package/src/v2/runtime/handlers/shared/json-response.ts +0 -9
- package/src/v2/runtime/handlers/shared/resolve-intelligence-user.ts +0 -28
- package/src/v2/runtime/handlers/shared/sse-response.ts +0 -215
- package/src/v2/runtime/handlers/sse/__tests__/sse-connect-agent-id.test.ts +0 -71
- package/src/v2/runtime/handlers/sse/connect.ts +0 -30
- package/src/v2/runtime/handlers/sse/run.ts +0 -40
- package/src/v2/runtime/hono.ts +0 -2
- package/src/v2/runtime/index.ts +0 -51
- package/src/v2/runtime/intelligence-platform/__tests__/client.test.ts +0 -601
- package/src/v2/runtime/intelligence-platform/__tests__/intelligence-mcp-helper.test.ts +0 -246
- package/src/v2/runtime/intelligence-platform/client.ts +0 -818
- package/src/v2/runtime/intelligence-platform/index.ts +0 -10
- package/src/v2/runtime/node.ts +0 -6
- package/src/v2/runtime/open-generative-ui-middleware.ts +0 -373
- package/src/v2/runtime/runner/__tests__/finalize-events.test.ts +0 -109
- package/src/v2/runtime/runner/__tests__/in-memory-runner.e2e.test.ts +0 -775
- package/src/v2/runtime/runner/__tests__/in-memory-runner.test.ts +0 -777
- package/src/v2/runtime/runner/__tests__/intelligence-runner.test.ts +0 -1039
- package/src/v2/runtime/runner/agent-runner.ts +0 -35
- package/src/v2/runtime/runner/in-memory.ts +0 -467
- package/src/v2/runtime/runner/index.ts +0 -4
- package/src/v2/runtime/runner/intelligence.ts +0 -498
- package/src/v2/runtime/telemetry/__tests__/instance-created.test.ts +0 -96
- package/src/v2/runtime/telemetry/events.ts +0 -35
- package/src/v2/runtime/telemetry/index.ts +0 -7
- package/src/v2/runtime/telemetry/instance-created.ts +0 -44
- package/src/v2/runtime/telemetry/scarf-client.ts +0 -39
- package/src/v2/runtime/telemetry/telemetry-client.ts +0 -70
- package/src/v2/runtime/transcription-service/transcription-service.ts +0 -11
- package/tests/global.d.ts +0 -1
- package/tests/service-adapters/anthropic/allowlist-approach.test.ts +0 -259
- package/tests/service-adapters/anthropic/anthropic-adapter-language-model.test.ts +0 -101
- package/tests/service-adapters/anthropic/anthropic-adapter.test.ts +0 -645
- package/tests/service-adapters/anthropic/utils-token-trimming.test.ts +0 -301
- package/tests/service-adapters/groq/groq-adapter-language-model.test.ts +0 -102
- package/tests/service-adapters/openai/allowlist-approach.test.ts +0 -294
- package/tests/service-adapters/openai/openai-adapter-language-model.test.ts +0 -122
- package/tests/service-adapters/openai/openai-adapter.test.ts +0 -291
- package/tests/service-adapters/shared/sdk-client-utils.test.ts +0 -36
- package/tests/setup.vitest.ts +0 -8
- package/tests/tsconfig.json +0 -10
- package/tsconfig.json +0 -20
- package/tsdown.config.ts +0 -45
- package/typedoc.json +0 -4
- package/vitest.config.mjs +0 -13
|
@@ -1,432 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MaybePromise,
|
|
3
|
-
NonEmptyRecord,
|
|
4
|
-
RuntimeMode,
|
|
5
|
-
RUNTIME_MODE_SSE,
|
|
6
|
-
RUNTIME_MODE_INTELLIGENCE,
|
|
7
|
-
} from "@copilotkit/shared";
|
|
8
|
-
import {
|
|
9
|
-
createLicenseChecker,
|
|
10
|
-
type LicenseChecker,
|
|
11
|
-
} from "@copilotkit/license-verifier";
|
|
12
|
-
import {
|
|
13
|
-
type ResolvedDebugConfig,
|
|
14
|
-
resolveDebugConfig,
|
|
15
|
-
type DebugConfig,
|
|
16
|
-
} from "@copilotkit/shared";
|
|
17
|
-
import { AbstractAgent } from "@ag-ui/client";
|
|
18
|
-
import type { MCPClientConfig } from "@ag-ui/mcp-apps-middleware";
|
|
19
|
-
import { A2UIMiddlewareConfig } from "@ag-ui/a2ui-middleware";
|
|
20
|
-
import pkg from "../../../../package.json";
|
|
21
|
-
import type {
|
|
22
|
-
BeforeRequestMiddleware,
|
|
23
|
-
AfterRequestMiddleware,
|
|
24
|
-
} from "./middleware";
|
|
25
|
-
import { createLogger, type CopilotRuntimeLogger } from "../../../lib/logger";
|
|
26
|
-
import { logRuntimeTelemetryDisclosure } from "../../../lib/telemetry-disclosure";
|
|
27
|
-
import { TranscriptionService } from "../transcription-service/transcription-service";
|
|
28
|
-
import { DebugEventBus } from "./debug-event-bus";
|
|
29
|
-
import { AgentRunner } from "../runner/agent-runner";
|
|
30
|
-
import { InMemoryAgentRunner } from "../runner/in-memory";
|
|
31
|
-
import { IntelligenceAgentRunner } from "../runner/intelligence";
|
|
32
|
-
import { CopilotKitIntelligence } from "../intelligence-platform";
|
|
33
|
-
|
|
34
|
-
export const VERSION = pkg.version;
|
|
35
|
-
|
|
36
|
-
interface BaseCopilotRuntimeMiddlewareOptions {
|
|
37
|
-
/** If set, middleware only applies to these named agents. Applies to all agents if omitted. */
|
|
38
|
-
agents?: string[];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export type McpAppsServerConfig = MCPClientConfig & {
|
|
42
|
-
/** Agent to bind this server to. If omitted, the server is available to all agents. */
|
|
43
|
-
agentId?: string;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export interface McpAppsConfig {
|
|
47
|
-
/** List of MCP server configurations. */
|
|
48
|
-
servers: McpAppsServerConfig[];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface OpenGenerativeUIOptions extends BaseCopilotRuntimeMiddlewareOptions {}
|
|
52
|
-
|
|
53
|
-
export type OpenGenerativeUIConfig = boolean | OpenGenerativeUIOptions;
|
|
54
|
-
|
|
55
|
-
interface CopilotRuntimeMiddlewares {
|
|
56
|
-
/**
|
|
57
|
-
* Auto-apply A2UIMiddleware to agents at run time.
|
|
58
|
-
* Pass an object to enable and customise behaviour, or omit to disable.
|
|
59
|
-
*/
|
|
60
|
-
a2ui?: BaseCopilotRuntimeMiddlewareOptions & A2UIMiddlewareConfig;
|
|
61
|
-
/** Auto-apply MCPAppsMiddleware to agents at run time. */
|
|
62
|
-
mcpApps?: McpAppsConfig;
|
|
63
|
-
/** Auto-apply OpenGenerativeUIMiddleware to agents at run time. */
|
|
64
|
-
openGenerativeUI?: OpenGenerativeUIConfig;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Context passed to agent factory functions for per-request agent resolution.
|
|
69
|
-
*/
|
|
70
|
-
export interface AgentFactoryContext {
|
|
71
|
-
/** The incoming HTTP request. */
|
|
72
|
-
request: Request;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* A function that dynamically creates agents on a per-request basis.
|
|
77
|
-
* Useful for multi-tenant scenarios or request-scoped agent configuration.
|
|
78
|
-
*/
|
|
79
|
-
export type AgentsFactory = (
|
|
80
|
-
ctx: AgentFactoryContext,
|
|
81
|
-
) => MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Agents can be provided as:
|
|
85
|
-
* - A static record of agents
|
|
86
|
-
* - A Promise that resolves to a record of agents
|
|
87
|
-
* - A factory function that receives request context and returns agents (or a Promise of agents)
|
|
88
|
-
*/
|
|
89
|
-
export type AgentsConfig =
|
|
90
|
-
| MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>
|
|
91
|
-
| AgentsFactory;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Resolve an AgentsConfig value to a concrete record of agents.
|
|
95
|
-
* If the config is a factory function, it is called with the given request context.
|
|
96
|
-
* Otherwise it is awaited directly (static record or Promise).
|
|
97
|
-
*/
|
|
98
|
-
export async function resolveAgents(
|
|
99
|
-
agents: AgentsConfig,
|
|
100
|
-
request?: Request,
|
|
101
|
-
): Promise<Record<string, AbstractAgent>> {
|
|
102
|
-
if (typeof agents === "function") {
|
|
103
|
-
if (!request) {
|
|
104
|
-
throw new Error(
|
|
105
|
-
"Agent factory function requires a request context, but none was provided.",
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
return agents({ request });
|
|
109
|
-
}
|
|
110
|
-
return agents;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
interface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {
|
|
114
|
-
/**
|
|
115
|
-
* Map of available agents, or a factory function for per-request agent resolution.
|
|
116
|
-
*
|
|
117
|
-
* Static record:
|
|
118
|
-
* ```ts
|
|
119
|
-
* agents: { support: new SupportAgent(), technical: new TechnicalAgent() }
|
|
120
|
-
* ```
|
|
121
|
-
*
|
|
122
|
-
* Factory function (called per-request):
|
|
123
|
-
* ```ts
|
|
124
|
-
* agents: ({ request }) => {
|
|
125
|
-
* const tenantId = request.headers.get("x-tenant-id");
|
|
126
|
-
* return { default: createAgentForTenant(tenantId) };
|
|
127
|
-
* }
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
|
-
agents: AgentsConfig;
|
|
131
|
-
/** Optional transcription service for audio processing. */
|
|
132
|
-
transcriptionService?: TranscriptionService;
|
|
133
|
-
/** Optional *before* middleware – callback function or webhook URL. */
|
|
134
|
-
beforeRequestMiddleware?: BeforeRequestMiddleware;
|
|
135
|
-
/** Optional *after* middleware – callback function or webhook URL. */
|
|
136
|
-
afterRequestMiddleware?: AfterRequestMiddleware;
|
|
137
|
-
/** Signed license token for server-side feature verification. Falls back to COPILOTKIT_LICENSE_TOKEN env var. */
|
|
138
|
-
licenseToken?: string;
|
|
139
|
-
/** Enable debug logging for the event pipeline. */
|
|
140
|
-
debug?: DebugConfig;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export interface CopilotRuntimeUser {
|
|
144
|
-
id: string;
|
|
145
|
-
name: string;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export type IdentifyUserCallback = (
|
|
149
|
-
request: Request,
|
|
150
|
-
) => MaybePromise<CopilotRuntimeUser>;
|
|
151
|
-
|
|
152
|
-
export interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {
|
|
153
|
-
/** The runner to use for running agents in SSE mode. */
|
|
154
|
-
runner?: AgentRunner;
|
|
155
|
-
intelligence?: undefined;
|
|
156
|
-
generateThreadNames?: undefined;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export interface CopilotIntelligenceRuntimeOptions extends BaseCopilotRuntimeOptions {
|
|
160
|
-
/** Configures Intelligence mode for durable threads and realtime events. */
|
|
161
|
-
intelligence: CopilotKitIntelligence;
|
|
162
|
-
/** Resolves the authenticated user for intelligence requests. */
|
|
163
|
-
identifyUser: IdentifyUserCallback;
|
|
164
|
-
/** Auto-generate short names for newly created threads. */
|
|
165
|
-
generateThreadNames?: boolean;
|
|
166
|
-
/** Max delay (ms) for WebSocket reconnect backoff. @default 10_000 */
|
|
167
|
-
maxReconnectMs?: number;
|
|
168
|
-
/** Max delay (ms) for channel rejoin backoff. @default 30_000 */
|
|
169
|
-
maxRejoinMs?: number;
|
|
170
|
-
/** Lock TTL in seconds. Clamped to a maximum of 3600 (1 hour). @default 20 */
|
|
171
|
-
lockTtlSeconds?: number;
|
|
172
|
-
/** Custom Redis key prefix for the thread lock. */
|
|
173
|
-
lockKeyPrefix?: string;
|
|
174
|
-
/** Interval in seconds at which the runtime renews the thread lock. Clamped to a maximum of 3000 (50 minutes). @default 15 */
|
|
175
|
-
lockHeartbeatIntervalSeconds?: number;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export type CopilotRuntimeOptions =
|
|
179
|
-
| CopilotSseRuntimeOptions
|
|
180
|
-
| CopilotIntelligenceRuntimeOptions;
|
|
181
|
-
|
|
182
|
-
export interface CopilotRuntimeLike {
|
|
183
|
-
agents: CopilotRuntimeOptions["agents"];
|
|
184
|
-
transcriptionService: CopilotRuntimeOptions["transcriptionService"];
|
|
185
|
-
beforeRequestMiddleware: CopilotRuntimeOptions["beforeRequestMiddleware"];
|
|
186
|
-
afterRequestMiddleware: CopilotRuntimeOptions["afterRequestMiddleware"];
|
|
187
|
-
runner: AgentRunner;
|
|
188
|
-
a2ui: CopilotRuntimeOptions["a2ui"];
|
|
189
|
-
mcpApps: CopilotRuntimeOptions["mcpApps"];
|
|
190
|
-
openGenerativeUI: CopilotRuntimeOptions["openGenerativeUI"];
|
|
191
|
-
intelligence?: CopilotKitIntelligence;
|
|
192
|
-
identifyUser?: IdentifyUserCallback;
|
|
193
|
-
mode: RuntimeMode;
|
|
194
|
-
licenseChecker?: LicenseChecker;
|
|
195
|
-
debugEventBus?: DebugEventBus;
|
|
196
|
-
debug: ResolvedDebugConfig;
|
|
197
|
-
debugLogger?: CopilotRuntimeLogger;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export interface CopilotSseRuntimeLike extends CopilotRuntimeLike {
|
|
201
|
-
intelligence?: undefined;
|
|
202
|
-
mode: RUNTIME_MODE_SSE;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export interface CopilotIntelligenceRuntimeLike extends CopilotRuntimeLike {
|
|
206
|
-
intelligence: CopilotKitIntelligence;
|
|
207
|
-
identifyUser: IdentifyUserCallback;
|
|
208
|
-
generateThreadNames: boolean;
|
|
209
|
-
lockTtlSeconds: number;
|
|
210
|
-
lockKeyPrefix?: string;
|
|
211
|
-
lockHeartbeatIntervalSeconds: number;
|
|
212
|
-
mode: RUNTIME_MODE_INTELLIGENCE;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
abstract class BaseCopilotRuntime implements CopilotRuntimeLike {
|
|
216
|
-
public agents: CopilotRuntimeOptions["agents"];
|
|
217
|
-
public transcriptionService: CopilotRuntimeOptions["transcriptionService"];
|
|
218
|
-
public beforeRequestMiddleware: CopilotRuntimeOptions["beforeRequestMiddleware"];
|
|
219
|
-
public afterRequestMiddleware: CopilotRuntimeOptions["afterRequestMiddleware"];
|
|
220
|
-
public runner: AgentRunner;
|
|
221
|
-
public a2ui: CopilotRuntimeOptions["a2ui"];
|
|
222
|
-
public mcpApps: CopilotRuntimeOptions["mcpApps"];
|
|
223
|
-
public openGenerativeUI: CopilotRuntimeOptions["openGenerativeUI"];
|
|
224
|
-
public licenseChecker?: LicenseChecker;
|
|
225
|
-
public readonly debugEventBus?: DebugEventBus;
|
|
226
|
-
public debug: ResolvedDebugConfig;
|
|
227
|
-
public debugLogger?: CopilotRuntimeLogger;
|
|
228
|
-
|
|
229
|
-
abstract readonly intelligence?: CopilotKitIntelligence;
|
|
230
|
-
abstract readonly mode: RuntimeMode;
|
|
231
|
-
|
|
232
|
-
constructor(options: BaseCopilotRuntimeOptions, runner: AgentRunner) {
|
|
233
|
-
logRuntimeTelemetryDisclosure();
|
|
234
|
-
|
|
235
|
-
const {
|
|
236
|
-
agents,
|
|
237
|
-
transcriptionService,
|
|
238
|
-
beforeRequestMiddleware,
|
|
239
|
-
afterRequestMiddleware,
|
|
240
|
-
a2ui,
|
|
241
|
-
mcpApps,
|
|
242
|
-
openGenerativeUI,
|
|
243
|
-
} = options;
|
|
244
|
-
|
|
245
|
-
this.agents = agents;
|
|
246
|
-
this.transcriptionService = transcriptionService;
|
|
247
|
-
this.beforeRequestMiddleware = beforeRequestMiddleware;
|
|
248
|
-
this.afterRequestMiddleware = afterRequestMiddleware;
|
|
249
|
-
this.a2ui = a2ui || undefined;
|
|
250
|
-
this.mcpApps = mcpApps;
|
|
251
|
-
this.openGenerativeUI = openGenerativeUI;
|
|
252
|
-
this.runner = runner;
|
|
253
|
-
|
|
254
|
-
if (process.env.NODE_ENV !== "production") {
|
|
255
|
-
this.debugEventBus = new DebugEventBus();
|
|
256
|
-
}
|
|
257
|
-
this.debug = resolveDebugConfig(options.debug);
|
|
258
|
-
if (this.debug.enabled) {
|
|
259
|
-
this.debugLogger = createLogger({
|
|
260
|
-
level: "debug",
|
|
261
|
-
component: "copilotkit-debug",
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
export class CopilotSseRuntime
|
|
268
|
-
extends BaseCopilotRuntime
|
|
269
|
-
implements CopilotSseRuntimeLike
|
|
270
|
-
{
|
|
271
|
-
readonly intelligence = undefined;
|
|
272
|
-
readonly mode = RUNTIME_MODE_SSE;
|
|
273
|
-
|
|
274
|
-
constructor(options: CopilotSseRuntimeOptions) {
|
|
275
|
-
super(options, options.runner ?? new InMemoryAgentRunner());
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
export class CopilotIntelligenceRuntime
|
|
280
|
-
extends BaseCopilotRuntime
|
|
281
|
-
implements CopilotIntelligenceRuntimeLike
|
|
282
|
-
{
|
|
283
|
-
readonly intelligence: CopilotKitIntelligence;
|
|
284
|
-
readonly identifyUser: IdentifyUserCallback;
|
|
285
|
-
readonly generateThreadNames: boolean;
|
|
286
|
-
readonly lockTtlSeconds: number;
|
|
287
|
-
readonly lockKeyPrefix?: string;
|
|
288
|
-
readonly lockHeartbeatIntervalSeconds: number;
|
|
289
|
-
readonly mode = RUNTIME_MODE_INTELLIGENCE;
|
|
290
|
-
|
|
291
|
-
/** Maximum allowed lock TTL in seconds (1 hour). */
|
|
292
|
-
static readonly MAX_LOCK_TTL_SECONDS = 3_600;
|
|
293
|
-
/** Maximum allowed heartbeat interval in seconds (50 minutes). */
|
|
294
|
-
static readonly MAX_HEARTBEAT_INTERVAL_SECONDS = 3_000;
|
|
295
|
-
|
|
296
|
-
constructor(options: CopilotIntelligenceRuntimeOptions) {
|
|
297
|
-
super(
|
|
298
|
-
options,
|
|
299
|
-
new IntelligenceAgentRunner({
|
|
300
|
-
url: options.intelligence.ɵgetRunnerWsUrl(),
|
|
301
|
-
authToken: options.intelligence.ɵgetRunnerAuthToken(),
|
|
302
|
-
maxReconnectMs: options.maxReconnectMs,
|
|
303
|
-
maxRejoinMs: options.maxRejoinMs,
|
|
304
|
-
}),
|
|
305
|
-
);
|
|
306
|
-
this.intelligence = options.intelligence;
|
|
307
|
-
this.identifyUser = options.identifyUser;
|
|
308
|
-
this.generateThreadNames = options.generateThreadNames ?? true;
|
|
309
|
-
this.licenseChecker = createLicenseChecker(options.licenseToken);
|
|
310
|
-
this.lockTtlSeconds = Math.min(
|
|
311
|
-
options.lockTtlSeconds ?? 20,
|
|
312
|
-
CopilotIntelligenceRuntime.MAX_LOCK_TTL_SECONDS,
|
|
313
|
-
);
|
|
314
|
-
this.lockKeyPrefix = options.lockKeyPrefix;
|
|
315
|
-
this.lockHeartbeatIntervalSeconds = Math.min(
|
|
316
|
-
options.lockHeartbeatIntervalSeconds ?? 15,
|
|
317
|
-
CopilotIntelligenceRuntime.MAX_HEARTBEAT_INTERVAL_SECONDS,
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
function hasIntelligenceOptions(
|
|
323
|
-
options: CopilotRuntimeOptions,
|
|
324
|
-
): options is CopilotIntelligenceRuntimeOptions {
|
|
325
|
-
return "intelligence" in options && !!options.intelligence;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
export function isIntelligenceRuntime(
|
|
329
|
-
runtime: CopilotRuntimeLike,
|
|
330
|
-
): runtime is CopilotIntelligenceRuntimeLike {
|
|
331
|
-
return runtime.mode === RUNTIME_MODE_INTELLIGENCE && !!runtime.intelligence;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Compatibility shim that preserves the legacy `CopilotRuntime` entrypoint.
|
|
336
|
-
* New code should prefer `CopilotSseRuntime` or `CopilotIntelligenceRuntime`.
|
|
337
|
-
*/
|
|
338
|
-
export class CopilotRuntime implements CopilotRuntimeLike {
|
|
339
|
-
private delegate: CopilotRuntimeLike;
|
|
340
|
-
|
|
341
|
-
constructor(options: CopilotRuntimeOptions) {
|
|
342
|
-
this.delegate = hasIntelligenceOptions(options)
|
|
343
|
-
? new CopilotIntelligenceRuntime(options)
|
|
344
|
-
: new CopilotSseRuntime(options);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
get agents(): CopilotRuntimeOptions["agents"] {
|
|
348
|
-
return this.delegate.agents;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
get transcriptionService(): CopilotRuntimeOptions["transcriptionService"] {
|
|
352
|
-
return this.delegate.transcriptionService;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
get beforeRequestMiddleware(): CopilotRuntimeOptions["beforeRequestMiddleware"] {
|
|
356
|
-
return this.delegate.beforeRequestMiddleware;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
get afterRequestMiddleware(): CopilotRuntimeOptions["afterRequestMiddleware"] {
|
|
360
|
-
return this.delegate.afterRequestMiddleware;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
get runner(): AgentRunner {
|
|
364
|
-
return this.delegate.runner;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
get a2ui(): CopilotRuntimeOptions["a2ui"] {
|
|
368
|
-
return this.delegate.a2ui;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
get mcpApps(): CopilotRuntimeOptions["mcpApps"] {
|
|
372
|
-
return this.delegate.mcpApps;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
get openGenerativeUI(): CopilotRuntimeOptions["openGenerativeUI"] {
|
|
376
|
-
return this.delegate.openGenerativeUI;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
get intelligence(): CopilotKitIntelligence | undefined {
|
|
380
|
-
return this.delegate.intelligence;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
get generateThreadNames(): boolean | undefined {
|
|
384
|
-
return isIntelligenceRuntime(this.delegate)
|
|
385
|
-
? this.delegate.generateThreadNames
|
|
386
|
-
: undefined;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
get identifyUser(): IdentifyUserCallback | undefined {
|
|
390
|
-
return isIntelligenceRuntime(this.delegate)
|
|
391
|
-
? this.delegate.identifyUser
|
|
392
|
-
: undefined;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
get lockTtlSeconds(): number | undefined {
|
|
396
|
-
return isIntelligenceRuntime(this.delegate)
|
|
397
|
-
? this.delegate.lockTtlSeconds
|
|
398
|
-
: undefined;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
get lockKeyPrefix(): string | undefined {
|
|
402
|
-
return isIntelligenceRuntime(this.delegate)
|
|
403
|
-
? this.delegate.lockKeyPrefix
|
|
404
|
-
: undefined;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
get lockHeartbeatIntervalSeconds(): number | undefined {
|
|
408
|
-
return isIntelligenceRuntime(this.delegate)
|
|
409
|
-
? this.delegate.lockHeartbeatIntervalSeconds
|
|
410
|
-
: undefined;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
get mode(): RuntimeMode {
|
|
414
|
-
return this.delegate.mode;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
get licenseChecker() {
|
|
418
|
-
return this.delegate.licenseChecker;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
get debugEventBus() {
|
|
422
|
-
return this.delegate.debugEventBus;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
get debug(): ResolvedDebugConfig {
|
|
426
|
-
return this.delegate.debug;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
get debugLogger(): CopilotRuntimeLogger | undefined {
|
|
430
|
-
return this.delegate.debugLogger;
|
|
431
|
-
}
|
|
432
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Express-aware Node ↔ Fetch bridge.
|
|
3
|
-
*
|
|
4
|
-
* When Express body-parsing middleware (e.g. `express.json()`) runs before the
|
|
5
|
-
* CopilotKit router, the Node request stream is already consumed and `req.body`
|
|
6
|
-
* holds the parsed content. The generic `createCopilotNodeHandler` (which uses
|
|
7
|
-
* `@remix-run/node-fetch-server`) would hang because it tries to read from the
|
|
8
|
-
* exhausted stream.
|
|
9
|
-
*
|
|
10
|
-
* This module detects the pre-parsed case and re-serialises `req.body` into the
|
|
11
|
-
* Fetch `Request`, falling back to the generic `createCopilotNodeHandler` when the
|
|
12
|
-
* stream is still available.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
16
|
-
import { sendResponse } from "@remix-run/node-fetch-server";
|
|
17
|
-
import { createCopilotNodeHandler } from "./node-fetch-handler";
|
|
18
|
-
import type { CopilotRuntimeFetchHandler } from "../core/fetch-handler";
|
|
19
|
-
import { logger } from "@copilotkit/shared";
|
|
20
|
-
|
|
21
|
-
const METHODS_WITHOUT_BODY = new Set(["GET", "HEAD", "OPTIONS"]);
|
|
22
|
-
|
|
23
|
-
export type ExpressNodeHandler = (
|
|
24
|
-
req: IncomingMessage,
|
|
25
|
-
res: ServerResponse,
|
|
26
|
-
) => Promise<void>;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Creates a Node HTTP handler from a fetch handler, with Express body-parser
|
|
30
|
-
* compatibility. Use this instead of `createNodeFetchHandler` in Express adapters.
|
|
31
|
-
*
|
|
32
|
-
* When the body stream hasn't been consumed, delegates to the generic
|
|
33
|
-
* `createCopilotNodeHandler`. Only intercepts when Express middleware has
|
|
34
|
-
* pre-parsed the body.
|
|
35
|
-
*/
|
|
36
|
-
export function createExpressNodeHandler(
|
|
37
|
-
handler: CopilotRuntimeFetchHandler,
|
|
38
|
-
): ExpressNodeHandler {
|
|
39
|
-
const nodeHandler = createCopilotNodeHandler(handler);
|
|
40
|
-
|
|
41
|
-
return async (req: IncomingMessage, res: ServerResponse) => {
|
|
42
|
-
const method = (req.method ?? "GET").toUpperCase();
|
|
43
|
-
|
|
44
|
-
// Fast path: if no body parser consumed the stream, use the generic handler.
|
|
45
|
-
if (METHODS_WITHOUT_BODY.has(method) || !hasPreParsedBody(req)) {
|
|
46
|
-
return nodeHandler(req, res);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Slow path: body was consumed by Express middleware — rebuild the Request.
|
|
50
|
-
try {
|
|
51
|
-
const fetchReq = buildPreParsedRequest(req, res);
|
|
52
|
-
const fetchRes = await handler(fetchReq);
|
|
53
|
-
await sendResponse(res, fetchRes);
|
|
54
|
-
} catch (err: unknown) {
|
|
55
|
-
logger.error({ err }, "Error in Express fetch bridge (pre-parsed path)");
|
|
56
|
-
if (!res.headersSent) {
|
|
57
|
-
res.statusCode = 500;
|
|
58
|
-
res.end("Internal Server Error");
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Build a Fetch Request from a Node IncomingMessage whose body stream has
|
|
66
|
-
* already been consumed by an Express body parser.
|
|
67
|
-
*/
|
|
68
|
-
function buildPreParsedRequest(
|
|
69
|
-
req: IncomingMessage,
|
|
70
|
-
res: ServerResponse,
|
|
71
|
-
): Request {
|
|
72
|
-
const expressReq = req as IncomingMessage & { body?: unknown };
|
|
73
|
-
const method = (req.method ?? "GET").toUpperCase();
|
|
74
|
-
|
|
75
|
-
const protocol = (req as any).protocol || "http";
|
|
76
|
-
const host = req.headers.host ?? "localhost";
|
|
77
|
-
const url = `${protocol}://${host}${(req as any).originalUrl ?? req.url ?? ""}`;
|
|
78
|
-
|
|
79
|
-
const headers = new Headers();
|
|
80
|
-
for (const [key, value] of Object.entries(req.headers)) {
|
|
81
|
-
if (value === undefined) continue;
|
|
82
|
-
if (Array.isArray(value)) {
|
|
83
|
-
for (const v of value) headers.append(key, v);
|
|
84
|
-
} else {
|
|
85
|
-
headers.set(key, value);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Wire an AbortSignal so client disconnects propagate to the fetch handler
|
|
90
|
-
const controller = new AbortController();
|
|
91
|
-
res.on("close", () => {
|
|
92
|
-
if (!res.writableFinished) controller.abort();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const init: RequestInit & { duplex?: "half" } = {
|
|
96
|
-
method,
|
|
97
|
-
headers,
|
|
98
|
-
signal: controller.signal,
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const { body, contentType } = synthesizeBody(expressReq.body);
|
|
102
|
-
if (contentType) {
|
|
103
|
-
headers.set("content-type", contentType);
|
|
104
|
-
}
|
|
105
|
-
headers.delete("content-length");
|
|
106
|
-
if (body !== undefined) {
|
|
107
|
-
init.body = body;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return new Request(url, init);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function hasPreParsedBody(req: IncomingMessage & { body?: unknown }): boolean {
|
|
114
|
-
if (req.body === undefined || req.body === null) return false;
|
|
115
|
-
|
|
116
|
-
// Check if the stream has already been consumed.
|
|
117
|
-
const state = (req as any)._readableState;
|
|
118
|
-
return Boolean(
|
|
119
|
-
req.readableEnded || req.complete || state?.ended || state?.endEmitted,
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function synthesizeBody(body: unknown): {
|
|
124
|
-
body?: BodyInit;
|
|
125
|
-
contentType?: string;
|
|
126
|
-
} {
|
|
127
|
-
if (Buffer.isBuffer(body) || body instanceof Uint8Array) {
|
|
128
|
-
return { body };
|
|
129
|
-
}
|
|
130
|
-
if (typeof body === "string") {
|
|
131
|
-
return { body };
|
|
132
|
-
}
|
|
133
|
-
if (typeof body === "object" && body !== null) {
|
|
134
|
-
return { body: JSON.stringify(body), contentType: "application/json" };
|
|
135
|
-
}
|
|
136
|
-
return {};
|
|
137
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { Router } from "express";
|
|
2
|
-
import { createCopilotExpressHandler } from "./express";
|
|
3
|
-
import type { CopilotRuntimeLike } from "../core/runtime";
|
|
4
|
-
import type { CopilotRuntimeHooks } from "../core/hooks";
|
|
5
|
-
|
|
6
|
-
interface CopilotSingleRouteExpressParams {
|
|
7
|
-
runtime: CopilotRuntimeLike;
|
|
8
|
-
basePath: string;
|
|
9
|
-
/**
|
|
10
|
-
* Lifecycle hooks for request processing.
|
|
11
|
-
*/
|
|
12
|
-
hooks?: CopilotRuntimeHooks;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an Express router that serves the CopilotKit runtime as a single
|
|
17
|
-
* POST endpoint. Clients send a JSON envelope with `{ method, params, body }`
|
|
18
|
-
* to dispatch to the appropriate handler.
|
|
19
|
-
*
|
|
20
|
-
* This is a convenience wrapper around {@link createCopilotExpressHandler}
|
|
21
|
-
* with `mode: "single-route"` and `cors: true`.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* import express from "express";
|
|
26
|
-
* import { CopilotRuntime } from "@copilotkit/runtime/v2";
|
|
27
|
-
* import { createCopilotEndpointSingleRouteExpress } from "@copilotkit/runtime/v2/express";
|
|
28
|
-
*
|
|
29
|
-
* const runtime = new CopilotRuntime({
|
|
30
|
-
* agents: { default: new BuiltInAgent({ model: "openai/gpt-4o-mini" }) },
|
|
31
|
-
* });
|
|
32
|
-
*
|
|
33
|
-
* const app = express();
|
|
34
|
-
* app.use(createCopilotEndpointSingleRouteExpress({
|
|
35
|
-
* runtime,
|
|
36
|
-
* basePath: "/api/copilotkit",
|
|
37
|
-
* }));
|
|
38
|
-
* app.listen(4000);
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
/** @deprecated Use `createCopilotExpressHandler` with `mode: "single-route"` instead. */
|
|
42
|
-
export function createCopilotEndpointSingleRouteExpress({
|
|
43
|
-
runtime,
|
|
44
|
-
basePath,
|
|
45
|
-
hooks,
|
|
46
|
-
}: CopilotSingleRouteExpressParams): Router {
|
|
47
|
-
return createCopilotExpressHandler({
|
|
48
|
-
runtime,
|
|
49
|
-
basePath,
|
|
50
|
-
mode: "single-route",
|
|
51
|
-
cors: true,
|
|
52
|
-
hooks,
|
|
53
|
-
});
|
|
54
|
-
}
|