Skip to content

Commit 9dc853c

Browse files
committed
feat(images): persist base64 in backend messages; normalize URIs once at ingestion; support VS Code CDN webview URLs in normalization
1 parent 3d796de commit 9dc853c

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/core/task/Task.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,21 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
872872
throw new Error("Current ask promise was ignored")
873873
}
874874

875-
const result = { response: this.askResponse!, text: this.askResponseText, images: this.askResponseImages }
875+
let result: { response: ClineAskResponse; text?: string; images?: string[] } = {
876+
response: this.askResponse!,
877+
text: this.askResponseText,
878+
images: this.askResponseImages,
879+
}
880+
// Normalize any image refs to base64 data URLs before handing back to callers
881+
if (Array.isArray(result.images) && result.images.length > 0) {
882+
try {
883+
const { normalizeImageRefsToDataUrls } = await import("../../integrations/misc/imageDataUrl")
884+
const normalized = await normalizeImageRefsToDataUrls(result.images)
885+
result.images = normalized
886+
} catch (e) {
887+
console.error("[Task#ask] Failed to normalize image refs:", e)
888+
}
889+
}
876890
this.askResponse = undefined
877891
this.askResponseText = undefined
878892
this.askResponseImages = undefined
@@ -1070,6 +1084,16 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
10701084
throw new Error(`[RooCode#say] task ${this.taskId}.${this.instanceId} aborted`)
10711085
}
10721086

1087+
// Ensure any image refs are normalized to base64 data URLs before persisting or sending to APIs
1088+
if (Array.isArray(images) && images.length > 0) {
1089+
try {
1090+
const { normalizeImageRefsToDataUrls } = await import("../../integrations/misc/imageDataUrl")
1091+
images = await normalizeImageRefsToDataUrls(images)
1092+
} catch (e) {
1093+
console.error("[Task#say] Failed to normalize image refs:", e)
1094+
}
1095+
}
1096+
10731097
if (partial !== undefined) {
10741098
const lastMessage = this.clineMessages.at(-1)
10751099

src/integrations/misc/imageDataUrl.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ export async function normalizeImageRefsToDataUrls(imageRefs: string[]): Promise
3838
* Converts a webview URI to a file system path
3939
*/
4040
function webviewUriToFilePath(webviewUri: string): string {
41+
// Handle VS Code CDN-style webview URLs:
42+
// Example: https://file+.vscode-resource.vscode-cdn.net/file/<absolute_path_to_image>
43+
if (webviewUri.startsWith("https://")) {
44+
try {
45+
const u = new URL(webviewUri)
46+
if (u.host === "vscode-cdn.net" || u.host.endsWith(".vscode-cdn.net")) {
47+
// Path is like /file/<abs-path> - strip the /file/ prefix
48+
let p = u.pathname || ""
49+
if (p.startsWith("/file/")) {
50+
p = p.slice("/file/".length)
51+
}
52+
return path.normalize(decodeURIComponent(p))
53+
}
54+
} catch {
55+
// fall through if not a valid URL or not the expected host
56+
}
57+
}
58+
4159
// Handle vscode-resource URIs like:
4260
// vscode-resource://vscode-webview/path/to/file
4361
if (webviewUri.includes("vscode-resource://")) {

0 commit comments

Comments
 (0)