The Open Framework for Building Agents
fix(eve): keep suffixed OpenAPI tool names within 64 characters (#4785)
Ben Pankowd8414ad4aed3
diff --git a/.changeset/openapi-unique-name-length.md b/.changeset/openapi-unique-name-length.mdnew file mode 100644index 000000000..493cc8f1e--- /dev/null+++ b/.changeset/openapi-unique-name-length.md@@ -0,0 +1,5 @@+---+"eve": patch+---++OpenAPI connections whose operation names collide at 64 characters now keep the suffixed tool names within the 64-character provider limit.diff --git a/packages/eve/src/runtime/connections/openapi-operations.test.ts b/packages/eve/src/runtime/connections/openapi-operations.test.tsnew file mode 100644index 000000000..1e314375b--- /dev/null+++ b/packages/eve/src/runtime/connections/openapi-operations.test.ts@@ -0,0 +1,11 @@+import { expect, it } from "vitest";+import { uniqueName } from "#runtime/connections/openapi-operations.js";++it("keeps collision suffixes within the 64-character tool name limit", () => {+ const base = "a".repeat(64);+ const used = new Set([base, `${"a".repeat(62)}_2`]);+ const names = Array.from({ length: 9 }, () => uniqueName(base, used));+ expect(names[0]).toBe(`${"a".repeat(62)}_3`);+ expect(names.at(-1)).toBe(`${"a".repeat(61)}_11`);+ expect(names.every((name) => name.length <= 64)).toBe(true);+});diff --git a/packages/eve/src/runtime/connections/openapi-operations.ts b/packages/eve/src/runtime/connections/openapi-operations.tsindex 181253752..1668e49a1 100644--- a/packages/eve/src/runtime/connections/openapi-operations.ts+++ b/packages/eve/src/runtime/connections/openapi-operations.ts@@ -44,12 +44,14 @@ export function operationName(return sanitizeToolName(`${method}_${sanitizedPath}`);}+const MAX_TOOL_NAME_LENGTH = 64;+/** Coerces an arbitrary string into a provider-legal tool name (`[a-zA-Z0-9_-]`, ≤64). */function sanitizeToolName(name: string): string {return name.replace(/[^a-zA-Z0-9_-]+/g, "_").replace(/^[_-]+|[_-]+$/g, "")- .slice(0, 64);+ .slice(0, MAX_TOOL_NAME_LENGTH);}/** Disambiguates a tool name against names already used in the same connection. */@@ -57,7 +59,8 @@ export function uniqueName(name: string, used: Set<string>): string {let candidate = name;let suffix = 2;while (used.has(candidate)) {- candidate = `${name}_${suffix}`;+ const ending = `_${suffix}`;+ candidate = `${name.slice(0, MAX_TOOL_NAME_LENGTH - ending.length)}${ending}`;suffix += 1;}used.add(candidate);