mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 10:22:44 +00:00
fix(cron): respect subagents.model in isolated cron sessions (#11474)
* fix(cron): respect subagents.model in isolated cron sessions * fix(cron): enforce model allowlist for subagents.model * Cron: fix isolated subagent model gate regressions --------- Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -6,8 +6,9 @@ import {
|
||||
inferUniqueProviderFromConfiguredModels,
|
||||
parseModelRef,
|
||||
buildModelAliasIndex,
|
||||
modelKey,
|
||||
normalizeModelSelection,
|
||||
normalizeProviderId,
|
||||
modelKey,
|
||||
resolveAllowedModelRef,
|
||||
resolveConfiguredModelRef,
|
||||
resolveModelRefFromString,
|
||||
@@ -470,3 +471,31 @@ describe("model-selection", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("normalizeModelSelection", () => {
|
||||
it("returns trimmed string for string input", () => {
|
||||
expect(normalizeModelSelection("ollama/llama3.2:3b")).toBe("ollama/llama3.2:3b");
|
||||
});
|
||||
|
||||
it("returns undefined for empty/whitespace string", () => {
|
||||
expect(normalizeModelSelection("")).toBeUndefined();
|
||||
expect(normalizeModelSelection(" ")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("extracts primary from object", () => {
|
||||
expect(normalizeModelSelection({ primary: "google/gemini-2.5-flash" })).toBe(
|
||||
"google/gemini-2.5-flash",
|
||||
);
|
||||
});
|
||||
|
||||
it("returns undefined for object without primary", () => {
|
||||
expect(normalizeModelSelection({ fallbacks: ["a"] })).toBeUndefined();
|
||||
expect(normalizeModelSelection({})).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns undefined for null/undefined/number", () => {
|
||||
expect(normalizeModelSelection(undefined)).toBeUndefined();
|
||||
expect(normalizeModelSelection(null)).toBeUndefined();
|
||||
expect(normalizeModelSelection(42)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -208,22 +208,6 @@ export function inferUniqueProviderFromConfiguredModels(params: {
|
||||
return providers.values().next().value;
|
||||
}
|
||||
|
||||
export function normalizeModelSelection(value: unknown): string | undefined {
|
||||
if (typeof value === "string") {
|
||||
const trimmed = value.trim();
|
||||
return trimmed || undefined;
|
||||
}
|
||||
if (!value || typeof value !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
const primary = (value as { primary?: unknown }).primary;
|
||||
if (typeof primary === "string") {
|
||||
const trimmed = primary.trim();
|
||||
return trimmed || undefined;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function resolveAllowlistModelKey(raw: string, defaultProvider: string): string | null {
|
||||
const parsed = parseModelRef(raw, defaultProvider);
|
||||
if (!parsed) {
|
||||
@@ -612,3 +596,23 @@ export function resolveHooksGmailModel(params: {
|
||||
|
||||
return resolved?.ref ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a model selection value (string or `{primary?: string}`) to a
|
||||
* plain trimmed string. Returns `undefined` when the input is empty/missing.
|
||||
* Shared by sessions-spawn and cron isolated-agent model resolution.
|
||||
*/
|
||||
export function normalizeModelSelection(value: unknown): string | undefined {
|
||||
if (typeof value === "string") {
|
||||
const trimmed = value.trim();
|
||||
return trimmed || undefined;
|
||||
}
|
||||
if (!value || typeof value !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
const primary = (value as { primary?: unknown }).primary;
|
||||
if (typeof primary === "string" && primary.trim()) {
|
||||
return primary.trim();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user