惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
V
Visual Studio Blog
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
B
Blog
I
InfoQ
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志
F
Fortinet All Blogs
H
Help Net Security
博客园 - Franky
宝玉的分享
宝玉的分享
博客园 - 司徒正美
C
Check Point Blog
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Jina AI
Jina AI
T
The Blog of Author Tim Ferriss
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
A
About on SuperTechFans
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
refactor: extract ACP translator session updates · opencl...
steipete · 2026-06-01 · via Recent Commits to openclaw:main
1+

import type {

2+

AgentSideConnection,

3+

AvailableCommand,

4+

PromptRequest,

5+

SessionUpdate,

6+

} from "@agentclientprotocol/sdk";

7+

import type { AcpEventLedger, AcpEventLedgerReplay } from "./event-ledger.js";

8+9+

export type AcpTranslatorSessionRef = {

10+

sessionId: string;

11+

sessionKey: string;

12+

ledgerSessionId?: string;

13+

};

14+15+

type AcpTranslatorLedgerSessionRef = AcpTranslatorSessionRef & {

16+

cwd: string;

17+

};

18+19+

type AcpTranslatorSessionUpdatesOptions = {

20+

connection: Pick<AgentSideConnection, "sessionUpdate">;

21+

eventLedger: AcpEventLedger;

22+

getAvailableCommands: () => Promise<AvailableCommand[]>;

23+

log: (message: string) => void;

24+

};

25+26+

function resolveLedgerSessionId(session: { sessionId: string; ledgerSessionId?: string }): string {

27+

return session.ledgerSessionId ?? session.sessionId;

28+

}

29+30+

export class AcpTranslatorSessionUpdates {

31+

constructor(private options: AcpTranslatorSessionUpdatesOptions) {}

32+33+

async startLedgerSession(

34+

session: AcpTranslatorLedgerSessionRef,

35+

options: { complete: boolean; reset?: boolean },

36+

): Promise<void> {

37+

try {

38+

await this.options.eventLedger.startSession({

39+

sessionId: resolveLedgerSessionId(session),

40+

sessionKey: session.sessionKey,

41+

cwd: session.cwd,

42+

complete: options.complete,

43+

...(options.reset ? { reset: true } : {}),

44+

});

45+

} catch (err) {

46+

this.options.log(

47+

`event ledger session start failed for ${session.sessionId}: ${String(err)}`,

48+

);

49+

}

50+

}

51+52+

async readLedgerReplay(params: {

53+

sessionId: string;

54+

sessionKey: string;

55+

}): Promise<AcpEventLedgerReplay> {

56+

try {

57+

return await this.options.eventLedger.readReplay(params);

58+

} catch (err) {

59+

this.options.log(`event ledger replay fallback for ${params.sessionId}: ${String(err)}`);

60+

return { complete: false, events: [] };

61+

}

62+

}

63+64+

async readLedgerReplayBySessionId(sessionId: string): Promise<AcpEventLedgerReplay> {

65+

try {

66+

return await this.options.eventLedger.readReplayBySessionId({ sessionId });

67+

} catch (err) {

68+

this.options.log(`event ledger exact replay fallback for ${sessionId}: ${String(err)}`);

69+

return { complete: false, events: [] };

70+

}

71+

}

72+73+

async readLedgerReplayBySessionKey(sessionKey: string): Promise<AcpEventLedgerReplay> {

74+

try {

75+

return await this.options.eventLedger.readReplayBySessionKey({ sessionKey });

76+

} catch (err) {

77+

this.options.log(

78+

`event ledger session-key replay fallback for ${sessionKey}: ${String(err)}`,

79+

);

80+

return { complete: false, events: [] };

81+

}

82+

}

83+84+

async recordUserPrompt(

85+

session: AcpTranslatorSessionRef,

86+

runId: string,

87+

prompt: PromptRequest["prompt"],

88+

): Promise<void> {

89+

try {

90+

await this.options.eventLedger.recordUserPrompt({

91+

sessionId: resolveLedgerSessionId(session),

92+

sessionKey: session.sessionKey,

93+

runId,

94+

prompt,

95+

});

96+

} catch (err) {

97+

this.options.log(

98+

`event ledger prompt record failed for ${session.sessionId}: ${String(err)}`,

99+

);

100+

await this.markLedgerIncomplete(session);

101+

}

102+

}

103+104+

async emit(params: {

105+

sessionId: string;

106+

sessionKey?: string;

107+

ledgerSessionId?: string;

108+

runId?: string;

109+

update: SessionUpdate;

110+

record?: boolean;

111+

}): Promise<void> {

112+

await this.options.connection.sessionUpdate({

113+

sessionId: params.sessionId,

114+

update: params.update,

115+

});

116+

if (params.record && params.sessionKey) {

117+

await this.recordLedgerUpdate({

118+

sessionId: params.sessionId,

119+

sessionKey: params.sessionKey,

120+

...(params.ledgerSessionId ? { ledgerSessionId: params.ledgerSessionId } : {}),

121+

...(params.runId ? { runId: params.runId } : {}),

122+

update: params.update,

123+

});

124+

}

125+

}

126+127+

async sendAvailableCommands(

128+

session: AcpTranslatorSessionRef,

129+

options: { record: boolean },

130+

): Promise<void> {

131+

await this.emit({

132+

sessionId: session.sessionId,

133+

sessionKey: session.sessionKey,

134+

...(session.ledgerSessionId ? { ledgerSessionId: session.ledgerSessionId } : {}),

135+

record: options.record,

136+

update: {

137+

sessionUpdate: "available_commands_update",

138+

availableCommands: await this.options.getAvailableCommands(),

139+

},

140+

});

141+

}

142+143+

private async recordLedgerUpdate(params: {

144+

sessionId: string;

145+

sessionKey: string;

146+

ledgerSessionId?: string;

147+

runId?: string;

148+

update: SessionUpdate;

149+

}): Promise<void> {

150+

try {

151+

await this.options.eventLedger.recordUpdate({

152+

sessionId: params.ledgerSessionId ?? params.sessionId,

153+

sessionKey: params.sessionKey,

154+

...(params.runId ? { runId: params.runId } : {}),

155+

update: params.update,

156+

});

157+

} catch (err) {

158+

this.options.log(`event ledger update record failed for ${params.sessionId}: ${String(err)}`);

159+

await this.markLedgerIncomplete({

160+

sessionId: params.sessionId,

161+

sessionKey: params.sessionKey,

162+

...(params.ledgerSessionId ? { ledgerSessionId: params.ledgerSessionId } : {}),

163+

});

164+

}

165+

}

166+167+

private async markLedgerIncomplete(session: AcpTranslatorSessionRef): Promise<void> {

168+

try {

169+

await this.options.eventLedger.markIncomplete({

170+

sessionId: resolveLedgerSessionId(session),

171+

sessionKey: session.sessionKey,

172+

});

173+

} catch (err) {

174+

this.options.log(

175+

`event ledger incomplete mark failed for ${session.sessionId}: ${String(err)}`,

176+

);

177+

}

178+

}

179+

}