@copilotkit/shared 2.0.0-next.1 → 2.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +93 -12
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/a2ui-envelope.cjs +154 -0
- package/dist/a2ui-envelope.cjs.map +1 -0
- package/dist/a2ui-envelope.d.cts +101 -0
- package/dist/a2ui-envelope.d.cts.map +1 -0
- package/dist/a2ui-envelope.d.mts +101 -0
- package/dist/a2ui-envelope.d.mts.map +1 -0
- package/dist/a2ui-envelope.mjs +151 -0
- package/dist/a2ui-envelope.mjs.map +1 -0
- package/dist/a2ui-prompts.cjs +259 -0
- package/dist/a2ui-prompts.cjs.map +1 -0
- package/dist/a2ui-prompts.d.cts +79 -0
- package/dist/a2ui-prompts.d.cts.map +1 -0
- package/dist/a2ui-prompts.d.mts +79 -0
- package/dist/a2ui-prompts.d.mts.map +1 -0
- package/dist/a2ui-prompts.mjs +251 -0
- package/dist/a2ui-prompts.mjs.map +1 -0
- package/dist/attachments/content.cjs +17 -0
- package/dist/attachments/content.cjs.map +1 -0
- package/dist/attachments/content.d.cts +9 -0
- package/dist/attachments/content.d.cts.map +1 -0
- package/dist/attachments/content.d.mts +9 -0
- package/dist/attachments/content.d.mts.map +1 -0
- package/dist/attachments/content.mjs +16 -0
- package/dist/attachments/content.mjs.map +1 -0
- package/dist/attachments/types.d.cts +64 -0
- package/dist/attachments/types.d.cts.map +1 -0
- package/dist/attachments/types.d.mts +64 -0
- package/dist/attachments/types.d.mts.map +1 -0
- package/dist/attachments/utils.cjs +137 -0
- package/dist/attachments/utils.cjs.map +1 -0
- package/dist/attachments/utils.d.cts +44 -0
- package/dist/attachments/utils.d.cts.map +1 -0
- package/dist/attachments/utils.d.mts +44 -0
- package/dist/attachments/utils.d.mts.map +1 -0
- package/dist/attachments/utils.mjs +129 -0
- package/dist/attachments/utils.mjs.map +1 -0
- package/dist/constants/index.cjs +25 -0
- package/dist/constants/index.cjs.map +1 -0
- package/dist/constants/index.d.cts +17 -0
- package/dist/constants/index.d.cts.map +1 -0
- package/dist/constants/index.d.mts +17 -0
- package/dist/constants/index.d.mts.map +1 -0
- package/dist/constants/index.mjs +17 -12
- package/dist/constants/index.mjs.map +1 -1
- package/dist/debug-event-envelope.d.cts +13 -0
- package/dist/debug-event-envelope.d.cts.map +1 -0
- package/dist/debug-event-envelope.d.mts +13 -0
- package/dist/debug-event-envelope.d.mts.map +1 -0
- package/dist/debug.cjs +38 -0
- package/dist/debug.cjs.map +1 -0
- package/dist/debug.d.cts +29 -0
- package/dist/debug.d.cts.map +1 -0
- package/dist/debug.d.mts +29 -0
- package/dist/debug.d.mts.map +1 -0
- package/dist/debug.mjs +37 -0
- package/dist/debug.mjs.map +1 -0
- package/dist/event-transforms/index.cjs +15 -0
- package/dist/event-transforms/index.d.cts +4 -0
- package/dist/event-transforms/index.d.mts +4 -0
- package/dist/event-transforms/index.mjs +5 -0
- package/dist/event-transforms/open-generative-ui-middleware.cjs +286 -0
- package/dist/event-transforms/open-generative-ui-middleware.cjs.map +1 -0
- package/dist/event-transforms/open-generative-ui-middleware.d.cts +60 -0
- package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +1 -0
- package/dist/event-transforms/open-generative-ui-middleware.d.mts +60 -0
- package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +1 -0
- package/dist/event-transforms/open-generative-ui-middleware.mjs +283 -0
- package/dist/event-transforms/open-generative-ui-middleware.mjs.map +1 -0
- package/dist/event-transforms/recorded-events.cjs +59 -0
- package/dist/event-transforms/recorded-events.cjs.map +1 -0
- package/dist/event-transforms/recorded-events.d.cts +23 -0
- package/dist/event-transforms/recorded-events.d.cts.map +1 -0
- package/dist/event-transforms/recorded-events.d.mts +23 -0
- package/dist/event-transforms/recorded-events.d.mts.map +1 -0
- package/dist/event-transforms/recorded-events.mjs +58 -0
- package/dist/event-transforms/recorded-events.mjs.map +1 -0
- package/dist/finalize-events.cjs +186 -0
- package/dist/finalize-events.cjs.map +1 -0
- package/dist/finalize-events.d.cts +40 -0
- package/dist/finalize-events.d.cts.map +1 -0
- package/dist/finalize-events.d.mts +40 -0
- package/dist/finalize-events.d.mts.map +1 -0
- package/dist/finalize-events.mjs +184 -0
- package/dist/finalize-events.mjs.map +1 -0
- package/dist/generative-ui/basic-functions.cjs +177 -0
- package/dist/generative-ui/basic-functions.cjs.map +1 -0
- package/dist/generative-ui/basic-functions.d.cts +108 -0
- package/dist/generative-ui/basic-functions.d.cts.map +1 -0
- package/dist/generative-ui/basic-functions.d.mts +108 -0
- package/dist/generative-ui/basic-functions.d.mts.map +1 -0
- package/dist/generative-ui/basic-functions.mjs +167 -0
- package/dist/generative-ui/basic-functions.mjs.map +1 -0
- package/dist/generative-ui/child-refs.cjs +161 -0
- package/dist/generative-ui/child-refs.cjs.map +1 -0
- package/dist/generative-ui/child-refs.d.cts +68 -0
- package/dist/generative-ui/child-refs.d.cts.map +1 -0
- package/dist/generative-ui/child-refs.d.mts +68 -0
- package/dist/generative-ui/child-refs.d.mts.map +1 -0
- package/dist/generative-ui/child-refs.mjs +152 -0
- package/dist/generative-ui/child-refs.mjs.map +1 -0
- package/dist/generative-ui/is-record.cjs +10 -0
- package/dist/generative-ui/is-record.cjs.map +1 -0
- package/dist/generative-ui/is-record.mjs +9 -0
- package/dist/generative-ui/is-record.mjs.map +1 -0
- package/dist/generative-ui/prompt.cjs +91 -0
- package/dist/generative-ui/prompt.cjs.map +1 -0
- package/dist/generative-ui/prompt.d.cts +13 -0
- package/dist/generative-ui/prompt.d.cts.map +1 -0
- package/dist/generative-ui/prompt.d.mts +13 -0
- package/dist/generative-ui/prompt.d.mts.map +1 -0
- package/dist/generative-ui/prompt.mjs +90 -0
- package/dist/generative-ui/prompt.mjs.map +1 -0
- package/dist/generative-ui/render-ui-args.cjs +160 -0
- package/dist/generative-ui/render-ui-args.cjs.map +1 -0
- package/dist/generative-ui/render-ui-args.d.cts +40 -0
- package/dist/generative-ui/render-ui-args.d.cts.map +1 -0
- package/dist/generative-ui/render-ui-args.d.mts +40 -0
- package/dist/generative-ui/render-ui-args.d.mts.map +1 -0
- package/dist/generative-ui/render-ui-args.mjs +159 -0
- package/dist/generative-ui/render-ui-args.mjs.map +1 -0
- package/dist/generative-ui/types.cjs +101 -0
- package/dist/generative-ui/types.cjs.map +1 -0
- package/dist/generative-ui/types.d.cts +270 -0
- package/dist/generative-ui/types.d.cts.map +1 -0
- package/dist/generative-ui/types.d.mts +270 -0
- package/dist/generative-ui/types.d.mts.map +1 -0
- package/dist/generative-ui/types.mjs +86 -0
- package/dist/generative-ui/types.mjs.map +1 -0
- package/dist/generative-ui/validate-operation.cjs +405 -0
- package/dist/generative-ui/validate-operation.cjs.map +1 -0
- package/dist/generative-ui/validate-operation.d.cts +86 -0
- package/dist/generative-ui/validate-operation.d.cts.map +1 -0
- package/dist/generative-ui/validate-operation.d.mts +86 -0
- package/dist/generative-ui/validate-operation.d.mts.map +1 -0
- package/dist/generative-ui/validate-operation.mjs +399 -0
- package/dist/generative-ui/validate-operation.mjs.map +1 -0
- package/dist/index.cjs +233 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +80 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +80 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +78 -123
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +3979 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/intelligence-routing-fields.cjs +35 -0
- package/dist/intelligence-routing-fields.cjs.map +1 -0
- package/dist/intelligence-routing-fields.d.cts +18 -0
- package/dist/intelligence-routing-fields.d.cts.map +1 -0
- package/dist/intelligence-routing-fields.d.mts +18 -0
- package/dist/intelligence-routing-fields.d.mts.map +1 -0
- package/dist/intelligence-routing-fields.mjs +34 -0
- package/dist/intelligence-routing-fields.mjs.map +1 -0
- package/dist/logger.cjs +7 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +5 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs +6 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/open-generative-ui-prompts.cjs +8 -0
- package/dist/open-generative-ui-prompts.cjs.map +1 -0
- package/dist/open-generative-ui-prompts.d.cts +6 -0
- package/dist/open-generative-ui-prompts.d.cts.map +1 -0
- package/dist/open-generative-ui-prompts.d.mts +6 -0
- package/dist/open-generative-ui-prompts.d.mts.map +1 -0
- package/dist/open-generative-ui-prompts.mjs +7 -0
- package/dist/open-generative-ui-prompts.mjs.map +1 -0
- package/dist/package.cjs +12 -0
- package/dist/package.cjs.map +1 -0
- package/dist/package.mjs +6 -0
- package/dist/package.mjs.map +1 -0
- package/dist/standard-schema.cjs +31 -0
- package/dist/standard-schema.cjs.map +1 -0
- package/dist/standard-schema.d.cts +33 -0
- package/dist/standard-schema.d.cts.map +1 -0
- package/dist/standard-schema.d.mts +33 -0
- package/dist/standard-schema.d.mts.map +1 -0
- package/dist/standard-schema.mjs +30 -0
- package/dist/standard-schema.mjs.map +1 -0
- package/dist/telemetry/events.d.cts +72 -0
- package/dist/telemetry/events.d.cts.map +1 -0
- package/dist/telemetry/events.d.mts +72 -0
- package/dist/telemetry/events.d.mts.map +1 -0
- package/dist/telemetry/index.cjs +18 -0
- package/dist/telemetry/index.d.cts +5 -0
- package/dist/telemetry/index.d.mts +5 -0
- package/dist/telemetry/index.mjs +6 -12
- package/dist/telemetry/lambda-client.cjs +91 -0
- package/dist/telemetry/lambda-client.cjs.map +1 -0
- package/dist/telemetry/lambda-client.d.cts +31 -0
- package/dist/telemetry/lambda-client.d.cts.map +1 -0
- package/dist/telemetry/lambda-client.d.mts +31 -0
- package/dist/telemetry/lambda-client.d.mts.map +1 -0
- package/dist/telemetry/lambda-client.mjs +87 -0
- package/dist/telemetry/lambda-client.mjs.map +1 -0
- package/dist/telemetry/model-host.cjs +104 -0
- package/dist/telemetry/model-host.cjs.map +1 -0
- package/dist/telemetry/model-host.d.cts +26 -0
- package/dist/telemetry/model-host.d.cts.map +1 -0
- package/dist/telemetry/model-host.d.mts +26 -0
- package/dist/telemetry/model-host.d.mts.map +1 -0
- package/dist/telemetry/model-host.mjs +102 -0
- package/dist/telemetry/model-host.mjs.map +1 -0
- package/dist/telemetry/sampling.cjs +50 -0
- package/dist/telemetry/sampling.cjs.map +1 -0
- package/dist/telemetry/sampling.d.cts +57 -0
- package/dist/telemetry/sampling.d.cts.map +1 -0
- package/dist/telemetry/sampling.d.mts +57 -0
- package/dist/telemetry/sampling.d.mts.map +1 -0
- package/dist/telemetry/sampling.mjs +44 -0
- package/dist/telemetry/sampling.mjs.map +1 -0
- package/dist/telemetry/telemetry-client.cjs +165 -0
- package/dist/telemetry/telemetry-client.cjs.map +1 -0
- package/dist/telemetry/telemetry-client.d.cts +87 -0
- package/dist/telemetry/telemetry-client.d.cts.map +1 -0
- package/dist/telemetry/telemetry-client.d.mts +87 -0
- package/dist/telemetry/telemetry-client.d.mts.map +1 -0
- package/dist/telemetry/telemetry-client.mjs +162 -9
- package/dist/telemetry/telemetry-client.mjs.map +1 -1
- package/dist/telemetry/telemetry-disabled.cjs +20 -0
- package/dist/telemetry/telemetry-disabled.cjs.map +1 -0
- package/dist/telemetry/telemetry-disabled.d.cts +16 -0
- package/dist/telemetry/telemetry-disabled.d.cts.map +1 -0
- package/dist/telemetry/telemetry-disabled.d.mts +16 -0
- package/dist/telemetry/telemetry-disabled.d.mts.map +1 -0
- package/dist/telemetry/telemetry-disabled.mjs +19 -0
- package/dist/telemetry/telemetry-disabled.mjs.map +1 -0
- package/dist/telemetry/utils.cjs +14 -0
- package/dist/telemetry/utils.cjs.map +1 -0
- package/dist/telemetry/utils.mjs +12 -8
- package/dist/telemetry/utils.mjs.map +1 -1
- package/dist/transcription-errors.cjs +84 -0
- package/dist/transcription-errors.cjs.map +1 -0
- package/dist/transcription-errors.d.cts +52 -0
- package/dist/transcription-errors.d.cts.map +1 -0
- package/dist/transcription-errors.d.mts +52 -0
- package/dist/transcription-errors.d.mts.map +1 -0
- package/dist/transcription-errors.mjs +82 -0
- package/dist/transcription-errors.mjs.map +1 -0
- package/dist/types/{action.d.ts → action.d.cts} +32 -32
- package/dist/types/action.d.cts.map +1 -0
- package/dist/types/action.d.mts +59 -0
- package/dist/types/action.d.mts.map +1 -0
- package/dist/types/copilot-cloud-config.d.cts +15 -0
- package/dist/types/copilot-cloud-config.d.cts.map +1 -0
- package/dist/types/copilot-cloud-config.d.mts +15 -0
- package/dist/types/copilot-cloud-config.d.mts.map +1 -0
- package/dist/types/error.d.cts +57 -0
- package/dist/types/error.d.cts.map +1 -0
- package/dist/types/error.d.mts +57 -0
- package/dist/types/error.d.mts.map +1 -0
- package/dist/types/message.d.cts +42 -0
- package/dist/types/message.d.cts.map +1 -0
- package/dist/types/message.d.mts +42 -0
- package/dist/types/message.d.mts.map +1 -0
- package/dist/types/openai-assistant.d.cts +55 -0
- package/dist/types/openai-assistant.d.cts.map +1 -0
- package/dist/types/openai-assistant.d.mts +55 -0
- package/dist/types/openai-assistant.d.mts.map +1 -0
- package/dist/types/utility.d.cts +6 -0
- package/dist/types/utility.d.cts.map +1 -0
- package/dist/types/utility.d.mts +6 -0
- package/dist/types/utility.d.mts.map +1 -0
- package/dist/utils/clipboard.cjs +28 -0
- package/dist/utils/clipboard.cjs.map +1 -0
- package/dist/utils/clipboard.d.cts +14 -0
- package/dist/utils/clipboard.d.cts.map +1 -0
- package/dist/utils/clipboard.d.mts +14 -0
- package/dist/utils/clipboard.d.mts.map +1 -0
- package/dist/utils/clipboard.mjs +27 -0
- package/dist/utils/clipboard.mjs.map +1 -0
- package/dist/utils/conditions.cjs +32 -0
- package/dist/utils/conditions.cjs.map +1 -0
- package/dist/utils/{conditions.d.ts → conditions.d.cts} +16 -11
- package/dist/utils/conditions.d.cts.map +1 -0
- package/dist/utils/conditions.d.mts +31 -0
- package/dist/utils/conditions.d.mts.map +1 -0
- package/dist/utils/conditions.mjs +30 -6
- package/dist/utils/conditions.mjs.map +1 -1
- package/dist/utils/console-styling.cjs +91 -0
- package/dist/utils/console-styling.cjs.map +1 -0
- package/dist/utils/console-styling.d.cts +65 -0
- package/dist/utils/console-styling.d.cts.map +1 -0
- package/dist/utils/console-styling.d.mts +65 -0
- package/dist/utils/console-styling.d.mts.map +1 -0
- package/dist/utils/console-styling.mjs +83 -15
- package/dist/utils/console-styling.mjs.map +1 -1
- package/dist/utils/dashboard-url.cjs +19 -0
- package/dist/utils/dashboard-url.cjs.map +1 -0
- package/dist/utils/dashboard-url.mjs +18 -0
- package/dist/utils/dashboard-url.mjs.map +1 -0
- package/dist/utils/errors.cjs +439 -0
- package/dist/utils/errors.cjs.map +1 -0
- package/dist/utils/{errors.d.ts → errors.d.cts} +188 -156
- package/dist/utils/errors.d.cts.map +1 -0
- package/dist/utils/errors.d.mts +312 -0
- package/dist/utils/errors.d.mts.map +1 -0
- package/dist/utils/errors.mjs +416 -63
- package/dist/utils/errors.mjs.map +1 -1
- package/dist/utils/index.cjs +105 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +58 -0
- package/dist/utils/index.d.cts.map +1 -0
- package/dist/utils/index.d.mts +58 -0
- package/dist/utils/index.d.mts.map +1 -0
- package/dist/utils/index.mjs +97 -107
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/inspector-learning.cjs +217 -0
- package/dist/utils/inspector-learning.cjs.map +1 -0
- package/dist/utils/inspector-learning.d.cts +104 -0
- package/dist/utils/inspector-learning.d.cts.map +1 -0
- package/dist/utils/inspector-learning.d.mts +104 -0
- package/dist/utils/inspector-learning.d.mts.map +1 -0
- package/dist/utils/inspector-learning.mjs +215 -0
- package/dist/utils/inspector-learning.mjs.map +1 -0
- package/dist/utils/inspector-metadata.cjs +146 -0
- package/dist/utils/inspector-metadata.cjs.map +1 -0
- package/dist/utils/inspector-metadata.d.cts +55 -0
- package/dist/utils/inspector-metadata.d.cts.map +1 -0
- package/dist/utils/inspector-metadata.d.mts +55 -0
- package/dist/utils/inspector-metadata.d.mts.map +1 -0
- package/dist/utils/inspector-metadata.mjs +146 -0
- package/dist/utils/inspector-metadata.mjs.map +1 -0
- package/dist/utils/inspector-visibility.cjs +13 -0
- package/dist/utils/inspector-visibility.cjs.map +1 -0
- package/dist/utils/inspector-visibility.d.cts +18 -0
- package/dist/utils/inspector-visibility.d.cts.map +1 -0
- package/dist/utils/inspector-visibility.d.mts +18 -0
- package/dist/utils/inspector-visibility.d.mts.map +1 -0
- package/dist/utils/inspector-visibility.mjs +12 -0
- package/dist/utils/inspector-visibility.mjs.map +1 -0
- package/dist/utils/json-schema.cjs +215 -0
- package/dist/utils/json-schema.cjs.map +1 -0
- package/dist/utils/{json-schema.d.ts → json-schema.d.cts} +20 -18
- package/dist/utils/json-schema.d.cts.map +1 -0
- package/dist/utils/json-schema.d.mts +36 -0
- package/dist/utils/json-schema.d.mts.map +1 -0
- package/dist/utils/json-schema.mjs +210 -12
- package/dist/utils/json-schema.mjs.map +1 -1
- package/dist/utils/random-id.cjs +38 -0
- package/dist/utils/random-id.cjs.map +1 -0
- package/dist/utils/{random-id.d.ts → random-id.d.cts} +3 -1
- package/dist/utils/random-id.d.cts.map +1 -0
- package/dist/utils/random-id.d.mts +8 -0
- package/dist/utils/random-id.d.mts.map +1 -0
- package/dist/utils/random-id.mjs +33 -12
- package/dist/utils/random-id.mjs.map +1 -1
- package/dist/utils/requests.cjs +58 -0
- package/dist/utils/requests.cjs.map +1 -0
- package/dist/utils/{requests.d.ts → requests.d.cts} +3 -1
- package/dist/utils/requests.d.cts.map +1 -0
- package/dist/utils/requests.d.mts +12 -0
- package/dist/utils/requests.d.mts.map +1 -0
- package/dist/utils/requests.mjs +56 -6
- package/dist/utils/requests.mjs.map +1 -1
- package/dist/utils/row-render-keys.cjs +206 -0
- package/dist/utils/row-render-keys.cjs.map +1 -0
- package/dist/utils/row-render-keys.d.cts +65 -0
- package/dist/utils/row-render-keys.d.cts.map +1 -0
- package/dist/utils/row-render-keys.d.mts +65 -0
- package/dist/utils/row-render-keys.d.mts.map +1 -0
- package/dist/utils/row-render-keys.mjs +201 -0
- package/dist/utils/row-render-keys.mjs.map +1 -0
- package/dist/utils/types.cjs +9 -0
- package/dist/utils/types.cjs.map +1 -0
- package/dist/utils/types.d.cts +122 -0
- package/dist/utils/types.d.cts.map +1 -0
- package/dist/utils/types.d.mts +122 -0
- package/dist/utils/types.d.mts.map +1 -0
- package/dist/utils/types.mjs +6 -1
- package/dist/utils/types.mjs.map +1 -1
- package/package.json +74 -40
- package/scripts/verify-cjs-exports.cjs +16 -0
- package/src/__tests__/a2ui-envelope.test.ts +434 -0
- package/src/__tests__/a2ui-prompts.test.ts +362 -0
- package/src/__tests__/debug.test.ts +116 -0
- package/src/__tests__/license-context.test.ts +253 -0
- package/src/__tests__/root-entry-browser-safety.test.ts +91 -0
- package/src/__tests__/standard-schema-types.test.ts +144 -0
- package/src/__tests__/standard-schema.test.ts +359 -0
- package/src/__tests__/zod-regression.test.ts +319 -0
- package/src/a2ui-envelope.ts +309 -0
- package/src/a2ui-prompts.ts +322 -0
- package/src/attachments/__tests__/utils.test.ts +214 -0
- package/src/attachments/content.test.ts +48 -0
- package/src/attachments/content.ts +16 -0
- package/src/attachments/index.ts +21 -0
- package/src/attachments/types.ts +77 -0
- package/src/attachments/utils.ts +169 -0
- package/src/constants/index.ts +14 -1
- package/src/debug-event-envelope.ts +9 -0
- package/src/debug.ts +55 -0
- package/src/event-transforms/index.ts +5 -0
- package/src/event-transforms/open-generative-ui-middleware.ts +392 -0
- package/src/event-transforms/recorded-events.test.ts +166 -0
- package/src/event-transforms/recorded-events.ts +74 -0
- package/src/finalize-events.test.ts +284 -0
- package/src/finalize-events.ts +260 -0
- package/src/generative-ui/__tests__/render-ui-args.test.ts +175 -0
- package/src/generative-ui/__tests__/validate-operation.test.ts +977 -0
- package/src/generative-ui/basic-functions.ts +282 -0
- package/src/generative-ui/child-refs.ts +210 -0
- package/src/generative-ui/index.ts +6 -0
- package/src/generative-ui/is-record.ts +4 -0
- package/src/generative-ui/prompt.ts +174 -0
- package/src/generative-ui/render-ui-args.ts +199 -0
- package/src/generative-ui/types.ts +314 -0
- package/src/generative-ui/validate-operation.ts +723 -0
- package/src/index.ts +190 -1
- package/src/intelligence-routing-fields.test.ts +51 -0
- package/src/intelligence-routing-fields.ts +40 -0
- package/src/logger.ts +1 -0
- package/src/open-generative-ui-prompts.ts +20 -0
- package/src/standard-schema.ts +82 -0
- package/src/telemetry/events.ts +37 -10
- package/src/telemetry/index.ts +8 -0
- package/src/telemetry/lambda-client.test.ts +446 -0
- package/src/telemetry/lambda-client.ts +194 -0
- package/src/telemetry/model-host.test.ts +145 -0
- package/src/telemetry/model-host.ts +156 -0
- package/src/telemetry/sampling.test.ts +65 -0
- package/src/telemetry/sampling.ts +103 -0
- package/src/telemetry/telemetry-blank-license-identity.test.ts +128 -0
- package/src/telemetry/telemetry-client.test.ts +798 -0
- package/src/telemetry/telemetry-client.ts +223 -37
- package/src/telemetry/telemetry-disabled.ts +22 -0
- package/src/telemetry/utils.ts +0 -24
- package/src/transcription-errors.ts +99 -0
- package/src/types/__tests__/message.test.ts +62 -0
- package/src/types/action.ts +9 -5
- package/src/types/error.ts +11 -2
- package/src/types/message.ts +33 -5
- package/src/types/openai-assistant.ts +6 -2
- package/src/utils/__tests__/clipboard.test.ts +87 -0
- package/src/utils/__tests__/conditions.test.ts +161 -0
- package/src/utils/__tests__/json-schema.test.ts +812 -0
- package/src/utils/__tests__/row-render-keys.test.ts +388 -0
- package/src/utils/clipboard.ts +23 -0
- package/src/utils/conditions.ts +27 -9
- package/src/utils/console-styling.ts +10 -8
- package/src/utils/dashboard-url.ts +17 -0
- package/src/utils/errors.ts +55 -22
- package/src/utils/index.ts +70 -1
- package/src/utils/inspector-learning.test.ts +423 -0
- package/src/utils/inspector-learning.ts +523 -0
- package/src/utils/inspector-metadata.test.ts +743 -0
- package/src/utils/inspector-metadata.ts +263 -0
- package/src/utils/inspector-visibility.test.ts +43 -0
- package/src/utils/inspector-visibility.ts +17 -0
- package/src/utils/json-schema.ts +156 -12
- package/src/utils/random-id.ts +5 -2
- package/src/utils/requests.ts +3 -1
- package/src/utils/row-render-keys.ts +263 -0
- package/src/utils/types.ts +128 -1
- package/src/utils.test.ts +137 -0
- package/tsconfig.json +10 -2
- package/tsdown.config.ts +49 -0
- package/vitest.config.mjs +11 -0
- package/CHANGELOG.md +0 -1817
- package/dist/chunk-2OJ5OJ2D.mjs +0 -1
- package/dist/chunk-2OJ5OJ2D.mjs.map +0 -1
- package/dist/chunk-64DYJ27R.mjs +0 -201
- package/dist/chunk-64DYJ27R.mjs.map +0 -1
- package/dist/chunk-6QGXWNS5.mjs +0 -34
- package/dist/chunk-6QGXWNS5.mjs.map +0 -1
- package/dist/chunk-6W2UEO2M.mjs +0 -94
- package/dist/chunk-6W2UEO2M.mjs.map +0 -1
- package/dist/chunk-7DJDTRNX.mjs +0 -426
- package/dist/chunk-7DJDTRNX.mjs.map +0 -1
- package/dist/chunk-A66772CV.mjs +0 -107
- package/dist/chunk-A66772CV.mjs.map +0 -1
- package/dist/chunk-BOKE4OKY.mjs +0 -41
- package/dist/chunk-BOKE4OKY.mjs.map +0 -1
- package/dist/chunk-FCCOSO5L.mjs +0 -1
- package/dist/chunk-FCCOSO5L.mjs.map +0 -1
- package/dist/chunk-GYZIHHE6.mjs +0 -13
- package/dist/chunk-GYZIHHE6.mjs.map +0 -1
- package/dist/chunk-IAFBVORQ.mjs +0 -1
- package/dist/chunk-IAFBVORQ.mjs.map +0 -1
- package/dist/chunk-JAAUCDUR.mjs +0 -38
- package/dist/chunk-JAAUCDUR.mjs.map +0 -1
- package/dist/chunk-MSUB6DGR.mjs +0 -1
- package/dist/chunk-MSUB6DGR.mjs.map +0 -1
- package/dist/chunk-N5EP5OD5.mjs +0 -1
- package/dist/chunk-N5EP5OD5.mjs.map +0 -1
- package/dist/chunk-NAFEBKSO.mjs +0 -1
- package/dist/chunk-NAFEBKSO.mjs.map +0 -1
- package/dist/chunk-P7STFMPO.mjs +0 -1
- package/dist/chunk-P7STFMPO.mjs.map +0 -1
- package/dist/chunk-PL5WNHFZ.mjs +0 -50
- package/dist/chunk-PL5WNHFZ.mjs.map +0 -1
- package/dist/chunk-UYARLQNA.mjs +0 -1
- package/dist/chunk-UYARLQNA.mjs.map +0 -1
- package/dist/chunk-XEMZTHQZ.mjs +0 -67
- package/dist/chunk-XEMZTHQZ.mjs.map +0 -1
- package/dist/chunk-XTHC46M2.mjs +0 -1
- package/dist/chunk-XTHC46M2.mjs.map +0 -1
- package/dist/constants/index.d.ts +0 -6
- package/dist/constants/index.js +0 -40
- package/dist/constants/index.js.map +0 -1
- package/dist/index.d.ts +0 -25
- package/dist/index.js +0 -1098
- package/dist/index.js.map +0 -1
- package/dist/telemetry/events.d.ts +0 -45
- package/dist/telemetry/events.js +0 -19
- package/dist/telemetry/events.js.map +0 -1
- package/dist/telemetry/events.mjs +0 -1
- package/dist/telemetry/events.mjs.map +0 -1
- package/dist/telemetry/index.d.ts +0 -3
- package/dist/telemetry/index.js +0 -188
- package/dist/telemetry/index.js.map +0 -1
- package/dist/telemetry/index.mjs.map +0 -1
- package/dist/telemetry/scarf-client.d.ts +0 -7
- package/dist/telemetry/scarf-client.js +0 -59
- package/dist/telemetry/scarf-client.js.map +0 -1
- package/dist/telemetry/scarf-client.mjs +0 -7
- package/dist/telemetry/scarf-client.mjs.map +0 -1
- package/dist/telemetry/security-check.d.ts +0 -2
- package/dist/telemetry/security-check.js +0 -2
- package/dist/telemetry/security-check.js.map +0 -1
- package/dist/telemetry/security-check.mjs +0 -1
- package/dist/telemetry/security-check.mjs.map +0 -1
- package/dist/telemetry/telemetry-client.d.ts +0 -40
- package/dist/telemetry/telemetry-client.js +0 -186
- package/dist/telemetry/telemetry-client.js.map +0 -1
- package/dist/telemetry/utils.d.ts +0 -8
- package/dist/telemetry/utils.js +0 -69
- package/dist/telemetry/utils.js.map +0 -1
- package/dist/types/action.js +0 -19
- package/dist/types/action.js.map +0 -1
- package/dist/types/action.mjs +0 -2
- package/dist/types/action.mjs.map +0 -1
- package/dist/types/copilot-cloud-config.d.ts +0 -13
- package/dist/types/copilot-cloud-config.js +0 -19
- package/dist/types/copilot-cloud-config.js.map +0 -1
- package/dist/types/copilot-cloud-config.mjs +0 -2
- package/dist/types/copilot-cloud-config.mjs.map +0 -1
- package/dist/types/error.d.ts +0 -55
- package/dist/types/error.js +0 -19
- package/dist/types/error.js.map +0 -1
- package/dist/types/error.mjs +0 -2
- package/dist/types/error.mjs.map +0 -1
- package/dist/types/index.d.ts +0 -7
- package/dist/types/index.js +0 -19
- package/dist/types/index.js.map +0 -1
- package/dist/types/index.mjs +0 -8
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/message.d.ts +0 -26
- package/dist/types/message.js +0 -19
- package/dist/types/message.js.map +0 -1
- package/dist/types/message.mjs +0 -2
- package/dist/types/message.mjs.map +0 -1
- package/dist/types/openai-assistant.d.ts +0 -53
- package/dist/types/openai-assistant.js +0 -19
- package/dist/types/openai-assistant.js.map +0 -1
- package/dist/types/openai-assistant.mjs +0 -2
- package/dist/types/openai-assistant.mjs.map +0 -1
- package/dist/types/utility.d.ts +0 -6
- package/dist/types/utility.js +0 -19
- package/dist/types/utility.js.map +0 -1
- package/dist/types/utility.mjs +0 -2
- package/dist/types/utility.mjs.map +0 -1
- package/dist/utils/conditions.js +0 -74
- package/dist/utils/conditions.js.map +0 -1
- package/dist/utils/console-styling.d.ts +0 -84
- package/dist/utils/console-styling.js +0 -123
- package/dist/utils/console-styling.js.map +0 -1
- package/dist/utils/errors.js +0 -443
- package/dist/utils/errors.js.map +0 -1
- package/dist/utils/index.d.ts +0 -32
- package/dist/utils/index.js +0 -927
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/json-schema.js +0 -228
- package/dist/utils/json-schema.js.map +0 -1
- package/dist/utils/random-id.js +0 -68
- package/dist/utils/random-id.js.map +0 -1
- package/dist/utils/requests.js +0 -91
- package/dist/utils/requests.js.map +0 -1
- package/dist/utils/types.d.ts +0 -20
- package/dist/utils/types.js +0 -19
- package/dist/utils/types.js.map +0 -1
- package/jest.config.js +0 -5
- package/src/telemetry/scarf-client.ts +0 -39
- package/src/telemetry/security-check.ts +0 -0
- package/src/utils/json-schema.test.ts +0 -383
- package/tsup.config.ts +0 -11
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The generative UI envelope that the client sends on every run as
|
|
3
|
+
* `forwardedProps.copilotkit.ui`. It has the A2UI v1.0 renderer capabilities
|
|
4
|
+
* shape, so a backend that speaks A2UI v1.0 can read the catalog as it is.
|
|
5
|
+
* CopilotKit data goes in `metadata.extensions`, under `copilotkit_` keys.
|
|
6
|
+
* The runtime reads it to pick the transport and to build the guide.
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
GENERATIVE_UI_MAX_REJECTION_LENGTH,
|
|
10
|
+
GENERATIVE_UI_MAX_SUMMARY_REJECTIONS,
|
|
11
|
+
GENERATIVE_UI_MAX_TARGET_COMPONENTS,
|
|
12
|
+
} from "./generative-ui/types";
|
|
13
|
+
import type {
|
|
14
|
+
A2UIActionMessage,
|
|
15
|
+
GenerativeUIComponentManifest,
|
|
16
|
+
GenerativeUIFunctionManifest,
|
|
17
|
+
GenerativeUIManifest,
|
|
18
|
+
GenerativeUISurfaceSummary,
|
|
19
|
+
GenerativeUITarget,
|
|
20
|
+
} from "./generative-ui/types";
|
|
21
|
+
import { isRecord } from "./generative-ui/is-record";
|
|
22
|
+
|
|
23
|
+
/** Top-level `forwardedProps` key that holds the CopilotKit run properties. */
|
|
24
|
+
export const COPILOTKIT_FORWARDED_PROPS_KEY = "copilotkit";
|
|
25
|
+
|
|
26
|
+
/** Version of the envelope shape (not of the UI protocol that it carries). */
|
|
27
|
+
export const COPILOTKIT_UI_ENVELOPE_FORMAT = 3;
|
|
28
|
+
|
|
29
|
+
/** What the client renders and calls, and how the model must write UI. */
|
|
30
|
+
export interface CopilotKitUIEnvelope {
|
|
31
|
+
/** The A2UI v1.0 renderer capabilities. */
|
|
32
|
+
"v1.0": {
|
|
33
|
+
/**
|
|
34
|
+
* The catalog that the client renders comes first, then the catalogs of
|
|
35
|
+
* its `extends`. An operation can name any of them.
|
|
36
|
+
*/
|
|
37
|
+
supportedCatalogIds: string[];
|
|
38
|
+
inlineCatalogs?: Array<{
|
|
39
|
+
catalogId: string;
|
|
40
|
+
protocolVersion: "1.0";
|
|
41
|
+
/** Not there when the client is set up with `includeCatalog: false`. */
|
|
42
|
+
components?: Record<string, GenerativeUIComponentManifest>;
|
|
43
|
+
/** The app functions that are mounted now. */
|
|
44
|
+
functions: Record<string, GenerativeUIFunctionManifest>;
|
|
45
|
+
/** The markdown guideline. Only the markdown transport sends it. */
|
|
46
|
+
instructions?: string;
|
|
47
|
+
}>;
|
|
48
|
+
};
|
|
49
|
+
metadata: {
|
|
50
|
+
extensions: {
|
|
51
|
+
/** Envelope shape version. */
|
|
52
|
+
copilotkit_format: typeof COPILOTKIT_UI_ENVELOPE_FORMAT;
|
|
53
|
+
/** "tool": the model calls the render tool. "markdown": the model writes ```a2ui fences. */
|
|
54
|
+
copilotkit_transport: "tool" | "markdown";
|
|
55
|
+
copilotkit_targets: GenerativeUIManifest["targets"];
|
|
56
|
+
copilotkit_surfaces: GenerativeUIManifest["surfaces"];
|
|
57
|
+
/** True when the client also sent the guide as context entries on this run. */
|
|
58
|
+
copilotkit_contextSent: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* The A2UI action that started this run, when a user event did: the
|
|
61
|
+
* structured form of the user message that the event added.
|
|
62
|
+
*/
|
|
63
|
+
copilotkit_action?: A2UIActionMessage;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
type InlineCatalog = NonNullable<
|
|
69
|
+
CopilotKitUIEnvelope["v1.0"]["inlineCatalogs"]
|
|
70
|
+
>[number];
|
|
71
|
+
type Extensions = CopilotKitUIEnvelope["metadata"]["extensions"];
|
|
72
|
+
|
|
73
|
+
function isOptionalString(value: unknown) {
|
|
74
|
+
return value === undefined || typeof value === "string";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isNonEmptyString(value: unknown): value is string {
|
|
78
|
+
return typeof value === "string" && value !== "";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function isRecordOf<T>(
|
|
82
|
+
value: unknown,
|
|
83
|
+
isEntry: (entry: unknown) => entry is T,
|
|
84
|
+
): value is Record<string, T> {
|
|
85
|
+
return isRecord(value) && Object.values(value).every(isEntry);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** A function, or an event of a component: a description and a parameter schema. */
|
|
89
|
+
function isSchemaEntry(value: unknown): value is GenerativeUIFunctionManifest {
|
|
90
|
+
return (
|
|
91
|
+
isRecord(value) &&
|
|
92
|
+
isRecord(value.parameters) &&
|
|
93
|
+
isOptionalString(value.description)
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function isSlotKind(value: unknown): value is "single" | "multiple" {
|
|
98
|
+
return value === "single" || value === "multiple";
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* `validateOperation` reads `properties` and `required` of a props schema,
|
|
103
|
+
* so those two must have the right shape when they are there.
|
|
104
|
+
*/
|
|
105
|
+
function isPropsSchema(value: unknown): value is Record<string, unknown> {
|
|
106
|
+
return (
|
|
107
|
+
isRecord(value) &&
|
|
108
|
+
(value.properties === undefined || isRecord(value.properties)) &&
|
|
109
|
+
(value.required === undefined ||
|
|
110
|
+
(Array.isArray(value.required) &&
|
|
111
|
+
value.required.every((name) => typeof name === "string")))
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function isComponentManifest(
|
|
116
|
+
value: unknown,
|
|
117
|
+
): value is GenerativeUIComponentManifest {
|
|
118
|
+
if (
|
|
119
|
+
!isRecord(value) ||
|
|
120
|
+
!isPropsSchema(value.props) ||
|
|
121
|
+
!isOptionalString(value.description) ||
|
|
122
|
+
(value.events !== undefined && !isRecordOf(value.events, isSchemaEntry)) ||
|
|
123
|
+
(value.slots !== undefined && !isRecordOf(value.slots, isSlotKind))
|
|
124
|
+
)
|
|
125
|
+
return false;
|
|
126
|
+
const order = value.parameterOrder;
|
|
127
|
+
if (order === undefined) return true;
|
|
128
|
+
const keys = new Set([
|
|
129
|
+
...Object.keys(value.props.properties ?? {}),
|
|
130
|
+
...Object.keys(value.slots ?? {}),
|
|
131
|
+
...Object.keys(value.events ?? {}),
|
|
132
|
+
]);
|
|
133
|
+
return (
|
|
134
|
+
Array.isArray(order) &&
|
|
135
|
+
new Set(order).size === order.length &&
|
|
136
|
+
order.every((key) => typeof key === "string" && keys.has(key))
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function isInlineCatalog(value: unknown): value is InlineCatalog {
|
|
141
|
+
return (
|
|
142
|
+
isRecord(value) &&
|
|
143
|
+
isNonEmptyString(value.catalogId) &&
|
|
144
|
+
value.protocolVersion === "1.0" &&
|
|
145
|
+
(value.components === undefined ||
|
|
146
|
+
isRecordOf(value.components, isComponentManifest)) &&
|
|
147
|
+
isRecordOf(value.functions, isSchemaEntry) &&
|
|
148
|
+
isOptionalString(value.instructions)
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function isCapabilities(value: unknown): value is CopilotKitUIEnvelope["v1.0"] {
|
|
153
|
+
return (
|
|
154
|
+
isRecord(value) &&
|
|
155
|
+
Array.isArray(value.supportedCatalogIds) &&
|
|
156
|
+
value.supportedCatalogIds.length > 0 &&
|
|
157
|
+
value.supportedCatalogIds.every(isNonEmptyString) &&
|
|
158
|
+
(value.inlineCatalogs === undefined ||
|
|
159
|
+
(Array.isArray(value.inlineCatalogs) &&
|
|
160
|
+
value.inlineCatalogs.every(isInlineCatalog)))
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** A short list of component names. */
|
|
165
|
+
function isComponentNameList(value: unknown): value is string[] {
|
|
166
|
+
return (
|
|
167
|
+
Array.isArray(value) &&
|
|
168
|
+
value.length <= GENERATIVE_UI_MAX_TARGET_COMPONENTS &&
|
|
169
|
+
value.every(isNonEmptyString)
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function isTarget(value: unknown): value is GenerativeUITarget {
|
|
174
|
+
return (
|
|
175
|
+
isRecord(value) &&
|
|
176
|
+
isNonEmptyString(value.id) &&
|
|
177
|
+
(value.kind === "chat" || value.kind === "inline") &&
|
|
178
|
+
isOptionalString(value.description) &&
|
|
179
|
+
(value.components === undefined || isComponentNameList(value.components))
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** A short list of short strings. The summary limits keep the guide small. */
|
|
184
|
+
function isRejectionList(value: unknown): value is string[] {
|
|
185
|
+
return (
|
|
186
|
+
Array.isArray(value) &&
|
|
187
|
+
value.length <= GENERATIVE_UI_MAX_SUMMARY_REJECTIONS &&
|
|
188
|
+
value.every(
|
|
189
|
+
(entry) =>
|
|
190
|
+
typeof entry === "string" &&
|
|
191
|
+
entry.length <= GENERATIVE_UI_MAX_REJECTION_LENGTH,
|
|
192
|
+
)
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function isSurfaceEntry(value: unknown): value is GenerativeUISurfaceSummary {
|
|
197
|
+
return (
|
|
198
|
+
isRecord(value) &&
|
|
199
|
+
isNonEmptyString(value.target) &&
|
|
200
|
+
(value.dataModel === undefined || isRecord(value.dataModel)) &&
|
|
201
|
+
(value.rejected === undefined || isRejectionList(value.rejected)) &&
|
|
202
|
+
(value.status === undefined ||
|
|
203
|
+
value.status === "deleted" ||
|
|
204
|
+
value.status === "failed")
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Checks the `copilotkit_` keys only. Other extensions can be there too. */
|
|
209
|
+
function isExtensions(value: unknown): value is Extensions {
|
|
210
|
+
return (
|
|
211
|
+
isRecord(value) &&
|
|
212
|
+
value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT &&
|
|
213
|
+
(value.copilotkit_transport === "tool" ||
|
|
214
|
+
value.copilotkit_transport === "markdown") &&
|
|
215
|
+
Array.isArray(value.copilotkit_targets) &&
|
|
216
|
+
value.copilotkit_targets.every(isTarget) &&
|
|
217
|
+
isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) &&
|
|
218
|
+
typeof value.copilotkit_contextSent === "boolean"
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function isEnvelope(value: unknown): value is CopilotKitUIEnvelope {
|
|
223
|
+
return (
|
|
224
|
+
isRecord(value) &&
|
|
225
|
+
isCapabilities(value["v1.0"]) &&
|
|
226
|
+
isRecord(value.metadata) &&
|
|
227
|
+
isExtensions(value.metadata.extensions)
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Reads the generative UI envelope from the `forwardedProps` of a run.
|
|
233
|
+
*
|
|
234
|
+
* The envelope comes from the client, so it is not trusted: every field is
|
|
235
|
+
* checked. Returns `undefined` when the envelope is not there, or when it is
|
|
236
|
+
* malformed (for example a wrong `copilotkit_format` or
|
|
237
|
+
* `copilotkit_transport`, or no catalog id).
|
|
238
|
+
*
|
|
239
|
+
* @param forwardedProps - The `forwardedProps` of the run input.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* const envelope = readCopilotKitUIEnvelope(input.forwardedProps);
|
|
244
|
+
* if (envelope?.metadata.extensions.copilotkit_transport === "markdown") {
|
|
245
|
+
* // The model writes ```a2ui fences. Add no render tool.
|
|
246
|
+
* }
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
export function readCopilotKitUIEnvelope(forwardedProps: unknown) {
|
|
250
|
+
if (!isRecord(forwardedProps)) return undefined;
|
|
251
|
+
const namespace = forwardedProps[COPILOTKIT_FORWARDED_PROPS_KEY];
|
|
252
|
+
if (!isRecord(namespace)) return undefined;
|
|
253
|
+
const envelope = namespace.ui;
|
|
254
|
+
return isEnvelope(envelope) ? envelope : undefined;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Turns an envelope into the manifest that the runtime and the prompts use.
|
|
259
|
+
*
|
|
260
|
+
* The catalog is the first of `supportedCatalogIds`, and `catalogIds` lists
|
|
261
|
+
* all of them. The components, functions, and instructions come from the
|
|
262
|
+
* inline catalog of the first id.
|
|
263
|
+
* With no such inline catalog, there are no components and no functions.
|
|
264
|
+
*
|
|
265
|
+
* The result also has:
|
|
266
|
+
* - `transport` and `contextSent`, from the extensions.
|
|
267
|
+
* - `instructions`, when the inline catalog has them.
|
|
268
|
+
* - `hasComponents`: false when the client left the component schemas out.
|
|
269
|
+
* The runtime cannot check operations without them.
|
|
270
|
+
* - `action`: the A2UI action message of the user event that started the
|
|
271
|
+
* run, when one did.
|
|
272
|
+
*
|
|
273
|
+
* @param envelope - An envelope from `readCopilotKitUIEnvelope`.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```ts
|
|
277
|
+
* const envelope = readCopilotKitUIEnvelope(input.forwardedProps);
|
|
278
|
+
* const manifest = envelope && envelopeToManifest(envelope);
|
|
279
|
+
* if (manifest?.transport === "tool" && manifest.hasComponents) {
|
|
280
|
+
* // Add the render tool and validate operations against manifest.components.
|
|
281
|
+
* }
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
export function envelopeToManifest(envelope: CopilotKitUIEnvelope) {
|
|
285
|
+
const { supportedCatalogIds, inlineCatalogs } = envelope["v1.0"];
|
|
286
|
+
const catalogId = supportedCatalogIds[0];
|
|
287
|
+
const catalog = inlineCatalogs?.find(
|
|
288
|
+
(entry) => entry.catalogId === catalogId,
|
|
289
|
+
);
|
|
290
|
+
const extensions = envelope.metadata.extensions;
|
|
291
|
+
const manifest: GenerativeUIManifest = {
|
|
292
|
+
catalogId,
|
|
293
|
+
catalogIds: supportedCatalogIds,
|
|
294
|
+
components: catalog?.components ?? {},
|
|
295
|
+
functions: catalog?.functions ?? {},
|
|
296
|
+
targets: extensions.copilotkit_targets,
|
|
297
|
+
surfaces: extensions.copilotkit_surfaces,
|
|
298
|
+
};
|
|
299
|
+
return {
|
|
300
|
+
...manifest,
|
|
301
|
+
transport: extensions.copilotkit_transport,
|
|
302
|
+
contextSent: extensions.copilotkit_contextSent,
|
|
303
|
+
instructions: catalog?.instructions,
|
|
304
|
+
hasComponents: catalog?.components !== undefined,
|
|
305
|
+
...(extensions.copilotkit_action === undefined
|
|
306
|
+
? {}
|
|
307
|
+
: { action: extensions.copilotkit_action }),
|
|
308
|
+
};
|
|
309
|
+
}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { isA2UIBasicFunction } from "./generative-ui/basic-functions";
|
|
2
|
+
import { A2UI_CHILD_LIST_REF } from "./generative-ui/child-refs";
|
|
3
|
+
import { GENERATIVE_UI_AGENT_FUNCTION_CALLS } from "./generative-ui/types";
|
|
4
|
+
import type { GenerativeUIManifest } from "./generative-ui/types";
|
|
5
|
+
/**
|
|
6
|
+
* Default A2UI generation and design guideline prompts.
|
|
7
|
+
*
|
|
8
|
+
* These are the canonical prompt fragments that instruct an LLM how to call
|
|
9
|
+
* the render_a2ui tool, how to bind data, and how to style surfaces.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Generation guidelines — protocol rules, tool arguments, path rules,
|
|
14
|
+
* data model format, and form/two-way-binding instructions.
|
|
15
|
+
*/
|
|
16
|
+
export const A2UI_DEFAULT_GENERATION_GUIDELINES = `\
|
|
17
|
+
Generate A2UI v0.9 JSON.
|
|
18
|
+
|
|
19
|
+
## A2UI Protocol Instructions
|
|
20
|
+
|
|
21
|
+
A2UI (Agent to UI) is a protocol for rendering rich UI surfaces from agent responses.
|
|
22
|
+
|
|
23
|
+
CRITICAL: You MUST call the render_a2ui tool with ALL of these arguments:
|
|
24
|
+
- surfaceId: A unique ID for the surface (e.g. "product-comparison")
|
|
25
|
+
- components: REQUIRED — the A2UI component array. NEVER omit this. Only use
|
|
26
|
+
components listed in the Available Components schema provided as context.
|
|
27
|
+
- data: OPTIONAL — a JSON object written to the root of the surface data model.
|
|
28
|
+
Use for pre-filling form values or providing data for path-bound components.
|
|
29
|
+
- every component must have the "component" field specifying the component type.
|
|
30
|
+
ONLY use component names from the Available Components schema — do NOT invent
|
|
31
|
+
component names or use names not in the schema.
|
|
32
|
+
|
|
33
|
+
COMPONENT ID RULES:
|
|
34
|
+
- Exactly one component MUST have id="root". This is the surface's entry
|
|
35
|
+
point — the renderer begins at "root" and walks the child/children tree
|
|
36
|
+
from there. Every other component must be reachable from "root". If no
|
|
37
|
+
component has id="root", the surface renders an empty loading placeholder
|
|
38
|
+
and none of your components will be shown.
|
|
39
|
+
- Every component ID must be unique within the surface.
|
|
40
|
+
- A component MUST NOT reference itself as child/children. This causes a
|
|
41
|
+
circular dependency error. For example, if a component has id="avatar",
|
|
42
|
+
its child must be a DIFFERENT id (e.g. "avatar-img"), never "avatar".
|
|
43
|
+
- The child/children tree must be a DAG — no cycles allowed.
|
|
44
|
+
|
|
45
|
+
REPEATING CONTENT (TEMPLATES):
|
|
46
|
+
To repeat a component for each item in an array, use the structural children format:
|
|
47
|
+
children: { componentId: "card-id", path: "/items" }
|
|
48
|
+
This tells the renderer to create one instance of "card-id" per item in the "/items" array.
|
|
49
|
+
|
|
50
|
+
PATH RULES FOR TEMPLATES:
|
|
51
|
+
Components inside a repeating template use RELATIVE paths (no leading slash).
|
|
52
|
+
The path is resolved relative to each array item automatically.
|
|
53
|
+
If a container has children: { componentId: "card", path: "/items" } and each item
|
|
54
|
+
has a key "name", use { "path": "name" } (NO leading slash — relative to item).
|
|
55
|
+
CRITICAL: Do NOT use "/name" (absolute) inside templates — use "name" (relative).
|
|
56
|
+
The container's path ("/items") uses a leading slash (absolute), but all
|
|
57
|
+
components INSIDE the template use paths WITHOUT leading slash.
|
|
58
|
+
|
|
59
|
+
COMPONENT VALUES — DEFAULT RULE:
|
|
60
|
+
Use inline literal values for ALL component properties. Pass strings, numbers,
|
|
61
|
+
arrays, and objects directly on the component. Do NOT use { "path": "..." }
|
|
62
|
+
objects unless the property's schema explicitly allows it (see exception below).
|
|
63
|
+
CRITICAL: USING { "path": "..." } ON A PROPERTY THAT DOES NOT DECLARE PATH
|
|
64
|
+
SUPPORT IN ITS SCHEMA WILL CAUSE A RUNTIME CRASH AND BREAK THE ENTIRE UI.
|
|
65
|
+
ALWAYS CHECK THE COMPONENT SCHEMA FIRST — IF THE PROPERTY ONLY ACCEPTS A
|
|
66
|
+
PLAIN TYPE, YOU MUST USE A LITERAL VALUE.
|
|
67
|
+
VERY IMPORTANT: THE APPLICATION WILL BREAK IF YOU DO NOT FOLLOW THIS RULE!
|
|
68
|
+
|
|
69
|
+
For example, a chart's "data" must always be an inline array:
|
|
70
|
+
"data": [{"label": "Jan", "value": 100}, {"label": "Feb", "value": 200}]
|
|
71
|
+
A metric's "value" must always be an inline string:
|
|
72
|
+
"value": "$1,200"
|
|
73
|
+
|
|
74
|
+
PATH BINDING EXCEPTION — SCHEMA-DRIVEN:
|
|
75
|
+
A few properties accept { "path": "/some/path" } as an alternative to a literal
|
|
76
|
+
value. You can identify these in the Available Components schema: the property
|
|
77
|
+
will list BOTH a literal type AND an object-with-path option. If a property only
|
|
78
|
+
shows a single type (string, number, array, etc.), it does NOT support path
|
|
79
|
+
binding — use a literal value only.
|
|
80
|
+
|
|
81
|
+
Path binding is typically used for editable form inputs so the client can write
|
|
82
|
+
user input back to the data model. When building forms:
|
|
83
|
+
- Bind input "value" to a data model path: "value": { "path": "/form/name" }
|
|
84
|
+
- Pre-fill via the "data" tool argument: "data": { "form": { "name": "Alice" } }
|
|
85
|
+
- Capture values on submit via button action context:
|
|
86
|
+
"action": { "event": { "name": "submit", "context": { "name": { "path": "/form/name" } } } }
|
|
87
|
+
|
|
88
|
+
REPEATING CONTENT uses a structural children format (not the same as value binding):
|
|
89
|
+
children: { componentId: "card-id", path: "/items" }
|
|
90
|
+
Components inside templates use RELATIVE paths (no leading slash): { "path": "name" }.`;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Design guidelines — visual design rules, component hierarchy tips,
|
|
94
|
+
* and action handler patterns.
|
|
95
|
+
*/
|
|
96
|
+
export const A2UI_DEFAULT_DESIGN_GUIDELINES = `\
|
|
97
|
+
Create polished, visually appealing interfaces. ONLY use components listed in the
|
|
98
|
+
Available Components schema — do NOT use component names that are not in the schema.
|
|
99
|
+
|
|
100
|
+
Design principles:
|
|
101
|
+
- Create clear visual hierarchy within cards and layouts.
|
|
102
|
+
- Keep cards clean — avoid clutter. Whitespace is good.
|
|
103
|
+
- Use consistent surfaceIds (lowercase, hyphenated).
|
|
104
|
+
- NEVER use the same ID for a component and its child — this creates a
|
|
105
|
+
circular dependency. E.g. if id="avatar", child must NOT be "avatar".
|
|
106
|
+
- For side-by-side comparisons, use a container with structural children
|
|
107
|
+
(children: { componentId, path }) to repeat a card template per data item.
|
|
108
|
+
- Include images when relevant (logos, icons, product photos):
|
|
109
|
+
- Prefer company logos via Google favicons: https://www.google.com/s2/favicons?domain=example.com&sz=128
|
|
110
|
+
- Do NOT invent Unsplash photo-IDs — they will 404. Only use real, known URLs.
|
|
111
|
+
- For buttons: action MUST use this exact nested format:
|
|
112
|
+
"action": { "event": { "name": "myAction", "context": { "key": "value" } } }
|
|
113
|
+
The "event" key holds an OBJECT with "name" (required) and "context" (optional).
|
|
114
|
+
Do NOT use a flat format like {"event": "name"} — "event" must be an object.
|
|
115
|
+
- For forms: check the component schema — if an input's "value" property
|
|
116
|
+
supports path binding, use it for editable fields. The submit button's
|
|
117
|
+
action context should reference the same paths to capture user input.
|
|
118
|
+
|
|
119
|
+
Use the SAME surfaceId as the main surface. Match action names to button action event names.`;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* When UI helps the user, for both transports: a light nudge to reach for UI
|
|
123
|
+
* where it conveys the answer better than prose, and to stay in prose
|
|
124
|
+
* otherwise.
|
|
125
|
+
*/
|
|
126
|
+
export const GENERATIVE_UI_WHEN_TO_SHOW =
|
|
127
|
+
"Show UI when it conveys the answer better than prose: to illustrate a concept (a diagram, a chart of how something changes), to compare options side by side, to let the user explore or adjust values, or to collect input. A small, focused surface next to your explanation often lands better than a long description. Reply in prose alone for a quick fact, a short answer, or conversation, and never add UI only as decoration.";
|
|
128
|
+
|
|
129
|
+
/** Description of the context entry that carries `GENERATIVE_UI_MARKDOWN_GUIDELINES`. */
|
|
130
|
+
export const GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION =
|
|
131
|
+
"Generative UI markdown guide: how to write UI surfaces inside ```a2ui code fences in a normal markdown reply.";
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Description of the context entry that carries the compact component schema
|
|
135
|
+
* in the markdown transport.
|
|
136
|
+
*
|
|
137
|
+
* It must not equal `A2UI_SCHEMA_CONTEXT_DESCRIPTION` (the key that
|
|
138
|
+
* `@ag-ui/a2ui-middleware` stamps for tool mode). The LangGraph and Strands
|
|
139
|
+
* adapters find that exact string and move the entry into
|
|
140
|
+
* `state["ag-ui"]["a2ui_schema"]` for the `render_a2ui` tool, so it never
|
|
141
|
+
* gets to the system prompt. The markdown transport has no tool, so the
|
|
142
|
+
* schema must stay ordinary context that the model reads as App Context.
|
|
143
|
+
*/
|
|
144
|
+
export const GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION =
|
|
145
|
+
"Generative UI component schema: the components, props, events, slots, functions, and targets that ```a2ui code fences can use, and the surfaces that already exist.";
|
|
146
|
+
|
|
147
|
+
/** Which optional parts of A2UI a manifest uses. The guides leave out the rules for the others. */
|
|
148
|
+
export interface GenerativeUIGuideFeatures {
|
|
149
|
+
/** A function is mounted: function calls and callRendererFunction. */
|
|
150
|
+
functions: boolean;
|
|
151
|
+
/** A component has an event prop. */
|
|
152
|
+
events: boolean;
|
|
153
|
+
/** A component has a "multiple" slot, which takes templates and @index. */
|
|
154
|
+
templates: boolean;
|
|
155
|
+
/** A component has a "checks" prop: validation rules on inputs. */
|
|
156
|
+
checks: boolean;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Every optional rule group. Use it when the manifest is not known. */
|
|
160
|
+
export const ALL_GENERATIVE_UI_GUIDE_FEATURES: GenerativeUIGuideFeatures = {
|
|
161
|
+
functions: true,
|
|
162
|
+
events: true,
|
|
163
|
+
templates: true,
|
|
164
|
+
checks: true,
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The optional parts of A2UI that a manifest uses, so that a guide sends only
|
|
169
|
+
* the rules that the model can apply.
|
|
170
|
+
*
|
|
171
|
+
* @param manifest - The components and the mounted functions of a run.
|
|
172
|
+
* @returns Which optional rule groups the guides include.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* const guide = buildGenerativeUIMarkdownGuidelines(
|
|
177
|
+
* generativeUIGuideFeatures(manifest),
|
|
178
|
+
* );
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export function generativeUIGuideFeatures(
|
|
182
|
+
manifest: Pick<GenerativeUIManifest, "components" | "functions">,
|
|
183
|
+
): GenerativeUIGuideFeatures {
|
|
184
|
+
const components = Object.values(manifest.components);
|
|
185
|
+
const hasChildList = (schema: unknown): boolean => {
|
|
186
|
+
if (Array.isArray(schema)) return schema.some(hasChildList);
|
|
187
|
+
if (typeof schema !== "object" || schema === null) return false;
|
|
188
|
+
const node = schema as Record<string, unknown>;
|
|
189
|
+
if (node.$ref === A2UI_CHILD_LIST_REF) return true;
|
|
190
|
+
return Object.values(node).some(hasChildList);
|
|
191
|
+
};
|
|
192
|
+
return {
|
|
193
|
+
// App functions only: the built-in ones are always there and have
|
|
194
|
+
// their own rules.
|
|
195
|
+
functions: Object.keys(manifest.functions).some(
|
|
196
|
+
(name) => !isA2UIBasicFunction(name),
|
|
197
|
+
),
|
|
198
|
+
events: components.some((c) => Object.keys(c.events ?? {}).length > 0),
|
|
199
|
+
templates: components.some(
|
|
200
|
+
(c) =>
|
|
201
|
+
Object.values(c.slots ?? {}).includes("multiple") ||
|
|
202
|
+
hasChildList(c.props),
|
|
203
|
+
),
|
|
204
|
+
checks: components.some((c) => {
|
|
205
|
+
const properties = c.props.properties;
|
|
206
|
+
return (
|
|
207
|
+
typeof properties === "object" &&
|
|
208
|
+
properties !== null &&
|
|
209
|
+
Object.prototype.hasOwnProperty.call(properties, "checks")
|
|
210
|
+
);
|
|
211
|
+
}),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** The first rules of every markdown guideline, before the optional groups. */
|
|
216
|
+
const MARKDOWN_BASE_RULES = [
|
|
217
|
+
"Write explanations as normal markdown prose outside the fences.",
|
|
218
|
+
"Open a fence with ```a2ui to show the surface in the chat, at the place of the fence.",
|
|
219
|
+
'Open a fence with ```a2ui target=<id> to show the surface in a named target. Use only target ids from the schema. When a target has "components", its surfaces can use only those components.',
|
|
220
|
+
"Inside a fence, write one JSON object per line and nothing else. No comments, no trailing commas, no pretty-printing.",
|
|
221
|
+
"Keep each operation whole on its line.",
|
|
222
|
+
'Give every operation "version":"v1.0".',
|
|
223
|
+
`Start a surface with one createSurface. Put all the initial data in "dataModel" and the "root" component in "components". Then write the children in updateComponents lines, so that they show while you write:
|
|
224
|
+
\`\`\`a2ui
|
|
225
|
+
{"version":"v1.0","createSurface":{"surfaceId":"plan-picker","dataModel":{ ...initial data... },"components":[{"id":"root","component":"<Name>","children":["seats","pick"]}]}}
|
|
226
|
+
{"version":"v1.0","updateComponents":{"surfaceId":"plan-picker","components":[ ...the children... ]}}
|
|
227
|
+
\`\`\``,
|
|
228
|
+
'Keep "dataModel" flat: top-level keys such as "seats" or "form", never one wrapper object around everything. Check that every { and [ you open in a line is closed.',
|
|
229
|
+
'Every surface renders from the component with id "root". Make every other component reachable from "root" through slots.',
|
|
230
|
+
"Use unique ids. Do not make cycles. A component cannot be its own child.",
|
|
231
|
+
'Write a component as one flat object: {"id":"title","component":"<Name>","text":"Hello"}.',
|
|
232
|
+
'Put the component name in "component" (never "type"). Put props next to it, never inside a "props" object.',
|
|
233
|
+
'A component may take "accessibility":{"label":"<1 to 3 words>","description":"<what it does>"} for screen readers: on the component it describes, when nothing visible names it. Not on every component, and "live":"polite" only on text that changes by itself.',
|
|
234
|
+
'Use only the components, props, events, and slots in the schema. A component with "includesCommonProps" also takes every prop in "commonProps".',
|
|
235
|
+
'Give a prop a literal value, or bind it to the data model with {"@path":"/x"}. Never write {"path":"/x"} as a binding.',
|
|
236
|
+
'A prop can also be a function value that updates with the data: {"@call":"formatCurrency","args":{"value":{"@path":"/total"},"currency":"EUR"}}. Use only the functions under "functions" in the schema. Write a literal when the value never changes.',
|
|
237
|
+
'formatString interpolates ${...}: {"@call":"formatString","args":{"value":"${/qty} × ${formatCurrency(value: /price, currency: \'EUR\')}"}}. Inside ${...}, a path has no quotes, a string has single quotes, and a function takes named args.',
|
|
238
|
+
'${...} is evaluated only in the value of formatString and in the item of series; in other strings it stays literal text. Inside formatString, ${...} does not support operators. For arithmetic use calc, with the values as named args: {"@call":"calc","args":{"expression":"seats * 29 * (annual ? 0.8 : 1)","seats":{"@path":"/seats"},"annual":{"@path":"/annual"}}}. Inside formatString: ${formatCurrency(value: calc(expression: \'seats * 29\', seats: /seats), currency: \'USD\')}. The UI then follows the user\'s input with no round trip.',
|
|
239
|
+
'For a computed list (chart data, template items) use series. Its description under "functions" in the schema gives the rules and an example. Bind the "data" of a Chart or the "items" of a List to it; a template path stays a literal path.',
|
|
240
|
+
'Bind a writable prop to let the user edit it: "value":{"@path":"/form/email"}. The user\'s input goes to that path.',
|
|
241
|
+
'To change data, write updateDataModel with a "path" and a "value": {"version":"v1.0","updateDataModel":{"surfaceId":"plan-picker","path":"/seats","value":12}}. Always give "value".',
|
|
242
|
+
'Set "value":null to delete the key at "path".',
|
|
243
|
+
];
|
|
244
|
+
|
|
245
|
+
/** The last rules of every markdown guideline, after the optional groups. */
|
|
246
|
+
const MARKDOWN_CLOSING_RULES = [
|
|
247
|
+
'The schema lists the surfaces that already exist under "surfaces". "dataModel" holds the values that the user entered: read them, and do not write those paths. "rejected" lists operations that the client dropped: send corrected operations in a new fence for that surfaceId. "status":"deleted" means the surface is gone: never use its id again. "status":"failed" means its createSurface was rejected: send a corrected createSurface with that id.',
|
|
248
|
+
"Never make a surface that is only prose. Write headings, paragraphs, lists of text, intros, and summaries as markdown outside the fences, also between two fences.",
|
|
249
|
+
"Put in a fence only what markdown cannot show: charts, tables, maps, images, badges, inputs, buttons, cards with controls.",
|
|
250
|
+
"Use Card only for an interactive panel (controls, a form, a configurator). Put everything else in a plain layout component.",
|
|
251
|
+
"Never wrap the whole reply in a fence.",
|
|
252
|
+
];
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Builds the markdown-transport guideline. The model writes A2UI v1.0
|
|
256
|
+
* operations inside ```a2ui fences between normal markdown prose. The rules
|
|
257
|
+
* for functions, events, and templates are left out when the manifest has
|
|
258
|
+
* none of them, so the guideline stays small.
|
|
259
|
+
*
|
|
260
|
+
* @param features - The optional rule groups to include. Defaults to all.
|
|
261
|
+
* @returns The guideline text, one rule per line.
|
|
262
|
+
*/
|
|
263
|
+
export function buildGenerativeUIMarkdownGuidelines(
|
|
264
|
+
features: GenerativeUIGuideFeatures = ALL_GENERATIVE_UI_GUIDE_FEATURES,
|
|
265
|
+
) {
|
|
266
|
+
const { functions, events, templates, checks } = features;
|
|
267
|
+
const rules = [...MARKDOWN_BASE_RULES];
|
|
268
|
+
if (events) {
|
|
269
|
+
rules.push(
|
|
270
|
+
'Give an event prop an object: {"event":{"name":"<name>","userMessage":"<text>","context":{...}}} or {"functionCall":{"@call":"<function>","args":{...}}}. Never a flat {"event":"<name>"}.',
|
|
271
|
+
functions
|
|
272
|
+
? 'Use {"functionCall": ...} to run a function in the browser when the user clicks: an app function from the schema, or openUrl: {"functionCall":{"@call":"openUrl","args":{"url":"https://example.com"}}}. You are not told about the call.'
|
|
273
|
+
: 'Use {"functionCall": ...} to open a URL when the user clicks: {"functionCall":{"@call":"openUrl","args":{"url":"https://example.com"}}}. You are not told about the call.',
|
|
274
|
+
'Use {"event": ...} to send the interaction back to you as a user message. Put the text of that message in "userMessage": {"event":{"name":"choose","userMessage":"Show me the Team plan"}}. "userMessage" is plain text: ${...} is not interpolated in it; put values in "context".',
|
|
275
|
+
'To send input values with an event, bind them in the context: "context":{"email":{"@path":"/form/email"}}.',
|
|
276
|
+
"A button or other event prop without an event or functionCall does nothing.",
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
if (checks) {
|
|
280
|
+
rules.push(
|
|
281
|
+
'Validate an input with "checks": [{"condition":{"@call":"email","args":{"value":{"@path":"/form/email"}}},"message":"Enter a valid email"}]. The check functions are required, regex, length, numeric and email; a condition can also be a boolean {"@path"}. A failed check shows the message under the input and disables a Button that has the same checks.',
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
rules.push(
|
|
285
|
+
'A prop typed componentId takes the id of another component, and a childList takes ids ["a","b"]: "child":"card", "children":["a","b"], "tabs":[{"title":"Specs","child":"specs"}].',
|
|
286
|
+
);
|
|
287
|
+
if (templates) {
|
|
288
|
+
rules.push(
|
|
289
|
+
'To repeat a component for each item of a list, give a childList a template: "children":{"componentId":"row","path":"/items"}.',
|
|
290
|
+
'Inside a template, paths are relative to the item ("name", not "/name").',
|
|
291
|
+
'Inside a template, {"@call":"@index"} gives the position of the item, from 0. To count from 1, write {"@call":"@index","args":{"offset":1}}.',
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
rules.push(
|
|
295
|
+
"Updating a component replaces all of its props. Send every prop again.",
|
|
296
|
+
"To change a surface in this reply, write another fence with the same surfaceId. Do not send createSurface again. The surface changes where it already is. A surface in a target can also be changed from a later reply; a chat surface cannot, because the chat is a transcript: a later reply with the same surfaceId makes a new surface.",
|
|
297
|
+
"Use a new surfaceId for a different view. Never use a surfaceId again, also after the surface is deleted.",
|
|
298
|
+
);
|
|
299
|
+
if (functions && GENERATIVE_UI_AGENT_FUNCTION_CALLS) {
|
|
300
|
+
rules.push(
|
|
301
|
+
'To run an app function now, with no click, write a callRendererFunction line in a fence: {"version":"v1.0","callRendererFunction":{"functionCallId":"<unique id>","callFunction":{"@call":"<function>","args":{...}}}}. It needs no surface.',
|
|
302
|
+
'Give every callRendererFunction a new functionCallId. Call only a function from the schema with "callers": "UI or agent" or "agent only"; a function without "callers" is for the UI only. A function with "callers": "agent only" is only for callRendererFunction: do not bind an event to it.',
|
|
303
|
+
'The result of a callRendererFunction comes back to you as a developer message: {"version":"v1.0","rendererFunctionResponse":{"functionCallId":"<id>","value":...}}. If the call failed, it has "error" in place of "value". Then you get a new turn.',
|
|
304
|
+
"Do not guess the result of a callRendererFunction. Wait for the developer message.",
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
rules.push(...MARKDOWN_CLOSING_RULES);
|
|
308
|
+
return `You can show interactive UI in your reply. Write A2UI operations inside a fenced code block tagged a2ui.
|
|
309
|
+
|
|
310
|
+
${GENERATIVE_UI_WHEN_TO_SHOW}
|
|
311
|
+
|
|
312
|
+
RULES
|
|
313
|
+
${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
314
|
+
`;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* The markdown-transport guideline with every rule group. A run sends
|
|
319
|
+
* `buildGenerativeUIMarkdownGuidelines` for its own manifest instead.
|
|
320
|
+
*/
|
|
321
|
+
export const GENERATIVE_UI_MARKDOWN_GUIDELINES =
|
|
322
|
+
buildGenerativeUIMarkdownGuidelines();
|