@agent-native/core 0.113.0 → 0.114.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent-native.eject.json +164 -0
- package/corpus/README.md +3 -3
- package/corpus/core/CHANGELOG.md +20 -0
- package/corpus/core/README.md +61 -174
- package/corpus/core/agent-native.eject.json +164 -0
- package/corpus/core/docs/content/agent-native-toolkit.mdx +38 -0
- package/corpus/core/docs/content/package-lifecycle.mdx +54 -4
- package/corpus/core/package.json +15 -2
- package/corpus/core/src/cli/eject.ts +1594 -0
- package/corpus/core/src/cli/index.ts +16 -0
- package/corpus/core/src/client/build-compatibility.ts +77 -0
- package/corpus/core/src/client/index.ts +4 -0
- package/corpus/core/src/client/resources/McpConnectionSuggestion.tsx +8 -2
- package/corpus/core/src/client/resources/McpIntegrationDialog.tsx +7 -2
- package/corpus/core/src/client/resources/ResourcesPanel.tsx +17 -3
- package/corpus/core/src/client/resources/index.ts +19 -0
- package/corpus/core/src/client/resources/mcp-integration-catalog.ts +9 -1
- package/corpus/core/src/client/resources/runtime.ts +1 -0
- package/corpus/core/src/client/route-chunk-recovery/index.ts +1 -0
- package/corpus/core/src/client/setup-connections/catalog.ts +6 -0
- package/corpus/core/src/client/setup-connections/index.ts +1 -0
- package/corpus/core/src/client/setup-connections/runtime.ts +1 -0
- package/corpus/core/src/client/use-action.ts +32 -1
- package/corpus/core/src/connections/catalog.ts +41 -24
- package/corpus/core/src/connections/index.ts +1 -0
- package/corpus/core/src/connections/runtime.ts +1 -0
- package/corpus/core/src/deploy/build.ts +4 -1
- package/corpus/core/src/eject/provider-api-definitions.ts +193 -0
- package/corpus/core/src/eject/remote-mcp-presets.ts +137 -0
- package/corpus/core/src/eject/setup-readiness-ui.tsx +29 -0
- package/corpus/core/src/eject/workspace-connections.ts +92 -0
- package/corpus/core/src/index.ts +1 -0
- package/corpus/core/src/integrations/adapter-overrides.ts +12 -0
- package/corpus/core/src/integrations/eject/messaging-adapters.ts +85 -0
- package/corpus/core/src/integrations/index.ts +5 -1
- package/corpus/core/src/integrations/plugin.ts +34 -12
- package/corpus/core/src/integrations/runtime.ts +1 -0
- package/corpus/core/src/integrations/types.ts +3 -1
- package/corpus/core/src/org/context.ts +56 -30
- package/corpus/core/src/package-lifecycle/eject-manifest.ts +345 -0
- package/corpus/core/src/package-lifecycle/index.ts +1 -0
- package/corpus/core/src/provider-api/index.ts +46 -12
- package/corpus/core/src/provider-api/runtime.ts +1 -0
- package/corpus/core/src/server/action-routes.ts +52 -2
- package/corpus/core/src/server/auth-plugin.ts +9 -4
- package/corpus/core/src/server/better-auth-instance.ts +5 -1
- package/corpus/core/src/setup-connections/index.ts +1 -0
- package/corpus/core/src/shared/mcp-embed-headers.ts +1 -1
- package/corpus/core/src/shared/merge-by-id.ts +14 -0
- package/corpus/core/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/corpus/core/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/core/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/core/src/templates/default/AGENTS.md +6 -5
- package/corpus/core/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/corpus/core/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/core/src/templates/headless/AGENTS.md +5 -4
- package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +3 -2
- package/corpus/core/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/core/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/core/src/templates/workspace-core/AGENTS.md +4 -4
- package/corpus/core/src/templates/workspace-root/AGENTS.md +4 -4
- package/corpus/core/src/vite/client.ts +42 -2
- package/corpus/templates/analytics/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/analytics/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/assets/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/assets/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/brain/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/brain/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/brain/actions/remediate-legacy-capture-audiences.ts +167 -0
- package/corpus/templates/brain/app/lib/brain-chat-readiness.ts +6 -0
- package/corpus/templates/brain/app/routes/_index.tsx +8 -0
- package/corpus/templates/brain/app/routes.ts +1 -0
- package/corpus/templates/brain/changelog/2026-07-19-ask-starts-immediately-when-builder-s-managed-ai-connection-.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-19-slack-and-granola-backfills-now-process-captures-concurrentl.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-19-source-review-settings-now-control-knowledge-approval.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-19-the-manage-agent-page-now-opens-correctly-from-brain-navigat.md +6 -0
- package/corpus/templates/brain/server/db/schema.ts +3 -0
- package/corpus/templates/brain/server/lib/brain.ts +41 -2
- package/corpus/templates/brain/server/lib/connectors.ts +379 -113
- package/corpus/templates/brain/server/lib/meeting-audience.ts +38 -0
- package/corpus/templates/brain/server/plugins/db.ts +10 -0
- package/corpus/templates/brain/server/routes/api/_agent-native/brain/ingest.post.ts +6 -4
- package/corpus/templates/calendar/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/calendar/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/chat/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/corpus/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/chat/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/chat/AGENTS.md +3 -2
- package/corpus/templates/clips/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/clips/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/content/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/content/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/content/AGENTS.md +2 -0
- package/corpus/templates/content/actions/_content-database-personal-view.ts +49 -5
- package/corpus/templates/content/actions/_content-document-access.ts +21 -0
- package/corpus/templates/content/actions/_content-favorites.ts +91 -0
- package/corpus/templates/content/actions/_content-files.ts +79 -23
- package/corpus/templates/content/actions/_content-sidebar-state.ts +24 -0
- package/corpus/templates/content/actions/_content-space-access.ts +15 -17
- package/corpus/templates/content/actions/_content-space-catalog-guards.ts +20 -0
- package/corpus/templates/content/actions/_content-spaces.ts +364 -167
- package/corpus/templates/content/actions/_database-source-utils.ts +8 -0
- package/corpus/templates/content/actions/_database-utils.ts +249 -15
- package/corpus/templates/content/actions/_delete-content-space.ts +84 -0
- package/corpus/templates/content/actions/_files-system-properties.ts +499 -0
- package/corpus/templates/content/actions/_local-file-documents.ts +0 -1
- package/corpus/templates/content/actions/_property-utils.ts +18 -9
- package/corpus/templates/content/actions/bind-content-database-source-field.ts +3 -0
- package/corpus/templates/content/actions/configure-document-property.ts +3 -0
- package/corpus/templates/content/actions/create-content-database.ts +2 -2
- package/corpus/templates/content/actions/create-content-space.ts +34 -0
- package/corpus/templates/content/actions/create-document.ts +4 -1
- package/corpus/templates/content/actions/delete-content-space.ts +19 -0
- package/corpus/templates/content/actions/delete-database-items.ts +28 -1
- package/corpus/templates/content/actions/delete-document-property.ts +3 -0
- package/corpus/templates/content/actions/delete-document.ts +39 -2
- package/corpus/templates/content/actions/duplicate-database-item.ts +6 -0
- package/corpus/templates/content/actions/duplicate-database-items.ts +6 -0
- package/corpus/templates/content/actions/duplicate-document-property.ts +3 -0
- package/corpus/templates/content/actions/get-content-database.ts +11 -2
- package/corpus/templates/content/actions/get-content-sidebar-state.ts +23 -0
- package/corpus/templates/content/actions/get-document.ts +32 -7
- package/corpus/templates/content/actions/import-content-source.ts +33 -1
- package/corpus/templates/content/actions/list-content-spaces.ts +34 -2
- package/corpus/templates/content/actions/list-documents.ts +39 -7
- package/corpus/templates/content/actions/reorder-document-property.ts +9 -0
- package/corpus/templates/content/actions/set-document-property.ts +41 -23
- package/corpus/templates/content/actions/share-local-file-document.ts +15 -0
- package/corpus/templates/content/actions/submit-content-database-form.ts +7 -0
- package/corpus/templates/content/actions/sync-local-folder-source.ts +14 -0
- package/corpus/templates/content/actions/update-content-database-view.ts +1 -0
- package/corpus/templates/content/actions/update-content-sidebar-state.ts +27 -0
- package/corpus/templates/content/actions/update-document.ts +158 -66
- package/corpus/templates/content/app/components/EmptyState.tsx +4 -57
- package/corpus/templates/content/app/components/editor/CommentsSidebar.tsx +8 -1
- package/corpus/templates/content/app/components/editor/DocumentEditor.tsx +519 -178
- package/corpus/templates/content/app/components/editor/DocumentInfoPanel.tsx +39 -0
- package/corpus/templates/content/app/components/editor/DocumentProperties.tsx +1 -1
- package/corpus/templates/content/app/components/editor/DocumentToolbar.tsx +266 -7
- package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +430 -152
- package/corpus/templates/content/app/components/editor/database/sidebar.tsx +467 -66
- package/corpus/templates/content/app/components/editor/database/view-config.ts +9 -3
- package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +720 -196
- package/corpus/templates/content/app/components/sidebar/DocumentTreeItem.tsx +173 -1
- package/corpus/templates/content/app/components/sidebar/document-sidebar-sections.ts +1 -1
- package/corpus/templates/content/app/components/sidebar/select-content-space.ts +91 -16
- package/corpus/templates/content/app/entry.client.tsx +5 -1
- package/corpus/templates/content/app/hooks/use-content-database.ts +84 -3
- package/corpus/templates/content/app/hooks/use-content-spaces.ts +60 -2
- package/corpus/templates/content/app/hooks/use-create-page.ts +30 -0
- package/corpus/templates/content/app/hooks/use-documents.ts +270 -19
- package/corpus/templates/content/app/i18n-data.ts +243 -20
- package/corpus/templates/content/app/lib/local-folder-picker-safety.ts +54 -0
- package/corpus/templates/content/app/lib/local-folder-picker-support.ts +18 -0
- package/corpus/templates/content/app/routes/_app.favorites.tsx +30 -0
- package/corpus/templates/content/app/routes/_app.local-files.tsx +18 -6
- package/corpus/templates/content/changelog/2026-07-17-workspace-files-now-stay-in-a-loading-state-until-automatic-.md +6 -0
- package/corpus/templates/content/changelog/2026-07-17-workspace-switching-now-opens-the-selected-files-database-pr.md +6 -0
- package/corpus/templates/content/changelog/2026-07-17-workspaces-now-expand-above-their-own-files-list-without-dup.md +6 -0
- package/corpus/templates/content/changelog/2026-07-18-create-named-workspaces-each-with-its-own-private-files-data.md +6 -0
- package/corpus/templates/content/changelog/2026-07-18-favorites-align-with-workspace-and-file-rows-in-the-sidebar.md +6 -0
- package/corpus/templates/content/changelog/2026-07-18-local-folder-selection-no-longer-invokes-the-unsafe-native-p.md +6 -0
- package/corpus/templates/content/changelog/2026-07-18-made-content-workspaces-independently-expandable-restored-or.md +6 -0
- package/corpus/templates/content/changelog/2026-07-18-page-details-now-live-in-a-shared-info-and-comments-rail-dat.md +6 -0
- package/corpus/templates/content/changelog/2026-07-18-workspace-database-views-now-control-sidebar-workspace-navig.md +6 -0
- package/corpus/templates/content/changelog/2026-07-18-workspace-navigation-now-aligns-favorites-with-workspace-pag.md +6 -0
- package/corpus/templates/content/changelog/2026-07-19-favorites-now-open-as-a-table-and-compact-breadcrumbs-make-w.md +6 -0
- package/corpus/templates/content/changelog/2026-07-19-files-databases-now-start-unfiltered-sidebar-rows-exactly-fo.md +6 -0
- package/corpus/templates/content/changelog/2026-07-19-sidebar-page-trees-now-open-only-when-expanded-remember-thei.md +6 -0
- package/corpus/templates/content/changelog/2026-07-19-workspace-file-databases-now-use-the-workspace-name-open-as-.md +6 -0
- package/corpus/templates/content/changelog/2026-07-19-workspace-navigation-now-stays-stable-on-hover-uses-folder-i.md +6 -0
- package/corpus/templates/content/changelog/2026-07-19-workspace-rows-now-use-folder-icons-and-deleting-a-user-crea.md +6 -0
- package/corpus/templates/content/changelog/2026-07-19-workspaces-can-be-created-without-leaving-the-workspaces-dat.md +6 -0
- package/corpus/templates/content/e2e/global-setup.ts +3 -2
- package/corpus/templates/content/parity/matrix.md +28 -28
- package/corpus/templates/content/parity/matrix.ts +8 -2
- package/corpus/templates/content/server/db/index.ts +1 -0
- package/corpus/templates/content/server/db/schema.ts +10 -0
- package/corpus/templates/content/server/lib/documents.ts +12 -7
- package/corpus/templates/content/server/plugins/db.ts +17 -0
- package/corpus/templates/content/shared/api.ts +9 -0
- package/corpus/templates/content/shared/database-form.ts +11 -2
- package/corpus/templates/content/vite.config.ts +1 -0
- package/corpus/templates/design/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/design/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/dispatch/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/dispatch/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/forms/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/forms/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/macros/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/mail/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/mail/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/plan/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/plan/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/slides/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/slides/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/tasks/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/corpus/templates/tasks/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/tasks/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/toolkit/CHANGELOG.md +6 -0
- package/corpus/toolkit/agent-native.eject.json +411 -0
- package/corpus/toolkit/package.json +5 -2
- package/dist/cli/eject.d.ts +21 -0
- package/dist/cli/eject.d.ts.map +1 -0
- package/dist/cli/eject.js +1145 -0
- package/dist/cli/eject.js.map +1 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/client/build-compatibility.d.ts +11 -0
- package/dist/client/build-compatibility.d.ts.map +1 -0
- package/dist/client/build-compatibility.js +56 -0
- package/dist/client/build-compatibility.js.map +1 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/resources/McpConnectionSuggestion.d.ts +4 -3
- package/dist/client/resources/McpConnectionSuggestion.d.ts.map +1 -1
- package/dist/client/resources/McpConnectionSuggestion.js +3 -3
- package/dist/client/resources/McpConnectionSuggestion.js.map +1 -1
- package/dist/client/resources/McpIntegrationDialog.d.ts +4 -3
- package/dist/client/resources/McpIntegrationDialog.d.ts.map +1 -1
- package/dist/client/resources/McpIntegrationDialog.js +2 -2
- package/dist/client/resources/McpIntegrationDialog.js.map +1 -1
- package/dist/client/resources/ResourcesPanel.d.ts +4 -1
- package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
- package/dist/client/resources/ResourcesPanel.js +9 -7
- package/dist/client/resources/ResourcesPanel.js.map +1 -1
- package/dist/client/resources/index.d.ts +3 -0
- package/dist/client/resources/index.d.ts.map +1 -1
- package/dist/client/resources/index.js +3 -0
- package/dist/client/resources/index.js.map +1 -1
- package/dist/client/resources/mcp-integration-catalog.d.ts +2 -1
- package/dist/client/resources/mcp-integration-catalog.d.ts.map +1 -1
- package/dist/client/resources/mcp-integration-catalog.js +6 -2
- package/dist/client/resources/mcp-integration-catalog.js.map +1 -1
- package/dist/client/resources/runtime.d.ts +2 -0
- package/dist/client/resources/runtime.d.ts.map +1 -0
- package/dist/client/resources/runtime.js +2 -0
- package/dist/client/resources/runtime.js.map +1 -0
- package/dist/client/route-chunk-recovery/index.d.ts +1 -0
- package/dist/client/route-chunk-recovery/index.d.ts.map +1 -1
- package/dist/client/route-chunk-recovery/index.js +1 -0
- package/dist/client/route-chunk-recovery/index.js.map +1 -1
- package/dist/client/setup-connections/catalog.d.ts +2 -0
- package/dist/client/setup-connections/catalog.d.ts.map +1 -0
- package/dist/client/setup-connections/catalog.js +7 -0
- package/dist/client/setup-connections/catalog.js.map +1 -0
- package/dist/client/setup-connections/index.d.ts +1 -0
- package/dist/client/setup-connections/index.d.ts.map +1 -1
- package/dist/client/setup-connections/index.js +1 -0
- package/dist/client/setup-connections/index.js.map +1 -1
- package/dist/client/setup-connections/runtime.d.ts +2 -0
- package/dist/client/setup-connections/runtime.d.ts.map +1 -0
- package/dist/client/setup-connections/runtime.js +2 -0
- package/dist/client/setup-connections/runtime.js.map +1 -0
- package/dist/client/use-action.d.ts.map +1 -1
- package/dist/client/use-action.js +19 -1
- package/dist/client/use-action.js.map +1 -1
- package/dist/collab/awareness.d.ts +2 -2
- package/dist/collab/awareness.d.ts.map +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/connections/catalog.d.ts +5 -3
- package/dist/connections/catalog.d.ts.map +1 -1
- package/dist/connections/catalog.js +16 -8
- package/dist/connections/catalog.js.map +1 -1
- package/dist/connections/index.d.ts +1 -1
- package/dist/connections/index.d.ts.map +1 -1
- package/dist/connections/index.js +1 -1
- package/dist/connections/index.js.map +1 -1
- package/dist/connections/runtime.d.ts +2 -0
- package/dist/connections/runtime.d.ts.map +1 -0
- package/dist/connections/runtime.js +2 -0
- package/dist/connections/runtime.js.map +1 -0
- package/dist/deploy/build.js +2 -1
- package/dist/deploy/build.js.map +1 -1
- package/dist/eject/provider-api-definitions.d.ts +34 -0
- package/dist/eject/provider-api-definitions.d.ts.map +1 -0
- package/dist/eject/provider-api-definitions.js +88 -0
- package/dist/eject/provider-api-definitions.js.map +1 -0
- package/dist/eject/remote-mcp-presets.d.ts +17 -0
- package/dist/eject/remote-mcp-presets.d.ts.map +1 -0
- package/dist/eject/remote-mcp-presets.js +81 -0
- package/dist/eject/remote-mcp-presets.js.map +1 -0
- package/dist/eject/setup-readiness-ui.d.ts +7 -0
- package/dist/eject/setup-readiness-ui.d.ts.map +1 -0
- package/dist/eject/setup-readiness-ui.js +13 -0
- package/dist/eject/setup-readiness-ui.js.map +1 -0
- package/dist/eject/workspace-connections.d.ts +11 -0
- package/dist/eject/workspace-connections.d.ts.map +1 -0
- package/dist/eject/workspace-connections.js +47 -0
- package/dist/eject/workspace-connections.js.map +1 -0
- package/dist/file-upload/actions/upload-image.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/integrations/adapter-overrides.d.ts +3 -0
- package/dist/integrations/adapter-overrides.d.ts.map +1 -0
- package/dist/integrations/adapter-overrides.js +7 -0
- package/dist/integrations/adapter-overrides.js.map +1 -0
- package/dist/integrations/eject/messaging-adapters.d.ts +12 -0
- package/dist/integrations/eject/messaging-adapters.d.ts.map +1 -0
- package/dist/integrations/eject/messaging-adapters.js +49 -0
- package/dist/integrations/eject/messaging-adapters.js.map +1 -0
- package/dist/integrations/index.d.ts +3 -2
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/index.js +2 -1
- package/dist/integrations/index.js.map +1 -1
- package/dist/integrations/plugin.d.ts +32 -1
- package/dist/integrations/plugin.d.ts.map +1 -1
- package/dist/integrations/plugin.js +19 -12
- package/dist/integrations/plugin.js.map +1 -1
- package/dist/integrations/runtime.d.ts +2 -0
- package/dist/integrations/runtime.d.ts.map +1 -0
- package/dist/integrations/runtime.js +2 -0
- package/dist/integrations/runtime.js.map +1 -0
- package/dist/integrations/types.d.ts +3 -1
- package/dist/integrations/types.d.ts.map +1 -1
- package/dist/integrations/types.js.map +1 -1
- package/dist/notifications/routes.d.ts +2 -2
- package/dist/observability/routes.d.ts +5 -5
- package/dist/org/context.d.ts +4 -2
- package/dist/org/context.d.ts.map +1 -1
- package/dist/org/context.js +44 -22
- package/dist/org/context.js.map +1 -1
- package/dist/package-lifecycle/eject-manifest.d.ts +43 -0
- package/dist/package-lifecycle/eject-manifest.d.ts.map +1 -0
- package/dist/package-lifecycle/eject-manifest.js +219 -0
- package/dist/package-lifecycle/eject-manifest.js.map +1 -0
- package/dist/package-lifecycle/index.d.ts +1 -0
- package/dist/package-lifecycle/index.d.ts.map +1 -1
- package/dist/package-lifecycle/index.js +1 -0
- package/dist/package-lifecycle/index.js.map +1 -1
- package/dist/provider-api/actions/custom-provider-registration.d.ts +11 -11
- package/dist/provider-api/actions/provider-api.d.ts +11 -11
- package/dist/provider-api/index.d.ts +6 -2
- package/dist/provider-api/index.d.ts.map +1 -1
- package/dist/provider-api/index.js +25 -12
- package/dist/provider-api/index.js.map +1 -1
- package/dist/provider-api/runtime.d.ts +2 -0
- package/dist/provider-api/runtime.d.ts.map +1 -0
- package/dist/provider-api/runtime.js +2 -0
- package/dist/provider-api/runtime.js.map +1 -0
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/server/action-routes.d.ts.map +1 -1
- package/dist/server/action-routes.js +32 -2
- package/dist/server/action-routes.js.map +1 -1
- package/dist/server/auth-plugin.d.ts.map +1 -1
- package/dist/server/auth-plugin.js +9 -5
- package/dist/server/auth-plugin.js.map +1 -1
- package/dist/server/better-auth-instance.d.ts.map +1 -1
- package/dist/server/better-auth-instance.js +4 -1
- package/dist/server/better-auth-instance.js.map +1 -1
- package/dist/setup-connections/index.d.ts +1 -1
- package/dist/setup-connections/index.d.ts.map +1 -1
- package/dist/setup-connections/index.js +1 -1
- package/dist/setup-connections/index.js.map +1 -1
- package/dist/shared/mcp-embed-headers.d.ts +1 -1
- package/dist/shared/mcp-embed-headers.d.ts.map +1 -1
- package/dist/shared/mcp-embed-headers.js +1 -1
- package/dist/shared/mcp-embed-headers.js.map +1 -1
- package/dist/shared/merge-by-id.d.ts +5 -0
- package/dist/shared/merge-by-id.d.ts.map +1 -0
- package/dist/shared/merge-by-id.js +7 -0
- package/dist/shared/merge-by-id.js.map +1 -0
- package/dist/templates/chat/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/dist/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/dist/templates/chat/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/dist/templates/chat/AGENTS.md +3 -2
- package/dist/templates/default/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/dist/templates/default/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/dist/templates/default/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/dist/templates/default/AGENTS.md +6 -5
- package/dist/templates/headless/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/dist/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/dist/templates/headless/AGENTS.md +5 -4
- package/dist/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/dist/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +3 -2
- package/dist/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/dist/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/dist/templates/workspace-core/AGENTS.md +4 -4
- package/dist/templates/workspace-root/AGENTS.md +4 -4
- package/dist/vite/client.d.ts +6 -0
- package/dist/vite/client.d.ts.map +1 -1
- package/dist/vite/client.js +30 -2
- package/dist/vite/client.js.map +1 -1
- package/docs/content/agent-native-toolkit.mdx +38 -0
- package/docs/content/package-lifecycle.mdx +54 -4
- package/package.json +15 -2
- package/src/a2a/agent-card.ts +83 -0
- package/src/a2a/artifact-response.ts +1648 -0
- package/src/a2a/auth-policy.ts +66 -0
- package/src/a2a/caller-auth.ts +102 -0
- package/src/a2a/client.ts +876 -0
- package/src/a2a/correlation.ts +50 -0
- package/src/a2a/handlers.ts +1285 -0
- package/src/a2a/index.ts +50 -0
- package/src/a2a/invoke.ts +348 -0
- package/src/a2a/response-text.ts +53 -0
- package/src/a2a/server.ts +586 -0
- package/src/a2a/task-store.ts +917 -0
- package/src/a2a/types.ts +221 -0
- package/src/a2a-claims.ts +52 -0
- package/src/action-change-marker.ts +74 -0
- package/src/action-ui.ts +38 -0
- package/src/action.ts +1406 -0
- package/src/adapters/cli/index.ts +6 -0
- package/src/adapters/cli/registry.ts +73 -0
- package/src/adapters/cli/shell-adapter.ts +92 -0
- package/src/adapters/cli/types.ts +27 -0
- package/src/agent/action-continuation-guidance.ts +38 -0
- package/src/agent/app-model-defaults.ts +201 -0
- package/src/agent/context-xray/actions/context-evict.ts +56 -0
- package/src/agent/context-xray/actions/context-manifest-get.ts +75 -0
- package/src/agent/context-xray/actions/context-pin.ts +56 -0
- package/src/agent/context-xray/actions/context-preview-get.ts +134 -0
- package/src/agent/context-xray/actions/context-report.ts +75 -0
- package/src/agent/context-xray/actions/context-restore.ts +51 -0
- package/src/agent/context-xray/actions/errors.ts +40 -0
- package/src/agent/context-xray/apply-directives.ts +137 -0
- package/src/agent/context-xray/directives-store.ts +178 -0
- package/src/agent/context-xray/identity.ts +37 -0
- package/src/agent/context-xray/manifest.ts +284 -0
- package/src/agent/context-xray/migrations.ts +32 -0
- package/src/agent/context-xray/plugin.ts +23 -0
- package/src/agent/context-xray/schema.ts +17 -0
- package/src/agent/context-xray/segments.ts +194 -0
- package/src/agent/context-xray/tokenize.ts +93 -0
- package/src/agent/default-model.ts +5 -0
- package/src/agent/durable-background.ts +547 -0
- package/src/agent/engine/ai-sdk-engine.ts +565 -0
- package/src/agent/engine/anthropic-engine.ts +320 -0
- package/src/agent/engine/builder-engine.ts +1110 -0
- package/src/agent/engine/builder-gateway-headers.ts +44 -0
- package/src/agent/engine/builtin.ts +122 -0
- package/src/agent/engine/context-directives-transform.ts +73 -0
- package/src/agent/engine/continuation-dispatch-retry.ts +168 -0
- package/src/agent/engine/credential-errors.ts +69 -0
- package/src/agent/engine/index.ts +54 -0
- package/src/agent/engine/openai-compatible-endpoint.ts +25 -0
- package/src/agent/engine/output-tokens.ts +181 -0
- package/src/agent/engine/provider-env-vars.ts +69 -0
- package/src/agent/engine/registry.ts +853 -0
- package/src/agent/engine/tool-call-journal-seed.ts +85 -0
- package/src/agent/engine/translate-ai-sdk.ts +407 -0
- package/src/agent/engine/translate-anthropic.ts +611 -0
- package/src/agent/engine/types.ts +310 -0
- package/src/agent/harness/acp-adapter.ts +893 -0
- package/src/agent/harness/acp-builtin.ts +70 -0
- package/src/agent/harness/ai-sdk-adapter.ts +509 -0
- package/src/agent/harness/background.ts +365 -0
- package/src/agent/harness/builtin.ts +50 -0
- package/src/agent/harness/index.ts +86 -0
- package/src/agent/harness/lifecycle.ts +498 -0
- package/src/agent/harness/registry.ts +97 -0
- package/src/agent/harness/runner.ts +182 -0
- package/src/agent/harness/store.ts +466 -0
- package/src/agent/harness/translate.ts +130 -0
- package/src/agent/harness/types.ts +129 -0
- package/src/agent/index.ts +32 -0
- package/src/agent/loop-settings.ts +186 -0
- package/src/agent/model-config.ts +363 -0
- package/src/agent/observational-memory/compactor.ts +78 -0
- package/src/agent/observational-memory/config.ts +78 -0
- package/src/agent/observational-memory/index.ts +79 -0
- package/src/agent/observational-memory/internal-run.ts +89 -0
- package/src/agent/observational-memory/message-text.ts +49 -0
- package/src/agent/observational-memory/migrations.ts +44 -0
- package/src/agent/observational-memory/observer.ts +128 -0
- package/src/agent/observational-memory/plugin.ts +35 -0
- package/src/agent/observational-memory/prompts.ts +53 -0
- package/src/agent/observational-memory/read.ts +131 -0
- package/src/agent/observational-memory/reflector.ts +119 -0
- package/src/agent/observational-memory/schema.ts +48 -0
- package/src/agent/observational-memory/store.ts +275 -0
- package/src/agent/observational-memory/types.ts +65 -0
- package/src/agent/processors.ts +209 -0
- package/src/agent/production-agent.ts +8254 -0
- package/src/agent/run-loop-with-resume.ts +394 -0
- package/src/agent/run-manager.ts +1825 -0
- package/src/agent/run-ownership.ts +75 -0
- package/src/agent/run-store.ts +2601 -0
- package/src/agent/runtime-context.ts +169 -0
- package/src/agent/thread-data-builder.ts +1584 -0
- package/src/agent/tool-call-journal.ts +368 -0
- package/src/agent/tool-error-redaction.ts +52 -0
- package/src/agent/tool-result-images.ts +178 -0
- package/src/agent/tool-search.ts +376 -0
- package/src/agent/types.ts +372 -0
- package/src/agent-native/index.ts +198 -0
- package/src/agent-web/config.ts +253 -0
- package/src/agent-web/generator.ts +382 -0
- package/src/agent-web/index.ts +36 -0
- package/src/appearance/actions/change-appearance.ts +35 -0
- package/src/application-state/emitter.ts +81 -0
- package/src/application-state/handlers.ts +121 -0
- package/src/application-state/index.ts +44 -0
- package/src/application-state/script-helpers.ts +155 -0
- package/src/application-state/store.ts +274 -0
- package/src/assets/branding/agent-native.icon/Assets/background.svg +3 -0
- package/src/assets/branding/agent-native.icon/Assets/foreground.svg +12 -0
- package/src/assets/branding/agent-native.icon/icon.json +49 -0
- package/src/assets/branding/favicon.png +0 -0
- package/src/assets/branding/favicon.svg +1 -0
- package/src/assets/branding/icon-on-dark.svg +10 -0
- package/src/assets/branding/icon-on-light.svg +10 -0
- package/src/assets/branding/mac-app-icon.svg +1 -0
- package/src/assets/branding/slack-bot/agent-native-1024.png +0 -0
- package/src/assets/branding/slack-bot/agent-native-512.png +0 -0
- package/src/assets/branding/tray-icon.svg +6 -0
- package/src/assets/branding/wordmark-on-dark.svg +21 -0
- package/src/assets/branding/wordmark-on-light.svg +21 -0
- package/src/assets/fonts/LICENSE_LIBERATION +96 -0
- package/src/assets/fonts/LICENSE_NOTO_NASKH_ARABIC +93 -0
- package/src/assets/fonts/LiberationSans-Bold.ttf +0 -0
- package/src/assets/fonts/LiberationSans-Regular.ttf +0 -0
- package/src/assets/fonts/NotoNaskhArabic-Variable.ttf +0 -0
- package/src/audit/actions/export-audit-events.ts +162 -0
- package/src/audit/actions/get-audit-event.ts +24 -0
- package/src/audit/actions/list-audit-events.ts +66 -0
- package/src/audit/cleanup-job.ts +100 -0
- package/src/audit/config.ts +90 -0
- package/src/audit/index.ts +43 -0
- package/src/audit/record.ts +180 -0
- package/src/audit/redact.ts +109 -0
- package/src/audit/store.ts +346 -0
- package/src/audit/types.ts +141 -0
- package/src/automation/index.ts +802 -0
- package/src/brand-kit/brand-signals.ts +124 -0
- package/src/brand-kit/fig/index.ts +64 -0
- package/src/brand-kit/index.ts +72 -0
- package/src/brand-kit/types.ts +113 -0
- package/src/browser-sessions/actions.ts +302 -0
- package/src/browser-sessions/routes.ts +234 -0
- package/src/browser-sessions/store.ts +679 -0
- package/src/browser-sessions/types.ts +84 -0
- package/src/changelog/parse.ts +328 -0
- package/src/chat-threads/emitter.ts +22 -0
- package/src/chat-threads/schema.ts +43 -0
- package/src/chat-threads/store.ts +1311 -0
- package/src/checkpoints/index.ts +15 -0
- package/src/checkpoints/service.ts +142 -0
- package/src/checkpoints/store.ts +153 -0
- package/src/cli/add.ts +425 -0
- package/src/cli/agent.ts +424 -0
- package/src/cli/agents.ts +122 -0
- package/src/cli/app-skill.ts +1455 -0
- package/src/cli/atomic-json-file.ts +324 -0
- package/src/cli/audit-agent-web.ts +324 -0
- package/src/cli/changelog.ts +199 -0
- package/src/cli/claude-code-participant.ts +515 -0
- package/src/cli/code-agent-commands.ts +270 -0
- package/src/cli/code-agent-connector.ts +1109 -0
- package/src/cli/code-agent-executor.ts +1970 -0
- package/src/cli/code-agent-output-smoother.ts +140 -0
- package/src/cli/code-agent-runs.concurrent-worker.ts +33 -0
- package/src/cli/code-agent-runs.ts +548 -0
- package/src/cli/code.ts +1805 -0
- package/src/cli/codex-cli-participant.ts +496 -0
- package/src/cli/connect.ts +2714 -0
- package/src/cli/content-local.ts +442 -0
- package/src/cli/context-xray-local.ts +2193 -0
- package/src/cli/create-workspace.ts +30 -0
- package/src/cli/create.ts +2247 -0
- package/src/cli/deploy-build.ts +50 -0
- package/src/cli/design-connect.ts +3187 -0
- package/src/cli/doctor.ts +472 -0
- package/src/cli/eject.ts +1594 -0
- package/src/cli/eval.ts +134 -0
- package/src/cli/gateway-helpers.ts +70 -0
- package/src/cli/index.ts +1217 -0
- package/src/cli/info.ts +105 -0
- package/src/cli/invoke.ts +288 -0
- package/src/cli/mcp-config-writers.ts +857 -0
- package/src/cli/mcp.ts +594 -0
- package/src/cli/migrate.ts +1813 -0
- package/src/cli/migration-codemod.ts +646 -0
- package/src/cli/multi-frontier-runs.ts +1952 -0
- package/src/cli/package-lifecycle.ts +823 -0
- package/src/cli/plan-blocks.ts +143 -0
- package/src/cli/plan-local.ts +3189 -0
- package/src/cli/plan-publish-store.ts +138 -0
- package/src/cli/pr-visual-recap-workflow.ts +2 -0
- package/src/cli/recap.ts +5 -0
- package/src/cli/setup-agents.ts +120 -0
- package/src/cli/skills-content/assets-skill.ts +83 -0
- package/src/cli/skills-content/canvas.ts +153 -0
- package/src/cli/skills-content/connection.ts +52 -0
- package/src/cli/skills-content/content-skill.ts +120 -0
- package/src/cli/skills-content/design-exploration-skill.ts +118 -0
- package/src/cli/skills-content/design-visual-edit-skill.ts +228 -0
- package/src/cli/skills-content/document-quality.ts +196 -0
- package/src/cli/skills-content/exemplar.ts +69 -0
- package/src/cli/skills-content/help.ts +77 -0
- package/src/cli/skills-content/index.ts +22 -0
- package/src/cli/skills-content/local-files.ts +100 -0
- package/src/cli/skills-content/plan-setup-auth.ts +80 -0
- package/src/cli/skills-content/visual-plan-skill.ts +493 -0
- package/src/cli/skills-content/visual-recap-skill.ts +553 -0
- package/src/cli/skills-content/visualize-repo-skill.ts +93 -0
- package/src/cli/skills-content/wireframe.ts +349 -0
- package/src/cli/skills.ts +4340 -0
- package/src/cli/sync-builder-starter-manifest.ts +631 -0
- package/src/cli/telemetry.ts +136 -0
- package/src/cli/templates-meta.ts +269 -0
- package/src/cli/upgrade.ts +956 -0
- package/src/cli/visualize-repo.ts +715 -0
- package/src/cli/workspace-dev.ts +1486 -0
- package/src/cli/workspacify.ts +258 -0
- package/src/client/AgentAskPopover.tsx +89 -0
- package/src/client/AgentChatHome.tsx +66 -0
- package/src/client/AgentNative.tsx +161 -0
- package/src/client/AgentNativeEmbedded.tsx +288 -0
- package/src/client/AgentNativeFrame.tsx +151 -0
- package/src/client/AgentPanel.tsx +3437 -0
- package/src/client/AgentTaskCard.tsx +273 -0
- package/src/client/AppearancePicker.tsx +79 -0
- package/src/client/AssistantChat.tsx +5793 -0
- package/src/client/ClientOnly.tsx +22 -0
- package/src/client/CommandMenu.tsx +726 -0
- package/src/client/ConnectBuilderCard.tsx +390 -0
- package/src/client/DefaultSpinner.tsx +47 -0
- package/src/client/ErrorBoundary.tsx +359 -0
- package/src/client/ErrorReportActions.tsx +69 -0
- package/src/client/FeedbackButton.tsx +553 -0
- package/src/client/HighlightedCodeBlock.tsx +173 -0
- package/src/client/IframeEmbed.tsx +151 -0
- package/src/client/KeepTabOpenNotice.tsx +181 -0
- package/src/client/MultiTabAssistantChat.tsx +2576 -0
- package/src/client/NewWorkspaceAppFlow.tsx +525 -0
- package/src/client/PoweredByBadge.tsx +284 -0
- package/src/client/RunStuckBanner.tsx +431 -0
- package/src/client/StarfieldBackground.tsx +466 -0
- package/src/client/Turnstile.tsx +125 -0
- package/src/client/active-run-state.ts +139 -0
- package/src/client/agent-chat/index.ts +279 -0
- package/src/client/agent-chat-adapter.ts +3692 -0
- package/src/client/agent-chat.ts +1233 -0
- package/src/client/agent-engine-key.ts +122 -0
- package/src/client/agent-page/AgentContextTab.tsx +487 -0
- package/src/client/agent-page/AgentEmptyState.tsx +44 -0
- package/src/client/agent-page/AgentJobsTab.tsx +441 -0
- package/src/client/agent-page/AgentTabFrame.tsx +39 -0
- package/src/client/agent-page/AgentTabsPage.tsx +1096 -0
- package/src/client/agent-page/types.ts +18 -0
- package/src/client/agent-page/use-jobs.ts +150 -0
- package/src/client/agent-sidebar-state.ts +166 -0
- package/src/client/analytics/index.ts +40 -0
- package/src/client/analytics-session.ts +70 -0
- package/src/client/analytics.ts +1757 -0
- package/src/client/api-path.ts +124 -0
- package/src/client/app-providers.tsx +230 -0
- package/src/client/appearance.ts +130 -0
- package/src/client/application-state.ts +154 -0
- package/src/client/assistant-ui-recovery.tsx +205 -0
- package/src/client/automation/index.ts +4 -0
- package/src/client/automation.ts +22 -0
- package/src/client/blocks/AiEditableField.tsx +30 -0
- package/src/client/blocks/BlockView.tsx +145 -0
- package/src/client/blocks/RegistryBlockDataProvider.tsx +121 -0
- package/src/client/blocks/SchemaBlockEditor.tsx +457 -0
- package/src/client/blocks/agent.ts +95 -0
- package/src/client/blocks/code-block-direction.ts +21 -0
- package/src/client/blocks/index.ts +308 -0
- package/src/client/blocks/library/AnnotatedCodeBlock.tsx +710 -0
- package/src/client/blocks/library/ApiEndpointBlock.tsx +1120 -0
- package/src/client/blocks/library/DataModelBlock.tsx +775 -0
- package/src/client/blocks/library/DiffBlock.tsx +1854 -0
- package/src/client/blocks/library/FileTreeBlock.tsx +868 -0
- package/src/client/blocks/library/HighlightedCode.tsx +260 -0
- package/src/client/blocks/library/JsonExplorerBlock.tsx +608 -0
- package/src/client/blocks/library/MermaidBlock.tsx +362 -0
- package/src/client/blocks/library/OpenApiSpecBlock.tsx +998 -0
- package/src/client/blocks/library/annotated-code.config.ts +101 -0
- package/src/client/blocks/library/annotation-rail.tsx +1020 -0
- package/src/client/blocks/library/api-endpoint.config.ts +207 -0
- package/src/client/blocks/library/block-copy.ts +399 -0
- package/src/client/blocks/library/callout.config.ts +57 -0
- package/src/client/blocks/library/callout.tsx +149 -0
- package/src/client/blocks/library/checklist.config.ts +56 -0
- package/src/client/blocks/library/checklist.tsx +208 -0
- package/src/client/blocks/library/code-filename-label.tsx +59 -0
- package/src/client/blocks/library/code-highlight.tsx +178 -0
- package/src/client/blocks/library/code-tabs.config.ts +70 -0
- package/src/client/blocks/library/code-tabs.tsx +606 -0
- package/src/client/blocks/library/code.config.ts +69 -0
- package/src/client/blocks/library/code.tsx +440 -0
- package/src/client/blocks/library/columns.config.ts +85 -0
- package/src/client/blocks/library/columns.tsx +334 -0
- package/src/client/blocks/library/data-model.config.ts +152 -0
- package/src/client/blocks/library/dev-doc-ui.tsx +191 -0
- package/src/client/blocks/library/diagram.config.ts +222 -0
- package/src/client/blocks/library/diagram.tsx +958 -0
- package/src/client/blocks/library/diff.config.ts +115 -0
- package/src/client/blocks/library/file-tree.config.ts +92 -0
- package/src/client/blocks/library/html.config.ts +79 -0
- package/src/client/blocks/library/html.tsx +258 -0
- package/src/client/blocks/library/json-explorer.config.ts +74 -0
- package/src/client/blocks/library/mermaid.config.ts +49 -0
- package/src/client/blocks/library/narrow-container.tsx +37 -0
- package/src/client/blocks/library/openapi-spec.config.ts +66 -0
- package/src/client/blocks/library/question-form.config.ts +127 -0
- package/src/client/blocks/library/question-form.tsx +944 -0
- package/src/client/blocks/library/sanitize-html.ts +343 -0
- package/src/client/blocks/library/server-specs.ts +338 -0
- package/src/client/blocks/library/specs.tsx +308 -0
- package/src/client/blocks/library/table.config.ts +61 -0
- package/src/client/blocks/library/table.tsx +449 -0
- package/src/client/blocks/library/tabs.config.ts +96 -0
- package/src/client/blocks/library/tabs.tsx +665 -0
- package/src/client/blocks/library/wireframe-icons.ts +210 -0
- package/src/client/blocks/library/wireframe-kit.tsx +1850 -0
- package/src/client/blocks/library/wireframe.config.ts +539 -0
- package/src/client/blocks/library/wireframe.tsx +535 -0
- package/src/client/blocks/mdx.ts +364 -0
- package/src/client/blocks/provider.tsx +51 -0
- package/src/client/blocks/registry.ts +83 -0
- package/src/client/blocks/schema-form/introspect.ts +201 -0
- package/src/client/blocks/server.ts +170 -0
- package/src/client/blocks/types.ts +415 -0
- package/src/client/browser-session-bridge.ts +548 -0
- package/src/client/browser-tab-id.ts +36 -0
- package/src/client/build-compatibility.ts +77 -0
- package/src/client/builder-frame.ts +194 -0
- package/src/client/builder-mark.tsx +21 -0
- package/src/client/changelog/Changelog.tsx +333 -0
- package/src/client/changelog/index.ts +1 -0
- package/src/client/chat/ChatHistoryList.tsx +7 -0
- package/src/client/chat/attachment-adapters.ts +426 -0
- package/src/client/chat/connectors.ts +1579 -0
- package/src/client/chat/index.ts +160 -0
- package/src/client/chat/markdown-renderer.tsx +693 -0
- package/src/client/chat/message-components.tsx +1326 -0
- package/src/client/chat/repo-helpers.ts +281 -0
- package/src/client/chat/run-recovery.tsx +994 -0
- package/src/client/chat/runtime.ts +1810 -0
- package/src/client/chat/tool-call-display.tsx +1270 -0
- package/src/client/chat/tool-render-registry.tsx +144 -0
- package/src/client/chat/use-agent-chat-lifecycle-tracking.ts +74 -0
- package/src/client/chat/use-reconnect-reader-owner.ts +28 -0
- package/src/client/chat/widgets/DataChartRenderer.tsx +242 -0
- package/src/client/chat/widgets/DataChartWidget.tsx +51 -0
- package/src/client/chat/widgets/DataInsightsWidget.tsx +59 -0
- package/src/client/chat/widgets/DataTableWidget.tsx +240 -0
- package/src/client/chat/widgets/InlineExtensionWidget.tsx +60 -0
- package/src/client/chat/widgets/builtin-tool-renderers.tsx +213 -0
- package/src/client/chat/widgets/data-widget-types.ts +1 -0
- package/src/client/chat/widgets/inline-extension-result.ts +86 -0
- package/src/client/chat-model-groups.ts +171 -0
- package/src/client/chat-thread-url.ts +11 -0
- package/src/client/chat-view-transition.ts +213 -0
- package/src/client/client-action.ts +21 -0
- package/src/client/client-bootstrap.ts +7 -0
- package/src/client/client-surface.ts +41 -0
- package/src/client/clipboard.ts +89 -0
- package/src/client/code-agent-chat-adapter.ts +537 -0
- package/src/client/collab/index.ts +60 -0
- package/src/client/command-navigation/index.ts +15 -0
- package/src/client/comments-review/index.ts +1 -0
- package/src/client/components/AgentPresenceChip.tsx +4 -0
- package/src/client/components/ApiKeySettings.tsx +309 -0
- package/src/client/components/CodeAgentIndicator.tsx +59 -0
- package/src/client/components/CodeRequiredDialog.tsx +470 -0
- package/src/client/components/LiveCursorOverlay.tsx +5 -0
- package/src/client/components/MissingKeyCard.tsx +61 -0
- package/src/client/components/PresenceBar.tsx +4 -0
- package/src/client/components/RecentEditHighlights.tsx +4 -0
- package/src/client/components/RemoteSelectionRings.tsx +5 -0
- package/src/client/components/icons/AgentNativeIcon.tsx +46 -0
- package/src/client/components/ui/dialog.tsx +1 -0
- package/src/client/components/ui/dropdown-menu.tsx +1 -0
- package/src/client/components/ui/hover-card.tsx +1 -0
- package/src/client/components/ui/message-scroller.tsx +131 -0
- package/src/client/components/ui/popover.tsx +1 -0
- package/src/client/components/ui/sheet.tsx +1 -0
- package/src/client/components/ui/tooltip.tsx +1 -0
- package/src/client/composer/index.ts +11 -0
- package/src/client/composer/runtime-adapters.tsx +123 -0
- package/src/client/composer/use-mention-search.ts +7 -0
- package/src/client/composer/wired-components.tsx +53 -0
- package/src/client/context-xray/ContextMeter.tsx +124 -0
- package/src/client/context-xray/ContextSegmentRow.tsx +27 -0
- package/src/client/context-xray/ContextTreemap.tsx +24 -0
- package/src/client/context-xray/ContextXRayPanel.tsx +59 -0
- package/src/client/context-xray/SegmentProvenancePopover.tsx +18 -0
- package/src/client/context-xray/format.ts +27 -0
- package/src/client/conversation/AgentConversation.tsx +555 -0
- package/src/client/conversation/code-agent-transcript.ts +283 -0
- package/src/client/conversation/index.ts +22 -0
- package/src/client/conversation/types.ts +85 -0
- package/src/client/conversation/use-near-bottom-autoscroll.ts +278 -0
- package/src/client/create-query-client.ts +86 -0
- package/src/client/db-admin/DataGrid.tsx +551 -0
- package/src/client/db-admin/DbAdminPage.tsx +218 -0
- package/src/client/db-admin/DevDatabaseLink.tsx +16 -0
- package/src/client/db-admin/EditableCell.tsx +451 -0
- package/src/client/db-admin/FilterBar.tsx +203 -0
- package/src/client/db-admin/ResultsGrid.tsx +114 -0
- package/src/client/db-admin/RowSidePanel.tsx +337 -0
- package/src/client/db-admin/SqlEditor.tsx +840 -0
- package/src/client/db-admin/TableBrowser.tsx +212 -0
- package/src/client/db-admin/TableEditor.tsx +760 -0
- package/src/client/db-admin/cell-format.ts +246 -0
- package/src/client/db-admin/changeset.ts +296 -0
- package/src/client/db-admin/export-utils.ts +78 -0
- package/src/client/db-admin/index.ts +33 -0
- package/src/client/db-admin/sql-storage.ts +134 -0
- package/src/client/db-admin/storage.ts +68 -0
- package/src/client/db-admin/useAgentSync.ts +226 -0
- package/src/client/db-admin/useDbAdmin.ts +294 -0
- package/src/client/dev-overlay/DevOverlay.tsx +576 -0
- package/src/client/dev-overlay/builtins.ts +40 -0
- package/src/client/dev-overlay/index.ts +23 -0
- package/src/client/dev-overlay/registry.ts +67 -0
- package/src/client/dev-overlay/types.ts +64 -0
- package/src/client/dev-overlay/use-dev-option.ts +78 -0
- package/src/client/dev-overlay/use-dev-overlay-shortcut.ts +31 -0
- package/src/client/dynamic-suggestions.ts +455 -0
- package/src/client/embed-auth.ts +544 -0
- package/src/client/embed.ts +54 -0
- package/src/client/error-capture.ts +690 -0
- package/src/client/error-format.ts +211 -0
- package/src/client/error-reporting.ts +100 -0
- package/src/client/extensions/AgentNativeExtensionFrame.e2e-host.tsx +136 -0
- package/src/client/extensions/AgentNativeExtensionFrame.tsx +708 -0
- package/src/client/extensions/EmbeddedExtension.tsx +604 -0
- package/src/client/extensions/ExtensionEditor.tsx +450 -0
- package/src/client/extensions/ExtensionQueryErrorState.tsx +47 -0
- package/src/client/extensions/ExtensionSlot.tsx +345 -0
- package/src/client/extensions/ExtensionViewer.tsx +1502 -0
- package/src/client/extensions/ExtensionViewerPage.tsx +32 -0
- package/src/client/extensions/ExtensionsListPage.tsx +432 -0
- package/src/client/extensions/ExtensionsSidebarSection.tsx +1259 -0
- package/src/client/extensions/InlineExtensionFrame.tsx +660 -0
- package/src/client/extensions/agent-native-extension-runtime.ts +495 -0
- package/src/client/extensions/delete-extension.ts +76 -0
- package/src/client/extensions/extension-load-error.ts +26 -0
- package/src/client/extensions/extension-order.ts +49 -0
- package/src/client/extensions/extension-popularity.ts +61 -0
- package/src/client/extensions/iframe-bridge.ts +377 -0
- package/src/client/extensions/index.ts +84 -0
- package/src/client/extensions/portable-extension.ts +712 -0
- package/src/client/feature-flags/FeatureFlagsPanel.tsx +519 -0
- package/src/client/feature-flags/helpers.ts +77 -0
- package/src/client/feature-flags/index.ts +13 -0
- package/src/client/feature-flags/types.ts +29 -0
- package/src/client/feature-flags/use-feature-flag.ts +26 -0
- package/src/client/feedback-context.ts +90 -0
- package/src/client/frame-protocol.ts +168 -0
- package/src/client/frame.ts +329 -0
- package/src/client/guided-questions.tsx +1152 -0
- package/src/client/history/VersionHistoryPanel.tsx +175 -0
- package/src/client/history/index.ts +21 -0
- package/src/client/history/use-history.ts +114 -0
- package/src/client/hooks/index.ts +46 -0
- package/src/client/host/index.ts +170 -0
- package/src/client/host-bridge.ts +1272 -0
- package/src/client/host-tools.ts +190 -0
- package/src/client/i18n.tsx +798 -0
- package/src/client/index.ts +370 -0
- package/src/client/integrations/IntegrationCard.tsx +186 -0
- package/src/client/integrations/IntegrationsPanel.tsx +633 -0
- package/src/client/integrations/api.ts +295 -0
- package/src/client/integrations/index.ts +29 -0
- package/src/client/integrations/useIntegrationStatus.ts +52 -0
- package/src/client/mcp-app-host.ts +720 -0
- package/src/client/mcp-apps/McpAppRenderer.tsx +760 -0
- package/src/client/navigation/index.ts +54 -0
- package/src/client/notifications/NotificationsBell.tsx +383 -0
- package/src/client/notifications/index.ts +1 -0
- package/src/client/observability/ObservabilityDashboard.tsx +890 -0
- package/src/client/observability/ThumbsFeedback.tsx +160 -0
- package/src/client/observability/index.ts +20 -0
- package/src/client/observability/useObservability.ts +266 -0
- package/src/client/onboarding/OnboardingBanner.tsx +73 -0
- package/src/client/onboarding/OnboardingPanel.tsx +1036 -0
- package/src/client/onboarding/SetupButton.tsx +64 -0
- package/src/client/onboarding/index.ts +25 -0
- package/src/client/onboarding/use-onboarding.ts +164 -0
- package/src/client/onboarding/use-preview-mode.ts +40 -0
- package/src/client/org/InvitationBanner.tsx +148 -0
- package/src/client/org/OrgSwitcher.tsx +754 -0
- package/src/client/org/RequireActiveOrg.tsx +337 -0
- package/src/client/org/TeamPage.tsx +1432 -0
- package/src/client/org/hooks.ts +359 -0
- package/src/client/org/index.ts +70 -0
- package/src/client/org/workspace-app-links.ts +367 -0
- package/src/client/org-team/index.ts +1 -0
- package/src/client/progress/RunsTray.tsx +680 -0
- package/src/client/progress/index.ts +1 -0
- package/src/client/require-session.tsx +142 -0
- package/src/client/resources/BuiltinCapabilityDetail.tsx +258 -0
- package/src/client/resources/McpConnectionSuggestion.tsx +276 -0
- package/src/client/resources/McpIntegrationDialog.tsx +808 -0
- package/src/client/resources/McpServerDetail.tsx +230 -0
- package/src/client/resources/ResourceEditor.tsx +872 -0
- package/src/client/resources/ResourceTree.tsx +860 -0
- package/src/client/resources/ResourcesPanel.tsx +1960 -0
- package/src/client/resources/index.ts +25 -0
- package/src/client/resources/mcp-integration-catalog.ts +771 -0
- package/src/client/resources/mcp-integration-logos.ts +108 -0
- package/src/client/resources/runtime.ts +1 -0
- package/src/client/resources/use-builtin-capabilities.ts +113 -0
- package/src/client/resources/use-mcp-servers.ts +217 -0
- package/src/client/resources/use-resources.ts +402 -0
- package/src/client/review/ReviewCommentComposer.tsx +123 -0
- package/src/client/review/ReviewStatusBadge.tsx +39 -0
- package/src/client/review/ReviewThreadPanel.tsx +625 -0
- package/src/client/review/index.ts +38 -0
- package/src/client/review/use-review.ts +186 -0
- package/src/client/route-chunk-recovery/index.ts +2 -0
- package/src/client/route-chunk-recovery.ts +331 -0
- package/src/client/route-state.ts +455 -0
- package/src/client/route-warmup.tsx +543 -0
- package/src/client/session-replay-iframe.e2e-host.tsx +100 -0
- package/src/client/session-replay.ts +3417 -0
- package/src/client/settings/AgentsSection.tsx +441 -0
- package/src/client/settings/AutomationsSection.tsx +516 -0
- package/src/client/settings/BackgroundAgentSection.tsx +189 -0
- package/src/client/settings/BrowserSection.tsx +110 -0
- package/src/client/settings/DemoModeSection.tsx +48 -0
- package/src/client/settings/SecretsSection.tsx +875 -0
- package/src/client/settings/SettingsPanel.tsx +3162 -0
- package/src/client/settings/SettingsSection.tsx +283 -0
- package/src/client/settings/SettingsTabsPage.tsx +592 -0
- package/src/client/settings/UsageSection.tsx +401 -0
- package/src/client/settings/VoiceTranscriptionSection.tsx +960 -0
- package/src/client/settings/agent-settings-search.ts +220 -0
- package/src/client/settings/index.ts +27 -0
- package/src/client/settings/useBuilderStatus.ts +1055 -0
- package/src/client/setup-connections/BuilderConnectCard.tsx +89 -0
- package/src/client/setup-connections/ProviderReadinessBadge.tsx +73 -0
- package/src/client/setup-connections/SetupConnectionsPage.tsx +94 -0
- package/src/client/setup-connections/catalog.ts +6 -0
- package/src/client/setup-connections/index.ts +47 -0
- package/src/client/setup-connections/runtime.ts +1 -0
- package/src/client/sharing/ShareButton.tsx +1748 -0
- package/src/client/sharing/ShareDialog.tsx +846 -0
- package/src/client/sharing/VisibilityBadge.tsx +4 -0
- package/src/client/sharing/index.ts +2 -0
- package/src/client/sse-event-processor.ts +2002 -0
- package/src/client/terminal/AgentTerminal.tsx +488 -0
- package/src/client/terminal/index.ts +7 -0
- package/src/client/theme.ts +27 -0
- package/src/client/tombstone/agent-presence-chip.ts +17 -0
- package/src/client/tombstone/editor.ts +265 -0
- package/src/client/tombstone/live-cursor-overlay.ts +21 -0
- package/src/client/tombstone/presence-bar.ts +17 -0
- package/src/client/tombstone/recent-edit-highlights.ts +17 -0
- package/src/client/tombstone/remote-selection-rings.ts +21 -0
- package/src/client/tombstone/rich-markdown-editor.ts +265 -0
- package/src/client/tombstone/ui-dialog.ts +49 -0
- package/src/client/tombstone/ui-dropdown-menu.ts +69 -0
- package/src/client/tombstone/ui-hover-card.ts +21 -0
- package/src/client/tombstone/ui-popover.ts +25 -0
- package/src/client/tombstone/ui-sheet.ts +49 -0
- package/src/client/tombstone/ui-tooltip.ts +29 -0
- package/src/client/tombstone/visual-style-controls.ts +61 -0
- package/src/client/tool-cells/BashCell.tsx +164 -0
- package/src/client/tool-cells/EditCell.tsx +303 -0
- package/src/client/tool-cells/FilesChangedSummary.tsx +208 -0
- package/src/client/tool-cells/WriteCell.tsx +145 -0
- package/src/client/tool-cells/index.ts +7 -0
- package/src/client/tool-display.ts +41 -0
- package/src/client/track.ts +57 -0
- package/src/client/transcription/BuilderTranscriptionCta.tsx +120 -0
- package/src/client/transcription/use-live-transcription.ts +292 -0
- package/src/client/ui/index.ts +55 -0
- package/src/client/uploads/index.ts +6 -0
- package/src/client/uploads/upload-editor-image.ts +79 -0
- package/src/client/uploads/use-upload-resource.ts +24 -0
- package/src/client/url-scrub.ts +51 -0
- package/src/client/use-action.ts +797 -0
- package/src/client/use-agent-chat-context.ts +63 -0
- package/src/client/use-agent-chat-home-handoff.ts +207 -0
- package/src/client/use-agent-chat.ts +53 -0
- package/src/client/use-agent-engine-configured.ts +211 -0
- package/src/client/use-avatar.ts +127 -0
- package/src/client/use-change-version.ts +150 -0
- package/src/client/use-chat-models.ts +252 -0
- package/src/client/use-chat-threads.ts +1262 -0
- package/src/client/use-db-sync.ts +1112 -0
- package/src/client/use-demo-mode-status.ts +30 -0
- package/src/client/use-dev-mode.ts +177 -0
- package/src/client/use-external-value.ts +40 -0
- package/src/client/use-pausing-interval.ts +65 -0
- package/src/client/use-pinch-zoom.ts +202 -0
- package/src/client/use-run-stuck-detection.ts +427 -0
- package/src/client/use-send-to-agent-chat.ts +85 -0
- package/src/client/use-session.ts +114 -0
- package/src/client/utils.ts +7 -0
- package/src/client/visual-style-controls.tsx +1 -0
- package/src/client/vite-dev-recovery-script.ts +226 -0
- package/src/client/voice-provider-status.ts +44 -0
- package/src/client/widgets/index.ts +41 -0
- package/src/code-agents/background-controller.ts +398 -0
- package/src/code-agents/background-run.ts +156 -0
- package/src/code-agents/index.ts +95 -0
- package/src/code-agents/prompt-attachments.ts +39 -0
- package/src/code-agents/transcript-normalizer.ts +750 -0
- package/src/code-agents/transcript-order.ts +73 -0
- package/src/coding-tools/index.ts +742 -0
- package/src/coding-tools/run-code.ts +1662 -0
- package/src/coding-tools/sandbox/adapter.ts +82 -0
- package/src/coding-tools/sandbox/background.ts +406 -0
- package/src/coding-tools/sandbox/executions-store.ts +517 -0
- package/src/coding-tools/sandbox/index.ts +132 -0
- package/src/coding-tools/sandbox/local-child-process-adapter.ts +217 -0
- package/src/collab/agent-identity.ts +5 -0
- package/src/collab/agent-presence.ts +341 -0
- package/src/collab/awareness-store.ts +196 -0
- package/src/collab/awareness.ts +317 -0
- package/src/collab/client-struct.ts +366 -0
- package/src/collab/client.ts +1205 -0
- package/src/collab/emitter.ts +31 -0
- package/src/collab/follow-mode.ts +107 -0
- package/src/collab/index.ts +151 -0
- package/src/collab/json-to-yjs.ts +504 -0
- package/src/collab/presence.ts +207 -0
- package/src/collab/recent-edits.ts +215 -0
- package/src/collab/routes.ts +191 -0
- package/src/collab/storage.ts +228 -0
- package/src/collab/struct-routes.ts +133 -0
- package/src/collab/text-to-yjs.ts +79 -0
- package/src/collab/undo.ts +432 -0
- package/src/collab/xml-ops.ts +68 -0
- package/src/collab/ydoc-manager.ts +544 -0
- package/src/command-navigation/actions.ts +100 -0
- package/src/command-navigation/index.ts +12 -0
- package/src/comments-review/index.ts +1 -0
- package/src/connections/catalog.ts +451 -0
- package/src/connections/index.ts +48 -0
- package/src/connections/reader.ts +911 -0
- package/src/connections/runtime.ts +1 -0
- package/src/credentials/index.ts +187 -0
- package/src/data-programs/actions.ts +335 -0
- package/src/data-programs/contract.ts +284 -0
- package/src/data-programs/execute.ts +693 -0
- package/src/data-programs/index.ts +72 -0
- package/src/data-programs/schema.ts +148 -0
- package/src/data-programs/store.ts +755 -0
- package/src/data-widgets/index.ts +376 -0
- package/src/db/client.ts +1627 -0
- package/src/db/create-get-db.ts +579 -0
- package/src/db/ddl-guard.ts +302 -0
- package/src/db/drizzle-config.ts +190 -0
- package/src/db/ensure-additive-columns.ts +430 -0
- package/src/db/index.ts +57 -0
- package/src/db/migrations.ts +691 -0
- package/src/db/request-telemetry.ts +154 -0
- package/src/db/runtime-diagnostics.ts +331 -0
- package/src/db/schema.ts +121 -0
- package/src/db/widen-columns.ts +75 -0
- package/src/db-admin/agent-tools.ts +202 -0
- package/src/db-admin/index.ts +26 -0
- package/src/db-admin/operations.ts +803 -0
- package/src/db-admin/routes.ts +174 -0
- package/src/db-admin/types.ts +110 -0
- package/src/demo/browser-state.ts +47 -0
- package/src/demo/fetch-interceptor.ts +175 -0
- package/src/demo/redact.ts +575 -0
- package/src/deploy/build.ts +3938 -0
- package/src/deploy/immutable-assets.ts +65 -0
- package/src/deploy/route-discovery.ts +458 -0
- package/src/deploy/workspace-core.ts +282 -0
- package/src/deploy/workspace-deploy.ts +1488 -0
- package/src/eject/provider-api-definitions.ts +193 -0
- package/src/eject/remote-mcp-presets.ts +137 -0
- package/src/eject/setup-readiness-ui.tsx +29 -0
- package/src/eject/workspace-connections.ts +92 -0
- package/src/embedding/agent.ts +159 -0
- package/src/embedding/bridge.ts +297 -0
- package/src/embedding/index.ts +43 -0
- package/src/embedding/protocol.ts +185 -0
- package/src/embedding/react.tsx +319 -0
- package/src/embeddings/index.ts +233 -0
- package/src/eval/agent-runner.ts +210 -0
- package/src/eval/define-eval.ts +55 -0
- package/src/eval/index.ts +49 -0
- package/src/eval/report.ts +75 -0
- package/src/eval/runner.ts +369 -0
- package/src/eval/scorer.ts +244 -0
- package/src/eval/types.ts +188 -0
- package/src/event-bus/bus.ts +140 -0
- package/src/event-bus/index.ts +3 -0
- package/src/event-bus/registry.ts +79 -0
- package/src/event-bus/types.ts +29 -0
- package/src/extensions/actions.ts +1636 -0
- package/src/extensions/change-marker.ts +54 -0
- package/src/extensions/content-patch.ts +468 -0
- package/src/extensions/fetch-tool.ts +461 -0
- package/src/extensions/html-shell.ts +803 -0
- package/src/extensions/local.ts +462 -0
- package/src/extensions/path.ts +40 -0
- package/src/extensions/proxy-security.ts +171 -0
- package/src/extensions/routes.ts +1080 -0
- package/src/extensions/schema.ts +269 -0
- package/src/extensions/session-replay-iframe.ts +131 -0
- package/src/extensions/slots/routes.ts +126 -0
- package/src/extensions/slots/schema.ts +87 -0
- package/src/extensions/slots/store.ts +450 -0
- package/src/extensions/store.ts +1347 -0
- package/src/extensions/theme.ts +114 -0
- package/src/extensions/url-safety.ts +316 -0
- package/src/extensions/web-content.ts +663 -0
- package/src/extensions/web-search-tool.ts +437 -0
- package/src/feature-flags/a2a-action-route.ts +56 -0
- package/src/feature-flags/actions/get-feature-flags.ts +24 -0
- package/src/feature-flags/actions/list-feature-flags.ts +69 -0
- package/src/feature-flags/actions/set-feature-flag.ts +89 -0
- package/src/feature-flags/index.ts +21 -0
- package/src/feature-flags/permissions.ts +53 -0
- package/src/feature-flags/plugin.ts +44 -0
- package/src/feature-flags/registry.ts +96 -0
- package/src/feature-flags/store.ts +176 -0
- package/src/file-upload/actions/upload-image.ts +213 -0
- package/src/file-upload/builder.ts +431 -0
- package/src/file-upload/index.ts +24 -0
- package/src/file-upload/pre-upload-attachments.ts +305 -0
- package/src/file-upload/registry.ts +125 -0
- package/src/file-upload/types.ts +89 -0
- package/src/guards/db-tool-scoping.ts +129 -0
- package/src/guards/index.ts +23 -0
- package/src/guards/no-drizzle-push.ts +116 -0
- package/src/guards/no-env-credentials.ts +229 -0
- package/src/guards/no-env-mutation.ts +114 -0
- package/src/guards/no-localhost-fallback.ts +124 -0
- package/src/guards/no-unscoped-credentials.ts +227 -0
- package/src/guards/no-unscoped-queries.ts +834 -0
- package/src/guards/scan-utils.ts +105 -0
- package/src/guards/types.ts +30 -0
- package/src/history/actions/create-resource-version.ts +92 -0
- package/src/history/actions/get-resource-version.ts +60 -0
- package/src/history/actions/list-resource-history.ts +53 -0
- package/src/history/actions/list-resource-versions.ts +43 -0
- package/src/history/actions/restore-resource-version.ts +96 -0
- package/src/history/index.ts +26 -0
- package/src/history/registry.ts +111 -0
- package/src/history/store.ts +379 -0
- package/src/history/types.ts +69 -0
- package/src/index.browser.ts +155 -0
- package/src/index.ts +408 -0
- package/src/ingestion/docx.ts +158 -0
- package/src/ingestion/figma-node-to-html.ts +1860 -0
- package/src/ingestion/figma.ts +548 -0
- package/src/ingestion/index.ts +107 -0
- package/src/ingestion/media.ts +264 -0
- package/src/ingestion/notion.ts +121 -0
- package/src/ingestion/office.ts +213 -0
- package/src/ingestion/orchestration.ts +160 -0
- package/src/ingestion/pptx.ts +331 -0
- package/src/ingestion/selection.ts +81 -0
- package/src/ingestion/website.ts +151 -0
- package/src/integrations/a2a-continuation-marker.ts +2 -0
- package/src/integrations/a2a-continuation-processor.ts +888 -0
- package/src/integrations/a2a-continuations-store.ts +643 -0
- package/src/integrations/adapter-overrides.ts +12 -0
- package/src/integrations/adapters/discord.ts +364 -0
- package/src/integrations/adapters/email.ts +1164 -0
- package/src/integrations/adapters/google-docs.ts +371 -0
- package/src/integrations/adapters/index.ts +29 -0
- package/src/integrations/adapters/microsoft-teams.ts +413 -0
- package/src/integrations/adapters/slack.ts +1914 -0
- package/src/integrations/adapters/telegram.ts +386 -0
- package/src/integrations/adapters/whatsapp.ts +358 -0
- package/src/integrations/awaiting-input-store.ts +130 -0
- package/src/integrations/catalog.ts +571 -0
- package/src/integrations/computer-supervision-store.ts +423 -0
- package/src/integrations/computer-supervision.ts +213 -0
- package/src/integrations/config-store.ts +131 -0
- package/src/integrations/controls-store.ts +187 -0
- package/src/integrations/eject/messaging-adapters.ts +85 -0
- package/src/integrations/google-docs-poller.ts +671 -0
- package/src/integrations/identity-links-store.ts +210 -0
- package/src/integrations/identity.ts +196 -0
- package/src/integrations/index.ts +220 -0
- package/src/integrations/installations-store.ts +677 -0
- package/src/integrations/integration-memory.ts +187 -0
- package/src/integrations/internal-token.ts +106 -0
- package/src/integrations/pending-tasks-retry-job.ts +286 -0
- package/src/integrations/pending-tasks-store.ts +468 -0
- package/src/integrations/plugin.ts +3048 -0
- package/src/integrations/remote-commands-store.ts +690 -0
- package/src/integrations/remote-devices-store.ts +492 -0
- package/src/integrations/remote-json-safety.ts +127 -0
- package/src/integrations/remote-push-delivery-job.ts +48 -0
- package/src/integrations/remote-push-delivery.ts +370 -0
- package/src/integrations/remote-push-store.ts +664 -0
- package/src/integrations/remote-retry-job.ts +55 -0
- package/src/integrations/remote-run-events-store.ts +222 -0
- package/src/integrations/remote-types.ts +186 -0
- package/src/integrations/runtime.ts +1 -0
- package/src/integrations/scope-store.ts +498 -0
- package/src/integrations/slack-manifest.ts +78 -0
- package/src/integrations/slack-oauth.ts +344 -0
- package/src/integrations/task-queue-stats.ts +144 -0
- package/src/integrations/thread-mapping-store.ts +134 -0
- package/src/integrations/types.ts +485 -0
- package/src/integrations/usage-budget-store.ts +906 -0
- package/src/integrations/webhook-delivery.ts +55 -0
- package/src/integrations/webhook-handler.ts +1939 -0
- package/src/jobs/actions/list-recurring-jobs.ts +105 -0
- package/src/jobs/actions/manage-recurring-job.ts +85 -0
- package/src/jobs/cron.ts +126 -0
- package/src/jobs/index.ts +9 -0
- package/src/jobs/scheduler.ts +703 -0
- package/src/jobs/tools.ts +367 -0
- package/src/local-artifacts/index.ts +1372 -0
- package/src/localization/actions/get-localization-preference.ts +24 -0
- package/src/localization/actions/set-localization-preference.ts +32 -0
- package/src/localization/default-messages.ts +1009 -0
- package/src/localization/index.ts +2 -0
- package/src/localization/server.ts +131 -0
- package/src/localization/shared.ts +208 -0
- package/src/mcp/actions/call-mcp-tool.ts +19 -0
- package/src/mcp/actions/create-org-service-token.ts +87 -0
- package/src/mcp/actions/list-mcp-tools.ts +18 -0
- package/src/mcp/actions/list-org-service-tokens.ts +44 -0
- package/src/mcp/actions/revoke-org-service-token.ts +30 -0
- package/src/mcp/actions/service-token-access.ts +121 -0
- package/src/mcp/ask-app-inline-tasks.ts +125 -0
- package/src/mcp/build-server.ts +2356 -0
- package/src/mcp/builtin-tools.ts +1506 -0
- package/src/mcp/connect-route.ts +1460 -0
- package/src/mcp/connect-store.ts +680 -0
- package/src/mcp/embed-app.ts +2051 -0
- package/src/mcp/embed-route.ts +84 -0
- package/src/mcp/external-agent-policy.ts +18 -0
- package/src/mcp/index.ts +47 -0
- package/src/mcp/oauth-route.ts +1016 -0
- package/src/mcp/oauth-store.ts +581 -0
- package/src/mcp/oauth-token.ts +227 -0
- package/src/mcp/org-directory.ts +343 -0
- package/src/mcp/route-paths.ts +34 -0
- package/src/mcp/screen-memory-stdio.ts +290 -0
- package/src/mcp/server.ts +507 -0
- package/src/mcp/stdio.ts +328 -0
- package/src/mcp/workspace-resolve.ts +261 -0
- package/src/mcp-client/app-api.ts +136 -0
- package/src/mcp-client/app-result.ts +64 -0
- package/src/mcp-client/builtin-capabilities.ts +146 -0
- package/src/mcp-client/builtin-store.ts +93 -0
- package/src/mcp-client/config.ts +281 -0
- package/src/mcp-client/errors.ts +54 -0
- package/src/mcp-client/hub-client.ts +172 -0
- package/src/mcp-client/hub-routes.ts +198 -0
- package/src/mcp-client/index.ts +504 -0
- package/src/mcp-client/manager.ts +968 -0
- package/src/mcp-client/oauth-client.ts +462 -0
- package/src/mcp-client/oauth-routes.ts +307 -0
- package/src/mcp-client/remote-store.ts +674 -0
- package/src/mcp-client/remote-url.ts +97 -0
- package/src/mcp-client/routes.ts +1093 -0
- package/src/mcp-client/screen-memory-local.ts +461 -0
- package/src/mcp-client/tool-policy.ts +182 -0
- package/src/mcp-client/visibility.ts +56 -0
- package/src/mcp-client/workspace-servers.ts +379 -0
- package/src/navigation/index.ts +170 -0
- package/src/notifications/actions.ts +151 -0
- package/src/notifications/channels.ts +410 -0
- package/src/notifications/index.ts +22 -0
- package/src/notifications/registry.ts +216 -0
- package/src/notifications/routes.ts +106 -0
- package/src/notifications/store.ts +236 -0
- package/src/notifications/types.ts +52 -0
- package/src/oauth-tokens/google-refresh.ts +175 -0
- package/src/oauth-tokens/index.ts +15 -0
- package/src/oauth-tokens/store.ts +384 -0
- package/src/observability/cleanup-job.ts +124 -0
- package/src/observability/evals.ts +507 -0
- package/src/observability/experiments.ts +359 -0
- package/src/observability/feedback.ts +332 -0
- package/src/observability/hosted-model-experiment.ts +118 -0
- package/src/observability/index.ts +62 -0
- package/src/observability/plugin.ts +31 -0
- package/src/observability/routes.ts +431 -0
- package/src/observability/sentiment.ts +261 -0
- package/src/observability/store.ts +1347 -0
- package/src/observability/traces.ts +789 -0
- package/src/observability/tracing.ts +157 -0
- package/src/observability/tracking-identity.ts +55 -0
- package/src/observability/types.ts +211 -0
- package/src/onboarding/default-steps.ts +428 -0
- package/src/onboarding/index.ts +22 -0
- package/src/onboarding/plugin.ts +262 -0
- package/src/onboarding/registry.ts +47 -0
- package/src/onboarding/types.ts +96 -0
- package/src/org/accept-pending.ts +98 -0
- package/src/org/auto-join-domain.ts +113 -0
- package/src/org/context.ts +640 -0
- package/src/org/free-email-providers.ts +124 -0
- package/src/org/handlers.ts +1153 -0
- package/src/org/index.ts +63 -0
- package/src/org/migrations.ts +105 -0
- package/src/org/permissions.ts +30 -0
- package/src/org/plugin.ts +255 -0
- package/src/org/schema.ts +28 -0
- package/src/org/types.ts +57 -0
- package/src/org-team/index.ts +1 -0
- package/src/package-lifecycle/deprecated-imports.ts +179 -0
- package/src/package-lifecycle/eject-manifest.ts +345 -0
- package/src/package-lifecycle/index.ts +7 -0
- package/src/package-lifecycle/manifest.ts +120 -0
- package/src/package-lifecycle/migration-manifest.ts +159 -0
- package/src/package-lifecycle/migration-message.ts +6 -0
- package/src/package-lifecycle/tombstone.ts +58 -0
- package/src/package-lifecycle/upgrade-error.ts +37 -0
- package/src/private-blob/index.ts +18 -0
- package/src/private-blob/registry.ts +242 -0
- package/src/private-blob/types.ts +55 -0
- package/src/progress/actions.ts +179 -0
- package/src/progress/index.ts +16 -0
- package/src/progress/registry.ts +127 -0
- package/src/progress/routes.ts +89 -0
- package/src/progress/store.ts +353 -0
- package/src/progress/types.ts +59 -0
- package/src/provider-api/actions/custom-provider-registration.ts +197 -0
- package/src/provider-api/actions/delete-staged-dataset.ts +5 -0
- package/src/provider-api/actions/github-repo-files.ts +266 -0
- package/src/provider-api/actions/list-staged-datasets.ts +5 -0
- package/src/provider-api/actions/provider-api-audit.ts +88 -0
- package/src/provider-api/actions/provider-api.ts +460 -0
- package/src/provider-api/actions/query-staged-dataset.ts +5 -0
- package/src/provider-api/actions/staged-datasets.ts +359 -0
- package/src/provider-api/corpus-jobs-store.ts +522 -0
- package/src/provider-api/corpus-jobs.ts +1817 -0
- package/src/provider-api/custom-registry.ts +456 -0
- package/src/provider-api/github-repo.ts +675 -0
- package/src/provider-api/gong.ts +108 -0
- package/src/provider-api/index.ts +5444 -0
- package/src/provider-api/quota-governor.ts +562 -0
- package/src/provider-api/runtime.ts +1 -0
- package/src/provider-api/staged-datasets-aggregate.ts +304 -0
- package/src/provider-api/staged-datasets-store.ts +441 -0
- package/src/provider-api/staging.ts +483 -0
- package/src/resources/agents.ts +65 -0
- package/src/resources/emitter.ts +54 -0
- package/src/resources/handlers.ts +728 -0
- package/src/resources/index.ts +4 -0
- package/src/resources/metadata.ts +252 -0
- package/src/resources/script-helpers.ts +160 -0
- package/src/resources/store.ts +1618 -0
- package/src/review/actions/consume-review-feedback.ts +48 -0
- package/src/review/actions/create-review-comment.ts +108 -0
- package/src/review/actions/delete-review-comment.ts +67 -0
- package/src/review/actions/get-review-feedback.ts +49 -0
- package/src/review/actions/list-review-comments.ts +87 -0
- package/src/review/actions/reply-review-comment.ts +118 -0
- package/src/review/actions/resolve-review-thread.ts +94 -0
- package/src/review/actions/send-review-thread-to-agent.ts +62 -0
- package/src/review/actions/set-review-status.ts +58 -0
- package/src/review/identity.ts +101 -0
- package/src/review/index.ts +45 -0
- package/src/review/mentions.ts +44 -0
- package/src/review/registry.ts +111 -0
- package/src/review/store.ts +997 -0
- package/src/review/types.ts +101 -0
- package/src/router/index.ts +24 -0
- package/src/scripts/agent-engines/list-agent-engines.ts +130 -0
- package/src/scripts/agent-engines/manage-agent-engine.ts +197 -0
- package/src/scripts/agent-engines/set-agent-engine.ts +84 -0
- package/src/scripts/agent-engines/test-agent-engine.ts +174 -0
- package/src/scripts/call-agent.ts +792 -0
- package/src/scripts/chat/index.ts +8 -0
- package/src/scripts/chat/open-chat.ts +56 -0
- package/src/scripts/chat/search-chats.ts +121 -0
- package/src/scripts/core-scripts.ts +22 -0
- package/src/scripts/db/check-scoping.ts +212 -0
- package/src/scripts/db/exec.ts +791 -0
- package/src/scripts/db/index.ts +19 -0
- package/src/scripts/db/migrate-encrypt-credentials.ts +223 -0
- package/src/scripts/db/migrate-encrypt-oauth-tokens.ts +213 -0
- package/src/scripts/db/migrate-user-api-keys.ts +257 -0
- package/src/scripts/db/patch.ts +820 -0
- package/src/scripts/db/query.ts +299 -0
- package/src/scripts/db/reset-dev-owner.ts +285 -0
- package/src/scripts/db/safety.ts +286 -0
- package/src/scripts/db/schema.ts +364 -0
- package/src/scripts/db/scoping.ts +341 -0
- package/src/scripts/db/sqlite-client.ts +78 -0
- package/src/scripts/db/tool-mode.ts +23 -0
- package/src/scripts/db/tool-schemas.ts +31 -0
- package/src/scripts/db/wipe-leaked-builder-keys.ts +201 -0
- package/src/scripts/dev/index.ts +296 -0
- package/src/scripts/dev/list-files.ts +119 -0
- package/src/scripts/dev/read-file.ts +77 -0
- package/src/scripts/dev/search-files.ts +151 -0
- package/src/scripts/dev/shell.ts +111 -0
- package/src/scripts/dev/write-file.ts +56 -0
- package/src/scripts/dev-session.ts +96 -0
- package/src/scripts/docs/index.ts +8 -0
- package/src/scripts/docs/search.ts +274 -0
- package/src/scripts/docs/source-search.ts +363 -0
- package/src/scripts/index.ts +15 -0
- package/src/scripts/manage-agent-loop-settings.ts +84 -0
- package/src/scripts/parse-args.ts +46 -0
- package/src/scripts/resources/delete-memory.ts +67 -0
- package/src/scripts/resources/delete.ts +69 -0
- package/src/scripts/resources/effective.ts +71 -0
- package/src/scripts/resources/index.ts +18 -0
- package/src/scripts/resources/list.ts +103 -0
- package/src/scripts/resources/migrate-learnings.ts +40 -0
- package/src/scripts/resources/read.ts +107 -0
- package/src/scripts/resources/save-memory.ts +99 -0
- package/src/scripts/resources/write.ts +158 -0
- package/src/scripts/runner.ts +339 -0
- package/src/scripts/utils.ts +130 -0
- package/src/search/index.ts +413 -0
- package/src/search-utils/index.ts +112 -0
- package/src/secrets/crypto.ts +228 -0
- package/src/secrets/index.ts +65 -0
- package/src/secrets/onboarding.ts +101 -0
- package/src/secrets/register-framework-secrets.ts +228 -0
- package/src/secrets/register.ts +129 -0
- package/src/secrets/routes.ts +697 -0
- package/src/secrets/schema.ts +52 -0
- package/src/secrets/storage.ts +561 -0
- package/src/secrets/substitution.ts +305 -0
- package/src/server/__snapshots__/agent-chat-plugin.surface.spec.ts.snap +150 -0
- package/src/server/action-change.ts +66 -0
- package/src/server/action-discovery.ts +774 -0
- package/src/server/action-routes.ts +658 -0
- package/src/server/agent-access.ts +72 -0
- package/src/server/agent-chat/action-filters-a2a.ts +339 -0
- package/src/server/agent-chat/browser-team-tools.ts +510 -0
- package/src/server/agent-chat/context-tools.ts +599 -0
- package/src/server/agent-chat/framework-prompts.ts +467 -0
- package/src/server/agent-chat/lazy-fs.ts +11 -0
- package/src/server/agent-chat/mcp-glue.ts +91 -0
- package/src/server/agent-chat/plugin-options.ts +379 -0
- package/src/server/agent-chat/process-run-failure.ts +62 -0
- package/src/server/agent-chat/prompt-resources.ts +1004 -0
- package/src/server/agent-chat/recurring-jobs-runtime.ts +80 -0
- package/src/server/agent-chat/request-surface.ts +71 -0
- package/src/server/agent-chat/run-code-tools.ts +67 -0
- package/src/server/agent-chat/script-entries.ts +796 -0
- package/src/server/agent-chat/shared-thread.ts +301 -0
- package/src/server/agent-chat/skill-frontmatter.ts +41 -0
- package/src/server/agent-chat-plugin.ts +5930 -0
- package/src/server/agent-discovery.ts +706 -0
- package/src/server/agent-engine-api-key-route.ts +236 -0
- package/src/server/agent-run-context.ts +204 -0
- package/src/server/agent-teams-run-queue.ts +344 -0
- package/src/server/agent-teams.ts +2257 -0
- package/src/server/agents-bundle.ts +464 -0
- package/src/server/analytics.ts +105 -0
- package/src/server/app-base-path.ts +79 -0
- package/src/server/app-name.ts +53 -0
- package/src/server/app-url.ts +184 -0
- package/src/server/attachment-actions.ts +276 -0
- package/src/server/attribution.ts +214 -0
- package/src/server/auth-marketing.ts +260 -0
- package/src/server/auth-plugin.ts +32 -0
- package/src/server/auth.ts +3803 -0
- package/src/server/better-auth-instance.ts +1201 -0
- package/src/server/builder-browser.ts +1701 -0
- package/src/server/builder-design-systems.ts +668 -0
- package/src/server/builder-space.ts +176 -0
- package/src/server/captcha.ts +63 -0
- package/src/server/capture-error.ts +64 -0
- package/src/server/cli-capture.ts +141 -0
- package/src/server/collab-plugin.ts +391 -0
- package/src/server/complete-text.ts +231 -0
- package/src/server/cookie-namespace.ts +159 -0
- package/src/server/core-routes-plugin.ts +4122 -0
- package/src/server/cors-origins.ts +60 -0
- package/src/server/create-server.ts +268 -0
- package/src/server/credential-provider.ts +1202 -0
- package/src/server/csrf.ts +229 -0
- package/src/server/date-utils.ts +42 -0
- package/src/server/deep-link.ts +119 -0
- package/src/server/derived-secret.ts +32 -0
- package/src/server/design-token-utils.ts +1032 -0
- package/src/server/desktop-sso.ts +83 -0
- package/src/server/edge.ts +69 -0
- package/src/server/email-actions.ts +218 -0
- package/src/server/email-template.ts +192 -0
- package/src/server/email-templates.ts +148 -0
- package/src/server/email.ts +219 -0
- package/src/server/embed-route.ts +283 -0
- package/src/server/embed-session.ts +805 -0
- package/src/server/embedded.ts +252 -0
- package/src/server/entry-server.tsx +154 -0
- package/src/server/framework-request-handler.ts +848 -0
- package/src/server/fusion-app.ts +447 -0
- package/src/server/google-auth-mode.ts +34 -0
- package/src/server/google-auth-plugin.ts +496 -0
- package/src/server/google-oauth-credentials.ts +128 -0
- package/src/server/google-oauth.ts +972 -0
- package/src/server/google-realtime-session.ts +182 -0
- package/src/server/h3-helpers.ts +174 -0
- package/src/server/http-response-telemetry.ts +396 -0
- package/src/server/identity-sso-store.ts +304 -0
- package/src/server/identity-sso.ts +514 -0
- package/src/server/index.ts +593 -0
- package/src/server/missing-key.ts +36 -0
- package/src/server/oauth-helpers.ts +44 -0
- package/src/server/oauth-public-origin.ts +44 -0
- package/src/server/oauth-return-url.ts +120 -0
- package/src/server/og-fonts-data.ts +15 -0
- package/src/server/og-fonts.ts +75 -0
- package/src/server/onboarding-html.ts +4040 -0
- package/src/server/open-route.ts +311 -0
- package/src/server/org-admin.ts +28 -0
- package/src/server/poll-events.ts +88 -0
- package/src/server/poll.ts +1224 -0
- package/src/server/prompts/framework-core-compact.ts +107 -0
- package/src/server/prompts/framework-core.ts +143 -0
- package/src/server/prompts/index.ts +16 -0
- package/src/server/prompts/model-overlays.ts +54 -0
- package/src/server/prompts/shared-rules.ts +104 -0
- package/src/server/realtime-voice.ts +967 -0
- package/src/server/recap-image-route.ts +242 -0
- package/src/server/recap-image-store.ts +185 -0
- package/src/server/request-context.ts +416 -0
- package/src/server/request-origin.ts +67 -0
- package/src/server/resources-plugin.ts +119 -0
- package/src/server/schema-prompt.ts +429 -0
- package/src/server/scoped-key-storage.ts +223 -0
- package/src/server/security-headers.ts +170 -0
- package/src/server/self-dispatch.ts +224 -0
- package/src/server/sentry-config.ts +73 -0
- package/src/server/sentry-plugin.ts +138 -0
- package/src/server/sentry.ts +444 -0
- package/src/server/short-lived-token.ts +170 -0
- package/src/server/social-og-image.ts +454 -0
- package/src/server/sse.ts +102 -0
- package/src/server/ssr-handler.ts +466 -0
- package/src/server/transcribe-voice.ts +1076 -0
- package/src/server/voice-providers-status.ts +118 -0
- package/src/server/workspace-oauth.ts +31 -0
- package/src/server/workspace-provider-oauth.ts +970 -0
- package/src/session-replay-iframe-protocol.ts +58 -0
- package/src/settings/handlers.ts +44 -0
- package/src/settings/index.ts +34 -0
- package/src/settings/org-settings.ts +83 -0
- package/src/settings/script-helpers.ts +24 -0
- package/src/settings/store.ts +247 -0
- package/src/settings/user-settings.ts +47 -0
- package/src/setup-connections/index.ts +90 -0
- package/src/setup-connections/onboarding.ts +47 -0
- package/src/shared/agent-access.ts +112 -0
- package/src/shared/agent-chat.ts +124 -0
- package/src/shared/agent-env.ts +46 -0
- package/src/shared/agent-readable-resource.ts +111 -0
- package/src/shared/agent-sidebar-url.ts +39 -0
- package/src/shared/cache-control.ts +25 -0
- package/src/shared/cloudflare-globals.d.ts +34 -0
- package/src/shared/context-xray.ts +172 -0
- package/src/shared/embed-auth.ts +6 -0
- package/src/shared/index.ts +83 -0
- package/src/shared/llm-connection.ts +42 -0
- package/src/shared/markdown-block-split.ts +129 -0
- package/src/shared/mcp-connect-content.ts +130 -0
- package/src/shared/mcp-embed-headers.ts +175 -0
- package/src/shared/mcp-integration-config.ts +101 -0
- package/src/shared/merge-by-id.ts +14 -0
- package/src/shared/oauth-state.ts +39 -0
- package/src/shared/reasoning-effort.ts +228 -0
- package/src/shared/route-warmup-config.ts +128 -0
- package/src/shared/runtime.ts +31 -0
- package/src/shared/social-meta.ts +82 -0
- package/src/shared/streaming-text-smoothing.ts +184 -0
- package/src/shared/truncate.ts +13 -0
- package/src/shared/workspace-app-audience.ts +177 -0
- package/src/shared/workspace-app-id.ts +54 -0
- package/src/sharing/access.ts +585 -0
- package/src/sharing/actions/create-agent-resource-link.ts +91 -0
- package/src/sharing/actions/extension-change.ts +22 -0
- package/src/sharing/actions/list-resource-shares.ts +93 -0
- package/src/sharing/actions/set-resource-visibility.ts +91 -0
- package/src/sharing/actions/share-resource.ts +322 -0
- package/src/sharing/actions/unshare-resource.ts +72 -0
- package/src/sharing/index.ts +35 -0
- package/src/sharing/registry.ts +201 -0
- package/src/sharing/schema.ts +99 -0
- package/src/styles/agent-conversation.css +766 -0
- package/src/styles/agent-native.css +938 -0
- package/src/styles/blocks.css +1717 -0
- package/src/styles/chat-history-list.css +1 -0
- package/src/styles/rich-markdown-editor.css +1 -0
- package/src/tailwind.preset.ts +140 -0
- package/src/templates/chat/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/src/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/src/templates/chat/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/src/templates/chat/AGENTS.md +3 -2
- package/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/src/templates/default/AGENTS.md +6 -5
- package/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/src/templates/headless/AGENTS.md +5 -4
- package/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +3 -2
- package/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/src/templates/workspace-core/AGENTS.md +4 -4
- package/src/templates/workspace-root/AGENTS.md +4 -4
- package/src/terminal/cli-registry.ts +57 -0
- package/src/terminal/index.ts +22 -0
- package/src/terminal/pty-server.ts +389 -0
- package/src/terminal/terminal-plugin.ts +265 -0
- package/src/testing.ts +23 -0
- package/src/tracking/index.ts +10 -0
- package/src/tracking/providers.ts +422 -0
- package/src/tracking/registry.ts +102 -0
- package/src/tracking/route.ts +108 -0
- package/src/tracking/types.ts +16 -0
- package/src/transcription/builder-transcription.ts +118 -0
- package/src/triggers/actions/list-automations.ts +99 -0
- package/src/triggers/actions/manage-automation.ts +78 -0
- package/src/triggers/actions.ts +333 -0
- package/src/triggers/condition-evaluator.ts +163 -0
- package/src/triggers/dispatcher.ts +536 -0
- package/src/triggers/index.ts +13 -0
- package/src/triggers/routes.ts +322 -0
- package/src/triggers/types.ts +42 -0
- package/src/types/pglite.d.ts +26 -0
- package/src/usage/store.ts +698 -0
- package/src/vite/action-types-plugin.ts +481 -0
- package/src/vite/agent-web-plugin.ts +78 -0
- package/src/vite/agents-bundle-plugin.ts +185 -0
- package/src/vite/client.ts +3056 -0
- package/src/vite/index.ts +21 -0
- package/src/voice/index.ts +18 -0
- package/src/voice/voice-cleanup-prompt.ts +38 -0
- package/src/voice/voice-context.ts +217 -0
- package/src/voice/voice-replacements.ts +75 -0
- package/src/workspace-connections/credentials.ts +603 -0
- package/src/workspace-connections/index.ts +72 -0
- package/src/workspace-connections/lifecycle.ts +43 -0
- package/src/workspace-connections/store.ts +1943 -0
- package/src/workspace-files/index.ts +18 -0
- package/src/workspace-files/store.ts +339 -0
- package/src/workspace-files/tool.ts +266 -0
|
@@ -0,0 +1,1618 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getDbExec,
|
|
5
|
+
isPostgres,
|
|
6
|
+
intType,
|
|
7
|
+
retryOnDdlRace,
|
|
8
|
+
type DbExec,
|
|
9
|
+
} from "../db/client.js";
|
|
10
|
+
import { ensureColumnExists, ensureTableExists } from "../db/ddl-guard.js";
|
|
11
|
+
import { widenIntColumnsToBigInt } from "../db/widen-columns.js";
|
|
12
|
+
import {
|
|
13
|
+
canUseLocalWorkspaceResourcePath,
|
|
14
|
+
deleteLocalWorkspaceResource,
|
|
15
|
+
isLocalWorkspaceResourceId,
|
|
16
|
+
isLocalWorkspaceResourcesEnabled,
|
|
17
|
+
listLocalWorkspaceResources,
|
|
18
|
+
localWorkspaceResourcePathFromId,
|
|
19
|
+
readLocalWorkspaceResource,
|
|
20
|
+
writeLocalWorkspaceResource,
|
|
21
|
+
type LocalWorkspaceResourceFile,
|
|
22
|
+
type LocalWorkspaceResourceMeta,
|
|
23
|
+
} from "../local-artifacts/index.js";
|
|
24
|
+
import {
|
|
25
|
+
getRequestOrgId,
|
|
26
|
+
getRequestUserEmail,
|
|
27
|
+
} from "../server/request-context.js";
|
|
28
|
+
import type { StoreWriteOptions } from "../settings/store.js";
|
|
29
|
+
import { emitResourceChange, emitResourceDelete } from "./emitter.js";
|
|
30
|
+
|
|
31
|
+
export const SHARED_OWNER = "__shared__";
|
|
32
|
+
export const WORKSPACE_OWNER = "__workspace__";
|
|
33
|
+
const ORGANIZATION_OWNER_PREFIX = "__organization__:";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Encode an organization id into the existing resource owner key. This keeps
|
|
37
|
+
* organization resources isolated without a destructive resources-table
|
|
38
|
+
* migration, while preserving the legacy `__shared__` owner as the app-wide
|
|
39
|
+
* default/fallback used by older deployments and solo mode.
|
|
40
|
+
*/
|
|
41
|
+
export function organizationResourceOwner(orgId: string): string {
|
|
42
|
+
const normalized = orgId.trim();
|
|
43
|
+
if (!normalized) {
|
|
44
|
+
throw new Error("organizationResourceOwner requires a non-empty orgId");
|
|
45
|
+
}
|
|
46
|
+
return `${ORGANIZATION_OWNER_PREFIX}${encodeURIComponent(normalized)}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function organizationIdFromResourceOwner(owner: string): string | null {
|
|
50
|
+
if (!owner.startsWith(ORGANIZATION_OWNER_PREFIX)) return null;
|
|
51
|
+
const encoded = owner.slice(ORGANIZATION_OWNER_PREFIX.length);
|
|
52
|
+
if (!encoded) return null;
|
|
53
|
+
try {
|
|
54
|
+
return decodeURIComponent(encoded);
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Active organization scope, with the legacy app-shared owner as solo fallback. */
|
|
61
|
+
export function sharedResourceOwner(orgId?: string | null): string {
|
|
62
|
+
const activeOrgId = orgId === undefined ? (getRequestOrgId() ?? null) : orgId;
|
|
63
|
+
return activeOrgId ? organizationResourceOwner(activeOrgId) : SHARED_OWNER;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function escapeLike(value: string): string {
|
|
67
|
+
return value.replace(/[!%_]/g, (char) => `!${char}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function prefixLike(value: string): string {
|
|
71
|
+
return `${escapeLike(value)}%`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface Resource {
|
|
75
|
+
id: string;
|
|
76
|
+
path: string;
|
|
77
|
+
owner: string;
|
|
78
|
+
content: string;
|
|
79
|
+
mimeType: string;
|
|
80
|
+
size: number;
|
|
81
|
+
createdAt: number;
|
|
82
|
+
updatedAt: number;
|
|
83
|
+
createdBy: ResourceCreatedBy;
|
|
84
|
+
visibility: ResourceVisibility;
|
|
85
|
+
threadId: string | null;
|
|
86
|
+
runId: string | null;
|
|
87
|
+
expiresAt: number | null;
|
|
88
|
+
metadata: string | null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface ResourceMeta {
|
|
92
|
+
id: string;
|
|
93
|
+
path: string;
|
|
94
|
+
owner: string;
|
|
95
|
+
mimeType: string;
|
|
96
|
+
size: number;
|
|
97
|
+
createdAt: number;
|
|
98
|
+
updatedAt: number;
|
|
99
|
+
createdBy: ResourceCreatedBy;
|
|
100
|
+
visibility: ResourceVisibility;
|
|
101
|
+
threadId: string | null;
|
|
102
|
+
runId: string | null;
|
|
103
|
+
expiresAt: number | null;
|
|
104
|
+
metadata: string | null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export type ResourceCreatedBy = "user" | "agent" | "system";
|
|
108
|
+
export type ResourceVisibility = "workspace" | "agent_scratch";
|
|
109
|
+
|
|
110
|
+
export interface ResourceWriteOptions extends StoreWriteOptions {
|
|
111
|
+
createdBy?: ResourceCreatedBy;
|
|
112
|
+
visibility?: ResourceVisibility;
|
|
113
|
+
threadId?: string | null;
|
|
114
|
+
runId?: string | null;
|
|
115
|
+
expiresAt?: number | null;
|
|
116
|
+
metadata?: string | Record<string, unknown> | null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface ResourceListOptions {
|
|
120
|
+
includeAgentScratch?: boolean;
|
|
121
|
+
workspaceAppId?: string | null;
|
|
122
|
+
userEmail?: string | null;
|
|
123
|
+
orgId?: string | null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface ResourceResolutionOptions {
|
|
127
|
+
workspaceAppId?: string | null;
|
|
128
|
+
userEmail?: string | null;
|
|
129
|
+
orgId?: string | null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export type ResourceInheritanceScope = "workspace" | "shared" | "personal";
|
|
133
|
+
|
|
134
|
+
export interface EffectiveResourceLayer {
|
|
135
|
+
scope: ResourceInheritanceScope;
|
|
136
|
+
label: string;
|
|
137
|
+
owner: string;
|
|
138
|
+
resource: ResourceMeta | null;
|
|
139
|
+
exists: boolean;
|
|
140
|
+
effective: boolean;
|
|
141
|
+
overridden: boolean;
|
|
142
|
+
canWrite: boolean;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface EffectiveResourceContext {
|
|
146
|
+
path: string;
|
|
147
|
+
effectiveResource: ResourceMeta | null;
|
|
148
|
+
effectiveScope: ResourceInheritanceScope | null;
|
|
149
|
+
layers: EffectiveResourceLayer[];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let _initPromise: Promise<void> | undefined;
|
|
153
|
+
let _lastScratchCleanupAt = 0;
|
|
154
|
+
|
|
155
|
+
const AGENT_SCRATCH_TTL_MS = 24 * 60 * 60 * 1000;
|
|
156
|
+
const SCRATCH_CLEANUP_INTERVAL_MS = 60 * 1000;
|
|
157
|
+
const RESOURCE_META_SELECT =
|
|
158
|
+
"id, path, owner, mime_type, size, created_at, updated_at, created_by, visibility, thread_id, run_id, expires_at, metadata";
|
|
159
|
+
const DISPATCH_WORKSPACE_RESOURCE_ID_PREFIX = "dispatch-workspace-resource:";
|
|
160
|
+
const DISPATCH_WORKSPACE_RESOURCE_METADATA_SOURCE =
|
|
161
|
+
"dispatch-workspace-resource";
|
|
162
|
+
export const LOCAL_WORKSPACE_RESOURCE_METADATA_SOURCE =
|
|
163
|
+
"local-workspace-resource";
|
|
164
|
+
|
|
165
|
+
const DEFAULT_LEARNINGS_SHARED_MD = `# Learnings
|
|
166
|
+
|
|
167
|
+
User preferences, corrections, and patterns. The agent reads this at the start of every conversation.
|
|
168
|
+
|
|
169
|
+
Keep this file tidy — revise, consolidate, and remove outdated entries. Don't just append forever.
|
|
170
|
+
|
|
171
|
+
## Preferences
|
|
172
|
+
|
|
173
|
+
## Corrections
|
|
174
|
+
|
|
175
|
+
## Patterns
|
|
176
|
+
`;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Read the project-root learnings seed file for the shared LEARNINGS.md
|
|
180
|
+
* resource. Prefers `learnings.md` (scaffolded by `create.ts`, possibly
|
|
181
|
+
* customized locally), then the checked-in `learnings.defaults.md` — the
|
|
182
|
+
* scaffolded copy is gitignored, so production deploys built from git only
|
|
183
|
+
* carry the defaults file. Returns null when neither file is present, both
|
|
184
|
+
* are empty, or fs is unavailable (e.g. edge runtimes) so seeding falls back
|
|
185
|
+
* to the built-in default. Only consulted on first insert (INSERT OR IGNORE),
|
|
186
|
+
* so an existing LEARNINGS.md resource is never overwritten.
|
|
187
|
+
*/
|
|
188
|
+
async function readProjectRootLearningsSeed(): Promise<string | null> {
|
|
189
|
+
try {
|
|
190
|
+
const [fs, path] = await Promise.all([import("fs"), import("path")]);
|
|
191
|
+
for (const name of ["learnings.md", "learnings.defaults.md"]) {
|
|
192
|
+
const filePath = path.resolve(process.cwd(), name);
|
|
193
|
+
if (!fs.existsSync(filePath)) continue;
|
|
194
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
195
|
+
if (content.trim()) return content;
|
|
196
|
+
}
|
|
197
|
+
return null;
|
|
198
|
+
} catch {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const DEFAULT_LEARNINGS_PERSONAL_MD = `# My Learnings
|
|
204
|
+
|
|
205
|
+
Personal preferences, corrections, and patterns — only visible to you.
|
|
206
|
+
|
|
207
|
+
## Preferences
|
|
208
|
+
|
|
209
|
+
## Corrections
|
|
210
|
+
|
|
211
|
+
## Patterns
|
|
212
|
+
`;
|
|
213
|
+
|
|
214
|
+
const DEFAULT_SKILL_LEARN_MD = `---
|
|
215
|
+
name: learn
|
|
216
|
+
description: >-
|
|
217
|
+
Review the conversation and save structured memories for future sessions.
|
|
218
|
+
user-invocable: true
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
# Learn
|
|
222
|
+
|
|
223
|
+
Review the current conversation and save anything worth remembering using the structured memory system.
|
|
224
|
+
|
|
225
|
+
## Memory types
|
|
226
|
+
|
|
227
|
+
- **user** — Preferences, role, personal context, contacts
|
|
228
|
+
- **feedback** — Corrections ("don't do X, do Y instead"), confirmed approaches
|
|
229
|
+
- **project** — Ongoing work context, decisions, status
|
|
230
|
+
- **reference** — Pointers to external systems, URLs, API details
|
|
231
|
+
|
|
232
|
+
## Steps
|
|
233
|
+
|
|
234
|
+
1. Review the conversation for new insights
|
|
235
|
+
2. Check your memory index with the \`resources\` tool: \`action: "read"\`, \`path: "memory/MEMORY.md"\`
|
|
236
|
+
3. For each new insight, use \`save-memory\` with a descriptive name, type, and content
|
|
237
|
+
4. If updating an existing memory, read it first with the \`resources\` tool (\`action: "read"\`, \`path: "memory/<name>.md"\`), then save with merged content
|
|
238
|
+
|
|
239
|
+
## What NOT to capture
|
|
240
|
+
|
|
241
|
+
- Things obvious from reading the code
|
|
242
|
+
- Standard language/framework behavior
|
|
243
|
+
- Temporary debugging notes
|
|
244
|
+
- Anything already in AGENTS.md or other skills
|
|
245
|
+
|
|
246
|
+
Keep one memory per logical topic. Descriptions should be concise — the index is loaded every conversation.
|
|
247
|
+
`;
|
|
248
|
+
|
|
249
|
+
const DEFAULT_SKILL_LEARN_SHARED_MD = `---
|
|
250
|
+
name: learn-shared
|
|
251
|
+
description: >-
|
|
252
|
+
Update the shared LEARNINGS.md with team-wide preferences, corrections, and
|
|
253
|
+
patterns from this session.
|
|
254
|
+
user-invocable: true
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
# Learn (Shared)
|
|
258
|
+
|
|
259
|
+
Review the current conversation and update the shared \`LEARNINGS.md\` resource with anything the whole team should know.
|
|
260
|
+
|
|
261
|
+
## What to capture
|
|
262
|
+
|
|
263
|
+
- **Team conventions** — agreed-upon approaches, code style decisions
|
|
264
|
+
- **Technical learnings** — API quirks, library gotchas, surprising behavior
|
|
265
|
+
- **Architectural decisions** — why something is done a certain way
|
|
266
|
+
- **Corrections** — mistakes that any team member's agent should avoid
|
|
267
|
+
|
|
268
|
+
## What NOT to capture
|
|
269
|
+
|
|
270
|
+
- Personal preferences (use \`/learn\` for those)
|
|
271
|
+
- Things obvious from reading the code
|
|
272
|
+
- Standard language/framework behavior
|
|
273
|
+
|
|
274
|
+
## Steps
|
|
275
|
+
|
|
276
|
+
1. Read shared learnings with the \`resources\` tool: \`action: "read"\`, \`path: "LEARNINGS.md"\`, \`scope: "shared"\`
|
|
277
|
+
2. Review the conversation for team-relevant insights
|
|
278
|
+
3. Merge new learnings with existing ones — don't duplicate, refine existing entries
|
|
279
|
+
4. Write back with the \`resources\` tool: \`action: "write"\`, \`path: "LEARNINGS.md"\`, \`scope: "shared"\`, \`content: "..."\`
|
|
280
|
+
|
|
281
|
+
Keep entries concise — one line per learning, grouped by category (Conventions, Technical, Patterns).
|
|
282
|
+
`;
|
|
283
|
+
|
|
284
|
+
const DEFAULT_AGENTS_SHARED_MD = `# Agent Instructions
|
|
285
|
+
|
|
286
|
+
This file customizes how the AI agent behaves in this app. Edit it to add your own instructions, preferences, and context.
|
|
287
|
+
|
|
288
|
+
Workspace-level resources managed from Dispatch are inherited before this file.
|
|
289
|
+
Use this shared app/organization file to override or narrow those defaults for
|
|
290
|
+
this app or team.
|
|
291
|
+
|
|
292
|
+
## What to put here
|
|
293
|
+
|
|
294
|
+
- **Preferences** — Tone, style, verbosity, response format
|
|
295
|
+
- **Context** — Domain knowledge, terminology, team conventions
|
|
296
|
+
- **Rules** — Things the agent should always/never do
|
|
297
|
+
- **Skills** — Reference skill files for specialized tasks (create them in the \`skills/\` folder)
|
|
298
|
+
|
|
299
|
+
## Skills
|
|
300
|
+
|
|
301
|
+
You can create skill files to give the agent specialized knowledge for specific tasks. Create resources under \`skills/<name>/SKILL.md\` (e.g., \`skills/data-analysis/SKILL.md\`, \`skills/code-review/SKILL.md\`) and reference them here:
|
|
302
|
+
|
|
303
|
+
| Skill | Path | Description |
|
|
304
|
+
|-------|------|-------------|
|
|
305
|
+
| *(add your skills here)* | \`skills/example/SKILL.md\` | What this skill teaches the agent |
|
|
306
|
+
|
|
307
|
+
The agent will read the relevant skill file when performing that type of task.
|
|
308
|
+
|
|
309
|
+
## Global instructions
|
|
310
|
+
|
|
311
|
+
Put always-on guardrails in this shared \`AGENTS.md\`. For separate policy files that should also apply every turn, create shared resources under \`instructions/<name>.md\`. These are loaded automatically with this file.
|
|
312
|
+
|
|
313
|
+
## Shared reference resources
|
|
314
|
+
|
|
315
|
+
Put company, brand, positioning, persona, product, or messaging context in shared resources under paths like \`context/core-positioning.md\` or \`context/brand-guidelines.md\`. The agent sees an index of shared reference resources and reads the relevant files when a task may depend on them.
|
|
316
|
+
|
|
317
|
+
## Workspace files
|
|
318
|
+
|
|
319
|
+
Workspace resources are for files users intentionally add, edit, or manage. Agents may create hidden \`agent_scratch\` resources for temporary working notes, scripts, or intermediate results; only promote those files into workspace visibility when a user explicitly asks to keep them.
|
|
320
|
+
|
|
321
|
+
## Example
|
|
322
|
+
|
|
323
|
+
\`\`\`markdown
|
|
324
|
+
## Tone
|
|
325
|
+
Be concise. Lead with the answer. Skip filler.
|
|
326
|
+
|
|
327
|
+
## Code style
|
|
328
|
+
- Use TypeScript, never JavaScript
|
|
329
|
+
- Prefer named exports
|
|
330
|
+
- Use early returns
|
|
331
|
+
|
|
332
|
+
## Domain context
|
|
333
|
+
We sell B2B SaaS. Our customers are enterprise engineering teams.
|
|
334
|
+
\`\`\`
|
|
335
|
+
`;
|
|
336
|
+
|
|
337
|
+
const DEFAULT_AGENTS_PERSONAL_MD = `# My Agent Instructions
|
|
338
|
+
|
|
339
|
+
Personal agent instructions — only visible to you. Use this for your own contacts, preferences, and context.
|
|
340
|
+
|
|
341
|
+
## Contacts
|
|
342
|
+
|
|
343
|
+
Add people you frequently interact with so the agent can resolve names like "email my wife" or "message John":
|
|
344
|
+
|
|
345
|
+
| Name | Email | Notes |
|
|
346
|
+
|------|-------|-------|
|
|
347
|
+
| *(add your contacts here)* | | |
|
|
348
|
+
|
|
349
|
+
## Preferences
|
|
350
|
+
|
|
351
|
+
## Context
|
|
352
|
+
|
|
353
|
+
## Workspace files
|
|
354
|
+
|
|
355
|
+
Files you create here are user-facing. Temporary agent working files should stay hidden as \`agent_scratch\` unless you ask the agent to keep them.
|
|
356
|
+
`;
|
|
357
|
+
|
|
358
|
+
async function migrateDefaultResourcePath({
|
|
359
|
+
client,
|
|
360
|
+
owner,
|
|
361
|
+
fromPath,
|
|
362
|
+
toPath,
|
|
363
|
+
defaultContent,
|
|
364
|
+
}: {
|
|
365
|
+
client: DbExec;
|
|
366
|
+
owner: string;
|
|
367
|
+
fromPath: string;
|
|
368
|
+
toPath: string;
|
|
369
|
+
defaultContent: string;
|
|
370
|
+
}): Promise<void> {
|
|
371
|
+
try {
|
|
372
|
+
const existing = await client.execute({
|
|
373
|
+
sql: `SELECT id, content FROM resources WHERE owner = ? AND path = ?`,
|
|
374
|
+
args: [owner, fromPath],
|
|
375
|
+
});
|
|
376
|
+
const row = existing.rows?.[0] as
|
|
377
|
+
| { id: string; content: string }
|
|
378
|
+
| undefined;
|
|
379
|
+
if (!row || row.content !== defaultContent) return;
|
|
380
|
+
|
|
381
|
+
const destination = await client.execute({
|
|
382
|
+
sql: `SELECT id FROM resources WHERE owner = ? AND path = ?`,
|
|
383
|
+
args: [owner, toPath],
|
|
384
|
+
});
|
|
385
|
+
if ((destination.rows?.length ?? 0) > 0) return;
|
|
386
|
+
|
|
387
|
+
await client.execute({
|
|
388
|
+
sql: `UPDATE resources SET path = ?, updated_at = ? WHERE id = ?`,
|
|
389
|
+
args: [toPath, Date.now(), row.id],
|
|
390
|
+
});
|
|
391
|
+
} catch {
|
|
392
|
+
// Best-effort compatibility migration; seeding below still works if it fails.
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function isDuplicateColumnError(err: unknown): boolean {
|
|
397
|
+
const code = (err as { code?: string })?.code;
|
|
398
|
+
const message = String((err as { message?: unknown })?.message ?? err)
|
|
399
|
+
.toLowerCase()
|
|
400
|
+
.trim();
|
|
401
|
+
return (
|
|
402
|
+
code === "42701" ||
|
|
403
|
+
message.includes("duplicate column") ||
|
|
404
|
+
message.includes("already exists")
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
async function ensureResourceColumn(
|
|
409
|
+
client: DbExec,
|
|
410
|
+
definition: string,
|
|
411
|
+
): Promise<void> {
|
|
412
|
+
try {
|
|
413
|
+
await retryOnDdlRace(() =>
|
|
414
|
+
client.execute(`ALTER TABLE resources ADD COLUMN ${definition}`),
|
|
415
|
+
);
|
|
416
|
+
} catch (err) {
|
|
417
|
+
if (!isDuplicateColumnError(err)) throw err;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function normalizeCreatedBy(value: unknown): ResourceCreatedBy {
|
|
422
|
+
return value === "agent" || value === "system" || value === "user"
|
|
423
|
+
? value
|
|
424
|
+
: "user";
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function normalizeVisibility(value: unknown): ResourceVisibility {
|
|
428
|
+
return value === "agent_scratch" ? "agent_scratch" : "workspace";
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function nullableString(value: unknown): string | null {
|
|
432
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function nullableNumber(value: unknown): number | null {
|
|
436
|
+
if (value === null || value === undefined) return null;
|
|
437
|
+
const parsed = Number(value);
|
|
438
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function hasOption<K extends keyof ResourceWriteOptions>(
|
|
442
|
+
options: ResourceWriteOptions | undefined,
|
|
443
|
+
key: K,
|
|
444
|
+
): boolean {
|
|
445
|
+
return (
|
|
446
|
+
Object.prototype.hasOwnProperty.call(options ?? {}, key) &&
|
|
447
|
+
options?.[key] !== undefined
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function serializeMetadata(
|
|
452
|
+
value: ResourceWriteOptions["metadata"] | undefined,
|
|
453
|
+
): string | null | undefined {
|
|
454
|
+
if (value === undefined) return undefined;
|
|
455
|
+
if (value === null) return null;
|
|
456
|
+
return typeof value === "string" ? value : JSON.stringify(value);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function scratchFilterSql(options?: ResourceListOptions): string {
|
|
460
|
+
return options?.includeAgentScratch === true
|
|
461
|
+
? ""
|
|
462
|
+
: " AND (visibility IS NULL OR visibility != 'agent_scratch')";
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function normalizeWorkspaceAppId(value: unknown): string | null {
|
|
466
|
+
if (typeof value !== "string") return null;
|
|
467
|
+
const trimmed = value.trim();
|
|
468
|
+
if (!trimmed) return null;
|
|
469
|
+
const candidate = trimmed.replace(/^\/+/, "").split("/")[0] ?? "";
|
|
470
|
+
if (!/^[a-z0-9][a-z0-9-]{0,127}$/.test(candidate)) return null;
|
|
471
|
+
return candidate;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function workspaceAppIdFromBasePath(value: unknown): string | null {
|
|
475
|
+
if (typeof value !== "string") return null;
|
|
476
|
+
return normalizeWorkspaceAppId(value);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function currentWorkspaceAppId(explicit?: string | null): string | null {
|
|
480
|
+
return (
|
|
481
|
+
normalizeWorkspaceAppId(explicit) ??
|
|
482
|
+
normalizeWorkspaceAppId(process.env.AGENT_NATIVE_WORKSPACE_APP_ID) ??
|
|
483
|
+
normalizeWorkspaceAppId(process.env.APP_NAME) ??
|
|
484
|
+
normalizeWorkspaceAppId(process.env.AGENT_APP) ??
|
|
485
|
+
workspaceAppIdFromBasePath(process.env.APP_BASE_PATH) ??
|
|
486
|
+
workspaceAppIdFromBasePath(process.env.VITE_APP_BASE_PATH)
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function requestScopedResourceIdentity(options?: ResourceResolutionOptions): {
|
|
491
|
+
userEmail: string | null;
|
|
492
|
+
orgId: string | null;
|
|
493
|
+
} {
|
|
494
|
+
const userEmail = options?.userEmail ?? getRequestUserEmail() ?? null;
|
|
495
|
+
const orgId = options?.orgId ?? getRequestOrgId() ?? null;
|
|
496
|
+
return { userEmail, orgId };
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function workspaceResourceMimeType(path: string): string {
|
|
500
|
+
return path.endsWith(".json") ? "application/json" : "text/markdown";
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function syntheticWorkspaceResourceId(resourceId: string): string {
|
|
504
|
+
return `${DISPATCH_WORKSPACE_RESOURCE_ID_PREFIX}${resourceId}`;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function physicalWorkspaceResourceId(id: string): string | null {
|
|
508
|
+
return id.startsWith(DISPATCH_WORKSPACE_RESOURCE_ID_PREFIX)
|
|
509
|
+
? id.slice(DISPATCH_WORKSPACE_RESOURCE_ID_PREFIX.length)
|
|
510
|
+
: null;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function rowToGrantedWorkspaceResource(row: any): Resource {
|
|
514
|
+
const content = String(row.content ?? "");
|
|
515
|
+
const path = String(row.path ?? "");
|
|
516
|
+
return {
|
|
517
|
+
id: syntheticWorkspaceResourceId(String(row.id)),
|
|
518
|
+
path,
|
|
519
|
+
owner: WORKSPACE_OWNER,
|
|
520
|
+
content,
|
|
521
|
+
mimeType: workspaceResourceMimeType(path),
|
|
522
|
+
size: Buffer.byteLength(content, "utf8"),
|
|
523
|
+
createdAt: Number(row.created_at ?? Date.now()),
|
|
524
|
+
updatedAt: Number(row.updated_at ?? Date.now()),
|
|
525
|
+
createdBy: "system",
|
|
526
|
+
visibility: "workspace",
|
|
527
|
+
threadId: null,
|
|
528
|
+
runId: null,
|
|
529
|
+
expiresAt: null,
|
|
530
|
+
metadata: JSON.stringify({
|
|
531
|
+
source: DISPATCH_WORKSPACE_RESOURCE_METADATA_SOURCE,
|
|
532
|
+
resourceId: String(row.id),
|
|
533
|
+
grantId: row.grant_id ? String(row.grant_id) : null,
|
|
534
|
+
kind: row.kind ?? null,
|
|
535
|
+
name: row.name ?? null,
|
|
536
|
+
description: row.description ?? null,
|
|
537
|
+
scope: "selected",
|
|
538
|
+
appId: row.app_id ?? null,
|
|
539
|
+
updatedAt: Number(row.updated_at ?? Date.now()),
|
|
540
|
+
}),
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
function localResourceTimestamp(value: string): number {
|
|
545
|
+
const parsed = Date.parse(value);
|
|
546
|
+
return Number.isFinite(parsed) ? parsed : Date.now();
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
function localWorkspaceResourceMetadata(
|
|
550
|
+
resource: LocalWorkspaceResourceMeta,
|
|
551
|
+
): string {
|
|
552
|
+
return JSON.stringify({
|
|
553
|
+
source: LOCAL_WORKSPACE_RESOURCE_METADATA_SOURCE,
|
|
554
|
+
absolutePath: resource.absolutePath,
|
|
555
|
+
hash: resource.hash,
|
|
556
|
+
mtimeMs: resource.mtimeMs,
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function localWorkspaceResourceToResource(
|
|
561
|
+
resource: LocalWorkspaceResourceFile,
|
|
562
|
+
): Resource {
|
|
563
|
+
return {
|
|
564
|
+
id: resource.id,
|
|
565
|
+
path: resource.path,
|
|
566
|
+
owner: WORKSPACE_OWNER,
|
|
567
|
+
content: resource.content,
|
|
568
|
+
mimeType: resource.mimeType,
|
|
569
|
+
size: resource.sizeBytes,
|
|
570
|
+
createdAt: localResourceTimestamp(resource.createdAt),
|
|
571
|
+
updatedAt: localResourceTimestamp(resource.updatedAt),
|
|
572
|
+
createdBy: "system",
|
|
573
|
+
visibility: "workspace",
|
|
574
|
+
threadId: null,
|
|
575
|
+
runId: null,
|
|
576
|
+
expiresAt: null,
|
|
577
|
+
metadata: localWorkspaceResourceMetadata(resource),
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function localWorkspaceResourceToMeta(
|
|
582
|
+
resource: LocalWorkspaceResourceMeta,
|
|
583
|
+
): ResourceMeta {
|
|
584
|
+
return {
|
|
585
|
+
id: resource.id,
|
|
586
|
+
path: resource.path,
|
|
587
|
+
owner: WORKSPACE_OWNER,
|
|
588
|
+
mimeType: resource.mimeType,
|
|
589
|
+
size: resource.sizeBytes,
|
|
590
|
+
createdAt: localResourceTimestamp(resource.createdAt),
|
|
591
|
+
updatedAt: localResourceTimestamp(resource.updatedAt),
|
|
592
|
+
createdBy: "system",
|
|
593
|
+
visibility: "workspace",
|
|
594
|
+
threadId: null,
|
|
595
|
+
runId: null,
|
|
596
|
+
expiresAt: null,
|
|
597
|
+
metadata: localWorkspaceResourceMetadata(resource),
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
async function localWorkspaceResourceById(
|
|
602
|
+
id: string,
|
|
603
|
+
): Promise<Resource | null> {
|
|
604
|
+
const resourcePath = localWorkspaceResourcePathFromId(id);
|
|
605
|
+
if (!resourcePath) return null;
|
|
606
|
+
const resource = await readLocalWorkspaceResource({ path: resourcePath });
|
|
607
|
+
return resource ? localWorkspaceResourceToResource(resource) : null;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
async function localWorkspaceResourceByPath(
|
|
611
|
+
resourcePath: string,
|
|
612
|
+
): Promise<Resource | null> {
|
|
613
|
+
if (!canUseLocalWorkspaceResourcePath(resourcePath)) return null;
|
|
614
|
+
const resource = await readLocalWorkspaceResource({ path: resourcePath });
|
|
615
|
+
return resource ? localWorkspaceResourceToResource(resource) : null;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
async function localWorkspaceResourceMetas(
|
|
619
|
+
pathPrefix?: string,
|
|
620
|
+
): Promise<ResourceMeta[]> {
|
|
621
|
+
const resources = (await listLocalWorkspaceResources()).map(
|
|
622
|
+
localWorkspaceResourceToMeta,
|
|
623
|
+
);
|
|
624
|
+
if (!pathPrefix) return resources;
|
|
625
|
+
return resources.filter((resource) => resource.path.startsWith(pathPrefix));
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
export async function canWriteLocalWorkspaceResourcePath(
|
|
629
|
+
resourcePath: string,
|
|
630
|
+
): Promise<boolean> {
|
|
631
|
+
return (
|
|
632
|
+
canUseLocalWorkspaceResourcePath(resourcePath) &&
|
|
633
|
+
(await isLocalWorkspaceResourcesEnabled())
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
async function shouldHandleWorkspaceResourceAsLocal(resourcePath: string) {
|
|
638
|
+
return (
|
|
639
|
+
(await isLocalWorkspaceResourcesEnabled()) &&
|
|
640
|
+
canUseLocalWorkspaceResourcePath(resourcePath)
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
async function assertWritableWorkspaceResourcePath(resourcePath: string) {
|
|
645
|
+
if (
|
|
646
|
+
(await isLocalWorkspaceResourcesEnabled()) &&
|
|
647
|
+
!canUseLocalWorkspaceResourcePath(resourcePath)
|
|
648
|
+
) {
|
|
649
|
+
throw new Error(
|
|
650
|
+
"Workspace resources in local file mode must be AGENTS.md, agent-native.json, mcp.config.json, .mcp.json, or under skills/.",
|
|
651
|
+
);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
export { isLocalWorkspaceResourceId };
|
|
656
|
+
|
|
657
|
+
function mergeResourceMetas(
|
|
658
|
+
primary: ResourceMeta[],
|
|
659
|
+
inherited: ResourceMeta[],
|
|
660
|
+
): ResourceMeta[] {
|
|
661
|
+
const seen = new Set(primary.map((resource) => resource.path));
|
|
662
|
+
const merged = [...primary];
|
|
663
|
+
for (const resource of inherited) {
|
|
664
|
+
if (seen.has(resource.path)) continue;
|
|
665
|
+
seen.add(resource.path);
|
|
666
|
+
merged.push(resource);
|
|
667
|
+
}
|
|
668
|
+
return merged;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
async function selectGrantedWorkspaceResourceRows(input: {
|
|
672
|
+
resourceId?: string;
|
|
673
|
+
path?: string;
|
|
674
|
+
pathPrefix?: string;
|
|
675
|
+
workspaceAppId?: string | null;
|
|
676
|
+
userEmail?: string | null;
|
|
677
|
+
orgId?: string | null;
|
|
678
|
+
}): Promise<any[]> {
|
|
679
|
+
const appId = currentWorkspaceAppId(input.workspaceAppId);
|
|
680
|
+
const { userEmail, orgId } = requestScopedResourceIdentity(input);
|
|
681
|
+
if (!appId || (!userEmail && !orgId)) return [];
|
|
682
|
+
|
|
683
|
+
const conditions = ["wr.scope = ?", "wg.status = ?", "wg.app_id = ?"];
|
|
684
|
+
const args: unknown[] = ["selected", "active", appId];
|
|
685
|
+
|
|
686
|
+
if (input.resourceId) {
|
|
687
|
+
conditions.push("wr.id = ?");
|
|
688
|
+
args.push(input.resourceId);
|
|
689
|
+
}
|
|
690
|
+
if (input.path) {
|
|
691
|
+
conditions.push("wr.path = ?");
|
|
692
|
+
args.push(input.path);
|
|
693
|
+
}
|
|
694
|
+
if (input.pathPrefix) {
|
|
695
|
+
conditions.push("wr.path LIKE ? ESCAPE '!'");
|
|
696
|
+
args.push(prefixLike(input.pathPrefix));
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
if (orgId) {
|
|
700
|
+
conditions.push("wr.org_id = ?", "wg.org_id = ?");
|
|
701
|
+
args.push(orgId, orgId);
|
|
702
|
+
} else if (userEmail) {
|
|
703
|
+
conditions.push(
|
|
704
|
+
"wr.owner_email = ?",
|
|
705
|
+
"wr.org_id IS NULL",
|
|
706
|
+
"wg.owner_email = ?",
|
|
707
|
+
"wg.org_id IS NULL",
|
|
708
|
+
);
|
|
709
|
+
args.push(userEmail, userEmail);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
const client = getDbExec();
|
|
713
|
+
const { rows } = await client.execute({
|
|
714
|
+
sql: `
|
|
715
|
+
SELECT
|
|
716
|
+
wr.id,
|
|
717
|
+
wr.kind,
|
|
718
|
+
wr.name,
|
|
719
|
+
wr.description,
|
|
720
|
+
wr.path,
|
|
721
|
+
wr.content,
|
|
722
|
+
wr.created_at,
|
|
723
|
+
wr.updated_at,
|
|
724
|
+
wg.id AS grant_id,
|
|
725
|
+
wg.app_id AS app_id
|
|
726
|
+
FROM workspace_resources wr
|
|
727
|
+
INNER JOIN workspace_resource_grants wg ON wg.resource_id = wr.id
|
|
728
|
+
WHERE ${conditions.join(" AND ")}
|
|
729
|
+
ORDER BY wr.updated_at DESC
|
|
730
|
+
`,
|
|
731
|
+
args,
|
|
732
|
+
});
|
|
733
|
+
return rows;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
async function grantedWorkspaceResources(input: {
|
|
737
|
+
pathPrefix?: string;
|
|
738
|
+
workspaceAppId?: string | null;
|
|
739
|
+
userEmail?: string | null;
|
|
740
|
+
orgId?: string | null;
|
|
741
|
+
}): Promise<Resource[]> {
|
|
742
|
+
try {
|
|
743
|
+
const rows = await selectGrantedWorkspaceResourceRows(input);
|
|
744
|
+
return rows.map(rowToGrantedWorkspaceResource);
|
|
745
|
+
} catch {
|
|
746
|
+
// Dispatch workspace-resource tables are optional for standalone apps.
|
|
747
|
+
return [];
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
async function grantedWorkspaceResourceById(
|
|
752
|
+
id: string,
|
|
753
|
+
options?: ResourceResolutionOptions,
|
|
754
|
+
): Promise<Resource | null> {
|
|
755
|
+
const resourceId = physicalWorkspaceResourceId(id);
|
|
756
|
+
if (!resourceId) return null;
|
|
757
|
+
try {
|
|
758
|
+
const rows = await selectGrantedWorkspaceResourceRows({
|
|
759
|
+
resourceId,
|
|
760
|
+
workspaceAppId: options?.workspaceAppId,
|
|
761
|
+
userEmail: options?.userEmail,
|
|
762
|
+
orgId: options?.orgId,
|
|
763
|
+
});
|
|
764
|
+
return rows[0] ? rowToGrantedWorkspaceResource(rows[0]) : null;
|
|
765
|
+
} catch {
|
|
766
|
+
return null;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
async function grantedWorkspaceResourceByPath(
|
|
771
|
+
path: string,
|
|
772
|
+
options?: ResourceResolutionOptions,
|
|
773
|
+
): Promise<Resource | null> {
|
|
774
|
+
try {
|
|
775
|
+
const rows = await selectGrantedWorkspaceResourceRows({
|
|
776
|
+
path,
|
|
777
|
+
workspaceAppId: options?.workspaceAppId,
|
|
778
|
+
userEmail: options?.userEmail,
|
|
779
|
+
orgId: options?.orgId,
|
|
780
|
+
});
|
|
781
|
+
return rows[0] ? rowToGrantedWorkspaceResource(rows[0]) : null;
|
|
782
|
+
} catch {
|
|
783
|
+
return null;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
async function cleanupExpiredAgentScratchResources(
|
|
788
|
+
client: DbExec,
|
|
789
|
+
): Promise<void> {
|
|
790
|
+
const now = Date.now();
|
|
791
|
+
if (now - _lastScratchCleanupAt < SCRATCH_CLEANUP_INTERVAL_MS) return;
|
|
792
|
+
_lastScratchCleanupAt = now;
|
|
793
|
+
await client.execute({
|
|
794
|
+
sql: `DELETE FROM resources WHERE visibility = ? AND expires_at IS NOT NULL AND expires_at <= ?`,
|
|
795
|
+
args: ["agent_scratch", now],
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
async function ensureTable(): Promise<void> {
|
|
800
|
+
if (!_initPromise) {
|
|
801
|
+
_initPromise = _doEnsureTable().catch((err) => {
|
|
802
|
+
// Don't cache the rejection — let the next caller retry a fresh init.
|
|
803
|
+
_initPromise = undefined;
|
|
804
|
+
throw err;
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
return _initPromise;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
async function _doEnsureTable(): Promise<void> {
|
|
811
|
+
const client = getDbExec();
|
|
812
|
+
const createSql = `
|
|
813
|
+
CREATE TABLE IF NOT EXISTS resources (
|
|
814
|
+
id TEXT PRIMARY KEY,
|
|
815
|
+
path TEXT NOT NULL,
|
|
816
|
+
owner TEXT NOT NULL,
|
|
817
|
+
content TEXT NOT NULL DEFAULT '',
|
|
818
|
+
mime_type TEXT NOT NULL DEFAULT 'text/markdown',
|
|
819
|
+
size ${intType()} NOT NULL DEFAULT 0,
|
|
820
|
+
created_at ${intType()} NOT NULL,
|
|
821
|
+
updated_at ${intType()} NOT NULL,
|
|
822
|
+
created_by TEXT NOT NULL DEFAULT 'user',
|
|
823
|
+
visibility TEXT NOT NULL DEFAULT 'workspace',
|
|
824
|
+
thread_id TEXT,
|
|
825
|
+
run_id TEXT,
|
|
826
|
+
expires_at ${intType()},
|
|
827
|
+
metadata TEXT,
|
|
828
|
+
UNIQUE(path, owner)
|
|
829
|
+
)
|
|
830
|
+
`;
|
|
831
|
+
|
|
832
|
+
if (isPostgres()) {
|
|
833
|
+
// Hot path: the `resources` table and its additive columns are virtually
|
|
834
|
+
// always already present in production. Issuing `CREATE TABLE`/`ALTER
|
|
835
|
+
// TABLE` still takes an ACCESS EXCLUSIVE lock that, in a fresh
|
|
836
|
+
// background-worker process behind a concurrent connection on the shared
|
|
837
|
+
// Neon DB, can block ~indefinitely. The ensure* wrappers probe
|
|
838
|
+
// `information_schema` first (plain reads, no lock) and run DDL ONLY for
|
|
839
|
+
// what is actually missing, bounded by a transaction-scoped `lock_timeout`.
|
|
840
|
+
// If a swallowed lock-timeout leaves the schema still missing they RE-PROBE
|
|
841
|
+
// and THROW rather than letting init memoize success against absent schema.
|
|
842
|
+
await ensureTableExists("resources", createSql);
|
|
843
|
+
// Additive columns — guarded so the hot path (columns already present)
|
|
844
|
+
// skips the ACCESS EXCLUSIVE ALTER entirely.
|
|
845
|
+
const pgColumns: Array<[string, string]> = [
|
|
846
|
+
["created_by", "TEXT NOT NULL DEFAULT 'user'"],
|
|
847
|
+
["visibility", "TEXT NOT NULL DEFAULT 'workspace'"],
|
|
848
|
+
["thread_id", "TEXT"],
|
|
849
|
+
["run_id", "TEXT"],
|
|
850
|
+
["expires_at", intType()],
|
|
851
|
+
["metadata", "TEXT"],
|
|
852
|
+
];
|
|
853
|
+
for (const [col, def] of pgColumns) {
|
|
854
|
+
await ensureColumnExists(
|
|
855
|
+
"resources",
|
|
856
|
+
col,
|
|
857
|
+
`ALTER TABLE resources ADD COLUMN IF NOT EXISTS ${col} ${def}`,
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
} else {
|
|
861
|
+
// SQLite (local dev): no lock problem — keep the original behaviour using
|
|
862
|
+
// `retryOnDdlRace` + `ensureResourceColumn` (duplicate-column catch).
|
|
863
|
+
await retryOnDdlRace(() => client.execute(createSql));
|
|
864
|
+
await ensureResourceColumn(
|
|
865
|
+
client,
|
|
866
|
+
"created_by TEXT NOT NULL DEFAULT 'user'",
|
|
867
|
+
);
|
|
868
|
+
await ensureResourceColumn(
|
|
869
|
+
client,
|
|
870
|
+
"visibility TEXT NOT NULL DEFAULT 'workspace'",
|
|
871
|
+
);
|
|
872
|
+
await ensureResourceColumn(client, "thread_id TEXT");
|
|
873
|
+
await ensureResourceColumn(client, "run_id TEXT");
|
|
874
|
+
await ensureResourceColumn(client, `expires_at ${intType()}`);
|
|
875
|
+
await ensureResourceColumn(client, "metadata TEXT");
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// Older deployments have 32-bit timestamp columns; on Postgres the
|
|
879
|
+
// `Date.now()` written on insert/update overflows int4. Widen in place
|
|
880
|
+
// (no-op once done / on fresh DBs).
|
|
881
|
+
await widenIntColumnsToBigInt("resources", [
|
|
882
|
+
"created_at",
|
|
883
|
+
"updated_at",
|
|
884
|
+
"expires_at",
|
|
885
|
+
]);
|
|
886
|
+
|
|
887
|
+
// Seed default shared resources if they don't exist (INSERT OR IGNORE to avoid race conditions)
|
|
888
|
+
const now = Date.now();
|
|
889
|
+
const seedSql = isPostgres()
|
|
890
|
+
? `INSERT INTO resources (id, path, owner, content, mime_type, size, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT (path, owner) DO NOTHING`
|
|
891
|
+
: `INSERT OR IGNORE INTO resources (id, path, owner, content, mime_type, size, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`;
|
|
892
|
+
|
|
893
|
+
// AGENTS.md — shared agent instructions
|
|
894
|
+
const agentsSize = Buffer.byteLength(DEFAULT_AGENTS_SHARED_MD, "utf8");
|
|
895
|
+
await client.execute({
|
|
896
|
+
sql: seedSql,
|
|
897
|
+
args: [
|
|
898
|
+
crypto.randomUUID(),
|
|
899
|
+
"AGENTS.md",
|
|
900
|
+
SHARED_OWNER,
|
|
901
|
+
DEFAULT_AGENTS_SHARED_MD,
|
|
902
|
+
"text/markdown",
|
|
903
|
+
agentsSize,
|
|
904
|
+
now,
|
|
905
|
+
now,
|
|
906
|
+
],
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
// LEARNINGS.md — shared learnings (preferences, corrections, patterns).
|
|
910
|
+
// Prefer the project-root learnings.md (scaffolded from the template's
|
|
911
|
+
// learnings.defaults.md) so template-authored defaults reach the prompt
|
|
912
|
+
// without a manual migrate-learnings step. INSERT OR IGNORE means this only
|
|
913
|
+
// applies on first seed — existing LEARNINGS.md content is never overwritten.
|
|
914
|
+
const learningsSeedContent =
|
|
915
|
+
(await readProjectRootLearningsSeed()) ?? DEFAULT_LEARNINGS_SHARED_MD;
|
|
916
|
+
const learningsSize = Buffer.byteLength(learningsSeedContent, "utf8");
|
|
917
|
+
await client.execute({
|
|
918
|
+
sql: seedSql,
|
|
919
|
+
args: [
|
|
920
|
+
crypto.randomUUID(),
|
|
921
|
+
"LEARNINGS.md",
|
|
922
|
+
SHARED_OWNER,
|
|
923
|
+
learningsSeedContent,
|
|
924
|
+
"text/markdown",
|
|
925
|
+
learningsSize,
|
|
926
|
+
now,
|
|
927
|
+
now,
|
|
928
|
+
],
|
|
929
|
+
});
|
|
930
|
+
|
|
931
|
+
await migrateDefaultResourcePath({
|
|
932
|
+
client,
|
|
933
|
+
owner: SHARED_OWNER,
|
|
934
|
+
fromPath: "skills/learn-shared.md",
|
|
935
|
+
toPath: "skills/learn-shared/SKILL.md",
|
|
936
|
+
defaultContent: DEFAULT_SKILL_LEARN_SHARED_MD,
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
// skills/learn-shared/SKILL.md — shared skill for updating shared LEARNINGS.md
|
|
940
|
+
const learnSharedSize = Buffer.byteLength(
|
|
941
|
+
DEFAULT_SKILL_LEARN_SHARED_MD,
|
|
942
|
+
"utf8",
|
|
943
|
+
);
|
|
944
|
+
await client.execute({
|
|
945
|
+
sql: seedSql,
|
|
946
|
+
args: [
|
|
947
|
+
crypto.randomUUID(),
|
|
948
|
+
"skills/learn-shared/SKILL.md",
|
|
949
|
+
SHARED_OWNER,
|
|
950
|
+
DEFAULT_SKILL_LEARN_SHARED_MD,
|
|
951
|
+
"text/markdown",
|
|
952
|
+
learnSharedSize,
|
|
953
|
+
now,
|
|
954
|
+
now,
|
|
955
|
+
],
|
|
956
|
+
});
|
|
957
|
+
|
|
958
|
+
// Seed built-in agents as shared resources under remote-agents/. ALWAYS
|
|
959
|
+
// use the production URL here, never the env-resolved devUrl. The seed
|
|
960
|
+
// runs once per DB (ON CONFLICT DO NOTHING), so a localhost URL written
|
|
961
|
+
// during a dev run sticks forever — including when that DB is later used
|
|
962
|
+
// by a prod deploy and the override wins over the built-in's prod URL.
|
|
963
|
+
// (Verified problem: `dispatch.agent-native.com` had every remote-agents
|
|
964
|
+
// entry pointing at localhost from an early-seed run, breaking call-agent
|
|
965
|
+
// outbound from Lambda for ~12h before this was caught.)
|
|
966
|
+
try {
|
|
967
|
+
const { getBuiltinAgents, BUILTIN_AGENTS_FOR_SEEDING } =
|
|
968
|
+
await import("../server/agent-discovery.js");
|
|
969
|
+
void getBuiltinAgents; // referenced to keep type-only import alive
|
|
970
|
+
const builtins = BUILTIN_AGENTS_FOR_SEEDING;
|
|
971
|
+
for (const agent of builtins) {
|
|
972
|
+
const agentJson = JSON.stringify(
|
|
973
|
+
{
|
|
974
|
+
id: agent.id,
|
|
975
|
+
name: agent.name,
|
|
976
|
+
description: agent.description,
|
|
977
|
+
url: agent.url, // always prod
|
|
978
|
+
color: agent.color,
|
|
979
|
+
},
|
|
980
|
+
null,
|
|
981
|
+
2,
|
|
982
|
+
);
|
|
983
|
+
const agentSize = Buffer.byteLength(agentJson, "utf8");
|
|
984
|
+
await client.execute({
|
|
985
|
+
sql: seedSql,
|
|
986
|
+
args: [
|
|
987
|
+
crypto.randomUUID(),
|
|
988
|
+
`remote-agents/${agent.id}.json`,
|
|
989
|
+
SHARED_OWNER,
|
|
990
|
+
agentJson,
|
|
991
|
+
"application/json",
|
|
992
|
+
agentSize,
|
|
993
|
+
now,
|
|
994
|
+
now,
|
|
995
|
+
],
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
} catch {
|
|
999
|
+
// Agent discovery not available — skip seeding
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
// One-time migration: rename legacy agents/*.json (A2A manifests) to
|
|
1003
|
+
// remote-agents/*.json so they live in their own folder, separate from
|
|
1004
|
+
// custom agents (agents/*.md).
|
|
1005
|
+
try {
|
|
1006
|
+
const legacy = await client.execute({
|
|
1007
|
+
sql: `SELECT id, path FROM resources WHERE path LIKE ? AND path LIKE ?`,
|
|
1008
|
+
args: ["agents/%", "%.json"],
|
|
1009
|
+
});
|
|
1010
|
+
const rows = (legacy.rows ?? []) as Array<{ id: string; path: string }>;
|
|
1011
|
+
for (const row of rows) {
|
|
1012
|
+
const newPath = row.path.replace(/^agents\//, "remote-agents/");
|
|
1013
|
+
try {
|
|
1014
|
+
await client.execute({
|
|
1015
|
+
sql: `UPDATE resources SET path = ?, updated_at = ? WHERE id = ?`,
|
|
1016
|
+
args: [newPath, Date.now(), row.id],
|
|
1017
|
+
});
|
|
1018
|
+
} catch {
|
|
1019
|
+
// Skip if destination path already exists (unique constraint) —
|
|
1020
|
+
// we'll leave the old row in place; readers accept both paths and
|
|
1021
|
+
// canonical remote-agents/ entries win when both exist.
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
} catch {
|
|
1025
|
+
// Migration best-effort
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
const _personalSeeded = new Set<string>();
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* Seed personal AGENTS.md and LEARNINGS.md for a user if they don't exist.
|
|
1033
|
+
* Called when listing resources or from the agent chat plugin.
|
|
1034
|
+
*/
|
|
1035
|
+
export async function ensurePersonalDefaults(owner: string): Promise<void> {
|
|
1036
|
+
if (
|
|
1037
|
+
owner === SHARED_OWNER ||
|
|
1038
|
+
owner === WORKSPACE_OWNER ||
|
|
1039
|
+
_personalSeeded.has(owner)
|
|
1040
|
+
) {
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
await ensureTable();
|
|
1044
|
+
|
|
1045
|
+
const client = getDbExec();
|
|
1046
|
+
const now = Date.now();
|
|
1047
|
+
const seedSql = isPostgres()
|
|
1048
|
+
? `INSERT INTO resources (id, path, owner, content, mime_type, size, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT (path, owner) DO NOTHING`
|
|
1049
|
+
: `INSERT OR IGNORE INTO resources (id, path, owner, content, mime_type, size, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`;
|
|
1050
|
+
|
|
1051
|
+
const agentsSize = Buffer.byteLength(DEFAULT_AGENTS_PERSONAL_MD, "utf8");
|
|
1052
|
+
await client.execute({
|
|
1053
|
+
sql: seedSql,
|
|
1054
|
+
args: [
|
|
1055
|
+
crypto.randomUUID(),
|
|
1056
|
+
"AGENTS.md",
|
|
1057
|
+
owner,
|
|
1058
|
+
DEFAULT_AGENTS_PERSONAL_MD,
|
|
1059
|
+
"text/markdown",
|
|
1060
|
+
agentsSize,
|
|
1061
|
+
now,
|
|
1062
|
+
now,
|
|
1063
|
+
],
|
|
1064
|
+
});
|
|
1065
|
+
|
|
1066
|
+
const learningsSize = Buffer.byteLength(
|
|
1067
|
+
DEFAULT_LEARNINGS_PERSONAL_MD,
|
|
1068
|
+
"utf8",
|
|
1069
|
+
);
|
|
1070
|
+
await client.execute({
|
|
1071
|
+
sql: seedSql,
|
|
1072
|
+
args: [
|
|
1073
|
+
crypto.randomUUID(),
|
|
1074
|
+
"LEARNINGS.md",
|
|
1075
|
+
owner,
|
|
1076
|
+
DEFAULT_LEARNINGS_PERSONAL_MD,
|
|
1077
|
+
"text/markdown",
|
|
1078
|
+
learningsSize,
|
|
1079
|
+
now,
|
|
1080
|
+
now,
|
|
1081
|
+
],
|
|
1082
|
+
});
|
|
1083
|
+
|
|
1084
|
+
// memory/MEMORY.md — personal structured memory index
|
|
1085
|
+
const memoryIndexContent = "# Memory Index\n";
|
|
1086
|
+
const memoryIndexSize = Buffer.byteLength(memoryIndexContent, "utf8");
|
|
1087
|
+
await client.execute({
|
|
1088
|
+
sql: seedSql,
|
|
1089
|
+
args: [
|
|
1090
|
+
crypto.randomUUID(),
|
|
1091
|
+
"memory/MEMORY.md",
|
|
1092
|
+
owner,
|
|
1093
|
+
memoryIndexContent,
|
|
1094
|
+
"text/markdown",
|
|
1095
|
+
memoryIndexSize,
|
|
1096
|
+
now,
|
|
1097
|
+
now,
|
|
1098
|
+
],
|
|
1099
|
+
});
|
|
1100
|
+
|
|
1101
|
+
await migrateDefaultResourcePath({
|
|
1102
|
+
client,
|
|
1103
|
+
owner,
|
|
1104
|
+
fromPath: "skills/learn.md",
|
|
1105
|
+
toPath: "skills/learn/SKILL.md",
|
|
1106
|
+
defaultContent: DEFAULT_SKILL_LEARN_MD,
|
|
1107
|
+
});
|
|
1108
|
+
|
|
1109
|
+
// skills/learn/SKILL.md — personal skill for updating memory
|
|
1110
|
+
const learnSize = Buffer.byteLength(DEFAULT_SKILL_LEARN_MD, "utf8");
|
|
1111
|
+
await client.execute({
|
|
1112
|
+
sql: seedSql,
|
|
1113
|
+
args: [
|
|
1114
|
+
crypto.randomUUID(),
|
|
1115
|
+
"skills/learn/SKILL.md",
|
|
1116
|
+
owner,
|
|
1117
|
+
DEFAULT_SKILL_LEARN_MD,
|
|
1118
|
+
"text/markdown",
|
|
1119
|
+
learnSize,
|
|
1120
|
+
now,
|
|
1121
|
+
now,
|
|
1122
|
+
],
|
|
1123
|
+
});
|
|
1124
|
+
|
|
1125
|
+
// Mark seeded only after all seeds succeed. If any await above throws (e.g. a
|
|
1126
|
+
// transient DB error), the owner is NOT cached as seeded, so the next request
|
|
1127
|
+
// retries instead of permanently skipping seeding. Seeds use INSERT OR IGNORE
|
|
1128
|
+
// / ON CONFLICT DO NOTHING, so a concurrent re-run is harmless.
|
|
1129
|
+
_personalSeeded.add(owner);
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
function rowToResource(row: any): Resource {
|
|
1133
|
+
return {
|
|
1134
|
+
id: row.id as string,
|
|
1135
|
+
path: row.path as string,
|
|
1136
|
+
owner: row.owner as string,
|
|
1137
|
+
content: row.content as string,
|
|
1138
|
+
mimeType: row.mime_type as string,
|
|
1139
|
+
size: Number(row.size),
|
|
1140
|
+
createdAt: Number(row.created_at),
|
|
1141
|
+
updatedAt: Number(row.updated_at),
|
|
1142
|
+
createdBy: normalizeCreatedBy(row.created_by),
|
|
1143
|
+
visibility: normalizeVisibility(row.visibility),
|
|
1144
|
+
threadId: nullableString(row.thread_id),
|
|
1145
|
+
runId: nullableString(row.run_id),
|
|
1146
|
+
expiresAt: nullableNumber(row.expires_at),
|
|
1147
|
+
metadata: nullableString(row.metadata),
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
function rowToMeta(row: any): ResourceMeta {
|
|
1152
|
+
return {
|
|
1153
|
+
id: row.id as string,
|
|
1154
|
+
path: row.path as string,
|
|
1155
|
+
owner: row.owner as string,
|
|
1156
|
+
mimeType: row.mime_type as string,
|
|
1157
|
+
size: Number(row.size),
|
|
1158
|
+
createdAt: Number(row.created_at),
|
|
1159
|
+
updatedAt: Number(row.updated_at),
|
|
1160
|
+
createdBy: normalizeCreatedBy(row.created_by),
|
|
1161
|
+
visibility: normalizeVisibility(row.visibility),
|
|
1162
|
+
threadId: nullableString(row.thread_id),
|
|
1163
|
+
runId: nullableString(row.run_id),
|
|
1164
|
+
expiresAt: nullableNumber(row.expires_at),
|
|
1165
|
+
metadata: nullableString(row.metadata),
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
function resourceToMeta(resource: Resource): ResourceMeta {
|
|
1170
|
+
const { content: _content, ...meta } = resource;
|
|
1171
|
+
return meta;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
export async function resourceGet(
|
|
1175
|
+
id: string,
|
|
1176
|
+
options?: ResourceResolutionOptions,
|
|
1177
|
+
): Promise<Resource | null> {
|
|
1178
|
+
await ensureTable();
|
|
1179
|
+
if (isLocalWorkspaceResourceId(id)) {
|
|
1180
|
+
return localWorkspaceResourceById(id);
|
|
1181
|
+
}
|
|
1182
|
+
const client = getDbExec();
|
|
1183
|
+
await cleanupExpiredAgentScratchResources(client);
|
|
1184
|
+
const { rows } = await client.execute({
|
|
1185
|
+
sql: `SELECT * FROM resources WHERE id = ?`,
|
|
1186
|
+
args: [id],
|
|
1187
|
+
});
|
|
1188
|
+
if (rows.length === 0) return grantedWorkspaceResourceById(id, options);
|
|
1189
|
+
return rowToResource(rows[0]);
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
export async function resourceGetByPath(
|
|
1193
|
+
owner: string,
|
|
1194
|
+
path: string,
|
|
1195
|
+
options?: ResourceResolutionOptions,
|
|
1196
|
+
): Promise<Resource | null> {
|
|
1197
|
+
await ensureTable();
|
|
1198
|
+
if (owner === WORKSPACE_OWNER) {
|
|
1199
|
+
const local = await localWorkspaceResourceByPath(path);
|
|
1200
|
+
if (local) return local;
|
|
1201
|
+
}
|
|
1202
|
+
const client = getDbExec();
|
|
1203
|
+
await cleanupExpiredAgentScratchResources(client);
|
|
1204
|
+
const { rows } = await client.execute({
|
|
1205
|
+
sql: `SELECT * FROM resources WHERE owner = ? AND path = ?`,
|
|
1206
|
+
args: [owner, path],
|
|
1207
|
+
});
|
|
1208
|
+
if (rows.length === 0 && owner === WORKSPACE_OWNER) {
|
|
1209
|
+
return grantedWorkspaceResourceByPath(path, options);
|
|
1210
|
+
}
|
|
1211
|
+
if (rows.length === 0) return null;
|
|
1212
|
+
return rowToResource(rows[0]);
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
export async function resourcePut(
|
|
1216
|
+
owner: string,
|
|
1217
|
+
path: string,
|
|
1218
|
+
content: string,
|
|
1219
|
+
mimeType?: string,
|
|
1220
|
+
options?: ResourceWriteOptions,
|
|
1221
|
+
): Promise<Resource> {
|
|
1222
|
+
await ensureTable();
|
|
1223
|
+
if (
|
|
1224
|
+
owner === WORKSPACE_OWNER &&
|
|
1225
|
+
(await shouldHandleWorkspaceResourceAsLocal(path))
|
|
1226
|
+
) {
|
|
1227
|
+
const written = await writeLocalWorkspaceResource({ path, content });
|
|
1228
|
+
const resource = localWorkspaceResourceToResource({
|
|
1229
|
+
...written,
|
|
1230
|
+
content,
|
|
1231
|
+
});
|
|
1232
|
+
emitResourceChange(
|
|
1233
|
+
resource.id,
|
|
1234
|
+
resource.path,
|
|
1235
|
+
resource.owner,
|
|
1236
|
+
options?.requestSource,
|
|
1237
|
+
);
|
|
1238
|
+
return resource;
|
|
1239
|
+
}
|
|
1240
|
+
if (owner === WORKSPACE_OWNER) {
|
|
1241
|
+
await assertWritableWorkspaceResourcePath(path);
|
|
1242
|
+
}
|
|
1243
|
+
const client = getDbExec();
|
|
1244
|
+
const now = Date.now();
|
|
1245
|
+
const size = Buffer.byteLength(content, "utf8");
|
|
1246
|
+
const mime = mimeType || "text/markdown";
|
|
1247
|
+
|
|
1248
|
+
// Check for existing resource to preserve ID on upsert
|
|
1249
|
+
const { rows: existing } = await client.execute({
|
|
1250
|
+
sql: `SELECT id, created_at, created_by, visibility, thread_id, run_id, expires_at, metadata FROM resources WHERE owner = ? AND path = ?`,
|
|
1251
|
+
args: [owner, path],
|
|
1252
|
+
});
|
|
1253
|
+
const existingRow = existing[0] as
|
|
1254
|
+
| {
|
|
1255
|
+
id: string;
|
|
1256
|
+
created_at: number;
|
|
1257
|
+
created_by?: string | null;
|
|
1258
|
+
visibility?: string | null;
|
|
1259
|
+
thread_id?: string | null;
|
|
1260
|
+
run_id?: string | null;
|
|
1261
|
+
expires_at?: number | null;
|
|
1262
|
+
metadata?: string | null;
|
|
1263
|
+
}
|
|
1264
|
+
| undefined;
|
|
1265
|
+
|
|
1266
|
+
const id =
|
|
1267
|
+
existing.length > 0 ? (existingRow?.id as string) : crypto.randomUUID();
|
|
1268
|
+
const createdAt = existingRow ? Number(existingRow.created_at) : now;
|
|
1269
|
+
const createdBy = normalizeCreatedBy(
|
|
1270
|
+
hasOption(options, "createdBy")
|
|
1271
|
+
? options?.createdBy
|
|
1272
|
+
: existingRow?.created_by,
|
|
1273
|
+
);
|
|
1274
|
+
const visibility = normalizeVisibility(
|
|
1275
|
+
hasOption(options, "visibility")
|
|
1276
|
+
? options?.visibility
|
|
1277
|
+
: existingRow?.visibility,
|
|
1278
|
+
);
|
|
1279
|
+
const threadId = hasOption(options, "threadId")
|
|
1280
|
+
? (options?.threadId ?? null)
|
|
1281
|
+
: nullableString(existingRow?.thread_id);
|
|
1282
|
+
const runId = hasOption(options, "runId")
|
|
1283
|
+
? (options?.runId ?? null)
|
|
1284
|
+
: nullableString(existingRow?.run_id);
|
|
1285
|
+
let expiresAt = hasOption(options, "expiresAt")
|
|
1286
|
+
? (options?.expiresAt ?? null)
|
|
1287
|
+
: nullableNumber(existingRow?.expires_at);
|
|
1288
|
+
if (visibility === "agent_scratch" && expiresAt === null) {
|
|
1289
|
+
expiresAt = now + AGENT_SCRATCH_TTL_MS;
|
|
1290
|
+
}
|
|
1291
|
+
if (visibility === "workspace" && !hasOption(options, "expiresAt")) {
|
|
1292
|
+
expiresAt = null;
|
|
1293
|
+
}
|
|
1294
|
+
const serializedMetadata = serializeMetadata(options?.metadata);
|
|
1295
|
+
const metadata =
|
|
1296
|
+
serializedMetadata !== undefined
|
|
1297
|
+
? serializedMetadata
|
|
1298
|
+
: nullableString(existingRow?.metadata);
|
|
1299
|
+
|
|
1300
|
+
await client.execute({
|
|
1301
|
+
sql: isPostgres()
|
|
1302
|
+
? `INSERT INTO resources (id, path, owner, content, mime_type, size, created_at, updated_at, created_by, visibility, thread_id, run_id, expires_at, metadata) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT (path, owner) DO UPDATE SET id=EXCLUDED.id, content=EXCLUDED.content, mime_type=EXCLUDED.mime_type, size=EXCLUDED.size, updated_at=EXCLUDED.updated_at, created_by=EXCLUDED.created_by, visibility=EXCLUDED.visibility, thread_id=EXCLUDED.thread_id, run_id=EXCLUDED.run_id, expires_at=EXCLUDED.expires_at, metadata=EXCLUDED.metadata`
|
|
1303
|
+
: `INSERT OR REPLACE INTO resources (id, path, owner, content, mime_type, size, created_at, updated_at, created_by, visibility, thread_id, run_id, expires_at, metadata) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
1304
|
+
args: [
|
|
1305
|
+
id,
|
|
1306
|
+
path,
|
|
1307
|
+
owner,
|
|
1308
|
+
content,
|
|
1309
|
+
mime,
|
|
1310
|
+
size,
|
|
1311
|
+
createdAt,
|
|
1312
|
+
now,
|
|
1313
|
+
createdBy,
|
|
1314
|
+
visibility,
|
|
1315
|
+
threadId,
|
|
1316
|
+
runId,
|
|
1317
|
+
expiresAt,
|
|
1318
|
+
metadata,
|
|
1319
|
+
],
|
|
1320
|
+
});
|
|
1321
|
+
|
|
1322
|
+
emitResourceChange(id, path, owner, options?.requestSource);
|
|
1323
|
+
|
|
1324
|
+
return {
|
|
1325
|
+
id,
|
|
1326
|
+
path,
|
|
1327
|
+
owner,
|
|
1328
|
+
content,
|
|
1329
|
+
mimeType: mime,
|
|
1330
|
+
size,
|
|
1331
|
+
createdAt,
|
|
1332
|
+
updatedAt: now,
|
|
1333
|
+
createdBy,
|
|
1334
|
+
visibility,
|
|
1335
|
+
threadId,
|
|
1336
|
+
runId,
|
|
1337
|
+
expiresAt,
|
|
1338
|
+
metadata,
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
export async function resourceDelete(id: string): Promise<boolean> {
|
|
1343
|
+
await ensureTable();
|
|
1344
|
+
if (isLocalWorkspaceResourceId(id)) {
|
|
1345
|
+
const resourcePath = localWorkspaceResourcePathFromId(id);
|
|
1346
|
+
if (!resourcePath) return false;
|
|
1347
|
+
const deleted = await deleteLocalWorkspaceResource({ path: resourcePath });
|
|
1348
|
+
if (deleted) {
|
|
1349
|
+
emitResourceDelete(id, resourcePath, WORKSPACE_OWNER);
|
|
1350
|
+
}
|
|
1351
|
+
return deleted;
|
|
1352
|
+
}
|
|
1353
|
+
const client = getDbExec();
|
|
1354
|
+
|
|
1355
|
+
// Get resource info for emitter before deleting
|
|
1356
|
+
const { rows } = await client.execute({
|
|
1357
|
+
sql: `SELECT path, owner FROM resources WHERE id = ?`,
|
|
1358
|
+
args: [id],
|
|
1359
|
+
});
|
|
1360
|
+
if (rows.length === 0) return false;
|
|
1361
|
+
|
|
1362
|
+
const result = await client.execute({
|
|
1363
|
+
sql: `DELETE FROM resources WHERE id = ?`,
|
|
1364
|
+
args: [id],
|
|
1365
|
+
});
|
|
1366
|
+
const deleted = result.rowsAffected > 0;
|
|
1367
|
+
if (deleted) {
|
|
1368
|
+
emitResourceDelete(id, rows[0].path as string, rows[0].owner as string);
|
|
1369
|
+
}
|
|
1370
|
+
return deleted;
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
export async function resourceDeleteByPath(
|
|
1374
|
+
owner: string,
|
|
1375
|
+
path: string,
|
|
1376
|
+
): Promise<boolean> {
|
|
1377
|
+
await ensureTable();
|
|
1378
|
+
if (
|
|
1379
|
+
owner === WORKSPACE_OWNER &&
|
|
1380
|
+
(await shouldHandleWorkspaceResourceAsLocal(path))
|
|
1381
|
+
) {
|
|
1382
|
+
const existing = await localWorkspaceResourceByPath(path);
|
|
1383
|
+
const deleted = await deleteLocalWorkspaceResource({ path });
|
|
1384
|
+
if (deleted) {
|
|
1385
|
+
emitResourceDelete(existing?.id ?? "", path, WORKSPACE_OWNER);
|
|
1386
|
+
return true;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
if (owner === WORKSPACE_OWNER) {
|
|
1390
|
+
await assertWritableWorkspaceResourcePath(path);
|
|
1391
|
+
}
|
|
1392
|
+
const client = getDbExec();
|
|
1393
|
+
|
|
1394
|
+
// Get resource info for emitter before deleting
|
|
1395
|
+
const { rows } = await client.execute({
|
|
1396
|
+
sql: `SELECT id FROM resources WHERE owner = ? AND path = ?`,
|
|
1397
|
+
args: [owner, path],
|
|
1398
|
+
});
|
|
1399
|
+
if (rows.length === 0) return false;
|
|
1400
|
+
|
|
1401
|
+
const result = await client.execute({
|
|
1402
|
+
sql: `DELETE FROM resources WHERE owner = ? AND path = ?`,
|
|
1403
|
+
args: [owner, path],
|
|
1404
|
+
});
|
|
1405
|
+
const deleted = result.rowsAffected > 0;
|
|
1406
|
+
if (deleted) {
|
|
1407
|
+
emitResourceDelete(rows[0].id as string, path, owner);
|
|
1408
|
+
}
|
|
1409
|
+
return deleted;
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
export async function resourceList(
|
|
1413
|
+
owner: string,
|
|
1414
|
+
pathPrefix?: string,
|
|
1415
|
+
options?: ResourceListOptions,
|
|
1416
|
+
): Promise<ResourceMeta[]> {
|
|
1417
|
+
await ensureTable();
|
|
1418
|
+
const client = getDbExec();
|
|
1419
|
+
await cleanupExpiredAgentScratchResources(client);
|
|
1420
|
+
const visibilitySql = scratchFilterSql(options);
|
|
1421
|
+
|
|
1422
|
+
if (pathPrefix) {
|
|
1423
|
+
const { rows } = await client.execute({
|
|
1424
|
+
sql: `SELECT ${RESOURCE_META_SELECT} FROM resources WHERE owner = ? AND path LIKE ? ESCAPE '!'${visibilitySql}`,
|
|
1425
|
+
args: [owner, prefixLike(pathPrefix)],
|
|
1426
|
+
});
|
|
1427
|
+
const resources = rows.map(rowToMeta);
|
|
1428
|
+
if (owner !== WORKSPACE_OWNER) return resources;
|
|
1429
|
+
const local = await localWorkspaceResourceMetas(pathPrefix);
|
|
1430
|
+
const granted = await grantedWorkspaceResources({
|
|
1431
|
+
pathPrefix,
|
|
1432
|
+
workspaceAppId: options?.workspaceAppId,
|
|
1433
|
+
userEmail: options?.userEmail,
|
|
1434
|
+
orgId: options?.orgId,
|
|
1435
|
+
});
|
|
1436
|
+
return mergeResourceMetas(
|
|
1437
|
+
local,
|
|
1438
|
+
mergeResourceMetas(resources, granted.map(resourceToMeta)),
|
|
1439
|
+
);
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
const { rows } = await client.execute({
|
|
1443
|
+
sql: `SELECT ${RESOURCE_META_SELECT} FROM resources WHERE owner = ?${visibilitySql}`,
|
|
1444
|
+
args: [owner],
|
|
1445
|
+
});
|
|
1446
|
+
const resources = rows.map(rowToMeta);
|
|
1447
|
+
if (owner !== WORKSPACE_OWNER) return resources;
|
|
1448
|
+
const local = await localWorkspaceResourceMetas();
|
|
1449
|
+
const granted = await grantedWorkspaceResources({
|
|
1450
|
+
workspaceAppId: options?.workspaceAppId,
|
|
1451
|
+
userEmail: options?.userEmail,
|
|
1452
|
+
orgId: options?.orgId,
|
|
1453
|
+
});
|
|
1454
|
+
return mergeResourceMetas(
|
|
1455
|
+
local,
|
|
1456
|
+
mergeResourceMetas(resources, granted.map(resourceToMeta)),
|
|
1457
|
+
);
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
export async function resourceListAccessible(
|
|
1461
|
+
userEmail: string,
|
|
1462
|
+
pathPrefix?: string,
|
|
1463
|
+
options?: ResourceListOptions,
|
|
1464
|
+
): Promise<ResourceMeta[]> {
|
|
1465
|
+
const organizationOwner = sharedResourceOwner(options?.orgId);
|
|
1466
|
+
const [personal, organization, legacyShared, workspace] = await Promise.all([
|
|
1467
|
+
resourceList(userEmail, pathPrefix, options),
|
|
1468
|
+
organizationOwner === SHARED_OWNER
|
|
1469
|
+
? Promise.resolve([])
|
|
1470
|
+
: resourceList(organizationOwner, pathPrefix, options),
|
|
1471
|
+
resourceList(SHARED_OWNER, pathPrefix, options),
|
|
1472
|
+
resourceList(WORKSPACE_OWNER, pathPrefix, {
|
|
1473
|
+
...options,
|
|
1474
|
+
userEmail,
|
|
1475
|
+
}),
|
|
1476
|
+
]);
|
|
1477
|
+
|
|
1478
|
+
// Later layers are inherited fallbacks. A personal resource wins over an
|
|
1479
|
+
// organization resource, which wins over the legacy app-shared default,
|
|
1480
|
+
// which wins over the workspace default.
|
|
1481
|
+
return mergeResourceMetas(
|
|
1482
|
+
personal,
|
|
1483
|
+
mergeResourceMetas(
|
|
1484
|
+
organization,
|
|
1485
|
+
mergeResourceMetas(legacyShared, workspace),
|
|
1486
|
+
),
|
|
1487
|
+
);
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
export async function resourceEffectiveContext(
|
|
1491
|
+
userEmail: string,
|
|
1492
|
+
path: string,
|
|
1493
|
+
options?: ResourceResolutionOptions,
|
|
1494
|
+
): Promise<EffectiveResourceContext> {
|
|
1495
|
+
await ensureTable();
|
|
1496
|
+
|
|
1497
|
+
const workspace = await resourceGetByPath(WORKSPACE_OWNER, path, {
|
|
1498
|
+
...options,
|
|
1499
|
+
userEmail,
|
|
1500
|
+
});
|
|
1501
|
+
const organizationOwner = sharedResourceOwner(options?.orgId);
|
|
1502
|
+
const organization =
|
|
1503
|
+
organizationOwner === SHARED_OWNER
|
|
1504
|
+
? null
|
|
1505
|
+
: await resourceGetByPath(organizationOwner, path);
|
|
1506
|
+
const legacyShared = await resourceGetByPath(SHARED_OWNER, path);
|
|
1507
|
+
const shared = organization ?? legacyShared;
|
|
1508
|
+
const personal = await resourceGetByPath(userEmail, path);
|
|
1509
|
+
const effective = personal ?? shared ?? workspace ?? null;
|
|
1510
|
+
const effectiveScope: ResourceInheritanceScope | null = personal
|
|
1511
|
+
? "personal"
|
|
1512
|
+
: shared
|
|
1513
|
+
? "shared"
|
|
1514
|
+
: workspace
|
|
1515
|
+
? "workspace"
|
|
1516
|
+
: null;
|
|
1517
|
+
|
|
1518
|
+
const layerDefs: Array<{
|
|
1519
|
+
scope: ResourceInheritanceScope;
|
|
1520
|
+
label: string;
|
|
1521
|
+
owner: string;
|
|
1522
|
+
resource: Resource | null;
|
|
1523
|
+
canWrite: boolean;
|
|
1524
|
+
}> = [
|
|
1525
|
+
{
|
|
1526
|
+
scope: "workspace",
|
|
1527
|
+
label: "Workspace default",
|
|
1528
|
+
owner: WORKSPACE_OWNER,
|
|
1529
|
+
resource: workspace,
|
|
1530
|
+
canWrite: workspace ? isLocalWorkspaceResourceId(workspace.id) : false,
|
|
1531
|
+
},
|
|
1532
|
+
{
|
|
1533
|
+
scope: "shared",
|
|
1534
|
+
label: "Organization/app override",
|
|
1535
|
+
owner: organizationOwner,
|
|
1536
|
+
resource: shared,
|
|
1537
|
+
canWrite: true,
|
|
1538
|
+
},
|
|
1539
|
+
{
|
|
1540
|
+
scope: "personal",
|
|
1541
|
+
label: "Personal override",
|
|
1542
|
+
owner: userEmail,
|
|
1543
|
+
resource: personal,
|
|
1544
|
+
canWrite: true,
|
|
1545
|
+
},
|
|
1546
|
+
];
|
|
1547
|
+
|
|
1548
|
+
return {
|
|
1549
|
+
path,
|
|
1550
|
+
effectiveResource: effective ? resourceToMeta(effective) : null,
|
|
1551
|
+
effectiveScope,
|
|
1552
|
+
layers: layerDefs.map((layer) => ({
|
|
1553
|
+
scope: layer.scope,
|
|
1554
|
+
label: layer.label,
|
|
1555
|
+
owner: layer.owner,
|
|
1556
|
+
resource: layer.resource ? resourceToMeta(layer.resource) : null,
|
|
1557
|
+
exists: !!layer.resource,
|
|
1558
|
+
effective: !!layer.resource && layer.resource.id === effective?.id,
|
|
1559
|
+
overridden: !!layer.resource && layer.resource.id !== effective?.id,
|
|
1560
|
+
canWrite: layer.canWrite,
|
|
1561
|
+
})),
|
|
1562
|
+
};
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
/**
|
|
1566
|
+
* List all resources matching a path prefix across ALL owners.
|
|
1567
|
+
* Used by the recurring jobs scheduler to find all job resources.
|
|
1568
|
+
*/
|
|
1569
|
+
export async function resourceListAllOwners(
|
|
1570
|
+
pathPrefix: string,
|
|
1571
|
+
): Promise<Resource[]> {
|
|
1572
|
+
await ensureTable();
|
|
1573
|
+
const client = getDbExec();
|
|
1574
|
+
const { rows } = await client.execute({
|
|
1575
|
+
sql: `SELECT * FROM resources WHERE path LIKE ? ESCAPE '!'`,
|
|
1576
|
+
args: [prefixLike(pathPrefix)],
|
|
1577
|
+
});
|
|
1578
|
+
const localResources = (
|
|
1579
|
+
await Promise.all(
|
|
1580
|
+
(
|
|
1581
|
+
await localWorkspaceResourceMetas(pathPrefix)
|
|
1582
|
+
).map((resource) => resourceGet(resource.id)),
|
|
1583
|
+
)
|
|
1584
|
+
).filter((resource): resource is Resource => !!resource);
|
|
1585
|
+
const localPaths = new Set(localResources.map((resource) => resource.path));
|
|
1586
|
+
return [
|
|
1587
|
+
...localResources,
|
|
1588
|
+
...rows
|
|
1589
|
+
.map(rowToResource)
|
|
1590
|
+
.filter((resource) => !localPaths.has(resource.path)),
|
|
1591
|
+
];
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
export async function resourceMove(
|
|
1595
|
+
id: string,
|
|
1596
|
+
newPath: string,
|
|
1597
|
+
): Promise<boolean> {
|
|
1598
|
+
await ensureTable();
|
|
1599
|
+
const client = getDbExec();
|
|
1600
|
+
const now = Date.now();
|
|
1601
|
+
|
|
1602
|
+
// Get current resource info
|
|
1603
|
+
const { rows } = await client.execute({
|
|
1604
|
+
sql: `SELECT path, owner FROM resources WHERE id = ?`,
|
|
1605
|
+
args: [id],
|
|
1606
|
+
});
|
|
1607
|
+
if (rows.length === 0) return false;
|
|
1608
|
+
|
|
1609
|
+
const result = await client.execute({
|
|
1610
|
+
sql: `UPDATE resources SET path = ?, updated_at = ? WHERE id = ?`,
|
|
1611
|
+
args: [newPath, now, id],
|
|
1612
|
+
});
|
|
1613
|
+
const moved = result.rowsAffected > 0;
|
|
1614
|
+
if (moved) {
|
|
1615
|
+
emitResourceChange(id, newPath, rows[0].owner as string);
|
|
1616
|
+
}
|
|
1617
|
+
return moved;
|
|
1618
|
+
}
|