aeon-ui-engine 1.0.3 → 1.2.0
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/CHANGELOG.md +34 -0
- package/CONSUMER.md +82 -40
- package/README.md +47 -16
- package/package.json +9 -2
- package/packages/cli/README.md +17 -0
- package/packages/cli/dist/bin.d.ts +1 -0
- package/packages/cli/dist/bin.js +35 -0
- package/packages/cli/dist/chunk-IW5NT2Z2.js +103 -0
- package/packages/cli/dist/index.d.ts +10 -0
- package/packages/cli/dist/index.js +6 -0
- package/packages/cli/node_modules/.bin/esbuild +21 -0
- package/packages/cli/node_modules/.bin/jiti +21 -0
- package/packages/cli/node_modules/.bin/tsc +21 -0
- package/packages/cli/node_modules/.bin/tsserver +21 -0
- package/packages/cli/node_modules/.bin/tsup +21 -0
- package/packages/cli/node_modules/.bin/tsup-node +21 -0
- package/packages/cli/node_modules/.bin/tsx +21 -0
- package/packages/cli/node_modules/.bin/vite +21 -0
- package/packages/cli/node_modules/.bin/vitest +21 -0
- package/packages/cli/package.json +50 -0
- package/packages/cli/src/bin.ts +34 -0
- package/packages/cli/src/index.ts +1 -0
- package/packages/cli/src/init.ts +107 -0
- package/packages/cli/tsconfig.json +10 -0
- package/packages/core/README.md +7 -1
- package/packages/core/dist/index.d.ts +255 -7
- package/packages/core/dist/index.js +372 -2
- package/packages/core/node_modules/.bin/esbuild +4 -4
- package/packages/core/node_modules/.bin/vite +4 -4
- package/packages/core/node_modules/.bin/vitest +2 -2
- package/packages/core/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -1
- package/packages/core/package.json +17 -5
- package/packages/core/src/anatomy.ts +234 -5
- package/packages/core/src/brand-theme.ts +172 -0
- package/packages/core/src/index.ts +1 -0
- package/packages/core/src/machine.test.ts +62 -1
- package/packages/core/src/machine.ts +93 -0
- package/packages/core/src/theme.ts +105 -0
- package/packages/panda/aeon.css +8 -0
- package/packages/panda/package.json +1 -1
- package/packages/panda/panda.config.ts +58 -1
- package/packages/panda/src/recipes/app-shell.ts +137 -0
- package/packages/panda/src/recipes/avatar.ts +131 -0
- package/packages/panda/src/recipes/bar.ts +206 -0
- package/packages/panda/src/recipes/button-group.ts +12 -4
- package/packages/panda/src/recipes/button.ts +1 -0
- package/packages/panda/src/recipes/combobox.ts +2 -1
- package/packages/panda/src/recipes/composer.ts +81 -0
- package/packages/panda/src/recipes/content.ts +104 -0
- package/packages/panda/src/recipes/conversation.ts +106 -0
- package/packages/panda/src/recipes/entry.ts +217 -0
- package/packages/panda/src/recipes/field.ts +12 -2
- package/packages/panda/src/recipes/floating.ts +26 -13
- package/packages/panda/src/recipes/identity.ts +73 -0
- package/packages/panda/src/recipes/index.ts +15 -0
- package/packages/panda/src/recipes/list-row.ts +109 -0
- package/packages/panda/src/recipes/metric-strip.ts +80 -0
- package/packages/panda/src/recipes/nav.ts +155 -0
- package/packages/panda/src/recipes/panel.ts +156 -0
- package/packages/panda/src/recipes/pin-input.ts +3 -2
- package/packages/panda/src/recipes/profile-header.ts +120 -0
- package/packages/panda/src/recipes/select.ts +2 -1
- package/packages/panda/src/recipes/slider.ts +6 -4
- package/packages/panda/src/recipes/theme-switcher.ts +110 -0
- package/packages/panda/src/recipes/thread.ts +88 -0
- package/packages/panda/src/theme/catalog-types.ts +2 -0
- package/packages/panda/src/theme/catalog.ts +23 -0
- package/packages/panda/src/theme/chrome.css +2 -1
- package/packages/panda/src/theme/consumer-shell.css +129 -0
- package/packages/panda/src/theme/electron.css +30 -0
- package/packages/panda/src/theme/global-theme-css.ts +9 -0
- package/packages/panda/src/theme/omarchy.themes.ts +607 -0
- package/packages/panda/src/theme/palette.ts +3 -0
- package/packages/panda/src/theme/scrollbars.css +58 -21
- package/packages/panda/src/theme/themes.config.ts +39 -1
- package/packages/panda/styled-system/css/conditions.mjs +1 -1
- package/packages/panda/styled-system/css/css.mjs +1 -1
- package/packages/panda/styled-system/css/sva.mjs +9 -4
- package/packages/panda/styled-system/helpers.mjs +11 -22
- package/packages/panda/styled-system/jsx/create-style-context.d.ts +54 -0
- package/packages/panda/styled-system/jsx/create-style-context.mjs +121 -0
- package/packages/panda/styled-system/jsx/factory.mjs +14 -5
- package/packages/panda/styled-system/jsx/index.d.ts +1 -0
- package/packages/panda/styled-system/jsx/index.mjs +1 -0
- package/packages/panda/styled-system/jsx/is-valid-prop.mjs +2 -2
- package/packages/panda/styled-system/patterns/aspect-ratio.d.ts +0 -1
- package/packages/panda/styled-system/patterns/bleed.d.ts +0 -1
- package/packages/panda/styled-system/patterns/box.d.ts +0 -1
- package/packages/panda/styled-system/patterns/center.d.ts +0 -1
- package/packages/panda/styled-system/patterns/circle.d.ts +0 -1
- package/packages/panda/styled-system/patterns/container.d.ts +0 -1
- package/packages/panda/styled-system/patterns/cq.d.ts +0 -1
- package/packages/panda/styled-system/patterns/divider.d.ts +0 -1
- package/packages/panda/styled-system/patterns/flex.d.ts +0 -1
- package/packages/panda/styled-system/patterns/float.d.ts +0 -1
- package/packages/panda/styled-system/patterns/grid-item.d.ts +0 -1
- package/packages/panda/styled-system/patterns/grid.d.ts +0 -1
- package/packages/panda/styled-system/patterns/grid.mjs +1 -1
- package/packages/panda/styled-system/patterns/hstack.d.ts +0 -1
- package/packages/panda/styled-system/patterns/hstack.mjs +1 -1
- package/packages/panda/styled-system/patterns/link-overlay.d.ts +0 -1
- package/packages/panda/styled-system/patterns/spacer.d.ts +0 -1
- package/packages/panda/styled-system/patterns/spacer.mjs +6 -2
- package/packages/panda/styled-system/patterns/square.d.ts +0 -1
- package/packages/panda/styled-system/patterns/stack.d.ts +0 -1
- package/packages/panda/styled-system/patterns/stack.mjs +1 -1
- package/packages/panda/styled-system/patterns/visually-hidden.d.ts +0 -1
- package/packages/panda/styled-system/patterns/vstack.d.ts +0 -1
- package/packages/panda/styled-system/patterns/vstack.mjs +1 -1
- package/packages/panda/styled-system/patterns/wrap.d.ts +0 -1
- package/packages/panda/styled-system/patterns/wrap.mjs +1 -1
- package/packages/panda/styled-system/recipes/aeon-accordion.d.ts +4 -3
- package/packages/panda/styled-system/recipes/aeon-accordion.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-app-shell.d.ts +34 -0
- package/packages/panda/styled-system/recipes/aeon-app-shell.mjs +70 -0
- package/packages/panda/styled-system/recipes/aeon-async.d.ts +4 -3
- package/packages/panda/styled-system/recipes/aeon-async.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-avatar.d.ts +36 -0
- package/packages/panda/styled-system/recipes/aeon-avatar.mjs +57 -0
- package/packages/panda/styled-system/recipes/aeon-badge.d.ts +3 -0
- package/packages/panda/styled-system/recipes/aeon-bar.d.ts +40 -0
- package/packages/panda/styled-system/recipes/aeon-bar.mjs +77 -0
- package/packages/panda/styled-system/recipes/aeon-button-group.d.ts +3 -2
- package/packages/panda/styled-system/recipes/aeon-button.d.ts +3 -2
- package/packages/panda/styled-system/recipes/aeon-checkbox.d.ts +4 -1
- package/packages/panda/styled-system/recipes/aeon-checkbox.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-combobox.d.ts +4 -3
- package/packages/panda/styled-system/recipes/aeon-combobox.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-composer.d.ts +31 -0
- package/packages/panda/styled-system/recipes/aeon-composer.mjs +45 -0
- package/packages/panda/styled-system/recipes/aeon-content.d.ts +34 -0
- package/packages/panda/styled-system/recipes/aeon-content.mjs +70 -0
- package/packages/panda/styled-system/recipes/aeon-conversation.d.ts +31 -0
- package/packages/panda/styled-system/recipes/aeon-conversation.mjs +61 -0
- package/packages/panda/styled-system/recipes/aeon-dialog.d.ts +4 -1
- package/packages/panda/styled-system/recipes/aeon-dialog.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-entry.d.ts +38 -0
- package/packages/panda/styled-system/recipes/aeon-entry.mjs +100 -0
- package/packages/panda/styled-system/recipes/aeon-field.d.ts +4 -3
- package/packages/panda/styled-system/recipes/aeon-field.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-identity.d.ts +36 -0
- package/packages/panda/styled-system/recipes/aeon-identity.mjs +63 -0
- package/packages/panda/styled-system/recipes/aeon-list-row.d.ts +33 -0
- package/packages/panda/styled-system/recipes/aeon-list-row.mjs +49 -0
- package/packages/panda/styled-system/recipes/aeon-menu.d.ts +4 -1
- package/packages/panda/styled-system/recipes/aeon-menu.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-metric-strip.d.ts +36 -0
- package/packages/panda/styled-system/recipes/aeon-metric-strip.mjs +54 -0
- package/packages/panda/styled-system/recipes/aeon-nav.d.ts +38 -0
- package/packages/panda/styled-system/recipes/aeon-nav.mjs +69 -0
- package/packages/panda/styled-system/recipes/aeon-panel.d.ts +34 -0
- package/packages/panda/styled-system/recipes/aeon-panel.mjs +58 -0
- package/packages/panda/styled-system/recipes/aeon-pin-input.d.ts +4 -1
- package/packages/panda/styled-system/recipes/aeon-pin-input.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-popover.d.ts +4 -1
- package/packages/panda/styled-system/recipes/aeon-popover.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-profile-header.d.ts +36 -0
- package/packages/panda/styled-system/recipes/aeon-profile-header.mjs +62 -0
- package/packages/panda/styled-system/recipes/aeon-progress.d.ts +4 -1
- package/packages/panda/styled-system/recipes/aeon-progress.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-radio-group.d.ts +4 -1
- package/packages/panda/styled-system/recipes/aeon-radio-group.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-scroll.d.ts +4 -3
- package/packages/panda/styled-system/recipes/aeon-scroll.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-select.d.ts +4 -3
- package/packages/panda/styled-system/recipes/aeon-select.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-separator.d.ts +4 -1
- package/packages/panda/styled-system/recipes/aeon-separator.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-slider.d.ts +4 -1
- package/packages/panda/styled-system/recipes/aeon-slider.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-switch.d.ts +4 -1
- package/packages/panda/styled-system/recipes/aeon-switch.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-tabs.d.ts +4 -1
- package/packages/panda/styled-system/recipes/aeon-tabs.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-theme-switcher.d.ts +34 -0
- package/packages/panda/styled-system/recipes/aeon-theme-switcher.mjs +59 -0
- package/packages/panda/styled-system/recipes/aeon-thread.d.ts +31 -0
- package/packages/panda/styled-system/recipes/aeon-thread.mjs +53 -0
- package/packages/panda/styled-system/recipes/aeon-toast.d.ts +4 -1
- package/packages/panda/styled-system/recipes/aeon-toast.mjs +1 -0
- package/packages/panda/styled-system/recipes/aeon-tooltip.d.ts +4 -1
- package/packages/panda/styled-system/recipes/aeon-tooltip.mjs +1 -0
- package/packages/panda/styled-system/recipes/index.d.ts +16 -1
- package/packages/panda/styled-system/recipes/index.mjs +16 -1
- package/packages/panda/styled-system/styles.css +2317 -450
- package/packages/panda/styled-system/tokens/index.mjs +43 -7
- package/packages/panda/styled-system/tokens/tokens.d.ts +5 -5
- package/packages/panda/styled-system/types/composition.d.ts +86 -23
- package/packages/panda/styled-system/types/conditions.d.ts +34 -10
- package/packages/panda/styled-system/types/csstype.d.ts +6405 -5133
- package/packages/panda/styled-system/types/jsx.d.ts +27 -10
- package/packages/panda/styled-system/types/pattern.d.ts +4 -4
- package/packages/panda/styled-system/types/prop-type.d.ts +11 -1
- package/packages/panda/styled-system/types/style-props.d.ts +2763 -2165
- package/packages/panda/styled-system/types/system-types.d.ts +38 -80
- package/packages/panda/theme-runtime.css +945 -0
- package/packages/primitives/dist/chunk-4NOKRUSG.js +81 -0
- package/packages/primitives/dist/chunk-R25CUHNF.js +46 -0
- package/packages/primitives/dist/chunk-RO2DMFN5.js +89 -0
- package/packages/primitives/dist/chunk-V5D7LS4J.js +61 -0
- package/packages/primitives/dist/chunk-YBPNI2LI.js +70 -0
- package/packages/primitives/dist/index.d.ts +5 -0
- package/packages/primitives/dist/index.js +46 -14
- package/packages/primitives/dist/machines/app-nav.d.ts +96 -0
- package/packages/primitives/dist/machines/app-nav.js +12 -0
- package/packages/primitives/dist/machines/app-shell.d.ts +57 -0
- package/packages/primitives/dist/machines/app-shell.js +8 -0
- package/packages/primitives/dist/machines/async.d.ts +4 -4
- package/packages/primitives/dist/machines/content-region.d.ts +72 -0
- package/packages/primitives/dist/machines/content-region.js +8 -0
- package/packages/primitives/dist/machines/panel.d.ts +50 -0
- package/packages/primitives/dist/machines/panel.js +6 -0
- package/packages/primitives/dist/machines/sticky-bar.d.ts +62 -0
- package/packages/primitives/dist/machines/sticky-bar.js +8 -0
- package/packages/primitives/node_modules/.bin/esbuild +21 -0
- package/packages/primitives/node_modules/.bin/vite +21 -0
- package/packages/primitives/node_modules/.bin/vitest +2 -2
- package/packages/primitives/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -1
- package/packages/primitives/package.json +15 -5
- package/packages/primitives/scripts/xstate-introspect.mjs +35 -0
- package/packages/primitives/src/__tests__/app-nav.test.ts +30 -0
- package/packages/primitives/src/index.ts +5 -0
- package/packages/primitives/src/machines/app-nav.ts +107 -0
- package/packages/primitives/src/machines/app-shell.ts +63 -0
- package/packages/primitives/src/machines/content-region.ts +107 -0
- package/packages/primitives/src/machines/panel.ts +71 -0
- package/packages/primitives/src/machines/sticky-bar.ts +89 -0
- package/packages/react/dist/index.d.ts +536 -17
- package/packages/react/dist/index.js +2163 -479
- package/packages/react/node_modules/.bin/esbuild +21 -0
- package/packages/react/node_modules/.bin/vite +21 -0
- package/packages/react/node_modules/.bin/vitest +2 -2
- package/packages/react/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -1
- package/packages/react/package.json +18 -7
- package/packages/react/src/app-nav/index.tsx +249 -0
- package/packages/react/src/app-shell/index.tsx +154 -0
- package/packages/react/src/async/index.tsx +6 -1
- package/packages/react/src/async/map-content-state.ts +18 -0
- package/packages/react/src/avatar/index.tsx +23 -1
- package/packages/react/src/bar/index.tsx +101 -0
- package/packages/react/src/button/index.tsx +4 -2
- package/packages/react/src/composer/index.tsx +75 -0
- package/packages/react/src/content/index.tsx +149 -0
- package/packages/react/src/conversation/index.tsx +78 -0
- package/packages/react/src/entry/index.tsx +85 -0
- package/packages/react/src/field/index.tsx +31 -18
- package/packages/react/src/hooks/use-fit-text.ts +59 -0
- package/packages/react/src/identity/index.tsx +110 -0
- package/packages/react/src/index.ts +19 -0
- package/packages/react/src/list-row/index.tsx +80 -0
- package/packages/react/src/metric-strip/index.tsx +88 -0
- package/packages/react/src/nav/index.tsx +155 -0
- package/packages/react/src/panel/index.tsx +267 -0
- package/packages/react/src/profile-header/index.tsx +91 -0
- package/packages/react/src/prompt/index.tsx +161 -0
- package/packages/react/src/radio-group/index.tsx +19 -7
- package/packages/react/src/slider/index.tsx +3 -1
- package/packages/react/src/status-banner/index.tsx +84 -0
- package/packages/react/src/sticky-bar/index.tsx +135 -0
- package/packages/react/src/switch/index.tsx +7 -1
- package/packages/react/src/theme-switcher/index.tsx +227 -0
- package/packages/react/src/thread/index.tsx +95 -0
- package/packages/react/src/toast/primitives.tsx +2 -2
- package/packages/react/src/tooltip/tooltip.test.tsx +9 -1
- package/packages/react/tsconfig.json +2 -1
- package/packages/schemas/README.md +52 -0
- package/packages/schemas/dist/index.d.ts +287 -0
- package/packages/schemas/dist/index.js +701 -0
- package/packages/schemas/json/accordion.json +132 -0
- package/packages/schemas/json/async.json +161 -0
- package/packages/schemas/json/button.json +170 -0
- package/packages/schemas/json/catalog.json +2299 -0
- package/packages/schemas/json/checkbox.json +136 -0
- package/packages/schemas/json/combobox.json +130 -0
- package/packages/schemas/json/dialog.json +154 -0
- package/packages/schemas/json/field.json +171 -0
- package/packages/schemas/json/menu.json +138 -0
- package/packages/schemas/json/popover.json +133 -0
- package/packages/schemas/json/progress.json +137 -0
- package/packages/schemas/json/scroll.json +129 -0
- package/packages/schemas/json/select.json +140 -0
- package/packages/schemas/json/switch.json +136 -0
- package/packages/schemas/json/tabs.json +135 -0
- package/packages/schemas/json/toast.json +141 -0
- package/packages/schemas/json/tooltip.json +123 -0
- package/packages/schemas/node_modules/.bin/esbuild +21 -0
- package/packages/schemas/node_modules/.bin/jiti +21 -0
- package/packages/schemas/node_modules/.bin/tsc +21 -0
- package/packages/schemas/node_modules/.bin/tsserver +21 -0
- package/packages/schemas/node_modules/.bin/tsup +21 -0
- package/packages/schemas/node_modules/.bin/tsup-node +21 -0
- package/packages/schemas/node_modules/.bin/tsx +21 -0
- package/packages/schemas/node_modules/.bin/vite +21 -0
- package/packages/schemas/node_modules/.bin/vitest +21 -0
- package/packages/schemas/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/packages/schemas/package.json +56 -0
- package/packages/schemas/prompts/cursorrules.md +64 -0
- package/packages/schemas/prompts/statecharts.md +31 -0
- package/packages/schemas/prompts/system.md +30 -0
- package/packages/schemas/registry/catalog.json +54 -0
- package/packages/schemas/registry/components/accordion.json +132 -0
- package/packages/schemas/registry/components/async.json +161 -0
- package/packages/schemas/registry/components/button.json +170 -0
- package/packages/schemas/registry/components/checkbox.json +136 -0
- package/packages/schemas/registry/components/combobox.json +130 -0
- package/packages/schemas/registry/components/dialog.json +154 -0
- package/packages/schemas/registry/components/field.json +171 -0
- package/packages/schemas/registry/components/menu.json +138 -0
- package/packages/schemas/registry/components/popover.json +133 -0
- package/packages/schemas/registry/components/progress.json +137 -0
- package/packages/schemas/registry/components/scroll.json +129 -0
- package/packages/schemas/registry/components/select.json +140 -0
- package/packages/schemas/registry/components/switch.json +136 -0
- package/packages/schemas/registry/components/tabs.json +135 -0
- package/packages/schemas/registry/components/toast.json +141 -0
- package/packages/schemas/registry/components/tooltip.json +123 -0
- package/packages/schemas/registry/machines/async.json +219 -0
- package/packages/schemas/registry/machines/buttonLifecycle.json +224 -0
- package/packages/schemas/registry/machines/dialog.json +143 -0
- package/packages/schemas/registry/machines/field.json +275 -0
- package/packages/schemas/scripts/emit.ts +61 -0
- package/packages/schemas/src/aeon-to-schema.test.ts +70 -0
- package/packages/schemas/src/aeon-to-schema.ts +206 -0
- package/packages/schemas/src/agent-bridge.ts +82 -0
- package/packages/schemas/src/components.ts +307 -0
- package/packages/schemas/src/index.test.ts +25 -0
- package/packages/schemas/src/index.ts +25 -0
- package/packages/schemas/src/prompts.ts +121 -0
- package/packages/schemas/src/registry.ts +73 -0
- package/packages/schemas/src/schema-builder.ts +87 -0
- package/packages/schemas/tsconfig.json +9 -0
- package/packages/solid/package.json +2 -2
- package/packages/svelte/node_modules/.bin/esbuild +21 -0
- package/packages/svelte/node_modules/.bin/vite +4 -4
- package/packages/svelte/package.json +15 -5
- package/packages/ui/README.md +19 -6
- package/packages/ui/dist/index.d.ts +254 -9
- package/packages/ui/dist/index.js +690 -139
- package/packages/ui/src/app-nav.tsx +2 -0
- package/packages/ui/src/app-shell.tsx +44 -0
- package/packages/ui/src/async.tsx +2 -1
- package/packages/ui/src/avatar.tsx +35 -0
- package/packages/ui/src/bar.tsx +34 -0
- package/packages/ui/src/composer.tsx +27 -0
- package/packages/ui/src/content.tsx +43 -0
- package/packages/ui/src/conversation.tsx +43 -0
- package/packages/ui/src/entry.tsx +76 -0
- package/packages/ui/src/field.tsx +5 -0
- package/packages/ui/src/identity.tsx +35 -0
- package/packages/ui/src/index.ts +20 -0
- package/packages/ui/src/list-row.tsx +30 -0
- package/packages/ui/src/metric-strip.tsx +29 -0
- package/packages/ui/src/nav.tsx +46 -0
- package/packages/ui/src/panel.tsx +39 -0
- package/packages/ui/src/profile-header.tsx +35 -0
- package/packages/ui/src/prompt.tsx +29 -0
- package/packages/ui/src/status-banner.tsx +1 -0
- package/packages/ui/src/sticky-bar.tsx +42 -0
- package/packages/ui/src/switch.tsx +17 -4
- package/packages/ui/src/theme-switcher.tsx +41 -0
- package/packages/ui/src/thread.tsx +35 -0
- package/packages/vue/package.json +3 -3
- package/scripts/vite-aliases.mjs +65 -3
- package/scripts/xstate-introspect.mjs +68 -0
- package/packages/react/src/async/legacy-region.tsx +0 -38
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "field",
|
|
3
|
+
"events": [
|
|
4
|
+
"INPUT",
|
|
5
|
+
"BLUR",
|
|
6
|
+
"RESET",
|
|
7
|
+
"VALIDATE",
|
|
8
|
+
"SUBMIT",
|
|
9
|
+
"SUBMIT_DONE",
|
|
10
|
+
"SUBMIT_FAIL"
|
|
11
|
+
],
|
|
12
|
+
"tree": {
|
|
13
|
+
"key": "field",
|
|
14
|
+
"id": "field",
|
|
15
|
+
"type": "parallel",
|
|
16
|
+
"events": [
|
|
17
|
+
"INPUT",
|
|
18
|
+
"BLUR",
|
|
19
|
+
"RESET",
|
|
20
|
+
"VALIDATE",
|
|
21
|
+
"SUBMIT",
|
|
22
|
+
"SUBMIT_DONE",
|
|
23
|
+
"SUBMIT_FAIL"
|
|
24
|
+
],
|
|
25
|
+
"transitions": [],
|
|
26
|
+
"children": [
|
|
27
|
+
{
|
|
28
|
+
"key": "interaction",
|
|
29
|
+
"id": "field.interaction",
|
|
30
|
+
"type": "compound",
|
|
31
|
+
"events": [
|
|
32
|
+
"INPUT",
|
|
33
|
+
"BLUR",
|
|
34
|
+
"RESET"
|
|
35
|
+
],
|
|
36
|
+
"transitions": [],
|
|
37
|
+
"children": [
|
|
38
|
+
{
|
|
39
|
+
"key": "pristine",
|
|
40
|
+
"id": "field.interaction.pristine",
|
|
41
|
+
"type": "atomic",
|
|
42
|
+
"events": [
|
|
43
|
+
"INPUT",
|
|
44
|
+
"BLUR"
|
|
45
|
+
],
|
|
46
|
+
"transitions": [
|
|
47
|
+
{
|
|
48
|
+
"event": "INPUT",
|
|
49
|
+
"target": [
|
|
50
|
+
"dirty"
|
|
51
|
+
],
|
|
52
|
+
"guarded": false
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"event": "BLUR",
|
|
56
|
+
"target": [
|
|
57
|
+
"dirty"
|
|
58
|
+
],
|
|
59
|
+
"guarded": false
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
"children": []
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"key": "dirty",
|
|
66
|
+
"id": "field.interaction.dirty",
|
|
67
|
+
"type": "atomic",
|
|
68
|
+
"events": [
|
|
69
|
+
"RESET"
|
|
70
|
+
],
|
|
71
|
+
"transitions": [
|
|
72
|
+
{
|
|
73
|
+
"event": "RESET",
|
|
74
|
+
"target": [
|
|
75
|
+
"pristine"
|
|
76
|
+
],
|
|
77
|
+
"guarded": false
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
"children": []
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"key": "validation",
|
|
86
|
+
"id": "field.validation",
|
|
87
|
+
"type": "compound",
|
|
88
|
+
"events": [
|
|
89
|
+
"VALIDATE",
|
|
90
|
+
"RESET"
|
|
91
|
+
],
|
|
92
|
+
"transitions": [],
|
|
93
|
+
"children": [
|
|
94
|
+
{
|
|
95
|
+
"key": "valid",
|
|
96
|
+
"id": "field.validation.valid",
|
|
97
|
+
"type": "atomic",
|
|
98
|
+
"events": [
|
|
99
|
+
"VALIDATE"
|
|
100
|
+
],
|
|
101
|
+
"transitions": [
|
|
102
|
+
{
|
|
103
|
+
"event": "VALIDATE",
|
|
104
|
+
"target": [
|
|
105
|
+
"invalid"
|
|
106
|
+
],
|
|
107
|
+
"guarded": true
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
"children": []
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"key": "invalid",
|
|
114
|
+
"id": "field.validation.invalid",
|
|
115
|
+
"type": "atomic",
|
|
116
|
+
"events": [
|
|
117
|
+
"VALIDATE",
|
|
118
|
+
"RESET"
|
|
119
|
+
],
|
|
120
|
+
"transitions": [
|
|
121
|
+
{
|
|
122
|
+
"event": "VALIDATE",
|
|
123
|
+
"target": [
|
|
124
|
+
"valid"
|
|
125
|
+
],
|
|
126
|
+
"guarded": true
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"event": "RESET",
|
|
130
|
+
"target": [
|
|
131
|
+
"valid"
|
|
132
|
+
],
|
|
133
|
+
"guarded": false
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
"children": []
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"key": "submission",
|
|
142
|
+
"id": "field.submission",
|
|
143
|
+
"type": "compound",
|
|
144
|
+
"events": [
|
|
145
|
+
"SUBMIT",
|
|
146
|
+
"SUBMIT_DONE",
|
|
147
|
+
"SUBMIT_FAIL"
|
|
148
|
+
],
|
|
149
|
+
"transitions": [],
|
|
150
|
+
"children": [
|
|
151
|
+
{
|
|
152
|
+
"key": "idle",
|
|
153
|
+
"id": "field.submission.idle",
|
|
154
|
+
"type": "atomic",
|
|
155
|
+
"events": [
|
|
156
|
+
"SUBMIT"
|
|
157
|
+
],
|
|
158
|
+
"transitions": [
|
|
159
|
+
{
|
|
160
|
+
"event": "SUBMIT",
|
|
161
|
+
"target": [
|
|
162
|
+
"pending"
|
|
163
|
+
],
|
|
164
|
+
"guarded": false
|
|
165
|
+
}
|
|
166
|
+
],
|
|
167
|
+
"children": []
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"key": "pending",
|
|
171
|
+
"id": "field.submission.pending",
|
|
172
|
+
"type": "atomic",
|
|
173
|
+
"events": [
|
|
174
|
+
"SUBMIT_DONE",
|
|
175
|
+
"SUBMIT_FAIL"
|
|
176
|
+
],
|
|
177
|
+
"transitions": [
|
|
178
|
+
{
|
|
179
|
+
"event": "SUBMIT_DONE",
|
|
180
|
+
"target": [
|
|
181
|
+
"idle"
|
|
182
|
+
],
|
|
183
|
+
"guarded": false
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"event": "SUBMIT_FAIL",
|
|
187
|
+
"target": [
|
|
188
|
+
"idle"
|
|
189
|
+
],
|
|
190
|
+
"guarded": false
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
"children": []
|
|
194
|
+
}
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
},
|
|
199
|
+
"states": {
|
|
200
|
+
"field": {
|
|
201
|
+
"events": [
|
|
202
|
+
"INPUT",
|
|
203
|
+
"BLUR",
|
|
204
|
+
"RESET",
|
|
205
|
+
"VALIDATE",
|
|
206
|
+
"SUBMIT",
|
|
207
|
+
"SUBMIT_DONE",
|
|
208
|
+
"SUBMIT_FAIL"
|
|
209
|
+
],
|
|
210
|
+
"type": "parallel"
|
|
211
|
+
},
|
|
212
|
+
"field.interaction": {
|
|
213
|
+
"events": [
|
|
214
|
+
"INPUT",
|
|
215
|
+
"BLUR",
|
|
216
|
+
"RESET"
|
|
217
|
+
],
|
|
218
|
+
"type": "compound"
|
|
219
|
+
},
|
|
220
|
+
"field.interaction.pristine": {
|
|
221
|
+
"events": [
|
|
222
|
+
"INPUT",
|
|
223
|
+
"BLUR"
|
|
224
|
+
],
|
|
225
|
+
"type": "atomic"
|
|
226
|
+
},
|
|
227
|
+
"field.interaction.dirty": {
|
|
228
|
+
"events": [
|
|
229
|
+
"RESET"
|
|
230
|
+
],
|
|
231
|
+
"type": "atomic"
|
|
232
|
+
},
|
|
233
|
+
"field.validation": {
|
|
234
|
+
"events": [
|
|
235
|
+
"VALIDATE",
|
|
236
|
+
"RESET"
|
|
237
|
+
],
|
|
238
|
+
"type": "compound"
|
|
239
|
+
},
|
|
240
|
+
"field.validation.valid": {
|
|
241
|
+
"events": [
|
|
242
|
+
"VALIDATE"
|
|
243
|
+
],
|
|
244
|
+
"type": "atomic"
|
|
245
|
+
},
|
|
246
|
+
"field.validation.invalid": {
|
|
247
|
+
"events": [
|
|
248
|
+
"VALIDATE",
|
|
249
|
+
"RESET"
|
|
250
|
+
],
|
|
251
|
+
"type": "atomic"
|
|
252
|
+
},
|
|
253
|
+
"field.submission": {
|
|
254
|
+
"events": [
|
|
255
|
+
"SUBMIT",
|
|
256
|
+
"SUBMIT_DONE",
|
|
257
|
+
"SUBMIT_FAIL"
|
|
258
|
+
],
|
|
259
|
+
"type": "compound"
|
|
260
|
+
},
|
|
261
|
+
"field.submission.idle": {
|
|
262
|
+
"events": [
|
|
263
|
+
"SUBMIT"
|
|
264
|
+
],
|
|
265
|
+
"type": "atomic"
|
|
266
|
+
},
|
|
267
|
+
"field.submission.pending": {
|
|
268
|
+
"events": [
|
|
269
|
+
"SUBMIT_DONE",
|
|
270
|
+
"SUBMIT_FAIL"
|
|
271
|
+
],
|
|
272
|
+
"type": "atomic"
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync, cpSync, existsSync } from 'node:fs'
|
|
2
|
+
import { dirname, join } from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import {
|
|
5
|
+
asyncMachine,
|
|
6
|
+
buttonLifecycleMachine,
|
|
7
|
+
dialogMachine,
|
|
8
|
+
fieldMachine,
|
|
9
|
+
} from '@aeon-ui/primitives'
|
|
10
|
+
import { catalog, componentSchemas } from '../src/components.js'
|
|
11
|
+
import { AEON_SYSTEM_PROMPT, CURSOR_RULES_SNIPPET, STATECHART_PROMPTS } from '../src/prompts.js'
|
|
12
|
+
import { aeonToSchema } from '../src/aeon-to-schema.js'
|
|
13
|
+
import { registryCatalog } from '../src/registry.js'
|
|
14
|
+
|
|
15
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
16
|
+
const jsonDir = join(root, 'json')
|
|
17
|
+
const promptsDir = join(root, 'prompts')
|
|
18
|
+
const registryDir = join(root, 'registry')
|
|
19
|
+
const demoRegistry = join(root, '../../apps/demo/public/registry')
|
|
20
|
+
|
|
21
|
+
mkdirSync(jsonDir, { recursive: true })
|
|
22
|
+
mkdirSync(promptsDir, { recursive: true })
|
|
23
|
+
mkdirSync(join(registryDir, 'components'), { recursive: true })
|
|
24
|
+
mkdirSync(join(registryDir, 'machines'), { recursive: true })
|
|
25
|
+
|
|
26
|
+
writeFileSync(join(jsonDir, 'catalog.json'), `${JSON.stringify(catalog, null, 2)}\n`)
|
|
27
|
+
|
|
28
|
+
for (const [id, schema] of Object.entries(componentSchemas)) {
|
|
29
|
+
writeFileSync(join(jsonDir, `${id}.json`), `${JSON.stringify(schema, null, 2)}\n`)
|
|
30
|
+
writeFileSync(join(registryDir, 'components', `${id}.json`), `${JSON.stringify(schema, null, 2)}\n`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const machines = {
|
|
34
|
+
async: asyncMachine,
|
|
35
|
+
buttonLifecycle: buttonLifecycleMachine,
|
|
36
|
+
dialog: dialogMachine,
|
|
37
|
+
field: fieldMachine,
|
|
38
|
+
} as const
|
|
39
|
+
|
|
40
|
+
for (const [id, machine] of Object.entries(machines)) {
|
|
41
|
+
const schema = aeonToSchema(machine)
|
|
42
|
+
writeFileSync(join(registryDir, 'machines', `${id}.json`), `${JSON.stringify(schema, null, 2)}\n`)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
writeFileSync(join(registryDir, 'catalog.json'), `${JSON.stringify(registryCatalog, null, 2)}\n`)
|
|
46
|
+
|
|
47
|
+
writeFileSync(join(promptsDir, 'system.md'), `${AEON_SYSTEM_PROMPT.trim()}\n`)
|
|
48
|
+
writeFileSync(join(promptsDir, 'cursorrules.md'), `${CURSOR_RULES_SNIPPET.trim()}\n`)
|
|
49
|
+
writeFileSync(
|
|
50
|
+
join(promptsDir, 'statecharts.md'),
|
|
51
|
+
`# Aeon UI statecharts (agent prompts)\n\n${Object.values(STATECHART_PROMPTS).join('\n\n')}\n`,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
mkdirSync(demoRegistry, { recursive: true })
|
|
55
|
+
if (existsSync(registryDir)) {
|
|
56
|
+
cpSync(registryDir, demoRegistry, { recursive: true })
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
console.log(
|
|
60
|
+
`Emitted ${Object.keys(componentSchemas).length} schemas + ${Object.keys(machines).length} machines → registry/ (+ demo public)`,
|
|
61
|
+
)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { createActor } from 'xstate'
|
|
3
|
+
import { asyncMachine, buttonLifecycleMachine } from '@aeon-ui/primitives'
|
|
4
|
+
import { aeonSnapshotSchema, aeonToPrompt, aeonToSchema } from './aeon-to-schema.js'
|
|
5
|
+
import { createAgentEventBridge } from './agent-bridge.js'
|
|
6
|
+
|
|
7
|
+
describe('aeonToSchema', () => {
|
|
8
|
+
it('builds a hierarchical state tree for async', () => {
|
|
9
|
+
const schema = aeonToSchema(asyncMachine)
|
|
10
|
+
expect(schema.id).toBe('async')
|
|
11
|
+
expect(schema.events).toEqual(expect.arrayContaining(['FETCH', 'RESOLVE', 'REJECT', 'RESET']))
|
|
12
|
+
expect(schema.tree.children.map((c) => c.key)).toEqual(
|
|
13
|
+
expect.arrayContaining(['idle', 'loading', 'success', 'failure', 'empty']),
|
|
14
|
+
)
|
|
15
|
+
const idle = schema.tree.children.find((c) => c.key === 'idle')
|
|
16
|
+
expect(idle?.events).toEqual(expect.arrayContaining(['FETCH', 'RESET']))
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('omits internal xstate.* events from the public tree', () => {
|
|
20
|
+
const schema = aeonToSchema(asyncMachine)
|
|
21
|
+
expect(schema.events.every((e) => !e.startsWith('xstate.'))).toBe(true)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('lists only valid events for the live snapshot', () => {
|
|
25
|
+
const actor = createActor(asyncMachine)
|
|
26
|
+
actor.start()
|
|
27
|
+
const live = aeonSnapshotSchema(asyncMachine, actor.getSnapshot())
|
|
28
|
+
expect(live.value).toBe('idle')
|
|
29
|
+
expect(live.validEvents).toEqual(expect.arrayContaining(['FETCH', 'RESET']))
|
|
30
|
+
expect(live.validEvents).not.toContain('RESOLVE')
|
|
31
|
+
actor.stop()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('produces a prompt with JSON tree', () => {
|
|
35
|
+
const prompt = aeonToPrompt(buttonLifecycleMachine)
|
|
36
|
+
expect(prompt).toContain('buttonLifecycle')
|
|
37
|
+
expect(prompt).toContain('```json')
|
|
38
|
+
expect(prompt).toContain('PRESS')
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
describe('createAgentEventBridge', () => {
|
|
43
|
+
it('maps AGENT_STREAM_START → FETCH and blocks illegal events', () => {
|
|
44
|
+
const actor = createActor(asyncMachine)
|
|
45
|
+
actor.start()
|
|
46
|
+
const illegal: string[] = []
|
|
47
|
+
const bridge = createAgentEventBridge(actor, {
|
|
48
|
+
map: {
|
|
49
|
+
AGENT_STREAM_START: 'FETCH',
|
|
50
|
+
AGENT_STREAM_ERROR: (e) =>
|
|
51
|
+
e.type === 'AGENT_STREAM_ERROR' ? { type: 'REJECT', error: e.error } : null,
|
|
52
|
+
},
|
|
53
|
+
onIllegal: (ev, reason) => illegal.push(`${ev.type}:${reason}`),
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
expect(bridge.push({ type: 'AGENT_STREAM_START' })).toBe(true)
|
|
57
|
+
expect(actor.getSnapshot().value).toBe('loading')
|
|
58
|
+
|
|
59
|
+
// RESOLVE is valid in loading — but AGENT_STREAM_ERROR maps to REJECT which is also valid
|
|
60
|
+
expect(bridge.push({ type: 'AGENT_STREAM_ERROR', error: 'boom' })).toBe(true)
|
|
61
|
+
expect(actor.getSnapshot().value).toBe('failure')
|
|
62
|
+
|
|
63
|
+
// FETCH is valid from failure
|
|
64
|
+
expect(bridge.push({ type: 'AGENT_STREAM_START' })).toBe(true)
|
|
65
|
+
expect(actor.getSnapshot().value).toBe('loading')
|
|
66
|
+
|
|
67
|
+
actor.stop()
|
|
68
|
+
expect(illegal).toEqual([])
|
|
69
|
+
})
|
|
70
|
+
})
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { AnyStateMachine, AnyStateNode, SnapshotFrom } from 'xstate'
|
|
2
|
+
import {
|
|
3
|
+
createActor,
|
|
4
|
+
getNextTransitions,
|
|
5
|
+
getStateNodes,
|
|
6
|
+
__unsafe_getAllOwnEventDescriptors,
|
|
7
|
+
} from 'xstate'
|
|
8
|
+
|
|
9
|
+
/** Hierarchical state-tree node for LLM / Generative UI consumption. */
|
|
10
|
+
export type AeonStateTreeNode = {
|
|
11
|
+
key: string
|
|
12
|
+
id: string
|
|
13
|
+
type: string
|
|
14
|
+
events: string[]
|
|
15
|
+
transitions: Array<{
|
|
16
|
+
event: string
|
|
17
|
+
target: string[]
|
|
18
|
+
guarded: boolean
|
|
19
|
+
}>
|
|
20
|
+
children: AeonStateTreeNode[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Deterministic statechart JSON an agent can read at any micro-moment. */
|
|
24
|
+
export type AeonMachineSchema = {
|
|
25
|
+
id: string
|
|
26
|
+
initial: string | undefined
|
|
27
|
+
events: string[]
|
|
28
|
+
tree: AeonStateTreeNode
|
|
29
|
+
/** Flat map: state id → events defined on that node */
|
|
30
|
+
states: Record<string, { events: string[]; type: string }>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type AeonSnapshotSchema = {
|
|
34
|
+
machineId: string
|
|
35
|
+
value: unknown
|
|
36
|
+
/** Event types valid from the active configuration (no getNextEvents in XState v5). */
|
|
37
|
+
validEvents: string[]
|
|
38
|
+
/** Transition rows including guard presence — agents should prefer unguarded or known payloads. */
|
|
39
|
+
nextTransitions: Array<{
|
|
40
|
+
event: string
|
|
41
|
+
target: string[]
|
|
42
|
+
guarded: boolean
|
|
43
|
+
}>
|
|
44
|
+
activeStateIds: string[]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isPublicEvent(event: string): boolean {
|
|
48
|
+
return !event.startsWith('xstate.')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function filterPublicEvents(events: readonly string[]): string[] {
|
|
52
|
+
return events.filter(isPublicEvent)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function walkNode(node: AnyStateNode): AeonStateTreeNode {
|
|
56
|
+
const on = node.config.on ?? {}
|
|
57
|
+
const transitionEntries = Object.entries(on as Record<string, unknown>)
|
|
58
|
+
.filter(([event]) => isPublicEvent(event))
|
|
59
|
+
.map(([event, def]) => {
|
|
60
|
+
const targets: string[] = []
|
|
61
|
+
const list = Array.isArray(def) ? def : [def]
|
|
62
|
+
let guarded = false
|
|
63
|
+
for (const item of list) {
|
|
64
|
+
if (item == null) continue
|
|
65
|
+
if (typeof item === 'string') {
|
|
66
|
+
targets.push(item)
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
if (typeof item === 'object') {
|
|
70
|
+
const row = item as { target?: string | string[]; guard?: unknown }
|
|
71
|
+
if (row.guard != null) guarded = true
|
|
72
|
+
if (typeof row.target === 'string') targets.push(row.target)
|
|
73
|
+
else if (Array.isArray(row.target)) targets.push(...row.target)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { event, target: targets, guarded }
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
key: node.key,
|
|
81
|
+
id: node.id,
|
|
82
|
+
type: node.type,
|
|
83
|
+
events: filterPublicEvents([...(node.events ?? [])]),
|
|
84
|
+
transitions: transitionEntries,
|
|
85
|
+
children: Object.values(node.states ?? {}).map(walkNode),
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function flattenNodes(node: AnyStateNode, out: AeonMachineSchema['states']) {
|
|
90
|
+
out[node.id] = {
|
|
91
|
+
events: filterPublicEvents([...(node.events ?? [])]),
|
|
92
|
+
type: node.type,
|
|
93
|
+
}
|
|
94
|
+
for (const child of Object.values(node.states ?? {})) {
|
|
95
|
+
flattenNodes(child, out)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Stringify an XState machine into a clean hierarchical state-tree JSON.
|
|
101
|
+
* Use this as the runtime contract for agents that must know which events
|
|
102
|
+
* (TOGGLE, SUBMIT, FETCH, …) are legal before calling `send`.
|
|
103
|
+
* Internal timers (`xstate.after.*`) are omitted — agents send public events only.
|
|
104
|
+
*/
|
|
105
|
+
export function aeonToSchema(machine: AnyStateMachine): AeonMachineSchema {
|
|
106
|
+
const tree = walkNode(machine.root)
|
|
107
|
+
const flat: AeonMachineSchema['states'] = {}
|
|
108
|
+
flattenNodes(machine.root, flat)
|
|
109
|
+
|
|
110
|
+
const initial =
|
|
111
|
+
typeof machine.config.initial === 'string' ? machine.config.initial : undefined
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
id: machine.id,
|
|
115
|
+
initial,
|
|
116
|
+
events: filterPublicEvents([...(machine.events ?? [])]),
|
|
117
|
+
tree,
|
|
118
|
+
states: flat,
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Snapshot-aware companion to `aeonToSchema`.
|
|
124
|
+
* Call whenever the actor advances so the LLM only proposes legal next events.
|
|
125
|
+
*/
|
|
126
|
+
export function aeonSnapshotSchema(
|
|
127
|
+
machine: AnyStateMachine,
|
|
128
|
+
snapshot: SnapshotFrom<AnyStateMachine>,
|
|
129
|
+
): AeonSnapshotSchema {
|
|
130
|
+
const active = getStateNodes(machine.root, snapshot.value)
|
|
131
|
+
const next = getNextTransitions(snapshot)
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
machineId: machine.id,
|
|
135
|
+
value: snapshot.value,
|
|
136
|
+
validEvents: [...__unsafe_getAllOwnEventDescriptors(snapshot)].filter(
|
|
137
|
+
(e) => !e.startsWith('xstate.'),
|
|
138
|
+
),
|
|
139
|
+
nextTransitions: next
|
|
140
|
+
.filter((t) => !t.eventType.startsWith('xstate.'))
|
|
141
|
+
.map((t) => ({
|
|
142
|
+
event: t.eventType,
|
|
143
|
+
target: (t.target ?? []).map((n) => n.id),
|
|
144
|
+
guarded: Boolean(t.guard),
|
|
145
|
+
})),
|
|
146
|
+
activeStateIds: active.map((n) => n.id),
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Turn a machine (+ optional live snapshot) into a deterministic system-prompt fragment.
|
|
152
|
+
*/
|
|
153
|
+
export function aeonToPrompt(
|
|
154
|
+
machine: AnyStateMachine,
|
|
155
|
+
snapshot?: SnapshotFrom<AnyStateMachine>,
|
|
156
|
+
): string {
|
|
157
|
+
const schema = aeonToSchema(machine)
|
|
158
|
+
const lines = [
|
|
159
|
+
`## Aeon statechart: ${schema.id}`,
|
|
160
|
+
`Initial: ${schema.initial ?? '(none)'}`,
|
|
161
|
+
`All events: ${schema.events.join(', ') || '(none)'}`,
|
|
162
|
+
'',
|
|
163
|
+
'### State tree (JSON)',
|
|
164
|
+
'```json',
|
|
165
|
+
JSON.stringify(schema.tree, null, 2),
|
|
166
|
+
'```',
|
|
167
|
+
'',
|
|
168
|
+
'Rules for agents:',
|
|
169
|
+
'- Only send event types listed under the *active* configuration.',
|
|
170
|
+
'- Never invent events or targets not present in this tree.',
|
|
171
|
+
'- Prefer events with guarded:false unless you can satisfy the guard payload.',
|
|
172
|
+
]
|
|
173
|
+
|
|
174
|
+
if (snapshot) {
|
|
175
|
+
const live = aeonSnapshotSchema(machine, snapshot)
|
|
176
|
+
lines.push(
|
|
177
|
+
'',
|
|
178
|
+
'### Live snapshot',
|
|
179
|
+
`- value: ${JSON.stringify(live.value)}`,
|
|
180
|
+
`- validEvents now: ${live.validEvents.join(', ') || '(none)'}`,
|
|
181
|
+
`- nextTransitions: ${JSON.stringify(live.nextTransitions)}`,
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return lines.join('\n')
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Convenience: start a throwaway actor at the initial state and return both
|
|
190
|
+
* static schema + snapshot schema for prompt injection.
|
|
191
|
+
*/
|
|
192
|
+
export function aeonInitialAgentContext(machine: AnyStateMachine): {
|
|
193
|
+
schema: AeonMachineSchema
|
|
194
|
+
snapshot: AeonSnapshotSchema
|
|
195
|
+
prompt: string
|
|
196
|
+
} {
|
|
197
|
+
const actor = createActor(machine)
|
|
198
|
+
actor.start()
|
|
199
|
+
const snap = actor.getSnapshot()
|
|
200
|
+
actor.stop()
|
|
201
|
+
return {
|
|
202
|
+
schema: aeonToSchema(machine),
|
|
203
|
+
snapshot: aeonSnapshotSchema(machine, snap),
|
|
204
|
+
prompt: aeonToPrompt(machine, snap),
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { AnyEventObject, AnyActorRef } from 'xstate'
|
|
2
|
+
|
|
3
|
+
/** Streaming / tool-loop events from an LLM or automation. */
|
|
4
|
+
export type AgentStreamEvent =
|
|
5
|
+
| { type: 'AGENT_STREAM_START'; taskId?: string }
|
|
6
|
+
| { type: 'AGENT_STREAM_CHUNK'; taskId?: string; data?: unknown }
|
|
7
|
+
| { type: 'AGENT_STREAM_END'; taskId?: string; data?: unknown }
|
|
8
|
+
| { type: 'AGENT_STREAM_ERROR'; taskId?: string; error: string }
|
|
9
|
+
| { type: 'AGENT_TOOL_CALL'; name: string; args?: unknown }
|
|
10
|
+
| { type: 'AGENT_TOOL_RESULT'; name: string; result?: unknown }
|
|
11
|
+
| { type: string; [key: string]: unknown }
|
|
12
|
+
|
|
13
|
+
export type AgentEventMap = Record<string, string | ((event: AgentStreamEvent) => AnyEventObject | null)>
|
|
14
|
+
|
|
15
|
+
export type AgentBridgeOptions = {
|
|
16
|
+
/**
|
|
17
|
+
* Map inbound agent event types → machine event types or transformers.
|
|
18
|
+
* Example: `{ AGENT_STREAM_START: 'FETCH', AGENT_STREAM_ERROR: (e) => ({ type: 'REJECT', error: e.error }) }`
|
|
19
|
+
*/
|
|
20
|
+
map: AgentEventMap
|
|
21
|
+
/** Optional filter — return false to drop the event. */
|
|
22
|
+
accept?: (event: AgentStreamEvent) => boolean
|
|
23
|
+
/** Called when a mapped event is not allowed by `snapshot.can` (if actor exposes getSnapshot). */
|
|
24
|
+
onIllegal?: (event: AnyEventObject, reason: string) => void
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type Sendable = {
|
|
28
|
+
send: (event: AnyEventObject) => void
|
|
29
|
+
getSnapshot?: () => { can: (event: AnyEventObject) => boolean }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Bind streaming LLM / tool-loop events to an Aeon machine actor.
|
|
34
|
+
* Prevents agents from firing transitions the chart will reject.
|
|
35
|
+
*/
|
|
36
|
+
export function createAgentEventBridge(actor: Sendable | AnyActorRef, options: AgentBridgeOptions) {
|
|
37
|
+
const { map, accept, onIllegal } = options
|
|
38
|
+
|
|
39
|
+
const resolve = (incoming: AgentStreamEvent): AnyEventObject | null => {
|
|
40
|
+
if (accept && !accept(incoming)) return null
|
|
41
|
+
const binding = map[incoming.type]
|
|
42
|
+
if (binding == null) return null
|
|
43
|
+
if (typeof binding === 'function') return binding(incoming)
|
|
44
|
+
return { type: binding }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const push = (incoming: AgentStreamEvent): boolean => {
|
|
48
|
+
const event = resolve(incoming)
|
|
49
|
+
if (!event) return false
|
|
50
|
+
|
|
51
|
+
const snap = typeof actor.getSnapshot === 'function' ? actor.getSnapshot() : undefined
|
|
52
|
+
if (snap && !snap.can(event)) {
|
|
53
|
+
onIllegal?.(event, `Event ${event.type} is not valid in the current configuration`)
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
actor.send(event)
|
|
58
|
+
return true
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
/** Push one agent/stream event through the map into `machine.send`. */
|
|
63
|
+
push,
|
|
64
|
+
/** Map of known agent → machine bindings (for prompts / docs). */
|
|
65
|
+
map,
|
|
66
|
+
/** Describe the bridge for system prompts. */
|
|
67
|
+
toPrompt(): string {
|
|
68
|
+
const rows = Object.entries(map).map(([from, to]) => {
|
|
69
|
+
const dest = typeof to === 'string' ? to : '(transform)'
|
|
70
|
+
return `- ${from} → ${dest}`
|
|
71
|
+
})
|
|
72
|
+
return [
|
|
73
|
+
'## Agent event bridge',
|
|
74
|
+
'Inbound stream events map to machine events:',
|
|
75
|
+
...rows,
|
|
76
|
+
'Illegal events (rejected by snapshot.can) are dropped.',
|
|
77
|
+
].join('\n')
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type AgentEventBridge = ReturnType<typeof createAgentEventBridge>
|