@assistant-ui/react-ag-ui 0.0.53 → 0.0.56
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/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/runtime/AgUiThreadRuntimeCore.d.ts +23 -2
- package/dist/runtime/AgUiThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtime/AgUiThreadRuntimeCore.js +183 -39
- package/dist/runtime/AgUiThreadRuntimeCore.js.map +1 -1
- package/dist/runtime/adapter/conversions.d.ts +19 -3
- package/dist/runtime/adapter/conversions.d.ts.map +1 -1
- package/dist/runtime/adapter/conversions.js +197 -36
- package/dist/runtime/adapter/conversions.js.map +1 -1
- package/dist/runtime/adapter/run-aggregator.d.ts +15 -2
- package/dist/runtime/adapter/run-aggregator.d.ts.map +1 -1
- package/dist/runtime/adapter/run-aggregator.js +62 -10
- package/dist/runtime/adapter/run-aggregator.js.map +1 -1
- package/dist/runtime/adapter/subscriber.d.ts +6 -0
- package/dist/runtime/adapter/subscriber.d.ts.map +1 -1
- package/dist/runtime/adapter/subscriber.js +10 -0
- package/dist/runtime/adapter/subscriber.js.map +1 -1
- package/dist/runtime/adapter/tool-approval.d.ts +56 -0
- package/dist/runtime/adapter/tool-approval.d.ts.map +1 -0
- package/dist/runtime/adapter/tool-approval.js +244 -0
- package/dist/runtime/adapter/tool-approval.js.map +1 -0
- package/dist/runtime/event-parser.d.ts.map +1 -1
- package/dist/runtime/event-parser.js +15 -1
- package/dist/runtime/event-parser.js.map +1 -1
- package/dist/runtime/interrupt-internals.d.ts +8 -0
- package/dist/runtime/interrupt-internals.d.ts.map +1 -0
- package/dist/runtime/interrupt-internals.js +25 -0
- package/dist/runtime/interrupt-internals.js.map +1 -0
- package/dist/runtime/types.d.ts +5 -0
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/useAgUiRuntime.js +4 -1
- package/dist/useAgUiRuntime.js.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +8 -2
- package/src/runtime/AgUiThreadRuntimeCore.ts +335 -42
- package/src/runtime/adapter/conversions.content.test.ts +278 -0
- package/src/runtime/adapter/conversions.ts +298 -50
- package/src/runtime/adapter/run-aggregator.approval.test.ts +103 -0
- package/src/runtime/adapter/run-aggregator.ts +96 -5
- package/src/runtime/adapter/subscriber.ts +17 -0
- package/src/runtime/adapter/tool-approval.test.ts +681 -0
- package/src/runtime/adapter/tool-approval.ts +366 -0
- package/src/runtime/event-parser.ts +23 -1
- package/src/runtime/interrupt-internals.ts +35 -0
- package/src/runtime/types.ts +6 -0
- package/src/useAgUiRuntime.approval.test.tsx +885 -0
- package/src/useAgUiRuntime.queue.test.tsx +68 -1
- package/src/useAgUiRuntime.ts +5 -1
|
@@ -27,7 +27,7 @@ const gatedAgent = () => {
|
|
|
27
27
|
},
|
|
28
28
|
);
|
|
29
29
|
return {
|
|
30
|
-
agent: { runAgent } as unknown as HttpAgent,
|
|
30
|
+
agent: { runAgent, abortRun: vi.fn() } as unknown as HttpAgent,
|
|
31
31
|
runAgent,
|
|
32
32
|
release: () => release(),
|
|
33
33
|
};
|
|
@@ -95,6 +95,73 @@ describe("useAgUiRuntime unstable_enableMessageQueue", () => {
|
|
|
95
95
|
);
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
+
it("preserves queued sends when the active run is cancelled", async () => {
|
|
99
|
+
const { agent, runAgent, release } = gatedAgent();
|
|
100
|
+
|
|
101
|
+
const { result } = renderHook(() =>
|
|
102
|
+
useAgUiRuntime({ agent, unstable_enableMessageQueue: true }),
|
|
103
|
+
);
|
|
104
|
+
mount(result.current);
|
|
105
|
+
|
|
106
|
+
await act(async () => {
|
|
107
|
+
await result.current.thread.append({
|
|
108
|
+
role: "user",
|
|
109
|
+
content: [{ type: "text", text: "first" }],
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
await waitFor(() => expect(runAgent).toHaveBeenCalledTimes(1));
|
|
113
|
+
|
|
114
|
+
await act(async () => {
|
|
115
|
+
await result.current.thread.append({
|
|
116
|
+
role: "user",
|
|
117
|
+
content: [{ type: "text", text: "second" }],
|
|
118
|
+
parentId: result.current.thread.getState().messages.at(-1)?.id ?? null,
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
await waitFor(() =>
|
|
122
|
+
expect(screen.getByTestId("queued").textContent).toBe("second"),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
act(() => {
|
|
126
|
+
result.current.thread.cancelRun();
|
|
127
|
+
});
|
|
128
|
+
await act(async () => {
|
|
129
|
+
release();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
expect(runAgent).toHaveBeenCalledTimes(1);
|
|
133
|
+
await waitFor(() =>
|
|
134
|
+
expect(screen.getByTestId("queued").textContent).toBe("second"),
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
await act(async () => {
|
|
138
|
+
await result.current.thread.append({
|
|
139
|
+
role: "user",
|
|
140
|
+
content: [{ type: "text", text: "third" }],
|
|
141
|
+
parentId: result.current.thread.getState().messages.at(-1)?.id ?? null,
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
await waitFor(() => expect(runAgent).toHaveBeenCalledTimes(3));
|
|
146
|
+
expect(runAgent.mock.calls[1]?.[0]).toEqual(
|
|
147
|
+
expect.objectContaining({
|
|
148
|
+
messages: expect.arrayContaining([
|
|
149
|
+
expect.objectContaining({ role: "user", content: "second" }),
|
|
150
|
+
]),
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
expect(runAgent.mock.calls[2]?.[0]).toEqual(
|
|
154
|
+
expect.objectContaining({
|
|
155
|
+
messages: expect.arrayContaining([
|
|
156
|
+
expect.objectContaining({ role: "user", content: "third" }),
|
|
157
|
+
]),
|
|
158
|
+
}),
|
|
159
|
+
);
|
|
160
|
+
await waitFor(() =>
|
|
161
|
+
expect(screen.getByTestId("queued").textContent).toBe(""),
|
|
162
|
+
);
|
|
163
|
+
});
|
|
164
|
+
|
|
98
165
|
it("keeps accepting sends after a queued run fails", async () => {
|
|
99
166
|
const runAgent = vi.fn(
|
|
100
167
|
async (_input: unknown, subscriber: { onRunFinalized?: () => void }) => {
|
package/src/useAgUiRuntime.ts
CHANGED
|
@@ -251,10 +251,14 @@ export function useAgUiRuntime(
|
|
|
251
251
|
return core.reload(parentId, config);
|
|
252
252
|
},
|
|
253
253
|
onCancel: async () => {
|
|
254
|
-
queueController?.
|
|
254
|
+
queueController?.notifyCancelled();
|
|
255
255
|
core.cancel();
|
|
256
256
|
},
|
|
257
257
|
onAddToolResult: (options) => core.addToolResult(options),
|
|
258
|
+
onRespondToToolApproval: (options) =>
|
|
259
|
+
core.respondToToolApproval(options).catch((error: unknown) => {
|
|
260
|
+
core.reportError(error);
|
|
261
|
+
}),
|
|
258
262
|
onResume: (config) => core.resume(config),
|
|
259
263
|
setMessages: (messages: readonly ThreadMessage[]) =>
|
|
260
264
|
core.applyExternalMessages(messages),
|