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

推荐订阅源

AWS News Blog
AWS News Blog
Engineering at Meta
Engineering at Meta
T
Tailwind CSS Blog
博客园 - 【当耐特】
F
Fortinet All Blogs
博客园 - 司徒正美
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
Google DeepMind News
Google DeepMind News
博客园_首页
A
About on SuperTechFans
博客园 - 聂微东
N
Netflix TechBlog - Medium
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
GbyAI
GbyAI
O
OpenAI News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
S
Schneier on Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Apple Machine Learning Research
Apple Machine Learning Research
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Martin Fowler
Martin Fowler
J
Java Code Geeks
T
Tor Project blog
T
Threatpost
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Y
Y Combinator Blog
The Register - Security
The Register - Security
阮一峰的网络日志
阮一峰的网络日志
D
Docker
Vercel News
Vercel News
I
Intezer
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
P
Privacy International News Feed
Cyberwarzone
Cyberwarzone
Spread Privacy
Spread Privacy
N
News and Events Feed by Topic
N
News | PayPal Newsroom
The GitHub Blog
The GitHub Blog
U
Unit 42
WordPress大学
WordPress大学
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Simon Willison's Weblog
Simon Willison's Weblog

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 test: trim doctor command hotspots · openclaw/openclaw@c66f16a test: isolate agent auth and spawn hotspots · openclaw/openclaw@9285935 test: stabilize MCP startup disposal race · openclaw/openclaw@dd9d2eb test: merge browser contract server suites · openclaw/openclaw@5817a76 test: narrow ollama provider discovery setup · openclaw/openclaw@a0d9598 build: declare qa-lab aimock runtime dependency · openclaw/openclaw@24431e5 test: speed up safe-bins exec harness · openclaw/openclaw@ee856ab test: preserve tool helpers in embedded runner mocks · openclaw/openclaw@acd86a0 refactor: move memory embeddings into provider plugins · openclaw/openclaw@77e6e4c test: reuse system-run temp fixtures · openclaw/openclaw@7e9ff0f test: trim hotspot wait overhead · openclaw/openclaw@12a59b0 Check: avoid duplicate boundary prep · openclaw/openclaw@baf11b8 test: reduce hotspot fixture overhead · openclaw/openclaw@3a59edd feat(ui): overhaul settings and slash command UX (#67819) thanks @Bun… · openclaw/openclaw@2cfb660 QA Matrix: exit cleanly on failure · openclaw/openclaw@42805d2 QA Matrix: isolate scenario coverage · openclaw/openclaw@7e659e1 Matrix: refresh crypto bootstrap state · openclaw/openclaw@94081d8 QA Lab: add provider registry · openclaw/openclaw@bb7e982 Matrix: add plugin changelog · openclaw/openclaw@4acab55 test: trim more hotspot overhead · openclaw/openclaw@f485311 test: trim remaining hotspot tests · openclaw/openclaw@6ba8626 test: narrow hotspot mocks · openclaw/openclaw@dbc8179 test: isolate gemini embedding request helpers · openclaw/openclaw@cd330f5 test: trim memory and mcp hotspots · openclaw/openclaw@fd48dfa test: slim provider registry mocks · openclaw/openclaw@2e08c77 test: harden Parallels update smoke · openclaw/openclaw@1a98090 feat: default Anthropic to Opus 4.7 · openclaw/openclaw@628b454 fix: harden node-host shell payload mutability checks · openclaw/openclaw@75c551e fix: land node-host approval binding for native binaries (#66731) (th… · openclaw/openclaw@29919bb CI: add daily schedule to CodeQL workflow (#67645) · openclaw/openclaw@69d25f5 fix(gateway): capture config hash after plugin auto-enable to prevent… · openclaw/openclaw@8c11210 fix: repair sanitized replay tool results before send (#67620) (thank… · openclaw/openclaw@c3c7a99 fix: restrict HTML timeout short-circuit to transient statuses · openclaw/openclaw@de129a6 fix: keep TUI watchdog bound to active run (#67401) (thanks @xantorres) · openclaw/openclaw@3525273 Gateway/skills: dedupe skills prefix-match + drop dead fallback on log · openclaw/openclaw@d7f489f Extensions/lmstudio: back off inference preload after consecutive fai… · openclaw/openclaw@b555214 TUI/streaming: add watchdog that resets the activity indicator after … · openclaw/openclaw@f44ab20 Agents/tool-loop: enable unknown-tool stream guard by default · openclaw/openclaw@36ed367 Gateway/skills: invalidate session skills snapshot on config write · openclaw/openclaw@b23d59a fix: classify HTML provider error pages correctly (#67642) (thanks @s… · openclaw/openclaw@e588e90 fix(skills): remove unused model-usage import (#67641) · openclaw/openclaw@55f05df docs(changelog): credit codex fix superseded PRs · openclaw/openclaw@e485f24 fix(openai-codex): normalize stale transport metadata in resolution a… · openclaw/openclaw@90801ba CI: pin Docker-related GitHub Actions (#67632) · openclaw/openclaw@f697b01 Android: modernize WebView and discovery API usage (#67627) · openclaw/openclaw@44a6e50 fix(deps): bump hono to 4.12.14 and @hono/node-server to 1.19.14 (GHS… · openclaw/openclaw@fbccc18 fix(deps): bump dompurify to 3.4.0 (#67614) · openclaw/openclaw@2c2dc00 CI: add explicit permissions to all workflow jobs (fixes code-scannin… · openclaw/openclaw@01b7516 fix: register bundled TTS providers and route overrides correctly (#6… · openclaw/openclaw@6ea3cdd fix: align host tilde paths with OS home (#62804) (thanks @stainlu) · openclaw/openclaw@ecfaf64 fix: flush creds queue before reconnect socket open (#67464) (thanks … · openclaw/openclaw@405c63f fix: strip standalone <function> tool call tags from visible text (#6… · openclaw/openclaw@78df859 fix(agents): preserve cli session metadata before transcript persist … · openclaw/openclaw@898fd04 docs(changelog): move cli transcript entry · openclaw/openclaw@c1817c6 fix(agents): normalize cli transcript api field · openclaw/openclaw@3a3fae0 docs(changelog): note cli transcript persistence · openclaw/openclaw@6c343f1 fix(agents): persist cli transcript turns · openclaw/openclaw@b8ef507 fix(msteams): harden security-sensitive flows (#65841) · openclaw/openclaw@c56b56e [Dashboard] Fix exec approval modal overflow for long command content… · openclaw/openclaw@053c5b0 Docs: remove QA changelog entry · openclaw/openclaw@7fd5771 QA: fix private runtime source loading (#67428) · openclaw/openclaw@d5933af docs(gateway): correct protocol.md schema path, hello-ok example, aut… · openclaw/openclaw@489404d CI: pin Node 22 runners to 22.18.0 · openclaw/openclaw@4ffa621 models.authStatus: normalize provider ids + tighten env-backed escape… · openclaw/openclaw@f2fdb9d Update CHANGELOG.md · openclaw/openclaw@7694a92 test(parallels): clean up npm update guard jobs · openclaw/openclaw@045ea7b Plugins: prefer scanDir override paths · openclaw/openclaw@b2974da fix(dreaming): default storage.mode to "separate" so phase blocks sto… · openclaw/openclaw@8c392f0 fix(memory-core): skip dreaming transcript ingestion via session stor… · openclaw/openclaw@a1b01f0 fix: dedupe replayed exec.finished node events (#67281) · openclaw/openclaw@5dcf526
perf: slim reset model selection imports · openclaw/openclaw@28fc03c
steipete · 2026-04-24 · via Recent Commits to openclaw:main

@@ -0,0 +1,351 @@

1+

import { modelKey, normalizeProviderId } from "../../agents/model-selection-normalize.js";

2+

import {

3+

resolveModelRefFromString,

4+

type ModelAliasIndex,

5+

} from "../../agents/model-selection-shared.js";

6+

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

7+8+

export type ModelDirectiveSelection = {

9+

provider: string;

10+

model: string;

11+

isDefault: boolean;

12+

alias?: string;

13+

};

14+15+

const FUZZY_VARIANT_TOKENS = [

16+

"lightning",

17+

"preview",

18+

"mini",

19+

"fast",

20+

"turbo",

21+

"lite",

22+

"beta",

23+

"small",

24+

"nano",

25+

];

26+27+

function boundedLevenshteinDistance(a: string, b: string, maxDistance: number): number | null {

28+

if (a === b) {

29+

return 0;

30+

}

31+

if (!a || !b) {

32+

return null;

33+

}

34+

const aLen = a.length;

35+

const bLen = b.length;

36+

if (Math.abs(aLen - bLen) > maxDistance) {

37+

return null;

38+

}

39+40+

// Standard DP with early exit. O(maxDistance * minLen) in common cases.

41+

const prev = Array.from({ length: bLen + 1 }, (_, idx) => idx);

42+

const curr = Array.from({ length: bLen + 1 }, () => 0);

43+44+

for (let i = 1; i <= aLen; i++) {

45+

curr[0] = i;

46+

let rowMin = curr[0];

47+48+

const aChar = a.charCodeAt(i - 1);

49+

for (let j = 1; j <= bLen; j++) {

50+

const cost = aChar === b.charCodeAt(j - 1) ? 0 : 1;

51+

curr[j] = Math.min(prev[j] + 1, curr[j - 1] + 1, prev[j - 1] + cost);

52+

if (curr[j] < rowMin) {

53+

rowMin = curr[j];

54+

}

55+

}

56+57+

if (rowMin > maxDistance) {

58+

return null;

59+

}

60+61+

for (let j = 0; j <= bLen; j++) {

62+

prev[j] = curr[j] ?? 0;

63+

}

64+

}

65+66+

const dist = prev[bLen] ?? null;

67+

if (dist == null || dist > maxDistance) {

68+

return null;

69+

}

70+

return dist;

71+

}

72+73+

function scoreFuzzyMatch(params: {

74+

provider: string;

75+

model: string;

76+

fragment: string;

77+

aliasIndex: ModelAliasIndex;

78+

defaultProvider: string;

79+

defaultModel: string;

80+

}): {

81+

score: number;

82+

isDefault: boolean;

83+

variantCount: number;

84+

variantMatchCount: number;

85+

modelLength: number;

86+

key: string;

87+

} {

88+

const provider = normalizeProviderId(params.provider);

89+

const model = params.model;

90+

const fragment = normalizeLowercaseStringOrEmpty(params.fragment);

91+

const providerLower = normalizeLowercaseStringOrEmpty(provider);

92+

const modelLower = normalizeLowercaseStringOrEmpty(model);

93+

const haystack = `${providerLower}/${modelLower}`;

94+

const key = modelKey(provider, model);

95+96+

const scoreFragment = (

97+

value: string,

98+

weights: { exact: number; starts: number; includes: number },

99+

) => {

100+

if (!fragment) {

101+

return 0;

102+

}

103+

let score = 0;

104+

if (value === fragment) {

105+

score = Math.max(score, weights.exact);

106+

}

107+

if (value.startsWith(fragment)) {

108+

score = Math.max(score, weights.starts);

109+

}

110+

if (value.includes(fragment)) {

111+

score = Math.max(score, weights.includes);

112+

}

113+

return score;

114+

};

115+116+

let score = 0;

117+

score += scoreFragment(haystack, { exact: 220, starts: 140, includes: 110 });

118+

score += scoreFragment(providerLower, {

119+

exact: 180,

120+

starts: 120,

121+

includes: 90,

122+

});

123+

score += scoreFragment(modelLower, {

124+

exact: 160,

125+

starts: 110,

126+

includes: 80,

127+

});

128+129+

// Best-effort typo tolerance for common near-misses like "claud" vs "claude".

130+

// Bounded to keep this cheap across large model sets.

131+

const distModel = boundedLevenshteinDistance(fragment, modelLower, 3);

132+

if (distModel != null) {

133+

score += (3 - distModel) * 70;

134+

}

135+136+

const aliases = params.aliasIndex.byKey.get(key) ?? [];

137+

for (const alias of aliases) {

138+

score += scoreFragment(normalizeLowercaseStringOrEmpty(alias), {

139+

exact: 140,

140+

starts: 90,

141+

includes: 60,

142+

});

143+

}

144+145+

if (modelLower.startsWith(providerLower)) {

146+

score += 30;

147+

}

148+149+

const fragmentVariants = FUZZY_VARIANT_TOKENS.filter((token) => fragment.includes(token));

150+

const modelVariants = FUZZY_VARIANT_TOKENS.filter((token) => modelLower.includes(token));

151+

const variantMatchCount = fragmentVariants.filter((token) => modelLower.includes(token)).length;

152+

const variantCount = modelVariants.length;

153+

if (fragmentVariants.length === 0 && variantCount > 0) {

154+

score -= variantCount * 30;

155+

} else if (fragmentVariants.length > 0) {

156+

if (variantMatchCount > 0) {

157+

score += variantMatchCount * 40;

158+

}

159+

if (variantMatchCount === 0) {

160+

score -= 20;

161+

}

162+

}

163+164+

const defaultProvider = normalizeProviderId(params.defaultProvider);

165+

const isDefault = provider === defaultProvider && model === params.defaultModel;

166+

if (isDefault) {

167+

score += 20;

168+

}

169+170+

return {

171+

score,

172+

isDefault,

173+

variantCount,

174+

variantMatchCount,

175+

modelLength: modelLower.length,

176+

key,

177+

};

178+

}

179+180+

export function resolveModelDirectiveSelection(params: {

181+

raw: string;

182+

defaultProvider: string;

183+

defaultModel: string;

184+

aliasIndex: ModelAliasIndex;

185+

allowedModelKeys: Set<string>;

186+

}): { selection?: ModelDirectiveSelection; error?: string } {

187+

const { raw, defaultProvider, defaultModel, aliasIndex, allowedModelKeys } = params;

188+189+

const rawTrimmed = raw.trim();

190+

const rawLower = normalizeLowercaseStringOrEmpty(rawTrimmed);

191+192+

const pickAliasForKey = (provider: string, model: string): string | undefined =>

193+

aliasIndex.byKey.get(modelKey(provider, model))?.[0];

194+195+

const buildSelection = (provider: string, model: string): ModelDirectiveSelection => {

196+

const alias = pickAliasForKey(provider, model);

197+

return {

198+

provider,

199+

model,

200+

isDefault: provider === defaultProvider && model === defaultModel,

201+

...(alias ? { alias } : undefined),

202+

};

203+

};

204+205+

const resolveFuzzy = (params: {

206+

provider?: string;

207+

fragment: string;

208+

}): { selection?: ModelDirectiveSelection; error?: string } => {

209+

const fragment = normalizeLowercaseStringOrEmpty(params.fragment);

210+

if (!fragment) {

211+

return {};

212+

}

213+214+

const providerFilter = params.provider ? normalizeProviderId(params.provider) : undefined;

215+216+

const candidates: Array<{ provider: string; model: string }> = [];

217+

for (const key of allowedModelKeys) {

218+

const slash = key.indexOf("/");

219+

if (slash <= 0) {

220+

continue;

221+

}

222+

const provider = normalizeProviderId(key.slice(0, slash));

223+

const model = key.slice(slash + 1);

224+

if (providerFilter && provider !== providerFilter) {

225+

continue;

226+

}

227+

candidates.push({ provider, model });

228+

}

229+230+

// Also allow partial alias matches when the user didn't specify a provider.

231+

if (!params.provider) {

232+

const aliasMatches: Array<{ provider: string; model: string }> = [];

233+

for (const [aliasKey, entry] of aliasIndex.byAlias.entries()) {

234+

if (!aliasKey.includes(fragment)) {

235+

continue;

236+

}

237+

aliasMatches.push({

238+

provider: entry.ref.provider,

239+

model: entry.ref.model,

240+

});

241+

}

242+

for (const match of aliasMatches) {

243+

const key = modelKey(match.provider, match.model);

244+

if (!allowedModelKeys.has(key)) {

245+

continue;

246+

}

247+

if (!candidates.some((c) => c.provider === match.provider && c.model === match.model)) {

248+

candidates.push(match);

249+

}

250+

}

251+

}

252+253+

if (candidates.length === 0) {

254+

return {};

255+

}

256+257+

const scored = candidates

258+

.map((candidate) => {

259+

const details = scoreFuzzyMatch({

260+

provider: candidate.provider,

261+

model: candidate.model,

262+

fragment,

263+

aliasIndex,

264+

defaultProvider,

265+

defaultModel,

266+

});

267+

return Object.assign({ candidate }, details);

268+

})

269+

.toSorted((a, b) => {

270+

if (b.score !== a.score) {

271+

return b.score - a.score;

272+

}

273+

if (a.isDefault !== b.isDefault) {

274+

return a.isDefault ? -1 : 1;

275+

}

276+

if (a.variantMatchCount !== b.variantMatchCount) {

277+

return b.variantMatchCount - a.variantMatchCount;

278+

}

279+

if (a.variantCount !== b.variantCount) {

280+

return a.variantCount - b.variantCount;

281+

}

282+

if (a.modelLength !== b.modelLength) {

283+

return a.modelLength - b.modelLength;

284+

}

285+

return a.key.localeCompare(b.key);

286+

});

287+288+

const bestScored = scored[0];

289+

const best = bestScored?.candidate;

290+

if (!best || !bestScored) {

291+

return {};

292+

}

293+294+

const minScore = providerFilter ? 90 : 120;

295+

if (bestScored.score < minScore) {

296+

return {};

297+

}

298+299+

return { selection: buildSelection(best.provider, best.model) };

300+

};

301+302+

const resolved = resolveModelRefFromString({

303+

raw: rawTrimmed,

304+

defaultProvider,

305+

aliasIndex,

306+

});

307+308+

if (!resolved) {

309+

const fuzzy = resolveFuzzy({ fragment: rawTrimmed });

310+

if (fuzzy.selection || fuzzy.error) {

311+

return fuzzy;

312+

}

313+

return {

314+

error: `Unrecognized model "${rawTrimmed}". Use /models to list providers, or /models <provider> to list models.`,

315+

};

316+

}

317+318+

const resolvedKey = modelKey(resolved.ref.provider, resolved.ref.model);

319+

if (allowedModelKeys.size === 0 || allowedModelKeys.has(resolvedKey)) {

320+

return {

321+

selection: {

322+

provider: resolved.ref.provider,

323+

model: resolved.ref.model,

324+

isDefault: resolved.ref.provider === defaultProvider && resolved.ref.model === defaultModel,

325+

alias: resolved.alias,

326+

},

327+

};

328+

}

329+330+

// If the user specified a provider/model but the exact model isn't allowed,

331+

// attempt a fuzzy match within that provider.

332+

if (rawLower.includes("/")) {

333+

const slash = rawTrimmed.indexOf("/");

334+

const provider = normalizeProviderId(rawTrimmed.slice(0, slash).trim());

335+

const fragment = rawTrimmed.slice(slash + 1).trim();

336+

const fuzzy = resolveFuzzy({ provider, fragment });

337+

if (fuzzy.selection || fuzzy.error) {

338+

return fuzzy;

339+

}

340+

}

341+342+

// Otherwise, try fuzzy matching across allowlisted models.

343+

const fuzzy = resolveFuzzy({ fragment: rawTrimmed });

344+

if (fuzzy.selection || fuzzy.error) {

345+

return fuzzy;

346+

}

347+348+

return {

349+

error: `Model "${resolved.ref.provider}/${resolved.ref.model}" is not allowed. Use /models to list providers, or /models <provider> to list models.`,

350+

};

351+

}