| 113 | } |
| 114 | |
| 115 | function toolPart( |
| 116 | index: number, |
| 117 | partIndex: number, |
| 118 | tool: string, |
| 119 | input: Record<string, unknown>, |
| 120 | outputLength = 160, |
| 121 | ): MessagePart { |
| 122 | const metadata = |
| 123 | tool === "apply_patch" |
| 124 | ? { files: [patchFile(index, "update"), patchFile(index + 1, index % 2 === 0 ? "add" : "delete")] } |
| 125 | : tool === "edit" || tool === "write" |
| 126 | ? { |
| 127 | filediff: fileDiff(String(input.filePath ?? `src/generated/file-${index}.ts`), index), |
| 128 | diff: patch(index, outputLength), |
| 129 | preview: patch(index + 1, 420), |
| 130 | } |
| 131 | : tool === "question" |
| 132 | ? { answers: [["Proceed"], ["Keep sample output"]] } |
| 133 | : {} |
| 134 | return { |
| 135 | id: id(`prt_tool_${tool}_${partIndex}`, index), |
| 136 | type: "tool", |
| 137 | callID: id("call", index * 10 + partIndex), |
| 138 | tool, |
| 139 | state: { |
| 140 | status: "completed", |
| 141 | input, |
| 142 | output: lorem(index * 23 + partIndex, outputLength), |
| 143 | title: tool === "bash" ? input.command : input.filePath || input.path || input.pattern || "completed", |
| 144 | metadata, |
| 145 | time: { start: 1700000000000 + index * 10_000, end: 1700000000000 + index * 10_000 + 400 }, |
| 146 | }, |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | function patchFile(seed: number, type: "add" | "update" | "delete") { |
| 151 | return { |