|
1 | 1 | import { decode } from 'html-entities'; |
2 | | -import { isEmpty } from 'lodash-es'; |
| 2 | +import { parseObjectToString } from '@open-webui-react-native/shared/utils/strings'; |
3 | 3 |
|
4 | 4 | type PayloadContentType = 'json' | 'text'; |
5 | 5 |
|
@@ -50,7 +50,11 @@ const readQuotedAttr = (tag: string, attr: string): string | null => { |
50 | 50 |
|
51 | 51 | continue; |
52 | 52 | } else { |
53 | | - out += esc; |
| 53 | + // e.g. `\"` in attributes: keep `\`, let `"` pass through for html decode |
| 54 | + out += c; |
| 55 | + i += 1; |
| 56 | + |
| 57 | + continue; |
54 | 58 | } |
55 | 59 |
|
56 | 60 | i += 2; |
@@ -114,8 +118,8 @@ const indexAfterOpenDetailsTag = (s: string): number => { |
114 | 118 | return -1; |
115 | 119 | }; |
116 | 120 |
|
117 | | -const parseJsonRecursive = (str: string): unknown => { |
118 | | - let cur: unknown = str.trim(); |
| 121 | +const parseJsonRecursive = (str: string): string => { |
| 122 | + let cur = str.trim(); |
119 | 123 |
|
120 | 124 | for (let depth = 0; depth < 32; depth++) { |
121 | 125 | if (typeof cur !== 'string') { |
@@ -198,11 +202,8 @@ const tryParseLeadingToolCallsDetails = (content: string): { tool: ToolData; res |
198 | 202 | const argsRaw = readQuotedAttr(openTag, 'arguments') ?? ''; |
199 | 203 | const resultRaw = readQuotedAttr(openTag, 'result') ?? ''; |
200 | 204 |
|
201 | | - const inputPayload = classifyAndNormalizePayload(argsRaw); |
202 | 205 | const outputPayload = classifyAndNormalizePayload(resultRaw); |
203 | | - const parsedArgs = parseJsonRecursive(decode(argsRaw).trim()); |
204 | | - const input = |
205 | | - typeof parsedArgs === 'object' && parsedArgs !== null && isEmpty(parsedArgs) ? undefined : inputPayload.normalized; |
| 206 | + const input = parseObjectToString(parseJsonRecursive(decode(argsRaw).trim())); |
206 | 207 |
|
207 | 208 | const blockEnd = leadingWs.length + openEnd + closeMatch.index + closeMatch[0].length; |
208 | 209 | const rest = content.slice(blockEnd).trimStart(); |
|
0 commit comments