@copilotkit/runtime 2.0.0-next.1 → 2.0.0-rc.1
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/LICENSE +21 -0
- package/README.md +135 -1
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/_virtual/_rolldown/runtime.mjs +18 -0
- package/dist/agent/converters/aisdk.cjs +355 -0
- package/dist/agent/converters/aisdk.cjs.map +1 -0
- package/dist/agent/converters/aisdk.d.cts +22 -0
- package/dist/agent/converters/aisdk.d.cts.map +1 -0
- package/dist/agent/converters/aisdk.d.mts +22 -0
- package/dist/agent/converters/aisdk.d.mts.map +1 -0
- package/dist/agent/converters/aisdk.mjs +351 -0
- package/dist/agent/converters/aisdk.mjs.map +1 -0
- package/dist/agent/converters/index.d.mts +2 -0
- package/dist/agent/converters/tanstack.cjs +374 -0
- package/dist/agent/converters/tanstack.cjs.map +1 -0
- package/dist/agent/converters/tanstack.d.cts +83 -0
- package/dist/agent/converters/tanstack.d.cts.map +1 -0
- package/dist/agent/converters/tanstack.d.mts +83 -0
- package/dist/agent/converters/tanstack.d.mts.map +1 -0
- package/dist/agent/converters/tanstack.mjs +372 -0
- package/dist/agent/converters/tanstack.mjs.map +1 -0
- package/dist/agent/converters/usage.cjs +68 -0
- package/dist/agent/converters/usage.cjs.map +1 -0
- package/dist/agent/converters/usage.d.cts +19 -0
- package/dist/agent/converters/usage.d.cts.map +1 -0
- package/dist/agent/converters/usage.d.mts +19 -0
- package/dist/agent/converters/usage.d.mts.map +1 -0
- package/dist/agent/converters/usage.mjs +62 -0
- package/dist/agent/converters/usage.mjs.map +1 -0
- package/dist/agent/index.cjs +1328 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +467 -0
- package/dist/agent/index.d.cts.map +1 -0
- package/dist/agent/index.d.mts +468 -0
- package/dist/agent/index.d.mts.map +1 -0
- package/dist/agent/index.mjs +1318 -0
- package/dist/agent/index.mjs.map +1 -0
- package/dist/agent/learned-skills.cjs +76 -0
- package/dist/agent/learned-skills.cjs.map +1 -0
- package/dist/agent/learned-skills.d.cts +15 -0
- package/dist/agent/learned-skills.d.cts.map +1 -0
- package/dist/agent/learned-skills.d.mts +15 -0
- package/dist/agent/learned-skills.d.mts.map +1 -0
- package/dist/agent/learned-skills.mjs +74 -0
- package/dist/agent/learned-skills.mjs.map +1 -0
- package/dist/agent/mcp-tool-names.cjs +82 -0
- package/dist/agent/mcp-tool-names.cjs.map +1 -0
- package/dist/agent/mcp-tool-names.mjs +80 -0
- package/dist/agent/mcp-tool-names.mjs.map +1 -0
- package/dist/agent/state-delta.cjs +321 -0
- package/dist/agent/state-delta.cjs.map +1 -0
- package/dist/agent/state-delta.mjs +320 -0
- package/dist/agent/state-delta.mjs.map +1 -0
- package/dist/agent/url-download.cjs +503 -0
- package/dist/agent/url-download.cjs.map +1 -0
- package/dist/agent/url-download.d.cts +79 -0
- package/dist/agent/url-download.d.cts.map +1 -0
- package/dist/agent/url-download.d.mts +79 -0
- package/dist/agent/url-download.d.mts.map +1 -0
- package/dist/agent/url-download.mjs +500 -0
- package/dist/agent/url-download.mjs.map +1 -0
- package/dist/index.cjs +75 -0
- package/dist/index.d.cts +24 -0
- package/dist/index.d.mts +24 -0
- package/dist/index.mjs +17 -5598
- package/dist/internal/learned-skills.cjs +21 -0
- package/dist/internal/learned-skills.d.cts +9 -0
- package/dist/internal/learned-skills.d.mts +9 -0
- package/dist/internal/learned-skills.mjs +9 -0
- package/dist/node.cjs +7 -0
- package/dist/node.d.cts +4 -0
- package/dist/node.d.mts +4 -0
- package/dist/node.mjs +4 -0
- package/dist/runtime/core/channel-activation-config.cjs +87 -0
- package/dist/runtime/core/channel-activation-config.cjs.map +1 -0
- package/dist/runtime/core/channel-activation-config.d.cts +39 -0
- package/dist/runtime/core/channel-activation-config.d.cts.map +1 -0
- package/dist/runtime/core/channel-activation-config.d.mts +39 -0
- package/dist/runtime/core/channel-activation-config.d.mts.map +1 -0
- package/dist/runtime/core/channel-activation-config.mjs +85 -0
- package/dist/runtime/core/channel-activation-config.mjs.map +1 -0
- package/dist/runtime/core/channel-manager.cjs +973 -0
- package/dist/runtime/core/channel-manager.cjs.map +1 -0
- package/dist/runtime/core/channel-manager.d.cts +166 -0
- package/dist/runtime/core/channel-manager.d.cts.map +1 -0
- package/dist/runtime/core/channel-manager.d.mts +167 -0
- package/dist/runtime/core/channel-manager.d.mts.map +1 -0
- package/dist/runtime/core/channel-manager.mjs +972 -0
- package/dist/runtime/core/channel-manager.mjs.map +1 -0
- package/dist/runtime/core/debug-event-bus.cjs +57 -0
- package/dist/runtime/core/debug-event-bus.cjs.map +1 -0
- package/dist/runtime/core/debug-event-bus.d.cts +18 -0
- package/dist/runtime/core/debug-event-bus.d.cts.map +1 -0
- package/dist/runtime/core/debug-event-bus.d.mts +18 -0
- package/dist/runtime/core/debug-event-bus.d.mts.map +1 -0
- package/dist/runtime/core/debug-event-bus.mjs +55 -0
- package/dist/runtime/core/debug-event-bus.mjs.map +1 -0
- package/dist/runtime/core/fetch-cors.cjs +71 -0
- package/dist/runtime/core/fetch-cors.cjs.map +1 -0
- package/dist/runtime/core/fetch-cors.d.cts +19 -0
- package/dist/runtime/core/fetch-cors.d.cts.map +1 -0
- package/dist/runtime/core/fetch-cors.d.mts +19 -0
- package/dist/runtime/core/fetch-cors.d.mts.map +1 -0
- package/dist/runtime/core/fetch-cors.mjs +69 -0
- package/dist/runtime/core/fetch-cors.mjs.map +1 -0
- package/dist/runtime/core/fetch-handler.cjs +539 -0
- package/dist/runtime/core/fetch-handler.cjs.map +1 -0
- package/dist/runtime/core/fetch-handler.d.cts +99 -0
- package/dist/runtime/core/fetch-handler.d.cts.map +1 -0
- package/dist/runtime/core/fetch-handler.d.mts +99 -0
- package/dist/runtime/core/fetch-handler.d.mts.map +1 -0
- package/dist/runtime/core/fetch-handler.mjs +538 -0
- package/dist/runtime/core/fetch-handler.mjs.map +1 -0
- package/dist/runtime/core/fetch-router.cjs +141 -0
- package/dist/runtime/core/fetch-router.cjs.map +1 -0
- package/dist/runtime/core/fetch-router.mjs +140 -0
- package/dist/runtime/core/fetch-router.mjs.map +1 -0
- package/dist/runtime/core/hooks.cjs +28 -0
- package/dist/runtime/core/hooks.cjs.map +1 -0
- package/dist/runtime/core/hooks.d.cts +121 -0
- package/dist/runtime/core/hooks.d.cts.map +1 -0
- package/dist/runtime/core/hooks.d.mts +121 -0
- package/dist/runtime/core/hooks.d.mts.map +1 -0
- package/dist/runtime/core/hooks.mjs +24 -0
- package/dist/runtime/core/hooks.mjs.map +1 -0
- package/dist/runtime/core/learning.cjs +61 -0
- package/dist/runtime/core/learning.cjs.map +1 -0
- package/dist/runtime/core/learning.d.cts +61 -0
- package/dist/runtime/core/learning.d.cts.map +1 -0
- package/dist/runtime/core/learning.d.mts +61 -0
- package/dist/runtime/core/learning.d.mts.map +1 -0
- package/dist/runtime/core/learning.mjs +56 -0
- package/dist/runtime/core/learning.mjs.map +1 -0
- package/dist/runtime/core/logger.cjs +21 -0
- package/dist/runtime/core/logger.cjs.map +1 -0
- package/dist/runtime/core/logger.d.cts +12 -0
- package/dist/runtime/core/logger.d.cts.map +1 -0
- package/dist/runtime/core/logger.d.mts +12 -0
- package/dist/runtime/core/logger.d.mts.map +1 -0
- package/dist/runtime/core/logger.mjs +18 -0
- package/dist/runtime/core/logger.mjs.map +1 -0
- package/dist/runtime/core/middleware-sse-parser.cjs +149 -0
- package/dist/runtime/core/middleware-sse-parser.cjs.map +1 -0
- package/dist/runtime/core/middleware-sse-parser.d.cts +21 -0
- package/dist/runtime/core/middleware-sse-parser.d.cts.map +1 -0
- package/dist/runtime/core/middleware-sse-parser.d.mts +21 -0
- package/dist/runtime/core/middleware-sse-parser.d.mts.map +1 -0
- package/dist/runtime/core/middleware-sse-parser.mjs +148 -0
- package/dist/runtime/core/middleware-sse-parser.mjs.map +1 -0
- package/dist/runtime/core/middleware.cjs +34 -0
- package/dist/runtime/core/middleware.cjs.map +1 -0
- package/dist/runtime/core/middleware.d.cts +31 -0
- package/dist/runtime/core/middleware.d.cts.map +1 -0
- package/dist/runtime/core/middleware.d.mts +31 -0
- package/dist/runtime/core/middleware.d.mts.map +1 -0
- package/dist/runtime/core/middleware.mjs +32 -0
- package/dist/runtime/core/middleware.mjs.map +1 -0
- package/dist/runtime/core/package-info.cjs +9 -0
- package/dist/runtime/core/package-info.cjs.map +1 -0
- package/dist/runtime/core/package-info.mjs +7 -0
- package/dist/runtime/core/package-info.mjs.map +1 -0
- package/dist/runtime/core/runtime-error-reporter.cjs +21 -0
- package/dist/runtime/core/runtime-error-reporter.cjs.map +1 -0
- package/dist/runtime/core/runtime-error-reporter.mjs +18 -0
- package/dist/runtime/core/runtime-error-reporter.mjs.map +1 -0
- package/dist/runtime/core/runtime.cjs +256 -0
- package/dist/runtime/core/runtime.cjs.map +1 -0
- package/dist/runtime/core/runtime.d.cts +481 -0
- package/dist/runtime/core/runtime.d.cts.map +1 -0
- package/dist/runtime/core/runtime.d.mts +481 -0
- package/dist/runtime/core/runtime.d.mts.map +1 -0
- package/dist/runtime/core/runtime.mjs +249 -0
- package/dist/runtime/core/runtime.mjs.map +1 -0
- package/dist/runtime/endpoints/auto-start-channels.cjs +46 -0
- package/dist/runtime/endpoints/auto-start-channels.cjs.map +1 -0
- package/dist/runtime/endpoints/auto-start-channels.mjs +45 -0
- package/dist/runtime/endpoints/auto-start-channels.mjs.map +1 -0
- package/dist/runtime/endpoints/node-fetch-handler.cjs +75 -0
- package/dist/runtime/endpoints/node-fetch-handler.cjs.map +1 -0
- package/dist/runtime/endpoints/node-fetch-handler.d.cts +11 -0
- package/dist/runtime/endpoints/node-fetch-handler.d.cts.map +1 -0
- package/dist/runtime/endpoints/node-fetch-handler.d.mts +11 -0
- package/dist/runtime/endpoints/node-fetch-handler.d.mts.map +1 -0
- package/dist/runtime/endpoints/node-fetch-handler.mjs +73 -0
- package/dist/runtime/endpoints/node-fetch-handler.mjs.map +1 -0
- package/dist/runtime/endpoints/node.cjs +16 -0
- package/dist/runtime/endpoints/node.cjs.map +1 -0
- package/dist/runtime/endpoints/node.d.cts +104 -0
- package/dist/runtime/endpoints/node.d.cts.map +1 -0
- package/dist/runtime/endpoints/node.d.mts +104 -0
- package/dist/runtime/endpoints/node.d.mts.map +1 -0
- package/dist/runtime/endpoints/node.mjs +16 -0
- package/dist/runtime/endpoints/node.mjs.map +1 -0
- package/dist/runtime/endpoints/single-route-helpers.cjs +130 -0
- package/dist/runtime/endpoints/single-route-helpers.cjs.map +1 -0
- package/dist/runtime/endpoints/single-route-helpers.mjs +125 -0
- package/dist/runtime/endpoints/single-route-helpers.mjs.map +1 -0
- package/dist/runtime/generative-ui/generative-ui-middleware.cjs +393 -0
- package/dist/runtime/generative-ui/generative-ui-middleware.cjs.map +1 -0
- package/dist/runtime/generative-ui/generative-ui-middleware.d.cts +20 -0
- package/dist/runtime/generative-ui/generative-ui-middleware.d.cts.map +1 -0
- package/dist/runtime/generative-ui/generative-ui-middleware.d.mts +20 -0
- package/dist/runtime/generative-ui/generative-ui-middleware.d.mts.map +1 -0
- package/dist/runtime/generative-ui/generative-ui-middleware.mjs +392 -0
- package/dist/runtime/generative-ui/generative-ui-middleware.mjs.map +1 -0
- package/dist/runtime/generative-ui/index.d.cts +2 -0
- package/dist/runtime/generative-ui/index.d.mts +2 -0
- package/dist/runtime/generative-ui/surface-writer.cjs +85 -0
- package/dist/runtime/generative-ui/surface-writer.cjs.map +1 -0
- package/dist/runtime/generative-ui/surface-writer.d.cts +32 -0
- package/dist/runtime/generative-ui/surface-writer.d.cts.map +1 -0
- package/dist/runtime/generative-ui/surface-writer.d.mts +32 -0
- package/dist/runtime/generative-ui/surface-writer.d.mts.map +1 -0
- package/dist/runtime/generative-ui/surface-writer.mjs +84 -0
- package/dist/runtime/generative-ui/surface-writer.mjs.map +1 -0
- package/dist/runtime/handlers/get-runtime-info.cjs +140 -0
- package/dist/runtime/handlers/get-runtime-info.cjs.map +1 -0
- package/dist/runtime/handlers/get-runtime-info.mjs +140 -0
- package/dist/runtime/handlers/get-runtime-info.mjs.map +1 -0
- package/dist/runtime/handlers/handle-connect.cjs +62 -0
- package/dist/runtime/handlers/handle-connect.cjs.map +1 -0
- package/dist/runtime/handlers/handle-connect.mjs +62 -0
- package/dist/runtime/handlers/handle-connect.mjs.map +1 -0
- package/dist/runtime/handlers/handle-debug-events.cjs +33 -0
- package/dist/runtime/handlers/handle-debug-events.cjs.map +1 -0
- package/dist/runtime/handlers/handle-debug-events.mjs +33 -0
- package/dist/runtime/handlers/handle-debug-events.mjs.map +1 -0
- package/dist/runtime/handlers/handle-inspector-learning.cjs +56 -0
- package/dist/runtime/handlers/handle-inspector-learning.cjs.map +1 -0
- package/dist/runtime/handlers/handle-inspector-learning.mjs +55 -0
- package/dist/runtime/handlers/handle-inspector-learning.mjs.map +1 -0
- package/dist/runtime/handlers/handle-inspector-metadata.cjs +36 -0
- package/dist/runtime/handlers/handle-inspector-metadata.cjs.map +1 -0
- package/dist/runtime/handlers/handle-inspector-metadata.mjs +35 -0
- package/dist/runtime/handlers/handle-inspector-metadata.mjs.map +1 -0
- package/dist/runtime/handlers/handle-run.cjs +111 -0
- package/dist/runtime/handlers/handle-run.cjs.map +1 -0
- package/dist/runtime/handlers/handle-run.mjs +110 -0
- package/dist/runtime/handlers/handle-run.mjs.map +1 -0
- package/dist/runtime/handlers/handle-stop.cjs +102 -0
- package/dist/runtime/handlers/handle-stop.cjs.map +1 -0
- package/dist/runtime/handlers/handle-stop.mjs +101 -0
- package/dist/runtime/handlers/handle-stop.mjs.map +1 -0
- package/dist/runtime/handlers/handle-suggest.cjs +83 -0
- package/dist/runtime/handlers/handle-suggest.cjs.map +1 -0
- package/dist/runtime/handlers/handle-suggest.mjs +82 -0
- package/dist/runtime/handlers/handle-suggest.mjs.map +1 -0
- package/dist/runtime/handlers/handle-trajectory-connect.cjs +40 -0
- package/dist/runtime/handlers/handle-trajectory-connect.cjs.map +1 -0
- package/dist/runtime/handlers/handle-trajectory-connect.mjs +39 -0
- package/dist/runtime/handlers/handle-trajectory-connect.mjs.map +1 -0
- package/dist/runtime/handlers/handle-transcribe.cjs +112 -0
- package/dist/runtime/handlers/handle-transcribe.cjs.map +1 -0
- package/dist/runtime/handlers/handle-transcribe.mjs +111 -0
- package/dist/runtime/handlers/handle-transcribe.mjs.map +1 -0
- package/dist/runtime/handlers/header-utils.cjs +185 -0
- package/dist/runtime/handlers/header-utils.cjs.map +1 -0
- package/dist/runtime/handlers/header-utils.d.cts +53 -0
- package/dist/runtime/handlers/header-utils.d.cts.map +1 -0
- package/dist/runtime/handlers/header-utils.d.mts +53 -0
- package/dist/runtime/handlers/header-utils.d.mts.map +1 -0
- package/dist/runtime/handlers/header-utils.mjs +183 -0
- package/dist/runtime/handlers/header-utils.mjs.map +1 -0
- package/dist/runtime/handlers/intelligence/annotate.cjs +83 -0
- package/dist/runtime/handlers/intelligence/annotate.cjs.map +1 -0
- package/dist/runtime/handlers/intelligence/annotate.mjs +82 -0
- package/dist/runtime/handlers/intelligence/annotate.mjs.map +1 -0
- package/dist/runtime/handlers/intelligence/connect.cjs +68 -0
- package/dist/runtime/handlers/intelligence/connect.cjs.map +1 -0
- package/dist/runtime/handlers/intelligence/connect.mjs +68 -0
- package/dist/runtime/handlers/intelligence/connect.mjs.map +1 -0
- package/dist/runtime/handlers/intelligence/memories.cjs +260 -0
- package/dist/runtime/handlers/intelligence/memories.cjs.map +1 -0
- package/dist/runtime/handlers/intelligence/memories.mjs +254 -0
- package/dist/runtime/handlers/intelligence/memories.mjs.map +1 -0
- package/dist/runtime/handlers/intelligence/run.cjs +283 -0
- package/dist/runtime/handlers/intelligence/run.cjs.map +1 -0
- package/dist/runtime/handlers/intelligence/run.mjs +282 -0
- package/dist/runtime/handlers/intelligence/run.mjs.map +1 -0
- package/dist/runtime/handlers/intelligence/thread-names.cjs +172 -0
- package/dist/runtime/handlers/intelligence/thread-names.cjs.map +1 -0
- package/dist/runtime/handlers/intelligence/thread-names.mjs +171 -0
- package/dist/runtime/handlers/intelligence/thread-names.mjs.map +1 -0
- package/dist/runtime/handlers/intelligence/threads.cjs +399 -0
- package/dist/runtime/handlers/intelligence/threads.cjs.map +1 -0
- package/dist/runtime/handlers/intelligence/threads.mjs +390 -0
- package/dist/runtime/handlers/intelligence/threads.mjs.map +1 -0
- package/dist/runtime/handlers/shared/agent-utils.cjs +267 -0
- package/dist/runtime/handlers/shared/agent-utils.cjs.map +1 -0
- package/dist/runtime/handlers/shared/agent-utils.mjs +262 -0
- package/dist/runtime/handlers/shared/agent-utils.mjs.map +1 -0
- package/dist/runtime/handlers/shared/cloud-telemetry.cjs +30 -0
- package/dist/runtime/handlers/shared/cloud-telemetry.cjs.map +1 -0
- package/dist/runtime/handlers/shared/cloud-telemetry.mjs +29 -0
- package/dist/runtime/handlers/shared/cloud-telemetry.mjs.map +1 -0
- package/dist/runtime/handlers/shared/describe-endpoint.cjs +25 -0
- package/dist/runtime/handlers/shared/describe-endpoint.cjs.map +1 -0
- package/dist/runtime/handlers/shared/describe-endpoint.mjs +24 -0
- package/dist/runtime/handlers/shared/describe-endpoint.mjs.map +1 -0
- package/dist/runtime/handlers/shared/intelligence-utils.cjs +24 -0
- package/dist/runtime/handlers/shared/intelligence-utils.cjs.map +1 -0
- package/dist/runtime/handlers/shared/intelligence-utils.mjs +23 -0
- package/dist/runtime/handlers/shared/intelligence-utils.mjs.map +1 -0
- package/dist/runtime/handlers/shared/json-response.cjs +14 -0
- package/dist/runtime/handlers/shared/json-response.cjs.map +1 -0
- package/dist/runtime/handlers/shared/json-response.mjs +12 -0
- package/dist/runtime/handlers/shared/json-response.mjs.map +1 -0
- package/dist/runtime/handlers/shared/mcp-apps-servers.cjs +22 -0
- package/dist/runtime/handlers/shared/mcp-apps-servers.cjs.map +1 -0
- package/dist/runtime/handlers/shared/mcp-apps-servers.mjs +22 -0
- package/dist/runtime/handlers/shared/mcp-apps-servers.mjs.map +1 -0
- package/dist/runtime/handlers/shared/memory-policy.cjs +78 -0
- package/dist/runtime/handlers/shared/memory-policy.cjs.map +1 -0
- package/dist/runtime/handlers/shared/memory-policy.mjs +77 -0
- package/dist/runtime/handlers/shared/memory-policy.mjs.map +1 -0
- package/dist/runtime/handlers/shared/platform-error.cjs +39 -0
- package/dist/runtime/handlers/shared/platform-error.cjs.map +1 -0
- package/dist/runtime/handlers/shared/platform-error.mjs +39 -0
- package/dist/runtime/handlers/shared/platform-error.mjs.map +1 -0
- package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs +50 -0
- package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -0
- package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs +49 -0
- package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -0
- package/dist/runtime/handlers/shared/sse-keep-alive.cjs +68 -0
- package/dist/runtime/handlers/shared/sse-keep-alive.cjs.map +1 -0
- package/dist/runtime/handlers/shared/sse-keep-alive.mjs +66 -0
- package/dist/runtime/handlers/shared/sse-keep-alive.mjs.map +1 -0
- package/dist/runtime/handlers/shared/sse-response.cjs +237 -0
- package/dist/runtime/handlers/shared/sse-response.cjs.map +1 -0
- package/dist/runtime/handlers/shared/sse-response.mjs +236 -0
- package/dist/runtime/handlers/shared/sse-response.mjs.map +1 -0
- package/dist/runtime/handlers/shared/thread-access.cjs +137 -0
- package/dist/runtime/handlers/shared/thread-access.cjs.map +1 -0
- package/dist/runtime/handlers/shared/thread-access.d.cts +28 -0
- package/dist/runtime/handlers/shared/thread-access.d.cts.map +1 -0
- package/dist/runtime/handlers/shared/thread-access.d.mts +28 -0
- package/dist/runtime/handlers/shared/thread-access.d.mts.map +1 -0
- package/dist/runtime/handlers/shared/thread-access.mjs +132 -0
- package/dist/runtime/handlers/shared/thread-access.mjs.map +1 -0
- package/dist/runtime/handlers/sse/connect.cjs +23 -0
- package/dist/runtime/handlers/sse/connect.cjs.map +1 -0
- package/dist/runtime/handlers/sse/connect.mjs +23 -0
- package/dist/runtime/handlers/sse/connect.mjs.map +1 -0
- package/dist/runtime/handlers/sse/run.cjs +44 -0
- package/dist/runtime/handlers/sse/run.cjs.map +1 -0
- package/dist/runtime/handlers/sse/run.mjs +44 -0
- package/dist/runtime/handlers/sse/run.mjs.map +1 -0
- package/dist/runtime/index.d.cts +29 -0
- package/dist/runtime/index.d.cts.map +1 -0
- package/dist/runtime/index.d.mts +29 -0
- package/dist/runtime/index.d.mts.map +1 -0
- package/dist/runtime/intelligence-platform/client.cjs +1338 -0
- package/dist/runtime/intelligence-platform/client.cjs.map +1 -0
- package/dist/runtime/intelligence-platform/client.d.cts +824 -0
- package/dist/runtime/intelligence-platform/client.d.cts.map +1 -0
- package/dist/runtime/intelligence-platform/client.d.mts +824 -0
- package/dist/runtime/intelligence-platform/client.d.mts.map +1 -0
- package/dist/runtime/intelligence-platform/client.mjs +1334 -0
- package/dist/runtime/intelligence-platform/client.mjs.map +1 -0
- package/dist/runtime/intelligence-platform/experimental.d.cts +26 -0
- package/dist/runtime/intelligence-platform/experimental.d.cts.map +1 -0
- package/dist/runtime/intelligence-platform/experimental.d.mts +26 -0
- package/dist/runtime/intelligence-platform/experimental.d.mts.map +1 -0
- package/dist/runtime/intelligence-platform/index.d.cts +3 -0
- package/dist/runtime/intelligence-platform/index.d.mts +3 -0
- package/dist/runtime/intelligence-platform/learned-skills.cjs +95 -0
- package/dist/runtime/intelligence-platform/learned-skills.cjs.map +1 -0
- package/dist/runtime/intelligence-platform/learned-skills.d.cts +43 -0
- package/dist/runtime/intelligence-platform/learned-skills.d.cts.map +1 -0
- package/dist/runtime/intelligence-platform/learned-skills.d.mts +43 -0
- package/dist/runtime/intelligence-platform/learned-skills.d.mts.map +1 -0
- package/dist/runtime/intelligence-platform/learned-skills.mjs +92 -0
- package/dist/runtime/intelligence-platform/learned-skills.mjs.map +1 -0
- package/dist/runtime/intelligence-platform/learning-management.cjs +203 -0
- package/dist/runtime/intelligence-platform/learning-management.cjs.map +1 -0
- package/dist/runtime/intelligence-platform/learning-management.d.cts +111 -0
- package/dist/runtime/intelligence-platform/learning-management.d.cts.map +1 -0
- package/dist/runtime/intelligence-platform/learning-management.d.mts +111 -0
- package/dist/runtime/intelligence-platform/learning-management.d.mts.map +1 -0
- package/dist/runtime/intelligence-platform/learning-management.mjs +193 -0
- package/dist/runtime/intelligence-platform/learning-management.mjs.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/archive.cjs +131 -0
- package/dist/runtime/intelligence-platform/skill-registry/archive.cjs.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts +10 -0
- package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts +10 -0
- package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/archive.mjs +127 -0
- package/dist/runtime/intelligence-platform/skill-registry/archive.mjs.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/config.cjs +65 -0
- package/dist/runtime/intelligence-platform/skill-registry/config.cjs.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/config.d.cts +47 -0
- package/dist/runtime/intelligence-platform/skill-registry/config.d.cts.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/config.d.mts +47 -0
- package/dist/runtime/intelligence-platform/skill-registry/config.d.mts.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/config.mjs +65 -0
- package/dist/runtime/intelligence-platform/skill-registry/config.mjs.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/errors.cjs +10 -0
- package/dist/runtime/intelligence-platform/skill-registry/errors.cjs.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/errors.d.cts +7 -0
- package/dist/runtime/intelligence-platform/skill-registry/errors.d.cts.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/errors.d.mts +7 -0
- package/dist/runtime/intelligence-platform/skill-registry/errors.d.mts.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/errors.mjs +10 -0
- package/dist/runtime/intelligence-platform/skill-registry/errors.mjs.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/index.d.cts +7 -0
- package/dist/runtime/intelligence-platform/skill-registry/index.d.mts +7 -0
- package/dist/runtime/intelligence-platform/skill-registry/registry.cjs +247 -0
- package/dist/runtime/intelligence-platform/skill-registry/registry.cjs.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/registry.d.cts +36 -0
- package/dist/runtime/intelligence-platform/skill-registry/registry.d.cts.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/registry.d.mts +36 -0
- package/dist/runtime/intelligence-platform/skill-registry/registry.d.mts.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/registry.mjs +246 -0
- package/dist/runtime/intelligence-platform/skill-registry/registry.mjs.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/skill-content.cjs +41 -0
- package/dist/runtime/intelligence-platform/skill-registry/skill-content.cjs.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/skill-content.d.cts +12 -0
- package/dist/runtime/intelligence-platform/skill-registry/skill-content.d.cts.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/skill-content.d.mts +12 -0
- package/dist/runtime/intelligence-platform/skill-registry/skill-content.d.mts.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/skill-content.mjs +38 -0
- package/dist/runtime/intelligence-platform/skill-registry/skill-content.mjs.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/snapshot.cjs +92 -0
- package/dist/runtime/intelligence-platform/skill-registry/snapshot.cjs.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/snapshot.d.cts +27 -0
- package/dist/runtime/intelligence-platform/skill-registry/snapshot.d.cts.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/snapshot.d.mts +27 -0
- package/dist/runtime/intelligence-platform/skill-registry/snapshot.d.mts.map +1 -0
- package/dist/runtime/intelligence-platform/skill-registry/snapshot.mjs +91 -0
- package/dist/runtime/intelligence-platform/skill-registry/snapshot.mjs.map +1 -0
- package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs +142 -0
- package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs.map +1 -0
- package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs +141 -0
- package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs.map +1 -0
- package/dist/runtime/intelligence-platform/trajectories.cjs +95 -0
- package/dist/runtime/intelligence-platform/trajectories.cjs.map +1 -0
- package/dist/runtime/intelligence-platform/trajectories.d.cts +11 -0
- package/dist/runtime/intelligence-platform/trajectories.d.cts.map +1 -0
- package/dist/runtime/intelligence-platform/trajectories.d.mts +11 -0
- package/dist/runtime/intelligence-platform/trajectories.d.mts.map +1 -0
- package/dist/runtime/intelligence-platform/trajectories.mjs +91 -0
- package/dist/runtime/intelligence-platform/trajectories.mjs.map +1 -0
- package/dist/runtime/node.d.cts +2 -0
- package/dist/runtime/node.d.mts +2 -0
- package/dist/runtime/runner/agent-runner.cjs +82 -0
- package/dist/runtime/runner/agent-runner.cjs.map +1 -0
- package/dist/runtime/runner/agent-runner.d.cts +151 -0
- package/dist/runtime/runner/agent-runner.d.cts.map +1 -0
- package/dist/runtime/runner/agent-runner.d.mts +151 -0
- package/dist/runtime/runner/agent-runner.d.mts.map +1 -0
- package/dist/runtime/runner/agent-runner.mjs +73 -0
- package/dist/runtime/runner/agent-runner.mjs.map +1 -0
- package/dist/runtime/runner/in-memory.cjs +741 -0
- package/dist/runtime/runner/in-memory.cjs.map +1 -0
- package/dist/runtime/runner/in-memory.d.cts +427 -0
- package/dist/runtime/runner/in-memory.d.cts.map +1 -0
- package/dist/runtime/runner/in-memory.d.mts +427 -0
- package/dist/runtime/runner/in-memory.d.mts.map +1 -0
- package/dist/runtime/runner/in-memory.mjs +734 -0
- package/dist/runtime/runner/in-memory.mjs.map +1 -0
- package/dist/runtime/runner/index.d.cts +5 -0
- package/dist/runtime/runner/index.d.mts +5 -0
- package/dist/runtime/runner/index.mjs +6 -0
- package/dist/runtime/runner/intelligence.cjs +617 -0
- package/dist/runtime/runner/intelligence.cjs.map +1 -0
- package/dist/runtime/runner/intelligence.d.cts +104 -0
- package/dist/runtime/runner/intelligence.d.cts.map +1 -0
- package/dist/runtime/runner/intelligence.d.mts +104 -0
- package/dist/runtime/runner/intelligence.d.mts.map +1 -0
- package/dist/runtime/runner/intelligence.mjs +616 -0
- package/dist/runtime/runner/intelligence.mjs.map +1 -0
- package/dist/runtime/telemetry/disclosure.cjs +25 -0
- package/dist/runtime/telemetry/disclosure.cjs.map +1 -0
- package/dist/runtime/telemetry/disclosure.mjs +24 -0
- package/dist/runtime/telemetry/disclosure.mjs.map +1 -0
- package/dist/runtime/telemetry/events.d.cts +66 -0
- package/dist/runtime/telemetry/events.d.cts.map +1 -0
- package/dist/runtime/telemetry/events.d.mts +66 -0
- package/dist/runtime/telemetry/events.d.mts.map +1 -0
- package/dist/runtime/telemetry/instance-created.cjs +34 -0
- package/dist/runtime/telemetry/instance-created.cjs.map +1 -0
- package/dist/runtime/telemetry/instance-created.mjs +34 -0
- package/dist/runtime/telemetry/instance-created.mjs.map +1 -0
- package/dist/runtime/telemetry/telemetry-client.cjs +108 -0
- package/dist/runtime/telemetry/telemetry-client.cjs.map +1 -0
- package/dist/runtime/telemetry/telemetry-client.d.cts +10 -0
- package/dist/runtime/telemetry/telemetry-client.d.cts.map +1 -0
- package/dist/runtime/telemetry/telemetry-client.d.mts +10 -0
- package/dist/runtime/telemetry/telemetry-client.d.mts.map +1 -0
- package/dist/runtime/telemetry/telemetry-client.mjs +107 -0
- package/dist/runtime/telemetry/telemetry-client.mjs.map +1 -0
- package/dist/runtime/telemetry/telemetry-identity.cjs +12 -0
- package/dist/runtime/telemetry/telemetry-identity.cjs.map +1 -0
- package/dist/runtime/telemetry/telemetry-identity.mjs +11 -0
- package/dist/runtime/telemetry/telemetry-identity.mjs.map +1 -0
- package/dist/runtime/transcription-service/transcription-service.cjs +7 -0
- package/dist/runtime/transcription-service/transcription-service.cjs.map +1 -0
- package/dist/runtime/transcription-service/transcription-service.d.cts +14 -0
- package/dist/runtime/transcription-service/transcription-service.d.cts.map +1 -0
- package/dist/runtime/transcription-service/transcription-service.d.mts +14 -0
- package/dist/runtime/transcription-service/transcription-service.d.mts.map +1 -0
- package/dist/runtime/transcription-service/transcription-service.mjs +6 -0
- package/dist/runtime/transcription-service/transcription-service.mjs.map +1 -0
- package/package.json +104 -105
- package/.eslintrc.js +0 -7
- package/CHANGELOG.md +0 -2920
- package/__snapshots__/schema/schema.graphql +0 -371
- package/dist/index.d.ts +0 -1494
- package/dist/index.js +0 -5641
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/langgraph.d.ts +0 -284
- package/dist/langgraph.js +0 -211
- package/dist/langgraph.js.map +0 -1
- package/dist/langgraph.mjs +0 -206
- package/dist/langgraph.mjs.map +0 -1
- package/dist/v2/index.d.ts +0 -2
- package/dist/v2/index.js +0 -22
- package/dist/v2/index.js.map +0 -1
- package/dist/v2/index.mjs +0 -5
- package/dist/v2/index.mjs.map +0 -1
- package/jest.config.js +0 -10
- package/scripts/generate-gql-schema.ts +0 -13
- package/src/agents/langgraph/event-source.ts +0 -329
- package/src/agents/langgraph/events.ts +0 -377
- 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 -1263
- package/src/graphql/message-conversion/agui-to-gql.ts +0 -333
- package/src/graphql/message-conversion/gql-to-agui.test.ts +0 -1580
- package/src/graphql/message-conversion/gql-to-agui.ts +0 -278
- package/src/graphql/message-conversion/index.ts +0 -2
- package/src/graphql/message-conversion/roundtrip-conversion.test.ts +0 -526
- package/src/graphql/resolvers/copilot.resolver.ts +0 -708
- package/src/graphql/resolvers/state.resolver.ts +0 -27
- 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 -176
- package/src/graphql/types/copilot-response.type.ts +0 -138
- 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 -42
- package/src/graphql/types/meta-events.type.ts +0 -71
- package/src/graphql/types/response-status.type.ts +0 -66
- package/src/index.ts +0 -4
- package/src/langgraph.ts +0 -1
- package/src/lib/cloud/index.ts +0 -4
- package/src/lib/error-messages.ts +0 -200
- package/src/lib/index.ts +0 -52
- package/src/lib/integrations/index.ts +0 -6
- package/src/lib/integrations/nest/index.ts +0 -14
- package/src/lib/integrations/nextjs/app-router.ts +0 -38
- package/src/lib/integrations/nextjs/pages-router.ts +0 -39
- package/src/lib/integrations/node-express/index.ts +0 -14
- package/src/lib/integrations/node-http/index.ts +0 -143
- package/src/lib/integrations/node-http/request-handler.ts +0 -111
- package/src/lib/integrations/shared.ts +0 -161
- package/src/lib/logger.ts +0 -28
- package/src/lib/observability.ts +0 -160
- package/src/lib/runtime/__tests__/copilot-runtime-error.test.ts +0 -169
- package/src/lib/runtime/__tests__/mcp-tools-utils.test.ts +0 -464
- package/src/lib/runtime/agent-integrations/langgraph/agent.ts +0 -209
- package/src/lib/runtime/agent-integrations/langgraph/consts.ts +0 -34
- package/src/lib/runtime/agent-integrations/langgraph/index.ts +0 -2
- package/src/lib/runtime/copilot-runtime.ts +0 -710
- package/src/lib/runtime/mcp-tools-utils.ts +0 -254
- package/src/lib/runtime/retry-utils.ts +0 -96
- package/src/lib/runtime/telemetry-agent-runner.ts +0 -139
- package/src/lib/runtime/types.ts +0 -49
- package/src/lib/runtime/utils.ts +0 -87
- package/src/lib/streaming.ts +0 -202
- package/src/lib/telemetry-client.ts +0 -64
- package/src/service-adapters/anthropic/anthropic-adapter.ts +0 -452
- package/src/service-adapters/anthropic/utils.ts +0 -152
- package/src/service-adapters/bedrock/bedrock-adapter.ts +0 -73
- package/src/service-adapters/conversion.ts +0 -67
- package/src/service-adapters/empty/empty-adapter.ts +0 -38
- package/src/service-adapters/events.ts +0 -294
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +0 -84
- package/src/service-adapters/google/google-genai-adapter.test.ts +0 -104
- package/src/service-adapters/google/google-genai-adapter.ts +0 -88
- package/src/service-adapters/groq/groq-adapter.ts +0 -203
- package/src/service-adapters/index.ts +0 -18
- package/src/service-adapters/langchain/langchain-adapter.ts +0 -111
- package/src/service-adapters/langchain/langserve.ts +0 -88
- package/src/service-adapters/langchain/types.ts +0 -14
- package/src/service-adapters/langchain/utils.ts +0 -313
- package/src/service-adapters/openai/openai-adapter.ts +0 -283
- package/src/service-adapters/openai/openai-assistant-adapter.ts +0 -344
- package/src/service-adapters/openai/utils.ts +0 -199
- package/src/service-adapters/service-adapter.ts +0 -41
- package/src/service-adapters/shared/error-utils.ts +0 -61
- package/src/service-adapters/shared/index.ts +0 -1
- package/src/service-adapters/unify/unify-adapter.ts +0 -151
- package/src/utils/failed-response-status-reasons.ts +0 -70
- package/src/utils/index.ts +0 -1
- package/src/v2/index.ts +0 -3
- package/tests/global.d.ts +0 -13
- package/tests/service-adapters/anthropic/allowlist-approach.test.ts +0 -226
- package/tests/service-adapters/anthropic/anthropic-adapter.test.ts +0 -389
- package/tests/service-adapters/openai/allowlist-approach.test.ts +0 -238
- package/tests/service-adapters/openai/openai-adapter.test.ts +0 -301
- package/tests/setup.jest.ts +0 -21
- package/tests/tsconfig.json +0 -10
- package/tsconfig.json +0 -13
- package/tsup.config.ts +0 -20
- package/typedoc.json +0 -4
|
@@ -0,0 +1,1338 @@
|
|
|
1
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
const require_learning_management = require('./learning-management.cjs');
|
|
3
|
+
const require_learning = require('../core/learning.cjs');
|
|
4
|
+
const require_trajectories = require('./trajectories.cjs');
|
|
5
|
+
const require_learned_skills = require('./learned-skills.cjs');
|
|
6
|
+
let _copilotkit_shared = require("@copilotkit/shared");
|
|
7
|
+
let zod = require("zod");
|
|
8
|
+
let crypto = require("crypto");
|
|
9
|
+
|
|
10
|
+
//#region src/runtime/intelligence-platform/client.ts
|
|
11
|
+
/** Let a confirmed HTTP denial survive an error body that never completes. */
|
|
12
|
+
async function learnedSkillsErrorBody(response, signal) {
|
|
13
|
+
if (!signal) return response.json();
|
|
14
|
+
let onAbort;
|
|
15
|
+
try {
|
|
16
|
+
return await new Promise((resolve, reject) => {
|
|
17
|
+
onAbort = () => reject(signal.reason);
|
|
18
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
19
|
+
if (signal.aborted) onAbort();
|
|
20
|
+
else response.json().then(resolve, reject);
|
|
21
|
+
});
|
|
22
|
+
} finally {
|
|
23
|
+
if (onAbort) signal.removeEventListener("abort", onAbort);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const RUNTIME_ENTITLEMENTS_REQUEST_TIMEOUT_MS = 1500;
|
|
27
|
+
const RUNTIME_ENTITLEMENTS_SUCCESS_TTL_MS = 3e4;
|
|
28
|
+
const RUNTIME_ENTITLEMENTS_NEGATIVE_TTL_MS = 5e3;
|
|
29
|
+
/** Whether a response grants Runtime access and therefore cannot be served stale. */
|
|
30
|
+
function grantsRuntimeAccess(response) {
|
|
31
|
+
return response.status === "ready" && response.entitlement.active;
|
|
32
|
+
}
|
|
33
|
+
/** Whether an HTTP status can recover without changing Runtime configuration. */
|
|
34
|
+
function isRetryableRuntimeEntitlementStatus(status) {
|
|
35
|
+
return status === 408 || status === 425 || status === 429 || status >= 500;
|
|
36
|
+
}
|
|
37
|
+
const runtimeEntitlementSchema = zod.z.object({
|
|
38
|
+
active: zod.z.boolean(),
|
|
39
|
+
source: zod.z.enum([
|
|
40
|
+
"managedOrgSubscription",
|
|
41
|
+
"selfHostedDeploymentLicense",
|
|
42
|
+
"awsMarketplaceDeploymentLicense"
|
|
43
|
+
]),
|
|
44
|
+
features: zod.z.record(zod.z.string(), zod.z.boolean()),
|
|
45
|
+
limits: zod.z.record(zod.z.string(), zod.z.number()),
|
|
46
|
+
planCode: zod.z.string().optional(),
|
|
47
|
+
entitlementSource: zod.z.string().optional()
|
|
48
|
+
}).strict();
|
|
49
|
+
const runtimeEntitlementResponseSchema = zod.z.discriminatedUnion("status", [zod.z.object({
|
|
50
|
+
status: zod.z.literal("ready"),
|
|
51
|
+
entitlement: runtimeEntitlementSchema
|
|
52
|
+
}).strict(), zod.z.object({
|
|
53
|
+
status: zod.z.enum([
|
|
54
|
+
"degraded",
|
|
55
|
+
"misconfigured",
|
|
56
|
+
"unavailable"
|
|
57
|
+
]),
|
|
58
|
+
error: zod.z.object({
|
|
59
|
+
code: zod.z.string(),
|
|
60
|
+
message: zod.z.string(),
|
|
61
|
+
retryable: zod.z.boolean(),
|
|
62
|
+
requestId: zod.z.string().optional(),
|
|
63
|
+
traceId: zod.z.string().optional()
|
|
64
|
+
}).strict()
|
|
65
|
+
}).strict()]);
|
|
66
|
+
const legacyRuntimeEntitlementTransportSchema = runtimeEntitlementSchema.extend({ organizationId: zod.z.string() });
|
|
67
|
+
/** Check the published App API response union without widening its type. */
|
|
68
|
+
function isPublishedRuntimeEntitlementResponse(value) {
|
|
69
|
+
return runtimeEntitlementResponseSchema.safeParse(value).success;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Validate the published App API response union, with flat-response support
|
|
73
|
+
* during mixed-version rollouts.
|
|
74
|
+
*/
|
|
75
|
+
function normalizeRuntimeEntitlementTransport(value) {
|
|
76
|
+
if (isPublishedRuntimeEntitlementResponse(value)) return value;
|
|
77
|
+
const legacyResponse = legacyRuntimeEntitlementTransportSchema.safeParse(value);
|
|
78
|
+
if (!legacyResponse.success) return;
|
|
79
|
+
const transport = legacyResponse.data;
|
|
80
|
+
return {
|
|
81
|
+
status: "ready",
|
|
82
|
+
entitlement: {
|
|
83
|
+
active: transport.active,
|
|
84
|
+
source: transport.source,
|
|
85
|
+
features: transport.features,
|
|
86
|
+
limits: transport.limits,
|
|
87
|
+
...transport.planCode !== void 0 ? { planCode: transport.planCode } : {},
|
|
88
|
+
...transport.entitlementSource !== void 0 ? { entitlementSource: transport.entitlementSource } : {}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Header name carrying the per-call end-user identity that the CopilotKit
|
|
94
|
+
* Intelligence `/mcp` endpoint requires. Internal CopilotKit machinery —
|
|
95
|
+
* `attachIntelligenceEnterpriseLearning` resolves the user via `identifyUser`
|
|
96
|
+
* and bakes this header onto the `MCPMiddleware`'s transport config, so every
|
|
97
|
+
* outbound MCP request stamps `X-Cpki-User-Id: <userId>`. Not part of the
|
|
98
|
+
* public user API.
|
|
99
|
+
*
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
const INTELLIGENCE_USER_ID_HEADER = "x-cpki-user-id";
|
|
103
|
+
/** Immutable user/project Memory grant forwarded to Intelligence. */
|
|
104
|
+
const INTELLIGENCE_MEMORY_GRANT_HEADER = "x-cpki-memory-grant";
|
|
105
|
+
const memoryRequestHeaders = (userId, grant) => ({
|
|
106
|
+
[INTELLIGENCE_USER_ID_HEADER]: userId,
|
|
107
|
+
...grant ? { [INTELLIGENCE_MEMORY_GRANT_HEADER]: JSON.stringify(grant) } : {}
|
|
108
|
+
});
|
|
109
|
+
/**
|
|
110
|
+
* REST base URL of cloud-hosted CopilotKit Intelligence — the default
|
|
111
|
+
* when {@link CopilotKitIntelligenceConfig.apiUrl} is omitted.
|
|
112
|
+
*/
|
|
113
|
+
const MANAGED_INTELLIGENCE_API_URL = "https://api.intelligence.copilotkit.ai";
|
|
114
|
+
/**
|
|
115
|
+
* Websocket base URL of cloud-hosted CopilotKit Intelligence — the
|
|
116
|
+
* default when {@link CopilotKitIntelligenceConfig.wsUrl} is omitted.
|
|
117
|
+
*
|
|
118
|
+
* A different host from {@link MANAGED_INTELLIGENCE_API_URL}: the API and
|
|
119
|
+
* realtime planes are deployed separately.
|
|
120
|
+
*/
|
|
121
|
+
const MANAGED_INTELLIGENCE_WS_URL = "wss://realtime.intelligence.copilotkit.ai";
|
|
122
|
+
/** Maximum time spent on the optional Inspector metadata provider request. */
|
|
123
|
+
const INSPECTOR_METADATA_REQUEST_TIMEOUT_MS = 5e3;
|
|
124
|
+
const INSPECTOR_LEARNING_REQUEST_TIMEOUT_MS = 5e3;
|
|
125
|
+
/** A 404 the caller expects: a thread lookup made before the thread exists. */
|
|
126
|
+
const NOT_FOUND = new Set([404]);
|
|
127
|
+
/** A 409 the caller expects: another request created the thread first. */
|
|
128
|
+
const CONFLICT = new Set([409]);
|
|
129
|
+
/**
|
|
130
|
+
* Error thrown when a CopilotKit Intelligence HTTP request returns a non-2xx
|
|
131
|
+
* status. Carries the HTTP {@link status} code so callers can branch on
|
|
132
|
+
* specific failures (e.g. 404 for "not found", 409 for "conflict") without
|
|
133
|
+
* parsing the error message string.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* try {
|
|
138
|
+
* await intelligence.getThread({ threadId, userId });
|
|
139
|
+
* } catch (error) {
|
|
140
|
+
* if (error instanceof PlatformRequestError && error.status === 404) {
|
|
141
|
+
* // thread does not exist yet
|
|
142
|
+
* }
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
var PlatformRequestError = class extends Error {
|
|
147
|
+
constructor(message, status, retryable, code) {
|
|
148
|
+
super(message);
|
|
149
|
+
this.status = status;
|
|
150
|
+
this.retryable = retryable;
|
|
151
|
+
this.code = code;
|
|
152
|
+
this.name = "PlatformRequestError";
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Read the platform's `retryable` hint from an error response body. The
|
|
157
|
+
* platform sends `{ error: { code, message, category, retryable } }`; anything
|
|
158
|
+
* else (non-JSON, proxies, older platforms) yields `undefined`.
|
|
159
|
+
*/
|
|
160
|
+
function readErrorBodyRetryable(text) {
|
|
161
|
+
if (!text) return void 0;
|
|
162
|
+
try {
|
|
163
|
+
const body = JSON.parse(text);
|
|
164
|
+
if (typeof body !== "object" || body === null) return void 0;
|
|
165
|
+
const error = body.error;
|
|
166
|
+
if (typeof error !== "object" || error === null) return void 0;
|
|
167
|
+
const retryable = error.retryable;
|
|
168
|
+
return typeof retryable === "boolean" ? retryable : void 0;
|
|
169
|
+
} catch {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/** Copy a public Runtime entitlement so callers cannot mutate cached authority. */
|
|
174
|
+
function cloneRuntimeEntitlementResponse(response) {
|
|
175
|
+
if (response.status === "ready") return {
|
|
176
|
+
status: "ready",
|
|
177
|
+
entitlement: {
|
|
178
|
+
...response.entitlement,
|
|
179
|
+
features: { ...response.entitlement.features },
|
|
180
|
+
limits: { ...response.entitlement.limits }
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
return {
|
|
184
|
+
status: response.status,
|
|
185
|
+
error: { ...response.error }
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/** Copy a cached Error while preserving its concrete type and own fields. */
|
|
189
|
+
function cloneRuntimeEntitlementError(error) {
|
|
190
|
+
if (!(error instanceof Error)) return error;
|
|
191
|
+
return Object.create(Object.getPrototypeOf(error), Object.getOwnPropertyDescriptors(error));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Client for the CopilotKit Intelligence REST API.
|
|
195
|
+
*
|
|
196
|
+
* Construct the client once and pass it to any consumers that need it
|
|
197
|
+
* (e.g. `CopilotRuntime`, `IntelligenceAgentRunner`):
|
|
198
|
+
*
|
|
199
|
+
* ```ts
|
|
200
|
+
* import { CopilotKitIntelligence, CopilotRuntime } from "@copilotkit/runtime";
|
|
201
|
+
*
|
|
202
|
+
* const intelligence = new CopilotKitIntelligence({
|
|
203
|
+
* apiKey: process.env.CPK_INTELLIGENCE_API_KEY!,
|
|
204
|
+
* });
|
|
205
|
+
*
|
|
206
|
+
* const runtime = new CopilotRuntime({
|
|
207
|
+
* agents,
|
|
208
|
+
* intelligence,
|
|
209
|
+
* });
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* `apiUrl` and `wsUrl` default to cloud-hosted CopilotKit Intelligence —
|
|
213
|
+
* `https://api.intelligence.copilotkit.ai` and
|
|
214
|
+
* `wss://realtime.intelligence.copilotkit.ai`. Those are the values for the
|
|
215
|
+
* managed service; leaving both unset is always correct against it.
|
|
216
|
+
*
|
|
217
|
+
* Override both together to target a non-production or future self-hosted
|
|
218
|
+
* deployment (the hosts below are placeholders — substitute your own):
|
|
219
|
+
*
|
|
220
|
+
* ```ts
|
|
221
|
+
* const intelligence = new CopilotKitIntelligence({
|
|
222
|
+
* apiUrl: "https://api.intelligence.example.com",
|
|
223
|
+
* wsUrl: "wss://realtime.intelligence.example.com",
|
|
224
|
+
* apiKey: process.env.CPK_INTELLIGENCE_API_KEY!,
|
|
225
|
+
* });
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
/**
|
|
229
|
+
* The thread events and state reads are scoped to one end user. A caller
|
|
230
|
+
* that omits `userId` (a JS caller, or one built against the earlier
|
|
231
|
+
* signature) would otherwise send the literal string "undefined" as the user.
|
|
232
|
+
*/
|
|
233
|
+
function requireThreadReadUserId(method, userId) {
|
|
234
|
+
if (typeof userId !== "string" || userId === "") throw new TypeError(`${method} requires a non-empty userId: the id identifyUser returned`);
|
|
235
|
+
}
|
|
236
|
+
var CopilotKitIntelligence = class {
|
|
237
|
+
#apiUrl;
|
|
238
|
+
#runnerWsUrl;
|
|
239
|
+
#clientWsUrl;
|
|
240
|
+
#channelsWsUrl;
|
|
241
|
+
#apiKey;
|
|
242
|
+
#enterpriseLearningEnabled;
|
|
243
|
+
#getLearningContainerId;
|
|
244
|
+
#getTrajectoryLearningContainerIds;
|
|
245
|
+
#runtimeEntitlementsCache;
|
|
246
|
+
#runtimeEntitlementsFailure;
|
|
247
|
+
#runtimeEntitlementsInFlight;
|
|
248
|
+
#threadCreatedListeners = /* @__PURE__ */ new Set();
|
|
249
|
+
#threadUpdatedListeners = /* @__PURE__ */ new Set();
|
|
250
|
+
#threadDeletedListeners = /* @__PURE__ */ new Set();
|
|
251
|
+
constructor(config) {
|
|
252
|
+
this.experimental = { learning: {
|
|
253
|
+
listLearningContainers: this.#listLearningContainers.bind(this),
|
|
254
|
+
getLearningContainer: this.#getLearningContainer.bind(this),
|
|
255
|
+
listLearningRuns: this.#listLearningRuns.bind(this),
|
|
256
|
+
startLearningRun: this.#startLearningRun.bind(this),
|
|
257
|
+
listLearningCandidates: this.#listLearningCandidates.bind(this),
|
|
258
|
+
getLearningCandidate: this.#getLearningCandidate.bind(this),
|
|
259
|
+
getLearningInsightEvidence: this.#getLearningInsightEvidence.bind(this),
|
|
260
|
+
reviewLearningCandidate: this.#reviewLearningCandidate.bind(this)
|
|
261
|
+
} };
|
|
262
|
+
if (config.getLearningContainerId !== void 0 && typeof config.getLearningContainerId !== "function") throw new Error("CopilotKitIntelligence `getLearningContainerId` must be a callback");
|
|
263
|
+
assertConfiguredApiKey(config.apiKey);
|
|
264
|
+
if (config.getTrajectoryLearningContainerIds !== void 0 && typeof config.getTrajectoryLearningContainerIds !== "function") throw new Error("CopilotKitIntelligence `getTrajectoryLearningContainerIds` must be a callback");
|
|
265
|
+
const configuredApiUrl = configuredUrl(config.apiUrl);
|
|
266
|
+
const configuredWsUrl = configuredUrl(config.wsUrl);
|
|
267
|
+
warnOnPartialHostOverride(configuredApiUrl, configuredWsUrl);
|
|
268
|
+
const intelligenceWsUrl = normalizeIntelligenceWsUrl(configuredWsUrl ?? MANAGED_INTELLIGENCE_WS_URL);
|
|
269
|
+
this.#apiUrl = (configuredApiUrl ?? MANAGED_INTELLIGENCE_API_URL).replace(/\/$/, "");
|
|
270
|
+
this.#runnerWsUrl = deriveRunnerWsUrl(intelligenceWsUrl);
|
|
271
|
+
this.#clientWsUrl = deriveClientWsUrl(intelligenceWsUrl);
|
|
272
|
+
this.#channelsWsUrl = deriveChannelsWsUrl(intelligenceWsUrl);
|
|
273
|
+
this.#apiKey = config.apiKey;
|
|
274
|
+
this.#enterpriseLearningEnabled = config.enableEnterpriseLearning ?? false;
|
|
275
|
+
this.#getLearningContainerId = config.getLearningContainerId;
|
|
276
|
+
this.#getTrajectoryLearningContainerIds = config.getTrajectoryLearningContainerIds;
|
|
277
|
+
if (config.onThreadCreated) this.onThreadCreated(config.onThreadCreated);
|
|
278
|
+
if (config.onThreadUpdated) this.onThreadUpdated(config.onThreadUpdated);
|
|
279
|
+
if (config.onThreadDeleted) this.onThreadDeleted(config.onThreadDeleted);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Register a listener invoked whenever a thread is created.
|
|
283
|
+
*
|
|
284
|
+
* Multiple listeners can be registered. Each call returns an unsubscribe
|
|
285
|
+
* function that removes the listener when called.
|
|
286
|
+
*
|
|
287
|
+
* @param callback - Receives the newly created {@link ThreadSummary}.
|
|
288
|
+
* @returns A function that removes this listener when called.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```ts
|
|
292
|
+
* const unsubscribe = intelligence.onThreadCreated((thread) => {
|
|
293
|
+
* console.log("Thread created:", thread.id);
|
|
294
|
+
* });
|
|
295
|
+
* // later…
|
|
296
|
+
* unsubscribe();
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
onThreadCreated(callback) {
|
|
300
|
+
this.#threadCreatedListeners.add(callback);
|
|
301
|
+
return () => {
|
|
302
|
+
this.#threadCreatedListeners.delete(callback);
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Register a listener invoked whenever a thread is updated (including archive).
|
|
307
|
+
*
|
|
308
|
+
* Multiple listeners can be registered. Each call returns an unsubscribe
|
|
309
|
+
* function that removes the listener when called.
|
|
310
|
+
*
|
|
311
|
+
* @param callback - Receives the updated {@link ThreadSummary}.
|
|
312
|
+
* @returns A function that removes this listener when called.
|
|
313
|
+
*/
|
|
314
|
+
onThreadUpdated(callback) {
|
|
315
|
+
this.#threadUpdatedListeners.add(callback);
|
|
316
|
+
return () => {
|
|
317
|
+
this.#threadUpdatedListeners.delete(callback);
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Register a listener invoked whenever a thread is deleted.
|
|
322
|
+
*
|
|
323
|
+
* Multiple listeners can be registered. Each call returns an unsubscribe
|
|
324
|
+
* function that removes the listener when called.
|
|
325
|
+
*
|
|
326
|
+
* @param callback - Receives the {@link ThreadDeletedPayload} identifying
|
|
327
|
+
* the deleted thread.
|
|
328
|
+
* @returns A function that removes this listener when called.
|
|
329
|
+
*/
|
|
330
|
+
onThreadDeleted(callback) {
|
|
331
|
+
this.#threadDeletedListeners.add(callback);
|
|
332
|
+
return () => {
|
|
333
|
+
this.#threadDeletedListeners.delete(callback);
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
ɵgetApiUrl() {
|
|
337
|
+
return this.#apiUrl;
|
|
338
|
+
}
|
|
339
|
+
ɵgetRunnerWsUrl() {
|
|
340
|
+
return this.#runnerWsUrl;
|
|
341
|
+
}
|
|
342
|
+
ɵgetClientWsUrl() {
|
|
343
|
+
return this.#clientWsUrl;
|
|
344
|
+
}
|
|
345
|
+
ɵgetChannelsWsUrl() {
|
|
346
|
+
return this.#channelsWsUrl;
|
|
347
|
+
}
|
|
348
|
+
ɵgetRunnerAuthToken() {
|
|
349
|
+
return this.#apiKey;
|
|
350
|
+
}
|
|
351
|
+
/** @internal Used by `attachIntelligenceEnterpriseLearning` to populate `Authorization`. */
|
|
352
|
+
ɵgetApiKey() {
|
|
353
|
+
return this.#apiKey;
|
|
354
|
+
}
|
|
355
|
+
/** @internal Used by the Intelligence runtime to assign Learning Containers. */
|
|
356
|
+
ɵgetLearningContainerId() {
|
|
357
|
+
return this.#getLearningContainerId;
|
|
358
|
+
}
|
|
359
|
+
/** @internal Used by `attachIntelligenceEnterpriseLearning` to gate MCP attachment. */
|
|
360
|
+
ɵisEnterpriseLearningEnabled() {
|
|
361
|
+
return this.#enterpriseLearningEnabled;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Fetch one authorized learned-skills ZIP with this client's project key.
|
|
365
|
+
* No retries, archive parsing, or cache. A caller signal bounds the request
|
|
366
|
+
* and body read. Native cancellation is preserved; deadline failures use
|
|
367
|
+
* {@link LearnedSkillsError} with code `TIMEOUT`.
|
|
368
|
+
*/
|
|
369
|
+
async getLearnedSkillsSnapshot(params) {
|
|
370
|
+
try {
|
|
371
|
+
params.signal?.throwIfAborted();
|
|
372
|
+
if (typeof params.containerId !== "string" || !params.containerId.trim() || params.revision !== void 0 && (typeof params.revision !== "string" || !params.revision.length) || params.ifNoneMatch !== void 0 && (typeof params.ifNoneMatch !== "string" || !params.ifNoneMatch.length || /[\r\n]/.test(params.ifNoneMatch))) throw new require_learned_skills.LearnedSkillsError("INVALID_CONFIG", false);
|
|
373
|
+
let url;
|
|
374
|
+
try {
|
|
375
|
+
url = new URL(`${this.#apiUrl}/api/v1/learning/containers/${encodeURIComponent(params.containerId)}/skills`);
|
|
376
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password) throw new Error("Invalid API URL");
|
|
377
|
+
if (params.revision !== void 0) url.searchParams.set("revision", params.revision);
|
|
378
|
+
} catch {
|
|
379
|
+
throw new require_learned_skills.LearnedSkillsError("INVALID_CONFIG", false);
|
|
380
|
+
}
|
|
381
|
+
const response = await fetch(url.toString(), {
|
|
382
|
+
method: "GET",
|
|
383
|
+
headers: {
|
|
384
|
+
Authorization: `Bearer ${this.#apiKey}`,
|
|
385
|
+
Accept: "application/zip",
|
|
386
|
+
...params.ifNoneMatch !== void 0 ? { "If-None-Match": params.ifNoneMatch } : {}
|
|
387
|
+
},
|
|
388
|
+
signal: params.signal,
|
|
389
|
+
redirect: "error"
|
|
390
|
+
});
|
|
391
|
+
if (response.status === 401) {
|
|
392
|
+
response.body?.cancel().catch(() => {});
|
|
393
|
+
throw new require_learned_skills.LearnedSkillsError("AUTHENTICATION_FAILED", false);
|
|
394
|
+
}
|
|
395
|
+
if (response.status !== 403) params.signal?.throwIfAborted();
|
|
396
|
+
if (response.status !== 200 && response.status !== 304) {
|
|
397
|
+
const denialCode = response.status === 403 ? "AUTHORIZATION_FAILED" : void 0;
|
|
398
|
+
let body;
|
|
399
|
+
try {
|
|
400
|
+
body = await learnedSkillsErrorBody(response, params.signal);
|
|
401
|
+
} catch (error) {
|
|
402
|
+
if (denialCode) throw new require_learned_skills.LearnedSkillsError(denialCode, false, error instanceof SyntaxError ? void 0 : error);
|
|
403
|
+
params.signal?.throwIfAborted();
|
|
404
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
405
|
+
}
|
|
406
|
+
const responseError = require_learned_skills.learnedSkillsResponseError(body);
|
|
407
|
+
if (response.status === 403 && ![
|
|
408
|
+
"AUTHENTICATION_FAILED",
|
|
409
|
+
"AUTHORIZATION_FAILED",
|
|
410
|
+
"ENTITLEMENT_REQUIRED",
|
|
411
|
+
"DELIVERY_DISABLED",
|
|
412
|
+
"CONTAINER_NOT_FOUND",
|
|
413
|
+
"REVISION_NOT_FOUND",
|
|
414
|
+
"REVISION_REVOKED"
|
|
415
|
+
].includes(responseError.code)) throw new require_learned_skills.LearnedSkillsError(denialCode, false);
|
|
416
|
+
throw responseError;
|
|
417
|
+
}
|
|
418
|
+
const revision = response.headers.get("X-CopilotKit-Skills-Revision");
|
|
419
|
+
const etag = response.headers.get("ETag");
|
|
420
|
+
if (!revision || !etag || !/^"[a-f0-9]{64}"$/.test(etag) || params.revision !== void 0 && revision !== params.revision) throw new require_learned_skills.LearnedSkillsError("INVALID_SNAPSHOT", false);
|
|
421
|
+
if (response.status === 304) {
|
|
422
|
+
if (params.ifNoneMatch === void 0) throw new require_learned_skills.LearnedSkillsError("INVALID_SNAPSHOT", false);
|
|
423
|
+
return {
|
|
424
|
+
status: "unchanged",
|
|
425
|
+
revision,
|
|
426
|
+
etag
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
const contentType = response.headers.get("Content-Type");
|
|
430
|
+
if (!contentType || contentType.split(";", 1)[0].trim().toLowerCase() !== "application/zip") throw new require_learned_skills.LearnedSkillsError("INVALID_SNAPSHOT", false);
|
|
431
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
432
|
+
params.signal?.throwIfAborted();
|
|
433
|
+
return {
|
|
434
|
+
status: "snapshot",
|
|
435
|
+
bytes,
|
|
436
|
+
revision,
|
|
437
|
+
etag,
|
|
438
|
+
contentType
|
|
439
|
+
};
|
|
440
|
+
} catch (error) {
|
|
441
|
+
if (error instanceof require_learned_skills.LearnedSkillsError) throw error;
|
|
442
|
+
const cause = params.signal?.aborted ? params.signal.reason : error;
|
|
443
|
+
if (cause instanceof Error && cause.name === "TimeoutError") throw new require_learned_skills.LearnedSkillsError("TIMEOUT", true, cause);
|
|
444
|
+
if (params.signal?.aborted || cause instanceof Error && cause.name === "AbortError") throw cause;
|
|
445
|
+
throw new require_learned_skills.LearnedSkillsError("NETWORK_ERROR", true, error);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
/** Fetch all requested containers in one authorized request, without retries. */
|
|
449
|
+
async getLearnedSkillsSnapshots(params) {
|
|
450
|
+
try {
|
|
451
|
+
params.signal?.throwIfAborted();
|
|
452
|
+
const containers = params.containers;
|
|
453
|
+
if (!Array.isArray(containers) || containers.length < 1 || containers.length > 50 || new Set(containers.map((item) => item?.containerId)).size !== containers.length) throw new require_learned_skills.LearnedSkillsError("INVALID_CONFIG", false);
|
|
454
|
+
for (const item of containers) {
|
|
455
|
+
if (!item || typeof item.containerId !== "string" || !item.containerId.trim() || /[\u0000-\u001f\u007f]/.test(item.containerId) || item.revision !== void 0 && (typeof item.revision !== "string" || !item.revision.trim()) || item.ifNoneMatch !== void 0 && (typeof item.ifNoneMatch !== "string" || !/^"[a-f0-9]{64}"$/.test(item.ifNoneMatch))) throw new require_learned_skills.LearnedSkillsError("INVALID_CONFIG", false);
|
|
456
|
+
try {
|
|
457
|
+
encodeURIComponent(item.containerId);
|
|
458
|
+
} catch {
|
|
459
|
+
throw new require_learned_skills.LearnedSkillsError("INVALID_CONFIG", false);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
let url;
|
|
463
|
+
try {
|
|
464
|
+
url = new URL(`${this.#apiUrl}/api/v1/learning/skills/batch`);
|
|
465
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password) throw new Error();
|
|
466
|
+
} catch {
|
|
467
|
+
throw new require_learned_skills.LearnedSkillsError("INVALID_CONFIG", false);
|
|
468
|
+
}
|
|
469
|
+
const response = await fetch(url.toString(), {
|
|
470
|
+
method: "POST",
|
|
471
|
+
headers: {
|
|
472
|
+
Authorization: `Bearer ${this.#apiKey}`,
|
|
473
|
+
Accept: "application/json",
|
|
474
|
+
"Content-Type": "application/json"
|
|
475
|
+
},
|
|
476
|
+
body: JSON.stringify({ containers: containers.map(({ containerId, revision, ifNoneMatch }) => ({
|
|
477
|
+
containerId,
|
|
478
|
+
...revision !== void 0 ? { revision } : {},
|
|
479
|
+
...ifNoneMatch !== void 0 ? { ifNoneMatch } : {}
|
|
480
|
+
})) }),
|
|
481
|
+
signal: params.signal,
|
|
482
|
+
redirect: "error"
|
|
483
|
+
});
|
|
484
|
+
if (response.status === 401) {
|
|
485
|
+
response.body?.cancel().catch(() => {});
|
|
486
|
+
throw new require_learned_skills.LearnedSkillsError("AUTHENTICATION_FAILED", false);
|
|
487
|
+
}
|
|
488
|
+
if (response.status !== 403) params.signal?.throwIfAborted();
|
|
489
|
+
if (response.status !== 200) {
|
|
490
|
+
let body;
|
|
491
|
+
try {
|
|
492
|
+
body = await learnedSkillsErrorBody(response, params.signal);
|
|
493
|
+
} catch (error) {
|
|
494
|
+
if (response.status === 403) throw new require_learned_skills.LearnedSkillsError("AUTHORIZATION_FAILED", false);
|
|
495
|
+
params.signal?.throwIfAborted();
|
|
496
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
497
|
+
}
|
|
498
|
+
const error = require_learned_skills.learnedSkillsResponseError(body);
|
|
499
|
+
if (response.status === 403 && ![
|
|
500
|
+
"AUTHENTICATION_FAILED",
|
|
501
|
+
"AUTHORIZATION_FAILED",
|
|
502
|
+
"ENTITLEMENT_REQUIRED",
|
|
503
|
+
"DELIVERY_DISABLED",
|
|
504
|
+
"CONTAINER_NOT_FOUND",
|
|
505
|
+
"REVISION_NOT_FOUND",
|
|
506
|
+
"REVISION_REVOKED"
|
|
507
|
+
].includes(error.code)) throw new require_learned_skills.LearnedSkillsError("AUTHORIZATION_FAILED", false);
|
|
508
|
+
throw error;
|
|
509
|
+
}
|
|
510
|
+
if (response.headers.get("Content-Type")?.split(";", 1)[0].trim().toLowerCase() !== "application/json") throw new require_learned_skills.LearnedSkillsError("INVALID_SNAPSHOT", false);
|
|
511
|
+
let body;
|
|
512
|
+
try {
|
|
513
|
+
body = await learnedSkillsErrorBody(response, params.signal);
|
|
514
|
+
} catch (error) {
|
|
515
|
+
if (error instanceof SyntaxError) throw new require_learned_skills.LearnedSkillsError("INVALID_SNAPSHOT", false);
|
|
516
|
+
throw error;
|
|
517
|
+
}
|
|
518
|
+
params.signal?.throwIfAborted();
|
|
519
|
+
return require_learned_skills.parseLearnedSkillsBatch(body, containers);
|
|
520
|
+
} catch (error) {
|
|
521
|
+
if (error instanceof require_learned_skills.LearnedSkillsError) throw error;
|
|
522
|
+
const cause = params.signal?.aborted ? params.signal.reason : error;
|
|
523
|
+
if (cause instanceof Error && cause.name === "TimeoutError") throw new require_learned_skills.LearnedSkillsError("TIMEOUT", true, cause);
|
|
524
|
+
if (params.signal?.aborted || cause instanceof Error && cause.name === "AbortError") throw cause;
|
|
525
|
+
throw new require_learned_skills.LearnedSkillsError("NETWORK_ERROR", true, error);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Fetch trusted Inspector metadata for this runtime's Intelligence project.
|
|
530
|
+
*
|
|
531
|
+
* The request always uses the server-configured Intelligence API key. A 404
|
|
532
|
+
* is treated as compatible absence so runtimes can work with older App API
|
|
533
|
+
* deployments that do not expose this endpoint yet.
|
|
534
|
+
*
|
|
535
|
+
* @returns Sanitized V1 metadata, or `undefined` when the provider has no
|
|
536
|
+
* supported metadata.
|
|
537
|
+
* @throws {@link PlatformRequestError} for provider failures other than 404.
|
|
538
|
+
*/
|
|
539
|
+
async getInspectorMetadata() {
|
|
540
|
+
const path = "/api/inspector/metadata";
|
|
541
|
+
const abortController = new AbortController();
|
|
542
|
+
const timeoutError = /* @__PURE__ */ new Error("Intelligence inspector metadata request timed out");
|
|
543
|
+
let timeoutId;
|
|
544
|
+
const timeout = new Promise((_, reject) => {
|
|
545
|
+
timeoutId = setTimeout(() => {
|
|
546
|
+
reject(timeoutError);
|
|
547
|
+
abortController.abort(timeoutError);
|
|
548
|
+
}, INSPECTOR_METADATA_REQUEST_TIMEOUT_MS);
|
|
549
|
+
});
|
|
550
|
+
try {
|
|
551
|
+
const response = await Promise.race([fetch(`${this.#apiUrl}${path}`, {
|
|
552
|
+
method: "GET",
|
|
553
|
+
headers: { Authorization: `Bearer ${this.#apiKey}` },
|
|
554
|
+
signal: abortController.signal
|
|
555
|
+
}), timeout]);
|
|
556
|
+
if (response.status === 204 || response.status === 404) return;
|
|
557
|
+
if (!response.ok) {
|
|
558
|
+
_copilotkit_shared.logger.error({
|
|
559
|
+
status: response.status,
|
|
560
|
+
path
|
|
561
|
+
}, "Intelligence platform request failed");
|
|
562
|
+
throw new PlatformRequestError(`Intelligence platform error ${response.status}`, response.status);
|
|
563
|
+
}
|
|
564
|
+
const body = await Promise.race([response.text(), timeout]);
|
|
565
|
+
return (0, _copilotkit_shared.parseInspectorMetadataV1)(JSON.parse(body));
|
|
566
|
+
} catch (error) {
|
|
567
|
+
if (error === timeoutError) _copilotkit_shared.logger.warn({
|
|
568
|
+
path,
|
|
569
|
+
timeoutMs: INSPECTOR_METADATA_REQUEST_TIMEOUT_MS
|
|
570
|
+
}, "Intelligence inspector metadata request timed out");
|
|
571
|
+
throw error;
|
|
572
|
+
} finally {
|
|
573
|
+
if (timeoutId !== void 0) clearTimeout(timeoutId);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
/** Lists a bounded page of Learning spaces owned by this server's project key. */
|
|
577
|
+
async #listLearningContainers(options = {}) {
|
|
578
|
+
const query = options.cursor === void 0 ? "" : `?cursor=${encodeURIComponent(zod.z.string().min(1).max(128).parse(options.cursor))}`;
|
|
579
|
+
return this.#learningRequest("GET", `/api/v1/learning/containers${query}`, require_learning_management.learningContainerPageSchema, options.signal);
|
|
580
|
+
}
|
|
581
|
+
/** Reads one Learning space; this does not assign or move any conversations. */
|
|
582
|
+
async #getLearningContainer(options) {
|
|
583
|
+
return (await this.#learningRequest("GET", require_learning_management.learningContainerPath(options.containerId), zod.z.object({ container: require_learning_management.learningContainerSchema }), options.signal)).container;
|
|
584
|
+
}
|
|
585
|
+
/** Reads the latest 100 Learning runs; queue admission is not completion. */
|
|
586
|
+
async #listLearningRuns(options) {
|
|
587
|
+
return (await this.#learningRequest("GET", `${require_learning_management.learningContainerPath(options.containerId)}/runs`, zod.z.object({ runs: zod.z.array(require_learning_management.learningRunSchema).max(100) }), options.signal)).runs;
|
|
588
|
+
}
|
|
589
|
+
/** Starts or recovers a manual run for all eligible evidence in this space. Never retries automatically. */
|
|
590
|
+
async #startLearningRun(options) {
|
|
591
|
+
return (await this.#learningRequest("POST", `${require_learning_management.learningContainerPath(options.containerId)}/runs`, zod.z.object({ run: require_learning_management.learningRunSchema }), options.signal)).run;
|
|
592
|
+
}
|
|
593
|
+
/** Reads the latest 500 proposed Skill changes, including completed reviews. */
|
|
594
|
+
async #listLearningCandidates(options) {
|
|
595
|
+
return (await this.#learningRequest("GET", `${require_learning_management.learningContainerPath(options.containerId)}/candidates`, zod.z.object({ candidates: zod.z.array(require_learning_management.learningCandidateSchema).max(500) }), options.signal)).candidates;
|
|
596
|
+
}
|
|
597
|
+
/** Reads proposed files and supporting Insights for an explicit review decision. */
|
|
598
|
+
async #getLearningCandidate(options) {
|
|
599
|
+
return (await this.#learningRequest("GET", `${require_learning_management.learningContainerPath(options.containerId)}/candidates/${require_learning_management.learningObjectId(options.candidateId)}`, zod.z.object({ candidate: require_learning_management.learningCandidateDetailSchema }), options.signal)).candidate;
|
|
600
|
+
}
|
|
601
|
+
/** Reads scoped source evidence, including unavailable-source reasons. */
|
|
602
|
+
async #getLearningInsightEvidence(options) {
|
|
603
|
+
return (await this.#learningRequest("GET", `${require_learning_management.learningContainerPath(options.containerId)}/insights/${require_learning_management.learningObjectId(options.insightId)}/evidence`, zod.z.object({ evidence: zod.z.array(require_learning_management.learningInsightEvidenceSchema) }), options.signal)).evidence;
|
|
604
|
+
}
|
|
605
|
+
/** Publishes or rejects a proposal. The application must authorize its reviewer before calling. */
|
|
606
|
+
async #reviewLearningCandidate(options) {
|
|
607
|
+
const action = zod.z.enum(["approve", "reject"]).parse(options.action);
|
|
608
|
+
return (await this.#learningRequest("POST", `${require_learning_management.learningContainerPath(options.containerId)}/candidates/${require_learning_management.learningObjectId(options.candidateId)}/${action}`, zod.z.object({ review: require_learning_management.learningCandidateReviewSchema }), options.signal)).review;
|
|
609
|
+
}
|
|
610
|
+
/** Uses server credentials, bounded JSON, and a deadline without retrying mutations. */
|
|
611
|
+
async #learningRequest(method, path, schema, signal) {
|
|
612
|
+
signal?.throwIfAborted();
|
|
613
|
+
const controller = new AbortController();
|
|
614
|
+
const abort = () => controller.abort(signal?.reason);
|
|
615
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
616
|
+
const timeout = setTimeout(() => controller.abort(/* @__PURE__ */ new Error("Learning request timed out")), 3e4);
|
|
617
|
+
try {
|
|
618
|
+
const response = await fetch(`${this.#apiUrl}${path}`, {
|
|
619
|
+
method,
|
|
620
|
+
headers: {
|
|
621
|
+
Authorization: `Bearer ${this.#apiKey}`,
|
|
622
|
+
"Content-Type": "application/json"
|
|
623
|
+
},
|
|
624
|
+
...method === "POST" ? { body: "{}" } : {},
|
|
625
|
+
signal: controller.signal
|
|
626
|
+
});
|
|
627
|
+
if (!response.ok) {
|
|
628
|
+
const body = await require_learning_management.readLearningJson(response, 64 * 1024, controller.signal).catch(() => void 0);
|
|
629
|
+
controller.signal.throwIfAborted();
|
|
630
|
+
const error = zod.z.object({ error: zod.z.object({
|
|
631
|
+
code: zod.z.string().regex(/^[A-Z][A-Z0-9_]{0,99}$/),
|
|
632
|
+
retryable: zod.z.boolean()
|
|
633
|
+
}) }).safeParse(body);
|
|
634
|
+
throw new PlatformRequestError(`Learning request failed (${response.status}).`, response.status, error.success ? error.data.error.retryable : response.status === 429 || response.status >= 500, error.success ? error.data.error.code : void 0);
|
|
635
|
+
}
|
|
636
|
+
try {
|
|
637
|
+
return schema.parse(await require_learning_management.readLearningJson(response, void 0, controller.signal));
|
|
638
|
+
} catch {
|
|
639
|
+
if (controller.signal.aborted) throw controller.signal.reason;
|
|
640
|
+
throw new PlatformRequestError("Invalid Learning response.", 502, true);
|
|
641
|
+
}
|
|
642
|
+
} finally {
|
|
643
|
+
clearTimeout(timeout);
|
|
644
|
+
signal?.removeEventListener("abort", abort);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
/** Fetches one credential-scoped, bounded Learning projection for Inspector. */
|
|
648
|
+
async getInspectorLearning(request) {
|
|
649
|
+
const url = new URL(`${this.#apiUrl}/api/inspector/learning`);
|
|
650
|
+
if (request.agentId) url.searchParams.set("agentId", request.agentId);
|
|
651
|
+
if (request.skillsPage) url.searchParams.set("skillsPage", String(request.skillsPage));
|
|
652
|
+
if (request.insightsPage) url.searchParams.set("insightsPage", String(request.insightsPage));
|
|
653
|
+
if (request.runtimeContainerId) url.searchParams.set("runtimeContainerId", request.runtimeContainerId);
|
|
654
|
+
const controller = new AbortController();
|
|
655
|
+
const timeoutError = /* @__PURE__ */ new Error("Intelligence Inspector Learning request timed out");
|
|
656
|
+
const timeout = setTimeout(() => controller.abort(timeoutError), INSPECTOR_LEARNING_REQUEST_TIMEOUT_MS);
|
|
657
|
+
try {
|
|
658
|
+
const response = await fetch(url, {
|
|
659
|
+
method: "GET",
|
|
660
|
+
headers: { Authorization: `Bearer ${this.#apiKey}` },
|
|
661
|
+
signal: controller.signal
|
|
662
|
+
});
|
|
663
|
+
if (!response.ok) throw new PlatformRequestError(`Intelligence platform error ${response.status}`, response.status, response.status === 429 || response.status >= 500);
|
|
664
|
+
const snapshot = (0, _copilotkit_shared.parseInspectorLearningSnapshotV1)(await response.json());
|
|
665
|
+
if (!snapshot) throw new PlatformRequestError("Invalid Inspector Learning response", 502, true);
|
|
666
|
+
return snapshot;
|
|
667
|
+
} finally {
|
|
668
|
+
clearTimeout(timeout);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Resolve the Runtime entitlement projection for this project.
|
|
673
|
+
*
|
|
674
|
+
* Concurrent calls share one request. Active grants cache for 30 seconds;
|
|
675
|
+
* inactive results and failures cache for 5 seconds. Callers receive copies
|
|
676
|
+
* so they cannot mutate cached authority.
|
|
677
|
+
*/
|
|
678
|
+
async getRuntimeEntitlements() {
|
|
679
|
+
const now = Date.now();
|
|
680
|
+
if (this.#runtimeEntitlementsCache && now < this.#runtimeEntitlementsCache.expiresAt) return cloneRuntimeEntitlementResponse(this.#runtimeEntitlementsCache.response);
|
|
681
|
+
if (this.#runtimeEntitlementsFailure && now < this.#runtimeEntitlementsFailure.expiresAt) throw cloneRuntimeEntitlementError(this.#runtimeEntitlementsFailure.error);
|
|
682
|
+
const request = this.#runtimeEntitlementsInFlight ?? this.#fetchRuntimeEntitlements().then((response) => {
|
|
683
|
+
this.#runtimeEntitlementsFailure = void 0;
|
|
684
|
+
this.#runtimeEntitlementsCache = {
|
|
685
|
+
response,
|
|
686
|
+
expiresAt: Date.now() + (grantsRuntimeAccess(response) ? RUNTIME_ENTITLEMENTS_SUCCESS_TTL_MS : RUNTIME_ENTITLEMENTS_NEGATIVE_TTL_MS)
|
|
687
|
+
};
|
|
688
|
+
return response;
|
|
689
|
+
}).catch((error) => {
|
|
690
|
+
this.#runtimeEntitlementsFailure = {
|
|
691
|
+
error,
|
|
692
|
+
expiresAt: Date.now() + RUNTIME_ENTITLEMENTS_NEGATIVE_TTL_MS
|
|
693
|
+
};
|
|
694
|
+
throw error;
|
|
695
|
+
});
|
|
696
|
+
this.#runtimeEntitlementsInFlight = request;
|
|
697
|
+
try {
|
|
698
|
+
return cloneRuntimeEntitlementResponse(await request);
|
|
699
|
+
} catch (error) {
|
|
700
|
+
throw cloneRuntimeEntitlementError(error);
|
|
701
|
+
} finally {
|
|
702
|
+
if (this.#runtimeEntitlementsInFlight === request) this.#runtimeEntitlementsInFlight = void 0;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
/** Perform one bounded Runtime entitlement request without caching. */
|
|
706
|
+
async #fetchRuntimeEntitlements() {
|
|
707
|
+
const path = "/api/entitlements/runtime";
|
|
708
|
+
const controller = new AbortController();
|
|
709
|
+
const timeout = setTimeout(() => controller.abort(), RUNTIME_ENTITLEMENTS_REQUEST_TIMEOUT_MS);
|
|
710
|
+
try {
|
|
711
|
+
const response = await fetch(`${this.#apiUrl}${path}`, {
|
|
712
|
+
method: "GET",
|
|
713
|
+
headers: {
|
|
714
|
+
Authorization: `Bearer ${this.#apiKey}`,
|
|
715
|
+
"Content-Type": "application/json"
|
|
716
|
+
},
|
|
717
|
+
signal: controller.signal
|
|
718
|
+
});
|
|
719
|
+
if (!response.ok) {
|
|
720
|
+
await response.body?.cancel();
|
|
721
|
+
_copilotkit_shared.logger.error({
|
|
722
|
+
status: response.status,
|
|
723
|
+
path
|
|
724
|
+
}, "Runtime entitlement request failed");
|
|
725
|
+
throw new PlatformRequestError(`Runtime entitlement request failed with status ${response.status}`, response.status, isRetryableRuntimeEntitlementStatus(response.status));
|
|
726
|
+
}
|
|
727
|
+
let payload;
|
|
728
|
+
try {
|
|
729
|
+
payload = await response.json();
|
|
730
|
+
} catch (error) {
|
|
731
|
+
if (controller.signal.aborted) throw error;
|
|
732
|
+
throw new PlatformRequestError("Runtime entitlement response was malformed", 502, false);
|
|
733
|
+
}
|
|
734
|
+
const normalized = normalizeRuntimeEntitlementTransport(payload);
|
|
735
|
+
if (!normalized) throw new PlatformRequestError("Runtime entitlement response was malformed", 502, false);
|
|
736
|
+
return normalized;
|
|
737
|
+
} catch (error) {
|
|
738
|
+
if (error instanceof PlatformRequestError) throw error;
|
|
739
|
+
if (controller.signal.aborted || error instanceof DOMException && error.name === "AbortError") throw new PlatformRequestError("Runtime entitlement request timed out", 504, true);
|
|
740
|
+
throw new PlatformRequestError("Runtime entitlement request failed", 502, true);
|
|
741
|
+
} finally {
|
|
742
|
+
clearTimeout(timeout);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Mint a browser capture grant using only the Runtime's project and user.
|
|
747
|
+
*
|
|
748
|
+
* Learning Container assignment never stops capture: a failed selection or
|
|
749
|
+
* an unknown Container is logged, and the Trajectory connects without
|
|
750
|
+
* assignments.
|
|
751
|
+
*/
|
|
752
|
+
async ɵconnectTrajectory(params) {
|
|
753
|
+
let learningContainerIds;
|
|
754
|
+
try {
|
|
755
|
+
learningContainerIds = await require_learning.resolveTrajectoryLearningContainerIds(this.#getTrajectoryLearningContainerIds, {
|
|
756
|
+
trajectoryId: params.trajectoryId,
|
|
757
|
+
user: params.user
|
|
758
|
+
}, params.signal);
|
|
759
|
+
} catch (error) {
|
|
760
|
+
if (params.signal?.aborted) throw params.signal.reason;
|
|
761
|
+
_copilotkit_shared.logger.error({
|
|
762
|
+
err: error,
|
|
763
|
+
trajectoryId: params.trajectoryId
|
|
764
|
+
}, "Failed to resolve Trajectory Learning Containers; connecting the Trajectory without Learning Container assignments");
|
|
765
|
+
}
|
|
766
|
+
params.signal?.throwIfAborted();
|
|
767
|
+
try {
|
|
768
|
+
return await this.#joinTrajectory(params, learningContainerIds);
|
|
769
|
+
} catch (error) {
|
|
770
|
+
if (learningContainerIds === void 0 || !(error instanceof require_trajectories.TrajectoryConnectionError) || error.code !== "LEARNING_CONTAINER_NOT_FOUND") throw error;
|
|
771
|
+
params.signal?.throwIfAborted();
|
|
772
|
+
_copilotkit_shared.logger.warn({
|
|
773
|
+
trajectoryId: params.trajectoryId,
|
|
774
|
+
learningContainerIds
|
|
775
|
+
}, "A selected Learning Container does not exist in this project; connecting the Trajectory without Learning Container assignments");
|
|
776
|
+
return this.#joinTrajectory(params, void 0);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
/** Requests one Trajectory join token, optionally with Container assignments. */
|
|
780
|
+
async #joinTrajectory(params, learningContainerIds) {
|
|
781
|
+
let response;
|
|
782
|
+
try {
|
|
783
|
+
response = await fetch(`${this.#apiUrl}/api/trajectories/join`, {
|
|
784
|
+
method: "POST",
|
|
785
|
+
headers: {
|
|
786
|
+
Authorization: `Bearer ${this.#apiKey}`,
|
|
787
|
+
"Content-Type": "application/json"
|
|
788
|
+
},
|
|
789
|
+
body: JSON.stringify({
|
|
790
|
+
trajectoryId: params.trajectoryId,
|
|
791
|
+
appUserId: params.user.id,
|
|
792
|
+
...learningContainerIds === void 0 ? {} : { learningContainerIds }
|
|
793
|
+
}),
|
|
794
|
+
signal: params.signal,
|
|
795
|
+
redirect: "error"
|
|
796
|
+
});
|
|
797
|
+
} catch (error) {
|
|
798
|
+
if (!params.signal?.aborted) _copilotkit_shared.logger.warn({
|
|
799
|
+
error: error instanceof Error ? error.name : typeof error,
|
|
800
|
+
causeCode: networkErrorCode(error instanceof Error ? error.cause : void 0),
|
|
801
|
+
host: urlHost(this.#apiUrl)
|
|
802
|
+
}, "Could not reach Intelligence to connect a Trajectory");
|
|
803
|
+
throw error;
|
|
804
|
+
}
|
|
805
|
+
const payload = await response.json().catch(() => void 0);
|
|
806
|
+
if (!response.ok) throw require_trajectories.trajectoryResponseError(payload, response.status, this.#apiKey);
|
|
807
|
+
return require_trajectories.parseTrajectoryConnectionGrant(payload, params.trajectoryId, this.ɵgetClientWsUrl());
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Sends one request to the platform and parses its JSON body.
|
|
811
|
+
*
|
|
812
|
+
* @param expectedStatuses - Non-2xx statuses the caller handles as a normal
|
|
813
|
+
* outcome, such as the 404 of a thread that does not exist yet. They are
|
|
814
|
+
* logged at debug instead of error, and still throw.
|
|
815
|
+
* @throws {@link PlatformRequestError} on every non-2xx response.
|
|
816
|
+
*/
|
|
817
|
+
async #request(method, path, body, extraHeaders, signal, expectedStatuses) {
|
|
818
|
+
const url = `${this.#apiUrl}${path}`;
|
|
819
|
+
const headers = {
|
|
820
|
+
Authorization: `Bearer ${this.#apiKey}`,
|
|
821
|
+
"Content-Type": "application/json",
|
|
822
|
+
...extraHeaders
|
|
823
|
+
};
|
|
824
|
+
const response = await fetch(url, {
|
|
825
|
+
method,
|
|
826
|
+
headers,
|
|
827
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
828
|
+
signal
|
|
829
|
+
});
|
|
830
|
+
if (!response.ok) {
|
|
831
|
+
const text = await response.text().catch(() => "");
|
|
832
|
+
if (expectedStatuses?.has(response.status)) _copilotkit_shared.logger.debug({
|
|
833
|
+
status: response.status,
|
|
834
|
+
path
|
|
835
|
+
}, "Intelligence platform request returned an expected status");
|
|
836
|
+
else _copilotkit_shared.logger.error({
|
|
837
|
+
status: response.status,
|
|
838
|
+
body: text,
|
|
839
|
+
path
|
|
840
|
+
}, "Intelligence platform request failed");
|
|
841
|
+
throw new PlatformRequestError(`Intelligence platform error ${response.status}: ${text || response.statusText}`, response.status, readErrorBodyRetryable(text));
|
|
842
|
+
}
|
|
843
|
+
const text = await response.text();
|
|
844
|
+
if (!text) return;
|
|
845
|
+
return JSON.parse(text);
|
|
846
|
+
}
|
|
847
|
+
#invokeLifecycleCallback(callbackName, payload) {
|
|
848
|
+
const listeners = callbackName === "onThreadCreated" ? this.#threadCreatedListeners : callbackName === "onThreadUpdated" ? this.#threadUpdatedListeners : this.#threadDeletedListeners;
|
|
849
|
+
for (const callback of listeners) try {
|
|
850
|
+
callback(payload);
|
|
851
|
+
} catch (error) {
|
|
852
|
+
_copilotkit_shared.logger.error({
|
|
853
|
+
err: error,
|
|
854
|
+
callbackName,
|
|
855
|
+
payload
|
|
856
|
+
}, "Intelligence lifecycle callback failed");
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* List all non-archived threads for a given user and agent.
|
|
861
|
+
*
|
|
862
|
+
* @param params.userId - User whose threads to list.
|
|
863
|
+
* @param params.agentId - Agent whose threads to list.
|
|
864
|
+
* @returns The thread list along with realtime subscription credentials.
|
|
865
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
866
|
+
*/
|
|
867
|
+
async listThreads(params) {
|
|
868
|
+
const query = {
|
|
869
|
+
userId: params.userId,
|
|
870
|
+
agentId: params.agentId
|
|
871
|
+
};
|
|
872
|
+
if (params.includeArchived) query.includeArchived = "true";
|
|
873
|
+
if (params.limit != null) query.limit = String(params.limit);
|
|
874
|
+
if (params.cursor) query.cursor = params.cursor;
|
|
875
|
+
const qs = new URLSearchParams(query).toString();
|
|
876
|
+
return this.#request("GET", `/api/threads?${qs}`);
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* List the given user's long-term memories, newest first.
|
|
880
|
+
*
|
|
881
|
+
* The platform scopes by the opaque app user supplied in the
|
|
882
|
+
* `x-cpki-user-id` header (resolved by the runtime via `identifyUser`),
|
|
883
|
+
* not a query param. Pass `includeInvalidated` to also return retired rows.
|
|
884
|
+
*
|
|
885
|
+
* @returns The `{ memories }` envelope the client memory store consumes.
|
|
886
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
887
|
+
*/
|
|
888
|
+
async listMemories(params) {
|
|
889
|
+
const qs = params.includeInvalidated ? "?includeInvalidated=true" : "";
|
|
890
|
+
return this.#request("GET", `/api/memories${qs}`, void 0, memoryRequestHeaders(params.userId, params.memoryGrant));
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Create a memory for the given user (platform `POST /api/memories`).
|
|
894
|
+
* @returns The stored memory; `absorbed` is true if the content was merged
|
|
895
|
+
* into a near-duplicate rather than inserted as a new row.
|
|
896
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
897
|
+
*/
|
|
898
|
+
async createMemory(params) {
|
|
899
|
+
return this.#request("POST", `/api/memories`, {
|
|
900
|
+
content: params.content,
|
|
901
|
+
kind: params.kind,
|
|
902
|
+
...params.scope !== void 0 ? { scope: params.scope } : {},
|
|
903
|
+
sourceThreadIds: params.sourceThreadIds ?? []
|
|
904
|
+
}, memoryRequestHeaders(params.userId, params.memoryGrant));
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Supersede an existing memory (platform `PATCH /api/memories/:id`). The
|
|
908
|
+
* `:id` row is retired and a new memory with the supplied content is
|
|
909
|
+
* inserted atomically.
|
|
910
|
+
* @returns The new memory plus `retiredId` (the id of the retired row).
|
|
911
|
+
* @throws {@link PlatformRequestError} on non-2xx responses (e.g. 404 when
|
|
912
|
+
* `:id` is not a live, same-scope memory for this user).
|
|
913
|
+
*/
|
|
914
|
+
async updateMemory(params) {
|
|
915
|
+
return this.#request("PATCH", `/api/memories/${encodeURIComponent(params.id)}`, {
|
|
916
|
+
content: params.content,
|
|
917
|
+
kind: params.kind,
|
|
918
|
+
...params.scope !== void 0 ? { scope: params.scope } : {},
|
|
919
|
+
sourceThreadIds: params.sourceThreadIds ?? []
|
|
920
|
+
}, memoryRequestHeaders(params.userId, params.memoryGrant));
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Non-lossily retire (forget) a memory (platform `DELETE /api/memories/:id`).
|
|
924
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
925
|
+
*/
|
|
926
|
+
async removeMemory(params) {
|
|
927
|
+
await this.#request("DELETE", `/api/memories/${encodeURIComponent(params.id)}`, void 0, memoryRequestHeaders(params.userId, params.memoryGrant));
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* Semantically recall the given user's memories (platform `POST
|
|
931
|
+
* /api/memories/recall`, hybrid RAG). Each returned memory carries a
|
|
932
|
+
* relevance `score`. `scope` narrows to `"user"`/`"project"`; omitted → platform default.
|
|
933
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
934
|
+
*/
|
|
935
|
+
async recallMemories(params) {
|
|
936
|
+
return this.#request("POST", `/api/memories/recall`, {
|
|
937
|
+
query: params.query,
|
|
938
|
+
...params.limit !== void 0 ? { limit: params.limit } : {},
|
|
939
|
+
...params.scope !== void 0 ? { scope: params.scope } : {}
|
|
940
|
+
}, memoryRequestHeaders(params.userId, params.memoryGrant));
|
|
941
|
+
}
|
|
942
|
+
async ɵsubscribeToThreads(params) {
|
|
943
|
+
return this.#request("POST", "/api/threads/subscribe", { userId: params.userId });
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Mint memory-realtime join credentials (platform `POST
|
|
947
|
+
* /api/memories/subscribe`). Returns both the single-use `joinToken` and the
|
|
948
|
+
* per-user `joinCode` the client needs to build the
|
|
949
|
+
* `user_meta:memories:<joinCode>` channel topic. When the platform also
|
|
950
|
+
* resolves a project scope it returns optional `projectJoinToken` /
|
|
951
|
+
* `projectJoinCode`; both are passed through verbatim (omitted when absent,
|
|
952
|
+
* the silent-degrade contract).
|
|
953
|
+
*
|
|
954
|
+
* The user is supplied via the `x-cpki-user-id` header — the same way every
|
|
955
|
+
* other memory endpoint (`listMemories`/`createMemory`/…) identifies the app
|
|
956
|
+
* user — because the platform's memory routes resolve identity from that
|
|
957
|
+
* header, not the body. (This differs from `ɵsubscribeToThreads`, whose
|
|
958
|
+
* platform endpoint reads `userId` from the body.)
|
|
959
|
+
*
|
|
960
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
961
|
+
*/
|
|
962
|
+
async ɵsubscribeToMemories(params) {
|
|
963
|
+
return this.#request("POST", "/api/memories/subscribe", void 0, memoryRequestHeaders(params.userId, params.memoryGrant));
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Update thread metadata (e.g. name).
|
|
967
|
+
*
|
|
968
|
+
* Fields in updates take precedence, preserving the server-side SDK contract.
|
|
969
|
+
* HTTP handlers must remove untrusted identity fields before calling this method.
|
|
970
|
+
*
|
|
971
|
+
* Triggers the `onThreadUpdated` lifecycle callback on success.
|
|
972
|
+
*
|
|
973
|
+
* @returns The updated thread summary.
|
|
974
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
975
|
+
*/
|
|
976
|
+
async updateThread(params) {
|
|
977
|
+
const response = await this.#request("PATCH", `/api/threads/${encodeURIComponent(params.threadId)}`, {
|
|
978
|
+
userId: params.userId,
|
|
979
|
+
agentId: params.agentId,
|
|
980
|
+
...params.updates
|
|
981
|
+
});
|
|
982
|
+
this.#invokeLifecycleCallback("onThreadUpdated", response.thread);
|
|
983
|
+
return response.thread;
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Create a new thread on the platform.
|
|
987
|
+
*
|
|
988
|
+
* Triggers the `onThreadCreated` lifecycle callback on success.
|
|
989
|
+
*
|
|
990
|
+
* @returns The newly created thread summary.
|
|
991
|
+
* @throws {@link PlatformRequestError} with status 409 if a thread with the
|
|
992
|
+
* same `threadId` already exists.
|
|
993
|
+
*/
|
|
994
|
+
async createThread(params) {
|
|
995
|
+
return this.#createThread(params);
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Creates a thread. {@link getOrCreateThread} passes 409 as expected,
|
|
999
|
+
* because there it means another request created the thread first.
|
|
1000
|
+
*/
|
|
1001
|
+
async #createThread(params, expectedStatuses) {
|
|
1002
|
+
const response = await this.#request("POST", `/api/threads`, {
|
|
1003
|
+
threadId: params.threadId,
|
|
1004
|
+
userId: params.userId,
|
|
1005
|
+
agentId: params.agentId,
|
|
1006
|
+
...params.name !== void 0 ? { name: params.name } : {},
|
|
1007
|
+
...params.learningContainerId !== void 0 ? { learningContainerId: params.learningContainerId } : {}
|
|
1008
|
+
}, void 0, void 0, expectedStatuses);
|
|
1009
|
+
this.#invokeLifecycleCallback("onThreadCreated", response.thread);
|
|
1010
|
+
return response.thread;
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Fetch a single thread by ID.
|
|
1014
|
+
*
|
|
1015
|
+
* @returns The thread summary.
|
|
1016
|
+
* @throws {@link PlatformRequestError} with status 404 if the thread does
|
|
1017
|
+
* not exist.
|
|
1018
|
+
*/
|
|
1019
|
+
async getThread(params) {
|
|
1020
|
+
return this.#getThread(params);
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Fetches a thread. {@link getOrCreateThread} passes 404 as expected,
|
|
1024
|
+
* because there it means the thread is about to be created (PE-678).
|
|
1025
|
+
*/
|
|
1026
|
+
async #getThread(params, expectedStatuses) {
|
|
1027
|
+
const qs = new URLSearchParams({ userId: params.userId }).toString();
|
|
1028
|
+
return (await this.#request("GET", `/api/threads/${encodeURIComponent(params.threadId)}?${qs}`, void 0, void 0, void 0, expectedStatuses)).thread;
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1031
|
+
* Get an existing thread or create it if it does not exist.
|
|
1032
|
+
*
|
|
1033
|
+
* Handles the race where a concurrent request creates the thread between
|
|
1034
|
+
* the initial 404 and the subsequent `createThread` call by catching the
|
|
1035
|
+
* 409 Conflict and retrying the get.
|
|
1036
|
+
*
|
|
1037
|
+
* Triggers the `onThreadCreated` lifecycle callback when a new thread is
|
|
1038
|
+
* created.
|
|
1039
|
+
*
|
|
1040
|
+
* @returns An object containing the thread and a `created` flag indicating
|
|
1041
|
+
* whether the thread was newly created (`true`) or already existed (`false`).
|
|
1042
|
+
* @throws {@link PlatformRequestError} on non-2xx responses other than
|
|
1043
|
+
* 404 (get) and 409 (create race).
|
|
1044
|
+
*/
|
|
1045
|
+
async getOrCreateThread(params) {
|
|
1046
|
+
try {
|
|
1047
|
+
return {
|
|
1048
|
+
thread: await this.#getThread({
|
|
1049
|
+
threadId: params.threadId,
|
|
1050
|
+
userId: params.userId
|
|
1051
|
+
}, NOT_FOUND),
|
|
1052
|
+
created: false
|
|
1053
|
+
};
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
if (!(error instanceof PlatformRequestError && error.status === 404)) throw error;
|
|
1056
|
+
}
|
|
1057
|
+
try {
|
|
1058
|
+
return {
|
|
1059
|
+
thread: await this.#createThread(params, CONFLICT),
|
|
1060
|
+
created: true
|
|
1061
|
+
};
|
|
1062
|
+
} catch (error) {
|
|
1063
|
+
if (error instanceof PlatformRequestError && error.status === 409) return {
|
|
1064
|
+
thread: await this.getThread({
|
|
1065
|
+
threadId: params.threadId,
|
|
1066
|
+
userId: params.userId
|
|
1067
|
+
}),
|
|
1068
|
+
created: false
|
|
1069
|
+
};
|
|
1070
|
+
throw error;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
/**
|
|
1074
|
+
* Fetch the full message history for a thread.
|
|
1075
|
+
*
|
|
1076
|
+
* @returns All persisted messages in chronological order.
|
|
1077
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
1078
|
+
*/
|
|
1079
|
+
async getThreadMessages(params) {
|
|
1080
|
+
const qs = new URLSearchParams({ userId: params.userId }).toString();
|
|
1081
|
+
return this.#request("GET", `/api/threads/${encodeURIComponent(params.threadId)}/messages?${qs}`, void 0, params.channelDeliveryId ? { "X-Cpki-Channel-Delivery-Id": params.channelDeliveryId } : void 0);
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* @internal Fetch only the ids of a thread's persisted messages.
|
|
1085
|
+
*
|
|
1086
|
+
* Sends `fields=id` so the platform can omit message content. Platform
|
|
1087
|
+
* versions that do not know the parameter ignore it and return the full
|
|
1088
|
+
* transcript; ids are read from `messages[].id` either way.
|
|
1089
|
+
*
|
|
1090
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
1091
|
+
*/
|
|
1092
|
+
async ɵgetThreadMessageIds(params) {
|
|
1093
|
+
const qs = new URLSearchParams({
|
|
1094
|
+
userId: params.userId,
|
|
1095
|
+
fields: "id"
|
|
1096
|
+
}).toString();
|
|
1097
|
+
return (await this.#request("GET", `/api/threads/${encodeURIComponent(params.threadId)}/messages?${qs}`, void 0, params.channelDeliveryId ? { "X-Cpki-Channel-Delivery-Id": params.channelDeliveryId } : void 0)).messages.map((message) => message.id);
|
|
1098
|
+
}
|
|
1099
|
+
/** @internal Fetches one authorized managed Channel asset for history hydration. */
|
|
1100
|
+
async ɵgetManagedChannelAsset(assetId) {
|
|
1101
|
+
const path = `/api/channels/files/${encodeURIComponent(assetId)}`;
|
|
1102
|
+
const response = await fetch(`${this.#apiUrl}${path}`, {
|
|
1103
|
+
method: "GET",
|
|
1104
|
+
headers: { Authorization: `Bearer ${this.#apiKey}` }
|
|
1105
|
+
});
|
|
1106
|
+
if (!response.ok) {
|
|
1107
|
+
const text = await response.text().catch(() => "");
|
|
1108
|
+
throw new PlatformRequestError(`Intelligence platform error ${response.status}: ${text || response.statusText}`, response.status);
|
|
1109
|
+
}
|
|
1110
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
1111
|
+
const mimeType = response.headers.get("content-type") ?? void 0;
|
|
1112
|
+
return {
|
|
1113
|
+
bytes,
|
|
1114
|
+
...mimeType ? { mimeType } : {}
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Fetch the persisted AG-UI event stream for a thread.
|
|
1119
|
+
*
|
|
1120
|
+
* Backed by the platform's `GET /api/_inspect/threads/:id/events`
|
|
1121
|
+
* introspection endpoint (see Intelligence PR #144). Events are returned
|
|
1122
|
+
* in replay order across every run that targeted the thread. The
|
|
1123
|
+
* `_inspect/` prefix flags this as debug-only — production code paths
|
|
1124
|
+
* must not depend on it.
|
|
1125
|
+
*
|
|
1126
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
1127
|
+
*/
|
|
1128
|
+
async getThreadEvents(params) {
|
|
1129
|
+
requireThreadReadUserId("getThreadEvents", params.userId);
|
|
1130
|
+
const qs = new URLSearchParams({ userId: params.userId }).toString();
|
|
1131
|
+
return this.#request("GET", `/api/_inspect/threads/${encodeURIComponent(params.threadId)}/events?${qs}`);
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* Fetch the current agent state for a thread.
|
|
1135
|
+
*
|
|
1136
|
+
* Backed by the platform's `GET /api/_inspect/threads/:id/state`
|
|
1137
|
+
* introspection endpoint (see Intelligence PR #144). The platform folds
|
|
1138
|
+
* RFC 6902 STATE_DELTA events on top of the latest STATE_SNAPSHOT, so
|
|
1139
|
+
* the returned state reflects the thread's current state — not just the
|
|
1140
|
+
* last snapshot. The discriminated response distinguishes "no snapshot
|
|
1141
|
+
* persisted yet" from "snapshot present" so consumers can render the
|
|
1142
|
+
* correct empty state.
|
|
1143
|
+
*
|
|
1144
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
1145
|
+
*/
|
|
1146
|
+
async getThreadState(params) {
|
|
1147
|
+
requireThreadReadUserId("getThreadState", params.userId);
|
|
1148
|
+
const qs = new URLSearchParams({ userId: params.userId }).toString();
|
|
1149
|
+
return this.#request("GET", `/api/_inspect/threads/${encodeURIComponent(params.threadId)}/state?${qs}`);
|
|
1150
|
+
}
|
|
1151
|
+
/**
|
|
1152
|
+
* Mark a thread as archived.
|
|
1153
|
+
*
|
|
1154
|
+
* Archived threads are excluded from {@link listThreads} results.
|
|
1155
|
+
* Triggers the `onThreadUpdated` lifecycle callback on success.
|
|
1156
|
+
*
|
|
1157
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
1158
|
+
*/
|
|
1159
|
+
async archiveThread(params) {
|
|
1160
|
+
const response = await this.#request("PATCH", `/api/threads/${encodeURIComponent(params.threadId)}`, {
|
|
1161
|
+
userId: params.userId,
|
|
1162
|
+
agentId: params.agentId,
|
|
1163
|
+
archived: true
|
|
1164
|
+
});
|
|
1165
|
+
this.#invokeLifecycleCallback("onThreadUpdated", response.thread);
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Permanently delete a thread and its message history.
|
|
1169
|
+
*
|
|
1170
|
+
* This is irreversible. Triggers the `onThreadDeleted` lifecycle callback
|
|
1171
|
+
* on success.
|
|
1172
|
+
*
|
|
1173
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
1174
|
+
*/
|
|
1175
|
+
async deleteThread(params) {
|
|
1176
|
+
await this.#request("DELETE", `/api/threads/${encodeURIComponent(params.threadId)}`, {
|
|
1177
|
+
userId: params.userId,
|
|
1178
|
+
agentId: params.agentId,
|
|
1179
|
+
reason: `Deleted via CopilotKit runtime (userId=${params.userId}, agentId=${params.agentId})`
|
|
1180
|
+
});
|
|
1181
|
+
this.#invokeLifecycleCallback("onThreadDeleted", params);
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Annotate a thread event on CopilotKit Intelligence's general annotation
|
|
1185
|
+
* endpoint (`PUT /connector/annotate/:clientEventId`).
|
|
1186
|
+
*
|
|
1187
|
+
* This is the generalized replacement for the old
|
|
1188
|
+
* `PUT /connector/user-actions/record/:clientEventId` endpoint. It supports
|
|
1189
|
+
* multiple annotation types via the `type` discriminator. The
|
|
1190
|
+
* `"user_action"` type records a user UI interaction for the self-learning
|
|
1191
|
+
* loop.
|
|
1192
|
+
*
|
|
1193
|
+
* `userId` must be resolved on the runtime side before calling this — the
|
|
1194
|
+
* platform prefixes it with the project id from the API key.
|
|
1195
|
+
*
|
|
1196
|
+
* Always hits the idempotent `PUT /connector/annotate/:clientEventId`
|
|
1197
|
+
* endpoint. A retry with the same `clientEventId` returns
|
|
1198
|
+
* `{ id: <original>, duplicate: true }` instead of creating a new row.
|
|
1199
|
+
* When `clientEventId` is omitted, a UUID is auto-generated for this call.
|
|
1200
|
+
*
|
|
1201
|
+
* @throws {@link PlatformRequestError} on non-2xx responses, OR when the
|
|
1202
|
+
* platform returns an empty 2xx body (which would otherwise corrupt the
|
|
1203
|
+
* caller's typed result).
|
|
1204
|
+
*/
|
|
1205
|
+
async annotate(params) {
|
|
1206
|
+
const clientEventId = params.clientEventId ?? (0, crypto.randomUUID)();
|
|
1207
|
+
const path = `/connector/annotate/${encodeURIComponent(clientEventId)}`;
|
|
1208
|
+
const body = {
|
|
1209
|
+
type: params.type,
|
|
1210
|
+
userId: params.userId,
|
|
1211
|
+
threadId: params.threadId
|
|
1212
|
+
};
|
|
1213
|
+
if (params.payload !== void 0) body.payload = params.payload;
|
|
1214
|
+
if (params.occurredAt !== void 0) body.occurredAt = params.occurredAt;
|
|
1215
|
+
const response = await this.#request("PUT", path, body);
|
|
1216
|
+
if (response == null) {
|
|
1217
|
+
_copilotkit_shared.logger.error({ path }, "annotate: Intelligence platform returned 200 with empty or null body");
|
|
1218
|
+
throw new PlatformRequestError("annotate: empty or null response body from Intelligence platform", 502);
|
|
1219
|
+
}
|
|
1220
|
+
return response;
|
|
1221
|
+
}
|
|
1222
|
+
async ɵacquireThreadLock(params) {
|
|
1223
|
+
return this.#request("POST", `/api/threads/${encodeURIComponent(params.threadId)}/lock`, {
|
|
1224
|
+
runId: params.runId,
|
|
1225
|
+
userId: params.userId,
|
|
1226
|
+
agentId: params.agentId,
|
|
1227
|
+
...params.supportsBackendThreadId === void 0 ? {} : { supportsBackendThreadId: params.supportsBackendThreadId },
|
|
1228
|
+
...params.learningContainerId !== void 0 ? { learningContainerId: params.learningContainerId } : {},
|
|
1229
|
+
...params.requestId !== void 0 ? { requestId: params.requestId } : {},
|
|
1230
|
+
...params.lockKeyPrefix !== void 0 ? { lockKeyPrefix: params.lockKeyPrefix } : {},
|
|
1231
|
+
...params.ttlSeconds !== void 0 ? { ttlSeconds: params.ttlSeconds } : {}
|
|
1232
|
+
}, params.channelDeliveryId ? { "X-Cpki-Channel-Delivery-Id": params.channelDeliveryId } : void 0);
|
|
1233
|
+
}
|
|
1234
|
+
async ɵcleanupThreadLock(params) {
|
|
1235
|
+
return this.#request("DELETE", `/api/threads/${encodeURIComponent(params.threadId)}/lock`, { runId: params.runId });
|
|
1236
|
+
}
|
|
1237
|
+
async ɵrenewThreadLock(params) {
|
|
1238
|
+
return this.#request("PATCH", `/api/threads/${encodeURIComponent(params.threadId)}/lock`, {
|
|
1239
|
+
runId: params.runId,
|
|
1240
|
+
ttlSeconds: params.ttlSeconds,
|
|
1241
|
+
...params.lockKeyPrefix !== void 0 ? { lockKeyPrefix: params.lockKeyPrefix } : {}
|
|
1242
|
+
}, void 0, params.signal);
|
|
1243
|
+
}
|
|
1244
|
+
async ɵgetActiveJoinCode(params) {
|
|
1245
|
+
const qs = new URLSearchParams({ userId: params.userId }).toString();
|
|
1246
|
+
return this.#request("GET", `/api/threads/${encodeURIComponent(params.threadId)}/join-code?${qs}`);
|
|
1247
|
+
}
|
|
1248
|
+
async ɵconnectThread(params) {
|
|
1249
|
+
return await this.#request("POST", `/api/threads/${encodeURIComponent(params.threadId)}/connect`, {
|
|
1250
|
+
userId: params.userId,
|
|
1251
|
+
agentId: params.agentId
|
|
1252
|
+
}) ?? null;
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
/**
|
|
1256
|
+
* Normalize a configured URL to "provided" or "not provided". A blank string
|
|
1257
|
+
* counts as not provided: these URLs are typically wired from environment
|
|
1258
|
+
* variables, and a declared-but-empty variable (`COPILOTKIT_INTELLIGENCE_URL=`,
|
|
1259
|
+
* common in generated `.env` files and container configs) arrives as `""`. Left
|
|
1260
|
+
* as-is it would produce host-relative requests instead of falling back to the
|
|
1261
|
+
* managed platform.
|
|
1262
|
+
*/
|
|
1263
|
+
function configuredUrl(url) {
|
|
1264
|
+
const trimmed = url?.trim();
|
|
1265
|
+
return trimmed ? trimmed : void 0;
|
|
1266
|
+
}
|
|
1267
|
+
/**
|
|
1268
|
+
* Reject an Intelligence project API key that carries no credential.
|
|
1269
|
+
*
|
|
1270
|
+
* `apiKey` is required on the config type, so TypeScript catches an absent
|
|
1271
|
+
* property. It does not catch an empty one, and the common shape is a
|
|
1272
|
+
* `process.env` read that TypeScript is told to trust — `?? ""` in the starter
|
|
1273
|
+
* wiring block, `!` in this file's own examples. When the variable is unset,
|
|
1274
|
+
* both produce a blank key that is sent verbatim as `Authorization: Bearer `
|
|
1275
|
+
* and fails much later as a 401 that points at nothing.
|
|
1276
|
+
*
|
|
1277
|
+
* A runtime with no credential cannot serve managed Intelligence, so this
|
|
1278
|
+
* throws at construction: callers build the client during boot, which puts the
|
|
1279
|
+
* error at startup rather than on a user's first message.
|
|
1280
|
+
*/
|
|
1281
|
+
function assertConfiguredApiKey(apiKey) {
|
|
1282
|
+
if (typeof apiKey === "string" && apiKey.trim() !== "") return;
|
|
1283
|
+
throw new Error("CopilotKitIntelligence `apiKey` is required and cannot be blank. It is the CopilotKit Intelligence project API key, normally read from the CPK_INTELLIGENCE_API_KEY environment variable. Run `copilotkit project select` to provision one for your project.");
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Warn when exactly one of `apiUrl`/`wsUrl` is configured. The API and realtime
|
|
1287
|
+
* planes are separate hosts, so a lone override silently leaves the other plane
|
|
1288
|
+
* on CopilotKit's managed platform — a self-hosted API paired with the managed
|
|
1289
|
+
* gateway (or vice versa), which fails as a hang rather than an error.
|
|
1290
|
+
*/
|
|
1291
|
+
function warnOnPartialHostOverride(apiUrl, wsUrl) {
|
|
1292
|
+
if (apiUrl && !wsUrl) {
|
|
1293
|
+
_copilotkit_shared.logger.warn(`CopilotKitIntelligence: apiUrl is set to "${apiUrl}" but wsUrl is not, so wsUrl falls back to the managed default "${MANAGED_INTELLIGENCE_WS_URL}". The API and realtime planes are separate hosts — set both when pointing at a self-hosted deployment.`);
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
if (wsUrl && !apiUrl) _copilotkit_shared.logger.warn(`CopilotKitIntelligence: wsUrl is set to "${wsUrl}" but apiUrl is not, so apiUrl falls back to the managed default "${MANAGED_INTELLIGENCE_API_URL}". The API and realtime planes are separate hosts — set both when pointing at a self-hosted deployment.`);
|
|
1297
|
+
}
|
|
1298
|
+
function normalizeIntelligenceWsUrl(wsUrl) {
|
|
1299
|
+
return wsUrl.replace(/\/$/, "");
|
|
1300
|
+
}
|
|
1301
|
+
function deriveRunnerWsUrl(wsUrl) {
|
|
1302
|
+
if (wsUrl.endsWith("/runner")) return wsUrl;
|
|
1303
|
+
if (wsUrl.endsWith("/client")) return `${wsUrl.slice(0, -7)}/runner`;
|
|
1304
|
+
if (wsUrl.endsWith("/channels")) return `${wsUrl.slice(0, -9)}/runner`;
|
|
1305
|
+
return `${wsUrl}/runner`;
|
|
1306
|
+
}
|
|
1307
|
+
/** A system error code such as ECONNREFUSED, or undefined for anything else. */
|
|
1308
|
+
function networkErrorCode(cause) {
|
|
1309
|
+
const code = typeof cause === "object" && cause !== null && "code" in cause ? cause.code : void 0;
|
|
1310
|
+
return typeof code === "string" && /^[A-Z][A-Z0-9_]{0,63}$/.test(code) ? code : void 0;
|
|
1311
|
+
}
|
|
1312
|
+
/** The host of a URL without its credentials, path or query. */
|
|
1313
|
+
function urlHost(url) {
|
|
1314
|
+
try {
|
|
1315
|
+
return new URL(url).host;
|
|
1316
|
+
} catch {
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
function deriveClientWsUrl(wsUrl) {
|
|
1321
|
+
if (wsUrl.endsWith("/client")) return wsUrl;
|
|
1322
|
+
if (wsUrl.endsWith("/runner")) return `${wsUrl.slice(0, -7)}/client`;
|
|
1323
|
+
if (wsUrl.endsWith("/channels")) return `${wsUrl.slice(0, -9)}/client`;
|
|
1324
|
+
return `${wsUrl}/client`;
|
|
1325
|
+
}
|
|
1326
|
+
function deriveChannelsWsUrl(wsUrl) {
|
|
1327
|
+
if (wsUrl.endsWith("/channels")) return wsUrl;
|
|
1328
|
+
if (wsUrl.endsWith("/runner")) return `${wsUrl.slice(0, -7)}/channels`;
|
|
1329
|
+
if (wsUrl.endsWith("/client")) return `${wsUrl.slice(0, -7)}/channels`;
|
|
1330
|
+
return `${wsUrl}/channels`;
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
//#endregion
|
|
1334
|
+
exports.CopilotKitIntelligence = CopilotKitIntelligence;
|
|
1335
|
+
exports.INTELLIGENCE_MEMORY_GRANT_HEADER = INTELLIGENCE_MEMORY_GRANT_HEADER;
|
|
1336
|
+
exports.INTELLIGENCE_USER_ID_HEADER = INTELLIGENCE_USER_ID_HEADER;
|
|
1337
|
+
exports.PlatformRequestError = PlatformRequestError;
|
|
1338
|
+
//# sourceMappingURL=client.cjs.map
|