aai-lark-bridge 0.2.41 → 0.2.42

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/README.md CHANGED
@@ -49,7 +49,7 @@ lark-cli --version # 见下方说明
49
49
 
50
50
  ### SDLC 文档评论确认(可选)
51
51
 
52
- `preferences.sdlcConfirmationWorkspace` 可设为 SDLC 工作区绝对路径,默认关闭。普通文档评论先保存最小线索,再唤醒固定只读核验;事件正文不作为授权。需同时安装并启用 SDLC 评论核验,部署后实测事件覆盖;配置与暂停方式见仓库 `plugins/aai-sdlc/agent/README.md`。
52
+ `preferences.sdlcConfirmationWorkspace` 可设为 SDLC 工作区绝对路径,默认关闭。普通文档评论先保存最小线索,再唤醒固定只读核验;事件正文不作为授权。需同时安装并启用 SDLC 评论核验,部署后实测事件覆盖;配置与暂停方式见仓库 `services/sdlc-agent/README.md`。
53
53
 
54
54
  ### 第 2 步:安装
55
55
 
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.41",
7
+ version: "0.2.42",
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",
@@ -20519,6 +20519,18 @@ function createGateway(opts) {
20519
20519
  const now = opts.now ?? Date.now;
20520
20520
  const sleep3 = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms).unref()));
20521
20521
  const handles = /* @__PURE__ */ new Map();
20522
+ const gone = /* @__PURE__ */ new Map();
20523
+ const GONE_MAX = 500;
20524
+ function forget(handle2, reason, runId, at = now()) {
20525
+ handles.delete(handle2);
20526
+ gone.set(handle2, { reason, runId, at });
20527
+ if (gone.size > GONE_MAX) gone.delete(gone.keys().next().value);
20528
+ }
20529
+ function noteExpired(event, api, handle2) {
20530
+ const g = handle2 ? gone.get(handle2) : void 0;
20531
+ const reason = !handle2 ? "no_handle" : g ? g.reason : "unknown";
20532
+ log.warn("user-gateway", event, { api, reason, runId: g?.runId, agoSec: g ? Math.round((now() - g.at) / 1e3) : void 0 });
20533
+ }
20522
20534
  const used = /* @__PURE__ */ new Map();
20523
20535
  const issuedFor = /* @__PURE__ */ new Map();
20524
20536
  const inFlight = /* @__PURE__ */ new Set();
