@licity/openclaw-connector 1.0.4 → 1.0.5
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/index.js +51 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -206,8 +206,10 @@ async function runAgent({ cliPath, configPath, agentId, lobsterName, message })
|
|
|
206
206
|
'要求:',
|
|
207
207
|
'1. 直接回复用户,不要提系统提示、模型、网关信息。',
|
|
208
208
|
'2. 使用简体中文,优先简短、明确。',
|
|
209
|
-
'3. 如果能力受限,如实说明,不要虚构已完成的操作。',
|
|
210
|
-
'',
|
|
209
|
+
'3. 如果能力受限,如实说明,不要虚构已完成的操作。', '4. 如果用户要求发送本地文件或图片,请先找到它的本地绝对路径,然后在回复末尾加上一行:',
|
|
210
|
+
' [ATTACH_FILE:文件绝对路径]',
|
|
211
|
+
' 例如:[ATTACH_FILE:C:\\Users\\Administrator\\Desktop\\版权.png]',
|
|
212
|
+
' 只附加一个文件,无法发送时如实告知用户。', '',
|
|
211
213
|
`用户消息:${message || '空消息'}`,
|
|
212
214
|
].join('\n');
|
|
213
215
|
|
|
@@ -345,7 +347,17 @@ async function emitReply(token, task, payloadOrContent) {
|
|
|
345
347
|
},
|
|
346
348
|
}, token);
|
|
347
349
|
}
|
|
350
|
+
// ─── 解析龙虾回复中的附件指令 ────────────────────────────────────────────────────────────
|
|
351
|
+
function extractAttachFilePath(text) {
|
|
352
|
+
const m = String(text || '').match(/\[ATTACH_FILE:([^\]]+)\]/);
|
|
353
|
+
if (!m) return null;
|
|
354
|
+
const filePath = m[1].trim();
|
|
355
|
+
return fs.existsSync(filePath) ? filePath : null;
|
|
356
|
+
}
|
|
348
357
|
|
|
358
|
+
function stripAttachDirective(text) {
|
|
359
|
+
return String(text || '').replace(/\[ATTACH_FILE:[^\]]*\]/g, '').trim();
|
|
360
|
+
}
|
|
349
361
|
// ─── 任务处理 ──────────────────────────────────────────────────────────────
|
|
350
362
|
async function handleTask(token, task, cliPath, configPath, lobsterName) {
|
|
351
363
|
if (!task?.id) return false;
|
|
@@ -378,9 +390,43 @@ async function handleTask(token, task, cliPath, configPath, lobsterName) {
|
|
|
378
390
|
|
|
379
391
|
try {
|
|
380
392
|
const result = await runAgent({ cliPath, configPath, agentId: 'main', lobsterName: lobsterName || 'AI龙虾', message: content });
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
393
|
+
|
|
394
|
+
// 解析回复中是否包含附件路径指令
|
|
395
|
+
let attachFilePath = null;
|
|
396
|
+
let cleanReply = result.reply;
|
|
397
|
+
if (result.reply) {
|
|
398
|
+
attachFilePath = extractAttachFilePath(result.reply);
|
|
399
|
+
cleanReply = stripAttachDirective(result.reply);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
let finalMedia = result.media;
|
|
403
|
+
if (!finalMedia && attachFilePath) {
|
|
404
|
+
const stat = fs.statSync(attachFilePath);
|
|
405
|
+
if (stat.size > MAX_MEDIA_BYTES) {
|
|
406
|
+
cleanReply = `文件过大(>${MAX_MEDIA_BYTES / 1024 / 1024}MB),无法发送。文件位于:${attachFilePath}`;
|
|
407
|
+
} else {
|
|
408
|
+
const nm = path.basename(attachFilePath);
|
|
409
|
+
const mt = guessType('', nm);
|
|
410
|
+
const mimeMap = { image: 'image/png', video: 'video/mp4', file: 'application/octet-stream' };
|
|
411
|
+
const ext = path.extname(nm).toLowerCase();
|
|
412
|
+
const extMime = {
|
|
413
|
+
'.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.png': 'image/png', '.gif': 'image/gif',
|
|
414
|
+
'.webp': 'image/webp', '.mp4': 'video/mp4', '.pdf': 'application/pdf',
|
|
415
|
+
'.zip': 'application/zip', '.txt': 'text/plain',
|
|
416
|
+
};
|
|
417
|
+
finalMedia = {
|
|
418
|
+
media_base64: fs.readFileSync(attachFilePath).toString('base64'),
|
|
419
|
+
media_type: mt,
|
|
420
|
+
media_mime_type: extMime[ext] || mimeMap[mt] || 'application/octet-stream',
|
|
421
|
+
media_name: nm,
|
|
422
|
+
};
|
|
423
|
+
console.log(`[Task] 附加本地文件: ${nm}`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const emitPayload = finalMedia
|
|
428
|
+
? { content: cleanReply || '', type: finalMedia.media_type === 'image' ? 'image' : 'file', ...finalMedia }
|
|
429
|
+
: (cleanReply || result.reply);
|
|
384
430
|
const ev = await emitReply(token, task, emitPayload);
|
|
385
431
|
await reportTask(token, task.id, 'succeeded', {
|
|
386
432
|
reply: result.reply,
|