@wirecat/drive-cli 0.44.0 → 0.45.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/dist/bin/drive.js +35 -40
- package/dist/bundle/all-profiles-O7CNQ7FO.js +26 -0
- package/dist/bundle/anthropic-6T67J2CE.js +71 -0
- package/dist/bundle/app-server-BVBZT3UY.js +237 -0
- package/dist/bundle/bun-O6RL6LRQ.js +169 -0
- package/dist/bundle/bun-sqlite-54W7JUY3.js +70 -0
- package/dist/bundle/chunk-2DLAJGRN.js +62 -0
- package/dist/bundle/chunk-37MAA6F2.js +5624 -0
- package/dist/bundle/chunk-3HRDEJJW.js +161 -0
- package/dist/bundle/chunk-3Z7WSD2A.js +433 -0
- package/dist/bundle/chunk-44FV5JAS.js +1855 -0
- package/dist/bundle/chunk-4DW6QGEV.js +164 -0
- package/dist/bundle/chunk-4NGLRHWO.js +24 -0
- package/dist/bundle/chunk-5DPV7X27.js +663 -0
- package/dist/bundle/chunk-5FONRUG6.js +24805 -0
- package/dist/bundle/chunk-5MGIL5LW.js +846 -0
- package/dist/bundle/chunk-5TC3NCAF.js +42 -0
- package/dist/bundle/chunk-6Y2BYFXQ.js +65 -0
- package/dist/bundle/chunk-A3FU4RR6.js +150 -0
- package/dist/bundle/chunk-ADLS6FVG.js +24600 -0
- package/dist/bundle/chunk-AIXLOMH4.js +63 -0
- package/dist/bundle/chunk-AOOD3RMK.js +384 -0
- package/dist/bundle/chunk-AUS6TKP5.js +1975 -0
- package/dist/bundle/chunk-B2J6FJNL.js +19 -0
- package/dist/bundle/chunk-BEXHAGXH.js +3542 -0
- package/dist/bundle/chunk-BHE7ZY2N.js +2352 -0
- package/dist/bundle/chunk-BJ3JRO34.js +2356 -0
- package/dist/bundle/chunk-BQUPOB5H.js +2315 -0
- package/dist/bundle/chunk-CFZWPIVC.js +1092 -0
- package/dist/bundle/chunk-CKR3DVUK.js +754 -0
- package/dist/bundle/chunk-CVIKKIGE.js +76 -0
- package/dist/bundle/chunk-D67JGWSC.js +190 -0
- package/dist/bundle/chunk-DDYR6DYL.js +78 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-DL7D6Y3B.js +18102 -0
- package/dist/bundle/chunk-DORXXBFC.js +484 -0
- package/dist/bundle/chunk-DXKVEOSS.js +53 -0
- package/dist/bundle/chunk-DXQEJWI3.js +522 -0
- package/dist/bundle/chunk-FEULDMWM.js +35598 -0
- package/dist/bundle/chunk-G3FAOS52.js +630 -0
- package/dist/bundle/chunk-GHOWRW7E.js +237 -0
- package/dist/bundle/chunk-GNFHZZ55.js +264 -0
- package/dist/bundle/chunk-GNI7INK6.js +18 -0
- package/dist/bundle/chunk-GOR3Z2FR.js +17 -0
- package/dist/bundle/chunk-GQW4GRYR.js +886 -0
- package/dist/bundle/chunk-GWPKIRNQ.js +220 -0
- package/dist/bundle/chunk-GYCUY4CL.js +9 -0
- package/dist/bundle/chunk-HEPIOCHN.js +8181 -0
- package/dist/bundle/chunk-HTQTIKWP.js +928 -0
- package/dist/bundle/chunk-IAW5A7OR.js +1913 -0
- package/dist/bundle/chunk-IGMRWQP3.js +1071 -0
- package/dist/bundle/chunk-IKNU5A5Y.js +82 -0
- package/dist/bundle/chunk-JVTVAZ5X.js +1054 -0
- package/dist/bundle/chunk-K74PQVQZ.js +168 -0
- package/dist/bundle/chunk-K7FRUB33.js +795 -0
- package/dist/bundle/chunk-KADPV4YA.js +45 -0
- package/dist/bundle/chunk-KJMBV574.js +16225 -0
- package/dist/bundle/chunk-LHIL46I3.js +31 -0
- package/dist/bundle/chunk-LJARCTGL.js +60 -0
- package/dist/bundle/chunk-LOTQ2HMT.js +3954 -0
- package/dist/bundle/chunk-MAXN7COO.js +99 -0
- package/dist/bundle/chunk-MFS52LTZ.js +570 -0
- package/dist/bundle/chunk-MFSIOSUM.js +1714 -0
- package/dist/bundle/chunk-NB2N6L3R.js +138 -0
- package/dist/bundle/chunk-NDNTLUPS.js +58 -0
- package/dist/bundle/chunk-NLEB26GA.js +288 -0
- package/dist/bundle/chunk-NP3XLLN3.js +73 -0
- package/dist/bundle/chunk-NW7IMGRR.js +6848 -0
- package/dist/bundle/chunk-O5EHUB2V.js +2 -0
- package/dist/bundle/chunk-OWXTPXIQ.js +215 -0
- package/dist/bundle/chunk-PDBBBUY7.js +166 -0
- package/dist/bundle/chunk-PH74B2VZ.js +122 -0
- package/dist/bundle/chunk-PJ7IQVOM.js +421 -0
- package/dist/bundle/chunk-Q2Z3VCM4.js +2 -0
- package/dist/bundle/chunk-QTJUH3LS.js +15572 -0
- package/dist/bundle/chunk-QW36EOAM.js +106 -0
- package/dist/bundle/chunk-QWSRPXCJ.js +281 -0
- package/dist/bundle/chunk-R2A3K7ZF.js +193 -0
- package/dist/bundle/chunk-R2QRP7EJ.js +835 -0
- package/dist/bundle/chunk-RCS2SCX5.js +375 -0
- package/dist/bundle/chunk-RJ633GFA.js +25 -0
- package/dist/bundle/chunk-SBZB7HMU.js +1055 -0
- package/dist/bundle/chunk-SMHQA5J6.js +459 -0
- package/dist/bundle/chunk-SWMMR3FR.js +48 -0
- package/dist/bundle/chunk-TRMIV3OA.js +18 -0
- package/dist/bundle/chunk-VAGF723Z.js +74 -0
- package/dist/bundle/chunk-VCYFEWPD.js +18078 -0
- package/dist/bundle/chunk-VHQNVG3J.js +263 -0
- package/dist/bundle/chunk-VHT2WI4I.js +2941 -0
- package/dist/bundle/chunk-VYBOYBLX.js +100 -0
- package/dist/bundle/chunk-WUFCYDKB.js +71 -0
- package/dist/bundle/chunk-XAZQTJXR.js +3402 -0
- package/dist/bundle/chunk-XEBFFKXO.js +111 -0
- package/dist/bundle/chunk-XF5MFUEB.js +498 -0
- package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-ZBM4GEV2.js +120 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/command-contract-MXCBV3GJ.js +38 -0
- package/dist/bundle/dist-MWTMOYWT.js +7577 -0
- package/dist/bundle/dist-PY3MVR3G.js +21 -0
- package/dist/bundle/drive.js +50 -0
- package/dist/bundle/echarts-LD3AI55P.js +42501 -0
- package/dist/bundle/embed-FJKIIM43.js +37 -0
- package/dist/bundle/embedder-NNQ5ZC25.js +110 -0
- package/dist/bundle/entry-ZYSNPDSD.js +15 -0
- package/dist/bundle/failure-MJJXFR63.js +37 -0
- package/dist/bundle/first-run-KA2UPZAU.js +24 -0
- package/dist/bundle/first-screen-VQ3RXDMF.js +36 -0
- package/dist/bundle/google-ZYDFTHLN.js +32 -0
- package/dist/bundle/google-api-2GT5PAW2.js +82 -0
- package/dist/bundle/identity-JQFQXQIR.js +10 -0
- package/dist/bundle/instructions-RZMSW3OC.js +11 -0
- package/dist/bundle/login-JU6NKW5P.js +158 -0
- package/dist/bundle/mcp-2PZDI7WE.js +501 -0
- package/dist/bundle/mcp-JOQMFGBC.js +95 -0
- package/dist/bundle/mcp-OQBZXELQ.js +165 -0
- package/dist/bundle/mdast-util-from-markdown-FXEPSNER.js +1958 -0
- package/dist/bundle/mdast-util-gfm-SZM5GBDF.js +2103 -0
- package/dist/bundle/micromark-extension-gfm-GRL24TU6.js +1838 -0
- package/dist/bundle/node-P4E63KXA.js +2340 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-ZRLYQL7J.js +176 -0
- package/dist/bundle/node-sqlite-TXPSRROT.js +46 -0
- package/dist/bundle/oauth-NAIBKERJ.js +18 -0
- package/dist/bundle/open-3P5EPXPV.js +20 -0
- package/dist/bundle/process-LL77573L.js +91 -0
- package/dist/bundle/program-CZ55L6EW.js +24078 -0
- package/dist/bundle/prompt-3TX2SWOY.js +13 -0
- package/dist/bundle/reasons-GF2TYGX6.js +11 -0
- package/dist/bundle/recognize-IFXOJHEA.js +191 -0
- package/dist/bundle/remote-663M42Y5.js +28 -0
- package/dist/bundle/rerank-OT2F2DBV.js +51 -0
- package/dist/bundle/serve-PDNNI6O6.js +20 -0
- package/dist/bundle/server-BFOEPMR7.js +56 -0
- package/dist/bundle/server-K566PJ7H.js +69 -0
- package/dist/bundle/services-5MCTECBU.js +333 -0
- package/dist/bundle/sqlite-runtime-BF3KDM7W.js +17 -0
- package/dist/bundle/state-SZX65E74.js +34 -0
- package/dist/bundle/store-TCWNLA3V.js +125 -0
- package/dist/bundle/store-UKPGGAPW.js +142 -0
- package/dist/bundle/store-maintenance-command-QHLUVBTJ.js +57 -0
- package/dist/bundle/terminal-TFCTWLOS.js +11 -0
- package/dist/bundle/tokens-DFCFRF7I.js +103 -0
- package/dist/commands/mcp.d.ts.map +1 -1
- package/dist/commands/mcp.js +82 -36
- package/dist/commands/mcp.js.map +1 -1
- package/dist/contract-overrides.d.ts.map +1 -1
- package/dist/contract-overrides.js +59 -53
- package/dist/contract-overrides.js.map +1 -1
- package/dist/mcp.d.ts +6 -5
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +13 -10
- package/dist/mcp.js.map +1 -1
- package/dist/program.js +4 -4
- package/dist/program.js.map +1 -1
- package/dist/registry.d.ts +2 -2
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +3 -3
- package/dist/registry.js.map +1 -1
- package/dist/state.d.ts +13 -2
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +12 -2
- package/dist/state.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -5
- package/skills/drive-cli/SKILL.md +1 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
CAPABILITY_STATEMENTS,
|
|
5
|
+
storeCapable
|
|
6
|
+
} from "./chunk-VYBOYBLX.js";
|
|
7
|
+
import {
|
|
8
|
+
importFrom
|
|
9
|
+
} from "./chunk-Y5E2WNWB.js";
|
|
10
|
+
import {
|
|
11
|
+
__name
|
|
12
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
13
|
+
|
|
14
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.473.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_39633e3162553a2c86dde989a9811fcb/node_modules/@wirecat/cli-core/dist/sqlite-runtime.js
|
|
15
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
16
|
+
import { readFileSync } from "node:fs";
|
|
17
|
+
import { dirname } from "node:path";
|
|
18
|
+
var RESTARTED = "CLI_MESSAGING_SQLITE_RESTARTED";
|
|
19
|
+
var USER_LIBRARY_PATH = "CLI_MESSAGING_USER_LD_LIBRARY_PATH";
|
|
20
|
+
var FORWARDED = ["SIGTERM", "SIGHUP", "SIGQUIT"];
|
|
21
|
+
var ensureSqlite = /* @__PURE__ */ __name(async (runtime = nodeRuntime()) => {
|
|
22
|
+
const { env } = runtime;
|
|
23
|
+
if (env[RESTARTED]) {
|
|
24
|
+
if (env[USER_LIBRARY_PATH] === void 0)
|
|
25
|
+
delete env.LD_LIBRARY_PATH;
|
|
26
|
+
else
|
|
27
|
+
env.LD_LIBRARY_PATH = env[USER_LIBRARY_PATH];
|
|
28
|
+
delete env[USER_LIBRARY_PATH];
|
|
29
|
+
delete env[RESTARTED];
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (runtime.bun || runtime.platform !== "linux")
|
|
33
|
+
return;
|
|
34
|
+
const maps = runtime.maps();
|
|
35
|
+
if (!maps.includes("libsqlite3"))
|
|
36
|
+
return;
|
|
37
|
+
if (await runtime.capable())
|
|
38
|
+
return;
|
|
39
|
+
const library = await runtime.library(maps.includes("ld-musl"));
|
|
40
|
+
if (!library)
|
|
41
|
+
return;
|
|
42
|
+
const restarted = {
|
|
43
|
+
...env,
|
|
44
|
+
LD_LIBRARY_PATH: [dirname(library.path), env.LD_LIBRARY_PATH].filter(Boolean).join(":"),
|
|
45
|
+
[RESTARTED]: "1"
|
|
46
|
+
};
|
|
47
|
+
if (env.LD_LIBRARY_PATH !== void 0)
|
|
48
|
+
restarted[USER_LIBRARY_PATH] = env.LD_LIBRARY_PATH;
|
|
49
|
+
if (!runtime.works(restarted, library.version))
|
|
50
|
+
return;
|
|
51
|
+
await runtime.restart(restarted);
|
|
52
|
+
}, "ensureSqlite");
|
|
53
|
+
var trialScript = /* @__PURE__ */ __name((version) => `
|
|
54
|
+
const { DatabaseSync } = await import("node:sqlite")
|
|
55
|
+
const database = new DatabaseSync(":memory:")
|
|
56
|
+
if (database.prepare("SELECT sqlite_version() AS v").get().v !== ${JSON.stringify(version)}) process.exit(1)
|
|
57
|
+
for (const statement of ${JSON.stringify(CAPABILITY_STATEMENTS)}) database.exec(statement)
|
|
58
|
+
`, "trialScript");
|
|
59
|
+
var nodeRuntime = /* @__PURE__ */ __name(() => ({
|
|
60
|
+
env: process.env,
|
|
61
|
+
platform: process.platform,
|
|
62
|
+
bun: "Bun" in globalThis,
|
|
63
|
+
maps: /* @__PURE__ */ __name(() => {
|
|
64
|
+
try {
|
|
65
|
+
return readFileSync("/proc/self/maps", "utf8");
|
|
66
|
+
} catch {
|
|
67
|
+
return "";
|
|
68
|
+
}
|
|
69
|
+
}, "maps"),
|
|
70
|
+
capable: /* @__PURE__ */ __name(() => storeCapable().then(() => true, () => false), "capable"),
|
|
71
|
+
library: /* @__PURE__ */ __name(async (musl) => {
|
|
72
|
+
try {
|
|
73
|
+
const { libraryFor, SQLITE_VERSION } = await importFrom(new URL("sqlite-runtime.js", import.meta.resolve("@wirecat/cli-core")).href, "@wirecat/cli-core-sqlite");
|
|
74
|
+
const path = libraryFor({ musl });
|
|
75
|
+
return path === void 0 ? void 0 : { path, version: SQLITE_VERSION };
|
|
76
|
+
} catch {
|
|
77
|
+
return void 0;
|
|
78
|
+
}
|
|
79
|
+
}, "library"),
|
|
80
|
+
works: /* @__PURE__ */ __name((env, version) => spawnSync(process.execPath, ["--no-warnings", "--input-type=module", "-e", trialScript(version)], {
|
|
81
|
+
env,
|
|
82
|
+
stdio: "ignore",
|
|
83
|
+
timeout: 1e4
|
|
84
|
+
}).status === 0, "works"),
|
|
85
|
+
restart: /* @__PURE__ */ __name((env) => relay(spawn(process.execPath, [...process.execArgv, ...process.argv.slice(1)], { env, stdio: "inherit" })), "restart")
|
|
86
|
+
}), "nodeRuntime");
|
|
87
|
+
var relay = /* @__PURE__ */ __name((child, host = process) => new Promise(() => {
|
|
88
|
+
for (const signal of FORWARDED)
|
|
89
|
+
host.on(signal, () => child.kill(signal));
|
|
90
|
+
host.on("SIGINT", () => {
|
|
91
|
+
});
|
|
92
|
+
child.on("error", () => host.exit(1));
|
|
93
|
+
child.on("exit", (code, signal) => {
|
|
94
|
+
if (signal) {
|
|
95
|
+
host.removeAllListeners(signal);
|
|
96
|
+
host.kill(host.pid, signal);
|
|
97
|
+
} else
|
|
98
|
+
host.exit(code ?? 1);
|
|
99
|
+
});
|
|
100
|
+
}), "relay");
|
|
101
|
+
|
|
102
|
+
export {
|
|
103
|
+
ensureSqlite,
|
|
104
|
+
nodeRuntime,
|
|
105
|
+
relay
|
|
106
|
+
};
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
answeredWire
|
|
5
|
+
} from "./chunk-CVIKKIGE.js";
|
|
6
|
+
import {
|
|
7
|
+
CALLER_META_KEY,
|
|
8
|
+
PROXY_CLIENT_NAME,
|
|
9
|
+
StdioServerTransport,
|
|
10
|
+
callerOf,
|
|
11
|
+
serveStdio
|
|
12
|
+
} from "./chunk-G3FAOS52.js";
|
|
13
|
+
import {
|
|
14
|
+
McpServer
|
|
15
|
+
} from "./chunk-5FONRUG6.js";
|
|
16
|
+
import {
|
|
17
|
+
__name
|
|
18
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
19
|
+
|
|
20
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.473.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_39633e3162553a2c86dde989a9811fcb/node_modules/@wirecat/cli-core/dist/mcp/all-profiles.js
|
|
21
|
+
import { spawn } from "node:child_process";
|
|
22
|
+
import { randomUUID } from "node:crypto";
|
|
23
|
+
var PROTOCOL = "2025-06-18";
|
|
24
|
+
var START_MS = 3e4;
|
|
25
|
+
var CHILD_IDLE_MS = 10 * 60 * 1e3;
|
|
26
|
+
var startChild = /* @__PURE__ */ __name((spec, note, onExit) => {
|
|
27
|
+
const child = spawn(spec.command, spec.args, { env: spec.env, stdio: "pipe" });
|
|
28
|
+
const pending = /* @__PURE__ */ new Map();
|
|
29
|
+
let next = 1;
|
|
30
|
+
let buffer = "";
|
|
31
|
+
let gone;
|
|
32
|
+
const fail = /* @__PURE__ */ __name((error) => {
|
|
33
|
+
gone ??= error;
|
|
34
|
+
for (const waiter of pending.values())
|
|
35
|
+
waiter.reject(error);
|
|
36
|
+
pending.clear();
|
|
37
|
+
}, "fail");
|
|
38
|
+
child.on("error", () => fail(new Error("the profile's MCP server could not be started")));
|
|
39
|
+
child.on("exit", () => {
|
|
40
|
+
fail(new Error("the profile's MCP server stopped"));
|
|
41
|
+
onExit();
|
|
42
|
+
});
|
|
43
|
+
child.stdin.on("error", () => fail(new Error("the profile's MCP server closed its input")));
|
|
44
|
+
child.stderr.setEncoding("utf8");
|
|
45
|
+
let errors = "";
|
|
46
|
+
child.stderr.on("data", (chunk) => {
|
|
47
|
+
const lines = (errors + chunk).split("\n");
|
|
48
|
+
errors = lines.pop() ?? "";
|
|
49
|
+
for (const line of lines)
|
|
50
|
+
if (line.trim())
|
|
51
|
+
note(line);
|
|
52
|
+
});
|
|
53
|
+
child.stdout.setEncoding("utf8");
|
|
54
|
+
child.stdout.on("data", (chunk) => {
|
|
55
|
+
buffer += chunk;
|
|
56
|
+
for (let at = buffer.indexOf("\n"); at !== -1; at = buffer.indexOf("\n")) {
|
|
57
|
+
const line = buffer.slice(0, at);
|
|
58
|
+
buffer = buffer.slice(at + 1);
|
|
59
|
+
let message;
|
|
60
|
+
try {
|
|
61
|
+
message = JSON.parse(line);
|
|
62
|
+
} catch {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (message.method !== void 0 && message.id !== void 0) {
|
|
66
|
+
send({ id: message.id, error: { code: -32601, message: "not offered through the all-profiles server" } });
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (typeof message.id !== "number")
|
|
70
|
+
continue;
|
|
71
|
+
const waiter = pending.get(message.id);
|
|
72
|
+
if (!waiter)
|
|
73
|
+
continue;
|
|
74
|
+
pending.delete(message.id);
|
|
75
|
+
if (message.error)
|
|
76
|
+
waiter.reject(new Error(message.error.message ?? "the profile's MCP server refused"));
|
|
77
|
+
else
|
|
78
|
+
waiter.resolve(message.result ?? {});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const send = /* @__PURE__ */ __name((message) => child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", ...message })}
|
|
82
|
+
`), "send");
|
|
83
|
+
const request = /* @__PURE__ */ __name((method, params) => new Promise((resolve, reject) => {
|
|
84
|
+
if (gone)
|
|
85
|
+
return reject(gone);
|
|
86
|
+
const id = next++;
|
|
87
|
+
pending.set(id, { resolve, reject });
|
|
88
|
+
send({ id, method, params });
|
|
89
|
+
}), "request");
|
|
90
|
+
const close = /* @__PURE__ */ __name(() => new Promise((resolve) => {
|
|
91
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
92
|
+
return resolve();
|
|
93
|
+
child.once("exit", () => resolve());
|
|
94
|
+
child.stdin.end();
|
|
95
|
+
}), "close");
|
|
96
|
+
const timer = setTimeout(() => fail(new Error("the profile's MCP server did not answer in time")), START_MS);
|
|
97
|
+
return request("initialize", {
|
|
98
|
+
protocolVersion: PROTOCOL,
|
|
99
|
+
capabilities: {},
|
|
100
|
+
clientInfo: { name: PROXY_CLIENT_NAME, version: "1" }
|
|
101
|
+
}).then(() => {
|
|
102
|
+
send({ method: "notifications/initialized" });
|
|
103
|
+
return { request, close };
|
|
104
|
+
}).catch(async (error) => {
|
|
105
|
+
await close();
|
|
106
|
+
throw error;
|
|
107
|
+
}).finally(() => clearTimeout(timer));
|
|
108
|
+
}, "startChild");
|
|
109
|
+
var pool = /* @__PURE__ */ __name((options) => {
|
|
110
|
+
const idleMs = options.idleMs ?? CHILD_IDLE_MS;
|
|
111
|
+
const note = options.note ?? (() => {
|
|
112
|
+
});
|
|
113
|
+
const running = /* @__PURE__ */ new Map();
|
|
114
|
+
const forget = /* @__PURE__ */ __name((profile, child) => {
|
|
115
|
+
const one = running.get(profile);
|
|
116
|
+
if (one?.child !== child)
|
|
117
|
+
return;
|
|
118
|
+
clearTimeout(one.timer);
|
|
119
|
+
running.delete(profile);
|
|
120
|
+
}, "forget");
|
|
121
|
+
const use = /* @__PURE__ */ __name(async (profile, work) => {
|
|
122
|
+
let one = running.get(profile);
|
|
123
|
+
if (!one) {
|
|
124
|
+
const child = startChild(options.child(profile), (line) => note(`${profile}: ${line}`), () => forget(profile, child));
|
|
125
|
+
child.catch(() => forget(profile, child));
|
|
126
|
+
one = { child };
|
|
127
|
+
running.set(profile, one);
|
|
128
|
+
}
|
|
129
|
+
clearTimeout(one.timer);
|
|
130
|
+
const entry = one;
|
|
131
|
+
try {
|
|
132
|
+
return await work(await entry.child);
|
|
133
|
+
} finally {
|
|
134
|
+
if (running.get(profile) === entry) {
|
|
135
|
+
entry.timer = setTimeout(() => {
|
|
136
|
+
forget(profile, entry.child);
|
|
137
|
+
void entry.child.then((child) => child.close()).catch(() => void 0);
|
|
138
|
+
}, idleMs);
|
|
139
|
+
entry.timer.unref();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}, "use");
|
|
143
|
+
const close = /* @__PURE__ */ __name(async () => {
|
|
144
|
+
const all = [...running.values()];
|
|
145
|
+
running.clear();
|
|
146
|
+
for (const one of all)
|
|
147
|
+
clearTimeout(one.timer);
|
|
148
|
+
await Promise.all(all.map((one) => one.child.then((child) => child.close()).catch(() => void 0)));
|
|
149
|
+
}, "close");
|
|
150
|
+
return { use, close };
|
|
151
|
+
}, "pool");
|
|
152
|
+
var withProfile = /* @__PURE__ */ __name((tool, profiles, name, signedIn = () => true) => {
|
|
153
|
+
const schema = tool.inputSchema;
|
|
154
|
+
const out = profiles.filter((profile) => !signedIn(profile));
|
|
155
|
+
const states = out.length === 0 ? "" : ` Signed in: ${profiles.filter(signedIn).join(", ") || "none"} \xB7 Not signed in: ${out.join(", ")}.`;
|
|
156
|
+
return {
|
|
157
|
+
...tool,
|
|
158
|
+
inputSchema: {
|
|
159
|
+
...tool.inputSchema,
|
|
160
|
+
properties: {
|
|
161
|
+
profile: {
|
|
162
|
+
type: "string",
|
|
163
|
+
enum: [...profiles],
|
|
164
|
+
oneOf: profiles.map((profile) => ({
|
|
165
|
+
const: profile,
|
|
166
|
+
title: signedIn(profile) ? profile : `${profile} \u2014 not signed in`
|
|
167
|
+
})),
|
|
168
|
+
description: `Which ${name} account, by its profile. If the owner did not name one, ask which \u2014 never guess.${states}`
|
|
169
|
+
},
|
|
170
|
+
...schema.properties
|
|
171
|
+
},
|
|
172
|
+
required: ["profile", ...(schema.required ?? []).filter((field) => field !== "profile")]
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}, "withProfile");
|
|
176
|
+
var refusal = /* @__PURE__ */ __name((text) => ({
|
|
177
|
+
isError: true,
|
|
178
|
+
content: [{ type: "text", text }]
|
|
179
|
+
}), "refusal");
|
|
180
|
+
var allProfilesServer = /* @__PURE__ */ __name((options) => {
|
|
181
|
+
const children = pool(options);
|
|
182
|
+
let listed;
|
|
183
|
+
const tools = /* @__PURE__ */ __name((profiles) => {
|
|
184
|
+
listed ??= children.use(profiles.find(signedIn) ?? profiles[0], (child) => child.request("tools/list", {})).then((answer) => answer.tools ?? []);
|
|
185
|
+
listed.catch(() => {
|
|
186
|
+
listed = void 0;
|
|
187
|
+
});
|
|
188
|
+
return listed;
|
|
189
|
+
}, "tools");
|
|
190
|
+
const signedIn = /* @__PURE__ */ __name((profile) => options.signedIn?.(profile) ?? true, "signedIn");
|
|
191
|
+
const build = /* @__PURE__ */ __name(() => {
|
|
192
|
+
const profiles = [...options.profiles()].sort();
|
|
193
|
+
const server = new McpServer({ name: options.command, version: options.version }, { capabilities: { tools: {} }, instructions: options.instructions });
|
|
194
|
+
server.server.setRequestHandler("tools/list", async () => ({
|
|
195
|
+
tools: profiles.length === 0 ? [] : (await tools(profiles)).map((one) => withProfile(one, profiles, options.name, signedIn))
|
|
196
|
+
}));
|
|
197
|
+
const callers = {
|
|
198
|
+
env: options.env ?? process.env,
|
|
199
|
+
client: /* @__PURE__ */ __name(() => server.server.getClientVersion(), "client"),
|
|
200
|
+
connectionId: randomUUID()
|
|
201
|
+
};
|
|
202
|
+
server.server.setRequestHandler("tools/call", async (request, ctx) => {
|
|
203
|
+
const { name, arguments: given = {}, _meta } = request.params;
|
|
204
|
+
const { profile, ...rest } = given;
|
|
205
|
+
if (typeof profile !== "string" || !profiles.includes(profile))
|
|
206
|
+
return refusal(`${name} needs "profile", one of: ${profiles.join(", ")}. If the owner did not say which account, ask.`);
|
|
207
|
+
if (!signedIn(profile))
|
|
208
|
+
return refusal(options.signIn?.(profile) ?? `profile ${profile} is not signed in.`);
|
|
209
|
+
try {
|
|
210
|
+
return await children.use(profile, (child) => (
|
|
211
|
+
// Children are shared by every session, so each call names its own caller.
|
|
212
|
+
child.request("tools/call", {
|
|
213
|
+
name,
|
|
214
|
+
arguments: rest,
|
|
215
|
+
_meta: { ..._meta, [CALLER_META_KEY]: callerOf(ctx, name, callers) }
|
|
216
|
+
})
|
|
217
|
+
));
|
|
218
|
+
} catch (error) {
|
|
219
|
+
return refusal(`profile ${profile}: ${error instanceof Error ? error.message : String(error)}`);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
return server;
|
|
223
|
+
}, "build");
|
|
224
|
+
return { build, close: /* @__PURE__ */ __name(() => children.close(), "close") };
|
|
225
|
+
}, "allProfilesServer");
|
|
226
|
+
var serveAllProfilesOverStdio = /* @__PURE__ */ __name(async (options, io = {}) => {
|
|
227
|
+
const { build, close } = allProfilesServer(options);
|
|
228
|
+
const own = io.stdin !== void 0 && io.stdin !== process.stdin;
|
|
229
|
+
const wire = answeredWire(io.stdin ?? process.stdin, io.stdout ?? process.stdout);
|
|
230
|
+
const handle = serveStdio(build, {
|
|
231
|
+
transport: new StdioServerTransport(wire.input, wire.output),
|
|
232
|
+
onerror: /* @__PURE__ */ __name((error) => options.note?.(`mcp: ${error.message}`), "onerror")
|
|
233
|
+
});
|
|
234
|
+
const ended = await new Promise((resolve) => {
|
|
235
|
+
wire.ended.then(() => resolve("input"));
|
|
236
|
+
if (own)
|
|
237
|
+
io.signal?.addEventListener("abort", () => resolve("stopped"), { once: true });
|
|
238
|
+
else {
|
|
239
|
+
process.once("SIGINT", () => resolve("stopped"));
|
|
240
|
+
process.once("SIGTERM", () => resolve("stopped"));
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
try {
|
|
244
|
+
if (ended === "input")
|
|
245
|
+
await wire.answered();
|
|
246
|
+
wire.release();
|
|
247
|
+
await handle.close();
|
|
248
|
+
} finally {
|
|
249
|
+
await close();
|
|
250
|
+
}
|
|
251
|
+
}, "serveAllProfilesOverStdio");
|
|
252
|
+
var serveAllProfilesOverHttp = /* @__PURE__ */ __name(async (options, http) => {
|
|
253
|
+
const { build, close } = allProfilesServer(options);
|
|
254
|
+
const { serveOverHttp } = await import("./serve-PDNNI6O6.js");
|
|
255
|
+
const listening = await serveOverHttp(build, {
|
|
256
|
+
...http,
|
|
257
|
+
appName: options.command,
|
|
258
|
+
onError: /* @__PURE__ */ __name((error) => options.note?.(`mcp: ${error.message}`), "onError")
|
|
259
|
+
}).catch(async (error) => {
|
|
260
|
+
await close();
|
|
261
|
+
throw error;
|
|
262
|
+
});
|
|
263
|
+
return {
|
|
264
|
+
url: listening.url,
|
|
265
|
+
close: /* @__PURE__ */ __name(async () => {
|
|
266
|
+
try {
|
|
267
|
+
await listening.close();
|
|
268
|
+
} finally {
|
|
269
|
+
await close();
|
|
270
|
+
}
|
|
271
|
+
}, "close")
|
|
272
|
+
};
|
|
273
|
+
}, "serveAllProfilesOverHttp");
|
|
274
|
+
|
|
275
|
+
export {
|
|
276
|
+
CHILD_IDLE_MS,
|
|
277
|
+
withProfile,
|
|
278
|
+
allProfilesServer,
|
|
279
|
+
serveAllProfilesOverStdio,
|
|
280
|
+
serveAllProfilesOverHttp
|
|
281
|
+
};
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
listen
|
|
5
|
+
} from "./chunk-DDYR6DYL.js";
|
|
6
|
+
import {
|
|
7
|
+
ownerLogin
|
|
8
|
+
} from "./chunk-NLEB26GA.js";
|
|
9
|
+
import {
|
|
10
|
+
WebStandardStreamableHTTPServerTransport,
|
|
11
|
+
createMcpHandler,
|
|
12
|
+
getOAuthProtectedResourceMetadataUrl,
|
|
13
|
+
hostHeaderValidationResponse,
|
|
14
|
+
isLegacyRequest,
|
|
15
|
+
oauthMetadataResponse,
|
|
16
|
+
requireBearerAuth
|
|
17
|
+
} from "./chunk-5FONRUG6.js";
|
|
18
|
+
import {
|
|
19
|
+
activityRecorder,
|
|
20
|
+
calledTools,
|
|
21
|
+
httpActivityFile,
|
|
22
|
+
httpLock
|
|
23
|
+
} from "./chunk-3HRDEJJW.js";
|
|
24
|
+
import {
|
|
25
|
+
CliError
|
|
26
|
+
} from "./chunk-BJ3JRO34.js";
|
|
27
|
+
import {
|
|
28
|
+
__name
|
|
29
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
30
|
+
|
|
31
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.473.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_39633e3162553a2c86dde989a9811fcb/node_modules/@wirecat/cli-core/dist/mcp/http/serve.js
|
|
32
|
+
import { randomUUID } from "node:crypto";
|
|
33
|
+
var MCP_PATH = "/mcp";
|
|
34
|
+
var AS_METADATA = "/.well-known/oauth-authorization-server";
|
|
35
|
+
var LOCAL = ["localhost", "127.0.0.1"];
|
|
36
|
+
var MAX_SESSIONS = 20;
|
|
37
|
+
var MAX_LOGIN_BODY = 64 * 1024;
|
|
38
|
+
var SESSION_IDLE_MS = 60 * 60 * 1e3;
|
|
39
|
+
var sessionMissing = /* @__PURE__ */ __name(() => new Response(JSON.stringify({ jsonrpc: "2.0", error: { code: -32001, message: "Session not found" }, id: null }), {
|
|
40
|
+
status: 404,
|
|
41
|
+
headers: { "content-type": "application/json" }
|
|
42
|
+
}), "sessionMissing");
|
|
43
|
+
var legacySessions = /* @__PURE__ */ __name((build, now) => {
|
|
44
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
45
|
+
const drop = /* @__PURE__ */ __name(async (id) => {
|
|
46
|
+
const one = sessions.get(id);
|
|
47
|
+
sessions.delete(id);
|
|
48
|
+
await one?.close();
|
|
49
|
+
}, "drop");
|
|
50
|
+
const handle = /* @__PURE__ */ __name(async (request, auth) => {
|
|
51
|
+
for (const [id2, one] of sessions)
|
|
52
|
+
if (now() - one.seen > SESSION_IDLE_MS)
|
|
53
|
+
await drop(id2);
|
|
54
|
+
const id = request.headers.get("mcp-session-id");
|
|
55
|
+
if (id) {
|
|
56
|
+
const known = sessions.get(id);
|
|
57
|
+
if (!known || known.clientId !== auth.clientId)
|
|
58
|
+
return sessionMissing();
|
|
59
|
+
known.seen = now();
|
|
60
|
+
return known.transport.handleRequest(request, { authInfo: auth });
|
|
61
|
+
}
|
|
62
|
+
const server = build();
|
|
63
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
64
|
+
sessionIdGenerator: /* @__PURE__ */ __name(() => randomUUID(), "sessionIdGenerator"),
|
|
65
|
+
onsessionclosed: /* @__PURE__ */ __name((closed) => void sessions.delete(closed), "onsessionclosed")
|
|
66
|
+
});
|
|
67
|
+
await server.connect(transport);
|
|
68
|
+
const response = await transport.handleRequest(request, { authInfo: auth });
|
|
69
|
+
if (!transport.sessionId) {
|
|
70
|
+
await server.close();
|
|
71
|
+
return response;
|
|
72
|
+
}
|
|
73
|
+
sessions.set(transport.sessionId, { transport, close: /* @__PURE__ */ __name(() => server.close(), "close"), clientId: auth.clientId, seen: now() });
|
|
74
|
+
while (sessions.size > MAX_SESSIONS)
|
|
75
|
+
await drop(sessions.keys().next().value);
|
|
76
|
+
return response;
|
|
77
|
+
}, "handle");
|
|
78
|
+
return {
|
|
79
|
+
handle,
|
|
80
|
+
close: /* @__PURE__ */ __name(async () => {
|
|
81
|
+
for (const id of [...sessions.keys()])
|
|
82
|
+
await drop(id);
|
|
83
|
+
}, "close")
|
|
84
|
+
};
|
|
85
|
+
}, "legacySessions");
|
|
86
|
+
var metadataRequest = /* @__PURE__ */ __name((request, path, base) => {
|
|
87
|
+
const url = new URL(request.url);
|
|
88
|
+
const inserted = base && path === `${AS_METADATA}${base}`;
|
|
89
|
+
if (!inserted && url.pathname === path)
|
|
90
|
+
return request;
|
|
91
|
+
url.pathname = inserted ? AS_METADATA : path;
|
|
92
|
+
return new Request(url, { method: request.method, headers: request.headers });
|
|
93
|
+
}, "metadataRequest");
|
|
94
|
+
var toolsIn = /* @__PURE__ */ __name(async (request) => {
|
|
95
|
+
if (request.method !== "POST")
|
|
96
|
+
return [];
|
|
97
|
+
try {
|
|
98
|
+
return calledTools(await request.clone().json());
|
|
99
|
+
} catch {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
}, "toolsIn");
|
|
103
|
+
var serveOverHttp = /* @__PURE__ */ __name(async (build, options) => {
|
|
104
|
+
const { publicUrl, port, tokenFile, appName, onCode, onError, now, lockFile, version } = options;
|
|
105
|
+
const lock = lockFile ? httpLock(lockFile, {
|
|
106
|
+
pid: process.pid,
|
|
107
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
108
|
+
port,
|
|
109
|
+
publicUrl: publicUrl.href,
|
|
110
|
+
...version ? { version } : {}
|
|
111
|
+
}) : void 0;
|
|
112
|
+
if (lock?.held)
|
|
113
|
+
throw new CliError("validation_error", `${appName} already serves MCP over HTTP for this profile on port ${lock.held.port} (PID ${lock.held.pid}, since ${lock.held.startedAt})`);
|
|
114
|
+
const base = publicUrl.pathname === "/" ? "" : publicUrl.pathname.replace(/\/+$/, "");
|
|
115
|
+
const issuer = new URL(`${publicUrl.origin}${base}`);
|
|
116
|
+
const resource = new URL(`${base}${MCP_PATH}`, publicUrl.origin);
|
|
117
|
+
const mcpPath = resource.pathname;
|
|
118
|
+
const publicPath = /* @__PURE__ */ __name((path) => base && path !== base && !path.startsWith(`${base}/`) && !path.startsWith("/.well-known/") ? `${base}${path}` : path, "publicPath");
|
|
119
|
+
const login = ownerLogin({
|
|
120
|
+
issuer,
|
|
121
|
+
resource,
|
|
122
|
+
file: tokenFile,
|
|
123
|
+
appName,
|
|
124
|
+
onCode: /* @__PURE__ */ __name((code, expires) => {
|
|
125
|
+
lock?.update({ loginCode: code, loginCodeExpiresAt: expires.toISOString() });
|
|
126
|
+
onCode(code, expires);
|
|
127
|
+
}, "onCode"),
|
|
128
|
+
...now ? { now } : {}
|
|
129
|
+
});
|
|
130
|
+
const insecure = issuer.protocol === "http:" && LOCAL.includes(issuer.hostname);
|
|
131
|
+
const mcp = createMcpHandler(build, { legacy: "reject", ...onError ? { onerror: onError } : {} });
|
|
132
|
+
const legacy = legacySessions(build, now ?? Date.now);
|
|
133
|
+
const bearer = requireBearerAuth({
|
|
134
|
+
verifier: login.verifier,
|
|
135
|
+
resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(resource)
|
|
136
|
+
});
|
|
137
|
+
const activity = activityRecorder(httpActivityFile(tokenFile), now);
|
|
138
|
+
const allowedHosts = [.../* @__PURE__ */ new Set([publicUrl.hostname, ...LOCAL])];
|
|
139
|
+
const allowedOrigins = [publicUrl.origin];
|
|
140
|
+
const listening = await listen(async (request) => {
|
|
141
|
+
const refused = hostHeaderValidationResponse(request, allowedHosts);
|
|
142
|
+
if (refused)
|
|
143
|
+
return refused;
|
|
144
|
+
const path = publicPath(new URL(request.url).pathname);
|
|
145
|
+
const discovery = oauthMetadataResponse(metadataRequest(request, path, base), {
|
|
146
|
+
oauthMetadata: login.metadata,
|
|
147
|
+
resourceServerUrl: resource,
|
|
148
|
+
resourceName: appName,
|
|
149
|
+
...insecure ? { dangerouslyAllowInsecureIssuerUrl: true } : {}
|
|
150
|
+
});
|
|
151
|
+
if (discovery)
|
|
152
|
+
return discovery;
|
|
153
|
+
if (Number(request.headers.get("content-length") ?? 0) > MAX_LOGIN_BODY && path !== mcpPath)
|
|
154
|
+
return new Response("Request too large", { status: 413 });
|
|
155
|
+
const origin = request.headers.get("origin");
|
|
156
|
+
if (origin && !allowedOrigins.includes(origin))
|
|
157
|
+
return new Response("Origin not allowed", { status: 403 });
|
|
158
|
+
const answered = await login.handle(request, path);
|
|
159
|
+
if (answered)
|
|
160
|
+
return answered;
|
|
161
|
+
if (path !== mcpPath)
|
|
162
|
+
return new Response("Not found", { status: 404 });
|
|
163
|
+
const auth = await bearer(request);
|
|
164
|
+
if (auth instanceof Response)
|
|
165
|
+
return auth;
|
|
166
|
+
activity.record(auth.clientId, await toolsIn(request));
|
|
167
|
+
return await isLegacyRequest(request) ? legacy.handle(request, auth) : mcp.fetch(request, { authInfo: auth });
|
|
168
|
+
}, { host: "127.0.0.1", port }).catch((error) => {
|
|
169
|
+
login.close();
|
|
170
|
+
lock?.release();
|
|
171
|
+
throw error;
|
|
172
|
+
});
|
|
173
|
+
lock?.update({ listeningAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
174
|
+
return {
|
|
175
|
+
url: listening.url,
|
|
176
|
+
close: /* @__PURE__ */ __name(async () => {
|
|
177
|
+
login.close();
|
|
178
|
+
activity.flush();
|
|
179
|
+
try {
|
|
180
|
+
await listening.close();
|
|
181
|
+
await legacy.close();
|
|
182
|
+
await mcp.close();
|
|
183
|
+
} finally {
|
|
184
|
+
lock?.release();
|
|
185
|
+
}
|
|
186
|
+
}, "close")
|
|
187
|
+
};
|
|
188
|
+
}, "serveOverHttp");
|
|
189
|
+
|
|
190
|
+
export {
|
|
191
|
+
MCP_PATH,
|
|
192
|
+
serveOverHttp
|
|
193
|
+
};
|