aai-lark-bridge 0.2.7 → 0.2.9
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 +45 -8
- package/dist/cli.js.map +1 -1
- package/dist/index.js +17 -1
- package/dist/index.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.9",
|
|
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",
|
|
@@ -1541,15 +1541,31 @@ var log = {
|
|
|
1541
1541
|
const stack = err instanceof Error ? err.stack : void 0;
|
|
1542
1542
|
const apiData = err?.response?.data;
|
|
1543
1543
|
const apiStatus = err?.response?.status;
|
|
1544
|
+
const code = err?.code;
|
|
1545
|
+
const cause = err instanceof Error && "cause" in err && err.cause !== void 0 ? describeCause(err.cause) : void 0;
|
|
1544
1546
|
emit("error", phase, "fail", {
|
|
1545
1547
|
...fields,
|
|
1546
1548
|
err: message,
|
|
1549
|
+
...typeof code === "string" ? { code } : {},
|
|
1547
1550
|
apiStatus,
|
|
1548
1551
|
apiData,
|
|
1549
|
-
stack
|
|
1552
|
+
stack,
|
|
1553
|
+
...cause !== void 0 ? { cause } : {}
|
|
1550
1554
|
});
|
|
1551
1555
|
}
|
|
1552
1556
|
};
|
|
1557
|
+
function describeCause(cause) {
|
|
1558
|
+
if (!(cause instanceof Error)) return String(cause);
|
|
1559
|
+
const c = cause;
|
|
1560
|
+
return {
|
|
1561
|
+
name: c.name,
|
|
1562
|
+
message: c.message,
|
|
1563
|
+
...c.code !== void 0 ? { code: c.code } : {},
|
|
1564
|
+
...c.errno !== void 0 ? { errno: c.errno } : {},
|
|
1565
|
+
...c.syscall !== void 0 ? { syscall: c.syscall } : {},
|
|
1566
|
+
...c.stack ? { stack: c.stack } : {}
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1553
1569
|
function configureLogger(opts) {
|
|
1554
1570
|
if (stream) {
|
|
1555
1571
|
try {
|
|
@@ -1569,6 +1585,9 @@ function withTrace(ctx, fn) {
|
|
|
1569
1585
|
const traceId = ctx.traceId ?? newTraceId();
|
|
1570
1586
|
return als.run({ ...ctx, traceId }, fn);
|
|
1571
1587
|
}
|
|
1588
|
+
function currentTraceId() {
|
|
1589
|
+
return als.getStore()?.traceId;
|
|
1590
|
+
}
|
|
1572
1591
|
function newTraceId() {
|
|
1573
1592
|
return Math.random().toString(36).slice(2, 10);
|
|
1574
1593
|
}
|
|
@@ -7167,6 +7186,7 @@ function budgetStopReply(title, spentUsd, budgetUsd) {
|
|
|
7167
7186
|
return `\u4EFB\u52A1\u300A${title}\u300B\u7684\u5BF9\u8BDD\u5DF2\u82B1 ${usd(spentUsd)} \u7F8E\u5143\uFF0C\u5230\u4E0A\u9650 ${usd(budgetUsd)} \u7F8E\u5143\uFF0C\u5148\u505C\u4E0B\uFF1B\u8BF7\u770B\u9884\u7B97\u5361\u7247`;
|
|
7168
7187
|
}
|
|
7169
7188
|
function taskFooterLine(binding) {
|
|
7189
|
+
if (binding.viaThread) return `\u672C\u8BDD\u9898\u4EFB\u52A1\uFF1A\u300A${binding.task.title}\u300B`;
|
|
7170
7190
|
return `\u5F53\u524D\u4EFB\u52A1\uFF1A\u300A${binding.task.title}\u300B\uFF0C\u6392\u961F ${binding.queued} \u6761`;
|
|
7171
7191
|
}
|
|
7172
7192
|
var SAFE_NAME = /^[A-Za-z0-9_.:@+-]{1,200}$/;
|
|
@@ -7191,7 +7211,7 @@ function isTaskItem(v) {
|
|
|
7191
7211
|
const t = v;
|
|
7192
7212
|
return typeof t.task_id === "string" && t.task_id !== "" && typeof t.title === "string" && typeof t.cwd === "string" && isAbsolute2(t.cwd) && typeof t.system_prompt_file === "string" && isAbsolute2(t.system_prompt_file) && (t.first_context === void 0 || typeof t.first_context === "string") && typeof t.ledger_key === "string" && safeName(t.ledger_key);
|
|
7193
7213
|
}
|
|
7194
|
-
function resolveBinding(rawConfig, chatId, senderOpenId) {
|
|
7214
|
+
function resolveBinding(rawConfig, chatId, senderOpenId, opts = {}) {
|
|
7195
7215
|
const cfg = taskBindingsConfig(rawConfig);
|
|
7196
7216
|
if (!cfg || !safeName(chatId)) return { kind: "none" };
|
|
7197
7217
|
const file = join19(cfg.dir, "chats", `${chatId}.json`);
|
|
@@ -7206,9 +7226,13 @@ function resolveBinding(rawConfig, chatId, senderOpenId) {
|
|
|
7206
7226
|
const doc = parsed;
|
|
7207
7227
|
if (doc.version !== BINDING_VERSION) return { kind: "invalid", reason: "version" };
|
|
7208
7228
|
if (doc.chat_id !== chatId) return { kind: "invalid", reason: "chat-id" };
|
|
7209
|
-
|
|
7229
|
+
const threadTask = opts.threadRootId ? taskOfMessage(cfg.dir, opts.threadRootId) : void 0;
|
|
7230
|
+
const queue = Array.isArray(doc.queue) ? doc.queue : [];
|
|
7231
|
+
const inThread = threadTask ? [doc.active, ...queue].find((x) => x && typeof x === "object" && x.task_id === threadTask) : void 0;
|
|
7232
|
+
if (threadTask && !inThread) return { kind: "none" };
|
|
7233
|
+
if (!inThread && (doc.active === null || doc.active === void 0)) return { kind: "none" };
|
|
7210
7234
|
if (doc.user_open_id !== senderOpenId) return { kind: "invalid", reason: "user" };
|
|
7211
|
-
const task = doc.active;
|
|
7235
|
+
const task = inThread ?? doc.active;
|
|
7212
7236
|
if (!isTaskItem(task)) return { kind: "invalid", reason: "task-shape" };
|
|
7213
7237
|
if (typeof task.budget_usd !== "number" || !Number.isFinite(task.budget_usd) || task.budget_usd <= 0) {
|
|
7214
7238
|
return { kind: "invalid", reason: "budget" };
|
|
@@ -7242,7 +7266,8 @@ function resolveBinding(rawConfig, chatId, senderOpenId) {
|
|
|
7242
7266
|
cwdRealpath: cwdReal,
|
|
7243
7267
|
settingsFile,
|
|
7244
7268
|
systemPromptFile: promptReal,
|
|
7245
|
-
queued:
|
|
7269
|
+
queued: queue.length,
|
|
7270
|
+
...inThread ? { viaThread: true } : {}
|
|
7246
7271
|
}
|
|
7247
7272
|
};
|
|
7248
7273
|
}
|
|
@@ -15256,7 +15281,8 @@ async function intakeMessage(deps) {
|
|
|
15256
15281
|
function dmBinding(controls, msg, scope, opts = {}) {
|
|
15257
15282
|
const cfg = controls.profileConfig.preferences.taskBindings;
|
|
15258
15283
|
if (!cfg) return void 0;
|
|
15259
|
-
|
|
15284
|
+
const threadRootId = msg.threadId ? msg.rootId : void 0;
|
|
15285
|
+
if (opts.switchByReply && !threadRootId) {
|
|
15260
15286
|
try {
|
|
15261
15287
|
const moved = switchByReply(cfg, msg.chatId, msg.senderId, [msg.replyToMessageId, msg.rootId]);
|
|
15262
15288
|
if (moved) log.info("binding", "switched-by-reply", { scope, from: moved.from, to: moved.to, eventWritten: moved.eventWritten });
|
|
@@ -15266,7 +15292,7 @@ function dmBinding(controls, msg, scope, opts = {}) {
|
|
|
15266
15292
|
}
|
|
15267
15293
|
let result;
|
|
15268
15294
|
try {
|
|
15269
|
-
result = resolveBinding(cfg, msg.chatId, msg.senderId);
|
|
15295
|
+
result = resolveBinding(cfg, msg.chatId, msg.senderId, { threadRootId });
|
|
15270
15296
|
} catch (err) {
|
|
15271
15297
|
result = { kind: "invalid", reason: err instanceof Error ? err.message : String(err) };
|
|
15272
15298
|
}
|
|
@@ -15276,6 +15302,10 @@ function dmBinding(controls, msg, scope, opts = {}) {
|
|
|
15276
15302
|
}
|
|
15277
15303
|
return result;
|
|
15278
15304
|
}
|
|
15305
|
+
function spawnFailedReply() {
|
|
15306
|
+
const traceId = currentTraceId();
|
|
15307
|
+
return "\u26A0\uFE0F \u8FD9\u6761\u6D88\u606F\u6CA1\u6709\u4EA4\u7ED9 agent\uFF1Abridge \u6CA1\u80FD\u542F\u52A8 agent\u3002\u8BF7\u7A0D\u540E\u91CD\u53D1\uFF1B\u8FDE\u7EED\u5931\u8D25\u8BF7\u8054\u7CFB bridge \u7BA1\u7406\u5458\u91CD\u542F bridge" + (traceId ? `\uFF0C\u5E76\u9644\u4E0A\u6392\u67E5\u7F16\u53F7 ${traceId}\u3002` : "\u3002");
|
|
15308
|
+
}
|
|
15279
15309
|
async function runAgentBatch(deps) {
|
|
15280
15310
|
const {
|
|
15281
15311
|
channel,
|
|
@@ -15421,6 +15451,13 @@ async function runAgentBatch(deps) {
|
|
|
15421
15451
|
source: "im",
|
|
15422
15452
|
stage: "submit"
|
|
15423
15453
|
}
|
|
15454
|
+
}).catch(async (err) => {
|
|
15455
|
+
if (err instanceof SpawnFailed) {
|
|
15456
|
+
await channel.send(chatId, { markdown: spawnFailedReply() }, sendOpts).catch((replyErr) => {
|
|
15457
|
+
log.fail("flush", replyErr, { step: "postSpawnFailedReply" });
|
|
15458
|
+
});
|
|
15459
|
+
}
|
|
15460
|
+
throw err;
|
|
15424
15461
|
});
|
|
15425
15462
|
if (!flow.ok) {
|
|
15426
15463
|
log.info("run-flow", "rejected", { scope, code: flow.rejectReason.code });
|