Skip to content

Commit f964380

Browse files
committed
Add image_as_paths option to agentic search so image symbols are replaced with file paths instead of base64 content
- do we send images with agentic search? We should send as paths. └── apps └── editor └── src ├── constants │ └── instructions.ts ├── context │ └── helpers │ └── get-all-workspace-files.ts ├── features │ └── search-files │ └── utils │ └── show-search-results-quick-pick.ts ├── utils │ └── extract-paths-from-bullet-list.ts └── views └── prompt ├── backend │ ├── message-handlers │ │ ├── handle-agentic-search │ │ │ ├── agentic-search.ts │ │ │ ├── agents │ │ │ │ ├── antigravity.ts │ │ │ │ ├── claude.ts │ │ │ │ ├── codex.ts │ │ │ │ ├── cursor.ts │ │ │ │ ├── grok.ts │ │ │ │ ├── muse.ts │ │ │ │ └── opencode.ts │ │ │ ├── handle-agentic-search.ts │ │ │ ├── index.ts │ │ │ ├── types.ts │ │ │ └── utils │ │ │ ├── build-agent-prompt.ts │ │ │ ├── check-command-exists.ts │ │ │ ├── format-duration.ts │ │ │ ├── get-progress-dots.ts │ │ │ ├── index.ts │ │ │ └── prompt-for-search-term.ts │ │ ├── handle-autofill.ts │ │ ├── handle-open-prompt-image.ts │ │ ├── handle-save-prompt-image.ts │ │ └── utils │ │ └── build-prompt-payload.ts │ ├── prompt-view-provider.ts │ └── utils │ └── symbols │ ├── image │ │ └── replace-image-symbol.ts │ └── replace-symbols.ts ├── frontend │ └── hooks │ └── use-prompt │ └── use-prompt.ts └── types └── messages.ts
1 parent 33526ef commit f964380

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

‎apps/editor/src/views/prompt/backend/message-handlers/handle-agentic-search/agentic-search.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ export const agentic_search = async (params: {
605605
instructions: query,
606606
extension_context: params.extension_context,
607607
workspace_provider: params.workspace_provider,
608-
remove_images: true
608+
image_as_paths: true
609609
})
610610

611611
if (token.isCancellationRequested) {

‎apps/editor/src/views/prompt/backend/utils/symbols/image/replace-image-symbol.ts‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as fs from 'fs'
55
export const replace_image_symbol = async (params: {
66
instruction: string
77
remove?: boolean
8+
as_paths?: boolean
89
}): Promise<string> => {
910
const regex = /#Image\(([a-fA-F0-9]+)\)/g
1011

@@ -21,13 +22,28 @@ export const replace_image_symbol = async (params: {
2122
const replacements = await Promise.all(
2223
matches.map(async (match) => {
2324
const hash = match[1]
24-
const filename = `cwc-image-${hash}.txt`
25-
const file_path = path.join(os.tmpdir(), filename)
25+
const txt_filename = `cwc-image-${hash}.txt`
26+
const txt_path = path.join(os.tmpdir(), txt_filename)
27+
const png_filename = `cwc-image-${hash}.png`
28+
const png_path = path.join(os.tmpdir(), png_filename)
29+
2630
try {
27-
const content_base64 = await fs.promises.readFile(file_path, 'utf-8')
28-
return {
29-
content_base64,
30-
success: true
31+
if (params.as_paths) {
32+
if (!fs.existsSync(png_path)) {
33+
const content_base64 = await fs.promises.readFile(txt_path, 'utf-8')
34+
const buffer = Buffer.from(content_base64, 'base64')
35+
await fs.promises.writeFile(png_path, buffer)
36+
}
37+
return {
38+
path: png_path,
39+
success: true
40+
}
41+
} else {
42+
const content_base64 = await fs.promises.readFile(txt_path, 'utf-8')
43+
return {
44+
content_base64,
45+
success: true
46+
}
3147
}
3248
} catch (error) {
3349
return {
@@ -46,8 +62,14 @@ export const replace_image_symbol = async (params: {
4662

4763
result_string += params.instruction.slice(last_index, match.index)
4864

49-
if (replacement.success && replacement.content_base64) {
50-
result_string += `<cwc-image>${replacement.content_base64}</cwc-image>`
65+
if (replacement.success) {
66+
if (params.as_paths && replacement.path) {
67+
result_string += replacement.path
68+
} else if (replacement.content_base64) {
69+
result_string += `<cwc-image>${replacement.content_base64}</cwc-image>`
70+
} else {
71+
result_string += match[0]
72+
}
5173
} else {
5274
result_string += match[0]
5375
}

‎apps/editor/src/views/prompt/backend/utils/symbols/replace-symbols.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const replace_symbols = async (params: {
1717
extension_context: vscode.ExtensionContext
1818
workspace_provider: WorkspaceProvider
1919
remove_images?: boolean
20+
image_as_paths?: boolean
2021
symbols_cache?: SymbolCacheManager
2122
}): Promise<{ instructions: string; skill_definitions: string }> => {
2223
let processed_instructions = params.instructions
@@ -66,7 +67,8 @@ export const replace_symbols = async (params: {
6667
if (processed_instructions.includes('#Image(')) {
6768
processed_instructions = await replace_image_symbol({
6869
instruction: processed_instructions,
69-
remove: params.remove_images
70+
remove: params.remove_images,
71+
as_paths: params.image_as_paths
7072
})
7173
}
7274

0 commit comments

Comments
 (0)