@assistant-ui/eve 0.0.21 → 0.0.23
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/convertEveMessages.d.ts +17 -0
- package/dist/convertEveMessages.d.ts.map +1 -1
- package/dist/convertEveMessages.js +68 -21
- package/dist/convertEveMessages.js.map +1 -1
- package/dist/sdkIdentity.js +1 -1
- package/dist/useEveAgentRuntime.d.ts.map +1 -1
- package/dist/useEveAgentRuntime.js +13 -18
- package/dist/useEveAgentRuntime.js.map +1 -1
- package/package.json +6 -5
- package/src/convertEveMessages.test.ts +386 -20
- package/src/convertEveMessages.ts +127 -17
- package/src/deriveCreatedAt.test.ts +1 -0
- package/src/testUtils.ts +57 -0
- package/src/useEveAgentRuntime.eveResume.test.tsx +21 -41
- package/src/useEveAgentRuntime.interruptedTurn.test.tsx +80 -0
- package/src/useEveAgentRuntime.refetch.test.tsx +21 -11
- package/src/useEveAgentRuntime.ts +34 -34
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
useRemoteThreadListRuntime,
|
|
30
30
|
useRuntimeAdapters,
|
|
31
31
|
} from "@assistant-ui/core/react";
|
|
32
|
+
import { invokeUserCallback } from "@assistant-ui/core/internal";
|
|
32
33
|
import { useReplaySafeEffect } from "@assistant-ui/store/internal";
|
|
33
34
|
import { useAui } from "@assistant-ui/store";
|
|
34
35
|
import type { AssistantCloud } from "assistant-cloud";
|
|
@@ -39,10 +40,12 @@ import {
|
|
|
39
40
|
type UseEveAgentStatus,
|
|
40
41
|
} from "eve/react";
|
|
41
42
|
import {
|
|
43
|
+
collectInterruptedTurnEvents,
|
|
42
44
|
convertEveMessages,
|
|
43
45
|
findEveInputRequest,
|
|
44
46
|
getEveMessageContent,
|
|
45
47
|
toEveInputResponse,
|
|
48
|
+
type InterruptedTurnEventCache,
|
|
46
49
|
} from "./convertEveMessages";
|
|
47
50
|
import {
|
|
48
51
|
collectTurnTimestamps,
|
|
@@ -71,35 +74,6 @@ const sendAbandonedError = new Error(
|
|
|
71
74
|
const isDroppedSend = (error: unknown) =>
|
|
72
75
|
error === sendCancelledError || error === sendAbandonedError;
|
|
73
76
|
|
|
74
|
-
type EveLifecycleCallbackName =
|
|
75
|
-
| "onError"
|
|
76
|
-
| "onEvent"
|
|
77
|
-
| "onFinish"
|
|
78
|
-
| "onSessionChange";
|
|
79
|
-
|
|
80
|
-
const reportEveLifecycleCallbackError = (
|
|
81
|
-
name: EveLifecycleCallbackName,
|
|
82
|
-
error: unknown,
|
|
83
|
-
) => {
|
|
84
|
-
console.error(`[assistant-ui/eve] ${name} callback threw an error`, error);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const invokeEveLifecycleCallback = <T>(
|
|
88
|
-
name: EveLifecycleCallbackName,
|
|
89
|
-
callback: ((value: T) => unknown) | undefined,
|
|
90
|
-
value: T,
|
|
91
|
-
) => {
|
|
92
|
-
if (!callback) return;
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
void Promise.resolve(callback(value)).catch((error) => {
|
|
96
|
-
reportEveLifecycleCallbackError(name, error);
|
|
97
|
-
});
|
|
98
|
-
} catch (error) {
|
|
99
|
-
reportEveLifecycleCallbackError(name, error);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
77
|
const hasRunConfig = (
|
|
104
78
|
runConfig: AppendMessage["runConfig"],
|
|
105
79
|
): runConfig is NonNullable<AppendMessage["runConfig"]> =>
|
|
@@ -227,18 +201,33 @@ const useEveThreadRuntime = (
|
|
|
227
201
|
...(onError
|
|
228
202
|
? {
|
|
229
203
|
onError: (error) =>
|
|
230
|
-
|
|
204
|
+
void invokeUserCallback(
|
|
205
|
+
"assistant-ui/eve",
|
|
206
|
+
"onError",
|
|
207
|
+
onError,
|
|
208
|
+
error,
|
|
209
|
+
),
|
|
231
210
|
}
|
|
232
211
|
: {}),
|
|
233
212
|
...(onEvent
|
|
234
213
|
? {
|
|
235
214
|
onEvent: (event) =>
|
|
236
|
-
|
|
215
|
+
void invokeUserCallback(
|
|
216
|
+
"assistant-ui/eve",
|
|
217
|
+
"onEvent",
|
|
218
|
+
onEvent,
|
|
219
|
+
event,
|
|
220
|
+
),
|
|
237
221
|
}
|
|
238
222
|
: {}),
|
|
239
223
|
onFinish: (snapshot) => {
|
|
240
224
|
lastFinishStatusRef.current = snapshot.status;
|
|
241
|
-
|
|
225
|
+
void invokeUserCallback(
|
|
226
|
+
"assistant-ui/eve",
|
|
227
|
+
"onFinish",
|
|
228
|
+
onFinish,
|
|
229
|
+
snapshot,
|
|
230
|
+
);
|
|
242
231
|
},
|
|
243
232
|
...(onSessionChange || cloudThread?.isNew
|
|
244
233
|
? {
|
|
@@ -254,7 +243,8 @@ const useEveThreadRuntime = (
|
|
|
254
243
|
if (aui.threadListItem.getState().status === "new")
|
|
255
244
|
aui.threadListItem.initialize().catch(() => {});
|
|
256
245
|
}
|
|
257
|
-
|
|
246
|
+
void invokeUserCallback(
|
|
247
|
+
"assistant-ui/eve",
|
|
258
248
|
"onSessionChange",
|
|
259
249
|
onSessionChange,
|
|
260
250
|
session,
|
|
@@ -297,6 +287,15 @@ const useEveThreadRuntime = (
|
|
|
297
287
|
() => collectTurnTimestamps(agent.events, turnTimestampCacheRef.current),
|
|
298
288
|
[agent.events],
|
|
299
289
|
);
|
|
290
|
+
const interruptionCacheRef = useRef<InterruptedTurnEventCache>({
|
|
291
|
+
lastEvents: [],
|
|
292
|
+
interruptions: [],
|
|
293
|
+
});
|
|
294
|
+
const interruptionEvents = useMemo(
|
|
295
|
+
() =>
|
|
296
|
+
collectInterruptedTurnEvents(agent.events, interruptionCacheRef.current),
|
|
297
|
+
[agent.events],
|
|
298
|
+
);
|
|
300
299
|
|
|
301
300
|
const convertedMessages = useMemo(() => {
|
|
302
301
|
const createdAtByMessageId = createdAtByMessageIdRef.current;
|
|
@@ -310,6 +309,7 @@ const useEveThreadRuntime = (
|
|
|
310
309
|
return convertEveMessages(agent.data, {
|
|
311
310
|
isRunning,
|
|
312
311
|
error: agent.error,
|
|
312
|
+
events: interruptionEvents,
|
|
313
313
|
getCreatedAt: (message) => {
|
|
314
314
|
const turnId = message.metadata?.turnId;
|
|
315
315
|
const durable =
|
|
@@ -326,7 +326,7 @@ const useEveThreadRuntime = (
|
|
|
326
326
|
return createdAt;
|
|
327
327
|
},
|
|
328
328
|
});
|
|
329
|
-
}, [agent.data, agent.error, isRunning, turnTimestamps]);
|
|
329
|
+
}, [agent.data, agent.error, interruptionEvents, isRunning, turnTimestamps]);
|
|
330
330
|
|
|
331
331
|
const messages = stagedMessages ?? convertedMessages;
|
|
332
332
|
const messagesRef = useRef(messages);
|