Explorar el Código

fix(app): translate legacy question tool IDs

Brendan Allan hace 1 semana
padre
commit
5d351406a1

+ 21 - 1
packages/app/src/utils/server-compat.test.ts

@@ -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" } })

+ 7 - 1
packages/app/src/utils/server-compat.ts

@@ -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]) {