@strand-js/react 0.1.0 → 0.1.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 +78 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# @strand-js/react
|
|
2
|
+
|
|
3
|
+
React hooks for [Strand](https://github.com/strand-js/strand) — AI state management for React.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @strand-js/core @strand-js/react zod
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Hooks
|
|
12
|
+
|
|
13
|
+
### `useConversation` — streaming chat with tool calls
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { useConversation } from '@strand-js/react'
|
|
17
|
+
|
|
18
|
+
function Chat() {
|
|
19
|
+
const { messages, send, isPending, isStreaming, cancel } = useConversation({
|
|
20
|
+
system: 'You are a helpful assistant.',
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div>
|
|
25
|
+
{messages.map(m => <div key={m.id}>{m.content}</div>)}
|
|
26
|
+
{isPending && <div>Thinking...</div>}
|
|
27
|
+
<input onKeyDown={e => e.key === 'Enter' && send(e.currentTarget.value)} />
|
|
28
|
+
{(isPending || isStreaming) && <button onClick={cancel}>Stop</button>}
|
|
29
|
+
</div>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### `useToolCall` — per-tool observable state
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
const { status, input, output } = useToolCall('get_weather')
|
|
38
|
+
// status: 'idle' | 'pending' | 'running' | 'done' | 'failed'
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### `useAgentSession` — multi-step autonomous agents
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
const { status, steps, result, run, cancel } = useAgentSession({ maxSteps: 10 })
|
|
45
|
+
run('Research the latest AI developments')
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### `useStreamingText` — low-level streaming primitive
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
const { text, isDone, isStreaming } = useStreamingText(readableStream)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Setup
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { createStrandClient } from '@strand-js/core'
|
|
58
|
+
import { StrandProvider } from '@strand-js/react'
|
|
59
|
+
|
|
60
|
+
const client = createStrandClient({ baseUrl: '/api/strand' })
|
|
61
|
+
|
|
62
|
+
function App() {
|
|
63
|
+
return (
|
|
64
|
+
<StrandProvider client={client}>
|
|
65
|
+
<YourApp />
|
|
66
|
+
</StrandProvider>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Why Strand?
|
|
72
|
+
|
|
73
|
+
- `isPending` and `isStreaming` are separate — fixes the `isLoading` design flaw in other libraries
|
|
74
|
+
- `useToolCall` works from any component in the tree — not just where `send()` was called
|
|
75
|
+
- Stable context injection — no stale closure bugs
|
|
76
|
+
- Built-in retry, context window management, and React Native support
|
|
77
|
+
|
|
78
|
+
[Full documentation →](https://github.com/strand-js/strand)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strand-js/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "React hooks for Strand — useConversation, useToolCall, useAgentSession, useStreamingText",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@strand-js/core": "0.1.
|
|
19
|
+
"@strand-js/core": "0.1.1"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"react": "^18.0.0",
|