@kyan-du/agent-wechat-openclaw 0.14.1 → 0.14.3
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/dist/index.js +55 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5296,6 +5296,14 @@ var openChatResultSchema = external_exports.object({
|
|
|
5296
5296
|
errorCode: external_exports.string().optional(),
|
|
5297
5297
|
error: external_exports.string().optional()
|
|
5298
5298
|
});
|
|
5299
|
+
var downloadFileParamsSchema = external_exports.object({
|
|
5300
|
+
chatId: external_exports.string().min(1),
|
|
5301
|
+
filename: external_exports.string().min(1).optional(),
|
|
5302
|
+
executionTimeoutMs: external_exports.number().int().positive().optional()
|
|
5303
|
+
});
|
|
5304
|
+
var downloadFileResultSchema = openChatResultSchema.extend({
|
|
5305
|
+
clicked: external_exports.boolean().optional()
|
|
5306
|
+
});
|
|
5299
5307
|
var idempotencyKeySchema = external_exports.string().min(1).max(128).regex(/^[A-Za-z0-9._:-]+$/);
|
|
5300
5308
|
var forwardedMessageNodeSchema = external_exports.lazy(() => external_exports.object({
|
|
5301
5309
|
sender: external_exports.string().optional(),
|
|
@@ -5535,6 +5543,9 @@ var WeChatClient = class {
|
|
|
5535
5543
|
async openChat(chatId, clearUnreads, signal, executionTimeoutMs) {
|
|
5536
5544
|
return this.post(`/api/chats/${encodeURIComponent(chatId)}/open${qs({ clearUnreads, executionTimeoutMs })}`, void 0, signal);
|
|
5537
5545
|
}
|
|
5546
|
+
async downloadFile(chatId, filename, signal, executionTimeoutMs) {
|
|
5547
|
+
return this.post(`/api/chats/${encodeURIComponent(chatId)}/download-file${qs({ filename, executionTimeoutMs })}`, void 0, signal);
|
|
5548
|
+
}
|
|
5538
5549
|
async listGroupMembersPage(groupId, limit, cursor) {
|
|
5539
5550
|
const page = groupMembersPageSchema.parse(await this.get(`/api/groups/${encodeURIComponent(groupId)}/members${qs({ limit, cursor })}`));
|
|
5540
5551
|
if (page.errorCode)
|
|
@@ -6789,27 +6800,55 @@ var RETRYABLE_MEDIA_ERRORS = /* @__PURE__ */ new Set([
|
|
|
6789
6800
|
var DEFAULT_MEDIA_POLL_ATTEMPTS = 6;
|
|
6790
6801
|
var DEFAULT_MEDIA_POLL_INTERVAL_MS = 500;
|
|
6791
6802
|
var IMAGE_MATERIALIZATION_OPEN_CHAT_TIMEOUT_MS = 400;
|
|
6792
|
-
|
|
6803
|
+
var FILE_MATERIALIZATION_CLICK_TIMEOUT_MS = 8e3;
|
|
6804
|
+
function shouldTriggerMediaMaterialization(result) {
|
|
6805
|
+
return result.type === "image" || result.type === "file" || result.type === "pending";
|
|
6806
|
+
}
|
|
6807
|
+
function isFileMaterialization(result) {
|
|
6808
|
+
return result.type === "file" || result.errorCode === "FILE_NOT_DOWNLOADED" || result.errorCode === "FILE_NOT_STABLE";
|
|
6809
|
+
}
|
|
6810
|
+
async function triggerImageOpenChat(client, chatId, timeoutMs, result, attempt, options) {
|
|
6811
|
+
options?.log?.info?.(
|
|
6812
|
+
`[wechat:media] triggering chat reopen for ${result.type} attempt=${attempt} skipOpen=${options?.skipOpen === true}`
|
|
6813
|
+
);
|
|
6814
|
+
const controller = new AbortController();
|
|
6815
|
+
const opened = Promise.resolve(client.openChat(chatId, true, controller.signal, timeoutMs));
|
|
6816
|
+
void opened.catch(() => void 0);
|
|
6817
|
+
try {
|
|
6818
|
+
await raceWithTimeout(opened, timeoutMs);
|
|
6819
|
+
} finally {
|
|
6820
|
+
controller.abort();
|
|
6821
|
+
}
|
|
6822
|
+
}
|
|
6823
|
+
function triggerFileBubbleClick(client, chatId, result, attempt, options) {
|
|
6824
|
+
const filename = result.filename?.trim() || void 0;
|
|
6825
|
+
const timeoutMs = options?.timeoutMs ?? FILE_MATERIALIZATION_CLICK_TIMEOUT_MS;
|
|
6826
|
+
options?.log?.info?.(
|
|
6827
|
+
`[wechat:media] triggering file bubble click attempt=${attempt} filename=${filename ?? ""} skipOpen=${options?.skipOpen === true}`
|
|
6828
|
+
);
|
|
6829
|
+
if (!client.downloadFile) {
|
|
6830
|
+
throw Object.assign(new Error("FILE_DOWNLOAD_TRIGGER_UNAVAILABLE"), {
|
|
6831
|
+
code: "FILE_DOWNLOAD_TRIGGER_UNAVAILABLE"
|
|
6832
|
+
});
|
|
6833
|
+
}
|
|
6834
|
+
const clicked = Promise.resolve(client.downloadFile(chatId, filename, void 0, timeoutMs));
|
|
6835
|
+
void clicked.catch(() => void 0);
|
|
6836
|
+
}
|
|
6837
|
+
function createMediaMaterializationTrigger(client, chatId, options) {
|
|
6793
6838
|
const timeoutMs = options?.timeoutMs ?? IMAGE_MATERIALIZATION_OPEN_CHAT_TIMEOUT_MS;
|
|
6794
6839
|
return async (result, attempt) => {
|
|
6795
|
-
if (result
|
|
6796
|
-
|
|
6797
|
-
|
|
6798
|
-
|
|
6799
|
-
const controller = new AbortController();
|
|
6800
|
-
const opened = Promise.resolve(client.openChat(chatId, true, controller.signal, timeoutMs));
|
|
6801
|
-
void opened.catch(() => void 0);
|
|
6802
|
-
try {
|
|
6803
|
-
await raceWithTimeout(opened, timeoutMs);
|
|
6804
|
-
} finally {
|
|
6805
|
-
controller.abort();
|
|
6840
|
+
if (!shouldTriggerMediaMaterialization(result)) return;
|
|
6841
|
+
if (isFileMaterialization(result)) {
|
|
6842
|
+
triggerFileBubbleClick(client, chatId, result, attempt, options);
|
|
6843
|
+
return;
|
|
6806
6844
|
}
|
|
6845
|
+
await triggerImageOpenChat(client, chatId, timeoutMs, result, attempt, options);
|
|
6807
6846
|
};
|
|
6808
6847
|
}
|
|
6809
|
-
function
|
|
6848
|
+
function mediaMaterializationTriggerForMessage(opts) {
|
|
6810
6849
|
const baseType = opts.messageType & 2147483647;
|
|
6811
|
-
if (baseType !== 3) return void 0;
|
|
6812
|
-
return
|
|
6850
|
+
if (baseType !== 3 && baseType !== 49) return void 0;
|
|
6851
|
+
return createMediaMaterializationTrigger(opts.client, opts.chatId, {
|
|
6813
6852
|
log: opts.log,
|
|
6814
6853
|
timeoutMs: opts.timeoutMs,
|
|
6815
6854
|
skipOpen: opts.skipOpen
|
|
@@ -7825,7 +7864,7 @@ async function prepareMessage(client, mediaPipeline, msg, chatId, chat, liveAcco
|
|
|
7825
7864
|
log,
|
|
7826
7865
|
void 0,
|
|
7827
7866
|
void 0,
|
|
7828
|
-
|
|
7867
|
+
mediaMaterializationTriggerForMessage({
|
|
7829
7868
|
client,
|
|
7830
7869
|
chatId,
|
|
7831
7870
|
messageType: baseType,
|