@@ -20615,7 +20627,7 @@ function createGateway(opts) {
20615
20627
  let expired = false;
20616
20628
  for (const [h, v] of handles)
20617
20629
  if (v.expiresAt <= t) {
20618
- handles.delete(h);
20630
+ forget(h, "ttl", v.runId, v.expiresAt);
20619
20631
  expired = true;
20620
20632
  }
20621
20633
  if (expired) void cleanupTmp();
@@ -20827,7 +20839,7 @@ function createGateway(opts) {
20827
20839
  const e = larkError(r);
20828
20840
  if (!r.timedOut && e.type === "authentication") {
20829
20841
  await rm14(authorizedMark(h.openId), { force: true });
20830
- for (const [k, v] of handles) if (v.openId === h.openId) handles.delete(k);
20842
+ for (const [k, v] of handles) if (v.openId === h.openId) forget(k, "auth", v.runId);
20831
20843
  try {
20832
20844
  await startAuth(h.openId);
20833
20845
  } catch (err) {
@@ -20950,12 +20962,16 @@ function createGateway(opts) {
20950
20962
  const h = issue(true);
20951
20963
  return { status: "ok", handle: h.handle, expiresAt: h.expiresAt, db: db.enabled };
20952
20964
  },
20965
+ /** 请求没带句柄就来读或查库:记一条带原因的 expired(server 调)。 */
20966
+ noteMissingHandle(event, api) {
20967
+ noteExpired(event, api, "");
20968
+ },
20953
20969
  /** DELETE /handles/{runId}:运行结束,作废这次运行的句柄。 */
20954
20970
  dropHandles(runId) {
20955
20971
  let n = 0;
20956
20972
  for (const [h, v] of handles) {
20957
20973
  if (v.runId === runId) {
20958
- handles.delete(h);
20974
+ forget(h, "run_end", v.runId);
20959
20975
  n++;
20960
20976
  }
20961
20977
  }
@@ -20972,6 +20988,7 @@ function createGateway(opts) {
20972
20988
  async read(handle2, api, input) {
20973
20989
  sweep();
20974
20990
  const h = handles.get(handle2);
20991
+ if (!h) noteExpired("read.expired", api, handle2);
20975
20992
  if (!h || h.kind !== "dm") return { status: "expired" };
20976
20993
  if (!h.read) {
20977
20994
  log.info("user-gateway", "read.need-auth", { identity: "user", sender: tail6(h.openId), messageId: h.messageId, runId: h.runId, api, detail: "handle-without-read" });
@@ -21007,7 +21024,7 @@ function createGateway(opts) {
21007
21024
  const v = await verify(messageId, "revoke");
21008
21025
  if (typeof v === "string") return { status: v };
21009
21026
  if (v.text?.trim() !== REVOKE_TEXT2) return { status: "not_revoke" };
21010
- for (const [h, x] of handles) if (x.openId === v.openId) handles.delete(h);
21027
+ for (const [h, x] of handles) if (x.openId === v.openId) forget(h, "revoke", x.runId);
21011
21028
  const had = existsSync10(userDir(v.openId));
21012
21029
  await rm14(userDir(v.openId), { recursive: true, force: true });
21013
21030
  bound2.delete(userDir(v.openId));
@@ -21147,7 +21164,10 @@ function createGateway(opts) {
21147
21164
  if (!db.enabled) return { status: "off" };
21148
21165
  sweep();
21149
21166
  const h = handles.get(handle2);
21150
- if (!h) return { status: "expired" };
21167
+ if (!h) {
21168
+ noteExpired("db.expired", "db-query", handle2);
21169
+ return { status: "expired" };
21170
+ }
21151
21171
  const name = typeof input.db === "string" && input.db ? input.db : "lotus";
21152
21172
  const sql = typeof input.sql === "string" ? input.sql : "";
21153
21173
  const fields = { sender: tail6(h.openId), runId: h.runId, kind: h.kind, db: name, sql: sql.slice(0, SQL_LOG_MAX) };
@@ -21246,7 +21266,10 @@ function createGatewayServer(opts) {
21246
21266
  };
21247
21267
  if (method === "POST" && path === DB_QUERY) {
21248
21268
  const handle2 = bearer();
21249
- if (!handle2) return send2(res, 200, { status: "expired" });
21269
+ if (!handle2) {
21270
+ gateway.noteMissingHandle("db.expired", "db-query");
21271
+ return send2(res, 200, { status: "expired" });
21272
+ }
21250
21273
  return send2(res, 200, await gateway.dbQuery(handle2, await readBody(req)));
21251
21274
  }
21252
21275
  const read = method === "POST" ? /^\/read\/([a-z-]+)$/.exec(path) : null;
@@ -21254,7 +21277,10 @@ function createGatewayServer(opts) {
21254
21277
  const api = read[1] ?? "";
21255
21278
  if (!isReadApi(api)) return send2(res, 404, { status: "unknown_api" });
21256
21279
  const handle2 = bearer();
21257
- if (!handle2) return send2(res, 200, { status: "expired" });
21280
+ if (!handle2) {
21281
+ gateway.noteMissingHandle("read.expired", api);
21282
+ return send2(res, 200, { status: "expired" });
21283
+ }
21258
21284
  return send2(res, 200, await gateway.read(handle2, api, await readBody(req)));
21259
21285
  }
21260
21286
  return send2(res, 404, { status: "not_found" });