@economic/agents-react 1.1.0 → 1.1.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.mts +51 -5823
- package/dist/index.mjs +19 -18
- package/package.json +9 -11
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useAgent as useAgent$1 } from "agents/react";
|
|
2
2
|
import { useAgentChat } from "@cloudflare/ai-chat/react";
|
|
3
|
-
import
|
|
3
|
+
import { useState } from "react";
|
|
4
4
|
//#region src/util.ts
|
|
5
5
|
function getTokenArgs(authToken) {
|
|
6
6
|
if (!authToken) return {};
|
|
@@ -12,28 +12,30 @@ function getTokenArgs(authToken) {
|
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/useAgent.ts
|
|
14
14
|
function useAgent(options) {
|
|
15
|
-
const { host, agentName, id, enabled, sub, authToken } = options;
|
|
15
|
+
const { host, agentName, userId, id, enabled, sub, authToken, onError, onOpen, onClose } = options;
|
|
16
16
|
return useAgent$1({
|
|
17
17
|
enabled,
|
|
18
18
|
host,
|
|
19
19
|
agent: agentName,
|
|
20
|
-
name: id,
|
|
20
|
+
name: userId ? `${userId}:${id}` : id,
|
|
21
21
|
sub,
|
|
22
|
+
onOpen,
|
|
23
|
+
onClose,
|
|
24
|
+
onError,
|
|
22
25
|
...getTokenArgs(authToken)
|
|
23
26
|
});
|
|
24
27
|
}
|
|
25
28
|
//#endregion
|
|
26
29
|
//#region src/useAssistant.ts
|
|
27
30
|
function useAssistant(options) {
|
|
28
|
-
const { host,
|
|
29
|
-
const
|
|
31
|
+
const { host, agentName, userId, authToken, toolContext, ...agentOptions } = options;
|
|
32
|
+
const [chatId, setChatId] = useState();
|
|
33
|
+
const assistant = useAgent({
|
|
30
34
|
host,
|
|
31
|
-
agentName
|
|
35
|
+
agentName,
|
|
32
36
|
id: userId,
|
|
33
37
|
authToken
|
|
34
|
-
};
|
|
35
|
-
const [chatId, setChatId] = React.useState(initialChatId);
|
|
36
|
-
const assistant = useAgent(config);
|
|
38
|
+
});
|
|
37
39
|
const getConversations = async () => {
|
|
38
40
|
return await assistant.call("getConversations");
|
|
39
41
|
};
|
|
@@ -52,12 +54,16 @@ function useAssistant(options) {
|
|
|
52
54
|
await getConversations();
|
|
53
55
|
};
|
|
54
56
|
const agent = useAgent({
|
|
55
|
-
...config,
|
|
56
57
|
enabled: !!chatId,
|
|
58
|
+
host,
|
|
59
|
+
agentName,
|
|
60
|
+
id: userId,
|
|
61
|
+
authToken,
|
|
57
62
|
sub: chatId ? [{
|
|
58
63
|
agent: assistant.state?.subAgentName ?? "",
|
|
59
64
|
name: chatId
|
|
60
|
-
}] : void 0
|
|
65
|
+
}] : void 0,
|
|
66
|
+
...agentOptions
|
|
61
67
|
});
|
|
62
68
|
const isChatReady = !!chatId && agent.state?.status === "connected";
|
|
63
69
|
const chat = useAgentChat({
|
|
@@ -79,13 +85,8 @@ function useAssistant(options) {
|
|
|
79
85
|
//#endregion
|
|
80
86
|
//#region src/useChatAgent.ts
|
|
81
87
|
function useChatAgent(options) {
|
|
82
|
-
const {
|
|
83
|
-
const agent = useAgent(
|
|
84
|
-
host,
|
|
85
|
-
agentName,
|
|
86
|
-
id,
|
|
87
|
-
authToken
|
|
88
|
-
});
|
|
88
|
+
const { toolContext, ...agentOptions } = options;
|
|
89
|
+
const agent = useAgent(agentOptions);
|
|
89
90
|
const chat = useAgentChat({
|
|
90
91
|
agent,
|
|
91
92
|
body: toolContext ?? {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@economic/agents-react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -18,8 +18,14 @@
|
|
|
18
18
|
"typecheck": "tsc --noEmit",
|
|
19
19
|
"prepublishOnly": "npm run build"
|
|
20
20
|
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@ai-sdk/react": "^3.0.182",
|
|
23
|
+
"@cloudflare/ai-chat": ">=0.7.2 <1.0.0",
|
|
24
|
+
"agents": ">=0.13.3 <1.0.0",
|
|
25
|
+
"ai": "^6.0.180",
|
|
26
|
+
"zod": "^4.4.3"
|
|
27
|
+
},
|
|
21
28
|
"devDependencies": {
|
|
22
|
-
"@cloudflare/ai-chat": "^0.7.2",
|
|
23
29
|
"@cloudflare/workers-types": "^4.20260527.1",
|
|
24
30
|
"@types/node": "^25.6.0",
|
|
25
31
|
"@typescript/native-preview": "7.0.0-dev.20260412.1",
|
|
@@ -28,17 +34,9 @@
|
|
|
28
34
|
"vitest": "^4.1.4"
|
|
29
35
|
},
|
|
30
36
|
"peerDependencies": {
|
|
31
|
-
"@cloudflare/ai-chat": ">=0.7.2 <1.0.0",
|
|
32
|
-
"agents": ">=0.13.3 <1.0.0",
|
|
33
37
|
"react": "^19"
|
|
34
38
|
},
|
|
35
39
|
"inlinedDependencies": {
|
|
36
|
-
"
|
|
37
|
-
"@ai-sdk/provider-utils": "4.0.27",
|
|
38
|
-
"@ai-sdk/react": "3.0.182",
|
|
39
|
-
"@standard-schema/spec": "1.1.0",
|
|
40
|
-
"ai": "6.0.180",
|
|
41
|
-
"partysocket": "1.1.19",
|
|
42
|
-
"zod": "4.4.3"
|
|
40
|
+
"partysocket": "1.1.19"
|
|
43
41
|
}
|
|
44
42
|
}
|