|
|
@@ -3,74 +3,31 @@ import { memoMap } from "@/effect/run-service"
|
|
|
import { Question } from "@/question"
|
|
|
import { QuestionID } from "@/question/schema"
|
|
|
import { lazy } from "@/util/lazy"
|
|
|
+import { QuestionReply, QuestionRequest, questionApi } from "@opencode-ai/server"
|
|
|
import { Effect, Layer, Schema } from "effect"
|
|
|
import { HttpRouter, HttpServer } from "effect/unstable/http"
|
|
|
-import { HttpApi, HttpApiBuilder, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
|
|
|
+import { HttpApiBuilder } from "effect/unstable/httpapi"
|
|
|
import type { Handler } from "hono"
|
|
|
|
|
|
const root = "/experimental/httpapi/question"
|
|
|
-const Reply = Schema.Struct({
|
|
|
- answers: Schema.Array(Question.Answer).annotate({
|
|
|
- description: "User answers in order of questions (each answer is an array of selected labels)",
|
|
|
- }),
|
|
|
-})
|
|
|
-
|
|
|
-const Api = HttpApi.make("question")
|
|
|
- .add(
|
|
|
- HttpApiGroup.make("question")
|
|
|
- .add(
|
|
|
- HttpApiEndpoint.get("list", root, {
|
|
|
- success: Schema.Array(Question.Request),
|
|
|
- }).annotateMerge(
|
|
|
- OpenApi.annotations({
|
|
|
- identifier: "question.list",
|
|
|
- summary: "List pending questions",
|
|
|
- description: "Get all pending question requests across all sessions.",
|
|
|
- }),
|
|
|
- ),
|
|
|
- HttpApiEndpoint.post("reply", `${root}/:requestID/reply`, {
|
|
|
- params: { requestID: QuestionID },
|
|
|
- payload: Reply,
|
|
|
- success: Schema.Boolean,
|
|
|
- }).annotateMerge(
|
|
|
- OpenApi.annotations({
|
|
|
- identifier: "question.reply",
|
|
|
- summary: "Reply to question request",
|
|
|
- description: "Provide answers to a question request from the AI assistant.",
|
|
|
- }),
|
|
|
- ),
|
|
|
- )
|
|
|
- .annotateMerge(
|
|
|
- OpenApi.annotations({
|
|
|
- title: "question",
|
|
|
- description: "Experimental HttpApi question routes.",
|
|
|
- }),
|
|
|
- ),
|
|
|
- )
|
|
|
- .annotateMerge(
|
|
|
- OpenApi.annotations({
|
|
|
- title: "opencode experimental HttpApi",
|
|
|
- version: "0.0.1",
|
|
|
- description: "Experimental HttpApi surface for selected instance routes.",
|
|
|
- }),
|
|
|
- )
|
|
|
|
|
|
const QuestionLive = HttpApiBuilder.group(
|
|
|
- Api,
|
|
|
+ questionApi,
|
|
|
"question",
|
|
|
Effect.fn("QuestionHttpApi.handlers")(function* (handlers) {
|
|
|
const svc = yield* Question.Service
|
|
|
+ const decode = Schema.decodeUnknownSync(Schema.Array(QuestionRequest))
|
|
|
|
|
|
const list = Effect.fn("QuestionHttpApi.list")(function* () {
|
|
|
- return yield* svc.list()
|
|
|
+ return decode(yield* svc.list())
|
|
|
})
|
|
|
|
|
|
const reply = Effect.fn("QuestionHttpApi.reply")(function* (ctx: {
|
|
|
- params: { requestID: QuestionID }
|
|
|
- payload: Schema.Schema.Type<typeof Reply>
|
|
|
+ params: { requestID: string }
|
|
|
+ payload: Schema.Schema.Type<typeof QuestionReply>
|
|
|
}) {
|
|
|
yield* svc.reply({
|
|
|
- requestID: ctx.params.requestID,
|
|
|
+ requestID: QuestionID.make(ctx.params.requestID),
|
|
|
answers: ctx.payload.answers,
|
|
|
})
|
|
|
return true
|
|
|
@@ -84,7 +41,7 @@ const web = lazy(() =>
|
|
|
HttpRouter.toWebHandler(
|
|
|
Layer.mergeAll(
|
|
|
AppLayer,
|
|
|
- HttpApiBuilder.layer(Api, { openapiPath: `${root}/doc` }).pipe(
|
|
|
+ HttpApiBuilder.layer(questionApi, { openapiPath: `${root}/doc` }).pipe(
|
|
|
Layer.provide(QuestionLive),
|
|
|
Layer.provide(HttpServer.layerServices),
|
|
|
),
|