@copilotkit/shared 2.0.0-rc.5 → 2.0.0-rc.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -15
- package/dist/a2ui-envelope.cjs +3 -3
- package/dist/a2ui-envelope.cjs.map +1 -1
- package/dist/a2ui-envelope.d.cts +1 -1
- package/dist/a2ui-envelope.d.cts.map +1 -1
- package/dist/a2ui-envelope.d.mts +1 -1
- package/dist/a2ui-envelope.d.mts.map +1 -1
- package/dist/a2ui-envelope.mjs +3 -3
- package/dist/a2ui-envelope.mjs.map +1 -1
- package/dist/a2ui-prompts.cjs +21 -62
- package/dist/a2ui-prompts.cjs.map +1 -1
- package/dist/a2ui-prompts.d.cts +8 -1
- package/dist/a2ui-prompts.d.cts.map +1 -1
- package/dist/a2ui-prompts.d.mts +8 -1
- package/dist/a2ui-prompts.d.mts.map +1 -1
- package/dist/a2ui-prompts.mjs +22 -62
- package/dist/a2ui-prompts.mjs.map +1 -1
- package/dist/attachments/types.d.cts +1 -3
- package/dist/attachments/types.d.cts.map +1 -1
- package/dist/attachments/types.d.mts +1 -3
- package/dist/attachments/types.d.mts.map +1 -1
- package/dist/attachments/utils.cjs +16 -5
- package/dist/attachments/utils.cjs.map +1 -1
- package/dist/attachments/utils.d.cts +3 -1
- package/dist/attachments/utils.d.cts.map +1 -1
- package/dist/attachments/utils.d.mts +3 -1
- package/dist/attachments/utils.d.mts.map +1 -1
- package/dist/attachments/utils.mjs +16 -5
- package/dist/attachments/utils.mjs.map +1 -1
- package/dist/finalize-events.cjs +16 -0
- package/dist/finalize-events.cjs.map +1 -1
- package/dist/finalize-events.d.cts.map +1 -1
- package/dist/finalize-events.d.mts.map +1 -1
- package/dist/finalize-events.mjs +16 -0
- package/dist/finalize-events.mjs.map +1 -1
- package/dist/generative-ui/basic-functions.cjs +1 -1
- package/dist/generative-ui/basic-functions.cjs.map +1 -1
- package/dist/generative-ui/basic-functions.mjs +1 -1
- package/dist/generative-ui/basic-functions.mjs.map +1 -1
- package/dist/generative-ui/catalog/catalog-export.cjs +329 -0
- package/dist/generative-ui/catalog/catalog-export.cjs.map +1 -0
- package/dist/generative-ui/catalog/catalog-export.d.cts +92 -0
- package/dist/generative-ui/catalog/catalog-export.d.cts.map +1 -0
- package/dist/generative-ui/catalog/catalog-export.d.mts +92 -0
- package/dist/generative-ui/catalog/catalog-export.d.mts.map +1 -0
- package/dist/generative-ui/catalog/catalog-export.mjs +328 -0
- package/dist/generative-ui/catalog/catalog-export.mjs.map +1 -0
- package/dist/generative-ui/catalog/catalog.cjs +315 -0
- package/dist/generative-ui/catalog/catalog.cjs.map +1 -0
- package/dist/generative-ui/catalog/catalog.d.cts +407 -0
- package/dist/generative-ui/catalog/catalog.d.cts.map +1 -0
- package/dist/generative-ui/catalog/catalog.d.mts +407 -0
- package/dist/generative-ui/catalog/catalog.d.mts.map +1 -0
- package/dist/generative-ui/catalog/catalog.mjs +312 -0
- package/dist/generative-ui/catalog/catalog.mjs.map +1 -0
- package/dist/generative-ui/catalog/errors.cjs +13 -0
- package/dist/generative-ui/catalog/errors.cjs.map +1 -0
- package/dist/generative-ui/catalog/errors.d.cts +46 -0
- package/dist/generative-ui/catalog/errors.d.cts.map +1 -0
- package/dist/generative-ui/catalog/errors.d.mts +46 -0
- package/dist/generative-ui/catalog/errors.d.mts.map +1 -0
- package/dist/generative-ui/catalog/errors.mjs +12 -0
- package/dist/generative-ui/catalog/errors.mjs.map +1 -0
- package/dist/generative-ui/catalog/index.d.mts +6 -0
- package/dist/generative-ui/catalog/json-schema.cjs +16 -0
- package/dist/generative-ui/catalog/json-schema.cjs.map +1 -0
- package/dist/generative-ui/catalog/json-schema.d.cts +12 -0
- package/dist/generative-ui/catalog/json-schema.d.cts.map +1 -0
- package/dist/generative-ui/catalog/json-schema.d.mts +12 -0
- package/dist/generative-ui/catalog/json-schema.d.mts.map +1 -0
- package/dist/generative-ui/catalog/json-schema.mjs +16 -0
- package/dist/generative-ui/catalog/json-schema.mjs.map +1 -0
- package/dist/generative-ui/catalog/refs.cjs +21 -0
- package/dist/generative-ui/catalog/refs.cjs.map +1 -0
- package/dist/generative-ui/catalog/refs.d.cts +55 -0
- package/dist/generative-ui/catalog/refs.d.cts.map +1 -0
- package/dist/generative-ui/catalog/refs.d.mts +55 -0
- package/dist/generative-ui/catalog/refs.d.mts.map +1 -0
- package/dist/generative-ui/catalog/refs.mjs +18 -0
- package/dist/generative-ui/catalog/refs.mjs.map +1 -0
- package/dist/generative-ui/catalog/schema.cjs +74 -0
- package/dist/generative-ui/catalog/schema.cjs.map +1 -0
- package/dist/generative-ui/catalog/schema.d.cts +43 -0
- package/dist/generative-ui/catalog/schema.d.cts.map +1 -0
- package/dist/generative-ui/catalog/schema.d.mts +43 -0
- package/dist/generative-ui/catalog/schema.d.mts.map +1 -0
- package/dist/generative-ui/catalog/schema.mjs +68 -0
- package/dist/generative-ui/catalog/schema.mjs.map +1 -0
- package/dist/generative-ui/child-refs.cjs +3 -3
- package/dist/generative-ui/child-refs.cjs.map +1 -1
- package/dist/generative-ui/child-refs.d.cts.map +1 -1
- package/dist/generative-ui/child-refs.d.mts.map +1 -1
- package/dist/generative-ui/child-refs.mjs +3 -3
- package/dist/generative-ui/child-refs.mjs.map +1 -1
- package/dist/generative-ui/clone-value.cjs +364 -0
- package/dist/generative-ui/clone-value.cjs.map +1 -0
- package/dist/generative-ui/clone-value.d.cts +51 -0
- package/dist/generative-ui/clone-value.d.cts.map +1 -0
- package/dist/generative-ui/clone-value.d.mts +51 -0
- package/dist/generative-ui/clone-value.d.mts.map +1 -0
- package/dist/generative-ui/clone-value.mjs +363 -0
- package/dist/generative-ui/clone-value.mjs.map +1 -0
- package/dist/generative-ui/compact-schema.cjs +187 -0
- package/dist/generative-ui/compact-schema.cjs.map +1 -0
- package/dist/generative-ui/compact-schema.d.cts +55 -0
- package/dist/generative-ui/compact-schema.d.cts.map +1 -0
- package/dist/generative-ui/compact-schema.d.mts +55 -0
- package/dist/generative-ui/compact-schema.d.mts.map +1 -0
- package/dist/generative-ui/compact-schema.mjs +185 -0
- package/dist/generative-ui/compact-schema.mjs.map +1 -0
- package/dist/generative-ui/index.cjs +286 -0
- package/dist/generative-ui/index.d.cts +39 -0
- package/dist/generative-ui/index.d.mts +41 -0
- package/dist/generative-ui/index.mjs +40 -0
- package/dist/generative-ui/is-record.cjs +6 -1
- package/dist/generative-ui/is-record.cjs.map +1 -1
- package/dist/generative-ui/is-record.d.cts +8 -0
- package/dist/generative-ui/is-record.d.cts.map +1 -0
- package/dist/generative-ui/is-record.d.mts +8 -0
- package/dist/generative-ui/is-record.d.mts.map +1 -0
- package/dist/generative-ui/is-record.mjs +6 -2
- package/dist/generative-ui/is-record.mjs.map +1 -1
- package/dist/generative-ui/prompt-spec.cjs +225 -0
- package/dist/generative-ui/prompt-spec.cjs.map +1 -0
- package/dist/generative-ui/prompt-spec.d.cts +94 -0
- package/dist/generative-ui/prompt-spec.d.cts.map +1 -0
- package/dist/generative-ui/prompt-spec.d.mts +94 -0
- package/dist/generative-ui/prompt-spec.d.mts.map +1 -0
- package/dist/generative-ui/prompt-spec.mjs +220 -0
- package/dist/generative-ui/prompt-spec.mjs.map +1 -0
- package/dist/generative-ui/prompt.cjs +10 -36
- package/dist/generative-ui/prompt.cjs.map +1 -1
- package/dist/generative-ui/prompt.d.cts +2 -1
- package/dist/generative-ui/prompt.d.cts.map +1 -1
- package/dist/generative-ui/prompt.d.mts +2 -1
- package/dist/generative-ui/prompt.d.mts.map +1 -1
- package/dist/generative-ui/prompt.mjs +12 -38
- package/dist/generative-ui/prompt.mjs.map +1 -1
- package/dist/generative-ui/render-ui-args.cjs +1 -0
- package/dist/generative-ui/render-ui-args.cjs.map +1 -1
- package/dist/generative-ui/render-ui-args.d.cts.map +1 -1
- package/dist/generative-ui/render-ui-args.d.mts.map +1 -1
- package/dist/generative-ui/render-ui-args.mjs +1 -0
- package/dist/generative-ui/render-ui-args.mjs.map +1 -1
- package/dist/generative-ui/schema-render.cjs +243 -0
- package/dist/generative-ui/schema-render.cjs.map +1 -0
- package/dist/generative-ui/schema-render.d.cts +44 -0
- package/dist/generative-ui/schema-render.d.cts.map +1 -0
- package/dist/generative-ui/schema-render.d.mts +44 -0
- package/dist/generative-ui/schema-render.d.mts.map +1 -0
- package/dist/generative-ui/schema-render.mjs +240 -0
- package/dist/generative-ui/schema-render.mjs.map +1 -0
- package/dist/generative-ui/standard/chart-config.cjs +347 -0
- package/dist/generative-ui/standard/chart-config.cjs.map +1 -0
- package/dist/generative-ui/standard/chart-config.d.cts +97 -0
- package/dist/generative-ui/standard/chart-config.d.cts.map +1 -0
- package/dist/generative-ui/standard/chart-config.d.mts +97 -0
- package/dist/generative-ui/standard/chart-config.d.mts.map +1 -0
- package/dist/generative-ui/standard/chart-config.mjs +342 -0
- package/dist/generative-ui/standard/chart-config.mjs.map +1 -0
- package/dist/generative-ui/standard/chart.cjs +56 -0
- package/dist/generative-ui/standard/chart.cjs.map +1 -0
- package/dist/generative-ui/standard/chart.d.cts +62 -0
- package/dist/generative-ui/standard/chart.d.cts.map +1 -0
- package/dist/generative-ui/standard/chart.d.mts +62 -0
- package/dist/generative-ui/standard/chart.d.mts.map +1 -0
- package/dist/generative-ui/standard/chart.mjs +54 -0
- package/dist/generative-ui/standard/chart.mjs.map +1 -0
- package/dist/generative-ui/standard/checks.cjs +74 -0
- package/dist/generative-ui/standard/checks.cjs.map +1 -0
- package/dist/generative-ui/standard/checks.d.cts +56 -0
- package/dist/generative-ui/standard/checks.d.cts.map +1 -0
- package/dist/generative-ui/standard/checks.d.mts +56 -0
- package/dist/generative-ui/standard/checks.d.mts.map +1 -0
- package/dist/generative-ui/standard/checks.mjs +71 -0
- package/dist/generative-ui/standard/checks.mjs.map +1 -0
- package/dist/generative-ui/standard/components.cjs +23 -0
- package/dist/generative-ui/standard/components.cjs.map +1 -0
- package/dist/generative-ui/standard/components.d.cts +24 -0
- package/dist/generative-ui/standard/components.d.cts.map +1 -0
- package/dist/generative-ui/standard/components.d.mts +24 -0
- package/dist/generative-ui/standard/components.d.mts.map +1 -0
- package/dist/generative-ui/standard/components.mjs +22 -0
- package/dist/generative-ui/standard/components.mjs.map +1 -0
- package/dist/generative-ui/standard/composites.cjs +143 -0
- package/dist/generative-ui/standard/composites.cjs.map +1 -0
- package/dist/generative-ui/standard/composites.d.cts +233 -0
- package/dist/generative-ui/standard/composites.d.cts.map +1 -0
- package/dist/generative-ui/standard/composites.d.mts +233 -0
- package/dist/generative-ui/standard/composites.d.mts.map +1 -0
- package/dist/generative-ui/standard/composites.mjs +132 -0
- package/dist/generative-ui/standard/composites.mjs.map +1 -0
- package/dist/generative-ui/standard/data.cjs +176 -0
- package/dist/generative-ui/standard/data.cjs.map +1 -0
- package/dist/generative-ui/standard/data.d.cts +365 -0
- package/dist/generative-ui/standard/data.d.cts.map +1 -0
- package/dist/generative-ui/standard/data.d.mts +365 -0
- package/dist/generative-ui/standard/data.d.mts.map +1 -0
- package/dist/generative-ui/standard/data.mjs +167 -0
- package/dist/generative-ui/standard/data.mjs.map +1 -0
- package/dist/generative-ui/standard/declarations.cjs +40 -0
- package/dist/generative-ui/standard/declarations.cjs.map +1 -0
- package/dist/generative-ui/standard/declarations.d.cts +2570 -0
- package/dist/generative-ui/standard/declarations.d.cts.map +1 -0
- package/dist/generative-ui/standard/declarations.d.mts +2571 -0
- package/dist/generative-ui/standard/declarations.d.mts.map +1 -0
- package/dist/generative-ui/standard/declarations.mjs +39 -0
- package/dist/generative-ui/standard/declarations.mjs.map +1 -0
- package/dist/generative-ui/standard/feedback.cjs +97 -0
- package/dist/generative-ui/standard/feedback.cjs.map +1 -0
- package/dist/generative-ui/standard/feedback.d.cts +133 -0
- package/dist/generative-ui/standard/feedback.d.cts.map +1 -0
- package/dist/generative-ui/standard/feedback.d.mts +133 -0
- package/dist/generative-ui/standard/feedback.d.mts.map +1 -0
- package/dist/generative-ui/standard/feedback.mjs +90 -0
- package/dist/generative-ui/standard/feedback.mjs.map +1 -0
- package/dist/generative-ui/standard/index.d.mts +20 -0
- package/dist/generative-ui/standard/inputs.cjs +333 -0
- package/dist/generative-ui/standard/inputs.cjs.map +1 -0
- package/dist/generative-ui/standard/inputs.d.cts +1128 -0
- package/dist/generative-ui/standard/inputs.d.cts.map +1 -0
- package/dist/generative-ui/standard/inputs.d.mts +1128 -0
- package/dist/generative-ui/standard/inputs.d.mts.map +1 -0
- package/dist/generative-ui/standard/inputs.mjs +318 -0
- package/dist/generative-ui/standard/inputs.mjs.map +1 -0
- package/dist/generative-ui/standard/layout.cjs +289 -0
- package/dist/generative-ui/standard/layout.cjs.map +1 -0
- package/dist/generative-ui/standard/layout.d.cts +1974 -0
- package/dist/generative-ui/standard/layout.d.cts.map +1 -0
- package/dist/generative-ui/standard/layout.d.mts +1975 -0
- package/dist/generative-ui/standard/layout.d.mts.map +1 -0
- package/dist/generative-ui/standard/layout.mjs +269 -0
- package/dist/generative-ui/standard/layout.mjs.map +1 -0
- package/dist/generative-ui/standard/map-helpers.cjs +104 -0
- package/dist/generative-ui/standard/map-helpers.cjs.map +1 -0
- package/dist/generative-ui/standard/map-helpers.d.cts +88 -0
- package/dist/generative-ui/standard/map-helpers.d.cts.map +1 -0
- package/dist/generative-ui/standard/map-helpers.d.mts +88 -0
- package/dist/generative-ui/standard/map-helpers.d.mts.map +1 -0
- package/dist/generative-ui/standard/map-helpers.mjs +95 -0
- package/dist/generative-ui/standard/map-helpers.mjs.map +1 -0
- package/dist/generative-ui/standard/map.cjs +27 -0
- package/dist/generative-ui/standard/map.cjs.map +1 -0
- package/dist/generative-ui/standard/map.d.cts +31 -0
- package/dist/generative-ui/standard/map.d.cts.map +1 -0
- package/dist/generative-ui/standard/map.d.mts +31 -0
- package/dist/generative-ui/standard/map.d.mts.map +1 -0
- package/dist/generative-ui/standard/map.mjs +25 -0
- package/dist/generative-ui/standard/map.mjs.map +1 -0
- package/dist/generative-ui/standard/media.cjs +215 -0
- package/dist/generative-ui/standard/media.cjs.map +1 -0
- package/dist/generative-ui/standard/media.d.cts +396 -0
- package/dist/generative-ui/standard/media.d.cts.map +1 -0
- package/dist/generative-ui/standard/media.d.mts +396 -0
- package/dist/generative-ui/standard/media.d.mts.map +1 -0
- package/dist/generative-ui/standard/media.mjs +205 -0
- package/dist/generative-ui/standard/media.mjs.map +1 -0
- package/dist/generative-ui/standard/parameter-order.cjs +231 -0
- package/dist/generative-ui/standard/parameter-order.cjs.map +1 -0
- package/dist/generative-ui/standard/parameter-order.d.cts +84 -0
- package/dist/generative-ui/standard/parameter-order.d.cts.map +1 -0
- package/dist/generative-ui/standard/parameter-order.d.mts +84 -0
- package/dist/generative-ui/standard/parameter-order.d.mts.map +1 -0
- package/dist/generative-ui/standard/parameter-order.mjs +230 -0
- package/dist/generative-ui/standard/parameter-order.mjs.map +1 -0
- package/dist/generative-ui/standard/style-helpers.cjs +151 -0
- package/dist/generative-ui/standard/style-helpers.cjs.map +1 -0
- package/dist/generative-ui/standard/style-helpers.d.cts +56 -0
- package/dist/generative-ui/standard/style-helpers.d.cts.map +1 -0
- package/dist/generative-ui/standard/style-helpers.d.mts +56 -0
- package/dist/generative-ui/standard/style-helpers.d.mts.map +1 -0
- package/dist/generative-ui/standard/style-helpers.mjs +142 -0
- package/dist/generative-ui/standard/style-helpers.mjs.map +1 -0
- package/dist/generative-ui/standard/styles.cjs +62 -0
- package/dist/generative-ui/standard/styles.cjs.map +1 -0
- package/dist/generative-ui/standard/styles.d.cts +17 -0
- package/dist/generative-ui/standard/styles.d.cts.map +1 -0
- package/dist/generative-ui/standard/styles.d.mts +17 -0
- package/dist/generative-ui/standard/styles.d.mts.map +1 -0
- package/dist/generative-ui/standard/styles.mjs +60 -0
- package/dist/generative-ui/standard/styles.mjs.map +1 -0
- package/dist/generative-ui/standard/text.cjs +226 -0
- package/dist/generative-ui/standard/text.cjs.map +1 -0
- package/dist/generative-ui/standard/text.d.cts +522 -0
- package/dist/generative-ui/standard/text.d.cts.map +1 -0
- package/dist/generative-ui/standard/text.d.mts +522 -0
- package/dist/generative-ui/standard/text.d.mts.map +1 -0
- package/dist/generative-ui/standard/text.mjs +209 -0
- package/dist/generative-ui/standard/text.mjs.map +1 -0
- package/dist/generative-ui/standard/theme.cjs +115 -0
- package/dist/generative-ui/standard/theme.cjs.map +1 -0
- package/dist/generative-ui/standard/theme.d.cts +60 -0
- package/dist/generative-ui/standard/theme.d.cts.map +1 -0
- package/dist/generative-ui/standard/theme.d.mts +60 -0
- package/dist/generative-ui/standard/theme.d.mts.map +1 -0
- package/dist/generative-ui/standard/theme.mjs +112 -0
- package/dist/generative-ui/standard/theme.mjs.map +1 -0
- package/dist/generative-ui/standard/tokens.cjs +336 -0
- package/dist/generative-ui/standard/tokens.cjs.map +1 -0
- package/dist/generative-ui/standard/tokens.d.cts +76 -0
- package/dist/generative-ui/standard/tokens.d.cts.map +1 -0
- package/dist/generative-ui/standard/tokens.d.mts +76 -0
- package/dist/generative-ui/standard/tokens.d.mts.map +1 -0
- package/dist/generative-ui/standard/tokens.mjs +305 -0
- package/dist/generative-ui/standard/tokens.mjs.map +1 -0
- package/dist/generative-ui/standard/url.cjs +54 -0
- package/dist/generative-ui/standard/url.cjs.map +1 -0
- package/dist/generative-ui/standard/url.d.cts +32 -0
- package/dist/generative-ui/standard/url.d.cts.map +1 -0
- package/dist/generative-ui/standard/url.d.mts +32 -0
- package/dist/generative-ui/standard/url.d.mts.map +1 -0
- package/dist/generative-ui/standard/url.mjs +50 -0
- package/dist/generative-ui/standard/url.mjs.map +1 -0
- package/dist/generative-ui/thrown.cjs +69 -0
- package/dist/generative-ui/thrown.cjs.map +1 -0
- package/dist/generative-ui/thrown.d.cts +21 -0
- package/dist/generative-ui/thrown.d.cts.map +1 -0
- package/dist/generative-ui/thrown.d.mts +21 -0
- package/dist/generative-ui/thrown.d.mts.map +1 -0
- package/dist/generative-ui/thrown.mjs +67 -0
- package/dist/generative-ui/thrown.mjs.map +1 -0
- package/dist/generative-ui/types.cjs +2 -2
- package/dist/generative-ui/types.cjs.map +1 -1
- package/dist/generative-ui/types.d.cts +20 -7
- package/dist/generative-ui/types.d.cts.map +1 -1
- package/dist/generative-ui/types.d.mts +20 -7
- package/dist/generative-ui/types.d.mts.map +1 -1
- package/dist/generative-ui/types.mjs +2 -2
- package/dist/generative-ui/types.mjs.map +1 -1
- package/dist/generative-ui/validate-operation.cjs +2 -2
- package/dist/generative-ui/validate-operation.cjs.map +1 -1
- package/dist/generative-ui/validate-operation.mjs +2 -2
- package/dist/generative-ui/validate-operation.mjs.map +1 -1
- package/dist/index.cjs +18 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -17
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +18 -17
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +10 -8
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1233 -456
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/standard-schema.cjs +20 -7
- package/dist/standard-schema.cjs.map +1 -1
- package/dist/standard-schema.d.cts +15 -16
- package/dist/standard-schema.d.cts.map +1 -1
- package/dist/standard-schema.d.mts +15 -16
- package/dist/standard-schema.d.mts.map +1 -1
- package/dist/standard-schema.mjs +20 -8
- package/dist/standard-schema.mjs.map +1 -1
- package/dist/telemetry/lambda-client.cjs +1 -1
- package/dist/telemetry/lambda-client.cjs.map +1 -1
- package/dist/telemetry/lambda-client.d.cts.map +1 -1
- package/dist/telemetry/lambda-client.d.mts.map +1 -1
- package/dist/telemetry/lambda-client.mjs +1 -1
- package/dist/telemetry/lambda-client.mjs.map +1 -1
- package/dist/telemetry/telemetry-disabled.cjs +0 -5
- package/dist/telemetry/telemetry-disabled.cjs.map +1 -1
- package/dist/telemetry/telemetry-disabled.d.cts +0 -5
- package/dist/telemetry/telemetry-disabled.d.cts.map +1 -1
- package/dist/telemetry/telemetry-disabled.d.mts +0 -5
- package/dist/telemetry/telemetry-disabled.d.mts.map +1 -1
- package/dist/telemetry/telemetry-disabled.mjs +0 -5
- package/dist/telemetry/telemetry-disabled.mjs.map +1 -1
- package/dist/types/message.d.cts +1 -18
- package/dist/types/message.d.cts.map +1 -1
- package/dist/types/message.d.mts +1 -18
- package/dist/types/message.d.mts.map +1 -1
- package/dist/utils/errors.cjs +5 -42
- package/dist/utils/errors.cjs.map +1 -1
- package/dist/utils/errors.d.cts +16 -34
- package/dist/utils/errors.d.cts.map +1 -1
- package/dist/utils/errors.d.mts +16 -34
- package/dist/utils/errors.d.mts.map +1 -1
- package/dist/utils/errors.mjs +6 -41
- package/dist/utils/errors.mjs.map +1 -1
- package/dist/utils/index.cjs +0 -2
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +5 -7
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.mts +5 -7
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.mjs +4 -6
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/inspector-visibility.cjs +25 -3
- package/dist/utils/inspector-visibility.cjs.map +1 -1
- package/dist/utils/inspector-visibility.d.cts +26 -3
- package/dist/utils/inspector-visibility.d.cts.map +1 -1
- package/dist/utils/inspector-visibility.d.mts +26 -3
- package/dist/utils/inspector-visibility.d.mts.map +1 -1
- package/dist/utils/inspector-visibility.mjs +25 -4
- package/dist/utils/inspector-visibility.mjs.map +1 -1
- package/dist/utils/json-schema.cjs +4 -79
- package/dist/utils/json-schema.cjs.map +1 -1
- package/dist/utils/json-schema.d.cts +1 -4
- package/dist/utils/json-schema.d.cts.map +1 -1
- package/dist/utils/json-schema.d.mts +1 -4
- package/dist/utils/json-schema.d.mts.map +1 -1
- package/dist/utils/json-schema.mjs +5 -78
- package/dist/utils/json-schema.mjs.map +1 -1
- package/dist/utils/random-id.cjs +13 -26
- package/dist/utils/random-id.cjs.map +1 -1
- package/dist/utils/random-id.d.cts +6 -3
- package/dist/utils/random-id.d.cts.map +1 -1
- package/dist/utils/random-id.d.mts +6 -3
- package/dist/utils/random-id.d.mts.map +1 -1
- package/dist/utils/random-id.mjs +14 -25
- package/dist/utils/random-id.mjs.map +1 -1
- package/dist/utils/types.cjs.map +1 -1
- package/dist/utils/types.d.cts +5 -12
- package/dist/utils/types.d.cts.map +1 -1
- package/dist/utils/types.d.mts +5 -12
- package/dist/utils/types.d.mts.map +1 -1
- package/dist/utils/types.mjs.map +1 -1
- package/package.json +19 -32
- package/scripts/verify-cjs-exports.cjs +1 -1
- package/src/__tests__/a2ui-envelope.test.ts +38 -13
- package/src/__tests__/a2ui-prompts.test.ts +47 -14
- package/src/__tests__/fixtures/prompt-goldens.json +354 -0
- package/src/__tests__/prompt-spec.test.ts +191 -0
- package/src/__tests__/root-entry-browser-safety.test.ts +5 -7
- package/src/__tests__/schema-render.test.ts +323 -0
- package/src/__tests__/standard-schema.test.ts +61 -101
- package/src/a2ui-envelope.ts +9 -7
- package/src/a2ui-prompts.ts +47 -96
- package/src/attachments/__tests__/utils.test.ts +22 -0
- package/src/attachments/types.ts +1 -3
- package/src/attachments/utils.ts +23 -5
- package/src/finalize-events.ts +16 -0
- package/src/generative-ui/__tests__/clone-value-differential.test.ts +480 -0
- package/src/generative-ui/__tests__/clone-value.test.ts +226 -0
- package/src/generative-ui/__tests__/render-ui-args.test.ts +7 -7
- package/src/generative-ui/__tests__/validate-operation.test.ts +19 -13
- package/src/generative-ui/base.ts +9 -0
- package/src/generative-ui/basic-functions.ts +1 -1
- package/src/generative-ui/catalog/catalog-export.ts +478 -0
- package/src/generative-ui/catalog/catalog.ts +1167 -0
- package/src/generative-ui/catalog/errors.ts +102 -0
- package/src/generative-ui/catalog/index.ts +6 -0
- package/src/generative-ui/catalog/json-schema.ts +14 -0
- package/src/generative-ui/catalog/refs.ts +87 -0
- package/src/generative-ui/catalog/schema.ts +107 -0
- package/src/generative-ui/child-refs.ts +5 -4
- package/src/generative-ui/clone-value.ts +511 -0
- package/src/generative-ui/compact-schema.ts +277 -0
- package/src/generative-ui/index.ts +14 -0
- package/src/generative-ui/is-record.ts +6 -1
- package/src/generative-ui/prompt-spec.ts +335 -0
- package/src/generative-ui/prompt.ts +25 -75
- package/src/generative-ui/render-ui-args.ts +3 -0
- package/src/generative-ui/schema-render.ts +378 -0
- package/src/generative-ui/standard/__tests__/standard-helpers.test.ts +407 -0
- package/src/generative-ui/standard/__tests__/theme.test.ts +61 -0
- package/src/generative-ui/standard/__tests__/tokens.test.ts +139 -0
- package/src/generative-ui/standard/chart-config.ts +434 -0
- package/src/generative-ui/standard/chart.ts +79 -0
- package/src/generative-ui/standard/checks.ts +98 -0
- package/src/generative-ui/standard/components.ts +35 -0
- package/src/generative-ui/standard/composites.ts +158 -0
- package/src/generative-ui/standard/data.ts +213 -0
- package/src/generative-ui/standard/declarations.ts +57 -0
- package/src/generative-ui/standard/feedback.ts +105 -0
- package/src/generative-ui/standard/index.ts +55 -0
- package/src/generative-ui/standard/inputs.ts +423 -0
- package/src/generative-ui/standard/layout.ts +312 -0
- package/src/generative-ui/standard/map-helpers.ts +155 -0
- package/src/generative-ui/standard/map.ts +32 -0
- package/src/generative-ui/standard/media.ts +265 -0
- package/src/generative-ui/standard/parameter-order.ts +155 -0
- package/src/generative-ui/standard/style-helpers.ts +170 -0
- package/src/generative-ui/standard/styles.ts +79 -0
- package/src/generative-ui/standard/text.ts +210 -0
- package/src/generative-ui/standard/theme.ts +198 -0
- package/src/generative-ui/standard/tokens.ts +317 -0
- package/src/generative-ui/standard/url.ts +51 -0
- package/src/generative-ui/thrown.ts +90 -0
- package/src/generative-ui/types.ts +23 -7
- package/src/generative-ui/validate-operation.ts +2 -2
- package/src/index.ts +9 -17
- package/src/standard-schema.ts +24 -27
- package/src/telemetry/lambda-client.ts +8 -3
- package/src/telemetry/model-host.test.ts +2 -5
- package/src/telemetry/telemetry-disabled.ts +0 -5
- package/src/types/message.ts +1 -19
- package/src/utils/__tests__/errors.test.ts +44 -0
- package/src/utils/__tests__/json-schema.test.ts +3 -479
- package/src/utils/__tests__/random-id.test.ts +37 -0
- package/src/utils/errors.ts +28 -85
- package/src/utils/index.ts +0 -2
- package/src/utils/inspector-visibility.test.ts +26 -0
- package/src/utils/inspector-visibility.ts +35 -3
- package/src/utils/json-schema.ts +5 -152
- package/src/utils/random-id.ts +17 -37
- package/src/utils/types.ts +4 -11
- package/tsconfig.json +3 -1
- package/tsdown.config.ts +2 -19
- package/dist/event-transforms/index.cjs +0 -15
- package/dist/event-transforms/index.d.cts +0 -4
- package/dist/event-transforms/index.d.mts +0 -4
- package/dist/event-transforms/index.mjs +0 -5
- package/dist/event-transforms/open-generative-ui-middleware.cjs +0 -286
- package/dist/event-transforms/open-generative-ui-middleware.cjs.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.d.cts +0 -60
- package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.d.mts +0 -60
- package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.mjs +0 -283
- package/dist/event-transforms/open-generative-ui-middleware.mjs.map +0 -1
- package/dist/event-transforms/recorded-events.cjs +0 -59
- package/dist/event-transforms/recorded-events.cjs.map +0 -1
- package/dist/event-transforms/recorded-events.d.cts +0 -23
- package/dist/event-transforms/recorded-events.d.cts.map +0 -1
- package/dist/event-transforms/recorded-events.d.mts +0 -23
- package/dist/event-transforms/recorded-events.d.mts.map +0 -1
- package/dist/event-transforms/recorded-events.mjs +0 -58
- package/dist/event-transforms/recorded-events.mjs.map +0 -1
- package/dist/telemetry/events.d.cts +0 -72
- package/dist/telemetry/events.d.cts.map +0 -1
- package/dist/telemetry/events.d.mts +0 -72
- package/dist/telemetry/events.d.mts.map +0 -1
- package/dist/telemetry/index.cjs +0 -18
- package/dist/telemetry/index.d.cts +0 -5
- package/dist/telemetry/index.d.mts +0 -5
- package/dist/telemetry/index.mjs +0 -6
- package/dist/telemetry/telemetry-client.cjs +0 -165
- package/dist/telemetry/telemetry-client.cjs.map +0 -1
- package/dist/telemetry/telemetry-client.d.cts +0 -87
- package/dist/telemetry/telemetry-client.d.cts.map +0 -1
- package/dist/telemetry/telemetry-client.d.mts +0 -87
- package/dist/telemetry/telemetry-client.d.mts.map +0 -1
- package/dist/telemetry/telemetry-client.mjs +0 -164
- package/dist/telemetry/telemetry-client.mjs.map +0 -1
- package/dist/telemetry/utils.cjs +0 -14
- package/dist/telemetry/utils.cjs.map +0 -1
- package/dist/telemetry/utils.mjs +0 -13
- package/dist/telemetry/utils.mjs.map +0 -1
- package/dist/utils/conditions.cjs +0 -32
- package/dist/utils/conditions.cjs.map +0 -1
- package/dist/utils/conditions.d.cts +0 -31
- package/dist/utils/conditions.d.cts.map +0 -1
- package/dist/utils/conditions.d.mts +0 -31
- package/dist/utils/conditions.d.mts.map +0 -1
- package/dist/utils/conditions.mjs +0 -31
- package/dist/utils/conditions.mjs.map +0 -1
- package/dist/utils/console-styling.cjs +0 -91
- package/dist/utils/console-styling.cjs.map +0 -1
- package/dist/utils/console-styling.d.cts +0 -65
- package/dist/utils/console-styling.d.cts.map +0 -1
- package/dist/utils/console-styling.d.mts +0 -65
- package/dist/utils/console-styling.d.mts.map +0 -1
- package/dist/utils/console-styling.mjs +0 -85
- package/dist/utils/console-styling.mjs.map +0 -1
- package/src/__tests__/zod-regression.test.ts +0 -319
- package/src/event-transforms/index.ts +0 -5
- package/src/event-transforms/open-generative-ui-middleware.ts +0 -392
- package/src/event-transforms/recorded-events.test.ts +0 -166
- package/src/event-transforms/recorded-events.ts +0 -74
- package/src/telemetry/events.ts +0 -68
- package/src/telemetry/index.ts +0 -9
- package/src/telemetry/telemetry-blank-license-identity.test.ts +0 -128
- package/src/telemetry/telemetry-client.test.ts +0 -798
- package/src/telemetry/telemetry-client.ts +0 -328
- package/src/telemetry/utils.ts +0 -15
- package/src/utils/__tests__/conditions.test.ts +0 -161
- package/src/utils/conditions.ts +0 -116
- package/src/utils/console-styling.ts +0 -126
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function(global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitShared = {}), global.
|
|
5
|
-
})(this, function(exports,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('partial-json'), require('@ag-ui/client')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'partial-json', '@ag-ui/client'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitShared = {}), global.PartialJSON,global.AgUIClient));
|
|
5
|
+
})(this, function(exports, partial_json, _ag_ui_client) {
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
7
7
|
//#region \0rolldown/runtime.js
|
|
8
8
|
var __create = Object.create;
|
|
@@ -58,118 +58,6 @@ partial_json = __toESM(partial_json);
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/utils/conditions.ts
|
|
63
|
-
function executeConditions({ conditions, value }) {
|
|
64
|
-
if (!(conditions === null || conditions === void 0 ? void 0 : conditions.length)) return true;
|
|
65
|
-
return conditions.every((condition) => executeCondition(condition, value));
|
|
66
|
-
}
|
|
67
|
-
function executeCondition(condition, value) {
|
|
68
|
-
const targetValue = condition.path ? getValueFromPath(value, condition.path) : value;
|
|
69
|
-
switch (condition.rule) {
|
|
70
|
-
case "AND": return condition.conditions.every((c) => executeCondition(c, value));
|
|
71
|
-
case "OR": return condition.conditions.some((c) => executeCondition(c, value));
|
|
72
|
-
case "NOT": return !condition.conditions.every((c) => executeCondition(c, value));
|
|
73
|
-
case "EQUALS": return targetValue === condition.value;
|
|
74
|
-
case "NOT_EQUALS": return targetValue !== condition.value;
|
|
75
|
-
case "GREATER_THAN": return targetValue > condition.value;
|
|
76
|
-
case "LESS_THAN": return targetValue < condition.value;
|
|
77
|
-
case "CONTAINS": return Array.isArray(targetValue) && targetValue.includes(condition.value);
|
|
78
|
-
case "NOT_CONTAINS": return Array.isArray(targetValue) && !targetValue.includes(condition.value);
|
|
79
|
-
case "MATCHES": return new RegExp(condition.value).test(String(targetValue));
|
|
80
|
-
case "STARTS_WITH": return String(targetValue).startsWith(condition.value);
|
|
81
|
-
case "ENDS_WITH": return String(targetValue).endsWith(condition.value);
|
|
82
|
-
case "EXISTS": return targetValue !== void 0 && targetValue !== null;
|
|
83
|
-
case "NOT_EXISTS": return targetValue === void 0 || targetValue === null;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function getValueFromPath(obj, path) {
|
|
87
|
-
return path.split(".").reduce((acc, part) => acc === null || acc === void 0 ? void 0 : acc[part], obj);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
//#endregion
|
|
91
|
-
//#region src/utils/console-styling.ts
|
|
92
|
-
/**
|
|
93
|
-
* Console styling utilities for CopilotKit branded messages
|
|
94
|
-
* Provides consistent, readable colors across light and dark console themes
|
|
95
|
-
*/
|
|
96
|
-
/**
|
|
97
|
-
* Color palette optimized for console readability
|
|
98
|
-
*/
|
|
99
|
-
const ConsoleColors = {
|
|
100
|
-
primary: "#007acc",
|
|
101
|
-
success: "#22c55e",
|
|
102
|
-
feature: "#a855f7",
|
|
103
|
-
cta: "#ef4444",
|
|
104
|
-
info: "#06b6d4",
|
|
105
|
-
inherit: "inherit",
|
|
106
|
-
warning: "#f59e0b"
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Console style templates for common patterns
|
|
110
|
-
*/
|
|
111
|
-
const ConsoleStyles = {
|
|
112
|
-
header: `color: ${ConsoleColors.warning}; font-weight: bold; font-size: 16px;`,
|
|
113
|
-
section: `color: ${ConsoleColors.success}; font-weight: bold;`,
|
|
114
|
-
highlight: `color: ${ConsoleColors.feature}; font-weight: bold;`,
|
|
115
|
-
cta: `color: ${ConsoleColors.success}; font-weight: bold;`,
|
|
116
|
-
info: `color: ${ConsoleColors.info}; font-weight: bold;`,
|
|
117
|
-
link: `color: ${ConsoleColors.primary}; text-decoration: underline;`,
|
|
118
|
-
body: `color: ${ConsoleColors.inherit};`,
|
|
119
|
-
warning: `color: ${ConsoleColors.cta}; font-weight: bold;`
|
|
120
|
-
};
|
|
121
|
-
/**
|
|
122
|
-
* Styled console message for CopilotKit Platform promotion
|
|
123
|
-
* Displays a beautiful, branded advertisement in the console
|
|
124
|
-
*/
|
|
125
|
-
function logCopilotKitPlatformMessage() {
|
|
126
|
-
console.log(`%cCopilotKit Warning%c
|
|
127
|
-
|
|
128
|
-
useCopilotChatHeadless_c provides full compatibility with CopilotKit's newly released Headless UI feature set. Headless UI requires a CopilotKit Intelligence license key, available for free at:
|
|
129
|
-
|
|
130
|
-
%chttps://dashboard.operations.copilotkit.ai%c
|
|
131
|
-
|
|
132
|
-
Alternatively, useCopilotChat is available for basic programmatic control, and does not require a license key.
|
|
133
|
-
|
|
134
|
-
To learn more about CopilotKit Intelligence, read the documentation here:
|
|
135
|
-
|
|
136
|
-
%chttps://docs.copilotkit.ai/intelligence/overview%c`, ConsoleStyles.header, ConsoleStyles.body, ConsoleStyles.cta, ConsoleStyles.body, ConsoleStyles.link, ConsoleStyles.body);
|
|
137
|
-
}
|
|
138
|
-
function publicApiKeyRequired(feature) {
|
|
139
|
-
console.log(`
|
|
140
|
-
%cCopilotKit Warning%c \n
|
|
141
|
-
In order to use ${feature}, you need to add your CopilotKit license key, available for free at https://dashboard.operations.copilotkit.ai.
|
|
142
|
-
`.trim(), ConsoleStyles.header, ConsoleStyles.body);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Create a styled console message with custom content
|
|
146
|
-
*
|
|
147
|
-
* @param template - Template string with %c placeholders
|
|
148
|
-
* @param styles - Array of style strings matching the %c placeholders
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* logStyled(
|
|
153
|
-
* '%cCopilotKit%c Welcome to the platform!',
|
|
154
|
-
* [ConsoleStyles.header, ConsoleStyles.body]
|
|
155
|
-
* );
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
|
-
function logStyled(template, styles) {
|
|
159
|
-
console.log(template, ...styles);
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Quick styled console methods for common use cases
|
|
163
|
-
*/
|
|
164
|
-
const styledConsole = {
|
|
165
|
-
success: (message) => logStyled(`%c✅ ${message}`, [ConsoleStyles.section]),
|
|
166
|
-
info: (message) => logStyled(`%cℹ️ ${message}`, [ConsoleStyles.info]),
|
|
167
|
-
feature: (message) => logStyled(`%c✨ ${message}`, [ConsoleStyles.highlight]),
|
|
168
|
-
cta: (message) => logStyled(`%c🚀 ${message}`, [ConsoleStyles.cta]),
|
|
169
|
-
logCopilotKitPlatformMessage,
|
|
170
|
-
publicApiKeyRequired
|
|
171
|
-
};
|
|
172
|
-
|
|
173
61
|
//#endregion
|
|
174
62
|
//#region src/utils/errors.ts
|
|
175
63
|
let Severity = /* @__PURE__ */ function(Severity) {
|
|
@@ -191,7 +79,6 @@ In order to use ${feature}, you need to add your CopilotKit license key, availab
|
|
|
191
79
|
COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR: "CopilotKitRemoteEndpointDiscoveryError",
|
|
192
80
|
COPILOT_KIT_AGENT_DISCOVERY_ERROR: "CopilotKitAgentDiscoveryError",
|
|
193
81
|
COPILOT_KIT_LOW_LEVEL_ERROR: "CopilotKitLowLevelError",
|
|
194
|
-
COPILOT_KIT_VERSION_MISMATCH_ERROR: "CopilotKitVersionMismatchError",
|
|
195
82
|
RESOLVED_COPILOT_KIT_ERROR: "ResolvedCopilotKitError",
|
|
196
83
|
CONFIGURATION_ERROR: "ConfigurationError",
|
|
197
84
|
MISSING_PUBLIC_API_KEY_ERROR: "MissingPublicApiKeyError",
|
|
@@ -296,7 +183,7 @@ In order to use ${feature}, you need to add your CopilotKit license key, availab
|
|
|
296
183
|
severity: Severity.INFO
|
|
297
184
|
}
|
|
298
185
|
};
|
|
299
|
-
var CopilotKitError = class extends
|
|
186
|
+
var CopilotKitError = class extends Error {
|
|
300
187
|
constructor({ message = "Unknown error occurred", code, severity, visibility }) {
|
|
301
188
|
var _ref;
|
|
302
189
|
const name = ERROR_NAMES.COPILOT_ERROR;
|
|
@@ -304,7 +191,8 @@ In order to use ${feature}, you need to add your CopilotKit license key, availab
|
|
|
304
191
|
const { statusCode } = config;
|
|
305
192
|
const resolvedVisibility = (_ref = visibility !== null && visibility !== void 0 ? visibility : config.visibility) !== null && _ref !== void 0 ? _ref : ErrorVisibility.TOAST;
|
|
306
193
|
const resolvedSeverity = severity !== null && severity !== void 0 ? severity : "severity" in config ? config.severity : void 0;
|
|
307
|
-
super(message
|
|
194
|
+
super(message);
|
|
195
|
+
this.extensions = {
|
|
308
196
|
name,
|
|
309
197
|
statusCode,
|
|
310
198
|
code,
|
|
@@ -315,7 +203,7 @@ In order to use ${feature}, you need to add your CopilotKit license key, availab
|
|
|
315
203
|
message,
|
|
316
204
|
stack: (/* @__PURE__ */ new Error()).stack
|
|
317
205
|
}
|
|
318
|
-
}
|
|
206
|
+
};
|
|
319
207
|
this.code = code;
|
|
320
208
|
this.name = name;
|
|
321
209
|
this.statusCode = statusCode;
|
|
@@ -340,26 +228,6 @@ In order to use ${feature}, you need to add your CopilotKit license key, availab
|
|
|
340
228
|
this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
|
|
341
229
|
}
|
|
342
230
|
};
|
|
343
|
-
const getVersionMismatchErrorMessage = ({ reactCoreVersion, runtimeVersion, runtimeClientGqlVersion }) => `Version mismatch detected: @copilotkit/runtime@${runtimeVersion !== null && runtimeVersion !== void 0 ? runtimeVersion : ""} is not compatible with @copilotkit/react-core@${reactCoreVersion} and @copilotkit/runtime-client-gql@${runtimeClientGqlVersion}. Please ensure all installed copilotkit packages are on the same version.`;
|
|
344
|
-
/**
|
|
345
|
-
* Error thrown when CPK versions does not match
|
|
346
|
-
*
|
|
347
|
-
* @extends CopilotKitError
|
|
348
|
-
*/
|
|
349
|
-
var CopilotKitVersionMismatchError = class extends CopilotKitError {
|
|
350
|
-
constructor({ reactCoreVersion, runtimeVersion, runtimeClientGqlVersion }) {
|
|
351
|
-
const code = CopilotKitErrorCode.VERSION_MISMATCH;
|
|
352
|
-
super({
|
|
353
|
-
message: getVersionMismatchErrorMessage({
|
|
354
|
-
reactCoreVersion,
|
|
355
|
-
runtimeVersion,
|
|
356
|
-
runtimeClientGqlVersion
|
|
357
|
-
}),
|
|
358
|
-
code
|
|
359
|
-
});
|
|
360
|
-
this.name = ERROR_NAMES.COPILOT_KIT_VERSION_MISMATCH_ERROR;
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
231
|
/**
|
|
364
232
|
* Error thrown when the CopilotKit API endpoint cannot be discovered or accessed.
|
|
365
233
|
* This typically occurs when:
|
|
@@ -550,19 +418,6 @@ In order to use ${feature}, you need to add your CopilotKit license key, availab
|
|
|
550
418
|
function ensureStructuredError(error, converter) {
|
|
551
419
|
return isStructuredCopilotKitError(error) ? error : converter(error);
|
|
552
420
|
}
|
|
553
|
-
async function getPossibleVersionMismatch({ runtimeVersion, runtimeClientGqlVersion }) {
|
|
554
|
-
if (!runtimeVersion || runtimeVersion === "" || !runtimeClientGqlVersion) return;
|
|
555
|
-
if (COPILOTKIT_VERSION !== runtimeVersion || COPILOTKIT_VERSION !== runtimeClientGqlVersion || runtimeVersion !== runtimeClientGqlVersion) return {
|
|
556
|
-
runtimeVersion,
|
|
557
|
-
runtimeClientGqlVersion,
|
|
558
|
-
reactCoreVersion: COPILOTKIT_VERSION,
|
|
559
|
-
message: getVersionMismatchErrorMessage({
|
|
560
|
-
runtimeVersion,
|
|
561
|
-
runtimeClientGqlVersion,
|
|
562
|
-
reactCoreVersion: COPILOTKIT_VERSION
|
|
563
|
-
})
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
421
|
const resolveLowLevelErrorMessage = ({ errorCode, url }) => {
|
|
567
422
|
const troubleshootingLink = ERROR_CONFIG[CopilotKitErrorCode.NETWORK_ERROR].troubleshootingUrl;
|
|
568
423
|
const genericMessage = (description = `Failed to fetch from url ${url}.`) => `${description}.
|
|
@@ -583,6 +438,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
583
438
|
case "ECONNREFUSED": return `Connection to ${url} was refused. Ensure the server is running and accessible.\n\n${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
584
439
|
case "ENOTFOUND": return `The server on ${url} could not be found. Check the URL or your network configuration.\n\n${getSeeMoreMarkdown(ERROR_CONFIG[CopilotKitErrorCode.NOT_FOUND].troubleshootingUrl)}`;
|
|
585
440
|
case "ETIMEDOUT": return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.\n\n${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
441
|
+
case void 0:
|
|
586
442
|
default: return;
|
|
587
443
|
}
|
|
588
444
|
};
|
|
@@ -707,6 +563,10 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
707
563
|
...properties && { properties },
|
|
708
564
|
...required && required.length > 0 && { required }
|
|
709
565
|
};
|
|
566
|
+
case "string[]":
|
|
567
|
+
case "number[]":
|
|
568
|
+
case "boolean[]":
|
|
569
|
+
case void 0:
|
|
710
570
|
default:
|
|
711
571
|
var _attribute$type;
|
|
712
572
|
if ((_attribute$type = attribute.type) === null || _attribute$type === void 0 ? void 0 : _attribute$type.endsWith("[]")) return {
|
|
@@ -720,82 +580,6 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
720
580
|
};
|
|
721
581
|
}
|
|
722
582
|
}
|
|
723
|
-
function convertJsonSchemaToZodSchema(jsonSchema, required, definitions, visitedRefs) {
|
|
724
|
-
var _ref, _jsonSchema$anyOf, _jsonSchema$type;
|
|
725
|
-
if (jsonSchema.$ref && definitions) {
|
|
726
|
-
const refPath = jsonSchema.$ref.replace(/^#\/\$defs\/|^#\/definitions\//, "");
|
|
727
|
-
const refs = visitedRefs !== null && visitedRefs !== void 0 ? visitedRefs : /* @__PURE__ */ new Set();
|
|
728
|
-
if (refs.has(refPath)) {
|
|
729
|
-
console.warn(`[CopilotKit] Circular $ref detected for "${refPath}" — falling back to z.any()`);
|
|
730
|
-
let schema = zod.z.any();
|
|
731
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
732
|
-
return required ? schema : schema.optional();
|
|
733
|
-
}
|
|
734
|
-
const resolved = definitions[refPath];
|
|
735
|
-
if (resolved) {
|
|
736
|
-
const nextRefs = new Set(refs);
|
|
737
|
-
nextRefs.add(refPath);
|
|
738
|
-
return convertJsonSchemaToZodSchema(resolved, required, definitions, nextRefs);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
const defs = (_ref = definitions !== null && definitions !== void 0 ? definitions : jsonSchema.$defs) !== null && _ref !== void 0 ? _ref : jsonSchema.definitions;
|
|
742
|
-
if (Array.isArray(jsonSchema.type)) {
|
|
743
|
-
const types = jsonSchema.type;
|
|
744
|
-
const hasNull = types.includes("null");
|
|
745
|
-
const nonNullTypes = types.filter((t) => t !== "null");
|
|
746
|
-
const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : "string";
|
|
747
|
-
const innerSchema = convertJsonSchemaToZodSchema({
|
|
748
|
-
...jsonSchema,
|
|
749
|
-
type: resolvedType
|
|
750
|
-
}, true, defs, visitedRefs);
|
|
751
|
-
let schema = hasNull ? zod.z.union([innerSchema, zod.z.null()]) : innerSchema;
|
|
752
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
753
|
-
return required ? schema : schema.optional();
|
|
754
|
-
}
|
|
755
|
-
const unionVariants = (_jsonSchema$anyOf = jsonSchema.anyOf) !== null && _jsonSchema$anyOf !== void 0 ? _jsonSchema$anyOf : jsonSchema.oneOf;
|
|
756
|
-
if (Array.isArray(unionVariants) && unionVariants.length > 0) {
|
|
757
|
-
if (unionVariants.length === 1) return convertJsonSchemaToZodSchema(unionVariants[0], required, defs, visitedRefs);
|
|
758
|
-
const schemas = unionVariants.map((v) => convertJsonSchemaToZodSchema(v, true, defs, visitedRefs));
|
|
759
|
-
let schema = zod.z.union(schemas);
|
|
760
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
761
|
-
return required ? schema : schema.optional();
|
|
762
|
-
}
|
|
763
|
-
if (jsonSchema.type === "object") {
|
|
764
|
-
const spec = {};
|
|
765
|
-
if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) return !required ? zod.z.object(spec).optional() : zod.z.object(spec);
|
|
766
|
-
for (const [key, value] of Object.entries(jsonSchema.properties)) spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false, defs, visitedRefs);
|
|
767
|
-
let schema = zod.z.object(spec).describe(jsonSchema.description);
|
|
768
|
-
return required ? schema : schema.optional();
|
|
769
|
-
} else if (jsonSchema.type === "string") {
|
|
770
|
-
if (jsonSchema.enum && jsonSchema.enum.length > 0) {
|
|
771
|
-
let schema = zod.z.enum(jsonSchema.enum).describe(jsonSchema.description);
|
|
772
|
-
return required ? schema : schema.optional();
|
|
773
|
-
}
|
|
774
|
-
let schema = zod.z.string().describe(jsonSchema.description);
|
|
775
|
-
return required ? schema : schema.optional();
|
|
776
|
-
} else if (jsonSchema.type === "number" || jsonSchema.type === "integer") {
|
|
777
|
-
let schema = zod.z.number().describe(jsonSchema.description);
|
|
778
|
-
return required ? schema : schema.optional();
|
|
779
|
-
} else if (jsonSchema.type === "boolean") {
|
|
780
|
-
let schema = zod.z.boolean().describe(jsonSchema.description);
|
|
781
|
-
return required ? schema : schema.optional();
|
|
782
|
-
} else if (jsonSchema.type === "array") {
|
|
783
|
-
let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true, defs, visitedRefs);
|
|
784
|
-
let schema = zod.z.array(itemSchema).describe(jsonSchema.description);
|
|
785
|
-
return required ? schema : schema.optional();
|
|
786
|
-
} else if (jsonSchema.type === "null") {
|
|
787
|
-
let schema = zod.z.null().describe(jsonSchema.description);
|
|
788
|
-
return required ? schema : schema.optional();
|
|
789
|
-
}
|
|
790
|
-
console.warn(`[CopilotKit] Unsupported JSON schema type "${(_jsonSchema$type = jsonSchema.type) !== null && _jsonSchema$type !== void 0 ? _jsonSchema$type : "unknown"}" — falling back to z.any()`);
|
|
791
|
-
let schema = zod.z.any();
|
|
792
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
793
|
-
return required ? schema : schema.optional();
|
|
794
|
-
}
|
|
795
|
-
function getZodParameters(parameters) {
|
|
796
|
-
if (!parameters) return zod.z.object({});
|
|
797
|
-
return convertJsonSchemaToZodSchema(actionParametersToJsonSchema(parameters), true);
|
|
798
|
-
}
|
|
799
583
|
|
|
800
584
|
//#endregion
|
|
801
585
|
//#region src/utils/dashboard-url.ts
|
|
@@ -815,7 +599,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
815
599
|
|
|
816
600
|
//#endregion
|
|
817
601
|
//#region src/utils/inspector-metadata.ts
|
|
818
|
-
function isRecord$
|
|
602
|
+
function isRecord$3(value) {
|
|
819
603
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
820
604
|
try {
|
|
821
605
|
const prototype = Object.getPrototypeOf(value);
|
|
@@ -838,7 +622,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
838
622
|
return parsed.length > 0 ? parsed : void 0;
|
|
839
623
|
}
|
|
840
624
|
function parseIdentity(value) {
|
|
841
|
-
if (!isRecord$
|
|
625
|
+
if (!isRecord$3(value)) return;
|
|
842
626
|
const organizationName = parseNonBlankString(value.organizationName);
|
|
843
627
|
const projectName = parseNonBlankString(value.projectName);
|
|
844
628
|
if (organizationName === void 0 || projectName === void 0) return;
|
|
@@ -848,7 +632,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
848
632
|
};
|
|
849
633
|
}
|
|
850
634
|
function parsePlan(value) {
|
|
851
|
-
if (!isRecord$
|
|
635
|
+
if (!isRecord$3(value)) return;
|
|
852
636
|
const code = parseNonBlankString(value.code);
|
|
853
637
|
const label = parseNonBlankString(value.label);
|
|
854
638
|
if (code === void 0 || label === void 0) return;
|
|
@@ -858,7 +642,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
858
642
|
};
|
|
859
643
|
}
|
|
860
644
|
function parseLicense(value) {
|
|
861
|
-
if (!isRecord$
|
|
645
|
+
if (!isRecord$3(value)) return;
|
|
862
646
|
switch (value.state) {
|
|
863
647
|
case "valid":
|
|
864
648
|
case "none":
|
|
@@ -893,7 +677,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
893
677
|
return isSafeDashboardUrl(parsed) ? url : void 0;
|
|
894
678
|
}
|
|
895
679
|
function parseAction(value) {
|
|
896
|
-
if (!isRecord$
|
|
680
|
+
if (!isRecord$3(value)) return;
|
|
897
681
|
const kind = parseActionKind(value.kind);
|
|
898
682
|
const url = parseSafeActionUrl(value.url);
|
|
899
683
|
if (kind === void 0 || url === void 0) return;
|
|
@@ -906,7 +690,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
906
690
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
907
691
|
}
|
|
908
692
|
function parseUsageLimit(value) {
|
|
909
|
-
if (!isRecord$
|
|
693
|
+
if (!isRecord$3(value)) return;
|
|
910
694
|
if (value.kind === "finite") {
|
|
911
695
|
if (typeof value.value !== "number" || !Number.isSafeInteger(value.value) || value.value < 1) return;
|
|
912
696
|
return {
|
|
@@ -918,7 +702,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
918
702
|
if (value.kind === "unknown") return { kind: "unknown" };
|
|
919
703
|
}
|
|
920
704
|
function parseUsage(value) {
|
|
921
|
-
if (!isRecord$
|
|
705
|
+
if (!isRecord$3(value)) return;
|
|
922
706
|
const limit = parseUsageLimit(value.limit);
|
|
923
707
|
const used = value.used;
|
|
924
708
|
if (!isFiniteNonnegativeInteger(used) || limit === void 0) return;
|
|
@@ -939,7 +723,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
939
723
|
* top-level payload.
|
|
940
724
|
*/
|
|
941
725
|
function parseInspectorMetadataV1(value) {
|
|
942
|
-
if (!isRecord$
|
|
726
|
+
if (!isRecord$3(value) || value.schemaVersion !== 1) return;
|
|
943
727
|
const identity = parseIdentity(value.identity);
|
|
944
728
|
const plan = parsePlan(value.plan);
|
|
945
729
|
const license = parseLicense(value.license);
|
|
@@ -1169,11 +953,32 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
1169
953
|
//#endregion
|
|
1170
954
|
//#region src/utils/inspector-visibility.ts
|
|
1171
955
|
/**
|
|
956
|
+
* Hosts the Inspector runs on. The Inspector reads agent state, messages and
|
|
957
|
+
* request headers, so it only mounts on a page served from this machine.
|
|
958
|
+
*
|
|
959
|
+
* @internal Framework adapters use this list. Applications must not depend on it.
|
|
960
|
+
*/
|
|
961
|
+
const ɵINSPECTOR_LOOPBACK_HOSTS = Object.freeze([
|
|
962
|
+
"localhost",
|
|
963
|
+
"127.0.0.1",
|
|
964
|
+
"[::1]"
|
|
965
|
+
]);
|
|
966
|
+
/**
|
|
1172
967
|
* The Inspector is a development-only browser tool. Consumers may disable it,
|
|
1173
|
-
* but an explicit `true` never overrides a production or server environment
|
|
968
|
+
* but an explicit `true` never overrides a production or server environment,
|
|
969
|
+
* or a page served from a non-loopback host.
|
|
970
|
+
*
|
|
971
|
+
* @example
|
|
972
|
+
* shouldEnableInspector({
|
|
973
|
+
* enableInspector,
|
|
974
|
+
* isBrowser: true,
|
|
975
|
+
* isDevelopment: process.env.NODE_ENV === "development",
|
|
976
|
+
* hostname: window.location.hostname,
|
|
977
|
+
* });
|
|
1174
978
|
*/
|
|
1175
|
-
function shouldEnableInspector({ enableInspector, isBrowser, isDevelopment }) {
|
|
1176
|
-
|
|
979
|
+
function shouldEnableInspector({ enableInspector, isBrowser, isDevelopment, hostname }) {
|
|
980
|
+
const isAllowedHost = hostname === void 0 || ɵINSPECTOR_LOOPBACK_HOSTS.includes(hostname);
|
|
981
|
+
return isBrowser && isDevelopment && enableInspector !== false && isAllowedHost;
|
|
1177
982
|
}
|
|
1178
983
|
|
|
1179
984
|
//#endregion
|
|
@@ -1184,31 +989,22 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
1184
989
|
//#endregion
|
|
1185
990
|
//#region src/utils/random-id.ts
|
|
1186
991
|
function randomId() {
|
|
1187
|
-
return "ck-" + (
|
|
1188
|
-
}
|
|
1189
|
-
function randomUUID() {
|
|
1190
|
-
return (0, uuid.v4)();
|
|
992
|
+
return "ck-" + randomUUID();
|
|
1191
993
|
}
|
|
1192
994
|
/**
|
|
1193
|
-
*
|
|
995
|
+
* Returns an RFC 4122 version 4 UUID. Uses `crypto.randomUUID()` when it
|
|
996
|
+
* exists, and builds the UUID from `crypto.getRandomValues()` when it does not
|
|
997
|
+
* (React Native's Hermes has no `randomUUID`).
|
|
1194
998
|
*/
|
|
1195
|
-
function
|
|
1196
|
-
|
|
1197
|
-
if (
|
|
1198
|
-
if (
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
return
|
|
1204
|
-
}
|
|
1205
|
-
function dataToUUID(input, namespace) {
|
|
1206
|
-
const BASE_NAMESPACE = "e4b01160-ff74-4c6e-9b27-d53cd930fe8e";
|
|
1207
|
-
const boundNamespace = namespace ? (0, uuid.v5)(namespace, BASE_NAMESPACE) : BASE_NAMESPACE;
|
|
1208
|
-
return (0, uuid.v5)(typeof input === "string" ? input : JSON.stringify(toSerializable(input)), boundNamespace);
|
|
1209
|
-
}
|
|
1210
|
-
function isValidUUID(uuid$1) {
|
|
1211
|
-
return (0, uuid.validate)(uuid$1);
|
|
999
|
+
function randomUUID() {
|
|
1000
|
+
const crypto = globalThis.crypto;
|
|
1001
|
+
if (typeof (crypto === null || crypto === void 0 ? void 0 : crypto.randomUUID) === "function") return crypto.randomUUID();
|
|
1002
|
+
if (typeof (crypto === null || crypto === void 0 ? void 0 : crypto.getRandomValues) !== "function") throw new Error("crypto.getRandomValues() is not available. In React Native, install a polyfill such as react-native-get-random-values.");
|
|
1003
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
1004
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
1005
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
1006
|
+
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0"));
|
|
1007
|
+
return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(6, 8).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10).join("")}`;
|
|
1212
1008
|
}
|
|
1213
1009
|
|
|
1214
1010
|
//#endregion
|
|
@@ -1587,11 +1383,6 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
1587
1383
|
* Users can opt out by setting:
|
|
1588
1384
|
* - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1
|
|
1589
1385
|
* - DO_NOT_TRACK=true or DO_NOT_TRACK=1
|
|
1590
|
-
*
|
|
1591
|
-
* Lives in its own module so that the browser-facing root entry can
|
|
1592
|
-
* re-export it without pulling in `telemetry-client.ts`, whose
|
|
1593
|
-
* `@segment/analytics-node` import drags Node built-ins into browser
|
|
1594
|
-
* bundler module graphs. See the note in `../index.ts`.
|
|
1595
1386
|
*/
|
|
1596
1387
|
function isTelemetryDisabled() {
|
|
1597
1388
|
const env = processEnv();
|
|
@@ -1777,7 +1568,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
1777
1568
|
try {
|
|
1778
1569
|
var _firstNonBlankTelemet;
|
|
1779
1570
|
const payload = parts[1];
|
|
1780
|
-
if (!/^[A-Za-z0-9_-]+$/.test(payload) || payload.length % 4 === 1) return null;
|
|
1571
|
+
if (payload === void 0 || !/^[A-Za-z0-9_-]+$/.test(payload) || payload.length % 4 === 1) return null;
|
|
1781
1572
|
let b64 = payload.replace(/-/g, "+").replace(/_/g, "/");
|
|
1782
1573
|
const padding = (4 - b64.length % 4) % 4;
|
|
1783
1574
|
b64 += "=".repeat(padding);
|
|
@@ -1867,6 +1658,18 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
1867
1658
|
//#endregion
|
|
1868
1659
|
//#region src/standard-schema.ts
|
|
1869
1660
|
/**
|
|
1661
|
+
* A Standard Schema that accepts any value and returns it unchanged.
|
|
1662
|
+
*
|
|
1663
|
+
* Wildcard tool call renderers use it when they declare no `args` schema.
|
|
1664
|
+
*
|
|
1665
|
+
* @internal Application authors must not depend on this contract.
|
|
1666
|
+
*/
|
|
1667
|
+
const ɵanySchema = { "~standard": {
|
|
1668
|
+
version: 1,
|
|
1669
|
+
vendor: "copilotkit",
|
|
1670
|
+
validate: (value) => ({ value })
|
|
1671
|
+
} };
|
|
1672
|
+
/**
|
|
1870
1673
|
* Check whether a schema implements the Standard JSON Schema V1 protocol.
|
|
1871
1674
|
*/
|
|
1872
1675
|
function hasStandardJsonSchema(schema) {
|
|
@@ -1879,17 +1682,17 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
1879
1682
|
* Strategy:
|
|
1880
1683
|
* 1. If the schema implements Standard JSON Schema V1 (`~standard.jsonSchema`),
|
|
1881
1684
|
* call `schema['~standard'].jsonSchema.input({ target: 'draft-07' })`.
|
|
1882
|
-
* 2
|
|
1883
|
-
*
|
|
1884
|
-
*
|
|
1885
|
-
*
|
|
1685
|
+
* Zod 4.2+, ArkType 2.1.28+ and Valibot (via `toStandardJsonSchema`) do.
|
|
1686
|
+
* 2. If the schema exposes a `toJSONSchema()` method, call it directly.
|
|
1687
|
+
* 3. Otherwise throw a descriptive error. Zod 3 schemas land here: they
|
|
1688
|
+
* implement Standard Schema validation but cannot describe themselves as
|
|
1689
|
+
* JSON Schema.
|
|
1886
1690
|
*/
|
|
1887
|
-
function schemaToJsonSchema(schema
|
|
1691
|
+
function schemaToJsonSchema(schema) {
|
|
1888
1692
|
if (hasStandardJsonSchema(schema)) return schema["~standard"].jsonSchema.input({ target: "draft-07" });
|
|
1889
1693
|
if (typeof schema.toJSONSchema === "function") return schema.toJSONSchema();
|
|
1890
1694
|
const vendor = schema["~standard"].vendor;
|
|
1891
|
-
|
|
1892
|
-
throw new Error(`Cannot convert schema to JSON Schema. The schema (vendor: "${vendor}") does not implement Standard JSON Schema V1 and no zodToJsonSchema fallback is available. Use a library that supports Standard JSON Schema (e.g., Zod 3.24+, Valibot v1+, ArkType v2+) or pass a zodToJsonSchema function in options.`);
|
|
1695
|
+
throw new Error(`Cannot convert schema to JSON Schema. The schema (vendor: "${vendor}") does not implement Standard JSON Schema V1. Use a library that does: Zod 4.2+ (Zod 3 is not supported), Valibot v1+ wrapped with toStandardJsonSchema() from @valibot/to-json-schema, or ArkType v2.1.28+.`);
|
|
1893
1696
|
}
|
|
1894
1697
|
|
|
1895
1698
|
//#endregion
|
|
@@ -1951,15 +1754,26 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
1951
1754
|
}
|
|
1952
1755
|
/**
|
|
1953
1756
|
* Generate a thumbnail data URL from a video file by capturing a frame near the start (at 0.1s).
|
|
1954
|
-
* Returns undefined if thumbnail generation fails
|
|
1757
|
+
* Returns undefined if thumbnail generation fails, if called outside a browser environment,
|
|
1758
|
+
* or if `file` is not a `Blob` the browser can read (React Native for web passes a
|
|
1759
|
+
* native file's description). Never rejects.
|
|
1955
1760
|
*/
|
|
1956
1761
|
function generateVideoThumbnail(file) {
|
|
1957
|
-
if (typeof document === "undefined") return Promise.resolve(void 0);
|
|
1762
|
+
if (typeof document === "undefined" || typeof Blob === "undefined" || !(file instanceof Blob)) return Promise.resolve(void 0);
|
|
1958
1763
|
return new Promise((resolve) => {
|
|
1959
1764
|
let resolved = false;
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1765
|
+
let url;
|
|
1766
|
+
let video;
|
|
1767
|
+
let canvas;
|
|
1768
|
+
try {
|
|
1769
|
+
video = document.createElement("video");
|
|
1770
|
+
canvas = document.createElement("canvas");
|
|
1771
|
+
url = URL.createObjectURL(file);
|
|
1772
|
+
} catch (error) {
|
|
1773
|
+
console.warn(`[CopilotKit] generateVideoThumbnail: could not read file "${file.name}"`, error);
|
|
1774
|
+
resolve(void 0);
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1963
1777
|
const cleanup = (result) => {
|
|
1964
1778
|
if (resolved) return;
|
|
1965
1779
|
resolved = true;
|
|
@@ -2136,6 +1950,22 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2136
1950
|
terminalEventObserved = true;
|
|
2137
1951
|
clearOpen();
|
|
2138
1952
|
break;
|
|
1953
|
+
case _ag_ui_client.EventType.TEXT_MESSAGE_CONTENT:
|
|
1954
|
+
case _ag_ui_client.EventType.TEXT_MESSAGE_CHUNK:
|
|
1955
|
+
case _ag_ui_client.EventType.TOOL_CALL_ARGS:
|
|
1956
|
+
case _ag_ui_client.EventType.TOOL_CALL_CHUNK:
|
|
1957
|
+
case _ag_ui_client.EventType.STATE_SNAPSHOT:
|
|
1958
|
+
case _ag_ui_client.EventType.STATE_DELTA:
|
|
1959
|
+
case _ag_ui_client.EventType.MESSAGES_SNAPSHOT:
|
|
1960
|
+
case _ag_ui_client.EventType.ACTIVITY_SNAPSHOT:
|
|
1961
|
+
case _ag_ui_client.EventType.ACTIVITY_DELTA:
|
|
1962
|
+
case _ag_ui_client.EventType.RAW:
|
|
1963
|
+
case _ag_ui_client.EventType.CUSTOM:
|
|
1964
|
+
case _ag_ui_client.EventType.STEP_STARTED:
|
|
1965
|
+
case _ag_ui_client.EventType.STEP_FINISHED:
|
|
1966
|
+
case _ag_ui_client.EventType.REASONING_MESSAGE_CONTENT:
|
|
1967
|
+
case _ag_ui_client.EventType.REASONING_MESSAGE_CHUNK:
|
|
1968
|
+
case _ag_ui_client.EventType.REASONING_ENCRYPTED_VALUE:
|
|
2139
1969
|
default: break;
|
|
2140
1970
|
}
|
|
2141
1971
|
};
|
|
@@ -2336,7 +2166,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2336
2166
|
|
|
2337
2167
|
//#endregion
|
|
2338
2168
|
//#region package.json
|
|
2339
|
-
var version = "2.0.0-rc.
|
|
2169
|
+
var version = "2.0.0-rc.51";
|
|
2340
2170
|
|
|
2341
2171
|
//#endregion
|
|
2342
2172
|
//#region src/generative-ui/basic-functions.ts
|
|
@@ -2464,7 +2294,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2464
2294
|
*/
|
|
2465
2295
|
const COPILOTKIT_FUNCTIONS = rendererOnly({
|
|
2466
2296
|
calc: {
|
|
2467
|
-
description: "The value of an arithmetic expression over the other args, by name: + - * / % ( ), comparisons, && || !, cond ? a : b, min max round floor ceil abs, 'text' + name",
|
|
2297
|
+
description: "The value of an arithmetic expression over the other args, by name: + - * / % ( ), x ^ y (power), comparisons, && || !, cond ? a : b, min max round floor ceil abs pow sqrt exp ln log10, the constants pi and e, 'text' + name",
|
|
2468
2298
|
parameters: "{ expression: string; [name: string]: number | string | boolean }",
|
|
2469
2299
|
returnType: "any",
|
|
2470
2300
|
extension: true
|
|
@@ -2506,8 +2336,8 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2506
2336
|
|
|
2507
2337
|
//#endregion
|
|
2508
2338
|
//#region src/generative-ui/is-record.ts
|
|
2509
|
-
/** True for a plain object: not null, not an array.
|
|
2510
|
-
function isRecord(value) {
|
|
2339
|
+
/** True for a plain object: not null, not an array. */
|
|
2340
|
+
function isRecord$2(value) {
|
|
2511
2341
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2512
2342
|
}
|
|
2513
2343
|
|
|
@@ -2553,7 +2383,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2553
2383
|
const visit = (node) => {
|
|
2554
2384
|
var _marked;
|
|
2555
2385
|
if (Array.isArray(node)) return node.map(visit);
|
|
2556
|
-
if (!isRecord(node)) return node;
|
|
2386
|
+
if (!isRecord$2(node)) return node;
|
|
2557
2387
|
const reference = (_marked = marked(node.description, A2UI_COMPONENT_ID_MARK, A2UI_COMPONENT_ID_REF)) !== null && _marked !== void 0 ? _marked : marked(node.description, A2UI_CHILD_LIST_MARK, A2UI_CHILD_LIST_REF);
|
|
2558
2388
|
if (reference) return reference;
|
|
2559
2389
|
return Object.fromEntries(Object.entries(node).map(([key, value]) => [key, visit(value)]));
|
|
@@ -2580,12 +2410,12 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2580
2410
|
});
|
|
2581
2411
|
};
|
|
2582
2412
|
const visit = (node, path) => {
|
|
2583
|
-
if (!isRecord(node)) return;
|
|
2413
|
+
if (!isRecord$2(node)) return;
|
|
2584
2414
|
const kind = childRefKind(node);
|
|
2585
2415
|
if (kind) return add(path, kind);
|
|
2586
2416
|
for (const list of [node.anyOf, node.oneOf]) {
|
|
2587
2417
|
if (!Array.isArray(list) || list.length === 0) continue;
|
|
2588
|
-
const kinds = list.map((variant) => isRecord(variant) ? childRefKind(variant) : void 0);
|
|
2418
|
+
const kinds = list.map((variant) => isRecord$2(variant) ? childRefKind(variant) : void 0);
|
|
2589
2419
|
const [first] = kinds;
|
|
2590
2420
|
if (first && kinds.every((k) => k === first)) add(path, first);
|
|
2591
2421
|
else if (kinds.every((k) => k === void 0)) {
|
|
@@ -2595,8 +2425,8 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2595
2425
|
}
|
|
2596
2426
|
}
|
|
2597
2427
|
if (Array.isArray(node.allOf)) node.allOf.forEach((variant) => visit(variant, path));
|
|
2598
|
-
if (isRecord(node.properties)) for (const [key, value] of Object.entries(node.properties)) visit(value, [...path, key]);
|
|
2599
|
-
if (isRecord(node.items)) visit(node.items, [...path, "*"]);
|
|
2428
|
+
if (isRecord$2(node.properties)) for (const [key, value] of Object.entries(node.properties)) visit(value, [...path, key]);
|
|
2429
|
+
if (isRecord$2(node.items)) visit(node.items, [...path, "*"]);
|
|
2600
2430
|
};
|
|
2601
2431
|
visit(schema, []);
|
|
2602
2432
|
return refs;
|
|
@@ -2611,16 +2441,16 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2611
2441
|
const collect = (value) => {
|
|
2612
2442
|
if (typeof value === "string") ids.push(value);
|
|
2613
2443
|
else if (Array.isArray(value)) value.forEach((id) => typeof id === "string" && ids.push(id));
|
|
2614
|
-
else if (isRecord(value) && typeof value.componentId === "string") ids.push(value.componentId);
|
|
2444
|
+
else if (isRecord$2(value) && typeof value.componentId === "string") ids.push(value.componentId);
|
|
2615
2445
|
};
|
|
2616
2446
|
const visit = (value, path) => {
|
|
2617
|
-
if (path.length === 0) return collect(value);
|
|
2618
2447
|
const [head, ...rest] = path;
|
|
2448
|
+
if (head === void 0) return collect(value);
|
|
2619
2449
|
if (head === "*") {
|
|
2620
2450
|
if (Array.isArray(value)) value.forEach((item) => visit(item, rest));
|
|
2621
2451
|
return;
|
|
2622
2452
|
}
|
|
2623
|
-
if (isRecord(value) && Object.prototype.hasOwnProperty.call(value, head)) visit(value[head], rest);
|
|
2453
|
+
if (isRecord$2(value) && Object.prototype.hasOwnProperty.call(value, head)) visit(value[head], rest);
|
|
2624
2454
|
};
|
|
2625
2455
|
for (const ref of refs) visit(component, ref.path);
|
|
2626
2456
|
return ids;
|
|
@@ -2631,13 +2461,13 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2631
2461
|
* at render time.
|
|
2632
2462
|
*/
|
|
2633
2463
|
function hasBoundChildRef(component, refs) {
|
|
2634
|
-
const isDynamic = (value) => isRecord(value) && ("@path" in value || "@call" in value);
|
|
2464
|
+
const isDynamic = (value) => isRecord$2(value) && ("@path" in value || "@call" in value);
|
|
2635
2465
|
const visit = (value, path) => {
|
|
2636
2466
|
if (isDynamic(value)) return true;
|
|
2637
|
-
if (path.length === 0) return false;
|
|
2638
2467
|
const [head, ...rest] = path;
|
|
2468
|
+
if (head === void 0) return false;
|
|
2639
2469
|
if (head === "*") return Array.isArray(value) && value.some((item) => visit(item, rest));
|
|
2640
|
-
return isRecord(value) && Object.prototype.hasOwnProperty.call(value, head) && visit(value[head], rest);
|
|
2470
|
+
return isRecord$2(value) && Object.prototype.hasOwnProperty.call(value, head) && visit(value[head], rest);
|
|
2641
2471
|
};
|
|
2642
2472
|
return refs.some((ref) => visit(component, ref.path));
|
|
2643
2473
|
}
|
|
@@ -2647,13 +2477,13 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2647
2477
|
* else keeps its identity. Missing keys are left alone.
|
|
2648
2478
|
*/
|
|
2649
2479
|
function mapAtChildRef(value, path, replace) {
|
|
2650
|
-
if (path.length === 0) return replace(value);
|
|
2651
2480
|
const [head, ...rest] = path;
|
|
2481
|
+
if (head === void 0) return replace(value);
|
|
2652
2482
|
if (head === "*") {
|
|
2653
2483
|
if (!Array.isArray(value)) return value;
|
|
2654
2484
|
return value.map((item) => mapAtChildRef(item, rest, replace));
|
|
2655
2485
|
}
|
|
2656
|
-
if (!isRecord(value) || !Object.prototype.hasOwnProperty.call(value, head)) return value;
|
|
2486
|
+
if (!isRecord$2(value) || !Object.prototype.hasOwnProperty.call(value, head)) return value;
|
|
2657
2487
|
return {
|
|
2658
2488
|
...value,
|
|
2659
2489
|
[head]: mapAtChildRef(value[head], rest, replace)
|
|
@@ -2663,7 +2493,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2663
2493
|
//#endregion
|
|
2664
2494
|
//#region src/generative-ui/types.ts
|
|
2665
2495
|
/** A2UI protocol version used on the wire. */
|
|
2666
|
-
const A2UI_VERSION = "
|
|
2496
|
+
const A2UI_VERSION = "1.0";
|
|
2667
2497
|
/** Activity type of a generated surface message. */
|
|
2668
2498
|
const GENERATIVE_UI_ACTIVITY_TYPE = "generative-ui-surface";
|
|
2669
2499
|
/** Activity type of a function call that the agent asks the client to run. */
|
|
@@ -2727,7 +2557,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2727
2557
|
* @example
|
|
2728
2558
|
* ```ts
|
|
2729
2559
|
* toA2UIActionMessage({ name: "buy", surfaceId: "s1", componentId: "b", context: { sku: "a" } });
|
|
2730
|
-
* // { version: "
|
|
2560
|
+
* // { version: "1.0", action: { name: "buy", surfaceId: "s1", sourceComponentId: "b", timestamp: "2026-…", context: { sku: "a" } } }
|
|
2731
2561
|
* ```
|
|
2732
2562
|
*/
|
|
2733
2563
|
function toA2UIActionMessage(event) {
|
|
@@ -2745,6 +2575,222 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
2745
2575
|
};
|
|
2746
2576
|
}
|
|
2747
2577
|
|
|
2578
|
+
//#endregion
|
|
2579
|
+
//#region src/generative-ui/prompt-spec.ts
|
|
2580
|
+
/**
|
|
2581
|
+
* When UI helps the user, for both transports: a light nudge to reach for UI
|
|
2582
|
+
* where it conveys the answer better than prose, and to stay in prose
|
|
2583
|
+
* otherwise.
|
|
2584
|
+
*/
|
|
2585
|
+
const GENERATIVE_UI_WHEN_TO_SHOW = "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.";
|
|
2586
|
+
/**
|
|
2587
|
+
* When and how to show UI in the markdown transport: the answer first, a
|
|
2588
|
+
* map from tasks to components, real interactivity, honest data and
|
|
2589
|
+
* restraint. Measured with tools/genui-eval against the earlier text.
|
|
2590
|
+
*/
|
|
2591
|
+
const GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW = "Answer first: lead with the result or the recommendation in a sentence or two, then show the UI that supports it.\n\nShow UI whenever it makes the answer easier to use, and do not wait for the user to ask for a chart, a calculator or a form. A markdown table or list is not enough when the user would want to change a value, see a shape or a trend, or pick between options. Reply in prose alone only for a greeting or thanks, a one-line fact, a definition, code, or a text the user asked you to write (an email, a message, an update).\n\nMatch the UI to the task:\n- A number that depends on inputs (a price, a loan or mortgage, savings, a conversion, a recipe for N people): a calculator, always. Bind a Slider, TextField or SegmentedControl to the data model and compute the results with calc, so they follow the input. calc has powers, roots and logs, so every input can be a control, also a rate or a term: a monthly payment is rate == 0 ? loan / (years * 12) : loan * (rate / 1200) / (1 - (1 + rate / 1200) ^ -(years * 12)).\n- Choosing between options that share attributes: a Table, or a Grid of EntityCards when each option has a photo, a price or a rating. Plans or offers to pick from: one card each, ending with a Button to choose it.\n- Items with a status, a category or a level: a Badge on each item.\n- Shares, patterns, trends, change over time: a Chart.\n- Places, routes, what is nearby: a Map with the places as markers, next to cards or a List with their details.\n- A sequence or a history: a timeline surface, a List of dated items with a Badge for each era, not a markdown list.\n- How something works, a process, a structure: a diagram drawn with Svg. Draw the real objects as shapes (a cylinder and its piston, a leaf, a server), with arrows for movement or flow and short labels. Labelled boxes of text are not a diagram.\n- A formula or an equation: Math. Solving a math problem: the steps in prose with Math, plus a Chart of the function and a Slider to try values of x.\n- A broad topic (\"tell me about X\"): an overview surface with the key facts, an Image, and a Table or Chart that compares the parts, ending with FollowUp suggestions for what to ask next.\n- Options to choose from (algorithms, products, plans): a Table, plus a SegmentedControl or Select that shows the best option for the user's situation.\n- Research or evidence: a Table of the studies, with a Citation for each source.\n- Things whose look matters (places, products, food): an Image, or the image of an EntityCard.\n- Several inputs, or an action with a side effect (sign-up, booking, contact, scheduling): a Form with fields, checks and a Button. A field with a fixed list of answers (a team size, a topic, a country) is a Select.\n- Practice and learning: a quiz with RadioGroup or ChoicePicker that gives feedback as soon as the user answers, or FlashcardFlip cards. Ask in one language and offer the answers in the other.\n- A plan to follow or tick off: CheckBox items with a progress count that updates as items are ticked.\n- Parallel views (the days of a trip, alternatives): Tabs.\n\nMake interactivity real:\n- Expose the few inputs that change the outcome, with sensible defaults from what the user said.\n- Bind every control to the data model and derive what depends on it with calc or formatString. Controls about the same scenario share the same paths.\n- Every Button does what its label says, and a Link takes \"href\".\n- Never pretend an action happened. For booking, sending or subscribing, show the form and let the user confirm, and say that nothing is sent until they do.\n\nKeep the data honest:\n- Use the facts, places, photos and numbers of the app context when it has them. Never invent prices, availability, ratings, sources or image URLs.\n- Label estimates and assumptions, keep units and currencies consistent, and cite the sources you rely on with Citation.\n\nDesign with restraint:\n- One clear surface beats several. Put the most important result first and make it stand out with a Title, or a Text with size \"lg\". Text sizes go from \"3xs\" to \"lg\"; there is no \"xl\" or \"2xl\".\n- Keep explanations in prose around the surface, not inside it. No decoration, and no surface that only holds text.\n\nBefore you reply, check: does the UI answer the actual question, does every control do something, are the numbers right?";
|
|
2592
|
+
/** The prompts that ship, as a spec. A new object on each call. */
|
|
2593
|
+
/**
|
|
2594
|
+
* The standard components that the default markdown guide names. A guide
|
|
2595
|
+
* line that names one the catalog lacks is left out of the prompt.
|
|
2596
|
+
*/
|
|
2597
|
+
const GUIDE_COMPONENTS = new Set([
|
|
2598
|
+
"Grid",
|
|
2599
|
+
"Card",
|
|
2600
|
+
"Tabs",
|
|
2601
|
+
"Title",
|
|
2602
|
+
"Text",
|
|
2603
|
+
"Label",
|
|
2604
|
+
"Badge",
|
|
2605
|
+
"Math",
|
|
2606
|
+
"Link",
|
|
2607
|
+
"Button",
|
|
2608
|
+
"Form",
|
|
2609
|
+
"TextField",
|
|
2610
|
+
"Select",
|
|
2611
|
+
"CheckBox",
|
|
2612
|
+
"RadioGroup",
|
|
2613
|
+
"Slider",
|
|
2614
|
+
"SegmentedControl",
|
|
2615
|
+
"ChoicePicker",
|
|
2616
|
+
"FlashcardFlip",
|
|
2617
|
+
"Table",
|
|
2618
|
+
"List",
|
|
2619
|
+
"Chart",
|
|
2620
|
+
"Map",
|
|
2621
|
+
"Image",
|
|
2622
|
+
"Svg",
|
|
2623
|
+
"Citation",
|
|
2624
|
+
"FollowUp",
|
|
2625
|
+
"EntityCard"
|
|
2626
|
+
]);
|
|
2627
|
+
function defaultGenerativeUIPromptSpec() {
|
|
2628
|
+
return {
|
|
2629
|
+
markdown: {
|
|
2630
|
+
intro: "You can show interactive UI in your reply. Write A2UI operations inside a fenced code block tagged a2ui.",
|
|
2631
|
+
whenToShow: GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW,
|
|
2632
|
+
rules: [
|
|
2633
|
+
"Write explanations as normal markdown prose outside the fences.",
|
|
2634
|
+
"Open a fence with ```a2ui to show the surface in the chat, at the place of the fence.",
|
|
2635
|
+
"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 limits its components, its surfaces can use only those components.",
|
|
2636
|
+
"Inside a fence, write one JSON object per line and nothing else. No comments, no trailing commas, no pretty-printing.",
|
|
2637
|
+
"Keep each operation whole on its line.",
|
|
2638
|
+
"Give every operation \"version\":\"1.0\".",
|
|
2639
|
+
"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:\n ```a2ui\n {\"version\":\"1.0\",\"createSurface\":{\"surfaceId\":\"plan-picker\",\"dataModel\":{ ...initial data... },\"components\":[{\"id\":\"root\",\"component\":\"<Name>\",\"children\":[\"seats\",\"pick\"]}]}}\n {\"version\":\"1.0\",\"updateComponents\":{\"surfaceId\":\"plan-picker\",\"components\":[ ...the children... ]}}\n ```",
|
|
2640
|
+
"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.",
|
|
2641
|
+
"Every surface renders from the component with id \"root\". Make every other component reachable from \"root\" through slots.",
|
|
2642
|
+
"Send every component you reference in the same reply. If a surface gets long, make it smaller rather than leave components out.",
|
|
2643
|
+
"Use unique ids. Do not make cycles. A component cannot be its own child.",
|
|
2644
|
+
"Write a component as one flat object: {\"id\":\"title\",\"component\":\"<Name>\",\"text\":\"Hello\"}.",
|
|
2645
|
+
"Close each component with exactly one }, also when its last prop is a list: {\"id\":\"map\",\"component\":\"Map\",\"markers\":[{\"label\":\"A\",\"lat\":48.2,\"lng\":16.4}]}. A createSurface or updateComponents line ends with }]}} : the last component, the \"components\" list, the operation, the line.",
|
|
2646
|
+
"A prop that holds a call closes with }} : its \"args\", then the call. The component closes with its own single } after its last prop. With a prop after the call: {\"id\":\"count\",\"component\":\"Text\",\"text\":{\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} items\"}},\"size\":\"lg\"}. With the call last: {\"id\":\"count\",\"component\":\"Text\",\"size\":\"lg\",\"text\":{\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} items\"}}}.",
|
|
2647
|
+
"Deep props close every level they open, then the component closes with its own }. An event with a context: \"onSubmit\":{\"event\":{\"name\":\"send\",\"context\":{\"email\":{\"@path\":\"/email\"}}}}} ends with }}}}} : the path, \"context\", \"event\", the prop, the component. A Table: \"rows\":[[\"Mon\",\"9°C\"],[\"Tue\",\"7°C\"]]} ends with ]]} : the last row, \"rows\", the component, and nothing more. A list item with a call: \"items\":[{\"label\":{\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} cups\"}}}]} ends with }}}]} : \"args\", the call, the item, the list, the component.",
|
|
2648
|
+
"Put the component name in \"component\" (never \"type\"). Put props next to it, never inside a \"props\" object.",
|
|
2649
|
+
"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. \"live\":\"polite\" goes only inside \"accessibility\" ({\"accessibility\":{\"live\":\"polite\"}}), only on text that changes by itself, never as a prop of the component.",
|
|
2650
|
+
"Use only the components, props, events, and slots in the schema. A component marked +common also takes every common prop. A component with a prop that is not in its schema, or a value outside its enum, is dropped with everything inside it, so check each prop against the schema.",
|
|
2651
|
+
"Give a prop a literal value, or bind it to the data model with {\"@path\":\"/x\"}. Never write {\"path\":\"/x\"} as a binding.",
|
|
2652
|
+
"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 in the schema. Write a literal when the value never changes.",
|
|
2653
|
+
"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.",
|
|
2654
|
+
"${...} 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.",
|
|
2655
|
+
"Inside ${...}, close every ( you open, and write no operators and no ?: : compute with calc. To round a computed number, round inside calc instead of wrapping it in formatNumber: ${calc(expression: 'round(servings * 0.5 * 10) / 10', servings: /servings)} cups. calc has ^ (power), sqrt, exp and ln.",
|
|
2656
|
+
"To show one of two texts, let calc choose: \"text\":{\"@call\":\"calc\",\"args\":{\"expression\":\"billing == 'yearly' ? 'per year' : 'per month'\",\"billing\":{\"@path\":\"/billing\"}}}.",
|
|
2657
|
+
"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.",
|
|
2658
|
+
"Bind a writable prop to let the user edit it: \"value\":{\"@path\":\"/form/email\"}. The user's input goes to that path.",
|
|
2659
|
+
"The value of a ChoicePicker is a list of strings, also for one choice. SegmentedControl, RadioGroup and Select take one string. Option values are always strings: for a yes/no choice use \"yes\" and \"no\", not true and false.",
|
|
2660
|
+
"To change data, write updateDataModel with a \"path\" and a \"value\": {\"version\":\"1.0\",\"updateDataModel\":{\"surfaceId\":\"plan-picker\",\"path\":\"/seats\",\"value\":12}}. Always give \"value\".",
|
|
2661
|
+
"Set \"value\":null to delete the key at \"path\".",
|
|
2662
|
+
{
|
|
2663
|
+
when: ["events"],
|
|
2664
|
+
items: ["Give an event prop an object: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} or {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}}. Never a flat {\"event\":\"<name>\"}.", "Put the action of a Button in its \"onClick\": {\"event\":{...}} to send it back to you, or {\"functionCall\":{\"@call\":\"openUrl\",\"args\":{\"url\":\"...\"}}}. Never write \"event\" or \"functionCall\" as a prop of its own."]
|
|
2665
|
+
},
|
|
2666
|
+
{
|
|
2667
|
+
when: ["events", "functions"],
|
|
2668
|
+
items: ["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."]
|
|
2669
|
+
},
|
|
2670
|
+
{
|
|
2671
|
+
when: ["events", "noFunctions"],
|
|
2672
|
+
items: ["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."]
|
|
2673
|
+
},
|
|
2674
|
+
{
|
|
2675
|
+
when: ["events"],
|
|
2676
|
+
items: [
|
|
2677
|
+
"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\".",
|
|
2678
|
+
"To send input values with an event, bind them in the context: \"context\":{\"email\":{\"@path\":\"/form/email\"}}.",
|
|
2679
|
+
"A button or other event prop without an event or functionCall does nothing."
|
|
2680
|
+
]
|
|
2681
|
+
},
|
|
2682
|
+
{
|
|
2683
|
+
when: ["checks"],
|
|
2684
|
+
items: ["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."]
|
|
2685
|
+
},
|
|
2686
|
+
"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\"}].",
|
|
2687
|
+
{
|
|
2688
|
+
when: ["templates"],
|
|
2689
|
+
items: [
|
|
2690
|
+
"To repeat a component for each item of a list, give a childList a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}.",
|
|
2691
|
+
"Inside a template, paths are relative to the item (\"name\", not \"/name\").",
|
|
2692
|
+
"Inside a template, {\"@call\":\"@index\"} gives the position of the item, from 0. To count from 1, write {\"@call\":\"@index\",\"args\":{\"offset\":1}}."
|
|
2693
|
+
]
|
|
2694
|
+
},
|
|
2695
|
+
"Updating a component replaces all of its props. Send every prop again.",
|
|
2696
|
+
"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.",
|
|
2697
|
+
"Use a new surfaceId for a different view. Never use a surfaceId again, also after the surface is deleted.",
|
|
2698
|
+
{
|
|
2699
|
+
when: ["agentCalls"],
|
|
2700
|
+
items: [
|
|
2701
|
+
"To run an app function now, with no click, write a callRendererFunction line in a fence: {\"version\":\"1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}. It needs no surface.",
|
|
2702
|
+
"Give every callRendererFunction a new functionCallId. Call only a function that the schema marks 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.",
|
|
2703
|
+
"The result of a callRendererFunction comes back to you as a developer message: {\"version\":\"1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Then you get a new turn.",
|
|
2704
|
+
"Do not guess the result of a callRendererFunction. Wait for the developer message."
|
|
2705
|
+
]
|
|
2706
|
+
},
|
|
2707
|
+
"The schema lists the surfaces that already exist. \"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.",
|
|
2708
|
+
"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.",
|
|
2709
|
+
"Put in a fence only what markdown cannot show: charts, tables, maps, images, badges, inputs, buttons, cards with controls.",
|
|
2710
|
+
"Use Card only for an interactive panel (controls, a form, a configurator). Put everything else in a plain layout component.",
|
|
2711
|
+
"Never wrap the whole reply in a fence."
|
|
2712
|
+
]
|
|
2713
|
+
},
|
|
2714
|
+
tool: {
|
|
2715
|
+
intro: `Call \`${GENERATIVE_UI_RENDER_TOOL}\` to show UI. Arguments: \`target\` first, then \`operations\` (A2UI v1.0 operations, applied in order).`,
|
|
2716
|
+
whenToShow: GENERATIVE_UI_WHEN_TO_SHOW,
|
|
2717
|
+
operations: [
|
|
2718
|
+
"{\"version\":\"1.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.",
|
|
2719
|
+
"{\"version\":\"1.0\",\"updateComponents\":{\"surfaceId\":\"<id>\",\"components\":[<component>, ...]}}: add or replace components by id.",
|
|
2720
|
+
"{\"version\":\"1.0\",\"updateDataModel\":{\"surfaceId\":\"<id>\",\"path\":\"/some/path\",\"value\":<json>}}: set the value at \"path\". Always give \"value\". \"value\":null deletes the key at \"path\".",
|
|
2721
|
+
"{\"version\":\"1.0\",\"deleteSurface\":{\"surfaceId\":\"<id>\"}}: remove the surface.",
|
|
2722
|
+
{
|
|
2723
|
+
when: ["agentCalls"],
|
|
2724
|
+
items: ["{\"version\":\"1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}: run an app function now, with no click. It needs no surface."]
|
|
2725
|
+
}
|
|
2726
|
+
],
|
|
2727
|
+
rules: [
|
|
2728
|
+
"Components are flat objects: {\"id\":\"...\",\"component\":\"<Name>\", ...props}. Every surface renders from the component with id \"root\". Reference children by id in slot props.",
|
|
2729
|
+
"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.",
|
|
2730
|
+
"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.",
|
|
2731
|
+
"Updating a component replaces all of its props, so resend every prop.",
|
|
2732
|
+
"Prop values are literals or data bindings {\"@path\":\"/data/path\"}. Never write {\"path\":\"/data/path\"} as a binding.",
|
|
2733
|
+
{
|
|
2734
|
+
when: ["events", "functions"],
|
|
2735
|
+
items: ["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."]
|
|
2736
|
+
},
|
|
2737
|
+
{
|
|
2738
|
+
when: ["events", "noFunctions"],
|
|
2739
|
+
items: ["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\"."]
|
|
2740
|
+
},
|
|
2741
|
+
"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.",
|
|
2742
|
+
"Never use a surfaceId again, also after deleteSurface.",
|
|
2743
|
+
"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.",
|
|
2744
|
+
"${...} 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\"}}}.",
|
|
2745
|
+
"For a computed list (chart data, template items) use series. Its description under Functions gives the rules and an example.",
|
|
2746
|
+
{
|
|
2747
|
+
when: ["checks"],
|
|
2748
|
+
items: ["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."]
|
|
2749
|
+
},
|
|
2750
|
+
{
|
|
2751
|
+
when: ["templates"],
|
|
2752
|
+
items: ["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."]
|
|
2753
|
+
},
|
|
2754
|
+
{
|
|
2755
|
+
when: ["agentCalls"],
|
|
2756
|
+
items: ["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.", "The result of a callRendererFunction comes back to you in a new turn, as a developer message: {\"version\":\"1.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."]
|
|
2757
|
+
}
|
|
2758
|
+
]
|
|
2759
|
+
},
|
|
2760
|
+
schema: {
|
|
2761
|
+
markdown: {
|
|
2762
|
+
notation: "lines",
|
|
2763
|
+
propDescriptions: true,
|
|
2764
|
+
commonProps: true
|
|
2765
|
+
},
|
|
2766
|
+
tool: {
|
|
2767
|
+
notation: "json-schema",
|
|
2768
|
+
propDescriptions: true,
|
|
2769
|
+
commonProps: false
|
|
2770
|
+
}
|
|
2771
|
+
},
|
|
2772
|
+
descriptions: {}
|
|
2773
|
+
};
|
|
2774
|
+
}
|
|
2775
|
+
/** The rules of `items` whose block conditions hold, in order. */
|
|
2776
|
+
function selectPromptItems(items, features) {
|
|
2777
|
+
return items.flatMap((item) => typeof item === "string" ? [item] : item.when.every((feature) => features[feature]) ? item.items : []);
|
|
2778
|
+
}
|
|
2779
|
+
/**
|
|
2780
|
+
* The prompt features of a run, from the guide features of its manifest
|
|
2781
|
+
* (`generativeUIGuideFeatures`).
|
|
2782
|
+
*/
|
|
2783
|
+
function generativeUIPromptFeatures(guide) {
|
|
2784
|
+
return {
|
|
2785
|
+
functions: guide.functions,
|
|
2786
|
+
noFunctions: !guide.functions,
|
|
2787
|
+
events: guide.events,
|
|
2788
|
+
templates: guide.templates,
|
|
2789
|
+
checks: guide.checks,
|
|
2790
|
+
agentCalls: guide.functions && GENERATIVE_UI_AGENT_FUNCTION_CALLS
|
|
2791
|
+
};
|
|
2792
|
+
}
|
|
2793
|
+
|
|
2748
2794
|
//#endregion
|
|
2749
2795
|
//#region src/a2ui-prompts.ts
|
|
2750
2796
|
/**
|
|
@@ -2860,12 +2906,6 @@ Design principles:
|
|
|
2860
2906
|
action context should reference the same paths to capture user input.
|
|
2861
2907
|
|
|
2862
2908
|
Use the SAME surfaceId as the main surface. Match action names to button action event names.`;
|
|
2863
|
-
/**
|
|
2864
|
-
* When UI helps the user, for both transports: a light nudge to reach for UI
|
|
2865
|
-
* where it conveys the answer better than prose, and to stay in prose
|
|
2866
|
-
* otherwise.
|
|
2867
|
-
*/
|
|
2868
|
-
const GENERATIVE_UI_WHEN_TO_SHOW = "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.";
|
|
2869
2909
|
/** Description of the context entry that carries `GENERATIVE_UI_MARKDOWN_GUIDELINES`. */
|
|
2870
2910
|
const GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION = "Generative UI markdown guide: how to write UI surfaces inside ```a2ui code fences in a normal markdown reply.";
|
|
2871
2911
|
/**
|
|
@@ -2911,6 +2951,7 @@ Use the SAME surfaceId as the main surface. Match action names to button action
|
|
|
2911
2951
|
return Object.values(node).some(hasChildList);
|
|
2912
2952
|
};
|
|
2913
2953
|
return {
|
|
2954
|
+
components: Object.keys(manifest.components),
|
|
2914
2955
|
functions: Object.keys(manifest.functions).some((name) => !isA2UIBasicFunction(name)),
|
|
2915
2956
|
events: components.some((c) => {
|
|
2916
2957
|
var _c$events;
|
|
@@ -2926,43 +2967,21 @@ Use the SAME surfaceId as the main surface. Match action names to button action
|
|
|
2926
2967
|
})
|
|
2927
2968
|
};
|
|
2928
2969
|
}
|
|
2929
|
-
/**
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
"Use unique ids. Do not make cycles. A component cannot be its own child.",
|
|
2945
|
-
"Write a component as one flat object: {\"id\":\"title\",\"component\":\"<Name>\",\"text\":\"Hello\"}.",
|
|
2946
|
-
"Put the component name in \"component\" (never \"type\"). Put props next to it, never inside a \"props\" object.",
|
|
2947
|
-
"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.",
|
|
2948
|
-
"Use only the components, props, events, and slots in the schema. A component with \"includesCommonProps\" also takes every prop in \"commonProps\".",
|
|
2949
|
-
"Give a prop a literal value, or bind it to the data model with {\"@path\":\"/x\"}. Never write {\"path\":\"/x\"} as a binding.",
|
|
2950
|
-
"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.",
|
|
2951
|
-
"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.",
|
|
2952
|
-
"${...} 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.",
|
|
2953
|
-
"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.",
|
|
2954
|
-
"Bind a writable prop to let the user edit it: \"value\":{\"@path\":\"/form/email\"}. The user's input goes to that path.",
|
|
2955
|
-
"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\".",
|
|
2956
|
-
"Set \"value\":null to delete the key at \"path\"."
|
|
2957
|
-
];
|
|
2958
|
-
/** The last rules of every markdown guideline, after the optional groups. */
|
|
2959
|
-
const MARKDOWN_CLOSING_RULES = [
|
|
2960
|
-
"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.",
|
|
2961
|
-
"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.",
|
|
2962
|
-
"Put in a fence only what markdown cannot show: charts, tables, maps, images, badges, inputs, buttons, cards with controls.",
|
|
2963
|
-
"Use Card only for an interactive panel (controls, a form, a configurator). Put everything else in a plain layout component.",
|
|
2964
|
-
"Never wrap the whole reply in a fence."
|
|
2965
|
-
];
|
|
2970
|
+
/**
|
|
2971
|
+
* Whether a guide line names only standard components (`GUIDE_COMPONENTS`,
|
|
2972
|
+
* also in the plural) that the catalog has. With no catalog, every line fits.
|
|
2973
|
+
*/
|
|
2974
|
+
function namesOnlyCatalogComponents(catalog) {
|
|
2975
|
+
if (!catalog) return () => true;
|
|
2976
|
+
const has = new Set(catalog);
|
|
2977
|
+
return (line) => {
|
|
2978
|
+
var _line$match;
|
|
2979
|
+
return ((_line$match = line.match(/\b[A-Z][A-Za-z0-9]*\b/g)) !== null && _line$match !== void 0 ? _line$match : []).every((word) => {
|
|
2980
|
+
const name = !GUIDE_COMPONENTS.has(word) && word.endsWith("s") ? word.slice(0, -1) : word;
|
|
2981
|
+
return !GUIDE_COMPONENTS.has(name) || has.has(name);
|
|
2982
|
+
});
|
|
2983
|
+
};
|
|
2984
|
+
}
|
|
2966
2985
|
/**
|
|
2967
2986
|
* Builds the markdown-transport guideline. The model writes A2UI v1.0
|
|
2968
2987
|
* operations inside ```a2ui fences between normal markdown prose. The rules
|
|
@@ -2970,25 +2989,15 @@ Use the SAME surfaceId as the main surface. Match action names to button action
|
|
|
2970
2989
|
* none of them, so the guideline stays small.
|
|
2971
2990
|
*
|
|
2972
2991
|
* @param features - The optional rule groups to include. Defaults to all.
|
|
2992
|
+
* @param spec - The wording. Defaults to the prompts that ship.
|
|
2973
2993
|
* @returns The guideline text, one rule per line.
|
|
2974
2994
|
*/
|
|
2975
|
-
function buildGenerativeUIMarkdownGuidelines(features = ALL_GENERATIVE_UI_GUIDE_FEATURES) {
|
|
2976
|
-
const {
|
|
2977
|
-
const
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
if (templates) rules.push("To repeat a component for each item of a list, give a childList a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}.", "Inside a template, paths are relative to the item (\"name\", not \"/name\").", "Inside a template, {\"@call\":\"@index\"} gives the position of the item, from 0. To count from 1, write {\"@call\":\"@index\",\"args\":{\"offset\":1}}.");
|
|
2982
|
-
rules.push("Updating a component replaces all of its props. Send every prop again.", "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.", "Use a new surfaceId for a different view. Never use a surfaceId again, also after the surface is deleted.");
|
|
2983
|
-
if (functions && GENERATIVE_UI_AGENT_FUNCTION_CALLS) rules.push("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.", "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.", "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.", "Do not guess the result of a callRendererFunction. Wait for the developer message.");
|
|
2984
|
-
rules.push(...MARKDOWN_CLOSING_RULES);
|
|
2985
|
-
return `You can show interactive UI in your reply. Write A2UI operations inside a fenced code block tagged a2ui.
|
|
2986
|
-
|
|
2987
|
-
${GENERATIVE_UI_WHEN_TO_SHOW}
|
|
2988
|
-
|
|
2989
|
-
RULES
|
|
2990
|
-
${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
2991
|
-
`;
|
|
2995
|
+
function buildGenerativeUIMarkdownGuidelines(features = ALL_GENERATIVE_UI_GUIDE_FEATURES, spec = defaultGenerativeUIPromptSpec()) {
|
|
2996
|
+
const { intro, rules } = spec.markdown;
|
|
2997
|
+
const fits = namesOnlyCatalogComponents(features.components);
|
|
2998
|
+
const selected = selectPromptItems(rules, generativeUIPromptFeatures(features)).filter(fits);
|
|
2999
|
+
const whenToShow = spec.markdown.whenToShow.split("\n").filter(fits).join("\n");
|
|
3000
|
+
return `${intro}\n\n${whenToShow ? `${whenToShow}\n\n` : ""}RULES\n${selected.map((rule) => `- ${rule}`).join("\n")}\n`;
|
|
2992
3001
|
}
|
|
2993
3002
|
/**
|
|
2994
3003
|
* The markdown-transport guideline with every rule group. A run sends
|
|
@@ -3016,11 +3025,11 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3016
3025
|
return typeof value === "string" && value !== "";
|
|
3017
3026
|
}
|
|
3018
3027
|
function isRecordOf(value, isEntry) {
|
|
3019
|
-
return isRecord(value) && Object.values(value).every(isEntry);
|
|
3028
|
+
return isRecord$2(value) && Object.values(value).every(isEntry);
|
|
3020
3029
|
}
|
|
3021
3030
|
/** A function, or an event of a component: a description and a parameter schema. */
|
|
3022
3031
|
function isSchemaEntry(value) {
|
|
3023
|
-
return isRecord(value) && isRecord(value.parameters) && isOptionalString(value.description);
|
|
3032
|
+
return isRecord$2(value) && isRecord$2(value.parameters) && isOptionalString(value.description);
|
|
3024
3033
|
}
|
|
3025
3034
|
function isSlotKind(value) {
|
|
3026
3035
|
return value === "single" || value === "multiple";
|
|
@@ -3030,11 +3039,11 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3030
3039
|
* so those two must have the right shape when they are there.
|
|
3031
3040
|
*/
|
|
3032
3041
|
function isPropsSchema(value) {
|
|
3033
|
-
return isRecord(value) && (value.properties === void 0 || isRecord(value.properties)) && (value.required === void 0 || Array.isArray(value.required) && value.required.every((name) => typeof name === "string"));
|
|
3042
|
+
return isRecord$2(value) && (value.properties === void 0 || isRecord$2(value.properties)) && (value.required === void 0 || Array.isArray(value.required) && value.required.every((name) => typeof name === "string"));
|
|
3034
3043
|
}
|
|
3035
3044
|
function isComponentManifest(value) {
|
|
3036
3045
|
var _value$props$properti, _value$slots, _value$events;
|
|
3037
|
-
if (!isRecord(value) || !isPropsSchema(value.props) || !isOptionalString(value.description) || value.events !== void 0 && !isRecordOf(value.events, isSchemaEntry) || value.slots !== void 0 && !isRecordOf(value.slots, isSlotKind)) return false;
|
|
3046
|
+
if (!isRecord$2(value) || !isPropsSchema(value.props) || !isOptionalString(value.description) || value.events !== void 0 && !isRecordOf(value.events, isSchemaEntry) || value.slots !== void 0 && !isRecordOf(value.slots, isSlotKind)) return false;
|
|
3038
3047
|
const order = value.parameterOrder;
|
|
3039
3048
|
if (order === void 0) return true;
|
|
3040
3049
|
const keys = new Set([
|
|
@@ -3045,31 +3054,31 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3045
3054
|
return Array.isArray(order) && new Set(order).size === order.length && order.every((key) => typeof key === "string" && keys.has(key));
|
|
3046
3055
|
}
|
|
3047
3056
|
function isInlineCatalog(value) {
|
|
3048
|
-
return isRecord(value) && isNonEmptyString(value.catalogId) && value.protocolVersion === "1.0" && (value.components === void 0 || isRecordOf(value.components, isComponentManifest)) && isRecordOf(value.functions, isSchemaEntry) && isOptionalString(value.instructions);
|
|
3057
|
+
return isRecord$2(value) && isNonEmptyString(value.catalogId) && value.protocolVersion === "1.0" && (value.components === void 0 || isRecordOf(value.components, isComponentManifest)) && isRecordOf(value.functions, isSchemaEntry) && isOptionalString(value.instructions);
|
|
3049
3058
|
}
|
|
3050
3059
|
function isCapabilities(value) {
|
|
3051
|
-
return isRecord(value) && Array.isArray(value.supportedCatalogIds) && value.supportedCatalogIds.length > 0 && value.supportedCatalogIds.every(isNonEmptyString) && (value.inlineCatalogs === void 0 || Array.isArray(value.inlineCatalogs) && value.inlineCatalogs.every(isInlineCatalog));
|
|
3060
|
+
return isRecord$2(value) && Array.isArray(value.supportedCatalogIds) && value.supportedCatalogIds.length > 0 && value.supportedCatalogIds.every(isNonEmptyString) && (value.inlineCatalogs === void 0 || Array.isArray(value.inlineCatalogs) && value.inlineCatalogs.every(isInlineCatalog));
|
|
3052
3061
|
}
|
|
3053
3062
|
/** A short list of component names. */
|
|
3054
3063
|
function isComponentNameList(value) {
|
|
3055
3064
|
return Array.isArray(value) && value.length <= GENERATIVE_UI_MAX_TARGET_COMPONENTS && value.every(isNonEmptyString);
|
|
3056
3065
|
}
|
|
3057
3066
|
function isTarget(value) {
|
|
3058
|
-
return isRecord(value) && isNonEmptyString(value.id) && (value.kind === "chat" || value.kind === "inline") && isOptionalString(value.description) && (value.components === void 0 || isComponentNameList(value.components));
|
|
3067
|
+
return isRecord$2(value) && isNonEmptyString(value.id) && (value.kind === "chat" || value.kind === "inline") && isOptionalString(value.description) && (value.components === void 0 || isComponentNameList(value.components));
|
|
3059
3068
|
}
|
|
3060
3069
|
/** A short list of short strings. The summary limits keep the guide small. */
|
|
3061
3070
|
function isRejectionList(value) {
|
|
3062
3071
|
return Array.isArray(value) && value.length <= GENERATIVE_UI_MAX_SUMMARY_REJECTIONS && value.every((entry) => typeof entry === "string" && entry.length <= GENERATIVE_UI_MAX_REJECTION_LENGTH);
|
|
3063
3072
|
}
|
|
3064
3073
|
function isSurfaceEntry(value) {
|
|
3065
|
-
return isRecord(value) && isNonEmptyString(value.target) && (value.dataModel === void 0 || isRecord(value.dataModel)) && (value.rejected === void 0 || isRejectionList(value.rejected)) && (value.status === void 0 || value.status === "deleted" || value.status === "failed");
|
|
3074
|
+
return isRecord$2(value) && isNonEmptyString(value.target) && (value.dataModel === void 0 || isRecord$2(value.dataModel)) && (value.rejected === void 0 || isRejectionList(value.rejected)) && (value.status === void 0 || value.status === "deleted" || value.status === "failed") && (value.a2uiSourceVersion === void 0 || value.a2uiSourceVersion === "0.9");
|
|
3066
3075
|
}
|
|
3067
3076
|
/** Checks the `copilotkit_` keys only. Other extensions can be there too. */
|
|
3068
3077
|
function isExtensions(value) {
|
|
3069
|
-
return isRecord(value) && value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT && (value.copilotkit_transport === "tool" || value.copilotkit_transport === "markdown") && Array.isArray(value.copilotkit_targets) && value.copilotkit_targets.every(isTarget) && isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) && typeof value.copilotkit_contextSent === "boolean";
|
|
3078
|
+
return isRecord$2(value) && value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT && (value.copilotkit_transport === "tool" || value.copilotkit_transport === "markdown") && Array.isArray(value.copilotkit_targets) && value.copilotkit_targets.every(isTarget) && isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) && typeof value.copilotkit_contextSent === "boolean";
|
|
3070
3079
|
}
|
|
3071
3080
|
function isEnvelope(value) {
|
|
3072
|
-
return isRecord(value) && isCapabilities(value["
|
|
3081
|
+
return isRecord$2(value) && isCapabilities(value["1.0"]) && isRecord$2(value.metadata) && isExtensions(value.metadata.extensions);
|
|
3073
3082
|
}
|
|
3074
3083
|
/**
|
|
3075
3084
|
* Reads the generative UI envelope from the `forwardedProps` of a run.
|
|
@@ -3090,9 +3099,9 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3090
3099
|
* ```
|
|
3091
3100
|
*/
|
|
3092
3101
|
function readCopilotKitUIEnvelope(forwardedProps) {
|
|
3093
|
-
if (!isRecord(forwardedProps)) return void 0;
|
|
3102
|
+
if (!isRecord$2(forwardedProps)) return void 0;
|
|
3094
3103
|
const namespace = forwardedProps[COPILOTKIT_FORWARDED_PROPS_KEY];
|
|
3095
|
-
if (!isRecord(namespace)) return void 0;
|
|
3104
|
+
if (!isRecord$2(namespace)) return void 0;
|
|
3096
3105
|
const envelope = namespace.ui;
|
|
3097
3106
|
return isEnvelope(envelope) ? envelope : void 0;
|
|
3098
3107
|
}
|
|
@@ -3125,7 +3134,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3125
3134
|
*/
|
|
3126
3135
|
function envelopeToManifest(envelope) {
|
|
3127
3136
|
var _catalog$components, _catalog$functions;
|
|
3128
|
-
const { supportedCatalogIds, inlineCatalogs } = envelope["
|
|
3137
|
+
const { supportedCatalogIds, inlineCatalogs } = envelope["1.0"];
|
|
3129
3138
|
const catalogId = supportedCatalogIds[0];
|
|
3130
3139
|
const catalog = inlineCatalogs === null || inlineCatalogs === void 0 ? void 0 : inlineCatalogs.find((entry) => entry.catalogId === catalogId);
|
|
3131
3140
|
const extensions = envelope.metadata.extensions;
|
|
@@ -3165,7 +3174,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3165
3174
|
});
|
|
3166
3175
|
/** Models write the v0.9 binding from habit. The reason names the v1.0 form. */
|
|
3167
3176
|
const V09_PATH_REASON = "bind data with {\"@path\": \"/x\"}, not {\"path\": \"/x\"}";
|
|
3168
|
-
function hasOwn(record, key) {
|
|
3177
|
+
function hasOwn$1(record, key) {
|
|
3169
3178
|
return Object.prototype.hasOwnProperty.call(record, key);
|
|
3170
3179
|
}
|
|
3171
3180
|
/**
|
|
@@ -3173,42 +3182,42 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3173
3182
|
* "toString" must not resolve to Object.prototype members.
|
|
3174
3183
|
*/
|
|
3175
3184
|
function ownValue(record, key) {
|
|
3176
|
-
return record && hasOwn(record, key) ? record[key] : void 0;
|
|
3185
|
+
return record && hasOwn$1(record, key) ? record[key] : void 0;
|
|
3177
3186
|
}
|
|
3178
3187
|
function getOperationKind(op) {
|
|
3179
|
-
if (!isRecord(op)) return void 0;
|
|
3188
|
+
if (!isRecord$2(op)) return void 0;
|
|
3180
3189
|
const kinds = OPERATION_KINDS.filter((kind) => kind in op);
|
|
3181
3190
|
return kinds.length === 1 ? kinds[0] : void 0;
|
|
3182
3191
|
}
|
|
3183
3192
|
/** The `surfaceId` of a surface operation. `callRendererFunction` has none. */
|
|
3184
3193
|
function getOperationSurfaceId(op) {
|
|
3185
|
-
if (!isRecord(op)) return void 0;
|
|
3194
|
+
if (!isRecord$2(op)) return void 0;
|
|
3186
3195
|
const kind = getOperationKind(op);
|
|
3187
3196
|
if (!kind) return void 0;
|
|
3188
3197
|
const payload = op[kind];
|
|
3189
|
-
return isRecord(payload) && typeof payload.surfaceId === "string" ? payload.surfaceId : void 0;
|
|
3198
|
+
return isRecord$2(payload) && typeof payload.surfaceId === "string" ? payload.surfaceId : void 0;
|
|
3190
3199
|
}
|
|
3191
3200
|
/** `{ "@path": "/x" }`: a data-model binding. */
|
|
3192
3201
|
function isPathBinding(value) {
|
|
3193
|
-
return isRecord(value) && typeof value["@path"] === "string" && Object.keys(value).length === 1;
|
|
3202
|
+
return isRecord$2(value) && typeof value["@path"] === "string" && Object.keys(value).length === 1;
|
|
3194
3203
|
}
|
|
3195
3204
|
/** `{ "path": "/x" }`: the v0.9 binding, which v1.0 does not accept. */
|
|
3196
3205
|
function isV09PathBinding(value) {
|
|
3197
|
-
return isRecord(value) && typeof value.path === "string" && Object.keys(value).length === 1;
|
|
3206
|
+
return isRecord$2(value) && typeof value.path === "string" && Object.keys(value).length === 1;
|
|
3198
3207
|
}
|
|
3199
3208
|
/**
|
|
3200
3209
|
* `{ "@call": "@index" }` or `{ "@call": "@index", "args": { "offset": 1 } }`:
|
|
3201
3210
|
* the 0-based position of the item in a template, plus `offset`.
|
|
3202
3211
|
*/
|
|
3203
3212
|
function isIndexCall(value) {
|
|
3204
|
-
if (!isRecord(value) || value["@call"] !== "@index") return false;
|
|
3213
|
+
if (!isRecord$2(value) || value["@call"] !== "@index") return false;
|
|
3205
3214
|
if (!Object.keys(value).every((key) => key === "@call" || key === "args")) return false;
|
|
3206
3215
|
const { args } = value;
|
|
3207
3216
|
if (args === void 0) return true;
|
|
3208
|
-
return isRecord(args) && Object.keys(args).every((key) => key === "offset") && (args.offset === void 0 || Number.isFinite(args.offset));
|
|
3217
|
+
return isRecord$2(args) && Object.keys(args).every((key) => key === "offset") && (args.offset === void 0 || Number.isFinite(args.offset));
|
|
3209
3218
|
}
|
|
3210
3219
|
function isActionBinding(value) {
|
|
3211
|
-
return isRecord(value) && Object.keys(value).length === 1 && (isRecord(value.functionCall) || isRecord(value.event));
|
|
3220
|
+
return isRecord$2(value) && Object.keys(value).length === 1 && (isRecord$2(value.functionCall) || isRecord$2(value.event));
|
|
3212
3221
|
}
|
|
3213
3222
|
/**
|
|
3214
3223
|
* Checks one A2UI v1.0 operation against the catalog and the surfaces that
|
|
@@ -3226,7 +3235,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3226
3235
|
* ```
|
|
3227
3236
|
*/
|
|
3228
3237
|
function validateOperation(op, options) {
|
|
3229
|
-
if (!isRecord(op)) return fail("operation must be a JSON object");
|
|
3238
|
+
if (!isRecord$2(op)) return fail("operation must be a JSON object");
|
|
3230
3239
|
if (op.version !== A2UI_VERSION) return fail(versionProblem(op.version));
|
|
3231
3240
|
const kind = getOperationKind(op);
|
|
3232
3241
|
if (!kind) return fail(`operation must contain exactly one of ${OPERATION_KINDS.join(", ")}`);
|
|
@@ -3235,7 +3244,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3235
3244
|
if (!GENERATIVE_UI_AGENT_FUNCTION_CALLS) return fail(GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON);
|
|
3236
3245
|
return validateRendererFunctionCall(payload, options);
|
|
3237
3246
|
}
|
|
3238
|
-
if (!isRecord(payload) || typeof payload.surfaceId !== "string" || !payload.surfaceId) return fail(`${kind}.surfaceId is required`);
|
|
3247
|
+
if (!isRecord$2(payload) || typeof payload.surfaceId !== "string" || !payload.surfaceId) return fail(`${kind}.surfaceId is required`);
|
|
3239
3248
|
const surfaceId = payload.surfaceId;
|
|
3240
3249
|
if (kind === "createSurface") return validateCreateSurface(payload, surfaceId, options);
|
|
3241
3250
|
if (!options.knownSurfaces.has(surfaceId)) return fail(`surface "${surfaceId}" does not exist; send createSurface first`);
|
|
@@ -3264,12 +3273,12 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3264
3273
|
const catalogReason = catalogProblem(payload.catalogId, options.manifest);
|
|
3265
3274
|
if (catalogReason) return fail(catalogReason);
|
|
3266
3275
|
const { dataModel, components } = payload;
|
|
3267
|
-
if (dataModel !== void 0 && !isRecord(dataModel)) return fail("createSurface.dataModel must be a JSON object");
|
|
3276
|
+
if (dataModel !== void 0 && !isRecord$2(dataModel)) return fail("createSurface.dataModel must be a JSON object");
|
|
3268
3277
|
if (components === void 0) return OK;
|
|
3269
3278
|
return validateComponents(components, "createSurface.components", options);
|
|
3270
3279
|
}
|
|
3271
3280
|
function validateRendererFunctionCall(payload, options) {
|
|
3272
|
-
if (!(isRecord(payload) && typeof payload.functionCallId === "string" && payload.functionCallId !== "")) return fail("callRendererFunction.functionCallId must be a non-empty string");
|
|
3281
|
+
if (!(isRecord$2(payload) && typeof payload.functionCallId === "string" && payload.functionCallId !== "")) return fail("callRendererFunction.functionCallId must be a non-empty string");
|
|
3273
3282
|
const reason = functionCallProblem(payload.callFunction, "callRendererFunction.callFunction", options);
|
|
3274
3283
|
return reason ? fail(reason) : OK;
|
|
3275
3284
|
}
|
|
@@ -3287,7 +3296,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3287
3296
|
const path = (_payload$path = payload.path) !== null && _payload$path !== void 0 ? _payload$path : "/";
|
|
3288
3297
|
if (typeof path !== "string" || !path.startsWith("/")) return fail("updateDataModel.path must be an absolute JSON pointer");
|
|
3289
3298
|
if (path === "/") {
|
|
3290
|
-
if (!isRecord(payload.value)) return fail("a root updateDataModel value must be a JSON object");
|
|
3299
|
+
if (!isRecord$2(payload.value)) return fail("a root updateDataModel value must be a JSON object");
|
|
3291
3300
|
return OK;
|
|
3292
3301
|
}
|
|
3293
3302
|
const reason = pathProblem(path, "updateDataModel.path");
|
|
@@ -3307,7 +3316,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3307
3316
|
if (!Array.isArray(components) || components.length === 0) return fail(`${label} must be a non-empty array`);
|
|
3308
3317
|
const ids = /* @__PURE__ */ new Set();
|
|
3309
3318
|
for (const node of components) {
|
|
3310
|
-
if (!isRecord(node)) return fail("component must be a JSON object");
|
|
3319
|
+
if (!isRecord$2(node)) return fail("component must be a JSON object");
|
|
3311
3320
|
const { id } = node;
|
|
3312
3321
|
if (typeof id !== "string" || !id) return fail("id is required");
|
|
3313
3322
|
const reason = nodeProblem(node, id, options);
|
|
@@ -3327,7 +3336,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3327
3336
|
return `"${node.component}" is not allowed in target "${allowedComponents.target}"; use one of: ${names}`;
|
|
3328
3337
|
}
|
|
3329
3338
|
const { properties, required } = entry.props;
|
|
3330
|
-
const propNames = isRecord(properties) ? Object.keys(properties) : [];
|
|
3339
|
+
const propNames = isRecord$2(properties) ? Object.keys(properties) : [];
|
|
3331
3340
|
const props = Object.entries(node);
|
|
3332
3341
|
for (const [key, value] of props) {
|
|
3333
3342
|
if (key === "id" || key === "component") continue;
|
|
@@ -3337,7 +3346,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3337
3346
|
continue;
|
|
3338
3347
|
}
|
|
3339
3348
|
if (key === "metadata") {
|
|
3340
|
-
if (!(isRecord(value) && (value.extensions === void 0 || isRecord(value.extensions)))) return "metadata must be { \"extensions\": { ... } }";
|
|
3349
|
+
if (!(isRecord$2(value) && (value.extensions === void 0 || isRecord$2(value.extensions)))) return "metadata must be { \"extensions\": { ... } }";
|
|
3341
3350
|
continue;
|
|
3342
3351
|
}
|
|
3343
3352
|
if (key === "accessibility") {
|
|
@@ -3385,7 +3394,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3385
3394
|
* values, `hidden` is a boolean or a dynamic value.
|
|
3386
3395
|
*/
|
|
3387
3396
|
function accessibilityProblem(value) {
|
|
3388
|
-
if (!isRecord(value)) return "must be { \"label\": \"...\", \"description\": \"...\", \"live\": \"polite\", \"hidden\": false }";
|
|
3397
|
+
if (!isRecord$2(value)) return "must be { \"label\": \"...\", \"description\": \"...\", \"live\": \"polite\", \"hidden\": false }";
|
|
3389
3398
|
const isDynamic = (field) => isPathBinding(field) || isCallBinding(field);
|
|
3390
3399
|
for (const [key, field] of Object.entries(value)) {
|
|
3391
3400
|
if (!ACCESSIBILITY_KEYS.includes(key)) return `unknown key "${key}"`;
|
|
@@ -3403,7 +3412,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3403
3412
|
}
|
|
3404
3413
|
}
|
|
3405
3414
|
function actionBindingProblem(value, options) {
|
|
3406
|
-
if (!isRecord(value)) return "must be an action object";
|
|
3415
|
+
if (!isRecord$2(value)) return "must be an action object";
|
|
3407
3416
|
const keys = Object.keys(value);
|
|
3408
3417
|
if (!(keys.length === 1 && (keys[0] === "functionCall" || keys[0] === "event"))) return "must be { \"event\": ... } or { \"functionCall\": ... }";
|
|
3409
3418
|
if (keys[0] === "functionCall") return functionCallProblem(value.functionCall, "functionCall", options);
|
|
@@ -3414,18 +3423,18 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3414
3423
|
* field in the reason.
|
|
3415
3424
|
*/
|
|
3416
3425
|
function functionCallProblem(call, label, options) {
|
|
3417
|
-
if (!isRecord(call)) return `${label} must be { "@call": "<function>", "args": { ... } }`;
|
|
3426
|
+
if (!isRecord$2(call)) return `${label} must be { "@call": "<function>", "args": { ... } }`;
|
|
3418
3427
|
const name = call["@call"];
|
|
3419
3428
|
if (typeof name !== "string" || !name) return typeof call.call === "string" ? `${label} names the function with "@call", not "call"` : `${label}["@call"] must be a function name`;
|
|
3420
3429
|
const { args } = call;
|
|
3421
|
-
if (args !== void 0 && !isRecord(args)) return `${label}.args must be an object`;
|
|
3430
|
+
if (args !== void 0 && !isRecord$2(args)) return `${label}.args must be an object`;
|
|
3422
3431
|
const catalogReason = catalogProblem(call.catalogId, options.manifest);
|
|
3423
3432
|
if (catalogReason) return `${label}: ${catalogReason}`;
|
|
3424
3433
|
const argEntries = Object.entries(args !== null && args !== void 0 ? args : {});
|
|
3425
3434
|
for (const [key, arg] of argEntries) if (isV09PathBinding(arg)) return `${label}.args.${key}: ${V09_PATH_REASON}`;
|
|
3426
3435
|
const appFunctions = options.functions;
|
|
3427
|
-
const declared = appFunctions !== void 0 && hasOwn(appFunctions, name) ? appFunctions[name] : void 0;
|
|
3428
|
-
const builtIn = declared === void 0 && hasOwn(GENERATIVE_UI_FUNCTIONS, name) ? GENERATIVE_UI_FUNCTIONS[name] : void 0;
|
|
3436
|
+
const declared = appFunctions !== void 0 && hasOwn$1(appFunctions, name) ? appFunctions[name] : void 0;
|
|
3437
|
+
const builtIn = declared === void 0 && hasOwn$1(GENERATIVE_UI_FUNCTIONS, name) ? GENERATIVE_UI_FUNCTIONS[name] : void 0;
|
|
3429
3438
|
if (declared === void 0 && builtIn === void 0) return appFunctions === void 0 ? void 0 : `function "${name}" is not exposed to generative UI`;
|
|
3430
3439
|
if (declared === void 0 && appFunctions === void 0) return void 0;
|
|
3431
3440
|
return callerProblem(name, declared !== null && declared !== void 0 ? declared : builtIn, label.startsWith("callRendererFunction") ? "agent" : "renderer");
|
|
@@ -3441,11 +3450,11 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3441
3450
|
if (caller === "renderer" && !callers.renderer) return `function "${name}" runs only for the agent (allowedCallers "agentOnly"); the UI cannot call it`;
|
|
3442
3451
|
}
|
|
3443
3452
|
function eventProblem(event) {
|
|
3444
|
-
if (!isRecord(event) || typeof event.name !== "string" || !event.name) return "event.name is required";
|
|
3453
|
+
if (!isRecord$2(event) || typeof event.name !== "string" || !event.name) return "event.name is required";
|
|
3445
3454
|
const { userMessage, context } = event;
|
|
3446
|
-
if (!(userMessage === void 0 || typeof userMessage === "string" || isPathBinding(userMessage) || isRecord(userMessage) && typeof userMessage["@call"] === "string" && findForbiddenCall(userMessage, { allowValueFunctions: true }) === void 0)) return isV09PathBinding(userMessage) ? `event.userMessage: ${V09_PATH_REASON}` : "event.userMessage must be a string, {\"@path\": \"/x\"} or a function value";
|
|
3455
|
+
if (!(userMessage === void 0 || typeof userMessage === "string" || isPathBinding(userMessage) || isRecord$2(userMessage) && typeof userMessage["@call"] === "string" && findForbiddenCall(userMessage, { allowValueFunctions: true }) === void 0)) return isV09PathBinding(userMessage) ? `event.userMessage: ${V09_PATH_REASON}` : "event.userMessage must be a string, {\"@path\": \"/x\"} or a function value";
|
|
3447
3456
|
if (context === void 0) return void 0;
|
|
3448
|
-
if (!isRecord(context)) return "event.context must be an object";
|
|
3457
|
+
if (!isRecord$2(context)) return "event.context must be an object";
|
|
3449
3458
|
const entries = Object.entries(context);
|
|
3450
3459
|
for (const [key, entry] of entries) {
|
|
3451
3460
|
if (isV09PathBinding(entry)) return `event.context.${key}: ${V09_PATH_REASON}`;
|
|
@@ -3454,7 +3463,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3454
3463
|
}
|
|
3455
3464
|
}
|
|
3456
3465
|
function slotProblem(value, kind, ownId) {
|
|
3457
|
-
const isTemplate = isRecord(value) && "componentId" in value;
|
|
3466
|
+
const isTemplate = isRecord$2(value) && "componentId" in value;
|
|
3458
3467
|
if (kind === "single" && isTemplate) return "a template { \"componentId\", \"path\" } is only allowed in a \"multiple\" slot";
|
|
3459
3468
|
if (kind === "multiple" && isTemplate) return templateProblem(value, ownId);
|
|
3460
3469
|
if (kind === "multiple" && !Array.isArray(value)) return "must be an array of component ids or a template { \"componentId\", \"path\" }";
|
|
@@ -3488,7 +3497,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3488
3497
|
}
|
|
3489
3498
|
return;
|
|
3490
3499
|
}
|
|
3491
|
-
if (!isRecord(value)) return void 0;
|
|
3500
|
+
if (!isRecord$2(value)) return void 0;
|
|
3492
3501
|
if (isIndexCall(value)) return void 0;
|
|
3493
3502
|
if (value["@call"] === "@index") return "@index takes only an offset";
|
|
3494
3503
|
if (typeof value.call === "string") return "name the function with \"@call\", not \"call\"";
|
|
@@ -3497,7 +3506,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3497
3506
|
if (typeof name === "string") {
|
|
3498
3507
|
if (!options.allowValueFunctions || !isA2UIValueFunction(name)) return isA2UIBasicFunction(name) ? `"${name}" runs only from an event` : `"${name}" is not a basic function`;
|
|
3499
3508
|
const args = value.args;
|
|
3500
|
-
if (args !== void 0 && !isRecord(args)) return `the args of "${name}" must be an object`;
|
|
3509
|
+
if (args !== void 0 && !isRecord$2(args)) return `the args of "${name}" must be an object`;
|
|
3501
3510
|
return args === void 0 ? void 0 : findForbiddenCall(args, options);
|
|
3502
3511
|
}
|
|
3503
3512
|
for (const item of Object.values(value)) {
|
|
@@ -3522,14 +3531,14 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3522
3531
|
*/
|
|
3523
3532
|
function childRefProblem(node, ref, ownId) {
|
|
3524
3533
|
const label = ref.path.filter((step) => step !== "*").join(".");
|
|
3525
|
-
const isDynamic = (value) => isPathBinding(value) || isRecord(value) && "@call" in value;
|
|
3534
|
+
const isDynamic = (value) => isPathBinding(value) || isRecord$2(value) && "@call" in value;
|
|
3526
3535
|
const visit = (value, steps) => {
|
|
3527
3536
|
if (isDynamic(value)) return void 0;
|
|
3528
|
-
|
|
3537
|
+
const [head, ...rest] = steps;
|
|
3538
|
+
if (head === void 0) {
|
|
3529
3539
|
const reason = slotProblem(value, ref.kind, ownId);
|
|
3530
3540
|
return reason ? `${label}: ${reason}` : void 0;
|
|
3531
3541
|
}
|
|
3532
|
-
const [head, ...rest] = steps;
|
|
3533
3542
|
if (head === "*") {
|
|
3534
3543
|
if (!Array.isArray(value)) return void 0;
|
|
3535
3544
|
for (const item of value) {
|
|
@@ -3538,7 +3547,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3538
3547
|
}
|
|
3539
3548
|
return;
|
|
3540
3549
|
}
|
|
3541
|
-
if (!isRecord(value) || !hasOwn(value, head)) return void 0;
|
|
3550
|
+
if (!isRecord$2(value) || !hasOwn$1(value, head)) return void 0;
|
|
3542
3551
|
return visit(value[head], rest);
|
|
3543
3552
|
};
|
|
3544
3553
|
return visit(node, ref.path);
|
|
@@ -3643,6 +3652,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3643
3652
|
expectingValue = false;
|
|
3644
3653
|
}
|
|
3645
3654
|
break;
|
|
3655
|
+
case void 0: break;
|
|
3646
3656
|
}
|
|
3647
3657
|
}
|
|
3648
3658
|
this.inString = inString;
|
|
@@ -3662,7 +3672,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3662
3672
|
function parseObject(raw) {
|
|
3663
3673
|
try {
|
|
3664
3674
|
const value = JSON.parse(raw);
|
|
3665
|
-
return isRecord(value) ? value : null;
|
|
3675
|
+
return isRecord$2(value) ? value : null;
|
|
3666
3676
|
} catch (_unused3) {
|
|
3667
3677
|
return null;
|
|
3668
3678
|
}
|
|
@@ -3699,6 +3709,799 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3699
3709
|
}
|
|
3700
3710
|
};
|
|
3701
3711
|
|
|
3712
|
+
//#endregion
|
|
3713
|
+
//#region src/generative-ui/clone-value.ts
|
|
3714
|
+
/**
|
|
3715
|
+
* A deep copy of `value` with `structuredClone` semantics. Uses the global
|
|
3716
|
+
* `structuredClone` when there is one. Hermes (React Native) has none, so
|
|
3717
|
+
* there a local copy runs. It decides the kind of an object by the same
|
|
3718
|
+
* internal slots that `structuredClone` reads (brand checks), not by
|
|
3719
|
+
* `instanceof` or `Symbol.toStringTag`, and gives what the native
|
|
3720
|
+
* `structuredClone` of V8 gives:
|
|
3721
|
+
*
|
|
3722
|
+
* - `undefined`, `null`, strings, booleans, numbers (also `NaN`,
|
|
3723
|
+
* `Infinity` and `-0`) and bigints are returned as they are.
|
|
3724
|
+
* - Arrays and ordinary objects are copied deeply: own enumerable string
|
|
3725
|
+
* keys only, so a class instance, or an object with its own
|
|
3726
|
+
* `Symbol.toStringTag`, becomes a plain object. A sparse array keeps its
|
|
3727
|
+
* holes and its length.
|
|
3728
|
+
* - `Date`, `RegExp`, `Map`, `Set`, boxed primitives, `ArrayBuffer`s (a
|
|
3729
|
+
* resizable one stays resizable), typed arrays (as the base type, never a
|
|
3730
|
+
* subclass), `DataView`s, `Blob`s and `File`s are copied.
|
|
3731
|
+
* - An `Error` becomes an `Error` of its standard type (a custom name or
|
|
3732
|
+
* `AggregateError` becomes `Error`), with its own `message`, its `stack`
|
|
3733
|
+
* and its own `cause`. A `DOMException` stays one where the global exists.
|
|
3734
|
+
* - A `SharedArrayBuffer` is shared, not copied, like `structuredClone`.
|
|
3735
|
+
* - Cycles and shared references are kept: an object reached twice is
|
|
3736
|
+
* copied once.
|
|
3737
|
+
* - Functions, symbols, `Symbol` wrappers, `arguments`, `WeakMap`,
|
|
3738
|
+
* `WeakSet`, `WeakRef`, `Promise`, iterators, generators and the web
|
|
3739
|
+
* platform objects that cannot be cloned (`URL`, `Headers`, streams...)
|
|
3740
|
+
* throw an error named `"DataCloneError"`: a `DOMException` where the
|
|
3741
|
+
* global exists, else an `Error` (Hermes has no `DOMException`).
|
|
3742
|
+
*
|
|
3743
|
+
* Two differences are left. A `Proxy` cannot be told from its target in
|
|
3744
|
+
* JavaScript, so the local copy reads it through its traps, where the
|
|
3745
|
+
* native one throws. And an ordinary object takes a fast path that runs no
|
|
3746
|
+
* brand check (each failed one throws and catches an exception, slow on
|
|
3747
|
+
* Hermes), so a `Map`, `Set`, `Promise` or other object whose prototype
|
|
3748
|
+
* was changed to `Object.prototype` or `null` is copied as a plain object.
|
|
3749
|
+
*
|
|
3750
|
+
* It never installs a global `structuredClone`, and it does not use the
|
|
3751
|
+
* JSON round trip of `structuredClone_` from `@ag-ui/client`, which turns
|
|
3752
|
+
* `undefined` into `{}` and drops or changes values JSON cannot hold.
|
|
3753
|
+
*
|
|
3754
|
+
* @param value - The value to copy.
|
|
3755
|
+
* @returns A copy that shares no object with `value`, except a
|
|
3756
|
+
* `SharedArrayBuffer`.
|
|
3757
|
+
* @throws An error named `"DataCloneError"` for a value that cannot be
|
|
3758
|
+
* cloned.
|
|
3759
|
+
*/
|
|
3760
|
+
function cloneValue(value) {
|
|
3761
|
+
const native = globalThis.structuredClone;
|
|
3762
|
+
if (typeof native === "function") return native(value);
|
|
3763
|
+
return cloneInto(value, /* @__PURE__ */ new Map());
|
|
3764
|
+
}
|
|
3765
|
+
/** A global, or `undefined` when this engine does not have it. */
|
|
3766
|
+
function globalNamed(name) {
|
|
3767
|
+
return globalThis[name];
|
|
3768
|
+
}
|
|
3769
|
+
/** True when `method` accepts `value` as its `this`: a brand check. */
|
|
3770
|
+
function hasBrand(value, method, ...args) {
|
|
3771
|
+
if (typeof method !== "function") return false;
|
|
3772
|
+
try {
|
|
3773
|
+
method.call(value, ...args);
|
|
3774
|
+
return true;
|
|
3775
|
+
} catch (_unused) {
|
|
3776
|
+
return false;
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
/** The getter of `key` on `proto`, for a brand check. */
|
|
3780
|
+
function getterOf(proto, key) {
|
|
3781
|
+
var _Object$getOwnPropert;
|
|
3782
|
+
if (!proto) return void 0;
|
|
3783
|
+
return (_Object$getOwnPropert = Object.getOwnPropertyDescriptor(proto, key)) === null || _Object$getOwnPropert === void 0 ? void 0 : _Object$getOwnPropert.get;
|
|
3784
|
+
}
|
|
3785
|
+
function protoOf(name) {
|
|
3786
|
+
var _globalNamed;
|
|
3787
|
+
return ((_globalNamed = globalNamed(name)) !== null && _globalNamed !== void 0 ? _globalNamed : {}).prototype;
|
|
3788
|
+
}
|
|
3789
|
+
function methodOf(name, key) {
|
|
3790
|
+
const proto = protoOf(name);
|
|
3791
|
+
return proto === null || proto === void 0 ? void 0 : proto[key];
|
|
3792
|
+
}
|
|
3793
|
+
const ERROR_NAMES$1 = new Set([
|
|
3794
|
+
"Error",
|
|
3795
|
+
"EvalError",
|
|
3796
|
+
"RangeError",
|
|
3797
|
+
"ReferenceError",
|
|
3798
|
+
"SyntaxError",
|
|
3799
|
+
"TypeError",
|
|
3800
|
+
"URIError"
|
|
3801
|
+
]);
|
|
3802
|
+
/** Web platform objects that `structuredClone` refuses, where they exist. */
|
|
3803
|
+
const PLATFORM_UNCLONEABLE = [
|
|
3804
|
+
"URL",
|
|
3805
|
+
"URLSearchParams",
|
|
3806
|
+
"Headers",
|
|
3807
|
+
"Request",
|
|
3808
|
+
"Response",
|
|
3809
|
+
"FormData",
|
|
3810
|
+
"ReadableStream",
|
|
3811
|
+
"WritableStream",
|
|
3812
|
+
"TransformStream",
|
|
3813
|
+
"MessagePort"
|
|
3814
|
+
];
|
|
3815
|
+
function* emptyGenerator() {}
|
|
3816
|
+
/** The prototypes of the built-in iterators and generators. */
|
|
3817
|
+
function iteratorPrototypes() {
|
|
3818
|
+
const protos = [];
|
|
3819
|
+
const add = (iterator) => {
|
|
3820
|
+
const proto = iterator && Object.getPrototypeOf(iterator);
|
|
3821
|
+
if (proto) protos.push(proto);
|
|
3822
|
+
};
|
|
3823
|
+
add([][Symbol.iterator]());
|
|
3824
|
+
add((/* @__PURE__ */ new Map())[Symbol.iterator]());
|
|
3825
|
+
add((/* @__PURE__ */ new Set())[Symbol.iterator]());
|
|
3826
|
+
add(""[Symbol.iterator]());
|
|
3827
|
+
protos.push(Object.getPrototypeOf(emptyGenerator.prototype));
|
|
3828
|
+
const matchAllKey = Symbol.matchAll;
|
|
3829
|
+
const matchAll = matchAllKey ? RegExp.prototype[matchAllKey] : void 0;
|
|
3830
|
+
if (typeof matchAll === "function") add(matchAll.call(/a/g, ""));
|
|
3831
|
+
return protos;
|
|
3832
|
+
}
|
|
3833
|
+
let iteratorProtos;
|
|
3834
|
+
function inheritsFrom(value, protos) {
|
|
3835
|
+
for (let proto = Object.getPrototypeOf(value); proto !== null; proto = Object.getPrototypeOf(proto)) if (protos.includes(proto)) return true;
|
|
3836
|
+
return false;
|
|
3837
|
+
}
|
|
3838
|
+
function dataCloneError(what) {
|
|
3839
|
+
const message = `${what} could not be cloned.`;
|
|
3840
|
+
const DOMExceptionClass = globalNamed("DOMException");
|
|
3841
|
+
if (typeof DOMExceptionClass === "function") return new DOMExceptionClass(message, "DataCloneError");
|
|
3842
|
+
const error = new Error(message);
|
|
3843
|
+
error.name = "DataCloneError";
|
|
3844
|
+
return error;
|
|
3845
|
+
}
|
|
3846
|
+
function describe(value) {
|
|
3847
|
+
if (typeof value === "function") return value.name ? `function ${value.name}` : "A function";
|
|
3848
|
+
if (typeof value === "symbol") return String(value);
|
|
3849
|
+
return Object.prototype.toString.call(value);
|
|
3850
|
+
}
|
|
3851
|
+
/** True for an object with the [[ErrorData]] slot. */
|
|
3852
|
+
function isError(value) {
|
|
3853
|
+
const isErrorCheck = Error.isError;
|
|
3854
|
+
if (typeof isErrorCheck === "function") return isErrorCheck.call(Error, value) === true;
|
|
3855
|
+
if (!(Symbol.toStringTag in value)) return Object.prototype.toString.call(value) === "[object Error]";
|
|
3856
|
+
return value instanceof Error;
|
|
3857
|
+
}
|
|
3858
|
+
function isDOMException(value) {
|
|
3859
|
+
return hasBrand(value, getterOf(protoOf("DOMException"), "code"));
|
|
3860
|
+
}
|
|
3861
|
+
/** The name of the base typed-array type of a view, or `undefined`. */
|
|
3862
|
+
function typedArrayName(value) {
|
|
3863
|
+
const getter = getterOf(Object.getPrototypeOf(Uint8Array.prototype), Symbol.toStringTag);
|
|
3864
|
+
if (!getter) return void 0;
|
|
3865
|
+
const name = getter.call(value);
|
|
3866
|
+
return typeof name === "string" ? name : void 0;
|
|
3867
|
+
}
|
|
3868
|
+
function cloneArrayBuffer(value) {
|
|
3869
|
+
const source = value;
|
|
3870
|
+
if (source.resizable === true) {
|
|
3871
|
+
const copy = new ArrayBuffer(source.byteLength, { maxByteLength: source.maxByteLength });
|
|
3872
|
+
new Uint8Array(copy).set(new Uint8Array(source));
|
|
3873
|
+
return copy;
|
|
3874
|
+
}
|
|
3875
|
+
return ArrayBuffer.prototype.slice.call(value, 0);
|
|
3876
|
+
}
|
|
3877
|
+
function cloneError(value, seen) {
|
|
3878
|
+
let copy;
|
|
3879
|
+
const own = (key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
3880
|
+
const messageDescriptor = Object.getOwnPropertyDescriptor(value, "message");
|
|
3881
|
+
const message = messageDescriptor && "value" in messageDescriptor ? `${messageDescriptor.value}` : void 0;
|
|
3882
|
+
if (isDOMException(value)) copy = new (globalNamed("DOMException"))(value.message, value.name);
|
|
3883
|
+
else {
|
|
3884
|
+
var _globalNamed2;
|
|
3885
|
+
const ErrorClass = (_globalNamed2 = globalNamed(ERROR_NAMES$1.has(value.name) ? value.name : "Error")) !== null && _globalNamed2 !== void 0 ? _globalNamed2 : Error;
|
|
3886
|
+
copy = message === void 0 ? new ErrorClass() : new ErrorClass(message);
|
|
3887
|
+
}
|
|
3888
|
+
seen.set(value, copy);
|
|
3889
|
+
if (typeof value.stack === "string") copy.stack = value.stack;
|
|
3890
|
+
if (!isDOMException(value)) {
|
|
3891
|
+
const causeDescriptor = Object.getOwnPropertyDescriptor(value, "cause");
|
|
3892
|
+
if (own("cause") && causeDescriptor && "value" in causeDescriptor) Object.defineProperty(copy, "cause", {
|
|
3893
|
+
value: cloneInto(causeDescriptor.value, seen),
|
|
3894
|
+
writable: true,
|
|
3895
|
+
enumerable: false,
|
|
3896
|
+
configurable: true
|
|
3897
|
+
});
|
|
3898
|
+
}
|
|
3899
|
+
return copy;
|
|
3900
|
+
}
|
|
3901
|
+
function cloneInto(value, seen) {
|
|
3902
|
+
if (typeof value === "function" || typeof value === "symbol") throw dataCloneError(describe(value));
|
|
3903
|
+
if (typeof value !== "object" || value === null) return value;
|
|
3904
|
+
const known = seen.get(value);
|
|
3905
|
+
if (known !== void 0) return known;
|
|
3906
|
+
if (Array.isArray(value)) {
|
|
3907
|
+
const copy = [];
|
|
3908
|
+
copy.length = value.length;
|
|
3909
|
+
seen.set(value, copy);
|
|
3910
|
+
copyKeys(value, copy, seen);
|
|
3911
|
+
return copy;
|
|
3912
|
+
}
|
|
3913
|
+
if (isPlainObject(value)) {
|
|
3914
|
+
const copy = {};
|
|
3915
|
+
seen.set(value, copy);
|
|
3916
|
+
copyKeys(value, copy, seen);
|
|
3917
|
+
return copy;
|
|
3918
|
+
}
|
|
3919
|
+
if (hasBrand(value, Date.prototype.getTime)) {
|
|
3920
|
+
const copy = new Date(Date.prototype.getTime.call(value));
|
|
3921
|
+
seen.set(value, copy);
|
|
3922
|
+
return copy;
|
|
3923
|
+
}
|
|
3924
|
+
if (hasBrand(value, getterOf(RegExp.prototype, "source"))) {
|
|
3925
|
+
const source = getterOf(RegExp.prototype, "source").call(value);
|
|
3926
|
+
const flags = getterOf(RegExp.prototype, "flags").call(value);
|
|
3927
|
+
const copy = new RegExp(source, flags);
|
|
3928
|
+
seen.set(value, copy);
|
|
3929
|
+
return copy;
|
|
3930
|
+
}
|
|
3931
|
+
if (hasBrand(value, Map.prototype.has, void 0)) {
|
|
3932
|
+
const copy = /* @__PURE__ */ new Map();
|
|
3933
|
+
seen.set(value, copy);
|
|
3934
|
+
const entries = [];
|
|
3935
|
+
Map.prototype.forEach.call(value, (entry, key) => {
|
|
3936
|
+
entries.push([key, entry]);
|
|
3937
|
+
});
|
|
3938
|
+
for (const [key, entry] of entries) copy.set(cloneInto(key, seen), cloneInto(entry, seen));
|
|
3939
|
+
return copy;
|
|
3940
|
+
}
|
|
3941
|
+
if (hasBrand(value, Set.prototype.has, void 0)) {
|
|
3942
|
+
const copy = /* @__PURE__ */ new Set();
|
|
3943
|
+
seen.set(value, copy);
|
|
3944
|
+
const entries = [];
|
|
3945
|
+
Set.prototype.forEach.call(value, (entry) => {
|
|
3946
|
+
entries.push(entry);
|
|
3947
|
+
});
|
|
3948
|
+
for (const entry of entries) copy.add(cloneInto(entry, seen));
|
|
3949
|
+
return copy;
|
|
3950
|
+
}
|
|
3951
|
+
if (hasBrand(value, getterOf(ArrayBuffer.prototype, "byteLength"))) {
|
|
3952
|
+
const copy = cloneArrayBuffer(value);
|
|
3953
|
+
seen.set(value, copy);
|
|
3954
|
+
return copy;
|
|
3955
|
+
}
|
|
3956
|
+
if (hasBrand(value, getterOf(protoOf("SharedArrayBuffer"), "byteLength"))) {
|
|
3957
|
+
seen.set(value, value);
|
|
3958
|
+
return value;
|
|
3959
|
+
}
|
|
3960
|
+
if (ArrayBuffer.isView(value)) {
|
|
3961
|
+
const view = value;
|
|
3962
|
+
const buffer = cloneInto(view.buffer, seen);
|
|
3963
|
+
const isDataView = hasBrand(value, getterOf(DataView.prototype, "byteLength"));
|
|
3964
|
+
let copy;
|
|
3965
|
+
if (isDataView) copy = new DataView(buffer, view.byteOffset, view.byteLength);
|
|
3966
|
+
else {
|
|
3967
|
+
const name = typedArrayName(value);
|
|
3968
|
+
const TypedArray = name ? globalNamed(name) : void 0;
|
|
3969
|
+
if (!TypedArray) throw dataCloneError(describe(value));
|
|
3970
|
+
const proto = Object.getPrototypeOf(Uint8Array.prototype);
|
|
3971
|
+
copy = new TypedArray(buffer, getterOf(proto, "byteOffset").call(value), getterOf(proto, "length").call(value));
|
|
3972
|
+
}
|
|
3973
|
+
seen.set(value, copy);
|
|
3974
|
+
return copy;
|
|
3975
|
+
}
|
|
3976
|
+
if (isError(value)) return cloneError(value, seen);
|
|
3977
|
+
for (const [name, Boxed] of [
|
|
3978
|
+
["Boolean", Boolean],
|
|
3979
|
+
["Number", Number],
|
|
3980
|
+
["String", String],
|
|
3981
|
+
["BigInt", globalNamed("BigInt")]
|
|
3982
|
+
]) {
|
|
3983
|
+
const valueOf = methodOf(name, "valueOf");
|
|
3984
|
+
if (Boxed && hasBrand(value, valueOf)) {
|
|
3985
|
+
const copy = Object(valueOf.call(value));
|
|
3986
|
+
seen.set(value, copy);
|
|
3987
|
+
return copy;
|
|
3988
|
+
}
|
|
3989
|
+
}
|
|
3990
|
+
if (hasBrand(value, methodOf("Symbol", "valueOf"))) throw dataCloneError(describe(value));
|
|
3991
|
+
const BlobClass = globalNamed("Blob");
|
|
3992
|
+
if (typeof BlobClass === "function" && value instanceof BlobClass) {
|
|
3993
|
+
const copy = cloneBlob(value);
|
|
3994
|
+
seen.set(value, copy);
|
|
3995
|
+
return copy;
|
|
3996
|
+
}
|
|
3997
|
+
if (isUncloneable(value)) throw dataCloneError(describe(value));
|
|
3998
|
+
const copy = {};
|
|
3999
|
+
seen.set(value, copy);
|
|
4000
|
+
copyKeys(value, copy, seen);
|
|
4001
|
+
return copy;
|
|
4002
|
+
}
|
|
4003
|
+
function cloneBlob(value) {
|
|
4004
|
+
const FileClass = globalNamed("File");
|
|
4005
|
+
if (typeof FileClass === "function" && value instanceof FileClass) {
|
|
4006
|
+
const file = value;
|
|
4007
|
+
return new FileClass([value], file.name, {
|
|
4008
|
+
type: value.type,
|
|
4009
|
+
lastModified: file.lastModified
|
|
4010
|
+
});
|
|
4011
|
+
}
|
|
4012
|
+
return new (globalNamed("Blob"))([value], { type: value.type });
|
|
4013
|
+
}
|
|
4014
|
+
/**
|
|
4015
|
+
* True for an ordinary object of this realm: its prototype is
|
|
4016
|
+
* `Object.prototype` or `null`, it has no `Symbol.toStringTag`, and its
|
|
4017
|
+
* built-in tag is "Object" (so not `arguments`, an `Error`, a `Date`, a
|
|
4018
|
+
* `RegExp` or a boxed primitive, whatever their prototype). Throws nothing.
|
|
4019
|
+
* An object with another slot (a `Map`, a `Set`, a `Promise`...) whose
|
|
4020
|
+
* prototype was changed to one of those passes too; only a brand check,
|
|
4021
|
+
* which throws, could tell, so it is copied as a plain object.
|
|
4022
|
+
*/
|
|
4023
|
+
function isPlainObject(value) {
|
|
4024
|
+
const proto = Object.getPrototypeOf(value);
|
|
4025
|
+
if (proto !== Object.prototype && proto !== null) return false;
|
|
4026
|
+
if (Symbol.toStringTag in value) return false;
|
|
4027
|
+
if (ArrayBuffer.isView(value)) return false;
|
|
4028
|
+
return Object.prototype.toString.call(value) === "[object Object]";
|
|
4029
|
+
}
|
|
4030
|
+
/** The globals of PLATFORM_UNCLONEABLE and their prototypes, when last read. */
|
|
4031
|
+
let platformCache;
|
|
4032
|
+
/**
|
|
4033
|
+
* The prototypes of the PLATFORM_UNCLONEABLE globals that exist. Kept
|
|
4034
|
+
* between calls, and built again only when one of the globals changed (a
|
|
4035
|
+
* polyfill installed late).
|
|
4036
|
+
*/
|
|
4037
|
+
function platformPrototypes() {
|
|
4038
|
+
const globals = globalThis;
|
|
4039
|
+
const cached = platformCache;
|
|
4040
|
+
if (cached && PLATFORM_UNCLONEABLE.every((name, index) => globals[name] === cached.classes[index])) return cached.protos;
|
|
4041
|
+
const classes = PLATFORM_UNCLONEABLE.map((name) => globals[name]);
|
|
4042
|
+
const protos = PLATFORM_UNCLONEABLE.map(protoOf).filter((proto) => proto !== void 0);
|
|
4043
|
+
platformCache = {
|
|
4044
|
+
classes,
|
|
4045
|
+
protos
|
|
4046
|
+
};
|
|
4047
|
+
return protos;
|
|
4048
|
+
}
|
|
4049
|
+
/** An object that structuredClone refuses, though it has no data slot. */
|
|
4050
|
+
function isUncloneable(value) {
|
|
4051
|
+
if (!(Symbol.toStringTag in value) && Object.prototype.toString.call(value) === "[object Arguments]") return true;
|
|
4052
|
+
if (hasBrand(value, methodOf("WeakMap", "has"), {}) || hasBrand(value, methodOf("WeakSet", "has"), {}) || hasBrand(value, methodOf("WeakRef", "deref")) || hasBrand(value, methodOf("FinalizationRegistry", "unregister"), {})) return true;
|
|
4053
|
+
const PromiseClass = globalNamed("Promise");
|
|
4054
|
+
if (PromiseClass && value instanceof PromiseClass) return true;
|
|
4055
|
+
if (!iteratorProtos) iteratorProtos = iteratorPrototypes();
|
|
4056
|
+
if (inheritsFrom(value, iteratorProtos)) return true;
|
|
4057
|
+
return inheritsFrom(value, platformPrototypes());
|
|
4058
|
+
}
|
|
4059
|
+
/** Copies the own enumerable string keys, as structuredClone does. */
|
|
4060
|
+
function copyKeys(source, target, seen) {
|
|
4061
|
+
for (const key of Object.keys(source)) assign(target, key, cloneInto(source[key], seen));
|
|
4062
|
+
}
|
|
4063
|
+
/**
|
|
4064
|
+
* Sets an own property. A plain assignment of "__proto__" would change the
|
|
4065
|
+
* prototype of the copy instead (JSON.parse makes "__proto__" an own key).
|
|
4066
|
+
*/
|
|
4067
|
+
function assign(target, key, value) {
|
|
4068
|
+
if (key === "__proto__") Object.defineProperty(target, key, {
|
|
4069
|
+
value,
|
|
4070
|
+
enumerable: true,
|
|
4071
|
+
configurable: true,
|
|
4072
|
+
writable: true
|
|
4073
|
+
});
|
|
4074
|
+
else target[key] = value;
|
|
4075
|
+
}
|
|
4076
|
+
|
|
4077
|
+
//#endregion
|
|
4078
|
+
//#region src/generative-ui/compact-schema.ts
|
|
4079
|
+
/** Objects nested deeper than this show as `object`. */
|
|
4080
|
+
const MAX_OBJECT_DEPTH = 2;
|
|
4081
|
+
/** A prop must appear verbatim in at least this many components to be hoisted. */
|
|
4082
|
+
const COMMON_PROP_MIN_COMPONENTS = 8;
|
|
4083
|
+
function isRecord$1(value) {
|
|
4084
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4085
|
+
}
|
|
4086
|
+
/** A JSON Schema of a list of schemas (`anyOf`, `oneOf`), else an empty list. */
|
|
4087
|
+
function schemaList(value) {
|
|
4088
|
+
return Array.isArray(value) ? value.filter(isRecord$1) : [];
|
|
4089
|
+
}
|
|
4090
|
+
/**
|
|
4091
|
+
* Puts a top-level union in parentheses, so that `[]` applies to all of
|
|
4092
|
+
* it. A union inside braces needs none.
|
|
4093
|
+
*/
|
|
4094
|
+
function asArrayItem(type) {
|
|
4095
|
+
let outside = type;
|
|
4096
|
+
for (let inner = outside.replace(/\{[^{}]*\}/g, ""); inner !== outside;) {
|
|
4097
|
+
outside = inner;
|
|
4098
|
+
inner = outside.replace(/\{[^{}]*\}/g, "");
|
|
4099
|
+
}
|
|
4100
|
+
return outside.includes(" | ") ? `(${type})[]` : `${type}[]`;
|
|
4101
|
+
}
|
|
4102
|
+
/**
|
|
4103
|
+
* A JSON Schema as a short TypeScript-like type, for example
|
|
4104
|
+
* `{ label: string; size?: "sm" | "md" }`.
|
|
4105
|
+
*/
|
|
4106
|
+
function compactType(schema, depth) {
|
|
4107
|
+
const ref = childRefKind(schema);
|
|
4108
|
+
if (ref === "single") return "componentId";
|
|
4109
|
+
if (ref === "multiple") return "componentId[] | { componentId: string; path: string }";
|
|
4110
|
+
if ("const" in schema) return JSON.stringify(schema.const);
|
|
4111
|
+
if (Array.isArray(schema.enum)) return schema.enum.map((value) => JSON.stringify(value)).join(" | ");
|
|
4112
|
+
const variants = [...schemaList(schema.anyOf), ...schemaList(schema.oneOf)];
|
|
4113
|
+
if (variants.length > 0) return variants.map((variant) => compactType(variant, depth)).join(" | ");
|
|
4114
|
+
return (Array.isArray(schema.type) ? schema.type : [schema.type]).map((type) => {
|
|
4115
|
+
switch (type) {
|
|
4116
|
+
case "string":
|
|
4117
|
+
case "boolean":
|
|
4118
|
+
case "null": return type;
|
|
4119
|
+
case "number":
|
|
4120
|
+
case "integer": return "number";
|
|
4121
|
+
case "array": return isRecord$1(schema.items) ? asArrayItem(compactType(schema.items, depth)) : "unknown[]";
|
|
4122
|
+
case "object": return compactObject(schema, depth);
|
|
4123
|
+
default: return "unknown";
|
|
4124
|
+
}
|
|
4125
|
+
}).join(" | ");
|
|
4126
|
+
}
|
|
4127
|
+
/** An object schema as `{ key: type; other?: type }`. */
|
|
4128
|
+
function compactObject(schema, depth) {
|
|
4129
|
+
const properties = isRecord$1(schema.properties) ? schema.properties : {};
|
|
4130
|
+
const entries = Object.entries(properties);
|
|
4131
|
+
if (entries.length === 0) return isRecord$1(schema.additionalProperties) ? `Record<string, ${compactType(schema.additionalProperties, depth + 1)}>` : "object";
|
|
4132
|
+
if (depth >= MAX_OBJECT_DEPTH) return "object";
|
|
4133
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
4134
|
+
return `{ ${entries.map(([key, value]) => {
|
|
4135
|
+
const type = isRecord$1(value) ? compactType(value, depth + 1) : "unknown";
|
|
4136
|
+
return `${key}${required.includes(key) ? "" : "?"}: ${type}`;
|
|
4137
|
+
}).join("; ")} }`;
|
|
4138
|
+
}
|
|
4139
|
+
/** A schema as its type, with its description after `//`. */
|
|
4140
|
+
function describedType(schema, depth) {
|
|
4141
|
+
const type = compactType(schema, depth);
|
|
4142
|
+
return typeof schema.description === "string" ? `${type} // ${schema.description}` : type;
|
|
4143
|
+
}
|
|
4144
|
+
/**
|
|
4145
|
+
* The props of a component: `{ "label": "string", "size?": "..." }`. With
|
|
4146
|
+
* `descriptions`, each type carries its description after `//`.
|
|
4147
|
+
*/
|
|
4148
|
+
function compactProps(schema, descriptions = true) {
|
|
4149
|
+
const properties = isRecord$1(schema.properties) ? schema.properties : {};
|
|
4150
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
4151
|
+
const props = {};
|
|
4152
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
4153
|
+
if (!isRecord$1(value)) continue;
|
|
4154
|
+
const name = required.includes(key) ? key : `${key}?`;
|
|
4155
|
+
props[name] = descriptions ? describedType(value, 1) : compactType(value, 1);
|
|
4156
|
+
}
|
|
4157
|
+
return props;
|
|
4158
|
+
}
|
|
4159
|
+
/**
|
|
4160
|
+
* The prop set worth listing once. Candidates are (key, type) pairs that at
|
|
4161
|
+
* least {@link COMMON_PROP_MIN_COMPONENTS} components carry verbatim. The
|
|
4162
|
+
* candidate subset of each component is a possible common set, scored by
|
|
4163
|
+
* the characters it saves (set size times the components that contain all
|
|
4164
|
+
* of it). `undefined` when no set is shared by enough components.
|
|
4165
|
+
*/
|
|
4166
|
+
function findCommonProps(propsList) {
|
|
4167
|
+
const pairKey = (key, type) => `${key}\u0000${type}`;
|
|
4168
|
+
const counts = /* @__PURE__ */ new Map();
|
|
4169
|
+
for (const props of propsList) for (const [key, type] of Object.entries(props)) {
|
|
4170
|
+
var _counts$get;
|
|
4171
|
+
const id = pairKey(key, type);
|
|
4172
|
+
counts.set(id, ((_counts$get = counts.get(id)) !== null && _counts$get !== void 0 ? _counts$get : 0) + 1);
|
|
4173
|
+
}
|
|
4174
|
+
let best;
|
|
4175
|
+
let bestScore = 0;
|
|
4176
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4177
|
+
for (const props of propsList) {
|
|
4178
|
+
const subset = Object.entries(props).filter(([key, type]) => {
|
|
4179
|
+
var _counts$get2;
|
|
4180
|
+
return ((_counts$get2 = counts.get(pairKey(key, type))) !== null && _counts$get2 !== void 0 ? _counts$get2 : 0) >= COMMON_PROP_MIN_COMPONENTS;
|
|
4181
|
+
});
|
|
4182
|
+
if (subset.length < 2) continue;
|
|
4183
|
+
const signature = subset.map(([key, type]) => pairKey(key, type)).join("\n");
|
|
4184
|
+
if (seen.has(signature)) continue;
|
|
4185
|
+
seen.add(signature);
|
|
4186
|
+
const members = propsList.filter((other) => subset.every(([key, type]) => other[key] === type)).length;
|
|
4187
|
+
if (members < COMMON_PROP_MIN_COMPONENTS) continue;
|
|
4188
|
+
const score = subset.reduce((total, [key, type]) => total + key.length + type.length, 0) * (members - 1);
|
|
4189
|
+
if (score > bestScore) {
|
|
4190
|
+
bestScore = score;
|
|
4191
|
+
best = Object.fromEntries(subset);
|
|
4192
|
+
}
|
|
4193
|
+
}
|
|
4194
|
+
return best;
|
|
4195
|
+
}
|
|
4196
|
+
/**
|
|
4197
|
+
* The component schema of the markdown transport, from the per-run
|
|
4198
|
+
* manifest. It is smaller than the manifest: each prop is one short type,
|
|
4199
|
+
* and the props that many components share verbatim (the layout props of
|
|
4200
|
+
* the containers) are listed once in `commonProps`; a component that takes
|
|
4201
|
+
* them is flagged `includesCommonProps`.
|
|
4202
|
+
* It has the catalog id, the targets with their descriptions and their
|
|
4203
|
+
* component lists, the functions with their parameters, the components
|
|
4204
|
+
* with their props, events and slots, and the surfaces of the thread. A surface lists the
|
|
4205
|
+
* values that the user set and the operations that the client dropped.
|
|
4206
|
+
*
|
|
4207
|
+
* @param manifest - The manifest from `buildGenerativeUIManifest`.
|
|
4208
|
+
* @param options - `propDescriptions` (default true) writes each prop's
|
|
4209
|
+
* description; `commonProps` (default true) lists shared props once.
|
|
4210
|
+
* @returns A JSON-ready object.
|
|
4211
|
+
*
|
|
4212
|
+
* @example
|
|
4213
|
+
* ```ts
|
|
4214
|
+
* const value = JSON.stringify(
|
|
4215
|
+
* buildCompactGenerativeUISchema(buildGenerativeUIManifest(runtime, threadId)),
|
|
4216
|
+
* );
|
|
4217
|
+
* ```
|
|
4218
|
+
*/
|
|
4219
|
+
function buildCompactGenerativeUISchema(manifest, options = {}) {
|
|
4220
|
+
const { propDescriptions = true, commonProps = true } = options;
|
|
4221
|
+
const components = {};
|
|
4222
|
+
for (const [name, component] of Object.entries(manifest.components)) {
|
|
4223
|
+
var _component$events;
|
|
4224
|
+
const events = Object.entries((_component$events = component.events) !== null && _component$events !== void 0 ? _component$events : {}).map(([event, definition]) => {
|
|
4225
|
+
var _definition$descripti;
|
|
4226
|
+
return [event, (_definition$descripti = definition.description) !== null && _definition$descripti !== void 0 ? _definition$descripti : compactType(definition.parameters, 0)];
|
|
4227
|
+
});
|
|
4228
|
+
components[name] = {
|
|
4229
|
+
...component.description ? { description: component.description } : {},
|
|
4230
|
+
props: compactProps(component.props, propDescriptions),
|
|
4231
|
+
...events.length > 0 ? { events: Object.fromEntries(events) } : {},
|
|
4232
|
+
...component.slots ? { slots: component.slots } : {}
|
|
4233
|
+
};
|
|
4234
|
+
}
|
|
4235
|
+
const common = commonProps ? findCommonProps(Object.values(components).map((component) => component.props)) : void 0;
|
|
4236
|
+
if (common) {
|
|
4237
|
+
const commonKeys = Object.keys(common);
|
|
4238
|
+
for (const component of Object.values(components)) {
|
|
4239
|
+
if (!commonKeys.every((key) => component.props[key] === common[key])) continue;
|
|
4240
|
+
component.includesCommonProps = true;
|
|
4241
|
+
component.props = Object.fromEntries(Object.entries(component.props).filter(([key]) => !(key in common)));
|
|
4242
|
+
}
|
|
4243
|
+
}
|
|
4244
|
+
const functions = Object.fromEntries(Object.entries(manifest.functions).map(([name, fn]) => {
|
|
4245
|
+
const signature = fn.parameters.description;
|
|
4246
|
+
const hasSignature = typeof signature === "string" && signature.startsWith("{") && Object.keys(fn.parameters).length === 2;
|
|
4247
|
+
const callers = functionCallers(fn);
|
|
4248
|
+
return [name, {
|
|
4249
|
+
...fn.description ? { description: fn.description } : {},
|
|
4250
|
+
parameters: hasSignature ? signature : compactType(fn.parameters, 0),
|
|
4251
|
+
...callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS ? { callers: callers.renderer ? "UI or agent" : "agent only" } : {}
|
|
4252
|
+
}];
|
|
4253
|
+
}));
|
|
4254
|
+
return {
|
|
4255
|
+
catalogId: manifest.catalogId,
|
|
4256
|
+
targets: manifest.targets,
|
|
4257
|
+
functions,
|
|
4258
|
+
...common ? { commonProps: common } : {},
|
|
4259
|
+
components,
|
|
4260
|
+
surfaces: manifest.surfaces
|
|
4261
|
+
};
|
|
4262
|
+
}
|
|
4263
|
+
|
|
4264
|
+
//#endregion
|
|
4265
|
+
//#region src/generative-ui/schema-render.ts
|
|
4266
|
+
/** An own key (shared compiles to ES2017, which has no Object.hasOwn). */
|
|
4267
|
+
const hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
4268
|
+
function isRecord(value) {
|
|
4269
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4270
|
+
}
|
|
4271
|
+
/** The props schema without the description of each prop. */
|
|
4272
|
+
function withoutPropDescriptions(schema) {
|
|
4273
|
+
if (!isRecord(schema.properties)) return schema;
|
|
4274
|
+
return {
|
|
4275
|
+
...schema,
|
|
4276
|
+
properties: Object.fromEntries(Object.entries(schema.properties).map(([key, value]) => {
|
|
4277
|
+
if (!isRecord(value)) return [key, value];
|
|
4278
|
+
const { description: _description, ...rest } = value;
|
|
4279
|
+
return [key, rest];
|
|
4280
|
+
}))
|
|
4281
|
+
};
|
|
4282
|
+
}
|
|
4283
|
+
/** The short signature of a function: its built-in signature, or its schema made short. */
|
|
4284
|
+
function functionSignature(fn) {
|
|
4285
|
+
const signature = fn.parameters.description;
|
|
4286
|
+
return typeof signature === "string" && signature.startsWith("{") && Object.keys(fn.parameters).length === 2 ? signature : compactType(fn.parameters, 0);
|
|
4287
|
+
}
|
|
4288
|
+
/**
|
|
4289
|
+
* A function name with its parameters: `pick{ id: string }`, `clearCart{}`
|
|
4290
|
+
* for no arguments, `setVolume(number)` for a parameter that is not an object.
|
|
4291
|
+
*/
|
|
4292
|
+
function nameWithParameters(name, parameters) {
|
|
4293
|
+
if (parameters.startsWith("{")) return `${name}${parameters}`;
|
|
4294
|
+
if (parameters === "object") return `${name}{}`;
|
|
4295
|
+
return `${name}(${parameters})`;
|
|
4296
|
+
}
|
|
4297
|
+
/**
|
|
4298
|
+
* One component as a TypeScript-like signature line, with its events and
|
|
4299
|
+
* slots on the lines below:
|
|
4300
|
+
* `- Text(text?: string // The text): Shows text`.
|
|
4301
|
+
*/
|
|
4302
|
+
function signatureLines(name, component, settings) {
|
|
4303
|
+
var _component$events, _component$slots;
|
|
4304
|
+
const lines = [`- ${name}(${Object.entries(compactProps(component.props, settings.propDescriptions)).map(([key, type]) => `${key}: ${type}`).join(", ")})${component.description ? `: ${oneLine(component.description)}` : ""}`];
|
|
4305
|
+
const events = Object.entries((_component$events = component.events) !== null && _component$events !== void 0 ? _component$events : {}).map(([event, definition]) => `${event}(${definition.description ? oneLine(definition.description) : compactType(definition.parameters, 0)})`);
|
|
4306
|
+
if (events.length > 0) lines.push(` events: ${events.join(", ")}`);
|
|
4307
|
+
const slots = Object.entries((_component$slots = component.slots) !== null && _component$slots !== void 0 ? _component$slots : {}).map(([slot, kind]) => `${slot} (${kind})`);
|
|
4308
|
+
if (slots.length > 0) lines.push(` slots: ${slots.join(", ")}`);
|
|
4309
|
+
return lines;
|
|
4310
|
+
}
|
|
4311
|
+
/** The whole schema as signature text: targets, functions, components, surfaces. */
|
|
4312
|
+
function signatureSchema(manifest, settings) {
|
|
4313
|
+
const targets = manifest.targets.map((t) => {
|
|
4314
|
+
const limit = t.components ? `; only ${t.components.join(", ")}` : "";
|
|
4315
|
+
return `- ${t.id} (${t.kind}${limit})${t.description ? `: ${oneLine(t.description)}` : ""}`;
|
|
4316
|
+
});
|
|
4317
|
+
const functions = Object.entries(manifest.functions).map(([name, fn]) => {
|
|
4318
|
+
const callers = functionCallers(fn);
|
|
4319
|
+
const who = callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS ? callers.renderer ? " (UI or agent)" : " (agent only)" : "";
|
|
4320
|
+
return `- ${nameWithParameters(name, functionSignature(fn))}${who}${fn.description ? `: ${oneLine(fn.description)}` : ""}`;
|
|
4321
|
+
});
|
|
4322
|
+
const components = Object.entries(manifest.components).flatMap(([name, component]) => signatureLines(name, component, settings));
|
|
4323
|
+
const surfaces = Object.entries(manifest.surfaces).map(([id, s]) => {
|
|
4324
|
+
var _s$rejected;
|
|
4325
|
+
return `- ${id} (target ${s.target})${s.status ? ` status: ${s.status}` : ""}${s.dataModel ? ` user values: ${JSON.stringify(s.dataModel)}` : ""}${((_s$rejected = s.rejected) !== null && _s$rejected !== void 0 ? _s$rejected : []).map((r) => ` rejected: ${r}`).join("")}`;
|
|
4326
|
+
});
|
|
4327
|
+
return [
|
|
4328
|
+
`Catalog: ${manifest.catalogId}`,
|
|
4329
|
+
`Targets:\n${targets.join("\n") || "- none"}`,
|
|
4330
|
+
`Functions:\n${functions.join("\n") || "- none"}`,
|
|
4331
|
+
`Components:\n${components.join("\n") || "- none"}`,
|
|
4332
|
+
`Surfaces:\n${surfaces.join("\n") || "- none"}`
|
|
4333
|
+
].join("\n\n");
|
|
4334
|
+
}
|
|
4335
|
+
/** A description on one line, so its lines cannot read as new entries. */
|
|
4336
|
+
function oneLine(text) {
|
|
4337
|
+
return text.replace(/\s*\n\s*/g, " ");
|
|
4338
|
+
}
|
|
4339
|
+
/** Values that would read as a type or a number once their quotes are gone. */
|
|
4340
|
+
const AMBIGUOUS_VALUE = /^(?:string|number|integer|boolean|true|false|null|object|array|unknown|any|-?\d[\d.]*)$/;
|
|
4341
|
+
/**
|
|
4342
|
+
* A compact type with bare enum values and tight unions:
|
|
4343
|
+
* `"sm" | "md" | "lg"` becomes `sm|md|lg`. A union keeps its quotes when it
|
|
4344
|
+
* also holds a type (`"sm" | number`) or a value that reads as a type or a
|
|
4345
|
+
* number (`"number" | "currency"`, `"1" | "2"`), and so do values that are
|
|
4346
|
+
* not plain words.
|
|
4347
|
+
*/
|
|
4348
|
+
function bareType(type) {
|
|
4349
|
+
return type.replace(/"[A-Za-z0-9_#%.-]+"(?: \| "[A-Za-z0-9_#%.-]+")*(?! \|)/g, (union, offset, whole) => {
|
|
4350
|
+
if (whole.slice(offset - 2, offset) === "| ") return union;
|
|
4351
|
+
const values = union.split(" | ").map((v) => v.slice(1, -1));
|
|
4352
|
+
if (values.some((v) => AMBIGUOUS_VALUE.test(v))) return union;
|
|
4353
|
+
return values.join("|");
|
|
4354
|
+
}).replace(/ \| /g, "|");
|
|
4355
|
+
}
|
|
4356
|
+
/** A compact prop (`type // description`) as `name: type - description`. */
|
|
4357
|
+
function propLine(key, value) {
|
|
4358
|
+
const name = key.endsWith("?") ? key.slice(0, -1) : `${key}*`;
|
|
4359
|
+
const cut = value.indexOf(" // ");
|
|
4360
|
+
const type = bareType(cut < 0 ? value : value.slice(0, cut));
|
|
4361
|
+
const text = cut < 0 ? "" : value.slice(cut + 4).trim();
|
|
4362
|
+
return ` ${name}: ${type}${text ? ` - ${oneLine(text)}` : ""}`;
|
|
4363
|
+
}
|
|
4364
|
+
/**
|
|
4365
|
+
* The whole schema as plain lines: a header line per component and one
|
|
4366
|
+
* indented line per prop: events are `action` props and slots `componentId`
|
|
4367
|
+
* or `childList` props. Props are optional unless marked `*`, enum values
|
|
4368
|
+
* are bare, and the common props are listed once. It carries the same names, types and descriptions as
|
|
4369
|
+
* `compact`, in fewer tokens.
|
|
4370
|
+
*/
|
|
4371
|
+
function linesSchema(manifest, settings) {
|
|
4372
|
+
const compact = buildCompactGenerativeUISchema(manifest, {
|
|
4373
|
+
propDescriptions: settings.propDescriptions,
|
|
4374
|
+
commonProps: settings.commonProps
|
|
4375
|
+
});
|
|
4376
|
+
const targets = compact.targets.map((t) => {
|
|
4377
|
+
const limit = t.components ? `, only ${t.components.join(", ")}` : "";
|
|
4378
|
+
return `${t.id} (${t.kind}${limit})${t.description ? `: ${oneLine(t.description)}` : ""}`;
|
|
4379
|
+
}).join("; ");
|
|
4380
|
+
const functions = Object.entries(compact.functions).map(([name, fn]) => `${nameWithParameters(name, fn.parameters)}${"callers" in fn ? ` (${fn.callers})` : ""}${fn.description ? `: ${oneLine(fn.description)}` : ""}`);
|
|
4381
|
+
const common = compact.commonProps ? Object.entries(compact.commonProps).map(([k, v]) => propLine(k, v)) : [];
|
|
4382
|
+
const components = Object.entries(compact.components).map(([name, c]) => {
|
|
4383
|
+
var _c$events;
|
|
4384
|
+
return {
|
|
4385
|
+
name,
|
|
4386
|
+
c,
|
|
4387
|
+
own: [...Object.entries(c.props).map(([k, v]) => propLine(k, v)), ...Object.entries((_c$events = c.events) !== null && _c$events !== void 0 ? _c$events : {}).map(([e, d]) => ` ${e}: action - ${oneLine(d)}`)]
|
|
4388
|
+
};
|
|
4389
|
+
}).flatMap(({ name, c, own }) => {
|
|
4390
|
+
var _c$slots;
|
|
4391
|
+
const lines = [`${name}${c.includesCommonProps ? " +common" : ""}${c.description ? `: ${oneLine(c.description)}` : ""}`, ...own];
|
|
4392
|
+
for (const [slot, kind] of Object.entries((_c$slots = c.slots) !== null && _c$slots !== void 0 ? _c$slots : {})) lines.push(` ${slot}: ${kind === "single" ? "componentId" : "childList"}`);
|
|
4393
|
+
return lines;
|
|
4394
|
+
});
|
|
4395
|
+
const surfaces = Object.keys(compact.surfaces).length ? JSON.stringify(compact.surfaces) : "none";
|
|
4396
|
+
return [
|
|
4397
|
+
`Catalog ${compact.catalogId}. Targets: ${targets || "none"}`,
|
|
4398
|
+
"Props are optional unless marked *. a|b|c is one of those strings, quoted when one reads as a type or a number. A component marked +common also takes every common prop. A prop of type action is an event prop: give it {\"event\":{...}} or {\"functionCall\":{...}}. A componentId prop takes one component id; a childList prop takes a list of ids or a template.",
|
|
4399
|
+
`Functions:\n${functions.join("\n")}`,
|
|
4400
|
+
...common.length ? [`Common props:\n${common.join("\n")}`] : [],
|
|
4401
|
+
`Components:\n${components.join("\n")}`,
|
|
4402
|
+
`Surfaces: ${surfaces}`
|
|
4403
|
+
].join("\n\n");
|
|
4404
|
+
}
|
|
4405
|
+
/**
|
|
4406
|
+
* The component schema of the markdown transport, as the text of its
|
|
4407
|
+
* context entry, in the notation of `settings`. `compact` is the schema that
|
|
4408
|
+
* ships (`buildCompactGenerativeUISchema`), `json-schema` the manifest parts
|
|
4409
|
+
* as JSON, `ts-signature` one line per component, `lines` one line per
|
|
4410
|
+
* prop with bare enums (the fewest tokens).
|
|
4411
|
+
*
|
|
4412
|
+
* @example
|
|
4413
|
+
* ```ts
|
|
4414
|
+
* const value = renderGenerativeUISchema(manifest, spec.schema.markdown);
|
|
4415
|
+
* ```
|
|
4416
|
+
*/
|
|
4417
|
+
function renderGenerativeUISchema(manifest, settings) {
|
|
4418
|
+
switch (settings.notation) {
|
|
4419
|
+
case "compact": return JSON.stringify(buildCompactGenerativeUISchema(manifest, {
|
|
4420
|
+
propDescriptions: settings.propDescriptions,
|
|
4421
|
+
commonProps: settings.commonProps
|
|
4422
|
+
}));
|
|
4423
|
+
case "json-schema": {
|
|
4424
|
+
const components = Object.fromEntries(Object.entries(manifest.components).map(([name, c]) => [name, settings.propDescriptions ? c : {
|
|
4425
|
+
...c,
|
|
4426
|
+
props: withoutPropDescriptions(c.props)
|
|
4427
|
+
}]));
|
|
4428
|
+
return JSON.stringify({
|
|
4429
|
+
catalogId: manifest.catalogId,
|
|
4430
|
+
targets: manifest.targets,
|
|
4431
|
+
functions: manifest.functions,
|
|
4432
|
+
components,
|
|
4433
|
+
surfaces: manifest.surfaces
|
|
4434
|
+
});
|
|
4435
|
+
}
|
|
4436
|
+
case "ts-signature": return signatureSchema(manifest, settings);
|
|
4437
|
+
case "lines": return linesSchema(manifest, settings);
|
|
4438
|
+
}
|
|
4439
|
+
}
|
|
4440
|
+
/**
|
|
4441
|
+
* The component list of the tool guide, one entry per component, in the
|
|
4442
|
+
* notation of `settings`. `json-schema` is the list that ships.
|
|
4443
|
+
*/
|
|
4444
|
+
function renderGenerativeUIComponentList(components, settings) {
|
|
4445
|
+
return Object.entries(components).map(([name, c]) => {
|
|
4446
|
+
if (settings.notation === "ts-signature" || settings.notation === "lines") return signatureLines(name, c, settings).join("\n");
|
|
4447
|
+
const props = settings.notation === "compact" ? compactProps(c.props, settings.propDescriptions) : settings.propDescriptions ? c.props : withoutPropDescriptions(c.props);
|
|
4448
|
+
const lines = [`- **${name}**${c.description ? `: ${oneLine(c.description)}` : ""}`, ` props: ${JSON.stringify(props)}`];
|
|
4449
|
+
if (c.events) lines.push(` event props: ${JSON.stringify(c.events)}`);
|
|
4450
|
+
if (c.slots) lines.push(` slot props (component ids): ${JSON.stringify(c.slots)}`);
|
|
4451
|
+
return lines.join("\n");
|
|
4452
|
+
}).join("\n");
|
|
4453
|
+
}
|
|
4454
|
+
/**
|
|
4455
|
+
* The manifest with replaced descriptions: `"Name"` replaces the
|
|
4456
|
+
* description of a component, `"Name.prop"` the description of one of its
|
|
4457
|
+
* props. Keys that name no component or prop are left out of the result
|
|
4458
|
+
* and listed in `unknown`. The manifest is not changed.
|
|
4459
|
+
*/
|
|
4460
|
+
function applyDescriptionOverrides(manifest, overrides) {
|
|
4461
|
+
const components = cloneValue(manifest.components);
|
|
4462
|
+
const unknown = [];
|
|
4463
|
+
for (const [key, description] of Object.entries(overrides)) {
|
|
4464
|
+
const [name, prop, ...rest] = key.split(".");
|
|
4465
|
+
const component = name !== void 0 && hasOwn(components, name) ? components[name] : void 0;
|
|
4466
|
+
if (!component || rest.length > 0) {
|
|
4467
|
+
unknown.push(key);
|
|
4468
|
+
continue;
|
|
4469
|
+
}
|
|
4470
|
+
if (prop === void 0) {
|
|
4471
|
+
component.description = description;
|
|
4472
|
+
continue;
|
|
4473
|
+
}
|
|
4474
|
+
const properties = component.props.properties;
|
|
4475
|
+
const property = isRecord(properties) && hasOwn(properties, prop) ? properties[prop] : void 0;
|
|
4476
|
+
if (!isRecord(property)) {
|
|
4477
|
+
unknown.push(key);
|
|
4478
|
+
continue;
|
|
4479
|
+
}
|
|
4480
|
+
property.description = description;
|
|
4481
|
+
}
|
|
4482
|
+
return {
|
|
4483
|
+
manifest: {
|
|
4484
|
+
...manifest,
|
|
4485
|
+
components
|
|
4486
|
+
},
|
|
4487
|
+
unknown
|
|
4488
|
+
};
|
|
4489
|
+
}
|
|
4490
|
+
/**
|
|
4491
|
+
* The components and props of `manifest` whose names do not appear in
|
|
4492
|
+
* `rendered`. A schema notation that leaves one out would hide part of the
|
|
4493
|
+
* catalog from the model.
|
|
4494
|
+
*/
|
|
4495
|
+
function schemaCoverage(manifest, rendered) {
|
|
4496
|
+
const missing = [];
|
|
4497
|
+
for (const [name, component] of Object.entries(manifest.components)) {
|
|
4498
|
+
if (!rendered.includes(name)) missing.push(name);
|
|
4499
|
+
const properties = isRecord(component.props.properties) ? component.props.properties : {};
|
|
4500
|
+
for (const prop of Object.keys(properties)) if (!rendered.includes(prop)) missing.push(`${name}.${prop}`);
|
|
4501
|
+
}
|
|
4502
|
+
return { missing };
|
|
4503
|
+
}
|
|
4504
|
+
|
|
3702
4505
|
//#endregion
|
|
3703
4506
|
//#region src/generative-ui/prompt.ts
|
|
3704
4507
|
const GENERATIVE_UI_CONTEXT_DESCRIPTION = "Generative UI guide: available components, functions, targets, and how to call render_ui.";
|
|
@@ -3713,19 +4516,15 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3713
4516
|
* the `render_ui` rules, the targets, components, functions, and surfaces of
|
|
3714
4517
|
* the manifest. It is in shared so that the inspector shows the same text.
|
|
3715
4518
|
*/
|
|
3716
|
-
function buildGenerativeUIPrompt(manifest) {
|
|
4519
|
+
function buildGenerativeUIPrompt(manifest, spec = defaultGenerativeUIPromptSpec()) {
|
|
4520
|
+
var _spec$tool$operations;
|
|
3717
4521
|
const targets = manifest.targets.map((t) => {
|
|
3718
4522
|
const place = t.kind === "chat" ? "inside the chat transcript" : "a named area of the app";
|
|
3719
4523
|
const limit = t.components ? `; only ${t.components.join(", ") || "no components"}` : "";
|
|
3720
4524
|
const description = t.description ? `: ${t.description}` : "";
|
|
3721
4525
|
return `- "${t.id}" (${place}${limit})${description}`;
|
|
3722
4526
|
}).join("\n");
|
|
3723
|
-
const components =
|
|
3724
|
-
const lines = [`- **${name}**${c.description ? `: ${c.description}` : ""}`, ` props: ${JSON.stringify(c.props)}`];
|
|
3725
|
-
if (c.events) lines.push(` event props: ${JSON.stringify(c.events)}`);
|
|
3726
|
-
if (c.slots) lines.push(` slot props (component ids): ${JSON.stringify(c.slots)}`);
|
|
3727
|
-
return lines.join("\n");
|
|
3728
|
-
}).join("\n");
|
|
4527
|
+
const components = renderGenerativeUIComponentList(manifest.components, spec.schema.tool);
|
|
3729
4528
|
const functions = Object.entries(manifest.functions).map(([name, f]) => {
|
|
3730
4529
|
const signature = f.parameters.description;
|
|
3731
4530
|
const args = typeof signature === "string" && signature.startsWith("{") && Object.keys(f.parameters).length === 2 ? signature : JSON.stringify(f.parameters);
|
|
@@ -3744,38 +4543,15 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
3744
4543
|
var _s$rejected$length, _s$rejected2;
|
|
3745
4544
|
return s.dataModel !== void 0 || ((_s$rejected$length = (_s$rejected2 = s.rejected) === null || _s$rejected2 === void 0 ? void 0 : _s$rejected2.length) !== null && _s$rejected$length !== void 0 ? _s$rejected$length : 0) > 0;
|
|
3746
4545
|
}) ? "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" : "";
|
|
3747
|
-
const
|
|
3748
|
-
const
|
|
3749
|
-
const operations = [
|
|
3750
|
-
|
|
3751
|
-
"{\"version\":\"v1.0\",\"updateComponents\":{\"surfaceId\":\"<id>\",\"components\":[<component>, ...]}}: add or replace components by id.",
|
|
3752
|
-
"{\"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\".",
|
|
3753
|
-
"{\"version\":\"v1.0\",\"deleteSurface\":{\"surfaceId\":\"<id>\"}}: remove the surface.",
|
|
3754
|
-
...agentCalls ? ["{\"version\":\"v1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}: run an app function now, with no click. It needs no surface."] : []
|
|
3755
|
-
];
|
|
3756
|
-
const rules = [
|
|
3757
|
-
"Components are flat objects: {\"id\":\"...\",\"component\":\"<Name>\", ...props}. Every surface renders from the component with id \"root\". Reference children by id in slot props.",
|
|
3758
|
-
"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.",
|
|
3759
|
-
"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.",
|
|
3760
|
-
"Updating a component replaces all of its props, so resend every prop.",
|
|
3761
|
-
"Prop values are literals or data bindings {\"@path\":\"/data/path\"}. Never write {\"path\":\"/data/path\"} as a binding.",
|
|
3762
|
-
...events ? [hasFunctions ? "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." : "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\"."] : [],
|
|
3763
|
-
"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.",
|
|
3764
|
-
"Never use a surfaceId again, also after deleteSurface.",
|
|
3765
|
-
"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.",
|
|
3766
|
-
"${...} 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\"}}}.",
|
|
3767
|
-
"For a computed list (chart data, template items) use series. Its description under Functions gives the rules and an example.",
|
|
3768
|
-
...checks ? ["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."] : [],
|
|
3769
|
-
...templates ? ["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."] : [],
|
|
3770
|
-
...agentCalls ? ["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.", "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."] : []
|
|
3771
|
-
];
|
|
4546
|
+
const features = generativeUIPromptFeatures(generativeUIGuideFeatures(manifest));
|
|
4547
|
+
const { intro, whenToShow } = spec.tool;
|
|
4548
|
+
const operations = selectPromptItems((_spec$tool$operations = spec.tool.operations) !== null && _spec$tool$operations !== void 0 ? _spec$tool$operations : [], features);
|
|
4549
|
+
const rules = selectPromptItems(spec.tool.rules, features);
|
|
3772
4550
|
return [
|
|
3773
4551
|
`## Generative UI
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
${GENERATIVE_UI_WHEN_TO_SHOW}
|
|
4552
|
+
${intro}
|
|
3777
4553
|
|
|
3778
|
-
Every operation has "version":"
|
|
4554
|
+
${whenToShow ? `${whenToShow}\n\n` : ""}Every operation has "version":"1.0" and exactly one of:
|
|
3779
4555
|
${operations.map((op) => `- ${op}`).join("\n")}
|
|
3780
4556
|
|
|
3781
4557
|
Rules:
|
|
@@ -3857,8 +4633,6 @@ exports.COPILOT_CLOUD_ERROR_NAMES = COPILOT_CLOUD_ERROR_NAMES;
|
|
|
3857
4633
|
exports.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = COPILOT_CLOUD_PUBLIC_API_KEY_HEADER;
|
|
3858
4634
|
exports.COPILOT_CLOUD_VERSION = COPILOT_CLOUD_VERSION;
|
|
3859
4635
|
exports.ConfigurationError = ConfigurationError;
|
|
3860
|
-
exports.ConsoleColors = ConsoleColors;
|
|
3861
|
-
exports.ConsoleStyles = ConsoleStyles;
|
|
3862
4636
|
exports.CopilotKitAgentDiscoveryError = CopilotKitAgentDiscoveryError;
|
|
3863
4637
|
exports.CopilotKitApiDiscoveryError = CopilotKitApiDiscoveryError;
|
|
3864
4638
|
exports.CopilotKitError = CopilotKitError;
|
|
@@ -3866,7 +4640,6 @@ exports.CopilotKitErrorCode = CopilotKitErrorCode;
|
|
|
3866
4640
|
exports.CopilotKitLowLevelError = CopilotKitLowLevelError;
|
|
3867
4641
|
exports.CopilotKitMisuseError = CopilotKitMisuseError;
|
|
3868
4642
|
exports.CopilotKitRemoteEndpointDiscoveryError = CopilotKitRemoteEndpointDiscoveryError;
|
|
3869
|
-
exports.CopilotKitVersionMismatchError = CopilotKitVersionMismatchError;
|
|
3870
4643
|
exports.DEFAULT_AGENT_ID = DEFAULT_AGENT_ID;
|
|
3871
4644
|
exports.ERROR_CONFIG = ERROR_CONFIG;
|
|
3872
4645
|
exports.ERROR_NAMES = ERROR_NAMES;
|
|
@@ -3883,11 +4656,14 @@ exports.GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE = GENERATIVE_UI_FUNCTION_CALL_
|
|
|
3883
4656
|
exports.GENERATIVE_UI_MARKDOWN_GUIDELINES = GENERATIVE_UI_MARKDOWN_GUIDELINES;
|
|
3884
4657
|
exports.GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION = GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION;
|
|
3885
4658
|
exports.GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION = GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION;
|
|
4659
|
+
exports.GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW = GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW;
|
|
3886
4660
|
exports.GENERATIVE_UI_MAX_REJECTION_LENGTH = GENERATIVE_UI_MAX_REJECTION_LENGTH;
|
|
3887
4661
|
exports.GENERATIVE_UI_MAX_SUMMARY_REJECTIONS = GENERATIVE_UI_MAX_SUMMARY_REJECTIONS;
|
|
3888
4662
|
exports.GENERATIVE_UI_MAX_TARGET_COMPONENTS = GENERATIVE_UI_MAX_TARGET_COMPONENTS;
|
|
3889
4663
|
exports.GENERATIVE_UI_RENDER_TOOL = GENERATIVE_UI_RENDER_TOOL;
|
|
3890
4664
|
exports.GENERATIVE_UI_ROOT_ID = GENERATIVE_UI_ROOT_ID;
|
|
4665
|
+
exports.GENERATIVE_UI_WHEN_TO_SHOW = GENERATIVE_UI_WHEN_TO_SHOW;
|
|
4666
|
+
exports.GUIDE_COMPONENTS = GUIDE_COMPONENTS;
|
|
3891
4667
|
exports.MODEL_HOST_CLASSES = MODEL_HOST_CLASSES;
|
|
3892
4668
|
exports.MissingPublicApiKeyError = MissingPublicApiKeyError;
|
|
3893
4669
|
exports.RUNTIME_MODE_INTELLIGENCE = RUNTIME_MODE_INTELLIGENCE;
|
|
@@ -3906,26 +4682,27 @@ exports.UNSAMPLED_RATE = UNSAMPLED_RATE;
|
|
|
3906
4682
|
exports.UpgradeRequiredError = UpgradeRequiredError;
|
|
3907
4683
|
exports.actionParametersToJsonSchema = actionParametersToJsonSchema;
|
|
3908
4684
|
exports.applyChildRefMarks = applyChildRefMarks;
|
|
4685
|
+
exports.applyDescriptionOverrides = applyDescriptionOverrides;
|
|
4686
|
+
exports.buildCompactGenerativeUISchema = buildCompactGenerativeUISchema;
|
|
3909
4687
|
exports.buildGenerativeUIMarkdownGuidelines = buildGenerativeUIMarkdownGuidelines;
|
|
3910
4688
|
exports.buildGenerativeUIPrompt = buildGenerativeUIPrompt;
|
|
3911
4689
|
exports.callerProblem = callerProblem;
|
|
3912
4690
|
exports.childIdsAtRefs = childIdsAtRefs;
|
|
3913
4691
|
exports.childRefKind = childRefKind;
|
|
3914
4692
|
exports.classifyModelHost = classifyModelHost;
|
|
4693
|
+
exports.cloneValue = cloneValue;
|
|
3915
4694
|
exports.collectChildRefs = collectChildRefs;
|
|
3916
4695
|
exports.commitRowKeyStore = commitRowKeyStore;
|
|
3917
4696
|
exports.computeSamplingMeta = computeSamplingMeta;
|
|
3918
|
-
exports.convertJsonSchemaToZodSchema = convertJsonSchemaToZodSchema;
|
|
3919
4697
|
exports.copyToClipboard = copyToClipboard;
|
|
3920
4698
|
exports.createAttachmentContent = createAttachmentContent;
|
|
3921
4699
|
exports.createLicenseContextValue = createLicenseContextValue;
|
|
3922
4700
|
exports.createRowKeyStore = createRowKeyStore;
|
|
3923
4701
|
exports.createRunEventFinalizer = createRunEventFinalizer;
|
|
3924
|
-
exports.
|
|
4702
|
+
exports.defaultGenerativeUIPromptSpec = defaultGenerativeUIPromptSpec;
|
|
3925
4703
|
exports.ensureStructuredError = ensureStructuredError;
|
|
3926
4704
|
exports.envelopeToManifest = envelopeToManifest;
|
|
3927
4705
|
exports.exceedsMaxSize = exceedsMaxSize;
|
|
3928
|
-
exports.executeConditions = executeConditions;
|
|
3929
4706
|
exports.extractRenderUIArgs = extractRenderUIArgs;
|
|
3930
4707
|
exports.finalizeRunEvents = finalizeRunEvents;
|
|
3931
4708
|
exports.firstNonBlankTelemetryId = firstNonBlankTelemetryId;
|
|
@@ -3934,14 +4711,13 @@ exports.functionCallers = functionCallers;
|
|
|
3934
4711
|
exports.generateVideoThumbnail = generateVideoThumbnail;
|
|
3935
4712
|
exports.generativeUIFunctionCallMessageId = generativeUIFunctionCallMessageId;
|
|
3936
4713
|
exports.generativeUIGuideFeatures = generativeUIGuideFeatures;
|
|
4714
|
+
exports.generativeUIPromptFeatures = generativeUIPromptFeatures;
|
|
3937
4715
|
exports.generativeUISurfaceMessageId = generativeUISurfaceMessageId;
|
|
3938
4716
|
exports.getDocumentIcon = getDocumentIcon;
|
|
3939
4717
|
exports.getModalityFromMimeType = getModalityFromMimeType;
|
|
3940
4718
|
exports.getOperationKind = getOperationKind;
|
|
3941
4719
|
exports.getOperationSurfaceId = getOperationSurfaceId;
|
|
3942
|
-
exports.getPossibleVersionMismatch = getPossibleVersionMismatch;
|
|
3943
4720
|
exports.getSourceUrl = getSourceUrl;
|
|
3944
|
-
exports.getZodParameters = getZodParameters;
|
|
3945
4721
|
exports.hasBoundChildRef = hasBoundChildRef;
|
|
3946
4722
|
exports.isA2UIBasicFunction = isA2UIBasicFunction;
|
|
3947
4723
|
exports.isA2UIValueFunction = isA2UIValueFunction;
|
|
@@ -3952,12 +4728,9 @@ exports.isMacOS = isMacOS;
|
|
|
3952
4728
|
exports.isPathBinding = isPathBinding;
|
|
3953
4729
|
exports.isStructuredCopilotKitError = isStructuredCopilotKitError;
|
|
3954
4730
|
exports.isTelemetryDisabled = isTelemetryDisabled;
|
|
3955
|
-
exports.isValidUUID = isValidUUID;
|
|
3956
4731
|
exports.isValidationResult = isValidationResult;
|
|
3957
4732
|
exports.jsonSchemaToActionParameters = jsonSchemaToActionParameters;
|
|
3958
4733
|
exports.lambdaClient = lambdaClient;
|
|
3959
|
-
exports.logCopilotKitPlatformMessage = logCopilotKitPlatformMessage;
|
|
3960
|
-
exports.logStyled = logStyled;
|
|
3961
4734
|
exports.logger = logger;
|
|
3962
4735
|
exports.mapAtChildRef = mapAtChildRef;
|
|
3963
4736
|
exports.matchesAcceptFilter = matchesAcceptFilter;
|
|
@@ -3972,22 +4745,26 @@ exports.partialJSONParse = partialJSONParse;
|
|
|
3972
4745
|
exports.phoenixExponentialBackoff = phoenixExponentialBackoff;
|
|
3973
4746
|
exports.processEnv = processEnv;
|
|
3974
4747
|
exports.pruneRowKeyStore = pruneRowKeyStore;
|
|
3975
|
-
exports.publicApiKeyRequired = publicApiKeyRequired;
|
|
3976
4748
|
exports.randomId = randomId;
|
|
3977
4749
|
exports.randomUUID = randomUUID;
|
|
3978
4750
|
exports.readBody = readBody;
|
|
3979
4751
|
exports.readCopilotKitUIEnvelope = readCopilotKitUIEnvelope;
|
|
3980
4752
|
exports.readFileAsBase64 = readFileAsBase64;
|
|
4753
|
+
exports.renderGenerativeUIComponentList = renderGenerativeUIComponentList;
|
|
4754
|
+
exports.renderGenerativeUISchema = renderGenerativeUISchema;
|
|
3981
4755
|
exports.resolveDebugConfig = resolveDebugConfig;
|
|
3982
4756
|
exports.resolveRowRenderKeys = resolveRowRenderKeys;
|
|
3983
4757
|
exports.resolveRowRenderKeysById = resolveRowRenderKeysById;
|
|
3984
4758
|
exports.safeParseToolArgs = safeParseToolArgs;
|
|
4759
|
+
exports.schemaCoverage = schemaCoverage;
|
|
3985
4760
|
exports.schemaToJsonSchema = schemaToJsonSchema;
|
|
4761
|
+
exports.selectPromptItems = selectPromptItems;
|
|
3986
4762
|
exports.shouldEnableInspector = shouldEnableInspector;
|
|
3987
4763
|
exports.stripIntelligenceRoutingFields = stripIntelligenceRoutingFields;
|
|
3988
|
-
exports.styledConsole = styledConsole;
|
|
3989
4764
|
exports.toA2UIActionMessage = toA2UIActionMessage;
|
|
3990
4765
|
exports.tryMap = tryMap;
|
|
3991
4766
|
exports.validateOperation = validateOperation;
|
|
4767
|
+
exports.ɵINSPECTOR_LOOPBACK_HOSTS = ɵINSPECTOR_LOOPBACK_HOSTS;
|
|
4768
|
+
exports.ɵanySchema = ɵanySchema;
|
|
3992
4769
|
});
|
|
3993
4770
|
//# sourceMappingURL=index.umd.js.map
|