@marshulll/openclaw-wecom 0.1.21 → 0.1.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marshulll/openclaw-wecom",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "type": "module",
5
5
  "description": "OpenClaw WeCom channel plugin (intelligent bot + internal app)",
6
6
  "author": "OpenClaw",
@@ -56,43 +56,52 @@ export async function describeImageWithVision(params: {
56
56
  return null;
57
57
  }
58
58
 
59
- const controller = new AbortController();
60
- const timeout = setTimeout(() => controller.abort(), config.timeoutMs ?? 15000);
59
+ const imageBase64 = buffer.toString("base64");
60
+ const payload = {
61
+ model: config.model,
62
+ messages: [
63
+ {
64
+ role: "user",
65
+ content: [
66
+ { type: "text", text: config.prompt },
67
+ { type: "image_url", image_url: { url: `data:${mimeType};base64,${imageBase64}` } },
68
+ ],
69
+ },
70
+ ],
71
+ max_tokens: config.maxTokens ?? 400,
72
+ };
61
73
 
62
- try {
63
- const imageBase64 = buffer.toString("base64");
64
- const payload = {
65
- model: config.model,
66
- messages: [
67
- {
68
- role: "user",
69
- content: [
70
- { type: "text", text: config.prompt },
71
- { type: "image_url", image_url: { url: `data:${mimeType};base64,${imageBase64}` } },
72
- ],
74
+ for (let attempt = 0; attempt < 2; attempt += 1) {
75
+ const controller = new AbortController();
76
+ const timeout = setTimeout(() => controller.abort(), config.timeoutMs ?? 15000);
77
+ try {
78
+ const res = await fetch(`${config.baseUrl}/chat/completions`, {
79
+ method: "POST",
80
+ headers: {
81
+ "Content-Type": "application/json",
82
+ Authorization: `Bearer ${config.apiKey}`,
73
83
  },
74
- ],
75
- max_tokens: config.maxTokens ?? 400,
76
- };
77
-
78
- const res = await fetch(`${config.baseUrl}/chat/completions`, {
79
- method: "POST",
80
- headers: {
81
- "Content-Type": "application/json",
82
- Authorization: `Bearer ${config.apiKey}`,
83
- },
84
- body: JSON.stringify(payload),
85
- signal: controller.signal,
86
- });
84
+ body: JSON.stringify(payload),
85
+ signal: controller.signal,
86
+ });
87
87
 
88
- if (!res.ok) return null;
89
- const data = await res.json() as any;
90
- const content = data?.choices?.[0]?.message?.content;
91
- if (typeof content !== "string") return null;
92
- return content.trim() || null;
93
- } catch {
94
- return null;
95
- } finally {
96
- clearTimeout(timeout);
88
+ if (!res.ok) {
89
+ continue;
90
+ }
91
+ const data = await res.json() as any;
92
+ const content = data?.choices?.[0]?.message?.content;
93
+ if (typeof content !== "string") {
94
+ continue;
95
+ }
96
+ const trimmed = content.trim();
97
+ if (!trimmed) continue;
98
+ return trimmed;
99
+ } catch {
100
+ // retry once
101
+ } finally {
102
+ clearTimeout(timeout);
103
+ }
97
104
  }
105
+
106
+ return null;
98
107
  }
@@ -695,6 +695,14 @@ async function processAppMessage(params: {
695
695
  createdAt: Date.now(),
696
696
  size: buffer.length,
697
697
  });
698
+ if (visionConfig && !summary) {
699
+ await appendOperationLog(target, {
700
+ action: "vision-image-failed",
701
+ accountId: target.account.accountId,
702
+ path: tempImagePath,
703
+ size: buffer.length,
704
+ });
705
+ }
698
706
  logVerbose(target, `app image saved (${buffer.length} bytes): ${tempImagePath}`);
699
707
  if (summary) {
700
708
  messageText = `[用户发送了一张图片]\n\n[图片识别结果]\n${summary}\n\n请根据识别结果回复用户。`;