mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 23:00:43 +00:00
* fix(models): normalize provider runtime selection * fix(models): reverse codex-only runtime migration * fix(models): default runtime selection to pi * fix(status): label model runtime clearly * fix(status): align pi runtime label * fix(plugins): align tool result middleware runtime naming * fix(models): validate runtime overrides
75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
import type {
|
|
AgentToolResultMiddleware,
|
|
AgentToolResultMiddlewareOptions,
|
|
AgentToolResultMiddlewareRuntime,
|
|
} from "./agent-tool-result-middleware-types.js";
|
|
import { getActivePluginRegistry } from "./runtime.js";
|
|
|
|
export const AGENT_TOOL_RESULT_MIDDLEWARE_RUNTIMES = [
|
|
"pi",
|
|
"codex",
|
|
] as const satisfies AgentToolResultMiddlewareRuntime[];
|
|
|
|
const AGENT_TOOL_RESULT_MIDDLEWARE_RUNTIME_SET = new Set<string>(
|
|
AGENT_TOOL_RESULT_MIDDLEWARE_RUNTIMES,
|
|
);
|
|
|
|
function normalizeAgentToolResultMiddlewareRuntime(
|
|
runtime: string,
|
|
): AgentToolResultMiddlewareRuntime | undefined {
|
|
const normalized = runtime.trim().toLowerCase();
|
|
if (normalized === "codex-app-server") {
|
|
return "codex";
|
|
}
|
|
return AGENT_TOOL_RESULT_MIDDLEWARE_RUNTIME_SET.has(normalized)
|
|
? (normalized as AgentToolResultMiddlewareRuntime)
|
|
: undefined;
|
|
}
|
|
|
|
export function normalizeAgentToolResultMiddlewareRuntimes(
|
|
options?: AgentToolResultMiddlewareOptions,
|
|
): AgentToolResultMiddlewareRuntime[] {
|
|
const requested = options?.runtimes ?? options?.harnesses;
|
|
if (!requested || requested.length === 0) {
|
|
return [...AGENT_TOOL_RESULT_MIDDLEWARE_RUNTIMES];
|
|
}
|
|
const normalized: AgentToolResultMiddlewareRuntime[] = [];
|
|
for (const runtime of requested) {
|
|
const value = normalizeAgentToolResultMiddlewareRuntime(runtime);
|
|
if (!value) {
|
|
continue;
|
|
}
|
|
if (!normalized.includes(value)) {
|
|
normalized.push(value);
|
|
}
|
|
}
|
|
return normalized;
|
|
}
|
|
|
|
/** @deprecated Use normalizeAgentToolResultMiddlewareRuntimes. */
|
|
export const normalizeAgentToolResultMiddlewareHarnesses =
|
|
normalizeAgentToolResultMiddlewareRuntimes;
|
|
|
|
export function normalizeAgentToolResultMiddlewareRuntimeIds(
|
|
runtimes: readonly string[] | undefined,
|
|
): AgentToolResultMiddlewareRuntime[] {
|
|
const normalized: AgentToolResultMiddlewareRuntime[] = [];
|
|
for (const runtime of runtimes ?? []) {
|
|
const value = normalizeAgentToolResultMiddlewareRuntime(runtime);
|
|
if (value && !normalized.includes(value)) {
|
|
normalized.push(value);
|
|
}
|
|
}
|
|
return normalized;
|
|
}
|
|
|
|
export function listAgentToolResultMiddlewares(
|
|
runtime: AgentToolResultMiddlewareRuntime,
|
|
): AgentToolResultMiddleware[] {
|
|
return (
|
|
getActivePluginRegistry()
|
|
?.agentToolResultMiddlewares?.filter((entry) => entry.runtimes.includes(runtime))
|
|
.map((entry) => entry.handler) ?? []
|
|
);
|
|
}
|