@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,734 @@
|
|
|
1
|
+
import { AgentRunner, ThreadAccessDeniedError, ThreadAlreadyRunningError, ɵSERVER_THREAD_OWNER, ɵresolveThreadOwner } from "./agent-runner.mjs";
|
|
2
|
+
import { finalizeRunEvents } from "@copilotkit/shared";
|
|
3
|
+
import { ReplaySubject } from "rxjs";
|
|
4
|
+
import { EventType, compactEvents } from "@ag-ui/client";
|
|
5
|
+
|
|
6
|
+
//#region src/runtime/runner/in-memory.ts
|
|
7
|
+
const ɵINMEMORY_DEFAULTS = {
|
|
8
|
+
maxThreads: 1e3,
|
|
9
|
+
maxRunsPerThread: 100,
|
|
10
|
+
maxBytes: 512 * 1024 ** 2
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A limit value is well-formed iff it is a non-negative integer OR `+Infinity`.
|
|
14
|
+
* `+Infinity` is the documented "disabled/unbounded" sentinel and `0` is the
|
|
15
|
+
* documented run-cap disable sentinel; both are non-negative and pass. Every
|
|
16
|
+
* enforcement site (`evictThreadsIfNeeded`, `enforceRunCap`,
|
|
17
|
+
* `evictByBytesIfNeeded`) compares its counter against the limit with `>` in a
|
|
18
|
+
* `while`/`if` guard, so only these shapes keep those loops finite and correct.
|
|
19
|
+
* Rejected: negatives (drive `count > -1` true on an empty collection, so
|
|
20
|
+
* `enforceRunCap` `shift()!`s `undefined` and throws), `-Infinity` (loops never
|
|
21
|
+
* terminate their intent — always "over"), `NaN` (every `>` is false, silently
|
|
22
|
+
* disabling the bound), and non-integer finites (fractional caps are nonsense).
|
|
23
|
+
*/
|
|
24
|
+
function ɵisValidLimit(value) {
|
|
25
|
+
return value === Infinity || Number.isInteger(value) && value >= 0;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Normalize a fully-resolved limits bag so every field is well-formed before it
|
|
29
|
+
* can reach an enforcement loop. Each field is validated independently against
|
|
30
|
+
* {@link ɵisValidLimit}; an invalid value is CLAMPED to its
|
|
31
|
+
* {@link ɵINMEMORY_DEFAULTS} floor and a single `console.warn` naming the field
|
|
32
|
+
* and the received value is emitted.
|
|
33
|
+
*
|
|
34
|
+
* Clamp-and-warn (rather than throw) is deliberate and matches this file's
|
|
35
|
+
* established posture toward bad input: `ɵestimateBytes` swallows serialization
|
|
36
|
+
* failures and returns 0, the limits-clobber path warns rather than throwing,
|
|
37
|
+
* and both the eviction and clobber logs are wrapped so "logging must never
|
|
38
|
+
* break construction/a run". Constructing a bounded in-memory runner is a
|
|
39
|
+
* best-effort, non-durable convenience; a typo'd bound must degrade to a safe
|
|
40
|
+
* default, never abort construction or (worse) surface later as an unhandled
|
|
41
|
+
* rejection from the fire-and-forget finalize path.
|
|
42
|
+
*/
|
|
43
|
+
function ɵnormalizeLimits(limits) {
|
|
44
|
+
const normalized = { ...limits };
|
|
45
|
+
for (const field of Object.keys(ɵINMEMORY_DEFAULTS)) {
|
|
46
|
+
const value = limits[field];
|
|
47
|
+
if (!ɵisValidLimit(value)) {
|
|
48
|
+
const fallback = ɵINMEMORY_DEFAULTS[field];
|
|
49
|
+
normalized[field] = fallback;
|
|
50
|
+
try {
|
|
51
|
+
console.warn(`[CopilotKit] InMemoryAgentRunner: invalid ${field} value ${String(value)} (expected a non-negative integer or Infinity); falling back to ${String(fallback)}.`);
|
|
52
|
+
} catch {}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return normalized;
|
|
56
|
+
}
|
|
57
|
+
const EVICTION_GUIDANCE = "[CopilotKit] InMemoryAgentRunner evicted in-memory thread history to stay under memory limits. This runner is bounded and non-durable by design. For durable or production threads, configure an Intelligence backend.";
|
|
58
|
+
const LIMITS_CLOBBER_GUIDANCE = "[CopilotKit] InMemoryAgentRunner was constructed with in-memory limits that differ from the already-configured process-global store; the last-constructed runner's limits apply to ALL in-memory threads (the store is shared per-process). Configure a single consistent set of limits, or use an Intelligence backend for isolated bounds.";
|
|
59
|
+
/**
|
|
60
|
+
* Best-effort approximate byte size of a value, via serialized length.
|
|
61
|
+
* Never throws — returns 0 when the value cannot be serialized. This is an
|
|
62
|
+
* approximation (UTF-16 length, not exact heap bytes), used only for relative
|
|
63
|
+
* accounting against `maxBytes`.
|
|
64
|
+
*/
|
|
65
|
+
function ɵestimateBytes(value) {
|
|
66
|
+
try {
|
|
67
|
+
return JSON.stringify(value)?.length ?? 0;
|
|
68
|
+
} catch {
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
var InMemoryEventStore = class {
|
|
73
|
+
/**
|
|
74
|
+
* @param ownerId Identity that owns this thread, recorded when the thread is
|
|
75
|
+
* created by its first run. `""` is the anonymous owner;
|
|
76
|
+
* {@link ɵSERVER_THREAD_OWNER} is the owner of a thread created server-side.
|
|
77
|
+
*/
|
|
78
|
+
constructor(threadId, ownerId) {
|
|
79
|
+
this.threadId = threadId;
|
|
80
|
+
this.ownerId = ownerId;
|
|
81
|
+
this.subject = null;
|
|
82
|
+
this.isRunning = false;
|
|
83
|
+
this.currentRunId = null;
|
|
84
|
+
this.historicRuns = [];
|
|
85
|
+
this.agent = null;
|
|
86
|
+
this.runSubject = null;
|
|
87
|
+
this.stopRequested = false;
|
|
88
|
+
this.activeFinalize = null;
|
|
89
|
+
this.currentEvents = null;
|
|
90
|
+
this.messagesSnapshot = [];
|
|
91
|
+
this.approxMessagesSnapshotBytes = 0;
|
|
92
|
+
this.createdAt = null;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* True when a caller acting as `owner` may reach `store`: only the thread's
|
|
97
|
+
* own owner may. Resolve an optional owner or scope with
|
|
98
|
+
* {@link ɵresolveThreadOwner} first; an omitted one is the server owner, never
|
|
99
|
+
* "every thread".
|
|
100
|
+
*/
|
|
101
|
+
function isVisibleTo(store, owner) {
|
|
102
|
+
return store.ownerId === owner;
|
|
103
|
+
}
|
|
104
|
+
/** The owner a Thread endpoint call acts as. */
|
|
105
|
+
function scopeOwner(scope) {
|
|
106
|
+
return ɵresolveThreadOwner(scope?.ownerId);
|
|
107
|
+
}
|
|
108
|
+
const ɵOWNER_RETENTION_DEFAULTS = {
|
|
109
|
+
ttlMs: 1440 * 60 * 1e3,
|
|
110
|
+
maxEntries: 1e5,
|
|
111
|
+
maxEntriesPerOwner: 1e4,
|
|
112
|
+
now: () => Date.now()
|
|
113
|
+
};
|
|
114
|
+
var ɵBoundedThreadStore = class {
|
|
115
|
+
constructor(limits) {
|
|
116
|
+
this.map = /* @__PURE__ */ new Map();
|
|
117
|
+
this.removedOwners = /* @__PURE__ */ new Map();
|
|
118
|
+
this.removedOwnersByOwner = /* @__PURE__ */ new Map();
|
|
119
|
+
this.ownerRetention = ɵOWNER_RETENTION_DEFAULTS;
|
|
120
|
+
this.totalBytes = 0;
|
|
121
|
+
this.warned = false;
|
|
122
|
+
this.limitsExplicitlySet = false;
|
|
123
|
+
this.clobberWarned = false;
|
|
124
|
+
this.limits = ɵnormalizeLimits(limits);
|
|
125
|
+
}
|
|
126
|
+
get byteTotal() {
|
|
127
|
+
return this.totalBytes;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The store's CURRENT effective bounds. Exposed (with the `ɵ` internal-API
|
|
131
|
+
* prefix) so a partial `setLimits` can coalesce unspecified fields against the
|
|
132
|
+
* live config rather than the hardcoded {@link ɵINMEMORY_DEFAULTS} — a partial
|
|
133
|
+
* update must be a partial update, never a silent reset of the fields the
|
|
134
|
+
* caller did not mention. Returns a copy so callers cannot mutate the store's
|
|
135
|
+
* bounds through it.
|
|
136
|
+
*/
|
|
137
|
+
get ɵlimits() {
|
|
138
|
+
return { ...this.limits };
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Reconfigure the process-global store's bounds. Called by the
|
|
142
|
+
* {@link InMemoryAgentRunner} constructor when limits are passed. Because the
|
|
143
|
+
* store is a per-process singleton, this replaces the bounds for ALL in-memory
|
|
144
|
+
* threads. Emits {@link LIMITS_CLOBBER_GUIDANCE} at most ONCE per store when a
|
|
145
|
+
* SECOND (or later) explicit set arrives whose resolved values differ from the
|
|
146
|
+
* prior explicit set — i.e. a genuine clobber of an already-customized config.
|
|
147
|
+
* The first explicit customization (defaults → custom) is the intended
|
|
148
|
+
* override and never warns; identical re-sets never warn.
|
|
149
|
+
*/
|
|
150
|
+
setLimits(limits) {
|
|
151
|
+
const normalized = ɵnormalizeLimits(limits);
|
|
152
|
+
if (this.limitsExplicitlySet && !this.clobberWarned && (normalized.maxThreads !== this.limits.maxThreads || normalized.maxRunsPerThread !== this.limits.maxRunsPerThread || normalized.maxBytes !== this.limits.maxBytes)) {
|
|
153
|
+
this.clobberWarned = true;
|
|
154
|
+
try {
|
|
155
|
+
console.warn(LIMITS_CLOBBER_GUIDANCE);
|
|
156
|
+
} catch {}
|
|
157
|
+
}
|
|
158
|
+
this.limitsExplicitlySet = true;
|
|
159
|
+
this.limits = normalized;
|
|
160
|
+
}
|
|
161
|
+
get size() {
|
|
162
|
+
return this.map.size;
|
|
163
|
+
}
|
|
164
|
+
/** Re-insert at the tail so Map iteration order stays LRU-first. */
|
|
165
|
+
touchOrder(threadId, store) {
|
|
166
|
+
this.map.delete(threadId);
|
|
167
|
+
this.map.set(threadId, store);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The thread's store, created and owned by `ownerId` when it does not exist
|
|
171
|
+
* yet. An existing store keeps its owner; callers check access first.
|
|
172
|
+
*/
|
|
173
|
+
getOrCreate(threadId, ownerId = ɵSERVER_THREAD_OWNER) {
|
|
174
|
+
const existing = this.map.get(threadId);
|
|
175
|
+
if (existing) {
|
|
176
|
+
this.touchOrder(threadId, existing);
|
|
177
|
+
return existing;
|
|
178
|
+
}
|
|
179
|
+
const store = new InMemoryEventStore(threadId, ownerId);
|
|
180
|
+
this.forgetOwner(threadId);
|
|
181
|
+
this.map.set(threadId, store);
|
|
182
|
+
this.evictThreadsIfNeeded(threadId);
|
|
183
|
+
return store;
|
|
184
|
+
}
|
|
185
|
+
get(threadId, opts) {
|
|
186
|
+
const store = this.map.get(threadId);
|
|
187
|
+
if (store && opts.touch) this.touchOrder(threadId, store);
|
|
188
|
+
return store;
|
|
189
|
+
}
|
|
190
|
+
peek(threadId) {
|
|
191
|
+
return this.map.get(threadId);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Evict the least-recently-used thread that is neither running NOR
|
|
195
|
+
* mid-finalization. Returns false if none evictable. The `protect` thread
|
|
196
|
+
* (typically the one just created) is never evicted, so a fresh thread is not
|
|
197
|
+
* immediately dropped when it is the only non-running candidate.
|
|
198
|
+
*
|
|
199
|
+
* A thread is skipped while `isRunning` OR `stopRequested` is set.
|
|
200
|
+
* `stop()` flips `isRunning` to false the moment it aborts the agent, but the
|
|
201
|
+
* run keeps finalizing asynchronously (the abort trips the `catch` in
|
|
202
|
+
* `runAgent`, which later calls `appendRun`). During that window
|
|
203
|
+
* `stopRequested` stays true; evicting the thread then would make the pending
|
|
204
|
+
* `appendRun` hit `if (!store) return` and silently drop the aborted run's
|
|
205
|
+
* history. Guarding on `stopRequested` keeps the thread alive until
|
|
206
|
+
* finalization completes.
|
|
207
|
+
*/
|
|
208
|
+
evictOneLru(protect) {
|
|
209
|
+
for (const [threadId, store] of this.map) {
|
|
210
|
+
if (threadId === protect) continue;
|
|
211
|
+
if (store.isRunning || store.stopRequested) continue;
|
|
212
|
+
this.removeThread(threadId, store);
|
|
213
|
+
this.noteEviction();
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Append a finished run to `writer`, the store its run started on. Nothing is
|
|
220
|
+
* written when `writer` is no longer the live store for `threadId` (the thread
|
|
221
|
+
* was removed, or removed and claimed again): a run must never write into a
|
|
222
|
+
* thread it did not start on, which may now belong to another owner.
|
|
223
|
+
*/
|
|
224
|
+
appendRun(threadId, writer, run) {
|
|
225
|
+
const store = this.map.get(threadId);
|
|
226
|
+
if (!store || store !== writer) return;
|
|
227
|
+
if (store.createdAt === null) store.createdAt = run.createdAt;
|
|
228
|
+
if (run.messages.length > 0) {
|
|
229
|
+
this.totalBytes -= store.approxMessagesSnapshotBytes;
|
|
230
|
+
store.messagesSnapshot = run.messages;
|
|
231
|
+
store.approxMessagesSnapshotBytes = ɵestimateBytes(run.messages);
|
|
232
|
+
this.totalBytes += store.approxMessagesSnapshotBytes;
|
|
233
|
+
}
|
|
234
|
+
run.messages = [];
|
|
235
|
+
run.approxMessageBytes = 0;
|
|
236
|
+
run.approxEventBytes = ɵestimateBytes(run.events);
|
|
237
|
+
store.historicRuns.push(run);
|
|
238
|
+
this.totalBytes += run.approxEventBytes;
|
|
239
|
+
this.touchOrder(threadId, store);
|
|
240
|
+
this.enforceRunCap(store);
|
|
241
|
+
this.evictByBytesIfNeeded(threadId);
|
|
242
|
+
}
|
|
243
|
+
enforceRunCap(store) {
|
|
244
|
+
const cap = this.limits.maxRunsPerThread;
|
|
245
|
+
if (!cap || cap === Infinity) return;
|
|
246
|
+
while (store.historicRuns.length > cap) {
|
|
247
|
+
const dropped = store.historicRuns.shift();
|
|
248
|
+
this.totalBytes -= dropped.approxEventBytes ?? 0;
|
|
249
|
+
this.noteEviction();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Trim the store back under the byte ceiling by evicting LRU non-running
|
|
254
|
+
* threads. `protect` (the just-appended thread) is never self-evicted, so a
|
|
255
|
+
* fresh run pushes OTHER threads out rather than dropping itself.
|
|
256
|
+
*/
|
|
257
|
+
evictByBytesIfNeeded(protect) {
|
|
258
|
+
while (this.totalBytes > this.limits.maxBytes) if (!this.evictOneLru(protect)) break;
|
|
259
|
+
}
|
|
260
|
+
removeThread(threadId, store) {
|
|
261
|
+
for (const run of store.historicRuns) this.totalBytes -= run.approxEventBytes ?? 0;
|
|
262
|
+
this.totalBytes -= store.approxMessagesSnapshotBytes;
|
|
263
|
+
this.map.delete(threadId);
|
|
264
|
+
this.rememberOwner(threadId, store.ownerId);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Keep the owner of a removed thread, within the retention bounds. See
|
|
268
|
+
* {@link ɵOwnerRetention} for which records go first over a limit.
|
|
269
|
+
*/
|
|
270
|
+
rememberOwner(threadId, ownerId) {
|
|
271
|
+
const { maxEntries, maxEntriesPerOwner, now } = this.ownerRetention;
|
|
272
|
+
this.forgetOwner(threadId);
|
|
273
|
+
this.removedOwners.set(threadId, {
|
|
274
|
+
ownerId,
|
|
275
|
+
removedAt: now()
|
|
276
|
+
});
|
|
277
|
+
let owned = this.removedOwnersByOwner.get(ownerId);
|
|
278
|
+
if (!owned) {
|
|
279
|
+
owned = /* @__PURE__ */ new Set();
|
|
280
|
+
this.removedOwnersByOwner.set(ownerId, owned);
|
|
281
|
+
}
|
|
282
|
+
owned.add(threadId);
|
|
283
|
+
this.pruneRemovedOwners();
|
|
284
|
+
while (owned.size > maxEntriesPerOwner) {
|
|
285
|
+
const oldest = owned.values().next().value;
|
|
286
|
+
if (oldest === void 0) break;
|
|
287
|
+
this.forgetOwner(oldest);
|
|
288
|
+
}
|
|
289
|
+
while (this.removedOwners.size > maxEntries) {
|
|
290
|
+
const oldest = this.removedOwners.keys().next().value;
|
|
291
|
+
if (oldest === void 0) break;
|
|
292
|
+
this.forgetOwner(oldest);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/** Remove the owner record of `threadId`, if any. */
|
|
296
|
+
forgetOwner(threadId) {
|
|
297
|
+
const record = this.removedOwners.get(threadId);
|
|
298
|
+
if (!record) return;
|
|
299
|
+
this.removedOwners.delete(threadId);
|
|
300
|
+
const owned = this.removedOwnersByOwner.get(record.ownerId);
|
|
301
|
+
owned?.delete(threadId);
|
|
302
|
+
if (owned?.size === 0) this.removedOwnersByOwner.delete(record.ownerId);
|
|
303
|
+
}
|
|
304
|
+
/** Drop expired owner records. They are oldest first, so stop at the first live one. */
|
|
305
|
+
pruneRemovedOwners() {
|
|
306
|
+
const { ttlMs, now } = this.ownerRetention;
|
|
307
|
+
const cutoff = now() - ttlMs;
|
|
308
|
+
for (const [threadId, record] of this.removedOwners) {
|
|
309
|
+
if (record.removedAt >= cutoff) break;
|
|
310
|
+
this.forgetOwner(threadId);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Owner of `threadId`: the live thread's owner, or the retained owner of a
|
|
315
|
+
* thread that was evicted or cleared. `undefined` when nobody owns the id, so
|
|
316
|
+
* the next run may claim it.
|
|
317
|
+
*/
|
|
318
|
+
ownerOf(threadId) {
|
|
319
|
+
const store = this.map.get(threadId);
|
|
320
|
+
if (store) return store.ownerId;
|
|
321
|
+
this.pruneRemovedOwners();
|
|
322
|
+
const record = this.removedOwners.get(threadId);
|
|
323
|
+
if (!record) return void 0;
|
|
324
|
+
const { ttlMs, now } = this.ownerRetention;
|
|
325
|
+
if (record.removedAt < now() - ttlMs) {
|
|
326
|
+
this.forgetOwner(threadId);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
return record.ownerId;
|
|
330
|
+
}
|
|
331
|
+
/** True when a caller acting as `owner` may run on, or claim, `threadId`. */
|
|
332
|
+
canClaim(threadId, owner) {
|
|
333
|
+
const current = this.ownerOf(threadId);
|
|
334
|
+
return current === void 0 || current === owner;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Replace the owner-record retention. Omitted fields fall back to
|
|
338
|
+
* {@link ɵOWNER_RETENTION_DEFAULTS}. Internal: for tests.
|
|
339
|
+
*/
|
|
340
|
+
ɵsetOwnerRetention(retention) {
|
|
341
|
+
this.ownerRetention = {
|
|
342
|
+
...ɵOWNER_RETENTION_DEFAULTS,
|
|
343
|
+
...retention
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
evictThreadsIfNeeded(protect) {
|
|
347
|
+
while (this.map.size > this.limits.maxThreads) if (!this.evictOneLru(protect)) break;
|
|
348
|
+
}
|
|
349
|
+
noteEviction() {
|
|
350
|
+
if (this.warned) return;
|
|
351
|
+
this.warned = true;
|
|
352
|
+
try {
|
|
353
|
+
console.warn(EVICTION_GUIDANCE);
|
|
354
|
+
} catch {}
|
|
355
|
+
}
|
|
356
|
+
listThreads(scope) {
|
|
357
|
+
const threads = [];
|
|
358
|
+
for (const [threadId, store] of this.map) {
|
|
359
|
+
if (store.historicRuns.length === 0) continue;
|
|
360
|
+
if (!isVisibleTo(store, scopeOwner(scope))) continue;
|
|
361
|
+
const lastRun = store.historicRuns[store.historicRuns.length - 1];
|
|
362
|
+
threads.push({
|
|
363
|
+
id: threadId,
|
|
364
|
+
name: null,
|
|
365
|
+
agentId: lastRun.agentId,
|
|
366
|
+
organizationId: "",
|
|
367
|
+
createdById: store.ownerId,
|
|
368
|
+
archived: false,
|
|
369
|
+
createdAt: new Date(store.createdAt ?? lastRun.createdAt).toISOString(),
|
|
370
|
+
updatedAt: new Date(lastRun.createdAt).toISOString()
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
return threads.sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Removes every thread visible to `scope`, except threads that are running
|
|
377
|
+
* or still finalizing: removing one would drop its owner record while its
|
|
378
|
+
* run still writes, so another identity could claim the id. Those threads
|
|
379
|
+
* stay, as in `evictOneLru`. A scoped clear leaves other owners' threads
|
|
380
|
+
* untouched.
|
|
381
|
+
*
|
|
382
|
+
* Without a scope the whole store is reset, running threads included. That
|
|
383
|
+
* is an internal reset for tests; `appendRun` keeps an orphaned run from
|
|
384
|
+
* writing into a thread created after the reset.
|
|
385
|
+
*/
|
|
386
|
+
clear(scope) {
|
|
387
|
+
if (scope !== void 0) {
|
|
388
|
+
for (const [threadId, store] of this.map) {
|
|
389
|
+
if (store.isRunning || store.stopRequested) continue;
|
|
390
|
+
if (isVisibleTo(store, scopeOwner(scope))) this.removeThread(threadId, store);
|
|
391
|
+
}
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
this.map.clear();
|
|
395
|
+
this.removedOwners.clear();
|
|
396
|
+
this.removedOwnersByOwner.clear();
|
|
397
|
+
this.totalBytes = 0;
|
|
398
|
+
this.warned = false;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
/**
|
|
402
|
+
* Process-wide singleton backing every {@link InMemoryAgentRunner}. Exported
|
|
403
|
+
* (with the `ɵ` internal-API prefix) so tests can inspect the exact store the
|
|
404
|
+
* runner writes to; not part of the public API.
|
|
405
|
+
*/
|
|
406
|
+
const ɵGLOBAL_STORE = new ɵBoundedThreadStore(ɵINMEMORY_DEFAULTS);
|
|
407
|
+
const sharedStore = ɵGLOBAL_STORE;
|
|
408
|
+
var InMemoryAgentRunner = class extends AgentRunner {
|
|
409
|
+
/**
|
|
410
|
+
* @param options Per-runner behavior (`onConcurrentRun`) plus optional bounds
|
|
411
|
+
* for the in-memory store ({@link InMemoryLimits}).
|
|
412
|
+
*
|
|
413
|
+
* Note the differing scopes: `onConcurrentRun` is per-runner instance, while
|
|
414
|
+
* the limits reconfigure the PROCESS-GLOBAL store shared by every
|
|
415
|
+
* `InMemoryAgentRunner`. Omit the limits for safe defaults
|
|
416
|
+
* ({@link ɵINMEMORY_DEFAULTS}); passing none leaves the store untouched. When
|
|
417
|
+
* multiple runners are constructed with differing limits, the last-constructed
|
|
418
|
+
* wins — in practice the OSS/SSE default construction passes nothing. If a
|
|
419
|
+
* second (or later) runner is constructed with limits that DIFFER from an
|
|
420
|
+
* already-customized store, a one-time `console.warn` is emitted to signal that
|
|
421
|
+
* the shared store's bounds are being clobbered for ALL in-memory threads.
|
|
422
|
+
*/
|
|
423
|
+
constructor(options) {
|
|
424
|
+
super();
|
|
425
|
+
this.ɵsupportsLocalThreadEndpoints = true;
|
|
426
|
+
const { onConcurrentRun, ...limits } = options ?? {};
|
|
427
|
+
this.onConcurrentRun = onConcurrentRun ?? "throw";
|
|
428
|
+
if (limits.maxThreads !== void 0 || limits.maxRunsPerThread !== void 0 || limits.maxBytes !== void 0) {
|
|
429
|
+
const current = sharedStore.ɵlimits;
|
|
430
|
+
sharedStore.setLimits({
|
|
431
|
+
maxThreads: limits.maxThreads ?? current.maxThreads,
|
|
432
|
+
maxRunsPerThread: limits.maxRunsPerThread ?? current.maxRunsPerThread,
|
|
433
|
+
maxBytes: limits.maxBytes ?? current.maxBytes
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
run(request) {
|
|
438
|
+
const owner = ɵresolveThreadOwner(request.ownerId);
|
|
439
|
+
if (!sharedStore.canClaim(request.threadId, owner)) throw new ThreadAccessDeniedError();
|
|
440
|
+
const store = sharedStore.getOrCreate(request.threadId, owner);
|
|
441
|
+
if (store.isRunning || store.stopRequested) {
|
|
442
|
+
if (this.onConcurrentRun !== "supersede") throw new ThreadAlreadyRunningError();
|
|
443
|
+
const priorAgent = store.agent;
|
|
444
|
+
const priorFinalize = store.activeFinalize;
|
|
445
|
+
if (priorFinalize) priorFinalize.stopRequested = true;
|
|
446
|
+
store.isRunning = false;
|
|
447
|
+
if (priorAgent) try {
|
|
448
|
+
priorAgent.abortRun();
|
|
449
|
+
} catch (error) {
|
|
450
|
+
console.error("Failed to abort superseded run", error);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
store.isRunning = true;
|
|
454
|
+
store.currentRunId = request.input.runId;
|
|
455
|
+
store.agent = request.agent;
|
|
456
|
+
store.stopRequested = false;
|
|
457
|
+
const finalizeControl = { stopRequested: false };
|
|
458
|
+
store.activeFinalize = finalizeControl;
|
|
459
|
+
const seenMessageIds = /* @__PURE__ */ new Set();
|
|
460
|
+
const currentRunEvents = [];
|
|
461
|
+
store.currentEvents = currentRunEvents;
|
|
462
|
+
const historicMessageIds = /* @__PURE__ */ new Set();
|
|
463
|
+
for (const run of store.historicRuns) for (const event of run.events) {
|
|
464
|
+
if ("messageId" in event && typeof event.messageId === "string") historicMessageIds.add(event.messageId);
|
|
465
|
+
if (event.type === EventType.RUN_STARTED) {
|
|
466
|
+
const messages = event.input?.messages ?? [];
|
|
467
|
+
for (const message of messages) historicMessageIds.add(message.id);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
const nextSubject = new ReplaySubject(Infinity);
|
|
471
|
+
store.subject = nextSubject;
|
|
472
|
+
const runSubject = new ReplaySubject(Infinity);
|
|
473
|
+
store.runSubject = runSubject;
|
|
474
|
+
const runAgent = async () => {
|
|
475
|
+
const parentRunId = store.historicRuns[store.historicRuns.length - 1]?.runId ?? null;
|
|
476
|
+
const finalizeRun = (opts) => {
|
|
477
|
+
const isError = opts.interruptionMessage !== void 0;
|
|
478
|
+
const preFinalizeEventCount = currentRunEvents.length;
|
|
479
|
+
if (finalizeControl.stopRequested && !currentRunEvents.some((event) => event.type === EventType.RUN_STARTED)) {
|
|
480
|
+
const started = {
|
|
481
|
+
type: EventType.RUN_STARTED,
|
|
482
|
+
threadId: request.threadId,
|
|
483
|
+
runId: request.input.runId,
|
|
484
|
+
input: {
|
|
485
|
+
...request.input,
|
|
486
|
+
messages: request.input.messages.filter((message) => !historicMessageIds.has(message.id))
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
currentRunEvents.unshift(started);
|
|
490
|
+
runSubject.next(started);
|
|
491
|
+
nextSubject.next(started);
|
|
492
|
+
}
|
|
493
|
+
const appendedEvents = finalizeRunEvents(currentRunEvents, {
|
|
494
|
+
stopRequested: finalizeControl.stopRequested,
|
|
495
|
+
protocolVersion: request.input.protocolVersion,
|
|
496
|
+
...isError ? { interruptionMessage: opts.interruptionMessage } : {}
|
|
497
|
+
});
|
|
498
|
+
for (const event of appendedEvents) {
|
|
499
|
+
runSubject.next(event);
|
|
500
|
+
nextSubject.next(event);
|
|
501
|
+
}
|
|
502
|
+
const ownsThread = store.currentRunId === request.input.runId;
|
|
503
|
+
if (ownsThread && (!isError || preFinalizeEventCount > 0 || finalizeControl.stopRequested)) {
|
|
504
|
+
const compactedEvents = compactEvents(currentRunEvents);
|
|
505
|
+
sharedStore.appendRun(request.threadId, store, {
|
|
506
|
+
threadId: request.threadId,
|
|
507
|
+
runId: request.input.runId,
|
|
508
|
+
agentId: request.agent.agentId ?? "default",
|
|
509
|
+
parentRunId,
|
|
510
|
+
events: compactedEvents,
|
|
511
|
+
messages: Array.isArray(request.agent.messages) ? [...request.agent.messages] : [],
|
|
512
|
+
createdAt: Date.now()
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
if (ownsThread) {
|
|
516
|
+
store.currentEvents = null;
|
|
517
|
+
store.currentRunId = null;
|
|
518
|
+
store.agent = null;
|
|
519
|
+
store.runSubject = null;
|
|
520
|
+
store.stopRequested = false;
|
|
521
|
+
store.isRunning = false;
|
|
522
|
+
store.activeFinalize = null;
|
|
523
|
+
}
|
|
524
|
+
runSubject.complete();
|
|
525
|
+
nextSubject.complete();
|
|
526
|
+
if (store.subject === nextSubject) store.subject = null;
|
|
527
|
+
};
|
|
528
|
+
try {
|
|
529
|
+
await request.agent.runAgent(request.input, {
|
|
530
|
+
onEvent: ({ event }) => {
|
|
531
|
+
let processedEvent = event;
|
|
532
|
+
if (event.type === EventType.RUN_STARTED) {
|
|
533
|
+
const runStartedEvent = event;
|
|
534
|
+
if (!runStartedEvent.input) {
|
|
535
|
+
const sanitizedMessages = request.input.messages ? request.input.messages.filter((message) => !historicMessageIds.has(message.id)) : void 0;
|
|
536
|
+
runStartedEvent.input = {
|
|
537
|
+
...request.input,
|
|
538
|
+
...sanitizedMessages !== void 0 ? { messages: sanitizedMessages } : {}
|
|
539
|
+
};
|
|
540
|
+
processedEvent = runStartedEvent;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
runSubject.next(processedEvent);
|
|
544
|
+
nextSubject.next(processedEvent);
|
|
545
|
+
currentRunEvents.push(processedEvent);
|
|
546
|
+
},
|
|
547
|
+
onNewMessage: ({ message }) => {
|
|
548
|
+
if (!seenMessageIds.has(message.id)) seenMessageIds.add(message.id);
|
|
549
|
+
},
|
|
550
|
+
onRunStartedEvent: () => {
|
|
551
|
+
if (request.input.messages) {
|
|
552
|
+
for (const message of request.input.messages) if (!seenMessageIds.has(message.id)) seenMessageIds.add(message.id);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
finalizeRun({});
|
|
557
|
+
} catch (error) {
|
|
558
|
+
finalizeRun({ interruptionMessage: error instanceof Error ? error.message : String(error) });
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
runAgent().catch((error) => {
|
|
562
|
+
console.error("Failed to finish agent run", {
|
|
563
|
+
threadId: request.threadId,
|
|
564
|
+
runId: request.input.runId
|
|
565
|
+
}, error);
|
|
566
|
+
if (store.currentRunId === request.input.runId) {
|
|
567
|
+
store.currentEvents = null;
|
|
568
|
+
store.currentRunId = null;
|
|
569
|
+
store.agent = null;
|
|
570
|
+
store.runSubject = null;
|
|
571
|
+
store.stopRequested = false;
|
|
572
|
+
store.isRunning = false;
|
|
573
|
+
store.activeFinalize = null;
|
|
574
|
+
}
|
|
575
|
+
runSubject.complete();
|
|
576
|
+
nextSubject.complete();
|
|
577
|
+
if (store.subject === nextSubject) store.subject = null;
|
|
578
|
+
});
|
|
579
|
+
return runSubject.asObservable();
|
|
580
|
+
}
|
|
581
|
+
connect(request) {
|
|
582
|
+
const found = sharedStore.peek(request.threadId);
|
|
583
|
+
const store = found && isVisibleTo(found, ɵresolveThreadOwner(request.ownerId)) ? sharedStore.get(request.threadId, { touch: true }) : void 0;
|
|
584
|
+
const connectionSubject = new ReplaySubject(Infinity);
|
|
585
|
+
if (!store) {
|
|
586
|
+
connectionSubject.complete();
|
|
587
|
+
return connectionSubject.asObservable();
|
|
588
|
+
}
|
|
589
|
+
const allHistoricEvents = [];
|
|
590
|
+
for (const run of store.historicRuns) allHistoricEvents.push(...run.events);
|
|
591
|
+
const compactedEvents = compactEvents(allHistoricEvents);
|
|
592
|
+
const emittedMessageIds = /* @__PURE__ */ new Set();
|
|
593
|
+
for (const event of compactedEvents) {
|
|
594
|
+
connectionSubject.next(event);
|
|
595
|
+
if ("messageId" in event && typeof event.messageId === "string") emittedMessageIds.add(event.messageId);
|
|
596
|
+
}
|
|
597
|
+
if (store.subject && (store.isRunning || store.stopRequested)) store.subject.subscribe({
|
|
598
|
+
next: (event) => {
|
|
599
|
+
if ("messageId" in event && typeof event.messageId === "string" && emittedMessageIds.has(event.messageId)) return;
|
|
600
|
+
connectionSubject.next(event);
|
|
601
|
+
},
|
|
602
|
+
complete: () => connectionSubject.complete(),
|
|
603
|
+
error: (err) => connectionSubject.error(err)
|
|
604
|
+
});
|
|
605
|
+
else connectionSubject.complete();
|
|
606
|
+
return connectionSubject.asObservable();
|
|
607
|
+
}
|
|
608
|
+
isRunning(request) {
|
|
609
|
+
const store = sharedStore.peek(request.threadId);
|
|
610
|
+
if (!store || !isVisibleTo(store, ɵresolveThreadOwner(request.ownerId))) return Promise.resolve(false);
|
|
611
|
+
return Promise.resolve(store.isRunning);
|
|
612
|
+
}
|
|
613
|
+
stop(request) {
|
|
614
|
+
const store = sharedStore.peek(request.threadId);
|
|
615
|
+
if (!store || !store.isRunning) return Promise.resolve(false);
|
|
616
|
+
if (!isVisibleTo(store, ɵresolveThreadOwner(request.ownerId))) return Promise.resolve(false);
|
|
617
|
+
if (request.runId !== void 0 && store.currentRunId !== request.runId) return Promise.resolve(false);
|
|
618
|
+
if (store.stopRequested) return Promise.resolve(false);
|
|
619
|
+
store.stopRequested = true;
|
|
620
|
+
store.isRunning = false;
|
|
621
|
+
const finalizeControl = store.activeFinalize;
|
|
622
|
+
if (finalizeControl) finalizeControl.stopRequested = true;
|
|
623
|
+
const agent = store.agent;
|
|
624
|
+
if (!agent) {
|
|
625
|
+
store.stopRequested = false;
|
|
626
|
+
store.isRunning = false;
|
|
627
|
+
if (finalizeControl) finalizeControl.stopRequested = false;
|
|
628
|
+
return Promise.resolve(false);
|
|
629
|
+
}
|
|
630
|
+
try {
|
|
631
|
+
agent.abortRun();
|
|
632
|
+
return Promise.resolve(true);
|
|
633
|
+
} catch (error) {
|
|
634
|
+
console.error("Failed to abort agent run", error);
|
|
635
|
+
store.stopRequested = false;
|
|
636
|
+
store.isRunning = true;
|
|
637
|
+
if (finalizeControl) finalizeControl.stopRequested = false;
|
|
638
|
+
return Promise.resolve(false);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Returns a summary of every thread that `scope`'s owner holds in the
|
|
643
|
+
* process-wide store, which every InMemoryAgentRunner shares. Without a
|
|
644
|
+
* scope, the server owner's threads ({@link ɵSERVER_THREAD_OWNER}).
|
|
645
|
+
*
|
|
646
|
+
* This powers the local-dev fallback for `GET /threads` when the Intelligence
|
|
647
|
+
* platform is not configured. Each entry mirrors the shape of a platform
|
|
648
|
+
* `ThreadRecord` so the HTTP handler can use the same response envelope.
|
|
649
|
+
*/
|
|
650
|
+
listThreads(scope) {
|
|
651
|
+
return sharedStore.listThreads(scope);
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Returns all messages for a thread, using the snapshot captured at the end
|
|
655
|
+
* of the most recent run.
|
|
656
|
+
*
|
|
657
|
+
* This powers the local-dev fallback for `GET /threads/:threadId/messages`
|
|
658
|
+
* when CopilotKit Intelligence is not configured. The returned `Message[]`
|
|
659
|
+
* objects come directly from the ag-ui agent, so their shape is compatible
|
|
660
|
+
* with CopilotKit Intelligence's `ThreadMessage` type.
|
|
661
|
+
*/
|
|
662
|
+
getThreadMessages(threadId, scope) {
|
|
663
|
+
const store = this.peekVisible(threadId, scope);
|
|
664
|
+
if (!store) return [];
|
|
665
|
+
return [...store.messagesSnapshot];
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Returns all AG-UI events for a thread, compacted across historic runs.
|
|
669
|
+
*
|
|
670
|
+
* Powers the local-dev fallback for `GET /threads/:threadId/events` when the
|
|
671
|
+
* CopilotKit Intelligence is not configured. The compaction logic matches
|
|
672
|
+
* the connection-replay path in {@link connect}, so the stream a
|
|
673
|
+
* late-joining inspector sees matches what this method returns.
|
|
674
|
+
*/
|
|
675
|
+
getThreadEvents(threadId, scope) {
|
|
676
|
+
const store = this.peekVisible(threadId, scope);
|
|
677
|
+
if (!store || store.historicRuns.length === 0) return [];
|
|
678
|
+
const all = [];
|
|
679
|
+
for (const run of store.historicRuns) all.push(...run.events);
|
|
680
|
+
return compactEvents(all);
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Returns the agent state snapshot for a thread.
|
|
684
|
+
*
|
|
685
|
+
* Derived from the last `STATE_SNAPSHOT` in the compacted event stream. The
|
|
686
|
+
* AG-UI `compactEvents` helper consolidates STATE_DELTA events and produces
|
|
687
|
+
* a single trailing STATE_SNAPSHOT when state changes exist, so this is a
|
|
688
|
+
* faithful view of state at the end of the most recent run.
|
|
689
|
+
*
|
|
690
|
+
* Returns `null` when the thread has never emitted a STATE_SNAPSHOT.
|
|
691
|
+
*/
|
|
692
|
+
getThreadState(threadId, scope) {
|
|
693
|
+
const events = this.getThreadEvents(threadId, scope);
|
|
694
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
695
|
+
const event = events[i];
|
|
696
|
+
if (event.type === EventType.STATE_SNAPSHOT) {
|
|
697
|
+
const snapshot = event.snapshot;
|
|
698
|
+
if (snapshot && typeof snapshot === "object" && !Array.isArray(snapshot)) return { ...snapshot };
|
|
699
|
+
return null;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return null;
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Clears the in-memory history of `scope`'s threads (without a scope, the
|
|
706
|
+
* server owner's). A thread with a run still active or finalizing is kept;
|
|
707
|
+
* see {@link ɵBoundedThreadStore.clear}.
|
|
708
|
+
*
|
|
709
|
+
* Powers the local-dev fallback for `POST /threads/clear`, letting consumers
|
|
710
|
+
* (e.g. the demo's Clear button) reset to an empty thread list without
|
|
711
|
+
* restarting the runtime. Intentionally not exposed on the Intelligence
|
|
712
|
+
* platform path: there, thread history lives in a real database and must
|
|
713
|
+
* not be wiped this way.
|
|
714
|
+
*/
|
|
715
|
+
clearThreads(scope) {
|
|
716
|
+
sharedStore.clear({ ownerId: scopeOwner(scope) });
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* False when the thread id is held by an owner other than `scope`'s: a
|
|
720
|
+
* live thread, or the retained owner of an evicted or cleared one.
|
|
721
|
+
*/
|
|
722
|
+
isThreadAccessible(threadId, scope) {
|
|
723
|
+
return sharedStore.canClaim(threadId, scopeOwner(scope));
|
|
724
|
+
}
|
|
725
|
+
/** The thread's store, or `undefined` when unknown or not visible to `scope`. */
|
|
726
|
+
peekVisible(threadId, scope) {
|
|
727
|
+
const store = sharedStore.peek(threadId);
|
|
728
|
+
return store && isVisibleTo(store, scopeOwner(scope)) ? store : void 0;
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
//#endregion
|
|
733
|
+
export { InMemoryAgentRunner, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵOWNER_RETENTION_DEFAULTS, ɵestimateBytes, ɵnormalizeLimits };
|
|
734
|
+
//# sourceMappingURL=in-memory.mjs.map
|