@economic/agents-react 1.3.7 → 1.4.1
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 +1 -1
- package/dist/index.mjs +28 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -163,7 +163,7 @@ All hooks share these connection options (`useAssistant` omits `actorId`):
|
|
|
163
163
|
## Types
|
|
164
164
|
|
|
165
165
|
```ts
|
|
166
|
-
type AgentConnectionStatus = "connecting" | "connected" | "disconnected" | "unauthorized";
|
|
166
|
+
type AgentConnectionStatus = "connecting" | "connected" | "disconnected" | "unauthorized" | "error";
|
|
167
167
|
type AgentConnectionType = "agent" | "chat" | "assistant";
|
|
168
168
|
|
|
169
169
|
type AgentConnectionState = {
|
package/dist/index.d.mts
CHANGED
|
@@ -7,7 +7,7 @@ type Agent = Omit<_CfAgent, "call"> & {
|
|
|
7
7
|
call<T = unknown>(method: string, args?: unknown[], options?: unknown): Promise<T>;
|
|
8
8
|
};
|
|
9
9
|
type Chat = ReturnType<typeof useAgentChat>;
|
|
10
|
-
type AgentConnectionStatus = "connecting" | "connected" | "disconnected" | "unauthorized";
|
|
10
|
+
type AgentConnectionStatus = "connecting" | "connected" | "disconnected" | "unauthorized" | "error";
|
|
11
11
|
type AgentConnectionType = "agent" | "chat" | "assistant";
|
|
12
12
|
type ChatSummary = {
|
|
13
13
|
name: string;
|
package/dist/index.mjs
CHANGED
|
@@ -11,6 +11,24 @@ function getTokenArgs(authToken) {
|
|
|
11
11
|
}
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/useAgent.ts
|
|
14
|
+
function getCloseReason(code) {
|
|
15
|
+
return {
|
|
16
|
+
1e3: "normal-closure",
|
|
17
|
+
1001: "going-away",
|
|
18
|
+
1002: "protocol-error",
|
|
19
|
+
1003: "unsupported-data",
|
|
20
|
+
1005: "no-status-received",
|
|
21
|
+
1006: "abnormal-closure",
|
|
22
|
+
1007: "invalid-frame-payload-data",
|
|
23
|
+
1008: "policy-violation",
|
|
24
|
+
1009: "message-too-big",
|
|
25
|
+
1010: "missing-extension",
|
|
26
|
+
1011: "internal-error",
|
|
27
|
+
1012: "service-restart",
|
|
28
|
+
1013: "try-again-later",
|
|
29
|
+
1015: "tls-handshake-failure"
|
|
30
|
+
}[code] ?? "unknown";
|
|
31
|
+
}
|
|
14
32
|
function useAgent(options) {
|
|
15
33
|
const { enabled, host, agentName, actorId, name, sub, authToken, onError, onOpen, onClose, onMessage } = options;
|
|
16
34
|
const [type, setType] = useState(void 0);
|
|
@@ -26,7 +44,15 @@ function useAgent(options) {
|
|
|
26
44
|
},
|
|
27
45
|
onClose: (event) => {
|
|
28
46
|
if (event.code >= 3e3) setStatus("unauthorized");
|
|
29
|
-
else
|
|
47
|
+
else {
|
|
48
|
+
setStatus("disconnected");
|
|
49
|
+
if (!event.wasClean) console.warn("[useAgent] WebSocket closed unexpectedly", {
|
|
50
|
+
code: event.code,
|
|
51
|
+
reason: event.reason,
|
|
52
|
+
closeReason: getCloseReason(event.code),
|
|
53
|
+
wasClean: event.wasClean
|
|
54
|
+
});
|
|
55
|
+
}
|
|
30
56
|
onClose?.(event);
|
|
31
57
|
},
|
|
32
58
|
onMessage: (event) => {
|
|
@@ -38,7 +64,7 @@ function useAgent(options) {
|
|
|
38
64
|
onMessage?.(event);
|
|
39
65
|
},
|
|
40
66
|
onError: (event) => {
|
|
41
|
-
setStatus("
|
|
67
|
+
setStatus("error");
|
|
42
68
|
onError?.(event);
|
|
43
69
|
},
|
|
44
70
|
...getTokenArgs(authToken)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@economic/agents-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@ai-sdk/react": "^3.0.182",
|
|
24
|
-
"@cloudflare/ai-chat": "
|
|
25
|
-
"agents": "
|
|
24
|
+
"@cloudflare/ai-chat": "^0.8.5",
|
|
25
|
+
"agents": "^0.16.0",
|
|
26
26
|
"ai": "^6.0.180",
|
|
27
27
|
"zod": "^4.4.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@cloudflare/workers-types": "^4.
|
|
30
|
+
"@cloudflare/workers-types": "^4.20260616.1",
|
|
31
31
|
"@types/node": "^25.6.0",
|
|
32
32
|
"@typescript/native-preview": "7.0.0-dev.20260412.1",
|
|
33
33
|
"tsdown": "^0.22.0",
|