openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.83 kB
JavaScript
import{n as getCachedLiveCatalogValue}from"./provider-live-catalog-cache-CBTQofrX.mjs";import{_ as runLiveProviderCatalog,g as LiveModelCatalogHttpError}from"./provider-catalog-live-runtime-BcG4uFWd.mjs";import"./provider-catalog-shared-pOPyBmVF.mjs";import{a as resolveGithubCopilotDomain}from"./domain-Bn9uiqna.mjs";import{t as buildCopilotRuntimeHeaders}from"./runtime-identity-DPmesWFB.mjs";import{a as resolveCopilotForwardCompatModel,i as isCopilotCatalogModelVisible,n as PROVIDER_ID,r as fetchCopilotModelCatalog}from"./models-hnw5ORFF.mjs";import{t as resolveFirstGithubToken}from"./auth-B_iKeJvV.mjs";import{t as CopilotRuntimeAuthError}from"./runtime-auth-error-BLmzAlcy.mjs";
//!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}}export{createGithubCopilotDynamicModelHooks as t};