@agent-native/core 0.144.1 → 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.
- package/corpus/templates/analytics/app/pages/DataSources.tsx +28 -4
- package/corpus/templates/analytics/server/jobs/dashboard-report.ts +7 -3
- package/corpus/templates/analytics/server/plugins/dashboard-report-jobs.ts +13 -3
- package/corpus/templates/calendar/app/components/calendar/GoogleConnectBanner.tsx +64 -23
- package/corpus/templates/calendar/app/hooks/use-google-auth.ts +69 -46
- package/corpus/templates/calendar/app/hooks/use-view-preferences.ts +35 -6
- package/corpus/templates/calendar/app/hooks/use-zoom-auth.ts +24 -3
- package/corpus/templates/clips/app/components/player/transcript-panel.tsx +45 -6
- package/corpus/templates/clips/app/components/recorder/storage-setup-card.tsx +38 -5
- package/corpus/templates/clips/desktop/src/app.tsx +146 -45
- package/corpus/templates/clips/server/jobs/brain-export.ts +13 -6
- package/corpus/templates/clips/server/jobs/builder-media-compression.ts +10 -3
- package/corpus/templates/clips/server/jobs/meeting-reminders.ts +10 -3
- package/corpus/templates/clips/server/jobs/poll-calendars.ts +23 -21
- package/corpus/templates/clips/server/jobs/stale-meeting-sweeper.ts +10 -3
- package/corpus/templates/clips/server/jobs/transactional-emails.ts +10 -3
- package/corpus/templates/content/app/components/sidebar/NotionButton.tsx +1 -0
- package/corpus/templates/design/app/components/design/FusionAppBanner.tsx +15 -2
- package/corpus/templates/mail/app/components/GoogleConnectBanner.tsx +82 -39
- package/corpus/templates/mail/app/components/layout/AppLayout.tsx +31 -9
- package/corpus/templates/mail/server/plugins/mail-jobs.ts +36 -17
- package/dist/client/AssistantChat.js +73 -43
- package/dist/client/MultiTabAssistantChat.d.ts +3 -1
- package/dist/client/MultiTabAssistantChat.js +79 -92
- package/dist/client/analytics/index.d.ts +1 -1
- package/dist/client/analytics/index.js +1 -1
- package/dist/client/analytics-session.d.ts +13 -0
- package/dist/client/analytics-session.js +57 -0
- package/dist/client/analytics.d.ts +1 -0
- package/dist/client/analytics.js +1 -0
- package/dist/client/browser-session-bridge.js +97 -54
- package/dist/client/db-admin/useAgentSync.js +34 -43
- package/dist/client/dynamic-suggestions.d.ts +3 -0
- package/dist/client/dynamic-suggestions.js +54 -52
- package/dist/client/hooks/index.d.ts +1 -0
- package/dist/client/hooks/index.js +1 -0
- package/dist/client/i18n.d.ts +7 -0
- package/dist/client/i18n.js +12 -3
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/integrations/useIntegrationStatus.d.ts +1 -1
- package/dist/client/integrations/useIntegrationStatus.js +9 -22
- package/dist/client/notifications/NotificationsBell.js +14 -9
- package/dist/client/progress/RunsTray.js +6 -5
- package/dist/client/settings/useBuilderStatus.js +95 -73
- package/dist/client/track.js +7 -0
- package/dist/client/transcription/BuilderTranscriptionCta.js +27 -31
- package/dist/client/use-action.js +10 -1
- package/dist/client/use-agent-engine-configured.js +21 -3
- package/dist/client/use-pausing-interval.d.ts +6 -0
- package/dist/client/use-pausing-interval.js +6 -0
- package/dist/client/use-poll-loop.d.ts +39 -0
- package/dist/client/use-poll-loop.js +73 -0
- package/dist/client/use-run-stuck-detection.js +41 -13
- package/dist/file-upload/actions/upload-image.d.ts +1 -1
- package/dist/integrations/google-docs-poller.js +26 -7
- package/dist/integrations/pending-tasks-retry-job.js +17 -23
- package/dist/integrations/plugin.js +16 -15
- package/dist/integrations/remote-push-delivery-job.js +16 -25
- package/dist/integrations/remote-retry-job.js +19 -23
- package/dist/mcp/screen-memory-stdio.d.ts +7 -7
- package/dist/notifications/routes.d.ts +3 -3
- package/dist/oauth-tokens/google-refresh.js +12 -19
- package/dist/observability/routes.d.ts +3 -3
- package/dist/progress/routes.d.ts +1 -1
- package/dist/provider-api/actions/custom-provider-registration.d.ts +7 -7
- package/dist/provider-api/actions/provider-api.d.ts +11 -11
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/secrets/routes.d.ts +3 -3
- package/dist/server/action-routes.js +4 -2
- package/dist/server/agent-chat-plugin.js +26 -29
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/dist/server/agent-run-context.d.ts +4 -2
- package/dist/server/agent-run-context.js +5 -3
- package/dist/server/core-routes-plugin.js +2 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/interval-job.d.ts +25 -0
- package/dist/server/interval-job.js +19 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +1 -0
- package/dist/shared/poll-engine.d.ts +49 -0
- package/dist/shared/poll-engine.js +148 -0
- package/dist/templates/default/.agents/skills/internationalization/SKILL.md +5 -0
- package/dist/templates/workspace-core/.agents/skills/internationalization/SKILL.md +5 -0
- package/dist/templates/workspace-core/.agents/skills/observability/SKILL.md +5 -1
- package/dist/templates/workspace-core/.agents/skills/tracking/SKILL.md +20 -3
- package/dist/tracking/index.d.ts +1 -1
- package/dist/tracking/providers.js +22 -2
- package/dist/tracking/registry.d.ts +12 -2
- package/dist/tracking/registry.js +27 -3
- package/dist/tracking/types.d.ts +8 -0
- package/docs/content/observability.mdx +16 -0
- package/docs/content/tracking.mdx +17 -2
- package/package.json +4 -3
- package/src/templates/default/.agents/skills/internationalization/SKILL.md +5 -0
- package/src/templates/workspace-core/.agents/skills/internationalization/SKILL.md +5 -0
- package/src/templates/workspace-core/.agents/skills/observability/SKILL.md +5 -1
- package/src/templates/workspace-core/.agents/skills/tracking/SKILL.md +20 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState, useCallback } from "react";
|
|
2
|
+
import { createPollEngine } from "../shared/poll-engine.js";
|
|
2
3
|
import { agentNativePath } from "./api-path.js";
|
|
3
4
|
const DEFAULT_STUCK_THRESHOLD_MS = 90_000;
|
|
4
5
|
export const DEFAULT_BACKGROUND_STUCK_THRESHOLD_MS = 180_000;
|
|
@@ -7,6 +8,12 @@ const DEFAULT_POLL_INTERVAL_MS = 5_000;
|
|
|
7
8
|
const IDLE_BACKOFF_INTERVAL_MS = 15_000;
|
|
8
9
|
const MAX_POLL_ERROR_BACKOFF_MS = 30_000;
|
|
9
10
|
const FRESH_BACKGROUND_HEARTBEAT_MS = 30_000;
|
|
11
|
+
// Bounds each poll fetch so a hung request can't stall the self-rescheduling
|
|
12
|
+
// setTimeout loop forever (the reschedule only fires once the fetch settles).
|
|
13
|
+
const POLL_ABORT_MIN_MS = 10_000;
|
|
14
|
+
function getPollAbortMs(interval) {
|
|
15
|
+
return Math.max(POLL_ABORT_MIN_MS, interval * 4);
|
|
16
|
+
}
|
|
10
17
|
const EMPTY_STATE = {
|
|
11
18
|
isStuck: false,
|
|
12
19
|
runId: null,
|
|
@@ -28,10 +35,15 @@ export function useRunStuckDetection({ threadId, enabled = true, stuckThresholdM
|
|
|
28
35
|
return;
|
|
29
36
|
const base = apiUrl ?? agentNativePath("/_agent-native/agent-chat");
|
|
30
37
|
let cancelled = false;
|
|
31
|
-
let timer = null;
|
|
32
38
|
let snapshotTransitionTimer = null;
|
|
33
39
|
let snapshotVersion = 0;
|
|
34
40
|
let consecutivePollFailures = 0;
|
|
41
|
+
// The engine's own cadence varies per tick (idle backoff, error backoff),
|
|
42
|
+
// which is why intervalMs below reads from this ref instead of a fixed
|
|
43
|
+
// number. Stagger the very first poll so a freshly-started run isn't
|
|
44
|
+
// immediately classified as stuck before the server has had a chance to
|
|
45
|
+
// record any progress events.
|
|
46
|
+
const nextDelayRef = { current: 2_000 };
|
|
35
47
|
const pollFailureDelay = () => {
|
|
36
48
|
consecutivePollFailures += 1;
|
|
37
49
|
return Math.min(Math.max(pollIntervalMs, 1) * 2 ** consecutivePollFailures, MAX_POLL_ERROR_BACKOFF_MS);
|
|
@@ -124,12 +136,10 @@ export function useRunStuckDetection({ threadId, enabled = true, stuckThresholdM
|
|
|
124
136
|
scheduleSnapshotTransition(snapshot, observedAtMs, version);
|
|
125
137
|
}, delayMs);
|
|
126
138
|
};
|
|
127
|
-
const
|
|
128
|
-
if (cancelled)
|
|
129
|
-
return;
|
|
139
|
+
const attempt = async (signal) => {
|
|
130
140
|
let nextDelay = pollIntervalMs;
|
|
131
141
|
try {
|
|
132
|
-
const res = await fetch(`${base}/runs/active?threadId=${encodeURIComponent(threadId)}`, { credentials: "same-origin" });
|
|
142
|
+
const res = await fetch(`${base}/runs/active?threadId=${encodeURIComponent(threadId)}`, { credentials: "same-origin", signal });
|
|
133
143
|
if (cancelled)
|
|
134
144
|
return;
|
|
135
145
|
if (res.ok) {
|
|
@@ -203,21 +213,39 @@ export function useRunStuckDetection({ threadId, enabled = true, stuckThresholdM
|
|
|
203
213
|
// while the server or database recovers.
|
|
204
214
|
nextDelay = pollFailureDelay();
|
|
205
215
|
}
|
|
206
|
-
|
|
207
|
-
|
|
216
|
+
finally {
|
|
217
|
+
nextDelayRef.current = nextDelay;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
// The per-tick backoff above needs a variable cadence, which is why this
|
|
221
|
+
// uses createPollEngine directly instead of usePollLoop (whose public
|
|
222
|
+
// intervalMs is a fixed number) — see poll-engine.ts for the
|
|
223
|
+
// never-overlaps/never-stalls guarantees this still gets for free.
|
|
224
|
+
const engine = createPollEngine(attempt, {
|
|
225
|
+
intervalMs: () => nextDelayRef.current,
|
|
226
|
+
timeoutMs: getPollAbortMs(pollIntervalMs),
|
|
227
|
+
leading: false,
|
|
228
|
+
});
|
|
229
|
+
engine.start();
|
|
230
|
+
const onVisibilityChange = () => {
|
|
231
|
+
if (document.hidden) {
|
|
232
|
+
engine.stop();
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
// Resume immediately rather than waiting out whatever delay was
|
|
236
|
+
// pending before the tab was hidden (which may be a long backoff).
|
|
237
|
+
engine.start();
|
|
238
|
+
engine.pollNow();
|
|
208
239
|
}
|
|
209
240
|
};
|
|
210
|
-
|
|
211
|
-
// classified as stuck before the server has had a chance to record
|
|
212
|
-
// any progress events.
|
|
213
|
-
timer = setTimeout(poll, 2_000);
|
|
241
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
214
242
|
return () => {
|
|
215
243
|
cancelled = true;
|
|
216
244
|
snapshotVersion += 1;
|
|
217
|
-
|
|
218
|
-
clearTimeout(timer);
|
|
245
|
+
engine.stop();
|
|
219
246
|
if (snapshotTransitionTimer)
|
|
220
247
|
clearTimeout(snapshotTransitionTimer);
|
|
248
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
221
249
|
};
|
|
222
250
|
}, [
|
|
223
251
|
threadId,
|
|
@@ -17,11 +17,11 @@ declare const _default: import("../../action.js").ActionDefinition<{
|
|
|
17
17
|
id?: undefined;
|
|
18
18
|
provider?: undefined;
|
|
19
19
|
} | {
|
|
20
|
-
error?: undefined;
|
|
21
20
|
configured?: undefined;
|
|
22
21
|
connectPath?: undefined;
|
|
23
22
|
url: string;
|
|
24
23
|
id: string;
|
|
25
24
|
provider: string;
|
|
25
|
+
error?: undefined;
|
|
26
26
|
}>;
|
|
27
27
|
export default _default;
|
|
@@ -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
|
|
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 (
|
|
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
|
-
|
|
494
|
-
|
|
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 (
|
|
505
|
-
|
|
506
|
-
|
|
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
|
|
43
|
-
let
|
|
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 (
|
|
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
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
-
|
|
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 (
|
|
294
|
-
clearTimeout(
|
|
295
|
-
|
|
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
|
-
|
|
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 (
|
|
165
|
+
if (a2aContinuationJob || a2aContinuationStartupTimer)
|
|
160
166
|
return;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
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
|
|
4
|
-
let
|
|
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 (
|
|
17
|
+
if (job || startupTimer)
|
|
24
18
|
return;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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 (
|
|
32
|
-
clearTimeout(
|
|
33
|
-
|
|
28
|
+
if (startupTimer) {
|
|
29
|
+
clearTimeout(startupTimer);
|
|
30
|
+
startupTimer = null;
|
|
34
31
|
}
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
4
|
-
let
|
|
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 (
|
|
18
|
+
if (job || startupTimer)
|
|
18
19
|
return;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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 (
|
|
34
|
-
clearTimeout(
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
if (retryInterval) {
|
|
38
|
-
clearInterval(retryInterval);
|
|
39
|
-
retryInterval = null;
|
|
34
|
+
if (startupTimer) {
|
|
35
|
+
clearTimeout(startupTimer);
|
|
36
|
+
startupTimer = null;
|
|
40
37
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
timer.unref?.();
|
|
38
|
+
job?.stop();
|
|
39
|
+
job = null;
|
|
44
40
|
}
|
|
@@ -137,13 +137,13 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
137
137
|
inputSchema: {
|
|
138
138
|
type: string;
|
|
139
139
|
properties: {
|
|
140
|
-
count?: undefined;
|
|
141
140
|
query?: undefined;
|
|
142
141
|
minutes?: undefined;
|
|
143
142
|
limit?: undefined;
|
|
144
143
|
clientHint?: undefined;
|
|
145
144
|
timestamp?: undefined;
|
|
146
145
|
chapterId?: undefined;
|
|
146
|
+
count?: undefined;
|
|
147
147
|
startAt?: undefined;
|
|
148
148
|
endAt?: undefined;
|
|
149
149
|
reason?: undefined;
|
|
@@ -159,7 +159,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
159
159
|
inputSchema: {
|
|
160
160
|
type: string;
|
|
161
161
|
properties: {
|
|
162
|
-
count?: undefined;
|
|
163
162
|
query: {
|
|
164
163
|
type: string;
|
|
165
164
|
description: string;
|
|
@@ -175,6 +174,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
175
174
|
clientHint?: undefined;
|
|
176
175
|
timestamp?: undefined;
|
|
177
176
|
chapterId?: undefined;
|
|
177
|
+
count?: undefined;
|
|
178
178
|
startAt?: undefined;
|
|
179
179
|
endAt?: undefined;
|
|
180
180
|
reason?: undefined;
|
|
@@ -190,7 +190,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
190
190
|
inputSchema: {
|
|
191
191
|
type: string;
|
|
192
192
|
properties: {
|
|
193
|
-
count?: undefined;
|
|
194
193
|
minutes: {
|
|
195
194
|
type: string;
|
|
196
195
|
description: string;
|
|
@@ -200,6 +199,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
200
199
|
clientHint?: undefined;
|
|
201
200
|
timestamp?: undefined;
|
|
202
201
|
chapterId?: undefined;
|
|
202
|
+
count?: undefined;
|
|
203
203
|
startAt?: undefined;
|
|
204
204
|
endAt?: undefined;
|
|
205
205
|
reason?: undefined;
|
|
@@ -216,7 +216,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
216
216
|
type: string;
|
|
217
217
|
required: string[];
|
|
218
218
|
properties: {
|
|
219
|
-
count?: undefined;
|
|
220
219
|
query: {
|
|
221
220
|
type: string;
|
|
222
221
|
description: string;
|
|
@@ -235,6 +234,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
235
234
|
};
|
|
236
235
|
timestamp?: undefined;
|
|
237
236
|
chapterId?: undefined;
|
|
237
|
+
count?: undefined;
|
|
238
238
|
startAt?: undefined;
|
|
239
239
|
endAt?: undefined;
|
|
240
240
|
reason?: undefined;
|
|
@@ -250,7 +250,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
250
250
|
type: string;
|
|
251
251
|
required: string[];
|
|
252
252
|
properties: {
|
|
253
|
-
count?: undefined;
|
|
254
253
|
query?: undefined;
|
|
255
254
|
minutes?: undefined;
|
|
256
255
|
limit?: undefined;
|
|
@@ -264,6 +263,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
264
263
|
description: string;
|
|
265
264
|
};
|
|
266
265
|
chapterId?: undefined;
|
|
266
|
+
count?: undefined;
|
|
267
267
|
startAt?: undefined;
|
|
268
268
|
endAt?: undefined;
|
|
269
269
|
includeMicrophone?: undefined;
|
|
@@ -314,13 +314,13 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
314
314
|
type: string;
|
|
315
315
|
required: string[];
|
|
316
316
|
properties: {
|
|
317
|
-
count?: undefined;
|
|
318
317
|
query?: undefined;
|
|
319
318
|
minutes?: undefined;
|
|
320
319
|
limit?: undefined;
|
|
321
320
|
clientHint?: undefined;
|
|
322
321
|
timestamp?: undefined;
|
|
323
322
|
chapterId?: undefined;
|
|
323
|
+
count?: undefined;
|
|
324
324
|
startAt: {
|
|
325
325
|
type: string;
|
|
326
326
|
description: string;
|
|
@@ -349,13 +349,13 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
349
349
|
type: string;
|
|
350
350
|
required: string[];
|
|
351
351
|
properties: {
|
|
352
|
-
count?: undefined;
|
|
353
352
|
query?: undefined;
|
|
354
353
|
minutes?: undefined;
|
|
355
354
|
limit?: undefined;
|
|
356
355
|
clientHint?: undefined;
|
|
357
356
|
timestamp?: undefined;
|
|
358
357
|
chapterId?: undefined;
|
|
358
|
+
count?: undefined;
|
|
359
359
|
startAt?: undefined;
|
|
360
360
|
endAt?: undefined;
|
|
361
361
|
reason?: undefined;
|
|
@@ -16,18 +16,18 @@ export declare function createNotificationsHandler(): import("h3").EventHandlerW
|
|
|
16
16
|
error?: undefined;
|
|
17
17
|
ok?: undefined;
|
|
18
18
|
} | {
|
|
19
|
-
count?: undefined;
|
|
20
19
|
updated: number;
|
|
21
20
|
error?: undefined;
|
|
22
21
|
ok?: undefined;
|
|
23
|
-
} | {
|
|
24
22
|
count?: undefined;
|
|
23
|
+
} | {
|
|
25
24
|
updated?: undefined;
|
|
26
25
|
error: string;
|
|
27
26
|
ok?: undefined;
|
|
28
|
-
} | {
|
|
29
27
|
count?: undefined;
|
|
28
|
+
} | {
|
|
30
29
|
updated?: undefined;
|
|
31
30
|
ok: boolean;
|
|
32
31
|
error?: undefined;
|
|
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
|
|
114
|
+
// Kick off the first pass shortly after startup (not immediately — the DB
|
|
112
115
|
// may still be initializing).
|
|
113
|
-
const
|
|
114
|
-
refreshExpiringGoogleTokens({ bufferMs })
|
|
115
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -42,22 +42,22 @@ export declare function createObservabilityHandler(): import("h3").EventHandlerW
|
|
|
42
42
|
avgEvalScore: number;
|
|
43
43
|
} | {
|
|
44
44
|
error?: undefined;
|
|
45
|
-
ok?: undefined;
|
|
46
45
|
summary: import("./types.js").TraceSummary;
|
|
47
46
|
spans: import("./types.js").TraceSpan[];
|
|
48
47
|
id?: undefined;
|
|
48
|
+
ok?: undefined;
|
|
49
49
|
} | {
|
|
50
50
|
error?: undefined;
|
|
51
|
-
ok?: undefined;
|
|
52
51
|
summary?: undefined;
|
|
53
52
|
spans?: undefined;
|
|
54
53
|
id: string;
|
|
55
|
-
} | {
|
|
56
54
|
ok?: undefined;
|
|
55
|
+
} | {
|
|
57
56
|
summary?: undefined;
|
|
58
57
|
spans?: undefined;
|
|
59
58
|
id?: undefined;
|
|
60
59
|
error: any;
|
|
60
|
+
ok?: undefined;
|
|
61
61
|
} | {
|
|
62
62
|
error?: undefined;
|
|
63
63
|
summary?: undefined;
|