@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,176 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { handleDebugEvents } from "../handle-debug-events";
|
|
3
|
-
import { DebugEventBus } from "../../core/debug-event-bus";
|
|
4
|
-
import type { CopilotRuntimeLike } from "../../core/runtime";
|
|
5
|
-
import type { BaseEvent } from "@ag-ui/client";
|
|
6
|
-
|
|
7
|
-
/* ------------------------------------------------------------------------------------------------
|
|
8
|
-
* Helpers
|
|
9
|
-
* --------------------------------------------------------------------------------------------- */
|
|
10
|
-
|
|
11
|
-
function createMockRuntime(
|
|
12
|
-
overrides: { debugEventBus?: DebugEventBus } = {},
|
|
13
|
-
): Pick<CopilotRuntimeLike, "debugEventBus"> {
|
|
14
|
-
return {
|
|
15
|
-
debugEventBus: overrides.debugEventBus ?? new DebugEventBus(),
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function createMockRequest(options: { signal?: AbortSignal } = {}): Request {
|
|
20
|
-
return new Request("http://localhost/cpk-debug-events", {
|
|
21
|
-
method: "GET",
|
|
22
|
-
signal: options.signal,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function createTestEvent(): BaseEvent {
|
|
27
|
-
return { type: "custom" } as BaseEvent;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function readNextSSELine(
|
|
31
|
-
reader: ReadableStreamDefaultReader<Uint8Array>,
|
|
32
|
-
): Promise<string> {
|
|
33
|
-
const decoder = new TextDecoder();
|
|
34
|
-
let accumulated = "";
|
|
35
|
-
while (true) {
|
|
36
|
-
const { value, done } = await reader.read();
|
|
37
|
-
if (done) break;
|
|
38
|
-
accumulated += decoder.decode(value, { stream: true });
|
|
39
|
-
if (accumulated.includes("\n\n")) return accumulated;
|
|
40
|
-
}
|
|
41
|
-
return accumulated;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/* ------------------------------------------------------------------------------------------------
|
|
45
|
-
* Tests
|
|
46
|
-
* --------------------------------------------------------------------------------------------- */
|
|
47
|
-
|
|
48
|
-
describe("handleDebugEvents", () => {
|
|
49
|
-
let savedNodeEnv: string | undefined;
|
|
50
|
-
|
|
51
|
-
beforeEach(() => {
|
|
52
|
-
savedNodeEnv = process.env.NODE_ENV;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
afterEach(() => {
|
|
56
|
-
if (savedNodeEnv === undefined) {
|
|
57
|
-
delete process.env.NODE_ENV;
|
|
58
|
-
} else {
|
|
59
|
-
process.env.NODE_ENV = savedNodeEnv;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("returns 404 when NODE_ENV is production", async () => {
|
|
64
|
-
process.env.NODE_ENV = "production";
|
|
65
|
-
|
|
66
|
-
const runtime = createMockRuntime();
|
|
67
|
-
const request = createMockRequest();
|
|
68
|
-
|
|
69
|
-
const response = handleDebugEvents({
|
|
70
|
-
runtime: runtime as CopilotRuntimeLike,
|
|
71
|
-
request,
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
expect(response.status).toBe(404);
|
|
75
|
-
expect(await response.text()).toBe("Not Found");
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("returns 503 when debugEventBus is undefined", async () => {
|
|
79
|
-
process.env.NODE_ENV = "test";
|
|
80
|
-
|
|
81
|
-
const runtime = createMockRuntime({ debugEventBus: undefined });
|
|
82
|
-
// Remove the property so it's truly undefined
|
|
83
|
-
delete (runtime as Record<string, unknown>).debugEventBus;
|
|
84
|
-
|
|
85
|
-
const request = createMockRequest();
|
|
86
|
-
|
|
87
|
-
const response = handleDebugEvents({
|
|
88
|
-
runtime: runtime as CopilotRuntimeLike,
|
|
89
|
-
request,
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
expect(response.status).toBe(503);
|
|
93
|
-
expect(await response.text()).toBe("Debug event bus not available");
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("returns correct SSE response headers", () => {
|
|
97
|
-
process.env.NODE_ENV = "test";
|
|
98
|
-
|
|
99
|
-
const runtime = createMockRuntime();
|
|
100
|
-
const request = createMockRequest();
|
|
101
|
-
|
|
102
|
-
const response = handleDebugEvents({
|
|
103
|
-
runtime: runtime as CopilotRuntimeLike,
|
|
104
|
-
request,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
expect(response.status).toBe(200);
|
|
108
|
-
expect(response.headers.get("Content-Type")).toBe("text/event-stream");
|
|
109
|
-
expect(response.headers.get("Cache-Control")).toBe("no-cache");
|
|
110
|
-
expect(response.headers.get("Connection")).toBe("keep-alive");
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("streams events as SSE data lines when bus broadcasts", async () => {
|
|
114
|
-
process.env.NODE_ENV = "test";
|
|
115
|
-
|
|
116
|
-
const bus = new DebugEventBus();
|
|
117
|
-
const runtime = createMockRuntime({ debugEventBus: bus });
|
|
118
|
-
const request = createMockRequest();
|
|
119
|
-
|
|
120
|
-
const response = handleDebugEvents({
|
|
121
|
-
runtime: runtime as CopilotRuntimeLike,
|
|
122
|
-
request,
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
const reader = response.body!.getReader();
|
|
126
|
-
|
|
127
|
-
// Read and discard the initial ": connected" SSE comment
|
|
128
|
-
const comment = await readNextSSELine(reader);
|
|
129
|
-
expect(comment).toMatch(/^: connected/);
|
|
130
|
-
|
|
131
|
-
// Broadcast an event through the bus
|
|
132
|
-
bus.broadcast(createTestEvent(), {
|
|
133
|
-
agentId: "agent-1",
|
|
134
|
-
threadId: "thread-1",
|
|
135
|
-
runId: "run-1",
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
const line = await readNextSSELine(reader);
|
|
139
|
-
|
|
140
|
-
// The line should be "data: {json}\n\n"
|
|
141
|
-
expect(line).toMatch(/^data: \{.*\}\n\n$/);
|
|
142
|
-
|
|
143
|
-
const parsed = JSON.parse(line.replace("data: ", "").trim());
|
|
144
|
-
expect(parsed.agentId).toBe("agent-1");
|
|
145
|
-
expect(parsed.threadId).toBe("thread-1");
|
|
146
|
-
expect(parsed.runId).toBe("run-1");
|
|
147
|
-
expect(parsed.event).toEqual(createTestEvent());
|
|
148
|
-
expect(typeof parsed.timestamp).toBe("number");
|
|
149
|
-
|
|
150
|
-
reader.releaseLock();
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("unsubscribes from bus when request is aborted", async () => {
|
|
154
|
-
process.env.NODE_ENV = "test";
|
|
155
|
-
|
|
156
|
-
const bus = new DebugEventBus();
|
|
157
|
-
const runtime = createMockRuntime({ debugEventBus: bus });
|
|
158
|
-
|
|
159
|
-
const abortController = new AbortController();
|
|
160
|
-
const request = createMockRequest({ signal: abortController.signal });
|
|
161
|
-
|
|
162
|
-
handleDebugEvents({
|
|
163
|
-
runtime: runtime as CopilotRuntimeLike,
|
|
164
|
-
request,
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// Before abort, the bus should have one listener
|
|
168
|
-
expect(bus.listenerCount).toBe(1);
|
|
169
|
-
|
|
170
|
-
// Abort the request
|
|
171
|
-
abortController.abort();
|
|
172
|
-
|
|
173
|
-
// After abort, the listener should be cleaned up
|
|
174
|
-
expect(bus.listenerCount).toBe(0);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import type { AgentCapabilities } from "@ag-ui/core";
|
|
2
|
-
import type { CopilotRuntimeLike } from "../core/runtime";
|
|
3
|
-
import { isIntelligenceRuntime, resolveAgents } from "../core/runtime";
|
|
4
|
-
import type { AgentDescription, RuntimeInfo } from "@copilotkit/shared";
|
|
5
|
-
import { type RuntimeLicenseStatus } from "@copilotkit/shared";
|
|
6
|
-
import { VERSION } from "../core/runtime";
|
|
7
|
-
import { isTelemetryDisabled } from "../telemetry/telemetry-client";
|
|
8
|
-
|
|
9
|
-
function resolveLicenseStatus(
|
|
10
|
-
runtime: CopilotRuntimeLike,
|
|
11
|
-
): RuntimeLicenseStatus {
|
|
12
|
-
if (!runtime.licenseChecker) return "none";
|
|
13
|
-
const status = runtime.licenseChecker.getStatus();
|
|
14
|
-
if (status.warningSeverity === "none") return "valid";
|
|
15
|
-
if (status.error === "expired") return "expired";
|
|
16
|
-
if (status.warningSeverity === "warning") return "expiring";
|
|
17
|
-
if (status.error) return "invalid";
|
|
18
|
-
if (status.warningSeverity === "info") return "none";
|
|
19
|
-
return "unknown";
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface HandleGetRuntimeInfoParameters {
|
|
23
|
-
runtime: CopilotRuntimeLike;
|
|
24
|
-
request: Request;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export async function handleGetRuntimeInfo({
|
|
28
|
-
runtime,
|
|
29
|
-
request,
|
|
30
|
-
}: HandleGetRuntimeInfoParameters) {
|
|
31
|
-
try {
|
|
32
|
-
const agents = await resolveAgents(runtime.agents, request);
|
|
33
|
-
|
|
34
|
-
const agentEntries = await Promise.all(
|
|
35
|
-
Object.entries(agents).map(async ([name, agent]) => {
|
|
36
|
-
let capabilities: AgentCapabilities | undefined;
|
|
37
|
-
try {
|
|
38
|
-
capabilities = agent.getCapabilities
|
|
39
|
-
? await agent.getCapabilities()
|
|
40
|
-
: undefined;
|
|
41
|
-
} catch (error) {
|
|
42
|
-
// Per-agent isolation: a single agent failing to report capabilities
|
|
43
|
-
// must not take down the entire /info endpoint.
|
|
44
|
-
console.warn(
|
|
45
|
-
`Failed to fetch capabilities for agent "${name}":`,
|
|
46
|
-
error instanceof Error ? error.message : error,
|
|
47
|
-
);
|
|
48
|
-
capabilities = undefined;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const description: AgentDescription = {
|
|
52
|
-
name,
|
|
53
|
-
description: agent.description,
|
|
54
|
-
className: agent.constructor.name,
|
|
55
|
-
...(capabilities ? { capabilities } : {}),
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
return [name, description] as const;
|
|
59
|
-
}),
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
const agentsDict: Record<string, AgentDescription> =
|
|
63
|
-
Object.fromEntries(agentEntries);
|
|
64
|
-
|
|
65
|
-
const runtimeInfo: RuntimeInfo = {
|
|
66
|
-
version: VERSION,
|
|
67
|
-
agents: agentsDict,
|
|
68
|
-
audioFileTranscriptionEnabled: !!runtime.transcriptionService,
|
|
69
|
-
mode: runtime.mode,
|
|
70
|
-
...(isIntelligenceRuntime(runtime)
|
|
71
|
-
? {
|
|
72
|
-
intelligence: {
|
|
73
|
-
wsUrl: runtime.intelligence.ɵgetClientWsUrl(),
|
|
74
|
-
},
|
|
75
|
-
}
|
|
76
|
-
: {}),
|
|
77
|
-
a2uiEnabled: !!runtime.a2ui,
|
|
78
|
-
openGenerativeUIEnabled: !!runtime.openGenerativeUI,
|
|
79
|
-
...(isIntelligenceRuntime(runtime)
|
|
80
|
-
? { licenseStatus: resolveLicenseStatus(runtime) }
|
|
81
|
-
: {}),
|
|
82
|
-
telemetryDisabled: isTelemetryDisabled(),
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
return new Response(JSON.stringify(runtimeInfo), {
|
|
86
|
-
status: 200,
|
|
87
|
-
headers: { "Content-Type": "application/json" },
|
|
88
|
-
});
|
|
89
|
-
} catch (error) {
|
|
90
|
-
return new Response(
|
|
91
|
-
JSON.stringify({
|
|
92
|
-
error: "Failed to retrieve runtime information",
|
|
93
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
94
|
-
}),
|
|
95
|
-
{
|
|
96
|
-
status: 500,
|
|
97
|
-
headers: { "Content-Type": "application/json" },
|
|
98
|
-
},
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { handleIntelligenceConnect } from "./intelligence/connect";
|
|
2
|
-
import { handleSseConnect } from "./sse/connect";
|
|
3
|
-
import { isIntelligenceRuntime } from "../core/runtime";
|
|
4
|
-
import { telemetry } from "../telemetry";
|
|
5
|
-
import {
|
|
6
|
-
parseConnectRequest,
|
|
7
|
-
RunAgentParameters as ConnectAgentParameters,
|
|
8
|
-
cloneAgentForRequest,
|
|
9
|
-
} from "./shared/agent-utils";
|
|
10
|
-
|
|
11
|
-
export async function handleConnectAgent({
|
|
12
|
-
runtime,
|
|
13
|
-
request,
|
|
14
|
-
agentId,
|
|
15
|
-
}: ConnectAgentParameters) {
|
|
16
|
-
telemetry.capture("oss.runtime.copilot_request_created", {
|
|
17
|
-
"cloud.guardrails.enabled": false,
|
|
18
|
-
requestType: "connect",
|
|
19
|
-
"cloud.api_key_provided": !!request.headers.get(
|
|
20
|
-
"x-copilotcloud-public-api-key",
|
|
21
|
-
),
|
|
22
|
-
...(request.headers.get("x-copilotcloud-public-api-key")
|
|
23
|
-
? {
|
|
24
|
-
"cloud.public_api_key": request.headers.get(
|
|
25
|
-
"x-copilotcloud-public-api-key",
|
|
26
|
-
)!,
|
|
27
|
-
}
|
|
28
|
-
: {}),
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
const agent = await cloneAgentForRequest(runtime, agentId, request);
|
|
33
|
-
if (agent instanceof Response) {
|
|
34
|
-
return agent;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const connectRequest = await parseConnectRequest(request);
|
|
38
|
-
if (connectRequest instanceof Response) {
|
|
39
|
-
return connectRequest;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (isIntelligenceRuntime(runtime)) {
|
|
43
|
-
return handleIntelligenceConnect({
|
|
44
|
-
runtime,
|
|
45
|
-
request,
|
|
46
|
-
agentId,
|
|
47
|
-
threadId: connectRequest.input.threadId,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return handleSseConnect({
|
|
52
|
-
runtime,
|
|
53
|
-
request,
|
|
54
|
-
agentId,
|
|
55
|
-
threadId: connectRequest.input.threadId,
|
|
56
|
-
});
|
|
57
|
-
} catch (error) {
|
|
58
|
-
console.error("Error running agent:", error);
|
|
59
|
-
console.error(
|
|
60
|
-
"Error stack:",
|
|
61
|
-
error instanceof Error ? error.stack : "No stack trace",
|
|
62
|
-
);
|
|
63
|
-
console.error("Error details:", {
|
|
64
|
-
name: error instanceof Error ? error.name : "Unknown",
|
|
65
|
-
message: error instanceof Error ? error.message : String(error),
|
|
66
|
-
cause: error instanceof Error ? error.cause : undefined,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
return new Response(
|
|
70
|
-
JSON.stringify({
|
|
71
|
-
error: "Failed to run agent",
|
|
72
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
73
|
-
}),
|
|
74
|
-
{
|
|
75
|
-
status: 500,
|
|
76
|
-
headers: { "Content-Type": "application/json" },
|
|
77
|
-
},
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { CopilotRuntimeLike } from "../core/runtime";
|
|
2
|
-
import { DebugEventEnvelope } from "@copilotkit/shared";
|
|
3
|
-
|
|
4
|
-
interface HandleDebugEventsParams {
|
|
5
|
-
runtime: CopilotRuntimeLike;
|
|
6
|
-
request: Request;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function handleDebugEvents({
|
|
10
|
-
runtime,
|
|
11
|
-
request,
|
|
12
|
-
}: HandleDebugEventsParams): Response {
|
|
13
|
-
if (process.env.NODE_ENV === "production") {
|
|
14
|
-
return new Response("Not Found", { status: 404 });
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (!runtime.debugEventBus) {
|
|
18
|
-
return new Response("Debug event bus not available", { status: 503 });
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const bus = runtime.debugEventBus;
|
|
22
|
-
const encoder = new TextEncoder();
|
|
23
|
-
const stream = new TransformStream();
|
|
24
|
-
const writer = stream.writable.getWriter();
|
|
25
|
-
|
|
26
|
-
// Send an SSE comment immediately to flush response headers to the client.
|
|
27
|
-
// Without this, some frameworks buffer the response until actual data is written,
|
|
28
|
-
// leaving the client stuck in "connecting" state.
|
|
29
|
-
writer.write(encoder.encode(": connected\n\n")).catch(() => {});
|
|
30
|
-
|
|
31
|
-
const unsubscribe = bus.subscribe((envelope: DebugEventEnvelope) => {
|
|
32
|
-
if (request.signal.aborted) return;
|
|
33
|
-
const line = `data: ${JSON.stringify(envelope)}\n\n`;
|
|
34
|
-
writer.write(encoder.encode(line)).catch(() => {
|
|
35
|
-
// Client disconnected, will be cleaned up by abort handler.
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
request.signal.addEventListener("abort", () => {
|
|
40
|
-
unsubscribe();
|
|
41
|
-
writer.close().catch(() => {});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return new Response(stream.readable, {
|
|
45
|
-
status: 200,
|
|
46
|
-
headers: {
|
|
47
|
-
"Content-Type": "text/event-stream",
|
|
48
|
-
"Cache-Control": "no-cache",
|
|
49
|
-
Connection: "keep-alive",
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { isIntelligenceRuntime } from "../core/runtime";
|
|
2
|
-
import { telemetry } from "../telemetry";
|
|
3
|
-
import {
|
|
4
|
-
cloneAgentForRequest,
|
|
5
|
-
configureAgentForRequest,
|
|
6
|
-
parseRunRequest,
|
|
7
|
-
RunAgentParameters,
|
|
8
|
-
} from "./shared/agent-utils";
|
|
9
|
-
import { handleIntelligenceRun } from "./intelligence/run";
|
|
10
|
-
import { handleSseRun } from "./sse/run";
|
|
11
|
-
|
|
12
|
-
export async function handleRunAgent({
|
|
13
|
-
runtime,
|
|
14
|
-
request,
|
|
15
|
-
agentId,
|
|
16
|
-
}: RunAgentParameters) {
|
|
17
|
-
telemetry.capture("oss.runtime.copilot_request_created", {
|
|
18
|
-
"cloud.guardrails.enabled": false,
|
|
19
|
-
requestType: "run",
|
|
20
|
-
"cloud.api_key_provided": !!request.headers.get(
|
|
21
|
-
"x-copilotcloud-public-api-key",
|
|
22
|
-
),
|
|
23
|
-
...(request.headers.get("x-copilotcloud-public-api-key")
|
|
24
|
-
? {
|
|
25
|
-
"cloud.public_api_key": request.headers.get(
|
|
26
|
-
"x-copilotcloud-public-api-key",
|
|
27
|
-
)!,
|
|
28
|
-
}
|
|
29
|
-
: {}),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
const agent = await cloneAgentForRequest(runtime, agentId, request);
|
|
34
|
-
if (agent instanceof Response) {
|
|
35
|
-
return agent;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Ensure the clone carries the registry key so InMemoryAgentRunner can
|
|
39
|
-
// tag historic runs with the correct agentId for filtering.
|
|
40
|
-
agent.agentId = agentId;
|
|
41
|
-
|
|
42
|
-
configureAgentForRequest({ runtime, request, agentId, agent });
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
runtime.licenseChecker &&
|
|
46
|
-
!runtime.licenseChecker.checkFeature("agents")
|
|
47
|
-
) {
|
|
48
|
-
console.warn(
|
|
49
|
-
'[CopilotKit Runtime] Warning: "agents" feature is not licensed. Visit copilotkit.ai/pricing',
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const input = await parseRunRequest(request);
|
|
54
|
-
if (input instanceof Response) {
|
|
55
|
-
return input;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
agent.setMessages(input.messages);
|
|
59
|
-
agent.setState(input.state);
|
|
60
|
-
agent.threadId = input.threadId;
|
|
61
|
-
|
|
62
|
-
if (runtime.debug?.lifecycle && runtime.debugLogger) {
|
|
63
|
-
runtime.debugLogger.debug(
|
|
64
|
-
{ agentName: agentId, threadId: input.threadId },
|
|
65
|
-
"Agent run started",
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (isIntelligenceRuntime(runtime)) {
|
|
70
|
-
return handleIntelligenceRun({
|
|
71
|
-
runtime,
|
|
72
|
-
request,
|
|
73
|
-
agentId,
|
|
74
|
-
agent,
|
|
75
|
-
input,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return handleSseRun({
|
|
80
|
-
runtime,
|
|
81
|
-
request,
|
|
82
|
-
agent,
|
|
83
|
-
input,
|
|
84
|
-
agentId,
|
|
85
|
-
debug: runtime.debug,
|
|
86
|
-
logger: runtime.debugLogger,
|
|
87
|
-
});
|
|
88
|
-
} catch (error) {
|
|
89
|
-
console.error("Error running agent:", error);
|
|
90
|
-
console.error(
|
|
91
|
-
"Error stack:",
|
|
92
|
-
error instanceof Error ? error.stack : "No stack trace",
|
|
93
|
-
);
|
|
94
|
-
console.error("Error details:", {
|
|
95
|
-
name: error instanceof Error ? error.name : "Unknown",
|
|
96
|
-
message: error instanceof Error ? error.message : String(error),
|
|
97
|
-
cause: error instanceof Error ? error.cause : undefined,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
return new Response(
|
|
101
|
-
JSON.stringify({
|
|
102
|
-
error: "Failed to run agent",
|
|
103
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
104
|
-
}),
|
|
105
|
-
{
|
|
106
|
-
status: 500,
|
|
107
|
-
headers: { "Content-Type": "application/json" },
|
|
108
|
-
},
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { CopilotRuntimeLike } from "../core/runtime";
|
|
2
|
-
import { resolveAgents } from "../core/runtime";
|
|
3
|
-
import { EventType } from "@ag-ui/client";
|
|
4
|
-
|
|
5
|
-
interface StopAgentParameters {
|
|
6
|
-
request: Request;
|
|
7
|
-
runtime: CopilotRuntimeLike;
|
|
8
|
-
agentId: string;
|
|
9
|
-
threadId: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export async function handleStopAgent({
|
|
13
|
-
runtime,
|
|
14
|
-
request,
|
|
15
|
-
agentId,
|
|
16
|
-
threadId,
|
|
17
|
-
}: StopAgentParameters) {
|
|
18
|
-
try {
|
|
19
|
-
const agents = await resolveAgents(runtime.agents, request);
|
|
20
|
-
|
|
21
|
-
if (!agents[agentId]) {
|
|
22
|
-
return new Response(
|
|
23
|
-
JSON.stringify({
|
|
24
|
-
error: "Agent not found",
|
|
25
|
-
message: `Agent '${agentId}' does not exist`,
|
|
26
|
-
}),
|
|
27
|
-
{
|
|
28
|
-
status: 404,
|
|
29
|
-
headers: { "Content-Type": "application/json" },
|
|
30
|
-
},
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const stopped = await runtime.runner.stop({ threadId });
|
|
35
|
-
|
|
36
|
-
if (!stopped) {
|
|
37
|
-
return new Response(
|
|
38
|
-
JSON.stringify({
|
|
39
|
-
stopped: false,
|
|
40
|
-
message: `No active run for thread '${threadId}'.`,
|
|
41
|
-
}),
|
|
42
|
-
{
|
|
43
|
-
status: 200,
|
|
44
|
-
headers: { "Content-Type": "application/json" },
|
|
45
|
-
},
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return new Response(
|
|
50
|
-
JSON.stringify({
|
|
51
|
-
stopped: true,
|
|
52
|
-
interrupt: {
|
|
53
|
-
type: EventType.RUN_ERROR,
|
|
54
|
-
message: "Run stopped by user",
|
|
55
|
-
code: "STOPPED",
|
|
56
|
-
},
|
|
57
|
-
}),
|
|
58
|
-
{
|
|
59
|
-
status: 200,
|
|
60
|
-
headers: { "Content-Type": "application/json" },
|
|
61
|
-
},
|
|
62
|
-
);
|
|
63
|
-
} catch (error) {
|
|
64
|
-
console.error("Error stopping agent run:", error);
|
|
65
|
-
|
|
66
|
-
return new Response(
|
|
67
|
-
JSON.stringify({
|
|
68
|
-
error: "Failed to stop agent",
|
|
69
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
70
|
-
}),
|
|
71
|
-
{
|
|
72
|
-
status: 500,
|
|
73
|
-
headers: { "Content-Type": "application/json" },
|
|
74
|
-
},
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
handleArchiveThread,
|
|
3
|
-
handleClearThreads,
|
|
4
|
-
handleDeleteThread,
|
|
5
|
-
handleGetThreadEvents,
|
|
6
|
-
handleGetThreadMessages,
|
|
7
|
-
handleGetThreadState,
|
|
8
|
-
handleListThreads,
|
|
9
|
-
handleSubscribeToThreads,
|
|
10
|
-
handleUpdateThread,
|
|
11
|
-
} from "./intelligence/threads";
|