@alfe.ai/openclaw-chat 0.0.18 → 0.0.19
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/plugin2.cjs +39 -7
- package/dist/plugin2.js +39 -7
- package/openclaw.plugin.json +0 -1
- package/package.json +1 -1
package/dist/plugin2.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
let node_module = require("node:module");
|
|
2
|
-
let _alfe_ai_chat = require("@alfe.ai/chat");
|
|
3
|
-
let _alfe_ai_config = require("@alfe.ai/config");
|
|
4
|
-
let _alfe_ai_agent_api_client = require("@alfe.ai/agent-api-client");
|
|
5
2
|
let node_fs_promises = require("node:fs/promises");
|
|
6
3
|
let node_path = require("node:path");
|
|
7
4
|
let node_os = require("node:os");
|
|
5
|
+
let _alfe_ai_chat = require("@alfe.ai/chat");
|
|
6
|
+
let _alfe_ai_config = require("@alfe.ai/config");
|
|
7
|
+
let _alfe_ai_agent_api_client = require("@alfe.ai/agent-api-client");
|
|
8
8
|
let node_fs = require("node:fs");
|
|
9
9
|
//#region src/alfe-channel.ts
|
|
10
10
|
const CHANNEL_ID = "alfe";
|
|
@@ -325,6 +325,33 @@ let pluginRuntime = null;
|
|
|
325
325
|
let chatClient = null;
|
|
326
326
|
let connectingPromise = null;
|
|
327
327
|
let metricsClient = null;
|
|
328
|
+
async function downloadAttachments(attachments, log) {
|
|
329
|
+
const attachDir = (0, node_path.join)((0, node_os.homedir)(), ".alfe", "attachments");
|
|
330
|
+
await (0, node_fs_promises.mkdir)(attachDir, { recursive: true });
|
|
331
|
+
const results = [];
|
|
332
|
+
for (const att of attachments) {
|
|
333
|
+
const filename = att.filename ?? att.id;
|
|
334
|
+
const localPath = (0, node_path.join)(attachDir, `${att.id}_${filename}`);
|
|
335
|
+
try {
|
|
336
|
+
const res = await fetch(att.url);
|
|
337
|
+
if (!res.ok) {
|
|
338
|
+
log.warn(`Failed to download attachment ${att.id}: ${String(res.status)}`);
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
const buffer = Buffer.from(await res.arrayBuffer());
|
|
342
|
+
await (0, node_fs_promises.writeFile)(localPath, buffer);
|
|
343
|
+
results.push({
|
|
344
|
+
localPath,
|
|
345
|
+
filename,
|
|
346
|
+
mimeType: att.mimeType
|
|
347
|
+
});
|
|
348
|
+
log.info(`Downloaded attachment: ${localPath} (${String(buffer.length)} bytes)`);
|
|
349
|
+
} catch (err) {
|
|
350
|
+
log.error(`Failed to download attachment ${att.id}: ${err instanceof Error ? err.message : String(err)}`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return results;
|
|
354
|
+
}
|
|
328
355
|
async function handleAgentRequest(request, log) {
|
|
329
356
|
const runtime = pluginRuntime;
|
|
330
357
|
if (!runtime) {
|
|
@@ -335,8 +362,8 @@ async function handleAgentRequest(request, log) {
|
|
|
335
362
|
chatClient?.sendResponse(request.id, false, { message: "OpenClaw SDK not available — cannot dispatch" });
|
|
336
363
|
return;
|
|
337
364
|
}
|
|
338
|
-
const { message, sessionKey: legacySessionKey, userId, conversationId, conversationType, tenantId, clientType, displayName } = request.params;
|
|
339
|
-
if (!message) {
|
|
365
|
+
const { message, sessionKey: legacySessionKey, userId, conversationId, conversationType, tenantId, clientType, displayName, attachments: rawAttachments } = request.params;
|
|
366
|
+
if (!message && !rawAttachments?.length) {
|
|
340
367
|
chatClient?.sendResponse(request.id, false, { message: "Missing message" });
|
|
341
368
|
return;
|
|
342
369
|
}
|
|
@@ -360,6 +387,8 @@ async function handleAgentRequest(request, log) {
|
|
|
360
387
|
});
|
|
361
388
|
});
|
|
362
389
|
try {
|
|
390
|
+
const downloadedFiles = rawAttachments?.length ? await downloadAttachments(rawAttachments, log) : [];
|
|
391
|
+
const bodyForAgent = downloadedFiles.length ? `${message || ""}\n\n[Attached files:\n${downloadedFiles.map((f) => `- ${f.filename}: ${f.localPath}`).join("\n")}]` : void 0;
|
|
363
392
|
const channelMode = extractChannelMode(conversationId ?? "", clientType ?? "chat");
|
|
364
393
|
const channelLabel = channelMode === "sms" ? "SMS" : channelMode === "whatsapp" ? "WhatsApp" : "Alfe";
|
|
365
394
|
const shortConvId = conversationId?.slice(-8) ?? "";
|
|
@@ -382,7 +411,8 @@ async function handleAgentRequest(request, log) {
|
|
|
382
411
|
senderAddress: `user:${senderId}`,
|
|
383
412
|
recipientAddress: "agent",
|
|
384
413
|
conversationLabel,
|
|
385
|
-
rawBody: message,
|
|
414
|
+
rawBody: message || "",
|
|
415
|
+
bodyForAgent,
|
|
386
416
|
messageId: request.id,
|
|
387
417
|
timestamp: Date.now(),
|
|
388
418
|
extraContext: {
|
|
@@ -394,11 +424,13 @@ async function handleAgentRequest(request, log) {
|
|
|
394
424
|
},
|
|
395
425
|
deliver: async (payload) => {
|
|
396
426
|
const responseText = payload.text ?? "";
|
|
427
|
+
const mediaUrls = [...payload.mediaUrl ? [payload.mediaUrl] : [], ...payload.mediaUrls ?? []];
|
|
397
428
|
await addMessage(sessionId, "assistant", responseText);
|
|
398
429
|
chatClient?.notify("agent-message", {
|
|
399
430
|
conversationId: conversationId ?? legacySessionKey,
|
|
400
431
|
text: responseText,
|
|
401
|
-
sessionKey: resolvedOpenClawKey ?? legacySessionKey
|
|
432
|
+
sessionKey: resolvedOpenClawKey ?? legacySessionKey,
|
|
433
|
+
...mediaUrls.length ? { mediaUrls } : {}
|
|
402
434
|
});
|
|
403
435
|
if (metricsClient && userId) metricsClient.recordActivity({
|
|
404
436
|
userId,
|
package/dist/plugin2.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { ChatServiceClient, resolveAlfeChat } from "@alfe.ai/chat";
|
|
3
|
-
import { resolveConfig } from "@alfe.ai/config";
|
|
4
|
-
import { AgentApiClient } from "@alfe.ai/agent-api-client";
|
|
5
2
|
import { mkdir, readFile, readdir, stat, unlink, writeFile } from "node:fs/promises";
|
|
6
3
|
import { join } from "node:path";
|
|
7
4
|
import { homedir } from "node:os";
|
|
5
|
+
import { ChatServiceClient, resolveAlfeChat } from "@alfe.ai/chat";
|
|
6
|
+
import { resolveConfig } from "@alfe.ai/config";
|
|
7
|
+
import { AgentApiClient } from "@alfe.ai/agent-api-client";
|
|
8
8
|
import { existsSync } from "node:fs";
|
|
9
9
|
//#region src/alfe-channel.ts
|
|
10
10
|
const CHANNEL_ID = "alfe";
|
|
@@ -325,6 +325,33 @@ let pluginRuntime = null;
|
|
|
325
325
|
let chatClient = null;
|
|
326
326
|
let connectingPromise = null;
|
|
327
327
|
let metricsClient = null;
|
|
328
|
+
async function downloadAttachments(attachments, log) {
|
|
329
|
+
const attachDir = join(homedir(), ".alfe", "attachments");
|
|
330
|
+
await mkdir(attachDir, { recursive: true });
|
|
331
|
+
const results = [];
|
|
332
|
+
for (const att of attachments) {
|
|
333
|
+
const filename = att.filename ?? att.id;
|
|
334
|
+
const localPath = join(attachDir, `${att.id}_${filename}`);
|
|
335
|
+
try {
|
|
336
|
+
const res = await fetch(att.url);
|
|
337
|
+
if (!res.ok) {
|
|
338
|
+
log.warn(`Failed to download attachment ${att.id}: ${String(res.status)}`);
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
const buffer = Buffer.from(await res.arrayBuffer());
|
|
342
|
+
await writeFile(localPath, buffer);
|
|
343
|
+
results.push({
|
|
344
|
+
localPath,
|
|
345
|
+
filename,
|
|
346
|
+
mimeType: att.mimeType
|
|
347
|
+
});
|
|
348
|
+
log.info(`Downloaded attachment: ${localPath} (${String(buffer.length)} bytes)`);
|
|
349
|
+
} catch (err) {
|
|
350
|
+
log.error(`Failed to download attachment ${att.id}: ${err instanceof Error ? err.message : String(err)}`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return results;
|
|
354
|
+
}
|
|
328
355
|
async function handleAgentRequest(request, log) {
|
|
329
356
|
const runtime = pluginRuntime;
|
|
330
357
|
if (!runtime) {
|
|
@@ -335,8 +362,8 @@ async function handleAgentRequest(request, log) {
|
|
|
335
362
|
chatClient?.sendResponse(request.id, false, { message: "OpenClaw SDK not available — cannot dispatch" });
|
|
336
363
|
return;
|
|
337
364
|
}
|
|
338
|
-
const { message, sessionKey: legacySessionKey, userId, conversationId, conversationType, tenantId, clientType, displayName } = request.params;
|
|
339
|
-
if (!message) {
|
|
365
|
+
const { message, sessionKey: legacySessionKey, userId, conversationId, conversationType, tenantId, clientType, displayName, attachments: rawAttachments } = request.params;
|
|
366
|
+
if (!message && !rawAttachments?.length) {
|
|
340
367
|
chatClient?.sendResponse(request.id, false, { message: "Missing message" });
|
|
341
368
|
return;
|
|
342
369
|
}
|
|
@@ -360,6 +387,8 @@ async function handleAgentRequest(request, log) {
|
|
|
360
387
|
});
|
|
361
388
|
});
|
|
362
389
|
try {
|
|
390
|
+
const downloadedFiles = rawAttachments?.length ? await downloadAttachments(rawAttachments, log) : [];
|
|
391
|
+
const bodyForAgent = downloadedFiles.length ? `${message || ""}\n\n[Attached files:\n${downloadedFiles.map((f) => `- ${f.filename}: ${f.localPath}`).join("\n")}]` : void 0;
|
|
363
392
|
const channelMode = extractChannelMode(conversationId ?? "", clientType ?? "chat");
|
|
364
393
|
const channelLabel = channelMode === "sms" ? "SMS" : channelMode === "whatsapp" ? "WhatsApp" : "Alfe";
|
|
365
394
|
const shortConvId = conversationId?.slice(-8) ?? "";
|
|
@@ -382,7 +411,8 @@ async function handleAgentRequest(request, log) {
|
|
|
382
411
|
senderAddress: `user:${senderId}`,
|
|
383
412
|
recipientAddress: "agent",
|
|
384
413
|
conversationLabel,
|
|
385
|
-
rawBody: message,
|
|
414
|
+
rawBody: message || "",
|
|
415
|
+
bodyForAgent,
|
|
386
416
|
messageId: request.id,
|
|
387
417
|
timestamp: Date.now(),
|
|
388
418
|
extraContext: {
|
|
@@ -394,11 +424,13 @@ async function handleAgentRequest(request, log) {
|
|
|
394
424
|
},
|
|
395
425
|
deliver: async (payload) => {
|
|
396
426
|
const responseText = payload.text ?? "";
|
|
427
|
+
const mediaUrls = [...payload.mediaUrl ? [payload.mediaUrl] : [], ...payload.mediaUrls ?? []];
|
|
397
428
|
await addMessage(sessionId, "assistant", responseText);
|
|
398
429
|
chatClient?.notify("agent-message", {
|
|
399
430
|
conversationId: conversationId ?? legacySessionKey,
|
|
400
431
|
text: responseText,
|
|
401
|
-
sessionKey: resolvedOpenClawKey ?? legacySessionKey
|
|
432
|
+
sessionKey: resolvedOpenClawKey ?? legacySessionKey,
|
|
433
|
+
...mediaUrls.length ? { mediaUrls } : {}
|
|
402
434
|
});
|
|
403
435
|
if (metricsClient && userId) metricsClient.recordActivity({
|
|
404
436
|
userId,
|
package/openclaw.plugin.json
CHANGED