From 80eaa8cc1ebdb6da609e5c571868a2b05c390754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E9=98=BF=E6=B1=9F=28Relakkes?= =?UTF-8?q?=29?= Date: Sat, 11 Apr 2026 21:14:28 +0800 Subject: [PATCH] fix(adapters): tsconfig-strict types for Dirent and Lark image upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - attachment-store.ts: pin Dirent[] and pass `encoding: 'utf8'` so newer @types/node doesn't infer Dirent - feishu/media.ts: drop Readable.from(buffer) and pass Buffer directly to im.image.create / im.file.create — Lark SDK already accepts Buffer and the stream wrapper trips the stricter Buffer | ReadStream union used on the main branch's tsconfig Co-Authored-By: Claude Opus 4.6 (1M context) --- adapters/common/attachment/attachment-store.ts | 7 +++++-- adapters/feishu/media.ts | 12 +++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/adapters/common/attachment/attachment-store.ts b/adapters/common/attachment/attachment-store.ts index 75cdd7c6..0214f9f3 100644 --- a/adapters/common/attachment/attachment-store.ts +++ b/adapters/common/attachment/attachment-store.ts @@ -12,6 +12,7 @@ import * as fs from 'node:fs/promises' import * as fsSync from 'node:fs' +import type { Dirent } from 'node:fs' import * as path from 'node:path' import * as os from 'node:os' import type { ImPlatform } from './attachment-types.js' @@ -84,9 +85,11 @@ export class AttachmentStore { const now = Date.now() const walk = async (dir: string): Promise => { - let entries: Awaited> + let entries: Dirent[] try { - entries = await fs.readdir(dir, { withFileTypes: true }) + // Pass encoding explicitly so Dirent stays string-typed under + // newer @types/node where the Buffer overload becomes the default. + entries = await fs.readdir(dir, { withFileTypes: true, encoding: 'utf8' }) } catch { return } diff --git a/adapters/feishu/media.ts b/adapters/feishu/media.ts index aa5fff23..a978e999 100644 --- a/adapters/feishu/media.ts +++ b/adapters/feishu/media.ts @@ -12,7 +12,6 @@ import * as Lark from '@larksuiteoapi/node-sdk' import * as fs from 'node:fs/promises' import * as path from 'node:path' -import { Readable } from 'node:stream' import { AttachmentStore } from '../common/attachment/attachment-store.js' import type { LocalAttachment } from '../common/attachment/attachment-types.js' @@ -123,13 +122,13 @@ export class FeishuMediaService { } /** Upload an image buffer, returns image_key. - * node-sdk expects `image` to be a readable stream (see OpenClaw media.ts:290). - * We use Readable.from(buffer) to avoid spilling to disk for pure in-memory buffers. */ + * The Lark node-sdk type for `image` accepts `Buffer | ReadStream`, + * so passing the buffer directly is the simplest path. */ async uploadImage(buffer: Buffer, _mime: string): Promise { const resp: any = await this.client.im.image.create({ data: { image_type: 'message', - image: Readable.from(buffer), + image: buffer, }, }) const key = resp?.data?.image_key @@ -137,14 +136,13 @@ export class FeishuMediaService { return key } - /** Upload a non-image file, returns file_key. - * See OpenClaw media.ts:334 for stream-based upload pattern. */ + /** Upload a non-image file, returns file_key. */ async uploadFile(buffer: Buffer, fileName: string): Promise { const resp: any = await this.client.im.file.create({ data: { file_type: detectFeishuFileType(fileName), file_name: fileName, - file: Readable.from(buffer), + file: buffer, }, }) const key = resp?.data?.file_key