| 34 | } |
| 35 | |
| 36 | function isFileEditResult(result: unknown): result is FileEditResult { |
| 37 | if (!result || typeof result !== 'object') return false |
| 38 | const r = result as Record<string, unknown> |
| 39 | // FileEditTool: has structuredPatch with content |
| 40 | // FileWriteTool (update): has structuredPatch with content |
| 41 | // FileWriteTool (create): has type='create' and content (structuredPatch is empty) |
| 42 | const hasFilePath = typeof r.filePath === 'string' |
| 43 | const hasStructuredPatch = |
| 44 | Array.isArray(r.structuredPatch) && r.structuredPatch.length > 0 |
| 45 | const isNewFile = r.type === 'create' && typeof r.content === 'string' |
| 46 | return hasFilePath && (hasStructuredPatch || isNewFile) |
| 47 | } |
| 48 | |
| 49 | function isFileWriteOutput(result: FileEditResult): result is FileWriteOutput { |
| 50 | return ( |