@mastra/react 0.4.1-alpha.6 → 0.4.1-alpha.8
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 +22 -0
- package/dist/agent/hooks.d.ts +7 -1
- package/dist/agent/hooks.d.ts.map +1 -1
- package/dist/index.cjs +86 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +86 -16
- package/dist/index.js.map +1 -1
- package/dist/lib/ai-sdk/utils/toUIMessage.d.ts.map +1 -1
- package/package.json +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @mastra/react
|
|
2
2
|
|
|
3
|
+
## 0.4.1-alpha.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed `clientTools` being silently dropped — and never executed — on thread-backed chats. When a chat had a `threadId`, the React `useChat` hook routed messages through the new agent signals path but did not pass the `clientTools` map into the signal startup flow, so client-side tools were unavailable when the model requested them. ([#16540](https://github.com/mastra-ai/mastra/pull/16540))
|
|
8
|
+
|
|
9
|
+
The signals path now carries `clientTools` and other per-send stream options on `sendSignal`. When the subscribed stream finishes with `tool-calls`, the client executes matching local tools with observability support, emits tool result chunks, and posts a continuation with the assistant tool-call messages plus tool-result messages so the run resumes on the same thread with the same per-send options.
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`c35b962`](https://github.com/mastra-ai/mastra/commit/c35b9625c7e854fcfdeee226a3338a750d0ff211), [`c35b962`](https://github.com/mastra-ai/mastra/commit/c35b9625c7e854fcfdeee226a3338a750d0ff211), [`9be1545`](https://github.com/mastra-ai/mastra/commit/9be1545475eb81a716169bb1281a37853cc739e0), [`4084113`](https://github.com/mastra-ai/mastra/commit/408411370fc48a822e8b616b3b63f9409774e0e9), [`bc01b1b`](https://github.com/mastra-ai/mastra/commit/bc01b1bfafe381d90af909f8bce7eeb4eee779f2), [`1120b4f`](https://github.com/mastra-ai/mastra/commit/1120b4fa928552c6ee1751efa5603d955841e766)]:
|
|
12
|
+
- @mastra/core@1.37.0-alpha.8
|
|
13
|
+
- @mastra/client-js@1.21.0-alpha.8
|
|
14
|
+
|
|
15
|
+
## 0.4.1-alpha.7
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Added support for reasoning-start and reasoning-end stream chunks so reasoning blocks are opened and closed with provider metadata preserved. ([#17061](https://github.com/mastra-ai/mastra/pull/17061))
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [[`168fa09`](https://github.com/mastra-ai/mastra/commit/168fa09d6b39114cb8c13bd06f1dccb9bc81c6cd), [`af2e1f8`](https://github.com/mastra-ai/mastra/commit/af2e1f8e2a2d2c4ba75167d5c93ca44395639eff)]:
|
|
22
|
+
- @mastra/core@1.37.0-alpha.7
|
|
23
|
+
- @mastra/client-js@1.21.0-alpha.7
|
|
24
|
+
|
|
3
25
|
## 0.4.1-alpha.6
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/agent/hooks.d.ts
CHANGED
|
@@ -13,6 +13,12 @@ export interface MastraChatProps {
|
|
|
13
13
|
initialMessages?: MastraUIMessage[];
|
|
14
14
|
/** Persistent request context used for tool approval/decline calls (e.g. agentVersionId). */
|
|
15
15
|
requestContext?: RequestContext;
|
|
16
|
+
/**
|
|
17
|
+
* Client-side tool definitions. Forwarded once to `subscribeToThread` so
|
|
18
|
+
* the client-js subscription drives the full client-tool execution loop
|
|
19
|
+
* (execute, emit tool-result, continuation) without any logic in React.
|
|
20
|
+
*/
|
|
21
|
+
clientTools?: Record<string, unknown>;
|
|
16
22
|
onSignalSent?: (signalId: string, preview: string) => void;
|
|
17
23
|
onSignalEcho?: (signalId: string) => void;
|
|
18
24
|
onThreadSignalsUnsupported?: () => void;
|
|
@@ -55,7 +61,7 @@ export type StreamArgs = SharedArgs & {
|
|
|
55
61
|
export type NetworkArgs = SharedArgs & {
|
|
56
62
|
onNetworkChunk?: (chunk: NetworkChunkType) => Promise<void>;
|
|
57
63
|
};
|
|
58
|
-
export declare const useChat: ({ agentId, resourceId, threadId, initialMessages, requestContext: propsRequestContext, onSignalSent, onSignalEcho, onThreadSignalsUnsupported, enableThreadSignals, }: MastraChatProps) => {
|
|
64
|
+
export declare const useChat: ({ agentId, resourceId, threadId, initialMessages, requestContext: propsRequestContext, clientTools: hookClientTools, onSignalSent, onSignalEcho, onThreadSignalsUnsupported, enableThreadSignals, }: MastraChatProps) => {
|
|
59
65
|
setMessages: import("react").Dispatch<import("react").SetStateAction<MastraUIMessage[]>>;
|
|
60
66
|
sendMessage: ({ mode, ...args }: SendMessageArgs) => Promise<void>;
|
|
61
67
|
isRunning: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/agent/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAQrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,KAAK,UAAU,GAAG,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/agent/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,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480,6 +480,39 @@ var toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
480
480
|
}
|
|
481
481
|
];
|
|
482
482
|
}
|
|
483
|
+
case "reasoning-start": {
|
|
484
|
+
const lastMessage = result[result.length - 1];
|
|
485
|
+
if (!lastMessage || lastMessage.role !== "assistant") {
|
|
486
|
+
const newMessage = {
|
|
487
|
+
id: `reasoning-${chunk.runId + Date.now()}`,
|
|
488
|
+
role: "assistant",
|
|
489
|
+
parts: [
|
|
490
|
+
{
|
|
491
|
+
type: "reasoning",
|
|
492
|
+
text: "",
|
|
493
|
+
state: "streaming",
|
|
494
|
+
providerMetadata: chunk.payload.providerMetadata
|
|
495
|
+
}
|
|
496
|
+
],
|
|
497
|
+
metadata
|
|
498
|
+
};
|
|
499
|
+
return [...result, newMessage];
|
|
500
|
+
}
|
|
501
|
+
const parts = [...lastMessage.parts];
|
|
502
|
+
parts.push({
|
|
503
|
+
type: "reasoning",
|
|
504
|
+
text: "",
|
|
505
|
+
state: "streaming",
|
|
506
|
+
providerMetadata: chunk.payload.providerMetadata
|
|
507
|
+
});
|
|
508
|
+
return [
|
|
509
|
+
...result.slice(0, -1),
|
|
510
|
+
{
|
|
511
|
+
...lastMessage,
|
|
512
|
+
parts
|
|
513
|
+
}
|
|
514
|
+
];
|
|
515
|
+
}
|
|
483
516
|
case "reasoning-delta": {
|
|
484
517
|
const lastMessage = result[result.length - 1];
|
|
485
518
|
if (!lastMessage || lastMessage.role !== "assistant") {
|
|
@@ -523,6 +556,36 @@ var toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
523
556
|
}
|
|
524
557
|
];
|
|
525
558
|
}
|
|
559
|
+
case "reasoning-end": {
|
|
560
|
+
const lastMessage = result[result.length - 1];
|
|
561
|
+
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
562
|
+
const parts = [...lastMessage.parts];
|
|
563
|
+
const reasoningPartIndex = parts.findLastIndex(
|
|
564
|
+
(part) => part.type === "reasoning" && part.state === "streaming"
|
|
565
|
+
);
|
|
566
|
+
if (reasoningPartIndex === -1) return result;
|
|
567
|
+
const reasoningPart = parts[reasoningPartIndex];
|
|
568
|
+
if (reasoningPart.type !== "reasoning") return result;
|
|
569
|
+
const existingMetadata = reasoningPart.providerMetadata;
|
|
570
|
+
const endMetadata = chunk.payload.providerMetadata;
|
|
571
|
+
parts[reasoningPartIndex] = {
|
|
572
|
+
...reasoningPart,
|
|
573
|
+
state: "done",
|
|
574
|
+
...existingMetadata || endMetadata ? {
|
|
575
|
+
providerMetadata: {
|
|
576
|
+
...existingMetadata ?? {},
|
|
577
|
+
...endMetadata ?? {}
|
|
578
|
+
}
|
|
579
|
+
} : {}
|
|
580
|
+
};
|
|
581
|
+
return [
|
|
582
|
+
...result.slice(0, -1),
|
|
583
|
+
{
|
|
584
|
+
...lastMessage,
|
|
585
|
+
parts
|
|
586
|
+
}
|
|
587
|
+
];
|
|
588
|
+
}
|
|
526
589
|
case "tool-call": {
|
|
527
590
|
const lastMessage = result[result.length - 1];
|
|
528
591
|
if (!lastMessage || lastMessage.role !== "assistant") {
|
|
@@ -1973,6 +2036,7 @@ var useChat = ({
|
|
|
1973
2036
|
threadId,
|
|
1974
2037
|
initialMessages,
|
|
1975
2038
|
requestContext: propsRequestContext,
|
|
2039
|
+
clientTools: hookClientTools,
|
|
1976
2040
|
onSignalSent,
|
|
1977
2041
|
onSignalEcho,
|
|
1978
2042
|
onThreadSignalsUnsupported,
|
|
@@ -2166,6 +2230,7 @@ var useChat = ({
|
|
|
2166
2230
|
requireToolApproval
|
|
2167
2231
|
} = modelSettings || {};
|
|
2168
2232
|
const resolvedRequestContext = requestContext ?? propsRequestContext;
|
|
2233
|
+
const resolvedClientTools = clientTools ?? hookClientTools;
|
|
2169
2234
|
_requestContext.current = resolvedRequestContext;
|
|
2170
2235
|
setIsRunning(true);
|
|
2171
2236
|
const clientWithAbort = new clientJs.MastraClient({
|
|
@@ -2193,7 +2258,7 @@ var useChat = ({
|
|
|
2193
2258
|
providerOptions,
|
|
2194
2259
|
tracingOptions,
|
|
2195
2260
|
requireToolApproval,
|
|
2196
|
-
clientTools
|
|
2261
|
+
clientTools: resolvedClientTools
|
|
2197
2262
|
});
|
|
2198
2263
|
if (response.finishReason === "suspended" && response.suspendPayload) {
|
|
2199
2264
|
const { toolCallId, toolName, args } = response.suspendPayload;
|
|
@@ -2253,6 +2318,23 @@ var useChat = ({
|
|
|
2253
2318
|
requireToolApproval
|
|
2254
2319
|
} = modelSettings || {};
|
|
2255
2320
|
const resolvedRequestContext = requestContext ?? propsRequestContext;
|
|
2321
|
+
const resolvedClientTools = clientTools ?? hookClientTools;
|
|
2322
|
+
const signalContinuationOptions = {
|
|
2323
|
+
maxSteps,
|
|
2324
|
+
modelSettings: {
|
|
2325
|
+
frequencyPenalty,
|
|
2326
|
+
presencePenalty,
|
|
2327
|
+
maxRetries,
|
|
2328
|
+
maxOutputTokens: maxTokens,
|
|
2329
|
+
temperature,
|
|
2330
|
+
topK,
|
|
2331
|
+
topP
|
|
2332
|
+
},
|
|
2333
|
+
instructions,
|
|
2334
|
+
providerOptions,
|
|
2335
|
+
requireToolApproval,
|
|
2336
|
+
tracingOptions
|
|
2337
|
+
};
|
|
2256
2338
|
_requestContext.current = resolvedRequestContext;
|
|
2257
2339
|
setIsRunning(true);
|
|
2258
2340
|
_streamAbortRef.current?.abort();
|
|
@@ -2287,7 +2369,7 @@ var useChat = ({
|
|
|
2287
2369
|
providerOptions,
|
|
2288
2370
|
requireToolApproval,
|
|
2289
2371
|
tracingOptions,
|
|
2290
|
-
clientTools
|
|
2372
|
+
clientTools: resolvedClientTools
|
|
2291
2373
|
});
|
|
2292
2374
|
_onChunk.current = onChunk;
|
|
2293
2375
|
_currentRunId.current = runId;
|
|
@@ -2322,21 +2404,9 @@ var useChat = ({
|
|
|
2322
2404
|
threadId: threadId2,
|
|
2323
2405
|
ifIdle: {
|
|
2324
2406
|
streamOptions: {
|
|
2325
|
-
|
|
2326
|
-
modelSettings: {
|
|
2327
|
-
frequencyPenalty,
|
|
2328
|
-
presencePenalty,
|
|
2329
|
-
maxRetries,
|
|
2330
|
-
maxOutputTokens: maxTokens,
|
|
2331
|
-
temperature,
|
|
2332
|
-
topK,
|
|
2333
|
-
topP
|
|
2334
|
-
},
|
|
2335
|
-
instructions,
|
|
2407
|
+
...signalContinuationOptions,
|
|
2336
2408
|
requestContext: resolvedRequestContext,
|
|
2337
|
-
|
|
2338
|
-
requireToolApproval,
|
|
2339
|
-
tracingOptions
|
|
2409
|
+
clientTools: resolvedClientTools
|
|
2340
2410
|
}
|
|
2341
2411
|
}
|
|
2342
2412
|
});
|