openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
2 lines • 1.39 kB
JavaScript
//!extensions/github-copilot/domain.ts
const PUBLIC_GITHUB_COPILOT_DOMAIN=`github.com`;const GHE_DATA_RESIDENCY_HOST=/^[a-z0-9-]+\.ghe\.com$/;function isSupportedGithubCopilotDomain(e){const t=(e??``).trim().toLowerCase();if(!t)return true;return/^[a-z0-9.-]+$/.test(t)&&(t===`github.com`||GHE_DATA_RESIDENCY_HOST.test(t))}function normalizeGithubCopilotDomain(e){const t=(e??``).trim().toLowerCase();return t&&isSupportedGithubCopilotDomain(t)?t:PUBLIC_GITHUB_COPILOT_DOMAIN}function normalizeGithubCopilotOAuthScope(e){if(!e)return PUBLIC_GITHUB_COPILOT_DOMAIN;const t=e.trim();if(!t)return;const n=URL.parse(t.includes(`://`)?t:`https://${t}`)?.hostname;return n&&isSupportedGithubCopilotDomain(n)?normalizeGithubCopilotDomain(n):void 0}function readConfiguredGithubCopilotDomain(e){const t=e?.models?.providers?.[`github-copilot`]?.params?.githubDomain;return typeof t===`string`&&t.trim().length>0?t.trim():void 0}function resolveGithubCopilotDomain(e){const t=(e?.env??process.env).COPILOT_GITHUB_DOMAIN?.trim();if(t)return normalizeGithubCopilotDomain(t);if(e?.explicit)return normalizeGithubCopilotDomain(e.explicit);return normalizeGithubCopilotDomain(readConfiguredGithubCopilotDomain(e?.config))}export{resolveGithubCopilotDomain as a,normalizeGithubCopilotOAuthScope as i,isSupportedGithubCopilotDomain as n,normalizeGithubCopilotDomain as r,PUBLIC_GITHUB_COPILOT_DOMAIN as t};