@leadbay/mcp 0.22.0 → 0.23.1
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 +18 -0
- package/dist/bin.js +1093 -81
- package/dist/http-server.js +925 -6
- package/dist/installer-electron.js +59 -21
- package/dist/installer-gui.js +59 -21
- package/package.json +1 -1
package/dist/http-server.js
CHANGED
|
@@ -33,6 +33,204 @@ import {
|
|
|
33
33
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
34
34
|
|
|
35
35
|
// src/prompts.generated.ts
|
|
36
|
+
var leadbay_build_campaign = `
|
|
37
|
+
## MEMORY
|
|
38
|
+
|
|
39
|
+
Before responding, glance at any \`_meta.agent_memory.summary\` returned by tool calls earlier in this session and reflect its top signals in your reasoning ("Filtering by your stated preference for healthcare"). After any material new signal from the user this conversation (sector, region, deal size, communication style, qualification rule, explicit retraction, or recurrence / scheduling preference such as "I do this every day" or "remind me every morning"), call \`leadbay_agent_memory_capture\` to persist it: \`source:"user_stated"\` if literal, \`source:"inferred"\` with confidence <=6 if inferred.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
Build me a Leadbay campaign from scratch{{arg:campaign_name_paren}}. {{arg:audience_block}}
|
|
43
|
+
|
|
44
|
+
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.
|
|
45
|
+
|
|
46
|
+
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.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# Resilience rules for Leadbay long-running tools
|
|
50
|
+
|
|
51
|
+
These four rules apply to every Leadbay workflow that calls \`leadbay_pull_leads\`, \`leadbay_bulk_qualify_leads\`, \`leadbay_research_lead_by_id\`, \`leadbay_import_and_qualify\`, or \`leadbay_enrich_titles\`. **Treat timeouts and stream-closed errors as transient, not as signals to replan.**
|
|
52
|
+
|
|
53
|
+
## Rule 1 \u2014 Pin the lens
|
|
54
|
+
|
|
55
|
+
After your first \`leadbay_pull_leads\` call, capture \`response.lens.id\` into your working memory and **pass it explicitly as the \`lensId\` argument to every subsequent call** in this session \u2014 including any re-pulls, bulk qualifies, or research calls that accept it. (Field-name caveat: the response nests it as \`lens.id\`; the parameter on subsequent calls is \`lensId\`.) The active lens can shift between calls (5-minute client cache + backend \`last_requested_lens\` can change if the user touches the web UI). A lens shift mid-workflow throws away your top-10 work.
|
|
56
|
+
|
|
57
|
+
## Rule 2 \u2014 Prefer async for bulk operations
|
|
58
|
+
|
|
59
|
+
\`leadbay_bulk_qualify_leads\` and \`leadbay_import_and_qualify\` accept \`wait_for_completion:false\`, which returns \`{status:'running', qualify_id}\` immediately. Then poll \`leadbay_qualify_status\` (or \`leadbay_import_status\`) every ~10s until the job completes. **Use the async pattern by default** \u2014 the blocking default can exceed the MCP client's per-call timeout on large batches and produce a misleading \`"Request timed out"\` even though the server is still working.
|
|
60
|
+
|
|
61
|
+
## Rule 3 \u2014 Serialize \`leadbay_research_lead_by_id\` fan-out
|
|
62
|
+
|
|
63
|
+
\`leadbay_research_lead_by_id\` is composite and reads many sub-resources. Calling it on 10 leads in parallel can saturate the transport and produce \`"Tool permission stream closed"\` errors that look like permission failures but are really backpressure. **Call it sequentially**, or at most 3 in parallel. If one call fails with a stream/timeout error, retry that one call once before moving on; on a second failure, note the lead and continue \u2014 do not abandon the remaining leads.
|
|
64
|
+
|
|
65
|
+
## Rule 4 \u2014 Retry, don't replan
|
|
66
|
+
|
|
67
|
+
If a Leadbay tool returns \`"Request timed out"\`, \`"stream closed"\`, or any other transport-level error (distinct from a Leadbay-issued error payload), the work may still be running server-side. Do this in order:
|
|
68
|
+
|
|
69
|
+
1. For bulk tools \u2014 retry with \`wait_for_completion:false\` and poll the status tool with the returned id. Don't re-pull leads; that can shift the lens.
|
|
70
|
+
2. For single-lead tools \u2014 retry the same call once. If it still fails, record the lead id and continue with the rest of the workflow.
|
|
71
|
+
3. **Do not** switch strategies (e.g. "the endpoint is broken, let me re-pull from scratch"). The earlier work is still valid; the timeout was the wire.
|
|
72
|
+
|
|
73
|
+
If \`pull_leads\` itself fails and you have no prior batch, then yes \u2014 retry it, explicitly pass the lensId you captured (if any), and continue.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# PHASE 0 \u2014 STATE + AUDIENCE
|
|
77
|
+
|
|
78
|
+
Call \`leadbay_account_status\` to see my remaining quota, my **enrichment credits**, and my **active lens**. Note \`web_fetch_remaining\` (qualification budget) and the enrichment credit balance \u2014 Phase 3 spends credits.
|
|
79
|
+
|
|
80
|
+
Resolve the audience:
|
|
81
|
+
|
|
82
|
+
- **Default \u2014 use my active lens.** If I didn't name a fresh audience, the active lens IS the audience. Do NOT create a new lens.
|
|
83
|
+
- **Fresh-audience fork.** Only if I described a NEW audience the active lens doesn't already cover, set it up first: \`leadbay_adjust_audience\` for sector/size tweaks, or \`leadbay_new_lens\` to create a brand-new named lens \u2014 then continue on that lens. Do NOT silently overwrite my existing lens; confirm once before switching.
|
|
84
|
+
|
|
85
|
+
# PHASE 1 \u2014 DISCOVER
|
|
86
|
+
|
|
87
|
+
Call \`leadbay_pull_leads\` on the resolved lens. **Capture \`response.lens.id\` and pass it as an explicit \`lensId\` on every later call this session** \u2014 a mid-session lens shift would discard the cohort I'm about to pick. Render the batch with the canonical layout:
|
|
88
|
+
|
|
89
|
+
## RENDERING \u2014 markdown table, three columns, score-bar driven
|
|
90
|
+
|
|
91
|
+
Present the response as a markdown table sorted by \`score\` descending, with exactly three columns. Do not summarize in prose. Do not show the numeric score anywhere.
|
|
92
|
+
|
|
93
|
+
## Score-bar (10-segment, inline-code wrapped)
|
|
94
|
+
|
|
95
|
+
Wrap a 10-glyph bar in a SINGLE inline-code span (backticks). The inline-code styling is what gives the bar contrast in most chat renderers \u2014 HTML \`<span>\` is stripped inside table cells.
|
|
96
|
+
|
|
97
|
+
Glyphs (use these exact characters; do not substitute):
|
|
98
|
+
|
|
99
|
+
- \`\u25B0\` \u2014 firmographic-only fill
|
|
100
|
+
- \`\u2756\` \u2014 AI-booster cap (placed at the RIGHT END of the filled run, never the front)
|
|
101
|
+
- \`\u25B1\` \u2014 empty
|
|
102
|
+
|
|
103
|
+
Computation:
|
|
104
|
+
|
|
105
|
+
\`\`\`
|
|
106
|
+
total_filled = round(score / 10), clamped to 0..10
|
|
107
|
+
ai_segments = round(qualification_summary.avg_qualification_boost / 3.3),
|
|
108
|
+
clamped to [0, total_filled]
|
|
109
|
+
normal_filled = total_filled \u2212 ai_segments
|
|
110
|
+
bar = "\u25B0" \xD7 normal_filled
|
|
111
|
+
+ "\u2756" \xD7 ai_segments
|
|
112
|
+
+ "\u25B1" \xD7 (10 \u2212 total_filled)
|
|
113
|
+
\`\`\`
|
|
114
|
+
|
|
115
|
+
If \`qualification_summary.answered == 0\` or \`avg_qualification_boost\` is null, set \`ai_segments = 0\` (no \u2756). Always wrap the bar in backticks. Print the legend \`\` \`\u25B0\` firmographic \xB7 \`\u2756\` AI booster cap \xB7 \`\u25B1\` unfilled \`\` once below the table.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
**Column 1 \u2014 Company**
|
|
119
|
+
|
|
120
|
+
- Line 1: the 10-segment score bar in inline-code backticks (see the score-bar snippet above for the algorithm).
|
|
121
|
+
- Insert \`<br>\` between lines.
|
|
122
|
+
- Line 2: linked company name + \` \xB7 \` + short location + \` \xB7 \` + compact size.
|
|
123
|
+
- Link target: \`website\` (prefix \`https://\` if it's a bare hostname). Don't synthesize an app deep-link.
|
|
124
|
+
- Location: shorten "City of New York" \u2192 "NYC"; otherwise "City ST"; state alone only when city missing.
|
|
125
|
+
- Size: \`"Xk+"\` when \`size.min >= 1000\`, \`"min\u2013max"\` otherwise.
|
|
126
|
+
|
|
127
|
+
**Column 2 \u2014 Why it fits**
|
|
128
|
+
|
|
129
|
+
- One sentence, \u2264 20 words.
|
|
130
|
+
- Synthesize from (in priority order, whichever is present) the lead's \`short_description\`, top 2 \`tags[].display_name\`, and the gist of \`qualification_summary.best_response_excerpt\`. The trim payload does NOT carry the longer \`description\` field \u2014 for that, agent must call \`leadbay_research_lead_by_id\` or \`leadbay_research_lead_by_name_fuzzy\`.
|
|
131
|
+
- Do NOT append \`(boost N)\` \u2014 the \u2756 cap in column 1 already carries that signal.
|
|
132
|
+
- No bullet lists, no line breaks inside the cell.
|
|
133
|
+
|
|
134
|
+
**Column 3 \u2014 Contact**
|
|
135
|
+
|
|
136
|
+
\`[Contact name](LINK) \xB7 short job title\`. The \`[Contact name](LINK)\` markdown link wrapping is mandatory \u2014 never render the name as plain text. See linking/contact-linkedin for the URL priority (real profile \u2192 constructed people-search) and the \xB0-flag fallback.
|
|
137
|
+
|
|
138
|
+
**Hide from the user (never include in any cell):** \`id\`, \`location.pos\`, \`location.country\` (unless city/state both missing), \`sector_id\`, \`is_hq\`, \`web_fetch_in_progress\`, \`enrichment_in_progress\`, \`highlighted_fields\`, \`custom_fields\`, \`contacts_count\` when 0, \`notes_count\` / \`epilogue_actions_count\` / \`prospecting_actions_count\` when 0, \`stale_at\`, \`deal_insights\`, \`social_presence\` booleans (except as the \xB0-flag signal), \`need_attention\` flags, any field whose value is the string \`"null"\`.
|
|
139
|
+
|
|
140
|
+
## Linking a contact's name
|
|
141
|
+
|
|
142
|
+
**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.**
|
|
143
|
+
|
|
144
|
+
URL priority (first applicable wins):
|
|
145
|
+
|
|
146
|
+
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).
|
|
147
|
+
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.
|
|
148
|
+
|
|
149
|
+
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.
|
|
150
|
+
|
|
151
|
+
## Linking the company
|
|
152
|
+
|
|
153
|
+
Use the lead's \`website\` as the company-name link target \u2014 prefix \`https://\` if the value is a bare hostname. (The MCP does NOT synthesize a Leadbay-app deep-link URL; the team has not standardized one. Linking to \`website\` is always real data.)
|
|
154
|
+
|
|
155
|
+
When the response carries \`social_urls\` (the post-fix multi-platform URL block on rich-lead responses), render every non-null platform as a pill chip in the company-info row. Iterate over \`social_urls\`'s keys \u2014 never hardcode a fixed list \u2014 and emit each as \`[<platform-label>](<url>)\`. Skip platforms whose URL is null.
|
|
156
|
+
|
|
157
|
+
\`social_presence\` carries booleans for the same 6 platforms (crunchbase, facebook, instagram, linkedin, tiktok, twitter) \u2014 useful when you only care that the company has a profile somewhere. Use it as the \xB0-flag signal in the contact people-search fallback (see linking/contact-linkedin).
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
If the batch is thin (fewer than ~10 workable leads) or I ask for more depth, top it up: call \`leadbay_bulk_qualify_leads({lensId:<captured>, count:<deficit, max 25>, wait_for_completion:false})\`, poll \`leadbay_qualify_status\` until done, then re-pull with the same \`lensId\`. Never re-pull without \`lensId\`.
|
|
162
|
+
|
|
163
|
+
# PHASE 2 \u2014 PICK AN ICP CANDIDATE POOL
|
|
164
|
+
|
|
165
|
+
A campaign is only as good as the leads in it \u2014 AND only as good as whether each lead has a reachable BUYER (see Phase 3). So pick a **generous candidate pool** now, not the final cohort: aim for ~1.5\xD7 the target size of in-ICP leads (highest \`ai_agent_lead_score\`), so Phase 3 can drop any lead that turns out to have no buyer-persona contact and still hit the target. If the batch is short, top up via \`leadbay_bulk_qualify_leads\` / \`leadbay_extend_lens\`.
|
|
166
|
+
|
|
167
|
+
If I named specific leads, use those (but still apply the Phase 3 buyer-coverage check and tell me which lack a buyer). Otherwise recommend the pool and show it. Capture the candidate \`leadIds\`. Confirm the count ("12 candidates \u2014 I'll lock the final ~8 after checking each has a buyer"). Do NOT create the campaign yet \u2014 the final cohort is decided after Phase 3's coverage check.
|
|
168
|
+
|
|
169
|
+
# PHASE 3 \u2014 ENRICH THE RIGHT CONTACTS (load-bearing)
|
|
170
|
+
|
|
171
|
+
This is the phase that decides whether the campaign is worth a salesperson's time. Contacts aren't attached by default and enrichment is paid \u2014 so spend it ONLY on the people who would actually **buy what I sell**, not on whoever is most senior.
|
|
172
|
+
|
|
173
|
+
**Step A \u2014 work out MY buyer persona (do this before touching titles).**
|
|
174
|
+
Figure out what *I* sell and therefore who, inside the target company, owns the decision to buy it:
|
|
175
|
+
|
|
176
|
+
- Infer my product / value-prop from my context: my org and account (\`leadbay_account_status\`), and especially my lens's qualification criteria \u2014 the \`qualification_summary\` on the leads tells you *why* these companies are good targets for me, which implies what I'm offering them.
|
|
177
|
+
- Map value-prop \u2192 the **buying department/persona**, NOT seniority:
|
|
178
|
+
- A sales / prospecting / lead-gen / outbound / marketing / GTM / revenue tool \u2192 the **revenue org**: VP / Head / Director of Sales, Business Development, Account/Carrier Sales, CRO, CMO / VP Marketing, Head of Growth / Demand Gen, RevOps. (This is Leadbay's own persona.)
|
|
179
|
+
- An operations / logistics tool \u2192 operations leaders. A finance tool \u2192 finance. A dev tool \u2192 engineering. Etc.
|
|
180
|
+
- **Company size caveat:** Founder / CEO / Owner is a real buyer at small companies (\u2264~50), but at larger ones they are not \u2014 there the functional leader (e.g. VP Sales) is the buyer.
|
|
181
|
+
- **State the persona in one line and confirm it with me** before spending (see Step C). I can correct it.
|
|
182
|
+
|
|
183
|
+
**ANTI-PATTERN \u2014 do NOT do this:** picking the most senior or most "decision-maker-sounding" title regardless of department. A Director of Operations, COO, Mgr of Logistics, CFO, or CTO will **never** buy a sales tool \u2014 enriching them wastes credits and hands me a useless list. Seniority is not the same as being my buyer.
|
|
184
|
+
|
|
185
|
+
**Step B \u2014 find the persona-matching, enrichable contacts.**
|
|
186
|
+
Call \`leadbay_recall_ordered_titles({leadIds, lensId})\` and \`leadbay_enrich_titles({leadIds, lensId})\` in **discovery mode** (no \`titles\`). These return previously-enriched titles, \`title_suggestions\`, \`auto_included_titles\`, \`available_in_selection\`, \`enrichable_contacts\`, and \`credits_remaining\`. Treat them as a **menu to filter against my persona \u2014 not the answer.** If past-enriched titles or suggestions are off-persona (e.g. operations roles for a sales tool), do NOT repeat them. Select the titles that match my buyer persona AND are actually enrichable.
|
|
187
|
+
|
|
188
|
+
**Step B.5 \u2014 coverage guarantee (lock the final cohort here).** A campaign where half the leads have no buyer is a failed campaign. So before enriching, determine for each candidate lead whether it actually has an **enrichable buyer-persona contact** \u2014 use the discovery data plus, where it's ambiguous, a quick \`leadbay_research_lead_by_id\` to see that lead's available contact titles. Then:
|
|
189
|
+
|
|
190
|
+
- **KEEP** candidates that have \u22651 enrichable buyer-persona contact.
|
|
191
|
+
- **SWAP OUT** candidates whose only contacts are off-persona (e.g. ops/dispatch/finance only) or who have no enrichable contact at all. Replace each with the **highest-\`ai_agent_lead_score\` in-ICP candidate** from the pool that DOES have a buyer, until the cohort hits the target size (default 20; here capped by the enrichment budget).
|
|
192
|
+
- **Do NOT trade ICP fit for coverage.** A lead with a buyer but weak ICP fit (low \`ai_agent_lead_score\`, a vertical that doesn't match what I sell) is still the wrong lead \u2014 coverage is a filter applied AFTER ICP, never a reason to admit an off-ICP company. The final cohort must be both high-ICP AND buyer-covered.
|
|
193
|
+
- If the lens genuinely can't supply enough buyer-ready, in-ICP leads, say so honestly and offer to widen/extend rather than padding the campaign with no-buyer leads OR with off-ICP ones.
|
|
194
|
+
|
|
195
|
+
Tell me what you swapped in one line ("dropped Corbett + RBS \u2014 ops-only; swapped in Acme + Globex which have Sales VPs"). The goal is a final cohort where EVERY lead has a real buyer to call.
|
|
196
|
+
|
|
197
|
+
**Step C \u2014 show the spend + persona and confirm.** State the persona, the chosen titles, and "You have {credits_remaining} credits; this enriches {enrichable_contacts} contacts." Confirm via \`ask_user_input_v0\` ("Enrich these {enrichable_contacts} <persona> contacts now?" \u2192 ["Yes, enrich", "No, skip", "Change the persona/titles"]). Never launch a paid run without this. Enrich up to the campaign size (default 20) best persona-matching contacts.
|
|
198
|
+
|
|
199
|
+
**Step D \u2014 launch + poll.** On yes: \`leadbay_enrich_titles({leadIds, lensId, titles:[...chosen], email:true, phone:true})\` to launch, then poll \`leadbay_bulk_enrich_status\` until done (enrichment can take several minutes \u2014 keep polling, don't render an empty sheet prematurely). Append one small line at the very end of your reply: \`_(N credits remaining)_\`.
|
|
200
|
+
|
|
201
|
+
If I skip enrichment, continue \u2014 the campaign can be enriched later from the call sheet.
|
|
202
|
+
|
|
203
|
+
# PHASE 4 \u2014 CREATE THE CAMPAIGN
|
|
204
|
+
|
|
205
|
+
Derive a name (\`<lens or audience> \u2013 <today's date>\`) or use the one I gave. Call \`leadbay_create_campaign({name, lead_ids:<final buyer-ready cohort from Phase 3>})\` \u2014 this creates AND seeds in one call. Seed the cohort you actually enriched buyers on, not the original raw pool. Confirm the returned campaign name + id in one line. (If I later ask to add more leads to it, that's \`leadbay_add_leads_to_campaign\`.)
|
|
206
|
+
|
|
207
|
+
# PHASE 5 \u2014 THE VIEW (call / email ready)
|
|
208
|
+
|
|
209
|
+
If you launched enrichment in Phase 3, **poll \`leadbay_bulk_enrich_status\` until it's actually done before rendering** \u2014 do not render a "still enriching" sheet with empty contact cells; the whole point is the landed phones/emails. Enrichment can take several minutes; keep polling.
|
|
210
|
+
|
|
211
|
+
Then call \`leadbay_campaign_call_sheet({campaign_id})\` and render it per its RENDERING block \u2014 one card per lead, contacts with \`[phone](tel:)\` + \`[email](mailto:)\` one-tap links, the readiness chip at the top, map optional. This is the view I work from: scan \u2192 tap to call \u2192 tap to email.
|
|
212
|
+
|
|
213
|
+
**Flag suspect contacts** so I don't email the wrong person blind: mark with \u26A0 any enriched contact whose email domain doesn't match the company's website, or who shows up on more than one lead in this campaign (a sign of a mis-attributed enrichment). Keep the phone (it's usually still right) but tell me the email looks off.
|
|
214
|
+
|
|
215
|
+
# PHASE 6 \u2014 HANDOFF + STOP
|
|
216
|
+
|
|
217
|
+
The campaign exists and is call/email ready. End by offering, via \`ask_user_input_v0\`:
|
|
218
|
+
|
|
219
|
+
- "Start working it now" \u2192 run \`leadbay_work_campaign\` on this campaign (the calling/email session + outcome-logging loop).
|
|
220
|
+
- "See the pulse" \u2192 \`leadbay_campaign_progression\` for per-lead status.
|
|
221
|
+
|
|
222
|
+
Then STOP. Building a campaign is NOT outreaching \u2014 do not send anything and do not call \`leadbay_report_outreach\`. When I come back later to log calls, see previous statuses, and do follow-ups, that is \`leadbay_work_campaign\`, not this prompt.
|
|
223
|
+
|
|
224
|
+
# Iron laws
|
|
225
|
+
|
|
226
|
+
- Enrichment targets MY buyer persona \u2014 the people who would actually buy what *I* sell, derived from my product/ICP \u2014 NOT generic seniority. For a sales/prospecting tool that means the revenue org (sales / BD / growth / marketing leaders); a Director of Operations, COO, or logistics manager is useless no matter how senior. Get the persona right or the campaign is worthless.
|
|
227
|
+
- Selection is DATA-DRIVEN (\`leadbay_recall_ordered_titles\` + \`leadbay_enrich_titles\` discovery) but FILTERED to the persona \u2014 never blindly repeat past-enriched or suggested titles that don't match who buys my product.
|
|
228
|
+
- The FINAL cohort must be all buyer-ready: drop/swap any lead with no enrichable buyer-persona contact (Phase 3 Step B.5) rather than shipping it empty. A campaign where half the leads have no buyer to call is a failed campaign. Pick a generous pool in Phase 2 so swaps are possible.
|
|
229
|
+
- NEVER launch paid enrichment without showing \`credits_remaining\` + \`enrichable_contacts\`, naming the persona, and getting a yes.
|
|
230
|
+
- Qualify / pick BEFORE \`leadbay_create_campaign\` \u2014 never seed a campaign with unvetted leads.
|
|
231
|
+
- Carry the captured \`lensId\` on every call. A lens shift loses the cohort.
|
|
232
|
+
- End at the rendered call sheet, then hand off to \`leadbay_work_campaign\`. Do NOT re-implement the calling / follow-up loop here, and do NOT call \`leadbay_report_outreach\`.
|
|
233
|
+
`;
|
|
36
234
|
var leadbay_daily_check_in = `
|
|
37
235
|
## MEMORY
|
|
38
236
|
|
|
@@ -1057,6 +1255,7 @@ Optional: offer to review the \`leadbay_campaign_progression\` for the same camp
|
|
|
1057
1255
|
- If the user dictates an outcome that doesn't cleanly map to one of the four epilogue values, ASK ONCE before guessing.
|
|
1058
1256
|
`;
|
|
1059
1257
|
var PROMPT_META = {
|
|
1258
|
+
leadbay_build_campaign: { "name": "leadbay_build_campaign", "short_description": 'Build a sales campaign from scratch in one guided flow: discover on the\nactive lens, qualify and pick a cohort, enrich the contacts most likely to\nengage, save it via `leadbay_create_campaign`, then show a one-tap call/email\nview via `leadbay_campaign_call_sheet`. Trigger on "build me a campaign",\n"set up a new campaign", "create a campaign from scratch". WORK an existing\ncampaign with `leadbay_work_campaign`; split leads across reps with\n`leadbay_setup_team_prospecting`.\n', "arguments": [{ "name": "audience", "description": "Optional: a fresh audience to target (e.g. 'dental clinics in Texas'). Omit to build from your ACTIVE lens \u2014 the default.", "required": false }, { "name": "campaign_name", "description": "Optional: a name for the campaign. Omit and one is derived from the lens/audience + date (or the backend AI-names it).", "required": false }], "expected_calls": ["leadbay_account_status", "leadbay_pull_leads", "leadbay_bulk_qualify_leads", "leadbay_qualify_status", "leadbay_recall_ordered_titles", "leadbay_enrich_titles", "leadbay_bulk_enrich_status", "leadbay_create_campaign", "leadbay_add_leads_to_campaign", "leadbay_campaign_call_sheet", "leadbay_campaign_progression", "leadbay_new_lens", "leadbay_adjust_audience"], "failure_modes": ["Enriches by seniority instead of by buyer persona \u2014 picks COO / Director of Operations / Mgr of Logistics / CFO / CTO because they sound senior, when the user sells a SALES tool whose buyer is the revenue org (VP/Head/Director of Sales, BD, growth, marketing). Operations people never buy a sales tool; this hands the salesperson a useless list.", "Fails to derive the user's buyer persona from their product/ICP before choosing titles \u2014 jumps straight to titles without working out who buys what THIS user sells, then defaults to generic exec titles.", "Blindly repeats leadbay_recall_ordered_titles / discovery suggestions even when they are off-persona (e.g. operations roles a prior session wrongly enriched) \u2014 recall is a filtered input, not the answer.", "Poor coverage \u2014 leaves many picked leads with no persona-matching contact (or 0 enrichments on some leads) and doesn't flag it, so the salesperson opens the campaign to half-empty rows.", "Launches paid enrichment without first showing credits_remaining + enrichable_contacts, naming the persona, and getting a yes \u2014 the spend-visibility gate is mandatory.", "Creates the campaign before qualifying / picking \u2014 seeds a campaign with unvetted leads. Qualify and let the user pick (or AI-recommend) FIRST, then leadbay_create_campaign.", "Ends at 'campaign created' without rendering the leadbay_campaign_call_sheet view \u2014 the ready-to-work view IS the deliverable; stopping short is purpose drift.", "Re-implements the calling / outcome / follow-up loop instead of handing off to leadbay_work_campaign \u2014 that prompt already owns it. This prompt BUILDS; work_campaign WORKS.", "Auto-sends outreach or calls leadbay_report_outreach \u2014 building a campaign is not outreaching. No send, no log; the user works it afterward.", "Re-pulls leadbay_pull_leads without the captured lensId \u2014 a mid-session lens shift discards the picked cohort.", "Silently overwrites the user's active lens when forking to a fresh audience \u2014 confirm once before switching lenses.", "Renders the picked leads or the call sheet as prose instead of the canonical per-tool RENDERING layout."] },
|
|
1060
1259
|
leadbay_daily_check_in: { "name": "leadbay_daily_check_in", "short_description": 'Morning DISCOVERY workflow \u2014 new leads from the lens wishlist. Trigger\non "show me leads", "what\'s new today", "let\'s prospect", "run my check-in",\n"my morning check-in", "I do this every day", "every morning". Recurrence\nlanguage always means this prompt. Do NOT trigger on follow-up phrasings\n("follow up", "before my trip") \u2014 those go to `leadbay_followup_check_in`.\n', "arguments": [], "expected_calls": ["leadbay_account_status", "leadbay_pull_leads", "leadbay_research_lead_by_id", "leadbay_bulk_qualify_leads", "leadbay_enrich_contacts"], "failure_modes": ["Calls leadbay_report_outreach without explicit user authorization", "Surfaces fewer than 10 leads when more are available, or fails to top up via leadbay_qualify_top_n when the batch is short", `Replaces the canonical pull_leads table layout with prose per row (the per-tool RENDERING block is the structural contract; "Today's nudges" goes above it, not in place of it)`, "Skips the nudge paragraph entirely \u2014 the table alone is fine but adding the nudge is the value-add", `Skips deep research on promising leads (Phase 4) \u2014 the agent must call leadbay_research_lead_by_id on each when the user's intent is to research specific leads; Phase 4 is intentionally skipped for batch-view requests ("show me today's leads", "run my morning check-in") per the Phase 4 skip gate`, "Triggers contact enrichment without asking the user first (it consumes quota)", "Skips the STOP byproduct and proposes next actions on its own", 'Fires 10 parallel leadbay_research_lead_by_id calls and treats "stream closed" errors as terminal \u2014 must serialize and retry singletons', "Re-pulls leadbay_pull_leads without passing the captured lensId, allowing a backend lens shift to discard the Phase 2 batch", 'Treats a "Request timed out" from leadbay_bulk_qualify_leads as terminal instead of retrying with wait_for_completion:false + qualify_status polling', 'Triggers on a follow-up query (e.g., "leads I should follow up with") that should have routed to `leadbay_followup_check_in` \u2014 the two entry points are different data sources (Discover wishlist vs Monitor view) per \xA71.6'] },
|
|
1061
1260
|
leadbay_extend_my_lens: { "name": "leadbay_extend_my_lens", "short_description": "Add more leads to the current lens on demand \u2014 for users whose appetite\nexceeds the standard daily fill. The agent picks seeds silently from\nwhat's already on the lens, fires the extra refill, and surfaces the\nqueue confirmation. The user never reviews the seed list.\n", "arguments": [{ "name": "extra_count", "description": "How many extra leads to add. Optional. Omit to use the backend default.", "required": false }], "expected_calls": ["leadbay_account_status", "leadbay_seed_candidates", "leadbay_extend_lens", "leadbay_pull_leads"], "failure_modes": ["Surfaces the seed candidate list to the user instead of picking silently \u2014 the user asked for MORE LEADS, not a candidate review meeting", "Skips the seeded path and calls `leadbay_extend_lens` with no `seed_lead_ids`, losing the bias signal the recommender needs", "On 429, silently retries instead of surfacing the three options (smaller / wait / upgrade) via your host's choice widget (`ask_user_input_v0` or `AskUserQuestion`)", "Forgets to pre-check `LENS_EXTRA_REFILL` quota in `leadbay_account_status` and burns a wasted API call", "Skips the post-queue pull-leads suggestion, so the user doesn't see what just got added"] },
|
|
1062
1261
|
leadbay_followup_check_in: { "name": "leadbay_followup_check_in", "short_description": 'Follow-up check-in: surface KNOWN leads from the Monitor view needing\nre-engagement. Trigger on "follow up", "already known leads", "what\'s\noverdue", "before my trip", "who should I re-engage". Do NOT trigger on\n"show me today\'s leads", "my morning check-in", "run my check-in",\n"I do this every day", "every morning" \u2014 those go to\n`leadbay_daily_check_in`.\n', "arguments": [], "expected_calls": ["leadbay_pull_followups", "leadbay_research_lead_by_id", "leadbay_prepare_outreach"], "failure_modes": ["Calls leadbay_pull_leads (the Discover entry point) instead of leadbay_pull_followups \u2014 these are different data sources; the Discover queue does NOT contain Monitor's known-but-cold pipeline", 'Iterates pages of leadbay_pull_leads filtering by engagement_count to "fake" a follow-up view (a real bug observed in 0.9.0 \u2014 the right move is to call pull_followups directly)', "Replaces the canonical pull_followups table layout with prose per row (the per-tool RENDERING block is the structural contract; commentary belongs above or below)", 'Skips the cross-mode pivot offer at the end ("Want to see NEW leads from your wishlist instead?" routes to leadbay_pull_leads)'] },
|
|
@@ -1078,6 +1277,7 @@ should I follow up on" to "I'll send via lemlist".
|
|
|
1078
1277
|
};
|
|
1079
1278
|
var PROMPT_CATALOG_HEADER = `This server exposes the following workflow prompts via \`prompts/list\` and \`prompts/get\`. Some MCP clients render them as slash commands; if your client does not, you (the agent) should invoke them directly via \`prompts/get\` when the user's request matches one of the triggers described below.`;
|
|
1080
1279
|
var PROMPT_CATALOG_BULLETS = {
|
|
1280
|
+
leadbay_build_campaign: `- \`leadbay_build_campaign\` (optional args: audience, campaign_name): Build a sales campaign from scratch in one guided flow: discover on the active lens, qualify and pick a cohort, enrich the contacts most likely to engage, save it via \`leadbay_create_campaign\`, then show a one-tap call/email view via \`leadbay_campaign_call_sheet\`. Trigger on "build me a campaign", "set up a new campaign", "create a campaign from scratch". WORK an existing campaign with \`leadbay_work_campaign\`; split leads across reps with \`leadbay_setup_team_prospecting\`.`,
|
|
1081
1281
|
leadbay_daily_check_in: `- \`leadbay_daily_check_in\`: Morning DISCOVERY workflow \u2014 new leads from the lens wishlist. Trigger on "show me leads", "what's new today", "let's prospect", "run my check-in", "my morning check-in", "I do this every day", "every morning". Recurrence language always means this prompt. Do NOT trigger on follow-up phrasings ("follow up", "before my trip") \u2014 those go to \`leadbay_followup_check_in\`.`,
|
|
1082
1282
|
leadbay_extend_my_lens: `- \`leadbay_extend_my_lens\` (optional args: extra_count): Add more leads to the current lens on demand \u2014 for users whose appetite exceeds the standard daily fill. The agent picks seeds silently from what's already on the lens, fires the extra refill, and surfaces the queue confirmation. The user never reviews the seed list.`,
|
|
1083
1283
|
leadbay_followup_check_in: `- \`leadbay_followup_check_in\`: Follow-up check-in: surface KNOWN leads from the Monitor view needing re-engagement. Trigger on "follow up", "already known leads", "what's overdue", "before my trip", "who should I re-engage". Do NOT trigger on "show me today's leads", "my morning check-in", "run my check-in", "I do this every day", "every morning" \u2014 those go to \`leadbay_daily_check_in\`.`,
|
|
@@ -1225,6 +1425,30 @@ var CATALOG = [
|
|
|
1225
1425
|
)
|
|
1226
1426
|
]
|
|
1227
1427
|
},
|
|
1428
|
+
{
|
|
1429
|
+
name: "leadbay_build_campaign",
|
|
1430
|
+
description: PROMPT_META.leadbay_build_campaign.short_description,
|
|
1431
|
+
arguments: [
|
|
1432
|
+
{
|
|
1433
|
+
name: "audience",
|
|
1434
|
+
description: "Optional: a fresh audience to target (e.g. 'dental clinics in Texas'). Omit to build from your ACTIVE lens \u2014 the default.",
|
|
1435
|
+
required: false
|
|
1436
|
+
},
|
|
1437
|
+
{
|
|
1438
|
+
name: "campaign_name",
|
|
1439
|
+
description: "Optional: a name for the campaign. Omit and one is derived from the lens/audience + date (or the backend AI-names it).",
|
|
1440
|
+
required: false
|
|
1441
|
+
}
|
|
1442
|
+
],
|
|
1443
|
+
render: (args) => [
|
|
1444
|
+
userMessage(
|
|
1445
|
+
substitutePlaceholders(leadbay_build_campaign, {
|
|
1446
|
+
audience_block: args.audience ? `Target audience: **${args.audience}** \u2014 if my active lens doesn't already cover it, set it up first (confirm before switching lenses).` : "Use my active Leadbay lens as the audience.",
|
|
1447
|
+
campaign_name_paren: args.campaign_name ? ` named **${args.campaign_name}**` : ""
|
|
1448
|
+
})
|
|
1449
|
+
)
|
|
1450
|
+
]
|
|
1451
|
+
},
|
|
1228
1452
|
{
|
|
1229
1453
|
name: "leadbay_setup_team_prospecting",
|
|
1230
1454
|
description: PROMPT_META.leadbay_setup_team_prospecting.short_description,
|
|
@@ -6310,9 +6534,13 @@ var COMPOSITE_FILE_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
|
6310
6534
|
"leadbay_campaign_call_sheet",
|
|
6311
6535
|
"leadbay_campaign_progression",
|
|
6312
6536
|
"leadbay_create_campaign",
|
|
6537
|
+
"leadbay_create_custom_field",
|
|
6538
|
+
"leadbay_delete_custom_field",
|
|
6313
6539
|
"leadbay_enrich_titles",
|
|
6314
6540
|
"leadbay_extend_lens",
|
|
6315
6541
|
"leadbay_followups_map",
|
|
6542
|
+
"leadbay_get_lead_custom_fields",
|
|
6543
|
+
"leadbay_get_qualification_questions",
|
|
6316
6544
|
"leadbay_import_and_qualify",
|
|
6317
6545
|
"leadbay_import_leads",
|
|
6318
6546
|
"leadbay_import_status",
|
|
@@ -6333,7 +6561,9 @@ var COMPOSITE_FILE_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
|
6333
6561
|
"leadbay_resolve_import_rows",
|
|
6334
6562
|
"leadbay_scan_portfolio_signals",
|
|
6335
6563
|
"leadbay_seed_candidates",
|
|
6564
|
+
"leadbay_set_qualification_questions",
|
|
6336
6565
|
"leadbay_team_activity",
|
|
6566
|
+
"leadbay_update_custom_field",
|
|
6337
6567
|
"leadbay_tour_plan"
|
|
6338
6568
|
]);
|
|
6339
6569
|
|
|
@@ -7182,6 +7412,23 @@ WHEN TO USE: when a quota error has blocked the user's intent and they want to k
|
|
|
7182
7412
|
|
|
7183
7413
|
WHEN NOT TO USE: pre-flight (the agent is not paying \u2014 the user is); for subscription / plan changes use \`leadbay_open_billing_portal\` instead; for read-only quota diagnostics use \`leadbay_account_status\` / \`leadbay_get_quota\`.
|
|
7184
7414
|
`;
|
|
7415
|
+
var leadbay_delete_custom_field = `Delete an org-level CRM custom field. Use when the user explicitly wants to remove a custom field from their account \u2014 e.g. "delete the old 'Legacy Source' field".
|
|
7416
|
+
|
|
7417
|
+
**This is destructive.** Removing the field drops its stored values from every lead and breaks any import mapping that targets \`CUSTOM.<id>\`. For that reason the tool has a safety gate:
|
|
7418
|
+
|
|
7419
|
+
- Call with \`id\` only \u2192 the tool returns the field that WOULD be deleted (\`{id, name, type, deleted:false, hint}\`) and changes nothing. Surface the hint to the user and ask them to confirm.
|
|
7420
|
+
- Call with \`id\` + \`confirm:true\` \u2192 the field is deleted (\`{id, name, type, deleted:true}\`).
|
|
7421
|
+
|
|
7422
|
+
\`id\` is the numeric custom-field id from \`leadbay_list_mappable_fields\` \u2014 NOT the \`CUSTOM.<id>\` mapping value.
|
|
7423
|
+
|
|
7424
|
+
WHEN TO USE: the user explicitly asks to delete/remove a custom field \u2014 and only fire with confirm:true after they confirm.
|
|
7425
|
+
|
|
7426
|
+
WHEN NOT TO USE: to rename or retype a field (use leadbay_update_custom_field) or to create one (use leadbay_create_custom_field).
|
|
7427
|
+
|
|
7428
|
+
### RENDERING
|
|
7429
|
+
|
|
7430
|
+
Before deleting (no confirm), render the \`hint\` and ask the user to confirm \u2014 do NOT auto-confirm on the user's behalf. After a confirmed delete, acknowledge in one line: **"Deleted custom field #12 'Legacy Source'."**
|
|
7431
|
+
`;
|
|
7185
7432
|
var leadbay_deselect_leads = `Remove leads from the user's transient selection.
|
|
7186
7433
|
|
|
7187
7434
|
WHEN TO USE: when narrowing a previously-built selection without clearing it entirely.
|
|
@@ -7585,6 +7832,68 @@ WHEN TO USE: to avoid redundant outreach and understand where this lead is in th
|
|
|
7585
7832
|
|
|
7586
7833
|
WHEN NOT TO USE: when leadbay_research_lead_by_id has already been called \u2014 it includes recent prospecting actions in its engagement block.
|
|
7587
7834
|
`;
|
|
7835
|
+
var leadbay_get_lead_custom_fields = `## WHEN TO USE
|
|
7836
|
+
|
|
7837
|
+
Trigger phrases: "what custom fields are on this lead", "show the CRM custom field values for <Company>", "what's the <custom field name> on this lead", "get lead <UUID>'s custom fields", "does this lead have any custom field values".
|
|
7838
|
+
|
|
7839
|
+
**Memory:** recall + capture via \`leadbay_agent_memory_*\` tools.
|
|
7840
|
+
|
|
7841
|
+
Do NOT use for: "what custom fields exist on my account" \u2192 \`leadbay_list_mappable_fields\`; "give me the full research dossier on this lead" \u2192 \`leadbay_research_lead_by_id\`.
|
|
7842
|
+
|
|
7843
|
+
Prefer when: user wants the custom-field VALUES on ONE lead; pass \`leadId\`
|
|
7844
|
+
|
|
7845
|
+
Examples that SHOULD invoke this tool:
|
|
7846
|
+
- "What custom field values are stored on this lead?"
|
|
7847
|
+
- "Show me the CRM custom fields for that company."
|
|
7848
|
+
|
|
7849
|
+
Examples that should NOT invoke this tool (sound similar, route elsewhere):
|
|
7850
|
+
- "What custom fields are defined on my account?"
|
|
7851
|
+
- "Give me the full research breakdown on Acme Corp."
|
|
7852
|
+
|
|
7853
|
+
## RENDER (quick)
|
|
7854
|
+
|
|
7855
|
+
3-column markdown table: Field | Type | Value, one row per entry. When
|
|
7856
|
+
\`custom_fields\` is empty, render the \`hint\` sentence instead of an empty
|
|
7857
|
+
table.
|
|
7858
|
+
|
|
7859
|
+
---
|
|
7860
|
+
|
|
7861
|
+
Retrieve the CRM custom-field **values** stored on a single lead \u2014 the actual
|
|
7862
|
+
data (\`value\`) per custom field, not the field definitions.
|
|
7863
|
+
|
|
7864
|
+
This is distinct from **leadbay_list_mappable_fields**, which returns the org's
|
|
7865
|
+
custom-field *catalog* (the definitions: id/name/type, used for import
|
|
7866
|
+
mapping). This tool answers "what does *this* lead hold for each custom field".
|
|
7867
|
+
|
|
7868
|
+
Params: \`leadId\` (required UUID); \`lensId\` (optional escape hatch \u2014 normally
|
|
7869
|
+
omit; auto-resolves to the active lens).
|
|
7870
|
+
|
|
7871
|
+
Returns:
|
|
7872
|
+
|
|
7873
|
+
- **\`custom_fields\`** \u2014 one row per value: \`{id, name, type, value}\`. The lead
|
|
7874
|
+
payload embeds each field's definition, so rows are fully named without a
|
|
7875
|
+
separate catalog lookup. Empty array when the org has no custom fields or
|
|
7876
|
+
none are set on this lead.
|
|
7877
|
+
- **\`count\`** \u2014 number of values.
|
|
7878
|
+
- **\`hint\`** \u2014 empty-state guidance (points at \`leadbay_list_mappable_fields\`
|
|
7879
|
+
and the import path), or a degradation note in the rare case a value arrived
|
|
7880
|
+
without an embedded definition and the catalog fallback failed.
|
|
7881
|
+
|
|
7882
|
+
Reading a lead marks it seen (LEAD_SEEN) the same way the research tools do, so
|
|
7883
|
+
it ages out of the 'new' Discover view.
|
|
7884
|
+
|
|
7885
|
+
Companion tools: **leadbay_list_mappable_fields** for the catalog/definitions;
|
|
7886
|
+
**leadbay_research_lead_by_id** for the full lead dossier (signals, contacts,
|
|
7887
|
+
qualification answers).
|
|
7888
|
+
|
|
7889
|
+
### RENDERING
|
|
7890
|
+
|
|
7891
|
+
Render \`custom_fields\` as a 3-column markdown table: **Field** (\`name\`, or the
|
|
7892
|
+
\`id\` when name is null) \xB7 **Type** (\`type\`) \xB7 **Value** (\`value\`, or "\u2014" when
|
|
7893
|
+
null/empty). One row per entry, in the order returned. When \`custom_fields\` is
|
|
7894
|
+
empty, render the \`hint\` sentence instead of an empty table. Don't fabricate
|
|
7895
|
+
fields or values \u2014 render verbatim.
|
|
7896
|
+
`;
|
|
7588
7897
|
var leadbay_get_lead_notes = `Read existing notes on a lead \u2014 context the human team or prior agent runs have already captured.
|
|
7589
7898
|
|
|
7590
7899
|
WHEN TO USE: before adding a note via leadbay_report_outreach, to avoid duplicating or overwriting context the SDR already wrote.
|
|
@@ -7615,6 +7924,70 @@ WHEN TO USE: before contacting the lead, to avoid duplicating outreach the team
|
|
|
7615
7924
|
|
|
7616
7925
|
WHEN NOT TO USE: when the lead summary's \`prospecting_actions_count\` is 0.
|
|
7617
7926
|
`;
|
|
7927
|
+
var leadbay_get_qualification_questions = `## WHEN TO USE
|
|
7928
|
+
|
|
7929
|
+
Trigger phrases: "what are my qualification questions", "what questions does Leadbay ask about each lead", "show me the org qualification questions", "how are my leads being qualified", "what's the qualification criteria".
|
|
7930
|
+
|
|
7931
|
+
**Memory:** recall + capture via \`leadbay_agent_memory_*\` tools.
|
|
7932
|
+
|
|
7933
|
+
Do NOT use for: "how did this lead score on the qualification questions" \u2192 \`leadbay_research_lead_by_id\`; "show my ideal buyer profile and intent tags" \u2192 \`leadbay_get_taste_profile\`.
|
|
7934
|
+
|
|
7935
|
+
Prefer when: user wants the ORG-level qualification questions catalog, no lead and no buyer profile
|
|
7936
|
+
|
|
7937
|
+
Examples that SHOULD invoke this tool:
|
|
7938
|
+
- "What qualification questions does Leadbay use to score my leads?"
|
|
7939
|
+
- "Show me my org's qualification questions."
|
|
7940
|
+
|
|
7941
|
+
Examples that should NOT invoke this tool (sound similar, route elsewhere):
|
|
7942
|
+
- "How did Acme Corp answer the qualification questions?"
|
|
7943
|
+
- "What's my ideal buyer profile?"
|
|
7944
|
+
|
|
7945
|
+
## RENDER (quick)
|
|
7946
|
+
|
|
7947
|
+
Numbered list of the questions (chat-native markdown), each one line. When
|
|
7948
|
+
\`is_admin\` is true, append the \`hint\` as a footnote (points at
|
|
7949
|
+
leadbay_set_qualification_questions for editing). When the list is empty,
|
|
7950
|
+
render the \`hint\` instead.
|
|
7951
|
+
|
|
7952
|
+
---
|
|
7953
|
+
|
|
7954
|
+
Retrieve the organization's **qualification questions** \u2014 the AI-agent questions
|
|
7955
|
+
Leadbay scores every lead against. These are the org-level questions that drive
|
|
7956
|
+
each lead's qualification boost; the per-lead ANSWERS to them surface inside
|
|
7957
|
+
\`leadbay_research_lead_by_id\`.
|
|
7958
|
+
|
|
7959
|
+
Returns:
|
|
7960
|
+
|
|
7961
|
+
- **\`qualification_questions\`** \u2014 the catalog. Each: \`{question, created_at,
|
|
7962
|
+
lang}\`. Ordered as the backend returns them.
|
|
7963
|
+
- **\`count\`** \u2014 number of configured questions.
|
|
7964
|
+
- **\`is_admin\`** \u2014 whether the current user is an org admin. Modifying the
|
|
7965
|
+
questions (\`leadbay_set_qualification_questions\`) is an org-admin action; for
|
|
7966
|
+
admins a \`hint\` points there.
|
|
7967
|
+
- **\`hint\`** \u2014 operator note: the modify pointer, or an empty-state message
|
|
7968
|
+
when no questions are configured.
|
|
7969
|
+
|
|
7970
|
+
This tool only READS. To change the questions, use
|
|
7971
|
+
**leadbay_set_qualification_questions** (add / remove / replace). The result is
|
|
7972
|
+
cached on the client (it reuses the same taste-profile fetch as
|
|
7973
|
+
\`leadbay_get_taste_profile\`), so repeated calls in a session are cheap.
|
|
7974
|
+
|
|
7975
|
+
Companion tools: **leadbay_set_qualification_questions** to modify the questions;
|
|
7976
|
+
**leadbay_get_taste_profile** when the user also wants the Ideal Buyer Profile +
|
|
7977
|
+
purchase-intent tags; **leadbay_research_lead_by_id** for how a SPECIFIC lead
|
|
7978
|
+
answered these questions; **leadbay_refine_prompt** to shape the AI agent's
|
|
7979
|
+
behaviour.
|
|
7980
|
+
|
|
7981
|
+
### RENDERING
|
|
7982
|
+
|
|
7983
|
+
Render \`qualification_questions\` as a numbered list \u2014 one question per line, in
|
|
7984
|
+
the order returned. Lead with a short heading like **"Qualification questions
|
|
7985
|
+
(N)"**. When \`qualification_questions\` is empty, render the \`hint\` sentence
|
|
7986
|
+
instead of an empty list. When \`is_admin\` is true and there are questions,
|
|
7987
|
+
append the \`hint\` as a one-line footnote (points at
|
|
7988
|
+
leadbay_set_qualification_questions). Do not invent questions or reword them \u2014
|
|
7989
|
+
render verbatim.
|
|
7990
|
+
`;
|
|
7618
7991
|
var leadbay_get_quota = `Read remaining quota / spend across daily, weekly, and monthly windows for the org's resources (\`llm_completion\`, \`ai_rescore\`, \`web_fetch\`). Each entry shows \`current_units\` vs \`max_units\` and \`resets_at\`.
|
|
7619
7992
|
|
|
7620
7993
|
WHEN TO USE: after a 429 error, to explain to the user which window was hit and when it resets.
|
|
@@ -9777,6 +10150,28 @@ WHEN NOT TO USE: the user is just skipping ONE outreach attempt \u2014 that's a
|
|
|
9777
10150
|
|
|
9778
10151
|
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\`.
|
|
9779
10152
|
`;
|
|
10153
|
+
var leadbay_set_qualification_questions = `Modify the organization's **qualification questions** \u2014 the AI-agent questions Leadbay scores every lead against. Use when the user wants to add, remove, or rewrite their qualification questions \u2014 e.g. "add a question about whether they run install crews", "remove the flooring question", "replace my questions with these three".
|
|
10154
|
+
|
|
10155
|
+
The backend stores the list as a whole, so this tool reads the current questions and applies your change:
|
|
10156
|
+
|
|
10157
|
+
- **\`add\`** \u2014 append questions (deduped against the current list).
|
|
10158
|
+
- **\`remove\`** \u2014 drop the exact question strings you pass.
|
|
10159
|
+
- **\`questions\`** \u2014 replace the ENTIRE list (mutually exclusive with add/remove).
|
|
10160
|
+
|
|
10161
|
+
Leadbay allows **at most 5** qualification questions. If a change would exceed 5, the tool rejects with a clear limit message \u2014 remove some before adding.
|
|
10162
|
+
|
|
10163
|
+
**Dropping any existing question is destructive** \u2014 it changes how every lead is scored. Any change that removes a current question requires \`confirm:true\` \u2014 including a same-count **swap** (remove one + add one) or a \`questions\` replacement that omits a current question, not only when the list gets shorter. Without \`confirm\`, the tool previews what would be removed and applies nothing. Pure additions never need confirm.
|
|
10164
|
+
|
|
10165
|
+
Returns the resulting \`{qualification_questions, count, previous_count, changed}\`. Phrase questions as the yes/no scoring prompts Leadbay uses (e.g. "Is the company likely to \u2026?").
|
|
10166
|
+
|
|
10167
|
+
WHEN TO USE: the user wants to change the org's qualification questions.
|
|
10168
|
+
|
|
10169
|
+
WHEN NOT TO USE: to READ the questions (use leadbay_get_qualification_questions) or to change a single lead's data. This is org-level \u2014 it affects scoring for ALL leads.
|
|
10170
|
+
|
|
10171
|
+
### RENDERING
|
|
10172
|
+
|
|
10173
|
+
After a change, confirm in one line \u2014 e.g. **"Added 1 question \u2014 you now score leads against 4 questions."** or **"Removed 'the flooring question' \u2014 3 questions remain."** Then list the resulting questions as a numbered list. When the result is a non-changing preview (a removal awaiting confirmation), surface the \`hint\` (what would be removed) and ask the user to confirm \u2014 do NOT auto-confirm.
|
|
10174
|
+
`;
|
|
9780
10175
|
var leadbay_set_user_prompt = `Set the org's intelligence-refinement prompt \u2014 free-text instruction that steers Leadbay's lead recommendations beyond firmographics. Admin-only. Setting this clears any pending clarification and triggers a full intelligence regeneration (web search + high-reasoning). \`dry_run:true\` returns the call shape without contacting the backend.
|
|
9781
10176
|
|
|
9782
10177
|
WHEN TO USE: low-level.
|
|
@@ -10003,6 +10398,20 @@ Returns \`{ updated: true, contact_id, contact: { id, first_name, last_name, job
|
|
|
10003
10398
|
|
|
10004
10399
|
Requires: LEADBAY_MCP_WRITE=1 (MCP) or exposeWrite=true (OpenClaw).
|
|
10005
10400
|
`;
|
|
10401
|
+
var leadbay_update_custom_field = `Update an org-level CRM custom field in place. Use when the user wants to rename a custom field or change its type/config \u2014 e.g. "rename the 'Tier' field to 'Account Tier'" or "make the ARR field a PRICE in USD".
|
|
10402
|
+
|
|
10403
|
+
Pass \`id\` (the numeric custom-field id from \`leadbay_list_mappable_fields\` \u2014 NOT the \`CUSTOM.<id>\` mapping value) plus any of \`name\`, \`type\`, \`config\`. The update is a partial merge over the current definition: a rename-only call keeps the existing type; a retype-only call keeps the name. At least one of \`name\` / \`type\` / \`config\` is required.
|
|
10404
|
+
|
|
10405
|
+
Type + config rules mirror creation: \`EXTERNAL_ID\` requires \`config.url_template\` containing \`{value}\`; \`PRICE\` requires \`config.currency\`; \`DATE\`/\`DATETIME\` may set \`config.format\`. Returns the updated \`{id, name, type, config, mapping_value}\`.
|
|
10406
|
+
|
|
10407
|
+
WHEN TO USE: the user wants to change an existing custom field's name or type.
|
|
10408
|
+
|
|
10409
|
+
WHEN NOT TO USE: to CREATE a new field (use leadbay_create_custom_field) or to DELETE one (use leadbay_delete_custom_field). To read a lead's custom-field values use leadbay_get_lead_custom_fields; to list the catalog use leadbay_list_mappable_fields.
|
|
10410
|
+
|
|
10411
|
+
### RENDERING
|
|
10412
|
+
|
|
10413
|
+
Confirm the change in one line naming the field and what changed, e.g. **"Renamed custom field #12 \u2192 'Account Tier' (TEXT)."** or **"Updated #13 'ARR' \u2192 PRICE (USD)."** Don't dump the raw payload.
|
|
10414
|
+
`;
|
|
10006
10415
|
var leadbay_update_lens = `Update lens metadata (name, description, mode flags). Does NOT change the audience filter \u2014 use leadbay_update_lens_filter for that.
|
|
10007
10416
|
|
|
10008
10417
|
WHEN TO USE: rename a lens or toggle \`multi_product_mode\` / \`use_hq_only\`.
|
|
@@ -13908,7 +14317,39 @@ var launchBulkEnrichment = {
|
|
|
13908
14317
|
}
|
|
13909
14318
|
};
|
|
13910
14319
|
|
|
13911
|
-
// ../core/dist/
|
|
14320
|
+
// ../core/dist/composite/_custom-field-config.js
|
|
14321
|
+
function sanitizeConfigForType(type, rawConfig) {
|
|
14322
|
+
if (!rawConfig)
|
|
14323
|
+
return null;
|
|
14324
|
+
let config;
|
|
14325
|
+
if (typeof rawConfig === "string") {
|
|
14326
|
+
try {
|
|
14327
|
+
const parsed = JSON.parse(rawConfig);
|
|
14328
|
+
if (!parsed || typeof parsed !== "object")
|
|
14329
|
+
return null;
|
|
14330
|
+
config = parsed;
|
|
14331
|
+
} catch {
|
|
14332
|
+
return null;
|
|
14333
|
+
}
|
|
14334
|
+
} else {
|
|
14335
|
+
config = rawConfig;
|
|
14336
|
+
}
|
|
14337
|
+
switch (type) {
|
|
14338
|
+
case "PRICE":
|
|
14339
|
+
return config.currency != null ? { currency: config.currency } : null;
|
|
14340
|
+
case "DATE":
|
|
14341
|
+
case "DATETIME":
|
|
14342
|
+
return "format" in config ? { format: config.format ?? null } : null;
|
|
14343
|
+
case "EXTERNAL_ID": {
|
|
14344
|
+
const url = config.url_template ?? config.urlTemplate;
|
|
14345
|
+
return url != null ? { url_template: url } : null;
|
|
14346
|
+
}
|
|
14347
|
+
default:
|
|
14348
|
+
return null;
|
|
14349
|
+
}
|
|
14350
|
+
}
|
|
14351
|
+
|
|
14352
|
+
// ../core/dist/composite/create-custom-field.js
|
|
13912
14353
|
var createCustomField = {
|
|
13913
14354
|
name: "leadbay_create_custom_field",
|
|
13914
14355
|
annotations: {
|
|
@@ -13933,8 +14374,8 @@ var createCustomField = {
|
|
|
13933
14374
|
description: "Custom field type: TEXT, NUMBER, PRICE, DATE, DATETIME, or EXTERNAL_ID. Defaults to TEXT."
|
|
13934
14375
|
},
|
|
13935
14376
|
config: {
|
|
13936
|
-
type: ["object", "null"],
|
|
13937
|
-
description: "Type-specific config. EXTERNAL_ID requires {url_template:'https://.../{value}'}; PRICE requires {currency:'USD'}; DATE/DATETIME may set {format}."
|
|
14377
|
+
type: ["object", "string", "null"],
|
|
14378
|
+
description: "Type-specific config, as an object (preferred) or a JSON string. EXTERNAL_ID requires {url_template:'https://.../{value}'}; PRICE requires {currency:'USD'}; DATE/DATETIME may set {format}."
|
|
13938
14379
|
},
|
|
13939
14380
|
if_not_exists: {
|
|
13940
14381
|
type: "boolean",
|
|
@@ -13968,9 +14409,9 @@ var createCustomField = {
|
|
|
13968
14409
|
throw client.makeError("CUSTOM_FIELD_NAME_REQUIRED", "name must be a non-empty string", "Pass a user-visible custom field name, e.g. 'HubSpot Contact'.", "POST /crm/custom_fields");
|
|
13969
14410
|
}
|
|
13970
14411
|
const type = params.type ?? "TEXT";
|
|
13971
|
-
const config = params.config ?? null;
|
|
14412
|
+
const config = sanitizeConfigForType(type, params.config ?? null);
|
|
13972
14413
|
if (type === "EXTERNAL_ID") {
|
|
13973
|
-
const urlTemplate = config?.url_template
|
|
14414
|
+
const urlTemplate = config?.url_template;
|
|
13974
14415
|
if (!urlTemplate || !urlTemplate.includes("{value}")) {
|
|
13975
14416
|
throw client.makeError("CUSTOM_FIELD_EXTERNAL_ID_TEMPLATE_REQUIRED", "EXTERNAL_ID custom fields require config.url_template containing {value}", "Use a URL template like https://app.hubspot.com/contacts/<portal-id>/record/0-1/{value}.", "POST /crm/custom_fields");
|
|
13976
14417
|
}
|
|
@@ -14000,6 +14441,170 @@ var createCustomField = {
|
|
|
14000
14441
|
}
|
|
14001
14442
|
};
|
|
14002
14443
|
|
|
14444
|
+
// ../core/dist/composite/update-custom-field.js
|
|
14445
|
+
var updateCustomField = {
|
|
14446
|
+
name: "leadbay_update_custom_field",
|
|
14447
|
+
annotations: {
|
|
14448
|
+
title: "Update CRM custom field",
|
|
14449
|
+
readOnlyHint: false,
|
|
14450
|
+
destructiveHint: false,
|
|
14451
|
+
idempotentHint: true,
|
|
14452
|
+
openWorldHint: true
|
|
14453
|
+
},
|
|
14454
|
+
description: leadbay_update_custom_field,
|
|
14455
|
+
write: true,
|
|
14456
|
+
inputSchema: {
|
|
14457
|
+
type: "object",
|
|
14458
|
+
properties: {
|
|
14459
|
+
id: {
|
|
14460
|
+
type: "string",
|
|
14461
|
+
description: "Custom field id to update (the numeric id from leadbay_list_mappable_fields, NOT the 'CUSTOM.<id>' mapping value)."
|
|
14462
|
+
},
|
|
14463
|
+
name: {
|
|
14464
|
+
type: "string",
|
|
14465
|
+
description: "New user-visible name. Omit to keep the current name."
|
|
14466
|
+
},
|
|
14467
|
+
type: {
|
|
14468
|
+
type: "string",
|
|
14469
|
+
description: "New type: TEXT, NUMBER, PRICE, DATE, DATETIME, or EXTERNAL_ID. Omit to keep the current type."
|
|
14470
|
+
},
|
|
14471
|
+
config: {
|
|
14472
|
+
type: ["object", "string", "null"],
|
|
14473
|
+
description: "New type-specific config, as an object (preferred) or a JSON string. EXTERNAL_ID requires {url_template:'https://.../{value}'}; PRICE requires {currency:'USD'}; DATE/DATETIME may set {format}. Omit to keep current config."
|
|
14474
|
+
}
|
|
14475
|
+
},
|
|
14476
|
+
required: ["id"],
|
|
14477
|
+
additionalProperties: false
|
|
14478
|
+
},
|
|
14479
|
+
outputSchema: {
|
|
14480
|
+
type: "object",
|
|
14481
|
+
properties: {
|
|
14482
|
+
id: { type: "string" },
|
|
14483
|
+
name: { type: "string" },
|
|
14484
|
+
type: { type: "string" },
|
|
14485
|
+
config: { type: ["object", "null"] },
|
|
14486
|
+
mapping_value: {
|
|
14487
|
+
type: "string",
|
|
14488
|
+
description: "Wire mapping value for import mappings, e.g. CUSTOM.123."
|
|
14489
|
+
}
|
|
14490
|
+
},
|
|
14491
|
+
required: ["id", "name", "type", "mapping_value"]
|
|
14492
|
+
},
|
|
14493
|
+
execute: async (client, params) => {
|
|
14494
|
+
const id = String(params.id ?? "").trim();
|
|
14495
|
+
if (!id) {
|
|
14496
|
+
throw client.makeError("CUSTOM_FIELD_ID_REQUIRED", "id must be a non-empty string", "Pass the custom field id from leadbay_list_mappable_fields (the numeric id, not 'CUSTOM.<id>').", "POST /crm/custom_fields/{id}");
|
|
14497
|
+
}
|
|
14498
|
+
if (params.name === void 0 && params.type === void 0 && params.config === void 0) {
|
|
14499
|
+
throw client.makeError("CUSTOM_FIELD_NO_CHANGE", "no field to update \u2014 pass at least one of name, type, config", "Provide a new name and/or type (and config when the type needs it).", "POST /crm/custom_fields/{id}");
|
|
14500
|
+
}
|
|
14501
|
+
const catalog = await client.request("GET", "/crm/custom_fields");
|
|
14502
|
+
const current = (catalog ?? []).find((f) => String(f.id) === id);
|
|
14503
|
+
if (!current) {
|
|
14504
|
+
throw client.makeError("CUSTOM_FIELD_NOT_FOUND", `no custom field with id ${id} on this org`, "Call leadbay_list_mappable_fields to see the available custom fields and their ids.", "POST /crm/custom_fields/{id}");
|
|
14505
|
+
}
|
|
14506
|
+
const name = params.name !== void 0 ? params.name.trim() : current.name;
|
|
14507
|
+
if (!name) {
|
|
14508
|
+
throw client.makeError("CUSTOM_FIELD_NAME_REQUIRED", "name must be a non-empty string", "Pass a user-visible custom field name, or omit name to keep the current one.", "POST /crm/custom_fields/{id}");
|
|
14509
|
+
}
|
|
14510
|
+
const type = params.type !== void 0 ? params.type : current.type;
|
|
14511
|
+
const rawConfig = params.config !== void 0 ? params.config : current.config ?? null;
|
|
14512
|
+
const config = sanitizeConfigForType(type, rawConfig);
|
|
14513
|
+
if (type === "EXTERNAL_ID") {
|
|
14514
|
+
const urlTemplate = config?.url_template;
|
|
14515
|
+
if (!urlTemplate || !urlTemplate.includes("{value}")) {
|
|
14516
|
+
throw client.makeError("CUSTOM_FIELD_EXTERNAL_ID_TEMPLATE_REQUIRED", "EXTERNAL_ID custom fields require config.url_template containing {value}", "Use a URL template like https://app.hubspot.com/contacts/<portal-id>/record/0-1/{value}.", "POST /crm/custom_fields/{id}");
|
|
14517
|
+
}
|
|
14518
|
+
}
|
|
14519
|
+
const body = {
|
|
14520
|
+
name,
|
|
14521
|
+
type,
|
|
14522
|
+
...config ? { config } : {}
|
|
14523
|
+
};
|
|
14524
|
+
await client.requestVoid("POST", `/crm/custom_fields/${id}`, body);
|
|
14525
|
+
return {
|
|
14526
|
+
id,
|
|
14527
|
+
name,
|
|
14528
|
+
type,
|
|
14529
|
+
config: config ?? null,
|
|
14530
|
+
mapping_value: `CUSTOM.${id}`
|
|
14531
|
+
};
|
|
14532
|
+
}
|
|
14533
|
+
};
|
|
14534
|
+
|
|
14535
|
+
// ../core/dist/composite/delete-custom-field.js
|
|
14536
|
+
var deleteCustomField = {
|
|
14537
|
+
name: "leadbay_delete_custom_field",
|
|
14538
|
+
annotations: {
|
|
14539
|
+
title: "Delete CRM custom field",
|
|
14540
|
+
readOnlyHint: false,
|
|
14541
|
+
destructiveHint: true,
|
|
14542
|
+
idempotentHint: false,
|
|
14543
|
+
openWorldHint: true
|
|
14544
|
+
},
|
|
14545
|
+
description: leadbay_delete_custom_field,
|
|
14546
|
+
write: true,
|
|
14547
|
+
inputSchema: {
|
|
14548
|
+
type: "object",
|
|
14549
|
+
properties: {
|
|
14550
|
+
id: {
|
|
14551
|
+
type: "string",
|
|
14552
|
+
description: "Custom field id to delete (the numeric id from leadbay_list_mappable_fields, NOT the 'CUSTOM.<id>' mapping value)."
|
|
14553
|
+
},
|
|
14554
|
+
confirm: {
|
|
14555
|
+
type: "boolean",
|
|
14556
|
+
description: "Must be true to actually delete. Without it the tool returns the field that WOULD be deleted and does nothing \u2014 a safety gate, because deletion drops the field's values from every lead."
|
|
14557
|
+
}
|
|
14558
|
+
},
|
|
14559
|
+
required: ["id"],
|
|
14560
|
+
additionalProperties: false
|
|
14561
|
+
},
|
|
14562
|
+
outputSchema: {
|
|
14563
|
+
type: "object",
|
|
14564
|
+
properties: {
|
|
14565
|
+
id: { type: "string" },
|
|
14566
|
+
name: { type: "string" },
|
|
14567
|
+
type: { type: "string" },
|
|
14568
|
+
deleted: {
|
|
14569
|
+
type: "boolean",
|
|
14570
|
+
description: "True when the field was deleted; false when confirm was not set."
|
|
14571
|
+
},
|
|
14572
|
+
hint: {
|
|
14573
|
+
type: "string",
|
|
14574
|
+
description: "Guidance \u2014 present when confirm was missing (re-call with confirm:true)."
|
|
14575
|
+
}
|
|
14576
|
+
},
|
|
14577
|
+
required: ["id", "deleted"]
|
|
14578
|
+
},
|
|
14579
|
+
execute: async (client, params) => {
|
|
14580
|
+
const id = String(params.id ?? "").trim();
|
|
14581
|
+
if (!id) {
|
|
14582
|
+
throw client.makeError("CUSTOM_FIELD_ID_REQUIRED", "id must be a non-empty string", "Pass the custom field id from leadbay_list_mappable_fields (the numeric id, not 'CUSTOM.<id>').", "DELETE /crm/custom_fields/{id}");
|
|
14583
|
+
}
|
|
14584
|
+
const catalog = await client.request("GET", "/crm/custom_fields");
|
|
14585
|
+
const current = (catalog ?? []).find((f) => String(f.id) === id);
|
|
14586
|
+
if (!current) {
|
|
14587
|
+
throw client.makeError("CUSTOM_FIELD_NOT_FOUND", `no custom field with id ${id} on this org`, "Call leadbay_list_mappable_fields to see the available custom fields and their ids.", "DELETE /crm/custom_fields/{id}");
|
|
14588
|
+
}
|
|
14589
|
+
if (params.confirm !== true) {
|
|
14590
|
+
return {
|
|
14591
|
+
id,
|
|
14592
|
+
name: current.name,
|
|
14593
|
+
type: current.type,
|
|
14594
|
+
deleted: false,
|
|
14595
|
+
hint: `Deleting "${current.name}" removes its values from every lead and breaks any import mapping using CUSTOM.${id}. Re-call with confirm:true to proceed.`
|
|
14596
|
+
};
|
|
14597
|
+
}
|
|
14598
|
+
await client.requestVoid("DELETE", `/crm/custom_fields/${id}`);
|
|
14599
|
+
return {
|
|
14600
|
+
id,
|
|
14601
|
+
name: current.name,
|
|
14602
|
+
type: current.type,
|
|
14603
|
+
deleted: true
|
|
14604
|
+
};
|
|
14605
|
+
}
|
|
14606
|
+
};
|
|
14607
|
+
|
|
14003
14608
|
// ../core/dist/tools/like-lead.js
|
|
14004
14609
|
var likeLead = {
|
|
14005
14610
|
name: "leadbay_like_lead",
|
|
@@ -16364,6 +16969,302 @@ var researchLeadByNameFuzzy = {
|
|
|
16364
16969
|
}
|
|
16365
16970
|
};
|
|
16366
16971
|
|
|
16972
|
+
// ../core/dist/composite/get-qualification-questions.js
|
|
16973
|
+
var getQualificationQuestions = {
|
|
16974
|
+
name: "leadbay_get_qualification_questions",
|
|
16975
|
+
annotations: {
|
|
16976
|
+
title: "Read the org's qualification questions",
|
|
16977
|
+
readOnlyHint: true,
|
|
16978
|
+
destructiveHint: false,
|
|
16979
|
+
idempotentHint: true,
|
|
16980
|
+
openWorldHint: true
|
|
16981
|
+
},
|
|
16982
|
+
description: leadbay_get_qualification_questions,
|
|
16983
|
+
inputSchema: {
|
|
16984
|
+
type: "object",
|
|
16985
|
+
properties: {},
|
|
16986
|
+
additionalProperties: false
|
|
16987
|
+
},
|
|
16988
|
+
outputSchema: {
|
|
16989
|
+
type: "object",
|
|
16990
|
+
properties: {
|
|
16991
|
+
qualification_questions: {
|
|
16992
|
+
type: "array",
|
|
16993
|
+
description: "Org-level questions Leadbay scores every lead against. Each: {question, created_at, lang}.",
|
|
16994
|
+
items: { type: "object" }
|
|
16995
|
+
},
|
|
16996
|
+
count: {
|
|
16997
|
+
type: "number",
|
|
16998
|
+
description: "Number of qualification questions configured."
|
|
16999
|
+
},
|
|
17000
|
+
is_admin: {
|
|
17001
|
+
type: "boolean",
|
|
17002
|
+
description: "Whether the current bearer-token holder is an org admin. Admins can modify the questions via leadbay_set_qualification_questions."
|
|
17003
|
+
},
|
|
17004
|
+
region: { type: "string" },
|
|
17005
|
+
hint: {
|
|
17006
|
+
type: "string",
|
|
17007
|
+
description: "Operator note \u2014 admin edit pointer, or the empty-state message when no questions are configured."
|
|
17008
|
+
},
|
|
17009
|
+
_meta: { type: "object" }
|
|
17010
|
+
},
|
|
17011
|
+
required: ["qualification_questions"]
|
|
17012
|
+
},
|
|
17013
|
+
execute: async (client, _params, ctx) => {
|
|
17014
|
+
const me = await client.resolveMe().catch(() => null);
|
|
17015
|
+
const isAdmin = me?.admin ?? false;
|
|
17016
|
+
const orgId = me?.organization?.id ?? await client.resolveOrgId();
|
|
17017
|
+
const questions = await client.request("GET", `/organizations/${orgId}/ai_agent_questions`) ?? [];
|
|
17018
|
+
let hint;
|
|
17019
|
+
if (questions.length === 0) {
|
|
17020
|
+
hint = "No qualification questions configured yet. Use leadbay_set_qualification_questions to add some, or leadbay_refine_prompt to shape the AI agent.";
|
|
17021
|
+
} else if (isAdmin) {
|
|
17022
|
+
hint = "You're an org admin \u2014 use leadbay_set_qualification_questions to add, remove, or replace these questions.";
|
|
17023
|
+
}
|
|
17024
|
+
return withAgentMemoryMeta(client, {
|
|
17025
|
+
qualification_questions: questions.map((q) => ({
|
|
17026
|
+
question: q.question,
|
|
17027
|
+
created_at: q.created_at,
|
|
17028
|
+
lang: q.lang
|
|
17029
|
+
})),
|
|
17030
|
+
count: questions.length,
|
|
17031
|
+
is_admin: isAdmin,
|
|
17032
|
+
region: client.region,
|
|
17033
|
+
...hint ? { hint } : {}
|
|
17034
|
+
}, ctx);
|
|
17035
|
+
}
|
|
17036
|
+
};
|
|
17037
|
+
|
|
17038
|
+
// ../core/dist/composite/set-qualification-questions.js
|
|
17039
|
+
var setQualificationQuestions = {
|
|
17040
|
+
name: "leadbay_set_qualification_questions",
|
|
17041
|
+
annotations: {
|
|
17042
|
+
title: "Modify the org's qualification questions",
|
|
17043
|
+
readOnlyHint: false,
|
|
17044
|
+
destructiveHint: true,
|
|
17045
|
+
idempotentHint: false,
|
|
17046
|
+
openWorldHint: true
|
|
17047
|
+
},
|
|
17048
|
+
description: leadbay_set_qualification_questions,
|
|
17049
|
+
write: true,
|
|
17050
|
+
inputSchema: {
|
|
17051
|
+
type: "object",
|
|
17052
|
+
properties: {
|
|
17053
|
+
questions: {
|
|
17054
|
+
type: "array",
|
|
17055
|
+
items: { type: "string" },
|
|
17056
|
+
description: "Full replacement list of qualification questions (replaces ALL current questions). Mutually exclusive with add/remove."
|
|
17057
|
+
},
|
|
17058
|
+
add: {
|
|
17059
|
+
type: "array",
|
|
17060
|
+
items: { type: "string" },
|
|
17061
|
+
description: "Questions to append to the current list (deduped). Mutually exclusive with `questions`."
|
|
17062
|
+
},
|
|
17063
|
+
remove: {
|
|
17064
|
+
type: "array",
|
|
17065
|
+
items: { type: "string" },
|
|
17066
|
+
description: "Exact question strings to remove from the current list. Mutually exclusive with `questions`. A removal requires confirm:true."
|
|
17067
|
+
},
|
|
17068
|
+
confirm: {
|
|
17069
|
+
type: "boolean",
|
|
17070
|
+
description: "Required whenever the change DROPS ANY existing question \u2014 including a same-count swap or a `questions` replacement that omits a current question, not only when the list gets shorter (removing a question changes how every lead is scored). Without it, such a change is previewed and not applied. Pure additions never need confirm."
|
|
17071
|
+
}
|
|
17072
|
+
},
|
|
17073
|
+
additionalProperties: false
|
|
17074
|
+
},
|
|
17075
|
+
outputSchema: {
|
|
17076
|
+
type: "object",
|
|
17077
|
+
properties: {
|
|
17078
|
+
qualification_questions: {
|
|
17079
|
+
type: "array",
|
|
17080
|
+
description: "The questions AFTER the change. Each: {question}.",
|
|
17081
|
+
items: { type: "object" }
|
|
17082
|
+
},
|
|
17083
|
+
count: { type: "number" },
|
|
17084
|
+
previous_count: { type: "number" },
|
|
17085
|
+
changed: {
|
|
17086
|
+
type: "boolean",
|
|
17087
|
+
description: "True when the list was actually written; false on a no-op or an unconfirmed shrink."
|
|
17088
|
+
},
|
|
17089
|
+
region: { type: "string" },
|
|
17090
|
+
hint: {
|
|
17091
|
+
type: "string",
|
|
17092
|
+
description: "Operator note \u2014 confirm prompt on a shrink, or a no-op explanation."
|
|
17093
|
+
},
|
|
17094
|
+
_meta: { type: "object" }
|
|
17095
|
+
},
|
|
17096
|
+
required: ["qualification_questions", "count", "changed"]
|
|
17097
|
+
},
|
|
17098
|
+
execute: async (client, params, ctx) => {
|
|
17099
|
+
const hasSet = Array.isArray(params.questions);
|
|
17100
|
+
const hasAdd = Array.isArray(params.add) && params.add.length > 0;
|
|
17101
|
+
const hasRemove = Array.isArray(params.remove) && params.remove.length > 0;
|
|
17102
|
+
if (hasSet && (hasAdd || hasRemove)) {
|
|
17103
|
+
throw client.makeError("QUALIFICATION_QUESTIONS_BAD_ARGS", "`questions` (full replace) is mutually exclusive with add/remove", "Pass EITHER `questions` (the full new list) OR `add`/`remove`, not both.", "POST /organizations/{orgId}");
|
|
17104
|
+
}
|
|
17105
|
+
if (!hasSet && !hasAdd && !hasRemove) {
|
|
17106
|
+
throw client.makeError("QUALIFICATION_QUESTIONS_NO_CHANGE", "nothing to change \u2014 pass `questions`, `add`, or `remove`", "Provide a full `questions` list, or `add`/`remove` entries.", "POST /organizations/{orgId}");
|
|
17107
|
+
}
|
|
17108
|
+
const orgId = await client.resolveOrgId();
|
|
17109
|
+
const current = await client.request("GET", `/organizations/${orgId}/ai_agent_questions`);
|
|
17110
|
+
const currentQs = (current ?? []).map((q) => q.question);
|
|
17111
|
+
const norm = (s) => s.trim();
|
|
17112
|
+
let next;
|
|
17113
|
+
if (hasSet) {
|
|
17114
|
+
next = params.questions.map(norm).filter((s) => s.length > 0);
|
|
17115
|
+
} else {
|
|
17116
|
+
next = [...currentQs];
|
|
17117
|
+
if (hasRemove) {
|
|
17118
|
+
const drop = new Set(params.remove.map(norm));
|
|
17119
|
+
next = next.filter((q) => !drop.has(norm(q)));
|
|
17120
|
+
}
|
|
17121
|
+
if (hasAdd) {
|
|
17122
|
+
const seen2 = new Set(next.map(norm));
|
|
17123
|
+
for (const q of params.add.map(norm)) {
|
|
17124
|
+
if (q.length > 0 && !seen2.has(q)) {
|
|
17125
|
+
next.push(q);
|
|
17126
|
+
seen2.add(q);
|
|
17127
|
+
}
|
|
17128
|
+
}
|
|
17129
|
+
}
|
|
17130
|
+
}
|
|
17131
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17132
|
+
next = next.filter((q) => {
|
|
17133
|
+
const k = norm(q);
|
|
17134
|
+
if (seen.has(k))
|
|
17135
|
+
return false;
|
|
17136
|
+
seen.add(k);
|
|
17137
|
+
return true;
|
|
17138
|
+
});
|
|
17139
|
+
const MAX_QUESTIONS = 5;
|
|
17140
|
+
if (next.length > MAX_QUESTIONS) {
|
|
17141
|
+
throw client.makeError("QUALIFICATION_QUESTIONS_LIMIT", `too many questions: ${next.length} (max ${MAX_QUESTIONS})`, `Leadbay allows at most ${MAX_QUESTIONS} qualification questions. Remove some first (pass fewer in \`questions\`, or use \`remove\`), then add.`, "POST /organizations/{orgId}");
|
|
17142
|
+
}
|
|
17143
|
+
const previousCount = currentQs.length;
|
|
17144
|
+
const noChange = next.length === currentQs.length && next.every((q, i) => norm(q) === norm(currentQs[i] ?? ""));
|
|
17145
|
+
if (noChange) {
|
|
17146
|
+
return withAgentMemoryMeta(client, {
|
|
17147
|
+
qualification_questions: currentQs.map((q) => ({ question: q })),
|
|
17148
|
+
count: currentQs.length,
|
|
17149
|
+
previous_count: previousCount,
|
|
17150
|
+
changed: false,
|
|
17151
|
+
region: client.region,
|
|
17152
|
+
hint: "No change \u2014 the resulting list is identical to the current one. Pass different `add`/`remove` entries, or call leadbay_get_qualification_questions to review the current questions."
|
|
17153
|
+
}, ctx);
|
|
17154
|
+
}
|
|
17155
|
+
const removed = currentQs.filter((q) => !next.some((n) => norm(n) === norm(q)));
|
|
17156
|
+
if (removed.length > 0 && params.confirm !== true) {
|
|
17157
|
+
return withAgentMemoryMeta(client, {
|
|
17158
|
+
qualification_questions: currentQs.map((q) => ({ question: q })),
|
|
17159
|
+
count: currentQs.length,
|
|
17160
|
+
previous_count: previousCount,
|
|
17161
|
+
changed: false,
|
|
17162
|
+
region: client.region,
|
|
17163
|
+
hint: `Re-call with confirm:true to apply. This would remove ${removed.length} question(s): ${removed.map((q) => `"${q}"`).join(", ")}. Removing a question changes how every lead is scored.`
|
|
17164
|
+
}, ctx);
|
|
17165
|
+
}
|
|
17166
|
+
await client.requestVoid("POST", `/organizations/${orgId}`, {
|
|
17167
|
+
ai_agent_lead_questions: next
|
|
17168
|
+
});
|
|
17169
|
+
client.invalidateTasteProfile();
|
|
17170
|
+
return withAgentMemoryMeta(client, {
|
|
17171
|
+
qualification_questions: next.map((q) => ({ question: q })),
|
|
17172
|
+
count: next.length,
|
|
17173
|
+
previous_count: previousCount,
|
|
17174
|
+
changed: true,
|
|
17175
|
+
region: client.region
|
|
17176
|
+
}, ctx);
|
|
17177
|
+
}
|
|
17178
|
+
};
|
|
17179
|
+
|
|
17180
|
+
// ../core/dist/composite/get-lead-custom-fields.js
|
|
17181
|
+
var getLeadCustomFields = {
|
|
17182
|
+
name: "leadbay_get_lead_custom_fields",
|
|
17183
|
+
annotations: {
|
|
17184
|
+
title: "Read a lead's custom-field values",
|
|
17185
|
+
readOnlyHint: true,
|
|
17186
|
+
destructiveHint: false,
|
|
17187
|
+
idempotentHint: true,
|
|
17188
|
+
openWorldHint: true
|
|
17189
|
+
},
|
|
17190
|
+
description: leadbay_get_lead_custom_fields,
|
|
17191
|
+
inputSchema: {
|
|
17192
|
+
type: "object",
|
|
17193
|
+
properties: {
|
|
17194
|
+
leadId: { type: "string", description: "Lead UUID (required)" },
|
|
17195
|
+
lensId: {
|
|
17196
|
+
type: "number",
|
|
17197
|
+
description: "Lens id (escape hatch \u2014 normally omit; auto-resolves to the active lens)"
|
|
17198
|
+
}
|
|
17199
|
+
},
|
|
17200
|
+
required: ["leadId"],
|
|
17201
|
+
additionalProperties: false
|
|
17202
|
+
},
|
|
17203
|
+
outputSchema: {
|
|
17204
|
+
type: "object",
|
|
17205
|
+
properties: {
|
|
17206
|
+
lead_id: { type: "string" },
|
|
17207
|
+
custom_fields: {
|
|
17208
|
+
type: "array",
|
|
17209
|
+
description: "Custom-field VALUES on this lead. Each: {id, name, type, value}. Empty when the org has no custom fields or none are set on this lead.",
|
|
17210
|
+
items: { type: "object" }
|
|
17211
|
+
},
|
|
17212
|
+
count: { type: "number" },
|
|
17213
|
+
region: { type: "string" },
|
|
17214
|
+
hint: {
|
|
17215
|
+
type: "string",
|
|
17216
|
+
description: "Operator note \u2014 empty-state guidance, or a degradation note when the lead fetch returned entries without embedded definitions."
|
|
17217
|
+
},
|
|
17218
|
+
_meta: { type: "object" }
|
|
17219
|
+
},
|
|
17220
|
+
required: ["custom_fields", "lead_id"]
|
|
17221
|
+
},
|
|
17222
|
+
execute: async (client, params, ctx) => {
|
|
17223
|
+
const lensId = params.lensId ?? await client.resolveDefaultLens();
|
|
17224
|
+
void client.request("POST", "/interactions", [
|
|
17225
|
+
{ type: "LEAD_SEEN", leadId: params.leadId, lensId: String(lensId) },
|
|
17226
|
+
{ type: "LEAD_CLICKED", leadId: params.leadId, lensId: String(lensId) }
|
|
17227
|
+
]).catch(() => {
|
|
17228
|
+
});
|
|
17229
|
+
const lead = await client.request("GET", `/lenses/${lensId}/leads/${params.leadId}`);
|
|
17230
|
+
const entries = lead.custom_fields ?? [];
|
|
17231
|
+
const needsCatalog = entries.some((e) => !e?.field?.name);
|
|
17232
|
+
let catalog = null;
|
|
17233
|
+
if (needsCatalog) {
|
|
17234
|
+
try {
|
|
17235
|
+
catalog = await client.request("GET", "/crm/custom_fields");
|
|
17236
|
+
} catch (err) {
|
|
17237
|
+
ctx?.logger?.warn?.(`get_lead_custom_fields: catalog fallback failed: ${err?.message ?? err?.code ?? err}`);
|
|
17238
|
+
}
|
|
17239
|
+
}
|
|
17240
|
+
const byId = new Map((catalog ?? []).map((f) => [f.id, f]));
|
|
17241
|
+
const rows = entries.map((e) => {
|
|
17242
|
+
const bareId = e.id;
|
|
17243
|
+
const id = e.field?.id ?? bareId ?? "";
|
|
17244
|
+
const def = e.field ? void 0 : byId.get(String(id));
|
|
17245
|
+
return {
|
|
17246
|
+
id: String(id),
|
|
17247
|
+
name: e.field?.name ?? def?.name ?? null,
|
|
17248
|
+
type: e.field?.type ?? def?.type ?? null,
|
|
17249
|
+
value: e.value ?? null
|
|
17250
|
+
};
|
|
17251
|
+
});
|
|
17252
|
+
let hint;
|
|
17253
|
+
if (rows.length === 0) {
|
|
17254
|
+
hint = "This lead has no custom-field values. The org may have no custom fields defined \u2014 see leadbay_list_mappable_fields for the catalog, or set values via import (map a column to CUSTOM.<id>).";
|
|
17255
|
+
} else if (needsCatalog && rows.some((r) => r.name === null)) {
|
|
17256
|
+
hint = "Some custom fields could not be named (the lead payload omitted definitions and the catalog fetch failed). Retry, or check leadbay_list_mappable_fields.";
|
|
17257
|
+
}
|
|
17258
|
+
return withAgentMemoryMeta(client, {
|
|
17259
|
+
lead_id: params.leadId,
|
|
17260
|
+
custom_fields: rows,
|
|
17261
|
+
count: rows.length,
|
|
17262
|
+
region: client.region,
|
|
17263
|
+
...hint ? { hint } : {}
|
|
17264
|
+
}, ctx);
|
|
17265
|
+
}
|
|
17266
|
+
};
|
|
17267
|
+
|
|
16367
17268
|
// ../core/dist/composite/account-history.js
|
|
16368
17269
|
var accountHistory = {
|
|
16369
17270
|
name: "leadbay_account_history",
|
|
@@ -21314,6 +22215,15 @@ var compositeReadTools = [
|
|
|
21314
22215
|
campaignCallSheet,
|
|
21315
22216
|
researchLeadById,
|
|
21316
22217
|
researchLeadByNameFuzzy,
|
|
22218
|
+
// Org qualification questions — the AI-agent questions every lead is scored
|
|
22219
|
+
// against. ALWAYS exposed (default surface): "how are my leads qualified"
|
|
22220
|
+
// is a first-session question, and the underlying get_taste_profile is
|
|
22221
|
+
// ADVANCED-gated. Read-only; no MCP edit endpoint exists (issue #3768).
|
|
22222
|
+
getQualificationQuestions,
|
|
22223
|
+
// Per-lead custom-field VALUES. ALWAYS exposed: complements the always-on
|
|
22224
|
+
// list_mappable_fields (which returns DEFINITIONS only). The lead payload
|
|
22225
|
+
// embeds each field's definition, so no catalog join is needed (issue #3768).
|
|
22226
|
+
getLeadCustomFields,
|
|
21317
22227
|
// accountHistory layers FULL notes + activity timeline on top of research
|
|
21318
22228
|
// so the agent can write the US4 "why has this dormant account resurfaced"
|
|
21319
22229
|
// narrative in ONE call. ALWAYS exposed (compositeReadTools) — the underlying
|
|
@@ -21407,6 +22317,15 @@ var compositeWriteTools = [
|
|
|
21407
22317
|
// createCustomField is granular-shaped but file-import prompts depend on it
|
|
21408
22318
|
// to preserve source-system links without requiring advanced-tool exposure.
|
|
21409
22319
|
createCustomField,
|
|
22320
|
+
// update/delete custom field — same default-surface rationale as create.
|
|
22321
|
+
// delete is destructive (requires confirm:true). Both gated behind
|
|
22322
|
+
// LEADBAY_MCP_WRITE=1 in MCP.
|
|
22323
|
+
updateCustomField,
|
|
22324
|
+
deleteCustomField,
|
|
22325
|
+
// Modify the org's qualification questions (AI-agent questions). Full-replace
|
|
22326
|
+
// endpoint (POST /organizations/{orgId} {ai_agent_lead_questions:[...]}); the
|
|
22327
|
+
// tool reads current + applies add/remove/set. Shrinking requires confirm.
|
|
22328
|
+
setQualificationQuestions,
|
|
21410
22329
|
// addNote is granular-shaped but file-import prompts depend on it to preserve
|
|
21411
22330
|
// meaningful source-file notes after imports return lead ids.
|
|
21412
22331
|
addNote,
|
|
@@ -22831,7 +23750,7 @@ function parseWriteEnv(env = process.env) {
|
|
|
22831
23750
|
}
|
|
22832
23751
|
|
|
22833
23752
|
// src/http-server.ts
|
|
22834
|
-
var VERSION = true ? "0.
|
|
23753
|
+
var VERSION = true ? "0.23.1" : "0.0.0-dev";
|
|
22835
23754
|
var PORT = Number(process.env.PORT ?? 8080);
|
|
22836
23755
|
var HOST = process.env.HOST ?? "0.0.0.0";
|
|
22837
23756
|
var sseSessions = /* @__PURE__ */ new Map();
|