@agent-native/core 0.101.2 → 0.101.4

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 (90) hide show
  1. package/corpus/README.md +1 -1
  2. package/corpus/core/CHANGELOG.md +25 -0
  3. package/corpus/core/package.json +1 -1
  4. package/corpus/core/src/client/RunStuckBanner.tsx +12 -5
  5. package/corpus/core/src/client/sse-event-processor.ts +36 -1
  6. package/corpus/core/src/client/use-run-stuck-detection.ts +162 -25
  7. package/corpus/core/src/credentials/index.ts +41 -8
  8. package/corpus/core/src/deploy/build.ts +78 -25
  9. package/corpus/core/src/extensions/fetch-tool.ts +33 -3
  10. package/corpus/core/src/notifications/channels.ts +20 -6
  11. package/corpus/core/src/secrets/crypto.ts +26 -10
  12. package/corpus/core/src/secrets/storage.ts +16 -3
  13. package/corpus/core/src/server/agent-chat-plugin.ts +60 -7
  14. package/corpus/core/src/server/derived-secret.ts +5 -1
  15. package/corpus/templates/analytics/changelog/2026-07-14-long-running-cross-app-analyses-now-continue-reliably-in-the.md +6 -0
  16. package/corpus/templates/analytics/server/plugins/agent-chat.ts +8 -4
  17. package/corpus/templates/chat/changelog/2026-07-14-chat-opens-reliably-on-hosted-deployments-instead-of-failing.md +6 -0
  18. package/corpus/templates/clips/app/components/player/media-duration.ts +24 -0
  19. package/corpus/templates/clips/app/components/player/share-dialog.tsx +44 -81
  20. package/corpus/templates/clips/app/components/player/video-player.tsx +9 -18
  21. package/corpus/templates/clips/app/i18n/ar-SA.ts +0 -8
  22. package/corpus/templates/clips/app/i18n/de-DE.ts +0 -9
  23. package/corpus/templates/clips/app/i18n/en-US.ts +0 -8
  24. package/corpus/templates/clips/app/i18n/es-ES.ts +0 -9
  25. package/corpus/templates/clips/app/i18n/fr-FR.ts +0 -9
  26. package/corpus/templates/clips/app/i18n/hi-IN.ts +0 -8
  27. package/corpus/templates/clips/app/i18n/ja-JP.ts +0 -9
  28. package/corpus/templates/clips/app/i18n/ko-KR.ts +0 -9
  29. package/corpus/templates/clips/app/i18n/pt-BR.ts +0 -9
  30. package/corpus/templates/clips/app/i18n/zh-CN.ts +0 -7
  31. package/corpus/templates/clips/app/i18n/zh-TW.ts +0 -7
  32. package/corpus/templates/clips/changelog/2026-07-14-paused-time-no-longer-counts-toward-chrome-extension-recordi.md +6 -0
  33. package/corpus/templates/clips/changelog/2026-07-14-share-dialogs-show-separate-links-for-people-and-agents.md +6 -0
  34. package/corpus/templates/clips/chrome-extension/src/offscreen.ts +30 -4
  35. package/corpus/templates/clips/chrome-extension/src/recording-duration.ts +32 -0
  36. package/corpus/templates/dispatch/changelog/2026-07-14-dispatch-now-distinguishes-connected-agents-from-locally-mou.md +6 -0
  37. package/corpus/templates/slides/actions/_uploaded-files.ts +13 -2
  38. package/corpus/templates/slides/actions/import-docx.ts +3 -9
  39. package/corpus/templates/slides/actions/import-file.ts +11 -14
  40. package/corpus/templates/slides/actions/import-pptx.ts +3 -9
  41. package/corpus/templates/slides/changelog/2026-07-14-powerpoint-template-uploads-now-work-in-hosted-slides-deploy.md +6 -0
  42. package/corpus/templates/slides/server/handlers/uploads.ts +100 -50
  43. package/corpus/templates/slides/server/lib/tenant-files.ts +38 -11
  44. package/corpus/templates/slides/server/lib/uploaded-reference-storage.ts +108 -0
  45. package/dist/client/RunStuckBanner.d.ts.map +1 -1
  46. package/dist/client/RunStuckBanner.js +9 -5
  47. package/dist/client/RunStuckBanner.js.map +1 -1
  48. package/dist/client/sse-event-processor.d.ts.map +1 -1
  49. package/dist/client/sse-event-processor.js +33 -1
  50. package/dist/client/sse-event-processor.js.map +1 -1
  51. package/dist/client/use-run-stuck-detection.d.ts +4 -4
  52. package/dist/client/use-run-stuck-detection.d.ts.map +1 -1
  53. package/dist/client/use-run-stuck-detection.js +104 -19
  54. package/dist/client/use-run-stuck-detection.js.map +1 -1
  55. package/dist/collab/awareness.d.ts +2 -2
  56. package/dist/collab/awareness.d.ts.map +1 -1
  57. package/dist/credentials/index.d.ts +12 -7
  58. package/dist/credentials/index.d.ts.map +1 -1
  59. package/dist/credentials/index.js +33 -8
  60. package/dist/credentials/index.js.map +1 -1
  61. package/dist/deploy/build.d.ts +15 -14
  62. package/dist/deploy/build.d.ts.map +1 -1
  63. package/dist/deploy/build.js +64 -23
  64. package/dist/deploy/build.js.map +1 -1
  65. package/dist/extensions/fetch-tool.d.ts +13 -1
  66. package/dist/extensions/fetch-tool.d.ts.map +1 -1
  67. package/dist/extensions/fetch-tool.js +9 -2
  68. package/dist/extensions/fetch-tool.js.map +1 -1
  69. package/dist/notifications/channels.js +20 -4
  70. package/dist/notifications/channels.js.map +1 -1
  71. package/dist/observability/routes.d.ts +1 -1
  72. package/dist/progress/routes.d.ts +1 -1
  73. package/dist/resources/handlers.d.ts +1 -1
  74. package/dist/secrets/crypto.d.ts +15 -7
  75. package/dist/secrets/crypto.d.ts.map +1 -1
  76. package/dist/secrets/crypto.js +23 -10
  77. package/dist/secrets/crypto.js.map +1 -1
  78. package/dist/secrets/storage.d.ts.map +1 -1
  79. package/dist/secrets/storage.js +16 -3
  80. package/dist/secrets/storage.js.map +1 -1
  81. package/dist/server/agent-chat-plugin.d.ts +20 -0
  82. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  83. package/dist/server/agent-chat-plugin.js +38 -4
  84. package/dist/server/agent-chat-plugin.js.map +1 -1
  85. package/dist/server/agent-engine-api-key-route.d.ts +1 -1
  86. package/dist/server/derived-secret.d.ts +1 -1
  87. package/dist/server/derived-secret.d.ts.map +1 -1
  88. package/dist/server/derived-secret.js.map +1 -1
  89. package/package.json +2 -2
  90. package/corpus/templates/clips/app/components/sharing/slack-share-hint.tsx +0 -68
