@yanhaidao/wecom 2.3.13 → 2.3.141
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 +148 -0
- package/changelog/v2.3.14.md +48 -0
- package/index.ts +4 -0
- package/package.json +3 -2
- package/src/agent/handler.event-filter.test.ts +15 -5
- package/src/agent/handler.ts +192 -48
- package/src/app/account-runtime.ts +1 -1
- package/src/app/index.ts +4 -0
- package/src/capability/agent/delivery-service.ts +16 -8
- package/src/capability/bot/fallback-delivery.ts +1 -1
- package/src/capability/bot/stream-orchestrator.ts +10 -10
- package/src/capability/doc/client.ts +1002 -0
- package/src/capability/doc/schema.ts +1500 -0
- package/src/capability/doc/tool.ts +1168 -0
- package/src/capability/doc/types.ts +408 -0
- package/src/channel.ts +1 -1
- package/src/outbound.ts +5 -5
- package/src/runtime/session-manager.ts +4 -4
- package/src/target.ts +3 -0
- package/src/transport/bot-webhook/active-reply.ts +4 -1
- package/src/transport/bot-ws/inbound.ts +2 -2
- package/src/transport/bot-ws/reply.test.ts +124 -56
- package/src/transport/bot-ws/reply.ts +121 -13
- package/src/transport/bot-ws/sdk-adapter.ts +1 -0
- package/src/types/runtime.ts +3 -0
|
@@ -2,9 +2,10 @@ import type { ResolvedAgentAccount } from "../../types/index.js";
|
|
|
2
2
|
import { resolveScopedWecomTarget } from "../../target.js";
|
|
3
3
|
import { deliverAgentApiMedia, deliverAgentApiText } from "../../transport/agent-api/delivery.js";
|
|
4
4
|
import { canUseAgentApiDelivery } from "./fallback-policy.js";
|
|
5
|
+
import { getWecomRuntime } from "../../runtime.js";
|
|
5
6
|
|
|
6
7
|
export class WecomAgentDeliveryService {
|
|
7
|
-
constructor(private readonly agent: ResolvedAgentAccount) {}
|
|
8
|
+
constructor(private readonly agent: ResolvedAgentAccount) { }
|
|
8
9
|
|
|
9
10
|
assertAvailable(): void {
|
|
10
11
|
if (!canUseAgentApiDelivery(this.agent)) {
|
|
@@ -35,8 +36,8 @@ export class WecomAgentDeliveryService {
|
|
|
35
36
|
);
|
|
36
37
|
throw new Error(
|
|
37
38
|
`企业微信(WeCom)Agent 主动发送不支持向群 chatId 发送(chatId=${target.chatid})。` +
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
`该路径在实际环境中经常失败(例如 86008:无权限访问该会话/会话由其他应用创建)。` +
|
|
40
|
+
`请改为发送给用户(userid / user:xxx),或由 Bot 模式在群内交付。`,
|
|
40
41
|
);
|
|
41
42
|
}
|
|
42
43
|
return target;
|
|
@@ -48,11 +49,18 @@ export class WecomAgentDeliveryService {
|
|
|
48
49
|
console.log(
|
|
49
50
|
`[wecom-agent-delivery] sendText account=${this.agent.accountId} to=${String(params.to ?? "")} len=${params.text.length}`,
|
|
50
51
|
);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
|
|
53
|
+
const runtime = getWecomRuntime();
|
|
54
|
+
const chunks = runtime.channel.text.chunkText(params.text, 2048);
|
|
55
|
+
|
|
56
|
+
for (const chunk of chunks) {
|
|
57
|
+
if (!chunk.trim()) continue;
|
|
58
|
+
await deliverAgentApiText({
|
|
59
|
+
agent: this.agent,
|
|
60
|
+
target,
|
|
61
|
+
text: chunk,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
async sendMedia(params: {
|
|
@@ -96,7 +96,7 @@ export async function sendAgentDmText(params: {
|
|
|
96
96
|
text: string;
|
|
97
97
|
core: PluginRuntime;
|
|
98
98
|
}): Promise<void> {
|
|
99
|
-
const chunks = params.core.channel.text.chunkText(params.text,
|
|
99
|
+
const chunks = params.core.channel.text.chunkText(params.text, 2048);
|
|
100
100
|
for (const chunk of chunks) {
|
|
101
101
|
const trimmed = chunk.trim();
|
|
102
102
|
if (!trimmed) continue;
|
|
@@ -201,7 +201,7 @@ export function createBotStreamOrchestrator(params: {
|
|
|
201
201
|
const targetAgentId = generateAgentId(chatType === "group" ? "group" : "dm", chatId, account.accountId);
|
|
202
202
|
route.agentId = targetAgentId;
|
|
203
203
|
route.sessionKey = `agent:${targetAgentId}:wecom:${account.accountId}:${chatType === "group" ? "group" : "dm"}:${chatId}`;
|
|
204
|
-
ensureDynamicAgentListed(targetAgentId, core).catch(() => {});
|
|
204
|
+
ensureDynamicAgentListed(targetAgentId, core).catch(() => { });
|
|
205
205
|
logVerbose(target, `dynamic agent routing: ${targetAgentId}, sessionKey=${route.sessionKey}`);
|
|
206
206
|
}
|
|
207
207
|
|
|
@@ -254,12 +254,12 @@ export function createBotStreamOrchestrator(params: {
|
|
|
254
254
|
|
|
255
255
|
const attachments = mediaPath
|
|
256
256
|
? [
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
257
|
+
{
|
|
258
|
+
name: media?.filename || "file",
|
|
259
|
+
mimeType: mediaType,
|
|
260
|
+
url: pathToFileURL(mediaPath).href,
|
|
261
|
+
},
|
|
262
|
+
]
|
|
263
263
|
: undefined;
|
|
264
264
|
|
|
265
265
|
const ctxPayload = core.channel.reply.finalizeInboundContext({
|
|
@@ -267,8 +267,8 @@ export function createBotStreamOrchestrator(params: {
|
|
|
267
267
|
RawBody: rawBody,
|
|
268
268
|
CommandBody: rawBody,
|
|
269
269
|
Attachments: attachments,
|
|
270
|
-
From: chatType === "group" ? `wecom:group:${chatId}` : `wecom:${userId}`,
|
|
271
|
-
To: `wecom:${chatId}`,
|
|
270
|
+
From: chatType === "group" ? `wecom:group:${chatId}` : `wecom:user:${userId}`,
|
|
271
|
+
To: chatType === "group" ? `wecom:group:${chatId}` : `wecom:user:${chatId}`,
|
|
272
272
|
SessionKey: route.sessionKey,
|
|
273
273
|
AccountId: route.accountId,
|
|
274
274
|
ChatType: chatType,
|
|
@@ -280,7 +280,7 @@ export function createBotStreamOrchestrator(params: {
|
|
|
280
280
|
MessageSid: msg.msgid,
|
|
281
281
|
CommandAuthorized: commandAuthorized,
|
|
282
282
|
OriginatingChannel: "wecom",
|
|
283
|
-
OriginatingTo: `wecom:${chatId}`,
|
|
283
|
+
OriginatingTo: chatType === "group" ? `wecom:group:${chatId}` : `wecom:user:${chatId}`,
|
|
284
284
|
MediaPath: mediaPath,
|
|
285
285
|
MediaType: mediaType,
|
|
286
286
|
MediaUrl: mediaPath,
|