forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion.ts
More file actions
44 lines (40 loc) · 1.36 KB
/
question.ts
File metadata and controls
44 lines (40 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { AppLayer } from "@/effect/app-runtime"
import { memoMap } from "@/effect/run-service"
import { Question } from "@/question"
import { QuestionID } from "@/question/schema"
import { lazy } from "@/util/lazy"
import { makeQuestionHandler, questionApi } from "@opencode-ai/server"
import { Effect, Layer } from "effect"
import { HttpRouter, HttpServer } from "effect/unstable/http"
import { HttpApiBuilder } from "effect/unstable/httpapi"
import type { Handler } from "hono"
const root = "/experimental/httpapi/question"
const QuestionLive = makeQuestionHandler({
list: Effect.fn("QuestionHttpApi.host.list")(function* () {
const svc = yield* Question.Service
return yield* svc.list()
}),
reply: Effect.fn("QuestionHttpApi.host.reply")(function* (input) {
const svc = yield* Question.Service
yield* svc.reply({
requestID: QuestionID.make(input.requestID),
answers: input.answers,
})
}),
}).pipe(Layer.provide(Question.defaultLayer))
const web = lazy(() =>
HttpRouter.toWebHandler(
Layer.mergeAll(
AppLayer,
HttpApiBuilder.layer(questionApi, { openapiPath: `${root}/doc` }).pipe(
Layer.provide(QuestionLive),
Layer.provide(HttpServer.layerServices),
),
),
{
disableLogger: true,
memoMap,
},
),
)
export const QuestionHttpApiHandler: Handler = (c, _next) => web().handler(c.req.raw)