@wirecat/notion-cli 0.0.0-stage → 0.2.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 (262) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/LICENSE +204 -0
  3. package/README.md +42 -2
  4. package/contracts/wirecat.json +1964 -0
  5. package/dist/bin/notion.d.ts +3 -0
  6. package/dist/bin/notion.d.ts.map +1 -0
  7. package/dist/bin/notion.js +40 -0
  8. package/dist/bin/notion.js.map +1 -0
  9. package/dist/bundle/all-profiles-JGYLQZ5C.js +278 -0
  10. package/dist/bundle/anthropic-S2VSMIKQ.js +91 -0
  11. package/dist/bundle/app-server-SASYDBCA.js +240 -0
  12. package/dist/bundle/bun-LU5LP3JI.js +169 -0
  13. package/dist/bundle/bun-sqlite-JBSINB4O.js +76 -0
  14. package/dist/bundle/chunk-22QQUKWA.js +53 -0
  15. package/dist/bundle/chunk-2F4QQ7WB.js +73 -0
  16. package/dist/bundle/chunk-2F6VO5HA.js +73 -0
  17. package/dist/bundle/chunk-2LWO3PDX.js +726 -0
  18. package/dist/bundle/chunk-3AL7QUS3.js +2778 -0
  19. package/dist/bundle/chunk-3Z4YTSRY.js +731 -0
  20. package/dist/bundle/chunk-4HWJOU7N.js +38 -0
  21. package/dist/bundle/chunk-4IPURN72.js +1221 -0
  22. package/dist/bundle/chunk-4ZTVJHWU.js +206 -0
  23. package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
  24. package/dist/bundle/chunk-5IYKVRH2.js +44811 -0
  25. package/dist/bundle/chunk-5NFK5EM2.js +362 -0
  26. package/dist/bundle/chunk-5QIQEUOG.js +188 -0
  27. package/dist/bundle/chunk-5RDNBG7D.js +72 -0
  28. package/dist/bundle/chunk-5RSC54NA.js +1328 -0
  29. package/dist/bundle/chunk-6EVKHZKN.js +158 -0
  30. package/dist/bundle/chunk-6RA3EABS.js +4012 -0
  31. package/dist/bundle/chunk-AOCUKEAX.js +131 -0
  32. package/dist/bundle/chunk-B26TQZKZ.js +217 -0
  33. package/dist/bundle/chunk-B7ON6KPT.js +1197 -0
  34. package/dist/bundle/chunk-BNPTZ5ZB.js +161 -0
  35. package/dist/bundle/chunk-D72URWJE.js +532 -0
  36. package/dist/bundle/chunk-D7QSEEYW.js +274 -0
  37. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  38. package/dist/bundle/chunk-DH5PRHT4.js +392 -0
  39. package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
  40. package/dist/bundle/chunk-EUIVXFLJ.js +259 -0
  41. package/dist/bundle/chunk-FPY6EJ7B.js +9568 -0
  42. package/dist/bundle/chunk-FT3LN3HP.js +6848 -0
  43. package/dist/bundle/chunk-FWVBPRL4.js +4436 -0
  44. package/dist/bundle/chunk-FXEJY4OL.js +12538 -0
  45. package/dist/bundle/chunk-G3EZFRSS.js +1297 -0
  46. package/dist/bundle/chunk-GZOUFX3C.js +230 -0
  47. package/dist/bundle/chunk-HL52XXZX.js +78 -0
  48. package/dist/bundle/chunk-KCLOUUYF.js +100 -0
  49. package/dist/bundle/chunk-KFVDL2QS.js +146 -0
  50. package/dist/bundle/chunk-KGERXYTV.js +24 -0
  51. package/dist/bundle/chunk-KM6WHPHI.js +288 -0
  52. package/dist/bundle/chunk-LAYPFBOM.js +95 -0
  53. package/dist/bundle/chunk-LLG2POQ7.js +170 -0
  54. package/dist/bundle/chunk-M3KB25D3.js +1392 -0
  55. package/dist/bundle/chunk-M7S2NDWB.js +76 -0
  56. package/dist/bundle/chunk-MGUEZYFA.js +5546 -0
  57. package/dist/bundle/chunk-MY742GAD.js +1977 -0
  58. package/dist/bundle/chunk-MZU2YFBZ.js +823 -0
  59. package/dist/bundle/chunk-NOQ7B5N7.js +58 -0
  60. package/dist/bundle/chunk-NQWV4WQO.js +300 -0
  61. package/dist/bundle/chunk-ODBZNSZ6.js +1028 -0
  62. package/dist/bundle/chunk-OTV53F34.js +370 -0
  63. package/dist/bundle/chunk-P7CUM5IB.js +18 -0
  64. package/dist/bundle/chunk-RV64YUQX.js +185 -0
  65. package/dist/bundle/chunk-SHJQ6JKG.js +106 -0
  66. package/dist/bundle/chunk-SWAOWNKW.js +52 -0
  67. package/dist/bundle/chunk-SZOVLP44.js +29 -0
  68. package/dist/bundle/chunk-TPX2M45D.js +385 -0
  69. package/dist/bundle/chunk-TSDBSIFM.js +66 -0
  70. package/dist/bundle/chunk-VBHETQVV.js +64146 -0
  71. package/dist/bundle/chunk-VCIALTEM.js +3139 -0
  72. package/dist/bundle/chunk-VKE77B3F.js +2 -0
  73. package/dist/bundle/chunk-WCSOH4JS.js +142 -0
  74. package/dist/bundle/chunk-WF4D56CA.js +54 -0
  75. package/dist/bundle/chunk-WJHZMR2W.js +335 -0
  76. package/dist/bundle/chunk-X4TIMMKJ.js +16 -0
  77. package/dist/bundle/chunk-XF26XKTS.js +82 -0
  78. package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
  79. package/dist/bundle/chunk-XQUUANA2.js +24600 -0
  80. package/dist/bundle/chunk-XYIT2XB3.js +1372 -0
  81. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  82. package/dist/bundle/chunk-YMYUBZWT.js +1068 -0
  83. package/dist/bundle/chunk-YNTLT3Z3.js +2310 -0
  84. package/dist/bundle/chunk-YVI5SQPY.js +46 -0
  85. package/dist/bundle/chunk-Z56QFOBR.js +63 -0
  86. package/dist/bundle/chunk-ZKAEZXUP.js +787 -0
  87. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  88. package/dist/bundle/chunk-ZZ32DXTH.js +23 -0
  89. package/dist/bundle/command-contract-JS5V27NX.js +38 -0
  90. package/dist/bundle/command-server-entry-UFSG7KRO.js +167 -0
  91. package/dist/bundle/decode-7LLWTSPT.js +297 -0
  92. package/dist/bundle/definitions-M3U4UYHN.js +45607 -0
  93. package/dist/bundle/dispatch-2GY6JIJH.js +411 -0
  94. package/dist/bundle/dist-ILNOLGYN.js +7577 -0
  95. package/dist/bundle/echarts-BXX4OQWC.js +42501 -0
  96. package/dist/bundle/embed-JXFNBTKH.js +38 -0
  97. package/dist/bundle/embedder-57YZ44KO.js +111 -0
  98. package/dist/bundle/failure-MYT4HPE3.js +25 -0
  99. package/dist/bundle/first-run-3PF7T74J.js +29 -0
  100. package/dist/bundle/first-screen-7BEROEQR.js +36 -0
  101. package/dist/bundle/instructions-2VECIDXF.js +11 -0
  102. package/dist/bundle/mcp-O6ACR2DX.js +167 -0
  103. package/dist/bundle/mdast-util-from-markdown-R66F4HZA.js +1958 -0
  104. package/dist/bundle/mdast-util-gfm-LN2ELINH.js +2699 -0
  105. package/dist/bundle/meeting-combined-PPUQ3KBR.js +24 -0
  106. package/dist/bundle/meeting-model-ZNMYKMCD.js +26 -0
  107. package/dist/bundle/meeting-semantic-ETN3A4BJ.js +22 -0
  108. package/dist/bundle/micromark-extension-gfm-5X7YT43T.js +1838 -0
  109. package/dist/bundle/node-KM3CUABH.js +2340 -0
  110. package/dist/bundle/node-MPEQSFI3.js +176 -0
  111. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  112. package/dist/bundle/node-sqlite-WA32MYSJ.js +74 -0
  113. package/dist/bundle/notion.js +185 -0
  114. package/dist/bundle/oauth-IAFZG3IR.js +20 -0
  115. package/dist/bundle/open-M3JQUC5G.js +23 -0
  116. package/dist/bundle/openai-HXUEHUSD.js +240 -0
  117. package/dist/bundle/process-F6TKXWWA.js +91 -0
  118. package/dist/bundle/program-Y7JAB6TG.js +33219 -0
  119. package/dist/bundle/prompt-IMUQLZD2.js +17 -0
  120. package/dist/bundle/recognize-2MZAYHAA.js +26 -0
  121. package/dist/bundle/remote-OV4LB6VR.js +32 -0
  122. package/dist/bundle/rerank-ZIULUS34.js +52 -0
  123. package/dist/bundle/schemas-DIVZS6TU.js +12214 -0
  124. package/dist/bundle/serve-YU7QBP6L.js +199 -0
  125. package/dist/bundle/server-FKQET4ZO.js +71 -0
  126. package/dist/bundle/server-LGMNONSB.js +202 -0
  127. package/dist/bundle/services-5WY4DCPJ.js +581 -0
  128. package/dist/bundle/sqlite-runtime-5MXZDETH.js +20 -0
  129. package/dist/bundle/state-LWMZH2KI.js +36 -0
  130. package/dist/bundle/store-EPZYV4VW.js +168 -0
  131. package/dist/bundle/store-QE6FEIZD.js +286 -0
  132. package/dist/bundle/store-maintenance-command-ZUUUFCHL.js +62 -0
  133. package/dist/commands/api.d.ts +4 -0
  134. package/dist/commands/api.d.ts.map +1 -0
  135. package/dist/commands/api.js +140 -0
  136. package/dist/commands/api.js.map +1 -0
  137. package/dist/commands/databases.d.ts +3 -0
  138. package/dist/commands/databases.d.ts.map +1 -0
  139. package/dist/commands/databases.js +65 -0
  140. package/dist/commands/databases.js.map +1 -0
  141. package/dist/commands/documents.d.ts +4 -0
  142. package/dist/commands/documents.d.ts.map +1 -0
  143. package/dist/commands/documents.js +41 -0
  144. package/dist/commands/documents.js.map +1 -0
  145. package/dist/commands/library.d.ts +10 -0
  146. package/dist/commands/library.d.ts.map +1 -0
  147. package/dist/commands/library.js +468 -0
  148. package/dist/commands/library.js.map +1 -0
  149. package/dist/commands/session.d.ts +3 -0
  150. package/dist/commands/session.d.ts.map +1 -0
  151. package/dist/commands/session.js +105 -0
  152. package/dist/commands/session.js.map +1 -0
  153. package/dist/config.d.ts +5 -0
  154. package/dist/config.d.ts.map +1 -0
  155. package/dist/config.js +13 -0
  156. package/dist/config.js.map +1 -0
  157. package/dist/context.d.ts +51 -0
  158. package/dist/context.d.ts.map +1 -0
  159. package/dist/context.js +67 -0
  160. package/dist/context.js.map +1 -0
  161. package/dist/generated/definitions.d.ts +3 -0
  162. package/dist/generated/definitions.d.ts.map +1 -0
  163. package/dist/generated/definitions.js +45603 -0
  164. package/dist/generated/definitions.js.map +1 -0
  165. package/dist/generated/manifest.d.ts +3 -0
  166. package/dist/generated/manifest.d.ts.map +1 -0
  167. package/dist/generated/manifest.js +2089 -0
  168. package/dist/generated/manifest.js.map +1 -0
  169. package/dist/generated/metadata.d.ts +6 -0
  170. package/dist/generated/metadata.d.ts.map +1 -0
  171. package/dist/generated/metadata.js +24 -0
  172. package/dist/generated/metadata.js.map +1 -0
  173. package/dist/generated/schemas.d.ts +1223 -0
  174. package/dist/generated/schemas.d.ts.map +1 -0
  175. package/dist/generated/schemas.js +11557 -0
  176. package/dist/generated/schemas.js.map +1 -0
  177. package/dist/generated/types.d.ts +11120 -0
  178. package/dist/generated/types.d.ts.map +1 -0
  179. package/dist/generated/types.js +5 -0
  180. package/dist/generated/types.js.map +1 -0
  181. package/dist/identity.d.ts +7 -0
  182. package/dist/identity.d.ts.map +1 -0
  183. package/dist/identity.js +30 -0
  184. package/dist/identity.js.map +1 -0
  185. package/dist/index.d.ts +3 -0
  186. package/dist/index.d.ts.map +1 -0
  187. package/dist/index.js +3 -0
  188. package/dist/index.js.map +1 -0
  189. package/dist/knowledge.d.ts +27 -0
  190. package/dist/knowledge.d.ts.map +1 -0
  191. package/dist/knowledge.js +87 -0
  192. package/dist/knowledge.js.map +1 -0
  193. package/dist/library.d.ts +44 -0
  194. package/dist/library.d.ts.map +1 -0
  195. package/dist/library.js +149 -0
  196. package/dist/library.js.map +1 -0
  197. package/dist/notion/client.d.ts +45 -0
  198. package/dist/notion/client.d.ts.map +1 -0
  199. package/dist/notion/client.js +121 -0
  200. package/dist/notion/client.js.map +1 -0
  201. package/dist/notion/errors.d.ts +24 -0
  202. package/dist/notion/errors.d.ts.map +1 -0
  203. package/dist/notion/errors.js +127 -0
  204. package/dist/notion/errors.js.map +1 -0
  205. package/dist/notion/ids.d.ts +7 -0
  206. package/dist/notion/ids.d.ts.map +1 -0
  207. package/dist/notion/ids.js +37 -0
  208. package/dist/notion/ids.js.map +1 -0
  209. package/dist/notion/links.d.ts +6 -0
  210. package/dist/notion/links.d.ts.map +1 -0
  211. package/dist/notion/links.js +22 -0
  212. package/dist/notion/links.js.map +1 -0
  213. package/dist/notion/notion.d.ts +95 -0
  214. package/dist/notion/notion.d.ts.map +1 -0
  215. package/dist/notion/notion.js +269 -0
  216. package/dist/notion/notion.js.map +1 -0
  217. package/dist/notion/port.d.ts +13 -0
  218. package/dist/notion/port.d.ts.map +1 -0
  219. package/dist/notion/port.js +60 -0
  220. package/dist/notion/port.js.map +1 -0
  221. package/dist/notion/read-posts.d.ts +36 -0
  222. package/dist/notion/read-posts.d.ts.map +1 -0
  223. package/dist/notion/read-posts.js +24 -0
  224. package/dist/notion/read-posts.js.map +1 -0
  225. package/dist/notion/reads.d.ts +331 -0
  226. package/dist/notion/reads.d.ts.map +1 -0
  227. package/dist/notion/reads.js +18 -0
  228. package/dist/notion/reads.js.map +1 -0
  229. package/dist/program.d.ts +6 -0
  230. package/dist/program.d.ts.map +1 -0
  231. package/dist/program.js +62 -0
  232. package/dist/program.js.map +1 -0
  233. package/dist/sync/cursor.d.ts +135 -0
  234. package/dist/sync/cursor.d.ts.map +1 -0
  235. package/dist/sync/cursor.js +113 -0
  236. package/dist/sync/cursor.js.map +1 -0
  237. package/dist/sync/files.d.ts +77 -0
  238. package/dist/sync/files.d.ts.map +1 -0
  239. package/dist/sync/files.js +12 -0
  240. package/dist/sync/files.js.map +1 -0
  241. package/dist/sync/front-matter.d.ts +10 -0
  242. package/dist/sync/front-matter.d.ts.map +1 -0
  243. package/dist/sync/front-matter.js +114 -0
  244. package/dist/sync/front-matter.js.map +1 -0
  245. package/dist/sync/markdown.d.ts +11 -0
  246. package/dist/sync/markdown.d.ts.map +1 -0
  247. package/dist/sync/markdown.js +42 -0
  248. package/dist/sync/markdown.js.map +1 -0
  249. package/dist/sync/source.d.ts +11 -0
  250. package/dist/sync/source.d.ts.map +1 -0
  251. package/dist/sync/source.js +995 -0
  252. package/dist/sync/source.js.map +1 -0
  253. package/dist/version.d.ts +2 -0
  254. package/dist/version.d.ts.map +1 -0
  255. package/dist/version.js +2 -0
  256. package/dist/version.js.map +1 -0
  257. package/dist/wcat.d.ts +3 -0
  258. package/dist/wcat.d.ts.map +1 -0
  259. package/dist/wcat.js +4 -0
  260. package/dist/wcat.js.map +1 -0
  261. package/package.json +85 -4
  262. package/skills/notion-cli/SKILL.md +45 -0
