Add plus button to prompt input for file and image attachments

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
tusharmagar 2026-02-17 13:42:53 +05:30 committed by Arjun
parent 9aa3a3f82b
commit c49a47e6bc
11 changed files with 507 additions and 115 deletions

View file

@ -6,6 +6,7 @@ import { LlmModelConfig } from './models.js';
import { AgentScheduleConfig, AgentScheduleEntry } from './agent-schedule.js';
import { AgentScheduleState } from './agent-schedule-state.js';
import { ServiceEvent } from './service-events.js';
import { UserMessageContent } from './message.js';
// ============================================================================
// Runtime Validation Schemas (Single Source of Truth)
@ -128,7 +129,7 @@ const ipcSchemas = {
'runs:createMessage': {
req: z.object({
runId: z.string(),
message: z.string(),
message: UserMessageContent,
}),
res: z.object({
messageId: z.string(),

View file

@ -28,9 +28,36 @@ export const AssistantContentPart = z.union([
ToolCallPart,
]);
// Metadata about an attached file or image
export const Attachment = z.object({
type: z.enum(["file", "image"]), // extensible — could add "url", "audio" later
path: z.string(), // absolute file path
filename: z.string(), // display name ("photo.png")
mediaType: z.string(), // MIME type ("image/png", "text/plain")
size: z.number().optional(), // bytes
});
// A piece of user-typed text within a content array
export const UserTextPart = z.object({
type: z.literal("text"),
text: z.string(),
});
// An attachment within a content array
export const UserAttachmentPart = z.object({
type: z.literal("attachment"),
attachment: Attachment,
});
// Any single part of a user message (text or attachment)
export const UserContentPart = z.union([UserTextPart, UserAttachmentPart]);
// Named type for user message content — used everywhere instead of repeating the union
export const UserMessageContent = z.union([z.string(), z.array(UserContentPart)]);
export const UserMessage = z.object({
role: z.literal("user"),
content: z.string(),
content: UserMessageContent,
providerOptions: ProviderOptions.optional(),
});