@paigy/mcp 0.34.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-X42EUXML.js → chunk-PRC6GKRN.js} +2113 -647
- package/dist/chunk-UG2FARVV.js +54 -0
- package/dist/chunk-VWVZLPZD.js +143 -0
- package/dist/{chunk-45CIZLCJ.js → chunk-WNE6STMA.js} +668 -463
- package/dist/chunk-XIPO3U6I.js +309 -0
- package/dist/enable.js +3 -2
- package/dist/index.js +110 -349
- package/dist/listen.js +31 -34
- package/dist/onboard.js +59 -42
- package/dist/statusline.js +1 -1
- package/package.json +7 -7
- package/dist/chunk-G2WR7FCJ.js +0 -177
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/message.ts
|
|
2
|
+
function contactMessage(result) {
|
|
3
|
+
const units = result.plan?.units ?? [];
|
|
4
|
+
const waitNow = units.some((unit) => unit.level === "call") || units.length > 0 && units.every((unit) => unit.settled);
|
|
5
|
+
return result.message && waitNow ? `${result.message} Call await_reply now with this notificationId.` : result.message;
|
|
6
|
+
}
|
|
7
|
+
function answerText(answer) {
|
|
8
|
+
switch (answer.kind) {
|
|
9
|
+
case "text":
|
|
10
|
+
return answer.text;
|
|
11
|
+
case "option":
|
|
12
|
+
return answer.label ?? answer.optionId;
|
|
13
|
+
case "multi":
|
|
14
|
+
case "ranked":
|
|
15
|
+
return (answer.labels ?? answer.optionIds).join(", ");
|
|
16
|
+
case "confirm":
|
|
17
|
+
return answer.approved ? "approved" : "declined";
|
|
18
|
+
case "clarify":
|
|
19
|
+
return answer.chunks.join(" ");
|
|
20
|
+
case "turns":
|
|
21
|
+
return answer.turns.map((turn) => turn.reply).join(" ");
|
|
22
|
+
case "precedent":
|
|
23
|
+
return answer.answer;
|
|
24
|
+
case "ignored":
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function awaitMessage(item) {
|
|
29
|
+
switch (item.type) {
|
|
30
|
+
case "partial":
|
|
31
|
+
return `The user is on the call. This is provisional: ${item.turn.reply}`;
|
|
32
|
+
case "idle":
|
|
33
|
+
return "Still waiting for the user. Call await_reply again with the same notificationId.";
|
|
34
|
+
case "remind":
|
|
35
|
+
return `The user asked to be reminded in ${item.remindInSeconds} seconds. Schedule a wake-up, then call await_reply again.`;
|
|
36
|
+
case "superseded":
|
|
37
|
+
return "This ask was superseded. Stop waiting on it and re-orient on the thread.";
|
|
38
|
+
case "reply": {
|
|
39
|
+
const ended = item.transcript !== void 0 || item.answer.kind === "turns" ? "The call ended. " : "";
|
|
40
|
+
if (item.answer.kind === "option" || item.answer.kind === "multi" || item.answer.kind === "ranked") {
|
|
41
|
+
return `${ended}The user chose ${answerText(item.answer)}.`;
|
|
42
|
+
}
|
|
43
|
+
if (item.answer.kind === "confirm") return `${ended}The user ${answerText(item.answer)}.`;
|
|
44
|
+
if (item.answer.kind === "ignored") return `${ended}The user did not answer.`;
|
|
45
|
+
return `${ended}The user replied: ${answerText(item.answer)}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export {
|
|
51
|
+
contactMessage,
|
|
52
|
+
answerText,
|
|
53
|
+
awaitMessage
|
|
54
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import {
|
|
2
|
+
deleteKeyFile,
|
|
3
|
+
fetchCredential,
|
|
4
|
+
finalizeE2ee,
|
|
5
|
+
isNetworkError,
|
|
6
|
+
pairStep,
|
|
7
|
+
readKeyFile,
|
|
8
|
+
requestCode,
|
|
9
|
+
saveKeyFile,
|
|
10
|
+
saveToken,
|
|
11
|
+
sleep,
|
|
12
|
+
startE2ee
|
|
13
|
+
} from "./chunk-PRC6GKRN.js";
|
|
14
|
+
|
|
15
|
+
// src/identity.ts
|
|
16
|
+
var CLIENT_LABELS = {
|
|
17
|
+
"claude-code": "Claude Code",
|
|
18
|
+
"claude-ai": "Claude",
|
|
19
|
+
cursor: "Cursor",
|
|
20
|
+
"cursor-vscode": "Cursor",
|
|
21
|
+
windsurf: "Windsurf",
|
|
22
|
+
cline: "Cline",
|
|
23
|
+
"roo-cline": "Roo Code",
|
|
24
|
+
continue: "Continue",
|
|
25
|
+
vscode: "VS Code",
|
|
26
|
+
"visual studio code": "VS Code",
|
|
27
|
+
zed: "Zed"
|
|
28
|
+
};
|
|
29
|
+
function suggestedAgentName(clientName) {
|
|
30
|
+
if (process.env.PAIGY_AGENT) return process.env.PAIGY_AGENT;
|
|
31
|
+
if (!clientName) return void 0;
|
|
32
|
+
return CLIENT_LABELS[clientName.toLowerCase()] ?? clientName.replace(/[-_]+/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/pairing.ts
|
|
36
|
+
async function resolvePairing(deviceCode, capMs, pollMs = 2e3) {
|
|
37
|
+
let kf = readKeyFile();
|
|
38
|
+
const start = Date.now();
|
|
39
|
+
while (Date.now() - start < capMs) {
|
|
40
|
+
let step;
|
|
41
|
+
try {
|
|
42
|
+
step = await pairStep(deviceCode, kf);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
if (isNetworkError(e)) {
|
|
45
|
+
await sleep(pollMs);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
return { kind: "error", message: e.message };
|
|
49
|
+
}
|
|
50
|
+
if (step.kind === "e2ee_aborted") {
|
|
51
|
+
deleteKeyFile();
|
|
52
|
+
kf = null;
|
|
53
|
+
await sleep(pollMs);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (step.kind === "awaiting_confirm") {
|
|
57
|
+
return { kind: "awaiting_confirm", sas: step.sas };
|
|
58
|
+
}
|
|
59
|
+
if (step.kind === "paired") {
|
|
60
|
+
saveToken(step.token);
|
|
61
|
+
if (!step.sas || !kf) {
|
|
62
|
+
deleteKeyFile();
|
|
63
|
+
return { kind: "paired", token: step.token };
|
|
64
|
+
}
|
|
65
|
+
const finalDeadline = Math.min(Date.now() + 1e4, start + capMs);
|
|
66
|
+
let e2ee = false;
|
|
67
|
+
while (Date.now() < finalDeadline) {
|
|
68
|
+
const cred = kf.userCode ? await fetchCredential(kf.userCode) : null;
|
|
69
|
+
if (cred && step.uikPub) {
|
|
70
|
+
e2ee = finalizeE2ee(kf, cred, step.uikPub);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
await sleep(pollMs);
|
|
74
|
+
}
|
|
75
|
+
if (!e2ee) deleteKeyFile();
|
|
76
|
+
return { kind: "paired", token: step.token, sas: step.sas, e2ee };
|
|
77
|
+
}
|
|
78
|
+
await sleep(pollMs);
|
|
79
|
+
}
|
|
80
|
+
return { kind: "pending" };
|
|
81
|
+
}
|
|
82
|
+
var bg = null;
|
|
83
|
+
var started = null;
|
|
84
|
+
async function startPairing(agent) {
|
|
85
|
+
if (started) return started;
|
|
86
|
+
const { keyFile, offer } = startE2ee();
|
|
87
|
+
const code = await requestCode(agent, offer);
|
|
88
|
+
started = {
|
|
89
|
+
verificationUri: code.verification_uri_complete,
|
|
90
|
+
userCode: code.user_code,
|
|
91
|
+
deviceCode: code.device_code,
|
|
92
|
+
expiresIn: code.expires_in
|
|
93
|
+
};
|
|
94
|
+
saveKeyFile({ ...keyFile, userCode: code.user_code });
|
|
95
|
+
startBackgroundPair(code.device_code, code.expires_in * 1e3);
|
|
96
|
+
return started;
|
|
97
|
+
}
|
|
98
|
+
function startBackgroundPair(deviceCode, budgetMs) {
|
|
99
|
+
const promise = resolvePairing(deviceCode, budgetMs).catch((e) => ({ kind: "error", message: e.message })).then((o) => {
|
|
100
|
+
if (bg?.deviceCode === deviceCode) bg.settled = o;
|
|
101
|
+
return o;
|
|
102
|
+
});
|
|
103
|
+
bg = { deviceCode, promise };
|
|
104
|
+
}
|
|
105
|
+
async function joinBackgroundPair(deviceCode, capMs) {
|
|
106
|
+
if (!bg || bg.deviceCode !== deviceCode) return null;
|
|
107
|
+
if (bg.settled) {
|
|
108
|
+
const s = bg.settled;
|
|
109
|
+
bg = null;
|
|
110
|
+
if (s.kind === "paired" || s.kind === "error") started = null;
|
|
111
|
+
return s;
|
|
112
|
+
}
|
|
113
|
+
const TIMEOUT = /* @__PURE__ */ Symbol("timeout");
|
|
114
|
+
const raced = await Promise.race([bg.promise, sleep(capMs).then(() => TIMEOUT)]);
|
|
115
|
+
if (raced !== TIMEOUT) {
|
|
116
|
+
bg = null;
|
|
117
|
+
if (raced.kind === "paired" || raced.kind === "error") started = null;
|
|
118
|
+
return raced;
|
|
119
|
+
}
|
|
120
|
+
if (bg?.settled) {
|
|
121
|
+
const s = bg.settled;
|
|
122
|
+
bg = null;
|
|
123
|
+
if (s.kind === "paired" || s.kind === "error") started = null;
|
|
124
|
+
return s;
|
|
125
|
+
}
|
|
126
|
+
return { kind: "pending" };
|
|
127
|
+
}
|
|
128
|
+
function cancelBackgroundPair() {
|
|
129
|
+
bg = null;
|
|
130
|
+
started = null;
|
|
131
|
+
}
|
|
132
|
+
function clearPairing(deviceCode) {
|
|
133
|
+
if (deviceCode && started?.deviceCode !== deviceCode) return;
|
|
134
|
+
cancelBackgroundPair();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export {
|
|
138
|
+
suggestedAgentName,
|
|
139
|
+
resolvePairing,
|
|
140
|
+
startPairing,
|
|
141
|
+
joinBackgroundPair,
|
|
142
|
+
clearPairing
|
|
143
|
+
};
|