Просмотр исходного кода

fix(cli): align prompt attachment mentions

Dax Raad 1 месяц назад
Родитель
Сommit
f87998f37f

+ 3 - 3
packages/cli/src/mini/stream-v2.transport.ts

@@ -190,7 +190,7 @@ async function prepareFile(file: RunFilePart) {
   return { text: `<file name="${file.filename}">\n${content}\n</file>` }
 }
 
-function promptFileSource(part: PromptFilePart) {
+function promptFileMention(part: PromptFilePart) {
   if (!part.source?.text) return
   return {
     start: part.source.text.start,
@@ -206,7 +206,7 @@ function promptFiles(next: SessionTurnInput) {
           {
             uri: part.url,
             name: part.filename,
-            source: promptFileSource(part),
+            mention: promptFileMention(part),
           },
         ]
       : [],
@@ -219,7 +219,7 @@ function promptAgents(next: SessionTurnInput) {
       ? [
           {
             name: part.name,
-            source: part.source
+            mention: part.source
               ? { start: part.source.start, end: part.source.end, text: part.source.value }
               : undefined,
           },

+ 16 - 15
packages/opencode/test/cli/run/session.shared.test.ts

@@ -256,21 +256,22 @@ describe("run session shared", () => {
     spyOn(client.message, "list").mockImplementation(() =>
       Promise.resolve({
         data: [
-            {
-              id: "msg_prompt",
-              type: "user",
-              text: "Review @note.ts",
-              files: [
-                {
-                  uri: "file:///tmp/note.ts",
-                  mime: "text/plain",
-                  name: "note.ts",
-                  source: { start: 7, end: 15, text: "@note.ts" },
-                },
-              ],
-              agents: [],
-              time: { created: 1 },
-            },
+          {
+            id: "msg_prompt",
+            type: "user",
+            text: "Review @note.ts",
+            files: [
+              {
+                data: "",
+                mime: "text/plain",
+                name: "note.ts",
+                source: { type: "uri", uri: "file:///tmp/note.ts" },
+                mention: { start: 7, end: 15, text: "@note.ts" },
+              },
+            ],
+            agents: [],
+            time: { created: 1 },
+          },
         ],
         cursor: {},
       }),

+ 5 - 5
packages/opencode/test/cli/run/stream-v2.transport.test.ts

@@ -302,12 +302,12 @@ describe("V2 mini transport", () => {
       {
         uri: pathToFileURL(filePath).href,
         name: "note.ts",
-        source: { start: 7, end: 15, text: "@note.ts" },
+        mention: { start: 7, end: 15, text: "@note.ts" },
       },
       {
         uri: pathToFileURL(`${directoryPath}${path.sep}`).href,
         name: "docs",
-        source: { start: 20, end: 25, text: "@docs" },
+        mention: { start: 20, end: 25, text: "@docs" },
       },
     ])
     await transport.close()
@@ -398,12 +398,12 @@ describe("V2 mini transport", () => {
       {
         uri: "file:///remote/project/note.ts",
         name: "note.ts",
-        source: { start: 7, end: 15, text: "@note.ts" },
+        mention: { start: 7, end: 15, text: "@note.ts" },
       },
       {
         uri: "file:///remote/project/docs",
         name: "docs",
-        source: { start: 20, end: 25, text: "@docs" },
+        mention: { start: 20, end: 25, text: "@docs" },
       },
     ])
     await transport.close()
@@ -486,7 +486,7 @@ describe("V2 mini transport", () => {
       {
         name: "diagram.png",
         uri: pathToFileURL(filePath).href,
-        source: { start: 7, end: 19, text: "@diagram.png" },
+        mention: { start: 7, end: 19, text: "@diagram.png" },
       },
     ])
     await transport.close()