@lanonasis/memory-client 1.0.0 → 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/dist/core/index.d.ts +421 -0
- package/dist/core/index.js +490 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index.d.ts +159 -395
- package/dist/index.esm.js +321 -737
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +329 -744
- package/dist/index.js.map +1 -1
- package/dist/node/index.d.ts +301 -0
- package/dist/node/index.js +610 -0
- package/dist/node/index.js.map +1 -0
- package/dist/presets/index.d.ts +146 -0
- package/dist/presets/index.js +234 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/react/index.d.ts +213 -0
- package/dist/react/index.js +348 -0
- package/dist/react/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/vue/index.d.ts +211 -0
- package/dist/vue/index.js +356 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +76 -22
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { inject, ref, onMounted, computed, watch } from 'vue';
|
|
2
|
+
import { createMemoryClient } from '../core/client';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Vue Plugin for Memory Client
|
|
6
|
+
*
|
|
7
|
+
* Provides a Memory Client instance to all components via Vue's provide/inject
|
|
8
|
+
*/
|
|
9
|
+
const MEMORY_CLIENT_KEY = Symbol('MemoryClient');
|
|
10
|
+
/**
|
|
11
|
+
* Vue plugin for Memory Client
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { createApp } from 'vue';
|
|
16
|
+
* import { createMemoryPlugin } from '@lanonasis/memory-client/vue';
|
|
17
|
+
* import App from './App.vue';
|
|
18
|
+
*
|
|
19
|
+
* const app = createApp(App);
|
|
20
|
+
*
|
|
21
|
+
* app.use(createMemoryPlugin({
|
|
22
|
+
* apiUrl: 'https://api.lanonasis.com',
|
|
23
|
+
* apiKey: import.meta.env.VITE_LANONASIS_KEY
|
|
24
|
+
* }));
|
|
25
|
+
*
|
|
26
|
+
* app.mount('#app');
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function createMemoryPlugin(options) {
|
|
30
|
+
return {
|
|
31
|
+
install(app) {
|
|
32
|
+
const client = createMemoryClient(options);
|
|
33
|
+
app.provide(MEMORY_CLIENT_KEY, client);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Hook to access the Memory Client instance
|
|
39
|
+
*
|
|
40
|
+
* @throws Error if used without installing the plugin
|
|
41
|
+
*/
|
|
42
|
+
function useMemoryClient() {
|
|
43
|
+
const client = inject(MEMORY_CLIENT_KEY);
|
|
44
|
+
if (!client) {
|
|
45
|
+
throw new Error('Memory client not provided. Did you install the createMemoryPlugin?');
|
|
46
|
+
}
|
|
47
|
+
return client;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Vue Composables for Memory Client
|
|
52
|
+
*
|
|
53
|
+
* Provides convenient Vue composables for working with memories
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* Composable to list memories with optional filtering
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```vue
|
|
60
|
+
* <script setup>
|
|
61
|
+
* import { useMemories } from '@lanonasis/memory-client/vue';
|
|
62
|
+
*
|
|
63
|
+
* const { memories, loading, error, refresh } = useMemories({
|
|
64
|
+
* memory_type: 'project',
|
|
65
|
+
* limit: 20
|
|
66
|
+
* });
|
|
67
|
+
* </script>
|
|
68
|
+
*
|
|
69
|
+
* <template>
|
|
70
|
+
* <div v-if="loading">Loading...</div>
|
|
71
|
+
* <div v-else-if="error">Error: {{ error.message }}</div>
|
|
72
|
+
* <div v-else>
|
|
73
|
+
* <div v-for="memory in memories" :key="memory.id">
|
|
74
|
+
* {{ memory.title }}
|
|
75
|
+
* </div>
|
|
76
|
+
* <button @click="refresh">Refresh</button>
|
|
77
|
+
* </div>
|
|
78
|
+
* </template>
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
function useMemories(options) {
|
|
82
|
+
const client = useMemoryClient();
|
|
83
|
+
const memories = ref([]);
|
|
84
|
+
const loading = ref(true);
|
|
85
|
+
const error = ref(null);
|
|
86
|
+
async function loadMemories() {
|
|
87
|
+
loading.value = true;
|
|
88
|
+
error.value = null;
|
|
89
|
+
const result = await client.listMemories(options);
|
|
90
|
+
if (result.error) {
|
|
91
|
+
error.value = {
|
|
92
|
+
message: result.error,
|
|
93
|
+
code: 'API_ERROR'
|
|
94
|
+
};
|
|
95
|
+
memories.value = [];
|
|
96
|
+
}
|
|
97
|
+
else if (result.data) {
|
|
98
|
+
memories.value = result.data.data;
|
|
99
|
+
}
|
|
100
|
+
loading.value = false;
|
|
101
|
+
}
|
|
102
|
+
onMounted(loadMemories);
|
|
103
|
+
return {
|
|
104
|
+
memories: computed(() => memories.value),
|
|
105
|
+
loading: computed(() => loading.value),
|
|
106
|
+
error: computed(() => error.value),
|
|
107
|
+
refresh: loadMemories
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Composable to fetch and manage a single memory by ID
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```vue
|
|
115
|
+
* <script setup>
|
|
116
|
+
* import { useMemory } from '@lanonasis/memory-client/vue';
|
|
117
|
+
*
|
|
118
|
+
* const props = defineProps<{ id: string }>();
|
|
119
|
+
* const { memory, loading, error, update, deleteMemory } = useMemory(() => props.id);
|
|
120
|
+
* </script>
|
|
121
|
+
*
|
|
122
|
+
* <template>
|
|
123
|
+
* <div v-if="loading">Loading...</div>
|
|
124
|
+
* <div v-else-if="error">Error: {{ error.message }}</div>
|
|
125
|
+
* <div v-else-if="memory">
|
|
126
|
+
* <h1>{{ memory.title }}</h1>
|
|
127
|
+
* <p>{{ memory.content }}</p>
|
|
128
|
+
* <button @click="update({ title: 'Updated Title' })">Update</button>
|
|
129
|
+
* <button @click="deleteMemory">Delete</button>
|
|
130
|
+
* </div>
|
|
131
|
+
* </template>
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
function useMemory(id) {
|
|
135
|
+
const client = useMemoryClient();
|
|
136
|
+
const memory = ref(null);
|
|
137
|
+
const loading = ref(true);
|
|
138
|
+
const error = ref(null);
|
|
139
|
+
const memoryId = computed(() => {
|
|
140
|
+
if (typeof id === 'function') {
|
|
141
|
+
return id();
|
|
142
|
+
}
|
|
143
|
+
else if (typeof id === 'string') {
|
|
144
|
+
return id;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
return id.value;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
async function loadMemory() {
|
|
151
|
+
if (!memoryId.value) {
|
|
152
|
+
memory.value = null;
|
|
153
|
+
loading.value = false;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
loading.value = true;
|
|
157
|
+
error.value = null;
|
|
158
|
+
const result = await client.getMemory(memoryId.value);
|
|
159
|
+
if (result.error) {
|
|
160
|
+
error.value = {
|
|
161
|
+
message: result.error,
|
|
162
|
+
code: 'API_ERROR'
|
|
163
|
+
};
|
|
164
|
+
memory.value = null;
|
|
165
|
+
}
|
|
166
|
+
else if (result.data) {
|
|
167
|
+
memory.value = result.data;
|
|
168
|
+
}
|
|
169
|
+
loading.value = false;
|
|
170
|
+
}
|
|
171
|
+
async function update(updates) {
|
|
172
|
+
if (!memoryId.value)
|
|
173
|
+
return;
|
|
174
|
+
const result = await client.updateMemory(memoryId.value, updates);
|
|
175
|
+
if (result.error) {
|
|
176
|
+
error.value = {
|
|
177
|
+
message: result.error,
|
|
178
|
+
code: 'API_ERROR'
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
else if (result.data) {
|
|
182
|
+
memory.value = result.data;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async function deleteMemory() {
|
|
186
|
+
if (!memoryId.value)
|
|
187
|
+
return;
|
|
188
|
+
const result = await client.deleteMemory(memoryId.value);
|
|
189
|
+
if (result.error) {
|
|
190
|
+
error.value = {
|
|
191
|
+
message: result.error,
|
|
192
|
+
code: 'API_ERROR'
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
memory.value = null;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
onMounted(loadMemory);
|
|
200
|
+
// Watch for ID changes and reload
|
|
201
|
+
watch(memoryId, loadMemory);
|
|
202
|
+
return {
|
|
203
|
+
memory: computed(() => memory.value),
|
|
204
|
+
loading: computed(() => loading.value),
|
|
205
|
+
error: computed(() => error.value),
|
|
206
|
+
refresh: loadMemory,
|
|
207
|
+
update,
|
|
208
|
+
deleteMemory
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Composable to create new memories
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```vue
|
|
216
|
+
* <script setup>
|
|
217
|
+
* import { ref } from 'vue';
|
|
218
|
+
* import { useCreateMemory } from '@lanonasis/memory-client/vue';
|
|
219
|
+
*
|
|
220
|
+
* const title = ref('');
|
|
221
|
+
* const content = ref('');
|
|
222
|
+
* const { createMemory, loading, error } = useCreateMemory();
|
|
223
|
+
*
|
|
224
|
+
* async function handleSubmit() {
|
|
225
|
+
* const memory = await createMemory({
|
|
226
|
+
* title: title.value,
|
|
227
|
+
* content: content.value
|
|
228
|
+
* });
|
|
229
|
+
* if (memory) {
|
|
230
|
+
* console.log('Created:', memory.id);
|
|
231
|
+
* title.value = '';
|
|
232
|
+
* content.value = '';
|
|
233
|
+
* }
|
|
234
|
+
* }
|
|
235
|
+
* </script>
|
|
236
|
+
*
|
|
237
|
+
* <template>
|
|
238
|
+
* <form @submit.prevent="handleSubmit">
|
|
239
|
+
* <input v-model="title" placeholder="Title" />
|
|
240
|
+
* <textarea v-model="content" placeholder="Content" />
|
|
241
|
+
* <button type="submit" :disabled="loading">Create</button>
|
|
242
|
+
* <div v-if="error">Error: {{ error.message }}</div>
|
|
243
|
+
* </form>
|
|
244
|
+
* </template>
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
function useCreateMemory() {
|
|
248
|
+
const client = useMemoryClient();
|
|
249
|
+
const loading = ref(false);
|
|
250
|
+
const error = ref(null);
|
|
251
|
+
async function createMemory(memory) {
|
|
252
|
+
loading.value = true;
|
|
253
|
+
error.value = null;
|
|
254
|
+
const result = await client.createMemory(memory);
|
|
255
|
+
if (result.error) {
|
|
256
|
+
error.value = {
|
|
257
|
+
message: result.error,
|
|
258
|
+
code: 'API_ERROR'
|
|
259
|
+
};
|
|
260
|
+
loading.value = false;
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
loading.value = false;
|
|
264
|
+
return result.data || null;
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
createMemory,
|
|
268
|
+
loading: computed(() => loading.value),
|
|
269
|
+
error: computed(() => error.value)
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Composable to search memories
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```vue
|
|
277
|
+
* <script setup>
|
|
278
|
+
* import { ref, watch } from 'vue';
|
|
279
|
+
* import { useSearchMemories } from '@lanonasis/memory-client/vue';
|
|
280
|
+
*
|
|
281
|
+
* const query = ref('');
|
|
282
|
+
* const { results, loading, error, search, totalResults, searchTime } = useSearchMemories();
|
|
283
|
+
*
|
|
284
|
+
* watch(query, (newQuery) => {
|
|
285
|
+
* if (newQuery.length > 2) {
|
|
286
|
+
* search(newQuery, { limit: 10 });
|
|
287
|
+
* }
|
|
288
|
+
* });
|
|
289
|
+
* </script>
|
|
290
|
+
*
|
|
291
|
+
* <template>
|
|
292
|
+
* <div>
|
|
293
|
+
* <input v-model="query" placeholder="Search memories..." />
|
|
294
|
+
* <div v-if="loading">Searching...</div>
|
|
295
|
+
* <div v-if="error">Error: {{ error.message }}</div>
|
|
296
|
+
* <div v-for="result in results" :key="result.id">
|
|
297
|
+
* <h3>{{ result.title }}</h3>
|
|
298
|
+
* <span>Score: {{ result.similarity_score.toFixed(2) }}</span>
|
|
299
|
+
* </div>
|
|
300
|
+
* <div v-if="totalResults > 0">
|
|
301
|
+
* Found {{ totalResults }} results in {{ searchTime }}ms
|
|
302
|
+
* </div>
|
|
303
|
+
* </div>
|
|
304
|
+
* </template>
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
function useSearchMemories(debounceMs = 300) {
|
|
308
|
+
const client = useMemoryClient();
|
|
309
|
+
const results = ref([]);
|
|
310
|
+
const loading = ref(false);
|
|
311
|
+
const error = ref(null);
|
|
312
|
+
const totalResults = ref(0);
|
|
313
|
+
const searchTime = ref(0);
|
|
314
|
+
let debounceTimer = null;
|
|
315
|
+
async function search(query, options) {
|
|
316
|
+
// Clear existing timer
|
|
317
|
+
if (debounceTimer) {
|
|
318
|
+
clearTimeout(debounceTimer);
|
|
319
|
+
}
|
|
320
|
+
// Set new timer
|
|
321
|
+
debounceTimer = setTimeout(async () => {
|
|
322
|
+
loading.value = true;
|
|
323
|
+
error.value = null;
|
|
324
|
+
const result = await client.searchMemories({
|
|
325
|
+
query,
|
|
326
|
+
...options
|
|
327
|
+
});
|
|
328
|
+
if (result.error) {
|
|
329
|
+
error.value = {
|
|
330
|
+
message: result.error,
|
|
331
|
+
code: 'API_ERROR'
|
|
332
|
+
};
|
|
333
|
+
results.value = [];
|
|
334
|
+
totalResults.value = 0;
|
|
335
|
+
searchTime.value = 0;
|
|
336
|
+
}
|
|
337
|
+
else if (result.data) {
|
|
338
|
+
results.value = result.data.results;
|
|
339
|
+
totalResults.value = result.data.total_results;
|
|
340
|
+
searchTime.value = result.data.search_time_ms;
|
|
341
|
+
}
|
|
342
|
+
loading.value = false;
|
|
343
|
+
}, debounceMs);
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
results: computed(() => results.value),
|
|
347
|
+
loading: computed(() => loading.value),
|
|
348
|
+
error: computed(() => error.value),
|
|
349
|
+
search,
|
|
350
|
+
totalResults: computed(() => totalResults.value),
|
|
351
|
+
searchTime: computed(() => searchTime.value)
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export { MEMORY_CLIENT_KEY, createMemoryPlugin, useCreateMemory, useMemories, useMemory, useMemoryClient, useSearchMemories };
|
|
356
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/vue/plugin.ts","../../src/vue/composables.ts"],"sourcesContent":["/**\n * Vue Plugin for Memory Client\n *\n * Provides a Memory Client instance to all components via Vue's provide/inject\n */\n\nimport { type App, type InjectionKey, inject } from 'vue';\nimport { createMemoryClient, type CoreMemoryClient, type CoreMemoryClientConfig } from '../core/client';\n\nexport const MEMORY_CLIENT_KEY: InjectionKey<CoreMemoryClient> = Symbol('MemoryClient');\n\nexport interface MemoryPluginOptions extends CoreMemoryClientConfig {\n // Plugin-specific options can be added here\n}\n\n/**\n * Vue plugin for Memory Client\n *\n * @example\n * ```ts\n * import { createApp } from 'vue';\n * import { createMemoryPlugin } from '@lanonasis/memory-client/vue';\n * import App from './App.vue';\n *\n * const app = createApp(App);\n *\n * app.use(createMemoryPlugin({\n * apiUrl: 'https://api.lanonasis.com',\n * apiKey: import.meta.env.VITE_LANONASIS_KEY\n * }));\n *\n * app.mount('#app');\n * ```\n */\nexport function createMemoryPlugin(options: MemoryPluginOptions) {\n return {\n install(app: App) {\n const client = createMemoryClient(options);\n app.provide(MEMORY_CLIENT_KEY, client);\n }\n };\n}\n\n/**\n * Hook to access the Memory Client instance\n *\n * @throws Error if used without installing the plugin\n */\nexport function useMemoryClient(): CoreMemoryClient {\n const client = inject(MEMORY_CLIENT_KEY);\n\n if (!client) {\n throw new Error('Memory client not provided. Did you install the createMemoryPlugin?');\n }\n\n return client;\n}\n","/**\n * Vue Composables for Memory Client\n *\n * Provides convenient Vue composables for working with memories\n */\n\nimport { ref, computed, onMounted, watch, type Ref } from 'vue';\nimport { useMemoryClient } from './plugin';\nimport type {\n MemoryEntry,\n CreateMemoryRequest,\n UpdateMemoryRequest,\n SearchMemoryRequest,\n MemorySearchResult\n} from '../core/types';\nimport type { ApiError } from '../core/client';\n\n/**\n * Composable to list memories with optional filtering\n *\n * @example\n * ```vue\n * <script setup>\n * import { useMemories } from '@lanonasis/memory-client/vue';\n *\n * const { memories, loading, error, refresh } = useMemories({\n * memory_type: 'project',\n * limit: 20\n * });\n * </script>\n *\n * <template>\n * <div v-if=\"loading\">Loading...</div>\n * <div v-else-if=\"error\">Error: {{ error.message }}</div>\n * <div v-else>\n * <div v-for=\"memory in memories\" :key=\"memory.id\">\n * {{ memory.title }}\n * </div>\n * <button @click=\"refresh\">Refresh</button>\n * </div>\n * </template>\n * ```\n */\nexport function useMemories(options?: {\n page?: number;\n limit?: number;\n memory_type?: string;\n topic_id?: string;\n project_ref?: string;\n status?: string;\n tags?: string[];\n sort?: string;\n order?: 'asc' | 'desc';\n}) {\n const client = useMemoryClient();\n const memories = ref<MemoryEntry[]>([]);\n const loading = ref(true);\n const error = ref<ApiError | null>(null);\n\n async function loadMemories() {\n loading.value = true;\n error.value = null;\n\n const result = await client.listMemories(options);\n\n if (result.error) {\n error.value = {\n message: result.error,\n code: 'API_ERROR'\n };\n memories.value = [];\n } else if (result.data) {\n memories.value = result.data.data;\n }\n\n loading.value = false;\n }\n\n onMounted(loadMemories);\n\n return {\n memories: computed(() => memories.value),\n loading: computed(() => loading.value),\n error: computed(() => error.value),\n refresh: loadMemories\n };\n}\n\n/**\n * Composable to fetch and manage a single memory by ID\n *\n * @example\n * ```vue\n * <script setup>\n * import { useMemory } from '@lanonasis/memory-client/vue';\n *\n * const props = defineProps<{ id: string }>();\n * const { memory, loading, error, update, deleteMemory } = useMemory(() => props.id);\n * </script>\n *\n * <template>\n * <div v-if=\"loading\">Loading...</div>\n * <div v-else-if=\"error\">Error: {{ error.message }}</div>\n * <div v-else-if=\"memory\">\n * <h1>{{ memory.title }}</h1>\n * <p>{{ memory.content }}</p>\n * <button @click=\"update({ title: 'Updated Title' })\">Update</button>\n * <button @click=\"deleteMemory\">Delete</button>\n * </div>\n * </template>\n * ```\n */\nexport function useMemory(id: Ref<string> | (() => string) | string) {\n const client = useMemoryClient();\n const memory = ref<MemoryEntry | null>(null);\n const loading = ref(true);\n const error = ref<ApiError | null>(null);\n\n const memoryId = computed(() => {\n if (typeof id === 'function') {\n return id();\n } else if (typeof id === 'string') {\n return id;\n } else {\n return id.value;\n }\n });\n\n async function loadMemory() {\n if (!memoryId.value) {\n memory.value = null;\n loading.value = false;\n return;\n }\n\n loading.value = true;\n error.value = null;\n\n const result = await client.getMemory(memoryId.value);\n\n if (result.error) {\n error.value = {\n message: result.error,\n code: 'API_ERROR'\n };\n memory.value = null;\n } else if (result.data) {\n memory.value = result.data;\n }\n\n loading.value = false;\n }\n\n async function update(updates: UpdateMemoryRequest) {\n if (!memoryId.value) return;\n\n const result = await client.updateMemory(memoryId.value, updates);\n\n if (result.error) {\n error.value = {\n message: result.error,\n code: 'API_ERROR'\n };\n } else if (result.data) {\n memory.value = result.data;\n }\n }\n\n async function deleteMemory() {\n if (!memoryId.value) return;\n\n const result = await client.deleteMemory(memoryId.value);\n\n if (result.error) {\n error.value = {\n message: result.error,\n code: 'API_ERROR'\n };\n } else {\n memory.value = null;\n }\n }\n\n onMounted(loadMemory);\n\n // Watch for ID changes and reload\n watch(memoryId, loadMemory);\n\n return {\n memory: computed(() => memory.value),\n loading: computed(() => loading.value),\n error: computed(() => error.value),\n refresh: loadMemory,\n update,\n deleteMemory\n };\n}\n\n/**\n * Composable to create new memories\n *\n * @example\n * ```vue\n * <script setup>\n * import { ref } from 'vue';\n * import { useCreateMemory } from '@lanonasis/memory-client/vue';\n *\n * const title = ref('');\n * const content = ref('');\n * const { createMemory, loading, error } = useCreateMemory();\n *\n * async function handleSubmit() {\n * const memory = await createMemory({\n * title: title.value,\n * content: content.value\n * });\n * if (memory) {\n * console.log('Created:', memory.id);\n * title.value = '';\n * content.value = '';\n * }\n * }\n * </script>\n *\n * <template>\n * <form @submit.prevent=\"handleSubmit\">\n * <input v-model=\"title\" placeholder=\"Title\" />\n * <textarea v-model=\"content\" placeholder=\"Content\" />\n * <button type=\"submit\" :disabled=\"loading\">Create</button>\n * <div v-if=\"error\">Error: {{ error.message }}</div>\n * </form>\n * </template>\n * ```\n */\nexport function useCreateMemory() {\n const client = useMemoryClient();\n const loading = ref(false);\n const error = ref<ApiError | null>(null);\n\n async function createMemory(memory: CreateMemoryRequest): Promise<MemoryEntry | null> {\n loading.value = true;\n error.value = null;\n\n const result = await client.createMemory(memory);\n\n if (result.error) {\n error.value = {\n message: result.error,\n code: 'API_ERROR'\n };\n loading.value = false;\n return null;\n }\n\n loading.value = false;\n return result.data || null;\n }\n\n return {\n createMemory,\n loading: computed(() => loading.value),\n error: computed(() => error.value)\n };\n}\n\n/**\n * Composable to search memories\n *\n * @example\n * ```vue\n * <script setup>\n * import { ref, watch } from 'vue';\n * import { useSearchMemories } from '@lanonasis/memory-client/vue';\n *\n * const query = ref('');\n * const { results, loading, error, search, totalResults, searchTime } = useSearchMemories();\n *\n * watch(query, (newQuery) => {\n * if (newQuery.length > 2) {\n * search(newQuery, { limit: 10 });\n * }\n * });\n * </script>\n *\n * <template>\n * <div>\n * <input v-model=\"query\" placeholder=\"Search memories...\" />\n * <div v-if=\"loading\">Searching...</div>\n * <div v-if=\"error\">Error: {{ error.message }}</div>\n * <div v-for=\"result in results\" :key=\"result.id\">\n * <h3>{{ result.title }}</h3>\n * <span>Score: {{ result.similarity_score.toFixed(2) }}</span>\n * </div>\n * <div v-if=\"totalResults > 0\">\n * Found {{ totalResults }} results in {{ searchTime }}ms\n * </div>\n * </div>\n * </template>\n * ```\n */\nexport function useSearchMemories(debounceMs: number = 300) {\n const client = useMemoryClient();\n const results = ref<MemorySearchResult[]>([]);\n const loading = ref(false);\n const error = ref<ApiError | null>(null);\n const totalResults = ref(0);\n const searchTime = ref(0);\n let debounceTimer: ReturnType<typeof setTimeout> | null = null;\n\n async function search(query: string, options?: Omit<SearchMemoryRequest, 'query'>) {\n // Clear existing timer\n if (debounceTimer) {\n clearTimeout(debounceTimer);\n }\n\n // Set new timer\n debounceTimer = setTimeout(async () => {\n loading.value = true;\n error.value = null;\n\n const result = await client.searchMemories({\n query,\n ...options\n });\n\n if (result.error) {\n error.value = {\n message: result.error,\n code: 'API_ERROR'\n };\n results.value = [];\n totalResults.value = 0;\n searchTime.value = 0;\n } else if (result.data) {\n results.value = result.data.results;\n totalResults.value = result.data.total_results;\n searchTime.value = result.data.search_time_ms;\n }\n\n loading.value = false;\n }, debounceMs);\n }\n\n return {\n results: computed(() => results.value),\n loading: computed(() => loading.value),\n error: computed(() => error.value),\n search,\n totalResults: computed(() => totalResults.value),\n searchTime: computed(() => searchTime.value)\n };\n}\n"],"names":[],"mappings":";;;AAAA;;;;AAIG;MAKU,iBAAiB,GAAmC,MAAM,CAAC,cAAc;AAMtF;;;;;;;;;;;;;;;;;;AAkBG;AACG,SAAU,kBAAkB,CAAC,OAA4B,EAAA;IAC7D,OAAO;AACL,QAAA,OAAO,CAAC,GAAQ,EAAA;AACd,YAAA,MAAM,MAAM,GAAG,kBAAkB,CAAC,OAAO,CAAC;AAC1C,YAAA,GAAG,CAAC,OAAO,CAAC,iBAAiB,EAAE,MAAM,CAAC;QACxC;KACD;AACH;AAEA;;;;AAIG;SACa,eAAe,GAAA;AAC7B,IAAA,MAAM,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAExC,IAAI,CAAC,MAAM,EAAE;AACX,QAAA,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC;IACxF;AAEA,IAAA,OAAO,MAAM;AACf;;ACxDA;;;;AAIG;AAaH;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;AACG,SAAU,WAAW,CAAC,OAU3B,EAAA;AACC,IAAA,MAAM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M,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC;gBACzC,KAAK;AACL,gBAAA,GAAG;AACJ,aAAA,CAAC;AAEF,YAAA,IAAI,MAAM,CAAC,KAAK,EAAE;gBAChB,KAAK,CAAC,KAAK,GAAG;oBACZ,OAAO,EAAE,MAAM,CAAC,KAAK;AACrB,oBAAA,IAAI,EAAE;iBACP;AACD,gBAAA,OAAO,CAAC,KAAK,GAAG,EAAE;AAClB,gBAAA,YAAY,CAAC,KAAK,GAAG,CAAC;AACtB,gBAAA,UAAU,CAAC,KAAK,GAAG,CAAC;YACtB;AAAO,iBAAA,IAAI,MAAM,CAAC,IAAI,EAAE;gBACtB,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO;gBACnC,YAAY,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa;gBAC9C,UAAU,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc;YAC/C;AAEA,YAAA,OAAO,CAAC,KAAK,GAAG,KAAK;QACvB,CAAC,EAAE,UAAU,CAAC;IAChB;IAEA,OAAO;QACL,OAAO,EAAE,QAAQ,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC;QACtC,OAAO,EAAE,QAAQ,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC;QACtC,KAAK,EAAE,QAAQ,CAAC,MAAM,KAAK,CAAC,KAAK,CAAC;QAClC,MAAM;QACN,YAAY,EAAE,QAAQ,CAAC,MAAM,YAAY,CAAC,KAAK,CAAC;QAChD,UAAU,EAAE,QAAQ,CAAC,MAAM,UAAU,CAAC,KAAK;KAC5C;AACH;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lanonasis/memory-client",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Memory as a Service (MaaS) Client SDK
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Universal Memory as a Service (MaaS) Client SDK - Works everywhere: Browser, Node.js, React, Vue, Edge Functions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.esm.js",
|
|
@@ -10,7 +10,35 @@
|
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"import": "./dist/index.esm.js",
|
|
13
|
-
"require": "./dist/index.js"
|
|
13
|
+
"require": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.esm.js"
|
|
15
|
+
},
|
|
16
|
+
"./core": {
|
|
17
|
+
"types": "./dist/core/index.d.ts",
|
|
18
|
+
"import": "./dist/core/index.js",
|
|
19
|
+
"browser": "./dist/core/index.js",
|
|
20
|
+
"default": "./dist/core/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./node": {
|
|
23
|
+
"types": "./dist/node/index.d.ts",
|
|
24
|
+
"node": "./dist/node/index.js",
|
|
25
|
+
"import": "./dist/node/index.js",
|
|
26
|
+
"default": null
|
|
27
|
+
},
|
|
28
|
+
"./react": {
|
|
29
|
+
"types": "./dist/react/index.d.ts",
|
|
30
|
+
"import": "./dist/react/index.js",
|
|
31
|
+
"default": "./dist/react/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./vue": {
|
|
34
|
+
"types": "./dist/vue/index.d.ts",
|
|
35
|
+
"import": "./dist/vue/index.js",
|
|
36
|
+
"default": "./dist/vue/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./presets": {
|
|
39
|
+
"types": "./dist/presets/index.d.ts",
|
|
40
|
+
"import": "./dist/presets/index.js",
|
|
41
|
+
"default": "./dist/presets/index.js"
|
|
14
42
|
}
|
|
15
43
|
},
|
|
16
44
|
"files": [
|
|
@@ -30,6 +58,13 @@
|
|
|
30
58
|
"clean": "rimraf dist",
|
|
31
59
|
"publish:both": "./scripts/publish-sdk.sh"
|
|
32
60
|
},
|
|
61
|
+
"browser": {
|
|
62
|
+
"./dist/node/index.js": false,
|
|
63
|
+
"child_process": false,
|
|
64
|
+
"fs": false,
|
|
65
|
+
"os": false,
|
|
66
|
+
"util": false
|
|
67
|
+
},
|
|
33
68
|
"keywords": [
|
|
34
69
|
"memory",
|
|
35
70
|
"ai",
|
|
@@ -43,7 +78,14 @@
|
|
|
43
78
|
"memory-as-a-service",
|
|
44
79
|
"cli-integration",
|
|
45
80
|
"mcp",
|
|
46
|
-
"model-context-protocol"
|
|
81
|
+
"model-context-protocol",
|
|
82
|
+
"react",
|
|
83
|
+
"vue",
|
|
84
|
+
"universal",
|
|
85
|
+
"edge-functions",
|
|
86
|
+
"cloudflare-workers",
|
|
87
|
+
"browser",
|
|
88
|
+
"nodejs"
|
|
47
89
|
],
|
|
48
90
|
"author": {
|
|
49
91
|
"name": "Lanonasis Team",
|
|
@@ -53,7 +95,7 @@
|
|
|
53
95
|
"license": "MIT",
|
|
54
96
|
"repository": {
|
|
55
97
|
"type": "git",
|
|
56
|
-
"url": "https://github.com/lanonasis/memory-client.git"
|
|
98
|
+
"url": "git+https://github.com/lanonasis/memory-client.git"
|
|
57
99
|
},
|
|
58
100
|
"homepage": "https://docs.lanonasis.com/sdk",
|
|
59
101
|
"bugs": {
|
|
@@ -63,32 +105,44 @@
|
|
|
63
105
|
"node": ">=16.0.0"
|
|
64
106
|
},
|
|
65
107
|
"dependencies": {
|
|
66
|
-
"zod": "^
|
|
108
|
+
"zod": "^4.1.12"
|
|
109
|
+
},
|
|
110
|
+
"peerDependencies": {
|
|
111
|
+
"react": ">=16.8.0",
|
|
112
|
+
"vue": ">=3.0.0"
|
|
67
113
|
},
|
|
68
|
-
"
|
|
69
|
-
"
|
|
114
|
+
"peerDependenciesMeta": {
|
|
115
|
+
"react": {
|
|
116
|
+
"optional": true
|
|
117
|
+
},
|
|
118
|
+
"vue": {
|
|
119
|
+
"optional": true
|
|
120
|
+
}
|
|
70
121
|
},
|
|
71
122
|
"devDependencies": {
|
|
72
|
-
"@rollup/plugin-commonjs": "^
|
|
73
|
-
"@rollup/plugin-node-resolve": "^
|
|
74
|
-
"@rollup/plugin-typescript": "^12.
|
|
75
|
-
"@types/jest": "^
|
|
76
|
-
"@types/node": "^
|
|
77
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
78
|
-
"@typescript-eslint/parser": "^8.
|
|
79
|
-
"eslint": "^9.
|
|
80
|
-
"jest": "^
|
|
81
|
-
"rimraf": "^6.
|
|
82
|
-
"rollup": "^4.
|
|
83
|
-
"rollup-plugin-dts": "^6.
|
|
84
|
-
"ts-jest": "^29.
|
|
123
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
124
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
125
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
126
|
+
"@types/jest": "^30.0.0",
|
|
127
|
+
"@types/node": "^24.10.1",
|
|
128
|
+
"@typescript-eslint/eslint-plugin": "^8.47.0",
|
|
129
|
+
"@typescript-eslint/parser": "^8.47.0",
|
|
130
|
+
"eslint": "^9.39.1",
|
|
131
|
+
"jest": "^30.2.0",
|
|
132
|
+
"rimraf": "^6.1.2",
|
|
133
|
+
"rollup": "^4.53.3",
|
|
134
|
+
"rollup-plugin-dts": "^6.2.3",
|
|
135
|
+
"ts-jest": "^29.4.5",
|
|
85
136
|
"tslib": "^2.8.1",
|
|
86
|
-
"typescript": "^5.
|
|
137
|
+
"typescript": "^5.9.3"
|
|
87
138
|
},
|
|
88
139
|
"publishConfig": {
|
|
89
140
|
"access": "public",
|
|
90
141
|
"registry": "https://registry.npmjs.org/"
|
|
91
142
|
},
|
|
143
|
+
"overrides": {
|
|
144
|
+
"js-yaml": "4.1.1"
|
|
145
|
+
},
|
|
92
146
|
"funding": {
|
|
93
147
|
"type": "github",
|
|
94
148
|
"url": "https://github.com/sponsors/lanonasis"
|