@ekairos/story-react 1.22.34-beta.development.0 → 1.22.35-beta.development.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 +12 -57
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,80 +1,35 @@
|
|
|
1
1
|
# @ekairos/story-react
|
|
2
2
|
|
|
3
|
-
React primitives for Ekairos
|
|
3
|
+
React client primitives for Ekairos story/context UIs.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Main hook
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- `useStory()`
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
pnpm add @ekairos/story-react
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## What `useStory` does
|
|
9
|
+
## What it gives you
|
|
14
10
|
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
11
|
+
- persisted timeline + optimistic overlay
|
|
12
|
+
- streaming assistant updates
|
|
13
|
+
- optional resumable streams
|
|
18
14
|
|
|
19
|
-
##
|
|
15
|
+
## Example
|
|
20
16
|
|
|
21
17
|
```tsx
|
|
22
18
|
"use client";
|
|
23
19
|
|
|
24
20
|
import { useStory } from "@ekairos/story-react";
|
|
25
21
|
|
|
26
|
-
export function
|
|
22
|
+
export function StoryUI({ db, apiUrl, contextId }: { db: any; apiUrl: string; contextId?: string }) {
|
|
27
23
|
const story = useStory(db, {
|
|
28
24
|
apiUrl,
|
|
29
25
|
initialContextId: contextId,
|
|
30
26
|
enableResumableStreams: true,
|
|
31
|
-
onContextUpdate: (id) => console.log("contextId:", id),
|
|
32
27
|
});
|
|
33
28
|
|
|
34
29
|
return (
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
disabled={story.sendStatus === "submitting"}
|
|
39
|
-
onClick={() => story.append({ parts: [{ type: "text", text: "Hola" }] })}
|
|
40
|
-
>
|
|
41
|
-
Send
|
|
42
|
-
</button>
|
|
43
|
-
<pre>{JSON.stringify(story.events, null, 2)}</pre>
|
|
44
|
-
</div>
|
|
30
|
+
<button onClick={() => story.append({ parts: [{ type: "text", text: "Hola" }] })}>
|
|
31
|
+
Send
|
|
32
|
+
</button>
|
|
45
33
|
);
|
|
46
34
|
}
|
|
47
35
|
```
|
|
48
|
-
|
|
49
|
-
## Default InstantDB queries (overrideable)
|
|
50
|
-
|
|
51
|
-
By default, `useStory` expects these namespaces:
|
|
52
|
-
|
|
53
|
-
- `context_contexts` (by `id`)
|
|
54
|
-
- `context_events` (by `context.id`, ordered by `createdAt: "asc"`)
|
|
55
|
-
|
|
56
|
-
If your schema differs, pass overrides (they MUST be hooks):
|
|
57
|
-
|
|
58
|
-
```ts
|
|
59
|
-
useStory(db, {
|
|
60
|
-
apiUrl,
|
|
61
|
-
context: (db, { contextId }) => {
|
|
62
|
-
const res = db.useQuery(/* your query */);
|
|
63
|
-
return { context: res.data?...., contextStatus: "open" };
|
|
64
|
-
},
|
|
65
|
-
events: (db, { contextId }) => {
|
|
66
|
-
const res = db.useQuery(/* your query */);
|
|
67
|
-
return { events: res.data?.... ?? [] };
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## API contract (server)
|
|
73
|
-
|
|
74
|
-
`useStory` sends:
|
|
75
|
-
|
|
76
|
-
- `POST apiUrl` with JSON `{ messages: [uiMessage], webSearch, reasoningLevel, contextId }`
|
|
77
|
-
- `GET apiUrl?runId=...&startIndex=...` (only if `enableResumableStreams` is enabled)
|
|
78
|
-
|
|
79
|
-
The server must respond with an `ai` SSE stream (`createUIMessageStreamResponse`).
|
|
80
|
-
|