@ai-setting/roy-agent-core 1.7.31 → 1.7.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/env/event-source/index.js +3 -3
- package/dist/env/index.js +5 -5
- package/dist/env/plugin/index.js +7 -5
- package/dist/env/task/plugins/index.js +2 -2
- package/dist/index.js +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-06wbc8km.js → roy-agent-core-6f7cjzem.js} +23 -8
- package/dist/shared/@ai-setting/{roy-agent-core-0ra1gtn9.js → roy-agent-core-bt7mg8j5.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-vqexb6am.js → roy-agent-core-jq8rmmm6.js} +23 -7
- package/dist/shared/@ai-setting/{roy-agent-core-1ht06trt.js → roy-agent-core-mssk8f0g.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-rmn29nrh.js +34 -0
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-az13yzmc.js +0 -11
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
larkCliHandler,
|
|
12
12
|
resolveBountyIMSystemPrompt,
|
|
13
13
|
timerHandler
|
|
14
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
14
|
+
} from "../../shared/@ai-setting/roy-agent-core-jq8rmmm6.js";
|
|
15
15
|
import"../../shared/@ai-setting/roy-agent-core-0nz53t5v.js";
|
|
16
16
|
import {
|
|
17
17
|
BUILT_IN_EVENT_SOURCE_TYPES,
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
isValidEventSourceType,
|
|
23
23
|
validateEventSourceConfig
|
|
24
24
|
} from "../../shared/@ai-setting/roy-agent-core-ds5f75pg.js";
|
|
25
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
25
|
+
import"../../shared/@ai-setting/roy-agent-core-6f7cjzem.js";
|
|
26
26
|
import"../../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
|
|
27
27
|
import"../../shared/@ai-setting/roy-agent-core-skqt40yy.js";
|
|
28
28
|
import"../../shared/@ai-setting/roy-agent-core-1df0grva.js";
|
|
@@ -30,7 +30,7 @@ import"../../shared/@ai-setting/roy-agent-core-jdvgzf2y.js";
|
|
|
30
30
|
import"../../shared/@ai-setting/roy-agent-core-jrj30vq3.js";
|
|
31
31
|
import"../../shared/@ai-setting/roy-agent-core-jbc1t62x.js";
|
|
32
32
|
import"../../shared/@ai-setting/roy-agent-core-e25xkv53.js";
|
|
33
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
33
|
+
import"../../shared/@ai-setting/roy-agent-core-rmn29nrh.js";
|
|
34
34
|
import"../../shared/@ai-setting/roy-agent-core-7hh0brvs.js";
|
|
35
35
|
import"../../shared/@ai-setting/roy-agent-core-m725wp1x.js";
|
|
36
36
|
import"../../shared/@ai-setting/roy-agent-core-sf4bjgwz.js";
|
package/dist/env/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseEnvironment
|
|
3
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
3
|
+
} from "../shared/@ai-setting/roy-agent-core-mssk8f0g.js";
|
|
4
4
|
import {
|
|
5
5
|
TaskComponent
|
|
6
6
|
} from "../shared/@ai-setting/roy-agent-core-m09a4xwh.js";
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
EventSourceComponent,
|
|
16
16
|
builtInHandlers,
|
|
17
17
|
larkCliHandler
|
|
18
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
18
|
+
} from "../shared/@ai-setting/roy-agent-core-jq8rmmm6.js";
|
|
19
19
|
import"../shared/@ai-setting/roy-agent-core-0nz53t5v.js";
|
|
20
20
|
import {
|
|
21
21
|
EventSourceInitHooks,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
isValidEventSourceType,
|
|
25
25
|
validateEventSourceConfig
|
|
26
26
|
} from "../shared/@ai-setting/roy-agent-core-ds5f75pg.js";
|
|
27
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
27
|
+
import"../shared/@ai-setting/roy-agent-core-6f7cjzem.js";
|
|
28
28
|
import"../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
|
|
29
29
|
import"../shared/@ai-setting/roy-agent-core-skqt40yy.js";
|
|
30
30
|
import {
|
|
@@ -69,8 +69,8 @@ import"../shared/@ai-setting/roy-agent-core-c1v263jn.js";
|
|
|
69
69
|
import"../shared/@ai-setting/roy-agent-core-e25xkv53.js";
|
|
70
70
|
import {
|
|
71
71
|
PluginComponent
|
|
72
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
73
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
72
|
+
} from "../shared/@ai-setting/roy-agent-core-bt7mg8j5.js";
|
|
73
|
+
import"../shared/@ai-setting/roy-agent-core-rmn29nrh.js";
|
|
74
74
|
import {
|
|
75
75
|
McpComponent
|
|
76
76
|
} from "../shared/@ai-setting/roy-agent-core-gjnhkemk.js";
|
package/dist/env/plugin/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EventBusNotificationChannel,
|
|
3
3
|
PluginComponent
|
|
4
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
4
|
+
} from "../../shared/@ai-setting/roy-agent-core-bt7mg8j5.js";
|
|
5
5
|
import {
|
|
6
|
-
BasePlugin
|
|
7
|
-
|
|
6
|
+
BasePlugin,
|
|
7
|
+
normalizeLarkAtMentions
|
|
8
|
+
} from "../../shared/@ai-setting/roy-agent-core-rmn29nrh.js";
|
|
8
9
|
import"../../shared/@ai-setting/roy-agent-core-m725wp1x.js";
|
|
9
10
|
import"../../shared/@ai-setting/roy-agent-core-sf4bjgwz.js";
|
|
10
11
|
import"../../shared/@ai-setting/roy-agent-core-g772q3gf.js";
|
|
@@ -64,6 +65,7 @@ ${options.content}`;
|
|
|
64
65
|
return new Promise((resolve, reject) => {
|
|
65
66
|
const { chatId, messageId, content, profile } = options;
|
|
66
67
|
let args;
|
|
68
|
+
const normalizedContent = normalizeLarkAtMentions(content);
|
|
67
69
|
if (messageId) {
|
|
68
70
|
args = [
|
|
69
71
|
"im",
|
|
@@ -71,7 +73,7 @@ ${options.content}`;
|
|
|
71
73
|
"--message-id",
|
|
72
74
|
messageId,
|
|
73
75
|
"--markdown",
|
|
74
|
-
|
|
76
|
+
normalizedContent,
|
|
75
77
|
"--as",
|
|
76
78
|
"bot"
|
|
77
79
|
];
|
|
@@ -82,7 +84,7 @@ ${options.content}`;
|
|
|
82
84
|
"--chat-id",
|
|
83
85
|
chatId,
|
|
84
86
|
"--markdown",
|
|
85
|
-
|
|
87
|
+
normalizedContent
|
|
86
88
|
];
|
|
87
89
|
}
|
|
88
90
|
if (profile) {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
formatExtractorInput,
|
|
11
11
|
formatExtractorInputFromDescription,
|
|
12
12
|
parseExtractorOutput
|
|
13
|
-
} from "../../../shared/@ai-setting/roy-agent-core-
|
|
13
|
+
} from "../../../shared/@ai-setting/roy-agent-core-6f7cjzem.js";
|
|
14
14
|
import"../../../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
|
|
15
15
|
import"../../../shared/@ai-setting/roy-agent-core-skqt40yy.js";
|
|
16
16
|
import"../../../shared/@ai-setting/roy-agent-core-1df0grva.js";
|
|
@@ -18,7 +18,7 @@ import"../../../shared/@ai-setting/roy-agent-core-jdvgzf2y.js";
|
|
|
18
18
|
import"../../../shared/@ai-setting/roy-agent-core-jrj30vq3.js";
|
|
19
19
|
import"../../../shared/@ai-setting/roy-agent-core-jbc1t62x.js";
|
|
20
20
|
import"../../../shared/@ai-setting/roy-agent-core-e25xkv53.js";
|
|
21
|
-
import"../../../shared/@ai-setting/roy-agent-core-
|
|
21
|
+
import"../../../shared/@ai-setting/roy-agent-core-rmn29nrh.js";
|
|
22
22
|
import"../../../shared/@ai-setting/roy-agent-core-m2pxg5d8.js";
|
|
23
23
|
import"../../../shared/@ai-setting/roy-agent-core-7p6rny5m.js";
|
|
24
24
|
import"../../../shared/@ai-setting/roy-agent-core-38rtrpk3.js";
|
package/dist/index.js
CHANGED
|
@@ -66,7 +66,7 @@ import {
|
|
|
66
66
|
BaseEnvironment,
|
|
67
67
|
generateDescendingId,
|
|
68
68
|
generateId
|
|
69
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
69
|
+
} from "./shared/@ai-setting/roy-agent-core-mssk8f0g.js";
|
|
70
70
|
import {
|
|
71
71
|
TaskComponent
|
|
72
72
|
} from "./shared/@ai-setting/roy-agent-core-m09a4xwh.js";
|
|
@@ -92,7 +92,7 @@ import {
|
|
|
92
92
|
larkCliHandler,
|
|
93
93
|
resolveBountyIMSystemPrompt,
|
|
94
94
|
timerHandler
|
|
95
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
95
|
+
} from "./shared/@ai-setting/roy-agent-core-jq8rmmm6.js";
|
|
96
96
|
import {
|
|
97
97
|
LogTraceComponent,
|
|
98
98
|
LogTraceConfigSchema
|
|
@@ -109,7 +109,7 @@ import {
|
|
|
109
109
|
import {
|
|
110
110
|
TaskTagPlugin,
|
|
111
111
|
createAutoTaskPlugin
|
|
112
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
112
|
+
} from "./shared/@ai-setting/roy-agent-core-6f7cjzem.js";
|
|
113
113
|
import {
|
|
114
114
|
TaskHookPoints
|
|
115
115
|
} from "./shared/@ai-setting/roy-agent-core-1pg0fepg.js";
|
|
@@ -189,10 +189,10 @@ import {
|
|
|
189
189
|
} from "./shared/@ai-setting/roy-agent-core-e25xkv53.js";
|
|
190
190
|
import {
|
|
191
191
|
PluginComponent
|
|
192
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
192
|
+
} from "./shared/@ai-setting/roy-agent-core-bt7mg8j5.js";
|
|
193
193
|
import {
|
|
194
194
|
BasePlugin
|
|
195
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
195
|
+
} from "./shared/@ai-setting/roy-agent-core-rmn29nrh.js";
|
|
196
196
|
import {
|
|
197
197
|
McpComponent
|
|
198
198
|
} from "./shared/@ai-setting/roy-agent-core-gjnhkemk.js";
|
|
@@ -11,8 +11,9 @@ import {
|
|
|
11
11
|
enqueueToAddFakeUserMessage
|
|
12
12
|
} from "./roy-agent-core-jbc1t62x.js";
|
|
13
13
|
import {
|
|
14
|
-
BasePlugin
|
|
15
|
-
|
|
14
|
+
BasePlugin,
|
|
15
|
+
normalizeLarkAtMentions
|
|
16
|
+
} from "./roy-agent-core-rmn29nrh.js";
|
|
16
17
|
import {
|
|
17
18
|
init_context
|
|
18
19
|
} from "./roy-agent-core-m2pxg5d8.js";
|
|
@@ -556,6 +557,7 @@ ${content}`;
|
|
|
556
557
|
return new Promise((resolve, reject) => {
|
|
557
558
|
const { chatId, messageId, content, profile } = options;
|
|
558
559
|
let args;
|
|
560
|
+
const normalizedContent = normalizeLarkAtMentions(content);
|
|
559
561
|
if (messageId) {
|
|
560
562
|
args = [
|
|
561
563
|
"im",
|
|
@@ -563,7 +565,7 @@ ${content}`;
|
|
|
563
565
|
"--message-id",
|
|
564
566
|
messageId,
|
|
565
567
|
"--markdown",
|
|
566
|
-
|
|
568
|
+
normalizedContent,
|
|
567
569
|
"--as",
|
|
568
570
|
"bot"
|
|
569
571
|
];
|
|
@@ -574,7 +576,7 @@ ${content}`;
|
|
|
574
576
|
"--chat-id",
|
|
575
577
|
chatId,
|
|
576
578
|
"--markdown",
|
|
577
|
-
|
|
579
|
+
normalizedContent
|
|
578
580
|
];
|
|
579
581
|
}
|
|
580
582
|
if (profile) {
|
|
@@ -830,6 +832,7 @@ class PerTaskGroupChatPlugin {
|
|
|
830
832
|
descriptionTemplate: config.descriptionTemplate ?? "roy-agent task #{id} - #{project_path}",
|
|
831
833
|
botAppIds: config.botAppIds ?? [],
|
|
832
834
|
inviteUserIds: config.inviteUserIds ?? ["sender"],
|
|
835
|
+
defaultInviteUserIds: config.defaultInviteUserIds ?? [],
|
|
833
836
|
fallbackToMain: config.fallbackToMain ?? true,
|
|
834
837
|
operationThrottleMs: config.operationThrottleMs ?? 5000,
|
|
835
838
|
disableSubTaskSkip: config.disableSubTaskSkip ?? false,
|
|
@@ -1137,7 +1140,7 @@ class PerTaskGroupChatPlugin {
|
|
|
1137
1140
|
"--chat-id",
|
|
1138
1141
|
opts.chatId,
|
|
1139
1142
|
"--markdown",
|
|
1140
|
-
opts.content,
|
|
1143
|
+
normalizeLarkAtMentions(opts.content),
|
|
1141
1144
|
"--as",
|
|
1142
1145
|
"bot"
|
|
1143
1146
|
];
|
|
@@ -1174,9 +1177,9 @@ class PerTaskGroupChatPlugin {
|
|
|
1174
1177
|
}
|
|
1175
1178
|
sendToMain(replyChannel, opts) {
|
|
1176
1179
|
return new Promise((resolve, reject) => {
|
|
1177
|
-
const message = `${opts.title}
|
|
1180
|
+
const message = normalizeLarkAtMentions(`${opts.title}
|
|
1178
1181
|
|
|
1179
|
-
${opts.content}
|
|
1182
|
+
${opts.content}`);
|
|
1180
1183
|
const args = replyChannel.messageId ? ["im", "+messages-reply", "--message-id", replyChannel.messageId, "--markdown", message, "--as", "bot"] : ["im", "+messages-send", "--chat-id", replyChannel.chatId, "--markdown", message];
|
|
1181
1184
|
if (opts.profile) {
|
|
1182
1185
|
args.unshift("--profile", opts.profile);
|
|
@@ -1258,6 +1261,15 @@ ${opts.content}`;
|
|
|
1258
1261
|
}
|
|
1259
1262
|
resolveUserIds(replyChannel) {
|
|
1260
1263
|
const ids = new Set;
|
|
1264
|
+
if (this.config.defaultInviteUserIds && this.config.defaultInviteUserIds.length > 0) {
|
|
1265
|
+
for (const id of this.config.defaultInviteUserIds) {
|
|
1266
|
+
if (id && id !== "sender" && id.startsWith("ou_")) {
|
|
1267
|
+
ids.add(id);
|
|
1268
|
+
} else if (id && id !== "sender") {
|
|
1269
|
+
logger4.debug(`resolveUserIds[${this.pluginName}]: skip non-open_id in defaultInviteUserIds: "${id}"`);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1261
1273
|
if (this.config.inviteUserIds && this.config.inviteUserIds.length > 0) {
|
|
1262
1274
|
for (const id of this.config.inviteUserIds) {
|
|
1263
1275
|
if (id !== "sender" && id)
|
|
@@ -1270,12 +1282,15 @@ ${opts.content}`;
|
|
|
1270
1282
|
ids.add(senderId);
|
|
1271
1283
|
}
|
|
1272
1284
|
}
|
|
1273
|
-
if (ids.size === 0) {
|
|
1285
|
+
if (ids.size === 0 && this.config.inviteUserIds?.includes("sender")) {
|
|
1274
1286
|
const alsUserId = getEnvContextOrEmpty().userId;
|
|
1275
1287
|
if (alsUserId && alsUserId.startsWith("ou_")) {
|
|
1276
1288
|
ids.add(alsUserId);
|
|
1277
1289
|
}
|
|
1278
1290
|
}
|
|
1291
|
+
if (isPluginDebugEnabled()) {
|
|
1292
|
+
logger4.debug(`resolveUserIds[${this.pluginName}]: ` + `defaultInviteUserIds=${JSON.stringify(this.config.defaultInviteUserIds)} ` + `inviteUserIds=${JSON.stringify(this.config.inviteUserIds)} ` + `replyChannel.userId=${replyChannel?.userId ?? "(none)"} ` + `→ final userIds=${JSON.stringify(Array.from(ids))}`);
|
|
1293
|
+
}
|
|
1279
1294
|
return Array.from(ids);
|
|
1280
1295
|
}
|
|
1281
1296
|
isSubTask(task) {
|
|
@@ -2,7 +2,10 @@ import {
|
|
|
2
2
|
TaskTagPlugin,
|
|
3
3
|
createLarkCliTaskNotifyHook,
|
|
4
4
|
createPerTaskGroupChatPlugin
|
|
5
|
-
} from "./roy-agent-core-
|
|
5
|
+
} from "./roy-agent-core-6f7cjzem.js";
|
|
6
|
+
import {
|
|
7
|
+
normalizeLarkAtMentions
|
|
8
|
+
} from "./roy-agent-core-rmn29nrh.js";
|
|
6
9
|
import {
|
|
7
10
|
envKeyToConfigKey
|
|
8
11
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
@@ -906,7 +909,10 @@ function extractMetadata(rawEvent, eventType) {
|
|
|
906
909
|
const larkInnerEvent = event.event;
|
|
907
910
|
const header = larkInnerEvent?.header || event.header;
|
|
908
911
|
const sender = larkInnerEvent?.sender || event.sender;
|
|
909
|
-
|
|
912
|
+
let senderId = sender?.sender_id;
|
|
913
|
+
if (!senderId && typeof event.sender_id === "string") {
|
|
914
|
+
senderId = event.sender_id;
|
|
915
|
+
}
|
|
910
916
|
let messageData;
|
|
911
917
|
if (larkInnerEvent?.message) {
|
|
912
918
|
messageData = larkInnerEvent.message;
|
|
@@ -932,7 +938,9 @@ function extractMetadata(rawEvent, eventType) {
|
|
|
932
938
|
metadata.messageId = messageData.message_id;
|
|
933
939
|
metadata.messageType = messageData.message_type;
|
|
934
940
|
}
|
|
935
|
-
if (senderId) {
|
|
941
|
+
if (typeof senderId === "string") {
|
|
942
|
+
metadata.senderId = senderId;
|
|
943
|
+
} else if (senderId) {
|
|
936
944
|
metadata.senderId = senderId.open_id || senderId.user_id || senderId.union_id;
|
|
937
945
|
}
|
|
938
946
|
let recommendedAction;
|
|
@@ -947,6 +955,7 @@ function extractMetadata(rawEvent, eventType) {
|
|
|
947
955
|
});
|
|
948
956
|
}
|
|
949
957
|
const profile = event.profile;
|
|
958
|
+
const senderOpenId = typeof senderId === "string" ? senderId : senderId?.open_id;
|
|
950
959
|
const replyChannel = {
|
|
951
960
|
type: "lark-cli",
|
|
952
961
|
appId: metadata.appId,
|
|
@@ -954,7 +963,7 @@ function extractMetadata(rawEvent, eventType) {
|
|
|
954
963
|
chatId: messageData?.chat_id,
|
|
955
964
|
messageId: messageData?.message_id,
|
|
956
965
|
params: {
|
|
957
|
-
userId:
|
|
966
|
+
userId: senderOpenId
|
|
958
967
|
}
|
|
959
968
|
};
|
|
960
969
|
return { metadata, replyChannel, recommendedAction };
|
|
@@ -1367,6 +1376,12 @@ class LarkCliInstance {
|
|
|
1367
1376
|
const message = innerEvent?.message || event.message;
|
|
1368
1377
|
const sender = innerEvent?.sender || event.sender || message?.sender;
|
|
1369
1378
|
const senderId = sender?.sender_id;
|
|
1379
|
+
if (typeof event.sender_id === "string") {
|
|
1380
|
+
return event.sender_id;
|
|
1381
|
+
}
|
|
1382
|
+
if (typeof senderId === "string") {
|
|
1383
|
+
return senderId;
|
|
1384
|
+
}
|
|
1370
1385
|
return senderId?.open_id || senderId?.user_id || senderId?.union_id || "unknown";
|
|
1371
1386
|
}
|
|
1372
1387
|
buildReplyChannel(replyChannel) {
|
|
@@ -1425,14 +1440,15 @@ class LarkCliInstance {
|
|
|
1425
1440
|
async sendLarkMessage(options) {
|
|
1426
1441
|
return new Promise((resolve, reject) => {
|
|
1427
1442
|
const { chatId, userId, messageId, content, as: identity, format = "text", profile } = options;
|
|
1443
|
+
const normalizedContent = normalizeLarkAtMentions(content);
|
|
1428
1444
|
const contentFlag = format === "markdown" ? "--markdown" : "--text";
|
|
1429
1445
|
const args = ["im"];
|
|
1430
1446
|
if (messageId) {
|
|
1431
|
-
args.push("+messages-reply", "--message-id", messageId, "--as", identity, contentFlag,
|
|
1447
|
+
args.push("+messages-reply", "--message-id", messageId, "--as", identity, contentFlag, normalizedContent);
|
|
1432
1448
|
} else if (chatId) {
|
|
1433
|
-
args.push("+messages-send", "--chat-id", chatId, "--as", identity, contentFlag,
|
|
1449
|
+
args.push("+messages-send", "--chat-id", chatId, "--as", identity, contentFlag, normalizedContent);
|
|
1434
1450
|
} else if (userId) {
|
|
1435
|
-
args.push("+messages-send", "--user-id", userId, "--as", identity, contentFlag,
|
|
1451
|
+
args.push("+messages-send", "--user-id", userId, "--as", identity, contentFlag, normalizedContent);
|
|
1436
1452
|
} else {
|
|
1437
1453
|
reject(new Error("No target specified for sending message"));
|
|
1438
1454
|
return;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/env/plugin/types.ts
|
|
2
|
+
class BasePlugin {
|
|
3
|
+
version = "1.0.0";
|
|
4
|
+
description;
|
|
5
|
+
priority = 0;
|
|
6
|
+
constructor() {}
|
|
7
|
+
init(env) {}
|
|
8
|
+
dispose() {}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/env/lark-mention-utils.ts
|
|
12
|
+
var SELF_CLOSING_AT_RE = /<at\s+user_id\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s>]+))\s*\/\s*>/g;
|
|
13
|
+
function normalizeLarkAtMentions(content, nameMap) {
|
|
14
|
+
if (!content)
|
|
15
|
+
return content;
|
|
16
|
+
return content.replace(SELF_CLOSING_AT_RE, (_match, dq, sq, bare) => {
|
|
17
|
+
const userId = dq ?? sq ?? bare ?? "";
|
|
18
|
+
if (!userId)
|
|
19
|
+
return _match;
|
|
20
|
+
const displayName = nameMap?.get(userId);
|
|
21
|
+
if (displayName) {
|
|
22
|
+
return `<at user_id="${escapeXmlAttr(userId)}">${escapeXmlText(displayName)}</at>`;
|
|
23
|
+
}
|
|
24
|
+
return `<at user_id="${escapeXmlAttr(userId)}"></at>`;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function escapeXmlAttr(value) {
|
|
28
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
29
|
+
}
|
|
30
|
+
function escapeXmlText(value) {
|
|
31
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { BasePlugin, normalizeLarkAtMentions };
|
package/package.json
CHANGED