
























@@ -125,6 +125,33 @@ describe("parseCliJson", () => {
125125});
126126});
127127128+it("unwraps nested Claude result JSON from JSON output", () => {
129+const result = parseCliJson(
130+JSON.stringify({
131+session_id: "session-nested-json",
132+result: JSON.stringify({
133+type: "result",
134+result: JSON.stringify({
135+type: "result",
136+subtype: "success",
137+result: "actual response text",
138+}),
139+}),
140+}),
141+{
142+command: "claude",
143+output: "json",
144+sessionIdFields: ["session_id"],
145+},
146+);
147+148+expect(result).toEqual({
149+text: "actual response text",
150+sessionId: "session-nested-json",
151+usage: undefined,
152+});
153+});
154+128155it("parses nested OpenAI-style cached token details from CLI json payloads", () => {
129156const result = parseCliJson(
130157JSON.stringify({
@@ -295,6 +322,38 @@ describe("parseCliJsonl", () => {
295322});
296323});
297324325+it("unwraps nested Claude agent result JSON from stream-json output", () => {
326+const result = parseCliJsonl(
327+[
328+JSON.stringify({ type: "init", session_id: "session-nested-jsonl" }),
329+JSON.stringify({
330+type: "result",
331+session_id: "session-nested-jsonl",
332+result: JSON.stringify({
333+type: "result",
334+result: JSON.stringify({
335+type: "result",
336+subtype: "success",
337+result: "actual response text",
338+}),
339+}),
340+}),
341+].join("\n"),
342+{
343+command: "claude",
344+output: "jsonl",
345+sessionIdFields: ["session_id"],
346+},
347+"claude-cli",
348+);
349+350+expect(result).toEqual({
351+text: "actual response text",
352+sessionId: "session-nested-jsonl",
353+usage: undefined,
354+});
355+});
356+298357it("parses multiple JSON objects embedded on the same line", () => {
299358const result = parseCliJsonl(
300359'{"type":"init","session_id":"session-999"} {"type":"result","session_id":"session-999","result":"done"}',
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。