Files
simstudioai--sim/apps/sim/tools/peopledatalabs/location_clean.ts
T
wehub-resource-sync d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
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
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

87 lines
2.5 KiB
TypeScript

import type { PdlCleanLocationParams, PdlCleanLocationResponse } from '@/tools/peopledatalabs/types'
import {
PDL_LOCATION_OUTPUT_PROPERTIES,
PEOPLEDATALABS_API_KEY_PREFIX,
} from '@/tools/peopledatalabs/types'
import { projectLocation } from '@/tools/peopledatalabs/utils'
import type { ToolConfig } from '@/tools/types'
export const cleanLocationTool: ToolConfig<PdlCleanLocationParams, PdlCleanLocationResponse> = {
id: 'pdl_clean_location',
name: 'PDL Location Cleaner',
description:
'Normalize a freeform location string into a structured locality/region/country record with coordinates.',
version: '1.0.0',
hosting: {
envKeyPrefix: PEOPLEDATALABS_API_KEY_PREFIX,
apiKeyParam: 'apiKey',
byokProviderId: 'peopledatalabs',
// Cleaner APIs are free on PDL (rate-limited only) — no credits consumed.
pricing: { type: 'per_request', cost: 0 },
rateLimit: {
mode: 'per_request',
requestsPerMinute: 60,
},
},
params: {
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'People Data Labs API key',
},
location: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Raw location string (e.g., "SF, CA")',
},
},
request: {
url: () => 'https://api.peopledatalabs.com/v5/location/clean',
method: 'POST',
headers: (params) => ({
'X-Api-Key': params.apiKey,
'Content-Type': 'application/json',
Accept: 'application/json',
}),
body: (params) => ({ location: params.location }),
},
transformResponse: async (response: Response) => {
const data = (await response.json()) as Record<string, unknown>
const status = (data.status as number) ?? response.status
if (status === 404) {
return { success: true, output: { matched: false, location: null } }
}
if (!response.ok) {
const error = (data.error as { message?: string })?.message
throw new Error(error || `People Data Labs error: ${response.status}`)
}
const hasFields = data.name || data.locality || data.country
return {
success: true,
output: {
matched: Boolean(hasFields),
location: hasFields ? projectLocation(data) : null,
},
}
},
outputs: {
matched: { type: 'boolean', description: 'Whether the input was matched to a known location' },
location: {
type: 'object',
description: 'Canonical location record',
optional: true,
properties: PDL_LOCATION_OUTPUT_PROPERTIES,
},
},
}