@agent-native/core 0.144.2 → 0.144.3

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 (70) hide show
  1. package/corpus/templates/analytics/app/pages/DataSources.tsx +28 -4
  2. package/corpus/templates/analytics/server/jobs/dashboard-report.ts +7 -3
  3. package/corpus/templates/analytics/server/plugins/dashboard-report-jobs.ts +13 -3
  4. package/corpus/templates/calendar/app/components/calendar/GoogleConnectBanner.tsx +64 -23
  5. package/corpus/templates/calendar/app/hooks/use-google-auth.ts +69 -46
  6. package/corpus/templates/calendar/app/hooks/use-view-preferences.ts +35 -6
  7. package/corpus/templates/calendar/app/hooks/use-zoom-auth.ts +24 -3
  8. package/corpus/templates/clips/app/components/player/transcript-panel.tsx +45 -6
  9. package/corpus/templates/clips/app/components/recorder/storage-setup-card.tsx +38 -5
  10. package/corpus/templates/clips/desktop/src/app.tsx +146 -45
  11. package/corpus/templates/clips/server/jobs/brain-export.ts +13 -6
  12. package/corpus/templates/clips/server/jobs/builder-media-compression.ts +10 -3
  13. package/corpus/templates/clips/server/jobs/meeting-reminders.ts +10 -3
  14. package/corpus/templates/clips/server/jobs/poll-calendars.ts +23 -21
  15. package/corpus/templates/clips/server/jobs/stale-meeting-sweeper.ts +10 -3
  16. package/corpus/templates/clips/server/jobs/transactional-emails.ts +10 -3
  17. package/corpus/templates/content/app/components/sidebar/NotionButton.tsx +1 -0
  18. package/corpus/templates/design/app/components/design/FusionAppBanner.tsx +15 -2
  19. package/corpus/templates/mail/app/components/GoogleConnectBanner.tsx +82 -39
  20. package/corpus/templates/mail/app/components/layout/AppLayout.tsx +31 -9
  21. package/corpus/templates/mail/server/plugins/mail-jobs.ts +36 -17
  22. package/dist/client/AssistantChat.js +73 -43
  23. package/dist/client/MultiTabAssistantChat.d.ts +3 -1
  24. package/dist/client/MultiTabAssistantChat.js +79 -92
  25. package/dist/client/browser-session-bridge.js +97 -54
  26. package/dist/client/db-admin/useAgentSync.js +34 -43
  27. package/dist/client/dynamic-suggestions.d.ts +3 -0
  28. package/dist/client/dynamic-suggestions.js +54 -52
  29. package/dist/client/hooks/index.d.ts +1 -0
  30. package/dist/client/hooks/index.js +1 -0
  31. package/dist/client/i18n.d.ts +7 -0
  32. package/dist/client/i18n.js +12 -3
  33. package/dist/client/integrations/useIntegrationStatus.d.ts +1 -1
  34. package/dist/client/integrations/useIntegrationStatus.js +9 -22
  35. package/dist/client/notifications/NotificationsBell.js +14 -9
  36. package/dist/client/progress/RunsTray.js +6 -5
  37. package/dist/client/settings/useBuilderStatus.js +95 -73
  38. package/dist/client/transcription/BuilderTranscriptionCta.js +27 -31
  39. package/dist/client/use-agent-engine-configured.js +21 -3
  40. package/dist/client/use-pausing-interval.d.ts +6 -0
  41. package/dist/client/use-pausing-interval.js +6 -0
  42. package/dist/client/use-poll-loop.d.ts +39 -0
  43. package/dist/client/use-poll-loop.js +73 -0
  44. package/dist/client/use-run-stuck-detection.js +41 -13
  45. package/dist/collab/routes.d.ts +1 -1
  46. package/dist/integrations/google-docs-poller.js +26 -7
  47. package/dist/integrations/pending-tasks-retry-job.js +17 -23
  48. package/dist/integrations/plugin.js +16 -15
  49. package/dist/integrations/remote-push-delivery-job.js +16 -25
  50. package/dist/integrations/remote-retry-job.js +19 -23
  51. package/dist/notifications/routes.d.ts +1 -1
  52. package/dist/oauth-tokens/google-refresh.js +12 -19
  53. package/dist/provider-api/actions/custom-provider-registration.d.ts +9 -9
  54. package/dist/provider-api/actions/provider-api.d.ts +11 -11
  55. package/dist/server/agent-chat-plugin.js +26 -29
  56. package/dist/server/index.d.ts +1 -0
  57. package/dist/server/index.js +1 -0
  58. package/dist/server/interval-job.d.ts +25 -0
  59. package/dist/server/interval-job.js +19 -0
  60. package/dist/server/realtime-token.d.ts +1 -1
  61. package/dist/shared/index.d.ts +1 -0
  62. package/dist/shared/index.js +1 -0
  63. package/dist/shared/poll-engine.d.ts +49 -0
  64. package/dist/shared/poll-engine.js +148 -0
  65. package/dist/templates/default/.agents/skills/internationalization/SKILL.md +5 -0
  66. package/dist/templates/workspace-core/.agents/skills/internationalization/SKILL.md +5 -0
  67. package/dist/tracking/providers.js +10 -1
  68. package/package.json +4 -3
  69. package/src/templates/default/.agents/skills/internationalization/SKILL.md +5 -0
  70. package/src/templates/workspace-core/.agents/skills/internationalization/SKILL.md +5 -0
