rice-node-sdk 1.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 +270 -0
- package/dist/Client.d.ts +16 -0
- package/dist/Client.js +117 -0
- package/dist/config.d.ts +13 -0
- package/dist/config.js +53 -0
- package/dist/index.d.ts +110 -0
- package/dist/index.js +34 -0
- package/dist/state/index.d.ts +62 -0
- package/dist/state/index.js +189 -0
- package/dist/state/proto/state.proto +100 -0
- package/dist/state/tools.d.ts +97 -0
- package/dist/state/tools.js +13 -0
- package/dist/storage/client/BaseClient.d.ts +133 -0
- package/dist/storage/client/BaseClient.js +81 -0
- package/dist/storage/client/GrpcClient.d.ts +87 -0
- package/dist/storage/client/GrpcClient.js +398 -0
- package/dist/storage/client/HttpClient.d.ts +87 -0
- package/dist/storage/client/HttpClient.js +335 -0
- package/dist/storage/client/RiceDBClient.d.ts +306 -0
- package/dist/storage/client/RiceDBClient.js +408 -0
- package/dist/storage/index.d.ts +8 -0
- package/dist/storage/index.js +29 -0
- package/dist/storage/proto/ricedb.d.ts +1183 -0
- package/dist/storage/proto/ricedb.js +4469 -0
- package/dist/storage/utils/BitVector.d.ts +10 -0
- package/dist/storage/utils/BitVector.js +54 -0
- package/dist/tools/anthropic.d.ts +29 -0
- package/dist/tools/anthropic.js +44 -0
- package/dist/tools/execute.d.ts +2 -0
- package/dist/tools/execute.js +22 -0
- package/dist/tools/google.d.ts +29 -0
- package/dist/tools/google.js +44 -0
- package/dist/tools/openai.d.ts +35 -0
- package/dist/tools/openai.js +53 -0
- package/package.json +58 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HttpClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const BaseClient_1 = require("./BaseClient");
|
|
9
|
+
const long_1 = __importDefault(require("long"));
|
|
10
|
+
const BitVector_1 = require("../utils/BitVector");
|
|
11
|
+
class HttpClient extends BaseClient_1.BaseRiceDBClient {
|
|
12
|
+
constructor(host = "localhost", port = 3000, token) {
|
|
13
|
+
super(host, port);
|
|
14
|
+
this.token = null;
|
|
15
|
+
if (token) {
|
|
16
|
+
this.token = token;
|
|
17
|
+
}
|
|
18
|
+
this.client = axios_1.default.create({
|
|
19
|
+
baseURL: `http://${host}:${port}`,
|
|
20
|
+
timeout: 30000,
|
|
21
|
+
validateStatus: () => true, // Handle status codes manually
|
|
22
|
+
});
|
|
23
|
+
if (this.token) {
|
|
24
|
+
this.setAuthHeader();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async connect() {
|
|
28
|
+
try {
|
|
29
|
+
const res = await this.client.get("/health");
|
|
30
|
+
this.connected = res.status === 200;
|
|
31
|
+
return this.connected;
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
this.connected = false;
|
|
35
|
+
throw e;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
disconnect() {
|
|
39
|
+
this.connected = false;
|
|
40
|
+
}
|
|
41
|
+
setAuthHeader() {
|
|
42
|
+
if (this.token) {
|
|
43
|
+
this.client.defaults.headers.common["Authorization"] = `Bearer ${this.token}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async request(method, url, data, params) {
|
|
47
|
+
const res = await this.client.request({
|
|
48
|
+
method,
|
|
49
|
+
url,
|
|
50
|
+
data,
|
|
51
|
+
params,
|
|
52
|
+
});
|
|
53
|
+
if (res.status >= 400) {
|
|
54
|
+
throw new Error(`Request failed with status ${res.status}: ${JSON.stringify(res.data)}`);
|
|
55
|
+
}
|
|
56
|
+
return res.data;
|
|
57
|
+
}
|
|
58
|
+
async health() {
|
|
59
|
+
return this.request("GET", "/health");
|
|
60
|
+
}
|
|
61
|
+
async login(username, password) {
|
|
62
|
+
const res = await this.request("POST", "/auth/login", { username, password });
|
|
63
|
+
this.token = res.token;
|
|
64
|
+
this.setAuthHeader();
|
|
65
|
+
return this.token;
|
|
66
|
+
}
|
|
67
|
+
async createUser(username, password, role = "user") {
|
|
68
|
+
const res = await this.request("POST", "/auth/create_user", { username, password, role });
|
|
69
|
+
return long_1.default.fromNumber(res.user_id);
|
|
70
|
+
}
|
|
71
|
+
async deleteUser(username) {
|
|
72
|
+
await this.request("DELETE", "/auth/delete_user", { username });
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
async getUser(username) {
|
|
76
|
+
return this.request("GET", `/auth/users/${username}`);
|
|
77
|
+
}
|
|
78
|
+
async listUsers() {
|
|
79
|
+
return this.request("GET", "/auth/users");
|
|
80
|
+
}
|
|
81
|
+
async insert(nodeId, text, metadata, userId = 1, sessionId, embedding) {
|
|
82
|
+
const payload = {
|
|
83
|
+
id: this.toLong(nodeId).toNumber(),
|
|
84
|
+
text,
|
|
85
|
+
metadata,
|
|
86
|
+
user_id: this.toLong(userId).toNumber(),
|
|
87
|
+
};
|
|
88
|
+
if (sessionId)
|
|
89
|
+
payload.session_id = sessionId;
|
|
90
|
+
if (embedding)
|
|
91
|
+
payload.embedding = embedding;
|
|
92
|
+
const res = await this.request("POST", "/insert", payload);
|
|
93
|
+
if (!res.success) {
|
|
94
|
+
throw new Error(res.message || "Insert failed");
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
success: res.success,
|
|
98
|
+
nodeId: long_1.default.fromValue(res.node_id),
|
|
99
|
+
message: res.message,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async search(query, userId, k = 10, sessionId, filter, queryEmbedding) {
|
|
103
|
+
const payload = {
|
|
104
|
+
query,
|
|
105
|
+
user_id: this.toLong(userId).toNumber(),
|
|
106
|
+
k,
|
|
107
|
+
};
|
|
108
|
+
if (sessionId)
|
|
109
|
+
payload.session_id = sessionId;
|
|
110
|
+
if (filter)
|
|
111
|
+
payload.filter = filter;
|
|
112
|
+
if (queryEmbedding)
|
|
113
|
+
payload.query_embedding = queryEmbedding;
|
|
114
|
+
const res = await this.request("POST", "/search", payload);
|
|
115
|
+
const results = Array.isArray(res) ? res : res.results || [];
|
|
116
|
+
return results.map((r) => ({
|
|
117
|
+
id: long_1.default.fromValue(r.id),
|
|
118
|
+
similarity: r.similarity,
|
|
119
|
+
metadata: r.metadata,
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
async delete(nodeId, sessionId) {
|
|
123
|
+
const params = {};
|
|
124
|
+
if (sessionId)
|
|
125
|
+
params.session_id = sessionId;
|
|
126
|
+
await this.request("DELETE", `/node/${this.toLong(nodeId).toString()}`, undefined, params);
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
// Cortex
|
|
130
|
+
async createSession(parentSessionId) {
|
|
131
|
+
const payload = {};
|
|
132
|
+
if (parentSessionId)
|
|
133
|
+
payload.parent_session_id = parentSessionId;
|
|
134
|
+
const res = await this.request("POST", "/session/create", payload);
|
|
135
|
+
return res.session_id;
|
|
136
|
+
}
|
|
137
|
+
async snapshotSession(sessionId, path) {
|
|
138
|
+
await this.request("POST", `/session/${sessionId}/snapshot`, { path });
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
async loadSession(path) {
|
|
142
|
+
const res = await this.request("POST", "/session/load", { path });
|
|
143
|
+
return res.session_id;
|
|
144
|
+
}
|
|
145
|
+
async commitSession(sessionId, mergeStrategy = "overwrite") {
|
|
146
|
+
await this.request("POST", `/session/${sessionId}/commit`, {
|
|
147
|
+
merge_strategy: mergeStrategy,
|
|
148
|
+
});
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
async dropSession(sessionId) {
|
|
152
|
+
await this.request("DELETE", `/session/${sessionId}/drop`);
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
// SDM
|
|
156
|
+
async writeMemory(address, data, userId = 1) {
|
|
157
|
+
const res = await this.request("POST", "/sdm/write", {
|
|
158
|
+
address: address.toList().map((l) => l.toNumber()),
|
|
159
|
+
data: data.toList().map((l) => l.toNumber()),
|
|
160
|
+
user_id: this.toLong(userId).toNumber(),
|
|
161
|
+
});
|
|
162
|
+
return { success: res.success, message: res.message };
|
|
163
|
+
}
|
|
164
|
+
async readMemory(address, userId = 1) {
|
|
165
|
+
const res = await this.request("POST", "/sdm/read", {
|
|
166
|
+
address: address.toList().map((l) => l.toNumber()),
|
|
167
|
+
user_id: this.toLong(userId).toNumber(),
|
|
168
|
+
});
|
|
169
|
+
// Assuming res.data is list of numbers
|
|
170
|
+
return new BitVector_1.BitVector(res.data.map((n) => long_1.default.fromNumber(n)));
|
|
171
|
+
}
|
|
172
|
+
// Agent Memory
|
|
173
|
+
async addMemory(sessionId, agentId, content, metadata = {}, ttlSeconds) {
|
|
174
|
+
const payload = {
|
|
175
|
+
agent_id: agentId,
|
|
176
|
+
content,
|
|
177
|
+
metadata,
|
|
178
|
+
};
|
|
179
|
+
if (ttlSeconds !== undefined)
|
|
180
|
+
payload.ttl_seconds = ttlSeconds;
|
|
181
|
+
const res = await this.request("POST", `/memory/${sessionId}`, payload);
|
|
182
|
+
return {
|
|
183
|
+
success: res.success,
|
|
184
|
+
message: res.message,
|
|
185
|
+
entry: {
|
|
186
|
+
...res.entry,
|
|
187
|
+
timestamp: long_1.default.fromValue(res.entry.timestamp),
|
|
188
|
+
expiresAt: res.entry.expires_at
|
|
189
|
+
? long_1.default.fromValue(res.entry.expires_at)
|
|
190
|
+
: undefined,
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
async getMemory(sessionId, limit = 50, after = 0, filter = {}) {
|
|
195
|
+
const params = { limit };
|
|
196
|
+
if (after)
|
|
197
|
+
params.after_timestamp = long_1.default.fromValue(after).toNumber();
|
|
198
|
+
const res = await this.request("GET", `/memory/${sessionId}`, undefined, params);
|
|
199
|
+
const entries = res.entries || [];
|
|
200
|
+
return entries.map((e) => ({
|
|
201
|
+
...e,
|
|
202
|
+
timestamp: long_1.default.fromValue(e.timestamp),
|
|
203
|
+
expiresAt: e.expires_at ? long_1.default.fromValue(e.expires_at) : undefined,
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
async clearMemory(sessionId) {
|
|
207
|
+
const res = await this.request("DELETE", `/memory/${sessionId}`);
|
|
208
|
+
return { success: res.success, message: res.message || "" };
|
|
209
|
+
}
|
|
210
|
+
async *watchMemory(sessionId) {
|
|
211
|
+
throw new Error("Watch memory is not supported via HTTP transport. Use gRPC.");
|
|
212
|
+
}
|
|
213
|
+
// Graph
|
|
214
|
+
async addEdge(fromNode, toNode, relation, weight = 1.0) {
|
|
215
|
+
await this.request("POST", "/graph/edge", {
|
|
216
|
+
from: this.toLong(fromNode).toNumber(),
|
|
217
|
+
to: this.toLong(toNode).toNumber(),
|
|
218
|
+
relation,
|
|
219
|
+
weight,
|
|
220
|
+
});
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
async getNeighbors(nodeId, relation) {
|
|
224
|
+
const payload = { node_id: this.toLong(nodeId).toNumber() };
|
|
225
|
+
if (relation)
|
|
226
|
+
payload.relation = relation;
|
|
227
|
+
const res = await this.request("POST", "/graph/neighbors", payload);
|
|
228
|
+
return (res.neighbors || []).map((id) => long_1.default.fromNumber(id));
|
|
229
|
+
}
|
|
230
|
+
async traverse(startNode, maxDepth = 1) {
|
|
231
|
+
const res = await this.request("POST", "/graph/traverse", {
|
|
232
|
+
start: this.toLong(startNode).toNumber(),
|
|
233
|
+
max_depth: maxDepth,
|
|
234
|
+
});
|
|
235
|
+
return (res.visited || []).map((id) => long_1.default.fromNumber(id));
|
|
236
|
+
}
|
|
237
|
+
async sampleGraph(limit = 100) {
|
|
238
|
+
return this.request("POST", "/graph/sample", { limit });
|
|
239
|
+
}
|
|
240
|
+
async *subscribe(filterType = "all", nodeId, queryText = "", threshold = 0.8) {
|
|
241
|
+
throw new Error("Subscribe is not supported via HTTP transport. Use gRPC.");
|
|
242
|
+
}
|
|
243
|
+
async batchInsert(documents, userId = 1) {
|
|
244
|
+
const payload = documents.map((doc) => ({
|
|
245
|
+
id: this.toLong(doc.id).toNumber(),
|
|
246
|
+
text: doc.text || "",
|
|
247
|
+
metadata: doc.metadata,
|
|
248
|
+
user_id: doc.userId !== undefined
|
|
249
|
+
? this.toLong(doc.userId).toNumber()
|
|
250
|
+
: this.toLong(userId).toNumber(),
|
|
251
|
+
}));
|
|
252
|
+
const res = await this.request("POST", "/batch_insert", payload);
|
|
253
|
+
return {
|
|
254
|
+
count: res.count,
|
|
255
|
+
nodeIds: (res.node_ids || []).map((id) => long_1.default.fromNumber(id)),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
async grantPermission(nodeId, userId, permissions) {
|
|
259
|
+
await this.request("POST", "/acl/grant", {
|
|
260
|
+
node_id: this.toLong(nodeId).toNumber(),
|
|
261
|
+
target_user_id: this.toLong(userId).toNumber(),
|
|
262
|
+
permissions,
|
|
263
|
+
});
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
async revokePermission(nodeId, userId) {
|
|
267
|
+
await this.request("POST", "/acl/revoke", {
|
|
268
|
+
node_id: this.toLong(nodeId).toNumber(),
|
|
269
|
+
target_user_id: this.toLong(userId).toNumber(),
|
|
270
|
+
});
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
async checkPermission(nodeId, userId, permissionType) {
|
|
274
|
+
const res = await this.request("POST", "/acl/check", {
|
|
275
|
+
node_id: this.toLong(nodeId).toNumber(),
|
|
276
|
+
user_id: this.toLong(userId).toNumber(),
|
|
277
|
+
permission_type: permissionType,
|
|
278
|
+
});
|
|
279
|
+
return res.allowed || false;
|
|
280
|
+
}
|
|
281
|
+
async batchGrant(grants) {
|
|
282
|
+
const results = [];
|
|
283
|
+
const errors = [];
|
|
284
|
+
for (let i = 0; i < grants.length; i++) {
|
|
285
|
+
const grant = grants[i];
|
|
286
|
+
try {
|
|
287
|
+
const success = await this.grantPermission(grant.nodeId, grant.userId, grant.permissions);
|
|
288
|
+
results.push({
|
|
289
|
+
index: i,
|
|
290
|
+
nodeId: grant.nodeId,
|
|
291
|
+
userId: grant.userId,
|
|
292
|
+
success: true,
|
|
293
|
+
result: success,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
catch (e) {
|
|
297
|
+
errors.push({
|
|
298
|
+
index: i,
|
|
299
|
+
nodeId: grant.nodeId,
|
|
300
|
+
userId: grant.userId,
|
|
301
|
+
error: e.message || String(e),
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
total: grants.length,
|
|
307
|
+
successful: results.length,
|
|
308
|
+
failed: errors.length,
|
|
309
|
+
results,
|
|
310
|
+
errors,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
async insertWithAcl(nodeId, text, metadata, userPermissions) {
|
|
314
|
+
if (!userPermissions || userPermissions.length === 0) {
|
|
315
|
+
throw new Error("At least one user permission must be provided");
|
|
316
|
+
}
|
|
317
|
+
const primaryUser = userPermissions[0];
|
|
318
|
+
const primaryUserId = primaryUser.userId;
|
|
319
|
+
// 1. Insert for primary user
|
|
320
|
+
const insertRes = await this.insert(nodeId, text, metadata, primaryUserId);
|
|
321
|
+
// 2. Grant permissions for others
|
|
322
|
+
const additionalGrants = userPermissions.slice(1).map((p) => ({
|
|
323
|
+
nodeId: nodeId,
|
|
324
|
+
userId: p.userId,
|
|
325
|
+
permissions: p.permissions,
|
|
326
|
+
}));
|
|
327
|
+
if (additionalGrants.length > 0) {
|
|
328
|
+
const grantRes = await this.batchGrant(additionalGrants);
|
|
329
|
+
insertRes.aclGrants = grantRes;
|
|
330
|
+
}
|
|
331
|
+
insertRes.aclUsers = userPermissions;
|
|
332
|
+
return insertRes;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
exports.HttpClient = HttpClient;
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { BaseRiceDBClient, HealthInfo, InsertResult, SearchResultItem, MemoryEntry } from "./BaseClient";
|
|
2
|
+
import Long from "long";
|
|
3
|
+
import { BitVector } from "../utils/BitVector";
|
|
4
|
+
/**
|
|
5
|
+
* Client for RiceDB (Persistent Semantic Database).
|
|
6
|
+
* Supports both gRPC and HTTP transports.
|
|
7
|
+
*/
|
|
8
|
+
export declare class RiceDBClient extends BaseRiceDBClient {
|
|
9
|
+
private client;
|
|
10
|
+
private transport;
|
|
11
|
+
private _grpcPort;
|
|
12
|
+
private _httpPort;
|
|
13
|
+
private token;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new RiceDB client instance.
|
|
16
|
+
* @param host - The hostname of the RiceDB server (default: "localhost").
|
|
17
|
+
* @param transport - The transport protocol to use: "grpc", "http", or "auto" (default: "auto").
|
|
18
|
+
* @param grpcPort - The port for gRPC connections (default: 50051).
|
|
19
|
+
* @param httpPort - The port for HTTP connections (default: 3000).
|
|
20
|
+
* @param token - Optional authentication token.
|
|
21
|
+
*/
|
|
22
|
+
constructor(host?: string, transport?: "grpc" | "http" | "auto", grpcPort?: number, httpPort?: number, token?: string);
|
|
23
|
+
/**
|
|
24
|
+
* Connects to the RiceDB server.
|
|
25
|
+
* If transport is "auto", tries gRPC first, then falls back to HTTP.
|
|
26
|
+
* @returns A promise that resolves to true if connected successfully.
|
|
27
|
+
*/
|
|
28
|
+
connect(): Promise<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* Disconnects from the RiceDB server.
|
|
31
|
+
*/
|
|
32
|
+
disconnect(): void;
|
|
33
|
+
private checkConnected;
|
|
34
|
+
/**
|
|
35
|
+
* Checks the health of the RiceDB server.
|
|
36
|
+
* @returns Detailed health information.
|
|
37
|
+
*/
|
|
38
|
+
health(): Promise<HealthInfo>;
|
|
39
|
+
/**
|
|
40
|
+
* Logs in a user.
|
|
41
|
+
* @param username - The username.
|
|
42
|
+
* @param password - The password.
|
|
43
|
+
* @returns An authentication token or session ID.
|
|
44
|
+
*/
|
|
45
|
+
login(username: string, password: string): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new user.
|
|
48
|
+
* @param username - The username.
|
|
49
|
+
* @param password - The password.
|
|
50
|
+
* @param role - Optional role for the user.
|
|
51
|
+
* @returns The ID of the created user.
|
|
52
|
+
*/
|
|
53
|
+
createUser(username: string, password: string, role?: string): Promise<Long>;
|
|
54
|
+
/**
|
|
55
|
+
* Deletes a user.
|
|
56
|
+
* @param username - The username to delete.
|
|
57
|
+
* @returns True if successful.
|
|
58
|
+
*/
|
|
59
|
+
deleteUser(username: string): Promise<boolean>;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves user details.
|
|
62
|
+
* @param username - The username.
|
|
63
|
+
* @returns User details object.
|
|
64
|
+
*/
|
|
65
|
+
getUser(username: string): Promise<any>;
|
|
66
|
+
/**
|
|
67
|
+
* Lists all users.
|
|
68
|
+
* @returns An array of user objects.
|
|
69
|
+
*/
|
|
70
|
+
listUsers(): Promise<any[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Inserts a document/node into the database.
|
|
73
|
+
* @param nodeId - Unique identifier for the node.
|
|
74
|
+
* @param text - The text content.
|
|
75
|
+
* @param metadata - Arbitrary metadata object.
|
|
76
|
+
* @param userId - The ID of the user inserting.
|
|
77
|
+
* @param sessionId - Optional session ID.
|
|
78
|
+
* @param embedding - Optional pre-computed embedding vector.
|
|
79
|
+
* @returns Result of the insertion.
|
|
80
|
+
*/
|
|
81
|
+
insert(nodeId: Long | number | string, text: string, metadata: any, userId?: Long | number | string, sessionId?: string, embedding?: number[]): Promise<InsertResult>;
|
|
82
|
+
/**
|
|
83
|
+
* Searches for similar documents/nodes.
|
|
84
|
+
* @param query - The query text.
|
|
85
|
+
* @param userId - The user ID performing the search.
|
|
86
|
+
* @param k - Number of results to return (default: 10).
|
|
87
|
+
* @param sessionId - Optional session ID to filter by.
|
|
88
|
+
* @param filter - Metadata filter criteria.
|
|
89
|
+
* @param queryEmbedding - Optional query embedding vector.
|
|
90
|
+
* @returns An array of search results.
|
|
91
|
+
*/
|
|
92
|
+
search(query: string, userId: Long | number | string, k?: number, sessionId?: string, filter?: {
|
|
93
|
+
[key: string]: any;
|
|
94
|
+
}, queryEmbedding?: number[]): Promise<SearchResultItem[]>;
|
|
95
|
+
/**
|
|
96
|
+
* Deletes a document/node.
|
|
97
|
+
* @param nodeId - The ID of the node to delete.
|
|
98
|
+
* @param sessionId - Optional session ID.
|
|
99
|
+
* @returns True if successful.
|
|
100
|
+
*/
|
|
101
|
+
delete(nodeId: Long | number | string, sessionId?: string): Promise<boolean>;
|
|
102
|
+
/**
|
|
103
|
+
* Creates a new session.
|
|
104
|
+
* @param parentSessionId - Optional parent session ID to fork from.
|
|
105
|
+
* @returns The new session ID.
|
|
106
|
+
*/
|
|
107
|
+
createSession(parentSessionId?: string): Promise<string>;
|
|
108
|
+
/**
|
|
109
|
+
* Saves a snapshot of a session to disk.
|
|
110
|
+
* @param sessionId - The session ID.
|
|
111
|
+
* @param path - The file path to save to.
|
|
112
|
+
* @returns True if successful.
|
|
113
|
+
*/
|
|
114
|
+
snapshotSession(sessionId: string, path: string): Promise<boolean>;
|
|
115
|
+
/**
|
|
116
|
+
* Loads a session from a snapshot.
|
|
117
|
+
* @param path - The file path to load from.
|
|
118
|
+
* @returns The loaded session ID.
|
|
119
|
+
*/
|
|
120
|
+
loadSession(path: string): Promise<string>;
|
|
121
|
+
/**
|
|
122
|
+
* Commits changes in a session (e.g., merging back).
|
|
123
|
+
* @param sessionId - The session ID.
|
|
124
|
+
* @param mergeStrategy - Strategy for merging ("overwrite", etc.).
|
|
125
|
+
* @returns True if successful.
|
|
126
|
+
*/
|
|
127
|
+
commitSession(sessionId: string, mergeStrategy?: string): Promise<boolean>;
|
|
128
|
+
/**
|
|
129
|
+
* Drops (deletes) a session.
|
|
130
|
+
* @param sessionId - The session ID.
|
|
131
|
+
* @returns True if successful.
|
|
132
|
+
*/
|
|
133
|
+
dropSession(sessionId: string): Promise<boolean>;
|
|
134
|
+
/**
|
|
135
|
+
* Writes raw data to memory at a specific address.
|
|
136
|
+
* @param address - The memory address (BitVector).
|
|
137
|
+
* @param data - The data to write (BitVector).
|
|
138
|
+
* @param userId - The user ID.
|
|
139
|
+
* @returns Success status and message.
|
|
140
|
+
*/
|
|
141
|
+
writeMemory(address: BitVector, data: BitVector, userId?: Long | number | string): Promise<{
|
|
142
|
+
success: boolean;
|
|
143
|
+
message: string;
|
|
144
|
+
}>;
|
|
145
|
+
/**
|
|
146
|
+
* Reads raw data from memory at a specific address.
|
|
147
|
+
* @param address - The memory address (BitVector).
|
|
148
|
+
* @param userId - The user ID.
|
|
149
|
+
* @returns The data at the address (BitVector).
|
|
150
|
+
*/
|
|
151
|
+
readMemory(address: BitVector, userId?: Long | number | string): Promise<BitVector>;
|
|
152
|
+
/**
|
|
153
|
+
* Adds a high-level memory entry for an agent.
|
|
154
|
+
* @param sessionId - The session ID.
|
|
155
|
+
* @param agentId - The agent ID.
|
|
156
|
+
* @param content - The content of the memory.
|
|
157
|
+
* @param metadata - Optional metadata.
|
|
158
|
+
* @param ttlSeconds - Time-to-live in seconds.
|
|
159
|
+
* @returns The created memory entry.
|
|
160
|
+
*/
|
|
161
|
+
addMemory(sessionId: string, agentId: string, content: string, metadata?: {
|
|
162
|
+
[key: string]: string;
|
|
163
|
+
}, ttlSeconds?: number): Promise<{
|
|
164
|
+
success: boolean;
|
|
165
|
+
message: string;
|
|
166
|
+
entry: MemoryEntry;
|
|
167
|
+
}>;
|
|
168
|
+
/**
|
|
169
|
+
* Retrieves memories for a session.
|
|
170
|
+
* @param sessionId - The session ID.
|
|
171
|
+
* @param limit - Maximum number of memories.
|
|
172
|
+
* @param after - Timestamp or ID to start after.
|
|
173
|
+
* @param filter - Metadata filter.
|
|
174
|
+
* @returns An array of memory entries.
|
|
175
|
+
*/
|
|
176
|
+
getMemory(sessionId: string, limit?: number, after?: number | Long, filter?: {
|
|
177
|
+
[key: string]: string;
|
|
178
|
+
}): Promise<MemoryEntry[]>;
|
|
179
|
+
/**
|
|
180
|
+
* Clears all memories for a session.
|
|
181
|
+
* @param sessionId - The session ID.
|
|
182
|
+
* @returns Success status.
|
|
183
|
+
*/
|
|
184
|
+
clearMemory(sessionId: string): Promise<{
|
|
185
|
+
success: boolean;
|
|
186
|
+
message: string;
|
|
187
|
+
}>;
|
|
188
|
+
/**
|
|
189
|
+
* Watches for changes in memory for a session.
|
|
190
|
+
* @param sessionId - The session ID.
|
|
191
|
+
* @returns An async iterable of changes.
|
|
192
|
+
*/
|
|
193
|
+
watchMemory(sessionId: string): AsyncIterable<any>;
|
|
194
|
+
/**
|
|
195
|
+
* Adds an edge between two nodes in the graph.
|
|
196
|
+
* @param fromNode - Source node ID.
|
|
197
|
+
* @param toNode - Target node ID.
|
|
198
|
+
* @param relation - The type of relation.
|
|
199
|
+
* @param weight - Edge weight (default: 1.0).
|
|
200
|
+
* @returns True if successful.
|
|
201
|
+
*/
|
|
202
|
+
addEdge(fromNode: Long | number | string, toNode: Long | number | string, relation: string, weight?: number): Promise<boolean>;
|
|
203
|
+
/**
|
|
204
|
+
* Gets neighboring nodes.
|
|
205
|
+
* @param nodeId - The node ID.
|
|
206
|
+
* @param relation - Optional relation type to filter by.
|
|
207
|
+
* @returns An array of neighbor node IDs.
|
|
208
|
+
*/
|
|
209
|
+
getNeighbors(nodeId: Long | number | string, relation?: string): Promise<Long[]>;
|
|
210
|
+
/**
|
|
211
|
+
* Traverses the graph from a start node.
|
|
212
|
+
* @param startNode - The starting node ID.
|
|
213
|
+
* @param maxDepth - Maximum depth to traverse (default: 1).
|
|
214
|
+
* @returns An array of visited node IDs.
|
|
215
|
+
*/
|
|
216
|
+
traverse(startNode: Long | number | string, maxDepth?: number): Promise<Long[]>;
|
|
217
|
+
/**
|
|
218
|
+
* Samples random nodes from the graph.
|
|
219
|
+
* @param limit - Number of nodes to sample.
|
|
220
|
+
* @returns Sampled nodes.
|
|
221
|
+
*/
|
|
222
|
+
sampleGraph(limit?: number): Promise<any>;
|
|
223
|
+
/**
|
|
224
|
+
* Subscribes to real-time updates.
|
|
225
|
+
* @param filterType - "all", "node", "query".
|
|
226
|
+
* @param nodeId - Specific node ID to watch.
|
|
227
|
+
* @param queryText - Query text to watch for similar items.
|
|
228
|
+
* @param threshold - Similarity threshold.
|
|
229
|
+
* @returns An async iterable of updates.
|
|
230
|
+
*/
|
|
231
|
+
subscribe(filterType?: string, nodeId?: Long | number | string, queryText?: string, threshold?: number): AsyncIterable<any>;
|
|
232
|
+
/**
|
|
233
|
+
* Inserts multiple documents in a batch.
|
|
234
|
+
* @param documents - Array of documents.
|
|
235
|
+
* @param userId - User ID.
|
|
236
|
+
* @returns Count of inserted items and their node IDs.
|
|
237
|
+
*/
|
|
238
|
+
batchInsert(documents: any[], userId?: Long | number | string): Promise<{
|
|
239
|
+
count: number;
|
|
240
|
+
nodeIds: Long[];
|
|
241
|
+
}>;
|
|
242
|
+
/**
|
|
243
|
+
* Grants permissions on a node to a user.
|
|
244
|
+
* @param nodeId - Node ID.
|
|
245
|
+
* @param userId - User ID.
|
|
246
|
+
* @param permissions - Permissions object ({ read, write, delete }).
|
|
247
|
+
* @returns True if successful.
|
|
248
|
+
*/
|
|
249
|
+
grantPermission(nodeId: Long | number | string, userId: Long | number | string, permissions: {
|
|
250
|
+
read?: boolean;
|
|
251
|
+
write?: boolean;
|
|
252
|
+
delete?: boolean;
|
|
253
|
+
}): Promise<boolean>;
|
|
254
|
+
/**
|
|
255
|
+
* Revokes all permissions on a node for a user.
|
|
256
|
+
* @param nodeId - Node ID.
|
|
257
|
+
* @param userId - User ID.
|
|
258
|
+
* @returns True if successful.
|
|
259
|
+
*/
|
|
260
|
+
revokePermission(nodeId: Long | number | string, userId: Long | number | string): Promise<boolean>;
|
|
261
|
+
/**
|
|
262
|
+
* Checks if a user has a specific permission on a node.
|
|
263
|
+
* @param nodeId - Node ID.
|
|
264
|
+
* @param userId - User ID.
|
|
265
|
+
* @param permissionType - "read", "write", "delete".
|
|
266
|
+
* @returns True if allowed.
|
|
267
|
+
*/
|
|
268
|
+
checkPermission(nodeId: Long | number | string, userId: Long | number | string, permissionType: string): Promise<boolean>;
|
|
269
|
+
/**
|
|
270
|
+
* Grants permissions in batch.
|
|
271
|
+
* @param grants - Array of grant objects.
|
|
272
|
+
* @returns Detailed results of the operation.
|
|
273
|
+
*/
|
|
274
|
+
batchGrant(grants: Array<{
|
|
275
|
+
nodeId: Long | number | string;
|
|
276
|
+
userId: Long | number | string;
|
|
277
|
+
permissions: {
|
|
278
|
+
read?: boolean;
|
|
279
|
+
write?: boolean;
|
|
280
|
+
delete?: boolean;
|
|
281
|
+
};
|
|
282
|
+
}>): Promise<{
|
|
283
|
+
total: number;
|
|
284
|
+
successful: number;
|
|
285
|
+
failed: number;
|
|
286
|
+
results: any[];
|
|
287
|
+
errors: any[];
|
|
288
|
+
}>;
|
|
289
|
+
/**
|
|
290
|
+
* Inserts a node with ACL permissions in one go.
|
|
291
|
+
* @param nodeId - Node ID.
|
|
292
|
+
* @param text - Content.
|
|
293
|
+
* @param metadata - Metadata.
|
|
294
|
+
* @param userPermissions - Array of user permissions.
|
|
295
|
+
* @returns Insertion result.
|
|
296
|
+
*/
|
|
297
|
+
insertWithAcl(nodeId: Long | number | string, text: string, metadata: any, userPermissions: Array<{
|
|
298
|
+
userId: Long | number | string;
|
|
299
|
+
permissions: {
|
|
300
|
+
read?: boolean;
|
|
301
|
+
write?: boolean;
|
|
302
|
+
delete?: boolean;
|
|
303
|
+
};
|
|
304
|
+
}>): Promise<InsertResult>;
|
|
305
|
+
protected toLong(val: Long | number | string): Long;
|
|
306
|
+
}
|