liangzimixin 0.3.62 → 0.3.64

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/index.cjs CHANGED
@@ -18432,10 +18432,31 @@ async function resolveAndUploadMedia(params) {
18432
18432
  const fileType = detectFileType(fileName);
18433
18433
  const mimeType = inferMimeType(fileName);
18434
18434
  const ext = path2.extname(fileName).replace(".", "").toLowerCase();
18435
+ const MIN_IMAGE_SIZE = 100;
18436
+ if (fileType === "image" && buffer.length < MIN_IMAGE_SIZE) {
18437
+ log5.error("media:invalid image \u2014 \u6587\u4EF6\u8FC7\u5C0F\uFF0C\u4E0D\u662F\u5408\u6CD5\u56FE\u7247", {
18438
+ fileName,
18439
+ fileSize: buffer.length,
18440
+ minRequired: MIN_IMAGE_SIZE
18441
+ });
18442
+ throw new FileServiceError({
18443
+ message: `\u56FE\u7247\u6587\u4EF6\u65E0\u6548: ${fileName} \u4EC5 ${buffer.length} \u5B57\u8282\uFF0C\u8FDC\u5C0F\u4E8E\u5408\u6CD5\u56FE\u7247\u7684\u6700\u5C0F\u5927\u5C0F (${MIN_IMAGE_SIZE} \u5B57\u8282)`,
18444
+ code: -1,
18445
+ operationContext: `resolveAndUploadMedia:imageValidation(${fileName})`
18446
+ });
18447
+ }
18435
18448
  let imageDimensions;
18436
18449
  if (fileType === "image") {
18437
18450
  imageDimensions = getImageDimensions(buffer);
18438
- log5.info("media:imageDimensions", { fileName, ...imageDimensions });
18451
+ if (!imageDimensions) {
18452
+ log5.warn("media:imageDimensions failed \u2014 \u65E0\u6CD5\u89E3\u6790\u56FE\u7247\u5BBD\u9AD8\uFF0C\u6587\u4EF6\u53EF\u80FD\u635F\u574F", {
18453
+ fileName,
18454
+ fileSize: buffer.length,
18455
+ headerHex: buffer.subarray(0, Math.min(16, buffer.length)).toString("hex")
18456
+ });
18457
+ } else {
18458
+ log5.info("media:imageDimensions", { fileName, ...imageDimensions });
18459
+ }
18439
18460
  }
18440
18461
  log5.info("media:fileType", { fileName, fileType, mimeType, ext });
18441
18462
  const originalFileSize = buffer.length;
@@ -19171,22 +19192,56 @@ var InboundPipeline = class {
19171
19192
  command: context.text.trim()
19172
19193
  });
19173
19194
  const cmdPayload = buildInboundPayload(msg, { text: context.text }, this.deps.pluginConfig);
19195
+ log15.info("\u{1F50D} [DEBUG] cmdPayload \u5173\u952E\u5B57\u6BB5", {
19196
+ messageId: msg.messageId,
19197
+ CommandAuthorized: cmdPayload.CommandAuthorized ?? "\u26A0\uFE0F \u672A\u8BBE\u7F6E",
19198
+ CommandBody: String(cmdPayload.CommandBody ?? "").slice(0, 100),
19199
+ RawBody: String(cmdPayload.RawBody ?? "").slice(0, 100),
19200
+ SessionKey: cmdPayload.SessionKey,
19201
+ AccountId: cmdPayload.AccountId,
19202
+ Surface: cmdPayload.Surface,
19203
+ Provider: cmdPayload.Provider,
19204
+ From: cmdPayload.From,
19205
+ To: cmdPayload.To,
19206
+ ChatType: cmdPayload.ChatType,
19207
+ payloadKeys: Object.keys(cmdPayload)
19208
+ });
19174
19209
  const cmdCtx = core.channel.reply.finalizeInboundContext(cmdPayload);
