@mastra/react 1.4.13-alpha.3 → 1.5.0-alpha.6
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/dist/agent/hooks.d.ts +7 -2
- package/dist/agent/hooks.d.ts.map +1 -1
- package/dist/agent/types.d.ts +1 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/index.cjs +66 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +66 -28
- package/dist/index.js.map +1 -1
- package/dist/lib/mastra-db/types.d.ts +2 -0
- package/dist/lib/mastra-db/types.d.ts.map +1 -1
- package/dist/ui/MessageFactory/MessageFactory.d.ts.map +1 -1
- package/dist/ui/MessageFactory/types.d.ts +2 -1
- package/dist/ui/MessageFactory/types.d.ts.map +1 -1
- package/dist/ui/index.cjs +1 -1
- package/dist/ui/index.js +1 -1
- package/dist/{ui-Bd2cu1B9.js → ui-BQyoxYsH.js} +2 -1
- package/dist/{ui-Bd2cu1B9.js.map → ui-BQyoxYsH.js.map} +1 -1
- package/dist/{ui-DL8WaLmH.cjs → ui-C979LXC_.cjs} +2 -1
- package/dist/{ui-DL8WaLmH.cjs.map → ui-C979LXC_.cjs.map} +1 -1
- package/package.json +4 -4
package/dist/agent/hooks.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { CoreUserMessage } from '@mastra/core/llm';
|
|
|
3
3
|
import type { TracingOptions } from '@mastra/core/observability';
|
|
4
4
|
import type { RequestContext } from '@mastra/core/request-context';
|
|
5
5
|
import type { ChunkType, NetworkChunkType } from '@mastra/core/stream';
|
|
6
|
-
import type { ClientToolsInput, ModelSettings } from './types.js';
|
|
6
|
+
import type { ClientToolsInput, ClientToolsResolver, ModelSettings } from './types.js';
|
|
7
7
|
export interface MastraChatProps {
|
|
8
8
|
agentId: string;
|
|
9
9
|
resourceId?: string;
|
|
@@ -25,6 +25,8 @@ export interface MastraChatProps {
|
|
|
25
25
|
* Defaults to `false`; set to `true` to opt into thread signals.
|
|
26
26
|
*/
|
|
27
27
|
enableThreadSignals?: boolean;
|
|
28
|
+
/** Override the legacy stream route for editor-owned hidden agents. */
|
|
29
|
+
streamPath?: string;
|
|
28
30
|
}
|
|
29
31
|
interface SharedArgs {
|
|
30
32
|
coreUserMessages: CoreUserMessage[];
|
|
@@ -50,10 +52,12 @@ export type SendMessageArgs = {
|
|
|
50
52
|
export type GenerateArgs = SharedArgs & {
|
|
51
53
|
onFinish?: (messages: MastraDBMessage[]) => Promise<void>;
|
|
52
54
|
clientTools?: ClientToolsInput;
|
|
55
|
+
clientToolsResolver?: ClientToolsResolver;
|
|
53
56
|
};
|
|
54
57
|
export type StreamArgs = SharedArgs & {
|
|
55
58
|
onChunk?: (chunk: ChunkType) => Promise<void>;
|
|
56
59
|
clientTools?: ClientToolsInput;
|
|
60
|
+
clientToolsResolver?: ClientToolsResolver;
|
|
57
61
|
signalId?: string;
|
|
58
62
|
/**
|
|
59
63
|
* Client-generated correlation id stamped on the optimistic pending bubble
|
|
@@ -64,10 +68,11 @@ export type StreamArgs = SharedArgs & {
|
|
|
64
68
|
export type NetworkArgs = SharedArgs & {
|
|
65
69
|
onNetworkChunk?: (chunk: NetworkChunkType) => Promise<void>;
|
|
66
70
|
};
|
|
67
|
-
export declare const useChat: ({ agentId, resourceId, threadId, initialMessages, requestContext: propsRequestContext, clientTools: hookClientTools, onSignalSent, onSignalEcho, onThreadSignalsUnsupported, enableThreadSignals, }: MastraChatProps) => {
|
|
71
|
+
export declare const useChat: ({ agentId, resourceId, threadId, initialMessages, requestContext: propsRequestContext, clientTools: hookClientTools, onSignalSent, onSignalEcho, onThreadSignalsUnsupported, enableThreadSignals, streamPath, }: MastraChatProps) => {
|
|
68
72
|
setMessages: import("react").Dispatch<import("react").SetStateAction<MastraDBMessage[]>>;
|
|
69
73
|
sendMessage: ({ mode, ...args }: SendMessageArgs) => Promise<void>;
|
|
70
74
|
isRunning: boolean;
|
|
75
|
+
activeRunId: string | undefined;
|
|
71
76
|
isAwaitingToolApproval: boolean;
|
|
72
77
|
messages: MastraDBMessage[];
|
|
73
78
|
tasks: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/agent/hooks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAY,eAAe,EAA4B,MAAM,iCAAiC,CAAC;AAE3G,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;AAEnE,OAAO,KAAK,EAAE,SAAS,EAAiB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAkBtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/agent/hooks.ts"],"names":[],"mappings":"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"}
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { GenerateLegacyParams } from '@mastra/client-js';
|
|
2
2
|
import type { ToolsInput } from '@mastra/core/agent';
|
|
3
3
|
export type ClientToolsInput = ToolsInput;
|
|
4
|
+
export type ClientToolsResolver = () => ClientToolsInput | undefined;
|
|
4
5
|
export type ProviderOptionsInput = GenerateLegacyParams['providerOptions'];
|
|
5
6
|
export interface ModelSettings {
|
|
6
7
|
frequencyPenalty?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC;AAC1C,MAAM,MAAM,oBAAoB,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;AAE3E,MAAM,WAAW,aAAa;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,oBAAoB,CAAC;IACvC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC;AAC1C,MAAM,MAAM,mBAAmB,GAAG,MAAM,gBAAgB,GAAG,SAAS,CAAC;AACrE,MAAM,MAAM,oBAAoB,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;AAE3E,MAAM,WAAW,aAAa;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,oBAAoB,CAAC;IACvC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_ui = require("./ui-
|
|
2
|
+
const require_ui = require("./ui-C979LXC_.cjs");
|
|
3
3
|
let _mastra_client_js = require("@mastra/client-js");
|
|
4
4
|
let react = require("react");
|
|
5
5
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -1909,7 +1909,7 @@ const dbFromServerUiMessages = (uiMessages, metadata) => uiMessages.map((uiMsg)
|
|
|
1909
1909
|
}
|
|
1910
1910
|
};
|
|
1911
1911
|
});
|
|
1912
|
-
const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContext: propsRequestContext, clientTools: hookClientTools, onSignalSent, onSignalEcho, onThreadSignalsUnsupported, enableThreadSignals = false }) => {
|
|
1912
|
+
const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContext: propsRequestContext, clientTools: hookClientTools, onSignalSent, onSignalEcho, onThreadSignalsUnsupported, enableThreadSignals = false, streamPath }) => {
|
|
1913
1913
|
const threadSignalsDisabled = enableThreadSignals === false;
|
|
1914
1914
|
const _currentRunId = (0, react.useRef)(void 0);
|
|
1915
1915
|
const _onChunk = (0, react.useRef)(void 0);
|
|
@@ -2046,11 +2046,29 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2046
2046
|
const processStreamChunk = (0, react.useCallback)(async (chunk, onChunk) => {
|
|
2047
2047
|
const isTerminal = chunk.type === "finish" || chunk.type === "abort" || chunk.type === "error";
|
|
2048
2048
|
if (isTerminal && liveRunId.current && chunk.runId !== liveRunId.current) return;
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2049
|
+
const runId = "runId" in chunk && typeof chunk.runId === "string" ? chunk.runId : void 0;
|
|
2050
|
+
setMessages((prev) => {
|
|
2051
|
+
const metadata = {
|
|
2052
|
+
mode: "stream",
|
|
2053
|
+
runId
|
|
2054
|
+
};
|
|
2055
|
+
const next = accumulateChunk({
|
|
2056
|
+
chunk,
|
|
2057
|
+
conversation: prev,
|
|
2058
|
+
metadata
|
|
2059
|
+
});
|
|
2060
|
+
if ((chunk.type === "start" || chunk.type === "step-start") && chunk.payload?.messageId && runId) return next.map((message) => message.id === chunk.payload.messageId && message.role === "assistant" ? {
|
|
2061
|
+
...message,
|
|
2062
|
+
content: {
|
|
2063
|
+
...message.content,
|
|
2064
|
+
metadata: {
|
|
2065
|
+
...message.content.metadata,
|
|
2066
|
+
...metadata
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
} : message);
|
|
2070
|
+
return next;
|
|
2071
|
+
});
|
|
2054
2072
|
const streamedTasks = extractTasksFromToolResultChunk(chunk) ?? extractTasksFromSignalChunk(chunk);
|
|
2055
2073
|
if (streamedTasks !== void 0) {
|
|
2056
2074
|
liveTasks.current = streamedTasks;
|
|
@@ -2085,7 +2103,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2085
2103
|
(onChunk ?? _onChunk.current)?.(chunk);
|
|
2086
2104
|
}, [onSignalEcho]);
|
|
2087
2105
|
const ensureThreadSubscription = (0, react.useCallback)(async ({ threadId, resourceId }) => {
|
|
2088
|
-
const subscriptionKey = `${agentId}:${resourceId ?? ""}:${threadId}`;
|
|
2106
|
+
const subscriptionKey = `${agentId}:${resourceId ?? ""}:${threadId}:${streamPath ?? ""}`;
|
|
2089
2107
|
if (_threadSubscriptionKeyRef.current === subscriptionKey && _threadSubscriptionPromiseRef.current) {
|
|
2090
2108
|
await _threadSubscriptionPromiseRef.current;
|
|
2091
2109
|
return;
|
|
@@ -2104,7 +2122,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2104
2122
|
const subscriptionAgent = new _mastra_client_js.MastraClient({
|
|
2105
2123
|
...baseClient.options,
|
|
2106
2124
|
abortSignal: subscriptionAbort.signal
|
|
2107
|
-
}).getAgent(agentId);
|
|
2125
|
+
}).getAgent(agentId, void 0, { stream: streamPath });
|
|
2108
2126
|
_threadSubscriptionPromiseRef.current = subscriptionAgent.subscribeToThread({
|
|
2109
2127
|
resourceId,
|
|
2110
2128
|
threadId
|
|
@@ -2142,7 +2160,8 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2142
2160
|
baseClient,
|
|
2143
2161
|
closeThreadSubscription,
|
|
2144
2162
|
markThreadSignalsUnsupported,
|
|
2145
|
-
processStreamChunk
|
|
2163
|
+
processStreamChunk,
|
|
2164
|
+
streamPath
|
|
2146
2165
|
]);
|
|
2147
2166
|
(0, react.useEffect)(() => {
|
|
2148
2167
|
_threadSignalsUnsupportedRef.current = false;
|
|
@@ -2172,7 +2191,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2172
2191
|
threadId,
|
|
2173
2192
|
threadSignalsDisabled
|
|
2174
2193
|
]);
|
|
2175
|
-
const generate = async ({ coreUserMessages, model, requestContext, threadId, modelSettings, signal, onFinish, tracingOptions, clientTools }) => {
|
|
2194
|
+
const generate = async ({ coreUserMessages, model, requestContext, threadId, modelSettings, signal, onFinish, tracingOptions, clientTools, clientToolsResolver }) => {
|
|
2176
2195
|
const { frequencyPenalty, presencePenalty, maxRetries, maxTokens, temperature, topK, topP, instructions, system, providerOptions, maxSteps, requireToolApproval } = modelSettings || {};
|
|
2177
2196
|
const resolvedRequestContext = requestContext ?? propsRequestContext;
|
|
2178
2197
|
const resolvedClientTools = clientTools ?? hookClientTools;
|
|
@@ -2184,7 +2203,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2184
2203
|
const agent = new _mastra_client_js.MastraClient({
|
|
2185
2204
|
...baseClient.options,
|
|
2186
2205
|
abortSignal: signal
|
|
2187
|
-
}).getAgent(agentId);
|
|
2206
|
+
}).getAgent(agentId, void 0, { stream: streamPath });
|
|
2188
2207
|
const runId = (0, _lukeed_uuid.v4)();
|
|
2189
2208
|
_currentRunId.current = runId;
|
|
2190
2209
|
const response = await agent.generate(coreUserMessages, {
|
|
@@ -2210,7 +2229,8 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2210
2229
|
providerOptions,
|
|
2211
2230
|
tracingOptions,
|
|
2212
2231
|
requireToolApproval,
|
|
2213
|
-
clientTools: resolvedClientTools
|
|
2232
|
+
clientTools: resolvedClientTools,
|
|
2233
|
+
clientToolsResolver
|
|
2214
2234
|
});
|
|
2215
2235
|
if (response.finishReason === "suspended" && response.suspendPayload) {
|
|
2216
2236
|
const { toolCallId, toolName, args } = response.suspendPayload;
|
|
@@ -2235,7 +2255,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2235
2255
|
setMessages((prev) => [...prev, ...dbMessages]);
|
|
2236
2256
|
}
|
|
2237
2257
|
};
|
|
2238
|
-
const stream = async ({ coreUserMessages, model, requestContext, threadId, onChunk, modelSettings, signal, tracingOptions, clientTools, signalId, clientMessageId }) => {
|
|
2258
|
+
const stream = async ({ coreUserMessages, model, requestContext, threadId, onChunk, modelSettings, signal, tracingOptions, clientTools, clientToolsResolver, signalId, clientMessageId }) => {
|
|
2239
2259
|
const { frequencyPenalty, presencePenalty, maxRetries, maxTokens, temperature, topK, topP, instructions, system, providerOptions, maxSteps, requireToolApproval } = modelSettings || {};
|
|
2240
2260
|
const resolvedRequestContext = requestContext ?? propsRequestContext;
|
|
2241
2261
|
const resolvedClientTools = clientTools ?? hookClientTools;
|
|
@@ -2270,7 +2290,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2270
2290
|
const agent = new _mastra_client_js.MastraClient({
|
|
2271
2291
|
...baseClient.options,
|
|
2272
2292
|
abortSignal: internalAbort.signal
|
|
2273
|
-
}).getAgent(agentId);
|
|
2293
|
+
}).getAgent(agentId, void 0, { stream: streamPath });
|
|
2274
2294
|
const streamWithLegacyRoute = async () => {
|
|
2275
2295
|
const runId = (0, _lukeed_uuid.v4)();
|
|
2276
2296
|
const response = await agent.stream(coreUserMessages, {
|
|
@@ -2297,7 +2317,8 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2297
2317
|
providerOptions,
|
|
2298
2318
|
requireToolApproval,
|
|
2299
2319
|
tracingOptions,
|
|
2300
|
-
clientTools: resolvedClientTools
|
|
2320
|
+
clientTools: resolvedClientTools,
|
|
2321
|
+
clientToolsResolver
|
|
2301
2322
|
});
|
|
2302
2323
|
_onChunk.current = onChunk;
|
|
2303
2324
|
_currentRunId.current = runId;
|
|
@@ -2338,7 +2359,9 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2338
2359
|
requestContext: requestContextRecord,
|
|
2339
2360
|
providerOptions,
|
|
2340
2361
|
requireToolApproval,
|
|
2341
|
-
tracingOptions
|
|
2362
|
+
tracingOptions,
|
|
2363
|
+
clientTools: resolvedClientTools,
|
|
2364
|
+
clientToolsResolver
|
|
2342
2365
|
};
|
|
2343
2366
|
try {
|
|
2344
2367
|
const result = await agent.sendMessage({
|
|
@@ -2351,7 +2374,8 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2351
2374
|
ifIdle: { streamOptions: {
|
|
2352
2375
|
...signalContinuationOptions,
|
|
2353
2376
|
requestContext: requestContextRecord,
|
|
2354
|
-
clientTools: resolvedClientTools
|
|
2377
|
+
clientTools: resolvedClientTools,
|
|
2378
|
+
clientToolsResolver
|
|
2355
2379
|
} }
|
|
2356
2380
|
});
|
|
2357
2381
|
const echoedSignalId = result.signal && typeof result.signal === "object" && "id" in result.signal && typeof result.signal.id === "string" ? result.signal.id : resolvedSignalId;
|
|
@@ -2396,8 +2420,9 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2396
2420
|
const agent = new _mastra_client_js.MastraClient({
|
|
2397
2421
|
...baseClient.options,
|
|
2398
2422
|
abortSignal: signal
|
|
2399
|
-
}).getAgent(agentId);
|
|
2423
|
+
}).getAgent(agentId, void 0, { stream: streamPath });
|
|
2400
2424
|
const runId = (0, _lukeed_uuid.v4)();
|
|
2425
|
+
_currentRunId.current = runId;
|
|
2401
2426
|
const response = await agent.network(coreUserMessages, {
|
|
2402
2427
|
model,
|
|
2403
2428
|
maxSteps,
|
|
@@ -2424,7 +2449,10 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2424
2449
|
setMessages((prev) => accumulateNetworkChunk({
|
|
2425
2450
|
chunk,
|
|
2426
2451
|
conversation: prev,
|
|
2427
|
-
metadata: {
|
|
2452
|
+
metadata: {
|
|
2453
|
+
mode: "network",
|
|
2454
|
+
runId
|
|
2455
|
+
}
|
|
2428
2456
|
}));
|
|
2429
2457
|
onNetworkChunk?.(chunk);
|
|
2430
2458
|
} });
|
|
@@ -2460,7 +2488,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2460
2488
|
...prev,
|
|
2461
2489
|
[toolCallId]: { status: "approved" }
|
|
2462
2490
|
}));
|
|
2463
|
-
const agent = baseClient.getAgent(agentId);
|
|
2491
|
+
const agent = baseClient.getAgent(agentId, void 0, { stream: streamPath });
|
|
2464
2492
|
if (_threadSubscriptionKeyRef.current && threadId) {
|
|
2465
2493
|
try {
|
|
2466
2494
|
await agent.sendToolApproval({
|
|
@@ -2521,7 +2549,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2521
2549
|
...prev,
|
|
2522
2550
|
[toolCallId]: { status: "declined" }
|
|
2523
2551
|
}));
|
|
2524
|
-
const agent = baseClient.getAgent(agentId);
|
|
2552
|
+
const agent = baseClient.getAgent(agentId, void 0, { stream: streamPath });
|
|
2525
2553
|
if (_threadSubscriptionKeyRef.current && threadId) {
|
|
2526
2554
|
try {
|
|
2527
2555
|
await agent.sendToolApproval({
|
|
@@ -2566,7 +2594,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2566
2594
|
...prev,
|
|
2567
2595
|
[toolCallId]: { status: "approved" }
|
|
2568
2596
|
}));
|
|
2569
|
-
const response = await baseClient.getAgent(agentId).approveToolCallGenerate({
|
|
2597
|
+
const response = await baseClient.getAgent(agentId, void 0, { stream: streamPath }).approveToolCallGenerate({
|
|
2570
2598
|
runId: currentRunId,
|
|
2571
2599
|
toolCallId,
|
|
2572
2600
|
...continuation
|
|
@@ -2586,7 +2614,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2586
2614
|
...prev,
|
|
2587
2615
|
[toolCallId]: { status: "declined" }
|
|
2588
2616
|
}));
|
|
2589
|
-
const response = await baseClient.getAgent(agentId).declineToolCallGenerate({
|
|
2617
|
+
const response = await baseClient.getAgent(agentId, void 0, { stream: streamPath }).declineToolCallGenerate({
|
|
2590
2618
|
runId: currentRunId,
|
|
2591
2619
|
toolCallId,
|
|
2592
2620
|
...continuation
|
|
@@ -2602,19 +2630,23 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2602
2630
|
const networkRunId = runId || _networkRunId.current;
|
|
2603
2631
|
const continuation = _activeContinuation.current;
|
|
2604
2632
|
if (!networkRunId) return console.info("[approveNetworkToolCall] approveNetworkToolCall can only be called after a network stream has started");
|
|
2633
|
+
_currentRunId.current = networkRunId;
|
|
2605
2634
|
setIsRunning(true);
|
|
2606
2635
|
setNetworkToolCallApprovals((prev) => ({
|
|
2607
2636
|
...prev,
|
|
2608
2637
|
[runId ? `${runId}-${toolName}` : toolName]: { status: "approved" }
|
|
2609
2638
|
}));
|
|
2610
|
-
await (await baseClient.getAgent(agentId).approveNetworkToolCall({
|
|
2639
|
+
await (await baseClient.getAgent(agentId, void 0, { stream: streamPath }).approveNetworkToolCall({
|
|
2611
2640
|
runId: networkRunId,
|
|
2612
2641
|
...continuation
|
|
2613
2642
|
})).processDataStream({ onChunk: async (chunk) => {
|
|
2614
2643
|
setMessages((prev) => accumulateNetworkChunk({
|
|
2615
2644
|
chunk,
|
|
2616
2645
|
conversation: prev,
|
|
2617
|
-
metadata: {
|
|
2646
|
+
metadata: {
|
|
2647
|
+
mode: "network",
|
|
2648
|
+
runId: networkRunId
|
|
2649
|
+
}
|
|
2618
2650
|
}));
|
|
2619
2651
|
onNetworkChunk?.(chunk);
|
|
2620
2652
|
} });
|
|
@@ -2626,19 +2658,23 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2626
2658
|
const networkRunId = runId || _networkRunId.current;
|
|
2627
2659
|
const continuation = _activeContinuation.current;
|
|
2628
2660
|
if (!networkRunId) return console.info("[declineNetworkToolCall] declineNetworkToolCall can only be called after a network stream has started");
|
|
2661
|
+
_currentRunId.current = networkRunId;
|
|
2629
2662
|
setIsRunning(true);
|
|
2630
2663
|
setNetworkToolCallApprovals((prev) => ({
|
|
2631
2664
|
...prev,
|
|
2632
2665
|
[runId ? `${runId}-${toolName}` : toolName]: { status: "declined" }
|
|
2633
2666
|
}));
|
|
2634
|
-
await (await baseClient.getAgent(agentId).declineNetworkToolCall({
|
|
2667
|
+
await (await baseClient.getAgent(agentId, void 0, { stream: streamPath }).declineNetworkToolCall({
|
|
2635
2668
|
runId: networkRunId,
|
|
2636
2669
|
...continuation
|
|
2637
2670
|
})).processDataStream({ onChunk: async (chunk) => {
|
|
2638
2671
|
setMessages((prev) => accumulateNetworkChunk({
|
|
2639
2672
|
chunk,
|
|
2640
2673
|
conversation: prev,
|
|
2641
|
-
metadata: {
|
|
2674
|
+
metadata: {
|
|
2675
|
+
mode: "network",
|
|
2676
|
+
runId: networkRunId
|
|
2677
|
+
}
|
|
2642
2678
|
}));
|
|
2643
2679
|
onNetworkChunk?.(chunk);
|
|
2644
2680
|
} });
|
|
@@ -2646,6 +2682,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2646
2682
|
setIsRunning(false);
|
|
2647
2683
|
};
|
|
2648
2684
|
const sendMessage = async ({ mode = "stream", ...args }) => {
|
|
2685
|
+
if (!isRunning && !isAwaitingToolApproval) _currentRunId.current = void 0;
|
|
2649
2686
|
const coreUserMessages = [{
|
|
2650
2687
|
role: "user",
|
|
2651
2688
|
content: [{
|
|
@@ -2699,6 +2736,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
|
|
|
2699
2736
|
setMessages,
|
|
2700
2737
|
sendMessage,
|
|
2701
2738
|
isRunning,
|
|
2739
|
+
activeRunId: isRunning || isAwaitingToolApproval ? _currentRunId.current : void 0,
|
|
2702
2740
|
isAwaitingToolApproval,
|
|
2703
2741
|
messages,
|
|
2704
2742
|
tasks,
|