@@ -28,6 +28,89 @@ export function useRunStuckDetection({ threadId, enabled = true, stuckThresholdM
28
28
  const base = apiUrl ?? agentNativePath("/_agent-native/agent-chat");
29
29
  let cancelled = false;
30
30
  let timer = null;
31
+ let snapshotTransitionTimer = null;
32
+ let snapshotVersion = 0;
33
+ const effectiveThresholdFor = (dispatchMode, heartbeatSinceMs) => {
34
+ const liveBackgroundWorker = dispatchMode === "background-processing" &&
35
+ heartbeatSinceMs != null &&
36
+ heartbeatSinceMs >= 0 &&
37
+ heartbeatSinceMs < FRESH_BACKGROUND_HEARTBEAT_MS;
38
+ const serverContinued = dispatchMode === "foreground-self-chain" ||
39
+ dispatchMode?.startsWith("background") === true;
40
+ return liveBackgroundWorker
41
+ ? Math.min(backgroundStuckThresholdMs, liveBackgroundStuckThresholdMs)
42
+ : serverContinued
43
+ ? backgroundStuckThresholdMs
44
+ : stuckThresholdMs;
45
+ };
46
+ const scheduleSnapshotTransition = (snapshot, observedAtMs, version) => {
47
+ if (snapshotTransitionTimer)
48
+ clearTimeout(snapshotTransitionTimer);
49
+ snapshotTransitionTimer = null;
50
+ if (cancelled ||
51
+ version !== snapshotVersion ||
52
+ !snapshot.active ||
53
+ snapshot.status !== "running" ||
54
+ snapshot.runId == null) {
55
+ return;
56
+ }
57
+ const currentElapsedMs = Math.max(0, Date.now() - observedAtMs);
58
+ const currentHeartbeatSinceMs = snapshot.heartbeatSinceMs == null
59
+ ? null
60
+ : snapshot.heartbeatSinceMs + currentElapsedMs;
61
+ const currentStuckSinceMs = snapshot.stuckSinceMs == null
62
+ ? null
63
+ : snapshot.stuckSinceMs + currentElapsedMs;
64
+ const effectiveThresholdMs = effectiveThresholdFor(snapshot.dispatchMode, currentHeartbeatSinceMs);
65
+ const currentlyStuck = Boolean(currentStuckSinceMs != null &&
66
+ currentStuckSinceMs > effectiveThresholdMs);
67
+ const transitionDelaysMs = [];
68
+ if (currentHeartbeatSinceMs != null &&
69
+ currentHeartbeatSinceMs >= 0 &&
70
+ currentHeartbeatSinceMs < FRESH_BACKGROUND_HEARTBEAT_MS) {
71
+ transitionDelaysMs.push(FRESH_BACKGROUND_HEARTBEAT_MS - currentHeartbeatSinceMs + 1);
72
+ }
73
+ if (currentStuckSinceMs != null && !currentlyStuck) {
74
+ transitionDelaysMs.push(Math.max(1, effectiveThresholdMs - currentStuckSinceMs + 1));
75
+ }
76
+ if (transitionDelaysMs.length === 0)
77
+ return;
78
+ // Both ages originate from the server clock. Advance those snapshots by
79
+ // only a local elapsed duration, which remains safe when client/server
80
+ // wall clocks differ. Wake at the earlier semantic boundary, then
81
+ // reschedule if the other boundary is still ahead.
82
+ const delayMs = Math.max(1, Math.min(...transitionDelaysMs));
83
+ snapshotTransitionTimer = setTimeout(() => {
84
+ snapshotTransitionTimer = null;
85
+ if (cancelled || version !== snapshotVersion)
86
+ return;
87
+ const elapsedSinceObservationMs = Math.max(0, Date.now() - observedAtMs);
88
+ const nextHeartbeatSinceMs = snapshot.heartbeatSinceMs == null
89
+ ? null
90
+ : snapshot.heartbeatSinceMs + elapsedSinceObservationMs;
91
+ const nextStuckSinceMs = snapshot.stuckSinceMs == null
92
+ ? null
93
+ : snapshot.stuckSinceMs + elapsedSinceObservationMs;
94
+ const nextEffectiveThresholdMs = effectiveThresholdFor(snapshot.dispatchMode, nextHeartbeatSinceMs);
95
+ const nextIsStuck = Boolean(nextStuckSinceMs != null &&
96
+ nextStuckSinceMs > nextEffectiveThresholdMs);
97
+ setState((current) => {
98
+ if (version !== snapshotVersion ||
99
+ current.runId !== snapshot.runId ||
100
+ current.lastProgressAt !== snapshot.lastProgressAt ||
101
+ current.heartbeatAt !== snapshot.heartbeatAt) {
102
+ return current;
103
+ }
104
+ return {
105
+ ...current,
106
+ isStuck: nextIsStuck,
107
+ stuckSinceMs: nextStuckSinceMs,
108
+ heartbeatSinceMs: nextHeartbeatSinceMs,
109
+ };
110
+ });
111
+ scheduleSnapshotTransition(snapshot, observedAtMs, version);
112
+ }, delayMs);
113
+ };
31
114
  const poll = async () => {
32
115
  if (cancelled)
33
116
  return;
@@ -49,30 +132,29 @@ export function useRunStuckDetection({ threadId, enabled = true, stuckThresholdM
49
132
  const heartbeatAt = data.heartbeatAt ?? null;
50
133
  const heartbeatSinceMs = heartbeatAt != null ? nowMs - heartbeatAt : null;
51
134
  const dispatchMode = typeof data.dispatchMode === "string" ? data.dispatchMode : null;
52
- // Server-continued runs get the wider threshold: the server's own
53
- // recovery (150s no-progress backstop + chained continuations) must
54
- // get its chance before the user sees a "stuck" affordance.
55
- const serverContinued = dispatchMode === "foreground-self-chain" ||
56
- dispatchMode?.startsWith("background") === true;
57
135
  // A claimed durable worker with a fresh heartbeat can legitimately
58
- // be waiting on a bounded long-running tool/sub-agent call. Showing
59
- // Retry at the generic 3-minute continuation threshold aborts healthy
60
- // work and starts the same call again. Let the worker's own 12-minute
61
- // watchdog act first; a dead/stale heartbeat still gets the earlier
62
- // background fallback below.
63
- const liveBackgroundWorker = dispatchMode === "background-processing" &&
64
- heartbeatSinceMs != null &&
65
- heartbeatSinceMs >= 0 &&
66
- heartbeatSinceMs < FRESH_BACKGROUND_HEARTBEAT_MS;
67
- const effectiveThresholdMs = liveBackgroundWorker
68
- ? liveBackgroundStuckThresholdMs
69
- : serverContinued
70
- ? backgroundStuckThresholdMs
71
- : stuckThresholdMs;
136
+ // be waiting on a bounded long-running tool/sub-agent call. Still
137
+ // surface informational status at the normal background threshold;
138
+ // RunStuckBanner uses the fresh heartbeat to withhold Retry while
139
+ // keeping an explicit Cancel available. The legacy live-worker
140
+ // threshold may make that notice earlier, but never later.
141
+ const effectiveThresholdMs = effectiveThresholdFor(dispatchMode, heartbeatSinceMs);
72
142
  const isStuck = Boolean(data.active &&
73
143
  data.status === "running" &&
74
144
  stuckSinceMs != null &&
75
145
  stuckSinceMs > effectiveThresholdMs);
146
+ const observedAtMs = Date.now();
147
+ const version = ++snapshotVersion;
148
+ scheduleSnapshotTransition({
149
+ active: data.active,
150
+ runId: data.runId ?? null,
151
+ status: data.status ?? null,
152
+ lastProgressAt,
153
+ stuckSinceMs,
154
+ heartbeatAt,
155
+ heartbeatSinceMs,
156
+ dispatchMode,
157
+ }, observedAtMs, version);
76
158
  setState({
77
159
  isStuck,
78
160
  runId: data.runId ?? null,
@@ -107,8 +189,11 @@ export function useRunStuckDetection({ threadId, enabled = true, stuckThresholdM
107
189
  timer = setTimeout(poll, 2_000);
108
190
  return () => {
109
191
  cancelled = true;
192
+ snapshotVersion += 1;
110
193
  if (timer)
111
194
  clearTimeout(timer);
195
+ if (snapshotTransitionTimer)
196
+ clearTimeout(snapshotTransitionTimer);
112
197
  };
113
198
  }, [
114
199
  threadId,
@@ -1 +1 @@
1
- {"version":3,"file":"use-run-stuck-detection.js","sourceRoot":"","sources":["../../src/client/use-run-stuck-detection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AA2EhD,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAC1C,MAAM,CAAC,MAAM,qCAAqC,GAAG,OAAO,CAAC;AAC7D,MAAM,CAAC,MAAM,0CAA0C,GAAG,EAAE,GAAG,MAAM,CAAC;AACtE,MAAM,wBAAwB,GAAG,KAAK,CAAC;AACvC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AACxC,MAAM,6BAA6B,GAAG,MAAM,CAAC;AAe7C,MAAM,WAAW,GAAkB;IACjC,OAAO,EAAE,KAAK;IACd,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;IACZ,cAAc,EAAE,IAAI;IACpB,YAAY,EAAE,IAAI;IAClB,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,IAAI;IACtB,YAAY,EAAE,IAAI;IAClB,eAAe,EAAE,IAAI;CACtB,CAAC;AAEF,MAAM,UAAU,oBAAoB,CAAC,EACnC,QAAQ,EACR,OAAO,GAAG,IAAI,EACd,gBAAgB,GAAG,0BAA0B,EAC7C,0BAA0B,GAAG,qCAAqC,EAClE,8BAA8B,GAAG,0CAA0C,EAC3E,cAAc,GAAG,wBAAwB,EACzC,MAAM,GACsB;IAC5B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,WAAW,CAAC,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AAO,IAAI,CAAC;YACzB,OAAO,KAAK,CAAC;QACf,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAC;AACJ,CAAC","sourcesContent":["import { useEffect, useState, useCallback } from \"react\";\n\nimport { agentNativePath } from \"./api-path.js\";\n\n/**\n * Per-thread chat run health, derived from the durable `last_progress_at`\n * timestamp on the server. Drives the user-visible \"this chat looks stuck\"\n * affordance — distinct from the silent reconnect logic in\n * `agent-chat-adapter.ts`, which keeps trying in the background. When\n * automatic recovery isn't making progress (for whatever reason), this\n * hook surfaces a Retry / Cancel button to the user instead of leaving\n * them staring at a frozen spinner.\n */\nexport interface RunStuckState {\n /** True when an active run hasn't emitted an event for `stuckThresholdMs`. */\n isStuck: boolean;\n /** ID of the active run, or null when nothing is in flight. */\n runId: string | null;\n /** Server-side run status (\"running\" / \"completed\" / \"errored\" / etc.). */\n status: string | null;\n /** Server timestamp (ms) of the last emitted event, or null if none yet. */\n lastProgressAt: number | null;\n /** Milliseconds since `lastProgressAt`, or null. */\n stuckSinceMs: number | null;\n /** Server timestamp (ms) of the last process-alive heartbeat. */\n heartbeatAt: number | null;\n /** Milliseconds since `heartbeatAt`, computed against the server clock. */\n heartbeatSinceMs: number | null;\n /** How the run was dispatched/continued, e.g. foreground-self-chain or background-processing. */\n dispatchMode: string | null;\n /**\n * Server-authoritative: true when the run holds an open tool call or A2A\n * `agent_call` delegation (`in_flight_since` marker set). Preferred over the\n * client-side proxy for deciding whether Retry (which aborts the run) is\n * safe to offer. Null when the server bundle predates this field.\n */\n hasInFlightWork: boolean | null;\n}\n\nexport interface UseRunStuckDetectionOptions {\n /** The thread to monitor. Pass null/undefined to disable polling. */\n threadId: string | null | undefined;\n /**\n * Set false to skip scheduling the poll loop entirely — used to gate\n * polling to only the active chat tab when multiple tabs are mounted\n * (inactive tabs are kept alive via display:none, not unmounted).\n * Defaults to true.\n */\n enabled?: boolean;\n /**\n * Threshold above which an in-flight FOREGROUND run is considered stuck.\n * The default sits comfortably above the adapter's 75s no-progress\n * reconnect — by then automatic recovery has already had its chance.\n */\n stuckThresholdMs?: number;\n /**\n * Threshold for BACKGROUND-dispatched runs (dispatchMode starts with\n * \"background\"). The server owns recovery for these — its run-manager\n * no-progress backstop (150s) and unclaimed-run sweep act first — so the\n * user-facing \"stuck\" affordance is a late fallback, not a race against\n * them. Selected inside the hook because the dispatch mode is only known\n * from the same poll response that computes the elapsed time.\n */\n backgroundStuckThresholdMs?: number;\n /**\n * Threshold for a claimed durable background worker that is still sending\n * fresh process heartbeats. These workers can legitimately spend up to the\n * 12-minute tool/no-progress window on large Design, Plan, or Assets work.\n * Default 13 minutes, matching the durable chunk handoff boundary.\n */\n liveBackgroundStuckThresholdMs?: number;\n /** Poll interval. Default 5_000ms. */\n pollIntervalMs?: number;\n /** API base path. Default `/_agent-native/agent-chat`. */\n apiUrl?: string;\n}\n\nconst DEFAULT_STUCK_THRESHOLD_MS = 90_000;\nexport const DEFAULT_BACKGROUND_STUCK_THRESHOLD_MS = 180_000;\nexport const DEFAULT_LIVE_BACKGROUND_STUCK_THRESHOLD_MS = 13 * 60_000;\nconst DEFAULT_POLL_INTERVAL_MS = 5_000;\nconst IDLE_BACKOFF_INTERVAL_MS = 15_000;\nconst FRESH_BACKGROUND_HEARTBEAT_MS = 30_000;\n\ninterface ActiveRunResponse {\n active: boolean;\n runId?: string;\n status?: string;\n heartbeatAt: number | null;\n lastProgressAt?: number | null;\n dispatchMode?: string | null;\n /** Server clock at response time, used to compute elapsed server-relative. */\n serverNow?: number;\n /** True when the run holds an open tool/A2A call (in_flight_since marker). */\n hasInFlightWork?: boolean;\n}\n\nconst EMPTY_STATE: RunStuckState = {\n isStuck: false,\n runId: null,\n status: null,\n lastProgressAt: null,\n stuckSinceMs: null,\n heartbeatAt: null,\n heartbeatSinceMs: null,\n dispatchMode: null,\n hasInFlightWork: null,\n};\n\nexport function useRunStuckDetection({\n threadId,\n enabled = true,\n stuckThresholdMs = DEFAULT_STUCK_THRESHOLD_MS,\n backgroundStuckThresholdMs = DEFAULT_BACKGROUND_STUCK_THRESHOLD_MS,\n liveBackgroundStuckThresholdMs = DEFAULT_LIVE_BACKGROUND_STUCK_THRESHOLD_MS,\n pollIntervalMs = DEFAULT_POLL_INTERVAL_MS,\n apiUrl,\n}: UseRunStuckDetectionOptions): RunStuckState {\n const [state, setState] = useState<RunStuckState>(EMPTY_STATE);\n\n useEffect(() => {\n // Reset on every thread change so the previous thread's stuck banner\n // doesn't bleed onto the new one before the first poll completes.\n setState(EMPTY_STATE);\n if (!threadId || !enabled) return;\n\n const base = apiUrl ?? agentNativePath(\"/_agent-native/agent-chat\");\n let cancelled = false;\n let timer: ReturnType<typeof setTimeout> | null = null;\n\n const poll = async () => {\n if (cancelled) return;\n let nextDelay = pollIntervalMs;\n try {\n const res = await fetch(\n `${base}/runs/active?threadId=${encodeURIComponent(threadId)}`,\n { credentials: \"same-origin\" },\n );\n if (cancelled) return;\n if (res.ok) {\n const data = (await res.json()) as ActiveRunResponse;\n const lastProgressAt = data.lastProgressAt ?? null;\n // Measure elapsed against the SERVER clock (serverNow) rather than the\n // client's Date.now(). lastProgressAt is a server timestamp, so client\n // clock skew of more than stuckThresholdMs would otherwise mark every\n // run stuck (clock ahead) or never stuck (clock behind). Fall back to\n // the client clock for older bundles that don't send serverNow.\n const nowMs = data.serverNow ?? Date.now();\n const stuckSinceMs =\n lastProgressAt != null ? nowMs - lastProgressAt : null;\n const heartbeatAt = data.heartbeatAt ?? null;\n const heartbeatSinceMs =\n heartbeatAt != null ? nowMs - heartbeatAt : null;\n const dispatchMode =\n typeof data.dispatchMode === \"string\" ? data.dispatchMode : null;\n // Server-continued runs get the wider threshold: the server's own\n // recovery (150s no-progress backstop + chained continuations) must\n // get its chance before the user sees a \"stuck\" affordance.\n const serverContinued =\n dispatchMode === \"foreground-self-chain\" ||\n dispatchMode?.startsWith(\"background\") === true;\n // A claimed durable worker with a fresh heartbeat can legitimately\n // be waiting on a bounded long-running tool/sub-agent call. Showing\n // Retry at the generic 3-minute continuation threshold aborts healthy\n // work and starts the same call again. Let the worker's own 12-minute\n // watchdog act first; a dead/stale heartbeat still gets the earlier\n // background fallback below.\n const liveBackgroundWorker =\n dispatchMode === \"background-processing\" &&\n heartbeatSinceMs != null &&\n heartbeatSinceMs >= 0 &&\n heartbeatSinceMs < FRESH_BACKGROUND_HEARTBEAT_MS;\n const effectiveThresholdMs = liveBackgroundWorker\n ? liveBackgroundStuckThresholdMs\n : serverContinued\n ? backgroundStuckThresholdMs\n : stuckThresholdMs;\n const isStuck = Boolean(\n data.active &&\n data.status === \"running\" &&\n stuckSinceMs != null &&\n stuckSinceMs > effectiveThresholdMs,\n );\n setState({\n isStuck,\n runId: data.runId ?? null,\n status: data.status ?? null,\n lastProgressAt,\n stuckSinceMs,\n heartbeatAt,\n heartbeatSinceMs,\n dispatchMode,\n hasInFlightWork:\n typeof data.hasInFlightWork === \"boolean\"\n ? data.hasInFlightWork\n : null,\n });\n // Back off polling when nothing is in flight — there's no point\n // hammering the endpoint while the chat is idle. We still poll\n // occasionally so a fresh run started in another tab is picked up.\n if (!data.active || data.status !== \"running\") {\n nextDelay = IDLE_BACKOFF_INTERVAL_MS;\n }\n }\n } catch {\n // Network blip — leave previous state. Next tick will retry.\n }\n if (!cancelled) {\n timer = setTimeout(poll, nextDelay);\n }\n };\n\n // Stagger the first poll so a freshly-started run isn't immediately\n // classified as stuck before the server has had a chance to record\n // any progress events.\n timer = setTimeout(poll, 2_000);\n\n return () => {\n cancelled = true;\n if (timer) clearTimeout(timer);\n };\n }, [\n threadId,\n enabled,\n stuckThresholdMs,\n backgroundStuckThresholdMs,\n liveBackgroundStuckThresholdMs,\n pollIntervalMs,\n apiUrl,\n ]);\n\n return state;\n}\n\n/**\n * POST `/runs/:id/abort` so the server flips the run to \"aborted\" and the\n * adapter's reconnect loop exits cleanly. Returns the run id that was\n * aborted (or null on failure) so callers can correlate observability\n * events. Best-effort — failures are swallowed, since the user's intent\n * is already captured locally.\n */\nexport function useAbortRun(apiUrl?: string) {\n return useCallback(\n async (runId: string, reason: string = \"user\"): Promise<string | null> => {\n const base = apiUrl ?? agentNativePath(\"/_agent-native/agent-chat\");\n try {\n const res = await fetch(\n `${base}/runs/${encodeURIComponent(runId)}/abort`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n credentials: \"same-origin\",\n body: JSON.stringify({ reason }),\n },\n );\n if (!res.ok) return null;\n return runId;\n } catch {\n return null;\n }\n },\n [apiUrl],\n );\n}\n"]}
1
+ {"version":3,"file":"use-run-stuck-detection.js","sourceRoot":"","sources":["../../src/client/use-run-stuck-detection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AA2EhD,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAC1C,MAAM,CAAC,MAAM,qCAAqC,GAAG,OAAO,CAAC;AAC7D,MAAM,CAAC,MAAM,0CAA0C,GAAG,EAAE,GAAG,MAAM,CAAC;AACtE,MAAM,wBAAwB,GAAG,KAAK,CAAC;AACvC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AACxC,MAAM,6BAA6B,GAAG,MAAM,CAAC;AAe7C,MAAM,WAAW,GAAkB;IACjC,OAAO,EAAE,KAAK;IACd,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;IACZ,cAAc,EAAE,IAAI;IACpB,YAAY,EAAE,IAAI;IAClB,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,IAAI;IACtB,YAAY,EAAE,IAAI;IAClB,eAAe,EAAE,IAAI;CACtB,CAAC;AAEF,MAAM,UAAU,oBAAoB,CAAC,EACnC,QAAQ,EACR,OAAO,GAAG,IAAI,EACd,gBAAgB,GAAG,0BAA0B,EAC7C,0BAA0B,GAAG,qCAA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gBAAE,OAAO,IAAI,CAAC;YACzB,OAAO,KAAK,CAAC;QACf,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAC;AACJ,CAAC","sourcesContent":["import { useEffect, useState, useCallback } from \"react\";\n\nimport { agentNativePath } from \"./api-path.js\";\n\n/**\n * Per-thread chat run health, derived from the durable `last_progress_at`\n * timestamp on the server. Drives the user-visible \"this chat looks stuck\"\n * affordance — distinct from the silent reconnect logic in\n * `agent-chat-adapter.ts`, which keeps trying in the background. When\n * automatic recovery isn't making progress (for whatever reason), this\n * hook surfaces a Retry / Cancel button to the user instead of leaving\n * them staring at a frozen spinner.\n */\nexport interface RunStuckState {\n /** True when an active run hasn't emitted an event for `stuckThresholdMs`. */\n isStuck: boolean;\n /** ID of the active run, or null when nothing is in flight. */\n runId: string | null;\n /** Server-side run status (\"running\" / \"completed\" / \"errored\" / etc.). */\n status: string | null;\n /** Server timestamp (ms) of the last emitted event, or null if none yet. */\n lastProgressAt: number | null;\n /** Milliseconds since `lastProgressAt`, or null. */\n stuckSinceMs: number | null;\n /** Server timestamp (ms) of the last process-alive heartbeat. */\n heartbeatAt: number | null;\n /** Milliseconds since `heartbeatAt`, computed against the server clock. */\n heartbeatSinceMs: number | null;\n /** How the run was dispatched/continued, e.g. foreground-self-chain or background-processing. */\n dispatchMode: string | null;\n /**\n * Server-authoritative: true when the run holds an open tool call or A2A\n * `agent_call` delegation (`in_flight_since` marker set). Preferred over the\n * client-side proxy for deciding whether Retry (which aborts the run) is\n * safe to offer. Null when the server bundle predates this field.\n */\n hasInFlightWork: boolean | null;\n}\n\nexport interface UseRunStuckDetectionOptions {\n /** The thread to monitor. Pass null/undefined to disable polling. */\n threadId: string | null | undefined;\n /**\n * Set false to skip scheduling the poll loop entirely — used to gate\n * polling to only the active chat tab when multiple tabs are mounted\n * (inactive tabs are kept alive via display:none, not unmounted).\n * Defaults to true.\n */\n enabled?: boolean;\n /**\n * Threshold above which an in-flight FOREGROUND run is considered stuck.\n * The default sits comfortably above the adapter's 75s no-progress\n * reconnect — by then automatic recovery has already had its chance.\n */\n stuckThresholdMs?: number;\n /**\n * Threshold for BACKGROUND-dispatched runs (dispatchMode starts with\n * \"background\"). The server owns recovery for these — its run-manager\n * no-progress backstop (150s) and unclaimed-run sweep act first — so the\n * user-facing \"stuck\" affordance is a late fallback, not a race against\n * them. Selected inside the hook because the dispatch mode is only known\n * from the same poll response that computes the elapsed time.\n */\n backgroundStuckThresholdMs?: number;\n /**\n * Legacy upper bound for a claimed durable background worker that is still\n * sending fresh process heartbeats. Informational quiet-run UI is never\n * delayed past `backgroundStuckThresholdMs`; this option can only request an\n * earlier notice for live workers. Default 13 minutes.\n */\n liveBackgroundStuckThresholdMs?: number;\n /** Poll interval. Default 5_000ms. */\n pollIntervalMs?: number;\n /** API base path. Default `/_agent-native/agent-chat`. */\n apiUrl?: string;\n}\n\nconst DEFAULT_STUCK_THRESHOLD_MS = 90_000;\nexport const DEFAULT_BACKGROUND_STUCK_THRESHOLD_MS = 180_000;\nexport const DEFAULT_LIVE_BACKGROUND_STUCK_THRESHOLD_MS = 13 * 60_000;\nconst DEFAULT_POLL_INTERVAL_MS = 5_000;\nconst IDLE_BACKOFF_INTERVAL_MS = 15_000;\nconst FRESH_BACKGROUND_HEARTBEAT_MS = 30_000;\n\ninterface ActiveRunResponse {\n active: boolean;\n runId?: string;\n status?: string;\n heartbeatAt: number | null;\n lastProgressAt?: number | null;\n dispatchMode?: string | null;\n /** Server clock at response time, used to compute elapsed server-relative. */\n serverNow?: number;\n /** True when the run holds an open tool/A2A call (in_flight_since marker). */\n hasInFlightWork?: boolean;\n}\n\nconst EMPTY_STATE: RunStuckState = {\n isStuck: false,\n runId: null,\n status: null,\n lastProgressAt: null,\n stuckSinceMs: null,\n heartbeatAt: null,\n heartbeatSinceMs: null,\n dispatchMode: null,\n hasInFlightWork: null,\n};\n\nexport function useRunStuckDetection({\n threadId,\n enabled = true,\n stuckThresholdMs = DEFAULT_STUCK_THRESHOLD_MS,\n backgroundStuckThresholdMs = DEFAULT_BACKGROUND_STUCK_THRESHOLD_MS,\n liveBackgroundStuckThresholdMs = DEFAULT_LIVE_BACKGROUND_STUCK_THRESHOLD_MS,\n pollIntervalMs = DEFAULT_POLL_INTERVAL_MS,\n apiUrl,\n}: UseRunStuckDetectionOptions): RunStuckState {\n const [state, setState] = useState<RunStuckState>(EMPTY_STATE);\n\n useEffect(() => {\n // Reset on every thread change so the previous thread's stuck banner\n // doesn't bleed onto the new one before the first poll completes.\n setState(EMPTY_STATE);\n if (!threadId || !enabled) return;\n\n const base = apiUrl ?? agentNativePath(\"/_agent-native/agent-chat\");\n let cancelled = false;\n let timer: ReturnType<typeof setTimeout> | null = null;\n let snapshotTransitionTimer: ReturnType<typeof setTimeout> | null = null;\n let snapshotVersion = 0;\n\n type RunHealthSnapshot = {\n active: boolean;\n runId: string | null;\n status: string | null;\n lastProgressAt: number | null;\n stuckSinceMs: number | null;\n heartbeatAt: number | null;\n heartbeatSinceMs: number | null;\n dispatchMode: string | null;\n };\n\n const effectiveThresholdFor = (\n dispatchMode: string | null,\n heartbeatSinceMs: number | null,\n ) => {\n const liveBackgroundWorker =\n dispatchMode === \"background-processing\" &&\n heartbeatSinceMs != null &&\n heartbeatSinceMs >= 0 &&\n heartbeatSinceMs < FRESH_BACKGROUND_HEARTBEAT_MS;\n const serverContinued =\n dispatchMode === \"foreground-self-chain\" ||\n dispatchMode?.startsWith(\"background\") === true;\n return liveBackgroundWorker\n ? Math.min(backgroundStuckThresholdMs, liveBackgroundStuckThresholdMs)\n : serverContinued\n ? backgroundStuckThresholdMs\n : stuckThresholdMs;\n };\n\n const scheduleSnapshotTransition = (\n snapshot: RunHealthSnapshot,\n observedAtMs: number,\n version: number,\n ) => {\n if (snapshotTransitionTimer) clearTimeout(snapshotTransitionTimer);\n snapshotTransitionTimer = null;\n if (\n cancelled ||\n version !== snapshotVersion ||\n !snapshot.active ||\n snapshot.status !== \"running\" ||\n snapshot.runId == null\n ) {\n return;\n }\n\n const currentElapsedMs = Math.max(0, Date.now() - observedAtMs);\n const currentHeartbeatSinceMs =\n snapshot.heartbeatSinceMs == null\n ? null\n : snapshot.heartbeatSinceMs + currentElapsedMs;\n const currentStuckSinceMs =\n snapshot.stuckSinceMs == null\n ? null\n : snapshot.stuckSinceMs + currentElapsedMs;\n const effectiveThresholdMs = effectiveThresholdFor(\n snapshot.dispatchMode,\n currentHeartbeatSinceMs,\n );\n const currentlyStuck = Boolean(\n currentStuckSinceMs != null &&\n currentStuckSinceMs > effectiveThresholdMs,\n );\n const transitionDelaysMs: number[] = [];\n if (\n currentHeartbeatSinceMs != null &&\n currentHeartbeatSinceMs >= 0 &&\n currentHeartbeatSinceMs < FRESH_BACKGROUND_HEARTBEAT_MS\n ) {\n transitionDelaysMs.push(\n FRESH_BACKGROUND_HEARTBEAT_MS - currentHeartbeatSinceMs + 1,\n );\n }\n if (currentStuckSinceMs != null && !currentlyStuck) {\n transitionDelaysMs.push(\n Math.max(1, effectiveThresholdMs - currentStuckSinceMs + 1),\n );\n }\n if (transitionDelaysMs.length === 0) return;\n\n // Both ages originate from the server clock. Advance those snapshots by\n // only a local elapsed duration, which remains safe when client/server\n // wall clocks differ. Wake at the earlier semantic boundary, then\n // reschedule if the other boundary is still ahead.\n const delayMs = Math.max(1, Math.min(...transitionDelaysMs));\n snapshotTransitionTimer = setTimeout(() => {\n snapshotTransitionTimer = null;\n if (cancelled || version !== snapshotVersion) return;\n const elapsedSinceObservationMs = Math.max(\n 0,\n Date.now() - observedAtMs,\n );\n const nextHeartbeatSinceMs =\n snapshot.heartbeatSinceMs == null\n ? null\n : snapshot.heartbeatSinceMs + elapsedSinceObservationMs;\n const nextStuckSinceMs =\n snapshot.stuckSinceMs == null\n ? null\n : snapshot.stuckSinceMs + elapsedSinceObservationMs;\n const nextEffectiveThresholdMs = effectiveThresholdFor(\n snapshot.dispatchMode,\n nextHeartbeatSinceMs,\n );\n const nextIsStuck = Boolean(\n nextStuckSinceMs != null &&\n nextStuckSinceMs > nextEffectiveThresholdMs,\n );\n setState((current) => {\n if (\n version !== snapshotVersion ||\n current.runId !== snapshot.runId ||\n current.lastProgressAt !== snapshot.lastProgressAt ||\n current.heartbeatAt !== snapshot.heartbeatAt\n ) {\n return current;\n }\n return {\n ...current,\n isStuck: nextIsStuck,\n stuckSinceMs: nextStuckSinceMs,\n heartbeatSinceMs: nextHeartbeatSinceMs,\n };\n });\n scheduleSnapshotTransition(snapshot, observedAtMs, version);\n }, delayMs);\n };\n\n const poll = async () => {\n if (cancelled) return;\n let nextDelay = pollIntervalMs;\n try {\n const res = await fetch(\n `${base}/runs/active?threadId=${encodeURIComponent(threadId)}`,\n { credentials: \"same-origin\" },\n );\n if (cancelled) return;\n if (res.ok) {\n const data = (await res.json()) as ActiveRunResponse;\n const lastProgressAt = data.lastProgressAt ?? null;\n // Measure elapsed against the SERVER clock (serverNow) rather than the\n // client's Date.now(). lastProgressAt is a server timestamp, so client\n // clock skew of more than stuckThresholdMs would otherwise mark every\n // run stuck (clock ahead) or never stuck (clock behind). Fall back to\n // the client clock for older bundles that don't send serverNow.\n const nowMs = data.serverNow ?? Date.now();\n const stuckSinceMs =\n lastProgressAt != null ? nowMs - lastProgressAt : null;\n const heartbeatAt = data.heartbeatAt ?? null;\n const heartbeatSinceMs =\n heartbeatAt != null ? nowMs - heartbeatAt : null;\n const dispatchMode =\n typeof data.dispatchMode === \"string\" ? data.dispatchMode : null;\n // A claimed durable worker with a fresh heartbeat can legitimately\n // be waiting on a bounded long-running tool/sub-agent call. Still\n // surface informational status at the normal background threshold;\n // RunStuckBanner uses the fresh heartbeat to withhold Retry while\n // keeping an explicit Cancel available. The legacy live-worker\n // threshold may make that notice earlier, but never later.\n const effectiveThresholdMs = effectiveThresholdFor(\n dispatchMode,\n heartbeatSinceMs,\n );\n const isStuck = Boolean(\n data.active &&\n data.status === \"running\" &&\n stuckSinceMs != null &&\n stuckSinceMs > effectiveThresholdMs,\n );\n const observedAtMs = Date.now();\n const version = ++snapshotVersion;\n scheduleSnapshotTransition(\n {\n active: data.active,\n runId: data.runId ?? null,\n status: data.status ?? null,\n lastProgressAt,\n stuckSinceMs,\n heartbeatAt,\n heartbeatSinceMs,\n dispatchMode,\n },\n observedAtMs,\n version,\n );\n setState({\n isStuck,\n runId: data.runId ?? null,\n status: data.status ?? null,\n lastProgressAt,\n stuckSinceMs,\n heartbeatAt,\n heartbeatSinceMs,\n dispatchMode,\n hasInFlightWork:\n typeof data.hasInFlightWork === \"boolean\"\n ? data.hasInFlightWork\n : null,\n });\n // Back off polling when nothing is in flight — there's no point\n // hammering the endpoint while the chat is idle. We still poll\n // occasionally so a fresh run started in another tab is picked up.\n if (!data.active || data.status !== \"running\") {\n nextDelay = IDLE_BACKOFF_INTERVAL_MS;\n }\n }\n } catch {\n // Network blip — leave previous state. Next tick will retry.\n }\n if (!cancelled) {\n timer = setTimeout(poll, nextDelay);\n }\n };\n\n // Stagger the first poll so a freshly-started run isn't immediately\n // classified as stuck before the server has had a chance to record\n // any progress events.\n timer = setTimeout(poll, 2_000);\n\n return () => {\n cancelled = true;\n snapshotVersion += 1;\n if (timer) clearTimeout(timer);\n if (snapshotTransitionTimer) clearTimeout(snapshotTransitionTimer);\n };\n }, [\n threadId,\n enabled,\n stuckThresholdMs,\n backgroundStuckThresholdMs,\n liveBackgroundStuckThresholdMs,\n pollIntervalMs,\n apiUrl,\n ]);\n\n return state;\n}\n\n/**\n * POST `/runs/:id/abort` so the server flips the run to \"aborted\" and the\n * adapter's reconnect loop exits cleanly. Returns the run id that was\n * aborted (or null on failure) so callers can correlate observability\n * events. Best-effort — failures are swallowed, since the user's intent\n * is already captured locally.\n */\nexport function useAbortRun(apiUrl?: string) {\n return useCallback(\n async (runId: string, reason: string = \"user\"): Promise<string | null> => {\n const base = apiUrl ?? agentNativePath(\"/_agent-native/agent-chat\");\n try {\n const res = await fetch(\n `${base}/runs/${encodeURIComponent(runId)}/abort`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n credentials: \"same-origin\",\n body: JSON.stringify({ reason }),\n },\n );\n if (!res.ok) return null;\n return runId;\n } catch {\n return null;\n }\n },\n [apiUrl],\n );\n}\n"]}
@@ -62,11 +62,11 @@ export declare const postAwareness: import("h3").EventHandlerWithFetch<import("h
62
62
  error: string;
63
63
  states?: undefined;
64
64
  } | {
65
- error?: undefined;
66
65
  states: {
67
66
  clientId: number;
68
67
  state: string;
69
68
  }[];
69
+ error?: undefined;
70
70
  }>>;
71
71
  /**
72
72
  * GET /_agent-native/collab/:docId/users
@@ -77,10 +77,10 @@ export declare const getActiveUsers: import("h3").EventHandlerWithFetch<import("
77
77
  error: string;
78
78
  users?: undefined;
79
79
  } | {
80
- error?: undefined;
81
80
  users: {
82
81
  clientId: number;
83
82
  lastSeen: number;
84
83
  }[];
84
+ error?: undefined;
85
85
  }>>;
86
86
  //# sourceMappingURL=awareness.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"awareness.d.ts","sourceRoot":"","sources":["../../src/collab/awareness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAgB3C,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAOD,eAAO,MAAM,sBAAsB,EAAG,kBAA2B,CAAC;AAElE,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,kBAAkB,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,MAAM,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,gFAAgF;IAChF,KAAK,CAAC,EAAE,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AAE,CAAC,EAClD,KAAK,CAAC,EAAE,cAAc,GACrB,IAAI,CAgBN;AAoBD,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,MAAmB,GAC7B,IAAI,CAON;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAE1E;AAiBD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAO1E;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,IAAI,CAOnE;AAkCD;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa;;;;;kBAwDa,MAAM;eAAS,MAAM;;;GAoB1D,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,cAAc;;;;;kBAYM,MAAM;kBAAY,MAAM;;;GAMvD,CAAC"}
@@ -14,16 +14,21 @@ export declare function resolveCredentialForScope(key: string, ctx: CredentialCo
14
14
  scope: CredentialStorageScope;
15
15
  }): Promise<string | undefined>;
16
16
  /**
17
- * Resolve a credential, scoped to the caller's user (and falling back to
18
- * the active org's shared credential, if any).
17
+ * Resolve a credential across the encrypted app_secrets store and the legacy
18
+ * settings-backed credential store. User overrides win, followed by the
19
+ * active org/workspace shared value.
19
20
  *
20
21
  * SECURITY: NEVER reads from process.env. Env vars are global to the
21
- * deployment and would leak across users in a multi-tenant app. The only
22
- * sources are per-user / per-org rows in the SQL `settings` table.
22
+ * deployment and would leak across users in a multi-tenant app.
23
23
  *
24
- * Storage keys (priority order):
25
- * 1. u:<email>:credential:<KEY> — per-user override
26
- * 2. o:<orgId>:credential:<KEY> — per-org shared credential (if orgId given)
24
+ * Read order:
25
+ * 1. user-scoped app_secrets
26
+ * 2. user-scoped legacy settings credential
27
+ * 3. org-scoped app_secrets
28
+ * 4. legacy workspace-scoped app_secrets for the org
29
+ * 5. org-scoped legacy settings credential
30
+ *
31
+ * Without an active org, step 3 is replaced by the solo workspace scope.
27
32
  */
28
33
  export declare function resolveCredential(key: string, ctx: CredentialContext): Promise<string | undefined>;
29
34
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/credentials/index.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,KAAK,CAAC;AA6BpD;;;;;;GAMG;AACH,wBAAsB,yBAAyB,CAC7C,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,iBAAiB,GAAG;IAAE,KAAK,EAAE,sBAAsB,CAAA;CAAE,GACzD,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAO7B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,iBAAiB,GACrB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAc7B;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,iBAAiB,GACrB,OAAO,CAAC,OAAO,CAAC,CAElB;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,iBAAiB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;CAAE,GAClD,OAAO,CAAC,IAAI,CAAC,CAoBf;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,iBAAiB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;CAAE,GAClD,OAAO,CAAC,IAAI,CAAC,CAcf"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/credentials/index.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,KAAK,CAAC;AA2CpD;;;;;;GAMG;AACH,wBAAsB,yBAAyB,CAC7C,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,iBAAiB,GAAG;IAAE,KAAK,EAAE,sBAAsB,CAAA;CAAE,GACzD,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAO7B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,iBAAiB,GACrB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA2B7B;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,iBAAiB,GACrB,OAAO,CAAC,OAAO,CAAC,CAElB;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,iBAAiB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;CAAE,GAClD,OAAO,CAAC,IAAI,CAAC,CAoBf;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,iBAAiB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;CAAE,GAClD,OAAO,CAAC,IAAI,CAAC,CAcf"}
@@ -1,4 +1,5 @@
1
1
  import { encryptSecretValue, decryptSecretValue, isEncryptedSecretValue, } from "../secrets/crypto.js";
2
+ import { readAppSecret } from "../secrets/storage.js";
2
3
  import { getSetting, putSetting, deleteSetting } from "../settings/store.js";
3
4
  const SETTING_PREFIX = "credential:";
4
5
  function userCredentialSettingKey(email, key) {
@@ -26,6 +27,16 @@ async function readCredentialSetting(settingKey) {
26
27
  return undefined;
27
28
  }
28
29
  }
30
+ async function readScopedAppSecret(key, scope, scopeId) {
31
+ try {
32
+ return (await readAppSecret({ key, scope, scopeId }))?.value;
33
+ }
34
+ catch {
35
+ // Older databases may not have app_secrets yet. Keep the legacy
36
+ // credential store available while the table bootstraps.
37
+ return undefined;
38
+ }
39
+ }
29
40
  /**
30
41
  * Resolve a credential from one explicit legacy SQL credential scope.
31
42
  *
@@ -44,20 +55,28 @@ export async function resolveCredentialForScope(key, ctx) {
44
55
  return readCredentialSetting(userCredentialSettingKey(ctx.userEmail, key));
45
56
  }
46
57
  /**
47
- * Resolve a credential, scoped to the caller's user (and falling back to
48
- * the active org's shared credential, if any).
58
+ * Resolve a credential across the encrypted app_secrets store and the legacy
59
+ * settings-backed credential store. User overrides win, followed by the
60
+ * active org/workspace shared value.
49
61
  *
50
62
  * SECURITY: NEVER reads from process.env. Env vars are global to the
51
- * deployment and would leak across users in a multi-tenant app. The only
52
- * sources are per-user / per-org rows in the SQL `settings` table.
63
+ * deployment and would leak across users in a multi-tenant app.
64
+ *
65
+ * Read order:
66
+ * 1. user-scoped app_secrets
67
+ * 2. user-scoped legacy settings credential
68
+ * 3. org-scoped app_secrets
69
+ * 4. legacy workspace-scoped app_secrets for the org
70
+ * 5. org-scoped legacy settings credential
53
71
  *
54
- * Storage keys (priority order):
55
- * 1. u:<email>:credential:<KEY> — per-user override
56
- * 2. o:<orgId>:credential:<KEY> — per-org shared credential (if orgId given)
72
+ * Without an active org, step 3 is replaced by the solo workspace scope.
57
73
  */
58
74
  export async function resolveCredential(key, ctx) {
59
75
  if (!ctx?.userEmail)
60
76
  return undefined;
77
+ const userSecret = await readScopedAppSecret(key, "user", ctx.userEmail);
78
+ if (userSecret)
79
+ return userSecret;
61
80
  const userSetting = await resolveCredentialForScope(key, {
62
81
  ...ctx,
63
82
  scope: "user",
@@ -65,9 +84,15 @@ export async function resolveCredential(key, ctx) {
65
84
  if (userSetting)
66
85
  return userSetting;
67
86
  if (ctx.orgId) {
87
+ const orgSecret = await readScopedAppSecret(key, "org", ctx.orgId);
88
+ if (orgSecret)
89
+ return orgSecret;
90
+ const workspaceSecret = await readScopedAppSecret(key, "workspace", ctx.orgId);
91
+ if (workspaceSecret)
92
+ return workspaceSecret;
68
93
  return resolveCredentialForScope(key, { ...ctx, scope: "org" });
69
94
  }
70
- return undefined;
95
+ return readScopedAppSecret(key, "workspace", `solo:${ctx.userEmail}`);
71
96
  }
72
97
  /**
73
98
  * Check if a credential is available for the given context.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/credentials/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE7E,MAAM,cAAc,GAAG,aAAa,CAAC;AASrC,SAAS,wBAAwB,CAAC,KAAa,EAAE,GAAW;IAC1D,OAAO,KAAK,KAAK,CAAC,WAAW,EAAE,IAAI,cAAc,GAAG,GAAG,EAAE,CAAC;AAC5D,CAAC;AAED,SAAS,uBAAuB,CAAC,KAAa,EAAE,GAAW;IACzD,OAAO,KAAK,KAAK,IAAI,cAAc,GAAG,GAAG,EAAE,CAAC;AAC9C,CAAC;AAED,KAAK,UAAU,qBAAqB,CAClC,UAAkB;IAElB,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,CAAC;IAC7C,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IACpE,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,sEAAsE;IACtE,uEAAuE;IACvE,sEAAsE;IACtE,IAAI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,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;QAC7D,OAAO;IACT,CAAC;IACD,MAAM,aAAa,CAAC,wBAAwB,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import {\n encryptSecretValue,\n decryptSecretValue,\n isEncryptedSecretValue,\n} from \"../secrets/crypto.js\";\nimport { getSetting, putSetting, deleteSetting } from \"../settings/store.js\";\n\nconst SETTING_PREFIX = \"credential:\";\n\nexport interface CredentialContext {\n userEmail: string;\n orgId?: string | null;\n}\n\nexport type CredentialStorageScope = \"user\" | \"org\";\n\nfunction userCredentialSettingKey(email: string, key: string): string {\n return `u:${email.toLowerCase()}:${SETTING_PREFIX}${key}`;\n}\n\nfunction orgCredentialSettingKey(orgId: string, key: string): string {\n return `o:${orgId}:${SETTING_PREFIX}${key}`;\n}\n\nasync function readCredentialSetting(\n settingKey: string,\n): Promise<string | undefined> {\n const setting = await getSetting(settingKey);\n if (!setting || typeof setting.value !== \"string\") return undefined;\n const stored = setting.value;\n // Values written by saveCredential are AES-256-GCM encrypted at rest.\n // Rows that predate encryption are plaintext — read them transparently\n // (the migrate-encrypt-credentials script re-encrypts them in place).\n if (!isEncryptedSecretValue(stored)) return stored;\n try {\n return decryptSecretValue(stored);\n } catch {\n // Key rotated, corrupt, or tampered row — treat as not set rather than\n // surfacing ciphertext or throwing into every credential lookup.\n return undefined;\n }\n}\n\n/**\n * Resolve a credential from one explicit legacy SQL credential scope.\n *\n * Prefer `resolveCredential()` for normal app-local credential lookup. This\n * helper exists for workspace connection refs, where a ref can explicitly say\n * \"use the org-scoped key\" and must not accidentally read a user override.\n */\nexport async function resolveCredentialForScope(\n key: string,\n ctx: CredentialContext & { scope: CredentialStorageScope },\n): Promise<string | undefined> {\n if (!ctx?.userEmail) return undefined;\n if (ctx.scope === \"org\") {\n if (!ctx.orgId) return undefined;\n return readCredentialSetting(orgCredentialSettingKey(ctx.orgId, key));\n }\n return readCredentialSetting(userCredentialSettingKey(ctx.userEmail, key));\n}\n\n/**\n * Resolve a credential, scoped to the caller's user (and falling back to\n * the active org's shared credential, if any).\n *\n * SECURITY: NEVER reads from process.env. Env vars are global to the\n * deployment and would leak across users in a multi-tenant app. The only\n * sources are per-user / per-org rows in the SQL `settings` table.\n *\n * Storage keys (priority order):\n * 1. u:<email>:credential:<KEY> — per-user override\n * 2. o:<orgId>:credential:<KEY> — per-org shared credential (if orgId given)\n */\nexport async function resolveCredential(\n key: string,\n ctx: CredentialContext,\n): Promise<string | undefined> {\n if (!ctx?.userEmail) return undefined;\n\n const userSetting = await resolveCredentialForScope(key, {\n ...ctx,\n scope: \"user\",\n });\n if (userSetting) return userSetting;\n\n if (ctx.orgId) {\n return resolveCredentialForScope(key, { ...ctx, scope: \"org\" });\n }\n\n return undefined;\n}\n\n/**\n * Check if a credential is available for the given context.\n */\nexport async function hasCredential(\n key: string,\n ctx: CredentialContext,\n): Promise<boolean> {\n return (await resolveCredential(key, ctx)) !== undefined;\n}\n\n/**\n * Save a credential. By default writes to the per-user store; pass\n * `scope: \"org\"` to write to the active org's shared credentials.\n */\nexport async function saveCredential(\n key: string,\n value: string,\n ctx: CredentialContext & { scope?: \"user\" | \"org\" },\n): Promise<void> {\n if (!ctx?.userEmail) {\n throw new Error(\"saveCredential requires CredentialContext with userEmail\");\n }\n // Encrypt at rest (AES-256-GCM) so a leaked DB backup / pg_dump / read\n // replica doesn't expose plaintext keys. resolveCredential decrypts\n // transparently on read.\n const encrypted = encryptSecretValue(value);\n if (ctx.scope === \"org\") {\n if (!ctx.orgId) {\n throw new Error(\"saveCredential scope='org' requires orgId\");\n }\n await putSetting(orgCredentialSettingKey(ctx.orgId, key), {\n value: encrypted,\n });\n return;\n }\n await putSetting(userCredentialSettingKey(ctx.userEmail, key), {\n value: encrypted,\n });\n}\n\n/**\n * Delete a credential from the per-user (default) or per-org store.\n */\nexport async function deleteCredential(\n key: string,\n ctx: CredentialContext & { scope?: \"user\" | \"org\" },\n): Promise<void> {\n if (!ctx?.userEmail) {\n throw new Error(\n \"deleteCredential requires CredentialContext with userEmail\",\n );\n }\n if (ctx.scope === \"org\") {\n if (!ctx.orgId) {\n throw new Error(\"deleteCredential scope='org' requires orgId\");\n }\n await deleteSetting(orgCredentialSettingKey(ctx.orgId, key));\n return;\n }\n await deleteSetting(userCredentialSettingKey(ctx.userEmail, key));\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/credentials/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAkB,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE7E,MAAM,cAAc,GAAG,aAAa,CAAC;AASrC,SAAS,wBAAwB,CAAC,KAAa,EAAE,GAAW;IAC1D,OAAO,KAAK,KAAK,CAAC,WAAW,EAAE,IAAI,cAAc,GAAG,GAAG,EAAE,CAAC;AAC5D,CAAC;AAED,SAAS,uBAAuB,CAAC,KAAa,EAAE,GAAW;IACzD,OAAO,KAAK,KAAK,IAAI,cAAc,GAAG,GAAG,EAAE,CAAC;AAC9C,CAAC;AAED,KAAK,UAAU,qBAAqB,CAClC,UAAkB;IAElB,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,CAAC;IAC7C,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IACpE,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,sEAAsE;IACtE,uEAAuE;IACvE,sEAAsE;IACtE,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IACnD,IAAI,CAAC;QACH,OAAO,kBAAkB,CAAC,MAAM,CAA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CAAC;QAC/D,CAAC;QACD,MAAM,UAAU,CAAC,uBAAuB,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE;YACxD,KAAK,EAAE,SAAS;SACjB,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IACD,MAAM,UAAU,CAAC,wBAAwB,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE;QAC7D,KAAK,EAAE,SAAS;KACjB,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,GAAW,EACX,GAAmD;IAEnD,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;IACJ,CAAC;IACD,IAAI,GAAG,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QACD,MAAM,aAAa,CAAC,uBAAuB,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;QAC7D,OAAO;IACT,CAAC;IACD,MAAM,aAAa,CAAC,wBAAwB,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import {\n encryptSecretValue,\n decryptSecretValue,\n isEncryptedSecretValue,\n} from \"../secrets/crypto.js\";\nimport { readAppSecret, type SecretRef } from \"../secrets/storage.js\";\nimport { getSetting, putSetting, deleteSetting } from \"../settings/store.js\";\n\nconst SETTING_PREFIX = \"credential:\";\n\nexport interface CredentialContext {\n userEmail: string;\n orgId?: string | null;\n}\n\nexport type CredentialStorageScope = \"user\" | \"org\";\n\nfunction userCredentialSettingKey(email: string, key: string): string {\n return `u:${email.toLowerCase()}:${SETTING_PREFIX}${key}`;\n}\n\nfunction orgCredentialSettingKey(orgId: string, key: string): string {\n return `o:${orgId}:${SETTING_PREFIX}${key}`;\n}\n\nasync function readCredentialSetting(\n settingKey: string,\n): Promise<string | undefined> {\n const setting = await getSetting(settingKey);\n if (!setting || typeof setting.value !== \"string\") return undefined;\n const stored = setting.value;\n // Values written by saveCredential are AES-256-GCM encrypted at rest.\n // Rows that predate encryption are plaintext — read them transparently\n // (the migrate-encrypt-credentials script re-encrypts them in place).\n if (!isEncryptedSecretValue(stored)) return stored;\n try {\n return decryptSecretValue(stored);\n } catch {\n // Key rotated, corrupt, or tampered row — treat as not set rather than\n // surfacing ciphertext or throwing into every credential lookup.\n return undefined;\n }\n}\n\nasync function readScopedAppSecret(\n key: string,\n scope: SecretRef[\"scope\"],\n scopeId: string,\n): Promise<string | undefined> {\n try {\n return (await readAppSecret({ key, scope, scopeId }))?.value;\n } catch {\n // Older databases may not have app_secrets yet. Keep the legacy\n // credential store available while the table bootstraps.\n return undefined;\n }\n}\n\n/**\n * Resolve a credential from one explicit legacy SQL credential scope.\n *\n * Prefer `resolveCredential()` for normal app-local credential lookup. This\n * helper exists for workspace connection refs, where a ref can explicitly say\n * \"use the org-scoped key\" and must not accidentally read a user override.\n */\nexport async function resolveCredentialForScope(\n key: string,\n ctx: CredentialContext & { scope: CredentialStorageScope },\n): Promise<string | undefined> {\n if (!ctx?.userEmail) return undefined;\n if (ctx.scope === \"org\") {\n if (!ctx.orgId) return undefined;\n return readCredentialSetting(orgCredentialSettingKey(ctx.orgId, key));\n }\n return readCredentialSetting(userCredentialSettingKey(ctx.userEmail, key));\n}\n\n/**\n * Resolve a credential across the encrypted app_secrets store and the legacy\n * settings-backed credential store. User overrides win, followed by the\n * active org/workspace shared value.\n *\n * SECURITY: NEVER reads from process.env. Env vars are global to the\n * deployment and would leak across users in a multi-tenant app.\n *\n * Read order:\n * 1. user-scoped app_secrets\n * 2. user-scoped legacy settings credential\n * 3. org-scoped app_secrets\n * 4. legacy workspace-scoped app_secrets for the org\n * 5. org-scoped legacy settings credential\n *\n * Without an active org, step 3 is replaced by the solo workspace scope.\n */\nexport async function resolveCredential(\n key: string,\n ctx: CredentialContext,\n): Promise<string | undefined> {\n if (!ctx?.userEmail) return undefined;\n\n const userSecret = await readScopedAppSecret(key, \"user\", ctx.userEmail);\n if (userSecret) return userSecret;\n\n const userSetting = await resolveCredentialForScope(key, {\n ...ctx,\n scope: \"user\",\n });\n if (userSetting) return userSetting;\n\n if (ctx.orgId) {\n const orgSecret = await readScopedAppSecret(key, \"org\", ctx.orgId);\n if (orgSecret) return orgSecret;\n\n const workspaceSecret = await readScopedAppSecret(\n key,\n \"workspace\",\n ctx.orgId,\n );\n if (workspaceSecret) return workspaceSecret;\n\n return resolveCredentialForScope(key, { ...ctx, scope: \"org\" });\n }\n\n return readScopedAppSecret(key, \"workspace\", `solo:${ctx.userEmail}`);\n}\n\n/**\n * Check if a credential is available for the given context.\n */\nexport async function hasCredential(\n key: string,\n ctx: CredentialContext,\n): Promise<boolean> {\n return (await resolveCredential(key, ctx)) !== undefined;\n}\n\n/**\n * Save a credential. By default writes to the per-user store; pass\n * `scope: \"org\"` to write to the active org's shared credentials.\n */\nexport async function saveCredential(\n key: string,\n value: string,\n ctx: CredentialContext & { scope?: \"user\" | \"org\" },\n): Promise<void> {\n if (!ctx?.userEmail) {\n throw new Error(\"saveCredential requires CredentialContext with userEmail\");\n }\n // Encrypt at rest (AES-256-GCM) so a leaked DB backup / pg_dump / read\n // replica doesn't expose plaintext keys. resolveCredential decrypts\n // transparently on read.\n const encrypted = encryptSecretValue(value);\n if (ctx.scope === \"org\") {\n if (!ctx.orgId) {\n throw new Error(\"saveCredential scope='org' requires orgId\");\n }\n await putSetting(orgCredentialSettingKey(ctx.orgId, key), {\n value: encrypted,\n });\n return;\n }\n await putSetting(userCredentialSettingKey(ctx.userEmail, key), {\n value: encrypted,\n });\n}\n\n/**\n * Delete a credential from the per-user (default) or per-org store.\n */\nexport async function deleteCredential(\n key: string,\n ctx: CredentialContext & { scope?: \"user\" | \"org\" },\n): Promise<void> {\n if (!ctx?.userEmail) {\n throw new Error(\n \"deleteCredential requires CredentialContext with userEmail\",\n );\n }\n if (ctx.scope === \"org\") {\n if (!ctx.orgId) {\n throw new Error(\"deleteCredential scope='org' requires orgId\");\n }\n await deleteSetting(orgCredentialSettingKey(ctx.orgId, key));\n return;\n }\n await deleteSetting(userCredentialSettingKey(ctx.userEmail, key));\n}\n"]}
@@ -151,12 +151,13 @@ export declare function isDurableBackgroundDeployEnabled(): boolean;
151
151
  */
152
152
  export declare function emitSingleTemplateNetlifyBackgroundFunction(projectCwd: string): void;
153
153
  /**
154
- * Nitro can preserve Vite's `yjs` external in a split server chunk even when
155
- * its own server build has emitted `_libs/yjs.mjs`. Netlify does not install
156
- * that bare package at runtime, so make every emitted server chunk use the
157
- * bundled copy before its function is packaged.
154
+ * Nitro receives the React Router SSR build as prebuilt chunks, so its normal
155
+ * dependency resolver cannot reliably fold the preserved bare `yjs` imports
156
+ * into the same module instance used by core's server collaboration code.
157
+ * Keep Yjs external through Nitro, bundle its complete public ESM surface once,
158
+ * then point every emitted server chunk at that one portable runtime module.
158
159
  */
159
- export declare function rewriteBareYjsImportsForServerlessOutput(serverDir: string): string[];
160
+ export declare function bundleYjsRuntimeForServerlessOutput(serverDir: string, projectCwd: string): string[];
160
161
  export declare function assertSingleTemplateNetlifyBuildOutput(projectCwd: string): void;
161
162
  /**
162
163
  * Strip the harmful single-template catch-all rewrite that points at
@@ -204,17 +205,17 @@ export interface NitroBuildPipelineOptions {
204
205
  */
205
206
  export declare function runNitroBuildPipeline(opts: NitroBuildPipelineOptions): Promise<void>;
206
207
  /**
207
- * Dependencies that must be bundled into every Nitro server output instead of
208
- * being left as runtime package imports.
209
- *
210
- * `yjs` is a direct core dependency, but it is deliberately externalized from
211
- * the intermediate Vite SSR graph so that Vite and Nitro do not create two
212
- * incompatible Yjs constructors. On file-traced serverless presets, leaving it
213
- * external at Nitro's final build can emit `import "yjs"` into a function
214
- * chunk without placing the package in that function's `node_modules`. Bundle
215
- * it in Nitro's final output so every template receives the one portable copy.
208
+ * Dependencies Nitro itself must bundle outside the controlled serverless
209
+ * output pass. Netlify, Vercel, and Lambda keep Yjs external through Nitro;
210
+ * `bundleYjsRuntimeForServerlessOutput` then creates their one portable copy.
216
211
  */
217
212
  export declare const NITRO_SERVER_RUNTIME_BUNDLED_DEPS: readonly ["yjs"];
213
+ /**
214
+ * Locate the core-owned ESM entry used by the controlled serverless bundling
215
+ * pass. Resolving from this module keeps the build independent of whether a
216
+ * template exposes core's transitive Yjs dependency at its own package root.
217
+ */
218
+ export declare function resolveNitroBundledYjsEntry(): string;
218
219
  /**
219
220
  * Edge runtimes have no node_modules, while Node/serverless outputs only need
220
221
  * the small set above bundled to keep their package manifests traceable.
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/deploy/build.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;GAYG;AAuCH,OAAO,EAML,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,qBAAqB,CAAC;AAI7B,eAAO,MAAM,6BAA6B,UAiBzC,CAAC;AAEF,eAAO,MAAM,mCAAmC,UAiB/C,CAAC;AACF,eAAO,MAAM,8BAA8B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAiFjE,CAAC;AA6BF,eAAO,MAAM,2CAA2C,EAAE,MAAM,CAC9D,MAAM,EACN,MAAM,CAmSP,CAAC;AAEF,MAAM,WAAW,0BAA0B;IACzC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,UAAU,wBAAwB;IAChC,KAAK,EAAE,6BAA6B,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,6BAA6B,CAAC,CAAC;IACtD,GAAG,EAAE,MAAM,CAAC;CACb;AAED,UAAU,6BAA6B;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAA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