@lumavox/react 0.17.0 → 0.21.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 CHANGED
@@ -91,6 +91,7 @@ Each returns `{ data, error, loading, refresh }`, with `error` a
91
91
  | `useSessions({ limit, cursor })` | a page of the person's conversations, and its `nextCursor` |
92
92
  | `useSession(id)` | one, with `messages`, `hasOlder` and `loadOlder()` |
93
93
  | `useFacts()` | what is remembered, with `forget(id)` and `forgetAll()` |
94
+ | `useMemories({ agent_id, category, session_id, limit, cursor })` | a page of the person's memories, with `nextCursor`, `forget(id)` and `forgetAll()` (every one, whatever the filters) |
94
95
  | `useRelation(agentId)` | live from an open `useAgent` under the same provider, else read once |
95
96
 
96
97
  MIT, copyright Lumavox.
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  /**
2
2
  * `@lumavox/react`: hooks for React and React Native alike, over
3
3
  * `@lumavox/client` — `useAgent` for a conversation, and `useSessions`,
4
- * `useSession`, `useFacts` and `useRelation` for what the REST routes
5
- * read. `useSyncExternalStore`, and nothing else of React's that 18 lacks;
4
+ * `useSession`, `useFacts`, `useMemories` and `useRelation` for what the
5
+ * REST routes read. `useSyncExternalStore`, and nothing else of React's that 18 lacks;
6
6
  * no data library: an app on TanStack Query calls `client.*` itself.
7
7
  */
8
8
  export { AgentProvider, type AgentProviderProps, useClient, } from "./provider.js";
9
9
  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
+ export { type MemoriesRead, useMemories } from "./use-memories.js";
12
13
  export { useRelation } from "./use-relation.js";
13
14
  export { type SessionRead, type SessionsRead, useSession, useSessions, } from "./use-sessions.js";
package/dist/index.js CHANGED
@@ -1,13 +1,14 @@
1
1
  /**
2
2
  * `@lumavox/react`: hooks for React and React Native alike, over
3
3
  * `@lumavox/client` — `useAgent` for a conversation, and `useSessions`,
4
- * `useSession`, `useFacts` and `useRelation` for what the REST routes
5
- * read. `useSyncExternalStore`, and nothing else of React's that 18 lacks;
4
+ * `useSession`, `useFacts`, `useMemories` and `useRelation` for what the
5
+ * REST routes read. `useSyncExternalStore`, and nothing else of React's that 18 lacks;
6
6
  * no data library: an app on TanStack Query calls `client.*` itself.
7
7
  */
8
8
  export { AgentProvider, useClient, } from "./provider.js";
9
9
  export { asPlatformError } from "./read.js";
10
10
  export { useAgent, } from "./use-agent.js";
11
11
  export { useFacts } from "./use-facts.js";
12
+ export { useMemories } from "./use-memories.js";
12
13
  export { useRelation } from "./use-relation.js";
13
14
  export { useSession, useSessions, } from "./use-sessions.js";
package/dist/use-agent.js CHANGED
@@ -38,6 +38,7 @@ const PASSED = [
38
38
  "onHeard",
39
39
  "onHeardPartial",
40
40
  "onKnowledge",
41
+ "onMemories",
41
42
  "onMood",
42
43
  "onThought",
43
44
  "onText",
@@ -0,0 +1,28 @@
1
+ /**
2
+ * What the agents remember of the person's life (`useMemories`): one
3
+ * memory per topic, the topic last talked about first, **a page at a
4
+ * time** — unlike `useFacts`, which reads every one: a memory carries its
5
+ * topic's whole story, and a person talking for years has many. A person
6
+ * with none has an empty page, never an error. `forget` and `forgetAll`
7
+ * change the page in place, without a read.
8
+ */
9
+ import type { Client, MemoryInfo, MemoryListParams } from "@lumavox/client";
10
+ import { type Read } from "./read.js";
11
+ export interface MemoriesRead extends Read<MemoryInfo[]> {
12
+ /** Pass as `cursor` for the next page; `null` on the last, or until the first answer. */
13
+ nextCursor: string | null;
14
+ /**
15
+ * Forget one; a memory already gone is forgotten too. A later
16
+ * conversation about the topic starts a new one. Rejects with the API's
17
+ * error.
18
+ */
19
+ forget(id: string): Promise<void>;
20
+ /**
21
+ * Forget every memory of the person — every agent's and every
22
+ * category's, whatever this read's filters. Their facts and
23
+ * conversations stay.
24
+ */
25
+ forgetAll(): Promise<void>;
26
+ }
27
+ /** One page of the person's memories, filtered by agent, category or conversation. */
28
+ export declare function useMemories(params?: MemoryListParams, client?: Client): MemoriesRead;
@@ -0,0 +1,27 @@
1
+ import { useCallback } from "react";
2
+ import { useClient } from "./provider.js";
3
+ import { useRead } from "./read.js";
4
+ /** One page of the person's memories, filtered by agent, category or conversation. */
5
+ export function useMemories(params = {}, client) {
6
+ const c = useClient(client);
7
+ const { agent_id, category, session_id, limit, cursor } = params;
8
+ const read = useRead(JSON.stringify(["memories", agent_id, category, session_id, limit, cursor]), () => c.memories.page({ agent_id, category, session_id, limit, cursor }));
9
+ const { set } = read;
10
+ const forget = useCallback(async (id) => {
11
+ await c.memories.delete(id);
12
+ set((page) => page && { ...page, data: page.data.filter((m) => m.id !== id) });
13
+ }, [c, set]);
14
+ const forgetAll = useCallback(async () => {
15
+ await c.memories.deleteAll();
16
+ set(() => ({ data: [], next_cursor: null }));
17
+ }, [c, set]);
18
+ return {
19
+ data: read.data?.data ?? null,
20
+ error: read.error,
21
+ loading: read.loading,
22
+ refresh: read.refresh,
23
+ nextCursor: read.data?.next_cursor ?? null,
24
+ forget,
25
+ forgetAll,
26
+ };
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumavox/react",
3
- "version": "0.17.0",
3
+ "version": "0.21.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.17.0"
32
+ "@lumavox/client": "0.21.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "react": ">=18"