@wirecat/mail-cli 0.0.0-stage → 0.1.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.
Files changed (226) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/LICENSE +204 -0
  3. package/README.md +141 -2
  4. package/dist/bin/mail.d.ts +3 -0
  5. package/dist/bin/mail.d.ts.map +1 -0
  6. package/dist/bin/mail.js +36 -0
  7. package/dist/bin/mail.js.map +1 -0
  8. package/dist/bundle/all-profiles-TKMBELRZ.js +286 -0
  9. package/dist/bundle/anthropic-7LMUAEIZ.js +72 -0
  10. package/dist/bundle/app-server-JGMIJDD4.js +229 -0
  11. package/dist/bundle/bun-XRO6XJHQ.js +169 -0
  12. package/dist/bundle/bun-sqlite-Z54LEHVM.js +71 -0
  13. package/dist/bundle/chunk-2LLNPNMB.js +24 -0
  14. package/dist/bundle/chunk-3E3WA2L6.js +1932 -0
  15. package/dist/bundle/chunk-3KEVLSNN.js +138 -0
  16. package/dist/bundle/chunk-3KOA73LS.js +3416 -0
  17. package/dist/bundle/chunk-4E7BN3TC.js +122 -0
  18. package/dist/bundle/chunk-4FEMINO2.js +409 -0
  19. package/dist/bundle/chunk-5BVIWP3S.js +71 -0
  20. package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
  21. package/dist/bundle/chunk-5NYMNSSO.js +264 -0
  22. package/dist/bundle/chunk-5WGEUDE4.js +27 -0
  23. package/dist/bundle/chunk-6MAZWSC3.js +132 -0
  24. package/dist/bundle/chunk-75CWWETH.js +379 -0
  25. package/dist/bundle/chunk-7SXGLT6T.js +444 -0
  26. package/dist/bundle/chunk-BTQX2ZSZ.js +288 -0
  27. package/dist/bundle/chunk-CEW6KIFA.js +1193 -0
  28. package/dist/bundle/chunk-CH6RXYAX.js +82 -0
  29. package/dist/bundle/chunk-D72URWJE.js +532 -0
  30. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  31. package/dist/bundle/chunk-EOEDICIE.js +6848 -0
  32. package/dist/bundle/chunk-F6D6PJ34.js +100 -0
  33. package/dist/bundle/chunk-FDCGTODC.js +78 -0
  34. package/dist/bundle/chunk-FZ5FXIG6.js +18 -0
  35. package/dist/bundle/chunk-GAH7N7HO.js +8181 -0
  36. package/dist/bundle/chunk-GK4M2SUP.js +195 -0
  37. package/dist/bundle/chunk-GN62YOT5.js +161 -0
  38. package/dist/bundle/chunk-GQQJOH7A.js +7050 -0
  39. package/dist/bundle/chunk-GWDCKUBI.js +781 -0
  40. package/dist/bundle/chunk-HTQTIKWP.js +928 -0
  41. package/dist/bundle/chunk-IK5TH3O7.js +217 -0
  42. package/dist/bundle/chunk-J3QXTBD2.js +2742 -0
  43. package/dist/bundle/chunk-J6MSJLIW.js +45 -0
  44. package/dist/bundle/chunk-JBBZCTTF.js +76 -0
  45. package/dist/bundle/chunk-JVMVLITS.js +260 -0
  46. package/dist/bundle/chunk-K4FVKPDQ.js +525 -0
  47. package/dist/bundle/chunk-KHTO2Q6E.js +886 -0
  48. package/dist/bundle/chunk-KM7Q67Z3.js +63 -0
  49. package/dist/bundle/chunk-LQ37ALDJ.js +2416 -0
  50. package/dist/bundle/chunk-MNOIRJEO.js +2315 -0
  51. package/dist/bundle/chunk-MS53RALV.js +168 -0
  52. package/dist/bundle/chunk-NK7EB63L.js +36225 -0
  53. package/dist/bundle/chunk-NPGVOZVK.js +2 -0
  54. package/dist/bundle/chunk-OTUOZ33L.js +82 -0
  55. package/dist/bundle/chunk-P7P5MNAU.js +46 -0
  56. package/dist/bundle/chunk-QLEUNU6G.js +537 -0
  57. package/dist/bundle/chunk-QQB7WT7R.js +216 -0
  58. package/dist/bundle/chunk-QX7RCLRS.js +23 -0
  59. package/dist/bundle/chunk-T6464KYA.js +35130 -0
  60. package/dist/bundle/chunk-TE5U5OAM.js +73 -0
  61. package/dist/bundle/chunk-TI6VBZKJ.js +166 -0
  62. package/dist/bundle/chunk-TQFCPUIM.js +53 -0
  63. package/dist/bundle/chunk-TVREDYX4.js +3574 -0
  64. package/dist/bundle/chunk-TWPDVUBR.js +106 -0
  65. package/dist/bundle/chunk-TWTATDM7.js +461 -0
  66. package/dist/bundle/chunk-UH4DDRHA.js +2989 -0
  67. package/dist/bundle/chunk-VEIZZRQ5.js +630 -0
  68. package/dist/bundle/chunk-WLFLBWNH.js +54 -0
  69. package/dist/bundle/chunk-WXAXYJJ7.js +486 -0
  70. package/dist/bundle/chunk-XQUUANA2.js +24600 -0
  71. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  72. package/dist/bundle/chunk-YO4CUH5E.js +33 -0
  73. package/dist/bundle/chunk-YPQQ5J4X.js +849 -0
  74. package/dist/bundle/chunk-Z34ICZA3.js +1028 -0
  75. package/dist/bundle/chunk-ZANYM66S.js +58 -0
  76. package/dist/bundle/chunk-ZD3WUGR2.js +142 -0
  77. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  78. package/dist/bundle/command-contract-WU434ZUL.js +34 -0
  79. package/dist/bundle/decode-YB3ZDTES.js +162 -0
  80. package/dist/bundle/dispatch-EUKKT3PD.js +411 -0
  81. package/dist/bundle/dist-A6GKSKFC.js +2072 -0
  82. package/dist/bundle/dist-X36THCOF.js +7577 -0
  83. package/dist/bundle/echarts-YNGCOYHW.js +42501 -0
  84. package/dist/bundle/embed-LWNHIRBQ.js +37 -0
  85. package/dist/bundle/embedder-2LYD3U37.js +110 -0
  86. package/dist/bundle/failure-OAIC5VAP.js +24 -0
  87. package/dist/bundle/first-run-N3HJKGU7.js +27 -0
  88. package/dist/bundle/first-screen-4U2DMV3G.js +32 -0
  89. package/dist/bundle/instructions-GJHHFV64.js +11 -0
  90. package/dist/bundle/mail.js +166 -0
  91. package/dist/bundle/mcp-L7SRVDRN.js +167 -0
  92. package/dist/bundle/node-GFOH6FKP.js +176 -0
  93. package/dist/bundle/node-KM3CUABH.js +2340 -0
  94. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  95. package/dist/bundle/node-sqlite-NBXQXBIU.js +63 -0
  96. package/dist/bundle/oauth-56EFO5AQ.js +19 -0
  97. package/dist/bundle/open-2V7QZQJP.js +21 -0
  98. package/dist/bundle/openai-V3SVACVL.js +251 -0
  99. package/dist/bundle/process-XVDX4SPD.js +91 -0
  100. package/dist/bundle/program-ILID6EAT.js +35542 -0
  101. package/dist/bundle/prompt-YKWAI222.js +14 -0
  102. package/dist/bundle/recognize-PAR66KVM.js +25 -0
  103. package/dist/bundle/remote-CE43TKXC.js +28 -0
  104. package/dist/bundle/rerank-M7S7P2TW.js +51 -0
  105. package/dist/bundle/serve-ENPMIV6J.js +197 -0
  106. package/dist/bundle/server-JRTHUCVY.js +63 -0
  107. package/dist/bundle/server-MBEZLVKZ.js +189 -0
  108. package/dist/bundle/sqlite-runtime-HVGDHBJJ.js +18 -0
  109. package/dist/bundle/state-QZSOSKBD.js +35 -0
  110. package/dist/bundle/store-2BUX6LVX.js +124 -0
  111. package/dist/bundle/store-UJ7SNKXI.js +141 -0
  112. package/dist/bundle/store-maintenance-command-I7V5C44K.js +52 -0
  113. package/dist/commands/account.d.ts +3 -0
  114. package/dist/commands/account.d.ts.map +1 -0
  115. package/dist/commands/account.js +47 -0
  116. package/dist/commands/account.js.map +1 -0
  117. package/dist/commands/context.d.ts +41 -0
  118. package/dist/commands/context.d.ts.map +1 -0
  119. package/dist/commands/context.js +52 -0
  120. package/dist/commands/context.js.map +1 -0
  121. package/dist/commands/doctor.d.ts +77 -0
  122. package/dist/commands/doctor.d.ts.map +1 -0
  123. package/dist/commands/doctor.js +74 -0
  124. package/dist/commands/doctor.js.map +1 -0
  125. package/dist/commands/folders.d.ts +3 -0
  126. package/dist/commands/folders.d.ts.map +1 -0
  127. package/dist/commands/folders.js +36 -0
  128. package/dist/commands/folders.js.map +1 -0
  129. package/dist/commands/login.d.ts +5 -0
  130. package/dist/commands/login.d.ts.map +1 -0
  131. package/dist/commands/login.js +21 -0
  132. package/dist/commands/login.js.map +1 -0
  133. package/dist/commands/mailbox.d.ts +16 -0
  134. package/dist/commands/mailbox.d.ts.map +1 -0
  135. package/dist/commands/mailbox.js +54 -0
  136. package/dist/commands/mailbox.js.map +1 -0
  137. package/dist/commands/mcp.d.ts +3 -0
  138. package/dist/commands/mcp.d.ts.map +1 -0
  139. package/dist/commands/mcp.js +97 -0
  140. package/dist/commands/mcp.js.map +1 -0
  141. package/dist/commands/session.d.ts +3 -0
  142. package/dist/commands/session.d.ts.map +1 -0
  143. package/dist/commands/session.js +211 -0
  144. package/dist/commands/session.js.map +1 -0
  145. package/dist/commands/setup.d.ts +3 -0
  146. package/dist/commands/setup.d.ts.map +1 -0
  147. package/dist/commands/setup.js +156 -0
  148. package/dist/commands/setup.js.map +1 -0
  149. package/dist/commands/status.d.ts +3 -0
  150. package/dist/commands/status.d.ts.map +1 -0
  151. package/dist/commands/status.js +89 -0
  152. package/dist/commands/status.js.map +1 -0
  153. package/dist/commands/sync.d.ts +3 -0
  154. package/dist/commands/sync.d.ts.map +1 -0
  155. package/dist/commands/sync.js +190 -0
  156. package/dist/commands/sync.js.map +1 -0
  157. package/dist/config.d.ts +190 -0
  158. package/dist/config.d.ts.map +1 -0
  159. package/dist/config.js +46 -0
  160. package/dist/config.js.map +1 -0
  161. package/dist/discovery.d.ts +42 -0
  162. package/dist/discovery.d.ts.map +1 -0
  163. package/dist/discovery.js +179 -0
  164. package/dist/discovery.js.map +1 -0
  165. package/dist/identity.d.ts +5 -0
  166. package/dist/identity.d.ts.map +1 -0
  167. package/dist/identity.js +16 -0
  168. package/dist/identity.js.map +1 -0
  169. package/dist/index.d.ts +3 -0
  170. package/dist/index.d.ts.map +1 -0
  171. package/dist/index.js +3 -0
  172. package/dist/index.js.map +1 -0
  173. package/dist/mail/imap-errors.d.ts +4 -0
  174. package/dist/mail/imap-errors.d.ts.map +1 -0
  175. package/dist/mail/imap-errors.js +41 -0
  176. package/dist/mail/imap-errors.js.map +1 -0
  177. package/dist/mail/imap-messages.d.ts +18 -0
  178. package/dist/mail/imap-messages.d.ts.map +1 -0
  179. package/dist/mail/imap-messages.js +66 -0
  180. package/dist/mail/imap-messages.js.map +1 -0
  181. package/dist/mail/imap.d.ts +67 -0
  182. package/dist/mail/imap.d.ts.map +1 -0
  183. package/dist/mail/imap.js +348 -0
  184. package/dist/mail/imap.js.map +1 -0
  185. package/dist/mail/parse.d.ts +18 -0
  186. package/dist/mail/parse.d.ts.map +1 -0
  187. package/dist/mail/parse.js +31 -0
  188. package/dist/mail/parse.js.map +1 -0
  189. package/dist/mail/port.d.ts +50 -0
  190. package/dist/mail/port.d.ts.map +1 -0
  191. package/dist/mail/port.js +4 -0
  192. package/dist/mail/port.js.map +1 -0
  193. package/dist/mcp.d.ts +29 -0
  194. package/dist/mcp.d.ts.map +1 -0
  195. package/dist/mcp.js +98 -0
  196. package/dist/mcp.js.map +1 -0
  197. package/dist/profile.d.ts +16 -0
  198. package/dist/profile.d.ts.map +1 -0
  199. package/dist/profile.js +31 -0
  200. package/dist/profile.js.map +1 -0
  201. package/dist/program.d.ts +6 -0
  202. package/dist/program.d.ts.map +1 -0
  203. package/dist/program.js +52 -0
  204. package/dist/program.js.map +1 -0
  205. package/dist/providers.d.ts +53 -0
  206. package/dist/providers.d.ts.map +1 -0
  207. package/dist/providers.js +106 -0
  208. package/dist/providers.js.map +1 -0
  209. package/dist/secret.d.ts +30 -0
  210. package/dist/secret.d.ts.map +1 -0
  211. package/dist/secret.js +68 -0
  212. package/dist/secret.js.map +1 -0
  213. package/dist/store.d.ts +12 -0
  214. package/dist/store.d.ts.map +1 -0
  215. package/dist/store.js +25 -0
  216. package/dist/store.js.map +1 -0
  217. package/dist/sync.d.ts +26 -0
  218. package/dist/sync.d.ts.map +1 -0
  219. package/dist/sync.js +75 -0
  220. package/dist/sync.js.map +1 -0
  221. package/dist/version.d.ts +2 -0
  222. package/dist/version.d.ts.map +1 -0
  223. package/dist/version.js +2 -0
  224. package/dist/version.js.map +1 -0
  225. package/package.json +83 -4
  226. package/skills/mail-cli/SKILL.md +27 -0
