@agent-native/core 0.164.3 → 0.164.11

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.
Files changed (234) hide show
  1. package/corpus/README.md +1 -1
  2. package/corpus/templates/calendar/app/components/calendar/CreateEventDialog.tsx +36 -47
  3. package/corpus/templates/calendar/app/components/calendar/DayView.tsx +3 -0
  4. package/corpus/templates/calendar/app/components/calendar/EventDetailPopover.tsx +18 -1
  5. package/corpus/templates/calendar/app/components/calendar/InlineEventPickers.tsx +256 -38
  6. package/corpus/templates/calendar/app/hooks/use-google-auth.ts +43 -3
  7. package/corpus/templates/calendar/app/i18n-data.ts +120 -0
  8. package/corpus/templates/calendar/app/lib/event-form-utils.ts +113 -0
  9. package/corpus/templates/calendar/server/handlers/google-auth.ts +119 -3
  10. package/corpus/templates/calendar/server/routes/[base]/_agent-native/google/add-account/auth-url.post.ts +1 -0
  11. package/corpus/templates/calendar/server/routes/[base]/_agent-native/google/auth-url.post.ts +1 -0
  12. package/corpus/templates/calendar/server/routes/_agent-native/google/add-account/auth-url.post.ts +1 -0
  13. package/corpus/templates/calendar/server/routes/_agent-native/google/auth-url.post.ts +1 -0
  14. package/corpus/templates/clips/.agents/skills/video-sharing/SKILL.md +1 -1
  15. package/corpus/templates/clips/app/components/player/video-player.tsx +12 -0
  16. package/corpus/templates/clips/app/routes/_app.dictate.tsx +18 -4
  17. package/corpus/templates/clips/app/routes/r.$recordingId.tsx +114 -20
  18. package/corpus/templates/clips/app/routes/share.$shareId.tsx +86 -78
  19. package/corpus/templates/clips/changelog/2026-08-19-clips-nightly-builds-are-available-for-trying-the-latest-upd.md +6 -0
  20. package/corpus/templates/clips/changelog/2026-08-19-social-preview-video-frames.md +6 -0
  21. package/corpus/templates/clips/desktop/README.md +19 -4
  22. package/corpus/templates/clips/desktop/src/app.tsx +78 -16
  23. package/corpus/templates/clips/desktop/src-tauri/Cargo.toml +3 -2
  24. package/corpus/templates/clips/desktop/src-tauri/tauri.conf.json +1 -0
  25. package/corpus/templates/clips/server/lib/slack-unfurls.ts +7 -13
  26. package/corpus/templates/clips/server/routes/[base]/_agent-native/google/auth-url.post.ts +1 -0
  27. package/corpus/templates/clips/server/routes/_agent-native/google/auth-url.get.ts +41 -3
  28. package/corpus/templates/clips/server/routes/_agent-native/google/auth-url.post.ts +1 -0
  29. package/corpus/templates/clips/server/routes/_agent-native/google/callback.get.ts +22 -1
  30. package/corpus/templates/clips/server/routes/api/clips-updater.json.get.ts +41 -22
  31. package/corpus/templates/clips/shared/share-meta.ts +67 -3
  32. package/corpus/templates/content/actions/list-content-databases.ts +95 -1
  33. package/corpus/templates/content/changelog/2026-08-11-content-mutations-delegated-from-verified-slack-dms-now-use-.md +6 -0
  34. package/corpus/templates/content/shared/api.ts +11 -0
  35. package/corpus/templates/factory/AGENTS.md +1 -1
  36. package/corpus/templates/factory/actions/list-factory-automations.ts +4 -0
  37. package/corpus/templates/factory/actions/start-builder-for-item.ts +19 -17
  38. package/corpus/templates/factory/app/components/factory/FactoryAuditView.tsx +100 -36
  39. package/corpus/templates/factory/app/i18n/en-US.ts +4 -0
  40. package/corpus/templates/factory/app/routes/factory.tsx +209 -46
  41. package/corpus/templates/factory/server/connectors/slack.ts +44 -2
  42. package/corpus/templates/factory/server/plugins/agent-chat.ts +9 -7
  43. package/corpus/templates/factory/server/plugins/factory-scheduler-job.ts +13 -0
  44. package/corpus/templates/factory/server/triage/slack-client.ts +5 -0
  45. package/corpus/templates/factory/server/triage/slack-poller.ts +72 -4
  46. package/corpus/templates/mail/actions/view-screen.ts +1 -1
  47. package/corpus/templates/mail/app/components/GoogleConnectBanner.tsx +100 -18
  48. package/corpus/templates/mail/server/handlers/google-auth.ts +125 -24
  49. package/corpus/templates/mail/server/lib/gmail-query.ts +5 -2
  50. package/corpus/templates/mail/server/routes/[base]/_agent-native/google/add-account/auth-url.post.ts +1 -0
  51. package/corpus/templates/mail/server/routes/[base]/_agent-native/google/auth-url.post.ts +1 -0
  52. package/corpus/templates/mail/server/routes/_agent-native/google/add-account/auth-url.post.ts +1 -0
  53. package/corpus/templates/mail/server/routes/_agent-native/google/auth-url.post.ts +1 -0
  54. package/corpus/templates/plan/app/pages/PlansPage.tsx +0 -12
  55. package/corpus/templates/plan/changelog/2026-08-19-plan-prompts-now-guide-you-to-connect-ai-before-sending-and-.md +6 -0
  56. package/corpus/templates/slides/actions/approve-deck-access-request.ts +234 -0
  57. package/corpus/templates/slides/actions/get-deck-access-status.ts +35 -2
  58. package/corpus/templates/slides/actions/request-deck-access.ts +263 -64
  59. package/corpus/templates/slides/app/components/editor/MissingDeckAccessPane.tsx +196 -0
  60. package/corpus/templates/slides/app/components/editor/RequestDeckAccessDialog.tsx +101 -0
  61. package/corpus/templates/slides/app/hooks/use-deck-access.ts +7 -4
  62. package/corpus/templates/slides/app/i18n/en-US.ts +29 -6
  63. package/corpus/templates/slides/app/pages/DeckEditor.tsx +147 -169
  64. package/corpus/templates/slides/app/routes/access-request.approve.tsx +250 -0
  65. package/corpus/templates/slides/server/db/schema.ts +8 -0
  66. package/corpus/templates/slides/server/lib/access-request-email.ts +36 -0
  67. package/corpus/templates/slides/server/lib/emails.ts +26 -0
  68. package/corpus/templates/slides/server/plugins/agent-chat.ts +7 -0
  69. package/corpus/templates/slides/server/plugins/db.ts +50 -0
  70. package/corpus/templates/slides/shared/deck-access.ts +31 -0
  71. package/dist/a2a/artifact-response.d.ts +50 -0
  72. package/dist/a2a/artifact-response.js +266 -39
  73. package/dist/a2a/index.d.ts +2 -0
  74. package/dist/a2a/index.js +1 -0
  75. package/dist/a2a/task-store.d.ts +1 -0
  76. package/dist/a2a/task-store.js +1 -1
  77. package/dist/agent/observational-memory/store.d.ts +1 -0
  78. package/dist/agent/observational-memory/store.js +1 -1
  79. package/dist/agent/run-store.d.ts +1 -0
  80. package/dist/agent/run-store.js +1 -1
  81. package/dist/agent/tool-approval-store.d.ts +1 -0
  82. package/dist/agent/tool-approval-store.js +1 -1
  83. package/dist/application-state/store.d.ts +1 -0
  84. package/dist/application-state/store.js +1 -1
  85. package/dist/browser-sessions/store.d.ts +1 -0
  86. package/dist/browser-sessions/store.js +1 -1
  87. package/dist/checkpoints/store.d.ts +1 -0
  88. package/dist/checkpoints/store.js +1 -1
  89. package/dist/cli/code-agent-schedules.d.ts +11 -0
  90. package/dist/cli/code-agent-schedules.js +44 -5
  91. package/dist/client/AgentPanel.d.ts +5 -1
  92. package/dist/client/AgentPanel.js +2 -2
  93. package/dist/client/AssistantChat.d.ts +5 -1
  94. package/dist/client/AssistantChat.js +40 -6
  95. package/dist/client/EnvironmentBadge.d.ts +7 -13
  96. package/dist/client/EnvironmentBadge.js +43 -92
  97. package/dist/client/agent-chat/index.d.ts +1 -0
  98. package/dist/client/agent-chat/index.js +1 -0
  99. package/dist/client/agent-chat-adapter.js +76 -50
  100. package/dist/client/app-providers.js +4 -4
  101. package/dist/client/chat/message-components.d.ts +4 -0
  102. package/dist/client/chat/message-components.js +28 -1
  103. package/dist/client/chat/run-recovery.js +26 -0
  104. package/dist/client/chat-first/apps-rail.d.ts +1 -0
  105. package/dist/client/chat-first/apps-rail.js +28 -2
  106. package/dist/client/sse-event-processor.js +13 -8
  107. package/dist/client/use-active-agent-chat-run.d.ts +2 -0
  108. package/dist/client/use-active-agent-chat-run.js +22 -0
  109. package/dist/coding-tools/sandbox/executions-store.d.ts +1 -0
  110. package/dist/coding-tools/sandbox/executions-store.js +1 -1
  111. package/dist/collab/awareness-store.d.ts +1 -0
  112. package/dist/collab/awareness-store.js +1 -1
  113. package/dist/collab/routes.d.ts +1 -1
  114. package/dist/collab/storage.d.ts +1 -0
  115. package/dist/collab/storage.js +1 -1
  116. package/dist/db/client.js +3 -3
  117. package/dist/db/ddl-guard.js +8 -0
  118. package/dist/db/migration-runtime.d.ts +23 -0
  119. package/dist/db/migration-runtime.js +41 -0
  120. package/dist/db/migrations.d.ts +1 -2
  121. package/dist/db/migrations.js +2 -24
  122. package/dist/email-catalog/log.d.ts +1 -0
  123. package/dist/email-catalog/log.js +1 -1
  124. package/dist/guards/index.d.ts +1 -0
  125. package/dist/guards/index.js +1 -0
  126. package/dist/guards/release-schema-complete.d.ts +22 -0
  127. package/dist/guards/release-schema-complete.js +144 -0
  128. package/dist/integrations/a2a-continuations-store.d.ts +1 -0
  129. package/dist/integrations/a2a-continuations-store.js +1 -1
  130. package/dist/integrations/adapters/slack.js +58 -7
  131. package/dist/integrations/awaiting-input-store.d.ts +1 -0
  132. package/dist/integrations/awaiting-input-store.js +1 -1
  133. package/dist/integrations/config-store.d.ts +1 -0
  134. package/dist/integrations/config-store.js +1 -1
  135. package/dist/integrations/controls-store.d.ts +1 -0
  136. package/dist/integrations/controls-store.js +1 -1
  137. package/dist/integrations/identity-links-store.d.ts +1 -0
  138. package/dist/integrations/identity-links-store.js +1 -1
  139. package/dist/integrations/installations-store.d.ts +1 -0
  140. package/dist/integrations/installations-store.js +1 -1
  141. package/dist/integrations/remote-commands-store.d.ts +1 -0
  142. package/dist/integrations/remote-commands-store.js +1 -1
  143. package/dist/integrations/remote-devices-store.d.ts +1 -0
  144. package/dist/integrations/remote-devices-store.js +1 -1
  145. package/dist/integrations/remote-push-store.d.ts +1 -0
  146. package/dist/integrations/remote-push-store.js +1 -1
  147. package/dist/integrations/remote-run-events-store.d.ts +1 -0
  148. package/dist/integrations/remote-run-events-store.js +1 -1
  149. package/dist/integrations/scope-store.d.ts +1 -0
  150. package/dist/integrations/scope-store.js +1 -1
  151. package/dist/integrations/thread-mapping-store.d.ts +1 -0
  152. package/dist/integrations/thread-mapping-store.js +1 -1
  153. package/dist/integrations/usage-budget-store.d.ts +1 -0
  154. package/dist/integrations/usage-budget-store.js +1 -1
  155. package/dist/jobs/background-automation-runner.js +111 -9
  156. package/dist/jobs/run-history.d.ts +1 -0
  157. package/dist/jobs/run-history.js +1 -1
  158. package/dist/jobs/scheduler-health.d.ts +1 -0
  159. package/dist/jobs/scheduler-health.js +1 -1
  160. package/dist/mcp/approval-store.d.ts +1 -0
  161. package/dist/mcp/approval-store.js +1 -1
  162. package/dist/mcp/connect-store.d.ts +1 -0
  163. package/dist/mcp/connect-store.js +1 -1
  164. package/dist/mcp/oauth-store.d.ts +1 -0
  165. package/dist/mcp/oauth-store.js +1 -1
  166. package/dist/notifications/routes.d.ts +3 -3
  167. package/dist/notifications/store.d.ts +1 -0
  168. package/dist/notifications/store.js +1 -1
  169. package/dist/oauth-tokens/store.d.ts +1 -0
  170. package/dist/oauth-tokens/store.js +1 -1
  171. package/dist/observability/routes.d.ts +3 -3
  172. package/dist/progress/routes.d.ts +1 -1
  173. package/dist/progress/store.d.ts +1 -0
  174. package/dist/progress/store.js +1 -1
  175. package/dist/provider-api/actions/custom-provider-registration.d.ts +5 -5
  176. package/dist/provider-api/actions/provider-api.d.ts +4 -4
  177. package/dist/provider-api/corpus-jobs-store.d.ts +1 -0
  178. package/dist/provider-api/corpus-jobs-store.js +1 -1
  179. package/dist/provider-api/custom-registry.d.ts +1 -0
  180. package/dist/provider-api/custom-registry.js +1 -1
  181. package/dist/provider-api/quota-governor.d.ts +1 -0
  182. package/dist/provider-api/quota-governor.js +1 -1
  183. package/dist/provider-api/staged-datasets-store.d.ts +1 -0
  184. package/dist/provider-api/staged-datasets-store.js +1 -1
  185. package/dist/resources/handlers.d.ts +3 -3
  186. package/dist/resources/store.d.ts +1 -0
  187. package/dist/resources/store.js +1 -1
  188. package/dist/scripts/dev/index.js +15 -1
  189. package/dist/search/index.js +3 -0
  190. package/dist/secrets/storage.d.ts +1 -0
  191. package/dist/secrets/storage.js +1 -1
  192. package/dist/server/agent-chat/action-filters-a2a.d.ts +2 -1
  193. package/dist/server/agent-chat/action-filters-a2a.js +10 -2
  194. package/dist/server/agent-chat-plugin.js +71 -20
  195. package/dist/server/agent-teams-run-queue.d.ts +1 -0
  196. package/dist/server/agent-teams-run-queue.js +1 -1
  197. package/dist/server/auth-marketing.js +3 -1
  198. package/dist/server/auth.d.ts +18 -1
  199. package/dist/server/auth.js +370 -154
  200. package/dist/server/embed-session.d.ts +1 -0
  201. package/dist/server/embed-session.js +1 -1
  202. package/dist/server/google-auth-plugin.js +3 -1
  203. package/dist/server/google-oauth.d.ts +10 -0
  204. package/dist/server/google-oauth.js +25 -1
  205. package/dist/server/identity-sso-store.d.ts +1 -0
  206. package/dist/server/identity-sso-store.js +1 -1
  207. package/dist/server/index.d.ts +1 -1
  208. package/dist/server/index.js +1 -1
  209. package/dist/server/onboarding-html.js +200 -31
  210. package/dist/server/poll.d.ts +2 -0
  211. package/dist/server/poll.js +19 -1
  212. package/dist/server/realtime-token.d.ts +1 -1
  213. package/dist/server/release-migrations.js +5 -0
  214. package/dist/server/release-schema.d.ts +46 -0
  215. package/dist/server/release-schema.js +307 -0
  216. package/dist/settings/store.d.ts +1 -0
  217. package/dist/settings/store.js +1 -1
  218. package/dist/shared/environment-lanes.d.ts +28 -0
  219. package/dist/shared/environment-lanes.js +61 -0
  220. package/dist/sharing/actions/share-resource.js +22 -2
  221. package/dist/styles/agent-native.css +17 -15
  222. package/dist/triggers/routes.d.ts +11 -0
  223. package/dist/triggers/routes.js +10 -0
  224. package/dist/usage/alerts-store.d.ts +1 -0
  225. package/dist/usage/alerts-store.js +1 -1
  226. package/dist/usage/store.d.ts +1 -0
  227. package/dist/usage/store.js +1 -1
  228. package/docs/content/drop-in-agent.mdx +4 -4
  229. package/docs/content/faq.mdx +15 -15
  230. package/docs/content/getting-started.mdx +173 -41
  231. package/docs/content/key-concepts.mdx +10 -10
  232. package/docs/content/using-your-agent.mdx +2 -2
  233. package/docs/content/what-is-agent-native.mdx +79 -228
  234. package/package.json +2 -2
