( item: ToolItem, descriptor: AgentActivityDescriptor, )
| 63 | } |
| 64 | |
| 65 | export function buildFileReadContent( |
| 66 | item: ToolItem, |
| 67 | descriptor: AgentActivityDescriptor, |
| 68 | ): FileReadContent | null { |
| 69 | if (descriptor.renderClass !== "file-read") { |
| 70 | return null; |
| 71 | } |
| 72 | |
| 73 | const path = |
| 74 | getToolString(item.args, ["path", "file", "file_path", "target_file"]) ?? |
| 75 | descriptor.object ?? |
| 76 | descriptor.preview; |
| 77 | if (!path) { |
| 78 | return null; |
| 79 | } |
| 80 | |
| 81 | const resultText = getResultText(item.result); |
| 82 | if (!resultText.trim()) { |
| 83 | return null; |
| 84 | } |
| 85 | |
| 86 | const parsed = parseReadFileOutput(resultText, path); |
| 87 | return { |
| 88 | footerText: parsed.footerText, |
| 89 | footerTitle: parsed.footerTitle, |
| 90 | lines: parsed.lines, |
| 91 | path, |
| 92 | }; |
| 93 | } |
| 94 | |
| 95 | function parseReadFileOutput(resultText: string, path: string) { |
| 96 | const rawLines = trimTrailingEmptyLines(resultText.split(/\r?\n/)); |
no test coverage detected