@agent-native/core 0.79.27 → 0.80.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/corpus/README.md +2 -2
- package/corpus/core/CHANGELOG.md +34 -0
- package/corpus/core/docs/content/locales/ar-SA/skills-guide.mdx +5 -0
- package/corpus/core/docs/content/locales/ar-SA/template-design.mdx +55 -1
- package/corpus/core/docs/content/locales/de-DE/skills-guide.mdx +5 -0
- package/corpus/core/docs/content/locales/de-DE/template-design.mdx +66 -1
- package/corpus/core/docs/content/locales/es-ES/skills-guide.mdx +5 -0
- package/corpus/core/docs/content/locales/es-ES/template-design.mdx +65 -1
- package/corpus/core/docs/content/locales/fr-FR/skills-guide.mdx +5 -0
- package/corpus/core/docs/content/locales/fr-FR/template-design.mdx +64 -1
- package/corpus/core/docs/content/locales/hi-IN/skills-guide.mdx +5 -0
- package/corpus/core/docs/content/locales/hi-IN/template-design.mdx +59 -1
- package/corpus/core/docs/content/locales/ja-JP/skills-guide.mdx +5 -0
- package/corpus/core/docs/content/locales/ja-JP/template-design.mdx +62 -1
- package/corpus/core/docs/content/locales/ko-KR/skills-guide.mdx +5 -0
- package/corpus/core/docs/content/locales/ko-KR/template-design.mdx +58 -1
- package/corpus/core/docs/content/locales/pt-BR/skills-guide.mdx +5 -0
- package/corpus/core/docs/content/locales/pt-BR/template-design.mdx +62 -1
- package/corpus/core/docs/content/locales/zh-CN/skills-guide.mdx +5 -0
- package/corpus/core/docs/content/locales/zh-CN/template-design.mdx +50 -1
- package/corpus/core/docs/content/locales/zh-TW/skills-guide.mdx +5 -0
- package/corpus/core/docs/content/locales/zh-TW/template-design.mdx +52 -1
- package/corpus/core/docs/content/skills-guide.mdx +5 -0
- package/corpus/core/docs/content/template-design.mdx +59 -1
- package/corpus/core/package.json +2 -1
- package/corpus/core/src/agent/engine/index.ts +1 -0
- package/corpus/core/src/agent/engine/registry.ts +40 -0
- package/corpus/core/src/agent/production-agent.ts +6 -2
- package/corpus/core/src/application-state/handlers.ts +1 -1
- package/corpus/core/src/brand-kit/index.ts +1 -1
- package/corpus/core/src/cli/design-connect.ts +490 -0
- package/corpus/core/src/cli/index.ts +16 -0
- package/corpus/core/src/cli/skills.ts +144 -3
- package/corpus/core/src/client/AgentPanel.tsx +1 -1
- package/corpus/core/src/client/AssistantChat.tsx +43 -7
- package/corpus/core/src/client/MultiTabAssistantChat.tsx +1 -1
- package/corpus/core/src/client/agent-chat.ts +27 -3
- package/corpus/core/src/client/blocks/library/MermaidBlock.tsx +1 -1
- package/corpus/core/src/client/blocks/library/diagram.tsx +2 -2
- package/corpus/core/src/client/blocks/library/wireframe.tsx +1 -1
- package/corpus/core/src/client/chat/message-components.tsx +1 -1
- package/corpus/core/src/client/chat-model-groups.ts +1 -2
- package/corpus/core/src/client/components/LiveCursorOverlay.tsx +33 -66
- package/corpus/core/src/client/composer/TiptapComposer.tsx +99 -24
- package/corpus/core/src/client/composer/useVoiceDictation.ts +429 -260
- package/corpus/core/src/client/extensions/portable-extension.ts +1 -1
- package/corpus/core/src/client/frame-protocol.ts +17 -2
- package/corpus/core/src/client/rich-markdown-editor/RegistryBlockNode.tsx +2 -2
- package/corpus/core/src/client/sharing/ShareButton.tsx +20 -15
- package/corpus/core/src/client/use-agent-engine-configured.ts +80 -28
- package/corpus/core/src/code-agents/transcript-normalizer.ts +1 -1
- package/corpus/core/src/extensions/path.ts +1 -4
- package/corpus/core/src/integrations/a2a-continuation-processor.ts +1 -1
- package/corpus/core/src/mcp/build-server.ts +1 -1
- package/corpus/core/src/org/handlers.ts +5 -5
- package/corpus/core/src/org/plugin.ts +2 -2
- package/corpus/core/src/scripts/call-agent.ts +1 -1
- package/corpus/core/src/scripts/db/safety.ts +1 -1
- package/corpus/core/src/server/auth.ts +3 -0
- package/corpus/core/src/server/builder-design-systems.ts +308 -0
- package/corpus/core/src/server/core-routes-plugin.ts +29 -3
- package/corpus/core/src/server/index.ts +8 -0
- package/corpus/core/src/server/transcribe-voice.ts +57 -22
- package/corpus/core/src/shared/mcp-embed-headers.ts +23 -1
- package/corpus/core/src/styles/agent-native.css +60 -4
- package/corpus/core/src/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +10 -0
- package/corpus/core/src/usage/store.ts +2 -2
- package/corpus/core/src/vite/client.ts +2 -0
- package/corpus/core/src/voice/index.ts +18 -0
- package/corpus/core/src/voice/voice-cleanup-prompt.ts +38 -0
- package/corpus/core/src/voice/voice-context.ts +217 -0
- package/corpus/core/src/voice/voice-replacements.ts +75 -0
- package/corpus/templates/analytics/AGENTS.md +4 -3
- package/corpus/templates/analytics/actions/dashboard-mutation-api.ts +298 -15
- package/corpus/templates/analytics/actions/get-sql-dashboard.ts +9 -4
- package/corpus/templates/analytics/actions/list-session-recordings.ts +6 -1
- package/corpus/templates/analytics/actions/mutate-dashboard.ts +18 -2
- package/corpus/templates/analytics/actions/query-agent-native-analytics.ts +12 -2
- package/corpus/templates/analytics/app/components/layout/Sidebar.tsx +557 -400
- package/corpus/templates/analytics/app/global.css +0 -4
- package/corpus/templates/analytics/app/hooks/use-replay-storage-status.ts +66 -0
- package/corpus/templates/analytics/app/i18n/zh-TW.ts +39 -0
- package/corpus/templates/analytics/app/i18n-data.ts +424 -0
- package/corpus/templates/analytics/app/pages/Settings.tsx +333 -0
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/PanelEditorDialog.tsx +2 -1
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/dashboard-layout.ts +121 -3
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/index.tsx +82 -34
- package/corpus/templates/analytics/app/pages/sessions/SessionDetailPage.tsx +7 -0
- package/corpus/templates/analytics/app/pages/sessions/SessionsPage.tsx +144 -36
- package/corpus/templates/analytics/changelog/2026-06-28-ask-tab-now-matches-the-darker-app-background.md +6 -0
- package/corpus/templates/analytics/changelog/2026-06-28-dashboard-email-reports-now-use-cleaner-light-mode-snapshots.md +6 -0
- package/corpus/templates/analytics/changelog/2026-06-28-left-sidebar-collapses-into-an-animated-icon-rail.md +6 -0
- package/corpus/templates/analytics/changelog/2026-06-28-sessions-now-show-only-signed-in-recordings-with-playable-re.md +6 -0
- package/corpus/templates/analytics/changelog/2026-06-29-analytics-agents-can-now-place-new-charts-into-requested-das.md +6 -0
- package/corpus/templates/analytics/changelog/2026-06-29-analytics-queries-now-report-failed-source-query-errors-inst.md +6 -0
- package/corpus/templates/analytics/changelog/2026-06-29-charts-can-now-be-dropped-between-full-dashboard-rows-to-cre.md +6 -0
- package/corpus/templates/analytics/changelog/2026-06-29-dashboard-email-reports-include-the-full-dashboard-image-wit.md +6 -0
- package/corpus/templates/analytics/changelog/2026-06-29-main-surface-border-reaches-the-top.md +6 -0
- package/corpus/templates/analytics/changelog/2026-06-29-session-replay-now-records-playable-sessions-in-production-a.md +6 -0
- package/corpus/templates/analytics/changelog/2026-06-29-set-up-session-replay-storage-from-settings-connect-builder-.md +6 -0
- package/corpus/templates/analytics/scripts/cleanup-empty-session-recordings.ts +102 -0
- package/corpus/templates/analytics/seeds/dashboards/agent-native-templates-first-party.json +3 -3
- package/corpus/templates/analytics/server/lib/dashboard-report.ts +75 -30
- package/corpus/templates/analytics/server/lib/first-party-metric-catalog.ts +5 -2
- package/corpus/templates/analytics/server/lib/real-data-actions.ts +81 -20
- package/corpus/templates/analytics/server/lib/replay-storage.ts +79 -0
- package/corpus/templates/analytics/server/lib/s3-upload-provider.ts +255 -0
- package/corpus/templates/analytics/server/lib/session-replay.ts +53 -12
- package/corpus/templates/analytics/server/plugins/agent-chat.ts +11 -2
- package/corpus/templates/analytics/server/plugins/onboarding.ts +97 -0
- package/corpus/templates/assets/app/components/layout/Sidebar.tsx +4 -4
- package/corpus/templates/assets/changelog/2026-06-28-left-sidebar-collapse-motion-and-footer-chrome-are-quieter.md +6 -0
- package/corpus/templates/brain/app/components/layout/Layout.tsx +29 -2
- package/corpus/templates/brain/app/components/layout/Sidebar.tsx +131 -42
- package/corpus/templates/brain/app/i18n/zh-TW.ts +2 -0
- package/corpus/templates/brain/app/i18n-data.ts +20 -0
- package/corpus/templates/brain/changelog/2026-06-28-left-sidebar-collapses-into-an-animated-icon-rail.md +6 -0
- package/corpus/templates/calendar/app/components/layout/AppLayout.tsx +29 -1
- package/corpus/templates/calendar/app/components/layout/Sidebar.tsx +417 -299
- package/corpus/templates/calendar/app/i18n/zh-TW.ts +2 -0
- package/corpus/templates/calendar/app/i18n-data.ts +20 -0
- package/corpus/templates/calendar/changelog/2026-06-28-left-sidebar-collapses-into-an-animated-icon-rail.md +6 -0
- package/corpus/templates/chat/app/components/layout/Sidebar.tsx +6 -19
- package/corpus/templates/chat/changelog/2026-06-28-left-sidebar-collapse-motion-and-footer-chrome-are-quieter.md +6 -0
- package/corpus/templates/clips/AGENTS.md +4 -0
- package/corpus/templates/clips/actions/cleanup-transcript.ts +39 -9
- package/corpus/templates/clips/actions/finalize-meeting.ts +81 -12
- package/corpus/templates/clips/actions/lib/agents-md-context.ts +4 -1
- package/corpus/templates/clips/app/components/library/library-layout.tsx +3 -3
- package/corpus/templates/clips/app/components/meetings/share-meeting-dialog.tsx +1 -1
- package/corpus/templates/clips/app/components/player/share-dialog.tsx +2 -2
- package/corpus/templates/clips/changelog/2026-06-28-left-sidebar-footer-controls-use-less-divider-chrome.md +6 -0
- package/corpus/templates/clips/desktop/src/lib/personal-vocabulary.ts +13 -8
- package/corpus/templates/clips/desktop/src/lib/recorder.ts +24 -0
- package/corpus/templates/clips/desktop/src/lib/transcription-capture.ts +105 -5
- package/corpus/templates/clips/desktop/src/lib/voice-dictation.ts +60 -1
- package/corpus/templates/content/actions/set-image-alt-text.ts +1 -1
- package/corpus/templates/content/app/components/editor/DocumentDatabase.tsx +1 -1
- package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +1 -1
- package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +5 -5
- package/corpus/templates/content/changelog/2026-06-28-left-sidebar-collapse-motion-and-footer-chrome-are-quieter.md +6 -0
- package/corpus/templates/content/shared/document-export.ts +1 -1
- package/corpus/templates/design/.agents/skills/design-systems/SKILL.md +8 -18
- package/corpus/templates/design/.agents/skills/visual-edit/SKILL.md +154 -0
- package/corpus/templates/design/AGENTS.md +95 -5
- package/corpus/templates/design/DESIGN.md +82 -0
- package/corpus/templates/design/DEVELOPING.md +43 -0
- package/corpus/templates/design/actions/add-localhost-screens.ts +453 -0
- package/corpus/templates/design/actions/apply-shader.ts +277 -0
- package/corpus/templates/design/actions/apply-visual-edit.ts +303 -0
- package/corpus/templates/design/actions/connect-localhost.ts +183 -0
- package/corpus/templates/design/actions/edit-design.ts +195 -42
- package/corpus/templates/design/actions/generate-design.ts +71 -1
- package/corpus/templates/design/actions/generate-screens.ts +193 -0
- package/corpus/templates/design/actions/get-code-layer-projection.ts +191 -0
- package/corpus/templates/design/actions/get-shader.ts +119 -0
- package/corpus/templates/design/actions/index-design-system-with-builder.ts +259 -0
- package/corpus/templates/design/actions/list-localhost-connections.ts +95 -0
- package/corpus/templates/design/actions/navigate.ts +55 -2
- package/corpus/templates/design/actions/update-file.ts +9 -2
- package/corpus/templates/design/actions/view-screen.ts +68 -1
- package/corpus/templates/design/agent-native.app-skill.json +10 -0
- package/corpus/templates/design/app/components/design/CanvasContextMenu.tsx +719 -0
- package/corpus/templates/design/app/components/design/DesignCanvas.tsx +2120 -103
- package/corpus/templates/design/app/components/design/DesignEditorSkeleton.tsx +74 -38
- package/corpus/templates/design/app/components/design/DesignExtensionsPanel.tsx +401 -0
- package/corpus/templates/design/app/components/design/EditPanel.tsx +3966 -440
- package/corpus/templates/design/app/components/design/LayersPanel.tsx +1473 -0
- package/corpus/templates/design/app/components/design/MultiScreenCanvas.tsx +3940 -147
- package/corpus/templates/design/app/components/design/QuestionFlow.tsx +700 -13
- package/corpus/templates/design/app/components/design/TweaksPanel.tsx +105 -63
- package/corpus/templates/design/app/components/design/index.ts +0 -5
- package/corpus/templates/design/app/components/design/inspector/AlignmentMatrix.tsx +353 -0
- package/corpus/templates/design/app/components/design/inspector/AutoLayoutMatrix.tsx +1589 -0
- package/corpus/templates/design/app/components/design/inspector/ConstraintsWidget.tsx +511 -0
- package/corpus/templates/design/app/components/design/inspector/ExportSettingsPanel.tsx +395 -0
- package/corpus/templates/design/app/components/design/inspector/FigmaColorPicker.tsx +2010 -0
- package/corpus/templates/design/app/components/design/inspector/GradientEditor.tsx +601 -0
- package/corpus/templates/design/app/components/design/inspector/ImageFillControls.tsx +242 -0
- package/corpus/templates/design/app/components/design/inspector/SHADER_INTEGRATION.md +420 -0
- package/corpus/templates/design/app/components/design/inspector/ScrubInput.tsx +238 -0
- package/corpus/templates/design/app/components/design/inspector/ShaderControls.stories.tsx +71 -0
- package/corpus/templates/design/app/components/design/inspector/ShaderControls.tsx +575 -0
- package/corpus/templates/design/app/components/design/inspector/ShaderEffectRow.tsx +106 -0
- package/corpus/templates/design/app/components/design/inspector/ShaderFillsPanel.tsx +423 -0
- package/corpus/templates/design/app/components/design/inspector/figma-icons.tsx +741 -0
- package/corpus/templates/design/app/components/design/inspector/index.ts +87 -0
- package/corpus/templates/design/app/components/design/inspector/scrub-input-utils.ts +201 -0
- package/corpus/templates/design/app/components/design/types.ts +23 -0
- package/corpus/templates/design/app/components/layout/Layout.tsx +24 -13
- package/corpus/templates/design/app/components/layout/Sidebar.tsx +4 -4
- package/corpus/templates/design/app/components/visual-editor/CanvasCommentPins.tsx +474 -36
- package/corpus/templates/design/app/components/visual-editor/DrawOverlay.tsx +22 -5
- package/corpus/templates/design/app/components/visual-editor/SaveStatusIndicator.tsx +24 -11
- package/corpus/templates/design/app/global.css +149 -5
- package/corpus/templates/design/app/hooks/use-agent-generating.ts +4 -0
- package/corpus/templates/design/app/hooks/use-navigation-state.ts +130 -8
- package/corpus/templates/design/app/hooks/useDesignHotkeys.ts +329 -0
- package/corpus/templates/design/app/i18n/zh-TW.ts +277 -0
- package/corpus/templates/design/app/i18n-data.ts +3028 -1
- package/corpus/templates/design/app/pages/DesignEditor.tsx +5831 -904
- package/corpus/templates/design/app/pages/DesignSystemSetup.tsx +57 -221
- package/corpus/templates/design/changelog/2026-06-28-annotate-mode-now-combines-drawing-and-comment-pins-in-one-c.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-design-editor-panel-borders-are-cleaner-so-the-canvas-edge-s.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-drawing-prompts-now-reliably-open-and-submit-to-the-design-a.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-editor-app-menus-now-use-an-outline-agent-native-mark-with-b.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-figma-style-code-design-mode.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-layer-selection-now-updates-chat-context-without-opening-the.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-layer-selections-now-preserve-hidden-and-locked-canvas-state.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-left-sidebar-collapse-motion-and-footer-chrome-are-quieter.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-live-cursors-now-keep-names-beside-a-cleaner-pointer-marker.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-mode-switching-now-lives-in-a-compact-bottom-right-icon-dock.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-screen-overview-now-handles-zooming-drawing-opening-and-dele.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-screen-overview-now-selects-screens-on-click-and-opens-them-.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-screen-overview-zooms-into-the-active-screen-with-smoother-e.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-selected-element-chips-in-chat-are-shorter-and-easier-to-sca.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-the-design-editor-toolbar-is-more-compact-and-the-app-menu-m.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-tweaks-now-live-at-the-top-of-the-design-sidebar-instead-of-.md +6 -0
- package/corpus/templates/design/changelog/2026-06-28-tweaks-now-live-in-the-right-inspector-beside-the-design-tab.md +6 -0
- package/corpus/templates/design/changelog/2026-06-29-active-sidebar-rows-use-soft-highlights.md +6 -0
- package/corpus/templates/design/changelog/2026-06-29-agents-can-now-open-screen-overview-focus-screens-and-add.md +6 -0
- package/corpus/templates/design/changelog/2026-06-29-canvas-selection-no-longer-flashes-broken-prototype-html-whe.md +6 -0
- package/corpus/templates/design/changelog/2026-06-29-command-menu-selections-are-clearer-in-dark-mode.md +6 -0
- package/corpus/templates/design/changelog/2026-06-29-design-agents-now-edit-broad-copy-changes-more-reliably.md +6 -0
- package/corpus/templates/design/changelog/2026-06-29-design-editor-extensions-now-run-inline-beside-the-artboard.md +6 -0
- package/corpus/templates/design/changelog/2026-06-29-design-mode-top-chrome-now-groups-collaborators-preview-shar.md +6 -0
- package/corpus/templates/design/changelog/2026-06-29-element-selection-now-stays-on-the-intended-layer-after-sele.md +6 -0
- package/corpus/templates/design/changelog/2026-06-29-screen-overview-full-view-controls-now-sit-above-frames-inst.md +6 -0
- package/corpus/templates/design/changelog/2026-06-29-screen-overview-tools-can-draw-shapes-create-screens-and-kee.md +6 -0
- package/corpus/templates/design/changelog/2026-06-29-sidebars-use-darker-chrome-and-chat-warns-immediately.md +6 -0
- package/corpus/templates/design/changelog/2026-06-29-the-pen-tool-now-creates-anchor-based-bezier-vectors-with-ha.md +6 -0
- package/corpus/templates/design/changelog/2026-06-29-visual-edit-can-open-localhost-routes-as-url-backed-screens.md +6 -0
- package/corpus/templates/design/package.json +1 -0
- package/corpus/templates/design/server/db/schema.ts +26 -0
- package/corpus/templates/design/server/handlers/import-figma-system.ts +38 -85
- package/corpus/templates/design/server/lib/design-snapshot.ts +9 -1
- package/corpus/templates/design/server/plugins/agent-chat.ts +3 -0
- package/corpus/templates/design/shared/api.ts +27 -0
- package/corpus/templates/design/shared/canvas-frames.ts +103 -0
- package/corpus/templates/design/shared/canvas-math.ts +1058 -0
- package/corpus/templates/design/shared/code-layer.ts +2412 -0
- package/corpus/templates/design/shared/color-utils.ts +180 -0
- package/corpus/templates/design/shared/generation-session.ts +61 -0
- package/corpus/templates/design/shared/html-content.ts +21 -0
- package/corpus/templates/design/shared/pen-path.ts +207 -0
- package/corpus/templates/design/shared/shader-presets.ts +782 -0
- package/corpus/templates/design/shared/shader-safety.ts +137 -0
- package/corpus/templates/design/shared/source-mode.ts +237 -0
- package/corpus/templates/forms/app/components/layout/Sidebar.tsx +149 -6
- package/corpus/templates/forms/app/i18n/ar-SA.ts +2 -0
- package/corpus/templates/forms/app/i18n/de-DE.ts +2 -0
- package/corpus/templates/forms/app/i18n/en-US.ts +2 -0
- package/corpus/templates/forms/app/i18n/es-ES.ts +2 -0
- package/corpus/templates/forms/app/i18n/fr-FR.ts +2 -0
- package/corpus/templates/forms/app/i18n/hi-IN.ts +2 -0
- package/corpus/templates/forms/app/i18n/ja-JP.ts +2 -0
- package/corpus/templates/forms/app/i18n/ko-KR.ts +2 -0
- package/corpus/templates/forms/app/i18n/pt-BR.ts +2 -0
- package/corpus/templates/forms/app/i18n/zh-CN.ts +2 -0
- package/corpus/templates/forms/app/i18n/zh-TW.ts +2 -0
- package/corpus/templates/forms/changelog/2026-06-28-left-sidebar-collapses-into-an-animated-icon-rail.md +6 -0
- package/corpus/templates/macros/app/components/layout/AppLayout.tsx +2 -2
- package/corpus/templates/macros/changelog/2026-06-28-left-sidebar-footer-controls-use-less-divider-chrome.md +6 -0
- package/corpus/templates/mail/app/components/layout/AppLayout.tsx +408 -247
- package/corpus/templates/mail/app/i18n/ar-SA.ts +4 -0
- package/corpus/templates/mail/app/i18n/de-DE.ts +4 -0
- package/corpus/templates/mail/app/i18n/en-US.ts +4 -0
- package/corpus/templates/mail/app/i18n/es-ES.ts +4 -0
- package/corpus/templates/mail/app/i18n/fr-FR.ts +4 -0
- package/corpus/templates/mail/app/i18n/hi-IN.ts +4 -0
- package/corpus/templates/mail/app/i18n/ja-JP.ts +4 -0
- package/corpus/templates/mail/app/i18n/ko-KR.ts +4 -0
- package/corpus/templates/mail/app/i18n/pt-BR.ts +4 -0
- package/corpus/templates/mail/app/i18n/zh-CN.ts +4 -0
- package/corpus/templates/mail/app/i18n/zh-TW.ts +4 -0
- package/corpus/templates/mail/app/lib/utils.ts +2 -2
- package/corpus/templates/mail/changelog/2026-06-28-pinned-sidebar-collapses-into-an-animated-icon-rail.md +6 -0
- package/corpus/templates/plan/app/components/layout/Sidebar.tsx +6 -8
- package/corpus/templates/plan/app/components/plan/wireframe/Wireframe.tsx +1 -1
- package/corpus/templates/plan/app/global.css +61 -78
- package/corpus/templates/plan/app/pages/PlansPage.tsx +8 -0
- package/corpus/templates/plan/changelog/2026-06-28-left-sidebar-collapse-motion-and-footer-chrome-are-quieter.md +6 -0
- package/corpus/templates/plan/changelog/2026-06-28-plans-use-the-shared-neutral-light-and-dark-theme.md +6 -0
- package/corpus/templates/plan/changelog/2026-06-28-sending-open-feedback-from-a-plan-now-opens-the-inline-plan-.md +6 -0
- package/corpus/templates/slides/.agents/skills/design-systems/SKILL.md +9 -10
- package/corpus/templates/slides/AGENTS.md +3 -2
- package/corpus/templates/slides/actions/import-file.ts +26 -17
- package/corpus/templates/slides/actions/index-design-system-with-builder.ts +259 -0
- package/corpus/templates/slides/app/components/design-system/DesignSystemSetup.tsx +35 -167
- package/corpus/templates/slides/app/components/design-system/fig-import-response.ts +9 -13
- package/corpus/templates/slides/app/components/layout/Sidebar.tsx +5 -5
- package/corpus/templates/slides/app/context/DeckContext.tsx +1 -1
- package/corpus/templates/slides/app/i18n/ar-SA.ts +9 -37
- package/corpus/templates/slides/app/i18n/de-DE.ts +10 -25
- package/corpus/templates/slides/app/i18n/en-US.ts +9 -26
- package/corpus/templates/slides/app/i18n/es-ES.ts +10 -28
- package/corpus/templates/slides/app/i18n/fr-FR.ts +10 -28
- package/corpus/templates/slides/app/i18n/hi-IN.ts +9 -26
- package/corpus/templates/slides/app/i18n/ja-JP.ts +10 -22
- package/corpus/templates/slides/app/i18n/ko-KR.ts +9 -23
- package/corpus/templates/slides/app/i18n/pt-BR.ts +10 -28
- package/corpus/templates/slides/app/i18n/zh-CN.ts +9 -22
- package/corpus/templates/slides/app/i18n/zh-TW.ts +9 -22
- package/corpus/templates/slides/changelog/2026-06-28-left-sidebar-collapse-motion-and-footer-chrome-are-quieter.md +6 -0
- package/corpus/templates/slides/server/handlers/import-figma-system.ts +44 -12
- package/corpus/templates/slides/server/lib/chat-attachments.ts +1 -1
- package/corpus/templates/videos/app/components/NewCompositionPopover.tsx +1 -1
- package/corpus/templates/videos/app/components/Sidebar.tsx +2 -2
- package/corpus/templates/videos/app/components/layout/Layout.tsx +29 -2
- package/corpus/templates/videos/app/components/layout/NavSidebar.tsx +113 -30
- package/corpus/templates/videos/app/i18n/ar-SA.ts +2 -0
- package/corpus/templates/videos/app/i18n/de-DE.ts +2 -0
- package/corpus/templates/videos/app/i18n/en-US.ts +2 -0
- package/corpus/templates/videos/app/i18n/es-ES.ts +2 -0
- package/corpus/templates/videos/app/i18n/fr-FR.ts +2 -0
- package/corpus/templates/videos/app/i18n/hi-IN.ts +2 -0
- package/corpus/templates/videos/app/i18n/ja-JP.ts +2 -0
- package/corpus/templates/videos/app/i18n/ko-KR.ts +2 -0
- package/corpus/templates/videos/app/i18n/pt-BR.ts +2 -0
- package/corpus/templates/videos/app/i18n/zh-CN.ts +2 -0
- package/corpus/templates/videos/app/i18n/zh-TW.ts +2 -0
- package/corpus/templates/videos/changelog/2026-06-28-left-sidebar-collapses-into-an-animated-icon-rail.md +6 -0
- package/dist/agent/engine/index.d.ts +1 -1
- package/dist/agent/engine/index.d.ts.map +1 -1
- package/dist/agent/engine/index.js +1 -1
- package/dist/agent/engine/index.js.map +1 -1
- package/dist/agent/engine/registry.d.ts +9 -0
- package/dist/agent/engine/registry.d.ts.map +1 -1
- package/dist/agent/engine/registry.js +37 -0
- package/dist/agent/engine/registry.js.map +1 -1
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +4 -3
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/application-state/handlers.js +1 -1
- package/dist/application-state/handlers.js.map +1 -1
- package/dist/brand-kit/index.d.ts +1 -1
- package/dist/brand-kit/index.js +1 -1
- package/dist/brand-kit/index.js.map +1 -1
- package/dist/cli/design-connect.d.ts +52 -0
- package/dist/cli/design-connect.d.ts.map +1 -0
- package/dist/cli/design-connect.js +409 -0
- package/dist/cli/design-connect.js.map +1 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/skills.d.ts +3 -0
- package/dist/cli/skills.d.ts.map +1 -1
- package/dist/cli/skills.js +139 -3
- package/dist/cli/skills.js.map +1 -1
- package/dist/client/AgentPanel.js +1 -1
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +38 -8
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/MultiTabAssistantChat.js +1 -1
- package/dist/client/MultiTabAssistantChat.js.map +1 -1
- package/dist/client/agent-chat.d.ts +6 -0
- package/dist/client/agent-chat.d.ts.map +1 -1
- package/dist/client/agent-chat.js +17 -3
- package/dist/client/agent-chat.js.map +1 -1
- package/dist/client/blocks/library/MermaidBlock.js +1 -1
- package/dist/client/blocks/library/MermaidBlock.js.map +1 -1
- package/dist/client/blocks/library/diagram.js +1 -1
- package/dist/client/blocks/library/diagram.js.map +1 -1
- package/dist/client/blocks/library/wireframe.js +1 -1
- package/dist/client/blocks/library/wireframe.js.map +1 -1
- package/dist/client/chat/message-components.js +1 -1
- package/dist/client/chat/message-components.js.map +1 -1
- package/dist/client/chat-model-groups.d.ts.map +1 -1
- package/dist/client/chat-model-groups.js +1 -2
- package/dist/client/chat-model-groups.js.map +1 -1
- package/dist/client/components/LiveCursorOverlay.d.ts +1 -2
- package/dist/client/components/LiveCursorOverlay.d.ts.map +1 -1
- package/dist/client/components/LiveCursorOverlay.js +19 -40
- package/dist/client/components/LiveCursorOverlay.js.map +1 -1
- package/dist/client/composer/TiptapComposer.d.ts +3 -1
- package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
- package/dist/client/composer/TiptapComposer.js +86 -24
- package/dist/client/composer/TiptapComposer.js.map +1 -1
- package/dist/client/composer/useVoiceDictation.d.ts +9 -0
- package/dist/client/composer/useVoiceDictation.d.ts.map +1 -1
- package/dist/client/composer/useVoiceDictation.js +154 -32
- package/dist/client/composer/useVoiceDictation.js.map +1 -1
- package/dist/client/extensions/portable-extension.d.ts +1 -1
- package/dist/client/extensions/portable-extension.d.ts.map +1 -1
- package/dist/client/extensions/portable-extension.js.map +1 -1
- package/dist/client/frame-protocol.d.ts +17 -2
- package/dist/client/frame-protocol.d.ts.map +1 -1
- package/dist/client/frame-protocol.js.map +1 -1
- package/dist/client/rich-markdown-editor/RegistryBlockNode.js +2 -2
- package/dist/client/rich-markdown-editor/RegistryBlockNode.js.map +1 -1
- package/dist/client/sharing/ShareButton.d.ts +2 -0
- package/dist/client/sharing/ShareButton.d.ts.map +1 -1
- package/dist/client/sharing/ShareButton.js +7 -6
- package/dist/client/sharing/ShareButton.js.map +1 -1
- package/dist/client/use-agent-engine-configured.d.ts +5 -0
- package/dist/client/use-agent-engine-configured.d.ts.map +1 -1
- package/dist/client/use-agent-engine-configured.js +51 -25
- package/dist/client/use-agent-engine-configured.js.map +1 -1
- package/dist/code-agents/transcript-normalizer.js +1 -1
- package/dist/code-agents/transcript-normalizer.js.map +1 -1
- package/dist/collab/routes.d.ts +1 -1
- package/dist/extensions/path.d.ts +1 -1
- package/dist/extensions/path.d.ts.map +1 -1
- package/dist/extensions/path.js.map +1 -1
- package/dist/file-upload/actions/upload-image.d.ts +2 -2
- package/dist/integrations/a2a-continuation-processor.js +1 -1
- package/dist/integrations/a2a-continuation-processor.js.map +1 -1
- package/dist/mcp/build-server.d.ts +1 -1
- package/dist/mcp/build-server.d.ts.map +1 -1
- package/dist/mcp/build-server.js.map +1 -1
- package/dist/notifications/routes.d.ts +3 -3
- package/dist/observability/routes.d.ts +5 -5
- package/dist/org/handlers.js +5 -5
- package/dist/org/handlers.js.map +1 -1
- package/dist/org/plugin.js +2 -2
- package/dist/org/plugin.js.map +1 -1
- package/dist/scripts/call-agent.js +1 -1
- package/dist/scripts/call-agent.js.map +1 -1
- package/dist/scripts/db/safety.js +1 -1
- package/dist/scripts/db/safety.js.map +1 -1
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +3 -0
- package/dist/server/auth.js.map +1 -1
- package/dist/server/builder-design-systems.d.ts +28 -0
- package/dist/server/builder-design-systems.d.ts.map +1 -0
- package/dist/server/builder-design-systems.js +217 -0
- package/dist/server/builder-design-systems.js.map +1 -0
- package/dist/server/core-routes-plugin.d.ts +1 -0
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +20 -3
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/transcribe-voice.d.ts +1 -1
- package/dist/server/transcribe-voice.d.ts.map +1 -1
- package/dist/server/transcribe-voice.js +40 -24
- package/dist/server/transcribe-voice.js.map +1 -1
- package/dist/shared/mcp-embed-headers.d.ts +1 -0
- package/dist/shared/mcp-embed-headers.d.ts.map +1 -1
- package/dist/shared/mcp-embed-headers.js +20 -1
- package/dist/shared/mcp-embed-headers.js.map +1 -1
- package/dist/styles/agent-native.css +60 -4
- package/dist/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +10 -0
- package/dist/usage/store.js +2 -2
- package/dist/usage/store.js.map +1 -1
- package/dist/vite/client.d.ts.map +1 -1
- package/dist/vite/client.js +2 -0
- package/dist/vite/client.js.map +1 -1
- package/dist/voice/index.d.ts +5 -0
- package/dist/voice/index.d.ts.map +1 -0
- package/dist/voice/index.js +4 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/voice/voice-cleanup-prompt.d.ts +6 -0
- package/dist/voice/voice-cleanup-prompt.d.ts.map +1 -0
- package/dist/voice/voice-cleanup-prompt.js +26 -0
- package/dist/voice/voice-cleanup-prompt.js.map +1 -0
- package/dist/voice/voice-context.d.ts +25 -0
- package/dist/voice/voice-context.d.ts.map +1 -0
- package/dist/voice/voice-context.js +156 -0
- package/dist/voice/voice-context.js.map +1 -0
- package/dist/voice/voice-replacements.d.ts +4 -0
- package/dist/voice/voice-replacements.d.ts.map +1 -0
- package/dist/voice/voice-replacements.js +52 -0
- package/dist/voice/voice-replacements.js.map +1 -0
- package/docs/content/locales/ar-SA/skills-guide.mdx +5 -0
- package/docs/content/locales/ar-SA/template-design.mdx +55 -1
- package/docs/content/locales/de-DE/skills-guide.mdx +5 -0
- package/docs/content/locales/de-DE/template-design.mdx +66 -1
- package/docs/content/locales/es-ES/skills-guide.mdx +5 -0
- package/docs/content/locales/es-ES/template-design.mdx +65 -1
- package/docs/content/locales/fr-FR/skills-guide.mdx +5 -0
- package/docs/content/locales/fr-FR/template-design.mdx +64 -1
- package/docs/content/locales/hi-IN/skills-guide.mdx +5 -0
- package/docs/content/locales/hi-IN/template-design.mdx +59 -1
- package/docs/content/locales/ja-JP/skills-guide.mdx +5 -0
- package/docs/content/locales/ja-JP/template-design.mdx +62 -1
- package/docs/content/locales/ko-KR/skills-guide.mdx +5 -0
- package/docs/content/locales/ko-KR/template-design.mdx +58 -1
- package/docs/content/locales/pt-BR/skills-guide.mdx +5 -0
- package/docs/content/locales/pt-BR/template-design.mdx +62 -1
- package/docs/content/locales/zh-CN/skills-guide.mdx +5 -0
- package/docs/content/locales/zh-CN/template-design.mdx +50 -1
- package/docs/content/locales/zh-TW/skills-guide.mdx +5 -0
- package/docs/content/locales/zh-TW/template-design.mdx +52 -1
- package/docs/content/skills-guide.mdx +5 -0
- package/docs/content/template-design.mdx +59 -1
- package/package.json +2 -1
- package/src/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +10 -0
- package/corpus/templates/design/actions/import-figma-file.ts +0 -166
- package/corpus/templates/design/app/components/design/DesignToolbar.tsx +0 -339
- package/corpus/templates/design/app/components/design/PresentMode.tsx +0 -68
- package/corpus/templates/design/app/components/design/ViewportTabs.tsx +0 -149
- package/corpus/templates/design/app/components/design/ZoomControls.tsx +0 -157
- package/corpus/templates/slides/server/lib/fig-design-system.ts +0 -110
|
@@ -53,6 +53,12 @@ export interface AgentChatMessage {
|
|
|
53
53
|
requestMode?: AgentChatRequestMode;
|
|
54
54
|
/** Scoped system prompt additions for this sub-agent */
|
|
55
55
|
instructions?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Message delivery target. Auto-submitted MCP App messages normally relay to
|
|
58
|
+
* the host chat; use "local" when a control explicitly targets this app's
|
|
59
|
+
* own AgentSidebar.
|
|
60
|
+
*/
|
|
61
|
+
chatTarget?: "auto" | "local";
|
|
56
62
|
/**
|
|
57
63
|
* Whether to open the agent sidebar if it's currently hidden.
|
|
58
64
|
* Defaults to true — submitting a chat should make the response visible.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-chat.d.ts","sourceRoot":"","sources":["../../src/client/agent-chat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAmBrE,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,MAAM,CAAC;AAElD,MAAM,WAAW,gBAAgB;IAC/B,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qCAAqC;IACrC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B,yCAAyC;IACzC,uBAAuB,CAAC,EAAE,MAAM,EAAE,C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AI,IAAI,CAGrD"}
|
|
@@ -291,7 +291,17 @@ export function normalizeAgentComposerReference(value) {
|
|
|
291
291
|
function postAgentChatContextMessage(type, data, options) {
|
|
292
292
|
if (typeof window === "undefined")
|
|
293
293
|
return;
|
|
294
|
-
const
|
|
294
|
+
const shouldForwardOpenSidebar = (type === AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE &&
|
|
295
|
+
options.openSidebar === false) ||
|
|
296
|
+
(type !== AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE &&
|
|
297
|
+
options.openSidebar === true);
|
|
298
|
+
const payloadData = shouldForwardOpenSidebar && typeof data === "object" && data !== null
|
|
299
|
+
? {
|
|
300
|
+
...data,
|
|
301
|
+
openSidebar: options.openSidebar,
|
|
302
|
+
}
|
|
303
|
+
: data;
|
|
304
|
+
const payload = { type, data: payloadData };
|
|
295
305
|
const targetSelf = isInBuilderFrame() || isDirectMcpAppEmbedSession();
|
|
296
306
|
const target = targetSelf
|
|
297
307
|
? window
|
|
@@ -448,6 +458,7 @@ function readStoredAgentChatRequestMode() {
|
|
|
448
458
|
export function sendToAgentChat(opts) {
|
|
449
459
|
const tabId = opts.tabId ?? generateTabId();
|
|
450
460
|
const isCodeRequest = opts.type === "code" || opts.requiresCode === true;
|
|
461
|
+
const localChatTarget = opts.chatTarget === "local";
|
|
451
462
|
const requestMode = normalizeAgentChatRequestMode(opts.requestMode ?? opts.mode) ??
|
|
452
463
|
readStoredAgentChatRequestMode();
|
|
453
464
|
if (isCodeRequest && isInBuilderFrame()) {
|
|
@@ -469,7 +480,9 @@ export function sendToAgentChat(opts) {
|
|
|
469
480
|
...(requestMode ? { mode: requestMode, requestMode } : {}),
|
|
470
481
|
},
|
|
471
482
|
};
|
|
472
|
-
if (opts.submit !== false &&
|
|
483
|
+
if (opts.submit !== false &&
|
|
484
|
+
!localChatTarget &&
|
|
485
|
+
isMcpAppChatBridgeEnabled()) {
|
|
473
486
|
const directHostMessage = sendMcpAppHostMessage({
|
|
474
487
|
message: opts.message,
|
|
475
488
|
context: opts.context,
|
|
@@ -491,7 +504,8 @@ export function sendToAgentChat(opts) {
|
|
|
491
504
|
return tabId;
|
|
492
505
|
}
|
|
493
506
|
const shouldOpenSidebar = opts.openSidebar !== false && !opts.background;
|
|
494
|
-
const targetSelf = !isCodeRequest &&
|
|
507
|
+
const targetSelf = !isCodeRequest &&
|
|
508
|
+
(localChatTarget || isInBuilderFrame() || isDirectMcpAppEmbedSession());
|
|
495
509
|
const target = targetSelf
|
|
496
510
|
? window
|
|
497
511
|
: window.parent !== window
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-chat.js","sourceRoot":"","sources":["../../src/client/agent-chat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,4BAA4B,EAC5B,iCAAiC,GAClC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,+BAA+B,EAC/B,qBAAqB,GACtB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAyI1D,MAAM,uBAAuB,GAAG,wBAAwB,CAAC;AACzD,MAAM,4BAA4B,GAAG,oBAAoB,CAAC;AAC1D,MAAM,wBAAwB,GAAG,wBAAwB,CAAC;AAC1D,MAAM,CAAC,MAAM,gCAAgC,GAC3C,gCAAgC,CAAC;AACnC,MAAM,CAAC,MAAM,mCAAmC,GAAG,4BAA4B,CAAC;AAChF,MAAM,CAAC,MAAM,sCAAsC,GACjD,+BAA+B,CAAC;AAClC,MAAM,CAAC,MAAM,qCAAqC,GAChD,8BAA8B,CAAC;AACjC,MAAM,CAAC,MAAM,wCAAwC,GACnD,qCAAqC,CAAC;AACxC,MAAM,CAAC,MAA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,CAAC;IACF,2BAA2B,CACzB,sCAAsC,EACtC,EAAE,GAAG,EAAE,EACP,EAAE,WAAW,EAAE,CAChB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,IAAI,GAAoC,EAAE;IAE1C,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO;IAC1C,4BAA4B,CAAC,EAAE,CAAC,CAAC;IACjC,2BAA2B,CACzB,qCAAqC,EACrC,EAAE,EACF,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,KAAK,IAAI,EAAE,CAC3C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,8BAA8B;IAC5C,qBAAqB,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IACpD,+BAA+B,EAAE,CAAC;AACpC,CAAC","sourcesContent":["/**\n * Agent Chat Bridge (browser)\n *\n * Sends structured messages to the agent chat from UI interactions.\n * Messages are sent via postMessage to the parent window (or self if top-level).\n * Builder frames are special: code requests go to Builder, but content prompts\n * stay inside the embedded app so its own AgentSidebar can receive them.\n */\n\nimport type { ReasoningEffort } from \"../shared/reasoning-effort.js\";\nimport { agentNativePath } from \"./api-path.js\";\nimport {\n isInBuilderFrame,\n isTrustedBuilderMessage,\n sendToBuilderChat,\n} from \"./builder-frame.js\";\nimport {\n isEmbedAuthActive,\n isEmbedMcpChatBridgeActive,\n markEmbedMcpChatBridgeActive,\n readEmbedMcpChatBridgeFlagFromUrl,\n} from \"./embed-auth.js\";\nimport {\n getFramePostMessageTargetOrigin,\n isTrustedFrameMessage,\n} from \"./frame.js\";\nimport { sendMcpAppHostMessage } from \"./mcp-app-host.js\";\n\nexport type AgentChatRequestMode = \"act\" | \"plan\";\n\nexport interface AgentChatMessage {\n /** The visible prompt message sent to the chat */\n message: string;\n /** Hidden context appended to the message (not shown in chat UI) */\n context?: string;\n /** true = auto-submit, false = prefill only, omit = use project setting */\n submit?: boolean;\n /** Optional project slug for structured context */\n projectSlug?: string;\n /** Optional preset name for downstream consumers */\n preset?: string;\n /** Optional reference image paths */\n referenceImagePaths?: string[];\n /** Optional uploaded reference images */\n uploadedReferenceImages?: string[];\n /** Optional image data URLs to include in the submitted chat message */\n images?: string[];\n /** Stable tab identifier — auto-generated if omitted */\n tabId?: string;\n /**\n * Message routing type:\n * - \"content\" (default): stays in the embedded app agent for content/data operations\n * - \"code\": routes to the code editing frame (Agent Native Desktop or Builder.io)\n *\n * When type is \"code\" and no frame is connected, a dialog is shown.\n * `requiresCode: true` is treated as `type: \"code\"` for backward compatibility.\n */\n type?: \"content\" | \"code\";\n /** @deprecated Use `type: \"code\"` instead. If true, treated as `type: \"code\"`. */\n requiresCode?: boolean;\n /** Model preference for this sub-agent (e.g. \"claude-haiku-4-5\"). Uses default if omitted */\n model?: string;\n /** Engine preference paired with model for cross-provider switches. */\n engine?: string;\n /** Reasoning effort preference paired with model. */\n effort?: ReasoningEffort;\n /**\n * Execution mode for this submitted turn. When omitted, sendToAgentChat\n * snapshots the current AgentPanel mode from localStorage when available.\n */\n mode?: AgentChatRequestMode;\n /** @deprecated Use `mode` instead. */\n requestMode?: AgentChatRequestMode;\n /** Scoped system prompt additions for this sub-agent */\n instructions?: string;\n /**\n * Whether to open the agent sidebar if it's currently hidden.\n * Defaults to true — submitting a chat should make the response visible.\n * Pass `false` for background/silent sends that shouldn't pop the UI open.\n */\n openSidebar?: boolean;\n /**\n * When true, opens a new chat tab before sending the message.\n * Use for creation requests (create tool, dashboard, etc.) that deserve\n * their own isolated thread rather than cluttering an existing conversation.\n */\n newTab?: boolean;\n /**\n * When true with newTab, creates the tab in the background without\n * focusing it or opening the sidebar. The message runs silently.\n */\n background?: boolean;\n}\n\nexport interface AgentChatContextItem {\n /** Stable key used to replace an existing context nugget. */\n key: string;\n /** Short label shown in the composer context chip. */\n title: string;\n /** Hidden context included with the next submitted prompt. */\n context: string;\n}\n\nexport interface AgentChatContextSetOptions extends AgentChatContextItem {\n /**\n * Whether to open the agent sidebar if it's currently hidden.\n * Defaults to true so the user can see the staged context.\n */\n openSidebar?: boolean;\n}\n\n/** @deprecated Use `AgentChatContextSetOptions` instead. */\nexport type AgentChatContextMessage = AgentChatContextSetOptions;\n\nexport interface AgentChatContextState {\n items: AgentChatContextItem[];\n updatedAt: number;\n}\n\nexport interface AgentComposerReference {\n label: string;\n icon?: string;\n source?: string;\n refType: string;\n refId?: string | null;\n refPath?: string | null;\n /** Stable composer slot this reference occupies. Slot references replace older values. */\n slotKey?: string;\n /** Short label shown before the selected value in the composer chip. */\n slotLabel?: string;\n /** Additional app-defined data used by the client for filtering and grouping. */\n metadata?: Record<string, unknown>;\n /** Slots to remove when this reference is inserted or removed. */\n clearsSlots?: string[];\n /** Additional references to insert before this one. */\n relatedReferences?: AgentComposerReference[];\n}\n\nexport interface AgentComposerReferenceInsertOptions {\n /**\n * Whether to open the agent sidebar before inserting the reference.\n * Defaults to false so contextual auto-tags can stay quiet.\n */\n openSidebar?: boolean;\n}\n\nexport interface AgentComposerReferenceInsertPayload extends AgentComposerReference {\n insertMessageId: string;\n}\n\nexport interface AgentChatContextMutationOptions {\n /**\n * Whether to open the agent sidebar if it's currently hidden.\n * Defaults to true for set/add and false for remove/clear.\n */\n openSidebar?: boolean;\n}\n\nexport interface AgentChatContextRemoveOptions extends AgentChatContextMutationOptions {\n /** Stable key of the staged context nugget to remove. */\n key: string;\n}\n\nconst AGENT_CHAT_MESSAGE_TYPE = \"agentNative.submitChat\";\nconst AGENT_CHAT_CONTEXT_STATE_KEY = \"agent-chat-context\";\nconst AGENT_CHAT_EXEC_MODE_KEY = \"agent-native-exec-mode\";\nexport const AGENT_CHAT_CONTEXT_CHANGED_EVENT =\n \"agentNative.chatContextChanged\";\nexport const AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE = \"agentNative.setChatContext\";\nexport const AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE =\n \"agentNative.removeChatContext\";\nexport const AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE =\n \"agentNative.clearChatContext\";\nexport const AGENT_CHAT_INSERT_REFERENCE_MESSAGE_TYPE =\n \"agentNative.insertComposerReference\";\nexport const AGENT_CHAT_INSERT_REFERENCE_EVENT =\n \"agentNative:insert-composer-reference\";\nconst AGENT_PANEL_PREPARE_EVENT = \"agent-panel:prepare\";\n\nlet agentChatContextState: AgentChatContextState = {\n items: [],\n updatedAt: 0,\n};\nconst agentChatContextListeners = new Set<() => void>();\n\n/**\n * Listen for chatRunning messages from the frame (postMessage)\n * and re-dispatch as a CustomEvent so hooks like useAgentChatGenerating() work.\n */\nif (typeof window !== \"undefined\") {\n window.addEventListener(\"message\", (event) => {\n if (!isTrustedFrameMessage(event) && !isTrustedBuilderMessage(event)) {\n return;\n }\n if (\n event.data?.type === \"agentNative.chatRunning\" ||\n event.data?.type === \"builder.chatRunning\"\n ) {\n window.dispatchEvent(\n new CustomEvent(\"agentNative.chatRunning\", {\n detail: event.data.detail ?? event.data.data,\n }),\n );\n }\n });\n}\n\n/** Generate a unique tab ID */\nexport function generateTabId(): string {\n return `chat-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n}\n\n/** Unique id for one submitted message, used to dedup live + replayed sends. */\nfunction generateSubmitMessageId(): string {\n return `submit-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n}\n\n// Self-submit buffer: same-window sends post to `window` itself, but the\n// receiver is lazy-loaded and may not be listening yet. Buffer each submit so\n// the panel can replay it on mount; claimAgentChatSubmit dedups by id so a\n// submit received both live and replayed is delivered exactly once.\ninterface BufferedSelfSubmit {\n id: string;\n data: Record<string, unknown>;\n at: number;\n}\n\nconst SELF_SUBMIT_BUFFER_TTL_MS = 8000;\nconst bufferedSelfSubmits: BufferedSelfSubmit[] = [];\nconst claimedSubmitIds = new Set<string>();\n\nfunction pruneSelfSubmitBuffer(now: number): void {\n for (let i = bufferedSelfSubmits.length - 1; i >= 0; i -= 1) {\n if (now - bufferedSelfSubmits[i].at > SELF_SUBMIT_BUFFER_TTL_MS) {\n const [removed] = bufferedSelfSubmits.splice(i, 1);\n if (removed) claimedSubmitIds.delete(removed.id);\n }\n }\n}\n\nfunction bufferSelfSubmit(data: Record<string, unknown>): void {\n const id =\n typeof data.submitMessageId === \"string\" ? data.submitMessageId : undefined;\n if (!id) return;\n const now = Date.now();\n pruneSelfSubmitBuffer(now);\n bufferedSelfSubmits.push({ id, data, at: now });\n}\n\n/** Unclaimed self-submit payloads, for the panel to replay once it mounts. */\nexport function drainBufferedAgentChatSubmits(): Array<\n Record<string, unknown>\n> {\n pruneSelfSubmitBuffer(Date.now());\n return bufferedSelfSubmits\n .filter((entry) => !claimedSubmitIds.has(entry.id))\n .map((entry) => entry.data);\n}\n\n/** Claim a submit; false if already handled. Idless submits always pass. */\nexport function claimAgentChatSubmit(id: string | undefined): boolean {\n if (!id) return true;\n if (claimedSubmitIds.has(id)) return false;\n claimedSubmitIds.add(id);\n return true;\n}\n\n/** Test-only: reset the self-submit buffer and claim set. */\nexport function _resetAgentChatSubmitBufferForTests(): void {\n bufferedSelfSubmits.length = 0;\n claimedSubmitIds.clear();\n}\n\nexport function normalizeAgentChatContextItem(\n item: unknown,\n): AgentChatContextItem | null {\n if (typeof item !== \"object\" || item === null) return null;\n const candidate = item as Partial<AgentChatContextItem>;\n if (\n typeof candidate.key !== \"string\" ||\n typeof candidate.context !== \"string\" ||\n typeof candidate.title !== \"string\"\n ) {\n return null;\n }\n const key = candidate.key.trim();\n const context = candidate.context.trim();\n if (!key || !context) return null;\n return {\n key,\n title: candidate.title.trim() || key,\n context,\n };\n}\n\nexport function normalizeAgentChatContextItems(\n items: unknown,\n): AgentChatContextItem[] {\n if (!Array.isArray(items)) return [];\n const deduped = new Map<string, AgentChatContextItem>();\n for (const rawItem of items) {\n const item = normalizeAgentChatContextItem(rawItem);\n if (!item) continue;\n deduped.set(item.key, item);\n }\n return [...deduped.values()];\n}\n\nfunction normalizeAgentChatContextState(\n value: unknown,\n): AgentChatContextState | null {\n if (!value || typeof value !== \"object\") return null;\n const raw = value as {\n value?: unknown;\n items?: unknown;\n updatedAt?: unknown;\n };\n const candidate =\n raw.value && typeof raw.value === \"object\"\n ? (raw.value as { items?: unknown; updatedAt?: unknown })\n : raw;\n const items = normalizeAgentChatContextItems(candidate.items);\n return {\n items,\n updatedAt:\n typeof candidate.updatedAt === \"number\" ? candidate.updatedAt : 0,\n };\n}\n\nfunction withReplacedAgentChatContextItem(\n items: readonly AgentChatContextItem[],\n item: AgentChatContextItem,\n): AgentChatContextItem[] {\n const index = items.findIndex((current) => current.key === item.key);\n if (index === -1) return [...items, item];\n return items.map((current, currentIndex) =>\n currentIndex === index ? item : current,\n );\n}\n\nfunction notifyAgentChatContextListeners(): void {\n for (const listener of agentChatContextListeners) listener();\n}\n\nfunction persistAgentChatContextState(state: AgentChatContextState): void {\n if (typeof window === \"undefined\" || typeof fetch !== \"function\") return;\n fetch(\n agentNativePath(\n `/_agent-native/application-state/${AGENT_CHAT_CONTEXT_STATE_KEY}`,\n ),\n {\n method: \"PUT\",\n keepalive: true,\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(state),\n },\n ).catch(() => {});\n}\n\nexport function publishAgentChatContextItems(\n items: readonly AgentChatContextItem[],\n options?: { persist?: boolean; updatedAt?: number },\n): AgentChatContextState {\n const next: AgentChatContextState = {\n items: normalizeAgentChatContextItems([...items]),\n updatedAt: options?.updatedAt ?? Date.now(),\n };\n if (next.updatedAt < agentChatContextState.updatedAt) {\n return agentChatContextState;\n }\n agentChatContextState = next;\n notifyAgentChatContextListeners();\n if (typeof window !== \"undefined\") {\n window.dispatchEvent(\n new CustomEvent(AGENT_CHAT_CONTEXT_CHANGED_EVENT, {\n detail: next,\n }),\n );\n }\n if (options?.persist !== false) {\n persistAgentChatContextState(next);\n }\n return next;\n}\n\nexport function getAgentChatContextState(): AgentChatContextState {\n return agentChatContextState;\n}\n\nexport function listAgentChatContext(): AgentChatContextItem[] {\n return [...agentChatContextState.items];\n}\n\nexport function subscribeAgentChatContext(listener: () => void): () => void {\n agentChatContextListeners.add(listener);\n return () => {\n agentChatContextListeners.delete(listener);\n };\n}\n\nexport async function refreshAgentChatContext(): Promise<AgentChatContextState> {\n if (typeof window === \"undefined\" || typeof fetch !== \"function\") {\n return agentChatContextState;\n }\n try {\n const res = await fetch(\n agentNativePath(\n `/_agent-native/application-state/${AGENT_CHAT_CONTEXT_STATE_KEY}`,\n ),\n );\n if (!res.ok || res.status === 204) return agentChatContextState;\n const text = await res.text();\n if (!text) return agentChatContextState;\n const state = normalizeAgentChatContextState(JSON.parse(text));\n if (!state) return agentChatContextState;\n return publishAgentChatContextItems(state.items, {\n persist: false,\n updatedAt: state.updatedAt,\n });\n } catch {\n return agentChatContextState;\n }\n}\n\nexport function formatAgentChatContextItemsForPrompt(\n items: readonly AgentChatContextItem[],\n): string {\n return items\n .map(normalizeAgentChatContextItem)\n .filter((item): item is AgentChatContextItem => item !== null)\n .map((item) => [`## ${item.title}`, item.context].join(\"\\n\"))\n .join(\"\\n\\n\");\n}\n\nexport function appendAgentChatContextToMessage(\n message: string,\n context: string,\n): string {\n const trimmedContext = context.trim();\n if (!trimmedContext) return message;\n return `${message.trim()}\\n\\n<context>\\n${trimmedContext}\\n</context>`;\n}\n\nfunction normalizeStringArray(value: unknown): string[] | undefined {\n if (!Array.isArray(value)) return undefined;\n const normalized = value\n .filter((item): item is string => typeof item === \"string\")\n .map((item) => item.trim())\n .filter(Boolean);\n return normalized.length > 0 ? normalized : undefined;\n}\n\nfunction normalizeMetadata(\n value: unknown,\n): Record<string, unknown> | undefined {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return undefined;\n }\n return value as Record<string, unknown>;\n}\n\nfunction normalizeAgentComposerReferenceInternal(\n value: unknown,\n depth: number,\n): AgentComposerReference | null {\n if (typeof value !== \"object\" || value === null) return null;\n const candidate = value as Partial<AgentComposerReference>;\n const label =\n typeof candidate.label === \"string\" ? candidate.label.trim() : \"\";\n const refType =\n typeof candidate.refType === \"string\" ? candidate.refType.trim() : \"\";\n if (!label || !refType) return null;\n const normalized: AgentComposerReference = {\n label,\n icon:\n typeof candidate.icon === \"string\" && candidate.icon.trim()\n ? candidate.icon.trim()\n : undefined,\n source:\n typeof candidate.source === \"string\" && candidate.source.trim()\n ? candidate.source.trim()\n : undefined,\n refType,\n refId:\n typeof candidate.refId === \"string\" && candidate.refId.trim()\n ? candidate.refId.trim()\n : null,\n refPath:\n typeof candidate.refPath === \"string\" && candidate.refPath.trim()\n ? candidate.refPath.trim()\n : null,\n };\n const slotKey =\n typeof candidate.slotKey === \"string\" ? candidate.slotKey.trim() : \"\";\n if (slotKey) normalized.slotKey = slotKey;\n const slotLabel =\n typeof candidate.slotLabel === \"string\" ? candidate.slotLabel.trim() : \"\";\n if (slotLabel) normalized.slotLabel = slotLabel;\n const metadata = normalizeMetadata(candidate.metadata);\n if (metadata) normalized.metadata = metadata;\n const clearsSlots = normalizeStringArray(candidate.clearsSlots);\n if (clearsSlots) normalized.clearsSlots = clearsSlots;\n if (depth < 3 && Array.isArray(candidate.relatedReferences)) {\n const relatedReferences = candidate.relatedReferences\n .map((item) => normalizeAgentComposerReferenceInternal(item, depth + 1))\n .filter((item): item is AgentComposerReference => item !== null);\n if (relatedReferences.length > 0) {\n normalized.relatedReferences = relatedReferences;\n }\n }\n return normalized;\n}\n\nexport function normalizeAgentComposerReference(\n value: unknown,\n): AgentComposerReference | null {\n return normalizeAgentComposerReferenceInternal(value, 0);\n}\n\nfunction postAgentChatContextMessage(\n type:\n | typeof AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE\n | typeof AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE\n | typeof AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE,\n data: unknown,\n options: { openSidebar: boolean },\n): void {\n if (typeof window === \"undefined\") return;\n\n const payload = { type, data };\n const targetSelf = isInBuilderFrame() || isDirectMcpAppEmbedSession();\n const target = targetSelf\n ? window\n : window.parent !== window\n ? window.parent\n : window;\n const targetOrigin = targetSelf\n ? window.location.origin\n : getFramePostMessageTargetOrigin() || window.location.origin;\n\n if (options.openSidebar) {\n window.dispatchEvent(\n new CustomEvent(\"agent-panel:set-mode\", {\n detail: { mode: \"chat\" },\n }),\n );\n window.dispatchEvent(new CustomEvent(\"agent-panel:open\"));\n } else {\n window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));\n }\n\n const postToTarget = () => target.postMessage(payload, targetOrigin);\n if (target === window) {\n setTimeout(postToTarget, 0);\n } else {\n postToTarget();\n }\n}\n\nfunction postAgentChatReferenceMessage(\n payload: AgentComposerReferenceInsertPayload,\n options: { openSidebar: boolean },\n): void {\n if (typeof window === \"undefined\") return;\n\n const message = {\n type: AGENT_CHAT_INSERT_REFERENCE_MESSAGE_TYPE,\n data: payload,\n };\n const targetSelf = isInBuilderFrame() || isDirectMcpAppEmbedSession();\n const target = targetSelf\n ? window\n : window.parent !== window\n ? window.parent\n : window;\n const targetOrigin = targetSelf\n ? window.location.origin\n : getFramePostMessageTargetOrigin() || window.location.origin;\n\n if (options.openSidebar) {\n window.dispatchEvent(\n new CustomEvent(\"agent-panel:set-mode\", {\n detail: { mode: \"chat\" },\n }),\n );\n window.dispatchEvent(new CustomEvent(\"agent-panel:open\"));\n } else {\n window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));\n }\n\n window.dispatchEvent(\n new CustomEvent(AGENT_CHAT_INSERT_REFERENCE_EVENT, {\n detail: payload,\n }),\n );\n\n const postToTarget = () => target.postMessage(message, targetOrigin);\n if (target === window) {\n setTimeout(postToTarget, 0);\n } else {\n postToTarget();\n }\n}\n\nfunction isMcpAppChatBridgeEnabled(): boolean {\n if (typeof window === \"undefined\" || window.parent === window) return false;\n if (readEmbedMcpChatBridgeFlagFromUrl()) markEmbedMcpChatBridgeActive();\n return isEmbedMcpChatBridgeActive() && isEmbedAuthActive();\n}\n\nfunction isDirectMcpAppEmbedSession(): boolean {\n if (typeof window === \"undefined\" || window.parent === window) return false;\n if (readEmbedMcpChatBridgeFlagFromUrl()) markEmbedMcpChatBridgeActive();\n return isEmbedAuthActive() && !isEmbedMcpChatBridgeActive();\n}\n\nfunction dispatchAgentChatRunning(isRunning: boolean): void {\n if (typeof window === \"undefined\") return;\n window.dispatchEvent(\n new CustomEvent(\"agentNative.chatRunning\", {\n detail: { isRunning },\n }),\n );\n}\n\nfunction normalizeAgentChatRequestMode(\n value: unknown,\n): AgentChatRequestMode | undefined {\n return value === \"act\" || value === \"plan\" ? value : undefined;\n}\n\n/** A normalized `agentNative.submitChat` payload — decode via {@link parseSubmitChatMessage}. */\nexport interface ParsedSubmitChat {\n /** Visible prompt text (non-empty). */\n message: string;\n context?: string;\n /** Submit (true) or prefill only (false); defaults to true. */\n submit: boolean;\n openSidebar?: boolean;\n model?: string;\n /** Raw effort hint; the receiver validates it against the model. */\n effort?: unknown;\n newTab?: boolean;\n background?: boolean;\n tabId?: string;\n images?: string[];\n /** Mode as sent; the receiver falls back to its exec mode when undefined. */\n requestMode?: AgentChatRequestMode;\n /** Id used to dedup the live post against a cold-start replay. */\n submitMessageId?: string;\n}\n\n/** Decode a `message` event into a submit payload, or null if it isn't one / has no text. */\nexport function parseSubmitChatMessage(\n event: MessageEvent,\n): ParsedSubmitChat | null {\n const envelope =\n event.data && typeof event.data === \"object\"\n ? (event.data as { type?: unknown; data?: unknown })\n : null;\n if (!envelope || envelope.type !== AGENT_CHAT_MESSAGE_TYPE) return null;\n const raw =\n envelope.data && typeof envelope.data === \"object\"\n ? (envelope.data as Record<string, unknown>)\n : null;\n if (!raw) return null;\n const message = typeof raw.message === \"string\" ? raw.message : \"\";\n if (!message) return null;\n const images = Array.isArray(raw.images)\n ? raw.images.filter(\n (image): image is string =>\n typeof image === \"string\" && image.length > 0,\n )\n : undefined;\n return {\n message,\n context: typeof raw.context === \"string\" ? raw.context : undefined,\n submit: raw.submit !== false,\n openSidebar:\n typeof raw.openSidebar === \"boolean\" ? raw.openSidebar : undefined,\n model: typeof raw.model === \"string\" ? raw.model : undefined,\n effort: raw.effort,\n newTab: typeof raw.newTab === \"boolean\" ? raw.newTab : undefined,\n background:\n typeof raw.background === \"boolean\" ? raw.background : undefined,\n tabId: typeof raw.tabId === \"string\" ? raw.tabId : undefined,\n images,\n requestMode: normalizeAgentChatRequestMode(raw.requestMode ?? raw.mode),\n submitMessageId:\n typeof raw.submitMessageId === \"string\" ? raw.submitMessageId : undefined,\n };\n}\n\nfunction normalizeStoredAgentChatExecMode(\n value: string | null,\n): AgentChatRequestMode | undefined {\n if (value === \"plan\") return \"plan\";\n if (value === \"build\" || value === \"act\") return \"act\";\n return undefined;\n}\n\nfunction readStoredAgentChatRequestMode(): AgentChatRequestMode | undefined {\n if (typeof window === \"undefined\") return undefined;\n try {\n const storage = window.localStorage;\n const saved = normalizeStoredAgentChatExecMode(\n storage.getItem(AGENT_CHAT_EXEC_MODE_KEY),\n );\n if (saved) return saved;\n const scopedModes: AgentChatRequestMode[] = [];\n for (let index = 0; index < storage.length; index += 1) {\n const key = storage.key(index);\n if (!key?.startsWith(`${AGENT_CHAT_EXEC_MODE_KEY}:`)) continue;\n const scopedSaved = normalizeStoredAgentChatExecMode(\n storage.getItem(key),\n );\n if (scopedSaved) scopedModes.push(scopedSaved);\n }\n if (scopedModes.length === 1) return scopedModes[0];\n } catch {}\n return undefined;\n}\n\n/**\n * Send a message to the agent chat via postMessage.\n * Returns the stable tabId for tracking this chat run.\n */\nexport function sendToAgentChat(opts: AgentChatMessage): string {\n const tabId = opts.tabId ?? generateTabId();\n const isCodeRequest = opts.type === \"code\" || opts.requiresCode === true;\n const requestMode =\n normalizeAgentChatRequestMode(opts.requestMode ?? opts.mode) ??\n readStoredAgentChatRequestMode();\n if (isCodeRequest && isInBuilderFrame()) {\n sendToBuilderChat({\n message: opts.message,\n context: opts.context,\n submit: opts.submit,\n ...(requestMode ? { mode: requestMode, requestMode } : {}),\n });\n return tabId;\n }\n\n const submitMessageId = generateSubmitMessageId();\n const payload = {\n type: AGENT_CHAT_MESSAGE_TYPE,\n data: {\n ...opts,\n tabId,\n submitMessageId,\n ...(requestMode ? { mode: requestMode, requestMode } : {}),\n },\n };\n\n if (opts.submit !== false && isMcpAppChatBridgeEnabled()) {\n const directHostMessage = sendMcpAppHostMessage({\n message: opts.message,\n context: opts.context,\n ...(requestMode ? { mode: requestMode, requestMode } : {}),\n });\n if (directHostMessage) {\n void Promise.resolve(directHostMessage)\n .then((ok) => {\n if (!ok) {\n window.parent.postMessage(\n payload,\n getFramePostMessageTargetOrigin() || \"*\",\n );\n }\n })\n .finally(() => {\n dispatchAgentChatRunning(false);\n });\n return tabId;\n }\n window.parent.postMessage(\n payload,\n getFramePostMessageTargetOrigin() || \"*\",\n );\n return tabId;\n }\n\n const shouldOpenSidebar = opts.openSidebar !== false && !opts.background;\n\n const targetSelf =\n !isCodeRequest && (isInBuilderFrame() || isDirectMcpAppEmbedSession());\n const target = targetSelf\n ? window\n : window.parent !== window\n ? window.parent\n : window;\n const targetOrigin = targetSelf\n ? window.location.origin\n : getFramePostMessageTargetOrigin() || window.location.origin;\n if (shouldOpenSidebar) {\n window.dispatchEvent(\n new CustomEvent(\"agent-panel:set-mode\", {\n detail: { mode: \"chat\" },\n }),\n );\n window.dispatchEvent(new CustomEvent(\"agent-panel:open\"));\n } else if (!isCodeRequest) {\n window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));\n }\n\n const postToTarget = () => target.postMessage(payload, targetOrigin);\n\n // Same-window: defer one tick so a sidebar mounting now can attach its\n // listener, and buffer the submit so the lazy panel can replay it if it\n // mounts later. The live post and the replay dedup by submitMessageId.\n if (!isCodeRequest && target === window) {\n bufferSelfSubmit(payload.data);\n setTimeout(postToTarget, 0);\n } else {\n postToTarget();\n }\n return tabId;\n}\n\n/**\n * Add or replace a keyed context nugget in the active agent chat composer.\n * The context is not submitted until the user sends the prompt.\n */\nexport function setAgentChatContextItem(\n opts: AgentChatContextSetOptions,\n): void {\n const item = normalizeAgentChatContextItem(opts);\n if (!item || typeof window === \"undefined\") return;\n\n publishAgentChatContextItems(\n withReplacedAgentChatContextItem(agentChatContextState.items, item),\n );\n postAgentChatContextMessage(AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE, item, {\n openSidebar: opts.openSidebar !== false,\n });\n}\n\n/** @deprecated Use `setAgentChatContextItem` instead. */\nexport const setContextToAgentChat = setAgentChatContextItem;\n\n/** @deprecated Use `setAgentChatContextItem` instead. */\nexport const addContextToAgentChat = setAgentChatContextItem;\n\nexport function insertAgentComposerReference(\n ref: AgentComposerReference,\n options: AgentComposerReferenceInsertOptions = {},\n): void {\n const normalized = normalizeAgentComposerReference(ref);\n if (!normalized || typeof window === \"undefined\") return;\n postAgentChatReferenceMessage(\n {\n ...normalized,\n insertMessageId: `reference-${Date.now()}-${Math.random()\n .toString(36)\n .slice(2, 8)}`,\n },\n { openSidebar: options.openSidebar === true },\n );\n}\n\nexport function removeAgentChatContextItem(\n keyOrOpts: string | AgentChatContextRemoveOptions,\n): void {\n const key =\n typeof keyOrOpts === \"string\" ? keyOrOpts.trim() : keyOrOpts.key.trim();\n if (!key || typeof window === \"undefined\") return;\n const openSidebar =\n typeof keyOrOpts === \"string\" ? false : keyOrOpts.openSidebar === true;\n\n publishAgentChatContextItems(\n agentChatContextState.items.filter((item) => item.key !== key),\n );\n postAgentChatContextMessage(\n AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE,\n { key },\n { openSidebar },\n );\n}\n\nexport function clearAgentChatContext(\n opts: AgentChatContextMutationOptions = {},\n): void {\n if (typeof window === \"undefined\") return;\n publishAgentChatContextItems([]);\n postAgentChatContextMessage(\n AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE,\n {},\n { openSidebar: opts.openSidebar === true },\n );\n}\n\nexport function _resetAgentChatContextForTests(): void {\n agentChatContextState = { items: [], updatedAt: 0 };\n notifyAgentChatContextListeners();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agent-ch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,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,CAC/D,CAAC;IACF,2BAA2B,CACzB,sCAAsC,EACtC,EAAE,GAAG,EAAE,EACP,EAAE,WAAW,EAAE,CAChB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,IAAI,GAAoC,EAAE;IAE1C,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO;IAC1C,4BAA4B,CAAC,EAAE,CAAC,CAAC;IACjC,2BAA2B,CACzB,qCAAqC,EACrC,EAAE,EACF,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,KAAK,IAAI,EAAE,CAC3C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,8BAA8B;IAC5C,qBAAqB,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IACpD,+BAA+B,EAAE,CAAC;AACpC,CAAC","sourcesContent":["/**\n * Agent Chat Bridge (browser)\n *\n * Sends structured messages to the agent chat from UI interactions.\n * Messages are sent via postMessage to the parent window (or self if top-level).\n * Builder frames are special: code requests go to Builder, but content prompts\n * stay inside the embedded app so its own AgentSidebar can receive them.\n */\n\nimport type { ReasoningEffort } from \"../shared/reasoning-effort.js\";\nimport { agentNativePath } from \"./api-path.js\";\nimport {\n isInBuilderFrame,\n isTrustedBuilderMessage,\n sendToBuilderChat,\n} from \"./builder-frame.js\";\nimport {\n isEmbedAuthActive,\n isEmbedMcpChatBridgeActive,\n markEmbedMcpChatBridgeActive,\n readEmbedMcpChatBridgeFlagFromUrl,\n} from \"./embed-auth.js\";\nimport {\n getFramePostMessageTargetOrigin,\n isTrustedFrameMessage,\n} from \"./frame.js\";\nimport { sendMcpAppHostMessage } from \"./mcp-app-host.js\";\n\nexport type AgentChatRequestMode = \"act\" | \"plan\";\n\nexport interface AgentChatMessage {\n /** The visible prompt message sent to the chat */\n message: string;\n /** Hidden context appended to the message (not shown in chat UI) */\n context?: string;\n /** true = auto-submit, false = prefill only, omit = use project setting */\n submit?: boolean;\n /** Optional project slug for structured context */\n projectSlug?: string;\n /** Optional preset name for downstream consumers */\n preset?: string;\n /** Optional reference image paths */\n referenceImagePaths?: string[];\n /** Optional uploaded reference images */\n uploadedReferenceImages?: string[];\n /** Optional image data URLs to include in the submitted chat message */\n images?: string[];\n /** Stable tab identifier — auto-generated if omitted */\n tabId?: string;\n /**\n * Message routing type:\n * - \"content\" (default): stays in the embedded app agent for content/data operations\n * - \"code\": routes to the code editing frame (Agent Native Desktop or Builder.io)\n *\n * When type is \"code\" and no frame is connected, a dialog is shown.\n * `requiresCode: true` is treated as `type: \"code\"` for backward compatibility.\n */\n type?: \"content\" | \"code\";\n /** @deprecated Use `type: \"code\"` instead. If true, treated as `type: \"code\"`. */\n requiresCode?: boolean;\n /** Model preference for this sub-agent (e.g. \"claude-haiku-4-5\"). Uses default if omitted */\n model?: string;\n /** Engine preference paired with model for cross-provider switches. */\n engine?: string;\n /** Reasoning effort preference paired with model. */\n effort?: ReasoningEffort;\n /**\n * Execution mode for this submitted turn. When omitted, sendToAgentChat\n * snapshots the current AgentPanel mode from localStorage when available.\n */\n mode?: AgentChatRequestMode;\n /** @deprecated Use `mode` instead. */\n requestMode?: AgentChatRequestMode;\n /** Scoped system prompt additions for this sub-agent */\n instructions?: string;\n /**\n * Message delivery target. Auto-submitted MCP App messages normally relay to\n * the host chat; use \"local\" when a control explicitly targets this app's\n * own AgentSidebar.\n */\n chatTarget?: \"auto\" | \"local\";\n /**\n * Whether to open the agent sidebar if it's currently hidden.\n * Defaults to true — submitting a chat should make the response visible.\n * Pass `false` for background/silent sends that shouldn't pop the UI open.\n */\n openSidebar?: boolean;\n /**\n * When true, opens a new chat tab before sending the message.\n * Use for creation requests (create tool, dashboard, etc.) that deserve\n * their own isolated thread rather than cluttering an existing conversation.\n */\n newTab?: boolean;\n /**\n * When true with newTab, creates the tab in the background without\n * focusing it or opening the sidebar. The message runs silently.\n */\n background?: boolean;\n}\n\nexport interface AgentChatContextItem {\n /** Stable key used to replace an existing context nugget. */\n key: string;\n /** Short label shown in the composer context chip. */\n title: string;\n /** Hidden context included with the next submitted prompt. */\n context: string;\n}\n\nexport interface AgentChatContextSetOptions extends AgentChatContextItem {\n /**\n * Whether to open the agent sidebar if it's currently hidden.\n * Defaults to true so the user can see the staged context.\n */\n openSidebar?: boolean;\n}\n\n/** @deprecated Use `AgentChatContextSetOptions` instead. */\nexport type AgentChatContextMessage = AgentChatContextSetOptions;\n\nexport interface AgentChatContextState {\n items: AgentChatContextItem[];\n updatedAt: number;\n}\n\nexport interface AgentComposerReference {\n label: string;\n icon?: string;\n source?: string;\n refType: string;\n refId?: string | null;\n refPath?: string | null;\n /** Stable composer slot this reference occupies. Slot references replace older values. */\n slotKey?: string;\n /** Short label shown before the selected value in the composer chip. */\n slotLabel?: string;\n /** Additional app-defined data used by the client for filtering and grouping. */\n metadata?: Record<string, unknown>;\n /** Slots to remove when this reference is inserted or removed. */\n clearsSlots?: string[];\n /** Additional references to insert before this one. */\n relatedReferences?: AgentComposerReference[];\n}\n\nexport interface AgentComposerReferenceInsertOptions {\n /**\n * Whether to open the agent sidebar before inserting the reference.\n * Defaults to false so contextual auto-tags can stay quiet.\n */\n openSidebar?: boolean;\n}\n\nexport interface AgentComposerReferenceInsertPayload extends AgentComposerReference {\n insertMessageId: string;\n}\n\nexport interface AgentChatContextMutationOptions {\n /**\n * Whether to open the agent sidebar if it's currently hidden.\n * Defaults to true for set/add and false for remove/clear.\n */\n openSidebar?: boolean;\n}\n\nexport interface AgentChatContextRemoveOptions extends AgentChatContextMutationOptions {\n /** Stable key of the staged context nugget to remove. */\n key: string;\n}\n\nconst AGENT_CHAT_MESSAGE_TYPE = \"agentNative.submitChat\";\nconst AGENT_CHAT_CONTEXT_STATE_KEY = \"agent-chat-context\";\nconst AGENT_CHAT_EXEC_MODE_KEY = \"agent-native-exec-mode\";\nexport const AGENT_CHAT_CONTEXT_CHANGED_EVENT =\n \"agentNative.chatContextChanged\";\nexport const AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE = \"agentNative.setChatContext\";\nexport const AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE =\n \"agentNative.removeChatContext\";\nexport const AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE =\n \"agentNative.clearChatContext\";\nexport const AGENT_CHAT_INSERT_REFERENCE_MESSAGE_TYPE =\n \"agentNative.insertComposerReference\";\nexport const AGENT_CHAT_INSERT_REFERENCE_EVENT =\n \"agentNative:insert-composer-reference\";\nconst AGENT_PANEL_PREPARE_EVENT = \"agent-panel:prepare\";\n\nlet agentChatContextState: AgentChatContextState = {\n items: [],\n updatedAt: 0,\n};\nconst agentChatContextListeners = new Set<() => void>();\n\n/**\n * Listen for chatRunning messages from the frame (postMessage)\n * and re-dispatch as a CustomEvent so hooks like useAgentChatGenerating() work.\n */\nif (typeof window !== \"undefined\") {\n window.addEventListener(\"message\", (event) => {\n if (!isTrustedFrameMessage(event) && !isTrustedBuilderMessage(event)) {\n return;\n }\n if (\n event.data?.type === \"agentNative.chatRunning\" ||\n event.data?.type === \"builder.chatRunning\"\n ) {\n window.dispatchEvent(\n new CustomEvent(\"agentNative.chatRunning\", {\n detail: event.data.detail ?? event.data.data,\n }),\n );\n }\n });\n}\n\n/** Generate a unique tab ID */\nexport function generateTabId(): string {\n return `chat-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n}\n\n/** Unique id for one submitted message, used to dedup live + replayed sends. */\nfunction generateSubmitMessageId(): string {\n return `submit-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n}\n\n// Self-submit buffer: same-window sends post to `window` itself, but the\n// receiver is lazy-loaded and may not be listening yet. Buffer each submit so\n// the panel can replay it on mount; claimAgentChatSubmit dedups by id so a\n// submit received both live and replayed is delivered exactly once.\ninterface BufferedSelfSubmit {\n id: string;\n data: Record<string, unknown>;\n at: number;\n}\n\nconst SELF_SUBMIT_BUFFER_TTL_MS = 8000;\nconst bufferedSelfSubmits: BufferedSelfSubmit[] = [];\nconst claimedSubmitIds = new Set<string>();\n\nfunction pruneSelfSubmitBuffer(now: number): void {\n for (let i = bufferedSelfSubmits.length - 1; i >= 0; i -= 1) {\n if (now - bufferedSelfSubmits[i].at > SELF_SUBMIT_BUFFER_TTL_MS) {\n const [removed] = bufferedSelfSubmits.splice(i, 1);\n if (removed) claimedSubmitIds.delete(removed.id);\n }\n }\n}\n\nfunction bufferSelfSubmit(data: Record<string, unknown>): void {\n const id =\n typeof data.submitMessageId === \"string\" ? data.submitMessageId : undefined;\n if (!id) return;\n const now = Date.now();\n pruneSelfSubmitBuffer(now);\n bufferedSelfSubmits.push({ id, data, at: now });\n}\n\n/** Unclaimed self-submit payloads, for the panel to replay once it mounts. */\nexport function drainBufferedAgentChatSubmits(): Array<\n Record<string, unknown>\n> {\n pruneSelfSubmitBuffer(Date.now());\n return bufferedSelfSubmits\n .filter((entry) => !claimedSubmitIds.has(entry.id))\n .map((entry) => entry.data);\n}\n\n/** Claim a submit; false if already handled. Idless submits always pass. */\nexport function claimAgentChatSubmit(id: string | undefined): boolean {\n if (!id) return true;\n if (claimedSubmitIds.has(id)) return false;\n claimedSubmitIds.add(id);\n return true;\n}\n\n/** Test-only: reset the self-submit buffer and claim set. */\nexport function _resetAgentChatSubmitBufferForTests(): void {\n bufferedSelfSubmits.length = 0;\n claimedSubmitIds.clear();\n}\n\nexport function normalizeAgentChatContextItem(\n item: unknown,\n): AgentChatContextItem | null {\n if (typeof item !== \"object\" || item === null) return null;\n const candidate = item as Partial<AgentChatContextItem>;\n if (\n typeof candidate.key !== \"string\" ||\n typeof candidate.context !== \"string\" ||\n typeof candidate.title !== \"string\"\n ) {\n return null;\n }\n const key = candidate.key.trim();\n const context = candidate.context.trim();\n if (!key || !context) return null;\n return {\n key,\n title: candidate.title.trim() || key,\n context,\n };\n}\n\nexport function normalizeAgentChatContextItems(\n items: unknown,\n): AgentChatContextItem[] {\n if (!Array.isArray(items)) return [];\n const deduped = new Map<string, AgentChatContextItem>();\n for (const rawItem of items) {\n const item = normalizeAgentChatContextItem(rawItem);\n if (!item) continue;\n deduped.set(item.key, item);\n }\n return [...deduped.values()];\n}\n\nfunction normalizeAgentChatContextState(\n value: unknown,\n): AgentChatContextState | null {\n if (!value || typeof value !== \"object\") return null;\n const raw = value as {\n value?: unknown;\n items?: unknown;\n updatedAt?: unknown;\n };\n const candidate =\n raw.value && typeof raw.value === \"object\"\n ? (raw.value as { items?: unknown; updatedAt?: unknown })\n : raw;\n const items = normalizeAgentChatContextItems(candidate.items);\n return {\n items,\n updatedAt:\n typeof candidate.updatedAt === \"number\" ? candidate.updatedAt : 0,\n };\n}\n\nfunction withReplacedAgentChatContextItem(\n items: readonly AgentChatContextItem[],\n item: AgentChatContextItem,\n): AgentChatContextItem[] {\n const index = items.findIndex((current) => current.key === item.key);\n if (index === -1) return [...items, item];\n return items.map((current, currentIndex) =>\n currentIndex === index ? item : current,\n );\n}\n\nfunction notifyAgentChatContextListeners(): void {\n for (const listener of agentChatContextListeners) listener();\n}\n\nfunction persistAgentChatContextState(state: AgentChatContextState): void {\n if (typeof window === \"undefined\" || typeof fetch !== \"function\") return;\n fetch(\n agentNativePath(\n `/_agent-native/application-state/${AGENT_CHAT_CONTEXT_STATE_KEY}`,\n ),\n {\n method: \"PUT\",\n keepalive: true,\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(state),\n },\n ).catch(() => {});\n}\n\nexport function publishAgentChatContextItems(\n items: readonly AgentChatContextItem[],\n options?: { persist?: boolean; updatedAt?: number },\n): AgentChatContextState {\n const next: AgentChatContextState = {\n items: normalizeAgentChatContextItems([...items]),\n updatedAt: options?.updatedAt ?? Date.now(),\n };\n if (next.updatedAt < agentChatContextState.updatedAt) {\n return agentChatContextState;\n }\n agentChatContextState = next;\n notifyAgentChatContextListeners();\n if (typeof window !== \"undefined\") {\n window.dispatchEvent(\n new CustomEvent(AGENT_CHAT_CONTEXT_CHANGED_EVENT, {\n detail: next,\n }),\n );\n }\n if (options?.persist !== false) {\n persistAgentChatContextState(next);\n }\n return next;\n}\n\nexport function getAgentChatContextState(): AgentChatContextState {\n return agentChatContextState;\n}\n\nexport function listAgentChatContext(): AgentChatContextItem[] {\n return [...agentChatContextState.items];\n}\n\nexport function subscribeAgentChatContext(listener: () => void): () => void {\n agentChatContextListeners.add(listener);\n return () => {\n agentChatContextListeners.delete(listener);\n };\n}\n\nexport async function refreshAgentChatContext(): Promise<AgentChatContextState> {\n if (typeof window === \"undefined\" || typeof fetch !== \"function\") {\n return agentChatContextState;\n }\n try {\n const res = await fetch(\n agentNativePath(\n `/_agent-native/application-state/${AGENT_CHAT_CONTEXT_STATE_KEY}`,\n ),\n );\n if (!res.ok || res.status === 204) return agentChatContextState;\n const text = await res.text();\n if (!text) return agentChatContextState;\n const state = normalizeAgentChatContextState(JSON.parse(text));\n if (!state) return agentChatContextState;\n return publishAgentChatContextItems(state.items, {\n persist: false,\n updatedAt: state.updatedAt,\n });\n } catch {\n return agentChatContextState;\n }\n}\n\nexport function formatAgentChatContextItemsForPrompt(\n items: readonly AgentChatContextItem[],\n): string {\n return items\n .map(normalizeAgentChatContextItem)\n .filter((item): item is AgentChatContextItem => item !== null)\n .map((item) => [`## ${item.title}`, item.context].join(\"\\n\"))\n .join(\"\\n\\n\");\n}\n\nexport function appendAgentChatContextToMessage(\n message: string,\n context: string,\n): string {\n const trimmedContext = context.trim();\n if (!trimmedContext) return message;\n return `${message.trim()}\\n\\n<context>\\n${trimmedContext}\\n</context>`;\n}\n\nfunction normalizeStringArray(value: unknown): string[] | undefined {\n if (!Array.isArray(value)) return undefined;\n const normalized = value\n .filter((item): item is string => typeof item === \"string\")\n .map((item) => item.trim())\n .filter(Boolean);\n return normalized.length > 0 ? normalized : undefined;\n}\n\nfunction normalizeMetadata(\n value: unknown,\n): Record<string, unknown> | undefined {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return undefined;\n }\n return value as Record<string, unknown>;\n}\n\nfunction normalizeAgentComposerReferenceInternal(\n value: unknown,\n depth: number,\n): AgentComposerReference | null {\n if (typeof value !== \"object\" || value === null) return null;\n const candidate = value as Partial<AgentComposerReference>;\n const label =\n typeof candidate.label === \"string\" ? candidate.label.trim() : \"\";\n const refType =\n typeof candidate.refType === \"string\" ? candidate.refType.trim() : \"\";\n if (!label || !refType) return null;\n const normalized: AgentComposerReference = {\n label,\n icon:\n typeof candidate.icon === \"string\" && candidate.icon.trim()\n ? candidate.icon.trim()\n : undefined,\n source:\n typeof candidate.source === \"string\" && candidate.source.trim()\n ? candidate.source.trim()\n : undefined,\n refType,\n refId:\n typeof candidate.refId === \"string\" && candidate.refId.trim()\n ? candidate.refId.trim()\n : null,\n refPath:\n typeof candidate.refPath === \"string\" && candidate.refPath.trim()\n ? candidate.refPath.trim()\n : null,\n };\n const slotKey =\n typeof candidate.slotKey === \"string\" ? candidate.slotKey.trim() : \"\";\n if (slotKey) normalized.slotKey = slotKey;\n const slotLabel =\n typeof candidate.slotLabel === \"string\" ? candidate.slotLabel.trim() : \"\";\n if (slotLabel) normalized.slotLabel = slotLabel;\n const metadata = normalizeMetadata(candidate.metadata);\n if (metadata) normalized.metadata = metadata;\n const clearsSlots = normalizeStringArray(candidate.clearsSlots);\n if (clearsSlots) normalized.clearsSlots = clearsSlots;\n if (depth < 3 && Array.isArray(candidate.relatedReferences)) {\n const relatedReferences = candidate.relatedReferences\n .map((item) => normalizeAgentComposerReferenceInternal(item, depth + 1))\n .filter((item): item is AgentComposerReference => item !== null);\n if (relatedReferences.length > 0) {\n normalized.relatedReferences = relatedReferences;\n }\n }\n return normalized;\n}\n\nexport function normalizeAgentComposerReference(\n value: unknown,\n): AgentComposerReference | null {\n return normalizeAgentComposerReferenceInternal(value, 0);\n}\n\nfunction postAgentChatContextMessage(\n type:\n | typeof AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE\n | typeof AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE\n | typeof AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE,\n data: unknown,\n options: { openSidebar: boolean },\n): void {\n if (typeof window === \"undefined\") return;\n\n const shouldForwardOpenSidebar =\n (type === AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE &&\n options.openSidebar === false) ||\n (type !== AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE &&\n options.openSidebar === true);\n const payloadData =\n shouldForwardOpenSidebar && typeof data === \"object\" && data !== null\n ? {\n ...(data as Record<string, unknown>),\n openSidebar: options.openSidebar,\n }\n : data;\n const payload = { type, data: payloadData };\n const targetSelf = isInBuilderFrame() || isDirectMcpAppEmbedSession();\n const target = targetSelf\n ? window\n : window.parent !== window\n ? window.parent\n : window;\n const targetOrigin = targetSelf\n ? window.location.origin\n : getFramePostMessageTargetOrigin() || window.location.origin;\n\n if (options.openSidebar) {\n window.dispatchEvent(\n new CustomEvent(\"agent-panel:set-mode\", {\n detail: { mode: \"chat\" },\n }),\n );\n window.dispatchEvent(new CustomEvent(\"agent-panel:open\"));\n } else {\n window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));\n }\n\n const postToTarget = () => target.postMessage(payload, targetOrigin);\n if (target === window) {\n setTimeout(postToTarget, 0);\n } else {\n postToTarget();\n }\n}\n\nfunction postAgentChatReferenceMessage(\n payload: AgentComposerReferenceInsertPayload,\n options: { openSidebar: boolean },\n): void {\n if (typeof window === \"undefined\") return;\n\n const message = {\n type: AGENT_CHAT_INSERT_REFERENCE_MESSAGE_TYPE,\n data: payload,\n };\n const targetSelf = isInBuilderFrame() || isDirectMcpAppEmbedSession();\n const target = targetSelf\n ? window\n : window.parent !== window\n ? window.parent\n : window;\n const targetOrigin = targetSelf\n ? window.location.origin\n : getFramePostMessageTargetOrigin() || window.location.origin;\n\n if (options.openSidebar) {\n window.dispatchEvent(\n new CustomEvent(\"agent-panel:set-mode\", {\n detail: { mode: \"chat\" },\n }),\n );\n window.dispatchEvent(new CustomEvent(\"agent-panel:open\"));\n } else {\n window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));\n }\n\n window.dispatchEvent(\n new CustomEvent(AGENT_CHAT_INSERT_REFERENCE_EVENT, {\n detail: payload,\n }),\n );\n\n const postToTarget = () => target.postMessage(message, targetOrigin);\n if (target === window) {\n setTimeout(postToTarget, 0);\n } else {\n postToTarget();\n }\n}\n\nfunction isMcpAppChatBridgeEnabled(): boolean {\n if (typeof window === \"undefined\" || window.parent === window) return false;\n if (readEmbedMcpChatBridgeFlagFromUrl()) markEmbedMcpChatBridgeActive();\n return isEmbedMcpChatBridgeActive() && isEmbedAuthActive();\n}\n\nfunction isDirectMcpAppEmbedSession(): boolean {\n if (typeof window === \"undefined\" || window.parent === window) return false;\n if (readEmbedMcpChatBridgeFlagFromUrl()) markEmbedMcpChatBridgeActive();\n return isEmbedAuthActive() && !isEmbedMcpChatBridgeActive();\n}\n\nfunction dispatchAgentChatRunning(isRunning: boolean): void {\n if (typeof window === \"undefined\") return;\n window.dispatchEvent(\n new CustomEvent(\"agentNative.chatRunning\", {\n detail: { isRunning },\n }),\n );\n}\n\nfunction normalizeAgentChatRequestMode(\n value: unknown,\n): AgentChatRequestMode | undefined {\n return value === \"act\" || value === \"plan\" ? value : undefined;\n}\n\n/** A normalized `agentNative.submitChat` payload — decode via {@link parseSubmitChatMessage}. */\nexport interface ParsedSubmitChat {\n /** Visible prompt text (non-empty). */\n message: string;\n context?: string;\n /** Submit (true) or prefill only (false); defaults to true. */\n submit: boolean;\n openSidebar?: boolean;\n model?: string;\n /** Raw effort hint; the receiver validates it against the model. */\n effort?: unknown;\n newTab?: boolean;\n background?: boolean;\n tabId?: string;\n images?: string[];\n /** Mode as sent; the receiver falls back to its exec mode when undefined. */\n requestMode?: AgentChatRequestMode;\n /** Id used to dedup the live post against a cold-start replay. */\n submitMessageId?: string;\n}\n\n/** Decode a `message` event into a submit payload, or null if it isn't one / has no text. */\nexport function parseSubmitChatMessage(\n event: MessageEvent,\n): ParsedSubmitChat | null {\n const envelope =\n event.data && typeof event.data === \"object\"\n ? (event.data as { type?: unknown; data?: unknown })\n : null;\n if (!envelope || envelope.type !== AGENT_CHAT_MESSAGE_TYPE) return null;\n const raw =\n envelope.data && typeof envelope.data === \"object\"\n ? (envelope.data as Record<string, unknown>)\n : null;\n if (!raw) return null;\n const message = typeof raw.message === \"string\" ? raw.message : \"\";\n if (!message) return null;\n const images = Array.isArray(raw.images)\n ? raw.images.filter(\n (image): image is string =>\n typeof image === \"string\" && image.length > 0,\n )\n : undefined;\n return {\n message,\n context: typeof raw.context === \"string\" ? raw.context : undefined,\n submit: raw.submit !== false,\n openSidebar:\n typeof raw.openSidebar === \"boolean\" ? raw.openSidebar : undefined,\n model: typeof raw.model === \"string\" ? raw.model : undefined,\n effort: raw.effort,\n newTab: typeof raw.newTab === \"boolean\" ? raw.newTab : undefined,\n background:\n typeof raw.background === \"boolean\" ? raw.background : undefined,\n tabId: typeof raw.tabId === \"string\" ? raw.tabId : undefined,\n images,\n requestMode: normalizeAgentChatRequestMode(raw.requestMode ?? raw.mode),\n submitMessageId:\n typeof raw.submitMessageId === \"string\" ? raw.submitMessageId : undefined,\n };\n}\n\nfunction normalizeStoredAgentChatExecMode(\n value: string | null,\n): AgentChatRequestMode | undefined {\n if (value === \"plan\") return \"plan\";\n if (value === \"build\" || value === \"act\") return \"act\";\n return undefined;\n}\n\nfunction readStoredAgentChatRequestMode(): AgentChatRequestMode | undefined {\n if (typeof window === \"undefined\") return undefined;\n try {\n const storage = window.localStorage;\n const saved = normalizeStoredAgentChatExecMode(\n storage.getItem(AGENT_CHAT_EXEC_MODE_KEY),\n );\n if (saved) return saved;\n const scopedModes: AgentChatRequestMode[] = [];\n for (let index = 0; index < storage.length; index += 1) {\n const key = storage.key(index);\n if (!key?.startsWith(`${AGENT_CHAT_EXEC_MODE_KEY}:`)) continue;\n const scopedSaved = normalizeStoredAgentChatExecMode(\n storage.getItem(key),\n );\n if (scopedSaved) scopedModes.push(scopedSaved);\n }\n if (scopedModes.length === 1) return scopedModes[0];\n } catch {}\n return undefined;\n}\n\n/**\n * Send a message to the agent chat via postMessage.\n * Returns the stable tabId for tracking this chat run.\n */\nexport function sendToAgentChat(opts: AgentChatMessage): string {\n const tabId = opts.tabId ?? generateTabId();\n const isCodeRequest = opts.type === \"code\" || opts.requiresCode === true;\n const localChatTarget = opts.chatTarget === \"local\";\n const requestMode =\n normalizeAgentChatRequestMode(opts.requestMode ?? opts.mode) ??\n readStoredAgentChatRequestMode();\n if (isCodeRequest && isInBuilderFrame()) {\n sendToBuilderChat({\n message: opts.message,\n context: opts.context,\n submit: opts.submit,\n ...(requestMode ? { mode: requestMode, requestMode } : {}),\n });\n return tabId;\n }\n\n const submitMessageId = generateSubmitMessageId();\n const payload = {\n type: AGENT_CHAT_MESSAGE_TYPE,\n data: {\n ...opts,\n tabId,\n submitMessageId,\n ...(requestMode ? { mode: requestMode, requestMode } : {}),\n },\n };\n\n if (\n opts.submit !== false &&\n !localChatTarget &&\n isMcpAppChatBridgeEnabled()\n ) {\n const directHostMessage = sendMcpAppHostMessage({\n message: opts.message,\n context: opts.context,\n ...(requestMode ? { mode: requestMode, requestMode } : {}),\n });\n if (directHostMessage) {\n void Promise.resolve(directHostMessage)\n .then((ok) => {\n if (!ok) {\n window.parent.postMessage(\n payload,\n getFramePostMessageTargetOrigin() || \"*\",\n );\n }\n })\n .finally(() => {\n dispatchAgentChatRunning(false);\n });\n return tabId;\n }\n window.parent.postMessage(\n payload,\n getFramePostMessageTargetOrigin() || \"*\",\n );\n return tabId;\n }\n\n const shouldOpenSidebar = opts.openSidebar !== false && !opts.background;\n\n const targetSelf =\n !isCodeRequest &&\n (localChatTarget || isInBuilderFrame() || isDirectMcpAppEmbedSession());\n const target = targetSelf\n ? window\n : window.parent !== window\n ? window.parent\n : window;\n const targetOrigin = targetSelf\n ? window.location.origin\n : getFramePostMessageTargetOrigin() || window.location.origin;\n if (shouldOpenSidebar) {\n window.dispatchEvent(\n new CustomEvent(\"agent-panel:set-mode\", {\n detail: { mode: \"chat\" },\n }),\n );\n window.dispatchEvent(new CustomEvent(\"agent-panel:open\"));\n } else if (!isCodeRequest) {\n window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));\n }\n\n const postToTarget = () => target.postMessage(payload, targetOrigin);\n\n // Same-window: defer one tick so a sidebar mounting now can attach its\n // listener, and buffer the submit so the lazy panel can replay it if it\n // mounts later. The live post and the replay dedup by submitMessageId.\n if (!isCodeRequest && target === window) {\n bufferSelfSubmit(payload.data);\n setTimeout(postToTarget, 0);\n } else {\n postToTarget();\n }\n return tabId;\n}\n\n/**\n * Add or replace a keyed context nugget in the active agent chat composer.\n * The context is not submitted until the user sends the prompt.\n */\nexport function setAgentChatContextItem(\n opts: AgentChatContextSetOptions,\n): void {\n const item = normalizeAgentChatContextItem(opts);\n if (!item || typeof window === \"undefined\") return;\n\n publishAgentChatContextItems(\n withReplacedAgentChatContextItem(agentChatContextState.items, item),\n );\n postAgentChatContextMessage(AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE, item, {\n openSidebar: opts.openSidebar !== false,\n });\n}\n\n/** @deprecated Use `setAgentChatContextItem` instead. */\nexport const setContextToAgentChat = setAgentChatContextItem;\n\n/** @deprecated Use `setAgentChatContextItem` instead. */\nexport const addContextToAgentChat = setAgentChatContextItem;\n\nexport function insertAgentComposerReference(\n ref: AgentComposerReference,\n options: AgentComposerReferenceInsertOptions = {},\n): void {\n const normalized = normalizeAgentComposerReference(ref);\n if (!normalized || typeof window === \"undefined\") return;\n postAgentChatReferenceMessage(\n {\n ...normalized,\n insertMessageId: `reference-${Date.now()}-${Math.random()\n .toString(36)\n .slice(2, 8)}`,\n },\n { openSidebar: options.openSidebar === true },\n );\n}\n\nexport function removeAgentChatContextItem(\n keyOrOpts: string | AgentChatContextRemoveOptions,\n): void {\n const key =\n typeof keyOrOpts === \"string\" ? keyOrOpts.trim() : keyOrOpts.key.trim();\n if (!key || typeof window === \"undefined\") return;\n const openSidebar =\n typeof keyOrOpts === \"string\" ? false : keyOrOpts.openSidebar === true;\n\n publishAgentChatContextItems(\n agentChatContextState.items.filter((item) => item.key !== key),\n );\n postAgentChatContextMessage(\n AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE,\n { key },\n { openSidebar },\n );\n}\n\nexport function clearAgentChatContext(\n opts: AgentChatContextMutationOptions = {},\n): void {\n if (typeof window === \"undefined\") return;\n publishAgentChatContextItems([]);\n postAgentChatContextMessage(\n AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE,\n {},\n { openSidebar: opts.openSidebar === true },\n );\n}\n\nexport function _resetAgentChatContextForTests(): void {\n agentChatContextState = { items: [], updatedAt: 0 };\n notifyAgentChatContextListeners();\n}\n"]}
|
|
@@ -154,7 +154,7 @@ function MermaidDiagram({ source, idSeed, }) {
|
|
|
154
154
|
// backdrop close via the reused `DiagramLightbox`). The enlarged view re-shows
|
|
155
155
|
// the same rendered SVG scaled to fit the wider modal.
|
|
156
156
|
const svg = state.svg;
|
|
157
|
-
return (_jsxs("div", { className: "group/mermaid relative", children: [_jsx(MermaidSvg, { svg: svg }), _jsx("button", { type: "button", "data-plan-interactive": true, onClick: () => setExpanded(true), "aria-label": copy.expandDiagram, title: copy.expandDiagram, className: "an-diagram-expand-trigger absolute right-2 top-2 z-10 flex size-7 items-center justify-center rounded-md border border-border/60 bg-background
|
|
157
|
+
return (_jsxs("div", { className: "group/mermaid relative", children: [_jsx(MermaidSvg, { svg: svg }), _jsx("button", { type: "button", "data-plan-interactive": true, onClick: () => setExpanded(true), "aria-label": copy.expandDiagram, title: copy.expandDiagram, className: "an-diagram-expand-trigger absolute right-2 top-2 z-10 flex size-7 items-center justify-center rounded-md border border-border/60 bg-background text-muted-foreground opacity-0 shadow-sm transition-[color,opacity] hover:text-foreground focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring group-hover/mermaid:opacity-100", children: _jsx(IconArrowsMaximize, { className: "size-4" }) }), expanded ? (_jsx(DiagramLightbox, { onClose: () => setExpanded(false), children: _jsx(MermaidSvg, { svg: svg, enlarged: true }) })) : null] }));
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
160
160
|
* Read-only renderer for a `mermaid` block. Wraps the diagram in the standard
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MermaidBlock.js","sourceRoot":"","sources":["../../../../src/client/blocks/library/MermaidBlock.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AA8B/C,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,0BAA0B,CAAC;AAC7E,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAW;IACpC,IAAI,OAAO,SAAS,KAAK,WAAW;QAAE,OAAO,GAAG,CAAC;IACjD,MAAM,GAAG,GAAG,IAAI,SAAS,EAAE,CAAC,eAAe,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IAClE,GAAG;SACA,gBAAgB,CAAC,uBAAuB,CAAC;SACzC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACpC,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC5D,KAAK,MAA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nB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAClB,QAAQ,CAAC;4BACP,GAAG,IAAI;4BACP,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,SAAS;yBACzC,CAAC,EAEJ,WAAW,EAAC,kBAAkB,GAC9B,IACE,IACF,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { IconArrowsMaximize } from \"@tabler/icons-react\";\nimport { useEffect, useId, useMemo, useState } from \"react\";\n\nimport { ltrCodeBlockProps } from \"../code-block-direction.js\";\nimport type { BlockEditProps, BlockReadProps } from \"../types.js\";\nimport { useBlockCopy } from \"./block-copy.js\";\nimport { DevInput, DevLabel } from \"./dev-doc-ui.js\";\nimport { DiagramLightbox } from \"./diagram.js\";\nimport type { MermaidData } from \"./mermaid.config.js\";\n\n/**\n * Read + Edit renderers for a `mermaid` block — a Mermaid diagram definition\n * (flowchart, sequence, etc.) edited as raw text and rendered as an\n * Excalidraw-style SVG so it matches the plan's hand-drawn / sketchy house\n * style.\n * Lives in core so any app can register the dev-doc block; it stays app-agnostic\n * (no shadcn / next-themes import).\n *\n * The Mermaid and Excalidraw runtimes are browser-only,\n * so the Read renderer SSR-guards: it renders a lightweight placeholder until a\n * `useEffect` confirms it is mounted, then dynamically imports\n * `@excalidraw/mermaid-to-excalidraw` + `@excalidraw/excalidraw` and injects\n * the exported SVG. If Excalidraw conversion fails, it falls back to Mermaid's\n * hand-drawn renderer. Parse errors never throw; they show the raw source and\n * the error message.\n *\n * Dark mode: the plan editor toggles a `.dark` class on <html>. The Read renderer\n * reads `document.documentElement.classList.contains(\"dark\")` (re-checking on a\n * `MutationObserver` of the html class) and re-renders the diagram with matching\n * light/dark export settings.\n */\n\ninterface MermaidRenderState {\n svg?: string;\n error?: string;\n}\n\nfunction errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : \"Failed to render diagram\";\n}\n\nfunction sanitizeSvgMarkup(svg: string): string {\n if (typeof DOMParser === \"undefined\") return svg;\n const doc = new DOMParser().parseFromString(svg, \"image/svg+xml\");\n doc\n .querySelectorAll(\"script, foreignObject\")\n .forEach((node) => node.remove());\n for (const element of Array.from(doc.querySelectorAll(\"*\"))) {\n for (const attr of Array.from(element.attributes)) {\n const name = attr.name.toLowerCase();\n const value = attr.value.trim().toLowerCase();\n if (\n name.startsWith(\"on\") ||\n ((name === \"href\" || name.endsWith(\":href\")) &&\n value.startsWith(\"javascript:\"))\n ) {\n element.removeAttribute(attr.name);\n }\n }\n }\n return doc.documentElement.outerHTML;\n}\n\nasync function renderExcalidrawSvg(\n source: string,\n isDark: boolean,\n): Promise<string> {\n const [{ parseMermaidToExcalidraw }, excalidraw] = await Promise.all([\n import(\"@excalidraw/mermaid-to-excalidraw\") as Promise<{\n parseMermaidToExcalidraw: (source: string) => Promise<{\n elements: unknown[];\n files?: Record<string, unknown>;\n }>;\n }>,\n import(\"@excalidraw/excalidraw\") as Promise<{\n convertToExcalidrawElements: (elements: unknown[]) => unknown[];\n exportToSvg: (options: {\n elements: unknown[];\n appState: {\n theme: \"dark\" | \"light\";\n viewBackgroundColor: string;\n exportWithDarkMode: boolean;\n };\n files: Record<string, unknown>;\n }) => Promise<{ outerHTML: string }>;\n }>,\n ]);\n const { elements, files } = await parseMermaidToExcalidraw(source);\n const excalidrawElements = excalidraw.convertToExcalidrawElements(elements);\n const svg = await excalidraw.exportToSvg({\n elements: excalidrawElements,\n appState: {\n theme: isDark ? \"dark\" : \"light\",\n viewBackgroundColor: \"transparent\",\n exportWithDarkMode: isDark,\n },\n files: files ?? {},\n });\n return sanitizeSvgMarkup(svg.outerHTML);\n}\n\nasync function renderMermaidSvg(\n source: string,\n id: string,\n isDark: boolean,\n): Promise<string> {\n const mermaid = (\n (await import(\"mermaid\")) as {\n default: {\n initialize: (config: Record<string, unknown>) => void;\n render: (id: string, source: string) => Promise<{ svg: string }>;\n };\n }\n ).default;\n mermaid.initialize({\n startOnLoad: false,\n securityLevel: \"strict\",\n look: \"handDrawn\",\n theme: isDark ? \"dark\" : \"neutral\",\n });\n const { svg } = await mermaid.render(id, source);\n return sanitizeSvgMarkup(svg);\n}\n\n/** Read the live dark-mode flag from the document root (next-themes-free). */\nfunction useIsDark(): boolean {\n const [isDark, setIsDark] = useState(false);\n useEffect(() => {\n if (typeof document === \"undefined\") return;\n const root = document.documentElement;\n const read = () => setIsDark(root.classList.contains(\"dark\"));\n read();\n const observer = new MutationObserver(read);\n observer.observe(root, { attributes: true, attributeFilter: [\"class\"] });\n return () => observer.disconnect();\n }, []);\n return isDark;\n}\n\n/**\n * Inject a rendered Mermaid/Excalidraw SVG string. Shared by the inline render\n * and the expand lightbox so the enlarged view shows the exact same SVG; the\n * lightbox passes `enlarged` so the SVG stretches to fill the wider modal\n * (`max-w-5xl`) instead of staying at its intrinsic inline size.\n */\nfunction MermaidSvg({ svg, enlarged }: { svg: string; enlarged?: boolean }) {\n return (\n <div\n className={\n enlarged\n ? \"flex justify-center overflow-auto [&_svg]:h-auto [&_svg]:w-full [&_svg]:max-w-full\"\n : \"mt-2 flex justify-center overflow-auto [&_svg]:h-auto [&_svg]:max-w-full\"\n }\n // Excalidraw and Mermaid output are sanitized before injection.\n dangerouslySetInnerHTML={{ __html: svg }}\n />\n );\n}\n\nfunction MermaidDiagram({\n source,\n idSeed,\n}: {\n source: string;\n idSeed: string;\n}) {\n const isDark = useIsDark();\n const copy = useBlockCopy();\n // Only render the diagram after mount: `mermaid` is client-only and SSR has no\n // DOM for it to measure against.\n const [mounted, setMounted] = useState(false);\n const [state, setState] = useState<MermaidRenderState>({});\n const [expanded, setExpanded] = useState(false);\n\n // A DOM-id-safe, stable-per-block render id. Mermaid requires a valid CSS id.\n const renderId = useMemo(\n () => `mermaid-${idSeed.replace(/[^a-zA-Z0-9_-]/g, \"-\")}`,\n [idSeed],\n );\n\n useEffect(() => {\n setMounted(true);\n }, []);\n\n useEffect(() => {\n if (!mounted) return;\n let cancelled = false;\n const trimmed = source.trim();\n if (!trimmed) {\n setState({});\n return;\n }\n (async () => {\n try {\n const svg = await renderExcalidrawSvg(trimmed, isDark);\n if (!cancelled) setState({ svg });\n } catch (excalidrawError) {\n try {\n // Fallback keeps diagrams usable if a Mermaid feature is not supported\n // by the Excalidraw converter in a given host app.\n const svg = await renderMermaidSvg(\n trimmed,\n `${renderId}-${isDark ? \"d\" : \"l\"}`,\n isDark,\n );\n if (!cancelled) setState({ svg });\n } catch (mermaidError) {\n const excalidrawMessage = errorMessage(excalidrawError);\n const mermaidMessage = errorMessage(mermaidError);\n if (!cancelled) {\n setState({\n error:\n excalidrawMessage === mermaidMessage\n ? mermaidMessage\n : `Excalidraw: ${excalidrawMessage}; Mermaid fallback: ${mermaidMessage}`,\n });\n }\n }\n }\n })();\n return () => {\n cancelled = true;\n };\n // Re-render when the source OR the resolved theme changes so toggling\n // dark/light updates the diagram live.\n }, [mounted, source, isDark, renderId]);\n\n if (!mounted) {\n return (\n <div className=\"mt-2 flex min-h-24 items-center justify-center rounded-lg border border-plan-line bg-plan-code text-sm text-plan-muted\">\n {copy.loadingDiagram}\n </div>\n );\n }\n\n if (state.error) {\n return (\n <div className=\"mt-2 space-y-2\">\n <pre className=\"overflow-auto rounded-lg border border-plan-line bg-plan-code px-3 py-2 font-mono [font-size:var(--plan-code-size)] text-plan-code-text\">\n {source}\n </pre>\n <p className=\"text-sm text-plan-muted\">\n {copy.couldNotRenderDiagram}: {state.error}\n </p>\n </div>\n );\n }\n\n if (!state.svg) {\n return (\n <div className=\"mt-2 flex min-h-24 items-center justify-center rounded-lg border border-plan-line bg-plan-code text-sm text-plan-muted\">\n {copy.addDiagramDefinition}\n </div>\n );\n }\n\n // Hover-revealed top-right expand button + shared lightbox, matching the\n // DiagramBlock affordance exactly (same icon, reveal-on-hover/focus, Escape +\n // backdrop close via the reused `DiagramLightbox`). The enlarged view re-shows\n // the same rendered SVG scaled to fit the wider modal.\n const svg = state.svg;\n return (\n <div className=\"group/mermaid relative\">\n <MermaidSvg svg={svg} />\n <button\n type=\"button\"\n data-plan-interactive\n onClick={() => setExpanded(true)}\n aria-label={copy.expandDiagram}\n title={copy.expandDiagram}\n className=\"an-diagram-expand-trigger absolute right-2 top-2 z-10 flex size-7 items-center justify-center rounded-md border border-border/60 bg-background/90 text-muted-foreground opacity-0 shadow-sm backdrop-blur transition-[color,opacity] hover:text-foreground focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring group-hover/mermaid:opacity-100\"\n >\n <IconArrowsMaximize className=\"size-4\" />\n </button>\n {expanded ? (\n <DiagramLightbox onClose={() => setExpanded(false)}>\n <MermaidSvg svg={svg} enlarged />\n </DiagramLightbox>\n ) : null}\n </div>\n );\n}\n\n/**\n * Read-only renderer for a `mermaid` block. Wraps the diagram in the standard\n * titled `plan-block` section + an optional muted caption, matching the plan\n * house style.\n */\nexport function MermaidRead({\n data,\n blockId,\n title,\n summary,\n}: BlockReadProps<MermaidData>) {\n return (\n <section\n {...ltrCodeBlockProps}\n className=\"plan-block\"\n data-block-id={blockId}\n >\n {title && <div className=\"plan-block-label\">{title}</div>}\n <MermaidDiagram source={data.source} idSeed={blockId} />\n {data.caption && (\n <p className=\"mt-3 text-sm text-plan-muted\">{data.caption}</p>\n )}\n {summary && <p className=\"mt-5 text-plan-muted\">{summary}</p>}\n </section>\n );\n}\n\n/**\n * Edit renderer (panel surface) for a `mermaid` block: a monospace textarea for\n * the diagram source plus an optional caption input. Both commit immediately via\n * `onChange`. `editSurface: \"panel\"` means the registry renders the `Read` view\n * with a corner edit button that opens this form in the plan's shared popover, so\n * this renders only the form (the popover supplies the chrome and title).\n */\nexport function MermaidEdit({\n data,\n onChange,\n editable,\n}: BlockEditProps<MermaidData>) {\n const sourceId = useId();\n const captionId = useId();\n\n return (\n <div className=\"grid gap-3\" data-plan-interactive>\n <div className=\"grid gap-1.5\">\n <DevLabel htmlFor={sourceId}>Diagram source</DevLabel>\n <textarea\n id={sourceId}\n value={data.source}\n readOnly={!editable}\n spellCheck={false}\n onChange={(event) =>\n onChange({ ...data, source: event.target.value })\n }\n className=\"flex min-h-56 w-full rounded-md border border-input bg-transparent px-3 py-2 font-mono text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50\"\n placeholder={\"flowchart TD\\n A[Start] --> B{Decision}\"}\n />\n <p className=\"text-xs text-muted-foreground\">\n Mermaid syntax — flowcharts, sequence diagrams, and more.\n </p>\n </div>\n <div className=\"grid gap-1.5\">\n <DevLabel htmlFor={captionId}>Caption</DevLabel>\n <DevInput\n id={captionId}\n value={data.caption ?? \"\"}\n readOnly={!editable}\n onChange={(event) =>\n onChange({\n ...data,\n caption: event.target.value || undefined,\n })\n }\n placeholder=\"Optional caption\"\n />\n </div>\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MermaidBlock.js","sourceRoot":"","sources":["../../../../src/client/blocks/library/MermaidBlock.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AA8B/C,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,0BAA0B,CAAC;AAC7E,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAW;IACpC,IAAI,OAAO,SAAS,KAAK,WAAW;QAAE,OAAO,GAAG,CAAC;IACjD,MAAM,GAAG,GAAG,IAAI,SAAS,EAAE,CAAC,eAA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AC,oQAAoQ,EAC9Q,WAAW,EAAE,0CAA0C,GACvD,EACF,YAAG,SAAS,EAAC,+BAA+B,+EAExC,IACA,EACN,eAAK,SAAS,EAAC,cAAc,aAC3B,KAAC,QAAQ,IAAC,OAAO,EAAE,SAAS,wBAAoB,EAChD,KAAC,QAAQ,IACP,EAAE,EAAE,SAAS,EACb,KAAK,EAAE,IAAI,CAAC,OAAO,IAAI,EAAE,EACzB,QAAQ,EAAE,CAAC,QAAQ,EACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAClB,QAAQ,CAAC;4BACP,GAAG,IAAI;4BACP,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,SAAS;yBACzC,CAAC,EAEJ,WAAW,EAAC,kBAAkB,GAC9B,IACE,IACF,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { IconArrowsMaximize } from \"@tabler/icons-react\";\nimport { useEffect, useId, useMemo, useState } from \"react\";\n\nimport { ltrCodeBlockProps } from \"../code-block-direction.js\";\nimport type { BlockEditProps, BlockReadProps } from \"../types.js\";\nimport { useBlockCopy } from \"./block-copy.js\";\nimport { DevInput, DevLabel } from \"./dev-doc-ui.js\";\nimport { DiagramLightbox } from \"./diagram.js\";\nimport type { MermaidData } from \"./mermaid.config.js\";\n\n/**\n * Read + Edit renderers for a `mermaid` block — a Mermaid diagram definition\n * (flowchart, sequence, etc.) edited as raw text and rendered as an\n * Excalidraw-style SVG so it matches the plan's hand-drawn / sketchy house\n * style.\n * Lives in core so any app can register the dev-doc block; it stays app-agnostic\n * (no shadcn / next-themes import).\n *\n * The Mermaid and Excalidraw runtimes are browser-only,\n * so the Read renderer SSR-guards: it renders a lightweight placeholder until a\n * `useEffect` confirms it is mounted, then dynamically imports\n * `@excalidraw/mermaid-to-excalidraw` + `@excalidraw/excalidraw` and injects\n * the exported SVG. If Excalidraw conversion fails, it falls back to Mermaid's\n * hand-drawn renderer. Parse errors never throw; they show the raw source and\n * the error message.\n *\n * Dark mode: the plan editor toggles a `.dark` class on <html>. The Read renderer\n * reads `document.documentElement.classList.contains(\"dark\")` (re-checking on a\n * `MutationObserver` of the html class) and re-renders the diagram with matching\n * light/dark export settings.\n */\n\ninterface MermaidRenderState {\n svg?: string;\n error?: string;\n}\n\nfunction errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : \"Failed to render diagram\";\n}\n\nfunction sanitizeSvgMarkup(svg: string): string {\n if (typeof DOMParser === \"undefined\") return svg;\n const doc = new DOMParser().parseFromString(svg, \"image/svg+xml\");\n doc\n .querySelectorAll(\"script, foreignObject\")\n .forEach((node) => node.remove());\n for (const element of Array.from(doc.querySelectorAll(\"*\"))) {\n for (const attr of Array.from(element.attributes)) {\n const name = attr.name.toLowerCase();\n const value = attr.value.trim().toLowerCase();\n if (\n name.startsWith(\"on\") ||\n ((name === \"href\" || name.endsWith(\":href\")) &&\n value.startsWith(\"javascript:\"))\n ) {\n element.removeAttribute(attr.name);\n }\n }\n }\n return doc.documentElement.outerHTML;\n}\n\nasync function renderExcalidrawSvg(\n source: string,\n isDark: boolean,\n): Promise<string> {\n const [{ parseMermaidToExcalidraw }, excalidraw] = await Promise.all([\n import(\"@excalidraw/mermaid-to-excalidraw\") as Promise<{\n parseMermaidToExcalidraw: (source: string) => Promise<{\n elements: unknown[];\n files?: Record<string, unknown>;\n }>;\n }>,\n import(\"@excalidraw/excalidraw\") as Promise<{\n convertToExcalidrawElements: (elements: unknown[]) => unknown[];\n exportToSvg: (options: {\n elements: unknown[];\n appState: {\n theme: \"dark\" | \"light\";\n viewBackgroundColor: string;\n exportWithDarkMode: boolean;\n };\n files: Record<string, unknown>;\n }) => Promise<{ outerHTML: string }>;\n }>,\n ]);\n const { elements, files } = await parseMermaidToExcalidraw(source);\n const excalidrawElements = excalidraw.convertToExcalidrawElements(elements);\n const svg = await excalidraw.exportToSvg({\n elements: excalidrawElements,\n appState: {\n theme: isDark ? \"dark\" : \"light\",\n viewBackgroundColor: \"transparent\",\n exportWithDarkMode: isDark,\n },\n files: files ?? {},\n });\n return sanitizeSvgMarkup(svg.outerHTML);\n}\n\nasync function renderMermaidSvg(\n source: string,\n id: string,\n isDark: boolean,\n): Promise<string> {\n const mermaid = (\n (await import(\"mermaid\")) as {\n default: {\n initialize: (config: Record<string, unknown>) => void;\n render: (id: string, source: string) => Promise<{ svg: string }>;\n };\n }\n ).default;\n mermaid.initialize({\n startOnLoad: false,\n securityLevel: \"strict\",\n look: \"handDrawn\",\n theme: isDark ? \"dark\" : \"neutral\",\n });\n const { svg } = await mermaid.render(id, source);\n return sanitizeSvgMarkup(svg);\n}\n\n/** Read the live dark-mode flag from the document root (next-themes-free). */\nfunction useIsDark(): boolean {\n const [isDark, setIsDark] = useState(false);\n useEffect(() => {\n if (typeof document === \"undefined\") return;\n const root = document.documentElement;\n const read = () => setIsDark(root.classList.contains(\"dark\"));\n read();\n const observer = new MutationObserver(read);\n observer.observe(root, { attributes: true, attributeFilter: [\"class\"] });\n return () => observer.disconnect();\n }, []);\n return isDark;\n}\n\n/**\n * Inject a rendered Mermaid/Excalidraw SVG string. Shared by the inline render\n * and the expand lightbox so the enlarged view shows the exact same SVG; the\n * lightbox passes `enlarged` so the SVG stretches to fill the wider modal\n * (`max-w-5xl`) instead of staying at its intrinsic inline size.\n */\nfunction MermaidSvg({ svg, enlarged }: { svg: string; enlarged?: boolean }) {\n return (\n <div\n className={\n enlarged\n ? \"flex justify-center overflow-auto [&_svg]:h-auto [&_svg]:w-full [&_svg]:max-w-full\"\n : \"mt-2 flex justify-center overflow-auto [&_svg]:h-auto [&_svg]:max-w-full\"\n }\n // Excalidraw and Mermaid output are sanitized before injection.\n dangerouslySetInnerHTML={{ __html: svg }}\n />\n );\n}\n\nfunction MermaidDiagram({\n source,\n idSeed,\n}: {\n source: string;\n idSeed: string;\n}) {\n const isDark = useIsDark();\n const copy = useBlockCopy();\n // Only render the diagram after mount: `mermaid` is client-only and SSR has no\n // DOM for it to measure against.\n const [mounted, setMounted] = useState(false);\n const [state, setState] = useState<MermaidRenderState>({});\n const [expanded, setExpanded] = useState(false);\n\n // A DOM-id-safe, stable-per-block render id. Mermaid requires a valid CSS id.\n const renderId = useMemo(\n () => `mermaid-${idSeed.replace(/[^a-zA-Z0-9_-]/g, \"-\")}`,\n [idSeed],\n );\n\n useEffect(() => {\n setMounted(true);\n }, []);\n\n useEffect(() => {\n if (!mounted) return;\n let cancelled = false;\n const trimmed = source.trim();\n if (!trimmed) {\n setState({});\n return;\n }\n (async () => {\n try {\n const svg = await renderExcalidrawSvg(trimmed, isDark);\n if (!cancelled) setState({ svg });\n } catch (excalidrawError) {\n try {\n // Fallback keeps diagrams usable if a Mermaid feature is not supported\n // by the Excalidraw converter in a given host app.\n const svg = await renderMermaidSvg(\n trimmed,\n `${renderId}-${isDark ? \"d\" : \"l\"}`,\n isDark,\n );\n if (!cancelled) setState({ svg });\n } catch (mermaidError) {\n const excalidrawMessage = errorMessage(excalidrawError);\n const mermaidMessage = errorMessage(mermaidError);\n if (!cancelled) {\n setState({\n error:\n excalidrawMessage === mermaidMessage\n ? mermaidMessage\n : `Excalidraw: ${excalidrawMessage}; Mermaid fallback: ${mermaidMessage}`,\n });\n }\n }\n }\n })();\n return () => {\n cancelled = true;\n };\n // Re-render when the source OR the resolved theme changes so toggling\n // dark/light updates the diagram live.\n }, [mounted, source, isDark, renderId]);\n\n if (!mounted) {\n return (\n <div className=\"mt-2 flex min-h-24 items-center justify-center rounded-lg border border-plan-line bg-plan-code text-sm text-plan-muted\">\n {copy.loadingDiagram}\n </div>\n );\n }\n\n if (state.error) {\n return (\n <div className=\"mt-2 space-y-2\">\n <pre className=\"overflow-auto rounded-lg border border-plan-line bg-plan-code px-3 py-2 font-mono [font-size:var(--plan-code-size)] text-plan-code-text\">\n {source}\n </pre>\n <p className=\"text-sm text-plan-muted\">\n {copy.couldNotRenderDiagram}: {state.error}\n </p>\n </div>\n );\n }\n\n if (!state.svg) {\n return (\n <div className=\"mt-2 flex min-h-24 items-center justify-center rounded-lg border border-plan-line bg-plan-code text-sm text-plan-muted\">\n {copy.addDiagramDefinition}\n </div>\n );\n }\n\n // Hover-revealed top-right expand button + shared lightbox, matching the\n // DiagramBlock affordance exactly (same icon, reveal-on-hover/focus, Escape +\n // backdrop close via the reused `DiagramLightbox`). The enlarged view re-shows\n // the same rendered SVG scaled to fit the wider modal.\n const svg = state.svg;\n return (\n <div className=\"group/mermaid relative\">\n <MermaidSvg svg={svg} />\n <button\n type=\"button\"\n data-plan-interactive\n onClick={() => setExpanded(true)}\n aria-label={copy.expandDiagram}\n title={copy.expandDiagram}\n className=\"an-diagram-expand-trigger absolute right-2 top-2 z-10 flex size-7 items-center justify-center rounded-md border border-border/60 bg-background text-muted-foreground opacity-0 shadow-sm transition-[color,opacity] hover:text-foreground focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring group-hover/mermaid:opacity-100\"\n >\n <IconArrowsMaximize className=\"size-4\" />\n </button>\n {expanded ? (\n <DiagramLightbox onClose={() => setExpanded(false)}>\n <MermaidSvg svg={svg} enlarged />\n </DiagramLightbox>\n ) : null}\n </div>\n );\n}\n\n/**\n * Read-only renderer for a `mermaid` block. Wraps the diagram in the standard\n * titled `plan-block` section + an optional muted caption, matching the plan\n * house style.\n */\nexport function MermaidRead({\n data,\n blockId,\n title,\n summary,\n}: BlockReadProps<MermaidData>) {\n return (\n <section\n {...ltrCodeBlockProps}\n className=\"plan-block\"\n data-block-id={blockId}\n >\n {title && <div className=\"plan-block-label\">{title}</div>}\n <MermaidDiagram source={data.source} idSeed={blockId} />\n {data.caption && (\n <p className=\"mt-3 text-sm text-plan-muted\">{data.caption}</p>\n )}\n {summary && <p className=\"mt-5 text-plan-muted\">{summary}</p>}\n </section>\n );\n}\n\n/**\n * Edit renderer (panel surface) for a `mermaid` block: a monospace textarea for\n * the diagram source plus an optional caption input. Both commit immediately via\n * `onChange`. `editSurface: \"panel\"` means the registry renders the `Read` view\n * with a corner edit button that opens this form in the plan's shared popover, so\n * this renders only the form (the popover supplies the chrome and title).\n */\nexport function MermaidEdit({\n data,\n onChange,\n editable,\n}: BlockEditProps<MermaidData>) {\n const sourceId = useId();\n const captionId = useId();\n\n return (\n <div className=\"grid gap-3\" data-plan-interactive>\n <div className=\"grid gap-1.5\">\n <DevLabel htmlFor={sourceId}>Diagram source</DevLabel>\n <textarea\n id={sourceId}\n value={data.source}\n readOnly={!editable}\n spellCheck={false}\n onChange={(event) =>\n onChange({ ...data, source: event.target.value })\n }\n className=\"flex min-h-56 w-full rounded-md border border-input bg-transparent px-3 py-2 font-mono text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50\"\n placeholder={\"flowchart TD\\n A[Start] --> B{Decision}\"}\n />\n <p className=\"text-xs text-muted-foreground\">\n Mermaid syntax — flowcharts, sequence diagrams, and more.\n </p>\n </div>\n <div className=\"grid gap-1.5\">\n <DevLabel htmlFor={captionId}>Caption</DevLabel>\n <DevInput\n id={captionId}\n value={data.caption ?? \"\"}\n readOnly={!editable}\n onChange={(event) =>\n onChange({\n ...data,\n caption: event.target.value || undefined,\n })\n }\n placeholder=\"Optional caption\"\n />\n </div>\n </div>\n );\n}\n"]}
|
|
@@ -286,7 +286,7 @@ function ExpandableDiagramBody({ data, ctx, compact, }) {
|
|
|
286
286
|
const styleTooltip = sketchy
|
|
287
287
|
? copy.handDrawnDiagramsSwitch
|
|
288
288
|
: copy.cleanDiagramsSwitch;
|
|
289
|
-
return (_jsxs("div", { className: "group/diagram relative", children: [_jsx(DiagramBody, { data: data, ctx: ctx, compact: compact }), _jsx(TooltipProvider, { delayDuration: 100, skipDelayDuration: 0, children: _jsxs("div", { className: "absolute right-2 top-2 z-10 flex items-center gap-1.5", children: [supportsStyleToggle && (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx("button", { type: "button", "data-plan-interactive": true, onClick: () => toggleWireframeStyle(), "aria-label": styleLabel, "aria-pressed": sketchy, className: "an-diagram-style-trigger flex size-7 items-center justify-center rounded-md border border-border/60 bg-background
|
|
289
|
+
return (_jsxs("div", { className: "group/diagram relative", children: [_jsx(DiagramBody, { data: data, ctx: ctx, compact: compact }), _jsx(TooltipProvider, { delayDuration: 100, skipDelayDuration: 0, children: _jsxs("div", { className: "absolute right-2 top-2 z-10 flex items-center gap-1.5", children: [supportsStyleToggle && (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx("button", { type: "button", "data-plan-interactive": true, onClick: () => toggleWireframeStyle(), "aria-label": styleLabel, "aria-pressed": sketchy, className: "an-diagram-style-trigger flex size-7 items-center justify-center rounded-md border border-border/60 bg-background text-muted-foreground opacity-0 shadow-sm transition-[color,opacity] hover:text-foreground focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring group-hover/diagram:opacity-100", children: sketchy ? (_jsx(IconScribble, { className: "size-4" })) : (_jsx(IconShape2, { className: "size-4" })) }) }), _jsx(TooltipContent, { side: "left", children: styleTooltip })] })), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx("button", { type: "button", "data-plan-interactive": true, onClick: () => setExpanded(true), "aria-label": copy.expandDiagram, className: "an-diagram-expand-trigger flex size-7 items-center justify-center rounded-md border border-border/60 bg-background text-muted-foreground opacity-0 shadow-sm transition-[color,opacity] hover:text-foreground focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring group-hover/diagram:opacity-100", children: _jsx(IconArrowsMaximize, { className: "size-4" }) }) }), _jsx(TooltipContent, { side: "left", children: copy.expandDiagram })] })] }) }), expanded ? (_jsx(DiagramLightbox, { onClose: () => setExpanded(false), children: _jsx(DiagramBody, { data: data, ctx: ctx }) })) : null] }));
|
|
290
290
|
}
|
|
291
291
|
/* -------------------------------------------------------------------------- */
|
|
292
292
|
/* Read + Edit */
|