mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-05 11:42:55 +00:00
* fix(browser): isolate Chrome MCP pending attach aborts * fix(browser): evict closing Chrome MCP sessions * fix(browser): clean chrome mcp pending session lifecycle * fix(browser): handle stale chrome mcp pending sessions * fix(browser): serialize stale chrome mcp replacement * fix(browser): skip cancelled chrome mcp attach * fix(browser): retire timed-out chrome mcp pending sessions * fix(browser): retire stale chrome mcp after readiness * fix(browser): keep shared chrome mcp timeouts isolated * fix(browser): bound stale chrome mcp ready retries * fix(browser): narrow pending session lease release * fix(browser): keep ephemeral probes out of pending attaches * fix(foundry): satisfy provider lint --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
179 lines
7.0 KiB
TypeScript
179 lines
7.0 KiB
TypeScript
import type { ProviderNormalizeResolvedModelContext } from "openclaw/plugin-sdk/core";
|
|
import type {
|
|
ModelProviderConfig,
|
|
ProviderPlugin,
|
|
} from "openclaw/plugin-sdk/provider-model-shared";
|
|
import { apiKeyAuthMethod, entraIdAuthMethod } from "./auth.js";
|
|
import { prepareFoundryRuntimeAuth } from "./runtime.js";
|
|
import {
|
|
PROVIDER_ID,
|
|
applyFoundryProfileBinding,
|
|
applyFoundryProviderConfig,
|
|
buildFoundryProviderBaseUrl,
|
|
extractFoundryEndpoint,
|
|
isFoundryProviderApi,
|
|
normalizeFoundryEndpoint,
|
|
resolveFoundryModelCapabilities,
|
|
resolveFoundryTargetProfileId,
|
|
} from "./shared.js";
|
|
|
|
export function buildMicrosoftFoundryProvider(): ProviderPlugin {
|
|
return {
|
|
id: PROVIDER_ID,
|
|
label: "Microsoft Foundry",
|
|
docsPath: "/providers/models",
|
|
envVars: ["AZURE_OPENAI_API_KEY", "AZURE_OPENAI_ENDPOINT"],
|
|
auth: [entraIdAuthMethod, apiKeyAuthMethod],
|
|
onModelSelected: async (ctx) => {
|
|
const providerConfig = ctx.config.models?.providers?.[PROVIDER_ID];
|
|
if (
|
|
!providerConfig ||
|
|
!providerConfig.baseUrl?.trim() ||
|
|
!Array.isArray(providerConfig.models) ||
|
|
!ctx.model.startsWith(`${PROVIDER_ID}/`)
|
|
) {
|
|
return;
|
|
}
|
|
const selectedModelId = ctx.model.slice(`${PROVIDER_ID}/`.length);
|
|
const configuredModels = providerConfig.models ?? [];
|
|
const existingModel = configuredModels.find(
|
|
(model: { id: string }) => model.id === selectedModelId,
|
|
);
|
|
const selectedModelCapabilities = resolveFoundryModelCapabilities(
|
|
selectedModelId,
|
|
existingModel?.name,
|
|
isFoundryProviderApi(existingModel?.api) ? existingModel.api : providerConfig.api,
|
|
existingModel?.input,
|
|
);
|
|
const providerEndpoint = normalizeFoundryEndpoint(providerConfig.baseUrl ?? "");
|
|
// Prefer the persisted per-model API choice from onboarding/discovery so arbitrary
|
|
// deployment aliases (for example prod-primary) do not fall back to name heuristics.
|
|
const selectedModelApi = isFoundryProviderApi(existingModel?.api)
|
|
? existingModel.api
|
|
: providerConfig.api;
|
|
const nextModels = configuredModels.map((model) => {
|
|
if (model.id !== selectedModelId) {
|
|
return model;
|
|
}
|
|
const nextModel = Object.assign({}, model, {
|
|
name: selectedModelCapabilities.modelName,
|
|
api: selectedModelCapabilities.api,
|
|
reasoning: selectedModelCapabilities.reasoning || model.reasoning,
|
|
thinkingLevelMap: selectedModelCapabilities.thinkingLevelMap ?? model.thinkingLevelMap,
|
|
input: selectedModelCapabilities.input,
|
|
});
|
|
if (selectedModelCapabilities.compat) {
|
|
const explicitSupportsReasoningEffort =
|
|
typeof model.compat?.supportsReasoningEffort === "boolean"
|
|
? model.compat.supportsReasoningEffort
|
|
: undefined;
|
|
const preserveExplicitReasoningEffort =
|
|
!selectedModelCapabilities.reasoning &&
|
|
model.reasoning &&
|
|
explicitSupportsReasoningEffort !== false;
|
|
const explicitMaxTokensField =
|
|
typeof model.compat?.maxTokensField === "string"
|
|
? model.compat.maxTokensField
|
|
: preserveExplicitReasoningEffort
|
|
? "max_completion_tokens"
|
|
: undefined;
|
|
nextModel.compat = {
|
|
...model.compat,
|
|
...selectedModelCapabilities.compat,
|
|
...(explicitSupportsReasoningEffort !== undefined
|
|
? { supportsReasoningEffort: explicitSupportsReasoningEffort }
|
|
: preserveExplicitReasoningEffort
|
|
? { supportsReasoningEffort: true }
|
|
: undefined),
|
|
...(explicitMaxTokensField ? { maxTokensField: explicitMaxTokensField } : {}),
|
|
};
|
|
}
|
|
return nextModel;
|
|
});
|
|
if (!nextModels.some((model) => model.id === selectedModelId)) {
|
|
nextModels.push({
|
|
id: selectedModelId,
|
|
name: selectedModelCapabilities.modelName,
|
|
api: selectedModelCapabilities.api,
|
|
reasoning: selectedModelCapabilities.reasoning,
|
|
...(selectedModelCapabilities.thinkingLevelMap
|
|
? { thinkingLevelMap: selectedModelCapabilities.thinkingLevelMap }
|
|
: {}),
|
|
input: selectedModelCapabilities.input,
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 128_000,
|
|
maxTokens: 16_384,
|
|
...(selectedModelCapabilities.compat ? { compat: selectedModelCapabilities.compat } : {}),
|
|
});
|
|
}
|
|
const nextProviderConfig: ModelProviderConfig = {
|
|
...providerConfig,
|
|
baseUrl: buildFoundryProviderBaseUrl(
|
|
providerEndpoint,
|
|
selectedModelId,
|
|
selectedModelCapabilities.modelName,
|
|
selectedModelApi,
|
|
),
|
|
api: selectedModelCapabilities.api,
|
|
models: nextModels,
|
|
};
|
|
const targetProfileId = resolveFoundryTargetProfileId(ctx.config);
|
|
if (targetProfileId) {
|
|
applyFoundryProfileBinding(ctx.config, targetProfileId);
|
|
}
|
|
applyFoundryProviderConfig(ctx.config, nextProviderConfig);
|
|
},
|
|
normalizeResolvedModel: ({ modelId, model }: ProviderNormalizeResolvedModelContext) => {
|
|
const endpoint = extractFoundryEndpoint(model.baseUrl ?? "");
|
|
if (!endpoint) {
|
|
return model;
|
|
}
|
|
const capabilities = resolveFoundryModelCapabilities(
|
|
modelId,
|
|
model.name,
|
|
isFoundryProviderApi(model.api) ? model.api : undefined,
|
|
model.input,
|
|
);
|
|
const explicitSupportsReasoningEffort =
|
|
typeof model.compat?.supportsReasoningEffort === "boolean"
|
|
? model.compat.supportsReasoningEffort
|
|
: undefined;
|
|
const preserveExplicitReasoningEffort = !capabilities.reasoning && model.reasoning;
|
|
const explicitMaxTokensField =
|
|
typeof model.compat?.maxTokensField === "string"
|
|
? model.compat.maxTokensField
|
|
: preserveExplicitReasoningEffort
|
|
? "max_completion_tokens"
|
|
: undefined;
|
|
const compat = capabilities.compat
|
|
? {
|
|
...model.compat,
|
|
...capabilities.compat,
|
|
...(explicitSupportsReasoningEffort !== undefined
|
|
? { supportsReasoningEffort: explicitSupportsReasoningEffort }
|
|
: preserveExplicitReasoningEffort
|
|
? { supportsReasoningEffort: true }
|
|
: undefined),
|
|
...(explicitMaxTokensField ? { maxTokensField: explicitMaxTokensField } : {}),
|
|
}
|
|
: undefined;
|
|
return {
|
|
...model,
|
|
name: capabilities.modelName,
|
|
api: capabilities.api,
|
|
reasoning: capabilities.reasoning || model.reasoning,
|
|
thinkingLevelMap: capabilities.thinkingLevelMap ?? model.thinkingLevelMap,
|
|
input: capabilities.input,
|
|
baseUrl: buildFoundryProviderBaseUrl(
|
|
endpoint,
|
|
modelId,
|
|
capabilities.modelName,
|
|
capabilities.api,
|
|
),
|
|
...(compat ? { compat } : {}),
|
|
};
|
|
},
|
|
prepareRuntimeAuth: prepareFoundryRuntimeAuth,
|
|
};
|
|
}
|