agent-bridge-aun 1.0.31 → 1.0.32

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.
@@ -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.31", type: "channel", displayName: "AUN 通道",
15
+ id: "aun", version: "1.0.32", 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",
@@ -799,7 +800,9 @@ class AunPlugin {
799
800
  }
800
801
  }
801
802
  async processMessage(message, aid, agentPlugin) {
802
- let replyAttempted = false;
803
+ let deliveryFailed = false;
804
+ const trace = { aid, peer: message.peerId, threadId: message.threadId ?? "", messageId: message.messageId ?? "", agentPlugin };
805
+ this.context?.logger.info("AUN 收到任务", { ...trace, stage: "接收消息", attachments: message.attachments?.length ?? 0 });
803
806
  const client = this.clients.get(aid)?.client;
804
807
  let attachments = [];
805
808
  let uploadedItems;
@@ -824,9 +827,9 @@ class AunPlugin {
824
827
  }
825
828
  }
826
829
  catch (error) {
827
- this.context?.logger.warn("AUN 附件下载失败", { error: safeError(error), ...(error instanceof attachments_1.AunDownloadUrlError ? { downloadUrl: error.diagnostic } : {}) });
830
+ this.context?.logger.warn("AUN 附件下载失败", { ...trace, stage: "下载入站附件", error: safeError((0, agent_1.errorDetails)(error)), ...(error instanceof attachments_1.AunDownloadUrlError ? { downloadUrl: error.diagnostic } : {}) });
828
831
  try {
829
- await this.sendText(aid, message.peerId, `附件接收失败:${safeError(error)}`, message.threadId);
832
+ await this.sendText(aid, message.peerId, `附件接收失败:下载入站附件失败:${safeError((0, agent_1.errorDetails)(error))}`, message.threadId);
830
833
  }
831
834
  catch { /* 尽力反馈 */ }
832
835
  return;
@@ -838,13 +841,18 @@ class AunPlugin {
838
841
  reply: async (text) => {
839
842
  if (!text.trim())
840
843
  return;
841
- replyAttempted = true;
842
- await this.sendText(aid, message.peerId, text, message.threadId);
844
+ try {
845
+ await this.sendText(aid, message.peerId, text, message.threadId);
846
+ this.context?.logger.info("AUN 文本已发送", { ...trace, stage: "发送文本消息" });
847
+ }
848
+ catch (error) {
849
+ deliveryFailed = true;
850
+ throw new agent_1.AgentOperationError("AUN_TEXT_SEND_FAILED", "发送 AUN 文本消息(结果未确认,不自动重发)", error);
851
+ }
843
852
  },
844
853
  replyAttachments: async (items, text) => {
845
854
  if (!items.length)
846
855
  return;
847
- replyAttempted = true;
848
856
  let sent = 0;
849
857
  let groupsCount = 0;
850
858
  let sending = false;
@@ -852,6 +860,7 @@ class AunPlugin {
852
860
  if (!client?.storage)
853
861
  throw new Error("AUN SDK 不支持附件存储接口");
854
862
  const refs = uploadedRefs && uploadedItems === items ? uploadedRefs : await (0, attachments_1.uploadAunAttachments)({ storage: client.storage }, aid, message.peerId, items);
863
+ this.context?.logger.info("AUN FS 文件上传与授权完成", { ...trace, stage: "上传并授权附件", files: items.map(item => ({ filename: item.filename, sizeBytes: item.data.byteLength })) });
855
864
  if (!uploadedRefs || uploadedItems !== items) {
856
865
  uploadedItems = items;
857
866
  uploadedRefs = refs;
@@ -873,32 +882,37 @@ class AunPlugin {
873
882
  sending = true;
874
883
  // message.send 失败时可能已送达,不自动重试或降级明文,避免重复发送和泄露引用。
875
884
  await client.call("message.send", { to: message.peerId, payload, encrypt: true });
885
+ this.context?.logger.info("AUN 附件消息已发送", { ...trace, stage: "发送附件消息", kind, count: group.length });
876
886
  sending = false;
877
887
  sent++;
878
888
  }
879
889
  }
880
890
  catch (error) {
891
+ deliveryFailed = true;
892
+ const failure = sending ? new agent_1.AgentOperationError("AUN_ATTACHMENT_SEND_FAILED", "发送 AUN 附件消息(FS 上传已完成)", error) : error;
881
893
  const progress = sending ? `(已确认发送 ${sent}/${groupsCount} 组,当前组结果未确认,请勿重复发送)` : "";
882
894
  try {
883
- await this.sendText(aid, message.peerId, `附件回传失败${progress}:${safeError(error)}`, message.threadId);
895
+ await this.sendText(aid, message.peerId, `附件回传失败${progress}:${safeError((0, agent_1.errorDetails)(failure))}`, message.threadId);
884
896
  }
885
897
  catch { /* 尽力反馈 */ }
886
- throw error;
898
+ throw failure;
887
899
  }
888
900
  },
889
901
  };
890
902
  try {
903
+ this.context?.logger.info("AUN 开始调用 Agent", { ...trace, stage: "调用 Agent" });
891
904
  await this.ingress.publish(channelMessage);
905
+ this.context?.logger.info("AUN 任务处理完成", { ...trace, stage: "回复已发送" });
892
906
  }
893
907
  catch (error) {
894
- this.context?.logger.warn("AUN 消息处理失败", { error: safeError(error) });
895
- if (!replyAttempted) {
908
+ this.context?.logger.warn("AUN 消息处理失败", { ...trace, stage: deliveryFailed ? "回传回复" : "执行 Agent 任务", error: safeError((0, agent_1.errorDetails)(error)) });
909
+ if (!deliveryFailed) {
896
910
  const action = attachments.length > 0 ? "附件处理失败" : newSessionCommand.test(message.text.trim()) ? "新建会话失败" : "消息处理失败";
897
911
  try {
898
- await channelMessage.reply(`${action}:${safeError(error)}`);
912
+ await channelMessage.reply(`${action}:${safeError((0, agent_1.errorDetails)(error))}`);
899
913
  }
900
914
  catch (replyError) {
901
- this.context?.logger.warn("AUN 错误回复失败", { error: safeError(replyError) });
915
+ this.context?.logger.warn("AUN 错误回复失败", { ...trace, stage: "发送最终错误消息", error: safeError((0, agent_1.errorDetails)(replyError)) });
902
916
  }
903
917
  }
904
918
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-bridge-aun",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "description": "mu-agent-bridge 的 AUN 通道插件。",
5
5
  "keywords": [
6
6
  "mu-agent-bridge-plugin",
package/plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "aun",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "type": "channel",
5
5
  "displayName": "AUN 通道",
6
6
  "entry": "dist/src-ts/plugins/aun/index.js",