MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / parseStreamingArgs

Function parseStreamingArgs

apps/kimi-code/src/tui/utils/event-payload.ts:47–73  ·  view source on GitHub ↗
(argumentsText: string)

Source from the content-addressed store, hash-verified

45}
46
47export 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
75export function argsRecord(args: unknown): Record<string, unknown> {
76 return typeof args === 'object' && args !== null && !Array.isArray(args)

Callers 3

flushToolCallPreviewMethod · 0.90

Calls 1

unescapeJsonStringFunction · 0.70

Tested by

no test coverage detected