(outputs: Record<string, any>, indentLevel = 0)
| 1993 | } |
| 1994 | |
| 1995 | function formatOutputStructure(outputs: Record<string, any>, indentLevel = 0): string { |
| 1996 | let result = '' |
| 1997 | |
| 1998 | for (const [key, output] of Object.entries(outputs)) { |
| 1999 | let type = 'unknown' |
| 2000 | let description = `${key} output from the tool` |
| 2001 | |
| 2002 | if (typeof output === 'object' && output !== null) { |
| 2003 | if (output.type) { |
| 2004 | type = output.type |
| 2005 | } |
| 2006 | |
| 2007 | if (output.description) { |
| 2008 | description = output.description |
| 2009 | } |
| 2010 | } |
| 2011 | |
| 2012 | const escapedDescription = description |
| 2013 | .replace(/\|/g, '\\|') |
| 2014 | .replace(/\{/g, '\\{') |
| 2015 | .replace(/\}/g, '\\}') |
| 2016 | .replace(/\(/g, '\\(') |
| 2017 | .replace(/\)/g, '\\)') |
| 2018 | .replace(/\[/g, '\\[') |
| 2019 | .replace(/\]/g, '\\]') |
| 2020 | .replace(/</g, '<') |
| 2021 | .replace(/>/g, '>') |
| 2022 | |
| 2023 | // Build prefix based on indent level - each level adds 2 spaces before the arrow |
| 2024 | let prefix = '' |
| 2025 | if (indentLevel > 0) { |
| 2026 | const spaces = ' '.repeat(indentLevel) |
| 2027 | prefix = `${spaces}↳ ` |
| 2028 | } |
| 2029 | |
| 2030 | if (typeof output === 'object' && output !== null && output.type === 'array') { |
| 2031 | result += `| ${prefix}\`${key}\` | ${type} | ${escapedDescription} |\n` |
| 2032 | |
| 2033 | if (output.items?.properties) { |
| 2034 | const arrayItemsResult = formatOutputStructure(output.items.properties, indentLevel + 1) |
| 2035 | result += arrayItemsResult |
| 2036 | } |
| 2037 | } else if ( |
| 2038 | typeof output === 'object' && |
| 2039 | output !== null && |
| 2040 | output.properties && |
| 2041 | (output.type === 'object' || output.type === 'json') |
| 2042 | ) { |
| 2043 | result += `| ${prefix}\`${key}\` | ${type} | ${escapedDescription} |\n` |
| 2044 | |
| 2045 | const nestedResult = formatOutputStructure(output.properties, indentLevel + 1) |
| 2046 | result += nestedResult |
| 2047 | } else { |
| 2048 | result += `| ${prefix}\`${key}\` | ${type} | ${escapedDescription} |\n` |
| 2049 | } |
| 2050 | } |
| 2051 | |
| 2052 | return result |
no test coverage detected