@agent-native/core 0.122.4 → 0.123.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/corpus/README.md +2 -2
- package/corpus/core/CHANGELOG.md +538 -0
- package/corpus/core/docs/content/actions.mdx +33 -20
- package/corpus/core/docs/content/agent-mentions.mdx +30 -19
- package/corpus/core/docs/content/agent-native-toolkit.mdx +8 -6
- package/corpus/core/docs/content/agent-resources.mdx +11 -0
- package/corpus/core/docs/content/agent-surfaces.mdx +41 -30
- package/corpus/core/docs/content/audit-log.mdx +78 -0
- package/corpus/core/docs/content/authentication.mdx +7 -5
- package/corpus/core/docs/content/automations.mdx +15 -9
- package/corpus/core/docs/content/client.mdx +11 -11
- package/corpus/core/docs/content/cloneable-saas.mdx +7 -1
- package/corpus/core/docs/content/code-agents-ui.mdx +9 -1
- package/corpus/core/docs/content/components.mdx +7 -0
- package/corpus/core/docs/content/context-awareness.mdx +1 -0
- package/corpus/core/docs/content/creating-templates.mdx +9 -1
- package/corpus/core/docs/content/custom-design-system.mdx +8 -0
- package/corpus/core/docs/content/data-programs.mdx +6 -0
- package/corpus/core/docs/content/deployment.mdx +2 -0
- package/corpus/core/docs/content/doctor.mdx +5 -3
- package/corpus/core/docs/content/extensions.mdx +26 -0
- package/corpus/core/docs/content/external-agents-catalog.mdx +533 -0
- package/corpus/core/docs/content/external-agents.mdx +20 -514
- package/corpus/core/docs/content/faq.mdx +2 -2
- package/corpus/core/docs/content/file-uploads.mdx +44 -0
- package/corpus/core/docs/content/frames.mdx +2 -2
- package/corpus/core/docs/content/generative-ui.mdx +8 -0
- package/corpus/core/docs/content/getting-started.mdx +45 -17
- package/corpus/core/docs/content/human-approval.mdx +9 -0
- package/corpus/core/docs/content/integrations.mdx +4 -3
- package/corpus/core/docs/content/internationalization.mdx +4 -11
- package/corpus/core/docs/content/key-concepts.mdx +1 -1
- package/corpus/core/docs/content/local-file-mode.mdx +5 -0
- package/corpus/core/docs/content/mcp-apps.mdx +2 -1
- package/corpus/core/docs/content/mcp-clients.mdx +32 -1
- package/corpus/core/docs/content/mcp-protocol.mdx +4 -3
- package/corpus/core/docs/content/messaging-internals.mdx +328 -0
- package/corpus/core/docs/content/messaging-recipes.mdx +194 -0
- package/corpus/core/docs/content/messaging.mdx +9 -307
- package/corpus/core/docs/content/multi-app-workspace.mdx +1 -1
- package/corpus/core/docs/content/multi-tenancy.mdx +1 -0
- package/corpus/core/docs/content/native-chat-ui.mdx +8 -0
- package/corpus/core/docs/content/notifications.mdx +18 -20
- package/corpus/core/docs/content/observability.mdx +1 -0
- package/corpus/core/docs/content/onboarding.mdx +20 -6
- package/corpus/core/docs/content/organizations-teams-permissions.mdx +99 -124
- package/corpus/core/docs/content/package-lifecycle.mdx +19 -7
- package/corpus/core/docs/content/progress.mdx +11 -0
- package/corpus/core/docs/content/real-time-collaboration.mdx +44 -3
- package/corpus/core/docs/content/recurring-jobs.mdx +14 -1
- package/corpus/core/docs/content/security.mdx +5 -2
- package/corpus/core/docs/content/server.mdx +2 -1
- package/corpus/core/docs/content/sharing.mdx +22 -3
- package/corpus/core/docs/content/skills-guide.mdx +62 -19
- package/corpus/core/docs/content/syncing-template-changes.mdx +9 -0
- package/corpus/core/docs/content/template-analytics-connectors.mdx +75 -0
- package/corpus/core/docs/content/template-analytics-dashboards.mdx +106 -0
- package/corpus/core/docs/content/template-analytics-developers.mdx +287 -0
- package/corpus/core/docs/content/template-analytics-monitoring-and-sessions.mdx +109 -0
- package/corpus/core/docs/content/template-analytics.mdx +21 -263
- package/corpus/core/docs/content/template-assets-developers.mdx +456 -0
- package/corpus/core/docs/content/template-assets-generation.mdx +147 -0
- package/corpus/core/docs/content/template-assets-integrations.mdx +319 -0
- package/corpus/core/docs/content/template-assets-presets.mdx +185 -0
- package/corpus/core/docs/content/template-assets.mdx +12 -562
- package/corpus/core/docs/content/template-brain-agent.mdx +103 -0
- package/corpus/core/docs/content/template-brain-developers.mdx +379 -0
- package/corpus/core/docs/content/template-brain-knowledge.mdx +50 -0
- package/corpus/core/docs/content/template-brain-sources.mdx +163 -0
- package/corpus/core/docs/content/template-brain.mdx +30 -390
- package/corpus/core/docs/content/template-calendar-agent.mdx +133 -0
- package/corpus/core/docs/content/template-calendar-booking-links.mdx +73 -0
- package/corpus/core/docs/content/template-calendar-developers.mdx +366 -0
- package/corpus/core/docs/content/template-calendar-scheduling.mdx +128 -0
- package/corpus/core/docs/content/template-calendar.mdx +13 -260
- package/corpus/core/docs/content/template-chat-developers.mdx +88 -0
- package/corpus/core/docs/content/template-chat-first-edits.mdx +145 -0
- package/corpus/core/docs/content/template-chat.mdx +12 -77
- package/corpus/core/docs/content/template-clips-ai-and-editing.mdx +114 -0
- package/corpus/core/docs/content/template-clips-capture-everywhere.mdx +120 -0
- package/corpus/core/docs/content/template-clips-developers.mdx +373 -0
- package/corpus/core/docs/content/template-clips-sharing-and-teams.mdx +182 -0
- package/corpus/core/docs/content/template-clips.mdx +19 -508
- package/corpus/core/docs/content/template-content-databases.mdx +406 -0
- package/corpus/core/docs/content/template-content-developers.mdx +364 -0
- package/corpus/core/docs/content/template-content-editing.mdx +60 -0
- package/corpus/core/docs/content/template-content-sync.mdx +149 -0
- package/corpus/core/docs/content/template-content.mdx +21 -561
- package/corpus/core/docs/content/template-design-brand-and-figma.mdx +150 -0
- package/corpus/core/docs/content/template-design-collaboration-and-full-apps.mdx +125 -0
- package/corpus/core/docs/content/template-design-developers.mdx +358 -0
- package/corpus/core/docs/content/template-design-quality-and-components.mdx +95 -0
- package/corpus/core/docs/content/template-design.mdx +20 -344
- package/corpus/core/docs/content/template-dispatch-developers.mdx +121 -0
- package/corpus/core/docs/content/template-dispatch-messaging-routing.mdx +114 -0
- package/corpus/core/docs/content/template-dispatch-operations.mdx +160 -0
- package/corpus/core/docs/content/template-dispatch-vault-integrations.mdx +316 -0
- package/corpus/core/docs/content/template-dispatch.mdx +24 -283
- package/corpus/core/docs/content/template-forms-building-publishing.mdx +135 -0
- package/corpus/core/docs/content/template-forms-developers.mdx +195 -0
- package/corpus/core/docs/content/template-forms-responses.mdx +120 -0
- package/corpus/core/docs/content/template-forms.mdx +21 -230
- package/corpus/core/docs/content/template-mail-agent.mdx +114 -0
- package/corpus/core/docs/content/template-mail-developers.mdx +356 -0
- package/corpus/core/docs/content/template-mail-drafts-and-queue.mdx +103 -0
- package/corpus/core/docs/content/template-mail-inbox.mdx +118 -0
- package/corpus/core/docs/content/template-mail.mdx +23 -274
- package/corpus/core/docs/content/template-plan-automations.mdx +213 -0
- package/corpus/core/docs/content/template-plan-developers.mdx +703 -0
- package/corpus/core/docs/content/template-plan-local-and-desktop.mdx +236 -0
- package/corpus/core/docs/content/template-plan-review-workflow.mdx +180 -0
- package/corpus/core/docs/content/template-plan.mdx +60 -910
- package/corpus/core/docs/content/template-slides-agent.mdx +102 -0
- package/corpus/core/docs/content/template-slides-design-and-media.mdx +94 -0
- package/corpus/core/docs/content/template-slides-developers.mdx +488 -0
- package/corpus/core/docs/content/template-slides-editing.mdx +56 -0
- package/corpus/core/docs/content/template-slides.mdx +20 -362
- package/corpus/core/docs/content/toolkit-capability-packages.mdx +38 -13
- package/corpus/core/docs/content/toolkit-context-knowledge.mdx +49 -9
- package/corpus/core/docs/content/toolkit-editors-canvases.mdx +72 -10
- package/corpus/core/docs/content/toolkit-resources.mdx +16 -0
- package/corpus/core/docs/content/toolkit-settings.mdx +3 -3
- package/corpus/core/docs/content/toolkit-sharing.mdx +5 -7
- package/corpus/core/docs/content/using-your-agent.mdx +25 -2
- package/corpus/core/docs/content/voice-input.mdx +11 -7
- package/corpus/core/docs/content/what-is-agent-native.mdx +1 -0
- package/corpus/core/docs/content/workspace-connections.mdx +21 -11
- package/corpus/core/docs/content/workspace-management.mdx +1 -1
- package/corpus/core/package.json +1 -3
- package/corpus/core/src/a2a/client.ts +4 -2
- package/corpus/core/src/agent/action-warnings.ts +103 -0
- package/corpus/core/src/agent/durable-background.ts +42 -5
- package/corpus/core/src/agent/engine/ai-sdk-engine.ts +58 -6
- package/corpus/core/src/agent/engine/anthropic-engine.ts +51 -8
- package/corpus/core/src/agent/engine/builder-engine.ts +56 -18
- package/corpus/core/src/agent/engine/continuation-dispatch-retry.ts +10 -9
- package/corpus/core/src/agent/engine/credential-errors.ts +11 -0
- package/corpus/core/src/agent/engine/error-detail.ts +39 -0
- package/corpus/core/src/agent/engine/prompt-cache.ts +44 -0
- package/corpus/core/src/agent/engine/registry.ts +22 -30
- package/corpus/core/src/agent/engine/tool-call-journal-seed.ts +2 -1
- package/corpus/core/src/agent/engine/translate-anthropic.ts +99 -0
- package/corpus/core/src/agent/loop-settings.ts +94 -7
- package/corpus/core/src/agent/production-agent.ts +667 -157
- package/corpus/core/src/agent/run-loop-with-resume.ts +27 -1
- package/corpus/core/src/agent/run-manager.ts +229 -39
- package/corpus/core/src/agent/run-store.ts +397 -64
- package/corpus/core/src/agent/thread-data-builder.ts +5 -1
- package/corpus/core/src/agent/types.ts +23 -6
- package/corpus/core/src/application-state/script-helpers.ts +5 -2
- package/corpus/core/src/cli/agents.ts +69 -1
- package/corpus/core/src/cli/app-skill.ts +1 -1
- package/corpus/core/src/cli/code-agent-executor.ts +7 -3
- package/corpus/core/src/cli/design-connect.ts +82 -8
- package/corpus/core/src/cli/skills-content/design-visual-edit-skill.ts +169 -24
- package/corpus/core/src/client/AssistantChat.tsx +623 -607
- package/corpus/core/src/client/agent-chat-adapter.ts +176 -29
- package/corpus/core/src/client/chat/message-components.tsx +13 -0
- package/corpus/core/src/client/embed-auth.ts +3 -1
- package/corpus/core/src/client/integrations/IntegrationCard.tsx +41 -24
- package/corpus/core/src/client/integrations/IntegrationsPanel.tsx +37 -21
- package/corpus/core/src/client/integrations/webhook-url.ts +29 -0
- package/corpus/core/src/client/org/OrgSwitcher.tsx +41 -27
- package/corpus/core/src/client/org/RequireActiveOrg.tsx +7 -0
- package/corpus/core/src/client/org/TeamPage.tsx +144 -14
- package/corpus/core/src/client/org/hooks.ts +27 -0
- package/corpus/core/src/client/org/index.ts +2 -0
- package/corpus/core/src/client/require-session.tsx +40 -29
- package/corpus/core/src/client/session-replay.ts +1 -1
- package/corpus/core/src/client/settings/DemoModeSection.tsx +0 -5
- package/corpus/core/src/client/settings/SecretsSection.tsx +47 -42
- package/corpus/core/src/client/settings/VoiceTranscriptionSection.tsx +0 -5
- package/corpus/core/src/client/sse-event-processor.ts +83 -8
- package/corpus/core/src/client/use-action.ts +22 -13
- package/corpus/core/src/client/use-agent-engine-configured.ts +36 -4
- package/corpus/core/src/client/use-db-sync.ts +21 -1
- package/corpus/core/src/credentials/index.ts +124 -2
- package/corpus/core/src/deploy/build.ts +93 -30
- package/corpus/core/src/deploy/workspace-deploy.ts +21 -16
- package/corpus/core/src/guards/no-localhost-fallback.ts +76 -14
- package/corpus/core/src/integrations/google-docs-poller.ts +19 -12
- package/corpus/core/src/integrations/webhook-handler.ts +56 -33
- package/corpus/core/src/jobs/scheduler.ts +57 -23
- package/corpus/core/src/localization/default-messages.ts +23 -1
- package/corpus/core/src/observability/evals.ts +7 -8
- package/corpus/core/src/observability/traces.ts +2 -0
- package/corpus/core/src/org/accept-pending.ts +2 -2
- package/corpus/core/src/org/active-org.ts +73 -0
- package/corpus/core/src/org/auto-join-domain.ts +7 -2
- package/corpus/core/src/org/context.ts +169 -66
- package/corpus/core/src/org/handlers.ts +148 -10
- package/corpus/core/src/org/plugin.ts +8 -1
- package/corpus/core/src/org/types.ts +6 -1
- package/corpus/core/src/provider-api/index.ts +6 -1
- package/corpus/core/src/resources/handlers.ts +2 -6
- package/corpus/core/src/resources/script-helpers.ts +2 -1
- package/corpus/core/src/scripts/chat/search-chats.ts +5 -2
- package/corpus/core/src/scripts/describe-workspace-apps.ts +59 -0
- package/corpus/core/src/scripts/resources/delete-memory.ts +5 -2
- package/corpus/core/src/scripts/resources/delete.ts +5 -2
- package/corpus/core/src/scripts/resources/effective.ts +5 -2
- package/corpus/core/src/scripts/resources/list.ts +5 -2
- package/corpus/core/src/scripts/resources/read.ts +5 -2
- package/corpus/core/src/scripts/resources/save-memory.ts +5 -2
- package/corpus/core/src/scripts/resources/write.ts +5 -2
- package/corpus/core/src/server/agent-capabilities.ts +147 -0
- package/corpus/core/src/server/agent-chat/framework-prompts.ts +11 -13
- package/corpus/core/src/server/agent-chat/prompt-resources.ts +183 -57
- package/corpus/core/src/server/agent-chat/script-entries.ts +20 -7
- package/corpus/core/src/server/agent-chat-plugin.ts +27 -0
- package/corpus/core/src/server/auth.ts +38 -32
- package/corpus/core/src/server/core-routes-plugin.ts +229 -179
- package/corpus/core/src/server/credential-provider.ts +196 -44
- package/corpus/core/src/server/embed-session.ts +10 -0
- package/corpus/core/src/server/framework-request-handler.ts +43 -0
- package/corpus/core/src/server/google-auth-plugin.ts +13 -450
- package/corpus/core/src/server/index.ts +4 -1
- package/corpus/core/src/server/onboarding-html.ts +20 -56
- package/corpus/core/src/server/open-route.ts +6 -1
- package/corpus/core/src/server/poll.ts +1 -1
- package/corpus/core/src/server/prompts/framework-core-compact.ts +5 -5
- package/corpus/core/src/server/prompts/framework-core.ts +7 -9
- package/corpus/core/src/server/prompts/shared-rules.ts +20 -9
- package/corpus/core/src/server/request-context.ts +58 -2
- package/corpus/core/src/server/scoped-key-storage.ts +1 -1
- package/corpus/core/src/settings/org-settings.ts +9 -0
- package/corpus/core/src/settings/store.ts +29 -0
- package/corpus/core/src/shared/index.ts +13 -0
- package/corpus/core/src/shared/sign-in-journey.ts +331 -0
- package/corpus/core/src/styles/agent-native.css +8 -0
- package/corpus/core/src/templates/chat/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/core/src/templates/chat/.agents/skills/adding-a-feature/SKILL.md +2 -0
- package/corpus/core/src/templates/chat/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/core/src/templates/chat/.agents/skills/security/SKILL.md +2 -0
- package/corpus/core/src/templates/chat/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/core/src/templates/chat/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/core/src/templates/chat/AGENTS.md +8 -0
- package/corpus/core/src/templates/chat/app/entry.client.tsx +3 -0
- package/corpus/core/src/templates/chat/changelog/2026-07-24-borderless-secondary-surfaces.md +6 -0
- package/corpus/core/src/templates/chat/changelog/2026-07-24-sidebar-footer-controls-follow-a-consistent-order.md +6 -0
- package/corpus/core/src/templates/chat/changelog/2026-07-25-settings-navigation-now-keeps-manage-agent-as-a-dedicated-li.md +6 -0
- package/corpus/core/src/templates/default/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/core/src/templates/default/.agents/skills/adding-a-feature/SKILL.md +2 -0
- package/corpus/core/src/templates/default/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/core/src/templates/default/.agents/skills/security/SKILL.md +2 -0
- package/corpus/core/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/core/src/templates/default/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/core/src/templates/default/AGENTS.md +68 -195
- package/corpus/core/src/templates/default/app/entry.client.tsx +3 -0
- package/corpus/core/src/templates/default/app/i18n/ar-SA.ts +8 -0
- package/corpus/core/src/templates/default/app/i18n/de-DE.ts +8 -0
- package/corpus/core/src/templates/default/app/i18n/en-US.ts +8 -0
- package/corpus/core/src/templates/default/app/i18n/es-ES.ts +8 -0
- package/corpus/core/src/templates/default/app/i18n/fr-FR.ts +8 -0
- package/corpus/core/src/templates/default/app/i18n/hi-IN.ts +8 -0
- package/corpus/core/src/templates/default/app/i18n/ja-JP.ts +8 -0
- package/corpus/core/src/templates/default/app/i18n/ko-KR.ts +8 -0
- package/corpus/core/src/templates/default/app/i18n/pt-BR.ts +8 -0
- package/corpus/core/src/templates/default/app/i18n/zh-CN.ts +8 -0
- package/corpus/core/src/templates/default/app/i18n/zh-TW.ts +8 -0
- package/corpus/core/src/templates/headless/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/core/src/templates/workspace-core/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/core/src/templates/workspace-core/.agents/skills/adding-a-feature/SKILL.md +2 -0
- package/corpus/core/src/templates/workspace-core/.agents/skills/adding-workspace-apps/SKILL.md +100 -0
- package/corpus/core/src/templates/workspace-core/.agents/skills/address-feedback/SKILL.md +2 -1
- package/corpus/core/src/templates/workspace-core/.agents/skills/authentication/SKILL.md +28 -0
- package/corpus/core/src/templates/workspace-core/.agents/skills/composable-mini-apps/SKILL.md +14 -1
- package/corpus/core/src/templates/workspace-core/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/core/src/templates/workspace-core/.agents/skills/qa/SKILL.md +6 -3
- package/corpus/core/src/templates/workspace-core/.agents/skills/security/SKILL.md +2 -0
- package/corpus/core/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/core/src/templates/workspace-core/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/core/src/templates/workspace-core/.agents/skills/workspace-conventions/SKILL.md +91 -0
- package/corpus/core/src/templates/workspace-core/.agents/skills/writing-agent-instructions/SKILL.md +60 -0
- package/corpus/core/src/templates/workspace-core/AGENTS.md +62 -124
- package/corpus/core/src/templates/workspace-root/AGENTS.md +6 -1
- package/corpus/core/src/triggers/dispatcher.ts +28 -17
- package/corpus/core/src/vite/client.ts +20 -8
- package/corpus/templates/analytics/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/templates/analytics/.agents/skills/dashboard-management/SKILL.md +41 -1
- package/corpus/templates/analytics/.agents/skills/dashboard-ops/SKILL.md +50 -22
- package/corpus/templates/analytics/.agents/skills/data-querying/SKILL.md +1 -1
- package/corpus/templates/analytics/.agents/skills/data-querying/references/inline-chart-embeds.md +8 -0
- package/corpus/templates/analytics/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/templates/analytics/.agents/skills/security/SKILL.md +2 -0
- package/corpus/templates/analytics/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/templates/analytics/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/templates/analytics/.agents/skills/sharing/SKILL.md +228 -0
- package/corpus/templates/analytics/.builder/skills/charts/SKILL.md +2 -2
- package/corpus/templates/analytics/actions/delete-dashboard-view.ts +24 -0
- package/corpus/templates/analytics/actions/delete-user-pref.ts +22 -0
- package/corpus/templates/analytics/actions/generate-chart.ts +8 -245
- package/corpus/templates/analytics/actions/get-theme.ts +27 -0
- package/corpus/templates/analytics/actions/get-user-pref.ts +22 -0
- package/corpus/templates/analytics/actions/list-dashboard-views.ts +25 -0
- package/corpus/templates/analytics/actions/save-dashboard-view.ts +33 -0
- package/corpus/templates/analytics/actions/set-theme.ts +22 -0
- package/corpus/templates/analytics/actions/set-user-pref.ts +24 -0
- package/corpus/templates/analytics/app/components/dashboard/SqlChart.tsx +134 -27
- package/corpus/templates/analytics/app/components/layout/CommandPalette.tsx +2 -9
- package/corpus/templates/analytics/app/components/layout/Layout.tsx +0 -17
- package/corpus/templates/analytics/app/components/layout/Sidebar.tsx +10 -5
- package/corpus/templates/analytics/app/hooks/use-dashboard-views.ts +22 -52
- package/corpus/templates/analytics/app/hooks/use-user-pref.ts +21 -31
- package/corpus/templates/analytics/app/i18n-data.ts +10 -0
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/PanelEditorDialog.tsx +2 -1
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/dual-axis.ts +73 -0
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/index.tsx +8 -27
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/report-panel-window.ts +0 -57
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/types.ts +8 -0
- package/corpus/templates/analytics/app/root.tsx +0 -28
- package/corpus/templates/analytics/changelog/2026-07-26-error-issues-now-group-by-message-as-well-as-stack-frame-and.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-26-line-area-and-bar-dashboard-panels-can-plot-series-on-a-seco.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-26-scheduled-dashboard-email-reports-now-arrive-complete-and-re.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-26-session-replays-now-detect-rage-clicks-so-the-rage-click-fil.md +6 -0
- package/corpus/templates/analytics/docs/error-capture.md +8 -4
- package/corpus/templates/analytics/package.json +1 -2
- package/corpus/templates/analytics/scripts/preview-dashboard-report.ts +221 -0
- package/corpus/templates/analytics/server/jobs/dashboard-report.ts +39 -32
- package/corpus/templates/analytics/server/lib/dashboard-report-render.ts +1168 -0
- package/corpus/templates/analytics/server/lib/dashboard-report.ts +111 -1358
- package/corpus/templates/analytics/server/lib/error-capture.ts +32 -15
- package/corpus/templates/analytics/server/lib/report-chart-svg.ts +901 -0
- package/corpus/templates/analytics/server/lib/session-replay.ts +77 -1
- package/corpus/templates/analytics/shared/dashboard-report-timeouts.ts +3 -4
- package/corpus/templates/assets/.agents/skills/a2a-assets/SKILL.md +28 -0
- package/corpus/templates/assets/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/templates/assets/.agents/skills/assets-navigation/SKILL.md +46 -0
- package/corpus/templates/assets/.agents/skills/creative-context/SKILL.md +12 -0
- package/corpus/templates/assets/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/templates/assets/.agents/skills/image-generation/SKILL.md +28 -0
- package/corpus/templates/assets/.agents/skills/library-management/SKILL.md +9 -0
- package/corpus/templates/assets/.agents/skills/logo-composite/SKILL.md +11 -0
- package/corpus/templates/assets/.agents/skills/security/SKILL.md +2 -0
- package/corpus/templates/assets/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/templates/assets/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/templates/assets/.agents/skills/sharing/SKILL.md +228 -0
- package/corpus/templates/assets/AGENTS.md +58 -125
- package/corpus/templates/assets/actions/variant-slots.ts +8 -4
- package/corpus/templates/assets/app/entry.client.tsx +3 -0
- package/corpus/templates/assets/package.json +0 -2
- package/corpus/templates/brain/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/templates/brain/.agents/skills/adding-a-feature/SKILL.md +2 -0
- package/corpus/templates/brain/.agents/skills/brain/SKILL.md +78 -4
- package/corpus/templates/brain/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/templates/brain/.agents/skills/ingestion-and-connectors/SKILL.md +15 -3
- package/corpus/templates/brain/.agents/skills/security/SKILL.md +2 -0
- package/corpus/templates/brain/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/templates/brain/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/templates/brain/.agents/skills/sharing/SKILL.md +228 -0
- package/corpus/templates/brain/.agents/skills/storing-data/SKILL.md +178 -0
- package/corpus/templates/brain/AGENTS.md +73 -119
- package/corpus/templates/brain/app/entry.client.tsx +3 -0
- package/corpus/templates/calendar/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/templates/calendar/.agents/skills/event-management/SKILL.md +56 -3
- package/corpus/templates/calendar/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/templates/calendar/.agents/skills/security/SKILL.md +2 -0
- package/corpus/templates/calendar/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/templates/calendar/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/templates/calendar/.agents/skills/sharing/SKILL.md +228 -0
- package/corpus/templates/calendar/AGENTS.md +22 -45
- package/corpus/templates/calendar/app/entry.client.tsx +3 -0
- package/corpus/templates/calendar/server/handlers/events.ts +0 -364
- package/corpus/templates/chat/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/templates/chat/.agents/skills/adding-a-feature/SKILL.md +2 -0
- package/corpus/templates/chat/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/templates/chat/.agents/skills/security/SKILL.md +2 -0
- package/corpus/templates/chat/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/templates/chat/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/templates/chat/.agents/skills/sharing/SKILL.md +228 -0
- package/corpus/templates/chat/.agents/skills/storing-data/SKILL.md +178 -0
- package/corpus/templates/chat/AGENTS.md +8 -0
- package/corpus/templates/chat/app/entry.client.tsx +3 -0
- package/corpus/templates/clips/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/templates/clips/.agents/skills/ai-video-tools/SKILL.md +42 -0
- package/corpus/templates/clips/.agents/skills/brain-export/SKILL.md +59 -0
- package/corpus/templates/clips/.agents/skills/bug-reports/SKILL.md +37 -0
- package/corpus/templates/clips/.agents/skills/crm-call-evidence/SKILL.md +41 -0
- package/corpus/templates/clips/.agents/skills/dictate/SKILL.md +4 -0
- package/corpus/templates/clips/.agents/skills/external-integrations/SKILL.md +45 -0
- package/corpus/templates/clips/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/templates/clips/.agents/skills/meetings/SKILL.md +9 -0
- package/corpus/templates/clips/.agents/skills/recording/SKILL.md +45 -0
- package/corpus/templates/clips/.agents/skills/screen-memory/SKILL.md +43 -0
- package/corpus/templates/clips/.agents/skills/security/SKILL.md +2 -0
- package/corpus/templates/clips/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/templates/clips/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/templates/clips/.agents/skills/video-sharing/SKILL.md +38 -1
- package/corpus/templates/clips/AGENTS.md +82 -224
- package/corpus/templates/clips/actions/create-recording.ts +4 -0
- package/corpus/templates/clips/app/components/player/sign-in-prompt-dialog.tsx +6 -10
- package/corpus/templates/clips/app/routes/invite.$token.tsx +6 -5
- package/corpus/templates/clips/app/routes/r.$recordingId.tsx +4 -5
- package/corpus/templates/clips/app/routes/share.$shareId.tsx +8 -8
- package/corpus/templates/clips/changelog/2026-07-26-long-agent-chat-turns-now-finish-instead-of-stopping-partway.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-26-recordings-no-longer-get-stuck-on-uploading-uploads-now-hold.md +6 -0
- package/corpus/templates/clips/server/db/schema.ts +3 -0
- package/corpus/templates/clips/server/jobs/brain-export.ts +4 -0
- package/corpus/templates/clips/server/lib/recording-upload-state.ts +0 -52
- package/corpus/templates/clips/server/lib/upload-lease.ts +241 -0
- package/corpus/templates/clips/server/plugins/agent-chat.ts +4 -0
- package/corpus/templates/clips/server/plugins/db.ts +18 -347
- package/corpus/templates/clips/server/routes/api/clips/brain-export/run.post.ts +7 -1
- package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/chunk.post.ts +123 -126
- package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/reset-chunks.post.ts +4 -0
- package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/resume.get.ts +118 -0
- package/corpus/templates/clips/server/routes/api/uploads/reap.post.ts +69 -0
- package/corpus/templates/content/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/templates/content/.agents/skills/content/SKILL.md +4 -0
- package/corpus/templates/content/.agents/skills/creative-context/SKILL.md +8 -0
- package/corpus/templates/content/.agents/skills/document-editing/SKILL.md +55 -0
- package/corpus/templates/content/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/templates/content/.agents/skills/notion-integration/SKILL.md +12 -1
- package/corpus/templates/content/.agents/skills/security/SKILL.md +2 -0
- package/corpus/templates/content/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/templates/content/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/templates/content/.agents/skills/sharing/SKILL.md +228 -0
- package/corpus/templates/content/AGENTS.md +63 -131
- package/corpus/templates/content/app/routes/_app.tsx +4 -4
- package/corpus/templates/content/server/routes/api/notion/callback.get.ts +6 -24
- package/corpus/templates/design/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/templates/design/.agents/skills/design-generation/SKILL.md +16 -0
- package/corpus/templates/design/.agents/skills/design-systems/SKILL.md +15 -0
- package/corpus/templates/design/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/templates/design/.agents/skills/full-app-build/SKILL.md +12 -0
- package/corpus/templates/design/.agents/skills/security/SKILL.md +2 -0
- package/corpus/templates/design/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/templates/design/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/templates/design/.agents/skills/sharing/SKILL.md +228 -0
- package/corpus/templates/design/.agents/skills/storing-data/SKILL.md +178 -0
- package/corpus/templates/design/.agents/skills/visual-edit/SKILL.md +201 -102
- package/corpus/templates/design/AGENTS.md +58 -71
- package/corpus/templates/design/actions/open-visual-edit.ts +111 -2
- package/corpus/templates/design/app/components/design/AddLocalhostScreenDialog.tsx +236 -0
- package/corpus/templates/design/app/components/design/DesignCanvas.tsx +1 -1
- package/corpus/templates/design/app/components/design/MultiScreenCanvas.tsx +2 -2
- package/corpus/templates/design/app/entry.client.tsx +3 -0
- package/corpus/templates/design/app/i18n-data.ts +180 -0
- package/corpus/templates/design/app/pages/Present.tsx +6 -9
- package/corpus/templates/design/app/pages/VisualEdit.tsx +4 -7
- package/corpus/templates/design/app/pages/design-editor/design-data-geometry-utils.ts +20 -0
- package/corpus/templates/dispatch/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/templates/dispatch/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/templates/dispatch/.agents/skills/security/SKILL.md +2 -0
- package/corpus/templates/dispatch/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/templates/dispatch/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/templates/dispatch/.agents/skills/sharing/SKILL.md +228 -0
- package/corpus/templates/dispatch/.agents/skills/storing-data/SKILL.md +178 -0
- package/corpus/templates/dispatch/app/entry.client.tsx +3 -0
- package/corpus/templates/dispatch/server/plugins/identity-sso.ts +27 -16
- package/corpus/templates/forms/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/templates/forms/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/templates/forms/.agents/skills/security/SKILL.md +2 -0
- package/corpus/templates/forms/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/templates/forms/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/templates/forms/.agents/skills/sharing/SKILL.md +228 -0
- package/corpus/templates/forms/DEVELOPING.md +1 -1
- package/corpus/templates/forms/app/entry.client.tsx +3 -0
- package/corpus/templates/forms/app/pages/FormsListPage.tsx +3 -5
- package/corpus/templates/forms/app/routes/_app.tsx +4 -4
- package/corpus/templates/macros/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/templates/macros/.agents/skills/security/SKILL.md +2 -0
- package/corpus/templates/macros/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/templates/macros/.agents/skills/sharing/SKILL.md +228 -0
- package/corpus/templates/macros/.agents/skills/storing-data/SKILL.md +178 -0
- package/corpus/templates/macros/app/entry.client.tsx +3 -0
- package/corpus/templates/mail/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/templates/mail/.agents/skills/contacts-and-crm/SKILL.md +10 -0
- package/corpus/templates/mail/.agents/skills/draft-queue/SKILL.md +3 -0
- package/corpus/templates/mail/.agents/skills/email-drafts/SKILL.md +26 -2
- package/corpus/templates/mail/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/templates/mail/.agents/skills/inbox-automations/SKILL.md +37 -0
- package/corpus/templates/mail/.agents/skills/inbox-reads-and-triage/SKILL.md +58 -0
- package/corpus/templates/mail/.agents/skills/mail-backends/SKILL.md +33 -0
- package/corpus/templates/mail/.agents/skills/provider-api-scans/SKILL.md +39 -0
- package/corpus/templates/mail/.agents/skills/security/SKILL.md +2 -0
- package/corpus/templates/mail/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/templates/mail/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/templates/mail/.agents/skills/sharing/SKILL.md +228 -0
- package/corpus/templates/mail/AGENTS.md +74 -143
- package/corpus/templates/mail/actions/create-alias.ts +36 -0
- package/corpus/templates/mail/actions/create-automation.ts +28 -0
- package/corpus/templates/mail/actions/create-scheduled-job.ts +45 -0
- package/corpus/templates/mail/actions/delete-alias.ts +26 -0
- package/corpus/templates/mail/actions/delete-automation.ts +21 -0
- package/corpus/templates/mail/actions/get-automation-settings.ts +32 -0
- package/corpus/templates/mail/actions/get-mail-preferences.ts +18 -0
- package/corpus/templates/mail/actions/list-aliases.ts +17 -0
- package/corpus/templates/mail/actions/list-automations.ts +18 -0
- package/corpus/templates/mail/actions/list-scheduled-jobs.ts +18 -0
- package/corpus/templates/mail/actions/update-alias.ts +37 -0
- package/corpus/templates/mail/actions/update-automation-settings.ts +33 -0
- package/corpus/templates/mail/actions/update-automation.ts +33 -0
- package/corpus/templates/mail/actions/update-mail-preferences.ts +68 -0
- package/corpus/templates/mail/actions/update-scheduled-job.ts +25 -0
- package/corpus/templates/mail/app/entry.client.tsx +3 -0
- package/corpus/templates/mail/app/hooks/use-aliases.ts +6 -36
- package/corpus/templates/mail/app/hooks/use-automations.ts +9 -16
- package/corpus/templates/mail/app/hooks/use-emails.ts +6 -5
- package/corpus/templates/mail/app/hooks/use-scheduled-jobs.ts +12 -15
- package/corpus/templates/mail/app/pages/SettingsPage.tsx +15 -9
- package/corpus/templates/mail/server/handlers/automations.ts +5 -142
- package/corpus/templates/mail/server/handlers/emails.ts +1 -56
- package/corpus/templates/mail/server/handlers/scheduled-jobs.ts +0 -134
- package/corpus/templates/mail/server/lib/aliases.ts +18 -0
- package/corpus/templates/mail/server/lib/automations.ts +104 -0
- package/corpus/templates/mail/server/lib/jobs.ts +34 -0
- package/corpus/templates/mail/server/lib/mail-settings.ts +43 -0
- package/corpus/templates/mail/shared/automation-schema.ts +10 -0
- package/corpus/templates/plan/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/templates/plan/.agents/skills/adding-a-feature/SKILL.md +2 -0
- package/corpus/templates/plan/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/templates/plan/.agents/skills/plan-authoring-flow/SKILL.md +98 -0
- package/corpus/templates/plan/.agents/skills/plan-browser-editing/SKILL.md +42 -0
- package/corpus/templates/plan/.agents/skills/plan-comments-and-feedback/SKILL.md +68 -0
- package/corpus/templates/plan/.agents/skills/plan-events/SKILL.md +22 -0
- package/corpus/templates/plan/.agents/skills/plan-hosted-writes/SKILL.md +42 -0
- package/corpus/templates/plan/.agents/skills/plan-local-codebase-chat/SKILL.md +38 -0
- package/corpus/templates/plan/.agents/skills/plan-review-recaps/SKILL.md +25 -0
- package/corpus/templates/plan/.agents/skills/plan-source-sync/SKILL.md +68 -0
- package/corpus/templates/plan/.agents/skills/plan-version-history/SKILL.md +25 -0
- package/corpus/templates/plan/.agents/skills/security/SKILL.md +2 -0
- package/corpus/templates/plan/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/templates/plan/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/templates/plan/.agents/skills/sharing/SKILL.md +228 -0
- package/corpus/templates/plan/.agents/skills/storing-data/SKILL.md +178 -0
- package/corpus/templates/plan/AGENTS.md +64 -296
- package/corpus/templates/plan/app/components/layout/Sidebar.tsx +9 -8
- package/corpus/templates/plan/app/pages/PlansPage.tsx +5 -10
- package/corpus/templates/slides/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/templates/slides/.agents/skills/deck-management/SKILL.md +7 -7
- package/corpus/templates/slides/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/templates/slides/.agents/skills/security/SKILL.md +2 -0
- package/corpus/templates/slides/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/templates/slides/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/templates/slides/.agents/skills/sharing/SKILL.md +228 -0
- package/corpus/templates/slides/.agents/skills/slide-editing/SKILL.md +3 -2
- package/corpus/templates/slides/.agents/skills/storing-data/SKILL.md +178 -0
- package/corpus/templates/slides/DEVELOPING.md +3 -3
- package/corpus/templates/slides/actions/_deck-write.ts +52 -0
- package/corpus/templates/slides/actions/add-deck.ts +73 -0
- package/corpus/templates/slides/actions/delete-deck.ts +60 -0
- package/corpus/templates/slides/actions/get-deck.ts +3 -1
- package/corpus/templates/slides/actions/save-deck.ts +144 -0
- package/corpus/templates/slides/app/components/editor/SlideEditor.tsx +27 -20
- package/corpus/templates/slides/app/context/DeckContext.tsx +173 -100
- package/corpus/templates/slides/app/pages/Index.tsx +3 -6
- package/corpus/templates/slides/app/routes/slide.tsx +16 -12
- package/corpus/templates/slides/changelog/2026-07-26-a-newly-created-deck-now-appears-in-the-deck-list-right-away.md +6 -0
- package/corpus/templates/slides/server/handlers/decks.ts +2 -378
- package/corpus/templates/tasks/.agents/skills/action-reference/SKILL.md +47 -0
- package/corpus/templates/tasks/.agents/skills/actions/SKILL.md +19 -1
- package/corpus/templates/tasks/.agents/skills/adding-a-feature/SKILL.md +2 -0
- package/corpus/templates/tasks/.agents/skills/change-summary/SKILL.md +19 -1
- package/corpus/templates/tasks/.agents/skills/custom-fields/SKILL.md +63 -0
- package/corpus/templates/tasks/.agents/skills/frontend-design/SKILL.md +20 -6
- package/corpus/templates/tasks/.agents/skills/security/SKILL.md +2 -0
- package/corpus/templates/tasks/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/corpus/templates/tasks/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/corpus/templates/tasks/.agents/skills/sharing/SKILL.md +228 -0
- package/corpus/templates/tasks/.agents/skills/store-conventions/SKILL.md +45 -0
- package/corpus/templates/tasks/.agents/skills/storing-data/SKILL.md +178 -0
- package/corpus/templates/tasks/.agents/skills/task-inbox-workflow/SKILL.md +66 -0
- package/corpus/templates/tasks/AGENTS.md +48 -113
- package/corpus/templates/tasks/app/entry.client.tsx +3 -0
- package/corpus/toolkit/CHANGELOG.md +12 -0
- package/corpus/toolkit/package.json +1 -1
- package/corpus/toolkit/src/composer/PromptComposer.tsx +23 -20
- package/dist/a2a/client.d.ts +3 -1
- package/dist/a2a/client.d.ts.map +1 -1
- package/dist/a2a/client.js +4 -2
- package/dist/a2a/client.js.map +1 -1
- package/dist/agent/action-warnings.d.ts +27 -0
- package/dist/agent/action-warnings.d.ts.map +1 -0
- package/dist/agent/action-warnings.js +73 -0
- package/dist/agent/action-warnings.js.map +1 -0
- package/dist/agent/durable-background.d.ts +8 -0
- package/dist/agent/durable-background.d.ts.map +1 -1
- package/dist/agent/durable-background.js +37 -5
- package/dist/agent/durable-background.js.map +1 -1
- package/dist/agent/engine/ai-sdk-engine.d.ts.map +1 -1
- package/dist/agent/engine/ai-sdk-engine.js +47 -6
- package/dist/agent/engine/ai-sdk-engine.js.map +1 -1
- package/dist/agent/engine/anthropic-engine.d.ts.map +1 -1
- package/dist/agent/engine/anthropic-engine.js +41 -9
- package/dist/agent/engine/anthropic-engine.js.map +1 -1
- package/dist/agent/engine/builder-engine.d.ts.map +1 -1
- package/dist/agent/engine/builder-engine.js +46 -19
- package/dist/agent/engine/builder-engine.js.map +1 -1
- package/dist/agent/engine/continuation-dispatch-retry.d.ts.map +1 -1
- package/dist/agent/engine/continuation-dispatch-retry.js +11 -9
- package/dist/agent/engine/continuation-dispatch-retry.js.map +1 -1
- package/dist/agent/engine/credential-errors.d.ts +6 -0
- package/dist/agent/engine/credential-errors.d.ts.map +1 -1
- package/dist/agent/engine/credential-errors.js +10 -0
- package/dist/agent/engine/credential-errors.js.map +1 -1
- package/dist/agent/engine/error-detail.d.ts +2 -0
- package/dist/agent/engine/error-detail.d.ts.map +1 -0
- package/dist/agent/engine/error-detail.js +37 -0
- package/dist/agent/engine/error-detail.js.map +1 -0
- package/dist/agent/engine/prompt-cache.d.ts +34 -0
- package/dist/agent/engine/prompt-cache.d.ts.map +1 -0
- package/dist/agent/engine/prompt-cache.js +39 -0
- package/dist/agent/engine/prompt-cache.js.map +1 -0
- package/dist/agent/engine/registry.d.ts.map +1 -1
- package/dist/agent/engine/registry.js +23 -33
- package/dist/agent/engine/registry.js.map +1 -1
- package/dist/agent/engine/tool-call-journal-seed.d.ts +1 -1
- package/dist/agent/engine/tool-call-journal-seed.d.ts.map +1 -1
- package/dist/agent/engine/tool-call-journal-seed.js +2 -2
- package/dist/agent/engine/tool-call-journal-seed.js.map +1 -1
- package/dist/agent/engine/translate-anthropic.d.ts +28 -0
- package/dist/agent/engine/translate-anthropic.d.ts.map +1 -1
- package/dist/agent/engine/translate-anthropic.js +75 -0
- package/dist/agent/engine/translate-anthropic.js.map +1 -1
- package/dist/agent/loop-settings.d.ts +35 -2
- package/dist/agent/loop-settings.d.ts.map +1 -1
- package/dist/agent/loop-settings.js +71 -8
- package/dist/agent/loop-settings.js.map +1 -1
- package/dist/agent/production-agent.d.ts +105 -20
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +516 -123
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/run-loop-with-resume.d.ts.map +1 -1
- package/dist/agent/run-loop-with-resume.js +24 -2
- package/dist/agent/run-loop-with-resume.js.map +1 -1
- package/dist/agent/run-manager.d.ts +52 -9
- package/dist/agent/run-manager.d.ts.map +1 -1
- package/dist/agent/run-manager.js +191 -36
- package/dist/agent/run-manager.js.map +1 -1
- package/dist/agent/run-store.d.ts +87 -14
- package/dist/agent/run-store.d.ts.map +1 -1
- package/dist/agent/run-store.js +331 -59
- package/dist/agent/run-store.js.map +1 -1
- package/dist/agent/thread-data-builder.d.ts.map +1 -1
- package/dist/agent/thread-data-builder.js +6 -1
- package/dist/agent/thread-data-builder.js.map +1 -1
- package/dist/agent/types.d.ts +18 -6
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js +9 -5
- package/dist/agent/types.js.map +1 -1
- package/dist/application-state/script-helpers.d.ts.map +1 -1
- package/dist/application-state/script-helpers.js +2 -2
- package/dist/application-state/script-helpers.js.map +1 -1
- package/dist/cli/agents.d.ts +2 -0
- package/dist/cli/agents.d.ts.map +1 -1
- package/dist/cli/agents.js +48 -1
- package/dist/cli/agents.js.map +1 -1
- package/dist/cli/app-skill.js +1 -1
- package/dist/cli/app-skill.js.map +1 -1
- package/dist/cli/code-agent-executor.d.ts.map +1 -1
- package/dist/cli/code-agent-executor.js +3 -3
- package/dist/cli/code-agent-executor.js.map +1 -1
- package/dist/cli/design-connect.d.ts.map +1 -1
- package/dist/cli/design-connect.js +73 -8
- package/dist/cli/design-connect.js.map +1 -1
- package/dist/cli/skills-content/design-visual-edit-skill.d.ts +1 -1
- package/dist/cli/skills-content/design-visual-edit-skill.d.ts.map +1 -1
- package/dist/cli/skills-content/design-visual-edit-skill.js +169 -24
- package/dist/cli/skills-content/design-visual-edit-skill.js.map +1 -1
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +135 -125
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts +17 -0
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +141 -31
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/chat/message-components.d.ts +9 -1
- package/dist/client/chat/message-components.d.ts.map +1 -1
- package/dist/client/chat/message-components.js +12 -1
- package/dist/client/chat/message-components.js.map +1 -1
- package/dist/client/embed-auth.d.ts.map +1 -1
- package/dist/client/embed-auth.js +3 -1
- package/dist/client/embed-auth.js.map +1 -1
- package/dist/client/integrations/IntegrationCard.d.ts.map +1 -1
- package/dist/client/integrations/IntegrationCard.js +9 -4
- package/dist/client/integrations/IntegrationCard.js.map +1 -1
- package/dist/client/integrations/IntegrationsPanel.d.ts.map +1 -1
- package/dist/client/integrations/IntegrationsPanel.js +13 -7
- package/dist/client/integrations/IntegrationsPanel.js.map +1 -1
- package/dist/client/integrations/webhook-url.d.ts +7 -0
- package/dist/client/integrations/webhook-url.d.ts.map +1 -0
- package/dist/client/integrations/webhook-url.js +32 -0
- package/dist/client/integrations/webhook-url.js.map +1 -0
- package/dist/client/org/OrgSwitcher.d.ts.map +1 -1
- package/dist/client/org/OrgSwitcher.js +13 -11
- package/dist/client/org/OrgSwitcher.js.map +1 -1
- package/dist/client/org/RequireActiveOrg.d.ts.map +1 -1
- package/dist/client/org/RequireActiveOrg.js +2 -2
- package/dist/client/org/RequireActiveOrg.js.map +1 -1
- package/dist/client/org/TeamPage.d.ts.map +1 -1
- package/dist/client/org/TeamPage.js +52 -13
- package/dist/client/org/TeamPage.js.map +1 -1
- package/dist/client/org/hooks.d.ts +9 -0
- package/dist/client/org/hooks.d.ts.map +1 -1
- package/dist/client/org/hooks.js +24 -0
- package/dist/client/org/hooks.js.map +1 -1
- package/dist/client/org/index.d.ts +1 -1
- package/dist/client/org/index.d.ts.map +1 -1
- package/dist/client/org/index.js +1 -1
- package/dist/client/org/index.js.map +1 -1
- package/dist/client/require-session.d.ts +12 -17
- package/dist/client/require-session.d.ts.map +1 -1
- package/dist/client/require-session.js +36 -23
- package/dist/client/require-session.js.map +1 -1
- package/dist/client/session-replay.js +1 -1
- package/dist/client/session-replay.js.map +1 -1
- package/dist/client/settings/DemoModeSection.d.ts +0 -1
- package/dist/client/settings/DemoModeSection.d.ts.map +1 -1
- package/dist/client/settings/DemoModeSection.js +0 -4
- package/dist/client/settings/DemoModeSection.js.map +1 -1
- package/dist/client/settings/SecretsSection.d.ts.map +1 -1
- package/dist/client/settings/SecretsSection.js +12 -8
- package/dist/client/settings/SecretsSection.js.map +1 -1
- package/dist/client/settings/VoiceTranscriptionSection.d.ts +0 -1
- package/dist/client/settings/VoiceTranscriptionSection.d.ts.map +1 -1
- package/dist/client/settings/VoiceTranscriptionSection.js +1 -4
- package/dist/client/settings/VoiceTranscriptionSection.js.map +1 -1
- package/dist/client/sse-event-processor.d.ts +33 -1
- package/dist/client/sse-event-processor.d.ts.map +1 -1
- package/dist/client/sse-event-processor.js +83 -8
- package/dist/client/sse-event-processor.js.map +1 -1
- package/dist/client/use-action.d.ts.map +1 -1
- package/dist/client/use-action.js +23 -14
- package/dist/client/use-action.js.map +1 -1
- package/dist/client/use-agent-engine-configured.d.ts +9 -3
- package/dist/client/use-agent-engine-configured.d.ts.map +1 -1
- package/dist/client/use-agent-engine-configured.js +30 -3
- package/dist/client/use-agent-engine-configured.js.map +1 -1
- package/dist/client/use-db-sync.d.ts +3 -0
- package/dist/client/use-db-sync.d.ts.map +1 -1
- package/dist/client/use-db-sync.js +18 -1
- package/dist/client/use-db-sync.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/credentials/index.d.ts +29 -1
- package/dist/credentials/index.d.ts.map +1 -1
- package/dist/credentials/index.js +111 -2
- package/dist/credentials/index.js.map +1 -1
- package/dist/deploy/build.d.ts +14 -3
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +81 -24
- package/dist/deploy/build.js.map +1 -1
- package/dist/deploy/workspace-deploy.d.ts +15 -0
- package/dist/deploy/workspace-deploy.d.ts.map +1 -1
- package/dist/deploy/workspace-deploy.js +19 -18
- package/dist/deploy/workspace-deploy.js.map +1 -1
- package/dist/file-upload/actions/upload-image.d.ts +2 -2
- package/dist/guards/no-localhost-fallback.d.ts +7 -0
- package/dist/guards/no-localhost-fallback.d.ts.map +1 -1
- package/dist/guards/no-localhost-fallback.js +75 -16
- package/dist/guards/no-localhost-fallback.js.map +1 -1
- package/dist/integrations/google-docs-poller.d.ts.map +1 -1
- package/dist/integrations/google-docs-poller.js +8 -3
- package/dist/integrations/google-docs-poller.js.map +1 -1
- package/dist/integrations/webhook-handler.d.ts.map +1 -1
- package/dist/integrations/webhook-handler.js +22 -4
- package/dist/integrations/webhook-handler.js.map +1 -1
- package/dist/jobs/scheduler.d.ts +17 -0
- package/dist/jobs/scheduler.d.ts.map +1 -1
- package/dist/jobs/scheduler.js +60 -33
- package/dist/jobs/scheduler.js.map +1 -1
- package/dist/localization/default-messages.d.ts +17 -1
- package/dist/localization/default-messages.d.ts.map +1 -1
- package/dist/localization/default-messages.js +17 -1
- package/dist/localization/default-messages.js.map +1 -1
- package/dist/notifications/routes.d.ts +1 -1
- package/dist/observability/evals.d.ts.map +1 -1
- package/dist/observability/evals.js +7 -10
- package/dist/observability/evals.js.map +1 -1
- package/dist/observability/routes.d.ts +1 -1
- package/dist/observability/traces.d.ts +2 -0
- package/dist/observability/traces.d.ts.map +1 -1
- package/dist/observability/traces.js.map +1 -1
- package/dist/org/accept-pending.js +2 -2
- package/dist/org/accept-pending.js.map +1 -1
- package/dist/org/active-org.d.ts +16 -0
- package/dist/org/active-org.d.ts.map +1 -0
- package/dist/org/active-org.js +57 -0
- package/dist/org/active-org.js.map +1 -0
- package/dist/org/auto-join-domain.d.ts.map +1 -1
- package/dist/org/auto-join-domain.js +3 -2
- package/dist/org/auto-join-domain.js.map +1 -1
- package/dist/org/context.d.ts +19 -1
- package/dist/org/context.d.ts.map +1 -1
- package/dist/org/context.js +159 -71
- package/dist/org/context.js.map +1 -1
- package/dist/org/handlers.d.ts +24 -1
- package/dist/org/handlers.d.ts.map +1 -1
- package/dist/org/handlers.js +129 -10
- package/dist/org/handlers.js.map +1 -1
- package/dist/org/plugin.d.ts +2 -0
- package/dist/org/plugin.d.ts.map +1 -1
- package/dist/org/plugin.js +9 -2
- package/dist/org/plugin.js.map +1 -1
- package/dist/org/types.d.ts +6 -1
- package/dist/org/types.d.ts.map +1 -1
- package/dist/org/types.js.map +1 -1
- package/dist/progress/routes.d.ts +1 -1
- package/dist/provider-api/actions/custom-provider-registration.d.ts +9 -9
- package/dist/provider-api/actions/provider-api.d.ts +11 -11
- package/dist/provider-api/index.d.ts.map +1 -1
- package/dist/provider-api/index.js +3 -2
- package/dist/provider-api/index.js.map +1 -1
- package/dist/resources/handlers.d.ts.map +1 -1
- package/dist/resources/handlers.js +2 -7
- package/dist/resources/handlers.js.map +1 -1
- package/dist/resources/script-helpers.d.ts.map +1 -1
- package/dist/resources/script-helpers.js +2 -2
- package/dist/resources/script-helpers.js.map +1 -1
- package/dist/scripts/chat/search-chats.d.ts.map +1 -1
- package/dist/scripts/chat/search-chats.js +2 -2
- package/dist/scripts/chat/search-chats.js.map +1 -1
- package/dist/scripts/describe-workspace-apps.d.ts +4 -0
- package/dist/scripts/describe-workspace-apps.d.ts.map +1 -0
- package/dist/scripts/describe-workspace-apps.js +34 -0
- package/dist/scripts/describe-workspace-apps.js.map +1 -0
- package/dist/scripts/resources/delete-memory.d.ts.map +1 -1
- package/dist/scripts/resources/delete-memory.js +2 -2
- package/dist/scripts/resources/delete-memory.js.map +1 -1
- package/dist/scripts/resources/delete.d.ts.map +1 -1
- package/dist/scripts/resources/delete.js +2 -2
- package/dist/scripts/resources/delete.js.map +1 -1
- package/dist/scripts/resources/effective.d.ts.map +1 -1
- package/dist/scripts/resources/effective.js +2 -2
- package/dist/scripts/resources/effective.js.map +1 -1
- package/dist/scripts/resources/list.d.ts.map +1 -1
- package/dist/scripts/resources/list.js +2 -2
- package/dist/scripts/resources/list.js.map +1 -1
- package/dist/scripts/resources/read.d.ts.map +1 -1
- package/dist/scripts/resources/read.js +2 -2
- package/dist/scripts/resources/read.js.map +1 -1
- package/dist/scripts/resources/save-memory.d.ts.map +1 -1
- package/dist/scripts/resources/save-memory.js +2 -2
- package/dist/scripts/resources/save-memory.js.map +1 -1
- package/dist/scripts/resources/write.d.ts.map +1 -1
- package/dist/scripts/resources/write.js +2 -2
- package/dist/scripts/resources/write.js.map +1 -1
- package/dist/secrets/routes.d.ts +9 -9
- package/dist/server/agent-capabilities.d.ts +21 -0
- package/dist/server/agent-capabilities.d.ts.map +1 -0
- package/dist/server/agent-capabilities.js +106 -0
- package/dist/server/agent-capabilities.js.map +1 -0
- package/dist/server/agent-chat/framework-prompts.d.ts.map +1 -1
- package/dist/server/agent-chat/framework-prompts.js +11 -13
- package/dist/server/agent-chat/framework-prompts.js.map +1 -1
- package/dist/server/agent-chat/prompt-resources.d.ts +32 -0
- package/dist/server/agent-chat/prompt-resources.d.ts.map +1 -1
- package/dist/server/agent-chat/prompt-resources.js +117 -56
- package/dist/server/agent-chat/prompt-resources.js.map +1 -1
- package/dist/server/agent-chat/script-entries.d.ts.map +1 -1
- package/dist/server/agent-chat/script-entries.js +18 -8
- package/dist/server/agent-chat/script-entries.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +27 -1
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/dist/server/auth.d.ts +9 -9
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +32 -33
- package/dist/server/auth.js.map +1 -1
- package/dist/server/core-routes-plugin.d.ts +45 -0
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +162 -139
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/credential-provider.d.ts +35 -2
- package/dist/server/credential-provider.d.ts.map +1 -1
- package/dist/server/credential-provider.js +155 -40
- package/dist/server/credential-provider.js.map +1 -1
- package/dist/server/embed-session.d.ts.map +1 -1
- package/dist/server/embed-session.js +10 -0
- package/dist/server/embed-session.js.map +1 -1
- package/dist/server/framework-request-handler.d.ts.map +1 -1
- package/dist/server/framework-request-handler.js +38 -0
- package/dist/server/framework-request-handler.js.map +1 -1
- package/dist/server/google-auth-plugin.d.ts.map +1 -1
- package/dist/server/google-auth-plugin.js +12 -444
- package/dist/server/google-auth-plugin.js.map +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/onboarding-html.d.ts.map +1 -1
- package/dist/server/onboarding-html.js +20 -56
- package/dist/server/onboarding-html.js.map +1 -1
- package/dist/server/open-route.d.ts.map +1 -1
- package/dist/server/open-route.js +6 -1
- package/dist/server/open-route.js.map +1 -1
- package/dist/server/poll.js +1 -1
- package/dist/server/poll.js.map +1 -1
- package/dist/server/prompts/framework-core-compact.d.ts.map +1 -1
- package/dist/server/prompts/framework-core-compact.js +5 -6
- package/dist/server/prompts/framework-core-compact.js.map +1 -1
- package/dist/server/prompts/framework-core.d.ts.map +1 -1
- package/dist/server/prompts/framework-core.js +7 -10
- package/dist/server/prompts/framework-core.js.map +1 -1
- package/dist/server/prompts/shared-rules.d.ts +20 -2
- package/dist/server/prompts/shared-rules.d.ts.map +1 -1
- package/dist/server/prompts/shared-rules.js +20 -10
- package/dist/server/prompts/shared-rules.js.map +1 -1
- package/dist/server/request-context.d.ts +26 -1
- package/dist/server/request-context.d.ts.map +1 -1
- package/dist/server/request-context.js +52 -2
- package/dist/server/request-context.js.map +1 -1
- package/dist/server/scoped-key-storage.js +1 -1
- package/dist/server/scoped-key-storage.js.map +1 -1
- package/dist/settings/org-settings.d.ts +2 -0
- package/dist/settings/org-settings.d.ts.map +1 -1
- package/dist/settings/org-settings.js +5 -1
- package/dist/settings/org-settings.js.map +1 -1
- package/dist/settings/store.d.ts +6 -0
- package/dist/settings/store.d.ts.map +1 -1
- package/dist/settings/store.js +25 -0
- package/dist/settings/store.js.map +1 -1
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +1 -0
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/sign-in-journey.d.ts +102 -0
- package/dist/shared/sign-in-journey.d.ts.map +1 -0
- package/dist/shared/sign-in-journey.js +269 -0
- package/dist/shared/sign-in-journey.js.map +1 -0
- package/dist/styles/agent-native.css +8 -0
- package/dist/templates/chat/.agents/skills/actions/SKILL.md +19 -1
- package/dist/templates/chat/.agents/skills/adding-a-feature/SKILL.md +2 -0
- package/dist/templates/chat/.agents/skills/frontend-design/SKILL.md +20 -6
- package/dist/templates/chat/.agents/skills/security/SKILL.md +2 -0
- package/dist/templates/chat/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/dist/templates/chat/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/dist/templates/chat/.agents/skills/sharing/SKILL.md +228 -0
- package/dist/templates/chat/.agents/skills/storing-data/SKILL.md +178 -0
- package/dist/templates/chat/AGENTS.md +8 -0
- package/dist/templates/chat/app/entry.client.tsx +3 -0
- package/dist/templates/default/.agents/skills/actions/SKILL.md +19 -1
- package/dist/templates/default/.agents/skills/adding-a-feature/SKILL.md +2 -0
- package/dist/templates/default/.agents/skills/frontend-design/SKILL.md +20 -6
- package/dist/templates/default/.agents/skills/security/SKILL.md +2 -0
- package/dist/templates/default/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/dist/templates/default/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/dist/templates/default/AGENTS.md +68 -195
- package/dist/templates/default/app/entry.client.tsx +3 -0
- package/dist/templates/default/app/i18n/ar-SA.ts +8 -0
- package/dist/templates/default/app/i18n/de-DE.ts +8 -0
- package/dist/templates/default/app/i18n/en-US.ts +8 -0
- package/dist/templates/default/app/i18n/es-ES.ts +8 -0
- package/dist/templates/default/app/i18n/fr-FR.ts +8 -0
- package/dist/templates/default/app/i18n/hi-IN.ts +8 -0
- package/dist/templates/default/app/i18n/ja-JP.ts +8 -0
- package/dist/templates/default/app/i18n/ko-KR.ts +8 -0
- package/dist/templates/default/app/i18n/pt-BR.ts +8 -0
- package/dist/templates/default/app/i18n/zh-CN.ts +8 -0
- package/dist/templates/default/app/i18n/zh-TW.ts +8 -0
- package/dist/templates/headless/.agents/skills/actions/SKILL.md +19 -1
- package/dist/templates/workspace-core/.agents/skills/actions/SKILL.md +19 -1
- package/dist/templates/workspace-core/.agents/skills/adding-a-feature/SKILL.md +2 -0
- package/dist/templates/workspace-core/.agents/skills/adding-workspace-apps/SKILL.md +100 -0
- package/dist/templates/workspace-core/.agents/skills/address-feedback/SKILL.md +2 -1
- package/dist/templates/workspace-core/.agents/skills/authentication/SKILL.md +28 -0
- package/dist/templates/workspace-core/.agents/skills/composable-mini-apps/SKILL.md +14 -1
- package/dist/templates/workspace-core/.agents/skills/frontend-design/SKILL.md +20 -6
- package/dist/templates/workspace-core/.agents/skills/qa/SKILL.md +6 -3
- package/dist/templates/workspace-core/.agents/skills/security/SKILL.md +2 -0
- package/dist/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/dist/templates/workspace-core/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/dist/templates/workspace-core/.agents/skills/workspace-conventions/SKILL.md +91 -0
- package/dist/templates/workspace-core/.agents/skills/writing-agent-instructions/SKILL.md +60 -0
- package/dist/templates/workspace-core/AGENTS.md +62 -124
- package/dist/templates/workspace-root/AGENTS.md +6 -1
- package/dist/triggers/dispatcher.d.ts.map +1 -1
- package/dist/triggers/dispatcher.js +10 -3
- package/dist/triggers/dispatcher.js.map +1 -1
- package/dist/vite/client.d.ts.map +1 -1
- package/dist/vite/client.js +18 -8
- package/dist/vite/client.js.map +1 -1
- package/docs/content/actions.mdx +33 -20
- package/docs/content/agent-mentions.mdx +30 -19
- package/docs/content/agent-native-toolkit.mdx +8 -6
- package/docs/content/agent-resources.mdx +11 -0
- package/docs/content/agent-surfaces.mdx +41 -30
- package/docs/content/audit-log.mdx +78 -0
- package/docs/content/authentication.mdx +7 -5
- package/docs/content/automations.mdx +15 -9
- package/docs/content/client.mdx +11 -11
- package/docs/content/cloneable-saas.mdx +7 -1
- package/docs/content/code-agents-ui.mdx +9 -1
- package/docs/content/components.mdx +7 -0
- package/docs/content/context-awareness.mdx +1 -0
- package/docs/content/creating-templates.mdx +9 -1
- package/docs/content/custom-design-system.mdx +8 -0
- package/docs/content/data-programs.mdx +6 -0
- package/docs/content/deployment.mdx +2 -0
- package/docs/content/doctor.mdx +5 -3
- package/docs/content/extensions.mdx +26 -0
- package/docs/content/external-agents-catalog.mdx +533 -0
- package/docs/content/external-agents.mdx +20 -514
- package/docs/content/faq.mdx +2 -2
- package/docs/content/file-uploads.mdx +44 -0
- package/docs/content/frames.mdx +2 -2
- package/docs/content/generative-ui.mdx +8 -0
- package/docs/content/getting-started.mdx +45 -17
- package/docs/content/human-approval.mdx +9 -0
- package/docs/content/integrations.mdx +4 -3
- package/docs/content/internationalization.mdx +4 -11
- package/docs/content/key-concepts.mdx +1 -1
- package/docs/content/local-file-mode.mdx +5 -0
- package/docs/content/mcp-apps.mdx +2 -1
- package/docs/content/mcp-clients.mdx +32 -1
- package/docs/content/mcp-protocol.mdx +4 -3
- package/docs/content/messaging-internals.mdx +328 -0
- package/docs/content/messaging-recipes.mdx +194 -0
- package/docs/content/messaging.mdx +9 -307
- package/docs/content/multi-app-workspace.mdx +1 -1
- package/docs/content/multi-tenancy.mdx +1 -0
- package/docs/content/native-chat-ui.mdx +8 -0
- package/docs/content/notifications.mdx +18 -20
- package/docs/content/observability.mdx +1 -0
- package/docs/content/onboarding.mdx +20 -6
- package/docs/content/organizations-teams-permissions.mdx +99 -124
- package/docs/content/package-lifecycle.mdx +19 -7
- package/docs/content/progress.mdx +11 -0
- package/docs/content/real-time-collaboration.mdx +44 -3
- package/docs/content/recurring-jobs.mdx +14 -1
- package/docs/content/security.mdx +5 -2
- package/docs/content/server.mdx +2 -1
- package/docs/content/sharing.mdx +22 -3
- package/docs/content/skills-guide.mdx +62 -19
- package/docs/content/syncing-template-changes.mdx +9 -0
- package/docs/content/template-analytics-connectors.mdx +75 -0
- package/docs/content/template-analytics-dashboards.mdx +106 -0
- package/docs/content/template-analytics-developers.mdx +287 -0
- package/docs/content/template-analytics-monitoring-and-sessions.mdx +109 -0
- package/docs/content/template-analytics.mdx +21 -263
- package/docs/content/template-assets-developers.mdx +456 -0
- package/docs/content/template-assets-generation.mdx +147 -0
- package/docs/content/template-assets-integrations.mdx +319 -0
- package/docs/content/template-assets-presets.mdx +185 -0
- package/docs/content/template-assets.mdx +12 -562
- package/docs/content/template-brain-agent.mdx +103 -0
- package/docs/content/template-brain-developers.mdx +379 -0
- package/docs/content/template-brain-knowledge.mdx +50 -0
- package/docs/content/template-brain-sources.mdx +163 -0
- package/docs/content/template-brain.mdx +30 -390
- package/docs/content/template-calendar-agent.mdx +133 -0
- package/docs/content/template-calendar-booking-links.mdx +73 -0
- package/docs/content/template-calendar-developers.mdx +366 -0
- package/docs/content/template-calendar-scheduling.mdx +128 -0
- package/docs/content/template-calendar.mdx +13 -260
- package/docs/content/template-chat-developers.mdx +88 -0
- package/docs/content/template-chat-first-edits.mdx +145 -0
- package/docs/content/template-chat.mdx +12 -77
- package/docs/content/template-clips-ai-and-editing.mdx +114 -0
- package/docs/content/template-clips-capture-everywhere.mdx +120 -0
- package/docs/content/template-clips-developers.mdx +373 -0
- package/docs/content/template-clips-sharing-and-teams.mdx +182 -0
- package/docs/content/template-clips.mdx +19 -508
- package/docs/content/template-content-databases.mdx +406 -0
- package/docs/content/template-content-developers.mdx +364 -0
- package/docs/content/template-content-editing.mdx +60 -0
- package/docs/content/template-content-sync.mdx +149 -0
- package/docs/content/template-content.mdx +21 -561
- package/docs/content/template-design-brand-and-figma.mdx +150 -0
- package/docs/content/template-design-collaboration-and-full-apps.mdx +125 -0
- package/docs/content/template-design-developers.mdx +358 -0
- package/docs/content/template-design-quality-and-components.mdx +95 -0
- package/docs/content/template-design.mdx +20 -344
- package/docs/content/template-dispatch-developers.mdx +121 -0
- package/docs/content/template-dispatch-messaging-routing.mdx +114 -0
- package/docs/content/template-dispatch-operations.mdx +160 -0
- package/docs/content/template-dispatch-vault-integrations.mdx +316 -0
- package/docs/content/template-dispatch.mdx +24 -283
- package/docs/content/template-forms-building-publishing.mdx +135 -0
- package/docs/content/template-forms-developers.mdx +195 -0
- package/docs/content/template-forms-responses.mdx +120 -0
- package/docs/content/template-forms.mdx +21 -230
- package/docs/content/template-mail-agent.mdx +114 -0
- package/docs/content/template-mail-developers.mdx +356 -0
- package/docs/content/template-mail-drafts-and-queue.mdx +103 -0
- package/docs/content/template-mail-inbox.mdx +118 -0
- package/docs/content/template-mail.mdx +23 -274
- package/docs/content/template-plan-automations.mdx +213 -0
- package/docs/content/template-plan-developers.mdx +703 -0
- package/docs/content/template-plan-local-and-desktop.mdx +236 -0
- package/docs/content/template-plan-review-workflow.mdx +180 -0
- package/docs/content/template-plan.mdx +60 -910
- package/docs/content/template-slides-agent.mdx +102 -0
- package/docs/content/template-slides-design-and-media.mdx +94 -0
- package/docs/content/template-slides-developers.mdx +488 -0
- package/docs/content/template-slides-editing.mdx +56 -0
- package/docs/content/template-slides.mdx +20 -362
- package/docs/content/toolkit-capability-packages.mdx +38 -13
- package/docs/content/toolkit-context-knowledge.mdx +49 -9
- package/docs/content/toolkit-editors-canvases.mdx +72 -10
- package/docs/content/toolkit-resources.mdx +16 -0
- package/docs/content/toolkit-settings.mdx +3 -3
- package/docs/content/toolkit-sharing.mdx +5 -7
- package/docs/content/using-your-agent.mdx +25 -2
- package/docs/content/voice-input.mdx +11 -7
- package/docs/content/what-is-agent-native.mdx +1 -0
- package/docs/content/workspace-connections.mdx +21 -11
- package/docs/content/workspace-management.mdx +1 -1
- package/package.json +2 -4
- package/src/a2a/client.ts +4 -2
- package/src/agent/action-warnings.ts +103 -0
- package/src/agent/durable-background.ts +42 -5
- package/src/agent/engine/ai-sdk-engine.ts +58 -6
- package/src/agent/engine/anthropic-engine.ts +51 -8
- package/src/agent/engine/builder-engine.ts +56 -18
- package/src/agent/engine/continuation-dispatch-retry.ts +10 -9
- package/src/agent/engine/credential-errors.ts +11 -0
- package/src/agent/engine/error-detail.ts +39 -0
- package/src/agent/engine/prompt-cache.ts +44 -0
- package/src/agent/engine/registry.ts +22 -30
- package/src/agent/engine/tool-call-journal-seed.ts +2 -1
- package/src/agent/engine/translate-anthropic.ts +99 -0
- package/src/agent/loop-settings.ts +94 -7
- package/src/agent/production-agent.ts +667 -157
- package/src/agent/run-loop-with-resume.ts +27 -1
- package/src/agent/run-manager.ts +229 -39
- package/src/agent/run-store.ts +397 -64
- package/src/agent/thread-data-builder.ts +5 -1
- package/src/agent/types.ts +23 -6
- package/src/application-state/script-helpers.ts +5 -2
- package/src/cli/agents.ts +69 -1
- package/src/cli/app-skill.ts +1 -1
- package/src/cli/code-agent-executor.ts +7 -3
- package/src/cli/design-connect.ts +82 -8
- package/src/cli/skills-content/design-visual-edit-skill.ts +169 -24
- package/src/client/AssistantChat.tsx +623 -607
- package/src/client/agent-chat-adapter.ts +176 -29
- package/src/client/chat/message-components.tsx +13 -0
- package/src/client/embed-auth.ts +3 -1
- package/src/client/integrations/IntegrationCard.tsx +41 -24
- package/src/client/integrations/IntegrationsPanel.tsx +37 -21
- package/src/client/integrations/webhook-url.ts +29 -0
- package/src/client/org/OrgSwitcher.tsx +41 -27
- package/src/client/org/RequireActiveOrg.tsx +7 -0
- package/src/client/org/TeamPage.tsx +144 -14
- package/src/client/org/hooks.ts +27 -0
- package/src/client/org/index.ts +2 -0
- package/src/client/require-session.tsx +40 -29
- package/src/client/session-replay.ts +1 -1
- package/src/client/settings/DemoModeSection.tsx +0 -5
- package/src/client/settings/SecretsSection.tsx +47 -42
- package/src/client/settings/VoiceTranscriptionSection.tsx +0 -5
- package/src/client/sse-event-processor.ts +83 -8
- package/src/client/use-action.ts +22 -13
- package/src/client/use-agent-engine-configured.ts +36 -4
- package/src/client/use-db-sync.ts +21 -1
- package/src/credentials/index.ts +124 -2
- package/src/deploy/build.ts +93 -30
- package/src/deploy/workspace-deploy.ts +21 -16
- package/src/guards/no-localhost-fallback.ts +76 -14
- package/src/integrations/google-docs-poller.ts +19 -12
- package/src/integrations/webhook-handler.ts +56 -33
- package/src/jobs/scheduler.ts +57 -23
- package/src/localization/default-messages.ts +23 -1
- package/src/observability/evals.ts +7 -8
- package/src/observability/traces.ts +2 -0
- package/src/org/accept-pending.ts +2 -2
- package/src/org/active-org.ts +73 -0
- package/src/org/auto-join-domain.ts +7 -2
- package/src/org/context.ts +169 -66
- package/src/org/handlers.ts +148 -10
- package/src/org/plugin.ts +8 -1
- package/src/org/types.ts +6 -1
- package/src/provider-api/index.ts +6 -1
- package/src/resources/handlers.ts +2 -6
- package/src/resources/script-helpers.ts +2 -1
- package/src/scripts/chat/search-chats.ts +5 -2
- package/src/scripts/describe-workspace-apps.ts +59 -0
- package/src/scripts/resources/delete-memory.ts +5 -2
- package/src/scripts/resources/delete.ts +5 -2
- package/src/scripts/resources/effective.ts +5 -2
- package/src/scripts/resources/list.ts +5 -2
- package/src/scripts/resources/read.ts +5 -2
- package/src/scripts/resources/save-memory.ts +5 -2
- package/src/scripts/resources/write.ts +5 -2
- package/src/server/__snapshots__/agent-chat-plugin.surface.spec.ts.snap +11 -31
- package/src/server/agent-capabilities.ts +147 -0
- package/src/server/agent-chat/framework-prompts.ts +11 -13
- package/src/server/agent-chat/prompt-resources.ts +183 -57
- package/src/server/agent-chat/script-entries.ts +20 -7
- package/src/server/agent-chat-plugin.ts +27 -0
- package/src/server/auth.ts +38 -32
- package/src/server/core-routes-plugin.ts +229 -179
- package/src/server/credential-provider.ts +196 -44
- package/src/server/embed-session.ts +10 -0
- package/src/server/framework-request-handler.ts +43 -0
- package/src/server/google-auth-plugin.ts +13 -450
- package/src/server/index.ts +4 -1
- package/src/server/onboarding-html.ts +20 -56
- package/src/server/open-route.ts +6 -1
- package/src/server/poll.ts +1 -1
- package/src/server/prompts/framework-core-compact.ts +5 -5
- package/src/server/prompts/framework-core.ts +7 -9
- package/src/server/prompts/shared-rules.ts +20 -9
- package/src/server/request-context.ts +58 -2
- package/src/server/scoped-key-storage.ts +1 -1
- package/src/settings/org-settings.ts +9 -0
- package/src/settings/store.ts +29 -0
- package/src/shared/index.ts +13 -0
- package/src/shared/sign-in-journey.ts +331 -0
- package/src/styles/agent-native.css +8 -0
- package/src/templates/chat/.agents/skills/actions/SKILL.md +19 -1
- package/src/templates/chat/.agents/skills/adding-a-feature/SKILL.md +2 -0
- package/src/templates/chat/.agents/skills/frontend-design/SKILL.md +20 -6
- package/src/templates/chat/.agents/skills/security/SKILL.md +2 -0
- package/src/templates/chat/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/src/templates/chat/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/src/templates/chat/.agents/skills/sharing/SKILL.md +228 -0
- package/src/templates/chat/.agents/skills/storing-data/SKILL.md +178 -0
- package/src/templates/chat/AGENTS.md +8 -0
- package/src/templates/chat/app/entry.client.tsx +3 -0
- package/src/templates/default/.agents/skills/actions/SKILL.md +19 -1
- package/src/templates/default/.agents/skills/adding-a-feature/SKILL.md +2 -0
- package/src/templates/default/.agents/skills/frontend-design/SKILL.md +20 -6
- package/src/templates/default/.agents/skills/security/SKILL.md +2 -0
- package/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/src/templates/default/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/src/templates/default/AGENTS.md +68 -195
- package/src/templates/default/app/entry.client.tsx +3 -0
- package/src/templates/default/app/i18n/ar-SA.ts +8 -0
- package/src/templates/default/app/i18n/de-DE.ts +8 -0
- package/src/templates/default/app/i18n/en-US.ts +8 -0
- package/src/templates/default/app/i18n/es-ES.ts +8 -0
- package/src/templates/default/app/i18n/fr-FR.ts +8 -0
- package/src/templates/default/app/i18n/hi-IN.ts +8 -0
- package/src/templates/default/app/i18n/ja-JP.ts +8 -0
- package/src/templates/default/app/i18n/ko-KR.ts +8 -0
- package/src/templates/default/app/i18n/pt-BR.ts +8 -0
- package/src/templates/default/app/i18n/zh-CN.ts +8 -0
- package/src/templates/default/app/i18n/zh-TW.ts +8 -0
- package/src/templates/headless/.agents/skills/actions/SKILL.md +19 -1
- package/src/templates/workspace-core/.agents/skills/actions/SKILL.md +19 -1
- package/src/templates/workspace-core/.agents/skills/adding-a-feature/SKILL.md +2 -0
- package/src/templates/workspace-core/.agents/skills/adding-workspace-apps/SKILL.md +100 -0
- package/src/templates/workspace-core/.agents/skills/address-feedback/SKILL.md +2 -1
- package/src/templates/workspace-core/.agents/skills/authentication/SKILL.md +28 -0
- package/src/templates/workspace-core/.agents/skills/composable-mini-apps/SKILL.md +14 -1
- package/src/templates/workspace-core/.agents/skills/frontend-design/SKILL.md +20 -6
- package/src/templates/workspace-core/.agents/skills/qa/SKILL.md +6 -3
- package/src/templates/workspace-core/.agents/skills/security/SKILL.md +2 -0
- package/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +4 -3
- package/src/templates/workspace-core/.agents/skills/shadcn-ui/SKILL.md +7 -3
- package/src/templates/workspace-core/.agents/skills/workspace-conventions/SKILL.md +91 -0
- package/src/templates/workspace-core/.agents/skills/writing-agent-instructions/SKILL.md +60 -0
- package/src/templates/workspace-core/AGENTS.md +62 -124
- package/src/templates/workspace-root/AGENTS.md +6 -1
- package/src/triggers/dispatcher.ts +28 -17
- package/src/vite/client.ts +20 -8
- package/corpus/core/src/client/components/MissingKeyCard.tsx +0 -61
- package/corpus/core/src/client/extensions/agent-native-extension-runtime.ts +0 -495
- package/corpus/core/src/client/settings/BackgroundAgentSection.tsx +0 -193
- package/corpus/core/src/client/settings/BrowserSection.tsx +0 -110
- package/corpus/templates/analytics/app/components/InlineMetric.tsx +0 -31
- package/corpus/templates/analytics/app/components/auth/LoginScreen.tsx +0 -4
- package/corpus/templates/analytics/app/components/dashboard/CumulativeNetChart.tsx +0 -128
- package/corpus/templates/analytics/app/components/dashboard/DataTable.tsx +0 -264
- package/corpus/templates/analytics/app/components/dashboard/RecentActivity.tsx +0 -84
- package/corpus/templates/analytics/app/components/dashboard/RevenueChart.tsx +0 -92
- package/corpus/templates/analytics/app/components/dashboard/RevenueComparisonChart.tsx +0 -154
- package/corpus/templates/analytics/app/components/dashboard/StatsCard.tsx +0 -49
- package/corpus/templates/analytics/app/components/dashboard/TimeSeriesChart.tsx +0 -120
- package/corpus/templates/analytics/server/handlers/dashboard-views.ts +0 -85
- package/corpus/templates/analytics/server/handlers/user-prefs.ts +0 -58
- package/corpus/templates/analytics/server/routes/api/dashboard-views/[dashboardId]/[viewId].delete.ts +0 -1
- package/corpus/templates/analytics/server/routes/api/dashboard-views/[dashboardId].get.ts +0 -1
- package/corpus/templates/analytics/server/routes/api/dashboard-views/[dashboardId].post.ts +0 -1
- package/corpus/templates/analytics/server/routes/api/theme.get.ts +0 -17
- package/corpus/templates/analytics/server/routes/api/theme.post.ts +0 -15
- package/corpus/templates/analytics/server/routes/api/user-prefs/[key].delete.ts +0 -1
- package/corpus/templates/analytics/server/routes/api/user-prefs/[key].get.ts +0 -1
- package/corpus/templates/analytics/server/routes/api/user-prefs/[key].put.ts +0 -1
- package/corpus/templates/assets/app/components/library/CreateLibraryDialog.tsx +0 -156
- package/corpus/templates/assets/app/components/library/LibraryCard.tsx +0 -213
- package/corpus/templates/calendar/app/components/calendar/GoogleSyncButton.tsx +0 -49
- package/corpus/templates/calendar/server/routes/api/events/[id].delete.ts +0 -1
- package/corpus/templates/calendar/server/routes/api/events/[id].get.ts +0 -1
- package/corpus/templates/calendar/server/routes/api/events/[id].put.ts +0 -1
- package/corpus/templates/content/app/components/layout/AppLayout.tsx +0 -9
- package/corpus/templates/content/server/routes/api/comments/[id].delete.ts +0 -69
- package/corpus/templates/content/server/routes/api/comments/[id].patch.ts +0 -109
- package/corpus/templates/content/server/routes/api/documents/[id]/versions.get.ts +0 -53
- package/corpus/templates/design/app/components/design/code-workbench/ActivityBar.tsx +0 -85
- package/corpus/templates/design/app/components/design-system/DesignSystemCard.tsx +0 -129
- package/corpus/templates/forms/app/components/layout/AppLayout.tsx +0 -9
- package/corpus/templates/mail/app/components/email/SnoozePopover.tsx +0 -213
- package/corpus/templates/mail/server/handlers/aliases.ts +0 -98
- package/corpus/templates/mail/server/routes/api/aliases/[id].delete.ts +0 -1
- package/corpus/templates/mail/server/routes/api/aliases/[id].patch.ts +0 -1
- package/corpus/templates/mail/server/routes/api/aliases/index.get.ts +0 -1
- package/corpus/templates/mail/server/routes/api/aliases/index.post.ts +0 -1
- package/corpus/templates/mail/server/routes/api/automations/[id].delete.ts +0 -1
- package/corpus/templates/mail/server/routes/api/automations/[id].patch.ts +0 -1
- package/corpus/templates/mail/server/routes/api/automations/index.get.ts +0 -1
- package/corpus/templates/mail/server/routes/api/automations/index.post.ts +0 -1
- package/corpus/templates/mail/server/routes/api/automations/settings.get.ts +0 -22
- package/corpus/templates/mail/server/routes/api/automations/settings.put.ts +0 -25
- package/corpus/templates/mail/server/routes/api/scheduled-jobs/[id].delete.ts +0 -1
- package/corpus/templates/mail/server/routes/api/scheduled-jobs/[id].patch.ts +0 -1
- package/corpus/templates/mail/server/routes/api/scheduled-jobs/index.get.ts +0 -1
- package/corpus/templates/mail/server/routes/api/scheduled-jobs/index.post.ts +0 -1
- package/corpus/templates/mail/server/routes/api/settings.get.ts +0 -1
- package/corpus/templates/mail/server/routes/api/settings.patch.ts +0 -1
- package/corpus/templates/slides/app/components/deck/BuilderLogo.tsx +0 -22
- package/corpus/templates/slides/app/components/design-system/DesignSystemPreview.tsx +0 -176
- package/corpus/templates/slides/app/components/editor/GenerateSlidesDialog.tsx +0 -244
- package/corpus/templates/slides/app/components/editor/ImportButton.tsx +0 -84
- package/corpus/templates/slides/server/routes/api/comments/[id].delete.ts +0 -43
- package/corpus/templates/slides/server/routes/api/comments/[id].patch.ts +0 -50
- package/corpus/templates/slides/server/routes/api/decks/[id].delete.ts +0 -1
- package/corpus/templates/slides/server/routes/api/decks/[id].get.ts +0 -1
- package/corpus/templates/slides/server/routes/api/decks/[id].put.ts +0 -1
- package/corpus/templates/slides/server/routes/api/decks/index.get.ts +0 -1
- package/corpus/templates/slides/server/routes/api/decks/index.post.ts +0 -1
- package/dist/client/components/MissingKeyCard.d.ts +0 -7
- package/dist/client/components/MissingKeyCard.d.ts.map +0 -1
- package/dist/client/components/MissingKeyCard.js +0 -32
- package/dist/client/components/MissingKeyCard.js.map +0 -1
- package/dist/client/extensions/agent-native-extension-runtime.d.ts +0 -69
- package/dist/client/extensions/agent-native-extension-runtime.d.ts.map +0 -1
- package/dist/client/extensions/agent-native-extension-runtime.js +0 -348
- package/dist/client/extensions/agent-native-extension-runtime.js.map +0 -1
- package/dist/client/settings/BackgroundAgentSection.d.ts +0 -2
- package/dist/client/settings/BackgroundAgentSection.d.ts.map +0 -1
- package/dist/client/settings/BackgroundAgentSection.js +0 -68
- package/dist/client/settings/BackgroundAgentSection.js.map +0 -1
- package/dist/client/settings/BrowserSection.d.ts +0 -2
- package/dist/client/settings/BrowserSection.d.ts.map +0 -1
- package/dist/client/settings/BrowserSection.js +0 -40
- package/dist/client/settings/BrowserSection.js.map +0 -1
- package/dist/templates/chat/.react-router/types/+server-build.d.ts +0 -18
- package/dist/templates/chat/.react-router/types/app/+types/root.ts +0 -68
- package/src/client/components/MissingKeyCard.tsx +0 -61
- package/src/client/extensions/agent-native-extension-runtime.ts +0 -495
- package/src/client/settings/BackgroundAgentSection.tsx +0 -193
- package/src/client/settings/BrowserSection.tsx +0 -110
- package/src/templates/chat/.react-router/types/+server-build.d.ts +0 -18
- package/src/templates/chat/.react-router/types/app/+types/root.ts +0 -68
|
@@ -17,6 +17,13 @@
|
|
|
17
17
|
* of hardcoded. The generic allowlist predicates (`*.spec.*`, `*.test.*`,
|
|
18
18
|
* `scripts/**`, `**\/seed(s)/**`) are kept verbatim.
|
|
19
19
|
*
|
|
20
|
+
* Also refuses to let request-handling code answer "who is the caller" with the
|
|
21
|
+
* ambient process identity (`?? process.env.AGENT_USER_EMAIL`,
|
|
22
|
+
* `|| process.env.WORKSPACE_OWNER_EMAIL`, `?? getAmbientUserEmail()`). That
|
|
23
|
+
* shape fails open toward more privilege: an admin gate reading it admits
|
|
24
|
+
* whoever the deploy env names rather than whoever signed in. CLI, cron, seed
|
|
25
|
+
* and test paths are exempt because they have no request by construction.
|
|
26
|
+
*
|
|
20
27
|
* Opt-out (same line, or the line immediately above):
|
|
21
28
|
* const x = email ?? "local@localhost" // guard:allow-localhost-fallback — short reason
|
|
22
29
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-localhost-fallback.d.ts","sourceRoot":"","sources":["../../src/guards/no-localhost-fallback.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"no-localhost-fallback.d.ts","sourceRoot":"","sources":["../../src/guards/no-localhost-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AASH,OAAO,KAAK,EAAgB,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9E,MAAM,WAAW,wBAAyB,SAAQ,gBAAgB;IAChE;4DACwD;IACxD,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAmED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,wBAAwB,GAChC,WAAW,CAyEb"}
|
|
@@ -17,6 +17,13 @@
|
|
|
17
17
|
* of hardcoded. The generic allowlist predicates (`*.spec.*`, `*.test.*`,
|
|
18
18
|
* `scripts/**`, `**\/seed(s)/**`) are kept verbatim.
|
|
19
19
|
*
|
|
20
|
+
* Also refuses to let request-handling code answer "who is the caller" with the
|
|
21
|
+
* ambient process identity (`?? process.env.AGENT_USER_EMAIL`,
|
|
22
|
+
* `|| process.env.WORKSPACE_OWNER_EMAIL`, `?? getAmbientUserEmail()`). That
|
|
23
|
+
* shape fails open toward more privilege: an admin gate reading it admits
|
|
24
|
+
* whoever the deploy env names rather than whoever signed in. CLI, cron, seed
|
|
25
|
+
* and test paths are exempt because they have no request by construction.
|
|
26
|
+
*
|
|
20
27
|
* Opt-out (same line, or the line immediately above):
|
|
21
28
|
* const x = email ?? "local@localhost" // guard:allow-localhost-fallback — short reason
|
|
22
29
|
*/
|
|
@@ -32,6 +39,31 @@ const OPT_OUT_MARKER = /\/\/\s*guard:allow-localhost-fallback\b[^\n]*/;
|
|
|
32
39
|
const OPT_OUT_REQUIRES_REASON = /\/\/\s*guard:allow-localhost-fallback\s*[—-]\s*\S/;
|
|
33
40
|
const LITERAL_RE = /(?:"local@localhost"|'local@localhost'|`local@localhost`)/g;
|
|
34
41
|
const SYMBOLIC_FALLBACK_RE = /(?:\?\?|\|\|)\s*DEV_MODE_USER_EMAIL\b/g;
|
|
42
|
+
/**
|
|
43
|
+
* Ambient process identity used as a request-scoped fallback:
|
|
44
|
+
*
|
|
45
|
+
* const email = getRequestUserEmail() ?? process.env.AGENT_USER_EMAIL;
|
|
46
|
+
* const owner = session?.email || process.env.WORKSPACE_OWNER_EMAIL;
|
|
47
|
+
*
|
|
48
|
+
* These name the identity of the deployment, not the caller, so a request
|
|
49
|
+
* handler reading one authorizes whoever the env names — failing open toward
|
|
50
|
+
* more privilege. Only the `??` / `||` fallback position matches: reading the
|
|
51
|
+
* same env var to build an admin allowlist asks a different, safe question.
|
|
52
|
+
*/
|
|
53
|
+
const AMBIENT_ENV_FALLBACK_RE = /(?:\?\?|\|\|)\s*process\.env\.(?:AGENT_USER_EMAIL|AGENT_ORG_ID|AGENT_USER_NAME|WORKSPACE_OWNER_EMAIL)\b/g;
|
|
54
|
+
const AMBIENT_HELPER_FALLBACK_RE = /(?:\?\?|\|\|)\s*getAmbient(?:UserEmail|OrgId)\s*\(\s*\)/g;
|
|
55
|
+
/** Paths where an ambient identity is correct because no request exists by
|
|
56
|
+
* construction: CLI entrypoints, cron, seed and QA scripts, tests. */
|
|
57
|
+
const AMBIENT_ALLOWED_PATH_PREDICATES = [
|
|
58
|
+
(rel) => /(?:^|\/)scripts\//.test(rel),
|
|
59
|
+
(rel) => /(?:^|\/)src\/cli\//.test(rel),
|
|
60
|
+
(rel) => /(?:^|\/)src\/scripts\//.test(rel),
|
|
61
|
+
(rel) => /(?:^|\/)script-(?:helpers|entries)\.ts$/.test(rel),
|
|
62
|
+
(rel) => /\.spec\.[tj]sx?$/.test(rel),
|
|
63
|
+
(rel) => /\.test\.[tj]sx?$/.test(rel),
|
|
64
|
+
(rel) => /\/seed\//.test(rel),
|
|
65
|
+
(rel) => /\/seeds\//.test(rel),
|
|
66
|
+
];
|
|
35
67
|
const SQL_DEFAULT_RE = /\bDEFAULT\s+['"`]local@localhost['"`]/i;
|
|
36
68
|
const DRIZZLE_DEFAULT_RE = /\.default\s*\(\s*['"`]local@localhost['"`]\s*\)/;
|
|
37
69
|
function isAllowedPath(rel, extraExemptPaths) {
|
|
@@ -59,44 +91,71 @@ export function scanLocalhostFallback(options) {
|
|
|
59
91
|
if (file.endsWith(".d.ts"))
|
|
60
92
|
continue;
|
|
61
93
|
const rel = relPosix(root, file);
|
|
62
|
-
|
|
94
|
+
const literalAllowed = isAllowedPath(rel, extraExemptPaths);
|
|
95
|
+
const ambientAllowed = AMBIENT_ALLOWED_PATH_PREDICATES.some((p) => p(rel));
|
|
96
|
+
if (literalAllowed && ambientAllowed)
|
|
63
97
|
continue;
|
|
64
98
|
const contents = readFileSafe(file);
|
|
65
|
-
if (contents === null
|
|
99
|
+
if (contents === null)
|
|
66
100
|
continue;
|
|
67
101
|
const lines = contents.split("\n");
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
102
|
+
if (!ambientAllowed) {
|
|
103
|
+
for (const re of [AMBIENT_ENV_FALLBACK_RE, AMBIENT_HELPER_FALLBACK_RE]) {
|
|
104
|
+
re.lastIndex = 0;
|
|
105
|
+
let a;
|
|
106
|
+
while ((a = re.exec(contents)) !== null) {
|
|
107
|
+
const { line } = lineColForOffset(contents, a.index);
|
|
108
|
+
const lineText = lines[line - 1] ?? "";
|
|
109
|
+
if (isCommentLine(lineText))
|
|
110
|
+
continue;
|
|
111
|
+
if (hasValidOptOut(lines, line - 1))
|
|
112
|
+
continue;
|
|
113
|
+
findings.push({
|
|
114
|
+
file: rel,
|
|
115
|
+
line,
|
|
116
|
+
message: `Ambient process identity used as a request-scoped fallback: ${lineText.trim()}. This authorizes whoever the deploy env names, not the signed-in user — fail closed on a missing caller, or call getAmbientUserEmail() from a CLI/cron path.`,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (literalAllowed)
|
|
122
|
+
continue;
|
|
123
|
+
// Scanned before the literal bail-out below: aliasing is exactly how this
|
|
124
|
+
// shape hides in a file that never spells out the literal itself.
|
|
125
|
+
SYMBOLIC_FALLBACK_RE.lastIndex = 0;
|
|
126
|
+
let symbolicMatch;
|
|
127
|
+
while ((symbolicMatch = SYMBOLIC_FALLBACK_RE.exec(contents)) !== null) {
|
|
128
|
+
const { line } = lineColForOffset(contents, symbolicMatch.index);
|
|
72
129
|
const lineText = lines[line - 1] ?? "";
|
|
73
130
|
if (isCommentLine(lineText))
|
|
74
131
|
continue;
|
|
75
|
-
if (SQL_DEFAULT_RE.test(lineText))
|
|
76
|
-
continue;
|
|
77
|
-
if (DRIZZLE_DEFAULT_RE.test(lineText))
|
|
78
|
-
continue;
|
|
79
132
|
if (hasValidOptOut(lines, line - 1))
|
|
80
133
|
continue;
|
|
81
134
|
findings.push({
|
|
82
135
|
file: rel,
|
|
83
136
|
line,
|
|
84
|
-
message: `
|
|
137
|
+
message: `DEV_MODE_USER_EMAIL used as a fallback identity: ${lineText.trim()}. Throw/401 on missing session instead.`,
|
|
85
138
|
});
|
|
86
139
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
140
|
+
if (!contents.includes("local@localhost"))
|
|
141
|
+
continue;
|
|
142
|
+
LITERAL_RE.lastIndex = 0;
|
|
143
|
+
let literalMatch;
|
|
144
|
+
while ((literalMatch = LITERAL_RE.exec(contents)) !== null) {
|
|
145
|
+
const { line } = lineColForOffset(contents, literalMatch.index);
|
|
91
146
|
const lineText = lines[line - 1] ?? "";
|
|
92
147
|
if (isCommentLine(lineText))
|
|
93
148
|
continue;
|
|
149
|
+
if (SQL_DEFAULT_RE.test(lineText))
|
|
150
|
+
continue;
|
|
151
|
+
if (DRIZZLE_DEFAULT_RE.test(lineText))
|
|
152
|
+
continue;
|
|
94
153
|
if (hasValidOptOut(lines, line - 1))
|
|
95
154
|
continue;
|
|
96
155
|
findings.push({
|
|
97
156
|
file: rel,
|
|
98
157
|
line,
|
|
99
|
-
message: `
|
|
158
|
+
message: `"local@localhost" used as a fallback identity: ${lineText.trim()}. Throw/401 on missing session instead — this pools every unauthenticated request onto one shared tenant.`,
|
|
100
159
|
});
|
|
101
160
|
}
|
|
102
161
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-localhost-fallback.js","sourceRoot":"","sources":["../../src/guards/no-localhost-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,QAAQ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al `local@localhost` (or the\n * `DEV_MODE_USER_EMAIL` symbolic alias) as a fallback identity when no\n * session is present — that pools every unauthenticated request onto one\n * shared tenant. The right behavior in production is to throw/401 when\n * there's no session, not fall back to a sentinel identity.\n *\n * Conditional guard — per report 005's V1 guard set table: the original\n * hardcodes framework-file exemptions (`packages/core/src/server/auth.ts`,\n * `packages/core/src/org/context.ts`, etc. — files that either define or\n * intentionally handle the dev-mode sentinel). Those live in `node_modules`\n * for a generated app and are already excluded by `SKIP_DIRS`, so they're\n * moved behind an optional `extraExemptPaths` param (default `[]`) instead\n * of hardcoded. The generic allowlist predicates (`*.spec.*`, `*.test.*`,\n * `scripts/**`, `**\\/seed(s)/**`) are kept verbatim.\n *\n * Opt-out (same line, or the line immediately above):\n * const x = email ?? \"local@localhost\" // guard:allow-localhost-fallback — short reason\n */\n\nimport {\n isCommentLine,\n lineColForOffset,\n readFileSafe,\n relPosix,\n walk,\n} from \"./scan-utils.js\";\nimport type { GuardFinding, GuardResult, GuardScanOptions } from \"./types.js\";\n\nexport interface LocalhostFallbackOptions extends GuardScanOptions {\n /** Exact repo-relative paths to exempt in addition to the generic\n * predicates (spec/test/scripts/seed). Default `[]`. */\n extraExemptPaths?: string[];\n}\n\nconst GENERIC_ALLOWED_PATH_PREDICATES: Array<(rel: string) => boolean> = [\n (rel) => /\\.spec\\.[tj]sx?$/.test(rel),\n (rel) => /\\.test\\.[tj]sx?$/.test(rel),\n (rel) => /^scripts\\//.test(rel),\n (rel) => /\\/seed\\//.test(rel),\n (rel) => /\\/seeds\\//.test(rel),\n];\n\nconst OPT_OUT_MARKER = /\\/\\/\\s*guard:allow-localhost-fallback\\b[^\\n]*/;\nconst OPT_OUT_REQUIRES_REASON =\n /\\/\\/\\s*guard:allow-localhost-fallback\\s*[—-]\\s*\\S/;\n\nconst LITERAL_RE = /(?:\"local@localhost\"|'local@localhost'|`local@localhost`)/g;\n\nconst SYMBOLIC_FALLBACK_RE = /(?:\\?\\?|\\|\\|)\\s*DEV_MODE_USER_EMAIL\\b/g;\n\nconst SQL_DEFAULT_RE = /\\bDEFAULT\\s+['\"`]local@localhost['\"`]/i;\nconst DRIZZLE_DEFAULT_RE = /\\.default\\s*\\(\\s*['\"`]local@localhost['\"`]\\s*\\)/;\n\nfunction isAllowedPath(rel: string, extraExemptPaths?: string[]): boolean {\n if (extraExemptPaths?.includes(rel)) return true;\n return GENERIC_ALLOWED_PATH_PREDICATES.some((p) => p(rel));\n}\n\nfunction hasValidOptOut(lines: string[], lineIdx: number): boolean {\n const cur = lines[lineIdx] ?? \"\";\n if (OPT_OUT_MARKER.test(cur)) {\n return OPT_OUT_REQUIRES_REASON.test(cur);\n }\n const prev = lines[lineIdx - 1] ?? \"\";\n if (/^\\s*\\/\\//.test(prev) && OPT_OUT_MARKER.test(prev)) {\n return OPT_OUT_REQUIRES_REASON.test(prev);\n }\n return false;\n}\n\nexport function scanLocalhostFallback(\n options: LocalhostFallbackOptions,\n): GuardResult {\n const { root, extraExemptPaths } = options;\n const findings: GuardFinding[] = [];\n\n for (const file of walk(root)) {\n if (!/\\.(ts|tsx|mts|cts|js|mjs|cjs)$/.test(file)) continue;\n if (file.endsWith(\".d.ts\")) continue;\n const rel = relPosix(root, file);\n if (isAllowedPath(rel, extraExemptPaths)) continue;\n\n const contents = readFileSafe(file);\n if (contents === null || !contents.includes(\"local@localhost\")) continue;\n\n const lines = contents.split(\"\\n\");\n\n LITERAL_RE.lastIndex = 0;\n let m: RegExpExecArray | null;\n while ((m = LITERAL_RE.exec(contents)) !== null) {\n const { line } = lineColForOffset(contents, m.index);\n const lineText = lines[line - 1] ?? \"\";\n if (isCommentLine(lineText)) continue;\n if (SQL_DEFAULT_RE.test(lineText)) continue;\n if (DRIZZLE_DEFAULT_RE.test(lineText)) continue;\n if (hasValidOptOut(lines, line - 1)) continue;\n findings.push({\n file: rel,\n line,\n message: `\"local@localhost\" used as a fallback identity: ${lineText.trim()}. Throw/401 on missing session instead — this pools every unauthenticated request onto one shared tenant.`,\n });\n }\n\n SYMBOLIC_FALLBACK_RE.lastIndex = 0;\n let s: RegExpExecArray | null;\n while ((s = SYMBOLIC_FALLBACK_RE.exec(contents)) !== null) {\n const { line } = lineColForOffset(contents, s.index);\n const lineText = lines[line - 1] ?? \"\";\n if (isCommentLine(lineText)) continue;\n if (hasValidOptOut(lines, line - 1)) continue;\n findings.push({\n file: rel,\n line,\n message: `DEV_MODE_USER_EMAIL used as a fallback identity: ${lineText.trim()}. Throw/401 on missing session instead.`,\n });\n }\n }\n\n return { name: \"no-localhost-fallback\", findings };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"no-localhost-fallback.js","sourceRoot":"","sources":["../../src/guards/no-localhost-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACR,IAAI,GACL,MAAM,iBAAiB,CAAC;AASzB,MAAM,+BAA+B,GAAoC;IACvE,CAAC,GAAG,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC;IACrC,CAAC,GAAG,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC;IACrC,CAAC,GAAG,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC;IAC/B,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC;IAC7B,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC;CAC/B,CAAC;AAEF,MAAM,cAAc,GAAG,+CAA+C,CAAC;AACvE,MAAM,uBAAuB,GAC3B,mDAAmD,CAAC;AAEtD,MAAM,UAAU,GAAG,4DAA4D,CAAC;AAEhF,MAAM,oBAAoB,GAAG,wCAAwC,CAAC;AAEtE;;;;;;;;;;GAUG;AACH,MAAM,uBAAuB,GAC3B,0GAA0G,CAAC;AAC7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BACT,IAAI;gBACJ,OAAO,EAAE,oDAAoD,QAAQ,CAAC,IAAI,EAAE,yCAAyC;aACtH,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,iBAAiB,CAAC;YAAE,SAAS;QAEpD,UAAU,CAAC,SAAS,GAAG,CAAC,CAAC;QACzB,IAAI,YAAoC,CAAC;QACzC,OAAO,CAAC,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YAC3D,MAAM,EAAE,IAAI,EAAE,GAAG,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;YAChE,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;YACvC,IAAI,aAAa,CAAC,QAAQ,CAAC;gBAAE,SAAS;YACtC,IAAI,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC;gBAAE,SAAS;YAC5C,IAAI,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC;gBAAE,SAAS;YAChD,IAAI,cAAc,CAAC,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC;gBAAE,SAAS;YAC9C,QAAQ,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,GAAG;gBACT,IAAI;gBACJ,OAAO,EAAE,kDAAkD,QAAQ,CAAC,IAAI,EAAE,2GAA2G;aACtL,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,uBAAuB,EAAE,QAAQ,EAAE,CAAC;AACrD,CAAC","sourcesContent":["/**\n * scanLocalhostFallback — ported from\n * `scripts/guard-no-localhost-fallback.mjs`.\n *\n * Refuse to let production code use the literal `local@localhost` (or the\n * `DEV_MODE_USER_EMAIL` symbolic alias) as a fallback identity when no\n * session is present — that pools every unauthenticated request onto one\n * shared tenant. The right behavior in production is to throw/401 when\n * there's no session, not fall back to a sentinel identity.\n *\n * Conditional guard — per report 005's V1 guard set table: the original\n * hardcodes framework-file exemptions (`packages/core/src/server/auth.ts`,\n * `packages/core/src/org/context.ts`, etc. — files that either define or\n * intentionally handle the dev-mode sentinel). Those live in `node_modules`\n * for a generated app and are already excluded by `SKIP_DIRS`, so they're\n * moved behind an optional `extraExemptPaths` param (default `[]`) instead\n * of hardcoded. The generic allowlist predicates (`*.spec.*`, `*.test.*`,\n * `scripts/**`, `**\\/seed(s)/**`) are kept verbatim.\n *\n * Also refuses to let request-handling code answer \"who is the caller\" with the\n * ambient process identity (`?? process.env.AGENT_USER_EMAIL`,\n * `|| process.env.WORKSPACE_OWNER_EMAIL`, `?? getAmbientUserEmail()`). That\n * shape fails open toward more privilege: an admin gate reading it admits\n * whoever the deploy env names rather than whoever signed in. CLI, cron, seed\n * and test paths are exempt because they have no request by construction.\n *\n * Opt-out (same line, or the line immediately above):\n * const x = email ?? \"local@localhost\" // guard:allow-localhost-fallback — short reason\n */\n\nimport {\n isCommentLine,\n lineColForOffset,\n readFileSafe,\n relPosix,\n walk,\n} from \"./scan-utils.js\";\nimport type { GuardFinding, GuardResult, GuardScanOptions } from \"./types.js\";\n\nexport interface LocalhostFallbackOptions extends GuardScanOptions {\n /** Exact repo-relative paths to exempt in addition to the generic\n * predicates (spec/test/scripts/seed). Default `[]`. */\n extraExemptPaths?: string[];\n}\n\nconst GENERIC_ALLOWED_PATH_PREDICATES: Array<(rel: string) => boolean> = [\n (rel) => /\\.spec\\.[tj]sx?$/.test(rel),\n (rel) => /\\.test\\.[tj]sx?$/.test(rel),\n (rel) => /^scripts\\//.test(rel),\n (rel) => /\\/seed\\//.test(rel),\n (rel) => /\\/seeds\\//.test(rel),\n];\n\nconst OPT_OUT_MARKER = /\\/\\/\\s*guard:allow-localhost-fallback\\b[^\\n]*/;\nconst OPT_OUT_REQUIRES_REASON =\n /\\/\\/\\s*guard:allow-localhost-fallback\\s*[—-]\\s*\\S/;\n\nconst LITERAL_RE = /(?:\"local@localhost\"|'local@localhost'|`local@localhost`)/g;\n\nconst SYMBOLIC_FALLBACK_RE = /(?:\\?\\?|\\|\\|)\\s*DEV_MODE_USER_EMAIL\\b/g;\n\n/**\n * Ambient process identity used as a request-scoped fallback:\n *\n * const email = getRequestUserEmail() ?? process.env.AGENT_USER_EMAIL;\n * const owner = session?.email || process.env.WORKSPACE_OWNER_EMAIL;\n *\n * These name the identity of the deployment, not the caller, so a request\n * handler reading one authorizes whoever the env names — failing open toward\n * more privilege. Only the `??` / `||` fallback position matches: reading the\n * same env var to build an admin allowlist asks a different, safe question.\n */\nconst AMBIENT_ENV_FALLBACK_RE =\n /(?:\\?\\?|\\|\\|)\\s*process\\.env\\.(?:AGENT_USER_EMAIL|AGENT_ORG_ID|AGENT_USER_NAME|WORKSPACE_OWNER_EMAIL)\\b/g;\nconst AMBIENT_HELPER_FALLBACK_RE =\n /(?:\\?\\?|\\|\\|)\\s*getAmbient(?:UserEmail|OrgId)\\s*\\(\\s*\\)/g;\n\n/** Paths where an ambient identity is correct because no request exists by\n * construction: CLI entrypoints, cron, seed and QA scripts, tests. */\nconst AMBIENT_ALLOWED_PATH_PREDICATES: Array<(rel: string) => boolean> = [\n (rel) => /(?:^|\\/)scripts\\//.test(rel),\n (rel) => /(?:^|\\/)src\\/cli\\//.test(rel),\n (rel) => /(?:^|\\/)src\\/scripts\\//.test(rel),\n (rel) => /(?:^|\\/)script-(?:helpers|entries)\\.ts$/.test(rel),\n (rel) => /\\.spec\\.[tj]sx?$/.test(rel),\n (rel) => /\\.test\\.[tj]sx?$/.test(rel),\n (rel) => /\\/seed\\//.test(rel),\n (rel) => /\\/seeds\\//.test(rel),\n];\n\nconst SQL_DEFAULT_RE = /\\bDEFAULT\\s+['\"`]local@localhost['\"`]/i;\nconst DRIZZLE_DEFAULT_RE = /\\.default\\s*\\(\\s*['\"`]local@localhost['\"`]\\s*\\)/;\n\nfunction isAllowedPath(rel: string, extraExemptPaths?: string[]): boolean {\n if (extraExemptPaths?.includes(rel)) return true;\n return GENERIC_ALLOWED_PATH_PREDICATES.some((p) => p(rel));\n}\n\nfunction hasValidOptOut(lines: string[], lineIdx: number): boolean {\n const cur = lines[lineIdx] ?? \"\";\n if (OPT_OUT_MARKER.test(cur)) {\n return OPT_OUT_REQUIRES_REASON.test(cur);\n }\n const prev = lines[lineIdx - 1] ?? \"\";\n if (/^\\s*\\/\\//.test(prev) && OPT_OUT_MARKER.test(prev)) {\n return OPT_OUT_REQUIRES_REASON.test(prev);\n }\n return false;\n}\n\nexport function scanLocalhostFallback(\n options: LocalhostFallbackOptions,\n): GuardResult {\n const { root, extraExemptPaths } = options;\n const findings: GuardFinding[] = [];\n\n for (const file of walk(root)) {\n if (!/\\.(ts|tsx|mts|cts|js|mjs|cjs)$/.test(file)) continue;\n if (file.endsWith(\".d.ts\")) continue;\n const rel = relPosix(root, file);\n const literalAllowed = isAllowedPath(rel, extraExemptPaths);\n const ambientAllowed = AMBIENT_ALLOWED_PATH_PREDICATES.some((p) => p(rel));\n if (literalAllowed && ambientAllowed) continue;\n\n const contents = readFileSafe(file);\n if (contents === null) continue;\n\n const lines = contents.split(\"\\n\");\n\n if (!ambientAllowed) {\n for (const re of [AMBIENT_ENV_FALLBACK_RE, AMBIENT_HELPER_FALLBACK_RE]) {\n re.lastIndex = 0;\n let a: RegExpExecArray | null;\n while ((a = re.exec(contents)) !== null) {\n const { line } = lineColForOffset(contents, a.index);\n const lineText = lines[line - 1] ?? \"\";\n if (isCommentLine(lineText)) continue;\n if (hasValidOptOut(lines, line - 1)) continue;\n findings.push({\n file: rel,\n line,\n message: `Ambient process identity used as a request-scoped fallback: ${lineText.trim()}. This authorizes whoever the deploy env names, not the signed-in user — fail closed on a missing caller, or call getAmbientUserEmail() from a CLI/cron path.`,\n });\n }\n }\n }\n\n if (literalAllowed) continue;\n\n // Scanned before the literal bail-out below: aliasing is exactly how this\n // shape hides in a file that never spells out the literal itself.\n SYMBOLIC_FALLBACK_RE.lastIndex = 0;\n let symbolicMatch: RegExpExecArray | null;\n while ((symbolicMatch = SYMBOLIC_FALLBACK_RE.exec(contents)) !== null) {\n const { line } = lineColForOffset(contents, symbolicMatch.index);\n const lineText = lines[line - 1] ?? \"\";\n if (isCommentLine(lineText)) continue;\n if (hasValidOptOut(lines, line - 1)) continue;\n findings.push({\n file: rel,\n line,\n message: `DEV_MODE_USER_EMAIL used as a fallback identity: ${lineText.trim()}. Throw/401 on missing session instead.`,\n });\n }\n\n if (!contents.includes(\"local@localhost\")) continue;\n\n LITERAL_RE.lastIndex = 0;\n let literalMatch: RegExpExecArray | null;\n while ((literalMatch = LITERAL_RE.exec(contents)) !== null) {\n const { line } = lineColForOffset(contents, literalMatch.index);\n const lineText = lines[line - 1] ?? \"\";\n if (isCommentLine(lineText)) continue;\n if (SQL_DEFAULT_RE.test(lineText)) continue;\n if (DRIZZLE_DEFAULT_RE.test(lineText)) continue;\n if (hasValidOptOut(lines, line - 1)) continue;\n findings.push({\n file: rel,\n line,\n message: `\"local@localhost\" used as a fallback identity: ${lineText.trim()}. Throw/401 on missing session instead — this pools every unauthenticated request onto one shared tenant.`,\n });\n }\n }\n\n return { name: \"no-localhost-fallback\", findings };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-docs-poller.d.ts","sourceRoot":"","sources":["../../src/integrations/google-docs-poller.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"google-docs-poller.d.ts","sourceRoot":"","sources":["../../src/integrations/google-docs-poller.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;AAmCtC,MAAM,WAAW,uBAAuB;IACtC,6EAA6E;IAC7E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACrC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,mBAAmB;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,yBAAyB;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,sEAAsE;IACtE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAWD;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAqExE;AAiMD;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAmCf;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAa5D;AAkLD;;;;;;;;;;GAUG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAmCf;AAgCD;;GAEG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAW1D"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createAnthropicEngine } from "../agent/engine/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { actionsToEngineTools, filterInitialEngineTools, } from "../agent/production-agent.js";
|
|
3
|
+
import { runAgentLoopDirectWithSoftTimeout } from "../agent/run-loop-with-resume.js";
|
|
3
4
|
import { startRun } from "../agent/run-manager.js";
|
|
4
5
|
import { buildAssistantMessage, extractThreadMeta, } from "../agent/thread-data-builder.js";
|
|
5
6
|
import { attachToolSearch } from "../agent/tool-search.js";
|
|
@@ -331,7 +332,11 @@ async function processComment(fileId, commentId, text, senderName, options, exis
|
|
|
331
332
|
const capturedThreadId = threadId;
|
|
332
333
|
const orgId = (await resolveOrgIdForEmail(options.ownerEmail)) ?? undefined;
|
|
333
334
|
startRun(runId, capturedThreadId, async (send, signal) => {
|
|
334
|
-
await runWithRequestContext({ userEmail: options.ownerEmail, orgId, isIntegrationCaller: true }, () =>
|
|
335
|
+
await runWithRequestContext({ userEmail: options.ownerEmail, orgId, isIntegrationCaller: true }, () =>
|
|
336
|
+
// Wrapper, not raw `runAgentLoop`: a doc-comment reply has no client
|
|
337
|
+
// driving continuation, so a transport-level cut has to be resumed
|
|
338
|
+
// inside this invocation or the commenter never gets an answer.
|
|
339
|
+
runAgentLoopDirectWithSoftTimeout({
|
|
335
340
|
engine,
|
|
336
341
|
model: options.model,
|
|
337
342
|
systemPrompt: options.systemPrompt,
|
|
@@ -341,7 +346,7 @@ async function processComment(fileId, commentId, text, senderName, options, exis
|
|
|
341
346
|
actions: runnableActions,
|
|
342
347
|
send,
|
|
343
348
|
signal,
|
|
344
|
-
}));
|
|
349
|
+
}, undefined, { useHostedDefault: true }));
|
|
345
350
|
}, async (completedRun) => {
|
|
346
351
|
try {
|
|
347
352
|
let responseText = "";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-docs-poller.js","sourceRoot":"","sources":["../../src/integrations/google-docs-poller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,wBAAwB,GAEzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAkB,MAAM,yBAAyB,CAAC;AACnE,OAAO,EACL,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACL,YAAY,EACZ,SAAS,EACT,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,E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,CAAC,CAAE,GAAW,EAAE,KAAK,IAAK,GAAW,EAAE,OAAO,IAAI,GAAG,CAAC,CAAC;YAC5D,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,MAAM,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACvB,cAAc,GAAG,WAAW,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAE/C,MAAM,KAAK,GAAG,sBAAsB,EAAE,CAAC;IACvC,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CACT,8CAA8C,UAAU,GAAG,IAAI,uBAAuB,KAAK,IAAI,gBAAgB,GAAG,CACnH,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,IAAI,cAAc,EAAE,CAAC;QACnB,aAAa,CAAC,cAAc,CAAC,CAAC;QAC9B,cAAc,GAAG,IAAI,CAAC;IACxB,CAAC;IACD,IAAI,iBAAiB,EAAE,CAAC;QACtB,YAAY,CAAC,iBAAiB,CAAC,CAAC;QAChC,iBAAiB,GAAG,IAAI,CAAC;IAC3B,CAAC;IACD,MAAM,SAAS,EAAE,CAAC;IAClB,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC","sourcesContent":["import { createAnthropicEngine } from \"../agent/engine/index.js\";\nimport type { EngineMessage } from \"../agent/engine/types.js\";\nimport {\n runAgentLoop,\n actionsToEngineTools,\n filterInitialEngineTools,\n type ActionEntry,\n} from \"../agent/production-agent.js\";\nimport { startRun, type ActiveRun } from \"../agent/run-manager.js\";\nimport {\n buildAssistantMessage,\n extractThreadMeta,\n} from \"../agent/thread-data-builder.js\";\nimport { attachToolSearch } from \"../agent/tool-search.js\";\nimport {\n createThread,\n getThread,\n updateThreadData,\n} from \"../chat-threads/store.js\";\nimport { resolveOrgIdForEmail } from \"../org/context.js\";\nimport { runWithRequestContext } from \"../server/request-context.js\";\nimport {\n getServiceAccountAccessToken,\n getServiceAccountEmail,\n getStartPageToken,\n googleDocsAdapter,\n listChanges,\n listDocComments,\n} from \"./adapters/google-docs.js\";\nimport { getIntegrationConfig, saveIntegrationConfig } from \"./config-store.js\";\nimport { getThreadMapping, saveThreadMapping } from \"./thread-mapping-store.js\";\nimport type { IncomingMessage } from \"./types.js\";\n\nconst PLATFORM = \"google-docs\";\nconst DEFAULT_TRIGGER = \"@agent\";\n\n/** Track processed comment IDs to avoid reprocessing */\nconst processedComments = new Set<string>();\n/** Track last-checked time per document for comment filtering */\nconst lastCheckedTimes = new Map<string, string>();\n\nexport interface GoogleDocsPollerOptions {\n /** Polling interval in milliseconds (fallback mode). Default: 30000 (30s) */\n intervalMs?: number;\n /** Trigger keyword in comments. Default: \"@agent\" (case-insensitive) */\n triggerKeyword?: string;\n /** System prompt for the agent */\n systemPrompt: string;\n /** Action entries for the agent */\n actions: Record<string, ActionEntry>;\n /**\n * Tool names to expose on the FIRST engine request. See\n * `WebhookHandlerOptions.initialToolNames` (`webhook-handler.ts`) — same\n * semantics, shared `actions` source from `createIntegrationsPlugin`. Omit\n * to keep the full `actions` set visible up front (current behavior).\n */\n initialToolNames?: string[];\n /** Model to use */\n model: string;\n /** Anthropic API key */\n apiKey: string;\n /** Thread owner email */\n ownerEmail: string;\n /** Webhook URL for push mode (set by plugin from WEBHOOK_BASE_URL) */\n webhookUrl?: string;\n}\n\nlet pollerInterval: ReturnType<typeof setInterval> | null = null;\nlet activeOptions: GoogleDocsPollerOptions | null = null;\n\n// ─── Watch Channel Management ───────────────────────────────────────────────\n\n/** How long a watch channel lasts (Google max is ~24h, we use 23h to renew early) */\nconst WATCH_CHANNEL_TTL_MS = 23 * 60 * 60 * 1000;\nlet watchRenewalTimer: ReturnType<typeof setTimeout> | null = null;\n\n/**\n * Register a Google Drive changes.watch channel so Google pushes\n * notifications to our webhook instead of us polling.\n *\n * Returns true if the watch was registered successfully.\n */\nexport async function registerWatch(webhookUrl: string): Promise<boolean> {\n const accessToken = await getServiceAccountAccessToken();\n if (!accessToken) return false;\n\n // Get the current page token as the starting point\n let pageToken = await getPageToken();\n if (!pageToken) {\n pageToken = await getStartPageToken(accessToken);\n await setPageToken(pageToken);\n }\n\n const channelId = `gdocs-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n const expiration = Date.now() + WATCH_CHANNEL_TTL_MS;\n\n try {\n const res = await fetch(\n \"https://www.googleapis.com/drive/v3/changes/watch\",\n {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${accessToken}`,\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n id: channelId,\n type: \"web_hook\",\n address: webhookUrl,\n expiration: expiration,\n payload: true,\n }),\n },\n );\n\n if (!res.ok) {\n const err = await res.text();\n console.error(\"[google-docs] Failed to register watch:\", err);\n return false;\n }\n\n const data = (await res.json()) as {\n id: string;\n resourceId: string;\n expiration: string;\n };\n\n // Save channel info for renewal and stopping\n await saveIntegrationConfig(\n PLATFORM,\n {\n channelId: data.id,\n resourceId: data.resourceId,\n expiration: data.expiration,\n webhookUrl,\n },\n \"watch-channel\",\n );\n\n console.log(\n `[google-docs] Watch registered (channel: ${data.id}, expires: ${new Date(parseInt(data.expiration)).toISOString()})`,\n );\n\n // Schedule renewal before expiration\n scheduleWatchRenewal(webhookUrl);\n\n return true;\n } catch (err) {\n console.error(\"[google-docs] Watch registration error:\", err);\n return false;\n }\n}\n\n/**\n * Stop an existing watch channel.\n */\nasync function stopWatch(): Promise<void> {\n const config = await getIntegrationConfig(PLATFORM, \"watch-channel\");\n if (!config?.configData?.channelId) return;\n\n const accessToken = await getServiceAccountAccessToken();\n if (!accessToken) return;\n\n try {\n await fetch(\"https://www.googleapis.com/drive/v3/channels/stop\", {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${accessToken}`,\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n id: config.configData.channelId,\n resourceId: config.configData.resourceId,\n }),\n });\n } catch {\n // Best effort — channel may have expired already\n }\n\n await saveIntegrationConfig(PLATFORM, {}, \"watch-channel\");\n}\n\n/**\n * Schedule automatic watch renewal before the channel expires.\n */\nfunction scheduleWatchRenewal(webhookUrl: string): void {\n if (watchRenewalTimer) clearTimeout(watchRenewalTimer);\n\n // Renew 1 hour before expiration\n const renewIn = WATCH_CHANNEL_TTL_MS - 60 * 60 * 1000;\n\n watchRenewalTimer = setTimeout(async () => {\n console.log(\"[google-docs] Renewing watch channel...\");\n await stopWatch();\n await registerWatch(webhookUrl);\n }, renewIn);\n}\n\n// ─── Page Token Management ──────────────────────────────────────────────────\n\nasync function getPageToken(): Promise<string | null> {\n const config = await getIntegrationConfig(PLATFORM, \"page-token\");\n return (config?.configData?.pageToken as string) ?? null;\n}\n\nasync function setPageToken(token: string): Promise<void> {\n await saveIntegrationConfig(PLATFORM, { pageToken: token }, \"page-token\");\n}\n\n// ─── Comment Detection ──────────────────────────────────────────────────────\n\nfunction isAgentMention(commentText: string, triggerKeyword: string): boolean {\n return commentText.toLowerCase().includes(triggerKeyword.toLowerCase());\n}\n\nfunction commentKey(fileId: string, commentId: string): string {\n return `${fileId}:${commentId}`;\n}\n\n/**\n * Check a single document for new agent-directed comments.\n */\nasync function checkDocumentComments(\n fileId: string,\n accessToken: string,\n options: GoogleDocsPollerOptions,\n): Promise<void> {\n const triggerKeyword = options.triggerKeyword ?? DEFAULT_TRIGGER;\n const serviceEmail = getServiceAccountEmail();\n\n const lastChecked = lastCheckedTimes.get(fileId);\n const comments = await listDocComments(fileId, accessToken, lastChecked);\n const now = new Date().toISOString();\n\n for (const comment of comments) {\n if (comment.resolved) continue;\n\n const key = commentKey(fileId, comment.id);\n\n // Skip comments authored by the service account\n if (\n serviceEmail &&\n comment.author.emailAddress?.toLowerCase() === serviceEmail.toLowerCase()\n ) {\n continue;\n }\n\n const existingMapping = await getThreadMapping(PLATFORM, key);\n\n if (existingMapping) {\n // Durable per-reply dedup: the in-memory `processedComments` Set does not\n // survive serverless cold starts (see pending-tasks-store H3 note), which\n // would let already-answered replies be reprocessed and double-posted.\n // Persist processed reply ids in the existing SQL thread mapping instead.\n const persistedReplyIds =\n existingMapping.platformContext.processedReplyIds;\n const processedReplyIds = new Set<string>(\n Array.isArray(persistedReplyIds) ? (persistedReplyIds as string[]) : [],\n );\n\n // Check for new follow-up replies from users\n const newUserReplies = (comment.replies ?? []).filter((r) => {\n if (\n serviceEmail &&\n r.author.emailAddress?.toLowerCase() === serviceEmail.toLowerCase()\n ) {\n return false;\n }\n const replyKey = `${key}:reply:${r.id}`;\n if (processedReplyIds.has(r.id) || processedComments.has(replyKey))\n return false;\n if (!isAgentMention(r.content, triggerKeyword)) return false;\n return true;\n });\n\n for (const reply of newUserReplies) {\n const replyKey = `${key}:reply:${reply.id}`;\n processedComments.add(replyKey);\n processedReplyIds.add(reply.id);\n // Persist immediately so a crash/cold-start between replies cannot\n // re-answer this reply on the next invocation.\n await saveThreadMapping(\n PLATFORM,\n key,\n existingMapping.internalThreadId,\n {\n ...existingMapping.platformContext,\n processedReplyIds: Array.from(processedReplyIds),\n },\n );\n\n const text = reply.content\n .replace(\n new RegExp(\n triggerKeyword.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"),\n \"gi\",\n ),\n \"\",\n )\n .trim();\n\n await processComment(\n fileId,\n comment.id,\n text,\n reply.author.displayName,\n options,\n existingMapping.internalThreadId,\n );\n }\n continue;\n }\n\n // New comment — check if it mentions the agent\n if (!isAgentMention(comment.content, triggerKeyword)) continue;\n\n processedComments.add(key);\n\n let text = comment.content;\n if (comment.quotedFileContent?.value) {\n text = `[Highlighted text: \"${comment.quotedFileContent.value}\"]\\n\\n${text}`;\n }\n\n text = text\n .replace(\n new RegExp(triggerKeyword.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"), \"gi\"),\n \"\",\n )\n .trim();\n\n await processComment(\n fileId,\n comment.id,\n text,\n comment.author.displayName,\n options,\n );\n }\n\n lastCheckedTimes.set(fileId, now);\n}\n\n// ─── Process Changes ────────────────────────────────────────────────────────\n\n/**\n * Process pending Drive changes — called by both push notifications and polling.\n * Fetches changes since the last page token, finds Google Docs that changed,\n * and checks their comments for agent mentions.\n */\nexport async function processChanges(\n options: GoogleDocsPollerOptions,\n): Promise<void> {\n const accessToken = await getServiceAccountAccessToken();\n if (!accessToken) return;\n\n let pageToken = await getPageToken();\n if (!pageToken) {\n pageToken = await getStartPageToken(accessToken);\n await setPageToken(pageToken);\n return; // First run — just save the cursor\n }\n\n const { changes, nextPageToken } = await listChanges(pageToken, accessToken);\n await setPageToken(nextPageToken);\n\n if (changes.length === 0) return;\n\n // Deduplicate and filter to Google Docs\n const docFileIds = new Set<string>();\n for (const change of changes) {\n if (change.removed) continue;\n if (\n change.file?.mimeType === \"application/vnd.google-apps.document\" ||\n !change.file?.mimeType\n ) {\n docFileIds.add(change.fileId);\n }\n }\n\n for (const fileId of docFileIds) {\n try {\n await checkDocumentComments(fileId, accessToken, options);\n } catch (err) {\n console.error(`[google-docs] Error checking comments on ${fileId}:`, err);\n }\n }\n}\n\n/**\n * Handle a push notification from Google Drive changes.watch.\n * Called from the integration webhook route.\n */\nexport async function handlePushNotification(): Promise<void> {\n if (!activeOptions) {\n console.warn(\n \"[google-docs] Push notification received but poller not configured\",\n );\n return;\n }\n\n try {\n await processChanges(activeOptions);\n } catch (err) {\n console.error(\"[google-docs] Error processing push notification:\", err);\n }\n}\n\n// ─── Agent Processing ───────────────────────────────────────────────────────\n\nasync function processComment(\n fileId: string,\n commentId: string,\n text: string,\n senderName: string,\n options: GoogleDocsPollerOptions,\n existingThreadId?: string,\n): Promise<void> {\n const adapter = googleDocsAdapter();\n const key = commentKey(fileId, commentId);\n\n const incoming: IncomingMessage = {\n platform: PLATFORM,\n externalThreadId: key,\n text,\n senderName,\n platformContext: { fileId, commentId },\n timestamp: Date.now(),\n };\n\n let threadId = existingThreadId;\n if (!threadId) {\n const thread = await createThread(options.ownerEmail, {\n title: `Google Doc: ${senderName}`,\n });\n await saveThreadMapping(PLATFORM, key, thread.id, { fileId, commentId });\n threadId = thread.id;\n }\n\n const thread = await getThread(threadId);\n const existingMessages: EngineMessage[] = [];\n if (thread?.threadData) {\n try {\n const data = JSON.parse(thread.threadData);\n if (Array.isArray(data.messages)) {\n for (const msg of data.messages) {\n const m = msg.message ?? msg;\n const textContent =\n typeof m.content === \"string\"\n ? m.content\n : Array.isArray(m.content)\n ? m.content\n .filter((c: any) => c.type === \"text\")\n .map((c: any) => c.text)\n .join(\"\\n\")\n : \"\";\n if (m.role === \"user\") {\n existingMessages.push({\n role: \"user\",\n content: [{ type: \"text\", text: textContent }],\n });\n } else if (m.role === \"assistant\") {\n existingMessages.push({\n role: \"assistant\",\n content: [{ type: \"text\", text: textContent }],\n });\n }\n }\n }\n } catch {}\n }\n\n const messages: EngineMessage[] = [\n ...existingMessages,\n { role: \"user\", content: [{ type: \"text\", text }] },\n ];\n\n const engine = createAnthropicEngine({ apiKey: options.apiKey });\n // Attach tool-search on a shallow copy so framework additions merged in by\n // `createIntegrationsPlugin` (integration memory, `call-agent`) can be\n // deferred behind it without mutating the plugin's long-lived registry.\n // `runAgentLoop`'s `expandActiveTools` re-expands from `availableTools`\n // after a tool-search call, so anything filtered out of the initial\n // `tools` list stays reachable.\n const runnableActions = attachToolSearch({ ...options.actions });\n const availableTools = actionsToEngineTools(runnableActions);\n const tools = filterInitialEngineTools(\n availableTools,\n options.initialToolNames,\n );\n const runId = `gdocs-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n const capturedThreadId = threadId;\n const orgId = (await resolveOrgIdForEmail(options.ownerEmail)) ?? undefined;\n\n startRun(\n runId,\n capturedThreadId,\n async (send, signal) => {\n await runWithRequestContext(\n { userEmail: options.ownerEmail, orgId, isIntegrationCaller: true },\n () =>\n runAgentLoop({\n engine,\n model: options.model,\n systemPrompt: options.systemPrompt,\n tools,\n availableTools,\n messages,\n actions: runnableActions,\n send,\n signal,\n }),\n );\n },\n async (completedRun: ActiveRun) => {\n try {\n let responseText = \"\";\n for (const runEvent of completedRun.events) {\n if (runEvent.event.type === \"text\") {\n responseText += runEvent.event.text;\n }\n }\n if (!responseText.trim()) responseText = \"(No response)\";\n\n const outgoing = adapter.formatAgentResponse(responseText);\n await adapter.sendResponse(outgoing, incoming);\n await persistThreadData(capturedThreadId, text, completedRun, thread);\n } catch (err) {\n console.error(\"[google-docs] Error sending response:\", err);\n }\n },\n );\n}\n\nasync function persistThreadData(\n threadId: string,\n userText: string,\n completedRun: ActiveRun,\n thread: any,\n): Promise<void> {\n try {\n let repo: any;\n try {\n repo = JSON.parse(thread?.threadData || \"{}\");\n } catch {\n repo = {};\n }\n if (!Array.isArray(repo.messages)) repo.messages = [];\n\n repo.messages.push({\n id: `msg-${Date.now()}-user`,\n role: \"user\",\n content: [{ type: \"text\", text: userText }],\n createdAt: new Date().toISOString(),\n });\n\n const assistantMsg = buildAssistantMessage(\n completedRun.events ?? [],\n completedRun.runId,\n );\n if (assistantMsg) repo.messages.push(assistantMsg);\n\n const meta = extractThreadMeta(repo);\n await updateThreadData(\n threadId,\n JSON.stringify(repo),\n meta.title || thread?.title || \"Google Doc Comment\",\n meta.preview || thread?.preview || \"\",\n repo.messages.length,\n );\n } catch {\n // Best-effort\n }\n}\n\n// ─── Poller (Hybrid: Push Primary, Poll Fallback) ───────────────────────────\n\n/**\n * Start the Google Docs integration.\n *\n * Hybrid approach:\n * 1. Attempts to register a Google Drive changes.watch webhook for\n * near-instant push notifications (~seconds latency)\n * 2. Falls back to polling if the watch registration fails\n * (e.g. domain not verified, local dev)\n * 3. Even in push mode, polls at a slow interval (5min) as a safety net\n * in case a push notification is missed\n */\nexport async function startGoogleDocsPoller(\n options: GoogleDocsPollerOptions,\n): Promise<void> {\n if (pollerInterval) {\n console.warn(\"[google-docs] Already running\");\n return;\n }\n\n activeOptions = options;\n\n // Check if integration is enabled before trying to register watch\n const config = await getIntegrationConfig(PLATFORM);\n if (!config?.configData?.enabled) {\n // Still start the poll loop so it picks up when enabled later\n startPollLoop(options, options.intervalMs ?? 30_000);\n return;\n }\n\n // Try to register push notifications\n const webhookUrl = options.webhookUrl;\n let pushMode = false;\n\n if (webhookUrl) {\n pushMode = await registerWatch(webhookUrl);\n if (pushMode) {\n console.log(\"[google-docs] Push mode active — using Drive webhooks\");\n // In push mode, still poll slowly as a safety net (every 5 min)\n startPollLoop(options, 5 * 60 * 1000);\n }\n }\n\n if (!pushMode) {\n console.log(\n \"[google-docs] Polling mode — push registration failed or no webhook URL\",\n );\n startPollLoop(options, options.intervalMs ?? 30_000);\n }\n}\n\nfunction startPollLoop(\n options: GoogleDocsPollerOptions,\n intervalMs: number,\n): void {\n async function poll() {\n try {\n const config = await getIntegrationConfig(PLATFORM);\n if (!config?.configData?.enabled) return;\n await processChanges(options);\n } catch (err) {\n // Unwrap ErrorEvent (Neon WS driver emits these on network failure) so logs show the real cause\n const detail =\n err instanceof Error\n ? err\n : ((err as any)?.error ?? (err as any)?.message ?? err);\n console.error(\"[google-docs] Poller error:\", detail);\n }\n }\n\n setTimeout(poll, 5000);\n pollerInterval = setInterval(poll, intervalMs);\n\n const email = getServiceAccountEmail();\n if (process.env.DEBUG) {\n console.log(\n `[google-docs] Poll loop started (interval: ${intervalMs / 1000}s, service account: ${email ?? \"not configured\"})`,\n );\n }\n}\n\n/**\n * Stop the Google Docs integration.\n */\nexport async function stopGoogleDocsPoller(): Promise<void> {\n if (pollerInterval) {\n clearInterval(pollerInterval);\n pollerInterval = null;\n }\n if (watchRenewalTimer) {\n clearTimeout(watchRenewalTimer);\n watchRenewalTimer = null;\n }\n await stopWatch();\n activeOptions = null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"google-docs-poller.js","sourceRoot":"","sources":["../../src/integrations/google-docs-poller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,EACL,oBAAoB,EACpB,wBAAwB,GAEzB,MAAM,8BAA8B,CA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iB,CAAC,CAAC;QAChC,iBAAiB,GAAG,IAAI,CAAC;IAC3B,CAAC;IACD,MAAM,SAAS,EAAE,CAAC;IAClB,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC","sourcesContent":["import { createAnthropicEngine } from \"../agent/engine/index.js\";\nimport type { EngineMessage } from \"../agent/engine/types.js\";\nimport {\n actionsToEngineTools,\n filterInitialEngineTools,\n type ActionEntry,\n} from \"../agent/production-agent.js\";\nimport { runAgentLoopDirectWithSoftTimeout } from \"../agent/run-loop-with-resume.js\";\nimport { startRun, type ActiveRun } from \"../agent/run-manager.js\";\nimport {\n buildAssistantMessage,\n extractThreadMeta,\n} from \"../agent/thread-data-builder.js\";\nimport { attachToolSearch } from \"../agent/tool-search.js\";\nimport {\n createThread,\n getThread,\n updateThreadData,\n} from \"../chat-threads/store.js\";\nimport { resolveOrgIdForEmail } from \"../org/context.js\";\nimport { runWithRequestContext } from \"../server/request-context.js\";\nimport {\n getServiceAccountAccessToken,\n getServiceAccountEmail,\n getStartPageToken,\n googleDocsAdapter,\n listChanges,\n listDocComments,\n} from \"./adapters/google-docs.js\";\nimport { getIntegrationConfig, saveIntegrationConfig } from \"./config-store.js\";\nimport { getThreadMapping, saveThreadMapping } from \"./thread-mapping-store.js\";\nimport type { IncomingMessage } from \"./types.js\";\n\nconst PLATFORM = \"google-docs\";\nconst DEFAULT_TRIGGER = \"@agent\";\n\n/** Track processed comment IDs to avoid reprocessing */\nconst processedComments = new Set<string>();\n/** Track last-checked time per document for comment filtering */\nconst lastCheckedTimes = new Map<string, string>();\n\nexport interface GoogleDocsPollerOptions {\n /** Polling interval in milliseconds (fallback mode). Default: 30000 (30s) */\n intervalMs?: number;\n /** Trigger keyword in comments. Default: \"@agent\" (case-insensitive) */\n triggerKeyword?: string;\n /** System prompt for the agent */\n systemPrompt: string;\n /** Action entries for the agent */\n actions: Record<string, ActionEntry>;\n /**\n * Tool names to expose on the FIRST engine request. See\n * `WebhookHandlerOptions.initialToolNames` (`webhook-handler.ts`) — same\n * semantics, shared `actions` source from `createIntegrationsPlugin`. Omit\n * to keep the full `actions` set visible up front (current behavior).\n */\n initialToolNames?: string[];\n /** Model to use */\n model: string;\n /** Anthropic API key */\n apiKey: string;\n /** Thread owner email */\n ownerEmail: string;\n /** Webhook URL for push mode (set by plugin from WEBHOOK_BASE_URL) */\n webhookUrl?: string;\n}\n\nlet pollerInterval: ReturnType<typeof setInterval> | null = null;\nlet activeOptions: GoogleDocsPollerOptions | null = null;\n\n// ─── Watch Channel Management ───────────────────────────────────────────────\n\n/** How long a watch channel lasts (Google max is ~24h, we use 23h to renew early) */\nconst WATCH_CHANNEL_TTL_MS = 23 * 60 * 60 * 1000;\nlet watchRenewalTimer: ReturnType<typeof setTimeout> | null = null;\n\n/**\n * Register a Google Drive changes.watch channel so Google pushes\n * notifications to our webhook instead of us polling.\n *\n * Returns true if the watch was registered successfully.\n */\nexport async function registerWatch(webhookUrl: string): Promise<boolean> {\n const accessToken = await getServiceAccountAccessToken();\n if (!accessToken) return false;\n\n // Get the current page token as the starting point\n let pageToken = await getPageToken();\n if (!pageToken) {\n pageToken = await getStartPageToken(accessToken);\n await setPageToken(pageToken);\n }\n\n const channelId = `gdocs-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n const expiration = Date.now() + WATCH_CHANNEL_TTL_MS;\n\n try {\n const res = await fetch(\n \"https://www.googleapis.com/drive/v3/changes/watch\",\n {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${accessToken}`,\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n id: channelId,\n type: \"web_hook\",\n address: webhookUrl,\n expiration: expiration,\n payload: true,\n }),\n },\n );\n\n if (!res.ok) {\n const err = await res.text();\n console.error(\"[google-docs] Failed to register watch:\", err);\n return false;\n }\n\n const data = (await res.json()) as {\n id: string;\n resourceId: string;\n expiration: string;\n };\n\n // Save channel info for renewal and stopping\n await saveIntegrationConfig(\n PLATFORM,\n {\n channelId: data.id,\n resourceId: data.resourceId,\n expiration: data.expiration,\n webhookUrl,\n },\n \"watch-channel\",\n );\n\n console.log(\n `[google-docs] Watch registered (channel: ${data.id}, expires: ${new Date(parseInt(data.expiration)).toISOString()})`,\n );\n\n // Schedule renewal before expiration\n scheduleWatchRenewal(webhookUrl);\n\n return true;\n } catch (err) {\n console.error(\"[google-docs] Watch registration error:\", err);\n return false;\n }\n}\n\n/**\n * Stop an existing watch channel.\n */\nasync function stopWatch(): Promise<void> {\n const config = await getIntegrationConfig(PLATFORM, \"watch-channel\");\n if (!config?.configData?.channelId) return;\n\n const accessToken = await getServiceAccountAccessToken();\n if (!accessToken) return;\n\n try {\n await fetch(\"https://www.googleapis.com/drive/v3/channels/stop\", {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${accessToken}`,\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n id: config.configData.channelId,\n resourceId: config.configData.resourceId,\n }),\n });\n } catch {\n // Best effort — channel may have expired already\n }\n\n await saveIntegrationConfig(PLATFORM, {}, \"watch-channel\");\n}\n\n/**\n * Schedule automatic watch renewal before the channel expires.\n */\nfunction scheduleWatchRenewal(webhookUrl: string): void {\n if (watchRenewalTimer) clearTimeout(watchRenewalTimer);\n\n // Renew 1 hour before expiration\n const renewIn = WATCH_CHANNEL_TTL_MS - 60 * 60 * 1000;\n\n watchRenewalTimer = setTimeout(async () => {\n console.log(\"[google-docs] Renewing watch channel...\");\n await stopWatch();\n await registerWatch(webhookUrl);\n }, renewIn);\n}\n\n// ─── Page Token Management ──────────────────────────────────────────────────\n\nasync function getPageToken(): Promise<string | null> {\n const config = await getIntegrationConfig(PLATFORM, \"page-token\");\n return (config?.configData?.pageToken as string) ?? null;\n}\n\nasync function setPageToken(token: string): Promise<void> {\n await saveIntegrationConfig(PLATFORM, { pageToken: token }, \"page-token\");\n}\n\n// ─── Comment Detection ──────────────────────────────────────────────────────\n\nfunction isAgentMention(commentText: string, triggerKeyword: string): boolean {\n return commentText.toLowerCase().includes(triggerKeyword.toLowerCase());\n}\n\nfunction commentKey(fileId: string, commentId: string): string {\n return `${fileId}:${commentId}`;\n}\n\n/**\n * Check a single document for new agent-directed comments.\n */\nasync function checkDocumentComments(\n fileId: string,\n accessToken: string,\n options: GoogleDocsPollerOptions,\n): Promise<void> {\n const triggerKeyword = options.triggerKeyword ?? DEFAULT_TRIGGER;\n const serviceEmail = getServiceAccountEmail();\n\n const lastChecked = lastCheckedTimes.get(fileId);\n const comments = await listDocComments(fileId, accessToken, lastChecked);\n const now = new Date().toISOString();\n\n for (const comment of comments) {\n if (comment.resolved) continue;\n\n const key = commentKey(fileId, comment.id);\n\n // Skip comments authored by the service account\n if (\n serviceEmail &&\n comment.author.emailAddress?.toLowerCase() === serviceEmail.toLowerCase()\n ) {\n continue;\n }\n\n const existingMapping = await getThreadMapping(PLATFORM, key);\n\n if (existingMapping) {\n // Durable per-reply dedup: the in-memory `processedComments` Set does not\n // survive serverless cold starts (see pending-tasks-store H3 note), which\n // would let already-answered replies be reprocessed and double-posted.\n // Persist processed reply ids in the existing SQL thread mapping instead.\n const persistedReplyIds =\n existingMapping.platformContext.processedReplyIds;\n const processedReplyIds = new Set<string>(\n Array.isArray(persistedReplyIds) ? (persistedReplyIds as string[]) : [],\n );\n\n // Check for new follow-up replies from users\n const newUserReplies = (comment.replies ?? []).filter((r) => {\n if (\n serviceEmail &&\n r.author.emailAddress?.toLowerCase() === serviceEmail.toLowerCase()\n ) {\n return false;\n }\n const replyKey = `${key}:reply:${r.id}`;\n if (processedReplyIds.has(r.id) || processedComments.has(replyKey))\n return false;\n if (!isAgentMention(r.content, triggerKeyword)) return false;\n return true;\n });\n\n for (const reply of newUserReplies) {\n const replyKey = `${key}:reply:${reply.id}`;\n processedComments.add(replyKey);\n processedReplyIds.add(reply.id);\n // Persist immediately so a crash/cold-start between replies cannot\n // re-answer this reply on the next invocation.\n await saveThreadMapping(\n PLATFORM,\n key,\n existingMapping.internalThreadId,\n {\n ...existingMapping.platformContext,\n processedReplyIds: Array.from(processedReplyIds),\n },\n );\n\n const text = reply.content\n .replace(\n new RegExp(\n triggerKeyword.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"),\n \"gi\",\n ),\n \"\",\n )\n .trim();\n\n await processComment(\n fileId,\n comment.id,\n text,\n reply.author.displayName,\n options,\n existingMapping.internalThreadId,\n );\n }\n continue;\n }\n\n // New comment — check if it mentions the agent\n if (!isAgentMention(comment.content, triggerKeyword)) continue;\n\n processedComments.add(key);\n\n let text = comment.content;\n if (comment.quotedFileContent?.value) {\n text = `[Highlighted text: \"${comment.quotedFileContent.value}\"]\\n\\n${text}`;\n }\n\n text = text\n .replace(\n new RegExp(triggerKeyword.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"), \"gi\"),\n \"\",\n )\n .trim();\n\n await processComment(\n fileId,\n comment.id,\n text,\n comment.author.displayName,\n options,\n );\n }\n\n lastCheckedTimes.set(fileId, now);\n}\n\n// ─── Process Changes ────────────────────────────────────────────────────────\n\n/**\n * Process pending Drive changes — called by both push notifications and polling.\n * Fetches changes since the last page token, finds Google Docs that changed,\n * and checks their comments for agent mentions.\n */\nexport async function processChanges(\n options: GoogleDocsPollerOptions,\n): Promise<void> {\n const accessToken = await getServiceAccountAccessToken();\n if (!accessToken) return;\n\n let pageToken = await getPageToken();\n if (!pageToken) {\n pageToken = await getStartPageToken(accessToken);\n await setPageToken(pageToken);\n return; // First run — just save the cursor\n }\n\n const { changes, nextPageToken } = await listChanges(pageToken, accessToken);\n await setPageToken(nextPageToken);\n\n if (changes.length === 0) return;\n\n // Deduplicate and filter to Google Docs\n const docFileIds = new Set<string>();\n for (const change of changes) {\n if (change.removed) continue;\n if (\n change.file?.mimeType === \"application/vnd.google-apps.document\" ||\n !change.file?.mimeType\n ) {\n docFileIds.add(change.fileId);\n }\n }\n\n for (const fileId of docFileIds) {\n try {\n await checkDocumentComments(fileId, accessToken, options);\n } catch (err) {\n console.error(`[google-docs] Error checking comments on ${fileId}:`, err);\n }\n }\n}\n\n/**\n * Handle a push notification from Google Drive changes.watch.\n * Called from the integration webhook route.\n */\nexport async function handlePushNotification(): Promise<void> {\n if (!activeOptions) {\n console.warn(\n \"[google-docs] Push notification received but poller not configured\",\n );\n return;\n }\n\n try {\n await processChanges(activeOptions);\n } catch (err) {\n console.error(\"[google-docs] Error processing push notification:\", err);\n }\n}\n\n// ─── Agent Processing ───────────────────────────────────────────────────────\n\nasync function processComment(\n fileId: string,\n commentId: string,\n text: string,\n senderName: string,\n options: GoogleDocsPollerOptions,\n existingThreadId?: string,\n): Promise<void> {\n const adapter = googleDocsAdapter();\n const key = commentKey(fileId, commentId);\n\n const incoming: IncomingMessage = {\n platform: PLATFORM,\n externalThreadId: key,\n text,\n senderName,\n platformContext: { fileId, commentId },\n timestamp: Date.now(),\n };\n\n let threadId = existingThreadId;\n if (!threadId) {\n const thread = await createThread(options.ownerEmail, {\n title: `Google Doc: ${senderName}`,\n });\n await saveThreadMapping(PLATFORM, key, thread.id, { fileId, commentId });\n threadId = thread.id;\n }\n\n const thread = await getThread(threadId);\n const existingMessages: EngineMessage[] = [];\n if (thread?.threadData) {\n try {\n const data = JSON.parse(thread.threadData);\n if (Array.isArray(data.messages)) {\n for (const msg of data.messages) {\n const m = msg.message ?? msg;\n const textContent =\n typeof m.content === \"string\"\n ? m.content\n : Array.isArray(m.content)\n ? m.content\n .filter((c: any) => c.type === \"text\")\n .map((c: any) => c.text)\n .join(\"\\n\")\n : \"\";\n if (m.role === \"user\") {\n existingMessages.push({\n role: \"user\",\n content: [{ type: \"text\", text: textContent }],\n });\n } else if (m.role === \"assistant\") {\n existingMessages.push({\n role: \"assistant\",\n content: [{ type: \"text\", text: textContent }],\n });\n }\n }\n }\n } catch {}\n }\n\n const messages: EngineMessage[] = [\n ...existingMessages,\n { role: \"user\", content: [{ type: \"text\", text }] },\n ];\n\n const engine = createAnthropicEngine({ apiKey: options.apiKey });\n // Attach tool-search on a shallow copy so framework additions merged in by\n // `createIntegrationsPlugin` (integration memory, `call-agent`) can be\n // deferred behind it without mutating the plugin's long-lived registry.\n // `runAgentLoop`'s `expandActiveTools` re-expands from `availableTools`\n // after a tool-search call, so anything filtered out of the initial\n // `tools` list stays reachable.\n const runnableActions = attachToolSearch({ ...options.actions });\n const availableTools = actionsToEngineTools(runnableActions);\n const tools = filterInitialEngineTools(\n availableTools,\n options.initialToolNames,\n );\n const runId = `gdocs-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n const capturedThreadId = threadId;\n const orgId = (await resolveOrgIdForEmail(options.ownerEmail)) ?? undefined;\n\n startRun(\n runId,\n capturedThreadId,\n async (send, signal) => {\n await runWithRequestContext(\n { userEmail: options.ownerEmail, orgId, isIntegrationCaller: true },\n () =>\n // Wrapper, not raw `runAgentLoop`: a doc-comment reply has no client\n // driving continuation, so a transport-level cut has to be resumed\n // inside this invocation or the commenter never gets an answer.\n runAgentLoopDirectWithSoftTimeout(\n {\n engine,\n model: options.model,\n systemPrompt: options.systemPrompt,\n tools,\n availableTools,\n messages,\n actions: runnableActions,\n send,\n signal,\n },\n undefined,\n { useHostedDefault: true },\n ),\n );\n },\n async (completedRun: ActiveRun) => {\n try {\n let responseText = \"\";\n for (const runEvent of completedRun.events) {\n if (runEvent.event.type === \"text\") {\n responseText += runEvent.event.text;\n }\n }\n if (!responseText.trim()) responseText = \"(No response)\";\n\n const outgoing = adapter.formatAgentResponse(responseText);\n await adapter.sendResponse(outgoing, incoming);\n await persistThreadData(capturedThreadId, text, completedRun, thread);\n } catch (err) {\n console.error(\"[google-docs] Error sending response:\", err);\n }\n },\n );\n}\n\nasync function persistThreadData(\n threadId: string,\n userText: string,\n completedRun: ActiveRun,\n thread: any,\n): Promise<void> {\n try {\n let repo: any;\n try {\n repo = JSON.parse(thread?.threadData || \"{}\");\n } catch {\n repo = {};\n }\n if (!Array.isArray(repo.messages)) repo.messages = [];\n\n repo.messages.push({\n id: `msg-${Date.now()}-user`,\n role: \"user\",\n content: [{ type: \"text\", text: userText }],\n createdAt: new Date().toISOString(),\n });\n\n const assistantMsg = buildAssistantMessage(\n completedRun.events ?? [],\n completedRun.runId,\n );\n if (assistantMsg) repo.messages.push(assistantMsg);\n\n const meta = extractThreadMeta(repo);\n await updateThreadData(\n threadId,\n JSON.stringify(repo),\n meta.title || thread?.title || \"Google Doc Comment\",\n meta.preview || thread?.preview || \"\",\n repo.messages.length,\n );\n } catch {\n // Best-effort\n }\n}\n\n// ─── Poller (Hybrid: Push Primary, Poll Fallback) ───────────────────────────\n\n/**\n * Start the Google Docs integration.\n *\n * Hybrid approach:\n * 1. Attempts to register a Google Drive changes.watch webhook for\n * near-instant push notifications (~seconds latency)\n * 2. Falls back to polling if the watch registration fails\n * (e.g. domain not verified, local dev)\n * 3. Even in push mode, polls at a slow interval (5min) as a safety net\n * in case a push notification is missed\n */\nexport async function startGoogleDocsPoller(\n options: GoogleDocsPollerOptions,\n): Promise<void> {\n if (pollerInterval) {\n console.warn(\"[google-docs] Already running\");\n return;\n }\n\n activeOptions = options;\n\n // Check if integration is enabled before trying to register watch\n const config = await getIntegrationConfig(PLATFORM);\n if (!config?.configData?.enabled) {\n // Still start the poll loop so it picks up when enabled later\n startPollLoop(options, options.intervalMs ?? 30_000);\n return;\n }\n\n // Try to register push notifications\n const webhookUrl = options.webhookUrl;\n let pushMode = false;\n\n if (webhookUrl) {\n pushMode = await registerWatch(webhookUrl);\n if (pushMode) {\n console.log(\"[google-docs] Push mode active — using Drive webhooks\");\n // In push mode, still poll slowly as a safety net (every 5 min)\n startPollLoop(options, 5 * 60 * 1000);\n }\n }\n\n if (!pushMode) {\n console.log(\n \"[google-docs] Polling mode — push registration failed or no webhook URL\",\n );\n startPollLoop(options, options.intervalMs ?? 30_000);\n }\n}\n\nfunction startPollLoop(\n options: GoogleDocsPollerOptions,\n intervalMs: number,\n): void {\n async function poll() {\n try {\n const config = await getIntegrationConfig(PLATFORM);\n if (!config?.configData?.enabled) return;\n await processChanges(options);\n } catch (err) {\n // Unwrap ErrorEvent (Neon WS driver emits these on network failure) so logs show the real cause\n const detail =\n err instanceof Error\n ? err\n : ((err as any)?.error ?? (err as any)?.message ?? err);\n console.error(\"[google-docs] Poller error:\", detail);\n }\n }\n\n setTimeout(poll, 5000);\n pollerInterval = setInterval(poll, intervalMs);\n\n const email = getServiceAccountEmail();\n if (process.env.DEBUG) {\n console.log(\n `[google-docs] Poll loop started (interval: ${intervalMs / 1000}s, service account: ${email ?? \"not configured\"})`,\n );\n }\n}\n\n/**\n * Stop the Google Docs integration.\n */\nexport async function stopGoogleDocsPoller(): Promise<void> {\n if (pollerInterval) {\n clearInterval(pollerInterval);\n pollerInterval = null;\n }\n if (watchRenewalTimer) {\n clearTimeout(watchRenewalTimer);\n watchRenewalTimer = null;\n }\n await stopWatch();\n activeOptions = null;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook-handler.d.ts","sourceRoot":"","sources":["../../src/integrations/webhook-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAElC,OAAO,EAIL,KAAK,mBAAmB,EAEzB,MAAM,6BAA6B,CAAC;AAerC,OAAO,KAAK,EAAE,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAOL,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"webhook-handler.d.ts","sourceRoot":"","sources":["../../src/integrations/webhook-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAElC,OAAO,EAIL,KAAK,mBAAmB,EAEzB,MAAM,6BAA6B,CAAC;AAerC,OAAO,KAAK,EAAE,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAOL,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;AAsDtC,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,KAA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AE,OAAO,GAAG,MAAM,CAgCrD;AAED;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,qBAAqB,EAC9B,eAAe,CAAC,EAAE;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC,GACA,OAAO,CAAC,4BAA4B,CAAC,CAmBvC;AAmqDD,wBAAsB,iCAAiC,CACrD,OAAO,EAAE,sCAAsC,EAC/C,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAsEf"}
|
|
@@ -5,8 +5,8 @@ import { formatLlmCredentialErrorMessage, isLlmCredentialError, } from "../agent
|
|
|
5
5
|
import { getConfiguredEngineNameForRequest, getStoredModelForEngine, normalizeModelForEngine, resolveEngine, } from "../agent/engine/index.js";
|
|
6
6
|
import { resolveMainChatMaxOutputTokens } from "../agent/engine/output-tokens.js";
|
|
7
7
|
import { PROVIDER_TO_ENV } from "../agent/engine/provider-env-vars.js";
|
|
8
|
-
import {
|
|
9
|
-
import { appendDurableContinuationContext } from "../agent/run-loop-with-resume.js";
|
|
8
|
+
import { actionsToEngineTools, filterInitialEngineTools, getOwnerActiveApiKey, getOwnerApiKey, engineToProvider, } from "../agent/production-agent.js";
|
|
9
|
+
import { appendDurableContinuationContext, runAgentLoopDirectWithSoftTimeout, } from "../agent/run-loop-with-resume.js";
|
|
10
10
|
import { startRun } from "../agent/run-manager.js";
|
|
11
11
|
import { buildCurrentTimeUserContext, buildRuntimeContextPrompt, } from "../agent/runtime-context.js";
|
|
12
12
|
import { buildAssistantMessage, extractThreadMeta, threadDataToEngineMessages, } from "../agent/thread-data-builder.js";
|
|
@@ -47,9 +47,19 @@ const INTEGRATION_CAMPAIGN_NO_PROGRESS_TIMEOUT_MS = 45_000;
|
|
|
47
47
|
* the loop itself emits one when it hits an internal step budget. The run's
|
|
48
48
|
* status is still "completed", so without this check a cut-off research request
|
|
49
49
|
* is reported to the user as a model that answered with nothing.
|
|
50
|
+
*
|
|
51
|
+
* Only the LAST terminal event decides: an in-invocation resume that recovered
|
|
52
|
+
* from an earlier boundary goes on to emit `done`, and that run did finish.
|
|
50
53
|
*/
|
|
51
54
|
function endedAtContinuationBoundary(run) {
|
|
52
|
-
|
|
55
|
+
for (let i = run.events.length - 1; i >= 0; i--) {
|
|
56
|
+
const event = run.events[i].event;
|
|
57
|
+
if (event.type === "auto_continue")
|
|
58
|
+
return true;
|
|
59
|
+
if (event.type === "done" || event.type === "error")
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
53
63
|
}
|
|
54
64
|
function continuationBoundaryReason(run) {
|
|
55
65
|
for (let index = run.events.length - 1; index >= 0; index -= 1) {
|
|
@@ -865,7 +875,12 @@ async function processIncomingMessage(incoming, options, opts = {}) {
|
|
|
865
875
|
model ??
|
|
866
876
|
engine.defaultModel;
|
|
867
877
|
const resolvedModel = normalizeModelForEngine(engine, modelCandidate);
|
|
868
|
-
|
|
878
|
+
// Wrapper, not raw `runAgentLoop`: an integration turn has no
|
|
879
|
+
// browser to re-POST a continuation, so a transport-level cut
|
|
880
|
+
// (gateway 45s, socket hang up, upstream 5xx) has to be resumed
|
|
881
|
+
// inside this invocation or the user's Slack thread just stops.
|
|
882
|
+
// Same budget the run-manager resolved for this run below.
|
|
883
|
+
usage = await runAgentLoopDirectWithSoftTimeout({
|
|
869
884
|
engine,
|
|
870
885
|
model: resolvedModel,
|
|
871
886
|
systemPrompt: effectiveSystemPrompt,
|
|
@@ -891,6 +906,9 @@ async function processIncomingMessage(incoming, options, opts = {}) {
|
|
|
891
906
|
// retry can step its reasoning effort down rather than
|
|
892
907
|
// repeatedly letting the engine choose Medium.
|
|
893
908
|
reasoningEffort: normalizeReasoningEffortForRequest(resolvedModel, undefined),
|
|
909
|
+
}, undefined, {
|
|
910
|
+
useHostedDefault: true,
|
|
911
|
+
backgroundFunction: isInBackgroundFunctionRuntime(),
|
|
894
912
|
});
|
|
895
913
|
return usage;
|
|
896
914
|
});
|