@economic/agents-react 1.6.6 → 2.0.0-alpha.38232858664.1.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 -1
- package/dist/index.d.mts +13 -6
- package/dist/index.mjs +3 -0
- package/dist/v1.d.mts +4 -6
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -212,4 +212,4 @@ The package also exports the handler types `AssistantActions`, `GetChatsHandler`
|
|
|
212
212
|
|
|
213
213
|
## Authentication
|
|
214
214
|
|
|
215
|
-
Pass a JWT as `authToken`. It is sent both as an `Authorization: Bearer …` header and as a WebSocket subprotocol (`["bearer", token]`), matching the server-side [`
|
|
215
|
+
Pass a JWT as `authToken`. It is sent both as an `Authorization: Bearer …` header and as a WebSocket subprotocol (`["bearer", token]`), matching the server-side [`getAuthenticator(env)`](../agents/README.md#authentication). When verification fails, the connection status becomes `"unauthorized"`.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useAgent as useAgent$1 } from "agents/react";
|
|
2
2
|
import { getToolApproval, getToolCallId, getToolPartState, useAgentChat } from "@cloudflare/ai-chat/react";
|
|
3
|
-
|
|
4
3
|
//#region src/types.d.ts
|
|
5
4
|
type _CfAgent = ReturnType<typeof useAgent$1>;
|
|
6
5
|
type Agent = Omit<_CfAgent, "call"> & {
|
|
@@ -10,7 +9,8 @@ type Chat = ReturnType<typeof useAgentChat>;
|
|
|
10
9
|
type AgentConnectionStatus = "connecting" | "reconnecting" | "connected" | "disconnected" | "unauthorized" | "error";
|
|
11
10
|
type AgentConnectionType = "agent" | "chat" | "assistant";
|
|
12
11
|
type ChatSummary = {
|
|
13
|
-
name: string;
|
|
12
|
+
name: string;
|
|
13
|
+
/** True when this entry only represents the active, unregistered chat facet. */
|
|
14
14
|
isTemporary?: boolean;
|
|
15
15
|
title?: string;
|
|
16
16
|
summary?: string;
|
|
@@ -27,6 +27,12 @@ type MessageFeedback = {
|
|
|
27
27
|
};
|
|
28
28
|
type MessageFeedbackHandler = (messageId: string, rating: number, comment?: string) => Promise<void>;
|
|
29
29
|
type GetMessageFeedbackHandler = () => Promise<Record<string, MessageFeedback>>;
|
|
30
|
+
type InvocableSkill = {
|
|
31
|
+
command: string;
|
|
32
|
+
name: string;
|
|
33
|
+
description: string;
|
|
34
|
+
};
|
|
35
|
+
type GetInvocableSkillsHandler = () => Promise<InvocableSkill[]>;
|
|
30
36
|
type GetChatsHandler = () => Promise<ChatSummary[]>;
|
|
31
37
|
type CreateChatHandler = () => Promise<string>;
|
|
32
38
|
type OpenChatHandler = (chatId: string) => void;
|
|
@@ -55,13 +61,14 @@ interface UseAgentOptions {
|
|
|
55
61
|
onError?: (event: ErrorEvent) => void;
|
|
56
62
|
onMessage?: (event: MessageEvent) => void;
|
|
57
63
|
}
|
|
58
|
-
declare function useAgent(options: UseAgentOptions): UseAgentReturn;
|
|
64
|
+
export declare function useAgent(options: UseAgentOptions): UseAgentReturn;
|
|
59
65
|
//#endregion
|
|
60
66
|
//#region src/useChat.d.ts
|
|
61
67
|
interface UseChatReturn {
|
|
62
68
|
status: AgentConnectionStatus;
|
|
63
69
|
agent: Agent;
|
|
64
70
|
chat: Chat;
|
|
71
|
+
getInvocableSkills: GetInvocableSkillsHandler;
|
|
65
72
|
submitMessageFeedback: MessageFeedbackHandler;
|
|
66
73
|
getMessageFeedback: GetMessageFeedbackHandler;
|
|
67
74
|
}
|
|
@@ -72,7 +79,7 @@ interface UseChatOptions<ToolContext extends Record<string, unknown>> extends Us
|
|
|
72
79
|
/** Include internal SDK messages such as compaction summaries. Defaults to false. */
|
|
73
80
|
showInternalMessages?: boolean;
|
|
74
81
|
}
|
|
75
|
-
declare function useChat<ToolContext extends Record<string, unknown>>(options: UseChatOptions<ToolContext>): UseChatReturn;
|
|
82
|
+
export declare function useChat<ToolContext extends Record<string, unknown>>(options: UseChatOptions<ToolContext>): UseChatReturn;
|
|
76
83
|
//#endregion
|
|
77
84
|
//#region src/useAssistant.d.ts
|
|
78
85
|
interface Assistant {
|
|
@@ -93,6 +100,6 @@ interface UseAssistantReturn {
|
|
|
93
100
|
interface UseAssistantOptions<ToolContext extends Record<string, unknown> = Record<string, unknown>> extends Omit<UseChatOptions<ToolContext>, "actorId" | "getInitialMessages"> {
|
|
94
101
|
initialChatId?: string;
|
|
95
102
|
}
|
|
96
|
-
declare function useAssistant<ToolContext extends Record<string, unknown>>(options: UseAssistantOptions<ToolContext>): UseAssistantReturn;
|
|
103
|
+
export declare function useAssistant<ToolContext extends Record<string, unknown>>(options: UseAssistantOptions<ToolContext>): UseAssistantReturn;
|
|
97
104
|
//#endregion
|
|
98
|
-
export { type Agent, type AgentConnectionStatus, type AgentConnectionType, type Assistant, type Chat, type ChatSummary, type CreateChatHandler, type DeleteChatHandler, type GetChatsHandler, type GetMessageFeedbackHandler, type MessageFeedback, type MessageFeedbackHandler, type OpenChatHandler, type RenameChatHandler, type UseAgentReturn, type UseAssistantReturn, type UseChatReturn, getToolApproval, getToolCallId, getToolPartState
|
|
105
|
+
export { type Agent, type AgentConnectionStatus, type AgentConnectionType, type Assistant, type Chat, type ChatSummary, type CreateChatHandler, type DeleteChatHandler, type GetChatsHandler, type GetInvocableSkillsHandler, type GetMessageFeedbackHandler, type InvocableSkill, type MessageFeedback, type MessageFeedbackHandler, type OpenChatHandler, type RenameChatHandler, type UseAgentReturn, type UseAssistantReturn, type UseChatReturn, getToolApproval, getToolCallId, getToolPartState };
|
package/dist/index.mjs
CHANGED
|
@@ -212,8 +212,10 @@ function useChat(options) {
|
|
|
212
212
|
const chat = useAgentChat({
|
|
213
213
|
agent,
|
|
214
214
|
body: toolContext ?? {},
|
|
215
|
+
headers: agentOptions.authToken ? { Authorization: `Bearer ${agentOptions.authToken}` } : void 0,
|
|
215
216
|
getInitialMessages: !!agentOptions.name && status === "connected" ? void 0 : null
|
|
216
217
|
});
|
|
218
|
+
const getInvocableSkills = useCallback(async () => await agent.call("getInvocableSkills"), [agent]);
|
|
217
219
|
const hasSentWelcome = useRef(false);
|
|
218
220
|
useEffect(() => {
|
|
219
221
|
if (welcomeMessage && status === "connected" && chat.messages.length === 0 && !hasSentWelcome.current) {
|
|
@@ -249,6 +251,7 @@ function useChat(options) {
|
|
|
249
251
|
...chat,
|
|
250
252
|
messages: visibleChatMessages(chat.messages, showInternalMessages)
|
|
251
253
|
},
|
|
254
|
+
getInvocableSkills,
|
|
252
255
|
submitMessageFeedback,
|
|
253
256
|
getMessageFeedback
|
|
254
257
|
};
|
package/dist/v1.d.mts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { useAgent } from "agents/react";
|
|
2
2
|
import { useAgentChat } from "@cloudflare/ai-chat/react";
|
|
3
|
-
|
|
4
3
|
//#region src/v1/index.d.ts
|
|
5
|
-
type AgentConnectionStatus = "connecting" | "connected" | "disconnected" | "unauthorized";
|
|
6
|
-
interface UseAIChatAgentOptions {
|
|
4
|
+
export type AgentConnectionStatus = "connecting" | "connected" | "disconnected" | "unauthorized";
|
|
5
|
+
export interface UseAIChatAgentOptions {
|
|
7
6
|
agent: string;
|
|
8
7
|
host: string;
|
|
9
8
|
basePath?: string;
|
|
@@ -27,6 +26,5 @@ type UseAIChatAgentResult = {
|
|
|
27
26
|
chat: ReturnType<typeof useAgentChat>;
|
|
28
27
|
connectionStatus: AgentConnectionStatus;
|
|
29
28
|
};
|
|
30
|
-
declare function useAIChatAgent(options: UseAIChatAgentOptions): UseAIChatAgentResult;
|
|
31
|
-
//#endregion
|
|
32
|
-
export { AgentConnectionStatus, UseAIChatAgentOptions, useAIChatAgent };
|
|
29
|
+
export declare function useAIChatAgent(options: UseAIChatAgentOptions): UseAIChatAgentResult;
|
|
30
|
+
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@economic/agents-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.0.0-alpha.38232858664.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -20,18 +20,18 @@
|
|
|
20
20
|
"prepublishOnly": "npm run build"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@ai-sdk/react": "^
|
|
24
|
-
"@cloudflare/ai-chat": "^0.
|
|
25
|
-
"agents": "^0.
|
|
26
|
-
"ai": "^
|
|
27
|
-
"zod": "^4.
|
|
23
|
+
"@ai-sdk/react": "^4.0.140",
|
|
24
|
+
"@cloudflare/ai-chat": "^0.12.1",
|
|
25
|
+
"agents": "^0.28.0",
|
|
26
|
+
"ai": "^7.0.137",
|
|
27
|
+
"zod": "^4.6.5"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@cloudflare/workers-types": "^
|
|
31
|
-
"@types/node": "^
|
|
32
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
33
|
-
"tsdown": "^0.
|
|
34
|
-
"typescript": "^
|
|
30
|
+
"@cloudflare/workers-types": "^5.20261009.1",
|
|
31
|
+
"@types/node": "^26.6.4",
|
|
32
|
+
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
33
|
+
"tsdown": "^0.23.0",
|
|
34
|
+
"typescript": "^7.0.2",
|
|
35
35
|
"vitest": "^4.1.4"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|