refactor(core): simplify location filesystem (#31545)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { FileSystem } from "@opencode-ai/core/filesystem"
|
||||
import { Location } from "@opencode-ai/core/location"
|
||||
import { RelativePath } from "@opencode-ai/core/schema"
|
||||
import { PositiveInt, RelativePath } from "@opencode-ai/core/schema"
|
||||
import { Schema } from "effect"
|
||||
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
|
||||
import { LocationQuery, locationQueryOpenApi, LocationMiddleware } from "./location"
|
||||
@@ -15,6 +15,13 @@ const ListQuery = Schema.Struct({
|
||||
path: RelativePath.pipe(Schema.optional),
|
||||
})
|
||||
|
||||
const FindQuery = Schema.Struct({
|
||||
...LocationQuery.fields,
|
||||
query: FileSystem.FindInput.fields.query,
|
||||
type: FileSystem.FindInput.fields.type,
|
||||
limit: Schema.NumberFromString.pipe(Schema.decodeTo(PositiveInt), Schema.optional),
|
||||
})
|
||||
|
||||
export const FileSystemGroup = HttpApiGroup.make("server.fs")
|
||||
.add(
|
||||
HttpApiEndpoint.get("fs.read", "/api/fs/read", {
|
||||
@@ -44,6 +51,20 @@ export const FileSystemGroup = HttpApiGroup.make("server.fs")
|
||||
}),
|
||||
),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.get("fs.find", "/api/fs/find", {
|
||||
query: FindQuery,
|
||||
success: Location.response(Schema.Array(FileSystem.Entry)),
|
||||
})
|
||||
.annotateMerge(locationQueryOpenApi)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "v2.fs.find",
|
||||
summary: "Find files",
|
||||
description: "Find recursively ranked filesystem entries relative to the requested location.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
title: "filesystem",
|
||||
|
||||
@@ -5,9 +5,10 @@ import { Api } from "../api"
|
||||
import { response } from "../groups/location"
|
||||
|
||||
export const FileSystemHandler = HttpApiBuilder.group(Api, "server.fs", (handlers) =>
|
||||
Effect.gen(function* () {
|
||||
return handlers
|
||||
Effect.succeed(
|
||||
handlers
|
||||
.handle("fs.read", (ctx) => response(FileSystem.Service.use((fs) => fs.read(ctx.query))))
|
||||
.handle("fs.list", (ctx) => response(FileSystem.Service.use((fs) => fs.list(ctx.query))))
|
||||
}),
|
||||
.handle("fs.find", (ctx) => response(FileSystem.Service.use((fs) => fs.find(ctx.query)))),
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user