@mastra/react 0.0.15-alpha.0 → 0.1.0-beta.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/CHANGELOG.md CHANGED
@@ -1,75 +1,24 @@
1
1
  # @mastra/react-hooks
2
2
 
3
- ## 0.0.15-alpha.0
3
+ ## 0.1.0-beta.0
4
4
 
5
- ### Patch Changes
6
-
7
- - update peerdeps ([`5ca1cca`](https://github.com/mastra-ai/mastra/commit/5ca1ccac61ffa7141e6d9fa8f22d3ad4d03bf5dc))
8
-
9
- - Updated dependencies [[`5ca1cca`](https://github.com/mastra-ai/mastra/commit/5ca1ccac61ffa7141e6d9fa8f22d3ad4d03bf5dc), [`23c2614`](https://github.com/mastra-ai/mastra/commit/23c26140fdbf04b8c59e8d7d52106d67dad962ec), [`139588d`](https://github.com/mastra-ai/mastra/commit/139588df7755c9111a3060f72a789c1a8c95e091), [`186b29b`](https://github.com/mastra-ai/mastra/commit/186b29bd51ac1dcc24ad3825fdb7207a6d6391a6)]:
10
- - @mastra/client-js@0.16.9-alpha.0
11
-
12
- ## 0.0.14
13
-
14
- ### Patch Changes
15
-
16
- - Updated dependencies [[`b55bbce`](https://github.com/mastra-ai/mastra/commit/b55bbce89404d35fdd967012dd503fae343d4c2d), [`e742d37`](https://github.com/mastra-ai/mastra/commit/e742d371f24ef8059670cc05e9aee308eac068b9)]:
17
- - @mastra/client-js@0.16.8
18
-
19
- ## 0.0.14-alpha.0
20
-
21
- ### Patch Changes
22
-
23
- - Updated dependencies [[`b55bbce`](https://github.com/mastra-ai/mastra/commit/b55bbce89404d35fdd967012dd503fae343d4c2d), [`e742d37`](https://github.com/mastra-ai/mastra/commit/e742d371f24ef8059670cc05e9aee308eac068b9)]:
24
- - @mastra/client-js@0.16.8-alpha.0
25
-
26
- ## 0.0.13
27
-
28
- ### Patch Changes
29
-
30
- - Updated dependencies []:
31
- - @mastra/client-js@0.16.7
32
-
33
- ## 0.0.13-alpha.1
5
+ ### Minor Changes
34
6
 
35
- ### Patch Changes
7
+ - Bump minimum required Node.js version to 22.13.0 ([#9706](https://github.com/mastra-ai/mastra/pull/9706))
36
8
 
37
- - Updated dependencies []:
38
- - @mastra/client-js@0.16.7-alpha.1
9
+ - Rename RuntimeContext to RequestContext ([#9511](https://github.com/mastra-ai/mastra/pull/9511))
39
10
 
40
- ## 0.0.13-alpha.0
41
-
42
- ### Patch Changes
43
-
44
- - Updated dependencies []:
45
- - @mastra/client-js@0.16.7-alpha.0
46
-
47
- ## 0.0.12
48
-
49
- ### Patch Changes
50
-
51
- - Fix peerdependencies ([`eb7c1c8`](https://github.com/mastra-ai/mastra/commit/eb7c1c8c592d8fb16dfd250e337d9cdc73c8d5de))
52
-
53
- - Updated dependencies [[`eb7c1c8`](https://github.com/mastra-ai/mastra/commit/eb7c1c8c592d8fb16dfd250e337d9cdc73c8d5de)]:
54
- - @mastra/client-js@0.16.6
55
-
56
- ## 0.0.11
11
+ - Renamed `MastraMessageV2` to `MastraDBMessage` ([#9255](https://github.com/mastra-ai/mastra/pull/9255))
12
+ Made the return format of all methods that return db messages consistent. It's always `{ messages: MastraDBMessage[] }` now, and messages can be converted after that using `@mastra/ai-sdk/ui`'s `toAISdkV4/5Messages()` function
57
13
 
58
14
  ### Patch Changes
59
15
 
60
16
  - Add tool call approval ([#8649](https://github.com/mastra-ai/mastra/pull/8649))
61
17
 
62
- - Updated dependencies [[`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`2060766`](https://github.com/mastra-ai/mastra/commit/20607667bf78ea104cca3e15dfb93ae0b62c9d18)]:
63
- - @mastra/client-js@0.16.5
64
-
65
- ## 0.0.11-alpha.0
66
-
67
- ### Patch Changes
68
-
69
- - Add tool call approval ([#8649](https://github.com/mastra-ai/mastra/pull/8649))
18
+ - Fix multi modal in react sdk ([#9373](https://github.com/mastra-ai/mastra/pull/9373))
70
19
 
71
- - Updated dependencies [[`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`2060766`](https://github.com/mastra-ai/mastra/commit/20607667bf78ea104cca3e15dfb93ae0b62c9d18)]:
72
- - @mastra/client-js@0.16.5-alpha.0
20
+ - Updated dependencies [[`3852192`](https://github.com/mastra-ai/mastra/commit/3852192c81b2a4f1f883f17d80ce50e0c60dba55), [`fec5129`](https://github.com/mastra-ai/mastra/commit/fec5129de7fc64423ea03661a56cef31dc747a0d), [`3443770`](https://github.com/mastra-ai/mastra/commit/3443770662df8eb24c9df3589b2792d78cfcb811), [`f0a07e0`](https://github.com/mastra-ai/mastra/commit/f0a07e0111b3307c5fabfa4094c5c2cfb734fbe6), [`aaa40e7`](https://github.com/mastra-ai/mastra/commit/aaa40e788628b319baa8e889407d11ad626547fa), [`dd1c38d`](https://github.com/mastra-ai/mastra/commit/dd1c38d1b75f1b695c27b40d8d9d6ed00d5e0f6f), [`5948e6a`](https://github.com/mastra-ai/mastra/commit/5948e6a5146c83666ba3f294b2be576c82a513fb), [`dff01d8`](https://github.com/mastra-ai/mastra/commit/dff01d81ce1f4e4087cfac20fa868e6db138dd14), [`b7de533`](https://github.com/mastra-ai/mastra/commit/b7de53361667eb51fefd89fcaed924f3c57cee8d), [`7051bf3`](https://github.com/mastra-ai/mastra/commit/7051bf38b3b122a069008f861f7bfc004a6d9f6e), [`1ee3411`](https://github.com/mastra-ai/mastra/commit/1ee34113192b11aa8bcdd8d9d5830ae13254b345), [`0793497`](https://github.com/mastra-ai/mastra/commit/079349753620c40246ffd673e3f9d7d9820beff3), [`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`f93d992`](https://github.com/mastra-ai/mastra/commit/f93d992a37d5431ab4a71246835d403ef7c4ce85), [`c576fc0`](https://github.com/mastra-ai/mastra/commit/c576fc0b100b2085afded91a37c97a0ea0ec09c7), [`9f4a683`](https://github.com/mastra-ai/mastra/commit/9f4a6833e88b52574665c028fd5508ad5c2f6004), [`ea0b8de`](https://github.com/mastra-ai/mastra/commit/ea0b8dec0d4bc86a72a7e75b2f56c6017c58786d), [`eb09742`](https://github.com/mastra-ai/mastra/commit/eb09742197f66c4c38154c3beec78313e69760b2), [`a1bd7b8`](https://github.com/mastra-ai/mastra/commit/a1bd7b8571db16b94eb01588f451a74758c96d65), [`0633100`](https://github.com/mastra-ai/mastra/commit/0633100a911ad22f5256471bdf753da21c104742), [`354ad0b`](https://github.com/mastra-ai/mastra/commit/354ad0b7b1b8183ac567f236a884fc7ede6d7138), [`519d9e6`](https://github.com/mastra-ai/mastra/commit/519d9e6d31910457c54bdae8b7b7cb3a69f41831), [`844ea5d`](https://github.com/mastra-ai/mastra/commit/844ea5dc0c248961e7bf73629ae7dcff503e853c), [`dfe3f8c`](https://github.com/mastra-ai/mastra/commit/dfe3f8c7376ffe159236819e19ca522143c1f972), [`f0f8f12`](https://github.com/mastra-ai/mastra/commit/f0f8f125c308f2d0fd36942ef652fd852df7522f), [`e8dcd71`](https://github.com/mastra-ai/mastra/commit/e8dcd71fa5e473c8ba1d6dad99eef182d20a0491), [`63f2f18`](https://github.com/mastra-ai/mastra/commit/63f2f1863dffe3ad23221d0660ed4e4f2b81789d), [`c23200d`](https://github.com/mastra-ai/mastra/commit/c23200ddfd60830effb39329674ba4ca93be6aac), [`363284b`](https://github.com/mastra-ai/mastra/commit/363284bb974e850f06f40f89a28c79d9f432d7e4), [`83d5942`](https://github.com/mastra-ai/mastra/commit/83d5942669ce7bba4a6ca4fd4da697a10eb5ebdc), [`b7959e6`](https://github.com/mastra-ai/mastra/commit/b7959e6e25a46b480f9ea2217c4c6c588c423791), [`0bddc6d`](https://github.com/mastra-ai/mastra/commit/0bddc6d8dbd6f6008c0cba2e4960a2da75a55af1), [`a0c8c1b`](https://github.com/mastra-ai/mastra/commit/a0c8c1b87d4fee252aebda73e8637fbe01d761c9), [`c218bd3`](https://github.com/mastra-ai/mastra/commit/c218bd3759e32423735b04843a09404572631014)]:
21
+ - @mastra/client-js@1.0.0-beta.0
73
22
 
74
23
  ## 0.0.10
75
24
 
package/dist/index.cjs CHANGED
@@ -428,11 +428,10 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
428
428
  const lastMessage = result[result.length - 1];
429
429
  if (!lastMessage || lastMessage.role !== "assistant") return result;
430
430
  const parts = lastMessage.parts.map((part) => {
431
- if (part.type === "text" && part.state === "streaming") {
432
- return { ...part, state: "done" };
433
- }
434
- if (part.type === "reasoning" && part.state === "streaming") {
435
- return { ...part, state: "done" };
431
+ if (typeof part === "object" && part !== null && "type" in part && "state" in part && part.state === "streaming") {
432
+ if (part.type === "text" || part.type === "reasoning") {
433
+ return { ...part, state: "done" };
434
+ }
436
435
  }
437
436
  return part;
438
437
  });
@@ -604,13 +603,23 @@ const toAssistantUIMessage = (message) => {
604
603
  };
605
604
  }
606
605
  if (part.type === "file") {
607
- return {
608
- type: "file",
609
- mimeType: part.mediaType,
610
- data: part.url,
611
- // Use URL as data source
612
- metadata: message.metadata
613
- };
606
+ const type = part.mediaType.includes("image/") ? "image" : "file";
607
+ if (type === "file") {
608
+ return {
609
+ type,
610
+ mimeType: part.mediaType,
611
+ data: part.url,
612
+ // Use URL as data source
613
+ metadata: message.metadata
614
+ };
615
+ }
616
+ if (type === "image") {
617
+ return {
618
+ type,
619
+ image: part.url,
620
+ metadata: message.metadata
621
+ };
622
+ }
614
623
  }
615
624
  if (part.type === "dynamic-tool") {
616
625
  const baseToolCall = {
@@ -687,7 +696,9 @@ const toAssistantUIMessage = (message) => {
687
696
 
688
697
  const resolveInitialMessages = (messages) => {
689
698
  return messages.map((message) => {
690
- const networkPart = message.parts.find((part) => part.type === "text" && part.text.includes('"isNetwork":true'));
699
+ const networkPart = message.parts.find(
700
+ (part) => typeof part === "object" && part !== null && "type" in part && part.type === "text" && "text" in part && typeof part.text === "string" && part.text.includes('"isNetwork":true')
701
+ );
691
702
  if (networkPart && networkPart.type === "text") {
692
703
  try {
693
704
  const json = JSON.parse(networkPart.text);
@@ -1161,6 +1172,51 @@ class AISdkNetworkTransformer {
1161
1172
  };
1162
1173
  }
1163
1174
 
1175
+ const fromCoreUserMessageToUIMessage = (coreUserMessage) => {
1176
+ const id = `user-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
1177
+ const parts = typeof coreUserMessage.content === "string" ? [
1178
+ {
1179
+ type: "text",
1180
+ text: coreUserMessage.content
1181
+ }
1182
+ ] : coreUserMessage.content.map((part) => {
1183
+ switch (part.type) {
1184
+ case "text": {
1185
+ return {
1186
+ type: "text",
1187
+ text: part.text
1188
+ };
1189
+ }
1190
+ case "image": {
1191
+ const url = typeof part.image === "string" ? part.image : part.image instanceof URL ? part.image.toString() : "";
1192
+ return {
1193
+ type: "file",
1194
+ mediaType: part.mimeType ?? "image/*",
1195
+ url
1196
+ };
1197
+ }
1198
+ case "file": {
1199
+ const url = typeof part.data === "string" ? part.data : part.data instanceof URL ? part.data.toString() : "";
1200
+ return {
1201
+ type: "file",
1202
+ mediaType: part.mimeType,
1203
+ url,
1204
+ ...part.filename !== void 0 ? { filename: part.filename } : {}
1205
+ };
1206
+ }
1207
+ default: {
1208
+ const exhaustiveCheck = part;
1209
+ throw new Error(`Unhandled content part type: ${exhaustiveCheck.type}`);
1210
+ }
1211
+ }
1212
+ });
1213
+ return {
1214
+ id,
1215
+ role: "user",
1216
+ parts
1217
+ };
1218
+ };
1219
+
1164
1220
  const useChat = ({ agentId, initializeMessages }) => {
1165
1221
  const _currentRunId = react.useRef(void 0);
1166
1222
  const _onChunk = react.useRef(void 0);
@@ -1172,7 +1228,7 @@ const useChat = ({ agentId, initializeMessages }) => {
1172
1228
  const [isRunning, setIsRunning] = react.useState(false);
1173
1229
  const generate = async ({
1174
1230
  coreUserMessages,
1175
- runtimeContext,
1231
+ requestContext,
1176
1232
  threadId,
1177
1233
  modelSettings,
1178
1234
  signal,
@@ -1210,7 +1266,7 @@ const useChat = ({ agentId, initializeMessages }) => {
1210
1266
  topP
1211
1267
  },
1212
1268
  instructions,
1213
- runtimeContext,
1269
+ requestContext,
1214
1270
  ...threadId ? { threadId, resourceId: agentId } : {},
1215
1271
  providerOptions
1216
1272
  });
@@ -1226,7 +1282,7 @@ const useChat = ({ agentId, initializeMessages }) => {
1226
1282
  setMessages((prev) => [...prev, ...mastraUIMessages]);
1227
1283
  }
1228
1284
  };
1229
- const stream = async ({ coreUserMessages, runtimeContext, threadId, onChunk, modelSettings, signal }) => {
1285
+ const stream = async ({ coreUserMessages, requestContext, threadId, onChunk, modelSettings, signal }) => {
1230
1286
  const {
1231
1287
  frequencyPenalty,
1232
1288
  presencePenalty,
@@ -1261,7 +1317,7 @@ const useChat = ({ agentId, initializeMessages }) => {
1261
1317
  topP
1262
1318
  },
1263
1319
  instructions,
1264
- runtimeContext,
1320
+ requestContext,
1265
1321
  ...threadId ? { threadId, resourceId: agentId } : {},
1266
1322
  providerOptions,
1267
1323
  requireToolApproval
@@ -1278,7 +1334,7 @@ const useChat = ({ agentId, initializeMessages }) => {
1278
1334
  };
1279
1335
  const network = async ({
1280
1336
  coreUserMessages,
1281
- runtimeContext,
1337
+ requestContext,
1282
1338
  threadId,
1283
1339
  onNetworkChunk,
1284
1340
  modelSettings,
@@ -1304,7 +1360,7 @@ const useChat = ({ agentId, initializeMessages }) => {
1304
1360
  topP
1305
1361
  },
1306
1362
  runId: agentId,
1307
- runtimeContext,
1363
+ requestContext,
1308
1364
  ...threadId ? { thread: threadId, resourceId: agentId } : {}
1309
1365
  });
1310
1366
  const transformer = new AISdkNetworkTransformer();
@@ -1357,14 +1413,18 @@ const useChat = ({ agentId, initializeMessages }) => {
1357
1413
  };
1358
1414
  const sendMessage = async ({ mode = "stream", ...args }) => {
1359
1415
  const nextMessage = { role: "user", content: [{ type: "text", text: args.message }] };
1360
- const messages2 = args.coreUserMessages ? [nextMessage, ...args.coreUserMessages] : [nextMessage];
1361
- setMessages((s) => [...s, { role: "user", parts: [{ type: "text", text: args.message }] }]);
1416
+ const coreUserMessages = [nextMessage];
1417
+ if (args.coreUserMessages) {
1418
+ coreUserMessages.push(...args.coreUserMessages);
1419
+ }
1420
+ const uiMessages = coreUserMessages.map(fromCoreUserMessageToUIMessage);
1421
+ setMessages((s) => [...s, ...uiMessages]);
1362
1422
  if (mode === "generate") {
1363
- await generate({ ...args, coreUserMessages: messages2 });
1423
+ await generate({ ...args, coreUserMessages });
1364
1424
  } else if (mode === "stream") {
1365
- await stream({ ...args, coreUserMessages: messages2 });
1425
+ await stream({ ...args, coreUserMessages });
1366
1426
  } else if (mode === "network") {
1367
- await network({ ...args, coreUserMessages: messages2 });
1427
+ await network({ ...args, coreUserMessages });
1368
1428
  }
1369
1429
  };
1370
1430
  return {