@leadbay/mcp 0.36.0 → 0.37.0
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.
- package/CHANGELOG.md +20 -0
- package/dist/bin.js +2664 -80
- package/dist/http-server.js +2677 -133
- package/dist/installer-electron.js +1 -1
- package/dist/installer-gui.js +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -30,6 +30,13 @@ function makeCancelledError(method, url) {
|
|
|
30
30
|
err.code = "CANCELLED";
|
|
31
31
|
return err;
|
|
32
32
|
}
|
|
33
|
+
function timeoutError(what, timeoutMs) {
|
|
34
|
+
const err = new Error(what);
|
|
35
|
+
err.code = "TIMEOUT";
|
|
36
|
+
if (timeoutMs !== void 0)
|
|
37
|
+
err.timeout_ms = timeoutMs;
|
|
38
|
+
return err;
|
|
39
|
+
}
|
|
33
40
|
function httpsRequest(method, url, headers, body, timeoutMs, signal) {
|
|
34
41
|
const deadlineMs = timeoutMs ?? defaultTimeoutMs();
|
|
35
42
|
const abortSignal = signal ?? requestSignalStore.getStore();
|
|
@@ -58,7 +65,12 @@ function httpsRequest(method, url, headers, body, timeoutMs, signal) {
|
|
|
58
65
|
port: 443,
|
|
59
66
|
path: parsed.pathname + parsed.search,
|
|
60
67
|
method,
|
|
61
|
-
headers: reqHeaders
|
|
68
|
+
headers: reqHeaders,
|
|
69
|
+
// Node aborts the socket and emits an AbortError on `error`, which the
|
|
70
|
+
// handler below rejects with. Without this a cancelled tool call sat on
|
|
71
|
+
// an in-flight GET until the server answered — the polling loop cannot
|
|
72
|
+
// honour its advertised <=2s exit while blocked inside one.
|
|
73
|
+
signal
|
|
62
74
|
}, (res) => {
|
|
63
75
|
const chunks = [];
|
|
64
76
|
res.on("data", (chunk) => chunks.push(chunk));
|
|
@@ -360,18 +372,70 @@ var init_client = __esm({
|
|
|
360
372
|
get _semaphoreState() {
|
|
361
373
|
return { active: this.activeRequests, queued: this.waitQueue.length };
|
|
362
374
|
}
|
|
363
|
-
|
|
375
|
+
// `signal` makes a QUEUED acquisition abortable. Without it a cancelled call
|
|
376
|
+
// that arrived when all MAX_CONCURRENT slots were busy could not observe the
|
|
377
|
+
// abort until an unrelated request finished — the signal was only forwarded
|
|
378
|
+
// to the socket, which this call had not reached yet. Against slow or stalled
|
|
379
|
+
// peers that stranded the caller well past the <=2s exit the delivery tools
|
|
380
|
+
// advertise.
|
|
381
|
+
// `deadlineAt` is an ABSOLUTE epoch-ms bound covering the queue wait itself.
|
|
382
|
+
// Without it a bounded call could still be stranded here without limit: the
|
|
383
|
+
// deadline was only handed to httpsRequest, which does not start until this
|
|
384
|
+
// resolves, so five slow peers let even `wait_seconds: 1` run unbounded. The
|
|
385
|
+
// wait a caller asked for is wall-clock, not socket time.
|
|
386
|
+
// `budgetMs` is the DURATION `deadlineAt` was derived from. Only the caller
|
|
387
|
+
// knows it — an absolute deadline cannot be turned back into "how long did we
|
|
388
|
+
// agree to wait" here — and the timeout error needs it, or the envelope
|
|
389
|
+
// reports the 600,000ms default instead of the seconds actually granted.
|
|
390
|
+
async acquireSemaphore(signal, deadlineAt, budgetMs) {
|
|
391
|
+
if (signal?.aborted)
|
|
392
|
+
throw this.cancelledBeforeSendError();
|
|
393
|
+
if (deadlineAt !== void 0 && Date.now() >= deadlineAt) {
|
|
394
|
+
throw timeoutError("Request deadline expired before a request slot was free", budgetMs);
|
|
395
|
+
}
|
|
364
396
|
if (this.activeRequests < MAX_CONCURRENT) {
|
|
365
397
|
this.activeRequests++;
|
|
366
398
|
return;
|
|
367
399
|
}
|
|
368
|
-
return new Promise((resolve) => {
|
|
369
|
-
|
|
400
|
+
return new Promise((resolve, reject) => {
|
|
401
|
+
let timer;
|
|
402
|
+
const waiter = () => {
|
|
403
|
+
cleanup();
|
|
370
404
|
this.activeRequests++;
|
|
371
405
|
resolve();
|
|
372
|
-
}
|
|
406
|
+
};
|
|
407
|
+
const drop = () => {
|
|
408
|
+
const i = this.waitQueue.indexOf(waiter);
|
|
409
|
+
if (i !== -1)
|
|
410
|
+
this.waitQueue.splice(i, 1);
|
|
411
|
+
cleanup();
|
|
412
|
+
};
|
|
413
|
+
const onAbort = () => {
|
|
414
|
+
drop();
|
|
415
|
+
reject(this.cancelledBeforeSendError());
|
|
416
|
+
};
|
|
417
|
+
const onDeadline = () => {
|
|
418
|
+
drop();
|
|
419
|
+
reject(timeoutError("Request deadline expired while queued for a request slot", budgetMs));
|
|
420
|
+
};
|
|
421
|
+
const cleanup = () => {
|
|
422
|
+
signal?.removeEventListener("abort", onAbort);
|
|
423
|
+
if (timer !== void 0)
|
|
424
|
+
clearTimeout(timer);
|
|
425
|
+
};
|
|
426
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
427
|
+
if (deadlineAt !== void 0) {
|
|
428
|
+
timer = setTimeout(onDeadline, Math.max(deadlineAt - Date.now(), 0));
|
|
429
|
+
timer.unref?.();
|
|
430
|
+
}
|
|
431
|
+
this.waitQueue.push(waiter);
|
|
373
432
|
});
|
|
374
433
|
}
|
|
434
|
+
// Cancelled while queued — nothing was ever put on the wire, which is what
|
|
435
|
+
// makes this safe to report as "not sent" even for a write.
|
|
436
|
+
cancelledBeforeSendError() {
|
|
437
|
+
return this.makeError("REQUEST_CANCELLED", "The request was cancelled before it was sent.", "Re-call the tool if you still want the result \u2014 nothing reached the API, so nothing was charged.");
|
|
438
|
+
}
|
|
375
439
|
releaseSemaphore() {
|
|
376
440
|
this.activeRequests--;
|
|
377
441
|
const next = this.waitQueue.shift();
|
|
@@ -413,16 +477,52 @@ var init_client = __esm({
|
|
|
413
477
|
// The 250ms backoff releases the concurrency slot first (release → sleep →
|
|
414
478
|
// re-acquire) so a wave of 401s doesn't pin all MAX_CONCURRENT slots in
|
|
415
479
|
// setTimeout and stall the queue.
|
|
416
|
-
httpsRequestWithRetry = async (method, url, headers, body, timeoutMs) => {
|
|
417
|
-
const
|
|
480
|
+
httpsRequestWithRetry = async (method, url, headers, body, timeoutMs, signal, held, totalDeadlineAt) => {
|
|
481
|
+
const perAttemptOptOut = timeoutMs !== void 0 && timeoutMs <= 0;
|
|
482
|
+
const retryStartedAt = Date.now();
|
|
483
|
+
const phaseBudget = () => {
|
|
484
|
+
const now = Date.now();
|
|
485
|
+
const perAttempt = timeoutMs !== void 0 && !perAttemptOptOut ? now + timeoutMs : void 0;
|
|
486
|
+
const deadline = totalDeadlineAt === void 0 ? perAttempt : perAttempt === void 0 ? totalDeadlineAt : Math.min(perAttempt, totalDeadlineAt);
|
|
487
|
+
if (deadline === void 0)
|
|
488
|
+
return perAttemptOptOut ? timeoutMs : void 0;
|
|
489
|
+
const left = deadline - now;
|
|
490
|
+
if (left <= 0) {
|
|
491
|
+
throw timeoutError(`Request deadline expired: ${method} ${url}`, Math.max(0, deadline - retryStartedAt));
|
|
492
|
+
}
|
|
493
|
+
return left;
|
|
494
|
+
};
|
|
495
|
+
const phaseDeadline = () => {
|
|
496
|
+
const b = phaseBudget();
|
|
497
|
+
if (b === void 0 || b <= 0)
|
|
498
|
+
return void 0;
|
|
499
|
+
return Date.now() + b;
|
|
500
|
+
};
|
|
501
|
+
const res = await httpsRequest(method, url, headers, body, phaseBudget(), signal);
|
|
418
502
|
if (res.status === 401 && retriesOn401(method)) {
|
|
503
|
+
if (signal?.aborted)
|
|
504
|
+
return res;
|
|
419
505
|
this.releaseSemaphore();
|
|
506
|
+
if (held)
|
|
507
|
+
held.value = false;
|
|
420
508
|
try {
|
|
421
|
-
await new Promise((
|
|
509
|
+
await new Promise((resolve) => {
|
|
510
|
+
const t = setTimeout(done, 250);
|
|
511
|
+
function done() {
|
|
512
|
+
clearTimeout(t);
|
|
513
|
+
signal?.removeEventListener("abort", done);
|
|
514
|
+
resolve();
|
|
515
|
+
}
|
|
516
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
517
|
+
});
|
|
422
518
|
} finally {
|
|
423
|
-
await this.acquireSemaphore();
|
|
519
|
+
await this.acquireSemaphore(held ? signal : void 0, phaseDeadline(), phaseBudget());
|
|
520
|
+
if (held)
|
|
521
|
+
held.value = true;
|
|
424
522
|
}
|
|
425
|
-
|
|
523
|
+
if (signal?.aborted)
|
|
524
|
+
return res;
|
|
525
|
+
return httpsRequest(method, url, headers, body, phaseBudget(), signal);
|
|
426
526
|
}
|
|
427
527
|
return res;
|
|
428
528
|
};
|
|
@@ -435,8 +535,43 @@ var init_client = __esm({
|
|
|
435
535
|
}
|
|
436
536
|
const retryOn401 = opts?.retryOn401 !== false;
|
|
437
537
|
const retriedOn401 = retryOn401 && retriesOn401(method);
|
|
438
|
-
|
|
538
|
+
const held = { value: true };
|
|
539
|
+
const startedAt = Date.now();
|
|
540
|
+
const totalDeadlineAt = opts?.totalTimeoutMs !== void 0 ? startedAt + opts.totalTimeoutMs : void 0;
|
|
541
|
+
const perAttemptOptOut = opts?.timeoutMs !== void 0 && opts.timeoutMs <= 0;
|
|
542
|
+
const phaseDeadlineAt = () => {
|
|
543
|
+
const now = Date.now();
|
|
544
|
+
const perAttempt = opts?.timeoutMs !== void 0 && !perAttemptOptOut ? now + opts.timeoutMs : void 0;
|
|
545
|
+
if (totalDeadlineAt === void 0)
|
|
546
|
+
return perAttempt;
|
|
547
|
+
if (perAttempt === void 0)
|
|
548
|
+
return totalDeadlineAt;
|
|
549
|
+
return Math.min(perAttempt, totalDeadlineAt);
|
|
550
|
+
};
|
|
551
|
+
const grantedBudget = () => {
|
|
552
|
+
const bounds = [opts?.timeoutMs, opts?.totalTimeoutMs].filter((n) => typeof n === "number" && n > 0);
|
|
553
|
+
return bounds.length ? Math.min(...bounds) : void 0;
|
|
554
|
+
};
|
|
555
|
+
const remainingBudget = () => {
|
|
556
|
+
const deadline = phaseDeadlineAt();
|
|
557
|
+
if (deadline === void 0)
|
|
558
|
+
return perAttemptOptOut ? opts?.timeoutMs : void 0;
|
|
559
|
+
const left = deadline - Date.now();
|
|
560
|
+
if (left <= 0) {
|
|
561
|
+
throw timeoutError(`Request deadline expired: ${method} ${path}`, grantedBudget());
|
|
562
|
+
}
|
|
563
|
+
return left;
|
|
564
|
+
};
|
|
565
|
+
const queueDeadlineAt = () => totalDeadlineAt;
|
|
566
|
+
const queueBudget = () => typeof opts?.totalTimeoutMs === "number" && opts.totalTimeoutMs > 0 ? opts.totalTimeoutMs : void 0;
|
|
567
|
+
try {
|
|
568
|
+
await this.acquireSemaphore(opts?.signal ?? opts?.preSendSignal, queueDeadlineAt(), queueBudget());
|
|
569
|
+
} catch (e) {
|
|
570
|
+
throw this.mapTransportError(e, `${method} ${path}`);
|
|
571
|
+
}
|
|
439
572
|
try {
|
|
573
|
+
if (opts?.preSendSignal?.aborted)
|
|
574
|
+
throw this.cancelledBeforeSendError();
|
|
440
575
|
const url = `${this._baseUrl}${API_PREFIX}${path}`;
|
|
441
576
|
const headers = {
|
|
442
577
|
Authorization: `Bearer ${this.token}`
|
|
@@ -444,7 +579,17 @@ var init_client = __esm({
|
|
|
444
579
|
if (body) {
|
|
445
580
|
headers["Content-Type"] = "application/json";
|
|
446
581
|
}
|
|
447
|
-
const
|
|
582
|
+
const payload = body ? JSON.stringify(body) : void 0;
|
|
583
|
+
const res = retryOn401 ? await this.httpsRequestWithRetry(method, url, headers, payload, opts?.timeoutMs, opts?.signal, held, totalDeadlineAt) : await httpsRequest(
|
|
584
|
+
method,
|
|
585
|
+
url,
|
|
586
|
+
headers,
|
|
587
|
+
payload,
|
|
588
|
+
// What is LEFT after queueing, not the original budget — otherwise
|
|
589
|
+
// the queue wait and the socket wait each get the full allowance.
|
|
590
|
+
remainingBudget(),
|
|
591
|
+
opts?.signal
|
|
592
|
+
);
|
|
448
593
|
this._lastMeta = {
|
|
449
594
|
region: this._region,
|
|
450
595
|
endpoint: `${method} ${path}`,
|
|
@@ -461,7 +606,8 @@ var init_client = __esm({
|
|
|
461
606
|
} catch (e) {
|
|
462
607
|
throw this.mapTransportError(e, `${method} ${path}`);
|
|
463
608
|
} finally {
|
|
464
|
-
|
|
609
|
+
if (held.value)
|
|
610
|
+
this.releaseSemaphore();
|
|
465
611
|
}
|
|
466
612
|
}
|
|
467
613
|
async requestVoid(method, path, body) {
|
|
@@ -950,6 +1096,7 @@ var init_composite_file_names = __esm({
|
|
|
950
1096
|
"leadbay_delete_custom_field",
|
|
951
1097
|
"leadbay_enrich_titles",
|
|
952
1098
|
"leadbay_extend_lens",
|
|
1099
|
+
"leadbay_find_new_leads",
|
|
953
1100
|
"leadbay_followups_map",
|
|
954
1101
|
"leadbay_get_lead_custom_fields",
|
|
955
1102
|
"leadbay_get_qualification_questions",
|
|
@@ -957,12 +1104,14 @@ var init_composite_file_names = __esm({
|
|
|
957
1104
|
"leadbay_import_and_qualify",
|
|
958
1105
|
"leadbay_import_leads",
|
|
959
1106
|
"leadbay_import_status",
|
|
1107
|
+
"leadbay_lead_job_status",
|
|
960
1108
|
"leadbay_list_campaigns",
|
|
961
1109
|
"leadbay_my_lenses",
|
|
962
1110
|
"leadbay_new_lens",
|
|
963
1111
|
"leadbay_prepare_outreach",
|
|
964
1112
|
"leadbay_pull_followups",
|
|
965
1113
|
"leadbay_pull_leads",
|
|
1114
|
+
"leadbay_qualify_leads",
|
|
966
1115
|
"leadbay_qualify_status",
|
|
967
1116
|
"leadbay_recall_ordered_titles",
|
|
968
1117
|
"leadbay_refine_prompt",
|
|
@@ -1215,12 +1364,12 @@ var init_ws_client = __esm({
|
|
|
1215
1364
|
this.pingTimer = setInterval(() => this.sendPing(), PING_INTERVAL_MS);
|
|
1216
1365
|
});
|
|
1217
1366
|
ws.addEventListener("message", (ev) => {
|
|
1218
|
-
const
|
|
1219
|
-
if (!
|
|
1367
|
+
const text2 = typeof ev.data === "string" ? ev.data : String(ev.data ?? "");
|
|
1368
|
+
if (!text2)
|
|
1220
1369
|
return;
|
|
1221
1370
|
let msg;
|
|
1222
1371
|
try {
|
|
1223
|
-
msg = JSON.parse(
|
|
1372
|
+
msg = JSON.parse(text2);
|
|
1224
1373
|
} catch {
|
|
1225
1374
|
this.logger?.warn?.("notifications.ws non_json_frame");
|
|
1226
1375
|
return;
|
|
@@ -1300,7 +1449,7 @@ var init_notifications = __esm({
|
|
|
1300
1449
|
});
|
|
1301
1450
|
|
|
1302
1451
|
// ../core/dist/tool-descriptions.generated.js
|
|
1303
|
-
var leadbay_account_history, leadbay_account_status, leadbay_acknowledge_notification, leadbay_add_contact, leadbay_add_leads_to_campaign, leadbay_add_note, leadbay_adjust_audience, leadbay_answer_clarification, leadbay_artifact_kit, leadbay_bulk_enrich_status, leadbay_bulk_qualify_leads, leadbay_campaign_call_sheet, leadbay_campaign_progression, leadbay_clear_selection, leadbay_clear_user_prompt, leadbay_create_campaign, leadbay_create_custom_field, leadbay_create_lens, leadbay_create_lens_draft, leadbay_create_topup_link, leadbay_delete_custom_field, leadbay_deselect_leads, leadbay_discover_leads, leadbay_dislike_lead, leadbay_dismiss_clarification, leadbay_enrich_contacts, leadbay_enrich_titles, leadbay_extend_lens, leadbay_followups_map, leadbay_get_clarification, leadbay_get_contacts, leadbay_get_enrichment_job_titles, leadbay_get_epilogue_responses, leadbay_get_lead_activities, leadbay_get_lead_custom_fields, leadbay_get_lead_notes, leadbay_get_lead_profile, leadbay_get_lens_filter, leadbay_get_lens_scoring, leadbay_get_prospecting_actions, leadbay_get_qualification_questions, leadbay_get_quota, leadbay_get_selection_ids, leadbay_get_taste_profile, leadbay_get_user_prompt, leadbay_get_web_fetch, leadbay_getting_started, leadbay_import_and_qualify, leadbay_import_leads, leadbay_import_status, leadbay_launch_bulk_enrichment, leadbay_like_lead, leadbay_list_campaigns, leadbay_list_lenses, leadbay_list_locations, leadbay_list_mappable_fields, leadbay_list_sectors, leadbay_login, leadbay_my_lenses, leadbay_new_lens, leadbay_open_billing_portal, leadbay_pick_clarification, leadbay_pin_contact, leadbay_prepare_outreach, leadbay_preview_bulk_enrichment, leadbay_promote_lens, leadbay_pull_followups, leadbay_pull_leads, leadbay_qualify_lead, leadbay_qualify_status, leadbay_recall_ordered_titles, leadbay_refine_prompt, leadbay_remove_contact, leadbay_remove_epilogue, leadbay_remove_leads_from_campaign, leadbay_remove_pushback, leadbay_report_friction, leadbay_report_outreach, leadbay_research_lead_by_id, leadbay_research_lead_by_name_fuzzy, leadbay_resolve_import_rows, leadbay_scan_portfolio_signals, leadbay_seed_candidates, leadbay_select_leads, leadbay_send_feedback, leadbay_set_active_lens, leadbay_set_epilogue_status, leadbay_set_lead_status, leadbay_set_pushback, leadbay_set_qualification_questions, leadbay_set_telemetry, leadbay_set_user_prompt, leadbay_team_activity, leadbay_tour_plan, leadbay_unpin_contact, leadbay_update_contact, leadbay_update_custom_field, leadbay_update_lens, leadbay_update_lens_filter, NO_COMMERCE_TOOL_DESCRIPTIONS;
|
|
1452
|
+
var leadbay_account_history, leadbay_account_status, leadbay_acknowledge_notification, leadbay_add_contact, leadbay_add_leads_to_campaign, leadbay_add_note, leadbay_adjust_audience, leadbay_answer_clarification, leadbay_artifact_kit, leadbay_bulk_enrich_status, leadbay_bulk_qualify_leads, leadbay_campaign_call_sheet, leadbay_campaign_progression, leadbay_clear_selection, leadbay_clear_user_prompt, leadbay_create_campaign, leadbay_create_custom_field, leadbay_create_lens, leadbay_create_lens_draft, leadbay_create_topup_link, leadbay_delete_custom_field, leadbay_deselect_leads, leadbay_discover_leads, leadbay_dislike_lead, leadbay_dismiss_clarification, leadbay_enrich_contacts, leadbay_enrich_titles, leadbay_extend_lens, leadbay_find_new_leads, leadbay_followups_map, leadbay_get_clarification, leadbay_get_contacts, leadbay_get_enrichment_job_titles, leadbay_get_epilogue_responses, leadbay_get_lead_activities, leadbay_get_lead_custom_fields, leadbay_get_lead_notes, leadbay_get_lead_profile, leadbay_get_lens_filter, leadbay_get_lens_scoring, leadbay_get_prospecting_actions, leadbay_get_qualification_questions, leadbay_get_quota, leadbay_get_selection_ids, leadbay_get_taste_profile, leadbay_get_user_prompt, leadbay_get_web_fetch, leadbay_getting_started, leadbay_import_and_qualify, leadbay_import_leads, leadbay_import_status, leadbay_launch_bulk_enrichment, leadbay_lead_job_status, leadbay_like_lead, leadbay_list_campaigns, leadbay_list_lenses, leadbay_list_locations, leadbay_list_mappable_fields, leadbay_list_sectors, leadbay_login, leadbay_my_lenses, leadbay_new_lens, leadbay_open_billing_portal, leadbay_pick_clarification, leadbay_pin_contact, leadbay_prepare_outreach, leadbay_preview_bulk_enrichment, leadbay_promote_lens, leadbay_pull_followups, leadbay_pull_leads, leadbay_qualify_lead, leadbay_qualify_leads, leadbay_qualify_status, leadbay_recall_ordered_titles, leadbay_refine_prompt, leadbay_remove_contact, leadbay_remove_epilogue, leadbay_remove_leads_from_campaign, leadbay_remove_pushback, leadbay_report_friction, leadbay_report_outreach, leadbay_research_lead_by_id, leadbay_research_lead_by_name_fuzzy, leadbay_resolve_import_rows, leadbay_scan_portfolio_signals, leadbay_seed_candidates, leadbay_select_leads, leadbay_send_feedback, leadbay_set_active_lens, leadbay_set_epilogue_status, leadbay_set_lead_status, leadbay_set_pushback, leadbay_set_qualification_questions, leadbay_set_telemetry, leadbay_set_user_prompt, leadbay_team_activity, leadbay_tour_plan, leadbay_unpin_contact, leadbay_update_contact, leadbay_update_custom_field, leadbay_update_lens, leadbay_update_lens_filter, NO_COMMERCE_TOOL_DESCRIPTIONS;
|
|
1304
1453
|
var init_tool_descriptions_generated = __esm({
|
|
1305
1454
|
"../core/dist/tool-descriptions.generated.js"() {
|
|
1306
1455
|
"use strict";
|
|
@@ -1879,7 +2028,7 @@ Context: Leadbay auto-qualifies roughly the top 10 of each daily batch. Leads be
|
|
|
1879
2028
|
|
|
1880
2029
|
WHEN TO USE: when the user wants more qualified leads than what's currently shown, or when a lead looks promising in leadbay_pull_leads but has an empty \`qualification_summary\`.
|
|
1881
2030
|
|
|
1882
|
-
WHEN NOT TO USE: to qualify a single specific lead \u2014 that's leadbay_qualify_lead (granular, advanced).
|
|
2031
|
+
WHEN NOT TO USE: to qualify a single specific lead \u2014 that's leadbay_qualify_lead (granular, advanced). And NOT for companies the user names or lists themselves (CRM rows, websites, prior deliveries) \u2014 that's leadbay_qualify_leads (server-side batch with per-item verdicts and contact matching); this tool only walks the ACTIVE LENS top-down.
|
|
1883
2032
|
|
|
1884
2033
|
## A launched job cannot be stopped
|
|
1885
2034
|
|
|
@@ -2511,7 +2660,7 @@ This tool MUTATES state. The caller (agent or human-in-the-loop) is responsible
|
|
|
2511
2660
|
|
|
2512
2661
|
Trigger phrases: "I want more leads on this lens", "extend the lens", "I need a bigger batch today", "fill more leads, I've burned through these", "more leads like the ones in this lens".
|
|
2513
2662
|
|
|
2514
|
-
Do NOT use for: "show me today's leads" \u2192 \`leadbay_pull_leads\`; "narrow the audience" \u2192 \`leadbay_adjust_audience\`; "stop showing me X" \u2192 \`leadbay_refine_prompt\`.
|
|
2663
|
+
Do NOT use for: "show me today's leads" \u2192 \`leadbay_pull_leads\`; "find me companies that <different profile than the lens>" \u2192 \`leadbay_find_new_leads\`; "narrow the audience" \u2192 \`leadbay_adjust_audience\`; "stop showing me X" \u2192 \`leadbay_refine_prompt\`.
|
|
2515
2664
|
|
|
2516
2665
|
Prefer when: user has bigger appetite than the daily lens fill delivers \u2014 additive refill on same criteria
|
|
2517
2666
|
|
|
@@ -2599,6 +2748,256 @@ Pick the row matching the response \`status\`. Seed-picking is internal; do NOT
|
|
|
2599
2748
|
| \`no_candidates\` (\`reason.code: no_new_leads\`) | "Work the leads already in the lens" | \`leadbay_pull_followups()\` |
|
|
2600
2749
|
|
|
2601
2750
|
If nothing matches cleanly, default to "pull leads now to see what's queued" \u2014 never invent a tool that doesn't exist.
|
|
2751
|
+
`;
|
|
2752
|
+
leadbay_find_new_leads = `## WHEN TO USE
|
|
2753
|
+
|
|
2754
|
+
Trigger phrases: "find me N companies that <profile>", "get me new prospects like <company>", "I need leads in <place> that <do X>", "search for companies that would buy <product>", "net-new leads outside my current pipeline", "we're entering <market> \u2014 who should we target".
|
|
2755
|
+
|
|
2756
|
+
Do NOT use for: "show me today's leads / what's new today" \u2192 \`leadbay_pull_leads\`; "find me new leads (no profile, no count named)" \u2192 \`leadbay_pull_leads\`; "more leads like the ones in my lens" \u2192 \`leadbay_extend_lens\`; "qualify / vet these companies I have" \u2192 \`leadbay_qualify_leads\`; "qualify the top N of my batch" \u2192 \`leadbay_bulk_qualify_leads\`; "leads I should follow up with" \u2192 \`leadbay_pull_followups\`; "tell me about <one company>" \u2192 \`leadbay_research_lead_by_name_fuzzy\`.
|
|
2757
|
+
|
|
2758
|
+
Prefer when: the user describes a target profile or names a count of NEW companies \u2014 craft the example_lead per the seed rules below BEFORE calling; never pass the user's raw sentence as query.
|
|
2759
|
+
|
|
2760
|
+
Examples that SHOULD invoke this tool:
|
|
2761
|
+
- "Find me 10 gyms around Dallas that would buy our flooring, with someone I can call."
|
|
2762
|
+
- "Get me 20 new US SaaS companies, 50-2000 employees, with the VP People's email."
|
|
2763
|
+
- "We're launching in Lyon \u2014 find 15 hotels that fit our ICP."
|
|
2764
|
+
|
|
2765
|
+
Examples that should NOT invoke this tool (sound similar, route elsewhere):
|
|
2766
|
+
- "Show me today's leads."
|
|
2767
|
+
- "Which leads should I follow up with this week?"
|
|
2768
|
+
- "Qualify these 40 websites from my spreadsheet."
|
|
2769
|
+
|
|
2770
|
+
## RENDER (quick)
|
|
2771
|
+
|
|
2772
|
+
3-col table of delivered leads in returned order: col 1 = 10-segment fit
|
|
2773
|
+
bar + linked company \xB7 location \xB7 size; col 2 = why-fits \u226420 words; col 3
|
|
2774
|
+
= contact + purchased channels. ALWAYS close with the honest funnel line
|
|
2775
|
+
(matched/examined/delivered/stop reason/spend) \u2014 especially on 0
|
|
2776
|
+
delivered. Full algorithm below.
|
|
2777
|
+
|
|
2778
|
+
---
|
|
2779
|
+
|
|
2780
|
+
Submit a net-new lead search: the backend matches an ICP seed against the full
|
|
2781
|
+
company universe, applies hard filters, skips what the org already knows
|
|
2782
|
+
(\`novelty: org\`), optionally qualifies against the org's own intelligence
|
|
2783
|
+
(questions, tags, ideal buyer profile \u2014 frozen at submit), and optionally buys
|
|
2784
|
+
contact channels. Polls up to \`wait_seconds\` (default 45); a longer job returns
|
|
2785
|
+
\`still_running\` + \`next_poll\` \u2014 hand off to \`leadbay_lead_job_status\`. Jobs run
|
|
2786
|
+
\u226430 min, results kept 30 days.
|
|
2787
|
+
|
|
2788
|
+
**Free vs paid \u2014 never spend silently.** Default (\`qualify: false\`,
|
|
2789
|
+
\`channels: []\`) is FREE: company profile + fit score + cached research +
|
|
2790
|
+
contact identity. Paid: \`qualify: true\` (~94 cost_cents per candidate
|
|
2791
|
+
EXAMINED, capped by \`exploration_cap\`/\`max_cost\`) and \`channels\` (email 25c /
|
|
2792
|
+
phone 250c, success-only). Enforced in code: a paid call is WITHHELD unless it
|
|
2793
|
+
carries \`confirm: true\` \u2014 nothing is submitted and you get
|
|
2794
|
+
\`mode: "needs_confirmation"\` with a real quote to show the user. Re-call with
|
|
2795
|
+
\`confirm: true\` on their go-ahead ("spend / get their emails" counts).
|
|
2796
|
+
\`confirm: false\` vetoes. Free needs no consent. **Preview free first** \u2014
|
|
2797
|
+
reshaping an off-profile seed is free, exploring it with \`qualify: true\` is
|
|
2798
|
+
not.
|
|
2799
|
+
|
|
2800
|
+
**Ad-hoc exclusions ("no chains") are enforced by NO tier** \u2014 \`filters\` has no
|
|
2801
|
+
exclusion key, and \`qualify\` scores against the org's FROZEN questions and IBP,
|
|
2802
|
+
which need not mention chains; the seed's inverse only shifts ranking.
|
|
2803
|
+
Violators can survive, be paid for and be delivered \u2014 post-filter them yourself
|
|
2804
|
+
and say the tier didn't enforce it. Durable enforcement \u2192
|
|
2805
|
+
\`leadbay_refine_prompt\`.
|
|
2806
|
+
|
|
2807
|
+
### Crafting the \`example_lead\` seed \u2014 the input that decides result quality
|
|
2808
|
+
|
|
2809
|
+
The \`example_lead\` is a FICTIONAL typical ideal customer, matched against real
|
|
2810
|
+
registry/website descriptions \u2014 which state what a company **IS**, never what
|
|
2811
|
+
is happening. Write it the same way or the matcher drifts. Every rule below is
|
|
2812
|
+
measured:
|
|
2813
|
+
|
|
2814
|
+
1. **Describe the BUYER, never the seller.** Ask: "would this company write a
|
|
2815
|
+
check to my user?" A seed describing what the user SELLS surfaces their
|
|
2816
|
+
*competitors and vendors*. If the product helps companies of type X serve
|
|
2817
|
+
customers of type Y, the seed describes X \u2014 never Y.
|
|
2818
|
+
2. **Put everything in \`description\`; leave \`name\` unset.** An invented brand
|
|
2819
|
+
name pulls matching toward name-lookalikes \u2014 a seed named "Meridian
|
|
2820
|
+
Analytics" returned five unrelated "Meridian" companies.
|
|
2821
|
+
3. **Registry style, one sentence to ~250 chars.** Industry niche, business
|
|
2822
|
+
model, what they sell or operate, who they serve, observable scale. Write
|
|
2823
|
+
it like the first paragraph of their About-Us page.
|
|
2824
|
+
- STRONG: "Operator of full-service fitness centers offering strength
|
|
2825
|
+
areas, group classes and personal training to members across multiple
|
|
2826
|
+
clubs."
|
|
2827
|
+
- WEAK (generic): "A gym in Texas."
|
|
2828
|
+
- WRONG (seller-side): "Supplier of durable modular flooring for gyms."
|
|
2829
|
+
4. **No event language.** "hiring", "expanding", "just raised" are not
|
|
2830
|
+
filters \u2014 registry descriptions never contain them, so they dilute the
|
|
2831
|
+
profile. Purchase triggers belong in the org's qualification questions.
|
|
2832
|
+
5. **No meta-markers.** Never "(example)", "(fictional)", "(placeholder)".
|
|
2833
|
+
6. **Hard constraints go in \`filters\`, not prose \u2014 exact keys:**
|
|
2834
|
+
\`sectors: string[]\`, \`locations: string[]\`, \`employees_min: number\`,
|
|
2835
|
+
\`employees_max: number\`. FLAT numbers \u2014 nested \`employees: {min, max}\`
|
|
2836
|
+
exists only in RESULT payloads. \`example_lead.employees\` does not filter.
|
|
2837
|
+
\`locations\` take city/state/region names ("Dallas, TX", "\xCEle-de-France");
|
|
2838
|
+
a country name is refused in code \u2014 whole-country intent = omit it.
|
|
2839
|
+
7. **Prefer \`example_lead\` over \`query\`.** Query matches topic *vocabulary*:
|
|
2840
|
+
"gyms that need durable flooring" surfaced flooring VENDORS, 0 delivered.
|
|
2841
|
+
Use \`query\` only for signal an example can't express.
|
|
2842
|
+
8. **One seed per buyer archetype.** An ask spanning two segments ("gyms and
|
|
2843
|
+
warehouses") needs one search each with its own description and
|
|
2844
|
+
\`request_id\` \u2014 a blended seed lands between the clusters and matches
|
|
2845
|
+
neither.
|
|
2846
|
+
|
|
2847
|
+
|
|
2848
|
+
**Parameter notes**
|
|
2849
|
+
- \`request_id\` (REQUIRED) is the retry contract: SAME value retrying the same
|
|
2850
|
+
ask (same live job, no double spend); NEW for a changed ask. Derive from ask
|
|
2851
|
+
+ archetype + date: \`gyms-dallas-2026-07-28\`.
|
|
2852
|
+
- Never lower \`min_ai_score\` together with \`channels\` \u2014 that buys emails for
|
|
2853
|
+
leads the AI just scored as junk.
|
|
2854
|
+
- \`count\` \u2264 50; \u22643 active jobs/org; \u226410 submits/hour (429 + Retry-After \u2014
|
|
2855
|
+
wait, don't hammer).
|
|
2856
|
+
|
|
2857
|
+
**Read the result honestly** \u2014 \`funnel\` + \`explain.scope_notes\` tell the story;
|
|
2858
|
+
zero delivered gets a cause and a next move (rules in RENDERING).
|
|
2859
|
+
|
|
2860
|
+
---
|
|
2861
|
+
|
|
2862
|
+
## RENDERING \u2014 delivery table + honest funnel line
|
|
2863
|
+
|
|
2864
|
+
Render delivered leads (\`leads[]\`, i.e. items with status \`delivered\` or
|
|
2865
|
+
\`degraded\`) as a markdown table **in the order returned**. Exactly three
|
|
2866
|
+
columns. Then ALWAYS close with the funnel line (below) \u2014 even, especially,
|
|
2867
|
+
when nothing was delivered.
|
|
2868
|
+
|
|
2869
|
+
**Column 1 \u2014 Company**
|
|
2870
|
+
|
|
2871
|
+
- Line 1: 10-segment fit bar in inline-code backticks from \`lead.fit.score\`
|
|
2872
|
+
(0-100): \`filled = round(score/10)\`, glyphs \`\u25B0\` filled / \`\u25B1\` empty. When
|
|
2873
|
+
\`lead.fit.components.qualification.available\` is true AND \`ai_score > 0\`,
|
|
2874
|
+
replace the LAST filled segment with \`\u2756\` (AI-confirmed cap). When
|
|
2875
|
+
\`fit.available\` is false, render \`\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\` and say "unscored" in col 2.
|
|
2876
|
+
Never print the numeric score.
|
|
2877
|
+
- Insert \`<br>\`, then: linked company name (target \`company.website\`, bare
|
|
2878
|
+
hostnames get \`https://\`; unlinked plain text when absent) + \` \xB7 \` + short
|
|
2879
|
+
location (City, ST / City, Country) + \` \xB7 \` + employees as \`min\u2013max\` (omit
|
|
2880
|
+
when \`employees.known\` is false).
|
|
2881
|
+
|
|
2882
|
+
**Column 2 \u2014 Why it fits**
|
|
2883
|
+
|
|
2884
|
+
- One sentence \u2264 20 words. Priority: \`fit.reasoning\` \u2192 gist of
|
|
2885
|
+
\`company.description\` \u2192 top \`fit.components.qualification.matched_tags\`.
|
|
2886
|
+
- If the item status is \`degraded\` or a requested channel failed, append the
|
|
2887
|
+
honest flag in italics, e.g. *(email could not be sourced)*.
|
|
2888
|
+
|
|
2889
|
+
**Column 3 \u2014 Contact**
|
|
2890
|
+
|
|
2891
|
+
- \`[Name](linkedin) \xB7 role\` (linked name mandatory when a LinkedIn URL
|
|
2892
|
+
exists; plain name otherwise). Below it, the PURCHASED channels only:
|
|
2893
|
+
\`\u2709 value\` / \`\u260E value\` inline as plain text (they auto-linkify).
|
|
2894
|
+
- Channel statuses: \`delivered\` \u2192 show value; \`already_owned\` \u2192 value +
|
|
2895
|
+
*(already yours)*; \`masked\` \u2192 "on file \u2014 reveal via channels";
|
|
2896
|
+
\`not_requested\` \u2192 omit; \`failed_*\` \u2192 *(no verified email/phone)*.
|
|
2897
|
+
- No contact on the item (\`contact\` null): render \`\u2014\` (title_gate \`prefer\`
|
|
2898
|
+
delivers such rows flagged; say so in col 2 only when contact_titles were
|
|
2899
|
+
requested).
|
|
2900
|
+
|
|
2901
|
+
**The funnel line (mandatory, after the table):**
|
|
2902
|
+
|
|
2903
|
+
One short line narrating the delivery honestly, from \`funnel\` + \`cost\` +
|
|
2904
|
+
\`explain.scope_notes\`:
|
|
2905
|
+
|
|
2906
|
+
> Matched N \xB7 examined E \xB7 qualified Q \xB7 disqualified D \u2192 **delivered X of
|
|
2907
|
+
> the Y asked** \xB7 stopped: <stop_reason in plain words> \xB7 spent C.CC.
|
|
2908
|
+
|
|
2909
|
+
**Money: divide, then symbol.** Every amount (\`cost.spent\`,
|
|
2910
|
+
\`estimated_cost.max\`, quotes) is \`cost_cents\` \u2014 divide by 100, two decimals,
|
|
2911
|
+
so \`165\` renders \`1.65\`, NEVER \`165.00\`. Symbol from the account region: US
|
|
2912
|
+
\`$\`, France \`\u20AC\`, unknown \u2192 bare. Never hard-code \`$\`: it misstates a charge.
|
|
2913
|
+
|
|
2914
|
+
"of the Y asked" needs \`summary.items_requested\`, which submits carry but a
|
|
2915
|
+
later \`leadbay_lead_job_status\` snapshot does not. Without it write **delivered
|
|
2916
|
+
X** and stop \u2014 never back-fill Y from \`matched\`/\`examined\` (they count
|
|
2917
|
+
candidates), never guess it.
|
|
2918
|
+
|
|
2919
|
+
Plain-word stop reasons: \`target_reached\` \u2192 omit (success), \`pool_exhausted\` \u2192
|
|
2920
|
+
"ran out of matching candidates", \`max_cost\` \u2192 "hit the cost cap", \`quota\` \u2192
|
|
2921
|
+
"hit an org quota", \`time_budget\` \u2192 "hit the 30-min time budget".
|
|
2922
|
+
|
|
2923
|
+
**When \`delivered\` is 0**: NEVER say just "no results". Render no table; give
|
|
2924
|
+
the funnel line plus the relevant \`explain.scope_notes\` (the backend's own
|
|
2925
|
+
diagnosis), then propose the concrete fix (reshape the seed per the craft
|
|
2926
|
+
rules, lower \`min_ai_score\`, raise \`max_cost\`, drop a filter) as NEXT STEPS.
|
|
2927
|
+
|
|
2928
|
+
**Weak batch**: when the BEST delivered \`fit.score\` is under 30, don't present
|
|
2929
|
+
the table as an answer \u2014 open with "weak matches only", show at most the top 3,
|
|
2930
|
+
propose reshaping the seed/filters first. The count was filled with
|
|
2931
|
+
barely-better-than-random candidates.
|
|
2932
|
+
|
|
2933
|
+
**Sanity-check every row**: (a) geo \u2014 \`city\`/\`region\` must sit inside any
|
|
2934
|
+
requested fence; drop and call out leaks (same-named cities slip through).
|
|
2935
|
+
(b) When \`explain.seed_strategy\` is \`text_match_exemplars\` (the standard FR
|
|
2936
|
+
path), fit is calibrated for lead-to-lead distances, not exemplar centroids \u2014
|
|
2937
|
+
treat high scores skeptically and verify each row's \`description\`.
|
|
2938
|
+
|
|
2939
|
+
**Skipped items** (\`skipped[]\`, qualify jobs mostly): render a compact second
|
|
2940
|
+
table \`Ref \u2192 Outcome\` translating \`status_reason\` to plain words:
|
|
2941
|
+
\`not_in_universe\` \u2192 "not in the Leadbay universe (import it first)",
|
|
2942
|
+
\`low_confidence_identity\` \u2192 "couldn't safely match \u2014 check \`resolution.alternatives\`",
|
|
2943
|
+
\`no_matching_contact\` \u2192 "no contact with the requested title",
|
|
2944
|
+
\`disqualified\` \u2192 "evaluated: does not fit" (evidence is in the item when owned),
|
|
2945
|
+
\`enrichment_failed\` \u2192 "channel could not be sourced (not billed)".
|
|
2946
|
+
|
|
2947
|
+
**\`items_truncated\`**: rows are a PREFIX, not the batch. Say so, and offer
|
|
2948
|
+
\`leadbay_lead_job_status(job_id, since: next_since)\` for the rest.
|
|
2949
|
+
|
|
2950
|
+
**Hide from the user:** UUIDs (keep for tool calls, never render), cursors,
|
|
2951
|
+
\`explain.model\`/\`intelligence_snapshot\`, raw \`distance\`/\`calibration\`,
|
|
2952
|
+
\`seq\`/\`from_cache\`, empty arrays.
|
|
2953
|
+
|
|
2954
|
+
## Linking a contact's name
|
|
2955
|
+
|
|
2956
|
+
**MANDATORY: every contact name in your output \u2014 table cells, prose, headers, "Reach <Name>" callouts \u2014 MUST be wrapped in markdown link syntax \`[Name](URL)\`. Never render a contact name as bare text. A plain-text name is a broken contact card; the underlined name is the user's primary affordance for "take me to this person's profile". No "no URL available" exception \u2014 the search URL below is always constructable from name + company.**
|
|
2957
|
+
|
|
2958
|
+
URL priority (first applicable wins):
|
|
2959
|
+
|
|
2960
|
+
1. **Real profile** \u2014 \`contact.linkedin_page\` when it's a string starting with \`https://\` (the MCP coerces the legacy literal \`"null"\` string to real null before you see it).
|
|
2961
|
+
2. **Constructed people-search** \u2014 \`https://www.linkedin.com/search/results/people/?keywords=<First>+<Last>+<Company>\`. URL-encode params. Strip Inc / LLC / Corp / Ltd / GmbH / Co / S.A. / S.L. / PLC / AG / SAS / SARL suffixes from the company. Append a trailing \` \xB0\` to the rendered name ONLY when this fallback is in use AND \`social_presence.linkedin == false\`. Never append \`\xB0\` when a real \`linkedin_page\` was used.
|
|
2962
|
+
|
|
2963
|
+
Never link a person's name to the company's LinkedIn page (and vice versa) \u2014 the two surfaces are different and conflating them quietly degrades the workflow.
|
|
2964
|
+
|
|
2965
|
+
|
|
2966
|
+
|
|
2967
|
+
---
|
|
2968
|
+
|
|
2969
|
+
## NEXT STEPS \u2014 after a find_new_leads delivery
|
|
2970
|
+
|
|
2971
|
+
**ALWAYS render NEXT STEPS via your host's next-step widget.** Use whichever is in your tool set \u2014 the NAME and SCHEMA differ: **\`ask_user_input_v0\`** (Claude chat / ChatGPT) takes plain-string options with \`type:"single_select"\`; **\`AskUserQuestion\`** (Claude cowork / Claude Code) takes object options \`{label, description}\` plus a required short \`header\` (\u226412 chars) and \`multiSelect\`, NO \`type\` field, and never add an "Other" option (the host adds it). Match the schema to the tool you actually have \u2014 the wrong schema fails silently and you fall back to prose. Prose bullets are the fallback ONLY when NEITHER widget exists. Any turn that would end with a choice must be the widget \u2014 the widget IS the question.
|
|
2972
|
+
|
|
2973
|
+
**If the tool result carries a \`next_steps\` object, that is the source of truth \u2014 use it directly.** Each option has a short \`.label\` (\u22645 words) and a full \`.description\`. Map \`next_steps.options[]\` into your host widget VERBATIM and in order: for \`AskUserQuestion\` (cowork / Claude Code) pass each as \`{label, description}\`; for \`ask_user_input_v0\` (Claude chat / ChatGPT, string options only) pass each option's \`.description\` as the string (it's the full sentence). Do NOT reword, reorder, drop, or prose-ify them \u2014 they're built deterministically by the server so the offer (incl. the artifact option at position 0) fires every time. Fall back to the table below only when there is NO \`next_steps\` field.
|
|
2974
|
+
|
|
2975
|
+
**One exception \u2014 skip the widget** when the user's original message contained a complete sequential instruction chain ("show me X and then do Y") AND all stated steps have been completed. In that case, end with STOP directly \u2014 the user stated their full plan and does not need a "what next?" prompt.
|
|
2976
|
+
- Skip example: "Show me today's leads and then research the top one for me." \u2192 after research completes, emit STOP without the widget.
|
|
2977
|
+
- Do NOT skip for: plain requests ("show me today's leads", "run my check-in"), recurring-language requests ("I do this every day"), or requests where only one action was stated.
|
|
2978
|
+
|
|
2979
|
+
Pick 2\u20134 rows from the (Observation, Suggest, Calls) table below most relevant to the response, then call your host's widget with ITS schema (per the schema rules above \u2014 wrong schema fails silently):
|
|
2980
|
+
- \`ask_user_input_v0\`: \`{questions:[{question,type:"single_select",options:["<Suggest 1>","<Suggest 2>"]}]}\`
|
|
2981
|
+
- \`AskUserQuestion\`: \`{questions:[{question,header:"Next step",multiSelect:false,options:[{label:"<\u22645 words>",description:"<Suggest 1>"}]}]}\`
|
|
2982
|
+
|
|
2983
|
+
User picks \u2192 call the matching \`Calls\` tool. Constraints: 2\u20134 mutually-exclusive options, AskUserQuestion labels \u22645 words (full text in \`description\`), max 3 questions. Table stays internal; never recite it.
|
|
2984
|
+
|
|
2985
|
+
---
|
|
2986
|
+
|
|
2987
|
+
|
|
2988
|
+
|
|
2989
|
+
Pick the 2-3 options that match what actually happened \u2014 never all seven:
|
|
2990
|
+
|
|
2991
|
+
| Observation | Suggest | Calls |
|
|
2992
|
+
|---|---|---|
|
|
2993
|
+
| Job still running (\`still_running: true\`) | "Check on it in ~1 min" | leadbay_lead_job_status(job_id, wait_seconds: 60) |
|
|
2994
|
+
| Free run delivered on-profile leads | "Qualify these N against your criteria (paid \u2014 \`dry_run\` first)" | leadbay_qualify_leads(prior_deliveries: {job_id}) |
|
|
2995
|
+
| Delivered leads look right | "Draft outreach for the top ones" | leadbay_prepare_outreach |
|
|
2996
|
+
| Delivered 0 or off-profile | "Reshape the example and retry" (name the fix from funnel + scope_notes) | leadbay_find_new_leads (NEW request_id) |
|
|
2997
|
+
| Stopped at cost cap (\`stop_reason: max_cost\`) | "Raise the cap to X and get the remaining N" \u2014 X in the account's currency per the funnel-line rule, never a hard-coded \`$\` | leadbay_find_new_leads, NEW request_id (same-id only dedupes onto a LIVE job) + higher max_cost + \`count\` = the SHORTFALL (\`items_requested\` \u2212 delivered), not the original + \`exclude_lead_ids\` = the examined-but-REJECTED ids (novelty covers delivered; these are what it misses \u2014 without them the rerun re-buys the same losers) |
|
|
2998
|
+
| Stopped on org quota (\`stop_reason: quota\`) | "Check which window is exhausted and when it resets" \u2014 never a re-run: it cannot clear an org quota and burns a submit slot to stop in the same place | leadbay_account_status |
|
|
2999
|
+
| Stopped on org quota and the user does not want to wait | "Top up to finish this run" | leadbay_create_topup_link |
|
|
3000
|
+
| User wants these tracked in Leadbay | "Add the keepers to a campaign" | leadbay_create_campaign / leadbay_add_leads_to_campaign |
|
|
2602
3001
|
`;
|
|
2603
3002
|
leadbay_followups_map = `## WHEN TO USE
|
|
2604
3003
|
|
|
@@ -3463,6 +3862,199 @@ spend before spending it again.
|
|
|
3463
3862
|
|
|
3464
3863
|
|
|
3465
3864
|
This tool MUTATES state. The caller (agent or human-in-the-loop) is responsible for confirming intent before invocation; the MCP server does not soft-prompt for confirmation. See \`annotations.destructiveHint\`.
|
|
3865
|
+
`;
|
|
3866
|
+
leadbay_lead_job_status = `## WHEN TO USE
|
|
3867
|
+
|
|
3868
|
+
Trigger phrases: "is the lead search done", "any results yet on that job", "check on the delivery".
|
|
3869
|
+
|
|
3870
|
+
Do NOT use for: "is the enrichment done" \u2192 \`leadbay_bulk_enrich_status\`; "is my import done" \u2192 \`leadbay_import_status\`; "is the top-N qualification done" \u2192 \`leadbay_qualify_status\`.
|
|
3871
|
+
|
|
3872
|
+
Prefer when: a find_new_leads / qualify_leads result carried next_poll \u2014 pass its job_id; use wait_seconds ~60 when the user asked to wait for results.
|
|
3873
|
+
|
|
3874
|
+
Examples that SHOULD invoke this tool:
|
|
3875
|
+
- "Any leads yet from that search you started?"
|
|
3876
|
+
- "Wait for the qualification job to finish and show me everything."
|
|
3877
|
+
|
|
3878
|
+
Examples that should NOT invoke this tool (sound similar, route elsewhere):
|
|
3879
|
+
- "Is the email enrichment finished?"
|
|
3880
|
+
- "Is my CSV import done?"
|
|
3881
|
+
|
|
3882
|
+
## RENDER (quick)
|
|
3883
|
+
|
|
3884
|
+
Terminal job -> render the full delivery per the lead-delivery table +
|
|
3885
|
+
honest funnel line. Still running -> one progress line (examined /
|
|
3886
|
+
delivered / spent so far) and offer to check again in ~1 min. Never
|
|
3887
|
+
render UUIDs or cursors.
|
|
3888
|
+
|
|
3889
|
+
---
|
|
3890
|
+
|
|
3891
|
+
Cumulative snapshot of a lead-delivery job: state, funnel counters, every
|
|
3892
|
+
item emitted so far (full lead payloads for delivered/degraded, honest
|
|
3893
|
+
status_reason for skipped), spend + breakdown, and the \`explain\` block
|
|
3894
|
+
(basis, seed strategy, scope notes). Items are immutable once emitted \u2014
|
|
3895
|
+
polling never re-reads live data, so numbers only ever grow.
|
|
3896
|
+
|
|
3897
|
+
\`wait_seconds: 0\` (default) answers instantly; set ~60 to block-wait for
|
|
3898
|
+
completion when the user asked for results "in this reply". \`since\` (from a
|
|
3899
|
+
prior poll's \`next_since\`) pages only the new items. Jobs terminalize
|
|
3900
|
+
server-side: past the 30-min wall clock a job reads \`completed_partial\`
|
|
3901
|
+
(time budget), past 30 days \`expired\` (items no longer listed \u2014 re-read
|
|
3902
|
+
billed leads via leadbay_qualify_leads \`prior_deliveries\`). A 404 means
|
|
3903
|
+
unknown job or another org's job.
|
|
3904
|
+
|
|
3905
|
+
---
|
|
3906
|
+
|
|
3907
|
+
## RENDERING \u2014 delivery table + honest funnel line
|
|
3908
|
+
|
|
3909
|
+
Render delivered leads (\`leads[]\`, i.e. items with status \`delivered\` or
|
|
3910
|
+
\`degraded\`) as a markdown table **in the order returned**. Exactly three
|
|
3911
|
+
columns. Then ALWAYS close with the funnel line (below) \u2014 even, especially,
|
|
3912
|
+
when nothing was delivered.
|
|
3913
|
+
|
|
3914
|
+
**Column 1 \u2014 Company**
|
|
3915
|
+
|
|
3916
|
+
- Line 1: 10-segment fit bar in inline-code backticks from \`lead.fit.score\`
|
|
3917
|
+
(0-100): \`filled = round(score/10)\`, glyphs \`\u25B0\` filled / \`\u25B1\` empty. When
|
|
3918
|
+
\`lead.fit.components.qualification.available\` is true AND \`ai_score > 0\`,
|
|
3919
|
+
replace the LAST filled segment with \`\u2756\` (AI-confirmed cap). When
|
|
3920
|
+
\`fit.available\` is false, render \`\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\` and say "unscored" in col 2.
|
|
3921
|
+
Never print the numeric score.
|
|
3922
|
+
- Insert \`<br>\`, then: linked company name (target \`company.website\`, bare
|
|
3923
|
+
hostnames get \`https://\`; unlinked plain text when absent) + \` \xB7 \` + short
|
|
3924
|
+
location (City, ST / City, Country) + \` \xB7 \` + employees as \`min\u2013max\` (omit
|
|
3925
|
+
when \`employees.known\` is false).
|
|
3926
|
+
|
|
3927
|
+
**Column 2 \u2014 Why it fits**
|
|
3928
|
+
|
|
3929
|
+
- One sentence \u2264 20 words. Priority: \`fit.reasoning\` \u2192 gist of
|
|
3930
|
+
\`company.description\` \u2192 top \`fit.components.qualification.matched_tags\`.
|
|
3931
|
+
- If the item status is \`degraded\` or a requested channel failed, append the
|
|
3932
|
+
honest flag in italics, e.g. *(email could not be sourced)*.
|
|
3933
|
+
|
|
3934
|
+
**Column 3 \u2014 Contact**
|
|
3935
|
+
|
|
3936
|
+
- \`[Name](linkedin) \xB7 role\` (linked name mandatory when a LinkedIn URL
|
|
3937
|
+
exists; plain name otherwise). Below it, the PURCHASED channels only:
|
|
3938
|
+
\`\u2709 value\` / \`\u260E value\` inline as plain text (they auto-linkify).
|
|
3939
|
+
- Channel statuses: \`delivered\` \u2192 show value; \`already_owned\` \u2192 value +
|
|
3940
|
+
*(already yours)*; \`masked\` \u2192 "on file \u2014 reveal via channels";
|
|
3941
|
+
\`not_requested\` \u2192 omit; \`failed_*\` \u2192 *(no verified email/phone)*.
|
|
3942
|
+
- No contact on the item (\`contact\` null): render \`\u2014\` (title_gate \`prefer\`
|
|
3943
|
+
delivers such rows flagged; say so in col 2 only when contact_titles were
|
|
3944
|
+
requested).
|
|
3945
|
+
|
|
3946
|
+
**The funnel line (mandatory, after the table):**
|
|
3947
|
+
|
|
3948
|
+
One short line narrating the delivery honestly, from \`funnel\` + \`cost\` +
|
|
3949
|
+
\`explain.scope_notes\`:
|
|
3950
|
+
|
|
3951
|
+
> Matched N \xB7 examined E \xB7 qualified Q \xB7 disqualified D \u2192 **delivered X of
|
|
3952
|
+
> the Y asked** \xB7 stopped: <stop_reason in plain words> \xB7 spent C.CC.
|
|
3953
|
+
|
|
3954
|
+
**Money: divide, then symbol.** Every amount (\`cost.spent\`,
|
|
3955
|
+
\`estimated_cost.max\`, quotes) is \`cost_cents\` \u2014 divide by 100, two decimals,
|
|
3956
|
+
so \`165\` renders \`1.65\`, NEVER \`165.00\`. Symbol from the account region: US
|
|
3957
|
+
\`$\`, France \`\u20AC\`, unknown \u2192 bare. Never hard-code \`$\`: it misstates a charge.
|
|
3958
|
+
|
|
3959
|
+
"of the Y asked" needs \`summary.items_requested\`, which submits carry but a
|
|
3960
|
+
later \`leadbay_lead_job_status\` snapshot does not. Without it write **delivered
|
|
3961
|
+
X** and stop \u2014 never back-fill Y from \`matched\`/\`examined\` (they count
|
|
3962
|
+
candidates), never guess it.
|
|
3963
|
+
|
|
3964
|
+
Plain-word stop reasons: \`target_reached\` \u2192 omit (success), \`pool_exhausted\` \u2192
|
|
3965
|
+
"ran out of matching candidates", \`max_cost\` \u2192 "hit the cost cap", \`quota\` \u2192
|
|
3966
|
+
"hit an org quota", \`time_budget\` \u2192 "hit the 30-min time budget".
|
|
3967
|
+
|
|
3968
|
+
**When \`delivered\` is 0**: NEVER say just "no results". Render no table; give
|
|
3969
|
+
the funnel line plus the relevant \`explain.scope_notes\` (the backend's own
|
|
3970
|
+
diagnosis), then propose the concrete fix (reshape the seed per the craft
|
|
3971
|
+
rules, lower \`min_ai_score\`, raise \`max_cost\`, drop a filter) as NEXT STEPS.
|
|
3972
|
+
|
|
3973
|
+
**Weak batch**: when the BEST delivered \`fit.score\` is under 30, don't present
|
|
3974
|
+
the table as an answer \u2014 open with "weak matches only", show at most the top 3,
|
|
3975
|
+
propose reshaping the seed/filters first. The count was filled with
|
|
3976
|
+
barely-better-than-random candidates.
|
|
3977
|
+
|
|
3978
|
+
**Sanity-check every row**: (a) geo \u2014 \`city\`/\`region\` must sit inside any
|
|
3979
|
+
requested fence; drop and call out leaks (same-named cities slip through).
|
|
3980
|
+
(b) When \`explain.seed_strategy\` is \`text_match_exemplars\` (the standard FR
|
|
3981
|
+
path), fit is calibrated for lead-to-lead distances, not exemplar centroids \u2014
|
|
3982
|
+
treat high scores skeptically and verify each row's \`description\`.
|
|
3983
|
+
|
|
3984
|
+
**Skipped items** (\`skipped[]\`, qualify jobs mostly): render a compact second
|
|
3985
|
+
table \`Ref \u2192 Outcome\` translating \`status_reason\` to plain words:
|
|
3986
|
+
\`not_in_universe\` \u2192 "not in the Leadbay universe (import it first)",
|
|
3987
|
+
\`low_confidence_identity\` \u2192 "couldn't safely match \u2014 check \`resolution.alternatives\`",
|
|
3988
|
+
\`no_matching_contact\` \u2192 "no contact with the requested title",
|
|
3989
|
+
\`disqualified\` \u2192 "evaluated: does not fit" (evidence is in the item when owned),
|
|
3990
|
+
\`enrichment_failed\` \u2192 "channel could not be sourced (not billed)".
|
|
3991
|
+
|
|
3992
|
+
**\`items_truncated\`**: rows are a PREFIX, not the batch. Say so, and offer
|
|
3993
|
+
\`leadbay_lead_job_status(job_id, since: next_since)\` for the rest.
|
|
3994
|
+
|
|
3995
|
+
**Hide from the user:** UUIDs (keep for tool calls, never render), cursors,
|
|
3996
|
+
\`explain.model\`/\`intelligence_snapshot\`, raw \`distance\`/\`calibration\`,
|
|
3997
|
+
\`seq\`/\`from_cache\`, empty arrays.
|
|
3998
|
+
|
|
3999
|
+
## Linking a contact's name
|
|
4000
|
+
|
|
4001
|
+
**MANDATORY: every contact name in your output \u2014 table cells, prose, headers, "Reach <Name>" callouts \u2014 MUST be wrapped in markdown link syntax \`[Name](URL)\`. Never render a contact name as bare text. A plain-text name is a broken contact card; the underlined name is the user's primary affordance for "take me to this person's profile". No "no URL available" exception \u2014 the search URL below is always constructable from name + company.**
|
|
4002
|
+
|
|
4003
|
+
URL priority (first applicable wins):
|
|
4004
|
+
|
|
4005
|
+
1. **Real profile** \u2014 \`contact.linkedin_page\` when it's a string starting with \`https://\` (the MCP coerces the legacy literal \`"null"\` string to real null before you see it).
|
|
4006
|
+
2. **Constructed people-search** \u2014 \`https://www.linkedin.com/search/results/people/?keywords=<First>+<Last>+<Company>\`. URL-encode params. Strip Inc / LLC / Corp / Ltd / GmbH / Co / S.A. / S.L. / PLC / AG / SAS / SARL suffixes from the company. Append a trailing \` \xB0\` to the rendered name ONLY when this fallback is in use AND \`social_presence.linkedin == false\`. Never append \`\xB0\` when a real \`linkedin_page\` was used.
|
|
4007
|
+
|
|
4008
|
+
Never link a person's name to the company's LinkedIn page (and vice versa) \u2014 the two surfaces are different and conflating them quietly degrades the workflow.
|
|
4009
|
+
|
|
4010
|
+
|
|
4011
|
+
|
|
4012
|
+
**Delivered \u2260 endorsed.** This tool DELIVERS org-owned companies that FAILED
|
|
4013
|
+
qualification, carrying their negative evidence \u2014 so a delivered item is not
|
|
4014
|
+
automatically a prospect. An item whose \`status_reason\` is \`disqualified\`, or
|
|
4015
|
+
whose \`fit.components.qualification\` is available with a negative \`ai_score\`,
|
|
4016
|
+
must NOT go in the fit table: its firmographic score can still be high, and a
|
|
4017
|
+
full bar beside "why it fits" reads as a recommendation to call an account the
|
|
4018
|
+
evaluation just rejected.
|
|
4019
|
+
|
|
4020
|
+
Give those their own short section after the fit table, titled
|
|
4021
|
+
**Evaluated \u2014 does not fit**: linked company, then the verdict in plain
|
|
4022
|
+
words from the
|
|
4023
|
+
qualification evidence (failed question verdicts, missed tags, IBP reasoning).
|
|
4024
|
+
That is the deliverable \u2014 "here's why to skip this account" \u2014 not a defect to
|
|
4025
|
+
hide.
|
|
4026
|
+
|
|
4027
|
+
|
|
4028
|
+
---
|
|
4029
|
+
|
|
4030
|
+
## NEXT STEPS \u2014 after a job status poll
|
|
4031
|
+
|
|
4032
|
+
**ALWAYS render NEXT STEPS via your host's next-step widget.** Use whichever is in your tool set \u2014 the NAME and SCHEMA differ: **\`ask_user_input_v0\`** (Claude chat / ChatGPT) takes plain-string options with \`type:"single_select"\`; **\`AskUserQuestion\`** (Claude cowork / Claude Code) takes object options \`{label, description}\` plus a required short \`header\` (\u226412 chars) and \`multiSelect\`, NO \`type\` field, and never add an "Other" option (the host adds it). Match the schema to the tool you actually have \u2014 the wrong schema fails silently and you fall back to prose. Prose bullets are the fallback ONLY when NEITHER widget exists. Any turn that would end with a choice must be the widget \u2014 the widget IS the question.
|
|
4033
|
+
|
|
4034
|
+
**If the tool result carries a \`next_steps\` object, that is the source of truth \u2014 use it directly.** Each option has a short \`.label\` (\u22645 words) and a full \`.description\`. Map \`next_steps.options[]\` into your host widget VERBATIM and in order: for \`AskUserQuestion\` (cowork / Claude Code) pass each as \`{label, description}\`; for \`ask_user_input_v0\` (Claude chat / ChatGPT, string options only) pass each option's \`.description\` as the string (it's the full sentence). Do NOT reword, reorder, drop, or prose-ify them \u2014 they're built deterministically by the server so the offer (incl. the artifact option at position 0) fires every time. Fall back to the table below only when there is NO \`next_steps\` field.
|
|
4035
|
+
|
|
4036
|
+
**One exception \u2014 skip the widget** when the user's original message contained a complete sequential instruction chain ("show me X and then do Y") AND all stated steps have been completed. In that case, end with STOP directly \u2014 the user stated their full plan and does not need a "what next?" prompt.
|
|
4037
|
+
- Skip example: "Show me today's leads and then research the top one for me." \u2192 after research completes, emit STOP without the widget.
|
|
4038
|
+
- Do NOT skip for: plain requests ("show me today's leads", "run my check-in"), recurring-language requests ("I do this every day"), or requests where only one action was stated.
|
|
4039
|
+
|
|
4040
|
+
Pick 2\u20134 rows from the (Observation, Suggest, Calls) table below most relevant to the response, then call your host's widget with ITS schema (per the schema rules above \u2014 wrong schema fails silently):
|
|
4041
|
+
- \`ask_user_input_v0\`: \`{questions:[{question,type:"single_select",options:["<Suggest 1>","<Suggest 2>"]}]}\`
|
|
4042
|
+
- \`AskUserQuestion\`: \`{questions:[{question,header:"Next step",multiSelect:false,options:[{label:"<\u22645 words>",description:"<Suggest 1>"}]}]}\`
|
|
4043
|
+
|
|
4044
|
+
User picks \u2192 call the matching \`Calls\` tool. Constraints: 2\u20134 mutually-exclusive options, AskUserQuestion labels \u22645 words (full text in \`description\`), max 3 questions. Table stays internal; never recite it.
|
|
4045
|
+
|
|
4046
|
+
---
|
|
4047
|
+
|
|
4048
|
+
|
|
4049
|
+
|
|
4050
|
+
Pick the ONE row matching the job's state and offer at most two options \u2014 this
|
|
4051
|
+
is a status tool, keep it terse:
|
|
4052
|
+
|
|
4053
|
+
| Observation | Suggest | Calls |
|
|
4054
|
+
|---|---|---|
|
|
4055
|
+
| Still running | "Keep waiting (~1 min) or leave it \u2014 results are kept 30 days" | leadbay_lead_job_status(job_id, wait_seconds: 60) |
|
|
4056
|
+
| Terminal (completed / partial / failed) | Render the delivery per the RENDERING block, then offer the matching find_new_leads / qualify_leads NEXT STEPS | \u2014 |
|
|
4057
|
+
| \`expired\` (past the 30-day window) | "Re-read the billed leads from your delivery ledger" \u2014 there is nothing left to render: the job terminalized and its items are no longer listed, so do NOT present an empty delivery as a result | leadbay_qualify_leads(prior_deliveries: {job_id}) |
|
|
3466
4058
|
`;
|
|
3467
4059
|
leadbay_like_lead = `## WHEN TO USE
|
|
3468
4060
|
|
|
@@ -4362,7 +4954,7 @@ Always offer at least one of: prep outreach, refilter, pushback. Pushback is the
|
|
|
4362
4954
|
|
|
4363
4955
|
Trigger phrases: "show me leads", "show me new leads", "show me today's leads", "today's prospects", "best new leads", "fresh leads", "what's new today".
|
|
4364
4956
|
|
|
4365
|
-
Do NOT use for: "leads I should follow up with" \u2192 \`leadbay_pull_followups\`; "I'm going to <city>" \u2192 \`leadbay_tour_plan\`; "I'm in <city> next week \u2014 who's worth meeting" \u2192 \`leadbay_tour_plan\`; "who should I meet in <city>" \u2192 \`leadbay_tour_plan\`; "visiting <city> \u2014 who's worth meeting / seeing" \u2192 \`leadbay_tour_plan\`; "leads I should reach out to" \u2192 \`leadbay_pull_followups\`; "leads to get back to" \u2192 \`leadbay_pull_followups\`; "leads to contact today" \u2192 \`leadbay_pull_followups\`; "should I contact" \u2192 \`leadbay_pull_followups\`; "reconnect with" \u2192 \`leadbay_pull_followups\`; "re-engage" \u2192 \`leadbay_pull_followups\`.
|
|
4957
|
+
Do NOT use for: "find me N companies that <specific profile>" \u2192 \`leadbay_find_new_leads\`; "new prospects like <company> with their emails" \u2192 \`leadbay_find_new_leads\`; "leads I should follow up with" \u2192 \`leadbay_pull_followups\`; "I'm going to <city>" \u2192 \`leadbay_tour_plan\`; "I'm in <city> next week \u2014 who's worth meeting" \u2192 \`leadbay_tour_plan\`; "who should I meet in <city>" \u2192 \`leadbay_tour_plan\`; "visiting <city> \u2014 who's worth meeting / seeing" \u2192 \`leadbay_tour_plan\`; "leads I should reach out to" \u2192 \`leadbay_pull_followups\`; "leads to get back to" \u2192 \`leadbay_pull_followups\`; "leads to contact today" \u2192 \`leadbay_pull_followups\`; "should I contact" \u2192 \`leadbay_pull_followups\`; "reconnect with" \u2192 \`leadbay_pull_followups\`; "re-engage" \u2192 \`leadbay_pull_followups\`.
|
|
4366
4958
|
|
|
4367
4959
|
Prefer when: fresh Discover leads; if a lens is named, pass \`lensId\` and pin it
|
|
4368
4960
|
|
|
@@ -4371,6 +4963,7 @@ Examples that SHOULD invoke this tool:
|
|
|
4371
4963
|
- "Pull my best new prospects."
|
|
4372
4964
|
|
|
4373
4965
|
Examples that should NOT invoke this tool (sound similar, route elsewhere):
|
|
4966
|
+
- "Find me 10 gyms around Dallas that would buy our flooring."
|
|
4374
4967
|
- "Which leads should I follow up with this week?"
|
|
4375
4968
|
- "I'm flying to Berlin Thursday \u2014 who should I meet?"
|
|
4376
4969
|
- "I'm in San Francisco next Tuesday \u2014 who's worth meeting?"
|
|
@@ -4400,7 +4993,7 @@ Every lead carries \`recommended_contact\` (with \`linkedin_page\` when the back
|
|
|
4400
4993
|
|
|
4401
4994
|
WHEN TO USE: as the agent's default opening move when the user wants to see leads, or as a daily check-in for what's new today.
|
|
4402
4995
|
|
|
4403
|
-
WHEN NOT TO USE: when the user has named a specific lens \u2014 pass \`lensId\` to override the auto-resolution.
|
|
4996
|
+
WHEN NOT TO USE: when the user has named a specific lens \u2014 pass \`lensId\` to override the auto-resolution.
|
|
4404
4997
|
|
|
4405
4998
|
The active lens can change between calls (5-min cache + backend \`last_requested_lens\`). If a multi-step workflow depends on staying on one lens, **capture \`response.lens.id\` from the first response and pass it as the \`lensId\` argument on every subsequent Leadbay call** \u2014 including re-pulls, bulk qualifies, and research. (Field-name caveat: response nests it as \`lens.id\`; the parameter is \`lensId\`.) Re-pulling without \`lensId\` after a long-running tool may silently switch to a different lens and discard prior work.
|
|
4406
4999
|
|
|
@@ -4549,6 +5142,231 @@ spend before spending it again.
|
|
|
4549
5142
|
|
|
4550
5143
|
|
|
4551
5144
|
This tool MUTATES state. The caller (agent or human-in-the-loop) is responsible for confirming intent before invocation; the MCP server does not soft-prompt for confirmation. See \`annotations.destructiveHint\`.
|
|
5145
|
+
`;
|
|
5146
|
+
leadbay_qualify_leads = `## WHEN TO USE
|
|
5147
|
+
|
|
5148
|
+
Trigger phrases: "qualify these companies", "vet this list", "which of these fit our ICP", "score these websites / accounts", "get me the right contact at these companies", "re-qualify what you delivered last week".
|
|
5149
|
+
|
|
5150
|
+
Do NOT use for: "find me new leads / companies that <profile>" \u2192 \`leadbay_find_new_leads\`; "qualify the top N of my lens batch" \u2192 \`leadbay_bulk_qualify_leads\`; "import this CSV file" \u2192 \`leadbay_import_leads\`; "tell me about <one company> in depth" \u2192 \`leadbay_research_lead_by_name_fuzzy\`; "add emails to the contacts I selected" \u2192 \`leadbay_enrich_titles\`.
|
|
5151
|
+
|
|
5152
|
+
Prefer when: the user points at SPECIFIC companies (ids, websites, names, a pasted list, "what you found yesterday") and wants fit verdicts and/or the right person to talk to.
|
|
5153
|
+
|
|
5154
|
+
Examples that SHOULD invoke this tool:
|
|
5155
|
+
- "Here are 60 restaurant websites from my Austin sweep \u2014 which fit, and who's the owner?"
|
|
5156
|
+
- "Re-qualify last week's delivery and get phone numbers for the good ones."
|
|
5157
|
+
- "Vet these 12 accounts from my spreadsheet against our criteria."
|
|
5158
|
+
|
|
5159
|
+
Examples that should NOT invoke this tool (sound similar, route elsewhere):
|
|
5160
|
+
- "Find me 10 new gyms in Texas."
|
|
5161
|
+
- "Qualify the top 10 leads in my batch."
|
|
5162
|
+
- "I have a CSV of 400 attendees to import."
|
|
5163
|
+
|
|
5164
|
+
## RENDER (quick)
|
|
5165
|
+
|
|
5166
|
+
3-col table for delivered items (fit bar + company / why-fits \u226420 words /
|
|
5167
|
+
contact + channels) in returned order, then a compact Ref \u2192 Outcome table
|
|
5168
|
+
for skipped refs (not_in_universe, low_confidence_identity, ... in plain
|
|
5169
|
+
words), then the honest funnel + cost line. Full algorithm below.
|
|
5170
|
+
|
|
5171
|
+
---
|
|
5172
|
+
|
|
5173
|
+
Submit a qualify batch over companies the org already has (or that exist in
|
|
5174
|
+
the Leadbay universe): each ref is resolved to a known company, freshly
|
|
5175
|
+
researched + AI-qualified against the org's questions / tags / ideal buyer
|
|
5176
|
+
profile (frozen at submit), matched to the requested contact titles, and \u2014
|
|
5177
|
+
when asked \u2014 enriched with verified channels. Answers arrive per-item from a
|
|
5178
|
+
job; this tool polls up to \`wait_seconds\` (default 45) and hands off to
|
|
5179
|
+
\`leadbay_lead_job_status\` when the batch needs longer.
|
|
5180
|
+
|
|
5181
|
+
**Refs are flexible; outcomes are per-item.** \`lead_refs\` accepts any mix of
|
|
5182
|
+
\`lead_id\`, \`website\`, \`name\`(+\`location\`), or a stable \`contact_id\` from a
|
|
5183
|
+
prior result (enrichment then targets exactly that person, never a re-match).
|
|
5184
|
+
\`prior_deliveries\` expands past MCP deliveries into refs \u2014 billed leads stay
|
|
5185
|
+
re-readable this way even after the 30-day result window. Duplicates collapse.
|
|
5186
|
+
A ref that can't be served comes back \`skipped\` with an honest
|
|
5187
|
+
\`status_reason\` (\`not_in_universe\`, \`low_confidence_identity\` with the
|
|
5188
|
+
\`resolution.alternatives\` to choose from, \`no_matching_contact\`, ...) \u2014 that
|
|
5189
|
+
is an ANSWER about the ref, not an error, and it costs nothing.
|
|
5190
|
+
|
|
5191
|
+
**Disqualified \u2260 dropped.** Companies the org owns that fail qualification
|
|
5192
|
+
are DELIVERED with their negative evidence (question verdicts, tag misses,
|
|
5193
|
+
IBP reasoning) \u2014 "here's why to skip this account" is a deliverable.
|
|
5194
|
+
|
|
5195
|
+
**Cost \u2014 never spend silently.** Resolution and identity are free.
|
|
5196
|
+
\`qualify: true\` (the default) costs ~94 cost_cents per lead needing FRESH
|
|
5197
|
+
research+scoring \u2014 but repeat calls reuse every fresh cached stage
|
|
5198
|
+
(\`from_cache\` flags on the items) and converge to near-zero cost. \`channels\`
|
|
5199
|
+
purchase verified email (25c) / phone (250c) on success only;
|
|
5200
|
+
\`already_owned\` values cost nothing.
|
|
5201
|
+
|
|
5202
|
+
The gate is enforced in code, not just here: a PAID call (\`qualify\` left at
|
|
5203
|
+
its default or set true, and/or any \`channels\`) is WITHHELD unless it carries
|
|
5204
|
+
\`confirm: true\`. Without it the tool submits nothing and returns
|
|
5205
|
+
\`mode: "needs_confirmation"\` with a real backend quote \u2014 show that quote to
|
|
5206
|
+
the user, get the go-ahead (an explicit "spend / get their emails" in their
|
|
5207
|
+
message counts), then re-call with \`confirm: true\`. \`confirm: false\` is a
|
|
5208
|
+
veto: nothing is submitted and no quote round-trip is made. A fully FREE
|
|
5209
|
+
call (\`qualify: false\`, no \`channels\`) needs no \`confirm\` and passes straight
|
|
5210
|
+
through. Set \`request_id\` and reuse it on retries of the same batch.
|
|
5211
|
+
|
|
5212
|
+
**Limits**: 500 refs/job, 3 active jobs/org, 10 submits/hour (429 +
|
|
5213
|
+
Retry-After beyond \u2014 wait, don't hammer), 30-min job wall clock.
|
|
5214
|
+
|
|
5215
|
+
---
|
|
5216
|
+
|
|
5217
|
+
## RENDERING \u2014 delivery table + honest funnel line
|
|
5218
|
+
|
|
5219
|
+
Render delivered leads (\`leads[]\`, i.e. items with status \`delivered\` or
|
|
5220
|
+
\`degraded\`) as a markdown table **in the order returned**. Exactly three
|
|
5221
|
+
columns. Then ALWAYS close with the funnel line (below) \u2014 even, especially,
|
|
5222
|
+
when nothing was delivered.
|
|
5223
|
+
|
|
5224
|
+
**Column 1 \u2014 Company**
|
|
5225
|
+
|
|
5226
|
+
- Line 1: 10-segment fit bar in inline-code backticks from \`lead.fit.score\`
|
|
5227
|
+
(0-100): \`filled = round(score/10)\`, glyphs \`\u25B0\` filled / \`\u25B1\` empty. When
|
|
5228
|
+
\`lead.fit.components.qualification.available\` is true AND \`ai_score > 0\`,
|
|
5229
|
+
replace the LAST filled segment with \`\u2756\` (AI-confirmed cap). When
|
|
5230
|
+
\`fit.available\` is false, render \`\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\` and say "unscored" in col 2.
|
|
5231
|
+
Never print the numeric score.
|
|
5232
|
+
- Insert \`<br>\`, then: linked company name (target \`company.website\`, bare
|
|
5233
|
+
hostnames get \`https://\`; unlinked plain text when absent) + \` \xB7 \` + short
|
|
5234
|
+
location (City, ST / City, Country) + \` \xB7 \` + employees as \`min\u2013max\` (omit
|
|
5235
|
+
when \`employees.known\` is false).
|
|
5236
|
+
|
|
5237
|
+
**Column 2 \u2014 Why it fits**
|
|
5238
|
+
|
|
5239
|
+
- One sentence \u2264 20 words. Priority: \`fit.reasoning\` \u2192 gist of
|
|
5240
|
+
\`company.description\` \u2192 top \`fit.components.qualification.matched_tags\`.
|
|
5241
|
+
- If the item status is \`degraded\` or a requested channel failed, append the
|
|
5242
|
+
honest flag in italics, e.g. *(email could not be sourced)*.
|
|
5243
|
+
|
|
5244
|
+
**Column 3 \u2014 Contact**
|
|
5245
|
+
|
|
5246
|
+
- \`[Name](linkedin) \xB7 role\` (linked name mandatory when a LinkedIn URL
|
|
5247
|
+
exists; plain name otherwise). Below it, the PURCHASED channels only:
|
|
5248
|
+
\`\u2709 value\` / \`\u260E value\` inline as plain text (they auto-linkify).
|
|
5249
|
+
- Channel statuses: \`delivered\` \u2192 show value; \`already_owned\` \u2192 value +
|
|
5250
|
+
*(already yours)*; \`masked\` \u2192 "on file \u2014 reveal via channels";
|
|
5251
|
+
\`not_requested\` \u2192 omit; \`failed_*\` \u2192 *(no verified email/phone)*.
|
|
5252
|
+
- No contact on the item (\`contact\` null): render \`\u2014\` (title_gate \`prefer\`
|
|
5253
|
+
delivers such rows flagged; say so in col 2 only when contact_titles were
|
|
5254
|
+
requested).
|
|
5255
|
+
|
|
5256
|
+
**The funnel line (mandatory, after the table):**
|
|
5257
|
+
|
|
5258
|
+
One short line narrating the delivery honestly, from \`funnel\` + \`cost\` +
|
|
5259
|
+
\`explain.scope_notes\`:
|
|
5260
|
+
|
|
5261
|
+
> Matched N \xB7 examined E \xB7 qualified Q \xB7 disqualified D \u2192 **delivered X of
|
|
5262
|
+
> the Y asked** \xB7 stopped: <stop_reason in plain words> \xB7 spent C.CC.
|
|
5263
|
+
|
|
5264
|
+
**Money: divide, then symbol.** Every amount (\`cost.spent\`,
|
|
5265
|
+
\`estimated_cost.max\`, quotes) is \`cost_cents\` \u2014 divide by 100, two decimals,
|
|
5266
|
+
so \`165\` renders \`1.65\`, NEVER \`165.00\`. Symbol from the account region: US
|
|
5267
|
+
\`$\`, France \`\u20AC\`, unknown \u2192 bare. Never hard-code \`$\`: it misstates a charge.
|
|
5268
|
+
|
|
5269
|
+
"of the Y asked" needs \`summary.items_requested\`, which submits carry but a
|
|
5270
|
+
later \`leadbay_lead_job_status\` snapshot does not. Without it write **delivered
|
|
5271
|
+
X** and stop \u2014 never back-fill Y from \`matched\`/\`examined\` (they count
|
|
5272
|
+
candidates), never guess it.
|
|
5273
|
+
|
|
5274
|
+
Plain-word stop reasons: \`target_reached\` \u2192 omit (success), \`pool_exhausted\` \u2192
|
|
5275
|
+
"ran out of matching candidates", \`max_cost\` \u2192 "hit the cost cap", \`quota\` \u2192
|
|
5276
|
+
"hit an org quota", \`time_budget\` \u2192 "hit the 30-min time budget".
|
|
5277
|
+
|
|
5278
|
+
**When \`delivered\` is 0**: NEVER say just "no results". Render no table; give
|
|
5279
|
+
the funnel line plus the relevant \`explain.scope_notes\` (the backend's own
|
|
5280
|
+
diagnosis), then propose the concrete fix (reshape the seed per the craft
|
|
5281
|
+
rules, lower \`min_ai_score\`, raise \`max_cost\`, drop a filter) as NEXT STEPS.
|
|
5282
|
+
|
|
5283
|
+
**Weak batch**: when the BEST delivered \`fit.score\` is under 30, don't present
|
|
5284
|
+
the table as an answer \u2014 open with "weak matches only", show at most the top 3,
|
|
5285
|
+
propose reshaping the seed/filters first. The count was filled with
|
|
5286
|
+
barely-better-than-random candidates.
|
|
5287
|
+
|
|
5288
|
+
**Sanity-check every row**: (a) geo \u2014 \`city\`/\`region\` must sit inside any
|
|
5289
|
+
requested fence; drop and call out leaks (same-named cities slip through).
|
|
5290
|
+
(b) When \`explain.seed_strategy\` is \`text_match_exemplars\` (the standard FR
|
|
5291
|
+
path), fit is calibrated for lead-to-lead distances, not exemplar centroids \u2014
|
|
5292
|
+
treat high scores skeptically and verify each row's \`description\`.
|
|
5293
|
+
|
|
5294
|
+
**Skipped items** (\`skipped[]\`, qualify jobs mostly): render a compact second
|
|
5295
|
+
table \`Ref \u2192 Outcome\` translating \`status_reason\` to plain words:
|
|
5296
|
+
\`not_in_universe\` \u2192 "not in the Leadbay universe (import it first)",
|
|
5297
|
+
\`low_confidence_identity\` \u2192 "couldn't safely match \u2014 check \`resolution.alternatives\`",
|
|
5298
|
+
\`no_matching_contact\` \u2192 "no contact with the requested title",
|
|
5299
|
+
\`disqualified\` \u2192 "evaluated: does not fit" (evidence is in the item when owned),
|
|
5300
|
+
\`enrichment_failed\` \u2192 "channel could not be sourced (not billed)".
|
|
5301
|
+
|
|
5302
|
+
**\`items_truncated\`**: rows are a PREFIX, not the batch. Say so, and offer
|
|
5303
|
+
\`leadbay_lead_job_status(job_id, since: next_since)\` for the rest.
|
|
5304
|
+
|
|
5305
|
+
**Hide from the user:** UUIDs (keep for tool calls, never render), cursors,
|
|
5306
|
+
\`explain.model\`/\`intelligence_snapshot\`, raw \`distance\`/\`calibration\`,
|
|
5307
|
+
\`seq\`/\`from_cache\`, empty arrays.
|
|
5308
|
+
|
|
5309
|
+
## Linking a contact's name
|
|
5310
|
+
|
|
5311
|
+
**MANDATORY: every contact name in your output \u2014 table cells, prose, headers, "Reach <Name>" callouts \u2014 MUST be wrapped in markdown link syntax \`[Name](URL)\`. Never render a contact name as bare text. A plain-text name is a broken contact card; the underlined name is the user's primary affordance for "take me to this person's profile". No "no URL available" exception \u2014 the search URL below is always constructable from name + company.**
|
|
5312
|
+
|
|
5313
|
+
URL priority (first applicable wins):
|
|
5314
|
+
|
|
5315
|
+
1. **Real profile** \u2014 \`contact.linkedin_page\` when it's a string starting with \`https://\` (the MCP coerces the legacy literal \`"null"\` string to real null before you see it).
|
|
5316
|
+
2. **Constructed people-search** \u2014 \`https://www.linkedin.com/search/results/people/?keywords=<First>+<Last>+<Company>\`. URL-encode params. Strip Inc / LLC / Corp / Ltd / GmbH / Co / S.A. / S.L. / PLC / AG / SAS / SARL suffixes from the company. Append a trailing \` \xB0\` to the rendered name ONLY when this fallback is in use AND \`social_presence.linkedin == false\`. Never append \`\xB0\` when a real \`linkedin_page\` was used.
|
|
5317
|
+
|
|
5318
|
+
Never link a person's name to the company's LinkedIn page (and vice versa) \u2014 the two surfaces are different and conflating them quietly degrades the workflow.
|
|
5319
|
+
|
|
5320
|
+
|
|
5321
|
+
|
|
5322
|
+
**Delivered \u2260 endorsed.** This tool DELIVERS org-owned companies that FAILED
|
|
5323
|
+
qualification, carrying their negative evidence \u2014 so a delivered item is not
|
|
5324
|
+
automatically a prospect. An item whose \`status_reason\` is \`disqualified\`, or
|
|
5325
|
+
whose \`fit.components.qualification\` is available with a negative \`ai_score\`,
|
|
5326
|
+
must NOT go in the fit table: its firmographic score can still be high, and a
|
|
5327
|
+
full bar beside "why it fits" reads as a recommendation to call an account the
|
|
5328
|
+
evaluation just rejected.
|
|
5329
|
+
|
|
5330
|
+
Give those their own short section after the fit table, titled
|
|
5331
|
+
**Evaluated \u2014 does not fit**: linked company, then the verdict in plain
|
|
5332
|
+
words from the
|
|
5333
|
+
qualification evidence (failed question verdicts, missed tags, IBP reasoning).
|
|
5334
|
+
That is the deliverable \u2014 "here's why to skip this account" \u2014 not a defect to
|
|
5335
|
+
hide.
|
|
5336
|
+
|
|
5337
|
+
|
|
5338
|
+
---
|
|
5339
|
+
|
|
5340
|
+
## NEXT STEPS \u2014 after a qualify_leads delivery
|
|
5341
|
+
|
|
5342
|
+
**ALWAYS render NEXT STEPS via your host's next-step widget.** Use whichever is in your tool set \u2014 the NAME and SCHEMA differ: **\`ask_user_input_v0\`** (Claude chat / ChatGPT) takes plain-string options with \`type:"single_select"\`; **\`AskUserQuestion\`** (Claude cowork / Claude Code) takes object options \`{label, description}\` plus a required short \`header\` (\u226412 chars) and \`multiSelect\`, NO \`type\` field, and never add an "Other" option (the host adds it). Match the schema to the tool you actually have \u2014 the wrong schema fails silently and you fall back to prose. Prose bullets are the fallback ONLY when NEITHER widget exists. Any turn that would end with a choice must be the widget \u2014 the widget IS the question.
|
|
5343
|
+
|
|
5344
|
+
**If the tool result carries a \`next_steps\` object, that is the source of truth \u2014 use it directly.** Each option has a short \`.label\` (\u22645 words) and a full \`.description\`. Map \`next_steps.options[]\` into your host widget VERBATIM and in order: for \`AskUserQuestion\` (cowork / Claude Code) pass each as \`{label, description}\`; for \`ask_user_input_v0\` (Claude chat / ChatGPT, string options only) pass each option's \`.description\` as the string (it's the full sentence). Do NOT reword, reorder, drop, or prose-ify them \u2014 they're built deterministically by the server so the offer (incl. the artifact option at position 0) fires every time. Fall back to the table below only when there is NO \`next_steps\` field.
|
|
5345
|
+
|
|
5346
|
+
**One exception \u2014 skip the widget** when the user's original message contained a complete sequential instruction chain ("show me X and then do Y") AND all stated steps have been completed. In that case, end with STOP directly \u2014 the user stated their full plan and does not need a "what next?" prompt.
|
|
5347
|
+
- Skip example: "Show me today's leads and then research the top one for me." \u2192 after research completes, emit STOP without the widget.
|
|
5348
|
+
- Do NOT skip for: plain requests ("show me today's leads", "run my check-in"), recurring-language requests ("I do this every day"), or requests where only one action was stated.
|
|
5349
|
+
|
|
5350
|
+
Pick 2\u20134 rows from the (Observation, Suggest, Calls) table below most relevant to the response, then call your host's widget with ITS schema (per the schema rules above \u2014 wrong schema fails silently):
|
|
5351
|
+
- \`ask_user_input_v0\`: \`{questions:[{question,type:"single_select",options:["<Suggest 1>","<Suggest 2>"]}]}\`
|
|
5352
|
+
- \`AskUserQuestion\`: \`{questions:[{question,header:"Next step",multiSelect:false,options:[{label:"<\u22645 words>",description:"<Suggest 1>"}]}]}\`
|
|
5353
|
+
|
|
5354
|
+
User picks \u2192 call the matching \`Calls\` tool. Constraints: 2\u20134 mutually-exclusive options, AskUserQuestion labels \u22645 words (full text in \`description\`), max 3 questions. Table stays internal; never recite it.
|
|
5355
|
+
|
|
5356
|
+
---
|
|
5357
|
+
|
|
5358
|
+
|
|
5359
|
+
|
|
5360
|
+
Pick the 2-3 options that match what actually happened:
|
|
5361
|
+
|
|
5362
|
+
| Observation | Suggest | Calls |
|
|
5363
|
+
|---|---|---|
|
|
5364
|
+
| Job still running | "Check on it in ~1 min" | leadbay_lead_job_status(job_id, wait_seconds: 60) |
|
|
5365
|
+
| Fit leads with contacts delivered | "Draft outreach for the qualified ones" | leadbay_prepare_outreach |
|
|
5366
|
+
| Items skipped \`not_in_universe\` | "Import those companies first, then re-qualify" | leadbay_import_leads \u2192 leadbay_qualify_leads |
|
|
5367
|
+
| Items skipped \`low_confidence_identity\` | "Pick the right match" (show \`resolution.alternatives\`) | leadbay_qualify_leads with the chosen lead_id |
|
|
5368
|
+
| Contacts delivered without channels | "Purchase verified emails/phones for the keepers (state cost first)" | leadbay_qualify_leads(lead_refs with contact_id, channels) |
|
|
5369
|
+
| Disqualified with evidence | "Review why \u2014 adjust qualification questions if the criteria are off" | leadbay_get_qualification_questions |
|
|
4552
5370
|
`;
|
|
4553
5371
|
leadbay_qualify_status = `Retrieve the current state of a bulk_qualify_leads or import_and_qualify launch. Which ids to pass depends on which tool launched it, because only one of them creates a qualification job on the backend:
|
|
4554
5372
|
|
|
@@ -6279,44 +7097,293 @@ WHEN TO USE: at the start of a session to know what the agent can/can't do, afte
|
|
|
6279
7097
|
|
|
6280
7098
|
WHEN NOT TO USE: as a pre-flight gate before bulk ops \u2014 operations themselves return 429; this tool is for context, not gating. And: a recent quota snapshot showing "exhausted" is NOT a reason to refuse a write call when the user has just topped up \u2014 re-call this tool first, then proceed.
|
|
6281
7099
|
`,
|
|
6282
|
-
|
|
7100
|
+
leadbay_find_new_leads: `## WHEN TO USE
|
|
6283
7101
|
|
|
6284
|
-
Trigger phrases: "
|
|
7102
|
+
Trigger phrases: "find me N companies that <profile>", "get me new prospects like <company>", "I need leads in <place> that <do X>", "search for companies that would buy <product>", "net-new leads outside my current pipeline", "we're entering <market> \u2014 who should we target".
|
|
6285
7103
|
|
|
6286
|
-
Do NOT use for: "
|
|
7104
|
+
Do NOT use for: "show me today's leads / what's new today" \u2192 \`leadbay_pull_leads\`; "find me new leads (no profile, no count named)" \u2192 \`leadbay_pull_leads\`; "more leads like the ones in my lens" \u2192 \`leadbay_extend_lens\`; "qualify / vet these companies I have" \u2192 \`leadbay_qualify_leads\`; "qualify the top N of my batch" \u2192 \`leadbay_bulk_qualify_leads\`; "leads I should follow up with" \u2192 \`leadbay_pull_followups\`; "tell me about <one company>" \u2192 \`leadbay_research_lead_by_name_fuzzy\`.
|
|
6287
7105
|
|
|
6288
|
-
Prefer when: user
|
|
7106
|
+
Prefer when: the user describes a target profile or names a count of NEW companies \u2014 craft the example_lead per the seed rules below BEFORE calling; never pass the user's raw sentence as query.
|
|
6289
7107
|
|
|
6290
7108
|
Examples that SHOULD invoke this tool:
|
|
6291
|
-
- "
|
|
6292
|
-
- "
|
|
6293
|
-
- "
|
|
7109
|
+
- "Find me 10 gyms around Dallas that would buy our flooring, with someone I can call."
|
|
7110
|
+
- "Get me 20 new US SaaS companies, 50-2000 employees, with the VP People's email."
|
|
7111
|
+
- "We're launching in Lyon \u2014 find 15 hotels that fit our ICP."
|
|
6294
7112
|
|
|
6295
7113
|
Examples that should NOT invoke this tool (sound similar, route elsewhere):
|
|
6296
|
-
- "
|
|
6297
|
-
- "
|
|
6298
|
-
- "Qualify
|
|
7114
|
+
- "Show me today's leads."
|
|
7115
|
+
- "Which leads should I follow up with this week?"
|
|
7116
|
+
- "Qualify these 40 websites from my spreadsheet."
|
|
6299
7117
|
|
|
6300
7118
|
## RENDER (quick)
|
|
6301
7119
|
|
|
6302
|
-
|
|
6303
|
-
|
|
6304
|
-
|
|
6305
|
-
|
|
6306
|
-
|
|
7120
|
+
3-col table of delivered leads in returned order: col 1 = 10-segment fit
|
|
7121
|
+
bar + linked company \xB7 location \xB7 size; col 2 = why-fits \u226420 words; col 3
|
|
7122
|
+
= contact + purchased channels. ALWAYS close with the honest funnel line
|
|
7123
|
+
(matched/examined/delivered/stop reason/spend) \u2014 especially on 0
|
|
7124
|
+
delivered. Full algorithm below.
|
|
6307
7125
|
|
|
6308
7126
|
---
|
|
6309
7127
|
|
|
6310
|
-
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
profile
|
|
7128
|
+
Submit a net-new lead search: the backend matches an ICP seed against the full
|
|
7129
|
+
company universe, applies hard filters, skips what the org already knows
|
|
7130
|
+
(\`novelty: org\`), optionally qualifies against the org's own intelligence
|
|
7131
|
+
(questions, tags, ideal buyer profile \u2014 frozen at submit), and optionally buys
|
|
7132
|
+
contact channels. Polls up to \`wait_seconds\` (default 45); a longer job returns
|
|
7133
|
+
\`still_running\` + \`next_poll\` \u2014 hand off to \`leadbay_lead_job_status\`. Jobs run
|
|
7134
|
+
\u226430 min, results kept 30 days.
|
|
7135
|
+
|
|
7136
|
+
**Free vs paid \u2014 never spend silently.** Default (\`qualify: false\`,
|
|
7137
|
+
\`channels: []\`) is FREE: company profile + fit score + cached research +
|
|
7138
|
+
contact identity. Paid: \`qualify: true\` (~94 cost_cents per candidate
|
|
7139
|
+
EXAMINED, capped by \`exploration_cap\`/\`max_cost\`) and \`channels\` (email 25c /
|
|
7140
|
+
phone 250c, success-only). Enforced in code: a paid call is WITHHELD unless it
|
|
7141
|
+
carries \`confirm: true\` \u2014 nothing is submitted and you get
|
|
7142
|
+
\`mode: "needs_confirmation"\` with a real quote to show the user. Re-call with
|
|
7143
|
+
\`confirm: true\` on their go-ahead ("spend / get their emails" counts).
|
|
7144
|
+
\`confirm: false\` vetoes. Free needs no consent. **Preview free first** \u2014
|
|
7145
|
+
reshaping an off-profile seed is free, exploring it with \`qualify: true\` is
|
|
7146
|
+
not.
|
|
7147
|
+
|
|
7148
|
+
**Ad-hoc exclusions ("no chains") are enforced by NO tier** \u2014 \`filters\` has no
|
|
7149
|
+
exclusion key, and \`qualify\` scores against the org's FROZEN questions and IBP,
|
|
7150
|
+
which need not mention chains; the seed's inverse only shifts ranking.
|
|
7151
|
+
Violators can survive, be paid for and be delivered \u2014 post-filter them yourself
|
|
7152
|
+
and say the tier didn't enforce it. Durable enforcement \u2192
|
|
7153
|
+
\`leadbay_refine_prompt\`.
|
|
7154
|
+
|
|
7155
|
+
### Crafting the \`example_lead\` seed \u2014 the input that decides result quality
|
|
7156
|
+
|
|
7157
|
+
The \`example_lead\` is a FICTIONAL typical ideal customer, matched against real
|
|
7158
|
+
registry/website descriptions \u2014 which state what a company **IS**, never what
|
|
7159
|
+
is happening. Write it the same way or the matcher drifts. Every rule below is
|
|
7160
|
+
measured:
|
|
7161
|
+
|
|
7162
|
+
1. **Describe the BUYER, never the seller.** Ask: "would this company write a
|
|
7163
|
+
check to my user?" A seed describing what the user SELLS surfaces their
|
|
7164
|
+
*competitors and vendors*. If the product helps companies of type X serve
|
|
7165
|
+
customers of type Y, the seed describes X \u2014 never Y.
|
|
7166
|
+
2. **Put everything in \`description\`; leave \`name\` unset.** An invented brand
|
|
7167
|
+
name pulls matching toward name-lookalikes \u2014 a seed named "Meridian
|
|
7168
|
+
Analytics" returned five unrelated "Meridian" companies.
|
|
7169
|
+
3. **Registry style, one sentence to ~250 chars.** Industry niche, business
|
|
7170
|
+
model, what they sell or operate, who they serve, observable scale. Write
|
|
7171
|
+
it like the first paragraph of their About-Us page.
|
|
7172
|
+
- STRONG: "Operator of full-service fitness centers offering strength
|
|
7173
|
+
areas, group classes and personal training to members across multiple
|
|
7174
|
+
clubs."
|
|
7175
|
+
- WEAK (generic): "A gym in Texas."
|
|
7176
|
+
- WRONG (seller-side): "Supplier of durable modular flooring for gyms."
|
|
7177
|
+
4. **No event language.** "hiring", "expanding", "just raised" are not
|
|
7178
|
+
filters \u2014 registry descriptions never contain them, so they dilute the
|
|
7179
|
+
profile. Purchase triggers belong in the org's qualification questions.
|
|
7180
|
+
5. **No meta-markers.** Never "(example)", "(fictional)", "(placeholder)".
|
|
7181
|
+
6. **Hard constraints go in \`filters\`, not prose \u2014 exact keys:**
|
|
7182
|
+
\`sectors: string[]\`, \`locations: string[]\`, \`employees_min: number\`,
|
|
7183
|
+
\`employees_max: number\`. FLAT numbers \u2014 nested \`employees: {min, max}\`
|
|
7184
|
+
exists only in RESULT payloads. \`example_lead.employees\` does not filter.
|
|
7185
|
+
\`locations\` take city/state/region names ("Dallas, TX", "\xCEle-de-France");
|
|
7186
|
+
a country name is refused in code \u2014 whole-country intent = omit it.
|
|
7187
|
+
7. **Prefer \`example_lead\` over \`query\`.** Query matches topic *vocabulary*:
|
|
7188
|
+
"gyms that need durable flooring" surfaced flooring VENDORS, 0 delivered.
|
|
7189
|
+
Use \`query\` only for signal an example can't express.
|
|
7190
|
+
8. **One seed per buyer archetype.** An ask spanning two segments ("gyms and
|
|
7191
|
+
warehouses") needs one search each with its own description and
|
|
7192
|
+
\`request_id\` \u2014 a blended seed lands between the clusters and matches
|
|
7193
|
+
neither.
|
|
7194
|
+
|
|
7195
|
+
|
|
7196
|
+
**Parameter notes**
|
|
7197
|
+
- \`request_id\` (REQUIRED) is the retry contract: SAME value retrying the same
|
|
7198
|
+
ask (same live job, no double spend); NEW for a changed ask. Derive from ask
|
|
7199
|
+
+ archetype + date: \`gyms-dallas-2026-07-28\`.
|
|
7200
|
+
- Never lower \`min_ai_score\` together with \`channels\` \u2014 that buys emails for
|
|
7201
|
+
leads the AI just scored as junk.
|
|
7202
|
+
- \`count\` \u2264 50; \u22643 active jobs/org; \u226410 submits/hour (429 + Retry-After \u2014
|
|
7203
|
+
wait, don't hammer).
|
|
7204
|
+
|
|
7205
|
+
**Read the result honestly** \u2014 \`funnel\` + \`explain.scope_notes\` tell the story;
|
|
7206
|
+
zero delivered gets a cause and a next move (rules in RENDERING).
|
|
6314
7207
|
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
7208
|
+
---
|
|
7209
|
+
|
|
7210
|
+
## RENDERING \u2014 delivery table + honest funnel line
|
|
7211
|
+
|
|
7212
|
+
Render delivered leads (\`leads[]\`, i.e. items with status \`delivered\` or
|
|
7213
|
+
\`degraded\`) as a markdown table **in the order returned**. Exactly three
|
|
7214
|
+
columns. Then ALWAYS close with the funnel line (below) \u2014 even, especially,
|
|
7215
|
+
when nothing was delivered.
|
|
7216
|
+
|
|
7217
|
+
**Column 1 \u2014 Company**
|
|
7218
|
+
|
|
7219
|
+
- Line 1: 10-segment fit bar in inline-code backticks from \`lead.fit.score\`
|
|
7220
|
+
(0-100): \`filled = round(score/10)\`, glyphs \`\u25B0\` filled / \`\u25B1\` empty. When
|
|
7221
|
+
\`lead.fit.components.qualification.available\` is true AND \`ai_score > 0\`,
|
|
7222
|
+
replace the LAST filled segment with \`\u2756\` (AI-confirmed cap). When
|
|
7223
|
+
\`fit.available\` is false, render \`\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1\` and say "unscored" in col 2.
|
|
7224
|
+
Never print the numeric score.
|
|
7225
|
+
- Insert \`<br>\`, then: linked company name (target \`company.website\`, bare
|
|
7226
|
+
hostnames get \`https://\`; unlinked plain text when absent) + \` \xB7 \` + short
|
|
7227
|
+
location (City, ST / City, Country) + \` \xB7 \` + employees as \`min\u2013max\` (omit
|
|
7228
|
+
when \`employees.known\` is false).
|
|
7229
|
+
|
|
7230
|
+
**Column 2 \u2014 Why it fits**
|
|
7231
|
+
|
|
7232
|
+
- One sentence \u2264 20 words. Priority: \`fit.reasoning\` \u2192 gist of
|
|
7233
|
+
\`company.description\` \u2192 top \`fit.components.qualification.matched_tags\`.
|
|
7234
|
+
- If the item status is \`degraded\` or a requested channel failed, append the
|
|
7235
|
+
honest flag in italics, e.g. *(email could not be sourced)*.
|
|
7236
|
+
|
|
7237
|
+
**Column 3 \u2014 Contact**
|
|
7238
|
+
|
|
7239
|
+
- \`[Name](linkedin) \xB7 role\` (linked name mandatory when a LinkedIn URL
|
|
7240
|
+
exists; plain name otherwise). Below it, the PURCHASED channels only:
|
|
7241
|
+
\`\u2709 value\` / \`\u260E value\` inline as plain text (they auto-linkify).
|
|
7242
|
+
- Channel statuses: \`delivered\` \u2192 show value; \`already_owned\` \u2192 value +
|
|
7243
|
+
*(already yours)*; \`masked\` \u2192 "on file \u2014 reveal via channels";
|
|
7244
|
+
\`not_requested\` \u2192 omit; \`failed_*\` \u2192 *(no verified email/phone)*.
|
|
7245
|
+
- No contact on the item (\`contact\` null): render \`\u2014\` (title_gate \`prefer\`
|
|
7246
|
+
delivers such rows flagged; say so in col 2 only when contact_titles were
|
|
7247
|
+
requested).
|
|
7248
|
+
|
|
7249
|
+
**The funnel line (mandatory, after the table):**
|
|
7250
|
+
|
|
7251
|
+
One short line narrating the delivery honestly, from \`funnel\` + \`cost\` +
|
|
7252
|
+
\`explain.scope_notes\`:
|
|
7253
|
+
|
|
7254
|
+
> Matched N \xB7 examined E \xB7 qualified Q \xB7 disqualified D \u2192 **delivered X of
|
|
7255
|
+
> the Y asked** \xB7 stopped: <stop_reason in plain words> \xB7 spent C.CC.
|
|
7256
|
+
|
|
7257
|
+
**Money: divide, then symbol.** Every amount (\`cost.spent\`,
|
|
7258
|
+
\`estimated_cost.max\`, quotes) is \`cost_cents\` \u2014 divide by 100, two decimals,
|
|
7259
|
+
so \`165\` renders \`1.65\`, NEVER \`165.00\`. Symbol from the account region: US
|
|
7260
|
+
\`$\`, France \`\u20AC\`, unknown \u2192 bare. Never hard-code \`$\`: it misstates a charge.
|
|
7261
|
+
|
|
7262
|
+
"of the Y asked" needs \`summary.items_requested\`, which submits carry but a
|
|
7263
|
+
later \`leadbay_lead_job_status\` snapshot does not. Without it write **delivered
|
|
7264
|
+
X** and stop \u2014 never back-fill Y from \`matched\`/\`examined\` (they count
|
|
7265
|
+
candidates), never guess it.
|
|
7266
|
+
|
|
7267
|
+
Plain-word stop reasons: \`target_reached\` \u2192 omit (success), \`pool_exhausted\` \u2192
|
|
7268
|
+
"ran out of matching candidates", \`max_cost\` \u2192 "hit the cost cap", \`quota\` \u2192
|
|
7269
|
+
"hit an org quota", \`time_budget\` \u2192 "hit the 30-min time budget".
|
|
7270
|
+
|
|
7271
|
+
**When \`delivered\` is 0**: NEVER say just "no results". Render no table; give
|
|
7272
|
+
the funnel line plus the relevant \`explain.scope_notes\` (the backend's own
|
|
7273
|
+
diagnosis), then propose the concrete fix (reshape the seed per the craft
|
|
7274
|
+
rules, lower \`min_ai_score\`, raise \`max_cost\`, drop a filter) as NEXT STEPS.
|
|
7275
|
+
|
|
7276
|
+
**Weak batch**: when the BEST delivered \`fit.score\` is under 30, don't present
|
|
7277
|
+
the table as an answer \u2014 open with "weak matches only", show at most the top 3,
|
|
7278
|
+
propose reshaping the seed/filters first. The count was filled with
|
|
7279
|
+
barely-better-than-random candidates.
|
|
7280
|
+
|
|
7281
|
+
**Sanity-check every row**: (a) geo \u2014 \`city\`/\`region\` must sit inside any
|
|
7282
|
+
requested fence; drop and call out leaks (same-named cities slip through).
|
|
7283
|
+
(b) When \`explain.seed_strategy\` is \`text_match_exemplars\` (the standard FR
|
|
7284
|
+
path), fit is calibrated for lead-to-lead distances, not exemplar centroids \u2014
|
|
7285
|
+
treat high scores skeptically and verify each row's \`description\`.
|
|
7286
|
+
|
|
7287
|
+
**Skipped items** (\`skipped[]\`, qualify jobs mostly): render a compact second
|
|
7288
|
+
table \`Ref \u2192 Outcome\` translating \`status_reason\` to plain words:
|
|
7289
|
+
\`not_in_universe\` \u2192 "not in the Leadbay universe (import it first)",
|
|
7290
|
+
\`low_confidence_identity\` \u2192 "couldn't safely match \u2014 check \`resolution.alternatives\`",
|
|
7291
|
+
\`no_matching_contact\` \u2192 "no contact with the requested title",
|
|
7292
|
+
\`disqualified\` \u2192 "evaluated: does not fit" (evidence is in the item when owned),
|
|
7293
|
+
\`enrichment_failed\` \u2192 "channel could not be sourced (not billed)".
|
|
7294
|
+
|
|
7295
|
+
**\`items_truncated\`**: rows are a PREFIX, not the batch. Say so, and offer
|
|
7296
|
+
\`leadbay_lead_job_status(job_id, since: next_since)\` for the rest.
|
|
7297
|
+
|
|
7298
|
+
**Hide from the user:** UUIDs (keep for tool calls, never render), cursors,
|
|
7299
|
+
\`explain.model\`/\`intelligence_snapshot\`, raw \`distance\`/\`calibration\`,
|
|
7300
|
+
\`seq\`/\`from_cache\`, empty arrays.
|
|
7301
|
+
|
|
7302
|
+
## Linking a contact's name
|
|
7303
|
+
|
|
7304
|
+
**MANDATORY: every contact name in your output \u2014 table cells, prose, headers, "Reach <Name>" callouts \u2014 MUST be wrapped in markdown link syntax \`[Name](URL)\`. Never render a contact name as bare text. A plain-text name is a broken contact card; the underlined name is the user's primary affordance for "take me to this person's profile". No "no URL available" exception \u2014 the search URL below is always constructable from name + company.**
|
|
7305
|
+
|
|
7306
|
+
URL priority (first applicable wins):
|
|
7307
|
+
|
|
7308
|
+
1. **Real profile** \u2014 \`contact.linkedin_page\` when it's a string starting with \`https://\` (the MCP coerces the legacy literal \`"null"\` string to real null before you see it).
|
|
7309
|
+
2. **Constructed people-search** \u2014 \`https://www.linkedin.com/search/results/people/?keywords=<First>+<Last>+<Company>\`. URL-encode params. Strip Inc / LLC / Corp / Ltd / GmbH / Co / S.A. / S.L. / PLC / AG / SAS / SARL suffixes from the company. Append a trailing \` \xB0\` to the rendered name ONLY when this fallback is in use AND \`social_presence.linkedin == false\`. Never append \`\xB0\` when a real \`linkedin_page\` was used.
|
|
7310
|
+
|
|
7311
|
+
Never link a person's name to the company's LinkedIn page (and vice versa) \u2014 the two surfaces are different and conflating them quietly degrades the workflow.
|
|
7312
|
+
|
|
7313
|
+
|
|
7314
|
+
|
|
7315
|
+
---
|
|
7316
|
+
|
|
7317
|
+
## NEXT STEPS \u2014 after a find_new_leads delivery
|
|
7318
|
+
|
|
7319
|
+
**ALWAYS render NEXT STEPS via your host's next-step widget.** Use whichever is in your tool set \u2014 the NAME and SCHEMA differ: **\`ask_user_input_v0\`** (Claude chat / ChatGPT) takes plain-string options with \`type:"single_select"\`; **\`AskUserQuestion\`** (Claude cowork / Claude Code) takes object options \`{label, description}\` plus a required short \`header\` (\u226412 chars) and \`multiSelect\`, NO \`type\` field, and never add an "Other" option (the host adds it). Match the schema to the tool you actually have \u2014 the wrong schema fails silently and you fall back to prose. Prose bullets are the fallback ONLY when NEITHER widget exists. Any turn that would end with a choice must be the widget \u2014 the widget IS the question.
|
|
7320
|
+
|
|
7321
|
+
**If the tool result carries a \`next_steps\` object, that is the source of truth \u2014 use it directly.** Each option has a short \`.label\` (\u22645 words) and a full \`.description\`. Map \`next_steps.options[]\` into your host widget VERBATIM and in order: for \`AskUserQuestion\` (cowork / Claude Code) pass each as \`{label, description}\`; for \`ask_user_input_v0\` (Claude chat / ChatGPT, string options only) pass each option's \`.description\` as the string (it's the full sentence). Do NOT reword, reorder, drop, or prose-ify them \u2014 they're built deterministically by the server so the offer (incl. the artifact option at position 0) fires every time. Fall back to the table below only when there is NO \`next_steps\` field.
|
|
7322
|
+
|
|
7323
|
+
**One exception \u2014 skip the widget** when the user's original message contained a complete sequential instruction chain ("show me X and then do Y") AND all stated steps have been completed. In that case, end with STOP directly \u2014 the user stated their full plan and does not need a "what next?" prompt.
|
|
7324
|
+
- Skip example: "Show me today's leads and then research the top one for me." \u2192 after research completes, emit STOP without the widget.
|
|
7325
|
+
- Do NOT skip for: plain requests ("show me today's leads", "run my check-in"), recurring-language requests ("I do this every day"), or requests where only one action was stated.
|
|
7326
|
+
|
|
7327
|
+
Pick 2\u20134 rows from the (Observation, Suggest, Calls) table below most relevant to the response, then call your host's widget with ITS schema (per the schema rules above \u2014 wrong schema fails silently):
|
|
7328
|
+
- \`ask_user_input_v0\`: \`{questions:[{question,type:"single_select",options:["<Suggest 1>","<Suggest 2>"]}]}\`
|
|
7329
|
+
- \`AskUserQuestion\`: \`{questions:[{question,header:"Next step",multiSelect:false,options:[{label:"<\u22645 words>",description:"<Suggest 1>"}]}]}\`
|
|
7330
|
+
|
|
7331
|
+
User picks \u2192 call the matching \`Calls\` tool. Constraints: 2\u20134 mutually-exclusive options, AskUserQuestion labels \u22645 words (full text in \`description\`), max 3 questions. Table stays internal; never recite it.
|
|
7332
|
+
|
|
7333
|
+
---
|
|
7334
|
+
|
|
7335
|
+
|
|
7336
|
+
|
|
7337
|
+
Pick the 2-3 options that match what actually happened \u2014 never all seven:
|
|
7338
|
+
|
|
7339
|
+
| Observation | Suggest | Calls |
|
|
7340
|
+
|---|---|---|
|
|
7341
|
+
| Job still running (\`still_running: true\`) | "Check on it in ~1 min" | leadbay_lead_job_status(job_id, wait_seconds: 60) |
|
|
7342
|
+
| Free run delivered on-profile leads | "Qualify these N against your criteria (paid \u2014 \`dry_run\` first)" | leadbay_qualify_leads(prior_deliveries: {job_id}) |
|
|
7343
|
+
| Delivered leads look right | "Draft outreach for the top ones" | leadbay_prepare_outreach |
|
|
7344
|
+
| Delivered 0 or off-profile | "Reshape the example and retry" (name the fix from funnel + scope_notes) | leadbay_find_new_leads (NEW request_id) |
|
|
7345
|
+
| Stopped at cost cap (\`stop_reason: max_cost\`) | "Raise the cap to X and get the remaining N" \u2014 X in the account's currency per the funnel-line rule, never a hard-coded \`$\` | leadbay_find_new_leads, NEW request_id (same-id only dedupes onto a LIVE job) + higher max_cost + \`count\` = the SHORTFALL (\`items_requested\` \u2212 delivered), not the original + \`exclude_lead_ids\` = the examined-but-REJECTED ids (novelty covers delivered; these are what it misses \u2014 without them the rerun re-buys the same losers) |
|
|
7346
|
+
| Stopped on org quota (\`stop_reason: quota\`) | "Check which window is exhausted and when it resets" \u2014 never a re-run: it cannot clear an org quota and burns a submit slot to stop in the same place | leadbay_account_status |
|
|
7347
|
+
| User wants these tracked in Leadbay | "Add the keepers to a campaign" | leadbay_create_campaign / leadbay_add_leads_to_campaign |
|
|
7348
|
+
`,
|
|
7349
|
+
leadbay_scan_portfolio_signals: `## WHEN TO USE
|
|
7350
|
+
|
|
7351
|
+
Trigger phrases: "which of my leads <did X>", "find leads that <raised / acquired / hired / moved / changed CEO>", "scan my portfolio for <signal>", "identify all the ones that <event> since <date>", "who in Monitor has a <funding / M&A / hiring> signal", "build a campaign from leads with <signal>".
|
|
7352
|
+
|
|
7353
|
+
Do NOT use for: "research one named company" \u2192 \`leadbay_research_lead_by_name_fuzzy\`; "everything about lead <UUID>" \u2192 \`leadbay_research_lead_by_id\`; "qualify my next N leads (they aren't researched yet)" \u2192 \`leadbay_bulk_qualify_leads\`; "just list my follow-ups" \u2192 \`leadbay_pull_followups\`.
|
|
7354
|
+
|
|
7355
|
+
Prefer when: user wants to FILTER a known portfolio by a web-research signal in bulk \u2014 pass \`query\`, optionally \`since\`, \`city\`/\`set_filter\`, or \`leadIds\`; NEVER a country name in \`city\` \u2014 a whole-country ask means NO geo filter
|
|
7356
|
+
|
|
7357
|
+
Examples that SHOULD invoke this tool:
|
|
7358
|
+
- "Which of my leads acquired a company since 2025?"
|
|
7359
|
+
- "Scan my Lyon portfolio for funding signals."
|
|
7360
|
+
- "Find everyone in Monitor who changed CEO and build a campaign."
|
|
7361
|
+
|
|
7362
|
+
Examples that should NOT invoke this tool (sound similar, route elsewhere):
|
|
7363
|
+
- "Look up Acme Corp for me."
|
|
7364
|
+
- "Show me my follow-ups."
|
|
7365
|
+
- "Qualify my next 10 leads."
|
|
7366
|
+
|
|
7367
|
+
## RENDER (quick)
|
|
7368
|
+
|
|
7369
|
+
Cohort grouped by lead: one block per matched lead (name \xB7 location +
|
|
7370
|
+
its matched signal entries, hot first, source-linked). Open with
|
|
7371
|
+
"N match <query> (M scanned)"; ALWAYS close with an honesty footer \u2014
|
|
7372
|
+
"scanned N \xB7 matched M \xB7 K not yet researched". Never present
|
|
7373
|
+
not_researched leads as "no signal". Full layout below.
|
|
7374
|
+
|
|
7375
|
+
---
|
|
7376
|
+
|
|
7377
|
+
Scan a known portfolio for a specific web-research signal in one call. This is
|
|
7378
|
+
the bulk, read-only answer to "which of my leads have signal X" \u2014 the question
|
|
7379
|
+
that otherwise forces a per-lead \`leadbay_research_lead_by_id\` loop (one full
|
|
7380
|
+
profile call per lead, slow and quota-heavy).
|
|
7381
|
+
|
|
7382
|
+
**Reads CACHED signals only \u2014 does not trigger new research.** For each lead in
|
|
7383
|
+
scope it reads \`GET /leads/{id}/web_fetch\` (the already-computed web-research
|
|
7384
|
+
signals) and filters the entries against \`query\`. It issues NO web_fetch POST,
|
|
7385
|
+
so it does not consume AI qualification credits and does not re-crawl. Leads
|
|
7386
|
+
that have no cached content (never qualified, or still in progress) are
|
|
6320
7387
|
reported in \`not_researched\` \u2014 they are **NOT** silently treated as "no
|
|
6321
7388
|
match". Qualify them with \`leadbay_bulk_qualify_leads\`, then re-scan.
|
|
6322
7389
|
|
|
@@ -13385,12 +14452,12 @@ var init_pull_leads = __esm({
|
|
|
13385
14452
|
});
|
|
13386
14453
|
|
|
13387
14454
|
// ../core/dist/composite/_geo-helpers.js
|
|
13388
|
-
function expandAlias(
|
|
13389
|
-
const key =
|
|
13390
|
-
return CITY_ALIASES[key] ??
|
|
14455
|
+
function expandAlias(text2) {
|
|
14456
|
+
const key = text2.trim().toLowerCase();
|
|
14457
|
+
return CITY_ALIASES[key] ?? text2;
|
|
13391
14458
|
}
|
|
13392
|
-
function scoreMatch(
|
|
13393
|
-
const t =
|
|
14459
|
+
function scoreMatch(text2, match) {
|
|
14460
|
+
const t = text2.trim().toLowerCase();
|
|
13394
14461
|
const n = match.name.trim().toLowerCase();
|
|
13395
14462
|
if (n === t)
|
|
13396
14463
|
return 1;
|
|
@@ -13413,8 +14480,8 @@ async function resolveLocations(client, texts) {
|
|
|
13413
14480
|
const resolved = [...direct];
|
|
13414
14481
|
const ambiguities = [];
|
|
13415
14482
|
for (const originalText of free) {
|
|
13416
|
-
const
|
|
13417
|
-
const path = `/geo/search?q=${encodeURIComponent(
|
|
14483
|
+
const text2 = expandAlias(originalText);
|
|
14484
|
+
const path = `/geo/search?q=${encodeURIComponent(text2)}`;
|
|
13418
14485
|
let response;
|
|
13419
14486
|
try {
|
|
13420
14487
|
response = await client.request("GET", path);
|
|
@@ -13453,7 +14520,7 @@ async function resolveLocations(client, texts) {
|
|
|
13453
14520
|
name: r.name,
|
|
13454
14521
|
country: r.country,
|
|
13455
14522
|
level: r.level,
|
|
13456
|
-
score: scoreMatch(
|
|
14523
|
+
score: scoreMatch(text2, r)
|
|
13457
14524
|
})).sort((a, b) => {
|
|
13458
14525
|
if (b.score !== a.score)
|
|
13459
14526
|
return b.score - a.score;
|
|
@@ -14723,9 +15790,9 @@ ${firm.short_description}`);
|
|
|
14723
15790
|
out.push(`### ${sec.section_emoji ?? ""} ${label}`.trim());
|
|
14724
15791
|
const entries = Array.isArray(sec.entries) ? sec.entries : [];
|
|
14725
15792
|
for (const e of entries.slice(0, 5)) {
|
|
14726
|
-
const
|
|
15793
|
+
const text2 = e.text ?? e.summary ?? JSON.stringify(e).slice(0, 200);
|
|
14727
15794
|
const hot = e.hot === true ? " \u{1F525}" : "";
|
|
14728
|
-
out.push(`- ${
|
|
15795
|
+
out.push(`- ${text2}${hot}`);
|
|
14729
15796
|
}
|
|
14730
15797
|
if (entries.length > 5)
|
|
14731
15798
|
out.push(`- _${entries.length - 5} more \u2026_`);
|
|
@@ -19455,8 +20522,8 @@ function tokens(s) {
|
|
|
19455
20522
|
return [];
|
|
19456
20523
|
return s.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);
|
|
19457
20524
|
}
|
|
19458
|
-
function bestMatches(
|
|
19459
|
-
const want = new Set(tokens(
|
|
20525
|
+
function bestMatches(text2, taxonomy) {
|
|
20526
|
+
const want = new Set(tokens(text2));
|
|
19460
20527
|
if (want.size === 0)
|
|
19461
20528
|
return [];
|
|
19462
20529
|
const ranked = taxonomy.map((s) => {
|
|
@@ -19485,12 +20552,12 @@ async function resolveSectors(client, texts, ctx) {
|
|
|
19485
20552
|
}
|
|
19486
20553
|
const resolved = [...direct];
|
|
19487
20554
|
const ambiguities = [];
|
|
19488
|
-
for (const
|
|
19489
|
-
const matches = bestMatches(
|
|
20555
|
+
for (const text2 of free) {
|
|
20556
|
+
const matches = bestMatches(text2, taxonomy);
|
|
19490
20557
|
if (matches.length === 1 || matches.length >= 2 && matches[0].score >= 0.66 && matches[0].score - matches[1].score >= 0.34) {
|
|
19491
20558
|
resolved.push(matches[0].id);
|
|
19492
20559
|
} else {
|
|
19493
|
-
ambiguities.push({ sector_text:
|
|
20560
|
+
ambiguities.push({ sector_text: text2, matches });
|
|
19494
20561
|
}
|
|
19495
20562
|
}
|
|
19496
20563
|
return { resolved, ambiguities };
|
|
@@ -20178,6 +21245,1254 @@ var init_seed_candidates = __esm({
|
|
|
20178
21245
|
}
|
|
20179
21246
|
});
|
|
20180
21247
|
|
|
21248
|
+
// ../core/dist/composite/_mcp-job-helpers.js
|
|
21249
|
+
import { createHash as createHash4 } from "crypto";
|
|
21250
|
+
function assertSafeJobId(jobId) {
|
|
21251
|
+
const reject = (why) => {
|
|
21252
|
+
throw {
|
|
21253
|
+
error: true,
|
|
21254
|
+
code: "INVALID_JOB_ID",
|
|
21255
|
+
message: `job_id ${why}.`,
|
|
21256
|
+
hint: "Pass the job_id exactly as leadbay_find_new_leads or leadbay_qualify_leads returned it \u2014 it is an opaque handle, not a path."
|
|
21257
|
+
};
|
|
21258
|
+
};
|
|
21259
|
+
if (typeof jobId !== "string" || jobId.length === 0)
|
|
21260
|
+
return reject("must be a non-empty string");
|
|
21261
|
+
if (jobId.length > MAX_JOB_ID_LENGTH)
|
|
21262
|
+
return reject(`is ${jobId.length} chars \u2014 the maximum is ${MAX_JOB_ID_LENGTH}`);
|
|
21263
|
+
if (/^\.+$/.test(jobId))
|
|
21264
|
+
return reject("cannot be a dot segment");
|
|
21265
|
+
if (!JOB_ID_CHARSET.test(jobId))
|
|
21266
|
+
return reject("contains characters that are not valid in a job handle");
|
|
21267
|
+
return encodeURIComponent(jobId);
|
|
21268
|
+
}
|
|
21269
|
+
async function collectJobSnapshot(client, jobId, since, limit, signal, timeoutMs = SNAPSHOT_TIMEOUT_MS) {
|
|
21270
|
+
if (signal?.aborted)
|
|
21271
|
+
throw cancelledError(jobId);
|
|
21272
|
+
const pageLimit = Math.min(Math.max(limit ?? PAGE_LIMIT, 1), PAGE_LIMIT);
|
|
21273
|
+
const safeJobId = assertSafeJobId(jobId);
|
|
21274
|
+
const qs = (cursor2) => `/mcp/jobs/${safeJobId}?limit=${pageLimit}` + (cursor2 ? `&since=${encodeURIComponent(cursor2)}` : "");
|
|
21275
|
+
const maxPages = maxPagesFor(pageLimit);
|
|
21276
|
+
const deadlineAt = Date.now() + timeoutMs;
|
|
21277
|
+
const remaining = () => deadlineAt - Date.now();
|
|
21278
|
+
let page = await client.request("GET", qs(since), void 0, {
|
|
21279
|
+
signal,
|
|
21280
|
+
// totalTimeoutMs, not timeoutMs: what is left of the wait must cover a 401
|
|
21281
|
+
// backoff and its retry too, or a blip buys the poll a second full budget.
|
|
21282
|
+
totalTimeoutMs: remaining()
|
|
21283
|
+
});
|
|
21284
|
+
const items = [...page.items];
|
|
21285
|
+
let cursor = page.next_since ?? since ?? null;
|
|
21286
|
+
let pages = 1;
|
|
21287
|
+
while (page.items.length >= pageLimit && page.next_since && pages < maxPages && !signal?.aborted) {
|
|
21288
|
+
if (remaining() <= 0)
|
|
21289
|
+
break;
|
|
21290
|
+
let next;
|
|
21291
|
+
try {
|
|
21292
|
+
next = await client.request("GET", qs(page.next_since), void 0, { signal, totalTimeoutMs: remaining() });
|
|
21293
|
+
} catch (e) {
|
|
21294
|
+
if (isTimeout(e))
|
|
21295
|
+
break;
|
|
21296
|
+
throw e;
|
|
21297
|
+
}
|
|
21298
|
+
items.push(...next.items);
|
|
21299
|
+
pages += 1;
|
|
21300
|
+
page = next;
|
|
21301
|
+
if (next.items.length === 0) {
|
|
21302
|
+
break;
|
|
21303
|
+
}
|
|
21304
|
+
cursor = next.next_since ?? cursor;
|
|
21305
|
+
}
|
|
21306
|
+
const itemsTruncated = page.items.length >= pageLimit && !!page.next_since;
|
|
21307
|
+
return {
|
|
21308
|
+
...page,
|
|
21309
|
+
items,
|
|
21310
|
+
next_since: cursor,
|
|
21311
|
+
...itemsTruncated ? { items_truncated: true } : {}
|
|
21312
|
+
};
|
|
21313
|
+
}
|
|
21314
|
+
function sleepUnlessAborted(ms, signal) {
|
|
21315
|
+
if (signal?.aborted)
|
|
21316
|
+
return Promise.resolve();
|
|
21317
|
+
return new Promise((resolve) => {
|
|
21318
|
+
const done = () => {
|
|
21319
|
+
clearTimeout(timer);
|
|
21320
|
+
signal?.removeEventListener("abort", done);
|
|
21321
|
+
resolve();
|
|
21322
|
+
};
|
|
21323
|
+
const timer = setTimeout(done, ms);
|
|
21324
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
21325
|
+
});
|
|
21326
|
+
}
|
|
21327
|
+
function cancelledError(jobId) {
|
|
21328
|
+
return {
|
|
21329
|
+
error: true,
|
|
21330
|
+
code: "REQUEST_CANCELLED",
|
|
21331
|
+
message: `The wait for job ${jobId} was cancelled before any status was read.`,
|
|
21332
|
+
hint: "The job itself is backend-owned and keeps running. Poll leadbay_lead_job_status when you want its result."
|
|
21333
|
+
};
|
|
21334
|
+
}
|
|
21335
|
+
function snapshotBudget(remainingMs) {
|
|
21336
|
+
return Math.min(SNAPSHOT_TIMEOUT_MS, Math.max(remainingMs, 1));
|
|
21337
|
+
}
|
|
21338
|
+
function isTimeout(e) {
|
|
21339
|
+
return typeof e === "object" && e !== null && e.code === "TIMEOUT";
|
|
21340
|
+
}
|
|
21341
|
+
function jobReadTimedOutError(jobId, waitSeconds) {
|
|
21342
|
+
return {
|
|
21343
|
+
error: true,
|
|
21344
|
+
code: "JOB_READ_TIMEOUT",
|
|
21345
|
+
// Structured, not just interpolated: a caller recovering programmatically
|
|
21346
|
+
// should not have to parse the message to find the handle.
|
|
21347
|
+
job_id: jobId,
|
|
21348
|
+
message: `Job ${jobId} was submitted and is running, but its status could not be read within ${waitSeconds}s.`,
|
|
21349
|
+
hint: `Pass job_id ${jobId} to leadbay_lead_job_status to read it \u2014 the job is backend-owned, still running, and its results are kept for 30 days.`
|
|
21350
|
+
};
|
|
21351
|
+
}
|
|
21352
|
+
function jobHandleError(jobId, cause) {
|
|
21353
|
+
const c = cause;
|
|
21354
|
+
if (c?.job_id === jobId)
|
|
21355
|
+
return cause;
|
|
21356
|
+
return {
|
|
21357
|
+
error: true,
|
|
21358
|
+
code: c?.code ?? "JOB_READ_FAILED",
|
|
21359
|
+
job_id: jobId,
|
|
21360
|
+
message: `Job ${jobId} was submitted and is running, but reading its status failed: ${c?.message ?? String(cause)}`,
|
|
21361
|
+
hint: `Pass job_id ${jobId} to leadbay_lead_job_status to read it \u2014 the job is backend-owned, keeps running whatever happened to this call, and its results are kept for 30 days.`
|
|
21362
|
+
};
|
|
21363
|
+
}
|
|
21364
|
+
async function snapshotAfterSubmit(client, jobId, waitSeconds, ctx, itemsRequested) {
|
|
21365
|
+
try {
|
|
21366
|
+
return waitSeconds > 0 ? await waitForJob(client, jobId, waitSeconds, ctx, itemsRequested) : await collectJobSnapshot(client, jobId, void 0, void 0, ctx?.signal);
|
|
21367
|
+
} catch (e) {
|
|
21368
|
+
throw jobHandleError(jobId, e);
|
|
21369
|
+
}
|
|
21370
|
+
}
|
|
21371
|
+
async function waitForJob(client, jobId, waitSeconds, ctx, itemsRequested, since, limit) {
|
|
21372
|
+
const startedAt = Date.now();
|
|
21373
|
+
const remainingMsOf = () => waitSeconds * 1e3 - (Date.now() - startedAt);
|
|
21374
|
+
if (ctx?.signal?.aborted)
|
|
21375
|
+
throw cancelledError(jobId);
|
|
21376
|
+
let snap;
|
|
21377
|
+
try {
|
|
21378
|
+
snap = await collectJobSnapshot(client, jobId, since, limit, ctx?.signal, snapshotBudget(remainingMsOf()));
|
|
21379
|
+
} catch (e) {
|
|
21380
|
+
if (isTimeout(e))
|
|
21381
|
+
throw jobReadTimedOutError(jobId, waitSeconds);
|
|
21382
|
+
throw e;
|
|
21383
|
+
}
|
|
21384
|
+
while (!TERMINAL_JOB_STATES.has(snap.job.state) && (Date.now() - startedAt) / 1e3 < waitSeconds && !ctx?.signal?.aborted) {
|
|
21385
|
+
const remainingMs = waitSeconds * 1e3 - (Date.now() - startedAt);
|
|
21386
|
+
if (remainingMs <= 0)
|
|
21387
|
+
break;
|
|
21388
|
+
await sleepUnlessAborted(Math.min(MCP_JOB_POLL.intervalMs, remainingMs), ctx?.signal);
|
|
21389
|
+
if (ctx?.signal?.aborted)
|
|
21390
|
+
break;
|
|
21391
|
+
if (remainingMsOf() <= 0)
|
|
21392
|
+
break;
|
|
21393
|
+
try {
|
|
21394
|
+
const fresh = await collectJobSnapshot(client, jobId, since, limit, ctx?.signal, snapshotBudget(remainingMsOf()));
|
|
21395
|
+
const regressed = fresh.items.length < snap.items.length;
|
|
21396
|
+
snap = regressed ? {
|
|
21397
|
+
...fresh,
|
|
21398
|
+
items: snap.items,
|
|
21399
|
+
next_since: snap.next_since ?? fresh.next_since,
|
|
21400
|
+
...snap.items_truncated ? { items_truncated: true } : {}
|
|
21401
|
+
} : fresh;
|
|
21402
|
+
} catch (e) {
|
|
21403
|
+
if (ctx?.signal?.aborted)
|
|
21404
|
+
break;
|
|
21405
|
+
if (isTimeout(e))
|
|
21406
|
+
break;
|
|
21407
|
+
throw e;
|
|
21408
|
+
}
|
|
21409
|
+
const f = snap.funnel;
|
|
21410
|
+
ctx?.progress?.({
|
|
21411
|
+
progress: f.delivered ?? 0,
|
|
21412
|
+
total: itemsRequested,
|
|
21413
|
+
message: `${snap.job.state}: ${f.examined ?? 0} examined, ${f.delivered ?? 0} delivered, ${snap.cost.spent}c spent`
|
|
21414
|
+
});
|
|
21415
|
+
}
|
|
21416
|
+
return snap;
|
|
21417
|
+
}
|
|
21418
|
+
function refIdentity(ref) {
|
|
21419
|
+
if (!ref || typeof ref !== "object" || Array.isArray(ref))
|
|
21420
|
+
return null;
|
|
21421
|
+
const o = ref;
|
|
21422
|
+
const str = (f) => {
|
|
21423
|
+
const v = o[f];
|
|
21424
|
+
if (typeof v !== "string")
|
|
21425
|
+
return null;
|
|
21426
|
+
const t = v.trim().toLowerCase();
|
|
21427
|
+
return t ? t : null;
|
|
21428
|
+
};
|
|
21429
|
+
const website = str("website");
|
|
21430
|
+
const parts = [
|
|
21431
|
+
normalizeUuid(o.lead_id) ?? null,
|
|
21432
|
+
normalizeUuid(o.contact_id) ?? null,
|
|
21433
|
+
website ? normalizeDomain(website) ?? website : null,
|
|
21434
|
+
str("name"),
|
|
21435
|
+
str("location")
|
|
21436
|
+
];
|
|
21437
|
+
return parts.some((p) => p !== null) ? JSON.stringify(parts) : null;
|
|
21438
|
+
}
|
|
21439
|
+
function remapInputIndexes(items, refs) {
|
|
21440
|
+
const list = Array.isArray(refs) ? refs : [];
|
|
21441
|
+
if (list.length === 0)
|
|
21442
|
+
return { items, remapped: false };
|
|
21443
|
+
const byIdentity = /* @__PURE__ */ new Map();
|
|
21444
|
+
list.forEach((ref, i) => {
|
|
21445
|
+
const key = refIdentity(ref);
|
|
21446
|
+
if (!key)
|
|
21447
|
+
return;
|
|
21448
|
+
const at = byIdentity.get(key);
|
|
21449
|
+
if (at)
|
|
21450
|
+
at.push(i);
|
|
21451
|
+
else
|
|
21452
|
+
byIdentity.set(key, [i]);
|
|
21453
|
+
});
|
|
21454
|
+
const next = [];
|
|
21455
|
+
let ok = true;
|
|
21456
|
+
for (const item of items) {
|
|
21457
|
+
const ref = item.ref;
|
|
21458
|
+
if (!ref || ref.input_indexes == null) {
|
|
21459
|
+
next.push(item);
|
|
21460
|
+
continue;
|
|
21461
|
+
}
|
|
21462
|
+
const key = refIdentity(ref.requested_as) ?? refIdentity({ lead_id: ref.lead_id ?? void 0 });
|
|
21463
|
+
const found = key ? byIdentity.get(key) : void 0;
|
|
21464
|
+
if (!found) {
|
|
21465
|
+
ok = false;
|
|
21466
|
+
break;
|
|
21467
|
+
}
|
|
21468
|
+
next.push({ ...item, ref: { ...ref, input_indexes: found } });
|
|
21469
|
+
}
|
|
21470
|
+
if (!ok) {
|
|
21471
|
+
return {
|
|
21472
|
+
items: items.map((item) => item.ref && item.ref.input_indexes != null ? { ...item, ref: { ...item.ref, input_indexes: null } } : item),
|
|
21473
|
+
remapped: false
|
|
21474
|
+
};
|
|
21475
|
+
}
|
|
21476
|
+
return { items: next, remapped: true };
|
|
21477
|
+
}
|
|
21478
|
+
function canonicalSet(values) {
|
|
21479
|
+
const list = values === void 0 || values === null ? [] : Array.isArray(values) ? values : [values];
|
|
21480
|
+
return [...new Set(list.map((v) => JSON.stringify(v)))].sort().map((v) => JSON.parse(v));
|
|
21481
|
+
}
|
|
21482
|
+
function coerceArrayParams(params, keys) {
|
|
21483
|
+
const out = { ...params };
|
|
21484
|
+
for (const key of keys) {
|
|
21485
|
+
const v = out[key];
|
|
21486
|
+
if (v !== void 0 && v !== null && !Array.isArray(v)) {
|
|
21487
|
+
out[key] = [v];
|
|
21488
|
+
}
|
|
21489
|
+
}
|
|
21490
|
+
return out;
|
|
21491
|
+
}
|
|
21492
|
+
function presentRequestId(value) {
|
|
21493
|
+
if (typeof value !== "string")
|
|
21494
|
+
return void 0;
|
|
21495
|
+
const trimmed = value.trim();
|
|
21496
|
+
return trimmed ? trimmed : void 0;
|
|
21497
|
+
}
|
|
21498
|
+
function isUuidShaped(value) {
|
|
21499
|
+
return typeof value === "string" && UUID_RE2.test(value.trim());
|
|
21500
|
+
}
|
|
21501
|
+
function normalizeUuid(value) {
|
|
21502
|
+
if (typeof value !== "string")
|
|
21503
|
+
return null;
|
|
21504
|
+
const v = value.trim();
|
|
21505
|
+
if (!v)
|
|
21506
|
+
return null;
|
|
21507
|
+
return UUID_RE2.test(v) ? v.toLowerCase() : v;
|
|
21508
|
+
}
|
|
21509
|
+
function canonicalIdSet(values) {
|
|
21510
|
+
const list = values === void 0 || values === null ? [] : Array.isArray(values) ? values : [values];
|
|
21511
|
+
return canonicalSet(list.map(normalizeUuid).filter((v) => !!v));
|
|
21512
|
+
}
|
|
21513
|
+
function canonicalLabelSet(values) {
|
|
21514
|
+
const list = values === void 0 || values === null ? [] : Array.isArray(values) ? values : [values];
|
|
21515
|
+
return canonicalSet(list.filter((v) => typeof v === "string").map((v) => v.trim().toLowerCase()).filter(Boolean));
|
|
21516
|
+
}
|
|
21517
|
+
function canonicalOptionalObject(value) {
|
|
21518
|
+
if (!value)
|
|
21519
|
+
return null;
|
|
21520
|
+
const out = {};
|
|
21521
|
+
for (const [k, v] of Object.entries(value)) {
|
|
21522
|
+
if (v === void 0 || v === null)
|
|
21523
|
+
continue;
|
|
21524
|
+
if (Array.isArray(v) && v.length === 0)
|
|
21525
|
+
continue;
|
|
21526
|
+
out[k] = v;
|
|
21527
|
+
}
|
|
21528
|
+
return Object.keys(out).length === 0 ? null : out;
|
|
21529
|
+
}
|
|
21530
|
+
function canonicalize(value) {
|
|
21531
|
+
if (Array.isArray(value))
|
|
21532
|
+
return value.map(canonicalize);
|
|
21533
|
+
if (value && typeof value === "object") {
|
|
21534
|
+
const out = {};
|
|
21535
|
+
for (const k of Object.keys(value).sort()) {
|
|
21536
|
+
out[k] = canonicalize(value[k]);
|
|
21537
|
+
}
|
|
21538
|
+
return out;
|
|
21539
|
+
}
|
|
21540
|
+
return value;
|
|
21541
|
+
}
|
|
21542
|
+
function derivedKey(prefix, shape) {
|
|
21543
|
+
const serialized = typeof shape === "string" ? shape : JSON.stringify(canonicalize(shape));
|
|
21544
|
+
return `${prefix}-${createHash4("sha256").update(serialized).digest("hex").slice(0, 32)}`;
|
|
21545
|
+
}
|
|
21546
|
+
function mockedSubmitPreview(submit, tool, region) {
|
|
21547
|
+
const s = submit ?? {};
|
|
21548
|
+
if (typeof s.job_id === "string" && s.job_id)
|
|
21549
|
+
return null;
|
|
21550
|
+
if (process.env.LEADBAY_MOCK !== "1") {
|
|
21551
|
+
throw {
|
|
21552
|
+
error: true,
|
|
21553
|
+
code: "MALFORMED_SUBMIT_RESPONSE",
|
|
21554
|
+
message: `${tool}: the submit succeeded but the response carried no job_id, so the job cannot be polled.`,
|
|
21555
|
+
hint: "The job may still be running server-side. Do not re-submit blindly \u2014 reuse the same request_id so a retry dedupes instead of double-spending."
|
|
21556
|
+
};
|
|
21557
|
+
}
|
|
21558
|
+
return {
|
|
21559
|
+
mocked: true,
|
|
21560
|
+
tool,
|
|
21561
|
+
submitted: false,
|
|
21562
|
+
would_call: s.would_call ?? null,
|
|
21563
|
+
note: "LEADBAY_MOCK=1 \u2014 the job was not submitted, so there is no job to poll.",
|
|
21564
|
+
region
|
|
21565
|
+
};
|
|
21566
|
+
}
|
|
21567
|
+
function splitItems(snapshot) {
|
|
21568
|
+
const leads = [];
|
|
21569
|
+
const skipped = [];
|
|
21570
|
+
for (const item of snapshot.items) {
|
|
21571
|
+
if (item.status === "skipped")
|
|
21572
|
+
skipped.push(item);
|
|
21573
|
+
else
|
|
21574
|
+
leads.push(item);
|
|
21575
|
+
}
|
|
21576
|
+
return { leads, skipped };
|
|
21577
|
+
}
|
|
21578
|
+
function compactBody(body) {
|
|
21579
|
+
return Object.fromEntries(Object.entries(body).filter(([, v]) => v !== void 0));
|
|
21580
|
+
}
|
|
21581
|
+
function exemptionsFor(region) {
|
|
21582
|
+
const key = typeof region === "string" ? region.trim().toLowerCase() : "";
|
|
21583
|
+
return SUBNATIONAL_EXEMPTIONS[key] ?? ALL_EXEMPTIONS;
|
|
21584
|
+
}
|
|
21585
|
+
function buildCountryLocationValues() {
|
|
21586
|
+
const values = new Set(COUNTRY_ALIASES.map(countryKey2));
|
|
21587
|
+
try {
|
|
21588
|
+
const A = "A".charCodeAt(0);
|
|
21589
|
+
const displays = ["en", "fr"].map((locale) => new Intl.DisplayNames([locale], { type: "region", fallback: "none" }));
|
|
21590
|
+
for (let i = 0; i < 26; i++) {
|
|
21591
|
+
for (let j = 0; j < 26; j++) {
|
|
21592
|
+
const code = String.fromCharCode(A + i) + String.fromCharCode(A + j);
|
|
21593
|
+
for (const display of displays) {
|
|
21594
|
+
const name = display.of(code);
|
|
21595
|
+
if (!name || name === code)
|
|
21596
|
+
continue;
|
|
21597
|
+
values.add(countryKey2(name));
|
|
21598
|
+
}
|
|
21599
|
+
}
|
|
21600
|
+
}
|
|
21601
|
+
} catch {
|
|
21602
|
+
}
|
|
21603
|
+
return values;
|
|
21604
|
+
}
|
|
21605
|
+
function countryKey2(raw) {
|
|
21606
|
+
return raw.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[-_,]/g, " ").replace(/^\s*(l|d)['’]\s*/, "").replace(/['’.]/g, "").replace(/\s+/g, " ").trim().replace(/^(les|the|la|le|l)\s+/, "").trim();
|
|
21607
|
+
}
|
|
21608
|
+
function rejectMalformedExclusions(ids) {
|
|
21609
|
+
if (ids === void 0 || ids === null)
|
|
21610
|
+
return;
|
|
21611
|
+
const list = Array.isArray(ids) ? ids : [ids];
|
|
21612
|
+
const bad = [];
|
|
21613
|
+
list.forEach((v, i) => {
|
|
21614
|
+
if (typeof v !== "string") {
|
|
21615
|
+
bad.push(`${i} (${v === null ? "null" : typeof v})`);
|
|
21616
|
+
} else if (!v.trim()) {
|
|
21617
|
+
bad.push(`${i} (blank)`);
|
|
21618
|
+
}
|
|
21619
|
+
});
|
|
21620
|
+
if (bad.length === 0)
|
|
21621
|
+
return;
|
|
21622
|
+
throw {
|
|
21623
|
+
error: true,
|
|
21624
|
+
code: "INVALID_EXCLUDE_LEAD_ID",
|
|
21625
|
+
message: `exclude_lead_ids has ${bad.length} entr${bad.length === 1 ? "y" : "ies"} that is not a lead id: ${bad.join(", ")}.`,
|
|
21626
|
+
hint: "Drop or fix those entries and re-call \u2014 every entry must be a non-blank lead id string. Silently skipping them would run the search without an exclusion you asked for, and could re-deliver and charge for that exact lead."
|
|
21627
|
+
};
|
|
21628
|
+
}
|
|
21629
|
+
function rejectOversizedExclusions(ids) {
|
|
21630
|
+
if (ids === void 0 || ids === null)
|
|
21631
|
+
return;
|
|
21632
|
+
const unique = canonicalIdSet(ids);
|
|
21633
|
+
if (unique.length <= MAX_EXCLUDE_LEAD_IDS)
|
|
21634
|
+
return;
|
|
21635
|
+
throw {
|
|
21636
|
+
error: true,
|
|
21637
|
+
code: "TOO_MANY_EXCLUSIONS",
|
|
21638
|
+
message: `exclude_lead_ids carries ${unique.length} ids \u2014 the maximum is ${MAX_EXCLUDE_LEAD_IDS}.`,
|
|
21639
|
+
hint: "Drop the DELIVERED ids first: novelty:'org' already excludes those. Send the examined-but-rejected ones (disqualified + skipped), most recent first, capped at 500."
|
|
21640
|
+
};
|
|
21641
|
+
}
|
|
21642
|
+
function rejectOversizedLeadRefs(refs) {
|
|
21643
|
+
if (refs === void 0 || refs === null)
|
|
21644
|
+
return;
|
|
21645
|
+
const list = Array.isArray(refs) ? refs : [refs];
|
|
21646
|
+
const unique = /* @__PURE__ */ new Set();
|
|
21647
|
+
let unkeyed = 0;
|
|
21648
|
+
for (const ref of list) {
|
|
21649
|
+
const key = refIdentity(ref);
|
|
21650
|
+
if (key === null)
|
|
21651
|
+
unkeyed += 1;
|
|
21652
|
+
else
|
|
21653
|
+
unique.add(key);
|
|
21654
|
+
}
|
|
21655
|
+
const count = unique.size + unkeyed;
|
|
21656
|
+
if (count <= MAX_LEAD_REFS)
|
|
21657
|
+
return;
|
|
21658
|
+
throw {
|
|
21659
|
+
error: true,
|
|
21660
|
+
code: "TOO_MANY_LEAD_REFS",
|
|
21661
|
+
message: `lead_refs carries ${count} companies \u2014 the maximum is ${MAX_LEAD_REFS}.`,
|
|
21662
|
+
hint: `Split the batch into runs of ${MAX_LEAD_REFS} or fewer and call leadbay_qualify_leads once per run, each with its OWN request_id. Results accumulate in the org ledger, so a later run can re-read the earlier ones via prior_deliveries.`
|
|
21663
|
+
};
|
|
21664
|
+
}
|
|
21665
|
+
function readSpendFlag(value, field) {
|
|
21666
|
+
if (value === void 0 || value === null)
|
|
21667
|
+
return void 0;
|
|
21668
|
+
if (typeof value === "boolean")
|
|
21669
|
+
return value;
|
|
21670
|
+
if (typeof value === "string") {
|
|
21671
|
+
const t = value.trim().toLowerCase();
|
|
21672
|
+
if (t === "true")
|
|
21673
|
+
return true;
|
|
21674
|
+
if (t === "false")
|
|
21675
|
+
return false;
|
|
21676
|
+
}
|
|
21677
|
+
throw {
|
|
21678
|
+
error: true,
|
|
21679
|
+
code: "BAD_INPUT",
|
|
21680
|
+
message: `${field} must be a boolean (got ${Array.isArray(value) ? "array" : typeof value}: ${JSON.stringify(value)}).`,
|
|
21681
|
+
hint: `Re-call the tool with ${field}: true or ${field}: false as a JSON boolean, not a string or a number. This flag decides whether the user is charged, so an unrecognised value is refused rather than guessed.`
|
|
21682
|
+
};
|
|
21683
|
+
}
|
|
21684
|
+
function rejectCountryLocations(locations, region) {
|
|
21685
|
+
if (locations === void 0 || locations === null)
|
|
21686
|
+
return;
|
|
21687
|
+
const exempt = exemptionsFor(region);
|
|
21688
|
+
const list = Array.isArray(locations) ? locations : [locations];
|
|
21689
|
+
for (const loc of list) {
|
|
21690
|
+
if (typeof loc !== "string")
|
|
21691
|
+
continue;
|
|
21692
|
+
const key = countryKey2(loc);
|
|
21693
|
+
if (!exempt.has(key) && COUNTRY_LOCATION_VALUES.has(key)) {
|
|
21694
|
+
throw {
|
|
21695
|
+
error: true,
|
|
21696
|
+
code: "COUNTRY_LEVEL_LOCATION",
|
|
21697
|
+
message: `filters.locations value "${loc}" is country-level \u2014 it would silently fence the search to a same-named town, not the whole country.`,
|
|
21698
|
+
hint: 'Whole-country intent = OMIT filters.locations entirely (each universe is single-country). Use city/state/region names for narrower fences. If you meant a town that shares the name, qualify it with its state or region (e.g. "Lebanon, Kentucky").'
|
|
21699
|
+
};
|
|
21700
|
+
}
|
|
21701
|
+
}
|
|
21702
|
+
}
|
|
21703
|
+
function normalizeSearchFilters(filters) {
|
|
21704
|
+
if (filters == null)
|
|
21705
|
+
return void 0;
|
|
21706
|
+
const { employees, employeesMin, employeesMax, ...rest } = filters;
|
|
21707
|
+
const out = { ...rest };
|
|
21708
|
+
if (out.employees_min == null) {
|
|
21709
|
+
out.employees_min = employees?.min ?? employees?.employees_min ?? employeesMin;
|
|
21710
|
+
}
|
|
21711
|
+
if (out.employees_max == null) {
|
|
21712
|
+
out.employees_max = employees?.max ?? employees?.employees_max ?? employeesMax;
|
|
21713
|
+
}
|
|
21714
|
+
if (out.employees_min == null)
|
|
21715
|
+
delete out.employees_min;
|
|
21716
|
+
if (out.employees_max == null)
|
|
21717
|
+
delete out.employees_max;
|
|
21718
|
+
for (const key of ["sectors", "locations"]) {
|
|
21719
|
+
const v = out[key];
|
|
21720
|
+
if (typeof v === "string")
|
|
21721
|
+
out[key] = v.trim() ? [v] : void 0;
|
|
21722
|
+
if (out[key] === void 0)
|
|
21723
|
+
delete out[key];
|
|
21724
|
+
}
|
|
21725
|
+
return out;
|
|
21726
|
+
}
|
|
21727
|
+
function clampWaitSeconds(requested, fallback) {
|
|
21728
|
+
if (requested == null || Number.isNaN(requested))
|
|
21729
|
+
return fallback;
|
|
21730
|
+
return Math.min(Math.max(requested, 0), 180);
|
|
21731
|
+
}
|
|
21732
|
+
var TERMINAL_JOB_STATES, MCP_JOB_POLL, SNAPSHOT_TIMEOUT_MS, PAGE_LIMIT, MAX_JOB_ITEMS, MIN_PAGES, maxPagesFor, JOB_ID_CHARSET, MAX_JOB_ID_LENGTH, UUID_RE2, COUNTRY_ALIASES, SUBNATIONAL_EXEMPTIONS, ALL_EXEMPTIONS, COUNTRY_LOCATION_VALUES, MAX_EXCLUDE_LEAD_IDS, MAX_LEAD_REFS;
|
|
21733
|
+
var init_mcp_job_helpers = __esm({
|
|
21734
|
+
"../core/dist/composite/_mcp-job-helpers.js"() {
|
|
21735
|
+
"use strict";
|
|
21736
|
+
init_import_leads();
|
|
21737
|
+
TERMINAL_JOB_STATES = /* @__PURE__ */ new Set([
|
|
21738
|
+
"completed",
|
|
21739
|
+
"completed_partial",
|
|
21740
|
+
"failed",
|
|
21741
|
+
"expired"
|
|
21742
|
+
]);
|
|
21743
|
+
MCP_JOB_POLL = { intervalMs: 4e3 };
|
|
21744
|
+
SNAPSHOT_TIMEOUT_MS = 3e4;
|
|
21745
|
+
PAGE_LIMIT = 100;
|
|
21746
|
+
MAX_JOB_ITEMS = 1e3;
|
|
21747
|
+
MIN_PAGES = 20;
|
|
21748
|
+
maxPagesFor = (pageLimit) => Math.max(MIN_PAGES, Math.ceil(MAX_JOB_ITEMS / pageLimit) + 1);
|
|
21749
|
+
JOB_ID_CHARSET = /^[A-Za-z0-9._~-]+$/;
|
|
21750
|
+
MAX_JOB_ID_LENGTH = 200;
|
|
21751
|
+
UUID_RE2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
21752
|
+
COUNTRY_ALIASES = [
|
|
21753
|
+
"united states",
|
|
21754
|
+
"united states of america",
|
|
21755
|
+
"usa",
|
|
21756
|
+
"us",
|
|
21757
|
+
"america",
|
|
21758
|
+
"etats unis",
|
|
21759
|
+
"etats unis d amerique",
|
|
21760
|
+
"france",
|
|
21761
|
+
"fr",
|
|
21762
|
+
"french republic",
|
|
21763
|
+
"republique francaise"
|
|
21764
|
+
];
|
|
21765
|
+
SUBNATIONAL_EXEMPTIONS = {
|
|
21766
|
+
us: new Set(["georgia", "georgie"].map(countryKey2)),
|
|
21767
|
+
fr: new Set([
|
|
21768
|
+
"guadeloupe",
|
|
21769
|
+
"martinique",
|
|
21770
|
+
"reunion",
|
|
21771
|
+
"mayotte",
|
|
21772
|
+
"french guiana",
|
|
21773
|
+
"guyane francaise",
|
|
21774
|
+
"new caledonia",
|
|
21775
|
+
"nouvelle caledonie",
|
|
21776
|
+
"french polynesia",
|
|
21777
|
+
"polynesie francaise",
|
|
21778
|
+
"saint martin",
|
|
21779
|
+
"saint barthelemy",
|
|
21780
|
+
"saint pierre and miquelon",
|
|
21781
|
+
"saint pierre et miquelon",
|
|
21782
|
+
"wallis and futuna",
|
|
21783
|
+
"wallis et futuna"
|
|
21784
|
+
].map(countryKey2))
|
|
21785
|
+
};
|
|
21786
|
+
ALL_EXEMPTIONS = new Set(Object.values(SUBNATIONAL_EXEMPTIONS).flatMap((s) => [...s]));
|
|
21787
|
+
COUNTRY_LOCATION_VALUES = buildCountryLocationValues();
|
|
21788
|
+
MAX_EXCLUDE_LEAD_IDS = 500;
|
|
21789
|
+
MAX_LEAD_REFS = 500;
|
|
21790
|
+
}
|
|
21791
|
+
});
|
|
21792
|
+
|
|
21793
|
+
// ../core/dist/composite/find-new-leads.js
|
|
21794
|
+
function sortFilterLists(filters) {
|
|
21795
|
+
if (!filters)
|
|
21796
|
+
return null;
|
|
21797
|
+
const out = { ...filters };
|
|
21798
|
+
for (const key of ["sectors", "locations"]) {
|
|
21799
|
+
if (Array.isArray(out[key])) {
|
|
21800
|
+
out[key] = canonicalLabelSet(out[key]);
|
|
21801
|
+
}
|
|
21802
|
+
}
|
|
21803
|
+
return out;
|
|
21804
|
+
}
|
|
21805
|
+
var DEFAULT_WAIT_SECONDS, findNewLeads;
|
|
21806
|
+
var init_find_new_leads = __esm({
|
|
21807
|
+
"../core/dist/composite/find-new-leads.js"() {
|
|
21808
|
+
"use strict";
|
|
21809
|
+
init_mcp_job_helpers();
|
|
21810
|
+
init_tool_descriptions_generated();
|
|
21811
|
+
DEFAULT_WAIT_SECONDS = 45;
|
|
21812
|
+
findNewLeads = {
|
|
21813
|
+
name: "leadbay_find_new_leads",
|
|
21814
|
+
annotations: {
|
|
21815
|
+
title: "Find new leads (net-new ICP search)",
|
|
21816
|
+
readOnlyHint: false,
|
|
21817
|
+
// The tool CAN bill (qualify:true and/or channels) and records deliveries
|
|
21818
|
+
// in the org novelty ledger, so it advertises destructive like the other
|
|
21819
|
+
// paid composites — annotations are static and must describe the worst
|
|
21820
|
+
// case, not the default. The free path is protected in execute() instead:
|
|
21821
|
+
// a paid call is withheld until `confirm: true`.
|
|
21822
|
+
destructiveHint: true,
|
|
21823
|
+
// The mandatory request_id dedups: re-submitting the same request returns
|
|
21824
|
+
// the SAME live job instead of double-spending.
|
|
21825
|
+
idempotentHint: true,
|
|
21826
|
+
openWorldHint: true
|
|
21827
|
+
},
|
|
21828
|
+
write: true,
|
|
21829
|
+
description: leadbay_find_new_leads,
|
|
21830
|
+
inputSchema: {
|
|
21831
|
+
type: "object",
|
|
21832
|
+
properties: {
|
|
21833
|
+
query: {
|
|
21834
|
+
type: "string",
|
|
21835
|
+
description: "Natural-language ICP ask. Matches topic VOCABULARY \u2014 can surface vendors of a product as easily as buyers of it. Prefer example_lead; use query only when the user's wording carries signal an example can't."
|
|
21836
|
+
},
|
|
21837
|
+
example_lead: {
|
|
21838
|
+
type: "object",
|
|
21839
|
+
description: "A FICTIONAL typical ideal customer used as a look-alike seed \u2014 the highest-leverage input. Put everything in `description` (registry 'About Us' style, what the company IS); leave `name` unset (a distinctive invented name pulls matches toward name-lookalikes).",
|
|
21840
|
+
properties: {
|
|
21841
|
+
name: { type: "string" },
|
|
21842
|
+
description: { type: "string" },
|
|
21843
|
+
location: { type: "string" },
|
|
21844
|
+
employees: { type: "number" }
|
|
21845
|
+
},
|
|
21846
|
+
additionalProperties: false
|
|
21847
|
+
},
|
|
21848
|
+
filters: {
|
|
21849
|
+
type: "object",
|
|
21850
|
+
description: "HARD constraints (the seed only shapes ranking). Sector/location labels resolve at submit; an unresolvable value is a 400 naming it.",
|
|
21851
|
+
properties: {
|
|
21852
|
+
sectors: { type: "array", items: { type: "string" } },
|
|
21853
|
+
locations: { type: "array", items: { type: "string" } },
|
|
21854
|
+
employees_min: { type: "number" },
|
|
21855
|
+
employees_max: { type: "number" }
|
|
21856
|
+
},
|
|
21857
|
+
additionalProperties: false
|
|
21858
|
+
},
|
|
21859
|
+
count: {
|
|
21860
|
+
type: "number",
|
|
21861
|
+
description: "Target DELIVERED leads, 1-50. With qualify:true this means n SURVIVORS of qualification, not n candidates examined."
|
|
21862
|
+
},
|
|
21863
|
+
qualify: {
|
|
21864
|
+
type: "boolean",
|
|
21865
|
+
description: "Run fresh AI qualification and drop candidates scoring below min_ai_score. PAID: ~94 cost_cents per candidate EXAMINED (survivor or not). Default false (free)."
|
|
21866
|
+
},
|
|
21867
|
+
min_ai_score: {
|
|
21868
|
+
type: "number",
|
|
21869
|
+
description: "Disqualification floor on the [-30,+30] qualification DELTA (not the 0-100 fit score). Default 0. Lower to -30 to keep every evaluated lead with its evidence."
|
|
21870
|
+
},
|
|
21871
|
+
contact_titles: {
|
|
21872
|
+
type: "array",
|
|
21873
|
+
items: { type: "string" },
|
|
21874
|
+
description: "Wanted decision-maker titles (max 10), matched semantically cross-language."
|
|
21875
|
+
},
|
|
21876
|
+
title_gate: {
|
|
21877
|
+
type: "string",
|
|
21878
|
+
enum: ["strict", "prefer"],
|
|
21879
|
+
description: "strict = only leads with a matching known contact; prefer (default when contact_titles set) = matched first, rest flagged."
|
|
21880
|
+
},
|
|
21881
|
+
channels: {
|
|
21882
|
+
type: "array",
|
|
21883
|
+
items: { type: "string", enum: ["email", "phone"] },
|
|
21884
|
+
description: "Contact channels to PURCHASE (email 25c, phone 250c, billed on success only). Empty = free identity tier."
|
|
21885
|
+
},
|
|
21886
|
+
exclude_lead_ids: {
|
|
21887
|
+
type: "array",
|
|
21888
|
+
items: { type: "string" },
|
|
21889
|
+
description: "Caller-side novelty belt on top of the server-side one (max 500 ids \u2014 over that the call is refused, so drop the DELIVERED ids first: novelty:'org' already covers those, and the examined-but-rejected ones are what it misses)."
|
|
21890
|
+
},
|
|
21891
|
+
novelty: {
|
|
21892
|
+
type: "string",
|
|
21893
|
+
enum: ["org", "none"],
|
|
21894
|
+
description: "org (default) = only companies NEW to the org (excludes org leads, lens members, CRM ids, prior MCP deliveries)."
|
|
21895
|
+
},
|
|
21896
|
+
max_cost: {
|
|
21897
|
+
type: "number",
|
|
21898
|
+
description: "Spend cap for the whole job in cost_cents. Defaults by plan tier (500/2000/5000). The job stops honestly at the cap (stop_reason max_cost)."
|
|
21899
|
+
},
|
|
21900
|
+
exploration_cap: {
|
|
21901
|
+
type: "number",
|
|
21902
|
+
description: "Max candidates the qualify gate may examine. Default min(3n,150), ceiling min(20n,1000)."
|
|
21903
|
+
},
|
|
21904
|
+
request_id: {
|
|
21905
|
+
type: "string",
|
|
21906
|
+
description: "REQUIRED idempotency key. Derive it from the ask (e.g. 'gyms-texas-2026-07-28'); REUSE the exact same value when retrying the same ask \u2014 a duplicate returns the SAME job instead of double-spending. Use a NEW value only for a genuinely new ask."
|
|
21907
|
+
},
|
|
21908
|
+
lang: { type: "string", description: "Output language (default: user's language)." },
|
|
21909
|
+
confirm: {
|
|
21910
|
+
type: "boolean",
|
|
21911
|
+
description: "Explicit spend decision, required only for a PAID search (qualify:true and/or channels). true = the user approved the quote, go ahead. false = a veto (returns mode:'needs_confirmation', spends nothing). Omitted on a paid call \u2192 the tool withholds the submit and returns a free quote to show the user first. The default FREE search (no qualify, no channels) needs no confirm."
|
|
21912
|
+
},
|
|
21913
|
+
dry_run: {
|
|
21914
|
+
type: "boolean",
|
|
21915
|
+
description: "Validate + worst-case cost estimate + quota forecast. No job, no spend. Use before the first PAID run of a session."
|
|
21916
|
+
},
|
|
21917
|
+
wait_seconds: {
|
|
21918
|
+
type: "number",
|
|
21919
|
+
description: "How long to poll before returning (default 45, max 180, 0 = submit + one snapshot). Free searches usually finish inside the window; paid exploration can take minutes \u2014 the result then carries still_running:true and the job_id to check with leadbay_lead_job_status."
|
|
21920
|
+
}
|
|
21921
|
+
},
|
|
21922
|
+
required: ["count", "request_id"],
|
|
21923
|
+
additionalProperties: false
|
|
21924
|
+
},
|
|
21925
|
+
execute: async (client, params, ctx) => {
|
|
21926
|
+
params = coerceArrayParams(params, [
|
|
21927
|
+
"contact_titles",
|
|
21928
|
+
"channels",
|
|
21929
|
+
"exclude_lead_ids"
|
|
21930
|
+
]);
|
|
21931
|
+
rejectCountryLocations(params.filters?.locations, client.region);
|
|
21932
|
+
rejectMalformedExclusions(params.exclude_lead_ids);
|
|
21933
|
+
rejectOversizedExclusions(params.exclude_lead_ids);
|
|
21934
|
+
const qualify = readSpendFlag(params.qualify, "qualify");
|
|
21935
|
+
const dryRun = readSpendFlag(params.dry_run, "dry_run");
|
|
21936
|
+
const confirm = readSpendFlag(params.confirm, "confirm");
|
|
21937
|
+
params = { ...params, qualify, dry_run: dryRun, confirm };
|
|
21938
|
+
const buysChannels = (params.channels?.length ?? 0) > 0;
|
|
21939
|
+
const buysQualification = qualify === true;
|
|
21940
|
+
const isPaid = buysQualification || buysChannels;
|
|
21941
|
+
const vetoed = confirm === false;
|
|
21942
|
+
const consented = !vetoed && confirm === true;
|
|
21943
|
+
const requestId = presentRequestId(params.request_id) ?? derivedKey(
|
|
21944
|
+
"search-auto",
|
|
21945
|
+
// Passed as an OBJECT: derivedKey canonicalizes recursively, so nested
|
|
21946
|
+
// property order (example_lead, filters) can never fork the key. Fields
|
|
21947
|
+
// with a documented backend default are canonicalized TO that default,
|
|
21948
|
+
// so an approval that omits one and a retry that passes it explicitly
|
|
21949
|
+
// derive the same key rather than launching a second paid,
|
|
21950
|
+
// novelty-claiming job.
|
|
21951
|
+
{
|
|
21952
|
+
query: params.query ?? null,
|
|
21953
|
+
example_lead: params.example_lead ?? null,
|
|
21954
|
+
// Sector/location lists are unordered sets to the backend — sort
|
|
21955
|
+
// them so a reordered retry still dedupes.
|
|
21956
|
+
filters: canonicalOptionalObject(sortFilterLists(normalizeSearchFilters(params.filters))),
|
|
21957
|
+
count: params.count ?? null,
|
|
21958
|
+
qualify: params.qualify === true,
|
|
21959
|
+
min_ai_score: params.min_ai_score ?? 0,
|
|
21960
|
+
contact_titles: canonicalLabelSet(params.contact_titles),
|
|
21961
|
+
title_gate: params.title_gate ?? ((params.contact_titles?.length ?? 0) > 0 ? "prefer" : null),
|
|
21962
|
+
channels: canonicalSet(params.channels),
|
|
21963
|
+
// Sorted so ordering alone never forks the key, but PRESENT — a
|
|
21964
|
+
// top-up differing only by exclude_lead_ids is a different approved
|
|
21965
|
+
// search, and hashing it the same would return the first job as a
|
|
21966
|
+
// duplicate with the exclusions never applied.
|
|
21967
|
+
exclude_lead_ids: canonicalIdSet(params.exclude_lead_ids),
|
|
21968
|
+
novelty: params.novelty ?? "org",
|
|
21969
|
+
max_cost: params.max_cost ?? null,
|
|
21970
|
+
// Documented backend default is min(3n,150), so an omitted cap is
|
|
21971
|
+
// canonicalized TO it — same principle as min_ai_score/novelty above.
|
|
21972
|
+
// Otherwise an approval that omits the cap and a retry that passes the
|
|
21973
|
+
// materialized default ask for identical work under different keys,
|
|
21974
|
+
// and the retry escapes dedupe into a second paid, novelty-claiming
|
|
21975
|
+
// job. An explicit non-default cap still hashes distinctly.
|
|
21976
|
+
exploration_cap: params.exploration_cap ?? (typeof params.count === "number" && params.count > 0 ? Math.min(3 * params.count, 150) : null),
|
|
21977
|
+
lang: params.lang ?? null
|
|
21978
|
+
}
|
|
21979
|
+
);
|
|
21980
|
+
const body = compactBody({
|
|
21981
|
+
query: params.query,
|
|
21982
|
+
example_lead: params.example_lead,
|
|
21983
|
+
filters: normalizeSearchFilters(params.filters),
|
|
21984
|
+
count: params.count,
|
|
21985
|
+
qualify,
|
|
21986
|
+
min_ai_score: params.min_ai_score,
|
|
21987
|
+
contact_titles: params.contact_titles,
|
|
21988
|
+
title_gate: params.title_gate,
|
|
21989
|
+
channels: params.channels,
|
|
21990
|
+
// Wire the SAME list the cap guard counted and the idempotency key was
|
|
21991
|
+
// derived from. Posting the raw array instead let a 600-entry list that
|
|
21992
|
+
// dedupes to 400 clear the guard and still be refused by the backend.
|
|
21993
|
+
// Kept undefined when absent so compactBody drops it rather than
|
|
21994
|
+
// sending an empty array.
|
|
21995
|
+
exclude_lead_ids: params.exclude_lead_ids ? canonicalIdSet(params.exclude_lead_ids) : void 0,
|
|
21996
|
+
novelty: params.novelty,
|
|
21997
|
+
max_cost: params.max_cost,
|
|
21998
|
+
exploration_cap: params.exploration_cap,
|
|
21999
|
+
request_id: requestId,
|
|
22000
|
+
lang: params.lang,
|
|
22001
|
+
dry_run: dryRun
|
|
22002
|
+
});
|
|
22003
|
+
if (dryRun === true) {
|
|
22004
|
+
const forecast = await client.request("POST", "/mcp/search", body);
|
|
22005
|
+
return {
|
|
22006
|
+
dry_run: true,
|
|
22007
|
+
...forecast,
|
|
22008
|
+
region: client.region
|
|
22009
|
+
};
|
|
22010
|
+
}
|
|
22011
|
+
if (isPaid && !consented) {
|
|
22012
|
+
const forecast = vetoed ? null : await client.request("POST", "/mcp/search", {
|
|
22013
|
+
...body,
|
|
22014
|
+
dry_run: true
|
|
22015
|
+
});
|
|
22016
|
+
return {
|
|
22017
|
+
mode: "needs_confirmation",
|
|
22018
|
+
submitted: false,
|
|
22019
|
+
vetoed,
|
|
22020
|
+
paid_because: [
|
|
22021
|
+
buysQualification ? "qualify: true (~94 cost_cents per candidate EXAMINED)" : null,
|
|
22022
|
+
buysChannels ? `channels requested: ${params.channels.join(", ")}` : null
|
|
22023
|
+
].filter(Boolean),
|
|
22024
|
+
quote: forecast,
|
|
22025
|
+
estimated_cost: forecast?.estimated_cost ?? null,
|
|
22026
|
+
items_requested: forecast?.items_requested ?? null,
|
|
22027
|
+
hint: vetoed ? "confirm:false vetoed the spend \u2014 nothing was submitted. Re-call with confirm:true to proceed, or drop qualify/channels for a free search." : "Show the user this worst-case quote and get an explicit go-ahead, then re-call with confirm:true. For a free search instead: omit qualify and channels.",
|
|
22028
|
+
region: client.region
|
|
22029
|
+
};
|
|
22030
|
+
}
|
|
22031
|
+
const submit = await client.request("POST", "/mcp/search", body, { preSendSignal: ctx?.signal });
|
|
22032
|
+
const mocked = mockedSubmitPreview(submit, "leadbay_find_new_leads", client.region);
|
|
22033
|
+
if (mocked)
|
|
22034
|
+
return mocked;
|
|
22035
|
+
const waitSeconds = clampWaitSeconds(params.wait_seconds, DEFAULT_WAIT_SECONDS);
|
|
22036
|
+
const snapshot = await snapshotAfterSubmit(client, submit.job_id, waitSeconds, ctx, params.count);
|
|
22037
|
+
const done = TERMINAL_JOB_STATES.has(snapshot.job.state);
|
|
22038
|
+
const { leads, skipped } = splitItems(snapshot);
|
|
22039
|
+
return {
|
|
22040
|
+
job_id: submit.job_id,
|
|
22041
|
+
request_id: requestId,
|
|
22042
|
+
duplicate_submit: submit.duplicate ?? false,
|
|
22043
|
+
state: snapshot.job.state,
|
|
22044
|
+
done,
|
|
22045
|
+
summary: {
|
|
22046
|
+
// Named items_requested (not `requested`) to match qualify_leads and
|
|
22047
|
+
// the shared renderer, which reads summary.items_requested for the
|
|
22048
|
+
// "delivered X of the Y asked" clause.
|
|
22049
|
+
items_requested: submit.items_requested ?? params.count,
|
|
22050
|
+
delivered: snapshot.funnel.delivered ?? 0,
|
|
22051
|
+
delivered_callable: snapshot.funnel.delivered_callable ?? 0,
|
|
22052
|
+
delivered_title_only: snapshot.funnel.delivered_title_only ?? 0,
|
|
22053
|
+
degraded: snapshot.funnel.degraded ?? 0,
|
|
22054
|
+
stop_reason: snapshot.funnel.stop_reason ?? null
|
|
22055
|
+
},
|
|
22056
|
+
funnel: snapshot.funnel,
|
|
22057
|
+
leads,
|
|
22058
|
+
skipped,
|
|
22059
|
+
items_truncated: snapshot.items_truncated ?? false,
|
|
22060
|
+
// Top-level, not only inside next_poll: on a TERMINAL job that truncated,
|
|
22061
|
+
// next_poll used to be null, so the rendering rule telling the agent to
|
|
22062
|
+
// fetch the rest with `since: next_since` named a cursor the response did
|
|
22063
|
+
// not contain. The rows are paid for; the way to reach them cannot be
|
|
22064
|
+
// conditional on the job still running.
|
|
22065
|
+
next_since: snapshot.next_since ?? null,
|
|
22066
|
+
cost: snapshot.cost,
|
|
22067
|
+
estimated_cost: submit.estimated_cost,
|
|
22068
|
+
explain: snapshot.explain,
|
|
22069
|
+
still_running: !done,
|
|
22070
|
+
// A finished job can still owe rows: truncation means the drain stopped
|
|
22071
|
+
// early, so there is a follow-up action even when done is true. It is a
|
|
22072
|
+
// page fetch, not a wait, hence suggested_wait_seconds 0.
|
|
22073
|
+
next_poll: done && !(snapshot.items_truncated ?? false) ? null : {
|
|
22074
|
+
tool: "leadbay_lead_job_status",
|
|
22075
|
+
job_id: submit.job_id,
|
|
22076
|
+
// Hand the cursor forward so the follow-up poll continues
|
|
22077
|
+
// INCREMENTALLY instead of re-reading (and re-rendering) the
|
|
22078
|
+
// rows already delivered in this response.
|
|
22079
|
+
since: snapshot.next_since ?? null,
|
|
22080
|
+
suggested_wait_seconds: done ? 0 : 60
|
|
22081
|
+
},
|
|
22082
|
+
region: client.region
|
|
22083
|
+
};
|
|
22084
|
+
}
|
|
22085
|
+
};
|
|
22086
|
+
}
|
|
22087
|
+
});
|
|
22088
|
+
|
|
22089
|
+
// ../core/dist/composite/qualify-leads.js
|
|
22090
|
+
function normalizeLeadRefs(refs) {
|
|
22091
|
+
if (!Array.isArray(refs))
|
|
22092
|
+
return refs;
|
|
22093
|
+
return refs.map((ref) => {
|
|
22094
|
+
if (typeof ref !== "string")
|
|
22095
|
+
return ref;
|
|
22096
|
+
const value = ref.trim();
|
|
22097
|
+
if (!value)
|
|
22098
|
+
return ref;
|
|
22099
|
+
if (isUuidShaped(value))
|
|
22100
|
+
return { lead_id: value };
|
|
22101
|
+
return normalizeDomain(value) ? { website: value } : { name: value };
|
|
22102
|
+
});
|
|
22103
|
+
}
|
|
22104
|
+
function rejectMalformedLeadRefs(refs) {
|
|
22105
|
+
if (!Array.isArray(refs))
|
|
22106
|
+
return;
|
|
22107
|
+
const bad = [];
|
|
22108
|
+
refs.forEach((ref, i) => {
|
|
22109
|
+
if (ref === null || typeof ref !== "object" || Array.isArray(ref)) {
|
|
22110
|
+
bad.push(`${i} (not an object)`);
|
|
22111
|
+
return;
|
|
22112
|
+
}
|
|
22113
|
+
for (const field of LEAD_REF_FIELDS) {
|
|
22114
|
+
const value = ref[field];
|
|
22115
|
+
if (value !== void 0 && typeof value !== "string") {
|
|
22116
|
+
bad.push(`${i}.${field} (${value === null ? "null" : typeof value})`);
|
|
22117
|
+
}
|
|
22118
|
+
}
|
|
22119
|
+
});
|
|
22120
|
+
if (bad.length === 0)
|
|
22121
|
+
return;
|
|
22122
|
+
throw {
|
|
22123
|
+
error: true,
|
|
22124
|
+
code: "INVALID_LEAD_REF",
|
|
22125
|
+
message: `lead_refs has ${bad.length} invalid entr${bad.length === 1 ? "y" : "ies"}: ${bad.join(", ")}.`,
|
|
22126
|
+
hint: "Each ref is an object whose fields are STRINGS \u2014 {lead_id} | {website} | {name, location?} | {contact_id}. A bare string is accepted and reshaped; null, numbers, arrays and non-string field values are not. Fix or drop those entries and re-call."
|
|
22127
|
+
};
|
|
22128
|
+
}
|
|
22129
|
+
function text(value) {
|
|
22130
|
+
if (typeof value !== "string")
|
|
22131
|
+
return null;
|
|
22132
|
+
const v = value.trim().toLowerCase();
|
|
22133
|
+
return v ? v : null;
|
|
22134
|
+
}
|
|
22135
|
+
function derivedRequestId(params) {
|
|
22136
|
+
const refs = canonicalSet((params.lead_refs ?? []).map((r) => {
|
|
22137
|
+
const website = text(r.website);
|
|
22138
|
+
return [
|
|
22139
|
+
// UUIDs are case-insensitive to the backend, so an uppercase id and
|
|
22140
|
+
// its lowercase form are the same lead and must share a key.
|
|
22141
|
+
normalizeUuid(r.lead_id),
|
|
22142
|
+
normalizeUuid(r.contact_id),
|
|
22143
|
+
// Normalize the website the SAME way the resolver does, so a pasted
|
|
22144
|
+
// "https://Acme.com/" and a retry's "acme.com" resolve to one company
|
|
22145
|
+
// AND to one key. Fall back to the trimmed/lowercased raw value when
|
|
22146
|
+
// it is not domain-shaped, rather than dropping the field.
|
|
22147
|
+
website ? normalizeDomain(website) ?? website : null,
|
|
22148
|
+
text(r.name),
|
|
22149
|
+
text(r.location)
|
|
22150
|
+
];
|
|
22151
|
+
}));
|
|
22152
|
+
const shape = {
|
|
22153
|
+
refs,
|
|
22154
|
+
// The WHOLE selector, not just the job id: qualifying the first 50 of a
|
|
22155
|
+
// delivery job and then the next 50 are different batches, and collapsing
|
|
22156
|
+
// them to one key would make the second submit look like a duplicate and
|
|
22157
|
+
// leave those refs unqualified.
|
|
22158
|
+
prior: [
|
|
22159
|
+
// UUID-folded like the refs above: the backend resolves the same
|
|
22160
|
+
// delivery job regardless of casing, so casing alone must not fork
|
|
22161
|
+
// the key and re-run a paid batch.
|
|
22162
|
+
normalizeUuid(params.prior_deliveries?.job_id),
|
|
22163
|
+
params.prior_deliveries?.since ?? null,
|
|
22164
|
+
params.prior_deliveries?.limit ?? null
|
|
22165
|
+
],
|
|
22166
|
+
// Canonicalize to the value the BACKEND will apply, so an approval that
|
|
22167
|
+
// omits a field and a retry that passes that field's documented default
|
|
22168
|
+
// derive the same key instead of launching a second paid job.
|
|
22169
|
+
qualify: params.qualify !== false,
|
|
22170
|
+
channels: canonicalSet(params.channels),
|
|
22171
|
+
contact_titles: canonicalLabelSet(params.contact_titles),
|
|
22172
|
+
// Same canonicalization as the search path: with contact_titles present
|
|
22173
|
+
// the backend applies `prefer` when the field is omitted, so an approval
|
|
22174
|
+
// that omits it and a retry that passes the materialized default describe
|
|
22175
|
+
// identical work. Hashing the omission as null forked the key and let the
|
|
22176
|
+
// retry escape dedupe into a second paid qualification / channel purchase.
|
|
22177
|
+
title_gate: params.title_gate ?? ((params.contact_titles?.length ?? 0) > 0 ? "prefer" : null),
|
|
22178
|
+
// The cap is part of the approval: raising it after a stop_reason:max_cost
|
|
22179
|
+
// is a NEW approved run, and must not dedupe onto the capped job.
|
|
22180
|
+
max_cost: params.max_cost ?? null,
|
|
22181
|
+
// Same for the output language — re-running the batch in another language
|
|
22182
|
+
// must not return the earlier job with evidence in the previous one.
|
|
22183
|
+
lang: params.lang ?? null
|
|
22184
|
+
};
|
|
22185
|
+
return derivedKey("qualify-auto", shape);
|
|
22186
|
+
}
|
|
22187
|
+
var DEFAULT_WAIT_SECONDS2, LEAD_REF_FIELDS, qualifyLeads;
|
|
22188
|
+
var init_qualify_leads = __esm({
|
|
22189
|
+
"../core/dist/composite/qualify-leads.js"() {
|
|
22190
|
+
"use strict";
|
|
22191
|
+
init_mcp_job_helpers();
|
|
22192
|
+
init_import_leads();
|
|
22193
|
+
init_tool_descriptions_generated();
|
|
22194
|
+
DEFAULT_WAIT_SECONDS2 = 45;
|
|
22195
|
+
LEAD_REF_FIELDS = [
|
|
22196
|
+
"lead_id",
|
|
22197
|
+
"website",
|
|
22198
|
+
"name",
|
|
22199
|
+
"location",
|
|
22200
|
+
"contact_id"
|
|
22201
|
+
];
|
|
22202
|
+
qualifyLeads = {
|
|
22203
|
+
name: "leadbay_qualify_leads",
|
|
22204
|
+
annotations: {
|
|
22205
|
+
title: "Qualify + get the right contact on known leads",
|
|
22206
|
+
readOnlyHint: false,
|
|
22207
|
+
// Spends real money (fresh qualification, and email/phone reveals when
|
|
22208
|
+
// channels are requested), same as bulk_qualify_leads / enrich-titles.
|
|
22209
|
+
// Hosts and approval layers key their prompts off this flag, so a paid
|
|
22210
|
+
// job submitter must not advertise itself as harmless.
|
|
22211
|
+
destructiveHint: true,
|
|
22212
|
+
idempotentHint: false,
|
|
22213
|
+
openWorldHint: true
|
|
22214
|
+
},
|
|
22215
|
+
write: true,
|
|
22216
|
+
description: leadbay_qualify_leads,
|
|
22217
|
+
inputSchema: {
|
|
22218
|
+
type: "object",
|
|
22219
|
+
properties: {
|
|
22220
|
+
lead_refs: {
|
|
22221
|
+
type: "array",
|
|
22222
|
+
description: "Companies to qualify (max 500). Each ref needs at least one identifying field. Duplicate lead_ids collapse into one item.",
|
|
22223
|
+
items: {
|
|
22224
|
+
type: "object",
|
|
22225
|
+
properties: {
|
|
22226
|
+
lead_id: { type: "string", description: "Leadbay lead UUID." },
|
|
22227
|
+
website: { type: "string" },
|
|
22228
|
+
name: { type: "string" },
|
|
22229
|
+
location: {
|
|
22230
|
+
type: "string",
|
|
22231
|
+
description: "Disambiguates name-only refs (city/region)."
|
|
22232
|
+
},
|
|
22233
|
+
contact_id: {
|
|
22234
|
+
type: "string",
|
|
22235
|
+
description: "Stable lead_contact id from a prior result \u2014 enrichment then targets EXACTLY this person, never a re-match."
|
|
22236
|
+
}
|
|
22237
|
+
},
|
|
22238
|
+
additionalProperties: false
|
|
22239
|
+
}
|
|
22240
|
+
},
|
|
22241
|
+
prior_deliveries: {
|
|
22242
|
+
type: "object",
|
|
22243
|
+
description: "Selector expanding the org's past MCP deliveries into refs \u2014 billed leads stay re-readable after result expiry. Combine with lead_refs or use alone.",
|
|
22244
|
+
properties: {
|
|
22245
|
+
job_id: { type: "string" },
|
|
22246
|
+
since: { type: "string", description: "ISO instant lower bound." },
|
|
22247
|
+
limit: { type: "number" }
|
|
22248
|
+
},
|
|
22249
|
+
additionalProperties: false
|
|
22250
|
+
},
|
|
22251
|
+
qualify: {
|
|
22252
|
+
type: "boolean",
|
|
22253
|
+
description: "Fresh AI qualification (default true; ~94 cost_cents per lead needing fresh research+scoring, cache-free when a fresh dossier exists). Owned disqualified leads come back WITH their negative evidence."
|
|
22254
|
+
},
|
|
22255
|
+
contact_titles: {
|
|
22256
|
+
type: "array",
|
|
22257
|
+
items: { type: "string" },
|
|
22258
|
+
description: "Wanted decision-maker titles (max 10), matched semantically."
|
|
22259
|
+
},
|
|
22260
|
+
title_gate: {
|
|
22261
|
+
type: "string",
|
|
22262
|
+
enum: ["strict", "prefer"],
|
|
22263
|
+
description: "strict = only items with a matching known contact deliver a contact; prefer = matched first, rest flagged."
|
|
22264
|
+
},
|
|
22265
|
+
channels: {
|
|
22266
|
+
type: "array",
|
|
22267
|
+
items: { type: "string", enum: ["email", "phone"] },
|
|
22268
|
+
description: "Channels to PURCHASE (email 25c, phone 250c, success-only, already-owned values are free). Empty = free identity tier."
|
|
22269
|
+
},
|
|
22270
|
+
max_cost: {
|
|
22271
|
+
type: "number",
|
|
22272
|
+
description: "Spend cap in cost_cents (plan-tier default when unset)."
|
|
22273
|
+
},
|
|
22274
|
+
request_id: {
|
|
22275
|
+
type: "string",
|
|
22276
|
+
description: "Recommended idempotency key \u2014 REUSE the same value when retrying the same batch so a retry returns the SAME job instead of re-spending."
|
|
22277
|
+
},
|
|
22278
|
+
lang: { type: "string", description: "Output language (default: user's language)." },
|
|
22279
|
+
confirm: {
|
|
22280
|
+
type: "boolean",
|
|
22281
|
+
description: "Explicit spend decision for the PAID work (fresh qualification and/or channel purchases). true = the user approved the quote, go ahead. false = a veto (returns mode:'needs_confirmation', spends nothing). Omitted on a paid call \u2192 the tool withholds the submit and returns a free quote to show the user first. A fully FREE call (qualify:false and no channels) needs no confirm."
|
|
22282
|
+
},
|
|
22283
|
+
dry_run: {
|
|
22284
|
+
type: "boolean",
|
|
22285
|
+
description: "Validate + worst-case cost + quota forecast. No job, no spend."
|
|
22286
|
+
},
|
|
22287
|
+
wait_seconds: {
|
|
22288
|
+
type: "number",
|
|
22289
|
+
description: "How long to poll before returning (default 45, max 180, 0 = submit + one snapshot). Large or research-heavy batches can take minutes \u2014 the result then carries still_running:true and the job_id for leadbay_lead_job_status."
|
|
22290
|
+
}
|
|
22291
|
+
},
|
|
22292
|
+
additionalProperties: false
|
|
22293
|
+
},
|
|
22294
|
+
execute: async (client, params, ctx) => {
|
|
22295
|
+
params = coerceArrayParams(params, [
|
|
22296
|
+
"lead_refs",
|
|
22297
|
+
"contact_titles",
|
|
22298
|
+
"channels"
|
|
22299
|
+
]);
|
|
22300
|
+
params = { ...params, lead_refs: normalizeLeadRefs(params.lead_refs) };
|
|
22301
|
+
rejectMalformedLeadRefs(params.lead_refs);
|
|
22302
|
+
rejectOversizedLeadRefs(params.lead_refs);
|
|
22303
|
+
const qualify = readSpendFlag(params.qualify, "qualify");
|
|
22304
|
+
const dryRun = readSpendFlag(params.dry_run, "dry_run");
|
|
22305
|
+
const confirm = readSpendFlag(params.confirm, "confirm");
|
|
22306
|
+
params = { ...params, qualify, dry_run: dryRun, confirm };
|
|
22307
|
+
const buysChannels = (params.channels?.length ?? 0) > 0;
|
|
22308
|
+
const buysQualification = qualify !== false;
|
|
22309
|
+
const isPaid = buysQualification || buysChannels;
|
|
22310
|
+
const vetoed = confirm === false;
|
|
22311
|
+
const consented = !vetoed && confirm === true;
|
|
22312
|
+
const requestId = presentRequestId(params.request_id) ?? (isPaid ? derivedRequestId(params) : void 0);
|
|
22313
|
+
const body = compactBody({
|
|
22314
|
+
lead_refs: params.lead_refs,
|
|
22315
|
+
prior_deliveries: params.prior_deliveries,
|
|
22316
|
+
qualify,
|
|
22317
|
+
contact_titles: params.contact_titles,
|
|
22318
|
+
title_gate: params.title_gate,
|
|
22319
|
+
channels: params.channels,
|
|
22320
|
+
max_cost: params.max_cost,
|
|
22321
|
+
request_id: requestId,
|
|
22322
|
+
lang: params.lang,
|
|
22323
|
+
dry_run: dryRun
|
|
22324
|
+
});
|
|
22325
|
+
if (dryRun === true) {
|
|
22326
|
+
const forecast = await client.request("POST", "/mcp/qualify", body);
|
|
22327
|
+
return { dry_run: true, ...forecast, region: client.region };
|
|
22328
|
+
}
|
|
22329
|
+
if (isPaid && !consented) {
|
|
22330
|
+
const forecast = vetoed ? null : await client.request("POST", "/mcp/qualify", {
|
|
22331
|
+
...body,
|
|
22332
|
+
dry_run: true
|
|
22333
|
+
});
|
|
22334
|
+
return {
|
|
22335
|
+
mode: "needs_confirmation",
|
|
22336
|
+
submitted: false,
|
|
22337
|
+
vetoed,
|
|
22338
|
+
paid_because: [
|
|
22339
|
+
buysQualification ? "qualify is on (backend default is true \u2014 pass qualify:false to keep it free)" : null,
|
|
22340
|
+
buysChannels ? `channels requested: ${params.channels.join(", ")}` : null
|
|
22341
|
+
].filter(Boolean),
|
|
22342
|
+
quote: forecast,
|
|
22343
|
+
estimated_cost: forecast?.estimated_cost ?? null,
|
|
22344
|
+
items_requested: forecast?.items_requested ?? null,
|
|
22345
|
+
hint: vetoed ? "confirm:false vetoed the spend \u2014 nothing was submitted. Re-call with confirm:true to proceed, or qualify:false with no channels for a free pass." : "Show the user this worst-case quote and get an explicit go-ahead, then re-call with confirm:true. For a free pass instead: qualify:false and no channels.",
|
|
22346
|
+
region: client.region
|
|
22347
|
+
};
|
|
22348
|
+
}
|
|
22349
|
+
const submit = await client.request("POST", "/mcp/qualify", body, { preSendSignal: ctx?.signal });
|
|
22350
|
+
const mocked = mockedSubmitPreview(submit, "leadbay_qualify_leads", client.region);
|
|
22351
|
+
if (mocked)
|
|
22352
|
+
return mocked;
|
|
22353
|
+
const waitSeconds = clampWaitSeconds(params.wait_seconds, DEFAULT_WAIT_SECONDS2);
|
|
22354
|
+
const snapshot = await snapshotAfterSubmit(client, submit.job_id, waitSeconds, ctx, submit.items_requested);
|
|
22355
|
+
const done = TERMINAL_JOB_STATES.has(snapshot.job.state);
|
|
22356
|
+
const indexed = submit.duplicate ?? false ? remapInputIndexes(snapshot.items, params.lead_refs) : { items: snapshot.items, remapped: true };
|
|
22357
|
+
const view = { ...snapshot, items: indexed.items };
|
|
22358
|
+
return {
|
|
22359
|
+
job_id: submit.job_id,
|
|
22360
|
+
// Echo the key actually sent, so a retry can reuse it verbatim.
|
|
22361
|
+
request_id: requestId ?? null,
|
|
22362
|
+
duplicate_submit: submit.duplicate ?? false,
|
|
22363
|
+
state: snapshot.job.state,
|
|
22364
|
+
done,
|
|
22365
|
+
summary: {
|
|
22366
|
+
refs_submitted: params.lead_refs?.length ?? 0,
|
|
22367
|
+
items_requested: submit.items_requested,
|
|
22368
|
+
delivered: snapshot.funnel.delivered ?? 0,
|
|
22369
|
+
delivered_callable: snapshot.funnel.delivered_callable ?? 0,
|
|
22370
|
+
degraded: snapshot.funnel.degraded ?? 0,
|
|
22371
|
+
resolved: snapshot.funnel.resolved ?? null,
|
|
22372
|
+
not_in_universe: snapshot.funnel.not_in_universe ?? null,
|
|
22373
|
+
stop_reason: snapshot.funnel.stop_reason ?? null
|
|
22374
|
+
},
|
|
22375
|
+
funnel: snapshot.funnel,
|
|
22376
|
+
// Per-item outcomes in input order where known (ref.input_indexes maps
|
|
22377
|
+
// back to the caller's lead_refs positions). Items carry the full
|
|
22378
|
+
// QualifiedLead payload when delivered/degraded, and an honest
|
|
22379
|
+
// status_reason (not_in_universe, low_confidence_identity, ...) when
|
|
22380
|
+
// skipped — a skip is an ANSWER about that ref, not an error.
|
|
22381
|
+
items: view.items,
|
|
22382
|
+
// On a duplicate submit whose indexes could not be re-pointed at this
|
|
22383
|
+
// caller's refs, input_indexes are null rather than stale — match items
|
|
22384
|
+
// by `ref.requested_as` / `lead_id` instead.
|
|
22385
|
+
input_indexes_remapped: submit.duplicate ?? false ? indexed.remapped : null,
|
|
22386
|
+
// ...and the same outcomes pre-split, because the shared
|
|
22387
|
+
// rendering/lead-delivery-table contract this tool's description
|
|
22388
|
+
// mandates reads deliveries from `leads[]` and skips from `skipped[]`.
|
|
22389
|
+
// Returning only `items` left an agent following the RENDER block with
|
|
22390
|
+
// two empty tables; the sibling tools (find_new_leads, lead_job_status)
|
|
22391
|
+
// both split. `items` stays for input-order per-ref mapping.
|
|
22392
|
+
...splitItems(view),
|
|
22393
|
+
items_truncated: snapshot.items_truncated ?? false,
|
|
22394
|
+
// Top-level, not only inside next_poll: a TERMINAL job that truncated had
|
|
22395
|
+
// next_poll null, so the rendering rule pointing at `since: next_since`
|
|
22396
|
+
// named a cursor the response did not carry.
|
|
22397
|
+
next_since: snapshot.next_since ?? null,
|
|
22398
|
+
cost: snapshot.cost,
|
|
22399
|
+
estimated_cost: submit.estimated_cost,
|
|
22400
|
+
explain: snapshot.explain,
|
|
22401
|
+
still_running: !done,
|
|
22402
|
+
// A finished job can still owe rows: truncation means the drain stopped
|
|
22403
|
+
// early, so there is a follow-up action even when done is true.
|
|
22404
|
+
next_poll: done && !(snapshot.items_truncated ?? false) ? null : {
|
|
22405
|
+
tool: "leadbay_lead_job_status",
|
|
22406
|
+
job_id: submit.job_id,
|
|
22407
|
+
// Hand the cursor forward so the follow-up poll continues
|
|
22408
|
+
// INCREMENTALLY instead of re-reading (and re-rendering) the
|
|
22409
|
+
// rows already delivered in this response.
|
|
22410
|
+
since: snapshot.next_since ?? null,
|
|
22411
|
+
suggested_wait_seconds: done ? 0 : 60
|
|
22412
|
+
},
|
|
22413
|
+
region: client.region
|
|
22414
|
+
};
|
|
22415
|
+
}
|
|
22416
|
+
};
|
|
22417
|
+
}
|
|
22418
|
+
});
|
|
22419
|
+
|
|
22420
|
+
// ../core/dist/composite/lead-job-status.js
|
|
22421
|
+
var leadJobStatus;
|
|
22422
|
+
var init_lead_job_status = __esm({
|
|
22423
|
+
"../core/dist/composite/lead-job-status.js"() {
|
|
22424
|
+
"use strict";
|
|
22425
|
+
init_mcp_job_helpers();
|
|
22426
|
+
init_tool_descriptions_generated();
|
|
22427
|
+
leadJobStatus = {
|
|
22428
|
+
name: "leadbay_lead_job_status",
|
|
22429
|
+
annotations: {
|
|
22430
|
+
title: "Poll a lead-delivery job",
|
|
22431
|
+
readOnlyHint: true,
|
|
22432
|
+
destructiveHint: false,
|
|
22433
|
+
idempotentHint: true,
|
|
22434
|
+
openWorldHint: true
|
|
22435
|
+
},
|
|
22436
|
+
description: leadbay_lead_job_status,
|
|
22437
|
+
inputSchema: {
|
|
22438
|
+
type: "object",
|
|
22439
|
+
properties: {
|
|
22440
|
+
job_id: {
|
|
22441
|
+
type: "string",
|
|
22442
|
+
description: "The job_id returned by leadbay_find_new_leads or leadbay_qualify_leads."
|
|
22443
|
+
},
|
|
22444
|
+
since: {
|
|
22445
|
+
type: "string",
|
|
22446
|
+
description: "Opaque cursor from a previous poll's next_since \u2014 returns only items emitted after it. Omit for the full snapshot."
|
|
22447
|
+
},
|
|
22448
|
+
limit: {
|
|
22449
|
+
type: "number",
|
|
22450
|
+
description: "Items per page, 1-100 (default 100; pages are auto-collected)."
|
|
22451
|
+
},
|
|
22452
|
+
wait_seconds: {
|
|
22453
|
+
type: "number",
|
|
22454
|
+
description: "0 (default) = instant snapshot. >0 = keep polling up to this many seconds until the job is terminal \u2014 use ~60 when the user asked to wait for results."
|
|
22455
|
+
}
|
|
22456
|
+
},
|
|
22457
|
+
required: ["job_id"],
|
|
22458
|
+
additionalProperties: false
|
|
22459
|
+
},
|
|
22460
|
+
execute: async (client, params, ctx) => {
|
|
22461
|
+
const waitSeconds = clampWaitSeconds(params.wait_seconds, 0);
|
|
22462
|
+
const snapshot = waitSeconds > 0 ? await waitForJob(client, params.job_id, waitSeconds, ctx, void 0, params.since, params.limit) : await collectJobSnapshot(client, params.job_id, params.since, params.limit, ctx?.signal);
|
|
22463
|
+
const done = TERMINAL_JOB_STATES.has(snapshot.job.state);
|
|
22464
|
+
const { leads, skipped } = splitItems(snapshot);
|
|
22465
|
+
return {
|
|
22466
|
+
job_id: params.job_id,
|
|
22467
|
+
state: snapshot.job.state,
|
|
22468
|
+
done,
|
|
22469
|
+
funnel: snapshot.funnel,
|
|
22470
|
+
leads,
|
|
22471
|
+
skipped,
|
|
22472
|
+
// Surfaced so the renderer never presents a partial page set as the whole
|
|
22473
|
+
// result: `leads` is a prefix, and next_since resumes it.
|
|
22474
|
+
items_truncated: snapshot.items_truncated ?? false,
|
|
22475
|
+
next_since: snapshot.next_since ?? null,
|
|
22476
|
+
cost: snapshot.cost,
|
|
22477
|
+
explain: snapshot.explain,
|
|
22478
|
+
still_running: !done,
|
|
22479
|
+
// Truncation leaves rows unread even on a finished job, so the follow-up
|
|
22480
|
+
// action survives `done` — same rule as the two submit tools.
|
|
22481
|
+
next_poll: done && !(snapshot.items_truncated ?? false) ? null : {
|
|
22482
|
+
tool: "leadbay_lead_job_status",
|
|
22483
|
+
job_id: params.job_id,
|
|
22484
|
+
// Same incremental handoff as the submit tools — following
|
|
22485
|
+
// next_poll without the cursor re-reads the rows just returned.
|
|
22486
|
+
since: snapshot.next_since ?? null,
|
|
22487
|
+
suggested_wait_seconds: done ? 0 : 60
|
|
22488
|
+
},
|
|
22489
|
+
region: client.region
|
|
22490
|
+
};
|
|
22491
|
+
}
|
|
22492
|
+
};
|
|
22493
|
+
}
|
|
22494
|
+
});
|
|
22495
|
+
|
|
20181
22496
|
// ../core/dist/composite/extend-lens.js
|
|
20182
22497
|
function httpStatus(err) {
|
|
20183
22498
|
return err?._meta?.http_status;
|
|
@@ -21587,8 +23902,8 @@ var init_send_feedback = __esm({
|
|
|
21587
23902
|
}
|
|
21588
23903
|
},
|
|
21589
23904
|
execute: async (client, params, ctx) => {
|
|
21590
|
-
const
|
|
21591
|
-
if (!
|
|
23905
|
+
const text2 = typeof params.message === "string" ? params.message.trim() : "";
|
|
23906
|
+
if (!text2) {
|
|
21592
23907
|
return {
|
|
21593
23908
|
error: true,
|
|
21594
23909
|
code: "BAD_INPUT",
|
|
@@ -21596,7 +23911,7 @@ var init_send_feedback = __esm({
|
|
|
21596
23911
|
hint: "Ask the user what they'd like to tell the Leadbay team, then call again with their words in `message`."
|
|
21597
23912
|
};
|
|
21598
23913
|
}
|
|
21599
|
-
const message =
|
|
23914
|
+
const message = text2.length > MESSAGE_MAX2 ? `${text2.slice(0, MESSAGE_MAX2 - 1)}\u2026` : text2;
|
|
21600
23915
|
if (!ctx?.sendFeedback) {
|
|
21601
23916
|
return {
|
|
21602
23917
|
sent: false,
|
|
@@ -21734,6 +24049,7 @@ __export(dist_exports, {
|
|
|
21734
24049
|
enrichContacts: () => enrichContacts,
|
|
21735
24050
|
enrichTitles: () => enrichTitles,
|
|
21736
24051
|
extendLens: () => extendLens,
|
|
24052
|
+
findNewLeads: () => findNewLeads,
|
|
21737
24053
|
followupsMap: () => followupsMap,
|
|
21738
24054
|
formatLoginError: () => formatLoginError,
|
|
21739
24055
|
getClarification: () => getClarification,
|
|
@@ -21764,6 +24080,7 @@ __export(dist_exports, {
|
|
|
21764
24080
|
inferKind: () => inferKind,
|
|
21765
24081
|
launchBulkEnrichment: () => launchBulkEnrichment,
|
|
21766
24082
|
launchFingerprint: () => launchFingerprint,
|
|
24083
|
+
leadJobStatus: () => leadJobStatus,
|
|
21767
24084
|
likeLead: () => likeLead,
|
|
21768
24085
|
listCampaigns: () => listCampaigns,
|
|
21769
24086
|
listLenses: () => listLenses,
|
|
@@ -21771,6 +24088,8 @@ __export(dist_exports, {
|
|
|
21771
24088
|
listMappableFields: () => listMappableFields,
|
|
21772
24089
|
listSectors: () => listSectors,
|
|
21773
24090
|
login: () => login,
|
|
24091
|
+
mcpFirstDeliveryAllTools: () => mcpFirstDeliveryAllTools,
|
|
24092
|
+
mcpFirstDeliveryTools: () => mcpFirstDeliveryTools,
|
|
21774
24093
|
openBillingPortal: () => openBillingPortal,
|
|
21775
24094
|
pickClarification: () => pickClarification,
|
|
21776
24095
|
prepareOutreach: () => prepareOutreach,
|
|
@@ -21779,6 +24098,7 @@ __export(dist_exports, {
|
|
|
21779
24098
|
pullFollowups: () => pullFollowups,
|
|
21780
24099
|
pullLeads: () => pullLeads,
|
|
21781
24100
|
qualifyLead: () => qualifyLead,
|
|
24101
|
+
qualifyLeads: () => qualifyLeads,
|
|
21782
24102
|
qualifyStatus: () => qualifyStatus,
|
|
21783
24103
|
recallLaunch: () => recallLaunch,
|
|
21784
24104
|
recallOrderedTitles: () => recallOrderedTitles,
|
|
@@ -21815,7 +24135,7 @@ __export(dist_exports, {
|
|
|
21815
24135
|
updateLens: () => updateLens,
|
|
21816
24136
|
updateLensFilter: () => updateLensFilter
|
|
21817
24137
|
});
|
|
21818
|
-
var granularReadTools, granularWriteTools, granularTools, compositeReadTools, compositeWriteTools, compositeTools, tools;
|
|
24138
|
+
var granularReadTools, granularWriteTools, granularTools, compositeReadTools, mcpFirstDeliveryTools, mcpFirstDeliveryAllTools, compositeWriteTools, compositeTools, tools;
|
|
21819
24139
|
var init_dist = __esm({
|
|
21820
24140
|
"../core/dist/index.js"() {
|
|
21821
24141
|
"use strict";
|
|
@@ -21913,6 +24233,9 @@ var init_dist = __esm({
|
|
|
21913
24233
|
init_adjust_audience();
|
|
21914
24234
|
init_refine_prompt();
|
|
21915
24235
|
init_seed_candidates();
|
|
24236
|
+
init_find_new_leads();
|
|
24237
|
+
init_qualify_leads();
|
|
24238
|
+
init_lead_job_status();
|
|
21916
24239
|
init_extend_lens();
|
|
21917
24240
|
init_my_lenses();
|
|
21918
24241
|
init_new_lens();
|
|
@@ -21982,6 +24305,13 @@ var init_dist = __esm({
|
|
|
21982
24305
|
t.advanced = true;
|
|
21983
24306
|
});
|
|
21984
24307
|
compositeReadTools = [
|
|
24308
|
+
// Poll surface for the MCP-first lead-delivery jobs (find_new_leads /
|
|
24309
|
+
// qualify_leads). Read-only snapshot of a backend-owned job. The backend
|
|
24310
|
+
// routes (`POST /1.6/mcp/search`, `POST /1.6/mcp/qualify`,
|
|
24311
|
+
// `GET /1.6/mcp/jobs/{id}`) shipped to production in backend v3.22.0
|
|
24312
|
+
// (2026-08-22) and were verified live on both regions, so the opt-in
|
|
24313
|
+
// LEADBAY_MCP_LEAD_DELIVERY flag that held these three back is gone.
|
|
24314
|
+
leadJobStatus,
|
|
21985
24315
|
pullLeads,
|
|
21986
24316
|
pullFollowups,
|
|
21987
24317
|
followupsMap,
|
|
@@ -22044,6 +24374,11 @@ var init_dist = __esm({
|
|
|
22044
24374
|
// leadbay_new_lens / leadbay_adjust_audience). Without it the agent can only
|
|
22045
24375
|
// probe sectors by trial-and-error or ask the user to read the web UI.
|
|
22046
24376
|
listSectors,
|
|
24377
|
+
// listLocations, same rationale on the geography axis. The delivery tools
|
|
24378
|
+
// reject an unresolvable filters.locations with a 400 naming the value and
|
|
24379
|
+
// send the agent here to look up the real admin area — a recovery path that
|
|
24380
|
+
// only works if the lookup is reachable without LEADBAY_MCP_ADVANCED=1.
|
|
24381
|
+
listLocations,
|
|
22047
24382
|
// Billing / top-up tools — granular-shaped but ALWAYS exposed because
|
|
22048
24383
|
// they're the canonical recovery path from a QUOTA_EXCEEDED wall. If
|
|
22049
24384
|
// they were gated behind LEADBAY_MCP_ADVANCED=1 the agent would
|
|
@@ -22073,7 +24408,21 @@ var init_dist = __esm({
|
|
|
22073
24408
|
// tools/) so it carries no _triggered_by mandate for a kit fetch.
|
|
22074
24409
|
artifactKit
|
|
22075
24410
|
];
|
|
24411
|
+
mcpFirstDeliveryTools = [
|
|
24412
|
+
// Write-tier: submits create server-side jobs that can spend money
|
|
24413
|
+
// (qualification research, channel purchase) and claim novelty in the
|
|
24414
|
+
// org's delivery ledger — same posture as the other spending composites.
|
|
24415
|
+
// The FREE tier (qualify:false, channels:[]) is the default ask, and a paid
|
|
24416
|
+
// call is withheld in code until `confirm: true`.
|
|
24417
|
+
findNewLeads,
|
|
24418
|
+
qualifyLeads
|
|
24419
|
+
];
|
|
24420
|
+
mcpFirstDeliveryAllTools = [
|
|
24421
|
+
...mcpFirstDeliveryTools,
|
|
24422
|
+
leadJobStatus
|
|
24423
|
+
];
|
|
22076
24424
|
compositeWriteTools = [
|
|
24425
|
+
...mcpFirstDeliveryTools,
|
|
22077
24426
|
bulkQualifyLeads,
|
|
22078
24427
|
enrichTitles,
|
|
22079
24428
|
adjustAudience,
|
|
@@ -23464,6 +25813,170 @@ After I answer, call \`leadbay_report_outreach({lead_id: '{{arg:lead_id}}', note
|
|
|
23464
25813
|
# PHASE 3 \u2014 CONFIRM
|
|
23465
25814
|
Tell me the outreach was logged, name the verification.source used, and surface the response's \`outreach_id\` if present so I can refer back to it.
|
|
23466
25815
|
`;
|
|
25816
|
+
var leadbay_new_leads = `
|
|
25817
|
+
## WHAT LEADBAY SHOULD REMEMBER
|
|
25818
|
+
|
|
25819
|
+
You keep your own memory of how this user likes to work \u2014 tone, naming, formatting, what they ask you to skip. Leadbay does not store that and does not need to.
|
|
25820
|
+
|
|
25821
|
+
What Leadbay does need is anything that changes **who it should find**. When the user states targeting criteria in conversation ("I target fleets over 100 vehicles", "carriers are a bad fit unless they do last-mile delivery", "climate engineering is also my market"), call \`leadbay_refine_prompt\` so it changes what Leadbay surfaces for the whole org and on every future refresh \u2014 not just this conversation. When they say a specific lead is wrong for them, record the dislike rather than noting it.
|
|
25822
|
+
|
|
25823
|
+
|
|
25824
|
+
IRON LAW \u2014 NO FABRICATION. Every lead id, contact email, custom field id, mapping decision, and tool argument must trace to a value you read from the file the user attached or to an output from a leadbay_* tool call in this session. Do not invent values. Do not "fill in" a missing leadId with a name match. Do not synthesize a CRM id from a guess. If a value is missing, leave the field blank and say so.
|
|
25825
|
+
|
|
25826
|
+
|
|
25827
|
+
GATE \u2014 DEFER TO TOOL RENDERING. When you call a Leadbay composite that ships its own RENDERING block (every composite in 0.9.0+ does), render the response using that block's recipe verbatim \u2014 score bars, glyph palette, column order, hide-list, link priorities, all of it. Do NOT substitute prose, a numbered list, or a different column structure even when an orchestrating prompt's body suggests alternate framing. Prompt-specific commentary (motivational nudges, summaries, next-action recommendations) belongs ABOVE or BELOW the canonical table, never in place of it.
|
|
25828
|
+
|
|
25829
|
+
If the prompt's body and the tool's RENDERING appear to conflict, the tool's RENDERING wins for the structural layout; the prompt's voice wins for the commentary that surrounds it.
|
|
25830
|
+
|
|
25831
|
+
|
|
25832
|
+
**First, check \`leadbay_find_new_leads\` is in your tool set.** Every phase below
|
|
25833
|
+
calls it or \`leadbay_qualify_leads\`, and both are write-tier: on a read-only
|
|
25834
|
+
deployment (\`LEADBAY_MCP_WRITE=0\`) neither is registered. The MCP prompt hides
|
|
25835
|
+
itself there; this file is a static Claude skill with no runtime gate, so the
|
|
25836
|
+
check has to be here. If they're missing: say plainly that net-new search isn't
|
|
25837
|
+
enabled on this connection, and offer \`leadbay_pull_leads\` for today's batch
|
|
25838
|
+
instead. Starting a workflow whose first call does not exist is worse than
|
|
25839
|
+
saying so up front.
|
|
25840
|
+
|
|
25841
|
+
Find net-new leads for me. My need, in my words:
|
|
25842
|
+
|
|
25843
|
+
> {{arg:need}}
|
|
25844
|
+
|
|
25845
|
+
If that need was not supplied to you directly, take it from the message that
|
|
25846
|
+
started this \u2014 the request in my own words is the need, and I should never be
|
|
25847
|
+
asked to repeat something I already said. Only when BOTH are missing or too
|
|
25848
|
+
vague to name (a) who I sell to and (b) roughly how many leads I want, ask me
|
|
25849
|
+
ONCE \u2014 one short question \u2014 then proceed. Default count when unstated: 10.
|
|
25850
|
+
|
|
25851
|
+
# PHASE 1 \u2014 UNDERSTAND THE BUYER (no tool calls yet)
|
|
25852
|
+
|
|
25853
|
+
From my words, work out:
|
|
25854
|
+
- What I SELL and therefore WHO WRITES ME CHECKS \u2014 the buyer category, never
|
|
25855
|
+
the buyer's customers, never my competitors. If my product helps companies
|
|
25856
|
+
of type X serve audience Y, my buyer is X.
|
|
25857
|
+
- Hard constraints: geography, size band, sector, exclusions ("no
|
|
25858
|
+
franchises", "pas de grands groupes" \u2014 negatives BIND).
|
|
25859
|
+
- Contact needs: do I want a person? Which titles? Email, phone, both?
|
|
25860
|
+
- Buyer archetypes: if my need genuinely spans two different kinds of buyer,
|
|
25861
|
+
plan one search per archetype \u2014 never one blended seed.
|
|
25862
|
+
|
|
25863
|
+
# PHASE 2 \u2014 CRAFT THE SEED
|
|
25864
|
+
|
|
25865
|
+
Compose the \`example_lead\` for each archetype following the craft rules in
|
|
25866
|
+
the leadbay_find_new_leads description (registry-style description of a
|
|
25867
|
+
FICTIONAL typical buyer; no invented brand name; no event language; hard
|
|
25868
|
+
constraints go in \`filters\` with the FLAT keys \`employees_min\`/\`employees_max\`
|
|
25869
|
+
and city/state/region \`locations\` \u2014 never a country name). Show me the seed
|
|
25870
|
+
description(s) in one line each \u2014 I should recognize my ideal customer in
|
|
25871
|
+
them.
|
|
25872
|
+
|
|
25873
|
+
\`filters\` only encodes sectors, locations and employee bounds. Any constraint
|
|
25874
|
+
that does not fit those keys \u2014 above all EXCLUSIONS like "no franchises" or
|
|
25875
|
+
"pas de grands groupes" \u2014 has nowhere to live in the filter schema, so it must
|
|
25876
|
+
not be dropped on the floor: express it positively in the seed \`description\`
|
|
25877
|
+
(an independent single-site operator rather than "no franchises"), and carry
|
|
25878
|
+
the exclusion forward yourself to Phase 5, where you drop violating rows and
|
|
25879
|
+
say you dropped them. Tell me plainly if a constraint can only be enforced
|
|
25880
|
+
that way \u2014 after the fact, not by the search.
|
|
25881
|
+
|
|
25882
|
+
Composing this fictional seed from my words is expected and permitted: it is
|
|
25883
|
+
the tool's designed input, not fabricated data. What must never be invented is
|
|
25884
|
+
a RESULT \u2014 company names, contacts, scores, or anything presented as coming
|
|
25885
|
+
back from Leadbay.
|
|
25886
|
+
|
|
25887
|
+
# PHASE 3 \u2014 FREE PREVIEW
|
|
25888
|
+
|
|
25889
|
+
Call \`leadbay_find_new_leads\` with the seed, \`filters\`, \`count\`,
|
|
25890
|
+
\`qualify: false\`, no channels \u2014 this is FREE \u2014 and a \`request_id\` derived
|
|
25891
|
+
from the ask + the ARCHETYPE + today's date. \`count\` is the TOTAL I asked
|
|
25892
|
+
for, not a per-search number: with two archetypes and a request for 10,
|
|
25893
|
+
split it (5 + 5, or whatever weighting fits my ask) rather than sending 10
|
|
25894
|
+
to each \u2014 otherwise I get 20 leads and, on the paid pass, pay for 20.
|
|
25895
|
+
|
|
25896
|
+
When you RETRY a search \u2014 it timed out, or the job is still live \u2014 reuse the
|
|
25897
|
+
\`request_id\` you already sent, verbatim. Do not recompute it: rederiving from
|
|
25898
|
+
"today's date" after midnight yields a new key, the backend cannot dedupe, and
|
|
25899
|
+
a second paid, novelty-claiming search launches. Roll the date only when I am
|
|
25900
|
+
genuinely asking for a new batch. The archetype component is not
|
|
25901
|
+
optional: \`request_id\` is the idempotency key, so two archetype searches
|
|
25902
|
+
sharing one id dedupe to the same job and the second archetype is never
|
|
25903
|
+
searched. Render the delivery table and judge fit honestly: are these the
|
|
25904
|
+
kind of companies I asked for?
|
|
25905
|
+
|
|
25906
|
+
- **\`still_running: true\`** \u2192 the job is ALIVE. Do not judge the seed and do
|
|
25907
|
+
not relaunch \u2014 poll \`leadbay_lead_job_status\` (\`wait_seconds: 60\`) until
|
|
25908
|
+
it goes terminal, reporting progress. Relaunching now burns an active-job
|
|
25909
|
+
slot and rate-limit budget on a search that may be about to deliver.
|
|
25910
|
+
- **On-profile** (terminal) \u2192 offer Phase 4.
|
|
25911
|
+
- **Off-profile or empty** (terminal) \u2192 read \`funnel\` +
|
|
25912
|
+
\`explain.scope_notes\`, tell me what went wrong in one line (wrong
|
|
25913
|
+
archetype? too narrow a filter? thin universe?), reshape the seed or
|
|
25914
|
+
filters, and retry under a NEW request_id. Reshaping is free; do not pay
|
|
25915
|
+
to explore a bad seed.
|
|
25916
|
+
|
|
25917
|
+
# PHASE 4 \u2014 PAID DEPTH (only with my explicit go-ahead)
|
|
25918
|
+
|
|
25919
|
+
When I want qualification evidence and/or reachable contacts:
|
|
25920
|
+
1. Quote first: \`dry_run: true\` on the tool you will actually run, with the
|
|
25921
|
+
exact flags I asked for, and tell me the worst-case cost in plain money.
|
|
25922
|
+
The two tools take DIFFERENT flags \u2014 passing the wrong one is rejected
|
|
25923
|
+
outright (\`additionalProperties: false\`):
|
|
25924
|
+
- \`leadbay_qualify_leads\`: \`qualify: true\`, \`contact_titles\`,
|
|
25925
|
+
\`title_gate\`, \`channels\`, \`max_cost\`. **No \`min_ai_score\`.**
|
|
25926
|
+
- \`leadbay_find_new_leads\`: the same, PLUS \`min_ai_score\` and \`count\`.
|
|
25927
|
+
2. On my go-ahead, prefer feeding the free preview's deliveries to
|
|
25928
|
+
\`leadbay_qualify_leads\` (\`prior_deliveries: {job_id}\`) \u2014 one paid pass PER
|
|
25929
|
+
preview job when Phase 3 ran several archetypes, or merge their delivered
|
|
25930
|
+
refs into a single \`lead_refs\` call. Never qualify just the first job and
|
|
25931
|
+
call it done: the other archetypes are part of what I asked for. It only
|
|
25932
|
+
spends on
|
|
25933
|
+
companies already known to match. Paid calls need \`confirm: true\`; without
|
|
25934
|
+
it the tool withholds the submit and hands back a quote instead of
|
|
25935
|
+
spending. That applies to \`leadbay_find_new_leads\` too whenever you set
|
|
25936
|
+
\`qualify: true\` or ask for channels.
|
|
25937
|
+
|
|
25938
|
+
If the preview delivered FEWER than I asked for, do both halves and do not
|
|
25939
|
+
conflate them: qualify what the preview already found, and run the fresh
|
|
25940
|
+
search only for the SHORTFALL \u2014 \`count\` = what is still missing, never the
|
|
25941
|
+
original number, under a NEW \`request_id\`. Reusing the preview's id dedupes
|
|
25942
|
+
the paid submit back into the free job; keeping the original count buys a
|
|
25943
|
+
whole second batch, because \`novelty: org\` already excludes everything the
|
|
25944
|
+
preview delivered.
|
|
25945
|
+
|
|
25946
|
+
The same arithmetic applies AFTER the paid pass. A full-count preview can
|
|
25947
|
+
still end short once qualification disqualifies rows or a strict title /
|
|
25948
|
+
channel match misses: what I asked for is n QUALIFIED, CONTACTABLE leads,
|
|
25949
|
+
not n examined. Count the delivered-and-callable rows; if they fall short,
|
|
25950
|
+
tell me the gap in one line and offer to top it up \u2014 another shortfall-sized
|
|
25951
|
+
search under a NEW \`request_id\`, quoted first like any paid run. Never
|
|
25952
|
+
silently hand back fewer than I asked for and paid toward.
|
|
25953
|
+
|
|
25954
|
+
Pass the leads already EXAMINED-AND-REJECTED into that top-up's
|
|
25955
|
+
\`exclude_lead_ids\` \u2014 disqualified and skipped, from both the preview and
|
|
25956
|
+
the paid pass. \`novelty: org\` already excludes prior DELIVERIES, so
|
|
25957
|
+
delivered ids are redundant there; the rejected ones are exactly what it
|
|
25958
|
+
misses, and without them the top-up re-picks the same misses and charges
|
|
25959
|
+
again to close no gap. **\`exclude_lead_ids\` caps at 500** \u2014 a wide
|
|
25960
|
+
\`exploration_cap\` can examine more than that, so send the most recent 500
|
|
25961
|
+
rejects rather than an over-long list the tool refuses outright.
|
|
25962
|
+
3. While the job runs, poll with \`leadbay_lead_job_status\`
|
|
25963
|
+
(\`wait_seconds: 60\`); report progress, not silence.
|
|
25964
|
+
|
|
25965
|
+
# PHASE 5 \u2014 DELIVER
|
|
25966
|
+
|
|
25967
|
+
Before rendering, sanity-check every row: geography inside my fence (drop
|
|
25968
|
+
and call out same-named-city leaks), descriptions actually matching my ask
|
|
25969
|
+
(especially when \`explain.seed_strategy\` is \`text_match_exemplars\` \u2014 fit
|
|
25970
|
+
scores run hot there), visible violations of my exclusions dropped. If the
|
|
25971
|
+
best fit is under 30, say "weak matches only" and propose reshaping before
|
|
25972
|
+
showing more than 3.
|
|
25973
|
+
|
|
25974
|
+
Render per the lead-delivery table, then ALWAYS the funnel line: matched /
|
|
25975
|
+
examined / qualified / disqualified / delivered / stop reason / spend. Zero
|
|
25976
|
+
delivered gets a diagnosis and a concrete next move, never a shrug. Close
|
|
25977
|
+
with NEXT STEPS from the tool description \u2014 and STOP; take no further action
|
|
25978
|
+
without my say-so.
|
|
25979
|
+
`;
|
|
23467
25980
|
var leadbay_plan_tour_in_city = `
|
|
23468
25981
|
Plan a field sales tour for me in **{{arg:city}}**{{arg:date_paren}}.
|
|
23469
25982
|
|
|
@@ -24857,6 +27370,14 @@ that's leadbay_prospecting_overview.
|
|
|
24857
27370
|
`, "arguments": [], "expected_calls": ["leadbay_account_status", "leadbay_pull_leads", "leadbay_prepare_outreach", "leadbay_enrich_titles", "leadbay_bulk_enrich_status"], "failure_modes": ['Presents a gate as prose ("let me know if you want me to pull your leads") instead of CALLING the host choice widget \u2014 the click IS the lesson, and prose turns the walkthrough into a lecture', "Runs a step's tool WITHOUT firing that step's widget first and waiting for the click \u2014 the walkthrough becomes an automated demo the user only watches, which is the exact opposite of learning by doing", "Fires the widget without the EXPLAIN beat, so the user gets an unexplained button and learns nothing about what a lens or an enrichment actually is", 'Answers gate 1 with a bare "you\'re connected as X at Y" when the quota IS readable \u2014 the user clicked a button labelled `check my account status`, so the quota windows (Daily/Weekly/Monthly gauges, % used, $ spent, resets) ARE the answer, not an optional extra', 'Renders quota as raw "credits" instead of the web app\'s percentage + dollar-spend gauges, or dumps raw `resource_type` strings the user has never seen', "Opens with a wall of text \u2014 previewing all four steps, explaining lenses up front, or writing several paragraphs before the first widget. The opening is TWO lines then the button; a first-run user wants to see it work, not read a syllabus", `Ends the first message without firing gate 1's widget, leaving the user to reply "ok" before anything happens`, "Rewrites the gate's own `next_steps` payload (its `question`, `label` or `description`) instead of mapping it into the widget verbatim, or merges two gates into a single multi-option widget", 'Fires a THIRD option, or turns the exit into an alternative route ("show me my lenses instead") \u2014 each gate carries exactly one forward action plus the `I\'m done for now` exit, never a menu of paths', `Fires a single-option widget \u2014 the host requires 2\u20134 options, so a lone option is rejected or silently degrades to prose ("say the word and I'll check it"), which is the exact defect this rule exists to prevent`, 'Launches the PAID reveal at gate 4 BEFORE the user has picked leads and confirmed \u2014 beat 1 must be the free `mode:"discover"` preview (no `titles`, no `confirm`, no `email`, no `phone`); the gate click bought the free look, not the reveal, and silence is never consent', "Stops at the free preview after the user DID pick leads and confirm \u2014 they asked for real contact details, so the second call must actually run with `confirm:true` and the chosen titles", "Reports the enrichment without polling `leadbay_bulk_enrich_status` to completion, so it claims contacts it never actually saw resolve", `Reveals contacts and never says what it cost \u2014 the user just spent credits and deserves the one-line "N contacts = N credits", which is also what makes gate 1's quota numbers concrete`, 'Reports "no leads" on an empty batch while `computing_wishlist` / `computing_scores` is true \u2014 the lens is still building; render the tool\'s own two-option warm-up widget verbatim and pause', "Rewords, reorders or prose-ifies the `next_steps` payload from `leadbay_pull_leads` instead of mapping `options[]` into the widget verbatim", "Runs all four steps in one turn without waiting for the user's click between gates \u2014 the walkthrough is a sequence of gates, not a script to recite", "Skips `leadbay_pull_leads` and jumps straight to enrichment, leaving gate 4 with no `leadIds` to scope", "Passes a singular `leadId` to `leadbay_enrich_titles` on the confirmed reveal \u2014 that key does not exist on this tool, so it is dropped and the paid call falls back to the whole default wishlist selection, charging for far more than the one lead the user agreed to. it is always the `leadIds` ARRAY, even for a single lead", "Drops the pinned `lens.id` between gates, so gate 4 enriches against a different lens than the one the user just saw", "Ends the completed walkthrough without the `keep_going` cheat-sheet \u2014 the buttons disappear with the tour, so a user who was never told what to TYPE learned to click a tutorial and nothing about using Leadbay tomorrow", "Invents phrases for the cheat-sheet, or rewords them into something that sounds nicer but doesn't match the tool's real triggers \u2014 teaching a phrase that doesn't route is worse than teaching none", "SENDS the gate 3 draft, or offers to send it \u2014 the walkthrough drafts and stops there; the email is the user's to judge, and nothing leaves the chat", "Passes `enrich:true` to `leadbay_prepare_outreach` at gate 3 \u2014 that launches a PAID contact reveal off the back of a DRAFT click, spending credits the user never agreed to", "Invents a contact NAME for the gate 3 draft \u2014 `recommended_contact` still has null email/name at that point, so the draft is addressed to the job TITLE; a fabricated name is the one thing that makes the whole draft untrustworthy", "Treats the null email at gate 3 as a failure \u2014 apologising for it, retrying, or calling another tool to fill it in. It is the setup for gate 4 \u2014 an email written, nobody to send it to yet", "Pastes the drafted email into chat prose alongside `message_compose_v1` instead of letting the composer BE the answer", "Enriches leads other than the one it drafted for at gate 3 \u2014 gate 4 reveals the person that email is going to, so it is scoped to that ONE lead, one contact, one credit", "Renders the cheat-sheet on the exit and stops there, dropping the 1:1 offer \u2014 the observed failure is that the agent feels finished once the table is on screen, so the user who just stepped out never hears about the help that would bring them back. ENDING B is not complete without the offer, and the offer goes LAST", "Treats the exit click as ENDING C (typed off-script) and closes in silence, or treats a typed request as ENDING B and buries their real answer under a cheat-sheet and a booking link", "Turns the exit offer into a pitch \u2014 several sentences, a re-opened gate, or an argument for finishing the tour. They said they were done; it is one line and a link", "Fires the 1:1 offer mid-tour, or at a user who left by TYPING a different request \u2014 a booking link on top of their real question is an interruption, not an offer", "Runs the four gates at a user whose actual problem is SETUP \u2014 the connector isn't installed, they can't sign in, or their Leadbay tools aren't appearing. The tour assumes a working connection and cannot fix any of it; the setup guide can", "Pastes the setup-guide link mid-tour, between gates, instead of once at the closing \u2014 a link in the middle of the walkthrough invites the user to leave the thing they're doing"] },
|
|
24858
27371
|
leadbay_import_file: { "name": "leadbay_import_file", "short_description": "Import a user-supplied CSV/file into Leadbay through five phases with\nevidence gates \u2014 scan, derive, resolve identities, preserve & commit,\nthen optionally qualify and report. The job is to maximize how many\nrows the Leadbay system actually ingests and matches.\n", "arguments": [{ "name": "file", "description": "Path or user-visible name of the CSV/file to import. If omitted, use the file the user attached or referenced.", "required": false }, { "name": "instruction", "description": 'Additional user goal, e.g. "then qualify the leads", "preserve owner phone as a custom field", or "only import restaurants in Manhattan".', "required": false }], "expected_calls": ["leadbay_resolve_import_rows", "leadbay_list_mappable_fields", "leadbay_create_custom_field", "leadbay_import_leads", "leadbay_import_and_qualify", "leadbay_add_note", "leadbay_import_status"], "failure_modes": ["Picks LEADBAY_ID from score alone, name-only, fuzzy-name-only, root-domain-only, brand-only, postcode-only, or city-only evidence", "Drops meaningful business notes or CRM record links instead of preserving them as custom fields or lead notes", "Treats a consumer mailbox domain (gmail.com, hotmail.com, ...) as the company domain", "Skips deriving company_domain from a business email when no website column exists (this kills match rate)", "Skips the COLUMN PRESERVATION PLAN byproduct before importing", "Skips the DECISION LOG byproduct before writing LEADBAY_ID", "Returns the imported records WITHOUT writing LEADBAY_ID values back into the user's file (leaves the user no audit trail of what matched)", "Fabricates leadIds, contact emails, or mapping IDs not present in the file or a tool response"] },
|
|
24859
27372
|
leadbay_log_outreach: { "name": "leadbay_log_outreach", "short_description": "Log outreach (an email I sent, a call I made, a meeting I had) on a\nspecific lead. Captures verification so the SDR pipeline trusts the entry.\n", "arguments": [{ "name": "lead_id", "description": "The lead UUID. Get it from leadbay_pull_leads or leadbay_research_lead_by_id.", "required": true }, { "name": "summary", "description": "1-2 sentences describing what I did (e.g. 'Sent intro email to CTO citing recent Hornsea contract').", "required": true }], "expected_calls": ["leadbay_report_outreach"], "failure_modes": ["Calls leadbay_report_outreach without first collecting a verification source", "Fabricates a gmail_message_id or calendar_event_id (the human team treats verification as canonical)", "Records outreach to a different lead_id than the one the user supplied", "Skips the dry_run step when the user is unsure what would be sent"] },
|
|
27373
|
+
leadbay_new_leads: { "name": "leadbay_new_leads", "short_description": `Guided net-new lead delivery \u2014 turn a described need ("gyms around Dallas
|
|
27374
|
+
that would buy our flooring") into ICP-perfect NEW companies with
|
|
27375
|
+
qualification evidence and the right contact, via leadbay_find_new_leads.
|
|
27376
|
+
Trigger when the user DESCRIBES who they want: "get me N companies that
|
|
27377
|
+
<profile>", "we're entering <market>". A bare "find me new leads" with no
|
|
27378
|
+
profile, and "today's leads", are the daily lens batch \u2014 leadbay_pull_leads.
|
|
27379
|
+
"Qualify these companies I have" is leadbay_qualify_leads.
|
|
27380
|
+
`, "arguments": [{ "name": "need", "description": "What the user is looking for, in their own words (e.g. '10 gyms around Dallas that would buy modular flooring, with phone numbers'). Optional \u2014 the session starts by asking when absent.", "required": false }], "expected_calls": ["leadbay_find_new_leads", "leadbay_lead_job_status", "leadbay_qualify_leads"], "failure_modes": ["Passes the user's raw sentence as `query` instead of crafting an example_lead description (vendor-vocabulary trap \u2014 measured 0 delivered from a raw query vs on-profile results from a crafted example)", "Invents a distinctive brand name in example_lead.name (pulls matching toward name-lookalikes)", 'Puts event language ("hiring", "expanding", "just raised") into the seed description', "Launches qualify:true or channels without a dry_run quote and the user's explicit go-ahead", "Retries a failed/timed-out submit with a NEW request_id (double-spend) \u2014 the same ask must reuse the same request_id", 'Reports "no results" without narrating the funnel + scope_notes and proposing a concrete fix', "Renders delivered leads as freeform prose instead of the canonical lead-delivery table", "Blends two distinct buyer archetypes into one seed description instead of running one search per archetype", "Passes a country name in filters.locations (silently matches a same-named town \u2014 whole-country intent means OMITTING locations) or a nested employees object instead of the flat employees_min/employees_max", "Renders rows that visibly violate the user's exclusions, or presents a best-fit-under-30 table as an answer instead of flagging weak matches"] },
|
|
24860
27381
|
leadbay_plan_tour_in_city: { "name": "leadbay_plan_tour_in_city", "short_description": 'Use whenever the user names a city they\'ll be in and asks who to see\n\u2014 "I\'m in SF next Tuesday, who\'s worth meeting?", "I\'m going to Berlin\n\u2014 who should I visit?", "plan my <city> tour". Any in-person/visit\nintent tied to a place routes here, NOT to `leadbay_pull_leads`. It\nsurfaces follow-ups + fresh Discover leads in the city via\n`leadbay_tour_plan`, ALWAYS offers to plot them on a map (rendering it\non yes), then offers outreach drafts + campaign persistence.\n', "arguments": [{ "name": "city", "description": "City or region the user is visiting (e.g. 'Limoges', 'Bay Area'). Used as the geo filter for both Monitor and Discover lookups. A country is not a city: this workspace already covers exactly one country, and a country name here silently fences the tour to a same-named village. Do NOT omit the argument to recover \u2014 a city-less tour returns arbitrary leads from across the whole workspace, which is not an itinerary. Ask which city or region the visit is to.", "required": true }, { "name": "date", "description": "When the visit is (e.g. 'May 24', 'next Thursday'). Surfaced in the outreach drafts as 'I'll be in <city> on <date>'.", "required": false }], "expected_calls": ["leadbay_tour_plan", "leadbay_research_lead_by_id", "leadbay_prepare_outreach", "leadbay_create_campaign"], "failure_modes": ["Calls leadbay_followups_map (Monitor-only) instead of leadbay_tour_plan \u2014 loses the Discover (fresh-lead) half that the user explicitly asked for", "Calls leadbay_pull_leads then drops the geo filter \u2014 returns the lens-wide wishlist instead of city-relevant fresh leads", 'Skips the campaign-persist step ("would you like to save these as a tour?") \u2014 leaves the rep with a one-shot map but no follow-up artifact', "Creates a campaign WITHOUT asking the user first \u2014 the persist step is high-intent; offer it, don't assume", "Fabricates lead_ids when seeding the campaign instead of using the ids returned by tour_plan"] },
|
|
24861
27382
|
leadbay_prospecting_overview: { "name": "leadbay_prospecting_overview", "short_description": `Orientation for working with Leadbay from any host \u2014 discovery vs.
|
|
24862
27383
|
follow-up, the outreach loop, outcome recording, imports, pushback /
|
|
@@ -24881,6 +27402,7 @@ var PROMPT_CATALOG_BULLETS = {
|
|
|
24881
27402
|
leadbay_getting_started: `- \`leadbay_getting_started\`: Guided first-run walkthrough \u2014 four clicks that actually use Leadbay: check the account, pull today's leads, draft a first email to the top one, then reveal who to send it to. Use when the user is new or asks to be SHOWN how Leadbay works ("walk me through Leadbay", "I'm new", "how do I use this", "give me a tour"). Don't use it for orientation prose with no clicking \u2014 that's leadbay_prospecting_overview.`,
|
|
24882
27403
|
leadbay_import_file: `- \`leadbay_import_file\` (optional args: file, instruction): Import a user-supplied CSV/file into Leadbay through five phases with evidence gates \u2014 scan, derive, resolve identities, preserve & commit, then optionally qualify and report. The job is to maximize how many rows the Leadbay system actually ingests and matches.`,
|
|
24883
27404
|
leadbay_log_outreach: `- \`leadbay_log_outreach\` (required args: lead_id, summary): Log outreach (an email I sent, a call I made, a meeting I had) on a specific lead. Captures verification so the SDR pipeline trusts the entry.`,
|
|
27405
|
+
leadbay_new_leads: `- \`leadbay_new_leads\` (optional args: need): Guided net-new lead delivery \u2014 turn a described need ("gyms around Dallas that would buy our flooring") into ICP-perfect NEW companies with qualification evidence and the right contact, via leadbay_find_new_leads. Trigger when the user DESCRIBES who they want: "get me N companies that <profile>", "we're entering <market>". A bare "find me new leads" with no profile, and "today's leads", are the daily lens batch \u2014 leadbay_pull_leads. "Qualify these companies I have" is leadbay_qualify_leads.`,
|
|
24884
27406
|
leadbay_plan_tour_in_city: `- \`leadbay_plan_tour_in_city\` (required args: city; optional args: date): Use whenever the user names a city they'll be in and asks who to see \u2014 "I'm in SF next Tuesday, who's worth meeting?", "I'm going to Berlin \u2014 who should I visit?", "plan my <city> tour". Any in-person/visit intent tied to a place routes here, NOT to \`leadbay_pull_leads\`. It surfaces follow-ups + fresh Discover leads in the city via \`leadbay_tour_plan\`, ALWAYS offers to plot them on a map (rendering it on yes), then offers outreach drafts + campaign persistence.`,
|
|
24885
27407
|
leadbay_prospecting_overview: `- \`leadbay_prospecting_overview\`: Orientation for working with Leadbay from any host \u2014 discovery vs. follow-up, the outreach loop, outcome recording, imports, pushback / snooze, and the connected-outreach-tool registry. Trigger when the conversation involves Leadbay leads, prospecting, pipeline, follow-up, outreach, or lens / ICP \u2014 anything from "show me my leads" to "what should I follow up on" to "I'll send via lemlist".`,
|
|
24886
27408
|
leadbay_qualify_top_n: `- \`leadbay_qualify_top_n\` (optional args: count): Bulk-qualify the top N un-qualified leads in the active lens. Uses leadbay_bulk_qualify_leads with a sensible default budget.`,
|
|
@@ -24892,8 +27414,8 @@ var PROMPT_CATALOG_BULLETS = {
|
|
|
24892
27414
|
};
|
|
24893
27415
|
|
|
24894
27416
|
// src/prompts.ts
|
|
24895
|
-
function userMessage(
|
|
24896
|
-
return { role: "user", content: { type: "text", text } };
|
|
27417
|
+
function userMessage(text2) {
|
|
27418
|
+
return { role: "user", content: { type: "text", text: text2 } };
|
|
24897
27419
|
}
|
|
24898
27420
|
function substitutePlaceholders(body, substitutions) {
|
|
24899
27421
|
let out = body;
|
|
@@ -24920,6 +27442,18 @@ var CATALOG = [
|
|
|
24920
27442
|
arguments: promptArguments("leadbay_prospecting_overview"),
|
|
24921
27443
|
render: () => [userMessage(leadbay_prospecting_overview)]
|
|
24922
27444
|
},
|
|
27445
|
+
{
|
|
27446
|
+
name: "leadbay_new_leads",
|
|
27447
|
+
description: PROMPT_META.leadbay_new_leads.short_description,
|
|
27448
|
+
arguments: promptArguments("leadbay_new_leads"),
|
|
27449
|
+
render: (args) => [
|
|
27450
|
+
userMessage(
|
|
27451
|
+
substitutePlaceholders(leadbay_new_leads, {
|
|
27452
|
+
need: args.need ?? "(not provided \u2014 ask me first)"
|
|
27453
|
+
})
|
|
27454
|
+
)
|
|
27455
|
+
]
|
|
27456
|
+
},
|
|
24923
27457
|
{
|
|
24924
27458
|
name: "leadbay_research_a_domain",
|
|
24925
27459
|
description: PROMPT_META.leadbay_research_a_domain.short_description,
|
|
@@ -25078,18 +27612,38 @@ var CATALOG = [
|
|
|
25078
27612
|
render: () => [userMessage(leadbay_getting_started2)]
|
|
25079
27613
|
}
|
|
25080
27614
|
];
|
|
25081
|
-
|
|
27615
|
+
var GATED_PROMPTS = {
|
|
27616
|
+
// Needs the write surface: every phase calls leadbay_find_new_leads /
|
|
27617
|
+
// leadbay_qualify_leads, which are write-tier, so a read-only server
|
|
27618
|
+
// (LEADBAY_MCP_WRITE=0) would offer a workflow whose tools are absent from
|
|
27619
|
+
// tools/list. The backend-rollout half of this gate is gone — the
|
|
27620
|
+
// /1.6/mcp/* routes shipped in backend v3.22.0.
|
|
27621
|
+
leadbay_new_leads: (opts) => opts.includeWrite !== false
|
|
27622
|
+
};
|
|
27623
|
+
function listAllPrompts() {
|
|
25082
27624
|
return CATALOG.map((c) => ({
|
|
25083
27625
|
name: c.name,
|
|
25084
27626
|
description: c.description,
|
|
25085
27627
|
arguments: c.arguments
|
|
25086
27628
|
}));
|
|
25087
27629
|
}
|
|
25088
|
-
function
|
|
27630
|
+
function listPrompts(opts = {}) {
|
|
27631
|
+
return listAllPrompts().filter((p) => {
|
|
27632
|
+
const gate = GATED_PROMPTS[p.name];
|
|
27633
|
+
return gate ? gate(opts) : true;
|
|
27634
|
+
});
|
|
27635
|
+
}
|
|
27636
|
+
function getPrompt(name, args = {}, opts = {}) {
|
|
25089
27637
|
const entry = CATALOG.find((c) => c.name === name);
|
|
25090
27638
|
if (!entry) {
|
|
25091
27639
|
throw new Error(`Unknown prompt: ${name}`);
|
|
25092
27640
|
}
|
|
27641
|
+
const gate = GATED_PROMPTS[name];
|
|
27642
|
+
if (gate && !gate(opts)) {
|
|
27643
|
+
throw new Error(
|
|
27644
|
+
`Prompt ${name} is not enabled in this deployment (requires the write surface \u2014 LEADBAY_MCP_WRITE must not be 0).`
|
|
27645
|
+
);
|
|
27646
|
+
}
|
|
25093
27647
|
const missing = entry.arguments.filter((a) => a.required && (args[a.name] === void 0 || args[a.name] === "")).map((a) => a.name);
|
|
25094
27648
|
if (missing.length > 0) {
|
|
25095
27649
|
throw new Error(
|
|
@@ -25978,8 +28532,22 @@ function buildProtocolPrimitivesParagraph(has) {
|
|
|
25978
28532
|
"import_and_qualify",
|
|
25979
28533
|
"enrich_titles",
|
|
25980
28534
|
"bulk_enrich_status",
|
|
25981
|
-
"qualify_status"
|
|
28535
|
+
"qualify_status",
|
|
28536
|
+
// The MCP-first delivery jobs block-poll for 45s by default and up to
|
|
28537
|
+
// 180s. Without a progressToken ctx.progress is absent, so the call looks
|
|
28538
|
+
// frozen for minutes — the exact case this paragraph exists to prevent.
|
|
28539
|
+
// `.filter(has)` keeps the iter-12 invariant: a deployment without the
|
|
28540
|
+
// delivery flag never sees them named.
|
|
28541
|
+
"find_new_leads",
|
|
28542
|
+
"qualify_leads",
|
|
28543
|
+
"lead_job_status"
|
|
25982
28544
|
].filter((n) => has(`leadbay_${n}`));
|
|
28545
|
+
const legacyRunners = longRunners.filter(
|
|
28546
|
+
(n) => !["find_new_leads", "qualify_leads", "lead_job_status"].includes(n)
|
|
28547
|
+
);
|
|
28548
|
+
const deliveryRunners = longRunners.filter(
|
|
28549
|
+
(n) => ["find_new_leads", "qualify_leads", "lead_job_status"].includes(n)
|
|
28550
|
+
);
|
|
25983
28551
|
const elicitTools = [
|
|
25984
28552
|
"refine_prompt clarifications",
|
|
25985
28553
|
"report_outreach.user_confirmed"
|
|
@@ -25998,9 +28566,20 @@ function buildProtocolPrimitivesParagraph(has) {
|
|
|
25998
28566
|
"(1) `notifications/progress` \u2014 when you pass `_meta.progressToken` on a tools/call, long-running composites stream per-unit-of-work progress (none of the long-runners are currently exposed in this configuration)."
|
|
25999
28567
|
);
|
|
26000
28568
|
}
|
|
26001
|
-
if (
|
|
28569
|
+
if (legacyRunners.length > 0 || deliveryRunners.length > 0) {
|
|
28570
|
+
const clauses = [];
|
|
28571
|
+
if (legacyRunners.length > 0) {
|
|
28572
|
+
clauses.push(
|
|
28573
|
+
"On " + legacyRunners.map((n) => `leadbay_${n}`).join(", ") + " the job itself keeps running on the backend; poll its notification_id / importIds later to pick it up."
|
|
28574
|
+
);
|
|
28575
|
+
}
|
|
28576
|
+
if (deliveryRunners.length > 0) {
|
|
28577
|
+
clauses.push(
|
|
28578
|
+
"On " + deliveryRunners.map((n) => `leadbay_${n}`).join(", ") + " the job is BACKEND-owned and likewise keeps running. Any work already paid for still completes; poll `leadbay_lead_job_status` with the `job_id` later to collect it."
|
|
28579
|
+
);
|
|
28580
|
+
}
|
|
26002
28581
|
parts.push(
|
|
26003
|
-
"(2) `notifications/cancelled` \u2014 when the user clicks Cancel in the host UI, the polling loop exits within \u22642 seconds.
|
|
28582
|
+
"(2) `notifications/cancelled` \u2014 when the user clicks Cancel in the host UI, the polling loop exits within \u22642 seconds. " + clauses.join(" ")
|
|
26004
28583
|
);
|
|
26005
28584
|
} else {
|
|
26006
28585
|
parts.push(
|
|
@@ -26207,11 +28786,16 @@ function buildServer(client, opts = {}) {
|
|
|
26207
28786
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
26208
28787
|
tools: toolsListPayload([...toolByName.values()])
|
|
26209
28788
|
}));
|
|
28789
|
+
const promptGate = { includeWrite: Boolean(opts.includeWrite) };
|
|
26210
28790
|
server.setRequestHandler(ListPromptsRequestSchema, async () => ({
|
|
26211
|
-
prompts: listPrompts()
|
|
28791
|
+
prompts: listPrompts(promptGate)
|
|
26212
28792
|
}));
|
|
26213
28793
|
server.setRequestHandler(GetPromptRequestSchema, async (req) => {
|
|
26214
|
-
return getPrompt(
|
|
28794
|
+
return getPrompt(
|
|
28795
|
+
req.params.name,
|
|
28796
|
+
req.params.arguments ?? {},
|
|
28797
|
+
promptGate
|
|
28798
|
+
);
|
|
26215
28799
|
});
|
|
26216
28800
|
server.setRequestHandler(ListResourcesRequestSchema, async () => ({
|
|
26217
28801
|
resources: listResources()
|
|
@@ -27291,8 +29875,8 @@ async function removeDxtExtension(claudeSupportDir) {
|
|
|
27291
29875
|
}
|
|
27292
29876
|
|
|
27293
29877
|
// installer/install-wizard.ts
|
|
27294
|
-
function ansi(
|
|
27295
|
-
return enabled ? `\x1B[${code}m${
|
|
29878
|
+
function ansi(text2, code, enabled) {
|
|
29879
|
+
return enabled ? `\x1B[${code}m${text2}\x1B[0m` : text2;
|
|
27296
29880
|
}
|
|
27297
29881
|
function parseInstallSelection(input, clientCount) {
|
|
27298
29882
|
const normalized = input.trim().toLowerCase();
|
|
@@ -27656,7 +30240,7 @@ async function createDefaultUpdateStateStore(opts = {}) {
|
|
|
27656
30240
|
}
|
|
27657
30241
|
|
|
27658
30242
|
// src/oauth.ts
|
|
27659
|
-
import { createHash as
|
|
30243
|
+
import { createHash as createHash5, randomBytes } from "crypto";
|
|
27660
30244
|
import { createServer } from "http";
|
|
27661
30245
|
import { request as httpsRequestRaw } from "https";
|
|
27662
30246
|
import { spawn as spawn3 } from "child_process";
|
|
@@ -27721,7 +30305,7 @@ async function inferRegionViaStargate(opts) {
|
|
|
27721
30305
|
function generatePkce() {
|
|
27722
30306
|
const verifier = base64UrlEncode(randomBytes(32));
|
|
27723
30307
|
const challenge = base64UrlEncode(
|
|
27724
|
-
|
|
30308
|
+
createHash5("sha256").update(verifier, "ascii").digest()
|
|
27725
30309
|
);
|
|
27726
30310
|
return { verifier, challenge, method: "S256" };
|
|
27727
30311
|
}
|
|
@@ -28203,7 +30787,7 @@ var OAUTH_BASE_URLS = {
|
|
|
28203
30787
|
fr: "https://staging.api.leadbay.app"
|
|
28204
30788
|
}
|
|
28205
30789
|
};
|
|
28206
|
-
var VERSION = "0.
|
|
30790
|
+
var VERSION = "0.37.0";
|
|
28207
30791
|
var HELP = `
|
|
28208
30792
|
leadbay-mcp ${VERSION} \u2014 Leadbay Model Context Protocol server
|
|
28209
30793
|
|
|
@@ -28678,8 +31262,8 @@ function parseFlag(args, name) {
|
|
|
28678
31262
|
function hasFlag(args, name) {
|
|
28679
31263
|
return args.some((a) => a === `--${name}`);
|
|
28680
31264
|
}
|
|
28681
|
-
function ansi2(
|
|
28682
|
-
return enabled ? `\x1B[${code}m${
|
|
31265
|
+
function ansi2(text2, code, enabled) {
|
|
31266
|
+
return enabled ? `\x1B[${code}m${text2}\x1B[0m` : text2;
|
|
28683
31267
|
}
|
|
28684
31268
|
function isInteractiveInstall() {
|
|
28685
31269
|
return process.stdin.isTTY === true && process.stdout.isTTY === true;
|