openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
593 lines (592 loc) • 22.8 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { D as parseStrictPositiveInteger } from "./number-coercion-D6u-4YD8.mjs";
import { r as normalizeProviderId } from "./provider-id-b5XGSf9C.mjs";
import { a as resolveAgentDir, f as resolveAgentWorkspaceDir, x as resolveSessionAgentId } from "./agent-scope-config-DmXgFGKP.mjs";
import { t as resolveDefaultAgentWorkspaceDir } from "./workspace-default-path-CWX4WiCH.mjs";
import "./agent-scope-BwB8YH6y.mjs";
import { i as listCliRuntimeModelBackendBindings } from "./cli-backends-B8PrIwPC.mjs";
import { i as buildModelAliasIndex, o as dedupeModelCatalogEntries, p as resolveBareModelDefaultProvider, t as LEGACY_MODEL_POLICY_ALLOW_CONFIG_PATH, y as resolveModelRefFromString } from "./model-selection-shared-9Kz63Hhm.mjs";
import { l as resolveModelCatalogIdentityKey } from "./model-catalog-entry-pfJ-_t4l.mjs";
import { n as resolveDefaultModelForAgent } from "./model-selection-config-Bvf5WqHo.mjs";
import { t as warnPluginSdkDeprecation } from "./sdk-deprecation-D5N9acnu.mjs";
import { t as getChannelPlugin } from "./registry-ByqVE5S3.mjs";
import "./plugins-BoMiRtiY.mjs";
import { p as formatProviderLoginCommand } from "./oauth-refresh-failure-DxrQiYzV.mjs";
import { n as prepareOperatorModelPolicy } from "./operator-model-policy-BoEHyFtN.mjs";
import { n as createModelVisibilityPolicy } from "./model-visibility-policy-CH4gPfvH.mjs";
import "./model-selection-C2A4Wyix.mjs";
import { l as resolveCliRuntimeTwinRoute, o as isRetiredModelPickerProvider, s as omitCliRuntimeAliasTwins } from "./model-runtime-aliases-DZy9Ea2c.mjs";
import { c as getPreparedModelRuntimeAuthStore } from "./prepared-model-runtime-auth-DVZroiat.mjs";
import { r as PreparedModelRuntimePublicationSupersededError, t as PreparedModelRuntimeOwnerNotPublishedError } from "./prepared-model-runtime-admission-errors-LxrcCg4d.mjs";
import "./prepared-model-runtime.errors-BRsU9-dm.mjs";
import "./workspace-DLlXz3VE.mjs";
import { c as loadPublishedPreparedModelCatalogOwnerSnapshot } from "./prepared-model-catalog-DSktrHGK.mjs";
import { n as commandReply, r as defineAuthorizedTextCommand } from "./command-gates-BZ-IYgiD.mjs";
import { n as resolveAgentRuntimeLabel } from "./agent-runtime-label-DOflqA_I.mjs";
import { i as normalizeRuntimeChoiceId, o as resolveRuntimeNormalization } from "./model-runtime-normalization-p5MbS203.mjs";
import { t as resolveCatalogDecisionRuntime } from "./model-catalog-decision-runtime-BNbeEaZO.mjs";
import { n as prepareModelCatalogDecisions, t as createModelCatalogDecisions } from "./model-catalog-decisions-DRtCsJb_.mjs";
import { n as resolveLogicalModelCatalogEntryState, r as resolveLogicalVisibleModelCatalog } from "./model-catalog-visibility-BtMLU5pm.mjs";
import { o as resolveProviderChannelLoginChoice } from "./provider-login-options-DZ4vdFqU.mjs";
import { n as resolveModelRuntimeRoute, t as CLAUDE_CLI_SETUP_GUIDANCE } from "./model-runtime-route-BV9eIh4b.mjs";
import { n as resolveModelAuthLabelAsync, t as resolveModelAuthLabel } from "./model-auth-label-B--cRmFA.mjs";
//#region src/auto-reply/reply/commands-models-menu.ts
const CUSTOM_MODEL_SETUP_GUIDANCE = "Set up this connection with the custom-provider guide: https://docs.openclaw.ai/concepts/model-providers/custom-providers";
const MODEL_PROVIDER_ROUTE_DETAILS = {
claudeCli: "Claude CLI runs through Claude Code using its native login or a selected saved account. An explicitly selected API-key account has separate API billing; CLI does not mean free or subscription-only.",
anthropicConfigured: "Anthropic models can use the API or Claude CLI. Check each model's route label and selected account: API-key usage is billed separately from a Claude subscription."
};
function buildModelsMenu(e) {
const t = new Map(e.modelNames);
const n = /* @__PURE__ */ new Map();
for (const [r, i] of e.byProvider) {
const a = /* @__PURE__ */ new Set();
const o = resolveModelRuntimeRoute(r);
if (o === "claudeCli" || o === "anthropicConfigured") a.add(MODEL_PROVIDER_ROUTE_DETAILS[o]);
let s = 0;
const c = e.loginProviders.has(r);
const l = formatProviderLoginCommand(r);
const u = e.pendingProviders?.includes(r) === true;
for (const n of i) {
const i = `${r}/${n}`;
const o = e.modelAvailability.get(i);
const d = resolveModelRuntimeRoute(r, o.runtimeId);
const f = d === "claudeCli" ? "Claude CLI" : d === "anthropicApi" ? "API" : "";
if (f) t.set(i, `${f} · ${e.modelNames.get(i) ?? n}`);
if (o.availability === true) {
s += 1;
continue;
}
let p;
let m;
if (o.runtimeAuth?.source === "native" && o.availability === void 0) {
p = u ? "Checking native agent" : "Connection not confirmed";
m = u ? "Run /models again when discovery finishes." : "Check the native app on the Gateway host, then run /models again.";
} else switch (o.unavailableReason) {
case "missing-auth":
p = "Sign-in needed";
m = d === "claudeCli" ? CLAUDE_CLI_SETUP_GUIDANCE : c ? `Connect with ${l}.` : CUSTOM_MODEL_SETUP_GUIDANCE;
break;
case "auth-failed":
p = "Sign-in failed";
m = c ? `Sign in again with ${l}.` : CUSTOM_MODEL_SETUP_GUIDANCE;
break;
case "cooldown":
p = "Temporarily unavailable";
m = "Try again later or choose another model.";
break;
default:
p = o.availability === false ? "Unavailable" : "Connection not confirmed";
m = o.availability === false ? "Run /models again or choose another model." : c ? `Connect with ${l}, or choose another model.` : CUSTOM_MODEL_SETUP_GUIDANCE;
}
t.set(i, `${p} — ${t.get(i) ?? n}`);
a.add(`${r}: ${p}. ${m}`);
}
n.set(r, {
available: s,
notice: [...a].join("\n")
});
}
return {
modelNames: t,
byProvider: n
};
}
//#endregion
//#region src/auto-reply/reply/commands-models-catalog.ts
/** Undefined is unknown; an empty list is an authoritative refusal. */
function getModelsRuntimeChoices(e, t, n) {
if (e.isCurrent?.() === false) return;
return n ? e.runtimeChoicesByModel?.get(`${normalizeProviderId(t)}/${n}`) : e.runtimeChoicesByProvider?.get(normalizeProviderId(t));
}
function buildPreparedModelsProviderData(e, t, n = {}) {
return loadModelsProviderData(e, t, n);
}
async function loadModelsProviderData(e, t, n, r) {
const i = await loadPublishedPreparedModelCatalogOwnerSnapshot({
config: e,
...t ? { agentId: t } : {},
...r ? { agentDir: r } : {},
...n.workspaceDir ? { workspaceDir: n.workspaceDir } : {},
readOnly: true
});
i.loadFullModelCatalog?.().catch(() => void 0);
const a = i.config;
const o = resolveRuntimeNormalization(a);
const s = resolveDefaultModelForAgent({
cfg: a,
agentId: t,
...o
});
const c = n.workspaceDir ?? (t ? resolveAgentWorkspaceDir(a, t) : void 0) ?? resolveDefaultAgentWorkspaceDir();
const l = new Set(listCliRuntimeModelBackendBindings().map((e) => normalizeProviderId(e.runtime)));
const u = i.modelCatalog;
const d = getPreparedModelRuntimeAuthStore(i);
const f = u.entries;
const p = createModelVisibilityPolicy({
cfg: a,
catalog: f,
defaultProvider: s.provider,
defaultModel: s,
agentId: t,
...o
});
if (!d) throw new Error("Model catalog owner omitted its auth store");
const m = {
cfg: a,
agentId: i.agentId ?? t ?? "main",
agentDir: i.agentDir,
workspaceDir: c,
snapshot: u,
metadataSnapshot: i.metadataSnapshot,
preparedAuthStore: d,
preparedRuntimeAuthModes: i.authModes,
pluginRegistry: i.pluginRegistry,
observationConfig: i.observationConfig,
isCurrent: i.isCurrent,
preferredProfileId: n.sessionEntry?.authProfileOverride,
pinnedProfileId: n.sessionEntry?.authProfileOverrideSource === "user" ? n.sessionEntry.authProfileOverride : void 0,
profileProvider: n.sessionEntry?.providerOverride ?? n.sessionEntry?.modelProvider,
runtimeOverride: n.sessionEntry?.agentRuntimeOverride
};
const h = await prepareModelCatalogDecisions(m);
const g = m.runtimeOverride && resolveModelRuntimeRoute(s.provider) ? createModelCatalogDecisions({
...m,
preparedPersonalCatalog: h.preparedPersonalCatalog,
runtimeOverride: void 0
}) : h;
const decisionsForEntry = (e) => normalizeProviderId(e.provider) === s.provider && e.id === s.model ? g : h;
const evaluateEntry = (e, t) => {
const n = decisionsForEntry(e);
return n.evaluateNative(e, n.evaluateEntry(e, t));
};
const _ = /* @__PURE__ */ new Set();
const v = /* @__PURE__ */ new Map();
const y = /* @__PURE__ */ new Map();
const recordModelAvailability = (e, r, o = e.provider) => {
const s = `${normalizeProviderId(o)}/${e.id}`;
const c = n.view === "all" ? void 0 : resolveCliRuntimeTwinRoute(e, {
config: a,
agentId: i.agentId ?? t ?? "main",
cliRuntimeBindings: h.cliRuntimeBindings
});
const l = resolveModelRuntimeRoute(o) || c && !c.alias ? resolveCatalogDecisionRuntime({
cfg: a,
agentId: i.agentId ?? t ?? "main",
entry: e,
evaluation: r,
pluginRegistry: i.pluginRegistry,
resolveOpenAIProviderRoutes: decisionsForEntry(e).resolveOpenAIProviderRoutes
}) : void 0;
if (c && (c.alias || r.availability === true)) y.set(s, {
twin: c,
runtime: l
});
else y.delete(s);
v.set(s, {
availability: r.availability,
unavailableReason: r.unavailableReason,
runtimeAuth: r.runtimeAuth,
runtimeId: resolveModelRuntimeRoute(o) ? l?.id : void 0
});
};
const b = n.view === "all" ? async () => true : async (e, t) => {
const n = f.find((n) => n.provider === e && n.id === t?.modelId);
if (!n) return false;
return evaluateEntry(n).availability === true;
};
const x = await resolveLogicalVisibleModelCatalog({
cfg: a,
metadataSnapshot: i.metadataSnapshot,
catalog: f,
defaultProvider: s.provider,
defaultModel: s,
selectedModel: s,
agentId: t,
workspaceDir: c,
view: n.view,
policy: p,
routeVariants: u.routeVariants,
evaluateEntry: async (e, t) => {
const r = evaluateEntry(e, t);
recordModelAvailability(e, r);
if (r.routeResolution?.kind === "incompatible") _.add(resolveModelCatalogIdentityKey(e));
return resolveLogicalModelCatalogEntryState({
evaluation: r,
authBacked: n.view === "all" || r.availability === true
});
}
});
const S = buildModelAliasIndex({
cfg: a,
defaultProvider: s.provider,
agentId: t,
...o
});
const C = n.view !== "all" && p.hasProviderWildcards;
const w = n.view === "all" || p.allowAny || p.allowConfigPath === "agents.defaults.models";
const T = /* @__PURE__ */ new Map();
const add = (e, t) => {
const n = normalizeProviderId(e);
if (isRetiredModelPickerProvider(n)) return;
if (C && !(w && l.has(n)) && !p.allows({
provider: n,
model: t
})) return;
const r = T.get(n) ?? /* @__PURE__ */ new Set();
r.add(t);
T.set(n, r);
};
const addRawModelRef = (e) => {
const n = normalizeOptionalString(e);
if (!n) return;
const r = !n.includes("/") ? resolveBareModelDefaultProvider({
cfg: a,
catalog: f,
model: n,
defaultProvider: s.provider,
agentId: t,
manifestPlugins: o.manifestPlugins
}) : s.provider;
const i = resolveModelRefFromString({
cfg: a,
agentId: t,
raw: n,
defaultProvider: r,
aliasIndex: S,
...o
});
if (!i) return;
if (_.has(resolveModelCatalogIdentityKey({
provider: i.ref.provider,
id: i.ref.model
}))) return;
add(i.ref.provider, i.ref.model);
};
for (const e of x) {
if (_.has(resolveModelCatalogIdentityKey(e))) continue;
add(e.provider, e.id);
}
for (const e of f) if (w && l.has(normalizeProviderId(e.provider)) && await b(e.provider, {
modelId: e.id,
api: e.api,
baseUrl: e.baseUrl
})) add(e.provider, e.id);
for (const e of p.exactModelRefs) addRawModelRef(e);
if (!_.has(resolveModelCatalogIdentityKey({
provider: s.provider,
id: s.model
}))) add(s.provider, s.model);
for (const e of [a.agents?.defaults?.model, a.agents?.defaults?.imageModel]) if (typeof e === "string") addRawModelRef(e);
else if (e) {
addRawModelRef(e.primary);
for (const t of e.fallbacks ?? []) addRawModelRef(t);
}
const E = h.snapshot.pendingProviders?.filter((e) => !isRetiredModelPickerProvider(e) && (n.view === "all" || p.allowAny || [...p.allowedKeys].some((t) => t.startsWith(`${e}/`))));
for (const e of E ?? []) if (!T.has(e)) T.set(e, /* @__PURE__ */ new Set());
const D = /* @__PURE__ */ new Map();
for (const e of [...f, ...x]) if (e.name && e.name !== e.id) D.set(`${normalizeProviderId(e.provider)}/${e.id}`, e.name);
const O = [...x, ...f];
const k = /* @__PURE__ */ new Map();
const A = /* @__PURE__ */ new Map();
for (const [e, t] of T) for (const n of t) {
const t = O.find((t) => normalizeProviderId(t.provider) === e && t.id === n);
const r = t ?? {
provider: e,
id: n,
name: n
};
const i = u.routeVariants.filter((e) => resolveModelCatalogIdentityKey(e) === resolveModelCatalogIdentityKey(r));
if (!v.has(`${e}/${n}`)) recordModelAvailability(r, evaluateEntry(r, i.length ? i : [r]), e);
if (!t) continue;
const o = decisionsForEntry(t).runtimeChoices(t, i.length ? i : [t]);
if (!o) continue;
const s = o.map((e) => {
const t = normalizeRuntimeChoiceId(e);
const n = resolveAgentRuntimeLabel({
config: a,
resolvedHarness: t
});
return {
id: t,
label: n,
description: t === "openclaw" ? "Use OpenClaw's built-in agent and tools." : `Use ${n} to run this model.`
};
});
A.set(`${e}/${n}`, s);
}
if (n.view !== "all") {
const e = [p, ...Object.values(a.gateway?.roles?.definitions ?? {}).flatMap(({ modelPolicy: e }) => prepareOperatorModelPolicy({
cfg: a,
policy: e,
manifestPlugins: i.metadataSnapshot
}) ?? [])];
const t = new Set(omitCliRuntimeAliasTwins([...T].flatMap(([e, t]) => [...t].map((t) => {
const n = y.get(`${e}/${t}`);
return {
row: {
provider: e,
id: t,
agentRuntime: n?.runtime
},
twin: n?.twin
};
})), e).map(({ provider: e, id: t }) => `${e}/${t}`));
for (const [e, n] of T) {
for (const r of n) if (!t.has(`${e}/${r}`)) {
n.delete(r);
A.delete(`${e}/${r}`);
}
if (n.size === 0 && !E?.includes(e)) T.delete(e);
}
}
for (const [e, t] of T) {
const n = /* @__PURE__ */ new Map();
for (const r of t) for (const t of A.get(`${e}/${r}`) ?? []) n.set(t.id, t);
k.set(e, [...n.values()]);
}
const j = [...T.keys()].toSorted();
const M = new Set(j.filter((e) => resolveProviderChannelLoginChoice(e, {
config: a,
workspaceDir: c,
metadataSnapshot: i.metadataSnapshot
}).status !== "unsupported"));
return {
byProvider: T,
pendingProviders: E,
providers: j,
resolvedDefault: s,
modelNames: D,
modelMenu: buildModelsMenu({
byProvider: T,
modelNames: D,
modelAvailability: v,
loginProviders: M,
pendingProviders: E
}),
refreshWarning: u.refreshFailed ? "Some models could not be refreshed. You can still choose from the available models." : void 0,
modelCatalog: dedupeModelCatalogEntries(O),
runtimeChoicesByProvider: k,
runtimeChoicesByModel: A,
isCurrent: h.isCurrent
};
}
//#endregion
//#region src/auto-reply/reply/commands-models.ts
const PAGE_SIZE_DEFAULT = 20;
const PAGE_SIZE_MAX = 100;
const MODELS_ADD_DEPRECATED_TEXT = "⚠️ /models add is deprecated. Use /models to browse providers and /model to switch models.";
const MODEL_PICKER_CHANGED_MESSAGE = "Available models changed. Open /models and choose again.";
function parseListArgs(e) {
const t = e[0];
let n = 1;
let r = PAGE_SIZE_DEFAULT;
let i = false;
for (const [t, a] of e.entries()) {
const e = a.toLowerCase();
if (t > 0 && (e === "all" || e === "--all")) {
i = true;
continue;
}
const o = e.startsWith("limit=") || e.startsWith("size=");
const s = parseStrictPositiveInteger(o || e.startsWith("page=") ? e.slice(e.indexOf("=") + 1) : e);
if (s !== void 0) {
if (o) r = Math.min(PAGE_SIZE_MAX, s);
else if (t > 0) n = s;
}
}
return {
action: "list",
provider: t ? normalizeProviderId(t) : void 0,
page: n,
pageSize: r,
all: i
};
}
function parseModelsArgs(e) {
const t = e.trim();
if (!t) return { action: "providers" };
const n = t.split(/\s+/g);
switch (n[0]?.toLowerCase()) {
case "providers": return { action: "providers" };
case "list": return parseListArgs(n.slice(1));
case "add": return { action: "add" };
default: return parseListArgs(n);
}
}
function formatProviderLabel(e, t) {
if (!t || t === "unknown") return e;
return `${e} · 🔑 ${t}`;
}
async function resolveProviderLabelAsync(e) {
return formatProviderLabel(e.provider, await resolveModelAuthLabelAsync(e));
}
/** @deprecated Use formatModelsAvailableHeaderAsync. Supported through 2026-12-31. Removal in the first January 2027 stable release. */
function formatModelsAvailableHeader(e) {
warnPluginSdkDeprecation({
family: "auth-profiles",
method: "formatModelsAvailableHeader",
replacement: "formatModelsAvailableHeaderAsync"
});
return formatModelsHeader(e, formatProviderLabel(e.provider, resolveModelAuthLabel(e)));
}
async function formatModelsAvailableHeaderAsync(e) {
return formatModelsHeader(e, await resolveProviderLabelAsync(e));
}
function formatModelsHeader(e, t) {
return [`Models (${t}) — ${e.availability && e.availability.available !== e.total ? `${e.availability.available} of ${e.total}` : String(e.total)} available`, e.availability?.notice].filter(Boolean).join("\n\n");
}
async function resolveModelsCommandReply(e) {
const t = e.commandBodyNormalized.trim();
if (!t.startsWith("/models")) return null;
const n = parseModelsArgs(t.replace(/^\/models\b/i, "").trim());
let r;
try {
r = await loadModelsProviderData(e.cfg, e.agentId, {
...n.action === "list" && n.all ? { view: "all" } : {},
workspaceDir: e.workspaceDir,
sessionEntry: e.sessionEntry
}, e.agentDir);
} catch (e) {
if (e instanceof PreparedModelRuntimeOwnerNotPublishedError) return { text: "Model catalog is not ready. Retry after Gateway startup or refresh finishes." };
if (e instanceof PreparedModelRuntimePublicationSupersededError) return { text: MODEL_PICKER_CHANGED_MESSAGE };
throw e;
}
const i = await buildModelsCommandReply(e, n, r);
return {
...i,
text: [r.refreshWarning, i.text].filter(Boolean).join("\n\n")
};
}
async function buildModelsCommandReply(e, t, n) {
const { byProvider: r, providers: i } = n;
const a = t.action === "list" && t.provider ? n.modelMenu?.byProvider.get(t.provider) : void 0;
const o = n.modelMenu?.modelNames ?? n.modelNames;
const s = t.action === "list" && t.provider ? a?.notice : [...n.modelMenu?.byProvider.values() ?? []].map((e) => e.notice).filter(Boolean).join("\n");
const c = n.pendingProviders?.filter((e) => t.action !== "list" || !t.provider || t.provider === e).map((e) => `${e}: checking models…`).join("\n");
const withAvailability = (e) => [
e,
s,
c
].filter(Boolean).join("\n\n");
const l = e.surface ? getChannelPlugin(e.surface) : null;
const u = i.map((e) => ({
id: e,
count: r.get(e)?.size ?? 0
}));
const providerMenuReply = (e) => {
const t = (e ? l?.commands?.buildModelsMenuChannelData?.({ providers: u }) : void 0) ?? l?.commands?.buildModelsProviderChannelData?.({ providers: u });
if (t) return {
text: withAvailability("Select a provider:"),
channelData: t
};
return { text: withAvailability([
"Providers:",
...i.map((e) => `- ${e} (${r.get(e)?.size ?? 0})`),
"",
"Use: /models <provider>",
"Switch: /model <provider/model>"
].join("\n")) };
};
if (t.action === "providers") return providerMenuReply(true);
if (t.action === "add") return { text: MODELS_ADD_DEPRECATED_TEXT };
const { provider: d, page: f, pageSize: p, all: m } = t;
if (!d) return providerMenuReply(false);
const h = r.get(d);
if (!h) return { text: [
`Unknown provider: ${d}`,
"",
"Available providers:",
...i.map((e) => `- ${e}`),
"",
"Use: /models <provider>"
].join("\n") };
const g = [...h];
const _ = g.length;
if (_ === 0) {
if (c) return { text: c };
return { text: [
`Models (${await resolveProviderLabelAsync({
...e,
provider: d
})}) — none`,
"",
"Browse: /models",
"Switch: /model <provider/model>"
].join("\n") };
}
const v = 8;
const y = Math.max(1, Math.ceil(_ / v));
const b = Math.max(1, Math.min(f, y));
const x = l?.commands?.buildModelsListChannelData?.({
provider: d,
models: g.toSorted(),
currentModel: e.currentModel,
currentPage: b,
totalPages: y,
pageSize: v,
modelNames: o
});
if (x) return {
text: await formatModelsAvailableHeaderAsync({
...e,
provider: d,
total: _,
availability: a
}),
channelData: x
};
const S = g.findIndex((t) => e.currentModel === `${d}/${t}`);
if (S > 0) g.unshift(...g.splice(S, 1));
const C = m ? _ : p;
const w = Math.ceil(_ / C);
const T = m ? 1 : Math.max(1, Math.min(f, w));
if (!m && f !== T) return { text: [
`Page out of range: ${f} (valid: 1-${w})`,
"",
`Try: /models list ${d} ${T}`,
`All: /models list ${d} all`
].join("\n") };
const E = (T - 1) * C;
const D = Math.min(_, E + C);
const O = g.slice(E, D);
const k = [`Models (${await resolveProviderLabelAsync({
...e,
provider: d
})}) — showing ${E + 1}-${D} of ${_} (page ${T}/${w})`];
for (const e of O) {
const t = `${d}/${e}`;
const r = o.get(t);
k.push(`- ${t}${r && r !== n.modelNames.get(t) ? ` (${r})` : ""}`);
}
k.push("", "Switch: /model <provider/model>");
if (!m && T < w) k.push(`More: /models list ${d} ${T + 1}`);
if (!m) k.push(`All: /models list ${d} all`);
return { text: withAvailability(k.join("\n")) };
}
const handleModelsCommand = defineAuthorizedTextCommand({
label: "/models",
match: (e) => e.trim().startsWith("/models") ? e.trim() : null
}, async (e, t) => {
if (parseModelsArgs(t.replace(/^\/models\b/i, "").trim()).action === "add") return commandReply(MODELS_ADD_DEPRECATED_TEXT);
const n = e.sessionKey ? resolveSessionAgentId({
sessionKey: e.sessionKey,
config: e.cfg
}) : e.agentId ?? "main";
const r = e.agentId ?? "main";
const i = n === r && e.agentDir ? e.agentDir : resolveAgentDir(e.cfg, n);
const a = e.sessionStore?.[e.sessionKey] ?? e.sessionEntry;
const o = await resolveModelsCommandReply({
cfg: e.cfg,
commandBodyNormalized: t,
surface: e.ctx.Surface,
currentModel: e.model ? `${e.provider}/${e.model}` : void 0,
agentId: n,
agentDir: i,
workspaceDir: a?.spawnedWorkspaceDir ?? (n === r ? e.workspaceDir : void 0),
sessionEntry: a
});
return o ? commandReply(o) : null;
});
//#endregion
export { resolveModelsCommandReply as a, handleModelsCommand as i, formatModelsAvailableHeader as n, buildPreparedModelsProviderData as o, formatModelsAvailableHeaderAsync as r, getModelsRuntimeChoices as s, MODEL_PICKER_CHANGED_MESSAGE as t };