@mangomagic/cli 0.1.13 → 0.1.15
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/index.mjs +32 -10
- package/src/tools/run.mjs +59 -0
package/package.json
CHANGED
package/src/index.mjs
CHANGED
|
@@ -175,15 +175,7 @@ async function enterChatAfterLogin(startChat) {
|
|
|
175
175
|
await chat(actions(), { showHeader: false });
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
async function
|
|
179
|
-
if (loadToken()) {
|
|
180
|
-
process.stdout.write(`${DIM}You're already signed in. Continuing in MangoMagic.${RESET}\n`);
|
|
181
|
-
await playSplash({ mode: splashMode(), greetingLine: "Welcome back to MangoMagic." });
|
|
182
|
-
if (!startChat) home();
|
|
183
|
-
await enterChatAfterLogin(startChat);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
|
|
178
|
+
async function performDeviceLogin({ openInBrowser = true, startChat = false } = {}) {
|
|
187
179
|
await deviceLogin({
|
|
188
180
|
openInBrowser,
|
|
189
181
|
onCode: (start) => {
|
|
@@ -206,6 +198,36 @@ ${BOLD}Sign in to MangoMagic${RESET}
|
|
|
206
198
|
});
|
|
207
199
|
}
|
|
208
200
|
|
|
201
|
+
async function validateCachedToken() {
|
|
202
|
+
try {
|
|
203
|
+
await runCatalogTool("get_user_stats", {});
|
|
204
|
+
return true;
|
|
205
|
+
} catch (err) {
|
|
206
|
+
const message = String(err?.message ?? err);
|
|
207
|
+
if (/token.*rejected|not signed in|not_authenticated|token_revoked|token_expired/i.test(message)) {
|
|
208
|
+
clearToken();
|
|
209
|
+
process.stdout.write(`${DIM}The saved terminal approval is no longer valid. Starting a fresh browser approval.${RESET}\n`);
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
process.stdout.write(`${DIM}Could not verify the saved terminal approval right now; continuing with the cached device token.${RESET}\n`);
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async function login({ openInBrowser = true, startChat = false } = {}) {
|
|
218
|
+
if (loadToken()) {
|
|
219
|
+
process.stdout.write(`${DIM}This terminal is already approved for MangoMagic. Browser logout does not remove this device token.${RESET}\n`);
|
|
220
|
+
const stillValid = await validateCachedToken();
|
|
221
|
+
if (!stillValid) return performDeviceLogin({ openInBrowser, startChat });
|
|
222
|
+
await playSplash({ mode: splashMode(), greetingLine: "Welcome back to MangoMagic." });
|
|
223
|
+
if (!startChat) home();
|
|
224
|
+
await enterChatAfterLogin(startChat);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return performDeviceLogin({ openInBrowser, startChat });
|
|
229
|
+
}
|
|
230
|
+
|
|
209
231
|
async function enterChat() {
|
|
210
232
|
await playSplash({ mode: splashMode(), greetingLine: "Welcome to MangoMagic." });
|
|
211
233
|
await chat(actions());
|
|
@@ -213,7 +235,7 @@ async function enterChat() {
|
|
|
213
235
|
|
|
214
236
|
function logout() {
|
|
215
237
|
clearToken();
|
|
216
|
-
process.stdout.write("Signed out.\n");
|
|
238
|
+
process.stdout.write("Signed out of this terminal. Your browser session is separate.\n");
|
|
217
239
|
}
|
|
218
240
|
|
|
219
241
|
function whoami() {
|
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) {
|