@assistant-ui/react-ag-ui 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/runtime/AgUiThreadController.d.ts +11 -0
- package/dist/runtime/AgUiThreadController.d.ts.map +1 -1
- package/dist/runtime/AgUiThreadController.js +242 -25
- package/dist/runtime/AgUiThreadController.js.map +1 -1
- package/dist/runtime/adapter/conversions.d.ts +9 -1
- package/dist/runtime/adapter/conversions.d.ts.map +1 -1
- package/dist/runtime/adapter/conversions.js +184 -9
- package/dist/runtime/adapter/conversions.js.map +1 -1
- package/dist/runtime/adapter/run-aggregator.d.ts +2 -0
- package/dist/runtime/adapter/run-aggregator.d.ts.map +1 -1
- package/dist/runtime/adapter/run-aggregator.js +42 -12
- package/dist/runtime/adapter/run-aggregator.js.map +1 -1
- package/dist/runtime/adapter/subscriber.d.ts +0 -1
- package/dist/runtime/adapter/subscriber.d.ts.map +1 -1
- package/dist/runtime/adapter/subscriber.js +1 -8
- package/dist/runtime/adapter/subscriber.js.map +1 -1
- package/dist/runtime/event-parser.d.ts.map +1 -1
- package/dist/runtime/event-parser.js +1 -0
- package/dist/runtime/event-parser.js.map +1 -1
- package/dist/runtime/types.d.ts +2 -0
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/types.js +2 -1
- package/dist/runtime/types.js.map +1 -1
- package/package.json +6 -5
- package/src/runtime/AgUiThreadController.disconnect.test.ts +914 -0
- package/src/runtime/AgUiThreadController.interrupt-history.test.ts +392 -0
- package/src/runtime/AgUiThreadController.replay.test.ts +8 -1
- package/src/runtime/AgUiThreadController.snapshot-head-move.test.ts +346 -0
- package/src/runtime/AgUiThreadController.subagent-snapshot.test.ts +854 -0
- package/src/runtime/AgUiThreadController.test.ts +173 -1
- package/src/runtime/AgUiThreadController.ts +528 -33
- package/src/runtime/adapter/conversions.content.test.ts +129 -0
- package/src/runtime/adapter/conversions.subagent-messages.test.ts +550 -0
- package/src/runtime/adapter/conversions.ts +331 -20
- package/src/runtime/adapter/run-aggregator.metadata.test.ts +151 -0
- package/src/runtime/adapter/run-aggregator.ts +63 -9
- package/src/runtime/adapter/subscriber.test.ts +1 -1
- package/src/runtime/adapter/subscriber.ts +1 -6
- package/src/runtime/event-parser.ts +3 -0
- package/src/runtime/types.ts +5 -0
- package/src/useAgUiRuntime.cloud-run-leases.test.tsx +384 -0
- package/src/useAgUiRuntime.state.test.tsx +87 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { HttpAgent } from "@ag-ui/client";
|
|
4
|
+
import { act, cleanup, renderHook, waitFor } from "@testing-library/react";
|
|
5
|
+
import { afterEach, expect, it } from "vitest";
|
|
6
|
+
import { useAgUiRuntime } from "./useAgUiRuntime";
|
|
7
|
+
|
|
8
|
+
afterEach(cleanup);
|
|
9
|
+
|
|
10
|
+
it("sends initialState on the first request and keeps middleware clientContext out of thread.state", async () => {
|
|
11
|
+
const sentStates: unknown[] = [];
|
|
12
|
+
const agent = new HttpAgent({
|
|
13
|
+
url: "http://agent.test/agent",
|
|
14
|
+
initialState: { fromInitialState: true },
|
|
15
|
+
fetch: async (_url, init) => {
|
|
16
|
+
const body = JSON.parse(String(init?.body));
|
|
17
|
+
sentStates.push(body.state);
|
|
18
|
+
const events = [
|
|
19
|
+
{ type: "RUN_STARTED", threadId: body.threadId, runId: body.runId },
|
|
20
|
+
{ type: "STATE_DELTA", delta: [{ op: "add", path: "/foo", value: 1 }] },
|
|
21
|
+
{
|
|
22
|
+
type: "TEXT_MESSAGE_START",
|
|
23
|
+
messageId: `m-${body.runId}`,
|
|
24
|
+
role: "assistant",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
type: "TEXT_MESSAGE_CONTENT",
|
|
28
|
+
messageId: `m-${body.runId}`,
|
|
29
|
+
delta: "ok",
|
|
30
|
+
},
|
|
31
|
+
{ type: "TEXT_MESSAGE_END", messageId: `m-${body.runId}` },
|
|
32
|
+
{ type: "RUN_FINISHED", threadId: body.threadId, runId: body.runId },
|
|
33
|
+
];
|
|
34
|
+
return new Response(
|
|
35
|
+
events.map((event) => `data: ${JSON.stringify(event)}\n\n`).join(""),
|
|
36
|
+
{ headers: { "content-type": "text/event-stream" } },
|
|
37
|
+
);
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
agent.use((input, next) =>
|
|
41
|
+
next.run({ ...input, state: { ...input.state, clientContext: "x" } }),
|
|
42
|
+
);
|
|
43
|
+
const { result } = renderHook(() => useAgUiRuntime({ agent }));
|
|
44
|
+
const { result: otherThread } = renderHook(() => useAgUiRuntime({ agent }));
|
|
45
|
+
|
|
46
|
+
expect(result.current.thread.getState().state).toEqual({
|
|
47
|
+
fromInitialState: true,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
for (const text of ["first", "second"]) {
|
|
51
|
+
await act(async () => {
|
|
52
|
+
await result.current.thread.append({
|
|
53
|
+
role: "user",
|
|
54
|
+
content: [{ type: "text", text }],
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
await waitFor(() =>
|
|
58
|
+
expect(result.current.thread.getState().isRunning).toBe(false),
|
|
59
|
+
);
|
|
60
|
+
expect(otherThread.current.thread.getState().state).toEqual({
|
|
61
|
+
fromInitialState: true,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
expect(sentStates).toEqual([
|
|
66
|
+
{ fromInitialState: true, clientContext: "x" },
|
|
67
|
+
{ fromInitialState: true, foo: 1, clientContext: "x" },
|
|
68
|
+
]);
|
|
69
|
+
expect(result.current.thread.getState().state).toEqual({
|
|
70
|
+
fromInitialState: true,
|
|
71
|
+
foo: 1,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
await act(async () => {
|
|
75
|
+
await otherThread.current.thread.append({
|
|
76
|
+
role: "user",
|
|
77
|
+
content: [{ type: "text", text: "other thread" }],
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
await waitFor(() =>
|
|
81
|
+
expect(otherThread.current.thread.getState().isRunning).toBe(false),
|
|
82
|
+
);
|
|
83
|
+
expect(sentStates[2]).toEqual({
|
|
84
|
+
fromInitialState: true,
|
|
85
|
+
clientContext: "x",
|
|
86
|
+
});
|
|
87
|
+
});
|