@memoryintelligence/react 2.0.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 +344 -0
- package/dist/index.cjs +225 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +224 -0
- package/dist/index.d.ts +224 -0
- package/dist/index.js +218 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
# @memoryintelligence/react
|
|
2
|
+
|
|
3
|
+
Official React hooks for [Memory Intelligence](https://memoryintelligence.io) SDK.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @memoryintelligence/react @memoryintelligence/sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add @memoryintelligence/react @memoryintelligence/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
### 1. Setup Provider
|
|
16
|
+
|
|
17
|
+
Wrap your app with `MemoryClientProvider`:
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { MemoryClientProvider } from '@memoryintelligence/react';
|
|
21
|
+
|
|
22
|
+
function App() {
|
|
23
|
+
return (
|
|
24
|
+
<MemoryClientProvider config={{ apiKey: process.env.REACT_APP_MI_API_KEY }}>
|
|
25
|
+
<YourApp />
|
|
26
|
+
</MemoryClientProvider>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### 2. Use Hooks
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import { useMemorySearch, useDriftSubscription } from '@memoryintelligence/react';
|
|
35
|
+
|
|
36
|
+
function SearchPage() {
|
|
37
|
+
const { search, data, loading } = useMemorySearch();
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<div>
|
|
41
|
+
<button onClick={() => search('project planning')}>Search</button>
|
|
42
|
+
{loading && <p>Searching...</p>}
|
|
43
|
+
{data && <Results results={data.results} />}
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## API Reference
|
|
50
|
+
|
|
51
|
+
### MemoryClientProvider
|
|
52
|
+
|
|
53
|
+
Provides Memory Intelligence client to child components.
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
<MemoryClientProvider
|
|
57
|
+
config={{
|
|
58
|
+
apiKey: string;
|
|
59
|
+
baseUrl?: string;
|
|
60
|
+
wsUrl?: string;
|
|
61
|
+
userUlid?: string;
|
|
62
|
+
orgUlid?: string;
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
{children}
|
|
66
|
+
</MemoryClientProvider>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### useMemoryClient
|
|
70
|
+
|
|
71
|
+
Access the Memory Intelligence client directly.
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
const client = useMemoryClient();
|
|
75
|
+
const umo = await client.umo.process('content');
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### useMemorySearch
|
|
79
|
+
|
|
80
|
+
Search memories with reactive state management.
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
const { search, data, loading, error, reset } = useMemorySearch();
|
|
84
|
+
|
|
85
|
+
// Trigger search
|
|
86
|
+
await search('query', { limit: 10, scope: Scope.USER });
|
|
87
|
+
|
|
88
|
+
// Access results
|
|
89
|
+
console.log(data?.results);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### useMemoryProcess
|
|
93
|
+
|
|
94
|
+
Process content into Meaning Objects.
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
const { process, data, loading, error, reset } = useMemoryProcess();
|
|
98
|
+
|
|
99
|
+
// Process content
|
|
100
|
+
await process('Meeting notes about Q2 strategy', {
|
|
101
|
+
source: 'web_form',
|
|
102
|
+
metadata: { category: 'meetings' }
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Access created UMO
|
|
106
|
+
console.log(data?.umo_id);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### useDriftSubscription
|
|
110
|
+
|
|
111
|
+
Subscribe to real-time entity meaning changes.
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
const { updates, latestUpdate, connected, error, clearUpdates } = useDriftSubscription({
|
|
115
|
+
entityUlids: ['01ARZ3NDEV5ARZ3ND']
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Access updates
|
|
119
|
+
updates.forEach(update => {
|
|
120
|
+
console.log(update.canonicalName, update.driftEpoch);
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Options:**
|
|
125
|
+
- `options.entityUlids` - Array of entity ULIDs to watch
|
|
126
|
+
- `options.orgUlid` - Organization filter
|
|
127
|
+
- `maxUpdates` - Maximum updates to retain (default: 50)
|
|
128
|
+
|
|
129
|
+
**Returns:**
|
|
130
|
+
- `updates` - Array of drift updates (newest first)
|
|
131
|
+
- `latestUpdate` - Most recent update
|
|
132
|
+
- `connected` - WebSocket connection status
|
|
133
|
+
- `error` - Error if any
|
|
134
|
+
- `clearUpdates()` - Clear update history
|
|
135
|
+
|
|
136
|
+
### useComputeProgress
|
|
137
|
+
|
|
138
|
+
Track long-running compute operations with progress.
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
const { progress, result, isComplete, error, reset } = useComputeProgress(
|
|
142
|
+
'analyze_decision_process',
|
|
143
|
+
{ narrative_ulid: '01ARZ3NDFQ69G5FAVSV4RRFF' }
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
// Access progress
|
|
147
|
+
if (progress) {
|
|
148
|
+
console.log(`${progress.progressPercent}%: ${progress.message}`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Access result when complete
|
|
152
|
+
if (isComplete && result) {
|
|
153
|
+
console.log(result.result);
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Options:**
|
|
158
|
+
- `enabled` - Whether to start subscription (default: true)
|
|
159
|
+
|
|
160
|
+
**Returns:**
|
|
161
|
+
- `progress` - Current progress update
|
|
162
|
+
- `result` - Final result when complete
|
|
163
|
+
- `connected` - WebSocket connection status
|
|
164
|
+
- `error` - Error if any
|
|
165
|
+
- `isComplete` - Whether operation finished
|
|
166
|
+
- `reset()` - Reset state
|
|
167
|
+
|
|
168
|
+
## Examples
|
|
169
|
+
|
|
170
|
+
### Drift Monitor Component
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
import { useDriftSubscription } from '@memoryintelligence/react';
|
|
174
|
+
|
|
175
|
+
function DriftMonitor({ entityUlid }) {
|
|
176
|
+
const { updates, connected, error } = useDriftSubscription({
|
|
177
|
+
entityUlids: [entityUlid]
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
if (error) return <div>Error: {error.message}</div>;
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<div>
|
|
184
|
+
<div className="status">
|
|
185
|
+
{connected ? '🟢 Live' : '⚪ Disconnected'}
|
|
186
|
+
</div>
|
|
187
|
+
|
|
188
|
+
<div className="updates">
|
|
189
|
+
{updates.map((update, i) => (
|
|
190
|
+
<div key={i} className={!update.meaningStable ? 'warning' : ''}>
|
|
191
|
+
<h4>{update.canonicalName}</h4>
|
|
192
|
+
<p>Epoch: {update.driftEpoch} | Magnitude: {update.driftMagnitude.toFixed(3)}</p>
|
|
193
|
+
|
|
194
|
+
{!update.meaningStable && (
|
|
195
|
+
<div className="alert">
|
|
196
|
+
<strong>Meaning Changed</strong>
|
|
197
|
+
<p>{update.explainHuman.driftSummary}</p>
|
|
198
|
+
<ul>
|
|
199
|
+
{update.explainHuman.whatChanged.changes.map((change, j) => (
|
|
200
|
+
<li key={j}>{change}</li>
|
|
201
|
+
))}
|
|
202
|
+
</ul>
|
|
203
|
+
</div>
|
|
204
|
+
)}
|
|
205
|
+
</div>
|
|
206
|
+
))}
|
|
207
|
+
</div>
|
|
208
|
+
</div>
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Search with Form
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
import { useState } from 'react';
|
|
217
|
+
import { useMemorySearch } from '@memoryintelligence/react';
|
|
218
|
+
|
|
219
|
+
function SearchBox() {
|
|
220
|
+
const [query, setQuery] = useState('');
|
|
221
|
+
const { search, data, loading, error } = useMemorySearch();
|
|
222
|
+
|
|
223
|
+
const handleSubmit = async (e) => {
|
|
224
|
+
e.preventDefault();
|
|
225
|
+
await search(query, { limit: 20 });
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
return (
|
|
229
|
+
<form onSubmit={handleSubmit}>
|
|
230
|
+
<input
|
|
231
|
+
value={query}
|
|
232
|
+
onChange={(e) => setQuery(e.target.value)}
|
|
233
|
+
placeholder="Search memories..."
|
|
234
|
+
/>
|
|
235
|
+
<button type="submit" disabled={loading}>
|
|
236
|
+
{loading ? 'Searching...' : 'Search'}
|
|
237
|
+
</button>
|
|
238
|
+
|
|
239
|
+
{error && <div className="error">{error.message}</div>}
|
|
240
|
+
|
|
241
|
+
{data && (
|
|
242
|
+
<div className="results">
|
|
243
|
+
<p>Found {data.count} results</p>
|
|
244
|
+
<ul>
|
|
245
|
+
{data.results.map((result) => (
|
|
246
|
+
<li key={result.umo_id}>
|
|
247
|
+
<h3>{result.summary}</h3>
|
|
248
|
+
<p>Score: {result.score.toFixed(3)}</p>
|
|
249
|
+
</li>
|
|
250
|
+
))}
|
|
251
|
+
</ul>
|
|
252
|
+
</div>
|
|
253
|
+
)}
|
|
254
|
+
</form>
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Capture Form
|
|
260
|
+
|
|
261
|
+
```tsx
|
|
262
|
+
import { useState } from 'react';
|
|
263
|
+
import { useMemoryProcess } from '@memoryintelligence/react';
|
|
264
|
+
|
|
265
|
+
function CaptureForm() {
|
|
266
|
+
const [content, setContent] = useState('');
|
|
267
|
+
const { process, data, loading, error, reset } = useMemoryProcess();
|
|
268
|
+
|
|
269
|
+
const handleSubmit = async (e) => {
|
|
270
|
+
e.preventDefault();
|
|
271
|
+
await process(content, { source: 'web_form' });
|
|
272
|
+
setContent(''); // Clear on success
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
return (
|
|
276
|
+
<form onSubmit={handleSubmit}>
|
|
277
|
+
<textarea
|
|
278
|
+
value={content}
|
|
279
|
+
onChange={(e) => setContent(e.target.value)}
|
|
280
|
+
placeholder="Enter your memory..."
|
|
281
|
+
rows={6}
|
|
282
|
+
/>
|
|
283
|
+
<button type="submit" disabled={loading || !content}>
|
|
284
|
+
{loading ? 'Processing...' : 'Capture Memory'}
|
|
285
|
+
</button>
|
|
286
|
+
|
|
287
|
+
{error && <div className="error">{error.message}</div>}
|
|
288
|
+
{data && <div className="success">Created: {data.umo_id}</div>}
|
|
289
|
+
</form>
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Compute Progress
|
|
295
|
+
|
|
296
|
+
```tsx
|
|
297
|
+
import { useComputeProgress } from '@memoryintelligence/react';
|
|
298
|
+
|
|
299
|
+
function AnalysisProgress({ narrativeUlid }) {
|
|
300
|
+
const { progress, result, isComplete, error } = useComputeProgress(
|
|
301
|
+
'analyze_decision_process',
|
|
302
|
+
{ narrative_ulid: narrativeUlid }
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
if (error) return <div>Error: {error.message}</div>;
|
|
306
|
+
|
|
307
|
+
if (isComplete && result) {
|
|
308
|
+
return (
|
|
309
|
+
<div className="complete">
|
|
310
|
+
<h3>Analysis Complete</h3>
|
|
311
|
+
<p>Execution time: {result.executionTimeMs}ms</p>
|
|
312
|
+
<pre>{JSON.stringify(result.result, null, 2)}</pre>
|
|
313
|
+
</div>
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return (
|
|
318
|
+
<div className="progress">
|
|
319
|
+
<h3>Analyzing...</h3>
|
|
320
|
+
{progress && (
|
|
321
|
+
<>
|
|
322
|
+
<progress value={progress.progressPercent} max={100} />
|
|
323
|
+
<p>{progress.progressPercent}%: {progress.message}</p>
|
|
324
|
+
</>
|
|
325
|
+
)}
|
|
326
|
+
</div>
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## TypeScript Support
|
|
332
|
+
|
|
333
|
+
Fully typed with TypeScript. All hooks include proper type inference:
|
|
334
|
+
|
|
335
|
+
```tsx
|
|
336
|
+
import type { SearchResponse, MeaningObject } from '@memoryintelligence/react';
|
|
337
|
+
|
|
338
|
+
const { data } = useMemorySearch(); // data: SearchResponse | null
|
|
339
|
+
const { data: umo } = useMemoryProcess(); // umo: MeaningObject | null
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## License
|
|
343
|
+
|
|
344
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var sdk = require('@memoryintelligence/sdk');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
// src/MemoryClientProvider.tsx
|
|
8
|
+
var MemoryClientContext = react.createContext({
|
|
9
|
+
client: null,
|
|
10
|
+
isReady: false
|
|
11
|
+
});
|
|
12
|
+
function MemoryClientProvider({ config, children }) {
|
|
13
|
+
const [client, setClient] = react.useState(null);
|
|
14
|
+
const [isReady, setIsReady] = react.useState(false);
|
|
15
|
+
react.useEffect(() => {
|
|
16
|
+
const newClient = new sdk.MemoryClient(config);
|
|
17
|
+
setClient(newClient);
|
|
18
|
+
setIsReady(true);
|
|
19
|
+
return () => {
|
|
20
|
+
if ("disconnect" in newClient && typeof newClient.disconnect === "function") {
|
|
21
|
+
newClient.disconnect();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}, [config.apiKey, config.baseUrl, config.wsUrl, config.userUlid, config.orgUlid]);
|
|
25
|
+
return /* @__PURE__ */ jsxRuntime.jsx(MemoryClientContext.Provider, { value: { client, isReady }, children });
|
|
26
|
+
}
|
|
27
|
+
function useMemoryClient() {
|
|
28
|
+
const { client, isReady } = react.useContext(MemoryClientContext);
|
|
29
|
+
if (!isReady || !client) {
|
|
30
|
+
throw new Error("useMemoryClient must be used within MemoryClientProvider");
|
|
31
|
+
}
|
|
32
|
+
return client;
|
|
33
|
+
}
|
|
34
|
+
function useDriftSubscription(options, maxUpdates = 50) {
|
|
35
|
+
const client = useMemoryClient();
|
|
36
|
+
const [updates, setUpdates] = react.useState([]);
|
|
37
|
+
const [latestUpdate, setLatestUpdate] = react.useState(null);
|
|
38
|
+
const [connected, setConnected] = react.useState(false);
|
|
39
|
+
const [error, setError] = react.useState(null);
|
|
40
|
+
const subscriptionRef = react.useRef(null);
|
|
41
|
+
const clearUpdates = react.useCallback(() => {
|
|
42
|
+
setUpdates([]);
|
|
43
|
+
setLatestUpdate(null);
|
|
44
|
+
}, []);
|
|
45
|
+
react.useEffect(() => {
|
|
46
|
+
const subscription = client.drift.watch(options);
|
|
47
|
+
subscriptionRef.current = subscription;
|
|
48
|
+
subscription.on("connected", () => {
|
|
49
|
+
setConnected(true);
|
|
50
|
+
setError(null);
|
|
51
|
+
});
|
|
52
|
+
subscription.on("disconnected", () => {
|
|
53
|
+
setConnected(false);
|
|
54
|
+
});
|
|
55
|
+
subscription.on("update", (update) => {
|
|
56
|
+
setLatestUpdate(update);
|
|
57
|
+
setUpdates((prev) => [update, ...prev].slice(0, maxUpdates));
|
|
58
|
+
});
|
|
59
|
+
subscription.on("error", (err) => {
|
|
60
|
+
setError(err);
|
|
61
|
+
setConnected(false);
|
|
62
|
+
});
|
|
63
|
+
subscription.start().catch((err) => {
|
|
64
|
+
setError(err);
|
|
65
|
+
});
|
|
66
|
+
return () => {
|
|
67
|
+
subscription.stop();
|
|
68
|
+
};
|
|
69
|
+
}, [
|
|
70
|
+
client,
|
|
71
|
+
maxUpdates,
|
|
72
|
+
JSON.stringify(options.entityUlids),
|
|
73
|
+
options.orgUlid
|
|
74
|
+
]);
|
|
75
|
+
return {
|
|
76
|
+
updates,
|
|
77
|
+
latestUpdate,
|
|
78
|
+
connected,
|
|
79
|
+
error,
|
|
80
|
+
clearUpdates
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function useComputeProgress(functionName, parameters, enabled = true) {
|
|
84
|
+
const client = useMemoryClient();
|
|
85
|
+
const [progress, setProgress] = react.useState(null);
|
|
86
|
+
const [result, setResult] = react.useState(null);
|
|
87
|
+
const [connected, setConnected] = react.useState(false);
|
|
88
|
+
const [error, setError] = react.useState(null);
|
|
89
|
+
const [isComplete, setIsComplete] = react.useState(false);
|
|
90
|
+
const subscriptionRef = react.useRef(null);
|
|
91
|
+
const reset = react.useCallback(() => {
|
|
92
|
+
setProgress(null);
|
|
93
|
+
setResult(null);
|
|
94
|
+
setError(null);
|
|
95
|
+
setIsComplete(false);
|
|
96
|
+
}, []);
|
|
97
|
+
react.useEffect(() => {
|
|
98
|
+
if (!enabled) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
reset();
|
|
102
|
+
const subscription = client.compute.watch(functionName, parameters);
|
|
103
|
+
subscriptionRef.current = subscription;
|
|
104
|
+
subscription.on("connected", () => {
|
|
105
|
+
setConnected(true);
|
|
106
|
+
setError(null);
|
|
107
|
+
});
|
|
108
|
+
subscription.on("disconnected", () => {
|
|
109
|
+
setConnected(false);
|
|
110
|
+
});
|
|
111
|
+
subscription.on("progress", (progressUpdate) => {
|
|
112
|
+
setProgress(progressUpdate);
|
|
113
|
+
});
|
|
114
|
+
subscription.on("result", (resultData) => {
|
|
115
|
+
setResult(resultData);
|
|
116
|
+
setIsComplete(true);
|
|
117
|
+
setConnected(false);
|
|
118
|
+
});
|
|
119
|
+
subscription.on("error", (err) => {
|
|
120
|
+
setError(err);
|
|
121
|
+
setConnected(false);
|
|
122
|
+
});
|
|
123
|
+
subscription.start().catch((err) => {
|
|
124
|
+
setError(err);
|
|
125
|
+
});
|
|
126
|
+
return () => {
|
|
127
|
+
subscription.stop();
|
|
128
|
+
};
|
|
129
|
+
}, [
|
|
130
|
+
client,
|
|
131
|
+
functionName,
|
|
132
|
+
JSON.stringify(parameters),
|
|
133
|
+
enabled,
|
|
134
|
+
reset
|
|
135
|
+
]);
|
|
136
|
+
return {
|
|
137
|
+
progress,
|
|
138
|
+
result,
|
|
139
|
+
connected,
|
|
140
|
+
error,
|
|
141
|
+
isComplete,
|
|
142
|
+
reset
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function useMemorySearch() {
|
|
146
|
+
const client = useMemoryClient();
|
|
147
|
+
const [data, setData] = react.useState(null);
|
|
148
|
+
const [loading, setLoading] = react.useState(false);
|
|
149
|
+
const [error, setError] = react.useState(null);
|
|
150
|
+
const search = react.useCallback(
|
|
151
|
+
async (query, options) => {
|
|
152
|
+
setLoading(true);
|
|
153
|
+
setError(null);
|
|
154
|
+
try {
|
|
155
|
+
const response = await client.umo.search(query, options);
|
|
156
|
+
setData(response);
|
|
157
|
+
return response;
|
|
158
|
+
} catch (err) {
|
|
159
|
+
const error2 = err instanceof Error ? err : new Error("Search failed");
|
|
160
|
+
setError(error2);
|
|
161
|
+
throw error2;
|
|
162
|
+
} finally {
|
|
163
|
+
setLoading(false);
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
[client]
|
|
167
|
+
);
|
|
168
|
+
const reset = react.useCallback(() => {
|
|
169
|
+
setData(null);
|
|
170
|
+
setError(null);
|
|
171
|
+
setLoading(false);
|
|
172
|
+
}, []);
|
|
173
|
+
return {
|
|
174
|
+
search,
|
|
175
|
+
data,
|
|
176
|
+
loading,
|
|
177
|
+
error,
|
|
178
|
+
reset
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function useMemoryProcess() {
|
|
182
|
+
const client = useMemoryClient();
|
|
183
|
+
const [data, setData] = react.useState(null);
|
|
184
|
+
const [loading, setLoading] = react.useState(false);
|
|
185
|
+
const [error, setError] = react.useState(null);
|
|
186
|
+
const process = react.useCallback(
|
|
187
|
+
async (content, options) => {
|
|
188
|
+
setLoading(true);
|
|
189
|
+
setError(null);
|
|
190
|
+
try {
|
|
191
|
+
const umo = await client.umo.process(content, options);
|
|
192
|
+
setData(umo);
|
|
193
|
+
return umo;
|
|
194
|
+
} catch (err) {
|
|
195
|
+
const error2 = err instanceof Error ? err : new Error("Process failed");
|
|
196
|
+
setError(error2);
|
|
197
|
+
throw error2;
|
|
198
|
+
} finally {
|
|
199
|
+
setLoading(false);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
[client]
|
|
203
|
+
);
|
|
204
|
+
const reset = react.useCallback(() => {
|
|
205
|
+
setData(null);
|
|
206
|
+
setError(null);
|
|
207
|
+
setLoading(false);
|
|
208
|
+
}, []);
|
|
209
|
+
return {
|
|
210
|
+
process,
|
|
211
|
+
data,
|
|
212
|
+
loading,
|
|
213
|
+
error,
|
|
214
|
+
reset
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
exports.MemoryClientProvider = MemoryClientProvider;
|
|
219
|
+
exports.useComputeProgress = useComputeProgress;
|
|
220
|
+
exports.useDriftSubscription = useDriftSubscription;
|
|
221
|
+
exports.useMemoryClient = useMemoryClient;
|
|
222
|
+
exports.useMemoryProcess = useMemoryProcess;
|
|
223
|
+
exports.useMemorySearch = useMemorySearch;
|
|
224
|
+
//# sourceMappingURL=index.cjs.map
|
|
225
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/MemoryClientProvider.tsx","../src/useDriftSubscription.ts","../src/useComputeProgress.ts","../src/useMemorySearch.ts","../src/useMemoryProcess.ts"],"names":["createContext","useState","useEffect","M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KAAK,CAAA;AAAA,MAClB;AAAA,IACF,CAAA;AAAA,IACA,CAAC,MAAM;AAAA,GACT;AAEA,EAAA,MAAM,KAAA,GAAQD,kBAAY,MAAM;AAC9B,IAAA,OAAA,CAAQ,IAAI,CAAA;AACZ,IAAA,QAAA,CAAS,IAAI,CAAA;AACb,IAAA,UAAA,CAAW,KAAK,CAAA;AAAA,EAClB,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,IAAA;AAAA,IACA,OAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["/**\n * React context provider for Memory Intelligence client.\n */\n\nimport React, { createContext, useContext, useEffect, useState } from 'react';\nimport { MemoryClient, type MemoryClientConfig } from '@memoryintelligence/sdk';\n\nexport interface MemoryClientContextValue {\n client: MemoryClient | null;\n isReady: boolean;\n}\n\nconst MemoryClientContext = createContext<MemoryClientContextValue>({\n client: null,\n isReady: false,\n});\n\nexport interface MemoryClientProviderProps {\n config: MemoryClientConfig;\n children: React.ReactNode;\n}\n\n/**\n * Provider component for Memory Intelligence client.\n * \n * @example\n * ```tsx\n * <MemoryClientProvider config={{ apiKey: process.env.MI_API_KEY }}>\n * <App />\n * </MemoryClientProvider>\n * ```\n */\nexport function MemoryClientProvider({ config, children }: MemoryClientProviderProps) {\n const [client, setClient] = useState<MemoryClient | null>(null);\n const [isReady, setIsReady] = useState(false);\n\n useEffect(() => {\n const newClient = new MemoryClient(config);\n setClient(newClient);\n setIsReady(true);\n\n return () => {\n // Cleanup WebSocket connections if client has disconnect method\n if ('disconnect' in newClient && typeof newClient.disconnect === 'function') {\n newClient.disconnect();\n }\n };\n }, [config.apiKey, config.baseUrl, config.wsUrl, config.userUlid, config.orgUlid]);\n\n return (\n <MemoryClientContext.Provider value={{ client, isReady }}>\n {children}\n </MemoryClientContext.Provider>\n );\n}\n\n/**\n * Hook to access the Memory Intelligence client from context.\n * \n * @throws Error if used outside MemoryClientProvider\n */\nexport function useMemoryClient(): MemoryClient {\n const { client, isReady } = useContext(MemoryClientContext);\n\n if (!isReady || !client) {\n throw new Error('useMemoryClient must be used within MemoryClientProvider');\n }\n\n return client;\n}\n","/**\n * React hook for drift subscriptions.\n */\n\nimport { useEffect, useState, useCallback, useRef } from 'react';\nimport type { DriftSubscription, DriftUpdate, DriftSubscriptionOptions } from '@memoryintelligence/sdk';\nimport { useMemoryClient } from './MemoryClientProvider.js';\n\nexport interface UseDriftSubscriptionResult {\n updates: DriftUpdate[];\n latestUpdate: DriftUpdate | null;\n connected: boolean;\n error: Error | null;\n clearUpdates: () => void;\n}\n\n/**\n * Hook for subscribing to drift updates.\n * \n * @param options - Subscription options\n * @param maxUpdates - Maximum number of updates to keep (default: 50)\n * @returns Drift subscription state\n * \n * @example\n * ```tsx\n * function DriftMonitor({ entityUlid }) {\n * const { updates, connected, error } = useDriftSubscription({\n * entityUlids: [entityUlid]\n * });\n * \n * if (error) return <div>Error: {error.message}</div>;\n * \n * return (\n * <div>\n * <p>Status: {connected ? 'Connected' : 'Disconnected'}</p>\n * {updates.map((update, i) => (\n * <div key={i}>{update.canonicalName} - Epoch {update.driftEpoch}</div>\n * ))}\n * </div>\n * );\n * }\n * ```\n */\nexport function useDriftSubscription(\n options: DriftSubscriptionOptions,\n maxUpdates: number = 50\n): UseDriftSubscriptionResult {\n const client = useMemoryClient();\n const [updates, setUpdates] = useState<DriftUpdate[]>([]);\n const [latestUpdate, setLatestUpdate] = useState<DriftUpdate | null>(null);\n const [connected, setConnected] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const subscriptionRef = useRef<DriftSubscription | null>(null);\n\n const clearUpdates = useCallback(() => {\n setUpdates([]);\n setLatestUpdate(null);\n }, []);\n\n useEffect(() => {\n const subscription = client.drift.watch(options);\n subscriptionRef.current = subscription;\n\n subscription.on('connected', () => {\n setConnected(true);\n setError(null);\n });\n\n subscription.on('disconnected', () => {\n setConnected(false);\n });\n\n subscription.on('update', (update) => {\n setLatestUpdate(update);\n setUpdates((prev) => [update, ...prev].slice(0, maxUpdates));\n });\n\n subscription.on('error', (err: any) => {\n setError(err);\n setConnected(false);\n });\n\n subscription.start().catch((err) => {\n setError(err);\n });\n\n return () => {\n subscription.stop();\n };\n }, [\n client,\n maxUpdates,\n JSON.stringify(options.entityUlids),\n options.orgUlid,\n ]);\n\n return {\n updates,\n latestUpdate,\n connected,\n error,\n clearUpdates,\n };\n}\n","/**\n * React hook for compute operation progress tracking.\n */\n\nimport { useEffect, useState, useCallback, useRef } from 'react';\nimport type { ComputeSubscription, ComputeProgress, ComputeResult } from '@memoryintelligence/sdk';\nimport { useMemoryClient } from './MemoryClientProvider.js';\n\nexport interface UseComputeProgressResult<T = any> {\n progress: ComputeProgress | null;\n result: ComputeResult<T> | null;\n connected: boolean;\n error: Error | null;\n isComplete: boolean;\n reset: () => void;\n}\n\n/**\n * Hook for tracking compute operation progress.\n * \n * @param functionName - Name of compute function\n * @param parameters - Function parameters\n * @param enabled - Whether to start the subscription (default: true)\n * @returns Compute progress state\n * \n * @example\n * ```tsx\n * function AnalysisProgress({ narrativeUlid }) {\n * const { progress, result, isComplete, error } = useComputeProgress(\n * 'analyze_decision_process',\n * { narrative_ulid: narrativeUlid }\n * );\n * \n * if (error) return <div>Error: {error.message}</div>;\n * if (isComplete && result) {\n * return <div>Analysis complete: {JSON.stringify(result.result)}</div>;\n * }\n * \n * return (\n * <div>\n * {progress && (\n * <div>\n * <progress value={progress.progressPercent} max={100} />\n * <p>{progress.message}</p>\n * </div>\n * )}\n * </div>\n * );\n * }\n * ```\n */\nexport function useComputeProgress<T = any>(\n functionName: string,\n parameters: Record<string, any>,\n enabled: boolean = true\n): UseComputeProgressResult<T> {\n const client = useMemoryClient();\n const [progress, setProgress] = useState<ComputeProgress | null>(null);\n const [result, setResult] = useState<ComputeResult<T> | null>(null);\n const [connected, setConnected] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [isComplete, setIsComplete] = useState(false);\n const subscriptionRef = useRef<ComputeSubscription<T> | null>(null);\n\n const reset = useCallback(() => {\n setProgress(null);\n setResult(null);\n setError(null);\n setIsComplete(false);\n }, []);\n\n useEffect(() => {\n if (!enabled) {\n return;\n }\n\n reset();\n\n const subscription = client.compute.watch<T>(functionName, parameters);\n subscriptionRef.current = subscription;\n\n subscription.on('connected', () => {\n setConnected(true);\n setError(null);\n });\n\n subscription.on('disconnected', () => {\n setConnected(false);\n });\n\n subscription.on('progress', (progressUpdate) => {\n setProgress(progressUpdate as ComputeProgress);\n });\n\n subscription.on('result', (resultData) => {\n setResult(resultData as ComputeResult<T>);\n setIsComplete(true);\n setConnected(false); // Auto-unsubscribes after result\n });\n\n subscription.on('error', (err: any) => {\n setError(err);\n setConnected(false);\n });\n\n subscription.start().catch((err) => {\n setError(err);\n });\n\n return () => {\n subscription.stop();\n };\n }, [\n client,\n functionName,\n JSON.stringify(parameters),\n enabled,\n reset,\n ]);\n\n return {\n progress,\n result,\n connected,\n error,\n isComplete,\n reset,\n };\n}\n","/**\n * React hook for memory search.\n */\n\nimport { useState, useCallback } from 'react';\nimport type { SearchResponse, Scope, ExplainLevel } from '@memoryintelligence/sdk';\nimport { useMemoryClient } from './MemoryClientProvider.js';\n\nexport interface UseMemorySearchOptions {\n userUlid?: string;\n limit?: number;\n scope?: Scope;\n scopeId?: string;\n explain?: ExplainLevel;\n}\n\nexport interface UseMemorySearchResult {\n search: (query: string, options?: UseMemorySearchOptions) => Promise<SearchResponse>;\n data: SearchResponse | null;\n loading: boolean;\n error: Error | null;\n reset: () => void;\n}\n\n/**\n * Hook for memory search operations.\n * \n * @returns Search function and state\n * \n * @example\n * ```tsx\n * function SearchBox() {\n * const { search, data, loading, error } = useMemorySearch();\n * const [query, setQuery] = useState('');\n * \n * const handleSearch = async () => {\n * await search(query, { limit: 10 });\n * };\n * \n * return (\n * <div>\n * <input value={query} onChange={(e) => setQuery(e.target.value)} />\n * <button onClick={handleSearch} disabled={loading}>Search</button>\n * {loading && <p>Searching...</p>}\n * {error && <p>Error: {error.message}</p>}\n * {data && (\n * <ul>\n * {data.results.map((result) => (\n * <li key={result.umo_id}>{result.summary}</li>\n * ))}\n * </ul>\n * )}\n * </div>\n * );\n * }\n * ```\n */\nexport function useMemorySearch(): UseMemorySearchResult {\n const client = useMemoryClient();\n const [data, setData] = useState<SearchResponse | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const search = useCallback(\n async (query: string, options?: UseMemorySearchOptions): Promise<SearchResponse> => {\n setLoading(true);\n setError(null);\n\n try {\n const response = await client.umo.search(query, options);\n setData(response);\n return response;\n } catch (err) {\n const error = err instanceof Error ? err : new Error('Search failed');\n setError(error);\n throw error;\n } finally {\n setLoading(false);\n }\n },\n [client]\n );\n\n const reset = useCallback(() => {\n setData(null);\n setError(null);\n setLoading(false);\n }, []);\n\n return {\n search,\n data,\n loading,\n error,\n reset,\n };\n}\n","/**\n * React hook for processing content into memories.\n */\n\nimport { useState, useCallback } from 'react';\nimport type {\n MeaningObject,\n RetentionPolicy,\n PIIHandling,\n ProvenanceMode,\n Scope,\n} from '@memoryintelligence/sdk';\nimport { useMemoryClient } from './MemoryClientProvider.js';\n\nexport interface ProcessOptions {\n userUlid?: string;\n retentionPolicy?: RetentionPolicy;\n piiHandling?: PIIHandling;\n provenanceMode?: ProvenanceMode;\n scope?: Scope;\n scopeId?: string;\n source?: string;\n metadata?: Record<string, unknown>;\n}\n\nexport interface UseMemoryProcessResult {\n process: (content: string, options?: ProcessOptions) => Promise<MeaningObject>;\n data: MeaningObject | null;\n loading: boolean;\n error: Error | null;\n reset: () => void;\n}\n\n/**\n * Hook for processing content into Meaning Objects.\n * \n * @returns Process function and state\n * \n * @example\n * ```tsx\n * function CaptureForm() {\n * const { process, data, loading, error } = useMemoryProcess();\n * const [content, setContent] = useState('');\n * \n * const handleSubmit = async () => {\n * await process(content, { source: 'web_form' });\n * setContent(''); // Clear after success\n * };\n * \n * return (\n * <div>\n * <textarea value={content} onChange={(e) => setContent(e.target.value)} />\n * <button onClick={handleSubmit} disabled={loading}>Capture</button>\n * {loading && <p>Processing...</p>}\n * {error && <p>Error: {error.message}</p>}\n * {data && <p>Created: {data.umo_id}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useMemoryProcess(): UseMemoryProcessResult {\n const client = useMemoryClient();\n const [data, setData] = useState<MeaningObject | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const process = useCallback(\n async (content: string, options?: ProcessOptions): Promise<MeaningObject> => {\n setLoading(true);\n setError(null);\n\n try {\n const umo = await client.umo.process(content, options);\n setData(umo);\n return umo;\n } catch (err) {\n const error = err instanceof Error ? err : new Error('Process failed');\n setError(error);\n throw error;\n } finally {\n setLoading(false);\n }\n },\n [client]\n );\n\n const reset = useCallback(() => {\n setData(null);\n setError(null);\n setLoading(false);\n }, []);\n\n return {\n process,\n data,\n loading,\n error,\n reset,\n };\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { MemoryClient, MemoryClientConfig, DriftUpdate, DriftSubscriptionOptions, ComputeProgress, ComputeResult, Scope, ExplainLevel, SearchResponse, RetentionPolicy, PIIHandling, ProvenanceMode, MeaningObject } from '@memoryintelligence/sdk';
|
|
4
|
+
export { ComputeProgress, ComputeResult, DriftSubscriptionOptions, DriftUpdate, ExplainLevel, MeaningObject, PIIHandling, ProvenanceMode, RetentionPolicy, Scope, SearchResponse, SearchResult } from '@memoryintelligence/sdk';
|
|
5
|
+
|
|
6
|
+
interface MemoryClientContextValue {
|
|
7
|
+
client: MemoryClient | null;
|
|
8
|
+
isReady: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface MemoryClientProviderProps {
|
|
11
|
+
config: MemoryClientConfig;
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Provider component for Memory Intelligence client.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* <MemoryClientProvider config={{ apiKey: process.env.MI_API_KEY }}>
|
|
20
|
+
* <App />
|
|
21
|
+
* </MemoryClientProvider>
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function MemoryClientProvider({ config, children }: MemoryClientProviderProps): react_jsx_runtime.JSX.Element;
|
|
25
|
+
/**
|
|
26
|
+
* Hook to access the Memory Intelligence client from context.
|
|
27
|
+
*
|
|
28
|
+
* @throws Error if used outside MemoryClientProvider
|
|
29
|
+
*/
|
|
30
|
+
declare function useMemoryClient(): MemoryClient;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* React hook for drift subscriptions.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
interface UseDriftSubscriptionResult {
|
|
37
|
+
updates: DriftUpdate[];
|
|
38
|
+
latestUpdate: DriftUpdate | null;
|
|
39
|
+
connected: boolean;
|
|
40
|
+
error: Error | null;
|
|
41
|
+
clearUpdates: () => void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Hook for subscribing to drift updates.
|
|
45
|
+
*
|
|
46
|
+
* @param options - Subscription options
|
|
47
|
+
* @param maxUpdates - Maximum number of updates to keep (default: 50)
|
|
48
|
+
* @returns Drift subscription state
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```tsx
|
|
52
|
+
* function DriftMonitor({ entityUlid }) {
|
|
53
|
+
* const { updates, connected, error } = useDriftSubscription({
|
|
54
|
+
* entityUlids: [entityUlid]
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
58
|
+
*
|
|
59
|
+
* return (
|
|
60
|
+
* <div>
|
|
61
|
+
* <p>Status: {connected ? 'Connected' : 'Disconnected'}</p>
|
|
62
|
+
* {updates.map((update, i) => (
|
|
63
|
+
* <div key={i}>{update.canonicalName} - Epoch {update.driftEpoch}</div>
|
|
64
|
+
* ))}
|
|
65
|
+
* </div>
|
|
66
|
+
* );
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
declare function useDriftSubscription(options: DriftSubscriptionOptions, maxUpdates?: number): UseDriftSubscriptionResult;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* React hook for compute operation progress tracking.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
interface UseComputeProgressResult<T = any> {
|
|
77
|
+
progress: ComputeProgress | null;
|
|
78
|
+
result: ComputeResult<T> | null;
|
|
79
|
+
connected: boolean;
|
|
80
|
+
error: Error | null;
|
|
81
|
+
isComplete: boolean;
|
|
82
|
+
reset: () => void;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Hook for tracking compute operation progress.
|
|
86
|
+
*
|
|
87
|
+
* @param functionName - Name of compute function
|
|
88
|
+
* @param parameters - Function parameters
|
|
89
|
+
* @param enabled - Whether to start the subscription (default: true)
|
|
90
|
+
* @returns Compute progress state
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```tsx
|
|
94
|
+
* function AnalysisProgress({ narrativeUlid }) {
|
|
95
|
+
* const { progress, result, isComplete, error } = useComputeProgress(
|
|
96
|
+
* 'analyze_decision_process',
|
|
97
|
+
* { narrative_ulid: narrativeUlid }
|
|
98
|
+
* );
|
|
99
|
+
*
|
|
100
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
101
|
+
* if (isComplete && result) {
|
|
102
|
+
* return <div>Analysis complete: {JSON.stringify(result.result)}</div>;
|
|
103
|
+
* }
|
|
104
|
+
*
|
|
105
|
+
* return (
|
|
106
|
+
* <div>
|
|
107
|
+
* {progress && (
|
|
108
|
+
* <div>
|
|
109
|
+
* <progress value={progress.progressPercent} max={100} />
|
|
110
|
+
* <p>{progress.message}</p>
|
|
111
|
+
* </div>
|
|
112
|
+
* )}
|
|
113
|
+
* </div>
|
|
114
|
+
* );
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
declare function useComputeProgress<T = any>(functionName: string, parameters: Record<string, any>, enabled?: boolean): UseComputeProgressResult<T>;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* React hook for memory search.
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
interface UseMemorySearchOptions {
|
|
125
|
+
userUlid?: string;
|
|
126
|
+
limit?: number;
|
|
127
|
+
scope?: Scope;
|
|
128
|
+
scopeId?: string;
|
|
129
|
+
explain?: ExplainLevel;
|
|
130
|
+
}
|
|
131
|
+
interface UseMemorySearchResult {
|
|
132
|
+
search: (query: string, options?: UseMemorySearchOptions) => Promise<SearchResponse>;
|
|
133
|
+
data: SearchResponse | null;
|
|
134
|
+
loading: boolean;
|
|
135
|
+
error: Error | null;
|
|
136
|
+
reset: () => void;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Hook for memory search operations.
|
|
140
|
+
*
|
|
141
|
+
* @returns Search function and state
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```tsx
|
|
145
|
+
* function SearchBox() {
|
|
146
|
+
* const { search, data, loading, error } = useMemorySearch();
|
|
147
|
+
* const [query, setQuery] = useState('');
|
|
148
|
+
*
|
|
149
|
+
* const handleSearch = async () => {
|
|
150
|
+
* await search(query, { limit: 10 });
|
|
151
|
+
* };
|
|
152
|
+
*
|
|
153
|
+
* return (
|
|
154
|
+
* <div>
|
|
155
|
+
* <input value={query} onChange={(e) => setQuery(e.target.value)} />
|
|
156
|
+
* <button onClick={handleSearch} disabled={loading}>Search</button>
|
|
157
|
+
* {loading && <p>Searching...</p>}
|
|
158
|
+
* {error && <p>Error: {error.message}</p>}
|
|
159
|
+
* {data && (
|
|
160
|
+
* <ul>
|
|
161
|
+
* {data.results.map((result) => (
|
|
162
|
+
* <li key={result.umo_id}>{result.summary}</li>
|
|
163
|
+
* ))}
|
|
164
|
+
* </ul>
|
|
165
|
+
* )}
|
|
166
|
+
* </div>
|
|
167
|
+
* );
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
declare function useMemorySearch(): UseMemorySearchResult;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* React hook for processing content into memories.
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
interface ProcessOptions {
|
|
178
|
+
userUlid?: string;
|
|
179
|
+
retentionPolicy?: RetentionPolicy;
|
|
180
|
+
piiHandling?: PIIHandling;
|
|
181
|
+
provenanceMode?: ProvenanceMode;
|
|
182
|
+
scope?: Scope;
|
|
183
|
+
scopeId?: string;
|
|
184
|
+
source?: string;
|
|
185
|
+
metadata?: Record<string, unknown>;
|
|
186
|
+
}
|
|
187
|
+
interface UseMemoryProcessResult {
|
|
188
|
+
process: (content: string, options?: ProcessOptions) => Promise<MeaningObject>;
|
|
189
|
+
data: MeaningObject | null;
|
|
190
|
+
loading: boolean;
|
|
191
|
+
error: Error | null;
|
|
192
|
+
reset: () => void;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Hook for processing content into Meaning Objects.
|
|
196
|
+
*
|
|
197
|
+
* @returns Process function and state
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```tsx
|
|
201
|
+
* function CaptureForm() {
|
|
202
|
+
* const { process, data, loading, error } = useMemoryProcess();
|
|
203
|
+
* const [content, setContent] = useState('');
|
|
204
|
+
*
|
|
205
|
+
* const handleSubmit = async () => {
|
|
206
|
+
* await process(content, { source: 'web_form' });
|
|
207
|
+
* setContent(''); // Clear after success
|
|
208
|
+
* };
|
|
209
|
+
*
|
|
210
|
+
* return (
|
|
211
|
+
* <div>
|
|
212
|
+
* <textarea value={content} onChange={(e) => setContent(e.target.value)} />
|
|
213
|
+
* <button onClick={handleSubmit} disabled={loading}>Capture</button>
|
|
214
|
+
* {loading && <p>Processing...</p>}
|
|
215
|
+
* {error && <p>Error: {error.message}</p>}
|
|
216
|
+
* {data && <p>Created: {data.umo_id}</p>}
|
|
217
|
+
* </div>
|
|
218
|
+
* );
|
|
219
|
+
* }
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
declare function useMemoryProcess(): UseMemoryProcessResult;
|
|
223
|
+
|
|
224
|
+
export { type MemoryClientContextValue, MemoryClientProvider, type MemoryClientProviderProps, type ProcessOptions, type UseComputeProgressResult, type UseDriftSubscriptionResult, type UseMemoryProcessResult, type UseMemorySearchOptions, type UseMemorySearchResult, useComputeProgress, useDriftSubscription, useMemoryClient, useMemoryProcess, useMemorySearch };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { MemoryClient, MemoryClientConfig, DriftUpdate, DriftSubscriptionOptions, ComputeProgress, ComputeResult, Scope, ExplainLevel, SearchResponse, RetentionPolicy, PIIHandling, ProvenanceMode, MeaningObject } from '@memoryintelligence/sdk';
|
|
4
|
+
export { ComputeProgress, ComputeResult, DriftSubscriptionOptions, DriftUpdate, ExplainLevel, MeaningObject, PIIHandling, ProvenanceMode, RetentionPolicy, Scope, SearchResponse, SearchResult } from '@memoryintelligence/sdk';
|
|
5
|
+
|
|
6
|
+
interface MemoryClientContextValue {
|
|
7
|
+
client: MemoryClient | null;
|
|
8
|
+
isReady: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface MemoryClientProviderProps {
|
|
11
|
+
config: MemoryClientConfig;
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Provider component for Memory Intelligence client.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* <MemoryClientProvider config={{ apiKey: process.env.MI_API_KEY }}>
|
|
20
|
+
* <App />
|
|
21
|
+
* </MemoryClientProvider>
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function MemoryClientProvider({ config, children }: MemoryClientProviderProps): react_jsx_runtime.JSX.Element;
|
|
25
|
+
/**
|
|
26
|
+
* Hook to access the Memory Intelligence client from context.
|
|
27
|
+
*
|
|
28
|
+
* @throws Error if used outside MemoryClientProvider
|
|
29
|
+
*/
|
|
30
|
+
declare function useMemoryClient(): MemoryClient;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* React hook for drift subscriptions.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
interface UseDriftSubscriptionResult {
|
|
37
|
+
updates: DriftUpdate[];
|
|
38
|
+
latestUpdate: DriftUpdate | null;
|
|
39
|
+
connected: boolean;
|
|
40
|
+
error: Error | null;
|
|
41
|
+
clearUpdates: () => void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Hook for subscribing to drift updates.
|
|
45
|
+
*
|
|
46
|
+
* @param options - Subscription options
|
|
47
|
+
* @param maxUpdates - Maximum number of updates to keep (default: 50)
|
|
48
|
+
* @returns Drift subscription state
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```tsx
|
|
52
|
+
* function DriftMonitor({ entityUlid }) {
|
|
53
|
+
* const { updates, connected, error } = useDriftSubscription({
|
|
54
|
+
* entityUlids: [entityUlid]
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
58
|
+
*
|
|
59
|
+
* return (
|
|
60
|
+
* <div>
|
|
61
|
+
* <p>Status: {connected ? 'Connected' : 'Disconnected'}</p>
|
|
62
|
+
* {updates.map((update, i) => (
|
|
63
|
+
* <div key={i}>{update.canonicalName} - Epoch {update.driftEpoch}</div>
|
|
64
|
+
* ))}
|
|
65
|
+
* </div>
|
|
66
|
+
* );
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
declare function useDriftSubscription(options: DriftSubscriptionOptions, maxUpdates?: number): UseDriftSubscriptionResult;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* React hook for compute operation progress tracking.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
interface UseComputeProgressResult<T = any> {
|
|
77
|
+
progress: ComputeProgress | null;
|
|
78
|
+
result: ComputeResult<T> | null;
|
|
79
|
+
connected: boolean;
|
|
80
|
+
error: Error | null;
|
|
81
|
+
isComplete: boolean;
|
|
82
|
+
reset: () => void;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Hook for tracking compute operation progress.
|
|
86
|
+
*
|
|
87
|
+
* @param functionName - Name of compute function
|
|
88
|
+
* @param parameters - Function parameters
|
|
89
|
+
* @param enabled - Whether to start the subscription (default: true)
|
|
90
|
+
* @returns Compute progress state
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```tsx
|
|
94
|
+
* function AnalysisProgress({ narrativeUlid }) {
|
|
95
|
+
* const { progress, result, isComplete, error } = useComputeProgress(
|
|
96
|
+
* 'analyze_decision_process',
|
|
97
|
+
* { narrative_ulid: narrativeUlid }
|
|
98
|
+
* );
|
|
99
|
+
*
|
|
100
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
101
|
+
* if (isComplete && result) {
|
|
102
|
+
* return <div>Analysis complete: {JSON.stringify(result.result)}</div>;
|
|
103
|
+
* }
|
|
104
|
+
*
|
|
105
|
+
* return (
|
|
106
|
+
* <div>
|
|
107
|
+
* {progress && (
|
|
108
|
+
* <div>
|
|
109
|
+
* <progress value={progress.progressPercent} max={100} />
|
|
110
|
+
* <p>{progress.message}</p>
|
|
111
|
+
* </div>
|
|
112
|
+
* )}
|
|
113
|
+
* </div>
|
|
114
|
+
* );
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
declare function useComputeProgress<T = any>(functionName: string, parameters: Record<string, any>, enabled?: boolean): UseComputeProgressResult<T>;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* React hook for memory search.
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
interface UseMemorySearchOptions {
|
|
125
|
+
userUlid?: string;
|
|
126
|
+
limit?: number;
|
|
127
|
+
scope?: Scope;
|
|
128
|
+
scopeId?: string;
|
|
129
|
+
explain?: ExplainLevel;
|
|
130
|
+
}
|
|
131
|
+
interface UseMemorySearchResult {
|
|
132
|
+
search: (query: string, options?: UseMemorySearchOptions) => Promise<SearchResponse>;
|
|
133
|
+
data: SearchResponse | null;
|
|
134
|
+
loading: boolean;
|
|
135
|
+
error: Error | null;
|
|
136
|
+
reset: () => void;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Hook for memory search operations.
|
|
140
|
+
*
|
|
141
|
+
* @returns Search function and state
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```tsx
|
|
145
|
+
* function SearchBox() {
|
|
146
|
+
* const { search, data, loading, error } = useMemorySearch();
|
|
147
|
+
* const [query, setQuery] = useState('');
|
|
148
|
+
*
|
|
149
|
+
* const handleSearch = async () => {
|
|
150
|
+
* await search(query, { limit: 10 });
|
|
151
|
+
* };
|
|
152
|
+
*
|
|
153
|
+
* return (
|
|
154
|
+
* <div>
|
|
155
|
+
* <input value={query} onChange={(e) => setQuery(e.target.value)} />
|
|
156
|
+
* <button onClick={handleSearch} disabled={loading}>Search</button>
|
|
157
|
+
* {loading && <p>Searching...</p>}
|
|
158
|
+
* {error && <p>Error: {error.message}</p>}
|
|
159
|
+
* {data && (
|
|
160
|
+
* <ul>
|
|
161
|
+
* {data.results.map((result) => (
|
|
162
|
+
* <li key={result.umo_id}>{result.summary}</li>
|
|
163
|
+
* ))}
|
|
164
|
+
* </ul>
|
|
165
|
+
* )}
|
|
166
|
+
* </div>
|
|
167
|
+
* );
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
declare function useMemorySearch(): UseMemorySearchResult;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* React hook for processing content into memories.
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
interface ProcessOptions {
|
|
178
|
+
userUlid?: string;
|
|
179
|
+
retentionPolicy?: RetentionPolicy;
|
|
180
|
+
piiHandling?: PIIHandling;
|
|
181
|
+
provenanceMode?: ProvenanceMode;
|
|
182
|
+
scope?: Scope;
|
|
183
|
+
scopeId?: string;
|
|
184
|
+
source?: string;
|
|
185
|
+
metadata?: Record<string, unknown>;
|
|
186
|
+
}
|
|
187
|
+
interface UseMemoryProcessResult {
|
|
188
|
+
process: (content: string, options?: ProcessOptions) => Promise<MeaningObject>;
|
|
189
|
+
data: MeaningObject | null;
|
|
190
|
+
loading: boolean;
|
|
191
|
+
error: Error | null;
|
|
192
|
+
reset: () => void;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Hook for processing content into Meaning Objects.
|
|
196
|
+
*
|
|
197
|
+
* @returns Process function and state
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```tsx
|
|
201
|
+
* function CaptureForm() {
|
|
202
|
+
* const { process, data, loading, error } = useMemoryProcess();
|
|
203
|
+
* const [content, setContent] = useState('');
|
|
204
|
+
*
|
|
205
|
+
* const handleSubmit = async () => {
|
|
206
|
+
* await process(content, { source: 'web_form' });
|
|
207
|
+
* setContent(''); // Clear after success
|
|
208
|
+
* };
|
|
209
|
+
*
|
|
210
|
+
* return (
|
|
211
|
+
* <div>
|
|
212
|
+
* <textarea value={content} onChange={(e) => setContent(e.target.value)} />
|
|
213
|
+
* <button onClick={handleSubmit} disabled={loading}>Capture</button>
|
|
214
|
+
* {loading && <p>Processing...</p>}
|
|
215
|
+
* {error && <p>Error: {error.message}</p>}
|
|
216
|
+
* {data && <p>Created: {data.umo_id}</p>}
|
|
217
|
+
* </div>
|
|
218
|
+
* );
|
|
219
|
+
* }
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
declare function useMemoryProcess(): UseMemoryProcessResult;
|
|
223
|
+
|
|
224
|
+
export { type MemoryClientContextValue, MemoryClientProvider, type MemoryClientProviderProps, type ProcessOptions, type UseComputeProgressResult, type UseDriftSubscriptionResult, type UseMemoryProcessResult, type UseMemorySearchOptions, type UseMemorySearchResult, useComputeProgress, useDriftSubscription, useMemoryClient, useMemoryProcess, useMemorySearch };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { createContext, useState, useEffect, useContext, useRef, useCallback } from 'react';
|
|
2
|
+
import { MemoryClient } from '@memoryintelligence/sdk';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
// src/MemoryClientProvider.tsx
|
|
6
|
+
var MemoryClientContext = createContext({
|
|
7
|
+
client: null,
|
|
8
|
+
isReady: false
|
|
9
|
+
});
|
|
10
|
+
function MemoryClientProvider({ config, children }) {
|
|
11
|
+
const [client, setClient] = useState(null);
|
|
12
|
+
const [isReady, setIsReady] = useState(false);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const newClient = new MemoryClient(config);
|
|
15
|
+
setClient(newClient);
|
|
16
|
+
setIsReady(true);
|
|
17
|
+
return () => {
|
|
18
|
+
if ("disconnect" in newClient && typeof newClient.disconnect === "function") {
|
|
19
|
+
newClient.disconnect();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}, [config.apiKey, config.baseUrl, config.wsUrl, config.userUlid, config.orgUlid]);
|
|
23
|
+
return /* @__PURE__ */ jsx(MemoryClientContext.Provider, { value: { client, isReady }, children });
|
|
24
|
+
}
|
|
25
|
+
function useMemoryClient() {
|
|
26
|
+
const { client, isReady } = useContext(MemoryClientContext);
|
|
27
|
+
if (!isReady || !client) {
|
|
28
|
+
throw new Error("useMemoryClient must be used within MemoryClientProvider");
|
|
29
|
+
}
|
|
30
|
+
return client;
|
|
31
|
+
}
|
|
32
|
+
function useDriftSubscription(options, maxUpdates = 50) {
|
|
33
|
+
const client = useMemoryClient();
|
|
34
|
+
const [updates, setUpdates] = useState([]);
|
|
35
|
+
const [latestUpdate, setLatestUpdate] = useState(null);
|
|
36
|
+
const [connected, setConnected] = useState(false);
|
|
37
|
+
const [error, setError] = useState(null);
|
|
38
|
+
const subscriptionRef = useRef(null);
|
|
39
|
+
const clearUpdates = useCallback(() => {
|
|
40
|
+
setUpdates([]);
|
|
41
|
+
setLatestUpdate(null);
|
|
42
|
+
}, []);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
const subscription = client.drift.watch(options);
|
|
45
|
+
subscriptionRef.current = subscription;
|
|
46
|
+
subscription.on("connected", () => {
|
|
47
|
+
setConnected(true);
|
|
48
|
+
setError(null);
|
|
49
|
+
});
|
|
50
|
+
subscription.on("disconnected", () => {
|
|
51
|
+
setConnected(false);
|
|
52
|
+
});
|
|
53
|
+
subscription.on("update", (update) => {
|
|
54
|
+
setLatestUpdate(update);
|
|
55
|
+
setUpdates((prev) => [update, ...prev].slice(0, maxUpdates));
|
|
56
|
+
});
|
|
57
|
+
subscription.on("error", (err) => {
|
|
58
|
+
setError(err);
|
|
59
|
+
setConnected(false);
|
|
60
|
+
});
|
|
61
|
+
subscription.start().catch((err) => {
|
|
62
|
+
setError(err);
|
|
63
|
+
});
|
|
64
|
+
return () => {
|
|
65
|
+
subscription.stop();
|
|
66
|
+
};
|
|
67
|
+
}, [
|
|
68
|
+
client,
|
|
69
|
+
maxUpdates,
|
|
70
|
+
JSON.stringify(options.entityUlids),
|
|
71
|
+
options.orgUlid
|
|
72
|
+
]);
|
|
73
|
+
return {
|
|
74
|
+
updates,
|
|
75
|
+
latestUpdate,
|
|
76
|
+
connected,
|
|
77
|
+
error,
|
|
78
|
+
clearUpdates
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function useComputeProgress(functionName, parameters, enabled = true) {
|
|
82
|
+
const client = useMemoryClient();
|
|
83
|
+
const [progress, setProgress] = useState(null);
|
|
84
|
+
const [result, setResult] = useState(null);
|
|
85
|
+
const [connected, setConnected] = useState(false);
|
|
86
|
+
const [error, setError] = useState(null);
|
|
87
|
+
const [isComplete, setIsComplete] = useState(false);
|
|
88
|
+
const subscriptionRef = useRef(null);
|
|
89
|
+
const reset = useCallback(() => {
|
|
90
|
+
setProgress(null);
|
|
91
|
+
setResult(null);
|
|
92
|
+
setError(null);
|
|
93
|
+
setIsComplete(false);
|
|
94
|
+
}, []);
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (!enabled) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
reset();
|
|
100
|
+
const subscription = client.compute.watch(functionName, parameters);
|
|
101
|
+
subscriptionRef.current = subscription;
|
|
102
|
+
subscription.on("connected", () => {
|
|
103
|
+
setConnected(true);
|
|
104
|
+
setError(null);
|
|
105
|
+
});
|
|
106
|
+
subscription.on("disconnected", () => {
|
|
107
|
+
setConnected(false);
|
|
108
|
+
});
|
|
109
|
+
subscription.on("progress", (progressUpdate) => {
|
|
110
|
+
setProgress(progressUpdate);
|
|
111
|
+
});
|
|
112
|
+
subscription.on("result", (resultData) => {
|
|
113
|
+
setResult(resultData);
|
|
114
|
+
setIsComplete(true);
|
|
115
|
+
setConnected(false);
|
|
116
|
+
});
|
|
117
|
+
subscription.on("error", (err) => {
|
|
118
|
+
setError(err);
|
|
119
|
+
setConnected(false);
|
|
120
|
+
});
|
|
121
|
+
subscription.start().catch((err) => {
|
|
122
|
+
setError(err);
|
|
123
|
+
});
|
|
124
|
+
return () => {
|
|
125
|
+
subscription.stop();
|
|
126
|
+
};
|
|
127
|
+
}, [
|
|
128
|
+
client,
|
|
129
|
+
functionName,
|
|
130
|
+
JSON.stringify(parameters),
|
|
131
|
+
enabled,
|
|
132
|
+
reset
|
|
133
|
+
]);
|
|
134
|
+
return {
|
|
135
|
+
progress,
|
|
136
|
+
result,
|
|
137
|
+
connected,
|
|
138
|
+
error,
|
|
139
|
+
isComplete,
|
|
140
|
+
reset
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function useMemorySearch() {
|
|
144
|
+
const client = useMemoryClient();
|
|
145
|
+
const [data, setData] = useState(null);
|
|
146
|
+
const [loading, setLoading] = useState(false);
|
|
147
|
+
const [error, setError] = useState(null);
|
|
148
|
+
const search = useCallback(
|
|
149
|
+
async (query, options) => {
|
|
150
|
+
setLoading(true);
|
|
151
|
+
setError(null);
|
|
152
|
+
try {
|
|
153
|
+
const response = await client.umo.search(query, options);
|
|
154
|
+
setData(response);
|
|
155
|
+
return response;
|
|
156
|
+
} catch (err) {
|
|
157
|
+
const error2 = err instanceof Error ? err : new Error("Search failed");
|
|
158
|
+
setError(error2);
|
|
159
|
+
throw error2;
|
|
160
|
+
} finally {
|
|
161
|
+
setLoading(false);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
[client]
|
|
165
|
+
);
|
|
166
|
+
const reset = useCallback(() => {
|
|
167
|
+
setData(null);
|
|
168
|
+
setError(null);
|
|
169
|
+
setLoading(false);
|
|
170
|
+
}, []);
|
|
171
|
+
return {
|
|
172
|
+
search,
|
|
173
|
+
data,
|
|
174
|
+
loading,
|
|
175
|
+
error,
|
|
176
|
+
reset
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function useMemoryProcess() {
|
|
180
|
+
const client = useMemoryClient();
|
|
181
|
+
const [data, setData] = useState(null);
|
|
182
|
+
const [loading, setLoading] = useState(false);
|
|
183
|
+
const [error, setError] = useState(null);
|
|
184
|
+
const process = useCallback(
|
|
185
|
+
async (content, options) => {
|
|
186
|
+
setLoading(true);
|
|
187
|
+
setError(null);
|
|
188
|
+
try {
|
|
189
|
+
const umo = await client.umo.process(content, options);
|
|
190
|
+
setData(umo);
|
|
191
|
+
return umo;
|
|
192
|
+
} catch (err) {
|
|
193
|
+
const error2 = err instanceof Error ? err : new Error("Process failed");
|
|
194
|
+
setError(error2);
|
|
195
|
+
throw error2;
|
|
196
|
+
} finally {
|
|
197
|
+
setLoading(false);
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
[client]
|
|
201
|
+
);
|
|
202
|
+
const reset = useCallback(() => {
|
|
203
|
+
setData(null);
|
|
204
|
+
setError(null);
|
|
205
|
+
setLoading(false);
|
|
206
|
+
}, []);
|
|
207
|
+
return {
|
|
208
|
+
process,
|
|
209
|
+
data,
|
|
210
|
+
loading,
|
|
211
|
+
error,
|
|
212
|
+
reset
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export { MemoryClientProvider, useComputeProgress, useDriftSubscription, useMemoryClient, useMemoryProcess, useMemorySearch };
|
|
217
|
+
//# sourceMappingURL=index.js.map
|
|
218
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/MemoryClientProvider.tsx","../src/useDriftSubscription.ts","../src/useComputeProgress.ts","../src/useMemorySearch.ts","../src/useMemoryProcess.ts"],"names":["useState","useEffect","useRef","useCallback","error"],"mappings":";;;;;AAYA,IAAM,sBAAsB,aAAA,CAAwC;AAAA,EAClE,MAAA,EAAQ,IAAA;AAAA,EACR,OAAA,EAAS;AACX,CAAC,CAAA;AAiBM,SAAS,oBAAA,CAAqB,EAAE,MAAA,EAAQ,QAAA,EAAS,EAA8B;AACpF,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAI,SAA8B,IAAI,CAAA;AAC9D,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAI,SAAS,KAAK,CAAA;AAE5C,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,MAAM,SAAA,GAAY,IAAI,YAAA,CAAa,MAAM,CAAA;AACzC,IAAA,SAAA,CAAU,SAAS,CAAA;AACnB,IAAA,UAAA,CAAW,IAAI,CAAA;AAEf,IAAA,OAAO,MAAM;AAEX,MAAA,IAAI,YAAA,IAAgB,SAAA,IAAa,OAAO,SAAA,CAAU,eAAe,UAAA,EAAY;AAC3E,QAAA,SAAA,CAAU,UAAA,EAAW;AAAA,MACvB;AAAA,IACF,CAAA;AAAA,EAC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AAA;AAAA,IACd,OAAO,SAAiB,OAAA,KAAqD;AAC3E,MAAA,UAAA,CAAW,IAAI,CAAA;AACf,MAAA,QAAA,CAAS,IAAI,CAAA;AAEb,MAAA,IAAI;AACF,QAAA,MAAM,MAAM,MAAM,MAAA,CAAO,GAAA,CAAI,OAAA,CAAQ,SAAS,OAAO,CAAA;AACrD,QAAA,OAAA,CAAQ,GAAG,CAAA;AACX,QAAA,OAAO,GAAA;AAAA,MACT,SAAS,GAAA,EAAK;AACZ,QAAA,MAAMC,SAAQ,GAAA,YAAe,KAAA,GAAQ,GAAA,GAAM,IAAI,MAAM,gBAAgB,CAAA;AACrE,QAAA,QAAA,CAASA,MAAK,CAAA;AACd,QAAA,MAAMA,MAAAA;AAAA,MACR,CAAA,SAAE;AACA,QAAA,UAAA,CAAW,KAAK,CAAA;AAAA,MAClB;AAAA,IACF,CAAA;AAAA,IACA,CAAC,MAAM;AAAA,GACT;AAEA,EAAA,MAAM,KAAA,GAAQD,YAAY,MAAM;AAC9B,IAAA,OAAA,CAAQ,IAAI,CAAA;AACZ,IAAA,QAAA,CAAS,IAAI,CAAA;AACb,IAAA,UAAA,CAAW,KAAK,CAAA;AAAA,EAClB,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,IAAA;AAAA,IACA,OAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * React context provider for Memory Intelligence client.\n */\n\nimport React, { createContext, useContext, useEffect, useState } from 'react';\nimport { MemoryClient, type MemoryClientConfig } from '@memoryintelligence/sdk';\n\nexport interface MemoryClientContextValue {\n client: MemoryClient | null;\n isReady: boolean;\n}\n\nconst MemoryClientContext = createContext<MemoryClientContextValue>({\n client: null,\n isReady: false,\n});\n\nexport interface MemoryClientProviderProps {\n config: MemoryClientConfig;\n children: React.ReactNode;\n}\n\n/**\n * Provider component for Memory Intelligence client.\n * \n * @example\n * ```tsx\n * <MemoryClientProvider config={{ apiKey: process.env.MI_API_KEY }}>\n * <App />\n * </MemoryClientProvider>\n * ```\n */\nexport function MemoryClientProvider({ config, children }: MemoryClientProviderProps) {\n const [client, setClient] = useState<MemoryClient | null>(null);\n const [isReady, setIsReady] = useState(false);\n\n useEffect(() => {\n const newClient = new MemoryClient(config);\n setClient(newClient);\n setIsReady(true);\n\n return () => {\n // Cleanup WebSocket connections if client has disconnect method\n if ('disconnect' in newClient && typeof newClient.disconnect === 'function') {\n newClient.disconnect();\n }\n };\n }, [config.apiKey, config.baseUrl, config.wsUrl, config.userUlid, config.orgUlid]);\n\n return (\n <MemoryClientContext.Provider value={{ client, isReady }}>\n {children}\n </MemoryClientContext.Provider>\n );\n}\n\n/**\n * Hook to access the Memory Intelligence client from context.\n * \n * @throws Error if used outside MemoryClientProvider\n */\nexport function useMemoryClient(): MemoryClient {\n const { client, isReady } = useContext(MemoryClientContext);\n\n if (!isReady || !client) {\n throw new Error('useMemoryClient must be used within MemoryClientProvider');\n }\n\n return client;\n}\n","/**\n * React hook for drift subscriptions.\n */\n\nimport { useEffect, useState, useCallback, useRef } from 'react';\nimport type { DriftSubscription, DriftUpdate, DriftSubscriptionOptions } from '@memoryintelligence/sdk';\nimport { useMemoryClient } from './MemoryClientProvider.js';\n\nexport interface UseDriftSubscriptionResult {\n updates: DriftUpdate[];\n latestUpdate: DriftUpdate | null;\n connected: boolean;\n error: Error | null;\n clearUpdates: () => void;\n}\n\n/**\n * Hook for subscribing to drift updates.\n * \n * @param options - Subscription options\n * @param maxUpdates - Maximum number of updates to keep (default: 50)\n * @returns Drift subscription state\n * \n * @example\n * ```tsx\n * function DriftMonitor({ entityUlid }) {\n * const { updates, connected, error } = useDriftSubscription({\n * entityUlids: [entityUlid]\n * });\n * \n * if (error) return <div>Error: {error.message}</div>;\n * \n * return (\n * <div>\n * <p>Status: {connected ? 'Connected' : 'Disconnected'}</p>\n * {updates.map((update, i) => (\n * <div key={i}>{update.canonicalName} - Epoch {update.driftEpoch}</div>\n * ))}\n * </div>\n * );\n * }\n * ```\n */\nexport function useDriftSubscription(\n options: DriftSubscriptionOptions,\n maxUpdates: number = 50\n): UseDriftSubscriptionResult {\n const client = useMemoryClient();\n const [updates, setUpdates] = useState<DriftUpdate[]>([]);\n const [latestUpdate, setLatestUpdate] = useState<DriftUpdate | null>(null);\n const [connected, setConnected] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const subscriptionRef = useRef<DriftSubscription | null>(null);\n\n const clearUpdates = useCallback(() => {\n setUpdates([]);\n setLatestUpdate(null);\n }, []);\n\n useEffect(() => {\n const subscription = client.drift.watch(options);\n subscriptionRef.current = subscription;\n\n subscription.on('connected', () => {\n setConnected(true);\n setError(null);\n });\n\n subscription.on('disconnected', () => {\n setConnected(false);\n });\n\n subscription.on('update', (update) => {\n setLatestUpdate(update);\n setUpdates((prev) => [update, ...prev].slice(0, maxUpdates));\n });\n\n subscription.on('error', (err: any) => {\n setError(err);\n setConnected(false);\n });\n\n subscription.start().catch((err) => {\n setError(err);\n });\n\n return () => {\n subscription.stop();\n };\n }, [\n client,\n maxUpdates,\n JSON.stringify(options.entityUlids),\n options.orgUlid,\n ]);\n\n return {\n updates,\n latestUpdate,\n connected,\n error,\n clearUpdates,\n };\n}\n","/**\n * React hook for compute operation progress tracking.\n */\n\nimport { useEffect, useState, useCallback, useRef } from 'react';\nimport type { ComputeSubscription, ComputeProgress, ComputeResult } from '@memoryintelligence/sdk';\nimport { useMemoryClient } from './MemoryClientProvider.js';\n\nexport interface UseComputeProgressResult<T = any> {\n progress: ComputeProgress | null;\n result: ComputeResult<T> | null;\n connected: boolean;\n error: Error | null;\n isComplete: boolean;\n reset: () => void;\n}\n\n/**\n * Hook for tracking compute operation progress.\n * \n * @param functionName - Name of compute function\n * @param parameters - Function parameters\n * @param enabled - Whether to start the subscription (default: true)\n * @returns Compute progress state\n * \n * @example\n * ```tsx\n * function AnalysisProgress({ narrativeUlid }) {\n * const { progress, result, isComplete, error } = useComputeProgress(\n * 'analyze_decision_process',\n * { narrative_ulid: narrativeUlid }\n * );\n * \n * if (error) return <div>Error: {error.message}</div>;\n * if (isComplete && result) {\n * return <div>Analysis complete: {JSON.stringify(result.result)}</div>;\n * }\n * \n * return (\n * <div>\n * {progress && (\n * <div>\n * <progress value={progress.progressPercent} max={100} />\n * <p>{progress.message}</p>\n * </div>\n * )}\n * </div>\n * );\n * }\n * ```\n */\nexport function useComputeProgress<T = any>(\n functionName: string,\n parameters: Record<string, any>,\n enabled: boolean = true\n): UseComputeProgressResult<T> {\n const client = useMemoryClient();\n const [progress, setProgress] = useState<ComputeProgress | null>(null);\n const [result, setResult] = useState<ComputeResult<T> | null>(null);\n const [connected, setConnected] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [isComplete, setIsComplete] = useState(false);\n const subscriptionRef = useRef<ComputeSubscription<T> | null>(null);\n\n const reset = useCallback(() => {\n setProgress(null);\n setResult(null);\n setError(null);\n setIsComplete(false);\n }, []);\n\n useEffect(() => {\n if (!enabled) {\n return;\n }\n\n reset();\n\n const subscription = client.compute.watch<T>(functionName, parameters);\n subscriptionRef.current = subscription;\n\n subscription.on('connected', () => {\n setConnected(true);\n setError(null);\n });\n\n subscription.on('disconnected', () => {\n setConnected(false);\n });\n\n subscription.on('progress', (progressUpdate) => {\n setProgress(progressUpdate as ComputeProgress);\n });\n\n subscription.on('result', (resultData) => {\n setResult(resultData as ComputeResult<T>);\n setIsComplete(true);\n setConnected(false); // Auto-unsubscribes after result\n });\n\n subscription.on('error', (err: any) => {\n setError(err);\n setConnected(false);\n });\n\n subscription.start().catch((err) => {\n setError(err);\n });\n\n return () => {\n subscription.stop();\n };\n }, [\n client,\n functionName,\n JSON.stringify(parameters),\n enabled,\n reset,\n ]);\n\n return {\n progress,\n result,\n connected,\n error,\n isComplete,\n reset,\n };\n}\n","/**\n * React hook for memory search.\n */\n\nimport { useState, useCallback } from 'react';\nimport type { SearchResponse, Scope, ExplainLevel } from '@memoryintelligence/sdk';\nimport { useMemoryClient } from './MemoryClientProvider.js';\n\nexport interface UseMemorySearchOptions {\n userUlid?: string;\n limit?: number;\n scope?: Scope;\n scopeId?: string;\n explain?: ExplainLevel;\n}\n\nexport interface UseMemorySearchResult {\n search: (query: string, options?: UseMemorySearchOptions) => Promise<SearchResponse>;\n data: SearchResponse | null;\n loading: boolean;\n error: Error | null;\n reset: () => void;\n}\n\n/**\n * Hook for memory search operations.\n * \n * @returns Search function and state\n * \n * @example\n * ```tsx\n * function SearchBox() {\n * const { search, data, loading, error } = useMemorySearch();\n * const [query, setQuery] = useState('');\n * \n * const handleSearch = async () => {\n * await search(query, { limit: 10 });\n * };\n * \n * return (\n * <div>\n * <input value={query} onChange={(e) => setQuery(e.target.value)} />\n * <button onClick={handleSearch} disabled={loading}>Search</button>\n * {loading && <p>Searching...</p>}\n * {error && <p>Error: {error.message}</p>}\n * {data && (\n * <ul>\n * {data.results.map((result) => (\n * <li key={result.umo_id}>{result.summary}</li>\n * ))}\n * </ul>\n * )}\n * </div>\n * );\n * }\n * ```\n */\nexport function useMemorySearch(): UseMemorySearchResult {\n const client = useMemoryClient();\n const [data, setData] = useState<SearchResponse | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const search = useCallback(\n async (query: string, options?: UseMemorySearchOptions): Promise<SearchResponse> => {\n setLoading(true);\n setError(null);\n\n try {\n const response = await client.umo.search(query, options);\n setData(response);\n return response;\n } catch (err) {\n const error = err instanceof Error ? err : new Error('Search failed');\n setError(error);\n throw error;\n } finally {\n setLoading(false);\n }\n },\n [client]\n );\n\n const reset = useCallback(() => {\n setData(null);\n setError(null);\n setLoading(false);\n }, []);\n\n return {\n search,\n data,\n loading,\n error,\n reset,\n };\n}\n","/**\n * React hook for processing content into memories.\n */\n\nimport { useState, useCallback } from 'react';\nimport type {\n MeaningObject,\n RetentionPolicy,\n PIIHandling,\n ProvenanceMode,\n Scope,\n} from '@memoryintelligence/sdk';\nimport { useMemoryClient } from './MemoryClientProvider.js';\n\nexport interface ProcessOptions {\n userUlid?: string;\n retentionPolicy?: RetentionPolicy;\n piiHandling?: PIIHandling;\n provenanceMode?: ProvenanceMode;\n scope?: Scope;\n scopeId?: string;\n source?: string;\n metadata?: Record<string, unknown>;\n}\n\nexport interface UseMemoryProcessResult {\n process: (content: string, options?: ProcessOptions) => Promise<MeaningObject>;\n data: MeaningObject | null;\n loading: boolean;\n error: Error | null;\n reset: () => void;\n}\n\n/**\n * Hook for processing content into Meaning Objects.\n * \n * @returns Process function and state\n * \n * @example\n * ```tsx\n * function CaptureForm() {\n * const { process, data, loading, error } = useMemoryProcess();\n * const [content, setContent] = useState('');\n * \n * const handleSubmit = async () => {\n * await process(content, { source: 'web_form' });\n * setContent(''); // Clear after success\n * };\n * \n * return (\n * <div>\n * <textarea value={content} onChange={(e) => setContent(e.target.value)} />\n * <button onClick={handleSubmit} disabled={loading}>Capture</button>\n * {loading && <p>Processing...</p>}\n * {error && <p>Error: {error.message}</p>}\n * {data && <p>Created: {data.umo_id}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useMemoryProcess(): UseMemoryProcessResult {\n const client = useMemoryClient();\n const [data, setData] = useState<MeaningObject | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const process = useCallback(\n async (content: string, options?: ProcessOptions): Promise<MeaningObject> => {\n setLoading(true);\n setError(null);\n\n try {\n const umo = await client.umo.process(content, options);\n setData(umo);\n return umo;\n } catch (err) {\n const error = err instanceof Error ? err : new Error('Process failed');\n setError(error);\n throw error;\n } finally {\n setLoading(false);\n }\n },\n [client]\n );\n\n const reset = useCallback(() => {\n setData(null);\n setError(null);\n setLoading(false);\n }, []);\n\n return {\n process,\n data,\n loading,\n error,\n reset,\n };\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@memoryintelligence/react",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "React hooks for Memory Intelligence SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup",
|
|
21
|
+
"type-check": "tsc --noEmit",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"memory-intelligence",
|
|
27
|
+
"react",
|
|
28
|
+
"hooks",
|
|
29
|
+
"drift",
|
|
30
|
+
"websocket",
|
|
31
|
+
"subscriptions"
|
|
32
|
+
],
|
|
33
|
+
"author": "Memory Intelligence",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@memoryintelligence/sdk": "^2.0.0",
|
|
37
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@memoryintelligence/sdk": "file:../js",
|
|
41
|
+
"@testing-library/react": "^16.1.0",
|
|
42
|
+
"@types/react": "^18.3.18",
|
|
43
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
44
|
+
"react": "^18.3.1",
|
|
45
|
+
"react-dom": "^18.3.1",
|
|
46
|
+
"tsup": "^8.3.5",
|
|
47
|
+
"typescript": "^5.7.3",
|
|
48
|
+
"vitest": "^1.6.1"
|
|
49
|
+
},
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "https://github.com/somewhere11/MemoryIntelligence",
|
|
53
|
+
"directory": "sdk/react"
|
|
54
|
+
}
|
|
55
|
+
}
|