@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 +1 -1
- package/wecom/src/media-vision.ts +44 -35
- package/wecom/src/wecom-app.ts +8 -0
package/package.json
CHANGED
|
@@ -56,43 +56,52 @@ export async function describeImageWithVision(params: {
|
|
|
56
56
|
return null;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
const
|
|
60
|
-
const
|
|
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
|
-
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
}
|
package/wecom/src/wecom-app.ts
CHANGED
|
@@ -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请根据识别结果回复用户。`;
|