refactor(opencode): move the tool-name alias gate into toolNameLengthAlias to keep opencode.ts under its frozen size

This commit is contained in:
diegosouzapw
2026-10-17 09:48:56 -03:00
parent 35d63b6df5
commit e42619dce0
2 changed files with 17 additions and 8 deletions

View File

@@ -33,7 +33,7 @@ import {
} from "../utils/opencodeHeaders.ts";
import { projectOpencodeSessionBody } from "../utils/opencodeSessionIdentity.ts";
import { listForRequest, releaseRequestList } from "./opencodeAccountScope.ts";
import { applyRegistryToolNameLengthAliases } from "./toolNameLengthAlias.ts";
import { applyOpencodeToolNameLengthAliases } from "./toolNameLengthAlias.ts";
import type { ScopedAccount, ScopedAccountHealth } from "./opencodeAccountScope.ts";
import { guardRequiredAccountProxies } from "./opencodeRequiredProxy.ts";
import {
@@ -1527,13 +1527,8 @@ export class OpencodeExecutor extends BaseExecutor {
if (isThinkingMessageModel(model)) {
modifiedBody = injectReasoningContentForThinkingModel(modifiedBody);
}
// OpenCode chat-completions 400s on tool names over 64 chars (Claude Code MCP
// names hit this). Alias them last, on the final body, so the request-scoped
// `_toolNameMap` restores the originals in the response. Claude / Responses
// surfaces carry their own tool shapes and are left alone.
if ((this._requestFormat ?? resolveOpencodeTargetFormat(this.provider, model)) === "openai") {
applyRegistryToolNameLengthAliases(this.provider, modifiedBody);
}
const toolFormat = this._requestFormat ?? resolveOpencodeTargetFormat(this.provider, model);
applyOpencodeToolNameLengthAliases(this.provider, modifiedBody, toolFormat);
return modifiedBody;
}
}

View File

@@ -66,3 +66,17 @@ export function applyRegistryToolNameLengthAliases(
): Map<string, string> {
return applyToolNameLengthAliases(body, getRegistryEntry(provider)?.toolNameMaxLength, normalize);
}
/**
* OpenCode chat-completions 400s on tool names over 64 chars (Claude Code MCP names
* hit this). Called last, on the final body, so the request-scoped `_toolNameMap`
* restores the originals in the response. Only the OpenAI chat surface is aliased;
* Claude / Responses surfaces carry their own tool shapes and are left alone.
*/
export function applyOpencodeToolNameLengthAliases(
provider: string,
body: unknown,
targetFormat: string
): void {
if (targetFormat === "openai") applyRegistryToolNameLengthAliases(provider, body);
}