Skip to content

Commit 3bf514d

Browse files
glasseraiclaude
andcommitted
fix(glasser): fold only the selected operation's inputs
Values stored by a previously selected operation stayed on the block and were folded into the request, so a social call could carry the web query or URL. The fold now reads only the operation's own sub-blocks and clears every other API field explicitly, so the merge with stored inputs cannot resurrect them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 37b8a66 commit 3bf514d

2 files changed

Lines changed: 98 additions & 30 deletions

File tree

‎apps/sim/blocks/blocks/glasser.ts‎

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,41 @@ const ACTION_FIELD: Record<string, string> = {
8686
[MARKET]: 'md_action',
8787
}
8888

89+
const SHARED_FIELDS = ['provider', 'task_id', 'apiKey'] as const
90+
91+
/**
92+
* Sub-blocks each operation owns. Values of the other operations stay stored on the block after
93+
* switching, so only these are folded and every other API field is cleared explicitly.
94+
*/
95+
const OPERATION_FIELDS: Record<string, readonly string[]> = {
96+
[PEOPLE]: [
97+
'ps_action',
98+
'job_titles',
99+
'seniorities',
100+
'locations',
101+
'company_domain',
102+
'ps_keywords',
103+
'full_name',
104+
'email',
105+
'linkedin_url',
106+
'limit',
107+
],
108+
[COMPANY]: ['ci_action', 'domain', 'ci_query', 'country', 'limit'],
109+
[SEO]: ['seo_action', 'seo_keywords', 'domain', 'country', 'limit'],
110+
[WEB]: ['wr_action', 'query', 'url', 'country', 'language', 'limit'],
111+
[SOCIAL]: ['sr_platform', 'sr_mode', 'sr_query', 'sr_url', 'handle'],
112+
[MARKET]: ['md_action', 'address', 'city', 'state', 'zip', 'symbol', 'limit'],
113+
}
114+
115+
/** Every API field any operation can send; cleared before the selected operation's fields are folded. */
116+
const ALL_PARAM_NAMES = Array.from(
117+
new Set(
118+
Object.values(OPERATION_FIELDS)
119+
.flat()
120+
.map((id) => (Object.values(ACTION_FIELD).includes(id) ? 'action' : (ID_TO_PARAM[id] ?? id)))
121+
)
122+
)
123+
89124
export const GlasserBlock: BlockConfig<GlasserResponse> = {
90125
type: 'glasser',
91126
name: 'Glasser',
@@ -618,17 +653,15 @@ export const GlasserBlock: BlockConfig<GlasserResponse> = {
618653
config: {
619654
tool: (params) => params.operation,
620655
params: (params) => {
621-
const { operation, ...rest } = params
622-
const result: Record<string, unknown> = {}
656+
const operation = String(params.operation ?? PEOPLE)
623657
const actionField = ACTION_FIELD[operation]
658+
const result: Record<string, unknown> = {}
659+
for (const name of ALL_PARAM_NAMES) result[name] = undefined
624660

625-
for (const [key, value] of Object.entries(rest)) {
661+
for (const id of [...(OPERATION_FIELDS[operation] ?? []), ...SHARED_FIELDS]) {
662+
const value = params[id]
626663
if (value === undefined || value === null || value === '') continue
627-
if (Object.values(ACTION_FIELD).includes(key)) {
628-
if (key === actionField) result.action = value
629-
continue
630-
}
631-
const paramName = ID_TO_PARAM[key] ?? key
664+
const paramName = id === actionField ? 'action' : (ID_TO_PARAM[id] ?? id)
632665
if (paramName === 'limit') {
633666
result.limit = Number(value)
634667
} else if (Array.isArray(value)) {

‎apps/sim/tools/glasser/glasser.test.ts‎

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -205,41 +205,76 @@ describe('glasser polling', () => {
205205

206206
describe('glasser block params', () => {
207207
const toParams = GlasserBlock.tools.config!.params!
208+
/** Keys the fold sends; cleared keys carry `undefined` so stale stored values cannot leak through the merge. */
209+
const sent = (result: Record<string, unknown>) =>
210+
Object.fromEntries(Object.entries(result).filter(([, value]) => value !== undefined))
208211

209212
it('routes the operation to its tool and folds the action field', () => {
210213
expect(GlasserBlock.tools.config!.tool!({ operation: 'glasser_seo_research' })).toBe(
211214
'glasser_seo_research'
212215
)
213216
expect(
214-
toParams({
215-
operation: 'glasser_seo_research',
216-
seo_action: 'keyword_ideas',
217-
seo_keywords: 'ai agents',
218-
ci_action: 'enrich',
219-
limit: '10',
220-
apiKey: 'k',
221-
})
217+
sent(
218+
toParams({
219+
operation: 'glasser_seo_research',
220+
seo_action: 'keyword_ideas',
221+
seo_keywords: 'ai agents',
222+
ci_action: 'enrich',
223+
limit: '10',
224+
apiKey: 'k',
225+
})
226+
)
222227
).toStrictEqual({ action: 'keyword_ideas', keywords: 'ai agents', limit: 10, apiKey: 'k' })
223228
})
224229

225230
it('joins multi-select values and maps platform and mode for social', () => {
226231
expect(
227-
toParams({
228-
operation: 'glasser_people_search',
229-
ps_action: 'search',
230-
seniorities: ['vp', 'c_suite'],
231-
job_titles: '',
232-
apiKey: 'k',
233-
})
232+
sent(
233+
toParams({
234+
operation: 'glasser_people_search',
235+
ps_action: 'search',
236+
seniorities: ['vp', 'c_suite'],
237+
job_titles: '',
238+
apiKey: 'k',
239+
})
240+
)
234241
).toStrictEqual({ action: 'search', seniorities: 'vp,c_suite', apiKey: 'k' })
235242
expect(
236-
toParams({
237-
operation: 'glasser_social_research',
238-
sr_platform: 'x',
239-
sr_mode: 'feed',
240-
handle: 'sim',
241-
apiKey: 'k',
242-
})
243+
sent(
244+
toParams({
245+
operation: 'glasser_social_research',
246+
sr_platform: 'x',
247+
sr_mode: 'feed',
248+
handle: 'sim',
249+
apiKey: 'k',
250+
})
251+
)
243252
).toStrictEqual({ platform: 'x', mode: 'feed', handle: 'sim', apiKey: 'k' })
244253
})
254+
255+
it('drops values stored by a previously selected operation and clears their API fields', () => {
256+
const result = toParams({
257+
operation: 'glasser_social_research',
258+
sr_platform: 'reddit',
259+
sr_mode: 'post',
260+
sr_url: 'https://reddit.com/r/rust/comments/1',
261+
wr_action: 'scrape',
262+
query: 'stale web query',
263+
url: 'https://stale.example',
264+
domain: 'stale.example',
265+
limit: '5',
266+
apiKey: 'k',
267+
})
268+
269+
expect(sent(result)).toStrictEqual({
270+
platform: 'reddit',
271+
mode: 'post',
272+
url: 'https://reddit.com/r/rust/comments/1',
273+
apiKey: 'k',
274+
})
275+
expect(result).toHaveProperty('query', undefined)
276+
expect(result).toHaveProperty('domain', undefined)
277+
expect(result).toHaveProperty('action', undefined)
278+
expect(result).toHaveProperty('limit', undefined)
279+
})
245280
})

0 commit comments

Comments
 (0)