@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durable-background.js","sourceRoot":"","sources":["../../src/agent/durable-background.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,mCAAmC,CAAC;AAE3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GACtC,wCAAwC,CAAC;AAE3C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,yBAAyB,CAAC;AAExE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,uBAAuB,8BAA8B,EAAE,CAAC;AAE1G;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,wBAAwB,CAAC;AACzE,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,CAAC;AACpD,MAAM,CAAC,MAAM,sCAAsC,GAAG,aAAa,CAAC;AACpE,MAAM,CAAC,MAAM,gCAAgC,GAAG,OAAO,CAAC;AACxD,MAAM,CAAC,MAAM,sCAAsC,GACjD,6BAA6B,CAAC;AAEhC;;;;;;;;GAQG;AACH,SAAS,yCAAyC;IAChD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC;IACtD,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACzC,2EAA2E;IA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,CAAC;QAC7C,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;YAC7C,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,MAAM,EAAE,GAAG;gBACX,KAAK,EAAE,oCAAoC;gBAC3C,KAAK;aACN,CAAC;QACJ,CAAC;IACH,CAAC;SAAM,IAAI,CAAC,qBAAqB,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;QAChD,wEAAwE;QACxE,yEAAyE;QACzE,0EAA0E;QAC1E,gEAAgE;QAChE,OAAO;YACL,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,GAAG;YACX,KAAK,EACH,8IAA8I;YAChJ,KAAK;SACN,CAAC;IACJ,CAAC;IAED,qEAAqE;IACrE,wEAAwE;IACxE,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,MAAM,CAAC,+BAA+B,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC;IACtD,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC3C,CAAC","sourcesContent":["/**\n * Durable background agent-chat runs (Netlify background functions).\n *\n * Off by default. When enabled, a long in-app agent-chat turn is dispatched\n * into a Netlify *background* function (15-min budget) instead of completing\n * synchronously under the ~40s soft-timeout. The foreground POST claims the\n * run slot, inserts the run row, fires an HMAC-signed self-dispatch to\n * `AGENT_CHAT_PROCESS_RUN_PATH`, and returns the existing SSE subscription so\n * the client streams the same events (via the cross-isolate SQL-poll path)\n * with no client change.\n *\n * This module owns ONLY the gating decision + shared constants so both the\n * HTTP handler (`production-agent.ts`) and the processor route\n * (`agent-chat-plugin.ts`) agree on when the path is active without a circular\n * import. The actual run machinery is reused verbatim from run-manager /\n * run-store / self-dispatch / internal-token.\n *\n * GUARDRAIL: when `isAgentChatDurableBackgroundEnabled()` returns false, the\n * agent-chat handler must behave byte-for-byte like the current synchronous\n * path. The gate is true only when ALL of these hold:\n * 1. `AGENT_CHAT_DURABLE_BACKGROUND` env is explicitly enabled, or a\n * workspace app's agent-chat plugin opts in with `durableBackgroundRuns`\n * where the workspace deploy emits a per-app background function by\n * default. Single-template Netlify deploys must set the env flag because\n * that same flag controls whether `server-agent-background` is emitted.\n * 2. The runtime is hosted/serverless (local dev keeps the inline path so SSE\n * stays a single live stream and no second function is needed).\n * 3. `A2A_SECRET` is configured (the HMAC handoff is required to authenticate\n * the background dispatch; without it the dispatch can't be trusted).\n *\n * Opt-in keeps the blast radius small while the worker path is still being\n * proven. And even when enabled, a *dispatch failure degrades to an inline run*:\n * if the self-dispatch self-POST can't be delivered (fast connection error or\n * fast non-2xx), the foreground handler runs the turn synchronously instead of\n * erroring (see `production-agent.ts` — the inline fallback claims the run row\n * atomically so a delayed delivery can never double-execute). So an app where\n * durable dispatch happens to fail still gets a working chat, just without the\n * 15-min budget.\n */\nimport {\n hasConfiguredA2ASecret,\n isTrustedLocalRuntime,\n} from \"../a2a/auth-policy.js\";\nimport {\n extractBearerToken,\n verifyInternalToken,\n} from \"../integrations/internal-token.js\";\n\n/**\n * Framework route the background function actually runs — sibling to\n * `AGENT_TEAM_PROCESS_RUN_PATH`. Reached *through* the Netlify background\n * function, so it inherits the 15-min budget.\n */\nexport const AGENT_CHAT_PROCESS_RUN_PATH =\n \"/_agent-native/agent-chat/_process-run\";\n\n/**\n * Name of the standalone Netlify background function the build emits (see\n * `emitSingleTemplateNetlifyBackgroundFunction` in deploy/build.ts). Shared so\n * the emit and the dispatch-path helper below can never drift on the name.\n *\n * MUST end in `-background` — both because that is the conventional Netlify\n * async-function suffix and because `isInBackgroundFunctionRuntime()` reads the\n * `AWS_LAMBDA_FUNCTION_NAME` `-background` suffix as a secondary runtime signal.\n */\nexport const AGENT_BACKGROUND_FUNCTION_NAME = \"server-agent-background\";\n\n/**\n * Default function URL of the background function on Netlify. Every Netlify\n * function is reachable at `/.netlify/functions/<name>` BY DEFAULT; that default\n * url is removed ONLY if the function declares a custom `config.path`. The\n * emitted background function declares NO custom `config.path` (it sets\n * `background: true` and nothing else routing-related), so it KEEPS this default\n * url — and the Nitro `server` function already excludes `/.netlify/*` from its\n * `/*` catch-all, so this namespace is never shadowed. The foreground therefore\n * dispatches HERE on hosted Netlify (see `resolveAgentChatProcessRunDispatchPath`).\n */\nexport const AGENT_BACKGROUND_FUNCTION_URL_PATH = `/.netlify/functions/${AGENT_BACKGROUND_FUNCTION_NAME}`;\n\n/**\n * Marker carried in a Netlify background-function body when the shared\n * long-running worker should route to a processor other than agent chat.\n * The emitted wrapper defaults to the normal agent-chat `_process-run` route;\n * A2A uses this marker to reuse the same 15-minute function for async tasks.\n */\nexport const AGENT_BACKGROUND_PROCESSOR_FIELD = \"__agentNativeProcessor\";\nexport const AGENT_BACKGROUND_PROCESSOR_A2A = \"a2a\";\nexport const AGENT_BACKGROUND_PROCESSOR_INTEGRATION = \"integration\";\nexport const AGENT_BACKGROUND_PROCESSOR_ROUTE = \"route\";\nexport const AGENT_BACKGROUND_PROCESSOR_ROUTE_FIELD =\n \"__agentNativeProcessorRoute\";\n\n/**\n * The per-app workspace background function URL path. Workspace deploy emits one\n * background function per app named `<app>-agent-background`, reachable at its\n * DEFAULT url `/.netlify/functions/<app>-agent-background` (no custom\n * `config.path`). The foreground resolves the current workspace app id from\n * `AGENT_NATIVE_WORKSPACE_APP_ID` (set by the workspace function entry) so it can\n * dispatch to the right per-app function url. Returns `null` when no workspace\n * app id is configured (single-template deploy).\n */\nfunction resolveWorkspaceBackgroundFunctionUrlPath(): string | null {\n const raw = process.env.AGENT_NATIVE_WORKSPACE_APP_ID;\n if (typeof raw !== \"string\") return null;\n // Mirror the workspace app-id normalization (resources/store.ts): take the\n // first path segment and accept only the safe slug shape used for function\n // names. Anything else falls back to the single-template name.\n const candidate = raw.trim().replace(/^\\/+/, \"\").split(\"/\")[0] ?? \"\";\n if (!/^[a-z0-9][a-z0-9-]{0,127}$/.test(candidate)) return null;\n return `/.netlify/functions/${candidate}-agent-background`;\n}\n\nfunction isNetlifyHostedRuntimeForDispatch(): boolean {\n if (process.env.NETLIFY_LOCAL === \"true\") return false;\n if (process.env.NETLIFY === \"false\") return false;\n if (process.env.NETLIFY && process.env.NETLIFY !== \"false\") return true;\n // NETLIFY is a build-only read-only variable. In deployed Functions Netlify\n // documents URL, SITE_NAME, and SITE_ID as the runtime read-only variables;\n // SITE_ID is the unambiguous host marker. Lambda compatibility mode also\n // exposes AWS runtime variables, so keep the function-name fallback for older\n // deploys. Without either check a modern Netlify Function silently selects the\n // portable framework route even though the emitted background function exists.\n if (process.env.SITE_ID) return true; // guard:allow-env-credential -- Netlify's read-only public site identifier is a runtime host marker, not a user credential.\n // Non-Netlify AWS falls back inline if the /.netlify/functions dispatch\n // fast-fails.\n return Boolean(process.env.AWS_LAMBDA_FUNCTION_NAME);\n}\n\n/**\n * Resolve the path the foreground POST should self-dispatch the chat background\n * worker to.\n *\n * GROUNDED IN THE REAL NETLIFY BUILD OUTPUT + THE NETLIFY DOCS DEFAULT-URL RULE:\n * the background function is emitted INTO the scanned dir\n * (`.netlify/functions-internal/server-agent-background`, or per-app\n * `<app>-agent-background` for workspaces) with `export const config = {\n * background: true, ... }` and NO custom `config.path`. Because it has no custom\n * path, Netlify keeps its DEFAULT function url `/.netlify/functions/<name>`, and\n * `background: true` makes any invocation of that url ASYNC (immediate 202,\n * 15-min budget). The Nitro `server` function already excludes `/.netlify/*`\n * from its `/*` catch-all, so the default-url namespace is NEVER shadowed by the\n * synchronous function.\n *\n * Therefore on hosted Netlify the foreground dispatches to the function's DEFAULT\n * url (`/.netlify/functions/<name>`); the function entry then rewrites the\n * incoming pathname to `AGENT_CHAT_PROCESS_RUN_PATH` (base-path-prefixed for\n * workspaces) before delegating to the Nitro router, so the `_process-run`\n * plugin runs with the async 15-min budget. Everywhere else (local dev, `netlify\n * dev`, non-Netlify hosts where no second function exists) there is no second\n * function, so the foreground dispatches to the framework route\n * `AGENT_CHAT_PROCESS_RUN_PATH` and the same in-process catch-all handles it\n * inline. The HMAC token (signed over the runId) is unchanged either way.\n *\n * NOTE: this is the DOC-CORRECT approach. An earlier attempt gave the function a\n * custom `config.path` + a catch-all `excludedPath` patch; the custom path was\n * NOT honored as a route in prod (probe → 404). Using the default function url\n * (no custom path) is what Netlify documents and is simpler — there is nothing\n * to shadow because `/.netlify/*` is already excluded from the `server` catch-all.\n */\nexport function resolveAgentChatProcessRunDispatchPath(): string {\n if (isNetlifyHostedRuntimeForDispatch()) {\n return (\n resolveWorkspaceBackgroundFunctionUrlPath() ??\n AGENT_BACKGROUND_FUNCTION_URL_PATH\n );\n }\n return AGENT_CHAT_PROCESS_RUN_PATH;\n}\n\nexport function resolveDurableBackgroundDispatchPath(\n fallbackPath: string,\n): string {\n if (isNetlifyHostedRuntimeForDispatch()) {\n return (\n resolveWorkspaceBackgroundFunctionUrlPath() ??\n AGENT_BACKGROUND_FUNCTION_URL_PATH\n );\n }\n return fallbackPath;\n}\n\nexport function dispatchPathTargetsNetlifyBackgroundFunction(\n dispatchPath: string,\n): boolean {\n return dispatchPath.startsWith(\"/.netlify/functions/\");\n}\n\n/**\n * Env flag for durable background runs. DEFAULT-OFF (opt-in): unset means\n * disabled; an app opts IN with an explicit truthy value (`true`/`1`/`yes`/`on`).\n */\nexport const AGENT_CHAT_DURABLE_BACKGROUND_ENV =\n \"AGENT_CHAT_DURABLE_BACKGROUND\";\n\n/**\n * Body field the foreground handler injects when self-dispatching to the\n * background processor. Its presence is how the re-entered handler knows it is\n * the background worker (run inline with the background soft-timeout; do NOT\n * re-claim the slot or re-dispatch). Untrusted on its own — the route also\n * verifies the HMAC token before invoking the handler.\n */\nexport const AGENT_CHAT_BACKGROUND_RUN_FIELD = \"__backgroundRun\";\n\n/**\n * Mirror of run-manager's private `isHostedRuntime`. Kept in sync deliberately:\n * the durable-background gate must agree with the soft-timeout regime about\n * what \"hosted\" means.\n */\nexport function isHostedRuntimeForDurableBackground(): boolean {\n if (process.env.NETLIFY_LOCAL === \"true\") return false;\n if (process.env.NETLIFY === \"false\") return false;\n if (process.env.SITE_ID) return true; // guard:allow-env-credential -- Netlify's read-only public site identifier is a runtime host marker, not a user credential.\n if (\n process.env.NETLIFY &&\n process.env.NETLIFY !== \"false\" &&\n process.env.NETLIFY_LOCAL !== \"true\"\n ) {\n return true;\n }\n if (\n process.env.AWS_LAMBDA_FUNCTION_NAME &&\n process.env.NETLIFY_LOCAL !== \"true\"\n ) {\n return true;\n }\n return Boolean(\n process.env.CF_PAGES ||\n process.env.VERCEL ||\n process.env.VERCEL_ENV ||\n process.env.RENDER ||\n process.env.FLY_APP_NAME ||\n process.env.K_SERVICE,\n );\n}\n\n/**\n * True when THIS process is actually executing inside a Netlify *background*\n * function (the long, 15-min-budget async function whose deployed name ends in\n * `-background`). Netlify runs functions on AWS Lambda and sets\n * `AWS_LAMBDA_FUNCTION_NAME` to the function's name, so a `-background` suffix is\n * the runtime proof that the ~60s synchronous wall does NOT apply here.\n *\n * This is the SAFETY GUARD for the soft-timeout regime. The `_process-run`\n * self-dispatch worker (`isBackgroundWorker`) is NOT enough on its own: if the\n * `-background` function was never emitted (deploy gate off, or Netlify routed\n * the path to the synchronous function), the self-POST lands on the regular\n * ~60s `server` function. A worker there MUST use the 40s soft-timeout and\n * checkpoint before the 60s wall — using the ~13min budget would overshoot the\n * hard wall and get killed at 60s, then re-dispatch/resume in a wasteful loop.\n * So the 13-min budget is taken ONLY when this returns true.\n *\n * The PRIMARY signal is a `globalThis` marker the emitted background function's\n * entry sets at cold start — the deployed Lambda name is not guaranteed to end\n * in `-background` on Netlify, so the entry marks its own runtime. A `globalThis`\n * flag (not `process.env`) keeps the no-env-mutation guard satisfied and carries\n * no cross-request state (set once per isolate). The `AWS_LAMBDA_FUNCTION_NAME`\n * suffix and the explicit `AGENT_CHAT_FORCE_BACKGROUND_RUNTIME` env (truthy) are\n * additional signals — the latter an operator escape hatch. Off by default.\n */\nexport function isInBackgroundFunctionRuntime(): boolean {\n // Set by the emitted `-background` function entry at cold start (the primary,\n // most reliable signal — see the emit in deploy/build.ts).\n if (\n (globalThis as Record<string, unknown>)\n .__AGENT_NATIVE_BACKGROUND_RUNTIME__ === true\n ) {\n return true;\n }\n const lambdaName = process.env.AWS_LAMBDA_FUNCTION_NAME;\n if (\n typeof lambdaName === \"string\" &&\n lambdaName.toLowerCase().endsWith(\"-background\")\n ) {\n return true;\n }\n const forced = process.env.AGENT_CHAT_FORCE_BACKGROUND_RUNTIME;\n if (forced != null) {\n const v = forced.trim().toLowerCase();\n return v === \"1\" || v === \"true\" || v === \"yes\" || v === \"on\";\n }\n return false;\n}\n\nexport function backgroundRunMarkerExpectsBackgroundRuntime(\n marker: unknown,\n): boolean {\n return (\n typeof marker === \"object\" &&\n marker !== null &&\n (marker as { backgroundFunctionRuntimeExpected?: unknown })\n .backgroundFunctionRuntimeExpected === true\n );\n}\n\nexport function shouldUseBackgroundFunctionTimeoutForWorker(\n _marker: unknown,\n): boolean {\n // The dispatch marker says which URL the foreground targeted, not where the\n // request actually landed. Only the worker runtime proof can safely lift the\n // hosted 40s clamp to the 15-minute background-function budget.\n return isInBackgroundFunctionRuntime();\n}\n\nexport function backgroundRuntimeDiagnosticDetail(marker: unknown): string {\n return [\n `markerExpected=${backgroundRunMarkerExpectsBackgroundRuntime(marker)}`,\n `runtimeDetected=${isInBackgroundFunctionRuntime()}`,\n `globalMarker=${(globalThis as Record<string, unknown>).__AGENT_NATIVE_BACKGROUND_RUNTIME__ === true}`,\n `lambdaNameEndsBackground=${typeof process.env.AWS_LAMBDA_FUNCTION_NAME === \"string\" && process.env.AWS_LAMBDA_FUNCTION_NAME.toLowerCase().endsWith(\"-background\")}`,\n `forceEnv=${typeof process.env.AGENT_CHAT_FORCE_BACKGROUND_RUNTIME === \"string\" && process.env.AGENT_CHAT_FORCE_BACKGROUND_RUNTIME.trim().length > 0}`,\n ].join(\" \");\n}\n\nfunction isFlagEnabled(): boolean {\n // Read the literal key (not `process.env[CONST]`) so guard:no-env-credentials\n // can statically verify it against the allowlisted `AGENT_*` prefix. Keep this\n // in sync with AGENT_CHAT_DURABLE_BACKGROUND_ENV.\n //\n // DEFAULT-OFF (opt-in): durable background runs are still being hardened. A\n // premature fleet-wide default-on caused real-user incidents (Assets/Analytics\n // hit \"Failed to dispatch\" + stalls, 2026-06-24) because the async background\n // worker path is not yet proven end-to-end and the deploy-time env opt-out is\n // not reliably baked into a given deploy. So an unset/empty/unknown flag means\n // OFF; an app opts IN only with an explicit truthy value\n // (AGENT_CHAT_DURABLE_BACKGROUND=true). This still composes with the hosted +\n // A2A_SECRET gates below. Flip back to default-on only after the 15-min\n // background-function worker is verified live in production (see the\n // project_durable_bg_prod_verified memory).\n const raw = process.env.AGENT_CHAT_DURABLE_BACKGROUND;\n if (raw == null) return false;\n const normalized = raw.trim().toLowerCase();\n return (\n normalized === \"1\" ||\n normalized === \"true\" ||\n normalized === \"yes\" ||\n normalized === \"on\"\n );\n}\n\nfunction isFlagExplicitlyDisabled(): boolean {\n const raw = process.env.AGENT_CHAT_DURABLE_BACKGROUND;\n if (raw == null) return false;\n const normalized = raw.trim().toLowerCase();\n return (\n normalized === \"0\" ||\n normalized === \"false\" ||\n normalized === \"no\" ||\n normalized === \"off\"\n );\n}\n\n/**\n * The single gate. True when the env flag is explicitly enabled, or a workspace\n * app opted in and has a per-app background-function target, AND the runtime is\n * hosted AND A2A_SECRET is configured. False otherwise — and false means the\n * current synchronous behavior is used unchanged. Single-template Netlify app\n * opt-ins deliberately require the env flag too because that flag controls\n * whether the `server-agent-background` function exists in the deploy output.\n */\nexport function isAgentChatDurableBackgroundEnabled(options?: {\n appOptIn?: boolean;\n}): boolean {\n // An app-level opt-out must win over a stale deploy-wide env flag. Netlify\n // environment variables can outlive the source config that originally set\n // them; allowing that flag to re-enable a worker an app explicitly disabled\n // recreates the missing-background-function failure this gate is meant to\n // prevent.\n if (options?.appOptIn === false) return false;\n const envOptIn = isFlagEnabled();\n const workspaceAppOptIn =\n options?.appOptIn === true &&\n !isFlagExplicitlyDisabled() &&\n resolveWorkspaceBackgroundFunctionUrlPath() !== null;\n return (\n (envOptIn || workspaceAppOptIn) &&\n isHostedRuntimeForDurableBackground() &&\n hasConfiguredA2ASecret()\n );\n}\n\n/**\n * Env flag for the FOREGROUND server-driven self-chain. DEFAULT-OFF: a hosted\n * app must explicitly opt in with a truthy value (`true`/`1`/`yes`/`on`). A\n * regular Netlify function has a fixed 60-second wall, and a self-dispatched\n * successor can otherwise be killed before it persists its next continuation.\n * Keep this separate from `AGENT_CHAT_DURABLE_BACKGROUND` so the experimental\n * regular-function chain can be enabled independently after its deployment is\n * proven safe.\n */\nexport const AGENT_CHAT_FOREGROUND_SELF_CHAIN_ENV =\n \"AGENT_CHAT_FOREGROUND_SELF_CHAIN\";\n\nfunction isForegroundSelfChainExplicitlyEnabled(): boolean {\n // Read the literal key (not `process.env[CONST]`) so guard:no-env-credentials\n // can statically verify it against the allowlisted `AGENT_*` prefix. Keep this\n // in sync with AGENT_CHAT_FOREGROUND_SELF_CHAIN_ENV.\n const raw = process.env.AGENT_CHAT_FOREGROUND_SELF_CHAIN;\n if (raw == null) return false;\n const normalized = raw.trim().toLowerCase();\n return (\n normalized === \"1\" ||\n normalized === \"true\" ||\n normalized === \"yes\" ||\n normalized === \"on\"\n );\n}\n\n/**\n * Gate for the foreground self-chain: a normal (non-durable-background)\n * agent-chat turn that hits its soft-timeout chunk boundary continues via a\n * server-side self-dispatch on the REGULAR function (not a Netlify\n * `-background` function) instead of depending on the client to re-POST\n * `auto_continue`. Composes exactly like `isAgentChatDurableBackgroundEnabled`:\n * true only when the env flag is explicitly truthy, the runtime is hosted, and\n * `A2A_SECRET` is configured (the HMAC handoff authenticates the dispatch).\n * False means the existing client-driven `auto_continue` re-POST path is used.\n *\n * Deliberately independent of `isAgentChatDurableBackgroundEnabled`: an app can\n * use this narrower capability without opting into the full 15-min\n * background-function worker path, and the two gates never need to agree.\n * When BOTH would be true for a given run, the durable-background dispatch\n * decision in `production-agent.ts` is evaluated first and takes precedence —\n * a run already dispatched to the durable background worker chains via the\n * existing `isBackgroundWorker` path, not this one.\n */\nexport function isAgentChatForegroundSelfChainEnabled(): boolean {\n return (\n isForegroundSelfChainExplicitlyEnabled() &&\n isHostedRuntimeForDurableBackground() &&\n hasConfiguredA2ASecret()\n );\n}\n\n/** Decision returned by `prepareProcessRunRequest`. */\nexport type ProcessRunPreparation =\n | {\n ok: true;\n /** The pre-claimed run id the background worker must reuse. */\n runId: string;\n /** Body to stash for the re-entered handler (marker guaranteed present). */\n body: Record<string, unknown>;\n }\n | {\n ok: false;\n /** HTTP status the route should return. */\n status: number;\n /** Error payload. */\n error: string;\n /**\n * The run id parsed from the body, when present. Carried even on failure\n * so the route can RECORD the auth/validation failure ONTO the run\n * (diag_stage) before returning the error status — otherwise a 401/503 in\n * the unreadable Netlify background function would leave the run to time\n * out with no clue why. Null when no run id could be parsed.\n */\n runId: string | null;\n };\n\n/**\n * Parse the run id from a `_process-run` request body without authenticating.\n * Mirrors the precedence in `prepareProcessRunRequest` (marker.runId, then\n * top-level taskId). Returns null when neither is a usable string. Used so the\n * route can attach a diagnostic to the run even on an auth/validation failure.\n */\nexport function extractProcessRunId(body: unknown): string | null {\n if (!body || typeof body !== \"object\") return null;\n const record = body as Record<string, unknown>;\n const marker = record[AGENT_CHAT_BACKGROUND_RUN_FIELD] as\n | { runId?: unknown }\n | undefined;\n if (marker && typeof marker.runId === \"string\" && marker.runId) {\n return marker.runId;\n }\n if (typeof record.taskId === \"string\" && record.taskId) {\n return record.taskId;\n }\n return null;\n}\n\n/**\n * Pure, transport-agnostic core of the `_process-run` route: validate the body,\n * authenticate the HMAC self-dispatch, and produce the body the re-entered\n * agent-chat handler should run as the background worker.\n *\n * Auth policy mirrors the agent-teams processor exactly:\n * - `A2A_SECRET` set → require a valid `verifyInternalToken(runId, token)`.\n * - no secret → require `isTrustedLocalRuntime({ loopback })` (see\n * auth-policy.ts): refuse (503) unless `A2A_ALLOW_UNSIGNED_INTERNAL=1` is\n * set. This function has no h3 `event` of its own, so callers that CAN\n * see the inbound socket peer (the route handler, which has the event)\n * should compute `loopback` from it and pass it through; callers that\n * can't determine the peer address should omit it (defaults to `false`\n * — never trust unsigned dispatch without an explicit opt-in).\n *\n * Extracted from the route handler so the auth + marker-prep decision is unit\n * testable without booting the whole Nitro plugin. The route only adds body\n * reading and the final handler invocation around this.\n */\nexport function prepareProcessRunRequest(\n body: unknown,\n authHeader: string | undefined,\n loopback: boolean = false,\n): ProcessRunPreparation {\n if (!body || typeof body !== \"object\") {\n return {\n ok: false,\n status: 400,\n error: \"Invalid request body\",\n runId: null,\n };\n }\n const record = body as Record<string, unknown>;\n const marker = record[AGENT_CHAT_BACKGROUND_RUN_FIELD] as\n | { runId?: unknown }\n | undefined;\n const runId =\n marker && typeof marker.runId === \"string\"\n ? marker.runId\n : typeof record.taskId === \"string\"\n ? (record.taskId as string)\n : \"\";\n if (!runId) {\n return { ok: false, status: 400, error: \"runId required\", runId: null };\n }\n\n if (hasConfiguredA2ASecret()) {\n const token = extractBearerToken(authHeader);\n if (!verifyInternalToken(runId, token ?? \"\")) {\n return {\n ok: false,\n status: 401,\n error: \"Invalid or expired processor token\",\n runId,\n };\n }\n } else if (!isTrustedLocalRuntime({ loopback })) {\n // Callers that can see the h3 `event` (the route handler) pass the real\n // loopback signal; callers without one default to non-loopback. Unsigned\n // dispatch is still allowed via A2A_ALLOW_UNSIGNED_INTERNAL=1 for trusted\n // local/dev setups; see auth-policy.ts `isTrustedLocalRuntime`.\n return {\n ok: false,\n status: 503,\n error:\n \"Agent chat background processor not configured — set A2A_SECRET on this deployment (or A2A_ALLOW_UNSIGNED_INTERNAL=1 for trusted local dev).\",\n runId,\n };\n }\n\n // Ensure the marker is present so the re-entered handler runs as the\n // background worker (reuses runId/turnId, no re-claim, no re-dispatch).\n if (!marker || typeof marker.runId !== \"string\") {\n record[AGENT_CHAT_BACKGROUND_RUN_FIELD] = { runId };\n }\n return { ok: true, runId, body: record };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"durable-background.js","sourceRoot":"","sources":["../../src/agent/durable-background.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,mCAAmC,CAAC;AAE3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GACtC,wCAAwC,CAAC;AAE3C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,yBAAyB,CAAC;AAExE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,uBAAuB,8BAA8B,EAAE,CAAC;AAE1G;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,wBAAwB,CAAC;AACzE,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,CAAC;AACpD,MAAM,CAAC,MAAM,sCAAsC,GAAG,aAAa,CAAC;AACpE,MAAM,CAAC,MAAM,gCAAgC,GAAG,OAAO,CAAC;AACxD,MAAM,CAAC,MAAM,sCAAsC,GACjD,6BAA6B,CAAC;AAEhC;;;;;;;;GAQG;AACH,SAAS,yCAAyC;IAChD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC;IACtD,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACzC,2EAA2E;IAC3E,2EAA2E;IAC3E,+DAA+D;IAC/D,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACrE,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC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AAK;QACd,CAAC,CAAC,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ;YACjC,CAAC,CAAE,MAAM,CAAC,MAAiB;YAC3B,CAAC,CAAC,EAAE,CAAC;IACX,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC1E,CAAC;IAED,IAAI,sBAAsB,EAAE,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAC7C,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;YAC7C,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,MAAM,EAAE,GAAG;gBACX,KAAK,EAAE,oCAAoC;gBAC3C,KAAK;aACN,CAAC;QACJ,CAAC;IACH,CAAC;SAAM,IAAI,CAAC,qBAAqB,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;QAChD,wEAAwE;QACxE,yEAAyE;QACzE,0EAA0E;QAC1E,gEAAgE;QAChE,OAAO;YACL,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,GAAG;YACX,KAAK,EACH,8IAA8I;YAChJ,KAAK;SACN,CAAC;IACJ,CAAC;IAED,qEAAqE;IACrE,wEAAwE;IACxE,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,MAAM,CAAC,+BAA+B,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC;IACtD,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC3C,CAAC","sourcesContent":["/**\n * Durable background agent-chat runs (Netlify background functions).\n *\n * Off by default. When enabled, a long in-app agent-chat turn is dispatched\n * into a Netlify *background* function (15-min budget) instead of completing\n * synchronously under the ~40s soft-timeout. The foreground POST claims the\n * run slot, inserts the run row, fires an HMAC-signed self-dispatch to\n * `AGENT_CHAT_PROCESS_RUN_PATH`, and returns the existing SSE subscription so\n * the client streams the same events (via the cross-isolate SQL-poll path)\n * with no client change.\n *\n * This module owns ONLY the gating decision + shared constants so both the\n * HTTP handler (`production-agent.ts`) and the processor route\n * (`agent-chat-plugin.ts`) agree on when the path is active without a circular\n * import. The actual run machinery is reused verbatim from run-manager /\n * run-store / self-dispatch / internal-token.\n *\n * GUARDRAIL: when `isAgentChatDurableBackgroundEnabled()` returns false, the\n * agent-chat handler must behave byte-for-byte like the current synchronous\n * path. The gate is true only when ALL of these hold:\n * 1. `AGENT_CHAT_DURABLE_BACKGROUND` env is explicitly enabled, or a\n * workspace app's agent-chat plugin opts in with `durableBackgroundRuns`\n * where the workspace deploy emits a per-app background function by\n * default. Single-template Netlify deploys must set the env flag because\n * that same flag controls whether `server-agent-background` is emitted.\n * 2. The runtime is hosted/serverless (local dev keeps the inline path so SSE\n * stays a single live stream and no second function is needed).\n * 3. `A2A_SECRET` is configured (the HMAC handoff is required to authenticate\n * the background dispatch; without it the dispatch can't be trusted).\n *\n * Opt-in keeps the blast radius small while the worker path is still being\n * proven. And even when enabled, a *dispatch failure degrades to an inline run*:\n * if the self-dispatch self-POST can't be delivered (fast connection error or\n * fast non-2xx), the foreground handler runs the turn synchronously instead of\n * erroring (see `production-agent.ts` — the inline fallback claims the run row\n * atomically so a delayed delivery can never double-execute). So an app where\n * durable dispatch happens to fail still gets a working chat, just without the\n * 15-min budget.\n */\nimport {\n hasConfiguredA2ASecret,\n isTrustedLocalRuntime,\n} from \"../a2a/auth-policy.js\";\nimport {\n extractBearerToken,\n verifyInternalToken,\n} from \"../integrations/internal-token.js\";\n\n/**\n * Framework route the background function actually runs — sibling to\n * `AGENT_TEAM_PROCESS_RUN_PATH`. Reached *through* the Netlify background\n * function, so it inherits the 15-min budget.\n */\nexport const AGENT_CHAT_PROCESS_RUN_PATH =\n \"/_agent-native/agent-chat/_process-run\";\n\n/**\n * Name of the standalone Netlify background function the build emits (see\n * `emitSingleTemplateNetlifyBackgroundFunction` in deploy/build.ts). Shared so\n * the emit and the dispatch-path helper below can never drift on the name.\n *\n * MUST end in `-background` — both because that is the conventional Netlify\n * async-function suffix and because `isInBackgroundFunctionRuntime()` reads the\n * `AWS_LAMBDA_FUNCTION_NAME` `-background` suffix as a secondary runtime signal.\n */\nexport const AGENT_BACKGROUND_FUNCTION_NAME = \"server-agent-background\";\n\n/**\n * Default function URL of the background function on Netlify. Every Netlify\n * function is reachable at `/.netlify/functions/<name>` BY DEFAULT; that default\n * url is removed ONLY if the function declares a custom `config.path`. The\n * emitted background function declares NO custom `config.path` (it sets\n * `background: true` and nothing else routing-related), so it KEEPS this default\n * url — and the Nitro `server` function already excludes `/.netlify/*` from its\n * `/*` catch-all, so this namespace is never shadowed. The foreground therefore\n * dispatches HERE on hosted Netlify (see `resolveAgentChatProcessRunDispatchPath`).\n */\nexport const AGENT_BACKGROUND_FUNCTION_URL_PATH = `/.netlify/functions/${AGENT_BACKGROUND_FUNCTION_NAME}`;\n\n/**\n * Marker carried in a Netlify background-function body when the shared\n * long-running worker should route to a processor other than agent chat.\n * The emitted wrapper defaults to the normal agent-chat `_process-run` route;\n * A2A uses this marker to reuse the same 15-minute function for async tasks.\n */\nexport const AGENT_BACKGROUND_PROCESSOR_FIELD = \"__agentNativeProcessor\";\nexport const AGENT_BACKGROUND_PROCESSOR_A2A = \"a2a\";\nexport const AGENT_BACKGROUND_PROCESSOR_INTEGRATION = \"integration\";\nexport const AGENT_BACKGROUND_PROCESSOR_ROUTE = \"route\";\nexport const AGENT_BACKGROUND_PROCESSOR_ROUTE_FIELD =\n \"__agentNativeProcessorRoute\";\n\n/**\n * The per-app workspace background function URL path. Workspace deploy emits one\n * background function per app named `<app>-agent-background`, reachable at its\n * DEFAULT url `/.netlify/functions/<app>-agent-background` (no custom\n * `config.path`). The foreground resolves the current workspace app id from\n * `AGENT_NATIVE_WORKSPACE_APP_ID` (set by the workspace function entry) so it can\n * dispatch to the right per-app function url. Returns `null` when no workspace\n * app id is configured (single-template deploy).\n */\nfunction resolveWorkspaceBackgroundFunctionUrlPath(): string | null {\n const raw = process.env.AGENT_NATIVE_WORKSPACE_APP_ID;\n if (typeof raw !== \"string\") return null;\n // Mirror the workspace app-id normalization (resources/store.ts): take the\n // first path segment and accept only the safe slug shape used for function\n // names. Anything else falls back to the single-template name.\n const candidate = raw.trim().replace(/^\\/+/, \"\").split(\"/\")[0] ?? \"\";\n if (!/^[a-z0-9][a-z0-9-]{0,127}$/.test(candidate)) return null;\n return `/.netlify/functions/${candidate}-agent-background`;\n}\n\nfunction isNetlifyHostedRuntimeForDispatch(): boolean {\n if (process.env.NETLIFY_LOCAL === \"true\") return false;\n if (process.env.NETLIFY === \"false\") return false;\n if (process.env.NETLIFY && process.env.NETLIFY !== \"false\") return true;\n // NETLIFY is a build-only read-only variable. In deployed Functions Netlify\n // documents URL, SITE_NAME, and SITE_ID as the runtime read-only variables;\n // SITE_ID is the unambiguous host marker. Lambda compatibility mode also\n // exposes AWS runtime variables, so keep the function-name fallback for older\n // deploys. Without either check a modern Netlify Function silently selects the\n // portable framework route even though the emitted background function exists.\n if (process.env.SITE_ID) return true; // guard:allow-env-credential -- Netlify's read-only public site identifier is a runtime host marker, not a user credential.\n // Non-Netlify AWS falls back inline if the /.netlify/functions dispatch\n // fast-fails.\n return Boolean(process.env.AWS_LAMBDA_FUNCTION_NAME);\n}\n\n/**\n * Resolve the path the foreground POST should self-dispatch the chat background\n * worker to.\n *\n * GROUNDED IN THE REAL NETLIFY BUILD OUTPUT + THE NETLIFY DOCS DEFAULT-URL RULE:\n * the background function is emitted INTO the scanned dir\n * (`.netlify/functions-internal/server-agent-background`, or per-app\n * `<app>-agent-background` for workspaces) with `export const config = {\n * background: true, ... }` and NO custom `config.path`. Because it has no custom\n * path, Netlify keeps its DEFAULT function url `/.netlify/functions/<name>`, and\n * `background: true` makes any invocation of that url ASYNC (immediate 202,\n * 15-min budget). The Nitro `server` function already excludes `/.netlify/*`\n * from its `/*` catch-all, so the default-url namespace is NEVER shadowed by the\n * synchronous function.\n *\n * Therefore on hosted Netlify the foreground dispatches to the function's DEFAULT\n * url (`/.netlify/functions/<name>`); the function entry then rewrites the\n * incoming pathname to `AGENT_CHAT_PROCESS_RUN_PATH` (base-path-prefixed for\n * workspaces) before delegating to the Nitro router, so the `_process-run`\n * plugin runs with the async 15-min budget. Everywhere else (local dev, `netlify\n * dev`, non-Netlify hosts where no second function exists) there is no second\n * function, so the foreground dispatches to the framework route\n * `AGENT_CHAT_PROCESS_RUN_PATH` and the same in-process catch-all handles it\n * inline. The HMAC token (signed over the runId) is unchanged either way.\n *\n * NOTE: this is the DOC-CORRECT approach. An earlier attempt gave the function a\n * custom `config.path` + a catch-all `excludedPath` patch; the custom path was\n * NOT honored as a route in prod (probe → 404). Using the default function url\n * (no custom path) is what Netlify documents and is simpler — there is nothing\n * to shadow because `/.netlify/*` is already excluded from the `server` catch-all.\n */\nexport function resolveAgentChatProcessRunDispatchPath(): string {\n if (isNetlifyHostedRuntimeForDispatch()) {\n return (\n resolveWorkspaceBackgroundFunctionUrlPath() ??\n AGENT_BACKGROUND_FUNCTION_URL_PATH\n );\n }\n return AGENT_CHAT_PROCESS_RUN_PATH;\n}\n\nexport function resolveDurableBackgroundDispatchPath(\n fallbackPath: string,\n): string {\n if (isNetlifyHostedRuntimeForDispatch()) {\n return (\n resolveWorkspaceBackgroundFunctionUrlPath() ??\n AGENT_BACKGROUND_FUNCTION_URL_PATH\n );\n }\n return fallbackPath;\n}\n\nexport function dispatchPathTargetsNetlifyBackgroundFunction(\n dispatchPath: string,\n): boolean {\n return dispatchPath.startsWith(\"/.netlify/functions/\");\n}\n\n/**\n * Env flag for durable background runs. DEFAULT-OFF (opt-in): unset means\n * disabled; an app opts IN with an explicit truthy value (`true`/`1`/`yes`/`on`).\n */\nexport const AGENT_CHAT_DURABLE_BACKGROUND_ENV =\n \"AGENT_CHAT_DURABLE_BACKGROUND\";\n\n/**\n * Body field the foreground handler injects when self-dispatching to the\n * background processor. Its presence is how the re-entered handler knows it is\n * the background worker (run inline with the background soft-timeout; do NOT\n * re-claim the slot or re-dispatch). Untrusted on its own — the route also\n * verifies the HMAC token before invoking the handler.\n */\nexport const AGENT_CHAT_BACKGROUND_RUN_FIELD = \"__backgroundRun\";\n\n/**\n * Mirror of run-manager's private `isHostedRuntime`. Kept in sync deliberately:\n * the durable-background gate must agree with the soft-timeout regime about\n * what \"hosted\" means.\n */\nexport function isHostedRuntimeForDurableBackground(): boolean {\n if (process.env.NETLIFY_LOCAL === \"true\") return false;\n if (process.env.NETLIFY === \"false\") return false;\n if (process.env.SITE_ID) return true; // guard:allow-env-credential -- Netlify's read-only public site identifier is a runtime host marker, not a user credential.\n if (\n process.env.NETLIFY &&\n process.env.NETLIFY !== \"false\" &&\n process.env.NETLIFY_LOCAL !== \"true\"\n ) {\n return true;\n }\n if (\n process.env.AWS_LAMBDA_FUNCTION_NAME &&\n process.env.NETLIFY_LOCAL !== \"true\"\n ) {\n return true;\n }\n return Boolean(\n process.env.CF_PAGES ||\n process.env.VERCEL ||\n process.env.VERCEL_ENV ||\n process.env.RENDER ||\n process.env.FLY_APP_NAME ||\n process.env.K_SERVICE,\n );\n}\n\n/**\n * True when THIS process is actually executing inside a Netlify *background*\n * function (the long, 15-min-budget async function whose deployed name ends in\n * `-background`). Netlify runs functions on AWS Lambda and sets\n * `AWS_LAMBDA_FUNCTION_NAME` to the function's name, so a `-background` suffix is\n * the runtime proof that the ~60s synchronous wall does NOT apply here.\n *\n * This is the SAFETY GUARD for the soft-timeout regime. The `_process-run`\n * self-dispatch worker (`isBackgroundWorker`) is NOT enough on its own: if the\n * `-background` function was never emitted (deploy gate off, or Netlify routed\n * the path to the synchronous function), the self-POST lands on the regular\n * ~60s `server` function. A worker there MUST use the 40s soft-timeout and\n * checkpoint before the 60s wall — using the ~13min budget would overshoot the\n * hard wall and get killed at 60s, then re-dispatch/resume in a wasteful loop.\n * So the 13-min budget is taken ONLY when this returns true.\n *\n * The PRIMARY signal is a `globalThis` marker the emitted background function's\n * entry sets at cold start — the deployed Lambda name is not guaranteed to end\n * in `-background` on Netlify, so the entry marks its own runtime. A `globalThis`\n * flag (not `process.env`) keeps the no-env-mutation guard satisfied and carries\n * no cross-request state (set once per isolate). The `AWS_LAMBDA_FUNCTION_NAME`\n * suffix and the explicit `AGENT_CHAT_FORCE_BACKGROUND_RUNTIME` env (truthy) are\n * additional signals — the latter an operator escape hatch. Off by default.\n */\nexport function isInBackgroundFunctionRuntime(): boolean {\n // Set by the emitted `-background` function entry at cold start (the primary,\n // most reliable signal — see the emit in deploy/build.ts).\n if (\n (globalThis as Record<string, unknown>)\n .__AGENT_NATIVE_BACKGROUND_RUNTIME__ === true\n ) {\n return true;\n }\n const lambdaName = process.env.AWS_LAMBDA_FUNCTION_NAME;\n if (\n typeof lambdaName === \"string\" &&\n lambdaName.toLowerCase().endsWith(\"-background\")\n ) {\n return true;\n }\n const forced = process.env.AGENT_CHAT_FORCE_BACKGROUND_RUNTIME;\n if (forced != null) {\n const v = forced.trim().toLowerCase();\n return v === \"1\" || v === \"true\" || v === \"yes\" || v === \"on\";\n }\n return false;\n}\n\nexport function backgroundRunMarkerExpectsBackgroundRuntime(\n marker: unknown,\n): boolean {\n return (\n typeof marker === \"object\" &&\n marker !== null &&\n (marker as { backgroundFunctionRuntimeExpected?: unknown })\n .backgroundFunctionRuntimeExpected === true\n );\n}\n\nexport function shouldUseBackgroundFunctionTimeoutForWorker(\n _marker: unknown,\n): boolean {\n // The dispatch marker says which URL the foreground targeted, not where the\n // request actually landed. Only the worker runtime proof can safely lift the\n // hosted 40s clamp to the 15-minute background-function budget.\n return isInBackgroundFunctionRuntime();\n}\n\nexport function backgroundRuntimeDiagnosticDetail(marker: unknown): string {\n const detail = [\n `markerExpected=${backgroundRunMarkerExpectsBackgroundRuntime(marker)}`,\n `runtimeDetected=${isInBackgroundFunctionRuntime()}`,\n `globalMarker=${(globalThis as Record<string, unknown>).__AGENT_NATIVE_BACKGROUND_RUNTIME__ === true}`,\n `lambdaNameEndsBackground=${typeof process.env.AWS_LAMBDA_FUNCTION_NAME === \"string\" && process.env.AWS_LAMBDA_FUNCTION_NAME.toLowerCase().endsWith(\"-background\")}`,\n `forceEnv=${typeof process.env.AGENT_CHAT_FORCE_BACKGROUND_RUNTIME === \"string\" && process.env.AGENT_CHAT_FORCE_BACKGROUND_RUNTIME.trim().length > 0}`,\n ].join(\" \");\n reportMissingBackgroundFunctionOnce(marker, detail);\n return detail;\n}\n\nexport const BACKGROUND_FUNCTION_UNREACHABLE_NOTICE_KEY =\n \"__AGENT_NATIVE_BACKGROUND_UNREACHABLE_NOTICE__\";\n\n/**\n * The foreground targeted the `-background` function's default url, yet this\n * worker is NOT running in that function: the deploy is missing the artifact (or\n * Netlify routed the url to the synchronous function). The turn still completes\n * on the 40s-clamped path, so nothing else ever surfaces it — an app can lose\n * the 15-min budget for its whole lifetime in silence (agent-native-plan did:\n * zero background runs ever, every turn pinned to the ~60s wall). Announce it\n * once per isolate; the same detail is already recorded on the run row by the\n * caller, so this only adds the server-side signal a deploy owner can grep.\n */\nfunction reportMissingBackgroundFunctionOnce(\n marker: unknown,\n detail: string,\n): void {\n if (!backgroundRunMarkerExpectsBackgroundRuntime(marker)) return;\n if (isInBackgroundFunctionRuntime()) return;\n const scope = globalThis as Record<string, unknown>;\n if (scope[BACKGROUND_FUNCTION_UNREACHABLE_NOTICE_KEY] === true) return;\n scope[BACKGROUND_FUNCTION_UNREACHABLE_NOTICE_KEY] = true;\n console.error(\n `[agent-chat] durable background is enabled but the \"${AGENT_BACKGROUND_FUNCTION_NAME}\" ` +\n \"function is unreachable — this worker is running on the synchronous function \" +\n \"with the 40s clamp instead of the 15-min budget. Check that the deploy emitted \" +\n `it (build log: \"Emitted durable-background function\"). ${detail}`,\n );\n}\n\n/**\n * Env flag parse, shared by the runtime gate and the deploy-time emit gates so\n * they can never drift apart (they did: the workspace deploy copy defaulted ON\n * while this one defaulted OFF).\n */\nexport function isDurableBackgroundFlagEnabled(): boolean {\n // Read the literal key (not `process.env[CONST]`) so guard:no-env-credentials\n // can statically verify it against the allowlisted `AGENT_*` prefix. Keep this\n // in sync with AGENT_CHAT_DURABLE_BACKGROUND_ENV.\n //\n // DEFAULT-OFF (opt-in): durable background runs are still being hardened. A\n // premature fleet-wide default-on caused real-user incidents (Assets/Analytics\n // hit \"Failed to dispatch\" + stalls, 2026-06-24) because the async background\n // worker path is not yet proven end-to-end and the deploy-time env opt-out is\n // not reliably baked into a given deploy. So an unset/empty/unknown flag means\n // OFF; an app opts IN only with an explicit truthy value\n // (AGENT_CHAT_DURABLE_BACKGROUND=true). This still composes with the hosted +\n // A2A_SECRET gates below. Flip back to default-on only after the 15-min\n // background-function worker is verified live in production (see the\n // project_durable_bg_prod_verified memory).\n const raw = process.env.AGENT_CHAT_DURABLE_BACKGROUND;\n if (raw == null) return false;\n const normalized = raw.trim().toLowerCase();\n return (\n normalized === \"1\" ||\n normalized === \"true\" ||\n normalized === \"yes\" ||\n normalized === \"on\"\n );\n}\n\nexport function isDurableBackgroundFlagExplicitlyDisabled(): boolean {\n const raw = process.env.AGENT_CHAT_DURABLE_BACKGROUND;\n if (raw == null) return false;\n const normalized = raw.trim().toLowerCase();\n return (\n normalized === \"0\" ||\n normalized === \"false\" ||\n normalized === \"no\" ||\n normalized === \"off\"\n );\n}\n\n/**\n * The single gate. True when the env flag is explicitly enabled, or a workspace\n * app opted in and has a per-app background-function target, AND the runtime is\n * hosted AND A2A_SECRET is configured. False otherwise — and false means the\n * current synchronous behavior is used unchanged. Single-template Netlify app\n * opt-ins deliberately require the env flag too because that flag controls\n * whether the `server-agent-background` function exists in the deploy output.\n */\nexport function isAgentChatDurableBackgroundEnabled(options?: {\n appOptIn?: boolean;\n}): boolean {\n // An app-level opt-out must win over a stale deploy-wide env flag. Netlify\n // environment variables can outlive the source config that originally set\n // them; allowing that flag to re-enable a worker an app explicitly disabled\n // recreates the missing-background-function failure this gate is meant to\n // prevent.\n if (options?.appOptIn === false) return false;\n const envOptIn = isDurableBackgroundFlagEnabled();\n const workspaceAppOptIn =\n options?.appOptIn === true &&\n !isDurableBackgroundFlagExplicitlyDisabled() &&\n resolveWorkspaceBackgroundFunctionUrlPath() !== null;\n return (\n (envOptIn || workspaceAppOptIn) &&\n isHostedRuntimeForDurableBackground() &&\n hasConfiguredA2ASecret()\n );\n}\n\n/**\n * Env flag for the FOREGROUND server-driven self-chain. DEFAULT-OFF: a hosted\n * app must explicitly opt in with a truthy value (`true`/`1`/`yes`/`on`). A\n * regular Netlify function has a fixed 60-second wall, and a self-dispatched\n * successor can otherwise be killed before it persists its next continuation.\n * Keep this separate from `AGENT_CHAT_DURABLE_BACKGROUND` so the experimental\n * regular-function chain can be enabled independently after its deployment is\n * proven safe.\n */\nexport const AGENT_CHAT_FOREGROUND_SELF_CHAIN_ENV =\n \"AGENT_CHAT_FOREGROUND_SELF_CHAIN\";\n\nfunction isForegroundSelfChainExplicitlyEnabled(): boolean {\n // Read the literal key (not `process.env[CONST]`) so guard:no-env-credentials\n // can statically verify it against the allowlisted `AGENT_*` prefix. Keep this\n // in sync with AGENT_CHAT_FOREGROUND_SELF_CHAIN_ENV.\n const raw = process.env.AGENT_CHAT_FOREGROUND_SELF_CHAIN;\n if (raw == null) return false;\n const normalized = raw.trim().toLowerCase();\n return (\n normalized === \"1\" ||\n normalized === \"true\" ||\n normalized === \"yes\" ||\n normalized === \"on\"\n );\n}\n\n/**\n * Gate for the foreground self-chain: a normal (non-durable-background)\n * agent-chat turn that hits its soft-timeout chunk boundary continues via a\n * server-side self-dispatch on the REGULAR function (not a Netlify\n * `-background` function) instead of depending on the client to re-POST\n * `auto_continue`. Composes exactly like `isAgentChatDurableBackgroundEnabled`:\n * true only when the env flag is explicitly truthy, the runtime is hosted, and\n * `A2A_SECRET` is configured (the HMAC handoff authenticates the dispatch).\n * False means the existing client-driven `auto_continue` re-POST path is used.\n *\n * Deliberately independent of `isAgentChatDurableBackgroundEnabled`: an app can\n * use this narrower capability without opting into the full 15-min\n * background-function worker path, and the two gates never need to agree.\n * When BOTH would be true for a given run, the durable-background dispatch\n * decision in `production-agent.ts` is evaluated first and takes precedence —\n * a run already dispatched to the durable background worker chains via the\n * existing `isBackgroundWorker` path, not this one.\n */\nexport function isAgentChatForegroundSelfChainEnabled(): boolean {\n return (\n isForegroundSelfChainExplicitlyEnabled() &&\n isHostedRuntimeForDurableBackground() &&\n hasConfiguredA2ASecret()\n );\n}\n\n/** Decision returned by `prepareProcessRunRequest`. */\nexport type ProcessRunPreparation =\n | {\n ok: true;\n /** The pre-claimed run id the background worker must reuse. */\n runId: string;\n /** Body to stash for the re-entered handler (marker guaranteed present). */\n body: Record<string, unknown>;\n }\n | {\n ok: false;\n /** HTTP status the route should return. */\n status: number;\n /** Error payload. */\n error: string;\n /**\n * The run id parsed from the body, when present. Carried even on failure\n * so the route can RECORD the auth/validation failure ONTO the run\n * (diag_stage) before returning the error status — otherwise a 401/503 in\n * the unreadable Netlify background function would leave the run to time\n * out with no clue why. Null when no run id could be parsed.\n */\n runId: string | null;\n };\n\n/**\n * Parse the run id from a `_process-run` request body without authenticating.\n * Mirrors the precedence in `prepareProcessRunRequest` (marker.runId, then\n * top-level taskId). Returns null when neither is a usable string. Used so the\n * route can attach a diagnostic to the run even on an auth/validation failure.\n */\nexport function extractProcessRunId(body: unknown): string | null {\n if (!body || typeof body !== \"object\") return null;\n const record = body as Record<string, unknown>;\n const marker = record[AGENT_CHAT_BACKGROUND_RUN_FIELD] as\n | { runId?: unknown }\n | undefined;\n if (marker && typeof marker.runId === \"string\" && marker.runId) {\n return marker.runId;\n }\n if (typeof record.taskId === \"string\" && record.taskId) {\n return record.taskId;\n }\n return null;\n}\n\n/**\n * Pure, transport-agnostic core of the `_process-run` route: validate the body,\n * authenticate the HMAC self-dispatch, and produce the body the re-entered\n * agent-chat handler should run as the background worker.\n *\n * Auth policy mirrors the agent-teams processor exactly:\n * - `A2A_SECRET` set → require a valid `verifyInternalToken(runId, token)`.\n * - no secret → require `isTrustedLocalRuntime({ loopback })` (see\n * auth-policy.ts): refuse (503) unless `A2A_ALLOW_UNSIGNED_INTERNAL=1` is\n * set. This function has no h3 `event` of its own, so callers that CAN\n * see the inbound socket peer (the route handler, which has the event)\n * should compute `loopback` from it and pass it through; callers that\n * can't determine the peer address should omit it (defaults to `false`\n * — never trust unsigned dispatch without an explicit opt-in).\n *\n * Extracted from the route handler so the auth + marker-prep decision is unit\n * testable without booting the whole Nitro plugin. The route only adds body\n * reading and the final handler invocation around this.\n */\nexport function prepareProcessRunRequest(\n body: unknown,\n authHeader: string | undefined,\n loopback: boolean = false,\n): ProcessRunPreparation {\n if (!body || typeof body !== \"object\") {\n return {\n ok: false,\n status: 400,\n error: \"Invalid request body\",\n runId: null,\n };\n }\n const record = body as Record<string, unknown>;\n const marker = record[AGENT_CHAT_BACKGROUND_RUN_FIELD] as\n | { runId?: unknown }\n | undefined;\n const runId =\n marker && typeof marker.runId === \"string\"\n ? marker.runId\n : typeof record.taskId === \"string\"\n ? (record.taskId as string)\n : \"\";\n if (!runId) {\n return { ok: false, status: 400, error: \"runId required\", runId: null };\n }\n\n if (hasConfiguredA2ASecret()) {\n const token = extractBearerToken(authHeader);\n if (!verifyInternalToken(runId, token ?? \"\")) {\n return {\n ok: false,\n status: 401,\n error: \"Invalid or expired processor token\",\n runId,\n };\n }\n } else if (!isTrustedLocalRuntime({ loopback })) {\n // Callers that can see the h3 `event` (the route handler) pass the real\n // loopback signal; callers without one default to non-loopback. Unsigned\n // dispatch is still allowed via A2A_ALLOW_UNSIGNED_INTERNAL=1 for trusted\n // local/dev setups; see auth-policy.ts `isTrustedLocalRuntime`.\n return {\n ok: false,\n status: 503,\n error:\n \"Agent chat background processor not configured — set A2A_SECRET on this deployment (or A2A_ALLOW_UNSIGNED_INTERNAL=1 for trusted local dev).\",\n runId,\n };\n }\n\n // Ensure the marker is present so the re-entered handler runs as the\n // background worker (reuses runId/turnId, no re-claim, no re-dispatch).\n if (!marker || typeof marker.runId !== \"string\") {\n record[AGENT_CHAT_BACKGROUND_RUN_FIELD] = { runId };\n }\n return { ok: true, runId, body: record };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sdk-engine.d.ts","sourceRoot":"","sources":["../../../src/agent/engine/ai-sdk-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAYH,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"ai-sdk-engine.d.ts","sourceRoot":"","sources":["../../../src/agent/engine/ai-sdk-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAYH,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAqB7E,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAInB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAMxD,QAAA,MAAM,qBAAqB,EAAE,MAAM,CAAC,aAAa,EAAE,kBAAkB,CAyDpE,CAAC;AAMF,QAAA,MAAM,uBAAuB,EAKxB,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;AAEnC,QAAA,MAAM,yBAAyB,EAKf,MAAM,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;AAEzD,QAAA,MAAM,iBAAiB,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,EAAE,CAStD,CAAC;AAEF,QAAA,MAAM,iBAAiB,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,CASpD,CAAC;AA4CF,kDAAkD;AAClD,MAAM,WAAW,iBAAiB;IAChC,sFAAsF;IACtF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0GAA0G;IAC1G,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,yFAAyF;IACzF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAqXD,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,aAAa,EACvB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACnC,WAAW,CAEb;AA8CD,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,GAClB,CAAC"}
|
|
@@ -14,9 +14,11 @@
|
|
|
14
14
|
import { clearProviderCredentialAuthFailure, readDeployCredentialEnv, recordProviderCredentialAuthFailure, } from "../../server/credential-provider.js";
|
|
15
15
|
import { anthropicManualThinkingBudget, normalizeReasoningEffortForModel, supportsClaudeAdaptiveThinking, } from "../../shared/reasoning-effort.js";
|
|
16
16
|
import { AI_SDK_MODEL_CONFIG } from "../model-config.js";
|
|
17
|
+
import { describeErrorWithCauses } from "./error-detail.js";
|
|
17
18
|
import { createFirstEventAbortController, FIRST_STREAM_EVENT_TIMEOUT_MS, } from "./first-event-timeout.js";
|
|
18
19
|
import { clampThinkingBudgetTokens, resolveMaxOutputTokensForEngine, } from "./output-tokens.js";
|
|
19
20
|
import { engineToolsToAISDK, engineMessagesToAISDK, aiSdkPartToEngineEvents, aiSdkStepToAssistantContent, } from "./translate-ai-sdk.js";
|
|
21
|
+
import { createStreamedToolInputState, finalizeStreamedToolInputs, observeStreamedToolInput, } from "./translate-anthropic.js";
|
|
20
22
|
// ---------------------------------------------------------------------------
|
|
21
23
|
// Provider definitions
|
|
22
24
|
// ---------------------------------------------------------------------------
|
|
@@ -265,10 +267,26 @@ class AISDKEngine {
|
|
|
265
267
|
}
|
|
266
268
|
}
|
|
267
269
|
else if (this.provider === "openai") {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
270
|
+
// OpenAI rejects `reasoning_effort` together with function tools on
|
|
271
|
+
// the legacy Chat Completions surface for some reasoning models
|
|
272
|
+
// ("Function tools with reasoning_effort are not supported for
|
|
273
|
+
// <model> in /v1/chat/completions. To use function tools, use
|
|
274
|
+
// /v1/responses or set reasoning_effort to 'none'.") — a real prod
|
|
275
|
+
// incident, e.g. Sentry AGENT-NATIVE-BROWSER-94 on gpt-5.6-terra.
|
|
276
|
+
// `createProviderModel` forces Chat Completions specifically when
|
|
277
|
+
// `this.baseUrl` is set (many OpenAI-compatible gateways/proxies
|
|
278
|
+
// don't implement Responses — see that comment). In that exact
|
|
279
|
+
// combination — forced Chat Completions AND tools present — drop
|
|
280
|
+
// the explicit override and let the model use its default reasoning
|
|
281
|
+
// behavior instead of hard-failing the whole request; Responses-API
|
|
282
|
+
// calls (no baseUrl) are unaffected and keep full effort control.
|
|
283
|
+
const forcedChatCompletionsWithTools = Boolean(this.baseUrl) && aiSdkTools !== undefined;
|
|
284
|
+
if (!forcedChatCompletionsWithTools) {
|
|
285
|
+
providerOpts.openai = {
|
|
286
|
+
...(providerOpts.openai ?? {}),
|
|
287
|
+
reasoningEffort,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
272
290
|
}
|
|
273
291
|
else if (this.provider === "openrouter") {
|
|
274
292
|
providerOpts.openrouter = {
|
|
@@ -301,6 +319,7 @@ class AISDKEngine {
|
|
|
301
319
|
}
|
|
302
320
|
let assistantContent = [];
|
|
303
321
|
const firstEventAbort = createFirstEventAbortController(opts.abortSignal);
|
|
322
|
+
const toolInputs = createStreamedToolInputState();
|
|
304
323
|
try {
|
|
305
324
|
const result = streamText({
|
|
306
325
|
model: providerModel,
|
|
@@ -308,6 +327,10 @@ class AISDKEngine {
|
|
|
308
327
|
messages,
|
|
309
328
|
tools: aiSdkTools,
|
|
310
329
|
maxOutputTokens: resolvedMaxOutputTokens,
|
|
330
|
+
// Explicit: the agent loop already retries a failed model call with
|
|
331
|
+
// backoff. Leaving the SDK on its default (2) multiplies the two retry
|
|
332
|
+
// layers into ~12 HTTP requests per failed run.
|
|
333
|
+
maxRetries: 1,
|
|
311
334
|
...(opts.temperature !== undefined
|
|
312
335
|
? { temperature: opts.temperature }
|
|
313
336
|
: {}),
|
|
@@ -334,6 +357,7 @@ class AISDKEngine {
|
|
|
334
357
|
firstEventAbort.markFirstEvent();
|
|
335
358
|
}
|
|
336
359
|
for (const event of aiSdkPartToEngineEvents(part)) {
|
|
360
|
+
observeStreamedToolInput(toolInputs, event);
|
|
337
361
|
if (event.type === "stop") {
|
|
338
362
|
bufferedStop = event;
|
|
339
363
|
}
|
|
@@ -348,6 +372,20 @@ class AISDKEngine {
|
|
|
348
372
|
if (!sawFirstEvent && firstEventAbort.didTimeout()) {
|
|
349
373
|
throw new Error(`Model request produced no stream events within ${FIRST_STREAM_EVENT_TIMEOUT_MS / 1000}s; the connection appears wedged.`);
|
|
350
374
|
}
|
|
375
|
+
// A step can finish having announced a tool call it never delivered.
|
|
376
|
+
// Assemble it from its deltas, or report it in-band, rather than ending
|
|
377
|
+
// the turn as if the model never asked for it.
|
|
378
|
+
for (const recovered of finalizeStreamedToolInputs(toolInputs, assistantContent.flatMap((part) => part.type === "tool-call" ? [part.id] : []))) {
|
|
379
|
+
if (recovered.type === "tool-call") {
|
|
380
|
+
assistantContent.push({
|
|
381
|
+
type: "tool-call",
|
|
382
|
+
id: recovered.id,
|
|
383
|
+
name: recovered.name,
|
|
384
|
+
input: recovered.input,
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
yield recovered;
|
|
388
|
+
}
|
|
351
389
|
yield { type: "assistant-content", parts: assistantContent };
|
|
352
390
|
await clearProviderCredentialAuthFailure({
|
|
353
391
|
key: PROVIDER_ENV_VARS[this.provider][0],
|
|
@@ -361,10 +399,13 @@ class AISDKEngine {
|
|
|
361
399
|
// isRetryableError can check statusCode/providerRetryable directly
|
|
362
400
|
// rather than keyword-matching the message string.
|
|
363
401
|
const statusCode = typeof err?.statusCode === "number" ? err.statusCode : undefined;
|
|
364
|
-
const
|
|
402
|
+
const rawMessage = err?.message ?? String(err);
|
|
403
|
+
// Classify on the bare message — the recorded `errorMessage` carries the
|
|
404
|
+
// cause chain, which is where the real transport failure lives.
|
|
405
|
+
const errorMessage = describeErrorWithCauses(err);
|
|
365
406
|
const isConnectionError = !timedOut &&
|
|
366
407
|
statusCode === undefined &&
|
|
367
|
-
|
|
408
|
+
rawMessage.trim().toLowerCase() === "connection error.";
|
|
368
409
|
const providerRetryable = typeof err?.isRetryable === "boolean"
|
|
369
410
|
? err.isRetryable
|
|
370
411
|
: isConnectionError || timedOut
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sdk-engine.js","sourceRoot":"","sources":["../../../src/agent/engine/ai-sdk-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,kCAAkC,EAClC,uBAAuB,EACvB,mCAAmC,GACpC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,6BAA6B,EAC7B,gCAAgC,EAChC,8BAA8B,GAC/B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAsB,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EACL,+BAA+B,EAC/B,6BAA6B,GAC9B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,yBAAyB,EACzB,+BAA+B,GAChC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,uBAAuB,CAAC;AAW/B,8EAA8E;AAC9E,uBAAuB;AACvB,8EAA8E;AAE9E,MAAM,qBAAqB,GAA8C;IACvE,SAAS,EAAE;QACT,QAAQ,EAAE,IAAI;QACd,aAAa,EAAE,IAAI;QACnB,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE,KAAK,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Q,QAAQ,EAAE,CAAC;QACjB,KAAK,WAAW;YACd,OAAO,MAAM,CAAC,mBAAmB,CAAC,CAAC;QACrC,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAClC,KAAK,YAAY;YACf,OAAO,MAAM,CAAC,6BAA6B,CAAC,CAAC;QAC/C,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAClC,KAAK,MAAM;YACT,OAAO,MAAM,CAAC,cAAc,CAAC,CAAC;QAChC,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC,iBAAiB,CAAC,CAAC;QACnC,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAClC,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,CAAS;IAC3B,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,iBAAiB,CAAC,QAAuB;IAChD,MAAM,OAAO,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC5C,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,MAAM,KAAK,GAAG,uBAAuB,CAAC,CAAC,CAAC,CAAC;QACzC,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;IAC1B,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,8EAA8E;AAC9E,oCAAoC;AACpC,8EAA8E;AAE9E,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,GAClB,CAAC","sourcesContent":["/**\n * AISDKEngine — wraps the Vercel AI SDK (ai package) for multi-provider support.\n *\n * Supports Anthropic, OpenAI, Google Gemini, Groq, and any provider with an\n * @ai-sdk/* package. Provider is selected via the `provider` config option.\n *\n * When provider is \"anthropic\", Anthropic-native features (thinking, cacheControl)\n * are forwarded through the AI SDK's providerOptions mechanism — no fidelity loss\n * compared to the native AnthropicEngine.\n *\n * The ai package is an OPTIONAL peer dependency. This engine uses dynamic import()\n * so the core package remains installable without the AI SDK.\n */\n\nimport {\n clearProviderCredentialAuthFailure,\n readDeployCredentialEnv,\n recordProviderCredentialAuthFailure,\n} from \"../../server/credential-provider.js\";\nimport {\n anthropicManualThinkingBudget,\n normalizeReasoningEffortForModel,\n supportsClaudeAdaptiveThinking,\n} from \"../../shared/reasoning-effort.js\";\nimport { AI_SDK_MODEL_CONFIG, type AISDKProvider } from \"../model-config.js\";\nimport {\n createFirstEventAbortController,\n FIRST_STREAM_EVENT_TIMEOUT_MS,\n} from \"./first-event-timeout.js\";\nimport {\n clampThinkingBudgetTokens,\n resolveMaxOutputTokensForEngine,\n} from \"./output-tokens.js\";\nimport {\n engineToolsToAISDK,\n engineMessagesToAISDK,\n aiSdkPartToEngineEvents,\n aiSdkStepToAssistantContent,\n} from \"./translate-ai-sdk.js\";\nimport type {\n AgentEngine,\n EngineCapabilities,\n EngineStreamOptions,\n EngineEvent,\n EngineContentPart,\n} from \"./types.js\";\n\nexport type { AISDKProvider } from \"../model-config.js\";\n\n// ---------------------------------------------------------------------------\n// Provider definitions\n// ---------------------------------------------------------------------------\n\nconst PROVIDER_CAPABILITIES: Record<AISDKProvider, EngineCapabilities> = {\n anthropic: {\n thinking: true,\n promptCaching: true,\n vision: true,\n computerUse: false, // not exposed through AI SDK yet\n parallelToolCalls: true,\n },\n openai: {\n thinking: true,\n promptCaching: false,\n vision: true,\n computerUse: false,\n parallelToolCalls: true,\n },\n openrouter: {\n thinking: true,\n promptCaching: true,\n vision: true,\n computerUse: false,\n parallelToolCalls: true,\n },\n google: {\n thinking: true,\n promptCaching: false,\n vision: true,\n computerUse: false,\n parallelToolCalls: true,\n },\n groq: {\n thinking: false,\n promptCaching: false,\n vision: false,\n computerUse: false,\n parallelToolCalls: true,\n },\n mistral: {\n thinking: false,\n promptCaching: false,\n vision: false,\n computerUse: false,\n parallelToolCalls: true,\n },\n cohere: {\n thinking: false,\n promptCaching: false,\n vision: false,\n computerUse: false,\n parallelToolCalls: true,\n },\n ollama: {\n thinking: false,\n promptCaching: false,\n vision: false,\n computerUse: false,\n parallelToolCalls: false,\n },\n};\n\nconst providerModelEntries = Object.entries(AI_SDK_MODEL_CONFIG) as Array<\n [AISDKProvider, (typeof AI_SDK_MODEL_CONFIG)[AISDKProvider]]\n>;\n\nconst PROVIDER_DEFAULT_MODELS = Object.fromEntries(\n providerModelEntries.map(([provider, config]) => [\n provider,\n config.defaultModel,\n ]),\n) as Record<AISDKProvider, string>;\n\nconst PROVIDER_SUPPORTED_MODELS = Object.fromEntries(\n providerModelEntries.map(([provider, config]) => [\n provider,\n config.supportedModels,\n ]),\n) as unknown as Record<AISDKProvider, readonly string[]>;\n\nconst PROVIDER_ENV_VARS: Record<AISDKProvider, string[]> = {\n anthropic: [\"ANTHROPIC_API_KEY\"],\n openai: [\"OPENAI_API_KEY\"],\n openrouter: [\"OPENROUTER_API_KEY\"],\n google: [\"GOOGLE_GENERATIVE_AI_API_KEY\"],\n groq: [\"GROQ_API_KEY\"],\n mistral: [\"MISTRAL_API_KEY\"],\n cohere: [\"COHERE_API_KEY\"],\n ollama: [], // runs locally\n};\n\nconst PROVIDER_PACKAGES: Record<AISDKProvider, string> = {\n anthropic: \"@ai-sdk/anthropic\",\n openai: \"@ai-sdk/openai\",\n openrouter: \"@openrouter/ai-sdk-provider\",\n google: \"@ai-sdk/google\",\n groq: \"@ai-sdk/groq\",\n mistral: \"@ai-sdk/mistral\",\n cohere: \"@ai-sdk/cohere\",\n ollama: \"ai-sdk-ollama\",\n};\n\n/** Factory export name per provider (not all follow `create<Provider>`). */\nconst PROVIDER_FACTORIES: Record<AISDKProvider, string> = {\n anthropic: \"createAnthropic\",\n openai: \"createOpenAI\",\n openrouter: \"createOpenRouter\",\n google: \"createGoogleGenerativeAI\",\n groq: \"createGroq\",\n mistral: \"createMistral\",\n cohere: \"createCohere\",\n ollama: \"createOllama\",\n};\n\nfunction googleThinkingBudget(effort: string) {\n if (effort === \"low\") return 1024;\n // \"medium\" is a normalized effort for Gemini models; without this case it\n // fell through to the -1 (\"dynamic/unlimited\") fallback, so selecting\n // medium effort silently uncapped the thinking budget.\n if (effort === \"medium\") return 4096;\n if (effort === \"high\") return 8000;\n if (effort === \"xhigh\") return 16_000;\n if (effort === \"max\") return 32_000;\n return -1;\n}\n\n/**\n * Map a reasoning effort level to Gemini 3.x thinkingLevel string.\n * Gemini 3 models (gemini-3.*) reject thinkingBudget and require thinkingLevel\n * with values 'low' | 'medium' | 'high'. Gemini 3.0 only supports 'low'/'high';\n * Gemini 3.1+ adds 'medium'. We always emit 'medium' for medium effort since it\n * is accepted by 3.1+, and 3.0 is expected to be phased out quickly.\n */\nfunction gemini3ThinkingLevel(effort: string): string {\n if (effort === \"low\") return \"low\";\n if (effort === \"medium\") return \"medium\";\n // high/xhigh/max map to the strongest available level for Gemini 3.\n return \"high\";\n}\n\n// ---------------------------------------------------------------------------\n// AISDKEngine implementation\n// ---------------------------------------------------------------------------\n\n/** Config accepted by every `ai-sdk:*` engine. */\nexport interface AISDKEngineConfig {\n /** Override the provider's default model (also becomes the engine's defaultModel). */\n model?: string;\n /** API key — falls back to the provider-specific env var if omitted. */\n apiKey?: string;\n /** Set false in request-scoped multi-tenant runs so provider packages cannot fall back to process.env. */\n allowEnvFallback?: boolean;\n /** Override the provider base URL (useful for proxies or OpenAI-compatible gateways). */\n baseUrl?: string;\n /** OpenRouter: `X-OpenRouter-Title` header for dashboard attribution. */\n appName?: string;\n /** OpenRouter: `HTTP-Referer` header for dashboard attribution. */\n appUrl?: string;\n}\n\nclass AISDKEngine implements AgentEngine {\n readonly name: string;\n readonly label: string;\n readonly defaultModel: string;\n readonly supportedModels: readonly string[];\n readonly preserveCustomModels: boolean;\n readonly capabilities: EngineCapabilities;\n\n private readonly provider: AISDKProvider;\n private readonly apiKey?: string;\n private readonly baseUrl?: string;\n private readonly appName?: string;\n private readonly appUrl?: string;\n\n constructor(provider: AISDKProvider, config: AISDKEngineConfig) {\n this.provider = provider;\n this.name = `ai-sdk:${provider}`;\n this.label = `${capitalize(provider)} (AI SDK)`;\n this.defaultModel = config.model ?? PROVIDER_DEFAULT_MODELS[provider];\n this.supportedModels = PROVIDER_SUPPORTED_MODELS[provider];\n this.preserveCustomModels =\n provider === \"openai\" && Boolean(config.baseUrl);\n this.capabilities = PROVIDER_CAPABILITIES[provider];\n this.apiKey =\n config.apiKey ??\n (config.allowEnvFallback === false ? \"\" : getProviderApiKey(provider));\n this.baseUrl = config.baseUrl;\n this.appName = config.appName;\n this.appUrl = config.appUrl;\n }\n\n async *stream(opts: EngineStreamOptions): AsyncIterable<EngineEvent> {\n let aiModule: any;\n try {\n aiModule = await import(\"ai\");\n } catch {\n yield {\n type: \"stop\",\n reason: \"error\",\n error: `The \"ai\" package is not installed. Run: pnpm add ai ${PROVIDER_PACKAGES[this.provider]}`,\n };\n return;\n }\n\n const { streamText, jsonSchema } = aiModule;\n\n let providerModel: any;\n try {\n providerModel = await this.createProviderModel(opts.model);\n } catch (err: any) {\n yield {\n type: \"stop\",\n reason: \"error\",\n error: err?.message ?? String(err),\n };\n return;\n }\n\n const aiSdkTools =\n opts.tools.length > 0\n ? engineToolsToAISDK(opts.tools, jsonSchema)\n : undefined;\n const messages = engineMessagesToAISDK(opts.messages, {\n // Vision-capable provider translators (anthropic/openai/google/\n // openrouter) map image parts to native blocks; the rest stringify\n // tool-result content arrays, so images degrade to their text notes.\n toolResultImages: this.capabilities.vision,\n });\n\n // Resolved once so both `maxOutputTokens` (below, in the streamText call)\n // and the thinking-budget headroom clamp agree on the same ceiling.\n const resolvedMaxOutputTokens = resolveMaxOutputTokensForEngine(\n this.name,\n opts.maxOutputTokens,\n opts.model,\n );\n\n // Build providerOptions for Anthropic-native features when using Anthropic provider\n const providerOpts: Record<string, unknown> = {};\n if (this.provider === \"anthropic\" && opts.providerOptions?.anthropic) {\n const anthropicOpts = opts.providerOptions.anthropic;\n if (anthropicOpts.thinking) {\n // Only the \"enabled\" config carries a numeric budgetTokens; clamp it\n // so thinking can't consume the entire maxOutputTokens budget and\n // leave zero room for the actual response (\"adaptive\" thinking has\n // no budgetTokens field at all per @ai-sdk/anthropic's schema).\n providerOpts.anthropic = {\n ...((providerOpts.anthropic as object) ?? {}),\n thinking: {\n type: \"enabled\",\n budgetTokens:\n typeof anthropicOpts.thinking.budgetTokens === \"number\"\n ? clampThinkingBudgetTokens(\n anthropicOpts.thinking.budgetTokens,\n resolvedMaxOutputTokens,\n )\n : anthropicOpts.thinking.budgetTokens,\n },\n };\n }\n if (anthropicOpts.cacheControl) {\n providerOpts.anthropic = {\n ...((providerOpts.anthropic as object) ?? {}),\n cacheControl: anthropicOpts.cacheControl,\n };\n }\n }\n const reasoningEffort = normalizeReasoningEffortForModel(\n opts.model,\n opts.reasoningEffort,\n );\n if (reasoningEffort) {\n if (this.provider === \"anthropic\") {\n const explicitThinking = (\n providerOpts.anthropic as { thinking?: unknown } | undefined\n )?.thinking;\n if (explicitThinking || supportsClaudeAdaptiveThinking(opts.model)) {\n providerOpts.anthropic = {\n ...((providerOpts.anthropic as object) ?? {}),\n thinking: explicitThinking ?? { type: \"adaptive\" },\n ...(explicitThinking\n ? {}\n : { outputConfig: { effort: reasoningEffort } }),\n };\n } else {\n const budgetTokens = clampThinkingBudgetTokens(\n anthropicManualThinkingBudget(reasoningEffort),\n resolvedMaxOutputTokens,\n );\n providerOpts.anthropic = {\n ...((providerOpts.anthropic as object) ?? {}),\n ...(budgetTokens === undefined\n ? {}\n : { thinking: { type: \"enabled\", budgetTokens } }),\n };\n }\n } else if (this.provider === \"openai\") {\n providerOpts.openai = {\n ...((providerOpts.openai as object) ?? {}),\n reasoningEffort,\n };\n } else if (this.provider === \"openrouter\") {\n providerOpts.openrouter = {\n ...((providerOpts.openrouter as object) ?? {}),\n reasoning: { effort: reasoningEffort },\n };\n } else if (this.provider === \"google\") {\n // Gemini 3.x models reject thinkingBudget — they require thinkingLevel.\n // Gemini 2.5.x models use thinkingBudget (integer token count or -1).\n const isGemini3 = /^gemini-3/.test(opts.model);\n const thinkingBudget = googleThinkingBudget(reasoningEffort);\n providerOpts.google = {\n ...((providerOpts.google as object) ?? {}),\n thinkingConfig: isGemini3\n ? { thinkingLevel: gemini3ThinkingLevel(reasoningEffort) }\n : {\n // Unlike Anthropic's adaptive thinking, Gemini 2.5's\n // thinkingBudget IS a concrete numeric token count, so the\n // same headroom clamp applies: at \"max\" effort this maps to\n // 32000 tokens, which can equal (or exceed) a small\n // maxOutputTokens cap and leave zero room for the actual\n // response. Preserve Gemini's -1 \"dynamic\" sentinel.\n thinkingBudget:\n thinkingBudget > 0\n ? clampThinkingBudgetTokens(\n thinkingBudget,\n resolvedMaxOutputTokens,\n )\n : thinkingBudget,\n },\n };\n }\n }\n\n let assistantContent: EngineContentPart[] = [];\n const firstEventAbort = createFirstEventAbortController(opts.abortSignal);\n\n try {\n const result = streamText({\n model: providerModel,\n system: opts.systemPrompt,\n messages,\n tools: aiSdkTools,\n maxOutputTokens: resolvedMaxOutputTokens,\n ...(opts.temperature !== undefined\n ? { temperature: opts.temperature }\n : {}),\n abortSignal: firstEventAbort.signal,\n onStepFinish: (step: any) => {\n assistantContent = aiSdkStepToAssistantContent(step);\n },\n ...(Object.keys(providerOpts).length > 0\n ? { providerOptions: providerOpts }\n : {}),\n });\n\n // Buffer the terminal stop so assistant-content can be emitted just\n // before it, regardless of where `finish` arrives in the stream.\n let bufferedStop: EngineEvent | undefined;\n let sawFirstEvent = false;\n\n for await (const part of result.fullStream) {\n // \"start\" is a synthetic lifecycle marker the AI SDK enqueues\n // synchronously when the stream begins — before any provider bytes\n // arrive — so it does not count as real progress. Every other part\n // (including \"start-step\", only enqueued on the step's first real\n // chunk) proves the provider is actually responding.\n if (!sawFirstEvent && part?.type !== \"start\") {\n sawFirstEvent = true;\n firstEventAbort.markFirstEvent();\n }\n for (const event of aiSdkPartToEngineEvents(part)) {\n if (event.type === \"stop\") {\n bufferedStop = event;\n } else {\n yield event;\n }\n }\n }\n\n // AI SDK surfaces an aborted stream as a graceful `{type: \"abort\"}`\n // part rather than a thrown error, so a first-event timeout would\n // otherwise fall through to the normal end_turn completion below.\n if (!sawFirstEvent && firstEventAbort.didTimeout()) {\n throw new Error(\n `Model request produced no stream events within ${FIRST_STREAM_EVENT_TIMEOUT_MS / 1000}s; the connection appears wedged.`,\n );\n }\n\n yield { type: \"assistant-content\", parts: assistantContent };\n await clearProviderCredentialAuthFailure({\n key: PROVIDER_ENV_VARS[this.provider][0],\n value: this.apiKey,\n });\n yield bufferedStop ?? { type: \"stop\", reason: \"end_turn\" };\n } catch (err: any) {\n const timedOut = firstEventAbort.didTimeout();\n // Surface structured fields from AI SDK's APICallError so\n // isRetryableError can check statusCode/providerRetryable directly\n // rather than keyword-matching the message string.\n const statusCode: number | undefined =\n typeof err?.statusCode === \"number\" ? err.statusCode : undefined;\n const errorMessage = err?.message ?? String(err);\n const isConnectionError =\n !timedOut &&\n statusCode === undefined &&\n String(errorMessage).trim().toLowerCase() === \"connection error.\";\n const providerRetryable: boolean | undefined =\n typeof err?.isRetryable === \"boolean\"\n ? err.isRetryable\n : isConnectionError || timedOut\n ? true\n : undefined;\n if (statusCode === 401) {\n await recordProviderCredentialAuthFailure({\n key: PROVIDER_ENV_VARS[this.provider][0],\n value: this.apiKey,\n status: statusCode,\n code: \"http_401\",\n message: errorMessage,\n });\n }\n yield {\n type: \"stop\",\n reason: \"error\",\n error: errorMessage,\n // Tag every known status with `http_<status>` (not just 401) so a\n // rate limit surfaces as `http_429`. The structured statusCode\n // already drives turn-level retries, but the run-level continuation\n // logic keys off the errorCode, so this lets a rate-limited turn\n // auto-resume too — matching the Builder gateway path.\n ...(statusCode !== undefined\n ? { errorCode: `http_${statusCode}`, statusCode }\n : isConnectionError || timedOut\n ? { errorCode: \"provider_network_error\" }\n : {}),\n ...(providerRetryable !== undefined ? { providerRetryable } : {}),\n };\n throw err;\n } finally {\n firstEventAbort.cleanup();\n }\n }\n\n private async createProviderModel(model: string): Promise<any> {\n const pkg = PROVIDER_PACKAGES[this.provider];\n let providerModule: any;\n try {\n providerModule = await importProviderPackage(this.provider);\n } catch {\n throw new Error(\n `Provider package \"${pkg}\" is not installed. Run: pnpm add ai ${pkg}`,\n );\n }\n\n const fnName = PROVIDER_FACTORIES[this.provider];\n const createFn = providerModule[fnName] ?? providerModule.default;\n if (typeof createFn !== \"function\") {\n throw new Error(`\"${pkg}\" does not export ${fnName} or default`);\n }\n\n const config: Record<string, unknown> = {};\n if (this.apiKey !== undefined) config.apiKey = this.apiKey;\n if (this.baseUrl) config.baseURL = this.baseUrl;\n // Scoped to openrouter — other providers' factories may reject unknown keys.\n if (this.provider === \"openrouter\") {\n if (this.appName) config.appName = this.appName;\n if (this.appUrl) config.appUrl = this.appUrl;\n }\n\n const provider = createFn(config);\n // Let first-party OpenAI use the AI SDK's default Responses path so newer\n // GPT reasoning models get the API OpenAI recommends. If someone points\n // the OpenAI provider at an OpenAI-compatible gateway, keep using Chat\n // Completions because many gateway base URLs do not implement Responses.\n return this.provider === \"openai\" && this.baseUrl\n ? provider.chat(model)\n : provider(model);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Factory functions\n// ---------------------------------------------------------------------------\n\nexport function createAISDKEngine(\n provider: AISDKProvider,\n config: Record<string, unknown> = {},\n): AgentEngine {\n return new AISDKEngine(provider, config as AISDKEngineConfig);\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n// Static string-literal imports so bundlers (Nitro/Rollup/Vercel) can analyze\n// and include provider packages. A variable-based `import(pkg)` gets skipped.\nasync function importProviderPackage(provider: AISDKProvider): Promise<any> {\n switch (provider) {\n case \"anthropic\":\n return import(\"@ai-sdk/anthropic\");\n case \"openai\":\n return import(\"@ai-sdk/openai\");\n case \"openrouter\":\n return import(\"@openrouter/ai-sdk-provider\");\n case \"google\":\n return import(\"@ai-sdk/google\");\n case \"groq\":\n return import(\"@ai-sdk/groq\");\n case \"mistral\":\n return import(\"@ai-sdk/mistral\");\n case \"cohere\":\n return import(\"@ai-sdk/cohere\");\n case \"ollama\":\n return import(\"ai-sdk-ollama\");\n }\n}\n\nfunction capitalize(s: string): string {\n return s.charAt(0).toUpperCase() + s.slice(1);\n}\n\nfunction getProviderApiKey(provider: AISDKProvider): string | undefined {\n const envVars = PROVIDER_ENV_VARS[provider];\n for (const v of envVars) {\n const value = readDeployCredentialEnv(v);\n if (value) return value;\n }\n return undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Exports for registry registration\n// ---------------------------------------------------------------------------\n\nexport {\n PROVIDER_CAPABILITIES,\n PROVIDER_DEFAULT_MODELS,\n PROVIDER_SUPPORTED_MODELS,\n PROVIDER_ENV_VARS,\n PROVIDER_PACKAGES,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"ai-sdk-engine.js","sourceRoot":"","sources":["../../../src/agent/engine/ai-sdk-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,kCAAkC,EAClC,uBAAuB,EACvB,mCAAmC,GACpC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,6BAA6B,EAC7B,gCAAgC,EAChC,8BAA8B,GAC/B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAsB,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EACL,+BAA+B,EAC/B,6BAA6B,GAC9B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,yBAAyB,EACzB,+BAA+B,GAChC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,uBAAuB,CAA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AE9E,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,GAClB,CAAC","sourcesContent":["/**\n * AISDKEngine — wraps the Vercel AI SDK (ai package) for multi-provider support.\n *\n * Supports Anthropic, OpenAI, Google Gemini, Groq, and any provider with an\n * @ai-sdk/* package. Provider is selected via the `provider` config option.\n *\n * When provider is \"anthropic\", Anthropic-native features (thinking, cacheControl)\n * are forwarded through the AI SDK's providerOptions mechanism — no fidelity loss\n * compared to the native AnthropicEngine.\n *\n * The ai package is an OPTIONAL peer dependency. This engine uses dynamic import()\n * so the core package remains installable without the AI SDK.\n */\n\nimport {\n clearProviderCredentialAuthFailure,\n readDeployCredentialEnv,\n recordProviderCredentialAuthFailure,\n} from \"../../server/credential-provider.js\";\nimport {\n anthropicManualThinkingBudget,\n normalizeReasoningEffortForModel,\n supportsClaudeAdaptiveThinking,\n} from \"../../shared/reasoning-effort.js\";\nimport { AI_SDK_MODEL_CONFIG, type AISDKProvider } from \"../model-config.js\";\nimport { describeErrorWithCauses } from \"./error-detail.js\";\nimport {\n createFirstEventAbortController,\n FIRST_STREAM_EVENT_TIMEOUT_MS,\n} from \"./first-event-timeout.js\";\nimport {\n clampThinkingBudgetTokens,\n resolveMaxOutputTokensForEngine,\n} from \"./output-tokens.js\";\nimport {\n engineToolsToAISDK,\n engineMessagesToAISDK,\n aiSdkPartToEngineEvents,\n aiSdkStepToAssistantContent,\n} from \"./translate-ai-sdk.js\";\nimport {\n createStreamedToolInputState,\n finalizeStreamedToolInputs,\n observeStreamedToolInput,\n} from \"./translate-anthropic.js\";\nimport type {\n AgentEngine,\n EngineCapabilities,\n EngineStreamOptions,\n EngineEvent,\n EngineContentPart,\n} from \"./types.js\";\n\nexport type { AISDKProvider } from \"../model-config.js\";\n\n// ---------------------------------------------------------------------------\n// Provider definitions\n// ---------------------------------------------------------------------------\n\nconst PROVIDER_CAPABILITIES: Record<AISDKProvider, EngineCapabilities> = {\n anthropic: {\n thinking: true,\n promptCaching: true,\n vision: true,\n computerUse: false, // not exposed through AI SDK yet\n parallelToolCalls: true,\n },\n openai: {\n thinking: true,\n promptCaching: false,\n vision: true,\n computerUse: false,\n parallelToolCalls: true,\n },\n openrouter: {\n thinking: true,\n promptCaching: true,\n vision: true,\n computerUse: false,\n parallelToolCalls: true,\n },\n google: {\n thinking: true,\n promptCaching: false,\n vision: true,\n computerUse: false,\n parallelToolCalls: true,\n },\n groq: {\n thinking: false,\n promptCaching: false,\n vision: false,\n computerUse: false,\n parallelToolCalls: true,\n },\n mistral: {\n thinking: false,\n promptCaching: false,\n vision: false,\n computerUse: false,\n parallelToolCalls: true,\n },\n cohere: {\n thinking: false,\n promptCaching: false,\n vision: false,\n computerUse: false,\n parallelToolCalls: true,\n },\n ollama: {\n thinking: false,\n promptCaching: false,\n vision: false,\n computerUse: false,\n parallelToolCalls: false,\n },\n};\n\nconst providerModelEntries = Object.entries(AI_SDK_MODEL_CONFIG) as Array<\n [AISDKProvider, (typeof AI_SDK_MODEL_CONFIG)[AISDKProvider]]\n>;\n\nconst PROVIDER_DEFAULT_MODELS = Object.fromEntries(\n providerModelEntries.map(([provider, config]) => [\n provider,\n config.defaultModel,\n ]),\n) as Record<AISDKProvider, string>;\n\nconst PROVIDER_SUPPORTED_MODELS = Object.fromEntries(\n providerModelEntries.map(([provider, config]) => [\n provider,\n config.supportedModels,\n ]),\n) as unknown as Record<AISDKProvider, readonly string[]>;\n\nconst PROVIDER_ENV_VARS: Record<AISDKProvider, string[]> = {\n anthropic: [\"ANTHROPIC_API_KEY\"],\n openai: [\"OPENAI_API_KEY\"],\n openrouter: [\"OPENROUTER_API_KEY\"],\n google: [\"GOOGLE_GENERATIVE_AI_API_KEY\"],\n groq: [\"GROQ_API_KEY\"],\n mistral: [\"MISTRAL_API_KEY\"],\n cohere: [\"COHERE_API_KEY\"],\n ollama: [], // runs locally\n};\n\nconst PROVIDER_PACKAGES: Record<AISDKProvider, string> = {\n anthropic: \"@ai-sdk/anthropic\",\n openai: \"@ai-sdk/openai\",\n openrouter: \"@openrouter/ai-sdk-provider\",\n google: \"@ai-sdk/google\",\n groq: \"@ai-sdk/groq\",\n mistral: \"@ai-sdk/mistral\",\n cohere: \"@ai-sdk/cohere\",\n ollama: \"ai-sdk-ollama\",\n};\n\n/** Factory export name per provider (not all follow `create<Provider>`). */\nconst PROVIDER_FACTORIES: Record<AISDKProvider, string> = {\n anthropic: \"createAnthropic\",\n openai: \"createOpenAI\",\n openrouter: \"createOpenRouter\",\n google: \"createGoogleGenerativeAI\",\n groq: \"createGroq\",\n mistral: \"createMistral\",\n cohere: \"createCohere\",\n ollama: \"createOllama\",\n};\n\nfunction googleThinkingBudget(effort: string) {\n if (effort === \"low\") return 1024;\n // \"medium\" is a normalized effort for Gemini models; without this case it\n // fell through to the -1 (\"dynamic/unlimited\") fallback, so selecting\n // medium effort silently uncapped the thinking budget.\n if (effort === \"medium\") return 4096;\n if (effort === \"high\") return 8000;\n if (effort === \"xhigh\") return 16_000;\n if (effort === \"max\") return 32_000;\n return -1;\n}\n\n/**\n * Map a reasoning effort level to Gemini 3.x thinkingLevel string.\n * Gemini 3 models (gemini-3.*) reject thinkingBudget and require thinkingLevel\n * with values 'low' | 'medium' | 'high'. Gemini 3.0 only supports 'low'/'high';\n * Gemini 3.1+ adds 'medium'. We always emit 'medium' for medium effort since it\n * is accepted by 3.1+, and 3.0 is expected to be phased out quickly.\n */\nfunction gemini3ThinkingLevel(effort: string): string {\n if (effort === \"low\") return \"low\";\n if (effort === \"medium\") return \"medium\";\n // high/xhigh/max map to the strongest available level for Gemini 3.\n return \"high\";\n}\n\n// ---------------------------------------------------------------------------\n// AISDKEngine implementation\n// ---------------------------------------------------------------------------\n\n/** Config accepted by every `ai-sdk:*` engine. */\nexport interface AISDKEngineConfig {\n /** Override the provider's default model (also becomes the engine's defaultModel). */\n model?: string;\n /** API key — falls back to the provider-specific env var if omitted. */\n apiKey?: string;\n /** Set false in request-scoped multi-tenant runs so provider packages cannot fall back to process.env. */\n allowEnvFallback?: boolean;\n /** Override the provider base URL (useful for proxies or OpenAI-compatible gateways). */\n baseUrl?: string;\n /** OpenRouter: `X-OpenRouter-Title` header for dashboard attribution. */\n appName?: string;\n /** OpenRouter: `HTTP-Referer` header for dashboard attribution. */\n appUrl?: string;\n}\n\nclass AISDKEngine implements AgentEngine {\n readonly name: string;\n readonly label: string;\n readonly defaultModel: string;\n readonly supportedModels: readonly string[];\n readonly preserveCustomModels: boolean;\n readonly capabilities: EngineCapabilities;\n\n private readonly provider: AISDKProvider;\n private readonly apiKey?: string;\n private readonly baseUrl?: string;\n private readonly appName?: string;\n private readonly appUrl?: string;\n\n constructor(provider: AISDKProvider, config: AISDKEngineConfig) {\n this.provider = provider;\n this.name = `ai-sdk:${provider}`;\n this.label = `${capitalize(provider)} (AI SDK)`;\n this.defaultModel = config.model ?? PROVIDER_DEFAULT_MODELS[provider];\n this.supportedModels = PROVIDER_SUPPORTED_MODELS[provider];\n this.preserveCustomModels =\n provider === \"openai\" && Boolean(config.baseUrl);\n this.capabilities = PROVIDER_CAPABILITIES[provider];\n this.apiKey =\n config.apiKey ??\n (config.allowEnvFallback === false ? \"\" : getProviderApiKey(provider));\n this.baseUrl = config.baseUrl;\n this.appName = config.appName;\n this.appUrl = config.appUrl;\n }\n\n async *stream(opts: EngineStreamOptions): AsyncIterable<EngineEvent> {\n let aiModule: any;\n try {\n aiModule = await import(\"ai\");\n } catch {\n yield {\n type: \"stop\",\n reason: \"error\",\n error: `The \"ai\" package is not installed. Run: pnpm add ai ${PROVIDER_PACKAGES[this.provider]}`,\n };\n return;\n }\n\n const { streamText, jsonSchema } = aiModule;\n\n let providerModel: any;\n try {\n providerModel = await this.createProviderModel(opts.model);\n } catch (err: any) {\n yield {\n type: \"stop\",\n reason: \"error\",\n error: err?.message ?? String(err),\n };\n return;\n }\n\n const aiSdkTools =\n opts.tools.length > 0\n ? engineToolsToAISDK(opts.tools, jsonSchema)\n : undefined;\n const messages = engineMessagesToAISDK(opts.messages, {\n // Vision-capable provider translators (anthropic/openai/google/\n // openrouter) map image parts to native blocks; the rest stringify\n // tool-result content arrays, so images degrade to their text notes.\n toolResultImages: this.capabilities.vision,\n });\n\n // Resolved once so both `maxOutputTokens` (below, in the streamText call)\n // and the thinking-budget headroom clamp agree on the same ceiling.\n const resolvedMaxOutputTokens = resolveMaxOutputTokensForEngine(\n this.name,\n opts.maxOutputTokens,\n opts.model,\n );\n\n // Build providerOptions for Anthropic-native features when using Anthropic provider\n const providerOpts: Record<string, unknown> = {};\n if (this.provider === \"anthropic\" && opts.providerOptions?.anthropic) {\n const anthropicOpts = opts.providerOptions.anthropic;\n if (anthropicOpts.thinking) {\n // Only the \"enabled\" config carries a numeric budgetTokens; clamp it\n // so thinking can't consume the entire maxOutputTokens budget and\n // leave zero room for the actual response (\"adaptive\" thinking has\n // no budgetTokens field at all per @ai-sdk/anthropic's schema).\n providerOpts.anthropic = {\n ...((providerOpts.anthropic as object) ?? {}),\n thinking: {\n type: \"enabled\",\n budgetTokens:\n typeof anthropicOpts.thinking.budgetTokens === \"number\"\n ? clampThinkingBudgetTokens(\n anthropicOpts.thinking.budgetTokens,\n resolvedMaxOutputTokens,\n )\n : anthropicOpts.thinking.budgetTokens,\n },\n };\n }\n if (anthropicOpts.cacheControl) {\n providerOpts.anthropic = {\n ...((providerOpts.anthropic as object) ?? {}),\n cacheControl: anthropicOpts.cacheControl,\n };\n }\n }\n const reasoningEffort = normalizeReasoningEffortForModel(\n opts.model,\n opts.reasoningEffort,\n );\n if (reasoningEffort) {\n if (this.provider === \"anthropic\") {\n const explicitThinking = (\n providerOpts.anthropic as { thinking?: unknown } | undefined\n )?.thinking;\n if (explicitThinking || supportsClaudeAdaptiveThinking(opts.model)) {\n providerOpts.anthropic = {\n ...((providerOpts.anthropic as object) ?? {}),\n thinking: explicitThinking ?? { type: \"adaptive\" },\n ...(explicitThinking\n ? {}\n : { outputConfig: { effort: reasoningEffort } }),\n };\n } else {\n const budgetTokens = clampThinkingBudgetTokens(\n anthropicManualThinkingBudget(reasoningEffort),\n resolvedMaxOutputTokens,\n );\n providerOpts.anthropic = {\n ...((providerOpts.anthropic as object) ?? {}),\n ...(budgetTokens === undefined\n ? {}\n : { thinking: { type: \"enabled\", budgetTokens } }),\n };\n }\n } else if (this.provider === \"openai\") {\n // OpenAI rejects `reasoning_effort` together with function tools on\n // the legacy Chat Completions surface for some reasoning models\n // (\"Function tools with reasoning_effort are not supported for\n // <model> in /v1/chat/completions. To use function tools, use\n // /v1/responses or set reasoning_effort to 'none'.\") — a real prod\n // incident, e.g. Sentry AGENT-NATIVE-BROWSER-94 on gpt-5.6-terra.\n // `createProviderModel` forces Chat Completions specifically when\n // `this.baseUrl` is set (many OpenAI-compatible gateways/proxies\n // don't implement Responses — see that comment). In that exact\n // combination — forced Chat Completions AND tools present — drop\n // the explicit override and let the model use its default reasoning\n // behavior instead of hard-failing the whole request; Responses-API\n // calls (no baseUrl) are unaffected and keep full effort control.\n const forcedChatCompletionsWithTools =\n Boolean(this.baseUrl) && aiSdkTools !== undefined;\n if (!forcedChatCompletionsWithTools) {\n providerOpts.openai = {\n ...((providerOpts.openai as object) ?? {}),\n reasoningEffort,\n };\n }\n } else if (this.provider === \"openrouter\") {\n providerOpts.openrouter = {\n ...((providerOpts.openrouter as object) ?? {}),\n reasoning: { effort: reasoningEffort },\n };\n } else if (this.provider === \"google\") {\n // Gemini 3.x models reject thinkingBudget — they require thinkingLevel.\n // Gemini 2.5.x models use thinkingBudget (integer token count or -1).\n const isGemini3 = /^gemini-3/.test(opts.model);\n const thinkingBudget = googleThinkingBudget(reasoningEffort);\n providerOpts.google = {\n ...((providerOpts.google as object) ?? {}),\n thinkingConfig: isGemini3\n ? { thinkingLevel: gemini3ThinkingLevel(reasoningEffort) }\n : {\n // Unlike Anthropic's adaptive thinking, Gemini 2.5's\n // thinkingBudget IS a concrete numeric token count, so the\n // same headroom clamp applies: at \"max\" effort this maps to\n // 32000 tokens, which can equal (or exceed) a small\n // maxOutputTokens cap and leave zero room for the actual\n // response. Preserve Gemini's -1 \"dynamic\" sentinel.\n thinkingBudget:\n thinkingBudget > 0\n ? clampThinkingBudgetTokens(\n thinkingBudget,\n resolvedMaxOutputTokens,\n )\n : thinkingBudget,\n },\n };\n }\n }\n\n let assistantContent: EngineContentPart[] = [];\n const firstEventAbort = createFirstEventAbortController(opts.abortSignal);\n const toolInputs = createStreamedToolInputState();\n\n try {\n const result = streamText({\n model: providerModel,\n system: opts.systemPrompt,\n messages,\n tools: aiSdkTools,\n maxOutputTokens: resolvedMaxOutputTokens,\n // Explicit: the agent loop already retries a failed model call with\n // backoff. Leaving the SDK on its default (2) multiplies the two retry\n // layers into ~12 HTTP requests per failed run.\n maxRetries: 1,\n ...(opts.temperature !== undefined\n ? { temperature: opts.temperature }\n : {}),\n abortSignal: firstEventAbort.signal,\n onStepFinish: (step: any) => {\n assistantContent = aiSdkStepToAssistantContent(step);\n },\n ...(Object.keys(providerOpts).length > 0\n ? { providerOptions: providerOpts }\n : {}),\n });\n\n // Buffer the terminal stop so assistant-content can be emitted just\n // before it, regardless of where `finish` arrives in the stream.\n let bufferedStop: EngineEvent | undefined;\n let sawFirstEvent = false;\n\n for await (const part of result.fullStream) {\n // \"start\" is a synthetic lifecycle marker the AI SDK enqueues\n // synchronously when the stream begins — before any provider bytes\n // arrive — so it does not count as real progress. Every other part\n // (including \"start-step\", only enqueued on the step's first real\n // chunk) proves the provider is actually responding.\n if (!sawFirstEvent && part?.type !== \"start\") {\n sawFirstEvent = true;\n firstEventAbort.markFirstEvent();\n }\n for (const event of aiSdkPartToEngineEvents(part)) {\n observeStreamedToolInput(toolInputs, event);\n if (event.type === \"stop\") {\n bufferedStop = event;\n } else {\n yield event;\n }\n }\n }\n\n // AI SDK surfaces an aborted stream as a graceful `{type: \"abort\"}`\n // part rather than a thrown error, so a first-event timeout would\n // otherwise fall through to the normal end_turn completion below.\n if (!sawFirstEvent && firstEventAbort.didTimeout()) {\n throw new Error(\n `Model request produced no stream events within ${FIRST_STREAM_EVENT_TIMEOUT_MS / 1000}s; the connection appears wedged.`,\n );\n }\n\n // A step can finish having announced a tool call it never delivered.\n // Assemble it from its deltas, or report it in-band, rather than ending\n // the turn as if the model never asked for it.\n for (const recovered of finalizeStreamedToolInputs(\n toolInputs,\n assistantContent.flatMap((part) =>\n part.type === \"tool-call\" ? [part.id] : [],\n ),\n )) {\n if (recovered.type === \"tool-call\") {\n assistantContent.push({\n type: \"tool-call\",\n id: recovered.id,\n name: recovered.name,\n input: recovered.input,\n });\n }\n yield recovered;\n }\n\n yield { type: \"assistant-content\", parts: assistantContent };\n await clearProviderCredentialAuthFailure({\n key: PROVIDER_ENV_VARS[this.provider][0],\n value: this.apiKey,\n });\n yield bufferedStop ?? { type: \"stop\", reason: \"end_turn\" };\n } catch (err: any) {\n const timedOut = firstEventAbort.didTimeout();\n // Surface structured fields from AI SDK's APICallError so\n // isRetryableError can check statusCode/providerRetryable directly\n // rather than keyword-matching the message string.\n const statusCode: number | undefined =\n typeof err?.statusCode === \"number\" ? err.statusCode : undefined;\n const rawMessage: string = err?.message ?? String(err);\n // Classify on the bare message — the recorded `errorMessage` carries the\n // cause chain, which is where the real transport failure lives.\n const errorMessage = describeErrorWithCauses(err);\n const isConnectionError =\n !timedOut &&\n statusCode === undefined &&\n rawMessage.trim().toLowerCase() === \"connection error.\";\n const providerRetryable: boolean | undefined =\n typeof err?.isRetryable === \"boolean\"\n ? err.isRetryable\n : isConnectionError || timedOut\n ? true\n : undefined;\n if (statusCode === 401) {\n await recordProviderCredentialAuthFailure({\n key: PROVIDER_ENV_VARS[this.provider][0],\n value: this.apiKey,\n status: statusCode,\n code: \"http_401\",\n message: errorMessage,\n });\n }\n yield {\n type: \"stop\",\n reason: \"error\",\n error: errorMessage,\n // Tag every known status with `http_<status>` (not just 401) so a\n // rate limit surfaces as `http_429`. The structured statusCode\n // already drives turn-level retries, but the run-level continuation\n // logic keys off the errorCode, so this lets a rate-limited turn\n // auto-resume too — matching the Builder gateway path.\n ...(statusCode !== undefined\n ? { errorCode: `http_${statusCode}`, statusCode }\n : isConnectionError || timedOut\n ? { errorCode: \"provider_network_error\" }\n : {}),\n ...(providerRetryable !== undefined ? { providerRetryable } : {}),\n };\n throw err;\n } finally {\n firstEventAbort.cleanup();\n }\n }\n\n private async createProviderModel(model: string): Promise<any> {\n const pkg = PROVIDER_PACKAGES[this.provider];\n let providerModule: any;\n try {\n providerModule = await importProviderPackage(this.provider);\n } catch {\n throw new Error(\n `Provider package \"${pkg}\" is not installed. Run: pnpm add ai ${pkg}`,\n );\n }\n\n const fnName = PROVIDER_FACTORIES[this.provider];\n const createFn = providerModule[fnName] ?? providerModule.default;\n if (typeof createFn !== \"function\") {\n throw new Error(`\"${pkg}\" does not export ${fnName} or default`);\n }\n\n const config: Record<string, unknown> = {};\n if (this.apiKey !== undefined) config.apiKey = this.apiKey;\n if (this.baseUrl) config.baseURL = this.baseUrl;\n // Scoped to openrouter — other providers' factories may reject unknown keys.\n if (this.provider === \"openrouter\") {\n if (this.appName) config.appName = this.appName;\n if (this.appUrl) config.appUrl = this.appUrl;\n }\n\n const provider = createFn(config);\n // Let first-party OpenAI use the AI SDK's default Responses path so newer\n // GPT reasoning models get the API OpenAI recommends. If someone points\n // the OpenAI provider at an OpenAI-compatible gateway, keep using Chat\n // Completions because many gateway base URLs do not implement Responses.\n return this.provider === \"openai\" && this.baseUrl\n ? provider.chat(model)\n : provider(model);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Factory functions\n// ---------------------------------------------------------------------------\n\nexport function createAISDKEngine(\n provider: AISDKProvider,\n config: Record<string, unknown> = {},\n): AgentEngine {\n return new AISDKEngine(provider, config as AISDKEngineConfig);\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n// Static string-literal imports so bundlers (Nitro/Rollup/Vercel) can analyze\n// and include provider packages. A variable-based `import(pkg)` gets skipped.\nasync function importProviderPackage(provider: AISDKProvider): Promise<any> {\n switch (provider) {\n case \"anthropic\":\n return import(\"@ai-sdk/anthropic\");\n case \"openai\":\n return import(\"@ai-sdk/openai\");\n case \"openrouter\":\n return import(\"@openrouter/ai-sdk-provider\");\n case \"google\":\n return import(\"@ai-sdk/google\");\n case \"groq\":\n return import(\"@ai-sdk/groq\");\n case \"mistral\":\n return import(\"@ai-sdk/mistral\");\n case \"cohere\":\n return import(\"@ai-sdk/cohere\");\n case \"ollama\":\n return import(\"ai-sdk-ollama\");\n }\n}\n\nfunction capitalize(s: string): string {\n return s.charAt(0).toUpperCase() + s.slice(1);\n}\n\nfunction getProviderApiKey(provider: AISDKProvider): string | undefined {\n const envVars = PROVIDER_ENV_VARS[provider];\n for (const v of envVars) {\n const value = readDeployCredentialEnv(v);\n if (value) return value;\n }\n return undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Exports for registry registration\n// ---------------------------------------------------------------------------\n\nexport {\n PROVIDER_CAPABILITIES,\n PROVIDER_DEFAULT_MODELS,\n PROVIDER_SUPPORTED_MODELS,\n PROVIDER_ENV_VARS,\n PROVIDER_PACKAGES,\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-engine.d.ts","sourceRoot":"","sources":["../../../src/agent/engine/anthropic-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"anthropic-engine.d.ts","sourceRoot":"","sources":["../../../src/agent/engine/anthropic-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAwCH,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAGnB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,sBAAsB,EAAE,kBAMpC,CAAC;AAEF,eAAO,MAAM,0BAA0B,sHACC,CAAC;AACzC,eAAO,MAAM,uBAAuB,yCAAsC,CAAC;AA2R3E;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACnC,WAAW,CAyBb"}
|
|
@@ -11,9 +11,11 @@ import { clearProviderCredentialAuthFailure, readDeployCredentialEnv, recordProv
|
|
|
11
11
|
import { anthropicManualThinkingBudget, normalizeReasoningEffortForModel, supportsClaudeAdaptiveThinking, } from "../../shared/reasoning-effort.js";
|
|
12
12
|
import { ANTHROPIC_MODEL_CONFIG } from "../model-config.js";
|
|
13
13
|
import { LLM_MISSING_CREDENTIALS_ERROR_CODE, LLM_MISSING_CREDENTIALS_MESSAGE, } from "./credential-errors.js";
|
|
14
|
+
import { describeErrorWithCauses } from "./error-detail.js";
|
|
14
15
|
import { createFirstEventAbortController, FIRST_STREAM_EVENT_TIMEOUT_MS, } from "./first-event-timeout.js";
|
|
15
16
|
import { clampThinkingBudgetTokens, resolveMaxOutputTokensForEngine, } from "./output-tokens.js";
|
|
16
|
-
import {
|
|
17
|
+
import { splitSystemPromptForCache, stablePrefixCacheControl, } from "./prompt-cache.js";
|
|
18
|
+
import { engineToolsToAnthropic, engineMessagesToAnthropic, anthropicContentToEngine, anthropicChunkToEngineEvents, createAnthropicChunkStreamState, createStreamedToolInputState, finalizeStreamedToolInputs, observeStreamedToolInput, } from "./translate-anthropic.js";
|
|
17
19
|
export const ANTHROPIC_CAPABILITIES = {
|
|
18
20
|
thinking: true,
|
|
19
21
|
promptCaching: true,
|
|
@@ -35,7 +37,10 @@ class AnthropicEngine {
|
|
|
35
37
|
}
|
|
36
38
|
async *stream(opts) {
|
|
37
39
|
const Anthropic = (await import("@anthropic-ai/sdk")).default;
|
|
38
|
-
|
|
40
|
+
// Explicit: the agent loop already retries a failed model call up to
|
|
41
|
+
// MAX_RETRIES times with backoff. Leaving the SDK on its default (2)
|
|
42
|
+
// multiplies the two layers into ~12 HTTP requests per failed run.
|
|
43
|
+
const client = new Anthropic({ apiKey: this.apiKey, maxRetries: 1 });
|
|
39
44
|
const tools = engineToolsToAnthropic(opts.tools);
|
|
40
45
|
const messages = engineMessagesToAnthropic(opts.messages);
|
|
41
46
|
const anthropicOpts = opts.providerOptions?.anthropic;
|
|
@@ -79,23 +84,32 @@ class AnthropicEngine {
|
|
|
79
84
|
// changes turn-to-turn, it's a no-op. Templates can opt out by setting
|
|
80
85
|
// providerOptions.anthropic.cacheControl = false.
|
|
81
86
|
const cacheEnabled = anthropicOpts?.cacheControl !== false;
|
|
82
|
-
|
|
87
|
+
// Two system blocks: the breakpoint sits on the stable prefix so a change
|
|
88
|
+
// in the volatile tail (resources the agent itself creates mid-turn, app
|
|
89
|
+
// extras, model overlay, runtime context) no longer invalidates system +
|
|
90
|
+
// tools. Callers that emit no sentinel get one block, as before.
|
|
91
|
+
const { stable, volatile } = splitSystemPromptForCache(opts.systemPrompt);
|
|
92
|
+
const systemBlocks = [{ type: "text", text: stable }];
|
|
83
93
|
if (cacheEnabled) {
|
|
84
|
-
systemBlocks[0].cache_control =
|
|
94
|
+
systemBlocks[0].cache_control = stablePrefixCacheControl();
|
|
85
95
|
}
|
|
96
|
+
if (volatile)
|
|
97
|
+
systemBlocks.push({ type: "text", text: volatile });
|
|
86
98
|
// Apply cache_control to the last tool definition when caching is enabled.
|
|
87
99
|
// Anthropic caches the prefix up to and including the last cached block.
|
|
88
100
|
let cachedTools = tools;
|
|
89
101
|
if (cacheEnabled && tools.length > 0) {
|
|
90
102
|
cachedTools = [...tools];
|
|
91
103
|
const last = { ...cachedTools[cachedTools.length - 1] };
|
|
92
|
-
last.cache_control =
|
|
104
|
+
last.cache_control = stablePrefixCacheControl();
|
|
93
105
|
cachedTools[cachedTools.length - 1] = last;
|
|
94
106
|
}
|
|
95
107
|
// Apply a moving cache breakpoint on the last user message's last content
|
|
96
108
|
// block so the entire conversation prefix (system + tools + growing
|
|
97
109
|
// history) is cached turn-over-turn as the thread lengthens. Mirrors the
|
|
98
|
-
// Builder gateway engine's identical handling in builder-engine.ts.
|
|
110
|
+
// Builder gateway engine's identical handling in builder-engine.ts. This
|
|
111
|
+
// breakpoint keeps the default 5m TTL: it moves every iteration, so a
|
|
112
|
+
// longer-lived entry would only pay the higher write premium.
|
|
99
113
|
let cachedMessages = messages;
|
|
100
114
|
if (cacheEnabled && messages.length > 0) {
|
|
101
115
|
let lastUserIdx = -1;
|
|
@@ -141,6 +155,7 @@ class AnthropicEngine {
|
|
|
141
155
|
// long tool-input generation emits countable `tool-input-start` /
|
|
142
156
|
// `tool-input-delta` progress events (mirroring the Builder engine).
|
|
143
157
|
const chunkState = createAnthropicChunkStreamState();
|
|
158
|
+
const toolInputs = createStreamedToolInputState();
|
|
144
159
|
try {
|
|
145
160
|
for await (const chunk of apiStream) {
|
|
146
161
|
// The SDK's SSE parsing already drops `ping` keepalives before they
|
|
@@ -148,11 +163,26 @@ class AnthropicEngine {
|
|
|
148
163
|
firstEventAbort.markFirstEvent();
|
|
149
164
|
const events = anthropicChunkToEngineEvents(chunk, chunkState);
|
|
150
165
|
for (const event of events) {
|
|
166
|
+
observeStreamedToolInput(toolInputs, event);
|
|
151
167
|
yield event;
|
|
152
168
|
}
|
|
153
169
|
}
|
|
154
170
|
const finalMessage = await apiStream.finalMessage();
|
|
155
171
|
const assistantContent = anthropicContentToEngine(finalMessage.content);
|
|
172
|
+
// A tool call the stream announced but the final message never carried
|
|
173
|
+
// would otherwise vanish, leaving the turn claiming an action it never
|
|
174
|
+
// ran. Recover it from its deltas, or tell the model in-band.
|
|
175
|
+
for (const recovered of finalizeStreamedToolInputs(toolInputs, assistantContent.flatMap((part) => part.type === "tool-call" ? [part.id] : []))) {
|
|
176
|
+
if (recovered.type === "tool-call") {
|
|
177
|
+
assistantContent.push({
|
|
178
|
+
type: "tool-call",
|
|
179
|
+
id: recovered.id,
|
|
180
|
+
name: recovered.name,
|
|
181
|
+
input: recovered.input,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
yield recovered;
|
|
185
|
+
}
|
|
156
186
|
// Emit usage
|
|
157
187
|
if (finalMessage.usage) {
|
|
158
188
|
yield {
|
|
@@ -189,15 +219,17 @@ class AnthropicEngine {
|
|
|
189
219
|
// A first-event abort surfaces from the SDK as a generic
|
|
190
220
|
// APIUserAbortError ("Request was aborted.") — replace it with a
|
|
191
221
|
// message that actually explains what happened.
|
|
222
|
+
const rawMessage = err?.message ?? String(err);
|
|
192
223
|
const errorMessage = timedOut
|
|
193
224
|
? `Model request produced no stream events within ${FIRST_STREAM_EVENT_TIMEOUT_MS / 1000}s; the connection appears wedged.`
|
|
194
|
-
: (err
|
|
225
|
+
: describeErrorWithCauses(err);
|
|
195
226
|
// Anthropic SDK APIConnectionError defaults to "Connection error." with
|
|
196
227
|
// no HTTP status. Tag it so in-run retries and run-level resume treat
|
|
197
|
-
// the failure as a transient network interruption.
|
|
228
|
+
// the failure as a transient network interruption. Classify on the bare
|
|
229
|
+
// message — the recorded `errorMessage` carries the cause chain.
|
|
198
230
|
const isConnectionError = !timedOut &&
|
|
199
231
|
statusCode === undefined &&
|
|
200
|
-
|
|
232
|
+
rawMessage.trim().toLowerCase() === "connection error.";
|
|
201
233
|
if (statusCode === 401) {
|
|
202
234
|
await recordProviderCredentialAuthFailure({
|
|
203
235
|
key: "ANTHROPIC_API_KEY",
|