refactor: simplify cross-session messaging

This commit is contained in:
chengyongru authored and chengyongru committed 2026-08-19 01:15:56 +08:00
1 parent 0e184965e8
commit 251a1ccd40
78 files changed
+1578 -7569

No files matched your search

+4 -20
View File
@@ -5,7 +5,6 @@ import type {
OutboundCliAppMention,
OutboundMcpPresetMention,
OutboundMedia,
SessionHandle,
SessionMention,
SidebarStatePayload,
GoalStateWsPayload,
@@ -196,7 +195,7 @@ export class NanobotClient {
private knownChats = new Set<string>();
/** Temporary chats are connection-owned and intentionally not reattached. */
private temporaryChatIds = new Set<string>();
/** Per-chat run projection, started optimistically and reconciled by lifecycle events. */
/** Wall-clock run strip: updated from ``goal_status`` even with no ``onChat`` subscriber. */
private runStartedAtByChatId = new Map<string, number>();
/** Per-turn clocks let a rejected newer turn fall back without borrowing its timer. */
private runStartedAtByTurnKey = new Map<string, number>();
@@ -538,14 +537,6 @@ export class NanobotClient {
}
}
private startRunLocally(chatId: string, turnId: string): void {
const startedAt = Date.now() / 1000;
this.runStartedAtByTurnKey.set(this.runSendKey(chatId, turnId), startedAt);
const previous = this.runStartedAtByChatId.get(chatId);
this.runStartedAtByChatId.set(chatId, startedAt);
if (previous !== startedAt) this.emitRunStatus(chatId, startedAt);
}
private settleRunTurn(chatId: string, turnId?: string): void {
if (!turnId) return;
this.clearPendingMessageSend(chatId, turnId);
@@ -725,7 +716,7 @@ export class NanobotClient {
}
}
private recordRunStatus(chatId: string, ev: InboundEvent): void {
private recordGoalStatusForRunStrip(chatId: string, ev: InboundEvent): void {
if (ev.event === "turn_end") {
this.recordRunCompletion(chatId, ev.turn_id);
return;
@@ -976,7 +967,6 @@ export class NanobotClient {
cliApps?: OutboundCliAppMention[];
mcpPresets?: OutboundMcpPresetMention[];
sessionMentions?: SessionMention[];
sessionHandles?: SessionHandle[];
quotedContext?: string;
workspaceScope?: WorkspaceScopePayload | null;
turnId?: string;
@@ -996,9 +986,6 @@ export class NanobotClient {
...(options?.sessionMentions?.length
? { session_mentions: options.sessionMentions }
: {}),
...(options?.sessionHandles?.length
? { session_handles: options.sessionHandles }
: {}),
...(options?.quotedContext?.trim() ? { quoted_context: options.quotedContext.trim() } : {}),
...(options?.workspaceScope ? { workspace_scope: options.workspaceScope } : {}),
...(options?.turnId ? { turn_id: options.turnId } : {}),
@@ -1017,10 +1004,7 @@ export class NanobotClient {
}
if (options?.turnId && !isSystemCommandTurnId(options.turnId)) {
const startsNewRun = options.startsNewRun !== false;
if (startsNewRun) {
this.advanceRunGeneration(chatId, options.turnId);
this.startRunLocally(chatId, options.turnId);
}
if (startsNewRun) this.advanceRunGeneration(chatId, options.turnId);
this.trackPendingMessageSend(chatId, options.turnId, startsNewRun);
}
this.queueSend(frame);
@@ -1256,7 +1240,7 @@ export class NanobotClient {
if (chatId) {
if (this.isCanonicalCompletedTurnEvent(chatId, parsed)) return;
const supersededRunCompletion = this.isSupersededRunCompletion(chatId, parsed);
this.recordRunStatus(chatId, parsed);
this.recordGoalStatusForRunStrip(chatId, parsed);
if (supersededRunCompletion) return;
this.recordGoalStateSnapshot(chatId, parsed);
this.dispatch(chatId, parsed);