@economic/agents-react 1.6.3 → 1.6.5
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.mts +2 -0
- package/dist/index.mjs +6 -11
- package/dist/util-tBvVuxIJ.mjs +13 -0
- package/dist/v1.d.mts +2 -0
- package/dist/v1.mjs +6 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -69,6 +69,8 @@ interface UseChatOptions<ToolContext extends Record<string, unknown>> extends Us
|
|
|
69
69
|
getInitialMessages?: undefined | null;
|
|
70
70
|
toolContext?: ToolContext;
|
|
71
71
|
welcomeMessage?: string;
|
|
72
|
+
/** Include internal SDK messages such as compaction summaries. Defaults to false. */
|
|
73
|
+
showInternalMessages?: boolean;
|
|
72
74
|
}
|
|
73
75
|
declare function useChat<ToolContext extends Record<string, unknown>>(options: UseChatOptions<ToolContext>): UseChatReturn;
|
|
74
76
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
+
import { n as visibleChatMessages, t as getTokenArgs } from "./util-tBvVuxIJ.mjs";
|
|
1
2
|
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
3
|
import { useAgent as useAgent$1 } from "agents/react";
|
|
3
4
|
import { getToolApproval, getToolCallId, getToolPartState, useAgentChat } from "@cloudflare/ai-chat/react";
|
|
4
|
-
//#region src/util.ts
|
|
5
|
-
function getTokenArgs(authToken) {
|
|
6
|
-
if (!authToken) return {};
|
|
7
|
-
return {
|
|
8
|
-
headers: { Authorization: `Bearer ${authToken}` },
|
|
9
|
-
protocols: ["bearer", authToken]
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
5
|
//#region src/useAgent.ts
|
|
14
6
|
function getAgentConnectionStatus(state, connectionId) {
|
|
15
7
|
return state.connectionId === connectionId ? state.status : "connecting";
|
|
@@ -212,7 +204,7 @@ function useAgent(options) {
|
|
|
212
204
|
//#endregion
|
|
213
205
|
//#region src/useChat.ts
|
|
214
206
|
function useChat(options) {
|
|
215
|
-
const { toolContext, welcomeMessage, ...agentOptions } = options;
|
|
207
|
+
const { toolContext, welcomeMessage, showInternalMessages = false, ...agentOptions } = options;
|
|
216
208
|
const { agent, status } = useAgent({
|
|
217
209
|
...agentOptions,
|
|
218
210
|
enabled: agentOptions.enabled ?? !!agentOptions.name
|
|
@@ -253,7 +245,10 @@ function useChat(options) {
|
|
|
253
245
|
return {
|
|
254
246
|
status,
|
|
255
247
|
agent,
|
|
256
|
-
chat
|
|
248
|
+
chat: {
|
|
249
|
+
...chat,
|
|
250
|
+
messages: visibleChatMessages(chat.messages, showInternalMessages)
|
|
251
|
+
},
|
|
257
252
|
submitMessageFeedback,
|
|
258
253
|
getMessageFeedback
|
|
259
254
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/util.ts
|
|
2
|
+
function getTokenArgs(authToken) {
|
|
3
|
+
if (!authToken) return {};
|
|
4
|
+
return {
|
|
5
|
+
headers: { Authorization: `Bearer ${authToken}` },
|
|
6
|
+
protocols: ["bearer", authToken]
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function visibleChatMessages(messages, showInternalMessages = false) {
|
|
10
|
+
return showInternalMessages ? messages : messages.filter((message) => !message.id.startsWith("compaction_"));
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { visibleChatMessages as n, getTokenArgs as t };
|
package/dist/v1.d.mts
CHANGED
|
@@ -15,6 +15,8 @@ interface UseAIChatAgentOptions {
|
|
|
15
15
|
toolContext?: Record<string, unknown>;
|
|
16
16
|
connectionParams?: Record<string, string>;
|
|
17
17
|
welcomeMessage?: string;
|
|
18
|
+
/** Include internal SDK messages such as compaction summaries. Defaults to false. */
|
|
19
|
+
showInternalMessages?: boolean;
|
|
18
20
|
onConnectionStatusChange?: (status: AgentConnectionStatus) => void;
|
|
19
21
|
onOpen?: () => void;
|
|
20
22
|
onClose?: (event: CloseEvent) => void;
|
package/dist/v1.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { n as visibleChatMessages } from "./util-tBvVuxIJ.mjs";
|
|
1
2
|
import React from "react";
|
|
2
3
|
import { useAgent } from "agents/react";
|
|
3
4
|
import { useAgentChat } from "@cloudflare/ai-chat/react";
|
|
@@ -16,7 +17,7 @@ function buildAgentHttpBaseUrl(options) {
|
|
|
16
17
|
return `${protocol}://${hostPart}${pathname}`;
|
|
17
18
|
}
|
|
18
19
|
function useAIChatAgent(options) {
|
|
19
|
-
const { agent: agentName, host, basePath, chatId, userId, subAgentName, authToken, toolContext, connectionParams, welcomeMessage, onConnectionStatusChange, onOpen: onOpenProp, onClose: onCloseProp, onError: onErrorProp } = options;
|
|
20
|
+
const { agent: agentName, host, basePath, chatId, userId, subAgentName, authToken, toolContext, connectionParams, welcomeMessage, showInternalMessages = false, onConnectionStatusChange, onOpen: onOpenProp, onClose: onCloseProp, onError: onErrorProp } = options;
|
|
20
21
|
const [connectionStatus, setConnectionStatus] = React.useState("connecting");
|
|
21
22
|
const updateConnectionStatus = React.useCallback((status) => {
|
|
22
23
|
setConnectionStatus(status);
|
|
@@ -113,7 +114,10 @@ function useAIChatAgent(options) {
|
|
|
113
114
|
]);
|
|
114
115
|
return {
|
|
115
116
|
agent,
|
|
116
|
-
chat
|
|
117
|
+
chat: {
|
|
118
|
+
...chat,
|
|
119
|
+
messages: visibleChatMessages(chat.messages, showInternalMessages)
|
|
120
|
+
},
|
|
117
121
|
connectionStatus
|
|
118
122
|
};
|
|
119
123
|
}
|