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

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
B
Blog
腾讯CDC
P
Proofpoint News Feed
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
L
LangChain Blog
F
Fortinet All Blogs
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
T
Tailwind CSS 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
fix: normalize Xiaomi array tool schemas (#82575) · openc...
steipete · 2026-05-16 · via Recent Commits to openclaw:main

@@ -1,7 +1,10 @@

11

import type { TSchema } from "typebox";

22

import type { ModelCompatConfig } from "../config/types.models.js";

33

import { stripUnsupportedSchemaKeywords } from "../plugin-sdk/provider-tools.js";

4-

import { resolveUnsupportedToolSchemaKeywords } from "../plugins/provider-model-compat.js";

4+

import {

5+

resolveUnsupportedToolSchemaKeywords,

6+

shouldOmitEmptyArrayItems,

7+

} from "../plugins/provider-model-compat.js";

58

import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js";

69

import { cleanSchemaForGemini } from "./schema/clean-for-gemini.js";

710

@@ -224,6 +227,88 @@ function normalizeArraySchemasMissingItems(schema: unknown): unknown {

224227

return changed ? nextSchema : schema;

225228

}

226229230+

function schemaAllowsArrayType(schema: Record<string, unknown>): boolean {

231+

const type = schema.type;

232+

return type === "array" || (Array.isArray(type) && type.includes("array"));

233+

}

234+235+

const ARRAY_ITEMS_SCHEMA_OBJECT_KEYS = new Set([

236+

"additionalProperties",

237+

"contains",

238+

"else",

239+

"if",

240+

"items",

241+

"not",

242+

"propertyNames",

243+

"then",

244+

]);

245+246+

const ARRAY_ITEMS_SCHEMA_ARRAY_KEYS = new Set(["allOf", "anyOf", "oneOf", "prefixItems"]);

247+248+

const ARRAY_ITEMS_SCHEMA_MAP_KEYS = new Set([

249+

"$defs",

250+

"definitions",

251+

"dependentSchemas",

252+

"patternProperties",

253+

"properties",

254+

]);

255+256+

function stripEmptyArrayItemsFromArraySchemas(schema: unknown): unknown {

257+

if (Array.isArray(schema)) {

258+

let changed = false;

259+

const entries = schema.map((entry) => {

260+

const next = stripEmptyArrayItemsFromArraySchemas(entry);

261+

changed ||= next !== entry;

262+

return next;

263+

});

264+

return changed ? entries : schema;

265+

}

266+

if (!isSchemaRecord(schema)) {

267+

return schema;

268+

}

269+270+

let changed = false;

271+

const entries = Object.entries(schema).flatMap(([key, value]) => {

272+

if (

273+

key === "items" &&

274+

schemaAllowsArrayType(schema) &&

275+

isSchemaRecord(value) &&

276+

isTrulyEmptySchema(value)

277+

) {

278+

changed = true;

279+

return [];

280+

}

281+282+

if (ARRAY_ITEMS_SCHEMA_OBJECT_KEYS.has(key)) {

283+

const next = stripEmptyArrayItemsFromArraySchemas(value);

284+

changed ||= next !== value;

285+

return [[key, next] as const];

286+

}

287+288+

if (ARRAY_ITEMS_SCHEMA_ARRAY_KEYS.has(key) && Array.isArray(value)) {

289+

const next = stripEmptyArrayItemsFromArraySchemas(value);

290+

changed ||= next !== value;

291+

return [[key, next] as const];

292+

}

293+294+

if (ARRAY_ITEMS_SCHEMA_MAP_KEYS.has(key) && isSchemaRecord(value)) {

295+

let mapChanged = false;

296+

const next = Object.fromEntries(

297+

Object.entries(value).map(([entryKey, entryValue]) => {

298+

const entryNext = stripEmptyArrayItemsFromArraySchemas(entryValue);

299+

mapChanged ||= entryNext !== entryValue;

300+

return [entryKey, entryNext] as const;

301+

}),

302+

);

303+

changed ||= mapChanged;

304+

return [[key, mapChanged ? next : value] as const];

305+

}

306+307+

return [[key, value] as const];

308+

});

309+

return changed ? Object.fromEntries(entries) : schema;

310+

}

311+227312

export function normalizeToolParameterSchema(

228313

schema: unknown,

229314

options?: { modelProvider?: string; modelId?: string; modelCompat?: ModelCompatConfig },

@@ -247,16 +332,23 @@ export function normalizeToolParameterSchema(

247332

normalizedProvider.includes("google") || normalizedProvider.includes("gemini");

248333

const isAnthropicProvider = normalizedProvider.includes("anthropic");

249334

const unsupportedToolSchemaKeywords = resolveUnsupportedToolSchemaKeywords(options?.modelCompat);

335+

const omitEmptyArrayItems = shouldOmitEmptyArrayItems(options?.modelCompat);

250336251337

function applyProviderCleaning(s: unknown): TSchema {

252338

const normalizedSchema = normalizeArraySchemasMissingItems(s);

339+

const arrayItemsCompatibleSchema = omitEmptyArrayItems

340+

? stripEmptyArrayItemsFromArraySchemas(normalizedSchema)

341+

: normalizedSchema;

253342

if (isGeminiProvider && !isAnthropicProvider) {

254-

return cleanSchemaForGemini(normalizedSchema);

343+

return cleanSchemaForGemini(arrayItemsCompatibleSchema);

255344

}

256345

if (unsupportedToolSchemaKeywords.size > 0) {

257-

return stripUnsupportedSchemaKeywords(normalizedSchema, unsupportedToolSchemaKeywords) as TSchema;

346+

return stripUnsupportedSchemaKeywords(

347+

arrayItemsCompatibleSchema,

348+

unsupportedToolSchemaKeywords,

349+

) as TSchema;

258350

}

259-

return normalizedSchema as TSchema;

351+

return arrayItemsCompatibleSchema as TSchema;

260352

}

261353262354

const conditionalKey = getTopLevelConditionalKey(schemaRecord);