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

推荐订阅源

S
SegmentFault 最新的问题
G
Google Developers Blog
H
Help Net Security
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog RSS Feed
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 三生石上(FineUI控件)
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
GbyAI
GbyAI
D
Docker
Hugging Face - Blog
Hugging Face - Blog
I
InfoQ
博客园 - 司徒正美
Last Week in AI
Last Week in AI
Microsoft Security Blog
Microsoft Security Blog
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence

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(providers): harden model catalog response schemas · o...
vincentkoc · 2026-05-16 · via Recent Commits to openclaw:main

@@ -1,3 +1,4 @@

1+

import { readProviderJsonArrayFieldResponse } from "openclaw/plugin-sdk/provider-http";

12

import type { ModelDefinitionConfig } from "openclaw/plugin-sdk/provider-model-shared";

23

import { createSubsystemLogger } from "openclaw/plugin-sdk/runtime-env";

34

import {

@@ -70,10 +71,6 @@ interface GatewayModelEntry {

7071

supported_parameters?: string[];

7172

}

727373-

interface GatewayModelsResponse {

74-

data: GatewayModelEntry[];

75-

}

76-7774

function toPricePerMillion(perToken: string | undefined): number {

7875

if (!perToken) {

7976

return 0;

@@ -133,6 +130,30 @@ function buildStaticCatalog(): ModelDefinitionConfig[] {

133130

}));

134131

}

135132133+

function asGatewayModelEntry(value: unknown): GatewayModelEntry {

134+

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

135+

throw new Error("Kilocode model list: malformed JSON response");

136+

}

137+

const entry = value as Partial<GatewayModelEntry>;

138+

if (

139+

typeof entry.id !== "string" ||

140+

typeof entry.pricing !== "object" ||

141+

entry.pricing === null ||

142+

Array.isArray(entry.pricing)

143+

) {

144+

throw new Error("Kilocode model list: malformed JSON response");

145+

}

146+

return value as GatewayModelEntry;

147+

}

148+149+

function readGatewayModelId(value: unknown): string {

150+

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

151+

return "";

152+

}

153+

const id = (value as Partial<GatewayModelEntry>).id;

154+

return typeof id === "string" ? id.trim() : "";

155+

}

156+136157

export async function discoverKilocodeModels(): Promise<ModelDefinitionConfig[]> {

137158

if (process.env.NODE_ENV === "test" || process.env.VITEST) {

138159

return buildStaticCatalog();

@@ -154,24 +175,26 @@ export async function discoverKilocodeModels(): Promise<ModelDefinitionConfig[]>

154175

return buildStaticCatalog();

155176

}

156177157-

const data = (await response.json()) as GatewayModelsResponse;

158-

if (!Array.isArray(data.data) || data.data.length === 0) {

178+

const data = await readProviderJsonArrayFieldResponse(

179+

response,

180+

"Kilocode model list",

181+

"data",

182+

);

183+

if (data.length === 0) {

159184

log.warn("No models found from gateway API, using static catalog");

160185

return buildStaticCatalog();

161186

}

162187163188

const models: ModelDefinitionConfig[] = [];

164189

const discoveredIds = new Set<string>();

165190166-

for (const entry of data.data) {

167-

if (!entry || typeof entry !== "object") {

168-

continue;

169-

}

170-

const id = typeof entry.id === "string" ? entry.id.trim() : "";

171-

if (!id || discoveredIds.has(id)) {

172-

continue;

173-

}

191+

for (const rawEntry of data) {

192+

const id = readGatewayModelId(rawEntry);

174193

try {

194+

const entry = asGatewayModelEntry(rawEntry);

195+

if (!id || discoveredIds.has(id)) {

196+

continue;

197+

}

175198

models.push(toModelDefinition(entry));

176199

discoveredIds.add(id);

177200

} catch (e) {