@clawos-dev/clawd 0.2.303 → 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.
- package/dist/cli.cjs +34 -49
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -52285,9 +52285,7 @@ var import_node_fs27 = __toESM(require("fs"), 1);
|
|
|
52285
52285
|
var import_node_path28 = __toESM(require("path"), 1);
|
|
52286
52286
|
init_protocol();
|
|
52287
52287
|
var ERROR_REPLY_TEXT = "\u5904\u7406\u51FA\u9519\u4E86\uFF0C\u8BF7\u91CD\u8BD5";
|
|
52288
|
-
var DEFAULT_TURN_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
52289
52288
|
var DEBOUNCE_MS = 1e3;
|
|
52290
|
-
var CONTENT_HOLD_MS = 6e4;
|
|
52291
52289
|
var MAX_IMAGE_BYTES = 8 * 1024 * 1024;
|
|
52292
52290
|
var EXT_BY_MIME = {
|
|
52293
52291
|
"image/png": "png",
|
|
@@ -52313,69 +52311,72 @@ function safeAttachmentName(raw) {
|
|
|
52313
52311
|
return cleaned.slice(0, 100 - ext.length) + ext;
|
|
52314
52312
|
}
|
|
52315
52313
|
function createLarkChatRouter(deps) {
|
|
52316
|
-
const timeoutMs = deps.turnTimeoutMs ?? DEFAULT_TURN_TIMEOUT_MS;
|
|
52317
52314
|
const replyDelays = deps.replyRetryDelaysMs ?? [2e3, 8e3, 3e4];
|
|
52318
52315
|
const sleep2 = deps.sleepImpl ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
52319
52316
|
const debounceMs = deps.debounceMs ?? DEBOUNCE_MS;
|
|
52320
|
-
const contentHoldMs = deps.contentHoldMs ?? CONTENT_HOLD_MS;
|
|
52321
|
-
const timerMsFor = (envs) => {
|
|
52322
|
-
if (envs.some((e) => e.text?.trim())) return debounceMs;
|
|
52323
|
-
const hasContent = envs.some(
|
|
52324
|
-
(e) => (e.imageKeys?.length ?? 0) > 0 || (e.files?.length ?? 0) > 0
|
|
52325
|
-
);
|
|
52326
|
-
return hasContent ? contentHoldMs : debounceMs;
|
|
52327
|
-
};
|
|
52328
52317
|
const queues = /* @__PURE__ */ new Map();
|
|
52329
52318
|
const activity = /* @__PURE__ */ new Map();
|
|
52330
52319
|
const pending = /* @__PURE__ */ new Map();
|
|
52331
|
-
const
|
|
52332
|
-
const
|
|
52333
|
-
for (const [i, key] of
|
|
52320
|
+
const imageLinesFor = async (env, ownerMessageId, keys) => {
|
|
52321
|
+
const lines = [];
|
|
52322
|
+
for (const [i, key] of keys.entries()) {
|
|
52334
52323
|
try {
|
|
52335
52324
|
if (!deps.fetchResource || !deps.mediaRootFor) throw new Error("resource pipeline not wired");
|
|
52336
|
-
const r = await deps.fetchResource(env.appId,
|
|
52325
|
+
const r = await deps.fetchResource(env.appId, ownerMessageId, key, MAX_IMAGE_BYTES, "image");
|
|
52337
52326
|
if (r.data.byteLength > MAX_IMAGE_BYTES) {
|
|
52338
52327
|
deps.logger?.warn(`larkBot image oversize ${key}: ${r.data.byteLength}B`);
|
|
52339
|
-
|
|
52328
|
+
lines.push(IMAGE_OVERSIZE_TEXT);
|
|
52340
52329
|
continue;
|
|
52341
52330
|
}
|
|
52342
52331
|
const ext = EXT_BY_MIME[r.contentType];
|
|
52343
52332
|
if (!ext) {
|
|
52344
52333
|
deps.logger?.warn(`larkBot image unsupported mime ${key}: ${r.contentType}`);
|
|
52345
|
-
|
|
52334
|
+
lines.push(IMAGE_UNAVAILABLE_TEXT);
|
|
52346
52335
|
continue;
|
|
52347
52336
|
}
|
|
52348
52337
|
const dir = deps.mediaRootFor(env.chatId);
|
|
52349
52338
|
import_node_fs27.default.mkdirSync(dir, { recursive: true });
|
|
52350
|
-
const p2 = import_node_path28.default.join(dir, `${safeMediaName(
|
|
52339
|
+
const p2 = import_node_path28.default.join(dir, `${safeMediaName(ownerMessageId)}-${i}.${ext}`);
|
|
52351
52340
|
import_node_fs27.default.writeFileSync(p2, r.data);
|
|
52352
|
-
|
|
52341
|
+
lines.push(`[\u56FE\u7247: ${p2}]\uFF08\u7528 Read \u5DE5\u5177\u67E5\u770B\uFF09`);
|
|
52353
52342
|
} catch (err) {
|
|
52354
52343
|
deps.logger?.warn(`larkBot image fetch failed ${key}: ${err.message}`);
|
|
52355
|
-
|
|
52344
|
+
lines.push(IMAGE_UNAVAILABLE_TEXT);
|
|
52356
52345
|
}
|
|
52357
52346
|
}
|
|
52358
|
-
|
|
52359
|
-
|
|
52347
|
+
return lines;
|
|
52348
|
+
};
|
|
52349
|
+
const fileLinesFor = async (env, ownerMessageId, entries) => {
|
|
52350
|
+
const lines = [];
|
|
52351
|
+
for (const [i, f] of entries.entries()) {
|
|
52360
52352
|
try {
|
|
52361
52353
|
if (!deps.fetchResource || !deps.mediaRootFor) throw new Error("resource pipeline not wired");
|
|
52362
|
-
const r = await deps.fetchResource(env.appId,
|
|
52354
|
+
const r = await deps.fetchResource(env.appId, ownerMessageId, f.key, MAX_FILE_BYTES, "file");
|
|
52363
52355
|
if (r.data.byteLength > MAX_FILE_BYTES) {
|
|
52364
52356
|
deps.logger?.warn(`larkBot file oversize ${f.key}: ${r.data.byteLength}B`);
|
|
52365
|
-
|
|
52357
|
+
lines.push(FILE_OVERSIZE_TEXT(f.name));
|
|
52366
52358
|
continue;
|
|
52367
52359
|
}
|
|
52368
52360
|
const dir = deps.mediaRootFor(env.chatId);
|
|
52369
52361
|
import_node_fs27.default.mkdirSync(dir, { recursive: true });
|
|
52370
|
-
const p2 = import_node_path28.default.join(dir, `${safeMediaName(
|
|
52362
|
+
const p2 = import_node_path28.default.join(dir, `${safeMediaName(ownerMessageId)}-${i}-${safeAttachmentName(f.name)}`);
|
|
52371
52363
|
import_node_fs27.default.writeFileSync(p2, r.data);
|
|
52372
|
-
|
|
52364
|
+
lines.push(`[\u6587\u4EF6: ${p2}]\uFF08\u7528 Read \u5DE5\u5177\u67E5\u770B\uFF09`);
|
|
52373
52365
|
} catch (err) {
|
|
52374
52366
|
deps.logger?.warn(`larkBot file fetch failed ${f.key}: ${err.message}`);
|
|
52375
|
-
|
|
52367
|
+
lines.push(FILE_UNAVAILABLE_TEXT(f.name));
|
|
52376
52368
|
}
|
|
52377
52369
|
}
|
|
52378
|
-
return
|
|
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");
|
|
52379
52380
|
};
|
|
52380
52381
|
const quoteAnnotation = (env, i, idxByMessageId) => {
|
|
52381
52382
|
if (!env.parentMessageId) return void 0;
|
|
@@ -52419,26 +52420,10 @@ ${formatLarkSpeakerReminder(speaker)}`;
|
|
|
52419
52420
|
lastActiveAt: Date.now(),
|
|
52420
52421
|
personaId: last.personaId
|
|
52421
52422
|
});
|
|
52422
|
-
|
|
52423
|
-
let timer;
|
|
52424
|
-
const timeout = new Promise((resolve6) => {
|
|
52425
|
-
timer = setTimeout(() => {
|
|
52426
|
-
timedOut = true;
|
|
52427
|
-
turn.kill();
|
|
52428
|
-
resolve6({ error: "turn timeout" });
|
|
52429
|
-
}, timeoutMs);
|
|
52430
|
-
});
|
|
52431
|
-
let result;
|
|
52432
|
-
try {
|
|
52433
|
-
result = await Promise.race([turn.ended, timeout]);
|
|
52434
|
-
} finally {
|
|
52435
|
-
clearTimeout(timer);
|
|
52436
|
-
}
|
|
52423
|
+
const result = await turn.ended;
|
|
52437
52424
|
const replyText = "ok" in result && result.ok ? result.replyText : ERROR_REPLY_TEXT;
|
|
52438
52425
|
if (!("ok" in result)) {
|
|
52439
|
-
deps.logger?.warn(
|
|
52440
|
-
`larkBot turn ${timedOut ? "timeout" : "error"} (${last.chatId}): ${result.error}`
|
|
52441
|
-
);
|
|
52426
|
+
deps.logger?.warn(`larkBot turn error (${last.chatId}): ${result.error}`);
|
|
52442
52427
|
}
|
|
52443
52428
|
const absorbed = envs.slice(0, -1).map((e) => e.eventId);
|
|
52444
52429
|
for (let attempt = 0; attempt <= replyDelays.length; attempt++) {
|
|
@@ -52501,12 +52486,12 @@ ${formatLarkSpeakerReminder(speaker)}`;
|
|
|
52501
52486
|
if (batch) {
|
|
52502
52487
|
batch.envelopes.push(env);
|
|
52503
52488
|
clearTimeout(batch.timer);
|
|
52504
|
-
batch.timer = setTimeout(() => flushPending(env.chatId),
|
|
52489
|
+
batch.timer = setTimeout(() => flushPending(env.chatId), debounceMs);
|
|
52505
52490
|
} else {
|
|
52506
52491
|
pending.set(env.chatId, {
|
|
52507
52492
|
envelopes: [env],
|
|
52508
52493
|
senderOpenId: sender,
|
|
52509
|
-
timer: setTimeout(() => flushPending(env.chatId),
|
|
52494
|
+
timer: setTimeout(() => flushPending(env.chatId), debounceMs)
|
|
52510
52495
|
});
|
|
52511
52496
|
}
|
|
52512
52497
|
},
|
|
@@ -59269,7 +59254,7 @@ function computeMethodAccess(args) {
|
|
|
59269
59254
|
}
|
|
59270
59255
|
|
|
59271
59256
|
// src/version.ts
|
|
59272
|
-
var version = "0.2.
|
|
59257
|
+
var version = "0.2.304".length > 0 ? "0.2.304" : "dev";
|
|
59273
59258
|
|
|
59274
59259
|
// src/cli-probe/probe.ts
|
|
59275
59260
|
var fs56 = __toESM(require("fs"), 1);
|