(argumentsText: string)
| 45 | } |
| 46 | |
| 47 | export function parseStreamingArgs(argumentsText: string): Record<string, unknown> { |
| 48 | const previewText = argumentsText.slice(0, STREAMING_ARGS_PREVIEW_MAX_CHARS); |
| 49 | if (previewText.trim().length === 0) return {}; |
| 50 | if ( |
| 51 | argumentsText.length <= STREAMING_ARGS_PREVIEW_MAX_CHARS && |
| 52 | previewText.trimEnd().endsWith('}') |
| 53 | ) { |
| 54 | try { |
| 55 | const parsed = JSON.parse(previewText) as unknown; |
| 56 | if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) { |
| 57 | return parsed as Record<string, unknown>; |
| 58 | } |
| 59 | } catch { |
| 60 | // fall through to partial scan |
| 61 | } |
| 62 | } |
| 63 | const result: Record<string, unknown> = {}; |
| 64 | for (const match of previewText.matchAll(STREAMING_ARGS_FIELD_RE)) { |
| 65 | const key = match[1]; |
| 66 | const rawValue = match[2]; |
| 67 | if (key === undefined || rawValue === undefined) continue; |
| 68 | if (!(key in result)) { |
| 69 | result[key] = unescapeJsonString(rawValue); |
| 70 | } |
| 71 | } |
| 72 | return result; |
| 73 | } |
| 74 | |
| 75 | export function argsRecord(args: unknown): Record<string, unknown> { |
| 76 | return typeof args === 'object' && args !== null && !Array.isArray(args) |
no test coverage detected