@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
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
// Framework-free chart helpers of the standard Chart component. They build a
|
|
2
|
+
// chart.js config without importing chart.js: the chart.js parts are typed
|
|
3
|
+
// structurally, so chart.js stays an optional peer of each framework package.
|
|
4
|
+
import { CHART_PALETTE, borderColor, textColor } from "./tokens";
|
|
5
|
+
import type { ChartProps, ChartSeries } from "./chart";
|
|
6
|
+
|
|
7
|
+
type ChartData = NonNullable<ChartProps["data"]>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The series of a chart, each with a key, a label and a color. Without
|
|
11
|
+
* series, the chart shows every number field of the first row, except the
|
|
12
|
+
* x key.
|
|
13
|
+
*
|
|
14
|
+
* @param series - The `series` prop of the chart.
|
|
15
|
+
* @param data - The rows of the chart.
|
|
16
|
+
* @param xKey - The field of the x axis (or of the slice names).
|
|
17
|
+
*/
|
|
18
|
+
export function normalizeSeries(
|
|
19
|
+
series: ChartSeries[] | undefined,
|
|
20
|
+
data: ChartData,
|
|
21
|
+
xKey: string | undefined,
|
|
22
|
+
) {
|
|
23
|
+
const first = data[0];
|
|
24
|
+
const isEmpty = series === undefined || series.length === 0;
|
|
25
|
+
const list: ChartSeries[] =
|
|
26
|
+
isEmpty && first !== undefined
|
|
27
|
+
? Object.keys(first).filter(
|
|
28
|
+
(key) => key !== xKey && typeof first[key] === "number",
|
|
29
|
+
)
|
|
30
|
+
: (series ?? []);
|
|
31
|
+
return list.map((item, index) => {
|
|
32
|
+
const entry = typeof item === "string" ? { key: item } : item;
|
|
33
|
+
const color: string =
|
|
34
|
+
textColor("color" in entry ? entry.color : undefined) ??
|
|
35
|
+
CHART_PALETTE[index % CHART_PALETTE.length]!;
|
|
36
|
+
return {
|
|
37
|
+
key: entry.key,
|
|
38
|
+
label: ("label" in entry && entry.label) || entry.key,
|
|
39
|
+
color,
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function numberStyle(format: NonNullable<ChartProps["format"]>) {
|
|
45
|
+
switch (format) {
|
|
46
|
+
case "currency":
|
|
47
|
+
return "currency";
|
|
48
|
+
case "percent":
|
|
49
|
+
return "percent";
|
|
50
|
+
case "number":
|
|
51
|
+
return "decimal";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The value formatter of the axis, the tooltip, the value labels and the
|
|
57
|
+
* data table. `undefined` when no `format` is set. Axis ticks must stay
|
|
58
|
+
* short ("$1.6K", "25%"): en-US, no decimals, and compact from 10,000.
|
|
59
|
+
*
|
|
60
|
+
* @param format - The `format` prop of the chart.
|
|
61
|
+
* @param currency - The ISO currency code for `"currency"`. Defaults to USD.
|
|
62
|
+
*/
|
|
63
|
+
export function makeFormatter(
|
|
64
|
+
format: ChartProps["format"],
|
|
65
|
+
currency: string | undefined,
|
|
66
|
+
) {
|
|
67
|
+
if (!format) return undefined;
|
|
68
|
+
const build = (isCompact: boolean) => {
|
|
69
|
+
try {
|
|
70
|
+
return new Intl.NumberFormat("en-US", {
|
|
71
|
+
style: numberStyle(format),
|
|
72
|
+
currency: format === "currency" ? (currency ?? "USD") : undefined,
|
|
73
|
+
maximumFractionDigits: format === "percent" ? 1 : 0,
|
|
74
|
+
notation: isCompact ? "compact" : undefined,
|
|
75
|
+
});
|
|
76
|
+
} catch {
|
|
77
|
+
// An unknown currency code throws. Plain numbers are a safe fallback.
|
|
78
|
+
return new Intl.NumberFormat("en-US");
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const plain = build(false);
|
|
82
|
+
const compact = build(true);
|
|
83
|
+
return (value: unknown) =>
|
|
84
|
+
typeof value === "number"
|
|
85
|
+
? (Math.abs(value) >= 10_000 ? compact : plain).format(value)
|
|
86
|
+
: String(value ?? "");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* A CSS color that a canvas can paint. The color tokens are
|
|
91
|
+
* `var(--name, fallback)` strings: the custom property comes from the
|
|
92
|
+
* computed style of `element`, else the fallback.
|
|
93
|
+
*
|
|
94
|
+
* @param value - A CSS color or a `var(...)` token.
|
|
95
|
+
* @param element - The element whose computed style holds the custom properties.
|
|
96
|
+
*/
|
|
97
|
+
export function resolveCssColor(value: string, element: Element) {
|
|
98
|
+
const match = /^var\((--[\w-]+)(?:,\s*(.*))?\)$/.exec(value.trim());
|
|
99
|
+
if (!match) return value;
|
|
100
|
+
const fallback = match[2]?.trim() ?? value;
|
|
101
|
+
if (typeof getComputedStyle !== "function") return fallback;
|
|
102
|
+
try {
|
|
103
|
+
const resolved = getComputedStyle(element)
|
|
104
|
+
.getPropertyValue(match[1]!)
|
|
105
|
+
.trim();
|
|
106
|
+
return resolved || fallback;
|
|
107
|
+
} catch {
|
|
108
|
+
return fallback;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* A `#rrggbb` color with an alpha channel added. Any other color comes back
|
|
114
|
+
* as it is.
|
|
115
|
+
*
|
|
116
|
+
* @example withAlpha("#ff0000", 0.2) // "#ff000033"
|
|
117
|
+
*/
|
|
118
|
+
export function withAlpha(color: string, alpha: number) {
|
|
119
|
+
const match = /^#([0-9a-f]{6})$/i.exec(color);
|
|
120
|
+
if (!match) return color;
|
|
121
|
+
const hex = Math.round(alpha * 255)
|
|
122
|
+
.toString(16)
|
|
123
|
+
.padStart(2, "0");
|
|
124
|
+
return `#${match[1]}${hex}`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The `key` of a chart.js point (`{ x, y }`), or the value itself when it is not a point. */
|
|
128
|
+
function pointValue(value: unknown, key: "x" | "y") {
|
|
129
|
+
if (typeof value !== "object" || value === null) return value;
|
|
130
|
+
if (key === "x") return "x" in value ? value.x : value;
|
|
131
|
+
return "y" in value ? value.y : value;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* A chart.js `Chart` constructor, as `chart.js/auto` exports it. Use it to
|
|
136
|
+
* type the module that a chart loader resolves.
|
|
137
|
+
*/
|
|
138
|
+
export type ChartConstructor = new (
|
|
139
|
+
canvas: HTMLCanvasElement,
|
|
140
|
+
config: Record<string, unknown>,
|
|
141
|
+
) => { destroy(): void };
|
|
142
|
+
|
|
143
|
+
/** The part of a chart.js chart that the value labels plugin reads and draws on. */
|
|
144
|
+
interface ChartForLabels {
|
|
145
|
+
ctx: CanvasRenderingContext2D;
|
|
146
|
+
data: { datasets: { data: unknown[] }[] };
|
|
147
|
+
options: { indexAxis?: string };
|
|
148
|
+
getDatasetMeta(index: number): {
|
|
149
|
+
hidden: boolean | null;
|
|
150
|
+
type: string;
|
|
151
|
+
data: {
|
|
152
|
+
x: number;
|
|
153
|
+
y: number;
|
|
154
|
+
getProps?: (keys: string[], final?: boolean) => Record<string, number>;
|
|
155
|
+
}[];
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* A chart.js plugin that draws the value of each bar, point and slice, for
|
|
161
|
+
* `showValueLabels`: chart.js has no value labels of its own. Bar and point
|
|
162
|
+
* labels sit above the mark (next to it in a horizontal layout); slice
|
|
163
|
+
* labels sit outside the arc, with a line unless `showLabelLines` is false.
|
|
164
|
+
*
|
|
165
|
+
* @param props - The chart props.
|
|
166
|
+
* @param format - The value formatter, from `makeFormatter`.
|
|
167
|
+
* @param textFill - The canvas color of the label text.
|
|
168
|
+
* @param lineStroke - The canvas color of the slice label lines.
|
|
169
|
+
*/
|
|
170
|
+
export function valueLabelsPlugin(
|
|
171
|
+
props: ChartProps,
|
|
172
|
+
format: ((value: unknown) => string) | undefined,
|
|
173
|
+
textFill: string | undefined,
|
|
174
|
+
lineStroke: string | undefined,
|
|
175
|
+
) {
|
|
176
|
+
const showLines = props.showLabelLines ?? true;
|
|
177
|
+
return {
|
|
178
|
+
id: "a2uiValueLabels",
|
|
179
|
+
afterDatasetsDraw(chart: ChartForLabels) {
|
|
180
|
+
const ctx = chart.ctx;
|
|
181
|
+
ctx.save();
|
|
182
|
+
ctx.font = "12px system-ui, sans-serif";
|
|
183
|
+
if (textFill) ctx.fillStyle = textFill;
|
|
184
|
+
if (lineStroke) ctx.strokeStyle = lineStroke;
|
|
185
|
+
ctx.lineWidth = 1;
|
|
186
|
+
const horizontal = chart.options.indexAxis === "y";
|
|
187
|
+
chart.data.datasets.forEach((dataset, datasetIndex) => {
|
|
188
|
+
const meta = chart.getDatasetMeta(datasetIndex);
|
|
189
|
+
if (meta.hidden) return;
|
|
190
|
+
meta.data.forEach((element, index) => {
|
|
191
|
+
const value = pointValue(dataset.data[index], "y");
|
|
192
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return;
|
|
193
|
+
const label = format ? format(value) : String(value);
|
|
194
|
+
if (meta.type === "pie" || meta.type === "doughnut") {
|
|
195
|
+
const arc = element.getProps?.(
|
|
196
|
+
["x", "y", "startAngle", "endAngle", "outerRadius"],
|
|
197
|
+
true,
|
|
198
|
+
);
|
|
199
|
+
if (!arc) return;
|
|
200
|
+
const angle = (arc.startAngle! + arc.endAngle!) / 2;
|
|
201
|
+
const cos = Math.cos(angle);
|
|
202
|
+
const sin = Math.sin(angle);
|
|
203
|
+
const edge = arc.outerRadius!;
|
|
204
|
+
const fromX = arc.x! + cos * edge;
|
|
205
|
+
const fromY = arc.y! + sin * edge;
|
|
206
|
+
const toX = arc.x! + cos * (edge + 12);
|
|
207
|
+
const toY = arc.y! + sin * (edge + 12);
|
|
208
|
+
if (showLines) {
|
|
209
|
+
ctx.beginPath();
|
|
210
|
+
ctx.moveTo(fromX, fromY);
|
|
211
|
+
ctx.lineTo(toX, toY);
|
|
212
|
+
ctx.stroke();
|
|
213
|
+
}
|
|
214
|
+
ctx.textAlign = cos >= 0 ? "left" : "right";
|
|
215
|
+
ctx.textBaseline = "middle";
|
|
216
|
+
ctx.fillText(label, toX + (cos >= 0 ? 3 : -3), toY);
|
|
217
|
+
} else if (horizontal) {
|
|
218
|
+
ctx.textAlign = "left";
|
|
219
|
+
ctx.textBaseline = "middle";
|
|
220
|
+
ctx.fillText(label, element.x + 4, element.y);
|
|
221
|
+
} else {
|
|
222
|
+
ctx.textAlign = "center";
|
|
223
|
+
ctx.textBaseline = "bottom";
|
|
224
|
+
ctx.fillText(label, element.x, element.y - 4);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
ctx.restore();
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* The chart.js config of the chart props: the marks, colors, axes, legend,
|
|
235
|
+
* tooltip and value labels. Pass it to a chart.js `Chart` constructor.
|
|
236
|
+
*
|
|
237
|
+
* @param props - The chart props.
|
|
238
|
+
* @param element - The chart element. Its computed style resolves the color tokens.
|
|
239
|
+
*/
|
|
240
|
+
export function chartConfig(
|
|
241
|
+
props: ChartProps,
|
|
242
|
+
element: Element,
|
|
243
|
+
): Record<string, unknown> {
|
|
244
|
+
const color = (value: string | undefined) =>
|
|
245
|
+
value === undefined ? undefined : resolveCssColor(value, element);
|
|
246
|
+
const data = props.data ?? [];
|
|
247
|
+
const chartType = props.chartType ?? "bar";
|
|
248
|
+
const series = normalizeSeries(props.series, data, props.xKey);
|
|
249
|
+
const format = makeFormatter(props.format, props.currency);
|
|
250
|
+
const xKey = props.xKey;
|
|
251
|
+
const secondary = color(textColor("secondary"));
|
|
252
|
+
const plugins = props.showValueLabels
|
|
253
|
+
? [valueLabelsPlugin(props, format, color(textColor("default")), secondary)]
|
|
254
|
+
: undefined;
|
|
255
|
+
const legend = {
|
|
256
|
+
display: (props.showLegend ?? true) && series.length > 0,
|
|
257
|
+
labels: {
|
|
258
|
+
usePointStyle: true,
|
|
259
|
+
pointStyle: "circle",
|
|
260
|
+
boxWidth: 8,
|
|
261
|
+
boxHeight: 8,
|
|
262
|
+
color: color(textColor("default")),
|
|
263
|
+
font: { size: 13 },
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
const tooltip = {
|
|
267
|
+
enabled: props.showTooltip ?? true,
|
|
268
|
+
callbacks: format
|
|
269
|
+
? {
|
|
270
|
+
label: (context: {
|
|
271
|
+
dataset: { label?: string };
|
|
272
|
+
parsed: unknown;
|
|
273
|
+
raw: unknown;
|
|
274
|
+
}) => {
|
|
275
|
+
const parsed = context.parsed;
|
|
276
|
+
// A horizontal layout puts the value on the x axis. A scatter
|
|
277
|
+
// point keeps its value in y whatever the layout.
|
|
278
|
+
const valueKey =
|
|
279
|
+
props.layout === "horizontal" && chartType !== "scatter"
|
|
280
|
+
? "x"
|
|
281
|
+
: "y";
|
|
282
|
+
const value = pointValue(parsed, valueKey);
|
|
283
|
+
const label = context.dataset.label;
|
|
284
|
+
return `${label ? `${label}: ` : ""}${format(value)}`;
|
|
285
|
+
},
|
|
286
|
+
}
|
|
287
|
+
: undefined,
|
|
288
|
+
};
|
|
289
|
+
const common = {
|
|
290
|
+
responsive: true,
|
|
291
|
+
maintainAspectRatio: false,
|
|
292
|
+
animation: false,
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
if (chartType === "pie" || chartType === "donut") {
|
|
296
|
+
const first = series[0];
|
|
297
|
+
const labels = data.map((row) => String(row[xKey ?? "name"] ?? ""));
|
|
298
|
+
return {
|
|
299
|
+
type: chartType === "pie" ? "pie" : "doughnut",
|
|
300
|
+
plugins,
|
|
301
|
+
data: {
|
|
302
|
+
labels,
|
|
303
|
+
datasets: first
|
|
304
|
+
? [
|
|
305
|
+
{
|
|
306
|
+
label: first.label,
|
|
307
|
+
data: data.map((row) => Number(row[first.key] ?? 0)),
|
|
308
|
+
backgroundColor: data.map((_, index) =>
|
|
309
|
+
color(CHART_PALETTE[index % CHART_PALETTE.length]!),
|
|
310
|
+
),
|
|
311
|
+
borderWidth: 0,
|
|
312
|
+
borderRadius: props.cornerRadius ?? 0,
|
|
313
|
+
spacing: props.paddingAngle ?? 0,
|
|
314
|
+
},
|
|
315
|
+
]
|
|
316
|
+
: [],
|
|
317
|
+
},
|
|
318
|
+
options: {
|
|
319
|
+
...common,
|
|
320
|
+
cutout: props.innerRadius ?? (chartType === "donut" ? "55%" : 0),
|
|
321
|
+
radius: props.outerRadius ?? "80%",
|
|
322
|
+
rotation: props.startAngle === undefined ? 0 : 90 - props.startAngle,
|
|
323
|
+
circumference:
|
|
324
|
+
props.startAngle !== undefined && props.endAngle !== undefined
|
|
325
|
+
? Math.abs(props.startAngle - props.endAngle)
|
|
326
|
+
: 360,
|
|
327
|
+
plugins: { legend, tooltip },
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const isHorizontal = props.layout === "horizontal";
|
|
333
|
+
const stacked = props.stacked === true;
|
|
334
|
+
// Scatter uses numeric distances when all x values are numbers. Preserve
|
|
335
|
+
// category spacing for string/mixed data and for the other chart types.
|
|
336
|
+
const isNumericScatter =
|
|
337
|
+
chartType === "scatter" &&
|
|
338
|
+
xKey !== undefined &&
|
|
339
|
+
data.length > 0 &&
|
|
340
|
+
data.every(
|
|
341
|
+
(row) => typeof row[xKey] === "number" && Number.isFinite(row[xKey]),
|
|
342
|
+
);
|
|
343
|
+
const labels = data.map((row) => String((xKey ? row[xKey] : "") ?? ""));
|
|
344
|
+
const pointRadius = props.showDots ? 3 : 0;
|
|
345
|
+
const datasets = series.map((item) => {
|
|
346
|
+
const paint = color(item.color);
|
|
347
|
+
const values = data.map((row) => row[item.key]);
|
|
348
|
+
switch (chartType) {
|
|
349
|
+
case "line":
|
|
350
|
+
return {
|
|
351
|
+
label: item.label,
|
|
352
|
+
data: values,
|
|
353
|
+
borderColor: paint,
|
|
354
|
+
backgroundColor: paint,
|
|
355
|
+
borderWidth: 2,
|
|
356
|
+
tension: 0.4,
|
|
357
|
+
pointRadius,
|
|
358
|
+
fill: false,
|
|
359
|
+
};
|
|
360
|
+
case "area":
|
|
361
|
+
return {
|
|
362
|
+
label: item.label,
|
|
363
|
+
data: values,
|
|
364
|
+
borderColor: paint,
|
|
365
|
+
backgroundColor: withAlpha(paint ?? "", 0.2),
|
|
366
|
+
borderWidth: 2,
|
|
367
|
+
tension: 0.4,
|
|
368
|
+
pointRadius,
|
|
369
|
+
fill: stacked ? "stack" : "origin",
|
|
370
|
+
};
|
|
371
|
+
case "scatter":
|
|
372
|
+
return {
|
|
373
|
+
label: item.label,
|
|
374
|
+
data: data.map((row, index) => ({
|
|
375
|
+
x: isNumericScatter ? row[xKey!] : index,
|
|
376
|
+
y: row[item.key],
|
|
377
|
+
})),
|
|
378
|
+
backgroundColor: paint,
|
|
379
|
+
pointRadius: 4,
|
|
380
|
+
};
|
|
381
|
+
default:
|
|
382
|
+
return {
|
|
383
|
+
label: item.label,
|
|
384
|
+
data: values,
|
|
385
|
+
backgroundColor: paint,
|
|
386
|
+
borderRadius: stacked ? 0 : (props.barRadius ?? 4),
|
|
387
|
+
borderSkipped: stacked ? false : undefined,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
const valueAxis = {
|
|
392
|
+
stacked,
|
|
393
|
+
min: props.yAxis?.min,
|
|
394
|
+
max: props.yAxis?.max,
|
|
395
|
+
grid: {
|
|
396
|
+
display: props.showGrid ?? true,
|
|
397
|
+
color: color(borderColor("subtle")),
|
|
398
|
+
},
|
|
399
|
+
border: { display: false },
|
|
400
|
+
ticks: {
|
|
401
|
+
color: secondary,
|
|
402
|
+
font: { size: 12 },
|
|
403
|
+
callback: format ? (value: unknown) => format(value) : undefined,
|
|
404
|
+
},
|
|
405
|
+
title: props.yAxis?.label
|
|
406
|
+
? {
|
|
407
|
+
display: true,
|
|
408
|
+
text: props.yAxis.label,
|
|
409
|
+
color: secondary,
|
|
410
|
+
font: { size: 12 },
|
|
411
|
+
}
|
|
412
|
+
: undefined,
|
|
413
|
+
};
|
|
414
|
+
const categoryAxis = {
|
|
415
|
+
stacked,
|
|
416
|
+
type: isNumericScatter ? "linear" : "category",
|
|
417
|
+
grid: { display: false },
|
|
418
|
+
border: { color: color(borderColor("default")) },
|
|
419
|
+
ticks: { color: secondary, font: { size: 12 } },
|
|
420
|
+
};
|
|
421
|
+
return {
|
|
422
|
+
type: chartType === "area" ? "line" : chartType,
|
|
423
|
+
plugins,
|
|
424
|
+
data: { labels: isNumericScatter ? undefined : labels, datasets },
|
|
425
|
+
options: {
|
|
426
|
+
...common,
|
|
427
|
+
indexAxis: isHorizontal ? "y" : "x",
|
|
428
|
+
plugins: { legend, tooltip },
|
|
429
|
+
scales: isHorizontal
|
|
430
|
+
? { x: valueAxis, y: categoryAxis }
|
|
431
|
+
: { x: categoryAxis, y: valueAxis },
|
|
432
|
+
},
|
|
433
|
+
};
|
|
434
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
// ---- Schema ----
|
|
4
|
+
|
|
5
|
+
export const chartSeries = z.union([
|
|
6
|
+
z.string(),
|
|
7
|
+
z.object({
|
|
8
|
+
key: z.string(),
|
|
9
|
+
label: z.string().optional(),
|
|
10
|
+
color: z.string().optional().describe("A text color token or a CSS color"),
|
|
11
|
+
}),
|
|
12
|
+
]);
|
|
13
|
+
export type ChartSeries = z.output<typeof chartSeries>;
|
|
14
|
+
|
|
15
|
+
export const chartSchema = z.object({
|
|
16
|
+
chartType: z
|
|
17
|
+
.enum(["bar", "line", "area", "scatter", "pie", "donut"])
|
|
18
|
+
.optional()
|
|
19
|
+
.describe('Default "bar"'),
|
|
20
|
+
data: z.array(z.record(z.string(), z.unknown())).optional(),
|
|
21
|
+
xKey: z.string().optional().describe("The field of the category axis"),
|
|
22
|
+
series: z
|
|
23
|
+
.array(chartSeries)
|
|
24
|
+
.optional()
|
|
25
|
+
.describe("Default: every number field except xKey"),
|
|
26
|
+
stacked: z.boolean().optional(),
|
|
27
|
+
layout: z
|
|
28
|
+
.enum(["vertical", "horizontal"])
|
|
29
|
+
.optional()
|
|
30
|
+
.describe(
|
|
31
|
+
'"horizontal" draws the bars from left to right. Default "vertical"',
|
|
32
|
+
),
|
|
33
|
+
yAxis: z
|
|
34
|
+
.object({
|
|
35
|
+
label: z.string().optional(),
|
|
36
|
+
min: z.number().optional(),
|
|
37
|
+
max: z.number().optional(),
|
|
38
|
+
width: z.number().optional().describe("Pixels"),
|
|
39
|
+
})
|
|
40
|
+
.optional()
|
|
41
|
+
.describe(
|
|
42
|
+
'Example: {label: "Revenue (USD)", min: 0, max: 100}. In a horizontal chart it is the horizontal axis, and width sets the category axis width',
|
|
43
|
+
),
|
|
44
|
+
showDots: z.boolean().optional().describe("Point markers on a line or area"),
|
|
45
|
+
barRadius: z
|
|
46
|
+
.number()
|
|
47
|
+
.optional()
|
|
48
|
+
.describe("The corner radius of a bar, in pixels"),
|
|
49
|
+
innerRadius: z
|
|
50
|
+
.union([z.number(), z.string()])
|
|
51
|
+
.optional()
|
|
52
|
+
.describe("Pie and donut"),
|
|
53
|
+
outerRadius: z
|
|
54
|
+
.union([z.number(), z.string()])
|
|
55
|
+
.optional()
|
|
56
|
+
.describe("Pie and donut"),
|
|
57
|
+
startAngle: z.number().optional().describe("Pie and donut. Default 90"),
|
|
58
|
+
endAngle: z.number().optional().describe("Pie and donut. Default -270"),
|
|
59
|
+
cornerRadius: z.number().optional().describe("The corners of a slice"),
|
|
60
|
+
paddingAngle: z.number().optional().describe("The gap between slices"),
|
|
61
|
+
showLabelLines: z
|
|
62
|
+
.boolean()
|
|
63
|
+
.optional()
|
|
64
|
+
.describe("Leader lines of the slice labels. Default true"),
|
|
65
|
+
height: z.number().optional().describe("Pixels. Default 240"),
|
|
66
|
+
showLegend: z.boolean().optional().describe("Default true"),
|
|
67
|
+
showGrid: z.boolean().optional().describe("Default true"),
|
|
68
|
+
showTooltip: z.boolean().optional().describe("Default true"),
|
|
69
|
+
showValueLabels: z.boolean().optional(),
|
|
70
|
+
format: z
|
|
71
|
+
.enum(["number", "currency", "percent"])
|
|
72
|
+
.optional()
|
|
73
|
+
.describe(
|
|
74
|
+
'With "percent", data values and axis min/max are fractions: 0.4 shows as 40%; for 0% to 10%, use min: 0 and max: 0.1.',
|
|
75
|
+
),
|
|
76
|
+
currency: z.string().optional().describe('ISO code. Default "USD"'),
|
|
77
|
+
title: z.string().optional(),
|
|
78
|
+
});
|
|
79
|
+
export type ChartProps = z.output<typeof chartSchema>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { textColor, textFont } from "./tokens";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The `checks` of the A2UI 1.0 `Checkable` components. The model writes
|
|
6
|
+
* each condition as a validator call or a boolean binding:
|
|
7
|
+
* `{ "condition": { "@call": "email", "args": { "value": { "@path": "/form/email" } } }, "message": "..." }`.
|
|
8
|
+
* The engine resolves the condition before the component renders, so a
|
|
9
|
+
* component sees a boolean or a `ValidationResult`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const severity = z.enum(["error", "warning", "info"]);
|
|
13
|
+
|
|
14
|
+
const validationResult = z
|
|
15
|
+
.object({
|
|
16
|
+
valid: z.boolean(),
|
|
17
|
+
message: z.string().optional(),
|
|
18
|
+
code: z.string().optional(),
|
|
19
|
+
severity: severity.optional(),
|
|
20
|
+
})
|
|
21
|
+
.loose();
|
|
22
|
+
|
|
23
|
+
/** The first failed check of a control, as the control shows it. */
|
|
24
|
+
export interface FailedCheck {
|
|
25
|
+
message: string;
|
|
26
|
+
/** `"error"` when the result named none. Only an error blocks. */
|
|
27
|
+
severity: z.output<typeof severity>;
|
|
28
|
+
/** The `code` of the validation result, when it had one. */
|
|
29
|
+
code?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const checksProp = z
|
|
33
|
+
.array(
|
|
34
|
+
z.object({
|
|
35
|
+
condition: z
|
|
36
|
+
.union([z.boolean(), validationResult])
|
|
37
|
+
.optional()
|
|
38
|
+
.describe(
|
|
39
|
+
'A validator call, for example {"@call":"required","args":{"value":{"@path":"/x"}}}, or a boolean binding',
|
|
40
|
+
),
|
|
41
|
+
message: z
|
|
42
|
+
.string()
|
|
43
|
+
.optional()
|
|
44
|
+
.describe("Shown when the check fails, instead of the default message"),
|
|
45
|
+
}),
|
|
46
|
+
)
|
|
47
|
+
.optional()
|
|
48
|
+
.describe("Validation rules. The control shows the first failed one");
|
|
49
|
+
|
|
50
|
+
export type ResolvedChecks = z.output<typeof checksProp>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The failed check to show, or `undefined` when every check passes: the
|
|
54
|
+
* first error, or the first warning or info when no check is an error, so
|
|
55
|
+
* a warning never hides an error that comes after it. A condition that is
|
|
56
|
+
* not known yet (undefined) passes. A `false` condition is an error with
|
|
57
|
+
* the check's message. The check's message also wins over the message of
|
|
58
|
+
* a validator result: the built-in validators always have one, and the
|
|
59
|
+
* check is where the model puts its own wording.
|
|
60
|
+
*/
|
|
61
|
+
export function firstFailedCheck(
|
|
62
|
+
checks: ResolvedChecks,
|
|
63
|
+
): FailedCheck | undefined {
|
|
64
|
+
let first: FailedCheck | undefined;
|
|
65
|
+
for (const check of checks ?? []) {
|
|
66
|
+
const { condition } = check;
|
|
67
|
+
if (condition === undefined || condition === null) continue;
|
|
68
|
+
let failed: FailedCheck;
|
|
69
|
+
if (typeof condition === "boolean") {
|
|
70
|
+
if (condition) continue;
|
|
71
|
+
failed = { message: check.message ?? "Invalid value", severity: "error" };
|
|
72
|
+
} else {
|
|
73
|
+
if (condition.valid) continue;
|
|
74
|
+
failed = {
|
|
75
|
+
message: check.message ?? condition.message ?? "Invalid value",
|
|
76
|
+
severity: condition.severity ?? "error",
|
|
77
|
+
...(condition.code === undefined ? {} : { code: condition.code }),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (failed.severity === "error") return failed;
|
|
81
|
+
first ??= failed;
|
|
82
|
+
}
|
|
83
|
+
return first;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The style of a check message, by its severity. */
|
|
87
|
+
export function checkMessageStyle(severity: FailedCheck["severity"]) {
|
|
88
|
+
return {
|
|
89
|
+
...textFont("sm"),
|
|
90
|
+
color: textColor(
|
|
91
|
+
severity === "error"
|
|
92
|
+
? "danger"
|
|
93
|
+
: severity === "warning"
|
|
94
|
+
? "warning"
|
|
95
|
+
: "secondary",
|
|
96
|
+
),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { GenerativeUIComponentDefinition } from "../catalog/catalog";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A standard component without its framework component: what the model
|
|
5
|
+
* sees (description, props, events, slots) and how the engine treats it.
|
|
6
|
+
* Each framework adds its own component with `withComponents`.
|
|
7
|
+
*/
|
|
8
|
+
export type GenerativeUIComponentDeclaration = Omit<
|
|
9
|
+
GenerativeUIComponentDefinition,
|
|
10
|
+
"component"
|
|
11
|
+
>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The definitions of `createGenerativeUI`: each declaration with the
|
|
15
|
+
* component of the same name.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const layoutComponents = withComponents(layoutDeclarations, { Box, Column });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function withComponents<
|
|
23
|
+
Declarations extends Record<string, GenerativeUIComponentDeclaration>,
|
|
24
|
+
Components extends { [Name in keyof Declarations]: unknown },
|
|
25
|
+
>(declarations: Declarations, components: Components) {
|
|
26
|
+
const definitions: Record<string, unknown> = {};
|
|
27
|
+
for (const name of Object.keys(declarations)) {
|
|
28
|
+
definitions[name] = { ...declarations[name], component: components[name] };
|
|
29
|
+
}
|
|
30
|
+
return definitions as {
|
|
31
|
+
[Name in keyof Declarations]: Declarations[Name] & {
|
|
32
|
+
component: Components[Name];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|