@@ -26,8 +26,8 @@ export declare const getCollabState: import("h3").EventHandlerWithFetch<import("
26
26
  * Body: { update: string (base64), requestSource?: string }
27
27
  */
28
28
  export declare const postCollabUpdate: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
29
- ok?: undefined;
30
29
  error: string;
30
+ ok?: undefined;
31
31
  } | {
32
32
  error?: undefined;
33
33
  ok: boolean;
@@ -7,6 +7,7 @@ import { buildAssistantMessage, extractThreadMeta, } from "../agent/thread-data-
7
7
  import { attachToolSearch } from "../agent/tool-search.js";
8
8
  import { createThread, getThread, setThreadSourceIfMissing, updateThreadData, } from "../chat-threads/store.js";
9
9
  import { resolveOrgIdForEmail } from "../org/context.js";
10
+ import { startIntervalJob, } from "../server/interval-job.js";
10
11
  import { runWithRequestContext } from "../server/request-context.js";
11
12
  import { getServiceAccountAccessToken, getServiceAccountEmail, getStartPageToken, googleDocsAdapter, listChanges, listDocComments, } from "./adapters/google-docs.js";
12
13
  import { getIntegrationConfig, integrationConfigWriteEpoch, saveIntegrationConfig, } from "./config-store.js";
@@ -17,7 +18,13 @@ const DEFAULT_TRIGGER = "@agent";
17
18
  const processedComments = new Set();
18
19
  /** Track last-checked time per document for comment filtering */
19
20
  const lastCheckedTimes = new Map();
20
- let pollerInterval = null;
21
+ let pollerJob = null;
22
+ // Held only for the startup delay below. It counts as "already running" for
23
+ // both the idempotency guard and stop(): `pollerJob` is still null during that
24
+ // window, so without this a second start() would build a second independent
25
+ // poller, and a stop() inside the window could not prevent the loop from
26
+ // arming itself afterwards.
27
+ let pollerStartTimer = null;
21
28
  let activeOptions = null;
22
29
  // ─── Watch Channel Management ───────────────────────────────────────────────
23
30
  /** How long a watch channel lasts (Google max is ~24h, we use 23h to renew early) */
@@ -429,7 +436,7 @@ async function persistThreadData(threadId, userText, completedRun, thread) {
429
436
  * in case a push notification is missed
430
437
  */
431
438
  export async function startGoogleDocsPoller(options) {
432
- if (pollerInterval) {
439
+ if (pollerJob || pollerStartTimer) {
433
440
  console.warn("[google-docs] Already running");
434
441
  return;
435
442
  }
@@ -490,8 +497,16 @@ function startPollLoop(options, intervalMs) {
490
497
  console.error("[google-docs] Poller error:", detail);
491
498
  }
492
499
  }
493
- setTimeout(poll, 5000);
494
- pollerInterval = setInterval(poll, intervalMs);
500
+ // processChanges ultimately calls the Drive/Docs REST API
501
+ // (adapters/google-docs.ts), none of whose fetch()s carry a request
502
+ // timeout — startIntervalJob's own cadence-scaled timeout backstops a hung
503
+ // call, same convention as SyncTransport's poll abort.
504
+ if (pollerStartTimer)
505
+ clearTimeout(pollerStartTimer);
506
+ pollerStartTimer = setTimeout(() => {
507
+ pollerStartTimer = null;
508
+ pollerJob = startIntervalJob(poll, { intervalMs });
509
+ }, 5000);
495
510
  const email = getServiceAccountEmail();
496
511
  if (process.env.DEBUG) {
497
512
  console.log(`[google-docs] Poll loop started (interval: ${intervalMs / 1000}s, service account: ${email ?? "not configured"})`);
@@ -501,9 +516,13 @@ function startPollLoop(options, intervalMs) {
501
516
  * Stop the Google Docs integration.
502
517
  */
503
518
  export async function stopGoogleDocsPoller() {
504
- if (pollerInterval) {
505
- clearInterval(pollerInterval);
506
- pollerInterval = null;
519
+ if (pollerStartTimer) {
520
+ clearTimeout(pollerStartTimer);
521
+ pollerStartTimer = null;
522
+ }
523
+ if (pollerJob) {
524
+ pollerJob.stop();
525
+ pollerJob = null;
507
526
  }
508
527
  if (watchRenewalTimer) {
509
528
  clearTimeout(watchRenewalTimer);
@@ -1,4 +1,5 @@
1
1
  import { getDbExec } from "../db/client.js";
2
+ import { startIntervalJob, } from "../server/interval-job.js";
2
3
  import { hasActiveIntegrationCampaign } from "./integration-campaigns-store.js";
3
4
  import { configuredIntegrationDurableDispatchScopes, dispatchPendingIntegrationTask, isIntegrationDurableDispatchEnabledForTask, } from "./integration-durable-dispatch.js";
4
5
  import { ensurePendingTasksTable, MAX_PENDING_TASK_ATTEMPTS, } from "./pending-tasks-store.js";
@@ -39,8 +40,8 @@ const SERVERLESS_PROCESSING_STUCK_AFTER_MS = 75_000;
39
40
  const DURABLE_BACKGROUND_PROCESSING_STUCK_AFTER_MS = 16 * 60 * 1000;
40
41
  /** After this many attempts we give up and mark the task failed */
41
42
  const DEFAULT_SWEEP_LIMIT = 100;
42
- let retryInterval = null;
43
- let initialTimer = null;
43
+ let job = null;
44
+ let startupTimer = null;
44
45
  let activeWebhookBaseUrl;
45
46
  /**
46
47
  * Whether the table exists. Cached after first probe so we don't log every
@@ -268,38 +269,31 @@ function getProcessingStuckAfterMs() {
268
269
  * is a no-op.
269
270
  */
270
271
  export function startPendingTasksRetryJob(options) {
271
- if (retryInterval)
272
+ if (job || startupTimer)
272
273
  return;
273
274
  activeWebhookBaseUrl = options?.webhookBaseUrl;
274
275
  // Stagger the first run a bit so we don't hammer the DB immediately on boot.
275
- initialTimer = setTimeout(() => {
276
- void retryStuckPendingTasks().catch((err) => {
277
- console.error("[integrations] Pending-tasks retry job error:", err);
276
+ startupTimer = setTimeout(() => {
277
+ startupTimer = null;
278
+ job = startIntervalJob(async () => void (await retryStuckPendingTasks()), {
279
+ intervalMs: RETRY_INTERVAL_MS,
280
+ onError: (err) => {
281
+ console.error("[integrations] Pending-tasks retry job error:", err);
282
+ },
278
283
  });
279
284
  }, 10_000);
280
- unrefTimer(initialTimer);
281
- retryInterval = setInterval(() => {
282
- void retryStuckPendingTasks().catch((err) => {
283
- console.error("[integrations] Pending-tasks retry job error:", err);
284
- });
285
- }, RETRY_INTERVAL_MS);
286
- unrefTimer(retryInterval);
285
+ startupTimer.unref?.();
287
286
  if (process.env.DEBUG) {
288
287
  console.log(`[integrations] Pending-tasks retry job started (every ${RETRY_INTERVAL_MS / 1000}s)`);
289
288
  }
290
289
  }
291
290
  /** Stop the retry loop. */
292
291
  export function stopPendingTasksRetryJob() {
293
- if (initialTimer) {
294
- clearTimeout(initialTimer);
295
- initialTimer = null;
296
- }
297
- if (retryInterval) {
298
- clearInterval(retryInterval);
299
- retryInterval = null;
292
+ if (startupTimer) {
293
+ clearTimeout(startupTimer);
294
+ startupTimer = null;
300
295
  }
296
+ job?.stop();
297
+ job = null;
301
298
  activeWebhookBaseUrl = undefined;
302
299
  }
303
- function unrefTimer(timer) {
304
- timer.unref?.();
305
- }
@@ -13,6 +13,7 @@ import { resolveSecret } from "../server/credential-provider.js";
13
13
  import { getH3App, markDefaultPluginProvided, } from "../server/framework-request-handler.js";
14
14
  import { decodeOAuthState, encodeOAuthState, oauthCallbackResponse, oauthErrorPage, resolveOAuthRedirectUri, } from "../server/google-oauth.js";
15
15
  import { readBody } from "../server/h3-helpers.js";
16
+ import { startIntervalJob, } from "../server/interval-job.js";
16
17
  import { runWithRequestContext } from "../server/request-context.js";
17
18
  import { processA2AContinuationById, processDueA2AContinuations, reconcileTerminalA2AParentIfDisabled, recoverA2AContinuationAfterProcessorFailure, recoverDueA2AContinuations, } from "./a2a-continuation-processor.js";
18
19
  import { getA2AContinuationTaskOutcome } from "./a2a-continuations-store.js";
@@ -50,7 +51,12 @@ import { assertSlackInstallAccess, buildSlackAuthorizeUrl, exchangeSlackOAuthCod
50
51
  import { getTaskQueueStats } from "./task-queue-stats.js";
51
52
  import { listIntegrationUsageBudgets, saveIntegrationUsageBudget, } from "./usage-budget-store.js";
52
53
  import { handleWebhook, processIntegrationTask, recordIntegrationResponseDelivery, } from "./webhook-handler.js";
53
- let a2aContinuationRetryInterval = null;
54
+ // Timer-driven sweep only — the atomic DB claim inside
55
+ // processDueA2AContinuations already makes concurrent calls (this timer, the
56
+ // opportunistic post-dispatch sweep, etc.) safe.
57
+ let a2aContinuationJob = null;
58
+ let a2aContinuationStartupTimer = null;
59
+ const A2A_CONTINUATION_SWEEP_INTERVAL_MS = 60_000;
54
60
  const INTEGRATION_DELIVERY_LEASE_MS = 2 * 60_000;
55
61
  async function checkpointIntegrationDeliveryRetry(task, payload, errorMessage, event, campaignLease) {
56
62
  let terminalStatus;
@@ -156,23 +162,18 @@ async function containFailedDeliveryTransition(task, errorMessage, event) {
156
162
  });
157
163
  }
158
164
  function startA2AContinuationRetryJob(adapters) {
159
- if (a2aContinuationRetryInterval)
165
+ if (a2aContinuationJob || a2aContinuationStartupTimer)
160
166
  return;
161
- const initialTimer = setTimeout(() => {
162
- processDueA2AContinuations({ adapters }).catch((err) => {
163
- console.error("[integrations] A2A continuation retry job failed:", err);
167
+ a2aContinuationStartupTimer = setTimeout(() => {
168
+ a2aContinuationStartupTimer = null;
169
+ a2aContinuationJob = startIntervalJob(() => processDueA2AContinuations({ adapters }), {
170
+ intervalMs: A2A_CONTINUATION_SWEEP_INTERVAL_MS,
171
+ onError: (err) => {
172
+ console.error("[integrations] A2A continuation retry job failed:", err);
173
+ },
164
174
  });
165
175
  }, 10_000);
166
- unrefTimer(initialTimer);
167
- a2aContinuationRetryInterval = setInterval(() => {
168
- processDueA2AContinuations({ adapters }).catch((err) => {
169
- console.error("[integrations] A2A continuation retry job failed:", err);
170
- });
171
- }, 60_000);
172
- unrefTimer(a2aContinuationRetryInterval);
173
- }
174
- function unrefTimer(timer) {
175
- timer.unref?.();
176
+ a2aContinuationStartupTimer.unref?.();
176
177
  }
177
178
  // ─── Google Pub/Sub OIDC verifier (for Drive changes.watch push) ────────────
178
179
  // Cache Google's public keys for OIDC verification. jose handles TTL +
@@ -1,12 +1,9 @@
1
+ import { startIntervalJob, } from "../server/interval-job.js";
1
2
  import { deliverPendingRemotePushNotifications } from "./remote-push-delivery.js";
2
3
  const DELIVERY_INTERVAL_MS = 60_000;
3
- let retryInterval = null;
4
- let initialTimer = null;
5
- let running = false;
4
+ let job = null;
5
+ let startupTimer = null;
6
6
  export async function runRemotePushDelivery() {
7
- if (running)
8
- return;
9
- running = true;
10
7
  try {
11
8
  await deliverPendingRemotePushNotifications();
12
9
  }
@@ -15,29 +12,23 @@ export async function runRemotePushDelivery() {
15
12
  error: error instanceof Error ? error.name : "UnknownError",
16
13
  });
17
14
  }
18
- finally {
19
- running = false;
20
- }
21
15
  }
22
16
  export function startRemotePushDeliveryJob() {
23
- if (retryInterval)
17
+ if (job || startupTimer)
24
18
  return;
25
- initialTimer = setTimeout(() => void runRemotePushDelivery(), 10_000);
26
- unrefTimer(initialTimer);
27
- retryInterval = setInterval(() => void runRemotePushDelivery(), DELIVERY_INTERVAL_MS);
28
- unrefTimer(retryInterval);
19
+ startupTimer = setTimeout(() => {
20
+ startupTimer = null;
21
+ job = startIntervalJob(runRemotePushDelivery, {
22
+ intervalMs: DELIVERY_INTERVAL_MS,
23
+ });
24
+ }, 10_000);
25
+ startupTimer.unref?.();
29
26
  }
30
27
  export function stopRemotePushDeliveryJob() {
31
- if (initialTimer) {
32
- clearTimeout(initialTimer);
33
- initialTimer = null;
28
+ if (startupTimer) {
29
+ clearTimeout(startupTimer);
30
+ startupTimer = null;
34
31
  }
35
- if (retryInterval) {
36
- clearInterval(retryInterval);
37
- retryInterval = null;
38
- }
39
- running = false;
40
- }
41
- function unrefTimer(timer) {
42
- timer.unref?.();
32
+ job?.stop();
33
+ job = null;
43
34
  }
@@ -1,7 +1,8 @@
1
+ import { startIntervalJob, } from "../server/interval-job.js";
1
2
  import { retryStaleRemoteCommands } from "./remote-commands-store.js";
2
3
  const RETRY_INTERVAL_MS = 60_000;
3
- let retryInterval = null;
4
- let initialTimer = null;
4
+ let job = null;
5
+ let startupTimer = null;
5
6
  export async function retryRemoteCommands() {
6
7
  try {
7
8
  return await retryStaleRemoteCommands();
@@ -14,31 +15,26 @@ export async function retryRemoteCommands() {
14
15
  }
15
16
  }
16
17
  export function startRemoteCommandsRetryJob() {
17
- if (retryInterval)
18
+ if (job || startupTimer)
18
19
  return;
19
- initialTimer = setTimeout(() => {
20
- void retryRemoteCommands().catch((err) => {
21
- console.error("[integrations] Remote command retry job error:", err);
20
+ startupTimer = setTimeout(() => {
21
+ startupTimer = null;
22
+ job = startIntervalJob(async () => {
23
+ await retryRemoteCommands();
24
+ }, {
25
+ intervalMs: RETRY_INTERVAL_MS,
26
+ onError: (err) => {
27
+ console.error("[integrations] Remote command retry job error:", err);
28
+ },
22
29
  });
23
30
  }, 10_000);
24
- unrefTimer(initialTimer);
25
- retryInterval = setInterval(() => {
26
- void retryRemoteCommands().catch((err) => {
27
- console.error("[integrations] Remote command retry job error:", err);
28
- });
29
- }, RETRY_INTERVAL_MS);
30
- unrefTimer(retryInterval);
31
+ startupTimer.unref?.();
31
32
  }
32
33
  export function stopRemoteCommandsRetryJob() {
33
- if (initialTimer) {
34
- clearTimeout(initialTimer);
35
- initialTimer = null;
36
- }
37
- if (retryInterval) {
38
- clearInterval(retryInterval);
39
- retryInterval = null;
34
+ if (startupTimer) {
35
+ clearTimeout(startupTimer);
36
+ startupTimer = null;
40
37
  }
41
- }
42
- function unrefTimer(timer) {
43
- timer.unref?.();
38
+ job?.stop();
39
+ job = null;
44
40
  }
@@ -27,7 +27,7 @@ export declare function createNotificationsHandler(): import("h3").EventHandlerW
27
27
  count?: undefined;
28
28
  } | {
29
29
  updated?: undefined;
30
- error?: undefined;
31
30
  ok: boolean;
31
+ error?: undefined;
32
32
  count?: undefined;
33
33
  }>>;
@@ -11,8 +11,11 @@
11
11
  * server plugin (see `templates/mail/server/plugins/oauth-refresh.ts`).
12
12
  */
13
13
  import { resolveGoogleProviderCredentialCandidates } from "../server/google-oauth-credentials.js";
14
+ import { startIntervalJob } from "../server/interval-job.js";
14
15
  import { listOAuthAccounts, saveOAuthTokens } from "./store.js";
15
16
  const GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
17
+ /** Bounds each per-account refresh call — this loop runs sequentially over every expiring account. */
18
+ const REFRESH_REQUEST_TIMEOUT_MS = 15_000;
16
19
  async function refreshOne(refreshToken) {
17
20
  const credentialCandidates = resolveGoogleProviderCredentialCandidates();
18
21
  if (!credentialCandidates.length) {
@@ -30,6 +33,7 @@ async function refreshOne(refreshToken) {
30
33
  client_secret: credentials.clientSecret,
31
34
  grant_type: "refresh_token",
32
35
  }),
36
+ signal: AbortSignal.timeout(REFRESH_REQUEST_TIMEOUT_MS),
33
37
  });
34
38
  lastStatusText = res.statusText;
35
39
  data = (await res.json());
@@ -91,7 +95,6 @@ export async function refreshExpiringGoogleTokens(opts = {}) {
91
95
  }
92
96
  }
93
97
  let _started = false;
94
- let _timer;
95
98
  /**
96
99
  * Start the refresh loop. Idempotent — calling more than once is a no-op,
97
100
  * so multiple plugins/templates loading this in the same process are safe.
@@ -108,25 +111,15 @@ export function startGoogleTokenRefreshLoop(opts = {}) {
108
111
  }
109
112
  const intervalMs = opts.intervalMs ?? 20 * 60 * 1000;
110
113
  const bufferMs = opts.bufferMs ?? 15 * 60 * 1000;
111
- // Kick off an initial pass shortly after startup (not immediately — the DB
114
+ // Kick off the first pass shortly after startup (not immediately — the DB
112
115
  // may still be initializing).
113
- const initialTimer = setTimeout(() => {
114
- refreshExpiringGoogleTokens({ bufferMs }).catch((err) => {
115
- console.error("[google-refresh] initial pass failed:", err);
116
+ const startupTimer = setTimeout(() => {
117
+ startIntervalJob(() => refreshExpiringGoogleTokens({ bufferMs }), {
118
+ intervalMs,
119
+ onError: (err) => {
120
+ console.error("[google-refresh] refresh pass failed:", err);
121
+ },
116
122
  });
117
123
  }, 30_000);
118
- _timer = setInterval(() => {
119
- refreshExpiringGoogleTokens({ bufferMs }).catch((err) => {
120
- console.error("[google-refresh] interval pass failed:", err);
121
- });
122
- }, intervalMs);
123
- // Don't let either timer keep the process alive on its own.
124
- if (typeof initialTimer === "object" &&
125
- initialTimer &&
126
- "unref" in initialTimer) {
127
- initialTimer.unref();
128
- }
129
- if (typeof _timer === "object" && _timer && "unref" in _timer) {
130
- _timer.unref();
131
- }
124
+ startupTimer.unref?.();
132
125
  }
@@ -75,8 +75,9 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
75
75
  user: "user";
76
76
  }>>;
77
77
  }, z.core.$strip>>, {
78
- deleted?: undefined;
79
78
  id?: undefined;
79
+ deleted?: undefined;
80
+ found?: undefined;
80
81
  providers: {
81
82
  id: string;
82
83
  label: string;
@@ -88,15 +89,14 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
88
89
  }[];
89
90
  count: number;
90
91
  provider?: undefined;
91
- found?: undefined;
92
92
  registered?: undefined;
93
93
  label?: undefined;
94
94
  message?: undefined;
95
95
  } | {
96
- deleted?: undefined;
97
- count?: undefined;
98
96
  id?: undefined;
97
+ deleted?: undefined;
99
98
  providers?: undefined;
99
+ count?: undefined;
100
100
  found: boolean;
101
101
  provider: import("../custom-registry.js").CustomProviderConfig;
102
102
  registered?: undefined;
@@ -104,8 +104,8 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
104
104
  message?: undefined;
105
105
  } | {
106
106
  deleted?: undefined;
107
- count?: undefined;
108
107
  providers?: undefined;
108
+ count?: undefined;
109
109
  provider?: undefined;
110
110
  found: boolean;
111
111
  id: string;
@@ -113,10 +113,10 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
113
113
  label?: undefined;
114
114
  message?: undefined;
115
115
  } | {
116
- count?: undefined;
116
+ found?: undefined;
117
117
  providers?: undefined;
118
+ count?: undefined;
118
119
  provider?: undefined;
119
- found?: undefined;
120
120
  deleted: boolean;
121
121
  id: string;
122
122
  registered?: undefined;
@@ -124,10 +124,10 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
124
124
  message?: undefined;
125
125
  } | {
126
126
  deleted?: undefined;
127
- count?: undefined;
127
+ found?: undefined;
128
128
  providers?: undefined;
129
+ count?: undefined;
129
130
  provider?: undefined;
130
- found?: undefined;
131
131
  registered: boolean;
132
132
  id: string;
133
133
  label: string;
@@ -311,10 +311,10 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
311
311
  notes?: string | undefined;
312
312
  scope?: "org" | "user" | undefined;
313
313
  }, {
314
- message?: undefined;
315
314
  id?: undefined;
316
315
  provider?: undefined;
317
316
  deleted?: undefined;
317
+ found?: undefined;
318
318
  providers: {
319
319
  id: string;
320
320
  label: string;
@@ -325,45 +325,45 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
325
325
  updatedAt: number;
326
326
  }[];
327
327
  count: number;
328
- found?: undefined;
329
328
  registered?: undefined;
330
329
  label?: undefined;
331
- } | {
332
330
  message?: undefined;
333
- count?: undefined;
331
+ } | {
334
332
  id?: undefined;
335
333
  deleted?: undefined;
334
+ count?: undefined;
336
335
  providers?: undefined;
337
336
  found: boolean;
338
337
  provider: import("../custom-registry.js").CustomProviderConfig;
339
338
  registered?: undefined;
340
339
  label?: undefined;
341
- } | {
342
340
  message?: undefined;
343
- count?: undefined;
341
+ } | {
344
342
  provider?: undefined;
345
343
  deleted?: undefined;
344
+ count?: undefined;
346
345
  providers?: undefined;
347
346
  found: boolean;
348
347
  id: string;
349
348
  registered?: undefined;
350
349
  label?: undefined;
351
- } | {
352
350
  message?: undefined;
353
- count?: undefined;
351
+ } | {
354
352
  provider?: undefined;
355
- providers?: undefined;
356
353
  found?: undefined;
354
+ count?: undefined;
355
+ providers?: undefined;
357
356
  deleted: boolean;
358
357
  id: string;
359
358
  registered?: undefined;
360
359
  label?: undefined;
360
+ message?: undefined;
361
361
  } | {
362
- count?: undefined;
363
362
  provider?: undefined;
364
363
  deleted?: undefined;
365
- providers?: undefined;
366
364
  found?: undefined;
365
+ count?: undefined;
366
+ providers?: undefined;
367
367
  registered: boolean;
368
368
  id: string;
369
369
  label: string;
@@ -41,6 +41,7 @@ import { captureError } from "./capture-error.js";
41
41
  import { getH3App, markDefaultPluginProvided, trackPluginInit, } from "./framework-request-handler.js";
42
42
  import { getOrigin } from "./google-oauth.js";
43
43
  import { readBody } from "./h3-helpers.js";
44
+ import { startIntervalJob } from "./interval-job.js";
44
45
  import { getModelFamilyOverlay } from "./prompts/index.js";
45
46
  import { mountRealtimeVoiceRoutes } from "./realtime-voice.js";
46
47
  import { runWithRequestContext, getRequestContext, getRequestOrgId, getRequestUserEmail, getRequestRunContext, ensureRequestRunContext, } from "./request-context.js";
@@ -4966,35 +4967,31 @@ Non-code requests are still fine on this surface: read data, navigate the UI, su
4966
4967
  setTimeout(() => {
4967
4968
  (async () => {
4968
4969
  const { UNCLAIMED_BACKGROUND_RUN_FAST_SWEEP_MS } = await import("../agent/run-store.js");
4969
- setInterval(() => {
4970
- (async () => {
4971
- const { listUnclaimedBackgroundRunRows, shouldRedispatchUnclaimedBackgroundRun, reapAllStaleRuns, } = await import("../agent/run-store.js");
4972
- // The unclaimed-background sweep below only matches
4973
- // dispatch_mode='background' — handoffs a worker never
4974
- // claimed. Once a worker CLAIMS a row nothing periodic looked
4975
- // at it again, so a dead producer was only reaped when some
4976
- // client request path or an unrelated run's cleanup happened
4977
- // to notice (prod: 24 minutes after the last heartbeat,
4978
- // against a 45s window). `reapAllStaleRuns` is per-row,
4979
- // idempotent, re-checks staleness at UPDATE time and honours
4980
- // the in-flight grace, so it is safe on this cadence.
4981
- await reapAllStaleRuns().catch(() => { });
4982
- let rows;
4983
- try {
4984
- rows = await listUnclaimedBackgroundRunRows();
4985
- }
4986
- catch {
4987
- return; // Table may not exist yet on first boot
4988
- }
4989
- for (const row of rows) {
4990
- if (!shouldRedispatchUnclaimedBackgroundRun(row))
4991
- continue;
4992
- await attemptUnclaimedBackgroundRunRedispatch(row).catch(() => { });
4993
- }
4994
- })().catch(() => {
4995
- // best-effort — never break the server
4996
- });
4997
- }, UNCLAIMED_BACKGROUND_RUN_FAST_SWEEP_MS);
4970
+ startIntervalJob(async () => {
4971
+ const { listUnclaimedBackgroundRunRows, shouldRedispatchUnclaimedBackgroundRun, reapAllStaleRuns, } = await import("../agent/run-store.js");
4972
+ // The unclaimed-background sweep below only matches
4973
+ // dispatch_mode='background' — handoffs a worker never
4974
+ // claimed. Once a worker CLAIMS a row nothing periodic looked
4975
+ // at it again, so a dead producer was only reaped when some
4976
+ // client request path or an unrelated run's cleanup happened
4977
+ // to notice (prod: 24 minutes after the last heartbeat,
4978
+ // against a 45s window). `reapAllStaleRuns` is per-row,
4979
+ // idempotent, re-checks staleness at UPDATE time and honours
4980
+ // the in-flight grace, so it is safe on this cadence.
4981
+ await reapAllStaleRuns().catch(() => { });
4982
+ let rows;
4983
+ try {
4984
+ rows = await listUnclaimedBackgroundRunRows();
4985
+ }
4986
+ catch {
4987
+ return; // Table may not exist yet on first boot
4988
+ }
4989
+ for (const row of rows) {
4990
+ if (!shouldRedispatchUnclaimedBackgroundRun(row))
4991
+ continue;
4992
+ await attemptUnclaimedBackgroundRunRedispatch(row).catch(() => { });
4993
+ }
4994
+ }, { intervalMs: UNCLAIMED_BACKGROUND_RUN_FAST_SWEEP_MS });
4998
4995
  })().catch(() => {
4999
4996
  // best-effort — if run-store fails to load, the slow sweep below
5000
4997
  // still provides eventual (loud) recovery.
@@ -1,4 +1,5 @@
1
1
  export { createServer, type CreateServerOptions, type EnvKeyConfig, } from "./create-server.js";
2
+ export { startIntervalJob, type IntervalJobOptions, type IntervalJobHandle, } from "./interval-job.js";
2
3
  export { AGENT_BACKGROUND_PROCESSOR_FIELD, AGENT_BACKGROUND_PROCESSOR_ROUTE, AGENT_BACKGROUND_PROCESSOR_ROUTE_FIELD, dispatchPathTargetsNetlifyBackgroundFunction, isInBackgroundFunctionRuntime, resolveDurableBackgroundDispatchPath, } from "../agent/durable-background.js";
3
4
  export { readBody, readBodyWithSizeLimit, streamFile, DEFAULT_CHAT_MAX_BODY_BYTES, DEFAULT_UPLOAD_MAX_FILE_BYTES, MAX_CHAT_ATTACHMENTS_PER_MESSAGE, isAllowedUploadMimeType, } from "./h3-helpers.js";
4
5
  export { buildDeepLink, toAbsoluteOpenUrl, toDesktopOpenUrl, toVsCodeOpenUrl, OPEN_ROUTE_SUBPATH, DESKTOP_OPEN_URL, VSCODE_OPEN_URL, type DeepLinkInput, } from "./deep-link.js";
@@ -1,4 +1,5 @@
1
1
  export { createServer, } from "./create-server.js";
2
+ export { startIntervalJob, } from "./interval-job.js";
2
3
  export { AGENT_BACKGROUND_PROCESSOR_FIELD, AGENT_BACKGROUND_PROCESSOR_ROUTE, AGENT_BACKGROUND_PROCESSOR_ROUTE_FIELD, dispatchPathTargetsNetlifyBackgroundFunction, isInBackgroundFunctionRuntime, resolveDurableBackgroundDispatchPath, } from "../agent/durable-background.js";
3
4
  export { readBody, readBodyWithSizeLimit, streamFile, DEFAULT_CHAT_MAX_BODY_BYTES, DEFAULT_UPLOAD_MAX_FILE_BYTES, MAX_CHAT_ATTACHMENTS_PER_MESSAGE, isAllowedUploadMimeType, } from "./h3-helpers.js";
4
5
  export { buildDeepLink, toAbsoluteOpenUrl, toDesktopOpenUrl, toVsCodeOpenUrl, OPEN_ROUTE_SUBPATH, DESKTOP_OPEN_URL, VSCODE_OPEN_URL, } from "./deep-link.js";
@@ -0,0 +1,25 @@
1
+ export interface IntervalJobOptions {
2
+ /** Delay in ms between runs. */
3
+ intervalMs: number;
4
+ /** Per-run timeout. Default: `Math.max(timeoutFloorMs, intervalMs * 4)`. */
5
+ timeoutMs?: number;
6
+ /** Floor used by the default `timeoutMs`. Default: 10_000. */
7
+ timeoutFloorMs?: number;
8
+ /** Called when a run throws or times out. Default: swallow (a background job shouldn't crash the host process). */
9
+ onError?: (err: unknown) => void;
10
+ /** Run immediately on start. Default: true. */
11
+ leading?: boolean;
12
+ }
13
+ export interface IntervalJobHandle {
14
+ stop(): void;
15
+ }
16
+ /**
17
+ * Run a background job on a recurring interval without hand-rolling a
18
+ * `running` overlap guard or a request timeout — see `createPollEngine` for
19
+ * the underlying guarantees. `runOnce` keeps its normal exported signature
20
+ * (serverless schedulers can still call it directly, bypassing the loop);
21
+ * this only replaces the `setInterval` + module-level flag wiring around it.
22
+ * The internal timer is `.unref()`'d so it never keeps the process alive on
23
+ * its own.
24
+ */
25
+ export declare function startIntervalJob(runOnce: (signal: AbortSignal) => Promise<void>, options: IntervalJobOptions): IntervalJobHandle;