fixed review comments

This commit is contained in:
Arjun 2026-02-26 21:03:58 +05:30
parent 5d78d66b00
commit a0a7933a7c
8 changed files with 53 additions and 76 deletions

View file

@ -416,23 +416,19 @@ export function convertFromMessages(messages: z.infer<typeof Message>[]): ModelM
} else {
// New content parts array — collapse to text for LLM
const textSegments: string[] = [];
const attachmentLines: string[] = [];
// Collect attachments into a header block
const attachmentParts = msg.content.filter((p: { type: string }) => p.type === "attachment");
if (attachmentParts.length > 0) {
textSegments.push("User has attached the following files:");
for (const part of attachmentParts) {
const att = (part as { type: string; attachment: { filename: string; mediaType: string; size?: number; path: string } }).attachment;
const sizeStr = att.size ? `, ${formatBytes(att.size)}` : '';
textSegments.push(`- ${att.filename} (${att.mediaType}${sizeStr}) at ${att.path}`);
for (const part of msg.content) {
if (part.type === "attachment") {
const sizeStr = part.size ? `, ${formatBytes(part.size)}` : '';
attachmentLines.push(`- ${part.filename} (${part.mimeType}${sizeStr}) at ${part.path}`);
} else {
textSegments.push(part.text);
}
textSegments.push(""); // blank line separator
}
// Collect text parts
const textParts = msg.content.filter((p: { type: string }) => p.type === "text");
for (const part of textParts) {
textSegments.push((part as { type: string; text: string }).text);
if (attachmentLines.length > 0) {
textSegments.unshift("User has attached the following files:", ...attachmentLines, "");
}
result.push({

View file

@ -49,10 +49,10 @@ export class FSRunsRepo implements IRunsRepo {
let textContent: string | undefined;
if (typeof content === 'string') {
textContent = content;
} else if (Array.isArray(content)) {
} else {
textContent = content
.filter((p: { type: string }) => p.type === 'text')
.map((p: { type: string; text?: string }) => p.text || '')
.filter(p => p.type === 'text')
.map(p => p.text)
.join('');
}
if (textContent && textContent.trim()) {
@ -101,10 +101,10 @@ export class FSRunsRepo implements IRunsRepo {
let textContent: string | undefined;
if (typeof content === 'string') {
textContent = content;
} else if (Array.isArray(content)) {
} else {
textContent = content
.filter((p: { type: string }) => p.type === 'text')
.map((p: { type: string; text?: string }) => p.text || '')
.filter(p => p.type === 'text')
.map(p => p.text)
.join('');
}
if (textContent && textContent.trim()) {
@ -257,13 +257,5 @@ export class FSRunsRepo implements IRunsRepo {
async delete(id: string): Promise<void> {
const filePath = path.join(WorkDir, 'runs', `${id}.jsonl`);
await fsp.unlink(filePath);
// Clean up attachment sidecar directory if it exists
const attachmentsDir = path.join(WorkDir, 'runs', 'attachments', id);
try {
await fsp.rm(attachmentsDir, { recursive: true });
} catch (err: unknown) {
const e = err as { code?: string };
if (e.code !== 'ENOENT') throw err;
}
}
}

View file

@ -28,15 +28,6 @@ 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"),
@ -46,7 +37,10 @@ export const UserTextPart = z.object({
// An attachment within a content array
export const UserAttachmentPart = z.object({
type: z.literal("attachment"),
attachment: Attachment,
path: z.string(), // absolute file path
filename: z.string(), // display name ("photo.png")
mimeType: z.string(), // MIME type ("image/png", "text/plain")
size: z.number().optional(), // bytes
});
// Any single part of a user message (text or attachment)