Skip to content

feat(server): add fs.write endpoint - #49466

Merged
Hona merged 1 commit into
v2from
fs-write
Sep 17, 2026
Merged

Hona merged 1 commit into
v2from
fs-write

Conversation

@Hona

@Hona Hona commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Adds POST /api/experimental/fs/write so a client can put raw bytes on the server's filesystem. First consumer: #49467 stages attachments the model can't read natively under the server tmp dir.

flowchart LR
  C[Client] -- "POST /api/experimental/fs/write?path=…<br/>body: raw bytes (application/octet-stream)" --> S[Server]
  S -- "path.resolve(location.directory, path)" --> R{absolute?}
  R -- yes --> A["/any/where/file.bin"]
  R -- no --> L["&lt;location&gt;/relative/file.bin"]
  A & L --> W["writeWithDirs → { path: resolved }"]
Loading
// packages/protocol/src/groups/fs.ts
HttpApiEndpoint.post("fs.write", "/api/experimental/fs/write", {
  query: WriteQuery,                                             // location + path
  payload: Schema.Uint8Array.pipe(HttpApiSchema.asUint8Array()), // raw body, no base64
  success: Location.response(FileSystem.Write),                  // { path: AbsolutePath }
})
// generated promise client
await api.file.write({ location, path: `${info.paths.tmp}/uploads/${id}/${name}`, payload: bytes })
  • Creates parent directories; returns the resolved absolute path (mixed separators from another OS normalize server-side).
  • Unlike fs.read, not confined to the location: the point is to reach paths.tmp from GET /api/info, which the model is already told to prefer and permitted to access.
  • Promise-client codegen learns binary request bodies (mirrors the existing binary response support used by fs.read); the Effect client omits the endpoint like fs.read. workerd stub reports unavailable.
  • Also fixes service.test.ts on Windows CI: it compared os.tmpdir() (an 8.3 short name on the runner) against the realpath'd paths.tmp the server reports.

@Hona
Hona added this pull request to stack #49468 September 17, 2026 03:48
@Hona
Hona marked this pull request as ready for review September 17, 2026 03:49
Copilot AI lite review requested due to automatic review settings September 17, 2026 03:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Clients can write raw bytes to an absolute path or a path relative to
the requested location. Parent directories are created and the resolved
absolute path is returned. Unlike fs.read, the target is not confined to
the location so clients can stage files in the server tmp directory
reported by /api/info, which the model already prefers and is permitted
to access.

The promise client codegen learns binary request bodies; the Effect
client omits the endpoint like fs.read.

Also compares the canonical tmp path in the service info test: on
Windows CI os.tmpdir() is an 8.3 short name that the server realpaths.
@Hona
Hona merged commit 1685e70 into v2 Sep 17, 2026
12 checks passed
@Hona
Hona deleted the fs-write branch September 17, 2026 10:17
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants