Files
openclaw/src/agents/bundle-mcp-adapter.ts
Peter Steinberger ebb2770000 refactor: eliminate export name collisions (#122084)
* refactor: eliminate export name collisions

* chore(scripts): burn resolved collision baselines

* refactor: narrow legacy session load options

* chore: refresh SDK and session debt baselines

* refactor: adopt upstream secrets collision fix

* test(plugin-sdk): mock renamed session store core

* fix(scripts): track renamed session accessor core
2026-08-11 10:41:50 -07:00

56 lines
1.8 KiB
TypeScript

// Shared mechanics for projecting bundle MCP config into provider-owned runners.
import { isRecord } from "../../packages/normalization-core/src/record-coerce.js";
import type { BundleMcpServerConfig } from "../plugins/bundle-mcp.js";
export { isRecord } from "../../packages/normalization-core/src/record-coerce.js";
export function normalizeMcpStringRecord(value: unknown): Record<string, string> | undefined {
if (!isRecord(value)) {
return undefined;
}
const entries = Object.entries(value).filter((entry): entry is [string, string] => {
return typeof entry[1] === "string";
});
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
}
export function decodeHeaderEnvPlaceholder(
value: string,
): { envVar: string; bearer: boolean } | null {
const match = /^(Bearer )?\${([A-Z0-9_]+)}$/.exec(value);
return match?.[2] ? { envVar: match[2], bearer: Boolean(match[1]) } : null;
}
const COMMON_STRING_FIELDS = ["command", "cwd", "url"] as const;
export function normalizeBundleMcpServerConfig(
server: BundleMcpServerConfig,
fields: {
strings?: readonly (keyof BundleMcpServerConfig)[];
booleans?: readonly (keyof BundleMcpServerConfig)[];
} = {},
): Record<string, unknown> {
const next: Record<string, unknown> = {};
for (const field of [...COMMON_STRING_FIELDS, ...(fields.strings ?? [])]) {
if (typeof server[field] === "string") {
next[field] = server[field];
}
}
for (const field of fields.booleans ?? []) {
if (typeof server[field] === "boolean") {
next[field] = server[field];
}
}
const args =
Array.isArray(server.args) && server.args.every((entry) => typeof entry === "string")
? [...server.args]
: undefined;
if (args) {
next.args = args;
}
const env = normalizeMcpStringRecord(server.env);
if (env) {
next.env = env;
}
return next;
}