@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,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The functions of the A2UI 1.0 basic catalog, as the model and the
|
|
3
|
+
* validator see them. The renderer implements them (react-core
|
|
4
|
+
* `generative-ui/functions.ts`); this file holds only what both sides share:
|
|
5
|
+
* the names, the short signatures for the schema the model reads, and who
|
|
6
|
+
* may call each one.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** What a function gives back, as A2UI 1.0 names it. */
|
|
10
|
+
export type A2UIFunctionReturnType =
|
|
11
|
+
| "string"
|
|
12
|
+
| "number"
|
|
13
|
+
| "boolean"
|
|
14
|
+
| "array"
|
|
15
|
+
| "object"
|
|
16
|
+
| "validationResult"
|
|
17
|
+
| "any"
|
|
18
|
+
| "void";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Who may call a function. The renderer calls it from an event binding or
|
|
22
|
+
* as a prop value; the agent calls it with `callRendererFunction`.
|
|
23
|
+
*/
|
|
24
|
+
export type A2UIAllowedCallers =
|
|
25
|
+
| "rendererOnly"
|
|
26
|
+
| "agentOnly"
|
|
27
|
+
| "rendererOrAgent";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The callers of an app function that names none: the renderer only, as
|
|
31
|
+
* in A2UI 1.0. The agent calls a function with `callRendererFunction` only
|
|
32
|
+
* when its declaration allows it (`"rendererOrAgent"` or `"agentOnly"`).
|
|
33
|
+
* The manifests and the exported catalog write the value out.
|
|
34
|
+
*/
|
|
35
|
+
export const GENERATIVE_UI_DEFAULT_ALLOWED_CALLERS: A2UIAllowedCallers =
|
|
36
|
+
"rendererOnly";
|
|
37
|
+
|
|
38
|
+
/** The A2UI 1.0 interface fields of a function: who calls it, and how. */
|
|
39
|
+
export interface A2UIFunctionPermissions {
|
|
40
|
+
allowedCallers?: A2UIAllowedCallers;
|
|
41
|
+
/**
|
|
42
|
+
* True for a function that only runs from a user gesture (a click, a key
|
|
43
|
+
* press). It is `rendererOnly`: the agent cannot call it, and a prop
|
|
44
|
+
* cannot be bound to it.
|
|
45
|
+
*/
|
|
46
|
+
requiresUserActivation?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Who may call a function, from its permissions. A function that needs a
|
|
51
|
+
* user gesture is for the renderer only, whatever `allowedCallers` says.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* functionCallers({}); // { renderer: true, agent: true }
|
|
56
|
+
* functionCallers({ allowedCallers: "rendererOnly" }); // { renderer: true, agent: false }
|
|
57
|
+
* functionCallers({ requiresUserActivation: true }); // { renderer: true, agent: false }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export function functionCallers(fn: A2UIFunctionPermissions) {
|
|
61
|
+
if (fn.requiresUserActivation) return { renderer: true, agent: false };
|
|
62
|
+
const callers = fn.allowedCallers ?? GENERATIVE_UI_DEFAULT_ALLOWED_CALLERS;
|
|
63
|
+
return {
|
|
64
|
+
renderer: callers !== "agentOnly",
|
|
65
|
+
agent: callers !== "rendererOnly",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface A2UIBasicFunctionInfo extends A2UIFunctionPermissions {
|
|
70
|
+
description: string;
|
|
71
|
+
/** The args, as a short TypeScript-like type for the compact schema. */
|
|
72
|
+
parameters: string;
|
|
73
|
+
returnType: A2UIFunctionReturnType;
|
|
74
|
+
/** Built-in functions are value functions of the renderer. */
|
|
75
|
+
allowedCallers: "rendererOnly";
|
|
76
|
+
requiresUserActivation?: true;
|
|
77
|
+
/** True for a CopilotKit function that the A2UI basic catalog lacks. */
|
|
78
|
+
extension?: true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Marks a table of built-in functions as callable by the renderer only. */
|
|
82
|
+
function rendererOnly<Name extends string>(
|
|
83
|
+
functions: Record<Name, Omit<A2UIBasicFunctionInfo, "allowedCallers">>,
|
|
84
|
+
): Readonly<Record<Name, A2UIBasicFunctionInfo>> {
|
|
85
|
+
return Object.fromEntries(
|
|
86
|
+
Object.entries<Omit<A2UIBasicFunctionInfo, "allowedCallers">>(
|
|
87
|
+
functions,
|
|
88
|
+
).map(([name, info]) => [
|
|
89
|
+
name,
|
|
90
|
+
{ ...info, allowedCallers: "rendererOnly" },
|
|
91
|
+
]),
|
|
92
|
+
) as Record<Name, A2UIBasicFunctionInfo>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The basic functions by name. A `{"@call"}` in a prop, in an event
|
|
97
|
+
* binding, or in a `callRendererFunction` may name any of them without a
|
|
98
|
+
* declaration in `createGenerativeUI({ functions })`.
|
|
99
|
+
*/
|
|
100
|
+
export const A2UI_BASIC_FUNCTIONS: Readonly<
|
|
101
|
+
Record<string, A2UIBasicFunctionInfo>
|
|
102
|
+
> = rendererOnly({
|
|
103
|
+
required: {
|
|
104
|
+
description: "Valid when the value is not empty",
|
|
105
|
+
parameters: "{ value: unknown }",
|
|
106
|
+
returnType: "validationResult",
|
|
107
|
+
},
|
|
108
|
+
regex: {
|
|
109
|
+
description: "Valid when the value matches the pattern",
|
|
110
|
+
parameters: "{ value: string; pattern: string }",
|
|
111
|
+
returnType: "validationResult",
|
|
112
|
+
},
|
|
113
|
+
length: {
|
|
114
|
+
description: "Valid when the length of the value is within min and max",
|
|
115
|
+
parameters: "{ value: string; min?: number; max?: number }",
|
|
116
|
+
returnType: "validationResult",
|
|
117
|
+
},
|
|
118
|
+
numeric: {
|
|
119
|
+
description: "Valid when the value is a number within min and max",
|
|
120
|
+
parameters: "{ value: number; min?: number; max?: number }",
|
|
121
|
+
returnType: "validationResult",
|
|
122
|
+
},
|
|
123
|
+
email: {
|
|
124
|
+
description: "Valid when the value is an email address",
|
|
125
|
+
parameters: "{ value: string }",
|
|
126
|
+
returnType: "validationResult",
|
|
127
|
+
},
|
|
128
|
+
formatString: {
|
|
129
|
+
description:
|
|
130
|
+
"Interpolates ${/path}, ${relative/path} and ${fn(arg: value)} in the value; \\${ is a literal",
|
|
131
|
+
parameters: "{ value: string }",
|
|
132
|
+
returnType: "string",
|
|
133
|
+
},
|
|
134
|
+
formatNumber: {
|
|
135
|
+
description: "The number in the locale of the user",
|
|
136
|
+
parameters: "{ value: number; decimals?: number; grouping?: boolean }",
|
|
137
|
+
returnType: "string",
|
|
138
|
+
},
|
|
139
|
+
formatCurrency: {
|
|
140
|
+
description: "The amount as money, with an ISO 4217 currency code",
|
|
141
|
+
parameters:
|
|
142
|
+
"{ value: number; currency: string; decimals?: number; grouping?: boolean }",
|
|
143
|
+
returnType: "string",
|
|
144
|
+
},
|
|
145
|
+
formatDate: {
|
|
146
|
+
description:
|
|
147
|
+
'A date or ISO string in a TR35 pattern, for example "MMM d, yyyy" or "HH:mm"',
|
|
148
|
+
parameters: "{ value: string | number; format: string }",
|
|
149
|
+
returnType: "string",
|
|
150
|
+
},
|
|
151
|
+
pluralize: {
|
|
152
|
+
description: "The string of the plural category of the value",
|
|
153
|
+
parameters:
|
|
154
|
+
"{ value: number; zero?: string; one?: string; two?: string; few?: string; many?: string; other: string }",
|
|
155
|
+
returnType: "string",
|
|
156
|
+
},
|
|
157
|
+
openUrl: {
|
|
158
|
+
description: "Opens an http(s) URL in a new tab. Only from an event",
|
|
159
|
+
parameters: "{ url: string }",
|
|
160
|
+
returnType: "void",
|
|
161
|
+
requiresUserActivation: true,
|
|
162
|
+
},
|
|
163
|
+
and: {
|
|
164
|
+
description: "True when every value is true",
|
|
165
|
+
parameters: "{ values: boolean[] }",
|
|
166
|
+
returnType: "boolean",
|
|
167
|
+
},
|
|
168
|
+
or: {
|
|
169
|
+
description: "True when any value is true",
|
|
170
|
+
parameters: "{ values: boolean[] }",
|
|
171
|
+
returnType: "boolean",
|
|
172
|
+
},
|
|
173
|
+
not: {
|
|
174
|
+
description: "The negated value",
|
|
175
|
+
parameters: "{ value: boolean }",
|
|
176
|
+
returnType: "boolean",
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The value functions that CopilotKit adds to the basic catalog, because
|
|
182
|
+
* A2UI 1.0 has no arithmetic: `calc` evaluates an expression over named
|
|
183
|
+
* args, and `series` builds a computed list. A catalog may declare its own
|
|
184
|
+
* functions in A2UI, so these are regular catalog functions to the model;
|
|
185
|
+
* a renderer without them rejects the call instead of misrendering.
|
|
186
|
+
*/
|
|
187
|
+
export const COPILOTKIT_FUNCTIONS: Readonly<
|
|
188
|
+
Record<string, A2UIBasicFunctionInfo>
|
|
189
|
+
> = rendererOnly({
|
|
190
|
+
calc: {
|
|
191
|
+
description:
|
|
192
|
+
"The value of an arithmetic expression over the other args, by name: + - * / % ( ), comparisons, && || !, cond ? a : b, min max round floor ceil abs, 'text' + name",
|
|
193
|
+
parameters:
|
|
194
|
+
"{ expression: string; [name: string]: number | string | boolean }",
|
|
195
|
+
returnType: "any",
|
|
196
|
+
extension: true,
|
|
197
|
+
},
|
|
198
|
+
// WORKAROUND(a2ui-agent-sdk 0.9.0): examples omit `variable` and use default i
|
|
199
|
+
// because the Express compiler mistakes a literal `variable` key for its AST.
|
|
200
|
+
// Runtime support for custom variable names is unchanged.
|
|
201
|
+
// https://github.com/a2ui-project/a2ui/issues/3410
|
|
202
|
+
series: {
|
|
203
|
+
description:
|
|
204
|
+
'A list of count copies of item, for chart data and template lists. Put arithmetic in ${expression} strings in item, using the loop variable (default i, counting from start, default 1) and other named args. A whole-expression string retains the result type, so "${i * monthlyCost}" yields a number. Arguments, including nested calc or formatString calls in item, resolve before the series loop; those calls cannot use the loop variable. Example: {"@call":"series","args":{"count":6,"item":{"month":"${i}","cost":"${i * monthlyCost}"},"monthlyCost":{"@path":"/monthlyCost"}}}. Omit variable to use i.',
|
|
205
|
+
parameters:
|
|
206
|
+
"{ count: number; item: unknown; variable?: string; start?: number; [name: string]: unknown }",
|
|
207
|
+
returnType: "array",
|
|
208
|
+
extension: true,
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
/** Every function a `{"@call"}` may name without a declaration: basic and CopilotKit. */
|
|
213
|
+
export const GENERATIVE_UI_FUNCTIONS: Readonly<
|
|
214
|
+
Record<string, A2UIBasicFunctionInfo>
|
|
215
|
+
> = { ...A2UI_BASIC_FUNCTIONS, ...COPILOTKIT_FUNCTIONS };
|
|
216
|
+
|
|
217
|
+
/** The name of the system function that gives the index of a template item. */
|
|
218
|
+
export const A2UI_INDEX_FUNCTION = "@index";
|
|
219
|
+
|
|
220
|
+
/** True for a built-in function name: basic, CopilotKit, or `@index`. */
|
|
221
|
+
export function isA2UIBasicFunction(name: string) {
|
|
222
|
+
return (
|
|
223
|
+
name === A2UI_INDEX_FUNCTION ||
|
|
224
|
+
Object.prototype.hasOwnProperty.call(GENERATIVE_UI_FUNCTIONS, name)
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* True for a built-in function that a prop or a check may call: every one
|
|
230
|
+
* except the functions that need a user gesture.
|
|
231
|
+
*/
|
|
232
|
+
export function isA2UIValueFunction(name: string) {
|
|
233
|
+
if (name === A2UI_INDEX_FUNCTION) return true;
|
|
234
|
+
const info = Object.prototype.hasOwnProperty.call(
|
|
235
|
+
GENERATIVE_UI_FUNCTIONS,
|
|
236
|
+
name,
|
|
237
|
+
)
|
|
238
|
+
? GENERATIVE_UI_FUNCTIONS[name]
|
|
239
|
+
: undefined;
|
|
240
|
+
return info !== undefined && !info.requiresUserActivation;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** `{ "@call": "<name>", "args"?: {...} }`: a function call value. */
|
|
244
|
+
export function isCallBinding(
|
|
245
|
+
value: unknown,
|
|
246
|
+
): value is { "@call": string; args?: Record<string, unknown> } {
|
|
247
|
+
return (
|
|
248
|
+
typeof value === "object" &&
|
|
249
|
+
value !== null &&
|
|
250
|
+
!Array.isArray(value) &&
|
|
251
|
+
typeof (value as Record<string, unknown>)["@call"] === "string"
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** How bad a failed check is. `error` is the default; only an error blocks. */
|
|
256
|
+
export type A2UIValidationSeverity = "error" | "warning" | "info";
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* A2UI's `ValidationResult`: what a check gives. A validator function gives
|
|
260
|
+
* one; a check may also bind a boolean, which the renderer coerces to one.
|
|
261
|
+
* `code` names the failure for programs; `severity` says how bad it is,
|
|
262
|
+
* `"error"` when left out. Other keys are allowed, for app validators that
|
|
263
|
+
* carry more (a suggested value, a field path).
|
|
264
|
+
*/
|
|
265
|
+
export interface A2UIValidationResult {
|
|
266
|
+
valid: boolean;
|
|
267
|
+
message?: string;
|
|
268
|
+
code?: string;
|
|
269
|
+
severity?: A2UIValidationSeverity;
|
|
270
|
+
[extra: string]: unknown;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export function isValidationResult(
|
|
274
|
+
value: unknown,
|
|
275
|
+
): value is A2UIValidationResult {
|
|
276
|
+
return (
|
|
277
|
+
typeof value === "object" &&
|
|
278
|
+
value !== null &&
|
|
279
|
+
!Array.isArray(value) &&
|
|
280
|
+
typeof (value as Record<string, unknown>).valid === "boolean"
|
|
281
|
+
);
|
|
282
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import type { GenerativeUIJSONSchema } from "./types";
|
|
2
|
+
import { isRecord } from "./is-record";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* How A2UI 1.0 marks a prop that holds a component reference: the JSON
|
|
6
|
+
* Schema of the prop is a `$ref` to one of these two common types.
|
|
7
|
+
* Validators and renderers find the children of a component by these refs,
|
|
8
|
+
* at any depth of the props schema.
|
|
9
|
+
*/
|
|
10
|
+
export const A2UI_COMPONENT_ID_REF = "common_types.json#/$defs/ComponentId";
|
|
11
|
+
export const A2UI_CHILD_LIST_REF = "common_types.json#/$defs/ChildList";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The start of the `description` that marks a schema as a component
|
|
15
|
+
* reference before it is turned into JSON Schema. `child()` and
|
|
16
|
+
* `childList()` set it; a schema from another library can set a description
|
|
17
|
+
* that starts with the same mark to get the same effect. What follows the
|
|
18
|
+
* mark (after a space) stays as the description of the reference.
|
|
19
|
+
*/
|
|
20
|
+
export const A2UI_COMPONENT_ID_MARK = "@a2ui/ComponentId";
|
|
21
|
+
export const A2UI_CHILD_LIST_MARK = "@a2ui/ChildList";
|
|
22
|
+
|
|
23
|
+
export type ChildRefKind = "single" | "multiple";
|
|
24
|
+
|
|
25
|
+
/** One component reference in a props schema. */
|
|
26
|
+
export interface ChildRef {
|
|
27
|
+
/**
|
|
28
|
+
* The keys from the props root to the reference. `"*"` stands for the
|
|
29
|
+
* items of an array. `["tabs", "*", "child"]` is the `child` of each
|
|
30
|
+
* entry of `tabs`.
|
|
31
|
+
*/
|
|
32
|
+
path: readonly string[];
|
|
33
|
+
kind: ChildRefKind;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The ref kind of a JSON Schema node, or `undefined` for a plain value. */
|
|
37
|
+
export function childRefKind(
|
|
38
|
+
schema: GenerativeUIJSONSchema,
|
|
39
|
+
): ChildRefKind | undefined {
|
|
40
|
+
const ref = schema.$ref;
|
|
41
|
+
if (ref === A2UI_COMPONENT_ID_REF) return "single";
|
|
42
|
+
if (ref === A2UI_CHILD_LIST_REF) return "multiple";
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Turns the reference marks of a JSON Schema into A2UI `$ref`s, in place of
|
|
48
|
+
* the marked node. The mark is the `description` set by `child()` and
|
|
49
|
+
* `childList()`; after this, the node is `{ "$ref": "common_types.json#/..." }`.
|
|
50
|
+
*/
|
|
51
|
+
export function applyChildRefMarks(
|
|
52
|
+
schema: GenerativeUIJSONSchema,
|
|
53
|
+
): GenerativeUIJSONSchema {
|
|
54
|
+
const marked = (description: unknown, mark: string, ref: string) => {
|
|
55
|
+
if (typeof description !== "string" || !description.startsWith(mark)) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const rest = description.slice(mark.length).trim();
|
|
59
|
+
return rest === "" ? { $ref: ref } : { $ref: ref, description: rest };
|
|
60
|
+
};
|
|
61
|
+
const visit = (node: unknown): unknown => {
|
|
62
|
+
if (Array.isArray(node)) return node.map(visit);
|
|
63
|
+
if (!isRecord(node)) return node;
|
|
64
|
+
const reference =
|
|
65
|
+
marked(node.description, A2UI_COMPONENT_ID_MARK, A2UI_COMPONENT_ID_REF) ??
|
|
66
|
+
marked(node.description, A2UI_CHILD_LIST_MARK, A2UI_CHILD_LIST_REF);
|
|
67
|
+
if (reference) return reference;
|
|
68
|
+
return Object.fromEntries(
|
|
69
|
+
Object.entries(node).map(([key, value]) => [key, visit(value)]),
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
return visit(schema) as GenerativeUIJSONSchema;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Every component reference in a props schema, with its path. Walks
|
|
77
|
+
* `properties`, array `items`, and the variants of `anyOf` / `oneOf` /
|
|
78
|
+
* `allOf`. A union counts as a reference only when every alternative is
|
|
79
|
+
* one of the same kind: a prop that is text in one branch and a child in
|
|
80
|
+
* another cannot be told apart from its value, so it stays data.
|
|
81
|
+
*/
|
|
82
|
+
export function collectChildRefs(schema: GenerativeUIJSONSchema): ChildRef[] {
|
|
83
|
+
const refs: ChildRef[] = [];
|
|
84
|
+
const seen = new Set<string>();
|
|
85
|
+
const add = (path: string[], kind: ChildRefKind) => {
|
|
86
|
+
const key = path.join("\u0000");
|
|
87
|
+
if (seen.has(key)) return;
|
|
88
|
+
seen.add(key);
|
|
89
|
+
refs.push({ path, kind });
|
|
90
|
+
};
|
|
91
|
+
const visit = (node: unknown, path: string[]) => {
|
|
92
|
+
if (!isRecord(node)) return;
|
|
93
|
+
const kind = childRefKind(node);
|
|
94
|
+
if (kind) return add(path, kind);
|
|
95
|
+
for (const list of [node.anyOf, node.oneOf]) {
|
|
96
|
+
if (!Array.isArray(list) || list.length === 0) continue;
|
|
97
|
+
const kinds = list.map((variant) =>
|
|
98
|
+
isRecord(variant) ? childRefKind(variant) : undefined,
|
|
99
|
+
);
|
|
100
|
+
const [first] = kinds;
|
|
101
|
+
if (first && kinds.every((k) => k === first)) add(path, first);
|
|
102
|
+
else if (kinds.every((k) => k === undefined)) {
|
|
103
|
+
// Objects in a union: a nested reference counts only when every
|
|
104
|
+
// alternative has it at the same path with the same kind.
|
|
105
|
+
const perVariant = list.map((variant) =>
|
|
106
|
+
collectChildRefs(variant as GenerativeUIJSONSchema),
|
|
107
|
+
);
|
|
108
|
+
const key = (ref: ChildRef) =>
|
|
109
|
+
`${ref.kind}\u0000${ref.path.join("\u0000")}`;
|
|
110
|
+
const shared = perVariant[0].filter((ref) =>
|
|
111
|
+
perVariant.every((refs) => refs.some((r) => key(r) === key(ref))),
|
|
112
|
+
);
|
|
113
|
+
shared.forEach((ref) => add([...path, ...ref.path], ref.kind));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (Array.isArray(node.allOf)) {
|
|
117
|
+
node.allOf.forEach((variant) => visit(variant, path));
|
|
118
|
+
}
|
|
119
|
+
if (isRecord(node.properties)) {
|
|
120
|
+
for (const [key, value] of Object.entries(node.properties)) {
|
|
121
|
+
visit(value, [...path, key]);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (isRecord(node.items)) visit(node.items, [...path, "*"]);
|
|
125
|
+
};
|
|
126
|
+
visit(schema, []);
|
|
127
|
+
return refs;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The component ids at the references of one component node: a string id,
|
|
132
|
+
* a list of ids, or the `componentId` of a template, at every ref path.
|
|
133
|
+
* Bound or computed values are not ids and are left out.
|
|
134
|
+
*/
|
|
135
|
+
export function childIdsAtRefs(
|
|
136
|
+
component: Record<string, unknown>,
|
|
137
|
+
refs: readonly ChildRef[],
|
|
138
|
+
): string[] {
|
|
139
|
+
const ids: string[] = [];
|
|
140
|
+
const collect = (value: unknown) => {
|
|
141
|
+
if (typeof value === "string") ids.push(value);
|
|
142
|
+
else if (Array.isArray(value)) {
|
|
143
|
+
value.forEach((id) => typeof id === "string" && ids.push(id));
|
|
144
|
+
} else if (isRecord(value) && typeof value.componentId === "string") {
|
|
145
|
+
ids.push(value.componentId);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const visit = (value: unknown, path: readonly string[]) => {
|
|
149
|
+
if (path.length === 0) return collect(value);
|
|
150
|
+
const [head, ...rest] = path;
|
|
151
|
+
if (head === "*") {
|
|
152
|
+
if (Array.isArray(value)) value.forEach((item) => visit(item, rest));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (isRecord(value) && Object.prototype.hasOwnProperty.call(value, head)) {
|
|
156
|
+
visit(value[head], rest);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
for (const ref of refs) visit(component, ref.path);
|
|
160
|
+
return ids;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* True when a reference of the component is bound or computed (`{"@path"}`,
|
|
165
|
+
* `{"@call"}`) at the ref itself or above it, so its ids are known only
|
|
166
|
+
* at render time.
|
|
167
|
+
*/
|
|
168
|
+
export function hasBoundChildRef(
|
|
169
|
+
component: Record<string, unknown>,
|
|
170
|
+
refs: readonly ChildRef[],
|
|
171
|
+
): boolean {
|
|
172
|
+
const isDynamic = (value: unknown) =>
|
|
173
|
+
isRecord(value) && ("@path" in value || "@call" in value);
|
|
174
|
+
const visit = (value: unknown, path: readonly string[]): boolean => {
|
|
175
|
+
if (isDynamic(value)) return true;
|
|
176
|
+
if (path.length === 0) return false;
|
|
177
|
+
const [head, ...rest] = path;
|
|
178
|
+
if (head === "*") {
|
|
179
|
+
return Array.isArray(value) && value.some((item) => visit(item, rest));
|
|
180
|
+
}
|
|
181
|
+
return (
|
|
182
|
+
isRecord(value) &&
|
|
183
|
+
Object.prototype.hasOwnProperty.call(value, head) &&
|
|
184
|
+
visit(value[head], rest)
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
return refs.some((ref) => visit(component, ref.path));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Walks `value` along a ref path and replaces what sits at the end with
|
|
192
|
+
* `replace(found)`. Objects and arrays on the way are copied; everything
|
|
193
|
+
* else keeps its identity. Missing keys are left alone.
|
|
194
|
+
*/
|
|
195
|
+
export function mapAtChildRef(
|
|
196
|
+
value: unknown,
|
|
197
|
+
path: readonly string[],
|
|
198
|
+
replace: (found: unknown) => unknown,
|
|
199
|
+
): unknown {
|
|
200
|
+
if (path.length === 0) return replace(value);
|
|
201
|
+
const [head, ...rest] = path;
|
|
202
|
+
if (head === "*") {
|
|
203
|
+
if (!Array.isArray(value)) return value;
|
|
204
|
+
return value.map((item) => mapAtChildRef(item, rest, replace));
|
|
205
|
+
}
|
|
206
|
+
if (!isRecord(value) || !Object.prototype.hasOwnProperty.call(value, head)) {
|
|
207
|
+
return value;
|
|
208
|
+
}
|
|
209
|
+
return { ...value, [head]: mapAtChildRef(value[head], rest, replace) };
|
|
210
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GENERATIVE_UI_WHEN_TO_SHOW,
|
|
3
|
+
generativeUIGuideFeatures,
|
|
4
|
+
} from "../a2ui-prompts";
|
|
5
|
+
import { functionCallers } from "./basic-functions";
|
|
6
|
+
import {
|
|
7
|
+
GENERATIVE_UI_AGENT_FUNCTION_CALLS,
|
|
8
|
+
GENERATIVE_UI_RENDER_TOOL,
|
|
9
|
+
} from "./types";
|
|
10
|
+
import type { GenerativeUIManifest } from "./types";
|
|
11
|
+
|
|
12
|
+
export const GENERATIVE_UI_CONTEXT_DESCRIPTION =
|
|
13
|
+
"Generative UI guide: available components, functions, targets, and how to call render_ui.";
|
|
14
|
+
|
|
15
|
+
/** Most characters of the user values of one surface in the guide. */
|
|
16
|
+
const MAX_USER_VALUES_LENGTH = 500;
|
|
17
|
+
|
|
18
|
+
/** Cuts long text and marks the cut with "...". */
|
|
19
|
+
function shorten(text: string) {
|
|
20
|
+
return text.length > MAX_USER_VALUES_LENGTH
|
|
21
|
+
? `${text.slice(0, MAX_USER_VALUES_LENGTH)}...`
|
|
22
|
+
: text;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The guide that the runtime adds as a context entry to a tool-transport run:
|
|
27
|
+
* the `render_ui` rules, the targets, components, functions, and surfaces of
|
|
28
|
+
* the manifest. It is in shared so that the inspector shows the same text.
|
|
29
|
+
*/
|
|
30
|
+
export function buildGenerativeUIPrompt(manifest: GenerativeUIManifest) {
|
|
31
|
+
const targets = manifest.targets
|
|
32
|
+
.map((t) => {
|
|
33
|
+
const place =
|
|
34
|
+
t.kind === "chat"
|
|
35
|
+
? "inside the chat transcript"
|
|
36
|
+
: "a named area of the app";
|
|
37
|
+
const limit = t.components
|
|
38
|
+
? `; only ${t.components.join(", ") || "no components"}`
|
|
39
|
+
: "";
|
|
40
|
+
const description = t.description ? `: ${t.description}` : "";
|
|
41
|
+
return `- "${t.id}" (${place}${limit})${description}`;
|
|
42
|
+
})
|
|
43
|
+
.join("\n");
|
|
44
|
+
const components = Object.entries(manifest.components)
|
|
45
|
+
.map(([name, c]) => {
|
|
46
|
+
const lines = [
|
|
47
|
+
`- **${name}**${c.description ? `: ${c.description}` : ""}`,
|
|
48
|
+
` props: ${JSON.stringify(c.props)}`,
|
|
49
|
+
];
|
|
50
|
+
if (c.events) lines.push(` event props: ${JSON.stringify(c.events)}`);
|
|
51
|
+
if (c.slots)
|
|
52
|
+
lines.push(` slot props (component ids): ${JSON.stringify(c.slots)}`);
|
|
53
|
+
return lines.join("\n");
|
|
54
|
+
})
|
|
55
|
+
.join("\n");
|
|
56
|
+
const functions = Object.entries(manifest.functions)
|
|
57
|
+
.map(([name, f]) => {
|
|
58
|
+
// A built-in function carries its short signature in the description
|
|
59
|
+
// of its parameters; an app function has a JSON Schema.
|
|
60
|
+
const signature = f.parameters.description;
|
|
61
|
+
const args =
|
|
62
|
+
typeof signature === "string" &&
|
|
63
|
+
signature.startsWith("{") &&
|
|
64
|
+
Object.keys(f.parameters).length === 2
|
|
65
|
+
? signature
|
|
66
|
+
: JSON.stringify(f.parameters);
|
|
67
|
+
// A function is for the UI unless marked: the agent calls only what
|
|
68
|
+
// the mark allows.
|
|
69
|
+
const callers = functionCallers(f);
|
|
70
|
+
const who =
|
|
71
|
+
callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS
|
|
72
|
+
? callers.renderer
|
|
73
|
+
? " (UI or agent)"
|
|
74
|
+
: " (agent only)"
|
|
75
|
+
: "";
|
|
76
|
+
return `- **${name}**${who}${f.description ? `: ${f.description}` : ""}\n args: ${args}`;
|
|
77
|
+
})
|
|
78
|
+
.join("\n");
|
|
79
|
+
const surfaces = Object.entries(manifest.surfaces)
|
|
80
|
+
.map(([id, s]) => {
|
|
81
|
+
const state =
|
|
82
|
+
s.status === "deleted"
|
|
83
|
+
? ", deleted: never use this id again"
|
|
84
|
+
: s.status === "failed"
|
|
85
|
+
? ", not created: send a corrected createSurface with this id"
|
|
86
|
+
: "";
|
|
87
|
+
const lines = [`- "${id}" (target "${s.target}"${state})`];
|
|
88
|
+
if (s.dataModel) {
|
|
89
|
+
lines.push(` user values: ${shorten(JSON.stringify(s.dataModel))}`);
|
|
90
|
+
}
|
|
91
|
+
for (const rejection of s.rejected ?? []) {
|
|
92
|
+
lines.push(` rejected: ${rejection}`);
|
|
93
|
+
}
|
|
94
|
+
return lines.join("\n");
|
|
95
|
+
})
|
|
96
|
+
.join("\n");
|
|
97
|
+
const hasSurfaceNotes = Object.values(manifest.surfaces).some(
|
|
98
|
+
(s) => s.dataModel !== undefined || (s.rejected?.length ?? 0) > 0,
|
|
99
|
+
);
|
|
100
|
+
const surfaceNotes = hasSurfaceNotes
|
|
101
|
+
? "User values are what the user entered, by path. Your writes to those paths are ignored. Rejected operations were dropped: send them again with the problem fixed.\n"
|
|
102
|
+
: "";
|
|
103
|
+
|
|
104
|
+
// Rules for functions, events, and templates go only to runs whose manifest
|
|
105
|
+
// has them, so the guide stays small.
|
|
106
|
+
const {
|
|
107
|
+
functions: hasFunctions,
|
|
108
|
+
events,
|
|
109
|
+
templates,
|
|
110
|
+
checks,
|
|
111
|
+
} = generativeUIGuideFeatures(manifest);
|
|
112
|
+
// The agent calls functions only while that path is on.
|
|
113
|
+
const agentCalls = hasFunctions && GENERATIVE_UI_AGENT_FUNCTION_CALLS;
|
|
114
|
+
const operations = [
|
|
115
|
+
'{"version":"v1.0","createSurface":{"surfaceId":"<new id>","dataModel":{...},"components":[{"id":"root","component":"<Name>","children":["<child id>"]}]}}: the first operation of a new surface. "dataModel" and "components" are optional.',
|
|
116
|
+
'{"version":"v1.0","updateComponents":{"surfaceId":"<id>","components":[<component>, ...]}}: add or replace components by id.',
|
|
117
|
+
'{"version":"v1.0","updateDataModel":{"surfaceId":"<id>","path":"/some/path","value":<json>}}: set the value at "path". Always give "value". "value":null deletes the key at "path".',
|
|
118
|
+
'{"version":"v1.0","deleteSurface":{"surfaceId":"<id>"}}: remove the surface.',
|
|
119
|
+
...(agentCalls
|
|
120
|
+
? [
|
|
121
|
+
'{"version":"v1.0","callRendererFunction":{"functionCallId":"<unique id>","callFunction":{"@call":"<function>","args":{...}}}}: run an app function now, with no click. It needs no surface.',
|
|
122
|
+
]
|
|
123
|
+
: []),
|
|
124
|
+
];
|
|
125
|
+
const eventRule = hasFunctions
|
|
126
|
+
? 'Event props take an action. {"functionCall":{"@call":"<function>","args":{...}}} runs an app function in the browser immediately, and you are not told about it. {"event":{"name":"<name>","userMessage":"<text>","context":{...}}} sends the interaction back to you as a user message, with "userMessage" as its first line. "userMessage" is plain text: ${...} is not interpolated in it; put values in "context". Only call functions listed below.'
|
|
127
|
+
: 'Event props take an action: {"event":{"name":"<name>","userMessage":"<text>","context":{...}}} sends the interaction back to you as a user message, with "userMessage" as its first line. "userMessage" is plain text: ${...} is not interpolated in it; put values in "context".';
|
|
128
|
+
const rules = [
|
|
129
|
+
'Components are flat objects: {"id":"...","component":"<Name>", ...props}. Every surface renders from the component with id "root". Reference children by id in slot props.',
|
|
130
|
+
'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.',
|
|
131
|
+
'Stream progressively: put the initial data in "dataModel" and the root in "components" of the createSurface operation, then send one updateComponents operation per child, so the UI appears while you are still writing. The root must already list the ids of its children in its slot props (for example "children":["card-1","card-2"]), even though the children come later. A component that no slot references is never shown.',
|
|
132
|
+
"Updating a component replaces all of its props, so resend every prop.",
|
|
133
|
+
'Prop values are literals or data bindings {"@path":"/data/path"}. Never write {"path":"/data/path"} as a binding.',
|
|
134
|
+
...(events ? [eventRule] : []),
|
|
135
|
+
"To show a different view, create a new surface with a new surfaceId (for example, a checkout form after a cart summary). Update an existing surface only when the user asks to change that same view: then do not send createSurface, use its surfaceId, and pass its existing target. Never reuse an earlier chat surface for a different view, because that replaces the earlier UI and anything the user typed into it.",
|
|
136
|
+
"Never use a surfaceId again, also after deleteSurface.",
|
|
137
|
+
'A prop can also be a function value that updates with the data: {"@call":"formatCurrency","args":{"value":{"@path":"/total"},"currency":"EUR"}}. Only call functions listed below. formatString interpolates ${/path} and ${fn(arg: value)} in its value.',
|
|
138
|
+
'${...} 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"}}}.',
|
|
139
|
+
"For a computed list (chart data, template items) use series. Its description under Functions gives the rules and an example.",
|
|
140
|
+
...(checks
|
|
141
|
+
? [
|
|
142
|
+
'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 failed check shows the message under the input and disables a Button that has the same checks.',
|
|
143
|
+
]
|
|
144
|
+
: []),
|
|
145
|
+
...(templates
|
|
146
|
+
? [
|
|
147
|
+
'To repeat a component for each item of a list, give a multiple slot a template: "children":{"componentId":"row","path":"/items"}. Inside the template, paths are relative to the item ("name", not "/name"). {"@call":"@index"} gives the position of the item, from 0; {"@call":"@index","args":{"offset":1}} counts from 1.',
|
|
148
|
+
]
|
|
149
|
+
: []),
|
|
150
|
+
...(agentCalls
|
|
151
|
+
? [
|
|
152
|
+
"Give every callRendererFunction a new functionCallId. Call only a function marked (UI or agent) or (agent only); a function with no mark is for the UI only. A function marked (agent only) is only for callRendererFunction: do not bind an event to it.",
|
|
153
|
+
'The result of a callRendererFunction comes back to you in a new turn, as a developer message: {"version":"v1.0","rendererFunctionResponse":{"functionCallId":"<id>","value":...}}. If the call failed, it has "error" in place of "value". Do not wait for the result in this reply, and do not guess it.',
|
|
154
|
+
]
|
|
155
|
+
: []),
|
|
156
|
+
];
|
|
157
|
+
|
|
158
|
+
return [
|
|
159
|
+
`## Generative UI
|
|
160
|
+
Call \`${GENERATIVE_UI_RENDER_TOOL}\` to show UI. Arguments: \`target\` first, then \`operations\` (A2UI v1.0 operations, applied in order).
|
|
161
|
+
|
|
162
|
+
${GENERATIVE_UI_WHEN_TO_SHOW}
|
|
163
|
+
|
|
164
|
+
Every operation has "version":"v1.0" and exactly one of:
|
|
165
|
+
${operations.map((op) => `- ${op}`).join("\n")}
|
|
166
|
+
|
|
167
|
+
Rules:
|
|
168
|
+
${rules.map((rule, index) => `${index + 1}. ${rule}`).join("\n")}`,
|
|
169
|
+
`### Targets\n${targets || "- none"}`,
|
|
170
|
+
`### Components\n${components || "- none"}`,
|
|
171
|
+
`### Functions\n${functions || "- none"}`,
|
|
172
|
+
`### Existing surfaces\n${surfaceNotes}${surfaces || "- none"}`,
|
|
173
|
+
].join("\n\n");
|
|
174
|
+
}
|