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

推荐订阅源

The Cloudflare Blog
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tailwind CSS Blog
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
博客园 - 司徒正美
V
Visual Studio Blog
G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客
aimingoo的专栏
aimingoo的专栏
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
S
SegmentFault 最新的问题
T
The Blog of Author Tim Ferriss
D
Docker
Vercel News
Vercel News
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
爱范儿
爱范儿
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏

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 oauth auth-result config patches · opencla...
steipete · 2026-05-12 · via Recent Commits to openclaw:main

@@ -1,9 +1,122 @@

11

import { buildAuthProfileId } from "../agents/auth-profiles/identity.js";

22

import type { AuthProfileCredential } from "../agents/auth-profiles/types.js";

3-

import { normalizeAgentModelRefForConfig } from "../config/model-input.js";

3+

import { normalizeConfiguredProviderCatalogModelId } from "../agents/model-ref-shared.js";

4+

import {

5+

normalizeAgentModelMapForConfig,

6+

normalizeAgentModelRefForConfig,

7+

} from "../config/model-input.js";

8+

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

49

import type { OpenClawConfig } from "../config/types.openclaw.js";

510

import type { ProviderAuthResult } from "../plugins/types.js";

61112+

function normalizeAgentModelConfigForAuthResult(value: unknown): unknown {

13+

if (typeof value === "string") {

14+

return normalizeAgentModelRefForConfig(value);

15+

}

16+

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

17+

return value;

18+

}

19+20+

let mutated = false;

21+

const next: Record<string, unknown> = { ...(value as Record<string, unknown>) };

22+

if (typeof next.primary === "string") {

23+

const primary = normalizeAgentModelRefForConfig(next.primary);

24+

if (primary !== next.primary) {

25+

next.primary = primary;

26+

mutated = true;

27+

}

28+

}

29+

if (Array.isArray(next.fallbacks)) {

30+

const originalFallbacks = next.fallbacks;

31+

const fallbacks = originalFallbacks.map((fallback) =>

32+

typeof fallback === "string" ? normalizeAgentModelRefForConfig(fallback) : fallback,

33+

);

34+

if (fallbacks.some((fallback, index) => fallback !== originalFallbacks[index])) {

35+

next.fallbacks = fallbacks;

36+

mutated = true;

37+

}

38+

}

39+

return mutated ? next : value;

40+

}

41+42+

function normalizeProviderConfigModelIdsForAuthResult(

43+

provider: string,

44+

providerConfig: ModelProviderConfig,

45+

): ModelProviderConfig {

46+

const models = providerConfig.models;

47+

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

48+

return providerConfig;

49+

}

50+51+

let mutated = false;

52+

const nextModels = models.map((model) => {

53+

const id = normalizeConfiguredProviderCatalogModelId(provider, model.id);

54+

if (id === model.id) {

55+

return model;

56+

}

57+

mutated = true;

58+

return Object.assign({}, model, { id });

59+

});

60+

return mutated ? { ...providerConfig, models: nextModels } : providerConfig;

61+

}

62+63+

function normalizeProviderAuthConfigPatchModelRefs(

64+

patch: Partial<OpenClawConfig>,

65+

): Partial<OpenClawConfig> {

66+

let next = patch;

67+

const defaults = patch.agents?.defaults;

68+

if (defaults) {

69+

let nextDefaults = defaults;

70+

if (defaults.model !== undefined) {

71+

const model = normalizeAgentModelConfigForAuthResult(defaults.model);

72+

if (model !== defaults.model) {

73+

nextDefaults = { ...nextDefaults, model: model as typeof defaults.model };

74+

}

75+

}

76+

if (defaults.models) {

77+

const models = normalizeAgentModelMapForConfig(defaults.models);

78+

if (models !== defaults.models) {

79+

nextDefaults = { ...nextDefaults, models };

80+

}

81+

}

82+

if (nextDefaults !== defaults) {

83+

next = {

84+

...next,

85+

agents: {

86+

...next.agents,

87+

defaults: nextDefaults,

88+

},

89+

};

90+

}

91+

}

92+93+

const providers = patch.models?.providers;

94+

if (!providers) {

95+

return next;

96+

}

97+98+

let mutated = false;

99+

const nextProviders = { ...providers };

100+

for (const [provider, providerConfig] of Object.entries(providers)) {

101+

const normalized = normalizeProviderConfigModelIdsForAuthResult(provider, providerConfig);

102+

if (normalized === providerConfig) {

103+

continue;

104+

}

105+

nextProviders[provider] = normalized;

106+

mutated = true;

107+

}

108+109+

return mutated

110+

? {

111+

...next,

112+

models: {

113+

...next.models,

114+

providers: nextProviders,

115+

},

116+

}

117+

: next;

118+

}

119+7120

/** Build the standard auth result payload for OAuth-style provider login flows. */

8121

export function buildOauthProviderAuthResult(params: {

9122

providerId: string;

@@ -41,17 +154,18 @@ export function buildOauthProviderAuthResult(params: {

4115442155

return {

43156

profiles: [{ profileId, credential }],

44-

configPatch:

157+

configPatch: normalizeProviderAuthConfigPatchModelRefs(

45158

params.configPatch ??

46-

({

47-

agents: {

48-

defaults: {

49-

models: {

50-

[defaultModel]: {},

159+

({

160+

agents: {

161+

defaults: {

162+

models: {

163+

[defaultModel]: {},

164+

},

51165

},

52166

},

53-

},

54-

} as Partial<OpenClawConfig>),

167+

} as Partial<OpenClawConfig>),

168+

),

55169

defaultModel,

56170

notes: params.notes,

57171

};