@convex-dev/agent 0.0.8 → 0.0.9-alpha.1

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/src/mapping.ts CHANGED
@@ -53,21 +53,11 @@ export function serializeMessageWithId(
53
53
  return { message: serializeMessage(messageWithId), id: messageWithId.id };
54
54
  }
55
55
 
56
- export function serializeContent(content: Content): SerializedContent {
57
- if (typeof content === "string") {
58
- return content;
59
- }
60
- const serialized = content.map((part) => {
61
- switch (part.type) {
62
- case "image":
63
- return { ...part, image: serializeDataOrUrl(part.image) };
64
- case "file":
65
- return { ...part, file: serializeDataOrUrl(part.data) };
66
- default:
67
- return part;
68
- }
69
- });
70
- return serialized as SerializedContent;
56
+ export function deserializeMessage(message: SerializedMessage): CoreMessage {
57
+ return {
58
+ ...message,
59
+ content: deserializeContent(message.content),
60
+ } as CoreMessage;
71
61
  }
72
62
 
73
63
  export function serializeStep<TOOLS extends ToolSet>(
@@ -137,6 +127,23 @@ export function serializeObjectResult(
137
127
  };
138
128
  }
139
129
 
130
+ export function serializeContent(content: Content): SerializedContent {
131
+ if (typeof content === "string") {
132
+ return content;
133
+ }
134
+ const serialized = content.map((part) => {
135
+ switch (part.type) {
136
+ case "image":
137
+ return { ...part, image: serializeDataOrUrl(part.image) };
138
+ case "file":
139
+ return { ...part, file: serializeDataOrUrl(part.data) };
140
+ default:
141
+ return part;
142
+ }
143
+ });
144
+ return serialized as SerializedContent;
145
+ }
146
+
140
147
  export function deserializeContent(content: SerializedContent): Content {
141
148
  if (typeof content === "string") {
142
149
  return content;
@@ -144,7 +151,7 @@ export function deserializeContent(content: SerializedContent): Content {
144
151
  return content.map((part) => {
145
152
  switch (part.type) {
146
153
  case "image":
147
- return { ...part, file: deserializeUrl(part.image) };
154
+ return { ...part, image: deserializeUrl(part.image) };
148
155
  case "file":
149
156
  return { ...part, file: deserializeUrl(part.data) };
150
157
  default:
@@ -4,6 +4,17 @@ if (typeof window === "undefined") {
4
4
  throw new Error("this is frontend code, but it's running somewhere else!");
5
5
  }
6
6
 
7
+ /**
8
+ * Use this hook to stream text from a server action, using the
9
+ * toTextStreamResponse or equivalent HTTP streaming endpoint returning text.
10
+ * @param url The URL of the server action to stream text from.
11
+ * e.g. https://....convex.site/yourendpoint
12
+ * @param threadId The ID of the thread to stream text from.
13
+ * @param token The auth token to use for the request.
14
+ * e.g. useAuthToken() from @convex-dev/auth/react
15
+ * @returns A tuple containing the {text, loading, error} and a function to call the endpoint
16
+ * with a given prompt, passing up { prompt, threadId } as the body in JSON.
17
+ */
7
18
  export function useStreamingText(
8
19
  url: string,
9
20
  threadId: string | null,