@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 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.cjs","names":["ɵresolveThreadOwner","ɵSERVER_THREAD_OWNER","AgentRunner","ThreadAccessDeniedError","ThreadAlreadyRunningError","EventType","ReplaySubject"],"sources":["../../../src/runtime/runner/in-memory.ts"],"sourcesContent":["import type {\n AgentRunnerConnectRequest,\n AgentRunnerIsRunningRequest,\n AgentRunnerRunRequest,\n LocalThreadEndpointScope,\n} from \"./agent-runner\";\nimport {\n AgentRunner,\n ThreadAccessDeniedError,\n ThreadAlreadyRunningError,\n ɵSERVER_THREAD_OWNER,\n ɵresolveThreadOwner,\n} from \"./agent-runner\";\nimport type { AgentRunnerStopRequest } from \"./agent-runner\";\nimport type { Observable } from \"rxjs\";\nimport { ReplaySubject } from \"rxjs\";\nimport type {\n AbstractAgent,\n BaseEvent,\n Message,\n RunStartedEvent,\n StateSnapshotEvent,\n} from \"@ag-ui/client\";\nimport { EventType, compactEvents } from \"@ag-ui/client\";\nimport { finalizeRunEvents } from \"@copilotkit/shared\";\n\nexport interface InMemoryLimits {\n /** LRU cap on distinct threads. */\n maxThreads?: number;\n /** FIFO cap on runs kept per thread. `Infinity` or `0` disables the cap. */\n maxRunsPerThread?: number;\n /**\n * Approximate byte ceiling on RETAINED thread/run history. Enforced at run\n * completion (in `appendRun`), where LRU non-running threads are evicted to\n * keep the total under this limit.\n *\n * Limitation: this bounds only history that has already been committed. A\n * single in-flight run's buffered events (`currentRunEvents` and the two\n * `ReplaySubject<BaseEvent>(Infinity)` buffers in `run()`) are NOT counted\n * until that run completes, so `maxBytes` does not bound a single runaway\n * run mid-stream.\n *\n * Limitation: byte eviction drops only other LRU non-running threads and\n * never self-evicts the active/just-appended thread, so a single dominant\n * thread's own retained history is not byte-trimmed (bounded only by\n * `maxRunsPerThread`). `maxBytes` is thus a cross-thread ceiling enforced by\n * evicting OTHER threads, not a per-thread cap.\n */\n maxBytes?: number;\n}\n\n/**\n * Constructor options for {@link InMemoryAgentRunner}.\n *\n * Extends {@link InMemoryLimits} so bounds can be passed inline alongside the\n * per-runner behavior flags. Be aware of the scope difference: the limits\n * reconfigure the process-global store shared by every runner, whereas\n * `onConcurrentRun` applies only to the runner instance it is passed to.\n */\nexport interface InMemoryAgentRunnerOptions extends InMemoryLimits {\n /**\n * How to handle a `run()` for a thread that already has an in-flight run.\n * `\"throw\"` (default) rejects with \"Thread already running\". `\"supersede\"`\n * aborts the prior run and starts the new one.\n */\n onConcurrentRun?: \"throw\" | \"supersede\";\n}\n\nexport const ɵINMEMORY_DEFAULTS: Required<InMemoryLimits> = {\n maxThreads: 1000,\n maxRunsPerThread: 100,\n maxBytes: 512 * 1024 ** 2,\n};\n\n/**\n * A limit value is well-formed iff it is a non-negative integer OR `+Infinity`.\n * `+Infinity` is the documented \"disabled/unbounded\" sentinel and `0` is the\n * documented run-cap disable sentinel; both are non-negative and pass. Every\n * enforcement site (`evictThreadsIfNeeded`, `enforceRunCap`,\n * `evictByBytesIfNeeded`) compares its counter against the limit with `>` in a\n * `while`/`if` guard, so only these shapes keep those loops finite and correct.\n * Rejected: negatives (drive `count > -1` true on an empty collection, so\n * `enforceRunCap` `shift()!`s `undefined` and throws), `-Infinity` (loops never\n * terminate their intent — always \"over\"), `NaN` (every `>` is false, silently\n * disabling the bound), and non-integer finites (fractional caps are nonsense).\n */\nfunction ɵisValidLimit(value: number): boolean {\n return value === Infinity || (Number.isInteger(value) && value >= 0);\n}\n\n/**\n * Normalize a fully-resolved limits bag so every field is well-formed before it\n * can reach an enforcement loop. Each field is validated independently against\n * {@link ɵisValidLimit}; an invalid value is CLAMPED to its\n * {@link ɵINMEMORY_DEFAULTS} floor and a single `console.warn` naming the field\n * and the received value is emitted.\n *\n * Clamp-and-warn (rather than throw) is deliberate and matches this file's\n * established posture toward bad input: `ɵestimateBytes` swallows serialization\n * failures and returns 0, the limits-clobber path warns rather than throwing,\n * and both the eviction and clobber logs are wrapped so \"logging must never\n * break construction/a run\". Constructing a bounded in-memory runner is a\n * best-effort, non-durable convenience; a typo'd bound must degrade to a safe\n * default, never abort construction or (worse) surface later as an unhandled\n * rejection from the fire-and-forget finalize path.\n */\nexport function ɵnormalizeLimits(\n limits: Required<InMemoryLimits>,\n): Required<InMemoryLimits> {\n const normalized = { ...limits };\n for (const field of Object.keys(\n ɵINMEMORY_DEFAULTS,\n ) as (keyof InMemoryLimits)[]) {\n const value = limits[field];\n if (!ɵisValidLimit(value)) {\n const fallback = ɵINMEMORY_DEFAULTS[field];\n normalized[field] = fallback;\n try {\n console.warn(\n `[CopilotKit] InMemoryAgentRunner: invalid ${field} value ` +\n `${String(value)} (expected a non-negative integer or Infinity); ` +\n `falling back to ${String(fallback)}.`,\n );\n } catch {\n // best-effort: logging must never break construction\n }\n }\n }\n return normalized;\n}\n\nconst EVICTION_GUIDANCE =\n \"[CopilotKit] InMemoryAgentRunner evicted in-memory thread history to stay \" +\n \"under memory limits. This runner is bounded and non-durable by design. For \" +\n \"durable or production threads, configure an Intelligence backend.\";\n\nconst LIMITS_CLOBBER_GUIDANCE =\n \"[CopilotKit] InMemoryAgentRunner was constructed with in-memory limits that \" +\n \"differ from the already-configured process-global store; the last-constructed \" +\n \"runner's limits apply to ALL in-memory threads (the store is shared per-process). \" +\n \"Configure a single consistent set of limits, or use an Intelligence backend for \" +\n \"isolated bounds.\";\n\n/**\n * Best-effort approximate byte size of a value, via serialized length.\n * Never throws — returns 0 when the value cannot be serialized. This is an\n * approximation (UTF-16 length, not exact heap bytes), used only for relative\n * accounting against `maxBytes`.\n */\nexport function ɵestimateBytes(value: unknown): number {\n try {\n return JSON.stringify(value)?.length ?? 0;\n } catch {\n return 0;\n }\n}\n\n/**\n * Per-run finalize intent, captured once when a run starts and mutated (only)\n * by whoever aborts THAT run — `stop()` or a superseding `run()`. The run's own\n * teardown reads this captured holder instead of the shared, mutable\n * `store.stopRequested`, so a later run that resets store state can never cause\n * an intentionally-stopped run to be finalized as an error (or vice versa).\n */\ninterface RunFinalizeControl {\n /** True once THIS run has been asked to stop (clean stop, not an error). */\n stopRequested: boolean;\n}\n\ninterface HistoricRun {\n threadId: string;\n runId: string;\n /** ID of the agent that executed this run. */\n agentId: string;\n parentRunId: string | null;\n events: BaseEvent[];\n /**\n * Snapshot of all messages (input + generated) at the end of this run, as\n * passed in by the caller. NOTE: `BoundedThreadStore.appendRun` moves this\n * snapshot to the THREAD level (`InMemoryEventStore.messagesSnapshot`) and\n * clears this field to `[]`, so a stored HistoricRun never carries messages.\n * The thread-messages fallback reads the thread-level snapshot, not this.\n */\n messages: Message[];\n createdAt: number;\n /** Approximate retained byte size of `events`; set by BoundedThreadStore at append. */\n approxEventBytes?: number;\n /**\n * Legacy field retained for shape compatibility. `appendRun` always zeroes it\n * because message bytes are accounted at the thread level, not per run.\n */\n approxMessageBytes?: number;\n}\n\n/**\n * Lightweight thread summary returned by {@link InMemoryAgentRunner.listThreads}.\n * Shape matches CopilotKit Intelligence's ThreadRecord so the same HTTP\n * response envelope can be used for both backends.\n */\nexport interface InMemoryThread {\n id: string;\n name: string | null;\n agentId: string;\n organizationId: \"\"; // always empty in in-memory mode\n /** Identity that owns the thread; `\"\"` for a thread created without identity. */\n createdById: string;\n archived: false; // always false in in-memory mode\n createdAt: string;\n updatedAt: string;\n}\n\nclass InMemoryEventStore {\n /**\n * @param ownerId Identity that owns this thread, recorded when the thread is\n * created by its first run. `\"\"` is the anonymous owner;\n * {@link ɵSERVER_THREAD_OWNER} is the owner of a thread created server-side.\n */\n constructor(\n public threadId: string,\n public readonly ownerId: string,\n ) {}\n\n /** The subject that current consumers subscribe to. */\n subject: ReplaySubject<BaseEvent> | null = null;\n\n /** True while a run is actively producing events. */\n isRunning = false;\n\n /** Current run ID */\n currentRunId: string | null = null;\n\n /** Historic completed runs */\n historicRuns: HistoricRun[] = [];\n\n /** Currently running agent instance (if any). */\n agent: AbstractAgent | null = null;\n\n /** Subject returned from run() while the run is active. */\n runSubject: ReplaySubject<BaseEvent> | null = null;\n\n /**\n * Thread-level lifecycle flag: true once a stop/supersede has been requested\n * for the currently-owning run but that run has not yet finalized. Drives\n * eviction protection, the connect() bridge, and stop() de-dup. This is NOT\n * the finalize intent read by a run's teardown — that lives per-run on\n * {@link activeFinalize}, so a superseding run resetting this field cannot\n * mislabel the run it replaced. A new run resets this to false when it takes\n * ownership.\n */\n stopRequested = false;\n\n /**\n * Finalize control of the currently-owning run. `stop()` and a superseding\n * `run()` flip the owning run's flag through this reference; each run also\n * captures the SAME object in its closure, so its teardown finalizes against\n * its own intent regardless of what a later run does to the store.\n */\n activeFinalize: RunFinalizeControl | null = null;\n\n /** Reference to the events emitted in the current run. */\n currentEvents: BaseEvent[] | null = null;\n\n /**\n * The thread's single latest NON-EMPTY message snapshot, held at the THREAD\n * level (independent of `historicRuns` lifecycle). Decoupling the snapshot\n * from per-run storage means run-cap FIFO eviction and interleaved\n * empty-snapshot runs can never drop or pin the thread's message history.\n */\n messagesSnapshot: Message[] = [];\n\n /** Approximate retained byte size of `messagesSnapshot`. */\n approxMessagesSnapshotBytes = 0;\n\n /**\n * The thread's true creation timestamp (epoch ms), captured from the FIRST\n * run ever appended and held at the THREAD level (independent of\n * `historicRuns` lifecycle). Decoupling it from per-run storage means run-cap\n * FIFO eviction — which shifts the oldest entries off `historicRuns` — can\n * never move the reported creation time forward. `null` until the first run\n * lands. Mirrors the `messagesSnapshot` thread-level decoupling.\n */\n createdAt: number | null = null;\n}\n\n/**\n * True when a caller acting as `owner` may reach `store`: only the thread's\n * own owner may. Resolve an optional owner or scope with\n * {@link ɵresolveThreadOwner} first; an omitted one is the server owner, never\n * \"every thread\".\n */\nfunction isVisibleTo(store: InMemoryEventStore, owner: string): boolean {\n return store.ownerId === owner;\n}\n\n/** The owner a Thread endpoint call acts as. */\nfunction scopeOwner(scope: LocalThreadEndpointScope | undefined): string {\n return ɵresolveThreadOwner(scope?.ownerId);\n}\n\n/**\n * How long, and how many, owner records the store keeps for threads that left\n * it through LRU eviction or a scoped clear. See\n * {@link ɵBoundedThreadStore.ownerOf}.\n *\n * When a record is added over a limit, expired records go first; then, when\n * the record's owner holds more than `maxEntriesPerOwner`, that owner's\n * oldest record; then, over `maxEntries`, the oldest record of any owner. So\n * one identity that churns threads (anonymous callers share one identity)\n * only displaces its own records. Residual risk: many distinct identities\n * together can still exceed `maxEntries` and push out another identity's\n * live record. That frees the id for a new owner but leaks nothing, since\n * the removed thread's history is already gone, and it needs the victim's\n * thread id.\n */\nexport interface ɵOwnerRetention {\n /** Milliseconds an owner record is kept after its thread was removed. */\n ttlMs: number;\n /** Most owner records kept in all. */\n maxEntries: number;\n /** Most owner records kept for one owner. */\n maxEntriesPerOwner: number;\n /** Clock, replaceable in tests. */\n now: () => number;\n}\n\nexport const ɵOWNER_RETENTION_DEFAULTS: ɵOwnerRetention = {\n ttlMs: 24 * 60 * 60 * 1000,\n maxEntries: 100_000,\n maxEntriesPerOwner: 10_000,\n now: () => Date.now(),\n};\n\nexport class ɵBoundedThreadStore {\n private readonly map = new Map<string, InMemoryEventStore>();\n /**\n * Owners of threads that were removed from `map`, oldest first. A removed\n * thread's history is gone, but its id stays reserved for its owner until\n * the record expires, so another identity cannot claim the id and receive\n * the owner's next runs or later replays.\n */\n private readonly removedOwners = new Map<\n string,\n { ownerId: string; removedAt: number }\n >();\n /** The ids in `removedOwners`, per owner, oldest first. */\n private readonly removedOwnersByOwner = new Map<string, Set<string>>();\n private ownerRetention: ɵOwnerRetention = ɵOWNER_RETENTION_DEFAULTS;\n private totalBytes = 0;\n private warned = false;\n /** True once limits have been EXPLICITLY set (via setLimits), not just the constructor default. */\n private limitsExplicitlySet = false;\n /** Warn-once latch for the clobber warning, kept distinct from the eviction `warned` latch. */\n private clobberWarned = false;\n\n private limits: Required<InMemoryLimits>;\n\n constructor(limits: Required<InMemoryLimits>) {\n // Normalize once at construction so `this.limits` is ALWAYS well-formed,\n // regardless of entry point (direct construction or a later `setLimits`).\n this.limits = ɵnormalizeLimits(limits);\n }\n\n get byteTotal(): number {\n return this.totalBytes;\n }\n\n /**\n * The store's CURRENT effective bounds. Exposed (with the `ɵ` internal-API\n * prefix) so a partial `setLimits` can coalesce unspecified fields against the\n * live config rather than the hardcoded {@link ɵINMEMORY_DEFAULTS} — a partial\n * update must be a partial update, never a silent reset of the fields the\n * caller did not mention. Returns a copy so callers cannot mutate the store's\n * bounds through it.\n */\n get ɵlimits(): Required<InMemoryLimits> {\n return { ...this.limits };\n }\n\n /**\n * Reconfigure the process-global store's bounds. Called by the\n * {@link InMemoryAgentRunner} constructor when limits are passed. Because the\n * store is a per-process singleton, this replaces the bounds for ALL in-memory\n * threads. Emits {@link LIMITS_CLOBBER_GUIDANCE} at most ONCE per store when a\n * SECOND (or later) explicit set arrives whose resolved values differ from the\n * prior explicit set — i.e. a genuine clobber of an already-customized config.\n * The first explicit customization (defaults → custom) is the intended\n * override and never warns; identical re-sets never warn.\n */\n setLimits(limits: Required<InMemoryLimits>): void {\n // Normalize FIRST so invalid fields can never reach an enforcement loop and\n // so the clobber comparison below is against the EFFECTIVE (clamped) values,\n // not the raw ones — a typo'd bound that clamps to the current default is not\n // a genuine clobber and must not warn.\n const normalized = ɵnormalizeLimits(limits);\n if (\n this.limitsExplicitlySet &&\n !this.clobberWarned &&\n (normalized.maxThreads !== this.limits.maxThreads ||\n normalized.maxRunsPerThread !== this.limits.maxRunsPerThread ||\n normalized.maxBytes !== this.limits.maxBytes)\n ) {\n this.clobberWarned = true;\n try {\n console.warn(LIMITS_CLOBBER_GUIDANCE);\n } catch {\n // best-effort: logging must never break construction\n }\n }\n this.limitsExplicitlySet = true;\n this.limits = normalized;\n }\n\n get size(): number {\n return this.map.size;\n }\n\n /** Re-insert at the tail so Map iteration order stays LRU-first. */\n private touchOrder(threadId: string, store: InMemoryEventStore): void {\n this.map.delete(threadId);\n this.map.set(threadId, store);\n }\n\n /**\n * The thread's store, created and owned by `ownerId` when it does not exist\n * yet. An existing store keeps its owner; callers check access first.\n */\n getOrCreate(\n threadId: string,\n ownerId: string = ɵSERVER_THREAD_OWNER,\n ): InMemoryEventStore {\n const existing = this.map.get(threadId);\n if (existing) {\n this.touchOrder(threadId, existing);\n return existing;\n }\n const store = new InMemoryEventStore(threadId, ownerId);\n // The live store now records the owner.\n this.forgetOwner(threadId);\n this.map.set(threadId, store);\n this.evictThreadsIfNeeded(threadId);\n return store;\n }\n\n get(\n threadId: string,\n opts: { touch: boolean },\n ): InMemoryEventStore | undefined {\n const store = this.map.get(threadId);\n if (store && opts.touch) this.touchOrder(threadId, store);\n return store;\n }\n\n peek(threadId: string): InMemoryEventStore | undefined {\n return this.map.get(threadId);\n }\n\n /**\n * Evict the least-recently-used thread that is neither running NOR\n * mid-finalization. Returns false if none evictable. The `protect` thread\n * (typically the one just created) is never evicted, so a fresh thread is not\n * immediately dropped when it is the only non-running candidate.\n *\n * A thread is skipped while `isRunning` OR `stopRequested` is set.\n * `stop()` flips `isRunning` to false the moment it aborts the agent, but the\n * run keeps finalizing asynchronously (the abort trips the `catch` in\n * `runAgent`, which later calls `appendRun`). During that window\n * `stopRequested` stays true; evicting the thread then would make the pending\n * `appendRun` hit `if (!store) return` and silently drop the aborted run's\n * history. Guarding on `stopRequested` keeps the thread alive until\n * finalization completes.\n */\n private evictOneLru(protect?: string): boolean {\n for (const [threadId, store] of this.map) {\n if (threadId === protect) continue; // never evict the just-created thread\n // never evict a running or still-finalizing (stop-requested) thread\n if (store.isRunning || store.stopRequested) continue;\n this.removeThread(threadId, store);\n this.noteEviction();\n return true;\n }\n return false;\n }\n\n /**\n * Append a finished run to `writer`, the store its run started on. Nothing is\n * written when `writer` is no longer the live store for `threadId` (the thread\n * was removed, or removed and claimed again): a run must never write into a\n * thread it did not start on, which may now belong to another owner.\n */\n appendRun(\n threadId: string,\n writer: InMemoryEventStore | undefined,\n run: HistoricRun,\n ): void {\n const store = this.map.get(threadId);\n if (!store || store !== writer) return;\n\n // Thread-level creation timestamp: capture the FIRST run's createdAt once\n // and never overwrite it. Held on the store (not derived from\n // `historicRuns[0]`) so run-cap FIFO eviction of the oldest runs cannot\n // drift the thread's reported creation time forward. Mirrors the\n // thread-level `messagesSnapshot` decoupling below.\n if (store.createdAt === null) {\n store.createdAt = run.createdAt;\n }\n\n // Thread-level message snapshot: keep the single latest NON-EMPTY snapshot\n // on the store, decoupled from `historicRuns`. When the incoming run\n // carries a non-empty snapshot, replace the thread's snapshot (adjusting\n // byte accounting). When it's empty (non-array `agent.messages` or an\n // error-path run), leave the existing thread snapshot untouched so history\n // is never lost. The snapshot never lives on a HistoricRun, so run-cap FIFO\n // eviction can never drop it and an interleaved empty run can never pin it.\n if (run.messages.length > 0) {\n this.totalBytes -= store.approxMessagesSnapshotBytes;\n // Store the incoming array directly (SHALLOW, array-level copy). `run.messages`\n // is already a fresh `[...agent.messages]` array created in run(), so we own the\n // array and it is decoupled from `agent.messages` at the array level (push/splice\n // on the agent's array cannot mutate our snapshot). We deliberately do NOT deep-copy\n // here: `structuredClone` throws DataCloneError on a non-cloneable message field,\n // which would wedge the thread and hang SSE — inconsistent with `ɵestimateBytes`,\n // which tolerates the same bad-payload class. The tradeoff is that the inner\n // `Message` objects remain shared by reference with `agent.messages`, so an agent\n // that mutates its own message objects IN PLACE after the run can still be observed\n // through this snapshot. That inner-object isolation is a known limitation tracked as\n // follow-up; callers must treat returned messages as read-only. Estimate bytes on the\n // same value so accounting matches exactly what is retained.\n store.messagesSnapshot = run.messages;\n store.approxMessagesSnapshotBytes = ɵestimateBytes(run.messages);\n this.totalBytes += store.approxMessagesSnapshotBytes;\n }\n\n // Do not carry message bytes on the HistoricRun: the snapshot is now tracked\n // at the thread level, so historicRuns must never account message bytes.\n run.messages = [];\n run.approxMessageBytes = 0;\n\n // Compute this run's approximate event size once, at append time.\n run.approxEventBytes = ɵestimateBytes(run.events);\n store.historicRuns.push(run);\n this.totalBytes += run.approxEventBytes;\n this.touchOrder(threadId, store);\n\n this.enforceRunCap(store);\n this.evictByBytesIfNeeded(threadId);\n }\n\n private enforceRunCap(store: InMemoryEventStore): void {\n const cap = this.limits.maxRunsPerThread;\n if (!cap || cap === Infinity) return; // 0 or Infinity → disabled\n while (store.historicRuns.length > cap) {\n const dropped = store.historicRuns.shift()!;\n // Only event bytes live on a HistoricRun; the message snapshot is tracked\n // at the thread level and survives run-cap eviction.\n this.totalBytes -= dropped.approxEventBytes ?? 0;\n // Per-thread run-cap trimming is also eviction — history is being dropped.\n // Route it through the SAME warn-once latch as whole-thread LRU eviction so\n // this shows up in logs rather than as silent data loss. `noteEviction` is\n // latched (one warning per store, reset by `clear()`), so a hot thread that\n // trims on every subsequent append warns once, never per dropped run. The\n // loop only runs when a run is ACTUALLY over the cap, so a disabled or\n // under-cap `enforceRunCap` stays silent (it returned / never entered here).\n this.noteEviction();\n }\n }\n\n /**\n * Trim the store back under the byte ceiling by evicting LRU non-running\n * threads. `protect` (the just-appended thread) is never self-evicted, so a\n * fresh run pushes OTHER threads out rather than dropping itself.\n */\n private evictByBytesIfNeeded(protect?: string): void {\n while (this.totalBytes > this.limits.maxBytes) {\n if (!this.evictOneLru(protect)) break; // only protected/running threads left → accept overage\n }\n }\n\n private removeThread(threadId: string, store: InMemoryEventStore): void {\n for (const run of store.historicRuns) {\n this.totalBytes -= run.approxEventBytes ?? 0;\n }\n // The thread's message snapshot is tracked at the store level, so it must\n // be reclaimed here in addition to the per-run event bytes.\n this.totalBytes -= store.approxMessagesSnapshotBytes;\n this.map.delete(threadId);\n this.rememberOwner(threadId, store.ownerId);\n }\n\n /**\n * Keep the owner of a removed thread, within the retention bounds. See\n * {@link ɵOwnerRetention} for which records go first over a limit.\n */\n private rememberOwner(threadId: string, ownerId: string): void {\n const { maxEntries, maxEntriesPerOwner, now } = this.ownerRetention;\n this.forgetOwner(threadId); // re-insert at the tail (newest)\n this.removedOwners.set(threadId, { ownerId, removedAt: now() });\n let owned = this.removedOwnersByOwner.get(ownerId);\n if (!owned) {\n owned = new Set();\n this.removedOwnersByOwner.set(ownerId, owned);\n }\n owned.add(threadId);\n this.pruneRemovedOwners();\n while (owned.size > maxEntriesPerOwner) {\n const oldest = owned.values().next().value;\n if (oldest === undefined) break;\n this.forgetOwner(oldest);\n }\n while (this.removedOwners.size > maxEntries) {\n const oldest = this.removedOwners.keys().next().value;\n if (oldest === undefined) break;\n this.forgetOwner(oldest);\n }\n }\n\n /** Remove the owner record of `threadId`, if any. */\n private forgetOwner(threadId: string): void {\n const record = this.removedOwners.get(threadId);\n if (!record) return;\n this.removedOwners.delete(threadId);\n const owned = this.removedOwnersByOwner.get(record.ownerId);\n owned?.delete(threadId);\n if (owned?.size === 0) this.removedOwnersByOwner.delete(record.ownerId);\n }\n\n /** Drop expired owner records. They are oldest first, so stop at the first live one. */\n private pruneRemovedOwners(): void {\n const { ttlMs, now } = this.ownerRetention;\n const cutoff = now() - ttlMs;\n for (const [threadId, record] of this.removedOwners) {\n if (record.removedAt >= cutoff) break;\n this.forgetOwner(threadId);\n }\n }\n\n /**\n * Owner of `threadId`: the live thread's owner, or the retained owner of a\n * thread that was evicted or cleared. `undefined` when nobody owns the id, so\n * the next run may claim it.\n */\n ownerOf(threadId: string): string | undefined {\n const store = this.map.get(threadId);\n if (store) return store.ownerId;\n this.pruneRemovedOwners();\n const record = this.removedOwners.get(threadId);\n if (!record) return undefined;\n const { ttlMs, now } = this.ownerRetention;\n if (record.removedAt < now() - ttlMs) {\n this.forgetOwner(threadId);\n return undefined;\n }\n return record.ownerId;\n }\n\n /** True when a caller acting as `owner` may run on, or claim, `threadId`. */\n canClaim(threadId: string, owner: string): boolean {\n const current = this.ownerOf(threadId);\n return current === undefined || current === owner;\n }\n\n /**\n * Replace the owner-record retention. Omitted fields fall back to\n * {@link ɵOWNER_RETENTION_DEFAULTS}. Internal: for tests.\n */\n ɵsetOwnerRetention(retention: Partial<ɵOwnerRetention>): void {\n this.ownerRetention = { ...ɵOWNER_RETENTION_DEFAULTS, ...retention };\n }\n\n private evictThreadsIfNeeded(protect?: string): void {\n while (this.map.size > this.limits.maxThreads) {\n if (!this.evictOneLru(protect)) break; // everything evictable is running → accept overage\n }\n }\n\n private noteEviction(): void {\n if (this.warned) return;\n this.warned = true;\n try {\n console.warn(EVICTION_GUIDANCE);\n } catch {\n // best-effort: logging must never break a run\n }\n }\n\n listThreads(scope?: LocalThreadEndpointScope): InMemoryThread[] {\n const threads: InMemoryThread[] = [];\n for (const [threadId, store] of this.map) {\n if (store.historicRuns.length === 0) continue;\n if (!isVisibleTo(store, scopeOwner(scope))) continue;\n const lastRun = store.historicRuns[store.historicRuns.length - 1]!;\n // Creation time comes from the thread-level `store.createdAt` (the first\n // run ever appended), NOT `historicRuns[0]` (the oldest RETAINED run):\n // run-cap FIFO eviction drops the oldest retained runs, so deriving it\n // from `historicRuns[0]` would silently drift the timestamp forward over\n // a thread's lifetime. `updatedAt` stays on `lastRun` because FIFO\n // eviction removes from the FRONT, so the newest run is never evicted.\n // The `?? lastRun.createdAt` fallback is defensive only: any thread with\n // runs has had `store.createdAt` set by `appendRun`.\n threads.push({\n id: threadId,\n name: null,\n agentId: lastRun.agentId,\n organizationId: \"\",\n createdById: store.ownerId,\n archived: false,\n createdAt: new Date(store.createdAt ?? lastRun.createdAt).toISOString(),\n updatedAt: new Date(lastRun.createdAt).toISOString(),\n });\n }\n return threads.sort(\n (a, b) =>\n new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(),\n );\n }\n\n /**\n * Removes every thread visible to `scope`, except threads that are running\n * or still finalizing: removing one would drop its owner record while its\n * run still writes, so another identity could claim the id. Those threads\n * stay, as in `evictOneLru`. A scoped clear leaves other owners' threads\n * untouched.\n *\n * Without a scope the whole store is reset, running threads included. That\n * is an internal reset for tests; `appendRun` keeps an orphaned run from\n * writing into a thread created after the reset.\n */\n clear(scope?: LocalThreadEndpointScope): void {\n if (scope !== undefined) {\n // Deleting the current entry while iterating a Map is safe.\n for (const [threadId, store] of this.map) {\n if (store.isRunning || store.stopRequested) continue;\n if (isVisibleTo(store, scopeOwner(scope)))\n this.removeThread(threadId, store);\n }\n return;\n }\n this.map.clear();\n this.removedOwners.clear();\n this.removedOwnersByOwner.clear();\n this.totalBytes = 0;\n this.warned = false;\n }\n}\n\n/**\n * Process-wide singleton backing every {@link InMemoryAgentRunner}. Exported\n * (with the `ɵ` internal-API prefix) so tests can inspect the exact store the\n * runner writes to; not part of the public API.\n */\nexport const ɵGLOBAL_STORE = new ɵBoundedThreadStore(ɵINMEMORY_DEFAULTS);\nconst sharedStore = ɵGLOBAL_STORE;\n\nexport class InMemoryAgentRunner extends AgentRunner {\n readonly ɵsupportsLocalThreadEndpoints = true;\n\n /**\n * How to handle a `run()` for a thread that already has an in-flight run.\n * `\"throw\"` (default) preserves the historic behavior. `\"supersede\"` aborts\n * the prior run (mirroring `stop()`) and starts the new one — opted into by\n * the hosted-bot listener so a fast follow-up turn on the same thread cleanly\n * replaces a still-running (or wedged) prior turn instead of erroring with\n * \"Thread already running\".\n */\n private readonly onConcurrentRun: \"throw\" | \"supersede\";\n\n /**\n * @param options Per-runner behavior (`onConcurrentRun`) plus optional bounds\n * for the in-memory store ({@link InMemoryLimits}).\n *\n * Note the differing scopes: `onConcurrentRun` is per-runner instance, while\n * the limits reconfigure the PROCESS-GLOBAL store shared by every\n * `InMemoryAgentRunner`. Omit the limits for safe defaults\n * ({@link ɵINMEMORY_DEFAULTS}); passing none leaves the store untouched. When\n * multiple runners are constructed with differing limits, the last-constructed\n * wins — in practice the OSS/SSE default construction passes nothing. If a\n * second (or later) runner is constructed with limits that DIFFER from an\n * already-customized store, a one-time `console.warn` is emitted to signal that\n * the shared store's bounds are being clobbered for ALL in-memory threads.\n */\n constructor(options?: InMemoryAgentRunnerOptions) {\n super();\n const { onConcurrentRun, ...limits } = options ?? {};\n this.onConcurrentRun = onConcurrentRun ?? \"throw\";\n\n // Only reconfigure the shared store when a bound was actually supplied.\n // `new InMemoryAgentRunner({ onConcurrentRun: \"supersede\" })` must stay\n // inert with respect to limits.\n if (\n limits.maxThreads !== undefined ||\n limits.maxRunsPerThread !== undefined ||\n limits.maxBytes !== undefined\n ) {\n // Coalesce each unspecified field against the store's CURRENT effective\n // limits, NOT ɵINMEMORY_DEFAULTS. The store is process-global, so tuning\n // one bound must leave every previously-customized sibling bound intact —\n // a partial update stays a partial update instead of silently resetting the\n // fields the caller never mentioned. Passing all three (e.g.\n // ɵINMEMORY_DEFAULTS) still fully replaces the config, so the defaults-\n // restore path is unaffected.\n const current = sharedStore.ɵlimits;\n sharedStore.setLimits({\n maxThreads: limits.maxThreads ?? current.maxThreads,\n maxRunsPerThread: limits.maxRunsPerThread ?? current.maxRunsPerThread,\n maxBytes: limits.maxBytes ?? current.maxBytes,\n });\n }\n }\n\n run(request: AgentRunnerRunRequest): Observable<BaseEvent> {\n // A thread belongs to the identity of its first run. Check before\n // `getOrCreate` so a refused run does not touch the thread's LRU position.\n const owner = ɵresolveThreadOwner(request.ownerId);\n if (!sharedStore.canClaim(request.threadId, owner)) {\n throw new ThreadAccessDeniedError();\n }\n const store = sharedStore.getOrCreate(request.threadId, owner);\n\n // Enter the concurrency branch whenever a prior run still owns the thread —\n // either actively running OR still finalizing after a stop()/supersede.\n // `stop()` flips `isRunning` to false the instant it aborts the agent, but\n // the run keeps finalizing asynchronously (`stopRequested` stays true).\n // Gating on `isRunning` alone let a `run()` slip through that window\n // unhandled: no supersede/throw, no per-run intent capture, and a leaked\n // bridge from the dying run's subject.\n if (store.isRunning || store.stopRequested) {\n if (this.onConcurrentRun !== \"supersede\") {\n throw new ThreadAlreadyRunningError();\n }\n // Supersede: abort the prior (possibly wedged) run so this one can start.\n // Mirrors stop(). Record the prior run's OWN finalize intent on its\n // captured control BEFORE resetting the shared store flags for the new\n // run: a supersede is a clean stop of the prior run, so its async teardown\n // must finalize as RUN_FINISHED, never a synthetic RUN_ERROR. The prior\n // run's async finalization is prevented from clobbering this run's state\n // by the run-id guard below.\n const priorAgent = store.agent;\n const priorFinalize = store.activeFinalize;\n if (priorFinalize) {\n priorFinalize.stopRequested = true;\n }\n store.isRunning = false;\n if (priorAgent) {\n try {\n priorAgent.abortRun();\n } catch (error) {\n console.error(\"Failed to abort superseded run\", error);\n }\n }\n }\n store.isRunning = true;\n store.currentRunId = request.input.runId;\n store.agent = request.agent;\n store.stopRequested = false;\n\n // Per-run finalize control. This run's teardown reads THIS captured holder\n // (never the shared `store.stopRequested`, which a later run resets), so an\n // aborted run is always finalized against its own stop-intent.\n const finalizeControl: RunFinalizeControl = { stopRequested: false };\n store.activeFinalize = finalizeControl;\n\n // Track seen message IDs and current run events for this run\n const seenMessageIds = new Set<string>();\n const currentRunEvents: BaseEvent[] = [];\n store.currentEvents = currentRunEvents;\n\n // Get all previously seen message IDs from historic runs\n const historicMessageIds = new Set<string>();\n for (const run of store.historicRuns) {\n for (const event of run.events) {\n if (\"messageId\" in event && typeof event.messageId === \"string\") {\n historicMessageIds.add(event.messageId);\n }\n if (event.type === EventType.RUN_STARTED) {\n const runStarted = event as RunStartedEvent;\n const messages = runStarted.input?.messages ?? [];\n for (const message of messages) {\n historicMessageIds.add(message.id);\n }\n }\n }\n }\n\n const nextSubject = new ReplaySubject<BaseEvent>(Infinity);\n\n // Update the store's subject immediately. We intentionally do NOT capture\n // and bridge the previous subject: see the note before `runAgent()` below.\n store.subject = nextSubject;\n\n // Create a subject for run() return value\n const runSubject = new ReplaySubject<BaseEvent>(Infinity);\n store.runSubject = runSubject;\n\n // Helper function to run the agent and handle errors\n const runAgent = async () => {\n // Get parent run ID for chaining\n const lastRun = store.historicRuns[store.historicRuns.length - 1];\n const parentRunId = lastRun?.runId ?? null;\n\n // Shared teardown for both the success and error paths. Keeping this one\n // helper means the two paths cannot drift apart (they were near-identical\n // and must stay symmetric). `interruptionMessage` is set only on the error\n // path; its presence is what distinguishes the two.\n const finalizeRun = (opts: { interruptionMessage?: string }) => {\n const isError = opts.interruptionMessage !== undefined;\n\n // Capture the count of REAL (agent-emitted) events BEFORE finalizing.\n // `finalizeRunEvents` mutates `currentRunEvents` IN PLACE — it always\n // pushes a synthetic terminal (and any closers) when the stream ended\n // without one — so after the call `currentRunEvents.length` is never 0.\n // The persistence guard below must gate on this pre-finalize count, or\n // the \"skip an immediate throw that emitted nothing\" check is dead.\n const preFinalizeEventCount = currentRunEvents.length;\n\n // Stop can arrive before the agent sends its first event.\n if (\n finalizeControl.stopRequested &&\n !currentRunEvents.some(\n (event) => event.type === EventType.RUN_STARTED,\n )\n ) {\n const started: RunStartedEvent = {\n type: EventType.RUN_STARTED,\n threadId: request.threadId,\n runId: request.input.runId,\n input: {\n ...request.input,\n messages: request.input.messages.filter(\n (message) => !historicMessageIds.has(message.id),\n ),\n },\n };\n currentRunEvents.unshift(started);\n runSubject.next(started);\n nextSubject.next(started);\n }\n\n // Finalize against THIS run's own captured stop-intent — never the\n // shared `store.stopRequested`, which a superseding run resets. An\n // aborted run is thus finalized as a clean RUN_FINISHED, not a synthetic\n // RUN_ERROR.\n const appendedEvents = finalizeRunEvents(currentRunEvents, {\n stopRequested: finalizeControl.stopRequested,\n protocolVersion: request.input.protocolVersion,\n ...(isError ? { interruptionMessage: opts.interruptionMessage } : {}),\n });\n for (const event of appendedEvents) {\n runSubject.next(event);\n nextSubject.next(event);\n }\n\n // Does this run still own the thread? A superseding run has changed\n // `currentRunId`, so the run it replaced no longer owns the store.\n const ownsThread = store.currentRunId === request.input.runId;\n\n // Store this run's events. Guard on the per-run id (not the shared\n // `store.currentRunId`): a superseded run no longer owns the store, so\n // it must not push history under a newer run's id.\n // Keep explicit stops even when abort rejects before the first event.\n // Other immediate errors with no real events must not create history.\n if (\n ownsThread &&\n (!isError ||\n preFinalizeEventCount > 0 ||\n finalizeControl.stopRequested)\n ) {\n // Compact the events before storing (like SQLite does)\n const compactedEvents = compactEvents(currentRunEvents);\n sharedStore.appendRun(request.threadId, store, {\n threadId: request.threadId,\n runId: request.input.runId,\n agentId: request.agent.agentId ?? \"default\",\n parentRunId,\n events: compactedEvents,\n // Snapshot all messages (input + generated) for the thread-messages endpoint\n messages: Array.isArray(request.agent.messages)\n ? [...request.agent.messages]\n : [],\n createdAt: Date.now(),\n });\n }\n\n // Complete the run. Guard the shared-store reset: if a newer run has\n // superseded this one (`currentRunId` changed), that run now owns the\n // store — don't clobber its state. Always complete THIS run's subjects.\n if (ownsThread) {\n store.currentEvents = null;\n store.currentRunId = null;\n store.agent = null;\n store.runSubject = null;\n store.stopRequested = false;\n store.isRunning = false;\n store.activeFinalize = null;\n }\n runSubject.complete();\n nextSubject.complete();\n // Time-scoped release: this run's events are now in historicRuns, so its\n // infinite ReplaySubject buffer is pure duplication — drop the store's\n // reference so it becomes collectable. The identity guard is what makes\n // this correct, and it does so differently on each path:\n //\n // - Owning path: no newer run superseded this one, so store.subject is\n // still nextSubject and the guard passes. The `if (ownsThread)` block\n // above just cleared isRunning and stopRequested, so connect() — which\n // bridges store.subject only while isRunning || stopRequested — will\n // not re-subscribe; it rebuilds this run's events from historicRuns\n // instead. Nulling the reference is therefore safe.\n //\n // - Superseded path (`onConcurrentRun: \"supersede\"`): a newer run has\n // already installed ITS subject and run id on the store, so the guard\n // fails and we leave store.subject untouched. Here isRunning/\n // stopRequested describe that live run (isRunning is typically true),\n // so it is precisely the identity guard — not those flags — that\n // prevents us from nulling the live run's subject and cutting\n // connect() off from the in-flight stream. This run's own buffer is no\n // longer referenced by the store and becomes collectable regardless.\n if (store.subject === nextSubject) {\n store.subject = null;\n }\n };\n\n try {\n await request.agent.runAgent(request.input, {\n onEvent: ({ event }) => {\n let processedEvent: BaseEvent = event;\n if (event.type === EventType.RUN_STARTED) {\n const runStartedEvent = event as RunStartedEvent;\n if (!runStartedEvent.input) {\n const sanitizedMessages = request.input.messages\n ? request.input.messages.filter(\n (message) => !historicMessageIds.has(message.id),\n )\n : undefined;\n const updatedInput = {\n ...request.input,\n ...(sanitizedMessages !== undefined\n ? { messages: sanitizedMessages }\n : {}),\n };\n runStartedEvent.input = updatedInput;\n processedEvent = runStartedEvent;\n }\n }\n\n runSubject.next(processedEvent); // For run() return - only agent events\n nextSubject.next(processedEvent); // For connect() / store - all events\n currentRunEvents.push(processedEvent); // Accumulate for storage\n },\n onNewMessage: ({ message }) => {\n // Called for each new message\n if (!seenMessageIds.has(message.id)) {\n seenMessageIds.add(message.id);\n }\n },\n onRunStartedEvent: () => {\n // Mark any messages from the input as seen so they aren't emitted twice\n if (request.input.messages) {\n for (const message of request.input.messages) {\n if (!seenMessageIds.has(message.id)) {\n seenMessageIds.add(message.id);\n }\n }\n }\n },\n });\n\n finalizeRun({});\n } catch (error) {\n const interruptionMessage =\n error instanceof Error ? error.message : String(error);\n finalizeRun({ interruptionMessage });\n }\n };\n\n // NOTE: we deliberately do NOT bridge the previous store subject into\n // `nextSubject`. `store.subject` is nulled the moment a run fully tears down\n // (identity guard in `finalizeRun`), so the previous subject is non-null\n // ONLY when this run is superseding a prior run that is still in flight or\n // finalizing. Forwarding that dying run's subject would replay its buffered\n // RUN_STARTED and push its terminal event (RUN_FINISHED/RUN_ERROR) into THIS\n // live run's stream — an invalid AG-UI sequence on a healthy run. A\n // superseded run's stream must stay isolated: it reaches only its own\n // connect() subscribers via its own (now-detached) subject, never the\n // superseding run's.\n\n // Start the agent execution immediately (not lazily). When finishing the\n // run throws on both paths, release the thread anyway: otherwise it stays\n // \"running\", refuses every later run and is never evicted.\n runAgent().catch((error) => {\n console.error(\n \"Failed to finish agent run\",\n { threadId: request.threadId, runId: request.input.runId },\n error,\n );\n if (store.currentRunId === request.input.runId) {\n store.currentEvents = null;\n store.currentRunId = null;\n store.agent = null;\n store.runSubject = null;\n store.stopRequested = false;\n store.isRunning = false;\n store.activeFinalize = null;\n }\n runSubject.complete();\n nextSubject.complete();\n if (store.subject === nextSubject) {\n store.subject = null;\n }\n });\n\n // Return the run subject (only agent events, no injected messages)\n return runSubject.asObservable();\n }\n\n connect(request: AgentRunnerConnectRequest): Observable<BaseEvent> {\n const found = sharedStore.peek(request.threadId);\n // A thread owned by another identity is indistinguishable from an\n // unknown one: no replay, no live bridge.\n const store =\n found && isVisibleTo(found, ɵresolveThreadOwner(request.ownerId))\n ? sharedStore.get(request.threadId, { touch: true })\n : undefined;\n const connectionSubject = new ReplaySubject<BaseEvent>(Infinity);\n\n if (!store) {\n // No store means no events\n connectionSubject.complete();\n return connectionSubject.asObservable();\n }\n\n // Collect all historic events from memory\n const allHistoricEvents: BaseEvent[] = [];\n for (const run of store.historicRuns) {\n allHistoricEvents.push(...run.events);\n }\n\n // Apply compaction to all historic events together (like SQLite)\n const compactedEvents = compactEvents(allHistoricEvents);\n\n // Emit compacted events and track message IDs\n const emittedMessageIds = new Set<string>();\n for (const event of compactedEvents) {\n connectionSubject.next(event);\n if (\"messageId\" in event && typeof event.messageId === \"string\") {\n emittedMessageIds.add(event.messageId);\n }\n }\n\n // Bridge active run to connection if exists\n if (store.subject && (store.isRunning || store.stopRequested)) {\n store.subject.subscribe({\n next: (event) => {\n // Skip message events that we've already emitted from historic\n if (\n \"messageId\" in event &&\n typeof event.messageId === \"string\" &&\n emittedMessageIds.has(event.messageId)\n ) {\n return;\n }\n connectionSubject.next(event);\n },\n complete: () => connectionSubject.complete(),\n error: (err) => connectionSubject.error(err),\n });\n } else {\n // No active run, complete after historic events\n connectionSubject.complete();\n }\n\n return connectionSubject.asObservable();\n }\n\n isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean> {\n const store = sharedStore.peek(request.threadId);\n // Another identity's thread reports \"not running\".\n if (!store || !isVisibleTo(store, ɵresolveThreadOwner(request.ownerId))) {\n return Promise.resolve(false);\n }\n return Promise.resolve(store.isRunning);\n }\n\n stop(request: AgentRunnerStopRequest): Promise<boolean | undefined> {\n const store = sharedStore.peek(request.threadId);\n if (!store || !store.isRunning) {\n return Promise.resolve(false);\n }\n // Another identity's run reports the same as \"no active run\".\n if (!isVisibleTo(store, ɵresolveThreadOwner(request.ownerId))) {\n return Promise.resolve(false);\n }\n if (request.runId !== undefined && store.currentRunId !== request.runId) {\n return Promise.resolve(false);\n }\n if (store.stopRequested) {\n return Promise.resolve(false);\n }\n\n store.stopRequested = true;\n store.isRunning = false;\n // Record the stop on the running run's OWN finalize control so its async\n // teardown finalizes as a clean RUN_FINISHED. This is the same object that\n // run's closure reads, so a later run cannot mislabel this stop.\n const finalizeControl = store.activeFinalize;\n if (finalizeControl) {\n finalizeControl.stopRequested = true;\n }\n\n const agent = store.agent;\n if (!agent) {\n store.stopRequested = false;\n store.isRunning = false;\n if (finalizeControl) {\n finalizeControl.stopRequested = false;\n }\n return Promise.resolve(false);\n }\n\n try {\n agent.abortRun();\n return Promise.resolve(true);\n } catch (error) {\n console.error(\"Failed to abort agent run\", error);\n store.stopRequested = false;\n store.isRunning = true;\n if (finalizeControl) {\n finalizeControl.stopRequested = false;\n }\n return Promise.resolve(false);\n }\n }\n\n /**\n * Returns a summary of every thread that `scope`'s owner holds in the\n * process-wide store, which every InMemoryAgentRunner shares. Without a\n * scope, the server owner's threads ({@link ɵSERVER_THREAD_OWNER}).\n *\n * This powers the local-dev fallback for `GET /threads` when the Intelligence\n * platform is not configured. Each entry mirrors the shape of a platform\n * `ThreadRecord` so the HTTP handler can use the same response envelope.\n */\n listThreads(scope?: LocalThreadEndpointScope): InMemoryThread[] {\n return sharedStore.listThreads(scope);\n }\n\n /**\n * Returns all messages for a thread, using the snapshot captured at the end\n * of the most recent run.\n *\n * This powers the local-dev fallback for `GET /threads/:threadId/messages`\n * when CopilotKit Intelligence is not configured. The returned `Message[]`\n * objects come directly from the ag-ui agent, so their shape is compatible\n * with CopilotKit Intelligence's `ThreadMessage` type.\n */\n getThreadMessages(\n threadId: string,\n scope?: LocalThreadEndpointScope,\n ): Message[] {\n const store = this.peekVisible(threadId, scope);\n if (!store) return [];\n // The thread's latest non-empty snapshot is held at the store level,\n // independent of `historicRuns` lifecycle, so run-cap eviction and\n // interleaved empty-snapshot runs can never lose it. Return a SHALLOW\n // (array-level) copy: a fresh array so a caller mutating array STRUCTURE\n // (push/splice/reassign elements) cannot affect the stored snapshot. We\n // deliberately do NOT deep-copy: `structuredClone` throws DataCloneError on a\n // non-cloneable message field, which would wedge the thread and hang SSE —\n // inconsistent with `ɵestimateBytes`, which tolerates the same bad-payload class.\n // The tradeoff is that the inner `Message` objects remain shared by reference with\n // the stored snapshot, so mutating a returned message's FIELD\n // (e.g. `getThreadMessages(t)[0].content = \"x\"`) is NOT isolated and would corrupt\n // the stored snapshot. That inner-object isolation is a known limitation tracked as\n // follow-up; callers must treat returned messages as read-only.\n return [...store.messagesSnapshot];\n }\n\n /**\n * Returns all AG-UI events for a thread, compacted across historic runs.\n *\n * Powers the local-dev fallback for `GET /threads/:threadId/events` when the\n * CopilotKit Intelligence is not configured. The compaction logic matches\n * the connection-replay path in {@link connect}, so the stream a\n * late-joining inspector sees matches what this method returns.\n */\n getThreadEvents(\n threadId: string,\n scope?: LocalThreadEndpointScope,\n ): BaseEvent[] {\n const store = this.peekVisible(threadId, scope);\n if (!store || store.historicRuns.length === 0) return [];\n const all: BaseEvent[] = [];\n for (const run of store.historicRuns) all.push(...run.events);\n return compactEvents(all);\n }\n\n /**\n * Returns the agent state snapshot for a thread.\n *\n * Derived from the last `STATE_SNAPSHOT` in the compacted event stream. The\n * AG-UI `compactEvents` helper consolidates STATE_DELTA events and produces\n * a single trailing STATE_SNAPSHOT when state changes exist, so this is a\n * faithful view of state at the end of the most recent run.\n *\n * Returns `null` when the thread has never emitted a STATE_SNAPSHOT.\n */\n getThreadState(\n threadId: string,\n scope?: LocalThreadEndpointScope,\n ): Record<string, unknown> | null {\n const events = this.getThreadEvents(threadId, scope);\n // Walk backwards — the last snapshot wins.\n for (let i = events.length - 1; i >= 0; i--) {\n const event = events[i]!;\n if (event.type === EventType.STATE_SNAPSHOT) {\n const snapshot = (event as StateSnapshotEvent).snapshot;\n // Only plain objects satisfy the Record<string, unknown> contract.\n // `typeof [] === \"object\"` is true, so arrays must be rejected\n // explicitly to avoid returning an array typed as a Record.\n if (\n snapshot &&\n typeof snapshot === \"object\" &&\n !Array.isArray(snapshot)\n ) {\n // Return a defensive shallow copy so callers can't mutate the\n // snapshot object held inside the stored event (matches the\n // getThreadMessages defensive-copy approach).\n return { ...(snapshot as Record<string, unknown>) };\n }\n return null;\n }\n }\n return null;\n }\n\n /**\n * Clears the in-memory history of `scope`'s threads (without a scope, the\n * server owner's). A thread with a run still active or finalizing is kept;\n * see {@link ɵBoundedThreadStore.clear}.\n *\n * Powers the local-dev fallback for `POST /threads/clear`, letting consumers\n * (e.g. the demo's Clear button) reset to an empty thread list without\n * restarting the runtime. Intentionally not exposed on the Intelligence\n * platform path: there, thread history lives in a real database and must\n * not be wiped this way.\n */\n clearThreads(scope?: LocalThreadEndpointScope): void {\n sharedStore.clear({ ownerId: scopeOwner(scope) });\n }\n\n /**\n * False when the thread id is held by an owner other than `scope`'s: a\n * live thread, or the retained owner of an evicted or cleared one.\n */\n isThreadAccessible(\n threadId: string,\n scope: LocalThreadEndpointScope,\n ): boolean {\n return sharedStore.canClaim(threadId, scopeOwner(scope));\n }\n\n /** The thread's store, or `undefined` when unknown or not visible to `scope`. */\n private peekVisible(\n threadId: string,\n scope: LocalThreadEndpointScope | undefined,\n ): InMemoryEventStore | undefined {\n const store = sharedStore.peek(threadId);\n return store && isVisibleTo(store, scopeOwner(scope)) ? store : undefined;\n }\n}\n"],"mappings":";;;;;;;AAoEA,MAAa,qBAA+C;CAC1D,YAAY;CACZ,kBAAkB;CAClB,UAAU,MAAM,QAAQ;CACzB;;;;;;;;;;;;;AAcD,SAAS,cAAc,OAAwB;AAC7C,QAAO,UAAU,YAAa,OAAO,UAAU,MAAM,IAAI,SAAS;;;;;;;;;;;;;;;;;;AAmBpE,SAAgB,iBACd,QAC0B;CAC1B,MAAM,aAAa,EAAE,GAAG,QAAQ;AAChC,MAAK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O,WAAW,MAAM,CAAC,GAAG,QAAQ"}
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, LocalThreadEndpointScope } from "./agent-runner.cjs";
|
|
2
|
+
import { AbstractAgent, BaseEvent, Message } from "@ag-ui/client";
|
|
3
|
+
import { Observable, ReplaySubject } from "rxjs";
|
|
4
|
+
|
|
5
|
+
//#region src/runtime/runner/in-memory.d.ts
|
|
6
|
+
interface InMemoryLimits {
|
|
7
|
+
/** LRU cap on distinct threads. */
|
|
8
|
+
maxThreads?: number;
|
|
9
|
+
/** FIFO cap on runs kept per thread. `Infinity` or `0` disables the cap. */
|
|
10
|
+
maxRunsPerThread?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Approximate byte ceiling on RETAINED thread/run history. Enforced at run
|
|
13
|
+
* completion (in `appendRun`), where LRU non-running threads are evicted to
|
|
14
|
+
* keep the total under this limit.
|
|
15
|
+
*
|
|
16
|
+
* Limitation: this bounds only history that has already been committed. A
|
|
17
|
+
* single in-flight run's buffered events (`currentRunEvents` and the two
|
|
18
|
+
* `ReplaySubject<BaseEvent>(Infinity)` buffers in `run()`) are NOT counted
|
|
19
|
+
* until that run completes, so `maxBytes` does not bound a single runaway
|
|
20
|
+
* run mid-stream.
|
|
21
|
+
*
|
|
22
|
+
* Limitation: byte eviction drops only other LRU non-running threads and
|
|
23
|
+
* never self-evicts the active/just-appended thread, so a single dominant
|
|
24
|
+
* thread's own retained history is not byte-trimmed (bounded only by
|
|
25
|
+
* `maxRunsPerThread`). `maxBytes` is thus a cross-thread ceiling enforced by
|
|
26
|
+
* evicting OTHER threads, not a per-thread cap.
|
|
27
|
+
*/
|
|
28
|
+
maxBytes?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Constructor options for {@link InMemoryAgentRunner}.
|
|
32
|
+
*
|
|
33
|
+
* Extends {@link InMemoryLimits} so bounds can be passed inline alongside the
|
|
34
|
+
* per-runner behavior flags. Be aware of the scope difference: the limits
|
|
35
|
+
* reconfigure the process-global store shared by every runner, whereas
|
|
36
|
+
* `onConcurrentRun` applies only to the runner instance it is passed to.
|
|
37
|
+
*/
|
|
38
|
+
interface InMemoryAgentRunnerOptions extends InMemoryLimits {
|
|
39
|
+
/**
|
|
40
|
+
* How to handle a `run()` for a thread that already has an in-flight run.
|
|
41
|
+
* `"throw"` (default) rejects with "Thread already running". `"supersede"`
|
|
42
|
+
* aborts the prior run and starts the new one.
|
|
43
|
+
*/
|
|
44
|
+
onConcurrentRun?: "throw" | "supersede";
|
|
45
|
+
}
|
|
46
|
+
declare const ɵINMEMORY_DEFAULTS: Required<InMemoryLimits>;
|
|
47
|
+
/**
|
|
48
|
+
* Normalize a fully-resolved limits bag so every field is well-formed before it
|
|
49
|
+
* can reach an enforcement loop. Each field is validated independently against
|
|
50
|
+
* {@link ɵisValidLimit}; an invalid value is CLAMPED to its
|
|
51
|
+
* {@link ɵINMEMORY_DEFAULTS} floor and a single `console.warn` naming the field
|
|
52
|
+
* and the received value is emitted.
|
|
53
|
+
*
|
|
54
|
+
* Clamp-and-warn (rather than throw) is deliberate and matches this file's
|
|
55
|
+
* established posture toward bad input: `ɵestimateBytes` swallows serialization
|
|
56
|
+
* failures and returns 0, the limits-clobber path warns rather than throwing,
|
|
57
|
+
* and both the eviction and clobber logs are wrapped so "logging must never
|
|
58
|
+
* break construction/a run". Constructing a bounded in-memory runner is a
|
|
59
|
+
* best-effort, non-durable convenience; a typo'd bound must degrade to a safe
|
|
60
|
+
* default, never abort construction or (worse) surface later as an unhandled
|
|
61
|
+
* rejection from the fire-and-forget finalize path.
|
|
62
|
+
*/
|
|
63
|
+
declare function ɵnormalizeLimits(limits: Required<InMemoryLimits>): Required<InMemoryLimits>;
|
|
64
|
+
/**
|
|
65
|
+
* Best-effort approximate byte size of a value, via serialized length.
|
|
66
|
+
* Never throws — returns 0 when the value cannot be serialized. This is an
|
|
67
|
+
* approximation (UTF-16 length, not exact heap bytes), used only for relative
|
|
68
|
+
* accounting against `maxBytes`.
|
|
69
|
+
*/
|
|
70
|
+
declare function ɵestimateBytes(value: unknown): number;
|
|
71
|
+
/**
|
|
72
|
+
* Per-run finalize intent, captured once when a run starts and mutated (only)
|
|
73
|
+
* by whoever aborts THAT run — `stop()` or a superseding `run()`. The run's own
|
|
74
|
+
* teardown reads this captured holder instead of the shared, mutable
|
|
75
|
+
* `store.stopRequested`, so a later run that resets store state can never cause
|
|
76
|
+
* an intentionally-stopped run to be finalized as an error (or vice versa).
|
|
77
|
+
*/
|
|
78
|
+
interface RunFinalizeControl {
|
|
79
|
+
/** True once THIS run has been asked to stop (clean stop, not an error). */
|
|
80
|
+
stopRequested: boolean;
|
|
81
|
+
}
|
|
82
|
+
interface HistoricRun {
|
|
83
|
+
threadId: string;
|
|
84
|
+
runId: string;
|
|
85
|
+
/** ID of the agent that executed this run. */
|
|
86
|
+
agentId: string;
|
|
87
|
+
parentRunId: string | null;
|
|
88
|
+
events: BaseEvent[];
|
|
89
|
+
/**
|
|
90
|
+
* Snapshot of all messages (input + generated) at the end of this run, as
|
|
91
|
+
* passed in by the caller. NOTE: `BoundedThreadStore.appendRun` moves this
|
|
92
|
+
* snapshot to the THREAD level (`InMemoryEventStore.messagesSnapshot`) and
|
|
93
|
+
* clears this field to `[]`, so a stored HistoricRun never carries messages.
|
|
94
|
+
* The thread-messages fallback reads the thread-level snapshot, not this.
|
|
95
|
+
*/
|
|
96
|
+
messages: Message[];
|
|
97
|
+
createdAt: number;
|
|
98
|
+
/** Approximate retained byte size of `events`; set by BoundedThreadStore at append. */
|
|
99
|
+
approxEventBytes?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Legacy field retained for shape compatibility. `appendRun` always zeroes it
|
|
102
|
+
* because message bytes are accounted at the thread level, not per run.
|
|
103
|
+
*/
|
|
104
|
+
approxMessageBytes?: number;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Lightweight thread summary returned by {@link InMemoryAgentRunner.listThreads}.
|
|
108
|
+
* Shape matches CopilotKit Intelligence's ThreadRecord so the same HTTP
|
|
109
|
+
* response envelope can be used for both backends.
|
|
110
|
+
*/
|
|
111
|
+
interface InMemoryThread {
|
|
112
|
+
id: string;
|
|
113
|
+
name: string | null;
|
|
114
|
+
agentId: string;
|
|
115
|
+
organizationId: "";
|
|
116
|
+
/** Identity that owns the thread; `""` for a thread created without identity. */
|
|
117
|
+
createdById: string;
|
|
118
|
+
archived: false;
|
|
119
|
+
createdAt: string;
|
|
120
|
+
updatedAt: string;
|
|
121
|
+
}
|
|
122
|
+
declare class InMemoryEventStore {
|
|
123
|
+
threadId: string;
|
|
124
|
+
readonly ownerId: string;
|
|
125
|
+
/**
|
|
126
|
+
* @param ownerId Identity that owns this thread, recorded when the thread is
|
|
127
|
+
* created by its first run. `""` is the anonymous owner;
|
|
128
|
+
* {@link ɵSERVER_THREAD_OWNER} is the owner of a thread created server-side.
|
|
129
|
+
*/
|
|
130
|
+
constructor(threadId: string, ownerId: string);
|
|
131
|
+
/** The subject that current consumers subscribe to. */
|
|
132
|
+
subject: ReplaySubject<BaseEvent> | null;
|
|
133
|
+
/** True while a run is actively producing events. */
|
|
134
|
+
isRunning: boolean;
|
|
135
|
+
/** Current run ID */
|
|
136
|
+
currentRunId: string | null;
|
|
137
|
+
/** Historic completed runs */
|
|
138
|
+
historicRuns: HistoricRun[];
|
|
139
|
+
/** Currently running agent instance (if any). */
|
|
140
|
+
agent: AbstractAgent | null;
|
|
141
|
+
/** Subject returned from run() while the run is active. */
|
|
142
|
+
runSubject: ReplaySubject<BaseEvent> | null;
|
|
143
|
+
/**
|
|
144
|
+
* Thread-level lifecycle flag: true once a stop/supersede has been requested
|
|
145
|
+
* for the currently-owning run but that run has not yet finalized. Drives
|
|
146
|
+
* eviction protection, the connect() bridge, and stop() de-dup. This is NOT
|
|
147
|
+
* the finalize intent read by a run's teardown — that lives per-run on
|
|
148
|
+
* {@link activeFinalize}, so a superseding run resetting this field cannot
|
|
149
|
+
* mislabel the run it replaced. A new run resets this to false when it takes
|
|
150
|
+
* ownership.
|
|
151
|
+
*/
|
|
152
|
+
stopRequested: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Finalize control of the currently-owning run. `stop()` and a superseding
|
|
155
|
+
* `run()` flip the owning run's flag through this reference; each run also
|
|
156
|
+
* captures the SAME object in its closure, so its teardown finalizes against
|
|
157
|
+
* its own intent regardless of what a later run does to the store.
|
|
158
|
+
*/
|
|
159
|
+
activeFinalize: RunFinalizeControl | null;
|
|
160
|
+
/** Reference to the events emitted in the current run. */
|
|
161
|
+
currentEvents: BaseEvent[] | null;
|
|
162
|
+
/**
|
|
163
|
+
* The thread's single latest NON-EMPTY message snapshot, held at the THREAD
|
|
164
|
+
* level (independent of `historicRuns` lifecycle). Decoupling the snapshot
|
|
165
|
+
* from per-run storage means run-cap FIFO eviction and interleaved
|
|
166
|
+
* empty-snapshot runs can never drop or pin the thread's message history.
|
|
167
|
+
*/
|
|
168
|
+
messagesSnapshot: Message[];
|
|
169
|
+
/** Approximate retained byte size of `messagesSnapshot`. */
|
|
170
|
+
approxMessagesSnapshotBytes: number;
|
|
171
|
+
/**
|
|
172
|
+
* The thread's true creation timestamp (epoch ms), captured from the FIRST
|
|
173
|
+
* run ever appended and held at the THREAD level (independent of
|
|
174
|
+
* `historicRuns` lifecycle). Decoupling it from per-run storage means run-cap
|
|
175
|
+
* FIFO eviction — which shifts the oldest entries off `historicRuns` — can
|
|
176
|
+
* never move the reported creation time forward. `null` until the first run
|
|
177
|
+
* lands. Mirrors the `messagesSnapshot` thread-level decoupling.
|
|
178
|
+
*/
|
|
179
|
+
createdAt: number | null;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* How long, and how many, owner records the store keeps for threads that left
|
|
183
|
+
* it through LRU eviction or a scoped clear. See
|
|
184
|
+
* {@link ɵBoundedThreadStore.ownerOf}.
|
|
185
|
+
*
|
|
186
|
+
* When a record is added over a limit, expired records go first; then, when
|
|
187
|
+
* the record's owner holds more than `maxEntriesPerOwner`, that owner's
|
|
188
|
+
* oldest record; then, over `maxEntries`, the oldest record of any owner. So
|
|
189
|
+
* one identity that churns threads (anonymous callers share one identity)
|
|
190
|
+
* only displaces its own records. Residual risk: many distinct identities
|
|
191
|
+
* together can still exceed `maxEntries` and push out another identity's
|
|
192
|
+
* live record. That frees the id for a new owner but leaks nothing, since
|
|
193
|
+
* the removed thread's history is already gone, and it needs the victim's
|
|
194
|
+
* thread id.
|
|
195
|
+
*/
|
|
196
|
+
interface ɵOwnerRetention {
|
|
197
|
+
/** Milliseconds an owner record is kept after its thread was removed. */
|
|
198
|
+
ttlMs: number;
|
|
199
|
+
/** Most owner records kept in all. */
|
|
200
|
+
maxEntries: number;
|
|
201
|
+
/** Most owner records kept for one owner. */
|
|
202
|
+
maxEntriesPerOwner: number;
|
|
203
|
+
/** Clock, replaceable in tests. */
|
|
204
|
+
now: () => number;
|
|
205
|
+
}
|
|
206
|
+
declare const ɵOWNER_RETENTION_DEFAULTS: ɵOwnerRetention;
|
|
207
|
+
declare class ɵBoundedThreadStore {
|
|
208
|
+
private readonly map;
|
|
209
|
+
/**
|
|
210
|
+
* Owners of threads that were removed from `map`, oldest first. A removed
|
|
211
|
+
* thread's history is gone, but its id stays reserved for its owner until
|
|
212
|
+
* the record expires, so another identity cannot claim the id and receive
|
|
213
|
+
* the owner's next runs or later replays.
|
|
214
|
+
*/
|
|
215
|
+
private readonly removedOwners;
|
|
216
|
+
/** The ids in `removedOwners`, per owner, oldest first. */
|
|
217
|
+
private readonly removedOwnersByOwner;
|
|
218
|
+
private ownerRetention;
|
|
219
|
+
private totalBytes;
|
|
220
|
+
private warned;
|
|
221
|
+
/** True once limits have been EXPLICITLY set (via setLimits), not just the constructor default. */
|
|
222
|
+
private limitsExplicitlySet;
|
|
223
|
+
/** Warn-once latch for the clobber warning, kept distinct from the eviction `warned` latch. */
|
|
224
|
+
private clobberWarned;
|
|
225
|
+
private limits;
|
|
226
|
+
constructor(limits: Required<InMemoryLimits>);
|
|
227
|
+
get byteTotal(): number;
|
|
228
|
+
/**
|
|
229
|
+
* The store's CURRENT effective bounds. Exposed (with the `ɵ` internal-API
|
|
230
|
+
* prefix) so a partial `setLimits` can coalesce unspecified fields against the
|
|
231
|
+
* live config rather than the hardcoded {@link ɵINMEMORY_DEFAULTS} — a partial
|
|
232
|
+
* update must be a partial update, never a silent reset of the fields the
|
|
233
|
+
* caller did not mention. Returns a copy so callers cannot mutate the store's
|
|
234
|
+
* bounds through it.
|
|
235
|
+
*/
|
|
236
|
+
get ɵlimits(): Required<InMemoryLimits>;
|
|
237
|
+
/**
|
|
238
|
+
* Reconfigure the process-global store's bounds. Called by the
|
|
239
|
+
* {@link InMemoryAgentRunner} constructor when limits are passed. Because the
|
|
240
|
+
* store is a per-process singleton, this replaces the bounds for ALL in-memory
|
|
241
|
+
* threads. Emits {@link LIMITS_CLOBBER_GUIDANCE} at most ONCE per store when a
|
|
242
|
+
* SECOND (or later) explicit set arrives whose resolved values differ from the
|
|
243
|
+
* prior explicit set — i.e. a genuine clobber of an already-customized config.
|
|
244
|
+
* The first explicit customization (defaults → custom) is the intended
|
|
245
|
+
* override and never warns; identical re-sets never warn.
|
|
246
|
+
*/
|
|
247
|
+
setLimits(limits: Required<InMemoryLimits>): void;
|
|
248
|
+
get size(): number;
|
|
249
|
+
/** Re-insert at the tail so Map iteration order stays LRU-first. */
|
|
250
|
+
private touchOrder;
|
|
251
|
+
/**
|
|
252
|
+
* The thread's store, created and owned by `ownerId` when it does not exist
|
|
253
|
+
* yet. An existing store keeps its owner; callers check access first.
|
|
254
|
+
*/
|
|
255
|
+
getOrCreate(threadId: string, ownerId?: string): InMemoryEventStore;
|
|
256
|
+
get(threadId: string, opts: {
|
|
257
|
+
touch: boolean;
|
|
258
|
+
}): InMemoryEventStore | undefined;
|
|
259
|
+
peek(threadId: string): InMemoryEventStore | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* Evict the least-recently-used thread that is neither running NOR
|
|
262
|
+
* mid-finalization. Returns false if none evictable. The `protect` thread
|
|
263
|
+
* (typically the one just created) is never evicted, so a fresh thread is not
|
|
264
|
+
* immediately dropped when it is the only non-running candidate.
|
|
265
|
+
*
|
|
266
|
+
* A thread is skipped while `isRunning` OR `stopRequested` is set.
|
|
267
|
+
* `stop()` flips `isRunning` to false the moment it aborts the agent, but the
|
|
268
|
+
* run keeps finalizing asynchronously (the abort trips the `catch` in
|
|
269
|
+
* `runAgent`, which later calls `appendRun`). During that window
|
|
270
|
+
* `stopRequested` stays true; evicting the thread then would make the pending
|
|
271
|
+
* `appendRun` hit `if (!store) return` and silently drop the aborted run's
|
|
272
|
+
* history. Guarding on `stopRequested` keeps the thread alive until
|
|
273
|
+
* finalization completes.
|
|
274
|
+
*/
|
|
275
|
+
private evictOneLru;
|
|
276
|
+
/**
|
|
277
|
+
* Append a finished run to `writer`, the store its run started on. Nothing is
|
|
278
|
+
* written when `writer` is no longer the live store for `threadId` (the thread
|
|
279
|
+
* was removed, or removed and claimed again): a run must never write into a
|
|
280
|
+
* thread it did not start on, which may now belong to another owner.
|
|
281
|
+
*/
|
|
282
|
+
appendRun(threadId: string, writer: InMemoryEventStore | undefined, run: HistoricRun): void;
|
|
283
|
+
private enforceRunCap;
|
|
284
|
+
/**
|
|
285
|
+
* Trim the store back under the byte ceiling by evicting LRU non-running
|
|
286
|
+
* threads. `protect` (the just-appended thread) is never self-evicted, so a
|
|
287
|
+
* fresh run pushes OTHER threads out rather than dropping itself.
|
|
288
|
+
*/
|
|
289
|
+
private evictByBytesIfNeeded;
|
|
290
|
+
private removeThread;
|
|
291
|
+
/**
|
|
292
|
+
* Keep the owner of a removed thread, within the retention bounds. See
|
|
293
|
+
* {@link ɵOwnerRetention} for which records go first over a limit.
|
|
294
|
+
*/
|
|
295
|
+
private rememberOwner;
|
|
296
|
+
/** Remove the owner record of `threadId`, if any. */
|
|
297
|
+
private forgetOwner;
|
|
298
|
+
/** Drop expired owner records. They are oldest first, so stop at the first live one. */
|
|
299
|
+
private pruneRemovedOwners;
|
|
300
|
+
/**
|
|
301
|
+
* Owner of `threadId`: the live thread's owner, or the retained owner of a
|
|
302
|
+
* thread that was evicted or cleared. `undefined` when nobody owns the id, so
|
|
303
|
+
* the next run may claim it.
|
|
304
|
+
*/
|
|
305
|
+
ownerOf(threadId: string): string | undefined;
|
|
306
|
+
/** True when a caller acting as `owner` may run on, or claim, `threadId`. */
|
|
307
|
+
canClaim(threadId: string, owner: string): boolean;
|
|
308
|
+
/**
|
|
309
|
+
* Replace the owner-record retention. Omitted fields fall back to
|
|
310
|
+
* {@link ɵOWNER_RETENTION_DEFAULTS}. Internal: for tests.
|
|
311
|
+
*/
|
|
312
|
+
ɵsetOwnerRetention(retention: Partial<ɵOwnerRetention>): void;
|
|
313
|
+
private evictThreadsIfNeeded;
|
|
314
|
+
private noteEviction;
|
|
315
|
+
listThreads(scope?: LocalThreadEndpointScope): InMemoryThread[];
|
|
316
|
+
/**
|
|
317
|
+
* Removes every thread visible to `scope`, except threads that are running
|
|
318
|
+
* or still finalizing: removing one would drop its owner record while its
|
|
319
|
+
* run still writes, so another identity could claim the id. Those threads
|
|
320
|
+
* stay, as in `evictOneLru`. A scoped clear leaves other owners' threads
|
|
321
|
+
* untouched.
|
|
322
|
+
*
|
|
323
|
+
* Without a scope the whole store is reset, running threads included. That
|
|
324
|
+
* is an internal reset for tests; `appendRun` keeps an orphaned run from
|
|
325
|
+
* writing into a thread created after the reset.
|
|
326
|
+
*/
|
|
327
|
+
clear(scope?: LocalThreadEndpointScope): void;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Process-wide singleton backing every {@link InMemoryAgentRunner}. Exported
|
|
331
|
+
* (with the `ɵ` internal-API prefix) so tests can inspect the exact store the
|
|
332
|
+
* runner writes to; not part of the public API.
|
|
333
|
+
*/
|
|
334
|
+
declare const ɵGLOBAL_STORE: ɵBoundedThreadStore;
|
|
335
|
+
declare class InMemoryAgentRunner extends AgentRunner {
|
|
336
|
+
readonly ɵsupportsLocalThreadEndpoints = true;
|
|
337
|
+
/**
|
|
338
|
+
* How to handle a `run()` for a thread that already has an in-flight run.
|
|
339
|
+
* `"throw"` (default) preserves the historic behavior. `"supersede"` aborts
|
|
340
|
+
* the prior run (mirroring `stop()`) and starts the new one — opted into by
|
|
341
|
+
* the hosted-bot listener so a fast follow-up turn on the same thread cleanly
|
|
342
|
+
* replaces a still-running (or wedged) prior turn instead of erroring with
|
|
343
|
+
* "Thread already running".
|
|
344
|
+
*/
|
|
345
|
+
private readonly onConcurrentRun;
|
|
346
|
+
/**
|
|
347
|
+
* @param options Per-runner behavior (`onConcurrentRun`) plus optional bounds
|
|
348
|
+
* for the in-memory store ({@link InMemoryLimits}).
|
|
349
|
+
*
|
|
350
|
+
* Note the differing scopes: `onConcurrentRun` is per-runner instance, while
|
|
351
|
+
* the limits reconfigure the PROCESS-GLOBAL store shared by every
|
|
352
|
+
* `InMemoryAgentRunner`. Omit the limits for safe defaults
|
|
353
|
+
* ({@link ɵINMEMORY_DEFAULTS}); passing none leaves the store untouched. When
|
|
354
|
+
* multiple runners are constructed with differing limits, the last-constructed
|
|
355
|
+
* wins — in practice the OSS/SSE default construction passes nothing. If a
|
|
356
|
+
* second (or later) runner is constructed with limits that DIFFER from an
|
|
357
|
+
* already-customized store, a one-time `console.warn` is emitted to signal that
|
|
358
|
+
* the shared store's bounds are being clobbered for ALL in-memory threads.
|
|
359
|
+
*/
|
|
360
|
+
constructor(options?: InMemoryAgentRunnerOptions);
|
|
361
|
+
run(request: AgentRunnerRunRequest): Observable<BaseEvent>;
|
|
362
|
+
connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;
|
|
363
|
+
isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean>;
|
|
364
|
+
stop(request: AgentRunnerStopRequest): Promise<boolean | undefined>;
|
|
365
|
+
/**
|
|
366
|
+
* Returns a summary of every thread that `scope`'s owner holds in the
|
|
367
|
+
* process-wide store, which every InMemoryAgentRunner shares. Without a
|
|
368
|
+
* scope, the server owner's threads ({@link ɵSERVER_THREAD_OWNER}).
|
|
369
|
+
*
|
|
370
|
+
* This powers the local-dev fallback for `GET /threads` when the Intelligence
|
|
371
|
+
* platform is not configured. Each entry mirrors the shape of a platform
|
|
372
|
+
* `ThreadRecord` so the HTTP handler can use the same response envelope.
|
|
373
|
+
*/
|
|
374
|
+
listThreads(scope?: LocalThreadEndpointScope): InMemoryThread[];
|
|
375
|
+
/**
|
|
376
|
+
* Returns all messages for a thread, using the snapshot captured at the end
|
|
377
|
+
* of the most recent run.
|
|
378
|
+
*
|
|
379
|
+
* This powers the local-dev fallback for `GET /threads/:threadId/messages`
|
|
380
|
+
* when CopilotKit Intelligence is not configured. The returned `Message[]`
|
|
381
|
+
* objects come directly from the ag-ui agent, so their shape is compatible
|
|
382
|
+
* with CopilotKit Intelligence's `ThreadMessage` type.
|
|
383
|
+
*/
|
|
384
|
+
getThreadMessages(threadId: string, scope?: LocalThreadEndpointScope): Message[];
|
|
385
|
+
/**
|
|
386
|
+
* Returns all AG-UI events for a thread, compacted across historic runs.
|
|
387
|
+
*
|
|
388
|
+
* Powers the local-dev fallback for `GET /threads/:threadId/events` when the
|
|
389
|
+
* CopilotKit Intelligence is not configured. The compaction logic matches
|
|
390
|
+
* the connection-replay path in {@link connect}, so the stream a
|
|
391
|
+
* late-joining inspector sees matches what this method returns.
|
|
392
|
+
*/
|
|
393
|
+
getThreadEvents(threadId: string, scope?: LocalThreadEndpointScope): BaseEvent[];
|
|
394
|
+
/**
|
|
395
|
+
* Returns the agent state snapshot for a thread.
|
|
396
|
+
*
|
|
397
|
+
* Derived from the last `STATE_SNAPSHOT` in the compacted event stream. The
|
|
398
|
+
* AG-UI `compactEvents` helper consolidates STATE_DELTA events and produces
|
|
399
|
+
* a single trailing STATE_SNAPSHOT when state changes exist, so this is a
|
|
400
|
+
* faithful view of state at the end of the most recent run.
|
|
401
|
+
*
|
|
402
|
+
* Returns `null` when the thread has never emitted a STATE_SNAPSHOT.
|
|
403
|
+
*/
|
|
404
|
+
getThreadState(threadId: string, scope?: LocalThreadEndpointScope): Record<string, unknown> | null;
|
|
405
|
+
/**
|
|
406
|
+
* Clears the in-memory history of `scope`'s threads (without a scope, the
|
|
407
|
+
* server owner's). A thread with a run still active or finalizing is kept;
|
|
408
|
+
* see {@link ɵBoundedThreadStore.clear}.
|
|
409
|
+
*
|
|
410
|
+
* Powers the local-dev fallback for `POST /threads/clear`, letting consumers
|
|
411
|
+
* (e.g. the demo's Clear button) reset to an empty thread list without
|
|
412
|
+
* restarting the runtime. Intentionally not exposed on the Intelligence
|
|
413
|
+
* platform path: there, thread history lives in a real database and must
|
|
414
|
+
* not be wiped this way.
|
|
415
|
+
*/
|
|
416
|
+
clearThreads(scope?: LocalThreadEndpointScope): void;
|
|
417
|
+
/**
|
|
418
|
+
* False when the thread id is held by an owner other than `scope`'s: a
|
|
419
|
+
* live thread, or the retained owner of an evicted or cleared one.
|
|
420
|
+
*/
|
|
421
|
+
isThreadAccessible(threadId: string, scope: LocalThreadEndpointScope): boolean;
|
|
422
|
+
/** The thread's store, or `undefined` when unknown or not visible to `scope`. */
|
|
423
|
+
private peekVisible;
|
|
424
|
+
}
|
|
425
|
+
//#endregion
|
|
426
|
+
export { InMemoryAgentRunner, InMemoryAgentRunnerOptions, InMemoryLimits, InMemoryThread, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵOWNER_RETENTION_DEFAULTS, ɵOwnerRetention, ɵestimateBytes, ɵnormalizeLimits };
|
|
427
|
+
//# sourceMappingURL=in-memory.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.d.cts","names":[],"sources":["../../../src/runtime/runner/in-memory.ts"],"mappings":";;;;;UA0BiB,cAAA;;EAEf,UAAA;EAAA;EAEA,gBAAA;EAkBA;;;AAWF;;;;;AASA;;;;;AAsCA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