@coldiq/mcp 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/executor.js +1 -1
  2. package/dist/executor.js.map +1 -1
  3. package/dist/registry.d.ts.map +1 -1
  4. package/dist/registry.js +27 -5
  5. package/dist/registry.js.map +1 -1
  6. package/dist/tools/call-endpoint.d.ts +1 -0
  7. package/dist/tools/call-endpoint.d.ts.map +1 -1
  8. package/dist/tools/call-endpoint.js +3 -1
  9. package/dist/tools/call-endpoint.js.map +1 -1
  10. package/dist/tools/extract-post-engagement.d.ts +0 -7
  11. package/dist/tools/extract-post-engagement.d.ts.map +1 -1
  12. package/dist/tools/extract-post-engagement.js +205 -21
  13. package/dist/tools/extract-post-engagement.js.map +1 -1
  14. package/dist/tools/get-endpoint-details.d.ts +1 -0
  15. package/dist/tools/get-endpoint-details.d.ts.map +1 -1
  16. package/dist/tools/get-endpoint-details.js +3 -1
  17. package/dist/tools/get-endpoint-details.js.map +1 -1
  18. package/dist/tools/search-web.d.ts +1 -1
  19. package/dist/tools/search-web.js +2 -2
  20. package/dist/tools/search-web.js.map +1 -1
  21. package/package.json +1 -1
  22. package/src/executor.ts +1 -1
  23. package/src/registry.ts +25 -5
  24. package/src/tools/call-endpoint.ts +3 -1
  25. package/src/tools/extract-post-engagement.ts +229 -27
  26. package/src/tools/get-endpoint-details.ts +3 -1
  27. package/src/tools/search-web.ts +2 -2
  28. package/tests/registry-enrich-person.test.ts +16 -14
  29. package/tests/registry.test.ts +7 -0
  30. package/tests/search-web-exa-compat.test.ts +11 -0
  31. package/tests/tools/call-endpoint.test.ts +16 -0
  32. package/tests/tools/extract-post-engagement.test.ts +167 -3
  33. package/tests/tools/get-endpoint-details.test.ts +12 -0
@@ -6,7 +6,8 @@ export const extractPostEngagementName = 'extract_post_engagement'
6
6
  export const extractPostEngagementDescription =
7
7
  'Extract the people who engaged with a LinkedIn post — commenters and/or reactors — as a deduplicated list of contacts (name, profile URL, headline). ' +
8
8
  'Use this for social-signal prospecting: pull everyone who engaged with a viral post, then chain the results into enrich_person / find_email to get roles and work emails. ' +
9
- 'Runs an async extraction job (typically ~30120s) and returns once the people are ready. Pricing is returned in the response credit headers.'
9
+ 'Runs an async extraction job (typically 13 minutes; longer for posts with 1000+ interactions) and returns every extracted person once ready. ' +
10
+ 'If the primary source fails or its account is out of credits, automatically retries on a second provider and says so in `_meta.provider` — those records carry name/profile URL/headline only, so enrich them before use. Pricing is returned in the response credit headers.'
10
11
 
