mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-22 00:30:19 +02:00
Improve grok transcript readability
This commit is contained in:
1 parent
9e265ce26e
commit
9b3decfad6
3 files changed
+22
-5
No files matched your search
@@ -6,10 +6,10 @@ describe("parseGrokStdoutLine", () => {
|
||||
|
||||
it("maps thought/text/end events into transcript entries", () => {
|
||||
expect(parseGrokStdoutLine(JSON.stringify({ type: "thought", data: "Plan first." }), ts)).toEqual([
|
||||
{ kind: "thinking", ts, text: "Plan first." },
|
||||
{ kind: "thinking", ts, text: "Plan first.", delta: true },
|
||||
]);
|
||||
expect(parseGrokStdoutLine(JSON.stringify({ type: "text", data: "hello" }), ts)).toEqual([
|
||||
{ kind: "assistant", ts, text: "hello" },
|
||||
{ kind: "assistant", ts, text: "hello", delta: true },
|
||||
]);
|
||||
expect(parseGrokStdoutLine(JSON.stringify({ type: "end", stopReason: "EndTurn", sessionId: "sess-1" }), ts)).toEqual([
|
||||
{ kind: "system", ts, text: "stop_reason=EndTurn session=sess-1" },
|
||||
|
||||
@@ -26,13 +26,13 @@ export function parseGrokStdoutLine(line: string, ts: string): TranscriptEntry[]
|
||||
const type = asString(parsed.type).trim();
|
||||
|
||||
if (type === "thought") {
|
||||
const text = asString(parsed.data).trim();
|
||||
return text ? [{ kind: "thinking", ts, text }] : [];
|
||||
const text = asString(parsed.data);
|
||||
return text ? [{ kind: "thinking", ts, text, delta: true }] : [];
|
||||
}
|
||||
|
||||
if (type === "text") {
|
||||
const text = asString(parsed.data);
|
||||
return text ? [{ kind: "assistant", ts, text }] : [];
|
||||
return text ? [{ kind: "assistant", ts, text, delta: true }] : [];
|
||||
}
|
||||
|
||||
if (type === "error") {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildTranscript, type RunLogChunk } from "./transcript";
|
||||
import { grokLocalUIAdapter } from "./grok-local";
|
||||
import type { UIAdapterModule } from "./types";
|
||||
|
||||
describe("buildTranscript", () => {
|
||||
@@ -182,4 +183,20 @@ describe("buildTranscript", () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("coalesces grok_local streaming text fragments into one assistant entry", () => {
|
||||
const entries = buildTranscript(
|
||||
[
|
||||
{ ts, stream: "stdout", chunk: `${JSON.stringify({ type: "text", data: "Hello " })}\n` },
|
||||
{ ts, stream: "stdout", chunk: `${JSON.stringify({ type: "text", data: "world" })}\n` },
|
||||
{ ts, stream: "stdout", chunk: `${JSON.stringify({ type: "end", stopReason: "EndTurn", sessionId: "sess-1" })}\n` },
|
||||
],
|
||||
grokLocalUIAdapter,
|
||||
);
|
||||
|
||||
expect(entries).toEqual([
|
||||
{ kind: "assistant", ts, text: "Hello world", delta: true },
|
||||
{ kind: "system", ts, text: "stop_reason=EndTurn session=sess-1" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user