agent-bridge-aun 1.0.31 → 1.0.33
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/src-ts/agent.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AgentError = void 0;
|
|
3
|
+
exports.AgentOperationError = exports.AgentError = void 0;
|
|
4
|
+
exports.errorDetails = errorDetails;
|
|
4
5
|
class AgentError extends Error {
|
|
5
6
|
constructor(message, options) {
|
|
6
7
|
super(message, options);
|
|
@@ -8,3 +9,26 @@ class AgentError extends Error {
|
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
11
|
exports.AgentError = AgentError;
|
|
12
|
+
/** 保留底层错误码,避免只留下 fetch failed 或超时这类表层提示。 */
|
|
13
|
+
function errorDetails(error) {
|
|
14
|
+
const parts = [];
|
|
15
|
+
const seen = new Set();
|
|
16
|
+
for (let current = error; current && !seen.has(current) && seen.size < 5;) {
|
|
17
|
+
seen.add(current);
|
|
18
|
+
const value = current;
|
|
19
|
+
const message = typeof value.message === "string" ? value.message : String(current);
|
|
20
|
+
parts.push(`${message}${value.code ? `(${String(value.code)})` : ""}`);
|
|
21
|
+
current = value.cause;
|
|
22
|
+
}
|
|
23
|
+
return parts.join(";原因:") || String(error);
|
|
24
|
+
}
|
|
25
|
+
class AgentOperationError extends AgentError {
|
|
26
|
+
code;
|
|
27
|
+
stage;
|
|
28
|
+
constructor(code, stage, cause) {
|
|
29
|
+
super(`${code}:${stage}失败:${errorDetails(cause)}`, { cause });
|
|
30
|
+
this.code = code;
|
|
31
|
+
this.stage = stage;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.AgentOperationError = AgentOperationError;
|
|
@@ -8,6 +8,7 @@ exports.uploadAunAttachments = uploadAunAttachments;
|
|
|
8
8
|
const node_crypto_1 = require("node:crypto");
|
|
9
9
|
const node_util_1 = require("node:util");
|
|
10
10
|
const attachments_1 = require("../../attachments");
|
|
11
|
+
const agent_1 = require("../../agent");
|
|
11
12
|
const aidPattern = /^[a-z0-9][a-z0-9_-]{2,63}\.[a-z0-9-]+(?:\.[a-z0-9-]+)+$/;
|
|
12
13
|
const mimePattern = /^[A-Za-z0-9!#$&^_.+-]+\/[A-Za-z0-9!#$&^_.+-]+$/;
|
|
13
14
|
const imageTypes = new Set(["image/png", "image/jpeg", "image/webp"]);
|
|
@@ -252,13 +253,15 @@ async function uploadAunAttachments(client, ownerAid, peerAid, items) {
|
|
|
252
253
|
// 视频播放器不携带 AID 凭据,沿用 EvolCore 的标准可读对象上传方式。
|
|
253
254
|
const video = contentType.startsWith("video/");
|
|
254
255
|
const ref = { ownerAid, bucket: "default", objectKey, filename, contentType, sizeBytes: item.data.byteLength, sha256 };
|
|
255
|
-
const uploaded = await client.storage.writeBytes(`/${objectKey}`, item.data, { contentType, public: video, overwrite: video })
|
|
256
|
+
const uploaded = await client.storage.writeBytes(`/${objectKey}`, item.data, { contentType, public: video, overwrite: video })
|
|
257
|
+
.catch(error => { throw new agent_1.AgentOperationError("AUN_FS_UPLOAD_FAILED", `上传 AUN FS 文件“${filename}”`, error); });
|
|
256
258
|
checkedMetadata({ ...uploaded, size: uploaded.size ?? uploaded.size_bytes ?? item.data.byteLength }, ref);
|
|
257
259
|
if (video) {
|
|
258
260
|
result.push({ owner_aid: ownerAid, object_key: objectKey, filename, content_type: contentType, size_bytes: item.data.byteLength, sha256 });
|
|
259
261
|
continue;
|
|
260
262
|
}
|
|
261
|
-
const share = await client.storage.lowlevel.createShareLink({ owner: ownerAid, bucket: "default", objectKey, allowedAids: [peerAid], expireInSeconds: 86400 })
|
|
263
|
+
const share = await client.storage.lowlevel.createShareLink({ owner: ownerAid, bucket: "default", objectKey, allowedAids: [peerAid], expireInSeconds: 86400 })
|
|
264
|
+
.catch(error => { throw new agent_1.AgentOperationError("AUN_FS_SHARE_FAILED", `创建 AUN FS 文件“${filename}”的接收方授权`, error); });
|
|
262
265
|
if (share.owner_aid && share.owner_aid !== ownerAid || share.bucket && share.bucket !== "default" || share.object_key && share.object_key !== objectKey)
|
|
263
266
|
throw new Error("AUN 附件分享对象不一致");
|
|
264
267
|
if (share.allowed_aids !== undefined && (!Array.isArray(share.allowed_aids) || share.allowed_aids.length !== 1 || share.allowed_aids[0] !== peerAid))
|
|
@@ -8,10 +8,11 @@ const node_module_1 = require("node:module");
|
|
|
8
8
|
const node_path_1 = require("node:path");
|
|
9
9
|
const node_os_1 = require("node:os");
|
|
10
10
|
const node_url_1 = require("node:url");
|
|
11
|
+
const agent_1 = require("../../agent");
|
|
11
12
|
const messages_1 = require("./messages");
|
|
12
13
|
const attachments_1 = require("./attachments");
|
|
13
14
|
const manifest = {
|
|
14
|
-
id: "aun", version: "1.0.
|
|
15
|
+
id: "aun", version: "1.0.33", type: "channel", displayName: "AUN 通道",
|
|
15
16
|
entry: "dist/src-ts/plugins/aun/index.js", apiVersion: "1", process: "in-process",
|
|
16
17
|
capabilities: ["channel", "channel.identity.create", "channel.receive", "channel.send", "health", "cli"],
|
|
17
18
|
configSchema: "config.schema.json",
|
|
@@ -82,10 +83,11 @@ class AunPlugin {
|
|
|
82
83
|
identity = {
|
|
83
84
|
list: async () => {
|
|
84
85
|
const own = new Set([...this.createdAids, ...this.legacyCreatedAids]);
|
|
86
|
+
const known = new Set([...this.clients.keys(), ...this.listStoreAids()]);
|
|
85
87
|
return {
|
|
86
|
-
evolcore: [...
|
|
88
|
+
evolcore: [...known].filter((aid) => !own.has(aid)).sort(),
|
|
87
89
|
muAgentBridge: [...this.clients.keys()].filter((aid) => own.has(aid)).sort(),
|
|
88
|
-
localMuAgentBridge: [...own].filter((aid) => !
|
|
90
|
+
localMuAgentBridge: [...own].filter((aid) => !known.has(aid)).sort(),
|
|
89
91
|
};
|
|
90
92
|
},
|
|
91
93
|
create: async (aid, owner) => {
|
|
@@ -799,7 +801,9 @@ class AunPlugin {
|
|
|
799
801
|
}
|
|
800
802
|
}
|
|
801
803
|
async processMessage(message, aid, agentPlugin) {
|
|
802
|
-
let
|
|
804
|
+
let deliveryFailed = false;
|
|
805
|
+
const trace = { aid, peer: message.peerId, threadId: message.threadId ?? "", messageId: message.messageId ?? "", agentPlugin };
|
|
806
|
+
this.context?.logger.info("AUN 收到任务", { ...trace, stage: "接收消息", attachments: message.attachments?.length ?? 0 });
|
|
803
807
|
const client = this.clients.get(aid)?.client;
|
|
804
808
|
let attachments = [];
|
|
805
809
|
let uploadedItems;
|
|
@@ -824,9 +828,9 @@ class AunPlugin {
|
|
|
824
828
|
}
|
|
825
829
|
}
|
|
826
830
|
catch (error) {
|
|
827
|
-
this.context?.logger.warn("AUN 附件下载失败", { error: safeError(error), ...(error instanceof attachments_1.AunDownloadUrlError ? { downloadUrl: error.diagnostic } : {}) });
|
|
831
|
+
this.context?.logger.warn("AUN 附件下载失败", { ...trace, stage: "下载入站附件", error: safeError((0, agent_1.errorDetails)(error)), ...(error instanceof attachments_1.AunDownloadUrlError ? { downloadUrl: error.diagnostic } : {}) });
|
|
828
832
|
try {
|
|
829
|
-
await this.sendText(aid, message.peerId,
|
|
833
|
+
await this.sendText(aid, message.peerId, `附件接收失败:下载入站附件失败:${safeError((0, agent_1.errorDetails)(error))}`, message.threadId);
|
|
830
834
|
}
|
|
831
835
|
catch { /* 尽力反馈 */ }
|
|
832
836
|
return;
|
|
@@ -838,13 +842,18 @@ class AunPlugin {
|
|
|
838
842
|
reply: async (text) => {
|
|
839
843
|
if (!text.trim())
|
|
840
844
|
return;
|
|
841
|
-
|
|
842
|
-
|
|
845
|
+
try {
|
|
846
|
+
await this.sendText(aid, message.peerId, text, message.threadId);
|
|
847
|
+
this.context?.logger.info("AUN 文本已发送", { ...trace, stage: "发送文本消息" });
|
|
848
|
+
}
|
|
849
|
+
catch (error) {
|
|
850
|
+
deliveryFailed = true;
|
|
851
|
+
throw new agent_1.AgentOperationError("AUN_TEXT_SEND_FAILED", "发送 AUN 文本消息(结果未确认,不自动重发)", error);
|
|
852
|
+
}
|
|
843
853
|
},
|
|
844
854
|
replyAttachments: async (items, text) => {
|
|
845
855
|
if (!items.length)
|
|
846
856
|
return;
|
|
847
|
-
replyAttempted = true;
|
|
848
857
|
let sent = 0;
|
|
849
858
|
let groupsCount = 0;
|
|
850
859
|
let sending = false;
|
|
@@ -852,6 +861,7 @@ class AunPlugin {
|
|
|
852
861
|
if (!client?.storage)
|
|
853
862
|
throw new Error("AUN SDK 不支持附件存储接口");
|
|
854
863
|
const refs = uploadedRefs && uploadedItems === items ? uploadedRefs : await (0, attachments_1.uploadAunAttachments)({ storage: client.storage }, aid, message.peerId, items);
|
|
864
|
+
this.context?.logger.info("AUN FS 文件上传与授权完成", { ...trace, stage: "上传并授权附件", files: items.map(item => ({ filename: item.filename, sizeBytes: item.data.byteLength })) });
|
|
855
865
|
if (!uploadedRefs || uploadedItems !== items) {
|
|
856
866
|
uploadedItems = items;
|
|
857
867
|
uploadedRefs = refs;
|
|
@@ -873,32 +883,37 @@ class AunPlugin {
|
|
|
873
883
|
sending = true;
|
|
874
884
|
// message.send 失败时可能已送达,不自动重试或降级明文,避免重复发送和泄露引用。
|
|
875
885
|
await client.call("message.send", { to: message.peerId, payload, encrypt: true });
|
|
886
|
+
this.context?.logger.info("AUN 附件消息已发送", { ...trace, stage: "发送附件消息", kind, count: group.length });
|
|
876
887
|
sending = false;
|
|
877
888
|
sent++;
|
|
878
889
|
}
|
|
879
890
|
}
|
|
880
891
|
catch (error) {
|
|
892
|
+
deliveryFailed = true;
|
|
893
|
+
const failure = sending ? new agent_1.AgentOperationError("AUN_ATTACHMENT_SEND_FAILED", "发送 AUN 附件消息(FS 上传已完成)", error) : error;
|
|
881
894
|
const progress = sending ? `(已确认发送 ${sent}/${groupsCount} 组,当前组结果未确认,请勿重复发送)` : "";
|
|
882
895
|
try {
|
|
883
|
-
await this.sendText(aid, message.peerId, `附件回传失败${progress}:${safeError(
|
|
896
|
+
await this.sendText(aid, message.peerId, `附件回传失败${progress}:${safeError((0, agent_1.errorDetails)(failure))}`, message.threadId);
|
|
884
897
|
}
|
|
885
898
|
catch { /* 尽力反馈 */ }
|
|
886
|
-
throw
|
|
899
|
+
throw failure;
|
|
887
900
|
}
|
|
888
901
|
},
|
|
889
902
|
};
|
|
890
903
|
try {
|
|
904
|
+
this.context?.logger.info("AUN 开始调用 Agent", { ...trace, stage: "调用 Agent" });
|
|
891
905
|
await this.ingress.publish(channelMessage);
|
|
906
|
+
this.context?.logger.info("AUN 任务处理完成", { ...trace, stage: "回复已发送" });
|
|
892
907
|
}
|
|
893
908
|
catch (error) {
|
|
894
|
-
this.context?.logger.warn("AUN 消息处理失败", { error: safeError(error) });
|
|
895
|
-
if (!
|
|
909
|
+
this.context?.logger.warn("AUN 消息处理失败", { ...trace, stage: deliveryFailed ? "回传回复" : "执行 Agent 任务", error: safeError((0, agent_1.errorDetails)(error)) });
|
|
910
|
+
if (!deliveryFailed) {
|
|
896
911
|
const action = attachments.length > 0 ? "附件处理失败" : newSessionCommand.test(message.text.trim()) ? "新建会话失败" : "消息处理失败";
|
|
897
912
|
try {
|
|
898
|
-
await channelMessage.reply(`${action}:${safeError(error)}`);
|
|
913
|
+
await channelMessage.reply(`${action}:${safeError((0, agent_1.errorDetails)(error))}`);
|
|
899
914
|
}
|
|
900
915
|
catch (replyError) {
|
|
901
|
-
this.context?.logger.warn("AUN 错误回复失败", { error: safeError(replyError) });
|
|
916
|
+
this.context?.logger.warn("AUN 错误回复失败", { ...trace, stage: "发送最终错误消息", error: safeError((0, agent_1.errorDetails)(replyError)) });
|
|
902
917
|
}
|
|
903
918
|
}
|
|
904
919
|
}
|
|
@@ -931,7 +946,7 @@ class AunPlugin {
|
|
|
931
946
|
exports.AunPlugin = AunPlugin;
|
|
932
947
|
exports.default = AunPlugin;
|
|
933
948
|
function safeError(error) {
|
|
934
|
-
return redact(error instanceof Error ? error.message : String(error))
|
|
949
|
+
return redact(error instanceof Error ? error.message : String(error));
|
|
935
950
|
}
|
|
936
951
|
async function readResponse(response, limit) {
|
|
937
952
|
if (!response.body) {
|
package/package.json
CHANGED