(outputsContent: string, toolPrefix?: string)
| 2053 | } |
| 2054 | |
| 2055 | function parseToolOutputsField(outputsContent: string, toolPrefix?: string): Record<string, any> { |
| 2056 | const outputs: Record<string, any> = {} |
| 2057 | |
| 2058 | // First, handle top-level const references |
| 2059 | // Patterns: "data: BOOKING_DATA_OUTPUT_PROPERTIES" or "pagination: PAGINATION_OUTPUT" |
| 2060 | if (toolPrefix) { |
| 2061 | // Pattern 1: Direct const reference |
| 2062 | const constRefRegex = /(\w+)\s*:\s*([A-Z][A-Z_0-9]+)\s*(?:,|$)/g |
| 2063 | let constMatch |
| 2064 | while ((constMatch = constRefRegex.exec(outputsContent)) !== null) { |
| 2065 | const propName = constMatch[1] |
| 2066 | const constName = constMatch[2] |
| 2067 | |
| 2068 | // Check if at depth 0 |
| 2069 | const beforeMatch = outputsContent.substring(0, constMatch.index) |
| 2070 | const openBraces = (beforeMatch.match(/\{/g) || []).length |
| 2071 | const closeBraces = (beforeMatch.match(/\}/g) || []).length |
| 2072 | if (openBraces !== closeBraces) { |
| 2073 | continue |
| 2074 | } |
| 2075 | |
| 2076 | const resolvedConst = resolveConstReference(constName, toolPrefix) |
| 2077 | if (resolvedConst) { |
| 2078 | outputs[propName] = resolvedConst |
| 2079 | } |
| 2080 | } |
| 2081 | |
| 2082 | // Pattern 2: Property access on const (e.g., "status: BOOKING_DATA_OUTPUT_PROPERTIES.status,") |
| 2083 | const propAccessRegex = /(\w+)\s*:\s*([A-Z][A-Z_0-9]+)\.(\w+)\s*(?:,|$)/g |
| 2084 | let propAccessMatch |
| 2085 | while ((propAccessMatch = propAccessRegex.exec(outputsContent)) !== null) { |
| 2086 | const propName = propAccessMatch[1] |
| 2087 | const constName = propAccessMatch[2] |
| 2088 | const accessedProp = propAccessMatch[3] |
| 2089 | |
| 2090 | // Skip if already resolved |
| 2091 | if (outputs[propName]) { |
| 2092 | continue |
| 2093 | } |
| 2094 | |
| 2095 | // Check if at depth 0 |
| 2096 | const beforeMatch = outputsContent.substring(0, propAccessMatch.index) |
| 2097 | const openBraces = (beforeMatch.match(/\{/g) || []).length |
| 2098 | const closeBraces = (beforeMatch.match(/\}/g) || []).length |
| 2099 | if (openBraces !== closeBraces) { |
| 2100 | continue |
| 2101 | } |
| 2102 | |
| 2103 | const resolvedConst = resolveConstReference(constName, toolPrefix) |
| 2104 | if (resolvedConst?.[accessedProp]) { |
| 2105 | outputs[propName] = resolvedConst[accessedProp] |
| 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | // Pattern 3: Spread operator (e.g., "...COMMENT_OUTPUT_PROPERTIES,") |
| 2110 | const spreadRegex = /\.\.\.([A-Z][A-Z_0-9]+)\s*(?:,|$)/g |
| 2111 | let spreadMatch |
| 2112 | while ((spreadMatch = spreadRegex.exec(outputsContent)) !== null) { |
no test coverage detected