@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,195 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ stringWidth,
5
+ wrapAnsi
6
+ } from "./chunk-HTQTIKWP.js";
7
+ import {
8
+ singleLine,
9
+ visibleControls
10
+ } from "./chunk-5BVIWP3S.js";
11
+ import {
12
+ __name
13
+ } from "./chunk-ZVVMGPBJ.js";
14
+
15
+ // 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/render/messages.js
16
+ import { styleText } from "node:util";
17
+ var TIME_WIDTH = 8;
18
+ var INDENT = " ".repeat(TIME_WIDTH + 2);
19
+ var MIN_WIDTH = 40;
20
+ var SENDER_COLOURS = ["green", "yellow", "magenta", "blue", "red"];
21
+ var renderMessages = /* @__PURE__ */ __name((messages, options = {}) => {
22
+ if (messages.length === 0)
23
+ return "(nothing)";
24
+ const day = dayFormatter(options);
25
+ const paint = painter(options);
26
+ let previous;
27
+ const blocks = [];
28
+ for (const message of messages) {
29
+ const date = day(message.timestamp);
30
+ if (date !== previous)
31
+ blocks.push(paint("dim", `\u2500\u2500 ${date} \u2500\u2500`));
32
+ previous = date;
33
+ blocks.push(renderMessage(message, options));
34
+ }
35
+ return blocks.join("\n\n");
36
+ }, "renderMessages");
37
+ var renderMessage = /* @__PURE__ */ __name((message, options = {}) => {
38
+ const paint = painter(options);
39
+ const width = Math.max(MIN_WIDTH, options.width ?? 80);
40
+ const room = width - INDENT.length;
41
+ const time = timeFormatter(options);
42
+ const verbosity = options.verbosity ?? 0;
43
+ const chat = "chatTitle" in message ? paint("dim", ` \xB7 ${singleLine(message.chatTitle ?? message.chatId)}`) : "";
44
+ const mark = "anchor" in message && message.anchor ? paint("bold", " \u25C0") : "";
45
+ const lines = [`${paint("dim", time(message.timestamp))} ${senderOf(message, options)}${chat}${mark}`];
46
+ const body = /* @__PURE__ */ __name((text) => wrapAnsi(visibleControls(text), room, { hard: true }).split("\n"), "body");
47
+ const email = message.email;
48
+ if (email)
49
+ lines.push(paint("dim", mailLine(email)));
50
+ if (message.replyTo)
51
+ lines.push(paint("dim", preview("\u21B3", message.replyTo, room, options)));
52
+ if (message.forwardedFrom) {
53
+ lines.push(paint("dim", `\u21AA ${nameOf(message.forwardedFrom, options)}`));
54
+ if (message.forwardedFrom.text)
55
+ for (const line of body(message.forwardedFrom.text))
56
+ lines.push(line);
57
+ lines.push(...attachmentLines(message.forwardedFrom.attachments, paint, options));
58
+ }
59
+ if (message.text)
60
+ for (const line of body(message.text))
61
+ lines.push(line);
62
+ lines.push(...attachmentLines(message.attachments, paint, options));
63
+ if (message.reactions && message.reactions.total > 0)
64
+ lines.push(paint("dim", reactionLine(message.reactions)));
65
+ if (message.editedAt)
66
+ lines.push(paint("dim", `edited ${editedAt(message, options)}`));
67
+ if (verbosity >= 1) {
68
+ const fields = [
69
+ ["message", message.id],
70
+ ["sender", message.senderId],
71
+ ["chat", message.chatId],
72
+ ["reply to", message.replyTo?.id ?? message.replyToId],
73
+ ["thread", message.threadId],
74
+ ["forward of", message.forwardedFrom?.id],
75
+ ...message.attachments.map((a) => ["link", a.url])
76
+ ];
77
+ if (verbosity >= 2) {
78
+ fields.push(["provider", options.provider], ["profile", options.profile], ["sent", message.timestamp], ["edited", message.editedAt], ["outgoing", message.outgoing === null ? "unknown" : String(message.outgoing)], ...message.attachments.map((a) => ["attachment", JSON.stringify(a)]), ["metadata", message.providerMetadata && JSON.stringify(message.providerMetadata)]);
79
+ }
80
+ const shown = fields.filter((field) => typeof field[1] === "string");
81
+ const label = Math.max(...shown.map(([key]) => key.length));
82
+ lines.push("", ...shown.map(([key, value]) => paint("dim", `${key.padEnd(label)} ${singleLine(value)}`)));
83
+ }
84
+ return lines.map((line, index) => index === 0 || line === "" ? line : `${INDENT}${line}`).join("\n");
85
+ }, "renderMessage");
86
+ var mailLine = /* @__PURE__ */ __name(({ to, cc, labels }) => {
87
+ const names = /* @__PURE__ */ __name((people) => people.map(({ name, address }) => singleLine(name ?? address)).join(", "), "names");
88
+ return [to.length ? `to ${names(to)}` : "", cc.length ? `cc ${names(cc)}` : "", labels.join(", ")].filter(Boolean).join(" \xB7 ");
89
+ }, "mailLine");
90
+ var painter = /* @__PURE__ */ __name(({ color = false }) => (style, text) => color ? styleText(style, text, { validateStream: false }) : text, "painter");
91
+ var senderOf = /* @__PURE__ */ __name((message, options) => {
92
+ const paint = painter(options);
93
+ if (message.outgoing === true)
94
+ return paint(["bold", "cyan"], you(options));
95
+ const name = nameOf(message, options);
96
+ if (!options.senderColors)
97
+ return paint("bold", name);
98
+ const colour = SENDER_COLOURS[hash(message.senderId ?? name) % SENDER_COLOURS.length] ?? "green";
99
+ return paint(["bold", colour], name);
100
+ }, "senderOf");
101
+ var nameOf = /* @__PURE__ */ __name(({ senderName, senderId, outgoing }, options) => outgoing === true ? you(options) : singleLine(senderName ?? senderId ?? "unknown"), "nameOf");
102
+ var DEFAULT_LOCALE = "ru-RU";
103
+ var you = /* @__PURE__ */ __name(({ locale = DEFAULT_LOCALE }) => locale.startsWith("ru") ? "\u0432\u044B" : "you", "you");
104
+ var hash = /* @__PURE__ */ __name((value) => [...value].reduce((sum, char) => sum * 31 + char.charCodeAt(0) >>> 0, 7), "hash");
105
+ var preview = /* @__PURE__ */ __name((mark, quoted, room, options) => {
106
+ const text = singleLine(quoted.text.split("\n")[0] ?? "") || (quoted.attachments[0] ? `\u{1F4CE} ${quoted.attachments[0].kind}` : "");
107
+ const line = text ? `${mark} ${nameOf(quoted, options)}: ${text}` : `${mark} message ${quoted.id}`;
108
+ if (stringWidth(line) <= room)
109
+ return line;
110
+ return `${wrapAnsi(line, room - 1, { hard: true }).split("\n")[0]}\u2026`;
111
+ }, "preview");
112
+ var attachmentLines = /* @__PURE__ */ __name((attachments, paint, options) => {
113
+ const link = /* @__PURE__ */ __name((label, raw) => {
114
+ if (raw === void 0)
115
+ return label;
116
+ const url = singleLine(raw);
117
+ return options.color ? `\x1B]8;;${url}\x07${label}\x1B]8;;\x07` : `${label} ${url}`;
118
+ }, "link");
119
+ let number = 0;
120
+ const keyboard = attachments.flatMap((attachment) => attachment.buttons ?? []).map((row) => paint("dim", row.map((button) => link(`[${++number} ${singleLine(button.text)}]`, button.url)).join(" ")));
121
+ const polls = attachments.flatMap((attachment) => attachment.poll ? pollLines(attachment.poll) : []);
122
+ const cards = attachments.flatMap(({ contact }) => contact ? [
123
+ paint("dim", `\u{1F464} ${[contact.name, contact.phone].flatMap((part) => part ? [singleLine(part)] : []).join(" \xB7 ")}`)
124
+ ] : []);
125
+ const groups = /* @__PURE__ */ new Map();
126
+ for (const attachment of attachments) {
127
+ if (attachment.buttons || attachment.poll || attachment.contact)
128
+ continue;
129
+ const key = singleLine(attachment.name ?? attachment.title ?? attachment.kind);
130
+ groups.set(key, [...groups.get(key) ?? [], attachment]);
131
+ }
132
+ const files = [...groups].map(([label, same]) => {
133
+ const first = same[0];
134
+ const size = first?.size === void 0 ? "" : ` \xB7 ${megabytes(first.size)}`;
135
+ if (same.length === 1)
136
+ return paint("dim", `\u{1F4CE} ${link(`${label}${size}`, first?.url)}`);
137
+ const each = same.map((attachment, index) => link(String(index + 1), attachment.url)).join(" ");
138
+ return paint("dim", `\u{1F4CE} ${label} \xD7${same.length} ${each}`);
139
+ });
140
+ return [...polls, ...cards, ...files, ...keyboard];
141
+ }, "attachmentLines");
142
+ var pollLines = /* @__PURE__ */ __name((poll) => {
143
+ const kind = [
144
+ poll.closed ? "closed" : "",
145
+ poll.multiple ? "several answers" : "",
146
+ poll.anonymous ? "anonymous" : "",
147
+ poll.quiz ? "quiz" : ""
148
+ ].filter(Boolean);
149
+ const count = /* @__PURE__ */ __name((voters) => voters === null ? "?" : String(voters), "count");
150
+ return [
151
+ `\u{1F4CA} ${visibleControls(poll.question)}`,
152
+ ...poll.answers.map((answer) => ` [${answer.id}] ${visibleControls(answer.text)} \u2014 ${count(answer.voters)}${answer.chosen ? " \u2713" : ""}`),
153
+ ` ${[`${count(poll.voters)} voted`, ...kind].join(" \xB7 ")}`
154
+ ];
155
+ }, "pollLines");
156
+ var megabytes = /* @__PURE__ */ __name((bytes) => bytes >= 1e6 ? `${Math.round(bytes / 1e6)} MB` : `${Math.max(1, Math.round(bytes / 1e3))} KB`, "megabytes");
157
+ var parts = /* @__PURE__ */ __name((format, iso) => Object.fromEntries(format.formatToParts(new Date(iso)).map(({ type, value }) => [type, value])), "parts");
158
+ var timeFormatter = /* @__PURE__ */ __name(({ timeZone }) => {
159
+ const format = new Intl.DateTimeFormat("en-GB", {
160
+ hour: "2-digit",
161
+ minute: "2-digit",
162
+ second: "2-digit",
163
+ hourCycle: "h23",
164
+ ...timeZone ? { timeZone } : {}
165
+ });
166
+ return (iso) => {
167
+ const { hour, minute, second } = parts(format, iso);
168
+ return `${hour}:${minute}:${second}`;
169
+ };
170
+ }, "timeFormatter");
171
+ var dayFormatter = /* @__PURE__ */ __name(({ locale = DEFAULT_LOCALE, timeZone }) => {
172
+ const format = new Intl.DateTimeFormat(locale, {
173
+ day: "numeric",
174
+ month: "long",
175
+ year: "numeric",
176
+ ...timeZone ? { timeZone } : {}
177
+ });
178
+ return (iso) => format.format(new Date(iso)).replace(/\s*г\.$/, "");
179
+ }, "dayFormatter");
180
+ var reactionLine = /* @__PURE__ */ __name(({ counts, mine }) => {
181
+ const shown = counts.map(({ reaction, count }) => `${singleLine(reaction)} ${count}`).join(" ");
182
+ return mine ? `${shown} (you: ${singleLine(mine)})` : shown;
183
+ }, "reactionLine");
184
+ var editedAt = /* @__PURE__ */ __name((message, options) => {
185
+ const edited = message.editedAt ?? message.timestamp;
186
+ const time = timeFormatter(options)(edited);
187
+ const day = dayFormatter(options);
188
+ return day(edited) === day(message.timestamp) ? time : `${day(edited)} ${time}`;
189
+ }, "editedAt");
190
+
191
+ export {
192
+ renderMessages,
193
+ renderMessage,
194
+ pollLines
195
+ };
@@ -0,0 +1,161 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ holdLock,
5
+ readLock,
6
+ releaseLock,
7
+ takeLock
8
+ } from "./chunk-TE5U5OAM.js";
9
+ import {
10
+ __name
11
+ } from "./chunk-ZVVMGPBJ.js";
12
+
13
+ // 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/state.js
14
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
15
+
16
+ // 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/activity.js
17
+ import { randomBytes } from "node:crypto";
18
+ import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
19
+ import { dirname } from "node:path";
20
+ var WRITE_EVERY_MS = 2e3;
21
+ var TOOL_NAME = /^[A-Za-z0-9_.-]{1,64}$/;
22
+ var httpActivityFile = /* @__PURE__ */ __name((tokenFile) => `${tokenFile.replace(/\.json$/, "")}.activity.json`, "httpActivityFile");
23
+ var localDay = /* @__PURE__ */ __name((ms) => {
24
+ const d = new Date(ms);
25
+ return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
26
+ }, "localDay");
27
+ var readActivity = /* @__PURE__ */ __name((path) => {
28
+ if (!existsSync(path))
29
+ return {};
30
+ try {
31
+ const parsed = JSON.parse(readFileSync(path, "utf8"));
32
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
33
+ } catch {
34
+ return {};
35
+ }
36
+ }, "readActivity");
37
+ var calledTools = /* @__PURE__ */ __name((body) => (Array.isArray(body) ? body : [body]).flatMap((message) => {
38
+ if (!message || typeof message !== "object")
39
+ return [];
40
+ const { method, params } = message;
41
+ const name = params?.name;
42
+ return method === "tools/call" && typeof name === "string" && TOOL_NAME.test(name) ? [name] : [];
43
+ }), "calledTools");
44
+ var activityRecorder = /* @__PURE__ */ __name((path, now = Date.now) => {
45
+ const activity = readActivity(path);
46
+ let timer;
47
+ const write = /* @__PURE__ */ __name(() => {
48
+ timer = void 0;
49
+ try {
50
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
51
+ const temporary = `${path}.${randomBytes(8).toString("hex")}.tmp`;
52
+ writeFileSync(temporary, JSON.stringify(activity), { mode: 384, flag: "wx" });
53
+ chmodSync(temporary, 384);
54
+ renameSync(temporary, path);
55
+ } catch {
56
+ }
57
+ }, "write");
58
+ return {
59
+ record: /* @__PURE__ */ __name((clientId, tools) => {
60
+ const at = now();
61
+ const iso = new Date(at).toISOString();
62
+ const day = localDay(at);
63
+ const before = activity[clientId];
64
+ const counted = before?.day === day ? before.toolCalls : 0;
65
+ const last = tools.at(-1);
66
+ activity[clientId] = {
67
+ lastRequestAt: iso,
68
+ day,
69
+ toolCalls: counted + tools.length,
70
+ ...last ? { lastTool: last, lastToolAt: iso } : before?.lastTool ? { lastTool: before.lastTool, ...before.lastToolAt ? { lastToolAt: before.lastToolAt } : {} } : {}
71
+ };
72
+ if (last) {
73
+ clearTimeout(timer);
74
+ write();
75
+ } else if (!timer) {
76
+ timer = setTimeout(write, WRITE_EVERY_MS);
77
+ timer.unref();
78
+ }
79
+ }, "record"),
80
+ flush: /* @__PURE__ */ __name(() => {
81
+ if (!timer)
82
+ return;
83
+ clearTimeout(timer);
84
+ write();
85
+ }, "flush")
86
+ };
87
+ }, "activityRecorder");
88
+
89
+ // 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/state.js
90
+ var ACCESS_SECONDS = 60 * 60;
91
+ var REFRESH_SECONDS = 30 * 24 * 60 * 60;
92
+ var readStored = /* @__PURE__ */ __name((path) => existsSync2(path) ? JSON.parse(readFileSync2(path, "utf8")) : { clients: [], tokens: [] }, "readStored");
93
+ var mcpHttpMarker = /* @__PURE__ */ __name((envPrefix) => `${envPrefix}_MCP_HTTP`, "mcpHttpMarker");
94
+ var httpLogFile = /* @__PURE__ */ __name((tokenFile) => `${tokenFile.replace(/\.json$/, "")}.log`, "httpLogFile");
95
+ var httpLockFile = /* @__PURE__ */ __name((tokenFile) => `${tokenFile.replace(/\.json$/, "")}.lock`, "httpLockFile");
96
+ var httpLaunchFile = /* @__PURE__ */ __name((lockFile) => `${lockFile.replace(/\.lock$/, "")}.launch.json`, "httpLaunchFile");
97
+ var readHttpLaunch = /* @__PURE__ */ __name((path) => {
98
+ try {
99
+ const launch = JSON.parse(readFileSync2(path, "utf8"));
100
+ return typeof launch.invocation === "string" && Array.isArray(launch.argv) && launch.argv.every((word) => typeof word === "string") && typeof launch.env === "object" && launch.env !== null ? launch : void 0;
101
+ } catch {
102
+ return void 0;
103
+ }
104
+ }, "readHttpLaunch");
105
+ var readHttpLock = /* @__PURE__ */ __name((path) => {
106
+ const lock = readLock(path);
107
+ return lock && typeof lock.port === "number" && typeof lock.publicUrl === "string" ? lock : void 0;
108
+ }, "readHttpLock");
109
+ var httpLock = /* @__PURE__ */ __name((path, first) => {
110
+ let current = first;
111
+ const held = takeLock(path, current);
112
+ return {
113
+ held,
114
+ update: /* @__PURE__ */ __name((change) => {
115
+ current = { ...current, ...change };
116
+ holdLock(path, current);
117
+ }, "update"),
118
+ release: /* @__PURE__ */ __name(() => releaseLock(path), "release")
119
+ };
120
+ }, "httpLock");
121
+ var signedInClients = /* @__PURE__ */ __name((tokenFile, now = Date.now()) => {
122
+ const seconds = Math.floor(now / 1e3);
123
+ const { clients, tokens } = readStored(tokenFile);
124
+ const activity = readActivity(httpActivityFile(tokenFile));
125
+ const today = localDay(now);
126
+ const last = /* @__PURE__ */ new Map();
127
+ for (const token of tokens) {
128
+ if (token.expiresAt <= seconds)
129
+ continue;
130
+ const issued = token.expiresAt - (token.kind === "access" ? ACCESS_SECONDS : REFRESH_SECONDS);
131
+ last.set(token.clientId, Math.max(last.get(token.clientId) ?? 0, issued));
132
+ }
133
+ return clients.filter((client) => last.has(client.id)).map((client) => {
134
+ const did = activity[client.id];
135
+ return {
136
+ claimedName: client.name ?? null,
137
+ lastLoginAt: new Date((last.get(client.id) ?? 0) * 1e3).toISOString(),
138
+ lastRequestAt: did?.lastRequestAt ?? null,
139
+ lastTool: did?.lastTool ?? null,
140
+ lastToolAt: did?.lastToolAt ?? null,
141
+ toolCallsToday: did?.day === today ? did.toolCalls : 0
142
+ };
143
+ }).sort((a, b) => b.lastLoginAt.localeCompare(a.lastLoginAt));
144
+ }, "signedInClients");
145
+
146
+ export {
147
+ httpActivityFile,
148
+ calledTools,
149
+ activityRecorder,
150
+ ACCESS_SECONDS,
151
+ REFRESH_SECONDS,
152
+ readStored,
153
+ mcpHttpMarker,
154
+ httpLogFile,
155
+ httpLockFile,
156
+ httpLaunchFile,
157
+ readHttpLaunch,
158
+ readHttpLock,
159
+ httpLock,
160
+ signedInClients
161
+ };