@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,187 +0,0 @@
|
|
|
1
|
-
import { CreateCopilotRuntimeServerOptions, getCommonConfig } from "../shared";
|
|
2
|
-
import telemetry, {
|
|
3
|
-
getRuntimeInstanceTelemetryInfo,
|
|
4
|
-
} from "../../telemetry-client";
|
|
5
|
-
import { createCopilotEndpointSingleRoute } from "../../../v2/runtime";
|
|
6
|
-
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
7
|
-
import {
|
|
8
|
-
getFullUrl,
|
|
9
|
-
IncomingWithBody,
|
|
10
|
-
isDisturbedOrLockedError,
|
|
11
|
-
isStreamConsumed,
|
|
12
|
-
nodeStreamToReadableStream,
|
|
13
|
-
readableStreamToNodeStream,
|
|
14
|
-
synthesizeBodyFromParsedBody,
|
|
15
|
-
toHeaders,
|
|
16
|
-
} from "./request-handler";
|
|
17
|
-
|
|
18
|
-
export function copilotRuntimeNodeHttpEndpoint(
|
|
19
|
-
options: CreateCopilotRuntimeServerOptions,
|
|
20
|
-
) {
|
|
21
|
-
const commonConfig = getCommonConfig(options);
|
|
22
|
-
|
|
23
|
-
telemetry.setGlobalProperties({
|
|
24
|
-
runtime: {
|
|
25
|
-
framework: "node-http",
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
if (options.properties?._copilotkit) {
|
|
30
|
-
telemetry.setGlobalProperties({
|
|
31
|
-
_copilotkit: options.properties._copilotkit,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
telemetry.capture(
|
|
36
|
-
"oss.runtime.instance_created",
|
|
37
|
-
getRuntimeInstanceTelemetryInfo(options),
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
const logger = commonConfig.logging;
|
|
41
|
-
logger.debug("Creating Node HTTP endpoint");
|
|
42
|
-
|
|
43
|
-
const serviceAdapter = options.serviceAdapter;
|
|
44
|
-
if (serviceAdapter) {
|
|
45
|
-
options.runtime.handleServiceAdapter(serviceAdapter);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Note: cors option requires @copilotkit/runtime with credentials support
|
|
49
|
-
const honoApp = createCopilotEndpointSingleRoute({
|
|
50
|
-
runtime: options.runtime.instance,
|
|
51
|
-
basePath: options.baseUrl ?? options.endpoint,
|
|
52
|
-
...(options.cors && { cors: options.cors }),
|
|
53
|
-
} as any);
|
|
54
|
-
|
|
55
|
-
const handle = async function handler(
|
|
56
|
-
req: IncomingWithBody,
|
|
57
|
-
res: ServerResponse,
|
|
58
|
-
) {
|
|
59
|
-
const url = getFullUrl(req);
|
|
60
|
-
const hasBody = req.method !== "GET" && req.method !== "HEAD";
|
|
61
|
-
|
|
62
|
-
const baseHeaders = toHeaders(req.headers);
|
|
63
|
-
const parsedBody = req.body;
|
|
64
|
-
|
|
65
|
-
const streamConsumed = isStreamConsumed(req) || parsedBody !== undefined;
|
|
66
|
-
const canStream = hasBody && !streamConsumed;
|
|
67
|
-
|
|
68
|
-
let requestBody: BodyInit | null | undefined = undefined;
|
|
69
|
-
let useDuplex = false;
|
|
70
|
-
|
|
71
|
-
if (hasBody && canStream) {
|
|
72
|
-
requestBody = nodeStreamToReadableStream(req);
|
|
73
|
-
useDuplex = true;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (hasBody && streamConsumed) {
|
|
77
|
-
if (parsedBody !== undefined) {
|
|
78
|
-
const synthesized = synthesizeBodyFromParsedBody(
|
|
79
|
-
parsedBody,
|
|
80
|
-
baseHeaders,
|
|
81
|
-
);
|
|
82
|
-
requestBody = synthesized.body ?? undefined;
|
|
83
|
-
baseHeaders.delete("content-length");
|
|
84
|
-
|
|
85
|
-
if (synthesized.contentType) {
|
|
86
|
-
baseHeaders.set("content-type", synthesized.contentType);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
logger.debug(
|
|
90
|
-
"Request stream already consumed; using parsed req.body to rebuild request.",
|
|
91
|
-
);
|
|
92
|
-
} else {
|
|
93
|
-
logger.warn(
|
|
94
|
-
"Request stream consumed with no available body; sending empty payload.",
|
|
95
|
-
);
|
|
96
|
-
requestBody = undefined;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const buildRequest = (
|
|
101
|
-
body: BodyInit | null | undefined,
|
|
102
|
-
headers: Headers,
|
|
103
|
-
duplex: boolean,
|
|
104
|
-
) =>
|
|
105
|
-
new Request(url, {
|
|
106
|
-
method: req.method,
|
|
107
|
-
headers,
|
|
108
|
-
body,
|
|
109
|
-
duplex: duplex ? "half" : undefined,
|
|
110
|
-
} as RequestInit);
|
|
111
|
-
|
|
112
|
-
let response: Response;
|
|
113
|
-
try {
|
|
114
|
-
response = await honoApp.fetch(
|
|
115
|
-
buildRequest(requestBody, baseHeaders, useDuplex),
|
|
116
|
-
);
|
|
117
|
-
} catch (error) {
|
|
118
|
-
if (isDisturbedOrLockedError(error) && hasBody) {
|
|
119
|
-
logger.warn(
|
|
120
|
-
"Encountered disturbed/locked request body; rebuilding request using parsed body or empty payload.",
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
const fallbackHeaders = new Headers(baseHeaders);
|
|
124
|
-
let fallbackBody: BodyInit | null | undefined;
|
|
125
|
-
|
|
126
|
-
if (parsedBody !== undefined) {
|
|
127
|
-
const synthesized = synthesizeBodyFromParsedBody(
|
|
128
|
-
parsedBody,
|
|
129
|
-
fallbackHeaders,
|
|
130
|
-
);
|
|
131
|
-
fallbackBody = synthesized.body ?? undefined;
|
|
132
|
-
fallbackHeaders.delete("content-length");
|
|
133
|
-
|
|
134
|
-
if (synthesized.contentType) {
|
|
135
|
-
fallbackHeaders.set("content-type", synthesized.contentType);
|
|
136
|
-
}
|
|
137
|
-
} else {
|
|
138
|
-
fallbackBody = undefined;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
response = await honoApp.fetch(
|
|
142
|
-
buildRequest(fallbackBody, fallbackHeaders, false),
|
|
143
|
-
);
|
|
144
|
-
} else {
|
|
145
|
-
throw error;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
res.statusCode = response.status;
|
|
150
|
-
response.headers.forEach((value, key) => {
|
|
151
|
-
res.setHeader(key, value);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
if (response.body) {
|
|
155
|
-
readableStreamToNodeStream(response.body).pipe(res);
|
|
156
|
-
} else {
|
|
157
|
-
res.end();
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
// Duck-type check for Request-like objects (handles polyfilled Request from @hono/node-server)
|
|
162
|
-
function isRequestLike(obj: unknown): obj is Request {
|
|
163
|
-
return (
|
|
164
|
-
obj instanceof Request ||
|
|
165
|
-
(typeof obj === "object" &&
|
|
166
|
-
obj !== null &&
|
|
167
|
-
"url" in obj &&
|
|
168
|
-
"method" in obj &&
|
|
169
|
-
"headers" in obj &&
|
|
170
|
-
typeof (obj as any).url === "string" &&
|
|
171
|
-
typeof (obj as any).method === "string")
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return function (
|
|
176
|
-
reqOrRequest: IncomingMessage | Request,
|
|
177
|
-
res?: ServerResponse,
|
|
178
|
-
): Promise<void> | Promise<Response> | Response {
|
|
179
|
-
if (isRequestLike(reqOrRequest) && !res) {
|
|
180
|
-
return honoApp.fetch(reqOrRequest as Request);
|
|
181
|
-
}
|
|
182
|
-
if (!res) {
|
|
183
|
-
throw new TypeError("ServerResponse is required for Node HTTP requests");
|
|
184
|
-
}
|
|
185
|
-
return handle(reqOrRequest as IncomingMessage, res);
|
|
186
|
-
};
|
|
187
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import type { IncomingMessage } from "http";
|
|
2
|
-
import { Readable } from "node:stream";
|
|
3
|
-
|
|
4
|
-
export type IncomingWithBody = IncomingMessage & {
|
|
5
|
-
body?: unknown;
|
|
6
|
-
complete?: boolean;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export function readableStreamToNodeStream(
|
|
10
|
-
webStream: ReadableStream,
|
|
11
|
-
): Readable {
|
|
12
|
-
const reader = webStream.getReader();
|
|
13
|
-
|
|
14
|
-
return new Readable({
|
|
15
|
-
async read() {
|
|
16
|
-
try {
|
|
17
|
-
const { done, value } = await reader.read();
|
|
18
|
-
if (done) {
|
|
19
|
-
this.push(null);
|
|
20
|
-
} else {
|
|
21
|
-
this.push(Buffer.from(value));
|
|
22
|
-
}
|
|
23
|
-
} catch (err) {
|
|
24
|
-
this.destroy(err as Error);
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function nodeStreamToReadableStream(
|
|
31
|
-
nodeStream: Readable,
|
|
32
|
-
): ReadableStream<Uint8Array> {
|
|
33
|
-
return new ReadableStream({
|
|
34
|
-
start(controller) {
|
|
35
|
-
nodeStream.on("data", (chunk) => {
|
|
36
|
-
controller.enqueue(
|
|
37
|
-
chunk instanceof Buffer ? new Uint8Array(chunk) : chunk,
|
|
38
|
-
);
|
|
39
|
-
});
|
|
40
|
-
nodeStream.on("end", () => {
|
|
41
|
-
controller.close();
|
|
42
|
-
});
|
|
43
|
-
nodeStream.on("error", (err) => {
|
|
44
|
-
controller.error(err);
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
cancel() {
|
|
48
|
-
nodeStream.destroy();
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function getFullUrl(req: IncomingMessage): string {
|
|
54
|
-
// Use req.url (path relative to mount point) for Hono routing to work correctly.
|
|
55
|
-
// Express sets req.url to the path after the mount point (e.g., "/" when mounted at "/copilotkit").
|
|
56
|
-
// Pure Node HTTP sets req.url to the full path.
|
|
57
|
-
const path = req.url || "/";
|
|
58
|
-
const host =
|
|
59
|
-
(req.headers["x-forwarded-host"] as string) ||
|
|
60
|
-
(req.headers.host as string) ||
|
|
61
|
-
"localhost";
|
|
62
|
-
const proto =
|
|
63
|
-
(req.headers["x-forwarded-proto"] as string) ||
|
|
64
|
-
((req.socket as any).encrypted ? "https" : "http");
|
|
65
|
-
|
|
66
|
-
return `${proto}://${host}${path}`;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function toHeaders(rawHeaders: IncomingMessage["headers"]): Headers {
|
|
70
|
-
const headers = new Headers();
|
|
71
|
-
|
|
72
|
-
for (const [key, value] of Object.entries(rawHeaders)) {
|
|
73
|
-
if (value === undefined) continue;
|
|
74
|
-
|
|
75
|
-
if (Array.isArray(value)) {
|
|
76
|
-
value.forEach((entry) => headers.append(key, entry));
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
headers.append(key, value);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return headers;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function isStreamConsumed(req: IncomingWithBody): boolean {
|
|
87
|
-
const readableState = (req as any)._readableState;
|
|
88
|
-
|
|
89
|
-
return Boolean(
|
|
90
|
-
req.readableEnded ||
|
|
91
|
-
req.complete ||
|
|
92
|
-
readableState?.ended ||
|
|
93
|
-
readableState?.endEmitted,
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function synthesizeBodyFromParsedBody(
|
|
98
|
-
parsedBody: unknown,
|
|
99
|
-
headers: Headers,
|
|
100
|
-
): { body: BodyInit | null; contentType?: string } {
|
|
101
|
-
if (parsedBody === null || parsedBody === undefined) {
|
|
102
|
-
return { body: null };
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (parsedBody instanceof Buffer || parsedBody instanceof Uint8Array) {
|
|
106
|
-
return { body: parsedBody };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (typeof parsedBody === "string") {
|
|
110
|
-
return {
|
|
111
|
-
body: parsedBody,
|
|
112
|
-
contentType: headers.get("content-type") ?? "text/plain",
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
body: JSON.stringify(parsedBody),
|
|
118
|
-
contentType: "application/json",
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function isDisturbedOrLockedError(error: unknown): boolean {
|
|
123
|
-
return (
|
|
124
|
-
error instanceof TypeError &&
|
|
125
|
-
typeof error.message === "string" &&
|
|
126
|
-
(error.message.includes("disturbed") || error.message.includes("locked"))
|
|
127
|
-
);
|
|
128
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { YogaInitialContext } from "graphql-yoga";
|
|
2
|
-
import { buildSchemaSync } from "type-graphql";
|
|
3
|
-
import { CopilotResolver } from "../../graphql/resolvers/copilot.resolver";
|
|
4
|
-
import { CopilotRuntime } from "../runtime/copilot-runtime";
|
|
5
|
-
import { CopilotServiceAdapter } from "../../service-adapters";
|
|
6
|
-
import { CopilotCloudOptions } from "../cloud";
|
|
7
|
-
import { LogLevel, createLogger } from "../../lib/logger";
|
|
8
|
-
import telemetry from "../telemetry-client";
|
|
9
|
-
import { StateResolver } from "../../graphql/resolvers/state.resolver";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* CORS configuration for CopilotKit endpoints.
|
|
13
|
-
*/
|
|
14
|
-
export interface CopilotEndpointCorsConfig {
|
|
15
|
-
/**
|
|
16
|
-
* Allowed origin(s). Can be a string, array of strings, or a function that returns the origin.
|
|
17
|
-
*/
|
|
18
|
-
origin:
|
|
19
|
-
| string
|
|
20
|
-
| string[]
|
|
21
|
-
| ((origin: string, c: any) => string | undefined | null);
|
|
22
|
-
/**
|
|
23
|
-
* Whether to include credentials (cookies, authorization headers) in CORS requests.
|
|
24
|
-
* When true, origin cannot be "*" - must be an explicit origin.
|
|
25
|
-
*/
|
|
26
|
-
credentials?: boolean;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const logger = createLogger();
|
|
30
|
-
|
|
31
|
-
type AnyPrimitive = string | boolean | number | null;
|
|
32
|
-
export type CopilotRequestContextProperties = Record<
|
|
33
|
-
string,
|
|
34
|
-
AnyPrimitive | Record<string, AnyPrimitive>
|
|
35
|
-
>;
|
|
36
|
-
|
|
37
|
-
export type GraphQLContext = YogaInitialContext & {
|
|
38
|
-
_copilotkit: CreateCopilotRuntimeServerOptions;
|
|
39
|
-
properties: CopilotRequestContextProperties;
|
|
40
|
-
logger: typeof logger;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export interface CreateCopilotRuntimeServerOptions {
|
|
44
|
-
runtime: CopilotRuntime<any>;
|
|
45
|
-
serviceAdapter?: CopilotServiceAdapter;
|
|
46
|
-
endpoint: string;
|
|
47
|
-
baseUrl?: string;
|
|
48
|
-
cloud?: CopilotCloudOptions;
|
|
49
|
-
properties?: CopilotRequestContextProperties;
|
|
50
|
-
logLevel?: LogLevel;
|
|
51
|
-
/**
|
|
52
|
-
* Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.
|
|
53
|
-
* To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.
|
|
54
|
-
*/
|
|
55
|
-
cors?: CopilotEndpointCorsConfig;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function buildSchema(
|
|
59
|
-
options: {
|
|
60
|
-
emitSchemaFile?: string;
|
|
61
|
-
} = {},
|
|
62
|
-
) {
|
|
63
|
-
logger.debug("Building GraphQL schema...");
|
|
64
|
-
const schema = buildSchemaSync({
|
|
65
|
-
resolvers: [CopilotResolver, StateResolver],
|
|
66
|
-
emitSchemaFile: options.emitSchemaFile,
|
|
67
|
-
});
|
|
68
|
-
logger.debug("GraphQL schema built successfully");
|
|
69
|
-
return schema;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export type CommonConfig = {
|
|
73
|
-
logging: typeof logger;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export function getCommonConfig(
|
|
77
|
-
options: CreateCopilotRuntimeServerOptions,
|
|
78
|
-
): CommonConfig {
|
|
79
|
-
const logLevel =
|
|
80
|
-
(process.env.LOG_LEVEL as LogLevel) ||
|
|
81
|
-
(options.logLevel as LogLevel) ||
|
|
82
|
-
"error";
|
|
83
|
-
const logger = createLogger({
|
|
84
|
-
level: logLevel,
|
|
85
|
-
component: "getCommonConfig",
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if (options.cloud) {
|
|
89
|
-
telemetry.setCloudConfiguration({
|
|
90
|
-
publicApiKey: options.cloud.publicApiKey,
|
|
91
|
-
baseUrl: options.cloud.baseUrl,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (options.properties?._copilotkit) {
|
|
96
|
-
telemetry.setGlobalProperties({
|
|
97
|
-
_copilotkit: {
|
|
98
|
-
...(options.properties._copilotkit as Record<string, any>),
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
telemetry.setGlobalProperties({
|
|
104
|
-
runtime: {
|
|
105
|
-
serviceAdapter: options.serviceAdapter?.constructor?.name ?? "none",
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
logging: createLogger({ component: "CopilotKit Runtime", level: logLevel }),
|
|
111
|
-
};
|
|
112
|
-
}
|
package/src/lib/logger.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import createPinoLogger from "pino";
|
|
2
|
-
import pretty from "pino-pretty";
|
|
3
|
-
|
|
4
|
-
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
5
|
-
|
|
6
|
-
export type CopilotRuntimeLogger = ReturnType<typeof createLogger>;
|
|
7
|
-
|
|
8
|
-
export function createLogger(options?: {
|
|
9
|
-
level?: LogLevel;
|
|
10
|
-
component?: string;
|
|
11
|
-
}) {
|
|
12
|
-
const { level, component } = options || {};
|
|
13
|
-
const stream = pretty({ colorize: true });
|
|
14
|
-
|
|
15
|
-
const logger = createPinoLogger(
|
|
16
|
-
{
|
|
17
|
-
level: process.env.LOG_LEVEL || level || "error",
|
|
18
|
-
redact: {
|
|
19
|
-
paths: ["pid", "hostname"],
|
|
20
|
-
remove: true,
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
stream,
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
if (component) {
|
|
27
|
-
return logger.child({ component });
|
|
28
|
-
} else {
|
|
29
|
-
return logger;
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/lib/observability.ts
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RuntimeEventSource,
|
|
3
|
-
RuntimeEventTypes,
|
|
4
|
-
} from "../service-adapters/events";
|
|
5
|
-
|
|
6
|
-
export interface LLMRequestData {
|
|
7
|
-
threadId?: string;
|
|
8
|
-
runId?: string;
|
|
9
|
-
model?: string;
|
|
10
|
-
messages: any[];
|
|
11
|
-
actions?: any[];
|
|
12
|
-
forwardedParameters?: any;
|
|
13
|
-
timestamp: number;
|
|
14
|
-
provider?: string;
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface LLMResponseData {
|
|
19
|
-
threadId: string;
|
|
20
|
-
runId?: string;
|
|
21
|
-
model?: string;
|
|
22
|
-
output: any;
|
|
23
|
-
latency: number;
|
|
24
|
-
timestamp: number;
|
|
25
|
-
provider?: string;
|
|
26
|
-
isProgressiveChunk?: boolean;
|
|
27
|
-
isFinalResponse?: boolean;
|
|
28
|
-
[key: string]: any;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface LLMErrorData {
|
|
32
|
-
threadId?: string;
|
|
33
|
-
runId?: string;
|
|
34
|
-
model?: string;
|
|
35
|
-
error: Error | string;
|
|
36
|
-
timestamp: number;
|
|
37
|
-
provider?: string;
|
|
38
|
-
[key: string]: any;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface CopilotObservabilityHooks {
|
|
42
|
-
handleRequest: (data: LLMRequestData) => void | Promise<void>;
|
|
43
|
-
handleResponse: (data: LLMResponseData) => void | Promise<void>;
|
|
44
|
-
handleError: (data: LLMErrorData) => void | Promise<void>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Configuration for CopilotKit logging functionality.
|
|
49
|
-
*
|
|
50
|
-
* @remarks
|
|
51
|
-
* Custom logging handlers require a valid CopilotKit public API key.
|
|
52
|
-
* Sign up at https://docs.copilotkit.ai/quickstart#get-a-copilot-cloud-public-api-key to get your key.
|
|
53
|
-
*/
|
|
54
|
-
export interface CopilotObservabilityConfig {
|
|
55
|
-
/**
|
|
56
|
-
* Enable or disable logging functionality.
|
|
57
|
-
*
|
|
58
|
-
* @default false
|
|
59
|
-
*/
|
|
60
|
-
enabled: boolean;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Controls whether logs are streamed progressively or buffered.
|
|
64
|
-
* - When true: Each token and update is logged as it's generated (real-time)
|
|
65
|
-
* - When false: Complete responses are logged after completion (batched)
|
|
66
|
-
*
|
|
67
|
-
* @default true
|
|
68
|
-
*/
|
|
69
|
-
progressive: boolean;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Custom observability hooks for request, response, and error events.
|
|
73
|
-
*
|
|
74
|
-
* @remarks
|
|
75
|
-
* Using custom observability hooks requires a valid CopilotKit public API key.
|
|
76
|
-
*/
|
|
77
|
-
hooks: CopilotObservabilityHooks;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Setup progressive logging by wrapping the event stream
|
|
82
|
-
*/
|
|
83
|
-
function setupProgressiveLogging(
|
|
84
|
-
eventSource: RuntimeEventSource,
|
|
85
|
-
streamedChunks: any[],
|
|
86
|
-
requestStartTime: number,
|
|
87
|
-
context: {
|
|
88
|
-
threadId?: string;
|
|
89
|
-
runId?: string;
|
|
90
|
-
model?: string;
|
|
91
|
-
provider?: string;
|
|
92
|
-
agentName?: string;
|
|
93
|
-
nodeName?: string;
|
|
94
|
-
},
|
|
95
|
-
publicApiKey?: string,
|
|
96
|
-
): void {
|
|
97
|
-
if (
|
|
98
|
-
this.observability?.enabled &&
|
|
99
|
-
this.observability.progressive &&
|
|
100
|
-
publicApiKey
|
|
101
|
-
) {
|
|
102
|
-
// Keep reference to original stream function
|
|
103
|
-
const originalStream = eventSource.stream.bind(eventSource);
|
|
104
|
-
|
|
105
|
-
// Wrap the stream function to intercept events
|
|
106
|
-
eventSource.stream = async (callback) => {
|
|
107
|
-
await originalStream(async (eventStream$) => {
|
|
108
|
-
// Create subscription to capture streaming events
|
|
109
|
-
eventStream$.subscribe({
|
|
110
|
-
next: (event) => {
|
|
111
|
-
// Only log content chunks
|
|
112
|
-
if (event.type === RuntimeEventTypes.TextMessageContent) {
|
|
113
|
-
// Store the chunk
|
|
114
|
-
streamedChunks.push(event.content);
|
|
115
|
-
|
|
116
|
-
// Log each chunk separately for progressive mode
|
|
117
|
-
try {
|
|
118
|
-
const progressiveData: LLMResponseData = {
|
|
119
|
-
threadId: context.threadId || "",
|
|
120
|
-
runId: context.runId,
|
|
121
|
-
model: context.model,
|
|
122
|
-
output: event.content,
|
|
123
|
-
latency: Date.now() - requestStartTime,
|
|
124
|
-
timestamp: Date.now(),
|
|
125
|
-
provider: context.provider,
|
|
126
|
-
isProgressiveChunk: true,
|
|
127
|
-
agentName: context.agentName,
|
|
128
|
-
nodeName: context.nodeName,
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// Use Promise to handle async logger without awaiting
|
|
132
|
-
Promise.resolve()
|
|
133
|
-
.then(() => {
|
|
134
|
-
this.observability.hooks.handleResponse(progressiveData);
|
|
135
|
-
})
|
|
136
|
-
.catch((error) => {
|
|
137
|
-
console.error("Error in progressive logging:", error);
|
|
138
|
-
});
|
|
139
|
-
} catch (error) {
|
|
140
|
-
console.error("Error preparing progressive log data:", error);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
// Call the original callback with the event stream
|
|
147
|
-
await callback(eventStream$);
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Log error if observability is enabled
|
|
155
|
-
*/
|
|
156
|
-
async function logObservabilityError(
|
|
157
|
-
errorData: LLMErrorData,
|
|
158
|
-
publicApiKey?: string,
|
|
159
|
-
): Promise<void> {
|
|
160
|
-
if (this.observability?.enabled && publicApiKey) {
|
|
161
|
-
try {
|
|
162
|
-
await this.observability.hooks.handleError(errorData);
|
|
163
|
-
} catch (logError) {
|
|
164
|
-
console.error("Error logging LLM error:", logError);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|