privateer-agent 0.15.4 → 0.15.6
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/README.md +11 -0
- package/bin/boot-bundle.d.mts +2 -0
- package/bin/boot-bundle.mjs +44 -0
- package/bin/fresh-supervisor.d.mts +5 -1
- package/bin/fresh-supervisor.mjs +47 -10
- package/bin/privateer-launch.mjs +27 -3
- package/bin/privateer-subagent.mjs +5 -2
- package/bin/privateer-verify.mjs +12 -0
- package/bin/session-recovery.d.mts +53 -0
- package/bin/session-recovery.mjs +240 -0
- package/bin/session-seal-preload.mjs +17 -0
- package/bin/session-seal.d.mts +25 -0
- package/bin/session-seal.mjs +242 -0
- package/dist-boot/boot.mjs +3 -0
- package/dist-boot/c-27JKSMWL.mjs +1460 -0
- package/dist-boot/c-2BMRFV24.mjs +269 -0
- package/dist-boot/c-2CTF6JA3.mjs +166 -0
- package/dist-boot/c-2G3BBHRJ.mjs +84 -0
- package/dist-boot/c-2IDLKXX6.mjs +250 -0
- package/dist-boot/c-2NJD5VYM.mjs +8 -0
- package/dist-boot/c-2S5EEQPW.mjs +1602 -0
- package/dist-boot/c-2WRDCUVI.mjs +25 -0
- package/dist-boot/c-2YN3M256.mjs +14 -0
- package/dist-boot/c-37GM3GMU.mjs +187 -0
- package/dist-boot/c-3STKRSVO.mjs +2480 -0
- package/dist-boot/c-3TPV6TQQ.mjs +2320 -0
- package/dist-boot/c-3UVHLQDJ.mjs +225 -0
- package/dist-boot/c-42PUUZYC.mjs +697 -0
- package/dist-boot/c-4D5UMWVW.mjs +683 -0
- package/dist-boot/c-4ETZRMTA.mjs +46 -0
- package/dist-boot/c-4QT25BD5.mjs +1482 -0
- package/dist-boot/c-4WVR32AP.mjs +2579 -0
- package/dist-boot/c-5EMM567G.mjs +152 -0
- package/dist-boot/c-5FA4CV63.mjs +145 -0
- package/dist-boot/c-5GV3X3RB.mjs +14 -0
- package/dist-boot/c-5JCEPRIY.mjs +52 -0
- package/dist-boot/c-5NDKIIWT.mjs +16 -0
- package/dist-boot/c-5QL3AR26.mjs +4665 -0
- package/dist-boot/c-5XY6MFKN.mjs +5142 -0
- package/dist-boot/c-65UZIZC7.mjs +2897 -0
- package/dist-boot/c-6FUXKHOK.mjs +1969 -0
- package/dist-boot/c-6JHWQE4V.mjs +18242 -0
- package/dist-boot/c-6LOBR4I6.mjs +5280 -0
- package/dist-boot/c-6QHOZXKQ.mjs +14394 -0
- package/dist-boot/c-6ZO2SADQ.mjs +178 -0
- package/dist-boot/c-6ZORVVZP.mjs +1449 -0
- package/dist-boot/c-76QH4UCP.mjs +2441 -0
- package/dist-boot/c-77GO5L5Y.mjs +20982 -0
- package/dist-boot/c-7M23XFTN.mjs +5052 -0
- package/dist-boot/c-7TC367E2.mjs +32 -0
- package/dist-boot/c-7UOG7POX.mjs +1524 -0
- package/dist-boot/c-7VHP3FLN.mjs +376 -0
- package/dist-boot/c-A73JHZP2.mjs +13207 -0
- package/dist-boot/c-ABXULAFL.mjs +71 -0
- package/dist-boot/c-ANDD2AQO.mjs +74 -0
- package/dist-boot/c-AOY77AZL.mjs +1430 -0
- package/dist-boot/c-AXEPZ22I.mjs +108 -0
- package/dist-boot/c-B2Y7VNHU.mjs +427 -0
- package/dist-boot/c-B7VJUH73.mjs +77 -0
- package/dist-boot/c-BFW6CDVL.mjs +24 -0
- package/dist-boot/c-BHNIF2AR.mjs +188 -0
- package/dist-boot/c-BKF2O6BL.mjs +23 -0
- package/dist-boot/c-BOZXFTZN.mjs +8 -0
- package/dist-boot/c-BRNYJWZL.mjs +28 -0
- package/dist-boot/c-C3N4Z2HO.mjs +93 -0
- package/dist-boot/c-C4IV7ZFG.mjs +717 -0
- package/dist-boot/c-C5NK6UYV.mjs +793 -0
- package/dist-boot/c-C67644MB.mjs +1659 -0
- package/dist-boot/c-C6S2YB53.mjs +620 -0
- package/dist-boot/c-CDBEJSBF.mjs +37 -0
- package/dist-boot/c-CG47HBKU.mjs +435 -0
- package/dist-boot/c-CKCTWCT5.mjs +51 -0
- package/dist-boot/c-CN77DCGF.mjs +60 -0
- package/dist-boot/c-CRBXNKFO.mjs +1795 -0
- package/dist-boot/c-CRIHASQ6.mjs +973 -0
- package/dist-boot/c-CU4NGAUO.mjs +3786 -0
- package/dist-boot/c-CWRFLGQU.mjs +1883 -0
- package/dist-boot/c-CYQB2USO.mjs +32 -0
- package/dist-boot/c-DEE67DJO.mjs +379 -0
- package/dist-boot/c-DIFDBYOP.mjs +1258 -0
- package/dist-boot/c-DOSGVXDZ.mjs +34879 -0
- package/dist-boot/c-DR7XQI32.mjs +381 -0
- package/dist-boot/c-DTGPSB46.mjs +14666 -0
- package/dist-boot/c-DTHDNA4P.mjs +320 -0
- package/dist-boot/c-E4Z3Y5B5.mjs +3864 -0
- package/dist-boot/c-E66Z2TI7.mjs +203 -0
- package/dist-boot/c-EBU6RLRV.mjs +1527 -0
- package/dist-boot/c-EBZZNGSF.mjs +432 -0
- package/dist-boot/c-EC3LJ2KF.mjs +1032 -0
- package/dist-boot/c-EQBKXWNX.mjs +15829 -0
- package/dist-boot/c-EUEPIW4S.mjs +574 -0
- package/dist-boot/c-EX4YVWAT.mjs +378 -0
- package/dist-boot/c-EYZGSAJU.mjs +98 -0
- package/dist-boot/c-F75VRKY4.mjs +172 -0
- package/dist-boot/c-FH4NXKHV.mjs +177 -0
- package/dist-boot/c-FHNUCTEM.mjs +140 -0
- package/dist-boot/c-FJ5T42DS.mjs +5349 -0
- package/dist-boot/c-FPCNRL7G.mjs +1728 -0
- package/dist-boot/c-G4DLN7Q4.mjs +8 -0
- package/dist-boot/c-G56GYQFZ.mjs +2507 -0
- package/dist-boot/c-GLIOERDQ.mjs +1200 -0
- package/dist-boot/c-GMJ5HUBM.mjs +14 -0
- package/dist-boot/c-H3HSGMAQ.mjs +461 -0
- package/dist-boot/c-HIKTO6P7.mjs +275 -0
- package/dist-boot/c-I2MCJ34O.mjs +464 -0
- package/dist-boot/c-I3C6LBW4.mjs +765 -0
- package/dist-boot/c-I54OKQHW.mjs +387 -0
- package/dist-boot/c-IFSP3R4D.mjs +80 -0
- package/dist-boot/c-IZK77VB7.mjs +171 -0
- package/dist-boot/c-J3Y25UGE.mjs +54 -0
- package/dist-boot/c-J5IESS7W.mjs +27750 -0
- package/dist-boot/c-JJWZBY7L.mjs +254 -0
- package/dist-boot/c-JKTFXTGF.mjs +463 -0
- package/dist-boot/c-JN57AXQ4.mjs +77 -0
- package/dist-boot/c-KFIO6LUW.mjs +1096 -0
- package/dist-boot/c-KIEMEFWW.mjs +478 -0
- package/dist-boot/c-KIVXWBYD.mjs +28 -0
- package/dist-boot/c-KP6CRIP4.mjs +580 -0
- package/dist-boot/c-L26VOJX4.mjs +11558 -0
- package/dist-boot/c-L5GHWG5G.mjs +5988 -0
- package/dist-boot/c-M7NSQAKK.mjs +353 -0
- package/dist-boot/c-MCEWOPBW.mjs +56 -0
- package/dist-boot/c-MGPIEG7I.mjs +20 -0
- package/dist-boot/c-NREXJV3M.mjs +393 -0
- package/dist-boot/c-O5PP6CTX.mjs +162 -0
- package/dist-boot/c-OBQDHSXM.mjs +1774 -0
- package/dist-boot/c-OLQHHDD4.mjs +21 -0
- package/dist-boot/c-OXW4JQQH.mjs +319 -0
- package/dist-boot/c-P3D7ZUWN.mjs +1288 -0
- package/dist-boot/c-P4PQZVV5.mjs +948 -0
- package/dist-boot/c-P63T3XL2.mjs +26373 -0
- package/dist-boot/c-P6N5DQGZ.mjs +194 -0
- package/dist-boot/c-P7MLKQFC.mjs +58 -0
- package/dist-boot/c-PB3PZJL5.mjs +1276 -0
- package/dist-boot/c-PTN4S6G2.mjs +1259 -0
- package/dist-boot/c-PYCE5J7U.mjs +1083 -0
- package/dist-boot/c-Q4HYCRLB.mjs +19410 -0
- package/dist-boot/c-QUXMETGG.mjs +68 -0
- package/dist-boot/c-RDMJZCOX.mjs +356 -0
- package/dist-boot/c-ROGJK76M.mjs +17 -0
- package/dist-boot/c-RQJJ26T4.mjs +708 -0
- package/dist-boot/c-RSKCUPJF.mjs +7559 -0
- package/dist-boot/c-RVJU4O6P.mjs +37 -0
- package/dist-boot/c-S2RVHR3M.mjs +165 -0
- package/dist-boot/c-SKMK3PEE.mjs +91120 -0
- package/dist-boot/c-TI7SM4EG.mjs +20 -0
- package/dist-boot/c-TILJ6GXD.mjs +1235 -0
- package/dist-boot/c-TT6BCUJD.mjs +114 -0
- package/dist-boot/c-U4ITOXAN.mjs +2107 -0
- package/dist-boot/c-UGERXVO2.mjs +7120 -0
- package/dist-boot/c-UPBH5AXY.mjs +1363 -0
- package/dist-boot/c-US2PUNZL.mjs +597 -0
- package/dist-boot/c-UU4WZPPE.mjs +20 -0
- package/dist-boot/c-UWVIYPQS.mjs +39 -0
- package/dist-boot/c-V4RHQBPQ.mjs +17683 -0
- package/dist-boot/c-V5MRVK47.mjs +351 -0
- package/dist-boot/c-V6CL266R.mjs +1755 -0
- package/dist-boot/c-VJTMFKYE.mjs +14975 -0
- package/dist-boot/c-VJTRUKIB.mjs +773 -0
- package/dist-boot/c-W4IFSHPW.mjs +43 -0
- package/dist-boot/c-WETGB2CF.mjs +113 -0
- package/dist-boot/c-WO3QSZUU.mjs +1337 -0
- package/dist-boot/c-WQLH73TY.mjs +242 -0
- package/dist-boot/c-XL735JW5.mjs +500 -0
- package/dist-boot/c-Y7HADL5B.mjs +1107 -0
- package/dist-boot/c-YGQHSVSK.mjs +41 -0
- package/dist-boot/c-YMP2AMEB.mjs +10350 -0
- package/dist-boot/c-YRDO2WEF.mjs +12012 -0
- package/dist-boot/c-YUSTRATJ.mjs +8 -0
- package/dist-boot/c-Z2262R22.mjs +2697 -0
- package/dist-boot/c-Z4ALQMJC.mjs +709 -0
- package/dist-boot/c-Z5ZUQVUY.mjs +62 -0
- package/dist-boot/c-ZDZUKXF7.mjs +874 -0
- package/dist-boot/c-ZJYLGIC3.mjs +32 -0
- package/dist-boot/c-ZNA5CDMI.mjs +77 -0
- package/dist-boot/c-ZSO6DI3M.mjs +204 -0
- package/dist-boot/c-ZWUVHKMK.mjs +100 -0
- package/dist-boot/c-ZY4MESEW.mjs +832 -0
- package/dist-boot/c-ZZ5REI4L.mjs +329 -0
- package/dist-boot/cli.mjs +51 -0
- package/dist-boot/ext-anthropic-attribution.mjs +207 -0
- package/dist-boot/ext-pi-background-tasks.mjs +7234 -0
- package/dist-boot/ext-pi-subagents.mjs +37 -0
- package/dist-boot/ext-privateer-account.mjs +4426 -0
- package/dist-boot/ext-privateer-brand.mjs +5274 -0
- package/dist-boot/ext-privateer-codemode.mjs +37 -0
- package/dist-boot/ext-privateer-computer.mjs +626 -0
- package/dist-boot/ext-privateer-connect.mjs +1862 -0
- package/dist-boot/ext-privateer-context.mjs +323 -0
- package/dist-boot/ext-privateer-desktop.mjs +92 -0
- package/dist-boot/ext-privateer-final-audit.mjs +48 -0
- package/dist-boot/ext-privateer-fresh.mjs +81 -0
- package/dist-boot/ext-privateer-gate.mjs +5959 -0
- package/dist-boot/ext-privateer-hints.mjs +236 -0
- package/dist-boot/ext-privateer-media.mjs +2626 -0
- package/dist-boot/ext-privateer-models.mjs +3397 -0
- package/dist-boot/ext-privateer-posture.mjs +3006 -0
- package/dist-boot/ext-privateer-privacy.mjs +4578 -0
- package/dist-boot/ext-privateer-recovery.mjs +287 -0
- package/dist-boot/ext-privateer-speak.mjs +4754 -0
- package/dist-boot/ext-privateer-terminals.mjs +725 -0
- package/dist-boot/ext-privateer-tools.mjs +528 -0
- package/dist-boot/ext-privateer-truncation.mjs +74 -0
- package/dist-boot/ext-privateer-update.mjs +210 -0
- package/dist-boot/ext-privateer-vision.mjs +148 -0
- package/dist-boot/ext-privateer-web.mjs +543 -0
- package/dist-boot/ext-rpiv-ask-user-question.mjs +710 -0
- package/dist-boot/manifest.json +9 -0
- package/extensions/privateer-brand.ts +3 -1
- package/extensions/privateer-context.ts +4 -2
- package/extensions/privateer-final-audit.ts +17 -0
- package/extensions/privateer-gate.ts +55 -9
- package/extensions/privateer-recovery.ts +175 -0
- package/extensions/privateer-web.ts +4 -4
- package/package.json +3 -1
- package/patches/@earendil-works+pi-coding-agent+1.3.0.patch +199 -2
- package/patches/pi-background-tasks+2.6.10.patch +91 -7
- package/src/cli/chat.ts +7 -1
- package/src/config/moatManifest.json +2 -0
- package/src/config/whatsNew.json +4 -4
- package/src/context.ts +33 -5
- package/src/engine/finalAudit.ts +38 -0
- package/src/engine/stallWatchdog.ts +8 -1
- package/src/providers/account.ts +34 -3
- package/src/remote/attentionPush.ts +40 -0
- package/src/remote/liveTaskSession.ts +7 -1
- package/src/remote/relayClient.ts +38 -4
- package/src/remote/remoteBridge.ts +17 -0
- package/src/remote/transcriptSnapshot.ts +104 -0
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import{createRequire as __pvCR}from"node:module";import{fileURLToPath as __pvF}from"node:url";import{dirname as __pvD}from"node:path";const require=__pvCR(import.meta.url);const __pvUrl=(r)=>new URL(r,import.meta.url).href;const __pvFile=(r)=>__pvF(new URL(r,import.meta.url));
|
|
2
|
+
import {
|
|
3
|
+
mcpNamespace,
|
|
4
|
+
require_proper_lockfile,
|
|
5
|
+
validateMcpServerConfig
|
|
6
|
+
} from "./c-E4Z3Y5B5.mjs";
|
|
7
|
+
import {
|
|
8
|
+
CONFIG_DIR_NAME,
|
|
9
|
+
canonicalizePath,
|
|
10
|
+
projectConfigDirCandidates,
|
|
11
|
+
resolvePath,
|
|
12
|
+
stripBom
|
|
13
|
+
} from "./c-PTN4S6G2.mjs";
|
|
14
|
+
import {
|
|
15
|
+
__name,
|
|
16
|
+
__toESM
|
|
17
|
+
} from "./c-CN77DCGF.mjs";
|
|
18
|
+
|
|
19
|
+
// node_modules/@earendil-works/pi-coding-agent/dist/core/trust-manager.js
|
|
20
|
+
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
21
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
22
|
+
import { homedir } from "node:os";
|
|
23
|
+
import { dirname, join } from "node:path";
|
|
24
|
+
var TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES = [
|
|
25
|
+
"settings.json",
|
|
26
|
+
"mcp.json",
|
|
27
|
+
"extensions",
|
|
28
|
+
"skills",
|
|
29
|
+
"prompts",
|
|
30
|
+
"themes",
|
|
31
|
+
"SYSTEM.md",
|
|
32
|
+
"APPEND_SYSTEM.md"
|
|
33
|
+
];
|
|
34
|
+
function normalizeCwd(cwd) {
|
|
35
|
+
return canonicalizePath(resolvePath(cwd));
|
|
36
|
+
}
|
|
37
|
+
__name(normalizeCwd, "normalizeCwd");
|
|
38
|
+
function findNearestTrustEntry(data, cwd) {
|
|
39
|
+
let currentDir = normalizeCwd(cwd);
|
|
40
|
+
while (true) {
|
|
41
|
+
const value = data[currentDir];
|
|
42
|
+
if (value === true || value === false) {
|
|
43
|
+
return { path: currentDir, decision: value };
|
|
44
|
+
}
|
|
45
|
+
const parentDir = dirname(currentDir);
|
|
46
|
+
if (parentDir === currentDir) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
currentDir = parentDir;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
__name(findNearestTrustEntry, "findNearestTrustEntry");
|
|
53
|
+
function getProjectTrustParentPath(cwd) {
|
|
54
|
+
const trustPath = normalizeCwd(cwd);
|
|
55
|
+
const parentDir = dirname(trustPath);
|
|
56
|
+
return parentDir === trustPath ? void 0 : parentDir;
|
|
57
|
+
}
|
|
58
|
+
__name(getProjectTrustParentPath, "getProjectTrustParentPath");
|
|
59
|
+
function getProjectTrustOptions(cwd, options) {
|
|
60
|
+
const trustPath = normalizeCwd(cwd);
|
|
61
|
+
const trustOptions = [
|
|
62
|
+
{ label: "Trust", trusted: true, updates: [{ path: trustPath, decision: true }], savedPath: trustPath }
|
|
63
|
+
];
|
|
64
|
+
const parentPath = getProjectTrustParentPath(cwd);
|
|
65
|
+
if (parentPath !== void 0) {
|
|
66
|
+
trustOptions.push({
|
|
67
|
+
label: `Trust parent folder (${parentPath})`,
|
|
68
|
+
trusted: true,
|
|
69
|
+
updates: [
|
|
70
|
+
{ path: parentPath, decision: true },
|
|
71
|
+
{ path: trustPath, decision: null }
|
|
72
|
+
],
|
|
73
|
+
savedPath: parentPath
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (options?.includeSessionOnly) {
|
|
77
|
+
trustOptions.push({ label: "Trust (this session only)", trusted: true, updates: [] });
|
|
78
|
+
}
|
|
79
|
+
trustOptions.push({
|
|
80
|
+
label: "Do not trust",
|
|
81
|
+
trusted: false,
|
|
82
|
+
updates: [{ path: trustPath, decision: false }],
|
|
83
|
+
savedPath: trustPath
|
|
84
|
+
});
|
|
85
|
+
if (options?.includeSessionOnly) {
|
|
86
|
+
trustOptions.push({ label: "Do not trust (this session only)", trusted: false, updates: [] });
|
|
87
|
+
}
|
|
88
|
+
return trustOptions;
|
|
89
|
+
}
|
|
90
|
+
__name(getProjectTrustOptions, "getProjectTrustOptions");
|
|
91
|
+
function readTrustFile(path) {
|
|
92
|
+
if (!existsSync(path)) {
|
|
93
|
+
return {};
|
|
94
|
+
}
|
|
95
|
+
let parsed;
|
|
96
|
+
try {
|
|
97
|
+
parsed = JSON.parse(stripBom(readFileSync(path, "utf-8")));
|
|
98
|
+
} catch (error) {
|
|
99
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
100
|
+
throw new Error(`Failed to read trust store ${path}: ${message}`);
|
|
101
|
+
}
|
|
102
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
103
|
+
throw new Error(`Invalid trust store ${path}: expected an object`);
|
|
104
|
+
}
|
|
105
|
+
const data = {};
|
|
106
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
107
|
+
if (value !== true && value !== false && value !== null) {
|
|
108
|
+
throw new Error(`Invalid trust store ${path}: value for ${JSON.stringify(key)} must be true, false, or null`);
|
|
109
|
+
}
|
|
110
|
+
data[key] = value;
|
|
111
|
+
}
|
|
112
|
+
return data;
|
|
113
|
+
}
|
|
114
|
+
__name(readTrustFile, "readTrustFile");
|
|
115
|
+
function writeTrustFile(path, data) {
|
|
116
|
+
const sorted = {};
|
|
117
|
+
for (const key of Object.keys(data).sort()) {
|
|
118
|
+
const value = data[key];
|
|
119
|
+
if (value === true || value === false || value === null) {
|
|
120
|
+
sorted[key] = value;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
124
|
+
writeFileSync(path, `${JSON.stringify(sorted, null, 2)}
|
|
125
|
+
`, "utf-8");
|
|
126
|
+
}
|
|
127
|
+
__name(writeTrustFile, "writeTrustFile");
|
|
128
|
+
function acquireTrustLockSync(path) {
|
|
129
|
+
const trustDir = dirname(path);
|
|
130
|
+
mkdirSync(trustDir, { recursive: true });
|
|
131
|
+
const maxAttempts = 10;
|
|
132
|
+
const delayMs = 20;
|
|
133
|
+
let lastError;
|
|
134
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
135
|
+
try {
|
|
136
|
+
return import_proper_lockfile.default.lockSync(trustDir, { realpath: false, lockfilePath: `${path}.lock` });
|
|
137
|
+
} catch (error) {
|
|
138
|
+
const code = typeof error === "object" && error !== null && "code" in error ? String(error.code) : void 0;
|
|
139
|
+
if (code !== "ELOCKED" || attempt === maxAttempts) {
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
lastError = error;
|
|
143
|
+
const start = Date.now();
|
|
144
|
+
while (Date.now() - start < delayMs) {
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (lastError instanceof Error) {
|
|
149
|
+
throw lastError;
|
|
150
|
+
}
|
|
151
|
+
throw new Error("Failed to acquire trust store lock");
|
|
152
|
+
}
|
|
153
|
+
__name(acquireTrustLockSync, "acquireTrustLockSync");
|
|
154
|
+
function withTrustFileLock(path, fn) {
|
|
155
|
+
const release = acquireTrustLockSync(path);
|
|
156
|
+
try {
|
|
157
|
+
return fn();
|
|
158
|
+
} finally {
|
|
159
|
+
release();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
__name(withTrustFileLock, "withTrustFileLock");
|
|
163
|
+
function hasTrustRequiringProjectResources(cwd) {
|
|
164
|
+
const homeDir = canonicalizePath(resolvePath(process.env.HOME || homedir()));
|
|
165
|
+
const userAgentsSkillsDir = join(homeDir, ".agents", "skills");
|
|
166
|
+
let currentDir = canonicalizePath(resolvePath(cwd));
|
|
167
|
+
for (const configDir of projectConfigDirCandidates(currentDir)) {
|
|
168
|
+
if (TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES.some((entry) => existsSync(join(configDir, entry)))) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
while (true) {
|
|
173
|
+
const agentsSkillsDir = join(currentDir, ".agents", "skills");
|
|
174
|
+
if (agentsSkillsDir !== userAgentsSkillsDir && existsSync(agentsSkillsDir)) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
const parentDir = dirname(currentDir);
|
|
178
|
+
if (parentDir === currentDir) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
currentDir = parentDir;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
__name(hasTrustRequiringProjectResources, "hasTrustRequiringProjectResources");
|
|
185
|
+
var ProjectTrustStore = class {
|
|
186
|
+
static {
|
|
187
|
+
__name(this, "ProjectTrustStore");
|
|
188
|
+
}
|
|
189
|
+
trustPath;
|
|
190
|
+
constructor(agentDir) {
|
|
191
|
+
this.trustPath = join(resolvePath(agentDir), "trust.json");
|
|
192
|
+
}
|
|
193
|
+
get(cwd) {
|
|
194
|
+
return this.getEntry(cwd)?.decision ?? null;
|
|
195
|
+
}
|
|
196
|
+
getEntry(cwd) {
|
|
197
|
+
return withTrustFileLock(this.trustPath, () => {
|
|
198
|
+
const data = readTrustFile(this.trustPath);
|
|
199
|
+
return findNearestTrustEntry(data, cwd);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
set(cwd, decision) {
|
|
203
|
+
this.setMany([{ path: cwd, decision }]);
|
|
204
|
+
}
|
|
205
|
+
setMany(decisions) {
|
|
206
|
+
withTrustFileLock(this.trustPath, () => {
|
|
207
|
+
const data = readTrustFile(this.trustPath);
|
|
208
|
+
for (const { path, decision } of decisions) {
|
|
209
|
+
const key = normalizeCwd(path);
|
|
210
|
+
if (decision === null) {
|
|
211
|
+
delete data[key];
|
|
212
|
+
} else {
|
|
213
|
+
data[key] = decision;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
writeTrustFile(this.trustPath, data);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
// node_modules/@earendil-works/pi-coding-agent/dist/utils/open-browser.js
|
|
222
|
+
import { spawn } from "node:child_process";
|
|
223
|
+
function openBrowser(target) {
|
|
224
|
+
const [cmd, args] = process.platform === "darwin" ? ["open", [target]] : process.platform === "win32" ? ["rundll32", ["url.dll,FileProtocolHandler", target]] : ["xdg-open", [target]];
|
|
225
|
+
spawn(cmd, args, { stdio: "ignore", detached: true }).on("error", () => {
|
|
226
|
+
}).unref();
|
|
227
|
+
}
|
|
228
|
+
__name(openBrowser, "openBrowser");
|
|
229
|
+
|
|
230
|
+
// node_modules/@earendil-works/pi-coding-agent/dist/extensions/mcp/config.js
|
|
231
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
232
|
+
import { dirname as dirname2, join as join2 } from "node:path";
|
|
233
|
+
var OVERRIDE_KEYS = ["enabled", "exposure", "toolExposure"];
|
|
234
|
+
function isOverride(value) {
|
|
235
|
+
return value.command === void 0 && value.url === void 0 && value.type === void 0;
|
|
236
|
+
}
|
|
237
|
+
__name(isOverride, "isOverride");
|
|
238
|
+
function isRecord(value) {
|
|
239
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
240
|
+
}
|
|
241
|
+
__name(isRecord, "isRecord");
|
|
242
|
+
function readConfigFile(path, scope, state) {
|
|
243
|
+
const { servers, errors } = state;
|
|
244
|
+
if (!existsSync2(path))
|
|
245
|
+
return;
|
|
246
|
+
let parsed;
|
|
247
|
+
try {
|
|
248
|
+
parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
249
|
+
} catch (error) {
|
|
250
|
+
errors.push(`${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (!isRecord(parsed) || parsed.mcpServers !== void 0 && !isRecord(parsed.mcpServers)) {
|
|
254
|
+
errors.push(`${path}: expected an object with an "mcpServers" object`);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (typeof parsed.autoEnableCodemode === "boolean")
|
|
258
|
+
state.autoEnableCodemode = parsed.autoEnableCodemode;
|
|
259
|
+
else if (parsed.autoEnableCodemode !== void 0)
|
|
260
|
+
errors.push(`${path}: autoEnableCodemode must be a boolean`);
|
|
261
|
+
for (const [name, value] of Object.entries(parsed.mcpServers ?? {})) {
|
|
262
|
+
if (scope === "project" && isRecord(value) && isOverride(value)) {
|
|
263
|
+
const base = servers.get(name);
|
|
264
|
+
const extra = Object.keys(value).filter((key) => !OVERRIDE_KEYS.includes(key));
|
|
265
|
+
if (!base) {
|
|
266
|
+
errors.push(`${path}: server "${name}" needs "command" or "url", or a global server to override`);
|
|
267
|
+
} else if (extra.length > 0) {
|
|
268
|
+
errors.push(`${path}: server "${name}": an override can only set ${OVERRIDE_KEYS.join(", ")}`);
|
|
269
|
+
} else {
|
|
270
|
+
const config2 = validateMcpServerConfig(name, { ...base.config, ...value });
|
|
271
|
+
if (typeof config2 === "string")
|
|
272
|
+
errors.push(`${path}: ${config2}`);
|
|
273
|
+
else
|
|
274
|
+
servers.set(name, { ...base, config: config2, override: path });
|
|
275
|
+
}
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
const config = validateMcpServerConfig(name, value);
|
|
279
|
+
if (typeof config === "string") {
|
|
280
|
+
errors.push(`${path}: ${config}`);
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const clash = [...servers.keys()].find((other) => other !== name && mcpNamespace(other) === mcpNamespace(name));
|
|
284
|
+
if (clash) {
|
|
285
|
+
errors.push(`${path}: server "${name}" conflicts with "${clash}"`);
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (scope === "project" && "url" in config && config.auth) {
|
|
289
|
+
errors.push(`${path}: server "${name}": auth is only allowed in the global mcp.json`);
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
servers.set(name, { name, config, source: path, scope });
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
__name(readConfigFile, "readConfigFile");
|
|
296
|
+
function loadMcpConfig(options) {
|
|
297
|
+
const state = { servers: /* @__PURE__ */ new Map(), errors: [] };
|
|
298
|
+
readConfigFile(join2(options.agentDir, "mcp.json"), "global", state);
|
|
299
|
+
const projectConfig = options.projectTrusted ? join2(options.cwd, CONFIG_DIR_NAME, "mcp.json") : void 0;
|
|
300
|
+
if (projectConfig)
|
|
301
|
+
readConfigFile(projectConfig, "project", state);
|
|
302
|
+
return {
|
|
303
|
+
servers: [...state.servers.values()],
|
|
304
|
+
...state.autoEnableCodemode === void 0 ? {} : { autoEnableCodemode: state.autoEnableCodemode },
|
|
305
|
+
errors: state.errors,
|
|
306
|
+
...projectConfig ? { projectConfig } : {}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
__name(loadMcpConfig, "loadMcpConfig");
|
|
310
|
+
function updateMcpServerConfig(path, name, patch, options = {}) {
|
|
311
|
+
editMcpServers(path, (servers, parsed) => {
|
|
312
|
+
let server = servers?.[name];
|
|
313
|
+
if (server === void 0 && options.override) {
|
|
314
|
+
server = {};
|
|
315
|
+
parsed.mcpServers = { ...servers, [name]: server };
|
|
316
|
+
}
|
|
317
|
+
if (!isRecord(server))
|
|
318
|
+
throw new Error(`${path} does not define MCP server "${name}"`);
|
|
319
|
+
const keepDefaults = isOverride(server);
|
|
320
|
+
if (patch.enabled !== void 0) {
|
|
321
|
+
if (patch.enabled && !keepDefaults)
|
|
322
|
+
delete server.enabled;
|
|
323
|
+
else
|
|
324
|
+
server.enabled = patch.enabled;
|
|
325
|
+
}
|
|
326
|
+
if (patch.exposure !== void 0) {
|
|
327
|
+
if (patch.exposure === "codemode" && !keepDefaults)
|
|
328
|
+
delete server.exposure;
|
|
329
|
+
else
|
|
330
|
+
server.exposure = patch.exposure;
|
|
331
|
+
}
|
|
332
|
+
return true;
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
__name(updateMcpServerConfig, "updateMcpServerConfig");
|
|
336
|
+
function addMcpServerConfig(path, name, config) {
|
|
337
|
+
let replaced = false;
|
|
338
|
+
editMcpServers(path, (servers, parsed) => {
|
|
339
|
+
const target = servers ?? {};
|
|
340
|
+
replaced = target[name] !== void 0;
|
|
341
|
+
target[name] = config;
|
|
342
|
+
parsed.mcpServers = target;
|
|
343
|
+
return true;
|
|
344
|
+
});
|
|
345
|
+
return replaced;
|
|
346
|
+
}
|
|
347
|
+
__name(addMcpServerConfig, "addMcpServerConfig");
|
|
348
|
+
function removeMcpServerConfig(path, name) {
|
|
349
|
+
if (!existsSync2(path))
|
|
350
|
+
return false;
|
|
351
|
+
let removed = false;
|
|
352
|
+
editMcpServers(path, (servers) => {
|
|
353
|
+
if (!servers || servers[name] === void 0)
|
|
354
|
+
return false;
|
|
355
|
+
delete servers[name];
|
|
356
|
+
removed = true;
|
|
357
|
+
return true;
|
|
358
|
+
});
|
|
359
|
+
return removed;
|
|
360
|
+
}
|
|
361
|
+
__name(removeMcpServerConfig, "removeMcpServerConfig");
|
|
362
|
+
function editMcpServers(path, edit) {
|
|
363
|
+
const text = existsSync2(path) ? readFileSync2(path, "utf8") : void 0;
|
|
364
|
+
const parsed = text === void 0 ? {} : JSON.parse(text);
|
|
365
|
+
if (!isRecord(parsed) || parsed.mcpServers !== void 0 && !isRecord(parsed.mcpServers)) {
|
|
366
|
+
throw new Error(`${path}: expected an object with an "mcpServers" object`);
|
|
367
|
+
}
|
|
368
|
+
const servers = isRecord(parsed.mcpServers) ? parsed.mcpServers : void 0;
|
|
369
|
+
if (!edit(servers, parsed))
|
|
370
|
+
return;
|
|
371
|
+
const indent = text && /^([ \t]+)\S/m.exec(text)?.[1] || " ";
|
|
372
|
+
mkdirSync2(dirname2(path), { recursive: true });
|
|
373
|
+
writeFileSync2(path, `${JSON.stringify(parsed, null, indent)}
|
|
374
|
+
`);
|
|
375
|
+
}
|
|
376
|
+
__name(editMcpServers, "editMcpServers");
|
|
377
|
+
|
|
378
|
+
export {
|
|
379
|
+
getProjectTrustOptions,
|
|
380
|
+
hasTrustRequiringProjectResources,
|
|
381
|
+
ProjectTrustStore,
|
|
382
|
+
openBrowser,
|
|
383
|
+
loadMcpConfig,
|
|
384
|
+
updateMcpServerConfig,
|
|
385
|
+
addMcpServerConfig,
|
|
386
|
+
removeMcpServerConfig
|
|
387
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import{createRequire as __pvCR}from"node:module";import{fileURLToPath as __pvF}from"node:url";import{dirname as __pvD}from"node:path";const require=__pvCR(import.meta.url);const __pvUrl=(r)=>new URL(r,import.meta.url).href;const __pvFile=(r)=>__pvF(new URL(r,import.meta.url));
|
|
2
|
+
import {
|
|
3
|
+
__name
|
|
4
|
+
} from "./c-CN77DCGF.mjs";
|
|
5
|
+
|
|
6
|
+
// node_modules/pi-background-tasks/src/core/delegate/types.ts?ext=pi-background-tasks
|
|
7
|
+
var DELEGATE_SEED_SCHEMA_VERSION = "pi-background-tasks.delegate-seed.v2";
|
|
8
|
+
var DELEGATE_LEDGER_SCHEMA_VERSION = "pi-background-tasks.delegate-ledger.v1";
|
|
9
|
+
var DELEGATE_RESULT_PACKAGE_SCHEMA_VERSION = "pi-background-tasks.delegate-result.v1";
|
|
10
|
+
var DELEGATE_RECEIPT_SCHEMA_VERSION = "pi-background-tasks.delegate-receipt.v1";
|
|
11
|
+
var DELEGATE_BUDGET_PLAN_SCHEMA_VERSION = "pi-background-tasks.delegate-budget-plan.v3";
|
|
12
|
+
var DELEGATE_MANIFEST_SCHEMA_VERSION = "pi-background-tasks.delegate-manifest.v2";
|
|
13
|
+
var DELEGATE_CONTEXT_POLICY_ID = "delegate-inspect-v1";
|
|
14
|
+
var DELEGATE_BRANCH_FILTER_ID = "exclude-active-delegate-batch-v1";
|
|
15
|
+
var DELEGATE_TOOL_NAME = "bg_delegate";
|
|
16
|
+
var DELEGATE_RESULT_TOOL_NAME = "bg_result";
|
|
17
|
+
var DELEGATE_CAPABILITIES = ["inspect"];
|
|
18
|
+
var DELEGATE_EXTENSION_MODES = ["isolated", "ambient"];
|
|
19
|
+
var DELEGATE_AUTO_DELIVER_MODES = ["never", "when_small", "always"];
|
|
20
|
+
var DelegateError = class extends Error {
|
|
21
|
+
static {
|
|
22
|
+
__name(this, "DelegateError");
|
|
23
|
+
}
|
|
24
|
+
code;
|
|
25
|
+
childCreated;
|
|
26
|
+
taskId;
|
|
27
|
+
artifactDir;
|
|
28
|
+
budget;
|
|
29
|
+
preserved;
|
|
30
|
+
remediation;
|
|
31
|
+
constructor(message, details) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = "DelegateError";
|
|
34
|
+
this.code = details.code;
|
|
35
|
+
this.childCreated = details.childCreated ?? false;
|
|
36
|
+
this.taskId = details.taskId;
|
|
37
|
+
this.artifactDir = details.artifactDir;
|
|
38
|
+
this.budget = details.budget;
|
|
39
|
+
this.preserved = details.preserved ?? [];
|
|
40
|
+
this.remediation = details.remediation ?? [];
|
|
41
|
+
}
|
|
42
|
+
/** Operator-facing rendering: cause, preserved evidence, and next action. */
|
|
43
|
+
describe() {
|
|
44
|
+
const lines = [`[${this.code}] ${this.message}`];
|
|
45
|
+
lines.push(`Child process created: ${this.childCreated ? "yes" : "no"}`);
|
|
46
|
+
if (this.artifactDir !== void 0) lines.push(`Artifacts: ${this.artifactDir}`);
|
|
47
|
+
lines.push(
|
|
48
|
+
this.preserved.length > 0 ? `Preserved: ${this.preserved.join(", ")}` : "Preserved: nothing was written for this failure"
|
|
49
|
+
);
|
|
50
|
+
if (this.remediation.length > 0) lines.push(`Remediation: ${this.remediation.join(" ")}`);
|
|
51
|
+
return lines.join("\n");
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// node_modules/pi-background-tasks/src/core/delegate/facade-contract.ts?ext=pi-background-tasks
|
|
56
|
+
var DELEGATE_DEFAULT_MAX_TURNS = 24;
|
|
57
|
+
var DELEGATE_DEFAULT_MAX_TOOL_CALLS = 120;
|
|
58
|
+
var DELEGATE_DEFAULT_TIMEOUT_SECONDS = 1200;
|
|
59
|
+
var DELEGATE_INLINE_ANSWER_BYTES = 48 * 1024;
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
DELEGATE_SEED_SCHEMA_VERSION,
|
|
63
|
+
DELEGATE_LEDGER_SCHEMA_VERSION,
|
|
64
|
+
DELEGATE_RESULT_PACKAGE_SCHEMA_VERSION,
|
|
65
|
+
DELEGATE_RECEIPT_SCHEMA_VERSION,
|
|
66
|
+
DELEGATE_BUDGET_PLAN_SCHEMA_VERSION,
|
|
67
|
+
DELEGATE_MANIFEST_SCHEMA_VERSION,
|
|
68
|
+
DELEGATE_CONTEXT_POLICY_ID,
|
|
69
|
+
DELEGATE_BRANCH_FILTER_ID,
|
|
70
|
+
DELEGATE_TOOL_NAME,
|
|
71
|
+
DELEGATE_RESULT_TOOL_NAME,
|
|
72
|
+
DELEGATE_CAPABILITIES,
|
|
73
|
+
DELEGATE_EXTENSION_MODES,
|
|
74
|
+
DELEGATE_AUTO_DELIVER_MODES,
|
|
75
|
+
DelegateError,
|
|
76
|
+
DELEGATE_DEFAULT_MAX_TURNS,
|
|
77
|
+
DELEGATE_DEFAULT_MAX_TOOL_CALLS,
|
|
78
|
+
DELEGATE_DEFAULT_TIMEOUT_SECONDS,
|
|
79
|
+
DELEGATE_INLINE_ANSWER_BYTES
|
|
80
|
+
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import{createRequire as __pvCR}from"node:module";import{fileURLToPath as __pvF}from"node:url";import{dirname as __pvD}from"node:path";const require=__pvCR(import.meta.url);const __pvUrl=(r)=>new URL(r,import.meta.url).href;const __pvFile=(r)=>__pvF(new URL(r,import.meta.url));
|
|
2
|
+
import {
|
|
3
|
+
isRecord,
|
|
4
|
+
parseClassifierUsage,
|
|
5
|
+
postClassifierRequest,
|
|
6
|
+
requiredNumber
|
|
7
|
+
} from "./c-WETGB2CF.mjs";
|
|
8
|
+
import {
|
|
9
|
+
formatProviderError,
|
|
10
|
+
normalizeProviderError
|
|
11
|
+
} from "./c-ZWUVHKMK.mjs";
|
|
12
|
+
import "./c-EYZGSAJU.mjs";
|
|
13
|
+
import "./c-ZJYLGIC3.mjs";
|
|
14
|
+
import "./c-WO3QSZUU.mjs";
|
|
15
|
+
import "./c-S2RVHR3M.mjs";
|
|
16
|
+
import {
|
|
17
|
+
__name
|
|
18
|
+
} from "./c-CN77DCGF.mjs";
|
|
19
|
+
|
|
20
|
+
// node_modules/@earendil-works/pi-ai/dist/api/openai-decisions.js
|
|
21
|
+
var LABEL = "OpenAI Decisions";
|
|
22
|
+
var MAX_IMAGES = 128;
|
|
23
|
+
function predicateInstructions(question) {
|
|
24
|
+
const meanings = [
|
|
25
|
+
question.criteria.true ? `True means: ${question.criteria.true}` : "",
|
|
26
|
+
question.criteria.false ? `False means: ${question.criteria.false}` : ""
|
|
27
|
+
].filter(Boolean);
|
|
28
|
+
return meanings.length > 0 ? `${question.instructions}
|
|
29
|
+
|
|
30
|
+
${meanings.join("\n")}` : question.instructions;
|
|
31
|
+
}
|
|
32
|
+
__name(predicateInstructions, "predicateInstructions");
|
|
33
|
+
function wireQuestion(name, question) {
|
|
34
|
+
if (question.type === "choice") {
|
|
35
|
+
return {
|
|
36
|
+
type: "choice",
|
|
37
|
+
name,
|
|
38
|
+
instructions: question.instructions,
|
|
39
|
+
choices: Object.entries(question.criteria).map(([value, description]) => description ? { value, description } : { value })
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (question.type === "score") {
|
|
43
|
+
return {
|
|
44
|
+
type: "score",
|
|
45
|
+
name,
|
|
46
|
+
instructions: question.instructions,
|
|
47
|
+
levels: question.criteria.map((label) => ({ label }))
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return { type: "predicate", name, instructions: predicateInstructions(question) };
|
|
51
|
+
}
|
|
52
|
+
__name(wireQuestion, "wireQuestion");
|
|
53
|
+
function wireInput(context) {
|
|
54
|
+
const state = JSON.stringify(context.state);
|
|
55
|
+
const images = context.images ?? [];
|
|
56
|
+
if (images.length === 0)
|
|
57
|
+
return state;
|
|
58
|
+
if (images.length > MAX_IMAGES) {
|
|
59
|
+
throw new Error(`${LABEL} accepts at most ${MAX_IMAGES} images, got ${images.length}`);
|
|
60
|
+
}
|
|
61
|
+
return [
|
|
62
|
+
{
|
|
63
|
+
role: "user",
|
|
64
|
+
content: [
|
|
65
|
+
{ type: "input_text", text: state },
|
|
66
|
+
...images.map((image) => ({
|
|
67
|
+
type: "input_image",
|
|
68
|
+
image_url: `data:${image.mimeType};base64,${image.data}`
|
|
69
|
+
}))
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
__name(wireInput, "wireInput");
|
|
75
|
+
function choiceProbabilities(value, id) {
|
|
76
|
+
if (!Array.isArray(value))
|
|
77
|
+
throw new Error(`${LABEL} returned invalid probabilities for ${id}`);
|
|
78
|
+
return Object.fromEntries(value.map((entry) => {
|
|
79
|
+
if (!isRecord(entry) || typeof entry.value !== "string") {
|
|
80
|
+
throw new Error(`${LABEL} returned invalid probabilities for ${id}`);
|
|
81
|
+
}
|
|
82
|
+
return [entry.value, requiredNumber(LABEL, entry.probability, `probability for ${id}.${entry.value}`)];
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
__name(choiceProbabilities, "choiceProbabilities");
|
|
86
|
+
function parseAnswer(id, question, answer) {
|
|
87
|
+
if (answer.type === "refusal")
|
|
88
|
+
throw new Error(`${LABEL} refused to answer ${id}`);
|
|
89
|
+
if (question.type === "choice") {
|
|
90
|
+
if (answer.type !== "choice" || typeof answer.choice !== "string") {
|
|
91
|
+
throw new Error(`${LABEL} did not return a choice answer for ${id}`);
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
type: "choice",
|
|
95
|
+
choice: answer.choice,
|
|
96
|
+
probabilities: choiceProbabilities(answer.probabilities, id),
|
|
97
|
+
confidence: requiredNumber(LABEL, answer.confidence, `confidence for ${id}`)
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
if (question.type === "score") {
|
|
101
|
+
if (answer.type !== "score")
|
|
102
|
+
throw new Error(`${LABEL} did not return a score answer for ${id}`);
|
|
103
|
+
return {
|
|
104
|
+
type: "score",
|
|
105
|
+
score: requiredNumber(LABEL, answer.score, `score for ${id}`),
|
|
106
|
+
confidence: requiredNumber(LABEL, answer.confidence, `confidence for ${id}`)
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (answer.type !== "predicate")
|
|
110
|
+
throw new Error(`${LABEL} did not return a predicate answer for ${id}`);
|
|
111
|
+
return { type: "bool", probability: requiredNumber(LABEL, answer.probability, `probability for ${id}`) };
|
|
112
|
+
}
|
|
113
|
+
__name(parseAnswer, "parseAnswer");
|
|
114
|
+
function parseAnswers(value, context) {
|
|
115
|
+
if (!Array.isArray(value))
|
|
116
|
+
throw new Error(`${LABEL} returned an unexpected response`);
|
|
117
|
+
const byName = /* @__PURE__ */ new Map();
|
|
118
|
+
for (const answer of value) {
|
|
119
|
+
if (isRecord(answer) && typeof answer.name === "string")
|
|
120
|
+
byName.set(answer.name, answer);
|
|
121
|
+
}
|
|
122
|
+
return Object.fromEntries(Object.entries(context.questions).map(([id, question]) => {
|
|
123
|
+
const answer = byName.get(id);
|
|
124
|
+
if (!answer)
|
|
125
|
+
throw new Error(`${LABEL} did not return an answer for ${id}`);
|
|
126
|
+
return [id, parseAnswer(id, question, answer)];
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
__name(parseAnswers, "parseAnswers");
|
|
130
|
+
var NO_RETRY_STATUSES = [504];
|
|
131
|
+
function errorMessage(error) {
|
|
132
|
+
if (error.status === 504) {
|
|
133
|
+
return `${LABEL} error (504): the request timed out at the gateway. Very large inputs (above roughly 600K tokens) currently exceed its time limit.`;
|
|
134
|
+
}
|
|
135
|
+
return formatProviderError(normalizeProviderError(error), `${LABEL} error`);
|
|
136
|
+
}
|
|
137
|
+
__name(errorMessage, "errorMessage");
|
|
138
|
+
var classify = /* @__PURE__ */ __name(async (model, context, options) => {
|
|
139
|
+
const output = {
|
|
140
|
+
api: model.api,
|
|
141
|
+
provider: model.provider,
|
|
142
|
+
model: model.id,
|
|
143
|
+
answers: {},
|
|
144
|
+
stopReason: "stop",
|
|
145
|
+
timestamp: Date.now()
|
|
146
|
+
};
|
|
147
|
+
try {
|
|
148
|
+
if (model.api !== "openai-decisions")
|
|
149
|
+
throw new Error(`Unsupported classifier API: ${model.api}`);
|
|
150
|
+
const body = await postClassifierRequest(LABEL, new URL("decisions", `${model.baseUrl.replace(/\/+$/u, "")}/`), model, {
|
|
151
|
+
model: model.id,
|
|
152
|
+
input: wireInput(context),
|
|
153
|
+
questions: Object.entries(context.questions).map(([id, question]) => wireQuestion(id, question))
|
|
154
|
+
}, options, NO_RETRY_STATUSES);
|
|
155
|
+
if (!isRecord(body))
|
|
156
|
+
throw new Error(`${LABEL} returned an unexpected response`);
|
|
157
|
+
const usage = parseClassifierUsage(body.usage, model);
|
|
158
|
+
if (usage)
|
|
159
|
+
output.usage = usage;
|
|
160
|
+
output.answers = parseAnswers(body.answers, context);
|
|
161
|
+
return output;
|
|
162
|
+
} catch (error) {
|
|
163
|
+
output.answers = {};
|
|
164
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
165
|
+
output.errorMessage = errorMessage(error);
|
|
166
|
+
return output;
|
|
167
|
+
}
|
|
168
|
+
}, "classify");
|
|
169
|
+
export {
|
|
170
|
+
classify
|
|
171
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import{createRequire as __pvCR}from"node:module";import{fileURLToPath as __pvF}from"node:url";import{dirname as __pvD}from"node:path";const require=__pvCR(import.meta.url);const __pvUrl=(r)=>new URL(r,import.meta.url).href;const __pvFile=(r)=>__pvF(new URL(r,import.meta.url));
|
|
2
|
+
import {
|
|
3
|
+
classifySystemOne
|
|
4
|
+
} from "./c-TT6BCUJD.mjs";
|
|
5
|
+
import {
|
|
6
|
+
isRecord
|
|
7
|
+
} from "./c-WETGB2CF.mjs";
|
|
8
|
+
import "./c-ZWUVHKMK.mjs";
|
|
9
|
+
import "./c-EYZGSAJU.mjs";
|
|
10
|
+
import "./c-ZJYLGIC3.mjs";
|
|
11
|
+
import "./c-WO3QSZUU.mjs";
|
|
12
|
+
import "./c-S2RVHR3M.mjs";
|
|
13
|
+
import {
|
|
14
|
+
__name
|
|
15
|
+
} from "./c-CN77DCGF.mjs";
|
|
16
|
+
|
|
17
|
+
// node_modules/@earendil-works/pi-ai/dist/api/cloudflare-workers-ai-system-one.js
|
|
18
|
+
var LABEL = "Cloudflare Workers AI";
|
|
19
|
+
function cloudflareErrorMessage(errors) {
|
|
20
|
+
if (Array.isArray(errors)) {
|
|
21
|
+
const messages = errors.map((error) => isRecord(error) && typeof error.message === "string" ? error.message : void 0).filter((message) => message !== void 0);
|
|
22
|
+
if (messages.length > 0)
|
|
23
|
+
return `${LABEL} error: ${messages.join("; ")}`;
|
|
24
|
+
}
|
|
25
|
+
return `${LABEL} request failed`;
|
|
26
|
+
}
|
|
27
|
+
__name(cloudflareErrorMessage, "cloudflareErrorMessage");
|
|
28
|
+
var transport = {
|
|
29
|
+
api: "cloudflare-workers-ai-system-one",
|
|
30
|
+
label: LABEL,
|
|
31
|
+
url: /* @__PURE__ */ __name((model) => new URL("run", `${model.baseUrl.replace(/\/+$/u, "")}/`), "url"),
|
|
32
|
+
payload: /* @__PURE__ */ __name((model, request) => ({ model: model.id, input: request }), "payload"),
|
|
33
|
+
output: /* @__PURE__ */ __name((body) => {
|
|
34
|
+
if (!isRecord(body))
|
|
35
|
+
throw new Error(`${LABEL} returned an unexpected response`);
|
|
36
|
+
if (body.success === false)
|
|
37
|
+
throw new Error(cloudflareErrorMessage(body.errors));
|
|
38
|
+
const result = body.result;
|
|
39
|
+
if (!isRecord(result))
|
|
40
|
+
throw new Error(`${LABEL} returned an unexpected response`);
|
|
41
|
+
if ("answers" in result)
|
|
42
|
+
return result;
|
|
43
|
+
if (result.state !== "Completed") {
|
|
44
|
+
throw new Error(`${LABEL} run did not complete (state: ${String(result.state)})`);
|
|
45
|
+
}
|
|
46
|
+
if (!isRecord(result.result))
|
|
47
|
+
throw new Error(`${LABEL} returned an unexpected response`);
|
|
48
|
+
return result.result;
|
|
49
|
+
}, "output")
|
|
50
|
+
};
|
|
51
|
+
var classify = /* @__PURE__ */ __name((model, context, options) => classifySystemOne(transport, model, context, options), "classify");
|
|
52
|
+
export {
|
|
53
|
+
classify
|
|
54
|
+
};
|