| 103 | } |
| 104 | |
| 105 | export function extractToolContent(part: any): string[] { |
| 106 | const contents: string[] = [] |
| 107 | |
| 108 | if (part?.type !== "tool") { |
| 109 | return contents |
| 110 | } |
| 111 | |
| 112 | if (part.state?.input !== undefined) { |
| 113 | contents.push(stringifyToolContent(part.state.input)) |
| 114 | } |
| 115 | |
| 116 | const completedOutput = extractCompletedToolOutput(part) |
| 117 | if (completedOutput !== undefined) { |
| 118 | contents.push(completedOutput) |
| 119 | } else if (part.state?.status === "error" && part.state?.error) { |
| 120 | contents.push(stringifyToolContent(part.state.error)) |
| 121 | } |
| 122 | |
| 123 | return contents |
| 124 | } |
| 125 | |
| 126 | export function countToolTokens(part: any): number { |
| 127 | const contents = extractToolContent(part) |