@agent-native/core 0.118.0 → 0.118.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/corpus/README.md +2 -2
- package/corpus/core/CHANGELOG.md +21 -0
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/a2a/client.ts +32 -10
- package/corpus/core/src/cli/index.ts +18 -10
- package/corpus/core/src/cli/multi-frontier-runs.ts +5 -3
- package/corpus/core/src/cli/templates-meta.ts +0 -12
- package/corpus/core/src/cli/workspace-dev.ts +1 -1
- package/corpus/core/src/client/AgentPanel.tsx +9 -1
- package/corpus/core/src/client/RunStuckBanner.tsx +39 -47
- package/corpus/core/src/client/chat/action-chat-ui-surface.tsx +32 -0
- package/corpus/core/src/client/chat/message-components.tsx +53 -8
- package/corpus/core/src/client/chat/tool-call-display.tsx +24 -9
- package/corpus/core/src/client/chat/widgets/InlineExtensionWidget.tsx +0 -1
- package/corpus/core/src/client/chat/widgets/builtin-tool-renderers.tsx +7 -3
- package/corpus/core/src/client/conversation/AgentConversation.tsx +12 -1
- package/corpus/core/src/client/error-capture.ts +2 -6
- package/corpus/core/src/client/resources/McpConnectionSuggestion.tsx +20 -14
- package/corpus/core/src/client/resources/ResourcesPanel.tsx +5 -1
- package/corpus/core/src/client/resources/mcp-integration-catalog.ts +7 -17
- package/corpus/core/src/client/resources/mcp-integration-logos.ts +2 -2
- package/corpus/core/src/client/route-chunk-recovery.ts +5 -3
- package/corpus/core/src/client/session-replay.ts +3 -3
- package/corpus/core/src/client/settings/SettingsPanel.tsx +15 -6
- package/corpus/core/src/client/transcription/use-live-transcription.ts +64 -45
- package/corpus/core/src/deploy/build.ts +2 -1
- package/corpus/core/src/guards/db-tool-scoping.ts +1 -1
- package/corpus/core/src/integrations/adapters/slack.ts +84 -5
- package/corpus/core/src/integrations/index.ts +5 -1
- package/corpus/core/src/localization/default-messages.ts +1 -1
- package/corpus/core/src/mcp-client/oauth-routes.ts +45 -12
- package/corpus/core/src/server/realtime-voice.ts +4 -1
- package/corpus/core/src/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +7 -5
- package/corpus/core/src/terminal/cli-registry.ts +1 -1
- package/corpus/core/src/vite/client.ts +166 -1
- package/corpus/templates/analytics/app/hooks/use-dashboard-views.ts +13 -1
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/ViewsMenu.tsx +10 -0
- package/corpus/templates/analytics/changelog/2026-07-22-show-a-useful-error-when-saving-a-dashboard-view-fails.md +6 -0
- package/corpus/templates/brain/app/routes/sources.tsx +181 -114
- package/corpus/templates/clips/AGENTS.md +8 -6
- package/corpus/templates/clips/actions/request-transcript.ts +90 -420
- package/corpus/templates/clips/actions/save-browser-transcript.ts +11 -28
- package/corpus/templates/clips/app/components/capture-install-options.tsx +5 -3
- package/corpus/templates/clips/app/components/player/transcript-panel.tsx +3 -136
- package/corpus/templates/clips/app/lib/capture-install-options.ts +15 -4
- package/corpus/templates/clips/app/routes/download.tsx +3 -2
- package/corpus/templates/clips/changelog/2026-07-22-fixed-an-intermittent-hydration-error-on-the-download-page.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-22-fixed-transcript-generation-when-native-speech-capture-retur.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-22-transcript-generation-now-retries-with-backup-speech-recogni.md +6 -0
- package/corpus/templates/clips/server/lib/public-agent-context.ts +2 -2
- package/corpus/templates/clips/server/register-secrets.ts +7 -6
- package/corpus/templates/content/app/components/editor/SlashCommandMenu.tsx +16 -84
- package/corpus/templates/content/app/components/editor/VisualEditor.tsx +13 -7
- package/corpus/templates/content/app/components/editor/extensions/ImageBlock.tsx +2 -2
- package/corpus/templates/content/app/i18n-data.ts +10 -0
- package/corpus/templates/design/server/lib/fig-file-decoder.ts +1 -0
- package/corpus/templates/plan/app/entry.client.tsx +3 -0
- package/corpus/templates/plan/changelog/2026-07-22-recover-stale-pages-after-a-deployment-refresh-automatically.md +6 -0
- package/corpus/templates/slides/app/hooks/use-agent-generating.ts +10 -3
- package/corpus/templates/slides/app/pages/Index.tsx +1 -0
- package/corpus/templates/slides/changelog/2026-07-22-new-deck-prompts-now-open-in-their-own-visible-chat-thread.md +6 -0
- package/corpus/toolkit/CHANGELOG.md +9 -0
- package/corpus/toolkit/package.json +1 -1
- package/corpus/toolkit/src/composer/PromptComposer.tsx +5 -1
- package/corpus/toolkit/src/composer/RealtimeVoiceMode.tsx +119 -31
- package/corpus/toolkit/src/composer/useRealtimeVoiceMode.tsx +30 -0
- package/corpus/toolkit/src/conformance/runner.tsx +153 -1
- package/corpus/toolkit/src/editor/SharedRichEditor.tsx +13 -2
- package/corpus/toolkit/src/editor/SlashCommandMenu.tsx +20 -0
- package/corpus/toolkit/src/editor/index.ts +2 -0
- package/corpus/toolkit/src/styles.css +52 -23
- package/dist/a2a/client.d.ts +3 -1
- package/dist/a2a/client.d.ts.map +1 -1
- package/dist/a2a/client.js +17 -12
- package/dist/a2a/client.js.map +1 -1
- package/dist/cli/index.js +18 -8
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/multi-frontier-runs.js +3 -3
- package/dist/cli/multi-frontier-runs.js.map +1 -1
- package/dist/cli/templates-meta.d.ts.map +1 -1
- package/dist/cli/templates-meta.js +0 -12
- package/dist/cli/templates-meta.js.map +1 -1
- package/dist/cli/workspace-dev.js +1 -1
- package/dist/cli/workspace-dev.js.map +1 -1
- package/dist/client/AgentPanel.d.ts.map +1 -1
- package/dist/client/AgentPanel.js +4 -1
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/client/RunStuckBanner.d.ts +3 -5
- package/dist/client/RunStuckBanner.d.ts.map +1 -1
- package/dist/client/RunStuckBanner.js +17 -18
- package/dist/client/RunStuckBanner.js.map +1 -1
- package/dist/client/chat/action-chat-ui-surface.d.ts +8 -0
- package/dist/client/chat/action-chat-ui-surface.d.ts.map +1 -0
- package/dist/client/chat/action-chat-ui-surface.js +10 -0
- package/dist/client/chat/action-chat-ui-surface.js.map +1 -0
- package/dist/client/chat/message-components.d.ts +3 -0
- package/dist/client/chat/message-components.d.ts.map +1 -1
- package/dist/client/chat/message-components.js +40 -7
- 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 +13 -9
- package/dist/client/chat/tool-call-display.js.map +1 -1
- package/dist/client/chat/widgets/InlineExtensionWidget.d.ts.map +1 -1
- package/dist/client/chat/widgets/InlineExtensionWidget.js +1 -1
- package/dist/client/chat/widgets/InlineExtensionWidget.js.map +1 -1
- package/dist/client/chat/widgets/builtin-tool-renderers.d.ts.map +1 -1
- package/dist/client/chat/widgets/builtin-tool-renderers.js +5 -3
- package/dist/client/chat/widgets/builtin-tool-renderers.js.map +1 -1
- package/dist/client/conversation/AgentConversation.d.ts.map +1 -1
- package/dist/client/conversation/AgentConversation.js +3 -2
- package/dist/client/conversation/AgentConversation.js.map +1 -1
- package/dist/client/error-capture.d.ts.map +1 -1
- package/dist/client/error-capture.js +2 -2
- package/dist/client/error-capture.js.map +1 -1
- package/dist/client/resources/McpConnectionSuggestion.d.ts +1 -0
- package/dist/client/resources/McpConnectionSuggestion.d.ts.map +1 -1
- package/dist/client/resources/McpConnectionSuggestion.js +9 -8
- package/dist/client/resources/McpConnectionSuggestion.js.map +1 -1
- package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
- package/dist/client/resources/ResourcesPanel.js +3 -1
- package/dist/client/resources/ResourcesPanel.js.map +1 -1
- package/dist/client/resources/mcp-integration-catalog.d.ts +1 -0
- package/dist/client/resources/mcp-integration-catalog.d.ts.map +1 -1
- package/dist/client/resources/mcp-integration-catalog.js +4 -17
- package/dist/client/resources/mcp-integration-catalog.js.map +1 -1
- package/dist/client/resources/mcp-integration-logos.js +2 -2
- package/dist/client/resources/mcp-integration-logos.js.map +1 -1
- package/dist/client/route-chunk-recovery.d.ts.map +1 -1
- package/dist/client/route-chunk-recovery.js +5 -3
- package/dist/client/route-chunk-recovery.js.map +1 -1
- package/dist/client/session-replay.js +3 -3
- package/dist/client/session-replay.js.map +1 -1
- package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
- package/dist/client/settings/SettingsPanel.js +2 -2
- package/dist/client/settings/SettingsPanel.js.map +1 -1
- package/dist/client/transcription/use-live-transcription.d.ts +3 -3
- package/dist/client/transcription/use-live-transcription.d.ts.map +1 -1
- package/dist/client/transcription/use-live-transcription.js +22 -11
- package/dist/client/transcription/use-live-transcription.js.map +1 -1
- package/dist/collab/routes.d.ts +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +1 -1
- package/dist/deploy/build.js.map +1 -1
- package/dist/guards/db-tool-scoping.js +1 -1
- package/dist/guards/db-tool-scoping.js.map +1 -1
- package/dist/integrations/adapters/slack.d.ts +1 -0
- package/dist/integrations/adapters/slack.d.ts.map +1 -1
- package/dist/integrations/adapters/slack.js +61 -5
- package/dist/integrations/adapters/slack.js.map +1 -1
- package/dist/integrations/index.d.ts +1 -1
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/index.js +1 -1
- package/dist/integrations/index.js.map +1 -1
- package/dist/localization/default-messages.js +1 -1
- package/dist/localization/default-messages.js.map +1 -1
- package/dist/mcp-client/oauth-routes.d.ts +3 -0
- package/dist/mcp-client/oauth-routes.d.ts.map +1 -1
- package/dist/mcp-client/oauth-routes.js +41 -12
- package/dist/mcp-client/oauth-routes.js.map +1 -1
- package/dist/notifications/routes.d.ts +2 -2
- package/dist/observability/routes.d.ts +3 -3
- package/dist/provider-api/actions/custom-provider-registration.d.ts +8 -8
- package/dist/provider-api/actions/provider-api.d.ts +11 -11
- package/dist/secrets/routes.d.ts +6 -6
- package/dist/server/realtime-voice.d.ts.map +1 -1
- package/dist/server/realtime-voice.js +1 -1
- package/dist/server/realtime-voice.js.map +1 -1
- package/dist/server/transcribe-voice.d.ts +1 -1
- package/dist/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +7 -5
- package/dist/terminal/cli-registry.js +1 -1
- package/dist/terminal/cli-registry.js.map +1 -1
- package/dist/vite/client.d.ts +8 -1
- package/dist/vite/client.d.ts.map +1 -1
- package/dist/vite/client.js +113 -2
- package/dist/vite/client.js.map +1 -1
- package/package.json +2 -2
- package/src/a2a/client.ts +32 -10
- package/src/cli/index.ts +18 -10
- package/src/cli/multi-frontier-runs.ts +5 -3
- package/src/cli/templates-meta.ts +0 -12
- package/src/cli/workspace-dev.ts +1 -1
- package/src/client/AgentPanel.tsx +9 -1
- package/src/client/RunStuckBanner.tsx +39 -47
- package/src/client/chat/action-chat-ui-surface.tsx +32 -0
- package/src/client/chat/message-components.tsx +53 -8
- package/src/client/chat/tool-call-display.tsx +24 -9
- package/src/client/chat/widgets/InlineExtensionWidget.tsx +0 -1
- package/src/client/chat/widgets/builtin-tool-renderers.tsx +7 -3
- package/src/client/conversation/AgentConversation.tsx +12 -1
- package/src/client/error-capture.ts +2 -6
- package/src/client/resources/McpConnectionSuggestion.tsx +20 -14
- package/src/client/resources/ResourcesPanel.tsx +5 -1
- package/src/client/resources/mcp-integration-catalog.ts +7 -17
- package/src/client/resources/mcp-integration-logos.ts +2 -2
- package/src/client/route-chunk-recovery.ts +5 -3
- package/src/client/session-replay.ts +3 -3
- package/src/client/settings/SettingsPanel.tsx +15 -6
- package/src/client/transcription/use-live-transcription.ts +64 -45
- package/src/deploy/build.ts +2 -1
- package/src/guards/db-tool-scoping.ts +1 -1
- package/src/integrations/adapters/slack.ts +84 -5
- package/src/integrations/index.ts +5 -1
- package/src/localization/default-messages.ts +1 -1
- package/src/mcp-client/oauth-routes.ts +45 -12
- package/src/server/realtime-voice.ts +4 -1
- package/src/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +7 -5
- package/src/terminal/cli-registry.ts +1 -1
- package/src/vite/client.ts +166 -1
- package/corpus/templates/crm/.agents/skills/agent-native-docs/SKILL.md +0 -115
- package/corpus/templates/crm/.agents/skills/agent-native-toolkit/SKILL.md +0 -177
- package/corpus/templates/crm/.agents/skills/crm/SKILL.md +0 -128
- package/corpus/templates/crm/.agents/skills/customizing-agent-native/SKILL.md +0 -220
- package/corpus/templates/crm/.agents/skills/feature-flags/SKILL.md +0 -169
- package/corpus/templates/crm/.agents/skills/upgrade-agent-native/SKILL.md +0 -100
- package/corpus/templates/crm/.env.example +0 -5
- package/corpus/templates/crm/AGENTS.md +0 -120
- package/corpus/templates/crm/CHANGELOG.md +0 -1
- package/corpus/templates/crm/DEVELOPING.md +0 -66
- package/corpus/templates/crm/README.md +0 -106
- package/corpus/templates/crm/_gitignore +0 -12
- package/corpus/templates/crm/actions/_crm-action-utils.ts +0 -87
- package/corpus/templates/crm/actions/_crm-dashboard.ts +0 -69
- package/corpus/templates/crm/actions/_crm-data-program-actions.ts +0 -15
- package/corpus/templates/crm/actions/_crm-signal-utils.ts +0 -79
- package/corpus/templates/crm/actions/apply-crm-proposals.ts +0 -203
- package/corpus/templates/crm/actions/attach-call-evidence.ts +0 -170
- package/corpus/templates/crm/actions/configure-crm-connection.ts +0 -126
- package/corpus/templates/crm/actions/configure-native-crm.ts +0 -44
- package/corpus/templates/crm/actions/create-crm-record.ts +0 -148
- package/corpus/templates/crm/actions/create-crm-signal-tracker.ts +0 -58
- package/corpus/templates/crm/actions/delete-staged-dataset.ts +0 -14
- package/corpus/templates/crm/actions/get-crm-automation-recipe.ts +0 -36
- package/corpus/templates/crm/actions/get-crm-dashboard-panel.ts +0 -35
- package/corpus/templates/crm/actions/get-crm-dashboard.ts +0 -14
- package/corpus/templates/crm/actions/get-crm-overview.ts +0 -13
- package/corpus/templates/crm/actions/get-crm-pipeline-data.ts +0 -61
- package/corpus/templates/crm/actions/get-crm-record.ts +0 -75
- package/corpus/templates/crm/actions/install-crm-pipeline-dashboard.ts +0 -81
- package/corpus/templates/crm/actions/list-crm-dashboard-revisions.ts +0 -15
- package/corpus/templates/crm/actions/list-crm-dashboards.ts +0 -15
- package/corpus/templates/crm/actions/list-crm-proposals.ts +0 -31
- package/corpus/templates/crm/actions/list-crm-records.ts +0 -79
- package/corpus/templates/crm/actions/list-crm-saved-views.ts +0 -15
- package/corpus/templates/crm/actions/list-crm-signal-hits.ts +0 -43
- package/corpus/templates/crm/actions/list-crm-signal-trackers.ts +0 -32
- package/corpus/templates/crm/actions/list-crm-tasks.ts +0 -22
- package/corpus/templates/crm/actions/list-staged-datasets.ts +0 -14
- package/corpus/templates/crm/actions/list-workspace-connections.ts +0 -47
- package/corpus/templates/crm/actions/manage-crm-signal-tracker.ts +0 -87
- package/corpus/templates/crm/actions/manage-crm-task.ts +0 -132
- package/corpus/templates/crm/actions/navigate.ts +0 -63
- package/corpus/templates/crm/actions/provider-api-catalog.ts +0 -22
- package/corpus/templates/crm/actions/provider-api-docs.ts +0 -54
- package/corpus/templates/crm/actions/provider-api-request.ts +0 -92
- package/corpus/templates/crm/actions/query-staged-dataset.ts +0 -44
- package/corpus/templates/crm/actions/record-crm-call-insight.ts +0 -160
- package/corpus/templates/crm/actions/record-crm-smart-signal.ts +0 -150
- package/corpus/templates/crm/actions/restore-crm-dashboard-revision.ts +0 -23
- package/corpus/templates/crm/actions/review-crm-signal.ts +0 -31
- package/corpus/templates/crm/actions/run-crm-saved-view-program.ts +0 -103
- package/corpus/templates/crm/actions/run-crm-signal-trackers.ts +0 -275
- package/corpus/templates/crm/actions/run.ts +0 -7
- package/corpus/templates/crm/actions/save-crm-dashboard.ts +0 -51
- package/corpus/templates/crm/actions/save-crm-saved-view.ts +0 -119
- package/corpus/templates/crm/actions/sync-crm.ts +0 -146
- package/corpus/templates/crm/actions/update-crm-record.ts +0 -510
- package/corpus/templates/crm/actions/view-screen.ts +0 -218
- package/corpus/templates/crm/agent-native.app-skill.json +0 -58
- package/corpus/templates/crm/app/components/crm/CreateCrmRecordDialog.tsx +0 -158
- package/corpus/templates/crm/app/components/crm/CrmDashboardPanel.tsx +0 -78
- package/corpus/templates/crm/app/components/crm/CrmSignalsPanel.tsx +0 -226
- package/corpus/templates/crm/app/components/crm/IntelligenceSettings.tsx +0 -414
- package/corpus/templates/crm/app/components/crm/RecordActions.tsx +0 -510
- package/corpus/templates/crm/app/components/crm/RecordGrid.tsx +0 -134
- package/corpus/templates/crm/app/components/crm/RecordWorkspace.tsx +0 -362
- package/corpus/templates/crm/app/components/crm/SavedViewDataProgram.tsx +0 -93
- package/corpus/templates/crm/app/components/crm/Surface.tsx +0 -97
- package/corpus/templates/crm/app/components/crm/WorkOverview.tsx +0 -180
- package/corpus/templates/crm/app/components/layout/CrmLayout.tsx +0 -112
- package/corpus/templates/crm/app/components/layout/CrmSidebar.tsx +0 -84
- package/corpus/templates/crm/app/components/ui/alert-dialog.tsx +0 -1
- package/corpus/templates/crm/app/components/ui/badge.tsx +0 -1
- package/corpus/templates/crm/app/components/ui/button.tsx +0 -1
- package/corpus/templates/crm/app/components/ui/card.tsx +0 -1
- package/corpus/templates/crm/app/components/ui/dialog.tsx +0 -1
- package/corpus/templates/crm/app/components/ui/input.tsx +0 -1
- package/corpus/templates/crm/app/components/ui/label.tsx +0 -1
- package/corpus/templates/crm/app/components/ui/select.tsx +0 -1
- package/corpus/templates/crm/app/components/ui/sheet.tsx +0 -1
- package/corpus/templates/crm/app/components/ui/skeleton.tsx +0 -1
- package/corpus/templates/crm/app/components/ui/switch.tsx +0 -1
- package/corpus/templates/crm/app/components/ui/table.tsx +0 -1
- package/corpus/templates/crm/app/components/ui/tabs.tsx +0 -1
- package/corpus/templates/crm/app/components/ui/textarea.tsx +0 -1
- package/corpus/templates/crm/app/components/ui/toolkit-provider.tsx +0 -17
- package/corpus/templates/crm/app/design-system.ts +0 -3
- package/corpus/templates/crm/app/entry.client.tsx +0 -16
- package/corpus/templates/crm/app/entry.server.tsx +0 -10
- package/corpus/templates/crm/app/global.css +0 -167
- package/corpus/templates/crm/app/hooks/use-navigation-state.ts +0 -60
- package/corpus/templates/crm/app/i18n/en-US.ts +0 -89
- package/corpus/templates/crm/app/i18n/index.ts +0 -34
- package/corpus/templates/crm/app/lib/dashboard.ts +0 -13
- package/corpus/templates/crm/app/lib/navigation.ts +0 -54
- package/corpus/templates/crm/app/lib/tab-id.ts +0 -1
- package/corpus/templates/crm/app/lib/types.ts +0 -172
- package/corpus/templates/crm/app/lib/utils.ts +0 -1
- package/corpus/templates/crm/app/root.tsx +0 -91
- package/corpus/templates/crm/app/routes/_index.tsx +0 -26
- package/corpus/templates/crm/app/routes/accounts.tsx +0 -41
- package/corpus/templates/crm/app/routes/agent.tsx +0 -5
- package/corpus/templates/crm/app/routes/ask.tsx +0 -53
- package/corpus/templates/crm/app/routes/dashboard.tsx +0 -118
- package/corpus/templates/crm/app/routes/opportunities.tsx +0 -41
- package/corpus/templates/crm/app/routes/people.tsx +0 -41
- package/corpus/templates/crm/app/routes/proposals.tsx +0 -266
- package/corpus/templates/crm/app/routes/records.$recordId.tsx +0 -35
- package/corpus/templates/crm/app/routes/settings.tsx +0 -63
- package/corpus/templates/crm/app/routes/setup.tsx +0 -308
- package/corpus/templates/crm/app/routes/tasks.tsx +0 -252
- package/corpus/templates/crm/app/routes/views.tsx +0 -333
- package/corpus/templates/crm/app/routes.ts +0 -17
- package/corpus/templates/crm/app/vite-env.d.ts +0 -6
- package/corpus/templates/crm/changelog/2026-07-21-agent-native-crm.md +0 -6
- package/corpus/templates/crm/changelog/2026-07-21-clips-call-evidence-review-recipe.md +0 -6
- package/corpus/templates/crm/changelog/2026-07-21-crm-can-now-find-and-review-evidence-grounded-call-signals-w.md +0 -6
- package/corpus/templates/crm/changelog/2026-07-21-crm-can-now-manage-keyword-and-smart-call-signal-trackers-fr.md +0 -6
- package/corpus/templates/crm/changelog/2026-07-21-delegated-local-crm-automation.md +0 -6
- package/corpus/templates/crm/changelog/2026-07-21-native-sql.md +0 -6
- package/corpus/templates/crm/changelog/2026-07-21-pipeline-dashboard.md +0 -6
- package/corpus/templates/crm/changelog/2026-07-21-pipeline-dashboards-now-install-correctly-from-the-crm-actio.md +0 -6
- package/corpus/templates/crm/changelog/2026-07-21-salesforce-connection.md +0 -6
- package/corpus/templates/crm/changelog/2026-07-22-crm-field-validation-now-explains-which-fields-cannot-be-edi.md +0 -6
- package/corpus/templates/crm/changelog/2026-07-22-fixed-hubspot-contact-syncs-missing-records-updated-after-th.md +0 -6
- package/corpus/templates/crm/changelog/2026-07-22-fixed-pipeline-dashboard-panels-so-their-opportunity-data-lo.md +0 -6
- package/corpus/templates/crm/changelog/2026-07-22-full-page-chat-keeps-the-active-conversation-when-moving-to-.md +0 -6
- package/corpus/templates/crm/components.json +0 -20
- package/corpus/templates/crm/docs/architecture/crm-contract.md +0 -180
- package/corpus/templates/crm/learnings.defaults.md +0 -5
- package/corpus/templates/crm/package.json +0 -59
- package/corpus/templates/crm/public/favicon.svg +0 -1
- package/corpus/templates/crm/public/icon-180.svg +0 -1
- package/corpus/templates/crm/public/manifest.json +0 -11
- package/corpus/templates/crm/react-router.config.ts +0 -7
- package/corpus/templates/crm/server/crm/adapter.ts +0 -32
- package/corpus/templates/crm/server/crm/crm-field-firewall.ts +0 -64
- package/corpus/templates/crm/server/crm/crm-mirror.ts +0 -711
- package/corpus/templates/crm/server/crm/hubspot-adapter.ts +0 -1146
- package/corpus/templates/crm/server/crm/native-adapter.ts +0 -1715
- package/corpus/templates/crm/server/crm/read-through.ts +0 -207
- package/corpus/templates/crm/server/crm/salesforce-adapter.ts +0 -1255
- package/corpus/templates/crm/server/db/crm-store.ts +0 -1170
- package/corpus/templates/crm/server/db/index.ts +0 -169
- package/corpus/templates/crm/server/db/schema.ts +0 -441
- package/corpus/templates/crm/server/lib/intelligence/default-detectors.ts +0 -65
- package/corpus/templates/crm/server/lib/intelligence/evidence.ts +0 -105
- package/corpus/templates/crm/server/lib/intelligence/keyword-detector.ts +0 -100
- package/corpus/templates/crm/server/lib/intelligence/smart-detector.ts +0 -144
- package/corpus/templates/crm/server/lib/intelligence/summary.ts +0 -141
- package/corpus/templates/crm/server/lib/provider-api.ts +0 -64
- package/corpus/templates/crm/server/middleware/auth.ts +0 -4
- package/corpus/templates/crm/server/plugins/agent-chat.ts +0 -68
- package/corpus/templates/crm/server/plugins/auth.ts +0 -14
- package/corpus/templates/crm/server/plugins/core-routes.ts +0 -17
- package/corpus/templates/crm/server/plugins/db.ts +0 -454
- package/corpus/templates/crm/server/routes/[...page].get.ts +0 -5
- package/corpus/templates/crm/shared/crm-automation-recipes.ts +0 -132
- package/corpus/templates/crm/shared/crm-contract.ts +0 -254
- package/corpus/templates/crm/shared/crm-sales-config.ts +0 -63
- package/corpus/templates/crm/ssr-entry.ts +0 -11
- package/corpus/templates/crm/tsconfig.json +0 -24
- package/corpus/templates/crm/vite.config.ts +0 -15
- package/corpus/templates/crm/vitest.config.ts +0 -5
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { defineAction } from "@agent-native/core/action";
|
|
2
|
-
import { accessFilter, assertAccess } from "@agent-native/core/sharing";
|
|
3
|
-
import { and, eq, inArray } from "drizzle-orm";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
|
|
6
|
-
import { isSafeCrmEvidenceExcerpt } from "../server/crm/crm-field-firewall.js";
|
|
7
|
-
import { getDb, schema } from "../server/db/index.js";
|
|
8
|
-
import {
|
|
9
|
-
crmSignalIdempotencyKey,
|
|
10
|
-
signalTupleError,
|
|
11
|
-
} from "./_crm-signal-utils.js";
|
|
12
|
-
|
|
13
|
-
const insightSchema = z.object({
|
|
14
|
-
evidenceId: z.string().trim().min(1).max(128),
|
|
15
|
-
kind: z.enum(["call-summary", "next-step"]),
|
|
16
|
-
label: z.string().trim().min(1).max(120),
|
|
17
|
-
summary: z.string().trim().min(1).max(1_200).refine(isSafeCrmEvidenceExcerpt),
|
|
18
|
-
quote: z
|
|
19
|
-
.string()
|
|
20
|
-
.trim()
|
|
21
|
-
.max(1_200)
|
|
22
|
-
.refine(isSafeCrmEvidenceExcerpt)
|
|
23
|
-
.optional(),
|
|
24
|
-
quoteSeconds: z.coerce.number().finite().min(0).max(86_400),
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
export default defineAction({
|
|
28
|
-
description:
|
|
29
|
-
"Atomically record a bounded, evidence-cited call recap or next-step set produced through agent chat. No transcript body or raw model response is accepted.",
|
|
30
|
-
schema: z.object({
|
|
31
|
-
runId: z.string().trim().min(1).max(128),
|
|
32
|
-
recordId: z.string().trim().min(1).max(128),
|
|
33
|
-
insights: z.array(insightSchema).min(1).max(20),
|
|
34
|
-
model: z.string().trim().min(1).max(120),
|
|
35
|
-
modelVersion: z.string().trim().max(120).optional(),
|
|
36
|
-
idempotencyKey: z.string().trim().min(1).max(180),
|
|
37
|
-
}),
|
|
38
|
-
run: async (args, ctx) => {
|
|
39
|
-
await Promise.all([
|
|
40
|
-
assertAccess("crm-record", args.recordId, "editor"),
|
|
41
|
-
assertAccess("crm-signal-run", args.runId, "editor"),
|
|
42
|
-
...args.insights.map((item) =>
|
|
43
|
-
assertAccess("crm-call-evidence", item.evidenceId, "viewer"),
|
|
44
|
-
),
|
|
45
|
-
]);
|
|
46
|
-
const db = getDb();
|
|
47
|
-
const [run] = await db
|
|
48
|
-
.select()
|
|
49
|
-
.from(schema.crmSignalRuns)
|
|
50
|
-
.where(
|
|
51
|
-
and(
|
|
52
|
-
eq(schema.crmSignalRuns.id, args.runId),
|
|
53
|
-
accessFilter(schema.crmSignalRuns, schema.crmSignalRunShares),
|
|
54
|
-
),
|
|
55
|
-
)
|
|
56
|
-
.limit(1);
|
|
57
|
-
const evidenceIds = [
|
|
58
|
-
...new Set(args.insights.map((item) => item.evidenceId)),
|
|
59
|
-
];
|
|
60
|
-
const evidence = await db
|
|
61
|
-
.select()
|
|
62
|
-
.from(schema.crmCallEvidence)
|
|
63
|
-
.where(
|
|
64
|
-
and(
|
|
65
|
-
inArray(schema.crmCallEvidence.id, evidenceIds),
|
|
66
|
-
accessFilter(schema.crmCallEvidence, schema.crmCallEvidenceShares),
|
|
67
|
-
),
|
|
68
|
-
)
|
|
69
|
-
.limit(20);
|
|
70
|
-
if (
|
|
71
|
-
!run ||
|
|
72
|
-
run.kind !== "summary" ||
|
|
73
|
-
run.recordId !== args.recordId ||
|
|
74
|
-
evidence.length !== evidenceIds.length ||
|
|
75
|
-
evidence.some((item) => item.recordId !== args.recordId)
|
|
76
|
-
)
|
|
77
|
-
signalTupleError(
|
|
78
|
-
"The summary run, evidence, and record do not form an accessible tuple.",
|
|
79
|
-
);
|
|
80
|
-
const byId = new Map(evidence.map((item) => [item.id, item]));
|
|
81
|
-
const now = new Date().toISOString();
|
|
82
|
-
const rows: Array<typeof schema.crmSignals.$inferInsert> = [];
|
|
83
|
-
for (const [index, item] of args.insights.entries()) {
|
|
84
|
-
const source = byId.get(item.evidenceId)!;
|
|
85
|
-
const excerpt = source.quote.trim() || source.summary.trim();
|
|
86
|
-
if (item.quote && !excerpt.includes(item.quote))
|
|
87
|
-
throw new Error(
|
|
88
|
-
"Every insight quote must be an exact substring of its stored bounded evidence excerpt.",
|
|
89
|
-
);
|
|
90
|
-
const start = source.startSeconds ?? 0;
|
|
91
|
-
if (
|
|
92
|
-
item.quoteSeconds < start ||
|
|
93
|
-
(source.endSeconds !== null && item.quoteSeconds > source.endSeconds)
|
|
94
|
-
)
|
|
95
|
-
throw new Error(
|
|
96
|
-
"Every insight timestamp must fall inside its evidence excerpt.",
|
|
97
|
-
);
|
|
98
|
-
const idem = await crmSignalIdempotencyKey(
|
|
99
|
-
ctx,
|
|
100
|
-
args.recordId,
|
|
101
|
-
`${args.idempotencyKey}:${index}`,
|
|
102
|
-
);
|
|
103
|
-
rows.push({
|
|
104
|
-
id: crypto.randomUUID(),
|
|
105
|
-
runId: args.runId,
|
|
106
|
-
trackerId: null,
|
|
107
|
-
recordId: args.recordId,
|
|
108
|
-
evidenceId: item.evidenceId,
|
|
109
|
-
kind: item.kind,
|
|
110
|
-
label: item.label,
|
|
111
|
-
quote: item.quote ?? "",
|
|
112
|
-
speaker: source.speaker,
|
|
113
|
-
startSeconds: item.quoteSeconds,
|
|
114
|
-
endSeconds: source.endSeconds,
|
|
115
|
-
summary: item.summary,
|
|
116
|
-
confidence: 100,
|
|
117
|
-
detector: "agent",
|
|
118
|
-
model: args.model,
|
|
119
|
-
modelVersion: args.modelVersion ?? null,
|
|
120
|
-
reviewStatus: "unreviewed",
|
|
121
|
-
idempotencyKey: idem.key,
|
|
122
|
-
...idem.scope,
|
|
123
|
-
createdAt: now,
|
|
124
|
-
updatedAt: now,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
const existing = await db
|
|
128
|
-
.select({ key: schema.crmSignals.idempotencyKey })
|
|
129
|
-
.from(schema.crmSignals)
|
|
130
|
-
.where(
|
|
131
|
-
and(
|
|
132
|
-
inArray(
|
|
133
|
-
schema.crmSignals.idempotencyKey,
|
|
134
|
-
rows.map((row) => row.idempotencyKey),
|
|
135
|
-
),
|
|
136
|
-
accessFilter(schema.crmSignals, schema.crmSignalShares),
|
|
137
|
-
),
|
|
138
|
-
);
|
|
139
|
-
const existingKeys = new Set(existing.map((item) => item.key));
|
|
140
|
-
const pending = rows.filter((row) => !existingKeys.has(row.idempotencyKey));
|
|
141
|
-
await db.transaction(async (tx) => {
|
|
142
|
-
if (pending.length) await tx.insert(schema.crmSignals).values(pending);
|
|
143
|
-
await tx
|
|
144
|
-
.update(schema.crmSignalRuns)
|
|
145
|
-
.set({
|
|
146
|
-
status: "completed",
|
|
147
|
-
model: args.model,
|
|
148
|
-
modelVersion: args.modelVersion ?? null,
|
|
149
|
-
completedAt: now,
|
|
150
|
-
updatedAt: now,
|
|
151
|
-
})
|
|
152
|
-
.where(eq(schema.crmSignalRuns.id, args.runId));
|
|
153
|
-
});
|
|
154
|
-
return {
|
|
155
|
-
created: pending.length,
|
|
156
|
-
replayed: rows.length - pending.length,
|
|
157
|
-
signalIds: pending.map((row) => row.id),
|
|
158
|
-
};
|
|
159
|
-
},
|
|
160
|
-
});
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { defineAction } from "@agent-native/core/action";
|
|
2
|
-
import { accessFilter, assertAccess } from "@agent-native/core/sharing";
|
|
3
|
-
import { and, eq } from "drizzle-orm";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
|
|
6
|
-
import { isSafeCrmEvidenceExcerpt } from "../server/crm/crm-field-firewall.js";
|
|
7
|
-
import { getDb, schema } from "../server/db/index.js";
|
|
8
|
-
import {
|
|
9
|
-
crmSignalIdempotencyKey,
|
|
10
|
-
signalTupleError,
|
|
11
|
-
} from "./_crm-signal-utils.js";
|
|
12
|
-
|
|
13
|
-
export default defineAction({
|
|
14
|
-
description:
|
|
15
|
-
"Record one delegated-agent detector hit only after grounding it to an access-scoped evidence excerpt and queued smart run.",
|
|
16
|
-
schema: z.object({
|
|
17
|
-
runId: z.string().trim().min(1).max(128),
|
|
18
|
-
trackerId: z.string().trim().min(1).max(128),
|
|
19
|
-
recordId: z.string().trim().min(1).max(128),
|
|
20
|
-
evidenceId: z.string().trim().min(1).max(128),
|
|
21
|
-
quote: z.string().trim().min(1).max(1_200).refine(isSafeCrmEvidenceExcerpt),
|
|
22
|
-
confidence: z.coerce.number().finite().min(0).max(100),
|
|
23
|
-
model: z.string().trim().min(1).max(120),
|
|
24
|
-
modelVersion: z.string().trim().max(120).optional(),
|
|
25
|
-
idempotencyKey: z.string().trim().min(1).max(180),
|
|
26
|
-
}),
|
|
27
|
-
run: async (args, ctx) => {
|
|
28
|
-
await Promise.all([
|
|
29
|
-
assertAccess("crm-record", args.recordId, "editor"),
|
|
30
|
-
assertAccess("crm-signal-run", args.runId, "editor"),
|
|
31
|
-
assertAccess("crm-signal-tracker", args.trackerId, "viewer"),
|
|
32
|
-
assertAccess("crm-call-evidence", args.evidenceId, "viewer"),
|
|
33
|
-
]);
|
|
34
|
-
const db = getDb();
|
|
35
|
-
const [[run], [tracker], [evidence]] = await Promise.all([
|
|
36
|
-
db
|
|
37
|
-
.select()
|
|
38
|
-
.from(schema.crmSignalRuns)
|
|
39
|
-
.where(
|
|
40
|
-
and(
|
|
41
|
-
eq(schema.crmSignalRuns.id, args.runId),
|
|
42
|
-
accessFilter(schema.crmSignalRuns, schema.crmSignalRunShares),
|
|
43
|
-
),
|
|
44
|
-
)
|
|
45
|
-
.limit(1),
|
|
46
|
-
db
|
|
47
|
-
.select()
|
|
48
|
-
.from(schema.crmSignalTrackers)
|
|
49
|
-
.where(
|
|
50
|
-
and(
|
|
51
|
-
eq(schema.crmSignalTrackers.id, args.trackerId),
|
|
52
|
-
accessFilter(
|
|
53
|
-
schema.crmSignalTrackers,
|
|
54
|
-
schema.crmSignalTrackerShares,
|
|
55
|
-
),
|
|
56
|
-
),
|
|
57
|
-
)
|
|
58
|
-
.limit(1),
|
|
59
|
-
db
|
|
60
|
-
.select()
|
|
61
|
-
.from(schema.crmCallEvidence)
|
|
62
|
-
.where(
|
|
63
|
-
and(
|
|
64
|
-
eq(schema.crmCallEvidence.id, args.evidenceId),
|
|
65
|
-
accessFilter(schema.crmCallEvidence, schema.crmCallEvidenceShares),
|
|
66
|
-
),
|
|
67
|
-
)
|
|
68
|
-
.limit(1),
|
|
69
|
-
]);
|
|
70
|
-
if (
|
|
71
|
-
!run ||
|
|
72
|
-
!tracker ||
|
|
73
|
-
!evidence ||
|
|
74
|
-
run.kind !== "smart" ||
|
|
75
|
-
run.recordId !== args.recordId ||
|
|
76
|
-
run.trackerId !== args.trackerId ||
|
|
77
|
-
tracker.kind !== "smart" ||
|
|
78
|
-
evidence.recordId !== args.recordId
|
|
79
|
-
)
|
|
80
|
-
signalTupleError(
|
|
81
|
-
"The signal run, tracker, evidence, and record do not form an accessible tuple.",
|
|
82
|
-
);
|
|
83
|
-
const source = evidence.quote.trim() || evidence.summary.trim();
|
|
84
|
-
if (!source.includes(args.quote))
|
|
85
|
-
throw new Error(
|
|
86
|
-
"The signal quote must be an exact substring of the stored bounded evidence excerpt.",
|
|
87
|
-
);
|
|
88
|
-
const idem = await crmSignalIdempotencyKey(
|
|
89
|
-
ctx,
|
|
90
|
-
args.recordId,
|
|
91
|
-
args.idempotencyKey,
|
|
92
|
-
);
|
|
93
|
-
const [existing] = await db
|
|
94
|
-
.select()
|
|
95
|
-
.from(schema.crmSignals)
|
|
96
|
-
.where(
|
|
97
|
-
and(
|
|
98
|
-
eq(schema.crmSignals.idempotencyKey, idem.key),
|
|
99
|
-
accessFilter(schema.crmSignals, schema.crmSignalShares),
|
|
100
|
-
),
|
|
101
|
-
)
|
|
102
|
-
.limit(1);
|
|
103
|
-
if (existing) return existing;
|
|
104
|
-
const now = new Date().toISOString();
|
|
105
|
-
const id = crypto.randomUUID();
|
|
106
|
-
await db.transaction(async (tx) => {
|
|
107
|
-
await tx.insert(schema.crmSignals).values({
|
|
108
|
-
id,
|
|
109
|
-
runId: args.runId,
|
|
110
|
-
trackerId: args.trackerId,
|
|
111
|
-
recordId: args.recordId,
|
|
112
|
-
evidenceId: args.evidenceId,
|
|
113
|
-
kind: "moment",
|
|
114
|
-
label: tracker.name,
|
|
115
|
-
quote: args.quote,
|
|
116
|
-
speaker: evidence.speaker,
|
|
117
|
-
startSeconds: evidence.startSeconds,
|
|
118
|
-
endSeconds: evidence.endSeconds,
|
|
119
|
-
summary: "",
|
|
120
|
-
confidence: args.confidence,
|
|
121
|
-
detector: "agent",
|
|
122
|
-
model: args.model,
|
|
123
|
-
modelVersion: args.modelVersion ?? null,
|
|
124
|
-
reviewStatus: "unreviewed",
|
|
125
|
-
idempotencyKey: idem.key,
|
|
126
|
-
...idem.scope,
|
|
127
|
-
createdAt: now,
|
|
128
|
-
updatedAt: now,
|
|
129
|
-
});
|
|
130
|
-
await tx
|
|
131
|
-
.update(schema.crmSignalRuns)
|
|
132
|
-
.set({
|
|
133
|
-
status: "completed",
|
|
134
|
-
model: args.model,
|
|
135
|
-
modelVersion: args.modelVersion ?? null,
|
|
136
|
-
completedAt: now,
|
|
137
|
-
updatedAt: now,
|
|
138
|
-
})
|
|
139
|
-
.where(eq(schema.crmSignalRuns.id, args.runId));
|
|
140
|
-
});
|
|
141
|
-
const [saved] = await db
|
|
142
|
-
.select()
|
|
143
|
-
.from(schema.crmSignals)
|
|
144
|
-
.where(eq(schema.crmSignals.id, id))
|
|
145
|
-
.limit(1);
|
|
146
|
-
if (!saved)
|
|
147
|
-
throw new Error("CRM signal could not be verified after saving.");
|
|
148
|
-
return saved;
|
|
149
|
-
},
|
|
150
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { defineAction, type ActionRunContext } from "@agent-native/core/action";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
import { crmDashboardStore } from "../server/db/index.js";
|
|
5
|
-
import { requireDashboardAccess } from "./_crm-dashboard.js";
|
|
6
|
-
|
|
7
|
-
export default defineAction({
|
|
8
|
-
description:
|
|
9
|
-
"Restore one revision of an access-scoped CRM dashboard. The restore is revision-aware and fails if the dashboard changed concurrently.",
|
|
10
|
-
schema: z.object({
|
|
11
|
-
id: z.string().trim().min(1).max(200),
|
|
12
|
-
revisionId: z.string().trim().min(1).max(200),
|
|
13
|
-
}),
|
|
14
|
-
run: async ({ id, revisionId }, ctx?: ActionRunContext) => {
|
|
15
|
-
const dashboard = await crmDashboardStore.restore(
|
|
16
|
-
id,
|
|
17
|
-
revisionId,
|
|
18
|
-
requireDashboardAccess(ctx),
|
|
19
|
-
);
|
|
20
|
-
if (!dashboard) throw new Error("CRM dashboard revision was not found.");
|
|
21
|
-
return dashboard;
|
|
22
|
-
},
|
|
23
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { defineAction } from "@agent-native/core/action";
|
|
2
|
-
import { assertAccess } from "@agent-native/core/sharing";
|
|
3
|
-
import { eq } from "drizzle-orm";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
|
|
6
|
-
import { getDb, schema } from "../server/db/index.js";
|
|
7
|
-
|
|
8
|
-
export default defineAction({
|
|
9
|
-
description:
|
|
10
|
-
"Confirm, dismiss, or return one access-scoped CRM signal to the unreviewed queue.",
|
|
11
|
-
schema: z.object({
|
|
12
|
-
signalId: z.string().trim().min(1).max(128),
|
|
13
|
-
reviewStatus: z.enum(["unreviewed", "confirmed", "dismissed"]),
|
|
14
|
-
}),
|
|
15
|
-
run: async (args) => {
|
|
16
|
-
await assertAccess("crm-signal", args.signalId, "editor");
|
|
17
|
-
const now = new Date().toISOString();
|
|
18
|
-
await getDb()
|
|
19
|
-
.update(schema.crmSignals)
|
|
20
|
-
.set({ reviewStatus: args.reviewStatus, updatedAt: now })
|
|
21
|
-
.where(eq(schema.crmSignals.id, args.signalId));
|
|
22
|
-
const [saved] = await getDb()
|
|
23
|
-
.select()
|
|
24
|
-
.from(schema.crmSignals)
|
|
25
|
-
.where(eq(schema.crmSignals.id, args.signalId))
|
|
26
|
-
.limit(1);
|
|
27
|
-
if (!saved)
|
|
28
|
-
throw new Error("CRM signal could not be verified after review.");
|
|
29
|
-
return saved;
|
|
30
|
-
},
|
|
31
|
-
});
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { defineAction, type ActionRunContext } from "@agent-native/core/action";
|
|
2
|
-
import { runDataProgram } from "@agent-native/core/data-programs";
|
|
3
|
-
import { accessFilter } from "@agent-native/core/sharing";
|
|
4
|
-
import { and, eq } from "drizzle-orm";
|
|
5
|
-
import { z } from "zod";
|
|
6
|
-
|
|
7
|
-
import { getDb, schema } from "../server/db/index.js";
|
|
8
|
-
import { CRM_APP_ID } from "../server/lib/provider-api.js";
|
|
9
|
-
import { isSafeCrmMutationFields } from "./_crm-action-utils.js";
|
|
10
|
-
|
|
11
|
-
export default defineAction({
|
|
12
|
-
description:
|
|
13
|
-
"Run the data program linked to one access-scoped CRM saved view and return a bounded, sanitized preview.",
|
|
14
|
-
schema: z.object({
|
|
15
|
-
viewId: z.string().trim().min(1).max(128),
|
|
16
|
-
}),
|
|
17
|
-
agentTool: false,
|
|
18
|
-
toolCallable: false,
|
|
19
|
-
run: async ({ viewId }, ctx?: ActionRunContext) => {
|
|
20
|
-
if (!ctx?.userEmail) {
|
|
21
|
-
throw new Error("CRM data programs require an authenticated user.");
|
|
22
|
-
}
|
|
23
|
-
const [view] = await getDb()
|
|
24
|
-
.select({ dataProgramId: schema.crmSavedViews.dataProgramId })
|
|
25
|
-
.from(schema.crmSavedViews)
|
|
26
|
-
.where(
|
|
27
|
-
and(
|
|
28
|
-
eq(schema.crmSavedViews.id, viewId),
|
|
29
|
-
accessFilter(schema.crmSavedViews, schema.crmSavedViewShares),
|
|
30
|
-
),
|
|
31
|
-
)
|
|
32
|
-
.limit(1);
|
|
33
|
-
if (!view?.dataProgramId) {
|
|
34
|
-
throw new Error("This CRM saved view has no data program.");
|
|
35
|
-
}
|
|
36
|
-
const result = await runDataProgram({
|
|
37
|
-
programId: view.dataProgramId,
|
|
38
|
-
appId: CRM_APP_ID,
|
|
39
|
-
params: {},
|
|
40
|
-
ctx: { userEmail: ctx.userEmail, orgId: ctx.orgId ?? null },
|
|
41
|
-
triggeredBy: "agent",
|
|
42
|
-
});
|
|
43
|
-
if (!result.ok) {
|
|
44
|
-
return {
|
|
45
|
-
ok: false as const,
|
|
46
|
-
code: result.error.code,
|
|
47
|
-
message: "The saved view data program could not run.",
|
|
48
|
-
...(result.lastGoodRun
|
|
49
|
-
? {
|
|
50
|
-
lastGoodRun: {
|
|
51
|
-
rowCount: result.lastGoodRun.rows.length,
|
|
52
|
-
columns: safeColumns(result.lastGoodRun.schema),
|
|
53
|
-
sampleRows: safeSampleRows(result.lastGoodRun.rows),
|
|
54
|
-
truncated: result.lastGoodRun.truncated,
|
|
55
|
-
asOfMs: result.lastGoodRun.asOfMs,
|
|
56
|
-
},
|
|
57
|
-
}
|
|
58
|
-
: {}),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
ok: true as const,
|
|
63
|
-
rowCount: result.rows.length,
|
|
64
|
-
columns: safeColumns(result.schema),
|
|
65
|
-
sampleRows: safeSampleRows(result.rows),
|
|
66
|
-
asOfMs: result.asOfMs,
|
|
67
|
-
cacheHit: result.cacheHit,
|
|
68
|
-
stale: result.stale,
|
|
69
|
-
truncated: result.truncated,
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
function safeColumns(columns: Array<{ name: string; type: string }>) {
|
|
75
|
-
return columns
|
|
76
|
-
.filter(
|
|
77
|
-
(column) =>
|
|
78
|
-
column.name.length <= 120 &&
|
|
79
|
-
isSafeCrmMutationFields({ [column.name]: "preview" }),
|
|
80
|
-
)
|
|
81
|
-
.slice(0, 12);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function safeSampleRows(rows: Array<Record<string, unknown>>) {
|
|
85
|
-
return rows.slice(0, 5).map((row) =>
|
|
86
|
-
Object.fromEntries(
|
|
87
|
-
Object.entries(row)
|
|
88
|
-
.filter(
|
|
89
|
-
([fieldName, value]) =>
|
|
90
|
-
isSafeCrmMutationFields({ [fieldName]: value }) &&
|
|
91
|
-
(value === null ||
|
|
92
|
-
typeof value === "string" ||
|
|
93
|
-
typeof value === "number" ||
|
|
94
|
-
typeof value === "boolean"),
|
|
95
|
-
)
|
|
96
|
-
.slice(0, 12)
|
|
97
|
-
.map(([fieldName, value]) => [
|
|
98
|
-
fieldName,
|
|
99
|
-
typeof value === "string" ? value.slice(0, 500) : value,
|
|
100
|
-
]),
|
|
101
|
-
),
|
|
102
|
-
);
|
|
103
|
-
}
|