@agent-native/core 0.137.7 → 0.138.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent-native.eject.json +2 -0
- package/corpus/README.md +1 -1
- package/corpus/templates/analytics/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/analytics/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/analytics/.agents/skills/data-querying/SKILL.md +15 -0
- package/corpus/templates/analytics/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/analytics/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/analytics/AGENTS.md +2 -2
- package/corpus/templates/analytics/actions/get-first-party-analytics-health.ts +65 -0
- package/corpus/templates/analytics/actions/provider-api-catalog.ts +3 -6
- package/corpus/templates/analytics/actions/provider-api-docs.ts +3 -6
- package/corpus/templates/analytics/actions/provider-api-request.ts +3 -6
- package/corpus/templates/analytics/actions/query-agent-native-analytics.ts +3 -3
- package/corpus/templates/analytics/agent-native.json +12 -0
- package/corpus/templates/analytics/app/i18n-data.ts +162 -0
- package/corpus/templates/analytics/app/pages/DataSources.tsx +126 -1
- package/corpus/templates/analytics/changelog/2026-08-05-analytics-now-flags-neon-pressure-and-guides-high-volume-tra.md +6 -0
- package/corpus/templates/analytics/changelog/2026-08-05-first-party-analytics-uses-compact-rollups-for-faster-usage-.md +6 -0
- package/corpus/templates/analytics/server/db/schema.ts +52 -0
- package/corpus/templates/analytics/server/lib/credential-keys.ts +3 -0
- package/corpus/templates/analytics/server/lib/first-party-analytics-health.ts +397 -0
- package/corpus/templates/analytics/server/lib/first-party-analytics-rollups.ts +182 -0
- package/corpus/templates/analytics/server/lib/first-party-analytics.ts +86 -15
- package/corpus/templates/analytics/server/lib/provider-api.ts +20 -1
- package/corpus/templates/analytics/server/lib/replay-storage.ts +1 -1
- package/corpus/templates/analytics/server/plugins/agent-chat.ts +1 -0
- package/corpus/templates/analytics/server/plugins/db.ts +60 -0
- package/corpus/templates/assets/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/assets/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/assets/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/assets/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/assets/agent-native.json +12 -0
- package/corpus/templates/assets/server/lib/generation.ts +8 -8
- package/corpus/templates/assets/server/lib/storage.ts +1 -1
- package/corpus/templates/assets/server/plugins/onboarding.ts +1 -1
- package/corpus/templates/brain/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/brain/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/brain/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/brain/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/brain/agent-native.json +12 -0
- package/corpus/templates/calendar/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/calendar/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/calendar/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/calendar/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/calendar/agent-native.json +12 -0
- package/corpus/templates/chat/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/chat/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/chat/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/chat/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/chat/AGENTS.md +3 -0
- package/corpus/templates/chat/DESIGN.md +28 -0
- package/corpus/templates/chat/agent-native.json +12 -0
- package/corpus/templates/clips/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/clips/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/clips/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/clips/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/clips/actions/cleanup-transcript.ts +2 -2
- package/corpus/templates/clips/actions/delete-recording-permanent.ts +3 -0
- package/corpus/templates/clips/actions/get-playback-position.ts +68 -0
- package/corpus/templates/clips/actions/import-loom-recording.ts +2 -2
- package/corpus/templates/clips/actions/save-playback-position.ts +80 -0
- package/corpus/templates/clips/actions/set-thumbnail.ts +1 -1
- package/corpus/templates/clips/agent-native.json +12 -0
- package/corpus/templates/clips/app/components/player/video-player.tsx +54 -5
- package/corpus/templates/clips/app/components/recorder/pre-record-panel.tsx +65 -18
- package/corpus/templates/clips/app/hooks/use-playback-position.ts +188 -0
- package/corpus/templates/clips/app/hooks/use-view-tracking.ts +6 -24
- package/corpus/templates/clips/app/i18n/en-US.ts +4 -0
- package/corpus/templates/clips/app/lib/playback-position.ts +99 -0
- package/corpus/templates/clips/app/lib/viewer-session.ts +29 -0
- package/corpus/templates/clips/changelog/2026-08-05-clip-buffering-now-uses-buffering-copy-after-playback.md +6 -0
- package/corpus/templates/clips/changelog/2026-08-05-clips-remembers-your-playback-position-when-you-reopen-a-cli.md +6 -0
- package/corpus/templates/clips/desktop/package.json +1 -0
- package/corpus/templates/clips/desktop/src/app.tsx +70 -6
- package/corpus/templates/clips/desktop/src/components/AlertDialog.tsx +131 -0
- package/corpus/templates/clips/desktop/src/styles.css +129 -0
- package/corpus/templates/clips/learnings.defaults.md +1 -1
- package/corpus/templates/clips/server/db/schema.ts +18 -0
- package/corpus/templates/clips/server/lib/public-agent-context.ts +1 -1
- package/corpus/templates/clips/server/lib/video-storage.ts +1 -1
- package/corpus/templates/clips/server/plugins/db.ts +15 -0
- package/corpus/templates/clips/server/routes/api/media/index.post.ts +1 -1
- package/corpus/templates/content/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/content/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/content/.agents/skills/document-editing/references/databases.md +13 -0
- package/corpus/templates/content/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/content/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/content/AGENTS.md +1 -0
- package/corpus/templates/content/actions/_content-database-mutation-lock.ts +41 -0
- package/corpus/templates/content/actions/_content-database-row-migration.ts +569 -0
- package/corpus/templates/content/actions/_database-source-utils.ts +82 -36
- package/corpus/templates/content/actions/_database-utils.ts +5 -0
- package/corpus/templates/content/actions/_delete-content-space.ts +25 -11
- package/corpus/templates/content/actions/add-database-item.ts +60 -42
- package/corpus/templates/content/actions/attach-content-database-source.ts +2 -0
- package/corpus/templates/content/actions/configure-document-property.ts +99 -104
- package/corpus/templates/content/actions/delete-content-database.ts +19 -7
- package/corpus/templates/content/actions/delete-document-property.ts +47 -58
- package/corpus/templates/content/actions/delete-document.ts +390 -167
- package/corpus/templates/content/actions/disconnect-content-database-source.ts +41 -24
- package/corpus/templates/content/actions/duplicate-database-item.ts +63 -31
- package/corpus/templates/content/actions/duplicate-database-items.ts +86 -43
- package/corpus/templates/content/actions/duplicate-document-property.ts +37 -14
- package/corpus/templates/content/actions/migrate-content-database-rows.ts +830 -0
- package/corpus/templates/content/actions/move-database-item.ts +14 -0
- package/corpus/templates/content/actions/permanently-delete-document.ts +27 -6
- package/corpus/templates/content/actions/remove-database-items.ts +13 -0
- package/corpus/templates/content/actions/reorder-document-property.ts +45 -46
- package/corpus/templates/content/actions/set-document-property.ts +68 -28
- package/corpus/templates/content/actions/submit-content-database-form.ts +49 -0
- package/corpus/templates/content/actions/transcribe-media.ts +1 -1
- package/corpus/templates/content/agent-native.json +12 -0
- package/corpus/templates/content/app/components/editor/image-upload.ts +2 -2
- package/corpus/templates/content/app/i18n-data.ts +1 -1
- package/corpus/templates/content/changelog/2026-08-01-content-can-reorganize-every-row-in-an-existing-database-as-.md +6 -0
- package/corpus/templates/content/parity/matrix.md +1 -1
- package/corpus/templates/content/parity/matrix.ts +4 -2
- package/corpus/templates/content/server/db/schema.ts +30 -0
- package/corpus/templates/content/server/plugins/db.ts +24 -0
- package/corpus/templates/content/server/plugins/onboarding.ts +2 -2
- package/corpus/templates/crm/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/crm/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/crm/agent-native.json +12 -0
- package/corpus/templates/design/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/design/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/design/.agents/skills/design-generation/SKILL.md +2 -0
- package/corpus/templates/design/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/design/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/design/CODE_NATIVE_DESIGN_STUDIO_IMPLEMENTATION_PLAN.md +2 -2
- package/corpus/templates/design/DESIGN-STUDIO-PLAN.md +2 -2
- package/corpus/templates/design/actions/apply-design-token-edit.ts +1 -1
- package/corpus/templates/design/actions/capture-design-state.ts +1 -1
- package/corpus/templates/design/actions/connect-builder-app.ts +2 -2
- package/corpus/templates/design/actions/create-design-branch.ts +1 -1
- package/corpus/templates/design/actions/create-fusion-app.ts +3 -3
- package/corpus/templates/design/actions/deploy-design-preview.ts +1 -1
- package/corpus/templates/design/actions/generate-design.ts +3 -2
- package/corpus/templates/design/actions/get-component-details.ts +1 -1
- package/corpus/templates/design/actions/get-design-branch-diff.ts +1 -1
- package/corpus/templates/design/actions/index-components.ts +3 -3
- package/corpus/templates/design/actions/index-design-system-with-builder.ts +1 -1
- package/corpus/templates/design/actions/migrate-inline-design-to-app.ts +3 -3
- package/corpus/templates/design/actions/open-component-source.ts +1 -1
- package/corpus/templates/design/actions/update-design.ts +96 -14
- package/corpus/templates/design/agent-native.json +12 -0
- package/corpus/templates/design/app/components/design/DesignImportPanel.tsx +7 -2
- package/corpus/templates/design/app/components/design/FigmaHydrationDialog.tsx +11 -2
- package/corpus/templates/design/app/components/design/edit-panel/component-section.tsx +1 -1
- package/corpus/templates/design/app/components/editor/PromptDialog.tsx +8 -1
- package/corpus/templates/design/app/i18n-data.ts +53 -22
- package/corpus/templates/design/app/lib/design-file-upload.ts +2 -3
- package/corpus/templates/design/app/lib/upload-limits.ts +4 -0
- package/corpus/templates/design/app/pages/DesignSystemSetup.tsx +1 -1
- package/corpus/templates/design/changelog/2026-08-05-chat-attachments-now-warn-before-upload-when-they-exceed-the.md +6 -0
- package/corpus/templates/design/changelog/2026-08-05-figma-fig-uploads-now-show-a-clear-4-mb-limit-up-front-inste.md +6 -0
- package/corpus/templates/design/scripts/qa-figma-stress-import.ts +1 -1
- package/corpus/templates/design/server/handlers/import-design-file.ts +9 -5
- package/corpus/templates/design/server/handlers/uploads.ts +13 -9
- package/corpus/templates/design/server/lib/fig-file-limits.ts +2 -1
- package/corpus/templates/design/server/lib/figma-image-hydration.ts +1 -1
- package/corpus/templates/design/server/lib/figma-node-import.ts +1 -1
- package/corpus/templates/design/server/lib/request-body-limits.ts +11 -0
- package/corpus/templates/design/shared/canvas-frames.ts +81 -0
- package/corpus/templates/design/shared/design-source-capabilities.ts +25 -9
- package/corpus/templates/dispatch/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/dispatch/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/dispatch/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/dispatch/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/dispatch/agent-native.json +12 -0
- package/corpus/templates/factory/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/factory/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/factory/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/factory/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/factory/agent-native.json +12 -0
- package/corpus/templates/forms/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/forms/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/forms/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/forms/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/forms/actions/export-responses.ts +1 -1
- package/corpus/templates/forms/agent-native.json +12 -0
- package/corpus/templates/macros/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/macros/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/macros/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/macros/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/macros/agent-native.json +12 -0
- package/corpus/templates/mail/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/mail/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/mail/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/mail/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/mail/agent-native.json +12 -0
- package/corpus/templates/mail/app/i18n/en-US.ts +1 -1
- package/corpus/templates/mail/server/lib/media-upload.ts +1 -1
- package/corpus/templates/plan/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/plan/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/plan/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/plan/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/plan/agent-native.json +12 -0
- package/corpus/templates/plan/server/lib/plan-assets.ts +1 -1
- package/corpus/templates/slides/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/slides/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/slides/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/slides/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/slides/actions/generate-image-api.ts +1 -1
- package/corpus/templates/slides/actions/generate-slides-ai.ts +1 -1
- package/corpus/templates/slides/actions/import-file.ts +2 -2
- package/corpus/templates/slides/actions/index-design-system-with-builder.ts +1 -1
- package/corpus/templates/slides/agent-native.json +12 -0
- package/corpus/templates/slides/app/components/design-system/DesignSystemSetup.tsx +1 -1
- package/corpus/templates/slides/app/i18n/en-US.ts +2 -2
- package/corpus/templates/slides/app/lib/deck-sorting.ts +19 -0
- package/corpus/templates/slides/app/lib/image-drop-to-agent.ts +1 -1
- package/corpus/templates/slides/app/pages/Index.tsx +7 -2
- package/corpus/templates/slides/changelog/2026-08-05-decks-are-now-sorted-by-most-recently-updated.md +6 -0
- package/corpus/templates/slides/server/handlers/assets.ts +1 -1
- package/corpus/templates/slides/server/handlers/uploads.ts +1 -1
- package/corpus/templates/tasks/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/corpus/templates/tasks/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/corpus/templates/tasks/.agents/skills/frontend-design/SKILL.md +23 -2
- package/corpus/templates/tasks/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/corpus/templates/tasks/agent-native.json +12 -0
- package/dist/action.d.ts +6 -0
- package/dist/agent/engine/builder-engine.js +2 -2
- package/dist/agent/engine/credential-errors.d.ts +1 -1
- package/dist/agent/engine/credential-errors.js +2 -2
- package/dist/agent/production-agent.js +3 -2
- package/dist/brand-kit/fig/index.js +1 -1
- package/dist/cli/agent.js +45 -3
- package/dist/cli/code-agent-executor.js +2 -1
- package/dist/cli/create.d.ts +9 -1
- package/dist/cli/create.js +94 -1
- package/dist/cli/doctor.d.ts +8 -11
- package/dist/cli/doctor.js +92 -24
- package/dist/cli/index.js +6 -5
- package/dist/client/AgentAskPopover.d.ts +3 -1
- package/dist/client/AgentAskPopover.js +2 -2
- package/dist/client/AgentPanel.js +9 -3
- package/dist/client/AssistantChat.js +54 -33
- package/dist/client/MultiTabAssistantChat.js +1 -1
- package/dist/client/RouteTransitionIndicator.d.ts +7 -0
- package/dist/client/RouteTransitionIndicator.js +31 -0
- package/dist/client/agent-engine-key.js +1 -1
- package/dist/client/app-providers.js +11 -2
- package/dist/client/chat/message-components.js +1 -1
- package/dist/client/chat/run-recovery.js +1 -1
- package/dist/client/chat/tool-call-display.d.ts +3 -1
- package/dist/client/chat/tool-call-display.js +4 -3
- package/dist/client/chat-model-groups.d.ts +6 -0
- package/dist/client/chat-model-groups.js +11 -0
- package/dist/client/error-format.js +1 -1
- package/dist/client/i18n.js +1 -1
- package/dist/client/onboarding/FirstRunOnboarding.d.ts +5 -1
- package/dist/client/onboarding/FirstRunOnboarding.js +29 -13
- package/dist/client/onboarding/first-run-enabled.d.ts +6 -1
- package/dist/client/onboarding/first-run-enabled.js +33 -3
- package/dist/client/onboarding/use-onboarding.js +16 -11
- package/dist/client/require-session.js +13 -4
- package/dist/client/resources/mcp-integration-catalog.js +26 -0
- package/dist/client/resources/mcp-integration-logos.js +4 -0
- package/dist/client/route-warmup.js +56 -10
- package/dist/client/settings/AccountSettingsCard.js +78 -3
- package/dist/client/settings/SettingsPanel.js +1 -1
- package/dist/client/settings/VoiceTranscriptionSection.js +2 -2
- package/dist/client/settings/useBuilderStatus.js +1 -1
- package/dist/client/setup-connections/useBuilderConnectCardController.js +1 -1
- package/dist/client/ui/index.d.ts +1 -0
- package/dist/client/ui/index.js +1 -0
- package/dist/client/uploads/upload-editor-image.js +1 -1
- package/dist/client/use-chat-threads.js +3 -0
- package/dist/client/use-session.d.ts +11 -0
- package/dist/client/use-session.js +34 -6
- package/dist/collab/routes.d.ts +2 -2
- package/dist/config.d.ts +48 -0
- package/dist/config.js +111 -0
- package/dist/db/migrations.js +5 -0
- package/dist/eject/provider-api-definitions.d.ts +1 -1
- package/dist/eject/provider-api-definitions.js +1 -0
- package/dist/eject/remote-mcp-presets.js +1 -0
- package/dist/extensions/web-search-tool.js +2 -2
- package/dist/file-upload/actions/upload-image.js +1 -1
- package/dist/file-upload/registry.js +1 -1
- package/dist/guards/index.d.ts +3 -0
- package/dist/guards/index.js +2 -0
- package/dist/guards/no-empty-migrations.d.ts +14 -0
- package/dist/guards/no-empty-migrations.js +126 -0
- package/dist/index.browser.d.ts +1 -0
- package/dist/index.browser.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/localization/default-messages.d.ts +24 -0
- package/dist/localization/default-messages.js +26 -2
- package/dist/notifications/routes.d.ts +6 -6
- package/dist/onboarding/app-profile.js +1 -1
- package/dist/onboarding/plugin.d.ts +2 -0
- package/dist/onboarding/plugin.js +29 -2
- package/dist/progress/routes.d.ts +1 -1
- package/dist/provider-api/actions/custom-provider-registration.d.ts +16 -16
- package/dist/provider-api/actions/provider-api.d.ts +13 -13
- package/dist/provider-api/index.d.ts +4 -4
- package/dist/provider-api/index.js +35 -0
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/resources/handlers.js +1 -1
- package/dist/scripts/docs/framework-search.d.ts +9 -0
- package/dist/scripts/docs/framework-search.js +239 -0
- package/dist/scripts/docs/index.js +1 -0
- package/dist/scripts/docs/search.d.ts +10 -0
- package/dist/scripts/docs/search.js +1 -1
- package/dist/scripts/docs/source-search.d.ts +10 -2
- package/dist/scripts/docs/source-search.js +108 -41
- package/dist/search-utils/index.d.ts +11 -0
- package/dist/search-utils/index.js +72 -0
- package/dist/server/action-change.d.ts +6 -0
- package/dist/server/action-change.js +28 -14
- package/dist/server/action-discovery.js +9 -0
- package/dist/server/action-routes.js +1 -0
- package/dist/server/agent-chat/browser-team-tools.js +1 -1
- package/dist/server/agent-chat/script-entries.js +43 -2
- package/dist/server/auth-login-mode.d.ts +8 -0
- package/dist/server/auth-login-mode.js +17 -0
- package/dist/server/auth.js +100 -15
- package/dist/server/better-auth-instance.d.ts +36 -0
- package/dist/server/better-auth-instance.js +25 -3
- package/dist/server/builder-design-systems.js +1 -1
- package/dist/server/core-routes-plugin.js +17 -14
- package/dist/server/credential-provider.js +3 -3
- package/dist/server/email-templates.d.ts +7 -0
- package/dist/server/email-templates.js +24 -0
- package/dist/server/email.d.ts +17 -0
- package/dist/server/email.js +22 -1
- package/dist/server/framework-request-handler.js +6 -0
- package/dist/server/onboarding-html.d.ts +2 -0
- package/dist/server/onboarding-html.js +169 -8
- package/dist/server/realtime-token.d.ts +1 -1
- package/dist/server/realtime-voice.js +1 -1
- package/dist/server/sentry.d.ts +1 -1
- package/dist/server/transcribe-voice.js +3 -3
- package/dist/shared/first-run-onboarding.d.ts +1 -0
- package/dist/shared/first-run-onboarding.js +1 -0
- package/dist/templates/chat/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/dist/templates/chat/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/dist/templates/chat/.agents/skills/frontend-design/SKILL.md +23 -2
- package/dist/templates/chat/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/dist/templates/chat/AGENTS.md +3 -0
- package/dist/templates/chat/DESIGN.md +28 -0
- package/dist/templates/chat/agent-native.json +12 -0
- package/dist/templates/default/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/dist/templates/default/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/dist/templates/default/.agents/skills/frontend-design/SKILL.md +23 -2
- package/dist/templates/default/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/dist/templates/default/AGENTS.md +4 -0
- package/dist/templates/default/DESIGN.md +30 -0
- package/dist/templates/default/agent-native.json +9 -0
- package/dist/templates/default/app/i18n/ar-SA.ts +2 -2
- package/dist/templates/default/app/i18n/de-DE.ts +2 -2
- package/dist/templates/default/app/i18n/en-US.ts +2 -2
- package/dist/templates/default/app/i18n/es-ES.ts +2 -2
- package/dist/templates/default/app/i18n/fr-FR.ts +2 -2
- package/dist/templates/default/app/i18n/hi-IN.ts +2 -2
- package/dist/templates/default/app/i18n/ja-JP.ts +2 -2
- package/dist/templates/default/app/i18n/ko-KR.ts +2 -2
- package/dist/templates/default/app/i18n/pt-BR.ts +2 -2
- package/dist/templates/default/app/i18n/zh-CN.ts +2 -2
- package/dist/templates/default/app/i18n/zh-TW.ts +1 -1
- package/dist/templates/default/package.json +1 -0
- package/dist/templates/headless/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/dist/templates/headless/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/dist/templates/headless/agent-native.json +9 -0
- package/dist/templates/headless/package.json +2 -0
- package/dist/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/dist/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/dist/templates/workspace-core/.agents/skills/frontend-design/SKILL.md +23 -2
- package/dist/templates/workspace-core/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/dist/templates/workspace-core/AGENTS.md +3 -0
- package/dist/templates/workspace-core/DESIGN.md +35 -0
- package/dist/templates/workspace-root/AGENTS.md +3 -0
- package/dist/templates/workspace-root/DESIGN.md +35 -0
- package/dist/templates/workspace-root/agent-native.json +9 -0
- package/dist/templates/workspace-root/package.json +3 -0
- package/dist/transcription/builder-transcription.js +1 -1
- package/dist/user-profile/actions/change-password.d.ts +8 -0
- package/dist/user-profile/actions/change-password.js +24 -0
- package/dist/user-profile/actions/get-auth-methods.d.ts +6 -0
- package/dist/user-profile/actions/get-auth-methods.js +23 -0
- package/dist/user-profile/actions/set-password.d.ts +7 -0
- package/dist/user-profile/actions/set-password.js +23 -0
- package/dist/vite/client.d.ts +8 -1
- package/dist/vite/client.js +63 -12
- package/dist/vite/index.d.ts +1 -0
- package/dist/vite/index.js +1 -0
- package/docs/AGENTS.md +7 -2
- package/docs/SKILL.md +7 -5
- package/docs/content/agent-native-config.mdx +165 -0
- package/docs/content/agent-native-toolkit.mdx +1 -1
- package/docs/content/deployment.mdx +7 -2
- package/docs/content/doctor.mdx +21 -13
- package/docs/content/environment-variables.mdx +158 -0
- package/docs/content/file-uploads.mdx +1 -1
- package/docs/content/getting-started.mdx +1 -1
- package/docs/content/key-concepts.mdx +1 -1
- package/docs/content/multi-app-workspace.mdx +1 -1
- package/docs/content/template-clips-ai-and-editing.mdx +6 -6
- package/docs/content/template-clips-developers.mdx +3 -3
- package/docs/content/toolkit-settings.mdx +1 -1
- package/docs/content/voice-input.mdx +4 -4
- package/package.json +6 -2
- package/src/eject/provider-api-definitions.ts +1 -0
- package/src/eject/remote-mcp-presets.ts +1 -0
- package/src/templates/chat/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/src/templates/chat/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/src/templates/chat/.agents/skills/frontend-design/SKILL.md +23 -2
- package/src/templates/chat/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/src/templates/chat/AGENTS.md +3 -0
- package/src/templates/chat/DESIGN.md +28 -0
- package/src/templates/chat/agent-native.json +12 -0
- package/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/src/templates/default/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/src/templates/default/.agents/skills/frontend-design/SKILL.md +23 -2
- package/src/templates/default/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/src/templates/default/AGENTS.md +4 -0
- package/src/templates/default/DESIGN.md +30 -0
- package/src/templates/default/agent-native.json +9 -0
- package/src/templates/default/app/i18n/ar-SA.ts +2 -2
- package/src/templates/default/app/i18n/de-DE.ts +2 -2
- package/src/templates/default/app/i18n/en-US.ts +2 -2
- package/src/templates/default/app/i18n/es-ES.ts +2 -2
- package/src/templates/default/app/i18n/fr-FR.ts +2 -2
- package/src/templates/default/app/i18n/hi-IN.ts +2 -2
- package/src/templates/default/app/i18n/ja-JP.ts +2 -2
- package/src/templates/default/app/i18n/ko-KR.ts +2 -2
- package/src/templates/default/app/i18n/pt-BR.ts +2 -2
- package/src/templates/default/app/i18n/zh-CN.ts +2 -2
- package/src/templates/default/app/i18n/zh-TW.ts +1 -1
- package/src/templates/default/package.json +1 -0
- package/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/src/templates/headless/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/src/templates/headless/agent-native.json +9 -0
- package/src/templates/headless/package.json +2 -0
- package/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +23 -3
- package/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +16 -0
- package/src/templates/workspace-core/.agents/skills/frontend-design/SKILL.md +23 -2
- package/src/templates/workspace-core/.agents/skills/frontend-design/references/visual-direction.md +99 -0
- package/src/templates/workspace-core/AGENTS.md +3 -0
- package/src/templates/workspace-core/DESIGN.md +35 -0
- package/src/templates/workspace-root/AGENTS.md +3 -0
- package/src/templates/workspace-root/DESIGN.md +35 -0
- package/src/templates/workspace-root/agent-native.json +9 -0
- package/src/templates/workspace-root/package.json +3 -0
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
import { and, asc, eq, inArray, isNull } from "drizzle-orm";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
import { schema } from "../server/db/index.js";
|
|
7
|
+
import {
|
|
8
|
+
DOCUMENT_PROPERTY_VISIBILITIES,
|
|
9
|
+
normalizePropertyValue,
|
|
10
|
+
serializePropertyOptions,
|
|
11
|
+
} from "../shared/properties.js";
|
|
12
|
+
import { chunks } from "./_batch-utils.js";
|
|
13
|
+
|
|
14
|
+
const propertyType = z.enum(["text", "url", "date", "multi_select"]);
|
|
15
|
+
const option = z.object({
|
|
16
|
+
id: z.string().min(1),
|
|
17
|
+
name: z.string().min(1),
|
|
18
|
+
color: z.enum([
|
|
19
|
+
"gray",
|
|
20
|
+
"brown",
|
|
21
|
+
"orange",
|
|
22
|
+
"yellow",
|
|
23
|
+
"green",
|
|
24
|
+
"blue",
|
|
25
|
+
"purple",
|
|
26
|
+
"pink",
|
|
27
|
+
"red",
|
|
28
|
+
]),
|
|
29
|
+
});
|
|
30
|
+
export const migrationPlanSchema = z.object({
|
|
31
|
+
databaseId: z.string().min(1),
|
|
32
|
+
databaseDocumentId: z.string().min(1),
|
|
33
|
+
idempotencyKey: z.string().min(1).max(200),
|
|
34
|
+
expectedRowCount: z.number().int().min(1).max(100),
|
|
35
|
+
propertyDefinitions: z
|
|
36
|
+
.array(
|
|
37
|
+
z.object({
|
|
38
|
+
id: z.string().min(1),
|
|
39
|
+
name: z.string().min(1),
|
|
40
|
+
type: propertyType,
|
|
41
|
+
visibility: z.enum(DOCUMENT_PROPERTY_VISIBILITIES),
|
|
42
|
+
options: z.array(option).max(100).optional(),
|
|
43
|
+
}),
|
|
44
|
+
)
|
|
45
|
+
.max(100),
|
|
46
|
+
rows: z
|
|
47
|
+
.array(
|
|
48
|
+
z.object({
|
|
49
|
+
itemId: z.string().min(1),
|
|
50
|
+
documentId: z.string().min(1),
|
|
51
|
+
expectedUpdatedAt: z.string().min(1),
|
|
52
|
+
content: z.string(),
|
|
53
|
+
propertyValues: z.array(
|
|
54
|
+
z.object({ propertyId: z.string().min(1), value: z.unknown() }),
|
|
55
|
+
),
|
|
56
|
+
protectedPropertyValues: z
|
|
57
|
+
.array(
|
|
58
|
+
z.object({ propertyId: z.string().min(1), valueJson: z.string() }),
|
|
59
|
+
)
|
|
60
|
+
.max(100),
|
|
61
|
+
}),
|
|
62
|
+
)
|
|
63
|
+
.max(100),
|
|
64
|
+
legacyPropertyIds: z.array(z.string().min(1)).max(100).default([]),
|
|
65
|
+
});
|
|
66
|
+
export type MigrationPlan = z.infer<typeof migrationPlanSchema>;
|
|
67
|
+
|
|
68
|
+
export function canonical(value: unknown): string {
|
|
69
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
70
|
+
if (value && typeof value === "object")
|
|
71
|
+
return `{${Object.entries(value as Record<string, unknown>)
|
|
72
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
73
|
+
.map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`)
|
|
74
|
+
.join(",")}}`;
|
|
75
|
+
return JSON.stringify(value);
|
|
76
|
+
}
|
|
77
|
+
export const digest = (value: unknown) =>
|
|
78
|
+
createHash("sha256").update(canonical(value)).digest("hex");
|
|
79
|
+
export const deterministicId = (prefix: string, ...parts: string[]) =>
|
|
80
|
+
`${prefix}_${digest(parts).slice(0, 28)}`;
|
|
81
|
+
|
|
82
|
+
function duplicate(values: string[]) {
|
|
83
|
+
return values.length !== new Set(values).size;
|
|
84
|
+
}
|
|
85
|
+
function valueId(documentId: string, propertyId: string) {
|
|
86
|
+
return deterministicId("migration_value", documentId, propertyId);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function snapshotMigration(tx: any, databaseId: string) {
|
|
90
|
+
const [database] = await tx
|
|
91
|
+
.select()
|
|
92
|
+
.from(schema.contentDatabases)
|
|
93
|
+
.where(
|
|
94
|
+
and(
|
|
95
|
+
eq(schema.contentDatabases.id, databaseId),
|
|
96
|
+
isNull(schema.contentDatabases.deletedAt),
|
|
97
|
+
),
|
|
98
|
+
);
|
|
99
|
+
if (!database) throw new Error("Database not found.");
|
|
100
|
+
const [databaseDocument] = await tx
|
|
101
|
+
.select()
|
|
102
|
+
.from(schema.documents)
|
|
103
|
+
.where(
|
|
104
|
+
and(
|
|
105
|
+
eq(schema.documents.id, database.documentId),
|
|
106
|
+
eq(schema.documents.ownerEmail, database.ownerEmail),
|
|
107
|
+
database.orgId
|
|
108
|
+
? eq(schema.documents.orgId, database.orgId)
|
|
109
|
+
: isNull(schema.documents.orgId),
|
|
110
|
+
),
|
|
111
|
+
);
|
|
112
|
+
if (!databaseDocument)
|
|
113
|
+
throw new Error("Database backing document not found.");
|
|
114
|
+
const rows = await tx
|
|
115
|
+
.select({ item: schema.contentDatabaseItems, document: schema.documents })
|
|
116
|
+
.from(schema.contentDatabaseItems)
|
|
117
|
+
.innerJoin(
|
|
118
|
+
schema.documents,
|
|
119
|
+
eq(schema.documents.id, schema.contentDatabaseItems.documentId),
|
|
120
|
+
)
|
|
121
|
+
.where(
|
|
122
|
+
and(
|
|
123
|
+
eq(schema.contentDatabaseItems.databaseId, databaseId),
|
|
124
|
+
isNull(schema.documents.trashedAt),
|
|
125
|
+
),
|
|
126
|
+
)
|
|
127
|
+
.orderBy(
|
|
128
|
+
asc(schema.contentDatabaseItems.position),
|
|
129
|
+
asc(schema.contentDatabaseItems.id),
|
|
130
|
+
);
|
|
131
|
+
const definitions = await tx
|
|
132
|
+
.select()
|
|
133
|
+
.from(schema.documentPropertyDefinitions)
|
|
134
|
+
.where(eq(schema.documentPropertyDefinitions.databaseId, databaseId))
|
|
135
|
+
.orderBy(
|
|
136
|
+
asc(schema.documentPropertyDefinitions.position),
|
|
137
|
+
asc(schema.documentPropertyDefinitions.id),
|
|
138
|
+
);
|
|
139
|
+
const values = rows.length
|
|
140
|
+
? await tx
|
|
141
|
+
.select()
|
|
142
|
+
.from(schema.documentPropertyValues)
|
|
143
|
+
.where(
|
|
144
|
+
inArray(
|
|
145
|
+
schema.documentPropertyValues.documentId,
|
|
146
|
+
rows.map((r: any) => r.document.id),
|
|
147
|
+
),
|
|
148
|
+
)
|
|
149
|
+
.orderBy(
|
|
150
|
+
asc(schema.documentPropertyValues.documentId),
|
|
151
|
+
asc(schema.documentPropertyValues.propertyId),
|
|
152
|
+
asc(schema.documentPropertyValues.id),
|
|
153
|
+
)
|
|
154
|
+
: [];
|
|
155
|
+
const documentIds = [
|
|
156
|
+
database.documentId,
|
|
157
|
+
...rows.map((r: any) => r.document.id),
|
|
158
|
+
];
|
|
159
|
+
const shares = await tx
|
|
160
|
+
.select()
|
|
161
|
+
.from(schema.documentShares)
|
|
162
|
+
.where(inArray(schema.documentShares.resourceId, documentIds))
|
|
163
|
+
.orderBy(
|
|
164
|
+
asc(schema.documentShares.resourceId),
|
|
165
|
+
asc(schema.documentShares.principalType),
|
|
166
|
+
asc(schema.documentShares.principalId),
|
|
167
|
+
asc(schema.documentShares.role),
|
|
168
|
+
asc(schema.documentShares.id),
|
|
169
|
+
);
|
|
170
|
+
const sourceFields = await tx
|
|
171
|
+
.select()
|
|
172
|
+
.from(schema.contentDatabaseSourceFields)
|
|
173
|
+
.where(
|
|
174
|
+
inArray(
|
|
175
|
+
schema.contentDatabaseSourceFields.propertyId,
|
|
176
|
+
definitions.map((definition: any) => definition.id),
|
|
177
|
+
),
|
|
178
|
+
)
|
|
179
|
+
.orderBy(asc(schema.contentDatabaseSourceFields.id));
|
|
180
|
+
const sources = await tx
|
|
181
|
+
.select({ id: schema.contentDatabaseSources.id })
|
|
182
|
+
.from(schema.contentDatabaseSources)
|
|
183
|
+
.where(eq(schema.contentDatabaseSources.databaseId, databaseId))
|
|
184
|
+
.orderBy(asc(schema.contentDatabaseSources.id));
|
|
185
|
+
return {
|
|
186
|
+
database,
|
|
187
|
+
databaseDocument,
|
|
188
|
+
rows,
|
|
189
|
+
definitions,
|
|
190
|
+
values,
|
|
191
|
+
shares,
|
|
192
|
+
sourceFields,
|
|
193
|
+
sources,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function validatePlan(
|
|
198
|
+
plan: MigrationPlan,
|
|
199
|
+
snapshot: Awaited<ReturnType<typeof snapshotMigration>>,
|
|
200
|
+
options: { checkTimestamps?: boolean } = {},
|
|
201
|
+
) {
|
|
202
|
+
if (
|
|
203
|
+
plan.databaseId !== snapshot.database.id ||
|
|
204
|
+
plan.databaseDocumentId !== snapshot.database.documentId
|
|
205
|
+
)
|
|
206
|
+
throw new Error(
|
|
207
|
+
"Plan database identity does not match the active database.",
|
|
208
|
+
);
|
|
209
|
+
if (snapshot.database.systemRole || snapshot.sources.length > 0)
|
|
210
|
+
throw new Error(
|
|
211
|
+
"Migration requires an ordinary database that is not mapped to a source.",
|
|
212
|
+
);
|
|
213
|
+
if (
|
|
214
|
+
plan.rows.length !== plan.expectedRowCount ||
|
|
215
|
+
snapshot.rows.length !== plan.expectedRowCount
|
|
216
|
+
)
|
|
217
|
+
throw new Error(
|
|
218
|
+
"Migration must include the exact full set of active database rows.",
|
|
219
|
+
);
|
|
220
|
+
if (
|
|
221
|
+
duplicate(plan.rows.map((r) => r.itemId)) ||
|
|
222
|
+
duplicate(plan.rows.map((r) => r.documentId))
|
|
223
|
+
)
|
|
224
|
+
throw new Error("Migration rows must be unique.");
|
|
225
|
+
const actual = new Set(
|
|
226
|
+
snapshot.rows.map((r: any) => `${r.item.id}:${r.document.id}`),
|
|
227
|
+
);
|
|
228
|
+
if (plan.rows.some((r) => !actual.has(`${r.itemId}:${r.documentId}`)))
|
|
229
|
+
throw new Error("Migration contains a missing or foreign database row.");
|
|
230
|
+
if (duplicate(plan.propertyDefinitions.map((p) => p.id)))
|
|
231
|
+
throw new Error("New property definition IDs must be unique.");
|
|
232
|
+
const names = plan.propertyDefinitions.map((p) =>
|
|
233
|
+
p.name.trim().toLocaleLowerCase(),
|
|
234
|
+
);
|
|
235
|
+
if (duplicate(names))
|
|
236
|
+
throw new Error("New property definition names must be unique.");
|
|
237
|
+
const existingIds = new Set(snapshot.definitions.map((p: any) => p.id));
|
|
238
|
+
const existingNames = new Set(
|
|
239
|
+
snapshot.definitions.map((p: any) => p.name.trim().toLocaleLowerCase()),
|
|
240
|
+
);
|
|
241
|
+
for (const definition of plan.propertyDefinitions) {
|
|
242
|
+
if (
|
|
243
|
+
existingIds.has(definition.id) ||
|
|
244
|
+
existingNames.has(definition.name.trim().toLocaleLowerCase())
|
|
245
|
+
)
|
|
246
|
+
throw new Error(
|
|
247
|
+
"New property definition collides with an existing definition.",
|
|
248
|
+
);
|
|
249
|
+
if (definition.type === "multi_select") {
|
|
250
|
+
if (
|
|
251
|
+
!definition.options ||
|
|
252
|
+
duplicate(definition.options.map((o) => o.id)) ||
|
|
253
|
+
duplicate(
|
|
254
|
+
definition.options.map((o) => o.name.trim().toLocaleLowerCase()),
|
|
255
|
+
)
|
|
256
|
+
)
|
|
257
|
+
throw new Error(
|
|
258
|
+
"Multi-select properties require unique stable option IDs and labels.",
|
|
259
|
+
);
|
|
260
|
+
} else if (definition.options?.length)
|
|
261
|
+
throw new Error("Only multi-select properties may declare options.");
|
|
262
|
+
}
|
|
263
|
+
const newDefs = new Map(plan.propertyDefinitions.map((p) => [p.id, p]));
|
|
264
|
+
const oldDefs = new Map<string, any>(
|
|
265
|
+
snapshot.definitions.map((p: any) => [p.id, p]),
|
|
266
|
+
);
|
|
267
|
+
if (duplicate(plan.legacyPropertyIds))
|
|
268
|
+
throw new Error("Legacy property IDs must be unique.");
|
|
269
|
+
for (const propertyId of plan.legacyPropertyIds) {
|
|
270
|
+
const definition = oldDefs.get(propertyId);
|
|
271
|
+
if (!definition || definition.systemRole || definition.type === "blocks")
|
|
272
|
+
throw new Error("Legacy property is missing or unsafe to finalize.");
|
|
273
|
+
if (
|
|
274
|
+
snapshot.sourceFields.some(
|
|
275
|
+
(field: any) => field.propertyId === propertyId,
|
|
276
|
+
)
|
|
277
|
+
)
|
|
278
|
+
throw new Error(
|
|
279
|
+
"Legacy properties mapped to a source cannot be migrated.",
|
|
280
|
+
);
|
|
281
|
+
if (newDefs.has(propertyId))
|
|
282
|
+
throw new Error("Legacy properties cannot be newly created properties.");
|
|
283
|
+
}
|
|
284
|
+
for (const row of plan.rows) {
|
|
285
|
+
const persisted = snapshot.rows.find(
|
|
286
|
+
(candidate: any) => candidate.item.id === row.itemId,
|
|
287
|
+
)!;
|
|
288
|
+
if (
|
|
289
|
+
options.checkTimestamps !== false &&
|
|
290
|
+
persisted.document.updatedAt !== row.expectedUpdatedAt
|
|
291
|
+
)
|
|
292
|
+
throw new Error(`Stale row ${row.documentId}.`);
|
|
293
|
+
if (
|
|
294
|
+
duplicate(row.propertyValues.map((v) => v.propertyId)) ||
|
|
295
|
+
duplicate(row.protectedPropertyValues.map((v) => v.propertyId))
|
|
296
|
+
)
|
|
297
|
+
throw new Error("Row property values must be unique.");
|
|
298
|
+
if (row.propertyValues.length !== newDefs.size)
|
|
299
|
+
throw new Error(
|
|
300
|
+
"Every row must contain every new property exactly once.",
|
|
301
|
+
);
|
|
302
|
+
for (const v of row.propertyValues) {
|
|
303
|
+
const definition = newDefs.get(v.propertyId);
|
|
304
|
+
if (!definition)
|
|
305
|
+
throw new Error("Only newly declared properties may be written.");
|
|
306
|
+
normalizeMigrationValue(definition, v.value);
|
|
307
|
+
}
|
|
308
|
+
for (const protectedValue of row.protectedPropertyValues) {
|
|
309
|
+
const definition = oldDefs.get(protectedValue.propertyId);
|
|
310
|
+
if (
|
|
311
|
+
!definition ||
|
|
312
|
+
definition.systemRole ||
|
|
313
|
+
definition.type === "blocks" ||
|
|
314
|
+
[
|
|
315
|
+
"formula",
|
|
316
|
+
"rollup",
|
|
317
|
+
"id",
|
|
318
|
+
"created_time",
|
|
319
|
+
"created_by",
|
|
320
|
+
"last_edited_time",
|
|
321
|
+
"last_edited_by",
|
|
322
|
+
].includes(definition.type)
|
|
323
|
+
)
|
|
324
|
+
throw new Error("Unsafe protected property target.");
|
|
325
|
+
const persistedValue =
|
|
326
|
+
snapshot.values.find(
|
|
327
|
+
(v: any) =>
|
|
328
|
+
v.documentId === row.documentId &&
|
|
329
|
+
v.propertyId === protectedValue.propertyId,
|
|
330
|
+
)?.valueJson ?? "null";
|
|
331
|
+
if (persistedValue !== protectedValue.valueJson)
|
|
332
|
+
throw new Error(
|
|
333
|
+
"Protected property values no longer match persisted values.",
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export function normalizeMigrationValue(
|
|
340
|
+
definition: MigrationPlan["propertyDefinitions"][number],
|
|
341
|
+
value: unknown,
|
|
342
|
+
) {
|
|
343
|
+
if (definition.type === "multi_select") {
|
|
344
|
+
if (!Array.isArray(value) || value.some((id) => typeof id !== "string"))
|
|
345
|
+
throw new Error(`Unknown multi-select option for ${definition.name}.`);
|
|
346
|
+
if (
|
|
347
|
+
duplicate(value) ||
|
|
348
|
+
value.some((id) => !definition.options!.some((o) => o.id === id))
|
|
349
|
+
)
|
|
350
|
+
throw new Error(`Unknown multi-select option for ${definition.name}.`);
|
|
351
|
+
return value;
|
|
352
|
+
}
|
|
353
|
+
const normalized = normalizePropertyValue(definition.type, value);
|
|
354
|
+
if (definition.type === "text" && typeof normalized !== "string")
|
|
355
|
+
throw new Error(`Text property ${definition.name} must be a string.`);
|
|
356
|
+
if (definition.type === "url") {
|
|
357
|
+
if (typeof normalized !== "string")
|
|
358
|
+
throw new Error(`URL property ${definition.name} must be a string.`);
|
|
359
|
+
try {
|
|
360
|
+
const url = new URL(normalized);
|
|
361
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
362
|
+
throw new Error();
|
|
363
|
+
} catch {
|
|
364
|
+
throw new Error(
|
|
365
|
+
`URL property ${definition.name} must be an http/https URL.`,
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
if (definition.type === "date" && normalized === null)
|
|
370
|
+
throw new Error(`Date property ${definition.name} cannot be null.`);
|
|
371
|
+
return normalized;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export function serializeMigrationValue(
|
|
375
|
+
definition: MigrationPlan["propertyDefinitions"][number],
|
|
376
|
+
value: unknown,
|
|
377
|
+
) {
|
|
378
|
+
return JSON.stringify(normalizeMigrationValue(definition, value));
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export function snapshotDigest(
|
|
382
|
+
snapshot: Awaited<ReturnType<typeof snapshotMigration>>,
|
|
383
|
+
) {
|
|
384
|
+
const document = (value: any) => ({
|
|
385
|
+
id: value.id,
|
|
386
|
+
title: value.title,
|
|
387
|
+
content: value.content,
|
|
388
|
+
parentId: value.parentId,
|
|
389
|
+
ownerEmail: value.ownerEmail,
|
|
390
|
+
orgId: value.orgId,
|
|
391
|
+
spaceId: value.spaceId,
|
|
392
|
+
visibility: value.visibility,
|
|
393
|
+
hideFromSearch: value.hideFromSearch,
|
|
394
|
+
trashedAt: value.trashedAt,
|
|
395
|
+
position: value.position,
|
|
396
|
+
});
|
|
397
|
+
return digest({
|
|
398
|
+
database: {
|
|
399
|
+
id: snapshot.database.id,
|
|
400
|
+
documentId: snapshot.database.documentId,
|
|
401
|
+
ownerEmail: snapshot.database.ownerEmail,
|
|
402
|
+
orgId: snapshot.database.orgId,
|
|
403
|
+
spaceId: snapshot.database.spaceId,
|
|
404
|
+
deletedAt: snapshot.database.deletedAt,
|
|
405
|
+
},
|
|
406
|
+
databaseDocument: document(snapshot.databaseDocument),
|
|
407
|
+
rows: snapshot.rows.map((row: any) => ({
|
|
408
|
+
item: {
|
|
409
|
+
id: row.item.id,
|
|
410
|
+
databaseId: row.item.databaseId,
|
|
411
|
+
documentId: row.item.documentId,
|
|
412
|
+
ownerEmail: row.item.ownerEmail,
|
|
413
|
+
orgId: row.item.orgId,
|
|
414
|
+
position: row.item.position,
|
|
415
|
+
},
|
|
416
|
+
document: document(row.document),
|
|
417
|
+
})),
|
|
418
|
+
definitions: snapshot.definitions.map((definition: any) => ({
|
|
419
|
+
id: definition.id,
|
|
420
|
+
databaseId: definition.databaseId,
|
|
421
|
+
ownerEmail: definition.ownerEmail,
|
|
422
|
+
orgId: definition.orgId,
|
|
423
|
+
systemRole: definition.systemRole,
|
|
424
|
+
name: definition.name,
|
|
425
|
+
type: definition.type,
|
|
426
|
+
description: definition.description,
|
|
427
|
+
visibility: definition.visibility,
|
|
428
|
+
optionsJson: definition.optionsJson,
|
|
429
|
+
position: definition.position,
|
|
430
|
+
})),
|
|
431
|
+
values: snapshot.values.map((value: any) => ({
|
|
432
|
+
id: value.id,
|
|
433
|
+
ownerEmail: value.ownerEmail,
|
|
434
|
+
documentId: value.documentId,
|
|
435
|
+
propertyId: value.propertyId,
|
|
436
|
+
valueJson: value.valueJson,
|
|
437
|
+
})),
|
|
438
|
+
shares: snapshot.shares.map((share: any) => ({
|
|
439
|
+
id: share.id,
|
|
440
|
+
resourceId: share.resourceId,
|
|
441
|
+
principalType: share.principalType,
|
|
442
|
+
principalId: share.principalId,
|
|
443
|
+
role: share.role,
|
|
444
|
+
})),
|
|
445
|
+
sourceFields: snapshot.sourceFields.map((field: any) => ({
|
|
446
|
+
id: field.id,
|
|
447
|
+
ownerEmail: field.ownerEmail,
|
|
448
|
+
sourceId: field.sourceId,
|
|
449
|
+
propertyId: field.propertyId,
|
|
450
|
+
localFieldKey: field.localFieldKey,
|
|
451
|
+
sourceFieldKey: field.sourceFieldKey,
|
|
452
|
+
sourceFieldLabel: field.sourceFieldLabel,
|
|
453
|
+
sourceFieldType: field.sourceFieldType,
|
|
454
|
+
mappingType: field.mappingType,
|
|
455
|
+
writeOwner: field.writeOwner,
|
|
456
|
+
readOnly: field.readOnly,
|
|
457
|
+
provenance: field.provenance,
|
|
458
|
+
freshness: field.freshness,
|
|
459
|
+
})),
|
|
460
|
+
sources: snapshot.sources,
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
export async function applyMigration(
|
|
465
|
+
tx: any,
|
|
466
|
+
plan: MigrationPlan,
|
|
467
|
+
snapshot: Awaited<ReturnType<typeof snapshotMigration>>,
|
|
468
|
+
receiptId: string,
|
|
469
|
+
now: string,
|
|
470
|
+
) {
|
|
471
|
+
const versions: Array<{
|
|
472
|
+
documentId: string;
|
|
473
|
+
versionId: string;
|
|
474
|
+
appliedUpdatedAt: string;
|
|
475
|
+
}> = [];
|
|
476
|
+
const versionRows: Array<typeof schema.documentVersions.$inferInsert> = [];
|
|
477
|
+
for (const row of plan.rows) {
|
|
478
|
+
const persisted = snapshot.rows.find(
|
|
479
|
+
(candidate: any) => candidate.item.id === row.itemId,
|
|
480
|
+
)!;
|
|
481
|
+
const versionId = deterministicId(
|
|
482
|
+
"migration_version",
|
|
483
|
+
receiptId,
|
|
484
|
+
row.documentId,
|
|
485
|
+
);
|
|
486
|
+
versions.push({
|
|
487
|
+
documentId: row.documentId,
|
|
488
|
+
versionId,
|
|
489
|
+
appliedUpdatedAt: now,
|
|
490
|
+
});
|
|
491
|
+
versionRows.push({
|
|
492
|
+
id: versionId,
|
|
493
|
+
ownerEmail: persisted.document.ownerEmail,
|
|
494
|
+
documentId: row.documentId,
|
|
495
|
+
title: persisted.document.title,
|
|
496
|
+
content: persisted.document.content,
|
|
497
|
+
createdAt: now,
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
for (const batch of chunks(versionRows, 100))
|
|
501
|
+
await tx.insert(schema.documentVersions).values(batch);
|
|
502
|
+
for (const row of plan.rows) {
|
|
503
|
+
const updated = await tx
|
|
504
|
+
.update(schema.documents)
|
|
505
|
+
.set({ content: row.content, updatedAt: now })
|
|
506
|
+
.where(
|
|
507
|
+
and(
|
|
508
|
+
eq(schema.documents.id, row.documentId),
|
|
509
|
+
eq(schema.documents.updatedAt, row.expectedUpdatedAt),
|
|
510
|
+
),
|
|
511
|
+
)
|
|
512
|
+
.returning({ id: schema.documents.id });
|
|
513
|
+
if (updated.length !== 1) throw new Error(`Stale row ${row.documentId}.`);
|
|
514
|
+
}
|
|
515
|
+
const definitionRows = plan.propertyDefinitions.map((definition, index) => ({
|
|
516
|
+
id: definition.id,
|
|
517
|
+
ownerEmail: snapshot.database.ownerEmail,
|
|
518
|
+
orgId: snapshot.database.orgId,
|
|
519
|
+
databaseId: plan.databaseId,
|
|
520
|
+
name: definition.name.trim(),
|
|
521
|
+
type: definition.type,
|
|
522
|
+
visibility: definition.visibility,
|
|
523
|
+
optionsJson: serializePropertyOptions(
|
|
524
|
+
definition.type === "multi_select" ? { options: definition.options } : {},
|
|
525
|
+
),
|
|
526
|
+
position:
|
|
527
|
+
Math.max(-1, ...snapshot.definitions.map((item: any) => item.position)) +
|
|
528
|
+
1 +
|
|
529
|
+
index,
|
|
530
|
+
createdAt: now,
|
|
531
|
+
updatedAt: now,
|
|
532
|
+
}));
|
|
533
|
+
for (const batch of chunks(definitionRows, 100))
|
|
534
|
+
await tx.insert(schema.documentPropertyDefinitions).values(batch);
|
|
535
|
+
const definitionById = new Map(
|
|
536
|
+
plan.propertyDefinitions.map((definition) => [definition.id, definition]),
|
|
537
|
+
);
|
|
538
|
+
const valueRows: Array<typeof schema.documentPropertyValues.$inferInsert> =
|
|
539
|
+
[];
|
|
540
|
+
for (const row of plan.rows) {
|
|
541
|
+
const persisted = snapshot.rows.find(
|
|
542
|
+
(candidate: any) => candidate.item.id === row.itemId,
|
|
543
|
+
)!;
|
|
544
|
+
for (const entry of row.propertyValues)
|
|
545
|
+
valueRows.push({
|
|
546
|
+
id: valueId(row.documentId, entry.propertyId),
|
|
547
|
+
ownerEmail: persisted.document.ownerEmail,
|
|
548
|
+
documentId: row.documentId,
|
|
549
|
+
propertyId: entry.propertyId,
|
|
550
|
+
valueJson: serializeMigrationValue(
|
|
551
|
+
definitionById.get(entry.propertyId)!,
|
|
552
|
+
entry.value,
|
|
553
|
+
),
|
|
554
|
+
createdAt: now,
|
|
555
|
+
updatedAt: now,
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
for (const batch of chunks(valueRows, 100))
|
|
559
|
+
await tx.insert(schema.documentPropertyValues).values(batch);
|
|
560
|
+
if (plan.rows.length || plan.propertyDefinitions.length)
|
|
561
|
+
await tx
|
|
562
|
+
.update(schema.contentDatabases)
|
|
563
|
+
.set({ updatedAt: now })
|
|
564
|
+
.where(eq(schema.contentDatabases.id, plan.databaseId));
|
|
565
|
+
return {
|
|
566
|
+
versions,
|
|
567
|
+
createdPropertyIds: plan.propertyDefinitions.map((p) => p.id),
|
|
568
|
+
};
|
|
569
|
+
}
|