fix: resolve ReadableStream cast in skills install
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { Readable } from "node:stream";
|
import { Readable } from "node:stream";
|
||||||
|
import type { ReadableStream as NodeReadableStream } from "node:stream/web";
|
||||||
import { pipeline } from "node:stream/promises";
|
import { pipeline } from "node:stream/promises";
|
||||||
|
|
||||||
import type { ClawdbotConfig } from "../config/config.js";
|
import type { ClawdbotConfig } from "../config/config.js";
|
||||||
@@ -154,10 +155,12 @@ async function downloadFile(
|
|||||||
await ensureDir(path.dirname(destPath));
|
await ensureDir(path.dirname(destPath));
|
||||||
const file = fs.createWriteStream(destPath);
|
const file = fs.createWriteStream(destPath);
|
||||||
const body = response.body;
|
const body = response.body;
|
||||||
|
// Node's Readable.fromWeb expects the node:stream/web type; cast through unknown for DOM streams.
|
||||||
|
const nodeStream = body as unknown as NodeJS.ReadableStream;
|
||||||
const readable =
|
const readable =
|
||||||
typeof (body as NodeJS.ReadableStream).pipe === "function"
|
typeof nodeStream.pipe === "function"
|
||||||
? (body as NodeJS.ReadableStream)
|
? nodeStream
|
||||||
: Readable.fromWeb(body as Parameters<typeof Readable.fromWeb>[0]);
|
: Readable.fromWeb(body as unknown as NodeReadableStream);
|
||||||
await pipeline(readable, file);
|
await pipeline(readable, file);
|
||||||
const stat = await fs.promises.stat(destPath);
|
const stat = await fs.promises.stat(destPath);
|
||||||
return { bytes: stat.size };
|
return { bytes: stat.size };
|
||||||
|
|||||||
Reference in New Issue
Block a user