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.
- package/README.md +596 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +99 -0
- package/dist/src/accounts.d.ts +57 -0
- package/dist/src/accounts.js +247 -0
- package/dist/src/agent/api-client.d.ts +95 -0
- package/dist/src/agent/api-client.js +425 -0
- package/dist/src/agent/handler.d.ts +64 -0
- package/dist/src/agent/handler.js +731 -0
- package/dist/src/agent/index.d.ts +5 -0
- package/dist/src/agent/index.js +21 -0
- package/dist/src/agent/webhook.d.ts +25 -0
- package/dist/src/agent/webhook.js +294 -0
- package/dist/src/agent/xml.d.ts +21 -0
- package/dist/src/agent/xml.js +43 -0
- package/dist/src/channel.d.ts +5 -0
- package/dist/src/channel.js +815 -0
- package/dist/src/chat-queue.d.ts +31 -0
- package/dist/src/chat-queue.js +53 -0
- package/dist/src/config-schema.d.ts +587 -0
- package/dist/src/config-schema.js +146 -0
- package/dist/src/const.d.ts +128 -0
- package/dist/src/const.js +168 -0
- package/dist/src/dm-policy.d.ts +29 -0
- package/dist/src/dm-policy.js +146 -0
- package/dist/src/dynamic-agent.d.ts +37 -0
- package/dist/src/dynamic-agent.js +67 -0
- package/dist/src/dynamic-routing.d.ts +65 -0
- package/dist/src/dynamic-routing.js +62 -0
- package/dist/src/endpoint-dispatch.d.ts +54 -0
- package/dist/src/endpoint-dispatch.js +967 -0
- package/dist/src/endpoint-event-adapter.d.ts +15 -0
- package/dist/src/endpoint-event-adapter.js +427 -0
- package/dist/src/group-policy.d.ts +30 -0
- package/dist/src/group-policy.js +126 -0
- package/dist/src/http.d.ts +27 -0
- package/dist/src/http.js +168 -0
- package/dist/src/im-runtime-telemetry.d.ts +25 -0
- package/dist/src/im-runtime-telemetry.js +68 -0
- package/dist/src/interface.d.ts +192 -0
- package/dist/src/interface.js +5 -0
- package/dist/src/markdown-chunk.d.ts +1 -0
- package/dist/src/markdown-chunk.js +396 -0
- package/dist/src/mcp/index.d.ts +6 -0
- package/dist/src/mcp/index.js +28 -0
- package/dist/src/mcp/interceptors/biz-error.d.ts +11 -0
- package/dist/src/mcp/interceptors/biz-error.js +73 -0
- package/dist/src/mcp/interceptors/doc-auth-error.d.ts +10 -0
- package/dist/src/mcp/interceptors/doc-auth-error.js +235 -0
- package/dist/src/mcp/interceptors/index.d.ts +35 -0
- package/dist/src/mcp/interceptors/index.js +143 -0
- package/dist/src/mcp/interceptors/msg-media.d.ts +11 -0
- package/dist/src/mcp/interceptors/msg-media.js +201 -0
- package/dist/src/mcp/interceptors/smartpage-create.d.ts +30 -0
- package/dist/src/mcp/interceptors/smartpage-create.js +252 -0
- package/dist/src/mcp/interceptors/smartpage-export.d.ts +17 -0
- package/dist/src/mcp/interceptors/smartpage-export.js +135 -0
- package/dist/src/mcp/interceptors/smartsheet-upload.d.ts +22 -0
- package/dist/src/mcp/interceptors/smartsheet-upload.js +388 -0
- package/dist/src/mcp/interceptors/types.d.ts +64 -0
- package/dist/src/mcp/interceptors/types.js +8 -0
- package/dist/src/mcp/schema.d.ts +11 -0
- package/dist/src/mcp/schema.js +115 -0
- package/dist/src/mcp/tool.d.ts +63 -0
- package/dist/src/mcp/tool.js +318 -0
- package/dist/src/mcp/transport.d.ts +94 -0
- package/dist/src/mcp/transport.js +702 -0
- package/dist/src/media-handler.d.ts +55 -0
- package/dist/src/media-handler.js +306 -0
- package/dist/src/media-uploader.d.ts +142 -0
- package/dist/src/media-uploader.js +446 -0
- package/dist/src/message-parser.d.ts +104 -0
- package/dist/src/message-parser.js +232 -0
- package/dist/src/message-sender.d.ts +54 -0
- package/dist/src/message-sender.js +210 -0
- package/dist/src/monitor.d.ts +69 -0
- package/dist/src/monitor.js +1846 -0
- package/dist/src/onboarding.d.ts +8 -0
- package/dist/src/onboarding.js +248 -0
- package/dist/src/openclaw-compat.d.ts +148 -0
- package/dist/src/openclaw-compat.js +839 -0
- package/dist/src/proactive-markdown-send.d.ts +14 -0
- package/dist/src/proactive-markdown-send.js +205 -0
- package/dist/src/reqid-store.d.ts +23 -0
- package/dist/src/reqid-store.js +136 -0
- package/dist/src/runtime.d.ts +2 -0
- package/dist/src/runtime.js +7 -0
- package/dist/src/shared/command-auth.d.ts +23 -0
- package/dist/src/shared/command-auth.js +112 -0
- package/dist/src/shared/xml-parser.d.ts +46 -0
- package/dist/src/shared/xml-parser.js +228 -0
- package/dist/src/state-dir-resolve.d.ts +2 -0
- package/dist/src/state-dir-resolve.js +33 -0
- package/dist/src/state-manager.d.ts +115 -0
- package/dist/src/state-manager.js +413 -0
- package/dist/src/target.d.ts +35 -0
- package/dist/src/target.js +71 -0
- package/dist/src/template-card-manager.d.ts +55 -0
- package/dist/src/template-card-manager.js +316 -0
- package/dist/src/template-card-parser.d.ts +37 -0
- package/dist/src/template-card-parser.js +672 -0
- package/dist/src/timeout.d.ts +20 -0
- package/dist/src/timeout.js +57 -0
- package/dist/src/types/account.d.ts +29 -0
- package/dist/src/types/account.js +5 -0
- package/dist/src/types/config.d.ts +98 -0
- package/dist/src/types/config.js +8 -0
- package/dist/src/types/constants.d.ts +42 -0
- package/dist/src/types/constants.js +45 -0
- package/dist/src/types/index.d.ts +7 -0
- package/dist/src/types/index.js +17 -0
- package/dist/src/types/message.d.ts +238 -0
- package/dist/src/types/message.js +6 -0
- package/dist/src/utils.d.ts +148 -0
- package/dist/src/utils.js +92 -0
- package/dist/src/version.d.ts +2 -0
- package/dist/src/version.js +28 -0
- package/dist/src/webhook/command-auth.d.ts +47 -0
- package/dist/src/webhook/command-auth.js +137 -0
- package/dist/src/webhook/gateway.d.ts +36 -0
- package/dist/src/webhook/gateway.js +297 -0
- package/dist/src/webhook/handler.d.ts +19 -0
- package/dist/src/webhook/handler.js +481 -0
- package/dist/src/webhook/helpers.d.ts +157 -0
- package/dist/src/webhook/helpers.js +936 -0
- package/dist/src/webhook/http.d.ts +27 -0
- package/dist/src/webhook/http.js +168 -0
- package/dist/src/webhook/index.d.ts +11 -0
- package/dist/src/webhook/index.js +43 -0
- package/dist/src/webhook/media.d.ts +30 -0
- package/dist/src/webhook/media.js +152 -0
- package/dist/src/webhook/monitor.d.ts +59 -0
- package/dist/src/webhook/monitor.js +1672 -0
- package/dist/src/webhook/state.d.ts +220 -0
- package/dist/src/webhook/state.js +568 -0
- package/dist/src/webhook/target.d.ts +41 -0
- package/dist/src/webhook/target.js +165 -0
- package/dist/src/webhook/types.d.ts +348 -0
- package/dist/src/webhook/types.js +36 -0
- package/dist/src/webhook/video-frame.d.ts +13 -0
- package/dist/src/webhook/video-frame.js +108 -0
- package/openclaw.plugin.json +19 -0
- package/package.json +96 -0
- package/schema.json +534 -0
- package/scripts/generate-schema.mjs +33 -0
- package/skills/wecom-contact/SKILL.md +162 -0
- package/skills/wecom-doc/SKILL.md +162 -0
- package/skills/wecom-doc/references/create-doc.md +56 -0
- package/skills/wecom-doc/references/edit-doc-content.md +68 -0
- package/skills/wecom-doc/references/get-doc-content.md +88 -0
- package/skills/wecom-doc/references/smartpage-create.md +125 -0
- package/skills/wecom-doc/references/smartpage-export.md +160 -0
- package/skills/wecom-meeting/SKILL.md +441 -0
- package/skills/wecom-meeting/references/example-full.md +30 -0
- package/skills/wecom-meeting/references/example-reminder.md +46 -0
- package/skills/wecom-meeting/references/example-security.md +22 -0
- package/skills/wecom-meeting/references/response-get-meeting-info.md +148 -0
- package/skills/wecom-msg/SKILL.md +157 -0
- package/skills/wecom-msg/references/api-get-messages.md +93 -0
- package/skills/wecom-msg/references/api-get-msg-chat-list.md +58 -0
- package/skills/wecom-msg/references/api-get-msg-media.md +44 -0
- package/skills/wecom-msg/references/api-send-message.md +39 -0
- package/skills/wecom-preflight/SKILL.md +141 -0
- package/skills/wecom-schedule/SKILL.md +161 -0
- package/skills/wecom-schedule/references/api-check-availability.md +56 -0
- package/skills/wecom-schedule/references/api-create-schedule.md +38 -0
- package/skills/wecom-schedule/references/api-get-schedule-detail.md +81 -0
- package/skills/wecom-schedule/references/api-update-schedule.md +32 -0
- package/skills/wecom-schedule/references/ref-reminders.md +24 -0
- package/skills/wecom-send-media/SKILL.md +68 -0
- package/skills/wecom-send-template-card/SKILL.md +157 -0
- package/skills/wecom-send-template-card/references/api-template-card-types.md +358 -0
- package/skills/wecom-smartsheet/SKILL.md +164 -0
- package/skills/wecom-smartsheet/references/smartsheet-cell-value-formats.md +163 -0
- package/skills/wecom-smartsheet/references/smartsheet-field-types.md +44 -0
- package/skills/wecom-smartsheet/references/smartsheet-get-records.md +96 -0
- package/skills/wecom-smartsheet/references/webhook-examples.md +185 -0
- package/skills/wecom-smartsheet/references/webhook-fallback.md +184 -0
- package/skills/wecom-todo/SKILL.md +392 -0
- package/skills/wecom-todo/examples/workflows.md +163 -0
package/dist/src/http.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
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;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.__esModule = true;
|
|
50
|
+
exports.readResponseBodyAsBuffer = exports.wecomFetch = void 0;
|
|
51
|
+
var undici_1 = require("undici");
|
|
52
|
+
var proxyDispatchers = new Map();
|
|
53
|
+
/**
|
|
54
|
+
* **getProxyDispatcher (获取代理 Dispatcher)**
|
|
55
|
+
*
|
|
56
|
+
* 缓存并复用 ProxyAgent,避免重复创建连接池。
|
|
57
|
+
*/
|
|
58
|
+
function getProxyDispatcher(proxyUrl) {
|
|
59
|
+
var existing = proxyDispatchers.get(proxyUrl);
|
|
60
|
+
if (existing)
|
|
61
|
+
return existing;
|
|
62
|
+
var created = new undici_1.ProxyAgent(proxyUrl);
|
|
63
|
+
proxyDispatchers.set(proxyUrl, created);
|
|
64
|
+
return created;
|
|
65
|
+
}
|
|
66
|
+
function mergeAbortSignal(params) {
|
|
67
|
+
var signals = [];
|
|
68
|
+
if (params.signal)
|
|
69
|
+
signals.push(params.signal);
|
|
70
|
+
if (params.timeoutMs && Number.isFinite(params.timeoutMs) && params.timeoutMs > 0) {
|
|
71
|
+
signals.push(AbortSignal.timeout(params.timeoutMs));
|
|
72
|
+
}
|
|
73
|
+
if (!signals.length)
|
|
74
|
+
return undefined;
|
|
75
|
+
if (signals.length === 1)
|
|
76
|
+
return signals[0];
|
|
77
|
+
return AbortSignal.any(signals);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* **wecomFetch (统一 HTTP 请求)**
|
|
81
|
+
*
|
|
82
|
+
* 基于 `undici` 的 fetch 封装,自动处理 ProxyAgent 和 Timeout。
|
|
83
|
+
* 所有对企业微信 API 的调用都应经过此函数。
|
|
84
|
+
*/
|
|
85
|
+
function wecomFetch(input, init, opts) {
|
|
86
|
+
var _a, _b, _c, _d, _e;
|
|
87
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
88
|
+
var proxyUrl, dispatcher, initSignal, signal, headers, nextInit, err_1, cause;
|
|
89
|
+
return __generator(this, function (_f) {
|
|
90
|
+
switch (_f.label) {
|
|
91
|
+
case 0:
|
|
92
|
+
proxyUrl = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.proxyUrl) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "";
|
|
93
|
+
dispatcher = proxyUrl ? getProxyDispatcher(proxyUrl) : undefined;
|
|
94
|
+
initSignal = (_c = init === null || init === void 0 ? void 0 : init.signal) !== null && _c !== void 0 ? _c : undefined;
|
|
95
|
+
signal = mergeAbortSignal({ signal: (_d = opts === null || opts === void 0 ? void 0 : opts.signal) !== null && _d !== void 0 ? _d : initSignal, timeoutMs: opts === null || opts === void 0 ? void 0 : opts.timeoutMs });
|
|
96
|
+
headers = new Headers((_e = init === null || init === void 0 ? void 0 : init.headers) !== null && _e !== void 0 ? _e : {});
|
|
97
|
+
if (!headers.has("User-Agent")) {
|
|
98
|
+
headers.set("User-Agent", "OpenClaw/2.0 (WeCom-Agent)");
|
|
99
|
+
}
|
|
100
|
+
nextInit = __assign(__assign(__assign(__assign({}, (init !== null && init !== void 0 ? init : {})), (signal ? { signal: signal } : {})), (dispatcher ? { dispatcher: dispatcher } : {})), { headers: headers });
|
|
101
|
+
_f.label = 1;
|
|
102
|
+
case 1:
|
|
103
|
+
_f.trys.push([1, 3, , 4]);
|
|
104
|
+
return [4 /*yield*/, undici_1.fetch(input, nextInit)];
|
|
105
|
+
case 2: return [2 /*return*/, _f.sent()];
|
|
106
|
+
case 3:
|
|
107
|
+
err_1 = _f.sent();
|
|
108
|
+
if (err_1 instanceof Error && err_1.name === "TypeError" && err_1.message === "fetch failed") {
|
|
109
|
+
cause = err_1.cause;
|
|
110
|
+
console.error("[wecom-http] fetch failed: " + input + " (proxy: " + (proxyUrl || "none") + ")" + (cause ? " - cause: " + String(cause) : ""));
|
|
111
|
+
}
|
|
112
|
+
throw err_1;
|
|
113
|
+
case 4: return [2 /*return*/];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
exports.wecomFetch = wecomFetch;
|
|
119
|
+
/**
|
|
120
|
+
* **readResponseBodyAsBuffer (读取响应 Body)**
|
|
121
|
+
*
|
|
122
|
+
* 将 Response Body 读取为 Buffer,支持最大字节限制以防止内存溢出。
|
|
123
|
+
* 适用于下载媒体文件等场景。
|
|
124
|
+
*/
|
|
125
|
+
function readResponseBodyAsBuffer(res, maxBytes) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
127
|
+
var limit, chunks, total, reader, _a, done, value, _b;
|
|
128
|
+
return __generator(this, function (_c) {
|
|
129
|
+
switch (_c.label) {
|
|
130
|
+
case 0:
|
|
131
|
+
if (!res.body)
|
|
132
|
+
return [2 /*return*/, Buffer.alloc(0)];
|
|
133
|
+
limit = maxBytes && Number.isFinite(maxBytes) && maxBytes > 0 ? maxBytes : undefined;
|
|
134
|
+
chunks = [];
|
|
135
|
+
total = 0;
|
|
136
|
+
reader = res.body.getReader();
|
|
137
|
+
_c.label = 1;
|
|
138
|
+
case 1:
|
|
139
|
+
if (!true) return [3 /*break*/, 8];
|
|
140
|
+
return [4 /*yield*/, reader.read()];
|
|
141
|
+
case 2:
|
|
142
|
+
_a = _c.sent(), done = _a.done, value = _a.value;
|
|
143
|
+
if (done)
|
|
144
|
+
return [3 /*break*/, 8];
|
|
145
|
+
if (!value)
|
|
146
|
+
return [3 /*break*/, 1];
|
|
147
|
+
total += value.byteLength;
|
|
148
|
+
if (!(limit && total > limit)) return [3 /*break*/, 7];
|
|
149
|
+
_c.label = 3;
|
|
150
|
+
case 3:
|
|
151
|
+
_c.trys.push([3, 5, , 6]);
|
|
152
|
+
return [4 /*yield*/, reader.cancel("body too large")];
|
|
153
|
+
case 4:
|
|
154
|
+
_c.sent();
|
|
155
|
+
return [3 /*break*/, 6];
|
|
156
|
+
case 5:
|
|
157
|
+
_b = _c.sent();
|
|
158
|
+
return [3 /*break*/, 6];
|
|
159
|
+
case 6: throw new Error("response body too large (>" + limit + " bytes)");
|
|
160
|
+
case 7:
|
|
161
|
+
chunks.push(value);
|
|
162
|
+
return [3 /*break*/, 1];
|
|
163
|
+
case 8: return [2 /*return*/, Buffer.concat(chunks.map(function (c) { return Buffer.from(c); }))];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
exports.readResponseBodyAsBuffer = readResponseBodyAsBuffer;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* im-agent-hub 进程内运行态打点(与 bridges/main registerImRuntimeTelemetryGlobals 对齐)。
|
|
3
|
+
*/
|
|
4
|
+
declare type ImRuntimePlatform = "wecom";
|
|
5
|
+
export declare function imRuntimeRecordChannelActivity(platform: ImRuntimePlatform, botAccountId: string, direction: "inbound" | "outbound", atMs?: number): void;
|
|
6
|
+
export declare function imRuntimeSetChannelStatus(params: {
|
|
7
|
+
platform: ImRuntimePlatform;
|
|
8
|
+
botAccountId: string;
|
|
9
|
+
linkStatus?: "connecting" | "connected" | "degraded" | "disconnected" | "error";
|
|
10
|
+
lastError?: string | null;
|
|
11
|
+
lastEvent?: string | null;
|
|
12
|
+
lastEventAt?: number;
|
|
13
|
+
running?: boolean;
|
|
14
|
+
connected?: boolean;
|
|
15
|
+
restartPending?: boolean;
|
|
16
|
+
reconnectCount?: number;
|
|
17
|
+
}): void;
|
|
18
|
+
export declare function imRuntimeRecordTransportDisconnect(params: {
|
|
19
|
+
platform: ImRuntimePlatform;
|
|
20
|
+
botAccountId: string;
|
|
21
|
+
atMs?: number;
|
|
22
|
+
error?: string | null;
|
|
23
|
+
loggedOut?: boolean;
|
|
24
|
+
}): void;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* im-agent-hub 进程内运行态打点(与 bridges/main registerImRuntimeTelemetryGlobals 对齐)。
|
|
4
|
+
*/
|
|
5
|
+
var __assign = (this && this.__assign) || function () {
|
|
6
|
+
__assign = Object.assign || function(t) {
|
|
7
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
8
|
+
s = arguments[i];
|
|
9
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
10
|
+
t[p] = s[p];
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
};
|
|
14
|
+
return __assign.apply(this, arguments);
|
|
15
|
+
};
|
|
16
|
+
exports.__esModule = true;
|
|
17
|
+
exports.imRuntimeRecordTransportDisconnect = exports.imRuntimeSetChannelStatus = exports.imRuntimeRecordChannelActivity = void 0;
|
|
18
|
+
function callGlobal(name, payload) {
|
|
19
|
+
try {
|
|
20
|
+
var fn = globalThis[name];
|
|
21
|
+
if (typeof fn === "function") {
|
|
22
|
+
fn(payload);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (_a) {
|
|
26
|
+
// ignore telemetry failures
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function imRuntimeRecordChannelActivity(platform, botAccountId, direction, atMs) {
|
|
30
|
+
var id = String(botAccountId || "").trim();
|
|
31
|
+
if (!id)
|
|
32
|
+
return;
|
|
33
|
+
callGlobal("__IM_RUNTIME_RECORD_CHANNEL_ACTIVITY__", __assign({ platform: platform, bot_account_id: id, direction: direction }, (atMs != null && Number.isFinite(atMs) ? { at_ms: atMs } : {})));
|
|
34
|
+
}
|
|
35
|
+
exports.imRuntimeRecordChannelActivity = imRuntimeRecordChannelActivity;
|
|
36
|
+
function imRuntimeSetChannelStatus(params) {
|
|
37
|
+
var id = String(params.botAccountId || "").trim();
|
|
38
|
+
if (!id)
|
|
39
|
+
return;
|
|
40
|
+
callGlobal("__IM_RUNTIME_SET_CHANNEL_STATUS__", __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({ platform: params.platform, bot_account_id: id }, (params.linkStatus ? { link_status: params.linkStatus } : {})), (params.lastError !== undefined ? { last_error: params.lastError } : {})), (params.lastEvent ? { last_event: params.lastEvent } : {})), (params.lastEventAt != null && Number.isFinite(params.lastEventAt)
|
|
41
|
+
? { last_event_at: params.lastEventAt, last_heartbeat_at: params.lastEventAt }
|
|
42
|
+
: {})), (typeof params.running === "boolean" ? { running: params.running } : {})), (typeof params.connected === "boolean" ? { connected: params.connected } : {})), (typeof params.restartPending === "boolean"
|
|
43
|
+
? { restart_pending: params.restartPending }
|
|
44
|
+
: {})), (typeof params.reconnectCount === "number"
|
|
45
|
+
? { reconnect_count: params.reconnectCount }
|
|
46
|
+
: {})), { status_source: "event" }));
|
|
47
|
+
}
|
|
48
|
+
exports.imRuntimeSetChannelStatus = imRuntimeSetChannelStatus;
|
|
49
|
+
function imRuntimeRecordTransportDisconnect(params) {
|
|
50
|
+
var _a;
|
|
51
|
+
var id = String(params.botAccountId || "").trim();
|
|
52
|
+
if (!id)
|
|
53
|
+
return;
|
|
54
|
+
imRuntimeSetChannelStatus({
|
|
55
|
+
platform: params.platform,
|
|
56
|
+
botAccountId: id,
|
|
57
|
+
linkStatus: "disconnected",
|
|
58
|
+
lastError: (_a = params.error) !== null && _a !== void 0 ? _a : null,
|
|
59
|
+
lastEvent: params.loggedOut ? "transport_logged_out" : "transport_disconnect",
|
|
60
|
+
lastEventAt: params.atMs,
|
|
61
|
+
running: false,
|
|
62
|
+
connected: false
|
|
63
|
+
});
|
|
64
|
+
callGlobal("__IM_RUNTIME_RECORD_TRANSPORT_DISCONNECT__", __assign(__assign(__assign({ platform: params.platform, bot_account_id: id }, (params.atMs != null && Number.isFinite(params.atMs)
|
|
65
|
+
? { at_ms: params.atMs }
|
|
66
|
+
: {})), (params.error != null ? { error: params.error } : {})), (params.loggedOut === true ? { logged_out: true } : {})));
|
|
67
|
+
}
|
|
68
|
+
exports.imRuntimeRecordTransportDisconnect = imRuntimeRecordTransportDisconnect;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 企业微信渠道类型定义
|
|
3
|
+
*/
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
import type { OpenClawConfig } from "ylib-openclaw/plugin-sdk";
|
|
6
|
+
import type { RuntimeEnv } from "ylib-openclaw/plugin-sdk";
|
|
7
|
+
import type { ResolvedWeComAccount } from "./utils.js";
|
|
8
|
+
import { WeComCommand } from "./const.js";
|
|
9
|
+
/**
|
|
10
|
+
* Monitor 配置选项
|
|
11
|
+
*/
|
|
12
|
+
export declare type WeComMonitorOptions = {
|
|
13
|
+
account: ResolvedWeComAccount;
|
|
14
|
+
config: OpenClawConfig;
|
|
15
|
+
runtime: RuntimeEnv;
|
|
16
|
+
abortSignal?: AbortSignal;
|
|
17
|
+
/** 框架层提供的状态更新回调,用于在致命错误场景中标记 channel 已停止 */
|
|
18
|
+
setStatus?: (next: Record<string, unknown>) => void;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* 消息状态
|
|
22
|
+
*/
|
|
23
|
+
export interface MessageState {
|
|
24
|
+
accumulatedText: string;
|
|
25
|
+
/** 流式回复的 streamId,用于保持同一个流式回复使用相同的 streamId */
|
|
26
|
+
streamId?: string;
|
|
27
|
+
/** 是否已成功发送过媒体文件 */
|
|
28
|
+
hasMedia?: boolean;
|
|
29
|
+
/** 是否有媒体发送失败(权限不足、文件过大等) */
|
|
30
|
+
hasMediaFailed?: boolean;
|
|
31
|
+
/** 媒体发送失败时的纯文本错误摘要(用于替换 thinking 流展示给用户) */
|
|
32
|
+
mediaErrorSummary?: string;
|
|
33
|
+
/** 流式回复是否已过期(errcode 846608,>6分钟),需降级为主动发送 */
|
|
34
|
+
streamExpired?: boolean;
|
|
35
|
+
/** 当前流式回复创建时间,用于本地提前降级,避免企微服务端 846608。 */
|
|
36
|
+
streamStartedAt?: number;
|
|
37
|
+
/** 流式超时降级提示是否已经主动发送,避免重复提醒。 */
|
|
38
|
+
streamExpiryNoticeSent?: boolean;
|
|
39
|
+
/** 是否已成功发送过模板卡片 */
|
|
40
|
+
hasTemplateCard?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** 从文本中提取的模板卡片 */
|
|
43
|
+
export interface ExtractedTemplateCard {
|
|
44
|
+
/** 原始 JSON 对象(已验证 card_type 合法) */
|
|
45
|
+
cardJson: Record<string, unknown>;
|
|
46
|
+
/** card_type 值 */
|
|
47
|
+
cardType: string;
|
|
48
|
+
}
|
|
49
|
+
/** extractTemplateCards 返回值 */
|
|
50
|
+
export interface TemplateCardExtractionResult {
|
|
51
|
+
/** 提取到的合法模板卡片列表 */
|
|
52
|
+
cards: ExtractedTemplateCard[];
|
|
53
|
+
/** 移除卡片代码块后的剩余文本 */
|
|
54
|
+
remainingText: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* WebSocket 请求消息基础格式
|
|
58
|
+
*/
|
|
59
|
+
export interface WeComRequest {
|
|
60
|
+
cmd: string;
|
|
61
|
+
headers: {
|
|
62
|
+
req_id: string;
|
|
63
|
+
};
|
|
64
|
+
body: any;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* WebSocket 响应消息格式
|
|
68
|
+
*/
|
|
69
|
+
export interface WeComResponse {
|
|
70
|
+
headers: {
|
|
71
|
+
req_id: string;
|
|
72
|
+
};
|
|
73
|
+
errcode: number;
|
|
74
|
+
errmsg: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 企业微信认证请求
|
|
78
|
+
*/
|
|
79
|
+
export interface WeComSubscribeRequest extends WeComRequest {
|
|
80
|
+
cmd: WeComCommand.SUBSCRIBE;
|
|
81
|
+
body: {
|
|
82
|
+
secret: string;
|
|
83
|
+
bot_id: string;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 企业微信推送消息格式
|
|
88
|
+
*/
|
|
89
|
+
export interface WeComCallbackMessage {
|
|
90
|
+
cmd: WeComCommand.AIBOT_CALLBACK | "aibot_event_callback";
|
|
91
|
+
headers: {
|
|
92
|
+
req_id: string;
|
|
93
|
+
};
|
|
94
|
+
body: {
|
|
95
|
+
msgid: string;
|
|
96
|
+
aibotid: string;
|
|
97
|
+
chatid?: string;
|
|
98
|
+
chattype: "single" | "group";
|
|
99
|
+
from: {
|
|
100
|
+
userid: string;
|
|
101
|
+
};
|
|
102
|
+
response_url: string;
|
|
103
|
+
msgtype: "text" | "image" | "voice" | "video" | "file" | "stream" | "mixed" | "event";
|
|
104
|
+
text?: {
|
|
105
|
+
content: string;
|
|
106
|
+
};
|
|
107
|
+
image?: {
|
|
108
|
+
/** 图片 URL(通过 URL 方式接收图片时) */
|
|
109
|
+
url?: string;
|
|
110
|
+
/** 图片 base64 数据(直接传输时) */
|
|
111
|
+
base64?: string;
|
|
112
|
+
md5?: string;
|
|
113
|
+
};
|
|
114
|
+
/** 图文混排消息 */
|
|
115
|
+
mixed?: {
|
|
116
|
+
msg_item: Array<{
|
|
117
|
+
msgtype: "text" | "image";
|
|
118
|
+
text?: {
|
|
119
|
+
content: string;
|
|
120
|
+
};
|
|
121
|
+
image?: {
|
|
122
|
+
url?: string;
|
|
123
|
+
base64?: string;
|
|
124
|
+
md5?: string;
|
|
125
|
+
};
|
|
126
|
+
}>;
|
|
127
|
+
};
|
|
128
|
+
quote?: {
|
|
129
|
+
msgtype: string;
|
|
130
|
+
text?: {
|
|
131
|
+
content: string;
|
|
132
|
+
};
|
|
133
|
+
image?: {
|
|
134
|
+
url?: string;
|
|
135
|
+
aeskey?: string;
|
|
136
|
+
};
|
|
137
|
+
file?: {
|
|
138
|
+
url?: string;
|
|
139
|
+
aeskey?: string;
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
stream?: {
|
|
143
|
+
id: string;
|
|
144
|
+
};
|
|
145
|
+
event?: {
|
|
146
|
+
eventtype: string;
|
|
147
|
+
template_card_event?: {
|
|
148
|
+
card_type?: string;
|
|
149
|
+
event_key?: string;
|
|
150
|
+
task_id?: string;
|
|
151
|
+
selected_items?: {
|
|
152
|
+
selected_item?: Array<{
|
|
153
|
+
question_key?: string;
|
|
154
|
+
option_ids?: {
|
|
155
|
+
option_id?: string[];
|
|
156
|
+
};
|
|
157
|
+
}>;
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* 企业微信响应消息格式
|
|
165
|
+
*/
|
|
166
|
+
export interface WeComResponseMessage extends WeComRequest {
|
|
167
|
+
cmd: WeComCommand.AIBOT_RESPONSE;
|
|
168
|
+
body: {
|
|
169
|
+
msgtype: "stream" | "text" | "markdown";
|
|
170
|
+
stream?: {
|
|
171
|
+
id: string;
|
|
172
|
+
finish: boolean;
|
|
173
|
+
content: string;
|
|
174
|
+
msg_item?: Array<{
|
|
175
|
+
msgtype: "image" | "file";
|
|
176
|
+
image?: {
|
|
177
|
+
base64: string;
|
|
178
|
+
md5: string;
|
|
179
|
+
};
|
|
180
|
+
}>;
|
|
181
|
+
feedback?: {
|
|
182
|
+
id: string;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
text?: {
|
|
186
|
+
content: string;
|
|
187
|
+
};
|
|
188
|
+
markdown?: {
|
|
189
|
+
content: string;
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function splitMarkdownIntoSafeChunks(text: string, hardLimitBytes: number): string[];
|