11
12
  export const extractPostEngagementSchema = {
12
13
  post_url: z
@@ -17,16 +18,133 @@ export const extractPostEngagementSchema = {
17
18
  .enum(['comments', 'reactions', 'both'])
18
19
  .default('both')
19
20
  .describe('Which engagement to extract: "comments" (people who commented), "reactions" (people who reacted), or "both" (default — deduplicated across both).'),
20
- include_replies: z
21
- .boolean()
22
- .optional()
23
- .describe('When extracting comments, also include people who replied to comments. Defaults to true upstream.'),
21
+ // `include_replies` was removed: this tool returns a DEDUPLICATED contact list,
22
+ // where a person is one entry regardless of whether they commented or replied,
23
+ // so the flag never changed the result. Use GET /v1/jungler/workbooks/{id}/comments
24
+ // to work with individual comments and their reply metadata.
25
+ }
26
+
27
+ // One page covers most posts; the loop below still walks the rest when it doesn't.
28
+ const CONTACTS_PAGE_SIZE = 500
29
+ // Backstop so a mis-paginating upstream can't spin this tool forever.
30
+ const MAX_CONTACT_PAGES = 20
31
+
32
+ /**
33
+ * True unless the contact demonstrably engaged with nothing.
34
+ *
35
+ * The workbook always collects the post itself, so the post's AUTHOR comes back
36
+ * as a contact with `stats: {comments: 0, reactions: 0}` even when nobody
37
+ * engaged. This tool promises the people who engaged, so a zero/zero contact is
38
+ * not one of them. Anything without usable stats is kept — never drop a contact
39
+ * on ambiguity.
40
+ */
41
+ function engaged(contact: unknown): boolean {
42
+ if (!contact || typeof contact !== 'object') return true
43
+ const stats = (contact as { stats?: unknown }).stats
44
+ if (!stats || typeof stats !== 'object') return true
45
+ const { comments, reactions } = stats as { comments?: unknown; reactions?: unknown }
46
+ if (typeof comments !== 'number' || typeof reactions !== 'number') return true
47
+ return comments > 0 || reactions > 0
48
+ }
49
+
50
+ /** Read one page of the contacts envelope, tolerating a bare-array response. */
51
+ function readContactsPage(data: unknown): { items: unknown[]; total?: number; pages?: number } {
52
+ if (Array.isArray(data)) return { items: data, pages: 1 }
53
+ if (data && typeof data === 'object') {
54
+ const obj = data as { items?: unknown; total?: unknown; pages?: unknown }
55
+ if (Array.isArray(obj.items)) {
56
+ return {
57
+ items: obj.items,
58
+ total: typeof obj.total === 'number' ? obj.total : undefined,
59
+ pages: typeof obj.pages === 'number' ? obj.pages : undefined,
60
+ }
61
+ }
62
+ }
63
+ return { items: [], pages: 1 }
24
64
  }
25
65
 
26
66
  function sleep(ms: number): Promise<void> {
27
67
  return new Promise((resolve) => setTimeout(resolve, ms))
28
68
  }
29
69
 
70
+ // ── Fallback provider ───────────────────────────────────────────────────────
71
+ //
72
+ // Jungler is the primary: it charges a flat rate per post regardless of size and
73
+ // returns enriched contacts (work email, company domain, title, seniority). Lima
74
+ // Data costs the same per post but returns profile URLs only, so it needs a
75
+ // separate enrichment pass — hence second, not first.
76
+ //
77
+ // We reach for it ONLY when Jungler failed for a reason that is ours, not the
78
+ // post's: a failed run, or an upstream account out of credits. A genuinely empty
79
+ // post must NOT fall through — Lima would return empty too, for another charge.
80
+ // Same env knobs as the primary poll, so a caller (or a test) can tighten both.
81
+ const fallbackPollMs = () => parseInt(process.env.COLDIQ_ENGAGEMENT_POLL_MS ?? '5000', 10)
82
+ const fallbackTimeoutMs = () => parseInt(process.env.COLDIQ_ENGAGEMENT_FALLBACK_TIMEOUT_MS ?? '240000', 10)
83
+
84
+ /** Flatten Lima's `{commenters:{comments:[{actor}]}, reactors:{reactions:[{actor}]}}` into contacts. */
85
+ function limaEngagersToPeople(data: unknown, type: 'comments' | 'reactions' | 'both'): unknown[] {
86
+ if (!data || typeof data !== 'object') return []
87
+ const d = data as {
88
+ commenters?: { comments?: unknown[] }
89
+ reactors?: { reactions?: unknown[] }
90
+ }
91
+ const rows: Array<{ actor?: unknown; engagement: string }> = []
92
+ if (type !== 'reactions') {
93
+ for (const c of d.commenters?.comments ?? []) rows.push({ ...(c as object), engagement: 'COMMENT' } as never)
94
+ }
95
+ if (type !== 'comments') {
96
+ for (const r of d.reactors?.reactions ?? []) rows.push({ ...(r as object), engagement: 'REACTION' } as never)
97
+ }
98
+ // Deduplicate by profile URL: someone who both commented and reacted is one person.
99
+ const byProfile = new Map<string, Record<string, unknown>>()
100
+ for (const row of rows) {
101
+ const actor = (row.actor ?? {}) as Record<string, unknown>
102
+ const key = String(actor.profile_url ?? actor.name ?? Math.random())
103
+ const existing = byProfile.get(key)
104
+ if (existing) {
105
+ const seen = existing.engagement_types as string[]
106
+ if (!seen.includes(row.engagement)) seen.push(row.engagement)
107
+ continue
108
+ }
109
+ byProfile.set(key, {
110
+ name: actor.name ?? null,
111
+ profile_url: actor.profile_url ?? null,
112
+ description: actor.headline ?? null,
113
+ profile_image_url: actor.image_url ?? null,
114
+ engagement_types: [row.engagement],
115
+ })
116
+ }
117
+ return [...byProfile.values()]
118
+ }
119
+
120
+ async function extractViaLimaData(postUrl: string, type: 'comments' | 'reactions' | 'both') {
121
+ const submit = await callApi('POST', '/limadata/batch/post-engagements', { urls: [postUrl] })
122
+ if (!submit.ok) {
123
+ return { ok: false as const, error: extractErrorMessage(submit.data) ?? `Fallback provider failed to start (status ${submit.status})` }
124
+ }
125
+ const batchId = (submit.data as { batch_id?: number | string }).batch_id
126
+ if (batchId === undefined) return { ok: false as const, error: 'Fallback provider did not return a batch id' }
127
+
128
+ const creditsCharged = Number(submit.headers['x-coldiq-credits-charged'])
129
+ const timeoutMs = fallbackTimeoutMs()
130
+ const deadline = Date.now() + timeoutMs
131
+ while (Date.now() < deadline) {
132
+ await sleep(fallbackPollMs())
133
+ const poll = await callApi('POST', '/limadata/batch/results', { batch_id: String(batchId) })
134
+ if (!poll.ok) continue
135
+ const body = poll.data as { items?: Array<{ status?: string; data?: unknown }> }
136
+ const item = body.items?.[0]
137
+ if (!item || String(item.status).toLowerCase() !== 'completed') continue
138
+ return {
139
+ ok: true as const,
140
+ people: limaEngagersToPeople(item.data, type),
141
+ creditsCharged: Number.isFinite(creditsCharged) ? creditsCharged : undefined,
142
+ batchId,
143
+ }
144
+ }
145
+ return { ok: false as const, error: `Fallback provider did not finish within ${Math.round(timeoutMs / 1000)}s`, batchId }
146
+ }
147
+
30
148
  function errorResult(error: string, extra?: Record<string, unknown>) {
31
149
  return {
32
150
  content: [{ type: 'text' as const, text: JSON.stringify({ error, ...extra }) }],
@@ -42,11 +160,50 @@ function extractErrorMessage(data: unknown): string | undefined {
42
160
  return undefined
43
161
  }
44
162
 
163
+ /**
164
+ * Try the fallback provider after the primary failed; if it also fails, report
165
+ * the ORIGINAL failure (that is the one the caller can act on) with the
166
+ * fallback's outcome attached.
167
+ *
168
+ * Set COLDIQ_ENGAGEMENT_FALLBACK=0 to disable — the fallback is a second billable
169
+ * provider, so anyone running to a strict budget must be able to opt out.
170
+ */
171
+ async function fallbackOr(
172
+ postUrl: string,
173
+ type: 'comments' | 'reactions' | 'both',
174
+ primaryError: string,
175
+ extra?: Record<string, unknown>,
176
+ ) {
177
+ if (process.env.COLDIQ_ENGAGEMENT_FALLBACK === '0') {
178
+ return errorResult(primaryError, { post_url: postUrl, ...extra })
179
+ }
180
+
181
+ const fb = await extractViaLimaData(postUrl, type)
182
+ if (!fb.ok) {
183
+ return errorResult(primaryError, { post_url: postUrl, ...extra, fallback_error: fb.error })
184
+ }
185
+
186
+ const meta: Record<string, unknown> = { provider: 'limadata', primary_error: primaryError }
187
+ if (fb.creditsCharged !== undefined) meta.credits_charged = fb.creditsCharged
188
+ return {
189
+ content: [{
190
+ type: 'text' as const,
191
+ text: JSON.stringify({
192
+ data: { post_url: postUrl, type, people: fb.people, count: fb.people.length },
193
+ // Say plainly that these records are thinner than the primary's, so the
194
+ // caller knows to run enrichment before treating them as contacts.
195
+ _meta: {
196
+ ...meta,
197
+ note: 'Served by the fallback provider after the primary failed. These records carry name, profile URL and headline only — no work email or company data. Run enrich_person / find_email on them if you need contact details.',
198
+ },
199
+ }),
200
+ }],
201
+ }
202
+ }
203
+
45
204
  export async function extractPostEngagementHandler(input: Record<string, unknown>) {
46
205
  const postUrl = input.post_url as string
47
206
  const type = (input.type as 'comments' | 'reactions' | 'both' | undefined) ?? 'both'
48
- const includeReplies = input.include_replies as boolean | undefined
49
-
50
207
  const dataTypes =
51
208
  type === 'comments' ? ['comment'] : type === 'reactions' ? ['reaction'] : ['comment', 'reaction']
52
209
 
@@ -56,21 +213,30 @@ export async function extractPostEngagementHandler(input: Record<string, unknown
56
213
  data_types: dataTypes,
57
214
  })
58
215
  if (!createRes.ok) {
59
- return errorResult(extractErrorMessage(createRes.data) ?? `Failed to start extraction (status ${createRes.status})`)
216
+ return fallbackOr(
217
+ postUrl, type,
218
+ extractErrorMessage(createRes.data) ?? `Failed to start extraction (status ${createRes.status})`,
219
+ )
60
220
  }
61
- const createData = createRes.data as { task_id?: string }
221
+ const createData = createRes.data as { task_id?: string; workbook_id?: string }
62
222
  const taskId = createData.task_id
63
223
  if (!taskId) {
64
- return errorResult('Extraction job did not return a task id')
224
+ return fallbackOr(postUrl, type, 'Extraction job did not return a task id')
65
225
  }
226
+ // Kept so a timeout can still hand the caller a way to collect what they paid
227
+ // for — the workbook stays readable upstream for 12 hours.
228
+ const createWorkbookId = createData.workbook_id
66
229
  // Credit headers are emitted on the create call (the only billed step).
67
230
  const creditsCharged = Number(createRes.headers['x-coldiq-credits-charged'])
68
231
  const creditsRemaining = Number(createRes.headers['x-coldiq-credits-remaining'])
69
232
 
70
233
  // Step 2 — poll task status until it resolves. The status endpoint is free, so
71
234
  // polling does not bill; only the create call above charged credits.
72
- const pollIntervalMs = parseInt(process.env.COLDIQ_ENGAGEMENT_POLL_MS ?? '2000', 10)
73
- const timeoutMs = parseInt(process.env.COLDIQ_ENGAGEMENT_TIMEOUT_MS ?? '180000', 10)
235
+ // Upstream quotes 1-3 minutes and explicitly warns that large posts (1000+
236
+ // interactions) take longer which is exactly the viral post this tool is for.
237
+ // A 180s deadline cut those off mid-extraction and reported a bogus timeout.
238
+ const pollIntervalMs = parseInt(process.env.COLDIQ_ENGAGEMENT_POLL_MS ?? '5000', 10)
239
+ const timeoutMs = parseInt(process.env.COLDIQ_ENGAGEMENT_TIMEOUT_MS ?? '600000', 10)
74
240
  const maxPollErrors = 3
75
241
  const deadline = Date.now() + timeoutMs
76
242
 
@@ -88,46 +254,82 @@ export async function extractPostEngagementHandler(input: Record<string, unknown
88
254
  continue
89
255
  }
90
256
  consecutivePollErrors = 0
91
- const status = (statusRes.data as { status?: string; workbook_id?: string }).status
257
+ const statusData = statusRes.data as { status?: string; workbook_id?: string; credits_exhausted?: boolean }
258
+ const status = statusData.status
92
259
  if (status === 'success') {
93
- workbookId = (statusRes.data as { workbook_id?: string }).workbook_id
260
+ // A credits-exhausted run is terminal but collected little or nothing
261
+ // because OUR provider account ran dry — the caller's request is sound, so
262
+ // route it to the fallback rather than handing back a hollow result. This
263
+ // charge is refunded server-side.
264
+ if (statusData.credits_exhausted) {
265
+ return fallbackOr(
266
+ postUrl, type,
267
+ 'Engagement extraction stopped early — the data provider account is out of credits (this request was refunded)',
268
+ { task_id: taskId },
269
+ )
270
+ }
271
+ workbookId = statusData.workbook_id
94
272
  break
95
273
  }
96
274
  if (status === 'failure') {
97
- return errorResult('Engagement extraction failed upstream the post may be private, deleted, or have no engagement', { post_url: postUrl })
275
+ // The status route refunds the create charge when a run reaches failure,
276
+ // so the user is made whole — say so rather than leaving them to wonder.
277
+ return fallbackOr(
278
+ postUrl, type,
279
+ 'Engagement extraction failed upstream — the post may be private, deleted, or have no engagement. The credits for this task have been refunded.',
280
+ { task_id: taskId },
281
+ )
98
282
  }
99
283
  }
100
284
 
101
285
  if (!workbookId) {
102
- return errorResult(`Engagement extraction did not complete within ${Math.round(timeoutMs / 1000)}s try again shortly`, { post_url: postUrl })
286
+ // Giving up here does NOT cancel the run, and the create call was already
287
+ // billed. Never drop that on the floor: hand back the ids so the caller can
288
+ // collect the results (upstream keeps the workbook for 12 hours) instead of
289
+ // paying again for a re-run that is probably still in flight.
290
+ return errorResult(
291
+ `Engagement extraction is still running after ${Math.round(timeoutMs / 1000)}s. It has NOT been cancelled and no re-run is needed — poll GET /v1/jungler/tasks/${taskId}/status until it reports success, then fetch the people from GET /v1/jungler/workbooks/${createWorkbookId ?? '{workbook_id}'}/contacts. Results stay available for 12 hours after the task was created.`,
292
+ { post_url: postUrl, task_id: taskId, workbook_id: createWorkbookId, status: 'running' },
293
+ )
103
294
  }
104
295
 
105
296
  // Step 3 — fetch the deduplicated people. activity_filter narrows to commenters
106
297
  // or reactors; omitted for "both" so the upstream returns all unique contacts.
107
- const queryParams: Record<string, string> = {}
298
+ // Contacts are paginated, and a viral post — the case this tool exists for —
299
+ // routinely exceeds one page, so walk every page rather than truncating to the
300
+ // first. Reads are free, so pagination costs the caller nothing.
301
+ const queryParams: Record<string, string> = { page_size: String(CONTACTS_PAGE_SIZE) }
108
302
  if (type === 'comments') queryParams.activity_filter = 'commenters'
109
303
  else if (type === 'reactions') queryParams.activity_filter = 'reactors'
110
- if (includeReplies !== undefined) queryParams.include_replies = String(includeReplies)
111
304
 
112
- const contactsRes = await callApi(
113
- 'GET',
114
- `/jungler/workbooks/${workbookId}/contacts`,
115
- undefined,
116
- Object.keys(queryParams).length > 0 ? queryParams : undefined,
117
- )
118
- if (!contactsRes.ok) {
119
- return errorResult(extractErrorMessage(contactsRes.data) ?? 'Failed to fetch extracted people', { post_url: postUrl })
305
+ const people: unknown[] = []
306
+ let totalContacts: number | undefined
307
+ for (let page = 1; page <= MAX_CONTACT_PAGES; page++) {
308
+ const contactsRes = await callApi(
309
+ 'GET',
310
+ `/jungler/workbooks/${workbookId}/contacts`,
311
+ undefined,
312
+ { ...queryParams, page: String(page) },
313
+ )
314
+ if (!contactsRes.ok) {
315
+ return errorResult(extractErrorMessage(contactsRes.data) ?? 'Failed to fetch extracted people', { post_url: postUrl, task_id: taskId, workbook_id: workbookId })
316
+ }
317
+ const { items, total, pages } = readContactsPage(contactsRes.data)
318
+ people.push(...items.filter(engaged))
319
+ totalContacts = total
320
+ if (items.length === 0 || (pages !== undefined && page >= pages)) break
120
321
  }
121
322
 
122
323
  const meta: Record<string, unknown> = {}
123
324
  if (Number.isFinite(creditsCharged)) meta.credits_charged = creditsCharged
124
325
  if (Number.isFinite(creditsRemaining)) meta.credits_remaining = creditsRemaining
326
+ if (totalContacts !== undefined && totalContacts > people.length) meta.truncated_from = totalContacts
125
327
 
126
328
  return {
127
329
  content: [{
128
330
  type: 'text' as const,
129
331
  text: JSON.stringify({
130
- data: { post_url: postUrl, type, people: contactsRes.data },
332
+ data: { post_url: postUrl, type, people, count: people.length },
131
333
  _meta: meta,
132
334
  }),
133
335
  }],
@@ -11,10 +11,12 @@ export const getEndpointDetailsDescription =
11
11
  export const getEndpointDetailsSchema = {
12
12
  api: z.string().describe('Provider key from search_endpoints, e.g. "coldiq" (Lima Data), "apollo", or "exa".'),
13
13
  path: z.string().describe('Endpoint path without the /v1 prefix, e.g. "/limadata/prospect/people/filter".'),
14
+ method: z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']).optional()
15
+ .describe('HTTP method from search_endpoints. Set this when one path supports more than one method.'),
14
16
  }
15
17
 
16
18
  export async function getEndpointDetailsHandler(input: Record<string, unknown>) {
17
- const res = await callApi('POST', '/endpoints/details', { api: input.api, path: input.path })
19
+ const res = await callApi('POST', '/endpoints/details', { api: input.api, path: input.path, method: input.method })
18
20
  if (!res.ok) {
19
21
  return {
20
22
  content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Endpoint not found or details unavailable', status: res.status, data: res.data }) }],
@@ -5,7 +5,7 @@ import { getProvidersForCapability } from '../utils/provider-resolver.js'
5
5
  export const searchWebName = 'search_web'
6
6
 
7
7
  export const searchWebDescription =
8
- 'Search the web for market research, company news, or general lookups. Supports Google search (default) and neural/semantic search via Exa. ' +
8
+ 'Search the web for market research, company news, or general lookups. Supports Google search (default), Exa auto through the neural compatibility alias, and Exa deep modes. ' +
9
9
  'NEVER use this to find, verify, or look up people, contacts, LinkedIn profiles, or executives — even as a fallback when find_people returns uncertain results. ' +
10
10
  'find_people is the only tool for people lookups; do not supplement or replace it with web search. ' +
11
11
  'ColdIQ automatically picks the best provider — pass use_providers only if you need a specific tool.'
@@ -14,7 +14,7 @@ export const searchWebSchema = {
14
14
  query: z.string().describe('Search query'),
15
15
  num_results: z.number().min(1).max(100).default(10).describe('Number of results (default: 10, max: 100)'),
16
16
  country: z.string().optional().describe('Country code for geo-targeting (e.g. "us", "fr")'),
17
- search_type: z.enum(['general', 'neural']).default('general').describe('"general" for Google search (default), "neural" for semantic search via Exa'),
17
+ search_type: z.enum(['general', 'neural', 'deep', 'deep-reasoning']).default('general').describe('"general" for the default web search, "neural" for Exa auto compatibility, or an Exa deep mode'),
18
18
  use_providers: z.array(z.string()).optional().describe(`Optional ordered list of providers to use. Leave empty to let ColdIQ automatically pick the best tool for your inputs — recommended for most use cases. Available providers: ${getProvidersForCapability('search_web').join(', ')}. Provider names are matched fuzzily, so minor typos are tolerated.`),
19
19
  }
20
20
 
@@ -390,20 +390,22 @@ describe('icypeas-reverse-email-lookup', () => {
390
390
  })
391
391
  })
392
392
 
393
- it('hasResult: true when non-empty profiles array', () => {
394
- expect(p().hasResult({ profiles: [{ name: 'Michel Lieben' }] })).toBe(true)
395
- })
396
-
397
- it('hasResult: true when success + data', () => {
398
- expect(p().hasResult({ success: true, data: { name: 'Michel Lieben' } })).toBe(true)
399
- })
400
-
401
- it('hasResult: false when profiles is empty array', () => {
402
- expect(p().hasResult({ profiles: [] })).toBe(false)
403
- })
404
-
405
- it('hasResult: false on empty object', () => {
406
- expect(p().hasResult({})).toBe(false)
393
+ it('hasResult: true for the documented hit shape', () => {
394
+ expect(p().hasResult({
395
+ success: true,
396
+ status: 'FOUND',
397
+ results: 'https://www.linkedin.com/in/michel-lieben',
398
+ })).toBe(true)
399
+ })
400
+
401
+ it.each([
402
+ { success: true, status: 'NOT_FOUND', results: 'https://www.linkedin.com/in/michel-lieben' },
403
+ { success: false, validationErrors: ['Invalid email'] },
404
+ { success: true },
405
+ { profiles: [{ name: 'Michel Lieben' }] },
406
+ { success: true, data: { name: 'Michel Lieben' } },
407
+ ])('hasResult: false for a miss, invalid, or unknown body', (body) => {
408
+ expect(p().hasResult(body)).toBe(false)
407
409
  })
408
410
  })
409
411
 
@@ -20,6 +20,13 @@ const ALL_CAPABILITIES: Capability[] = [
20
20
  ]
21
21
 
22
22
  describe('registry', () => {
23
+ it('maps the neural compatibility alias to Exa auto and preserves deep modes', () => {
24
+ const exa = getConfiguredProviders('search_web').find((provider) => provider.id === 'exa')!
25
+ expect(exa.mapParams({ query: 'ColdIQ', search_type: 'neural' }).body).toMatchObject({ type: 'auto' })
26
+ expect(exa.mapParams({ query: 'ColdIQ', search_type: 'deep' }).body).toMatchObject({ type: 'deep' })
27
+ expect(exa.mapParams({ query: 'ColdIQ', search_type: 'deep-reasoning' }).body).toMatchObject({ type: 'deep-reasoning' })
28
+ })
29
+
23
30
  it('every capability has at least one provider', () => {
24
31
  for (const cap of ALL_CAPABILITIES) {
25
32
  const providers = getProviders(cap)
@@ -0,0 +1,11 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { z } from 'zod'
3
+ import { searchWebSchema } from '../src/tools/search-web.js'
4
+
5
+ const schema = z.object(searchWebSchema)
6
+
7
+ describe('search_web Exa compatibility', () => {
8
+ it.each(['general', 'neural', 'deep', 'deep-reasoning'])('accepts %s', (search_type) => {
9
+ expect(schema.safeParse({ query: 'ColdIQ', search_type }).success).toBe(true)
10
+ })
11
+ })
@@ -38,4 +38,20 @@ describe('call_endpoint handler', () => {
38
38
  expect(parsed.status).toBe(404)
39
39
  expect(parsed.error).toBe('Endpoint call failed')
40
40
  })
41
+
42
+ it('forwards the HTTP method for a shared endpoint path', async () => {
43
+ let capturedBody: unknown
44
+ globalThis.fetch = vi.fn(async (_url: string | URL | Request, opts?: RequestInit) => {
45
+ capturedBody = opts?.body ? JSON.parse(opts.body as string) : undefined
46
+ return new Response(JSON.stringify({ ok: true, status: 201, data: { id: 'run_1' } }), { status: 200 })
47
+ }) as typeof fetch
48
+
49
+ await callEndpointHandler({
50
+ api: 'exa', path: '/exa/agent/runs', method: 'POST', params: { query: 'Research ColdIQ' },
51
+ })
52
+
53
+ expect(capturedBody).toEqual({
54
+ api: 'exa', path: '/exa/agent/runs', method: 'POST', params: { query: 'Research ColdIQ' },
55
+ })
56
+ })
41
57
  })