@@ -32,7 +32,7 @@ const INDEXES = [
32
32
  ON ${TABLE}(org_id, user_email)`,
33
33
  ],
34
34
  ];
35
- async function ensureTable() {
35
+ export async function ensureTable() {
36
36
  if (!_initPromise) {
37
37
  _initPromise = (async () => {
38
38
  const client = getDbExec();
@@ -83,6 +83,7 @@ export interface IntegrationInstallationUpdate {
83
83
  lastHealthyAt?: number | null;
84
84
  tokenExpiresAt?: number | null;
85
85
  }
86
+ export declare function ensureTable(): Promise<void>;
86
87
  /**
87
88
  * Create or refresh a managed install. Re-installs may rotate tokens inside
88
89
  * the same owner/org scope, but cannot silently move an existing provider
@@ -61,7 +61,7 @@ const INDEXES = [
61
61
  `CREATE INDEX IF NOT EXISTS idx_integration_installations_org ON ${TABLE}(org_id, updated_at)`,
62
62
  ],
63
63
  ];
64
- async function ensureTable() {
64
+ export async function ensureTable() {
65
65
  if (!_initPromise) {
66
66
  _initPromise = (async () => {
67
67
  const client = getDbExec();
@@ -1,4 +1,5 @@
1
1
  import type { ComputerCommandEnvelope, ComputerOperationClass, RemoteCommand, RemoteCommandKind } from "./remote-types.js";
2
+ export declare function ensureTable(): Promise<void>;
2
3
  export declare function isRemoteCommandKind(value: unknown): value is RemoteCommandKind;
3
4
  export declare function enqueueRemoteCommand(input: {
4
5
  deviceId: string;
@@ -16,7 +16,7 @@ const REMOTE_COMMAND_KINDS = [
16
16
  "status",
17
17
  ];
18
18
  const TERMINAL_STATUSES = new Set(["completed", "failed"]);
19
- async function ensureTable() {
19
+ export async function ensureTable() {
20
20
  if (!_initPromise) {
21
21
  _initPromise = (async () => {
22
22
  const client = getDbExec();
@@ -1,4 +1,5 @@
1
1
  import type { PublicRemoteDevice, RemoteComputerCapabilities, RemoteDevice, RemoteDeviceMetadata, RemoteExecutionCapabilities } from "./remote-types.js";
2
+ export declare function ensureTable(): Promise<void>;
2
3
  export declare function toPublicRemoteDevice(device: RemoteDevice): PublicRemoteDevice;
3
4
  export declare function getRemoteComputerCapabilities(device: Pick<RemoteDevice, "metadata">): RemoteComputerCapabilities | null;
4
5
  export declare function getRemoteExecutionCapabilities(device: Pick<RemoteDevice, "metadata">): RemoteExecutionCapabilities | null;
@@ -1,7 +1,7 @@
1
1
  import { getDbExec, intType, isPostgres, retryOnDdlRace, } from "../db/client.js";
2
2
  import { ensureColumnExists, ensureIndexExists, ensureTableExists, } from "../db/ddl-guard.js";
3
3
  let _initPromise;
4
- async function ensureTable() {
4
+ export async function ensureTable() {
5
5
  if (!_initPromise) {
6
6
  _initPromise = (async () => {
7
7
  const client = getDbExec();
@@ -1,4 +1,5 @@
1
1
  import type { PublicRemotePushRegistration, RemotePushNotification, RemotePushRegistration } from "./remote-types.js";
2
+ export declare function ensureTables(): Promise<void>;
2
3
  export declare function toPublicRemotePushRegistration(registration: RemotePushRegistration): PublicRemotePushRegistration;
3
4
  export declare function upsertRemotePushRegistration(input: {
4
5
  ownerEmail: string;
@@ -43,7 +43,7 @@ function buildCreateNotificationsSql() {
43
43
  )
44
44
  `;
45
45
  }
