duclaw-cli 1.8.17 → 1.8.18

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/bundle.js CHANGED
@@ -30242,7 +30242,7 @@ function printHelp() {
30242
30242
  `);
30243
30243
  }
30244
30244
  function printVersion() {
30245
- console.log(`duclaw-cli v${true ? "1.8.17" : "unknown"}`);
30245
+ console.log(`duclaw-cli v${true ? "1.8.18" : "unknown"}`);
30246
30246
  }
30247
30247
  function getDuclawTemplate() {
30248
30248
  return {
@@ -46463,9 +46463,8 @@ var wakeDepartmentAgent = async (mailboxId, msgIds) => {
46463
46463
  };
46464
46464
  var finalizeDepartmentAgentUnrepliedMessages = (mailboxId, msgIds, result) => {
46465
46465
  const fallbackContent = result.content?.trim();
46466
- for (const id of msgIds) {
46467
- const row = db2.prepare(
46468
- `SELECT
46466
+ const processingRows = msgIds.map((id) => db2.prepare(
46467
+ `SELECT
46469
46468
  id,
46470
46469
  to_mailbox_id as toMailboxId,
46471
46470
  from_mailbox_id as fromMailboxId,
@@ -46475,10 +46474,48 @@ var finalizeDepartmentAgentUnrepliedMessages = (mailboxId, msgIds, result) => {
46475
46474
  thread_id as threadId
46476
46475
  FROM mailbox
46477
46476
  WHERE id = ?`
46478
- ).get(id);
46479
- if (!row || row.status !== "processing") continue;
46477
+ ).get(id)).filter((row) => Boolean(row && row.status === "processing"));
46478
+ if (fallbackContent && processingRows.length > 1) {
46479
+ const bySender = /* @__PURE__ */ new Map();
46480
+ for (const row of processingRows) {
46481
+ const rows = bySender.get(row.fromMailboxId) ?? [];
46482
+ rows.push(row);
46483
+ bySender.set(row.fromMailboxId, rows);
46484
+ }
46485
+ for (const [senderMailboxId, rows] of bySender.entries()) {
46486
+ const changedRows = rows.filter((row) => updateMailboxMessageStatus(row.id, "failed", {
46487
+ fromStatus: "processing",
46488
+ actorMailboxId: mailboxId,
46489
+ counterpartMailboxId: senderMailboxId,
46490
+ reason: "department_agent_batch_fallback_ambiguous"
46491
+ }));
46492
+ if (changedRows.length === 0) continue;
46493
+ const first = changedRows[0];
46494
+ const ids = changedRows.map((row) => row.id).join(", ");
46495
+ sendMessage2(mailboxId, senderMailboxId, [
46496
+ `[\u7CFB\u7EDF\u901A\u77E5] ${mailboxId} \u672C\u8F6E\u540C\u65F6\u5904\u7406\u4E86 ${changedRows.length} \u5C01\u90AE\u4EF6\uFF0C\u4F46\u6CA1\u6709\u8C03\u7528 reply_mailbox\uFF0C\u65E0\u6CD5\u53EF\u9760\u5224\u65AD\u6700\u7EC8\u6587\u672C\u5206\u522B\u5BF9\u5E94\u54EA\u5C01\u90AE\u4EF6\u3002`,
46497
+ `\u5DF2\u5C06\u8FD9\u4E9B\u90AE\u4EF6\u6807\u8BB0\u4E3A failed\uFF0C\u907F\u514D\u91CD\u590D\u6295\u9012\u6216\u751F\u6210\u5927\u91CF\u91CD\u590D\u56DE\u4FE1\u3002`,
46498
+ `\u53D7\u5F71\u54CD\u90AE\u4EF6: ${ids}`,
46499
+ ``,
46500
+ `agent \u6700\u7EC8\u6587\u672C\u6458\u5F55:`,
46501
+ fallbackContent.slice(0, 1200)
46502
+ ].join("\n"), {
46503
+ originUserId: first.originUserId,
46504
+ originPlatform: first.originPlatform,
46505
+ threadId: first.threadId || first.id,
46506
+ parentMessageId: first.id,
46507
+ auditDetail: {
46508
+ fallbackReason: "department_agent_batch_returned_without_reply_mailbox",
46509
+ affectedMessageIds: changedRows.map((row) => row.id)
46510
+ }
46511
+ });
46512
+ console.warn(`[mailbox] department agent ${mailboxId} \u672A\u8C03\u7528 reply_mailbox\uFF0C\u6279\u91CF\u515C\u5E95\u5B58\u5728\u6B67\u4E49\uFF0C\u5DF2\u5C06 ${changedRows.length} \u5C01\u90AE\u4EF6\u6807\u8BB0 failed \u5E76\u5411 ${senderMailboxId} \u53D1\u9001\u4E00\u5C01\u7CFB\u7EDF\u901A\u77E5`);
46513
+ }
46514
+ return;
46515
+ }
46516
+ for (const row of processingRows) {
46480
46517
  if (fallbackContent) {
46481
- const changed2 = updateMailboxMessageStatus(id, "done", {
46518
+ const changed2 = updateMailboxMessageStatus(row.id, "done", {
46482
46519
  fromStatus: "processing",
46483
46520
  actorMailboxId: mailboxId,
46484
46521
  counterpartMailboxId: row.fromMailboxId,
@@ -46494,11 +46531,11 @@ var finalizeDepartmentAgentUnrepliedMessages = (mailboxId, msgIds, result) => {
46494
46531
  fallbackReason: "department_agent_returned_without_reply_mailbox"
46495
46532
  }
46496
46533
  });
46497
- console.warn(`[mailbox] department agent ${mailboxId} \u672A\u8C03\u7528 reply_mailbox\uFF0C\u5DF2\u5C06\u6700\u7EC8\u6587\u672C\u515C\u5E95\u8F6C\u4E3A\u90AE\u4EF6 ${id} \u7684\u56DE\u4FE1`);
46534
+ console.warn(`[mailbox] department agent ${mailboxId} \u672A\u8C03\u7528 reply_mailbox\uFF0C\u5DF2\u5C06\u6700\u7EC8\u6587\u672C\u515C\u5E95\u8F6C\u4E3A\u90AE\u4EF6 ${row.id} \u7684\u56DE\u4FE1`);
46498
46535
  }
46499
46536
  continue;
46500
46537
  }
46501
- const changed = updateMailboxMessageStatus(id, "failed", {
46538
+ const changed = updateMailboxMessageStatus(row.id, "failed", {
46502
46539
  fromStatus: "processing",
46503
46540
  actorMailboxId: mailboxId,
46504
46541
  counterpartMailboxId: row.fromMailboxId,
@@ -46514,7 +46551,7 @@ var finalizeDepartmentAgentUnrepliedMessages = (mailboxId, msgIds, result) => {
46514
46551
  fallbackReason: "department_agent_returned_empty_without_reply_mailbox"
46515
46552
  }
46516
46553
  });
46517
- console.warn(`[mailbox] department agent ${mailboxId} \u6CA1\u6709\u56DE\u590D\u5185\u5BB9\uFF0C\u90AE\u4EF6 ${id} \u5DF2\u6807\u8BB0 failed`);
46554
+ console.warn(`[mailbox] department agent ${mailboxId} \u6CA1\u6709\u56DE\u590D\u5185\u5BB9\uFF0C\u90AE\u4EF6 ${row.id} \u5DF2\u6807\u8BB0 failed`);
46518
46555
  }
46519
46556
  }
46520
46557
  };
@@ -51485,7 +51522,7 @@ var systemRoutes = new Hono2();
51485
51522
  var startTime = Date.now();
51486
51523
  systemRoutes.get("/system/info", (c) => {
51487
51524
  return c.json({
51488
- version: true ? "1.8.17" : "unknown",
51525
+ version: true ? "1.8.18" : "unknown",
51489
51526
  uptime: Math.floor((Date.now() - startTime) / 1e3),
51490
51527
  env: process.env.NODE_ENV || "development",
51491
51528
  nodeVersion: process.version