hebbrix 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/index.mjs ADDED
@@ -0,0 +1,550 @@
1
+ // src/resources.ts
2
+ var BaseResource = class {
3
+ constructor(client) {
4
+ this.client = client;
5
+ }
6
+ };
7
+ var AuthResource = class extends BaseResource {
8
+ /**
9
+ * Register a new user
10
+ */
11
+ async register(email, password, fullName) {
12
+ return this.client.post("/v1/auth/register", {
13
+ email,
14
+ password,
15
+ full_name: fullName
16
+ });
17
+ }
18
+ /**
19
+ * Login with email and password
20
+ */
21
+ async login(email, password) {
22
+ return this.client.post("/v1/auth/login", {
23
+ email,
24
+ password
25
+ });
26
+ }
27
+ /**
28
+ * Create a new API key
29
+ */
30
+ async createApiKey(name) {
31
+ return this.client.post("/v1/auth/api-keys", { name });
32
+ }
33
+ /**
34
+ * Get current user information
35
+ */
36
+ async getMe() {
37
+ return this.client.get("/v1/auth/me");
38
+ }
39
+ };
40
+ var CollectionsResource = class extends BaseResource {
41
+ /**
42
+ * Create a new collection
43
+ */
44
+ async create(params) {
45
+ return this.client.post("/v1/collections", params);
46
+ }
47
+ /**
48
+ * List all collections
49
+ */
50
+ async list(params = {}) {
51
+ return this.client.get("/v1/collections", params);
52
+ }
53
+ /**
54
+ * Get a specific collection
55
+ */
56
+ async get(collectionId) {
57
+ return this.client.get(`/v1/collections/${collectionId}`);
58
+ }
59
+ /**
60
+ * Update a collection
61
+ */
62
+ async update(collectionId, params) {
63
+ return this.client.patch(
64
+ `/v1/collections/${collectionId}`,
65
+ params
66
+ );
67
+ }
68
+ /**
69
+ * Delete a collection
70
+ */
71
+ async delete(collectionId) {
72
+ await this.client.delete(`/v1/collections/${collectionId}`);
73
+ }
74
+ };
75
+ var MemoriesResource = class extends BaseResource {
76
+ /**
77
+ * Create a new memory
78
+ */
79
+ async create(params) {
80
+ return this.client.post("/v1/memories", params);
81
+ }
82
+ /**
83
+ * List memories
84
+ */
85
+ async list(params = {}) {
86
+ return this.client.get("/v1/memories", params);
87
+ }
88
+ /**
89
+ * Get a specific memory
90
+ */
91
+ async get(memoryId) {
92
+ return this.client.get(`/v1/memories/${memoryId}`);
93
+ }
94
+ /**
95
+ * Update a memory
96
+ */
97
+ async update(memoryId, params) {
98
+ return this.client.patch(`/v1/memories/${memoryId}`, params);
99
+ }
100
+ /**
101
+ * Delete a memory
102
+ */
103
+ async delete(memoryId) {
104
+ await this.client.delete(`/v1/memories/${memoryId}`);
105
+ }
106
+ };
107
+ var SearchResource = class extends BaseResource {
108
+ /**
109
+ * Search memories
110
+ */
111
+ async search(params) {
112
+ const response = await this.client.post("/v1/search", {
113
+ query: params.query,
114
+ collection_id: params.collection_id,
115
+ limit: params.limit || 10,
116
+ search_type: params.search_type || "hybrid",
117
+ filters: params.filters || {}
118
+ });
119
+ return response.results;
120
+ }
121
+ /**
122
+ * Find similar memories
123
+ */
124
+ async similar(memoryId, limit = 10) {
125
+ const response = await this.client.get(
126
+ `/v1/search/similar/${memoryId}`,
127
+ { limit }
128
+ );
129
+ return response.results;
130
+ }
131
+ /**
132
+ * Perform reasoning over memories
133
+ */
134
+ async reason(params) {
135
+ return this.client.post("/v1/search/reason", {
136
+ query: params.query,
137
+ collection_id: params.collection_id,
138
+ provider: params.provider,
139
+ include_steps: params.include_steps || false
140
+ });
141
+ }
142
+ };
143
+ var RLResource = class extends BaseResource {
144
+ /**
145
+ * Train the Memory Manager agent using RL
146
+ */
147
+ async trainMemoryManager(params) {
148
+ return this.client.post("/rl/train/memory-manager", {
149
+ collection_id: params.collection_id,
150
+ num_episodes: params.num_episodes || 100,
151
+ ...params
152
+ });
153
+ }
154
+ /**
155
+ * Train the Answer Agent using RL
156
+ */
157
+ async trainAnswerAgent(params) {
158
+ return this.client.post("/rl/train/answer-agent", {
159
+ collection_id: params.collection_id,
160
+ num_episodes: params.num_episodes || 100,
161
+ ...params
162
+ });
163
+ }
164
+ /**
165
+ * Get RL training metrics
166
+ */
167
+ async getMetrics() {
168
+ return this.client.get("/rl/metrics");
169
+ }
170
+ /**
171
+ * Evaluate a trained RL agent
172
+ */
173
+ async evaluate(agentType, collectionId) {
174
+ return this.client.post("/rl/evaluate", {
175
+ agent_type: agentType,
176
+ collection_id: collectionId
177
+ });
178
+ }
179
+ };
180
+ var ProceduralResource = class extends BaseResource {
181
+ /**
182
+ * Create a new procedure
183
+ */
184
+ async create(params) {
185
+ return this.client.post("/procedural", {
186
+ name: params.name,
187
+ description: params.description,
188
+ trigger_condition: params.trigger_condition,
189
+ action_sequence: params.action_sequence,
190
+ collection_id: params.collection_id,
191
+ category: params.category,
192
+ metadata: params.metadata || {}
193
+ });
194
+ }
195
+ /**
196
+ * List procedures
197
+ */
198
+ async list(params) {
199
+ return this.client.get("/procedural", {
200
+ collection_id: params?.collection_id,
201
+ category: params?.category,
202
+ skip: params?.skip || 0,
203
+ limit: params?.limit || 100
204
+ });
205
+ }
206
+ /**
207
+ * Get a specific procedure
208
+ */
209
+ async get(procedureId) {
210
+ return this.client.get(`/procedural/${procedureId}`);
211
+ }
212
+ /**
213
+ * Execute a procedure
214
+ */
215
+ async execute(procedureId, context) {
216
+ return this.client.post(`/procedural/${procedureId}/execute`, {
217
+ context: context || {}
218
+ });
219
+ }
220
+ /**
221
+ * Update a procedure
222
+ */
223
+ async update(procedureId, params) {
224
+ return this.client.patch(`/procedural/${procedureId}`, params);
225
+ }
226
+ /**
227
+ * Delete a procedure
228
+ */
229
+ async delete(procedureId) {
230
+ await this.client.delete(`/procedural/${procedureId}`);
231
+ }
232
+ };
233
+ var TemporalResource = class extends BaseResource {
234
+ /**
235
+ * Add a temporal fact to the knowledge graph
236
+ */
237
+ async addFact(params) {
238
+ return this.client.post("/temporal/facts", {
239
+ subject: params.subject,
240
+ predicate: params.predicate,
241
+ object: params.object,
242
+ valid_from: params.valid_from,
243
+ valid_until: params.valid_until,
244
+ confidence: params.confidence || 1,
245
+ source_memory_id: params.source_memory_id,
246
+ metadata: params.metadata || {}
247
+ });
248
+ }
249
+ /**
250
+ * Query temporal facts
251
+ */
252
+ async queryFacts(params) {
253
+ return this.client.get("/temporal/facts", {
254
+ subject: params?.subject,
255
+ predicate: params?.predicate,
256
+ object: params?.object,
257
+ at_time: params?.at_time
258
+ });
259
+ }
260
+ /**
261
+ * Query knowledge state at a specific point in time
262
+ */
263
+ async pointInTime(timestamp, entity) {
264
+ return this.client.post("/temporal/point-in-time", {
265
+ timestamp,
266
+ entity
267
+ });
268
+ }
269
+ };
270
+ var WorkingMemoryResource = class extends BaseResource {
271
+ /**
272
+ * Add item to working memory buffer
273
+ */
274
+ async add(params) {
275
+ return this.client.post("/working-memory", {
276
+ role: params.role,
277
+ content: params.content,
278
+ metadata: params.metadata || {}
279
+ });
280
+ }
281
+ /**
282
+ * Get current working memory context
283
+ */
284
+ async getContext() {
285
+ return this.client.get("/working-memory/context");
286
+ }
287
+ /**
288
+ * Compress working memory buffer
289
+ */
290
+ async compress() {
291
+ return this.client.post("/working-memory/compress");
292
+ }
293
+ /**
294
+ * Clear working memory buffer
295
+ */
296
+ async clear() {
297
+ return this.client.delete("/working-memory");
298
+ }
299
+ };
300
+ var ConsolidationResource = class extends BaseResource {
301
+ /**
302
+ * Trigger memory consolidation
303
+ */
304
+ async consolidate(collectionId, threshold = 100) {
305
+ return this.client.post("/consolidation/consolidate", {
306
+ collection_id: collectionId,
307
+ threshold
308
+ });
309
+ }
310
+ /**
311
+ * Get consolidation statistics
312
+ */
313
+ async getStats(collectionId) {
314
+ return this.client.get("/consolidation/stats", {
315
+ collection_id: collectionId
316
+ });
317
+ }
318
+ /**
319
+ * Archive old memories
320
+ */
321
+ async archive(collectionId, beforeDate) {
322
+ return this.client.post("/consolidation/archive", {
323
+ collection_id: collectionId,
324
+ before_date: beforeDate
325
+ });
326
+ }
327
+ };
328
+ var MemoryToolsResource = class extends BaseResource {
329
+ /**
330
+ * Replace memory content
331
+ */
332
+ async replace(params) {
333
+ return this.client.post("/memory-tools/replace", {
334
+ memory_id: params.memory_id,
335
+ new_content: params.new_content,
336
+ reason: params.reason
337
+ });
338
+ }
339
+ /**
340
+ * Insert new memory at position
341
+ */
342
+ async insert(params) {
343
+ return this.client.post("/memory-tools/insert", {
344
+ collection_id: params.collection_id,
345
+ content: params.content,
346
+ position: params.position,
347
+ reason: params.reason
348
+ });
349
+ }
350
+ /**
351
+ * Re-evaluate memory in light of new information
352
+ */
353
+ async rethink(memoryId, query) {
354
+ return this.client.post("/memory-tools/rethink", {
355
+ memory_id: memoryId,
356
+ query
357
+ });
358
+ }
359
+ };
360
+ var WorldModelResource = class extends BaseResource {
361
+ /**
362
+ * Simulate retrieval without actually retrieving
363
+ */
364
+ async imagineRetrieval(query, collectionId) {
365
+ return this.client.post("/world-model/imagine-retrieval", {
366
+ query,
367
+ collection_id: collectionId
368
+ });
369
+ }
370
+ /**
371
+ * Plan memory operations to achieve goal
372
+ */
373
+ async plan(goal, collectionId) {
374
+ return this.client.post("/world-model/plan", {
375
+ goal,
376
+ collection_id: collectionId
377
+ });
378
+ }
379
+ };
380
+
381
+ // src/errors.ts
382
+ var HebbrixError = class _HebbrixError extends Error {
383
+ constructor(message, statusCode) {
384
+ super(message);
385
+ this.name = "HebbrixError";
386
+ this.statusCode = statusCode;
387
+ Object.setPrototypeOf(this, _HebbrixError.prototype);
388
+ }
389
+ };
390
+ var AuthenticationError = class _AuthenticationError extends HebbrixError {
391
+ constructor(message = "Authentication failed") {
392
+ super(message, 401);
393
+ this.name = "AuthenticationError";
394
+ Object.setPrototypeOf(this, _AuthenticationError.prototype);
395
+ }
396
+ };
397
+ var ValidationError = class _ValidationError extends HebbrixError {
398
+ constructor(message, errors) {
399
+ super(message, 422);
400
+ this.name = "ValidationError";
401
+ this.errors = errors;
402
+ Object.setPrototypeOf(this, _ValidationError.prototype);
403
+ }
404
+ };
405
+ var NotFoundError = class _NotFoundError extends HebbrixError {
406
+ constructor(message = "Resource not found") {
407
+ super(message, 404);
408
+ this.name = "NotFoundError";
409
+ Object.setPrototypeOf(this, _NotFoundError.prototype);
410
+ }
411
+ };
412
+ var RateLimitError = class _RateLimitError extends HebbrixError {
413
+ constructor(message = "Rate limit exceeded") {
414
+ super(message, 429);
415
+ this.name = "RateLimitError";
416
+ Object.setPrototypeOf(this, _RateLimitError.prototype);
417
+ }
418
+ };
419
+ var ServerError = class _ServerError extends HebbrixError {
420
+ constructor(message = "Internal server error") {
421
+ super(message, 500);
422
+ this.name = "ServerError";
423
+ Object.setPrototypeOf(this, _ServerError.prototype);
424
+ }
425
+ };
426
+
427
+ // src/client.ts
428
+ var MemoryClient = class {
429
+ constructor(config = {}) {
430
+ this.apiKey = config.apiKey;
431
+ this.baseUrl = config.baseUrl || "https://memory-api.livelystone-78e9a45c.centralus.azurecontainerapps.io";
432
+ this.timeout = config.timeout || 12e4;
433
+ this.baseUrl = this.baseUrl.replace(/\/$/, "");
434
+ this.auth = new AuthResource(this);
435
+ this.collections = new CollectionsResource(this);
436
+ this.memories = new MemoriesResource(this);
437
+ this.searchResource = new SearchResource(this);
438
+ this.rl = new RLResource(this);
439
+ this.procedural = new ProceduralResource(this);
440
+ this.temporal = new TemporalResource(this);
441
+ this.workingMemory = new WorkingMemoryResource(this);
442
+ this.consolidation = new ConsolidationResource(this);
443
+ this.memoryTools = new MemoryToolsResource(this);
444
+ this.worldModel = new WorldModelResource(this);
445
+ }
446
+ getHeaders() {
447
+ const headers = {
448
+ "Content-Type": "application/json",
449
+ "User-Agent": "hebbrix-typescript/2.0.0"
450
+ };
451
+ if (this.apiKey) {
452
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
453
+ }
454
+ return headers;
455
+ }
456
+ handleError(response, data) {
457
+ const statusCode = response.status;
458
+ const message = data?.error?.message || data?.detail || response.statusText;
459
+ if (statusCode === 401) {
460
+ throw new AuthenticationError(message);
461
+ } else if (statusCode === 404) {
462
+ throw new NotFoundError(message);
463
+ } else if (statusCode === 422) {
464
+ const errors = data?.error?.details || [];
465
+ throw new ValidationError(message, errors);
466
+ } else if (statusCode === 429) {
467
+ throw new RateLimitError(message);
468
+ } else if (statusCode >= 500) {
469
+ throw new ServerError(message);
470
+ } else {
471
+ throw new HebbrixError(message, statusCode);
472
+ }
473
+ }
474
+ async request(method, path, options = {}) {
475
+ const url = `${this.baseUrl}${path}`;
476
+ const response = await fetch(url, {
477
+ method,
478
+ headers: {
479
+ ...this.getHeaders(),
480
+ ...options.headers || {}
481
+ },
482
+ ...options,
483
+ signal: AbortSignal.timeout(this.timeout)
484
+ });
485
+ let data;
486
+ const contentType = response.headers.get("content-type");
487
+ if (contentType?.includes("application/json")) {
488
+ data = await response.json();
489
+ } else {
490
+ data = await response.text();
491
+ }
492
+ if (!response.ok) {
493
+ this.handleError(response, data);
494
+ }
495
+ return data;
496
+ }
497
+ async get(path, params) {
498
+ let url = path;
499
+ if (params) {
500
+ const searchParams = new URLSearchParams();
501
+ Object.entries(params).forEach(([key, value]) => {
502
+ if (value !== void 0 && value !== null) {
503
+ searchParams.append(key, String(value));
504
+ }
505
+ });
506
+ url += `?${searchParams.toString()}`;
507
+ }
508
+ return this.request("GET", url);
509
+ }
510
+ async post(path, body) {
511
+ return this.request("POST", path, {
512
+ body: JSON.stringify(body)
513
+ });
514
+ }
515
+ async patch(path, body) {
516
+ return this.request("PATCH", path, {
517
+ body: JSON.stringify(body)
518
+ });
519
+ }
520
+ async delete(path) {
521
+ return this.request("DELETE", path);
522
+ }
523
+ // Convenience methods
524
+ async search(params) {
525
+ return this.searchResource.search(params);
526
+ }
527
+ async reason(params) {
528
+ return this.searchResource.reason(params);
529
+ }
530
+ };
531
+ export {
532
+ AuthResource,
533
+ AuthenticationError,
534
+ CollectionsResource,
535
+ ConsolidationResource,
536
+ HebbrixError,
537
+ MemoriesResource,
538
+ MemoryClient,
539
+ MemoryToolsResource,
540
+ NotFoundError,
541
+ ProceduralResource,
542
+ RLResource,
543
+ RateLimitError,
544
+ SearchResource,
545
+ ServerError,
546
+ TemporalResource,
547
+ ValidationError,
548
+ WorkingMemoryResource,
549
+ WorldModelResource
550
+ };
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "hebbrix",
3
+ "version": "2.0.0",
4
+ "description": "Advanced Memory API for AI Agents with Reinforcement Learning - TypeScript/JavaScript SDK",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsup src/index.ts --format cjs,esm --dts",
21
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
22
+ "test": "jest",
23
+ "lint": "eslint src --ext .ts",
24
+ "format": "prettier --write \"src/**/*.ts\"",
25
+ "prepublishOnly": "npm run build"
26
+ },
27
+ "keywords": [
28
+ "ai",
29
+ "memory",
30
+ "agents",
31
+ "llm",
32
+ "chatbot",
33
+ "rag",
34
+ "vector-search",
35
+ "knowledge-graph",
36
+ "embeddings",
37
+ "reasoning",
38
+ "reinforcement-learning",
39
+ "temporal",
40
+ "procedural-memory",
41
+ "working-memory",
42
+ "memory-api",
43
+ "typescript",
44
+ "javascript"
45
+ ],
46
+ "author": "Hebbrix Team <support@hebbrix.com>",
47
+ "license": "MIT",
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "https://github.com/hebbrix/hebbrix-typescript.git"
51
+ },
52
+ "bugs": {
53
+ "url": "https://github.com/hebbrix/hebbrix-typescript/issues"
54
+ },
55
+ "homepage": "https://hebbrix.com",
56
+ "devDependencies": {
57
+ "@types/node": "^20.10.0",
58
+ "@typescript-eslint/eslint-plugin": "^6.15.0",
59
+ "@typescript-eslint/parser": "^6.15.0",
60
+ "eslint": "^8.56.0",
61
+ "jest": "^29.7.0",
62
+ "prettier": "^3.1.1",
63
+ "tsup": "^8.0.1",
64
+ "typescript": "^5.3.3"
65
+ },
66
+ "engines": {
67
+ "node": ">=16.0.0"
68
+ }
69
+ }