@cloudbase/agent-adapter-wx 1.0.1-alpha.25 → 1.0.1-alpha.25-2

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/README.md CHANGED
@@ -151,7 +151,7 @@ new WeChatSender(config: WeChatConfig)
151
151
  ```typescript
152
152
  enum WeChatPlatform {
153
153
  CUSTOM_SERVICE = "WXCustomerService",
154
- MINI_APP = "WXMiniApp",
154
+ MINI_APP = "WXMiniapp",
155
155
  SERVICE = "WXService",
156
156
  SUBSCRIPTION = "WXSubscription",
157
157
  }
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Request, Response } from 'express';
2
2
  import { AbstractAgent, AgentConfig, BaseEvent, RunAgentInput } from '@ag-ui/client';
3
3
  import { Observable } from 'rxjs';
4
- import { WxSendMessageInput } from '@cloudbase/aiagent-framework';
4
+ import { WxSendMessageInput, aitools } from '@cloudbase/aiagent-framework';
5
5
  import { Logger } from '@cloudbase/agent-shared';
6
6
 
7
7
  /**
@@ -11,7 +11,7 @@ declare enum WeChatPlatform {
11
11
  /** 企业微信客服 */
12
12
  CUSTOM_SERVICE = "WXCustomerService",
13
13
  /** 微信小程序 */
14
- MINI_APP = "WXMiniApp",
14
+ MINI_APP = "WXMiniapp",
15
15
  /** 微信服务号 */
16
16
  SERVICE = "WXService",
17
17
  /** 微信订阅号 */
@@ -127,7 +127,7 @@ interface WeChatWorkCommonInput {
127
127
  /**
128
128
  * Supported trigger sources - 支持的触发源
129
129
  */
130
- type WeChatTriggerSrc = "WXSubscription" | "WXService" | "WXMiniApp" | "WXCustomerService";
130
+ type WeChatTriggerSrc = WeChatPlatform.SUBSCRIPTION | WeChatPlatform.SERVICE | WeChatPlatform.MINI_APP | WeChatPlatform.CUSTOM_SERVICE;
131
131
  /**
132
132
  * Supported message types - 支持的消息类型
133
133
  */
@@ -236,8 +236,8 @@ interface WeChatReplyMessage {
236
236
  createTime: number;
237
237
  msgType: string;
238
238
  content: string;
239
+ msgId: string;
239
240
  openKfId?: string;
240
- msgId?: string;
241
241
  }
242
242
  /**
243
243
  * Format reply message for WeChat
@@ -465,13 +465,13 @@ interface IWxRunAgentInput extends RunAgentInput {
465
465
  declare class WeChatAgent extends AbstractAgent {
466
466
  private wrappedAgent;
467
467
  private wechatSender?;
468
- private aitools?;
469
468
  private wechatConfig;
470
469
  private _historyManager;
471
470
  private messageFormatter;
472
471
  private eventFilter;
473
472
  private messageBuffer;
474
473
  private recommendQuestions?;
474
+ aitools?: aitools.AITools;
475
475
  constructor(config: WeChatAgentConfig);
476
476
  /**
477
477
  * Last assembled reply content after run() completes
@@ -568,15 +568,15 @@ interface AgentCreatorResult {
568
568
  toAGUIAgent(): AbstractAgent;
569
569
  };
570
570
  cleanup?: () => void;
571
- aitools?: {
572
- getWxMediaContent: (botId: string, triggerSrc: string, mediaId: string) => Promise<string | null>;
573
- };
574
571
  }
575
572
  /**
576
573
  * Agent creator function type
577
574
  */
578
575
  type AgentCreator = (params: {
579
576
  request: Request;
577
+ options?: {
578
+ agentId: string;
579
+ };
580
580
  }) => AgentCreatorResult | Promise<AgentCreatorResult>;
581
581
  /**
582
582
  * Handler options
@@ -589,7 +589,7 @@ interface WxMessageHandlerOptions {
589
589
  * Directly using sendMessageAGUI.handler from @cloudbase/agent-server
590
590
  * Aligned with chat_wx_v2.service.ts logic
591
591
  *
592
- * @param createAgent - Function to create agent instance (returns { agent, cleanup?, aitools? })
592
+ * @param createAgent - Function to create agent instance (returns { agent, cleanup?})
593
593
  * @param options - Handler options
594
594
  * @returns Express route handler
595
595
  */
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Request, Response } from 'express';
2
2
  import { AbstractAgent, AgentConfig, BaseEvent, RunAgentInput } from '@ag-ui/client';
3
3
  import { Observable } from 'rxjs';
4
- import { WxSendMessageInput } from '@cloudbase/aiagent-framework';
4
+ import { WxSendMessageInput, aitools } from '@cloudbase/aiagent-framework';
5
5
  import { Logger } from '@cloudbase/agent-shared';
6
6
 
7
7
  /**
@@ -11,7 +11,7 @@ declare enum WeChatPlatform {
11
11
  /** 企业微信客服 */
12
12
  CUSTOM_SERVICE = "WXCustomerService",
13
13
  /** 微信小程序 */
14
- MINI_APP = "WXMiniApp",
14
+ MINI_APP = "WXMiniapp",
15
15
  /** 微信服务号 */
16
16
  SERVICE = "WXService",
17
17
  /** 微信订阅号 */
@@ -127,7 +127,7 @@ interface WeChatWorkCommonInput {
127
127
  /**
128
128
  * Supported trigger sources - 支持的触发源
129
129
  */
130
- type WeChatTriggerSrc = "WXSubscription" | "WXService" | "WXMiniApp" | "WXCustomerService";
130
+ type WeChatTriggerSrc = WeChatPlatform.SUBSCRIPTION | WeChatPlatform.SERVICE | WeChatPlatform.MINI_APP | WeChatPlatform.CUSTOM_SERVICE;
131
131
  /**
132
132
  * Supported message types - 支持的消息类型
133
133
  */
@@ -236,8 +236,8 @@ interface WeChatReplyMessage {
236
236
  createTime: number;
237
237
  msgType: string;
238
238
  content: string;
239
+ msgId: string;
239
240
  openKfId?: string;
240
- msgId?: string;
241
241
  }
242
242
  /**
243
243
  * Format reply message for WeChat
@@ -465,13 +465,13 @@ interface IWxRunAgentInput extends RunAgentInput {
465
465
  declare class WeChatAgent extends AbstractAgent {
466
466
  private wrappedAgent;
467
467
  private wechatSender?;
468
- private aitools?;
469
468
  private wechatConfig;
470
469
  private _historyManager;
471
470
  private messageFormatter;
472
471
  private eventFilter;
473
472
  private messageBuffer;
474
473
  private recommendQuestions?;
474
+ aitools?: aitools.AITools;
475
475
  constructor(config: WeChatAgentConfig);
476
476
  /**
477
477
  * Last assembled reply content after run() completes
@@ -568,15 +568,15 @@ interface AgentCreatorResult {
568
568
  toAGUIAgent(): AbstractAgent;
569
569
  };
570
570
  cleanup?: () => void;
571
- aitools?: {
572
- getWxMediaContent: (botId: string, triggerSrc: string, mediaId: string) => Promise<string | null>;
573
- };
574
571
  }
575
572
  /**
576
573
  * Agent creator function type
577
574
  */
578
575
  type AgentCreator = (params: {
579
576
  request: Request;
577
+ options?: {
578
+ agentId: string;
579
+ };
580
580
  }) => AgentCreatorResult | Promise<AgentCreatorResult>;
581
581
  /**
582
582
  * Handler options
@@ -589,7 +589,7 @@ interface WxMessageHandlerOptions {
589
589
  * Directly using sendMessageAGUI.handler from @cloudbase/agent-server
590
590
  * Aligned with chat_wx_v2.service.ts logic
591
591
  *
592
- * @param createAgent - Function to create agent instance (returns { agent, cleanup?, aitools? })
592
+ * @param createAgent - Function to create agent instance (returns { agent, cleanup?})
593
593
  * @param options - Handler options
594
594
  * @returns Express route handler
595
595
  */
package/dist/index.js CHANGED
@@ -61,6 +61,27 @@ __export(index_exports, {
61
61
  });
62
62
  module.exports = __toCommonJS(index_exports);
63
63
 
64
+ // src/types.ts
65
+ var WeChatPlatform = /* @__PURE__ */ ((WeChatPlatform2) => {
66
+ WeChatPlatform2["CUSTOM_SERVICE"] = "WXCustomerService";
67
+ WeChatPlatform2["MINI_APP"] = "WXMiniapp";
68
+ WeChatPlatform2["SERVICE"] = "WXService";
69
+ WeChatPlatform2["SUBSCRIPTION"] = "WXSubscription";
70
+ return WeChatPlatform2;
71
+ })(WeChatPlatform || {});
72
+ var MessageType = /* @__PURE__ */ ((MessageType2) => {
73
+ MessageType2["TEXT"] = "text";
74
+ MessageType2["IMAGE"] = "image";
75
+ MessageType2["EVENT"] = "event";
76
+ MessageType2["VOICE"] = "voice";
77
+ return MessageType2;
78
+ })(MessageType || {});
79
+ var WeChatSendMode = /* @__PURE__ */ ((WeChatSendMode2) => {
80
+ WeChatSendMode2["LOCAL"] = "local";
81
+ WeChatSendMode2["AITOOLS"] = "aitools";
82
+ return WeChatSendMode2;
83
+ })(WeChatSendMode || {});
84
+
64
85
  // src/wechat-message-handler.ts
65
86
  var SUPPORTED_MSG_TYPES = ["text", "voice"];
66
87
  function validateMessageType(msgType) {
@@ -77,21 +98,25 @@ function validateMessageType(msgType) {
77
98
  function extractMsgType(originMsg) {
78
99
  return originMsg.msgType || originMsg.MsgType || "text";
79
100
  }
80
- function extractTriggerSrc(originMsg, defaultSrc = "WXCustomerService") {
101
+ function extractTriggerSrc(originMsg, defaultSrc = "WXService" /* SERVICE */) {
81
102
  return originMsg.triggerSrc || defaultSrc;
82
103
  }
83
104
  function extractTextContent(originMsg, triggerSrc) {
84
- if (["WXSubscription", "WXService", "WXMiniApp"].includes(triggerSrc)) {
105
+ if ([
106
+ "WXSubscription" /* SUBSCRIPTION */,
107
+ "WXService" /* SERVICE */,
108
+ "WXMiniapp" /* MINI_APP */
109
+ ].includes(triggerSrc)) {
85
110
  return originMsg.Content || originMsg.content || "";
86
- } else if (triggerSrc === "WXCustomerService") {
111
+ } else if (triggerSrc === "WXCustomerService" /* CUSTOM_SERVICE */) {
87
112
  return originMsg.text?.content || "";
88
113
  }
89
114
  return "";
90
115
  }
91
116
  function extractVoiceMediaId(originMsg, triggerSrc) {
92
- if (["WXSubscription", "WXService"].includes(triggerSrc)) {
117
+ if (["WXSubscription" /* SUBSCRIPTION */, "WXService" /* SERVICE */].includes(triggerSrc)) {
93
118
  return originMsg.MediaId || originMsg.mediaId || "";
94
- } else if (triggerSrc === "WXCustomerService") {
119
+ } else if (triggerSrc === "WXCustomerService" /* CUSTOM_SERVICE */) {
95
120
  return originMsg.voice?.mediaId || "";
96
121
  }
97
122
  return "";
@@ -111,17 +136,25 @@ async function getWxChatContent(originMsg, triggerSrc, voiceMessageHandler, botI
111
136
  return "";
112
137
  }
113
138
  function extractSender(originMsg, triggerSrc) {
114
- if (["WXSubscription", "WXService", "WXMiniApp"].includes(triggerSrc)) {
139
+ if ([
140
+ "WXSubscription" /* SUBSCRIPTION */,
141
+ "WXService" /* SERVICE */,
142
+ "WXMiniapp" /* MINI_APP */
143
+ ].includes(triggerSrc)) {
115
144
  return originMsg.FromUserName || originMsg.fromUserName || "";
116
- } else if (triggerSrc === "WXCustomerService") {
145
+ } else if (triggerSrc === "WXCustomerService" /* CUSTOM_SERVICE */) {
117
146
  return originMsg.externalUserId || "";
118
147
  }
119
148
  return "";
120
149
  }
121
150
  function extractConversation(originMsg, triggerSrc) {
122
- if (["WXSubscription", "WXService", "WXMiniApp"].includes(triggerSrc)) {
151
+ if ([
152
+ "WXSubscription" /* SUBSCRIPTION */,
153
+ "WXService" /* SERVICE */,
154
+ "WXMiniapp" /* MINI_APP */
155
+ ].includes(triggerSrc)) {
123
156
  return originMsg.FromUserName || originMsg.fromUserName || "";
124
- } else if (triggerSrc === "WXCustomerService") {
157
+ } else if (triggerSrc === "WXCustomerService" /* CUSTOM_SERVICE */) {
125
158
  return originMsg.externalUserId || "";
126
159
  }
127
160
  return "";
@@ -133,13 +166,15 @@ function extractMsgId(originMsg) {
133
166
  return originMsg.msgId || originMsg.MsgId || Date.now().toString();
134
167
  }
135
168
  function extractTimestamp(originMsg, triggerSrc) {
136
- if (triggerSrc === "WXCustomerService") {
169
+ if (triggerSrc === "WXCustomerService" /* CUSTOM_SERVICE */) {
137
170
  return originMsg.sendTime || Math.floor(Date.now() / 1e3);
138
171
  }
139
172
  return originMsg.createTime || originMsg.CreateTime || Math.floor(Date.now() / 1e3);
140
173
  }
141
174
  function needAsyncReply(triggerSrc, wxVerify) {
142
- if (["WXMiniApp", "WXCustomerService"].includes(triggerSrc)) {
175
+ if (["WXMiniapp" /* MINI_APP */, "WXCustomerService" /* CUSTOM_SERVICE */].includes(
176
+ triggerSrc
177
+ )) {
143
178
  return true;
144
179
  }
145
180
  return wxVerify;
@@ -147,14 +182,15 @@ function needAsyncReply(triggerSrc, wxVerify) {
147
182
  function formatWeChatReplyMessage(callbackData, triggerSrc, content) {
148
183
  const createTime = Math.floor(Date.now() / 1e3);
149
184
  const finalContent = content || "\u62B1\u6B49\u6682\u65F6\u65E0\u6CD5\u5904\u7406\u8FD9\u4E2A\u7C7B\u578B\u7684\u6D88\u606F";
150
- if (triggerSrc === "WXCustomerService") {
185
+ if (triggerSrc === "WXCustomerService" /* CUSTOM_SERVICE */) {
151
186
  return {
152
187
  toUserName: callbackData.externalUserId || callbackData.fromUserName,
153
188
  fromUserName: callbackData.openKfId,
154
189
  openKfId: callbackData.openKfId,
155
190
  createTime,
156
191
  msgType: "text",
157
- content: finalContent
192
+ content: finalContent,
193
+ msgId: callbackData.msgId
158
194
  };
159
195
  }
160
196
  return {
@@ -162,7 +198,8 @@ function formatWeChatReplyMessage(callbackData, triggerSrc, content) {
162
198
  fromUserName: callbackData.toUserName || callbackData.ToUserName,
163
199
  createTime,
164
200
  msgType: "text",
165
- content: finalContent
201
+ content: finalContent,
202
+ msgId: callbackData.msgId
166
203
  };
167
204
  }
168
205
  function dealMsgData(originMsg, triggerSrc, wxVerify, botId) {
@@ -242,20 +279,57 @@ var import_agent_server = require("@cloudbase/agent-server");
242
279
  var import_agent_shared = require("@cloudbase/agent-shared");
243
280
  var import_client = require("@ag-ui/client");
244
281
  var import_agent_shared2 = require("@cloudbase/agent-shared");
282
+ var import_aiagent_framework = require("@cloudbase/aiagent-framework");
283
+ function getServiceNameFromHostname(hostname) {
284
+ const parts = hostname.split("-");
285
+ let versionIdx = -1;
286
+ for (let i = parts.length - 1; i >= 0; i--) {
287
+ if (/^\d+$/.test(parts[i])) {
288
+ versionIdx = i;
289
+ break;
290
+ }
291
+ }
292
+ return versionIdx > 0 ? parts.slice(0, versionIdx).join("-") : hostname;
293
+ }
294
+ function getBotId(url, fallback = "agent-id") {
295
+ if (process.env.SCF_FUNCTIONNAME) {
296
+ return process.env.SCF_FUNCTIONNAME;
297
+ }
298
+ if (url) {
299
+ const parsedBotId = import_aiagent_framework.utils.parseBotId(url);
300
+ if (parsedBotId) {
301
+ return parsedBotId;
302
+ }
303
+ }
304
+ if (process.env.HOSTNAME) {
305
+ return getServiceNameFromHostname(process.env.HOSTNAME);
306
+ }
307
+ return fallback;
308
+ }
245
309
  function createWxMessageHandler(createAgent, options) {
246
310
  const { logger: parentLogger = import_agent_shared.noopLogger } = options ?? {};
247
311
  const adapterLogger = parentLogger.child?.({ component: "sendWXMessageAGUI" }) ?? parentLogger;
248
312
  return async (req, res) => {
249
313
  let cleanup = null;
314
+ let agent = void 0;
315
+ const { callbackData } = import_aiagent_framework.utils.transformKeysToCamelCase(req.body);
316
+ const { triggerSrc, wxVerify } = import_aiagent_framework.utils.parseWxEnvParam({
317
+ httpContext: {
318
+ headers: req.headers
319
+ }
320
+ });
321
+ const wxSendmessageInput = {
322
+ callbackData,
323
+ triggerSrc,
324
+ wxVerify
325
+ };
326
+ const requestId = (0, import_uuid.v4)();
327
+ const logger = adapterLogger.child?.({ requestId }) ?? adapterLogger;
328
+ const botId = getBotId(
329
+ `${req.protocol}://${req.get("host")}${req.originalUrl}`,
330
+ "agent-wx-send-message"
331
+ );
250
332
  try {
251
- const {
252
- callbackData,
253
- triggerSrc,
254
- wxVerify = false,
255
- botId = "default"
256
- } = req.body;
257
- const requestId = (0, import_uuid.v4)();
258
- const logger = adapterLogger.child?.({ requestId }) ?? adapterLogger;
259
333
  if (!callbackData || !triggerSrc) {
260
334
  return res.status(400).json({
261
335
  error: "Bad Request",
@@ -263,9 +337,11 @@ function createWxMessageHandler(createAgent, options) {
263
337
  });
264
338
  }
265
339
  logger.info?.("[WX] Received message:", { triggerSrc, wxVerify, botId });
266
- const { agent: unknownAgent, cleanup: agentCleanup } = await Promise.resolve(createAgent({ request: req }));
340
+ const { agent: unknownAgent, cleanup: agentCleanup } = await Promise.resolve(
341
+ createAgent({ request: req, options: { agentId: botId } })
342
+ );
267
343
  cleanup = agentCleanup ?? null;
268
- const agent = "toAGUIAgent" in unknownAgent ? unknownAgent.toAGUIAgent() : unknownAgent;
344
+ agent = "toAGUIAgent" in unknownAgent ? unknownAgent.toAGUIAgent() : unknownAgent;
269
345
  const { msgData, replyMsgData } = dealMsgData(
270
346
  callbackData,
271
347
  triggerSrc,
@@ -286,17 +362,12 @@ function createWxMessageHandler(createAgent, options) {
286
362
  );
287
363
  const voiceHandler = async (vBotId, vTriggerSrc, mediaId) => {
288
364
  try {
289
- const content2 = await agent?.aitools?.getWxMediaContent(
365
+ const result = await agent?.aitools?.getWxMediaContent(
290
366
  vBotId,
291
367
  vTriggerSrc,
292
368
  mediaId
293
369
  );
294
- if (content2) {
295
- return {
296
- content: content2
297
- };
298
- }
299
- return null;
370
+ return result || null;
300
371
  } catch {
301
372
  return null;
302
373
  }
@@ -353,7 +424,7 @@ function createWxMessageHandler(createAgent, options) {
353
424
  tools: [],
354
425
  context: [],
355
426
  forwardedProps: {
356
- wxSendmessageInput: req.body,
427
+ wxSendmessageInput,
357
428
  // Pass full msgData for history storage
358
429
  msgData,
359
430
  // Pass replay info with replyMsgData for assistant history
@@ -381,10 +452,34 @@ function createWxMessageHandler(createAgent, options) {
381
452
  formatWeChatReplyMessage(callbackData, triggerSrc, finalContent)
382
453
  );
383
454
  } catch (error) {
384
- console.error("[WX] Error processing message:", error);
455
+ logger.error?.("[WX] Error processing message:", error);
456
+ const message = error instanceof Error ? error.message : String(error);
457
+ try {
458
+ if (agent?.aitools?.sendWxClientMessage) {
459
+ const data = formatWeChatReplyMessage(
460
+ callbackData,
461
+ triggerSrc,
462
+ message
463
+ );
464
+ await agent.aitools.sendWxClientMessage(
465
+ agent.agentId || botId,
466
+ triggerSrc,
467
+ {
468
+ msgType: data.msgType,
469
+ touser: data.toUserName,
470
+ text: {
471
+ content: data.content
472
+ },
473
+ openKfId: data.openKfId,
474
+ msgId: data.msgId
475
+ }
476
+ );
477
+ }
478
+ } catch (e) {
479
+ }
385
480
  return res.status(500).json({
386
481
  error: "Internal Server Error",
387
- message: error instanceof Error ? error.message : String(error)
482
+ message
388
483
  });
389
484
  } finally {
390
485
  if (cleanup) cleanup();
@@ -392,27 +487,6 @@ function createWxMessageHandler(createAgent, options) {
392
487
  };
393
488
  }
394
489
 
395
- // src/types.ts
396
- var WeChatPlatform = /* @__PURE__ */ ((WeChatPlatform2) => {
397
- WeChatPlatform2["CUSTOM_SERVICE"] = "WXCustomerService";
398
- WeChatPlatform2["MINI_APP"] = "WXMiniApp";
399
- WeChatPlatform2["SERVICE"] = "WXService";
400
- WeChatPlatform2["SUBSCRIPTION"] = "WXSubscription";
401
- return WeChatPlatform2;
402
- })(WeChatPlatform || {});
403
- var MessageType = /* @__PURE__ */ ((MessageType2) => {
404
- MessageType2["TEXT"] = "text";
405
- MessageType2["IMAGE"] = "image";
406
- MessageType2["EVENT"] = "event";
407
- MessageType2["VOICE"] = "voice";
408
- return MessageType2;
409
- })(MessageType || {});
410
- var WeChatSendMode = /* @__PURE__ */ ((WeChatSendMode2) => {
411
- WeChatSendMode2["LOCAL"] = "local";
412
- WeChatSendMode2["AITOOLS"] = "aitools";
413
- return WeChatSendMode2;
414
- })(WeChatSendMode || {});
415
-
416
490
  // src/token-manager.ts
417
491
  var TokenManager = class {
418
492
  constructor() {
@@ -560,7 +634,7 @@ var PlatformRouter = class {
560
634
  switch (config.platform) {
561
635
  case "WXCustomerService" /* CUSTOM_SERVICE */:
562
636
  return this.sendToCustomService(message, accessToken, config);
563
- case "WXMiniApp" /* MINI_APP */:
637
+ case "WXMiniapp" /* MINI_APP */:
564
638
  return this.sendToMiniApp(message, accessToken);
565
639
  case "WXService" /* SERVICE */:
566
640
  case "WXSubscription" /* SUBSCRIPTION */:
@@ -744,7 +818,7 @@ var WeChatHistoryManager = class _WeChatHistoryManager {
744
818
  await db.createCollection(this.collectionName);
745
819
  this.collectionReady = true;
746
820
  } catch (error) {
747
- if (error?.code === -502005 || error?.message?.includes("already exists")) {
821
+ if (error?.code === "DATABASE_COLLECTION_ALREADY_EXIST") {
748
822
  this.collectionReady = true;
749
823
  } else {
750
824
  console.error(
@@ -808,9 +882,9 @@ var WeChatHistoryManager = class _WeChatHistoryManager {
808
882
  var getHistoryManager = WeChatHistoryManager.getInstance;
809
883
 
810
884
  // src/agent.ts
811
- var import_aiagent_framework = require("@cloudbase/aiagent-framework");
885
+ var import_aiagent_framework2 = require("@cloudbase/aiagent-framework");
812
886
  var import_crypto = require("crypto");
813
- var AITOOLS = import_aiagent_framework.aitools.AITools;
887
+ var AITOOLS = import_aiagent_framework2.aitools.AITools;
814
888
  var WeChatAgent = class extends import_client2.AbstractAgent {
815
889
  constructor(config) {
816
890
  super({
@@ -1039,7 +1113,7 @@ var WeChatAgent = class extends import_client2.AbstractAgent {
1039
1113
  try {
1040
1114
  const needAsyncReply2 = input.forwardedProps?.replay.needAsyncReply ?? true;
1041
1115
  if (needAsyncReply2) {
1042
- const sendMode = this.wechatConfig.sendMode || "local" /* LOCAL */;
1116
+ const sendMode = this.wechatConfig.sendMode || "aitools" /* AITOOLS */;
1043
1117
  if (sendMode === "aitools" /* AITOOLS */) {
1044
1118
  await this.sendViaAITools(content, input);
1045
1119
  } else {
@@ -1104,15 +1178,19 @@ var WeChatAgent = class extends import_client2.AbstractAgent {
1104
1178
  return;
1105
1179
  }
1106
1180
  const triggerSrc = wxSendmessageInput.triggerSrc || this.wechatConfig.platform;
1107
- await this.aitools.sendMessageToClient(triggerSrc, {
1108
- msgType: toWxMsgData.msgType,
1109
- touser: toWxMsgData.toUserName,
1110
- text: {
1111
- content: toWxMsgData.content
1112
- },
1113
- openKfId: toWxMsgData.openKfId,
1114
- msgId: toWxMsgData.msgId
1115
- });
1181
+ await this.aitools.sendWxClientMessage(
1182
+ this.agentId || "agent",
1183
+ triggerSrc,
1184
+ {
1185
+ msgType: toWxMsgData.msgType,
1186
+ touser: toWxMsgData.toUserName,
1187
+ text: {
1188
+ content: toWxMsgData.content
1189
+ },
1190
+ openKfId: toWxMsgData.openKfId,
1191
+ msgId: toWxMsgData.msgId || ""
1192
+ }
1193
+ );
1116
1194
  }
1117
1195
  /**
1118
1196
  * Format reply message for WeChat HTTP response (sync mode)