-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathautocomplete.ts
More file actions
102 lines (94 loc) · 2.99 KB
/
Copy pathautocomplete.ts
File metadata and controls
102 lines (94 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import type { PdlAutocompleteParams, PdlAutocompleteResponse } from '@/tools/peopledatalabs/types'
import { buildQueryString } from '@/tools/peopledatalabs/utils'
import type { OutputProperty, ToolConfig } from '@/tools/types'
const SUGGESTION_PROPERTIES = {
name: { type: 'string', description: 'Suggestion value' },
count: { type: 'number', description: 'Number of records matching this value' },
meta: {
type: 'object',
description: 'Field-specific metadata (e.g., for `company`: id, website, industry)',
optional: true,
},
} as const satisfies Record<string, OutputProperty>
export const autocompleteTool: ToolConfig<PdlAutocompleteParams, PdlAutocompleteResponse> = {
id: 'pdl_autocomplete',
name: 'PDL Autocomplete',
description:
'Get autocomplete suggestions for a PDL field (title, skill, company, industry, location, school, major, role, sub_role).',
version: '1.0.0',
params: {
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'People Data Labs API key',
},
field: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description:
'Field to autocomplete: all_location, class, company, country, industry, location_name, major, region, role, school, sub_role, skill, title, website',
},
text: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Search text prefix',
},
size: {
type: 'number',
required: false,
visibility: 'user-or-llm',
description: 'Number of suggestions to return (1-100, default 10)',
},
titlecase: {
type: 'boolean',
required: false,
visibility: 'user-or-llm',
description: 'Return name fields in title case',
},
},
request: {
url: (params) => {
const qs = buildQueryString({
field: params.field,
text: params.text,
size: params.size,
titlecase: params.titlecase,
})
return `https://api.peopledatalabs.com/v5/autocomplete${qs}`
},
method: 'GET',
headers: (params) => ({
'X-Api-Key': params.apiKey,
Accept: 'application/json',
}),
},
transformResponse: async (response: Response) => {
const data = (await response.json()) as Record<string, unknown>
if (!response.ok) {
const error = (data.error as { message?: string })?.message
throw new Error(error || `People Data Labs error: ${response.status}`)
}
const items =
(data.data as { name: string; count: number; meta?: Record<string, unknown> }[]) ?? []
return {
success: true,
output: {
suggestions: items.map((item) => ({
name: item.name,
count: item.count ?? 0,
meta: item.meta ?? undefined,
})),
},
}
},
outputs: {
suggestions: {
type: 'array',
description: 'Autocomplete suggestions ordered by frequency',
items: { type: 'object', properties: SUGGESTION_PROPERTIES },
},
},
}