@agent-native/core 0.114.16 → 0.115.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 +2 -0
- package/corpus/README.md +3 -3
- package/corpus/core/CHANGELOG.md +29 -0
- package/corpus/core/agent-native.eject.json +2 -0
- package/corpus/core/docs/content/agent-native-toolkit.mdx +16 -0
- package/corpus/core/docs/content/recurring-jobs.mdx +35 -6
- package/corpus/core/export-snapshot.json +4 -0
- package/corpus/core/package.json +5 -1
- package/corpus/core/src/action.ts +22 -1
- package/corpus/core/src/agent/production-agent.ts +105 -3
- package/corpus/core/src/cli/templates-meta.ts +12 -0
- package/corpus/core/src/client/AssistantChat.tsx +53 -26
- package/corpus/core/src/client/agent-page/AgentJobsTab.tsx +19 -0
- package/corpus/core/src/client/agent-page/use-jobs.ts +1 -0
- package/corpus/core/src/client/chat/message-components.tsx +35 -1
- package/corpus/core/src/client/chat/tool-call-display.tsx +38 -3
- package/corpus/core/src/connections/catalog.ts +20 -1
- package/corpus/core/src/connections/reader.ts +65 -0
- package/corpus/core/src/dashboard-storage/index.ts +27 -0
- package/corpus/core/src/dashboard-storage/panel-source.ts +168 -0
- package/corpus/core/src/dashboard-storage/schema.ts +62 -0
- package/corpus/core/src/dashboard-storage/store.ts +333 -0
- package/corpus/core/src/deploy/build.ts +95 -16
- package/corpus/core/src/eject/provider-api-definitions.ts +1 -0
- package/corpus/core/src/eject/workspace-connections.ts +1 -0
- package/corpus/core/src/extensions/actions.ts +199 -73
- package/corpus/core/src/jobs/actions/list-recurring-jobs.ts +2 -0
- package/corpus/core/src/jobs/scheduler.ts +71 -4
- package/corpus/core/src/jobs/tools.ts +31 -1
- package/corpus/core/src/localization/default-messages.ts +1 -0
- package/corpus/core/src/mcp-client/index.ts +6 -0
- package/corpus/core/src/provider-api/actions/provider-api.ts +1 -1
- package/corpus/core/src/provider-api/index.ts +190 -5
- package/corpus/core/src/secrets/register-framework-secrets.ts +8 -0
- package/corpus/core/src/server/agent-chat/context-tools.ts +9 -0
- package/corpus/core/src/server/agent-chat/framework-prompts.ts +2 -2
- package/corpus/core/src/server/agent-chat-plugin.ts +22 -2
- package/corpus/core/src/server/core-routes-plugin.ts +1 -0
- package/corpus/core/src/server/credential-provider.ts +9 -3
- package/corpus/core/src/server/workspace-provider-oauth.ts +181 -4
- package/corpus/core/src/styles/agent-native.css +45 -2
- package/corpus/core/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +27 -0
- package/corpus/core/src/templates/default/.agents/skills/app-branding/SKILL.md +159 -0
- package/corpus/core/src/templates/default/.agents/skills/app-permissions/SKILL.md +155 -0
- package/corpus/core/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +27 -0
- package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +27 -0
- package/corpus/core/src/templates/workspace-core/.agents/skills/extensions/SKILL.md +31 -18
- package/corpus/core/src/templates/workspace-core/.agents/skills/recurring-jobs/SKILL.md +15 -0
- package/corpus/core/src/triggers/actions.ts +11 -2
- package/corpus/core/src/triggers/dispatcher.ts +20 -1
- package/corpus/core/src/triggers/types.ts +5 -0
- package/corpus/core/src/vite/action-types-plugin.ts +9 -1
- package/corpus/templates/analytics/.agents/skills/agent-native-docs/SKILL.md +115 -0
- package/corpus/templates/analytics/AGENTS.md +11 -11
- package/corpus/templates/analytics/_gitignore +39 -0
- package/corpus/templates/analytics/actions/query-dashboard-panel.ts +30 -0
- package/corpus/templates/analytics/actions/update-dashboard.ts +2 -1
- package/corpus/templates/analytics/app/lib/sql-query.ts +11 -25
- package/corpus/templates/analytics/changelog/2026-07-21-fixed-extension-updates-failing-before-changes-could-be-appl.md +6 -0
- package/corpus/templates/analytics/server/lib/dashboard-panel-query.ts +1 -0
- package/corpus/templates/analytics/server/lib/dashboard-panel-source-resolver.ts +51 -0
- package/corpus/templates/analytics/server/lib/prometheus.ts +1 -1
- package/corpus/templates/analytics/server/plugins/agent-chat.ts +1 -1
- package/corpus/templates/assets/.agents/skills/agent-native-docs/SKILL.md +115 -0
- package/corpus/templates/brain/.agents/skills/agent-native-docs/SKILL.md +115 -0
- package/corpus/templates/calendar/.agents/skills/agent-native-docs/SKILL.md +115 -0
- package/corpus/templates/calendar/_gitignore +39 -0
- package/corpus/templates/chat/.agents/skills/agent-native-docs/SKILL.md +27 -0
- package/corpus/templates/chat/AGENTS.md +1 -1
- package/corpus/templates/clips/.agents/skills/agent-native-docs/SKILL.md +115 -0
- package/corpus/templates/clips/AGENTS.md +7 -0
- package/corpus/templates/clips/actions/prepare-crm-call-evidence.ts +58 -0
- package/corpus/templates/clips/app/components/recorder/recorder-engine.ts +88 -11
- package/corpus/templates/clips/changelog/2026-07-21-crm-call-evidence-handoff.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-21-recording-retries-and-restarts-keep-their-upload-session-so-.md +6 -0
- package/corpus/templates/clips/chrome-extension/src/background.ts +20 -5
- package/corpus/templates/clips/chrome-extension/src/native-recording-state.ts +19 -0
- package/corpus/templates/clips/chrome-extension/src/offscreen.ts +8 -0
- package/corpus/templates/clips/desktop/src/overlays/recording-pill.tsx +9 -0
- package/corpus/templates/clips/desktop/src-tauri/src/recording_indicator.rs +54 -28
- package/corpus/templates/clips/server/plugins/agent-chat.ts +1 -0
- package/corpus/templates/content/.agents/skills/agent-native-docs/SKILL.md +115 -0
- package/corpus/templates/content/_gitignore +39 -0
- package/corpus/templates/content/learnings.defaults.md +5 -0
- package/corpus/templates/crm/.agents/skills/agent-native-docs/SKILL.md +115 -0
- package/corpus/templates/crm/.agents/skills/agent-native-toolkit/SKILL.md +133 -0
- package/corpus/templates/crm/.agents/skills/crm/SKILL.md +128 -0
- package/corpus/templates/crm/.agents/skills/customizing-agent-native/SKILL.md +145 -0
- package/corpus/templates/crm/.agents/skills/feature-flags/SKILL.md +169 -0
- package/corpus/templates/crm/.agents/skills/upgrade-agent-native/SKILL.md +100 -0
- package/corpus/templates/crm/.env.example +5 -0
- package/corpus/templates/crm/AGENTS.md +120 -0
- package/corpus/templates/crm/CHANGELOG.md +1 -0
- package/corpus/templates/crm/DEVELOPING.md +66 -0
- package/corpus/templates/crm/README.md +106 -0
- package/corpus/templates/crm/_gitignore +12 -0
- package/corpus/templates/crm/actions/_crm-action-utils.ts +87 -0
- package/corpus/templates/crm/actions/_crm-dashboard.ts +69 -0
- package/corpus/templates/crm/actions/_crm-signal-utils.ts +79 -0
- package/corpus/templates/crm/actions/apply-crm-proposals.ts +203 -0
- package/corpus/templates/crm/actions/attach-call-evidence.ts +170 -0
- package/corpus/templates/crm/actions/configure-crm-connection.ts +126 -0
- package/corpus/templates/crm/actions/configure-native-crm.ts +44 -0
- package/corpus/templates/crm/actions/create-crm-record.ts +148 -0
- package/corpus/templates/crm/actions/create-crm-signal-tracker.ts +58 -0
- package/corpus/templates/crm/actions/delete-staged-dataset.ts +14 -0
- package/corpus/templates/crm/actions/get-crm-automation-recipe.ts +36 -0
- package/corpus/templates/crm/actions/get-crm-dashboard-panel.ts +33 -0
- package/corpus/templates/crm/actions/get-crm-dashboard.ts +14 -0
- package/corpus/templates/crm/actions/get-crm-overview.ts +13 -0
- package/corpus/templates/crm/actions/get-crm-pipeline-data.ts +61 -0
- package/corpus/templates/crm/actions/get-crm-record.ts +75 -0
- package/corpus/templates/crm/actions/install-crm-pipeline-dashboard.ts +81 -0
- package/corpus/templates/crm/actions/list-crm-dashboard-revisions.ts +15 -0
- package/corpus/templates/crm/actions/list-crm-dashboards.ts +15 -0
- package/corpus/templates/crm/actions/list-crm-proposals.ts +31 -0
- package/corpus/templates/crm/actions/list-crm-records.ts +79 -0
- package/corpus/templates/crm/actions/list-crm-saved-views.ts +15 -0
- package/corpus/templates/crm/actions/list-crm-signal-hits.ts +43 -0
- package/corpus/templates/crm/actions/list-crm-signal-trackers.ts +32 -0
- package/corpus/templates/crm/actions/list-crm-tasks.ts +22 -0
- package/corpus/templates/crm/actions/list-staged-datasets.ts +14 -0
- package/corpus/templates/crm/actions/list-workspace-connections.ts +47 -0
- package/corpus/templates/crm/actions/manage-crm-signal-tracker.ts +87 -0
- package/corpus/templates/crm/actions/manage-crm-task.ts +132 -0
- package/corpus/templates/crm/actions/navigate.ts +63 -0
- package/corpus/templates/crm/actions/provider-api-catalog.ts +22 -0
- package/corpus/templates/crm/actions/provider-api-docs.ts +54 -0
- package/corpus/templates/crm/actions/provider-api-request.ts +92 -0
- package/corpus/templates/crm/actions/query-staged-dataset.ts +44 -0
- package/corpus/templates/crm/actions/record-crm-call-insight.ts +160 -0
- package/corpus/templates/crm/actions/record-crm-smart-signal.ts +150 -0
- package/corpus/templates/crm/actions/restore-crm-dashboard-revision.ts +23 -0
- package/corpus/templates/crm/actions/review-crm-signal.ts +31 -0
- package/corpus/templates/crm/actions/run-crm-saved-view-program.ts +103 -0
- package/corpus/templates/crm/actions/run-crm-signal-trackers.ts +275 -0
- package/corpus/templates/crm/actions/run.ts +11 -0
- package/corpus/templates/crm/actions/save-crm-dashboard.ts +51 -0
- package/corpus/templates/crm/actions/save-crm-saved-view.ts +119 -0
- package/corpus/templates/crm/actions/sync-crm.ts +146 -0
- package/corpus/templates/crm/actions/update-crm-record.ts +508 -0
- package/corpus/templates/crm/actions/view-screen.ts +218 -0
- package/corpus/templates/crm/agent-native.app-skill.json +58 -0
- package/corpus/templates/crm/app/components/crm/CreateCrmRecordDialog.tsx +158 -0
- package/corpus/templates/crm/app/components/crm/CrmDashboardPanel.tsx +83 -0
- package/corpus/templates/crm/app/components/crm/CrmSignalsPanel.tsx +225 -0
- package/corpus/templates/crm/app/components/crm/IntelligenceSettings.tsx +413 -0
- package/corpus/templates/crm/app/components/crm/RecordActions.tsx +510 -0
- package/corpus/templates/crm/app/components/crm/RecordGrid.tsx +134 -0
- package/corpus/templates/crm/app/components/crm/RecordWorkspace.tsx +367 -0
- package/corpus/templates/crm/app/components/crm/SavedViewDataProgram.tsx +92 -0
- package/corpus/templates/crm/app/components/crm/Surface.tsx +96 -0
- package/corpus/templates/crm/app/components/crm/WorkOverview.tsx +180 -0
- package/corpus/templates/crm/app/components/layout/CrmLayout.tsx +106 -0
- package/corpus/templates/crm/app/components/layout/CrmSidebar.tsx +84 -0
- package/corpus/templates/crm/app/entry.client.tsx +16 -0
- package/corpus/templates/crm/app/entry.server.tsx +10 -0
- package/corpus/templates/crm/app/global.css +167 -0
- package/corpus/templates/crm/app/hooks/use-navigation-state.ts +60 -0
- package/corpus/templates/crm/app/i18n/en-US.ts +89 -0
- package/corpus/templates/crm/app/i18n/index.ts +34 -0
- package/corpus/templates/crm/app/lib/dashboard.ts +13 -0
- package/corpus/templates/crm/app/lib/navigation.ts +54 -0
- package/corpus/templates/crm/app/lib/tab-id.ts +1 -0
- package/corpus/templates/crm/app/lib/types.ts +172 -0
- package/corpus/templates/crm/app/lib/utils.ts +1 -0
- package/corpus/templates/crm/app/root.tsx +88 -0
- package/corpus/templates/crm/app/routes/_index.tsx +26 -0
- package/corpus/templates/crm/app/routes/accounts.tsx +41 -0
- package/corpus/templates/crm/app/routes/agent.tsx +5 -0
- package/corpus/templates/crm/app/routes/ask.tsx +53 -0
- package/corpus/templates/crm/app/routes/dashboard.tsx +118 -0
- package/corpus/templates/crm/app/routes/opportunities.tsx +41 -0
- package/corpus/templates/crm/app/routes/people.tsx +41 -0
- package/corpus/templates/crm/app/routes/proposals.tsx +266 -0
- package/corpus/templates/crm/app/routes/records.$recordId.tsx +35 -0
- package/corpus/templates/crm/app/routes/settings.tsx +63 -0
- package/corpus/templates/crm/app/routes/setup.tsx +308 -0
- package/corpus/templates/crm/app/routes/tasks.tsx +252 -0
- package/corpus/templates/crm/app/routes/views.tsx +333 -0
- package/corpus/templates/crm/app/routes.ts +17 -0
- package/corpus/templates/crm/app/vite-env.d.ts +6 -0
- package/corpus/templates/crm/changelog/2026-07-21-agent-native-crm.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-21-clips-call-evidence-review-recipe.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-21-crm-can-now-find-and-review-evidence-grounded-call-signals-w.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-21-crm-can-now-manage-keyword-and-smart-call-signal-trackers-fr.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-21-delegated-local-crm-automation.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-21-native-sql.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-21-pipeline-dashboard.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-21-pipeline-dashboards-now-install-correctly-from-the-crm-actio.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-21-salesforce-connection.md +6 -0
- package/corpus/templates/crm/components.json +20 -0
- package/corpus/templates/crm/docs/architecture/crm-contract.md +180 -0
- package/corpus/templates/crm/learnings.defaults.md +5 -0
- package/corpus/templates/crm/package.json +59 -0
- package/corpus/templates/crm/public/favicon.svg +1 -0
- package/corpus/templates/crm/public/icon-180.svg +1 -0
- package/corpus/templates/crm/public/manifest.json +11 -0
- package/corpus/templates/crm/react-router.config.ts +7 -0
- package/corpus/templates/crm/server/crm/adapter.ts +32 -0
- package/corpus/templates/crm/server/crm/crm-field-firewall.ts +64 -0
- package/corpus/templates/crm/server/crm/crm-mirror.ts +711 -0
- package/corpus/templates/crm/server/crm/hubspot-adapter.ts +1143 -0
- package/corpus/templates/crm/server/crm/native-adapter.ts +1715 -0
- package/corpus/templates/crm/server/crm/read-through.ts +207 -0
- package/corpus/templates/crm/server/crm/salesforce-adapter.ts +1255 -0
- package/corpus/templates/crm/server/db/crm-store.ts +1170 -0
- package/corpus/templates/crm/server/db/index.ts +169 -0
- package/corpus/templates/crm/server/db/schema.ts +441 -0
- package/corpus/templates/crm/server/lib/intelligence/default-detectors.ts +65 -0
- package/corpus/templates/crm/server/lib/intelligence/evidence.ts +105 -0
- package/corpus/templates/crm/server/lib/intelligence/keyword-detector.ts +100 -0
- package/corpus/templates/crm/server/lib/intelligence/smart-detector.ts +144 -0
- package/corpus/templates/crm/server/lib/intelligence/summary.ts +141 -0
- package/corpus/templates/crm/server/lib/provider-api.ts +64 -0
- package/corpus/templates/crm/server/middleware/auth.ts +4 -0
- package/corpus/templates/crm/server/plugins/agent-chat.ts +68 -0
- package/corpus/templates/crm/server/plugins/auth.ts +14 -0
- package/corpus/templates/crm/server/plugins/core-routes.ts +17 -0
- package/corpus/templates/crm/server/plugins/db.ts +454 -0
- package/corpus/templates/crm/server/routes/[...page].get.ts +5 -0
- package/corpus/templates/crm/shared/crm-automation-recipes.ts +132 -0
- package/corpus/templates/crm/shared/crm-contract.ts +254 -0
- package/corpus/templates/crm/shared/crm-sales-config.ts +63 -0
- package/corpus/templates/crm/ssr-entry.ts +11 -0
- package/corpus/templates/crm/tsconfig.json +24 -0
- package/corpus/templates/crm/vite.config.ts +15 -0
- package/corpus/templates/crm/vitest.config.ts +5 -0
- package/corpus/templates/design/.agents/skills/agent-native-docs/SKILL.md +115 -0
- package/corpus/templates/dispatch/.agents/skills/agent-native-docs/SKILL.md +115 -0
- package/corpus/templates/forms/.agents/skills/agent-native-docs/SKILL.md +115 -0
- package/corpus/templates/forms/_gitignore +39 -0
- package/corpus/templates/forms/learnings.defaults.md +5 -0
- package/corpus/templates/macros/.agents/skills/agent-native-docs/SKILL.md +115 -0
- package/corpus/templates/macros/_gitignore +39 -0
- package/corpus/templates/macros/learnings.defaults.md +5 -0
- package/corpus/templates/mail/.agents/skills/agent-native-docs/SKILL.md +115 -0
- package/corpus/templates/mail/_gitignore +39 -0
- package/corpus/templates/plan/.agents/skills/agent-native-docs/SKILL.md +115 -0
- package/corpus/templates/slides/.agents/skills/agent-native-docs/SKILL.md +115 -0
- package/corpus/templates/slides/_gitignore +39 -0
- package/corpus/templates/tasks/.agents/skills/agent-native-docs/SKILL.md +27 -0
- package/corpus/templates/tasks/_gitignore +39 -0
- package/corpus/toolkit/CHANGELOG.md +12 -0
- package/corpus/toolkit/README.md +30 -0
- package/corpus/toolkit/agent-native.eject.json +33 -0
- package/corpus/toolkit/package.json +15 -1
- package/corpus/toolkit/src/dashboard/DataTable.tsx +273 -0
- package/corpus/toolkit/src/dashboard/DateRangePicker.tsx +57 -0
- package/corpus/toolkit/src/dashboard/GenericChartPanel.tsx +461 -0
- package/corpus/toolkit/src/dashboard/MetricCard.tsx +54 -0
- package/corpus/toolkit/src/dashboard/StatsCard.tsx +49 -0
- package/corpus/toolkit/src/dashboard/dashboard-layout.ts +329 -0
- package/corpus/toolkit/src/dashboard/index.ts +6 -0
- package/corpus/toolkit/src/index.ts +1 -0
- package/corpus/toolkit/src/ui/calendar.tsx +8 -8
- package/corpus/toolkit/src/ui/date-picker.tsx +4 -1
- package/dist/action.d.ts +14 -1
- package/dist/action.d.ts.map +1 -1
- package/dist/action.js.map +1 -1
- package/dist/agent/production-agent.d.ts +3 -1
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +83 -3
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/cli/templates-meta.d.ts.map +1 -1
- package/dist/cli/templates-meta.js +12 -0
- package/dist/cli/templates-meta.js.map +1 -1
- package/dist/client/AssistantChat.d.ts +4 -0
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +30 -17
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/agent-page/AgentJobsTab.d.ts.map +1 -1
- package/dist/client/agent-page/AgentJobsTab.js +3 -1
- package/dist/client/agent-page/AgentJobsTab.js.map +1 -1
- package/dist/client/agent-page/use-jobs.d.ts +1 -0
- package/dist/client/agent-page/use-jobs.d.ts.map +1 -1
- package/dist/client/agent-page/use-jobs.js.map +1 -1
- package/dist/client/chat/message-components.d.ts +5 -0
- package/dist/client/chat/message-components.d.ts.map +1 -1
- package/dist/client/chat/message-components.js +17 -1
- package/dist/client/chat/message-components.js.map +1 -1
- package/dist/client/chat/tool-call-display.d.ts +3 -1
- package/dist/client/chat/tool-call-display.d.ts.map +1 -1
- package/dist/client/chat/tool-call-display.js +17 -7
- package/dist/client/chat/tool-call-display.js.map +1 -1
- package/dist/collab/awareness.d.ts +2 -2
- package/dist/collab/awareness.d.ts.map +1 -1
- package/dist/collab/routes.d.ts +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/connections/catalog.d.ts +17 -3
- package/dist/connections/catalog.d.ts.map +1 -1
- package/dist/connections/catalog.js +16 -1
- package/dist/connections/catalog.js.map +1 -1
- package/dist/connections/reader.d.ts +18 -0
- package/dist/connections/reader.d.ts.map +1 -1
- package/dist/connections/reader.js +41 -0
- package/dist/connections/reader.js.map +1 -1
- package/dist/dashboard-storage/index.d.ts +4 -0
- package/dist/dashboard-storage/index.d.ts.map +1 -0
- package/dist/dashboard-storage/index.js +4 -0
- package/dist/dashboard-storage/index.js.map +1 -0
- package/dist/dashboard-storage/panel-source.d.ts +68 -0
- package/dist/dashboard-storage/panel-source.d.ts.map +1 -0
- package/dist/dashboard-storage/panel-source.js +76 -0
- package/dist/dashboard-storage/panel-source.js.map +1 -0
- package/dist/dashboard-storage/schema.d.ts +562 -0
- package/dist/dashboard-storage/schema.d.ts.map +1 -0
- package/dist/dashboard-storage/schema.js +32 -0
- package/dist/dashboard-storage/schema.js.map +1 -0
- package/dist/dashboard-storage/store.d.ts +62 -0
- package/dist/dashboard-storage/store.d.ts.map +1 -0
- package/dist/dashboard-storage/store.js +227 -0
- package/dist/dashboard-storage/store.js.map +1 -0
- package/dist/deploy/build.d.ts +7 -0
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +78 -14
- package/dist/deploy/build.js.map +1 -1
- package/dist/eject/provider-api-definitions.d.ts +2 -1
- package/dist/eject/provider-api-definitions.d.ts.map +1 -1
- package/dist/eject/provider-api-definitions.js +1 -0
- package/dist/eject/provider-api-definitions.js.map +1 -1
- package/dist/eject/workspace-connections.d.ts.map +1 -1
- package/dist/eject/workspace-connections.js +1 -0
- package/dist/eject/workspace-connections.js.map +1 -1
- package/dist/extensions/actions.d.ts.map +1 -1
- package/dist/extensions/actions.js +165 -67
- package/dist/extensions/actions.js.map +1 -1
- package/dist/file-upload/actions/upload-image.d.ts +1 -1
- package/dist/jobs/actions/list-recurring-jobs.d.ts +1 -0
- package/dist/jobs/actions/list-recurring-jobs.d.ts.map +1 -1
- package/dist/jobs/actions/list-recurring-jobs.js +1 -0
- package/dist/jobs/actions/list-recurring-jobs.js.map +1 -1
- package/dist/jobs/scheduler.d.ts +17 -2
- package/dist/jobs/scheduler.d.ts.map +1 -1
- package/dist/jobs/scheduler.js +51 -2
- package/dist/jobs/scheduler.js.map +1 -1
- package/dist/jobs/tools.d.ts.map +1 -1
- package/dist/jobs/tools.js +32 -2
- package/dist/jobs/tools.js.map +1 -1
- package/dist/localization/default-messages.d.ts +1 -0
- package/dist/localization/default-messages.d.ts.map +1 -1
- package/dist/localization/default-messages.js +1 -0
- package/dist/localization/default-messages.js.map +1 -1
- package/dist/mcp-client/index.d.ts +2 -0
- package/dist/mcp-client/index.d.ts.map +1 -1
- package/dist/mcp-client/index.js +5 -0
- package/dist/mcp-client/index.js.map +1 -1
- package/dist/notifications/routes.d.ts +3 -3
- package/dist/observability/routes.d.ts +5 -5
- package/dist/provider-api/actions/custom-provider-registration.d.ts +8 -8
- package/dist/provider-api/actions/provider-api.d.ts +8 -6
- package/dist/provider-api/actions/provider-api.d.ts.map +1 -1
- package/dist/provider-api/actions/provider-api.js +1 -1
- package/dist/provider-api/actions/provider-api.js.map +1 -1
- package/dist/provider-api/index.d.ts +11 -7
- package/dist/provider-api/index.d.ts.map +1 -1
- package/dist/provider-api/index.js +143 -5
- package/dist/provider-api/index.js.map +1 -1
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/secrets/register-framework-secrets.d.ts.map +1 -1
- package/dist/secrets/register-framework-secrets.js +7 -0
- package/dist/secrets/register-framework-secrets.js.map +1 -1
- package/dist/secrets/routes.d.ts +9 -9
- package/dist/server/agent-chat/context-tools.d.ts.map +1 -1
- package/dist/server/agent-chat/context-tools.js +9 -0
- package/dist/server/agent-chat/context-tools.js.map +1 -1
- package/dist/server/agent-chat/framework-prompts.js +2 -2
- package/dist/server/agent-chat/framework-prompts.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +18 -2
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +1 -0
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/credential-provider.d.ts +4 -3
- package/dist/server/credential-provider.d.ts.map +1 -1
- package/dist/server/credential-provider.js +9 -3
- package/dist/server/credential-provider.js.map +1 -1
- package/dist/server/transcribe-voice.d.ts +1 -1
- package/dist/server/workspace-provider-oauth.d.ts +6 -1
- package/dist/server/workspace-provider-oauth.d.ts.map +1 -1
- package/dist/server/workspace-provider-oauth.js +141 -4
- package/dist/server/workspace-provider-oauth.js.map +1 -1
- package/dist/styles/agent-native.css +45 -2
- package/dist/templates/chat/.agents/skills/agent-native-docs/SKILL.md +27 -0
- package/dist/templates/chat/AGENTS.md +1 -1
- package/dist/templates/default/.agents/skills/agent-native-docs/SKILL.md +27 -0
- package/dist/templates/default/.agents/skills/app-branding/SKILL.md +159 -0
- package/dist/templates/default/.agents/skills/app-permissions/SKILL.md +155 -0
- package/dist/templates/headless/.agents/skills/agent-native-docs/SKILL.md +27 -0
- package/dist/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +27 -0
- package/dist/templates/workspace-core/.agents/skills/extensions/SKILL.md +31 -18
- package/dist/templates/workspace-core/.agents/skills/recurring-jobs/SKILL.md +15 -0
- package/dist/triggers/actions.d.ts.map +1 -1
- package/dist/triggers/actions.js +10 -2
- package/dist/triggers/actions.js.map +1 -1
- package/dist/triggers/dispatcher.d.ts.map +1 -1
- package/dist/triggers/dispatcher.js +15 -0
- package/dist/triggers/dispatcher.js.map +1 -1
- package/dist/triggers/types.d.ts +5 -0
- package/dist/triggers/types.d.ts.map +1 -1
- package/dist/triggers/types.js.map +1 -1
- package/dist/vite/action-types-plugin.d.ts.map +1 -1
- package/dist/vite/action-types-plugin.js +4 -1
- package/dist/vite/action-types-plugin.js.map +1 -1
- package/docs/content/agent-native-toolkit.mdx +16 -0
- package/docs/content/recurring-jobs.mdx +35 -6
- package/package.json +6 -2
- package/src/action.ts +22 -1
- package/src/agent/production-agent.ts +105 -3
- package/src/cli/templates-meta.ts +12 -0
- package/src/client/AssistantChat.tsx +53 -26
- package/src/client/agent-page/AgentJobsTab.tsx +19 -0
- package/src/client/agent-page/use-jobs.ts +1 -0
- package/src/client/chat/message-components.tsx +35 -1
- package/src/client/chat/tool-call-display.tsx +38 -3
- package/src/connections/catalog.ts +20 -1
- package/src/connections/reader.ts +65 -0
- package/src/dashboard-storage/index.ts +27 -0
- package/src/dashboard-storage/panel-source.ts +168 -0
- package/src/dashboard-storage/schema.ts +62 -0
- package/src/dashboard-storage/store.ts +333 -0
- package/src/deploy/build.ts +95 -16
- package/src/eject/provider-api-definitions.ts +1 -0
- package/src/eject/workspace-connections.ts +1 -0
- package/src/extensions/actions.ts +199 -73
- package/src/jobs/actions/list-recurring-jobs.ts +2 -0
- package/src/jobs/scheduler.ts +71 -4
- package/src/jobs/tools.ts +31 -1
- package/src/localization/default-messages.ts +1 -0
- package/src/mcp-client/index.ts +6 -0
- package/src/provider-api/actions/provider-api.ts +1 -1
- package/src/provider-api/index.ts +190 -5
- package/src/secrets/register-framework-secrets.ts +8 -0
- package/src/server/agent-chat/context-tools.ts +9 -0
- package/src/server/agent-chat/framework-prompts.ts +2 -2
- package/src/server/agent-chat-plugin.ts +22 -2
- package/src/server/core-routes-plugin.ts +1 -0
- package/src/server/credential-provider.ts +9 -3
- package/src/server/workspace-provider-oauth.ts +181 -4
- package/src/styles/agent-native.css +45 -2
- package/src/templates/chat/.agents/skills/agent-native-docs/SKILL.md +27 -0
- package/src/templates/chat/AGENTS.md +1 -1
- package/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +27 -0
- package/src/templates/default/.agents/skills/app-branding/SKILL.md +159 -0
- package/src/templates/default/.agents/skills/app-permissions/SKILL.md +155 -0
- package/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +27 -0
- package/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +27 -0
- package/src/templates/workspace-core/.agents/skills/extensions/SKILL.md +31 -18
- package/src/templates/workspace-core/.agents/skills/recurring-jobs/SKILL.md +15 -0
- package/src/triggers/actions.ts +11 -2
- package/src/triggers/dispatcher.ts +20 -1
- package/src/triggers/types.ts +5 -0
- package/src/vite/action-types-plugin.ts +9 -1
- package/corpus/templates/analytics/server/handlers/sql-query.ts +0 -36
- package/corpus/templates/analytics/server/routes/api/sql-query.post.ts +0 -1
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
import { assertAccess, accessFilter } from "@agent-native/core/sharing";
|
|
2
|
+
import { and, eq, inArray } from "drizzle-orm";
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
CrmAdapter,
|
|
6
|
+
CrmFieldDefinition,
|
|
7
|
+
CrmFieldStoragePolicy,
|
|
8
|
+
CrmObjectDefinition,
|
|
9
|
+
CrmRecord,
|
|
10
|
+
CrmSyncScope,
|
|
11
|
+
CrmValue,
|
|
12
|
+
} from "../../shared/crm-contract.js";
|
|
13
|
+
import { getDb, schema } from "../db/index.js";
|
|
14
|
+
|
|
15
|
+
export const CORE_HUBSPOT_OBJECTS = ["companies", "contacts", "deals"] as const;
|
|
16
|
+
export const CORE_SALESFORCE_OBJECTS = [
|
|
17
|
+
"Account",
|
|
18
|
+
"Contact",
|
|
19
|
+
"Opportunity",
|
|
20
|
+
] as const;
|
|
21
|
+
export const MAX_SYNC_PAGE_SIZE = 50;
|
|
22
|
+
export const MAX_SYNC_PAGES = 5;
|
|
23
|
+
|
|
24
|
+
const DEFAULT_FIELDS: Record<string, string[]> = {
|
|
25
|
+
companies: ["name", "domain", "industry", "city", "state", "country"],
|
|
26
|
+
contacts: ["firstname", "lastname", "email", "jobtitle", "company"],
|
|
27
|
+
deals: ["dealname", "amount", "dealstage", "pipeline", "closedate"],
|
|
28
|
+
Account: [
|
|
29
|
+
"Name",
|
|
30
|
+
"Website",
|
|
31
|
+
"Industry",
|
|
32
|
+
"BillingCity",
|
|
33
|
+
"BillingState",
|
|
34
|
+
"BillingCountry",
|
|
35
|
+
"OwnerId",
|
|
36
|
+
],
|
|
37
|
+
Contact: ["FirstName", "LastName", "Email", "Title", "AccountId", "OwnerId"],
|
|
38
|
+
Opportunity: [
|
|
39
|
+
"Name",
|
|
40
|
+
"Amount",
|
|
41
|
+
"StageName",
|
|
42
|
+
"CloseDate",
|
|
43
|
+
"AccountId",
|
|
44
|
+
"OwnerId",
|
|
45
|
+
"Type",
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const BINARY_OR_TRANSCRIPT_FIELD =
|
|
50
|
+
/(?:attachment|audio|base64|binary|file|image|media|recording|transcript|video)/i;
|
|
51
|
+
|
|
52
|
+
const CADENCE_FIELDS: CrmFieldDefinition[] = [
|
|
53
|
+
{
|
|
54
|
+
name: "desiredCadenceDays",
|
|
55
|
+
label: "Desired cadence days",
|
|
56
|
+
valueType: "number",
|
|
57
|
+
storagePolicy: "local-authoritative",
|
|
58
|
+
sensitive: false,
|
|
59
|
+
readable: true,
|
|
60
|
+
createable: false,
|
|
61
|
+
updateable: true,
|
|
62
|
+
required: false,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "lastMeaningfulInteractionAt",
|
|
66
|
+
label: "Last meaningful interaction",
|
|
67
|
+
valueType: "datetime",
|
|
68
|
+
storagePolicy: "derived-local",
|
|
69
|
+
sensitive: false,
|
|
70
|
+
readable: true,
|
|
71
|
+
createable: false,
|
|
72
|
+
updateable: false,
|
|
73
|
+
required: false,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "nextContactAt",
|
|
77
|
+
label: "Next contact",
|
|
78
|
+
valueType: "datetime",
|
|
79
|
+
storagePolicy: "derived-local",
|
|
80
|
+
sensitive: false,
|
|
81
|
+
readable: true,
|
|
82
|
+
createable: false,
|
|
83
|
+
updateable: false,
|
|
84
|
+
required: false,
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
type Ownership = {
|
|
89
|
+
ownerEmail: string;
|
|
90
|
+
orgId: string | null;
|
|
91
|
+
visibility: "private" | "org";
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type MirrorSyncInput = {
|
|
95
|
+
connectionId: string;
|
|
96
|
+
objectType: string;
|
|
97
|
+
scope: CrmSyncScope;
|
|
98
|
+
fieldAllowList?: string[];
|
|
99
|
+
allowCustomObject?: boolean;
|
|
100
|
+
cursor?: string;
|
|
101
|
+
pageSize?: number;
|
|
102
|
+
maxPages?: number;
|
|
103
|
+
ownership: Ownership;
|
|
104
|
+
adapter: CrmAdapter;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export function isCustomHubSpotObject(objectType: string): boolean {
|
|
108
|
+
return !CORE_HUBSPOT_OBJECTS.includes(
|
|
109
|
+
objectType as (typeof CORE_HUBSPOT_OBJECTS)[number],
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function resolveMirrorFields(input: {
|
|
114
|
+
object: CrmObjectDefinition;
|
|
115
|
+
requested: string[] | undefined;
|
|
116
|
+
allowCustomObject: boolean | undefined;
|
|
117
|
+
}): string[] {
|
|
118
|
+
const available = new Map(
|
|
119
|
+
input.object.fields
|
|
120
|
+
.filter((field) => field.readable)
|
|
121
|
+
.map((field) => [field.name, field]),
|
|
122
|
+
);
|
|
123
|
+
const custom = input.object.custom;
|
|
124
|
+
const requested =
|
|
125
|
+
input.requested?.map((field) => field.trim()).filter(Boolean) ?? [];
|
|
126
|
+
if (custom && (!input.allowCustomObject || requested.length === 0)) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
"Custom CRM objects require allowCustomObject and an explicit field allow-list.",
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
const candidates = requested.length
|
|
132
|
+
? requested
|
|
133
|
+
: (DEFAULT_FIELDS[input.object.objectType] ?? []);
|
|
134
|
+
return Array.from(new Set(candidates)).filter((fieldName) => {
|
|
135
|
+
const field = available.get(fieldName);
|
|
136
|
+
return Boolean(
|
|
137
|
+
field && !field.sensitive && !BINARY_OR_TRANSCRIPT_FIELD.test(fieldName),
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function storagePolicyFor(
|
|
143
|
+
field: CrmFieldDefinition,
|
|
144
|
+
mirrored: Set<string>,
|
|
145
|
+
): CrmFieldStoragePolicy {
|
|
146
|
+
if (field.sensitive) return "redacted";
|
|
147
|
+
return mirrored.has(field.name) ? "mirrored" : "remote-only";
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function fieldsForPolicyDiscovery(object: CrmObjectDefinition) {
|
|
151
|
+
if (object.kind !== "account" && object.kind !== "person") {
|
|
152
|
+
return object.fields;
|
|
153
|
+
}
|
|
154
|
+
return [...object.fields, ...CADENCE_FIELDS];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function hasBase64Shape(value: string): boolean {
|
|
158
|
+
return (
|
|
159
|
+
value.length > 256 &&
|
|
160
|
+
/^[A-Za-z0-9+/=\s]+$/.test(value) &&
|
|
161
|
+
value.replace(/\s/g, "").length % 4 === 0
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function safeMirroredValue(value: CrmValue, depth = 0): CrmValue | null {
|
|
166
|
+
if (value === null || typeof value === "boolean" || typeof value === "number")
|
|
167
|
+
return value;
|
|
168
|
+
if (typeof value === "string") {
|
|
169
|
+
if (
|
|
170
|
+
value.length > 2_000 ||
|
|
171
|
+
value.trimStart().startsWith("data:") ||
|
|
172
|
+
hasBase64Shape(value)
|
|
173
|
+
)
|
|
174
|
+
return null;
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
if (depth >= 3 || !Array.isArray(value) || value.length > 40) return null;
|
|
178
|
+
const values = value.map((item) => safeMirroredValue(item, depth + 1));
|
|
179
|
+
return values.every((item) => item !== null) ? (values as CrmValue) : null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function fieldColumns(value: CrmValue) {
|
|
183
|
+
if (typeof value === "string")
|
|
184
|
+
return {
|
|
185
|
+
stringValue: value,
|
|
186
|
+
numberValue: null,
|
|
187
|
+
booleanValue: null,
|
|
188
|
+
jsonValue: null,
|
|
189
|
+
};
|
|
190
|
+
if (typeof value === "number")
|
|
191
|
+
return {
|
|
192
|
+
stringValue: null,
|
|
193
|
+
numberValue: value,
|
|
194
|
+
booleanValue: null,
|
|
195
|
+
jsonValue: null,
|
|
196
|
+
};
|
|
197
|
+
if (typeof value === "boolean")
|
|
198
|
+
return {
|
|
199
|
+
stringValue: null,
|
|
200
|
+
numberValue: null,
|
|
201
|
+
booleanValue: value,
|
|
202
|
+
jsonValue: null,
|
|
203
|
+
};
|
|
204
|
+
if (value === null)
|
|
205
|
+
return {
|
|
206
|
+
stringValue: null,
|
|
207
|
+
numberValue: null,
|
|
208
|
+
booleanValue: null,
|
|
209
|
+
jsonValue: null,
|
|
210
|
+
};
|
|
211
|
+
const jsonValue = JSON.stringify(value);
|
|
212
|
+
if (jsonValue.length > 8_000)
|
|
213
|
+
throw new Error("Mirrored field value exceeds the 8,000-character limit.");
|
|
214
|
+
return {
|
|
215
|
+
stringValue: null,
|
|
216
|
+
numberValue: null,
|
|
217
|
+
booleanValue: null,
|
|
218
|
+
jsonValue,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function crmRecordIdentityColumns(record: CrmRecord) {
|
|
223
|
+
return {
|
|
224
|
+
provider: record.ref.provider,
|
|
225
|
+
objectType: record.ref.objectType,
|
|
226
|
+
kind: record.ref.kind,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function crmRecordSummaryColumns(record: CrmRecord) {
|
|
231
|
+
const fields = record.fields;
|
|
232
|
+
const string = (...names: string[]) => {
|
|
233
|
+
for (const name of names) {
|
|
234
|
+
if (typeof fields[name] === "string") return fields[name];
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
};
|
|
238
|
+
const numeric = (...names: string[]) => {
|
|
239
|
+
for (const name of names) {
|
|
240
|
+
const value = fields[name];
|
|
241
|
+
if (typeof value === "number") return value;
|
|
242
|
+
if (typeof value === "string" && /^-?\d+(\.\d+)?$/.test(value))
|
|
243
|
+
return Number(value);
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
};
|
|
247
|
+
return {
|
|
248
|
+
displayName: record.displayName.slice(0, 500),
|
|
249
|
+
primaryEmail: string("email", "Email"),
|
|
250
|
+
domain: string("domain", "Website"),
|
|
251
|
+
stage: string("dealstage", "StageName"),
|
|
252
|
+
pipelineId: string("pipeline", "RecordTypeId"),
|
|
253
|
+
ownerRemoteId: string("hubspot_owner_id", "OwnerId"),
|
|
254
|
+
amount: numeric("amount", "Amount"),
|
|
255
|
+
closeDate: string("closedate", "CloseDate"),
|
|
256
|
+
remoteRevision: record.remoteRevision ?? null,
|
|
257
|
+
remoteUpdatedAt: record.remoteUpdatedAt ?? null,
|
|
258
|
+
lastSyncedAt: new Date().toISOString(),
|
|
259
|
+
accessScopeKey: record.accessScope.key.slice(0, 500),
|
|
260
|
+
accessScopeJson: JSON.stringify(record.accessScope).slice(0, 8_000),
|
|
261
|
+
tombstone: record.deleted,
|
|
262
|
+
updatedAt: new Date().toISOString(),
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async function persistSchema(input: {
|
|
267
|
+
connectionId: string;
|
|
268
|
+
object: CrmObjectDefinition;
|
|
269
|
+
mirrored: Set<string>;
|
|
270
|
+
ownership: Ownership;
|
|
271
|
+
capabilities: CrmAdapter["capabilities"];
|
|
272
|
+
}): Promise<Map<string, string>> {
|
|
273
|
+
const db = getDb();
|
|
274
|
+
const [existingObject] = await db
|
|
275
|
+
.select({ id: schema.crmObjects.id })
|
|
276
|
+
.from(schema.crmObjects)
|
|
277
|
+
.where(
|
|
278
|
+
and(
|
|
279
|
+
eq(schema.crmObjects.connectionId, input.connectionId),
|
|
280
|
+
eq(schema.crmObjects.objectType, input.object.objectType),
|
|
281
|
+
accessFilter(schema.crmObjects, schema.crmObjectShares),
|
|
282
|
+
),
|
|
283
|
+
)
|
|
284
|
+
.limit(1);
|
|
285
|
+
const now = new Date().toISOString();
|
|
286
|
+
const objectValues = {
|
|
287
|
+
provider: input.object.provider,
|
|
288
|
+
objectType: input.object.objectType,
|
|
289
|
+
kind: input.object.kind,
|
|
290
|
+
label: input.object.label.slice(0, 500),
|
|
291
|
+
pluralLabel: input.object.pluralLabel.slice(0, 500),
|
|
292
|
+
custom: input.object.custom,
|
|
293
|
+
queryable: input.object.queryable,
|
|
294
|
+
searchable: input.object.searchable,
|
|
295
|
+
createable: input.object.createable,
|
|
296
|
+
updateable: input.object.updateable,
|
|
297
|
+
deleteable: input.object.deleteable,
|
|
298
|
+
capabilitiesJson: JSON.stringify(input.capabilities).slice(0, 4_000),
|
|
299
|
+
updatedAt: now,
|
|
300
|
+
};
|
|
301
|
+
if (existingObject) {
|
|
302
|
+
await assertAccess("crm-object", existingObject.id, "editor");
|
|
303
|
+
await db
|
|
304
|
+
.update(schema.crmObjects)
|
|
305
|
+
.set(objectValues)
|
|
306
|
+
.where(
|
|
307
|
+
and(
|
|
308
|
+
eq(schema.crmObjects.id, existingObject.id),
|
|
309
|
+
accessFilter(
|
|
310
|
+
schema.crmObjects,
|
|
311
|
+
schema.crmObjectShares,
|
|
312
|
+
undefined,
|
|
313
|
+
"editor",
|
|
314
|
+
),
|
|
315
|
+
),
|
|
316
|
+
);
|
|
317
|
+
} else {
|
|
318
|
+
await db.insert(schema.crmObjects).values({
|
|
319
|
+
id: crypto.randomUUID(),
|
|
320
|
+
connectionId: input.connectionId,
|
|
321
|
+
...objectValues,
|
|
322
|
+
...input.ownership,
|
|
323
|
+
createdAt: now,
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const existingPolicies = await db
|
|
328
|
+
.select({
|
|
329
|
+
id: schema.crmFieldPolicies.id,
|
|
330
|
+
fieldName: schema.crmFieldPolicies.fieldName,
|
|
331
|
+
storagePolicy: schema.crmFieldPolicies.storagePolicy,
|
|
332
|
+
})
|
|
333
|
+
.from(schema.crmFieldPolicies)
|
|
334
|
+
.where(
|
|
335
|
+
and(
|
|
336
|
+
eq(schema.crmFieldPolicies.connectionId, input.connectionId),
|
|
337
|
+
eq(schema.crmFieldPolicies.objectType, input.object.objectType),
|
|
338
|
+
accessFilter(schema.crmFieldPolicies, schema.crmFieldPolicyShares),
|
|
339
|
+
),
|
|
340
|
+
);
|
|
341
|
+
const byName = new Map(
|
|
342
|
+
existingPolicies.map((policy) => [policy.fieldName, policy]),
|
|
343
|
+
);
|
|
344
|
+
const policyIds = new Map(
|
|
345
|
+
existingPolicies.map((policy) => [policy.fieldName, policy.id]),
|
|
346
|
+
);
|
|
347
|
+
for (const field of fieldsForPolicyDiscovery(input.object)) {
|
|
348
|
+
const existing = byName.get(field.name);
|
|
349
|
+
const discoveredPolicy =
|
|
350
|
+
field.storagePolicy === "local-authoritative" ||
|
|
351
|
+
field.storagePolicy === "derived-local"
|
|
352
|
+
? field.storagePolicy
|
|
353
|
+
: storagePolicyFor(field, input.mirrored);
|
|
354
|
+
const storagePolicy =
|
|
355
|
+
existing?.storagePolicy === "local-authoritative"
|
|
356
|
+
? "local-authoritative"
|
|
357
|
+
: discoveredPolicy;
|
|
358
|
+
const values = {
|
|
359
|
+
label: field.label.slice(0, 500),
|
|
360
|
+
valueType: field.valueType,
|
|
361
|
+
storagePolicy,
|
|
362
|
+
sensitive: field.sensitive,
|
|
363
|
+
readable: field.readable,
|
|
364
|
+
createable: field.createable,
|
|
365
|
+
updateable: field.updateable,
|
|
366
|
+
required: field.required,
|
|
367
|
+
metadataJson: JSON.stringify({
|
|
368
|
+
options: field.options,
|
|
369
|
+
referencedObjectType: field.referencedObjectType,
|
|
370
|
+
}).slice(0, 8_000),
|
|
371
|
+
updatedAt: now,
|
|
372
|
+
};
|
|
373
|
+
if (existing) {
|
|
374
|
+
await assertAccess("crm-field-policy", existing.id, "editor");
|
|
375
|
+
await db
|
|
376
|
+
.update(schema.crmFieldPolicies)
|
|
377
|
+
.set(values)
|
|
378
|
+
.where(
|
|
379
|
+
and(
|
|
380
|
+
eq(schema.crmFieldPolicies.id, existing.id),
|
|
381
|
+
accessFilter(
|
|
382
|
+
schema.crmFieldPolicies,
|
|
383
|
+
schema.crmFieldPolicyShares,
|
|
384
|
+
undefined,
|
|
385
|
+
"editor",
|
|
386
|
+
),
|
|
387
|
+
),
|
|
388
|
+
);
|
|
389
|
+
} else {
|
|
390
|
+
const id = crypto.randomUUID();
|
|
391
|
+
await db.insert(schema.crmFieldPolicies).values({
|
|
392
|
+
id,
|
|
393
|
+
connectionId: input.connectionId,
|
|
394
|
+
objectType: input.object.objectType,
|
|
395
|
+
fieldName: field.name,
|
|
396
|
+
...values,
|
|
397
|
+
...input.ownership,
|
|
398
|
+
createdAt: now,
|
|
399
|
+
});
|
|
400
|
+
policyIds.set(field.name, id);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return policyIds;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
async function persistPage(input: {
|
|
407
|
+
connectionId: string;
|
|
408
|
+
provider: string;
|
|
409
|
+
objectType: string;
|
|
410
|
+
page: Awaited<ReturnType<CrmAdapter["syncPage"]>>;
|
|
411
|
+
fields: Map<string, CrmFieldDefinition>;
|
|
412
|
+
fieldPolicyIds: Map<string, string>;
|
|
413
|
+
mirrored: Set<string>;
|
|
414
|
+
ownership: Ownership;
|
|
415
|
+
}) {
|
|
416
|
+
const db = getDb();
|
|
417
|
+
const remoteIds = input.page.records.map((record) => record.ref.remoteId);
|
|
418
|
+
if (remoteIds.length === 0)
|
|
419
|
+
return { recordsUpserted: 0, tombstonesApplied: 0, rejectedFields: 0 };
|
|
420
|
+
return db.transaction(async (tx) => {
|
|
421
|
+
const existingRecords = await tx
|
|
422
|
+
.select({
|
|
423
|
+
id: schema.crmRecords.id,
|
|
424
|
+
remoteId: schema.crmRecords.remoteId,
|
|
425
|
+
ownerEmail: schema.crmRecords.ownerEmail,
|
|
426
|
+
orgId: schema.crmRecords.orgId,
|
|
427
|
+
visibility: schema.crmRecords.visibility,
|
|
428
|
+
})
|
|
429
|
+
.from(schema.crmRecords)
|
|
430
|
+
.where(
|
|
431
|
+
and(
|
|
432
|
+
eq(schema.crmRecords.connectionId, input.connectionId),
|
|
433
|
+
eq(schema.crmRecords.provider, input.provider),
|
|
434
|
+
eq(schema.crmRecords.objectType, input.objectType),
|
|
435
|
+
inArray(schema.crmRecords.remoteId, remoteIds),
|
|
436
|
+
accessFilter(schema.crmRecords, schema.crmRecordShares),
|
|
437
|
+
),
|
|
438
|
+
);
|
|
439
|
+
const recordsByRemoteId = new Map(
|
|
440
|
+
existingRecords.map((record) => [record.remoteId, record]),
|
|
441
|
+
);
|
|
442
|
+
const recordIds = existingRecords.map((record) => record.id);
|
|
443
|
+
const existingFields = recordIds.length
|
|
444
|
+
? await tx
|
|
445
|
+
.select({
|
|
446
|
+
id: schema.crmRecordFields.id,
|
|
447
|
+
recordId: schema.crmRecordFields.recordId,
|
|
448
|
+
fieldName: schema.crmRecordFields.fieldName,
|
|
449
|
+
storagePolicy: schema.crmRecordFields.storagePolicy,
|
|
450
|
+
})
|
|
451
|
+
.from(schema.crmRecordFields)
|
|
452
|
+
.where(
|
|
453
|
+
and(
|
|
454
|
+
inArray(schema.crmRecordFields.recordId, recordIds),
|
|
455
|
+
accessFilter(schema.crmRecordFields, schema.crmRecordFieldShares),
|
|
456
|
+
),
|
|
457
|
+
)
|
|
458
|
+
: [];
|
|
459
|
+
const fieldsByRecord = new Map(
|
|
460
|
+
existingFields.map((field) => [
|
|
461
|
+
`${field.recordId}:${field.fieldName}`,
|
|
462
|
+
field,
|
|
463
|
+
]),
|
|
464
|
+
);
|
|
465
|
+
let recordsUpserted = 0;
|
|
466
|
+
let tombstonesApplied = 0;
|
|
467
|
+
let rejectedFields = 0;
|
|
468
|
+
for (const remoteRecord of input.page.records) {
|
|
469
|
+
const existing = recordsByRemoteId.get(remoteRecord.ref.remoteId);
|
|
470
|
+
const values = crmRecordSummaryColumns(remoteRecord);
|
|
471
|
+
const identity = crmRecordIdentityColumns(remoteRecord);
|
|
472
|
+
const recordId = existing?.id ?? crypto.randomUUID();
|
|
473
|
+
const ownership = existing
|
|
474
|
+
? {
|
|
475
|
+
ownerEmail: existing.ownerEmail,
|
|
476
|
+
orgId: existing.orgId,
|
|
477
|
+
visibility: existing.visibility,
|
|
478
|
+
}
|
|
479
|
+
: input.ownership;
|
|
480
|
+
if (existing) {
|
|
481
|
+
await tx
|
|
482
|
+
.update(schema.crmRecords)
|
|
483
|
+
.set({
|
|
484
|
+
...values,
|
|
485
|
+
...identity,
|
|
486
|
+
})
|
|
487
|
+
.where(
|
|
488
|
+
and(
|
|
489
|
+
eq(schema.crmRecords.id, existing.id),
|
|
490
|
+
accessFilter(
|
|
491
|
+
schema.crmRecords,
|
|
492
|
+
schema.crmRecordShares,
|
|
493
|
+
undefined,
|
|
494
|
+
"editor",
|
|
495
|
+
),
|
|
496
|
+
),
|
|
497
|
+
);
|
|
498
|
+
} else {
|
|
499
|
+
await tx.insert(schema.crmRecords).values({
|
|
500
|
+
id: recordId,
|
|
501
|
+
connectionId: input.connectionId,
|
|
502
|
+
...identity,
|
|
503
|
+
remoteId: remoteRecord.ref.remoteId,
|
|
504
|
+
...values,
|
|
505
|
+
...ownership,
|
|
506
|
+
createdAt: new Date().toISOString(),
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
recordsUpserted += 1;
|
|
510
|
+
if (remoteRecord.deleted) tombstonesApplied += 1;
|
|
511
|
+
for (const [fieldName, rawValue] of Object.entries(remoteRecord.fields)) {
|
|
512
|
+
if (
|
|
513
|
+
!input.mirrored.has(fieldName) ||
|
|
514
|
+
BINARY_OR_TRANSCRIPT_FIELD.test(fieldName)
|
|
515
|
+
) {
|
|
516
|
+
rejectedFields += 1;
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
const definition = input.fields.get(fieldName);
|
|
520
|
+
if (!definition || definition.sensitive) {
|
|
521
|
+
rejectedFields += 1;
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
const value = safeMirroredValue(rawValue);
|
|
525
|
+
if (value === null && rawValue !== null) {
|
|
526
|
+
rejectedFields += 1;
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
529
|
+
const provenance = remoteRecord.provenance.filter(
|
|
530
|
+
(item) => item.fieldName === fieldName,
|
|
531
|
+
);
|
|
532
|
+
const fieldValues = {
|
|
533
|
+
fieldPolicyId: input.fieldPolicyIds.get(fieldName) ?? null,
|
|
534
|
+
valueType: definition.valueType,
|
|
535
|
+
storagePolicy: "mirrored" as const,
|
|
536
|
+
...fieldColumns(value),
|
|
537
|
+
provenanceJson: JSON.stringify(provenance).slice(0, 4_000),
|
|
538
|
+
accessScopeKey: remoteRecord.accessScope.key.slice(0, 500),
|
|
539
|
+
accessScopeJson: JSON.stringify(remoteRecord.accessScope).slice(
|
|
540
|
+
0,
|
|
541
|
+
8_000,
|
|
542
|
+
),
|
|
543
|
+
remoteRevision: remoteRecord.remoteRevision ?? null,
|
|
544
|
+
updatedAt: new Date().toISOString(),
|
|
545
|
+
};
|
|
546
|
+
const existingField = fieldsByRecord.get(`${recordId}:${fieldName}`);
|
|
547
|
+
if (existingField?.storagePolicy === "local-authoritative") continue;
|
|
548
|
+
if (existingField) {
|
|
549
|
+
await tx
|
|
550
|
+
.update(schema.crmRecordFields)
|
|
551
|
+
.set(fieldValues)
|
|
552
|
+
.where(
|
|
553
|
+
and(
|
|
554
|
+
eq(schema.crmRecordFields.id, existingField.id),
|
|
555
|
+
accessFilter(
|
|
556
|
+
schema.crmRecordFields,
|
|
557
|
+
schema.crmRecordFieldShares,
|
|
558
|
+
undefined,
|
|
559
|
+
"editor",
|
|
560
|
+
),
|
|
561
|
+
),
|
|
562
|
+
);
|
|
563
|
+
} else {
|
|
564
|
+
await tx.insert(schema.crmRecordFields).values({
|
|
565
|
+
id: crypto.randomUUID(),
|
|
566
|
+
recordId,
|
|
567
|
+
fieldName,
|
|
568
|
+
...fieldValues,
|
|
569
|
+
...ownership,
|
|
570
|
+
createdAt: new Date().toISOString(),
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return { recordsUpserted, tombstonesApplied, rejectedFields };
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export async function syncCrmMirror(input: MirrorSyncInput) {
|
|
580
|
+
const object = await input.adapter.describeObject(input.objectType);
|
|
581
|
+
const fields = resolveMirrorFields({
|
|
582
|
+
object,
|
|
583
|
+
requested: input.fieldAllowList,
|
|
584
|
+
allowCustomObject: input.allowCustomObject,
|
|
585
|
+
});
|
|
586
|
+
if (fields.length === 0)
|
|
587
|
+
throw new Error(
|
|
588
|
+
"No readable, safe fields are eligible for thin mirroring.",
|
|
589
|
+
);
|
|
590
|
+
const mirrored = new Set(fields);
|
|
591
|
+
const fieldPolicyIds = await persistSchema({
|
|
592
|
+
connectionId: input.connectionId,
|
|
593
|
+
object,
|
|
594
|
+
mirrored,
|
|
595
|
+
ownership: input.ownership,
|
|
596
|
+
capabilities: input.adapter.capabilities,
|
|
597
|
+
});
|
|
598
|
+
const db = getDb();
|
|
599
|
+
const startedAt = new Date().toISOString();
|
|
600
|
+
const syncRunId = crypto.randomUUID();
|
|
601
|
+
await db.insert(schema.crmSyncRuns).values({
|
|
602
|
+
id: syncRunId,
|
|
603
|
+
connectionId: input.connectionId,
|
|
604
|
+
status: "running",
|
|
605
|
+
scopeJson: JSON.stringify(input.scope).slice(0, 8_000),
|
|
606
|
+
cursor: input.cursor ?? null,
|
|
607
|
+
startedAt,
|
|
608
|
+
...input.ownership,
|
|
609
|
+
createdAt: startedAt,
|
|
610
|
+
updatedAt: startedAt,
|
|
611
|
+
});
|
|
612
|
+
let cursor = input.cursor;
|
|
613
|
+
let complete = false;
|
|
614
|
+
let recordsUpserted = 0;
|
|
615
|
+
let tombstonesApplied = 0;
|
|
616
|
+
let rejectedFields = 0;
|
|
617
|
+
const pages = Math.min(input.maxPages ?? MAX_SYNC_PAGES, MAX_SYNC_PAGES);
|
|
618
|
+
const pageSize = Math.min(
|
|
619
|
+
input.pageSize ?? MAX_SYNC_PAGE_SIZE,
|
|
620
|
+
MAX_SYNC_PAGE_SIZE,
|
|
621
|
+
);
|
|
622
|
+
try {
|
|
623
|
+
for (let pageIndex = 0; pageIndex < pages; pageIndex += 1) {
|
|
624
|
+
const page = await input.adapter.syncPage({
|
|
625
|
+
scope: input.scope,
|
|
626
|
+
fieldAllowList: fields,
|
|
627
|
+
cursor,
|
|
628
|
+
limit: pageSize,
|
|
629
|
+
});
|
|
630
|
+
const result = await persistPage({
|
|
631
|
+
connectionId: input.connectionId,
|
|
632
|
+
provider: object.provider,
|
|
633
|
+
objectType: object.objectType,
|
|
634
|
+
page,
|
|
635
|
+
fields: new Map(object.fields.map((field) => [field.name, field])),
|
|
636
|
+
fieldPolicyIds,
|
|
637
|
+
mirrored,
|
|
638
|
+
ownership: input.ownership,
|
|
639
|
+
});
|
|
640
|
+
recordsUpserted += result.recordsUpserted;
|
|
641
|
+
tombstonesApplied += result.tombstonesApplied;
|
|
642
|
+
rejectedFields += result.rejectedFields;
|
|
643
|
+
cursor = page.nextCursor;
|
|
644
|
+
complete = page.complete;
|
|
645
|
+
if (complete || !cursor) break;
|
|
646
|
+
}
|
|
647
|
+
const status = complete ? "success" : "partial";
|
|
648
|
+
const completedAt = new Date().toISOString();
|
|
649
|
+
await db
|
|
650
|
+
.update(schema.crmSyncRuns)
|
|
651
|
+
.set({
|
|
652
|
+
status,
|
|
653
|
+
cursor: cursor ?? null,
|
|
654
|
+
recordsUpserted,
|
|
655
|
+
tombstonesApplied,
|
|
656
|
+
relationshipsUpserted: 0,
|
|
657
|
+
completedAt,
|
|
658
|
+
updatedAt: completedAt,
|
|
659
|
+
})
|
|
660
|
+
.where(
|
|
661
|
+
and(
|
|
662
|
+
eq(schema.crmSyncRuns.id, syncRunId),
|
|
663
|
+
accessFilter(
|
|
664
|
+
schema.crmSyncRuns,
|
|
665
|
+
schema.crmSyncRunShares,
|
|
666
|
+
undefined,
|
|
667
|
+
"editor",
|
|
668
|
+
),
|
|
669
|
+
),
|
|
670
|
+
);
|
|
671
|
+
return {
|
|
672
|
+
syncRunId,
|
|
673
|
+
status,
|
|
674
|
+
cursor,
|
|
675
|
+
complete,
|
|
676
|
+
recordsUpserted,
|
|
677
|
+
tombstonesApplied,
|
|
678
|
+
relationshipsUpserted: 0,
|
|
679
|
+
rejectedFields,
|
|
680
|
+
fieldAllowList: fields,
|
|
681
|
+
};
|
|
682
|
+
} catch (error) {
|
|
683
|
+
const message =
|
|
684
|
+
error instanceof Error
|
|
685
|
+
? error.message.slice(0, 1_000)
|
|
686
|
+
: "CRM sync failed.";
|
|
687
|
+
await db
|
|
688
|
+
.update(schema.crmSyncRuns)
|
|
689
|
+
.set({
|
|
690
|
+
status: "failed",
|
|
691
|
+
cursor: cursor ?? null,
|
|
692
|
+
recordsUpserted,
|
|
693
|
+
tombstonesApplied,
|
|
694
|
+
error: message,
|
|
695
|
+
completedAt: new Date().toISOString(),
|
|
696
|
+
updatedAt: new Date().toISOString(),
|
|
697
|
+
})
|
|
698
|
+
.where(
|
|
699
|
+
and(
|
|
700
|
+
eq(schema.crmSyncRuns.id, syncRunId),
|
|
701
|
+
accessFilter(
|
|
702
|
+
schema.crmSyncRuns,
|
|
703
|
+
schema.crmSyncRunShares,
|
|
704
|
+
undefined,
|
|
705
|
+
"editor",
|
|
706
|
+
),
|
|
707
|
+
),
|
|
708
|
+
);
|
|
709
|
+
throw error;
|
|
710
|
+
}
|
|
711
|
+
}
|