@copilotkit/runtime 1.57.3 → 1.58.0-canary.thread-id-propagation
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/observability.d.cts +1 -1
- package/dist/lib/observability.d.cts.map +1 -1
- package/dist/lib/observability.d.mts +1 -1
- package/dist/lib/observability.d.mts.map +1 -1
- 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 +5 -8
- package/dist/package.mjs +5 -8
- 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 +9 -19
- 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,313 +0,0 @@
|
|
|
1
|
-
import { Action, Parameter } from "@copilotkit/shared";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents a tool provided by an MCP server.
|
|
5
|
-
*/
|
|
6
|
-
export interface MCPTool {
|
|
7
|
-
description?: string;
|
|
8
|
-
/** Schema defining parameters, mirroring the MCP structure. */
|
|
9
|
-
schema?: {
|
|
10
|
-
parameters?: {
|
|
11
|
-
properties?: Record<string, any>;
|
|
12
|
-
required?: string[];
|
|
13
|
-
jsonSchema?: Record<string, any>;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
/** The function to call to execute the tool on the MCP server. */
|
|
17
|
-
execute(params: any): Promise<any>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Defines the contract for *any* MCP client implementation the user might provide.
|
|
22
|
-
*/
|
|
23
|
-
export interface MCPClient {
|
|
24
|
-
/** A method that returns a map of tool names to MCPTool objects available from the connected MCP server. */
|
|
25
|
-
tools(): Promise<Record<string, MCPTool>>;
|
|
26
|
-
/** An optional method for cleanup if the underlying client requires explicit disconnection. */
|
|
27
|
-
close?(): Promise<void>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Configuration for connecting to an MCP endpoint.
|
|
32
|
-
*/
|
|
33
|
-
export interface MCPEndpointConfig {
|
|
34
|
-
endpoint: string;
|
|
35
|
-
apiKey?: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Extracts CopilotKit-compatible parameters from an MCP tool schema.
|
|
40
|
-
* @param toolOrSchema The schema object from an MCPTool or the full MCPTool object.
|
|
41
|
-
* @returns An array of Parameter objects.
|
|
42
|
-
*/
|
|
43
|
-
export function extractParametersFromSchema(
|
|
44
|
-
toolOrSchema?: MCPTool | MCPTool["schema"],
|
|
45
|
-
): Parameter[] {
|
|
46
|
-
const parameters: Parameter[] = [];
|
|
47
|
-
|
|
48
|
-
// Handle either full tool object or just schema
|
|
49
|
-
const schema =
|
|
50
|
-
"schema" in (toolOrSchema || {})
|
|
51
|
-
? (toolOrSchema as MCPTool).schema
|
|
52
|
-
: (toolOrSchema as MCPTool["schema"]);
|
|
53
|
-
|
|
54
|
-
const toolParameters = schema?.parameters?.jsonSchema || schema?.parameters;
|
|
55
|
-
const properties = toolParameters?.properties;
|
|
56
|
-
const requiredParams = new Set(toolParameters?.required || []);
|
|
57
|
-
|
|
58
|
-
if (!properties) {
|
|
59
|
-
return parameters;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
for (const paramName in properties) {
|
|
63
|
-
if (Object.prototype.hasOwnProperty.call(properties, paramName)) {
|
|
64
|
-
const paramDef = properties[paramName];
|
|
65
|
-
|
|
66
|
-
// Enhanced type extraction with support for complex types
|
|
67
|
-
let type = paramDef.type || "string";
|
|
68
|
-
let description = paramDef.description || "";
|
|
69
|
-
|
|
70
|
-
// Handle arrays with items
|
|
71
|
-
if (type === "array" && paramDef.items) {
|
|
72
|
-
const itemType = paramDef.items.type || "object";
|
|
73
|
-
if (itemType === "object" && paramDef.items.properties) {
|
|
74
|
-
// For arrays of objects, describe the structure
|
|
75
|
-
const itemProperties = Object.keys(paramDef.items.properties).join(
|
|
76
|
-
", ",
|
|
77
|
-
);
|
|
78
|
-
description =
|
|
79
|
-
description +
|
|
80
|
-
(description ? " " : "") +
|
|
81
|
-
`Array of objects with properties: ${itemProperties}`;
|
|
82
|
-
} else {
|
|
83
|
-
// For arrays of primitives
|
|
84
|
-
type = `array<${itemType}>`;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Handle enums — preserve as structured data for Zod conversion
|
|
89
|
-
let enumValues: string[] | undefined;
|
|
90
|
-
if (paramDef.enum && Array.isArray(paramDef.enum)) {
|
|
91
|
-
enumValues = paramDef.enum.map(String);
|
|
92
|
-
const enumDisplay = enumValues.join(" | ");
|
|
93
|
-
description =
|
|
94
|
-
description +
|
|
95
|
-
(description ? " " : "") +
|
|
96
|
-
`Allowed values: ${enumDisplay}`;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Handle objects with properties — recurse to preserve nested structure
|
|
100
|
-
let attributes: Parameter[] | undefined;
|
|
101
|
-
if (type === "object" && paramDef.properties) {
|
|
102
|
-
const objectProperties = Object.keys(paramDef.properties).join(", ");
|
|
103
|
-
description =
|
|
104
|
-
description +
|
|
105
|
-
(description ? " " : "") +
|
|
106
|
-
`Object with properties: ${objectProperties}`;
|
|
107
|
-
// Recursively extract nested parameters
|
|
108
|
-
attributes = extractParametersFromSchema({
|
|
109
|
-
parameters: {
|
|
110
|
-
properties: paramDef.properties,
|
|
111
|
-
required: paramDef.required || [],
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Handle object arrays — recurse into item schema
|
|
117
|
-
if (type === "array" && paramDef.items?.type === "object" && paramDef.items?.properties) {
|
|
118
|
-
attributes = extractParametersFromSchema({
|
|
119
|
-
parameters: {
|
|
120
|
-
properties: paramDef.items.properties,
|
|
121
|
-
required: paramDef.items.required || [],
|
|
122
|
-
},
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const param: any = {
|
|
127
|
-
name: paramName,
|
|
128
|
-
type: type,
|
|
129
|
-
description: description,
|
|
130
|
-
required: requiredParams.has(paramName),
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
// Preserve enum values for string parameters
|
|
134
|
-
if (type === "string" && enumValues) {
|
|
135
|
-
param.enum = enumValues;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Preserve nested attributes for object and object[] types
|
|
139
|
-
if (attributes && attributes.length > 0) {
|
|
140
|
-
param.attributes = attributes;
|
|
141
|
-
if (type === "array") {
|
|
142
|
-
param.type = "object[]";
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
parameters.push(param);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return parameters;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Converts a map of MCPTools into an array of CopilotKit Actions.
|
|
155
|
-
* @param mcpTools A record mapping tool names to MCPTool objects.
|
|
156
|
-
* @param mcpEndpoint The endpoint URL from which these tools were fetched.
|
|
157
|
-
* @returns An array of Action<any> objects.
|
|
158
|
-
*/
|
|
159
|
-
export function convertMCPToolsToActions(
|
|
160
|
-
mcpTools: Record<string, MCPTool>,
|
|
161
|
-
mcpEndpoint: string,
|
|
162
|
-
): Action<any>[] {
|
|
163
|
-
const actions: Action<any>[] = [];
|
|
164
|
-
|
|
165
|
-
for (const [toolName, tool] of Object.entries(mcpTools)) {
|
|
166
|
-
const parameters = extractParametersFromSchema(tool);
|
|
167
|
-
|
|
168
|
-
const handler = async (params: any): Promise<any> => {
|
|
169
|
-
try {
|
|
170
|
-
const result = await tool.execute(params);
|
|
171
|
-
// Ensure the result is a string or stringify it, as required by many LLMs.
|
|
172
|
-
// This might need adjustment depending on how different LLMs handle tool results.
|
|
173
|
-
return typeof result === "string" ? result : JSON.stringify(result);
|
|
174
|
-
} catch (error) {
|
|
175
|
-
console.error(
|
|
176
|
-
`Error executing MCP tool '${toolName}' from endpoint ${mcpEndpoint}:`,
|
|
177
|
-
error,
|
|
178
|
-
);
|
|
179
|
-
// Re-throw or format the error for the LLM
|
|
180
|
-
throw new Error(
|
|
181
|
-
`Execution failed for MCP tool '${toolName}': ${
|
|
182
|
-
error instanceof Error ? error.message : String(error)
|
|
183
|
-
}`, { cause: error },
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
actions.push({
|
|
189
|
-
name: toolName,
|
|
190
|
-
description:
|
|
191
|
-
tool.description || `MCP tool: ${toolName} (from ${mcpEndpoint})`,
|
|
192
|
-
parameters: parameters,
|
|
193
|
-
handler: handler,
|
|
194
|
-
// Add metadata for easier identification/debugging
|
|
195
|
-
_isMCPTool: true,
|
|
196
|
-
_mcpEndpoint: mcpEndpoint,
|
|
197
|
-
} as Action<any> & { _isMCPTool: boolean; _mcpEndpoint: string }); // Type assertion for metadata
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return actions;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Generate better instructions for using MCP tools
|
|
205
|
-
* This is used to enhance the system prompt with tool documentation
|
|
206
|
-
*/
|
|
207
|
-
export function generateMcpToolInstructions(
|
|
208
|
-
toolsMap: Record<string, MCPTool>,
|
|
209
|
-
): string {
|
|
210
|
-
if (!toolsMap || Object.keys(toolsMap).length === 0) {
|
|
211
|
-
return "";
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const toolEntries = Object.entries(toolsMap);
|
|
215
|
-
|
|
216
|
-
// Generate documentation for each tool
|
|
217
|
-
const toolsDoc = toolEntries
|
|
218
|
-
.map(([name, tool]) => {
|
|
219
|
-
// Extract schema information if available
|
|
220
|
-
let paramsDoc = " No parameters required";
|
|
221
|
-
|
|
222
|
-
try {
|
|
223
|
-
if (tool.schema && typeof tool.schema === "object") {
|
|
224
|
-
const schema = tool.schema as any;
|
|
225
|
-
|
|
226
|
-
// Extract parameters from JSON Schema - check both schema.parameters.properties and schema.properties
|
|
227
|
-
const toolParameters =
|
|
228
|
-
schema.parameters?.jsonSchema || schema.parameters;
|
|
229
|
-
const properties = toolParameters?.properties || schema.properties;
|
|
230
|
-
const requiredParams =
|
|
231
|
-
toolParameters?.required || schema.required || [];
|
|
232
|
-
|
|
233
|
-
if (properties) {
|
|
234
|
-
// Build parameter documentation from properties with enhanced type information
|
|
235
|
-
const paramsList = Object.entries(properties).map(
|
|
236
|
-
([paramName, propSchema]) => {
|
|
237
|
-
const propDetails = propSchema as any;
|
|
238
|
-
const requiredMark = requiredParams.includes(paramName)
|
|
239
|
-
? "*"
|
|
240
|
-
: "";
|
|
241
|
-
let typeInfo = propDetails.type || "any";
|
|
242
|
-
let description = propDetails.description
|
|
243
|
-
? ` - ${propDetails.description}`
|
|
244
|
-
: "";
|
|
245
|
-
|
|
246
|
-
// Enhanced type display for complex schemas
|
|
247
|
-
if (typeInfo === "array" && propDetails.items) {
|
|
248
|
-
const itemType = propDetails.items.type || "object";
|
|
249
|
-
if (itemType === "object" && propDetails.items.properties) {
|
|
250
|
-
const itemProps = Object.keys(
|
|
251
|
-
propDetails.items.properties,
|
|
252
|
-
).join(", ");
|
|
253
|
-
typeInfo = `array<object>`;
|
|
254
|
-
description =
|
|
255
|
-
description +
|
|
256
|
-
(description ? " " : " - ") +
|
|
257
|
-
`Array of objects with properties: ${itemProps}`;
|
|
258
|
-
} else {
|
|
259
|
-
typeInfo = `array<${itemType}>`;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// Handle enums
|
|
264
|
-
if (propDetails.enum && Array.isArray(propDetails.enum)) {
|
|
265
|
-
const enumValues = propDetails.enum.join(" | ");
|
|
266
|
-
description =
|
|
267
|
-
description +
|
|
268
|
-
(description ? " " : " - ") +
|
|
269
|
-
`Allowed values: ${enumValues}`;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// Handle objects
|
|
273
|
-
if (typeInfo === "object" && propDetails.properties) {
|
|
274
|
-
const objectProps = Object.keys(propDetails.properties).join(
|
|
275
|
-
", ",
|
|
276
|
-
);
|
|
277
|
-
description =
|
|
278
|
-
description +
|
|
279
|
-
(description ? " " : " - ") +
|
|
280
|
-
`Object with properties: ${objectProps}`;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
return ` - ${paramName}${requiredMark} (${typeInfo})${description}`;
|
|
284
|
-
},
|
|
285
|
-
);
|
|
286
|
-
|
|
287
|
-
if (paramsList.length > 0) {
|
|
288
|
-
paramsDoc = paramsList.join("\n");
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
} catch (e) {
|
|
293
|
-
console.error(`Error parsing schema for tool ${name}:`, e);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return `- ${name}: ${tool.description || ""}
|
|
297
|
-
${paramsDoc}`;
|
|
298
|
-
})
|
|
299
|
-
.join("\n\n");
|
|
300
|
-
|
|
301
|
-
return `You have access to the following external tools provided by Model Context Protocol (MCP) servers:
|
|
302
|
-
|
|
303
|
-
${toolsDoc}
|
|
304
|
-
|
|
305
|
-
When using these tools:
|
|
306
|
-
1. Only provide valid parameters according to their type requirements
|
|
307
|
-
2. Required parameters are marked with *
|
|
308
|
-
3. For array parameters, provide data in the correct array format
|
|
309
|
-
4. For object parameters, include all required nested properties
|
|
310
|
-
5. For enum parameters, use only the allowed values listed
|
|
311
|
-
6. Format API calls correctly with the expected parameter structure
|
|
312
|
-
7. Always check tool responses to determine your next action`;
|
|
313
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { Logger } from "pino";
|
|
2
|
-
|
|
3
|
-
// Retry configuration for network requests
|
|
4
|
-
export const RETRY_CONFIG = {
|
|
5
|
-
maxRetries: 3,
|
|
6
|
-
baseDelayMs: 1000,
|
|
7
|
-
maxDelayMs: 5000,
|
|
8
|
-
// HTTP status codes that should be retried
|
|
9
|
-
retryableStatusCodes: [502, 503, 504, 408, 429],
|
|
10
|
-
// Maximum Retry-After value (in seconds) we're willing to honor
|
|
11
|
-
maxRetryAfterSeconds: 60,
|
|
12
|
-
// Network error patterns that should be retried
|
|
13
|
-
retryableErrorMessages: [
|
|
14
|
-
"fetch failed",
|
|
15
|
-
"network error",
|
|
16
|
-
"connection timeout",
|
|
17
|
-
"ECONNREFUSED",
|
|
18
|
-
"ETIMEDOUT",
|
|
19
|
-
"ENOTFOUND",
|
|
20
|
-
"ECONNRESET",
|
|
21
|
-
],
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// Helper function to check if an error/response is retryable
|
|
25
|
-
export function isRetryableError(error: any, response?: Response): boolean {
|
|
26
|
-
// Check HTTP response status
|
|
27
|
-
if (response && RETRY_CONFIG.retryableStatusCodes.includes(response.status)) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Check error codes (for connection errors like ECONNREFUSED)
|
|
32
|
-
const errorCode = error?.cause?.code || error?.code;
|
|
33
|
-
if (errorCode && RETRY_CONFIG.retryableErrorMessages.includes(errorCode)) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Check error messages
|
|
38
|
-
const errorMessage = error?.message?.toLowerCase() || "";
|
|
39
|
-
return RETRY_CONFIG.retryableErrorMessages.some((msg) =>
|
|
40
|
-
errorMessage.includes(msg),
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Helper function to sleep for a given duration
|
|
45
|
-
export function sleep(ms: number): Promise<void> {
|
|
46
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Parse the Retry-After header value into milliseconds.
|
|
50
|
-
// Returns undefined if the header is missing or unparseable.
|
|
51
|
-
export function parseRetryAfter(response: Response): number | undefined {
|
|
52
|
-
const retryAfter = response.headers.get("Retry-After");
|
|
53
|
-
if (!retryAfter) return undefined;
|
|
54
|
-
|
|
55
|
-
// Try as seconds (integer)
|
|
56
|
-
const seconds = Number(retryAfter);
|
|
57
|
-
if (!Number.isNaN(seconds) && seconds >= 0) {
|
|
58
|
-
return seconds * 1000;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Try as HTTP-date
|
|
62
|
-
const date = Date.parse(retryAfter);
|
|
63
|
-
if (!Number.isNaN(date)) {
|
|
64
|
-
const delayMs = date - Date.now();
|
|
65
|
-
return delayMs > 0 ? delayMs : 0;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Calculate exponential backoff delay
|
|
72
|
-
export function calculateDelay(attempt: number): number {
|
|
73
|
-
const delay = RETRY_CONFIG.baseDelayMs * Math.pow(2, attempt);
|
|
74
|
-
return Math.min(delay, RETRY_CONFIG.maxDelayMs);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Retry wrapper for fetch requests
|
|
78
|
-
export async function fetchWithRetry(
|
|
79
|
-
url: string,
|
|
80
|
-
options: RequestInit,
|
|
81
|
-
logger?: Logger,
|
|
82
|
-
): Promise<Response> {
|
|
83
|
-
let lastError: any;
|
|
84
|
-
|
|
85
|
-
for (let attempt = 0; attempt <= RETRY_CONFIG.maxRetries; attempt++) {
|
|
86
|
-
try {
|
|
87
|
-
const response = await fetch(url, options);
|
|
88
|
-
|
|
89
|
-
// If response is retryable, treat as error and retry
|
|
90
|
-
if (
|
|
91
|
-
isRetryableError(null, response) &&
|
|
92
|
-
attempt < RETRY_CONFIG.maxRetries
|
|
93
|
-
) {
|
|
94
|
-
let delay = calculateDelay(attempt);
|
|
95
|
-
|
|
96
|
-
// Honor Retry-After header on 429 responses
|
|
97
|
-
if (response.status === 429) {
|
|
98
|
-
const retryAfterMs = parseRetryAfter(response);
|
|
99
|
-
if (retryAfterMs !== undefined) {
|
|
100
|
-
const maxMs = RETRY_CONFIG.maxRetryAfterSeconds * 1000;
|
|
101
|
-
if (retryAfterMs > maxMs) {
|
|
102
|
-
throw new Error(
|
|
103
|
-
`Server requested Retry-After of ${Math.ceil(retryAfterMs / 1000)}s ` +
|
|
104
|
-
`which exceeds the maximum of ${RETRY_CONFIG.maxRetryAfterSeconds}s`,
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
delay = retryAfterMs;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
logger?.warn(
|
|
112
|
-
`Request to ${url} failed with status ${response.status}. ` +
|
|
113
|
-
`Retrying attempt ${attempt + 1}/${RETRY_CONFIG.maxRetries + 1} in ${delay}ms.`,
|
|
114
|
-
);
|
|
115
|
-
await sleep(delay);
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return response; // Success or non-retryable error
|
|
120
|
-
} catch (error) {
|
|
121
|
-
lastError = error;
|
|
122
|
-
|
|
123
|
-
// Check if this is a retryable network error
|
|
124
|
-
if (isRetryableError(error) && attempt < RETRY_CONFIG.maxRetries) {
|
|
125
|
-
const delay = calculateDelay(attempt);
|
|
126
|
-
logger?.warn(
|
|
127
|
-
`Request to ${url} failed with network error. ` +
|
|
128
|
-
`Retrying attempt ${attempt + 1}/${RETRY_CONFIG.maxRetries + 1} in ${delay}ms. Error: ${error?.message || String(error)}`,
|
|
129
|
-
);
|
|
130
|
-
await sleep(delay);
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Not retryable or max retries exceeded
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Re-throw the last error after retries exhausted
|
|
140
|
-
throw lastError;
|
|
141
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TelemetryAgentRunner - A wrapper around AgentRunner that adds telemetry
|
|
3
|
-
* for agent execution streams.
|
|
4
|
-
*
|
|
5
|
-
* This captures the following telemetry events:
|
|
6
|
-
* - oss.runtime.agent_execution_stream_started - when an agent execution starts
|
|
7
|
-
* - oss.runtime.agent_execution_stream_ended - when an agent execution completes
|
|
8
|
-
* - oss.runtime.agent_execution_stream_errored - when an agent execution fails
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { type AgentRunner, InMemoryAgentRunner } from "../../v2/runtime";
|
|
12
|
-
import { createHash } from "node:crypto";
|
|
13
|
-
import { tap, catchError, finalize } from "rxjs";
|
|
14
|
-
import telemetry from "../telemetry-client";
|
|
15
|
-
import type { AgentExecutionResponseInfo } from "@copilotkit/shared/src/telemetry/events";
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Configuration options for TelemetryAgentRunner
|
|
19
|
-
*/
|
|
20
|
-
export interface TelemetryAgentRunnerConfig {
|
|
21
|
-
/**
|
|
22
|
-
* The underlying runner to delegate to
|
|
23
|
-
* If not provided, defaults to InMemoryAgentRunner
|
|
24
|
-
*/
|
|
25
|
-
runner?: AgentRunner;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Optional LangSmith API key (will be hashed for telemetry)
|
|
29
|
-
*/
|
|
30
|
-
langsmithApiKey?: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* An AgentRunner wrapper that adds telemetry tracking for agent executions.
|
|
35
|
-
*
|
|
36
|
-
* Usage:
|
|
37
|
-
* ```ts
|
|
38
|
-
* const runtime = new CopilotRuntime({
|
|
39
|
-
* runner: new TelemetryAgentRunner(),
|
|
40
|
-
* // or with custom runner:
|
|
41
|
-
* runner: new TelemetryAgentRunner({ runner: customRunner }),
|
|
42
|
-
* });
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export class TelemetryAgentRunner implements AgentRunner {
|
|
46
|
-
private readonly _runner: AgentRunner;
|
|
47
|
-
private readonly hashedLgcKey: string | undefined;
|
|
48
|
-
|
|
49
|
-
constructor(config?: TelemetryAgentRunnerConfig) {
|
|
50
|
-
this._runner = config?.runner ?? new InMemoryAgentRunner();
|
|
51
|
-
this.hashedLgcKey = config?.langsmithApiKey
|
|
52
|
-
? createHash("sha256").update(config.langsmithApiKey).digest("hex")
|
|
53
|
-
: undefined;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Runs an agent with telemetry tracking.
|
|
58
|
-
* Wraps the underlying runner's Observable stream with telemetry events.
|
|
59
|
-
*/
|
|
60
|
-
run(...args: Parameters<AgentRunner["run"]>): ReturnType<AgentRunner["run"]> {
|
|
61
|
-
const streamInfo: AgentExecutionResponseInfo = {
|
|
62
|
-
hashedLgcKey: this.hashedLgcKey,
|
|
63
|
-
};
|
|
64
|
-
let streamErrored = false;
|
|
65
|
-
|
|
66
|
-
// Capture stream started event
|
|
67
|
-
telemetry.capture("oss.runtime.agent_execution_stream_started", {
|
|
68
|
-
hashedLgcKey: this.hashedLgcKey,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// Delegate to the underlying runner and wrap with telemetry
|
|
72
|
-
return this._runner.run(...args).pipe(
|
|
73
|
-
// Extract metadata from events if available
|
|
74
|
-
tap((event) => {
|
|
75
|
-
// Try to extract provider/model info from raw events
|
|
76
|
-
const rawEvent = (
|
|
77
|
-
event as {
|
|
78
|
-
rawEvent?: {
|
|
79
|
-
metadata?: Record<string, unknown>;
|
|
80
|
-
data?: Record<string, unknown>;
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
).rawEvent;
|
|
84
|
-
if (rawEvent?.data) {
|
|
85
|
-
const data = rawEvent.data as { output?: { model?: string } };
|
|
86
|
-
if (data?.output?.model) {
|
|
87
|
-
streamInfo.model = data.output.model;
|
|
88
|
-
streamInfo.provider = data.output.model;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (rawEvent?.metadata) {
|
|
92
|
-
const metadata = rawEvent.metadata as {
|
|
93
|
-
langgraph_host?: string;
|
|
94
|
-
langgraph_version?: string;
|
|
95
|
-
};
|
|
96
|
-
if (metadata?.langgraph_host) {
|
|
97
|
-
streamInfo.langGraphHost = metadata.langgraph_host;
|
|
98
|
-
}
|
|
99
|
-
if (metadata?.langgraph_version) {
|
|
100
|
-
streamInfo.langGraphVersion = metadata.langgraph_version;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}),
|
|
104
|
-
catchError((error) => {
|
|
105
|
-
// Capture stream error event
|
|
106
|
-
streamErrored = true;
|
|
107
|
-
telemetry.capture("oss.runtime.agent_execution_stream_errored", {
|
|
108
|
-
...streamInfo,
|
|
109
|
-
error: error instanceof Error ? error.message : String(error),
|
|
110
|
-
});
|
|
111
|
-
throw error;
|
|
112
|
-
}),
|
|
113
|
-
finalize(() => {
|
|
114
|
-
// Capture stream ended event (only if not errored)
|
|
115
|
-
if (!streamErrored) {
|
|
116
|
-
telemetry.capture(
|
|
117
|
-
"oss.runtime.agent_execution_stream_ended",
|
|
118
|
-
streamInfo,
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
}),
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Delegates to the underlying runner's connect method
|
|
127
|
-
*/
|
|
128
|
-
connect(
|
|
129
|
-
...args: Parameters<AgentRunner["connect"]>
|
|
130
|
-
): ReturnType<AgentRunner["connect"]> {
|
|
131
|
-
return this._runner.connect(...args);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Delegates to the underlying runner's isRunning method
|
|
136
|
-
*/
|
|
137
|
-
isRunning(
|
|
138
|
-
...args: Parameters<AgentRunner["isRunning"]>
|
|
139
|
-
): ReturnType<AgentRunner["isRunning"]> {
|
|
140
|
-
return this._runner.isRunning(...args);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Delegates to the underlying runner's stop method
|
|
145
|
-
*/
|
|
146
|
-
stop(
|
|
147
|
-
...args: Parameters<AgentRunner["stop"]>
|
|
148
|
-
): ReturnType<AgentRunner["stop"]> {
|
|
149
|
-
return this._runner.stop(...args);
|
|
150
|
-
}
|
|
151
|
-
}
|
package/src/lib/runtime/types.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { GraphQLContext } from "../integrations";
|
|
2
|
-
import { ActionInput } from "../../graphql/inputs/action.input";
|
|
3
|
-
import { Message } from "../../graphql/types/converted";
|
|
4
|
-
import { MetaEventInput } from "../../graphql/inputs/meta-event.input";
|
|
5
|
-
|
|
6
|
-
export interface BaseEndpointDefinition<TActionType extends EndpointType> {
|
|
7
|
-
type?: TActionType;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface CopilotKitEndpoint extends BaseEndpointDefinition<EndpointType.CopilotKit> {
|
|
11
|
-
url: string;
|
|
12
|
-
onBeforeRequest?: ({ ctx }: { ctx: GraphQLContext }) => {
|
|
13
|
-
headers?: Record<string, string> | undefined;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface LangGraphPlatformAgent {
|
|
18
|
-
name: string;
|
|
19
|
-
description: string;
|
|
20
|
-
assistantId?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface LangGraphPlatformEndpoint extends BaseEndpointDefinition<EndpointType.LangGraphPlatform> {
|
|
24
|
-
deploymentUrl: string;
|
|
25
|
-
langsmithApiKey?: string | null;
|
|
26
|
-
agents: LangGraphPlatformAgent[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export type RemoteActionInfoResponse = {
|
|
30
|
-
actions: any[];
|
|
31
|
-
agents: any[];
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export type RemoteAgentHandlerParams = {
|
|
35
|
-
name: string;
|
|
36
|
-
actionInputsWithoutAgents: ActionInput[];
|
|
37
|
-
threadId?: string;
|
|
38
|
-
nodeName?: string;
|
|
39
|
-
additionalMessages?: Message[];
|
|
40
|
-
metaEvents?: MetaEventInput[];
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export type EndpointDefinition = CopilotKitEndpoint | LangGraphPlatformEndpoint;
|
|
44
|
-
|
|
45
|
-
export enum EndpointType {
|
|
46
|
-
CopilotKit = "copilotKit",
|
|
47
|
-
LangGraphPlatform = "langgraph-platform",
|
|
48
|
-
}
|