@assistant-ui/react-statewire 0.1.1 → 0.2.0
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 +2 -2
- package/dist/AssistantTransportThread.d.ts.map +1 -1
- package/dist/AssistantTransportThread.js +14 -6
- package/dist/AssistantTransportThread.js.map +1 -1
- package/dist/StatewireThread.d.ts +69 -8
- package/dist/StatewireThread.d.ts.map +1 -1
- package/dist/StatewireThread.js +126 -33
- package/dist/StatewireThread.js.map +1 -1
- package/dist/index.d.ts +3 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/types.d.ts +12 -25
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/AssistantTransportThread.ts +23 -10
- package/src/StatewireThread.test.tsx +320 -65
- package/src/StatewireThread.ts +255 -37
- package/src/__tests__/testHelpers.tsx +1 -1
- package/src/athena.e2e.test.tsx +17 -17
- package/src/index.ts +2 -6
- package/src/legacy-diff.test.tsx +25 -8
- package/src/transport.test.tsx +18 -18
- package/src/types.ts +12 -33
package/src/transport.test.tsx
CHANGED
|
@@ -56,7 +56,7 @@ describe("AssistantTransportThread", () => {
|
|
|
56
56
|
expect(fetchMock.requests[0]!.url).toBe("https://example.com/api");
|
|
57
57
|
expect(fetchMock.requests[0]!.body.commands).toEqual([
|
|
58
58
|
{
|
|
59
|
-
type: "add
|
|
59
|
+
type: "message/add",
|
|
60
60
|
message: { role: "user", parts: [{ type: "text", text: "hello" }] },
|
|
61
61
|
parentId: null,
|
|
62
62
|
sourceId: null,
|
|
@@ -147,7 +147,7 @@ describe("AssistantTransportThread", () => {
|
|
|
147
147
|
const meta = metas.at(-1)!;
|
|
148
148
|
expect(meta.isSending).toBe(true);
|
|
149
149
|
expect(meta.pendingCommands).toHaveLength(1);
|
|
150
|
-
expect(meta.pendingCommands[0]).toMatchObject({ type: "add
|
|
150
|
+
expect(meta.pendingCommands[0]).toMatchObject({ type: "message/add" });
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
server.emit({
|
|
@@ -239,7 +239,7 @@ describe("AssistantTransportThread", () => {
|
|
|
239
239
|
});
|
|
240
240
|
|
|
241
241
|
sendCommand(aui, {
|
|
242
|
-
type: "add
|
|
242
|
+
type: "message/add",
|
|
243
243
|
message: { role: "user", parts: [{ type: "text", text: "hello" }] },
|
|
244
244
|
parentId: null,
|
|
245
245
|
sourceId: null,
|
|
@@ -1126,11 +1126,11 @@ describe("AssistantTransportThread", () => {
|
|
|
1126
1126
|
expect(aui().thread().getState().isRunning).toBe(false),
|
|
1127
1127
|
);
|
|
1128
1128
|
|
|
1129
|
-
// Give any stray
|
|
1129
|
+
// Give any stray tool-result/add dispatch a chance to fire.
|
|
1130
1130
|
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
1131
1131
|
expect(
|
|
1132
1132
|
allCommands(fetchMock.requests).filter(
|
|
1133
|
-
(c) => c.type === "
|
|
1133
|
+
(c) => c.type === "tool-result/add",
|
|
1134
1134
|
),
|
|
1135
1135
|
).toEqual([]);
|
|
1136
1136
|
});
|
|
@@ -1156,7 +1156,7 @@ describe("AssistantTransportThread", () => {
|
|
|
1156
1156
|
);
|
|
1157
1157
|
});
|
|
1158
1158
|
|
|
1159
|
-
it("folds completed attachments into the add
|
|
1159
|
+
it("folds completed attachments into the message/add command (CompositeAttachmentAdapter)", async () => {
|
|
1160
1160
|
const fetchMock = installFetch();
|
|
1161
1161
|
const { aui } = mountThread({
|
|
1162
1162
|
adapters: {
|
|
@@ -1180,7 +1180,7 @@ describe("AssistantTransportThread", () => {
|
|
|
1180
1180
|
|
|
1181
1181
|
await waitFor(() => expect(fetchMock.requests).toHaveLength(1));
|
|
1182
1182
|
const command = fetchMock.requests[0]!.body.commands[0];
|
|
1183
|
-
expect(command.type).toBe("add
|
|
1183
|
+
expect(command.type).toBe("message/add");
|
|
1184
1184
|
const texts = command.message.parts.map((p: any) => p.text);
|
|
1185
1185
|
expect(texts[0]).toBe("see file");
|
|
1186
1186
|
expect(texts[1]).toContain("attached body");
|
|
@@ -1212,7 +1212,7 @@ describe("AssistantTransportThread", () => {
|
|
|
1212
1212
|
await waitFor(() => expect(fetchMock.requests).toHaveLength(1));
|
|
1213
1213
|
expect(fetchMock.requests[0]!.body.commands).toEqual([
|
|
1214
1214
|
{
|
|
1215
|
-
type: "add
|
|
1215
|
+
type: "message/add",
|
|
1216
1216
|
message: { role: "user", parts: [{ type: "text", text: "edited" }] },
|
|
1217
1217
|
parentId: "a1",
|
|
1218
1218
|
sourceId: "u2",
|
|
@@ -1244,7 +1244,7 @@ describe("AssistantTransportThread", () => {
|
|
|
1244
1244
|
expect(body.parentId).toBe("a1");
|
|
1245
1245
|
expect(body.commands).toEqual([
|
|
1246
1246
|
{
|
|
1247
|
-
type: "add
|
|
1247
|
+
type: "message/add",
|
|
1248
1248
|
message: { role: "user", parts: [{ type: "text", text: "again" }] },
|
|
1249
1249
|
parentId: "a1",
|
|
1250
1250
|
sourceId: null,
|
|
@@ -1306,7 +1306,7 @@ describe("AssistantTransportThread", () => {
|
|
|
1306
1306
|
servers[1]!.done();
|
|
1307
1307
|
});
|
|
1308
1308
|
|
|
1309
|
-
it("executes frontend tools and posts
|
|
1309
|
+
it("executes frontend tools and posts tool-result/add in a follow-up run", async () => {
|
|
1310
1310
|
const fetchMock = installFetch();
|
|
1311
1311
|
const servers: StreamResponse[] = [];
|
|
1312
1312
|
fetchMock.setHandler(() => {
|
|
@@ -1353,7 +1353,7 @@ describe("AssistantTransportThread", () => {
|
|
|
1353
1353
|
await waitFor(() => expect(fetchMock.requests).toHaveLength(2));
|
|
1354
1354
|
expect(fetchMock.requests[1]!.body.commands).toEqual([
|
|
1355
1355
|
{
|
|
1356
|
-
type: "
|
|
1356
|
+
type: "tool-result/add",
|
|
1357
1357
|
toolCallId: "tc1",
|
|
1358
1358
|
toolName: "probe_tool",
|
|
1359
1359
|
result: { probed: true },
|
|
@@ -1414,7 +1414,7 @@ describe("AssistantTransportThread", () => {
|
|
|
1414
1414
|
await waitFor(() => expect(fetchMock.requests).toHaveLength(2));
|
|
1415
1415
|
expect(fetchMock.requests[1]!.body.commands).toEqual([
|
|
1416
1416
|
{
|
|
1417
|
-
type: "
|
|
1417
|
+
type: "tool-result/add",
|
|
1418
1418
|
toolCallId: "tc1",
|
|
1419
1419
|
toolName: "probe_tool",
|
|
1420
1420
|
result: { answer: "yes" },
|
|
@@ -1463,7 +1463,7 @@ describe("AssistantTransportThread", () => {
|
|
|
1463
1463
|
|
|
1464
1464
|
await waitFor(() =>
|
|
1465
1465
|
expect(allCommands(fetchMock.requests)).toContainEqual({
|
|
1466
|
-
type: "
|
|
1466
|
+
type: "tool-result/add",
|
|
1467
1467
|
toolCallId: "tc1",
|
|
1468
1468
|
toolName: "probe_tool",
|
|
1469
1469
|
result: "Tool execution was cancelled.",
|
|
@@ -1515,14 +1515,14 @@ describe("AssistantTransportThread", () => {
|
|
|
1515
1515
|
await waitFor(() => {
|
|
1516
1516
|
const commands = allCommands(fetchMock.requests);
|
|
1517
1517
|
expect(commands).toContainEqual({
|
|
1518
|
-
type: "
|
|
1518
|
+
type: "tool-result/add",
|
|
1519
1519
|
toolCallId: "tc1",
|
|
1520
1520
|
toolName: "probe_tool",
|
|
1521
1521
|
result: "Tool execution was cancelled.",
|
|
1522
1522
|
isError: true,
|
|
1523
1523
|
});
|
|
1524
1524
|
expect(commands).toContainEqual({
|
|
1525
|
-
type: "add
|
|
1525
|
+
type: "message/add",
|
|
1526
1526
|
message: {
|
|
1527
1527
|
role: "user",
|
|
1528
1528
|
parts: [{ type: "text", text: "next question" }],
|
|
@@ -1990,7 +1990,7 @@ describe("reload", () => {
|
|
|
1990
1990
|
return server.response;
|
|
1991
1991
|
});
|
|
1992
1992
|
sendCommand(aui, {
|
|
1993
|
-
type: "add
|
|
1993
|
+
type: "message/add",
|
|
1994
1994
|
message: { role: "user", parts: [{ type: "text", text: "retry" }] },
|
|
1995
1995
|
parentId: null,
|
|
1996
1996
|
sourceId: null,
|
|
@@ -2042,7 +2042,7 @@ describe("message queue", () => {
|
|
|
2042
2042
|
await waitFor(() => expect(fetchMock.requests).toHaveLength(2));
|
|
2043
2043
|
expect(fetchMock.requests[1]!.body.commands).toMatchObject([
|
|
2044
2044
|
{
|
|
2045
|
-
type: "add
|
|
2045
|
+
type: "message/add",
|
|
2046
2046
|
message: { role: "user", parts: [{ type: "text", text: "second" }] },
|
|
2047
2047
|
},
|
|
2048
2048
|
]);
|
|
@@ -2101,7 +2101,7 @@ describe("message queue", () => {
|
|
|
2101
2101
|
await waitFor(() => expect(fetchMock.requests).toHaveLength(2));
|
|
2102
2102
|
expect(fetchMock.requests[1]!.body.commands).toMatchObject([
|
|
2103
2103
|
{
|
|
2104
|
-
type: "add
|
|
2104
|
+
type: "message/add",
|
|
2105
2105
|
message: { parts: [{ type: "text", text: "second" }] },
|
|
2106
2106
|
},
|
|
2107
2107
|
]);
|
package/src/types.ts
CHANGED
|
@@ -36,15 +36,21 @@ export type AssistantMessage = {
|
|
|
36
36
|
readonly parts: readonly TextPart[];
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
export type
|
|
40
|
-
readonly type: "add
|
|
39
|
+
export type MessageAddCommand = {
|
|
40
|
+
readonly type: "message/add";
|
|
41
41
|
readonly message: UserMessage | AssistantMessage;
|
|
42
42
|
readonly parentId: string | null;
|
|
43
43
|
readonly sourceId: string | null;
|
|
44
|
+
/**
|
|
45
|
+
* How the host handles the message while a run is active: `"queue"`
|
|
46
|
+
* appends to the queue, `"steer"` moves it to the front and interrupts
|
|
47
|
+
* the run. Absent, the host decides. Ignored when the host is idle.
|
|
48
|
+
*/
|
|
49
|
+
readonly behavior?: "queue" | "steer";
|
|
44
50
|
};
|
|
45
51
|
|
|
46
|
-
export type
|
|
47
|
-
readonly type: "
|
|
52
|
+
export type ToolResultAddCommand = {
|
|
53
|
+
readonly type: "tool-result/add";
|
|
48
54
|
readonly toolCallId: string;
|
|
49
55
|
readonly toolName: string;
|
|
50
56
|
readonly result: ReadonlyJSONValue;
|
|
@@ -53,36 +59,9 @@ export type AddToolResultCommand = {
|
|
|
53
59
|
readonly modelContent?: readonly ToolModelContentPart[];
|
|
54
60
|
};
|
|
55
61
|
|
|
56
|
-
export type EnqueueMessageCommand = {
|
|
57
|
-
readonly type: "enqueue-message";
|
|
58
|
-
readonly message: UserMessage | AssistantMessage;
|
|
59
|
-
readonly parentId: string | null;
|
|
60
|
-
readonly sourceId: string | null;
|
|
61
|
-
readonly steer: boolean;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export type SteerQueueItemCommand = {
|
|
65
|
-
readonly type: "steer-queue-item";
|
|
66
|
-
readonly queueItemId: string;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export type RemoveQueueItemCommand = {
|
|
70
|
-
readonly type: "remove-queue-item";
|
|
71
|
-
readonly queueItemId: string;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export type ClearQueueCommand = {
|
|
75
|
-
readonly type: "clear-queue";
|
|
76
|
-
readonly reason: "edit" | "reload" | "cancel-run";
|
|
77
|
-
};
|
|
78
|
-
|
|
79
62
|
export type AssistantTransportCommand =
|
|
80
|
-
|
|
|
81
|
-
|
|
|
82
|
-
| EnqueueMessageCommand
|
|
83
|
-
| SteerQueueItemCommand
|
|
84
|
-
| RemoveQueueItemCommand
|
|
85
|
-
| ClearQueueCommand
|
|
63
|
+
| MessageAddCommand
|
|
64
|
+
| ToolResultAddCommand
|
|
86
65
|
| UserCommands;
|
|
87
66
|
|
|
88
67
|
export type AssistantTransportState = {
|