@juspay/hippocampus 0.1.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/client.d.ts +69 -0
- package/dist/errors.d.ts +6 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +318 -0
- package/dist/logger.d.ts +12 -0
- package/dist/types.d.ts +161 -0
- package/package.json +65 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Engram, EngramCreateInput, EngramUpdateInput, SearchQuery, SearchResult, Chronicle, ChronicleCreateInput, ChronicleUpdateInput, ChronicleQuery, Nexus, NexusCreateInput, HealthResponse, StatusResponse, HippocampusOptions, Strand } from './types';
|
|
2
|
+
export declare class Hippocampus {
|
|
3
|
+
private baseUrl;
|
|
4
|
+
private headers;
|
|
5
|
+
private retries;
|
|
6
|
+
private retryDelay;
|
|
7
|
+
constructor(options?: HippocampusOptions);
|
|
8
|
+
addMemory(input: EngramCreateInput): Promise<{
|
|
9
|
+
engrams: Engram[];
|
|
10
|
+
}>;
|
|
11
|
+
listEngrams(ownerId: string, options?: {
|
|
12
|
+
limit?: number;
|
|
13
|
+
offset?: number;
|
|
14
|
+
strand?: Strand;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
engrams: Engram[];
|
|
17
|
+
total: number;
|
|
18
|
+
}>;
|
|
19
|
+
getEngram(id: string): Promise<{
|
|
20
|
+
engram: Engram;
|
|
21
|
+
}>;
|
|
22
|
+
updateEngram(id: string, input: EngramUpdateInput): Promise<{
|
|
23
|
+
engram: Engram;
|
|
24
|
+
}>;
|
|
25
|
+
deleteEngram(id: string): Promise<void>;
|
|
26
|
+
search(query: SearchQuery): Promise<SearchResult>;
|
|
27
|
+
reinforceEngram(id: string, boost?: number): Promise<{
|
|
28
|
+
engram: Engram;
|
|
29
|
+
}>;
|
|
30
|
+
recordChronicle(input: ChronicleCreateInput): Promise<{
|
|
31
|
+
chronicle: Chronicle;
|
|
32
|
+
}>;
|
|
33
|
+
queryChronicles(query: ChronicleQuery): Promise<{
|
|
34
|
+
chronicles: Chronicle[];
|
|
35
|
+
total: number;
|
|
36
|
+
}>;
|
|
37
|
+
getCurrentFact(ownerId: string, entity: string, attribute: string): Promise<{
|
|
38
|
+
chronicle: Chronicle;
|
|
39
|
+
}>;
|
|
40
|
+
getTimeline(ownerId: string, entity: string): Promise<{
|
|
41
|
+
chronicles: Chronicle[];
|
|
42
|
+
}>;
|
|
43
|
+
getChronicle(id: string): Promise<{
|
|
44
|
+
chronicle: Chronicle;
|
|
45
|
+
}>;
|
|
46
|
+
updateChronicle(id: string, input: ChronicleUpdateInput): Promise<{
|
|
47
|
+
chronicle: Chronicle;
|
|
48
|
+
}>;
|
|
49
|
+
expireChronicle(id: string): Promise<void>;
|
|
50
|
+
createNexus(input: NexusCreateInput): Promise<{
|
|
51
|
+
nexus: Nexus;
|
|
52
|
+
}>;
|
|
53
|
+
getRelatedChronicles(chronicleId: string): Promise<{
|
|
54
|
+
related: {
|
|
55
|
+
nexus: Nexus;
|
|
56
|
+
chronicle: Chronicle;
|
|
57
|
+
}[];
|
|
58
|
+
}>;
|
|
59
|
+
health(): Promise<HealthResponse>;
|
|
60
|
+
status(): Promise<StatusResponse>;
|
|
61
|
+
runDecay(ownerId: string): Promise<{
|
|
62
|
+
affected: number;
|
|
63
|
+
}>;
|
|
64
|
+
private request;
|
|
65
|
+
private get;
|
|
66
|
+
private post;
|
|
67
|
+
private patch;
|
|
68
|
+
private del;
|
|
69
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare class HippocampusError extends Error {
|
|
2
|
+
readonly statusCode: number;
|
|
3
|
+
readonly details?: unknown | undefined;
|
|
4
|
+
constructor(statusCode: number, message: string, details?: unknown | undefined);
|
|
5
|
+
static fromResponse(status: number, body: unknown): HippocampusError;
|
|
6
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Hippocampus } from './client';
|
|
2
|
+
export { HippocampusError } from './errors';
|
|
3
|
+
export { logger } from './logger';
|
|
4
|
+
export type { LogLevel } from './logger';
|
|
5
|
+
export type { Engram, EngramCreateInput, EngramUpdateInput, SearchQuery, SearchResult, SearchHit, RetrievalTrace, ChronicleHit, Chronicle, ChronicleCreateInput, ChronicleUpdateInput, ChronicleQuery, Nexus, NexusCreateInput, Strand, HealthResponse, StatusResponse, HippocampusOptions, } from './types';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
class HippocampusError extends Error {
|
|
2
|
+
statusCode;
|
|
3
|
+
details;
|
|
4
|
+
constructor(statusCode, message, details) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.statusCode = statusCode;
|
|
7
|
+
this.details = details;
|
|
8
|
+
this.name = 'HippocampusError';
|
|
9
|
+
}
|
|
10
|
+
static fromResponse(status, body) {
|
|
11
|
+
if (body && typeof body === 'object' && 'error' in body) {
|
|
12
|
+
const err = body.error;
|
|
13
|
+
return new HippocampusError(status, err.message || 'Unknown error', err.details);
|
|
14
|
+
}
|
|
15
|
+
return new HippocampusError(status, `HTTP ${status}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const ALL_LEVELS = ['debug', 'info', 'warn', 'error'];
|
|
20
|
+
function parseLogLevels(input) {
|
|
21
|
+
const trimmed = input.trim().toLowerCase();
|
|
22
|
+
if (trimmed === 'off' || trimmed === '') {
|
|
23
|
+
return new Set();
|
|
24
|
+
}
|
|
25
|
+
const levels = trimmed
|
|
26
|
+
.split(',')
|
|
27
|
+
.map((s) => s.trim())
|
|
28
|
+
.filter(Boolean);
|
|
29
|
+
return new Set(levels.filter((l) => ALL_LEVELS.includes(l)));
|
|
30
|
+
}
|
|
31
|
+
let enabledLevels = null;
|
|
32
|
+
function getEnabledLevels() {
|
|
33
|
+
if (enabledLevels === null) {
|
|
34
|
+
enabledLevels = parseLogLevels(process.env.HC_LOG_LEVEL || 'off');
|
|
35
|
+
}
|
|
36
|
+
return enabledLevels;
|
|
37
|
+
}
|
|
38
|
+
function shouldLog(level) {
|
|
39
|
+
return getEnabledLevels().has(level);
|
|
40
|
+
}
|
|
41
|
+
function formatMessage(level, message, context) {
|
|
42
|
+
const timestamp = new Date().toISOString();
|
|
43
|
+
const base = `[${timestamp}] [HIPPOCAMPUS@0.1.0] [${level.toUpperCase()}] ${message}`;
|
|
44
|
+
if (context && Object.keys(context).length > 0) {
|
|
45
|
+
return `${base} ${JSON.stringify(context)}`;
|
|
46
|
+
}
|
|
47
|
+
return base;
|
|
48
|
+
}
|
|
49
|
+
const logger = {
|
|
50
|
+
/**
|
|
51
|
+
* Programmatically override which log levels are active.
|
|
52
|
+
* Pass an array of levels or `'off'` to disable all logging.
|
|
53
|
+
*/
|
|
54
|
+
setLevels(levels) {
|
|
55
|
+
enabledLevels = levels === 'off' ? new Set() : new Set(levels);
|
|
56
|
+
},
|
|
57
|
+
debug(message, context) {
|
|
58
|
+
if (shouldLog('debug')) {
|
|
59
|
+
console.debug(formatMessage('debug', message, context));
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
info(message, context) {
|
|
63
|
+
if (shouldLog('info')) {
|
|
64
|
+
console.info(formatMessage('info', message, context));
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
warn(message, context) {
|
|
68
|
+
if (shouldLog('warn')) {
|
|
69
|
+
console.warn(formatMessage('warn', message, context));
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
error(message, context) {
|
|
73
|
+
if (shouldLog('error')) {
|
|
74
|
+
console.error(formatMessage('error', message, context));
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
class Hippocampus {
|
|
80
|
+
baseUrl;
|
|
81
|
+
headers;
|
|
82
|
+
retries;
|
|
83
|
+
retryDelay;
|
|
84
|
+
constructor(options = {}) {
|
|
85
|
+
const baseUrl = options.baseUrl || process.env.HC_BASE_URL || 'http://localhost:4477';
|
|
86
|
+
const apiKey = options.apiKey || process.env.HC_API_KEY;
|
|
87
|
+
this.baseUrl = baseUrl.replace(/\/$/, '');
|
|
88
|
+
this.headers = {
|
|
89
|
+
'Content-Type': 'application/json',
|
|
90
|
+
...(apiKey ? { 'X-API-Key': apiKey } : {}),
|
|
91
|
+
...options.headers,
|
|
92
|
+
};
|
|
93
|
+
this.retries = options.retries ?? 0;
|
|
94
|
+
this.retryDelay = options.retryDelay ?? 1000;
|
|
95
|
+
logger.debug('Hippocampus client initialized', {
|
|
96
|
+
baseUrl: this.baseUrl,
|
|
97
|
+
retries: this.retries,
|
|
98
|
+
retryDelay: this.retryDelay,
|
|
99
|
+
hasApiKey: !!apiKey,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
// --- Engrams ---
|
|
103
|
+
async addMemory(input) {
|
|
104
|
+
logger.info('Adding memory', { ownerId: input.ownerId, strand: input.strand });
|
|
105
|
+
const result = await this.post('/api/engrams', input);
|
|
106
|
+
logger.info('Memory added', { count: result.engrams.length });
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
async listEngrams(ownerId, options) {
|
|
110
|
+
logger.debug('Listing engrams', { ownerId, ...options });
|
|
111
|
+
const params = new URLSearchParams({ ownerId });
|
|
112
|
+
if (options?.limit) {
|
|
113
|
+
params.set('limit', String(options.limit));
|
|
114
|
+
}
|
|
115
|
+
if (options?.offset) {
|
|
116
|
+
params.set('offset', String(options.offset));
|
|
117
|
+
}
|
|
118
|
+
if (options?.strand) {
|
|
119
|
+
params.set('strand', options.strand);
|
|
120
|
+
}
|
|
121
|
+
const result = await this.get(`/api/engrams?${params}`);
|
|
122
|
+
logger.debug('Engrams listed', { total: result.total });
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
async getEngram(id) {
|
|
126
|
+
logger.debug('Getting engram', { id });
|
|
127
|
+
return this.get(`/api/engrams/${id}`);
|
|
128
|
+
}
|
|
129
|
+
async updateEngram(id, input) {
|
|
130
|
+
logger.info('Updating engram', { id });
|
|
131
|
+
const result = await this.patch(`/api/engrams/${id}`, input);
|
|
132
|
+
logger.info('Engram updated', { id });
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
async deleteEngram(id) {
|
|
136
|
+
logger.info('Deleting engram', { id });
|
|
137
|
+
await this.del(`/api/engrams/${id}`);
|
|
138
|
+
logger.info('Engram deleted', { id });
|
|
139
|
+
}
|
|
140
|
+
async search(query) {
|
|
141
|
+
logger.info('Searching engrams', { ownerId: query.ownerId, query: query.query, limit: query.limit });
|
|
142
|
+
const result = await this.post('/api/engrams/search', query);
|
|
143
|
+
logger.info('Search completed', { hits: result.hits.length, total: result.total, took: result.took });
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
async reinforceEngram(id, boost) {
|
|
147
|
+
logger.debug('Reinforcing engram', { id, boost });
|
|
148
|
+
const result = await this.post(`/api/engrams/${id}/reinforce`, { boost });
|
|
149
|
+
logger.debug('Engram reinforced', { id, signal: result.engram.signal });
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
// --- Chronicles ---
|
|
153
|
+
async recordChronicle(input) {
|
|
154
|
+
logger.info('Recording chronicle', { ownerId: input.ownerId, entity: input.entity, attribute: input.attribute });
|
|
155
|
+
const result = await this.post('/api/chronicles', input);
|
|
156
|
+
logger.info('Chronicle recorded', { id: result.chronicle.id });
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
async queryChronicles(query) {
|
|
160
|
+
logger.debug('Querying chronicles', { ownerId: query.ownerId, entity: query.entity, attribute: query.attribute });
|
|
161
|
+
const params = new URLSearchParams({ ownerId: query.ownerId });
|
|
162
|
+
if (query.entity) {
|
|
163
|
+
params.set('entity', query.entity);
|
|
164
|
+
}
|
|
165
|
+
if (query.attribute) {
|
|
166
|
+
params.set('attribute', query.attribute);
|
|
167
|
+
}
|
|
168
|
+
if (query.at) {
|
|
169
|
+
params.set('at', query.at);
|
|
170
|
+
}
|
|
171
|
+
if (query.from) {
|
|
172
|
+
params.set('from', query.from);
|
|
173
|
+
}
|
|
174
|
+
if (query.to) {
|
|
175
|
+
params.set('to', query.to);
|
|
176
|
+
}
|
|
177
|
+
if (query.limit) {
|
|
178
|
+
params.set('limit', String(query.limit));
|
|
179
|
+
}
|
|
180
|
+
if (query.offset) {
|
|
181
|
+
params.set('offset', String(query.offset));
|
|
182
|
+
}
|
|
183
|
+
const result = await this.get(`/api/chronicles?${params}`);
|
|
184
|
+
logger.debug('Chronicles queried', { total: result.total });
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
async getCurrentFact(ownerId, entity, attribute) {
|
|
188
|
+
logger.debug('Getting current fact', { ownerId, entity, attribute });
|
|
189
|
+
const params = new URLSearchParams({ ownerId, entity, attribute });
|
|
190
|
+
return this.get(`/api/chronicles/current?${params}`);
|
|
191
|
+
}
|
|
192
|
+
async getTimeline(ownerId, entity) {
|
|
193
|
+
logger.debug('Getting timeline', { ownerId, entity });
|
|
194
|
+
const params = new URLSearchParams({ ownerId, entity });
|
|
195
|
+
const result = await this.get(`/api/chronicles/timeline?${params}`);
|
|
196
|
+
logger.debug('Timeline retrieved', { count: result.chronicles.length });
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
async getChronicle(id) {
|
|
200
|
+
logger.debug('Getting chronicle', { id });
|
|
201
|
+
return this.get(`/api/chronicles/${id}`);
|
|
202
|
+
}
|
|
203
|
+
async updateChronicle(id, input) {
|
|
204
|
+
logger.info('Updating chronicle', { id });
|
|
205
|
+
const result = await this.patch(`/api/chronicles/${id}`, input);
|
|
206
|
+
logger.info('Chronicle updated', { id });
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
async expireChronicle(id) {
|
|
210
|
+
logger.info('Expiring chronicle', { id });
|
|
211
|
+
await this.del(`/api/chronicles/${id}`);
|
|
212
|
+
logger.info('Chronicle expired', { id });
|
|
213
|
+
}
|
|
214
|
+
// --- Nexuses ---
|
|
215
|
+
async createNexus(input) {
|
|
216
|
+
logger.info('Creating nexus', { originId: input.originId, linkedId: input.linkedId, bondType: input.bondType });
|
|
217
|
+
const result = await this.post('/api/nexuses', input);
|
|
218
|
+
logger.info('Nexus created', { id: result.nexus.id });
|
|
219
|
+
return result;
|
|
220
|
+
}
|
|
221
|
+
async getRelatedChronicles(chronicleId) {
|
|
222
|
+
logger.debug('Getting related chronicles', { chronicleId });
|
|
223
|
+
const result = await this.get(`/api/chronicles/${chronicleId}/related`);
|
|
224
|
+
logger.debug('Related chronicles retrieved', { count: result.related.length });
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
// --- System ---
|
|
228
|
+
async health() {
|
|
229
|
+
logger.debug('Health check');
|
|
230
|
+
return this.get('/api/health');
|
|
231
|
+
}
|
|
232
|
+
async status() {
|
|
233
|
+
logger.debug('Status check');
|
|
234
|
+
return this.get('/api/status');
|
|
235
|
+
}
|
|
236
|
+
async runDecay(ownerId) {
|
|
237
|
+
logger.info('Running decay', { ownerId });
|
|
238
|
+
const result = await this.post('/api/decay/run', { ownerId });
|
|
239
|
+
logger.info('Decay completed', { affected: result.affected });
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
242
|
+
// --- HTTP helpers ---
|
|
243
|
+
async request(method, path, body) {
|
|
244
|
+
const url = `${this.baseUrl}${path}`;
|
|
245
|
+
let lastError = null;
|
|
246
|
+
for (let attempt = 0; attempt <= this.retries; attempt++) {
|
|
247
|
+
try {
|
|
248
|
+
if (attempt > 0) {
|
|
249
|
+
logger.warn('Retrying request', { method, path, attempt, maxRetries: this.retries });
|
|
250
|
+
}
|
|
251
|
+
logger.debug('Sending request', { method, url });
|
|
252
|
+
const response = await fetch(url, {
|
|
253
|
+
method,
|
|
254
|
+
headers: this.headers,
|
|
255
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
256
|
+
});
|
|
257
|
+
if (response.status === 204) {
|
|
258
|
+
logger.debug('Request successful (204 No Content)', { method, path });
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
const json = await response.json();
|
|
262
|
+
if (!response.ok) {
|
|
263
|
+
const error = HippocampusError.fromResponse(response.status, json);
|
|
264
|
+
logger.error('Request failed with HTTP error', {
|
|
265
|
+
method,
|
|
266
|
+
path,
|
|
267
|
+
statusCode: response.status,
|
|
268
|
+
message: error.message,
|
|
269
|
+
});
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
logger.debug('Request successful', { method, path, status: response.status });
|
|
273
|
+
return json;
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
277
|
+
// Don't retry client errors (4xx)
|
|
278
|
+
if (error instanceof HippocampusError && error.statusCode >= 400 && error.statusCode < 500) {
|
|
279
|
+
throw error;
|
|
280
|
+
}
|
|
281
|
+
if (attempt < this.retries) {
|
|
282
|
+
const delay = this.retryDelay * Math.pow(2, attempt);
|
|
283
|
+
logger.warn('Request failed, will retry', {
|
|
284
|
+
method,
|
|
285
|
+
path,
|
|
286
|
+
attempt,
|
|
287
|
+
nextRetryIn: `${delay}ms`,
|
|
288
|
+
error: lastError.message,
|
|
289
|
+
});
|
|
290
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
logger.error('Request failed after all retries', {
|
|
294
|
+
method,
|
|
295
|
+
path,
|
|
296
|
+
attempts: attempt + 1,
|
|
297
|
+
error: lastError.message,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
throw lastError || new Error('Request failed');
|
|
303
|
+
}
|
|
304
|
+
get(path) {
|
|
305
|
+
return this.request('GET', path);
|
|
306
|
+
}
|
|
307
|
+
post(path, body) {
|
|
308
|
+
return this.request('POST', path, body);
|
|
309
|
+
}
|
|
310
|
+
patch(path, body) {
|
|
311
|
+
return this.request('PATCH', path, body);
|
|
312
|
+
}
|
|
313
|
+
del(path) {
|
|
314
|
+
return this.request('DELETE', path);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export { Hippocampus, HippocampusError, logger };
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
2
|
+
export declare const logger: {
|
|
3
|
+
/**
|
|
4
|
+
* Programmatically override which log levels are active.
|
|
5
|
+
* Pass an array of levels or `'off'` to disable all logging.
|
|
6
|
+
*/
|
|
7
|
+
setLevels(levels: LogLevel[] | "off"): void;
|
|
8
|
+
debug(message: string, context?: Record<string, unknown>): void;
|
|
9
|
+
info(message: string, context?: Record<string, unknown>): void;
|
|
10
|
+
warn(message: string, context?: Record<string, unknown>): void;
|
|
11
|
+
error(message: string, context?: Record<string, unknown>): void;
|
|
12
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
export type Strand = 'factual' | 'experiential' | 'procedural' | 'preferential' | 'relational' | 'general';
|
|
2
|
+
export interface Engram {
|
|
3
|
+
id: string;
|
|
4
|
+
ownerId: string;
|
|
5
|
+
content: string;
|
|
6
|
+
contentHash: string;
|
|
7
|
+
strand: Strand;
|
|
8
|
+
tags: string[];
|
|
9
|
+
metadata: Record<string, unknown>;
|
|
10
|
+
signal: number;
|
|
11
|
+
pulseRate: number;
|
|
12
|
+
accessCount: number;
|
|
13
|
+
version: number;
|
|
14
|
+
createdAt: string;
|
|
15
|
+
updatedAt: string;
|
|
16
|
+
lastAccessedAt: string;
|
|
17
|
+
}
|
|
18
|
+
export interface EngramCreateInput {
|
|
19
|
+
ownerId: string;
|
|
20
|
+
content: string;
|
|
21
|
+
strand?: Strand;
|
|
22
|
+
tags?: string[];
|
|
23
|
+
metadata?: Record<string, unknown>;
|
|
24
|
+
signal?: number;
|
|
25
|
+
pulseRate?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface EngramUpdateInput {
|
|
28
|
+
content?: string;
|
|
29
|
+
strand?: Strand;
|
|
30
|
+
tags?: string[];
|
|
31
|
+
metadata?: Record<string, unknown>;
|
|
32
|
+
signal?: number;
|
|
33
|
+
pulseRate?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface RetrievalTrace {
|
|
36
|
+
vectorScore: number;
|
|
37
|
+
keywordScore: number;
|
|
38
|
+
recencyBoost: number;
|
|
39
|
+
signalBoost: number;
|
|
40
|
+
synapseBoost: number;
|
|
41
|
+
finalScore: number;
|
|
42
|
+
}
|
|
43
|
+
export interface SearchHit {
|
|
44
|
+
engram: {
|
|
45
|
+
id: string;
|
|
46
|
+
ownerId: string;
|
|
47
|
+
content: string;
|
|
48
|
+
strand: Strand;
|
|
49
|
+
tags: string[];
|
|
50
|
+
metadata: Record<string, unknown>;
|
|
51
|
+
signal: number;
|
|
52
|
+
accessCount: number;
|
|
53
|
+
createdAt: string;
|
|
54
|
+
updatedAt: string;
|
|
55
|
+
lastAccessedAt: string;
|
|
56
|
+
};
|
|
57
|
+
trace: RetrievalTrace;
|
|
58
|
+
}
|
|
59
|
+
export interface ChronicleHit {
|
|
60
|
+
chronicle: Chronicle;
|
|
61
|
+
relevance: number;
|
|
62
|
+
}
|
|
63
|
+
export interface SearchResult {
|
|
64
|
+
hits: SearchHit[];
|
|
65
|
+
chronicles: ChronicleHit[];
|
|
66
|
+
total: number;
|
|
67
|
+
query: string;
|
|
68
|
+
took: number;
|
|
69
|
+
}
|
|
70
|
+
export interface SearchQuery {
|
|
71
|
+
ownerId: string;
|
|
72
|
+
query: string;
|
|
73
|
+
limit?: number;
|
|
74
|
+
offset?: number;
|
|
75
|
+
strand?: Strand;
|
|
76
|
+
tags?: string[];
|
|
77
|
+
minSignal?: number;
|
|
78
|
+
minScore?: number;
|
|
79
|
+
expandSynapses?: boolean;
|
|
80
|
+
}
|
|
81
|
+
export interface Chronicle {
|
|
82
|
+
id: string;
|
|
83
|
+
ownerId: string;
|
|
84
|
+
entity: string;
|
|
85
|
+
attribute: string;
|
|
86
|
+
value: string;
|
|
87
|
+
certainty: number;
|
|
88
|
+
effectiveFrom: string;
|
|
89
|
+
effectiveUntil: string | null;
|
|
90
|
+
recordedAt: string;
|
|
91
|
+
metadata: Record<string, unknown>;
|
|
92
|
+
}
|
|
93
|
+
export interface ChronicleCreateInput {
|
|
94
|
+
ownerId: string;
|
|
95
|
+
entity: string;
|
|
96
|
+
attribute: string;
|
|
97
|
+
value: string;
|
|
98
|
+
certainty?: number;
|
|
99
|
+
effectiveFrom?: string;
|
|
100
|
+
effectiveUntil?: string | null;
|
|
101
|
+
metadata?: Record<string, unknown>;
|
|
102
|
+
}
|
|
103
|
+
export interface ChronicleUpdateInput {
|
|
104
|
+
certainty?: number;
|
|
105
|
+
effectiveUntil?: string | null;
|
|
106
|
+
metadata?: Record<string, unknown>;
|
|
107
|
+
}
|
|
108
|
+
export interface ChronicleQuery {
|
|
109
|
+
ownerId: string;
|
|
110
|
+
entity?: string;
|
|
111
|
+
attribute?: string;
|
|
112
|
+
at?: string;
|
|
113
|
+
from?: string;
|
|
114
|
+
to?: string;
|
|
115
|
+
limit?: number;
|
|
116
|
+
offset?: number;
|
|
117
|
+
}
|
|
118
|
+
export interface Nexus {
|
|
119
|
+
id: string;
|
|
120
|
+
originId: string;
|
|
121
|
+
linkedId: string;
|
|
122
|
+
bondType: string;
|
|
123
|
+
strength: number;
|
|
124
|
+
effectiveFrom: string;
|
|
125
|
+
effectiveUntil: string | null;
|
|
126
|
+
metadata: Record<string, unknown>;
|
|
127
|
+
}
|
|
128
|
+
export interface NexusCreateInput {
|
|
129
|
+
originId: string;
|
|
130
|
+
linkedId: string;
|
|
131
|
+
bondType: string;
|
|
132
|
+
strength?: number;
|
|
133
|
+
effectiveFrom?: string;
|
|
134
|
+
effectiveUntil?: string | null;
|
|
135
|
+
metadata?: Record<string, unknown>;
|
|
136
|
+
}
|
|
137
|
+
export interface HealthResponse {
|
|
138
|
+
status: string;
|
|
139
|
+
database: string;
|
|
140
|
+
timestamp: string;
|
|
141
|
+
}
|
|
142
|
+
export interface StatusResponse {
|
|
143
|
+
database: string;
|
|
144
|
+
stats: {
|
|
145
|
+
engrams: number;
|
|
146
|
+
synapses: number;
|
|
147
|
+
chronicles: number;
|
|
148
|
+
nexuses: number;
|
|
149
|
+
};
|
|
150
|
+
uptime: number;
|
|
151
|
+
memory: Record<string, number>;
|
|
152
|
+
}
|
|
153
|
+
export interface HippocampusOptions {
|
|
154
|
+
/** Server URL. Falls back to HC_BASE_URL env var, then http://localhost:4477 */
|
|
155
|
+
baseUrl?: string;
|
|
156
|
+
/** API key. Falls back to HC_API_KEY env var */
|
|
157
|
+
apiKey?: string;
|
|
158
|
+
headers?: Record<string, string>;
|
|
159
|
+
retries?: number;
|
|
160
|
+
retryDelay?: number;
|
|
161
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@juspay/hippocampus",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript client SDK for Hippocampus memory server",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "rollup --config rollup.config.js",
|
|
16
|
+
"clean": "rm -rf dist",
|
|
17
|
+
"lint": "eslint src/",
|
|
18
|
+
"lint:fix": "eslint src/ --fix",
|
|
19
|
+
"format": "prettier --write 'src/**/*.ts' '*.json' '*.js'",
|
|
20
|
+
"format:check": "prettier --check 'src/**/*.ts' '*.json' '*.js'",
|
|
21
|
+
"prepublishOnly": "pnpm run clean && pnpm run build"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@eslint/js": "^9.39.2",
|
|
25
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
26
|
+
"@rollup/plugin-replace": "^6.0.3",
|
|
27
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
28
|
+
"@types/node": "^22.19.8",
|
|
29
|
+
"eslint": "^9.39.2",
|
|
30
|
+
"eslint-config-prettier": "^10.1.8",
|
|
31
|
+
"eslint-plugin-unused-imports": "^4.4.1",
|
|
32
|
+
"prettier": "^3.8.1",
|
|
33
|
+
"rollup": "^4.57.1",
|
|
34
|
+
"tslib": "^2.8.1",
|
|
35
|
+
"typescript": "^5.6.0",
|
|
36
|
+
"typescript-eslint": "^8.55.0"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist"
|
|
43
|
+
],
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/juspay/hippocampus.git",
|
|
48
|
+
"directory": "sdk"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/juspay/hippocampus#readme",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/juspay/hippocampus/issues"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"hippocampus",
|
|
56
|
+
"memory",
|
|
57
|
+
"ai",
|
|
58
|
+
"llm",
|
|
59
|
+
"semantic-search",
|
|
60
|
+
"vector-database",
|
|
61
|
+
"embeddings",
|
|
62
|
+
"ai-agents",
|
|
63
|
+
"memory-engine"
|
|
64
|
+
]
|
|
65
|
+
}
|