@@ -0,0 +1,199 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ listen
5
+ } from "./chunk-HL52XXZX.js";
6
+ import {
7
+ ownerLogin
8
+ } from "./chunk-KM6WHPHI.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-BNPTZ5ZB.js";
24
+ import "./chunk-2F4QQ7WB.js";
25
+ import "./chunk-Z56QFOBR.js";
26
+ import "./chunk-3AL7QUS3.js";
27
+ import "./chunk-4IPURN72.js";
28
+ import "./chunk-XYIT2XB3.js";
29
+ import "./chunk-Y5E2WNWB.js";
30
+ import {
31
+ CliError
32
+ } from "./chunk-5RDNBG7D.js";
33
+ import {
34
+ __name
35
+ } from "./chunk-ZVVMGPBJ.js";
36
+
37
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/mcp/http/serve.js
38
+ import { randomUUID } from "node:crypto";
39
+ var MCP_PATH = "/mcp";
40
+ var AS_METADATA = "/.well-known/oauth-authorization-server";
41
+ var LOCAL = ["localhost", "127.0.0.1"];
42
+ var MAX_SESSIONS = 20;
43
+ var MAX_LOGIN_BODY = 64 * 1024;
44
+ var SESSION_IDLE_MS = 60 * 60 * 1e3;
45
+ var sessionMissing = /* @__PURE__ */ __name(() => new Response(JSON.stringify({ jsonrpc: "2.0", error: { code: -32001, message: "Session not found" }, id: null }), {
46
+ status: 404,
47
+ headers: { "content-type": "application/json" }
48
+ }), "sessionMissing");
49
+ var legacySessions = /* @__PURE__ */ __name((build, now) => {
50
+ const sessions = /* @__PURE__ */ new Map();
51
+ const drop = /* @__PURE__ */ __name(async (id) => {
52
+ const one = sessions.get(id);
53
+ sessions.delete(id);
54
+ await one?.close();
55
+ }, "drop");
56
+ const handle = /* @__PURE__ */ __name(async (request, auth) => {
57
+ for (const [id2, one] of sessions)
58
+ if (now() - one.seen > SESSION_IDLE_MS)
59
+ await drop(id2);
60
+ const id = request.headers.get("mcp-session-id");
61
+ if (id) {
62
+ const known = sessions.get(id);
63
+ if (!known || known.clientId !== auth.clientId)
64
+ return sessionMissing();
65
+ known.seen = now();
66
+ return known.transport.handleRequest(request, { authInfo: auth });
67
+ }
68
+ const server = build();
69
+ const transport = new WebStandardStreamableHTTPServerTransport({
70
+ sessionIdGenerator: /* @__PURE__ */ __name(() => randomUUID(), "sessionIdGenerator"),
71
+ onsessionclosed: /* @__PURE__ */ __name((closed) => void sessions.delete(closed), "onsessionclosed")
72
+ });
73
+ await server.connect(transport);
74
+ const response = await transport.handleRequest(request, { authInfo: auth });
75
+ if (!transport.sessionId) {
76
+ await server.close();
77
+ return response;
78
+ }
79
+ sessions.set(transport.sessionId, { transport, close: /* @__PURE__ */ __name(() => server.close(), "close"), clientId: auth.clientId, seen: now() });
80
+ while (sessions.size > MAX_SESSIONS)
81
+ await drop(sessions.keys().next().value);
82
+ return response;
83
+ }, "handle");
84
+ return {
85
+ handle,
86
+ close: /* @__PURE__ */ __name(async () => {
87
+ for (const id of [...sessions.keys()])
88
+ await drop(id);
89
+ }, "close")
90
+ };
91
+ }, "legacySessions");
92
+ var metadataRequest = /* @__PURE__ */ __name((request, path, base) => {
93
+ const url = new URL(request.url);
94
+ const inserted = base && path === `${AS_METADATA}${base}`;
95
+ if (!inserted && url.pathname === path)
96
+ return request;
97
+ url.pathname = inserted ? AS_METADATA : path;
98
+ return new Request(url, { method: request.method, headers: request.headers });
99
+ }, "metadataRequest");
100
+ var toolsIn = /* @__PURE__ */ __name(async (request) => {
101
+ if (request.method !== "POST")
102
+ return [];
103
+ try {
104
+ return calledTools(await request.clone().json());
105
+ } catch {
106
+ return [];
107
+ }
108
+ }, "toolsIn");
109
+ var serveOverHttp = /* @__PURE__ */ __name(async (build, options) => {
110
+ const { publicUrl, port, tokenFile, appName, reaches, onCode, onError, now, lockFile, version } = options;
111
+ const lock = lockFile ? httpLock(lockFile, {
112
+ pid: process.pid,
113
+ startedAt: (/* @__PURE__ */ new Date()).toISOString(),
114
+ port,
115
+ publicUrl: publicUrl.href,
116
+ ...version ? { version } : {}
117
+ }) : void 0;
118
+ if (lock?.held)
119
+ 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})`);
120
+ const base = publicUrl.pathname === "/" ? "" : publicUrl.pathname.replace(/\/+$/, "");
121
+ const issuer = new URL(`${publicUrl.origin}${base}`);
122
+ const resource = new URL(`${base}${MCP_PATH}`, publicUrl.origin);
123
+ const mcpPath = resource.pathname;
124
+ const publicPath = /* @__PURE__ */ __name((path) => base && path !== base && !path.startsWith(`${base}/`) && !path.startsWith("/.well-known/") ? `${base}${path}` : path, "publicPath");
125
+ const login = ownerLogin({
126
+ issuer,
127
+ resource,
128
+ file: tokenFile,
129
+ appName,
130
+ ...reaches ? { reaches } : {},
131
+ onCode: /* @__PURE__ */ __name((code, expires) => {
132
+ lock?.update({ loginCode: code, loginCodeExpiresAt: expires.toISOString() });
133
+ onCode(code, expires);
134
+ }, "onCode"),
135
+ ...now ? { now } : {}
136
+ });
137
+ const insecure = issuer.protocol === "http:" && LOCAL.includes(issuer.hostname);
138
+ const mcp = createMcpHandler(build, { legacy: "reject", ...onError ? { onerror: onError } : {} });
139
+ const legacy = legacySessions(build, now ?? Date.now);
140
+ const bearer = requireBearerAuth({
141
+ verifier: login.verifier,
142
+ resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(resource)
143
+ });
144
+ const activity = activityRecorder(httpActivityFile(tokenFile), now);
145
+ const allowedHosts = [.../* @__PURE__ */ new Set([publicUrl.hostname, ...LOCAL])];
146
+ const allowedOrigins = [publicUrl.origin];
147
+ const listening = await listen(async (request) => {
148
+ const refused = hostHeaderValidationResponse(request, allowedHosts);
149
+ if (refused)
150
+ return refused;
151
+ const path = publicPath(new URL(request.url).pathname);
152
+ const discovery = oauthMetadataResponse(metadataRequest(request, path, base), {
153
+ oauthMetadata: login.metadata,
154
+ resourceServerUrl: resource,
155
+ resourceName: appName,
156
+ ...insecure ? { dangerouslyAllowInsecureIssuerUrl: true } : {}
157
+ });
158
+ if (discovery)
159
+ return discovery;
160
+ if (Number(request.headers.get("content-length") ?? 0) > MAX_LOGIN_BODY && path !== mcpPath)
161
+ return new Response("Request too large", { status: 413 });
162
+ const origin = request.headers.get("origin");
163
+ if (origin && !allowedOrigins.includes(origin))
164
+ return new Response("Origin not allowed", { status: 403 });
165
+ const answered = await login.handle(request, path);
166
+ if (answered)
167
+ return answered;
168
+ if (path !== mcpPath)
169
+ return new Response("Not found", { status: 404 });
170
+ const auth = await bearer(request);
171
+ if (auth instanceof Response)
172
+ return auth;
173
+ activity.record(auth.clientId, await toolsIn(request));
174
+ return await isLegacyRequest(request) ? legacy.handle(request, auth) : mcp.fetch(request, { authInfo: auth });
175
+ }, { host: "127.0.0.1", port }).catch((error) => {
176
+ login.close();
177
+ lock?.release();
178
+ throw error;
179
+ });
180
+ lock?.update({ listeningAt: (/* @__PURE__ */ new Date()).toISOString() });
181
+ return {
182
+ url: listening.url,
183
+ close: /* @__PURE__ */ __name(async () => {
184
+ login.close();
185
+ activity.flush();
186
+ try {
187
+ await listening.close();
188
+ await legacy.close();
189
+ await mcp.close();
190
+ } finally {
191
+ lock?.release();
192
+ }
193
+ }, "close")
194
+ };
195
+ }, "serveOverHttp");
196
+ export {
197
+ MCP_PATH,
198
+ serveOverHttp
199
+ };
@@ -0,0 +1,71 @@
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-ZKAEZXUP.js";
10
+ import "./chunk-5RSC54NA.js";
11
+ import "./chunk-P7CUM5IB.js";
12
+ import "./chunk-6RA3EABS.js";
13
+ import "./chunk-G3EZFRSS.js";
14
+ import "./chunk-3Z4YTSRY.js";
15
+ import "./chunk-M3KB25D3.js";
16
+ import "./chunk-2LWO3PDX.js";
17
+ import "./chunk-XF26XKTS.js";
18
+ import "./chunk-22QQUKWA.js";
19
+ import "./chunk-5D4AEUVA.js";
20
+ import "./chunk-5IYKVRH2.js";
21
+ import "./chunk-DH5PRHT4.js";
22
+ import "./chunk-WCSOH4JS.js";
23
+ import "./chunk-YVI5SQPY.js";
24
+ import "./chunk-M7S2NDWB.js";
25
+ import "./chunk-EUIVXFLJ.js";
26
+ import "./chunk-TPX2M45D.js";
27
+ import "./chunk-LLG2POQ7.js";
28
+ import "./chunk-BNPTZ5ZB.js";
29
+ import "./chunk-2F4QQ7WB.js";
30
+ import "./chunk-AOCUKEAX.js";
31
+ import "./chunk-FXEJY4OL.js";
32
+ import "./chunk-5NFK5EM2.js";
33
+ import "./chunk-SWAOWNKW.js";
34
+ import "./chunk-WJHZMR2W.js";
35
+ import "./chunk-Z56QFOBR.js";
36
+ import "./chunk-YMYUBZWT.js";
37
+ import "./chunk-TSDBSIFM.js";
38
+ import "./chunk-VBHETQVV.js";
39
+ import "./chunk-YNTLT3Z3.js";
40
+ import "./chunk-MZU2YFBZ.js";
41
+ import "./chunk-X4TIMMKJ.js";
42
+ import "./chunk-MY742GAD.js";
43
+ import "./chunk-6EVKHZKN.js";
44
+ import "./chunk-SZOVLP44.js";
45
+ import "./chunk-FWVBPRL4.js";
46
+ import "./chunk-RV64YUQX.js";
47
+ import "./chunk-2F6VO5HA.js";
48
+ import "./chunk-B7ON6KPT.js";
49
+ import "./chunk-ODBZNSZ6.js";
50
+ import "./chunk-D7QSEEYW.js";
51
+ import "./chunk-ZZ32DXTH.js";
52
+ import "./chunk-VKE77B3F.js";
53
+ import "./chunk-NQWV4WQO.js";
54
+ import "./chunk-D72URWJE.js";
55
+ import "./chunk-WF4D56CA.js";
56
+ import "./chunk-LAYPFBOM.js";
57
+ import "./chunk-4HWJOU7N.js";
58
+ import "./chunk-3AL7QUS3.js";
59
+ import "./chunk-4IPURN72.js";
60
+ import "./chunk-XYIT2XB3.js";
61
+ import "./chunk-Y5E2WNWB.js";
62
+ import "./chunk-5RDNBG7D.js";
63
+ import "./chunk-FT3LN3HP.js";
64
+ import "./chunk-ZVVMGPBJ.js";
65
+ export {
66
+ PER_RUN,
67
+ createServer,
68
+ envelope,
69
+ serveOverHttpUntilStopped,
70
+ serveOverStdio
71
+ };
@@ -0,0 +1,202 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ botInstructions
5
+ } from "./chunk-KGERXYTV.js";
6
+ import {
7
+ answered,
8
+ normal,
9
+ registerCommands,
10
+ runCommandForAgent,
11
+ toolsFromCommands
12
+ } from "./chunk-6RA3EABS.js";
13
+ import {
14
+ agentJson,
15
+ skillResource
16
+ } from "./chunk-G3EZFRSS.js";
17
+ import {
18
+ StdioServerTransport,
19
+ answeredWire,
20
+ callerOf,
21
+ serveStdio
22
+ } from "./chunk-3Z4YTSRY.js";
23
+ import {
24
+ wholeList
25
+ } from "./chunk-2LWO3PDX.js";
26
+ import "./chunk-XF26XKTS.js";
27
+ import {
28
+ McpServer
29
+ } from "./chunk-5D4AEUVA.js";
30
+ import "./chunk-5IYKVRH2.js";
31
+ import "./chunk-DH5PRHT4.js";
32
+ import "./chunk-WCSOH4JS.js";
33
+ import "./chunk-YVI5SQPY.js";
34
+ import "./chunk-M7S2NDWB.js";
35
+ import "./chunk-EUIVXFLJ.js";
36
+ import "./chunk-TPX2M45D.js";
37
+ import "./chunk-LLG2POQ7.js";
38
+ import {
39
+ MESSENGER_CHANGE_REFUSAL,
40
+ changesMessenger,
41
+ flatten,
42
+ itemOf,
43
+ readOnlyLockOf,
44
+ readOnlyRefusal
45
+ } from "./chunk-FXEJY4OL.js";
46
+ import "./chunk-5NFK5EM2.js";
47
+ import "./chunk-SWAOWNKW.js";
48
+ import "./chunk-WJHZMR2W.js";
49
+ import "./chunk-Z56QFOBR.js";
50
+ import "./chunk-YMYUBZWT.js";
51
+ import "./chunk-TSDBSIFM.js";
52
+ import "./chunk-VBHETQVV.js";
53
+ import "./chunk-YNTLT3Z3.js";
54
+ import "./chunk-MZU2YFBZ.js";
55
+ import "./chunk-X4TIMMKJ.js";
56
+ import "./chunk-MY742GAD.js";
57
+ import "./chunk-6EVKHZKN.js";
58
+ import "./chunk-SZOVLP44.js";
59
+ import "./chunk-FWVBPRL4.js";
60
+ import "./chunk-RV64YUQX.js";
61
+ import "./chunk-2F6VO5HA.js";
62
+ import "./chunk-B7ON6KPT.js";
63
+ import "./chunk-ODBZNSZ6.js";
64
+ import "./chunk-D7QSEEYW.js";
65
+ import "./chunk-ZZ32DXTH.js";
66
+ import "./chunk-VKE77B3F.js";
67
+ import "./chunk-NQWV4WQO.js";
68
+ import "./chunk-D72URWJE.js";
69
+ import "./chunk-WF4D56CA.js";
70
+ import "./chunk-LAYPFBOM.js";
71
+ import "./chunk-4HWJOU7N.js";
72
+ import "./chunk-3AL7QUS3.js";
73
+ import {
74
+ mcpErrorResult
75
+ } from "./chunk-4IPURN72.js";
76
+ import {
77
+ object
78
+ } from "./chunk-XYIT2XB3.js";
79
+ import "./chunk-Y5E2WNWB.js";
80
+ import "./chunk-5RDNBG7D.js";
81
+ import "./chunk-FT3LN3HP.js";
82
+ import {
83
+ __name
84
+ } from "./chunk-ZVVMGPBJ.js";
85
+
86
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/mcp/bot/server.js
87
+ import { randomUUID } from "node:crypto";
88
+ 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");
89
+ var createBotServer = /* @__PURE__ */ __name((options) => {
90
+ const { bot, program, settings, env } = options;
91
+ const command = bot.app.command;
92
+ const levels = options.levels ?? (() => settings.permissions);
93
+ const authority = /* @__PURE__ */ __name((path) => options.authority?.(path) === true || path[0] === "config" && (path[1] === "set" || path[1] === "unset"), "authority");
94
+ const catalogue = {
95
+ includeUnavailable: true,
96
+ levels: settings.permissions,
97
+ currentLevels: levels,
98
+ readOnly: readOnlyLockOf(bot.app, env) !== void 0,
99
+ ...options.keyOf ? { keyOf: options.keyOf } : {},
100
+ authority,
101
+ ...options.fetchOnly ? { fetchOnly: options.fetchOnly } : {},
102
+ ...options.fetches ? { fetches: options.fetches } : {},
103
+ offline: true,
104
+ // Another bot's copy is this bot's to read only where `read_other_bots` says so.
105
+ ...settings.readOtherBots ? {} : { omit: ["all_bots", "bots"] }
106
+ };
107
+ const tools = [
108
+ ...toolsFromCommands(program.commands, { ...catalogue, root: ["bot"] }),
109
+ ...toolsFromCommands(program.commands.filter((one) => one.path[0] === "config"), {
110
+ ...catalogue,
111
+ omit: ["bot", "personal", "defaults"]
112
+ })
113
+ ];
114
+ const writes = tools.filter((tool) => tool.writes && tool.availability?.().available !== false).map((tool) => tool.command);
115
+ const skill = options.skill ? skillResource(bot.app, options.skill) : void 0;
116
+ let queue = Promise.resolve();
117
+ const invoke = /* @__PURE__ */ __name((path, input, caller) => {
118
+ const next = queue.then(() => runCommandForAgent(program, path, path[0] === "config" ? { ...input, bot: true } : input, {
119
+ profile: settings.profile,
120
+ readOnly: readOnlyLockOf(bot.app, env) !== void 0,
121
+ env,
122
+ levels,
123
+ ...options.keyOf ? { keyOf: options.keyOf } : {},
124
+ authority,
125
+ ...options.fetches ? { fetches: options.fetches } : {},
126
+ ...caller ? { caller } : {}
127
+ }));
128
+ queue = next.catch(() => void 0);
129
+ return next;
130
+ }, "invoke");
131
+ const build = /* @__PURE__ */ __name(() => {
132
+ const callers = { env, client: /* @__PURE__ */ __name(() => server.server.getClientVersion(), "client"), connectionId: randomUUID() };
133
+ const server = new McpServer({ name: `${command}-bot-${settings.profile}`, version: bot.app.version }, {
134
+ instructions: botInstructions({
135
+ command,
136
+ name: bot.name ?? command,
137
+ profile: settings.profile,
138
+ writes,
139
+ ...skill ? { skill: skill.instruction } : {}
140
+ })
141
+ });
142
+ if (skill) {
143
+ const { uri, name, title, description, mimeType, read } = skill;
144
+ server.registerResource(name, uri, { title, description, mimeType }, read);
145
+ }
146
+ const commands = Object.fromEntries(tools.map((tool) => [
147
+ tool.command,
148
+ {
149
+ title: tool.title,
150
+ description: tool.description,
151
+ writes: tool.writes,
152
+ availability: tool.availability,
153
+ input: tool.input,
154
+ run: /* @__PURE__ */ __name(async (args, ctx) => {
155
+ const caller = callerOf(ctx, `${command}_${tool.command.replaceAll(" ", "_")}`, callers);
156
+ const answer = await invoke(tool.path, args, caller);
157
+ return "error" in answer ? mcpErrorResult(JSON.parse(agentJson(answer.error))) : answered(body(tool.command, answer.result));
158
+ }, "run")
159
+ }
160
+ ]));
161
+ commands.status = {
162
+ title: "This server's bot and profile",
163
+ 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.",
164
+ writes: false,
165
+ input: object({}),
166
+ run: /* @__PURE__ */ __name(async () => {
167
+ const auth = await invoke(["bot", "auth", "show"], {});
168
+ const shown = "error" in auth ? auth.error : auth.result?.item ?? auth.result;
169
+ return answered(itemOf({
170
+ profile: settings.profile,
171
+ kind: "bot",
172
+ auth: shown,
173
+ writes: tools.filter((tool) => tool.writes && tool.availability?.().available !== false).map((tool) => tool.command),
174
+ permissions: levels()
175
+ }));
176
+ }, "run")
177
+ };
178
+ registerCommands(server, `${command}_bot`, commands, void 0, (asked) => {
179
+ const lock = readOnlyLockOf(bot.app, env);
180
+ const one = flatten(program.commands).find((info) => info.path[0] === "bot" && normal(info.path.slice(1).join(" ")) === asked);
181
+ if (lock && one && changesMessenger(one))
182
+ throw readOnlyRefusal(lock, MESSENGER_CHANGE_REFUSAL);
183
+ }, bot.app.messenger);
184
+ return server;
185
+ }, "build");
186
+ return { build, tools, offered: tools.map((tool) => tool.command) };
187
+ }, "createBotServer");
188
+ var serveBotOverStdio = /* @__PURE__ */ __name(async (options, note) => {
189
+ const { build } = createBotServer(options);
190
+ const wire = answeredWire(process.stdin, process.stdout);
191
+ const handle = serveStdio(build, {
192
+ transport: new StdioServerTransport(wire.input, wire.output),
193
+ onerror: /* @__PURE__ */ __name((error) => note(`mcp: ${error.message}`), "onerror")
194
+ });
195
+ await wire.finished();
196
+ wire.release();
197
+ await handle.close();
198
+ }, "serveBotOverStdio");
199
+ export {
200
+ createBotServer,
201
+ serveBotOverStdio
202
+ };