Revert "Enable AI to see images when using the read tool"

This reverts commit 2641252c6a.
This commit is contained in:
Alex Gleason committed 2026-03-28 22:21:17 -05:00
1 parent 2641252c6a
commit 34bfbb971b
3 files changed
+3 -38

No files matched your search

+1 -25
View File
@@ -4,7 +4,7 @@ import type { JSRuntimeFS } from './JSRuntime';
import { DotAI } from './DotAI';
import { parseProviderModel } from './parseProviderModel';
import { createAIClient } from './ai-client';
import type { Tool, ToolResultImage } from './tools/Tool';
import type { Tool } from './tools/Tool';
import type { NUser } from '@nostrify/react/login';
import type { AIProvider } from '@/contexts/AISettingsContext';
import { makeSystemPrompt } from './system';
@@ -656,11 +656,6 @@ export class SessionManager {
const result = await tool.execute(toolArgs);
await this.addToolMessage(projectId, functionToolCall.id, result.content);
// If tool returned images, inject a user message so the AI can "see" them
if (result.images?.length) {
await this.addToolImageMessage(projectId, result.images);
}
// Update session cost if tool returned a cost
if (result.cost !== undefined) {
const updatedSession = this.sessions.get(projectId);
@@ -804,25 +799,6 @@ export class SessionManager {
await this.addMessage(projectId, toolMessage);
}
/**
* Helper to inject a user message with images from tool results.
* Since tool messages only support text content, images are sent
* as a follow-up user message so vision models can actually see them.
*/
private async addToolImageMessage(projectId: string, images: ToolResultImage[]): Promise<void> {
const content: OpenAI.Chat.Completions.ChatCompletionContentPart[] = images.map((img) => ({
type: 'image_url' as const,
image_url: { url: img.url },
}));
const imageMessage: AIMessage = {
role: 'user',
content,
};
await this.addMessage(projectId, imageMessage);
}
/**
* Update session cost and context usage based on usage data
*/
+2 -7
View File
@@ -86,15 +86,10 @@ Usage:
const base64 = this.arrayBufferToBase64(bytes);
const ext = this.getFileExtension(filepath).toLowerCase();
const mimeType = this.getMimeType(ext);
const dataUrl = `data:${mimeType};base64,${base64}`;
// For vision-supported formats (JPG/PNG), return as a structured image
// so the AI can actually "see" the image
const isVisionSupported = ['jpg', 'jpeg', 'png'].includes(ext);
// Return base64 data URL in the content
return {
content: `[Image file: ${ext.toUpperCase()} file]\n\nImage read successfully.${!isVisionSupported ? `\n\nData URL: ${dataUrl}` : ''}`,
images: isVisionSupported ? [{ type: 'image' as const, url: dataUrl }] : undefined,
content: `[Image file: ${ext.toUpperCase()} file]\n\nImage read successfully.\n\nData URL: data:${mimeType};base64,${base64}`,
};
}
-6
View File
@@ -1,14 +1,8 @@
import type z from "zod";
export interface ToolResultImage {
type: 'image';
url: string; // data URL (e.g. data:image/png;base64,...)
}
export interface ToolResult {
content: string;
cost?: number;
images?: ToolResultImage[];
}
export interface Tool<TParams> {