GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(acp): preserve resource text source (#33524) · soequelle/opencode@8e2d422

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/opencode
    • src/acp
      • content.ts
    • test/acp
      • content.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/opencode/src/acp/content.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/acp/content.ts
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ContentBlock, ContentChunk, ResourceLink, Role } from "@agentclientprotocol/sdk"
22
import path from "node:path"
3-
import { pathToFileURL } from "node:url"
3+
import { fileURLToPath, pathToFileURL } from "node:url"
44
import { SessionV1 } from "@opencode-ai/core/v1/session"
55

66
export type PromptPart = SessionV1.TextPartInput | SessionV1.FilePartInput
@@ -76,7 +76,19 @@ export function contentBlockToParts(block: ContentBlock): PromptPart[] {
7676

7777
case "resource":
7878
if ("text" in block.resource) {
79-
return [{ type: "text", text: block.resource.text }]
79+
try {
80+
const parsed = new URL(block.resource.uri)
81+
if (parsed.protocol === "file:") {
82+
const line = parsed.hash.match(/^#L(\d+)/)?.[1]
83+
return [
84+
{
85+
type: "text",
86+
text: `[${fileURLToPath(parsed)}${line ? `:${line}` : ""}]\n${block.resource.text}`,
87+
},
88+
]
89+
}
90+
} catch {}
91+
return [{ type: "text", text: `[${block.resource.uri}]\n${block.resource.text}` }]
8092
}
8193
if (block.resource.mimeType) {
8294
return [
Collapse file

‎packages/opencode/test/acp/content.test.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/test/acp/content.test.ts
+15-3Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,29 @@ describe("acp content conversion", () => {
9999
])
100100
})
101101

102-
test("resource with text becomes a text part", () => {
102+
test("resource with text becomes a sourced text part", () => {
103103
expect(
104104
contentBlockToParts({
105105
type: "resource",
106106
resource: {
107-
uri: "file:///tmp/context.txt",
107+
uri: "file:///tmp/context.txt#L12-L14",
108108
mimeType: "text/plain",
109109
text: "context",
110110
},
111111
}),
112-
).toEqual([{ type: "text", text: "context" }])
112+
).toEqual([{ type: "text", text: "[/tmp/context.txt:12]\ncontext" }])
113+
})
114+
115+
test("resource with text uses URI fallback for non-file resources", () => {
116+
expect(
117+
contentBlockToParts({
118+
type: "resource",
119+
resource: {
120+
uri: "mcp://server/context",
121+
text: "context",
122+
},
123+
}),
124+
).toEqual([{ type: "text", text: "[mcp://server/context]\ncontext" }])
113125
})
114126

115127
test("resource with blob and mimeType becomes a data URL file part", () => {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.