Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import colors from 'picocolors'; |
| 2 | import { S_BAR, S_BAR_H, unicodeOr } from '@clack/prompts'; |
| 3 | |
| 4 | const S_CORNER_TOP_LEFT = unicodeOr('╭', '+'); |
| 5 | const S_CORNER_BOTTOM_LEFT = unicodeOr('╰', '+'); |
| 6 | |
| 7 | export function renderPrettyError(errorLines: Array<[key: string, value: unknown]>): string { |
| 8 | return Array.from(renderPrettyErrorGen(errorLines)).join('\n'); |
| 9 | } |
| 10 | |
| 11 | function* renderPrettyErrorGen( |
| 12 | errorLines: Array<[key: string, value: unknown]> |
| 13 | ): Generator<string, void, unknown> { |
| 14 | if (errorLines.length === 0) { |
| 15 | yield ''; |
| 16 | } else if (errorLines.length <= 2) { |
| 17 | for (const [key, value] of errorLines) { |
| 18 | yield `${colors.inverse(S_BAR)} ${colors.blueBright(key)}: ${value}`; |
| 19 | } |
| 20 | } else if (errorLines.length > 2) { |
| 21 | for (let i = 0; i < errorLines.length; i++) { |
| 22 | const [key, value] = errorLines[i]; |
| 23 | |
| 24 | if (i === 0) { |
| 25 | yield `${colors.inverse(`${S_CORNER_TOP_LEFT}${S_BAR_H}`)} ${colors.blueBright(key)}: ${value}`; |
| 26 | } else if (i === errorLines.length - 1) { |
| 27 | yield `${colors.inverse(`${S_CORNER_BOTTOM_LEFT}${S_BAR_H}`)} ${colors.blueBright(key)}: ${value}`; |
| 28 | } else { |
| 29 | yield `${colors.inverse(S_BAR)} ${colors.blueBright(key)}: ${value}`; |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | } |