Skip to content

Commit 37dba90

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(providers): bound overlong tool wire names
1 parent 044660b commit 37dba90

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

‎apps/sim/providers/tool-identity.test.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,40 @@ describe('provider tool identities', () => {
8383

8484
assignProviderToolIdentities(tools)
8585

86-
expect(tools[0].id).toBe(longId)
86+
expect(tools[0].id).toHaveLength(64)
87+
expect(tools[0].id).toMatch(/__sim_1$/)
88+
expect(tools[0].canonicalId).toBe(longId)
8789
expect(tools[1].id).toHaveLength(64)
8890
expect(tools[1].id).toMatch(/__sim_2$/)
8991
})
9092

93+
it('preserves ids at the limit and aliases unique overlong ids without collisions', () => {
94+
const prefix = 'a'.repeat(57)
95+
const longId = `${prefix}${'b'.repeat(8)}`
96+
const otherLongId = `${prefix}${'c'.repeat(8)}`
97+
const reservedId = `${prefix}__sim_1`
98+
const tools = [
99+
providerTool(longId, 'a'),
100+
providerTool(otherLongId, 'b'),
101+
providerTool(reservedId, 'reserved'),
102+
providerTool('d'.repeat(64), 'at-limit'),
103+
]
104+
105+
const identities = assignProviderToolIdentities(tools)
106+
const wireIds = tools.map((tool) => tool.id)
107+
108+
expect(new Set(wireIds).size).toBe(4)
109+
expect(wireIds.every((id) => id.length <= 64)).toBe(true)
110+
expect(tools[2].id).toBe(reservedId)
111+
expect(tools[3].id).toBe('d'.repeat(64))
112+
expect(identities.toolIdByWireId.get(tools[0].id)).toBe(longId)
113+
expect(identities.toolIdByWireId.get(tools[1].id)).toBe(otherLongId)
114+
expect(tools[0].params.oauthCredential).toBe('a')
115+
116+
assignProviderToolIdentities(tools)
117+
expect(tools.map((tool) => tool.id)).toEqual(wireIds)
118+
})
119+
91120
it('projects provider response names back to their canonical ids', () => {
92121
const tools = [providerTool('gmail_send', 'a'), providerTool('gmail_send', 'b')]
93122
const identities = assignProviderToolIdentities(tools)

‎apps/sim/providers/tool-identity.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ function buildProviderAlias(toolId: string, occurrence: number, attempt: number)
1818
}
1919

2020
/**
21-
* Gives duplicate configured tools deterministic provider-safe wire ids.
21+
* Gives duplicate or overlong configured tools deterministic provider-safe wire ids.
2222
*
23-
* The first occurrence and every already-unique tool keep their existing id for backwards
24-
* compatibility. Later occurrences receive opaque ordinal aliases; resource and credential ids
23+
* Unique ids within the provider limit keep their existing id for backwards compatibility.
24+
* Overlong ids and later occurrences receive opaque ordinal aliases; resource and credential ids
2525
* never enter the provider-visible name. Tool objects are updated in place so their instance-bound
2626
* params and secret provenance remain attached to the exact object selected by provider adapters.
2727
*/
@@ -47,7 +47,7 @@ export function assignProviderToolIdentities(
4747
occurrences.set(canonicalId, occurrence)
4848

4949
let wireId = canonicalId
50-
if (usedWireIds.has(wireId)) {
50+
if (wireId.length > MAX_PROVIDER_TOOL_ID_LENGTH || usedWireIds.has(wireId)) {
5151
let attempt = 0
5252
do {
5353
wireId = buildProviderAlias(canonicalId, occurrence, attempt)

0 commit comments

Comments
 (0)