@perstack/react 0.0.49 → 0.0.51
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 +81 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @perstack/react
|
|
2
2
|
|
|
3
|
-
React hooks and utilities for Perstack integration.
|
|
3
|
+
Reusable React hooks and utilities for Perstack integration. This is the shared React library layer that provides framework-agnostic hooks consumed by both TUI and web applications.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -52,6 +52,58 @@ function ExpertRunner() {
|
|
|
52
52
|
}
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
### useJobStream
|
|
56
|
+
|
|
57
|
+
Stream events for a single job. Wraps `useRun` with automatic stream connection management.
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { useJobStream } from "@perstack/react"
|
|
61
|
+
|
|
62
|
+
function JobViewer({ jobId }: { jobId: string }) {
|
|
63
|
+
const { activities, streaming, latestActivity, isConnected, error } = useJobStream({
|
|
64
|
+
jobId,
|
|
65
|
+
connect: (jobId, signal) => fetchStream(`/api/jobs/${jobId}/events`, signal),
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div>
|
|
70
|
+
{isConnected && <span>Connected</span>}
|
|
71
|
+
{error && <span>Error: {error.message}</span>}
|
|
72
|
+
<ActivityLog activities={activities} />
|
|
73
|
+
</div>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### useJobStreams
|
|
79
|
+
|
|
80
|
+
Track multiple jobs simultaneously with lightweight summaries (latest activity only).
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
import { useJobStreams } from "@perstack/react"
|
|
84
|
+
|
|
85
|
+
function JobList({ jobIds }: { jobIds: string[] }) {
|
|
86
|
+
const states = useJobStreams({
|
|
87
|
+
jobs: jobIds.map((id) => ({ id, enabled: true })),
|
|
88
|
+
connect: (jobId, signal) => fetchStream(`/api/jobs/${jobId}/events`, signal),
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<ul>
|
|
93
|
+
{jobIds.map((id) => {
|
|
94
|
+
const state = states.get(id)
|
|
95
|
+
return (
|
|
96
|
+
<li key={id}>
|
|
97
|
+
{id}: {state?.isConnected ? "Connected" : "Disconnected"}
|
|
98
|
+
{state?.latestActivity && ` - ${state.latestActivity.type}`}
|
|
99
|
+
</li>
|
|
100
|
+
)
|
|
101
|
+
})}
|
|
102
|
+
</ul>
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
55
107
|
### Utility Functions
|
|
56
108
|
|
|
57
109
|
For advanced use cases, you can use the utility functions directly:
|
|
@@ -91,6 +143,34 @@ Returns an object with:
|
|
|
91
143
|
|
|
92
144
|
**Note:** Activities are append-only and never cleared. This is required for compatibility with Ink's `<Static>` component.
|
|
93
145
|
|
|
146
|
+
### useJobStream(options)
|
|
147
|
+
|
|
148
|
+
Streams events for a single job. Parameters:
|
|
149
|
+
|
|
150
|
+
- `jobId`: Job ID to stream (or `null` to disable)
|
|
151
|
+
- `connect`: `StreamConnector` function `(jobId, signal) => AsyncIterable<PerstackEvent>`
|
|
152
|
+
- `enabled`: Whether to connect (default: `true`)
|
|
153
|
+
|
|
154
|
+
Returns:
|
|
155
|
+
|
|
156
|
+
- `activities`: Array of `ActivityOrGroup`
|
|
157
|
+
- `streaming`: Current `StreamingState`
|
|
158
|
+
- `latestActivity`: Most recent activity (or `null`)
|
|
159
|
+
- `isConnected`: Whether the stream is active
|
|
160
|
+
- `error`: Connection error (or `null`)
|
|
161
|
+
|
|
162
|
+
### useJobStreams(options)
|
|
163
|
+
|
|
164
|
+
Tracks multiple jobs with lightweight summaries. Parameters:
|
|
165
|
+
|
|
166
|
+
- `jobs`: Array of `{ id: string; enabled: boolean }`
|
|
167
|
+
- `connect`: `StreamConnector` function
|
|
168
|
+
|
|
169
|
+
Returns a `Map<string, JobStreamSummary>` where each summary contains:
|
|
170
|
+
|
|
171
|
+
- `latestActivity`: Most recent activity for the job
|
|
172
|
+
- `isConnected`: Whether the stream is active
|
|
173
|
+
|
|
94
174
|
## Types
|
|
95
175
|
|
|
96
176
|
### StreamingState
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perstack/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.51",
|
|
4
4
|
"description": "React hooks and utilities for Perstack integration",
|
|
5
5
|
"author": "Wintermute Technologies, Inc.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@perstack/core": "0.0.
|
|
21
|
+
"@perstack/core": "0.0.47"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": ">=18.0.0"
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@testing-library/react": "^16.3.2",
|
|
28
28
|
"@tsconfig/node22": "^22.0.5",
|
|
29
|
-
"@types/node": "^25.
|
|
30
|
-
"@types/react": "^19.2.
|
|
29
|
+
"@types/node": "^25.2.3",
|
|
30
|
+
"@types/react": "^19.2.14",
|
|
31
31
|
"@types/react-dom": "^19.2.3",
|
|
32
|
-
"jsdom": "^
|
|
32
|
+
"jsdom": "^28.0.0",
|
|
33
33
|
"tsup": "^8.5.1",
|
|
34
34
|
"typescript": "^5.9.3",
|
|
35
35
|
"vitest": "^4.0.18"
|