@lumavox/react 0.1.1 → 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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/read.js +1 -1
- package/dist/use-agent.js +2 -2
- package/dist/use-facts.js +7 -1
- package/dist/use-relation.js +2 -2
- package/dist/use-sessions.d.ts +10 -3
- package/dist/use-sessions.js +14 -13
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ Each returns `{ data, error, loading, refresh }`, with `error` a
|
|
|
77
77
|
|
|
78
78
|
| Hook | |
|
|
79
79
|
|---|---|
|
|
80
|
-
| `useSessions({ limit,
|
|
80
|
+
| `useSessions({ limit, cursor })` | a page of the person's conversations, and its `nextCursor` |
|
|
81
81
|
| `useSession(id)` | one, with `messages`, `hasOlder` and `loadOlder()` |
|
|
82
82
|
| `useFacts()` | what is remembered, with `forget(id)` and `forgetAll()` |
|
|
83
83
|
| `useRelation(agentId)` | live from an open `useAgent` under the same provider, else read once |
|
package/dist/index.d.ts
CHANGED
|
@@ -10,4 +10,4 @@ export { asPlatformError, type Read } from "./read.js";
|
|
|
10
10
|
export { type AgentControls, type AgentError, type AgentTarget, type RecordingOptions, type StopRecordingOptions, type UseAgentOptions, useAgent, } from "./use-agent.js";
|
|
11
11
|
export { type FactsRead, useFacts } from "./use-facts.js";
|
|
12
12
|
export { useRelation } from "./use-relation.js";
|
|
13
|
-
export { type SessionRead, useSession, useSessions, } from "./use-sessions.js";
|
|
13
|
+
export { type SessionRead, type SessionsRead, useSession, useSessions, } from "./use-sessions.js";
|
package/dist/read.js
CHANGED
package/dist/use-agent.js
CHANGED
|
@@ -61,7 +61,7 @@ const CLOSED = snapshotOf("closed");
|
|
|
61
61
|
const notOpen = {
|
|
62
62
|
status: "dropped",
|
|
63
63
|
reason: "closed",
|
|
64
|
-
|
|
64
|
+
message: "The conversation is not open.",
|
|
65
65
|
};
|
|
66
66
|
export function useAgent(target, options = {}) {
|
|
67
67
|
const client = useClient(options.client);
|
|
@@ -149,7 +149,7 @@ export function useAgent(target, options = {}) {
|
|
|
149
149
|
latest.current.onTurnStart?.(frame);
|
|
150
150
|
};
|
|
151
151
|
wired.onError = (frame) => {
|
|
152
|
-
setError({ kind: "frame", message: frame.
|
|
152
|
+
setError({ kind: "frame", message: frame.message, frame });
|
|
153
153
|
latest.current.onError?.(frame);
|
|
154
154
|
};
|
|
155
155
|
wired.onClose = (close) => {
|
package/dist/use-facts.js
CHANGED
|
@@ -3,7 +3,13 @@ import { useClient } from "./provider.js";
|
|
|
3
3
|
import { useRead } from "./read.js";
|
|
4
4
|
export function useFacts(client) {
|
|
5
5
|
const c = useClient(client);
|
|
6
|
-
|
|
6
|
+
// Every page: the route answers its one, the newest 100, for now.
|
|
7
|
+
const read = useRead("facts", async () => {
|
|
8
|
+
const facts = [];
|
|
9
|
+
for await (const fact of c.facts.list())
|
|
10
|
+
facts.push(fact);
|
|
11
|
+
return facts;
|
|
12
|
+
});
|
|
7
13
|
const { set } = read;
|
|
8
14
|
const forget = useCallback(async (id) => {
|
|
9
15
|
await c.facts.delete(id);
|
package/dist/use-relation.js
CHANGED
|
@@ -8,8 +8,8 @@ export function useRelation(agentId, client) {
|
|
|
8
8
|
const conversation = useSyncExternalStore(useCallback((fn) => live?.subscribe(fn) ?? (() => { }), [live]), () => live?.get(agentId) ?? null, () => null);
|
|
9
9
|
const fromSocket = useSyncExternalStore(conversation ? (fn) => conversation.subscribe(fn) : none, () => conversation?.snapshot.relation ?? null, () => null);
|
|
10
10
|
const read = useRead(conversation ? null : `relation:${agentId}`, () => c.relations
|
|
11
|
-
.
|
|
12
|
-
.then((
|
|
11
|
+
.page({ agent_id: agentId, limit: 1 })
|
|
12
|
+
.then((page) => page.data[0] ?? null));
|
|
13
13
|
if (conversation) {
|
|
14
14
|
return {
|
|
15
15
|
data: fromSocket,
|
package/dist/use-sessions.d.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The person's conversations (`useSessions`) and one of them with its
|
|
3
3
|
* transcript (`useSession`), read through the client's REST routes — each
|
|
4
|
-
* a `Read` (`read.ts`): `{ data, error, loading, refresh }`.
|
|
4
|
+
* a `Read` (`read.ts`): `{ data, error, loading, refresh }`. Both page
|
|
5
|
+
* by the cursor the API names: `nextCursor` for the next page of
|
|
6
|
+
* conversations, `messages.next_cursor` (behind `loadOlder`) for older
|
|
7
|
+
* messages.
|
|
5
8
|
*/
|
|
6
9
|
import type { Client, MessageInfo, SessionDetail, SessionGetParams, SessionInfo, SessionListParams } from "@lumavox/client";
|
|
7
10
|
import { type Read } from "./read.js";
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
export interface SessionsRead extends Read<SessionInfo[]> {
|
|
12
|
+
/** Pass as `cursor` for the next page; `null` on the last, or until the first answer. */
|
|
13
|
+
nextCursor: string | null;
|
|
14
|
+
}
|
|
15
|
+
/** One page of the person's conversations, most recent first. */
|
|
16
|
+
export declare function useSessions(params?: SessionListParams, client?: Client): SessionsRead;
|
|
10
17
|
export interface SessionRead extends Read<SessionDetail> {
|
|
11
18
|
/** Every message read so far, oldest first: the older pages, then the latest. */
|
|
12
19
|
messages: MessageInfo[];
|
package/dist/use-sessions.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
2
|
import { useClient } from "./provider.js";
|
|
3
3
|
import { asPlatformError, useRead } from "./read.js";
|
|
4
|
-
/** One page of the person's conversations,
|
|
4
|
+
/** One page of the person's conversations, most recent first. */
|
|
5
5
|
export function useSessions(params = {}, client) {
|
|
6
6
|
const c = useClient(client);
|
|
7
|
-
const { limit,
|
|
8
|
-
const read = useRead(`${limit ?? ""}:${
|
|
7
|
+
const { limit, cursor } = params;
|
|
8
|
+
const read = useRead(`${limit ?? ""}:${cursor ?? ""}`, () => c.sessions.page({ limit, cursor }));
|
|
9
9
|
return {
|
|
10
|
-
data: read.data,
|
|
10
|
+
data: read.data?.data ?? null,
|
|
11
11
|
error: read.error,
|
|
12
12
|
loading: read.loading,
|
|
13
13
|
refresh: read.refresh,
|
|
14
|
+
nextCursor: read.data?.next_cursor ?? null,
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
/** A conversation and its transcript's latest page; `loadOlder` reads back. */
|
|
@@ -19,7 +20,7 @@ export function useSession(id, params = {}, client) {
|
|
|
19
20
|
const { limit } = params;
|
|
20
21
|
const read = useRead(id === null ? null : `${id}:${limit ?? ""}`, () => c.sessions.get(id, { limit }));
|
|
21
22
|
const [older, setOlder] = useState([]);
|
|
22
|
-
const [
|
|
23
|
+
const [cursor, setCursor] = useState(null);
|
|
23
24
|
const [loadingOlder, setLoadingOlder] = useState(false);
|
|
24
25
|
const [olderError, setOlderError] = useState(null);
|
|
25
26
|
const page = useRef(0);
|
|
@@ -28,19 +29,19 @@ export function useSession(id, params = {}, client) {
|
|
|
28
29
|
page.current += 1;
|
|
29
30
|
setOlder([]);
|
|
30
31
|
setOlderError(null);
|
|
31
|
-
|
|
32
|
+
setCursor(read.data?.messages.next_cursor ?? null);
|
|
32
33
|
}, [read.data]);
|
|
33
34
|
const loadOlder = useCallback(async () => {
|
|
34
|
-
if (id === null ||
|
|
35
|
+
if (id === null || cursor === null)
|
|
35
36
|
return;
|
|
36
37
|
const mine = page.current;
|
|
37
38
|
setLoadingOlder(true);
|
|
38
39
|
try {
|
|
39
|
-
const
|
|
40
|
+
const { messages } = await c.sessions.get(id, { limit, cursor });
|
|
40
41
|
if (mine !== page.current)
|
|
41
42
|
return;
|
|
42
|
-
setOlder((held) => [...
|
|
43
|
-
|
|
43
|
+
setOlder((held) => [...messages.data, ...held]);
|
|
44
|
+
setCursor(messages.next_cursor);
|
|
44
45
|
setOlderError(null);
|
|
45
46
|
}
|
|
46
47
|
catch (failure) {
|
|
@@ -52,14 +53,14 @@ export function useSession(id, params = {}, client) {
|
|
|
52
53
|
if (mine === page.current)
|
|
53
54
|
setLoadingOlder(false);
|
|
54
55
|
}
|
|
55
|
-
}, [c, id, limit,
|
|
56
|
+
}, [c, id, limit, cursor]);
|
|
56
57
|
return {
|
|
57
58
|
data: read.data,
|
|
58
59
|
error: olderError ?? read.error,
|
|
59
60
|
loading: read.loading || loadingOlder,
|
|
60
61
|
refresh: read.refresh,
|
|
61
|
-
messages: [...older, ...(read.data?.messages ?? [])],
|
|
62
|
-
hasOlder:
|
|
62
|
+
messages: [...older, ...(read.data?.messages.data ?? [])],
|
|
63
|
+
hasOlder: cursor !== null,
|
|
63
64
|
loadOlder,
|
|
64
65
|
};
|
|
65
66
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumavox/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "React and React Native hooks for Lumavox agents: a conversation that keeps itself connected, sessions, memory and relations, over @lumavox/client.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"typecheck": "tsc --noEmit && tsc --noEmit -p test"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@lumavox/client": "0.
|
|
32
|
+
"@lumavox/client": "0.4.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": ">=18"
|