Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion apps/sim/providers/tool-identity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions apps/sim/providers/tool-identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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)
Expand Down
Loading