@mangomagic/cli 0.1.13 → 0.1.14
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/package.json +1 -1
- package/src/tools/run.mjs +59 -0
package/package.json
CHANGED
package/src/tools/run.mjs
CHANGED
|
@@ -2,6 +2,56 @@ import { apiCall } from "../api.mjs";
|
|
|
2
2
|
import { ALL_MCP_TOOL_CATALOG } from "./catalog.mjs";
|
|
3
3
|
import { functionNameFromEdgeTool } from "./edge-functions.mjs";
|
|
4
4
|
|
|
5
|
+
function asArray(data) {
|
|
6
|
+
if (Array.isArray(data)) return data;
|
|
7
|
+
if (Array.isArray(data?.data)) return data.data;
|
|
8
|
+
if (Array.isArray(data?.items)) return data.items;
|
|
9
|
+
if (Array.isArray(data?.results)) return data.results;
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function leadName(lead) {
|
|
14
|
+
return [lead.first_name, lead.last_name].filter(Boolean).join(" ") || lead.title || lead.name || lead.email || lead.id || "Unnamed lead";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function qualifyFromLeads(result) {
|
|
18
|
+
const leads = asArray(result);
|
|
19
|
+
const recommendations = leads.map((lead) => {
|
|
20
|
+
const hasEmail = Boolean(lead.email || lead.metadata?.email);
|
|
21
|
+
const hasProfile = Boolean(lead.profile_url || lead.metadata?.profile_url);
|
|
22
|
+
const enrichmentStatus = lead.enrichment_status || lead.metadata?.enrichment_status || "unknown";
|
|
23
|
+
const score = (hasEmail ? 45 : 0) + (hasProfile ? 30 : 0) + (enrichmentStatus === "pending" ? 10 : 20);
|
|
24
|
+
return {
|
|
25
|
+
id: lead.id,
|
|
26
|
+
name: leadName(lead),
|
|
27
|
+
email: lead.email || lead.metadata?.email || null,
|
|
28
|
+
profileUrl: lead.profile_url || lead.metadata?.profile_url || null,
|
|
29
|
+
stage: lead.stage || lead.metadata?.stage || null,
|
|
30
|
+
enrichmentStatus,
|
|
31
|
+
score: Math.min(score, 100),
|
|
32
|
+
nextAction: enrichmentStatus === "pending" ? "Enrich this guest, then draft outreach." : "Draft outreach or invite to a recording.",
|
|
33
|
+
};
|
|
34
|
+
}).sort((a, b) => b.score - a.score);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
tool: "qualify_leads",
|
|
38
|
+
data: {
|
|
39
|
+
analysed: recommendations.length,
|
|
40
|
+
contactable: recommendations.filter((lead) => lead.email || lead.profileUrl).length,
|
|
41
|
+
needsEnrichment: recommendations.filter((lead) => lead.enrichmentStatus === "pending").length,
|
|
42
|
+
recommendations,
|
|
43
|
+
},
|
|
44
|
+
items: recommendations.slice(0, 10).map((lead) => ({
|
|
45
|
+
type: "lead_recommendation",
|
|
46
|
+
id: lead.id,
|
|
47
|
+
title: `${lead.name} (${lead.score}/100)`,
|
|
48
|
+
subtitle: lead.nextAction,
|
|
49
|
+
link: lead.id ? `/leads?id=${lead.id}` : undefined,
|
|
50
|
+
metadata: lead,
|
|
51
|
+
})),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
5
55
|
const BUILTIN_TOOL_HANDLERS = {
|
|
6
56
|
list_episodes: async ({ limit = 10 }) => apiCall("cli-list-episodes", { body: { limit } }),
|
|
7
57
|
get_episode: async ({ episode }) => apiCall("cli-get-episode", { body: { episode } }),
|
|
@@ -12,6 +62,15 @@ const BUILTIN_TOOL_HANDLERS = {
|
|
|
12
62
|
count: Math.max(1, Math.min(Number(count || 3), 10)),
|
|
13
63
|
},
|
|
14
64
|
}),
|
|
65
|
+
qualify_leads: async ({ stage = "all", limit = 10 } = {}) => {
|
|
66
|
+
const leads = await apiCall("magic-assistant", {
|
|
67
|
+
body: {
|
|
68
|
+
toolName: "get_user_leads",
|
|
69
|
+
args: { stage, limit: Math.max(1, Math.min(Number(limit || 10), 20)) },
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
return qualifyFromLeads(leads);
|
|
73
|
+
},
|
|
15
74
|
};
|
|
16
75
|
|
|
17
76
|
export function findTool(name) {
|