Skip to content

Commit af99704

Browse files
committed
refactor: change types to conform server SessionStream
resolves #13
1 parent 408dbd4 commit af99704

13 files changed

+785
-160
lines changed

src/__tests__/serve_mock.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test("Should run hook", async () => {
1313
counter++;
1414
},
1515
onclose() {
16-
expect(counter).greaterThanOrEqual(40);
16+
expect(counter).greaterThanOrEqual(39);
1717
},
1818
onerror(err: Error) {
1919
throw err;

src/__tests__/useMessageStreamByEvents.test.tsx

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { renderHook, waitFor } from "@testing-library/react";
2-
import { act } from "react";
1+
import { act, renderHook, waitFor } from "@testing-library/react";
32
import { expect } from "vitest";
43
import { useMessageStreamByEvents } from "../useMessageStreamByEvents";
54
import { useStream } from "../useStream";
65
import { test } from "./test_extended";
76

87
test("should process empty events array", async () => {
98
const { result } = renderHook(() =>
10-
useMessageStreamByEvents({ emittedEvents: [] }),
9+
useMessageStreamByEvents({ sessionStream: [] }),
1110
);
1211
expect(result.current.isThinking).toBe(false);
1312
expect(result.current.messages).toEqual([]);
@@ -16,22 +15,23 @@ test("should process empty events array", async () => {
1615
test("should set isThinking if event is status", async () => {
1716
const { result } = renderHook(() =>
1817
useMessageStreamByEvents({
19-
emittedEvents: [
18+
sessionStream: [
2019
{
2120
id: "63678573-3ac5-45fe-b7b5-1cee2a8a0759",
22-
source: "ai_agent",
23-
type: "status",
24-
correlation_id: "sess1",
21+
event: "status",
2522
data: {
23+
id: "63678573-3ac5-45fe-b7b5-1cee2a8a0759",
24+
source: "ai_agent",
2625
type: "status",
27-
acknowledged_offset: 0,
28-
status: "processing",
29-
data: {},
26+
correlation_id: "sess1",
27+
data: {
28+
type: "status",
29+
acknowledged_offset: 0,
30+
status: "processing",
31+
data: {},
32+
},
33+
metadata: null,
3034
},
31-
metadata: null,
32-
offset: 0,
33-
deleted: false,
34-
created_at: "2021-08-26T14:00:00.000",
3535
},
3636
],
3737
}),
@@ -44,15 +44,17 @@ test("should set isThinking if event is status", async () => {
4444
test("should handle a new chunk", async () => {
4545
const { result } = renderHook(() =>
4646
useMessageStreamByEvents({
47-
emittedEvents: [
47+
sessionStream: [
4848
{
49-
id: "a1b2c3d4e5",
50-
correlation_id: "sess1",
51-
event_id: "event1",
52-
seq: 0,
53-
patches: [{ op: "add", path: "/-", value: "The" }],
54-
metadata: { agent_id: "foo", agent_name: "test" },
55-
timestamp: 1740583796.8028002,
49+
event: "chunk",
50+
data: {
51+
correlation_id: "sess1",
52+
event_id: "event1",
53+
seq: 0,
54+
patches: [{ op: "add", path: "/-", value: "The" }],
55+
metadata: { agent_id: "foo", agent_name: "test" },
56+
timestamp: 1740583796.8028002,
57+
},
5658
},
5759
],
5860
}),
@@ -75,7 +77,7 @@ test("should handle full run", async () => {
7577
});
7678

7779
const { result } = renderHook(() =>
78-
useMessageStreamByEvents({ emittedEvents: useStreamResult.current.events }),
80+
useMessageStreamByEvents({ sessionStream: useStreamResult.current.events }),
7981
);
8082

8183
expect(result.current.isThinking).toBe(false);
@@ -101,22 +103,23 @@ test("should handle full run", async () => {
101103
test("should handle persisted events", async () => {
102104
const { result } = renderHook(() =>
103105
useMessageStreamByEvents({
104-
emittedEvents: [
106+
sessionStream: [
105107
{
106108
id: "63678573-3ac5-45fe-b7b5-1cee2a8a0759",
107-
source: "ai_agent",
108-
type: "status",
109-
correlation_id: "sess1",
109+
event: "status",
110110
data: {
111+
id: "63678573-3ac5-45fe-b7b5-1cee2a8a0759",
112+
source: "ai_agent",
111113
type: "status",
112-
acknowledged_offset: 0,
113-
status: "processing",
114-
data: {},
114+
correlation_id: "sess1",
115+
data: {
116+
type: "status",
117+
acknowledged_offset: 0,
118+
status: "processing",
119+
data: {},
120+
},
121+
metadata: null,
115122
},
116-
metadata: null,
117-
offset: 0,
118-
deleted: false,
119-
created_at: "2021-08-26T14:00:00.000",
120123
},
121124
],
122125
}),

src/__tests__/useStream.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test("should start streaming and process received events", async () => {
1515
timeout: 2000,
1616
});
1717

18-
expect(result.current.events.length).greaterThanOrEqual(40);
18+
expect(result.current.events.length).greaterThanOrEqual(39);
1919
expect(result.current.streaming).toBe(false);
2020
});
2121

0 commit comments

Comments
 (0)