@wirecat/notion-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 (243) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE +204 -0
  3. package/README.md +36 -2
  4. package/contracts/wirecat.json +1315 -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-OETMCOLN.js +278 -0
  10. package/dist/bundle/anthropic-5Y3O2TYM.js +91 -0
  11. package/dist/bundle/app-server-IVWBIVHC.js +231 -0
  12. package/dist/bundle/bun-EO636SAD.js +169 -0
  13. package/dist/bundle/bun-sqlite-C2T7QJ2M.js +76 -0
  14. package/dist/bundle/chunk-24FAYAML.js +52 -0
  15. package/dist/bundle/chunk-2YR3RYT4.js +73 -0
  16. package/dist/bundle/chunk-35K5T6WV.js +24 -0
  17. package/dist/bundle/chunk-3D3PFXBP.js +2315 -0
  18. package/dist/bundle/chunk-47R43UVJ.js +1068 -0
  19. package/dist/bundle/chunk-4GC5DBHW.js +100 -0
  20. package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
  21. package/dist/bundle/chunk-64D5VUZ4.js +9564 -0
  22. package/dist/bundle/chunk-66PL7P4C.js +23 -0
  23. package/dist/bundle/chunk-7FII4DCE.js +362 -0
  24. package/dist/bundle/chunk-7N5QB6NL.js +156 -0
  25. package/dist/bundle/chunk-AE2KQ37N.js +95 -0
  26. package/dist/bundle/chunk-AQZO3ITW.js +58 -0
  27. package/dist/bundle/chunk-B2WFKFYL.js +1488 -0
  28. package/dist/bundle/chunk-B2XKEEFX.js +230 -0
  29. package/dist/bundle/chunk-B4B65XIO.js +73 -0
  30. package/dist/bundle/chunk-BWICUW7W.js +288 -0
  31. package/dist/bundle/chunk-CLG2ISQH.js +206 -0
  32. package/dist/bundle/chunk-CWVAYQXI.js +185 -0
  33. package/dist/bundle/chunk-D72URWJE.js +532 -0
  34. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  35. package/dist/bundle/chunk-DIM5YWBU.js +53 -0
  36. package/dist/bundle/chunk-EGTBL3MJ.js +6848 -0
  37. package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
  38. package/dist/bundle/chunk-EPAZ7DJB.js +783 -0
  39. package/dist/bundle/chunk-ESZT4WW3.js +142 -0
  40. package/dist/bundle/chunk-EU5WCOMQ.js +4001 -0
  41. package/dist/bundle/chunk-F6MLJ3V5.js +72 -0
  42. package/dist/bundle/chunk-FF4DDBCB.js +1028 -0
  43. package/dist/bundle/chunk-GA3URWIF.js +46 -0
  44. package/dist/bundle/chunk-HRTIRRXR.js +3112 -0
  45. package/dist/bundle/chunk-HWRKURQH.js +54 -0
  46. package/dist/bundle/chunk-IQWEJEB5.js +39724 -0
  47. package/dist/bundle/chunk-JK44XO2S.js +392 -0
  48. package/dist/bundle/chunk-JKIN5TOU.js +131 -0
  49. package/dist/bundle/chunk-K5TWMQSY.js +188 -0
  50. package/dist/bundle/chunk-KHOVVPLC.js +18 -0
  51. package/dist/bundle/chunk-NLDYZBTC.js +5862 -0
  52. package/dist/bundle/chunk-OWJDC4CB.js +217 -0
  53. package/dist/bundle/chunk-QBC23NHD.js +38 -0
  54. package/dist/bundle/chunk-QC3KOJT4.js +300 -0
  55. package/dist/bundle/chunk-R6ZM45NF.js +1239 -0
  56. package/dist/bundle/chunk-RAZKIHGH.js +76 -0
  57. package/dist/bundle/chunk-RDZ7SVBZ.js +731 -0
  58. package/dist/bundle/chunk-RLSFOR2D.js +161 -0
  59. package/dist/bundle/chunk-RSIS7BR7.js +2778 -0
  60. package/dist/bundle/chunk-ST2UC7FS.js +1324 -0
  61. package/dist/bundle/chunk-TR7R5DL4.js +370 -0
  62. package/dist/bundle/chunk-TSCIIXN3.js +106 -0
  63. package/dist/bundle/chunk-UWIA2G6Q.js +12737 -0
  64. package/dist/bundle/chunk-UWW24JQF.js +66 -0
  65. package/dist/bundle/chunk-WK3OSDNV.js +1197 -0
  66. package/dist/bundle/chunk-WM7663C2.js +1221 -0
  67. package/dist/bundle/chunk-WVZFXI36.js +274 -0
  68. package/dist/bundle/chunk-WWMB4UHF.js +78 -0
  69. package/dist/bundle/chunk-XC5CKHX2.js +63 -0
  70. package/dist/bundle/chunk-XL2HXHP3.js +82 -0
  71. package/dist/bundle/chunk-XQUUANA2.js +24600 -0
  72. package/dist/bundle/chunk-XYIT2XB3.js +1372 -0
  73. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  74. package/dist/bundle/chunk-YA4LSSDZ.js +64499 -0
  75. package/dist/bundle/chunk-ZI3YTXSF.js +2 -0
  76. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  77. package/dist/bundle/command-contract-6G5DC2FN.js +35 -0
  78. package/dist/bundle/command-server-entry-A66DJ3MH.js +164 -0
  79. package/dist/bundle/decode-7XOFRAAT.js +163 -0
  80. package/dist/bundle/definitions-M3U4UYHN.js +45607 -0
  81. package/dist/bundle/dispatch-FEKU5UXC.js +411 -0
  82. package/dist/bundle/dist-YFKABFFF.js +7577 -0
  83. package/dist/bundle/echarts-XD2JSWU4.js +42501 -0
  84. package/dist/bundle/embed-F3HYGAF7.js +38 -0
  85. package/dist/bundle/embedder-GSEDDUH7.js +111 -0
  86. package/dist/bundle/failure-HDJLR2YJ.js +25 -0
  87. package/dist/bundle/first-run-TXNTIUSP.js +28 -0
  88. package/dist/bundle/first-screen-JZPJND7J.js +33 -0
  89. package/dist/bundle/instructions-NZGJ4FW5.js +11 -0
  90. package/dist/bundle/mcp-VFIOZDVY.js +167 -0
  91. package/dist/bundle/node-KM3CUABH.js +2340 -0
  92. package/dist/bundle/node-RPKPDYQS.js +176 -0
  93. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  94. package/dist/bundle/node-sqlite-KH2UUYVO.js +74 -0
  95. package/dist/bundle/notion.js +185 -0
  96. package/dist/bundle/oauth-NKAI7TQD.js +20 -0
  97. package/dist/bundle/open-WSAEAA2V.js +23 -0
  98. package/dist/bundle/openai-JPVDGHG5.js +238 -0
  99. package/dist/bundle/process-5ZFVKOQX.js +91 -0
  100. package/dist/bundle/program-M3D56D6T.js +28854 -0
  101. package/dist/bundle/prompt-FROYQ5LV.js +17 -0
  102. package/dist/bundle/recognize-NYCHQMCX.js +26 -0
  103. package/dist/bundle/remote-4OERF3Z4.js +32 -0
  104. package/dist/bundle/rerank-TEGXFUWY.js +52 -0
  105. package/dist/bundle/schemas-MZNNOEYN.js +12214 -0
  106. package/dist/bundle/serve-HLYYBAXY.js +199 -0
  107. package/dist/bundle/server-D5OYNEUW.js +193 -0
  108. package/dist/bundle/server-LWZGVMNW.js +62 -0
  109. package/dist/bundle/sqlite-runtime-H2S5RR2F.js +20 -0
  110. package/dist/bundle/state-OPOXCDZL.js +36 -0
  111. package/dist/bundle/store-NHMXEJPD.js +164 -0
  112. package/dist/bundle/store-Y3KRLCJ7.js +281 -0
  113. package/dist/bundle/store-maintenance-command-D4W7WSLQ.js +53 -0
  114. package/dist/commands/api.d.ts +4 -0
  115. package/dist/commands/api.d.ts.map +1 -0
  116. package/dist/commands/api.js +140 -0
  117. package/dist/commands/api.js.map +1 -0
  118. package/dist/commands/comments.d.ts +3 -0
  119. package/dist/commands/comments.d.ts.map +1 -0
  120. package/dist/commands/comments.js +114 -0
  121. package/dist/commands/comments.js.map +1 -0
  122. package/dist/commands/databases.d.ts +3 -0
  123. package/dist/commands/databases.d.ts.map +1 -0
  124. package/dist/commands/databases.js +65 -0
  125. package/dist/commands/databases.js.map +1 -0
  126. package/dist/commands/documents.d.ts +3 -0
  127. package/dist/commands/documents.d.ts.map +1 -0
  128. package/dist/commands/documents.js +41 -0
  129. package/dist/commands/documents.js.map +1 -0
  130. package/dist/commands/session.d.ts +3 -0
  131. package/dist/commands/session.d.ts.map +1 -0
  132. package/dist/commands/session.js +104 -0
  133. package/dist/commands/session.js.map +1 -0
  134. package/dist/config.d.ts +5 -0
  135. package/dist/config.d.ts.map +1 -0
  136. package/dist/config.js +13 -0
  137. package/dist/config.js.map +1 -0
  138. package/dist/context.d.ts +46 -0
  139. package/dist/context.d.ts.map +1 -0
  140. package/dist/context.js +58 -0
  141. package/dist/context.js.map +1 -0
  142. package/dist/generated/definitions.d.ts +3 -0
  143. package/dist/generated/definitions.d.ts.map +1 -0
  144. package/dist/generated/definitions.js +45603 -0
  145. package/dist/generated/definitions.js.map +1 -0
  146. package/dist/generated/manifest.d.ts +3 -0
  147. package/dist/generated/manifest.d.ts.map +1 -0
  148. package/dist/generated/manifest.js +2089 -0
  149. package/dist/generated/manifest.js.map +1 -0
  150. package/dist/generated/metadata.d.ts +6 -0
  151. package/dist/generated/metadata.d.ts.map +1 -0
  152. package/dist/generated/metadata.js +24 -0
  153. package/dist/generated/metadata.js.map +1 -0
  154. package/dist/generated/schemas.d.ts +1223 -0
  155. package/dist/generated/schemas.d.ts.map +1 -0
  156. package/dist/generated/schemas.js +11557 -0
  157. package/dist/generated/schemas.js.map +1 -0
  158. package/dist/generated/types.d.ts +11120 -0
  159. package/dist/generated/types.d.ts.map +1 -0
  160. package/dist/generated/types.js +5 -0
  161. package/dist/generated/types.js.map +1 -0
  162. package/dist/identity.d.ts +7 -0
  163. package/dist/identity.d.ts.map +1 -0
  164. package/dist/identity.js +29 -0
  165. package/dist/identity.js.map +1 -0
  166. package/dist/index.d.ts +3 -0
  167. package/dist/index.d.ts.map +1 -0
  168. package/dist/index.js +3 -0
  169. package/dist/index.js.map +1 -0
  170. package/dist/notion/client.d.ts +42 -0
  171. package/dist/notion/client.d.ts.map +1 -0
  172. package/dist/notion/client.js +118 -0
  173. package/dist/notion/client.js.map +1 -0
  174. package/dist/notion/errors.d.ts +24 -0
  175. package/dist/notion/errors.d.ts.map +1 -0
  176. package/dist/notion/errors.js +102 -0
  177. package/dist/notion/errors.js.map +1 -0
  178. package/dist/notion/ids.d.ts +7 -0
  179. package/dist/notion/ids.d.ts.map +1 -0
  180. package/dist/notion/ids.js +37 -0
  181. package/dist/notion/ids.js.map +1 -0
  182. package/dist/notion/links.d.ts +6 -0
  183. package/dist/notion/links.d.ts.map +1 -0
  184. package/dist/notion/links.js +22 -0
  185. package/dist/notion/links.js.map +1 -0
  186. package/dist/notion/notion.d.ts +95 -0
  187. package/dist/notion/notion.d.ts.map +1 -0
  188. package/dist/notion/notion.js +269 -0
  189. package/dist/notion/notion.js.map +1 -0
  190. package/dist/notion/port.d.ts +13 -0
  191. package/dist/notion/port.d.ts.map +1 -0
  192. package/dist/notion/port.js +60 -0
  193. package/dist/notion/port.js.map +1 -0
  194. package/dist/notion/read-posts.d.ts +36 -0
  195. package/dist/notion/read-posts.d.ts.map +1 -0
  196. package/dist/notion/read-posts.js +24 -0
  197. package/dist/notion/read-posts.js.map +1 -0
  198. package/dist/notion/reads.d.ts +327 -0
  199. package/dist/notion/reads.d.ts.map +1 -0
  200. package/dist/notion/reads.js +18 -0
  201. package/dist/notion/reads.js.map +1 -0
  202. package/dist/program.d.ts +6 -0
  203. package/dist/program.d.ts.map +1 -0
  204. package/dist/program.js +62 -0
  205. package/dist/program.js.map +1 -0
  206. package/dist/sample/comments.d.ts +61 -0
  207. package/dist/sample/comments.d.ts.map +1 -0
  208. package/dist/sample/comments.js +39 -0
  209. package/dist/sample/comments.js.map +1 -0
  210. package/dist/sample/records.d.ts +16 -0
  211. package/dist/sample/records.d.ts.map +1 -0
  212. package/dist/sample/records.js +22 -0
  213. package/dist/sample/records.js.map +1 -0
  214. package/dist/sample/transport.d.ts +42 -0
  215. package/dist/sample/transport.d.ts.map +1 -0
  216. package/dist/sample/transport.js +153 -0
  217. package/dist/sample/transport.js.map +1 -0
  218. package/dist/sync/cursor.d.ts +54 -0
  219. package/dist/sync/cursor.d.ts.map +1 -0
  220. package/dist/sync/cursor.js +52 -0
  221. package/dist/sync/cursor.js.map +1 -0
  222. package/dist/sync/front-matter.d.ts +10 -0
  223. package/dist/sync/front-matter.d.ts.map +1 -0
  224. package/dist/sync/front-matter.js +114 -0
  225. package/dist/sync/front-matter.js.map +1 -0
  226. package/dist/sync/markdown.d.ts +8 -0
  227. package/dist/sync/markdown.d.ts.map +1 -0
  228. package/dist/sync/markdown.js +40 -0
  229. package/dist/sync/markdown.js.map +1 -0
  230. package/dist/sync/source.d.ts +64 -0
  231. package/dist/sync/source.d.ts.map +1 -0
  232. package/dist/sync/source.js +634 -0
  233. package/dist/sync/source.js.map +1 -0
  234. package/dist/version.d.ts +2 -0
  235. package/dist/version.d.ts.map +1 -0
  236. package/dist/version.js +2 -0
  237. package/dist/version.js.map +1 -0
  238. package/dist/wcat.d.ts +3 -0
  239. package/dist/wcat.d.ts.map +1 -0
  240. package/dist/wcat.js +4 -0
  241. package/dist/wcat.js.map +1 -0
  242. package/package.json +85 -4
  243. package/skills/notion-cli/SKILL.md +34 -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-WWMB4UHF.js";
