openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
40 lines (39 loc) • 1.99 kB
JavaScript
//#region extensions/github-copilot/domain.ts
/** Public GitHub Copilot host used when no data-residency domain is configured. */
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;
}
/** Normalize legacy OAuth URL/domain spellings without accepting unsupported tenants. */
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;
}
/**
* Resolve the GitHub Copilot host for this provider from (in priority order) the
* `COPILOT_GITHUB_DOMAIN` env override, the persisted
* `models.providers.github-copilot.params.githubDomain` config, then public
* `github.com`. The provider allowlist rejects unsafe values.
*/
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));
}
//#endregion
export { resolveGithubCopilotDomain as a, normalizeGithubCopilotOAuthScope as i, isSupportedGithubCopilotDomain as n, normalizeGithubCopilotDomain as r, PUBLIC_GITHUB_COPILOT_DOMAIN as t };