@economic/agents-react 1.6.4 → 1.6.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/index.d.mts +2 -0
- package/dist/index.mjs +3 -3
- package/dist/util-tBvVuxIJ.mjs +13 -0
- package/dist/v1.d.mts +2 -0
- package/dist/v1.mjs +3 -3
- package/package.json +3 -3
- package/dist/util-CPk3RN3P.mjs +0 -13
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,4 +1,4 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { n as visibleChatMessages, t as getTokenArgs } from "./util-tBvVuxIJ.mjs";
|
|
2
2
|
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
3
3
|
import { useAgent as useAgent$1 } from "agents/react";
|
|
4
4
|
import { getToolApproval, getToolCallId, getToolPartState, useAgentChat } from "@cloudflare/ai-chat/react";
|
|
@@ -204,7 +204,7 @@ function useAgent(options) {
|
|
|
204
204
|
//#endregion
|
|
205
205
|
//#region src/useChat.ts
|
|
206
206
|
function useChat(options) {
|
|
207
|
-
const { toolContext, welcomeMessage, ...agentOptions } = options;
|
|
207
|
+
const { toolContext, welcomeMessage, showInternalMessages = false, ...agentOptions } = options;
|
|
208
208
|
const { agent, status } = useAgent({
|
|
209
209
|
...agentOptions,
|
|
210
210
|
enabled: agentOptions.enabled ?? !!agentOptions.name
|
|
@@ -247,7 +247,7 @@ function useChat(options) {
|
|
|
247
247
|
agent,
|
|
248
248
|
chat: {
|
|
249
249
|
...chat,
|
|
250
|
-
messages: chat.messages
|
|
250
|
+
messages: visibleChatMessages(chat.messages, showInternalMessages)
|
|
251
251
|
},
|
|
252
252
|
submitMessageFeedback,
|
|
253
253
|
getMessageFeedback
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { n as visibleChatMessages } from "./util-tBvVuxIJ.mjs";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { useAgent } from "agents/react";
|
|
4
4
|
import { useAgentChat } from "@cloudflare/ai-chat/react";
|
|
@@ -17,7 +17,7 @@ function buildAgentHttpBaseUrl(options) {
|
|
|
17
17
|
return `${protocol}://${hostPart}${pathname}`;
|
|
18
18
|
}
|
|
19
19
|
function useAIChatAgent(options) {
|
|
20
|
-
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;
|
|
21
21
|
const [connectionStatus, setConnectionStatus] = React.useState("connecting");
|
|
22
22
|
const updateConnectionStatus = React.useCallback((status) => {
|
|
23
23
|
setConnectionStatus(status);
|
|
@@ -116,7 +116,7 @@ function useAIChatAgent(options) {
|
|
|
116
116
|
agent,
|
|
117
117
|
chat: {
|
|
118
118
|
...chat,
|
|
119
|
-
messages: chat.messages
|
|
119
|
+
messages: visibleChatMessages(chat.messages, showInternalMessages)
|
|
120
120
|
},
|
|
121
121
|
connectionStatus
|
|
122
122
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@economic/agents-react",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@ai-sdk/react": "^3.0.182",
|
|
24
|
-
"@cloudflare/ai-chat": "^0.
|
|
25
|
-
"agents": "^0.
|
|
24
|
+
"@cloudflare/ai-chat": "^0.11.0",
|
|
25
|
+
"agents": "^0.22.0",
|
|
26
26
|
"ai": "^6.0.180",
|
|
27
27
|
"zod": "^4.4.3"
|
|
28
28
|
},
|
package/dist/util-CPk3RN3P.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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 isPublicChatMessage(message) {
|
|
10
|
-
return !message.id.startsWith("compaction_");
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { isPublicChatMessage as n, getTokenArgs as t };
|