fix(model-catalog): strip manifest model-id prefixes by the matched l… · openclaw/openclaw@e33760c
parveshsaini
·
2026-06-23
·
via Recent Commits to openclaw:main
File tree
packages/model-catalog-core/src
| Original file line number | Diff line number | Diff line change |
|---|
@@ -89,3 +89,34 @@ describe("provider model id policy normalization", () => {
|
89 | 89 | ); |
90 | 90 | }); |
91 | 91 | }); |
| 92 | + |
| 93 | +describe("manifest stripPrefixes matches and slices on the same normalized value", () => { |
| 94 | +function stripWith(stripPrefixes: string[], modelId: string): string { |
| 95 | +const policies = collectManifestModelIdNormalizationPolicies([ |
| 96 | +{ |
| 97 | +modelIdNormalization: { |
| 98 | +providers: { |
| 99 | +openai: { stripPrefixes }, |
| 100 | +}, |
| 101 | +}, |
| 102 | +}, |
| 103 | +]); |
| 104 | +return normalizeStaticProviderModelIdWithPolicies("openai", modelId, policies); |
| 105 | +} |
| 106 | + |
| 107 | +it("strips a whitespace-free prefix exactly (control: no regression)", () => { |
| 108 | +expect(stripWith(["openai/"], "openai/gpt-4")).toBe("gpt-4"); |
| 109 | +}); |
| 110 | + |
| 111 | +it("strips by the matched length when the manifest prefix has a leading space", () => { |
| 112 | +expect(stripWith([" openai/"], "openai/gpt-4")).toBe("gpt-4"); |
| 113 | +}); |
| 114 | + |
| 115 | +it("strips by the matched length when the manifest prefix has a trailing space", () => { |
| 116 | +expect(stripWith(["openai/ "], "openai/gpt-4")).toBe("gpt-4"); |
| 117 | +}); |
| 118 | + |
| 119 | +it("strips by the matched length when the manifest prefix differs in case and spacing", () => { |
| 120 | +expect(stripWith([" OpenAI/ "], "openai/gpt-4")).toBe("gpt-4"); |
| 121 | +}); |
| 122 | +}); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -98,7 +98,7 @@ export function normalizeProviderModelIdWithPolicies(params: {
|
98 | 98 | for (const prefix of policy.stripPrefixes ?? []) { |
99 | 99 | const normalizedPrefix = normalizeLowercaseStringOrEmpty(prefix); |
100 | 100 | if (normalizedPrefix && normalizeLowercaseStringOrEmpty(modelId).startsWith(normalizedPrefix)) { |
101 | | -modelId = modelId.slice(prefix.length); |
| 101 | +modelId = modelId.slice(normalizedPrefix.length); |
102 | 102 | break; |
103 | 103 | } |
104 | 104 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。