6
+ import {
7
+ ownerLogin
8
+ } from "./chunk-BWICUW7W.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-RLSFOR2D.js";
24
+ import "./chunk-B4B65XIO.js";
25
+ import "./chunk-XC5CKHX2.js";
26
+ import "./chunk-RSIS7BR7.js";
27
+ import "./chunk-WM7663C2.js";
28
+ import "./chunk-XYIT2XB3.js";
29
+ import "./chunk-Y5E2WNWB.js";
30
+ import {
31
+ CliError
32
+ } from "./chunk-F6MLJ3V5.js";
33
+ import {
34
+ __name
35
+ } from "./chunk-ZVVMGPBJ.js";
36
+
37
+ // node_modules/.pnpm/@wirecat+cli-core@0.663.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_8be6aa3a41727a76ce87cf0d5a7bd659/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,193 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ botInstructions
5
+ } from "./chunk-35K5T6WV.js";
6
+ import {
7
+ answered,
8
+ normal,
9
+ registerCommands,
10
+ runCommandForAgent,
11
+ toolsFromCommands
12
+ } from "./chunk-EU5WCOMQ.js";
13
+ import {
14
+ agentJson,
15
+ skillResource
16
+ } from "./chunk-R6ZM45NF.js";
17
+ import {
18
+ StdioServerTransport,
19
+ answeredWire,
20
+ callerOf,
21
+ serveStdio
22
+ } from "./chunk-RDZ7SVBZ.js";
23
+ import {
24
+ McpServer
25
+ } from "./chunk-5D4AEUVA.js";
26
+ import {
27
+ wholeList
28
+ } from "./chunk-IQWEJEB5.js";
29
+ import "./chunk-JK44XO2S.js";
30
+ import "./chunk-RAZKIHGH.js";
31
+ import "./chunk-XL2HXHP3.js";
32
+ import {
33
+ MESSENGER_CHANGE_REFUSAL,
34
+ changesMessenger,
35
+ flatten,
36
+ itemOf,
37
+ readOnlyLockOf,
38
+ readOnlyRefusal
39
+ } from "./chunk-UWIA2G6Q.js";
40
+ import "./chunk-7FII4DCE.js";
41
+ import "./chunk-XC5CKHX2.js";
42
+ import "./chunk-ESZT4WW3.js";
43
+ import "./chunk-GA3URWIF.js";
44
+ import "./chunk-24FAYAML.js";
45
+ import "./chunk-47R43UVJ.js";
46
+ import "./chunk-UWW24JQF.js";
47
+ import "./chunk-YA4LSSDZ.js";
48
+ import "./chunk-NLDYZBTC.js";
49
+ import "./chunk-7N5QB6NL.js";
50
+ import "./chunk-3D3PFXBP.js";
51
+ import "./chunk-CWVAYQXI.js";
52
+ import "./chunk-2YR3RYT4.js";
53
+ import "./chunk-WK3OSDNV.js";
54
+ import "./chunk-FF4DDBCB.js";
55
+ import "./chunk-WVZFXI36.js";
56
+ import "./chunk-66PL7P4C.js";
57
+ import "./chunk-ZI3YTXSF.js";
58
+ import "./chunk-QC3KOJT4.js";
59
+ import "./chunk-D72URWJE.js";
60
+ import "./chunk-HWRKURQH.js";
61
+ import "./chunk-AE2KQ37N.js";
62
+ import "./chunk-QBC23NHD.js";
63
+ import "./chunk-RSIS7BR7.js";
64
+ import {
65
+ mcpErrorResult
66
+ } from "./chunk-WM7663C2.js";
67
+ import {
68
+ object
69
+ } from "./chunk-XYIT2XB3.js";
70
+ import "./chunk-Y5E2WNWB.js";
71
+ import "./chunk-F6MLJ3V5.js";
72
+ import "./chunk-EGTBL3MJ.js";
73
+ import {
74
+ __name
75
+ } from "./chunk-ZVVMGPBJ.js";
76
+
77
+ // node_modules/.pnpm/@wirecat+cli-core@0.663.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_8be6aa3a41727a76ce87cf0d5a7bd659/node_modules/@wirecat/cli-core/dist/mcp/bot/server.js
78
+ import { randomUUID } from "node:crypto";
79
+ 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");
80
+ var createBotServer = /* @__PURE__ */ __name((options) => {
81
+ const { bot, program, settings, env } = options;
82
+ const command = bot.app.command;
83
+ const levels = options.levels ?? (() => settings.permissions);
84
+ const authority = /* @__PURE__ */ __name((path) => options.authority?.(path) === true || path[0] === "config" && (path[1] === "set" || path[1] === "unset"), "authority");
85
+ const catalogue = {
86
+ includeUnavailable: true,
87
+ levels: settings.permissions,
88
+ currentLevels: levels,
89
+ readOnly: readOnlyLockOf(bot.app, env) !== void 0,
90
+ ...options.keyOf ? { keyOf: options.keyOf } : {},
91
+ authority,
92
+ ...options.fetchOnly ? { fetchOnly: options.fetchOnly } : {},
93
+ ...options.fetches ? { fetches: options.fetches } : {},
94
+ offline: true,
95
+ // Another bot's copy is this bot's to read only where `read_other_bots` says so.
96
+ ...settings.readOtherBots ? {} : { omit: ["all_bots", "bots"] }
97
+ };
98
+ const tools = [
99
+ ...toolsFromCommands(program.commands, { ...catalogue, root: ["bot"] }),
100
+ ...toolsFromCommands(program.commands.filter((one) => one.path[0] === "config"), {
101
+ ...catalogue,
102
+ omit: ["bot", "personal", "defaults"]
103
+ })
104
+ ];
105
+ const writes = tools.filter((tool) => tool.writes && tool.availability?.().available !== false).map((tool) => tool.command);
106
+ const skill = options.skill ? skillResource(bot.app, options.skill) : void 0;
107
+ let queue = Promise.resolve();
108
+ const invoke = /* @__PURE__ */ __name((path, input, caller) => {
109
+ const next = queue.then(() => runCommandForAgent(program, path, path[0] === "config" ? { ...input, bot: true } : input, {
110
+ profile: settings.profile,
111
+ readOnly: readOnlyLockOf(bot.app, env) !== void 0,
112
+ env,
113
+ levels,
114
+ ...options.keyOf ? { keyOf: options.keyOf } : {},
115
+ authority,
116
+ ...options.fetches ? { fetches: options.fetches } : {},
117
+ ...caller ? { caller } : {}
118
+ }));
119
+ queue = next.catch(() => void 0);
120
+ return next;
121
+ }, "invoke");
122
+ const build = /* @__PURE__ */ __name(() => {
123
+ const callers = { env, client: /* @__PURE__ */ __name(() => server.server.getClientVersion(), "client"), connectionId: randomUUID() };
124
+ const server = new McpServer({ name: `${command}-bot-${settings.profile}`, version: bot.app.version }, {
125
+ instructions: botInstructions({
126
+ command,
127
+ name: bot.name ?? command,
128
+ profile: settings.profile,
129
+ writes,
130
+ ...skill ? { skill: skill.instruction } : {}
131
+ })
132
+ });
133
+ if (skill) {
134
+ const { uri, name, title, description, mimeType, read } = skill;
135
+ server.registerResource(name, uri, { title, description, mimeType }, read);
136
+ }
137
+ const commands = Object.fromEntries(tools.map((tool) => [
138
+ tool.command,
139
+ {
140
+ title: tool.title,
141
+ description: tool.description,
142
+ writes: tool.writes,
143
+ availability: tool.availability,
144
+ input: tool.input,
145
+ run: /* @__PURE__ */ __name(async (args, ctx) => {
146
+ const caller = callerOf(ctx, `${command}_${tool.command.replaceAll(" ", "_")}`, callers);
147
+ const answer = await invoke(tool.path, args, caller);
148
+ return "error" in answer ? mcpErrorResult(JSON.parse(agentJson(answer.error))) : answered(body(tool.command, answer.result));
149
+ }, "run")
150
+ }
151
+ ]));
152
+ commands.status = {
153
+ title: "This server's bot and profile",
154
+ 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.",
155
+ writes: false,
156
+ input: object({}),
157
+ run: /* @__PURE__ */ __name(async () => {
158
+ const auth = await invoke(["bot", "auth", "show"], {});
159
+ const shown = "error" in auth ? auth.error : auth.result?.item ?? auth.result;
160
+ return answered(itemOf({
161
+ profile: settings.profile,
162
+ kind: "bot",
163
+ auth: shown,
164
+ writes: tools.filter((tool) => tool.writes && tool.availability?.().available !== false).map((tool) => tool.command),
165
+ permissions: levels()
166
+ }));
167
+ }, "run")
168
+ };
169
+ registerCommands(server, `${command}_bot`, commands, void 0, (asked) => {
170
+ const lock = readOnlyLockOf(bot.app, env);
171
+ const one = flatten(program.commands).find((info) => info.path[0] === "bot" && normal(info.path.slice(1).join(" ")) === asked);
172
+ if (lock && one && changesMessenger(one))
173
+ throw readOnlyRefusal(lock, MESSENGER_CHANGE_REFUSAL);
174
+ }, bot.app.messenger);
175
+ return server;
176
+ }, "build");
177
+ return { build, tools, offered: tools.map((tool) => tool.command) };
178
+ }, "createBotServer");
179
+ var serveBotOverStdio = /* @__PURE__ */ __name(async (options, note) => {
180
+ const { build } = createBotServer(options);
181
+ const wire = answeredWire(process.stdin, process.stdout);
182
+ const handle = serveStdio(build, {
183
+ transport: new StdioServerTransport(wire.input, wire.output),
184
+ onerror: /* @__PURE__ */ __name((error) => note(`mcp: ${error.message}`), "onerror")
185
+ });
186
+ await wire.finished();
187
+ wire.release();
188
+ await handle.close();
189
+ }, "serveBotOverStdio");
190
+ export {
191
+ createBotServer,
192
+ serveBotOverStdio
193
+ };
@@ -0,0 +1,62 @@
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-EPAZ7DJB.js";
10
+ import "./chunk-ST2UC7FS.js";
11
+ import "./chunk-KHOVVPLC.js";
12
+ import "./chunk-EU5WCOMQ.js";
13
+ import "./chunk-R6ZM45NF.js";
14
+ import "./chunk-DIM5YWBU.js";
15
+ import "./chunk-RDZ7SVBZ.js";
16
+ import "./chunk-5D4AEUVA.js";
17
+ import "./chunk-RLSFOR2D.js";
18
+ import "./chunk-B2WFKFYL.js";
19
+ import "./chunk-IQWEJEB5.js";
20
+ import "./chunk-JK44XO2S.js";
21
+ import "./chunk-RAZKIHGH.js";
22
+ import "./chunk-B4B65XIO.js";
23
+ import "./chunk-XL2HXHP3.js";
24
+ import "./chunk-JKIN5TOU.js";
25
+ import "./chunk-UWIA2G6Q.js";
26
+ import "./chunk-7FII4DCE.js";
27
+ import "./chunk-XC5CKHX2.js";
28
+ import "./chunk-ESZT4WW3.js";
29
+ import "./chunk-GA3URWIF.js";
30
+ import "./chunk-24FAYAML.js";
31
+ import "./chunk-47R43UVJ.js";
32
+ import "./chunk-UWW24JQF.js";
33
+ import "./chunk-YA4LSSDZ.js";
34
+ import "./chunk-NLDYZBTC.js";
35
+ import "./chunk-7N5QB6NL.js";
36
+ import "./chunk-3D3PFXBP.js";
37
+ import "./chunk-CWVAYQXI.js";
38
+ import "./chunk-2YR3RYT4.js";
39
+ import "./chunk-WK3OSDNV.js";
40
+ import "./chunk-FF4DDBCB.js";
41
+ import "./chunk-WVZFXI36.js";
42
+ import "./chunk-66PL7P4C.js";
43
+ import "./chunk-ZI3YTXSF.js";
44
+ import "./chunk-QC3KOJT4.js";
45
+ import "./chunk-D72URWJE.js";
46
+ import "./chunk-HWRKURQH.js";
47
+ import "./chunk-AE2KQ37N.js";
48
+ import "./chunk-QBC23NHD.js";
49
+ import "./chunk-RSIS7BR7.js";
50
+ import "./chunk-WM7663C2.js";
51
+ import "./chunk-XYIT2XB3.js";
52
+ import "./chunk-Y5E2WNWB.js";
53
+ import "./chunk-F6MLJ3V5.js";
54
+ import "./chunk-EGTBL3MJ.js";
55
+ import "./chunk-ZVVMGPBJ.js";
56
+ export {
57
+ PER_RUN,
58
+ createServer,
59
+ envelope,
60
+ serveOverHttpUntilStopped,
61
+ serveOverStdio
62
+ };
@@ -0,0 +1,20 @@
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-TSCIIXN3.js";
8
+ import "./chunk-AE2KQ37N.js";
9
+ import "./chunk-QBC23NHD.js";
10
+ import "./chunk-RSIS7BR7.js";
11
+ import "./chunk-WM7663C2.js";
12
+ import "./chunk-XYIT2XB3.js";
13
+ import "./chunk-Y5E2WNWB.js";
14
+ import "./chunk-F6MLJ3V5.js";
15
+ import "./chunk-ZVVMGPBJ.js";
16
+ export {
17
+ ensureSqlite,
18
+ nodeRuntime,
19
+ relay
20
+ };
@@ -0,0 +1,36 @@
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-RLSFOR2D.js";
16
+ import "./chunk-B4B65XIO.js";
17
+ import "./chunk-XC5CKHX2.js";
18
+ import "./chunk-RSIS7BR7.js";
19
+ import "./chunk-WM7663C2.js";
20
+ import "./chunk-XYIT2XB3.js";
21
+ import "./chunk-Y5E2WNWB.js";
22
+ import "./chunk-F6MLJ3V5.js";
23
+ import "./chunk-ZVVMGPBJ.js";
24
+ export {
25
+ ACCESS_SECONDS,
26
+ REFRESH_SECONDS,
27
+ httpLaunchFile,
28
+ httpLock,
29
+ httpLockFile,
30
+ httpLogFile,
31
+ mcpHttpMarker,
32
+ readHttpLaunch,
33
+ readHttpLock,
34
+ readStored,
35
+ signedInClients
36
+ };
@@ -0,0 +1,164 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ AGENDA_COLUMNS,
5
+ BACKFILL_ON_OPEN,
6
+ BUSINESS_FIND_MAX,
7
+ CHAT_COLUMNS,
8
+ CHAT_LIST_KEY,
9
+ CONVERSATION_COLUMNS,
10
+ DEFAULT_AGENT_CLOSE,
11
+ DEFAULT_FIRST_PASS_PER_CHAT,
12
+ DEFAULT_OWNER_LANGUAGES,
13
+ ENRICHMENT_SUBJECTS,
14
+ MAIL_AGENDA_COLUMNS,
15
+ MENTION_QUERY,
16
+ MENTION_STATUSES,
17
+ OTHER_SOURCES,
18
+ THREAD_COLUMNS,
19
+ TRACKED_CHAT_COLUMNS,
20
+ accountGroupsOf,
21
+ attachmentColumns,
22
+ crmSettingsOf,
23
+ drainNoteIndex,
24
+ dropAllUnusedVectors,
25
+ fetchedKey,
26
+ fileFacts,
27
+ fillSearchIndex,
28
+ fillStems,
29
+ firstPassPerChatOf,
30
+ foldedWords,
31
+ historyStartKey,
32
+ inboxKey,
33
+ involvementStoreOver,
34
+ mergeId,
35
+ messageOfEmail,
36
+ noteIndexState,
37
+ openSqlite,
38
+ openStore,
39
+ orphanPointers,
40
+ ownerLanguages,
41
+ parseCrmSetting,
42
+ parseCrmSettingValue,
43
+ parseMergeId,
44
+ parseOwnerLanguages,
45
+ pendingNormalization,
46
+ queryFilter,
47
+ readStoreTables,
48
+ registerProvider,
49
+ resetAttachmentWords,
50
+ resetNoteIndex,
51
+ resetSearchIndex,
52
+ resetStems,
53
+ rollBack,
54
+ rowCounts,
55
+ saveCrmSetting,
56
+ saveOwnerLanguages,
57
+ saveStorePhoneCountries,
58
+ savedAgentClose,
59
+ savedFirstPassPerChat,
60
+ savedOwnerLanguages,
61
+ savedPhoneCountries,
62
+ savedStemmers,
63
+ savedTaskCategories,
64
+ searchIndexState,
65
+ stemmerCache,
66
+ stemmersOrigin,
67
+ stemsState,
68
+ storeClients,
69
+ storeContents,
70
+ storedTemplateBodies,
71
+ threadConversation,
72
+ titlePart,
73
+ vectorIndexCounts
74
+ } from "./chunk-YA4LSSDZ.js";
75
+ import {
76
+ BUSINESS_KINDS
77
+ } from "./chunk-NLDYZBTC.js";
78
+ import "./chunk-7N5QB6NL.js";
79
+ import "./chunk-3D3PFXBP.js";
80
+ import "./chunk-WK3OSDNV.js";
81
+ import "./chunk-ZI3YTXSF.js";
82
+ import "./chunk-HWRKURQH.js";
83
+ import "./chunk-AE2KQ37N.js";
84
+ import "./chunk-QBC23NHD.js";
85
+ import "./chunk-RSIS7BR7.js";
86
+ import "./chunk-WM7663C2.js";
87
+ import "./chunk-XYIT2XB3.js";
88
+ import "./chunk-Y5E2WNWB.js";
89
+ import "./chunk-F6MLJ3V5.js";
90
+ import "./chunk-EGTBL3MJ.js";
91
+ import "./chunk-ZVVMGPBJ.js";
92
+ export {
93
+ AGENDA_COLUMNS,
94
+ BACKFILL_ON_OPEN,
95
+ BUSINESS_FIND_MAX,
96
+ BUSINESS_KINDS,
97
+ CHAT_COLUMNS,
98
+ CHAT_LIST_KEY,
99
+ CONVERSATION_COLUMNS,
100
+ DEFAULT_AGENT_CLOSE,
101
+ DEFAULT_FIRST_PASS_PER_CHAT,
102
+ DEFAULT_OWNER_LANGUAGES,
103
+ ENRICHMENT_SUBJECTS,
104
+ MAIL_AGENDA_COLUMNS,
105
+ MENTION_QUERY,
106
+ MENTION_STATUSES,
107
+ OTHER_SOURCES,
108
+ THREAD_COLUMNS,
109
+ TRACKED_CHAT_COLUMNS,
110
+ accountGroupsOf,
111
+ attachmentColumns,
112
+ crmSettingsOf,
113
+ drainNoteIndex,
114
+ dropAllUnusedVectors,
115
+ fetchedKey,
116
+ fileFacts,
117
+ fillSearchIndex,
118
+ fillStems,
119
+ firstPassPerChatOf,
120
+ foldedWords,
121
+ historyStartKey,
122
+ inboxKey,
123
+ involvementStoreOver,
124
+ mergeId,
125
+ messageOfEmail,
126
+ noteIndexState,
127
+ openSqlite,
128
+ openStore,
129
+ orphanPointers,
130
+ ownerLanguages,
131
+ parseCrmSetting,
132
+ parseCrmSettingValue,
133
+ parseMergeId,
134
+ parseOwnerLanguages,
135
+ pendingNormalization,
136
+ queryFilter,
137
+ readStoreTables,
138
+ registerProvider,
139
+ resetAttachmentWords,
140
+ resetNoteIndex,
141
+ resetSearchIndex,
142
+ resetStems,
143
+ rollBack,
144
+ rowCounts,
145
+ saveCrmSetting,
146
+ saveOwnerLanguages,
147
+ saveStorePhoneCountries,
148
+ savedAgentClose,
149
+ savedFirstPassPerChat,
150
+ savedOwnerLanguages,
151
+ savedPhoneCountries,
152
+ savedStemmers,
153
+ savedTaskCategories,
154
+ searchIndexState,
155
+ stemmerCache,
156
+ stemmersOrigin,
157
+ stemsState,
158
+ storeClients,
159
+ storeContents,
160
+ storedTemplateBodies,
161
+ threadConversation,
162
+ titlePart,
163
+ vectorIndexCounts
164
+ };