Compare commits
3 commits
dev
...
fix/sessio
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
934c605e44 |
||
|
|
d99467c027 | ||
|
|
678d8f6ab2 |
11 changed files with 149 additions and 101 deletions
4
bun.lock
4
bun.lock
|
|
@ -356,6 +356,7 @@
|
||||||
"@opencode-ai/plugin": "workspace:*",
|
"@opencode-ai/plugin": "workspace:*",
|
||||||
"@opencode-ai/script": "workspace:*",
|
"@opencode-ai/script": "workspace:*",
|
||||||
"@opencode-ai/sdk": "workspace:*",
|
"@opencode-ai/sdk": "workspace:*",
|
||||||
|
"@opencode-ai/server": "workspace:*",
|
||||||
"@opencode-ai/util": "workspace:*",
|
"@opencode-ai/util": "workspace:*",
|
||||||
"@openrouter/ai-sdk-provider": "2.5.1",
|
"@openrouter/ai-sdk-provider": "2.5.1",
|
||||||
"@opentui/core": "0.1.99",
|
"@opentui/core": "0.1.99",
|
||||||
|
|
@ -501,6 +502,9 @@
|
||||||
"packages/server": {
|
"packages/server": {
|
||||||
"name": "@opencode-ai/server",
|
"name": "@opencode-ai/server",
|
||||||
"version": "1.4.3",
|
"version": "1.4.3",
|
||||||
|
"dependencies": {
|
||||||
|
"effect": "catalog:",
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "catalog:",
|
"typescript": "catalog:",
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,7 @@
|
||||||
"@octokit/rest": "catalog:",
|
"@octokit/rest": "catalog:",
|
||||||
"@openauthjs/openauth": "catalog:",
|
"@openauthjs/openauth": "catalog:",
|
||||||
"@opencode-ai/plugin": "workspace:*",
|
"@opencode-ai/plugin": "workspace:*",
|
||||||
|
"@opencode-ai/server": "workspace:*",
|
||||||
"@opencode-ai/script": "workspace:*",
|
"@opencode-ai/script": "workspace:*",
|
||||||
"@opencode-ai/sdk": "workspace:*",
|
"@opencode-ai/sdk": "workspace:*",
|
||||||
"@opencode-ai/util": "workspace:*",
|
"@opencode-ai/util": "workspace:*",
|
||||||
|
|
|
||||||
|
|
@ -1183,28 +1183,26 @@ export function Session() {
|
||||||
<Show when={session()?.parentID}>
|
<Show when={session()?.parentID}>
|
||||||
<SubagentFooter />
|
<SubagentFooter />
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={visible()}>
|
<TuiPluginRuntime.Slot
|
||||||
<TuiPluginRuntime.Slot
|
name="session_prompt"
|
||||||
name="session_prompt"
|
mode="replace"
|
||||||
mode="replace"
|
session_id={route.sessionID}
|
||||||
session_id={route.sessionID}
|
visible={visible()}
|
||||||
|
disabled={disabled()}
|
||||||
|
on_submit={toBottom}
|
||||||
|
ref={bind}
|
||||||
|
>
|
||||||
|
<Prompt
|
||||||
visible={visible()}
|
visible={visible()}
|
||||||
disabled={disabled()}
|
|
||||||
on_submit={toBottom}
|
|
||||||
ref={bind}
|
ref={bind}
|
||||||
>
|
disabled={disabled()}
|
||||||
<Prompt
|
onSubmit={() => {
|
||||||
visible={visible()}
|
toBottom()
|
||||||
ref={bind}
|
}}
|
||||||
disabled={disabled()}
|
sessionID={route.sessionID}
|
||||||
onSubmit={() => {
|
right={<TuiPluginRuntime.Slot name="session_prompt_right" session_id={route.sessionID} />}
|
||||||
toBottom()
|
/>
|
||||||
}}
|
</TuiPluginRuntime.Slot>
|
||||||
sessionID={route.sessionID}
|
|
||||||
right={<TuiPluginRuntime.Slot name="session_prompt_right" session_id={route.sessionID} />}
|
|
||||||
/>
|
|
||||||
</TuiPluginRuntime.Slot>
|
|
||||||
</Show>
|
|
||||||
</box>
|
</box>
|
||||||
</Show>
|
</Show>
|
||||||
<Toast />
|
<Toast />
|
||||||
|
|
|
||||||
|
|
@ -3,74 +3,31 @@ import { memoMap } from "@/effect/run-service"
|
||||||
import { Question } from "@/question"
|
import { Question } from "@/question"
|
||||||
import { QuestionID } from "@/question/schema"
|
import { QuestionID } from "@/question/schema"
|
||||||
import { lazy } from "@/util/lazy"
|
import { lazy } from "@/util/lazy"
|
||||||
|
import { QuestionReply, QuestionRequest, questionApi } from "@opencode-ai/server"
|
||||||
import { Effect, Layer, Schema } from "effect"
|
import { Effect, Layer, Schema } from "effect"
|
||||||
import { HttpRouter, HttpServer } from "effect/unstable/http"
|
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"
|
import type { Handler } from "hono"
|
||||||
|
|
||||||
const root = "/experimental/httpapi/question"
|
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(
|
const QuestionLive = HttpApiBuilder.group(
|
||||||
Api,
|
questionApi,
|
||||||
"question",
|
"question",
|
||||||
Effect.fn("QuestionHttpApi.handlers")(function* (handlers) {
|
Effect.fn("QuestionHttpApi.handlers")(function* (handlers) {
|
||||||
const svc = yield* Question.Service
|
const svc = yield* Question.Service
|
||||||
|
const decode = Schema.decodeUnknownSync(Schema.Array(QuestionRequest))
|
||||||
|
|
||||||
const list = Effect.fn("QuestionHttpApi.list")(function* () {
|
const list = Effect.fn("QuestionHttpApi.list")(function* () {
|
||||||
return yield* svc.list()
|
return decode(yield* svc.list())
|
||||||
})
|
})
|
||||||
|
|
||||||
const reply = Effect.fn("QuestionHttpApi.reply")(function* (ctx: {
|
const reply = Effect.fn("QuestionHttpApi.reply")(function* (ctx: {
|
||||||
params: { requestID: QuestionID }
|
params: { requestID: string }
|
||||||
payload: Schema.Schema.Type<typeof Reply>
|
payload: Schema.Schema.Type<typeof QuestionReply>
|
||||||
}) {
|
}) {
|
||||||
yield* svc.reply({
|
yield* svc.reply({
|
||||||
requestID: ctx.params.requestID,
|
requestID: QuestionID.make(ctx.params.requestID),
|
||||||
answers: ctx.payload.answers,
|
answers: ctx.payload.answers,
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
|
|
@ -84,7 +41,7 @@ const web = lazy(() =>
|
||||||
HttpRouter.toWebHandler(
|
HttpRouter.toWebHandler(
|
||||||
Layer.mergeAll(
|
Layer.mergeAll(
|
||||||
AppLayer,
|
AppLayer,
|
||||||
HttpApiBuilder.layer(Api, { openapiPath: `${root}/doc` }).pipe(
|
HttpApiBuilder.layer(questionApi, { openapiPath: `${root}/doc` }).pipe(
|
||||||
Layer.provide(QuestionLive),
|
Layer.provide(QuestionLive),
|
||||||
Layer.provide(HttpServer.layerServices),
|
Layer.provide(HttpServer.layerServices),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
"./openapi": "./src/openapi.ts",
|
"./openapi": "./src/openapi.ts",
|
||||||
"./definition": "./src/definition/index.ts",
|
"./definition": "./src/definition/index.ts",
|
||||||
"./definition/api": "./src/definition/api.ts",
|
"./definition/api": "./src/definition/api.ts",
|
||||||
|
"./definition/question": "./src/definition/question.ts",
|
||||||
"./api": "./src/api/index.ts"
|
"./api": "./src/api/index.ts"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
|
@ -20,5 +21,8 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "catalog:"
|
"typescript": "catalog:"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"effect": "catalog:"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
import type { ServerApi } from "../types.js"
|
import { HttpApi, OpenApi } from "effect/unstable/httpapi"
|
||||||
|
import { questionApi } from "./question.js"
|
||||||
|
|
||||||
export const api: ServerApi = {
|
export const api = HttpApi.make("opencode")
|
||||||
name: "opencode",
|
.addHttpApi(questionApi)
|
||||||
groups: [],
|
.annotateMerge(
|
||||||
}
|
OpenApi.annotations({
|
||||||
|
title: "opencode experimental HttpApi",
|
||||||
|
version: "0.0.1",
|
||||||
|
description: "Experimental HttpApi surface for selected instance routes.",
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
export { api } from "./api.js"
|
export { api } from "./api.js"
|
||||||
|
export { questionApi, QuestionReply, QuestionRequest } from "./question.js"
|
||||||
|
|
|
||||||
94
packages/server/src/definition/question.ts
Normal file
94
packages/server/src/definition/question.ts
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
import { Schema } from "effect"
|
||||||
|
import { HttpApi, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
|
||||||
|
|
||||||
|
const root = "/experimental/httpapi/question"
|
||||||
|
|
||||||
|
// Temporary transport-local schemas until canonical question schemas move into packages/core.
|
||||||
|
export const QuestionID = Schema.String.annotate({ identifier: "QuestionID" })
|
||||||
|
export const SessionID = Schema.String.annotate({ identifier: "SessionID" })
|
||||||
|
export const MessageID = Schema.String.annotate({ identifier: "MessageID" })
|
||||||
|
|
||||||
|
export class QuestionOption extends Schema.Class<QuestionOption>("QuestionOption")({
|
||||||
|
label: Schema.String.annotate({
|
||||||
|
description: "Display text (1-5 words, concise)",
|
||||||
|
}),
|
||||||
|
description: Schema.String.annotate({
|
||||||
|
description: "Explanation of choice",
|
||||||
|
}),
|
||||||
|
}) {}
|
||||||
|
|
||||||
|
const base = {
|
||||||
|
question: Schema.String.annotate({
|
||||||
|
description: "Complete question",
|
||||||
|
}),
|
||||||
|
header: Schema.String.annotate({
|
||||||
|
description: "Very short label (max 30 chars)",
|
||||||
|
}),
|
||||||
|
options: Schema.Array(QuestionOption).annotate({
|
||||||
|
description: "Available choices",
|
||||||
|
}),
|
||||||
|
multiple: Schema.optional(Schema.Boolean).annotate({
|
||||||
|
description: "Allow selecting multiple choices",
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
|
||||||
|
export class QuestionInfo extends Schema.Class<QuestionInfo>("QuestionInfo")({
|
||||||
|
...base,
|
||||||
|
custom: Schema.optional(Schema.Boolean).annotate({
|
||||||
|
description: "Allow typing a custom answer (default: true)",
|
||||||
|
}),
|
||||||
|
}) {}
|
||||||
|
|
||||||
|
export class QuestionTool extends Schema.Class<QuestionTool>("QuestionTool")({
|
||||||
|
messageID: MessageID,
|
||||||
|
callID: Schema.String,
|
||||||
|
}) {}
|
||||||
|
|
||||||
|
export class QuestionRequest extends Schema.Class<QuestionRequest>("QuestionRequest")({
|
||||||
|
id: QuestionID,
|
||||||
|
sessionID: SessionID,
|
||||||
|
questions: Schema.Array(QuestionInfo).annotate({
|
||||||
|
description: "Questions to ask",
|
||||||
|
}),
|
||||||
|
tool: Schema.optional(QuestionTool),
|
||||||
|
}) {}
|
||||||
|
|
||||||
|
export const QuestionAnswer = Schema.Array(Schema.String).annotate({ identifier: "QuestionAnswer" })
|
||||||
|
|
||||||
|
export class QuestionReply extends Schema.Class<QuestionReply>("QuestionReply")({
|
||||||
|
answers: Schema.Array(QuestionAnswer).annotate({
|
||||||
|
description: "User answers in order of questions (each answer is an array of selected labels)",
|
||||||
|
}),
|
||||||
|
}) {}
|
||||||
|
|
||||||
|
export const questionApi = HttpApi.make("question").add(
|
||||||
|
HttpApiGroup.make("question")
|
||||||
|
.add(
|
||||||
|
HttpApiEndpoint.get("list", root, {
|
||||||
|
success: Schema.Array(QuestionRequest),
|
||||||
|
}).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: QuestionReply,
|
||||||
|
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.",
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
export { openapi } from "./openapi.js"
|
export { openapi } from "./openapi.js"
|
||||||
export { api } from "./definition/api.js"
|
export { api } from "./definition/api.js"
|
||||||
|
export { questionApi, QuestionReply, QuestionRequest } from "./definition/question.js"
|
||||||
export type { OpenApiSpec, ServerApi } from "./types.js"
|
export type { OpenApiSpec, ServerApi } from "./types.js"
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,5 @@
|
||||||
|
import { OpenApi } from "effect/unstable/httpapi"
|
||||||
import { api } from "./definition/api.js"
|
import { api } from "./definition/api.js"
|
||||||
import type { OpenApiSpec } from "./types.js"
|
import type { OpenApiSpec } from "./types.js"
|
||||||
|
|
||||||
export function openapi(): OpenApiSpec {
|
export const openapi = (): OpenApiSpec => OpenApi.fromApi(api)
|
||||||
return {
|
|
||||||
openapi: "3.1.1",
|
|
||||||
info: {
|
|
||||||
title: api.name,
|
|
||||||
version: "0.0.0",
|
|
||||||
description: "Contract-first server package scaffold.",
|
|
||||||
},
|
|
||||||
paths: {},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,5 @@
|
||||||
export interface ServerApi {
|
import type { HttpApi, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
|
||||||
readonly name: string
|
|
||||||
readonly groups: readonly string[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface OpenApiSpec {
|
export type ServerApi = HttpApi.HttpApi<string, HttpApiGroup.Any>
|
||||||
readonly openapi: string
|
|
||||||
readonly info: {
|
export type OpenApiSpec = OpenApi.OpenAPISpec
|
||||||
readonly title: string
|
|
||||||
readonly version: string
|
|
||||||
readonly description: string
|
|
||||||
}
|
|
||||||
readonly paths: Record<string, never>
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue