@convex-dev/agent 0.1.15-alpha.2 → 0.1.15

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.
@@ -2,6 +2,7 @@ import type { TextPart, ToolCallPart, ToolResultPart } from "ai";
2
2
  import type { MessageDoc } from "../client/index.js";
3
3
  import type {
4
4
  Message,
5
+ MessageStatus,
5
6
  StreamDelta,
6
7
  StreamMessage,
7
8
  TextStreamPart,
@@ -99,6 +100,12 @@ export function applyDeltasToStreamMessage(
99
100
  cursor = delta.end;
100
101
  parts.push(...delta.parts);
101
102
  }
103
+ if (existing && existing.messages.length > 0 && !changed) {
104
+ const lastMessage = existing.messages.at(-1)!;
105
+ if (statusFromStreamStatus(streamMessage.status) !== lastMessage.status) {
106
+ changed = true;
107
+ }
108
+ }
102
109
  if (!changed) {
103
110
  return [
104
111
  existing ?? { streamId: streamMessage.streamId, cursor, messages: [] },
@@ -115,6 +122,7 @@ export function applyDeltasToStreamMessage(
115
122
  currentMessage = {
116
123
  ...lastMessage,
117
124
  message: cloneMessageAndContent(lastMessage.message),
125
+ status: statusFromStreamStatus(streamMessage.status),
118
126
  };
119
127
  } else {
120
128
  const newMessage = createStreamingMessage(
@@ -248,6 +256,21 @@ function getLastContent(message: MessageDoc) {
248
256
  return undefined;
249
257
  }
250
258
 
259
+ function statusFromStreamStatus(
260
+ status: StreamMessage["status"]
261
+ ): MessageStatus {
262
+ switch (status) {
263
+ case "streaming":
264
+ return "pending";
265
+ case "finished":
266
+ return "success";
267
+ case "aborted":
268
+ return "failed";
269
+ default:
270
+ return "pending";
271
+ }
272
+ }
273
+
251
274
  export function createStreamingMessage(
252
275
  threadId: string,
253
276
  message: StreamMessage,
@@ -259,9 +282,7 @@ export function createStreamingMessage(
259
282
  ...rest,
260
283
  _id: `${streamId}-${index}`,
261
284
  _creationTime: Date.now(),
262
- status: (
263
- { streaming: "pending", finished: "success", aborted: "failed" } as const
264
- )[message.status],
285
+ status: statusFromStreamStatus(message.status),
265
286
  threadId,
266
287
  tool: false,
267
288
  };
@@ -114,7 +114,7 @@ export function useThreadMessages<
114
114
  const streamListMessages =
115
115
  streamMessages?.map((m) => ({
116
116
  ...m,
117
- streaming: !m.status || m.status === "streaming",
117
+ streaming: !m.status || m.status === "pending",
118
118
  })) ?? [];
119
119
  return {
120
120
  ...paginated,