diff --git a/apps/sim/providers/tool-identity.test.ts b/apps/sim/providers/tool-identity.test.ts index 6c496ad0f21..fb66ecbc55c 100644 --- a/apps/sim/providers/tool-identity.test.ts +++ b/apps/sim/providers/tool-identity.test.ts @@ -83,11 +83,40 @@ describe('provider tool identities', () => { assignProviderToolIdentities(tools) - expect(tools[0].id).toBe(longId) + expect(tools[0].id).toHaveLength(64) + expect(tools[0].id).toMatch(/__sim_1$/) + expect(tools[0].canonicalId).toBe(longId) expect(tools[1].id).toHaveLength(64) expect(tools[1].id).toMatch(/__sim_2$/) }) + it('preserves ids at the limit and aliases unique overlong ids without collisions', () => { + const prefix = 'a'.repeat(57) + const longId = `${prefix}${'b'.repeat(8)}` + const otherLongId = `${prefix}${'c'.repeat(8)}` + const reservedId = `${prefix}__sim_1` + const tools = [ + providerTool(longId, 'a'), + providerTool(otherLongId, 'b'), + providerTool(reservedId, 'reserved'), + providerTool('d'.repeat(64), 'at-limit'), + ] + + const identities = assignProviderToolIdentities(tools) + const wireIds = tools.map((tool) => tool.id) + + expect(new Set(wireIds).size).toBe(4) + expect(wireIds.every((id) => id.length <= 64)).toBe(true) + expect(tools[2].id).toBe(reservedId) + expect(tools[3].id).toBe('d'.repeat(64)) + expect(identities.toolIdByWireId.get(tools[0].id)).toBe(longId) + expect(identities.toolIdByWireId.get(tools[1].id)).toBe(otherLongId) + expect(tools[0].params.oauthCredential).toBe('a') + + assignProviderToolIdentities(tools) + expect(tools.map((tool) => tool.id)).toEqual(wireIds) + }) + it('projects provider response names back to their canonical ids', () => { const tools = [providerTool('gmail_send', 'a'), providerTool('gmail_send', 'b')] const identities = assignProviderToolIdentities(tools) diff --git a/apps/sim/providers/tool-identity.ts b/apps/sim/providers/tool-identity.ts index 58998fa1fec..e0516185b55 100644 --- a/apps/sim/providers/tool-identity.ts +++ b/apps/sim/providers/tool-identity.ts @@ -18,10 +18,10 @@ function buildProviderAlias(toolId: string, occurrence: number, attempt: number) } /** - * Gives duplicate configured tools deterministic provider-safe wire ids. + * Gives duplicate or overlong configured tools deterministic provider-safe wire ids. * - * The first occurrence and every already-unique tool keep their existing id for backwards - * compatibility. Later occurrences receive opaque ordinal aliases; resource and credential ids + * Unique ids within the provider limit keep their existing id for backwards compatibility. + * Overlong ids and later occurrences receive opaque ordinal aliases; resource and credential ids * never enter the provider-visible name. Tool objects are updated in place so their instance-bound * params and secret provenance remain attached to the exact object selected by provider adapters. */ @@ -47,7 +47,7 @@ export function assignProviderToolIdentities( occurrences.set(canonicalId, occurrence) let wireId = canonicalId - if (usedWireIds.has(wireId)) { + if (wireId.length > MAX_PROVIDER_TOOL_ID_LENGTH || usedWireIds.has(wireId)) { let attempt = 0 do { wireId = buildProviderAlias(canonicalId, occurrence, attempt)