core: add question tool route and update server imports to support new question endpoint functionality
This commit is contained in:
parent
5a2768b546
commit
5849df9bbc
3 changed files with 2797 additions and 2771 deletions
|
|
@ -515,7 +515,15 @@ export const GithubRunCommand = cmd({
|
||||||
|
|
||||||
// Setup opencode session
|
// Setup opencode session
|
||||||
const repoData = await fetchRepo()
|
const repoData = await fetchRepo()
|
||||||
session = await Session.create({})
|
session = await Session.create({
|
||||||
|
permission: [
|
||||||
|
{
|
||||||
|
permission: "question",
|
||||||
|
action: "deny",
|
||||||
|
pattern: "*",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
subscribeSessionEvents()
|
subscribeSessionEvents()
|
||||||
shareId = await (async () => {
|
shareId = await (async () => {
|
||||||
if (share === false) return
|
if (share === false) return
|
||||||
|
|
|
||||||
95
packages/opencode/src/server/question.ts
Normal file
95
packages/opencode/src/server/question.ts
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
import { Hono } from "hono"
|
||||||
|
import { describeRoute, validator } from "hono-openapi"
|
||||||
|
import { resolver } from "hono-openapi"
|
||||||
|
import { Question } from "../question"
|
||||||
|
import z from "zod"
|
||||||
|
import { errors } from "./error"
|
||||||
|
|
||||||
|
export const QuestionRoute = new Hono()
|
||||||
|
.get(
|
||||||
|
"/",
|
||||||
|
describeRoute({
|
||||||
|
summary: "List pending questions",
|
||||||
|
description: "Get all pending question requests across all sessions.",
|
||||||
|
operationId: "question.list",
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: "List of pending questions",
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: resolver(Question.Request.array()),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
async (c) => {
|
||||||
|
const questions = await Question.list()
|
||||||
|
return c.json(questions)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.post(
|
||||||
|
"/:requestID/reply",
|
||||||
|
describeRoute({
|
||||||
|
summary: "Reply to question request",
|
||||||
|
description: "Provide answers to a question request from the AI assistant.",
|
||||||
|
operationId: "question.reply",
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: "Question answered successfully",
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: resolver(z.boolean()),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...errors(400, 404),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
validator(
|
||||||
|
"param",
|
||||||
|
z.object({
|
||||||
|
requestID: z.string(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
validator("json", z.object({ answers: z.array(z.string()) })),
|
||||||
|
async (c) => {
|
||||||
|
const params = c.req.valid("param")
|
||||||
|
const json = c.req.valid("json")
|
||||||
|
await Question.reply({
|
||||||
|
requestID: params.requestID,
|
||||||
|
answers: json.answers,
|
||||||
|
})
|
||||||
|
return c.json(true)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.post(
|
||||||
|
"/:requestID/reject",
|
||||||
|
describeRoute({
|
||||||
|
summary: "Reject question request",
|
||||||
|
description: "Reject a question request from the AI assistant.",
|
||||||
|
operationId: "question.reject",
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: "Question rejected successfully",
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: resolver(z.boolean()),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...errors(400, 404),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
validator(
|
||||||
|
"param",
|
||||||
|
z.object({
|
||||||
|
requestID: z.string(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
async (c) => {
|
||||||
|
const params = c.req.valid("param")
|
||||||
|
await Question.reject(params.requestID)
|
||||||
|
return c.json(true)
|
||||||
|
},
|
||||||
|
)
|
||||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue