@clawos-dev/clawd 0.2.302 → 0.2.304

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.
Files changed (2) hide show
  1. package/dist/cli.cjs +43 -51
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -52074,11 +52074,18 @@ function buildLarkBotHandlers(deps) {
52074
52074
  response: { type: "larkBot:status:ok", state: "unbound", groups: [] }
52075
52075
  };
52076
52076
  }
52077
+ if (cloudBinding && (cloudBinding.appId !== meta.appId || cloudBinding.botName !== meta.botName)) {
52078
+ deps.store.write(personaId2, {
52079
+ appId: cloudBinding.appId,
52080
+ botName: cloudBinding.botName,
52081
+ boundAt: now()
52082
+ });
52083
+ }
52077
52084
  const broken = cloudBinding?.status === "broken";
52078
52085
  const result = {
52079
52086
  state: broken ? "broken" : "bound",
52080
- appId: meta.appId,
52081
- botName: meta.botName,
52087
+ appId: cloudBinding?.appId ?? meta.appId,
52088
+ botName: cloudBinding?.botName ?? meta.botName,
52082
52089
  ...broken ? { brokenReason: cloudBinding?.brokenReason ?? "unknown" } : {},
52083
52090
  groups: groupsOf(personaId2)
52084
52091
  };
@@ -52278,9 +52285,7 @@ var import_node_fs27 = __toESM(require("fs"), 1);
52278
52285
  var import_node_path28 = __toESM(require("path"), 1);
52279
52286
  init_protocol();
52280
52287
  var ERROR_REPLY_TEXT = "\u5904\u7406\u51FA\u9519\u4E86\uFF0C\u8BF7\u91CD\u8BD5";
52281
- var DEFAULT_TURN_TIMEOUT_MS = 10 * 60 * 1e3;
52282
52288
  var DEBOUNCE_MS = 1e3;
52283
- var CONTENT_HOLD_MS = 6e4;
52284
52289
  var MAX_IMAGE_BYTES = 8 * 1024 * 1024;
52285
52290
  var EXT_BY_MIME = {
52286
52291
  "image/png": "png",
@@ -52306,69 +52311,72 @@ function safeAttachmentName(raw) {
52306
52311
  return cleaned.slice(0, 100 - ext.length) + ext;
52307
52312
  }
52308
52313
  function createLarkChatRouter(deps) {
52309
- const timeoutMs = deps.turnTimeoutMs ?? DEFAULT_TURN_TIMEOUT_MS;
52310
52314
  const replyDelays = deps.replyRetryDelaysMs ?? [2e3, 8e3, 3e4];
52311
52315
  const sleep2 = deps.sleepImpl ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
52312
52316
  const debounceMs = deps.debounceMs ?? DEBOUNCE_MS;
52313
- const contentHoldMs = deps.contentHoldMs ?? CONTENT_HOLD_MS;
52314
- const timerMsFor = (envs) => {
52315
- if (envs.some((e) => e.text?.trim())) return debounceMs;
52316
- const hasContent = envs.some(
52317
- (e) => (e.imageKeys?.length ?? 0) > 0 || (e.files?.length ?? 0) > 0
52318
- );
52319
- return hasContent ? contentHoldMs : debounceMs;
52320
- };
52321
52317
  const queues = /* @__PURE__ */ new Map();
52322
52318
  const activity = /* @__PURE__ */ new Map();
52323
52319
  const pending = /* @__PURE__ */ new Map();
52324
- const buildSection = async (env) => {
52325
- const imageLines = [];
52326
- for (const [i, key] of (env.imageKeys ?? []).entries()) {
52320
+ const imageLinesFor = async (env, ownerMessageId, keys) => {
52321
+ const lines = [];
52322
+ for (const [i, key] of keys.entries()) {
52327
52323
  try {
52328
52324
  if (!deps.fetchResource || !deps.mediaRootFor) throw new Error("resource pipeline not wired");
52329
- const r = await deps.fetchResource(env.appId, env.messageId, key, MAX_IMAGE_BYTES, "image");
52325
+ const r = await deps.fetchResource(env.appId, ownerMessageId, key, MAX_IMAGE_BYTES, "image");
52330
52326
  if (r.data.byteLength > MAX_IMAGE_BYTES) {
52331
52327
  deps.logger?.warn(`larkBot image oversize ${key}: ${r.data.byteLength}B`);
52332
- imageLines.push(IMAGE_OVERSIZE_TEXT);
52328
+ lines.push(IMAGE_OVERSIZE_TEXT);
52333
52329
  continue;
52334
52330
  }
52335
52331
  const ext = EXT_BY_MIME[r.contentType];
52336
52332
  if (!ext) {
52337
52333
  deps.logger?.warn(`larkBot image unsupported mime ${key}: ${r.contentType}`);
52338
- imageLines.push(IMAGE_UNAVAILABLE_TEXT);
52334
+ lines.push(IMAGE_UNAVAILABLE_TEXT);
52339
52335
  continue;
52340
52336
  }
52341
52337
  const dir = deps.mediaRootFor(env.chatId);
52342
52338
  import_node_fs27.default.mkdirSync(dir, { recursive: true });
52343
- const p2 = import_node_path28.default.join(dir, `${safeMediaName(env.messageId)}-${i}.${ext}`);
52339
+ const p2 = import_node_path28.default.join(dir, `${safeMediaName(ownerMessageId)}-${i}.${ext}`);
52344
52340
  import_node_fs27.default.writeFileSync(p2, r.data);
52345
- imageLines.push(`[\u56FE\u7247: ${p2}]\uFF08\u7528 Read \u5DE5\u5177\u67E5\u770B\uFF09`);
52341
+ lines.push(`[\u56FE\u7247: ${p2}]\uFF08\u7528 Read \u5DE5\u5177\u67E5\u770B\uFF09`);
52346
52342
  } catch (err) {
52347
52343
  deps.logger?.warn(`larkBot image fetch failed ${key}: ${err.message}`);
52348
- imageLines.push(IMAGE_UNAVAILABLE_TEXT);
52344
+ lines.push(IMAGE_UNAVAILABLE_TEXT);
52349
52345
  }
52350
52346
  }
52351
- const fileLines = [];
52352
- for (const [i, f] of (env.files ?? []).entries()) {
52347
+ return lines;
52348
+ };
52349
+ const fileLinesFor = async (env, ownerMessageId, entries) => {
52350
+ const lines = [];
52351
+ for (const [i, f] of entries.entries()) {
52353
52352
  try {
52354
52353
  if (!deps.fetchResource || !deps.mediaRootFor) throw new Error("resource pipeline not wired");
52355
- const r = await deps.fetchResource(env.appId, env.messageId, f.key, MAX_FILE_BYTES, "file");
52354
+ const r = await deps.fetchResource(env.appId, ownerMessageId, f.key, MAX_FILE_BYTES, "file");
52356
52355
  if (r.data.byteLength > MAX_FILE_BYTES) {
52357
52356
  deps.logger?.warn(`larkBot file oversize ${f.key}: ${r.data.byteLength}B`);
52358
- fileLines.push(FILE_OVERSIZE_TEXT(f.name));
52357
+ lines.push(FILE_OVERSIZE_TEXT(f.name));
52359
52358
  continue;
52360
52359
  }
52361
52360
  const dir = deps.mediaRootFor(env.chatId);
52362
52361
  import_node_fs27.default.mkdirSync(dir, { recursive: true });
52363
- const p2 = import_node_path28.default.join(dir, `${safeMediaName(env.messageId)}-${i}-${safeAttachmentName(f.name)}`);
52362
+ const p2 = import_node_path28.default.join(dir, `${safeMediaName(ownerMessageId)}-${i}-${safeAttachmentName(f.name)}`);
52364
52363
  import_node_fs27.default.writeFileSync(p2, r.data);
52365
- fileLines.push(`[\u6587\u4EF6: ${p2}]\uFF08\u7528 Read \u5DE5\u5177\u67E5\u770B\uFF09`);
52364
+ lines.push(`[\u6587\u4EF6: ${p2}]\uFF08\u7528 Read \u5DE5\u5177\u67E5\u770B\uFF09`);
52366
52365
  } catch (err) {
52367
52366
  deps.logger?.warn(`larkBot file fetch failed ${f.key}: ${err.message}`);
52368
- fileLines.push(FILE_UNAVAILABLE_TEXT(f.name));
52367
+ lines.push(FILE_UNAVAILABLE_TEXT(f.name));
52369
52368
  }
52370
52369
  }
52371
- return [env.text?.trim(), ...imageLines, ...fileLines].filter(Boolean).join("\n");
52370
+ return lines;
52371
+ };
52372
+ const buildSection = async (env) => {
52373
+ const parentLines = env.parentMessageId ? [
52374
+ ...await imageLinesFor(env, env.parentMessageId, env.parentImageKeys ?? []),
52375
+ ...await fileLinesFor(env, env.parentMessageId, env.parentFiles ?? [])
52376
+ ] : [];
52377
+ const imageLines = await imageLinesFor(env, env.messageId, env.imageKeys ?? []);
52378
+ const fileLines = await fileLinesFor(env, env.messageId, env.files ?? []);
52379
+ return [...parentLines, env.text?.trim(), ...imageLines, ...fileLines].filter(Boolean).join("\n");
52372
52380
  };
52373
52381
  const quoteAnnotation = (env, i, idxByMessageId) => {
52374
52382
  if (!env.parentMessageId) return void 0;
@@ -52412,26 +52420,10 @@ ${formatLarkSpeakerReminder(speaker)}`;
52412
52420
  lastActiveAt: Date.now(),
52413
52421
  personaId: last.personaId
52414
52422
  });
52415
- let timedOut = false;
52416
- let timer;
52417
- const timeout = new Promise((resolve6) => {
52418
- timer = setTimeout(() => {
52419
- timedOut = true;
52420
- turn.kill();
52421
- resolve6({ error: "turn timeout" });
52422
- }, timeoutMs);
52423
- });
52424
- let result;
52425
- try {
52426
- result = await Promise.race([turn.ended, timeout]);
52427
- } finally {
52428
- clearTimeout(timer);
52429
- }
52423
+ const result = await turn.ended;
52430
52424
  const replyText = "ok" in result && result.ok ? result.replyText : ERROR_REPLY_TEXT;
52431
52425
  if (!("ok" in result)) {
52432
- deps.logger?.warn(
52433
- `larkBot turn ${timedOut ? "timeout" : "error"} (${last.chatId}): ${result.error}`
52434
- );
52426
+ deps.logger?.warn(`larkBot turn error (${last.chatId}): ${result.error}`);
52435
52427
  }
52436
52428
  const absorbed = envs.slice(0, -1).map((e) => e.eventId);
52437
52429
  for (let attempt = 0; attempt <= replyDelays.length; attempt++) {
@@ -52494,12 +52486,12 @@ ${formatLarkSpeakerReminder(speaker)}`;
52494
52486
  if (batch) {
52495
52487
  batch.envelopes.push(env);
52496
52488
  clearTimeout(batch.timer);
52497
- batch.timer = setTimeout(() => flushPending(env.chatId), timerMsFor(batch.envelopes));
52489
+ batch.timer = setTimeout(() => flushPending(env.chatId), debounceMs);
52498
52490
  } else {
52499
52491
  pending.set(env.chatId, {
52500
52492
  envelopes: [env],
52501
52493
  senderOpenId: sender,
52502
- timer: setTimeout(() => flushPending(env.chatId), timerMsFor([env]))
52494
+ timer: setTimeout(() => flushPending(env.chatId), debounceMs)
52503
52495
  });
52504
52496
  }
52505
52497
  },
@@ -59262,7 +59254,7 @@ function computeMethodAccess(args) {
59262
59254
  }
59263
59255
 
59264
59256
  // src/version.ts
59265
- var version = "0.2.302".length > 0 ? "0.2.302" : "dev";
59257
+ var version = "0.2.304".length > 0 ? "0.2.304" : "dev";
59266
59258
 
59267
59259
  // src/cli-probe/probe.ts
59268
59260
  var fs56 = __toESM(require("fs"), 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawos-dev/clawd",
3
- "version": "0.2.302",
3
+ "version": "0.2.304",
4
4
  "description": "Standalone clawd daemon — Claude Code (and future Codex) session server over WebSocket",
5
5
  "type": "module",
6
6
  "license": "MIT",