19210
+ log15.info("\u{1F50D} [DEBUG] cmdCtx (finalizeInboundContext \u4E4B\u540E)", {
19211
+ messageId: msg.messageId,
19212
+ CommandAuthorized: cmdCtx.CommandAuthorized ?? "\u26A0\uFE0F \u672A\u8BBE\u7F6E",
19213
+ CommandBody: String(cmdCtx.CommandBody ?? "").slice(0, 100),
19214
+ SessionKey: cmdCtx.SessionKey,
19215
+ ctxKeys: Object.keys(cmdCtx)
19216
+ });
19175
19217
  const cmdSkipEncrypt = this.deps.pluginConfig.credentials.encryptionMode === "quantum_only" ? false : true;
19176
- await core.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
19218
+ let deliverCalled = false;
19219
+ let deliverCallCount = 0;
19220
+ log15.info("\u{1F680} [DEBUG] \u5F00\u59CB dispatchReplyWithBufferedBlockDispatcher", {
19221
+ messageId: msg.messageId,
19222
+ command: context.text.trim()
19223
+ });
19224
+ const dispatchResult = await core.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
19177
19225
  ctx: cmdCtx,
19178
19226
  cfg: this.deps.sdkConfig,
19179
19227
  dispatcherOptions: {
19180
19228
  deliver: async (payload2) => {
19229
+ deliverCallCount++;
19230
+ deliverCalled = true;
19181
19231
  log15.info("\u{1F527} \u547D\u4EE4 deliver \u56DE\u8C03\u6536\u5230", {
19182
19232
  messageId: msg.messageId,
19233
+ callIndex: deliverCallCount,
19183
19234
  hasText: Boolean(payload2.text),
19184
19235
  textLength: payload2.text?.length ?? 0,
19185
- textPreview: (payload2.text ?? "").slice(0, 200),
19186
- payloadKeys: Object.keys(payload2)
19236
+ textPreview: (payload2.text ?? "").slice(0, 500),
19237
+ payloadKeys: Object.keys(payload2),
19238
+ fullPayload: JSON.stringify(payload2).slice(0, 1e3)
19187
19239
  });
19188
19240
  const text = (payload2.text ?? "").trim();
19189
- if (!text) return;
19241
+ if (!text) {
19242
+ log15.warn("\u26A0\uFE0F deliver \u6536\u5230\u7A7A\u6587\u672C\uFF0C\u8DF3\u8FC7\u53D1\u9001", { messageId: msg.messageId });
19243
+ return;
19244
+ }
19190
19245
  await this.deps.messagePipe.sendMessage({
19191
19246
  chatId: msg.chatId,
19192
19247
  senderId: msg.senderId,
@@ -19195,17 +19250,58 @@ var InboundPipeline = class {
19195
19250
  skipEncrypt: cmdSkipEncrypt
19196
19251
  });
19197
19252
  },
19198
- onError: (err) => {
19199
- log15.error("\u274C \u547D\u4EE4\u56DE\u590D\u53D1\u9001\u5931\u8D25", { error: String(err) });
19253
+ onSkip: (payload2, info) => {
19254
+ log15.warn("\u23ED\uFE0F [DEBUG] dispatcher onSkip", {
19255
+ messageId: msg.messageId,
19256
+ reason: info?.reason,
19257
+ payload: JSON.stringify(payload2).slice(0, 300)
19258
+ });
19259
+ },
19260
+ onError: (err, info) => {
19261
+ log15.error("\u274C \u547D\u4EE4\u56DE\u590D\u9519\u8BEF", {
19262
+ messageId: msg.messageId,
19263
+ error: String(err),
19264
+ errorStack: err?.stack?.slice(0, 500),
19265
+ kind: info?.kind
19266
+ });
19200
19267
  }
19201
19268
  },
19202
19269
  replyOptions: {}
19203
19270
  });
