handoff-app-next 2.0.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Changelog.md +2069 -0
- package/License.md +19 -0
- package/README.md +461 -0
- package/components.json +21 -0
- package/config/config.template.js +95 -0
- package/config/config.template.ts +54 -0
- package/config/docs/design.md +14 -0
- package/config/docs/foundations/border-radius.md +6 -0
- package/config/docs/foundations/colors.md +7 -0
- package/config/docs/foundations/effects.md +8 -0
- package/config/docs/foundations/elevation.md +6 -0
- package/config/docs/foundations/focus.md +6 -0
- package/config/docs/foundations/fonts.md +7 -0
- package/config/docs/foundations/grid.md +21 -0
- package/config/docs/foundations/icon.md +6 -0
- package/config/docs/foundations/icons.md +6 -0
- package/config/docs/foundations/logo.md +7 -0
- package/config/docs/foundations/logos.md +7 -0
- package/config/docs/foundations/motion.md +6 -0
- package/config/docs/foundations/spacing.md +7 -0
- package/config/docs/foundations/typography.md +8 -0
- package/config/docs/foundations.md +44 -0
- package/config/docs/guidelines.md +11 -0
- package/config/docs/index.md +9 -0
- package/config/docs/playground.md +14 -0
- package/config/docs/system/figma-sync.md +14 -0
- package/config/docs/system/tokens/foundations/colors.md +24 -0
- package/config/docs/system/tokens/foundations/effects.md +21 -0
- package/config/docs/system/tokens/foundations/spacing.md +22 -0
- package/config/docs/system/tokens/foundations/typography.md +24 -0
- package/config/docs/system.md +13 -0
- package/config/templates/component/template.hbs +6 -0
- package/config/templates/component/template.js +0 -0
- package/config/templates/component/template.json +45 -0
- package/config/templates/component/template.scss +2 -0
- package/config/templates/page.md +11 -0
- package/config/templates/page.mdx +49 -0
- package/config/templates/template.html +7 -0
- package/dist/app/components/Component/Cards.d.ts +25 -0
- package/dist/app/components/Component/Cards.jsx +27 -0
- package/dist/app/lib/adapter-kit/types.d.ts +581 -0
- package/dist/app/lib/adapter-kit/types.js +36 -0
- package/dist/app/lib/hubspot-field-map.d.ts +170 -0
- package/dist/app/lib/hubspot-field-map.js +538 -0
- package/dist/app/lib/hubspot-module/build-module.d.ts +136 -0
- package/dist/app/lib/hubspot-module/build-module.js +122 -0
- package/dist/app/lib/hubspot-module/context.d.ts +111 -0
- package/dist/app/lib/hubspot-module/context.js +228 -0
- package/dist/app/lib/hubspot-module/fields/boolean.d.ts +8 -0
- package/dist/app/lib/hubspot-module/fields/boolean.js +22 -0
- package/dist/app/lib/hubspot-module/fields/button.d.ts +19 -0
- package/dist/app/lib/hubspot-module/fields/button.js +66 -0
- package/dist/app/lib/hubspot-module/fields/fields.d.ts +20 -0
- package/dist/app/lib/hubspot-module/fields/fields.js +93 -0
- package/dist/app/lib/hubspot-module/fields/generic.d.ts +33 -0
- package/dist/app/lib/hubspot-module/fields/generic.js +150 -0
- package/dist/app/lib/hubspot-module/fields/hubdb.d.ts +14 -0
- package/dist/app/lib/hubspot-module/fields/hubdb.js +155 -0
- package/dist/app/lib/hubspot-module/fields/image.d.ts +27 -0
- package/dist/app/lib/hubspot-module/fields/image.js +59 -0
- package/dist/app/lib/hubspot-module/fields/menu.d.ts +8 -0
- package/dist/app/lib/hubspot-module/fields/menu.js +12 -0
- package/dist/app/lib/hubspot-module/fields/object.d.ts +11 -0
- package/dist/app/lib/hubspot-module/fields/object.js +31 -0
- package/dist/app/lib/hubspot-module/fields/select.d.ts +17 -0
- package/dist/app/lib/hubspot-module/fields/select.js +37 -0
- package/dist/app/lib/hubspot-module/fields/text.d.ts +15 -0
- package/dist/app/lib/hubspot-module/fields/text.js +63 -0
- package/dist/app/lib/hubspot-module/fields/url.d.ts +35 -0
- package/dist/app/lib/hubspot-module/fields/url.js +57 -0
- package/dist/app/lib/hubspot-module/fields/utils.d.ts +20 -0
- package/dist/app/lib/hubspot-module/fields/utils.js +33 -0
- package/dist/app/lib/hubspot-module/fields/video.d.ts +21 -0
- package/dist/app/lib/hubspot-module/fields/video.js +70 -0
- package/dist/app/lib/hubspot-module/index.d.ts +20 -0
- package/dist/app/lib/hubspot-module/index.js +17 -0
- package/dist/app/lib/hubspot-module/transpile.d.ts +27 -0
- package/dist/app/lib/hubspot-module/transpile.js +658 -0
- package/dist/app/lib/hubspot-module/types.d.ts +204 -0
- package/dist/app/lib/hubspot-module/types.js +47 -0
- package/dist/app/lib/hubspot-module-build.d.ts +33 -0
- package/dist/app/lib/hubspot-module-build.js +41 -0
- package/dist/app-builder/build.d.ts +21 -0
- package/dist/app-builder/build.js +649 -0
- package/dist/app-builder/client-config.d.ts +17 -0
- package/dist/app-builder/client-config.js +106 -0
- package/dist/app-builder/config-diff/index.d.ts +4 -0
- package/dist/app-builder/config-diff/index.js +3 -0
- package/dist/app-builder/config-diff/registry.d.ts +9 -0
- package/dist/app-builder/config-diff/registry.js +15 -0
- package/dist/app-builder/config-diff/snapshot.d.ts +13 -0
- package/dist/app-builder/config-diff/snapshot.js +38 -0
- package/dist/app-builder/config-diff/strategies/pattern.d.ts +2 -0
- package/dist/app-builder/config-diff/strategies/pattern.js +66 -0
- package/dist/app-builder/config-diff/types.d.ts +33 -0
- package/dist/app-builder/config-diff/types.js +1 -0
- package/dist/app-builder/index.d.ts +6 -0
- package/dist/app-builder/index.js +4 -0
- package/dist/app-builder/path-contract.d.ts +23 -0
- package/dist/app-builder/path-contract.js +60 -0
- package/dist/app-builder/paths.d.ts +24 -0
- package/dist/app-builder/paths.js +82 -0
- package/dist/app-builder/watchers/component.d.ts +15 -0
- package/dist/app-builder/watchers/component.js +58 -0
- package/dist/app-builder/watchers/utils.d.ts +14 -0
- package/dist/app-builder/watchers/utils.js +31 -0
- package/dist/app-builder/watchers.d.ts +44 -0
- package/dist/app-builder/watchers.js +299 -0
- package/dist/app-builder/websocket.d.ts +12 -0
- package/dist/app-builder/websocket.js +56 -0
- package/dist/cache/build-cache.d.ts +169 -0
- package/dist/cache/build-cache.js +421 -0
- package/dist/cache/file-state.d.ts +58 -0
- package/dist/cache/file-state.js +122 -0
- package/dist/cache/index.d.ts +3 -0
- package/dist/cache/index.js +6 -0
- package/dist/cache/push-state.d.ts +69 -0
- package/dist/cache/push-state.js +156 -0
- package/dist/cli/create.d.ts +5 -0
- package/dist/cli/create.js +301 -0
- package/dist/cli/eject.d.ts +17 -0
- package/dist/cli/eject.js +82 -0
- package/dist/cli/fetch-design-md.d.ts +14 -0
- package/dist/cli/fetch-design-md.js +62 -0
- package/dist/cli/figma-audit.d.ts +7 -0
- package/dist/cli/figma-audit.js +55 -0
- package/dist/cli/init-claude-core.d.ts +26 -0
- package/dist/cli/init-claude-core.js +81 -0
- package/dist/cli/make.d.ts +12 -0
- package/dist/cli/make.js +178 -0
- package/dist/cli/scaffold.d.ts +5 -0
- package/dist/cli/scaffold.js +504 -0
- package/dist/cli/sync/apply-declaration-pull.d.ts +14 -0
- package/dist/cli/sync/apply-declaration-pull.js +184 -0
- package/dist/cli/sync/apply-pull.d.ts +24 -0
- package/dist/cli/sync/apply-pull.js +174 -0
- package/dist/cli/sync/cli-auth-store.d.ts +12 -0
- package/dist/cli/sync/cli-auth-store.js +44 -0
- package/dist/cli/sync/collect-build-artifacts.d.ts +17 -0
- package/dist/cli/sync/collect-build-artifacts.js +143 -0
- package/dist/cli/sync/collect-referenced-images.d.ts +36 -0
- package/dist/cli/sync/collect-referenced-images.js +165 -0
- package/dist/cli/sync/declaration-patch.d.ts +9 -0
- package/dist/cli/sync/declaration-patch.js +196 -0
- package/dist/cli/sync/hash.d.ts +2 -0
- package/dist/cli/sync/hash.js +11 -0
- package/dist/cli/sync/open-browser.d.ts +5 -0
- package/dist/cli/sync/open-browser.js +37 -0
- package/dist/cli/sync/push-provenance.d.ts +25 -0
- package/dist/cli/sync/push-provenance.js +82 -0
- package/dist/cli/sync/push-registry-content.d.ts +132 -0
- package/dist/cli/sync/push-registry-content.js +854 -0
- package/dist/cli/sync/push-shared-assets.d.ts +26 -0
- package/dist/cli/sync/push-shared-assets.js +33 -0
- package/dist/cli/sync/resolve-declaration-payload.d.ts +8 -0
- package/dist/cli/sync/resolve-declaration-payload.js +208 -0
- package/dist/cli/sync/resolve-declaration.d.ts +5 -0
- package/dist/cli/sync/resolve-declaration.js +12 -0
- package/dist/cli/sync/run-cli-login.d.ts +9 -0
- package/dist/cli/sync/run-cli-login.js +81 -0
- package/dist/cli/sync/run-history-purge.d.ts +19 -0
- package/dist/cli/sync/run-history-purge.js +112 -0
- package/dist/cli/sync/run-pull.d.ts +9 -0
- package/dist/cli/sync/run-pull.js +92 -0
- package/dist/cli/sync/run-push.d.ts +47 -0
- package/dist/cli/sync/run-push.js +585 -0
- package/dist/cli/sync/run-sync-status.d.ts +2 -0
- package/dist/cli/sync/run-sync-status.js +30 -0
- package/dist/cli/sync/sync-remote-env.d.ts +14 -0
- package/dist/cli/sync/sync-remote-env.js +52 -0
- package/dist/cli/sync/sync-state.d.ts +15 -0
- package/dist/cli/sync/sync-state.js +26 -0
- package/dist/cli/tokens/ensure-default-brand.d.ts +18 -0
- package/dist/cli/tokens/ensure-default-brand.js +95 -0
- package/dist/cli/tokens/migrate-legacy.d.ts +23 -0
- package/dist/cli/tokens/migrate-legacy.js +213 -0
- package/dist/cli/tokens/parse-css-brands.d.ts +25 -0
- package/dist/cli/tokens/parse-css-brands.js +148 -0
- package/dist/cli/tokens/transform.d.ts +12 -0
- package/dist/cli/tokens/transform.js +126 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +56 -0
- package/dist/commands/audit/figma-components.d.ts +8 -0
- package/dist/commands/audit/figma-components.js +27 -0
- package/dist/commands/build/app.d.ts +8 -0
- package/dist/commands/build/app.js +22 -0
- package/dist/commands/build/components.d.ts +7 -0
- package/dist/commands/build/components.js +17 -0
- package/dist/commands/build/hubspot.d.ts +56 -0
- package/dist/commands/build/hubspot.js +177 -0
- package/dist/commands/dev/index.d.ts +6 -0
- package/dist/commands/dev/index.js +14 -0
- package/dist/commands/eject/config.d.ts +6 -0
- package/dist/commands/eject/config.js +14 -0
- package/dist/commands/eject/pages.d.ts +6 -0
- package/dist/commands/eject/pages.js +14 -0
- package/dist/commands/eject/theme.d.ts +6 -0
- package/dist/commands/eject/theme.js +14 -0
- package/dist/commands/fetch/index.d.ts +6 -0
- package/dist/commands/fetch/index.js +14 -0
- package/dist/commands/history-purge.d.ts +19 -0
- package/dist/commands/history-purge.js +52 -0
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.js +66 -0
- package/dist/commands/init/index.d.ts +5 -0
- package/dist/commands/init/index.js +12 -0
- package/dist/commands/init/vercel.d.ts +6 -0
- package/dist/commands/init/vercel.js +99 -0
- package/dist/commands/init-claude.d.ts +9 -0
- package/dist/commands/init-claude.js +47 -0
- package/dist/commands/login.d.ts +9 -0
- package/dist/commands/login.js +28 -0
- package/dist/commands/logout.d.ts +6 -0
- package/dist/commands/logout.js +16 -0
- package/dist/commands/make/component.d.ts +7 -0
- package/dist/commands/make/component.js +23 -0
- package/dist/commands/make/page.d.ts +8 -0
- package/dist/commands/make/page.js +33 -0
- package/dist/commands/make/template.d.ts +8 -0
- package/dist/commands/make/template.js +33 -0
- package/dist/commands/mcp-init.d.ts +12 -0
- package/dist/commands/mcp-init.js +94 -0
- package/dist/commands/mcp-token.d.ts +7 -0
- package/dist/commands/mcp-token.js +23 -0
- package/dist/commands/prepare-runtime.d.ts +7 -0
- package/dist/commands/prepare-runtime.js +28 -0
- package/dist/commands/pull.d.ts +7 -0
- package/dist/commands/pull.js +18 -0
- package/dist/commands/push-all.d.ts +23 -0
- package/dist/commands/push-all.js +146 -0
- package/dist/commands/push-assets.d.ts +8 -0
- package/dist/commands/push-assets.js +40 -0
- package/dist/commands/push-tokens.d.ts +8 -0
- package/dist/commands/push-tokens.js +40 -0
- package/dist/commands/push.d.ts +14 -0
- package/dist/commands/push.js +75 -0
- package/dist/commands/scaffold/index.d.ts +6 -0
- package/dist/commands/scaffold/index.js +15 -0
- package/dist/commands/start/index.d.ts +6 -0
- package/dist/commands/start/index.js +14 -0
- package/dist/commands/sync-status.d.ts +6 -0
- package/dist/commands/sync-status.js +14 -0
- package/dist/commands/tokens-build.d.ts +7 -0
- package/dist/commands/tokens-build.js +104 -0
- package/dist/commands/types.d.ts +5 -0
- package/dist/commands/types.js +1 -0
- package/dist/commands/utils.d.ts +18 -0
- package/dist/commands/utils.js +19 -0
- package/dist/commands/validate/components.d.ts +7 -0
- package/dist/commands/validate/components.js +19 -0
- package/dist/commands/validate.d.ts +11 -0
- package/dist/commands/validate.js +163 -0
- package/dist/commands/vercel-build.d.ts +7 -0
- package/dist/commands/vercel-build.js +81 -0
- package/dist/config/declaration-module-load.d.ts +6 -0
- package/dist/config/declaration-module-load.js +68 -0
- package/dist/config/defaults.d.ts +16 -0
- package/dist/config/defaults.js +60 -0
- package/dist/config/helpers.d.ts +7 -0
- package/dist/config/helpers.js +29 -0
- package/dist/config/index.d.ts +7 -0
- package/dist/config/index.js +11 -0
- package/dist/config/loader.d.ts +20 -0
- package/dist/config/loader.js +107 -0
- package/dist/config/normalizers/declaration.d.ts +11 -0
- package/dist/config/normalizers/declaration.js +122 -0
- package/dist/config/normalizers/pattern.d.ts +8 -0
- package/dist/config/normalizers/pattern.js +31 -0
- package/dist/config/runtime.d.ts +42 -0
- package/dist/config/runtime.js +337 -0
- package/dist/config/validator.d.ts +9 -0
- package/dist/config/validator.js +22 -0
- package/dist/declarations/codegen.d.ts +57 -0
- package/dist/declarations/codegen.js +279 -0
- package/dist/declarations/helpers.d.ts +6 -0
- package/dist/declarations/helpers.js +20 -0
- package/dist/declarations/index.d.ts +2 -0
- package/dist/declarations/index.js +1 -0
- package/dist/declarations/types.d.ts +193 -0
- package/dist/declarations/types.js +1 -0
- package/dist/figma/component-linking.d.ts +164 -0
- package/dist/figma/component-linking.js +1080 -0
- package/dist/figma/image-fills.d.ts +32 -0
- package/dist/figma/image-fills.js +211 -0
- package/dist/generated/build-meta.d.ts +4 -0
- package/dist/generated/build-meta.js +6 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +301 -0
- package/dist/pipeline/archive.d.ts +19 -0
- package/dist/pipeline/archive.js +62 -0
- package/dist/pipeline/components.d.ts +5 -0
- package/dist/pipeline/components.js +7 -0
- package/dist/pipeline/documentation.d.ts +3 -0
- package/dist/pipeline/documentation.js +64 -0
- package/dist/pipeline/figma.d.ts +11 -0
- package/dist/pipeline/figma.js +142 -0
- package/dist/pipeline/hubspot/config.d.ts +179 -0
- package/dist/pipeline/hubspot/config.js +171 -0
- package/dist/pipeline/hubspot/emit.d.ts +101 -0
- package/dist/pipeline/hubspot/emit.js +283 -0
- package/dist/pipeline/index.d.ts +14 -0
- package/dist/pipeline/index.js +34 -0
- package/dist/pipeline/patterns.d.ts +8 -0
- package/dist/pipeline/patterns.js +8 -0
- package/dist/pipeline/styles.d.ts +10 -0
- package/dist/pipeline/styles.js +127 -0
- package/dist/pipeline/validation.d.ts +6 -0
- package/dist/pipeline/validation.js +23 -0
- package/dist/transformers/docgen/index.d.ts +24 -0
- package/dist/transformers/docgen/index.js +244 -0
- package/dist/transformers/plugins/csf-render.d.ts +5 -0
- package/dist/transformers/plugins/csf-render.js +406 -0
- package/dist/transformers/plugins/handlebars-previews.d.ts +12 -0
- package/dist/transformers/plugins/handlebars-previews.js +128 -0
- package/dist/transformers/plugins/index.d.ts +11 -0
- package/dist/transformers/plugins/index.js +10 -0
- package/dist/transformers/plugins/slot-probe-candidates.d.ts +159 -0
- package/dist/transformers/plugins/slot-probe-candidates.js +279 -0
- package/dist/transformers/plugins/slot-probe.d.ts +66 -0
- package/dist/transformers/plugins/slot-probe.js +298 -0
- package/dist/transformers/plugins/ssr-render.d.ts +33 -0
- package/dist/transformers/plugins/ssr-render.js +531 -0
- package/dist/transformers/plugins.d.ts +14 -0
- package/dist/transformers/plugins.js +15 -0
- package/dist/transformers/preview/component/api.d.ts +22 -0
- package/dist/transformers/preview/component/api.js +146 -0
- package/dist/transformers/preview/component/artifacts.d.ts +3 -0
- package/dist/transformers/preview/component/artifacts.js +103 -0
- package/dist/transformers/preview/component/build-shared-bundles.d.ts +83 -0
- package/dist/transformers/preview/component/build-shared-bundles.js +400 -0
- package/dist/transformers/preview/component/builder.d.ts +29 -0
- package/dist/transformers/preview/component/builder.js +638 -0
- package/dist/transformers/preview/component/css.d.ts +68 -0
- package/dist/transformers/preview/component/css.js +219 -0
- package/dist/transformers/preview/component/field-annotations.d.ts +129 -0
- package/dist/transformers/preview/component/field-annotations.js +325 -0
- package/dist/transformers/preview/component/html.d.ts +21 -0
- package/dist/transformers/preview/component/html.js +80 -0
- package/dist/transformers/preview/component/javascript.d.ts +24 -0
- package/dist/transformers/preview/component/javascript.js +162 -0
- package/dist/transformers/preview/component/normalizer.d.ts +35 -0
- package/dist/transformers/preview/component/normalizer.js +56 -0
- package/dist/transformers/preview/component/playwright-shared.d.ts +70 -0
- package/dist/transformers/preview/component/playwright-shared.js +164 -0
- package/dist/transformers/preview/component/preview-assets.d.ts +55 -0
- package/dist/transformers/preview/component/preview-assets.js +144 -0
- package/dist/transformers/preview/component/preview-merge.d.ts +53 -0
- package/dist/transformers/preview/component/preview-merge.js +50 -0
- package/dist/transformers/preview/component/preview-select.d.ts +86 -0
- package/dist/transformers/preview/component/preview-select.js +150 -0
- package/dist/transformers/preview/component/preview-server.d.ts +41 -0
- package/dist/transformers/preview/component/preview-server.js +112 -0
- package/dist/transformers/preview/component/preview-validation.d.ts +64 -0
- package/dist/transformers/preview/component/preview-validation.js +194 -0
- package/dist/transformers/preview/component/previews.d.ts +9 -0
- package/dist/transformers/preview/component/previews.js +6 -0
- package/dist/transformers/preview/component/screenshot.d.ts +90 -0
- package/dist/transformers/preview/component/screenshot.js +282 -0
- package/dist/transformers/preview/component/serialized-elements.d.ts +86 -0
- package/dist/transformers/preview/component/serialized-elements.js +118 -0
- package/dist/transformers/preview/component/summary.d.ts +6 -0
- package/dist/transformers/preview/component/summary.js +41 -0
- package/dist/transformers/preview/component.d.ts +13 -0
- package/dist/transformers/preview/component.js +26 -0
- package/dist/transformers/preview/height-reporter.d.ts +27 -0
- package/dist/transformers/preview/height-reporter.js +32 -0
- package/dist/transformers/preview/pattern/api.d.ts +11 -0
- package/dist/transformers/preview/pattern/api.js +58 -0
- package/dist/transformers/preview/pattern/builder.d.ts +17 -0
- package/dist/transformers/preview/pattern/builder.js +149 -0
- package/dist/transformers/preview/pattern/html.d.ts +25 -0
- package/dist/transformers/preview/pattern/html.js +95 -0
- package/dist/transformers/preview/slots.d.ts +109 -0
- package/dist/transformers/preview/slots.js +13 -0
- package/dist/transformers/preview/types.d.ts +292 -0
- package/dist/transformers/preview/types.js +7 -0
- package/dist/transformers/types.d.ts +60 -0
- package/dist/transformers/types.js +1 -0
- package/dist/transformers/utils/build.d.ts +27 -0
- package/dist/transformers/utils/build.js +77 -0
- package/dist/transformers/utils/csf.d.ts +16 -0
- package/dist/transformers/utils/csf.js +29 -0
- package/dist/transformers/utils/handlebars.d.ts +32 -0
- package/dist/transformers/utils/handlebars.js +73 -0
- package/dist/transformers/utils/html.d.ts +18 -0
- package/dist/transformers/utils/html.js +40 -0
- package/dist/transformers/utils/index.d.ts +13 -0
- package/dist/transformers/utils/index.js +20 -0
- package/dist/transformers/utils/module.d.ts +13 -0
- package/dist/transformers/utils/module.js +41 -0
- package/dist/transformers/utils/schema-loader.d.ts +19 -0
- package/dist/transformers/utils/schema-loader.js +61 -0
- package/dist/transformers/utils/schema.d.ts +33 -0
- package/dist/transformers/utils/schema.js +517 -0
- package/dist/transformers/utils/string.d.ts +36 -0
- package/dist/transformers/utils/string.js +52 -0
- package/dist/transformers/utils/svg-sprite.d.ts +16 -0
- package/dist/transformers/utils/svg-sprite.js +114 -0
- package/dist/transformers/utils/usage.d.ts +23 -0
- package/dist/transformers/utils/usage.js +282 -0
- package/dist/transformers/utils/vite-logger.d.ts +2 -0
- package/dist/transformers/utils/vite-logger.js +30 -0
- package/dist/transformers/validation/runner.d.ts +67 -0
- package/dist/transformers/validation/runner.js +277 -0
- package/dist/transformers/vite-config.d.ts +3 -0
- package/dist/transformers/vite-config.js +18 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/config.d.ts +472 -0
- package/dist/types/config.js +1 -0
- package/dist/types/font.d.ts +3 -0
- package/dist/types/font.js +1 -0
- package/dist/types/handoff-sync.d.ts +132 -0
- package/dist/types/handoff-sync.js +5 -0
- package/dist/types/history-purge.d.ts +112 -0
- package/dist/types/history-purge.js +18 -0
- package/dist/types/icon.d.ts +8 -0
- package/dist/types/icon.js +1 -0
- package/dist/types/preview.d.ts +138 -0
- package/dist/types/preview.js +1 -0
- package/dist/types/validation.d.ts +200 -0
- package/dist/types/validation.js +11 -0
- package/dist/utils/asset-upload-limits.d.ts +87 -0
- package/dist/utils/asset-upload-limits.js +129 -0
- package/dist/utils/design-md.d.ts +55 -0
- package/dist/utils/design-md.js +107 -0
- package/dist/utils/duration.d.ts +2 -0
- package/dist/utils/duration.js +2 -0
- package/dist/utils/filter.d.ts +31 -0
- package/dist/utils/filter.js +109 -0
- package/dist/utils/fs.d.ts +8 -0
- package/dist/utils/fs.js +31 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/line-diff.d.ts +25 -0
- package/dist/utils/line-diff.js +74 -0
- package/dist/utils/logger.d.ts +50 -0
- package/dist/utils/logger.js +158 -0
- package/dist/utils/path.d.ts +21 -0
- package/dist/utils/path.js +50 -0
- package/dist/utils/port.d.ts +15 -0
- package/dist/utils/port.js +38 -0
- package/dist/utils/rich-text.d.ts +228 -0
- package/dist/utils/rich-text.js +1087 -0
- package/dist/validators/axe.d.ts +47 -0
- package/dist/validators/axe.js +222 -0
- package/dist/validators/contrast.d.ts +33 -0
- package/dist/validators/contrast.js +235 -0
- package/dist/validators/index.d.ts +30 -0
- package/dist/validators/index.js +26 -0
- package/dist/validators/schema.d.ts +34 -0
- package/dist/validators/schema.js +138 -0
- package/docs/DEPENDENCIES.md +26 -0
- package/docs/DEPLOYMENT.md +110 -0
- package/docs/LOCAL-RIG.md +305 -0
- package/docs/README.md +15 -0
- package/docs/REGISTRY-SETUP.md +353 -0
- package/docs/STANDALONE-INSTALL.md +70 -0
- package/docs/WORKSPACE-PACKAGE-JSON.md +125 -0
- package/docs/api.md +657 -0
- package/docs/api_spec.yaml +450 -0
- package/docs/cli.md +86 -0
- package/docs/schemas/component.schema.json +167 -0
- package/docs/schemas/examples/button.json +83 -0
- package/drizzle.config.ts +10 -0
- package/package.json +271 -0
- package/postcss.config.mjs +8 -0
- package/scripts/assert-standalone-install.mjs +60 -0
- package/src/app/app/[...slug]/DocCatchAllClient.tsx +103 -0
- package/src/app/app/[...slug]/page.tsx +101 -0
- package/src/app/app/account/AccountClient.tsx +116 -0
- package/src/app/app/account/IntegrationsSection.tsx +273 -0
- package/src/app/app/account/SanityCard.tsx +473 -0
- package/src/app/app/account/ai-cost/page.tsx +141 -0
- package/src/app/app/account/appearance/AppearanceClient.tsx +433 -0
- package/src/app/app/account/appearance/page.tsx +52 -0
- package/src/app/app/account/integrations/page.tsx +37 -0
- package/src/app/app/account/layout.tsx +82 -0
- package/src/app/app/account/page.tsx +41 -0
- package/src/app/app/account/users/UsersClient.tsx +244 -0
- package/src/app/app/account/users/page.tsx +36 -0
- package/src/app/app/actions/ai-generate.ts +25 -0
- package/src/app/app/actions/components.ts +126 -0
- package/src/app/app/actions/patterns.ts +289 -0
- package/src/app/app/admin/ai-cost/AiCostClient.tsx +236 -0
- package/src/app/app/admin/ai-cost/page.tsx +56 -0
- package/src/app/app/admin/builds/BuildsClient.tsx +527 -0
- package/src/app/app/admin/builds/page.tsx +41 -0
- package/src/app/app/admin/integrations/page.tsx +32 -0
- package/src/app/app/admin/pages/PagesClient.tsx +282 -0
- package/src/app/app/admin/pages/edit/PageEditorClient.tsx +157 -0
- package/src/app/app/admin/pages/edit/page.tsx +48 -0
- package/src/app/app/admin/pages/page.tsx +31 -0
- package/src/app/app/admin/protection/ProtectionClient.tsx +235 -0
- package/src/app/app/admin/protection/page.tsx +33 -0
- package/src/app/app/admin/reference/ReferenceClient.tsx +150 -0
- package/src/app/app/admin/reference/page.tsx +38 -0
- package/src/app/app/admin/users/page.tsx +11 -0
- package/src/app/app/api/account/route.ts +36 -0
- package/src/app/app/api/admin/builds/status/route.ts +34 -0
- package/src/app/app/api/admin/cleanup-versions/route.ts +64 -0
- package/src/app/app/api/admin/contract-limit-audit/route.ts +126 -0
- package/src/app/app/api/admin/contract-render-audit/route.ts +116 -0
- package/src/app/app/api/admin/field-bridge-audit/route.ts +152 -0
- package/src/app/app/api/admin/migrate/route.ts +47 -0
- package/src/app/app/api/admin/playground-turns/route.ts +85 -0
- package/src/app/app/api/admin/purge-history/route.ts +119 -0
- package/src/app/app/api/auth/[...nextauth]/route.ts +30 -0
- package/src/app/app/api/component/[...path]/route.ts +141 -0
- package/src/app/app/api/component-artifact/[...path]/route.ts +18 -0
- package/src/app/app/api/components/route.ts +78 -0
- package/src/app/app/api/figma-plugin/auth/device/route.ts +40 -0
- package/src/app/app/api/figma-plugin/auth/revoke/route.ts +15 -0
- package/src/app/app/api/figma-plugin/auth/token/route.ts +50 -0
- package/src/app/app/api/figma-plugin/foundations/commit/route.ts +111 -0
- package/src/app/app/api/figma-plugin/foundations/preview/route.ts +69 -0
- package/src/app/app/api/figma-plugin/foundations/route.ts +49 -0
- package/src/app/app/api/handoff/admin/appearance/route.ts +80 -0
- package/src/app/app/api/handoff/admin/backfill-artifact-blobs/route.ts +48 -0
- package/src/app/app/api/handoff/admin/build-tasks/kill/route.ts +43 -0
- package/src/app/app/api/handoff/admin/build-tasks/route.ts +21 -0
- package/src/app/app/api/handoff/admin/invite/route.ts +18 -0
- package/src/app/app/api/handoff/admin/normalize-previews/route.ts +107 -0
- package/src/app/app/api/handoff/admin/reference-materials/route.ts +69 -0
- package/src/app/app/api/handoff/admin/remove/route.ts +18 -0
- package/src/app/app/api/handoff/admin/resend-invite/route.ts +18 -0
- package/src/app/app/api/handoff/admin/role/route.ts +18 -0
- package/src/app/app/api/handoff/admin/users/route.ts +16 -0
- package/src/app/app/api/handoff/ai/analyze-layout-guide/route.ts +172 -0
- package/src/app/app/api/handoff/ai/analyze-layout-guide/wireframe-style/wireframe-example-1.png +0 -0
- package/src/app/app/api/handoff/ai/analyze-layout-guide/wireframe-style/wireframe-example-2.png +0 -0
- package/src/app/app/api/handoff/ai/chat/route.ts +217 -0
- package/src/app/app/api/handoff/ai/component-screenshot/route.ts +43 -0
- package/src/app/app/api/handoff/ai/debug-foundation-raster/route.ts +162 -0
- package/src/app/app/api/handoff/ai/design-artifact/[id]/clone/route.ts +68 -0
- package/src/app/app/api/handoff/ai/design-artifact/[id]/public/route.ts +37 -0
- package/src/app/app/api/handoff/ai/design-artifact/[id]/route.ts +99 -0
- package/src/app/app/api/handoff/ai/design-artifact/[id]/status/route.ts +44 -0
- package/src/app/app/api/handoff/ai/design-artifact/route.ts +405 -0
- package/src/app/app/api/handoff/ai/design-artifact-extract/route.ts +37 -0
- package/src/app/app/api/handoff/ai/design-generation-job/[id]/route.ts +67 -0
- package/src/app/app/api/handoff/ai/design-generation-jobs/route.ts +23 -0
- package/src/app/app/api/handoff/ai/design-jobs/run/route.ts +102 -0
- package/src/app/app/api/handoff/ai/extract-url/route.ts +34 -0
- package/src/app/app/api/handoff/ai/foundation-preview/route.ts +44 -0
- package/src/app/app/api/handoff/ai/generate-component/route.ts +137 -0
- package/src/app/app/api/handoff/ai/generate-design/route.ts +210 -0
- package/src/app/app/api/handoff/ai/generate-image/route.ts +72 -0
- package/src/app/app/api/handoff/ai/generate-pattern/route.ts +86 -0
- package/src/app/app/api/handoff/ai/playground-chat/refine/route.ts +52 -0
- package/src/app/app/api/handoff/ai/playground-chat/route.ts +102 -0
- package/src/app/app/api/handoff/ai/status/route.ts +14 -0
- package/src/app/app/api/handoff/artifact-asset/route.ts +88 -0
- package/src/app/app/api/handoff/assets/[id]/raw/route.ts +49 -0
- package/src/app/app/api/handoff/assets/[id]/route.ts +76 -0
- package/src/app/app/api/handoff/assets/collections/route.ts +54 -0
- package/src/app/app/api/handoff/assets/confirm/route.ts +80 -0
- package/src/app/app/api/handoff/assets/icon-sets/route.ts +47 -0
- package/src/app/app/api/handoff/assets/presign/route.ts +41 -0
- package/src/app/app/api/handoff/assets/route.ts +89 -0
- package/src/app/app/api/handoff/assets/upload/route.ts +152 -0
- package/src/app/app/api/handoff/assets/usages/[id]/route.ts +21 -0
- package/src/app/app/api/handoff/assets/usages/route.ts +69 -0
- package/src/app/app/api/handoff/auth/request-reset/route.ts +9 -0
- package/src/app/app/api/handoff/auth/reset-password/route.ts +17 -0
- package/src/app/app/api/handoff/capture/health/route.ts +86 -0
- package/src/app/app/api/handoff/capture/jobs/route.ts +75 -0
- package/src/app/app/api/handoff/capture/run/route.ts +112 -0
- package/src/app/app/api/handoff/changelog/pushes/route.ts +49 -0
- package/src/app/app/api/handoff/changelog/route.ts +28 -0
- package/src/app/app/api/handoff/changes/why/route.ts +41 -0
- package/src/app/app/api/handoff/cms/connections/route.ts +182 -0
- package/src/app/app/api/handoff/cms/sanity/callback/route.ts +18 -0
- package/src/app/app/api/handoff/cms/sanity/categories/route.ts +146 -0
- package/src/app/app/api/handoff/cms/sanity/connect/route.ts +15 -0
- package/src/app/app/api/handoff/cms/sanity/publish/route.ts +161 -0
- package/src/app/app/api/handoff/cms/sanity/token/route.ts +87 -0
- package/src/app/app/api/handoff/components/[id]/screenshot.png/route.ts +101 -0
- package/src/app/app/api/handoff/components/[id]/thumbnail.svg/route.ts +158 -0
- package/src/app/app/api/handoff/components/build/route.ts +26 -0
- package/src/app/app/api/handoff/components/history/contract/route.ts +33 -0
- package/src/app/app/api/handoff/components/history/route.ts +35 -0
- package/src/app/app/api/handoff/components/history/version/route.ts +36 -0
- package/src/app/app/api/handoff/components/route.ts +56 -0
- package/src/app/app/api/handoff/components/validation/route.ts +36 -0
- package/src/app/app/api/handoff/design/workspace/brand-imagery-image/route.ts +75 -0
- package/src/app/app/api/handoff/design/workspace/route.ts +163 -0
- package/src/app/app/api/handoff/figma/component-properties/route.ts +34 -0
- package/src/app/app/api/handoff/figma/components/route.ts +21 -0
- package/src/app/app/api/handoff/figma/components/sync/route.ts +50 -0
- package/src/app/app/api/handoff/figma/fetch/route.ts +126 -0
- package/src/app/app/api/handoff/guest/assets/route.ts +52 -0
- package/src/app/app/api/handoff/guest/enter/route.ts +169 -0
- package/src/app/app/api/handoff/guest/submission/route.ts +209 -0
- package/src/app/app/api/handoff/guest/submission/submit/route.ts +63 -0
- package/src/app/app/api/handoff/image-slots/route.ts +24 -0
- package/src/app/app/api/handoff/navigation/prune/route.ts +106 -0
- package/src/app/app/api/handoff/pages/route.ts +90 -0
- package/src/app/app/api/handoff/patterns/[id]/clone/route.ts +69 -0
- package/src/app/app/api/handoff/patterns/[id]/manifest/route.ts +102 -0
- package/src/app/app/api/handoff/patterns/[id]/notes/route.ts +101 -0
- package/src/app/app/api/handoff/patterns/[id]/route.ts +41 -0
- package/src/app/app/api/handoff/patterns/[id]/thumbnail.svg/route.ts +70 -0
- package/src/app/app/api/handoff/patterns/route.ts +77 -0
- package/src/app/app/api/handoff/reference-materials/route.ts +40 -0
- package/src/app/app/api/handoff/review/[id]/route.ts +172 -0
- package/src/app/app/api/handoff/review/[id]/voice/route.ts +58 -0
- package/src/app/app/api/handoff/review/route.ts +31 -0
- package/src/app/app/api/handoff/share/[token]/route.ts +82 -0
- package/src/app/app/api/handoff/share/links/route.ts +48 -0
- package/src/app/app/api/handoff/share/route.ts +172 -0
- package/src/app/app/api/handoff/site-protection/route.ts +85 -0
- package/src/app/app/api/handoff/site-protection/unlock/route.ts +62 -0
- package/src/app/app/api/handoff/templates/[id]/submissions/route.ts +41 -0
- package/src/app/app/api/mcp/route.ts +39 -0
- package/src/app/app/api/oauth/authorization-server-metadata/route.ts +30 -0
- package/src/app/app/api/oauth/authorize/route.ts +158 -0
- package/src/app/app/api/oauth/device/approve/route.ts +32 -0
- package/src/app/app/api/oauth/device/route.ts +34 -0
- package/src/app/app/api/oauth/protected-resource-metadata/route.ts +26 -0
- package/src/app/app/api/oauth/register/route.ts +43 -0
- package/src/app/app/api/oauth/token/route.ts +94 -0
- package/src/app/app/api/openapi/route.ts +38 -0
- package/src/app/app/api/patterns/route.ts +8 -0
- package/src/app/app/api/registry/assets/ingest/route.ts +204 -0
- package/src/app/app/api/registry/assets/ingest-figma-fills/route.ts +81 -0
- package/src/app/app/api/registry/components/[id]/previews/[previewId]/route.ts +56 -0
- package/src/app/app/api/registry/components/[id]/previews/route.ts +66 -0
- package/src/app/app/api/registry/config/route.ts +50 -0
- package/src/app/app/api/registry/dtcg/download/route.ts +78 -0
- package/src/app/app/api/registry/dtcg/route.ts +133 -0
- package/src/app/app/api/registry/fonts/route.ts +67 -0
- package/src/app/app/api/registry/icons/download/route.ts +52 -0
- package/src/app/app/api/registry/icons/route.ts +47 -0
- package/src/app/app/api/registry/image-slots/route.ts +68 -0
- package/src/app/app/api/registry/logo.svg/route.ts +45 -0
- package/src/app/app/api/registry/logos/route.ts +47 -0
- package/src/app/app/api/registry/navigation/route.ts +52 -0
- package/src/app/app/api/registry/pages/route.ts +67 -0
- package/src/app/app/api/registry/theme/route.ts +51 -0
- package/src/app/app/api/registry/theme.css/route.ts +34 -0
- package/src/app/app/api/registry/tokens/route.ts +59 -0
- package/src/app/app/api/sync/changes/route.ts +24 -0
- package/src/app/app/api/sync/shared-assets/route.ts +79 -0
- package/src/app/app/api/sync/status/route.ts +12 -0
- package/src/app/app/api/sync/upload/route.ts +109 -0
- package/src/app/app/assets/AssetsClient.tsx +670 -0
- package/src/app/app/assets/[id]/AssetDetailClient.tsx +319 -0
- package/src/app/app/assets/[id]/page.tsx +8 -0
- package/src/app/app/assets/fonts/page.tsx +5 -0
- package/src/app/app/assets/logos/page.tsx +5 -0
- package/src/app/app/assets/page.tsx +5 -0
- package/src/app/app/cli/device/CliDeviceClient.tsx +104 -0
- package/src/app/app/cli/device/page.tsx +45 -0
- package/src/app/app/design/DesignClient.tsx +1682 -0
- package/src/app/app/design/SessionHistoryPanel.tsx +116 -0
- package/src/app/app/design/assets/[id]/page.tsx +11 -0
- package/src/app/app/design/assets/icons/page.tsx +8 -0
- package/src/app/app/design/assets/page.tsx +8 -0
- package/src/app/app/design/library/[id]/SavedDesignDetailClient.tsx +892 -0
- package/src/app/app/design/library/[id]/page.tsx +40 -0
- package/src/app/app/design/library/[id]/share/SharePublicClient.tsx +107 -0
- package/src/app/app/design/library/[id]/share/page.tsx +22 -0
- package/src/app/app/design/library/page.tsx +12 -0
- package/src/app/app/design/page.tsx +158 -0
- package/src/app/app/design/settings/SettingsClient.tsx +648 -0
- package/src/app/app/design/settings/page.tsx +41 -0
- package/src/app/app/design/settings/settings-constants.ts +96 -0
- package/src/app/app/design/v1/DesignClient.tsx +1316 -0
- package/src/app/app/design/v1/page.tsx +103 -0
- package/src/app/app/design/workbench-session.ts +54 -0
- package/src/app/app/design/workbench-types.ts +72 -0
- package/src/app/app/dev/local-setup/LocalSetupClient.tsx +119 -0
- package/src/app/app/dev/local-setup/McpSetupSection.tsx +174 -0
- package/src/app/app/dev/local-setup/page.tsx +5 -0
- package/src/app/app/developer/api/route.ts +13 -0
- package/src/app/app/developer/cli/page.tsx +192 -0
- package/src/app/app/developer/layout.tsx +57 -0
- package/src/app/app/developer/local-setup/page.tsx +37 -0
- package/src/app/app/developer/mcp/page.tsx +74 -0
- package/src/app/app/developer/page.tsx +111 -0
- package/src/app/app/developer/push-pull/page.tsx +130 -0
- package/src/app/app/fonts/[filename]/route.ts +41 -0
- package/src/app/app/foundations/[...slug]/page.tsx +83 -0
- package/src/app/app/foundations/assets/[id]/page.tsx +35 -0
- package/src/app/app/foundations/assets/page.tsx +31 -0
- package/src/app/app/foundations/border-radius/page.tsx +179 -0
- package/src/app/app/foundations/colors/page.tsx +166 -0
- package/src/app/app/foundations/effects/page.tsx +124 -0
- package/src/app/app/foundations/elevation/page.tsx +209 -0
- package/src/app/app/foundations/error.tsx +22 -0
- package/src/app/app/foundations/grid/page.tsx +315 -0
- package/src/app/app/foundations/icons/IconsPageClient.tsx +100 -0
- package/src/app/app/foundations/icons/[name]/SingleIconClient.tsx +231 -0
- package/src/app/app/foundations/icons/[name]/page.tsx +44 -0
- package/src/app/app/foundations/icons/page.tsx +58 -0
- package/src/app/app/foundations/logo/page.tsx +213 -0
- package/src/app/app/foundations/motion/page.tsx +228 -0
- package/src/app/app/foundations/page.tsx +65 -0
- package/src/app/app/foundations/spacing/page.tsx +171 -0
- package/src/app/app/foundations/typography/page.tsx +115 -0
- package/src/app/app/layout.tsx +131 -0
- package/src/app/app/library/LibraryClient.tsx +567 -0
- package/src/app/app/library/page.tsx +46 -0
- package/src/app/app/login/LoginClient.tsx +75 -0
- package/src/app/app/login/page.tsx +33 -0
- package/src/app/app/page.tsx +178 -0
- package/src/app/app/patterns/PatternBrowserClient.tsx +263 -0
- package/src/app/app/patterns/page.tsx +14 -0
- package/src/app/app/playground/PlaygroundClient.tsx +84 -0
- package/src/app/app/playground/[id]/page.tsx +215 -0
- package/src/app/app/playground/page.tsx +79 -0
- package/src/app/app/providers.tsx +72 -0
- package/src/app/app/reset-password/ResetPasswordClient.tsx +89 -0
- package/src/app/app/reset-password/page.tsx +24 -0
- package/src/app/app/review/ReviewClient.tsx +31 -0
- package/src/app/app/review/page.tsx +56 -0
- package/src/app/app/s/[token]/page.tsx +317 -0
- package/src/app/app/setup/SetupClient.tsx +87 -0
- package/src/app/app/setup/actions.ts +53 -0
- package/src/app/app/setup/page.tsx +28 -0
- package/src/app/app/system/FigmaFetchControls.tsx +163 -0
- package/src/app/app/system/FigmaSyncPanel.tsx +357 -0
- package/src/app/app/system/NewComponentForm.tsx +272 -0
- package/src/app/app/system/SystemPageClient.tsx +137 -0
- package/src/app/app/system/changelog/ChangelogClient.tsx +608 -0
- package/src/app/app/system/changelog/page.tsx +28 -0
- package/src/app/app/system/component/[component]/ComponentAssetsPanel.tsx +108 -0
- package/src/app/app/system/component/[component]/ComponentDetailClient.tsx +420 -0
- package/src/app/app/system/component/[component]/ComponentImageSlotsPanel.tsx +163 -0
- package/src/app/app/system/component/[component]/ComponentVersionHistory.tsx +430 -0
- package/src/app/app/system/component/[component]/VersionCompare.tsx +267 -0
- package/src/app/app/system/component/[component]/page.tsx +68 -0
- package/src/app/app/system/component/page.tsx +5 -0
- package/src/app/app/system/figma-sync/FigmaSyncPageClient.tsx +35 -0
- package/src/app/app/system/figma-sync/page.tsx +21 -0
- package/src/app/app/system/health/ComponentHealthTable.tsx +217 -0
- package/src/app/app/system/health/HealthDashboardClient.tsx +141 -0
- package/src/app/app/system/health/RuleBreakdownTable.tsx +123 -0
- package/src/app/app/system/health/ScoreBadge.tsx +58 -0
- package/src/app/app/system/health/TrendChart.tsx +76 -0
- package/src/app/app/system/health/ValidatorBreakdownBars.tsx +35 -0
- package/src/app/app/system/health/health-types.ts +7 -0
- package/src/app/app/system/health/page.tsx +100 -0
- package/src/app/app/system/page.tsx +21 -0
- package/src/app/app/system/pattern/[pattern]/PatternDetailClient.tsx +216 -0
- package/src/app/app/system/pattern/[pattern]/page.tsx +53 -0
- package/src/app/app/system/pattern/page.tsx +5 -0
- package/src/app/app/unlock/UnlockClient.tsx +100 -0
- package/src/app/app/unlock/page.tsx +40 -0
- package/src/app/components/Auth/AuthControls.tsx +146 -0
- package/src/app/components/Brief/BuildList.tsx +78 -0
- package/src/app/components/Brief/BuildPanel.tsx +460 -0
- package/src/app/components/Brief/export-blocks.ts +47 -0
- package/src/app/components/Chat/ChatActionCard.tsx +97 -0
- package/src/app/components/Chat/ChatChangelogFeed.tsx +252 -0
- package/src/app/components/Chat/ChatComponentGrid.tsx +144 -0
- package/src/app/components/Chat/ChatContext.tsx +192 -0
- package/src/app/components/Chat/ChatDrawer.tsx +162 -0
- package/src/app/components/Chat/ChatFab.tsx +41 -0
- package/src/app/components/Chat/ChatInput.tsx +150 -0
- package/src/app/components/Chat/ChatMessage.tsx +125 -0
- package/src/app/components/Chat/ChatValidationPanel.tsx +161 -0
- package/src/app/components/CloudFeatureGate.tsx +27 -0
- package/src/app/components/Component/BestPracticesCard.tsx +36 -0
- package/src/app/components/Component/Cards.tsx +76 -0
- package/src/app/components/Component/ComponentLists.tsx +279 -0
- package/src/app/components/Component/ComponentWorkbenchDialog.tsx +230 -0
- package/src/app/components/Component/InlineComponentEditor.tsx +163 -0
- package/src/app/components/Component/PageSliceResolver.tsx +81 -0
- package/src/app/components/Component/Preview.tsx +1091 -0
- package/src/app/components/Component/slices/BestPracticesSlice.tsx +14 -0
- package/src/app/components/Component/slices/CardsSlice.tsx +17 -0
- package/src/app/components/Component/slices/ComponentDisplaySlice.tsx +101 -0
- package/src/app/components/Component/slices/PropertiesSlice.tsx +24 -0
- package/src/app/components/Component/slices/TextSlice.tsx +23 -0
- package/src/app/components/Component/slices/ValidationResultsSlice.tsx +31 -0
- package/src/app/components/Component/slices/index.ts +14 -0
- package/src/app/components/Component/usePreviews.ts +97 -0
- package/src/app/components/ComponentDesignTokens.tsx +271 -0
- package/src/app/components/ComponentGuidelines.tsx +21 -0
- package/src/app/components/ComponentNotFound.tsx +35 -0
- package/src/app/components/ComponentSearch.tsx +96 -0
- package/src/app/components/CopyCode.tsx +59 -0
- package/src/app/components/CopyToClipboard.tsx +63 -0
- package/src/app/components/Design/DevHandoffPanel.tsx +481 -0
- package/src/app/components/DownloadTokens.tsx +78 -0
- package/src/app/components/Footer.tsx +46 -0
- package/src/app/components/Foundations/BrandColorSwatches.tsx +151 -0
- package/src/app/components/Foundations/ColorContrast.tsx +179 -0
- package/src/app/components/Foundations/ColorGrid.tsx +199 -0
- package/src/app/components/Foundations/ColorInfo.tsx +64 -0
- package/src/app/components/Foundations/ColorSpaces.tsx +119 -0
- package/src/app/components/Foundations/ColorTailwind.tsx +58 -0
- package/src/app/components/Foundations/ColorsDisplay.tsx +136 -0
- package/src/app/components/Foundations/DisplayLogo.tsx +16 -0
- package/src/app/components/Foundations/IconCatalogGrid.tsx +145 -0
- package/src/app/components/Foundations/ProvenanceBadge.tsx +40 -0
- package/src/app/components/Foundations/RulesSheet.tsx +204 -0
- package/src/app/components/Foundations/TokenOutputTabs.tsx +88 -0
- package/src/app/components/Foundations/TypographyExample.tsx +275 -0
- package/src/app/components/Guest/GuestAuthoring.tsx +589 -0
- package/src/app/components/Guest/GuestEditor.tsx +157 -0
- package/src/app/components/Hero.tsx +42 -0
- package/src/app/components/InlineEdit/InlineEditField.tsx +162 -0
- package/src/app/components/InlineEdit/InlineEditHeader.tsx +98 -0
- package/src/app/components/Layout/BuildBadge.tsx +90 -0
- package/src/app/components/Layout/Header.tsx +54 -0
- package/src/app/components/Layout/Main.tsx +84 -0
- package/src/app/components/Markdown/CodeHighlight.tsx +328 -0
- package/src/app/components/Markdown/MarkdownComponents.tsx +270 -0
- package/src/app/components/Markdown/MarkdownEditor.tsx +153 -0
- package/src/app/components/Markdown/WysiwygEditor.tsx +364 -0
- package/src/app/components/Markdown/wysiwyg.css +89 -0
- package/src/app/components/ModeSwitcher.tsx +29 -0
- package/src/app/components/NavLink.tsx +26 -0
- package/src/app/components/Navigation/AnchorNav.tsx +94 -0
- package/src/app/components/Navigation/AnchorNavLink.tsx +41 -0
- package/src/app/components/Navigation/AnchorNavNew.tsx +27 -0
- package/src/app/components/Navigation/MainNav.tsx +84 -0
- package/src/app/components/Navigation/MobileNav.tsx +123 -0
- package/src/app/components/Navigation/PrevNextNav.tsx +53 -0
- package/src/app/components/Navigation/SideNav.tsx +336 -0
- package/src/app/components/Navigation/anchor-slugify.ts +6 -0
- package/src/app/components/Playground/AiChatPanel.tsx +1483 -0
- package/src/app/components/Playground/ComponentCard.tsx +65 -0
- package/src/app/components/Playground/ComponentLibrary.tsx +228 -0
- package/src/app/components/Playground/CoverImagePicker.tsx +281 -0
- package/src/app/components/Playground/EditContext.tsx +247 -0
- package/src/app/components/Playground/EditSheet.tsx +82 -0
- package/src/app/components/Playground/FieldGuardrailsContext.ts +31 -0
- package/src/app/components/Playground/FieldLinkContext.ts +138 -0
- package/src/app/components/Playground/FieldMediaContext.ts +50 -0
- package/src/app/components/Playground/FindingsList.tsx +149 -0
- package/src/app/components/Playground/MediaBrowser.tsx +397 -0
- package/src/app/components/Playground/PageChecks.tsx +71 -0
- package/src/app/components/Playground/PageTitle.tsx +93 -0
- package/src/app/components/Playground/PlaygroundBuilder.tsx +1271 -0
- package/src/app/components/Playground/PlaygroundContext.tsx +990 -0
- package/src/app/components/Playground/PlaygroundWorkbench.tsx +260 -0
- package/src/app/components/Playground/Preview.tsx +1465 -0
- package/src/app/components/Playground/PublishToSanityDialog.tsx +468 -0
- package/src/app/components/Playground/SavePatternDialog.tsx +231 -0
- package/src/app/components/Playground/ShareTemplate.tsx +503 -0
- package/src/app/components/Playground/SortableItem.tsx +94 -0
- package/src/app/components/Playground/Wizard/ApiKeySettings.tsx +139 -0
- package/src/app/components/Playground/Wizard/PageImporter.tsx +384 -0
- package/src/app/components/Playground/Wizard/WizardDialog.tsx +329 -0
- package/src/app/components/Playground/Wizard/llm-client.ts +87 -0
- package/src/app/components/Playground/Wizard/prompt-builder.ts +134 -0
- package/src/app/components/Playground/Wizard/response-parser.ts +80 -0
- package/src/app/components/Playground/fields/ButtonField.tsx +24 -0
- package/src/app/components/Playground/fields/Field.tsx +344 -0
- package/src/app/components/Playground/fields/FieldLabel.tsx +9 -0
- package/src/app/components/Playground/fields/FunctionField.tsx +19 -0
- package/src/app/components/Playground/fields/ImageField.tsx +239 -0
- package/src/app/components/Playground/fields/LinkField.tsx +24 -0
- package/src/app/components/Playground/fields/RawJsonField.tsx +60 -0
- package/src/app/components/Playground/fields/RichTextField.tsx +220 -0
- package/src/app/components/Playground/fields/SelectField.tsx +55 -0
- package/src/app/components/Playground/fields/SlotField.tsx +40 -0
- package/src/app/components/Playground/fields/TextField.tsx +125 -0
- package/src/app/components/Playground/fields/VideoFileField.tsx +67 -0
- package/src/app/components/Playground/fields/content-only.ts +121 -0
- package/src/app/components/Playground/fields/field-type.ts +84 -0
- package/src/app/components/Playground/fields/reseed.ts +140 -0
- package/src/app/components/Playground/inline-edit-script.ts +596 -0
- package/src/app/components/Playground/link-guard-script.ts +50 -0
- package/src/app/components/Playground/types.ts +76 -0
- package/src/app/components/Playground/usePublishToSanity.ts +153 -0
- package/src/app/components/Review/ReviewQueueClient.tsx +288 -0
- package/src/app/components/SideNav/Custom.tsx +40 -0
- package/src/app/components/SideNavNew.tsx +280 -0
- package/src/app/components/Typography/Headers.tsx +50 -0
- package/src/app/components/Validation/ValidationFrameworkResults.tsx +208 -0
- package/src/app/components/Validation/ValidationResults.tsx +60 -0
- package/src/app/components/cards/CardsWithIcons.tsx +38 -0
- package/src/app/components/context/AuthUiContext.tsx +13 -0
- package/src/app/components/context/ConfigContext.tsx +43 -0
- package/src/app/components/context/HandoffCapabilitiesContext.tsx +40 -0
- package/src/app/components/context/HotReloadProvider.tsx +38 -0
- package/src/app/components/context/PreviewContext.tsx +135 -0
- package/src/app/components/library/AssetCard.tsx +166 -0
- package/src/app/components/library/KindPicker.tsx +66 -0
- package/src/app/components/library/LaneTabs.tsx +54 -0
- package/src/app/components/library/LifecycleBadge.tsx +28 -0
- package/src/app/components/library/LifecyclePicker.tsx +53 -0
- package/src/app/components/library/MetaControl.tsx +294 -0
- package/src/app/components/library/OwnerAttribution.tsx +106 -0
- package/src/app/components/library/PageNotes.tsx +191 -0
- package/src/app/components/library/PageOrigin.tsx +124 -0
- package/src/app/components/library/VisibilityBadge.tsx +25 -0
- package/src/app/components/library/VisibilityPicker.tsx +56 -0
- package/src/app/components/library/index.ts +7 -0
- package/src/app/components/ui/accordion.tsx +49 -0
- package/src/app/components/ui/alert.tsx +39 -0
- package/src/app/components/ui/attachment.tsx +204 -0
- package/src/app/components/ui/badge.tsx +32 -0
- package/src/app/components/ui/breadcrumb.tsx +68 -0
- package/src/app/components/ui/bubble.tsx +125 -0
- package/src/app/components/ui/button.tsx +45 -0
- package/src/app/components/ui/card.tsx +76 -0
- package/src/app/components/ui/collapsible.tsx +9 -0
- package/src/app/components/ui/dialog.tsx +80 -0
- package/src/app/components/ui/drawer.tsx +103 -0
- package/src/app/components/ui/dropdown-menu.tsx +176 -0
- package/src/app/components/ui/input.tsx +22 -0
- package/src/app/components/ui/json-tree-view.tsx +250 -0
- package/src/app/components/ui/label.tsx +24 -0
- package/src/app/components/ui/marker.tsx +69 -0
- package/src/app/components/ui/message-scroller.tsx +130 -0
- package/src/app/components/ui/message.tsx +92 -0
- package/src/app/components/ui/mobile-nav.tsx +95 -0
- package/src/app/components/ui/navigation-menu.tsx +116 -0
- package/src/app/components/ui/popover.tsx +31 -0
- package/src/app/components/ui/radio-group.tsx +36 -0
- package/src/app/components/ui/select.tsx +132 -0
- package/src/app/components/ui/separator.tsx +29 -0
- package/src/app/components/ui/sheet.tsx +140 -0
- package/src/app/components/ui/sidebar.tsx +609 -0
- package/src/app/components/ui/skeleton.tsx +15 -0
- package/src/app/components/ui/switch.tsx +29 -0
- package/src/app/components/ui/table.tsx +60 -0
- package/src/app/components/ui/tabs.tsx +53 -0
- package/src/app/components/ui/textarea.tsx +19 -0
- package/src/app/components/ui/toggle-group.tsx +51 -0
- package/src/app/components/ui/toggle.tsx +39 -0
- package/src/app/components/ui/tooltip.tsx +30 -0
- package/src/app/components/util/colors.ts +93 -0
- package/src/app/components/util/dtcg.ts +50 -0
- package/src/app/components/util/index.ts +963 -0
- package/src/app/components/util/theme-provider.tsx +11 -0
- package/src/app/components/util/token.ts +70 -0
- package/src/app/components.json +21 -0
- package/src/app/css/index.css +275 -0
- package/src/app/css/theme.css +14 -0
- package/src/app/css.d.ts +1 -0
- package/src/app/hooks/use-mobile.tsx +17 -0
- package/src/app/instrumentation.ts +39 -0
- package/src/app/lib/adapter-kit/errors.ts +141 -0
- package/src/app/lib/adapter-kit/types.ts +637 -0
- package/src/app/lib/admin-build-tasks-types.ts +41 -0
- package/src/app/lib/api-path.ts +12 -0
- package/src/app/lib/asset-search.ts +167 -0
- package/src/app/lib/asset-types.ts +88 -0
- package/src/app/lib/asset-upload-source.ts +314 -0
- package/src/app/lib/auth.ts +244 -0
- package/src/app/lib/authoring-guardrails.ts +591 -0
- package/src/app/lib/authoring-shapes.ts +261 -0
- package/src/app/lib/authz/guest.ts +131 -0
- package/src/app/lib/authz/notes.ts +102 -0
- package/src/app/lib/authz/policy.ts +228 -0
- package/src/app/lib/authz/review.ts +180 -0
- package/src/app/lib/authz/vocab.ts +175 -0
- package/src/app/lib/brief-components.ts +212 -0
- package/src/app/lib/build-audits.ts +239 -0
- package/src/app/lib/capture-chromium-plan.ts +123 -0
- package/src/app/lib/capture-determinism.ts +397 -0
- package/src/app/lib/capture-kinds.ts +207 -0
- package/src/app/lib/change-digest.ts +108 -0
- package/src/app/lib/chat-turn-guards.ts +149 -0
- package/src/app/lib/cli-sync-jwt.ts +110 -0
- package/src/app/lib/client/poll-generation-job.ts +85 -0
- package/src/app/lib/client-name.ts +29 -0
- package/src/app/lib/cms-migration-prompt.ts +99 -0
- package/src/app/lib/component-capture.ts +156 -0
- package/src/app/lib/component-id.ts +14 -0
- package/src/app/lib/component-thumbnail.ts +200 -0
- package/src/app/lib/composition-summary.ts +84 -0
- package/src/app/lib/content-length-plan.ts +512 -0
- package/src/app/lib/contract-limit-audit.ts +228 -0
- package/src/app/lib/contract-render-audit.ts +208 -0
- package/src/app/lib/data/component-row.ts +121 -0
- package/src/app/lib/data/components-digest.ts +116 -0
- package/src/app/lib/data/dynamic-provider.ts +765 -0
- package/src/app/lib/data/has-payload.ts +18 -0
- package/src/app/lib/data/hybrid-provider.ts +6 -0
- package/src/app/lib/data/index.ts +45 -0
- package/src/app/lib/data/menu-merge.ts +417 -0
- package/src/app/lib/data/page-metadata.ts +85 -0
- package/src/app/lib/data/pattern-merge.ts +78 -0
- package/src/app/lib/data/static-provider.ts +237 -0
- package/src/app/lib/data/types.ts +125 -0
- package/src/app/lib/db/auto-migrate.ts +205 -0
- package/src/app/lib/db/bootstrap-admin.ts +45 -0
- package/src/app/lib/db/capture-job-queries.ts +333 -0
- package/src/app/lib/db/changelog-queries.ts +623 -0
- package/src/app/lib/db/cms-connection-config.ts +21 -0
- package/src/app/lib/db/cms-connection-queries.ts +218 -0
- package/src/app/lib/db/component-artifact-queries.ts +115 -0
- package/src/app/lib/db/component-facets.ts +535 -0
- package/src/app/lib/db/component-preview-queries.ts +224 -0
- package/src/app/lib/db/component-version-queries.ts +682 -0
- package/src/app/lib/db/dialect.ts +15 -0
- package/src/app/lib/db/event-log-store.ts +47 -0
- package/src/app/lib/db/grant-queries.ts +827 -0
- package/src/app/lib/db/history-purge-plan.ts +446 -0
- package/src/app/lib/db/history-purge.ts +233 -0
- package/src/app/lib/db/index.ts +92 -0
- package/src/app/lib/db/migrations/0000_init.sql +226 -0
- package/src/app/lib/db/migrations/0001_design_workspace.sql +12 -0
- package/src/app/lib/db/migrations/0002_boring_ricochet.sql +50 -0
- package/src/app/lib/db/migrations/0003_demonic_flatman.sql +41 -0
- package/src/app/lib/db/migrations/0004_validation_runs.sql +18 -0
- package/src/app/lib/db/migrations/0005_component_versions.sql +21 -0
- package/src/app/lib/db/migrations/0006_token_and_page_changes.sql +40 -0
- package/src/app/lib/db/migrations/0007_design_spec.sql +9 -0
- package/src/app/lib/db/migrations/0008_design_generation_jobs.sql +22 -0
- package/src/app/lib/db/migrations/0009_assets.sql +80 -0
- package/src/app/lib/db/migrations/0010_registry_dtcg.sql +13 -0
- package/src/app/lib/db/migrations/0011_dtcg_brands.sql +5 -0
- package/src/app/lib/db/migrations/0012_icon_logo_registry.sql +13 -0
- package/src/app/lib/db/migrations/0013_registry_fonts.sql +13 -0
- package/src/app/lib/db/migrations/0014_asset_blobs.sql +9 -0
- package/src/app/lib/db/migrations/0015_appearance.sql +7 -0
- package/src/app/lib/db/migrations/0016_image_slots.sql +16 -0
- package/src/app/lib/db/migrations/0017_component_preview.sql +20 -0
- package/src/app/lib/db/migrations/0018_token_change_details.sql +26 -0
- package/src/app/lib/db/migrations/0019_change_why.sql +18 -0
- package/src/app/lib/db/migrations/0020_pattern_change.sql +17 -0
- package/src/app/lib/db/migrations/0021_mcp_oauth_connector.sql +37 -0
- package/src/app/lib/db/migrations/0022_dtcg_source.sql +21 -0
- package/src/app/lib/db/migrations/0023_perf_indexes.sql +30 -0
- package/src/app/lib/db/migrations/0024_phase_b_visibility.sql +40 -0
- package/src/app/lib/db/migrations/0027_guest_authoring.sql +49 -0
- package/src/app/lib/db/migrations/0028_invite_to_build.sql +99 -0
- package/src/app/lib/db/migrations/0029_pages_templates_reflow.sql +121 -0
- package/src/app/lib/db/migrations/0030_retire_briefs.sql +71 -0
- package/src/app/lib/db/migrations/0031_drop_brief_columns.sql +32 -0
- package/src/app/lib/db/migrations/0033_site_protection.sql +45 -0
- package/src/app/lib/db/migrations/0034_brand_imagery.sql +8 -0
- package/src/app/lib/db/migrations/0035_history_provenance.sql +42 -0
- package/src/app/lib/db/migrations/0036_cms_connections.sql +68 -0
- package/src/app/lib/db/migrations/0037_component_preview_purpose.sql +17 -0
- package/src/app/lib/db/migrations/0038_capture_job.sql +87 -0
- package/src/app/lib/db/migrations/meta/0000_snapshot.json +1424 -0
- package/src/app/lib/db/migrations/meta/0002_snapshot.json +1644 -0
- package/src/app/lib/db/migrations/meta/0003_snapshot.json +1820 -0
- package/src/app/lib/db/migrations/meta/_journal.json +258 -0
- package/src/app/lib/db/note-queries.ts +184 -0
- package/src/app/lib/db/pattern-write.ts +1094 -0
- package/src/app/lib/db/property-delta.ts +117 -0
- package/src/app/lib/db/push-grouping.ts +256 -0
- package/src/app/lib/db/queries.ts +2426 -0
- package/src/app/lib/db/registry-queries.ts +607 -0
- package/src/app/lib/db/schema-active.ts +2 -0
- package/src/app/lib/db/schema-pg.ts +1201 -0
- package/src/app/lib/db/schema.ts +2 -0
- package/src/app/lib/db/seed.ts +117 -0
- package/src/app/lib/db/sync-queries.ts +542 -0
- package/src/app/lib/db/token-flatten.ts +95 -0
- package/src/app/lib/db/validation-queries.ts +82 -0
- package/src/app/lib/db/version-baseline.ts +42 -0
- package/src/app/lib/design-workspace-client.ts +194 -0
- package/src/app/lib/design-workspace-format.ts +294 -0
- package/src/app/lib/docx-copy.ts +279 -0
- package/src/app/lib/dtcg-axes.ts +138 -0
- package/src/app/lib/dtcg-normalizer.ts +370 -0
- package/src/app/lib/edit-operations.ts +275 -0
- package/src/app/lib/email.ts +199 -0
- package/src/app/lib/error-summary.ts +79 -0
- package/src/app/lib/evals/cases.ts +678 -0
- package/src/app/lib/evals/copy-coverage.ts +147 -0
- package/src/app/lib/evals/copy-decks.ts +296 -0
- package/src/app/lib/field-lens.ts +308 -0
- package/src/app/lib/field-marks.ts +206 -0
- package/src/app/lib/figma-plugin-contract.ts +104 -0
- package/src/app/lib/figma-sync-types.ts +56 -0
- package/src/app/lib/generated/build-meta.ts +8 -0
- package/src/app/lib/guest-editable.ts +371 -0
- package/src/app/lib/handoff-capabilities.ts +91 -0
- package/src/app/lib/health-types.ts +324 -0
- package/src/app/lib/hubspot-field-map.ts +770 -0
- package/src/app/lib/hubspot-module/build-module.ts +238 -0
- package/src/app/lib/hubspot-module/context.ts +259 -0
- package/src/app/lib/hubspot-module/fields/boolean.ts +24 -0
- package/src/app/lib/hubspot-module/fields/button.ts +70 -0
- package/src/app/lib/hubspot-module/fields/fields.ts +104 -0
- package/src/app/lib/hubspot-module/fields/generic.ts +183 -0
- package/src/app/lib/hubspot-module/fields/hubdb.ts +168 -0
- package/src/app/lib/hubspot-module/fields/image.ts +65 -0
- package/src/app/lib/hubspot-module/fields/menu.ts +14 -0
- package/src/app/lib/hubspot-module/fields/object.ts +42 -0
- package/src/app/lib/hubspot-module/fields/select.ts +43 -0
- package/src/app/lib/hubspot-module/fields/text.ts +68 -0
- package/src/app/lib/hubspot-module/fields/url.ts +57 -0
- package/src/app/lib/hubspot-module/fields/utils.ts +36 -0
- package/src/app/lib/hubspot-module/fields/video.ts +75 -0
- package/src/app/lib/hubspot-module/index.ts +30 -0
- package/src/app/lib/hubspot-module/transpile.ts +727 -0
- package/src/app/lib/hubspot-module/types.ts +238 -0
- package/src/app/lib/hubspot-module-build.ts +50 -0
- package/src/app/lib/image-bytes.ts +133 -0
- package/src/app/lib/image-dimensions.ts +214 -0
- package/src/app/lib/image-field-write.ts +51 -0
- package/src/app/lib/image-generation-request.ts +142 -0
- package/src/app/lib/image-target.ts +175 -0
- package/src/app/lib/json-shape.ts +121 -0
- package/src/app/lib/library-image-seed.ts +236 -0
- package/src/app/lib/login-required-messages.ts +17 -0
- package/src/app/lib/mcp/apps/component-gallery.bundle.ts +2 -0
- package/src/app/lib/mcp/apps/component-gallery.client.ts +208 -0
- package/src/app/lib/mcp/apps/component-preview.bundle.ts +2 -0
- package/src/app/lib/mcp/apps/component-preview.client.ts +140 -0
- package/src/app/lib/mcp/apps/token-palette.bundle.ts +2 -0
- package/src/app/lib/mcp/apps/token-palette.client.ts +199 -0
- package/src/app/lib/mcp/contract-report.ts +200 -0
- package/src/app/lib/mcp/create-server.ts +2622 -0
- package/src/app/lib/mcp/history-shapes.ts +72 -0
- package/src/app/lib/mcp/project-profile.ts +82 -0
- package/src/app/lib/mcp/scaffold-helpers.ts +93 -0
- package/src/app/lib/mcp/stack-guides/bootstrap-handlebars.md +62 -0
- package/src/app/lib/mcp/stack-guides/react-scss.md +7 -0
- package/src/app/lib/mcp/stack-guides/react-tailwind.md +9 -0
- package/src/app/lib/mcp/stack-guides/tailwind-handlebars.md +142 -0
- package/src/app/lib/mcp/stack-guides.ts +68 -0
- package/src/app/lib/mcp/tool-catalog.ts +132 -0
- package/src/app/lib/mcp-auth.ts +85 -0
- package/src/app/lib/merge-block-values.ts +868 -0
- package/src/app/lib/normalize-preview-values.ts +244 -0
- package/src/app/lib/notify.ts +213 -0
- package/src/app/lib/oauth-scopes.ts +33 -0
- package/src/app/lib/page-exemplars.ts +112 -0
- package/src/app/lib/page-manifest.ts +162 -0
- package/src/app/lib/page-provenance.ts +231 -0
- package/src/app/lib/page-slug.ts +68 -0
- package/src/app/lib/page-title.ts +44 -0
- package/src/app/lib/page-urls.ts +41 -0
- package/src/app/lib/passwords.ts +33 -0
- package/src/app/lib/pattern-payload.ts +122 -0
- package/src/app/lib/pattern-thumbnail.ts +234 -0
- package/src/app/lib/placeholder-audit.ts +196 -0
- package/src/app/lib/placeholder-copy.ts +370 -0
- package/src/app/lib/playground-prompt-link.ts +46 -0
- package/src/app/lib/preview-groups.ts +107 -0
- package/src/app/lib/preview-purpose-labels.ts +37 -0
- package/src/app/lib/preview-purpose.ts +37 -0
- package/src/app/lib/preview-render-target.ts +27 -0
- package/src/app/lib/preview-url.ts +15 -0
- package/src/app/lib/publish-to-sanity-state.ts +605 -0
- package/src/app/lib/rate-limit.ts +75 -0
- package/src/app/lib/remote-handoff-client.ts +33 -0
- package/src/app/lib/sanity-assets.ts +211 -0
- package/src/app/lib/sanity-categories.ts +178 -0
- package/src/app/lib/sanity-config.ts +266 -0
- package/src/app/lib/sanity-integration-state.ts +235 -0
- package/src/app/lib/sanity-mapping.ts +3284 -0
- package/src/app/lib/sanity-portable-text.ts +640 -0
- package/src/app/lib/sanity-publish.ts +337 -0
- package/src/app/lib/sanity-references.ts +295 -0
- package/src/app/lib/server/admin-users.ts +162 -0
- package/src/app/lib/server/ai-client.ts +633 -0
- package/src/app/lib/server/ai-proxy.ts +70 -0
- package/src/app/lib/server/api-gate.ts +148 -0
- package/src/app/lib/server/appearance.ts +169 -0
- package/src/app/lib/server/asset-generation-worker.ts +133 -0
- package/src/app/lib/server/asset-ingest-store.ts +55 -0
- package/src/app/lib/server/asset-ingest.ts +347 -0
- package/src/app/lib/server/auth-reset.ts +107 -0
- package/src/app/lib/server/capture-browser.ts +130 -0
- package/src/app/lib/server/capture-harness.ts +319 -0
- package/src/app/lib/server/capture-worker.ts +178 -0
- package/src/app/lib/server/change-why.ts +195 -0
- package/src/app/lib/server/cli-device-oauth.ts +159 -0
- package/src/app/lib/server/cms-providers.ts +53 -0
- package/src/app/lib/server/component-build-preload.cjs +3 -0
- package/src/app/lib/server/component-build-worker.ts +196 -0
- package/src/app/lib/server/component-builder.ts +96 -0
- package/src/app/lib/server/component-capture-reads.ts +172 -0
- package/src/app/lib/server/component-generation-context.ts +165 -0
- package/src/app/lib/server/component-generation-images.ts +40 -0
- package/src/app/lib/server/component-generation-llm.ts +232 -0
- package/src/app/lib/server/component-generation-run.ts +289 -0
- package/src/app/lib/server/component-generation-schedule.ts +12 -0
- package/src/app/lib/server/component-preview-screenshot.ts +111 -0
- package/src/app/lib/server/component-scaffold.ts +88 -0
- package/src/app/lib/server/component-visual-compare.ts +90 -0
- package/src/app/lib/server/design-artifact-persist.ts +49 -0
- package/src/app/lib/server/design-asset-extractor.ts +414 -0
- package/src/app/lib/server/design-asset-schedule.ts +36 -0
- package/src/app/lib/server/design-asset-worker-spawn.ts +64 -0
- package/src/app/lib/server/design-asset-worker.ts +24 -0
- package/src/app/lib/server/design-generation-worker.ts +281 -0
- package/src/app/lib/server/design-prompt-builder.ts +322 -0
- package/src/app/lib/server/design-spec-generator.ts +739 -0
- package/src/app/lib/server/design-spec-types.ts +219 -0
- package/src/app/lib/server/design-system-context.ts +141 -0
- package/src/app/lib/server/design-token-summary.ts +133 -0
- package/src/app/lib/server/design-workspace.ts +230 -0
- package/src/app/lib/server/dev-handoff.ts +334 -0
- package/src/app/lib/server/doc-pages.ts +442 -0
- package/src/app/lib/server/event-log.ts +138 -0
- package/src/app/lib/server/fetch-asset-bytes.ts +161 -0
- package/src/app/lib/server/figma-audit-api.ts +188 -0
- package/src/app/lib/server/figma-auth.ts +113 -0
- package/src/app/lib/server/figma-fetch-runner.ts +241 -0
- package/src/app/lib/server/figma-fetch-worker.ts +130 -0
- package/src/app/lib/server/figma-fetch.ts +90 -0
- package/src/app/lib/server/figma-fills-ingest.ts +201 -0
- package/src/app/lib/server/figma-plugin-properties-sync.ts +438 -0
- package/src/app/lib/server/figma-sync-service.ts +1076 -0
- package/src/app/lib/server/find-assets.ts +53 -0
- package/src/app/lib/server/foundation-image.tsx +671 -0
- package/src/app/lib/server/generation-queue-health.ts +108 -0
- package/src/app/lib/server/guest-context.ts +62 -0
- package/src/app/lib/server/guest-session.ts +153 -0
- package/src/app/lib/server/handoff-app-paths.ts +77 -0
- package/src/app/lib/server/handoff-component-patch.ts +123 -0
- package/src/app/lib/server/handoff-config-load.ts +29 -0
- package/src/app/lib/server/handoff-config-project.ts +104 -0
- package/src/app/lib/server/mcp-oauth-connector.ts +269 -0
- package/src/app/lib/server/node-tsx-worker-launcher.cjs +32 -0
- package/src/app/lib/server/oauth-state.ts +83 -0
- package/src/app/lib/server/passphrase.ts +121 -0
- package/src/app/lib/server/pattern-api-map.ts +123 -0
- package/src/app/lib/server/playground-chat.ts +1890 -0
- package/src/app/lib/server/public-api-paths.ts +34 -0
- package/src/app/lib/server/reference-material-generator.ts +341 -0
- package/src/app/lib/server/reference-material-ids.ts +8 -0
- package/src/app/lib/server/reference-material-persist.ts +25 -0
- package/src/app/lib/server/reference-material-schedule.ts +13 -0
- package/src/app/lib/server/registry-cache.ts +110 -0
- package/src/app/lib/server/request-public-url.ts +19 -0
- package/src/app/lib/server/runtime-config.ts +43 -0
- package/src/app/lib/server/s3-assets.ts +188 -0
- package/src/app/lib/server/sanity-connection.ts +176 -0
- package/src/app/lib/server/sanity-oauth.ts +34 -0
- package/src/app/lib/server/scaffold-args.ts +392 -0
- package/src/app/lib/server/secret-box.ts +85 -0
- package/src/app/lib/server/serverless-chromium.ts +93 -0
- package/src/app/lib/server/share-link-token.ts +106 -0
- package/src/app/lib/server/site-protection.ts +145 -0
- package/src/app/lib/server/spawn-tsx-worker.ts +47 -0
- package/src/app/lib/server/store-image-asset.ts +220 -0
- package/src/app/lib/server/token-freshness.ts +23 -0
- package/src/app/lib/server/unlock-cookie.ts +70 -0
- package/src/app/lib/server/upload-asset-to-library.ts +128 -0
- package/src/app/lib/server/url-extract.ts +117 -0
- package/src/app/lib/server/voice-audit.ts +209 -0
- package/src/app/lib/set-at-args-path.ts +36 -0
- package/src/app/lib/site-gate.ts +374 -0
- package/src/app/lib/slot-capabilities.ts +487 -0
- package/src/app/lib/source-copy.ts +295 -0
- package/src/app/lib/storage/artifact-images.ts +225 -0
- package/src/app/lib/storage/capture-artifacts.ts +109 -0
- package/src/app/lib/swap-image-src.ts +121 -0
- package/src/app/lib/sync-auth.ts +124 -0
- package/src/app/lib/tool-payload.ts +101 -0
- package/src/app/lib/turn-log.ts +78 -0
- package/src/app/lib/url-safety.ts +46 -0
- package/src/app/lib/utils.ts +35 -0
- package/src/app/lib/workbench-level.ts +56 -0
- package/src/app/middleware-hook.mjs +2 -0
- package/src/app/next-env.d.ts +6 -0
- package/src/app/next.config.mjs +355 -0
- package/src/app/postcss.config.mjs +8 -0
- package/src/app/proxy.ts +133 -0
- package/src/app/public/assets/css/preview.css +27 -0
- package/src/app/public/assets/design/blocks/callout-cta.jpg +0 -0
- package/src/app/public/assets/design/blocks/carousel.png +0 -0
- package/src/app/public/assets/design/blocks/container.png +0 -0
- package/src/app/public/assets/design/blocks/customer-stories.jpg +0 -0
- package/src/app/public/assets/design/blocks/faq.jpg +0 -0
- package/src/app/public/assets/design/blocks/features-comparison.jpg +0 -0
- package/src/app/public/assets/design/blocks/table.jpg +0 -0
- package/src/app/public/assets/images/blocks.svg +150 -0
- package/src/app/public/assets/images/check-circle.svg +10 -0
- package/src/app/public/assets/images/colors.svg +186 -0
- package/src/app/public/assets/images/components.png +0 -0
- package/src/app/public/assets/images/components.svg +183 -0
- package/src/app/public/assets/images/illustration-sample-2.svg +102 -0
- package/src/app/public/assets/images/illustration-sample-3.svg +124 -0
- package/src/app/public/assets/images/illustration-sample-bw-1.svg +84 -0
- package/src/app/public/assets/images/illustration-sample-bw-2.svg +88 -0
- package/src/app/public/assets/images/illustration-sample-bw-3.svg +125 -0
- package/src/app/public/assets/images/illustration-sample.svg +110 -0
- package/src/app/public/assets/images/typography.svg +279 -0
- package/src/app/public/assets/images/usage-correct.png +0 -0
- package/src/app/public/assets/images/usage-wrong.png +0 -0
- package/src/app/public/assets/images/x-circle.svg +10 -0
- package/src/app/public/assets/js/preview.js +90 -0
- package/src/app/public/assets/svg/activity.svg +1 -0
- package/src/app/public/assets/svg/add.svg +1 -0
- package/src/app/public/assets/svg/airplay.svg +1 -0
- package/src/app/public/assets/svg/alert-circle.svg +1 -0
- package/src/app/public/assets/svg/alert-octagon.svg +1 -0
- package/src/app/public/assets/svg/alert-triangle.svg +1 -0
- package/src/app/public/assets/svg/align-center.svg +1 -0
- package/src/app/public/assets/svg/align-justify.svg +1 -0
- package/src/app/public/assets/svg/align-left.svg +1 -0
- package/src/app/public/assets/svg/arrow-down-circle.svg +1 -0
- package/src/app/public/assets/svg/arrow-left-circle.svg +1 -0
- package/src/app/public/assets/svg/arrow-right-circle.svg +1 -0
- package/src/app/public/assets/svg/arrow-right.svg +4 -0
- package/src/app/public/assets/svg/arrow-up-circle.svg +1 -0
- package/src/app/public/assets/svg/bell-off.svg +1 -0
- package/src/app/public/assets/svg/bell.svg +1 -0
- package/src/app/public/assets/svg/camera.svg +1 -0
- package/src/app/public/assets/svg/cast.svg +1 -0
- package/src/app/public/assets/svg/check.svg +1 -0
- package/src/app/public/assets/svg/clock.svg +1 -0
- package/src/app/public/assets/svg/code.svg +1 -0
- package/src/app/public/assets/svg/component-accordion.svg +56 -0
- package/src/app/public/assets/svg/component-alert.svg +34 -0
- package/src/app/public/assets/svg/component-button.svg +63 -0
- package/src/app/public/assets/svg/component-checkbox.svg +41 -0
- package/src/app/public/assets/svg/component-input.svg +30 -0
- package/src/app/public/assets/svg/component-modal.svg +63 -0
- package/src/app/public/assets/svg/component-pagination.svg +82 -0
- package/src/app/public/assets/svg/component-radio.svg +15 -0
- package/src/app/public/assets/svg/component-select.svg +48 -0
- package/src/app/public/assets/svg/component-switch.svg +6 -0
- package/src/app/public/assets/svg/component-table.svg +45 -0
- package/src/app/public/assets/svg/component-tabs.svg +34 -0
- package/src/app/public/assets/svg/component-tooltip.svg +60 -0
- package/src/app/public/assets/svg/component.svg +48 -0
- package/src/app/public/assets/svg/copy.svg +1 -0
- package/src/app/public/assets/svg/delivery.svg +1 -0
- package/src/app/public/assets/svg/download.svg +1 -0
- package/src/app/public/assets/svg/file-jpg.svg +20 -0
- package/src/app/public/assets/svg/file-svg.svg +31 -0
- package/src/app/public/assets/svg/file-zip.svg +24 -0
- package/src/app/public/assets/svg/hero-brand-assets.svg +44 -0
- package/src/app/public/assets/svg/hero-colors.svg +10 -0
- package/src/app/public/assets/svg/hero-components.svg +68 -0
- package/src/app/public/assets/svg/hero-design.svg +20 -0
- package/src/app/public/assets/svg/hero-effects.svg +1 -0
- package/src/app/public/assets/svg/illustration-sample.svg +82 -0
- package/src/app/public/assets/svg/image.svg +8 -0
- package/src/app/public/assets/svg/link.svg +1 -0
- package/src/app/public/assets/svg/logo.svg +8 -0
- package/src/app/public/assets/svg/moon.svg +1 -0
- package/src/app/public/assets/svg/motiv-logo-dark-example.svg +11 -0
- package/src/app/public/assets/svg/motiv-logo-example.svg +11 -0
- package/src/app/public/assets/svg/plus-circle.svg +1 -0
- package/src/app/public/assets/svg/react.svg +10 -0
- package/src/app/public/assets/svg/search-laptop.svg +20 -0
- package/src/app/public/assets/svg/search.svg +1 -0
- package/src/app/public/assets/svg/send.svg +10 -0
- package/src/app/public/assets/svg/share.svg +1 -0
- package/src/app/public/assets/svg/small-accordion.svg +9 -0
- package/src/app/public/assets/svg/small-button.svg +9 -0
- package/src/app/public/assets/svg/small-pagination.svg +14 -0
- package/src/app/public/assets/svg/small-radio.svg +15 -0
- package/src/app/public/assets/svg/small-select.svg +9 -0
- package/src/app/public/assets/svg/small-table.svg +16 -0
- package/src/app/public/assets/svg/small-toggle.svg +9 -0
- package/src/app/public/assets/svg/sun.svg +1 -0
- package/src/app/public/assets/svg/token-alignment.svg +5 -0
- package/src/app/public/assets/svg/token-border-radius.svg +3 -0
- package/src/app/public/assets/svg/token-border-width.svg +10 -0
- package/src/app/public/assets/svg/token-spacing-horizontal.svg +8 -0
- package/src/app/public/assets/svg/token-spacing-vertical.svg +8 -0
- package/src/app/public/assets/svg/token-type-small.svg +5 -0
- package/src/app/public/assets/svg/x.svg +1 -0
- package/src/app/public/assets/svg/zap.svg +1 -0
- package/src/app/public/favicon.ico +0 -0
- package/src/app/public/fonts/readme.md +4 -0
- package/src/app/public/handoff-logo.svg +38 -0
- package/src/app/public/logo.svg +13 -0
- package/src/app/public/openapi.yaml +1818 -0
- package/src/app/public/robots.txt +0 -0
- package/src/app/tsconfig.json +53 -0
- package/src/app/types/middleware-hook.d.ts +10 -0
- package/src/app/types/next-auth-augmentation.d.ts +20 -0
- package/src/app-builder/README.md +43 -0
- package/src/app-builder/build.ts +741 -0
- package/src/app-builder/client-config.ts +124 -0
- package/src/app-builder/config-diff/index.ts +4 -0
- package/src/app-builder/config-diff/registry.ts +23 -0
- package/src/app-builder/config-diff/snapshot.ts +51 -0
- package/src/app-builder/config-diff/strategies/pattern.ts +80 -0
- package/src/app-builder/config-diff/types.ts +36 -0
- package/src/app-builder/index.ts +7 -0
- package/src/app-builder/path-contract.ts +81 -0
- package/src/app-builder/paths.ts +90 -0
- package/src/app-builder/watchers/component.ts +72 -0
- package/src/app-builder/watchers/utils.ts +44 -0
- package/src/app-builder/watchers.ts +345 -0
- package/src/app-builder/websocket.ts +72 -0
- package/src/cache/README.md +49 -0
- package/src/cache/build-cache.ts +567 -0
- package/src/cache/file-state.ts +170 -0
- package/src/cache/index.ts +46 -0
- package/src/cache/push-state.ts +201 -0
- package/src/cli/README.md +12 -0
- package/src/cli/create.ts +366 -0
- package/src/cli/eject.ts +93 -0
- package/src/cli/fetch-design-md.ts +60 -0
- package/src/cli/figma-audit.ts +76 -0
- package/src/cli/init-claude-core.ts +111 -0
- package/src/cli/make.ts +203 -0
- package/src/cli/scaffold.ts +651 -0
- package/src/cli/sync/apply-declaration-pull.ts +257 -0
- package/src/cli/sync/apply-pull.ts +223 -0
- package/src/cli/sync/cli-auth-store.ts +51 -0
- package/src/cli/sync/collect-build-artifacts.ts +159 -0
- package/src/cli/sync/collect-referenced-images.ts +204 -0
- package/src/cli/sync/declaration-patch.ts +192 -0
- package/src/cli/sync/hash.ts +12 -0
- package/src/cli/sync/open-browser.ts +37 -0
- package/src/cli/sync/push-provenance.ts +109 -0
- package/src/cli/sync/push-registry-content.ts +1025 -0
- package/src/cli/sync/push-shared-assets.ts +62 -0
- package/src/cli/sync/resolve-declaration-payload.ts +231 -0
- package/src/cli/sync/resolve-declaration.ts +18 -0
- package/src/cli/sync/run-cli-login.ts +110 -0
- package/src/cli/sync/run-history-purge.ts +142 -0
- package/src/cli/sync/run-pull.ts +112 -0
- package/src/cli/sync/run-push.ts +702 -0
- package/src/cli/sync/run-sync-status.ts +37 -0
- package/src/cli/sync/sync-remote-env.ts +64 -0
- package/src/cli/sync/sync-state.ts +42 -0
- package/src/cli/tokens/ensure-default-brand.ts +115 -0
- package/src/cli/tokens/migrate-legacy.ts +261 -0
- package/src/cli/tokens/parse-css-brands.ts +208 -0
- package/src/cli/tokens/transform.ts +134 -0
- package/src/cli.ts +62 -0
- package/src/commands/README.md +25 -0
- package/src/commands/audit/figma-components.ts +37 -0
- package/src/commands/build/app.ts +32 -0
- package/src/commands/build/components.ts +25 -0
- package/src/commands/build/hubspot.ts +267 -0
- package/src/commands/dev/index.ts +20 -0
- package/src/commands/eject/config.ts +20 -0
- package/src/commands/eject/pages.ts +20 -0
- package/src/commands/eject/theme.ts +20 -0
- package/src/commands/fetch/index.ts +20 -0
- package/src/commands/history-purge.ts +67 -0
- package/src/commands/index.ts +67 -0
- package/src/commands/init/index.ts +17 -0
- package/src/commands/init/vercel.ts +112 -0
- package/src/commands/init-claude.ts +61 -0
- package/src/commands/login.ts +39 -0
- package/src/commands/logout.ts +22 -0
- package/src/commands/make/component.ts +34 -0
- package/src/commands/make/page.ts +47 -0
- package/src/commands/make/template.ts +47 -0
- package/src/commands/mcp-init.ts +111 -0
- package/src/commands/mcp-token.ts +32 -0
- package/src/commands/prepare-runtime.ts +39 -0
- package/src/commands/pull.ts +28 -0
- package/src/commands/push-all.ts +202 -0
- package/src/commands/push-assets.ts +52 -0
- package/src/commands/push-tokens.ts +52 -0
- package/src/commands/push.ts +91 -0
- package/src/commands/scaffold/index.ts +22 -0
- package/src/commands/start/index.ts +20 -0
- package/src/commands/sync-status.ts +21 -0
- package/src/commands/tokens-build.ts +118 -0
- package/src/commands/types.ts +6 -0
- package/src/commands/utils.ts +21 -0
- package/src/commands/validate/components.ts +27 -0
- package/src/commands/validate.ts +189 -0
- package/src/commands/vercel-build.ts +96 -0
- package/src/config/README.md +32 -0
- package/src/config/declaration-module-load.ts +74 -0
- package/src/config/defaults.ts +78 -0
- package/src/config/helpers.ts +43 -0
- package/src/config/index.ts +16 -0
- package/src/config/loader.ts +131 -0
- package/src/config/normalizers/declaration.ts +180 -0
- package/src/config/normalizers/pattern.ts +56 -0
- package/src/config/runtime.ts +426 -0
- package/src/config/validator.ts +24 -0
- package/src/declarations/codegen.ts +367 -0
- package/src/declarations/helpers.ts +36 -0
- package/src/declarations/index.ts +20 -0
- package/src/declarations/types.ts +214 -0
- package/src/figma/component-linking.ts +1415 -0
- package/src/figma/image-fills.ts +247 -0
- package/src/generated/build-meta.ts +8 -0
- package/src/index.d.ts +13 -0
- package/src/index.ts +369 -0
- package/src/pipeline/README.md +21 -0
- package/src/pipeline/archive.ts +75 -0
- package/src/pipeline/components.ts +9 -0
- package/src/pipeline/documentation.ts +77 -0
- package/src/pipeline/figma.ts +173 -0
- package/src/pipeline/hubspot/config.ts +288 -0
- package/src/pipeline/hubspot/emit.ts +385 -0
- package/src/pipeline/index.ts +38 -0
- package/src/pipeline/patterns.ts +12 -0
- package/src/pipeline/styles.ts +154 -0
- package/src/pipeline/validation.ts +25 -0
- package/src/stacks/bootstrap-handlebars.md +117 -0
- package/src/stacks/react-scss.md +126 -0
- package/src/stacks/react-tailwind.md +123 -0
- package/src/stacks/tailwind-handlebars.md +142 -0
- package/src/transformers/README.md +19 -0
- package/src/transformers/docgen/index.ts +305 -0
- package/src/transformers/plugins/csf-render.ts +485 -0
- package/src/transformers/plugins/handlebars-previews.ts +194 -0
- package/src/transformers/plugins/index.ts +14 -0
- package/src/transformers/plugins/slot-probe-candidates.ts +386 -0
- package/src/transformers/plugins/slot-probe.ts +366 -0
- package/src/transformers/plugins/ssr-render.ts +622 -0
- package/src/transformers/plugins.ts +17 -0
- package/src/transformers/preview/component/api.ts +175 -0
- package/src/transformers/preview/component/artifacts.ts +112 -0
- package/src/transformers/preview/component/build-shared-bundles.ts +453 -0
- package/src/transformers/preview/component/builder.ts +754 -0
- package/src/transformers/preview/component/css.ts +253 -0
- package/src/transformers/preview/component/field-annotations.ts +400 -0
- package/src/transformers/preview/component/html.ts +96 -0
- package/src/transformers/preview/component/javascript.ts +182 -0
- package/src/transformers/preview/component/normalizer.ts +83 -0
- package/src/transformers/preview/component/playwright-shared.ts +183 -0
- package/src/transformers/preview/component/preview-assets.ts +158 -0
- package/src/transformers/preview/component/preview-merge.ts +95 -0
- package/src/transformers/preview/component/preview-select.ts +184 -0
- package/src/transformers/preview/component/preview-server.ts +128 -0
- package/src/transformers/preview/component/preview-validation.ts +255 -0
- package/src/transformers/preview/component/previews.ts +12 -0
- package/src/transformers/preview/component/screenshot.ts +306 -0
- package/src/transformers/preview/component/serialized-elements.ts +124 -0
- package/src/transformers/preview/component/summary.ts +54 -0
- package/src/transformers/preview/component.ts +31 -0
- package/src/transformers/preview/height-reporter.ts +37 -0
- package/src/transformers/preview/pattern/api.ts +83 -0
- package/src/transformers/preview/pattern/builder.ts +192 -0
- package/src/transformers/preview/pattern/html.ts +115 -0
- package/src/transformers/preview/slots.ts +105 -0
- package/src/transformers/preview/types.ts +302 -0
- package/src/transformers/types.ts +68 -0
- package/src/transformers/utils/build.ts +85 -0
- package/src/transformers/utils/csf.ts +48 -0
- package/src/transformers/utils/handlebars.ts +92 -0
- package/src/transformers/utils/html.ts +44 -0
- package/src/transformers/utils/index.ts +27 -0
- package/src/transformers/utils/module.ts +54 -0
- package/src/transformers/utils/schema-loader.ts +68 -0
- package/src/transformers/utils/schema.ts +569 -0
- package/src/transformers/utils/string.ts +55 -0
- package/src/transformers/utils/svg-sprite.ts +139 -0
- package/src/transformers/utils/usage.ts +317 -0
- package/src/transformers/utils/vite-logger.ts +33 -0
- package/src/transformers/validation/runner.ts +351 -0
- package/src/transformers/vite-config.ts +21 -0
- package/src/types/README.md +12 -0
- package/src/types/config.ts +482 -0
- package/src/types/font.ts +3 -0
- package/src/types/handoff-sync.ts +145 -0
- package/src/types/history-purge.ts +141 -0
- package/src/types/icon.ts +8 -0
- package/src/types/preview.ts +136 -0
- package/src/types/validation.ts +213 -0
- package/src/utils/README.md +14 -0
- package/src/utils/asset-upload-limits.ts +157 -0
- package/src/utils/design-md.ts +152 -0
- package/src/utils/duration.ts +3 -0
- package/src/utils/filter.ts +134 -0
- package/src/utils/fs.ts +35 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/line-diff.ts +80 -0
- package/src/utils/logger.ts +176 -0
- package/src/utils/path.ts +61 -0
- package/src/utils/port.ts +46 -0
- package/src/utils/rich-text.ts +1202 -0
- package/src/validators/axe.ts +288 -0
- package/src/validators/contrast.ts +270 -0
- package/src/validators/index.ts +42 -0
- package/src/validators/schema.ts +191 -0
- package/tailwind.config.ts +96 -0
- package/templates/default/README.md.tpl +15 -0
- package/templates/default/components/button/Button.jsx.tpl +64 -0
- package/templates/default/components/button/Button.tsx.tpl +92 -0
- package/templates/default/components/button/button.react.handoff.js.tpl +31 -0
- package/templates/default/components/button/button.react.handoff.ts.tpl +31 -0
- package/templates/default/env.tpl +2 -0
- package/templates/default/gitignore.tpl +7 -0
- package/templates/default/handoff.config.js.tpl +216 -0
- package/templates/default/handoff.config.ts.tpl +196 -0
- package/templates/default/handoff.config.with-examples.js.tpl +215 -0
- package/templates/default/handoff.config.with-examples.ts.tpl +208 -0
- package/templates/default/package.json.tpl +19 -0
- package/templates/default/tsconfig.json.tpl +24 -0
- package/templates/workflows/hubspot-deploy.yml +134 -0
- package/tsconfig.json +30 -0
|
@@ -0,0 +1,1890 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import { getDataProvider } from '@/lib/data';
|
|
4
|
+
import { openAiChatTools, type OpenAiTool } from '@/lib/server/ai-client';
|
|
5
|
+
import { formatBrandVoiceForPrompt, getDesignWorkspace } from '@/lib/server/design-workspace';
|
|
6
|
+
import { scaffoldArgsForComponent } from '@/lib/server/scaffold-args';
|
|
7
|
+
import { blankContentValues, mergeBlockValues, placeholderImageUrl, summarizeFields } from '@/lib/merge-block-values';
|
|
8
|
+
import { formatExemplars } from '@/lib/page-exemplars';
|
|
9
|
+
import { buildImagePrompt, parseSize, sizeForDimensions, type GeneratedImageSize } from '@/lib/image-generation-request';
|
|
10
|
+
import { describeImagePlacement, imageFieldsFor, resolveImageTarget, valueForImageTarget } from '@/lib/image-target';
|
|
11
|
+
import {
|
|
12
|
+
describeMissingImagery,
|
|
13
|
+
describeOptionalGaps,
|
|
14
|
+
describeReplacedImages,
|
|
15
|
+
findPlaceholderImages,
|
|
16
|
+
findUnplacedImages,
|
|
17
|
+
imageGapInstruction,
|
|
18
|
+
unplacedImageInstruction,
|
|
19
|
+
} from '@/lib/placeholder-audit';
|
|
20
|
+
import { summarizeError } from '@/lib/error-summary';
|
|
21
|
+
import { packToBudget, purposeLine, truncationNote } from '@/lib/tool-payload';
|
|
22
|
+
import { looseMatchNote } from '@/lib/asset-search';
|
|
23
|
+
import { readCapabilities } from '@/lib/slot-capabilities';
|
|
24
|
+
import { resolvePreviewKey } from '@handoff/transformers/preview/component/preview-select';
|
|
25
|
+
import { describeTurn, flagsFor, type TurnFacts, type TurnRetry } from '@/lib/turn-log';
|
|
26
|
+
import { logAiEvent } from '@/lib/server/event-log';
|
|
27
|
+
import { applyOps, parseEditEntries, verifyOps, type EditOp, type PageBlock } from '@/lib/edit-operations';
|
|
28
|
+
import { summarizeComposition } from '@/lib/composition-summary';
|
|
29
|
+
import {
|
|
30
|
+
COMPOSE_MAX_TOKENS,
|
|
31
|
+
nextGapAsk,
|
|
32
|
+
salvageTurn,
|
|
33
|
+
toolCallWasCut,
|
|
34
|
+
truncatedToolCallInstruction,
|
|
35
|
+
type GapAsks,
|
|
36
|
+
} from '@/lib/chat-turn-guards';
|
|
37
|
+
|
|
38
|
+
export { summarizeComposition };
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The playground's "generate with AI": a conversation that assembles a page from **existing** blocks.
|
|
42
|
+
*
|
|
43
|
+
* Nothing here generates imagery. Layout comes from the component catalog, copy from the model under
|
|
44
|
+
* the workspace's brand voice, and pictures from the asset store. That is the whole scope, and it is why
|
|
45
|
+
* this is a tool-calling chat rather than a pipeline — no cron, no stages, answers in seconds.
|
|
46
|
+
*
|
|
47
|
+
* Replaces `components/Playground/Wizard/llm-client.ts`, which called OpenAI **directly from the
|
|
48
|
+
* browser** with a user-pasted key: no cost tracking, no shared key, a secret in localStorage, and none
|
|
49
|
+
* of the workspace context every other generation path inherits. Running it here fixes all four.
|
|
50
|
+
*
|
|
51
|
+
* **The chat proposes; the client applies.** `propose_page` is terminal and returns blocks — it never
|
|
52
|
+
* writes a pattern. The caller hands them to `bulkAddComponents`, the user watches the page assemble in
|
|
53
|
+
* the preview they already have, and every existing edit affordance stays meaningful. A bad proposal
|
|
54
|
+
* costs a click, not a saved artifact.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
export interface ProposedBlock {
|
|
58
|
+
componentId: string;
|
|
59
|
+
args: Record<string, unknown>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface PlaygroundChatTurn {
|
|
63
|
+
/** Assistant prose — a question, a summary, or an explanation of the proposal. */
|
|
64
|
+
reply: string;
|
|
65
|
+
/** Present only when the model called `propose_page`. The client renders an apply card. */
|
|
66
|
+
proposal?: { blocks: ProposedBlock[]; rationale: string; notices?: string[] };
|
|
67
|
+
/** Present when the model called `propose_edits`. Targeted changes to what is already there. */
|
|
68
|
+
changeset?: { ops: EditOp[]; summary: string; rejected: { reason: string }[] };
|
|
69
|
+
/** Tool names invoked this turn, in order. Surfaced for the UI to show its working. */
|
|
70
|
+
toolsUsed: string[];
|
|
71
|
+
/**
|
|
72
|
+
* Images this turn kicked off. Each is already referenced in the page as a placeholder; the client
|
|
73
|
+
* polls these and swaps in the real src as they land.
|
|
74
|
+
*/
|
|
75
|
+
queuedImages?: QueuedImage[];
|
|
76
|
+
/**
|
|
77
|
+
* What the turn did, as recorded in the log.
|
|
78
|
+
*
|
|
79
|
+
* Returned rather than only logged so an eval asserts on the *same numbers production reports*. Two
|
|
80
|
+
* definitions of "did it work" drifting apart is the failure this whole line of work keeps hitting;
|
|
81
|
+
* one is cheap to avoid here.
|
|
82
|
+
*/
|
|
83
|
+
facts?: TurnFacts;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface PlaygroundChatMessage {
|
|
87
|
+
role: 'user' | 'assistant';
|
|
88
|
+
content: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Progress emitted while the loop runs.
|
|
93
|
+
*
|
|
94
|
+
* Deliberately *events*, not tokens. A turn spends 10–30s doing real work — searching the catalog,
|
|
95
|
+
* scaffolding props, looking for imagery — and a spinner cannot distinguish that from being stuck.
|
|
96
|
+
* Streaming the model's prose would show characters appearing while the interesting part happened
|
|
97
|
+
* invisibly between them; streaming what it is *doing* is the thing worth watching.
|
|
98
|
+
*
|
|
99
|
+
* The loop takes a callback rather than being a generator so it stays transport-agnostic: the route
|
|
100
|
+
* turns these into SSE, and a test can collect them into an array.
|
|
101
|
+
*/
|
|
102
|
+
export type PlaygroundChatEvent =
|
|
103
|
+
| { type: 'status'; text: string }
|
|
104
|
+
| { type: 'reply'; content: string }
|
|
105
|
+
| {
|
|
106
|
+
type: 'proposal';
|
|
107
|
+
blocks: ProposedBlock[];
|
|
108
|
+
rationale: string;
|
|
109
|
+
/**
|
|
110
|
+
* Values that were refused while building these blocks — a refused image src, most often.
|
|
111
|
+
*
|
|
112
|
+
* The proposal event had no channel for this at all, so on a fresh page a chosen-and-rejected
|
|
113
|
+
* image was invisible: the reply said the slots held placeholders, and never that an image had
|
|
114
|
+
* been picked and thrown away. Named `notices` rather than `rejected` because nothing was dropped
|
|
115
|
+
* from the proposal; a value inside it was substituted.
|
|
116
|
+
*/
|
|
117
|
+
notices?: string[];
|
|
118
|
+
}
|
|
119
|
+
| { type: 'changeset'; ops: EditOp[]; summary: string; rejected: { reason: string }[] }
|
|
120
|
+
| { type: 'images'; queued: QueuedImage[] }
|
|
121
|
+
| { type: 'image_offers'; offers: ImageOffer[] }
|
|
122
|
+
| { type: 'error'; message: string };
|
|
123
|
+
|
|
124
|
+
/** Human-readable narration for a tool call. Named for what the user cares about, not the function. */
|
|
125
|
+
function narrate(name: string, args: Record<string, unknown>): string {
|
|
126
|
+
switch (name) {
|
|
127
|
+
case 'list_blocks':
|
|
128
|
+
return 'Reading your block catalog…';
|
|
129
|
+
case 'search_assets': {
|
|
130
|
+
const q = typeof args.query === 'string' ? args.query.trim() : '';
|
|
131
|
+
return q ? `Searching your assets for ${q}…` : 'Searching your asset library…';
|
|
132
|
+
}
|
|
133
|
+
case 'search_icons': {
|
|
134
|
+
const q = typeof args.query === 'string' ? args.query.trim() : '';
|
|
135
|
+
return q ? `Finding a ${q} icon…` : 'Looking through the icon library…';
|
|
136
|
+
}
|
|
137
|
+
case 'request_image': {
|
|
138
|
+
const t = typeof args.title === 'string' ? args.title.trim() : '';
|
|
139
|
+
return t ? `Generating an image: ${t}…` : 'Generating an image…';
|
|
140
|
+
}
|
|
141
|
+
case 'offer_image': {
|
|
142
|
+
const t = typeof args.title === 'string' ? args.title.trim() : '';
|
|
143
|
+
return t ? `Offering to make an image: ${t}…` : 'Offering to make an image…';
|
|
144
|
+
}
|
|
145
|
+
case 'propose_page':
|
|
146
|
+
return 'Putting the page together…';
|
|
147
|
+
case 'propose_edits':
|
|
148
|
+
return 'Working out what to change…';
|
|
149
|
+
default:
|
|
150
|
+
return 'Working…';
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Ceiling on the tool loop.
|
|
156
|
+
*
|
|
157
|
+
* A real run exhausted 16 rounds on 17 tool calls without ever proposing: it searched section by
|
|
158
|
+
* section and inspected each block in turn. Serving the whole catalog in one call removed the need for
|
|
159
|
+
* either, so a page should now take two or three calls and this ceiling should be unreachable.
|
|
160
|
+
* Rounds are superlinear in cost — the whole transcript replays each time — so hitting it means
|
|
161
|
+
* something is wrong rather than that the page was complicated.
|
|
162
|
+
*/
|
|
163
|
+
const MAX_TOOL_ROUNDS = 16;
|
|
164
|
+
|
|
165
|
+
const TOOLS: OpenAiTool[] = [
|
|
166
|
+
{
|
|
167
|
+
type: 'function',
|
|
168
|
+
function: {
|
|
169
|
+
name: 'list_blocks',
|
|
170
|
+
description:
|
|
171
|
+
'The block catalog for CHOOSING: every block, with its group and one line on what it is for. ' +
|
|
172
|
+
'Call this ONCE with no arguments and pick from the result — the whole catalog fits in one ' +
|
|
173
|
+
'response. It does not include field names; call describe_blocks for the blocks you decide to ' +
|
|
174
|
+
'use. Read the `use` line before choosing: several blocks hold copy and they are not ' +
|
|
175
|
+
'interchangeable.',
|
|
176
|
+
parameters: {
|
|
177
|
+
type: 'object',
|
|
178
|
+
properties: {
|
|
179
|
+
group: { type: 'string', description: 'Optional. Omit to see everything, which is usually right.' },
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
type: 'function',
|
|
186
|
+
function: {
|
|
187
|
+
name: 'describe_blocks',
|
|
188
|
+
description:
|
|
189
|
+
'The editable fields of specific blocks, with the shape each field takes. Call this once for ' +
|
|
190
|
+
'every block you intend to use, in a single call, after choosing from list_blocks and before ' +
|
|
191
|
+
'proposing. Authoring without it means guessing field names, and a guessed field is dropped.',
|
|
192
|
+
parameters: {
|
|
193
|
+
type: 'object',
|
|
194
|
+
properties: {
|
|
195
|
+
ids: {
|
|
196
|
+
type: 'array',
|
|
197
|
+
items: { type: 'string' },
|
|
198
|
+
description: 'The block ids you are going to use, all of them in one call.',
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
required: ['ids'],
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
type: 'function',
|
|
207
|
+
function: {
|
|
208
|
+
name: 'search_assets',
|
|
209
|
+
description:
|
|
210
|
+
'Search the image asset store. Returns { id, name, src }. This is the ONLY source of imagery — ' +
|
|
211
|
+
'put a returned `src` into an image-typed arg. Never invent an image path: a fabricated src ' +
|
|
212
|
+
'renders as a broken image and looks like a bug in the page rather than a gap in the library. ' +
|
|
213
|
+
'If nothing suitable exists, say so and leave the image arg empty.',
|
|
214
|
+
parameters: {
|
|
215
|
+
type: 'object',
|
|
216
|
+
properties: { query: { type: 'string', description: 'What the image should depict.' } },
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
type: 'function',
|
|
222
|
+
function: {
|
|
223
|
+
name: 'request_image',
|
|
224
|
+
description:
|
|
225
|
+
'Generate an image that the asset store does not have, for ONE named slot on ONE block that is ' +
|
|
226
|
+
'already on the canvas. Search first — this is the fallback, not the default, and a real photo ' +
|
|
227
|
+
'from the library beats a generated one. Returns `value`, already in the shape that slot ' +
|
|
228
|
+
'accepts: a labelled placeholder that swaps itself for the real image a minute or two later. ' +
|
|
229
|
+
'You must still write it in with propose_edits — requesting does not place. Say in your reply ' +
|
|
230
|
+
'which images are being generated. Capped per turn.',
|
|
231
|
+
parameters: {
|
|
232
|
+
type: 'object',
|
|
233
|
+
properties: {
|
|
234
|
+
index: {
|
|
235
|
+
type: 'integer',
|
|
236
|
+
description:
|
|
237
|
+
'ZERO-based position of the block on the canvas — the same convention as propose_edits, so ' +
|
|
238
|
+
'block 1 in the listing is index 0. Required: an image with no destination is generated, ' +
|
|
239
|
+
'paid for, and lands nowhere.',
|
|
240
|
+
},
|
|
241
|
+
field: {
|
|
242
|
+
type: 'string',
|
|
243
|
+
description:
|
|
244
|
+
'The exact image field on that block, e.g. "desktopImageSlot". Not "src" and not ' +
|
|
245
|
+
'"image" — those are not field names. Get it wrong and the reply lists the real ones.',
|
|
246
|
+
},
|
|
247
|
+
prompt: {
|
|
248
|
+
type: 'string',
|
|
249
|
+
description:
|
|
250
|
+
'What to depict, as a photography or illustration brief. Describe the subject, setting ' +
|
|
251
|
+
'and mood. No text or logos — generated lettering renders as gibberish.',
|
|
252
|
+
},
|
|
253
|
+
title: { type: 'string', description: 'Short name for the asset library, e.g. "Nurse using a tablet".' },
|
|
254
|
+
altText: { type: 'string', description: 'Alt text for the image.' },
|
|
255
|
+
orientation: {
|
|
256
|
+
type: 'string',
|
|
257
|
+
enum: ['landscape', 'portrait', 'square'],
|
|
258
|
+
description: 'Shape the slot needs. Landscape for heroes and cards; square for avatars and logos.',
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
required: ['index', 'field', 'prompt', 'title'],
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
type: 'function',
|
|
267
|
+
function: {
|
|
268
|
+
name: 'offer_image',
|
|
269
|
+
description:
|
|
270
|
+
'Offer to generate an image the library does not have, instead of generating it. Use when the ' +
|
|
271
|
+
'user named specific imagery, search found no genuine match, and they did NOT explicitly ask ' +
|
|
272
|
+
'you to generate — generation costs money, so the choice is theirs. The offer renders as a ' +
|
|
273
|
+
'"Make an image" button in the chat; nothing is generated or placed until they press it. Costs ' +
|
|
274
|
+
'nothing. Takes the same slot targeting as request_image and validates it the same way. Keep ' +
|
|
275
|
+
'your reply to ONE short question — like: Nothing in the library matched abstract circles — ' +
|
|
276
|
+
'want me to make that image? Do not mention the button, an "option", or what you added; the ' +
|
|
277
|
+
'button renders right under your reply and speaks for itself.',
|
|
278
|
+
parameters: {
|
|
279
|
+
type: 'object',
|
|
280
|
+
properties: {
|
|
281
|
+
index: {
|
|
282
|
+
type: 'integer',
|
|
283
|
+
description: 'ZERO-based position of the block on the canvas, same convention as propose_edits.',
|
|
284
|
+
},
|
|
285
|
+
field: {
|
|
286
|
+
type: 'string',
|
|
287
|
+
description: 'The exact image field on that block, e.g. "desktopImageSlot". Get it wrong and the reply lists the real ones.',
|
|
288
|
+
},
|
|
289
|
+
prompt: {
|
|
290
|
+
type: 'string',
|
|
291
|
+
description:
|
|
292
|
+
'The generation brief the button will run, as a photography or illustration brief: subject, ' +
|
|
293
|
+
'setting, mood. No text or logos — generated lettering renders as gibberish.',
|
|
294
|
+
},
|
|
295
|
+
title: { type: 'string', description: 'Short name for the asset library, e.g. "Abstract circles background".' },
|
|
296
|
+
altText: { type: 'string', description: 'Alt text for the image.' },
|
|
297
|
+
orientation: {
|
|
298
|
+
type: 'string',
|
|
299
|
+
enum: ['landscape', 'portrait', 'square'],
|
|
300
|
+
description: 'Shape the slot needs. Landscape for heroes and cards; square for avatars and logos.',
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
required: ['index', 'field', 'prompt', 'title'],
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
type: 'function',
|
|
309
|
+
function: {
|
|
310
|
+
name: 'search_icons',
|
|
311
|
+
description:
|
|
312
|
+
'Search the design system icon library. Returns { name, category, tags }. Use a returned NAME ' +
|
|
313
|
+
'in any icon-typed field. Like imagery, icons come from the system — never invent an icon name, ' +
|
|
314
|
+
'because an unrecognised one renders as nothing and reads as a broken block.',
|
|
315
|
+
parameters: {
|
|
316
|
+
type: 'object',
|
|
317
|
+
properties: { query: { type: 'string', description: 'What the icon should depict, e.g. "shield", "chat".' } },
|
|
318
|
+
required: ['query'],
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
type: 'function',
|
|
324
|
+
function: {
|
|
325
|
+
name: 'propose_edits',
|
|
326
|
+
description:
|
|
327
|
+
'Change specific blocks on the page that already exists. USE THIS, not propose_page, whenever ' +
|
|
328
|
+
'the canvas has blocks and the request is a change rather than a fresh start — "shorten the ' +
|
|
329
|
+
'headline", "swap the hero", "add a pricing section", "drop the FAQ". Re-proposing the whole ' +
|
|
330
|
+
'page to change one field re-rolls copy the user was happy with.',
|
|
331
|
+
parameters: {
|
|
332
|
+
type: 'object',
|
|
333
|
+
properties: {
|
|
334
|
+
edits: {
|
|
335
|
+
type: 'array',
|
|
336
|
+
description:
|
|
337
|
+
'Operations against the numbered blocks shown under "Already on the canvas". ALL indices ' +
|
|
338
|
+
'refer to that listing as it stands — the operations are applied together, so NEVER adjust ' +
|
|
339
|
+
'an index to account for another operation in the same batch. To remove blocks 1, 2 and 3, ' +
|
|
340
|
+
'send remove(index 0), remove(index 1), remove(index 2) — not remove(index 0) three times. ' +
|
|
341
|
+
'The one exception is a run of inserts: they are placed in the order written, each into the ' +
|
|
342
|
+
'listing with the earlier inserts already present. To append three blocks to a 2-block page, ' +
|
|
343
|
+
'send insert(index 2), insert(index 3), insert(index 4) — they land in that order.',
|
|
344
|
+
items: {
|
|
345
|
+
type: 'object',
|
|
346
|
+
properties: {
|
|
347
|
+
op: {
|
|
348
|
+
type: 'string',
|
|
349
|
+
enum: ['update', 'replace', 'insert', 'remove', 'reorder'],
|
|
350
|
+
description:
|
|
351
|
+
'Which change to make. `update` keeps the block and changes its field values — copy, ' +
|
|
352
|
+
'images, links, theme. `replace` puts a DIFFERENT component in that position: use it ' +
|
|
353
|
+
'whenever the user asks to change what a block IS ("make this a stats block", "use a ' +
|
|
354
|
+
'carousel here", "switch this to two columns"), because `update` cannot change a ' +
|
|
355
|
+
"block's type and will leave it as it was. `insert` adds a new block AT `index` — that is " +
|
|
356
|
+
'the position the new block will occupy, and the block currently there moves down. So ' +
|
|
357
|
+
'"after block 3" (index 2) is insert(index 3), and "before block 3" is insert(index 2); ' +
|
|
358
|
+
'sending the anchor block\'s own index puts the new block ABOVE it. ' +
|
|
359
|
+
'`remove` deletes one. `reorder` rearranges the page: to MOVE blocks around — reverse ' +
|
|
360
|
+
'them, move one up — ALWAYS use one `reorder` op, NEVER remove-and-reinsert: recreating ' +
|
|
361
|
+
'blocks loses their content, because you only see a summary of it.',
|
|
362
|
+
},
|
|
363
|
+
order: {
|
|
364
|
+
type: 'array',
|
|
365
|
+
items: { type: 'number' },
|
|
366
|
+
description:
|
|
367
|
+
'For reorder ONLY: the complete new sequence as OLD zero-based indices — every current ' +
|
|
368
|
+
'position exactly once. [2,1,0] reverses a three-block page; [1,0,2] swaps the first two.',
|
|
369
|
+
},
|
|
370
|
+
index: {
|
|
371
|
+
type: 'number',
|
|
372
|
+
description:
|
|
373
|
+
'ZERO-based position IN THE CURRENT LISTING. Block 1 in the listing is index 0. For an ' +
|
|
374
|
+
'insert it is the slot the NEW block takes: to place it after block k use index k, to ' +
|
|
375
|
+
'place it before block k use index k - 1 (1-based k). Do not simulate the page shrinking ' +
|
|
376
|
+
'or growing from other edits in this call — except for inserts, which count the inserts ' +
|
|
377
|
+
'written before them (see `edits`).',
|
|
378
|
+
},
|
|
379
|
+
expect: {
|
|
380
|
+
type: 'string',
|
|
381
|
+
description:
|
|
382
|
+
'The component id you believe is at that index. Required for update, replace and ' +
|
|
383
|
+
'remove. If it does not match, the operation is rejected rather than applied to the ' +
|
|
384
|
+
'wrong block.',
|
|
385
|
+
},
|
|
386
|
+
componentId: { type: 'string', description: 'The NEW component, for replace and insert.' },
|
|
387
|
+
values: {
|
|
388
|
+
type: 'object',
|
|
389
|
+
description:
|
|
390
|
+
'For update: only the fields that change — everything else is kept. For replace and ' +
|
|
391
|
+
'insert: the full content for the new block.',
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
required: ['op', 'index'],
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
summary: { type: 'string', description: 'One line describing the change, for the user.' },
|
|
398
|
+
},
|
|
399
|
+
required: ['edits', 'summary'],
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
type: 'function',
|
|
405
|
+
function: {
|
|
406
|
+
name: 'propose_page',
|
|
407
|
+
description:
|
|
408
|
+
'Propose the finished composition. Terminal — call it once, when you have scaffolded every ' +
|
|
409
|
+
'block and filled its args. The user reviews and applies it; this does not save anything.',
|
|
410
|
+
parameters: {
|
|
411
|
+
type: 'object',
|
|
412
|
+
properties: {
|
|
413
|
+
blocks: {
|
|
414
|
+
type: 'array',
|
|
415
|
+
description: 'Ordered blocks, top of page first.',
|
|
416
|
+
items: {
|
|
417
|
+
type: 'object',
|
|
418
|
+
properties: {
|
|
419
|
+
componentId: { type: 'string' },
|
|
420
|
+
values: {
|
|
421
|
+
type: 'object',
|
|
422
|
+
description:
|
|
423
|
+
'CONTENT ONLY, keyed by the field names from list_blocks — e.g. ' +
|
|
424
|
+
'{ "headline": "One platform. Every conversation.", "cta": { "label": "Book a demo" } }. ' +
|
|
425
|
+
'Write real copy. Do not describe structure or repeat field types; the server applies ' +
|
|
426
|
+
'these to the block\'s real shape. Omit a field to keep its default.',
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
required: ['componentId', 'values'],
|
|
430
|
+
},
|
|
431
|
+
},
|
|
432
|
+
rationale: { type: 'string', description: 'One or two sentences on why this composition.' },
|
|
433
|
+
replacesExistingPage: {
|
|
434
|
+
type: 'boolean',
|
|
435
|
+
description:
|
|
436
|
+
'Set true ONLY if the user asked to start the page over. Proposing a page while the canvas ' +
|
|
437
|
+
'has blocks discards their copy, imagery and links — for a change to what is there, use ' +
|
|
438
|
+
'propose_edits instead.',
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
required: ['blocks', 'rationale'],
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
];
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Turn the model's content into real block args.
|
|
449
|
+
*
|
|
450
|
+
* Scaffolds each component here rather than making the model do it, then merges the authored values
|
|
451
|
+
* onto that template. The model never sees or restates a shape, which is what removes both the
|
|
452
|
+
* round-trips and the possibility of a block that applies cleanly and renders empty.
|
|
453
|
+
*/
|
|
454
|
+
async function buildBlocks(
|
|
455
|
+
raw: { componentId?: unknown; values?: unknown }[],
|
|
456
|
+
knownAssetSrcs?: Set<string>
|
|
457
|
+
): Promise<{
|
|
458
|
+
blocks: ProposedBlock[];
|
|
459
|
+
problems: string[];
|
|
460
|
+
gaps: { componentId: string; fields: string[] }[];
|
|
461
|
+
/** Empty optional fields, for telling the user rather than asking the model. */
|
|
462
|
+
optionalGaps: { componentId: string; fields: string[] }[];
|
|
463
|
+
/**
|
|
464
|
+
* Per-block field names the model used that the component does not have, plus the names it does.
|
|
465
|
+
*
|
|
466
|
+
* Returned rather than only logged because `propose_edits` needs it: an update whose every named
|
|
467
|
+
* field was unknown produces an edit that changes nothing and still reports "Applied", which is how
|
|
468
|
+
* a mistyped field name reads to the user as a silent lie.
|
|
469
|
+
*/
|
|
470
|
+
rejectedFields: { componentId: string; unknown: string[]; available: string[] }[];
|
|
471
|
+
/**
|
|
472
|
+
* Values the merge refused — an invented image src, an out-of-enum theme.
|
|
473
|
+
*
|
|
474
|
+
* Returned rather than only logged. A live run invented three image srcs, had all three replaced with
|
|
475
|
+
* placeholders, was asked to try again, and proposed the same three: the retry never told it what had
|
|
476
|
+
* been rejected, so it had no reason to do anything different. Same shape as the unknown-key bug.
|
|
477
|
+
*/
|
|
478
|
+
invalidValues: { componentId: string; problems: string[] }[];
|
|
479
|
+
/**
|
|
480
|
+
* Images swapped for a placeholder, flat and per field, for telling the **user**.
|
|
481
|
+
*
|
|
482
|
+
* `invalidValues` above carries the same fact phrased for the model. Both are needed: the model has to
|
|
483
|
+
* be told to use a verbatim asset src, and the person has to be told their hero is a stand-in. Only
|
|
484
|
+
* the first existed, which is why an edit could report success with no image and no explanation.
|
|
485
|
+
*/
|
|
486
|
+
replacedImages: { componentId: string; field: string }[];
|
|
487
|
+
/**
|
|
488
|
+
* The fields the model named, per built block, **after** name correction.
|
|
489
|
+
*
|
|
490
|
+
* Returned so `propose_edits` does not re-derive them from the raw input. It did, and the two
|
|
491
|
+
* disagreed: `mergeBlockValues` corrected `buttonSlot` to `buttonSlots` and wrote it into the args,
|
|
492
|
+
* while the caller filtered by the original spelling, found nothing, and rejected the whole update as
|
|
493
|
+
* naming no fields. The correction worked and the edit was still lost.
|
|
494
|
+
*
|
|
495
|
+
* Two callers deriving one value is the most expensive recurring bug in this codebase. The fix is not
|
|
496
|
+
* to correct the second derivation; it is to have only one.
|
|
497
|
+
*/
|
|
498
|
+
namedKeys: string[][];
|
|
499
|
+
}> {
|
|
500
|
+
const blocks: ProposedBlock[] = [];
|
|
501
|
+
const problems: string[] = [];
|
|
502
|
+
const gaps: { componentId: string; fields: string[] }[] = [];
|
|
503
|
+
const optionalGaps: { componentId: string; fields: string[] }[] = [];
|
|
504
|
+
const rejectedFields: { componentId: string; unknown: string[]; available: string[] }[] = [];
|
|
505
|
+
const invalidValues: { componentId: string; problems: string[] }[] = [];
|
|
506
|
+
const replacedImages: { componentId: string; field: string }[] = [];
|
|
507
|
+
const namedKeys: string[][] = [];
|
|
508
|
+
|
|
509
|
+
for (const entry of raw) {
|
|
510
|
+
const componentId = String(entry?.componentId ?? '').trim();
|
|
511
|
+
if (!componentId) continue;
|
|
512
|
+
|
|
513
|
+
const scaffold = await scaffoldArgsForComponent(componentId);
|
|
514
|
+
if ('error' in scaffold) {
|
|
515
|
+
problems.push(`${componentId}: ${scaffold.error}`);
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// Shape from the preview, content blanked. Leaving the preview's own copy in place made an
|
|
520
|
+
// unfilled field render as somebody else's sample rather than as a gap, which is how a page ships
|
|
521
|
+
// looking finished and isn't.
|
|
522
|
+
const template = blankContentValues(scaffold.args, scaffold.fields);
|
|
523
|
+
const values = (entry?.values ?? {}) as Record<string, unknown>;
|
|
524
|
+
const {
|
|
525
|
+
args,
|
|
526
|
+
unknownKeys,
|
|
527
|
+
invalidValues: invalid,
|
|
528
|
+
replacedImages: replaced,
|
|
529
|
+
correctedFields,
|
|
530
|
+
unfilled,
|
|
531
|
+
unfilledOptional,
|
|
532
|
+
} = mergeBlockValues(template, values, scaffold.fields, knownAssetSrcs);
|
|
533
|
+
if (unknownKeys.length) {
|
|
534
|
+
// Surfaced rather than swallowed: a model that keeps inventing the same field name is a prompt
|
|
535
|
+
// problem, and silently dropping it is how that goes unnoticed for weeks.
|
|
536
|
+
console.warn('[playground-chat] unknown fields on', componentId, unknownKeys.join(', '));
|
|
537
|
+
rejectedFields.push({ componentId, unknown: unknownKeys, available: Object.keys(template) });
|
|
538
|
+
}
|
|
539
|
+
if (invalid.length) {
|
|
540
|
+
console.warn('[playground-chat] rejected values on', componentId, invalid.join('; '));
|
|
541
|
+
invalidValues.push({ componentId, problems: invalid });
|
|
542
|
+
}
|
|
543
|
+
for (const { field } of replaced) replacedImages.push({ componentId, field });
|
|
544
|
+
if (correctedFields.length) {
|
|
545
|
+
// An acceptance, not a rejection — the change landed. Logged because a model repeatedly needing the
|
|
546
|
+
// same correction is a prompt problem, and this is where that becomes visible.
|
|
547
|
+
console.log(
|
|
548
|
+
'[playground-chat] corrected field names on',
|
|
549
|
+
componentId,
|
|
550
|
+
correctedFields.map((c) => `${c.from}→${c.to}`).join(', ')
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
if (unfilled.length) gaps.push({ componentId, fields: unfilled });
|
|
554
|
+
// Reported to the user, never retried on. See `MergeResult.unfilledOptional`.
|
|
555
|
+
if (unfilledOptional.length) optionalGaps.push({ componentId, fields: unfilledOptional });
|
|
556
|
+
|
|
557
|
+
// What the model asked to set, in the component's own spelling. `correctedFields` maps each slip to
|
|
558
|
+
// the real name; everything else it named is already real.
|
|
559
|
+
const corrections = new Map(correctedFields.map((c) => [c.from, c.to]));
|
|
560
|
+
const unknown = new Set(unknownKeys);
|
|
561
|
+
namedKeys.push(
|
|
562
|
+
Object.keys(values)
|
|
563
|
+
.filter((k) => !unknown.has(k))
|
|
564
|
+
.map((k) => corrections.get(k) ?? k)
|
|
565
|
+
);
|
|
566
|
+
|
|
567
|
+
blocks.push({ componentId, args });
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
return { blocks, problems, gaps, optionalGaps, rejectedFields, invalidValues, replacedImages, namedKeys };
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Ceiling on generated images per turn.
|
|
575
|
+
*
|
|
576
|
+
* An image is the most expensive thing in this loop by an order of magnitude, and "build me a product
|
|
577
|
+
* page" could plausibly justify one per section. Three covers a hero plus a couple of supporting
|
|
578
|
+
* shots; beyond that the honest answer is that the library is missing imagery, which is a thing to fix
|
|
579
|
+
* in the library rather than paper over per page.
|
|
580
|
+
*/
|
|
581
|
+
const MAX_GENERATED_IMAGES_PER_TURN = 3;
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Budgets for the two catalog tools, both comfortably under the 24,000-character tool-result cap.
|
|
585
|
+
*
|
|
586
|
+
* Headroom on purpose: the cap is applied by slicing the serialized JSON, so a payload that reaches it
|
|
587
|
+
* is not merely trimmed but malformed. Staying clear of it means the slice never fires.
|
|
588
|
+
*/
|
|
589
|
+
const LIST_BLOCKS_BUDGET = 20_000;
|
|
590
|
+
const DESCRIBE_BLOCKS_BUDGET = 18_000;
|
|
591
|
+
/** Enough for a whole page's worth of blocks in one call, not the whole catalog. */
|
|
592
|
+
const MAX_DESCRIBED_BLOCKS = 12;
|
|
593
|
+
|
|
594
|
+
/** The tools that actually change the page. Requesting an image is not one of them. */
|
|
595
|
+
function isPlacementTool(name: string): boolean {
|
|
596
|
+
return name === 'propose_edits' || name === 'propose_page';
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/** A generation the turn kicked off. Carried back so the client knows what to poll for and swap. */
|
|
600
|
+
export interface QueuedImage {
|
|
601
|
+
jobId: number;
|
|
602
|
+
title: string;
|
|
603
|
+
placeholderSrc: string;
|
|
604
|
+
/**
|
|
605
|
+
* Set when the request could not even be enqueued. Carried back rather than swallowed: a failure
|
|
606
|
+
* that only the model sees is a failure the user experiences as nothing happening at all, which is
|
|
607
|
+
* exactly how the first live run presented.
|
|
608
|
+
*/
|
|
609
|
+
error?: string;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* A generation the model proposed but did not run. The library had nothing matching what the user
|
|
614
|
+
* named, and generating unasked spends their money — so the offer travels to the client, which renders
|
|
615
|
+
* a "Make an image" button. Clicking it sends the generation request as its own turn.
|
|
616
|
+
*/
|
|
617
|
+
export interface ImageOffer {
|
|
618
|
+
/** ZERO-based canvas position, same convention as propose_edits. */
|
|
619
|
+
index: number;
|
|
620
|
+
/** The validated image field on that block. */
|
|
621
|
+
field: string;
|
|
622
|
+
/** The generation brief, ready to hand back to `request_image` verbatim. */
|
|
623
|
+
prompt: string;
|
|
624
|
+
title: string;
|
|
625
|
+
altText?: string;
|
|
626
|
+
orientation?: string;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
interface ImageRequestContext {
|
|
630
|
+
/** FK to `user.id` — the job table requires it, so a turn with no user cannot generate. */
|
|
631
|
+
actorUserId: string | null;
|
|
632
|
+
/** Whether blocks are already on the canvas. Generation needs a slot that exists to swap into. */
|
|
633
|
+
hasCanvas: boolean;
|
|
634
|
+
/**
|
|
635
|
+
* The canvas itself, so `request_image` can check where the picture is going *before* generating it.
|
|
636
|
+
*
|
|
637
|
+
* Only `hasCanvas` was here, which is why the target could not be validated: the tool knew a page
|
|
638
|
+
* existed but not what was on it, so it could only hand back a src and hope.
|
|
639
|
+
*/
|
|
640
|
+
blocks: { componentId: string }[];
|
|
641
|
+
/** The workspace's design guidance, so generated imagery matches the system it is going into. */
|
|
642
|
+
styleGuidance: string;
|
|
643
|
+
queued: QueuedImage[];
|
|
644
|
+
/** Generations proposed for the user to trigger, not run. See `ImageOffer`. */
|
|
645
|
+
offers: ImageOffer[];
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
async function runTool(
|
|
649
|
+
name: string,
|
|
650
|
+
args: Record<string, unknown>,
|
|
651
|
+
preferredAssetIds: string[],
|
|
652
|
+
/** Collects every src the store returned, so an invented URL can be told from a real one. */
|
|
653
|
+
seenAssetSrcs?: Set<string>,
|
|
654
|
+
imageCtx?: ImageRequestContext
|
|
655
|
+
): Promise<unknown> {
|
|
656
|
+
const provider = getDataProvider();
|
|
657
|
+
|
|
658
|
+
if (name === 'list_blocks') {
|
|
659
|
+
const group = typeof args.group === 'string' ? args.group.toLowerCase().trim() : '';
|
|
660
|
+
// Projected list read: the rows below are built from group, id, title and the `should_do`/`shouldDo`/
|
|
661
|
+
// `description` purpose line — all list-shaped. `describe_blocks` keeps the full read, because the
|
|
662
|
+
// field summaries it returns are computed from the payload's capability keys.
|
|
663
|
+
let list = await provider.getComponentList();
|
|
664
|
+
if (group) list = list.filter((c) => (c.group || '').toLowerCase() === group);
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Selection, not authoring. Id, title, group and one line on what the block is *for*.
|
|
668
|
+
*
|
|
669
|
+
* This carried a field summary per component and came to 32,270 characters against a 24,000 cap
|
|
670
|
+
* applied by slicing the serialized string — so 16 of 77 components silently never arrived, the last
|
|
671
|
+
* of them alphabetically after `simple-copy`, and the payload was invalid JSON. A ten-section brief
|
|
672
|
+
* came back as six consecutive `simple-copy` blocks because the alternatives were not in the list.
|
|
673
|
+
*
|
|
674
|
+
* The purpose line is the other half. The registry has held an authored description for every block
|
|
675
|
+
* all along and this sent none of it, so the model chose from ids and field names — and
|
|
676
|
+
* `simple-copy`, whose own guidance says "legal pages, terms, and informational text", looks like a
|
|
677
|
+
* safe default for any text at all.
|
|
678
|
+
*
|
|
679
|
+
* Field shapes come from `describe_blocks` for the handful actually chosen. Cheaper as well as
|
|
680
|
+
* complete: this result is replayed on every subsequent round of the loop, so the full catalog's
|
|
681
|
+
* field summaries were being paid for repeatedly.
|
|
682
|
+
*/
|
|
683
|
+
const rows = list.map((c) => ({
|
|
684
|
+
id: c.id,
|
|
685
|
+
title: c.title,
|
|
686
|
+
group: c.group,
|
|
687
|
+
/**
|
|
688
|
+
* Authored guidance first, description second.
|
|
689
|
+
*
|
|
690
|
+
* `should_do[0]` is written as an instruction — "Use for simple copy blocks such as legal pages,
|
|
691
|
+
* terms, and informational text" — and it is the line that discriminates. The description says
|
|
692
|
+
* "a component for simple rich-text copy blocks with optional CTA buttons", which sounds ideal for
|
|
693
|
+
* any copy section and is why five of them ended up on a marketing page. It is also *shorter*:
|
|
694
|
+
* 10.5k for the whole catalog against 11.9k.
|
|
695
|
+
*/
|
|
696
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
697
|
+
use: purposeLine((c as any).should_do?.[0] ?? (c as any).shouldDo?.[0] ?? (c as any).description),
|
|
698
|
+
}));
|
|
699
|
+
|
|
700
|
+
const packed = packToBudget(rows, LIST_BLOCKS_BUDGET);
|
|
701
|
+
const note = truncationNote(
|
|
702
|
+
packed.dropped,
|
|
703
|
+
rows.length,
|
|
704
|
+
'Call list_blocks again with a `group` to see the rest.'
|
|
705
|
+
);
|
|
706
|
+
return note ? { blocks: packed.items, note } : packed.items;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
if (name === 'describe_blocks') {
|
|
710
|
+
const ids = Array.isArray(args.ids) ? args.ids.map((i) => String(i).trim()).filter(Boolean) : [];
|
|
711
|
+
if (!ids.length) return { error: 'Pass the ids of the blocks you intend to use.' };
|
|
712
|
+
|
|
713
|
+
const list = await provider.getComponents();
|
|
714
|
+
const byId = new Map(list.map((c) => [String(c.id), c]));
|
|
715
|
+
const missing = ids.filter((id) => !byId.has(id));
|
|
716
|
+
|
|
717
|
+
const rows = ids
|
|
718
|
+
.slice(0, MAX_DESCRIBED_BLOCKS)
|
|
719
|
+
.map((id) => byId.get(id))
|
|
720
|
+
.filter((c): c is NonNullable<typeof c> => !!c)
|
|
721
|
+
.map((c) => {
|
|
722
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
723
|
+
const comp = c as any;
|
|
724
|
+
// Shapes from a real preview's values, so `buttonSlots` is described as whatever this component
|
|
725
|
+
// actually uses rather than guessed from its declared type.
|
|
726
|
+
const previews = (comp?.previews ?? {}) as Record<string, { values?: Record<string, unknown> }>;
|
|
727
|
+
const key = resolvePreviewKey(previews, 'seed');
|
|
728
|
+
const values = key ? (previews[key]?.values ?? (previews[key] as Record<string, unknown>)) : null;
|
|
729
|
+
return {
|
|
730
|
+
id: c.id,
|
|
731
|
+
title: c.title,
|
|
732
|
+
fields: summarizeFields(
|
|
733
|
+
comp?.properties ?? null,
|
|
734
|
+
values as Record<string, unknown> | null,
|
|
735
|
+
undefined,
|
|
736
|
+
readCapabilities(comp)
|
|
737
|
+
),
|
|
738
|
+
};
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
const packed = packToBudget(rows, DESCRIBE_BLOCKS_BUDGET);
|
|
742
|
+
return {
|
|
743
|
+
blocks: packed.items,
|
|
744
|
+
...(missing.length ? { unknownIds: missing } : {}),
|
|
745
|
+
...(ids.length > MAX_DESCRIBED_BLOCKS
|
|
746
|
+
? { note: `Only the first ${MAX_DESCRIBED_BLOCKS} ids were described; ask again for the rest.` }
|
|
747
|
+
: {}),
|
|
748
|
+
...(packed.dropped
|
|
749
|
+
? { note: truncationNote(packed.dropped, rows.length, 'Ask for fewer blocks at a time.') }
|
|
750
|
+
: {}),
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
if (name === 'search_assets') {
|
|
755
|
+
const { listAssets } = await import('@/lib/db/queries');
|
|
756
|
+
const { findAssets } = await import('@/lib/server/find-assets');
|
|
757
|
+
const q = typeof args.query === 'string' ? args.query.trim() : '';
|
|
758
|
+
// Two queries rather than one: the search narrows by the asset's text, but anything the user attached
|
|
759
|
+
// must surface regardless of what they called it — they uploaded it FOR this page.
|
|
760
|
+
//
|
|
761
|
+
// `findAssets` owns the precise-then-loose policy so MCP's search behaves the same way. It lived here
|
|
762
|
+
// inline, which is exactly how MCP ended up with the term matching and none of the fallback.
|
|
763
|
+
const [found, all] = await Promise.all([
|
|
764
|
+
findAssets({ assetType: 'image', status: 'active', limit: 60, ...(q ? { search: q } : {}) }),
|
|
765
|
+
preferredAssetIds.length ? listAssets({ assetType: 'image', status: 'active', limit: 200 }) : Promise.resolve([]),
|
|
766
|
+
]);
|
|
767
|
+
const matches = found.rows;
|
|
768
|
+
const attachedRows = all.filter((r) => preferredAssetIds.includes(String(r.id)));
|
|
769
|
+
|
|
770
|
+
const seen = new Set<string>();
|
|
771
|
+
const out: { id: string; name: string; src: string; alt: string; attached: boolean }[] = [];
|
|
772
|
+
for (const r of [...attachedRows, ...matches]) {
|
|
773
|
+
const id = String(r.id ?? '');
|
|
774
|
+
// `storageUrl` and `title` are the real column names — `url`/`name` do not exist on this table,
|
|
775
|
+
// and getting them wrong returns rows whose src is empty, which renders as a broken image.
|
|
776
|
+
const src = String(r.storageUrl ?? '');
|
|
777
|
+
if (!id || !src || seen.has(id)) continue;
|
|
778
|
+
seen.add(id);
|
|
779
|
+
out.push({ id, name: String(r.title ?? ''), src, alt: String(r.altText ?? ''), attached: preferredAssetIds.includes(id) });
|
|
780
|
+
}
|
|
781
|
+
for (const a of out) seenAssetSrcs?.add(a.src);
|
|
782
|
+
|
|
783
|
+
const results = out.slice(0, 25);
|
|
784
|
+
// A loose match is weaker evidence and the model should be able to tell: "students" returned for
|
|
785
|
+
// "lecture hall" may be the right picture or merely the nearest one. The shared note ends at "say
|
|
786
|
+
// so" because MCP has no generator; here the way out is `offer_image` — without a named
|
|
787
|
+
// alternative the model settled for the nearest match ("abstract waves" for "abstract circles").
|
|
788
|
+
const note =
|
|
789
|
+
looseMatchNote(q) +
|
|
790
|
+
(imageCtx?.hasCanvas
|
|
791
|
+
? ' When the user asked for specific content none of these show, call `offer_image` instead of settling for the nearest match.'
|
|
792
|
+
: '');
|
|
793
|
+
return found.loose ? { results, note } : results;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
if (name === 'request_image') {
|
|
797
|
+
if (!imageCtx?.actorUserId) {
|
|
798
|
+
return { error: 'Image generation is unavailable in this session. Leave the image empty.' };
|
|
799
|
+
}
|
|
800
|
+
// **No canvas, no generation.** A picture made while composing a page that has not been applied has
|
|
801
|
+
// nowhere to land: the slot does not exist yet, so the swap finds nothing and the image waits
|
|
802
|
+
// forever. Two live runs died exactly there. Propose the page with placeholders, let the user apply
|
|
803
|
+
// it, then fill — by which point every slot is real and the swap always has a target.
|
|
804
|
+
if (!imageCtx.hasCanvas) {
|
|
805
|
+
return {
|
|
806
|
+
error:
|
|
807
|
+
'No page is on the canvas yet, so a generated image would have nowhere to go. Propose the page ' +
|
|
808
|
+
'with placeholders in the image fields, tell the user which slots are unfilled, and offer to ' +
|
|
809
|
+
'fill them once they apply it.',
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
if (imageCtx.queued.length >= MAX_GENERATED_IMAGES_PER_TURN) {
|
|
813
|
+
return {
|
|
814
|
+
error: `Already generating ${MAX_GENERATED_IMAGES_PER_TURN} images this turn, which is the cap. Use a library asset or leave the image empty.`,
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
const prompt = typeof args.prompt === 'string' ? args.prompt.trim() : '';
|
|
819
|
+
const title = typeof args.title === 'string' && args.title.trim() ? args.title.trim() : 'Generated image';
|
|
820
|
+
if (!prompt) return { error: 'A prompt is required.' };
|
|
821
|
+
|
|
822
|
+
// **Resolve the destination before spending anything.** Generation costs real money and a minute of
|
|
823
|
+
// compute; a target that turns out not to exist afterwards is a paid-for image with nowhere to go,
|
|
824
|
+
// which is precisely what shipped. Rejecting here is free, and the error names the real fields so
|
|
825
|
+
// the retry is informed rather than a second guess.
|
|
826
|
+
const scaffold = await scaffoldArgsForComponent(
|
|
827
|
+
imageCtx.blocks[Number(args.index)]?.componentId ?? ''
|
|
828
|
+
).catch(() => null);
|
|
829
|
+
const target = resolveImageTarget({
|
|
830
|
+
blocks: imageCtx.blocks,
|
|
831
|
+
index: args.index,
|
|
832
|
+
field: args.field,
|
|
833
|
+
fields: scaffold && !('error' in scaffold) ? scaffold.fields : undefined,
|
|
834
|
+
});
|
|
835
|
+
// `'error' in target`, not `!target.ok`. The app compiles with `strictNullChecks: false`, and under
|
|
836
|
+
// that setting TypeScript does not narrow a union on a boolean discriminant — `!target.ok` leaves
|
|
837
|
+
// the type unnarrowed and `target.error` fails to compile. The `in` operator narrows under both
|
|
838
|
+
// settings, and is the idiom the scaffold check above already uses.
|
|
839
|
+
if ('error' in target) {
|
|
840
|
+
// Logged, because a run that burns nine `request_image` calls to queue three images is invisible
|
|
841
|
+
// otherwise — the tool result goes to the model and nowhere else, so the loop looks like the model
|
|
842
|
+
// being indecisive rather than a target it keeps getting wrong.
|
|
843
|
+
console.warn('[playground-chat] image target refused', { index: args.index, field: args.field, reason: target.error });
|
|
844
|
+
return { error: target.error };
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// The slot says what shape it wants; the model's `orientation` is only the fallback for a slot that
|
|
848
|
+
// declares nothing. Same picker the block editor's Generate uses, so both entry points agree — and
|
|
849
|
+
// gpt-image-2 takes any legal resolution, so a 1120x2080 slot gets exactly that rather than the
|
|
850
|
+
// nearest of four presets.
|
|
851
|
+
const slotDims = (scaffold && !('error' in scaffold) ? scaffold.fields[target.field] : undefined) as
|
|
852
|
+
| { dimensions?: { width: number; height: number } }
|
|
853
|
+
| undefined;
|
|
854
|
+
const orientation = typeof args.orientation === 'string' ? args.orientation : 'landscape';
|
|
855
|
+
const fallback: GeneratedImageSize =
|
|
856
|
+
orientation === 'portrait' ? '1024x1536' : orientation === 'square' ? '1024x1024' : '1536x1024';
|
|
857
|
+
const size = slotDims?.dimensions ? sizeForDimensions({ recommended: slotDims.dimensions }) : fallback;
|
|
858
|
+
const [w, h] = parseSize(size);
|
|
859
|
+
|
|
860
|
+
// The placeholder is returned *now* so the proposal is complete and applicable immediately. It is
|
|
861
|
+
// also registered as a known src, or `mergeBlockValues` would strip it as fabricated — the same
|
|
862
|
+
// guard that stops the model inventing asset URLs.
|
|
863
|
+
const placeholderSrc = placeholderImageUrl(w, h, title);
|
|
864
|
+
seenAssetSrcs?.add(placeholderSrc);
|
|
865
|
+
|
|
866
|
+
const { insertDesignGenerationJob } = await import('@/lib/db/queries');
|
|
867
|
+
let jobId: number;
|
|
868
|
+
try {
|
|
869
|
+
jobId = await insertDesignGenerationJob({
|
|
870
|
+
artifactId: null,
|
|
871
|
+
userId: imageCtx.actorUserId,
|
|
872
|
+
requestParams: {
|
|
873
|
+
intent: 'asset',
|
|
874
|
+
// Same composition the block editor's Generate uses — the no-text rule and the house style
|
|
875
|
+
// matter identically from either entry point, and generated lettering is the failure most
|
|
876
|
+
// likely to be mistaken for a real word on a marketing page.
|
|
877
|
+
prompt: buildImagePrompt(prompt, imageCtx.styleGuidance),
|
|
878
|
+
title,
|
|
879
|
+
altText: typeof args.altText === 'string' ? args.altText : title,
|
|
880
|
+
size,
|
|
881
|
+
quality: 'medium',
|
|
882
|
+
tags: ['playground'],
|
|
883
|
+
brief: prompt,
|
|
884
|
+
placeholderSrc,
|
|
885
|
+
},
|
|
886
|
+
});
|
|
887
|
+
} catch (err) {
|
|
888
|
+
// Logged, and reported to the user via the images card — not just handed back to the model,
|
|
889
|
+
// which may narrate success regardless.
|
|
890
|
+
const message = summarizeError(err);
|
|
891
|
+
console.error('[playground-chat] could not enqueue image generation', message);
|
|
892
|
+
imageCtx.queued.push({ jobId: 0, title, placeholderSrc, error: message });
|
|
893
|
+
return { error: `Could not start image generation: ${message}. Use the placeholder src anyway.`, src: placeholderSrc };
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
console.log('[playground-chat] queued image generation', { jobId, title, target: `${target.position}.${target.field}` });
|
|
897
|
+
imageCtx.queued.push({ jobId, title, placeholderSrc });
|
|
898
|
+
// The value, already in the encoding this slot was measured to accept — not a src for the model to
|
|
899
|
+
// wrap however it guesses. `array-of-image-object` needs a one-item array, and an object there is
|
|
900
|
+
// the same silent no-op in a different costume.
|
|
901
|
+
return {
|
|
902
|
+
value: valueForImageTarget(target.encoding, {
|
|
903
|
+
src: placeholderSrc,
|
|
904
|
+
alt: typeof args.altText === 'string' ? args.altText : title,
|
|
905
|
+
}),
|
|
906
|
+
status: 'generating',
|
|
907
|
+
note: describeImagePlacement(target),
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
if (name === 'offer_image') {
|
|
912
|
+
if (!imageCtx) return { error: 'Offers are unavailable in this session.' };
|
|
913
|
+
if (!imageCtx.hasCanvas) {
|
|
914
|
+
return {
|
|
915
|
+
error:
|
|
916
|
+
'No page is on the canvas yet, so there is no slot to offer generation for. Propose the page ' +
|
|
917
|
+
'with placeholders and name the slots you left empty instead.',
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
const prompt = typeof args.prompt === 'string' ? args.prompt.trim() : '';
|
|
921
|
+
const title = typeof args.title === 'string' && args.title.trim() ? args.title.trim() : 'Generated image';
|
|
922
|
+
if (!prompt) return { error: 'A prompt is required.' };
|
|
923
|
+
|
|
924
|
+
// Same pre-flight as request_image, for the same reason it exists there: an offer whose target turns
|
|
925
|
+
// out not to exist becomes a button that fails when pressed, which reads as the feature being broken.
|
|
926
|
+
const scaffold = await scaffoldArgsForComponent(
|
|
927
|
+
imageCtx.blocks[Number(args.index)]?.componentId ?? ''
|
|
928
|
+
).catch(() => null);
|
|
929
|
+
const target = resolveImageTarget({
|
|
930
|
+
blocks: imageCtx.blocks,
|
|
931
|
+
index: args.index,
|
|
932
|
+
field: args.field,
|
|
933
|
+
fields: scaffold && !('error' in scaffold) ? scaffold.fields : undefined,
|
|
934
|
+
});
|
|
935
|
+
if ('error' in target) {
|
|
936
|
+
console.warn('[playground-chat] image offer target refused', { index: args.index, field: args.field, reason: target.error });
|
|
937
|
+
return { error: target.error };
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
imageCtx.offers.push({
|
|
941
|
+
index: target.position,
|
|
942
|
+
field: target.field,
|
|
943
|
+
prompt,
|
|
944
|
+
title,
|
|
945
|
+
altText: typeof args.altText === 'string' ? args.altText : undefined,
|
|
946
|
+
orientation: typeof args.orientation === 'string' ? args.orientation : undefined,
|
|
947
|
+
});
|
|
948
|
+
return {
|
|
949
|
+
status: 'offered',
|
|
950
|
+
note:
|
|
951
|
+
'The user now sees a "Make an image" button for this slot; do not call request_image for it this ' +
|
|
952
|
+
'turn. Reply with ONE short question ("Nothing in the library matched X — want me to make that ' +
|
|
953
|
+
'image?") and do not mention the button or say you added an option.',
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
if (name === 'search_icons') {
|
|
958
|
+
const q = typeof args.query === 'string' ? args.query.toLowerCase().trim() : '';
|
|
959
|
+
const catalog = await provider.getIconCatalog();
|
|
960
|
+
const hits = q
|
|
961
|
+
? catalog.filter(
|
|
962
|
+
(e) =>
|
|
963
|
+
e.name.toLowerCase().includes(q) ||
|
|
964
|
+
(e.description ?? '').toLowerCase().includes(q) ||
|
|
965
|
+
(e.tags ?? []).some((t) => t.toLowerCase().includes(q))
|
|
966
|
+
)
|
|
967
|
+
: catalog;
|
|
968
|
+
// Names and tags only. Icon SVG bodies are large and get re-sent on every subsequent round of the
|
|
969
|
+
// loop, so the full catalog entry is exactly the wrong thing to put in a tool result.
|
|
970
|
+
return hits.slice(0, 30).map((e) => ({ name: e.name, category: e.category, tags: (e.tags ?? []).slice(0, 6) }));
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
return { error: `Unknown tool "${name}".` };
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
function systemPrompt(
|
|
977
|
+
brandVoice: string,
|
|
978
|
+
designMd: string,
|
|
979
|
+
attachedCount: number,
|
|
980
|
+
composition: string,
|
|
981
|
+
targetNote = ''
|
|
982
|
+
): string {
|
|
983
|
+
const exemplars = formatExemplars();
|
|
984
|
+
return `You compose landing pages in a design-system playground by assembling EXISTING blocks.
|
|
985
|
+
|
|
986
|
+
You do not write CSS. You choose blocks from the catalog, write their copy, and fill their props with
|
|
987
|
+
values shaped exactly as the scaffold tells you.
|
|
988
|
+
|
|
989
|
+
## How to work — this should take two or three tool calls, not ten
|
|
990
|
+
1. Ask ONE round of clarifying questions if the request is genuinely vague. One round only.
|
|
991
|
+
2. \`list_blocks\` ONCE, with no arguments. That is the entire catalog with every block's fields. Read
|
|
992
|
+
it and choose. Do NOT call it repeatedly for different sections.
|
|
993
|
+
3. **Decide the whole page** — every block, in order, with its copy written.
|
|
994
|
+
4. \`search_assets\` for the image fields, and \`search_icons\` if the page needs icons. Use whatever the
|
|
995
|
+
store already has.
|
|
996
|
+
5. \`propose_page\` with all the blocks, your copy, and any srcs those searches returned.
|
|
997
|
+
|
|
998
|
+
**The turn is not finished until \`propose_page\` runs.** A page the user can apply is the deliverable.
|
|
999
|
+
|
|
1000
|
+
## Imagery comes after the page, not during it
|
|
1001
|
+
Building a page and generating pictures are two turns, deliberately:
|
|
1002
|
+
|
|
1003
|
+
- **Composing a new page:** leave image fields on their placeholders. \`request_image\` is unavailable —
|
|
1004
|
+
a picture generated now has nowhere to land, because the slot does not exist until the page is
|
|
1005
|
+
applied. Propose the page, name the slots you left empty, and offer to fill them once it is applied.
|
|
1006
|
+
- **A page already on the canvas:** \`request_image\` works normally, and generated pictures swap into
|
|
1007
|
+
their slots as they finish.
|
|
1008
|
+
|
|
1009
|
+
This also means the user sees the page before paying for images, and can say which ones they actually
|
|
1010
|
+
want.
|
|
1011
|
+
|
|
1012
|
+
You do not need to inspect a block before using it — the fields listed by \`list_blocks\` are all you
|
|
1013
|
+
need, and the server applies your values to the block's real shape. Write copy, not structure.
|
|
1014
|
+
|
|
1015
|
+
## Filling blocks
|
|
1016
|
+
- **Write every content field.** Nothing is filled in for you; a field you skip ships empty. This is
|
|
1017
|
+
the most common way a generated page looks unfinished.
|
|
1018
|
+
- **Arrays need every item.** Four stats means four entries, each with its own copy — not one.
|
|
1019
|
+
- **Match the shape \`list_blocks\` shows for each field, exactly.** It is taken from what the block
|
|
1020
|
+
really renders. \`plain text\` means no markup — wrapping it in \`<p>\` puts visible tags on the page.
|
|
1021
|
+
\`HTML, e.g. <h1>…\` means write that markup. \`{ url, text }\` means those keys, not \`label\`.
|
|
1022
|
+
- **\`array of { … } — write EVERY item\`** means every item, fully filled. Four stats means four
|
|
1023
|
+
entries each with its own numbers and copy. An array of empty objects is worse than no array.
|
|
1024
|
+
- Image fields already hold a correctly-proportioned placeholder. Replace \`src\` only with a src a
|
|
1025
|
+
tool gave you — \`search_assets\` or \`request_image\`. Never write an image path yourself.
|
|
1026
|
+
- **Search before you generate.** A real photo from the library beats a generated one, and generation
|
|
1027
|
+
costs real money. Use \`request_image\` only where the page genuinely needs a picture the library
|
|
1028
|
+
does not have — a hero, a main feature shot. Leave decorative slots on their placeholder. It is only
|
|
1029
|
+
available once a page is on the canvas; see above.
|
|
1030
|
+
- **Never substitute a near-miss for a named picture.** When the user names what the picture should
|
|
1031
|
+
show ("add an image of…", "change the background to…"), a library asset is only a match if it
|
|
1032
|
+
actually shows that. If search returns nothing better than a near-miss, do NOT generate on your own
|
|
1033
|
+
and do NOT swap in the nearest library image — call \`offer_image\` with the slot and a generation
|
|
1034
|
+
brief, and tell the user nothing in the library matches, so they get a button to generate it.
|
|
1035
|
+
Only call \`request_image\` directly when the user has explicitly asked you to generate.
|
|
1036
|
+
- **\`request_image\` does not put anything on the page.** It returns a src; you must still write that
|
|
1037
|
+
src into the block with \`propose_edits\` (or \`propose_page\`) in the same turn. Requesting an image
|
|
1038
|
+
and then only describing it leaves the page unchanged — this is the most common way to get this
|
|
1039
|
+
wrong. Mention the generation in your reply *as well as* making the edit, never instead of it.
|
|
1040
|
+
- Choosing then authoring is two calls: \`list_blocks\` once to see every block and what each is for,
|
|
1041
|
+
then one \`describe_blocks\` call naming every block you decided on, which gives you their field
|
|
1042
|
+
names and shapes. Several blocks hold copy and they are not interchangeable — \`simple-copy\` is for
|
|
1043
|
+
legal and informational text, not for a marketing section that wants media beside it.
|
|
1044
|
+
- A full page normally opens with the \`header\` block and closes with \`footer\`, both with empty
|
|
1045
|
+
values — they are site chrome with nothing to author. Omit them when asked for a single section.
|
|
1046
|
+
${attachedCount > 0 ? `\nThe user attached ${attachedCount} image(s) to this conversation. They are in the asset store and marked \`attached: true\` in search_assets results — prefer them.\n` : ''}${composition ? `\n## Already on the canvas\n${composition}\n\nA follow-up almost certainly refers to one of these. Use \`propose_edits\` to change them — the numbering above is 1-based for reading, so block 1 is index 0. Only use \`propose_page\` if the user wants to start over.\n` : ''}${targetNote}
|
|
1047
|
+
## What a finished page looks like here
|
|
1048
|
+
Real pages on this site run to a dozen sections or more, and they alternate background treatment —
|
|
1049
|
+
a coloured band every third or fourth section, never one flat colour throughout. A four-section page
|
|
1050
|
+
reads as a fragment. Follow whichever shape fits, adapting the sections to the brief:
|
|
1051
|
+
|
|
1052
|
+
${exemplars}
|
|
1053
|
+
|
|
1054
|
+
Backgrounds: pick real values from the field's own \`one of …\` list. The hero and the final CTA
|
|
1055
|
+
usually carry a brand colour; light and white alternate between them; a dark section breaks up the
|
|
1056
|
+
middle. Never set the same background on every block.
|
|
1057
|
+
|
|
1058
|
+
## Copy
|
|
1059
|
+
Write real copy, not placeholders. It must obey the brand voice below.
|
|
1060
|
+
${brandVoice ? `\n### Brand voice\n${brandVoice.slice(0, 4000)}\n` : ''}${designMd ? `\n### Design guidelines\n${designMd.slice(0, 2000)}\n` : ''}
|
|
1061
|
+
Keep replies short. The user is watching a page get built, not reading an essay.
|
|
1062
|
+
|
|
1063
|
+
**Describe only what you actually did.** If image slots are still on placeholders, say so — "I left the
|
|
1064
|
+
gallery images empty, ask me to generate them" is useful. Claiming imagery you did not add is worse than
|
|
1065
|
+
leaving an obvious gap, because the gap is visible and the claim is not.`;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
export async function runPlaygroundChatTurn(args: {
|
|
1069
|
+
messages: PlaygroundChatMessage[];
|
|
1070
|
+
attachedAssetIds?: string[];
|
|
1071
|
+
actorUserId?: string | null;
|
|
1072
|
+
/** Progress sink. Omit for a plain awaited turn — the loop behaves identically either way. */
|
|
1073
|
+
onEvent?: (event: PlaygroundChatEvent) => void;
|
|
1074
|
+
/** Aborts between rounds. Without it, a closed tab leaves the loop running and burning tokens. */
|
|
1075
|
+
signal?: AbortSignal;
|
|
1076
|
+
/** What is currently on the canvas, so a follow-up can refer to it. Summarised, never sent whole. */
|
|
1077
|
+
currentBlocks?: { componentId: string; args?: Record<string, unknown> }[];
|
|
1078
|
+
/**
|
|
1079
|
+
* Index into `currentBlocks` of the block the user selected on the canvas, or null for the whole page.
|
|
1080
|
+
* A selection scopes the prompt: the request is about THIS block, and only it may be edited.
|
|
1081
|
+
*/
|
|
1082
|
+
targetBlockIndex?: number | null;
|
|
1083
|
+
}): Promise<PlaygroundChatTurn> {
|
|
1084
|
+
const emit = args.onEvent ?? (() => {});
|
|
1085
|
+
const attached = args.attachedAssetIds ?? [];
|
|
1086
|
+
const workspace = await getDesignWorkspace().catch(() => null);
|
|
1087
|
+
const brandVoice = workspace ? formatBrandVoiceForPrompt(workspace.brandVoice).trim() : '';
|
|
1088
|
+
|
|
1089
|
+
// Annotated with each block's image fields, resolved from its measured capabilities. One scaffold
|
|
1090
|
+
// lookup per block, once per turn — cheap against the alternative, which was the model guessing a
|
|
1091
|
+
// field name and stranding an image it had already paid for.
|
|
1092
|
+
const canvas = args.currentBlocks ?? [];
|
|
1093
|
+
const composition = summarizeComposition(
|
|
1094
|
+
await Promise.all(
|
|
1095
|
+
canvas.map(async (b) => {
|
|
1096
|
+
const scaffold = await scaffoldArgsForComponent(b.componentId).catch(() => null);
|
|
1097
|
+
return {
|
|
1098
|
+
...b,
|
|
1099
|
+
imageFields: scaffold && !('error' in scaffold) ? imageFieldsFor(scaffold.fields) : [],
|
|
1100
|
+
};
|
|
1101
|
+
})
|
|
1102
|
+
)
|
|
1103
|
+
);
|
|
1104
|
+
/**
|
|
1105
|
+
* The canvas selection, as an instruction rather than a hint. The index is validated by the route
|
|
1106
|
+
* against the same request's canvas, so `canvas[targetBlockIndex]` is always a real block here.
|
|
1107
|
+
*/
|
|
1108
|
+
const target = typeof args.targetBlockIndex === 'number' ? canvas[args.targetBlockIndex] : undefined;
|
|
1109
|
+
const targetNote = target
|
|
1110
|
+
? `\n## Selected block\nThe user has SELECTED block ${args.targetBlockIndex! + 1} (${target.componentId}) on the canvas. ` +
|
|
1111
|
+
`Their request is about this block. Update, replace or remove ONLY it, via \`propose_edits\` targeting index ${args.targetBlockIndex} ` +
|
|
1112
|
+
`— changes to any other existing block will be rejected; the user deselects to edit the rest of the page. ` +
|
|
1113
|
+
`INSERTING new blocks is still allowed, at any position — "add a banner below this" means insert at index ${args.targetBlockIndex + 1}.\n`
|
|
1114
|
+
: '';
|
|
1115
|
+
const convo: unknown[] = [
|
|
1116
|
+
{ role: 'system', content: systemPrompt(brandVoice, workspace?.designMd ?? '', attached.length, composition, targetNote) },
|
|
1117
|
+
...args.messages.map((m) => ({ role: m.role, content: m.content })),
|
|
1118
|
+
];
|
|
1119
|
+
// Repeated NEXT TO the latest message, not only in the system prompt: a conversation whose history is
|
|
1120
|
+
// full of edits to some other block anchors the model harder than a note it read pages ago — observed
|
|
1121
|
+
// as three wrong-block edits in a row with the selection plainly set.
|
|
1122
|
+
if (target) {
|
|
1123
|
+
convo.push({
|
|
1124
|
+
role: 'system',
|
|
1125
|
+
content: `Reminder: the user's selection is block ${args.targetBlockIndex! + 1} (${target.componentId}), index ${args.targetBlockIndex}. This message overrides any other block the conversation above focused on.`,
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
const toolsUsed: string[] = [];
|
|
1130
|
+
const seenAssetSrcs = new Set<string>();
|
|
1131
|
+
const imageCtx: ImageRequestContext = {
|
|
1132
|
+
actorUserId: args.actorUserId ?? null,
|
|
1133
|
+
hasCanvas: (args.currentBlocks ?? []).length > 0,
|
|
1134
|
+
blocks: (args.currentBlocks ?? []).map((b) => ({ componentId: b.componentId })),
|
|
1135
|
+
styleGuidance: workspace?.designMd ?? '',
|
|
1136
|
+
queued: [],
|
|
1137
|
+
offers: [],
|
|
1138
|
+
};
|
|
1139
|
+
/**
|
|
1140
|
+
* Announce any generations this turn started, immediately before the turn ends.
|
|
1141
|
+
*
|
|
1142
|
+
* Every terminal path calls this rather than each remembering to: the images were enqueued during
|
|
1143
|
+
* the tool loop and are already running, so a return that forgets to report them leaves the user
|
|
1144
|
+
* with placeholders that silently become real, or never do.
|
|
1145
|
+
*/
|
|
1146
|
+
const finish = <T extends PlaygroundChatTurn>(turn: T): T => {
|
|
1147
|
+
if (imageCtx.queued.length) emit({ type: 'images', queued: imageCtx.queued });
|
|
1148
|
+
if (imageCtx.offers.length) emit({ type: 'image_offers', offers: imageCtx.offers });
|
|
1149
|
+
|
|
1150
|
+
// Record what the turn *did*, not what it said. Prose is exactly what goes wrong — a page was
|
|
1151
|
+
// narrated in detail that had never been proposed — so the tool sequence and every retry reason go
|
|
1152
|
+
// to the log where one run can be diagnosed instead of inferred.
|
|
1153
|
+
const proposedBlocks = turn.proposal?.blocks ?? [];
|
|
1154
|
+
/**
|
|
1155
|
+
* Where a generated image could have landed — a proposed block, or an edit op's values.
|
|
1156
|
+
*
|
|
1157
|
+
* `unplacedImages` counted only proposal blocks, so **every changeset that generated an image was
|
|
1158
|
+
* logged as stranding it**, however correctly it was placed. Caught by the eval suite: after the
|
|
1159
|
+
* placement fix `gallery-four-images` went green while `fill-the-images` stayed red on the
|
|
1160
|
+
* invariant alone, with its own placement check passing — the two disagreeing is what exposed it.
|
|
1161
|
+
* A metric that cries wolf on a working path is worse than no metric; this was in production logs.
|
|
1162
|
+
*/
|
|
1163
|
+
const placedIn = proposedBlocks.length
|
|
1164
|
+
? proposedBlocks
|
|
1165
|
+
: (turn.changeset?.ops ?? []).map((op) => ({
|
|
1166
|
+
args: ('values' in op ? op.values : {}) as Record<string, unknown>,
|
|
1167
|
+
}));
|
|
1168
|
+
const facts: TurnFacts = {
|
|
1169
|
+
prompt: (args.messages.filter((m) => m.role === 'user').pop()?.content ?? '').slice(0, 500),
|
|
1170
|
+
rounds: roundsUsed,
|
|
1171
|
+
toolsUsed,
|
|
1172
|
+
retries,
|
|
1173
|
+
outcome: turn.proposal ? 'proposal' : turn.changeset ? 'changeset' : exhaustedTurn ? 'exhausted' : 'reply-only',
|
|
1174
|
+
hasCanvas: imageCtx.hasCanvas,
|
|
1175
|
+
blocks: proposedBlocks.length,
|
|
1176
|
+
queuedImages: imageCtx.queued.length,
|
|
1177
|
+
placeholderImages: findPlaceholderImages(proposedBlocks).length,
|
|
1178
|
+
unplacedImages: findUnplacedImages(placedIn, imageCtx.queued).length,
|
|
1179
|
+
durationMs: Date.now() - startedAt,
|
|
1180
|
+
};
|
|
1181
|
+
console.log('[playground-chat]', describeTurn(facts));
|
|
1182
|
+
void logAiEvent({
|
|
1183
|
+
eventType: 'ai.playground_turn',
|
|
1184
|
+
// Not a model call — a summary of the whole turn, which may span several. The model column is
|
|
1185
|
+
// required, so it names the loop rather than pretending to be one request.
|
|
1186
|
+
model: 'playground-chat-turn',
|
|
1187
|
+
actorUserId: args.actorUserId ?? undefined,
|
|
1188
|
+
route: '/api/handoff/ai/playground-chat',
|
|
1189
|
+
durationMs: facts.durationMs,
|
|
1190
|
+
status: Object.values(flagsFor(facts)).some(Boolean) ? 'error' : 'success',
|
|
1191
|
+
metadata: { ...facts, flags: flagsFor(facts) },
|
|
1192
|
+
}).catch(() => {});
|
|
1193
|
+
|
|
1194
|
+
return { ...turn, facts, ...(imageCtx.queued.length ? { queuedImages: imageCtx.queued } : {}) };
|
|
1195
|
+
};
|
|
1196
|
+
// One retry only; see the gap handler below.
|
|
1197
|
+
const startedAt = Date.now();
|
|
1198
|
+
const retries: TurnRetry[] = [];
|
|
1199
|
+
/** Every guard that fired, so a failed turn can be read from the log instead of inferred from prose. */
|
|
1200
|
+
const noteRetry = (kind: string, detail?: string) => retries.push({ kind, ...(detail ? { detail } : {}) });
|
|
1201
|
+
|
|
1202
|
+
/** One-shot: the whole-page-rebuild refusal fires once, then the model's second choice stands. */
|
|
1203
|
+
let refusedWholePageRebuild = false;
|
|
1204
|
+
/** Two one-shots, not one — see `GapAsks`. They were a single flag and the first silenced the other. */
|
|
1205
|
+
const askedForGaps: GapAsks = { rejectedValues: false, emptyContent: false };
|
|
1206
|
+
// Likewise one-shot: ask once for imagery the composition left on placeholders.
|
|
1207
|
+
let askedForImages = false;
|
|
1208
|
+
// Likewise: nudge once if images were requested but never written into a block.
|
|
1209
|
+
let askedToPlaceImages = false;
|
|
1210
|
+
|
|
1211
|
+
/**
|
|
1212
|
+
* The last page we actually built, kept so a retry can never destroy it.
|
|
1213
|
+
*
|
|
1214
|
+
* Every guard that asks the model to try again is a chance for it to answer with prose instead, and
|
|
1215
|
+
* then the turn ends with nothing to apply — a page that existed, was set aside to ask for one
|
|
1216
|
+
* improvement, and never came back. That is not a hypothetical: reporting three rejected image srcs
|
|
1217
|
+
* turned a working eight-block proposal into a reply claiming "no placeholders or broken links" and
|
|
1218
|
+
* zero blocks.
|
|
1219
|
+
*
|
|
1220
|
+
* An imperfect page beats no page, so the fallback is unconditional.
|
|
1221
|
+
*/
|
|
1222
|
+
let lastBuiltProposal: { blocks: ProposedBlock[]; rationale: string; notices?: string[] } | null = null;
|
|
1223
|
+
|
|
1224
|
+
let roundsUsed = 0;
|
|
1225
|
+
let exhaustedTurn = false;
|
|
1226
|
+
|
|
1227
|
+
for (let round = 0; round < MAX_TOOL_ROUNDS; round += 1) {
|
|
1228
|
+
roundsUsed = round + 1;
|
|
1229
|
+
// Checked between rounds rather than mid-call: the in-flight request finishes either way, but we
|
|
1230
|
+
// stop paying for the next one.
|
|
1231
|
+
if (args.signal?.aborted) return { reply: '', toolsUsed };
|
|
1232
|
+
|
|
1233
|
+
const { content, toolCalls, finishReason } = await openAiChatTools(convo, TOOLS, {
|
|
1234
|
+
actorUserId: args.actorUserId ?? null,
|
|
1235
|
+
route: '/api/handoff/ai/playground-chat',
|
|
1236
|
+
eventType: 'ai.playground_chat',
|
|
1237
|
+
// Explicit, because the client's 4,096 default is a third of what a real page costs. See
|
|
1238
|
+
// `COMPOSE_MAX_TOKENS` for the arithmetic.
|
|
1239
|
+
maxTokens: COMPOSE_MAX_TOKENS,
|
|
1240
|
+
});
|
|
1241
|
+
|
|
1242
|
+
/**
|
|
1243
|
+
* The completion ran out of room part-way through a tool call.
|
|
1244
|
+
*
|
|
1245
|
+
* Handled before anything reads `call.arguments`, because those arguments are a JSON object cut
|
|
1246
|
+
* mid-string: parsing them throws, the catch below leaves `{}`, and `propose_page` then builds
|
|
1247
|
+
* zero blocks and is told "None of those blocks resolved" — a correctness complaint about a size
|
|
1248
|
+
* failure. The model's answer to that is to try the same page again and be cut again.
|
|
1249
|
+
*/
|
|
1250
|
+
if (toolCallWasCut(finishReason, toolCalls.length > 0)) {
|
|
1251
|
+
noteRetry('truncated-tool-call', toolCalls.map((t) => t.name).join(', '));
|
|
1252
|
+
console.warn('[playground-chat] tool call cut off at the output limit', {
|
|
1253
|
+
tools: toolCalls.map((t) => t.name),
|
|
1254
|
+
maxTokens: COMPOSE_MAX_TOKENS,
|
|
1255
|
+
});
|
|
1256
|
+
convo.push({
|
|
1257
|
+
role: 'assistant',
|
|
1258
|
+
content,
|
|
1259
|
+
// The arguments are kept only as far as the cut, and marked. Replaying a 16,000-token
|
|
1260
|
+
// half-object for every remaining round would cost more than the retry is worth, and sending
|
|
1261
|
+
// `{}` instead would misrepresent what the model actually said.
|
|
1262
|
+
tool_calls: toolCalls.map((t) => ({
|
|
1263
|
+
id: t.id,
|
|
1264
|
+
type: 'function',
|
|
1265
|
+
function: { name: t.name, arguments: `${t.arguments.slice(0, 500)}… [cut off at the output limit]` },
|
|
1266
|
+
})),
|
|
1267
|
+
});
|
|
1268
|
+
for (const call of toolCalls) {
|
|
1269
|
+
toolsUsed.push(call.name);
|
|
1270
|
+
convo.push({
|
|
1271
|
+
role: 'tool',
|
|
1272
|
+
tool_call_id: call.id,
|
|
1273
|
+
content: JSON.stringify({ incomplete: true, reason: truncatedToolCallInstruction(call.name) }),
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
continue;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
if (!toolCalls.length) {
|
|
1280
|
+
// Requesting an image and then only describing it leaves the page untouched — which is exactly
|
|
1281
|
+
// how the first live run failed. The prompt says so; this is the check that the prompt worked.
|
|
1282
|
+
// Once only, matching the unfilled-content gap: a model that ignores the second ask will ignore
|
|
1283
|
+
// a third, and an honest reply beats a loop.
|
|
1284
|
+
// Ending with prose and no proposal is a dead turn: the user gets a paragraph and nothing to
|
|
1285
|
+
// apply. Fires when images were generated but nothing was composed, and also when the catalog was
|
|
1286
|
+
// read and nothing came of it — both are "you did the setup and stopped".
|
|
1287
|
+
// An offer is a legitimate way to end the turn: the user gets a button, not a paragraph.
|
|
1288
|
+
const composedNothing =
|
|
1289
|
+
!toolsUsed.some(isPlacementTool) &&
|
|
1290
|
+
imageCtx.offers.length === 0 &&
|
|
1291
|
+
(imageCtx.queued.length > 0 || toolsUsed.includes('list_blocks'));
|
|
1292
|
+
if (composedNothing && !askedToPlaceImages) {
|
|
1293
|
+
askedToPlaceImages = true;
|
|
1294
|
+
noteRetry('no-proposal');
|
|
1295
|
+
console.warn('[playground-chat] images requested but never placed; asking once', {
|
|
1296
|
+
queued: imageCtx.queued.map((q) => q.jobId),
|
|
1297
|
+
});
|
|
1298
|
+
convo.push({
|
|
1299
|
+
role: 'user',
|
|
1300
|
+
content:
|
|
1301
|
+
'You have not proposed a page or an edit, so there is nothing for me to apply — the turn is ' +
|
|
1302
|
+
'incomplete. Call `propose_page` (or `propose_edits` if changing an existing page) now, with ' +
|
|
1303
|
+
'every block and its copy.' +
|
|
1304
|
+
(imageCtx.queued.length
|
|
1305
|
+
? ' Reuse these exact placeholder srcs in the image fields they were meant for; do NOT ' +
|
|
1306
|
+
`request them again, they are already generating: ${imageCtx.queued.map((q) => q.placeholderSrc).join(' , ')}`
|
|
1307
|
+
: ''),
|
|
1308
|
+
});
|
|
1309
|
+
continue;
|
|
1310
|
+
}
|
|
1311
|
+
// A turn that ends with prose and no proposal produced nothing the user can apply — and the model
|
|
1312
|
+
// will happily narrate the page it intended ("Hero section uses a strong image…") as though it
|
|
1313
|
+
// exists. Same principle as the imagery note: state the truth alongside the claim rather than try
|
|
1314
|
+
// to police the wording.
|
|
1315
|
+
// A page was built and a retry lost it. Return it rather than the prose that replaced it.
|
|
1316
|
+
if (lastBuiltProposal) {
|
|
1317
|
+
const salvaged = describeMissingImagery(findPlaceholderImages(lastBuiltProposal.blocks, imageCtx.queued.map((q) => q.placeholderSrc)));
|
|
1318
|
+
const salvagedReply = [content ?? '', salvaged].filter(Boolean).join('\n\n');
|
|
1319
|
+
console.warn('[playground-chat] retry ended without a proposal; returning the page already built');
|
|
1320
|
+
emit({ type: 'reply', content: salvagedReply });
|
|
1321
|
+
emit({ type: 'proposal', ...lastBuiltProposal });
|
|
1322
|
+
return finish({ reply: salvagedReply, proposal: lastBuiltProposal, toolsUsed });
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
const nothingProposed = !toolsUsed.some(isPlacementTool) && toolsUsed.includes('list_blocks');
|
|
1326
|
+
const reply = [
|
|
1327
|
+
content ?? '',
|
|
1328
|
+
nothingProposed
|
|
1329
|
+
? '⚠️ Nothing was actually proposed — there are no blocks to apply. Ask me to try again.'
|
|
1330
|
+
: null,
|
|
1331
|
+
]
|
|
1332
|
+
.filter(Boolean)
|
|
1333
|
+
.join('\n\n');
|
|
1334
|
+
emit({ type: 'reply', content: reply });
|
|
1335
|
+
return finish({ reply, toolsUsed });
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
convo.push({
|
|
1339
|
+
role: 'assistant',
|
|
1340
|
+
content,
|
|
1341
|
+
tool_calls: toolCalls.map((t) => ({ id: t.id, type: 'function', function: { name: t.name, arguments: t.arguments } })),
|
|
1342
|
+
});
|
|
1343
|
+
|
|
1344
|
+
for (const call of toolCalls) {
|
|
1345
|
+
toolsUsed.push(call.name);
|
|
1346
|
+
let parsed: Record<string, unknown> = {};
|
|
1347
|
+
let argumentsUnreadable = false;
|
|
1348
|
+
try {
|
|
1349
|
+
parsed = JSON.parse(call.arguments) as Record<string, unknown>;
|
|
1350
|
+
} catch {
|
|
1351
|
+
/* a malformed argument object is reported back to the model rather than thrown */
|
|
1352
|
+
argumentsUnreadable = true;
|
|
1353
|
+
}
|
|
1354
|
+
/**
|
|
1355
|
+
* An unreadable argument object is reported as itself.
|
|
1356
|
+
*
|
|
1357
|
+
* `{}` is a plausible-looking empty call, and for the terminal tools that is the worst possible
|
|
1358
|
+
* substitute: `propose_page` with no `blocks` reads as "the model proposed nothing", so the loop
|
|
1359
|
+
* complains about component ids. The length case is caught above; this is everything else —
|
|
1360
|
+
* malformed escaping, a stray newline in a string — and it deserves the same honesty.
|
|
1361
|
+
*/
|
|
1362
|
+
if (argumentsUnreadable && (call.name === 'propose_page' || call.name === 'propose_edits')) {
|
|
1363
|
+
noteRetry('unreadable-arguments', call.name);
|
|
1364
|
+
console.warn('[playground-chat] could not parse tool arguments', { tool: call.name, length: call.arguments.length });
|
|
1365
|
+
convo.push({
|
|
1366
|
+
role: 'tool',
|
|
1367
|
+
tool_call_id: call.id,
|
|
1368
|
+
content: JSON.stringify({
|
|
1369
|
+
rejected: true,
|
|
1370
|
+
reason:
|
|
1371
|
+
`The arguments to \`${call.name}\` were not valid JSON, so none of it could be read. Send the ` +
|
|
1372
|
+
'call again — if the copy contains quotes or markup, make sure they are escaped.',
|
|
1373
|
+
}),
|
|
1374
|
+
});
|
|
1375
|
+
continue;
|
|
1376
|
+
}
|
|
1377
|
+
emit({ type: 'status', text: narrate(call.name, parsed) });
|
|
1378
|
+
|
|
1379
|
+
// Terminal: targeted changes to the page that exists.
|
|
1380
|
+
if (call.name === 'propose_edits') {
|
|
1381
|
+
const current: PageBlock[] = (args.currentBlocks ?? []).map((b) => ({
|
|
1382
|
+
componentId: b.componentId,
|
|
1383
|
+
args: (b.args ?? {}) as Record<string, unknown>,
|
|
1384
|
+
}));
|
|
1385
|
+
// Validated, not cast. A `null` in this array threw `Cannot read properties of null` on the
|
|
1386
|
+
// first `e.op` and killed the turn outright — no changeset, no reply.
|
|
1387
|
+
const { entries: raw, discarded } = parseEditEntries(parsed.edits);
|
|
1388
|
+
|
|
1389
|
+
// Build real args for anything carrying content, so an edit gets the same shape guarantees a
|
|
1390
|
+
// fresh proposal does — correct prop shapes, no invented images, no sample content.
|
|
1391
|
+
const ops: EditOp[] = [];
|
|
1392
|
+
/** Edits dropped before verification — a bad field name, an unknown component. */
|
|
1393
|
+
const preRejected: { reason: string }[] = [];
|
|
1394
|
+
if (discarded) {
|
|
1395
|
+
preRejected.push({
|
|
1396
|
+
reason: `${discarded} edit${discarded === 1 ? '' : 's'} could not be read and were skipped.`,
|
|
1397
|
+
});
|
|
1398
|
+
}
|
|
1399
|
+
for (const e of raw) {
|
|
1400
|
+
const op = String(e.op ?? '');
|
|
1401
|
+
const index = Number(e.index);
|
|
1402
|
+
const expect = String(e.expect ?? '');
|
|
1403
|
+
if (op === 'reorder') {
|
|
1404
|
+
// Content never travels with a reorder — that is the whole point. Verified as a permutation
|
|
1405
|
+
// in verifyOps.
|
|
1406
|
+
const order = Array.isArray(e.order) ? (e.order as unknown[]).map(Number) : [];
|
|
1407
|
+
ops.push({ op: 'reorder', order });
|
|
1408
|
+
continue;
|
|
1409
|
+
}
|
|
1410
|
+
if (op === 'remove') {
|
|
1411
|
+
ops.push({ op: 'remove', index, expect });
|
|
1412
|
+
continue;
|
|
1413
|
+
}
|
|
1414
|
+
const componentId = op === 'update' ? expect : String(e.componentId ?? '');
|
|
1415
|
+
const built = await buildBlocks([{ componentId, values: e.values }], seenAssetSrcs);
|
|
1416
|
+
const block = built.blocks[0];
|
|
1417
|
+
if (!block) {
|
|
1418
|
+
preRejected.push({ reason: built.problems[0] ?? `Could not build ${componentId || 'that block'}.` });
|
|
1419
|
+
continue;
|
|
1420
|
+
}
|
|
1421
|
+
// Shown to the user, not only fed back to the model. A silently-swapped image is the exact
|
|
1422
|
+
// shape of "it listed components as edited and there were no images": the op is valid, it
|
|
1423
|
+
// applies, the card says Applied, and nothing anywhere says the picture was refused.
|
|
1424
|
+
for (const message of describeReplacedImages(built.replacedImages)) {
|
|
1425
|
+
preRejected.push({ reason: message });
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
if (op === 'update') {
|
|
1429
|
+
// Only the fields the model actually named — merging the whole rebuilt block would drag
|
|
1430
|
+
// blanked placeholders over content the user already has. Taken from `buildBlocks` rather
|
|
1431
|
+
// than re-derived from `e.values`: re-deriving used the model's original spelling, so a name
|
|
1432
|
+
// corrected during the merge (`buttonSlot` → `buttonSlots`) was filtered straight back out
|
|
1433
|
+
// and the update was rejected as naming no fields.
|
|
1434
|
+
const named = built.namedKeys[0] ?? [];
|
|
1435
|
+
const values = Object.fromEntries(named.filter((k) => k in block.args).map((k) => [k, block.args[k]]));
|
|
1436
|
+
// An update with nothing left in it is not an update. Every named field was unknown to the
|
|
1437
|
+
// component — a mistyped or guessed field name — and emitting it anyway produced a
|
|
1438
|
+
// changeset that said "Update block 2 — no fields" and then "Applied", having changed
|
|
1439
|
+
// nothing at all. Rejecting it says so, and gives the model the real field names to retry
|
|
1440
|
+
// with instead of leaving it to guess a second time.
|
|
1441
|
+
if (!Object.keys(values).length) {
|
|
1442
|
+
const detail = built.rejectedFields[0];
|
|
1443
|
+
// Every named field being unknown usually means the wrong *component*, not the wrong field
|
|
1444
|
+
// names: the model wrote another block's fields onto this one. Measured at 2 of 5 runs on
|
|
1445
|
+
// "change this section to a stats block", where it reached for `update` and the block kept
|
|
1446
|
+
// its old type — "I wanted to change a component type and it didn't swap it out". Naming
|
|
1447
|
+
// the alternative costs nothing and a rejection that only complains gets guessed at again.
|
|
1448
|
+
const swapHint =
|
|
1449
|
+
' If you meant to change this block to a different component, use `op: "replace"` with ' +
|
|
1450
|
+
'the new `componentId` — `update` only changes fields on the block that is already there.';
|
|
1451
|
+
preRejected.push({
|
|
1452
|
+
reason:
|
|
1453
|
+
(detail
|
|
1454
|
+
? `${componentId}: no such field${detail.unknown.length === 1 ? '' : 's'} ${detail.unknown.join(', ')}. Its fields are: ${detail.available.join(', ')}`
|
|
1455
|
+
: `${componentId}: that edit named no fields the block has.`) + swapHint,
|
|
1456
|
+
});
|
|
1457
|
+
continue;
|
|
1458
|
+
}
|
|
1459
|
+
ops.push({ op: 'update', index, expect, values });
|
|
1460
|
+
} else if (op === 'replace') {
|
|
1461
|
+
ops.push({ op: 'replace', index, expect, componentId, values: block.args });
|
|
1462
|
+
} else if (op === 'insert') {
|
|
1463
|
+
ops.push({ op: 'insert', index, componentId, values: block.args });
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
// Verified here so the model can be told it mis-indexed; the client verifies again at apply
|
|
1468
|
+
// time, where the canvas is the actual truth.
|
|
1469
|
+
// Same placement check for a targeted edit — an op that does not carry the generated src leaves
|
|
1470
|
+
// the image with nowhere to land.
|
|
1471
|
+
const editBlocks = ops.map((o) => ({
|
|
1472
|
+
componentId: 'expect' in o && o.expect ? o.expect : 'componentId' in o ? o.componentId : 'block',
|
|
1473
|
+
args: ('values' in o ? o.values : {}) as Record<string, unknown>,
|
|
1474
|
+
}));
|
|
1475
|
+
const unplacedEdits = findUnplacedImages(editBlocks, imageCtx.queued);
|
|
1476
|
+
if (unplacedEdits.length && !askedToPlaceImages) {
|
|
1477
|
+
askedToPlaceImages = true;
|
|
1478
|
+
noteRetry('unplaced-edits');
|
|
1479
|
+
console.warn('[playground-chat] generated images not placed in edits', unplacedEdits.map((u) => u.placeholderSrc));
|
|
1480
|
+
convo.push({
|
|
1481
|
+
role: 'tool',
|
|
1482
|
+
tool_call_id: call.id,
|
|
1483
|
+
content: JSON.stringify({ incomplete: true, reason: unplacedImageInstruction(unplacedEdits) }),
|
|
1484
|
+
});
|
|
1485
|
+
continue;
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
// Selection is a guarantee, not a suggestion. The prompt says "only the selected block", but a
|
|
1489
|
+
// conversation anchored on some other block can out-pull a prompt note — so it is enforced here,
|
|
1490
|
+
// and the rejection reason re-teaches the rule for the retry.
|
|
1491
|
+
let scopedOps = ops;
|
|
1492
|
+
if (typeof args.targetBlockIndex === 'number' && target) {
|
|
1493
|
+
scopedOps = [];
|
|
1494
|
+
for (const op of ops) {
|
|
1495
|
+
// Inserts pass at any position: adding a block cannot clobber an existing one, and "add a
|
|
1496
|
+
// banner below this" is exactly what a selection should allow. Reorders pass too — moving
|
|
1497
|
+
// blocks touches no content. The enforced part is not rewriting some OTHER existing block —
|
|
1498
|
+
// the wrong-block bug this scoping exists for.
|
|
1499
|
+
if (op.op === 'insert' || op.op === 'reorder' || op.index === args.targetBlockIndex) {
|
|
1500
|
+
scopedOps.push(op);
|
|
1501
|
+
} else {
|
|
1502
|
+
preRejected.push({
|
|
1503
|
+
reason:
|
|
1504
|
+
`the user has selected block ${args.targetBlockIndex + 1} (${target.componentId}) — this edit ` +
|
|
1505
|
+
`targeted block ${op.index + 1}. While a block is selected, update/replace/remove apply ONLY ` +
|
|
1506
|
+
`to the selected block (index ${args.targetBlockIndex}); inserting new blocks is allowed anywhere.`,
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
const { valid, rejected } = verifyOps(scopedOps, current);
|
|
1512
|
+
const allRejected = [...preRejected, ...rejected.map((r) => ({ reason: r.reason }))];
|
|
1513
|
+
if (allRejected.length) console.warn('[playground-chat] rejected edits', allRejected.map((r) => r.reason).join('; '));
|
|
1514
|
+
|
|
1515
|
+
if (!valid.length) {
|
|
1516
|
+
convo.push({
|
|
1517
|
+
role: 'tool',
|
|
1518
|
+
tool_call_id: call.id,
|
|
1519
|
+
content: JSON.stringify({
|
|
1520
|
+
rejected: true,
|
|
1521
|
+
reason:
|
|
1522
|
+
'None of those edits could be applied. Fix them and call propose_edits again. Remember: ' +
|
|
1523
|
+
'all indices refer to the canvas listing as it stands, and the edits apply together — ' +
|
|
1524
|
+
'never shift an index to account for another edit in the same batch. Inserts are the ' +
|
|
1525
|
+
'exception: each one may go up to one past the end of the listing plus the inserts before it.',
|
|
1526
|
+
problems: allRejected.map((r) => r.reason),
|
|
1527
|
+
}),
|
|
1528
|
+
});
|
|
1529
|
+
continue;
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
const summary = String(parsed.summary ?? '');
|
|
1533
|
+
// The same deterministic note the proposal path gets. It existed only there, so an *edit* turn
|
|
1534
|
+
// could claim imagery it had not added with nothing to contradict it — which is precisely how
|
|
1535
|
+
// "it listed these as edited" read to somebody looking at a page with no images on it.
|
|
1536
|
+
const editImagery = describeMissingImagery(findPlaceholderImages(editBlocks, imageCtx.queued.map((q) => q.placeholderSrc)));
|
|
1537
|
+
const reply = [content ?? summary, editImagery].filter(Boolean).join('\n\n');
|
|
1538
|
+
emit({ type: 'reply', content: reply });
|
|
1539
|
+
emit({ type: 'changeset', ops: valid, summary, rejected: allRejected });
|
|
1540
|
+
return finish({ reply, changeset: { ops: valid, summary, rejected: allRejected }, toolsUsed });
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
// Terminal. No scaffolding check any more: the server scaffolds every block itself while
|
|
1544
|
+
// building the args, so there is no step the model can skip. The enforcement existed only to
|
|
1545
|
+
// catch that, and removing the possibility is better than policing it.
|
|
1546
|
+
if (call.name === 'propose_page') {
|
|
1547
|
+
/**
|
|
1548
|
+
* A change to an existing page must not come back as a whole new page.
|
|
1549
|
+
*
|
|
1550
|
+
* The tool description has said "USE THIS, not propose_page, whenever the canvas has blocks and
|
|
1551
|
+
* the request is a change" since the edits path existed. Measured: asking to change every link
|
|
1552
|
+
* and CTA label on a six-block page re-proposed the whole page in **3 of 3 runs**. A prompt
|
|
1553
|
+
* instruction is not a constraint, and this is the one failure where being wrong is worse than
|
|
1554
|
+
* being unhelpful — accepting the proposal discards every earlier decision, and the user cannot
|
|
1555
|
+
* tell until they look. A user reported: "this eliminates all of your changes upstream and starts you from
|
|
1556
|
+
* scratch again."
|
|
1557
|
+
*
|
|
1558
|
+
* So the model has to *say* it means to replace the page, and gets told once that it probably
|
|
1559
|
+
* does not. The escape hatch is real — "start over" is a legitimate request — but it now costs a
|
|
1560
|
+
* deliberate second call rather than being the path of least resistance.
|
|
1561
|
+
*/
|
|
1562
|
+
const replacesPage = parsed.replacesExistingPage === true;
|
|
1563
|
+
if (imageCtx.hasCanvas && !replacesPage && !refusedWholePageRebuild) {
|
|
1564
|
+
refusedWholePageRebuild = true;
|
|
1565
|
+
noteRetry('whole-page-rebuild');
|
|
1566
|
+
console.warn('[playground-chat] refused a whole-page rebuild over a canvas', {
|
|
1567
|
+
canvasBlocks: imageCtx.blocks.length,
|
|
1568
|
+
});
|
|
1569
|
+
convo.push({
|
|
1570
|
+
role: 'tool',
|
|
1571
|
+
tool_call_id: call.id,
|
|
1572
|
+
content: JSON.stringify({
|
|
1573
|
+
rejected: true,
|
|
1574
|
+
reason:
|
|
1575
|
+
`The canvas already has ${imageCtx.blocks.length} blocks with the user's own copy, ` +
|
|
1576
|
+
'imagery and links in them. Proposing a new page throws all of that away, including ' +
|
|
1577
|
+
'decisions made in earlier turns. Use `propose_edits` with one `update` op per block ' +
|
|
1578
|
+
'you actually need to change — that is what "change every CTA label" or "add a section" ' +
|
|
1579
|
+
'means. Only if the user explicitly asked to start the page over, call propose_page ' +
|
|
1580
|
+
'again with `replacesExistingPage: true`.',
|
|
1581
|
+
canvas: imageCtx.blocks.map((b, i) => ({ block: i + 1, componentId: b.componentId })),
|
|
1582
|
+
}),
|
|
1583
|
+
});
|
|
1584
|
+
continue;
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
const raw = Array.isArray(parsed.blocks) ? (parsed.blocks as { componentId?: unknown; values?: unknown }[]) : [];
|
|
1588
|
+
const { blocks, problems, gaps, optionalGaps, invalidValues, replacedImages } = await buildBlocks(raw, seenAssetSrcs);
|
|
1589
|
+
const notices = describeReplacedImages(replacedImages);
|
|
1590
|
+
if (blocks.length) lastBuiltProposal = { blocks, rationale: String(parsed.rationale ?? ''), notices };
|
|
1591
|
+
|
|
1592
|
+
// Ask once for the content it skipped. Templates are seeded from real previews, so an
|
|
1593
|
+
// unfilled field is not empty — it is somebody's sample copy, and shipping that produces a
|
|
1594
|
+
// page that looks finished and is not. Once only: a second ask rarely helps and the honest
|
|
1595
|
+
// fallback is a visibly incomplete page rather than a plausible fake one.
|
|
1596
|
+
// Images this turn generated that never made it into a block. The other placement guard only
|
|
1597
|
+
// fires when a turn ends without a placement tool, so a `propose_page` that omits the returned
|
|
1598
|
+
// srcs walks straight past it — which is how three generated images ended up waiting forever
|
|
1599
|
+
// for a placeholder that was never on the canvas.
|
|
1600
|
+
const unplaced = findUnplacedImages(blocks, imageCtx.queued);
|
|
1601
|
+
if (unplaced.length && !askedToPlaceImages) {
|
|
1602
|
+
askedToPlaceImages = true;
|
|
1603
|
+
noteRetry('unplaced-images');
|
|
1604
|
+
console.warn('[playground-chat] generated images not placed', unplaced.map((u) => u.placeholderSrc));
|
|
1605
|
+
convo.push({
|
|
1606
|
+
role: 'tool',
|
|
1607
|
+
tool_call_id: call.id,
|
|
1608
|
+
content: JSON.stringify({ incomplete: true, reason: unplacedImageInstruction(unplaced) }),
|
|
1609
|
+
});
|
|
1610
|
+
continue;
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
// Imagery first, and phrased for imagery. The generic gap retry says "write real values", which
|
|
1614
|
+
// is not a thing you can do for an image — so a page asking for "good images of students" came
|
|
1615
|
+
// back with none, and the model reported "real student imagery" anyway.
|
|
1616
|
+
const placeholders = findPlaceholderImages(blocks, imageCtx.queued.map((q) => q.placeholderSrc));
|
|
1617
|
+
// Only chase imagery on a page that already exists. Composing a fresh one, placeholders are the
|
|
1618
|
+
// *intended* outcome — and this retry told the model to call `request_image`, which is gated off
|
|
1619
|
+
// in that case. It read the contradiction, burned rounds on it, and ended the turn with prose
|
|
1620
|
+
// and no proposal at all.
|
|
1621
|
+
if (imageCtx.hasCanvas && placeholders.length && !askedForImages) {
|
|
1622
|
+
askedForImages = true;
|
|
1623
|
+
noteRetry('imagery');
|
|
1624
|
+
console.log('[playground-chat] asking for imagery', JSON.stringify(placeholders));
|
|
1625
|
+
convo.push({
|
|
1626
|
+
role: 'tool',
|
|
1627
|
+
tool_call_id: call.id,
|
|
1628
|
+
content: JSON.stringify({ incomplete: true, reason: imageGapInstruction(placeholders) }),
|
|
1629
|
+
});
|
|
1630
|
+
continue;
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
// Values the merge threw away — almost always an invented image src. Reported before the gap
|
|
1634
|
+
// check because it is the more actionable failure: a model told only "these fields are empty"
|
|
1635
|
+
// re-proposed the same three fabricated srcs and had them rejected again.
|
|
1636
|
+
//
|
|
1637
|
+
// `alsoEmpty` stays on that ask even though the empty-content ask can now fire on its own round
|
|
1638
|
+
// afterwards: a model that fixes both at once saves a retry, and one that reads it as context
|
|
1639
|
+
// still gets asked properly. Which is the whole change — it used to be the only mention the
|
|
1640
|
+
// empty fields ever got.
|
|
1641
|
+
const gapAsk = nextGapAsk(askedForGaps, { invalidValues: invalidValues.length, gaps: gaps.length });
|
|
1642
|
+
|
|
1643
|
+
if (gapAsk === 'rejected-values') {
|
|
1644
|
+
askedForGaps.rejectedValues = true;
|
|
1645
|
+
noteRetry('rejected-values');
|
|
1646
|
+
console.log('[playground-chat] reporting rejected values', JSON.stringify(invalidValues));
|
|
1647
|
+
convo.push({
|
|
1648
|
+
role: 'tool',
|
|
1649
|
+
tool_call_id: call.id,
|
|
1650
|
+
content: JSON.stringify({
|
|
1651
|
+
incomplete: true,
|
|
1652
|
+
reason:
|
|
1653
|
+
'Some values were rejected and replaced with placeholders. An image src must come from a ' +
|
|
1654
|
+
'`search_assets` result — you cannot invent a path, and a made-up one renders as a broken ' +
|
|
1655
|
+
'image. Either use a src a search actually returned, or leave the placeholder and say so ' +
|
|
1656
|
+
'in your reply. Then call propose_page again.',
|
|
1657
|
+
rejected: invalidValues,
|
|
1658
|
+
...(gaps.length ? { alsoEmpty: gaps } : {}),
|
|
1659
|
+
}),
|
|
1660
|
+
});
|
|
1661
|
+
continue;
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
if (gapAsk === 'content-gaps') {
|
|
1665
|
+
askedForGaps.emptyContent = true;
|
|
1666
|
+
noteRetry('content-gaps');
|
|
1667
|
+
console.log('[playground-chat] asking for unfilled content', JSON.stringify(gaps));
|
|
1668
|
+
convo.push({
|
|
1669
|
+
role: 'tool',
|
|
1670
|
+
tool_call_id: call.id,
|
|
1671
|
+
content: JSON.stringify({
|
|
1672
|
+
incomplete: true,
|
|
1673
|
+
reason:
|
|
1674
|
+
'These content fields are empty. Nothing fills them for you — an unwritten field ships ' +
|
|
1675
|
+
'blank. Write real values (arrays need EVERY item authored, not one) and call ' +
|
|
1676
|
+
'propose_page again with the complete set of blocks.',
|
|
1677
|
+
missing: gaps,
|
|
1678
|
+
}),
|
|
1679
|
+
});
|
|
1680
|
+
continue;
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
if (!blocks.length) {
|
|
1684
|
+
// Every block failed to resolve — usually invented component ids. Hand it back so the model
|
|
1685
|
+
// can pick real ones from the catalog rather than ending the turn on a dead proposal.
|
|
1686
|
+
convo.push({
|
|
1687
|
+
role: 'tool',
|
|
1688
|
+
tool_call_id: call.id,
|
|
1689
|
+
content: JSON.stringify({
|
|
1690
|
+
rejected: true,
|
|
1691
|
+
reason: 'None of those blocks resolved. Use ids exactly as returned by list_blocks.',
|
|
1692
|
+
problems,
|
|
1693
|
+
}),
|
|
1694
|
+
});
|
|
1695
|
+
continue;
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
const rationale = String(parsed.rationale ?? '');
|
|
1699
|
+
// Appended, not substituted. The model's prose may be accurate, vague, or an outright claim of
|
|
1700
|
+
// imagery it never added — this makes the real state visible without trying to police wording.
|
|
1701
|
+
const missingImagery = describeMissingImagery(findPlaceholderImages(blocks, imageCtx.queued.map((q) => q.placeholderSrc)));
|
|
1702
|
+
// Optional fields left blank. Deterministic, and deliberately not a retry: this is worth knowing
|
|
1703
|
+
// and not worth a round of invented copy.
|
|
1704
|
+
const optionalNote = describeOptionalGaps(optionalGaps);
|
|
1705
|
+
const reply = [content ?? rationale ?? 'Here is the page.', missingImagery, optionalNote]
|
|
1706
|
+
.filter(Boolean)
|
|
1707
|
+
.join('\n\n');
|
|
1708
|
+
emit({ type: 'reply', content: reply });
|
|
1709
|
+
emit({ type: 'proposal', blocks, rationale, notices });
|
|
1710
|
+
return finish({ reply, proposal: { blocks, rationale, notices }, toolsUsed });
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
let result: unknown;
|
|
1714
|
+
try {
|
|
1715
|
+
result = await runTool(call.name, parsed, attached, seenAssetSrcs, imageCtx);
|
|
1716
|
+
} catch (e) {
|
|
1717
|
+
// Feed the failure back rather than aborting the turn — the model can pick another block or
|
|
1718
|
+
// explain itself, which is far more useful than a dead conversation.
|
|
1719
|
+
result = { error: e instanceof Error ? e.message : 'Tool failed.' };
|
|
1720
|
+
}
|
|
1721
|
+
convo.push({ role: 'tool', tool_call_id: call.id, content: JSON.stringify(result).slice(0, 24_000) });
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
/**
|
|
1726
|
+
* The round cap, which until now threw away a finished page.
|
|
1727
|
+
*
|
|
1728
|
+
* `lastBuiltProposal` exists precisely so a retry can never destroy a page we already built, and the
|
|
1729
|
+
* comment above it says an imperfect page beats no page — but the only branch that read it was the
|
|
1730
|
+
* no-tool-calls one. Reaching the cap with eight composed blocks in hand returned "I got stuck" and
|
|
1731
|
+
* dropped them, which is the same loss the fallback was added to prevent, by a different door.
|
|
1732
|
+
*/
|
|
1733
|
+
exhaustedTurn = true;
|
|
1734
|
+
console.warn('[playground-chat] round cap hit', { rounds: MAX_TOOL_ROUNDS, tools: toolsUsed, salvaged: !!lastBuiltProposal });
|
|
1735
|
+
const salvage = salvageTurn('round-cap', !!lastBuiltProposal);
|
|
1736
|
+
if (salvage.useBuiltProposal && lastBuiltProposal) {
|
|
1737
|
+
const stillOnPlaceholders = describeMissingImagery(
|
|
1738
|
+
findPlaceholderImages(lastBuiltProposal.blocks, imageCtx.queued.map((q) => q.placeholderSrc))
|
|
1739
|
+
);
|
|
1740
|
+
const reply = [salvage.note, stillOnPlaceholders].filter(Boolean).join('\n\n');
|
|
1741
|
+
emit({ type: 'reply', content: reply });
|
|
1742
|
+
emit({ type: 'proposal', ...lastBuiltProposal });
|
|
1743
|
+
return finish({ reply, proposal: lastBuiltProposal, toolsUsed });
|
|
1744
|
+
}
|
|
1745
|
+
// Say what actually happened rather than blaming the user for a limit they cannot see. With the
|
|
1746
|
+
// catalog available in one call this should now be close to unreachable — reaching it means
|
|
1747
|
+
// something is genuinely wrong, so it reads as our problem, not theirs.
|
|
1748
|
+
const exhausted = salvage.note ?? '';
|
|
1749
|
+
emit({ type: 'reply', content: exhausted });
|
|
1750
|
+
return finish({ reply: exhausted, toolsUsed });
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
// ── Single-block refinement ───────────────────────────────────────────────────
|
|
1754
|
+
|
|
1755
|
+
/**
|
|
1756
|
+
* Reconsider one block in a proposal without touching the rest.
|
|
1757
|
+
*
|
|
1758
|
+
* The all-or-nothing problem: the only way to change a suggested hero was to regenerate everything and
|
|
1759
|
+
* hope the parts you liked survived. This scopes the request to one slot — the model sees the whole
|
|
1760
|
+
* composition for context but can only return a single block, so "I don't like the bubble hero" cannot
|
|
1761
|
+
* quietly reword the pricing section.
|
|
1762
|
+
*
|
|
1763
|
+
* Scoping also sidesteps the reason full conversational editing looked expensive: the model never has
|
|
1764
|
+
* to resolve "before the footer" when there are two candidate footers, because the caller already said
|
|
1765
|
+
* which index it means.
|
|
1766
|
+
*/
|
|
1767
|
+
export interface BlockRefinementResult {
|
|
1768
|
+
ok: boolean;
|
|
1769
|
+
block?: ProposedBlock;
|
|
1770
|
+
note?: string;
|
|
1771
|
+
error?: string;
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
const REFINE_TOOLS: OpenAiTool[] = [
|
|
1775
|
+
...TOOLS.filter((t) => t.function.name !== 'propose_page'),
|
|
1776
|
+
{
|
|
1777
|
+
type: 'function',
|
|
1778
|
+
function: {
|
|
1779
|
+
name: 'propose_block',
|
|
1780
|
+
description: 'Return the single replacement block. Terminal — call once.',
|
|
1781
|
+
parameters: {
|
|
1782
|
+
type: 'object',
|
|
1783
|
+
properties: {
|
|
1784
|
+
componentId: { type: 'string' },
|
|
1785
|
+
values: { type: 'object', description: 'CONTENT ONLY, keyed by the field names from list_blocks.' },
|
|
1786
|
+
note: { type: 'string', description: 'One short sentence on what changed and why.' },
|
|
1787
|
+
},
|
|
1788
|
+
required: ['componentId', 'values'],
|
|
1789
|
+
},
|
|
1790
|
+
},
|
|
1791
|
+
},
|
|
1792
|
+
];
|
|
1793
|
+
|
|
1794
|
+
export async function refineProposalBlock(args: {
|
|
1795
|
+
blocks: ProposedBlock[];
|
|
1796
|
+
index: number;
|
|
1797
|
+
/** What the user wants: "something other than a bubble hero", "shorter copy", … */
|
|
1798
|
+
instruction: string;
|
|
1799
|
+
actorUserId?: string | null;
|
|
1800
|
+
onEvent?: (event: PlaygroundChatEvent) => void;
|
|
1801
|
+
signal?: AbortSignal;
|
|
1802
|
+
}): Promise<BlockRefinementResult> {
|
|
1803
|
+
const emit = args.onEvent ?? (() => {});
|
|
1804
|
+
const target = args.blocks[args.index];
|
|
1805
|
+
if (!target) return { ok: false, error: 'That block is no longer in the proposal.' };
|
|
1806
|
+
|
|
1807
|
+
const workspace = await getDesignWorkspace().catch(() => null);
|
|
1808
|
+
const brandVoice = workspace ? formatBrandVoiceForPrompt(workspace.brandVoice).trim() : '';
|
|
1809
|
+
|
|
1810
|
+
const convo: unknown[] = [
|
|
1811
|
+
{
|
|
1812
|
+
role: 'system',
|
|
1813
|
+
content: `You are changing ONE block of an already-composed page. Do not redesign the page.
|
|
1814
|
+
|
|
1815
|
+
## The page as it stands
|
|
1816
|
+
${summarizeComposition(args.blocks)}
|
|
1817
|
+
|
|
1818
|
+
## The block to change
|
|
1819
|
+
Position ${args.index + 1}: ${target.componentId}
|
|
1820
|
+
|
|
1821
|
+
## What the user wants
|
|
1822
|
+
${args.instruction}
|
|
1823
|
+
|
|
1824
|
+
Call list_blocks once to see what is available, then call propose_block ONCE with the component id and
|
|
1825
|
+
your content. Carry over anything worth keeping from the current block. Returning the same componentId
|
|
1826
|
+
is fine when the request is about the copy rather than the layout.
|
|
1827
|
+
${brandVoice ? `\n## Brand voice — any copy you write must obey this\n${brandVoice.slice(0, 3000)}\n` : ''}`,
|
|
1828
|
+
},
|
|
1829
|
+
{ role: 'user', content: args.instruction },
|
|
1830
|
+
];
|
|
1831
|
+
|
|
1832
|
+
for (let round = 0; round < 8; round += 1) {
|
|
1833
|
+
if (args.signal?.aborted) return { ok: false, error: 'Cancelled.' };
|
|
1834
|
+
|
|
1835
|
+
const { content, toolCalls } = await openAiChatTools(convo, REFINE_TOOLS, {
|
|
1836
|
+
actorUserId: args.actorUserId ?? null,
|
|
1837
|
+
route: '/api/handoff/ai/playground-chat/refine',
|
|
1838
|
+
eventType: 'ai.playground_refine',
|
|
1839
|
+
});
|
|
1840
|
+
|
|
1841
|
+
if (!toolCalls.length) {
|
|
1842
|
+
// No tool call means it answered in prose — usually a question or a refusal. Pass it through
|
|
1843
|
+
// rather than reporting a failure, so the user reads the actual reason.
|
|
1844
|
+
return { ok: false, error: content ?? 'No replacement was proposed.' };
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
convo.push({
|
|
1848
|
+
role: 'assistant',
|
|
1849
|
+
content,
|
|
1850
|
+
tool_calls: toolCalls.map((t) => ({ id: t.id, type: 'function', function: { name: t.name, arguments: t.arguments } })),
|
|
1851
|
+
});
|
|
1852
|
+
|
|
1853
|
+
for (const call of toolCalls) {
|
|
1854
|
+
let parsed: Record<string, unknown> = {};
|
|
1855
|
+
try {
|
|
1856
|
+
parsed = JSON.parse(call.arguments) as Record<string, unknown>;
|
|
1857
|
+
} catch {
|
|
1858
|
+
/* reported back to the model rather than thrown */
|
|
1859
|
+
}
|
|
1860
|
+
emit({ type: 'status', text: narrate(call.name, parsed) });
|
|
1861
|
+
|
|
1862
|
+
if (call.name === 'propose_block') {
|
|
1863
|
+
const { blocks, problems } = await buildBlocks([{ componentId: parsed.componentId, values: parsed.values }]);
|
|
1864
|
+
if (!blocks.length) {
|
|
1865
|
+
convo.push({
|
|
1866
|
+
role: 'tool',
|
|
1867
|
+
tool_call_id: call.id,
|
|
1868
|
+
content: JSON.stringify({
|
|
1869
|
+
rejected: true,
|
|
1870
|
+
reason: 'That block did not resolve. Use an id exactly as returned by list_blocks.',
|
|
1871
|
+
problems,
|
|
1872
|
+
}),
|
|
1873
|
+
});
|
|
1874
|
+
continue;
|
|
1875
|
+
}
|
|
1876
|
+
return { ok: true, block: blocks[0], note: typeof parsed.note === 'string' ? parsed.note : undefined };
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
let result: unknown;
|
|
1880
|
+
try {
|
|
1881
|
+
result = await runTool(call.name, parsed, []);
|
|
1882
|
+
} catch (e) {
|
|
1883
|
+
result = { error: e instanceof Error ? e.message : 'Tool failed.' };
|
|
1884
|
+
}
|
|
1885
|
+
convo.push({ role: 'tool', tool_call_id: call.id, content: JSON.stringify(result).slice(0, 24_000) });
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
return { ok: false, error: 'Could not settle on a replacement. Try describing what you want instead.' };
|
|
1890
|
+
}
|