dooers-agents-client 0.2.7 → 0.4.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 +16 -16
- package/dist/main.cjs +417 -48
- package/dist/main.cjs.map +1 -1
- package/dist/main.d.cts +226 -9
- package/dist/main.d.ts +226 -9
- package/dist/main.js +411 -48
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,21 +12,21 @@ Peer dependency: `react >= 18`
|
|
|
12
12
|
|
|
13
13
|
## Quick Start
|
|
14
14
|
|
|
15
|
-
Wrap your component tree in `
|
|
15
|
+
Wrap your component tree in `AgentProvider`, then use hooks anywhere inside.
|
|
16
16
|
|
|
17
17
|
```tsx
|
|
18
|
-
import {
|
|
18
|
+
import { AgentProvider, useConnection, useThreadDetails, useMessage } from "dooers-agents-client"
|
|
19
19
|
|
|
20
20
|
function App() {
|
|
21
21
|
return (
|
|
22
|
-
<
|
|
22
|
+
<AgentProvider
|
|
23
23
|
url="ws://localhost:8000/ws"
|
|
24
|
-
|
|
24
|
+
agentId="agent-1"
|
|
25
25
|
userId="user-1"
|
|
26
26
|
userName="Alice"
|
|
27
27
|
>
|
|
28
28
|
<Chat threadId="thread-1" />
|
|
29
|
-
</
|
|
29
|
+
</AgentProvider>
|
|
30
30
|
)
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -60,12 +60,12 @@ function Chat({ threadId }: { threadId: string }) {
|
|
|
60
60
|
|
|
61
61
|
## Provider
|
|
62
62
|
|
|
63
|
-
`
|
|
63
|
+
`AgentProvider` manages the WebSocket lifecycle. On mount it connects, on unmount it disconnects. When any prop changes, the connection resets.
|
|
64
64
|
|
|
65
65
|
```tsx
|
|
66
|
-
<
|
|
66
|
+
<AgentProvider
|
|
67
67
|
url="ws://localhost:8000/ws" // WebSocket endpoint
|
|
68
|
-
|
|
68
|
+
agentId="agent-1" // Agent to connect to
|
|
69
69
|
organizationId="org-1" // Context passed to handler
|
|
70
70
|
workspaceId="ws-1"
|
|
71
71
|
userId="user-1"
|
|
@@ -78,14 +78,14 @@ function Chat({ threadId }: { threadId: string }) {
|
|
|
78
78
|
onError={(err) => console.error(err.code, err.message)}
|
|
79
79
|
>
|
|
80
80
|
{children}
|
|
81
|
-
</
|
|
81
|
+
</AgentProvider>
|
|
82
82
|
```
|
|
83
83
|
|
|
84
84
|
All props except `children` and `onError` are primitive strings, so React can diff them cheaply.
|
|
85
85
|
|
|
86
86
|
## Hooks
|
|
87
87
|
|
|
88
|
-
All hooks must be called inside a `
|
|
88
|
+
All hooks must be called inside a `AgentProvider`.
|
|
89
89
|
|
|
90
90
|
### useConnection
|
|
91
91
|
|
|
@@ -121,7 +121,7 @@ if (hasOlderEvents) {
|
|
|
121
121
|
|
|
122
122
|
### useThreadsList
|
|
123
123
|
|
|
124
|
-
Read-only thread list for the connected
|
|
124
|
+
Read-only thread list for the connected agent.
|
|
125
125
|
|
|
126
126
|
```tsx
|
|
127
127
|
const { threads, isLoading, hasMore, totalCount } = useThreadsList()
|
|
@@ -190,7 +190,7 @@ useEffect(() => {
|
|
|
190
190
|
|
|
191
191
|
### useSettings
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
Agent settings with real-time sync across clients.
|
|
194
194
|
|
|
195
195
|
```tsx
|
|
196
196
|
const { fields, updatedAt, isLoading, subscribe, unsubscribe, patchField } = useSettings()
|
|
@@ -215,7 +215,7 @@ All public types are camelCase. The SDK transforms the wire format (snake_case)
|
|
|
215
215
|
```typescript
|
|
216
216
|
import type {
|
|
217
217
|
User, // { userId, userName, userEmail, systemRole, organizationRole, workspaceRole }
|
|
218
|
-
Thread, // { id,
|
|
218
|
+
Thread, // { id, agentId, organizationId, workspaceId, owner, users, title, ... }
|
|
219
219
|
ThreadEvent, // { id, threadId, type, actor, author, user, content, data, createdAt, ... }
|
|
220
220
|
Run, // { id, threadId, agentId, status, startedAt, endedAt, error }
|
|
221
221
|
ContentPart, // TextPart | ImagePart | DocumentPart
|
|
@@ -238,9 +238,9 @@ import { isSettingsFieldGroup } from "dooers-agents-client" // type guard
|
|
|
238
238
|
## Architecture
|
|
239
239
|
|
|
240
240
|
```
|
|
241
|
-
|
|
242
|
-
├──
|
|
243
|
-
└──
|
|
241
|
+
AgentProvider
|
|
242
|
+
├── AgentClient WebSocket lifecycle, reconnection, optimistic events
|
|
243
|
+
└── AgentStore Zustand vanilla store
|
|
244
244
|
├── connection { status, error, reconnectFailed }
|
|
245
245
|
├── threads Record<id, Thread>
|
|
246
246
|
├── events Record<threadId, ThreadEvent[]>
|