19271
+ log15.info("\u{1F3C1} [DEBUG] dispatchReplyWithBufferedBlockDispatcher \u5B8C\u6210", {
19272
+ messageId: msg.messageId,
19273
+ command: context.text.trim(),
19274
+ deliverCalled,
19275
+ deliverCallCount,
19276
+ dispatchResult: JSON.stringify(dispatchResult ?? null).slice(0, 500)
19277
+ });
19278
+ if (!deliverCalled) {
19279
+ const command = context.text.trim();
19280
+ const fallbackMessages = {
19281
+ "/new": "\u2705 \u4F1A\u8BDD\u5DF2\u91CD\u7F6E\uFF0C\u53EF\u4EE5\u5F00\u59CB\u65B0\u7684\u5BF9\u8BDD\u4E86\u3002",
19282
+ "/reset": "\u2705 \u4F1A\u8BDD\u5DF2\u91CD\u7F6E\uFF0C\u53EF\u4EE5\u5F00\u59CB\u65B0\u7684\u5BF9\u8BDD\u4E86\u3002"
19283
+ };
19284
+ const fallbackText = fallbackMessages[command] ?? `\u2705 \u547D\u4EE4 \`${command}\` \u5DF2\u6267\u884C\u3002`;
19285
+ log15.info("\u{1F4E8} SDK \u672A\u56DE\u8C03 deliver\uFF0C\u53D1\u9001\u56DE\u9000\u786E\u8BA4\u6D88\u606F", {
19286
+ messageId: msg.messageId,
19287
+ command
19288
+ });
19289
+ await this.deps.messagePipe.sendMessage({
19290
+ chatId: msg.chatId,
19291
+ senderId: msg.senderId,
19292
+ msgType: "markdown",
19293
+ content: JSON.stringify({ content: fallbackText }),
19294
+ skipEncrypt: cmdSkipEncrypt
19295
+ }).catch((err) => {
19296
+ log15.warn("\u26A0\uFE0F \u56DE\u9000\u786E\u8BA4\u6D88\u606F\u53D1\u9001\u5931\u8D25", { error: err.message });
19297
+ });
19298
+ }
19204
19299
  clearInboundEncryptionStatus(msg.chatId, msg.messageId);
19205
19300
  const durationMs2 = Date.now() - startMs;
19206
19301
  log15.info("\u2705 \u7CFB\u7EDF\u547D\u4EE4\u5904\u7406\u5B8C\u6210", {
19207
19302
  messageId: msg.messageId,
19208
19303
  command: context.text.trim(),
19304
+ deliverCalled,
19209
19305
  \u8017\u65F6ms: durationMs2
19210
19306
  });
19211
19307
  return;
@@ -4505,10 +4505,31 @@ async function resolveAndUploadMedia(params) {
4505
4505
  const fileType = detectFileType(fileName);
4506
4506
  const mimeType = inferMimeType(fileName);
4507
4507
  const ext = path2.extname(fileName).replace(".", "").toLowerCase();
4508
+ const MIN_IMAGE_SIZE = 100;
4509
+ if (fileType === "image" && buffer.length < MIN_IMAGE_SIZE) {
4510
+ log5.error("media:invalid image \u2014 \u6587\u4EF6\u8FC7\u5C0F\uFF0C\u4E0D\u662F\u5408\u6CD5\u56FE\u7247", {
4511
+ fileName,
4512
+ fileSize: buffer.length,
4513
+ minRequired: MIN_IMAGE_SIZE
4514
+ });
4515
+ throw new FileServiceError({
4516
+ message: `\u56FE\u7247\u6587\u4EF6\u65E0\u6548: ${fileName} \u4EC5 ${buffer.length} \u5B57\u8282\uFF0C\u8FDC\u5C0F\u4E8E\u5408\u6CD5\u56FE\u7247\u7684\u6700\u5C0F\u5927\u5C0F (${MIN_IMAGE_SIZE} \u5B57\u8282)`,
4517
+ code: -1,
4518
+ operationContext: `resolveAndUploadMedia:imageValidation(${fileName})`
4519
+ });
4520
+ }
4508
4521
  let imageDimensions;
4509
4522
  if (fileType === "image") {
4510
4523
  imageDimensions = getImageDimensions(buffer);
4511
- log5.info("media:imageDimensions", { fileName, ...imageDimensions });
4524
+ if (!imageDimensions) {
4525
+ log5.warn("media:imageDimensions failed \u2014 \u65E0\u6CD5\u89E3\u6790\u56FE\u7247\u5BBD\u9AD8\uFF0C\u6587\u4EF6\u53EF\u80FD\u635F\u574F", {
4526
+ fileName,
4527
+ fileSize: buffer.length,
4528
+ headerHex: buffer.subarray(0, Math.min(16, buffer.length)).toString("hex")
4529
+ });
4530
+ } else {
4531
+ log5.info("media:imageDimensions", { fileName, ...imageDimensions });
4532
+ }
4512
4533
  }
4513
4534
  log5.info("media:fileType", { fileName, fileType, mimeType, ext });
4514
4535
  const originalFileSize = buffer.length;
@@ -21469,22 +21490,56 @@ var InboundPipeline = class {
21469
21490
  command: context.text.trim()
21470
21491
  });
