aai-lark-bridge 0.2.42 → 0.2.43
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/LICENSE +21 -0
- package/dist/cli.js +100 -1
- package/dist/cli.js.map +1 -1
- package/package.json +7 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lark Channel Bridge contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Command } from "commander";
|
|
|
4
4
|
// package.json
|
|
5
5
|
var package_default = {
|
|
6
6
|
name: "aai-lark-bridge",
|
|
7
|
-
version: "0.2.
|
|
7
|
+
version: "0.2.43",
|
|
8
8
|
description: "Lark AI Native Bridge - Lark\u57FA\u7840\u8BBE\u65BD\u5C42\u548CCLI\u96C6\u6210",
|
|
9
9
|
type: "module",
|
|
10
10
|
main: "./dist/index.js",
|
|
@@ -15332,6 +15332,73 @@ async function removeReaction(channel, messageId, reactionId) {
|
|
|
15332
15332
|
}
|
|
15333
15333
|
}
|
|
15334
15334
|
|
|
15335
|
+
// src/bridge/bot/reaction-confirm.ts
|
|
15336
|
+
var POSITIVE_EMOJIS = /* @__PURE__ */ new Set(["OK", "THUMBSUP", "DONE", "JIAYI", "LGTM"]);
|
|
15337
|
+
var CONFIRM_WINDOW_MS = 45 * 6e4;
|
|
15338
|
+
var SCOPE_MAX = 500;
|
|
15339
|
+
function isConfirmQuestion(text) {
|
|
15340
|
+
const tail = text.trim().split(/[。!!\n]/).map((s) => s.trim()).filter(Boolean).pop() ?? "";
|
|
15341
|
+
return /[??]$/.test(tail) && /吗|是否|要不要|可不可以|对不对|行不行|可以不/.test(tail);
|
|
15342
|
+
}
|
|
15343
|
+
var ReactionConfirmer = class {
|
|
15344
|
+
constructor(now = Date.now) {
|
|
15345
|
+
this.now = now;
|
|
15346
|
+
}
|
|
15347
|
+
now;
|
|
15348
|
+
byUserMsg = /* @__PURE__ */ new Map();
|
|
15349
|
+
latestByScope = /* @__PURE__ */ new Map();
|
|
15350
|
+
used = /* @__PURE__ */ new Set();
|
|
15351
|
+
/** 一批用户消息开始跑时登记:该 scope 里 bot 之后的回复,都是对这条消息的回复。 */
|
|
15352
|
+
noteHandled(scope, msg) {
|
|
15353
|
+
const prev = this.latestByScope.get(scope);
|
|
15354
|
+
if (prev) this.byUserMsg.delete(prev);
|
|
15355
|
+
this.byUserMsg.set(msg.messageId, { scope, msg });
|
|
15356
|
+
this.latestByScope.set(scope, msg.messageId);
|
|
15357
|
+
while (this.latestByScope.size > SCOPE_MAX) {
|
|
15358
|
+
const oldest = this.latestByScope.keys().next().value;
|
|
15359
|
+
const id = this.latestByScope.get(oldest);
|
|
15360
|
+
this.latestByScope.delete(oldest);
|
|
15361
|
+
if (id) this.byUserMsg.delete(id);
|
|
15362
|
+
}
|
|
15363
|
+
}
|
|
15364
|
+
async handle(evt, channel) {
|
|
15365
|
+
const reject4 = (reason) => {
|
|
15366
|
+
log.info("reaction-confirm", "ignored", { reason, messageId: evt.messageId });
|
|
15367
|
+
return void 0;
|
|
15368
|
+
};
|
|
15369
|
+
if (evt.action !== "added") return reject4("not-added");
|
|
15370
|
+
if (!POSITIVE_EMOJIS.has(evt.emojiType)) return reject4("not-positive");
|
|
15371
|
+
if (this.used.has(evt.messageId)) return reject4("already-used");
|
|
15372
|
+
let bot;
|
|
15373
|
+
try {
|
|
15374
|
+
bot = await channel.fetchMessage(evt.messageId);
|
|
15375
|
+
} catch (err) {
|
|
15376
|
+
log.warn("reaction-confirm", "fetch-failed", { messageId: evt.messageId, err: String(err) });
|
|
15377
|
+
return void 0;
|
|
15378
|
+
}
|
|
15379
|
+
if (!bot) return reject4("message-not-found");
|
|
15380
|
+
if (bot.senderIsBot !== true) return reject4("not-bot-message");
|
|
15381
|
+
const parentId = bot.replyToMessageId;
|
|
15382
|
+
const handled = parentId ? this.byUserMsg.get(parentId) : void 0;
|
|
15383
|
+
if (!handled || !parentId) return reject4("not-reply-to-handled-message");
|
|
15384
|
+
if (this.latestByScope.get(handled.scope) !== parentId) return reject4("not-latest");
|
|
15385
|
+
if (handled.msg.chatId !== bot.chatId) return reject4("chat-mismatch");
|
|
15386
|
+
if (evt.operator.openId !== handled.msg.senderId) return reject4("not-asker");
|
|
15387
|
+
if (!isConfirmQuestion(bot.content)) return reject4("not-a-question");
|
|
15388
|
+
const t = this.now();
|
|
15389
|
+
if (t - handled.msg.createTime > CONFIRM_WINDOW_MS) return reject4("expired");
|
|
15390
|
+
this.used.add(evt.messageId);
|
|
15391
|
+
if (this.used.size > 1e3) this.used.delete(this.used.values().next().value);
|
|
15392
|
+
const msg = {
|
|
15393
|
+
...handled.msg,
|
|
15394
|
+
content: `\u53EF\u4EE5\uFF08\u7528\u6237\u70B9\u4E86 ${evt.emojiType} \u8868\u60C5\u786E\u8BA4\uFF09`,
|
|
15395
|
+
resources: [],
|
|
15396
|
+
createTime: t
|
|
15397
|
+
};
|
|
15398
|
+
return { scope: handled.scope, msg };
|
|
15399
|
+
}
|
|
15400
|
+
};
|
|
15401
|
+
|
|
15335
15402
|
// src/bridge/bot/channel-registry.ts
|
|
15336
15403
|
var active2 = /* @__PURE__ */ new Map();
|
|
15337
15404
|
function registerChannel(profile2) {
|
|
@@ -15891,6 +15958,7 @@ async function startChannel(deps) {
|
|
|
15891
15958
|
}) : void 0;
|
|
15892
15959
|
const activePolicyFingerprints = /* @__PURE__ */ new Map();
|
|
15893
15960
|
const lastRunModelByScope = /* @__PURE__ */ new Map();
|
|
15961
|
+
const reactionConfirmer = new ReactionConfirmer();
|
|
15894
15962
|
const cotClient = new CotClient({
|
|
15895
15963
|
tenant: cfg.accounts.app.tenant,
|
|
15896
15964
|
appId: cfg.accounts.app.id,
|
|
@@ -15989,6 +16057,7 @@ async function startChannel(deps) {
|
|
|
15989
16057
|
callbackAuth,
|
|
15990
16058
|
activePolicyFingerprints,
|
|
15991
16059
|
lastRunModelByScope,
|
|
16060
|
+
reactionConfirmer,
|
|
15992
16061
|
scope,
|
|
15993
16062
|
mode
|
|
15994
16063
|
});
|
|
@@ -16033,6 +16102,34 @@ async function startChannel(deps) {
|
|
|
16033
16102
|
})
|
|
16034
16103
|
).catch((err) => log.fail("intake", err));
|
|
16035
16104
|
},
|
|
16105
|
+
reaction: async (evt) => {
|
|
16106
|
+
markInbound("reaction");
|
|
16107
|
+
const hit = await reactionConfirmer.handle(evt, channel).catch((err) => {
|
|
16108
|
+
log.fail("reaction-confirm", err);
|
|
16109
|
+
return void 0;
|
|
16110
|
+
});
|
|
16111
|
+
if (!hit) return;
|
|
16112
|
+
log.info("reaction-confirm", "accepted", { scope: hit.scope, emoji: evt.emojiType, msgId: hit.msg.messageId });
|
|
16113
|
+
await withTrace(
|
|
16114
|
+
{ chatId: hit.msg.chatId, msgId: hit.msg.messageId },
|
|
16115
|
+
() => intakeMessage({
|
|
16116
|
+
channel,
|
|
16117
|
+
agent,
|
|
16118
|
+
sessions: sessions2,
|
|
16119
|
+
sessionCatalog,
|
|
16120
|
+
workspaces,
|
|
16121
|
+
activeRuns,
|
|
16122
|
+
pending,
|
|
16123
|
+
recent: recentDm,
|
|
16124
|
+
msg: hit.msg,
|
|
16125
|
+
controls,
|
|
16126
|
+
chatModeCache,
|
|
16127
|
+
logThreadModeOverride,
|
|
16128
|
+
executor,
|
|
16129
|
+
pool
|
|
16130
|
+
})
|
|
16131
|
+
).catch((err) => log.fail("intake", err));
|
|
16132
|
+
},
|
|
16036
16133
|
reject: (evt) => {
|
|
16037
16134
|
markInbound("reject");
|
|
16038
16135
|
log.info("intake", "reject", { chatId: evt.chatId, reason: evt.reason });
|
|
@@ -16539,6 +16636,7 @@ async function runAgentBatchInner(deps) {
|
|
|
16539
16636
|
callbackAuth,
|
|
16540
16637
|
activePolicyFingerprints,
|
|
16541
16638
|
lastRunModelByScope,
|
|
16639
|
+
reactionConfirmer,
|
|
16542
16640
|
scope,
|
|
16543
16641
|
mode
|
|
16544
16642
|
} = deps;
|
|
@@ -16546,6 +16644,7 @@ async function runAgentBatchInner(deps) {
|
|
|
16546
16644
|
const firstMsg = batch[0];
|
|
16547
16645
|
const lastMsg = batch[batch.length - 1];
|
|
16548
16646
|
if (!firstMsg || !lastMsg) return;
|
|
16647
|
+
reactionConfirmer.noteHandled(scope, lastMsg);
|
|
16549
16648
|
const chatId = firstMsg.chatId;
|
|
16550
16649
|
const threadId = firstMsg.threadId;
|
|
16551
16650
|
const bindingResult = deps.preBinding ? deps.preBinding.result : firstMsg.chatType === "p2p" ? dmBinding(controls, firstMsg, scope) : void 0;
|