@agent-native/core 0.79.11 → 0.79.15
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 +25 -0
- package/corpus/core/docs/content/locales/zh-TW/a2a-protocol.md +68 -68
- package/corpus/core/docs/content/locales/zh-TW/actions.md +82 -82
- package/corpus/core/docs/content/locales/zh-TW/agent-mentions.md +22 -22
- package/corpus/core/docs/content/locales/zh-TW/agent-surfaces.md +82 -82
- package/corpus/core/docs/content/locales/zh-TW/agent-teams.md +29 -29
- package/corpus/core/docs/content/locales/zh-TW/agent-web-surfaces.md +11 -11
- package/corpus/core/docs/content/locales/zh-TW/audit-log.md +16 -16
- package/corpus/core/docs/content/locales/zh-TW/authentication.md +32 -32
- package/corpus/core/docs/content/locales/zh-TW/automations.md +32 -32
- package/corpus/core/docs/content/locales/zh-TW/blueprint-installer.md +19 -19
- package/corpus/core/docs/content/locales/zh-TW/cli-adapters.md +17 -17
- package/corpus/core/docs/content/locales/zh-TW/client.md +62 -62
- package/corpus/core/docs/content/locales/zh-TW/cloneable-saas.md +32 -32
- package/corpus/core/docs/content/locales/zh-TW/code-agents-ui.md +91 -91
- package/corpus/core/docs/content/locales/zh-TW/components.md +51 -51
- package/corpus/core/docs/content/locales/zh-TW/context-awareness.md +66 -66
- package/corpus/core/docs/content/locales/zh-TW/creating-templates.md +39 -39
- package/corpus/core/docs/content/locales/zh-TW/cross-app-sso.md +29 -29
- package/corpus/core/docs/content/locales/zh-TW/database.md +21 -21
- package/corpus/core/docs/content/locales/zh-TW/deployment.md +37 -37
- package/corpus/core/docs/content/locales/zh-TW/dispatch.md +43 -43
- package/corpus/core/docs/content/locales/zh-TW/drop-in-agent.md +34 -34
- package/corpus/core/docs/content/locales/zh-TW/durable-resume.md +18 -18
- package/corpus/core/docs/content/locales/zh-TW/embedding-sdk.md +73 -73
- package/corpus/core/docs/content/locales/zh-TW/evals.md +16 -16
- package/corpus/core/docs/content/locales/zh-TW/extensions.md +81 -81
- package/corpus/core/docs/content/locales/zh-TW/external-agents.md +146 -146
- package/corpus/core/docs/content/locales/zh-TW/faq.md +43 -43
- package/corpus/core/docs/content/locales/zh-TW/file-uploads.md +11 -11
- package/corpus/core/docs/content/locales/zh-TW/frames.md +33 -33
- package/corpus/core/docs/content/locales/zh-TW/getting-started.md +28 -28
- package/corpus/core/docs/content/locales/zh-TW/harness-agents.md +78 -78
- package/corpus/core/docs/content/locales/zh-TW/human-approval.md +27 -27
- package/corpus/core/docs/content/locales/zh-TW/internationalization.md +19 -19
- package/corpus/core/docs/content/locales/zh-TW/key-concepts.md +68 -68
- package/corpus/core/docs/content/locales/zh-TW/local-file-mode.md +50 -50
- package/corpus/core/docs/content/locales/zh-TW/mcp-apps.md +38 -38
- package/corpus/core/docs/content/locales/zh-TW/mcp-clients.md +67 -67
- package/corpus/core/docs/content/locales/zh-TW/mcp-protocol.md +50 -50
- package/corpus/core/docs/content/locales/zh-TW/messaging.md +99 -99
- package/corpus/core/docs/content/locales/zh-TW/migration-workbench.md +6 -6
- package/corpus/core/docs/content/locales/zh-TW/multi-app-workspace.md +39 -39
- package/corpus/core/docs/content/locales/zh-TW/multi-tenancy.md +7 -7
- package/corpus/core/docs/content/locales/zh-TW/native-chat-ui.md +38 -38
- package/corpus/core/docs/content/locales/zh-TW/notifications.md +23 -23
- package/corpus/core/docs/content/locales/zh-TW/observability.md +49 -49
- package/corpus/core/docs/content/locales/zh-TW/observational-memory.md +23 -23
- package/corpus/core/docs/content/locales/zh-TW/onboarding.md +40 -40
- package/corpus/core/docs/content/locales/zh-TW/plan-plugin.md +37 -37
- package/corpus/core/docs/content/locales/zh-TW/pr-visual-recap.md +72 -72
- package/corpus/core/docs/content/locales/zh-TW/processors.md +17 -17
- package/corpus/core/docs/content/locales/zh-TW/progress.md +15 -15
- package/corpus/core/docs/content/locales/zh-TW/pure-agent-apps.md +10 -10
- package/corpus/core/docs/content/locales/zh-TW/real-time-collaboration.md +103 -103
- package/corpus/core/docs/content/locales/zh-TW/recurring-jobs.md +19 -19
- package/corpus/core/docs/content/locales/zh-TW/routing.md +9 -9
- package/corpus/core/docs/content/locales/zh-TW/sandbox-adapters.md +48 -48
- package/corpus/core/docs/content/locales/zh-TW/security.md +49 -49
- package/corpus/core/docs/content/locales/zh-TW/server.md +47 -47
- package/corpus/core/docs/content/locales/zh-TW/sharing.md +22 -22
- package/corpus/core/docs/content/locales/zh-TW/skills-guide.md +46 -46
- package/corpus/core/docs/content/locales/zh-TW/template-analytics.md +40 -40
- package/corpus/core/docs/content/locales/zh-TW/template-assets.md +69 -69
- package/corpus/core/docs/content/locales/zh-TW/template-brain.md +81 -81
- package/corpus/core/docs/content/locales/zh-TW/template-calendar.md +40 -40
- package/corpus/core/docs/content/locales/zh-TW/template-chat.md +27 -27
- package/corpus/core/docs/content/locales/zh-TW/template-clips.md +85 -85
- package/corpus/core/docs/content/locales/zh-TW/template-content.md +65 -66
- package/corpus/core/docs/content/locales/zh-TW/template-design.md +29 -29
- package/corpus/core/docs/content/locales/zh-TW/template-dispatch.md +51 -51
- package/corpus/core/docs/content/locales/zh-TW/template-forms.md +25 -25
- package/corpus/core/docs/content/locales/zh-TW/template-mail.md +71 -71
- package/corpus/core/docs/content/locales/zh-TW/template-plan.md +92 -92
- package/corpus/core/docs/content/locales/zh-TW/template-slides.md +52 -52
- package/corpus/core/docs/content/locales/zh-TW/template-videos.md +30 -30
- package/corpus/core/docs/content/locales/zh-TW/tracking.md +29 -29
- package/corpus/core/docs/content/locales/zh-TW/using-your-agent.md +18 -18
- package/corpus/core/docs/content/locales/zh-TW/voice-input.md +19 -19
- package/corpus/core/docs/content/locales/zh-TW/what-is-agent-native.md +61 -61
- package/corpus/core/docs/content/locales/zh-TW/workspace-connections.md +41 -41
- package/corpus/core/docs/content/locales/zh-TW/workspace-management.md +27 -27
- package/corpus/core/docs/content/locales/zh-TW/workspace.md +58 -58
- package/corpus/core/docs/content/locales/zh-TW/writing-agent-instructions.md +41 -41
- package/corpus/core/docs/content/template-clips.md +48 -2
- package/corpus/core/package.json +2 -1
- package/corpus/core/src/client/AgentPanel.tsx +27 -3
- package/corpus/core/src/deploy/build.ts +738 -57
- package/corpus/core/src/deploy/route-discovery.ts +1 -1
- package/corpus/core/src/server/edge.ts +50 -0
- package/corpus/core/src/styles/agent-native.css +93 -0
- package/corpus/core/src/templates/default/app/i18n/zh-TW.ts +44 -44
- package/corpus/core/src/vite/client.ts +1 -0
- package/corpus/templates/analytics/app/components/layout/Layout.tsx +5 -3
- package/corpus/templates/analytics/app/i18n/zh-TW.ts +69 -70
- package/corpus/templates/analytics/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
- package/corpus/templates/assets/app/components/layout/Layout.tsx +3 -3
- package/corpus/templates/assets/app/i18n/zh-TW.ts +82 -82
- package/corpus/templates/assets/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
- package/corpus/templates/brain/app/components/layout/Layout.tsx +6 -4
- package/corpus/templates/brain/app/i18n/zh-TW.ts +90 -90
- package/corpus/templates/brain/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
- package/corpus/templates/calendar/app/components/layout/AppLayout.tsx +1 -1
- package/corpus/templates/calendar/app/components/layout/Sidebar.tsx +1 -1
- package/corpus/templates/calendar/app/i18n/zh-TW.ts +57 -57
- package/corpus/templates/calendar/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
- package/corpus/templates/calendar/server/lib/booking-og-fonts.ts +20 -6
- package/corpus/templates/calendar/server/lib/booking-og-image.ts +17 -9
- package/corpus/templates/chat/app/components/layout/Layout.tsx +5 -3
- package/corpus/templates/chat/app/i18n/zh-TW.ts +3 -3
- package/corpus/templates/chat/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
- package/corpus/templates/clips/AGENTS.md +6 -0
- package/corpus/templates/clips/actions/delete-recording-permanent.ts +7 -1
- package/corpus/templates/clips/actions/get-recording-player-data.ts +44 -2
- package/corpus/templates/clips/actions/navigate.ts +2 -0
- package/corpus/templates/clips/actions/save-bug-report-context.ts +173 -0
- package/corpus/templates/clips/actions/view-screen.ts +58 -7
- package/corpus/templates/clips/app/components/recorder/storage-setup-card.tsx +9 -3
- package/corpus/templates/clips/app/hooks/use-navigation-state.ts +17 -0
- package/corpus/templates/clips/app/i18n/ar-SA.ts +31 -0
- package/corpus/templates/clips/app/i18n/de-DE.ts +32 -0
- package/corpus/templates/clips/app/i18n/en-US.ts +32 -0
- package/corpus/templates/clips/app/i18n/es-ES.ts +32 -0
- package/corpus/templates/clips/app/i18n/fr-FR.ts +32 -0
- package/corpus/templates/clips/app/i18n/hi-IN.ts +32 -0
- package/corpus/templates/clips/app/i18n/ja-JP.ts +31 -0
- package/corpus/templates/clips/app/i18n/ko-KR.ts +32 -0
- package/corpus/templates/clips/app/i18n/pt-BR.ts +32 -0
- package/corpus/templates/clips/app/i18n/zh-CN.ts +30 -0
- package/corpus/templates/clips/app/i18n/zh-TW.ts +461 -451
- package/corpus/templates/clips/app/routes/bug-report.done.tsx +126 -0
- package/corpus/templates/clips/app/routes/bug-report.tsx +222 -0
- package/corpus/templates/clips/app/routes/record.tsx +104 -12
- package/corpus/templates/clips/changelog/2026-06-26-brief-network-blips-no-longer-block-recording-or-wrongly-pro.md +6 -0
- package/corpus/templates/clips/changelog/2026-06-26-bug-report-recordings-can-keep-redacted-host-app-context-wit.md +6 -0
- package/corpus/templates/clips/changelog/2026-06-26-bug-report-widgets-can-launch-clips-recordings-from-embedded.md +6 -0
- package/corpus/templates/clips/changelog/2026-06-26-desktop-recording-keeps-connected-users-out-of-the-storage-s.md +6 -0
- package/corpus/templates/clips/changelog/2026-06-26-if-a-recording-can-t-be-uploaded-the-chrome-extension-now-sa.md +6 -0
- package/corpus/templates/clips/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
- package/corpus/templates/clips/chrome-extension/public/manifest.json +9 -2
- package/corpus/templates/clips/chrome-extension/src/background.ts +43 -0
- package/corpus/templates/clips/chrome-extension/src/offscreen.ts +111 -6
- package/corpus/templates/clips/chrome-extension/src/popup.ts +18 -7
- package/corpus/templates/clips/desktop/src/app.tsx +53 -19
- package/corpus/templates/clips/server/db/schema.ts +26 -0
- package/corpus/templates/clips/server/lib/public-agent-context.ts +51 -0
- package/corpus/templates/clips/server/plugins/auth.ts +1 -0
- package/corpus/templates/clips/server/plugins/db.ts +28 -0
- package/corpus/templates/clips/server/routes/api/agent-context.json.get.ts +4 -1
- package/corpus/templates/clips/shared/bug-report.ts +161 -0
- package/corpus/templates/content/app/components/layout/Layout.tsx +10 -8
- package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +1 -1
- package/corpus/templates/content/app/i18n/zh-TW.ts +67 -66
- package/corpus/templates/content/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
- package/corpus/templates/design/app/components/layout/Layout.tsx +3 -3
- package/corpus/templates/design/app/i18n/zh-TW.ts +44 -44
- package/corpus/templates/design/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
- package/corpus/templates/dispatch/app/i18n/zh-TW.ts +5 -4
- package/corpus/templates/dispatch/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
- package/corpus/templates/forms/app/components/layout/Layout.tsx +4 -2
- package/corpus/templates/forms/app/components/layout/Sidebar.tsx +1 -1
- package/corpus/templates/forms/app/i18n/zh-TW.ts +48 -48
- package/corpus/templates/forms/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
- package/corpus/templates/macros/app/components/layout/AppLayout.tsx +3 -3
- package/corpus/templates/macros/app/i18n/zh-TW.ts +5 -5
- package/corpus/templates/macros/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
- package/corpus/templates/mail/app/i18n/zh-TW.ts +83 -83
- package/corpus/templates/mail/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
- package/corpus/templates/plan/app/components/layout/Layout.tsx +5 -3
- package/corpus/templates/plan/app/i18n/zh-TW.ts +69 -69
- package/corpus/templates/plan/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
- package/corpus/templates/slides/app/components/layout/Layout.tsx +3 -3
- package/corpus/templates/slides/app/i18n/zh-TW.ts +64 -64
- package/corpus/templates/slides/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
- package/corpus/templates/videos/app/components/layout/Layout.tsx +2 -2
- package/corpus/templates/videos/app/i18n/zh-TW.ts +54 -54
- package/corpus/templates/videos/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
- package/dist/client/AgentPanel.d.ts.map +1 -1
- package/dist/client/AgentPanel.js +14 -4
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/collab/routes.d.ts +1 -1
- package/dist/deploy/build.d.ts +29 -2
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +587 -51
- package/dist/deploy/build.js.map +1 -1
- package/dist/deploy/route-discovery.d.ts +1 -1
- package/dist/deploy/route-discovery.js +1 -1
- package/dist/deploy/route-discovery.js.map +1 -1
- package/dist/file-upload/actions/upload-image.d.ts +2 -2
- package/dist/notifications/routes.d.ts +2 -2
- package/dist/observability/routes.d.ts +7 -7
- package/dist/resources/handlers.d.ts +2 -2
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/dist/server/edge.d.ts +11 -0
- package/dist/server/edge.d.ts.map +1 -0
- package/dist/server/edge.js +11 -0
- package/dist/server/edge.js.map +1 -0
- package/dist/styles/agent-native.css +93 -0
- package/dist/templates/default/app/i18n/zh-TW.ts +44 -44
- package/dist/vite/client.d.ts.map +1 -1
- package/dist/vite/client.js +1 -0
- package/dist/vite/client.js.map +1 -1
- package/docs/content/locales/zh-TW/a2a-protocol.md +68 -68
- package/docs/content/locales/zh-TW/actions.md +82 -82
- package/docs/content/locales/zh-TW/agent-mentions.md +22 -22
- package/docs/content/locales/zh-TW/agent-surfaces.md +82 -82
- package/docs/content/locales/zh-TW/agent-teams.md +29 -29
- package/docs/content/locales/zh-TW/agent-web-surfaces.md +11 -11
- package/docs/content/locales/zh-TW/audit-log.md +16 -16
- package/docs/content/locales/zh-TW/authentication.md +32 -32
- package/docs/content/locales/zh-TW/automations.md +32 -32
- package/docs/content/locales/zh-TW/blueprint-installer.md +19 -19
- package/docs/content/locales/zh-TW/cli-adapters.md +17 -17
- package/docs/content/locales/zh-TW/client.md +62 -62
- package/docs/content/locales/zh-TW/cloneable-saas.md +32 -32
- package/docs/content/locales/zh-TW/code-agents-ui.md +91 -91
- package/docs/content/locales/zh-TW/components.md +51 -51
- package/docs/content/locales/zh-TW/context-awareness.md +66 -66
- package/docs/content/locales/zh-TW/creating-templates.md +39 -39
- package/docs/content/locales/zh-TW/cross-app-sso.md +29 -29
- package/docs/content/locales/zh-TW/database.md +21 -21
- package/docs/content/locales/zh-TW/deployment.md +37 -37
- package/docs/content/locales/zh-TW/dispatch.md +43 -43
- package/docs/content/locales/zh-TW/drop-in-agent.md +34 -34
- package/docs/content/locales/zh-TW/durable-resume.md +18 -18
- package/docs/content/locales/zh-TW/embedding-sdk.md +73 -73
- package/docs/content/locales/zh-TW/evals.md +16 -16
- package/docs/content/locales/zh-TW/extensions.md +81 -81
- package/docs/content/locales/zh-TW/external-agents.md +146 -146
- package/docs/content/locales/zh-TW/faq.md +43 -43
- package/docs/content/locales/zh-TW/file-uploads.md +11 -11
- package/docs/content/locales/zh-TW/frames.md +33 -33
- package/docs/content/locales/zh-TW/getting-started.md +28 -28
- package/docs/content/locales/zh-TW/harness-agents.md +78 -78
- package/docs/content/locales/zh-TW/human-approval.md +27 -27
- package/docs/content/locales/zh-TW/internationalization.md +19 -19
- package/docs/content/locales/zh-TW/key-concepts.md +68 -68
- package/docs/content/locales/zh-TW/local-file-mode.md +50 -50
- package/docs/content/locales/zh-TW/mcp-apps.md +38 -38
- package/docs/content/locales/zh-TW/mcp-clients.md +67 -67
- package/docs/content/locales/zh-TW/mcp-protocol.md +50 -50
- package/docs/content/locales/zh-TW/messaging.md +99 -99
- package/docs/content/locales/zh-TW/migration-workbench.md +6 -6
- package/docs/content/locales/zh-TW/multi-app-workspace.md +39 -39
- package/docs/content/locales/zh-TW/multi-tenancy.md +7 -7
- package/docs/content/locales/zh-TW/native-chat-ui.md +38 -38
- package/docs/content/locales/zh-TW/notifications.md +23 -23
- package/docs/content/locales/zh-TW/observability.md +49 -49
- package/docs/content/locales/zh-TW/observational-memory.md +23 -23
- package/docs/content/locales/zh-TW/onboarding.md +40 -40
- package/docs/content/locales/zh-TW/plan-plugin.md +37 -37
- package/docs/content/locales/zh-TW/pr-visual-recap.md +72 -72
- package/docs/content/locales/zh-TW/processors.md +17 -17
- package/docs/content/locales/zh-TW/progress.md +15 -15
- package/docs/content/locales/zh-TW/pure-agent-apps.md +10 -10
- package/docs/content/locales/zh-TW/real-time-collaboration.md +103 -103
- package/docs/content/locales/zh-TW/recurring-jobs.md +19 -19
- package/docs/content/locales/zh-TW/routing.md +9 -9
- package/docs/content/locales/zh-TW/sandbox-adapters.md +48 -48
- package/docs/content/locales/zh-TW/security.md +49 -49
- package/docs/content/locales/zh-TW/server.md +47 -47
- package/docs/content/locales/zh-TW/sharing.md +22 -22
- package/docs/content/locales/zh-TW/skills-guide.md +46 -46
- package/docs/content/locales/zh-TW/template-analytics.md +40 -40
- package/docs/content/locales/zh-TW/template-assets.md +69 -69
- package/docs/content/locales/zh-TW/template-brain.md +81 -81
- package/docs/content/locales/zh-TW/template-calendar.md +40 -40
- package/docs/content/locales/zh-TW/template-chat.md +27 -27
- package/docs/content/locales/zh-TW/template-clips.md +85 -85
- package/docs/content/locales/zh-TW/template-content.md +65 -66
- package/docs/content/locales/zh-TW/template-design.md +29 -29
- package/docs/content/locales/zh-TW/template-dispatch.md +51 -51
- package/docs/content/locales/zh-TW/template-forms.md +25 -25
- package/docs/content/locales/zh-TW/template-mail.md +71 -71
- package/docs/content/locales/zh-TW/template-plan.md +92 -92
- package/docs/content/locales/zh-TW/template-slides.md +52 -52
- package/docs/content/locales/zh-TW/template-videos.md +30 -30
- package/docs/content/locales/zh-TW/tracking.md +29 -29
- package/docs/content/locales/zh-TW/using-your-agent.md +18 -18
- package/docs/content/locales/zh-TW/voice-input.md +19 -19
- package/docs/content/locales/zh-TW/what-is-agent-native.md +61 -61
- package/docs/content/locales/zh-TW/workspace-connections.md +41 -41
- package/docs/content/locales/zh-TW/workspace-management.md +27 -27
- package/docs/content/locales/zh-TW/workspace.md +58 -58
- package/docs/content/locales/zh-TW/writing-agent-instructions.md +41 -41
- package/docs/content/template-clips.md +48 -2
- package/package.json +2 -1
- package/src/templates/default/app/i18n/zh-TW.ts +44 -44
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "建立範本"
|
|
3
|
-
description: "
|
|
3
|
+
description: "如何建立和發布您自己的 Agent-Native 應用範本。"
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# 建立範本
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
範本是完整的、可分叉的 Agent-Native 應用程式,可解決實際工作流程。第一方範本使用您使用的相同框架表面建置:用於 UI 的 React 路由、用於資料的 Drizzle SQL、用於操作的 actions、用於代理行為的工作區資源以及輪詢同步,以便代理和 UI 保持一致。
|
|
9
9
|
|
|
10
10
|
一個好的範本:
|
|
11
11
|
|
|
12
12
|
- 使用有用的種子資料或空狀態流端對端地解決一個工作流。
|
|
13
|
-
-
|
|
13
|
+
- 將持久狀態儲存在 SQL 中,而不是 JSON 檔案中。
|
|
14
14
|
- 將應用操作定義為 `defineAction()` actions。
|
|
15
|
-
-
|
|
15
|
+
- 透過應用程式狀態公開導覽和選取。
|
|
16
16
|
- 為不明顯的工作流程提供清晰的 `AGENTS.md` 和重點 skills。
|
|
17
17
|
- 註冊所需提供者和機密的加入步驟。
|
|
18
18
|
- 作為獨立應用和多應用工作區的一部分工作。
|
|
@@ -31,7 +31,7 @@ npx @agent-native/core@latest create my-template --template chat --standalone
|
|
|
31
31
|
npx @agent-native/core@latest create my-platform
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
聊天為您提供驗證、持久聊天對話串、SQL 支援的資源、工具、應用程式狀態、actions 和輪詢同步。您新增域模型和產品 UI。
|
|
35
35
|
|
|
36
36
|
如果您尚未建置可重複使用的 UI 範本,請使用 [Getting Started](/docs/getting-started#1-create-your-app) 中的無頭入口:定義一個操作,使用 `pnpm agent` 執行它,並在工作流程需要耐用表面時新增 UI。
|
|
37
37
|
|
|
@@ -63,20 +63,20 @@ npx @agent-native/core@latest create my-platform
|
|
|
63
63
|
}
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
不要為應用程式狀態新增 `data/` 目錄。持久應用資料屬於 SQL,UI
|
|
66
|
+
不要為應用程式狀態新增 `data/` 目錄。持久應用資料屬於 SQL,UI 透過 actions 或型別化伺服器處理常式讀取它。
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
每個範本的四個區域透過一個共用操作介面和一個 SQL 資料庫連線在一起 - 代理和 UI 是執行相同操作的平等合作伙伴:
|
|
69
69
|
|
|
70
|
-
```an-diagram title="範本的四個區域如何連線" summary="UI
|
|
70
|
+
```an-diagram title="範本的四個區域如何連線" summary="UI 和代理都透過相同的操作到達 SQL;應用程式狀態和輪詢同步使它們保持一致。"
|
|
71
71
|
{
|
|
72
|
-
"html": "<div class=\"diagram-tmpl\"><div class=\"diagram-col\"><div class=\"diagram-node\">React 介面<br><small class=\"diagram-muted\">app/routes · 元件</small></div><div class=\"diagram-node\">Agent<br><small class=\"diagram-muted\">AGENTS.md · skills</small></div></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><div class=\"diagram-panel center\"><span class=\"diagram-pill accent\">行動</span><small class=\"diagram-muted\">defineAction()</small></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><div class=\"diagram-box\" data-rough
|
|
72
|
+
"html": "<div class=\"diagram-tmpl\"><div class=\"diagram-col\"><div class=\"diagram-node\">React 介面<br><small class=\"diagram-muted\">app/routes · 元件</small></div><div class=\"diagram-node\">Agent<br><small class=\"diagram-muted\">AGENTS.md · skills</small></div></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><div class=\"diagram-panel center\"><span class=\"diagram-pill accent\">行動</span><small class=\"diagram-muted\">defineAction()</small></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><div class=\"diagram-box\" data-rough>透過 Drizzle 使用 SQL<br><small class=\"diagram-muted\">additive schema</small></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">↻</div><div class=\"diagram-pill ok\">輪詢ing sync</div></div>",
|
|
73
73
|
"css": ".diagram-tmpl{display:flex;align-items:center;gap:12px;flex-wrap:wrap}.diagram-tmpl .diagram-col{display:flex;flex-direction:column;gap:10px}.diagram-tmpl .diagram-arrow{font-size:22px;line-height:1}.diagram-tmpl .center{display:flex;flex-direction:column;align-items:center;gap:4px}"
|
|
74
74
|
}
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
## SQL中的模型資料 {#data-models}
|
|
77
|
+
## SQL 中的模型資料 {#data-models}
|
|
78
78
|
|
|
79
|
-
使用框架 Drizzle
|
|
79
|
+
使用框架 Drizzle 幫助程式定義域表,以便架構在 SQLite、Postgres、D1、Turso、Supabase、Neon 和其他支援的後端之間保持可移植性:
|
|
80
80
|
|
|
81
81
|
```ts
|
|
82
82
|
// server/db/schema.ts
|
|
@@ -106,9 +106,9 @@ export const projects = table("projects", {
|
|
|
106
106
|
export const projectShares = createSharesTable("project_shares");
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
-
架構更改必須是附加的。 `server/plugins/db.ts
|
|
109
|
+
架構更改必須是附加的。 `server/plugins/db.ts`中透過`runMigrations()`新增表和列;切勿使用破壞性的 SQL、`drizzle-kit push`、表重新命名或列刪除。
|
|
110
110
|
|
|
111
|
-
對於應用程式讀取和寫入,請使用 Drizzle 的查詢生成器和 `drizzle-orm` 的可移植運算符。當Drizzle可以表達查詢時,不要使用原始SQL編寫產品程式碼,並且不要在範本中從`drizzle-orm/sqlite-core`或`drizzle-orm/pg-core`匯入。
|
|
111
|
+
對於應用程式讀取和寫入,請使用 Drizzle 的查詢生成器和 `drizzle-orm` 的可移植運算符。當 Drizzle 可以表達查詢時,不要使用原始 SQL 編寫產品程式碼,並且不要在範本中從`drizzle-orm/sqlite-core`或`drizzle-orm/pg-core`匯入。
|
|
112
112
|
|
|
113
113
|
```ts
|
|
114
114
|
// server/plugins/db.ts
|
|
@@ -139,7 +139,7 @@ export default runMigrations(
|
|
|
139
139
|
|
|
140
140
|
## 將操作定義為行動 {#actions}
|
|
141
141
|
|
|
142
|
-
行動
|
|
142
|
+
行動 是應用行為的單一事實來源。代理將它們作為工具呼叫,前端透過鉤子呼叫它們,其他應用程式可以透過 MCP/A2A 存取它們。
|
|
143
143
|
|
|
144
144
|
```an-annotated-code title="actions/create-project.ts"
|
|
145
145
|
{
|
|
@@ -148,18 +148,18 @@ export default runMigrations(
|
|
|
148
148
|
"code": "import { defineAction } from \"@agent-native/core/action\";\nimport { getDb } from \"../server/db/index.js\";\nimport { nanoid } from \"nanoid\";\nimport { z } from \"zod\";\nimport * as schema from \"../server/db/schema\";\n\nexport default defineAction({\n description: \"Create a project.\",\n schema: z.object({\n title: z.string().min(1).describe(\"Project title\"),\n }),\n run: async ({ title }, ctx) => {\n const db = getDb();\n const id = nanoid();\n await db.insert(schema.projects).values({\n id,\n title,\n ownerEmail: ctx.userEmail,\n orgId: ctx.orgId,\n });\n return { id, title };\n },\n});",
|
|
149
149
|
"annotations": [
|
|
150
150
|
{ "lines": "2", "note": "`getDb` is created per app via `createGetDb(schema)` in `server/db/index.ts`." },
|
|
151
|
-
{ "lines": "8", "label": "工具表面", "note": "`description`
|
|
151
|
+
{ "lines": "8", "label": "工具表面", "note": "`description` 是代理讀取的內容,以決定何時將此操作作為工具呼叫。" },
|
|
152
152
|
{ "lines": "9-11", "label": "型別化契約", "note": "一個 zod `schema` 會驗證來自代理、UI、HTTP、MCP 和 A2A 的輸入。" },
|
|
153
153
|
{ "lines": "18-19", "label": "範圍寫入", "note": "從 `ctx` 標記 `ownerEmail` / `orgId`,以便該行正確地確定共用和存取檢查的範圍。" }
|
|
154
154
|
]
|
|
155
155
|
}
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
-
使用 `http: { method: "GET" }` 或 `readOnly: true` 表示唯讀 actions。僅將 `parallelSafe: true` 用於變異 actions,這些 actions
|
|
158
|
+
使用 `http: { method: "GET" }` 或 `readOnly: true` 表示唯讀 actions。僅將 `parallelSafe: true` 用於變異 actions,這些 actions 可以安全地與同輪工具呼叫同時執行。將 `toolCallable: false` 用於不應從沙盒工具執行的高爆炸半徑 actions。
|
|
159
159
|
|
|
160
160
|
## 建置 UI {#ui}
|
|
161
161
|
|
|
162
|
-
路由位於 `app/routes/` 中並使用 React Router v8
|
|
162
|
+
路由位於 `app/routes/` 中並使用 React Router v8 檔案路由。透過actions或 API 處理常式查詢資料,並預設使突變樂觀。
|
|
163
163
|
|
|
164
164
|
```tsx
|
|
165
165
|
import { useActionMutation, useActionQuery } from "@agent-native/core/client";
|
|
@@ -176,7 +176,7 @@ export default function ProjectsPage() {
|
|
|
176
176
|
}
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
-
在應用程式 shell
|
|
179
|
+
在應用程式 shell 附近連線一次即時同步,以便在代理、另一個分頁或操作更改資料時重新整理 React 查詢快取:
|
|
180
180
|
|
|
181
181
|
```tsx
|
|
182
182
|
import { useDbSync } from "@agent-native/core/client";
|
|
@@ -189,7 +189,7 @@ export function AppSync() {
|
|
|
189
189
|
}
|
|
190
190
|
```
|
|
191
191
|
|
|
192
|
-
|
|
192
|
+
**Agent-Native 承諾:代理寫入顯示在 UI 中,無需手動重新整理。** `useActionQuery` 是簡單路徑 - 當變異操作發出 `source: "action"` 時,每個鉤子都會重新取得。如果您使用自訂金鑰(例如,讀取整合狀態的低階用戶端幫助程式)取得原始 `useQuery`,請將每個來源計數器折疊到 queryKey 中以進行有針對性的重新整理:
|
|
193
193
|
|
|
194
194
|
```tsx
|
|
195
195
|
import { useChangeVersions } from "@agent-native/core/client";
|
|
@@ -202,14 +202,14 @@ useQuery({
|
|
|
202
202
|
});
|
|
203
203
|
```
|
|
204
204
|
|
|
205
|
-
常見來源:`"action"`(每個成功的代理操作 - 可靠的後備)、`"app-state"`、`"settings"
|
|
205
|
+
常見來源:`"action"`(每個成功的代理操作 - 可靠的後備)、`"app-state"`、`"settings"`,以及您的商店透過 `recordChange` 發出的任何自訂資源來源。完整模式請參見 `real-time-sync` 技能。
|
|
206
206
|
|
|
207
207
|
## 新增應用程式狀態 {#application-state}
|
|
208
208
|
|
|
209
209
|
應用程式狀態是代理如何了解使用者所看到的內容。至少新增:
|
|
210
210
|
|
|
211
211
|
- 一個 UI 鉤子,當路由、所選紀錄、活動分頁或編輯器選取發生更改時,它會寫入語義 `navigation` 狀態。
|
|
212
|
-
-
|
|
212
|
+
- 讀取該狀態並返回目前螢幕截圖的 `view-screen` 操作。
|
|
213
213
|
- 一個 `navigate` 操作,寫入一次性 `navigate` 指令以供 UI 使用。
|
|
214
214
|
|
|
215
215
|
使用 `useAgentRouteState` 作為 UI 掛鉤,以便應用程式狀態寫入、分頁範圍指令讀取、讀取後刪除和重複指令保護保持一致:
|
|
@@ -232,7 +232,7 @@ export function useNavigationState() {
|
|
|
232
232
|
}
|
|
233
233
|
```
|
|
234
234
|
|
|
235
|
-
在 URL 查詢參數中保留可共用過濾器。框架將它們公開為 `<current-url>`
|
|
235
|
+
在 URL 查詢參數中保留可共用過濾器。框架將它們公開為 `<current-url>` 代理,內建代理可以使用 `set-search-params` 更改它們; `navigation` 應儲存語義 ID 和別名,而不是完整查詢字串的第二個副本。
|
|
236
236
|
|
|
237
237
|
對於應用導覽,首選包含同來源的 `navigate` 指令
|
|
238
238
|
`path`(當 URL 已知時)。同一動作不要寫為 `__set_url__`;
|
|
@@ -262,14 +262,14 @@ export default defineAction({
|
|
|
262
262
|
|
|
263
263
|
## 謹慎使用 API 路由 {#api-routes}
|
|
264
264
|
|
|
265
|
-
首選 actions 進行應用操作。僅為無法幹淨地成為 actions 的表面建立自訂 Nitro
|
|
265
|
+
首選 actions 進行應用操作。僅為無法幹淨地成為 actions 的表面建立自訂 Nitro 路由:
|
|
266
266
|
|
|
267
267
|
- 檔案上傳或二進制流。
|
|
268
268
|
- 公開匿名頁面和webhooks。
|
|
269
|
-
- OAuth
|
|
269
|
+
- OAuth 回呼和特定於提供者的協議處理常式。
|
|
270
270
|
- 伺服器渲染的公開內容。
|
|
271
271
|
|
|
272
|
-
|
|
272
|
+
在使用存取助手之前,接觸可擁有資料的自訂路由必須呼叫 `getSession(event)` 並將資料庫工作包裝在 `runWithRequestContext({ userEmail, orgId }, fn)` 中。
|
|
273
273
|
|
|
274
274
|
## 編寫代理指令 {#write-agents-md}
|
|
275
275
|
|
|
@@ -284,7 +284,7 @@ One workspace for projects, tasks, and notes.
|
|
|
284
284
|
|
|
285
285
|
## 核心規則
|
|
286
286
|
|
|
287
|
-
- Data lives in
|
|
287
|
+
- Data lives in 透過 Drizzle 使用 SQL. Use actions for all writes; schema is additive.
|
|
288
288
|
- Use `view-screen` before acting on "this project" if the screen is unclear.
|
|
289
289
|
|
|
290
290
|
## 應用狀態
|
|
@@ -300,15 +300,15 @@ One workspace for projects, tasks, and notes.
|
|
|
300
300
|
| `create-project` | Create a project |
|
|
301
301
|
```
|
|
302
302
|
|
|
303
|
-
|
|
303
|
+
每當新增新操作、路由、狀態鍵或重複操作時更新 `AGENTS.md`
|
|
304
304
|
工作流程。 [Writing Agent Instructions](/docs/writing-agent-instructions) 是
|
|
305
|
-
完整指南 - 如何保持 `AGENTS.md`
|
|
305
|
+
完整指南 - 如何保持 `AGENTS.md` 可略讀,這四個分別屬於什麼
|
|
306
306
|
指導面,以及如何表達技能和工具描述,以便代理
|
|
307
307
|
可靠地觸發它們。
|
|
308
308
|
|
|
309
309
|
## 新增Skills {#skills}
|
|
310
310
|
|
|
311
|
-
使用 skills
|
|
311
|
+
使用 skills 來取得會使 `AGENTS.md` 膨脹的詳細模式:特定於提供者的 API、匯入/匯出格式、複雜的編輯流程或域術語。
|
|
312
312
|
|
|
313
313
|
```markdown
|
|
314
314
|
---
|
|
@@ -327,7 +327,7 @@ Use this skill when the user uploads a legacy project CSV.
|
|
|
327
327
|
- Save rejected rows as a note attached to the import summary.
|
|
328
328
|
```
|
|
329
329
|
|
|
330
|
-
將範本 skills
|
|
330
|
+
將範本 skills 儲存在 `.agents/skills/<name>/SKILL.md` 中。如果使用者應該能夠在執行時編輯指南,也可以透過工作區資源來顯示它。
|
|
331
331
|
|
|
332
332
|
## 註冊設定步驟 {#onboarding}
|
|
333
333
|
|
|
@@ -370,23 +370,23 @@ export default defineNitroPlugin(() => {
|
|
|
370
370
|
|
|
371
371
|
清單:
|
|
372
372
|
|
|
373
|
-
-
|
|
373
|
+
- 透過框架代理聊天外掛或 `mountA2A()` 掛載 A2A,以便同級應用程式可以呼叫您的代理。
|
|
374
374
|
- 保持代理卡描述足夠具體,以便 Dispatch 準確地安排工作。
|
|
375
375
|
- 註冊所需的機密/加入,以便設定出現在側欄中,並且 Dispatch 可以管理共用憑證。
|
|
376
376
|
- 將橫切指令保留在工作區 `AGENTS.md` 或工作區資源中,而不是複製到每個應用程式中。
|
|
377
|
-
-
|
|
377
|
+
- 對所有可擁有的資源使用共用/存取幫助程式,以便組織範圍內的工作空間保持隔離。
|
|
378
378
|
|
|
379
379
|
## 發布範本 {#publishing}
|
|
380
380
|
|
|
381
381
|
分享之前:
|
|
382
382
|
|
|
383
383
|
1. 執行 `pnpm install`、`pnpm typecheck` 和範本的測試。
|
|
384
|
-
2.
|
|
384
|
+
2. 驗證其是否可以在未設定可選提供者金鑰的情況下正常工作。
|
|
385
385
|
3. 檢查驗證、共用和兩個使用者資料隔離。
|
|
386
386
|
4. 紀錄所需的環境變數和入門步驟。
|
|
387
|
-
5.
|
|
387
|
+
5. 透過附加遷移包含範例或種子行,而不是跟蹤的執行時資料檔案。
|
|
388
388
|
|
|
389
|
-
可以從 GitHub
|
|
389
|
+
可以從 GitHub 儲存庫建立社群範本:
|
|
390
390
|
|
|
391
391
|
```bash
|
|
392
392
|
npx @agent-native/core@latest create my-app --template github:user/repo
|
|
@@ -398,14 +398,14 @@ npx @agent-native/core@latest create my-app --template github:user/repo
|
|
|
398
398
|
|
|
399
399
|
當您在框架 monorepo 中工作並需要生成時
|
|
400
400
|
工作區使用未發布的包或範本更改,使用
|
|
401
|
-
|
|
401
|
+
本機包標誌:
|
|
402
402
|
|
|
403
403
|
```bash
|
|
404
404
|
AGENT_NATIVE_CREATE_USE_LOCAL_CORE=1 pnpm --filter @agent-native/core create my-platform
|
|
405
405
|
```
|
|
406
406
|
|
|
407
|
-
|
|
408
|
-
`@agent-native/dispatch`
|
|
407
|
+
產生的工作空間連結本機`@agent-native/core`和
|
|
408
|
+
`@agent-native/dispatch` 套件,因此更改為 Core API、Dispatch 工作區
|
|
409
409
|
可以在發布之前測試行為或第一方範本。包裹
|
|
410
|
-
`prepack`
|
|
410
|
+
`prepack` 指令碼在連結之前建置 `dist`,這會保留產生的
|
|
411
411
|
工作空間指向目前建置輸出。
|
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "跨應用SSO"
|
|
3
|
-
description: "使用 Dispatch
|
|
2
|
+
title: "跨應用 SSO"
|
|
3
|
+
description: "使用 Dispatch 作為身分授權,透過身分聯合在每個託管 Agent-Native 應用程式中登入一次 - 每個應用程式選取加入,可透過單一環境變數進行逆轉。"
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# 跨應用SSO
|
|
6
|
+
# 跨應用 SSO
|
|
7
7
|
|
|
8
|
-
`*.agent-native.com`
|
|
8
|
+
`*.agent-native.com` 上的每個託管應用程式都使用其**自己的獨立使用者儲存**執行自己的部署。 `mail.agent-native.com`和`calendar.agent-native.com`不共用資料庫、工作階段表或cookie域。因此,“登入一次,使用每個應用程式”不能是共用 cookie — 它必須是**身分聯合**,其中 [Dispatch](/docs/dispatch) 充當工作區的身分授權機構。
|
|
9
9
|
|
|
10
|
-
這與 [A2A](/docs/a2a-protocol) 和 [External Agents](/docs/external-agents) 已經使用的信任原語相同 - 在請求邊界驗證的 `A2A_SECRET` 簽名的 JWT -
|
|
10
|
+
這與 [A2A](/docs/a2a-protocol) 和 [External Agents](/docs/external-agents) 已經使用的信任原語相同 - 在請求邊界驗證的 `A2A_SECRET` 簽名的 JWT - 應用於人工登入路徑,而不是代理到代理的呼叫。
|
|
11
11
|
|
|
12
|
-
> **統一部署與每個域部署。** 如果您在一個來源(`your-agents.com/mail`、`your-agents.com/calendar
|
|
12
|
+
> **統一部署與每個域部署。** 如果您在一個來源(`your-agents.com/mail`、`your-agents.com/calendar`)託管所有應用程式,您已經透過單一 cookie 域獲得共用登入 - 無需聯合。僅當應用程式在不同的域上執行時,才需要跨應用程式 SSO。參見[Multi-App Workspaces — Unified deploy](/docs/multi-app-workspace#deployment)。
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## 什麼以及為什麼 {#what-why}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
每個應用程式的使用者儲存意味著瀏覽器 cookie 沒有一個可以被每個應用程式信任的地方。相反,聯合模型將一個應用程式命名為 **Dispatch** 作為身分授權機構。任何其他應用程式都可以委托“這個人是誰?”要調度,取回使用者已驗證電子郵件的短暫簽名斷言,然後**透過電子郵件將其連結到其自己的本機帳戶**。
|
|
17
17
|
|
|
18
18
|
連結規則故意狹窄和附加:
|
|
19
19
|
|
|
20
|
-
-
|
|
20
|
+
- **現有同一電子郵件使用者→連結。**本機帳戶與經過驗證的電子郵件匹配並按原樣重複使用。它**永遠不會被修改、重新命名或刪除** - 聯合層只會讀取它並為其建立一個工作階段。
|
|
21
21
|
- **新電子郵件 → 建立。** 為該經過驗證的電子郵件建立一個新的本機帳戶,然後建立一個正常的本機工作階段。
|
|
22
22
|
|
|
23
|
-
這使得部署安全,即使它會導致人們退出。 **預計會登出。**
|
|
23
|
+
這使得部署安全,即使它會導致人們退出。 **預計會登出。** 當應用程式開啟此功能時,現有工作階段將結束,並且使用者透過 Dispatch 重新進行驗證。但他們總是重新登入**同一個電子郵件匹配帳戶,所有資料都完好無損**,因為身分行只會*新增到* — 永遠不會被銷毀、重新命名或重新指向。
|
|
24
24
|
|
|
25
25
|
## 它是如何工作的 {#how-it-works}
|
|
26
26
|
|
|
27
27
|
該流程是標準授權 → 簽名權杖 → 回調重新導向,其中電子郵件是唯一跨越信任邊界的內容。
|
|
28
28
|
|
|
29
|
-
```an-diagram title="身分聯合流程" summary="Dispatch 對人員進行驗證,並返回一件事的短暫簽名斷言 -
|
|
29
|
+
```an-diagram title="身分聯合流程" summary="Dispatch 對人員進行驗證,並返回一件事的短暫簽名斷言 - 經過驗證的電子郵件。該應用程式透過電子郵件連結並建立自己的本機工作階段。"
|
|
30
30
|
{
|
|
31
|
-
"html": "<div class=\"diagram-sso\"><div class=\"diagram-card\" data-rough><strong>用戶端應用</strong><small class=\"diagram-muted\">own user store</small></div><div class=\"diagram-step\"><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><span class=\"diagram-pill\">authorize</span></div><div class=\"diagram-card\" data-rough><strong>Dispatch</strong><small class=\"diagram-muted\">identity authority</small><span class=\"diagram-pill accent\">authenticates human</span></div><div class=\"diagram-step\"><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><span class=\"diagram-pill accent\">302 + signed JWT</span></div><div class=\"diagram-card\" data-rough><strong>應用回調</strong><small class=\"diagram-muted\">verify signature · scope:identity · exp ≤ 2 min</small><span class=\"diagram-pill ok\"
|
|
31
|
+
"html": "<div class=\"diagram-sso\"><div class=\"diagram-card\" data-rough><strong>用戶端應用</strong><small class=\"diagram-muted\">own user store</small></div><div class=\"diagram-step\"><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><span class=\"diagram-pill\">authorize</span></div><div class=\"diagram-card\" data-rough><strong>Dispatch</strong><small class=\"diagram-muted\">identity authority</small><span class=\"diagram-pill accent\">authenticates human</span></div><div class=\"diagram-step\"><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><span class=\"diagram-pill accent\">302 + signed JWT</span></div><div class=\"diagram-card\" data-rough><strong>應用回調</strong><small class=\"diagram-muted\">verify signature · scope:identity · exp ≤ 2 min</small><span class=\"diagram-pill ok\">透過信箱即時關聯</span><span class=\"diagram-pill ok\">mint local session</span></div></div>",
|
|
32
32
|
"css": ".diagram-sso{display:flex;align-items:stretch;gap:12px;flex-wrap:wrap}.diagram-sso .diagram-card{display:flex;flex-direction:column;gap:6px;padding:14px 16px;min-width:150px}.diagram-sso .diagram-step{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px}.diagram-sso .diagram-arrow{font-size:22px;line-height:1}"
|
|
33
33
|
}
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
1.
|
|
36
|
+
1. **應用程式→調度(授權)。**應用程式將使用者傳送到身分授權機構:
|
|
37
37
|
|
|
38
38
|
```
|
|
39
39
|
GET https://dispatch.agent-native.com/_agent-native/identity/authorize
|
|
@@ -49,7 +49,7 @@ description: "使用 Dispatch 作為身分授權,通過身分聯合在每個
|
|
|
49
49
|
“summary”:“Dispatch(身分授權)對人員進行驗證並使用簽名的身分權杖重新導向回來”,
|
|
50
50
|
"auth": "調度工作階段(如果沒有則互動式登入)",
|
|
51
51
|
“參數”:[
|
|
52
|
-
{ "name": "app", "in": "query", "type": "string", "required": true, "description": "
|
|
52
|
+
{ "name": "app", "in": "query", "type": "string", "required": true, "description": "請求的應用程式識別碼。" },
|
|
53
53
|
{ "name": "redirect_uri", "in": "query", "type": "string", "required": true, "description": "應用程式回調 URL。根據嚴格的允許清單進行驗證(預設為 `\*.agent-native.com`或 localhost)。" },
|
|
54
54
|
{ "name": "state", "in": "query", "type": "string", "required": true, "description": "CSRF 狀態在重新導向上回顯。" }
|
|
55
55
|
],
|
|
@@ -63,20 +63,20 @@ description: "使用 Dispatch 作為身分授權,通過身分聯合在每個
|
|
|
63
63
|
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
2. **Dispatch 對人員進行驗證。** 如果使用者已有 Dispatch 工作階段,則這是透明的。如果沒有,Dispatch 將顯示其自己的正常登入資訊(電子郵件/密碼、Google 等 — 請參閱 [Authentication](/docs/authentication))。 Dispatch
|
|
66
|
+
2. **Dispatch 對人員進行驗證。** 如果使用者已有 Dispatch 工作階段,則這是透明的。如果沒有,Dispatch 將顯示其自己的正常登入資訊(電子郵件/密碼、Google 等 — 請參閱 [Authentication](/docs/authentication))。 Dispatch 只是一個一般的 Agent-Native 應用程式;它沒有執行特殊的驗證模式。
|
|
67
67
|
|
|
68
|
-
3. **調度→應用程式(簽名身分權杖)。**調度根據嚴格的允許清單驗證`redirect_uri`,並302重新導向回應用程式的`redirect_uri`,攜帶短暫的**`A2A_SECRET`簽名身分JWT**。權杖的聲明故意最小化:
|
|
68
|
+
3. **調度→應用程式(簽名身分權杖)。**調度根據嚴格的允許清單驗證`redirect_uri`,並302重新導向回應用程式的`redirect_uri`,攜帶短暫的**`A2A_SECRET`簽名身分 JWT**。權杖的聲明故意最小化:
|
|
69
69
|
|
|
70
70
|
| 聲明 | 含義 |
|
|
71
71
|
| ------------ | ------------------------------------------- |
|
|
72
72
|
| `sub` | 身分機構的穩定使用者ID |
|
|
73
73
|
| `email` | 使用者的**已驗證**電子郵件 - 唯一的加入金鑰 |
|
|
74
|
-
| `name` | 顯示名稱(非權威,僅適用於UI)
|
|
74
|
+
| `name` | 顯示名稱(非權威,僅適用於 UI) |
|
|
75
75
|
| `org_domain` | 工作空間/組織域(如果存在) |
|
|
76
76
|
| `scope` | 始終為 `"identity"` — 此權杖僅授權登入 |
|
|
77
77
|
| `exp` | **≤ 2 分鐘** 距問題 |
|
|
78
78
|
|
|
79
|
-
4.
|
|
79
|
+
4. **應用程式透過電子郵件驗證和 JIT 連結。**應用程式使用自己的 `A2A_SECRET` 驗證權杖簽名,檢查 `scope: "identity"` 和 `exp`,然後嚴格透過經過驗證的電子郵件執行**即時連結**:
|
|
80
80
|
- 如果具有該電子郵件地址的本機使用者存在 → 不加修改地重新使用它。
|
|
81
81
|
- 如果沒有 → 為該電子郵件建立本機使用者。
|
|
82
82
|
|
|
@@ -99,8 +99,8 @@ AGENT_NATIVE_IDENTITY_HUB_URL=https://dispatch.agent-native.com
|
|
|
99
99
|
|
|
100
100
|
- **短暫的簽名權杖。**身分斷言是 `A2A_SECRET` 簽名的 JWT,具有 **≤ 2 分鐘** 到期時間和 `scope: "identity"`。它授權單次登入,並且不能長時間重播或重新用於 API/A2A 存取。
|
|
101
101
|
- **嚴格的 `redirect_uri` 允許清單。** 預設情況下,調度僅重新導向到 `*.agent-native.com` 或本機主機。任意、方案相關 (`//host`) 和跨域重新導向目標都會被拒絕,因此權限無法轉變為開放重新導向或權杖滲透預言機。
|
|
102
|
-
-
|
|
103
|
-
-
|
|
102
|
+
- **從經過驗證的權杖僅透過電子郵件加入。** 跨越信任邊界的*唯一*事物是簽名權杖中經過驗證的電子郵件。該應用程式不接受來自線路的使用者 ID、角色、組織成員資格或任何特權狀態 - 它從匹配的帳戶在本機派生所有內容。
|
|
103
|
+
- **僅新增身分寫入。**連結可以不受影響地重複使用現有的同一電子郵件帳戶,也可以插入一個新帳戶。此路徑上不會發生任何身分行的更新、重新命名、重新指向或刪除。
|
|
104
104
|
- **預設情況下關閉。**如果取消設定 `AGENT_NATIVE_IDENTITY_HUB_URL`,則整個功能將處於惰性狀態。
|
|
105
105
|
|
|
106
106
|
```an-callout
|
|
@@ -114,7 +114,7 @@ AGENT_NATIVE_IDENTITY_HUB_URL=https://dispatch.agent-native.com
|
|
|
114
114
|
|
|
115
115
|
```an-diagram title="JIT-link 決定" summary="連結以經過驗證的電子郵件為關鍵,並且僅是附加的 - 現有帳戶不變地重複使用,新電子郵件建立新的本機使用者。"
|
|
116
116
|
{
|
|
117
|
-
"html": "<div class=\"diagram-jit\"><div class=\"diagram-node\" data-rough
|
|
117
|
+
"html": "<div class=\"diagram-jit\"><div class=\"diagram-node\" data-rough>已驗證信箱<br><small class=\"diagram-muted\">來自已簽名身分 JWT</small></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><div class=\"diagram-branch\"><div class=\"diagram-box\" data-rough>Local user exists?<span class=\"diagram-pill ok\">yes → reuse unchanged</span><span class=\"diagram-pill accent\">no → create local user</span></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><div class=\"diagram-box\" data-rough>簽發普通本機工作階段</div></div></div>",
|
|
118
118
|
"css": ".diagram-jit{display:flex;align-items:center;gap:12px;flex-wrap:wrap}.diagram-jit .diagram-node{display:flex;flex-direction:column;gap:4px;padding:12px 14px}.diagram-jit .diagram-branch{display:flex;align-items:center;gap:12px;flex-wrap:wrap}.diagram-jit .diagram-box{display:flex;flex-direction:column;gap:6px;padding:12px 14px}.diagram-jit .diagram-arrow{font-size:22px;line-height:1}"
|
|
119
119
|
}
|
|
120
120
|
```
|
|
@@ -127,17 +127,17 @@ AGENT_NATIVE_IDENTITY_HUB_URL=https://dispatch.agent-native.com
|
|
|
127
127
|
AGENT_NATIVE_IDENTITY_HUB_URL=https://dispatch.yourcompany.com
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
**重新導向允許清單。** 集線器(調度)在發出權杖之前驗證授權端點上的 `redirect_uri`。允許名單在`templates/dispatch/server/lib/identity-sso.ts`中設定:
|
|
131
131
|
|
|
132
132
|
- **預設值:** 僅 `*.agent-native.com` 和 localhost(`DEFAULT_ALLOWED_HOST_SUFFIXES` 常量)。
|
|
133
|
-
- **擴充功能它:**在 Dispatch 部署上設定 `IDENTITY_SSO_ALLOWED_HOST_SUFFIXES`
|
|
133
|
+
- **擴充功能它:**在 Dispatch 部署上設定 `IDENTITY_SSO_ALLOWED_HOST_SUFFIXES` 環境變數,並使用逗號分隔的其他主機後綴清單:
|
|
134
134
|
|
|
135
135
|
```bash
|
|
136
136
|
# 除預設值外還允許 yourcompany.com 子域
|
|
137
137
|
IDENTITY_SSO_ALLOWED_HOST_SUFFIXES=".yourcompany.com,.staging.yourcompany.com"
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
-
每個條目都被標準化為點前綴後綴 (`.yourcompany.com`),因此後綴檢查既足夠又最不容易發生 —
|
|
140
|
+
每個條目都被標準化為點前綴後綴 (`.yourcompany.com`),因此後綴檢查既足夠又最不容易發生 — 無需按應用程式清單保持同步。與所有內容匹配的條目(空或只是 `.`)將被過濾掉。
|
|
141
141
|
|
|
142
142
|
- 無論 `IDENTITY_SSO_ALLOWED_HOST_SUFFIXES` 為何,**Localhost** 始終允許本機開發用戶端應用程式。
|
|
143
143
|
|
|
@@ -145,7 +145,7 @@ AGENT_NATIVE_IDENTITY_HUB_URL=https://dispatch.yourcompany.com
|
|
|
145
145
|
|
|
146
146
|
## 金絲雀推出執行手冊 {#canary-rollout}
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
切換和回滾是**每個應用程式部署的單一環境變數**。一次推出一個應用程式,驗證,然後擴充功能。不要同時在每個應用程式上設定變數。
|
|
149
149
|
|
|
150
150
|
**1。部署程式碼——沒有行為改變。**
|
|
151
151
|
使用 `AGENT_NATIVE_IDENTITY_HUB_URL` **將版本發布到每個應用程式**到處都未設定\*\*。確認正常登入在幾個應用程式上仍然有效。
|
|
@@ -157,13 +157,13 @@ AGENT_NATIVE_IDENTITY_HUB_URL=https://dispatch.yourcompany.com
|
|
|
157
157
|
AGENT_NATIVE_IDENTITY_HUB_URL=https://dispatch.agent-native.com
|
|
158
158
|
```
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
保留所有其他應用程式的環境未設定。重新部署/重新啟動,以便它取得變數。
|
|
161
161
|
|
|
162
162
|
**3。驗證金絲雀(清單)。**
|
|
163
163
|
|
|
164
164
|
- 登出應用程式。
|
|
165
165
|
- 登入螢幕現在顯示**“使用 Agent-Native 登入”**。點選它。
|
|
166
|
-
- 您將進入 **Dispatch**
|
|
166
|
+
- 您將進入 **Dispatch** 並完成登入(如果已經登入,則直接透過)。
|
|
167
167
|
- 您將被重新導向**返回應用程式並登入** — 並且它是您之前擁有的**相同的現有帳戶**(同一電子郵件),而不是新帳戶。
|
|
168
168
|
- **應用資料完好無損** — 您的現有紀錄、設定和組織範圍與原來完全相同。
|
|
169
169
|
- **現有的直接登入仍然有效** - 電子郵件/密碼和 Google 登入繼續與 SSO 一起使用。
|
|
@@ -174,9 +174,9 @@ AGENT_NATIVE_IDENTITY_HUB_URL=https://dispatch.agent-native.com
|
|
|
174
174
|
驗證一個應用程式後,對下一個應用程式重複步驟 2-3 - 一次在一個部署上設定 `AGENT_NATIVE_IDENTITY_HUB_URL`。切勿批量啟用。
|
|
175
175
|
|
|
176
176
|
**5。回滾 = 取消設定該應用程式部署上的環境變數。**
|
|
177
|
-
要恢復任何應用程式,**從該應用程式的環境中刪除 `AGENT_NATIVE_IDENTITY_HUB_URL` 並重新部署/重新啟動它。**應用程式立即返回到其之前的驗證行為。
|
|
177
|
+
要恢復任何應用程式,**從該應用程式的環境中刪除 `AGENT_NATIVE_IDENTITY_HUB_URL` 並重新部署/重新啟動它。**應用程式立即返回到其之前的驗證行為。 **沒有資料更改可以復原** - 僅新增了識別行,取消設定變數只會使聯合路徑再次休眠。每個應用的割接和回滾都是獨立且可逆的。
|
|
178
178
|
|
|
179
|
-
> 啟用每個應用程式時,Rollout
|
|
179
|
+
> 啟用每個應用程式時,Rollout 會將使用者登出(他們透過 Dispatch 重新進行驗證),但他們始終會重新登入到**相同的電子郵件匹配帳戶,並且資料完好無損**,因為身分行永遠不會被銷毀或重新命名 - 只是新增。
|
|
180
180
|
|
|
181
181
|
## 相關 {#related}
|
|
182
182
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "資料庫"
|
|
3
|
-
description: "將便攜式 SQL
|
|
3
|
+
description: "將便攜式 SQL 資料庫連線到您的 Agent-Native 應用,並編寫與提供者無關的 Drizzle 程式碼。"
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# 資料庫
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Agent-Native 應用程式使用 [Drizzle ORM](https://orm.drizzle.team) 並支援便攜式 SQL 後端。對於本機開發之外的任何內容,請透過設定 `DATABASE_URL` 連線持久性 SQL 資料庫 - Postgres、libSQL/Turso 或另一個 Drizzle 相容後端。取消設定該變數後,應用程式將回退到零設定本機 SQLite 檔案,以便您可以立即開始開發。
|
|
9
9
|
|
|
10
|
-
```an-diagram title="一個模式,多個後端" summary="
|
|
10
|
+
```an-diagram title="一個模式,多個後端" summary="應用程式的程式碼使用框架的與方言無關的幫助程式。執行時從 DATABASE_URL 自動偵測方言; 未設定表示本機 SQLite 檔案。"
|
|
11
11
|
{
|
|
12
12
|
"html": "<div class=\"diagram-db\"><div class=\"diagram-panel center\" data-rough><span class=\"diagram-pill accent\">@agent-native/core/db/schema</span><small class=\"diagram-muted\">table · text · integer · real · now</small><small class=\"diagram-muted\">+ Drizzle query DSL</small></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><div class=\"diagram-box\" data-rough>DATABASE_URL<br><small class=\"diagram-muted\">dialect auto-detected</small></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><div class=\"diagram-grid\"><span class=\"diagram-pill\">Postgres<br><small class=\"diagram-muted\">Neon · Supabase</small></span><span class=\"diagram-pill\">libSQL / Turso</span><span class=\"diagram-pill\">Cloudflare D1</span><span class=\"diagram-pill warn\">SQLite file<br><small class=\"diagram-muted\">unset = local dev only</small></span></div></div>",
|
|
13
13
|
"css": ".diagram-db{display:flex;align-items:center;gap:12px;flex-wrap:wrap}.diagram-db .center{display:flex;flex-direction:column;align-items:center;gap:4px;padding:14px 16px}.diagram-db .diagram-arrow{font-size:22px;line-height:1}.diagram-db .diagram-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}"
|
|
@@ -18,11 +18,11 @@ description: "將便攜式 SQL 資料庫連線到您的代理本機應用,並
|
|
|
18
18
|
|
|
19
19
|
當未設定 `DATABASE_URL` 時,應用程式會在 `data/app.db` 處建立 SQLite 資料庫。這是本機開發的零設定預設設定 - 無需設定。它僅用於開發;對於正式環境,將 `DATABASE_URL` 設定為持久 SQL 資料庫。
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
不要依賴該本機檔案來部署應用程式。容器、無伺服器功能和預覽環境可能會重設其檔案系統,這意味著本機 SQLite 檔案可能會在重新啟動之間消失。在正式環境使用之前將 `DATABASE_URL` 設定為持久託管資料庫。
|
|
22
22
|
|
|
23
23
|
## 連線正式環境資料庫 {#production}
|
|
24
24
|
|
|
25
|
-
在 `.env`
|
|
25
|
+
在 `.env` 檔案或部署提供者環境中設定 `DATABASE_URL` 以連線託管資料庫。圖爾索不是必需的;使用適合您的部署的與 Drizzle 相容的 SQL 後端:
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
28
|
# Neon 託管的 Postgres 資料庫
|
|
@@ -39,15 +39,15 @@ DATABASE_URL=libsql://my-db-org.turso.io
|
|
|
39
39
|
DATABASE_AUTH_TOKEN=your-token
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
框架自動偵測 URL 的方言並相應地設定 Drizzle。內建轉接器涵蓋 Postgres URL、libSQL/Turso URL、SQLite 檔案 URL 和 Cloudflare D1 綁定。常見的正式環境選取包括 Neon、Supabase、Turso/libSQL、普通 Postgres、持久 SQLite 和 Builder.io 託管環境(如果可用)。
|
|
43
43
|
|
|
44
|
-
## Builder.io託管資料庫 {#builder-managed}
|
|
44
|
+
## Builder.io 託管資料庫 {#builder-managed}
|
|
45
45
|
|
|
46
46
|
*計畫(尚不可用):*連線到 Builder.io 時,您的應用將能夠使用自動設定的託管資料庫,無需連線字串。
|
|
47
47
|
|
|
48
48
|
## 資料庫用戶端所在的位置 {#db-client}
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
每個範本透過從 `@agent-native/core/db` 呼叫 `createGetDb(schema)` 來建立一個惰性的單例 Drizzle 用戶端。規範位置是 `server/db/index.ts`:
|
|
51
51
|
|
|
52
52
|
```ts
|
|
53
53
|
// server/db/index.ts
|
|
@@ -61,7 +61,7 @@ export const getDb = createGetDb(schema);
|
|
|
61
61
|
|
|
62
62
|
## 與方言無關的架構和查詢 {#schema}
|
|
63
63
|
|
|
64
|
-
應用程式資料庫程式碼應使用 Drizzle 的架構並查詢 DSL
|
|
64
|
+
應用程式資料庫程式碼應使用 Drizzle 的架構並查詢 DSL,以便它可以跨提供者執行。切勿在產品程式碼中編寫僅 SQLite 語法(`INSERT OR REPLACE`、`AUTOINCREMENT`、`datetime('now')`)或僅 Postgres 語法。
|
|
65
65
|
|
|
66
66
|
使用 `@agent-native/core/db/schema` 中的框架架構助手:
|
|
67
67
|
|
|
@@ -82,7 +82,7 @@ export const tasks = table("tasks", {
|
|
|
82
82
|
| 幫手 | 目的 |
|
|
83
83
|
| --------- | ------------------------------------------------------------- |
|
|
84
84
|
| `table` | 定義一個表——委托給`pgTable`或`sqliteTable` |
|
|
85
|
-
| `text` |
|
|
85
|
+
| `text` | 文字欄,支援`{ enum: [...] }` |
|
|
86
86
|
| `integer` | 整數列,`{ mode: "boolean" }` 對應到 Postgres 布爾值 |
|
|
87
87
|
| `real` | 浮動列 - SQLite 上的 `real`、Postgres 上的 `double precision` |
|
|
88
88
|
| `now` | `.default(now())` 與方言無關的目前時間戳 |
|
|
@@ -112,7 +112,7 @@ export const tasks = table("tasks", {
|
|
|
112
112
|
|
|
113
113
|
切勿直接從 `drizzle-orm/sqlite-core` 或 `drizzle-orm/pg-core` 匯入。始終使用 `@agent-native/core/db/schema`。
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
儲存面向使用者的資料的表必須包含 `owner_email` 列,以便框架的 SQL 層級範圍可以篩選經過驗證的使用者的行 - 請參閱 [Security](/docs/security#data-scoping)。還支援與其他使用者或組織共用的表應改為傳播 `...ownableColumns()`,這會在一次呼叫中新增 `owner_email`、`org_id` 和 `visibility` — 請參閱 [Sharing](/docs/sharing#building)。
|
|
116
116
|
|
|
117
117
|
對於讀取和寫入,請使用 Drizzle 的查詢生成器和 `drizzle-orm` 中的可移植運算符:
|
|
118
118
|
|
|
@@ -134,7 +134,7 @@ await db.update(tasks).set({ done: true }).where(eq(tasks.id, taskId));
|
|
|
134
134
|
|
|
135
135
|
## 原始 SQL 逃生艙口 {#raw-sql}
|
|
136
136
|
|
|
137
|
-
原始 SQL 不是預設的應用程式碼 API。僅將其用於附加遷移、執行狀況檢查、仔細審查 Drizzle
|
|
137
|
+
原始 SQL 不是預設的應用程式碼 API。僅將其用於附加遷移、執行狀況檢查、仔細審查 Drizzle 無法表達的進階查詢或一次性維護。保持參數化且與方言無關。對於 Drizzle 模式中的時間戳,優先選取 `.default(now())`;對於遷移 SQL,請使用 `runMigrations()`,以便框架支援的相容性重寫和方言門控語句保持集中。
|
|
138
138
|
|
|
139
139
|
對於您確實需要 Drizzle 查詢之外的原始 SQL 的情況:
|
|
140
140
|
|
|
@@ -151,16 +151,16 @@ await db.update(tasks).set({ done: true }).where(eq(tasks.id, taskId));
|
|
|
151
151
|
所有資料庫架構更新都必須**嚴格附加**。
|
|
152
152
|
|
|
153
153
|
- **不要刪除表或列。**
|
|
154
|
-
-
|
|
155
|
-
-
|
|
154
|
+
- **不要重新命名表或列。**重新命名列或表看起來像是 Drizzle 的 drop + create 序列,這將永久刪除您現有的正式環境資料。
|
|
155
|
+
- 如果需要重新命名或替換某一列,請在舊列旁邊新增新列,更新應用程式的程式碼以讀取/寫入兩者,遷移資料,並且僅在沒有活動部署引用舊列時才在後續版本中停用舊列。
|
|
156
156
|
|
|
157
157
|
> [!WARNING]
|
|
158
158
|
> **切勿針對正式環境資料庫執行 `drizzle-kit push`。**
|
|
159
|
-
> 範本資料庫模式僅定義特定於應用程式的域表;它們沒有定義中央框架表(`user`、`session`、`application_state` 等)。如果您在正式環境環境中執行 `drizzle-kit push`,Drizzle
|
|
159
|
+
> 範本資料庫模式僅定義特定於應用程式的域表;它們沒有定義中央框架表(`user`、`session`、`application_state` 等)。如果您在正式環境環境中執行 `drizzle-kit push`,Drizzle 會將這些框架表偵測為“不在架構中”並嘗試刪除它們,從而立即導致系統範圍內的故障和資料丟失。
|
|
160
160
|
|
|
161
161
|
### 安全遷移路徑
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
不應直接推送,而應透過在應用程式啟動時執行的 SQL 遷移來應用架構更改。透過呼叫框架的 `runMigrations()` 幫助程式,在伺服器外掛(例如 `server/plugins/db.ts`)中實現附加遷移:
|
|
164
164
|
|
|
165
165
|
```an-annotated-code title="附加遷移外掛"
|
|
166
166
|
{
|
|
@@ -168,7 +168,7 @@ await db.update(tasks).set({ done: true }).where(eq(tasks.id, taskId));
|
|
|
168
168
|
"language": "ts",
|
|
169
169
|
"code": "import { runMigrations } from \"@agent-native/core/db\";\n\nexport default runMigrations(\n [\n {\n version: 1,\n sql: `ALTER TABLE projects ADD COLUMN IF NOT EXISTS sort_order INTEGER NOT NULL DEFAULT 0`,\n },\n {\n // Dialect-gated: runs only on the matching backend. Omit the other key\n // to make it a no-op on that dialect.\n version: 2,\n sql: {\n postgres: `ALTER TABLE projects ADD COLUMN IF NOT EXISTS tsv tsvector`,\n sqlite: `SELECT 1`, // no-op; tsvector is Postgres-only\n },\n },\n ],\n { table: \"my_app_migrations\" },\n);",
|
|
170
170
|
"annotations": [
|
|
171
|
-
{ "lines": "6-7", "label": "僅新增劑", "note": "`ADD COLUMN IF NOT EXISTS`
|
|
171
|
+
{ "lines": "6-7", "label": "僅新增劑", "note": "`ADD COLUMN IF NOT EXISTS` 可以安全地重新執行並且永遠不會丟失資料。重新命名看起來像 drop+create 為 Drizzle,所以改為新增然後遷移。" },
|
|
172
172
|
{ "lines": "13-16", "label": "方言門控", "note": "Pass an object keyed by dialect to run different SQL per backend. Make the other key a no-op (`SELECT 1`) for Postgres-only or SQLite-only features." },
|
|
173
173
|
{ "lines": "19", "label": "每個應用程式版本表", "note": "每個應用程式都會跟蹤自己的應用版本,因此遷移在重新啟動和執行個體之間是冪等的。" }
|
|
174
174
|
]
|
|
@@ -177,7 +177,7 @@ await db.update(tasks).set({ done: true }).where(eq(tasks.id, taskId));
|
|
|
177
177
|
|
|
178
178
|
## 環境變數 {#environment-variables}
|
|
179
179
|
|
|
180
|
-
| 變數 | 目的
|
|
181
|
-
| --------------------- |
|
|
182
|
-
| `DATABASE_URL` | 持久化SQL連線字串(未設定=本機SQLite,僅對本機開發持久) |
|
|
183
|
-
| `DATABASE_AUTH_TOKEN` | 需要單獨權杖的提供者的驗證權杖,例如 Turso/libSQL
|
|
180
|
+
| 變數 | 目的 |
|
|
181
|
+
| --------------------- | ----------------------------------------------------------- |
|
|
182
|
+
| `DATABASE_URL` | 持久化 SQL 連線字串(未設定=本機 SQLite,僅對本機開發持久) |
|
|
183
|
+
| `DATABASE_AUTH_TOKEN` | 需要單獨權杖的提供者的驗證權杖,例如 Turso/libSQL |
|