21471
21492
  const cmdPayload = buildInboundPayload(msg, { text: context.text }, this.deps.pluginConfig);
21493
+ log28.info("\u{1F50D} [DEBUG] cmdPayload \u5173\u952E\u5B57\u6BB5", {
21494
+ messageId: msg.messageId,
21495
+ CommandAuthorized: cmdPayload.CommandAuthorized ?? "\u26A0\uFE0F \u672A\u8BBE\u7F6E",
21496
+ CommandBody: String(cmdPayload.CommandBody ?? "").slice(0, 100),
21497
+ RawBody: String(cmdPayload.RawBody ?? "").slice(0, 100),
21498
+ SessionKey: cmdPayload.SessionKey,
21499
+ AccountId: cmdPayload.AccountId,
21500
+ Surface: cmdPayload.Surface,
21501
+ Provider: cmdPayload.Provider,
21502
+ From: cmdPayload.From,
21503
+ To: cmdPayload.To,
21504
+ ChatType: cmdPayload.ChatType,
21505
+ payloadKeys: Object.keys(cmdPayload)
21506
+ });
21472
21507
  const cmdCtx = core.channel.reply.finalizeInboundContext(cmdPayload);
21508
+ log28.info("\u{1F50D} [DEBUG] cmdCtx (finalizeInboundContext \u4E4B\u540E)", {
21509
+ messageId: msg.messageId,
21510
+ CommandAuthorized: cmdCtx.CommandAuthorized ?? "\u26A0\uFE0F \u672A\u8BBE\u7F6E",
21511
+ CommandBody: String(cmdCtx.CommandBody ?? "").slice(0, 100),
21512
+ SessionKey: cmdCtx.SessionKey,
21513
+ ctxKeys: Object.keys(cmdCtx)
21514
+ });
21473
21515
  const cmdSkipEncrypt = this.deps.pluginConfig.credentials.encryptionMode === "quantum_only" ? false : true;
21474
- await core.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
21516
+ let deliverCalled = false;
21517
+ let deliverCallCount = 0;
21518
+ log28.info("\u{1F680} [DEBUG] \u5F00\u59CB dispatchReplyWithBufferedBlockDispatcher", {
21519
+ messageId: msg.messageId,
21520
+ command: context.text.trim()
21521
+ });
21522
+ const dispatchResult = await core.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
21475
21523
  ctx: cmdCtx,
21476
21524
  cfg: this.deps.sdkConfig,
