agents 0.21.0 → 0.22.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/README.md +1 -0
- package/dist/{agent-tool-types-CzGGB-20.d.ts → agent-routing-CnkaHb-v.d.ts} +2921 -3057
- package/dist/agent-routing.d.ts +14 -0
- package/dist/agent-routing.js +187 -0
- package/dist/agent-routing.js.map +1 -0
- package/dist/agent-tool-types.d.ts +26 -26
- package/dist/{agent-tools-zR2d5uij.d.ts → agent-tools-C0XJqWzB.d.ts} +7 -7
- package/dist/agent-tools.d.ts +21 -21
- package/dist/agent-tools.js +2 -1
- package/dist/agent-tools.js.map +1 -1
- package/dist/browser/ai.js +2 -1
- package/dist/browser/ai.js.map +1 -1
- package/dist/capability-BjSKYpzg.js +42 -0
- package/dist/capability-BjSKYpzg.js.map +1 -0
- package/dist/capability-runner-CvHGZqUu.d.ts +150 -0
- package/dist/chat/index.d.ts +22 -15
- package/dist/chat/index.js +4 -4
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/react.d.ts +14 -1
- package/dist/chat/react.js +82 -52
- package/dist/chat/react.js.map +1 -1
- package/dist/chat/transport.js +1 -1
- package/dist/chat-sdk/index.d.ts +4 -4
- package/dist/chat-sdk/index.js +1 -1
- package/dist/{client-zqKcsyFa.js → client-jagG8a9_.js} +129 -37
- package/dist/client-jagG8a9_.js.map +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.js +1 -1
- package/dist/{cloudflare-BduZwmYK.js → cloudflare-Dzvc7V2N.js} +10 -3
- package/dist/{cloudflare-BduZwmYK.js.map → cloudflare-Dzvc7V2N.js.map} +1 -1
- package/dist/current-agent-CuMErtly.d.ts +283 -0
- package/dist/current-agent-DhoDkSnH.js +51 -0
- package/dist/current-agent-DhoDkSnH.js.map +1 -0
- package/dist/diagnostics-CaBjfz4J.js +41 -0
- package/dist/diagnostics-CaBjfz4J.js.map +1 -0
- package/dist/{do-oauth-client-provider-VTZj2VtM.d.ts → do-oauth-client-provider-Tmf1vgKz.d.ts} +2 -2
- package/dist/durable-object-lifecycle-D6nNQJJd.js +862 -0
- package/dist/durable-object-lifecycle-D6nNQJJd.js.map +1 -0
- package/dist/{email-CL27preh.d.ts → email-7TatiTnl.d.ts} +38 -9
- package/dist/email-send.d.ts +15 -0
- package/dist/email-send.js +32 -0
- package/dist/email-send.js.map +1 -0
- package/dist/email.d.ts +14 -10
- package/dist/email.js.map +1 -1
- package/dist/experimental/memory/session/index.d.ts +3 -2
- package/dist/experimental/memory/session/index.js +15 -10
- package/dist/experimental/memory/session/index.js.map +1 -1
- package/dist/{handler-stateless-C_bo-Ytq.d.ts → handler-stateless-DxYpJ_XF.d.ts} +3 -3
- package/dist/{handler-stateless-CIkKPETH.js → handler-stateless-VvrWSAVA.js} +5 -5
- package/dist/handler-stateless-VvrWSAVA.js.map +1 -0
- package/dist/{index-BRnybD6X.d.ts → index-DcSAZKsB.d.ts} +19 -31
- package/dist/index.d.ts +98 -95
- package/dist/index.js +10 -7234
- package/dist/internal_context-BlxFEWfn.d.ts +19 -0
- package/dist/internal_context.d.ts +10 -4
- package/dist/internal_context.js +1 -10
- package/dist/{client-invoker-BNSZxAkv.d.ts → invoker-CG0_p_Wq.d.ts} +2 -2
- package/dist/{client-invoker-VNZ7X0nn.js → invoker-CHMnoxIA.js} +2 -2
- package/dist/invoker-CHMnoxIA.js.map +1 -0
- package/dist/lifecycle/index.d.ts +48 -0
- package/dist/lifecycle/index.js +4 -0
- package/dist/mcp/{do-oauth-client-provider.d.ts → client/do-oauth-client-provider.d.ts} +1 -1
- package/dist/mcp/{do-oauth-client-provider.js → client/do-oauth-client-provider.js} +1 -1
- package/dist/mcp/client/do-oauth-client-provider.js.map +1 -0
- package/dist/mcp/client/index.d.ts +42 -0
- package/dist/mcp/{client.js → client/index.js} +1 -1
- package/dist/mcp/{x402.d.ts → client/x402.d.ts} +2 -2
- package/dist/mcp/{x402.js → client/x402.js} +2 -2
- package/dist/mcp/client/x402.js.map +1 -0
- package/dist/mcp/index.d.ts +36 -36
- package/dist/mcp/index.js +14 -16
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/{server.d.ts → server/index.d.ts} +1 -1
- package/dist/mcp/{server.js → server/index.js} +1 -1
- package/dist/observability/ai/index.js +50 -35
- package/dist/observability/ai/index.js.map +1 -1
- package/dist/observability/index.d.ts +4 -4
- package/dist/observability/index.js +3 -50
- package/dist/observability/index.js.map +1 -1
- package/dist/{protocol-Dqc2MQxo.js → protocol-B0nh6KNf.js} +19 -21
- package/dist/protocol-B0nh6KNf.js.map +1 -0
- package/dist/react.d.ts +4 -4
- package/dist/react.js +1 -1
- package/dist/schedule.d.ts +25 -94
- package/dist/schedule.js +1 -98
- package/dist/schedule.js.map +1 -1
- package/dist/scheduler-CR9RHGos.js +857 -0
- package/dist/scheduler-CR9RHGos.js.map +1 -0
- package/dist/scheduler-DQoTGoAW.d.ts +224 -0
- package/dist/schedules/index.d.ts +22 -0
- package/dist/schedules/index.js +2 -0
- package/dist/schedules/parser.d.ts +79 -0
- package/dist/schedules/parser.js +103 -0
- package/dist/schedules/parser.js.map +1 -0
- package/dist/serializable.d.ts +1 -1
- package/dist/sql-error-CPY-GXyI.d.ts +12 -0
- package/dist/sql-error.d.ts +2 -0
- package/dist/sql-error.js +16 -0
- package/dist/sql-error.js.map +1 -0
- package/dist/src-5W6JNKVb.js +6613 -0
- package/dist/src-5W6JNKVb.js.map +1 -0
- package/dist/sub-routing.d.ts +12 -12
- package/dist/workflow-types.d.ts +25 -25
- package/dist/workflows.d.ts +22 -22
- package/dist/workflows.js +2 -1
- package/dist/workflows.js.map +1 -1
- package/dist/{ws-chat-transport-CIoOBbO7.js → ws-chat-transport-rWwta645.js} +152 -15
- package/dist/ws-chat-transport-rWwta645.js.map +1 -0
- package/docs/agent-class.md +28 -86
- package/docs/chat-agents.md +13 -12
- package/docs/durable-execution.md +1 -1
- package/docs/http-websockets.md +1 -11
- package/docs/human-in-the-loop.md +1 -1
- package/docs/index.md +1 -0
- package/docs/lifecycle.md +323 -0
- package/docs/long-running-agents.md +2 -4
- package/docs/mcp-client.md +55 -0
- package/docs/observability.md +11 -11
- package/docs/resumable-streaming.md +1 -1
- package/docs/scheduling.md +175 -15
- package/docs/server-driven-messages.md +1 -1
- package/docs/sub-agents.md +1 -1
- package/package.json +30 -21
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +0 -26
- package/dist/cli/index.js.map +0 -1
- package/dist/client-invoker-VNZ7X0nn.js.map +0 -1
- package/dist/client-zqKcsyFa.js.map +0 -1
- package/dist/handler-stateless-CIkKPETH.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/internal_context-Dg4Cgjcu.d.ts +0 -37
- package/dist/internal_context.js.map +0 -1
- package/dist/mcp/client.d.ts +0 -42
- package/dist/mcp/do-oauth-client-provider.js.map +0 -1
- package/dist/mcp/x402.js.map +0 -1
- package/dist/protocol-Dqc2MQxo.js.map +0 -1
- package/dist/ws-chat-transport-CIoOBbO7.js.map +0 -1
package/dist/chat/react.d.ts
CHANGED
|
@@ -208,7 +208,10 @@ type OnToolCallCallback = (options: {
|
|
|
208
208
|
type UseAgentChatOptions<
|
|
209
209
|
State = unknown,
|
|
210
210
|
ChatMessage extends UIMessage = UIMessage
|
|
211
|
-
> = Omit<
|
|
211
|
+
> = Omit<
|
|
212
|
+
UseChatParams<ChatMessage>,
|
|
213
|
+
"fetch" | "onToolCall" | "throttle" | "experimental_throttle"
|
|
214
|
+
> & {
|
|
212
215
|
/** Agent connection from useAgent (accepts both typed and untyped agents) */ agent: AgentConnection & {
|
|
213
216
|
agent: string;
|
|
214
217
|
name: string;
|
|
@@ -227,6 +230,16 @@ type UseAgentChatOptions<
|
|
|
227
230
|
) => Promise<ChatMessage[]>) /** Request credentials */;
|
|
228
231
|
credentials?: RequestCredentials /** Request headers */;
|
|
229
232
|
headers?: HeadersInit;
|
|
233
|
+
/**
|
|
234
|
+
* Milliseconds to coalesce chat state updates before re-rendering,
|
|
235
|
+
* defaulting to 50.
|
|
236
|
+
*
|
|
237
|
+
* Streaming writes chat state once per chunk, so without a throttle a fast
|
|
238
|
+
* burst of chunks renders once per chunk. The first chunk is never delayed.
|
|
239
|
+
* Pass `false` to render every chunk as it arrives.
|
|
240
|
+
*/
|
|
241
|
+
throttle?: number | false /** @deprecated Use `throttle`. */;
|
|
242
|
+
experimental_throttle?: number;
|
|
230
243
|
/**
|
|
231
244
|
* Callback for handling client-side tool execution.
|
|
232
245
|
* Called when a tool without server-side `execute` is invoked by the LLM.
|
package/dist/chat/react.js
CHANGED
|
@@ -1,10 +1,40 @@
|
|
|
1
|
-
import { n as STREAM_RESUME_NONE_REASONS, r as transition } from "../protocol-
|
|
1
|
+
import { n as STREAM_RESUME_NONE_REASONS, r as transition } from "../protocol-B0nh6KNf.js";
|
|
2
2
|
import "../wire-types-CnMt6_HR.js";
|
|
3
|
-
import { t as WebSocketChatTransport } from "../ws-chat-transport-
|
|
3
|
+
import { t as WebSocketChatTransport } from "../ws-chat-transport-rWwta645.js";
|
|
4
4
|
import { getToolName, isToolUIPart } from "ai";
|
|
5
5
|
import { nanoid } from "nanoid";
|
|
6
6
|
import { use, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
7
7
|
import { useChat } from "@ai-sdk/react";
|
|
8
|
+
/**
|
|
9
|
+
* Picks the throttle from an explicit caller value, the deprecated alias, or
|
|
10
|
+
* the default — in that order. `false` turns throttling off.
|
|
11
|
+
*/
|
|
12
|
+
function resolveChatThrottleMs(options) {
|
|
13
|
+
if (options.throttle === false) return void 0;
|
|
14
|
+
return options.throttle ?? options.experimental_throttle ?? 50;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The throttle spelled under both option names, or neither name when it is off.
|
|
18
|
+
*
|
|
19
|
+
* The two names are not interchangeable across the peer range. `@ai-sdk/react`
|
|
20
|
+
* v3 only reads `experimental_throttle`; v4 renamed it to `throttle` and reads
|
|
21
|
+
* `throttle ?? experimental_throttle`. Our peer range allows both majors, so
|
|
22
|
+
* sending one name would silently do nothing on the other. Unknown option keys
|
|
23
|
+
* are ignored by both, so sending both names is safe.
|
|
24
|
+
*
|
|
25
|
+
* Turning throttling off omits both names rather than inventing a numeric
|
|
26
|
+
* value. Both majors also treat an explicit `0` as unthrottled, so callers that
|
|
27
|
+
* pass `0` keep that value under both spellings.
|
|
28
|
+
*/
|
|
29
|
+
function chatThrottleOptions(options) {
|
|
30
|
+
const ms = resolveChatThrottleMs(options);
|
|
31
|
+
if (ms === void 0) return {};
|
|
32
|
+
return {
|
|
33
|
+
experimental_throttle: ms,
|
|
34
|
+
throttle: ms
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
8
38
|
//#region src/chat/react.tsx
|
|
9
39
|
/**
|
|
10
40
|
* One-shot deprecation warnings (warns once per key per session).
|
|
@@ -186,7 +216,7 @@ function detectToolsRequiringConfirmation(tools) {
|
|
|
186
216
|
return Object.entries(tools).filter(([_name, tool]) => !tool.execute).map(([name]) => name);
|
|
187
217
|
}
|
|
188
218
|
function useAgentChat(options) {
|
|
189
|
-
const { agent, getInitialMessages, messages: optionsInitialMessages, onToolCall, onData, experimental_automaticToolResolution, tools, toolsRequiringConfirmation: manualToolsRequiringConfirmation, autoContinueAfterToolResult = true, autoSendAfterAllConfirmationsResolved = true, resume = true, cancelOnClientAbort = false, syncMessagesToServer = true, body: bodyOption, prepareSendMessagesRequest, ...rest } = options;
|
|
219
|
+
const { agent, getInitialMessages, messages: optionsInitialMessages, onToolCall, onData, experimental_automaticToolResolution, tools, toolsRequiringConfirmation: manualToolsRequiringConfirmation, autoContinueAfterToolResult = true, autoSendAfterAllConfirmationsResolved = true, resume = true, cancelOnClientAbort = false, syncMessagesToServer = true, body: bodyOption, prepareSendMessagesRequest, throttle, experimental_throttle, ...rest } = options;
|
|
190
220
|
if (manualToolsRequiringConfirmation) warnDeprecated("useAgentChat.toolsRequiringConfirmation", "The 'toolsRequiringConfirmation' option is deprecated. Use needsApproval on server-side tools instead. Will be removed in the next major version.");
|
|
191
221
|
if (experimental_automaticToolResolution) warnDeprecated("useAgentChat.experimental_automaticToolResolution", "The 'experimental_automaticToolResolution' option is deprecated. Use the onToolCall callback instead. Will be removed in the next major version.");
|
|
192
222
|
if (options.autoSendAfterAllConfirmationsResolved !== void 0) warnDeprecated("useAgentChat.autoSendAfterAllConfirmationsResolved", "The 'autoSendAfterAllConfirmationsResolved' option is deprecated. Use sendAutomaticallyWhen from AI SDK instead. Will be removed in the next major version.");
|
|
@@ -312,6 +342,10 @@ function useAgentChat(options) {
|
|
|
312
342
|
const customTransport = customTransportRef.current;
|
|
313
343
|
const useChatHelpers = useChat({
|
|
314
344
|
...rest,
|
|
345
|
+
...chatThrottleOptions({
|
|
346
|
+
experimental_throttle,
|
|
347
|
+
throttle
|
|
348
|
+
}),
|
|
315
349
|
onData,
|
|
316
350
|
messages: initialMessages,
|
|
317
351
|
transport: customTransport,
|
|
@@ -415,8 +449,6 @@ function useAgentChat(options) {
|
|
|
415
449
|
const isResolvingToolsRef = useRef(false);
|
|
416
450
|
const [toolResolutionTrigger, setToolResolutionTrigger] = useState(0);
|
|
417
451
|
const [clientToolResults, setClientToolResults] = useState(/* @__PURE__ */ new Map());
|
|
418
|
-
const messagesRef = useRef(chatMessages);
|
|
419
|
-
messagesRef.current = chatMessages;
|
|
420
452
|
const initialMessagesRef = useRef(initialMessages);
|
|
421
453
|
initialMessagesRef.current = initialMessages;
|
|
422
454
|
const seededInitialMessagesKeyRef = useRef(null);
|
|
@@ -436,7 +468,7 @@ function useAgentChat(options) {
|
|
|
436
468
|
]);
|
|
437
469
|
const localResponseMessageIdsRef = useRef(/* @__PURE__ */ new Map());
|
|
438
470
|
const protectedStreamingAssistantRef = useRef(null);
|
|
439
|
-
const preserveProtectedStreamingAssistant = useCallback((messages) => {
|
|
471
|
+
const preserveProtectedStreamingAssistant = useCallback((messages, currentMessages) => {
|
|
440
472
|
const protection = protectedStreamingAssistantRef.current;
|
|
441
473
|
if (!protection) return [...messages];
|
|
442
474
|
const protectedIndex = messages.findIndex((message) => message.id === protection.assistantId);
|
|
@@ -444,22 +476,20 @@ function useAgentChat(options) {
|
|
|
444
476
|
protectedStreamingAssistantRef.current = null;
|
|
445
477
|
return [...messages];
|
|
446
478
|
}
|
|
447
|
-
const protectedAssistant =
|
|
479
|
+
const protectedAssistant = currentMessages.find((message) => message.id === protection.assistantId) ?? messages.find((message) => message.id === protection.assistantId);
|
|
448
480
|
if (!protectedAssistant) return [...messages];
|
|
449
481
|
return [...messages.filter((message) => message.id !== protection.assistantId), protectedAssistant];
|
|
450
482
|
}, []);
|
|
451
483
|
const protectStreamingAssistantTail = useCallback(() => {
|
|
452
484
|
if (statusRef.current !== "streaming") return;
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
assistantId
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
if (!protection) return prevMessages;
|
|
462
|
-
return moveMessageToEnd(prevMessages, protection.assistantId);
|
|
485
|
+
setMessages((currentMessages) => {
|
|
486
|
+
const assistantInfo = findLastAssistantMessage(currentMessages);
|
|
487
|
+
if (!assistantInfo) return currentMessages;
|
|
488
|
+
if (protectedStreamingAssistantRef.current?.assistantId !== assistantInfo.message.id) protectedStreamingAssistantRef.current = {
|
|
489
|
+
assistantId: assistantInfo.message.id,
|
|
490
|
+
anchorMessageId: currentMessages[assistantInfo.index - 1]?.id ?? null
|
|
491
|
+
};
|
|
492
|
+
return moveMessageToEnd(currentMessages, assistantInfo.message.id);
|
|
463
493
|
});
|
|
464
494
|
}, [setMessages]);
|
|
465
495
|
const restoreProtectedStreamingAssistant = useCallback((assistantId) => {
|
|
@@ -740,17 +770,18 @@ function useAgentChat(options) {
|
|
|
740
770
|
case "cf_agent_chat_recovering":
|
|
741
771
|
setIsRecovering(Boolean(data.recovering));
|
|
742
772
|
break;
|
|
743
|
-
case "cf_agent_chat_messages":
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
773
|
+
case "cf_agent_chat_messages":
|
|
774
|
+
setMessages((currentMessages) => {
|
|
775
|
+
let next = preserveProtectedStreamingAssistant(data.messages, currentMessages);
|
|
776
|
+
const observed = streamStateRef.current;
|
|
777
|
+
if (observed.status === "observing" && observed.accumulator.parts.length > 0) {
|
|
778
|
+
const snapshotIdx = next.findIndex((m) => m.id === observed.accumulator.messageId);
|
|
779
|
+
const snapshotParts = snapshotIdx >= 0 ? next[snapshotIdx].parts.length : 0;
|
|
780
|
+
if (observed.accumulator.parts.length >= snapshotParts) next = observed.accumulator.mergeInto(next);
|
|
781
|
+
}
|
|
782
|
+
return next;
|
|
783
|
+
});
|
|
752
784
|
break;
|
|
753
|
-
}
|
|
754
785
|
case "cf_agent_message_updated":
|
|
755
786
|
setMessages((prevMessages) => {
|
|
756
787
|
const updatedMessage = data.message;
|
|
@@ -818,21 +849,21 @@ function useAgentChat(options) {
|
|
|
818
849
|
if (data.body?.trim()) try {
|
|
819
850
|
const chunkData = JSON.parse(data.body);
|
|
820
851
|
if (chunkData.type === "start" && typeof chunkData.messageId === "string") {
|
|
821
|
-
|
|
852
|
+
const messageId = chunkData.messageId;
|
|
853
|
+
localResponseIds.set(data.id, messageId);
|
|
822
854
|
if (!data.continuation) {
|
|
823
|
-
if (protectedStreamingAssistantRef.current?.assistantId !==
|
|
824
|
-
const
|
|
825
|
-
const idx = msgs.findIndex((m) => m.id === chunkData.messageId);
|
|
826
|
-
const anchorMessageId = idx >= 0 ? msgs[idx - 1]?.id ?? null : msgs[msgs.length - 1]?.id ?? null;
|
|
855
|
+
if (protectedStreamingAssistantRef.current?.assistantId !== messageId) setMessages((currentMessages) => {
|
|
856
|
+
const idx = currentMessages.findIndex((message) => message.id === messageId);
|
|
827
857
|
protectedStreamingAssistantRef.current = {
|
|
828
|
-
assistantId:
|
|
829
|
-
anchorMessageId
|
|
858
|
+
assistantId: messageId,
|
|
859
|
+
anchorMessageId: idx >= 0 ? currentMessages[idx - 1]?.id ?? null : currentMessages[currentMessages.length - 1]?.id ?? null
|
|
830
860
|
};
|
|
831
|
-
|
|
861
|
+
return currentMessages;
|
|
862
|
+
});
|
|
832
863
|
}
|
|
833
864
|
if (data.replay && !data.continuation && !resumingToolContinuationRef.current && observedToolContinuationRequestIdRef.current !== data.id) {
|
|
834
865
|
pendingReplayResumeRequestIdsRef.current.delete(data.id);
|
|
835
|
-
resetMatchingHydratedAssistantForReplay(
|
|
866
|
+
resetMatchingHydratedAssistantForReplay(messageId);
|
|
836
867
|
}
|
|
837
868
|
}
|
|
838
869
|
} catch {}
|
|
@@ -892,8 +923,7 @@ function useAgentChat(options) {
|
|
|
892
923
|
error: data.error,
|
|
893
924
|
replay: data.replay,
|
|
894
925
|
replayComplete: data.replayComplete,
|
|
895
|
-
continuation: data.continuation
|
|
896
|
-
currentMessages: data.continuation ? messagesRef.current : void 0
|
|
926
|
+
continuation: data.continuation
|
|
897
927
|
});
|
|
898
928
|
streamStateRef.current = result.state;
|
|
899
929
|
if (result.messagesUpdate) setMessages(result.messagesUpdate);
|
|
@@ -1013,13 +1043,13 @@ function useAgentChat(options) {
|
|
|
1013
1043
|
const addToolApprovalResponseAndNotifyServer = (args) => {
|
|
1014
1044
|
const { id: approvalId, approved } = args;
|
|
1015
1045
|
let toolCallId;
|
|
1016
|
-
|
|
1017
|
-
for (const part of msg.parts) if ("toolCallId" in part && "approval" in part && part.approval?.id === approvalId) {
|
|
1046
|
+
setMessages((currentMessages) => {
|
|
1047
|
+
for (const msg of currentMessages) for (const part of msg.parts) if ("toolCallId" in part && "approval" in part && part.approval?.id === approvalId) {
|
|
1018
1048
|
toolCallId = part.toolCallId;
|
|
1019
|
-
|
|
1049
|
+
return currentMessages;
|
|
1020
1050
|
}
|
|
1021
|
-
|
|
1022
|
-
}
|
|
1051
|
+
return currentMessages;
|
|
1052
|
+
});
|
|
1023
1053
|
if (toolCallId) sendToolApprovalToServer(toolCallId, approved);
|
|
1024
1054
|
else console.warn(`[useAgentChat] addToolApprovalResponse: Could not find toolCallId for approval ID "${approvalId}". Server will not be notified, which may cause duplicate messages.`);
|
|
1025
1055
|
addToolApprovalResponse(args);
|
|
@@ -1118,15 +1148,15 @@ function useAgentChat(options) {
|
|
|
1118
1148
|
agent.send(JSON.stringify({ type: "cf_agent_chat_clear" }));
|
|
1119
1149
|
},
|
|
1120
1150
|
setMessages: (messagesOrUpdater) => {
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
})
|
|
1151
|
+
setMessages((currentMessages) => {
|
|
1152
|
+
const resolvedMessages = typeof messagesOrUpdater === "function" ? messagesOrUpdater(currentMessages) : messagesOrUpdater;
|
|
1153
|
+
if (resolvedMessages.length === 0) markInitialMessagesSeeded();
|
|
1154
|
+
if (syncMessagesToServer) agent.send(JSON.stringify({
|
|
1155
|
+
messages: resolvedMessages,
|
|
1156
|
+
type: "cf_agent_chat_messages"
|
|
1157
|
+
}));
|
|
1158
|
+
return resolvedMessages;
|
|
1159
|
+
});
|
|
1130
1160
|
}
|
|
1131
1161
|
};
|
|
1132
1162
|
}
|