mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-18 07:58:27 +00:00
refactor(opencode): move the tool-name alias gate into toolNameLengthAlias to keep opencode.ts under its frozen size
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user