Skip to content

Commit 1fb531e

Browse files
committed
fix: add missing type discriminators to storybook chat messages
The MarkdownTables story was emitting messages without the required `type: "message"` field. The `as WorkspaceChatMessage` type casts hid this from TypeScript, causing messages to not be recognized by the chat processor and rendering "No Messages Yet" instead. Also fix ChatEventProcessor tests that had invalid event shapes: - Remove invalid `role`/`timestamp` from stream-start events - Add missing `workspaceId`/`tokens` to delta events
1 parent d136f35 commit 1fb531e

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

src/browser/App.stories.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,17 +1140,16 @@ export const MarkdownTables: Story = {
11401140
setTimeout(() => {
11411141
// User message
11421142
emit({
1143+
type: "message",
11431144
id: "msg-1",
11441145
role: "user",
11451146
parts: [{ type: "text", text: "Show me some table examples" }],
1146-
metadata: {
1147-
historySequence: 1,
1148-
timestamp: STABLE_TIMESTAMP,
1149-
},
1150-
} as WorkspaceChatMessage);
1147+
createdAt: new Date(STABLE_TIMESTAMP),
1148+
});
11511149

11521150
// Assistant message with tables
11531151
emit({
1152+
type: "message",
11541153
id: "msg-2",
11551154
role: "assistant",
11561155
parts: [
@@ -1226,10 +1225,10 @@ These tables should render cleanly without any disruptive copy or download actio
12261225
},
12271226
duration: 2000,
12281227
},
1229-
} as WorkspaceChatMessage);
1228+
});
12301229

12311230
// Mark as caught up
1232-
emit({ type: "caught-up" } as WorkspaceChatMessage);
1231+
emit({ type: "caught-up" });
12331232
}, 100);
12341233
};
12351234

src/browser/utils/messages/ChatEventProcessor.test.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
11
import { createChatEventProcessor } from "./ChatEventProcessor";
2-
import type { WorkspaceChatMessage } from "@/common/orpc/types";
32

43
describe("ChatEventProcessor - Reasoning Delta", () => {
54
it("should merge consecutive reasoning deltas into a single part", () => {
65
const processor = createChatEventProcessor();
6+
const workspaceId = "ws-1";
77
const messageId = "msg-1";
88

99
// Start stream
1010
processor.handleEvent({
1111
type: "stream-start",
12-
workspaceId: "ws-1",
12+
workspaceId,
1313
messageId,
14-
role: "assistant",
1514
model: "gpt-4",
16-
timestamp: 1000,
1715
historySequence: 1,
18-
} as WorkspaceChatMessage);
16+
});
1917

2018
// Send reasoning deltas
2119
processor.handleEvent({
2220
type: "reasoning-delta",
21+
workspaceId,
2322
messageId,
2423
delta: "Thinking",
24+
tokens: 1,
2525
timestamp: 1001,
26-
} as WorkspaceChatMessage);
26+
});
2727

2828
processor.handleEvent({
2929
type: "reasoning-delta",
30+
workspaceId,
3031
messageId,
3132
delta: " about",
33+
tokens: 1,
3234
timestamp: 1002,
33-
} as WorkspaceChatMessage);
35+
});
3436

3537
processor.handleEvent({
3638
type: "reasoning-delta",
39+
workspaceId,
3740
messageId,
3841
delta: " this...",
42+
tokens: 1,
3943
timestamp: 1003,
40-
} as WorkspaceChatMessage);
44+
});
4145

4246
const messages = processor.getMessages();
4347
expect(messages).toHaveLength(1);
@@ -55,42 +59,47 @@ describe("ChatEventProcessor - Reasoning Delta", () => {
5559

5660
it("should separate reasoning parts if interrupted by other content (though unlikely in practice)", () => {
5761
const processor = createChatEventProcessor();
62+
const workspaceId = "ws-1";
5863
const messageId = "msg-1";
5964

6065
// Start stream
6166
processor.handleEvent({
6267
type: "stream-start",
63-
workspaceId: "ws-1",
68+
workspaceId,
6469
messageId,
65-
role: "assistant",
6670
model: "gpt-4",
67-
timestamp: 1000,
6871
historySequence: 1,
69-
} as WorkspaceChatMessage);
72+
});
7073

7174
// Reasoning 1
7275
processor.handleEvent({
7376
type: "reasoning-delta",
77+
workspaceId,
7478
messageId,
7579
delta: "Part 1",
80+
tokens: 1,
7681
timestamp: 1001,
77-
} as WorkspaceChatMessage);
82+
});
7883

7984
// Text delta (interruption - although usually reasoning comes before text)
8085
processor.handleEvent({
8186
type: "stream-delta",
87+
workspaceId,
8288
messageId,
8389
delta: "Some text",
90+
tokens: 2,
8491
timestamp: 1002,
85-
} as WorkspaceChatMessage);
92+
});
8693

8794
// Reasoning 2
8895
processor.handleEvent({
8996
type: "reasoning-delta",
97+
workspaceId,
9098
messageId,
9199
delta: "Part 2",
100+
tokens: 1,
92101
timestamp: 1003,
93-
} as WorkspaceChatMessage);
102+
});
94103

95104
const messages = processor.getMessages();
96105
const parts = messages[0].parts;

0 commit comments

Comments
 (0)