@assistant-ui/react-statewire 0.0.2 → 0.0.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/dist/AssistantTransportThread.d.ts +4 -2
- package/dist/AssistantTransportThread.d.ts.map +1 -1
- package/dist/AssistantTransportThread.js +11 -10
- package/dist/AssistantTransportThread.js.map +1 -1
- package/dist/StatewireThread.d.ts +35 -0
- package/dist/StatewireThread.d.ts.map +1 -0
- package/dist/StatewireThread.js +71 -0
- package/dist/StatewireThread.js.map +1 -0
- package/dist/host.d.ts +2 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +120 -123
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +22 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -2
- package/dist/replayBoundaryStream.d.ts.map +1 -1
- package/dist/replayBoundaryStream.js +4 -2
- package/dist/replayBoundaryStream.js.map +1 -1
- package/dist/stateOps.d.ts +2 -2
- package/dist/stateOps.d.ts.map +1 -1
- package/dist/stateOps.js +24 -16
- package/dist/stateOps.js.map +1 -1
- package/package.json +11 -12
- package/src/AssistantTransportThread.ts +18 -17
- package/src/StatewireThread.test.tsx +262 -0
- package/src/StatewireThread.ts +159 -0
- package/src/host.ts +112 -98
- package/src/index.ts +23 -19
- package/src/replayBoundaryStream.ts +8 -2
- package/src/stateOps.test.ts +53 -13
- package/src/stateOps.ts +23 -19
- package/src/transport.test.tsx +146 -6
- package/LICENSE +0 -21
package/src/transport.test.tsx
CHANGED
|
@@ -341,7 +341,7 @@ describe("AssistantTransportThread", () => {
|
|
|
341
341
|
expect(errored[0]).toEqual([{ type: "custom-a" }]);
|
|
342
342
|
});
|
|
343
343
|
|
|
344
|
-
it("applies
|
|
344
|
+
it("applies chunk ops one-by-one — an op error mid-chunk keeps the applied prefix", async () => {
|
|
345
345
|
const fetchMock = installFetch();
|
|
346
346
|
const servers: StreamResponse[] = [];
|
|
347
347
|
fetchMock.setHandler(() => {
|
|
@@ -361,8 +361,8 @@ describe("AssistantTransportThread", () => {
|
|
|
361
361
|
sendCommand(aui, { type: "custom-a" } as never);
|
|
362
362
|
await waitFor(() => expect(fetchMock.requests).toHaveLength(1));
|
|
363
363
|
|
|
364
|
-
// Second op is invalid (append-text onto a non-string) — the
|
|
365
|
-
//
|
|
364
|
+
// Second op is invalid (append-text onto a non-string) — the run errors,
|
|
365
|
+
// but the ops before it stay applied.
|
|
366
366
|
servers[0]!.emit({
|
|
367
367
|
type: "update-state",
|
|
368
368
|
operations: [
|
|
@@ -378,11 +378,13 @@ describe("AssistantTransportThread", () => {
|
|
|
378
378
|
|
|
379
379
|
await waitFor(() => expect(errors).toHaveLength(1));
|
|
380
380
|
|
|
381
|
-
// The
|
|
381
|
+
// The applied prefix carries into the next request body.
|
|
382
382
|
sendCommand(aui, { type: "custom-b" } as never);
|
|
383
383
|
await waitFor(() => expect(fetchMock.requests).toHaveLength(2));
|
|
384
|
-
expect(fetchMock.requests[1]!.body.state).toEqual(
|
|
385
|
-
|
|
384
|
+
expect(fetchMock.requests[1]!.body.state).toEqual({
|
|
385
|
+
messages: [{ id: "m1", role: "assistant", text: "partial" }],
|
|
386
|
+
});
|
|
387
|
+
expect(threadTexts(aui)).toEqual(["partial"]);
|
|
386
388
|
});
|
|
387
389
|
|
|
388
390
|
it("cancels a running request and reports all pending commands", async () => {
|
|
@@ -438,6 +440,48 @@ describe("AssistantTransportThread", () => {
|
|
|
438
440
|
);
|
|
439
441
|
});
|
|
440
442
|
|
|
443
|
+
it("decodes resume runs leniently — unknown events and a missing [DONE] still apply valid chunks", async () => {
|
|
444
|
+
const fetchMock = installFetch();
|
|
445
|
+
fetchMock.setHandler(() => {
|
|
446
|
+
const server = createStreamResponse();
|
|
447
|
+
server.push("event: custom\ndata: {}\n\n");
|
|
448
|
+
server.emit({
|
|
449
|
+
type: "update-state",
|
|
450
|
+
operations: [
|
|
451
|
+
{
|
|
452
|
+
type: "set",
|
|
453
|
+
path: ["messages"],
|
|
454
|
+
value: [{ id: "m1", role: "assistant", text: "recovered" }],
|
|
455
|
+
},
|
|
456
|
+
],
|
|
457
|
+
});
|
|
458
|
+
server.close();
|
|
459
|
+
return server.response;
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
const errors: string[] = [];
|
|
463
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
464
|
+
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
465
|
+
try {
|
|
466
|
+
const { aui } = mountThread({
|
|
467
|
+
resumeApi: "https://example.com/resume",
|
|
468
|
+
onError: (error) => {
|
|
469
|
+
errors.push(error.message);
|
|
470
|
+
},
|
|
471
|
+
});
|
|
472
|
+
aui().thread().resumeRun({ parentId: null });
|
|
473
|
+
|
|
474
|
+
await waitFor(() => expect(threadTexts(aui)).toEqual(["recovered"]));
|
|
475
|
+
await waitFor(() =>
|
|
476
|
+
expect(aui().thread().getState().isRunning).toBe(false),
|
|
477
|
+
);
|
|
478
|
+
expect(errors).toEqual([]);
|
|
479
|
+
} finally {
|
|
480
|
+
warnSpy.mockRestore();
|
|
481
|
+
errorSpy.mockRestore();
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
|
|
441
485
|
it("surfaces error chunks after the stream completes", async () => {
|
|
442
486
|
const fetchMock = installFetch();
|
|
443
487
|
fetchMock.setHandler(() => {
|
|
@@ -858,6 +902,31 @@ describe("AssistantTransportThread", () => {
|
|
|
858
902
|
expect(loadingStates).toEqual([false, false]);
|
|
859
903
|
});
|
|
860
904
|
|
|
905
|
+
it("surfaces an invalid replay header via onError", async () => {
|
|
906
|
+
const fetchMock = installFetch();
|
|
907
|
+
fetchMock.setHandler(() => {
|
|
908
|
+
const server = createStreamResponse({
|
|
909
|
+
headers: { "Aui-Replay-Content-Length": "garbage" },
|
|
910
|
+
});
|
|
911
|
+
return server.response;
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
const errors: string[] = [];
|
|
915
|
+
const { aui } = mountThread({
|
|
916
|
+
resumeApi: "https://example.com/resume",
|
|
917
|
+
onError: (error) => {
|
|
918
|
+
errors.push(error.message);
|
|
919
|
+
},
|
|
920
|
+
});
|
|
921
|
+
aui().thread().resumeRun({ parentId: null });
|
|
922
|
+
|
|
923
|
+
await waitFor(() =>
|
|
924
|
+
expect(errors).toEqual([
|
|
925
|
+
'statewire: invalid Aui-Replay-Content-Length header "garbage"',
|
|
926
|
+
]),
|
|
927
|
+
);
|
|
928
|
+
});
|
|
929
|
+
|
|
861
930
|
it("reads body object getters at request time", async () => {
|
|
862
931
|
const fetchMock = installFetch();
|
|
863
932
|
let dynamic = "before";
|
|
@@ -1856,3 +1925,74 @@ describe("AssistantTransportThread", () => {
|
|
|
1856
1925
|
]);
|
|
1857
1926
|
});
|
|
1858
1927
|
});
|
|
1928
|
+
|
|
1929
|
+
describe("reload", () => {
|
|
1930
|
+
const completeFirstTurn = async (
|
|
1931
|
+
fetchMock: ReturnType<typeof installFetch>,
|
|
1932
|
+
aui: () => ReturnType<typeof useAui>,
|
|
1933
|
+
) => {
|
|
1934
|
+
let server!: StreamResponse;
|
|
1935
|
+
fetchMock.setHandler(() => {
|
|
1936
|
+
server = createStreamResponse();
|
|
1937
|
+
return server.response;
|
|
1938
|
+
});
|
|
1939
|
+
aui().thread().append("hello");
|
|
1940
|
+
await waitFor(() => expect(fetchMock.requests).toHaveLength(1));
|
|
1941
|
+
server.emit({
|
|
1942
|
+
type: "update-state",
|
|
1943
|
+
operations: [
|
|
1944
|
+
{
|
|
1945
|
+
type: "set",
|
|
1946
|
+
path: ["messages"],
|
|
1947
|
+
value: [
|
|
1948
|
+
{ id: "m1", role: "user", text: "hello" },
|
|
1949
|
+
{ id: "m2", role: "assistant", text: "hi" },
|
|
1950
|
+
],
|
|
1951
|
+
},
|
|
1952
|
+
],
|
|
1953
|
+
});
|
|
1954
|
+
server.done();
|
|
1955
|
+
await waitFor(() =>
|
|
1956
|
+
expect(aui().thread().getState().isRunning).toBe(false),
|
|
1957
|
+
);
|
|
1958
|
+
};
|
|
1959
|
+
|
|
1960
|
+
it("regenerates from idle with an empty queue", async () => {
|
|
1961
|
+
const fetchMock = installFetch();
|
|
1962
|
+
const { aui } = mountThread();
|
|
1963
|
+
await completeFirstTurn(fetchMock, aui);
|
|
1964
|
+
|
|
1965
|
+
aui().thread().message({ id: "m2" }).reload();
|
|
1966
|
+
await waitFor(() => expect(fetchMock.requests).toHaveLength(2));
|
|
1967
|
+
expect(fetchMock.requests[1]!.body.commands).toEqual([]);
|
|
1968
|
+
expect(fetchMock.requests[1]!.body.parentId).toBe("m1");
|
|
1969
|
+
});
|
|
1970
|
+
|
|
1971
|
+
it("keeps the parentId for the next run when the reload run fails", async () => {
|
|
1972
|
+
const fetchMock = installFetch();
|
|
1973
|
+
const { aui } = mountThread();
|
|
1974
|
+
await completeFirstTurn(fetchMock, aui);
|
|
1975
|
+
|
|
1976
|
+
fetchMock.setHandler(() => new Response(null, { status: 500 }));
|
|
1977
|
+
aui().thread().message({ id: "m2" }).reload();
|
|
1978
|
+
await waitFor(() => expect(fetchMock.requests).toHaveLength(2));
|
|
1979
|
+
await waitFor(() =>
|
|
1980
|
+
expect(aui().thread().getState().isRunning).toBe(false),
|
|
1981
|
+
);
|
|
1982
|
+
expect(fetchMock.requests[1]!.body.parentId).toBe("m1");
|
|
1983
|
+
|
|
1984
|
+
fetchMock.setHandler(() => {
|
|
1985
|
+
const server = createStreamResponse();
|
|
1986
|
+
server.done();
|
|
1987
|
+
return server.response;
|
|
1988
|
+
});
|
|
1989
|
+
sendCommand(aui, {
|
|
1990
|
+
type: "add-message",
|
|
1991
|
+
message: { role: "user", parts: [{ type: "text", text: "retry" }] },
|
|
1992
|
+
parentId: null,
|
|
1993
|
+
sourceId: null,
|
|
1994
|
+
});
|
|
1995
|
+
await waitFor(() => expect(fetchMock.requests).toHaveLength(3));
|
|
1996
|
+
expect(fetchMock.requests[2]!.body.parentId).toBe("m1");
|
|
1997
|
+
});
|
|
1998
|
+
});
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 AgentbaseAI Inc.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|