@copilotkit/runtime 2.0.0-rc.6 → 2.0.0-rc.61
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/README.md +29 -4
- package/dist/agent/{url-download.cjs → ai-sdk/url-download.cjs} +19 -76
- package/dist/agent/ai-sdk/url-download.cjs.map +1 -0
- package/dist/agent/{url-download.d.cts → ai-sdk/url-download.d.cts} +11 -8
- package/dist/agent/ai-sdk/url-download.d.cts.map +1 -0
- package/dist/agent/{url-download.d.mts → ai-sdk/url-download.d.mts} +11 -8
- package/dist/agent/ai-sdk/url-download.d.mts.map +1 -0
- package/dist/agent/{url-download.mjs → ai-sdk/url-download.mjs} +20 -74
- package/dist/agent/ai-sdk/url-download.mjs.map +1 -0
- package/dist/agent/ai-sdk.cjs +425 -0
- package/dist/agent/ai-sdk.cjs.map +1 -0
- package/dist/agent/ai-sdk.d.cts +119 -0
- package/dist/agent/ai-sdk.d.cts.map +1 -0
- package/dist/agent/ai-sdk.d.mts +119 -0
- package/dist/agent/ai-sdk.d.mts.map +1 -0
- package/dist/agent/ai-sdk.mjs +419 -0
- package/dist/agent/ai-sdk.mjs.map +1 -0
- package/dist/agent/classic-tools.cjs +185 -0
- package/dist/agent/classic-tools.cjs.map +1 -0
- package/dist/agent/classic-tools.mjs +183 -0
- package/dist/agent/classic-tools.mjs.map +1 -0
- package/dist/agent/converters/aisdk.cjs +17 -4
- package/dist/agent/converters/aisdk.cjs.map +1 -1
- package/dist/agent/converters/aisdk.d.cts.map +1 -1
- package/dist/agent/converters/aisdk.d.mts.map +1 -1
- package/dist/agent/converters/aisdk.mjs +18 -2
- package/dist/agent/converters/aisdk.mjs.map +1 -1
- package/dist/agent/converters/tanstack.cjs +202 -30
- package/dist/agent/converters/tanstack.cjs.map +1 -1
- package/dist/agent/converters/tanstack.d.cts +90 -6
- package/dist/agent/converters/tanstack.d.cts.map +1 -1
- package/dist/agent/converters/tanstack.d.mts +90 -6
- package/dist/agent/converters/tanstack.d.mts.map +1 -1
- package/dist/agent/converters/tanstack.mjs +202 -29
- package/dist/agent/converters/tanstack.mjs.map +1 -1
- package/dist/agent/learned-skills.cjs +15 -17
- package/dist/agent/learned-skills.cjs.map +1 -1
- package/dist/agent/learned-skills.d.cts +9 -3
- package/dist/agent/learned-skills.d.cts.map +1 -1
- package/dist/agent/learned-skills.d.mts +9 -3
- package/dist/agent/learned-skills.d.mts.map +1 -1
- package/dist/agent/learned-skills.mjs +15 -16
- package/dist/agent/learned-skills.mjs.map +1 -1
- package/dist/agent/model.cjs +42 -0
- package/dist/agent/model.cjs.map +1 -0
- package/dist/agent/model.d.cts +19 -0
- package/dist/agent/model.d.cts.map +1 -0
- package/dist/agent/model.d.mts +19 -0
- package/dist/agent/model.d.mts.map +1 -0
- package/dist/agent/model.mjs +41 -0
- package/dist/agent/model.mjs.map +1 -0
- package/dist/agent/state-delta.cjs +0 -1
- package/dist/agent/state-delta.cjs.map +1 -1
- package/dist/agent.cjs +558 -0
- package/dist/agent.cjs.map +1 -0
- package/dist/agent.d.cts +455 -0
- package/dist/agent.d.cts.map +1 -0
- package/dist/agent.d.mts +455 -0
- package/dist/agent.d.mts.map +1 -0
- package/dist/agent.mjs +551 -0
- package/dist/agent.mjs.map +1 -0
- package/dist/index.cjs +23 -28
- package/dist/index.d.cts +14 -14
- package/dist/index.d.mts +14 -14
- package/dist/index.mjs +8 -8
- package/dist/internal/learned-skills.d.cts +1 -1
- package/dist/internal/learned-skills.d.mts +1 -1
- package/dist/node.cjs +2 -3
- package/dist/node.d.cts +3 -3
- package/dist/node.d.mts +3 -3
- package/dist/node.mjs +3 -3
- package/dist/runtime/core/channel-manager.cjs +10 -2
- package/dist/runtime/core/channel-manager.cjs.map +1 -1
- package/dist/runtime/core/channel-manager.d.cts +1 -1
- package/dist/runtime/core/channel-manager.d.mts +1 -1
- package/dist/runtime/core/channel-manager.mjs +10 -1
- package/dist/runtime/core/channel-manager.mjs.map +1 -1
- package/dist/runtime/core/debug-event-bus.cjs +4 -3
- package/dist/runtime/core/debug-event-bus.cjs.map +1 -1
- package/dist/runtime/core/debug-event-bus.d.cts +5 -1
- package/dist/runtime/core/debug-event-bus.d.cts.map +1 -1
- package/dist/runtime/core/debug-event-bus.d.mts +4 -0
- package/dist/runtime/core/debug-event-bus.d.mts.map +1 -1
- package/dist/runtime/core/debug-event-bus.mjs +5 -3
- package/dist/runtime/core/debug-event-bus.mjs.map +1 -1
- package/dist/runtime/core/fetch-cors.cjs.map +1 -1
- package/dist/runtime/core/fetch-cors.d.cts +2 -2
- package/dist/runtime/core/fetch-cors.d.cts.map +1 -1
- package/dist/runtime/core/fetch-cors.d.mts +2 -2
- package/dist/runtime/core/fetch-cors.d.mts.map +1 -1
- package/dist/runtime/core/fetch-cors.mjs.map +1 -1
- package/dist/runtime/core/fetch-handler.cjs +17 -14
- package/dist/runtime/core/fetch-handler.cjs.map +1 -1
- package/dist/runtime/core/fetch-handler.d.cts +22 -14
- package/dist/runtime/core/fetch-handler.d.cts.map +1 -1
- package/dist/runtime/core/fetch-handler.d.mts +22 -14
- package/dist/runtime/core/fetch-handler.d.mts.map +1 -1
- package/dist/runtime/core/fetch-handler.mjs +9 -5
- package/dist/runtime/core/fetch-handler.mjs.map +1 -1
- package/dist/runtime/core/hooks.cjs.map +1 -1
- package/dist/runtime/core/hooks.d.cts +5 -5
- package/dist/runtime/core/hooks.d.cts.map +1 -1
- package/dist/runtime/core/hooks.d.mts +5 -5
- package/dist/runtime/core/hooks.d.mts.map +1 -1
- package/dist/runtime/core/hooks.mjs.map +1 -1
- package/dist/runtime/core/learning.cjs.map +1 -1
- package/dist/runtime/core/learning.d.cts +9 -9
- package/dist/runtime/core/learning.d.cts.map +1 -1
- package/dist/runtime/core/learning.d.mts +8 -8
- package/dist/runtime/core/learning.d.mts.map +1 -1
- package/dist/runtime/core/learning.mjs.map +1 -1
- package/dist/runtime/core/logger.cjs +105 -14
- package/dist/runtime/core/logger.cjs.map +1 -1
- package/dist/runtime/core/logger.d.cts +26 -9
- package/dist/runtime/core/logger.d.cts.map +1 -1
- package/dist/runtime/core/logger.d.mts +26 -9
- package/dist/runtime/core/logger.d.mts.map +1 -1
- package/dist/runtime/core/logger.mjs +105 -12
- package/dist/runtime/core/logger.mjs.map +1 -1
- package/dist/runtime/core/middleware-sse-parser.cjs +3 -4
- package/dist/runtime/core/middleware-sse-parser.cjs.map +1 -1
- package/dist/runtime/core/middleware-sse-parser.d.cts.map +1 -1
- package/dist/runtime/core/middleware-sse-parser.d.mts.map +1 -1
- package/dist/runtime/core/middleware-sse-parser.mjs +2 -2
- package/dist/runtime/core/middleware-sse-parser.mjs.map +1 -1
- package/dist/runtime/core/middleware.cjs +5 -5
- package/dist/runtime/core/middleware.cjs.map +1 -1
- package/dist/runtime/core/middleware.d.cts +3 -3
- package/dist/runtime/core/middleware.d.cts.map +1 -1
- package/dist/runtime/core/middleware.d.mts +3 -3
- package/dist/runtime/core/middleware.d.mts.map +1 -1
- package/dist/runtime/core/middleware.mjs +4 -3
- package/dist/runtime/core/middleware.mjs.map +1 -1
- package/dist/runtime/core/package-info.cjs +1 -1
- package/dist/runtime/core/package-info.mjs +1 -1
- package/dist/runtime/core/runtime-error-reporter.cjs.map +1 -1
- package/dist/runtime/core/runtime-error-reporter.mjs.map +1 -1
- package/dist/runtime/core/runtime.cjs +44 -46
- package/dist/runtime/core/runtime.cjs.map +1 -1
- package/dist/runtime/core/runtime.d.cts +178 -91
- package/dist/runtime/core/runtime.d.cts.map +1 -1
- package/dist/runtime/core/runtime.d.mts +178 -91
- package/dist/runtime/core/runtime.d.mts.map +1 -1
- package/dist/runtime/core/runtime.mjs +42 -42
- package/dist/runtime/core/runtime.mjs.map +1 -1
- package/dist/runtime/endpoints/auto-start-channels.cjs +3 -4
- package/dist/runtime/endpoints/auto-start-channels.cjs.map +1 -1
- package/dist/runtime/endpoints/auto-start-channels.mjs +2 -2
- package/dist/runtime/endpoints/auto-start-channels.mjs.map +1 -1
- package/dist/runtime/endpoints/node-fetch-handler.cjs +4 -8
- package/dist/runtime/endpoints/node-fetch-handler.cjs.map +1 -1
- package/dist/runtime/endpoints/node-fetch-handler.d.cts +4 -5
- package/dist/runtime/endpoints/node-fetch-handler.d.cts.map +1 -1
- package/dist/runtime/endpoints/node-fetch-handler.d.mts +4 -5
- package/dist/runtime/endpoints/node-fetch-handler.d.mts.map +1 -1
- package/dist/runtime/endpoints/node-fetch-handler.mjs +3 -5
- package/dist/runtime/endpoints/node-fetch-handler.mjs.map +1 -1
- package/dist/runtime/endpoints/node.cjs +7 -5
- package/dist/runtime/endpoints/node.cjs.map +1 -1
- package/dist/runtime/endpoints/node.d.cts +16 -16
- package/dist/runtime/endpoints/node.d.cts.map +1 -1
- package/dist/runtime/endpoints/node.d.mts +16 -16
- package/dist/runtime/endpoints/node.d.mts.map +1 -1
- package/dist/runtime/endpoints/node.mjs +9 -7
- package/dist/runtime/endpoints/node.mjs.map +1 -1
- package/dist/runtime/event-transforms/index.d.cts +4 -0
- package/dist/runtime/event-transforms/index.d.mts +4 -0
- package/dist/runtime/event-transforms/index.mjs +5 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.cjs +277 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.cjs.map +1 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.d.cts +61 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.d.cts.map +1 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.d.mts +61 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.d.mts.map +1 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.mjs +276 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.mjs.map +1 -0
- package/dist/runtime/event-transforms/recorded-events.cjs +68 -0
- package/dist/runtime/event-transforms/recorded-events.cjs.map +1 -0
- package/dist/runtime/event-transforms/recorded-events.d.cts +27 -0
- package/dist/runtime/event-transforms/recorded-events.d.cts.map +1 -0
- package/dist/runtime/event-transforms/recorded-events.d.mts +27 -0
- package/dist/runtime/event-transforms/recorded-events.d.mts.map +1 -0
- package/dist/runtime/event-transforms/recorded-events.mjs +68 -0
- package/dist/runtime/event-transforms/recorded-events.mjs.map +1 -0
- package/dist/runtime/event-transforms/streaming-json-scanner.cjs +289 -0
- package/dist/runtime/event-transforms/streaming-json-scanner.cjs.map +1 -0
- package/dist/runtime/event-transforms/streaming-json-scanner.mjs +288 -0
- package/dist/runtime/event-transforms/streaming-json-scanner.mjs.map +1 -0
- package/dist/runtime/generative-ui/a2ui-v09-actions.cjs +106 -0
- package/dist/runtime/generative-ui/a2ui-v09-actions.cjs.map +1 -0
- package/dist/runtime/generative-ui/a2ui-v09-actions.mjs +106 -0
- package/dist/runtime/generative-ui/a2ui-v09-actions.mjs.map +1 -0
- package/dist/runtime/generative-ui/a2ui-v09-catalog.cjs +422 -0
- package/dist/runtime/generative-ui/a2ui-v09-catalog.cjs.map +1 -0
- package/dist/runtime/generative-ui/a2ui-v09-catalog.mjs +422 -0
- package/dist/runtime/generative-ui/a2ui-v09-catalog.mjs.map +1 -0
- package/dist/runtime/generative-ui/a2ui-v09-middleware.cjs +84 -0
- package/dist/runtime/generative-ui/a2ui-v09-middleware.cjs.map +1 -0
- package/dist/runtime/generative-ui/a2ui-v09-middleware.d.cts +41 -0
- package/dist/runtime/generative-ui/a2ui-v09-middleware.d.cts.map +1 -0
- package/dist/runtime/generative-ui/a2ui-v09-middleware.d.mts +41 -0
- package/dist/runtime/generative-ui/a2ui-v09-middleware.d.mts.map +1 -0
- package/dist/runtime/generative-ui/a2ui-v09-middleware.mjs +83 -0
- package/dist/runtime/generative-ui/a2ui-v09-middleware.mjs.map +1 -0
- package/dist/runtime/generative-ui/a2ui-v09-operations.cjs +694 -0
- package/dist/runtime/generative-ui/a2ui-v09-operations.cjs.map +1 -0
- package/dist/runtime/generative-ui/a2ui-v09-operations.mjs +694 -0
- package/dist/runtime/generative-ui/a2ui-v09-operations.mjs.map +1 -0
- package/dist/runtime/generative-ui/generative-ui-middleware.cjs +0 -1
- package/dist/runtime/generative-ui/generative-ui-middleware.cjs.map +1 -1
- package/dist/runtime/generative-ui/index.d.cts +1 -0
- package/dist/runtime/generative-ui/index.d.mts +1 -0
- package/dist/runtime/generative-ui/surface-writer.cjs +4 -5
- package/dist/runtime/generative-ui/surface-writer.cjs.map +1 -1
- package/dist/runtime/generative-ui/surface-writer.d.cts +1 -1
- package/dist/runtime/generative-ui/surface-writer.d.cts.map +1 -1
- package/dist/runtime/generative-ui/surface-writer.d.mts.map +1 -1
- package/dist/runtime/generative-ui/surface-writer.mjs +5 -5
- package/dist/runtime/generative-ui/surface-writer.mjs.map +1 -1
- package/dist/runtime/handlers/get-runtime-info.cjs +24 -6
- package/dist/runtime/handlers/get-runtime-info.cjs.map +1 -1
- package/dist/runtime/handlers/get-runtime-info.mjs +25 -7
- package/dist/runtime/handlers/get-runtime-info.mjs.map +1 -1
- package/dist/runtime/handlers/handle-connect.cjs +3 -8
- package/dist/runtime/handlers/handle-connect.cjs.map +1 -1
- package/dist/runtime/handlers/handle-connect.mjs +3 -8
- package/dist/runtime/handlers/handle-connect.mjs.map +1 -1
- package/dist/runtime/handlers/handle-debug-events.cjs.map +1 -1
- package/dist/runtime/handlers/handle-debug-events.mjs.map +1 -1
- package/dist/runtime/handlers/handle-inspector-learning.cjs +2 -3
- package/dist/runtime/handlers/handle-inspector-learning.cjs.map +1 -1
- package/dist/runtime/handlers/handle-inspector-learning.mjs.map +1 -1
- package/dist/runtime/handlers/handle-inspector-metadata.cjs +2 -3
- package/dist/runtime/handlers/handle-inspector-metadata.cjs.map +1 -1
- package/dist/runtime/handlers/handle-inspector-metadata.mjs.map +1 -1
- package/dist/runtime/handlers/handle-run.cjs +11 -16
- package/dist/runtime/handlers/handle-run.cjs.map +1 -1
- package/dist/runtime/handlers/handle-run.mjs +8 -12
- package/dist/runtime/handlers/handle-run.mjs.map +1 -1
- package/dist/runtime/handlers/handle-stop.cjs +5 -5
- package/dist/runtime/handlers/handle-stop.cjs.map +1 -1
- package/dist/runtime/handlers/handle-stop.mjs +2 -1
- package/dist/runtime/handlers/handle-stop.mjs.map +1 -1
- package/dist/runtime/handlers/handle-suggest.cjs +6 -3
- package/dist/runtime/handlers/handle-suggest.cjs.map +1 -1
- package/dist/runtime/handlers/handle-suggest.mjs +6 -2
- package/dist/runtime/handlers/handle-suggest.mjs.map +1 -1
- package/dist/runtime/handlers/handle-trajectory-connect.cjs.map +1 -1
- package/dist/runtime/handlers/handle-trajectory-connect.mjs.map +1 -1
- package/dist/runtime/handlers/handle-transcribe.cjs +0 -1
- package/dist/runtime/handlers/handle-transcribe.cjs.map +1 -1
- package/dist/runtime/handlers/handle-transcribe.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/annotate.cjs +8 -8
- package/dist/runtime/handlers/intelligence/annotate.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/annotate.mjs +5 -4
- package/dist/runtime/handlers/intelligence/annotate.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/connect.cjs +6 -2
- package/dist/runtime/handlers/intelligence/connect.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/connect.mjs +6 -2
- package/dist/runtime/handlers/intelligence/connect.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/memories.cjs +28 -23
- package/dist/runtime/handlers/intelligence/memories.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/memories.mjs +12 -6
- package/dist/runtime/handlers/intelligence/memories.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/run.cjs +38 -30
- package/dist/runtime/handlers/intelligence/run.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/run.mjs +37 -28
- package/dist/runtime/handlers/intelligence/run.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/thread-names.cjs +6 -5
- package/dist/runtime/handlers/intelligence/thread-names.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/thread-names.mjs +3 -1
- package/dist/runtime/handlers/intelligence/thread-names.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/threads.cjs +40 -31
- package/dist/runtime/handlers/intelligence/threads.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/threads.mjs +18 -8
- package/dist/runtime/handlers/intelligence/threads.mjs.map +1 -1
- package/dist/runtime/handlers/shared/agent-utils.cjs +50 -46
- package/dist/runtime/handlers/shared/agent-utils.cjs.map +1 -1
- package/dist/runtime/handlers/shared/agent-utils.mjs +47 -42
- package/dist/runtime/handlers/shared/agent-utils.mjs.map +1 -1
- package/dist/runtime/handlers/shared/cloud-telemetry.cjs +0 -1
- package/dist/runtime/handlers/shared/cloud-telemetry.cjs.map +1 -1
- package/dist/runtime/handlers/shared/memory-policy.cjs.map +1 -1
- package/dist/runtime/handlers/shared/memory-policy.mjs.map +1 -1
- package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs +4 -3
- package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -1
- package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs +4 -3
- package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -1
- package/dist/runtime/handlers/shared/sse-response.cjs +77 -78
- package/dist/runtime/handlers/shared/sse-response.cjs.map +1 -1
- package/dist/runtime/handlers/shared/sse-response.mjs +77 -77
- package/dist/runtime/handlers/shared/sse-response.mjs.map +1 -1
- package/dist/runtime/handlers/shared/thread-access.cjs +4 -3
- package/dist/runtime/handlers/shared/thread-access.cjs.map +1 -1
- package/dist/runtime/handlers/shared/thread-access.d.cts.map +1 -1
- package/dist/runtime/handlers/shared/thread-access.d.mts.map +1 -1
- package/dist/runtime/handlers/shared/thread-access.mjs +4 -3
- package/dist/runtime/handlers/shared/thread-access.mjs.map +1 -1
- package/dist/runtime/handlers/sse/connect.cjs +2 -0
- package/dist/runtime/handlers/sse/connect.cjs.map +1 -1
- package/dist/runtime/handlers/sse/connect.mjs +2 -0
- package/dist/runtime/handlers/sse/connect.mjs.map +1 -1
- package/dist/runtime/handlers/sse/run.cjs +5 -2
- package/dist/runtime/handlers/sse/run.cjs.map +1 -1
- package/dist/runtime/handlers/sse/run.mjs +5 -2
- package/dist/runtime/handlers/sse/run.mjs.map +1 -1
- package/dist/runtime/index.d.cts +13 -18
- package/dist/runtime/index.d.mts +13 -18
- package/dist/runtime/intelligence-platform/analytics-context.cjs +84 -0
- package/dist/runtime/intelligence-platform/analytics-context.cjs.map +1 -0
- package/dist/runtime/intelligence-platform/analytics-context.mjs +83 -0
- package/dist/runtime/intelligence-platform/analytics-context.mjs.map +1 -0
- package/dist/runtime/intelligence-platform/client.cjs +30 -4
- package/dist/runtime/intelligence-platform/client.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/client.d.cts +25 -2
- package/dist/runtime/intelligence-platform/client.d.cts.map +1 -1
- package/dist/runtime/intelligence-platform/client.d.mts +25 -2
- package/dist/runtime/intelligence-platform/client.d.mts.map +1 -1
- package/dist/runtime/intelligence-platform/client.mjs +30 -3
- package/dist/runtime/intelligence-platform/client.mjs.map +1 -1
- package/dist/runtime/intelligence-platform/learning-management.cjs +7 -8
- package/dist/runtime/intelligence-platform/learning-management.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/learning-management.mjs +7 -7
- package/dist/runtime/intelligence-platform/learning-management.mjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/archive.cjs +104 -110
- package/dist/runtime/intelligence-platform/skill-registry/archive.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts +8 -2
- package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts +8 -2
- package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/archive.mjs +104 -109
- package/dist/runtime/intelligence-platform/skill-registry/archive.mjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/config.cjs +0 -1
- package/dist/runtime/intelligence-platform/skill-registry/config.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/index.d.cts +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/index.d.mts +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/registry.cjs +22 -19
- package/dist/runtime/intelligence-platform/skill-registry/registry.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/registry.d.cts.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/registry.d.mts.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/registry.mjs +22 -19
- package/dist/runtime/intelligence-platform/skill-registry/registry.mjs.map +1 -1
- package/dist/runtime/intelligence-platform/stop-run.cjs +50 -0
- package/dist/runtime/intelligence-platform/stop-run.cjs.map +1 -0
- package/dist/runtime/intelligence-platform/stop-run.mjs +50 -0
- package/dist/runtime/intelligence-platform/stop-run.mjs.map +1 -0
- package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs +3 -3
- package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs +2 -1
- package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs.map +1 -1
- package/dist/runtime/intelligence-platform/trajectories.cjs +2 -3
- package/dist/runtime/intelligence-platform/trajectories.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/trajectories.mjs +2 -2
- package/dist/runtime/intelligence-platform/trajectories.mjs.map +1 -1
- package/dist/runtime/node.d.cts +2 -2
- package/dist/runtime/node.d.mts +2 -2
- package/dist/runtime/runner/agent-runner.cjs +0 -1
- package/dist/runtime/runner/agent-runner.cjs.map +1 -1
- package/dist/runtime/runner/agent-runner.d.cts +9 -0
- package/dist/runtime/runner/agent-runner.d.cts.map +1 -1
- package/dist/runtime/runner/agent-runner.d.mts +9 -0
- package/dist/runtime/runner/agent-runner.d.mts.map +1 -1
- package/dist/runtime/runner/agent-runner.mjs.map +1 -1
- package/dist/runtime/runner/in-memory.cjs +0 -1
- package/dist/runtime/runner/in-memory.cjs.map +1 -1
- package/dist/runtime/runner/index.d.cts +1 -1
- package/dist/runtime/runner/index.d.mts +1 -1
- package/dist/runtime/runner/index.mjs +1 -1
- package/dist/runtime/runner/intelligence.cjs +55 -9
- package/dist/runtime/runner/intelligence.cjs.map +1 -1
- package/dist/runtime/runner/intelligence.d.cts +12 -1
- package/dist/runtime/runner/intelligence.d.cts.map +1 -1
- package/dist/runtime/runner/intelligence.d.mts +12 -1
- package/dist/runtime/runner/intelligence.d.mts.map +1 -1
- package/dist/runtime/runner/intelligence.mjs +56 -10
- package/dist/runtime/runner/intelligence.mjs.map +1 -1
- package/dist/runtime/telemetry/disclosure.cjs +2 -3
- package/dist/runtime/telemetry/disclosure.cjs.map +1 -1
- package/dist/runtime/telemetry/disclosure.mjs +3 -3
- package/dist/runtime/telemetry/disclosure.mjs.map +1 -1
- package/dist/runtime/telemetry/events.d.cts +1 -1
- package/dist/runtime/telemetry/events.d.mts +1 -1
- package/dist/runtime/telemetry/instance-created.cjs +33 -12
- package/dist/runtime/telemetry/instance-created.cjs.map +1 -1
- package/dist/runtime/telemetry/instance-created.mjs +33 -12
- package/dist/runtime/telemetry/instance-created.mjs.map +1 -1
- package/dist/runtime/telemetry/telemetry-client.cjs +0 -5
- package/dist/runtime/telemetry/telemetry-client.cjs.map +1 -1
- package/dist/runtime/telemetry/telemetry-client.mjs +0 -4
- package/dist/runtime/telemetry/telemetry-client.mjs.map +1 -1
- package/dist/runtime/telemetry/telemetry-identity.cjs +0 -1
- package/dist/runtime/telemetry/telemetry-identity.cjs.map +1 -1
- package/dist/v2/index.d.cts +242 -0
- package/dist/v2/index.d.mts +242 -0
- package/dist/v2/node.d.cts +18 -0
- package/dist/v2/node.d.mts +18 -0
- package/package.json +84 -29
- package/dist/_virtual/_rolldown/runtime.cjs +0 -29
- package/dist/agent/converters/index.d.mts +0 -2
- package/dist/agent/index.cjs +0 -1328
- package/dist/agent/index.cjs.map +0 -1
- package/dist/agent/index.d.cts +0 -467
- package/dist/agent/index.d.cts.map +0 -1
- package/dist/agent/index.d.mts +0 -468
- package/dist/agent/index.d.mts.map +0 -1
- package/dist/agent/index.mjs +0 -1318
- package/dist/agent/index.mjs.map +0 -1
- package/dist/agent/mcp-tool-names.cjs +0 -82
- package/dist/agent/mcp-tool-names.cjs.map +0 -1
- package/dist/agent/mcp-tool-names.mjs +0 -80
- package/dist/agent/mcp-tool-names.mjs.map +0 -1
- package/dist/agent/url-download.cjs.map +0 -1
- package/dist/agent/url-download.d.cts.map +0 -1
- package/dist/agent/url-download.d.mts.map +0 -1
- package/dist/agent/url-download.mjs.map +0 -1
- package/dist/runtime/index.d.cts.map +0 -1
- package/dist/runtime/index.d.mts.map +0 -1
package/dist/agent.mjs
ADDED
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
import { collectStandardRunFinishedDetails, isRecord } from "./agent/converters/usage.mjs";
|
|
2
|
+
import { convertAISDKStream, formatToolError } from "./agent/converters/aisdk.mjs";
|
|
3
|
+
import { convertInputToTanStackAI, convertTanStackStream } from "./agent/converters/tanstack.mjs";
|
|
4
|
+
import { SkillRegistry } from "./runtime/intelligence-platform/skill-registry/registry.mjs";
|
|
5
|
+
import { assertNoSkillToolConflicts, prepareLearnedSkills } from "./agent/learned-skills.mjs";
|
|
6
|
+
import { assertTextAdapter, isAISDKLanguageModel } from "./agent/model.mjs";
|
|
7
|
+
import { STATE_TOOLS, assertFrontendToolSchemas, withClassicToolRules } from "./agent/classic-tools.mjs";
|
|
8
|
+
import { randomUUID, schemaToJsonSchema } from "@copilotkit/shared";
|
|
9
|
+
import { Observable } from "rxjs";
|
|
10
|
+
import { AbstractAgent, EventType, PROTOCOL_VERSION } from "@ag-ui/client";
|
|
11
|
+
|
|
12
|
+
//#region src/agent/index.ts
|
|
13
|
+
/**
|
|
14
|
+
* Thrown by `AgentFactoryContext.interrupt()` on a fresh (non-resume) run to
|
|
15
|
+
* pause the factory. Caught in `runFactory` and translated into a RUN_FINISHED
|
|
16
|
+
* event carrying `outcome:{type:"interrupt",interrupts}`. Not a real error.
|
|
17
|
+
*/
|
|
18
|
+
var InterruptSignal = class extends Error {
|
|
19
|
+
constructor(interrupts) {
|
|
20
|
+
super("CopilotKit interrupt: run paused awaiting human input");
|
|
21
|
+
this.interrupts = interrupts;
|
|
22
|
+
this.name = "InterruptSignal";
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Defines a server tool for BuiltInAgent, or for any TanStack AI `chat()`
|
|
27
|
+
* call.
|
|
28
|
+
*
|
|
29
|
+
* The parameters become the tool's JSON Schema, which the model sees. Before
|
|
30
|
+
* `execute` runs, the arguments go through the schema's own Standard Schema
|
|
31
|
+
* validation, so `execute` gets the parsed output (for example with Zod
|
|
32
|
+
* defaults applied). Arguments that fail the schema, and errors that `execute`
|
|
33
|
+
* throws, become the tool's error result.
|
|
34
|
+
*
|
|
35
|
+
* A tool without `execute` (an interrupt tool) has no executor, so `chat()`
|
|
36
|
+
* stops the run when the model calls it.
|
|
37
|
+
*
|
|
38
|
+
* @param config.name - The name of the tool.
|
|
39
|
+
* @param config.description - What the tool does, for the model.
|
|
40
|
+
* @param config.parameters - Schema for the tool's input parameters (any
|
|
41
|
+
* Standard Schema V1 library that can describe itself as JSON Schema: Zod,
|
|
42
|
+
* Valibot, ArkType, etc.).
|
|
43
|
+
* @param config.execute - Runs the tool server-side with the parsed arguments.
|
|
44
|
+
* @param config.interrupt - Pause the run for human input instead of
|
|
45
|
+
* executing. See {@link CopilotKitToolSettings}.
|
|
46
|
+
* @throws Error when the parameters schema cannot describe itself as JSON
|
|
47
|
+
* Schema.
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* const weather = defineTool({
|
|
51
|
+
* name: "get_weather",
|
|
52
|
+
* description: "Get the weather for a city.",
|
|
53
|
+
* parameters: z.object({ city: z.string() }),
|
|
54
|
+
* execute: async ({ city }) => ({ city, temperature: 21 }),
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
function defineTool(config) {
|
|
59
|
+
const tool = {
|
|
60
|
+
__toolSide: "server",
|
|
61
|
+
name: config.name,
|
|
62
|
+
description: config.description,
|
|
63
|
+
inputSchema: schemaToJsonSchema(config.parameters),
|
|
64
|
+
metadata: { copilotkit: {
|
|
65
|
+
interrupt: config.interrupt,
|
|
66
|
+
interruptReason: config.interruptReason,
|
|
67
|
+
interruptMessage: config.interruptMessage
|
|
68
|
+
} }
|
|
69
|
+
};
|
|
70
|
+
const { execute, parameters } = config;
|
|
71
|
+
if (!execute) return tool;
|
|
72
|
+
const executeWithParsedArgs = async (args) => {
|
|
73
|
+
const parsed = await parameters["~standard"].validate(args);
|
|
74
|
+
if (!("value" in parsed) || parsed.issues) {
|
|
75
|
+
const details = (parsed.issues ?? []).map((issue) => issue.message).join("; ");
|
|
76
|
+
throw new Error(`Invalid arguments for tool ${config.name}: ${details}`);
|
|
77
|
+
}
|
|
78
|
+
const value = parsed.value;
|
|
79
|
+
try {
|
|
80
|
+
return await execute(value);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
throw new Error(formatToolError(error), { cause: error });
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
tool.execute = executeWithParsedArgs;
|
|
86
|
+
return tool;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Type guard: returns true if this is a factory-mode config.
|
|
90
|
+
*/
|
|
91
|
+
function isFactoryConfig(config) {
|
|
92
|
+
return "factory" in config;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A `forwardedProps.toolChoice` value as a TanStack AI tool choice, or
|
|
96
|
+
* `undefined` when it is not one. `{ type: "tool", toolName }` is accepted
|
|
97
|
+
* as well as `{ type: "tool", name }`.
|
|
98
|
+
*/
|
|
99
|
+
function toToolChoice(value) {
|
|
100
|
+
if (value === "auto" || value === "required" || value === "none") return value;
|
|
101
|
+
if (!isRecord(value) || value.type !== "tool") return void 0;
|
|
102
|
+
const name = typeof value.name === "string" ? value.name : value.toolName;
|
|
103
|
+
return typeof name === "string" ? {
|
|
104
|
+
type: "tool",
|
|
105
|
+
name
|
|
106
|
+
} : void 0;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Splits `input.resume` for a classic run.
|
|
110
|
+
*
|
|
111
|
+
* - `approvals`: the entries that answer a call of a `needsApproval` config
|
|
112
|
+
* tool, under the interrupt id `chat()` gave that call
|
|
113
|
+
* (`approval_<toolCallId>`). `chat()` then runs the tool on approve, and
|
|
114
|
+
* skips it on reject or cancel.
|
|
115
|
+
* - `toolResults`: the other entries. They go back to the model as tool
|
|
116
|
+
* results.
|
|
117
|
+
* - `messages`: the history without a tool message the client added for an
|
|
118
|
+
* approval in this resume. `chat()` would read that message as the tool's
|
|
119
|
+
* result and not run the tool.
|
|
120
|
+
*/
|
|
121
|
+
function splitApprovalResume(input, tools) {
|
|
122
|
+
const approvalTools = new Set(tools.filter((tool) => tool.needsApproval).map((tool) => tool.name));
|
|
123
|
+
const approvalCallIds = new Set(input.messages.flatMap((message) => message.role === "assistant" ? (message.toolCalls ?? []).filter((call) => approvalTools.has(call.function.name)).map((call) => call.id) : []));
|
|
124
|
+
const approvals = [];
|
|
125
|
+
const toolResults = [];
|
|
126
|
+
for (const entry of input.resume ?? []) if (approvalCallIds.has(entry.interruptId)) approvals.push({
|
|
127
|
+
...entry,
|
|
128
|
+
interruptId: `approval_${entry.interruptId}`
|
|
129
|
+
});
|
|
130
|
+
else toolResults.push(entry);
|
|
131
|
+
const resumedCallIds = new Set(approvals.map((entry) => entry.interruptId.slice(9)));
|
|
132
|
+
return {
|
|
133
|
+
approvals,
|
|
134
|
+
toolResults,
|
|
135
|
+
messages: input.messages.filter((message) => !(message.role === "tool" && resumedCallIds.has(message.toolCallId)))
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The `chat()` options of a classic config that the agent passes to `chat()`
|
|
140
|
+
* as they are. It leaves out the CopilotKit settings, and the options that
|
|
141
|
+
* the agent merges or replaces on each run (`systemPrompts`, `tools`,
|
|
142
|
+
* `toolChoice`, `modelOptions`, `reasoning`, `agentLoopStrategy`,
|
|
143
|
+
* `repairToolInput`). Keys the config does not set stay out.
|
|
144
|
+
*/
|
|
145
|
+
function passThroughChatOptions(config) {
|
|
146
|
+
const { promptCache, retry, wrapFetch, middleware, context, toolExecution, lazyToolsConfig, metadata, debug } = config;
|
|
147
|
+
return {
|
|
148
|
+
promptCache,
|
|
149
|
+
retry,
|
|
150
|
+
wrapFetch,
|
|
151
|
+
middleware,
|
|
152
|
+
context,
|
|
153
|
+
toolExecution,
|
|
154
|
+
lazyToolsConfig,
|
|
155
|
+
metadata,
|
|
156
|
+
debug
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* An AG-UI agent that runs a model with TanStack AI `chat()` (classic config),
|
|
161
|
+
* or runs your own LLM call (factory config).
|
|
162
|
+
*
|
|
163
|
+
* @typeParam TAdapter - The adapter type of a classic config, inferred from
|
|
164
|
+
* `model`. It types the `chat()` options of the config.
|
|
165
|
+
* @typeParam TContext - The type of the classic config's `context`, inferred
|
|
166
|
+
* from it.
|
|
167
|
+
*
|
|
168
|
+
* ```ts
|
|
169
|
+
* const agent = new BuiltInAgent({
|
|
170
|
+
* model: openaiText("gpt-5.2"),
|
|
171
|
+
* prompt: "You are a helpful assistant.",
|
|
172
|
+
* reasoning: "low",
|
|
173
|
+
* });
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
var BuiltInAgent = class BuiltInAgent extends AbstractAgent {
|
|
177
|
+
/**
|
|
178
|
+
* @throws Error when a classic config's `model` is a model string or an AI
|
|
179
|
+
* SDK model object. Pass a TanStack AI text adapter, or run AI SDK models
|
|
180
|
+
* with a `type: "aisdk"` factory.
|
|
181
|
+
*/
|
|
182
|
+
constructor(config) {
|
|
183
|
+
super();
|
|
184
|
+
this.config = config;
|
|
185
|
+
this.warnedUnresolvedModel = false;
|
|
186
|
+
this.modelHostClass = "unknown";
|
|
187
|
+
if (!isFactoryConfig(config)) assertTextAdapter(config.model);
|
|
188
|
+
this.skillRegistry = config.learnedSkills === void 0 ? void 0 : new SkillRegistry(config.learnedSkills);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Check if a property can be overridden by forwardedProps
|
|
192
|
+
*/
|
|
193
|
+
canOverride(property) {
|
|
194
|
+
if (isFactoryConfig(this.config)) return false;
|
|
195
|
+
return this.config?.overridableProperties?.includes(property) ?? false;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The `forwardedProps` values this run may use, one per property in
|
|
199
|
+
* `overridableProperties`. A value of the wrong shape is ignored.
|
|
200
|
+
*/
|
|
201
|
+
forwardedOverrides(forwardedProps) {
|
|
202
|
+
const props = isRecord(forwardedProps) ? forwardedProps : {};
|
|
203
|
+
return {
|
|
204
|
+
model: typeof props.model === "string" && this.canOverride("model") ? props.model : void 0,
|
|
205
|
+
toolChoice: this.canOverride("toolChoice") ? toToolChoice(props.toolChoice) : void 0,
|
|
206
|
+
prompt: typeof props.prompt === "string" && this.canOverride("prompt") ? props.prompt : void 0,
|
|
207
|
+
modelOptions: isRecord(props.modelOptions) && this.canOverride("modelOptions") ? props.modelOptions : void 0
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* The model for this run: the forwarded model name through `resolveModel`,
|
|
212
|
+
* else the configured `model`. Returns the adapter with the `modelOptions`
|
|
213
|
+
* and `reasoning` to use with it. An override that does not resolve logs
|
|
214
|
+
* one warning per agent.
|
|
215
|
+
*
|
|
216
|
+
* @throws Error when `resolveModel` returns a model string or an AI SDK
|
|
217
|
+
* model object.
|
|
218
|
+
*/
|
|
219
|
+
modelFor(config, modelName) {
|
|
220
|
+
const configured = {
|
|
221
|
+
adapter: config.model,
|
|
222
|
+
modelOptions: config.modelOptions,
|
|
223
|
+
reasoning: config.reasoning
|
|
224
|
+
};
|
|
225
|
+
if (modelName === void 0) return configured;
|
|
226
|
+
const resolved = config.resolveModel?.(modelName);
|
|
227
|
+
if (resolved) {
|
|
228
|
+
const source = `resolveModel(${JSON.stringify(modelName)})`;
|
|
229
|
+
assertTextAdapter(resolved, source);
|
|
230
|
+
if (!("adapter" in resolved)) return {
|
|
231
|
+
...configured,
|
|
232
|
+
adapter: resolved
|
|
233
|
+
};
|
|
234
|
+
assertTextAdapter(resolved.adapter, source);
|
|
235
|
+
return resolved;
|
|
236
|
+
}
|
|
237
|
+
if (!this.warnedUnresolvedModel) {
|
|
238
|
+
this.warnedUnresolvedModel = true;
|
|
239
|
+
const reason = config.resolveModel ? "resolveModel returned undefined for it" : "the agent has no resolveModel";
|
|
240
|
+
console.warn(`[CopilotKit] Ignoring the forwarded model ${JSON.stringify(modelName)}: ${reason}. The run uses the configured model adapter.`);
|
|
241
|
+
}
|
|
242
|
+
return configured;
|
|
243
|
+
}
|
|
244
|
+
async getCapabilities() {
|
|
245
|
+
const inferred = {
|
|
246
|
+
tools: {
|
|
247
|
+
supported: true,
|
|
248
|
+
clientProvided: true
|
|
249
|
+
},
|
|
250
|
+
transport: { streaming: true },
|
|
251
|
+
humanInTheLoop: { interrupts: true }
|
|
252
|
+
};
|
|
253
|
+
const capabilities = isFactoryConfig(this.config) ? void 0 : this.config.capabilities;
|
|
254
|
+
if (!capabilities) return inferred;
|
|
255
|
+
return {
|
|
256
|
+
...inferred,
|
|
257
|
+
...capabilities
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
run(input) {
|
|
261
|
+
if (isFactoryConfig(this.config)) return this.runFactory(input, this.config);
|
|
262
|
+
const config = this.config;
|
|
263
|
+
if (this.abortController) throw new Error("Agent is already running. Call abortRun() first or create a new instance.");
|
|
264
|
+
this.abortController = new AbortController();
|
|
265
|
+
const abortController = this.abortController;
|
|
266
|
+
const signal = abortController.signal;
|
|
267
|
+
return new Observable((subscriber) => {
|
|
268
|
+
const startEvent = {
|
|
269
|
+
type: EventType.RUN_STARTED,
|
|
270
|
+
threadId: input.threadId,
|
|
271
|
+
runId: input.runId,
|
|
272
|
+
protocolVersion: PROTOCOL_VERSION
|
|
273
|
+
};
|
|
274
|
+
subscriber.next(startEvent);
|
|
275
|
+
(async () => {
|
|
276
|
+
const runFinishedDetails = {};
|
|
277
|
+
const pendingInterrupts = [];
|
|
278
|
+
try {
|
|
279
|
+
const overrides = this.forwardedOverrides(input.forwardedProps);
|
|
280
|
+
const model = this.modelFor(config, overrides.model);
|
|
281
|
+
const prompt = overrides.prompt ?? config.prompt;
|
|
282
|
+
const configSystemPrompts = config.systemPrompts ?? [];
|
|
283
|
+
const promptJoinsContext = configSystemPrompts.length === 0;
|
|
284
|
+
assertFrontendToolSchemas(input.tools ?? []);
|
|
285
|
+
const resume = splitApprovalResume(input, config.tools ?? []);
|
|
286
|
+
const converted = convertInputToTanStackAI({
|
|
287
|
+
...input,
|
|
288
|
+
messages: resume.messages
|
|
289
|
+
}, {
|
|
290
|
+
forwardSystemMessages: config.forwardSystemMessages ?? false,
|
|
291
|
+
forwardDeveloperMessages: config.forwardDeveloperMessages ?? false,
|
|
292
|
+
prompt: promptJoinsContext ? prompt : void 0,
|
|
293
|
+
resume: resume.toolResults,
|
|
294
|
+
keepToolResultMedia: true,
|
|
295
|
+
format: "classic"
|
|
296
|
+
});
|
|
297
|
+
const learnedSkills = await prepareLearnedSkills(this.skillRegistry, signal);
|
|
298
|
+
signal.throwIfAborted();
|
|
299
|
+
const promptOnItsOwn = !promptJoinsContext && prompt ? [prompt] : [];
|
|
300
|
+
const systemPrompts = [
|
|
301
|
+
...learnedSkills.catalog ? [learnedSkills.catalog] : [],
|
|
302
|
+
...promptOnItsOwn,
|
|
303
|
+
...configSystemPrompts,
|
|
304
|
+
...converted.systemPrompts
|
|
305
|
+
];
|
|
306
|
+
const ownTools = [
|
|
307
|
+
...converted.tools,
|
|
308
|
+
...config.tools ?? [],
|
|
309
|
+
...STATE_TOOLS
|
|
310
|
+
];
|
|
311
|
+
const appTools = [...new Map(ownTools.map((tool) => [tool.name, tool])).values()];
|
|
312
|
+
if (this.skillRegistry) {
|
|
313
|
+
assertNoSkillToolConflicts(appTools);
|
|
314
|
+
appTools.push(...learnedSkills.tools);
|
|
315
|
+
}
|
|
316
|
+
const { chat, maxIterations } = await import("@tanstack/ai");
|
|
317
|
+
const events = convertTanStackStream(withClassicToolRules(chat({
|
|
318
|
+
...passThroughChatOptions(config),
|
|
319
|
+
adapter: model.adapter,
|
|
320
|
+
messages: converted.messages,
|
|
321
|
+
systemPrompts,
|
|
322
|
+
tools: appTools,
|
|
323
|
+
...config.mcp ? { mcp: {
|
|
324
|
+
connection: "keep-alive",
|
|
325
|
+
...config.mcp
|
|
326
|
+
} } : {},
|
|
327
|
+
toolChoice: overrides.toolChoice ?? config.toolChoice,
|
|
328
|
+
modelOptions: overrides.modelOptions ?? model.modelOptions,
|
|
329
|
+
reasoning: model.reasoning,
|
|
330
|
+
agentLoopStrategy: config.agentLoopStrategy ?? maxIterations(config.maxSteps || (learnedSkills.catalog ? 10 : 1)),
|
|
331
|
+
repairToolInput: config.repairToolInput ?? false,
|
|
332
|
+
abortController,
|
|
333
|
+
threadId: input.threadId,
|
|
334
|
+
...resume.approvals.length > 0 ? {
|
|
335
|
+
resume: resume.approvals,
|
|
336
|
+
parentRunId: input.parentRunId ?? input.runId
|
|
337
|
+
} : {},
|
|
338
|
+
stream: true
|
|
339
|
+
}), config.tools ?? [], pendingInterrupts), signal, pendingInterrupts, input.state, runFinishedDetails);
|
|
340
|
+
for await (const event of events) subscriber.next(event);
|
|
341
|
+
if (signal.aborted) {
|
|
342
|
+
const cancelledEvent = {
|
|
343
|
+
type: EventType.RUN_FINISHED,
|
|
344
|
+
threadId: input.threadId,
|
|
345
|
+
runId: input.runId,
|
|
346
|
+
...input.protocolVersion !== void 0 ? { outcome: { type: "cancelled" } } : {}
|
|
347
|
+
};
|
|
348
|
+
subscriber.next(cancelledEvent);
|
|
349
|
+
} else {
|
|
350
|
+
const finishedEvent = {
|
|
351
|
+
type: EventType.RUN_FINISHED,
|
|
352
|
+
threadId: input.threadId,
|
|
353
|
+
runId: input.runId,
|
|
354
|
+
...runFinishedDetails,
|
|
355
|
+
...pendingInterrupts.length > 0 ? { outcome: {
|
|
356
|
+
type: "interrupt",
|
|
357
|
+
interrupts: pendingInterrupts
|
|
358
|
+
} } : {}
|
|
359
|
+
};
|
|
360
|
+
subscriber.next(finishedEvent);
|
|
361
|
+
}
|
|
362
|
+
subscriber.complete();
|
|
363
|
+
} catch (error) {
|
|
364
|
+
if (signal.aborted) subscriber.complete();
|
|
365
|
+
else {
|
|
366
|
+
const runErrorEvent = {
|
|
367
|
+
type: EventType.RUN_ERROR,
|
|
368
|
+
message: error instanceof Error ? error.message : String(error),
|
|
369
|
+
threadId: input.threadId,
|
|
370
|
+
runId: input.runId
|
|
371
|
+
};
|
|
372
|
+
subscriber.next(runErrorEvent);
|
|
373
|
+
subscriber.error(error);
|
|
374
|
+
}
|
|
375
|
+
} finally {
|
|
376
|
+
if (this.abortController === abortController) this.abortController = void 0;
|
|
377
|
+
}
|
|
378
|
+
})();
|
|
379
|
+
return () => {
|
|
380
|
+
abortController.abort();
|
|
381
|
+
if (this.abortController === abortController) this.abortController = void 0;
|
|
382
|
+
};
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
runFactory(input, config) {
|
|
386
|
+
if (this.abortController) throw new Error("Agent is already running. Call abortRun() first or create a new instance.");
|
|
387
|
+
this.abortController = new AbortController();
|
|
388
|
+
const controller = this.abortController;
|
|
389
|
+
return new Observable((subscriber) => {
|
|
390
|
+
const startEvent = {
|
|
391
|
+
type: EventType.RUN_STARTED,
|
|
392
|
+
threadId: input.threadId,
|
|
393
|
+
runId: input.runId,
|
|
394
|
+
protocolVersion: PROTOCOL_VERSION
|
|
395
|
+
};
|
|
396
|
+
subscriber.next(startEvent);
|
|
397
|
+
const ctx = {
|
|
398
|
+
input,
|
|
399
|
+
abortController: controller,
|
|
400
|
+
abortSignal: controller.signal,
|
|
401
|
+
interrupt: async (interrupts) => {
|
|
402
|
+
const resume = input.resume ?? [];
|
|
403
|
+
const ids = new Set(interrupts.map((i) => i.id));
|
|
404
|
+
const matching = resume.filter((r) => ids.has(r.interruptId));
|
|
405
|
+
if (interrupts.length > 0 && matching.length === interrupts.length) return matching;
|
|
406
|
+
throw new InterruptSignal(interrupts);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
(async () => {
|
|
410
|
+
const runFinishedDetails = {};
|
|
411
|
+
try {
|
|
412
|
+
const toolCallIds = new Set(input.messages.flatMap((message) => message.role === "assistant" ? (message.toolCalls ?? []).map((call) => call.id) : []));
|
|
413
|
+
const answeredToolMessages = input.messages.filter((message) => message.role === "tool");
|
|
414
|
+
const answeredToolCallIds = new Set(answeredToolMessages.map((message) => message.toolCallId));
|
|
415
|
+
const nativeResume = config.type === "custom" ? [] : input.resume ?? [];
|
|
416
|
+
const resumeToolMessages = [];
|
|
417
|
+
const decisionsByCall = /* @__PURE__ */ new Map();
|
|
418
|
+
for (const entry of nativeResume) {
|
|
419
|
+
if (!toolCallIds.has(entry.interruptId)) continue;
|
|
420
|
+
const content = JSON.stringify(entry.status === "cancelled" ? { status: "cancelled" } : entry.payload ?? { status: "resolved" });
|
|
421
|
+
if (decisionsByCall.has(entry.interruptId)) {
|
|
422
|
+
if (decisionsByCall.get(entry.interruptId) !== content) throw new Error(`Conflicting decisions for resumed tool call ${entry.interruptId}`);
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
decisionsByCall.set(entry.interruptId, content);
|
|
426
|
+
if (answeredToolCallIds.has(entry.interruptId)) continue;
|
|
427
|
+
resumeToolMessages.push({
|
|
428
|
+
id: randomUUID(),
|
|
429
|
+
role: "tool",
|
|
430
|
+
toolCallId: entry.interruptId,
|
|
431
|
+
content
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
const resumedIds = new Set(nativeResume.map((entry) => entry.interruptId));
|
|
435
|
+
const resumedResults = new Map([...answeredToolMessages, ...resumeToolMessages].filter((message) => resumedIds.has(message.toolCallId)).map((message) => [message.toolCallId, message.content]));
|
|
436
|
+
for (const message of resumeToolMessages) {
|
|
437
|
+
const event = {
|
|
438
|
+
type: EventType.TOOL_CALL_RESULT,
|
|
439
|
+
messageId: message.id,
|
|
440
|
+
toolCallId: message.toolCallId,
|
|
441
|
+
role: "tool",
|
|
442
|
+
content: message.content
|
|
443
|
+
};
|
|
444
|
+
subscriber.next(event);
|
|
445
|
+
}
|
|
446
|
+
const factoryInput = resumeToolMessages.length > 0 && config.type !== "custom" ? {
|
|
447
|
+
...input,
|
|
448
|
+
messages: [...input.messages, ...resumeToolMessages]
|
|
449
|
+
} : input;
|
|
450
|
+
const learnedSkills = await prepareLearnedSkills(this.skillRegistry, controller.signal);
|
|
451
|
+
controller.signal.throwIfAborted();
|
|
452
|
+
const factoryCtx = {
|
|
453
|
+
...ctx,
|
|
454
|
+
input: factoryInput,
|
|
455
|
+
learnedSkills
|
|
456
|
+
};
|
|
457
|
+
let events;
|
|
458
|
+
let customRunFinishedEvent;
|
|
459
|
+
const pendingInterrupts = [];
|
|
460
|
+
switch (config.type) {
|
|
461
|
+
case "aisdk":
|
|
462
|
+
events = convertAISDKStream((await config.factory(factoryCtx)).fullStream, controller.signal, pendingInterrupts, input.state, runFinishedDetails);
|
|
463
|
+
break;
|
|
464
|
+
case "tanstack":
|
|
465
|
+
events = convertTanStackStream(await config.factory(factoryCtx), controller.signal, pendingInterrupts, input.state, runFinishedDetails);
|
|
466
|
+
break;
|
|
467
|
+
case "custom":
|
|
468
|
+
events = await config.factory(factoryCtx);
|
|
469
|
+
break;
|
|
470
|
+
default: {
|
|
471
|
+
const _exhaustive = config;
|
|
472
|
+
throw new Error(`Unknown agent config type: ${_exhaustive.type}`);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
for await (const event of events) {
|
|
476
|
+
if (event.type === EventType.TOOL_CALL_RESULT && "toolCallId" in event && typeof event.toolCallId === "string" && "content" in event && resumedResults.has(event.toolCallId)) {
|
|
477
|
+
if (resumedResults.get(event.toolCallId) !== event.content) throw new Error(`Conflicting result for resumed tool call ${event.toolCallId}`);
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
if (config.type === "custom" && event.type === EventType.RUN_FINISHED) {
|
|
481
|
+
customRunFinishedEvent = event;
|
|
482
|
+
collectStandardRunFinishedDetails(event, runFinishedDetails);
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
subscriber.next(event);
|
|
486
|
+
}
|
|
487
|
+
if (pendingInterrupts.length > 0 && !controller.signal.aborted) throw new InterruptSignal(pendingInterrupts);
|
|
488
|
+
if (!controller.signal.aborted) {
|
|
489
|
+
const finishedEvent = {
|
|
490
|
+
...customRunFinishedEvent,
|
|
491
|
+
type: EventType.RUN_FINISHED,
|
|
492
|
+
threadId: input.threadId,
|
|
493
|
+
runId: input.runId,
|
|
494
|
+
...runFinishedDetails
|
|
495
|
+
};
|
|
496
|
+
subscriber.next(finishedEvent);
|
|
497
|
+
}
|
|
498
|
+
subscriber.complete();
|
|
499
|
+
} catch (error) {
|
|
500
|
+
if (error instanceof InterruptSignal) {
|
|
501
|
+
const finishedEvent = {
|
|
502
|
+
type: EventType.RUN_FINISHED,
|
|
503
|
+
threadId: input.threadId,
|
|
504
|
+
runId: input.runId,
|
|
505
|
+
...runFinishedDetails,
|
|
506
|
+
outcome: {
|
|
507
|
+
type: "interrupt",
|
|
508
|
+
interrupts: error.interrupts
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
subscriber.next(finishedEvent);
|
|
512
|
+
subscriber.complete();
|
|
513
|
+
} else if (controller.signal.aborted) subscriber.complete();
|
|
514
|
+
else {
|
|
515
|
+
const runErrorEvent = {
|
|
516
|
+
type: EventType.RUN_ERROR,
|
|
517
|
+
message: error instanceof Error ? error.message : String(error),
|
|
518
|
+
threadId: input.threadId,
|
|
519
|
+
runId: input.runId
|
|
520
|
+
};
|
|
521
|
+
subscriber.next(runErrorEvent);
|
|
522
|
+
subscriber.error(error);
|
|
523
|
+
}
|
|
524
|
+
} finally {
|
|
525
|
+
if (this.abortController === controller) this.abortController = void 0;
|
|
526
|
+
}
|
|
527
|
+
})();
|
|
528
|
+
return () => {
|
|
529
|
+
controller.abort();
|
|
530
|
+
if (this.abortController === controller) this.abortController = void 0;
|
|
531
|
+
};
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
clone() {
|
|
535
|
+
const cloned = new BuiltInAgent({
|
|
536
|
+
...this.config,
|
|
537
|
+
learnedSkills: void 0
|
|
538
|
+
});
|
|
539
|
+
cloned.config = this.config;
|
|
540
|
+
cloned.skillRegistry = this.skillRegistry;
|
|
541
|
+
cloned.middlewares = [...this.middlewares];
|
|
542
|
+
return cloned;
|
|
543
|
+
}
|
|
544
|
+
abortRun() {
|
|
545
|
+
this.abortController?.abort();
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
//#endregion
|
|
550
|
+
export { BuiltInAgent, InterruptSignal, convertAISDKStream, convertInputToTanStackAI, convertTanStackStream, defineTool, isAISDKLanguageModel };
|
|
551
|
+
//# sourceMappingURL=agent.mjs.map
|