refactor(client): simplify embedded setup
This commit is contained in:
@@ -3,6 +3,7 @@ import { SessionGroup } from "@opencode-ai/server/groups/session"
|
||||
import { compile, emitEffectImported, emitPromise, write } from "@opencode-ai/httpapi-codegen"
|
||||
import { Effect } from "effect"
|
||||
import { HttpApi } from "effect/unstable/httpapi"
|
||||
import { fileURLToPath } from "url"
|
||||
|
||||
const Api = HttpApi.make("opencode-client").add(SessionGroup)
|
||||
const contract = compile(Api, { groupNames: { "server.session": "sessions" } })
|
||||
@@ -10,13 +11,13 @@ const contract = compile(Api, { groupNames: { "server.session": "sessions" } })
|
||||
await Effect.runPromise(
|
||||
Effect.all(
|
||||
[
|
||||
write(emitPromise(contract), new URL("../src/generated", import.meta.url).pathname),
|
||||
write(emitPromise(contract), fileURLToPath(new URL("../src/generated", import.meta.url))),
|
||||
write(
|
||||
emitEffectImported(contract, {
|
||||
module: "@opencode-ai/server/groups/session",
|
||||
group: "SessionGroup",
|
||||
}),
|
||||
new URL("../src/generated-effect", import.meta.url).pathname,
|
||||
fileURLToPath(new URL("../src/generated-effect", import.meta.url)),
|
||||
),
|
||||
],
|
||||
{ concurrency: 2, discard: true },
|
||||
|
||||
@@ -44,11 +44,11 @@ export const create = Effect.fn("OpenCode.create")(function* () {
|
||||
}
|
||||
})
|
||||
|
||||
export interface Interface extends Effect.Success<ReturnType<typeof create>> {}
|
||||
export type Interface = Effect.Success<ReturnType<typeof create>>
|
||||
|
||||
export class Service extends Context.Service<Service, Interface>()("@opencode-ai/client/OpenCode") {}
|
||||
|
||||
export const layer = Layer.effect(Service, create().pipe(Effect.map(Service.of)))
|
||||
export const layer = Layer.effect(Service, create())
|
||||
|
||||
export { ClientError } from "./generated-effect/index"
|
||||
export { Tool } from "@opencode-ai/core/public/tool"
|
||||
|
||||
Reference in New Issue
Block a user