@@ -0,0 +1,14 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ readSecret
5
+ } from "./chunk-OTUOZ33L.js";
6
+ import "./chunk-CH6RXYAX.js";
7
+ import "./chunk-J3QXTBD2.js";
8
+ import "./chunk-LQ37ALDJ.js";
9
+ import "./chunk-Y5E2WNWB.js";
10
+ import "./chunk-5BVIWP3S.js";
11
+ import "./chunk-ZVVMGPBJ.js";
12
+ export {
13
+ readSecret
14
+ };
@@ -0,0 +1,25 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ SAMPLE_RATE,
5
+ decodeOgg,
6
+ detector,
7
+ loadSherpa,
8
+ openRecognizer,
9
+ openSpeechCutter,
10
+ toModelRate
11
+ } from "./chunk-QQB7WT7R.js";
12
+ import "./chunk-J3QXTBD2.js";
13
+ import "./chunk-LQ37ALDJ.js";
14
+ import "./chunk-Y5E2WNWB.js";
15
+ import "./chunk-5BVIWP3S.js";
16
+ import "./chunk-ZVVMGPBJ.js";
17
+ export {
18
+ SAMPLE_RATE,
19
+ decodeOgg,
20
+ detector,
21
+ loadSherpa,
22
+ openRecognizer,
23
+ openSpeechCutter,
24
+ toModelRate
25
+ };
@@ -0,0 +1,28 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ DEFAULT_OPENAI_MODEL,
5
+ OPENAI_MODELS,
6
+ OPENAI_URL,
7
+ isLocal,
8
+ openRemote,
9
+ remoteKey,
10
+ remoteModel
11
+ } from "./chunk-4E7BN3TC.js";
12
+ import "./chunk-Z34ICZA3.js";
13
+ import "./chunk-5NYMNSSO.js";
14
+ import "./chunk-FZ5FXIG6.js";
15
+ import "./chunk-J3QXTBD2.js";
16
+ import "./chunk-LQ37ALDJ.js";
17
+ import "./chunk-Y5E2WNWB.js";
18
+ import "./chunk-5BVIWP3S.js";
19
+ import "./chunk-ZVVMGPBJ.js";
20
+ export {
21
+ DEFAULT_OPENAI_MODEL,
22
+ OPENAI_MODELS,
23
+ OPENAI_URL,
24
+ isLocal,
25
+ openRemote,
26
+ remoteKey,
27
+ remoteModel
28
+ };
@@ -0,0 +1,51 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ defaultThreads,
5
+ loadModel,
6
+ truncated
7
+ } from "./chunk-Z34ICZA3.js";
8
+ import "./chunk-5NYMNSSO.js";
9
+ import "./chunk-FZ5FXIG6.js";
10
+ import "./chunk-J3QXTBD2.js";
11
+ import "./chunk-LQ37ALDJ.js";
12
+ import "./chunk-Y5E2WNWB.js";
13
+ import "./chunk-5BVIWP3S.js";
14
+ import {
15
+ __name
16
+ } from "./chunk-ZVVMGPBJ.js";
17
+
18
+ // node_modules/.pnpm/@wirecat+cli-core@0.507.0_@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_type_d5beb0101c7a90701cc33879a5be8d28/node_modules/@wirecat/cli-core/dist/embeddings/rerank.js
19
+ var openReranker = /* @__PURE__ */ __name(async (model, directory, { threads = defaultThreads() } = {}) => {
20
+ const { ort, tokenizer, session } = await loadModel(model, directory, threads);
21
+ const typeIds = session.inputNames.includes("token_type_ids");
22
+ const output = session.outputNames[0];
23
+ const one = /* @__PURE__ */ __name(async (question, passage) => {
24
+ const encoded = tokenizer.encode(question, { text_pair: passage, return_token_type_ids: true });
25
+ const ids = truncated(encoded.ids, model.maxTokens);
26
+ const shape = [1, ids.length];
27
+ const feeds = {
28
+ input_ids: new ort.Tensor("int64", BigInt64Array.from(ids, BigInt), shape),
29
+ attention_mask: new ort.Tensor("int64", new BigInt64Array(ids.length).fill(1n), shape)
30
+ };
31
+ if (typeIds)
32
+ feeds.token_type_ids = new ort.Tensor("int64", BigInt64Array.from(truncated(encoded.token_type_ids, model.maxTokens), BigInt), shape);
33
+ const logit = (await session.run(feeds))[output]?.data[0];
34
+ if (typeof logit !== "number" || !Number.isFinite(logit))
35
+ throw new Error(`${model.id} gave no score`);
36
+ return logit;
37
+ }, "one");
38
+ return {
39
+ model,
40
+ score: /* @__PURE__ */ __name(async (question, passages) => {
41
+ const scores = [];
42
+ for (const passage of passages)
43
+ scores.push(await one(question, passage));
44
+ return scores;
45
+ }, "score"),
46
+ close: /* @__PURE__ */ __name(() => session.release(), "close")
47
+ };
48
+ }, "openReranker");
49
+ export {
50
+ openReranker
51
+ };
@@ -0,0 +1,197 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ listen
5
+ } from "./chunk-FDCGTODC.js";
6
+ import {
7
+ ownerLogin
8
+ } from "./chunk-BTQX2ZSZ.js";
9
+ import {
10
+ WebStandardStreamableHTTPServerTransport,
11
+ createMcpHandler,
12
+ getOAuthProtectedResourceMetadataUrl,
13
+ hostHeaderValidationResponse,
14
+ isLegacyRequest,
15
+ oauthMetadataResponse,
16
+ requireBearerAuth
17
+ } from "./chunk-5D4AEUVA.js";
18
+ import {
19
+ activityRecorder,
20
+ calledTools,
21
+ httpActivityFile,
22
+ httpLock
23
+ } from "./chunk-GN62YOT5.js";
24
+ import "./chunk-TE5U5OAM.js";
25
+ import "./chunk-KM7Q67Z3.js";
26
+ import "./chunk-J3QXTBD2.js";
27
+ import "./chunk-LQ37ALDJ.js";
28
+ import "./chunk-Y5E2WNWB.js";
29
+ import {
30
+ CliError
31
+ } from "./chunk-5BVIWP3S.js";
32
+ import {
33
+ __name
34
+ } from "./chunk-ZVVMGPBJ.js";
35
+
36
+ // node_modules/.pnpm/@wirecat+cli-core@0.507.0_@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_type_d5beb0101c7a90701cc33879a5be8d28/node_modules/@wirecat/cli-core/dist/mcp/http/serve.js
37
+ import { randomUUID } from "node:crypto";
38
+ var MCP_PATH = "/mcp";
39
+ var AS_METADATA = "/.well-known/oauth-authorization-server";
40
+ var LOCAL = ["localhost", "127.0.0.1"];
41
+ var MAX_SESSIONS = 20;
42
+ var MAX_LOGIN_BODY = 64 * 1024;
43
+ var SESSION_IDLE_MS = 60 * 60 * 1e3;
44
+ var sessionMissing = /* @__PURE__ */ __name(() => new Response(JSON.stringify({ jsonrpc: "2.0", error: { code: -32001, message: "Session not found" }, id: null }), {
45
+ status: 404,
46
+ headers: { "content-type": "application/json" }
47
+ }), "sessionMissing");
48
+ var legacySessions = /* @__PURE__ */ __name((build, now) => {
49
+ const sessions = /* @__PURE__ */ new Map();
50
+ const drop = /* @__PURE__ */ __name(async (id) => {
51
+ const one = sessions.get(id);
52
+ sessions.delete(id);
53
+ await one?.close();
54
+ }, "drop");
55
+ const handle = /* @__PURE__ */ __name(async (request, auth) => {
56
+ for (const [id2, one] of sessions)
57
+ if (now() - one.seen > SESSION_IDLE_MS)
58
+ await drop(id2);
59
+ const id = request.headers.get("mcp-session-id");
60
+ if (id) {
61
+ const known = sessions.get(id);
62
+ if (!known || known.clientId !== auth.clientId)
63
+ return sessionMissing();
64
+ known.seen = now();
65
+ return known.transport.handleRequest(request, { authInfo: auth });
66
+ }
67
+ const server = build();
68
+ const transport = new WebStandardStreamableHTTPServerTransport({
69
+ sessionIdGenerator: /* @__PURE__ */ __name(() => randomUUID(), "sessionIdGenerator"),
70
+ onsessionclosed: /* @__PURE__ */ __name((closed) => void sessions.delete(closed), "onsessionclosed")
71
+ });
72
+ await server.connect(transport);
73
+ const response = await transport.handleRequest(request, { authInfo: auth });
74
+ if (!transport.sessionId) {
75
+ await server.close();
76
+ return response;
77
+ }
78
+ sessions.set(transport.sessionId, { transport, close: /* @__PURE__ */ __name(() => server.close(), "close"), clientId: auth.clientId, seen: now() });
79
+ while (sessions.size > MAX_SESSIONS)
80
+ await drop(sessions.keys().next().value);
81
+ return response;
82
+ }, "handle");
83
+ return {
84
+ handle,
85
+ close: /* @__PURE__ */ __name(async () => {
86
+ for (const id of [...sessions.keys()])
87
+ await drop(id);
88
+ }, "close")
89
+ };
90
+ }, "legacySessions");
91
+ var metadataRequest = /* @__PURE__ */ __name((request, path, base) => {
92
+ const url = new URL(request.url);
93
+ const inserted = base && path === `${AS_METADATA}${base}`;
94
+ if (!inserted && url.pathname === path)
95
+ return request;
96
+ url.pathname = inserted ? AS_METADATA : path;
97
+ return new Request(url, { method: request.method, headers: request.headers });
98
+ }, "metadataRequest");
99
+ var toolsIn = /* @__PURE__ */ __name(async (request) => {
100
+ if (request.method !== "POST")
101
+ return [];
102
+ try {
103
+ return calledTools(await request.clone().json());
104
+ } catch {
105
+ return [];
106
+ }
107
+ }, "toolsIn");
108
+ var serveOverHttp = /* @__PURE__ */ __name(async (build, options) => {
109
+ const { publicUrl, port, tokenFile, appName, onCode, onError, now, lockFile, version } = options;
110
+ const lock = lockFile ? httpLock(lockFile, {
111
+ pid: process.pid,
112
+ startedAt: (/* @__PURE__ */ new Date()).toISOString(),
113
+ port,
114
+ publicUrl: publicUrl.href,
115
+ ...version ? { version } : {}
116
+ }) : void 0;
117
+ if (lock?.held)
118
+ 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})`);
119
+ const base = publicUrl.pathname === "/" ? "" : publicUrl.pathname.replace(/\/+$/, "");
120
+ const issuer = new URL(`${publicUrl.origin}${base}`);
121
+ const resource = new URL(`${base}${MCP_PATH}`, publicUrl.origin);
122
+ const mcpPath = resource.pathname;
123
+ const publicPath = /* @__PURE__ */ __name((path) => base && path !== base && !path.startsWith(`${base}/`) && !path.startsWith("/.well-known/") ? `${base}${path}` : path, "publicPath");
124
+ const login = ownerLogin({
125
+ issuer,
126
+ resource,
127
+ file: tokenFile,
128
+ appName,
129
+ onCode: /* @__PURE__ */ __name((code, expires) => {
130
+ lock?.update({ loginCode: code, loginCodeExpiresAt: expires.toISOString() });
131
+ onCode(code, expires);
132
+ }, "onCode"),
133
+ ...now ? { now } : {}
134
+ });
135
+ const insecure = issuer.protocol === "http:" && LOCAL.includes(issuer.hostname);
136
+ const mcp = createMcpHandler(build, { legacy: "reject", ...onError ? { onerror: onError } : {} });
137
+ const legacy = legacySessions(build, now ?? Date.now);
138
+ const bearer = requireBearerAuth({
139
+ verifier: login.verifier,
140
+ resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(resource)
141
+ });
142
+ const activity = activityRecorder(httpActivityFile(tokenFile), now);
143
+ const allowedHosts = [.../* @__PURE__ */ new Set([publicUrl.hostname, ...LOCAL])];
144
+ const allowedOrigins = [publicUrl.origin];
145
+ const listening = await listen(async (request) => {
146
+ const refused = hostHeaderValidationResponse(request, allowedHosts);
147
+ if (refused)
148
+ return refused;
149
+ const path = publicPath(new URL(request.url).pathname);
150
+ const discovery = oauthMetadataResponse(metadataRequest(request, path, base), {
151
+ oauthMetadata: login.metadata,
152
+ resourceServerUrl: resource,
153
+ resourceName: appName,
154
+ ...insecure ? { dangerouslyAllowInsecureIssuerUrl: true } : {}
155
+ });
156
+ if (discovery)
157
+ return discovery;
158
+ if (Number(request.headers.get("content-length") ?? 0) > MAX_LOGIN_BODY && path !== mcpPath)
159
+ return new Response("Request too large", { status: 413 });
160
+ const origin = request.headers.get("origin");
161
+ if (origin && !allowedOrigins.includes(origin))
162
+ return new Response("Origin not allowed", { status: 403 });
163
+ const answered = await login.handle(request, path);
164
+ if (answered)
165
+ return answered;
166
+ if (path !== mcpPath)
167
+ return new Response("Not found", { status: 404 });
168
+ const auth = await bearer(request);
169
+ if (auth instanceof Response)
170
+ return auth;
171
+ activity.record(auth.clientId, await toolsIn(request));
172
+ return await isLegacyRequest(request) ? legacy.handle(request, auth) : mcp.fetch(request, { authInfo: auth });
173
+ }, { host: "127.0.0.1", port }).catch((error) => {
174
+ login.close();
175
+ lock?.release();
176
+ throw error;
177
+ });
178
+ lock?.update({ listeningAt: (/* @__PURE__ */ new Date()).toISOString() });
179
+ return {
180
+ url: listening.url,
181
+ close: /* @__PURE__ */ __name(async () => {
182
+ login.close();
183
+ activity.flush();
184
+ try {
185
+ await listening.close();
186
+ await legacy.close();
187
+ await mcp.close();
188
+ } finally {
189
+ lock?.release();
190
+ }
191
+ }, "close")
192
+ };
193
+ }, "serveOverHttp");
194
+ export {
195
+ MCP_PATH,
196
+ serveOverHttp
197
+ };
@@ -0,0 +1,63 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ PER_RUN,
5
+ createServer,
6
+ envelope,
7
+ serveOverHttpUntilStopped,
8
+ serveOverStdio
9
+ } from "./chunk-GWDCKUBI.js";
10
+ import "./chunk-3KOA73LS.js";
11
+ import "./chunk-CEW6KIFA.js";
12
+ import "./chunk-K4FVKPDQ.js";
13
+ import "./chunk-JVMVLITS.js";
14
+ import "./chunk-TQFCPUIM.js";
15
+ import "./chunk-JBBZCTTF.js";
16
+ import "./chunk-VEIZZRQ5.js";
17
+ import "./chunk-5D4AEUVA.js";
18
+ import "./chunk-3E3WA2L6.js";
19
+ import "./chunk-T6464KYA.js";
20
+ import "./chunk-75CWWETH.js";
21
+ import "./chunk-WXAXYJJ7.js";
22
+ import "./chunk-J6MSJLIW.js";
23
+ import "./chunk-CH6RXYAX.js";
24
+ import "./chunk-MS53RALV.js";
25
+ import "./chunk-TVREDYX4.js";
26
+ import "./chunk-GQQJOH7A.js";
27
+ import "./chunk-QLEUNU6G.js";
28
+ import "./chunk-7SXGLT6T.js";
29
+ import "./chunk-ZD3WUGR2.js";
30
+ import "./chunk-P7P5MNAU.js";
31
+ import "./chunk-WLFLBWNH.js";
32
+ import "./chunk-GN62YOT5.js";
33
+ import "./chunk-TE5U5OAM.js";
34
+ import "./chunk-KM7Q67Z3.js";
35
+ import "./chunk-4E7BN3TC.js";
36
+ import "./chunk-YPQQ5J4X.js";
37
+ import "./chunk-6MAZWSC3.js";
38
+ import "./chunk-NK7EB63L.js";
39
+ import "./chunk-4FEMINO2.js";
40
+ import "./chunk-3KEVLSNN.js";
41
+ import "./chunk-UH4DDRHA.js";
42
+ import "./chunk-NPGVOZVK.js";
43
+ import "./chunk-MNOIRJEO.js";
44
+ import "./chunk-KHTO2Q6E.js";
45
+ import "./chunk-F6D6PJ34.js";
46
+ import "./chunk-EOEDICIE.js";
47
+ import "./chunk-QX7RCLRS.js";
48
+ import "./chunk-D72URWJE.js";
49
+ import "./chunk-Z34ICZA3.js";
50
+ import "./chunk-5NYMNSSO.js";
51
+ import "./chunk-FZ5FXIG6.js";
52
+ import "./chunk-J3QXTBD2.js";
53
+ import "./chunk-LQ37ALDJ.js";
54
+ import "./chunk-Y5E2WNWB.js";
55
+ import "./chunk-5BVIWP3S.js";
56
+ import "./chunk-ZVVMGPBJ.js";
57
+ export {
58
+ PER_RUN,
59
+ createServer,
60
+ envelope,
61
+ serveOverHttpUntilStopped,
62
+ serveOverStdio
63
+ };
@@ -0,0 +1,189 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ botInstructions
5
+ } from "./chunk-2LLNPNMB.js";
6
+ import {
7
+ answered,
8
+ normal,
9
+ registerCommands,
10
+ runCommandForAgent,
11
+ toolsFromCommands
12
+ } from "./chunk-3KOA73LS.js";
13
+ import {
14
+ agentJson,
15
+ skillResource
16
+ } from "./chunk-K4FVKPDQ.js";
17
+ import "./chunk-JVMVLITS.js";
18
+ import {
19
+ callerOf,
20
+ serveStdio
21
+ } from "./chunk-VEIZZRQ5.js";
22
+ import {
23
+ McpServer
24
+ } from "./chunk-5D4AEUVA.js";
25
+ import {
26
+ wholeList
27
+ } from "./chunk-T6464KYA.js";
28
+ import "./chunk-75CWWETH.js";
29
+ import "./chunk-WXAXYJJ7.js";
30
+ import "./chunk-J6MSJLIW.js";
31
+ import "./chunk-CH6RXYAX.js";
32
+ import "./chunk-TVREDYX4.js";
33
+ import {
34
+ MESSENGER_CHANGE_REFUSAL,
35
+ changesMessenger,
36
+ flatten,
37
+ itemOf,
38
+ readOnlyLockOf,
39
+ readOnlyRefusal
40
+ } from "./chunk-GQQJOH7A.js";
41
+ import "./chunk-QLEUNU6G.js";
42
+ import "./chunk-7SXGLT6T.js";
43
+ import "./chunk-ZD3WUGR2.js";
44
+ import "./chunk-P7P5MNAU.js";
45
+ import "./chunk-WLFLBWNH.js";
46
+ import "./chunk-KM7Q67Z3.js";
47
+ import "./chunk-4E7BN3TC.js";
48
+ import "./chunk-YPQQ5J4X.js";
49
+ import "./chunk-6MAZWSC3.js";
50
+ import "./chunk-NK7EB63L.js";
51
+ import "./chunk-4FEMINO2.js";
52
+ import "./chunk-3KEVLSNN.js";
53
+ import "./chunk-UH4DDRHA.js";
54
+ import "./chunk-NPGVOZVK.js";
55
+ import "./chunk-MNOIRJEO.js";
56
+ import "./chunk-KHTO2Q6E.js";
57
+ import "./chunk-F6D6PJ34.js";
58
+ import "./chunk-EOEDICIE.js";
59
+ import "./chunk-QX7RCLRS.js";
60
+ import "./chunk-D72URWJE.js";
61
+ import "./chunk-Z34ICZA3.js";
62
+ import "./chunk-5NYMNSSO.js";
63
+ import "./chunk-FZ5FXIG6.js";
64
+ import "./chunk-J3QXTBD2.js";
65
+ import {
66
+ mcpErrorResult,
67
+ object
68
+ } from "./chunk-LQ37ALDJ.js";
69
+ import "./chunk-Y5E2WNWB.js";
70
+ import "./chunk-5BVIWP3S.js";
71
+ import {
72
+ __name
73
+ } from "./chunk-ZVVMGPBJ.js";
74
+
75
+ // node_modules/.pnpm/@wirecat+cli-core@0.507.0_@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_type_d5beb0101c7a90701cc33879a5be8d28/node_modules/@wirecat/cli-core/dist/mcp/bot/server.js
76
+ import { randomUUID } from "node:crypto";
77
+ var body = /* @__PURE__ */ __name((command, value) => Array.isArray(value) ? wholeList(`bot ${command}`, value) : value !== null && typeof value === "object" && ("item" in value || "items" in value) ? value : itemOf(value !== null && typeof value === "object" ? value : { value }), "body");
78
+ var createBotServer = /* @__PURE__ */ __name((options) => {
79
+ const { bot, program, settings, env } = options;
80
+ const command = bot.app.command;
81
+ const levels = options.levels ?? (() => settings.permissions);
82
+ const authority = /* @__PURE__ */ __name((path) => options.authority?.(path) === true || path[0] === "config" && (path[1] === "set" || path[1] === "unset"), "authority");
83
+ const catalogue = {
84
+ includeUnavailable: true,
85
+ levels: settings.permissions,
86
+ currentLevels: levels,
87
+ readOnly: readOnlyLockOf(bot.app, env) !== void 0,
88
+ ...options.keyOf ? { keyOf: options.keyOf } : {},
89
+ authority,
90
+ ...options.fetchOnly ? { fetchOnly: options.fetchOnly } : {},
91
+ offline: true,
92
+ // Another bot's copy is this bot's to read only where `read_other_bots` says so.
93
+ ...settings.readOtherBots ? {} : { omit: ["all_bots", "bots"] }
94
+ };
95
+ const tools = [
96
+ ...toolsFromCommands(program.commands, { ...catalogue, root: ["bot"] }),
97
+ ...toolsFromCommands(program.commands.filter((one) => one.path[0] === "config"), {
98
+ ...catalogue,
99
+ omit: ["bot", "personal", "defaults"]
100
+ })
101
+ ];
102
+ const writes = tools.filter((tool) => tool.writes && tool.availability?.().available !== false).map((tool) => tool.command);
103
+ const skill = options.skill ? skillResource(bot.app, options.skill) : void 0;
104
+ let queue = Promise.resolve();
105
+ const invoke = /* @__PURE__ */ __name((path, input, caller) => {
106
+ const next = queue.then(() => runCommandForAgent(program, path, path[0] === "config" ? { ...input, bot: true } : input, {
107
+ profile: settings.profile,
108
+ readOnly: readOnlyLockOf(bot.app, env) !== void 0,
109
+ env,
110
+ levels,
111
+ ...options.keyOf ? { keyOf: options.keyOf } : {},
112
+ authority,
113
+ ...caller ? { caller } : {}
114
+ }));
115
+ queue = next.catch(() => void 0);
116
+ return next;
117
+ }, "invoke");
118
+ const build = /* @__PURE__ */ __name(() => {
119
+ const callers = { env, client: /* @__PURE__ */ __name(() => server.server.getClientVersion(), "client"), connectionId: randomUUID() };
120
+ const server = new McpServer({ name: `${command}-bot-${settings.profile}`, version: bot.app.version }, {
121
+ instructions: botInstructions({
122
+ command,
123
+ name: bot.name ?? command,
124
+ profile: settings.profile,
125
+ writes,
126
+ ...skill ? { skill: skill.instruction } : {}
127
+ })
128
+ });
129
+ if (skill) {
130
+ const { uri, name, title, description, mimeType, read } = skill;
131
+ server.registerResource(name, uri, { title, description, mimeType }, read);
132
+ }
133
+ const commands = Object.fromEntries(tools.map((tool) => [
134
+ tool.command,
135
+ {
136
+ title: tool.title,
137
+ description: tool.description,
138
+ writes: tool.writes,
139
+ availability: tool.availability,
140
+ input: tool.input,
141
+ run: /* @__PURE__ */ __name(async (args, ctx) => {
142
+ const caller = callerOf(ctx, `${command}_${tool.command.replaceAll(" ", "_")}`, callers);
143
+ const answer = await invoke(tool.path, args, caller);
144
+ return "error" in answer ? mcpErrorResult(JSON.parse(agentJson(answer.error))) : answered(body(tool.command, answer.result));
145
+ }, "run")
146
+ }
147
+ ]));
148
+ commands.status = {
149
+ title: "This server's bot and profile",
150
+ description: "Which profile this server speaks for, where its bot token comes from, which bot it is, and which writing commands are on. Sends nothing.",
151
+ writes: false,
152
+ input: object({}),
153
+ run: /* @__PURE__ */ __name(async () => {
154
+ const auth = await invoke(["bot", "auth", "show"], {});
155
+ const shown = "error" in auth ? auth.error : auth.result?.item ?? auth.result;
156
+ return answered(itemOf({
157
+ profile: settings.profile,
158
+ kind: "bot",
159
+ auth: shown,
160
+ writes: tools.filter((tool) => tool.writes && tool.availability?.().available !== false).map((tool) => tool.command),
161
+ permissions: levels()
162
+ }));
163
+ }, "run")
164
+ };
165
+ registerCommands(server, `${command}_bot`, commands, void 0, (asked) => {
166
+ const lock = readOnlyLockOf(bot.app, env);
167
+ const one = flatten(program.commands).find((info) => info.path[0] === "bot" && normal(info.path.slice(1).join(" ")) === asked);
168
+ if (lock && one && changesMessenger(one))
169
+ throw readOnlyRefusal(lock, MESSENGER_CHANGE_REFUSAL);
170
+ }, bot.app.messenger);
171
+ return server;
172
+ }, "build");
173
+ return { build, tools, offered: tools.map((tool) => tool.command) };
174
+ }, "createBotServer");
175
+ var serveBotOverStdio = /* @__PURE__ */ __name(async (options, note) => {
176
+ const { build } = createBotServer(options);
177
+ const handle = serveStdio(build, { onerror: /* @__PURE__ */ __name((error) => note(`mcp: ${error.message}`), "onerror") });
178
+ await new Promise((resolve) => {
179
+ process.stdin.once("end", resolve);
180
+ process.stdin.once("close", resolve);
181
+ process.once("SIGINT", resolve);
182
+ process.once("SIGTERM", resolve);
183
+ });
184
+ await handle.close();
185
+ }, "serveBotOverStdio");
186
+ export {
187
+ createBotServer,
188
+ serveBotOverStdio
189
+ };
@@ -0,0 +1,18 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ ensureSqlite,
5
+ nodeRuntime,
6
+ relay
7
+ } from "./chunk-TWPDVUBR.js";
8
+ import "./chunk-F6D6PJ34.js";
9
+ import "./chunk-J3QXTBD2.js";
10
+ import "./chunk-LQ37ALDJ.js";
11
+ import "./chunk-Y5E2WNWB.js";
12
+ import "./chunk-5BVIWP3S.js";
13
+ import "./chunk-ZVVMGPBJ.js";
14
+ export {
15
+ ensureSqlite,
16
+ nodeRuntime,
17
+ relay
18
+ };
@@ -0,0 +1,35 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ ACCESS_SECONDS,
5
+ REFRESH_SECONDS,
6
+ httpLaunchFile,
7
+ httpLock,
8
+ httpLockFile,
9
+ httpLogFile,
10
+ mcpHttpMarker,
11
+ readHttpLaunch,
12
+ readHttpLock,
13
+ readStored,
14
+ signedInClients
15
+ } from "./chunk-GN62YOT5.js";
16
+ import "./chunk-TE5U5OAM.js";
17
+ import "./chunk-KM7Q67Z3.js";
18
+ import "./chunk-J3QXTBD2.js";
19
+ import "./chunk-LQ37ALDJ.js";
20
+ import "./chunk-Y5E2WNWB.js";
21
+ import "./chunk-5BVIWP3S.js";
22
+ import "./chunk-ZVVMGPBJ.js";
23
+ export {
24
+ ACCESS_SECONDS,
25
+ REFRESH_SECONDS,
26
+ httpLaunchFile,
27
+ httpLock,
28
+ httpLockFile,
29
+ httpLogFile,
30
+ mcpHttpMarker,
31
+ readHttpLaunch,
32
+ readHttpLock,
33
+ readStored,
34
+ signedInClients
35
+ };