openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
92 lines (91 loc) • 3.21 kB
JavaScript
import { v as normalizeUniqueTrimmedStringList } from "./string-normalization-DLmfYZXI.mjs";
import { l as isNonSecretApiKeyMarker } from "./model-auth-markers-4YSUG71a.mjs";
import "./string-coerce-runtime-BwAZZDf5.mjs";
import "./provider-auth-D_oAZ3fr.mjs";
import { _ as runLiveProviderCatalog } from "./provider-catalog-live-runtime-D-M7f_ww.mjs";
import { T as resolveLmstudioInferenceBase, V as LMSTUDIO_PROVIDER_ID, c as resolveLmstudioConfiguredApiKey, h as resolvePersistedLmstudioApiKey, j as LMSTUDIO_DEFAULT_API_KEY_ENV_VAR, m as resolveLmstudioProviderAuthMode, n as discoverLmstudioModels, o as LmstudioConfigResolutionError, p as hasLmstudioAuthorizationHeader, u as resolveLmstudioProviderHeaders } from "./models.fetch-DUbxqdcp.mjs";
//#region extensions/lmstudio/src/catalog.ts
async function discoverLmstudioProvider(e, t) {
if (e.providerIds && !e.providerIds.includes("lmstudio")) return null;
const n = e.config.models?.providers?.[LMSTUDIO_PROVIDER_ID];
const { headers: r, auth: i, apiKey: a, ...o } = n ?? {};
const { apiKey: s, discoveryApiKey: c, profileId: l } = e.resolveProviderApiKey(LMSTUDIO_PROVIDER_ID);
let u;
let d;
let f;
try {
u = await resolveLmstudioProviderHeaders({
config: e.config,
env: e.env,
headers: n?.headers
});
d = hasLmstudioAuthorizationHeader(u);
f = await resolveLmstudioConfiguredApiKey({
config: e.config,
env: e.env,
allowUnresolved: d || Boolean(c)
});
} catch (e) {
if (e instanceof LmstudioConfigResolutionError) return null;
throw e;
}
const p = d ? void 0 : c ?? f;
const m = s ?? n?.apiKey;
const h = resolveLmstudioInferenceBase(n?.baseUrl);
const g = !s && !n && !p;
const _ = !d && c && !isNonSecretApiKeyMarker(c) ? l : void 0;
const run = async () => {
let e;
const r = !t && n?.models?.length ? n.models : await discoverLmstudioModels({
onListedModels: (t) => {
e = {
baseUrl: h,
modelIds: normalizeUniqueTrimmedStringList(t.flatMap((e) => [e.key, ...e.loaded_instances?.map((e) => e?.id) ?? []])),
aliases: normalizeUniqueTrimmedStringList(t.flatMap((e) => e.key?.trim() ? [e.selected_variant, ...normalizeUniqueTrimmedStringList(e.variants)] : []))
};
},
baseUrl: h,
apiKey: p ?? "",
headers: u,
quiet: g,
...!g && t ? t : {}
});
const a = e ? [{
provider: LMSTUDIO_PROVIDER_ID,
profileId: _,
status: "ready",
modelIdCatalog: e
}] : void 0;
if (r.length === 0 && (t ? g : !s && !n?.apiKey)) return t && a ? {
providers: {},
outcomes: a
} : null;
const c = resolvePersistedLmstudioApiKey({
currentApiKey: m,
explicitAuth: i,
fallbackApiKey: LMSTUDIO_DEFAULT_API_KEY_ENV_VAR,
hasModels: r.length > 0,
hasAuthorizationHeader: d
});
const l = resolveLmstudioProviderAuthMode(c);
return {
...a ? { outcomes: a } : {},
provider: {
...o,
baseUrl: h,
api: n?.api ?? "openai-completions",
...u ? { headers: u } : {},
...c ? { apiKey: c } : {},
...l ? { auth: l } : {},
models: r
}
};
};
return t ? await runLiveProviderCatalog({
providerId: LMSTUDIO_PROVIDER_ID,
profileId: _,
run
}) : await run();
}
//#endregion
export { discoverLmstudioProvider as t };