openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
99 lines (98 loc) • 3.36 kB
JavaScript
import { n as getCachedLiveCatalogValue } from "./provider-live-catalog-cache-BIG8VvFH.mjs";
import { _ as runLiveProviderCatalog, g as LiveModelCatalogHttpError } from "./provider-catalog-live-runtime-D-M7f_ww.mjs";
import "./provider-catalog-shared-ZRbc_4xZ.mjs";
import { a as resolveGithubCopilotDomain } from "./domain-CmrCAfb-.mjs";
import { t as buildCopilotRuntimeHeaders } from "./runtime-identity-BCYAo2Tm.mjs";
import { a as resolveCopilotForwardCompatModel, i as isCopilotCatalogModelVisible, n as PROVIDER_ID, r as fetchCopilotModelCatalog } from "./models-BjkArA0g.mjs";
import { t as resolveFirstGithubToken } from "./auth-BSnFFp-T.mjs";
import { t as CopilotRuntimeAuthError } from "./runtime-auth-error-CKTqd5Gw.mjs";
//#region extensions/github-copilot/dynamic-models.ts
function dynamicModelScope(e, t) {
const n = e?.trim();
return n ? `profile:${n}` : t ? `direct:${t}` : "unscoped";
}
function createGithubCopilotDynamicModelHooks() {
const e = /* @__PURE__ */ new WeakMap();
async function loadCatalog(e, t, n) {
const { resolveCopilotRuntimeAuth: r } = await import("./extensions/github-copilot/register.runtime.js");
const { apiKey: i, baseUrl: a } = await r({
githubToken: t.githubToken,
env: e.env,
githubDomain: resolveGithubCopilotDomain({
env: e.env,
explicit: t.githubDomain,
config: e.config
})
}).catch((e) => {
if (e instanceof CopilotRuntimeAuthError && e.status !== void 0) throw new LiveModelCatalogHttpError(PROVIDER_ID, e.status);
throw e;
});
return {
baseUrl: a,
models: await getCachedLiveCatalogValue({
keyParts: [
PROVIDER_ID,
"models",
a,
i,
n["Copilot-Integration-Id"]
],
load: async () => await fetchCopilotModelCatalog({
copilotApiToken: i,
baseUrl: a,
headers: n
})
})
};
}
async function runCatalog(e) {
const t = await resolveFirstGithubToken(e);
if (!t.githubToken) return null;
const n = buildCopilotRuntimeHeaders({ config: e.config });
return await runLiveProviderCatalog({
providerId: PROVIDER_ID,
profileId: t.profileId,
run: async () => {
const r = await loadCatalog(e, t, n);
return { provider: {
...r,
models: r.models.filter(isCopilotCatalogModelVisible)
} };
}
});
}
async function prepareDynamicModel(t) {
const n = {
agentDir: t.agentDir,
env: process.env,
config: t.config,
profileId: t.authProfileId,
authProfileMode: t.authProfileMode
};
const r = await resolveFirstGithubToken(n);
const i = r.githubToken ? await loadCatalog(n, r, buildCopilotRuntimeHeaders({ config: t.config })).catch(() => null) : null;
const a = /* @__PURE__ */ new Map();
if (i) for (const e of i.models) a.set(e.id, {
...e,
provider: PROVIDER_ID,
baseUrl: i.baseUrl
});
let o = e.get(t.modelRegistry);
if (!o) {
o = /* @__PURE__ */ new Map();
e.set(t.modelRegistry, o);
}
o.set(dynamicModelScope(t.authProfileId, t.authProfileMode), a);
}
function resolveDynamicModel(t) {
return e.get(t.modelRegistry)?.get(dynamicModelScope(t.authProfileId, t.authProfileMode))?.get(t.modelId) ?? resolveCopilotForwardCompatModel(t);
}
return {
prepareDynamicModel,
resolveDynamicModel,
runCatalog,
preferRuntimeResolvedModel: () => true
};
}
//#endregion
export { createGithubCopilotDynamicModelHooks as t };