mirror of https://github.com/openclaw/openclaw.git
refactor(models): share model selection normalizer
This commit is contained in:
parent
2475353fdc
commit
881b73dcd9
|
|
@ -146,6 +146,22 @@ export function parseModelRef(raw: string, defaultProvider: string): ModelRef |
|
|||
return normalizeModelRef(providerRaw, model);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { normalizeAgentId, parseAgentSessionKey } from "../routing/session-key.j
|
|||
import { normalizeDeliveryContext } from "../utils/delivery-context.js";
|
||||
import { resolveAgentConfig } from "./agent-scope.js";
|
||||
import { AGENT_LANE_SUBAGENT } from "./lanes.js";
|
||||
import { resolveDefaultModelForAgent } from "./model-selection.js";
|
||||
import { normalizeModelSelection, resolveDefaultModelForAgent } from "./model-selection.js";
|
||||
import { buildSubagentSystemPrompt } from "./subagent-announce.js";
|
||||
import { getSubagentDepthFromSessionStore } from "./subagent-depth.js";
|
||||
import { countActiveRunsForSession, registerSubagentRun } from "./subagent-registry.js";
|
||||
|
|
@ -67,21 +67,6 @@ export function splitModelRef(ref?: string) {
|
|||
return { provider: undefined, model: trimmed };
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
export async function spawnSubagentDirect(
|
||||
params: SpawnSubagentParams,
|
||||
ctx: SpawnSubagentContext,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
import { randomUUID } from "node:crypto";
|
||||
import { resolveAgentConfig, resolveDefaultAgentId } from "../agents/agent-scope.js";
|
||||
import type { ModelCatalogEntry } from "../agents/model-catalog.js";
|
||||
import { resolveAllowedModelRef, resolveDefaultModelForAgent } from "../agents/model-selection.js";
|
||||
import {
|
||||
normalizeModelSelection,
|
||||
resolveAllowedModelRef,
|
||||
resolveDefaultModelForAgent,
|
||||
} from "../agents/model-selection.js";
|
||||
import { normalizeGroupActivation } from "../auto-reply/group-activation.js";
|
||||
import {
|
||||
formatThinkingLevels,
|
||||
|
|
@ -58,22 +62,6 @@ function normalizeExecAsk(raw: string): "off" | "on-miss" | "always" | undefined
|
|||
return undefined;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
function resolveSubagentModelHint(cfg: OpenClawConfig, agentId: string): string | undefined {
|
||||
const agentConfig = resolveAgentConfig(cfg, agentId);
|
||||
return (
|
||||
|
|
|
|||
Loading…
Reference in New Issue