ylib-wecom-openclaw-plugin 2026.4.29

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 (180) hide show
  1. package/README.md +596 -0
  2. package/dist/index.d.ts +10 -0
  3. package/dist/index.js +99 -0
  4. package/dist/src/accounts.d.ts +57 -0
  5. package/dist/src/accounts.js +247 -0
  6. package/dist/src/agent/api-client.d.ts +95 -0
  7. package/dist/src/agent/api-client.js +425 -0
  8. package/dist/src/agent/handler.d.ts +64 -0
  9. package/dist/src/agent/handler.js +731 -0
  10. package/dist/src/agent/index.d.ts +5 -0
  11. package/dist/src/agent/index.js +21 -0
  12. package/dist/src/agent/webhook.d.ts +25 -0
  13. package/dist/src/agent/webhook.js +294 -0
  14. package/dist/src/agent/xml.d.ts +21 -0
  15. package/dist/src/agent/xml.js +43 -0
  16. package/dist/src/channel.d.ts +5 -0
  17. package/dist/src/channel.js +815 -0
  18. package/dist/src/chat-queue.d.ts +31 -0
  19. package/dist/src/chat-queue.js +53 -0
  20. package/dist/src/config-schema.d.ts +587 -0
  21. package/dist/src/config-schema.js +146 -0
  22. package/dist/src/const.d.ts +128 -0
  23. package/dist/src/const.js +168 -0
  24. package/dist/src/dm-policy.d.ts +29 -0
  25. package/dist/src/dm-policy.js +146 -0
  26. package/dist/src/dynamic-agent.d.ts +37 -0
  27. package/dist/src/dynamic-agent.js +67 -0
  28. package/dist/src/dynamic-routing.d.ts +65 -0
  29. package/dist/src/dynamic-routing.js +62 -0
  30. package/dist/src/endpoint-dispatch.d.ts +54 -0
  31. package/dist/src/endpoint-dispatch.js +967 -0
  32. package/dist/src/endpoint-event-adapter.d.ts +15 -0
  33. package/dist/src/endpoint-event-adapter.js +427 -0
  34. package/dist/src/group-policy.d.ts +30 -0
  35. package/dist/src/group-policy.js +126 -0
  36. package/dist/src/http.d.ts +27 -0
  37. package/dist/src/http.js +168 -0
  38. package/dist/src/im-runtime-telemetry.d.ts +25 -0
  39. package/dist/src/im-runtime-telemetry.js +68 -0
  40. package/dist/src/interface.d.ts +192 -0
  41. package/dist/src/interface.js +5 -0
  42. package/dist/src/markdown-chunk.d.ts +1 -0
  43. package/dist/src/markdown-chunk.js +396 -0
  44. package/dist/src/mcp/index.d.ts +6 -0
  45. package/dist/src/mcp/index.js +28 -0
  46. package/dist/src/mcp/interceptors/biz-error.d.ts +11 -0
  47. package/dist/src/mcp/interceptors/biz-error.js +73 -0
  48. package/dist/src/mcp/interceptors/doc-auth-error.d.ts +10 -0
  49. package/dist/src/mcp/interceptors/doc-auth-error.js +235 -0
  50. package/dist/src/mcp/interceptors/index.d.ts +35 -0
  51. package/dist/src/mcp/interceptors/index.js +143 -0
  52. package/dist/src/mcp/interceptors/msg-media.d.ts +11 -0
  53. package/dist/src/mcp/interceptors/msg-media.js +201 -0
  54. package/dist/src/mcp/interceptors/smartpage-create.d.ts +30 -0
  55. package/dist/src/mcp/interceptors/smartpage-create.js +252 -0
  56. package/dist/src/mcp/interceptors/smartpage-export.d.ts +17 -0
  57. package/dist/src/mcp/interceptors/smartpage-export.js +135 -0
  58. package/dist/src/mcp/interceptors/smartsheet-upload.d.ts +22 -0
  59. package/dist/src/mcp/interceptors/smartsheet-upload.js +388 -0
  60. package/dist/src/mcp/interceptors/types.d.ts +64 -0
  61. package/dist/src/mcp/interceptors/types.js +8 -0
  62. package/dist/src/mcp/schema.d.ts +11 -0
  63. package/dist/src/mcp/schema.js +115 -0
  64. package/dist/src/mcp/tool.d.ts +63 -0
  65. package/dist/src/mcp/tool.js +318 -0
  66. package/dist/src/mcp/transport.d.ts +94 -0
  67. package/dist/src/mcp/transport.js +702 -0
  68. package/dist/src/media-handler.d.ts +55 -0
  69. package/dist/src/media-handler.js +306 -0
  70. package/dist/src/media-uploader.d.ts +142 -0
  71. package/dist/src/media-uploader.js +446 -0
  72. package/dist/src/message-parser.d.ts +104 -0
  73. package/dist/src/message-parser.js +232 -0
  74. package/dist/src/message-sender.d.ts +54 -0
  75. package/dist/src/message-sender.js +210 -0
  76. package/dist/src/monitor.d.ts +69 -0
  77. package/dist/src/monitor.js +1846 -0
  78. package/dist/src/onboarding.d.ts +8 -0
  79. package/dist/src/onboarding.js +248 -0
  80. package/dist/src/openclaw-compat.d.ts +148 -0
  81. package/dist/src/openclaw-compat.js +839 -0
  82. package/dist/src/proactive-markdown-send.d.ts +14 -0
  83. package/dist/src/proactive-markdown-send.js +205 -0
  84. package/dist/src/reqid-store.d.ts +23 -0
  85. package/dist/src/reqid-store.js +136 -0
  86. package/dist/src/runtime.d.ts +2 -0
  87. package/dist/src/runtime.js +7 -0
  88. package/dist/src/shared/command-auth.d.ts +23 -0
  89. package/dist/src/shared/command-auth.js +112 -0
  90. package/dist/src/shared/xml-parser.d.ts +46 -0
  91. package/dist/src/shared/xml-parser.js +228 -0
  92. package/dist/src/state-dir-resolve.d.ts +2 -0
  93. package/dist/src/state-dir-resolve.js +33 -0
  94. package/dist/src/state-manager.d.ts +115 -0
  95. package/dist/src/state-manager.js +413 -0
  96. package/dist/src/target.d.ts +35 -0
  97. package/dist/src/target.js +71 -0
  98. package/dist/src/template-card-manager.d.ts +55 -0
  99. package/dist/src/template-card-manager.js +316 -0
  100. package/dist/src/template-card-parser.d.ts +37 -0
  101. package/dist/src/template-card-parser.js +672 -0
  102. package/dist/src/timeout.d.ts +20 -0
  103. package/dist/src/timeout.js +57 -0
  104. package/dist/src/types/account.d.ts +29 -0
  105. package/dist/src/types/account.js +5 -0
  106. package/dist/src/types/config.d.ts +98 -0
  107. package/dist/src/types/config.js +8 -0
  108. package/dist/src/types/constants.d.ts +42 -0
  109. package/dist/src/types/constants.js +45 -0
  110. package/dist/src/types/index.d.ts +7 -0
  111. package/dist/src/types/index.js +17 -0
  112. package/dist/src/types/message.d.ts +238 -0
  113. package/dist/src/types/message.js +6 -0
  114. package/dist/src/utils.d.ts +148 -0
  115. package/dist/src/utils.js +92 -0
  116. package/dist/src/version.d.ts +2 -0
  117. package/dist/src/version.js +28 -0
  118. package/dist/src/webhook/command-auth.d.ts +47 -0
  119. package/dist/src/webhook/command-auth.js +137 -0
  120. package/dist/src/webhook/gateway.d.ts +36 -0
  121. package/dist/src/webhook/gateway.js +297 -0
  122. package/dist/src/webhook/handler.d.ts +19 -0
  123. package/dist/src/webhook/handler.js +481 -0
  124. package/dist/src/webhook/helpers.d.ts +157 -0
  125. package/dist/src/webhook/helpers.js +936 -0
  126. package/dist/src/webhook/http.d.ts +27 -0
  127. package/dist/src/webhook/http.js +168 -0
  128. package/dist/src/webhook/index.d.ts +11 -0
  129. package/dist/src/webhook/index.js +43 -0
  130. package/dist/src/webhook/media.d.ts +30 -0
  131. package/dist/src/webhook/media.js +152 -0
  132. package/dist/src/webhook/monitor.d.ts +59 -0
  133. package/dist/src/webhook/monitor.js +1672 -0
  134. package/dist/src/webhook/state.d.ts +220 -0
  135. package/dist/src/webhook/state.js +568 -0
  136. package/dist/src/webhook/target.d.ts +41 -0
  137. package/dist/src/webhook/target.js +165 -0
  138. package/dist/src/webhook/types.d.ts +348 -0
  139. package/dist/src/webhook/types.js +36 -0
  140. package/dist/src/webhook/video-frame.d.ts +13 -0
  141. package/dist/src/webhook/video-frame.js +108 -0
  142. package/openclaw.plugin.json +19 -0
  143. package/package.json +96 -0
  144. package/schema.json +534 -0
  145. package/scripts/generate-schema.mjs +33 -0
  146. package/skills/wecom-contact/SKILL.md +162 -0
  147. package/skills/wecom-doc/SKILL.md +162 -0
  148. package/skills/wecom-doc/references/create-doc.md +56 -0
  149. package/skills/wecom-doc/references/edit-doc-content.md +68 -0
  150. package/skills/wecom-doc/references/get-doc-content.md +88 -0
  151. package/skills/wecom-doc/references/smartpage-create.md +125 -0
  152. package/skills/wecom-doc/references/smartpage-export.md +160 -0
  153. package/skills/wecom-meeting/SKILL.md +441 -0
  154. package/skills/wecom-meeting/references/example-full.md +30 -0
  155. package/skills/wecom-meeting/references/example-reminder.md +46 -0
  156. package/skills/wecom-meeting/references/example-security.md +22 -0
  157. package/skills/wecom-meeting/references/response-get-meeting-info.md +148 -0
  158. package/skills/wecom-msg/SKILL.md +157 -0
  159. package/skills/wecom-msg/references/api-get-messages.md +93 -0
  160. package/skills/wecom-msg/references/api-get-msg-chat-list.md +58 -0
  161. package/skills/wecom-msg/references/api-get-msg-media.md +44 -0
  162. package/skills/wecom-msg/references/api-send-message.md +39 -0
  163. package/skills/wecom-preflight/SKILL.md +141 -0
  164. package/skills/wecom-schedule/SKILL.md +161 -0
  165. package/skills/wecom-schedule/references/api-check-availability.md +56 -0
  166. package/skills/wecom-schedule/references/api-create-schedule.md +38 -0
  167. package/skills/wecom-schedule/references/api-get-schedule-detail.md +81 -0
  168. package/skills/wecom-schedule/references/api-update-schedule.md +32 -0
  169. package/skills/wecom-schedule/references/ref-reminders.md +24 -0
  170. package/skills/wecom-send-media/SKILL.md +68 -0
  171. package/skills/wecom-send-template-card/SKILL.md +157 -0
  172. package/skills/wecom-send-template-card/references/api-template-card-types.md +358 -0
  173. package/skills/wecom-smartsheet/SKILL.md +164 -0
  174. package/skills/wecom-smartsheet/references/smartsheet-cell-value-formats.md +163 -0
  175. package/skills/wecom-smartsheet/references/smartsheet-field-types.md +44 -0
  176. package/skills/wecom-smartsheet/references/smartsheet-get-records.md +96 -0
  177. package/skills/wecom-smartsheet/references/webhook-examples.md +185 -0
  178. package/skills/wecom-smartsheet/references/webhook-fallback.md +184 -0
  179. package/skills/wecom-todo/SKILL.md +392 -0
  180. package/skills/wecom-todo/examples/workflows.md +163 -0
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+ /**
3
+ * smartpage_create 请求拦截器
4
+ *
5
+ * 核心逻辑:
6
+ * smartpage_create 的 pages 数组中,每个 page 可能包含 page_filepath 字段
7
+ * (指向本地 markdown 文件),用于避免在命令行传递大段文本内容。
8
+ * 本拦截器在 beforeCall 阶段遍历 pages 数组,逐个读取 page_filepath
9
+ * 指向的本地文件内容,填入 page_content 字段,并移除 page_filepath。
10
+ *
11
+ * 入参约定:
12
+ * wecom_mcp call doc smartpage_create '{
13
+ * "title": "主页标题",
14
+ * "pages": [
15
+ * {"page_title": "页面1", "page_filepath": "/tmp/page1.md", "content_type": "markdown"},
16
+ * {"page_title": "页面2", "page_filepath": "/tmp/page2.md", "content_type": "markdown"}
17
+ * ]
18
+ * }'
19
+ *
20
+ * 拦截器行为:
21
+ * 1. 检测 args.pages 数组
22
+ * 2. 校验文件大小:单文件不超过 10MB,所有文件总计不超过 20MB
23
+ * 3. 遍历每个 page,若存在 page_filepath 则读取本地文件内容
24
+ * 4. 将文件内容填入 page_content 字段,移除 page_filepath
25
+ * 5. 返回修改后的完整 args
26
+ *
27
+ * 传给 MCP Server 的格式:
28
+ * { "title": "...", "pages": [{"page_title": "...", "page_content": "...", "content_type": "..."}] }
29
+ */
30
+ var __assign = (this && this.__assign) || function () {
31
+ __assign = Object.assign || function(t) {
32
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
33
+ s = arguments[i];
34
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
35
+ t[p] = s[p];
36
+ }
37
+ return t;
38
+ };
39
+ return __assign.apply(this, arguments);
40
+ };
41
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
42
+ if (k2 === undefined) k2 = k;
43
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
44
+ }) : (function(o, m, k, k2) {
45
+ if (k2 === undefined) k2 = k;
46
+ o[k2] = m[k];
47
+ }));
48
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
49
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
50
+ }) : function(o, v) {
51
+ o["default"] = v;
52
+ });
53
+ var __importStar = (this && this.__importStar) || function (mod) {
54
+ if (mod && mod.__esModule) return mod;
55
+ var result = {};
56
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
57
+ __setModuleDefault(result, mod);
58
+ return result;
59
+ };
60
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
61
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
62
+ return new (P || (P = Promise))(function (resolve, reject) {
63
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
64
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
65
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
66
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
67
+ });
68
+ };
69
+ var __generator = (this && this.__generator) || function (thisArg, body) {
70
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
71
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
72
+ function verb(n) { return function (v) { return step([n, v]); }; }
73
+ function step(op) {
74
+ if (f) throw new TypeError("Generator is already executing.");
75
+ while (_) try {
76
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
77
+ if (y = 0, t) op = [op[0] & 2, t.value];
78
+ switch (op[0]) {
79
+ case 0: case 1: t = op; break;
80
+ case 4: _.label++; return { value: op[1], done: false };
81
+ case 5: _.label++; y = op[1]; op = [0]; continue;
82
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
83
+ default:
84
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
85
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
86
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
87
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
88
+ if (t[2]) _.ops.pop();
89
+ _.trys.pop(); continue;
90
+ }
91
+ op = body.call(thisArg, _);
92
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
93
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
94
+ }
95
+ };
96
+ var __rest = (this && this.__rest) || function (s, e) {
97
+ var t = {};
98
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
99
+ t[p] = s[p];
100
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
101
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
102
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
103
+ t[p[i]] = s[p[i]];
104
+ }
105
+ return t;
106
+ };
107
+ exports.__esModule = true;
108
+ exports.smartpageCreateInterceptor = void 0;
109
+ var fs = __importStar(require("node:fs/promises"));
110
+ // ============================================================================
111
+ // 常量
112
+ // ============================================================================
113
+ /** 单个 page_filepath 文件大小上限:10MB */
114
+ var MAX_SINGLE_FILE_SIZE = 10 * 1024 * 1024;
115
+ /** 所有 page_filepath 文件总大小上限:20MB */
116
+ var MAX_TOTAL_FILE_SIZE = 20 * 1024 * 1024;
117
+ // ============================================================================
118
+ // 内部辅助函数
119
+ // ============================================================================
120
+ /**
121
+ * 校验所有 page_filepath 的文件大小
122
+ *
123
+ * 使用 fs.stat 在读取文件内容之前检查大小,避免超大文件被加载到内存。
124
+ * - 单文件 > 10MB → 报错
125
+ * - 所有文件累计 > 20MB → 报错
126
+ */
127
+ function validateFileSize(pages) {
128
+ return __awaiter(this, void 0, void 0, function () {
129
+ var totalSize, i, filePath, stat, err_1;
130
+ return __generator(this, function (_a) {
131
+ switch (_a.label) {
132
+ case 0:
133
+ totalSize = 0;
134
+ i = 0;
135
+ _a.label = 1;
136
+ case 1:
137
+ if (!(i < pages.length)) return [3 /*break*/, 7];
138
+ filePath = pages[i].page_filepath;
139
+ if (typeof filePath !== "string" || !filePath)
140
+ return [3 /*break*/, 6];
141
+ stat = void 0;
142
+ _a.label = 2;
143
+ case 2:
144
+ _a.trys.push([2, 4, , 5]);
145
+ return [4 /*yield*/, fs.stat(filePath)];
146
+ case 3:
147
+ stat = _a.sent();
148
+ return [3 /*break*/, 5];
149
+ case 4:
150
+ err_1 = _a.sent();
151
+ // stat 失败不在这里处理,留给后续 readFile 阶段抛出更详细的错误
152
+ return [3 /*break*/, 6];
153
+ case 5:
154
+ if (stat.size > MAX_SINGLE_FILE_SIZE) {
155
+ console.error("[mcp] smartpage_create: pages[" + i + "] \u6587\u4EF6 \"" + filePath + "\" " +
156
+ ("\u5927\u5C0F " + (stat.size / 1024 / 1024).toFixed(1) + "MB \u8D85\u8FC7\u5355\u6587\u4EF6\u4E0A\u9650 10MB"));
157
+ throw new Error("内容大小超出限制,无法创建");
158
+ }
159
+ totalSize += stat.size;
160
+ if (totalSize > MAX_TOTAL_FILE_SIZE) {
161
+ console.error("[mcp] smartpage_create: \u7D2F\u8BA1\u6587\u4EF6\u5927\u5C0F " + (totalSize / 1024 / 1024).toFixed(1) + "MB " +
162
+ ("\u8D85\u8FC7\u603B\u4E0A\u9650 20MB\uFF08\u5728 pages[" + i + "] \"" + filePath + "\" \u5904\u8D85\u51FA\uFF09"));
163
+ throw new Error("内容大小超出限制,无法创建");
164
+ }
165
+ _a.label = 6;
166
+ case 6:
167
+ i++;
168
+ return [3 /*break*/, 1];
169
+ case 7:
170
+ if (totalSize > 0) {
171
+ console.log("[mcp] smartpage_create: \u6587\u4EF6\u5927\u5C0F\u6821\u9A8C\u901A\u8FC7\uFF0C\u603B\u8BA1 " + (totalSize / 1024 / 1024).toFixed(2) + "MB");
172
+ }
173
+ return [2 /*return*/];
174
+ }
175
+ });
176
+ });
177
+ }
178
+ /** 异步解析 pages 中的 page_filepath,返回 BeforeCallOptions */
179
+ function resolvePages(ctx, pages) {
180
+ return __awaiter(this, void 0, void 0, function () {
181
+ var resolvedPages;
182
+ var _this = this;
183
+ return __generator(this, function (_a) {
184
+ switch (_a.label) {
185
+ case 0:
186
+ console.log("[mcp] smartpage_create: \u5F00\u59CB\u89E3\u6790 " + pages.length + " \u4E2A page \u7684 page_filepath");
187
+ // 阶段 1:文件大小校验(stat 阶段,不读内容)
188
+ return [4 /*yield*/, validateFileSize(pages)];
189
+ case 1:
190
+ // 阶段 1:文件大小校验(stat 阶段,不读内容)
191
+ _a.sent();
192
+ return [4 /*yield*/, Promise.all(pages.map(function (page, index) { return __awaiter(_this, void 0, void 0, function () {
193
+ var filePath, fileContent, err_2, _, rest;
194
+ return __generator(this, function (_a) {
195
+ switch (_a.label) {
196
+ case 0:
197
+ filePath = page.page_filepath;
198
+ if (typeof filePath !== "string" || !filePath) {
199
+ // 该 page 没有 page_filepath,保留原样(可能已有 page_content)
200
+ return [2 /*return*/, page];
201
+ }
202
+ _a.label = 1;
203
+ case 1:
204
+ _a.trys.push([1, 3, , 4]);
205
+ return [4 /*yield*/, fs.readFile(filePath, "utf-8")];
206
+ case 2:
207
+ fileContent = _a.sent();
208
+ return [3 /*break*/, 4];
209
+ case 3:
210
+ err_2 = _a.sent();
211
+ throw new Error("smartpage_create: pages[" + index + "] \u65E0\u6CD5\u8BFB\u53D6\u6587\u4EF6 \"" + filePath + "\": " + (err_2 instanceof Error ? err_2.message : String(err_2)));
212
+ case 4:
213
+ console.log("[mcp] smartpage_create: pages[" + index + "] \u8BFB\u53D6\u6210\u529F \"" + filePath + "\" (" + fileContent.length + " chars)");
214
+ _ = page.page_filepath, rest = __rest(page, ["page_filepath"]);
215
+ return [2 /*return*/, __assign(__assign({}, rest), { page_content: fileContent })];
216
+ }
217
+ });
218
+ }); }))];
219
+ case 2:
220
+ resolvedPages = _a.sent();
221
+ console.log("[mcp] smartpage_create: \u6240\u6709 page_filepath \u89E3\u6790\u5B8C\u6210");
222
+ // 返回修改后的完整 args
223
+ return [2 /*return*/, {
224
+ args: __assign(__assign({}, ctx.args), { pages: resolvedPages })
225
+ }];
226
+ }
227
+ });
228
+ });
229
+ }
230
+ // ============================================================================
231
+ // 拦截器实现
232
+ // ============================================================================
233
+ exports.smartpageCreateInterceptor = {
234
+ name: "smartpage-create",
235
+ /** 仅对 doc 品类的 smartpage_create 方法生效 */
236
+ match: function (ctx) { return ctx.category === "doc" && ctx.method === "smartpage_create"; },
237
+ /** 遍历 pages 数组,逐个读取 page_filepath 填入 page_content */
238
+ beforeCall: function (ctx) {
239
+ var pages = ctx.args.pages;
240
+ if (!Array.isArray(pages) || pages.length === 0) {
241
+ // 没有 pages 数组,不做拦截
242
+ return undefined;
243
+ }
244
+ // 检查是否有任何 page 包含 page_filepath
245
+ var hasFilePath = pages.some(function (p) { return typeof p.page_filepath === "string" && p.page_filepath; });
246
+ if (!hasFilePath) {
247
+ // 所有 page 都没有 page_filepath(可能直接传了 page_content),不做拦截
248
+ return undefined;
249
+ }
250
+ return resolvePages(ctx, pages);
251
+ }
252
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * smartpage_get_export_result 响应拦截器
3
+ *
4
+ * 核心逻辑:
5
+ * MCP Server 返回的 smartpage_get_export_result 响应中,当 task_done=true 时
6
+ * 会包含 content 字段(markdown 文本内容)。该内容可能很大,直接返回给 LLM
7
+ * 会消耗大量 token。
8
+ *
9
+ * 本拦截器在 afterCall 阶段:
10
+ * 1. 检测 task_done=true 且存在 content 字段
11
+ * 2. 将 content 保存到本地文件(使用与 msg-media 一致的媒体目录)
12
+ * 3. 用 content_path(文件路径)替换 content 字段
13
+ *
14
+ * 这样 LLM 只看到轻量的文件路径信息,Skill 可通过文件路径读取完整内容。
15
+ */
16
+ import type { CallInterceptor } from "./types.js";
17
+ export declare const smartpageExportInterceptor: CallInterceptor;
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ /**
3
+ * smartpage_get_export_result 响应拦截器
4
+ *
5
+ * 核心逻辑:
6
+ * MCP Server 返回的 smartpage_get_export_result 响应中,当 task_done=true 时
7
+ * 会包含 content 字段(markdown 文本内容)。该内容可能很大,直接返回给 LLM
8
+ * 会消耗大量 token。
9
+ *
10
+ * 本拦截器在 afterCall 阶段:
11
+ * 1. 检测 task_done=true 且存在 content 字段
12
+ * 2. 将 content 保存到本地文件(使用与 msg-media 一致的媒体目录)
13
+ * 3. 用 content_path(文件路径)替换 content 字段
14
+ *
15
+ * 这样 LLM 只看到轻量的文件路径信息,Skill 可通过文件路径读取完整内容。
16
+ */
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ exports.__esModule = true;
54
+ exports.smartpageExportInterceptor = void 0;
55
+ var runtime_js_1 = require("../../runtime.js");
56
+ // ============================================================================
57
+ // 拦截器实现
58
+ // ============================================================================
59
+ exports.smartpageExportInterceptor = {
60
+ name: "smartpage-export",
61
+ /** 仅对 doc 品类的 smartpage_get_export_result 方法生效 */
62
+ match: function (ctx) { return ctx.category === "doc" && ctx.method === "smartpage_get_export_result"; },
63
+ /** 拦截响应:将 markdown content 保存为本地文件 */
64
+ afterCall: function (_ctx, result) {
65
+ return __awaiter(this, void 0, void 0, function () {
66
+ return __generator(this, function (_a) {
67
+ return [2 /*return*/, interceptExportResponse(result)];
68
+ });
69
+ });
70
+ }
71
+ };
72
+ // ============================================================================
73
+ // 内部实现
74
+ // ============================================================================
75
+ /**
76
+ * 拦截 smartpage_get_export_result 的 MCP 响应
77
+ *
78
+ * 1. 从 MCP result 的 content[].text 中提取业务 JSON
79
+ * 2. 检测 task_done=true 且存在 content 字段
80
+ * 3. 将 content(markdown 文本)通过 saveMediaBuffer 保存到本地媒体目录
81
+ * 4. 构造新响应:移除 content,添加 content_path
82
+ */
83
+ function interceptExportResponse(result) {
84
+ var _a, _b;
85
+ return __awaiter(this, void 0, void 0, function () {
86
+ var content, textItem, bizData, markdownContent, buffer, core, saved, newBizData;
87
+ return __generator(this, function (_c) {
88
+ switch (_c.label) {
89
+ case 0:
90
+ content = (_a = result) === null || _a === void 0 ? void 0 : _a.content;
91
+ if (!Array.isArray(content))
92
+ return [2 /*return*/, result];
93
+ textItem = content.find(function (c) { return c.type === "text" && typeof c.text === "string"; });
94
+ if (!textItem)
95
+ return [2 /*return*/, result];
96
+ try {
97
+ bizData = JSON.parse(textItem.text);
98
+ }
99
+ catch (_d) {
100
+ // 非 JSON 格式,原样返回
101
+ return [2 /*return*/, result];
102
+ }
103
+ // 3. 校验:errcode !== 0 或 task_done 不为 true 或无 content 时原样返回
104
+ if (bizData.errcode !== 0)
105
+ return [2 /*return*/, result];
106
+ if (bizData.task_done !== true)
107
+ return [2 /*return*/, result];
108
+ if (typeof bizData.content !== "string")
109
+ return [2 /*return*/, result];
110
+ markdownContent = bizData.content;
111
+ console.log("[mcp] smartpage_get_export_result: \u62E6\u622A content (" + markdownContent.length + " chars)\uFF0C\u4FDD\u5B58\u5230\u672C\u5730\u6587\u4EF6");
112
+ buffer = Buffer.from(markdownContent, "utf-8");
113
+ core = runtime_js_1.getWeComRuntime();
114
+ return [4 /*yield*/, core.channel.media.saveMediaBuffer(buffer, "text/markdown", "inbound", undefined, // maxBytes: markdown 文本通常不大,使用默认限制
115
+ "smartpage_export.md")];
116
+ case 1:
117
+ saved = _c.sent();
118
+ console.log("[mcp] smartpage_get_export_result: \u5DF2\u4FDD\u5B58\u5230 " + saved.path);
119
+ newBizData = {
120
+ errcode: bizData.errcode,
121
+ errmsg: (_b = bizData.errmsg) !== null && _b !== void 0 ? _b : "ok",
122
+ task_done: true,
123
+ content_path: saved.path
124
+ };
125
+ // 6. 返回修改后的 MCP result 结构
126
+ return [2 /*return*/, {
127
+ content: [{
128
+ type: "text",
129
+ text: JSON.stringify(newBizData)
130
+ }]
131
+ }];
132
+ }
133
+ });
134
+ });
135
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * smartsheet_add_records / smartsheet_update_records 本地文件上传拦截器
3
+ *
4
+ * 核心逻辑:
5
+ * 大模型在调用 smartsheet_add_records / smartsheet_update_records 时,
6
+ * 可在 CellImageValue 中传入 image_path(本地图片路径)代替 image_url/title,
7
+ * 或在 CellAttachmentValue 中传入 file_path(本地文件路径)代替 file_id。
8
+ *
9
+ * 本拦截器在 beforeCall 阶段:
10
+ * 1. 深度扫描 records[].values 中的所有字段值,收集含 image_path / file_path 的单元格
11
+ * 2. 校验文件大小:单文件不超过 10MB,所有文件总计不超过 20MB
12
+ * 3. 并行读取本地文件 → base64 编码 → 调用 MCP 上传接口
13
+ * - image_path → upload_doc_image → 获取 image_url
14
+ * - file_path → upload_doc_file → 获取 file_id
15
+ * 4. 用上传结果替换原字段,移除 image_path / file_path
16
+ * 5. 返回修改后的完整 args
17
+ *
18
+ * 传给 MCP Server 的始终是标准协议格式(image_url / file_id),
19
+ * MCP Server 不需要感知 image_path / file_path 的存在。
20
+ */
21
+ import type { CallInterceptor } from "./types.js";
22
+ export declare const smartsheetUploadInterceptor: CallInterceptor;