46
- async function ensureTables() {
46
+ export async function ensureTables() {
47
47
  if (!_initPromise) {
48
48
  _initPromise = (async () => {
49
49
  const client = getDbExec();
@@ -1,4 +1,5 @@
1
1
  import type { RemoteLiveViewEvent, RemoteRunEvent } from "./remote-types.js";
2
+ export declare function ensureTable(): Promise<void>;
2
3
  export declare function insertRemoteRunEvents(input: {
3
4
  deviceId: string;
4
5
  remoteRunId: string;
@@ -18,7 +18,7 @@ function buildCreateSql() {
18
18
  )
19
19
  `;
20
20
  }
21
- async function ensureTable() {
21
+ export async function ensureTable() {
22
22
  if (!_initPromise) {
23
23
  _initPromise = (async () => {
24
24
  const client = getDbExec();
@@ -42,6 +42,7 @@ export interface SaveIntegrationScopeInput extends IntegrationScopeKey {
42
42
  defaultModel?: string | null;
43
43
  policy?: Partial<IntegrationScopePolicy>;
44
44
  }
45
+ export declare function ensureTable(): Promise<void>;
45
46
  /** A stable, non-secret subject key suitable for a scope budget. */
46
47
  export declare function integrationScopeSubjectKey(key: IntegrationScopeKey): string;
47
48
  export declare function getIntegrationScope(keyInput: IntegrationScopeKey, accessInput: IntegrationScopeAccess): Promise<IntegrationScope | null>;
@@ -20,7 +20,7 @@ const TRUST_VALUES = new Set([
20
20
  "external_shared",
21
21
  "unknown",
22
22
  ]);
23
- async function ensureTable() {
23
+ export async function ensureTable() {
24
24
  if (!initPromise) {
25
25
  initPromise = (async () => {
26
26
  const db = getDbExec();
@@ -1,3 +1,4 @@
1
+ export declare function ensureTable(): Promise<void>;
1
2
  export interface ThreadMapping {
2
3
  platform: string;
3
4
  externalThreadId: string;
@@ -1,7 +1,7 @@
1
1
  import { getDbExec, isPostgres, intType } from "../db/client.js";
2
2
  import { ensureTableExists } from "../db/ddl-guard.js";
3
3
  let _initPromise;
4
- async function ensureTable() {
4
+ export async function ensureTable() {
5
5
  if (!_initPromise) {
6
6
  _initPromise = (async () => {
7
7
  const client = getDbExec();
@@ -53,6 +53,7 @@ export interface IntegrationBudgetThresholdEvent {
53
53
  observedMicros: number;
54
54
  createdAt: number;
55
55
  }
56
+ export declare function ensureTables(): Promise<void>;
56
57
  export declare function saveIntegrationUsageBudget(input: {
57
58
  subject: IntegrationBudgetSubject;
58
59
  period: IntegrationBudgetPeriod;
@@ -5,7 +5,7 @@ let initPromise;
5
5
  let transactionTail = Promise.resolve();
6
6
  /** All budget values are integer millionths of one billing currency unit. */
7
7
  export const INTEGRATION_BUDGET_COST_UNIT = "currency_micros";
8
- async function ensureTables() {
8
+ export async function ensureTables() {
9
9
  if (!initPromise) {
10
10
  initPromise = (async () => {
11
11
  const db = getDbExec();
@@ -2,11 +2,12 @@ import { collectFinalResponseTextFromAgentEvents } from "../a2a/response-text.js
2
2
  import { getStoredModelForEngine, normalizeModelForEngine, resolveEngine, } from "../agent/engine/index.js";
3
3
  import { actionsToEngineTools, filterInitialEngineTools, getOwnerActiveApiKey, } from "../agent/production-agent.js";
4
4
  import { runAgentLoopDirectWithSoftTimeout } from "../agent/run-loop-with-resume.js";
5
- import { resolveRunSoftTimeoutMs, startRun } from "../agent/run-manager.js";
5
+ import { resolveRunSoftTimeoutMs, startRun, } from "../agent/run-manager.js";
6
6
  import { claimBackgroundRun, insertRun } from "../agent/run-store.js";
7
+ import { buildAssistantMessage, buildUserMessage, extractThreadMeta, foldAssistantTurn, upsertUserMessage, } from "../agent/thread-data-builder.js";
7
8
  import { attachToolSearch } from "../agent/tool-search.js";
8
9
  import { resolveAutomationExecutionIdentity, } from "../automations/service.js";
9
- import { createThread } from "../chat-threads/store.js";
10
+ import { createThread, getThread, updateThreadData, withThreadDataLock, } from "../chat-threads/store.js";
10
11
  import { queryOrgMembers } from "../org/context.js";
11
12
  import { organizationIdFromResourceOwner, organizationResourceOwner, } from "../resources/store.js";
12
13
  import { runWithRequestContext, } from "../server/request-context.js";
@@ -204,6 +205,80 @@ async function recordRunThread(historyId, threadId, runId) {
204
205
  console.error(`[automations] Could not attach thread ${threadId} to run ${historyId}:`, err);
205
206
  }
206
207
  }
208
+ function backgroundAutomationPersistFailure(input) {
209
+ if (input.hardTimedOut) {
210
+ return {
211
+ message: `Background automation timed out after ${BACKGROUND_RUN_HARD_TIMEOUT_MS / 60_000} minutes`,
212
+ errorCode: "background_automation_hard_timeout",
213
+ };
214
+ }
215
+ const cutOffReason = backgroundRunCutOffReason(input.run);
216
+ if (!cutOffReason)
217
+ return undefined;
218
+ return {
219
+ message: `Background automation was cut off before finishing (${cutOffReason})`,
220
+ errorCode: "background_automation_cut_off",
221
+ };
222
+ }
223
+ /**
224
+ * Chat opens `/chat/:threadId` from `thread_data`, not `agent_run_events`.
225
+ * Persist before the cut-off/status reject so a failed run still has a
226
+ * visible trace. Keep the scheduler title — `extractThreadMeta` would
227
+ * otherwise replace `Job: …` with the prompt excerpt.
228
+ *
229
+ * Cut-off and hard-abort turns have no terminal error event of their own.
230
+ * `suppressInternalContinuation` also drops `auto_continue`, so persist
231
+ * would otherwise store a completed assistant message. Append a
232
+ * non-recoverable error and skip that suppress so Open thread shows the
233
+ * incomplete state.
234
+ */
235
+ async function persistBackgroundAutomationTurn(input) {
236
+ await withThreadDataLock(input.threadId, async () => {
237
+ const row = await getThread(input.threadId);
238
+ if (!row) {
239
+ throw new Error(`Background automation thread ${input.threadId} was not found while saving run ${input.run.runId}.`);
240
+ }
241
+ let repo;
242
+ try {
243
+ repo = JSON.parse(row.threadData || "{}");
244
+ }
245
+ catch {
246
+ throw new Error(`Background automation thread ${input.threadId} has unreadable thread data.`);
247
+ }
248
+ if (!repo || typeof repo !== "object" || Array.isArray(repo)) {
249
+ throw new Error(`Background automation thread ${input.threadId} has unreadable thread data.`);
250
+ }
251
+ repo = upsertUserMessage(repo, buildUserMessage({ text: input.prompt, runId: input.run.runId }));
252
+ const events = [...(input.run.events ?? [])];
253
+ if (input.persistFailure) {
254
+ events.push({
255
+ seq: events.length,
256
+ event: {
257
+ type: "error",
258
+ error: input.persistFailure.message,
259
+ errorCode: input.persistFailure.errorCode,
260
+ recoverable: false,
261
+ },
262
+ });
263
+ }
264
+ const assistantMsg = buildAssistantMessage(events, input.run.runId, {
265
+ suppressInternalContinuation: !input.persistFailure,
266
+ turnId: input.run.turnId,
267
+ runDurationMs: Number.isFinite(input.run.startedAt)
268
+ ? Math.max(0, Date.now() - input.run.startedAt)
269
+ : undefined,
270
+ });
271
+ if (assistantMsg) {
272
+ repo = foldAssistantTurn(repo, assistantMsg, {
273
+ runId: input.run.runId,
274
+ turnId: input.run.turnId,
275
+ });
276
+ }
277
+ const meta = extractThreadMeta(repo);
278
+ const messages = repo.messages;
279
+ await updateThreadData(input.threadId, JSON.stringify(repo), input.threadTitle || row.title, meta.preview || row.preview, Array.isArray(messages) ? messages.length : 0);
280
+ });
281
+ }
207
282
  async function recordRunOutcome(historyId, status, error) {
208
283
  if (!historyId)
209
284
  return;
@@ -282,6 +357,7 @@ async function executeBackgroundAutomation(options, deps, historyId) {
282
357
  const usageRef = { current: null };
283
358
  let responseText = "";
284
359
  let hardAbortTimer = null;
360
+ let hardTimedOut = false;
285
361
  // This runner executes in-process, synchronously — there is no HTTP
286
362
  // self-dispatch to a separate worker. Self-claim the row into
287
363
  // 'background-processing' right away, exactly like a genuine HTTP
@@ -331,9 +407,29 @@ async function executeBackgroundAutomation(options, deps, historyId) {
331
407
  clearTimeout(hardAbortTimer);
332
408
  hardAbortTimer = null;
333
409
  }
334
- const cutOffReason = backgroundRunCutOffReason(run);
335
- if (cutOffReason) {
336
- reject(new Error(`Background automation was cut off before finishing (${cutOffReason})`));
410
+ const persistFailure = backgroundAutomationPersistFailure({
411
+ run,
412
+ hardTimedOut,
413
+ });
414
+ try {
415
+ await persistBackgroundAutomationTurn({
416
+ threadId: thread.id,
417
+ threadTitle,
418
+ prompt,
419
+ run,
420
+ persistFailure,
421
+ });
422
+ }
423
+ catch (err) {
424
+ reject(err instanceof Error ? err : new Error(String(err)));
425
+ throw err;
426
+ }
427
+ // Hard timeout owns the runner reject so a serverless return
428
+ // waits for this persist via `activeRun.finalized`.
429
+ if (hardTimedOut)
430
+ return;
431
+ if (persistFailure) {
432
+ reject(new Error(persistFailure.message));
337
433
  return;
338
434
  }
339
435
  if (run.status !== "completed") {
@@ -350,10 +446,16 @@ async function executeBackgroundAutomation(options, deps, historyId) {
350
446
  });
351
447
  hardAbortTimer = setTimeout(() => {
352
448
  hardAbortTimer = null;
353
- if (activeRun.status === "running") {
354
- activeRun.abort.abort("background_automation_hard_timeout");
355
- reject(new Error(`Background automation timed out after ${BACKGROUND_RUN_HARD_TIMEOUT_MS / 60_000} minutes`));
356
- }
449
+ if (activeRun.status !== "running")
450
+ return;
451
+ hardTimedOut = true;
452
+ activeRun.abort.abort("background_automation_hard_timeout");
453
+ const timeoutError = new Error(`Background automation timed out after ${BACKGROUND_RUN_HARD_TIMEOUT_MS / 60_000} minutes`);
454
+ void activeRun.finalized
455
+ .catch(() => { })
456
+ .then(() => {
457
+ reject(timeoutError);
458
+ });
357
459
  }, BACKGROUND_RUN_HARD_TIMEOUT_MS);
358
460
  }).finally(() => {
359
461
  if (hardAbortTimer) {
@@ -36,6 +36,7 @@ export interface StartAutomationRunInput {
36
36
  /** Authoritative release-time schema for durable automation history. */
37
37
  export declare const AUTOMATION_RUN_MIGRATIONS: MigrationEntry[];
38
38
  export declare function runAutomationRunMigrations(nitroApp: unknown): Promise<void>;
39
+ export declare function ensureTable(): Promise<void>;
39
40
  /**
40
41
  * Record an automation execution. Manual runs create the row before dispatch,
41
42
  * so `dispatchPending` distinguishes that durable handoff from a run that has
@@ -83,7 +83,7 @@ export async function runAutomationRunMigrations(nitroApp) {
83
83
  })(nitroApp);
84
84
  }
85
85
  let _initPromise;
86
- async function ensureTable() {
86
+ export async function ensureTable() {
87
87
  if (!_initPromise) {
88
88
  _initPromise = (async () => {
89
89
  const client = getDbExec();
@@ -13,6 +13,7 @@ export interface AutomationSchedulerHealth {
13
13
  runtime: string | null;
14
14
  updatedAt: number | null;
15
15
  }
16
+ export declare function ensureHealthTable(): Promise<void>;
16
17
  /** Claim one recurring scheduler across all deployments of an app. */
17
18
  export declare function acquireAutomationSchedulerLease(input?: {
18
19
  appId?: string;
@@ -55,7 +55,7 @@ function rowIdForScope(appId, orgId) {
55
55
  return `${appId}:${orgId ?? "global"}`;
56
56
  }
57
57
  let initPromise;
58
- async function ensureHealthTable() {
58
+ export async function ensureHealthTable() {
59
59
  if (!initPromise) {
60
60
  initPromise = (async () => {
61
61
  const createSql = `
@@ -1,3 +1,4 @@
1
+ export declare function ensureApprovalTable(): Promise<void>;
1
2
  export interface McpApprovalGrant {
2
3
  nonce: string;
3
4
  callerKey: string;
@@ -1,7 +1,7 @@
1
1
  import { getDbExec, intType, isPostgres } from "../db/client.js";
2
2
  import { ensureTableExists } from "../db/ddl-guard.js";
3
3
  let initPromise;
4
- async function ensureApprovalTable() {
4
+ export async function ensureApprovalTable() {
5
5
  if (!initPromise) {
6
6
  initPromise = (async () => {
7
7
  const createSql = `
@@ -41,6 +41,7 @@ export declare const MAX_TOKEN_TTL_DAYS = 365;
41
41
  */
42
42
  export declare const DEVICE_START_MAX = 20;
43
43
  export declare const DEVICE_START_WINDOW_MS = 60000;
44
+ export declare function ensureTable(): Promise<void>;
44
45
  export interface MintedTokenRow {
45
46
  id: string;
46
47
  jti: string;
@@ -45,7 +45,7 @@ export const MAX_TOKEN_TTL_DAYS = 365;
45
45
  */
46
46
  export const DEVICE_START_MAX = 20;
47
47
  export const DEVICE_START_WINDOW_MS = 60_000;
48
- async function ensureTable() {
48
+ export async function ensureTable() {
49
49
  if (!_initPromise) {
50
50
  _initPromise = (async () => {
51
51
  const client = getDbExec();
@@ -19,6 +19,7 @@ export declare const MCP_OAUTH_ACCESS_TOKEN_TTL_SECONDS: number;
19
19
  export declare const MCP_OAUTH_REFRESH_TOKEN_TTL_MS: number;
20
20
  export declare const MCP_OAUTH_REGISTER_MAX = 60;
21
21
  export declare const MCP_OAUTH_REGISTER_WINDOW_MS = 60000;
22
+ export declare function ensureTable(): Promise<void>;
22
23
  export interface OAuthClientRow {
23
24
  clientId: string;
24
25
  clientName: string | null;
@@ -65,7 +65,7 @@ export const MCP_OAUTH_ACCESS_TOKEN_TTL_SECONDS = _accessTokenTtl.seconds;
65
65
  export const MCP_OAUTH_REFRESH_TOKEN_TTL_MS = 365 * 24 * 60 * 60_000;
66
66
  export const MCP_OAUTH_REGISTER_MAX = 60;
67
67
  export const MCP_OAUTH_REGISTER_WINDOW_MS = 60_000;
68
- async function ensureTable() {
68
+ export async function ensureTable() {
69
69
  if (!_initPromise) {
70
70
  _initPromise = (async () => {
71
71
  const client = getDbExec();
@@ -13,13 +13,13 @@
13
13
  export declare function createNotificationsHandler(): import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<"" | import("./types.js").Notification[] | {
14
14
  count: number;
15
15
  updated?: undefined;
16
- error?: undefined;
17
16
  ok?: undefined;
17
+ error?: undefined;
18
18
  } | {
19
19
  count?: undefined;
20
20
  updated: number;
21
- error?: undefined;
22
21
  ok?: undefined;
22
+ error?: undefined;
23
23
  } | {
24
24
  count?: undefined;
25
25
  updated?: undefined;
@@ -28,6 +28,6 @@ export declare function createNotificationsHandler(): import("h3").EventHandlerW
28
28
  } | {
29
29
  count?: undefined;
30
30
  updated?: undefined;
31
- error?: undefined;
32
31
  ok: boolean;
32
+ error?: undefined;
33
33
  }>>;
@@ -1,4 +1,5 @@
1
1
  import type { Notification, NotificationSeverity } from "./types.js";
2
+ export declare function ensureTable(): Promise<void>;
2
3
  export interface InsertNotificationInput {
3
4
  owner: string;
4
5
  severity: NotificationSeverity;
@@ -11,7 +11,7 @@ function normalizeLimit(value, fallback = 50) {
11
11
  return fallback;
12
12
  return Math.min(Math.floor(value), 200);
13
13
  }
14
- async function ensureTable() {
14
+ export async function ensureTable() {
15
15
  if (!_initPromise) {
16
16
  _initPromise = (async () => {
17
17
  const client = getDbExec();
@@ -1,3 +1,4 @@
1
+ export declare function ensureTable(): Promise<void>;
1
2
  export declare function getOAuthTokens(provider: string, accountId: string, owner?: string): Promise<Record<string, unknown> | null>;
2
3
  export interface OAuthTokenSnapshot {
3
4
  tokens: Record<string, unknown>;
@@ -51,7 +51,7 @@ function isDuplicateColumnError(err) {
51
51
  message.includes("duplicate column") ||
52
52
  message.includes("already exists"));
53
53
  }
54
- async function ensureTable() {
54
+ export async function ensureTable() {
55
55
  if (!_initPromise) {
56
56
  _initPromise = (async () => {
57
57
  const client = getDbExec();
@@ -41,16 +41,16 @@ export declare function createObservabilityHandler(): import("h3").EventHandlerW
41
41
  thumbsUpRate: number;
42
42
  avgEvalScore: number;
43
43
  } | {
44
+ error?: undefined;
44
45
  summary: import("./types.js").TraceSummary;
45
46
  spans: import("./types.js").TraceSpan[];
46
47
  id?: undefined;
47
- error?: undefined;
48
48
  ok?: undefined;
49
49
  } | {
50
+ error?: undefined;
50
51
  summary?: undefined;
51
52
  spans?: undefined;
52
53
  id: string;
53
- error?: undefined;
54
54
  ok?: undefined;
55
55
  } | {
56
56
  summary?: undefined;
@@ -59,9 +59,9 @@ export declare function createObservabilityHandler(): import("h3").EventHandlerW
59
59
  error: any;
60
60
  ok?: undefined;
61
61
  } | {
62
+ error?: undefined;
62
63
  summary?: undefined;
63
64
  spans?: undefined;
64
65
  id?: undefined;
65
- error?: undefined;
66
66
  ok: boolean;
67
67
  }>>;
@@ -15,6 +15,6 @@ export declare function createProgressHandler(): import("h3").EventHandlerWithFe
15
15
  error: string;
16
16
  ok?: undefined;
17
17
  } | {
18
- error?: undefined;
19
18
  ok: boolean;
19
+ error?: undefined;
20
20
  }>>;
@@ -1,5 +1,6 @@
1
1
  import type { AgentRun, ListRunsOptions, StartRunInput, UpdateProgressInput } from "./types.js";
2
2
  export declare const DEFAULT_PROGRESS_RUN_STALE_MS: number;
3
+ export declare function ensureTable(): Promise<void>;
3
4
  export declare function insertRun(input: StartRunInput): Promise<AgentRun>;
4
5
  export declare function getRun(id: string, owner: string): Promise<AgentRun | null>;
5
6
  export declare function updateRun(id: string, owner: string, input: UpdateProgressInput): Promise<AgentRun | null>;
@@ -21,7 +21,7 @@ function resolveProgressRunStaleMs() {
21
21
  }
22
22
  return DEFAULT_PROGRESS_RUN_STALE_MS;
23
23
  }
24
- async function ensureTable() {
24
+ export async function ensureTable() {
25
25
  if (!_initPromise) {
26
26
  _initPromise = (async () => {
27
27
  const client = getDbExec();
@@ -75,7 +75,6 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
75
75
  user: "user";
76
76
  }>>;
77
77
  }, z.core.$strip>>, {
78
- message?: undefined;
79
78
  id?: undefined;
80
79
  provider?: undefined;
81
80
  deleted?: undefined;
@@ -92,18 +91,18 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
92
91
  found?: undefined;
93
92
  registered?: undefined;
94
93
  label?: undefined;
95
- } | {
96
94
  message?: undefined;
97
- count?: undefined;
95
+ } | {
98
96
  id?: undefined;
97
+ count?: undefined;
99
98
  deleted?: undefined;
100
99
  providers?: undefined;
101
100
  found: boolean;
102
101
  provider: import("../custom-registry.js").CustomProviderConfig;
103
102
  registered?: undefined;
104
103
  label?: undefined;
105
- } | {
106
104
  message?: undefined;
105
+ } | {
107
106
  count?: undefined;
108
107
  provider?: undefined;
109
108
  deleted?: undefined;
@@ -112,8 +111,8 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
112
111
  id: string;
113
112
  registered?: undefined;
114
113
  label?: undefined;
115
- } | {
116
114
  message?: undefined;
115
+ } | {
117
116
  count?: undefined;
118
117
  provider?: undefined;
119
118
  providers?: undefined;
@@ -122,6 +121,7 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
122
121
  id: string;
123
122
  registered?: undefined;
124
123
  label?: undefined;
124
+ message?: undefined;
125
125
  } | {
126
126
  count?: undefined;
127
127
  provider?: undefined;
@@ -311,6 +311,7 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
311
311
  notes?: string | undefined;
312
312
  scope?: "org" | "user" | undefined;
313
313
  }, {
314
+ message?: undefined;
314
315
  deleted?: undefined;
315
316
  id?: undefined;
316
317
  providers: {
@@ -327,8 +328,8 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
327
328
  found?: undefined;
328
329
  registered?: undefined;
329
330
  label?: undefined;
330
- message?: undefined;
331
331
  } | {
332
+ message?: undefined;
332
333
  deleted?: undefined;
333
334
  id?: undefined;
334
335
  providers?: undefined;
@@ -337,8 +338,8 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
337
338
  provider: import("../custom-registry.js").CustomProviderConfig;
338
339
  registered?: undefined;
339
340
  label?: undefined;
340
- message?: undefined;
341
341
  } | {
342
+ message?: undefined;
342
343
  deleted?: undefined;
343
344
  providers?: undefined;
344
345
  count?: undefined;
@@ -347,8 +348,8 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
347
348
  id: string;
348
349
  registered?: undefined;
349
350
  label?: undefined;
350
- message?: undefined;
351
351
  } | {
352
+ message?: undefined;
352
353
  providers?: undefined;
353
354
  count?: undefined;
354
355
  provider?: undefined;
@@ -357,7 +358,6 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
357
358
  id: string;
358
359
  registered?: undefined;
359
360
  label?: undefined;
360
- message?: undefined;
361
361
  } | {
362
362
  deleted?: undefined;
363
363
  providers?: undefined;
@@ -62,6 +62,7 @@ export interface UpdateProviderCorpusJobOptions {
62
62
  error?: string | null;
63
63
  nextResumeAt?: number | null;
64
64
  }
65
+ export declare function ensureTables(): Promise<void>;
65
66
  export declare function createProviderCorpusJob(options: CreateProviderCorpusJobOptions): Promise<ProviderCorpusJobRecord>;
66
67
  export declare function getProviderCorpusJob(options: {
67
68
  id: string;
@@ -9,7 +9,7 @@
9
9
  import { getDbExec, intType, isPostgres } from "../db/client.js";
10
10
  import { ensureTableExists, ensureIndexExists } from "../db/ddl-guard.js";
11
11
  let initPromise;
12
- async function ensureTables() {
12
+ export async function ensureTables() {
13
13
  if (!initPromise) {
14
14
  initPromise = (async () => {
15
15
  const db = getDbExec();
@@ -67,6 +67,7 @@ export interface UpsertCustomProviderArgs {
67
67
  */
68
68
  orgRole: string | null;
69
69
  }
70
+ export declare function ensureTable(): Promise<void>;
70
71
  /**
71
72
  * Validate and normalise a custom provider base URL. Throws when the URL is
72
73
  * invalid, uses a non-http(s) scheme, or resolves to a private/internal host.