d25d482dc2
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
132 lines
3.6 KiB
TypeScript
132 lines
3.6 KiB
TypeScript
import type {
|
|
BrightDataSyncScrapeParams,
|
|
BrightDataSyncScrapeResponse,
|
|
} from '@/tools/brightdata/types'
|
|
import type { ToolConfig } from '@/tools/types'
|
|
|
|
export const brightDataSyncScrapeTool: ToolConfig<
|
|
BrightDataSyncScrapeParams,
|
|
BrightDataSyncScrapeResponse
|
|
> = {
|
|
id: 'brightdata_sync_scrape',
|
|
name: 'Bright Data Sync Scrape',
|
|
description:
|
|
'Scrape URLs synchronously using a Bright Data pre-built scraper and get structured results directly. Supports up to 20 URLs with a 1-minute timeout.',
|
|
version: '1.0.0',
|
|
|
|
params: {
|
|
apiKey: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-only',
|
|
description: 'Bright Data API token',
|
|
},
|
|
datasetId: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description:
|
|
'Dataset scraper ID from your Bright Data dashboard (e.g., "gd_l1viktl72bvl7bjuj0")',
|
|
},
|
|
urls: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description:
|
|
'JSON array of URL objects to scrape, up to 20 (e.g., [{"url": "https://example.com/product"}])',
|
|
},
|
|
format: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Output format: "json", "ndjson", or "csv". Defaults to "json"',
|
|
},
|
|
includeErrors: {
|
|
type: 'boolean',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Whether to include error reports in results',
|
|
},
|
|
},
|
|
|
|
request: {
|
|
method: 'POST',
|
|
url: (params) => {
|
|
const queryParams = new URLSearchParams()
|
|
queryParams.set('dataset_id', params.datasetId.trim())
|
|
queryParams.set('format', params.format || 'json')
|
|
if (params.includeErrors) queryParams.set('include_errors', 'true')
|
|
return `https://api.brightdata.com/datasets/v3/scrape?${queryParams.toString()}`
|
|
},
|
|
headers: (params) => ({
|
|
'Content-Type': 'application/json',
|
|
Authorization: `Bearer ${params.apiKey}`,
|
|
}),
|
|
body: (params) => {
|
|
if (typeof params.urls === 'string') {
|
|
try {
|
|
const parsed = JSON.parse(params.urls)
|
|
return { input: Array.isArray(parsed) ? parsed : [parsed] }
|
|
} catch {
|
|
return { input: [{ url: params.urls }] }
|
|
}
|
|
}
|
|
return { input: params.urls }
|
|
},
|
|
},
|
|
|
|
transformResponse: async (response: Response) => {
|
|
if (!response.ok) {
|
|
const errorText = await response.text()
|
|
throw new Error(errorText || `Sync scrape failed with status ${response.status}`)
|
|
}
|
|
|
|
if (response.status === 202) {
|
|
const data = await response.json()
|
|
return {
|
|
success: true,
|
|
output: {
|
|
data: [],
|
|
snapshotId: data.snapshot_id ?? null,
|
|
isAsync: true,
|
|
},
|
|
}
|
|
}
|
|
|
|
const data = await response.json()
|
|
const results = Array.isArray(data) ? data : [data]
|
|
|
|
return {
|
|
success: true,
|
|
output: {
|
|
data: results,
|
|
snapshotId: null,
|
|
isAsync: false,
|
|
},
|
|
}
|
|
},
|
|
|
|
outputs: {
|
|
data: {
|
|
type: 'array',
|
|
description:
|
|
'Array of scraped result objects with fields specific to the dataset scraper used',
|
|
items: {
|
|
type: 'json',
|
|
description: 'A scraped record with dataset-specific fields',
|
|
},
|
|
},
|
|
snapshotId: {
|
|
type: 'string',
|
|
description:
|
|
'Snapshot ID returned if the request exceeded the 1-minute timeout and switched to async processing',
|
|
optional: true,
|
|
},
|
|
isAsync: {
|
|
type: 'boolean',
|
|
description:
|
|
'Whether the request fell back to async mode (true means use snapshot ID to retrieve results)',
|
|
},
|
|
},
|
|
}
|