mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:20:43 +00:00
refactor: share model allowlist entry helper
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
9ea6b1d14500054ef8ce6fae3b08a4f2e401fa2aa5e48056dcdfa94bf330c3fb plugin-sdk-api-baseline.json
|
||||
e3f04797748cb35e1f10d6451d206744fdc188cdbc0251aad01211b94087f565 plugin-sdk-api-baseline.jsonl
|
||||
d4f327b3e09b0ac0a6fa3a96ee8042f8cd3197c1204270d2566abec6bf851876 plugin-sdk-api-baseline.json
|
||||
d7544ea5d45f90526bba0e4501e4f5728d43a1f42b2ea7f39cbd18330e0229ef plugin-sdk-api-baseline.jsonl
|
||||
|
||||
41
src/agents/model-allowlist-entry.ts
Normal file
41
src/agents/model-allowlist-entry.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import { DEFAULT_PROVIDER } from "./defaults.js";
|
||||
import { resolveStaticAllowlistModelKey } from "./model-ref-shared.js";
|
||||
|
||||
export function ensureStaticModelAllowlistEntry(params: {
|
||||
cfg: OpenClawConfig;
|
||||
modelRef: string;
|
||||
defaultProvider?: string;
|
||||
}): OpenClawConfig {
|
||||
const rawModelRef = params.modelRef.trim();
|
||||
if (!rawModelRef) {
|
||||
return params.cfg;
|
||||
}
|
||||
|
||||
const models = { ...params.cfg.agents?.defaults?.models };
|
||||
const keySet = new Set<string>([rawModelRef]);
|
||||
const canonicalKey = resolveStaticAllowlistModelKey(
|
||||
rawModelRef,
|
||||
params.defaultProvider ?? DEFAULT_PROVIDER,
|
||||
);
|
||||
if (canonicalKey) {
|
||||
keySet.add(canonicalKey);
|
||||
}
|
||||
|
||||
for (const key of keySet) {
|
||||
models[key] = {
|
||||
...models[key],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...params.cfg,
|
||||
agents: {
|
||||
...params.cfg.agents,
|
||||
defaults: {
|
||||
...params.cfg.agents?.defaults,
|
||||
models,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
// Keep provider onboarding helpers dependency-light so bundled provider plugins
|
||||
// do not pull heavyweight runtime graphs at activation time.
|
||||
|
||||
import { DEFAULT_PROVIDER } from "../agents/defaults.js";
|
||||
import { resolveStaticAllowlistModelKey } from "../agents/model-ref-shared.js";
|
||||
import { ensureStaticModelAllowlistEntry } from "../agents/model-allowlist-entry.js";
|
||||
import { findNormalizedProviderKey } from "../agents/provider-id.js";
|
||||
import type { AgentModelEntryConfig } from "../config/types.agent-defaults.js";
|
||||
import type {
|
||||
@@ -453,35 +452,5 @@ export function ensureModelAllowlistEntry(params: {
|
||||
modelRef: string;
|
||||
defaultProvider?: string;
|
||||
}): OpenClawConfig {
|
||||
const rawModelRef = params.modelRef.trim();
|
||||
if (!rawModelRef) {
|
||||
return params.cfg;
|
||||
}
|
||||
|
||||
const models = { ...params.cfg.agents?.defaults?.models };
|
||||
const keySet = new Set<string>([rawModelRef]);
|
||||
const canonicalKey = resolveStaticAllowlistModelKey(
|
||||
rawModelRef,
|
||||
params.defaultProvider ?? DEFAULT_PROVIDER,
|
||||
);
|
||||
if (canonicalKey) {
|
||||
keySet.add(canonicalKey);
|
||||
}
|
||||
|
||||
for (const key of keySet) {
|
||||
models[key] = {
|
||||
...models[key],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...params.cfg,
|
||||
agents: {
|
||||
...params.cfg.agents,
|
||||
defaults: {
|
||||
...params.cfg.agents?.defaults,
|
||||
models,
|
||||
},
|
||||
},
|
||||
};
|
||||
return ensureStaticModelAllowlistEntry(params);
|
||||
}
|
||||
|
||||
@@ -1,41 +1 @@
|
||||
import { DEFAULT_PROVIDER } from "../agents/defaults.js";
|
||||
import { resolveAllowlistModelKey } from "../agents/model-allowlist-ref.js";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
|
||||
export function ensureModelAllowlistEntry(params: {
|
||||
cfg: OpenClawConfig;
|
||||
modelRef: string;
|
||||
defaultProvider?: string;
|
||||
}): OpenClawConfig {
|
||||
const rawModelRef = params.modelRef.trim();
|
||||
if (!rawModelRef) {
|
||||
return params.cfg;
|
||||
}
|
||||
|
||||
const models = { ...params.cfg.agents?.defaults?.models };
|
||||
const keySet = new Set<string>([rawModelRef]);
|
||||
const canonicalKey = resolveAllowlistModelKey(
|
||||
rawModelRef,
|
||||
params.defaultProvider ?? DEFAULT_PROVIDER,
|
||||
);
|
||||
if (canonicalKey) {
|
||||
keySet.add(canonicalKey);
|
||||
}
|
||||
|
||||
for (const key of keySet) {
|
||||
models[key] = {
|
||||
...models[key],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...params.cfg,
|
||||
agents: {
|
||||
...params.cfg.agents,
|
||||
defaults: {
|
||||
...params.cfg.agents?.defaults,
|
||||
models,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
export { ensureStaticModelAllowlistEntry as ensureModelAllowlistEntry } from "../agents/model-allowlist-entry.js";
|
||||
|
||||
Reference in New Issue
Block a user