refactor(server): serve raw filesystem content (#31911)

This commit is contained in:
Dax
2026-06-11 11:20:11 -04:00
committed by GitHub
parent 31b233e9db
commit 31c5454ee6
12 changed files with 67 additions and 93 deletions
+9 -7
View File
@@ -1,5 +1,7 @@
import { FileSystem } from "@opencode-ai/core/filesystem"
import { RelativePath } from "@opencode-ai/core/schema"
import { Effect } from "effect"
import { HttpServerResponse } from "effect/unstable/http"
import { HttpApiBuilder } from "effect/unstable/httpapi"
import { Api } from "../api"
import { response } from "../groups/location"
@@ -7,13 +9,13 @@ import { response } from "../groups/location"
export const FileSystemHandler = HttpApiBuilder.group(Api, "server.fs", (handlers) =>
Effect.gen(function* () {
return handlers
.handle("fs.read", (ctx) =>
response(
Effect.gen(function* () {
const fs = yield* FileSystem.Service
return yield* fs.read(ctx.query)
}),
),
.handleRaw("fs.read", (ctx) =>
Effect.gen(function* () {
const file = yield* (yield* FileSystem.Service).read({
path: RelativePath.make(decodeURIComponent(new URL(ctx.request.url, "http://localhost").pathname.slice(13))),
})
return HttpServerResponse.uint8Array(file.content, { contentType: file.mime })
}),
)
.handle("fs.list", (ctx) =>
response(