aai-lark-bridge 0.2.42 → 0.2.44
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 +118 -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.44",
|
|
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,91 @@ 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 extractText(content) {
|
|
15340
|
+
if (!content) return "";
|
|
15341
|
+
let tree;
|
|
15342
|
+
try {
|
|
15343
|
+
tree = JSON.parse(content);
|
|
15344
|
+
} catch {
|
|
15345
|
+
return content;
|
|
15346
|
+
}
|
|
15347
|
+
const out = [];
|
|
15348
|
+
const walk = (v, key) => {
|
|
15349
|
+
if (typeof v === "string") {
|
|
15350
|
+
if (key === "text" || key === "content" || key === "title") out.push(v);
|
|
15351
|
+
} else if (Array.isArray(v)) v.forEach((x) => walk(x, key));
|
|
15352
|
+
else if (v && typeof v === "object") for (const [k, x] of Object.entries(v)) walk(x, k);
|
|
15353
|
+
};
|
|
15354
|
+
walk(tree);
|
|
15355
|
+
return out.join("\n");
|
|
15356
|
+
}
|
|
15357
|
+
function isConfirmQuestion(text) {
|
|
15358
|
+
const tail = text.trim().split(/[。!!\n]/).map((s) => s.trim()).filter(Boolean).pop() ?? "";
|
|
15359
|
+
return /[??]$/.test(tail) && /吗|是否|要不要|可不可以|对不对|行不行|可以不/.test(tail);
|
|
15360
|
+
}
|
|
15361
|
+
var ReactionConfirmer = class {
|
|
15362
|
+
constructor(now = Date.now) {
|
|
15363
|
+
this.now = now;
|
|
15364
|
+
}
|
|
15365
|
+
now;
|
|
15366
|
+
byUserMsg = /* @__PURE__ */ new Map();
|
|
15367
|
+
latestByScope = /* @__PURE__ */ new Map();
|
|
15368
|
+
used = /* @__PURE__ */ new Set();
|
|
15369
|
+
/** 一批用户消息开始跑时登记:该 scope 里 bot 之后的回复,都是对这条消息的回复。 */
|
|
15370
|
+
noteHandled(scope, msg) {
|
|
15371
|
+
const prev = this.latestByScope.get(scope);
|
|
15372
|
+
if (prev) this.byUserMsg.delete(prev);
|
|
15373
|
+
this.byUserMsg.set(msg.messageId, { scope, msg });
|
|
15374
|
+
this.latestByScope.set(scope, msg.messageId);
|
|
15375
|
+
while (this.latestByScope.size > SCOPE_MAX) {
|
|
15376
|
+
const oldest = this.latestByScope.keys().next().value;
|
|
15377
|
+
const id = this.latestByScope.get(oldest);
|
|
15378
|
+
this.latestByScope.delete(oldest);
|
|
15379
|
+
if (id) this.byUserMsg.delete(id);
|
|
15380
|
+
}
|
|
15381
|
+
}
|
|
15382
|
+
async handle(evt, channel) {
|
|
15383
|
+
const reject4 = (reason) => {
|
|
15384
|
+
log.info("reaction-confirm", "ignored", { reason, messageId: evt.messageId });
|
|
15385
|
+
return void 0;
|
|
15386
|
+
};
|
|
15387
|
+
if (evt.action !== "added") return reject4("not-added");
|
|
15388
|
+
if (!POSITIVE_EMOJIS.has(evt.emojiType)) return reject4("not-positive");
|
|
15389
|
+
if (this.used.has(evt.messageId)) return reject4("already-used");
|
|
15390
|
+
let bot;
|
|
15391
|
+
try {
|
|
15392
|
+
bot = (await channel.fetchRawMessage(evt.messageId))[0];
|
|
15393
|
+
} catch (err) {
|
|
15394
|
+
log.warn("reaction-confirm", "fetch-failed", { messageId: evt.messageId, err: String(err) });
|
|
15395
|
+
return void 0;
|
|
15396
|
+
}
|
|
15397
|
+
if (!bot?.message_id) return reject4("message-not-found");
|
|
15398
|
+
if (bot.sender?.sender_type !== "app" && bot.sender?.sender_type !== "bot") return reject4("not-bot-message");
|
|
15399
|
+
const parentId = bot.parent_id;
|
|
15400
|
+
const handled = parentId ? this.byUserMsg.get(parentId) : void 0;
|
|
15401
|
+
if (!handled || !parentId) return reject4("not-reply-to-handled-message");
|
|
15402
|
+
if (this.latestByScope.get(handled.scope) !== parentId) return reject4("not-latest");
|
|
15403
|
+
if (handled.msg.chatId !== bot.chat_id) return reject4("chat-mismatch");
|
|
15404
|
+
if (evt.operator.openId !== handled.msg.senderId) return reject4("not-asker");
|
|
15405
|
+
if (!isConfirmQuestion(extractText(bot.body?.content))) return reject4("not-a-question");
|
|
15406
|
+
const t = this.now();
|
|
15407
|
+
if (t - handled.msg.createTime > CONFIRM_WINDOW_MS) return reject4("expired");
|
|
15408
|
+
this.used.add(evt.messageId);
|
|
15409
|
+
if (this.used.size > 1e3) this.used.delete(this.used.values().next().value);
|
|
15410
|
+
const msg = {
|
|
15411
|
+
...handled.msg,
|
|
15412
|
+
content: `\u53EF\u4EE5\uFF08\u7528\u6237\u70B9\u4E86 ${evt.emojiType} \u8868\u60C5\u786E\u8BA4\uFF09`,
|
|
15413
|
+
resources: [],
|
|
15414
|
+
createTime: t
|
|
15415
|
+
};
|
|
15416
|
+
return { scope: handled.scope, msg };
|
|
15417
|
+
}
|
|
15418
|
+
};
|
|
15419
|
+
|
|
15335
15420
|
// src/bridge/bot/channel-registry.ts
|
|
15336
15421
|
var active2 = /* @__PURE__ */ new Map();
|
|
15337
15422
|
function registerChannel(profile2) {
|
|
@@ -15891,6 +15976,7 @@ async function startChannel(deps) {
|
|
|
15891
15976
|
}) : void 0;
|
|
15892
15977
|
const activePolicyFingerprints = /* @__PURE__ */ new Map();
|
|
15893
15978
|
const lastRunModelByScope = /* @__PURE__ */ new Map();
|
|
15979
|
+
const reactionConfirmer = new ReactionConfirmer();
|
|
15894
15980
|
const cotClient = new CotClient({
|
|
15895
15981
|
tenant: cfg.accounts.app.tenant,
|
|
15896
15982
|
appId: cfg.accounts.app.id,
|
|
@@ -15989,6 +16075,7 @@ async function startChannel(deps) {
|
|
|
15989
16075
|
callbackAuth,
|
|
15990
16076
|
activePolicyFingerprints,
|
|
15991
16077
|
lastRunModelByScope,
|
|
16078
|
+
reactionConfirmer,
|
|
15992
16079
|
scope,
|
|
15993
16080
|
mode
|
|
15994
16081
|
});
|
|
@@ -16033,6 +16120,34 @@ async function startChannel(deps) {
|
|
|
16033
16120
|
})
|
|
16034
16121
|
).catch((err) => log.fail("intake", err));
|
|
16035
16122
|
},
|
|
16123
|
+
reaction: async (evt) => {
|
|
16124
|
+
markInbound("reaction");
|
|
16125
|
+
const hit = await reactionConfirmer.handle(evt, channel).catch((err) => {
|
|
16126
|
+
log.fail("reaction-confirm", err);
|
|
16127
|
+
return void 0;
|
|
16128
|
+
});
|
|
16129
|
+
if (!hit) return;
|
|
16130
|
+
log.info("reaction-confirm", "accepted", { scope: hit.scope, emoji: evt.emojiType, msgId: hit.msg.messageId });
|
|
16131
|
+
await withTrace(
|
|
16132
|
+
{ chatId: hit.msg.chatId, msgId: hit.msg.messageId },
|
|
16133
|
+
() => intakeMessage({
|
|
16134
|
+
channel,
|
|
16135
|
+
agent,
|
|
16136
|
+
sessions: sessions2,
|
|
16137
|
+
sessionCatalog,
|
|
16138
|
+
workspaces,
|
|
16139
|
+
activeRuns,
|
|
16140
|
+
pending,
|
|
16141
|
+
recent: recentDm,
|
|
16142
|
+
msg: hit.msg,
|
|
16143
|
+
controls,
|
|
16144
|
+
chatModeCache,
|
|
16145
|
+
logThreadModeOverride,
|
|
16146
|
+
executor,
|
|
16147
|
+
pool
|
|
16148
|
+
})
|
|
16149
|
+
).catch((err) => log.fail("intake", err));
|
|
16150
|
+
},
|
|
16036
16151
|
reject: (evt) => {
|
|
16037
16152
|
markInbound("reject");
|
|
16038
16153
|
log.info("intake", "reject", { chatId: evt.chatId, reason: evt.reason });
|
|
@@ -16539,6 +16654,7 @@ async function runAgentBatchInner(deps) {
|
|
|
16539
16654
|
callbackAuth,
|
|
16540
16655
|
activePolicyFingerprints,
|
|
16541
16656
|
lastRunModelByScope,
|
|
16657
|
+
reactionConfirmer,
|
|
16542
16658
|
scope,
|
|
16543
16659
|
mode
|
|
16544
16660
|
} = deps;
|
|
@@ -16546,6 +16662,7 @@ async function runAgentBatchInner(deps) {
|
|
|
16546
16662
|
const firstMsg = batch[0];
|
|
16547
16663
|
const lastMsg = batch[batch.length - 1];
|
|
16548
16664
|
if (!firstMsg || !lastMsg) return;
|
|
16665
|
+
reactionConfirmer.noteHandled(scope, lastMsg);
|
|
16549
16666
|
const chatId = firstMsg.chatId;
|
|
16550
16667
|
const threadId = firstMsg.threadId;
|
|
16551
16668
|
const bindingResult = deps.preBinding ? deps.preBinding.result : firstMsg.chatType === "p2p" ? dmBinding(controls, firstMsg, scope) : void 0;
|