Files
openclaw/src/auto-reply/model.ts
Vincent Koc aa27e27f36 fix(models): normalize provider runtime selection (#71259)
* fix(models): normalize provider runtime selection

* fix(models): reverse codex-only runtime migration

* fix(models): default runtime selection to pi

* fix(status): label model runtime clearly

* fix(status): align pi runtime label

* fix(plugins): align tool result middleware runtime naming

* fix(models): validate runtime overrides
2026-04-24 16:56:49 -07:00

55 lines
1.4 KiB
TypeScript

import { splitTrailingAuthProfile } from "../agents/model-ref-profile.js";
import { escapeRegExp } from "../utils.js";
export function extractModelDirective(
body?: string,
options?: { aliases?: string[] },
): {
cleaned: string;
rawModel?: string;
rawProfile?: string;
rawRuntime?: string;
hasDirective: boolean;
} {
if (!body) {
return { cleaned: "", hasDirective: false };
}
const modelMatch = body.match(
/(?:^|\s)\/model(?=$|\s|:)\s*:?\s*([A-Za-z0-9_.:@-]+(?:\/[A-Za-z0-9_.:@-]+)*)?(?:\s+(?:--runtime|runtime=|harness=)\s*([A-Za-z0-9_.:-]+))?/i,
);
const aliases = (options?.aliases ?? []).map((alias) => alias.trim()).filter(Boolean);
const aliasMatch =
modelMatch || aliases.length === 0
? null
: body.match(
new RegExp(
`(?:^|\\s)\\/(${aliases.map(escapeRegExp).join("|")})(?=$|\\s|:)(?:\\s*:\\s*)?`,
"i",
),
);
const match = modelMatch ?? aliasMatch;
const raw = modelMatch ? modelMatch?.[1]?.trim() : aliasMatch?.[1]?.trim();
const rawRuntime = modelMatch?.[2]?.trim();
let rawModel = raw;
let rawProfile: string | undefined;
if (raw) {
const split = splitTrailingAuthProfile(raw);
rawModel = split.model;
rawProfile = split.profile;
}
const cleaned = match ? body.replace(match[0], " ").replace(/\s+/g, " ").trim() : body.trim();
return {
cleaned,
rawModel,
rawProfile,
rawRuntime,
hasDirective: !!match,
};
}