aai-lark-bridge 0.2.33 → 0.2.34
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/cli.js +44 -6
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
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.34",
|
|
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",
|
|
@@ -14767,6 +14767,10 @@ var PendingQueue = class {
|
|
|
14767
14767
|
});
|
|
14768
14768
|
return 1;
|
|
14769
14769
|
}
|
|
14770
|
+
/** 有消息在排队、或正在 flush / 运行(被 block)的 scope:还没占上 ActiveRuns 的也算。 */
|
|
14771
|
+
scopes() {
|
|
14772
|
+
return [.../* @__PURE__ */ new Set([...this.map.keys(), ...this.blocked])];
|
|
14773
|
+
}
|
|
14770
14774
|
cancel(scope) {
|
|
14771
14775
|
const entry = this.map.get(scope);
|
|
14772
14776
|
if (!entry) return [];
|
|
@@ -15022,6 +15026,33 @@ async function observeWorkerRun(i) {
|
|
|
15022
15026
|
}
|
|
15023
15027
|
return report;
|
|
15024
15028
|
}
|
|
15029
|
+
var ReportInbox = class {
|
|
15030
|
+
constructor(max = 10, ttlMs = 24 * 60 * 60 * 1e3, now = Date.now) {
|
|
15031
|
+
this.max = max;
|
|
15032
|
+
this.ttlMs = ttlMs;
|
|
15033
|
+
this.now = now;
|
|
15034
|
+
}
|
|
15035
|
+
max;
|
|
15036
|
+
ttlMs;
|
|
15037
|
+
now;
|
|
15038
|
+
byChat = /* @__PURE__ */ new Map();
|
|
15039
|
+
add(chatId, text) {
|
|
15040
|
+
const list = this.byChat.get(chatId) ?? [];
|
|
15041
|
+
list.push({ text, at: this.now() });
|
|
15042
|
+
while (list.length > this.max) list.shift();
|
|
15043
|
+
this.byChat.set(chatId, list);
|
|
15044
|
+
}
|
|
15045
|
+
/** 取走这个私聊攒下的回流(过了 TTL 的丢掉)。 */
|
|
15046
|
+
take(chatId) {
|
|
15047
|
+
const list = this.byChat.get(chatId) ?? [];
|
|
15048
|
+
this.byChat.delete(chatId);
|
|
15049
|
+
const cutoff = this.now() - this.ttlMs;
|
|
15050
|
+
return list.filter((r) => r.at >= cutoff).map((r) => r.text);
|
|
15051
|
+
}
|
|
15052
|
+
};
|
|
15053
|
+
function reportsInstruction(reports) {
|
|
15054
|
+
return "\u4F60\u4E4B\u524D\u6D3E\u5230\u8BDD\u9898\u91CC\u7684\u4EFB\u52A1\u6709\u65B0\u7684\u7EC8\u6001\uFF0C\u4E0B\u9762\u662F\u7CFB\u7EDF\u56DE\u6D41\uFF0C\u53EA\u7528\u6765\u56DE\u6EAF\uFF0C\u4E0D\u662F\u7528\u6237\u8BF4\u7684\u8BDD\uFF0C\u4E0D\u8981\u4E3A\u5B83\u4EEC\u5355\u72EC\u56DE\u590D\u7528\u6237\uFF1B\u7528\u6237\u540E\u9762\u95EE\u8D77\u65F6\u51ED trace \u8BA4\u662F\u54EA\u4E2A\u8BDD\u9898\u3002\n\n" + reports.join("\n\n");
|
|
15055
|
+
}
|
|
15025
15056
|
|
|
15026
15057
|
// src/bridge/bot/quote.ts
|
|
15027
15058
|
import { normalize } from "@larksuite/channel";
|
|
@@ -15833,6 +15864,7 @@ async function startChannel(deps) {
|
|
|
15833
15864
|
const channel = createLarkChannel(opts);
|
|
15834
15865
|
installStreamResilience(channel);
|
|
15835
15866
|
const media = new MediaCache(channel, deps.appPaths?.mediaDir);
|
|
15867
|
+
const reportInbox = new ReportInbox();
|
|
15836
15868
|
const pending = new PendingQueue(DEBOUNCE_MS, (scope, batch, arrival) => {
|
|
15837
15869
|
const firstMsg = batch[0];
|
|
15838
15870
|
if (!firstMsg) return;
|
|
@@ -15866,8 +15898,9 @@ async function startChannel(deps) {
|
|
|
15866
15898
|
batch,
|
|
15867
15899
|
arrival,
|
|
15868
15900
|
pushToRouter: (m) => {
|
|
15869
|
-
|
|
15901
|
+
reportInbox.add(m.chatId, m.content);
|
|
15870
15902
|
},
|
|
15903
|
+
reportInbox,
|
|
15871
15904
|
controls,
|
|
15872
15905
|
cotClient,
|
|
15873
15906
|
callbackAuth,
|
|
@@ -16047,7 +16080,7 @@ async function startChannel(deps) {
|
|
|
16047
16080
|
const spawnInbox = spawnDir ? startSpawnInbox({
|
|
16048
16081
|
dir: spawnDir,
|
|
16049
16082
|
recent: recentDm,
|
|
16050
|
-
activeScopes: () => activeRuns.scopes(),
|
|
16083
|
+
activeScopes: () => [.../* @__PURE__ */ new Set([...activeRuns.scopes(), ...pending.scopes()])],
|
|
16051
16084
|
limit: MAX_DM_WORKERS,
|
|
16052
16085
|
isRoot: (id) => isDispatchRoot(spawnDir, id),
|
|
16053
16086
|
register: (id, chatId) => registerDispatchRoot(spawnDir, id, chatId),
|
|
@@ -16307,7 +16340,8 @@ async function intakeMessage(deps) {
|
|
|
16307
16340
|
log.info("intake", "command", { scope, droppedPending: dropped.length });
|
|
16308
16341
|
return;
|
|
16309
16342
|
}
|
|
16310
|
-
|
|
16343
|
+
const inFlightScopes = [.../* @__PURE__ */ new Set([...activeRuns.scopes(), ...pending.scopes()])];
|
|
16344
|
+
if (workerScope && !inFlightScopes.includes(scope) && runningWorkers(inFlightScopes, emsg.chatId) >= MAX_DM_WORKERS) {
|
|
16311
16345
|
log.info("intake", "worker-limit", { scope, limit: MAX_DM_WORKERS });
|
|
16312
16346
|
await channel.send(emsg.chatId, { markdown: `\u4F60\u540C\u65F6\u5728\u8DD1\u7684\u4EFB\u52A1\u5DF2\u7ECF\u6709 ${MAX_DM_WORKERS} \u4E2A\uFF0C\u7B49\u5176\u4E2D\u4E00\u4E2A\u7ED3\u675F\u540E\u518D\u53D1\u8FD9\u6761\u3002` }, { replyTo: emsg.messageId }).catch((err) => log.warn("intake", "worker-limit-reply-failed", { err: String(err) }));
|
|
16313
16347
|
return;
|
|
@@ -16415,6 +16449,7 @@ async function runAgentBatchInner(deps) {
|
|
|
16415
16449
|
batch,
|
|
16416
16450
|
arrival,
|
|
16417
16451
|
pushToRouter,
|
|
16452
|
+
reportInbox,
|
|
16418
16453
|
controls,
|
|
16419
16454
|
cotClient,
|
|
16420
16455
|
callbackAuth,
|
|
@@ -16488,11 +16523,13 @@ async function runAgentBatchInner(deps) {
|
|
|
16488
16523
|
const prevModel = lastRunModelByScope.get(scope);
|
|
16489
16524
|
const modelSwitched = prevModel !== void 0 && prevModel !== modelSelection;
|
|
16490
16525
|
lastRunModelByScope.set(scope, modelSelection);
|
|
16526
|
+
const reportsForRouter = firstMsg.chatType === "p2p" && scope === chatId && !binding ? reportInbox?.take(chatId) ?? [] : [];
|
|
16491
16527
|
const extraInstructions = [
|
|
16492
16528
|
...modelSwitched ? [
|
|
16493
16529
|
`\u7528\u6237\u521A\u628A\u672C\u4F1A\u8BDD\u4F7F\u7528\u7684\u6A21\u578B\u5207\u6362\u4E3A\u300C${modelLabel(agentKind, modelPref)}\u300D\u3002\u4E4B\u524D\u7684\u5BF9\u8BDD\u91CC\u53EF\u80FD\u63D0\u5230\u522B\u7684\u6A21\u578B,\u8BF7\u4EE5\u5F53\u524D\u6A21\u578B\u4E3A\u51C6;\u82E5\u88AB\u95EE\u5230\u4F60\u7528\u7684\u662F\u4EC0\u4E48\u6A21\u578B,\u636E\u6B64\u56DE\u7B54\u3002`
|
|
16494
16530
|
] : [],
|
|
16495
|
-
...deps.userRead ? [deps.userRead.instruction] : []
|
|
16531
|
+
...deps.userRead ? [deps.userRead.instruction] : [],
|
|
16532
|
+
...reportsForRouter.length > 0 ? [reportsInstruction(reportsForRouter)] : []
|
|
16496
16533
|
];
|
|
16497
16534
|
const prompt = buildPrompt(
|
|
16498
16535
|
batch,
|
|
@@ -16516,11 +16553,12 @@ async function runAgentBatchInner(deps) {
|
|
|
16516
16553
|
replyInThread: sendOpts.replyInThread === true
|
|
16517
16554
|
});
|
|
16518
16555
|
const accessDecision = firstMsg.chatType === "p2p" ? canUseDm(controls.profileConfig, controls, firstMsg.senderId) : canUseGroup(controls.profileConfig, controls, firstMsg.chatId, firstMsg.senderId);
|
|
16556
|
+
const workerScope = firstMsg.chatType === "p2p" && scope.startsWith(`${chatId}:`);
|
|
16519
16557
|
const scopeContext = {
|
|
16520
16558
|
source: "im",
|
|
16521
16559
|
chatId,
|
|
16522
16560
|
actorId: firstMsg.senderId,
|
|
16523
|
-
...threadId ? { threadId } : {}
|
|
16561
|
+
...threadId && !workerScope ? { threadId } : {}
|
|
16524
16562
|
};
|
|
16525
16563
|
const capability = controls.profileConfig.agentKind === "codex" ? codexCapability(controls.profileConfig) : claudeCapability(controls.profileConfig);
|
|
16526
16564
|
const flow = await startRunFlow({
|