@adhdev/daemon-core 0.9.82-rc.476 → 0.9.82-rc.477

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/dist/index.mjs CHANGED
@@ -404,10 +404,10 @@ function readInjected(value) {
404
404
  }
405
405
  function getDaemonBuildInfo() {
406
406
  if (cached) return cached;
407
- const commit = readInjected(true ? "f3bc279bf108da3a23da4e0e33ebdc41d851930c" : void 0) ?? "unknown";
408
- const commitShort = readInjected(true ? "f3bc279b" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
409
- const version = readInjected(true ? "0.9.82-rc.476" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
410
- const builtAt = readInjected(true ? "2026-07-06T08:19:57.539Z" : void 0);
407
+ const commit = readInjected(true ? "e565a4d93874e580f3923a562a7a58229af17997" : void 0) ?? "unknown";
408
+ const commitShort = readInjected(true ? "e565a4d9" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
409
+ const version = readInjected(true ? "0.9.82-rc.477" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
410
+ const builtAt = readInjected(true ? "2026-07-06T18:09:09.172Z" : void 0);
411
411
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
412
412
  return cached;
413
413
  }
@@ -19313,6 +19313,16 @@ function evaluateMeshEventSuppression(args, ctx) {
19313
19313
  }
19314
19314
  return null;
19315
19315
  }
19316
+ function sourceWorkerAutoApproves(components, sessionId) {
19317
+ if (!sessionId) return false;
19318
+ try {
19319
+ const state = components.instanceManager?.getInstance?.(sessionId)?.getState?.();
19320
+ const settings = state?.settings || {};
19321
+ return settings.autoApprove === true;
19322
+ } catch {
19323
+ return false;
19324
+ }
19325
+ }
19316
19326
  function injectMeshSystemMessage(components, args) {
19317
19327
  const eventSessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
19318
19328
  const eventNodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
@@ -19371,6 +19381,11 @@ function injectMeshSystemMessage(components, args) {
19371
19381
  }
19372
19382
  }
19373
19383
  const eventTimestamp = readEventTimestamp(args.metadataEvent.timestamp);
19384
+ if (args.event === "agent:waiting_approval" && sourceWorkerAutoApproves(components, eventSessionId)) {
19385
+ LOG.info("MeshEvents", `Suppressed agent:waiting_approval for auto-approving worker session ${eventSessionId || "(unknown)"} (mesh ${args.meshId}) \u2014 modal is resolved locally, coordinator not notified`);
19386
+ traceMeshEventDrop("waiting_approval_auto_approving_worker", traceCtx);
19387
+ return { success: true, forwarded: 0, suppressed: true, autoApprovingWorkerApproval: true };
19388
+ }
19374
19389
  const suppression = evaluateMeshEventSuppression(args, {
19375
19390
  traceCtx,
19376
19391
  eventSessionId,
@@ -34051,10 +34066,14 @@ function hydratePersistedProviderSessionPinsOnce() {
34051
34066
  } catch {
34052
34067
  }
34053
34068
  }
34054
- function recordBoundProviderSessionId(meshSessionId, providerSessionId) {
34069
+ function recordBoundProviderSessionId(h, meshSessionId, providerSessionId) {
34055
34070
  const key2 = typeof meshSessionId === "string" ? meshSessionId.trim() : "";
34056
34071
  const value = typeof providerSessionId === "string" ? providerSessionId.trim() : "";
34057
34072
  if (!key2 || !value) return;
34073
+ try {
34074
+ h.ctx?.sessionRegistry?.setProviderSessionId?.(key2, value);
34075
+ } catch {
34076
+ }
34058
34077
  lastBoundProviderSessionIdByMeshSession.set(key2, value);
34059
34078
  try {
34060
34079
  recordPersistedProviderSessionPin(key2, value);
@@ -34627,8 +34646,14 @@ function hasSafeNativeHistoryMapping(args) {
34627
34646
  if (!args.requireWorkspaceContentOverlap) return true;
34628
34647
  return hasOverlappingVisibleConversationText(args.nativeMessages, args.ptyMessages || []);
34629
34648
  }
34649
+ function effectiveReadSessionId(h, targetSessionId) {
34650
+ const explicit = typeof targetSessionId === "string" ? targetSessionId.trim() : "";
34651
+ if (explicit) return explicit;
34652
+ const current = h.currentSession?.sessionId;
34653
+ return typeof current === "string" ? current.trim() : "";
34654
+ }
34630
34655
  function sessionStartedAtMsFromRegistry(h, targetSessionId) {
34631
- const sid = typeof targetSessionId === "string" ? targetSessionId.trim() : "";
34656
+ const sid = effectiveReadSessionId(h, targetSessionId);
34632
34657
  if (!sid) return void 0;
34633
34658
  const target = h.ctx?.sessionRegistry?.get?.(sid);
34634
34659
  return typeof target?.spawnedAtMs === "number" ? target.spawnedAtMs : void 0;
@@ -34925,7 +34950,7 @@ async function handleChatHistory(h, args) {
34925
34950
  scripts: provider?.scripts,
34926
34951
  sessionStartedAtMs: sessionStartedAtMsFromRegistry(h, args?.targetSessionId),
34927
34952
  envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
34928
- instanceId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0,
34953
+ instanceId: effectiveReadSessionId(h, args?.targetSessionId) || void 0,
34929
34954
  pinnedProviderSessionId: getBoundProviderSessionIdPin(args?.targetSessionId)
34930
34955
  }) : readProviderChatHistory(agentStr, {
34931
34956
  canonicalHistory: provider?.nativeHistory,
@@ -34942,7 +34967,7 @@ async function handleChatHistory(h, args) {
34942
34967
  const messages = Array.isArray(result.messages) ? normalizeAndFilterNativeHistory(h, agentStr, args, result.messages, result?.providerSessionId) : [];
34943
34968
  const historyProviderSessionId = typeof result?.providerSessionId === "string" ? result.providerSessionId : readHistorySessionIdFromMessages(messages) || historySessionId;
34944
34969
  if (typeof result?.providerSessionId === "string" && result.providerSessionId.trim()) {
34945
- recordBoundProviderSessionId(args?.targetSessionId, result.providerSessionId.trim());
34970
+ recordBoundProviderSessionId(h, effectiveReadSessionId(h, args?.targetSessionId), result.providerSessionId.trim());
34946
34971
  }
34947
34972
  const safeMapping = hasSafeNativeHistoryMapping({
34948
34973
  historySessionId: lookup === "workspace" ? void 0 : historySessionId,
@@ -35086,7 +35111,7 @@ async function handleReadChat(h, args) {
35086
35111
  envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
35087
35112
  // Stable per-session identity for antigravity's conversation-claim
35088
35113
  // owner token (== session registry sessionId == instance instanceId).
35089
- instanceId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0,
35114
+ instanceId: effectiveReadSessionId(h, args?.targetSessionId) || void 0,
35090
35115
  pinnedProviderSessionId: pinnedProviderSessionIdForRead,
35091
35116
  // Last-resort only when no pin was ever recorded for this
35092
35117
  // session; the downstream workspace-overlap safety gate
@@ -35095,7 +35120,7 @@ async function handleReadChat(h, args) {
35095
35120
  });
35096
35121
  const resolvedProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId.trim() : "";
35097
35122
  if (resolvedProviderSessionId) {
35098
- recordBoundProviderSessionId(targetSessionId, resolvedProviderSessionId);
35123
+ recordBoundProviderSessionId(h, effectiveReadSessionId(h, targetSessionId), resolvedProviderSessionId);
35099
35124
  }
35100
35125
  } catch (error) {
35101
35126
  nativeHistoryError = error;
@@ -35137,7 +35162,7 @@ async function handleReadChat(h, args) {
35137
35162
  excludeInProgressTurn: returnedStatus === "waiting_approval",
35138
35163
  sessionStartedAtMs,
35139
35164
  envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
35140
- instanceId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0
35165
+ instanceId: effectiveReadSessionId(h, args?.targetSessionId) || void 0
35141
35166
  });
35142
35167
  nativeHistoryError = void 0;
35143
35168
  nativeMessages = nativeHistory && Array.isArray(nativeHistory.messages) ? normalizeAndFilterNativeHistory(h, agentStr, args, nativeHistory.messages, nativeHistory.providerSessionId) : [];
@@ -35359,7 +35384,7 @@ async function handleReadChat(h, args) {
35359
35384
  scripts: provider?.scripts,
35360
35385
  sessionStartedAtMs: sessionStartedAtMsFromRegistry(h, args?.targetSessionId),
35361
35386
  envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
35362
- instanceId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0,
35387
+ instanceId: effectiveReadSessionId(h, args?.targetSessionId) || void 0,
35363
35388
  pinnedProviderSessionId: pinnedProviderSessionIdForHistory,
35364
35389
  // Last-resort only when no pin was ever recorded AND the
35365
35390
  // runtime fallback did not resolve a real provider session.
@@ -35378,7 +35403,7 @@ async function handleReadChat(h, args) {
35378
35403
  const historyMessages = Array.isArray(history?.messages) ? normalizeAndFilterNativeHistory(h, agentStr, args, history.messages, history?.providerSessionId) : [];
35379
35404
  const historyProviderSessionId = typeof history?.providerSessionId === "string" ? history.providerSessionId : readHistorySessionIdFromMessages(historyMessages) || effectiveHistorySessionIdForRead;
35380
35405
  if (typeof history?.providerSessionId === "string" && history.providerSessionId.trim()) {
35381
- recordBoundProviderSessionId(targetSid, history.providerSessionId.trim());
35406
+ recordBoundProviderSessionId(h, effectiveReadSessionId(h, targetSid), history.providerSessionId.trim());
35382
35407
  }
35383
35408
  const mappingSessionId = effectiveHistorySessionIdForRead;
35384
35409
  const safeMapping = supportsNative ? hasSafeNativeHistoryMapping({
@@ -43845,6 +43870,7 @@ function createCliAdapter(provider, workingDir, cliArgs, extraEnv, transportFact
43845
43870
  }
43846
43871
 
43847
43872
  // src/providers/cli-provider-instance.ts
43873
+ init_state_store();
43848
43874
  init_logger();
43849
43875
  init_debug_trace();
43850
43876
  init_debug_config();
@@ -43877,13 +43903,10 @@ function normalizeUuid(uuid) {
43877
43903
  return String(uuid || "").trim().toLowerCase();
43878
43904
  }
43879
43905
  function antigravityOwnerToken(workspace, sessionStartedAtMs, instanceId) {
43906
+ void workspace;
43907
+ void sessionStartedAtMs;
43880
43908
  const iid = typeof instanceId === "string" ? instanceId.trim() : "";
43881
- if (iid) return `iid:${iid}`;
43882
- if (typeof sessionStartedAtMs === "number" && sessionStartedAtMs > 0) {
43883
- const ws = String(workspace || "").trim().toLowerCase();
43884
- return `spawn:${ws}:${sessionStartedAtMs}`;
43885
- }
43886
- return "";
43909
+ return iid ? `iid:${iid}` : "";
43887
43910
  }
43888
43911
  function claimAntigravityConversation(uuid, owner, now = Date.now()) {
43889
43912
  const key2 = normalizeUuid(uuid);
@@ -44643,6 +44666,27 @@ var CliProviderInstance = class _CliProviderInstance {
44643
44666
  senderName: message.senderName,
44644
44667
  receivedAt: message.receivedAt
44645
44668
  })) : mergedMessages;
44669
+ const adapterOwnsMessagesElsewhereForTail = this.adapter?.chatMessagesOwnedExternally === true;
44670
+ if (adapterOwnsMessagesElsewhereForTail && this.lastCompletionSummary) {
44671
+ const summary = this.lastCompletionSummary;
44672
+ let hasTrailingAssistant = false;
44673
+ for (let i = statusMessages.length - 1; i >= 0; i -= 1) {
44674
+ const m = statusMessages[i];
44675
+ const role = typeof m?.role === "string" ? m.role : "";
44676
+ if (role === "system") continue;
44677
+ if (typeof m?.kind === "string" && m.kind === "tool") continue;
44678
+ hasTrailingAssistant = role === "assistant" && typeof m?.receivedAt === "number" && m.receivedAt >= summary.receivedAt - 1e3;
44679
+ break;
44680
+ }
44681
+ if (!hasTrailingAssistant) {
44682
+ statusMessages.push({
44683
+ role: "assistant",
44684
+ content: summary.content,
44685
+ kind: "standard",
44686
+ receivedAt: summary.receivedAt
44687
+ });
44688
+ }
44689
+ }
44646
44690
  const dirName = workingDirBasename(this.workingDir);
44647
44691
  const parsedChatStatus = typeof parsedStatus?.status === "string" && parsedStatus.status.trim() ? parsedStatus.status.trim() : void 0;
44648
44692
  const suppressStaleParsedBusyStatus = this.shouldSuppressStaleParsedBusyStatus(parsedStatus, adapterStatus);
@@ -45075,6 +45119,18 @@ var CliProviderInstance = class _CliProviderInstance {
45075
45119
  completedDebounceTimer = null;
45076
45120
  completedDebouncePending = null;
45077
45121
  lastExternalCompletionProbe = null;
45122
+ /**
45123
+ * The final assistant summary of the last completed turn, cached at
45124
+ * completion-emit time. For a native-source provider (antigravity) whose
45125
+ * assistant answer lives only in native-history — never in the PTY parse that
45126
+ * feeds activeChat.messages — the dashboard's preview / lastMessageRole /
45127
+ * completionMarker would otherwise never see the answer and show the session
45128
+ * stuck on the user prompt. getState() appends this cached assistant bubble to
45129
+ * the status messages when the PTY tail has none, so those fields reflect the
45130
+ * real last answer with ZERO per-tick native reads (the native read already ran
45131
+ * once at completion). Reset on the next turn's start.
45132
+ */
45133
+ lastCompletionSummary = null;
45078
45134
  async enforceFreshSessionLaunchIfNeeded() {
45079
45135
  const scriptName = getForcedNewSessionScriptName(this.provider, this.launchMode);
45080
45136
  if (!scriptName) return;
@@ -45138,8 +45194,15 @@ var CliProviderInstance = class _CliProviderInstance {
45138
45194
  readExternalCompletionMessages() {
45139
45195
  const adapterOwnsMessagesElsewhere = this.adapter?.chatMessagesOwnedExternally === true;
45140
45196
  if (!adapterOwnsMessagesElsewhere) return null;
45141
- if (!this.providerSessionId) return null;
45142
45197
  if (!isNativeSourceCanonicalHistory(this.provider.nativeHistory)) return null;
45198
+ let resolvedHandle = this.providerSessionId || "";
45199
+ if (!resolvedHandle) {
45200
+ try {
45201
+ const pinned = loadPersistedProviderSessionPins()[this.instanceId];
45202
+ if (typeof pinned === "string" && pinned.trim()) resolvedHandle = pinned.trim();
45203
+ } catch {
45204
+ }
45205
+ }
45143
45206
  if (this.lastExternalCompletionProbe?.sourcePath) {
45144
45207
  try {
45145
45208
  fs21.statSync(this.lastExternalCompletionProbe.sourcePath);
@@ -45148,13 +45211,18 @@ var CliProviderInstance = class _CliProviderInstance {
45148
45211
  }
45149
45212
  const restoredHistory = readProviderChatHistory(this.type, {
45150
45213
  canonicalHistory: this.provider.nativeHistory,
45151
- historySessionId: this.providerSessionId,
45214
+ historySessionId: resolvedHandle || void 0,
45152
45215
  workspace: this.workingDir,
45153
45216
  offset: 0,
45154
45217
  limit: Number.MAX_SAFE_INTEGER,
45155
45218
  historyBehavior: this.provider.historyBehavior,
45156
45219
  scripts: this.provider.scripts,
45157
45220
  sessionStartedAtMs: this.startedAt,
45221
+ // The claim owner token must match read_chat's so the exact-bind on our
45222
+ // own conversation stays idempotent rather than looking foreign, and so
45223
+ // the floor-based resolution above claims THIS session's db under its
45224
+ // own owner (never a sibling's).
45225
+ instanceId: this.instanceId,
45158
45226
  envOverrides: this.spawnedEnvOverrides(),
45159
45227
  forceRefresh: true
45160
45228
  });
@@ -45169,6 +45237,26 @@ var CliProviderInstance = class _CliProviderInstance {
45169
45237
  );
45170
45238
  return restoredHistory.messages;
45171
45239
  }
45240
+ /**
45241
+ * The content of the LAST visible assistant bubble in a message list, or ''
45242
+ * when the tail is not an assistant reply. Skips trailing system/tool/activity
45243
+ * bubbles; stops (returns '') at the first user/human message. Used only for
45244
+ * the dashboard tail-repair cache — a display value, not a completion decision.
45245
+ */
45246
+ lastVisibleAssistantSummary(messages) {
45247
+ if (!Array.isArray(messages)) return "";
45248
+ for (let i = messages.length - 1; i >= 0; i -= 1) {
45249
+ const m = messages[i];
45250
+ const role = typeof m?.role === "string" ? m.role : "";
45251
+ const kind = typeof m?.kind === "string" ? m.kind : "";
45252
+ if (role === "system") continue;
45253
+ if (kind === "tool" || kind === "activity") continue;
45254
+ if (role === "user" || role === "human") return "";
45255
+ if (role === "assistant") return flattenContent(m.content).trim();
45256
+ return "";
45257
+ }
45258
+ return "";
45259
+ }
45172
45260
  completionFinalAssistantEvidence(parsedMessages, turnStartedAt) {
45173
45261
  const turnClosed = !this.hasAdapterPendingResponse();
45174
45262
  if (this.completionHasFinalAssistantMessage(parsedMessages, turnStartedAt)) {
@@ -45180,8 +45268,13 @@ var CliProviderInstance = class _CliProviderInstance {
45180
45268
  }
45181
45269
  const externalMessages = this.readExternalCompletionMessages();
45182
45270
  if (externalMessages) {
45271
+ const present = turnClosed && this.completionHasFinalAssistantMessage(externalMessages, turnStartedAt);
45272
+ const lastVisibleAssistant = this.lastVisibleAssistantSummary(externalMessages);
45273
+ if (lastVisibleAssistant) {
45274
+ this.lastCompletionSummary = { content: lastVisibleAssistant, receivedAt: Date.now() };
45275
+ }
45183
45276
  return {
45184
- present: turnClosed && this.completionHasFinalAssistantMessage(externalMessages, turnStartedAt),
45277
+ present,
45185
45278
  messages: externalMessages,
45186
45279
  source: "external-native"
45187
45280
  };
@@ -45201,7 +45294,10 @@ var CliProviderInstance = class _CliProviderInstance {
45201
45294
  if (adapterOwnsMessagesElsewhere) {
45202
45295
  const externalMessages = this.readExternalCompletionMessages();
45203
45296
  const externalSummary = externalMessages ? extractFinalSummaryFromMessagesAfter(externalMessages, turnStartedAt) : "";
45204
- if (externalSummary) return externalSummary;
45297
+ if (externalSummary) {
45298
+ this.lastCompletionSummary = { content: externalSummary, receivedAt: Date.now() };
45299
+ return externalSummary;
45300
+ }
45205
45301
  return parsedSummary || void 0;
45206
45302
  }
45207
45303
  return parsedSummary || void 0;
@@ -45669,6 +45765,10 @@ var CliProviderInstance = class _CliProviderInstance {
45669
45765
  * the emitted event, exactly as each inline builder produced before.
45670
45766
  */
45671
45767
  emitGeneratingCompleted(opts) {
45768
+ const summary = typeof opts.finalSummary === "string" ? opts.finalSummary.trim() : "";
45769
+ if (summary) {
45770
+ this.lastCompletionSummary = { content: summary, receivedAt: opts.timestamp };
45771
+ }
45672
45772
  this.pushEvent({
45673
45773
  event: "agent:generating_completed",
45674
45774
  chatTitle: opts.chatTitle,
@@ -45953,6 +46053,7 @@ var CliProviderInstance = class _CliProviderInstance {
45953
46053
  this.completedDebouncePending = null;
45954
46054
  }
45955
46055
  if (!this.generatingStartedAt) this.generatingStartedAt = now;
46056
+ this.lastCompletionSummary = null;
45956
46057
  this.busyEpoch++;
45957
46058
  if (this.generatingDebounceTimer) clearTimeout(this.generatingDebounceTimer);
45958
46059
  this.generatingDebouncePending = { chatTitle, timestamp: now };
@@ -51094,10 +51195,24 @@ function resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instan
51094
51195
  const brainRoot2 = path34.join(agyRoot, "brain");
51095
51196
  if (fs26.existsSync(brainRoot2)) {
51096
51197
  const cutoff = spawnAwareCutoff(sessionStartedAtMs);
51097
- const entries = fs26.readdirSync(brainRoot2, { withFileTypes: true }).filter((e) => e.isDirectory() && isUuidLikeSessionId2(e.name)).filter((e) => !isAntigravityConversationClaimedByOther(e.name, owner)).map((e) => ({ uuid: e.name, p: path34.join(brainRoot2, e.name), mtime: safeMtime(path34.join(brainRoot2, e.name)) })).filter((e) => e.mtime >= cutoff).sort((a, b) => b.mtime - a.mtime);
51098
- for (const e of entries) {
51099
- const t = path34.join(e.p, ".system_generated", "logs", "transcript.jsonl");
51100
- if (fs26.existsSync(t) && safeSize(t) > 0) {
51198
+ const nonEmptyBrain = (uuid, p) => {
51199
+ const t = path34.join(p, ".system_generated", "logs", "transcript.jsonl");
51200
+ return fs26.existsSync(t) && safeSize(t) > 0 ? t : null;
51201
+ };
51202
+ const all = fs26.readdirSync(brainRoot2, { withFileTypes: true }).filter((e) => e.isDirectory() && isUuidLikeSessionId2(e.name)).filter((e) => !isAntigravityConversationClaimedByOther(e.name, owner)).map((e) => {
51203
+ const p = path34.join(brainRoot2, e.name);
51204
+ return { uuid: e.name, p, mtime: safeMtime(p), birth: safeBirthtime(p) };
51205
+ }).filter((e) => e.mtime >= cutoff);
51206
+ let ordered = [];
51207
+ if (sessionStartedAtMs > 0) {
51208
+ const floor = sessionStartedAtMs - AGY_SPAWN_CLAIM_GRACE_MS;
51209
+ ordered = all.filter((e) => (e.birth > 0 ? e.birth : e.mtime) >= floor).sort((a, b) => (a.birth || a.mtime) - (b.birth || b.mtime));
51210
+ } else {
51211
+ ordered = [...all].sort((a, b) => b.mtime - a.mtime);
51212
+ }
51213
+ for (const e of ordered) {
51214
+ const t = nonEmptyBrain(e.uuid, e.p);
51215
+ if (t) {
51101
51216
  if (owner) claimAntigravityConversation(e.uuid, owner);
51102
51217
  return t;
51103
51218
  }
@@ -68380,7 +68495,11 @@ var SessionRegistry = class {
68380
68495
  byInstanceKey = /* @__PURE__ */ new Map();
68381
68496
  byParentSessionId = /* @__PURE__ */ new Map();
68382
68497
  register(target) {
68498
+ const priorProviderSessionId = this.bySessionId.get(target.sessionId)?.providerSessionId;
68383
68499
  this.unregister(target.sessionId);
68500
+ if (priorProviderSessionId && !target.providerSessionId) {
68501
+ target = { ...target, providerSessionId: priorProviderSessionId };
68502
+ }
68384
68503
  this.bySessionId.set(target.sessionId, target);
68385
68504
  if (target.cdpManagerKey) this.addIndex(this.byManagerKey, target.cdpManagerKey, target.sessionId);
68386
68505
  if (target.instanceKey) this.addIndex(this.byInstanceKey, target.instanceKey, target.sessionId);
@@ -68390,6 +68509,22 @@ var SessionRegistry = class {
68390
68509
  if (!sessionId) return void 0;
68391
68510
  return this.bySessionId.get(sessionId);
68392
68511
  }
68512
+ /**
68513
+ * Record the authoritative provider-native conversation id for a session
68514
+ * (SSOT). Idempotent; a no-op when the session is unknown or the value is
68515
+ * empty or unchanged. Never overwrites a known binding with an empty one.
68516
+ * Returns whether the stored value changed.
68517
+ */
68518
+ setProviderSessionId(sessionId, providerSessionId) {
68519
+ const sid = typeof sessionId === "string" ? sessionId.trim() : "";
68520
+ const value = typeof providerSessionId === "string" ? providerSessionId.trim() : "";
68521
+ if (!sid || !value) return false;
68522
+ const target = this.bySessionId.get(sid);
68523
+ if (!target) return false;
68524
+ if (target.providerSessionId === value) return false;
68525
+ target.providerSessionId = value;
68526
+ return true;
68527
+ }
68393
68528
  unregister(sessionId) {
68394
68529
  if (!sessionId) return;
68395
68530
  const target = this.bySessionId.get(sessionId);