21477
21525
  dispatcherOptions: {
21478
21526
  deliver: async (payload2) => {
21527
+ deliverCallCount++;
21528
+ deliverCalled = true;
21479
21529
  log28.info("\u{1F527} \u547D\u4EE4 deliver \u56DE\u8C03\u6536\u5230", {
21480
21530
  messageId: msg.messageId,
21531
+ callIndex: deliverCallCount,
21481
21532
  hasText: Boolean(payload2.text),
21482
21533
  textLength: payload2.text?.length ?? 0,
21483
- textPreview: (payload2.text ?? "").slice(0, 200),
21484
- payloadKeys: Object.keys(payload2)
21534
+ textPreview: (payload2.text ?? "").slice(0, 500),
21535
+ payloadKeys: Object.keys(payload2),
21536
+ fullPayload: JSON.stringify(payload2).slice(0, 1e3)
21485
21537
  });
21486
21538
  const text = (payload2.text ?? "").trim();
21487
- if (!text) return;
21539
+ if (!text) {
21540
+ log28.warn("\u26A0\uFE0F deliver \u6536\u5230\u7A7A\u6587\u672C\uFF0C\u8DF3\u8FC7\u53D1\u9001", { messageId: msg.messageId });
21541
+ return;
21542
+ }
21488
21543
  await this.deps.messagePipe.sendMessage({
21489
21544
  chatId: msg.chatId,
21490
21545
  senderId: msg.senderId,
@@ -21493,17 +21548,58 @@ var InboundPipeline = class {
21493
21548
  skipEncrypt: cmdSkipEncrypt
21494
21549
  });
21495
21550
  },
21496
- onError: (err) => {
21497
- log28.error("\u274C \u547D\u4EE4\u56DE\u590D\u53D1\u9001\u5931\u8D25", { error: String(err) });
21551
+ onSkip: (payload2, info) => {
21552
+ log28.warn("\u23ED\uFE0F [DEBUG] dispatcher onSkip", {
21553
+ messageId: msg.messageId,
21554
+ reason: info?.reason,
21555
+ payload: JSON.stringify(payload2).slice(0, 300)
21556
+ });
21557
+ },
21558
+ onError: (err, info) => {
21559
+ log28.error("\u274C \u547D\u4EE4\u56DE\u590D\u9519\u8BEF", {
21560
+ messageId: msg.messageId,
21561
+ error: String(err),
21562
+ errorStack: err?.stack?.slice(0, 500),
21563
+ kind: info?.kind
21564
+ });
21498
21565
  }
21499
21566
  },
21500
21567
  replyOptions: {}
21501
21568
  });
21569
+ log28.info("\u{1F3C1} [DEBUG] dispatchReplyWithBufferedBlockDispatcher \u5B8C\u6210", {
21570
+ messageId: msg.messageId,
21571
+ command: context.text.trim(),
21572
+ deliverCalled,
21573
+ deliverCallCount,
21574
+ dispatchResult: JSON.stringify(dispatchResult ?? null).slice(0, 500)
21575
+ });
21576
+ if (!deliverCalled) {
21577
+ const command = context.text.trim();
21578
+ const fallbackMessages = {
21579
+ "/new": "\u2705 \u4F1A\u8BDD\u5DF2\u91CD\u7F6E\uFF0C\u53EF\u4EE5\u5F00\u59CB\u65B0\u7684\u5BF9\u8BDD\u4E86\u3002",
21580
+ "/reset": "\u2705 \u4F1A\u8BDD\u5DF2\u91CD\u7F6E\uFF0C\u53EF\u4EE5\u5F00\u59CB\u65B0\u7684\u5BF9\u8BDD\u4E86\u3002"
21581
+ };
21582
+ const fallbackText = fallbackMessages[command] ?? `\u2705 \u547D\u4EE4 \`${command}\` \u5DF2\u6267\u884C\u3002`;
21583
+ log28.info("\u{1F4E8} SDK \u672A\u56DE\u8C03 deliver\uFF0C\u53D1\u9001\u56DE\u9000\u786E\u8BA4\u6D88\u606F", {
21584
+ messageId: msg.messageId,
21585
+ command
21586
+ });
21587
+ await this.deps.messagePipe.sendMessage({
21588
+ chatId: msg.chatId,
21589
+ senderId: msg.senderId,
21590
+ msgType: "markdown",
21591
+ content: JSON.stringify({ content: fallbackText }),
21592
+ skipEncrypt: cmdSkipEncrypt
21593
+ }).catch((err) => {
21594
+ log28.warn("\u26A0\uFE0F \u56DE\u9000\u786E\u8BA4\u6D88\u606F\u53D1\u9001\u5931\u8D25", { error: err.message });
21595
+ });
21596
+ }
21502
21597
  clearInboundEncryptionStatus(msg.chatId, msg.messageId);
21503
21598
  const durationMs2 = Date.now() - startMs;
21504
21599
  log28.info("\u2705 \u7CFB\u7EDF\u547D\u4EE4\u5904\u7406\u5B8C\u6210", {
21505
21600
  messageId: msg.messageId,
21506
21601
  command: context.text.trim(),
21602
+ deliverCalled,
21507
21603
  \u8017\u65F6ms: durationMs2
21508
21604
  });
21509
21605
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "liangzimixin",
3
- "version": "0.3.62",
3
+ "version": "0.3.64",
4
4
  "description": "Quantum-encrypted IM channel plugin for OpenClaw",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",