@copilotkit/runtime 2.0.0-rc.5 → 2.0.0-rc.51
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 +27 -27
- package/dist/index.d.cts +15 -15
- package/dist/index.d.mts +15 -15
- package/dist/index.mjs +9 -8
- package/dist/internal/learned-skills.d.cts +1 -1
- package/dist/internal/learned-skills.d.mts +1 -1
- package/dist/node.cjs +3 -2
- 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 +24 -13
- package/dist/runtime/core/fetch-handler.cjs.map +1 -1
- package/dist/runtime/core/fetch-handler.d.cts +35 -14
- package/dist/runtime/core/fetch-handler.d.cts.map +1 -1
- package/dist/runtime/core/fetch-handler.d.mts +35 -14
- package/dist/runtime/core/fetch-handler.d.mts.map +1 -1
- package/dist/runtime/core/fetch-handler.mjs +16 -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 +29 -46
- package/dist/runtime/core/runtime.cjs.map +1 -1
- package/dist/runtime/core/runtime.d.cts +157 -91
- package/dist/runtime/core/runtime.d.cts.map +1 -1
- package/dist/runtime/core/runtime.d.mts +157 -91
- package/dist/runtime/core/runtime.d.mts.map +1 -1
- package/dist/runtime/core/runtime.mjs +27 -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 +11 -7
- package/dist/runtime/endpoints/node-fetch-handler.cjs.map +1 -1
- package/dist/runtime/endpoints/node-fetch-handler.d.cts +9 -5
- package/dist/runtime/endpoints/node-fetch-handler.d.cts.map +1 -1
- package/dist/runtime/endpoints/node-fetch-handler.d.mts +9 -5
- package/dist/runtime/endpoints/node-fetch-handler.d.mts.map +1 -1
- package/dist/runtime/endpoints/node-fetch-handler.mjs +10 -5
- package/dist/runtime/endpoints/node-fetch-handler.mjs.map +1 -1
- package/dist/runtime/endpoints/node.cjs +14 -4
- package/dist/runtime/endpoints/node.cjs.map +1 -1
- package/dist/runtime/endpoints/node.d.cts +39 -16
- package/dist/runtime/endpoints/node.d.cts.map +1 -1
- package/dist/runtime/endpoints/node.d.mts +39 -16
- package/dist/runtime/endpoints/node.d.mts.map +1 -1
- package/dist/runtime/endpoints/node.mjs +16 -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.cjs +29 -0
- package/dist/runtime/index.cjs.map +1 -0
- package/dist/runtime/index.d.cts +61 -15
- package/dist/runtime/index.d.cts.map +1 -1
- package/dist/runtime/index.d.mts +61 -15
- package/dist/runtime/index.d.mts.map +1 -1
- package/dist/runtime/index.mjs +27 -0
- package/dist/runtime/index.mjs.map +1 -0
- 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/package.json +54 -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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a2ui-v09-operations.mjs","names":[],"sources":["../../../src/runtime/generative-ui/a2ui-v09-operations.ts"],"sourcesContent":["import { EventType } from \"@ag-ui/client\";\nimport type {\n ActivityDeltaEvent,\n ActivitySnapshotEvent,\n BaseEvent,\n} from \"@ag-ui/client\";\nimport {\n A2UI_VERSION,\n GENERATIVE_UI_ACTIVITY_TYPE,\n GENERATIVE_UI_CHAT_TARGET,\n GENERATIVE_UI_MAX_REJECTION_LENGTH,\n cloneValue,\n generativeUISurfaceMessageId,\n} from \"@copilotkit/shared\";\nimport type {\n A2UIComponentNode,\n A2UIOperation,\n GenerativeUIRejectedOperation,\n GenerativeUISurfaceContent,\n} from \"@copilotkit/shared\";\nimport { STANDARD_CATALOG_ID } from \"@copilotkit/shared/generative-ui\";\nimport { isRecord } from \"../../agent/converters/usage\";\n\n/**\n * The activity type and content key of v0.9 surfaces, as\n * `@ag-ui/a2ui-middleware`, `@ag-ui/a2a` and the Python helpers emit them.\n */\nconst A2UI_SURFACE_ACTIVITY_TYPE = \"a2ui-surface\";\nconst A2UI_OPERATIONS_KEY = \"a2ui_operations\";\n\n/** The `version` values of A2UI v0.9 messages. */\nconst V09_VERSIONS: ReadonlySet<string> = new Set([\"v0.9\", \"v0.9.1\"]);\nconst V09_KINDS = [\n \"createSurface\",\n \"updateComponents\",\n \"updateDataModel\",\n \"deleteSurface\",\n] as const;\ntype V09Kind = (typeof V09_KINDS)[number];\n\n/**\n * The ids of the v0.9 basic catalog: the one agents send, and the `$id` of\n * the published catalog document. Both become the standard catalog, which has\n * the same 18 components.\n */\nconst V09_BASIC_CATALOG_IDS: ReadonlySet<string> = new Set([\n \"https://a2ui.org/specification/v0_9/basic_catalog.json\",\n \"https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json\",\n]);\n\n/**\n * The ids of the A2UI 1.0 basic catalog, which native 1.0 agents (for\n * example ADK) send. It has the 18 components of the v0.9 basic catalog\n * with 1.0 bindings, so it becomes the standard catalog too.\n */\nconst V10_BASIC_CATALOG_IDS: ReadonlySet<string> = new Set([\n \"https://a2ui.org/specification/v1_0/catalogs/basic/catalog.json\",\n]);\n\n/** The A2UI version that an `a2ui-surface` operation was written in. */\ntype SourceVersion = \"0.9\" | \"1.0\";\n\n/** v0.9 `Text` heading variants as 1.0 `Title` sizes, largest first. */\nconst HEADING_SIZES: Readonly<Record<string, string>> = {\n h1: \"2xl\",\n h2: \"xl\",\n h3: \"lg\",\n h4: \"md\",\n h5: \"sm\",\n};\n\n/** The one v0.9 operation key of `op`, when it has exactly one. */\nfunction v09Kind(op: Record<string, unknown>): V09Kind | undefined {\n const kinds = V09_KINDS.filter((kind) => kind in op);\n return kinds.length === 1 ? kinds[0] : undefined;\n}\n\n/**\n * True for an A2UI v0.9 operation: an object whose `version` is `\"v0.9\"` (or\n * `\"v0.9.1\"`). An object without `version` counts when it has exactly one\n * v0.9 operation key with an object payload. A 1.0 operation always carries\n * `version: \"1.0\"` (the client rejects one without it), and v0.8 uses other\n * keys (`beginRendering`, `surfaceUpdate`), so a versionless operation with\n * a v0.9 key can only be v0.9. Agents leave `version` out often enough that\n * requiring it would drop their surfaces.\n *\n * @example\n * ```ts\n * isA2UIV09Operation({ version: \"v0.9\", deleteSurface: { surfaceId: \"s\" } }); // true\n * isA2UIV09Operation({ deleteSurface: { surfaceId: \"s\" } }); // true\n * isA2UIV09Operation({ version: \"1.0\", deleteSurface: { surfaceId: \"s\" } }); // false\n * ```\n */\nexport function isA2UIV09Operation(value: unknown): boolean {\n if (!isRecord(value)) return false;\n if (value.version !== undefined) {\n return typeof value.version === \"string\" && V09_VERSIONS.has(value.version);\n }\n const kind = v09Kind(value);\n return kind !== undefined && isRecord(value[kind]);\n}\n\n// Checked with `ok === false`: runtime compiles non-strict, where a check of\n// `reason` does not narrow the union.\ntype Converted<T> = { ok: true; value: T } | { ok: false; reason: string };\n\nconst ok = <T>(value: T): { ok: true; value: T } => ({ ok: true, value });\nconst failed = (reason: string): { ok: false; reason: string } => ({\n ok: false,\n reason,\n});\n\n/**\n * A v0.9 dynamic value as 1.0: `{ path }` becomes `{ \"@path\" }` and\n * `{ call, args }` becomes `{ \"@call\", args }`, at any depth. Literals stay.\n */\nfunction convertValue(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(convertValue);\n if (!isRecord(value)) return value;\n const keys = Object.keys(value);\n if (keys.length === 1 && typeof value.path === \"string\") {\n return { \"@path\": value.path };\n }\n const isCall =\n typeof value.call === \"string\" &&\n keys.every(\n (key) => key === \"call\" || key === \"args\" || key === \"returnType\",\n );\n if (isCall) return convertCall(value);\n return Object.fromEntries(\n Object.entries(value).map(([key, item]) => [key, convertValue(item)]),\n );\n}\n\n/** A v0.9 function call `{ call, args, returnType }` as `{ \"@call\", args }`. */\nfunction convertCall(call: Record<string, unknown>) {\n return {\n \"@call\": call.call as string,\n ...(call.args === undefined ? {} : { args: convertValue(call.args) }),\n };\n}\n\n/** `{ event: {...} }` or `{ functionCall: {...} }`: the v0.9 Action. */\nfunction isV09Action(value: unknown): value is Record<string, unknown> {\n if (!isRecord(value)) return false;\n const keys = Object.keys(value);\n return (\n keys.length === 1 && (isRecord(value.event) || isRecord(value.functionCall))\n );\n}\n\n/**\n * A v0.9 action as a 1.0 event binding. The event keeps its name and\n * context (with converted values); a function call gets the `@call` form.\n */\nfunction convertAction(action: unknown): Converted<unknown> {\n if (!isV09Action(action)) {\n return failed('action must be { \"event\": ... } or { \"functionCall\": ... }');\n }\n if (isRecord(action.functionCall)) {\n const call = action.functionCall;\n if (typeof call.call !== \"string\" || !call.call) {\n return failed(\"action.functionCall.call must be a function name\");\n }\n return ok({ functionCall: convertCall(call) });\n }\n const event = action.event as Record<string, unknown>;\n if (typeof event.name !== \"string\" || !event.name) {\n return failed(\"action.event.name is required\");\n }\n return ok({\n event: {\n name: event.name,\n ...(event.context === undefined\n ? {}\n : { context: convertValue(event.context) }),\n },\n });\n}\n\n/**\n * The basic-catalog changes of one component. Every other prop keeps its\n * name; the 1.0 standard catalog uses the v0.9 names.\n *\n * - `Text` with a heading `variant` becomes `Title` (h1 \"2xl\" to h5 \"sm\"),\n * with `caption` it becomes `Caption`; `variant` goes. Title and Caption\n * have no `weight`, so it goes too.\n * - `Button.action` becomes `onClick`.\n * - `TextField.validationRegexp` becomes a `regex` check on its value.\n */\nfunction applyBasicCatalogChanges(node: Record<string, unknown>) {\n if (node.component === \"Text\" && \"variant\" in node) {\n const { variant, ...rest } = node;\n const size =\n typeof variant === \"string\" ? HEADING_SIZES[variant] : undefined;\n if (size !== undefined) {\n const { weight: _weight, ...title } = rest;\n return { ...title, component: \"Title\", size };\n }\n if (variant === \"caption\") {\n const { weight: _weight, ...caption } = rest;\n return { ...caption, component: \"Caption\" };\n }\n return rest;\n }\n if (node.component === \"Button\" && \"action\" in node) {\n const { action, ...rest } = node;\n return { ...rest, onClick: action };\n }\n if (node.component === \"TextField\" && \"validationRegexp\" in node) {\n const { validationRegexp, ...rest } = node;\n if (typeof validationRegexp !== \"string\" || rest.value === undefined) {\n return rest;\n }\n const check = {\n condition: {\n \"@call\": \"regex\",\n args: { value: rest.value, pattern: validationRegexp },\n },\n };\n const checks = Array.isArray(rest.checks) ? rest.checks : [];\n return { ...rest, checks: [...checks, check] };\n }\n return node;\n}\n\n/** One v0.9 component (flat format) as a 1.0 component node. */\nfunction convertComponent(node: unknown): Converted<A2UIComponentNode> {\n if (!isRecord(node) || typeof node.id !== \"string\" || !node.id) {\n return failed(\"a component needs a string id\");\n }\n if (typeof node.component !== \"string\" || !node.component) {\n return failed(\n `component \"${node.id}\": the component type must be a string (the v0.9 flat format)`,\n );\n }\n const converted: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(node)) {\n if (key === \"id\" || key === \"component\") {\n converted[key] = value;\n } else if (key === \"action\" || isV09Action(value)) {\n const action = convertAction(value);\n if (action.ok === false) {\n return failed(`component \"${node.id}\": ${action.reason}`);\n }\n converted[key] = action.value;\n } else {\n converted[key] = convertValue(value);\n }\n }\n return ok(applyBasicCatalogChanges(converted) as A2UIComponentNode);\n}\n\nfunction convertUpdateComponents(\n payload: Record<string, unknown>,\n surfaceId: string,\n): Converted<A2UIOperation> {\n const { components } = payload;\n if (!Array.isArray(components) || components.length === 0) {\n return failed(\"updateComponents.components must be a non-empty array\");\n }\n const nodes: A2UIComponentNode[] = [];\n for (const component of components) {\n const converted = convertComponent(component);\n if (converted.ok === false) return converted;\n nodes.push(converted.value);\n }\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n updateComponents: { surfaceId, components: nodes },\n });\n}\n\n/**\n * v0.9 removes the key at `path` when `value` is left out; 1.0 removes it\n * for `null`. At the root, removing means an empty data model.\n */\nfunction convertUpdateDataModel(\n payload: Record<string, unknown>,\n surfaceId: string,\n): Converted<A2UIOperation> {\n const { path, value } = payload;\n if (path !== undefined && typeof path !== \"string\") {\n return failed(\"updateDataModel.path must be a string\");\n }\n const relative = typeof path === \"string\" ? path : \"\";\n const pointer = relative.startsWith(\"/\") ? relative : `/${relative}`;\n const isRoot = pointer === \"/\";\n if (isRoot && value !== undefined && !isRecord(value)) {\n return failed(\n \"a root updateDataModel value must be a JSON object in A2UI 1.0\",\n );\n }\n const nextValue = value === undefined ? (isRoot ? {} : null) : value;\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n updateDataModel: { surfaceId, path: pointer, value: nextValue },\n });\n}\n\nfunction convertCreateSurface(\n payload: Record<string, unknown>,\n surfaceId: string,\n): A2UIOperation {\n const { catalogId } = payload;\n const sendDataModel = payload.sendDataModel ?? payload.attachDataModel;\n return {\n version: A2UI_VERSION,\n createSurface: {\n surfaceId,\n ...(typeof catalogId === \"string\" && catalogId\n ? {\n catalogId: V09_BASIC_CATALOG_IDS.has(catalogId)\n ? STANDARD_CATALOG_ID\n : catalogId,\n }\n : {}),\n ...(typeof sendDataModel === \"boolean\" ? { sendDataModel } : {}),\n },\n };\n}\n\n/** Basic catalog components as standard ones; anything else stays. */\nfunction standardComponents(components: unknown) {\n return Array.isArray(components)\n ? components.map((node) =>\n isRecord(node) ? applyBasicCatalogChanges(node) : node,\n )\n : components;\n}\n\n/**\n * A native A2UI 1.0 operation, for the standard catalog: the 1.0 basic\n * catalog id becomes the standard catalog id, and the basic catalog\n * components (inline in createSurface, or in updateComponents) get the\n * changes of {@link applyBasicCatalogChanges}. Bindings are already 1.0.\n * Everything else stays; the client validates the operation.\n */\nfunction upgradeV10Operation(op: Record<string, unknown>): A2UIOperation {\n const { createSurface: create, updateComponents: update } = op;\n if (isRecord(create)) {\n const { catalogId } = create;\n return {\n ...op,\n createSurface: {\n ...create,\n ...(typeof catalogId === \"string\" &&\n V10_BASIC_CATALOG_IDS.has(catalogId)\n ? { catalogId: STANDARD_CATALOG_ID }\n : {}),\n ...(create.components === undefined\n ? {}\n : { components: standardComponents(create.components) }),\n },\n } as A2UIOperation;\n }\n if (isRecord(update)) {\n return {\n ...op,\n updateComponents: {\n ...update,\n ...(update.components === undefined\n ? {}\n : { components: standardComponents(update.components) }),\n },\n } as A2UIOperation;\n }\n return op as A2UIOperation;\n}\n\n/** One operation as 1.0, or why it cannot be converted. */\nfunction upgradeOperation(op: unknown): Converted<A2UIOperation> {\n if (!isRecord(op)) return failed(\"operation must be a JSON object\");\n if (op.version === A2UI_VERSION) return ok(upgradeV10Operation(op));\n if (!isA2UIV09Operation(op)) {\n return failed(\n typeof op.version === \"string\"\n ? `unsupported A2UI version \"${op.version}\"; only v0.9 and 1.0 operations are supported`\n : `not an A2UI v0.9 operation: it needs exactly one of ${V09_KINDS.join(\", \")}`,\n );\n }\n const kind = v09Kind(op);\n if (!kind) {\n return failed(\n `operation must contain exactly one of ${V09_KINDS.join(\", \")}`,\n );\n }\n const payload = op[kind];\n if (\n !isRecord(payload) ||\n typeof payload.surfaceId !== \"string\" ||\n !payload.surfaceId\n ) {\n return failed(`${kind}.surfaceId is required`);\n }\n const { surfaceId } = payload;\n switch (kind) {\n case \"createSurface\":\n return ok(convertCreateSurface(payload, surfaceId));\n case \"updateComponents\":\n return convertUpdateComponents(payload, surfaceId);\n case \"updateDataModel\":\n return convertUpdateDataModel(payload, surfaceId);\n case \"deleteSurface\":\n return ok<A2UIOperation>({\n version: A2UI_VERSION,\n deleteSurface: { surfaceId },\n });\n }\n}\n\n/**\n * Converts A2UI v0.9 operations to A2UI 1.0, in order. Pure; never throws.\n *\n * - createSurface: the v0.9 basic catalog id becomes the standard catalog\n * id (`copilotkit/standard@1`); any other catalog id stays. `theme` has no\n * 1.0 field and goes; `sendDataModel` stays.\n * - updateComponents: `{ path }` becomes `{ \"@path\" }` and `{ call, args }`\n * becomes `{ \"@call\", args }` at any depth; an action becomes an\n * `{ event }` or `{ functionCall }` binding; child lists and templates\n * stay. See {@link applyBasicCatalogChanges} for the props that change.\n * - updateDataModel: a left-out `value` (remove) becomes `null`, or `{}` at\n * the root.\n * - deleteSurface: unchanged.\n *\n * An operation that is already 1.0 (native, for example from ADK) keeps its\n * form: only the 1.0 basic catalog id becomes the standard catalog id, and\n * its basic catalog components get the same changes as v0.9 ones. Any other\n * operation, and any v0.9 operation that cannot be converted, goes to\n * `dropped` with the reason.\n *\n * @example\n * ```ts\n * upgradeA2UIV09Operations([\n * { version: \"v0.9\", updateDataModel: { surfaceId: \"s\", path: \"/x\" } },\n * ]);\n * // { operations: [{ version: \"1.0\", updateDataModel: { surfaceId: \"s\", path: \"/x\", value: null } }], dropped: [] }\n * ```\n */\nexport function upgradeA2UIV09Operations(operations: unknown[]): {\n operations: A2UIOperation[];\n dropped: Array<{ operation: unknown; reason: string }>;\n} {\n const upgraded: A2UIOperation[] = [];\n const dropped: Array<{ operation: unknown; reason: string }> = [];\n for (const operation of Array.isArray(operations) ? operations : []) {\n let result: Converted<A2UIOperation>;\n try {\n result = upgradeOperation(operation);\n } catch (error) {\n // A getter or a Proxy trap of the operation threw while it was read.\n result = failed(\n `operation could not be read: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n if (result.ok === false) {\n dropped.push({ operation, reason: result.reason });\n } else {\n upgraded.push(result.value);\n }\n }\n return { operations: upgraded, dropped };\n}\n\n/** The nested `surfaceId` of a v0.9 or 1.0 surface operation. */\nfunction surfaceIdOf(op: unknown) {\n if (!isRecord(op)) return undefined;\n for (const kind of V09_KINDS) {\n const payload = op[kind];\n if (isRecord(payload) && typeof payload.surfaceId === \"string\") {\n return payload.surfaceId || undefined;\n }\n }\n return undefined;\n}\n\n/**\n * The error of a `failed` lifecycle snapshot: the agent's A2UI recovery\n * gave up (`a2ui_recovery_exhausted`). Undefined for any other content.\n */\nfunction failedLifecycleError(content: unknown): string | undefined {\n if (!isRecord(content) || content.status !== \"failed\") return undefined;\n const error =\n typeof content.error === \"string\" && content.error\n ? content.error\n : \"A2UI generation failed\";\n return error.slice(0, GENERATIVE_UI_MAX_REJECTION_LENGTH);\n}\n\n/** The operations of `a2ui-surface` content. Lifecycle content has none. */\nfunction readOperations(content: unknown): unknown[] {\n if (!isRecord(content)) return [];\n const operations = content[A2UI_OPERATIONS_KEY] ?? content.operations;\n return Array.isArray(operations) ? operations : [];\n}\n\ntype JsonPatchOperation = {\n op: \"add\" | \"remove\" | \"replace\" | \"move\" | \"copy\" | \"test\";\n path: string;\n from?: string;\n value?: unknown;\n};\n\nfunction pointerSegments(pointer: string) {\n if (pointer === \"\") return [];\n if (!pointer.startsWith(\"/\")) throw new Error(`invalid pointer \"${pointer}\"`);\n return pointer\n .slice(1)\n .split(\"/\")\n .map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"));\n}\n\nconst FORBIDDEN_SEGMENTS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/**\n * Applies RFC 6902 operations to `document` in place and returns the new\n * root. Throws on a path that does not resolve, like `fast-json-patch` in\n * the AG-UI client, so a bad delta leaves the stored content alone.\n */\nfunction applyJsonPatch(document: unknown, patch: unknown): unknown {\n if (!Array.isArray(patch)) throw new Error(\"patch must be an array\");\n let root = document;\n const parentOf = (pointer: string) => {\n const segments = pointerSegments(pointer);\n const key = segments.pop();\n let parent: unknown = root;\n for (const segment of segments) {\n if (FORBIDDEN_SEGMENTS.has(segment)) throw new Error(\"forbidden path\");\n parent = Array.isArray(parent)\n ? parent[Number(segment)]\n : isRecord(parent)\n ? parent[segment]\n : undefined;\n if (parent === undefined) throw new Error(`path \"${pointer}\" not found`);\n }\n if (key !== undefined && FORBIDDEN_SEGMENTS.has(key)) {\n throw new Error(\"forbidden path\");\n }\n return { parent, key };\n };\n const read = (pointer: string) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) return root;\n if (Array.isArray(parent)) return parent[Number(key)];\n return isRecord(parent) ? parent[key] : undefined;\n };\n const remove = (pointer: string) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) throw new Error(\"cannot remove the root\");\n if (Array.isArray(parent)) parent.splice(Number(key), 1);\n else if (isRecord(parent) && key in parent) delete parent[key];\n else throw new Error(`path \"${pointer}\" not found`);\n };\n const write = (pointer: string, value: unknown, insert: boolean) => {\n const { parent, key } = parentOf(pointer);\n if (key === undefined) {\n root = value;\n } else if (Array.isArray(parent)) {\n const index = key === \"-\" ? parent.length : Number(key);\n if (!Number.isInteger(index) || index < 0 || index > parent.length) {\n throw new Error(`index \"${key}\" is out of range`);\n }\n parent.splice(index, insert ? 0 : 1, value);\n } else if (isRecord(parent)) {\n parent[key] = value;\n } else {\n throw new Error(`path \"${pointer}\" not found`);\n }\n };\n for (const entry of patch as JsonPatchOperation[]) {\n if (!isRecord(entry) || typeof entry.path !== \"string\") {\n throw new Error(\"invalid patch operation\");\n }\n switch (entry.op) {\n case \"add\":\n write(entry.path, cloneValue(entry.value), true);\n break;\n case \"replace\":\n if (read(entry.path) === undefined) {\n throw new Error(`path \"${entry.path}\" not found`);\n }\n write(entry.path, cloneValue(entry.value), false);\n break;\n case \"remove\":\n remove(entry.path);\n break;\n case \"copy\":\n write(entry.path, cloneValue(read(entry.from ?? \"\")), true);\n break;\n case \"move\": {\n const value = read(entry.from ?? \"\");\n remove(entry.from ?? \"\");\n write(entry.path, value, true);\n break;\n }\n case \"test\":\n if (JSON.stringify(read(entry.path)) !== JSON.stringify(entry.value)) {\n throw new Error(`test failed at \"${entry.path}\"`);\n }\n break;\n default:\n throw new Error(`unknown patch op \"${String(entry.op)}\"`);\n }\n }\n return root;\n}\n\n/** One converted operation, with where it came from. */\ninterface SourceOperation {\n operation: A2UIOperation;\n /** Its index in the source message. */\n index: number;\n version: SourceVersion;\n}\n\n/** The converted part of one surface that one source message holds. */\ninterface SourcePart {\n operations: SourceOperation[];\n rejected: GenerativeUIRejectedOperation[];\n}\n\n/**\n * The operations of the next snapshot of a surface, so that the client\n * applies every change of the source.\n *\n * The client applies only the operations after the ones it applied, when the\n * operation at its last applied index did not change. A source that changes\n * an earlier operation but not that one (a progressive render that rewrites\n * its components, then sends the same data again) would lose the change. In\n * that case the changed operations of the source are appended to the sent\n * ones: v0.9 updates replace by id or path, so sending them again is safe,\n * and a second createSurface is left out. In every other case the source\n * operations go as they are: the client either extends its surface with them\n * or builds it again from them.\n *\n * @param lastSource - The source operations of the last snapshot (none\n * before the first one).\n * @param sent - The operations of the last snapshot.\n * @param source - The source operations now.\n * @returns The operations of the next snapshot.\n */\nfunction clientOperations(\n lastSource: A2UIOperation[],\n sent: A2UIOperation[],\n source: A2UIOperation[],\n): A2UIOperation[] {\n let same = 0;\n while (\n same < lastSource.length &&\n same < source.length &&\n JSON.stringify(lastSource[same]) === JSON.stringify(source[same])\n ) {\n same++;\n }\n const appended = source.slice(same);\n if (same === lastSource.length) return [...sent, ...appended];\n // The client builds the surface again when the list is shorter than the\n // one it applied, or when the operation at its last applied index changed.\n const last = sent.length - 1;\n if (\n source.length < sent.length ||\n JSON.stringify(source[last]) !== JSON.stringify(sent[last])\n ) {\n return source;\n }\n return [...sent, ...appended.filter((op) => !(\"createSurface\" in op))];\n}\n\ninterface SurfaceState {\n /** The part of each source message, in the order they first touched it. */\n parts: Map<string, SourcePart>;\n /** JSON of the last snapshot content. */\n lastSnapshot?: string;\n /** The converted operations of the source, at the last snapshot. */\n snapshotSource: A2UIOperation[];\n /** The operations of the last snapshot, as the client applied them. */\n snapshotOperations: A2UIOperation[];\n /** Operations sent as deltas, for a surface created in an earlier run. */\n sentOperations: A2UIOperation[];\n /** JSON of the last `rejected` sent as a delta. */\n sentRejected: string;\n}\n\n/**\n * Converts the `a2ui-surface` surfaces of one run (A2UI v0.9, or native\n * A2UI 1.0) to `generative-ui-surface` surfaces. Create one per run and pass\n * every event of the run through `transform`, in order.\n *\n * - An `a2ui-surface` `ACTIVITY_SNAPSHOT` or `ACTIVITY_DELTA` is kept per\n * messageId (a delta is applied to the stored content), and its\n * operations are converted with {@link upgradeA2UIV09Operations}.\n * - Each surface becomes one `generative-ui-surface` message,\n * `genui:<surfaceId>`, like a `render_ui` surface. A surface that is\n * created in this run is sent as an `ACTIVITY_SNAPSHOT` with the\n * cumulative 1.0 content: the operations of every source message for it,\n * in order, with only the first createSurface. The target is the chat,\n * the status is \"ready\", dropped operations are `rejected` (at their\n * index in the source message), and `a2uiSourceVersion` is \"0.9\" for a\n * surface written in v0.9.\n * - A surface written in native A2UI 1.0 (`version: \"1.0\"`, for example\n * from ADK) becomes the same `generative-ui-surface` message, without\n * `a2uiSourceVersion`: a click on it is a 1.0 action, so it reaches the\n * agent unchanged. One surface has one version, the version of its\n * first operation; an operation of the other version is rejected.\n * - A surface that this run updates but does not create (v0.9 sends no\n * second createSurface) was created in an earlier run, so its new\n * operations are appended to its message with an `ACTIVITY_DELTA`, as\n * the `render_ui` path updates an existing surface.\n * - A lifecycle snapshot (`status: \"building\"` and so on, no operations)\n * names no surface, so it is consumed. A `failed` one (the agent's\n * recovery gave up) becomes a surface with no operations, status\n * \"error\", and its error as the one rejected entry, so the chat shows\n * that the UI could not be made. Its surfaceId is the source messageId.\n * Every other event passes through.\n *\n * @example\n * ```ts\n * const upgrader = createA2UIV09ActivityUpgrader();\n * source.pipe(mergeMap((event) => upgrader.transform(event)));\n * ```\n */\nexport function createA2UIV09ActivityUpgrader(): {\n transform(event: BaseEvent): BaseEvent[];\n} {\n const sources = new Map<string, unknown>();\n const surfaces = new Map<string, SurfaceState>();\n /** The source messages whose `failed` snapshot was sent. */\n const failures = new Set<string>();\n\n /** The surface that shows a failed lifecycle snapshot, sent once. */\n const failureOf = (messageId: string, error: string): BaseEvent[] => {\n if (failures.has(messageId)) return [];\n failures.add(messageId);\n const content: GenerativeUISurfaceContent = {\n surfaceId: messageId,\n target: GENERATIVE_UI_CHAT_TARGET,\n catalogId: STANDARD_CATALOG_ID,\n operations: [],\n status: \"error\",\n rejected: [{ index: 0, reason: error }],\n a2uiSourceVersion: \"0.9\",\n };\n const event: ActivitySnapshotEvent = {\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: generativeUISurfaceMessageId(messageId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n content,\n replace: true,\n };\n return [event];\n };\n\n const snapshotOf = (\n surfaceId: string,\n state: SurfaceState,\n source: A2UIOperation[],\n rejected: GenerativeUIRejectedOperation[],\n version: SourceVersion,\n ): BaseEvent[] => {\n const operations = clientOperations(\n state.snapshotSource,\n state.snapshotOperations,\n source,\n );\n const create = operations.find((op) => \"createSurface\" in op);\n const catalogId =\n (create && \"createSurface\" in create && create.createSurface.catalogId) ||\n STANDARD_CATALOG_ID;\n const content: GenerativeUISurfaceContent = {\n surfaceId,\n target: GENERATIVE_UI_CHAT_TARGET,\n catalogId,\n operations,\n status: \"ready\",\n rejected,\n ...(version === \"0.9\" ? { a2uiSourceVersion: \"0.9\" as const } : {}),\n };\n const json = JSON.stringify(content);\n if (json === state.lastSnapshot) return [];\n state.lastSnapshot = json;\n state.snapshotSource = source;\n state.snapshotOperations = operations;\n const event: ActivitySnapshotEvent = {\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n content: cloneValue(content),\n replace: true,\n };\n return [event];\n };\n\n const deltaOf = (\n surfaceId: string,\n state: SurfaceState,\n operations: A2UIOperation[],\n rejected: GenerativeUIRejectedOperation[],\n ): BaseEvent[] => {\n const sent = state.sentOperations;\n let same = 0;\n while (\n same < sent.length &&\n same < operations.length &&\n JSON.stringify(sent[same]) === JSON.stringify(operations[same])\n ) {\n same++;\n }\n // Operations that changed after they were sent cannot be taken back.\n // v0.9 updates replace by id or path, so sending them again is safe.\n const patch: unknown[] = operations.slice(same).map((op) => ({\n op: \"add\",\n path: \"/operations/-\",\n value: cloneValue(op),\n }));\n const rejectedJson = JSON.stringify(rejected);\n if (rejectedJson !== state.sentRejected) {\n patch.push({ op: \"replace\", path: \"/rejected\", value: rejected });\n }\n state.sentOperations = operations;\n state.sentRejected = rejectedJson;\n if (patch.length === 0) return [];\n const event: ActivityDeltaEvent = {\n type: EventType.ACTIVITY_DELTA,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n patch: patch as ActivityDeltaEvent[\"patch\"],\n };\n return [event];\n };\n\n const emitSurface = (surfaceId: string): BaseEvent[] => {\n const state = surfaces.get(surfaceId);\n if (!state) return [];\n const operations: A2UIOperation[] = [];\n const rejected: GenerativeUIRejectedOperation[] = [];\n let created = false;\n let version: SourceVersion | undefined;\n for (const part of state.parts.values()) {\n for (const { operation, index, version: opVersion } of part.operations) {\n version ??= opVersion;\n if (opVersion !== version) {\n rejected.push({\n index,\n reason: `surface \"${surfaceId}\" is A2UI ${version}; an A2UI ${opVersion} operation cannot change it`,\n });\n continue;\n }\n if (\"createSurface\" in operation) {\n // A second createSurface of the same id is rejected in 1.0.\n if (created) continue;\n created = true;\n }\n operations.push(operation);\n }\n rejected.push(...part.rejected);\n }\n return created\n ? snapshotOf(surfaceId, state, operations, rejected, version ?? \"0.9\")\n : deltaOf(surfaceId, state, operations, rejected);\n };\n\n /** Converts the stored content of one source message again. */\n const refresh = (messageId: string): BaseEvent[] => {\n const parts = new Map<string, SourcePart>();\n readOperations(sources.get(messageId)).forEach((op, index) => {\n // An operation with no surface cannot be shown anywhere.\n const surfaceId = surfaceIdOf(op);\n if (surfaceId === undefined) return;\n let part = parts.get(surfaceId);\n if (!part) {\n part = { operations: [], rejected: [] };\n parts.set(surfaceId, part);\n }\n const { operations, dropped } = upgradeA2UIV09Operations([op]);\n // Only v0.9 and 1.0 operations convert.\n const version: SourceVersion =\n isRecord(op) && op.version === A2UI_VERSION ? \"1.0\" : \"0.9\";\n for (const operation of operations) {\n part.operations.push({ operation, index, version });\n }\n for (const { reason } of dropped) part.rejected.push({ index, reason });\n });\n const touched = new Set(parts.keys());\n for (const [surfaceId, state] of surfaces) {\n if (!parts.has(surfaceId) && state.parts.delete(messageId)) {\n touched.add(surfaceId);\n }\n }\n for (const [surfaceId, part] of parts) {\n let state = surfaces.get(surfaceId);\n if (!state) {\n state = {\n parts: new Map(),\n snapshotSource: [],\n snapshotOperations: [],\n sentOperations: [],\n sentRejected: \"[]\",\n };\n surfaces.set(surfaceId, state);\n }\n state.parts.set(messageId, part);\n }\n const events = [...touched].flatMap(emitSurface);\n const error = failedLifecycleError(sources.get(messageId));\n return error === undefined\n ? events\n : [...events, ...failureOf(messageId, error)];\n };\n\n return {\n transform(event) {\n if (event.type === EventType.ACTIVITY_SNAPSHOT) {\n const snapshot = event as ActivitySnapshotEvent;\n if (snapshot.activityType !== A2UI_SURFACE_ACTIVITY_TYPE) {\n return [event];\n }\n const { messageId } = snapshot;\n // `replace: false` does not replace a message that already exists.\n if (snapshot.replace === false && sources.has(messageId)) return [];\n sources.set(messageId, cloneValue(snapshot.content));\n return refresh(messageId);\n }\n if (event.type === EventType.ACTIVITY_DELTA) {\n const delta = event as ActivityDeltaEvent;\n if (delta.activityType !== A2UI_SURFACE_ACTIVITY_TYPE) return [event];\n const { messageId } = delta;\n if (!sources.has(messageId)) return [];\n let content: unknown;\n try {\n content = applyJsonPatch(\n cloneValue(sources.get(messageId)),\n delta.patch,\n );\n } catch {\n // The AG-UI client also skips a delta that does not apply.\n return [];\n }\n sources.set(messageId, content);\n return refresh(messageId);\n }\n return [event];\n },\n };\n}\n"],"mappings":";;;;;;;;;;AA2BA,MAAM,6BAA6B;AACnC,MAAM,sBAAsB;;AAG5B,MAAM,eAAoC,IAAI,IAAI,CAAC,QAAQ,SAAS,CAAC;AACrE,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACD;;;;;;AAQD,MAAM,wBAA6C,IAAI,IAAI,CACzD,0DACA,kEACD,CAAC;;;;;;AAOF,MAAM,wBAA6C,IAAI,IAAI,CACzD,kEACD,CAAC;;AAMF,MAAM,gBAAkD;CACtD,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACL;;AAGD,SAAS,QAAQ,IAAkD;CACjE,MAAM,QAAQ,UAAU,QAAQ,SAAS,QAAQ,GAAG;AACpD,QAAO,MAAM,WAAW,IAAI,MAAM,KAAK;;;;;;;;;;;;;;;;;;AAmBzC,SAAgB,mBAAmB,OAAyB;AAC1D,KAAI,CAAC,SAAS,MAAM,CAAE,QAAO;AAC7B,KAAI,MAAM,YAAY,OACpB,QAAO,OAAO,MAAM,YAAY,YAAY,aAAa,IAAI,MAAM,QAAQ;CAE7E,MAAM,OAAO,QAAQ,MAAM;AAC3B,QAAO,SAAS,UAAa,SAAS,MAAM,MAAM;;A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OAAI,SAAS,iBAAiB,2BAC5B,QAAO,CAAC,MAAM;GAEhB,MAAM,EAAE,cAAc;AAEtB,OAAI,SAAS,YAAY,SAAS,QAAQ,IAAI,UAAU,CAAE,QAAO,EAAE;AACnE,WAAQ,IAAI,WAAW,WAAW,SAAS,QAAQ,CAAC;AACpD,UAAO,QAAQ,UAAU;;AAE3B,MAAI,MAAM,SAAS,UAAU,gBAAgB;GAC3C,MAAM,QAAQ;AACd,OAAI,MAAM,iBAAiB,2BAA4B,QAAO,CAAC,MAAM;GACrE,MAAM,EAAE,cAAc;AACtB,OAAI,CAAC,QAAQ,IAAI,UAAU,CAAE,QAAO,EAAE;GACtC,IAAI;AACJ,OAAI;AACF,cAAU,eACR,WAAW,QAAQ,IAAI,UAAU,CAAC,EAClC,MAAM,MACP;WACK;AAEN,WAAO,EAAE;;AAEX,WAAQ,IAAI,WAAW,QAAQ;AAC/B,UAAO,QAAQ,UAAU;;AAE3B,SAAO,CAAC,MAAM;IAEjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generative-ui-middleware.cjs","names":["GENERATIVE_UI_RENDER_TOOL","GENERATIVE_UI_CONTEXT_DESCRIPTION","Middleware","Observable","EventType","GENERATIVE_UI_ACTIVITY_TYPE","GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE","RenderUIArgsStream"],"sources":["../../../src/runtime/generative-ui/generative-ui-middleware.ts"],"sourcesContent":["import { EventType, Middleware } from \"@ag-ui/client\";\nimport type {\n AbstractAgent,\n BaseEvent,\n Message,\n RunAgentInput,\n ToolCallArgsEvent,\n ToolCallEndEvent,\n ToolCallStartEvent,\n} from \"@ag-ui/client\";\nimport { Observable } from \"rxjs\";\nimport {\n GENERATIVE_UI_ACTIVITY_TYPE,\n GENERATIVE_UI_CONTEXT_DESCRIPTION,\n GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE,\n GENERATIVE_UI_RENDER_TOOL,\n RenderUIArgsStream,\n buildGenerativeUIPrompt,\n envelopeToManifest,\n generativeUIFunctionCallMessageId,\n generativeUISurfaceMessageId,\n getOperationKind,\n getOperationSurfaceId,\n randomUUID,\n readCopilotKitUIEnvelope,\n validateOperation,\n} from \"@copilotkit/shared\";\nimport type {\n A2UIOperation,\n GenerativeUIFunctionCallContent,\n GenerativeUIManifest,\n GenerativeUIRejectedOperation,\n GenerativeUISurfaceContent,\n} from \"@copilotkit/shared\";\n\ntype EventWithState = { event: BaseEvent; messages: Message[] };\ntype JsonPatchOperation = {\n op: \"add\" | \"replace\";\n path: string;\n value: unknown;\n};\n\ninterface RenderCallState {\n stream: RenderUIArgsStream;\n target?: string;\n buffered: Array<Record<string, unknown> | null>;\n nextIndex: number;\n /** Accepted surface operations. */\n applied: number;\n /** Accepted `callRendererFunction` operations. */\n calls: number;\n rejected: GenerativeUIRejectedOperation[];\n touched: Set<string>;\n finished: boolean;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Builds the manifest from the generative UI envelope\n * (`forwardedProps.copilotkit.ui`). The client sends the envelope, so it is\n * not trusted: `readCopilotKitUIEnvelope` checks every field, and\n * `envelopeToManifest` turns it into the manifest. Returns\n * `undefined` (the run passes through) when:\n * - there is no valid envelope;\n * - the transport is \"markdown\" (the model writes fences, not render_ui);\n * - the catalog has no components (the server cannot validate operations).\n */\nfunction readManifest(forwardedProps: unknown) {\n const envelope = readCopilotKitUIEnvelope(forwardedProps);\n if (!envelope) return undefined;\n const manifest = envelopeToManifest(envelope);\n const isToolRun = manifest.transport === \"tool\" && manifest.hasComponents;\n return isToolRun ? manifest : undefined;\n}\n\nfunction prepareInput(input: RunAgentInput, manifest: GenerativeUIManifest) {\n const tools = (input.tools ?? []).filter(\n (t) => t.name !== GENERATIVE_UI_RENDER_TOOL,\n );\n tools.push({\n name: GENERATIVE_UI_RENDER_TOOL,\n description:\n \"Render or update generative UI surfaces, or call app functions, with A2UI v1.0 operations. Follow the generative UI guide in context.\",\n parameters: {\n type: \"object\",\n properties: {\n target: {\n type: \"string\",\n enum: manifest.targets.map((t) => t.id),\n description:\n 'Where the surface is shown: \"chat\" or a named inline target.',\n },\n operations: {\n type: \"array\",\n description: \"A2UI v1.0 operations, applied in order.\",\n items: { type: \"object\" },\n },\n },\n required: [\"target\", \"operations\"],\n },\n });\n const context = (input.context ?? []).filter(\n (c) => c.description !== GENERATIVE_UI_CONTEXT_DESCRIPTION,\n );\n context.push({\n description: GENERATIVE_UI_CONTEXT_DESCRIPTION,\n value: buildGenerativeUIPrompt(manifest),\n });\n return { ...input, tools, context };\n}\n\n/**\n * Experimental. Lets an agent render CopilotKit generative UI surfaces via the\n * `render_ui` tool. It applies only to runs whose generative UI envelope uses\n * the \"tool\" transport. Each complete operation in the streamed arguments is\n * validated against the catalog in the envelope and committed immediately:\n * - `ACTIVITY_SNAPSHOT` for a new surface, `ACTIVITY_DELTA` for every further\n * operation on it.\n * - One `ACTIVITY_SNAPSHOT` of type `generative-ui-function-call` for each\n * `callRendererFunction`. The client runs the function.\n */\nexport class GenerativeUIMiddleware extends Middleware {\n run(input: RunAgentInput, next: AbstractAgent): Observable<BaseEvent> {\n const manifest = readManifest(input.forwardedProps);\n if (!manifest) return this.runNext(input, next);\n return processStream(\n this.runNextWithState(\n prepareInput(input, manifest),\n next,\n ) as Observable<EventWithState>,\n manifest,\n );\n }\n}\n\n/**\n * The first time a render_ui call touches an existing surface, mark it\n * streaming and clear its rejection list: earlier calls' rejections were\n * already reported to the model in their own tool results, and a repaired\n * surface must not keep showing them. A surface created by this call starts\n * with an empty list in its snapshot.\n */\nfunction beginSurfaceUpdate(\n state: RenderCallState,\n surfaceId: string,\n): JsonPatchOperation[] {\n if (state.touched.has(surfaceId)) return [];\n state.touched.add(surfaceId);\n return [\n { op: \"replace\", path: \"/status\", value: \"streaming\" },\n { op: \"replace\", path: \"/rejected\", value: [] },\n ];\n}\n\nfunction processStream(\n source: Observable<EventWithState>,\n manifest: GenerativeUIManifest,\n) {\n return new Observable<BaseEvent>((subscriber) => {\n const entries = Object.entries(manifest.surfaces);\n // Only live surfaces take updates. A surface that the client deleted, or\n // that was never created, has a `status`.\n const surfaces = new Map<string, string>(\n entries.filter(([, s]) => !s.status).map(([id, s]) => [id, s.target]),\n );\n // A surface id is unique for the life of the page. Keep the ids that were\n // created, also after deleteSurface (in this run or an earlier one), so a\n // second createSurface is rejected. A failed create can be sent again.\n const createdSurfaces = new Set(\n entries.filter(([, s]) => s.status !== \"failed\").map(([id]) => id),\n );\n // The targets that limit their components, by target id.\n const targetComponents = new Map(\n manifest.targets\n .filter((t) => t.components !== undefined)\n .map((t) => [t.id, new Set(t.components)]),\n );\n const functionCallIds = new Set<string>();\n const calls = new Map<string, RenderCallState>();\n let heldFinish: EventWithState | null = null;\n\n const emit = (event: BaseEvent) => subscriber.next(event);\n const patch = (surfaceId: string, ops: JsonPatchOperation[]) =>\n emit({\n type: EventType.ACTIVITY_DELTA,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n patch: ops,\n });\n\n const processOperation = (\n state: RenderCallState,\n op: Record<string, unknown> | null,\n ) => {\n const index = state.nextIndex++;\n const reject = (reason: string, surfaceId?: string) => {\n const entry = { index, reason };\n state.rejected.push(entry);\n if (surfaceId && surfaces.has(surfaceId)) {\n patch(surfaceId, [\n ...beginSurfaceUpdate(state, surfaceId),\n { op: \"add\", path: \"/rejected/-\", value: entry },\n ]);\n }\n };\n if (op === null) return reject(\"operation is not valid JSON\");\n let surfaceId: string | undefined;\n try {\n surfaceId = getOperationSurfaceId(op);\n applyOperation(state, withCatalogId(op), surfaceId, reject);\n } catch (error) {\n // Never let one bad operation take down the run: report it to the\n // model through the tool result instead.\n reject(\n `operation could not be processed: ${error instanceof Error ? error.message : String(error)}`,\n surfaceId,\n );\n }\n };\n\n /**\n * The model does not have to name the catalog. A createSurface keeps a\n * catalogId that the envelope lists, and gets the catalog id of the run\n * for any other value. The whole operation, with its inline components\n * and data model, stays in the snapshot.\n */\n const catalogIds = manifest.catalogIds ?? [manifest.catalogId];\n const withCatalogId = (op: Record<string, unknown>) => {\n const create = op.createSurface;\n if (!isRecord(create)) return op;\n const catalogId = catalogIds.includes(create.catalogId as string)\n ? create.catalogId\n : manifest.catalogId;\n return { ...op, createSurface: { ...create, catalogId } };\n };\n\n /**\n * The components that the target of the surface takes. A createSurface\n * goes to the target of the render_ui call. Every other operation goes to\n * the target that the surface was created on.\n */\n const allowedComponentsFor = (\n state: RenderCallState,\n op: Record<string, unknown>,\n surfaceId: string | undefined,\n ) => {\n const target =\n getOperationKind(op) === \"createSurface\"\n ? state.target\n : surfaces.get(surfaceId);\n const names = targetComponents.get(target);\n return names && { target, names };\n };\n\n const applyOperation = (\n state: RenderCallState,\n op: Record<string, unknown>,\n surfaceId: string | undefined,\n reject: (reason: string, surfaceId?: string) => void,\n ) => {\n const validation = validateOperation(op, {\n manifest,\n knownSurfaces: new Set(surfaces.keys()),\n createdSurfaces,\n functions: manifest.functions,\n allowedComponents: allowedComponentsFor(state, op, surfaceId),\n });\n // `=== false` (not `!ok`): runtime is compiled non-strict, where `!ok`\n // does not narrow the discriminated union.\n if (validation.ok === false) return reject(validation.reason, surfaceId);\n // validateOperation checked the shape of the operation.\n const accepted = op as A2UIOperation;\n if (\"callRendererFunction\" in accepted) {\n return callRendererFunction(\n state,\n accepted.callRendererFunction,\n reject,\n );\n }\n if (\"createSurface\" in accepted) {\n return createSurface(state, surfaceId, accepted, reject);\n }\n patch(surfaceId, [\n ...beginSurfaceUpdate(state, surfaceId),\n { op: \"add\", path: \"/operations/-\", value: accepted },\n ]);\n if (\"deleteSurface\" in accepted) surfaces.delete(surfaceId);\n state.applied++;\n };\n\n const createSurface = (\n state: RenderCallState,\n surfaceId: string,\n op: A2UIOperation,\n reject: (reason: string) => void,\n ) => {\n const { target } = state;\n if (target === undefined) {\n return reject(\"render_ui was called without a target\");\n }\n if (!manifest.targets.some((t) => t.id === target)) {\n return reject(`target \"${target}\" is not mounted`);\n }\n surfaces.set(surfaceId, target);\n createdSurfaces.add(surfaceId);\n const content: GenerativeUISurfaceContent = {\n surfaceId,\n target,\n catalogId:\n (\"createSurface\" in op && op.createSurface.catalogId) ||\n manifest.catalogId,\n operations: [op],\n status: \"streaming\",\n rejected: [],\n };\n emit({\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n content,\n replace: true,\n });\n state.touched.add(surfaceId);\n state.applied++;\n };\n\n /**\n * Sends one function call to the client, which runs it. A function call\n * needs no target and no surface. Each `functionCallId` runs once.\n */\n const callRendererFunction = (\n state: RenderCallState,\n content: GenerativeUIFunctionCallContent,\n reject: (reason: string) => void,\n ) => {\n const { functionCallId } = content;\n if (functionCallIds.has(functionCallId)) {\n return reject(\n `functionCallId \"${functionCallId}\" was used before; use a new functionCallId`,\n );\n }\n functionCallIds.add(functionCallId);\n emit({\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: generativeUIFunctionCallMessageId(functionCallId),\n activityType: GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE,\n content: {\n functionCallId,\n callFunction: content.callFunction,\n } satisfies GenerativeUIFunctionCallContent,\n replace: true,\n });\n state.calls++;\n };\n\n /** Same buffering rule as streamed ops: hold them until the target is known. */\n const acceptOperation = (\n state: RenderCallState,\n op: Record<string, unknown> | null,\n ) => {\n if (state.target === undefined) state.buffered.push(op);\n else processOperation(state, op);\n };\n\n /**\n * The streaming parser found no operations at all. Models sometimes send\n * `operations` as a JSON-encoded string; recover those from the complete\n * arguments. Anything still unusable leaves the call with zero operations,\n * which the tool result reports as an error.\n */\n const recoverOperations = (state: RenderCallState) => {\n let args: unknown;\n try {\n args = JSON.parse(state.stream.text);\n } catch {\n return;\n }\n if (!isRecord(args)) return;\n if (state.target === undefined && typeof args.target === \"string\") {\n state.target = args.target;\n }\n let operations = args.operations;\n if (typeof operations === \"string\") {\n try {\n operations = JSON.parse(operations);\n } catch {\n return;\n }\n }\n if (!Array.isArray(operations)) return;\n for (const op of operations)\n acceptOperation(state, isRecord(op) ? op : null);\n };\n\n const finishCall = (state: RenderCallState) => {\n if (state.finished) return;\n state.finished = true;\n if (state.nextIndex === 0 && state.buffered.length === 0)\n recoverOperations(state);\n if (state.target === undefined) {\n // A function call needs no target, so it still runs. Every other\n // operation is rejected.\n const buffered = state.buffered;\n state.buffered = [];\n for (const op of buffered) {\n if (getOperationKind(op) === \"callRendererFunction\") {\n processOperation(state, op);\n continue;\n }\n state.rejected.push({\n index: state.nextIndex++,\n reason: \"render_ui was called without a target\",\n });\n }\n }\n if (state.stream.hasIncompleteOperation) {\n // The arguments ended inside an element (for example the model hit its\n // output limit): report it instead of silently dropping it.\n state.rejected.push({\n index: state.nextIndex++,\n reason: \"operation was truncated\",\n });\n }\n for (const id of state.touched) {\n patch(id, [{ op: \"replace\", path: \"/status\", value: \"ready\" }]);\n }\n };\n\n const flushFinish = () => {\n if (heldFinish) {\n emit(heldFinish.event);\n heldFinish = null;\n }\n };\n\n const handleEvent = ({ event, messages }: EventWithState) => {\n flushFinish();\n if (event.type === EventType.RUN_FINISHED) {\n heldFinish = { event, messages };\n return;\n }\n emit(event);\n if (event.type === EventType.TOOL_CALL_START) {\n const start = event as ToolCallStartEvent;\n if (start.toolCallName === GENERATIVE_UI_RENDER_TOOL) {\n calls.set(start.toolCallId, {\n stream: new RenderUIArgsStream(),\n buffered: [],\n nextIndex: 0,\n applied: 0,\n calls: 0,\n rejected: [],\n touched: new Set(),\n finished: false,\n });\n }\n } else if (event.type === EventType.TOOL_CALL_ARGS) {\n const args = event as ToolCallArgsEvent;\n const state = calls.get(args.toolCallId);\n if (!state || state.finished) return;\n const { target, newOperations } = state.stream.push(args.delta);\n if (target !== undefined && state.target === undefined) {\n state.target = target;\n const buffered = state.buffered;\n state.buffered = [];\n for (const op of buffered) processOperation(state, op);\n }\n for (const op of newOperations) acceptOperation(state, op);\n } else if (event.type === EventType.TOOL_CALL_END) {\n const state = calls.get((event as ToolCallEndEvent).toolCallId);\n if (state) finishCall(state);\n }\n };\n\n const completeRun = () => {\n for (const state of calls.values()) finishCall(state);\n if (heldFinish) {\n const answered = new Set(\n heldFinish.messages\n .filter((m) => m.role === \"tool\")\n .map((m) => (m as { toolCallId: string }).toolCallId),\n );\n for (const [toolCallId, state] of calls) {\n if (answered.has(toolCallId)) continue;\n const nothingParsed =\n state.applied === 0 &&\n state.calls === 0 &&\n state.rejected.length === 0;\n // `applied` counts the surface operations, `calls` the function calls.\n emit({\n type: EventType.TOOL_CALL_RESULT,\n messageId: randomUUID(),\n toolCallId,\n content: JSON.stringify(\n nothingParsed\n ? {\n status: \"error\",\n applied: 0,\n calls: 0,\n rejected: [],\n reason:\n \"operations must be a JSON array of A2UI operation objects; nothing was rendered\",\n }\n : {\n status: \"rendered\",\n applied: state.applied,\n calls: state.calls,\n rejected: state.rejected,\n },\n ),\n });\n }\n flushFinish();\n }\n subscriber.complete();\n };\n\n let failed = false;\n const subscription = source.subscribe({\n next: (item) => {\n if (failed) return;\n try {\n handleEvent(item);\n } catch (error) {\n // Anything unexpected must reach the consumer as an error instead of\n // escaping this callback, where RxJS would rethrow it asynchronously\n // as an uncaught exception.\n failed = true;\n subscriber.error(error);\n }\n },\n error: (error) => {\n flushFinish();\n subscriber.error(error);\n },\n complete: () => {\n if (failed) return;\n try {\n completeRun();\n } catch (error) {\n failed = true;\n subscriber.error(error);\n }\n },\n });\n return () => subscription.unsubscribe();\n });\n}\n"],"mappings":";;;;;;AAwDA,SAAS,SAAS,OAAkD;AAClE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;;;;;;;;;;;AAa7E,SAAS,aAAa,gBAAyB;CAC7C,MAAM,4DAAoC,eAAe;AACzD,KAAI,CAAC,SAAU,QAAO;CACtB,MAAM,sDAA8B,SAAS;AAE7C,QADkB,SAAS,cAA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
{"version":3,"file":"generative-ui-middleware.cjs","names":["GENERATIVE_UI_RENDER_TOOL","GENERATIVE_UI_CONTEXT_DESCRIPTION","Middleware","Observable","EventType","GENERATIVE_UI_ACTIVITY_TYPE","GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE","RenderUIArgsStream"],"sources":["../../../src/runtime/generative-ui/generative-ui-middleware.ts"],"sourcesContent":["import { EventType, Middleware } from \"@ag-ui/client\";\nimport type {\n AbstractAgent,\n BaseEvent,\n Message,\n RunAgentInput,\n ToolCallArgsEvent,\n ToolCallEndEvent,\n ToolCallStartEvent,\n} from \"@ag-ui/client\";\nimport { Observable } from \"rxjs\";\nimport {\n GENERATIVE_UI_ACTIVITY_TYPE,\n GENERATIVE_UI_CONTEXT_DESCRIPTION,\n GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE,\n GENERATIVE_UI_RENDER_TOOL,\n RenderUIArgsStream,\n buildGenerativeUIPrompt,\n envelopeToManifest,\n generativeUIFunctionCallMessageId,\n generativeUISurfaceMessageId,\n getOperationKind,\n getOperationSurfaceId,\n randomUUID,\n readCopilotKitUIEnvelope,\n validateOperation,\n} from \"@copilotkit/shared\";\nimport type {\n A2UIOperation,\n GenerativeUIFunctionCallContent,\n GenerativeUIManifest,\n GenerativeUIRejectedOperation,\n GenerativeUISurfaceContent,\n} from \"@copilotkit/shared\";\n\ntype EventWithState = { event: BaseEvent; messages: Message[] };\ntype JsonPatchOperation = {\n op: \"add\" | \"replace\";\n path: string;\n value: unknown;\n};\n\ninterface RenderCallState {\n stream: RenderUIArgsStream;\n target?: string;\n buffered: Array<Record<string, unknown> | null>;\n nextIndex: number;\n /** Accepted surface operations. */\n applied: number;\n /** Accepted `callRendererFunction` operations. */\n calls: number;\n rejected: GenerativeUIRejectedOperation[];\n touched: Set<string>;\n finished: boolean;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Builds the manifest from the generative UI envelope\n * (`forwardedProps.copilotkit.ui`). The client sends the envelope, so it is\n * not trusted: `readCopilotKitUIEnvelope` checks every field, and\n * `envelopeToManifest` turns it into the manifest. Returns\n * `undefined` (the run passes through) when:\n * - there is no valid envelope;\n * - the transport is \"markdown\" (the model writes fences, not render_ui);\n * - the catalog has no components (the server cannot validate operations).\n */\nfunction readManifest(forwardedProps: unknown) {\n const envelope = readCopilotKitUIEnvelope(forwardedProps);\n if (!envelope) return undefined;\n const manifest = envelopeToManifest(envelope);\n const isToolRun = manifest.transport === \"tool\" && manifest.hasComponents;\n return isToolRun ? manifest : undefined;\n}\n\nfunction prepareInput(input: RunAgentInput, manifest: GenerativeUIManifest) {\n const tools = (input.tools ?? []).filter(\n (t) => t.name !== GENERATIVE_UI_RENDER_TOOL,\n );\n tools.push({\n name: GENERATIVE_UI_RENDER_TOOL,\n description:\n \"Render or update generative UI surfaces, or call app functions, with A2UI v1.0 operations. Follow the generative UI guide in context.\",\n parameters: {\n type: \"object\",\n properties: {\n target: {\n type: \"string\",\n enum: manifest.targets.map((t) => t.id),\n description:\n 'Where the surface is shown: \"chat\" or a named inline target.',\n },\n operations: {\n type: \"array\",\n description: \"A2UI v1.0 operations, applied in order.\",\n items: { type: \"object\" },\n },\n },\n required: [\"target\", \"operations\"],\n },\n });\n const context = (input.context ?? []).filter(\n (c) => c.description !== GENERATIVE_UI_CONTEXT_DESCRIPTION,\n );\n context.push({\n description: GENERATIVE_UI_CONTEXT_DESCRIPTION,\n value: buildGenerativeUIPrompt(manifest),\n });\n return { ...input, tools, context };\n}\n\n/**\n * Experimental. Lets an agent render CopilotKit generative UI surfaces via the\n * `render_ui` tool. It applies only to runs whose generative UI envelope uses\n * the \"tool\" transport. Each complete operation in the streamed arguments is\n * validated against the catalog in the envelope and committed immediately:\n * - `ACTIVITY_SNAPSHOT` for a new surface, `ACTIVITY_DELTA` for every further\n * operation on it.\n * - One `ACTIVITY_SNAPSHOT` of type `generative-ui-function-call` for each\n * `callRendererFunction`. The client runs the function.\n */\nexport class GenerativeUIMiddleware extends Middleware {\n run(input: RunAgentInput, next: AbstractAgent): Observable<BaseEvent> {\n const manifest = readManifest(input.forwardedProps);\n if (!manifest) return this.runNext(input, next);\n return processStream(\n this.runNextWithState(\n prepareInput(input, manifest),\n next,\n ) as Observable<EventWithState>,\n manifest,\n );\n }\n}\n\n/**\n * The first time a render_ui call touches an existing surface, mark it\n * streaming and clear its rejection list: earlier calls' rejections were\n * already reported to the model in their own tool results, and a repaired\n * surface must not keep showing them. A surface created by this call starts\n * with an empty list in its snapshot.\n */\nfunction beginSurfaceUpdate(\n state: RenderCallState,\n surfaceId: string,\n): JsonPatchOperation[] {\n if (state.touched.has(surfaceId)) return [];\n state.touched.add(surfaceId);\n return [\n { op: \"replace\", path: \"/status\", value: \"streaming\" },\n { op: \"replace\", path: \"/rejected\", value: [] },\n ];\n}\n\nfunction processStream(\n source: Observable<EventWithState>,\n manifest: GenerativeUIManifest,\n) {\n return new Observable<BaseEvent>((subscriber) => {\n const entries = Object.entries(manifest.surfaces);\n // Only live surfaces take updates. A surface that the client deleted, or\n // that was never created, has a `status`.\n const surfaces = new Map<string, string>(\n entries.filter(([, s]) => !s.status).map(([id, s]) => [id, s.target]),\n );\n // A surface id is unique for the life of the page. Keep the ids that were\n // created, also after deleteSurface (in this run or an earlier one), so a\n // second createSurface is rejected. A failed create can be sent again.\n const createdSurfaces = new Set(\n entries.filter(([, s]) => s.status !== \"failed\").map(([id]) => id),\n );\n // The targets that limit their components, by target id.\n const targetComponents = new Map(\n manifest.targets\n .filter((t) => t.components !== undefined)\n .map((t) => [t.id, new Set(t.components)]),\n );\n const functionCallIds = new Set<string>();\n const calls = new Map<string, RenderCallState>();\n let heldFinish: EventWithState | null = null;\n\n const emit = (event: BaseEvent) => subscriber.next(event);\n const patch = (surfaceId: string, ops: JsonPatchOperation[]) =>\n emit({\n type: EventType.ACTIVITY_DELTA,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n patch: ops,\n });\n\n const processOperation = (\n state: RenderCallState,\n op: Record<string, unknown> | null,\n ) => {\n const index = state.nextIndex++;\n const reject = (reason: string, surfaceId?: string) => {\n const entry = { index, reason };\n state.rejected.push(entry);\n if (surfaceId && surfaces.has(surfaceId)) {\n patch(surfaceId, [\n ...beginSurfaceUpdate(state, surfaceId),\n { op: \"add\", path: \"/rejected/-\", value: entry },\n ]);\n }\n };\n if (op === null) return reject(\"operation is not valid JSON\");\n let surfaceId: string | undefined;\n try {\n surfaceId = getOperationSurfaceId(op);\n applyOperation(state, withCatalogId(op), surfaceId, reject);\n } catch (error) {\n // Never let one bad operation take down the run: report it to the\n // model through the tool result instead.\n reject(\n `operation could not be processed: ${error instanceof Error ? error.message : String(error)}`,\n surfaceId,\n );\n }\n };\n\n /**\n * The model does not have to name the catalog. A createSurface keeps a\n * catalogId that the envelope lists, and gets the catalog id of the run\n * for any other value. The whole operation, with its inline components\n * and data model, stays in the snapshot.\n */\n const catalogIds = manifest.catalogIds ?? [manifest.catalogId];\n const withCatalogId = (op: Record<string, unknown>) => {\n const create = op.createSurface;\n if (!isRecord(create)) return op;\n const catalogId = catalogIds.includes(create.catalogId as string)\n ? create.catalogId\n : manifest.catalogId;\n return { ...op, createSurface: { ...create, catalogId } };\n };\n\n /**\n * The components that the target of the surface takes. A createSurface\n * goes to the target of the render_ui call. Every other operation goes to\n * the target that the surface was created on.\n */\n const allowedComponentsFor = (\n state: RenderCallState,\n op: Record<string, unknown>,\n surfaceId: string | undefined,\n ) => {\n const target =\n getOperationKind(op) === \"createSurface\"\n ? state.target\n : surfaces.get(surfaceId);\n const names = targetComponents.get(target);\n return names && { target, names };\n };\n\n const applyOperation = (\n state: RenderCallState,\n op: Record<string, unknown>,\n surfaceId: string | undefined,\n reject: (reason: string, surfaceId?: string) => void,\n ) => {\n const validation = validateOperation(op, {\n manifest,\n knownSurfaces: new Set(surfaces.keys()),\n createdSurfaces,\n functions: manifest.functions,\n allowedComponents: allowedComponentsFor(state, op, surfaceId),\n });\n // `=== false` (not `!ok`): runtime is compiled non-strict, where `!ok`\n // does not narrow the discriminated union.\n if (validation.ok === false) return reject(validation.reason, surfaceId);\n // validateOperation checked the shape of the operation.\n const accepted = op as A2UIOperation;\n if (\"callRendererFunction\" in accepted) {\n return callRendererFunction(\n state,\n accepted.callRendererFunction,\n reject,\n );\n }\n if (\"createSurface\" in accepted) {\n return createSurface(state, surfaceId, accepted, reject);\n }\n patch(surfaceId, [\n ...beginSurfaceUpdate(state, surfaceId),\n { op: \"add\", path: \"/operations/-\", value: accepted },\n ]);\n if (\"deleteSurface\" in accepted) surfaces.delete(surfaceId);\n state.applied++;\n };\n\n const createSurface = (\n state: RenderCallState,\n surfaceId: string,\n op: A2UIOperation,\n reject: (reason: string) => void,\n ) => {\n const { target } = state;\n if (target === undefined) {\n return reject(\"render_ui was called without a target\");\n }\n if (!manifest.targets.some((t) => t.id === target)) {\n return reject(`target \"${target}\" is not mounted`);\n }\n surfaces.set(surfaceId, target);\n createdSurfaces.add(surfaceId);\n const content: GenerativeUISurfaceContent = {\n surfaceId,\n target,\n catalogId:\n (\"createSurface\" in op && op.createSurface.catalogId) ||\n manifest.catalogId,\n operations: [op],\n status: \"streaming\",\n rejected: [],\n };\n emit({\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: generativeUISurfaceMessageId(surfaceId),\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n content,\n replace: true,\n });\n state.touched.add(surfaceId);\n state.applied++;\n };\n\n /**\n * Sends one function call to the client, which runs it. A function call\n * needs no target and no surface. Each `functionCallId` runs once.\n */\n const callRendererFunction = (\n state: RenderCallState,\n content: GenerativeUIFunctionCallContent,\n reject: (reason: string) => void,\n ) => {\n const { functionCallId } = content;\n if (functionCallIds.has(functionCallId)) {\n return reject(\n `functionCallId \"${functionCallId}\" was used before; use a new functionCallId`,\n );\n }\n functionCallIds.add(functionCallId);\n emit({\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: generativeUIFunctionCallMessageId(functionCallId),\n activityType: GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE,\n content: {\n functionCallId,\n callFunction: content.callFunction,\n } satisfies GenerativeUIFunctionCallContent,\n replace: true,\n });\n state.calls++;\n };\n\n /** Same buffering rule as streamed ops: hold them until the target is known. */\n const acceptOperation = (\n state: RenderCallState,\n op: Record<string, unknown> | null,\n ) => {\n if (state.target === undefined) state.buffered.push(op);\n else processOperation(state, op);\n };\n\n /**\n * The streaming parser found no operations at all. Models sometimes send\n * `operations` as a JSON-encoded string; recover those from the complete\n * arguments. Anything still unusable leaves the call with zero operations,\n * which the tool result reports as an error.\n */\n const recoverOperations = (state: RenderCallState) => {\n let args: unknown;\n try {\n args = JSON.parse(state.stream.text);\n } catch {\n return;\n }\n if (!isRecord(args)) return;\n if (state.target === undefined && typeof args.target === \"string\") {\n state.target = args.target;\n }\n let operations = args.operations;\n if (typeof operations === \"string\") {\n try {\n operations = JSON.parse(operations);\n } catch {\n return;\n }\n }\n if (!Array.isArray(operations)) return;\n for (const op of operations)\n acceptOperation(state, isRecord(op) ? op : null);\n };\n\n const finishCall = (state: RenderCallState) => {\n if (state.finished) return;\n state.finished = true;\n if (state.nextIndex === 0 && state.buffered.length === 0)\n recoverOperations(state);\n if (state.target === undefined) {\n // A function call needs no target, so it still runs. Every other\n // operation is rejected.\n const buffered = state.buffered;\n state.buffered = [];\n for (const op of buffered) {\n if (getOperationKind(op) === \"callRendererFunction\") {\n processOperation(state, op);\n continue;\n }\n state.rejected.push({\n index: state.nextIndex++,\n reason: \"render_ui was called without a target\",\n });\n }\n }\n if (state.stream.hasIncompleteOperation) {\n // The arguments ended inside an element (for example the model hit its\n // output limit): report it instead of silently dropping it.\n state.rejected.push({\n index: state.nextIndex++,\n reason: \"operation was truncated\",\n });\n }\n for (const id of state.touched) {\n patch(id, [{ op: \"replace\", path: \"/status\", value: \"ready\" }]);\n }\n };\n\n const flushFinish = () => {\n if (heldFinish) {\n emit(heldFinish.event);\n heldFinish = null;\n }\n };\n\n const handleEvent = ({ event, messages }: EventWithState) => {\n flushFinish();\n if (event.type === EventType.RUN_FINISHED) {\n heldFinish = { event, messages };\n return;\n }\n emit(event);\n if (event.type === EventType.TOOL_CALL_START) {\n const start = event as ToolCallStartEvent;\n if (start.toolCallName === GENERATIVE_UI_RENDER_TOOL) {\n calls.set(start.toolCallId, {\n stream: new RenderUIArgsStream(),\n buffered: [],\n nextIndex: 0,\n applied: 0,\n calls: 0,\n rejected: [],\n touched: new Set(),\n finished: false,\n });\n }\n } else if (event.type === EventType.TOOL_CALL_ARGS) {\n const args = event as ToolCallArgsEvent;\n const state = calls.get(args.toolCallId);\n if (!state || state.finished) return;\n const { target, newOperations } = state.stream.push(args.delta);\n if (target !== undefined && state.target === undefined) {\n state.target = target;\n const buffered = state.buffered;\n state.buffered = [];\n for (const op of buffered) processOperation(state, op);\n }\n for (const op of newOperations) acceptOperation(state, op);\n } else if (event.type === EventType.TOOL_CALL_END) {\n const state = calls.get((event as ToolCallEndEvent).toolCallId);\n if (state) finishCall(state);\n }\n };\n\n const completeRun = () => {\n for (const state of calls.values()) finishCall(state);\n if (heldFinish) {\n const answered = new Set(\n heldFinish.messages\n .filter((m) => m.role === \"tool\")\n .map((m) => (m as { toolCallId: string }).toolCallId),\n );\n for (const [toolCallId, state] of calls) {\n if (answered.has(toolCallId)) continue;\n const nothingParsed =\n state.applied === 0 &&\n state.calls === 0 &&\n state.rejected.length === 0;\n // `applied` counts the surface operations, `calls` the function calls.\n emit({\n type: EventType.TOOL_CALL_RESULT,\n messageId: randomUUID(),\n toolCallId,\n content: JSON.stringify(\n nothingParsed\n ? {\n status: \"error\",\n applied: 0,\n calls: 0,\n rejected: [],\n reason:\n \"operations must be a JSON array of A2UI operation objects; nothing was rendered\",\n }\n : {\n status: \"rendered\",\n applied: state.applied,\n calls: state.calls,\n rejected: state.rejected,\n },\n ),\n });\n }\n flushFinish();\n }\n subscriber.complete();\n };\n\n let failed = false;\n const subscription = source.subscribe({\n next: (item) => {\n if (failed) return;\n try {\n handleEvent(item);\n } catch (error) {\n // Anything unexpected must reach the consumer as an error instead of\n // escaping this callback, where RxJS would rethrow it asynchronously\n // as an uncaught exception.\n failed = true;\n subscriber.error(error);\n }\n },\n error: (error) => {\n flushFinish();\n subscriber.error(error);\n },\n complete: () => {\n if (failed) return;\n try {\n completeRun();\n } catch (error) {\n failed = true;\n subscriber.error(error);\n }\n },\n });\n return () => subscription.unsubscribe();\n });\n}\n"],"mappings":";;;;;AAwDA,SAAS,SAAS,OAAkD;AAClE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;;;;;;;;;;;AAa7E,SAAS,aAAa,gBAAyB;CAC7C,MAAM,4DAAoC,eAAe;AACzD,KAAI,CAAC,SAAU,QAAO;CACtB,MAAM,sDAA8B,SAAS;AAE7C,QADkB,SAAS,cAAc,UAAU,SAAS,gBACzC,WAAW;;AAGhC,SAAS,aAAa,OAAsB,UAAgC;CAC1E,MAAM,SAAS,MAAM,SAAS,EAAE,EAAE,QAC/B,MAAM,EAAE,SAASA,6CACnB;AACD,OAAM,KAAK;EACT,MAAMA;EACN,aACE;EACF,YAAY;GACV,MAAM;GACN,YAAY;IACV,QAAQ;KACN,MAAM;KACN,MAAM,SAAS,QAAQ,KAAK,MAAM,EAAE,GAAG;KACvC,aACE;KACH;IACD,YAAY;KACV,MAAM;KACN,aAAa;KACb,OAAO,EAAE,MAAM,UAAU;KAC1B;IACF;GACD,UAAU,CAAC,UAAU,aAAa;GACnC;EACF,CAAC;CACF,MAAM,WAAW,MAAM,WAAW,EAAE,EAAE,QACnC,MAAM,EAAE,gBAAgBC,qDAC1B;AACD,SAAQ,KAAK;EACX,aAAaA;EACb,uDAA+B,SAAS;EACzC,CAAC;AACF,QAAO;EAAE,GAAG;EAAO;EAAO;EAAS;;;;;;;;;;;;AAarC,IAAa,yBAAb,cAA4CC,yBAAW;CACrD,I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Z,gBACI;OACE,QAAQ;OACR,SAAS;OACT,OAAO;OACP,UAAU,EAAE;OACZ,QACE;OACH,GACD;OACE,QAAQ;OACR,SAAS,MAAM;OACf,OAAO,MAAM;OACb,UAAU,MAAM;OACjB,CACN;MACF,CAAC;;AAEJ,iBAAa;;AAEf,cAAW,UAAU;;EAGvB,IAAI,SAAS;EACb,MAAM,eAAe,OAAO,UAAU;GACpC,OAAO,SAAS;AACd,QAAI,OAAQ;AACZ,QAAI;AACF,iBAAY,KAAK;aACV,OAAO;AAId,cAAS;AACT,gBAAW,MAAM,MAAM;;;GAG3B,QAAQ,UAAU;AAChB,iBAAa;AACb,eAAW,MAAM,MAAM;;GAEzB,gBAAgB;AACd,QAAI,OAAQ;AACZ,QAAI;AACF,kBAAa;aACN,OAAO;AACd,cAAS;AACT,gBAAW,MAAM,MAAM;;;GAG5B,CAAC;AACF,eAAa,aAAa,aAAa;GACvC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
2
1
|
let _copilotkit_shared = require("@copilotkit/shared");
|
|
3
2
|
let _ag_ui_client = require("@ag-ui/client");
|
|
4
3
|
|
|
@@ -29,7 +28,7 @@ function createSurfaceWriter(emit) {
|
|
|
29
28
|
target,
|
|
30
29
|
catalogId: catalog,
|
|
31
30
|
operations: [{
|
|
32
|
-
version:
|
|
31
|
+
version: _copilotkit_shared.A2UI_VERSION,
|
|
33
32
|
createSurface: {
|
|
34
33
|
surfaceId,
|
|
35
34
|
catalogId: catalog
|
|
@@ -47,7 +46,7 @@ function createSurfaceWriter(emit) {
|
|
|
47
46
|
});
|
|
48
47
|
return {
|
|
49
48
|
setRoot: (node) => append({
|
|
50
|
-
version:
|
|
49
|
+
version: _copilotkit_shared.A2UI_VERSION,
|
|
51
50
|
updateComponents: {
|
|
52
51
|
surfaceId,
|
|
53
52
|
components: [{
|
|
@@ -57,14 +56,14 @@ function createSurfaceWriter(emit) {
|
|
|
57
56
|
}
|
|
58
57
|
}),
|
|
59
58
|
upsert: (...nodes) => append({
|
|
60
|
-
version:
|
|
59
|
+
version: _copilotkit_shared.A2UI_VERSION,
|
|
61
60
|
updateComponents: {
|
|
62
61
|
surfaceId,
|
|
63
62
|
components: nodes
|
|
64
63
|
}
|
|
65
64
|
}),
|
|
66
65
|
updateData: (path, value) => append({
|
|
67
|
-
version:
|
|
66
|
+
version: _copilotkit_shared.A2UI_VERSION,
|
|
68
67
|
updateDataModel: {
|
|
69
68
|
surfaceId,
|
|
70
69
|
path,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface-writer.cjs","names":["EventType","GENERATIVE_UI_ACTIVITY_TYPE","GENERATIVE_UI_ROOT_ID"],"sources":["../../../src/runtime/generative-ui/surface-writer.ts"],"sourcesContent":["import { EventType } from \"@ag-ui/client\";\nimport type { BaseEvent } from \"@ag-ui/client\";\nimport {\n GENERATIVE_UI_ACTIVITY_TYPE,\n GENERATIVE_UI_ROOT_ID,\n generativeUISurfaceMessageId,\n} from \"@copilotkit/shared\";\nimport type {\n A2UIComponentNode,\n A2UIOperation,\n GenerativeUISurfaceContent,\n} from \"@copilotkit/shared\";\n\nexport interface GenerativeUISurfaceWriter {\n setRoot(node: Omit<A2UIComponentNode, \"id\">): void;\n upsert(...nodes: A2UIComponentNode[]): void;\n /** Sets `value` at `path`. A `null` value deletes the key at `path`. */\n updateData(path: string, value: unknown): void;\n close(): void;\n}\n\n/**\n * Experimental. Programmatic façade for custom agents and workflows: emits the\n * same `generative-ui-surface` activity events as `render_ui`, one per call.\n * Every operation is A2UI v1.0.\n * Does not validate against the browser manifest; the client still validates\n * every operation before applying it.\n */\nexport function createSurfaceWriter(emit: (event: BaseEvent) => void) {\n return {\n openSurface({\n target,\n surfaceId,\n catalog,\n }: {\n target: string;\n surfaceId: string;\n catalog: string;\n }): GenerativeUISurfaceWriter {\n const messageId = generativeUISurfaceMessageId(surfaceId);\n const patch = (ops: unknown[]) =>\n emit({\n type: EventType.ACTIVITY_DELTA,\n messageId,\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n patch: ops,\n });\n const append = (op: A2UIOperation) =>\n patch([{ op: \"add\", path: \"/operations/-\", value: op }]);\n const content: GenerativeUISurfaceContent = {\n surfaceId,\n target,\n catalogId: catalog,\n operations: [\n {
|
|
1
|
+
{"version":3,"file":"surface-writer.cjs","names":["EventType","GENERATIVE_UI_ACTIVITY_TYPE","A2UI_VERSION","GENERATIVE_UI_ROOT_ID"],"sources":["../../../src/runtime/generative-ui/surface-writer.ts"],"sourcesContent":["import { EventType } from \"@ag-ui/client\";\nimport type { BaseEvent } from \"@ag-ui/client\";\nimport {\n A2UI_VERSION,\n GENERATIVE_UI_ACTIVITY_TYPE,\n GENERATIVE_UI_ROOT_ID,\n generativeUISurfaceMessageId,\n} from \"@copilotkit/shared\";\nimport type {\n A2UIComponentNode,\n A2UIOperation,\n GenerativeUISurfaceContent,\n} from \"@copilotkit/shared\";\n\nexport interface GenerativeUISurfaceWriter {\n setRoot(node: Omit<A2UIComponentNode, \"id\">): void;\n upsert(...nodes: A2UIComponentNode[]): void;\n /** Sets `value` at `path`. A `null` value deletes the key at `path`. */\n updateData(path: string, value: unknown): void;\n close(): void;\n}\n\n/**\n * Experimental. Programmatic façade for custom agents and workflows: emits the\n * same `generative-ui-surface` activity events as `render_ui`, one per call.\n * Every operation is A2UI v1.0.\n * Does not validate against the browser manifest; the client still validates\n * every operation before applying it.\n */\nexport function createSurfaceWriter(emit: (event: BaseEvent) => void) {\n return {\n openSurface({\n target,\n surfaceId,\n catalog,\n }: {\n target: string;\n surfaceId: string;\n catalog: string;\n }): GenerativeUISurfaceWriter {\n const messageId = generativeUISurfaceMessageId(surfaceId);\n const patch = (ops: unknown[]) =>\n emit({\n type: EventType.ACTIVITY_DELTA,\n messageId,\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n patch: ops,\n });\n const append = (op: A2UIOperation) =>\n patch([{ op: \"add\", path: \"/operations/-\", value: op }]);\n const content: GenerativeUISurfaceContent = {\n surfaceId,\n target,\n catalogId: catalog,\n operations: [\n {\n version: A2UI_VERSION,\n createSurface: { surfaceId, catalogId: catalog },\n },\n ],\n status: \"streaming\",\n rejected: [],\n };\n emit({\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId,\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n content,\n replace: true,\n });\n return {\n setRoot: (node) =>\n append({\n version: A2UI_VERSION,\n updateComponents: {\n surfaceId,\n components: [\n { ...node, id: GENERATIVE_UI_ROOT_ID } as A2UIComponentNode,\n ],\n },\n }),\n upsert: (...nodes) =>\n append({\n version: A2UI_VERSION,\n updateComponents: { surfaceId, components: nodes },\n }),\n updateData: (path, value) =>\n append({\n version: A2UI_VERSION,\n updateDataModel: { surfaceId, path, value },\n }),\n close: () =>\n patch([{ op: \"replace\", path: \"/status\", value: \"ready\" }]),\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;AA6BA,SAAgB,oBAAoB,MAAkC;AACpE,QAAO,EACL,YAAY,EACV,QACA,WACA,WAK4B;EAC5B,MAAM,iEAAyC,UAAU;EACzD,MAAM,SAAS,QACb,KAAK;GACH,MAAMA,wBAAU;GAChB;GACA,cAAcC;GACd,OAAO;GACR,CAAC;EACJ,MAAM,UAAU,OACd,MAAM,CAAC;GAAE,IAAI;GAAO,MAAM;GAAiB,OAAO;GAAI,CAAC,CAAC;EAC1D,MAAM,UAAsC;GAC1C;GACA;GACA,WAAW;GACX,YAAY,CACV;IACE,SAASC;IACT,eAAe;KAAE;KAAW,WAAW;KAAS;IACjD,CACF;GACD,QAAQ;GACR,UAAU,EAAE;GACb;AACD,OAAK;GACH,MAAMF,wBAAU;GAChB;GACA,cAAcC;GACd;GACA,SAAS;GACV,CAAC;AACF,SAAO;GACL,UAAU,SACR,OAAO;IACL,SAASC;IACT,kBAAkB;KAChB;KACA,YAAY,CACV;MAAE,GAAG;MAAM,IAAIC;MAAuB,CACvC;KACF;IACF,CAAC;GACJ,SAAS,GAAG,UACV,OAAO;IACL,SAASD;IACT,kBAAkB;KAAE;KAAW,YAAY;KAAO;IACnD,CAAC;GACJ,aAAa,MAAM,UACjB,OAAO;IACL,SAASA;IACT,iBAAiB;KAAE;KAAW;KAAM;KAAO;IAC5C,CAAC;GACJ,aACE,MAAM,CAAC;IAAE,IAAI;IAAW,MAAM;IAAW,OAAO;IAAS,CAAC,CAAC;GAC9D;IAEJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface-writer.d.cts","names":[],"sources":["../../../src/runtime/generative-ui/surface-writer.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"surface-writer.d.cts","names":[],"sources":["../../../src/runtime/generative-ui/surface-writer.ts"],"mappings":";;;;UAciB,yBAAA;EACf,OAAA,CAAQ,IAAA,EAAM,IAAA,CAAK,iBAAA;EACnB,MAAA,IAAU,KAAA,EAAO,iBAAA;EAFuB;EAIxC,UAAA,CAAW,IAAA,UAAc,KAAA;EACzB,KAAA;AAAA;;;;;;;;iBAUc,mBAAA,CAAoB,IAAA,GAAO,KAAA,EAAO,SAAA;;;;;;IAO5C,MAAA;IACA,SAAA;IACA,OAAA;EAAA,IACE,yBAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface-writer.d.mts","names":[],"sources":["../../../src/runtime/generative-ui/surface-writer.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"surface-writer.d.mts","names":[],"sources":["../../../src/runtime/generative-ui/surface-writer.ts"],"mappings":";;;;UAciB,yBAAA;EACf,OAAA,CAAQ,IAAA,EAAM,IAAA,CAAK,iBAAA;EACnB,MAAA,IAAU,KAAA,EAAO,iBAAA;EAFuB;EAIxC,UAAA,CAAW,IAAA,UAAc,KAAA;EACzB,KAAA;AAAA;;;;;;;;iBAUc,mBAAA,CAAoB,IAAA,GAAO,KAAA,EAAO,SAAA;;;;;;IAO5C,MAAA;IACA,SAAA;IACA,OAAA;EAAA,IACE,yBAAA;AAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GENERATIVE_UI_ACTIVITY_TYPE, GENERATIVE_UI_ROOT_ID, generativeUISurfaceMessageId } from "@copilotkit/shared";
|
|
1
|
+
import { A2UI_VERSION, GENERATIVE_UI_ACTIVITY_TYPE, GENERATIVE_UI_ROOT_ID, generativeUISurfaceMessageId } from "@copilotkit/shared";
|
|
2
2
|
import { EventType } from "@ag-ui/client";
|
|
3
3
|
|
|
4
4
|
//#region src/runtime/generative-ui/surface-writer.ts
|
|
@@ -28,7 +28,7 @@ function createSurfaceWriter(emit) {
|
|
|
28
28
|
target,
|
|
29
29
|
catalogId: catalog,
|
|
30
30
|
operations: [{
|
|
31
|
-
version:
|
|
31
|
+
version: A2UI_VERSION,
|
|
32
32
|
createSurface: {
|
|
33
33
|
surfaceId,
|
|
34
34
|
catalogId: catalog
|
|
@@ -46,7 +46,7 @@ function createSurfaceWriter(emit) {
|
|
|
46
46
|
});
|
|
47
47
|
return {
|
|
48
48
|
setRoot: (node) => append({
|
|
49
|
-
version:
|
|
49
|
+
version: A2UI_VERSION,
|
|
50
50
|
updateComponents: {
|
|
51
51
|
surfaceId,
|
|
52
52
|
components: [{
|
|
@@ -56,14 +56,14 @@ function createSurfaceWriter(emit) {
|
|
|
56
56
|
}
|
|
57
57
|
}),
|
|
58
58
|
upsert: (...nodes) => append({
|
|
59
|
-
version:
|
|
59
|
+
version: A2UI_VERSION,
|
|
60
60
|
updateComponents: {
|
|
61
61
|
surfaceId,
|
|
62
62
|
components: nodes
|
|
63
63
|
}
|
|
64
64
|
}),
|
|
65
65
|
updateData: (path, value) => append({
|
|
66
|
-
version:
|
|
66
|
+
version: A2UI_VERSION,
|
|
67
67
|
updateDataModel: {
|
|
68
68
|
surfaceId,
|
|
69
69
|
path,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface-writer.mjs","names":[],"sources":["../../../src/runtime/generative-ui/surface-writer.ts"],"sourcesContent":["import { EventType } from \"@ag-ui/client\";\nimport type { BaseEvent } from \"@ag-ui/client\";\nimport {\n GENERATIVE_UI_ACTIVITY_TYPE,\n GENERATIVE_UI_ROOT_ID,\n generativeUISurfaceMessageId,\n} from \"@copilotkit/shared\";\nimport type {\n A2UIComponentNode,\n A2UIOperation,\n GenerativeUISurfaceContent,\n} from \"@copilotkit/shared\";\n\nexport interface GenerativeUISurfaceWriter {\n setRoot(node: Omit<A2UIComponentNode, \"id\">): void;\n upsert(...nodes: A2UIComponentNode[]): void;\n /** Sets `value` at `path`. A `null` value deletes the key at `path`. */\n updateData(path: string, value: unknown): void;\n close(): void;\n}\n\n/**\n * Experimental. Programmatic façade for custom agents and workflows: emits the\n * same `generative-ui-surface` activity events as `render_ui`, one per call.\n * Every operation is A2UI v1.0.\n * Does not validate against the browser manifest; the client still validates\n * every operation before applying it.\n */\nexport function createSurfaceWriter(emit: (event: BaseEvent) => void) {\n return {\n openSurface({\n target,\n surfaceId,\n catalog,\n }: {\n target: string;\n surfaceId: string;\n catalog: string;\n }): GenerativeUISurfaceWriter {\n const messageId = generativeUISurfaceMessageId(surfaceId);\n const patch = (ops: unknown[]) =>\n emit({\n type: EventType.ACTIVITY_DELTA,\n messageId,\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n patch: ops,\n });\n const append = (op: A2UIOperation) =>\n patch([{ op: \"add\", path: \"/operations/-\", value: op }]);\n const content: GenerativeUISurfaceContent = {\n surfaceId,\n target,\n catalogId: catalog,\n operations: [\n {
|
|
1
|
+
{"version":3,"file":"surface-writer.mjs","names":[],"sources":["../../../src/runtime/generative-ui/surface-writer.ts"],"sourcesContent":["import { EventType } from \"@ag-ui/client\";\nimport type { BaseEvent } from \"@ag-ui/client\";\nimport {\n A2UI_VERSION,\n GENERATIVE_UI_ACTIVITY_TYPE,\n GENERATIVE_UI_ROOT_ID,\n generativeUISurfaceMessageId,\n} from \"@copilotkit/shared\";\nimport type {\n A2UIComponentNode,\n A2UIOperation,\n GenerativeUISurfaceContent,\n} from \"@copilotkit/shared\";\n\nexport interface GenerativeUISurfaceWriter {\n setRoot(node: Omit<A2UIComponentNode, \"id\">): void;\n upsert(...nodes: A2UIComponentNode[]): void;\n /** Sets `value` at `path`. A `null` value deletes the key at `path`. */\n updateData(path: string, value: unknown): void;\n close(): void;\n}\n\n/**\n * Experimental. Programmatic façade for custom agents and workflows: emits the\n * same `generative-ui-surface` activity events as `render_ui`, one per call.\n * Every operation is A2UI v1.0.\n * Does not validate against the browser manifest; the client still validates\n * every operation before applying it.\n */\nexport function createSurfaceWriter(emit: (event: BaseEvent) => void) {\n return {\n openSurface({\n target,\n surfaceId,\n catalog,\n }: {\n target: string;\n surfaceId: string;\n catalog: string;\n }): GenerativeUISurfaceWriter {\n const messageId = generativeUISurfaceMessageId(surfaceId);\n const patch = (ops: unknown[]) =>\n emit({\n type: EventType.ACTIVITY_DELTA,\n messageId,\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n patch: ops,\n });\n const append = (op: A2UIOperation) =>\n patch([{ op: \"add\", path: \"/operations/-\", value: op }]);\n const content: GenerativeUISurfaceContent = {\n surfaceId,\n target,\n catalogId: catalog,\n operations: [\n {\n version: A2UI_VERSION,\n createSurface: { surfaceId, catalogId: catalog },\n },\n ],\n status: \"streaming\",\n rejected: [],\n };\n emit({\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId,\n activityType: GENERATIVE_UI_ACTIVITY_TYPE,\n content,\n replace: true,\n });\n return {\n setRoot: (node) =>\n append({\n version: A2UI_VERSION,\n updateComponents: {\n surfaceId,\n components: [\n { ...node, id: GENERATIVE_UI_ROOT_ID } as A2UIComponentNode,\n ],\n },\n }),\n upsert: (...nodes) =>\n append({\n version: A2UI_VERSION,\n updateComponents: { surfaceId, components: nodes },\n }),\n updateData: (path, value) =>\n append({\n version: A2UI_VERSION,\n updateDataModel: { surfaceId, path, value },\n }),\n close: () =>\n patch([{ op: \"replace\", path: \"/status\", value: \"ready\" }]),\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;AA6BA,SAAgB,oBAAoB,MAAkC;AACpE,QAAO,EACL,YAAY,EACV,QACA,WACA,WAK4B;EAC5B,MAAM,YAAY,6BAA6B,UAAU;EACzD,MAAM,SAAS,QACb,KAAK;GACH,MAAM,UAAU;GAChB;GACA,cAAc;GACd,OAAO;GACR,CAAC;EACJ,MAAM,UAAU,OACd,MAAM,CAAC;GAAE,IAAI;GAAO,MAAM;GAAiB,OAAO;GAAI,CAAC,CAAC;EAC1D,MAAM,UAAsC;GAC1C;GACA;GACA,WAAW;GACX,YAAY,CACV;IACE,SAAS;IACT,eAAe;KAAE;KAAW,WAAW;KAAS;IACjD,CACF;GACD,QAAQ;GACR,UAAU,EAAE;GACb;AACD,OAAK;GACH,MAAM,UAAU;GAChB;GACA,cAAc;GACd;GACA,SAAS;GACV,CAAC;AACF,SAAO;GACL,UAAU,SACR,OAAO;IACL,SAAS;IACT,kBAAkB;KAChB;KACA,YAAY,CACV;MAAE,GAAG;MAAM,IAAI;MAAuB,CACvC;KACF;IACF,CAAC;GACJ,SAAS,GAAG,UACV,OAAO;IACL,SAAS;IACT,kBAAkB;KAAE;KAAW,YAAY;KAAO;IACnD,CAAC;GACJ,aAAa,MAAM,UACjB,OAAO;IACL,SAAS;IACT,iBAAiB;KAAE;KAAW;KAAM;KAAO;IAC5C,CAAC;GACJ,aACE,MAAM,CAAC;IAAE,IAAI;IAAW,MAAM;IAAW,OAAO;IAAS,CAAC,CAAC;GAC9D;IAEJ"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_logger = require('../core/logger.cjs');
|
|
1
2
|
const require_agent_runner = require('../runner/agent-runner.cjs');
|
|
2
3
|
const require_learning = require('../core/learning.cjs');
|
|
3
4
|
const require_client = require('../intelligence-platform/client.cjs');
|
|
@@ -72,7 +73,10 @@ async function handleGetRuntimeInfo({ runtime, request, threadEndpointsEnabled =
|
|
|
72
73
|
try {
|
|
73
74
|
capabilities = agent.getCapabilities ? await agent.getCapabilities() : void 0;
|
|
74
75
|
} catch (error) {
|
|
75
|
-
|
|
76
|
+
require_logger.getRuntimeLogger(runtime).warn({
|
|
77
|
+
err: error,
|
|
78
|
+
agentId: name
|
|
79
|
+
}, `Failed to fetch capabilities for agent "${name}"`);
|
|
76
80
|
capabilities = void 0;
|
|
77
81
|
}
|
|
78
82
|
return [name, {
|
|
@@ -101,12 +105,8 @@ async function handleGetRuntimeInfo({ runtime, request, threadEndpointsEnabled =
|
|
|
101
105
|
inspectorMetadata: true,
|
|
102
106
|
...require_learning.hasLearningContainerConfiguration(runtime) ? { inspectorLearning: true } : {}
|
|
103
107
|
} : {},
|
|
104
|
-
a2uiEnabled: webEnabled && require_runtime.isA2UIEnabled(runtime.a2ui),
|
|
105
|
-
...webEnabled && require_runtime.isA2UIEnabled(runtime.a2ui) ? { a2ui: {
|
|
106
|
-
enabled: true,
|
|
107
|
-
...runtime.a2ui.agents ? { agents: runtime.a2ui.agents } : {}
|
|
108
|
-
} } : {},
|
|
109
108
|
openGenerativeUIEnabled: webEnabled && !!runtime.openGenerativeUI,
|
|
109
|
+
generativeUI: resolveGenerativeUIInfo(runtime, webEnabled),
|
|
110
110
|
...require_runtime.isIntelligenceRuntime(runtime) ? { licenseStatus: resolveCompatibilityLicenseStatus(licenseChecker, runtimeEntitlements) } : {},
|
|
111
111
|
...runtimeEntitlements ? { runtimeEntitlements } : {},
|
|
112
112
|
telemetryDisabled: require_telemetry_client.isTelemetryDisabled()
|
|
@@ -125,6 +125,24 @@ async function handleGetRuntimeInfo({ runtime, request, threadEndpointsEnabled =
|
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Report generative UI with the rules `configureAgentForRequest` uses to
|
|
130
|
+
* attach the generative UI middlewares: it is on unless `generativeUI` is
|
|
131
|
+
* `false`, and `{ agents }` limits it to those agents. The A2UI version of an
|
|
132
|
+
* agent (`a2uiVersion`) does not change it: the client renders 1.0 for both,
|
|
133
|
+
* as the runtime converts v0.9 surfaces. When the option is omitted, the
|
|
134
|
+
* middlewares run only for a client that asks for them, so the client can
|
|
135
|
+
* still turn generative UI on.
|
|
136
|
+
*/
|
|
137
|
+
function resolveGenerativeUIInfo(runtime, webEnabled) {
|
|
138
|
+
const generativeUI = runtime.generativeUI;
|
|
139
|
+
if (!webEnabled || generativeUI === false) return { enabled: false };
|
|
140
|
+
const agents = typeof generativeUI === "object" ? generativeUI.agents : void 0;
|
|
141
|
+
return {
|
|
142
|
+
enabled: true,
|
|
143
|
+
...agents ? { agents } : {}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
128
146
|
function resolveThreadEndpointInfo(runtime, threadEndpointsEnabled) {
|
|
129
147
|
const available = (operation) => threadEndpointsEnabled && (require_runtime.isIntelligenceRuntime(runtime) || require_agent_runner.supportsLocalThreadEndpoints(runtime.runner) && require_thread_access.isThreadOperationAvailable(runtime, operation));
|
|
130
148
|
const managedThreadMetadata = threadEndpointsEnabled && require_runtime.isIntelligenceRuntime(runtime);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-runtime-info.cjs","names":["isIntelligenceRuntime","PlatformRequestError","resolveAgents","VERSION","hasLearningContainerConfiguration","isA2UIEnabled","isTelemetryDisabled","supportsLocalThreadEndpoints","isThreadOperationAvailable"],"sources":["../../../src/runtime/handlers/get-runtime-info.ts"],"sourcesContent":["import type { AgentCapabilities } from \"@ag-ui/core\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { hasLearningContainerConfiguration } from \"../core/learning\";\nimport {\n isA2UIEnabled,\n isIntelligenceRuntime,\n resolveAgents,\n} from \"../core/runtime\";\nimport type {\n AgentDescription,\n RuntimeInfo,\n RuntimeEntitlementResponse,\n ThreadEndpointRuntimeInfo,\n} from \"@copilotkit/shared\";\nimport type { RuntimeLicenseStatus } from \"@copilotkit/shared\";\nimport type { LicenseChecker } from \"@copilotkit/license-verifier\";\nimport { VERSION } from \"../core/runtime\";\nimport { PlatformRequestError } from \"../intelligence-platform/client\";\nimport { isTelemetryDisabled } from \"../telemetry/telemetry-client\";\nimport { supportsLocalThreadEndpoints } from \"../runner/agent-runner\";\nimport { isThreadOperationAvailable } from \"./shared/thread-access\";\n\nfunction resolveLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n): RuntimeLicenseStatus {\n if (!licenseChecker) return \"none\";\n const status = licenseChecker.getStatus();\n if (status.warningSeverity === \"none\") return \"valid\";\n if (status.error === \"expired\") return \"expired\";\n if (status.warningSeverity === \"warning\") return \"expiring\";\n if (status.error) return \"invalid\";\n if (status.warningSeverity === \"info\") return \"none\";\n return \"unknown\";\n}\n\n/**\n * Map the structured entitlement authority onto the legacy status consumed by\n * older Core, React, and Angular thread surfaces. A ready managed entitlement\n * is authoritative in both directions. Otherwise, preserve the legacy\n * self-hosted license fallback. A retryable lookup without that fallback\n * remains unknown until it resolves.\n */\nfunction resolveCompatibilityLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n runtimeEntitlements: RuntimeEntitlementResponse | undefined,\n): RuntimeLicenseStatus {\n if (runtimeEntitlements?.status === \"ready\") {\n if (\n runtimeEntitlements.entitlement.source === \"managedOrgSubscription\" ||\n runtimeEntitlements.entitlement.source ===\n \"awsMarketplaceDeploymentLicense\"\n ) {\n return runtimeEntitlements.entitlement.active ? \"valid\" : \"none\";\n }\n\n if (runtimeEntitlements.entitlement.active) {\n return \"valid\";\n }\n }\n\n const legacyLicenseStatus = resolveLicenseStatus(licenseChecker);\n if (\n legacyLicenseStatus === \"none\" &&\n runtimeEntitlements?.status !== \"ready\" &&\n runtimeEntitlements?.error.retryable\n ) {\n return \"unknown\";\n }\n\n return legacyLicenseStatus;\n}\n\ninterface HandleGetRuntimeInfoParameters {\n runtime: CopilotRuntimeLike;\n request: Request;\n threadEndpointsEnabled?: boolean;\n singleRouteResourceOperationsEnabled?: boolean;\n}\n\n/**\n * Resolve structured Runtime entitlements for configured Intelligence runtimes.\n *\n * Dependency failures are deliberately converted to a stable unavailable\n * diagnostic so `/info` remains an availability endpoint. The underlying\n * error is not exposed because it may contain upstream response details.\n */\nasync function resolveRuntimeEntitlements(\n runtime: CopilotRuntimeLike,\n): Promise<RuntimeEntitlementResponse | undefined> {\n if (!isIntelligenceRuntime(runtime)) {\n return undefined;\n }\n\n try {\n return await runtime.intelligence.getRuntimeEntitlements();\n } catch (error) {\n if (error instanceof PlatformRequestError && error.retryable === false) {\n return {\n status: \"misconfigured\",\n error: {\n code: \"runtime_entitlements_misconfigured\",\n message: \"Runtime entitlement lookup is misconfigured\",\n retryable: false,\n },\n };\n }\n\n return {\n status: \"unavailable\",\n error: {\n code: \"runtime_entitlements_unavailable\",\n message: \"Runtime entitlement lookup failed\",\n retryable: true,\n },\n };\n }\n}\n\nexport async function handleGetRuntimeInfo({\n runtime,\n request,\n threadEndpointsEnabled = true,\n singleRouteResourceOperationsEnabled = false,\n}: HandleGetRuntimeInfoParameters) {\n try {\n const runtimeEntitlementsPromise = resolveRuntimeEntitlements(runtime);\n const webEnabled =\n !isIntelligenceRuntime(runtime) || runtime.identifyUser !== undefined;\n const agents = webEnabled\n ? await resolveAgents(runtime.agents, request)\n : {};\n\n const agentEntries = await Promise.all(\n Object.entries(agents).map(async ([name, agent]) => {\n let capabilities: AgentCapabilities | undefined;\n try {\n capabilities = agent.getCapabilities\n ? await agent.getCapabilities()\n : undefined;\n } catch (error) {\n // Per-agent isolation: a single agent failing to report capabilities\n // must not take down the entire /info endpoint.\n console.warn(\n `Failed to fetch capabilities for agent \"${name}\":`,\n error instanceof Error ? error.message : error,\n );\n capabilities = undefined;\n }\n\n const description: AgentDescription = {\n name,\n description: agent.description,\n className: agent.constructor.name,\n ...(capabilities ? { capabilities } : {}),\n };\n\n return [name, description] as const;\n }),\n );\n\n const agentsDict: Record<string, AgentDescription> =\n Object.fromEntries(agentEntries);\n const runtimeEntitlements = await runtimeEntitlementsPromise;\n // Verified on first use, not at construction (see getLicenseChecker).\n const licenseChecker = isIntelligenceRuntime(runtime)\n ? await runtime.getLicenseChecker?.()\n : undefined;\n\n const runtimeInfo: RuntimeInfo = {\n version: VERSION,\n agents: agentsDict,\n audioFileTranscriptionEnabled:\n webEnabled && !!runtime.transcriptionService,\n mode: runtime.mode,\n threadEndpoints: resolveThreadEndpointInfo(\n runtime,\n threadEndpointsEnabled && webEnabled,\n ),\n ...(singleRouteResourceOperationsEnabled\n ? {\n singleRoute: {\n resourceOperations: true,\n threadEndpoints: resolveThreadEndpointInfo(runtime, webEnabled),\n },\n }\n : {}),\n // Advertised unconditionally. Multi-route runtimes expose the dedicated\n // POST /agent/:agentId/suggest path; single-route clients fall back to a\n // client-side run (they don't construct the single-route envelope for\n // suggest). The flag lets multi-route clients detect the stateless path.\n suggestions: webEnabled,\n ...(isIntelligenceRuntime(runtime) && webEnabled\n ? {\n intelligence: {\n wsUrl: runtime.intelligence.ɵgetClientWsUrl(),\n },\n inspectorMetadata: true,\n ...(hasLearningContainerConfiguration(runtime)\n ? { inspectorLearning: true }\n : {}),\n }\n : {}),\n // Legacy flat flag, kept for older clients. The `a2ui` object below is\n // the source of truth: it preserves the per-agent scoping that this\n // boolean discards (see CopilotKit/CopilotKit#5369). Both go through the\n // shared isA2UIEnabled() predicate so an explicit `enabled: false`\n // disables a2ui here exactly as it does on the run path.\n a2uiEnabled: webEnabled && isA2UIEnabled(runtime.a2ui),\n ...(webEnabled && isA2UIEnabled(runtime.a2ui)\n ? {\n a2ui: {\n enabled: true,\n ...(runtime.a2ui.agents ? { agents: runtime.a2ui.agents } : {}),\n },\n }\n : {}),\n openGenerativeUIEnabled: webEnabled && !!runtime.openGenerativeUI,\n ...(isIntelligenceRuntime(runtime)\n ? {\n licenseStatus: resolveCompatibilityLicenseStatus(\n licenseChecker,\n runtimeEntitlements,\n ),\n }\n : {}),\n ...(runtimeEntitlements ? { runtimeEntitlements } : {}),\n telemetryDisabled: isTelemetryDisabled(),\n };\n\n return new Response(JSON.stringify(runtimeInfo), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (error) {\n return new Response(\n JSON.stringify({\n error: \"Failed to retrieve runtime information\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n\nfunction resolveThreadEndpointInfo(\n runtime: CopilotRuntimeLike,\n threadEndpointsEnabled: boolean,\n): ThreadEndpointRuntimeInfo {\n // A local route is advertised only when the Thread access policy lets it\n // serve requests: without identity, list is refused by default while\n // reading a Thread by id is not.\n const available = (operation: \"list\" | \"read\") =>\n threadEndpointsEnabled &&\n (isIntelligenceRuntime(runtime) ||\n (supportsLocalThreadEndpoints(runtime.runner) &&\n isThreadOperationAvailable(runtime, operation)));\n const managedThreadMetadata =\n threadEndpointsEnabled && isIntelligenceRuntime(runtime);\n\n return {\n list: available(\"list\"),\n inspect: available(\"read\"),\n mutations: managedThreadMetadata,\n realtimeMetadata: managedThreadMetadata,\n };\n}\n"],"mappings":";;;;;;;;AAsBA,SAAS,qBACP,gBACsB;AACtB,KAAI,CAAC,eAAgB,QAAO;CAC5B,MAAM,SAAS,eAAe,WAAW;AACzC,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,KAAI,OAAO,UAAU,UAAW,QAAO;AACvC,KAAI,OAAO,oBAAoB,UAAW,QAAO;AACjD,KAAI,OAAO,MAAO,QAAO;AACzB,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,QAAO;;;;;;;;;AAUT,SAAS,kCACP,gBACA,qBACsB;AACtB,KAAI,qBAAqB,WAAW,SAAS;AAC3C,MACE,oBAAoB,YAAY,WAAW,4BAC3C,oBAAoB,YAAY,WAC9B,kCAEF,QAAO,oBAAoB,YAAY,SAAS,UAAU;AAG5D,MAAI,oBAAoB,YAAY,OAClC,QAAO;;CAIX,MAAM,sBAAsB,qBAAqB,eAAe;AAChE,KACE,wBAAwB,UACxB,qBAAqB,WAAW,WAChC,qBAAqB,MAAM,UAE3B,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AAM,UAAU,OAAO;EACvB,SAAS,UAAU,OAAO;EAC1B,WAAW;EACX,kBAAkB;EACnB"}
|
|
1
|
+
{"version":3,"file":"get-runtime-info.cjs","names":["isIntelligenceRuntime","PlatformRequestError","resolveAgents","VERSION","hasLearningContainerConfiguration","isTelemetryDisabled","supportsLocalThreadEndpoints","isThreadOperationAvailable"],"sources":["../../../src/runtime/handlers/get-runtime-info.ts"],"sourcesContent":["import { getRuntimeLogger } from \"../core/logger\";\nimport type { AgentCapabilities } from \"@ag-ui/core\";\nimport type { CopilotKitRuntimeLike } from \"../core/runtime\";\nimport { hasLearningContainerConfiguration } from \"../core/learning\";\nimport { isIntelligenceRuntime, resolveAgents } from \"../core/runtime\";\nimport type {\n AgentDescription,\n GenerativeUIRuntimeInfo,\n RuntimeInfo,\n RuntimeEntitlementResponse,\n ThreadEndpointRuntimeInfo,\n} from \"@copilotkit/shared\";\nimport type { RuntimeLicenseStatus } from \"@copilotkit/shared\";\nimport type { LicenseChecker } from \"@copilotkit/license-verifier\";\nimport { VERSION } from \"../core/runtime\";\nimport { PlatformRequestError } from \"../intelligence-platform/client\";\nimport { isTelemetryDisabled } from \"../telemetry/telemetry-client\";\nimport { supportsLocalThreadEndpoints } from \"../runner/agent-runner\";\nimport { isThreadOperationAvailable } from \"./shared/thread-access\";\n\nfunction resolveLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n): RuntimeLicenseStatus {\n if (!licenseChecker) return \"none\";\n const status = licenseChecker.getStatus();\n if (status.warningSeverity === \"none\") return \"valid\";\n if (status.error === \"expired\") return \"expired\";\n if (status.warningSeverity === \"warning\") return \"expiring\";\n if (status.error) return \"invalid\";\n if (status.warningSeverity === \"info\") return \"none\";\n return \"unknown\";\n}\n\n/**\n * Map the structured entitlement authority onto the legacy status consumed by\n * older Core, React, and Angular thread surfaces. A ready managed entitlement\n * is authoritative in both directions. Otherwise, preserve the legacy\n * self-hosted license fallback. A retryable lookup without that fallback\n * remains unknown until it resolves.\n */\nfunction resolveCompatibilityLicenseStatus(\n licenseChecker: LicenseChecker | undefined,\n runtimeEntitlements: RuntimeEntitlementResponse | undefined,\n): RuntimeLicenseStatus {\n if (runtimeEntitlements?.status === \"ready\") {\n if (\n runtimeEntitlements.entitlement.source === \"managedOrgSubscription\" ||\n runtimeEntitlements.entitlement.source ===\n \"awsMarketplaceDeploymentLicense\"\n ) {\n return runtimeEntitlements.entitlement.active ? \"valid\" : \"none\";\n }\n\n if (runtimeEntitlements.entitlement.active) {\n return \"valid\";\n }\n }\n\n const legacyLicenseStatus = resolveLicenseStatus(licenseChecker);\n if (\n legacyLicenseStatus === \"none\" &&\n runtimeEntitlements?.status !== \"ready\" &&\n runtimeEntitlements?.error.retryable\n ) {\n return \"unknown\";\n }\n\n return legacyLicenseStatus;\n}\n\ninterface HandleGetRuntimeInfoParameters {\n runtime: CopilotKitRuntimeLike;\n request: Request;\n threadEndpointsEnabled?: boolean;\n singleRouteResourceOperationsEnabled?: boolean;\n}\n\n/**\n * Resolve structured Runtime entitlements for configured Intelligence runtimes.\n *\n * Dependency failures are deliberately converted to a stable unavailable\n * diagnostic so `/info` remains an availability endpoint. The underlying\n * error is not exposed because it may contain upstream response details.\n */\nasync function resolveRuntimeEntitlements(\n runtime: CopilotKitRuntimeLike,\n): Promise<RuntimeEntitlementResponse | undefined> {\n if (!isIntelligenceRuntime(runtime)) {\n return undefined;\n }\n\n try {\n return await runtime.intelligence.getRuntimeEntitlements();\n } catch (error) {\n if (error instanceof PlatformRequestError && error.retryable === false) {\n return {\n status: \"misconfigured\",\n error: {\n code: \"runtime_entitlements_misconfigured\",\n message: \"Runtime entitlement lookup is misconfigured\",\n retryable: false,\n },\n };\n }\n\n return {\n status: \"unavailable\",\n error: {\n code: \"runtime_entitlements_unavailable\",\n message: \"Runtime entitlement lookup failed\",\n retryable: true,\n },\n };\n }\n}\n\nexport async function handleGetRuntimeInfo({\n runtime,\n request,\n threadEndpointsEnabled = true,\n singleRouteResourceOperationsEnabled = false,\n}: HandleGetRuntimeInfoParameters) {\n try {\n const runtimeEntitlementsPromise = resolveRuntimeEntitlements(runtime);\n const webEnabled =\n !isIntelligenceRuntime(runtime) || runtime.identifyUser !== undefined;\n const agents = webEnabled\n ? await resolveAgents(runtime.agents, request)\n : {};\n\n const agentEntries = await Promise.all(\n Object.entries(agents).map(async ([name, agent]) => {\n let capabilities: AgentCapabilities | undefined;\n try {\n capabilities = agent.getCapabilities\n ? await agent.getCapabilities()\n : undefined;\n } catch (error) {\n // Per-agent isolation: a single agent failing to report capabilities\n // must not take down the entire /info endpoint.\n getRuntimeLogger(runtime).warn(\n { err: error, agentId: name },\n `Failed to fetch capabilities for agent \"${name}\"`,\n );\n capabilities = undefined;\n }\n\n const description: AgentDescription = {\n name,\n description: agent.description,\n className: agent.constructor.name,\n ...(capabilities ? { capabilities } : {}),\n };\n\n return [name, description] as const;\n }),\n );\n\n const agentsDict: Record<string, AgentDescription> =\n Object.fromEntries(agentEntries);\n const runtimeEntitlements = await runtimeEntitlementsPromise;\n // Verified on first use, not at construction (see getLicenseChecker).\n const licenseChecker = isIntelligenceRuntime(runtime)\n ? await runtime.getLicenseChecker?.()\n : undefined;\n\n const runtimeInfo: RuntimeInfo = {\n version: VERSION,\n agents: agentsDict,\n audioFileTranscriptionEnabled:\n webEnabled && !!runtime.transcriptionService,\n mode: runtime.mode,\n threadEndpoints: resolveThreadEndpointInfo(\n runtime,\n threadEndpointsEnabled && webEnabled,\n ),\n ...(singleRouteResourceOperationsEnabled\n ? {\n singleRoute: {\n resourceOperations: true,\n threadEndpoints: resolveThreadEndpointInfo(runtime, webEnabled),\n },\n }\n : {}),\n // Advertised unconditionally. Multi-route runtimes expose the dedicated\n // POST /agent/:agentId/suggest path; single-route clients fall back to a\n // client-side run (they don't construct the single-route envelope for\n // suggest). The flag lets multi-route clients detect the stateless path.\n suggestions: webEnabled,\n ...(isIntelligenceRuntime(runtime) && webEnabled\n ? {\n intelligence: {\n wsUrl: runtime.intelligence.ɵgetClientWsUrl(),\n },\n inspectorMetadata: true,\n ...(hasLearningContainerConfiguration(runtime)\n ? { inspectorLearning: true }\n : {}),\n }\n : {}),\n openGenerativeUIEnabled: webEnabled && !!runtime.openGenerativeUI,\n generativeUI: resolveGenerativeUIInfo(runtime, webEnabled),\n ...(isIntelligenceRuntime(runtime)\n ? {\n licenseStatus: resolveCompatibilityLicenseStatus(\n licenseChecker,\n runtimeEntitlements,\n ),\n }\n : {}),\n ...(runtimeEntitlements ? { runtimeEntitlements } : {}),\n telemetryDisabled: isTelemetryDisabled(),\n };\n\n return new Response(JSON.stringify(runtimeInfo), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (error) {\n return new Response(\n JSON.stringify({\n error: \"Failed to retrieve runtime information\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n\n/**\n * Report generative UI with the rules `configureAgentForRequest` uses to\n * attach the generative UI middlewares: it is on unless `generativeUI` is\n * `false`, and `{ agents }` limits it to those agents. The A2UI version of an\n * agent (`a2uiVersion`) does not change it: the client renders 1.0 for both,\n * as the runtime converts v0.9 surfaces. When the option is omitted, the\n * middlewares run only for a client that asks for them, so the client can\n * still turn generative UI on.\n */\nfunction resolveGenerativeUIInfo(\n runtime: CopilotKitRuntimeLike,\n webEnabled: boolean,\n): GenerativeUIRuntimeInfo {\n const generativeUI = runtime.generativeUI;\n if (!webEnabled || generativeUI === false) return { enabled: false };\n const agents =\n typeof generativeUI === \"object\" ? generativeUI.agents : undefined;\n return { enabled: true, ...(agents ? { agents } : {}) };\n}\n\nfunction resolveThreadEndpointInfo(\n runtime: CopilotKitRuntimeLike,\n threadEndpointsEnabled: boolean,\n): ThreadEndpointRuntimeInfo {\n // A local route is advertised only when the Thread access policy lets it\n // serve requests: without identity, list is refused by default while\n // reading a Thread by id is not.\n const available = (operation: \"list\" | \"read\") =>\n threadEndpointsEnabled &&\n (isIntelligenceRuntime(runtime) ||\n (supportsLocalThreadEndpoints(runtime.runner) &&\n isThreadOperationAvailable(runtime, operation)));\n const managedThreadMetadata =\n threadEndpointsEnabled && isIntelligenceRuntime(runtime);\n\n return {\n list: available(\"list\"),\n inspect: available(\"read\"),\n mutations: managedThreadMetadata,\n realtimeMetadata: managedThreadMetadata,\n };\n}\n"],"mappings":";;;;;;;;;AAoBA,SAAS,qBACP,gBACsB;AACtB,KAAI,CAAC,eAAgB,QAAO;CAC5B,MAAM,SAAS,eAAe,WAAW;AACzC,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,KAAI,OAAO,UAAU,UAAW,QAAO;AACvC,KAAI,OAAO,oBAAoB,UAAW,QAAO;AACjD,KAAI,OAAO,MAAO,QAAO;AACzB,KAAI,OAAO,oBAAoB,OAAQ,QAAO;AAC9C,QAAO;;;;;;;;;AAUT,SAAS,kCACP,gBACA,qBACsB;AACtB,KAAI,qBAAqB,WAAW,SAAS;AAC3C,MACE,oBAAoB,YAAY,WAAW,4BAC3C,oBAAoB,YAAY,WAC9B,kCAEF,QAAO,oBAAoB,YAAY,SAAS,UAAU;AAG5D,MAAI,oBAAoB,YAAY,OAClC,QAAO;;CAIX,MAAM,sBAAsB,qBAAqB,eAAe;AAChE,KACE,wBAAwB,UACxB,qBAAqB,WAAW,WAChC,qBAAqB,MAAM,UAE3B,QAAO;AAGT,QAAO;;;;;;;;;AAiBT,eAAe,2BACb,SACiD;AACjD,KAAI,CAACA,sCAAsB,QAAQ,CACjC;AAGF,KAAI;AACF,SAAO,MAAM,QAAQ,aAAa,wBAAwB;UACnD,OAAO;AACd,MAAI,iBAAiBC,uCAAwB,MAAM,cAAc,MAC/D,QAAO;GACL,QAAQ;GACR,OAAO;IACL,MAAM;IACN,SAAS;IACT,WAAW;IACZ;GACF;AAGH,SAAO;GACL,QAAQ;GACR,OAAO;IACL,MAAM;IACN,SAAS;IACT,WAAW;IACZ;GACF;;;AAIL,eAAsB,qBAAqB,EACzC,SACA,SACA,yBAA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C,QAAQ;GACjD,cAAc,wBAAwB,SAAS,WAAW;GAC1D,GAAIJ,sCAAsB,QAAQ,GAC9B,EACE,eAAe,kCACb,gBACA,oBACD,EACF,GACD,EAAE;GACN,GAAI,sBAAsB,EAAE,qBAAqB,GAAG,EAAE;GACtD,mBAAmBK,8CAAqB;GACzC;AAED,SAAO,IAAI,SAAS,KAAK,UAAU,YAAY,EAAE;GAC/C,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CAAC;UACK,OAAO;AACd,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;;;;;;;;;;;;AAaL,SAAS,wBACP,SACA,YACyB;CACzB,MAAM,eAAe,QAAQ;AAC7B,KAAI,CAAC,cAAc,iBAAiB,MAAO,QAAO,EAAE,SAAS,OAAO;CACpE,MAAM,SACJ,OAAO,iBAAiB,WAAW,aAAa,SAAS;AAC3D,QAAO;EAAE,SAAS;EAAM,GAAI,SAAS,EAAE,QAAQ,GAAG,EAAE;EAAG;;AAGzD,SAAS,0BACP,SACA,wBAC2B;CAI3B,MAAM,aAAa,cACjB,2BACCL,sCAAsB,QAAQ,IAC5BM,kDAA6B,QAAQ,OAAO,IAC3CC,iDAA2B,SAAS,UAAU;CACpD,MAAM,wBACJ,0BAA0BP,sCAAsB,QAAQ;AAE1D,QAAO;EACL,MAAM,UAAU,OAAO;EACvB,SAAS,UAAU,OAAO;EAC1B,WAAW;EACX,kBAAkB;EACnB"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { getRuntimeLogger } from "../core/logger.mjs";
|
|
1
2
|
import { supportsLocalThreadEndpoints } from "../runner/agent-runner.mjs";
|
|
2
3
|
import { hasLearningContainerConfiguration } from "../core/learning.mjs";
|
|
3
4
|
import { PlatformRequestError } from "../intelligence-platform/client.mjs";
|
|
4
5
|
import { isThreadOperationAvailable } from "./shared/thread-access.mjs";
|
|
5
6
|
import { isTelemetryDisabled } from "../telemetry/telemetry-client.mjs";
|
|
6
|
-
import { VERSION,
|
|
7
|
+
import { VERSION, isIntelligenceRuntime, resolveAgents } from "../core/runtime.mjs";
|
|
7
8
|
|
|
8
9
|
//#region src/runtime/handlers/get-runtime-info.ts
|
|
9
10
|
function resolveLicenseStatus(licenseChecker) {
|
|
@@ -72,7 +73,10 @@ async function handleGetRuntimeInfo({ runtime, request, threadEndpointsEnabled =
|
|
|
72
73
|
try {
|
|
73
74
|
capabilities = agent.getCapabilities ? await agent.getCapabilities() : void 0;
|
|
74
75
|
} catch (error) {
|
|
75
|
-
|
|
76
|
+
getRuntimeLogger(runtime).warn({
|
|
77
|
+
err: error,
|
|
78
|
+
agentId: name
|
|
79
|
+
}, `Failed to fetch capabilities for agent "${name}"`);
|
|
76
80
|
capabilities = void 0;
|
|
77
81
|
}
|
|
78
82
|
return [name, {
|
|
@@ -101,12 +105,8 @@ async function handleGetRuntimeInfo({ runtime, request, threadEndpointsEnabled =
|
|
|
101
105
|
inspectorMetadata: true,
|
|
102
106
|
...hasLearningContainerConfiguration(runtime) ? { inspectorLearning: true } : {}
|
|
103
107
|
} : {},
|
|
104
|
-
a2uiEnabled: webEnabled && isA2UIEnabled(runtime.a2ui),
|
|
105
|
-
...webEnabled && isA2UIEnabled(runtime.a2ui) ? { a2ui: {
|
|
106
|
-
enabled: true,
|
|
107
|
-
...runtime.a2ui.agents ? { agents: runtime.a2ui.agents } : {}
|
|
108
|
-
} } : {},
|
|
109
108
|
openGenerativeUIEnabled: webEnabled && !!runtime.openGenerativeUI,
|
|
109
|
+
generativeUI: resolveGenerativeUIInfo(runtime, webEnabled),
|
|
110
110
|
...isIntelligenceRuntime(runtime) ? { licenseStatus: resolveCompatibilityLicenseStatus(licenseChecker, runtimeEntitlements) } : {},
|
|
111
111
|
...runtimeEntitlements ? { runtimeEntitlements } : {},
|
|
112
112
|
telemetryDisabled: isTelemetryDisabled()
|
|
@@ -125,6 +125,24 @@ async function handleGetRuntimeInfo({ runtime, request, threadEndpointsEnabled =
|
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Report generative UI with the rules `configureAgentForRequest` uses to
|
|
130
|
+
* attach the generative UI middlewares: it is on unless `generativeUI` is
|
|
131
|
+
* `false`, and `{ agents }` limits it to those agents. The A2UI version of an
|
|
132
|
+
* agent (`a2uiVersion`) does not change it: the client renders 1.0 for both,
|
|
133
|
+
* as the runtime converts v0.9 surfaces. When the option is omitted, the
|
|
134
|
+
* middlewares run only for a client that asks for them, so the client can
|
|
135
|
+
* still turn generative UI on.
|
|
136
|
+
*/
|
|
137
|
+
function resolveGenerativeUIInfo(runtime, webEnabled) {
|
|
138
|
+
const generativeUI = runtime.generativeUI;
|
|
139
|
+
if (!webEnabled || generativeUI === false) return { enabled: false };
|
|
140
|
+
const agents = typeof generativeUI === "object" ? generativeUI.agents : void 0;
|
|
141
|
+
return {
|
|
142
|
+
enabled: true,
|
|
143
|
+
...agents ? { agents } : {}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
128
146
|
function resolveThreadEndpointInfo(runtime, threadEndpointsEnabled) {
|
|
129
147
|
const available = (operation) => threadEndpointsEnabled && (isIntelligenceRuntime(runtime) || supportsLocalThreadEndpoints(runtime.runner) && isThreadOperationAvailable(runtime, operation));
|
|
130
148
|
const managedThreadMetadata = threadEndpointsEnabled && isIntelligenceRuntime(runtime);
|