@cilow/sdk 0.2.0 → 0.2.1

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.
Files changed (45) hide show
  1. package/README.md +412 -199
  2. package/dist/client.d.mts +224 -0
  3. package/dist/client.d.ts +224 -0
  4. package/dist/client.js +509 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/client.mjs +505 -0
  7. package/dist/client.mjs.map +1 -0
  8. package/dist/index.d.mts +94 -390
  9. package/dist/index.d.ts +94 -390
  10. package/dist/index.js +745 -350
  11. package/dist/index.js.map +1 -0
  12. package/dist/index.mjs +732 -318
  13. package/dist/index.mjs.map +1 -0
  14. package/dist/providers/langchain.js +821 -0
  15. package/dist/providers/langchain.js.map +1 -0
  16. package/dist/providers/langchain.mjs +816 -0
  17. package/dist/providers/langchain.mjs.map +1 -0
  18. package/dist/providers/openai.js +737 -0
  19. package/dist/providers/openai.js.map +1 -0
  20. package/dist/providers/openai.mjs +732 -0
  21. package/dist/providers/openai.mjs.map +1 -0
  22. package/dist/providers/vercel.js +866 -0
  23. package/dist/providers/vercel.js.map +1 -0
  24. package/dist/providers/vercel.mjs +860 -0
  25. package/dist/providers/vercel.mjs.map +1 -0
  26. package/dist/react/hooks.d.mts +327 -0
  27. package/dist/react/hooks.d.ts +327 -0
  28. package/dist/react/hooks.js +1183 -0
  29. package/dist/react/hooks.js.map +1 -0
  30. package/dist/react/hooks.mjs +1172 -0
  31. package/dist/react/hooks.mjs.map +1 -0
  32. package/dist/types.d.mts +494 -0
  33. package/dist/types.d.ts +494 -0
  34. package/dist/types.js +18 -0
  35. package/dist/types.js.map +1 -0
  36. package/dist/types.mjs +14 -0
  37. package/dist/types.mjs.map +1 -0
  38. package/dist/websocket.d.mts +160 -0
  39. package/dist/websocket.d.ts +160 -0
  40. package/dist/websocket.js +342 -0
  41. package/dist/websocket.js.map +1 -0
  42. package/dist/websocket.mjs +339 -0
  43. package/dist/websocket.mjs.map +1 -0
  44. package/package.json +90 -31
  45. package/LICENSE +0 -21
