@cloudflare/ai-chat 0.5.1 → 0.5.2
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/index.d.ts +2 -20
- package/dist/index.js +20 -207
- package/dist/index.js.map +1 -1
- package/dist/react.js +17 -4
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -521,11 +521,12 @@ function useAgentChat(options) {
|
|
|
521
521
|
const resolvedInitialMessagesCacheKey = agentUrl ? `${agentUrl.origin}${agentUrl.pathname}|${agentIdentityKey}` : null;
|
|
522
522
|
const initialMessagesCacheKey = agentIdentityKey;
|
|
523
523
|
const stableChatIdRef = useRef(null);
|
|
524
|
-
const
|
|
524
|
+
const previousAgentRef = useRef(null);
|
|
525
525
|
const fallbackChatId = agentIdentityKey;
|
|
526
|
-
if (stableChatIdRef.current === null
|
|
527
|
-
else if (
|
|
528
|
-
|
|
526
|
+
if (stableChatIdRef.current === null) stableChatIdRef.current = resolvedInitialMessagesCacheKey ?? fallbackChatId;
|
|
527
|
+
else if (previousAgentRef.current !== agent) stableChatIdRef.current = resolvedInitialMessagesCacheKey ?? fallbackChatId;
|
|
528
|
+
else if (resolvedInitialMessagesCacheKey && stableChatIdRef.current === fallbackChatId) stableChatIdRef.current = resolvedInitialMessagesCacheKey;
|
|
529
|
+
previousAgentRef.current = agent;
|
|
529
530
|
const agentRef = useRef(agent);
|
|
530
531
|
agentRef.current = agent;
|
|
531
532
|
async function defaultGetInitialMessagesFetch({ url }) {
|
|
@@ -1100,8 +1101,20 @@ function useAgentChat(options) {
|
|
|
1100
1101
|
isToolContinuation,
|
|
1101
1102
|
sendMessage: sendMessageWithStreamingProtection,
|
|
1102
1103
|
stop: stopWithToolContinuationAbort,
|
|
1104
|
+
/**
|
|
1105
|
+
* Provide output for a tool call. Use this for tools that require user interaction
|
|
1106
|
+
* or client-side execution.
|
|
1107
|
+
*/
|
|
1103
1108
|
addToolOutput,
|
|
1109
|
+
/**
|
|
1110
|
+
* @deprecated Use `addToolOutput` instead.
|
|
1111
|
+
*/
|
|
1104
1112
|
addToolResult: addToolResultAndSendMessage,
|
|
1113
|
+
/**
|
|
1114
|
+
* Respond to a tool approval request. Use this for tools with `needsApproval`.
|
|
1115
|
+
* This wrapper notifies the server before updating local state, preventing
|
|
1116
|
+
* duplicate messages when sendMessage() is called afterward.
|
|
1117
|
+
*/
|
|
1105
1118
|
addToolApprovalResponse: addToolApprovalResponseAndNotifyServer,
|
|
1106
1119
|
clearHistory: () => {
|
|
1107
1120
|
resetLocalChatState();
|