An open-source, faster Devin alternative
TypeScript
drop writeStream/readStream
Brian Reardon63e778f8318d
diff --git a/sdks/python/opencomputer/filesystem.py b/sdks/python/opencomputer/filesystem.pyindex 3da34b47..8bd15c4c 100644--- a/sdks/python/opencomputer/filesystem.py+++ b/sdks/python/opencomputer/filesystem.py@@ -43,9 +43,12 @@ class Filesystem:resp.raise_for_status()return resp.content- async def write(self, path: str, content: str | bytes) -> None:- """Write content to a file."""- data = content if isinstance(content, bytes) else content.encode()+ async def write(self, path: str, content: str | bytes | AsyncIterator[bytes]) -> None:+ """Write content to a file. Accepts str, bytes, or an async iterator of bytes for streaming."""+ if isinstance(content, (str, bytes)):+ data: str | bytes | AsyncIterator[bytes] = content if isinstance(content, bytes) else content.encode()+ else:+ data = contentresp = await self._client.put(f"/sandboxes/{self._sandbox_id}/files",params={"path": path},@@ -89,26 +92,6 @@ class Filesystem:)resp.raise_for_status()- async def read_stream(self, path: str) -> AsyncIterator[bytes]:- """Stream a file as async byte chunks. Avoids buffering the full file in memory."""- req = self._client.build_request(- "GET",- f"/sandboxes/{self._sandbox_id}/files",- params={"path": path},- )- resp = await self._client.send(req, stream=True)- resp.raise_for_status()- return resp.aiter_bytes()-- async def write_stream(self, path: str, stream: AsyncIterator[bytes]) -> None:- """Stream content to a file from an async iterator. Avoids buffering the full file in memory."""- resp = await self._client.put(- f"/sandboxes/{self._sandbox_id}/files",- params={"path": path},- content=stream,- )- resp.raise_for_status()-async def exists(self, path: str) -> bool:"""Check if a path exists."""try:diff --git a/sdks/typescript/src/filesystem.ts b/sdks/typescript/src/filesystem.tsindex 433a66c8..0f0ff369 100644--- a/sdks/typescript/src/filesystem.ts+++ b/sdks/typescript/src/filesystem.ts@@ -36,14 +36,20 @@ export class Filesystem {return new Uint8Array(await resp.arrayBuffer());}- async write(path: string, content: string | Uint8Array): Promise<void> {+ async write(path: string, content: string | Uint8Array | ReadableStream<Uint8Array>): Promise<void> {+ const opts: RequestInit & Record<string, unknown> = {+ method: "PUT",+ headers: this.headers,+ body: content as BodyInit,+ };+ // duplex: "half" is required for ReadableStream bodies in Node.js fetch,+ // but must NOT be set for Uint8Array/Buffer/string bodies.+ if (content instanceof ReadableStream) {+ opts.duplex = "half";+ }const resp = await fetch(`${this.apiUrl}/sandboxes/${this.sandboxId}/files?path=${encodeURIComponent(path)}`,- {- method: "PUT",- headers: this.headers,- body: content as BodyInit,- },+ opts,);if (!resp.ok) throw new Error(`Failed to write ${path}: ${resp.status}`);}@@ -74,42 +80,6 @@ export class Filesystem {if (!resp.ok) throw new Error(`Failed to remove ${path}: ${resp.status}`);}- /**- * Returns the raw response body as a ReadableStream for large file downloads.- * Avoids buffering the entire file in memory.- */- async readStream(path: string): Promise<ReadableStream<Uint8Array>> {- const resp = await fetch(- `${this.apiUrl}/sandboxes/${this.sandboxId}/files?path=${encodeURIComponent(path)}`,- { headers: this.headers },- );- if (!resp.ok) throw new Error(`Failed to read ${path}: ${resp.status}`);- if (!resp.body) throw new Error(`No response body for ${path}`);- return resp.body;- }-- /**- * Streams a ReadableStream or Uint8Array as the request body for large file uploads.- * Avoids buffering the entire file in memory when given a ReadableStream.- */- async writeStream(path: string, stream: ReadableStream<Uint8Array> | Uint8Array): Promise<void> {- const opts: RequestInit & Record<string, unknown> = {- method: "PUT",- headers: this.headers,- body: stream as BodyInit,- };- // duplex: "half" is required for ReadableStream bodies in Node.js fetch,- // but must NOT be set for Uint8Array/Buffer bodies.- if (stream instanceof ReadableStream) {- opts.duplex = "half";- }- const resp = await fetch(- `${this.apiUrl}/sandboxes/${this.sandboxId}/files?path=${encodeURIComponent(path)}`,- opts,- );- if (!resp.ok) throw new Error(`Failed to write ${path}: ${resp.status}`);- }-async exists(path: string): Promise<boolean> {try {const resp = await fetch(