mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-14 20:43:22 +00:00
fix(app): translate legacy question tool IDs
This commit is contained in:
parent
86d90eb4ef
commit
5d351406a1
2 changed files with 28 additions and 2 deletions
|
|
@ -4,7 +4,10 @@ import { createCompatibleApi } from "./server-compat"
|
|||
|
||||
function setup(
|
||||
protocol: "v1" | "v2" | Promise<"v1" | "v2">,
|
||||
responses?: { vcs?: { branch: string; default_branch: string } },
|
||||
responses?: {
|
||||
vcs?: { branch: string; default_branch: string }
|
||||
question?: { id: string; sessionID: string; questions: never[]; tool?: { messageID: string; callID: string } }[]
|
||||
},
|
||||
) {
|
||||
const requests: Request[] = []
|
||||
const fetcher = Object.assign(
|
||||
|
|
@ -36,6 +39,8 @@ function setup(
|
|||
}
|
||||
if (request.method === "GET" && new URL(request.url).pathname === "/vcs")
|
||||
return Response.json(responses?.vcs ?? {})
|
||||
if (request.method === "GET" && new URL(request.url).pathname === "/question")
|
||||
return Response.json(responses?.question ?? [])
|
||||
if (request.method === "GET") return Response.json([])
|
||||
return new Response(undefined, { status: 204 })
|
||||
},
|
||||
|
|
@ -163,6 +168,21 @@ describe("createCompatibleApi", () => {
|
|||
expect(new URL(requests[0]!.url).pathname).toBe("/experimental/session")
|
||||
})
|
||||
|
||||
test("translates V1 question tool call IDs", async () => {
|
||||
const { api } = setup("v1", {
|
||||
question: [
|
||||
{
|
||||
id: "que_1",
|
||||
sessionID: "ses_1",
|
||||
questions: [],
|
||||
tool: { messageID: "msg_1", callID: "call_1" },
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
expect((await api.question.request.list()).data[0]?.tool).toEqual({ messageID: "msg_1", id: "call_1" })
|
||||
})
|
||||
|
||||
/*
|
||||
test("projects the V1 default branch", async () => {
|
||||
const { api } = setup("v1", { vcs: { branch: "feature", default_branch: "dev" } })
|
||||
|
|
|
|||
|
|
@ -606,7 +606,13 @@ function createV1Api(input: CompatibleInput): CompatibleApi {
|
|||
request: {
|
||||
...input.current.question.request,
|
||||
async list(value?: Parameters<ServerApi["question"]["request"]["list"]>[0]) {
|
||||
return located((await legacy(value?.location).question.list()).data ?? [], value?.location)
|
||||
return located(
|
||||
((await legacy(value?.location).question.list()).data ?? []).map((request) => ({
|
||||
...request,
|
||||
tool: request.tool && { messageID: request.tool.messageID, id: request.tool.callID },
|
||||
})),
|
||||
value?.location,
|
||||
)
|
||||
},
|
||||
},
|
||||
async reply(value: Parameters<ServerApi["question"]["reply"]>[0]) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue