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

推荐订阅源

Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
博客园 - 司徒正美
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
罗磊的独立博客
IT之家
IT之家
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
MyScale Blog
MyScale Blog
J
Java Code Geeks
L
LangChain Blog
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
G
Google Developers Blog

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: share interactive payload normalizers · opencla...
steipete · 2026-04-24 · via Recent Commits to openclaw:main

@@ -46,17 +46,9 @@ export type MessagePresentationTone = "info" | "success" | "warning" | "danger"

46464747

export type MessagePresentationButtonStyle = InteractiveButtonStyle;

484849-

export type MessagePresentationButton = {

50-

label: string;

51-

value?: string;

52-

url?: string;

53-

style?: MessagePresentationButtonStyle;

54-

};

49+

export type MessagePresentationButton = InteractiveReplyButton;

555056-

export type MessagePresentationOption = {

57-

label: string;

58-

value: string;

59-

};

51+

export type MessagePresentationOption = InteractiveReplyOption;

60526153

export type MessagePresentationTextBlock = {

6254

type: "text";

@@ -124,11 +116,18 @@ function normalizePresentationTone(value: unknown): MessagePresentationTone | un

124116

: undefined;

125117

}

126118127-

function normalizeInteractiveButton(raw: unknown): InteractiveReplyButton | undefined {

119+

function toRecord(raw: unknown): Record<string, unknown> | undefined {

128120

if (!raw || typeof raw !== "object" || Array.isArray(raw)) {

129121

return undefined;

130122

}

131-

const record = raw as Record<string, unknown>;

123+

return raw as Record<string, unknown>;

124+

}

125+126+

function normalizeButton(raw: unknown): InteractiveReplyButton | undefined {

127+

const record = toRecord(raw);

128+

if (!record) {

129+

return undefined;

130+

}

132131

const label = normalizeOptionalString(record.label) ?? normalizeOptionalString(record.text);

133132

const value =

134133

normalizeOptionalString(record.value) ??

@@ -146,11 +145,11 @@ function normalizeInteractiveButton(raw: unknown): InteractiveReplyButton | unde

146145

};

147146

}

148147149-

function normalizeInteractiveOption(raw: unknown): InteractiveReplyOption | undefined {

150-

if (!raw || typeof raw !== "object" || Array.isArray(raw)) {

148+

function normalizeOption(raw: unknown): InteractiveReplyOption | undefined {

149+

const record = toRecord(raw);

150+

if (!record) {

151151

return undefined;

152152

}

153-

const record = raw as Record<string, unknown>;

154153

const label = normalizeOptionalString(record.label) ?? normalizeOptionalString(record.text);

155154

const value = normalizeOptionalString(record.value);

156155

if (!label || !value) {

@@ -159,30 +158,28 @@ function normalizeInteractiveOption(raw: unknown): InteractiveReplyOption | unde

159158

return { label, value };

160159

}

161160161+

function normalizeList<T>(value: unknown, normalizeEntry: (entry: unknown) => T | undefined): T[] {

162+

return Array.isArray(value)

163+

? value.map((entry) => normalizeEntry(entry)).filter((entry): entry is T => Boolean(entry))

164+

: [];

165+

}

166+162167

function normalizeInteractiveBlock(raw: unknown): InteractiveReplyBlock | undefined {

163-

if (!raw || typeof raw !== "object" || Array.isArray(raw)) {

168+

const record = toRecord(raw);

169+

if (!record) {

164170

return undefined;

165171

}

166-

const record = raw as Record<string, unknown>;

167172

const type = normalizeOptionalLowercaseString(record.type);

168173

if (type === "text") {

169174

const text = normalizeOptionalString(record.text);

170175

return text ? { type: "text", text } : undefined;

171176

}

172177

if (type === "buttons") {

173-

const buttons = Array.isArray(record.buttons)

174-

? record.buttons

175-

.map((entry) => normalizeInteractiveButton(entry))

176-

.filter((entry): entry is InteractiveReplyButton => Boolean(entry))

177-

: [];

178+

const buttons = normalizeList(record.buttons, normalizeButton);

178179

return buttons.length > 0 ? { type: "buttons", buttons } : undefined;

179180

}

180181

if (type === "select") {

181-

const options = Array.isArray(record.options)

182-

? record.options

183-

.map((entry) => normalizeInteractiveOption(entry))

184-

.filter((entry): entry is InteractiveReplyOption => Boolean(entry))

185-

: [];

182+

const options = normalizeList(record.options, normalizeOption);

186183

return options.length > 0

187184

? {

188185

type: "select",

@@ -195,50 +192,19 @@ function normalizeInteractiveBlock(raw: unknown): InteractiveReplyBlock | undefi

195192

}

196193197194

export function normalizeInteractiveReply(raw: unknown): InteractiveReply | undefined {

198-

if (!raw || typeof raw !== "object" || Array.isArray(raw)) {

195+

const record = toRecord(raw);

196+

if (!record) {

199197

return undefined;

200198

}

201-

const record = raw as Record<string, unknown>;

202-

const blocks = Array.isArray(record.blocks)

203-

? record.blocks

204-

.map((entry) => normalizeInteractiveBlock(entry))

205-

.filter((entry): entry is InteractiveReplyBlock => Boolean(entry))

206-

: [];

199+

const blocks = normalizeList(record.blocks, normalizeInteractiveBlock);

207200

return blocks.length > 0 ? { blocks } : undefined;

208201

}

209202210-

function normalizePresentationButton(raw: unknown): MessagePresentationButton | undefined {

211-

if (!raw || typeof raw !== "object" || Array.isArray(raw)) {

212-

return undefined;

213-

}

214-

const record = raw as Record<string, unknown>;

215-

const label = normalizeOptionalString(record.label) ?? normalizeOptionalString(record.text);

216-

const value =

217-

normalizeOptionalString(record.value) ??

218-

normalizeOptionalString(record.callbackData) ??

219-

normalizeOptionalString(record.callback_data);

220-

const url = normalizeOptionalString(record.url);

221-

if (!label || (!value && !url)) {

222-

return undefined;

223-

}

224-

return {

225-

label,

226-

...(value ? { value } : {}),

227-

...(url ? { url } : {}),

228-

style: normalizeButtonStyle(record.style),

229-

};

230-

}

231-232-

function normalizePresentationOption(raw: unknown): MessagePresentationOption | undefined {

233-

const option = normalizeInteractiveOption(raw);

234-

return option ? { label: option.label, value: option.value } : undefined;

235-

}

236-237203

function normalizePresentationBlock(raw: unknown): MessagePresentationBlock | undefined {

238-

if (!raw || typeof raw !== "object" || Array.isArray(raw)) {

204+

const record = toRecord(raw);

205+

if (!record) {

239206

return undefined;

240207

}

241-

const record = raw as Record<string, unknown>;

242208

const type = normalizeOptionalLowercaseString(record.type);

243209

if (type === "text" || type === "context") {

244210

const text = normalizeOptionalString(record.text);

@@ -248,19 +214,11 @@ function normalizePresentationBlock(raw: unknown): MessagePresentationBlock | un

248214

return { type: "divider" };

249215

}

250216

if (type === "buttons") {

251-

const buttons = Array.isArray(record.buttons)

252-

? record.buttons

253-

.map((entry) => normalizePresentationButton(entry))

254-

.filter((entry): entry is MessagePresentationButton => Boolean(entry))

255-

: [];

217+

const buttons = normalizeList(record.buttons, normalizeButton);

256218

return buttons.length > 0 ? { type: "buttons", buttons } : undefined;

257219

}

258220

if (type === "select") {

259-

const options = Array.isArray(record.options)

260-

? record.options

261-

.map((entry) => normalizePresentationOption(entry))

262-

.filter((entry): entry is MessagePresentationOption => Boolean(entry))

263-

: [];

221+

const options = normalizeList(record.options, normalizeOption);

264222

return options.length > 0

265223

? {

266224

type: "select",

@@ -273,15 +231,11 @@ function normalizePresentationBlock(raw: unknown): MessagePresentationBlock | un

273231

}

274232275233

export function normalizeMessagePresentation(raw: unknown): MessagePresentation | undefined {

276-

if (!raw || typeof raw !== "object" || Array.isArray(raw)) {

234+

const record = toRecord(raw);

235+

if (!record) {

277236

return undefined;

278237

}

279-

const record = raw as Record<string, unknown>;

280-

const blocks = Array.isArray(record.blocks)

281-

? record.blocks

282-

.map((entry) => normalizePresentationBlock(entry))

283-

.filter((entry): entry is MessagePresentationBlock => Boolean(entry))

284-

: [];

238+

const blocks = normalizeList(record.blocks, normalizePresentationBlock);

285239

const title = normalizeOptionalString(record.title);

286240

if (!title && blocks.length === 0) {

287241

return undefined;