unimemory 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/README.md +2 -2
- package/dist/index.d.mts +104 -38
- package/dist/index.d.ts +104 -38
- package/dist/index.js +151 -60
- package/dist/index.mjs +149 -59
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# UniMemory
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The memory layer for your AI apps.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -37,7 +37,7 @@ Create a new UniMemory client.
|
|
|
37
37
|
```typescript
|
|
38
38
|
const client = new UniMemory({
|
|
39
39
|
apiKey: 'um_live_xxx...',
|
|
40
|
-
baseUrl: 'https://
|
|
40
|
+
baseUrl: 'https://unimemory.up.railway.app/api/v1' // optional, defaults to production API
|
|
41
41
|
});
|
|
42
42
|
```
|
|
43
43
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,62 +1,106 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* UniMemory SDK
|
|
3
|
-
*
|
|
2
|
+
* UniMemory SDK v2
|
|
3
|
+
* The memory layer for AI applications
|
|
4
|
+
*
|
|
5
|
+
* Core API: POST/GET/PATCH/DELETE /memories, POST /search
|
|
6
|
+
* Ingest API: POST /ingest/text, /ingest/chat, /ingest/document
|
|
4
7
|
*/
|
|
5
8
|
interface UniMemoryConfig {
|
|
6
9
|
apiKey: string;
|
|
7
10
|
baseUrl?: string;
|
|
8
11
|
}
|
|
9
|
-
interface
|
|
12
|
+
interface CreateMemoryOptions {
|
|
10
13
|
content: string;
|
|
11
|
-
sourceApp?: string;
|
|
12
14
|
userId?: string;
|
|
15
|
+
appId?: string;
|
|
16
|
+
tags?: string[];
|
|
13
17
|
metadata?: Record<string, unknown>;
|
|
18
|
+
projectId?: string;
|
|
14
19
|
}
|
|
15
|
-
interface
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
interface CreateMemoryResponse {
|
|
21
|
+
id: string;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
}
|
|
24
|
+
interface Memory {
|
|
25
|
+
id: string;
|
|
26
|
+
content: string;
|
|
27
|
+
userId: string;
|
|
28
|
+
tags: string[];
|
|
29
|
+
salience: number;
|
|
30
|
+
createdAt: string;
|
|
31
|
+
}
|
|
32
|
+
interface ListMemoriesOptions {
|
|
33
|
+
limit?: number;
|
|
34
|
+
offset?: number;
|
|
35
|
+
userId?: string;
|
|
36
|
+
sector?: string;
|
|
37
|
+
}
|
|
38
|
+
interface ListMemoriesResponse {
|
|
39
|
+
memories: Memory[];
|
|
40
|
+
total: number;
|
|
41
|
+
}
|
|
42
|
+
interface UpdateMemoryOptions {
|
|
43
|
+
tags?: string[];
|
|
44
|
+
salience?: number;
|
|
45
|
+
metadata?: Record<string, unknown>;
|
|
23
46
|
}
|
|
24
47
|
interface SearchOptions {
|
|
25
48
|
limit?: number;
|
|
26
49
|
userId?: string;
|
|
27
50
|
minSalience?: number;
|
|
28
|
-
|
|
51
|
+
projectId?: string;
|
|
29
52
|
}
|
|
30
53
|
interface SearchResult {
|
|
31
54
|
id: string;
|
|
32
55
|
content: string;
|
|
33
|
-
sector?: string;
|
|
34
|
-
salience: number;
|
|
35
|
-
score: number;
|
|
36
56
|
tags: string[];
|
|
57
|
+
salience: number;
|
|
58
|
+
createdAt?: string;
|
|
37
59
|
}
|
|
38
60
|
interface SearchResponse {
|
|
39
61
|
results: SearchResult[];
|
|
40
62
|
total: number;
|
|
41
63
|
query: string;
|
|
42
64
|
}
|
|
43
|
-
interface
|
|
44
|
-
id: string;
|
|
65
|
+
interface IngestTextOptions {
|
|
45
66
|
content: string;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
67
|
+
userId?: string;
|
|
68
|
+
appId?: string;
|
|
69
|
+
sourceId?: string;
|
|
70
|
+
projectId?: string;
|
|
71
|
+
createSource?: boolean;
|
|
50
72
|
}
|
|
51
|
-
interface
|
|
52
|
-
|
|
53
|
-
|
|
73
|
+
interface IngestChatOptions {
|
|
74
|
+
messages: Array<{
|
|
75
|
+
role: string;
|
|
76
|
+
content: string;
|
|
77
|
+
}>;
|
|
54
78
|
userId?: string;
|
|
55
|
-
|
|
79
|
+
appId?: string;
|
|
80
|
+
sourceId?: string;
|
|
81
|
+
projectId?: string;
|
|
82
|
+
sourceMetadata?: Record<string, unknown>;
|
|
56
83
|
}
|
|
57
|
-
interface
|
|
58
|
-
|
|
59
|
-
|
|
84
|
+
interface IngestDocumentOptions {
|
|
85
|
+
content: string;
|
|
86
|
+
title?: string;
|
|
87
|
+
userId?: string;
|
|
88
|
+
appId?: string;
|
|
89
|
+
sourceId?: string;
|
|
90
|
+
projectId?: string;
|
|
91
|
+
}
|
|
92
|
+
interface IngestResponse {
|
|
93
|
+
stored: number;
|
|
94
|
+
skipped: number;
|
|
95
|
+
memoryIds: string[];
|
|
96
|
+
tokensUsed: number;
|
|
97
|
+
sourceId?: string;
|
|
98
|
+
sourceTitle?: string;
|
|
99
|
+
}
|
|
100
|
+
declare class UniMemoryError extends Error {
|
|
101
|
+
status?: number | undefined;
|
|
102
|
+
code?: string | undefined;
|
|
103
|
+
constructor(message: string, status?: number | undefined, code?: string | undefined);
|
|
60
104
|
}
|
|
61
105
|
declare class UniMemory {
|
|
62
106
|
private apiKey;
|
|
@@ -64,23 +108,45 @@ declare class UniMemory {
|
|
|
64
108
|
constructor(config: UniMemoryConfig);
|
|
65
109
|
private request;
|
|
66
110
|
/**
|
|
67
|
-
*
|
|
111
|
+
* Store an explicit memory (deterministic, no LLM).
|
|
68
112
|
*/
|
|
69
|
-
|
|
113
|
+
add(options: CreateMemoryOptions): Promise<CreateMemoryResponse>;
|
|
70
114
|
/**
|
|
71
|
-
*
|
|
115
|
+
* List memories with optional filters.
|
|
72
116
|
*/
|
|
73
|
-
|
|
117
|
+
list(options?: ListMemoriesOptions): Promise<ListMemoriesResponse>;
|
|
118
|
+
/**
|
|
119
|
+
* Get a single memory by ID.
|
|
120
|
+
*/
|
|
121
|
+
get(memoryId: string): Promise<Memory>;
|
|
74
122
|
/**
|
|
75
|
-
*
|
|
123
|
+
* Update a memory (tags, salience, metadata only — content cannot be changed).
|
|
76
124
|
*/
|
|
77
|
-
|
|
125
|
+
update(memoryId: string, options: UpdateMemoryOptions): Promise<Memory>;
|
|
78
126
|
/**
|
|
79
|
-
* Delete a memory
|
|
127
|
+
* Delete a memory.
|
|
80
128
|
*/
|
|
81
|
-
|
|
129
|
+
delete(memoryId: string): Promise<{
|
|
82
130
|
success: boolean;
|
|
131
|
+
id: string;
|
|
83
132
|
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Semantic search across memories.
|
|
135
|
+
*/
|
|
136
|
+
search(query: string, options?: SearchOptions): Promise<SearchResponse>;
|
|
137
|
+
/**
|
|
138
|
+
* Ingest raw text — LLM extracts memories in the background.
|
|
139
|
+
*/
|
|
140
|
+
ingestText(options: IngestTextOptions): Promise<IngestResponse>;
|
|
141
|
+
/**
|
|
142
|
+
* Ingest chat messages — LLM extracts memories in the background.
|
|
143
|
+
*/
|
|
144
|
+
ingestChat(options: IngestChatOptions): Promise<IngestResponse>;
|
|
145
|
+
/**
|
|
146
|
+
* Ingest a document — LLM extracts memories in the background.
|
|
147
|
+
*/
|
|
148
|
+
ingestDocument(options: IngestDocumentOptions): Promise<IngestResponse>;
|
|
149
|
+
private ingestRequest;
|
|
84
150
|
}
|
|
85
151
|
|
|
86
|
-
export { type
|
|
152
|
+
export { type CreateMemoryOptions, type CreateMemoryResponse, type IngestChatOptions, type IngestDocumentOptions, type IngestResponse, type IngestTextOptions, type ListMemoriesOptions, type ListMemoriesResponse, type Memory, type SearchOptions, type SearchResponse, type SearchResult, UniMemory, type UniMemoryConfig, UniMemoryError, type UpdateMemoryOptions, UniMemory as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,62 +1,106 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* UniMemory SDK
|
|
3
|
-
*
|
|
2
|
+
* UniMemory SDK v2
|
|
3
|
+
* The memory layer for AI applications
|
|
4
|
+
*
|
|
5
|
+
* Core API: POST/GET/PATCH/DELETE /memories, POST /search
|
|
6
|
+
* Ingest API: POST /ingest/text, /ingest/chat, /ingest/document
|
|
4
7
|
*/
|
|
5
8
|
interface UniMemoryConfig {
|
|
6
9
|
apiKey: string;
|
|
7
10
|
baseUrl?: string;
|
|
8
11
|
}
|
|
9
|
-
interface
|
|
12
|
+
interface CreateMemoryOptions {
|
|
10
13
|
content: string;
|
|
11
|
-
sourceApp?: string;
|
|
12
14
|
userId?: string;
|
|
15
|
+
appId?: string;
|
|
16
|
+
tags?: string[];
|
|
13
17
|
metadata?: Record<string, unknown>;
|
|
18
|
+
projectId?: string;
|
|
14
19
|
}
|
|
15
|
-
interface
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
interface CreateMemoryResponse {
|
|
21
|
+
id: string;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
}
|
|
24
|
+
interface Memory {
|
|
25
|
+
id: string;
|
|
26
|
+
content: string;
|
|
27
|
+
userId: string;
|
|
28
|
+
tags: string[];
|
|
29
|
+
salience: number;
|
|
30
|
+
createdAt: string;
|
|
31
|
+
}
|
|
32
|
+
interface ListMemoriesOptions {
|
|
33
|
+
limit?: number;
|
|
34
|
+
offset?: number;
|
|
35
|
+
userId?: string;
|
|
36
|
+
sector?: string;
|
|
37
|
+
}
|
|
38
|
+
interface ListMemoriesResponse {
|
|
39
|
+
memories: Memory[];
|
|
40
|
+
total: number;
|
|
41
|
+
}
|
|
42
|
+
interface UpdateMemoryOptions {
|
|
43
|
+
tags?: string[];
|
|
44
|
+
salience?: number;
|
|
45
|
+
metadata?: Record<string, unknown>;
|
|
23
46
|
}
|
|
24
47
|
interface SearchOptions {
|
|
25
48
|
limit?: number;
|
|
26
49
|
userId?: string;
|
|
27
50
|
minSalience?: number;
|
|
28
|
-
|
|
51
|
+
projectId?: string;
|
|
29
52
|
}
|
|
30
53
|
interface SearchResult {
|
|
31
54
|
id: string;
|
|
32
55
|
content: string;
|
|
33
|
-
sector?: string;
|
|
34
|
-
salience: number;
|
|
35
|
-
score: number;
|
|
36
56
|
tags: string[];
|
|
57
|
+
salience: number;
|
|
58
|
+
createdAt?: string;
|
|
37
59
|
}
|
|
38
60
|
interface SearchResponse {
|
|
39
61
|
results: SearchResult[];
|
|
40
62
|
total: number;
|
|
41
63
|
query: string;
|
|
42
64
|
}
|
|
43
|
-
interface
|
|
44
|
-
id: string;
|
|
65
|
+
interface IngestTextOptions {
|
|
45
66
|
content: string;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
67
|
+
userId?: string;
|
|
68
|
+
appId?: string;
|
|
69
|
+
sourceId?: string;
|
|
70
|
+
projectId?: string;
|
|
71
|
+
createSource?: boolean;
|
|
50
72
|
}
|
|
51
|
-
interface
|
|
52
|
-
|
|
53
|
-
|
|
73
|
+
interface IngestChatOptions {
|
|
74
|
+
messages: Array<{
|
|
75
|
+
role: string;
|
|
76
|
+
content: string;
|
|
77
|
+
}>;
|
|
54
78
|
userId?: string;
|
|
55
|
-
|
|
79
|
+
appId?: string;
|
|
80
|
+
sourceId?: string;
|
|
81
|
+
projectId?: string;
|
|
82
|
+
sourceMetadata?: Record<string, unknown>;
|
|
56
83
|
}
|
|
57
|
-
interface
|
|
58
|
-
|
|
59
|
-
|
|
84
|
+
interface IngestDocumentOptions {
|
|
85
|
+
content: string;
|
|
86
|
+
title?: string;
|
|
87
|
+
userId?: string;
|
|
88
|
+
appId?: string;
|
|
89
|
+
sourceId?: string;
|
|
90
|
+
projectId?: string;
|
|
91
|
+
}
|
|
92
|
+
interface IngestResponse {
|
|
93
|
+
stored: number;
|
|
94
|
+
skipped: number;
|
|
95
|
+
memoryIds: string[];
|
|
96
|
+
tokensUsed: number;
|
|
97
|
+
sourceId?: string;
|
|
98
|
+
sourceTitle?: string;
|
|
99
|
+
}
|
|
100
|
+
declare class UniMemoryError extends Error {
|
|
101
|
+
status?: number | undefined;
|
|
102
|
+
code?: string | undefined;
|
|
103
|
+
constructor(message: string, status?: number | undefined, code?: string | undefined);
|
|
60
104
|
}
|
|
61
105
|
declare class UniMemory {
|
|
62
106
|
private apiKey;
|
|
@@ -64,23 +108,45 @@ declare class UniMemory {
|
|
|
64
108
|
constructor(config: UniMemoryConfig);
|
|
65
109
|
private request;
|
|
66
110
|
/**
|
|
67
|
-
*
|
|
111
|
+
* Store an explicit memory (deterministic, no LLM).
|
|
68
112
|
*/
|
|
69
|
-
|
|
113
|
+
add(options: CreateMemoryOptions): Promise<CreateMemoryResponse>;
|
|
70
114
|
/**
|
|
71
|
-
*
|
|
115
|
+
* List memories with optional filters.
|
|
72
116
|
*/
|
|
73
|
-
|
|
117
|
+
list(options?: ListMemoriesOptions): Promise<ListMemoriesResponse>;
|
|
118
|
+
/**
|
|
119
|
+
* Get a single memory by ID.
|
|
120
|
+
*/
|
|
121
|
+
get(memoryId: string): Promise<Memory>;
|
|
74
122
|
/**
|
|
75
|
-
*
|
|
123
|
+
* Update a memory (tags, salience, metadata only — content cannot be changed).
|
|
76
124
|
*/
|
|
77
|
-
|
|
125
|
+
update(memoryId: string, options: UpdateMemoryOptions): Promise<Memory>;
|
|
78
126
|
/**
|
|
79
|
-
* Delete a memory
|
|
127
|
+
* Delete a memory.
|
|
80
128
|
*/
|
|
81
|
-
|
|
129
|
+
delete(memoryId: string): Promise<{
|
|
82
130
|
success: boolean;
|
|
131
|
+
id: string;
|
|
83
132
|
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Semantic search across memories.
|
|
135
|
+
*/
|
|
136
|
+
search(query: string, options?: SearchOptions): Promise<SearchResponse>;
|
|
137
|
+
/**
|
|
138
|
+
* Ingest raw text — LLM extracts memories in the background.
|
|
139
|
+
*/
|
|
140
|
+
ingestText(options: IngestTextOptions): Promise<IngestResponse>;
|
|
141
|
+
/**
|
|
142
|
+
* Ingest chat messages — LLM extracts memories in the background.
|
|
143
|
+
*/
|
|
144
|
+
ingestChat(options: IngestChatOptions): Promise<IngestResponse>;
|
|
145
|
+
/**
|
|
146
|
+
* Ingest a document — LLM extracts memories in the background.
|
|
147
|
+
*/
|
|
148
|
+
ingestDocument(options: IngestDocumentOptions): Promise<IngestResponse>;
|
|
149
|
+
private ingestRequest;
|
|
84
150
|
}
|
|
85
151
|
|
|
86
|
-
export { type
|
|
152
|
+
export { type CreateMemoryOptions, type CreateMemoryResponse, type IngestChatOptions, type IngestDocumentOptions, type IngestResponse, type IngestTextOptions, type ListMemoriesOptions, type ListMemoriesResponse, type Memory, type SearchOptions, type SearchResponse, type SearchResult, UniMemory, type UniMemoryConfig, UniMemoryError, type UpdateMemoryOptions, UniMemory as default };
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
UniMemory: () => UniMemory,
|
|
24
|
+
UniMemoryError: () => UniMemoryError,
|
|
24
25
|
default: () => index_default
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -38,102 +39,192 @@ var UniMemory = class {
|
|
|
38
39
|
throw new UniMemoryError("API key is required");
|
|
39
40
|
}
|
|
40
41
|
this.apiKey = config.apiKey;
|
|
41
|
-
this.baseUrl = config.baseUrl || "https://
|
|
42
|
+
this.baseUrl = (config.baseUrl || "https://unimemory.up.railway.app/api/v1").replace(/\/$/, "");
|
|
42
43
|
}
|
|
43
44
|
async request(method, path, body) {
|
|
44
|
-
const url = `${this.baseUrl}${path}`;
|
|
45
45
|
const headers = {
|
|
46
46
|
"Content-Type": "application/json",
|
|
47
47
|
"X-API-Key": this.apiKey
|
|
48
48
|
};
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
options.body = JSON.stringify(body);
|
|
55
|
-
}
|
|
56
|
-
const response = await fetch(url, options);
|
|
57
|
-
if (!response.ok) {
|
|
58
|
-
const error = await response.json().catch(() => ({}));
|
|
49
|
+
const init = { method, headers };
|
|
50
|
+
if (body) init.body = JSON.stringify(body);
|
|
51
|
+
const res = await fetch(`${this.baseUrl}${path}`, init);
|
|
52
|
+
if (!res.ok) {
|
|
53
|
+
const err = await res.json().catch(() => ({}));
|
|
59
54
|
throw new UniMemoryError(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
err.detail || `Request failed with status ${res.status}`,
|
|
56
|
+
res.status,
|
|
57
|
+
err.code
|
|
63
58
|
);
|
|
64
59
|
}
|
|
65
|
-
|
|
60
|
+
if (res.status === 204) return {};
|
|
61
|
+
return res.json();
|
|
66
62
|
}
|
|
63
|
+
// -------------------------------------------------------------------------
|
|
64
|
+
// Core Memory API
|
|
65
|
+
// -------------------------------------------------------------------------
|
|
67
66
|
/**
|
|
68
|
-
*
|
|
67
|
+
* Store an explicit memory (deterministic, no LLM).
|
|
69
68
|
*/
|
|
70
|
-
async
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
async add(options) {
|
|
70
|
+
const res = await this.request(
|
|
71
|
+
"POST",
|
|
72
|
+
"/memories",
|
|
73
|
+
{
|
|
74
|
+
content: options.content,
|
|
75
|
+
user_id: options.userId,
|
|
76
|
+
app_id: options.appId,
|
|
77
|
+
tags: options.tags,
|
|
78
|
+
metadata: options.metadata,
|
|
79
|
+
project_id: options.projectId
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
return { id: res.id, createdAt: res.created_at };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* List memories with optional filters.
|
|
86
|
+
*/
|
|
87
|
+
async list(options) {
|
|
88
|
+
const p = new URLSearchParams();
|
|
89
|
+
if (options?.limit) p.set("limit", String(options.limit));
|
|
90
|
+
if (options?.offset) p.set("offset", String(options.offset));
|
|
91
|
+
if (options?.userId) p.set("user_id", options.userId);
|
|
92
|
+
if (options?.sector) p.set("sector", options.sector);
|
|
93
|
+
const qs = p.toString();
|
|
94
|
+
const res = await this.request("GET", `/memories${qs ? `?${qs}` : ""}`);
|
|
95
|
+
return {
|
|
96
|
+
memories: res.memories.map((m) => ({
|
|
97
|
+
id: m.id,
|
|
98
|
+
content: m.content,
|
|
99
|
+
userId: m.user_id,
|
|
100
|
+
tags: m.tags,
|
|
101
|
+
salience: m.salience,
|
|
102
|
+
createdAt: m.created_at
|
|
103
|
+
})),
|
|
104
|
+
total: res.total
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get a single memory by ID.
|
|
109
|
+
*/
|
|
110
|
+
async get(memoryId) {
|
|
111
|
+
const m = await this.request("GET", `/memories/${memoryId}`);
|
|
112
|
+
return {
|
|
113
|
+
id: m.id,
|
|
114
|
+
content: m.content,
|
|
115
|
+
userId: m.user_id,
|
|
116
|
+
tags: m.tags,
|
|
117
|
+
salience: m.salience,
|
|
118
|
+
createdAt: m.created_at
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Update a memory (tags, salience, metadata only — content cannot be changed).
|
|
123
|
+
*/
|
|
124
|
+
async update(memoryId, options) {
|
|
125
|
+
const m = await this.request("PATCH", `/memories/${memoryId}`, {
|
|
126
|
+
tags: options.tags,
|
|
127
|
+
salience: options.salience,
|
|
75
128
|
metadata: options.metadata
|
|
76
129
|
});
|
|
77
130
|
return {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}))
|
|
131
|
+
id: m.id,
|
|
132
|
+
content: m.content,
|
|
133
|
+
userId: m.user_id,
|
|
134
|
+
tags: m.tags,
|
|
135
|
+
salience: m.salience,
|
|
136
|
+
createdAt: m.created_at
|
|
85
137
|
};
|
|
86
138
|
}
|
|
87
139
|
/**
|
|
88
|
-
*
|
|
140
|
+
* Delete a memory.
|
|
141
|
+
*/
|
|
142
|
+
async delete(memoryId) {
|
|
143
|
+
return this.request("DELETE", `/memories/${memoryId}`);
|
|
144
|
+
}
|
|
145
|
+
// -------------------------------------------------------------------------
|
|
146
|
+
// Search API
|
|
147
|
+
// -------------------------------------------------------------------------
|
|
148
|
+
/**
|
|
149
|
+
* Semantic search across memories.
|
|
89
150
|
*/
|
|
90
151
|
async search(query, options) {
|
|
91
|
-
const
|
|
152
|
+
const res = await this.request("POST", "/search", {
|
|
92
153
|
query,
|
|
93
154
|
limit: options?.limit,
|
|
94
155
|
user_id: options?.userId,
|
|
95
156
|
min_salience: options?.minSalience,
|
|
96
|
-
|
|
157
|
+
project_id: options?.projectId
|
|
97
158
|
});
|
|
98
159
|
return {
|
|
99
|
-
results:
|
|
100
|
-
|
|
101
|
-
|
|
160
|
+
results: res.results.map((r) => ({
|
|
161
|
+
id: r.id,
|
|
162
|
+
content: r.content,
|
|
163
|
+
tags: r.tags,
|
|
164
|
+
salience: r.salience,
|
|
165
|
+
createdAt: r.created_at
|
|
166
|
+
})),
|
|
167
|
+
total: res.total,
|
|
168
|
+
query: res.query
|
|
102
169
|
};
|
|
103
170
|
}
|
|
171
|
+
// -------------------------------------------------------------------------
|
|
172
|
+
// Ingest API (LLM-powered, background processing)
|
|
173
|
+
// -------------------------------------------------------------------------
|
|
104
174
|
/**
|
|
105
|
-
*
|
|
175
|
+
* Ingest raw text — LLM extracts memories in the background.
|
|
106
176
|
*/
|
|
107
|
-
async
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
memories: response.memories.map((m) => ({
|
|
118
|
-
id: m.id,
|
|
119
|
-
content: m.content,
|
|
120
|
-
sector: m.sector,
|
|
121
|
-
salience: m.salience,
|
|
122
|
-
tags: m.tags,
|
|
123
|
-
createdAt: m.created_at
|
|
124
|
-
})),
|
|
125
|
-
total: response.total
|
|
126
|
-
};
|
|
177
|
+
async ingestText(options) {
|
|
178
|
+
return this.ingestRequest("/ingest/text", {
|
|
179
|
+
content: options.content,
|
|
180
|
+
user_id: options.userId,
|
|
181
|
+
app_id: options.appId,
|
|
182
|
+
source_id: options.sourceId,
|
|
183
|
+
project_id: options.projectId,
|
|
184
|
+
create_source: options.createSource
|
|
185
|
+
});
|
|
127
186
|
}
|
|
128
187
|
/**
|
|
129
|
-
*
|
|
188
|
+
* Ingest chat messages — LLM extracts memories in the background.
|
|
130
189
|
*/
|
|
131
|
-
async
|
|
132
|
-
return this.
|
|
190
|
+
async ingestChat(options) {
|
|
191
|
+
return this.ingestRequest("/ingest/chat", {
|
|
192
|
+
messages: options.messages,
|
|
193
|
+
user_id: options.userId,
|
|
194
|
+
app_id: options.appId,
|
|
195
|
+
source_id: options.sourceId,
|
|
196
|
+
project_id: options.projectId,
|
|
197
|
+
source_metadata: options.sourceMetadata
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Ingest a document — LLM extracts memories in the background.
|
|
202
|
+
*/
|
|
203
|
+
async ingestDocument(options) {
|
|
204
|
+
return this.ingestRequest("/ingest/document", {
|
|
205
|
+
content: options.content,
|
|
206
|
+
title: options.title,
|
|
207
|
+
user_id: options.userId,
|
|
208
|
+
app_id: options.appId,
|
|
209
|
+
source_id: options.sourceId,
|
|
210
|
+
project_id: options.projectId
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
async ingestRequest(path, body) {
|
|
214
|
+
const res = await this.request("POST", path, body);
|
|
215
|
+
return {
|
|
216
|
+
stored: res.stored,
|
|
217
|
+
skipped: res.skipped,
|
|
218
|
+
memoryIds: res.memory_ids,
|
|
219
|
+
tokensUsed: res.tokens_used,
|
|
220
|
+
sourceId: res.source_id,
|
|
221
|
+
sourceTitle: res.source_title
|
|
222
|
+
};
|
|
133
223
|
}
|
|
134
224
|
};
|
|
135
225
|
var index_default = UniMemory;
|
|
136
226
|
// Annotate the CommonJS export names for ESM import in node:
|
|
137
227
|
0 && (module.exports = {
|
|
138
|
-
UniMemory
|
|
228
|
+
UniMemory,
|
|
229
|
+
UniMemoryError
|
|
139
230
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -13,102 +13,192 @@ var UniMemory = class {
|
|
|
13
13
|
throw new UniMemoryError("API key is required");
|
|
14
14
|
}
|
|
15
15
|
this.apiKey = config.apiKey;
|
|
16
|
-
this.baseUrl = config.baseUrl || "https://
|
|
16
|
+
this.baseUrl = (config.baseUrl || "https://unimemory.up.railway.app/api/v1").replace(/\/$/, "");
|
|
17
17
|
}
|
|
18
18
|
async request(method, path, body) {
|
|
19
|
-
const url = `${this.baseUrl}${path}`;
|
|
20
19
|
const headers = {
|
|
21
20
|
"Content-Type": "application/json",
|
|
22
21
|
"X-API-Key": this.apiKey
|
|
23
22
|
};
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
options.body = JSON.stringify(body);
|
|
30
|
-
}
|
|
31
|
-
const response = await fetch(url, options);
|
|
32
|
-
if (!response.ok) {
|
|
33
|
-
const error = await response.json().catch(() => ({}));
|
|
23
|
+
const init = { method, headers };
|
|
24
|
+
if (body) init.body = JSON.stringify(body);
|
|
25
|
+
const res = await fetch(`${this.baseUrl}${path}`, init);
|
|
26
|
+
if (!res.ok) {
|
|
27
|
+
const err = await res.json().catch(() => ({}));
|
|
34
28
|
throw new UniMemoryError(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
err.detail || `Request failed with status ${res.status}`,
|
|
30
|
+
res.status,
|
|
31
|
+
err.code
|
|
38
32
|
);
|
|
39
33
|
}
|
|
40
|
-
|
|
34
|
+
if (res.status === 204) return {};
|
|
35
|
+
return res.json();
|
|
41
36
|
}
|
|
37
|
+
// -------------------------------------------------------------------------
|
|
38
|
+
// Core Memory API
|
|
39
|
+
// -------------------------------------------------------------------------
|
|
42
40
|
/**
|
|
43
|
-
*
|
|
41
|
+
* Store an explicit memory (deterministic, no LLM).
|
|
44
42
|
*/
|
|
45
|
-
async
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
async add(options) {
|
|
44
|
+
const res = await this.request(
|
|
45
|
+
"POST",
|
|
46
|
+
"/memories",
|
|
47
|
+
{
|
|
48
|
+
content: options.content,
|
|
49
|
+
user_id: options.userId,
|
|
50
|
+
app_id: options.appId,
|
|
51
|
+
tags: options.tags,
|
|
52
|
+
metadata: options.metadata,
|
|
53
|
+
project_id: options.projectId
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
return { id: res.id, createdAt: res.created_at };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* List memories with optional filters.
|
|
60
|
+
*/
|
|
61
|
+
async list(options) {
|
|
62
|
+
const p = new URLSearchParams();
|
|
63
|
+
if (options?.limit) p.set("limit", String(options.limit));
|
|
64
|
+
if (options?.offset) p.set("offset", String(options.offset));
|
|
65
|
+
if (options?.userId) p.set("user_id", options.userId);
|
|
66
|
+
if (options?.sector) p.set("sector", options.sector);
|
|
67
|
+
const qs = p.toString();
|
|
68
|
+
const res = await this.request("GET", `/memories${qs ? `?${qs}` : ""}`);
|
|
69
|
+
return {
|
|
70
|
+
memories: res.memories.map((m) => ({
|
|
71
|
+
id: m.id,
|
|
72
|
+
content: m.content,
|
|
73
|
+
userId: m.user_id,
|
|
74
|
+
tags: m.tags,
|
|
75
|
+
salience: m.salience,
|
|
76
|
+
createdAt: m.created_at
|
|
77
|
+
})),
|
|
78
|
+
total: res.total
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get a single memory by ID.
|
|
83
|
+
*/
|
|
84
|
+
async get(memoryId) {
|
|
85
|
+
const m = await this.request("GET", `/memories/${memoryId}`);
|
|
86
|
+
return {
|
|
87
|
+
id: m.id,
|
|
88
|
+
content: m.content,
|
|
89
|
+
userId: m.user_id,
|
|
90
|
+
tags: m.tags,
|
|
91
|
+
salience: m.salience,
|
|
92
|
+
createdAt: m.created_at
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Update a memory (tags, salience, metadata only — content cannot be changed).
|
|
97
|
+
*/
|
|
98
|
+
async update(memoryId, options) {
|
|
99
|
+
const m = await this.request("PATCH", `/memories/${memoryId}`, {
|
|
100
|
+
tags: options.tags,
|
|
101
|
+
salience: options.salience,
|
|
50
102
|
metadata: options.metadata
|
|
51
103
|
});
|
|
52
104
|
return {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}))
|
|
105
|
+
id: m.id,
|
|
106
|
+
content: m.content,
|
|
107
|
+
userId: m.user_id,
|
|
108
|
+
tags: m.tags,
|
|
109
|
+
salience: m.salience,
|
|
110
|
+
createdAt: m.created_at
|
|
60
111
|
};
|
|
61
112
|
}
|
|
62
113
|
/**
|
|
63
|
-
*
|
|
114
|
+
* Delete a memory.
|
|
115
|
+
*/
|
|
116
|
+
async delete(memoryId) {
|
|
117
|
+
return this.request("DELETE", `/memories/${memoryId}`);
|
|
118
|
+
}
|
|
119
|
+
// -------------------------------------------------------------------------
|
|
120
|
+
// Search API
|
|
121
|
+
// -------------------------------------------------------------------------
|
|
122
|
+
/**
|
|
123
|
+
* Semantic search across memories.
|
|
64
124
|
*/
|
|
65
125
|
async search(query, options) {
|
|
66
|
-
const
|
|
126
|
+
const res = await this.request("POST", "/search", {
|
|
67
127
|
query,
|
|
68
128
|
limit: options?.limit,
|
|
69
129
|
user_id: options?.userId,
|
|
70
130
|
min_salience: options?.minSalience,
|
|
71
|
-
|
|
131
|
+
project_id: options?.projectId
|
|
72
132
|
});
|
|
73
133
|
return {
|
|
74
|
-
results:
|
|
75
|
-
|
|
76
|
-
|
|
134
|
+
results: res.results.map((r) => ({
|
|
135
|
+
id: r.id,
|
|
136
|
+
content: r.content,
|
|
137
|
+
tags: r.tags,
|
|
138
|
+
salience: r.salience,
|
|
139
|
+
createdAt: r.created_at
|
|
140
|
+
})),
|
|
141
|
+
total: res.total,
|
|
142
|
+
query: res.query
|
|
77
143
|
};
|
|
78
144
|
}
|
|
145
|
+
// -------------------------------------------------------------------------
|
|
146
|
+
// Ingest API (LLM-powered, background processing)
|
|
147
|
+
// -------------------------------------------------------------------------
|
|
79
148
|
/**
|
|
80
|
-
*
|
|
149
|
+
* Ingest raw text — LLM extracts memories in the background.
|
|
81
150
|
*/
|
|
82
|
-
async
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
memories: response.memories.map((m) => ({
|
|
93
|
-
id: m.id,
|
|
94
|
-
content: m.content,
|
|
95
|
-
sector: m.sector,
|
|
96
|
-
salience: m.salience,
|
|
97
|
-
tags: m.tags,
|
|
98
|
-
createdAt: m.created_at
|
|
99
|
-
})),
|
|
100
|
-
total: response.total
|
|
101
|
-
};
|
|
151
|
+
async ingestText(options) {
|
|
152
|
+
return this.ingestRequest("/ingest/text", {
|
|
153
|
+
content: options.content,
|
|
154
|
+
user_id: options.userId,
|
|
155
|
+
app_id: options.appId,
|
|
156
|
+
source_id: options.sourceId,
|
|
157
|
+
project_id: options.projectId,
|
|
158
|
+
create_source: options.createSource
|
|
159
|
+
});
|
|
102
160
|
}
|
|
103
161
|
/**
|
|
104
|
-
*
|
|
162
|
+
* Ingest chat messages — LLM extracts memories in the background.
|
|
105
163
|
*/
|
|
106
|
-
async
|
|
107
|
-
return this.
|
|
164
|
+
async ingestChat(options) {
|
|
165
|
+
return this.ingestRequest("/ingest/chat", {
|
|
166
|
+
messages: options.messages,
|
|
167
|
+
user_id: options.userId,
|
|
168
|
+
app_id: options.appId,
|
|
169
|
+
source_id: options.sourceId,
|
|
170
|
+
project_id: options.projectId,
|
|
171
|
+
source_metadata: options.sourceMetadata
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Ingest a document — LLM extracts memories in the background.
|
|
176
|
+
*/
|
|
177
|
+
async ingestDocument(options) {
|
|
178
|
+
return this.ingestRequest("/ingest/document", {
|
|
179
|
+
content: options.content,
|
|
180
|
+
title: options.title,
|
|
181
|
+
user_id: options.userId,
|
|
182
|
+
app_id: options.appId,
|
|
183
|
+
source_id: options.sourceId,
|
|
184
|
+
project_id: options.projectId
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
async ingestRequest(path, body) {
|
|
188
|
+
const res = await this.request("POST", path, body);
|
|
189
|
+
return {
|
|
190
|
+
stored: res.stored,
|
|
191
|
+
skipped: res.skipped,
|
|
192
|
+
memoryIds: res.memory_ids,
|
|
193
|
+
tokensUsed: res.tokens_used,
|
|
194
|
+
sourceId: res.source_id,
|
|
195
|
+
sourceTitle: res.source_title
|
|
196
|
+
};
|
|
108
197
|
}
|
|
109
198
|
};
|
|
110
199
|
var index_default = UniMemory;
|
|
111
200
|
export {
|
|
112
201
|
UniMemory,
|
|
202
|
+
UniMemoryError,
|
|
113
203
|
index_default as default
|
|
114
204
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unimemory",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "UniMemory SDK -
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "UniMemory SDK - The memory layer for your AI apps.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|