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