@mastra/react 0.0.0-remove-unused-model-providers-api-20251030210744 → 0.0.0-remove-ai-peer-dep-from-evals-20260105220639
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 +455 -4
- package/dist/index.cjs +213 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +213 -61
- package/dist/index.js.map +1 -1
- package/dist/react.css +1 -1
- package/dist/src/agent/hooks.d.ts +4 -1
- package/dist/src/lib/ai-sdk/types.d.ts +33 -2
- package/dist/src/lib/ai-sdk/utils/fromCoreUserMessageToUIMessage.d.ts +1 -1
- package/package.json +15 -11
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5
5
|
const jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
const react = require('react');
|
|
7
7
|
const clientJs = require('@mastra/client-js');
|
|
8
|
+
const uuid = require('@lukeed/uuid');
|
|
8
9
|
const lucideReact = require('lucide-react');
|
|
9
10
|
const tailwindMerge = require('tailwind-merge');
|
|
10
11
|
const hastUtilToJsxRuntime = require('hast-util-to-jsx-runtime');
|
|
@@ -50,7 +51,7 @@ const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
|
|
|
50
51
|
return {
|
|
51
52
|
...prev,
|
|
52
53
|
status: chunk.payload.workflowStatus,
|
|
53
|
-
...finalStatus === "success" && lastStep?.status === "success" ? { result: lastStep?.output } : finalStatus === "failed" && lastStep?.status === "failed" ? { error: lastStep?.error } : {}
|
|
54
|
+
...finalStatus === "success" && lastStep?.status === "success" ? { result: lastStep?.output } : finalStatus === "failed" && lastStep?.status === "failed" ? { error: lastStep?.error } : finalStatus === "tripwire" && chunk.payload.tripwire ? { tripwire: chunk.payload.tripwire } : {}
|
|
54
55
|
};
|
|
55
56
|
}
|
|
56
57
|
const { stepCallId, stepName, ...newPayload } = chunk.payload ?? {};
|
|
@@ -102,6 +103,34 @@ const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
|
|
|
102
103
|
};
|
|
103
104
|
const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
104
105
|
const result = [...conversation];
|
|
106
|
+
if (chunk.type.startsWith("data-")) {
|
|
107
|
+
const lastMessage = result[result.length - 1];
|
|
108
|
+
if (!lastMessage || lastMessage.role !== "assistant") {
|
|
109
|
+
const newMessage = {
|
|
110
|
+
id: `data-${chunk.runId}-${Date.now()}`,
|
|
111
|
+
role: "assistant",
|
|
112
|
+
parts: [
|
|
113
|
+
{
|
|
114
|
+
type: chunk.type,
|
|
115
|
+
data: "data" in chunk ? chunk.data : void 0
|
|
116
|
+
}
|
|
117
|
+
],
|
|
118
|
+
metadata
|
|
119
|
+
};
|
|
120
|
+
return [...result, newMessage];
|
|
121
|
+
}
|
|
122
|
+
const updatedMessage = {
|
|
123
|
+
...lastMessage,
|
|
124
|
+
parts: [
|
|
125
|
+
...lastMessage.parts,
|
|
126
|
+
{
|
|
127
|
+
type: chunk.type,
|
|
128
|
+
data: "data" in chunk ? chunk.data : void 0
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
};
|
|
132
|
+
return [...result.slice(0, -1), updatedMessage];
|
|
133
|
+
}
|
|
105
134
|
switch (chunk.type) {
|
|
106
135
|
case "tripwire": {
|
|
107
136
|
const newMessage = {
|
|
@@ -110,19 +139,24 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
110
139
|
parts: [
|
|
111
140
|
{
|
|
112
141
|
type: "text",
|
|
113
|
-
text: chunk.payload.
|
|
142
|
+
text: chunk.payload.reason
|
|
114
143
|
}
|
|
115
144
|
],
|
|
116
145
|
metadata: {
|
|
117
146
|
...metadata,
|
|
118
|
-
status: "
|
|
147
|
+
status: "tripwire",
|
|
148
|
+
tripwire: {
|
|
149
|
+
retry: chunk.payload.retry,
|
|
150
|
+
tripwirePayload: chunk.payload.metadata,
|
|
151
|
+
processorId: chunk.payload.processorId
|
|
152
|
+
}
|
|
119
153
|
}
|
|
120
154
|
};
|
|
121
155
|
return [...result, newMessage];
|
|
122
156
|
}
|
|
123
157
|
case "start": {
|
|
124
158
|
const newMessage = {
|
|
125
|
-
id: `start-${chunk.runId + Date.now()}`,
|
|
159
|
+
id: typeof chunk.payload.messageId === "string" ? chunk.payload.messageId : `start-${chunk.runId + Date.now()}`,
|
|
126
160
|
role: "assistant",
|
|
127
161
|
parts: [],
|
|
128
162
|
metadata
|
|
@@ -259,17 +293,19 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
259
293
|
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
260
294
|
const parts = [...lastMessage.parts];
|
|
261
295
|
const toolPartIndex = parts.findIndex(
|
|
262
|
-
(part) => part.type === "dynamic-tool" && "toolCallId" in part && part.toolCallId === chunk.payload.toolCallId
|
|
296
|
+
(part) => (part.type === "dynamic-tool" || typeof part.type === "string" && part.type.startsWith("tool-")) && "toolCallId" in part && part.toolCallId === chunk.payload.toolCallId
|
|
263
297
|
);
|
|
264
298
|
if (toolPartIndex !== -1) {
|
|
265
299
|
const toolPart = parts[toolPartIndex];
|
|
266
|
-
if (toolPart.type === "dynamic-tool") {
|
|
300
|
+
if (toolPart.type === "dynamic-tool" || typeof toolPart.type === "string" && toolPart.type.startsWith("tool-")) {
|
|
301
|
+
const toolName = "toolName" in toolPart && typeof toolPart.toolName === "string" ? toolPart.toolName : toolPart.type.startsWith("tool-") ? toolPart.type.substring(5) : "";
|
|
302
|
+
const toolCallId = toolPart.toolCallId;
|
|
267
303
|
if (chunk.type === "tool-result" && chunk.payload.isError || chunk.type === "tool-error") {
|
|
268
304
|
const error = chunk.type === "tool-error" ? chunk.payload.error : chunk.payload.result;
|
|
269
305
|
parts[toolPartIndex] = {
|
|
270
306
|
type: "dynamic-tool",
|
|
271
|
-
toolName
|
|
272
|
-
toolCallId
|
|
307
|
+
toolName,
|
|
308
|
+
toolCallId,
|
|
273
309
|
state: "output-error",
|
|
274
310
|
input: toolPart.input,
|
|
275
311
|
errorText: String(error),
|
|
@@ -288,8 +324,8 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
288
324
|
}
|
|
289
325
|
parts[toolPartIndex] = {
|
|
290
326
|
type: "dynamic-tool",
|
|
291
|
-
toolName
|
|
292
|
-
toolCallId
|
|
327
|
+
toolName,
|
|
328
|
+
toolCallId,
|
|
293
329
|
state: "output-available",
|
|
294
330
|
input: toolPart.input,
|
|
295
331
|
output,
|
|
@@ -311,11 +347,14 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
311
347
|
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
312
348
|
const parts = [...lastMessage.parts];
|
|
313
349
|
const toolPartIndex = parts.findIndex(
|
|
314
|
-
(part) => part.type === "dynamic-tool" && "toolCallId" in part && part.toolCallId === chunk.payload.toolCallId
|
|
350
|
+
(part) => (part.type === "dynamic-tool" || typeof part.type === "string" && part.type.startsWith("tool-")) && "toolCallId" in part && part.toolCallId === chunk.payload.toolCallId
|
|
315
351
|
);
|
|
316
352
|
if (toolPartIndex !== -1) {
|
|
317
353
|
const toolPart = parts[toolPartIndex];
|
|
318
|
-
if (toolPart.type === "dynamic-tool") {
|
|
354
|
+
if (toolPart.type === "dynamic-tool" || typeof toolPart.type === "string" && toolPart.type.startsWith("tool-")) {
|
|
355
|
+
const toolName = "toolName" in toolPart && typeof toolPart.toolName === "string" ? toolPart.toolName : typeof toolPart.type === "string" && toolPart.type.startsWith("tool-") ? toolPart.type.substring(5) : "";
|
|
356
|
+
const toolCallId = toolPart.toolCallId;
|
|
357
|
+
const input = toolPart.input;
|
|
319
358
|
if (chunk.payload.output?.type?.startsWith("workflow-")) {
|
|
320
359
|
const existingWorkflowState = toolPart.output || {};
|
|
321
360
|
const updatedWorkflowState = mapWorkflowStreamChunkToWatchResult(
|
|
@@ -323,7 +362,11 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
323
362
|
chunk.payload.output
|
|
324
363
|
);
|
|
325
364
|
parts[toolPartIndex] = {
|
|
326
|
-
|
|
365
|
+
type: "dynamic-tool",
|
|
366
|
+
toolName,
|
|
367
|
+
toolCallId,
|
|
368
|
+
state: "input-streaming",
|
|
369
|
+
input,
|
|
327
370
|
output: updatedWorkflowState
|
|
328
371
|
};
|
|
329
372
|
} else if (chunk.payload.output?.from === "AGENT" || chunk.payload.output?.from === "USER" && chunk.payload.output?.payload?.output?.type?.startsWith("workflow-")) {
|
|
@@ -332,7 +375,11 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
332
375
|
const currentOutput = toolPart.output || [];
|
|
333
376
|
const existingOutput = Array.isArray(currentOutput) ? currentOutput : [];
|
|
334
377
|
parts[toolPartIndex] = {
|
|
335
|
-
|
|
378
|
+
type: "dynamic-tool",
|
|
379
|
+
toolName,
|
|
380
|
+
toolCallId,
|
|
381
|
+
state: "input-streaming",
|
|
382
|
+
input,
|
|
336
383
|
output: [...existingOutput, chunk.payload.output]
|
|
337
384
|
};
|
|
338
385
|
}
|
|
@@ -414,7 +461,7 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
414
461
|
mode: "stream",
|
|
415
462
|
requireApprovalMetadata: {
|
|
416
463
|
...lastRequireApprovalMetadata,
|
|
417
|
-
[chunk.payload.
|
|
464
|
+
[chunk.payload.toolName]: {
|
|
418
465
|
toolCallId: chunk.payload.toolCallId,
|
|
419
466
|
toolName: chunk.payload.toolName,
|
|
420
467
|
args: chunk.payload.args
|
|
@@ -424,15 +471,38 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
424
471
|
}
|
|
425
472
|
];
|
|
426
473
|
}
|
|
474
|
+
case "tool-call-suspended": {
|
|
475
|
+
const lastMessage = result[result.length - 1];
|
|
476
|
+
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
477
|
+
const lastSuspendedTools = lastMessage.metadata?.mode === "stream" ? lastMessage.metadata?.suspendedTools : {};
|
|
478
|
+
return [
|
|
479
|
+
...result.slice(0, -1),
|
|
480
|
+
{
|
|
481
|
+
...lastMessage,
|
|
482
|
+
metadata: {
|
|
483
|
+
...lastMessage.metadata,
|
|
484
|
+
mode: "stream",
|
|
485
|
+
suspendedTools: {
|
|
486
|
+
...lastSuspendedTools,
|
|
487
|
+
[chunk.payload.toolName]: {
|
|
488
|
+
toolCallId: chunk.payload.toolCallId,
|
|
489
|
+
toolName: chunk.payload.toolName,
|
|
490
|
+
args: chunk.payload.args,
|
|
491
|
+
suspendPayload: chunk.payload.suspendPayload
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
];
|
|
497
|
+
}
|
|
427
498
|
case "finish": {
|
|
428
499
|
const lastMessage = result[result.length - 1];
|
|
429
500
|
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
430
501
|
const parts = lastMessage.parts.map((part) => {
|
|
431
|
-
if (part
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
return { ...part, state: "done" };
|
|
502
|
+
if (typeof part === "object" && part !== null && "type" in part && "state" in part && part.state === "streaming") {
|
|
503
|
+
if (part.type === "text" || part.type === "reasoning") {
|
|
504
|
+
return { ...part, state: "done" };
|
|
505
|
+
}
|
|
436
506
|
}
|
|
437
507
|
return part;
|
|
438
508
|
});
|
|
@@ -640,13 +710,14 @@ const toAssistantUIMessage = (message) => {
|
|
|
640
710
|
return baseToolCall;
|
|
641
711
|
}
|
|
642
712
|
if (part.type.startsWith("tool-") && part.state !== "input-available") {
|
|
643
|
-
const
|
|
713
|
+
const toolName2 = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.substring(5);
|
|
714
|
+
const { suspendedToolRunId, ...cleanInput } = "input" in part ? part.input : {};
|
|
644
715
|
const baseToolCall = {
|
|
645
716
|
type: "tool-call",
|
|
646
717
|
toolCallId: "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : "",
|
|
647
|
-
toolName,
|
|
648
|
-
argsText:
|
|
649
|
-
args:
|
|
718
|
+
toolName: toolName2,
|
|
719
|
+
argsText: JSON.stringify(cleanInput ?? {}),
|
|
720
|
+
args: cleanInput ?? {},
|
|
650
721
|
metadata: message.metadata
|
|
651
722
|
};
|
|
652
723
|
if ("output" in part) {
|
|
@@ -656,6 +727,31 @@ const toAssistantUIMessage = (message) => {
|
|
|
656
727
|
}
|
|
657
728
|
return baseToolCall;
|
|
658
729
|
}
|
|
730
|
+
const toolName = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.startsWith("tool-") ? part.type.substring(5) : "";
|
|
731
|
+
const requireApprovalMetadata = extendedMessage.metadata?.requireApprovalMetadata;
|
|
732
|
+
const suspendedTools = extendedMessage.metadata?.suspendedTools;
|
|
733
|
+
const partToolCallId = "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : void 0;
|
|
734
|
+
const suspensionData = toolName ? requireApprovalMetadata?.[toolName] ?? suspendedTools?.[toolName] : void 0;
|
|
735
|
+
if (suspensionData) {
|
|
736
|
+
const { suspendedToolRunId, ...cleanInput } = "input" in part ? part.input : {};
|
|
737
|
+
return {
|
|
738
|
+
type: "tool-call",
|
|
739
|
+
toolCallId: partToolCallId,
|
|
740
|
+
toolName,
|
|
741
|
+
argsText: JSON.stringify(cleanInput ?? {}),
|
|
742
|
+
args: cleanInput,
|
|
743
|
+
metadata: extendedMessage.metadata
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
if (part.type.startsWith("data-")) {
|
|
747
|
+
return {
|
|
748
|
+
type: "data",
|
|
749
|
+
name: part.type.substring(5),
|
|
750
|
+
// Extract name from 'data-{name}'
|
|
751
|
+
data: part.data,
|
|
752
|
+
metadata: message.metadata
|
|
753
|
+
};
|
|
754
|
+
}
|
|
659
755
|
return {
|
|
660
756
|
type: "text",
|
|
661
757
|
text: "",
|
|
@@ -697,7 +793,9 @@ const toAssistantUIMessage = (message) => {
|
|
|
697
793
|
|
|
698
794
|
const resolveInitialMessages = (messages) => {
|
|
699
795
|
return messages.map((message) => {
|
|
700
|
-
const networkPart = message.parts.find(
|
|
796
|
+
const networkPart = message.parts.find(
|
|
797
|
+
(part) => typeof part === "object" && part !== null && "type" in part && part.type === "text" && "text" in part && typeof part.text === "string" && part.text.includes('"isNetwork":true')
|
|
798
|
+
);
|
|
701
799
|
if (networkPart && networkPart.type === "text") {
|
|
702
800
|
try {
|
|
703
801
|
const json = JSON.parse(networkPart.text);
|
|
@@ -706,28 +804,34 @@ const resolveInitialMessages = (messages) => {
|
|
|
706
804
|
const primitiveType = json.primitiveType || "";
|
|
707
805
|
const primitiveId = json.primitiveId || "";
|
|
708
806
|
const finalResult = json.finalResult;
|
|
709
|
-
const
|
|
807
|
+
const messages2 = finalResult?.messages || [];
|
|
710
808
|
const childMessages = [];
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
809
|
+
const toolResultMap = /* @__PURE__ */ new Map();
|
|
810
|
+
for (const msg of messages2) {
|
|
811
|
+
if (Array.isArray(msg.content)) {
|
|
812
|
+
for (const part of msg.content) {
|
|
813
|
+
if (typeof part === "object" && part.type === "tool-result") {
|
|
814
|
+
toolResultMap.set(part.toolCallId, part);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
for (const msg of messages2) {
|
|
820
|
+
if (msg.type === "tool-call" && Array.isArray(msg.content)) {
|
|
821
|
+
for (const part of msg.content) {
|
|
822
|
+
if (typeof part === "object" && part.type === "tool-call") {
|
|
823
|
+
const toolCallContent = part;
|
|
824
|
+
const toolResult = toolResultMap.get(toolCallContent.toolCallId);
|
|
825
|
+
const isWorkflow = Boolean(toolResult?.result?.result?.steps);
|
|
826
|
+
childMessages.push({
|
|
827
|
+
type: "tool",
|
|
828
|
+
toolCallId: toolCallContent.toolCallId,
|
|
829
|
+
toolName: toolCallContent.toolName,
|
|
830
|
+
args: toolCallContent.args,
|
|
831
|
+
toolOutput: isWorkflow ? toolResult?.result?.result : toolResult?.result
|
|
832
|
+
});
|
|
721
833
|
}
|
|
722
834
|
}
|
|
723
|
-
const isWorkflow = Boolean(toolResult?.result?.result?.steps);
|
|
724
|
-
childMessages.push({
|
|
725
|
-
type: "tool",
|
|
726
|
-
toolCallId: toolCall.payload.toolCallId,
|
|
727
|
-
toolName: toolCall.payload.toolName,
|
|
728
|
-
args: toolCall.payload.args,
|
|
729
|
-
toolOutput: isWorkflow ? toolResult?.result?.result : toolResult?.result
|
|
730
|
-
});
|
|
731
835
|
}
|
|
732
836
|
}
|
|
733
837
|
if (finalResult && finalResult.text) {
|
|
@@ -740,7 +844,6 @@ const resolveInitialMessages = (messages) => {
|
|
|
740
844
|
childMessages,
|
|
741
845
|
result: finalResult?.text || ""
|
|
742
846
|
};
|
|
743
|
-
console.log("json", json);
|
|
744
847
|
const nextMessage = {
|
|
745
848
|
role: "assistant",
|
|
746
849
|
parts: [
|
|
@@ -768,6 +871,29 @@ const resolveInitialMessages = (messages) => {
|
|
|
768
871
|
return message;
|
|
769
872
|
}
|
|
770
873
|
}
|
|
874
|
+
const extendedMessage = message;
|
|
875
|
+
const pendingToolApprovals = extendedMessage.metadata?.pendingToolApprovals;
|
|
876
|
+
if (pendingToolApprovals && typeof pendingToolApprovals === "object") {
|
|
877
|
+
return {
|
|
878
|
+
...message,
|
|
879
|
+
metadata: {
|
|
880
|
+
...message.metadata,
|
|
881
|
+
mode: "stream",
|
|
882
|
+
requireApprovalMetadata: pendingToolApprovals
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
const suspendedTools = extendedMessage.metadata?.suspendedTools;
|
|
887
|
+
if (suspendedTools && typeof suspendedTools === "object") {
|
|
888
|
+
return {
|
|
889
|
+
...message,
|
|
890
|
+
metadata: {
|
|
891
|
+
...message.metadata,
|
|
892
|
+
mode: "stream",
|
|
893
|
+
suspendedTools
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
}
|
|
771
897
|
return message;
|
|
772
898
|
});
|
|
773
899
|
};
|
|
@@ -1216,12 +1342,24 @@ const fromCoreUserMessageToUIMessage = (coreUserMessage) => {
|
|
|
1216
1342
|
};
|
|
1217
1343
|
};
|
|
1218
1344
|
|
|
1219
|
-
const useChat = ({ agentId, initializeMessages }) => {
|
|
1220
|
-
const
|
|
1345
|
+
const useChat = ({ agentId, resourceId, initializeMessages }) => {
|
|
1346
|
+
const extractRunIdFromMessages = (messages2) => {
|
|
1347
|
+
for (const message of messages2) {
|
|
1348
|
+
const pendingToolApprovals = message.metadata?.pendingToolApprovals;
|
|
1349
|
+
if (pendingToolApprovals && typeof pendingToolApprovals === "object") {
|
|
1350
|
+
const suspensionData = Object.values(pendingToolApprovals)[0];
|
|
1351
|
+
if (suspensionData?.runId) {
|
|
1352
|
+
return suspensionData.runId;
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
return void 0;
|
|
1357
|
+
};
|
|
1358
|
+
const initialMessages = initializeMessages?.() || [];
|
|
1359
|
+
const initialRunId = extractRunIdFromMessages(initialMessages);
|
|
1360
|
+
const _currentRunId = react.useRef(initialRunId);
|
|
1221
1361
|
const _onChunk = react.useRef(void 0);
|
|
1222
|
-
const [messages, setMessages] = react.useState(
|
|
1223
|
-
() => resolveInitialMessages(initializeMessages?.() || [])
|
|
1224
|
-
);
|
|
1362
|
+
const [messages, setMessages] = react.useState(() => resolveInitialMessages(initialMessages));
|
|
1225
1363
|
const [toolCallApprovals, setToolCallApprovals] = react.useState({});
|
|
1226
1364
|
const baseClient = useMastraClient();
|
|
1227
1365
|
const [isRunning, setIsRunning] = react.useState(false);
|
|
@@ -1231,7 +1369,8 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1231
1369
|
threadId,
|
|
1232
1370
|
modelSettings,
|
|
1233
1371
|
signal,
|
|
1234
|
-
onFinish
|
|
1372
|
+
onFinish,
|
|
1373
|
+
tracingOptions
|
|
1235
1374
|
}) => {
|
|
1236
1375
|
const {
|
|
1237
1376
|
frequencyPenalty,
|
|
@@ -1253,7 +1392,7 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1253
1392
|
const agent = clientWithAbort.getAgent(agentId);
|
|
1254
1393
|
const response = await agent.generate({
|
|
1255
1394
|
messages: coreUserMessages,
|
|
1256
|
-
runId:
|
|
1395
|
+
runId: uuid.v4(),
|
|
1257
1396
|
maxSteps,
|
|
1258
1397
|
modelSettings: {
|
|
1259
1398
|
frequencyPenalty,
|
|
@@ -1266,8 +1405,9 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1266
1405
|
},
|
|
1267
1406
|
instructions,
|
|
1268
1407
|
requestContext,
|
|
1269
|
-
...threadId ? { threadId, resourceId: agentId } : {},
|
|
1270
|
-
providerOptions
|
|
1408
|
+
...threadId ? { threadId, resourceId: resourceId || agentId } : {},
|
|
1409
|
+
providerOptions,
|
|
1410
|
+
tracingOptions
|
|
1271
1411
|
});
|
|
1272
1412
|
setIsRunning(false);
|
|
1273
1413
|
if (response && "uiMessages" in response.response && response.response.uiMessages) {
|
|
@@ -1281,7 +1421,15 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1281
1421
|
setMessages((prev) => [...prev, ...mastraUIMessages]);
|
|
1282
1422
|
}
|
|
1283
1423
|
};
|
|
1284
|
-
const stream = async ({
|
|
1424
|
+
const stream = async ({
|
|
1425
|
+
coreUserMessages,
|
|
1426
|
+
requestContext,
|
|
1427
|
+
threadId,
|
|
1428
|
+
onChunk,
|
|
1429
|
+
modelSettings,
|
|
1430
|
+
signal,
|
|
1431
|
+
tracingOptions
|
|
1432
|
+
}) => {
|
|
1285
1433
|
const {
|
|
1286
1434
|
frequencyPenalty,
|
|
1287
1435
|
presencePenalty,
|
|
@@ -1301,7 +1449,7 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1301
1449
|
abortSignal: signal
|
|
1302
1450
|
});
|
|
1303
1451
|
const agent = clientWithAbort.getAgent(agentId);
|
|
1304
|
-
const runId =
|
|
1452
|
+
const runId = uuid.v4();
|
|
1305
1453
|
const response = await agent.stream({
|
|
1306
1454
|
messages: coreUserMessages,
|
|
1307
1455
|
runId,
|
|
@@ -1317,9 +1465,10 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1317
1465
|
},
|
|
1318
1466
|
instructions,
|
|
1319
1467
|
requestContext,
|
|
1320
|
-
...threadId ? { threadId, resourceId: agentId } : {},
|
|
1468
|
+
...threadId ? { threadId, resourceId: resourceId || agentId } : {},
|
|
1321
1469
|
providerOptions,
|
|
1322
|
-
requireToolApproval
|
|
1470
|
+
requireToolApproval,
|
|
1471
|
+
tracingOptions
|
|
1323
1472
|
});
|
|
1324
1473
|
_onChunk.current = onChunk;
|
|
1325
1474
|
_currentRunId.current = runId;
|
|
@@ -1337,7 +1486,8 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1337
1486
|
threadId,
|
|
1338
1487
|
onNetworkChunk,
|
|
1339
1488
|
modelSettings,
|
|
1340
|
-
signal
|
|
1489
|
+
signal,
|
|
1490
|
+
tracingOptions
|
|
1341
1491
|
}) => {
|
|
1342
1492
|
const { frequencyPenalty, presencePenalty, maxRetries, maxTokens, temperature, topK, topP, maxSteps } = modelSettings || {};
|
|
1343
1493
|
setIsRunning(true);
|
|
@@ -1346,6 +1496,7 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1346
1496
|
abortSignal: signal
|
|
1347
1497
|
});
|
|
1348
1498
|
const agent = clientWithAbort.getAgent(agentId);
|
|
1499
|
+
const runId = uuid.v4();
|
|
1349
1500
|
const response = await agent.network({
|
|
1350
1501
|
messages: coreUserMessages,
|
|
1351
1502
|
maxSteps,
|
|
@@ -1358,9 +1509,10 @@ const useChat = ({ agentId, initializeMessages }) => {
|
|
|
1358
1509
|
topK,
|
|
1359
1510
|
topP
|
|
1360
1511
|
},
|
|
1361
|
-
runId
|
|
1512
|
+
runId,
|
|
1362
1513
|
requestContext,
|
|
1363
|
-
...threadId ? { thread: threadId, resourceId: agentId } : {}
|
|
1514
|
+
...threadId ? { thread: threadId, resourceId: resourceId || agentId } : {},
|
|
1515
|
+
tracingOptions
|
|
1364
1516
|
});
|
|
1365
1517
|
const transformer = new AISdkNetworkTransformer();
|
|
1366
1518
|
await response.processDataStream({
|