Skip to content

Commit 22df446

Browse files
waleedlatif1claude
andcommitted
fix(brightdata): use params for echo-back fields in transformResponse
transformResponse receives params as its second argument. Use it to return the original url, query, snapshotId, and searchEngine values instead of hardcoding null or extracting from response data that may not contain them. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cd8c5bd commit 22df446

5 files changed

Lines changed: 17 additions & 12 deletions

File tree

apps/sim/tools/brightdata/cancel_snapshot.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ export const brightDataCancelSnapshotTool: ToolConfig<
3838
}),
3939
},
4040

41-
transformResponse: async (response: Response) => {
41+
transformResponse: async (response: Response, params) => {
4242
if (!response.ok) {
4343
const errorText = await response.text()
4444
throw new Error(errorText || `Cancel snapshot failed with status ${response.status}`)
4545
}
4646

47-
const data = (await response.json().catch(() => null)) as Record<string, unknown> | null
47+
await response.json().catch(() => null)
4848
return {
4949
success: true,
5050
output: {
51-
snapshotId: (data?.snapshot_id as string) ?? null,
51+
snapshotId: params?.snapshotId ?? null,
5252
cancelled: true,
5353
},
5454
}

apps/sim/tools/brightdata/discover.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const brightDataDiscoverTool: ToolConfig<
8484
},
8585
},
8686

87-
transformResponse: async (response: Response) => {
87+
transformResponse: async (response: Response, params) => {
8888
if (!response.ok) {
8989
const errorText = await response.text()
9090
throw new Error(errorText || `Discover request failed with status ${response.status}`)
@@ -117,7 +117,7 @@ export const brightDataDiscoverTool: ToolConfig<
117117
success: true,
118118
output: {
119119
results,
120-
query: null,
120+
query: params?.query ?? null,
121121
totalResults: results.length,
122122
},
123123
}

apps/sim/tools/brightdata/download_snapshot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const brightDataDownloadSnapshotTool: ToolConfig<
5656
}),
5757
},
5858

59-
transformResponse: async (response: Response) => {
59+
transformResponse: async (response: Response, params) => {
6060
if (response.status === 409) {
6161
throw new Error(
6262
'Snapshot is not ready for download. Check the snapshot status first and wait until it is "ready".'
@@ -89,7 +89,7 @@ export const brightDataDownloadSnapshotTool: ToolConfig<
8989
output: {
9090
data,
9191
format: contentType,
92-
snapshotId: (data[0]?.snapshot_id as string) ?? null,
92+
snapshotId: params?.snapshotId ?? null,
9393
},
9494
}
9595
},

apps/sim/tools/brightdata/scrape_url.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const brightDataScrapeUrlTool: ToolConfig<
6666
},
6767
},
6868

69-
transformResponse: async (response: Response) => {
69+
transformResponse: async (response: Response, params) => {
7070
const contentType = response.headers.get('content-type') || ''
7171

7272
if (!response.ok) {
@@ -86,7 +86,7 @@ export const brightDataScrapeUrlTool: ToolConfig<
8686
success: true,
8787
output: {
8888
content,
89-
url: null,
89+
url: params?.url ?? null,
9090
statusCode: response.status,
9191
},
9292
}

apps/sim/tools/brightdata/serp_search.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export const brightDataSerpSearchTool: ToolConfig<
129129
},
130130
},
131131

132-
transformResponse: async (response: Response) => {
132+
transformResponse: async (response: Response, params) => {
133133
if (!response.ok) {
134134
const errorText = await response.text()
135135
throw new Error(errorText || `SERP request failed with status ${response.status}`)
@@ -178,9 +178,14 @@ export const brightDataSerpSearchTool: ToolConfig<
178178
success: true,
179179
output: {
180180
results,
181-
query: ((data?.general as Record<string, unknown> | undefined)?.query as string) ?? null,
181+
query:
182+
((data?.general as Record<string, unknown> | undefined)?.query as string) ??
183+
params?.query ??
184+
null,
182185
searchEngine:
183-
((data?.general as Record<string, unknown> | undefined)?.search_engine as string) ?? null,
186+
((data?.general as Record<string, unknown> | undefined)?.search_engine as string) ??
187+
params?.searchEngine ??
188+
null,
184189
},
185190
}
186191
},

0 commit comments

Comments
 (0)