/** * One parsed kimi stream-json event, normalized for incremental streaming. * - 'assistant': rawText is the full assistant text (fences intact) for * end-of-turn tool-call parsing; text is the fence-stripped prose, * present only when non-empty. * `toolCalls` carries the native tool calls the same message started. * - 'native': a tool-call-only assistant message (`toolCalls`) or a * tool result ({"role":"tool","tool_call_id",...} → `toolResult`) — * forwarded by run() as rich tool_use/tool_result AgentMessages. * - 'tool': a {"role":"tool",...} event with no call id — forwarded by * run() as a `tool_use` liveness AgentMessage (see header). * - 'meta': any other event that only carries a session id. */ export interface KimiStreamEvent { kind: 'assistant' | 'native' | 'tool' | 'meta'; text?: string; rawText?: string; toolName?: string; toolCalls?: Array<{ id: string; name: string; input: unknown; }>; toolResult?: { id: string; output: unknown; }; sessionId?: string; } /** * Parse ONE kimi stream-json line into a normalized event (null for blank, * non-JSON, or content-free lines). Exported for unit tests — this encodes * the wire format verified against kimi 0.29.2, and a CLI format change * should fail loudly in CI, not silently starve an org at runtime. * * Real shapes (verified): * {"role":"assistant","content":"..."} — reply text * {"role":"assistant","content":[{"type":"text",...}]} — block form * {"role":"meta","type":"session.resume_hint",session_id} — resume hint * {"role":"tool","content":"Bash(ls ...)"} — tool progress * kimi-code 2.x stream-json (read from its PromptJsonWriter, not live — * no kimi install here) adds the call/result pairing: * {"role":"assistant","content":...,"tool_calls":[{id,function:{name,arguments}}]} * {"role":"tool","tool_call_id":"...","content":""} */ export declare function parseStreamJsonLine(line: string): KimiStreamEvent | null; /** * Parse kimi stream-json lines into normalized texts + session id. * Batch convenience wrapper over parseStreamJsonLine, kept for callers/tests * that parse a completed turn's output; the runner itself streams per line. */ export declare function parseStreamJsonLines(lines: string[]): { texts: string[]; rawTexts: string[]; sessionId?: string; }; /** Scan stderr for session_id events. Kimi 0.33+ emits session.resume_hint on * stderr (not stdout) in stream-json mode; the stdout parser captures session_id * from assistant events, but if kimi emits it ONLY on stderr we'd miss it and * fall back to a cold session on every turn. This defensive scan catches it * regardless of which stream kimi writes it to. */ export declare function extractStderrSessionId(stderr: string): string | undefined; export interface FatalErrorInfo { fatal: boolean; label?: string; /** A transient provider rate limit (429), not exhausted quota. */ rateLimited?: boolean; } /** Classify a CLI turn's stderr: is this a fatal (non-retryable) failure? */ export declare function classifyStderr(stderrTail: string): FatalErrorInfo; //# sourceMappingURL=kimicode-runner-parse.d.ts.map