@@ -0,0 +1,327 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import { CilowClient } from '../client.js';
5
+ import { CilowWebSocket } from '../websocket.js';
6
+ import { CilowConfig, WebSocketConfig, CreateMemoryOptions, Memory, SearchResult, CilowEvent, MemoryStats } from '../types.js';
7
+
8
+ /**
9
+ * Cilow context value
10
+ */
11
+ interface CilowContextValue {
12
+ /** Cilow client instance */
13
+ client: CilowClient;
14
+ /** WebSocket connection (if enabled) */
15
+ ws: CilowWebSocket | null;
16
+ /** Current user ID */
17
+ userId?: string;
18
+ /** Current session ID */
19
+ sessionId?: string;
20
+ /** Set user ID */
21
+ setUserId: (userId: string) => void;
22
+ /** Set session ID */
23
+ setSessionId: (sessionId: string) => void;
24
+ /** Whether WebSocket is connected */
25
+ isConnected: boolean;
26
+ }
27
+ /**
28
+ * Props for CilowProvider
29
+ */
30
+ interface CilowProviderProps extends CilowConfig, Partial<WebSocketConfig> {
31
+ /** React children */
32
+ children: ReactNode;
33
+ /** Initial user ID */
34
+ userId?: string;
35
+ /** Initial session ID */
36
+ sessionId?: string;
37
+ /** Enable WebSocket connection */
38
+ enableWebSocket?: boolean;
39
+ }
40
+ /**
41
+ * CilowProvider - Context provider for Cilow SDK
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * function App() {
46
+ * return (
47
+ * <CilowProvider
48
+ * apiUrl="https://api.cilow.ai"
49
+ * apiKey="your-key"
50
+ * userId="user-123"
51
+ * enableWebSocket={true}
52
+ * >
53
+ * <YourApp />
54
+ * </CilowProvider>
55
+ * );
56
+ * }
57
+ * ```
58
+ */
59
+ declare function CilowProvider({ children, userId: initialUserId, sessionId: initialSessionId, enableWebSocket, ...config }: CilowProviderProps): react_jsx_runtime.JSX.Element;
60
+ /**
61
+ * Hook to access Cilow context
62
+ */
63
+ declare function useCilow(): CilowContextValue;
64
+ /**
65
+ * State for useMemory hook
66
+ */
67
+ interface UseMemoryState {
68
+ /** Store a new memory */
69
+ remember: (content: string, options?: CreateMemoryOptions) => Promise<string>;
70
+ /** Delete memories */
71
+ forget: (filter: {
72
+ memoryId?: string;
73
+ tags?: string[];
74
+ }) => Promise<number>;
75
+ /** Get a memory by ID */
76
+ getMemory: (memoryId: string) => Promise<Memory>;
77
+ /** Loading state */
78
+ isLoading: boolean;
79
+ /** Error state */
80
+ error: Error | null;
81
+ }
82
+ /**
83
+ * useMemory - Hook for memory CRUD operations
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * function MyComponent() {
88
+ * const { remember, forget, isLoading, error } = useMemory();
89
+ *
90
+ * const handleSave = async () => {
91
+ * await remember("Important information", { tags: ["important"] });
92
+ * };
93
+ *
94
+ * const handleDelete = async (memoryId: string) => {
95
+ * await forget({ memoryId });
96
+ * };
97
+ *
98
+ * return <div>...</div>;
99
+ * }
100
+ * ```
101
+ */
102
+ declare function useMemory(): UseMemoryState;
103
+ /**
104
+ * State for useRecall hook
105
+ */
106
+ interface UseRecallState {
107
+ /** Search results */
108
+ data: SearchResult[];
109
+ /** Execute search */
110
+ search: (query: string, options?: {
111
+ limit?: number;
112
+ tags?: string[];
113
+ }) => Promise<void>;
114
+ /** Clear results */
115
+ clear: () => void;
116
+ /** Loading state */
117
+ isLoading: boolean;
118
+ /** Error state */
119
+ error: Error | null;
120
+ }
121
+ /**
122
+ * useRecall - Hook for searching memories
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * function SearchComponent() {
127
+ * const { data, search, isLoading, error } = useRecall();
128
+ * const [query, setQuery] = useState('');
129
+ *
130
+ * const handleSearch = () => {
131
+ * search(query, { limit: 10 });
132
+ * };
133
+ *
134
+ * return (
135
+ * <div>
136
+ * <input value={query} onChange={e => setQuery(e.target.value)} />
137
+ * <button onClick={handleSearch} disabled={isLoading}>Search</button>
138
+ * {data.map(result => (
139
+ * <div key={result.memory.id}>
140
+ * <p>{result.memory.content}</p>
141
+ * <span>Score: {result.score}</span>
142
+ * </div>
143
+ * ))}
144
+ * </div>
145
+ * );
146
+ * }
147
+ * ```
148
+ */
149
+ declare function useRecall(): UseRecallState;
150
+ /**
151
+ * Options for useMemorySubscription
152
+ */
153
+ interface UseMemorySubscriptionOptions {
154
+ /** Filter by user ID */
155
+ userId?: string;
156
+ /** Filter by session ID */
157
+ sessionId?: string;
158
+ /** Filter by tags */
159
+ tags?: string[];
160
+ /** Event types to subscribe to */
161
+ eventTypes?: ('memory.created' | 'memory.updated' | 'memory.deleted')[];
162
+ }
163
+ /**
164
+ * State for useMemorySubscription hook
165
+ */
166
+ interface UseMemorySubscriptionState {
167
+ /** Latest event */
168
+ latestEvent: CilowEvent | null;
169
+ /** All events received */
170
+ events: CilowEvent[];
171
+ /** Whether connected */
172
+ isConnected: boolean;
173
+ /** Clear events */
174
+ clearEvents: () => void;
175
+ }
176
+ /**
177
+ * useMemorySubscription - Hook for real-time memory updates
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * function LiveMemories() {
182
+ * const { latestEvent, events, isConnected } = useMemorySubscription({
183
+ * userId: 'user-123'
184
+ * });
185
+ *
186
+ * useEffect(() => {
187
+ * if (latestEvent?.type === 'memory.created') {
188
+ * console.log('New memory:', latestEvent.memory);
189
+ * }
190
+ * }, [latestEvent]);
191
+ *
192
+ * return (
193
+ * <div>
194
+ * <p>Status: {isConnected ? 'Connected' : 'Disconnected'}</p>
195
+ * <p>Events received: {events.length}</p>
196
+ * </div>
197
+ * );
198
+ * }
199
+ * ```
200
+ */
201
+ declare function useMemorySubscription(options?: UseMemorySubscriptionOptions): UseMemorySubscriptionState;
202
+ /**
203
+ * useMemoryContext - Hook for getting AI context from memories
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * function ChatInput() {
208
+ * const { getContext, context, isLoading } = useMemoryContext();
209
+ *
210
+ * const handleSend = async (message: string) => {
211
+ * const ctx = await getContext(message);
212
+ *
213
+ * // Use ctx.context as system message or context
214
+ * await sendToAI(message, ctx.context);
215
+ * };
216
+ *
217
+ * return <input onSubmit={handleSend} />;
218
+ * }
219
+ * ```
220
+ */
221
+ declare function useMemoryContext(): {
222
+ getContext: (query: string, options?: {
223
+ maxTokens?: number;
224
+ tags?: string[];
225
+ }) => Promise<{
226
+ context: string;
227
+ memoriesUsed: number;
228
+ }>;
229
+ context: string;
230
+ memoriesUsed: number;
231
+ clearContext: () => void;
232
+ isLoading: boolean;
233
+ error: Error | null;
234
+ };
235
+ /**
236
+ * useMemoryStats - Hook for memory statistics
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * function StatsPanel() {
241
+ * const { stats, refresh, isLoading } = useMemoryStats();
242
+ *
243
+ * return (
244
+ * <div>
245
+ * <p>Total memories: {stats?.totalMemories ?? 0}</p>
246
+ * <p>Hot: {stats?.hotMemories ?? 0}</p>
247
+ * <p>Warm: {stats?.warmMemories ?? 0}</p>
248
+ * <p>Cold: {stats?.coldMemories ?? 0}</p>
249
+ * <button onClick={refresh} disabled={isLoading}>Refresh</button>
250
+ * </div>
251
+ * );
252
+ * }
253
+ * ```
254
+ */
255
+ declare function useMemoryStats(): {
256
+ stats: MemoryStats | null;
257
+ refresh: () => Promise<void>;
258
+ isLoading: boolean;
259
+ error: Error | null;
260
+ };
261
+ /**
262
+ * useConversation - Hook for storing conversation turns
263
+ *
264
+ * @example
265
+ * ```typescript
266
+ * function Chat() {
267
+ * const { storeConversation, isLoading } = useConversation();
268
+ *
269
+ * const handleMessage = async (userMsg: string, aiResponse: string) => {
270
+ * // Store after getting AI response
271
+ * await storeConversation(userMsg, aiResponse);
272
+ * };
273
+ *
274
+ * return <ChatUI onMessage={handleMessage} />;
275
+ * }
276
+ * ```
277
+ */
278
+ declare function useConversation(): {
279
+ storeConversation: (userMessage: string, assistantResponse: string, metadata?: Record<string, unknown>) => Promise<string>;
280
+ storedCount: number;
281
+ isLoading: boolean;
282
+ error: Error | null;
283
+ };
284
+ /**
285
+ * useDebounce - Debounce a value
286
+ */
287
+ declare function useDebounce<T>(value: T, delay: number): T;
288
+ /**
289
+ * useDebouncedSearch - Hook for debounced memory search
290
+ *
291
+ * @example
292
+ * ```typescript
293
+ * function SearchWithDebounce() {
294
+ * const { query, setQuery, results, isLoading } = useDebouncedSearch({
295
+ * delay: 300
296
+ * });
297
+ *
298
+ * return (
299
+ * <div>
300
+ * <input
301
+ * value={query}
302
+ * onChange={e => setQuery(e.target.value)}
303
+ * placeholder="Search memories..."
304
+ * />
305
+ * {isLoading && <p>Searching...</p>}
306
+ * {results.map(r => (
307
+ * <div key={r.memory.id}>{r.memory.content}</div>
308
+ * ))}
309
+ * </div>
310
+ * );
311
+ * }
312
+ * ```
313
+ */
314
+ declare function useDebouncedSearch(options?: {
315
+ delay?: number;
316
+ minLength?: number;
317
+ limit?: number;
318
+ }): {
319
+ query: string;
320
+ setQuery: react.Dispatch<react.SetStateAction<string>>;
321
+ results: SearchResult[];
322
+ clear: () => void;
323
+ isLoading: boolean;
324
+ error: Error | null;
325
+ };
326
+
327
+ export { type CilowContextValue, CilowProvider, type CilowProviderProps, type UseMemoryState, type UseMemorySubscriptionOptions, type UseMemorySubscriptionState, type UseRecallState, useCilow, useConversation, useDebounce, useDebouncedSearch, useMemory, useMemoryContext, useMemoryStats, useMemorySubscription, useRecall };