@deuz-sdk/react 1.9.0 → 2.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.
Files changed (2) hide show
  1. package/README.md +60 -16
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,35 +1,79 @@
1
1
  # @deuz-sdk/react
2
2
 
3
- React bindings for the [Deuz SDK](https://github.com/Deuz-AI/Deuz-SDK) — `useChat` / `useObject` hooks and minimal headless components on top of `@deuz-sdk/core`.
3
+ React bindings for the [Deuz SDK](https://github.com/Deuz-AI/Deuz-SDK) — `useChat` / `useObject` and a couple of headless components on top of `@deuz-sdk/core`.
4
4
 
5
5
  ```bash
6
6
  npm i @deuz-sdk/core @deuz-sdk/react
7
7
  ```
8
8
 
9
- Thin adapter by design: every chat-state transformation lives in `@deuz-sdk/core/chat` (the pure reducer/branch helpers) and the Deuz UI wire (`@deuz-sdk/core/ui`); this package only binds them to React state. `react` is a peer dependency (`^18 || ^19`). The legacy `@deuz-sdk/core/react` subpath keeps working but is frozen; new features land here.
9
+ ```tsx
10
+ import { useChat } from '@deuz-sdk/react';
10
11
 
11
- ## API
12
+ export function Chat() {
13
+ const { messages, sendMessage, status } = useChat({ api: '/api/chat' });
12
14
 
13
- ### `useChat(options): UseChatResult`
15
+ return (
16
+ <>
17
+ {messages.map((m) => (
18
+ <div key={m.id}>
19
+ {m.parts.map((p, i) => (p.type === 'text' ? <span key={i}>{p.text}</span> : null))}
20
+ </div>
21
+ ))}
22
+ <button disabled={status === 'streaming'} onClick={() => sendMessage({ text: 'Hello!' })}>
23
+ Send
24
+ </button>
25
+ </>
26
+ );
27
+ }
28
+ ```
29
+
30
+ Thin adapter by design. Every chat-state transformation lives in `@deuz-sdk/core/chat` (pure reducers, branch helpers) and the Deuz UI wire in `@deuz-sdk/core/ui`; this package only binds them to React state, which is why a refresh, a network blip and a server crash all look the same to your component. `react` is a peer dependency (`^18 || ^19`). The legacy `@deuz-sdk/core/react` subpath still works but is frozen — new work lands here.
31
+
32
+ ## `useChat(options)`
33
+
34
+ **Options**
35
+
36
+ | Option | Notes |
37
+ | --- | --- |
38
+ | `api` | Endpoint that returns a Deuz stream. Required. |
39
+ | `initialMessages?` | Canonical `Message[]`, projected once at mount via `uiFromMessages`. |
40
+ | `headers?` / `body?` | Merged into every request. |
41
+ | `chatId?` | Sent with every request; the server side keys persistence on it. |
42
+ | `resume?` | `{ endpoint, lastEventId?, auto?, cursor? }` — enables `reconnect()`, and with `auto` reconnects on mount after a reload. |
43
+ | `throttleMs?` | Coalesce re-renders during a fast stream. |
44
+ | `onToolCall?` | Client-tool executor. The round-trip and its error self-healing are handled for you. |
45
+ | `onData?` | Custom `data` parts from the server. |
46
+ | `onError?` / `onHttpError?` | `onHttpError: 'error-part'` (default) surfaces a non-2xx response on the stream instead of throwing. |
47
+ | `generateId?` / `fetch?` | Injection seams, same idea as core's. |
48
+
49
+ **State**
50
+
51
+ `messages` (`UIMessage[]`, ordered parts), `history` (`{ ui, canonical }`), `status`, `error`, `pendingApprovals`, `pendingToolCalls`, `cost`, `budgetExceeded`, `dataParts`, `citations`, `plan`, `activity`, `verifications`, `warnings`, `falseFinishes`, `subAgents`, `steps`, `usage`, `finishReason`.
52
+
53
+ Most of those exist because the agentic loop reports more than text: an approval it is waiting on, a plan it is following, a sub-agent it delegated to, the cost so far. Render what you need and ignore the rest.
14
54
 
15
- Options: `api`, `initialMessages?` (rendered via `uiFromMessages`), `headers?`, `body?`, `chatId?` (merged into every request body), `resume?` (`{ endpoint, lastEventId? }` — enables `reconnect()`), `generateId?`, `onToolCall?` (client-tool executor, auto round-trip with self-healing errors), `onError?`, `fetch?`.
55
+ **Methods**
16
56
 
17
- Result:
57
+ - `sendMessage(input)` — `input` is a `ChatInput`: `{ text }`, files, or both.
58
+ - `stop()`, `regenerate()`, `editAndResend(messageId, input)` — the last two branch history through core's `dropTrailingAssistant` / `branchBeforeUserMessage`.
59
+ - `addToolApprovalResponse(response)` — carries the request's signed token automatically, and resumes the run once every pending approval has a verdict.
60
+ - `setHistory(update)` / `setMessages(update)` — writable state for optimistic UI and hand-editing.
61
+ - `reconnect()` — re-attaches to an interrupted stream through `connectDeuzStream`.
62
+ - `clearError()`.
18
63
 
19
- - State: `messages: UIMessage[]`, `status: 'idle' | 'streaming' | 'error'`, `error`, `pendingApprovals: ToolApprovalRequest[]`, `cost?: { costUsd, cacheSavingsUsd? }`, `budgetExceeded?: { kind, limit, value }`, `dataParts: { name, payload }[]`, `citations`.
20
- - Methods: `sendMessage(text)`, `stop()`, `regenerate()` (core `dropTrailingAssistant`), `editAndResend(messageId, text)` (core `branchBeforeUserMessage`), `addToolApprovalResponse(response)` (auto-preserves the request's signed `token`; auto-resumes with `approvalResponses` once every pending approval has a verdict), `reconnect()` (reads the resume endpoint via `connectDeuzStream`).
64
+ ## `useObject<T>(options)`
21
65
 
22
- ### `useObject<T>(options): UseObjectResult<T>`
66
+ Streams `toDeuzObjectStreamResponse` output. Options: `api`, `headers?`, `fetch?`. Returns `object` (the latest `DeepPartial<T>`), `isLoading`, `error`, `submit(input)`, `stop()`.
23
67
 
24
- Streams `toDeuzObjectStreamResponse` output. Options: `api`, `headers?`, `fetch?`. Result: `object` (latest `DeepPartial<T>`), `isLoading`, `error`, `submit(input)`, `stop()`.
68
+ ## Headless components
25
69
 
26
- ### Headless components (zero styling)
70
+ Zero styling, both overridable.
27
71
 
28
- - `ToolApprovalCard({ approval, onRespond, render? })` — Approve/Deny for one pending approval; the verdict always carries the request's signed `token`. `render` overrides presentation and receives wired `approve()` / `deny(reason?)` callbacks.
29
- - `CostBadge({ cost, format? })` — `$X.XXXX` plus ` (saved $Y.YYYY)` when cache savings are positive; `format` overrides.
72
+ - `ToolApprovalCard({ approval, onRespond, render? })` — approve/deny for one pending approval; the verdict always carries the request's signed token. `render` receives wired `approve()` / `deny(reason?)` callbacks.
73
+ - `CostBadge({ cost, format? })` — `$X.XXXX`, plus ` (saved $Y.YYYY)` when cache savings are positive.
30
74
 
31
- ### Re-exported core types
75
+ ## Re-exported types
32
76
 
33
- `UIMessage`, `UIToolCall`, `AssistantTurnState`, `ChatHistory`, `DeuzUIPart`, `Message`, `ToolApprovalRequest`, `ToolApprovalResponse`.
77
+ `UIMessage`, `UIMessagePart`, `UIToolCall`, `AssistantTurnState`, `ChatHistory`, `ChatInput`, `DeuzUIPart`, `Message`, `ToolApprovalRequest`, `ToolApprovalResponse`.
34
78
 
35
- See the [main README](https://github.com/Deuz-AI/Deuz-SDK#readme) for the full SDK tour.
79
+ Full SDK tour, architecture and the honest limitations list: [github.com/Deuz-AI/Deuz-SDK](https://github.com/Deuz-AI/Deuz-SDK#readme).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deuz-sdk/react",
3
- "version": "1.9.0",
3
+ "version": "2.1.0",
4
4
  "description": "React bindings for the Deuz SDK — useChat/useObject hooks and headless chat components.",
5
5
  "license": "MIT",
6
6
  "author": "Umutcan Edizaslan (U-C4N)",
@@ -56,12 +56,12 @@
56
56
  "deuz"
57
57
  ],
58
58
  "peerDependencies": {
59
- "@deuz-sdk/core": "^1.9.0",
59
+ "@deuz-sdk/core": "^2.0.0",
60
60
  "react": "^18.0.0 || ^19.0.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@arethetypeswrong/cli": "^0.18.0",
64
- "@deuz-sdk/core": "^1.9.0",
64
+ "@deuz-sdk/core": "^2.1.0",
65
65
  "@testing-library/react": "^16.3.2",
66
66
  "@types/react": "^19.2.17",
67
67
  "eslint": "^9.18.0",