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

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.js CHANGED
@@ -409,10 +409,10 @@ function readInjected(value) {
409
409
  }
410
410
  function getDaemonBuildInfo() {
411
411
  if (cached) return cached;
412
- const commit = readInjected(true ? "f3bc279bf108da3a23da4e0e33ebdc41d851930c" : void 0) ?? "unknown";
413
- const commitShort = readInjected(true ? "f3bc279b" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
414
- const version = readInjected(true ? "0.9.82-rc.476" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
415
- const builtAt = readInjected(true ? "2026-07-06T08:19:57.539Z" : void 0);
412
+ const commit = readInjected(true ? "5ae79caf6a3117a9b9353f4a2dfd2083e2657007" : void 0) ?? "unknown";
413
+ const commitShort = readInjected(true ? "5ae79caf" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
414
+ const version = readInjected(true ? "0.9.82-rc.478" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
415
+ const builtAt = readInjected(true ? "2026-07-06T19:05:05.753Z" : void 0);
416
416
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
417
417
  return cached;
418
418
  }
@@ -19311,6 +19311,16 @@ function evaluateMeshEventSuppression(args, ctx) {
19311
19311
  }
19312
19312
  return null;
19313
19313
  }
19314
+ function sourceWorkerAutoApproves(components, sessionId) {
19315
+ if (!sessionId) return false;
19316
+ try {
19317
+ const state = components.instanceManager?.getInstance?.(sessionId)?.getState?.();
19318
+ const settings = state?.settings || {};
19319
+ return settings.autoApprove === true;
19320
+ } catch {
19321
+ return false;
19322
+ }
19323
+ }
19314
19324
  function injectMeshSystemMessage(components, args) {
19315
19325
  const eventSessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
19316
19326
  const eventNodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
@@ -19369,6 +19379,11 @@ function injectMeshSystemMessage(components, args) {
19369
19379
  }
19370
19380
  }
19371
19381
  const eventTimestamp = readEventTimestamp(args.metadataEvent.timestamp);
19382
+ if (args.event === "agent:waiting_approval" && sourceWorkerAutoApproves(components, eventSessionId)) {
19383
+ 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`);
19384
+ traceMeshEventDrop("waiting_approval_auto_approving_worker", traceCtx);
19385
+ return { success: true, forwarded: 0, suppressed: true, autoApprovingWorkerApproval: true };
19386
+ }
19372
19387
  const suppression = evaluateMeshEventSuppression(args, {
19373
19388
  traceCtx,
19374
19389
  eventSessionId,
@@ -34474,10 +34489,14 @@ function hydratePersistedProviderSessionPinsOnce() {
34474
34489
  } catch {
34475
34490
  }
34476
34491
  }
34477
- function recordBoundProviderSessionId(meshSessionId, providerSessionId) {
34492
+ function recordBoundProviderSessionId(h, meshSessionId, providerSessionId) {
34478
34493
  const key2 = typeof meshSessionId === "string" ? meshSessionId.trim() : "";
34479
34494
  const value = typeof providerSessionId === "string" ? providerSessionId.trim() : "";
34480
34495
  if (!key2 || !value) return;
34496
+ try {
34497
+ h.ctx?.sessionRegistry?.setProviderSessionId?.(key2, value);
34498
+ } catch {
34499
+ }
34481
34500
  lastBoundProviderSessionIdByMeshSession.set(key2, value);
34482
34501
  try {
34483
34502
  recordPersistedProviderSessionPin(key2, value);
@@ -35050,8 +35069,14 @@ function hasSafeNativeHistoryMapping(args) {
35050
35069
  if (!args.requireWorkspaceContentOverlap) return true;
35051
35070
  return hasOverlappingVisibleConversationText(args.nativeMessages, args.ptyMessages || []);
35052
35071
  }
35072
+ function effectiveReadSessionId(h, targetSessionId) {
35073
+ const explicit = typeof targetSessionId === "string" ? targetSessionId.trim() : "";
35074
+ if (explicit) return explicit;
35075
+ const current = h.currentSession?.sessionId;
35076
+ return typeof current === "string" ? current.trim() : "";
35077
+ }
35053
35078
  function sessionStartedAtMsFromRegistry(h, targetSessionId) {
35054
- const sid = typeof targetSessionId === "string" ? targetSessionId.trim() : "";
35079
+ const sid = effectiveReadSessionId(h, targetSessionId);
35055
35080
  if (!sid) return void 0;
35056
35081
  const target = h.ctx?.sessionRegistry?.get?.(sid);
35057
35082
  return typeof target?.spawnedAtMs === "number" ? target.spawnedAtMs : void 0;
@@ -35348,7 +35373,7 @@ async function handleChatHistory(h, args) {
35348
35373
  scripts: provider?.scripts,
35349
35374
  sessionStartedAtMs: sessionStartedAtMsFromRegistry(h, args?.targetSessionId),
35350
35375
  envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
35351
- instanceId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0,
35376
+ instanceId: effectiveReadSessionId(h, args?.targetSessionId) || void 0,
35352
35377
  pinnedProviderSessionId: getBoundProviderSessionIdPin(args?.targetSessionId)
35353
35378
  }) : readProviderChatHistory(agentStr, {
35354
35379
  canonicalHistory: provider?.nativeHistory,
@@ -35365,7 +35390,7 @@ async function handleChatHistory(h, args) {
35365
35390
  const messages = Array.isArray(result.messages) ? normalizeAndFilterNativeHistory(h, agentStr, args, result.messages, result?.providerSessionId) : [];
35366
35391
  const historyProviderSessionId = typeof result?.providerSessionId === "string" ? result.providerSessionId : readHistorySessionIdFromMessages(messages) || historySessionId;
35367
35392
  if (typeof result?.providerSessionId === "string" && result.providerSessionId.trim()) {
35368
- recordBoundProviderSessionId(args?.targetSessionId, result.providerSessionId.trim());
35393
+ recordBoundProviderSessionId(h, effectiveReadSessionId(h, args?.targetSessionId), result.providerSessionId.trim());
35369
35394
  }
35370
35395
  const safeMapping = hasSafeNativeHistoryMapping({
35371
35396
  historySessionId: lookup === "workspace" ? void 0 : historySessionId,
@@ -35509,7 +35534,7 @@ async function handleReadChat(h, args) {
35509
35534
  envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
35510
35535
  // Stable per-session identity for antigravity's conversation-claim
35511
35536
  // owner token (== session registry sessionId == instance instanceId).
35512
- instanceId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0,
35537
+ instanceId: effectiveReadSessionId(h, args?.targetSessionId) || void 0,
35513
35538
  pinnedProviderSessionId: pinnedProviderSessionIdForRead,
35514
35539
  // Last-resort only when no pin was ever recorded for this
35515
35540
  // session; the downstream workspace-overlap safety gate
@@ -35518,7 +35543,7 @@ async function handleReadChat(h, args) {
35518
35543
  });
35519
35544
  const resolvedProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId.trim() : "";
35520
35545
  if (resolvedProviderSessionId) {
35521
- recordBoundProviderSessionId(targetSessionId, resolvedProviderSessionId);
35546
+ recordBoundProviderSessionId(h, effectiveReadSessionId(h, targetSessionId), resolvedProviderSessionId);
35522
35547
  }
35523
35548
  } catch (error) {
35524
35549
  nativeHistoryError = error;
@@ -35560,7 +35585,7 @@ async function handleReadChat(h, args) {
35560
35585
  excludeInProgressTurn: returnedStatus === "waiting_approval",
35561
35586
  sessionStartedAtMs,
35562
35587
  envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
35563
- instanceId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0
35588
+ instanceId: effectiveReadSessionId(h, args?.targetSessionId) || void 0
35564
35589
  });
35565
35590
  nativeHistoryError = void 0;
35566
35591
  nativeMessages = nativeHistory && Array.isArray(nativeHistory.messages) ? normalizeAndFilterNativeHistory(h, agentStr, args, nativeHistory.messages, nativeHistory.providerSessionId) : [];
@@ -35782,7 +35807,7 @@ async function handleReadChat(h, args) {
35782
35807
  scripts: provider?.scripts,
35783
35808
  sessionStartedAtMs: sessionStartedAtMsFromRegistry(h, args?.targetSessionId),
35784
35809
  envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
35785
- instanceId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0,
35810
+ instanceId: effectiveReadSessionId(h, args?.targetSessionId) || void 0,
35786
35811
  pinnedProviderSessionId: pinnedProviderSessionIdForHistory,
35787
35812
  // Last-resort only when no pin was ever recorded AND the
35788
35813
  // runtime fallback did not resolve a real provider session.
@@ -35801,7 +35826,7 @@ async function handleReadChat(h, args) {
35801
35826
  const historyMessages = Array.isArray(history?.messages) ? normalizeAndFilterNativeHistory(h, agentStr, args, history.messages, history?.providerSessionId) : [];
35802
35827
  const historyProviderSessionId = typeof history?.providerSessionId === "string" ? history.providerSessionId : readHistorySessionIdFromMessages(historyMessages) || effectiveHistorySessionIdForRead;
35803
35828
  if (typeof history?.providerSessionId === "string" && history.providerSessionId.trim()) {
35804
- recordBoundProviderSessionId(targetSid, history.providerSessionId.trim());
35829
+ recordBoundProviderSessionId(h, effectiveReadSessionId(h, targetSid), history.providerSessionId.trim());
35805
35830
  }
35806
35831
  const mappingSessionId = effectiveHistorySessionIdForRead;
35807
35832
  const safeMapping = supportsNative ? hasSafeNativeHistoryMapping({
@@ -44268,6 +44293,7 @@ function createCliAdapter(provider, workingDir, cliArgs, extraEnv, transportFact
44268
44293
  }
44269
44294
 
44270
44295
  // src/providers/cli-provider-instance.ts
44296
+ init_state_store();
44271
44297
  init_logger();
44272
44298
  init_debug_trace();
44273
44299
  init_debug_config();
@@ -44300,13 +44326,10 @@ function normalizeUuid(uuid) {
44300
44326
  return String(uuid || "").trim().toLowerCase();
44301
44327
  }
44302
44328
  function antigravityOwnerToken(workspace, sessionStartedAtMs, instanceId) {
44329
+ void workspace;
44330
+ void sessionStartedAtMs;
44303
44331
  const iid = typeof instanceId === "string" ? instanceId.trim() : "";
44304
- if (iid) return `iid:${iid}`;
44305
- if (typeof sessionStartedAtMs === "number" && sessionStartedAtMs > 0) {
44306
- const ws = String(workspace || "").trim().toLowerCase();
44307
- return `spawn:${ws}:${sessionStartedAtMs}`;
44308
- }
44309
- return "";
44332
+ return iid ? `iid:${iid}` : "";
44310
44333
  }
44311
44334
  function claimAntigravityConversation(uuid, owner, now = Date.now()) {
44312
44335
  const key2 = normalizeUuid(uuid);
@@ -45066,6 +45089,27 @@ var CliProviderInstance = class _CliProviderInstance {
45066
45089
  senderName: message.senderName,
45067
45090
  receivedAt: message.receivedAt
45068
45091
  })) : mergedMessages;
45092
+ const adapterOwnsMessagesElsewhereForTail = this.adapter?.chatMessagesOwnedExternally === true;
45093
+ if (adapterOwnsMessagesElsewhereForTail && this.lastCompletionSummary) {
45094
+ const summary = this.lastCompletionSummary;
45095
+ let hasTrailingAssistant = false;
45096
+ for (let i = statusMessages.length - 1; i >= 0; i -= 1) {
45097
+ const m = statusMessages[i];
45098
+ const role = typeof m?.role === "string" ? m.role : "";
45099
+ if (role === "system") continue;
45100
+ if (typeof m?.kind === "string" && m.kind === "tool") continue;
45101
+ hasTrailingAssistant = role === "assistant" && typeof m?.receivedAt === "number" && m.receivedAt >= summary.receivedAt - 1e3;
45102
+ break;
45103
+ }
45104
+ if (!hasTrailingAssistant) {
45105
+ statusMessages.push({
45106
+ role: "assistant",
45107
+ content: summary.content,
45108
+ kind: "standard",
45109
+ receivedAt: summary.receivedAt
45110
+ });
45111
+ }
45112
+ }
45069
45113
  const dirName = workingDirBasename(this.workingDir);
45070
45114
  const parsedChatStatus = typeof parsedStatus?.status === "string" && parsedStatus.status.trim() ? parsedStatus.status.trim() : void 0;
45071
45115
  const suppressStaleParsedBusyStatus = this.shouldSuppressStaleParsedBusyStatus(parsedStatus, adapterStatus);
@@ -45498,6 +45542,18 @@ var CliProviderInstance = class _CliProviderInstance {
45498
45542
  completedDebounceTimer = null;
45499
45543
  completedDebouncePending = null;
45500
45544
  lastExternalCompletionProbe = null;
45545
+ /**
45546
+ * The final assistant summary of the last completed turn, cached at
45547
+ * completion-emit time. For a native-source provider (antigravity) whose
45548
+ * assistant answer lives only in native-history — never in the PTY parse that
45549
+ * feeds activeChat.messages — the dashboard's preview / lastMessageRole /
45550
+ * completionMarker would otherwise never see the answer and show the session
45551
+ * stuck on the user prompt. getState() appends this cached assistant bubble to
45552
+ * the status messages when the PTY tail has none, so those fields reflect the
45553
+ * real last answer with ZERO per-tick native reads (the native read already ran
45554
+ * once at completion). Reset on the next turn's start.
45555
+ */
45556
+ lastCompletionSummary = null;
45501
45557
  async enforceFreshSessionLaunchIfNeeded() {
45502
45558
  const scriptName = getForcedNewSessionScriptName(this.provider, this.launchMode);
45503
45559
  if (!scriptName) return;
@@ -45561,8 +45617,15 @@ var CliProviderInstance = class _CliProviderInstance {
45561
45617
  readExternalCompletionMessages() {
45562
45618
  const adapterOwnsMessagesElsewhere = this.adapter?.chatMessagesOwnedExternally === true;
45563
45619
  if (!adapterOwnsMessagesElsewhere) return null;
45564
- if (!this.providerSessionId) return null;
45565
45620
  if (!isNativeSourceCanonicalHistory(this.provider.nativeHistory)) return null;
45621
+ let resolvedHandle = this.providerSessionId || "";
45622
+ if (!resolvedHandle) {
45623
+ try {
45624
+ const pinned = loadPersistedProviderSessionPins()[this.instanceId];
45625
+ if (typeof pinned === "string" && pinned.trim()) resolvedHandle = pinned.trim();
45626
+ } catch {
45627
+ }
45628
+ }
45566
45629
  if (this.lastExternalCompletionProbe?.sourcePath) {
45567
45630
  try {
45568
45631
  fs21.statSync(this.lastExternalCompletionProbe.sourcePath);
@@ -45571,13 +45634,18 @@ var CliProviderInstance = class _CliProviderInstance {
45571
45634
  }
45572
45635
  const restoredHistory = readProviderChatHistory(this.type, {
45573
45636
  canonicalHistory: this.provider.nativeHistory,
45574
- historySessionId: this.providerSessionId,
45637
+ historySessionId: resolvedHandle || void 0,
45575
45638
  workspace: this.workingDir,
45576
45639
  offset: 0,
45577
45640
  limit: Number.MAX_SAFE_INTEGER,
45578
45641
  historyBehavior: this.provider.historyBehavior,
45579
45642
  scripts: this.provider.scripts,
45580
45643
  sessionStartedAtMs: this.startedAt,
45644
+ // The claim owner token must match read_chat's so the exact-bind on our
45645
+ // own conversation stays idempotent rather than looking foreign, and so
45646
+ // the floor-based resolution above claims THIS session's db under its
45647
+ // own owner (never a sibling's).
45648
+ instanceId: this.instanceId,
45581
45649
  envOverrides: this.spawnedEnvOverrides(),
45582
45650
  forceRefresh: true
45583
45651
  });
@@ -45592,6 +45660,26 @@ var CliProviderInstance = class _CliProviderInstance {
45592
45660
  );
45593
45661
  return restoredHistory.messages;
45594
45662
  }
45663
+ /**
45664
+ * The content of the LAST visible assistant bubble in a message list, or ''
45665
+ * when the tail is not an assistant reply. Skips trailing system/tool/activity
45666
+ * bubbles; stops (returns '') at the first user/human message. Used only for
45667
+ * the dashboard tail-repair cache — a display value, not a completion decision.
45668
+ */
45669
+ lastVisibleAssistantSummary(messages) {
45670
+ if (!Array.isArray(messages)) return "";
45671
+ for (let i = messages.length - 1; i >= 0; i -= 1) {
45672
+ const m = messages[i];
45673
+ const role = typeof m?.role === "string" ? m.role : "";
45674
+ const kind = typeof m?.kind === "string" ? m.kind : "";
45675
+ if (role === "system") continue;
45676
+ if (kind === "tool" || kind === "activity") continue;
45677
+ if (role === "user" || role === "human") return "";
45678
+ if (role === "assistant") return flattenContent(m.content).trim();
45679
+ return "";
45680
+ }
45681
+ return "";
45682
+ }
45595
45683
  completionFinalAssistantEvidence(parsedMessages, turnStartedAt) {
45596
45684
  const turnClosed = !this.hasAdapterPendingResponse();
45597
45685
  if (this.completionHasFinalAssistantMessage(parsedMessages, turnStartedAt)) {
@@ -45603,8 +45691,13 @@ var CliProviderInstance = class _CliProviderInstance {
45603
45691
  }
45604
45692
  const externalMessages = this.readExternalCompletionMessages();
45605
45693
  if (externalMessages) {
45694
+ const present = turnClosed && this.completionHasFinalAssistantMessage(externalMessages, turnStartedAt);
45695
+ const lastVisibleAssistant = this.lastVisibleAssistantSummary(externalMessages);
45696
+ if (lastVisibleAssistant) {
45697
+ this.lastCompletionSummary = { content: lastVisibleAssistant, receivedAt: Date.now() };
45698
+ }
45606
45699
  return {
45607
- present: turnClosed && this.completionHasFinalAssistantMessage(externalMessages, turnStartedAt),
45700
+ present,
45608
45701
  messages: externalMessages,
45609
45702
  source: "external-native"
45610
45703
  };
@@ -45624,7 +45717,10 @@ var CliProviderInstance = class _CliProviderInstance {
45624
45717
  if (adapterOwnsMessagesElsewhere) {
45625
45718
  const externalMessages = this.readExternalCompletionMessages();
45626
45719
  const externalSummary = externalMessages ? extractFinalSummaryFromMessagesAfter(externalMessages, turnStartedAt) : "";
45627
- if (externalSummary) return externalSummary;
45720
+ if (externalSummary) {
45721
+ this.lastCompletionSummary = { content: externalSummary, receivedAt: Date.now() };
45722
+ return externalSummary;
45723
+ }
45628
45724
  return parsedSummary || void 0;
45629
45725
  }
45630
45726
  return parsedSummary || void 0;
@@ -46092,6 +46188,10 @@ var CliProviderInstance = class _CliProviderInstance {
46092
46188
  * the emitted event, exactly as each inline builder produced before.
46093
46189
  */
46094
46190
  emitGeneratingCompleted(opts) {
46191
+ const summary = typeof opts.finalSummary === "string" ? opts.finalSummary.trim() : "";
46192
+ if (summary) {
46193
+ this.lastCompletionSummary = { content: summary, receivedAt: opts.timestamp };
46194
+ }
46095
46195
  this.pushEvent({
46096
46196
  event: "agent:generating_completed",
46097
46197
  chatTitle: opts.chatTitle,
@@ -46376,6 +46476,7 @@ var CliProviderInstance = class _CliProviderInstance {
46376
46476
  this.completedDebouncePending = null;
46377
46477
  }
46378
46478
  if (!this.generatingStartedAt) this.generatingStartedAt = now;
46479
+ this.lastCompletionSummary = null;
46379
46480
  this.busyEpoch++;
46380
46481
  if (this.generatingDebounceTimer) clearTimeout(this.generatingDebounceTimer);
46381
46482
  this.generatingDebouncePending = { chatTitle, timestamp: now };
@@ -51512,10 +51613,24 @@ function resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instan
51512
51613
  const brainRoot2 = path34.join(agyRoot, "brain");
51513
51614
  if (fs26.existsSync(brainRoot2)) {
51514
51615
  const cutoff = spawnAwareCutoff(sessionStartedAtMs);
51515
- 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);
51516
- for (const e of entries) {
51517
- const t = path34.join(e.p, ".system_generated", "logs", "transcript.jsonl");
51518
- if (fs26.existsSync(t) && safeSize(t) > 0) {
51616
+ const nonEmptyBrain = (uuid, p) => {
51617
+ const t = path34.join(p, ".system_generated", "logs", "transcript.jsonl");
51618
+ return fs26.existsSync(t) && safeSize(t) > 0 ? t : null;
51619
+ };
51620
+ const all = fs26.readdirSync(brainRoot2, { withFileTypes: true }).filter((e) => e.isDirectory() && isUuidLikeSessionId2(e.name)).filter((e) => !isAntigravityConversationClaimedByOther(e.name, owner)).map((e) => {
51621
+ const p = path34.join(brainRoot2, e.name);
51622
+ return { uuid: e.name, p, mtime: safeMtime(p), birth: safeBirthtime(p) };
51623
+ }).filter((e) => e.mtime >= cutoff);
51624
+ let ordered = [];
51625
+ if (sessionStartedAtMs > 0) {
51626
+ const floor = sessionStartedAtMs - AGY_SPAWN_CLAIM_GRACE_MS;
51627
+ ordered = all.filter((e) => (e.birth > 0 ? e.birth : e.mtime) >= floor).sort((a, b) => (a.birth || a.mtime) - (b.birth || b.mtime));
51628
+ } else {
51629
+ ordered = [...all].sort((a, b) => b.mtime - a.mtime);
51630
+ }
51631
+ for (const e of ordered) {
51632
+ const t = nonEmptyBrain(e.uuid, e.p);
51633
+ if (t) {
51519
51634
  if (owner) claimAntigravityConversation(e.uuid, owner);
51520
51635
  return t;
51521
51636
  }
@@ -68788,7 +68903,11 @@ var SessionRegistry = class {
68788
68903
  byInstanceKey = /* @__PURE__ */ new Map();
68789
68904
  byParentSessionId = /* @__PURE__ */ new Map();
68790
68905
  register(target) {
68906
+ const priorProviderSessionId = this.bySessionId.get(target.sessionId)?.providerSessionId;
68791
68907
  this.unregister(target.sessionId);
68908
+ if (priorProviderSessionId && !target.providerSessionId) {
68909
+ target = { ...target, providerSessionId: priorProviderSessionId };
68910
+ }
68792
68911
  this.bySessionId.set(target.sessionId, target);
68793
68912
  if (target.cdpManagerKey) this.addIndex(this.byManagerKey, target.cdpManagerKey, target.sessionId);
68794
68913
  if (target.instanceKey) this.addIndex(this.byInstanceKey, target.instanceKey, target.sessionId);
@@ -68798,6 +68917,22 @@ var SessionRegistry = class {
68798
68917
  if (!sessionId) return void 0;
68799
68918
  return this.bySessionId.get(sessionId);
68800
68919
  }
68920
+ /**
68921
+ * Record the authoritative provider-native conversation id for a session
68922
+ * (SSOT). Idempotent; a no-op when the session is unknown or the value is
68923
+ * empty or unchanged. Never overwrites a known binding with an empty one.
68924
+ * Returns whether the stored value changed.
68925
+ */
68926
+ setProviderSessionId(sessionId, providerSessionId) {
68927
+ const sid = typeof sessionId === "string" ? sessionId.trim() : "";
68928
+ const value = typeof providerSessionId === "string" ? providerSessionId.trim() : "";
68929
+ if (!sid || !value) return false;
68930
+ const target = this.bySessionId.get(sid);
68931
+ if (!target) return false;
68932
+ if (target.providerSessionId === value) return false;
68933
+ target.providerSessionId = value;
68934
+ return true;
68935
+ }
68801
68936
  unregister(sessionId) {
68802
68937
  if (!sessionId) return;
68803
68938
  const target = this.bySessionId.get(sessionId);