openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
165 lines (164 loc) • 6.57 kB
JavaScript
import { t as normalizeOptionalSecretInput } from "./normalize-secret-input-Cxkx67Fv.mjs";
import { i as ensureAuthProfileStoreAsync } from "./store-runtime-dW0pXLJI.mjs";
import "./provider-auth-D_oAZ3fr.mjs";
import { t as captureProviderApiKey } from "./provider-api-key-auth-B0AQ5Vpx.mjs";
import "./provider-auth-api-key-D-0BDe0y.mjs";
import { b as resolveConfiguredModelNameHint, c as buildFoundryAuthResult, f as formatFoundryApiLabel, h as listConfiguredFoundryProfileIds, o as PROVIDER_ID, p as isFoundryMaiImageModel, x as resolveFoundryApi } from "./shared-DiLOhEpP.mjs";
import { a as getLoggedInAccount, o as isAzCliInstalled, s as listSubscriptions } from "./cli-BYOdN2ZS.mjs";
import { a as promptTenantId, c as testFoundryConnection, i as promptEndpointAndModelManually, n as loginWithTenantFallback, o as selectFoundryDeployment, r as promptApiKeyEndpointAndModel, s as selectFoundryResource, t as listResourceDeployments } from "./onboard-vjtvGuGu.mjs";
//#region extensions/microsoft-foundry/auth.ts
const entraIdAuthMethod = {
id: "entra-id",
label: "Entra ID (az login)",
hint: "Use your Azure login — no API key needed",
kind: "custom",
wizard: {
choiceId: "microsoft-foundry-entra",
choiceLabel: "Microsoft Foundry (Entra ID / az login)",
choiceHint: "Use your Azure login — no API key needed",
onboardingScopes: ["text-inference", "image-generation"],
groupId: "microsoft-foundry",
groupLabel: "Microsoft Foundry",
groupHint: "Entra ID + API key"
},
run: async (e) => {
if (!isAzCliInstalled()) throw new Error("Azure CLI (az) is not installed.\nInstall it from https://learn.microsoft.com/cli/azure/install-azure-cli");
const t = getLoggedInAccount();
let n = t?.tenantId;
if (t) {
if (!await e.prompter.confirm({
message: `Already logged in as ${t.user?.name ?? "unknown"} (${t.name}). Use this account?`,
initialValue: true
})) {
const t = await loginWithTenantFallback(e);
n = t.tenantId ?? t.account?.tenantId;
}
} else {
await e.prompter.note("You need to log in to Azure. A device code will be displayed - follow the instructions.", "Azure Login");
const t = await loginWithTenantFallback(e);
n = t.tenantId ?? t.account?.tenantId;
}
const r = listSubscriptions();
let i = null;
if (r.length === 0) {
n ??= await promptTenantId(e, { reason: "No enabled Azure subscriptions were found. Continue with tenant-scoped Entra ID auth instead." });
await e.prompter.note(`Continuing with tenant-scoped auth (${n}).`, "Azure Tenant");
} else if (r.length === 1) {
i = r[0];
n ??= i.tenantId;
await e.prompter.note(`Using subscription: ${i.name} (${i.id})`, "Subscription");
} else {
const t = await e.prompter.select({
message: "Select Azure subscription",
options: r.map((e) => ({
value: e.id,
label: `${e.name} (${e.id})`
}))
});
const a = r.find((e) => e.id === t);
if (!a) throw new Error(`Selected subscription not found: ${t}`);
i = a;
n ??= i.tenantId;
}
let a;
let o;
let s;
let c;
let l;
if (i && await e.prompter.confirm({
message: "Discover Microsoft Foundry resources from this subscription?",
initialValue: true
})) {
const t = await selectFoundryResource(e, i);
const n = listResourceDeployments(t, i.id);
const { selected: r, supported: u } = await selectFoundryDeployment(e, t, n);
l = u.map((e) => Object.assign({ name: e.name }, e.modelName ? { modelName: e.modelName } : {}, { api: resolveFoundryApi(e.name, e.modelName) }));
a = t.endpoint;
o = r.name;
s = resolveConfiguredModelNameHint(o, r.modelName);
c = resolveFoundryApi(o, s);
await e.prompter.note([
`Resource: ${t.accountName}`,
`Endpoint: ${a}`,
`Deployment: ${o}`,
r.modelName ? `Model: ${r.modelName}` : void 0,
`API: ${formatFoundryApiLabel(c)}`
].filter(Boolean).join("\n"), "Microsoft Foundry");
} else ({endpoint: a, modelId: o, modelNameHint: s, api: c} = await promptEndpointAndModelManually(e));
if (!isFoundryMaiImageModel(resolveConfiguredModelNameHint(o, s))) await testFoundryConnection({
ctx: e,
endpoint: a,
modelId: o,
modelNameHint: s,
api: c,
subscriptionId: i?.id,
tenantId: n
});
return buildFoundryAuthResult({
profileId: `${PROVIDER_ID}:entra`,
apiKey: "__entra_id_dynamic__",
endpoint: a,
modelId: o,
modelNameHint: s,
api: c,
authMethod: "entra-id",
...i?.id ? { subscriptionId: i.id } : {},
...i?.name ? { subscriptionName: i.name } : {},
...n ? { tenantId: n } : {},
currentProviderProfileIds: listConfiguredFoundryProfileIds(e.config),
currentPluginsAllow: e.config.plugins?.allow,
...l ? { deployments: l } : {},
notes: [
...i?.name ? [`Subscription: ${i.name}`] : [],
...n ? [`Tenant: ${n}`] : [],
`Endpoint: ${a}`,
`Model: ${o}`,
"Token is refreshed automatically via az CLI - keep az login active."
]
});
}
};
const apiKeyAuthMethod = {
id: "api-key",
label: "Azure OpenAI API key",
hint: "Direct Azure OpenAI API key",
kind: "api_key",
wizard: {
choiceId: "microsoft-foundry-apikey",
choiceLabel: "Microsoft Foundry (API key)",
onboardingScopes: ["text-inference", "image-generation"],
groupId: "microsoft-foundry",
groupLabel: "Microsoft Foundry",
groupHint: "Entra ID + API key"
},
run: async (e) => {
const t = (await ensureAuthProfileStoreAsync(e.agentDir, { allowKeychainPrompt: false })).profiles[`${PROVIDER_ID}:default`];
const n = t?.type === "api_key" ? t.metadata : void 0;
const { input: r, mode: i } = await captureProviderApiKey(e, {
token: normalizeOptionalSecretInput(e.opts?.azureOpenaiApiKey),
tokenProvider: PROVIDER_ID,
expectedProviders: [PROVIDER_ID],
provider: PROVIDER_ID,
envLabel: "AZURE_OPENAI_API_KEY",
promptMessage: "Enter Azure OpenAI API key",
missingInputMessage: "Missing Azure OpenAI API key."
});
const a = await promptApiKeyEndpointAndModel(e);
const o = n?.modelId === a.modelId ? n.modelName ?? n.modelId : void 0;
return buildFoundryAuthResult({
profileId: `${PROVIDER_ID}:default`,
apiKey: r,
...i ? { secretInputMode: i } : {},
endpoint: a.endpoint,
modelId: a.modelId,
modelNameHint: a.modelNameHint ?? o,
api: a.api,
authMethod: "api-key",
currentProviderProfileIds: listConfiguredFoundryProfileIds(e.config),
currentPluginsAllow: e.config.plugins?.allow,
notes: [`Endpoint: ${a.endpoint}`, `Model: ${a.modelId}`]
});
}
};
//#endregion
export { entraIdAuthMethod as n, apiKeyAuthMethod as t };