@senselab-ai/amfs 0.2.1 → 0.3.1
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/adapters/http.d.ts +10 -0
- package/dist/adapters/http.js +11 -0
- package/dist/memory.d.ts +34 -0
- package/dist/memory.js +91 -0
- package/package.json +1 -1
package/dist/adapters/http.d.ts
CHANGED
|
@@ -6,11 +6,13 @@ import type { AmfsAdapter, WatchHandle } from "../adapter.js";
|
|
|
6
6
|
export interface HttpAdapterOptions {
|
|
7
7
|
url: string;
|
|
8
8
|
apiKey?: string;
|
|
9
|
+
agentId?: string;
|
|
9
10
|
headers?: Record<string, string>;
|
|
10
11
|
}
|
|
11
12
|
export declare class HttpAdapter implements AmfsAdapter {
|
|
12
13
|
private readonly baseUrl;
|
|
13
14
|
private readonly headers;
|
|
15
|
+
private readonly agentId;
|
|
14
16
|
constructor(opts: HttpAdapterOptions);
|
|
15
17
|
private fetch;
|
|
16
18
|
read(entityPath: string, key: string, options?: {
|
|
@@ -24,6 +26,10 @@ export declare class HttpAdapter implements AmfsAdapter {
|
|
|
24
26
|
value: unknown;
|
|
25
27
|
confidence?: number;
|
|
26
28
|
memoryType?: string;
|
|
29
|
+
agentId?: string;
|
|
30
|
+
shared?: boolean;
|
|
31
|
+
patternRefs?: string[];
|
|
32
|
+
branch?: string;
|
|
27
33
|
}): Promise<MemoryEntry>;
|
|
28
34
|
list(entityPath?: string, options?: {
|
|
29
35
|
includeSuperseded?: boolean;
|
|
@@ -35,6 +41,8 @@ export declare class HttpAdapter implements AmfsAdapter {
|
|
|
35
41
|
query?: string;
|
|
36
42
|
entityPath?: string;
|
|
37
43
|
minConfidence?: number;
|
|
44
|
+
agentId?: string;
|
|
45
|
+
sortBy?: string;
|
|
38
46
|
limit?: number;
|
|
39
47
|
}): Promise<MemoryEntry[]>;
|
|
40
48
|
watch(entityPath: string, callback: (entry: MemoryEntry) => void): WatchHandle;
|
|
@@ -42,6 +50,8 @@ export declare class HttpAdapter implements AmfsAdapter {
|
|
|
42
50
|
commitOutcomeAsync(record: {
|
|
43
51
|
outcomeRef: string;
|
|
44
52
|
outcomeType: string;
|
|
53
|
+
entityPath?: string;
|
|
54
|
+
causalEntryKeys?: string[];
|
|
45
55
|
}): Promise<unknown>;
|
|
46
56
|
statsAsync(): Promise<Record<string, unknown>>;
|
|
47
57
|
healthAsync(): Promise<Record<string, unknown>>;
|
package/dist/adapters/http.js
CHANGED
|
@@ -5,8 +5,10 @@ import { createWatchHandle } from "../adapter.js";
|
|
|
5
5
|
export class HttpAdapter {
|
|
6
6
|
baseUrl;
|
|
7
7
|
headers;
|
|
8
|
+
agentId;
|
|
8
9
|
constructor(opts) {
|
|
9
10
|
this.baseUrl = opts.url.replace(/\/+$/, "");
|
|
11
|
+
this.agentId = opts.agentId;
|
|
10
12
|
this.headers = {
|
|
11
13
|
"Content-Type": "application/json",
|
|
12
14
|
...opts.headers,
|
|
@@ -43,6 +45,7 @@ export class HttpAdapter {
|
|
|
43
45
|
return entry;
|
|
44
46
|
}
|
|
45
47
|
async writeAsync(entry) {
|
|
48
|
+
const agentId = entry.agentId ?? this.agentId;
|
|
46
49
|
return this.fetch("/api/v1/entries", {
|
|
47
50
|
method: "POST",
|
|
48
51
|
body: JSON.stringify({
|
|
@@ -51,6 +54,10 @@ export class HttpAdapter {
|
|
|
51
54
|
value: entry.value,
|
|
52
55
|
confidence: entry.confidence ?? 1.0,
|
|
53
56
|
memory_type: entry.memoryType ?? "fact",
|
|
57
|
+
...(agentId ? { agent_id: agentId } : {}),
|
|
58
|
+
...(entry.shared != null ? { shared: entry.shared } : {}),
|
|
59
|
+
...(entry.patternRefs?.length ? { pattern_refs: entry.patternRefs } : {}),
|
|
60
|
+
...(entry.branch ? { branch: entry.branch } : {}),
|
|
54
61
|
}),
|
|
55
62
|
});
|
|
56
63
|
}
|
|
@@ -75,6 +82,8 @@ export class HttpAdapter {
|
|
|
75
82
|
entity_path: query.entityPath,
|
|
76
83
|
min_confidence: query.minConfidence ?? 0.0,
|
|
77
84
|
limit: query.limit ?? 100,
|
|
85
|
+
...(query.agentId ? { agent_id: query.agentId } : {}),
|
|
86
|
+
...(query.sortBy ? { sort_by: query.sortBy } : {}),
|
|
78
87
|
}),
|
|
79
88
|
});
|
|
80
89
|
}
|
|
@@ -127,6 +136,8 @@ export class HttpAdapter {
|
|
|
127
136
|
body: JSON.stringify({
|
|
128
137
|
outcome_ref: record.outcomeRef,
|
|
129
138
|
outcome_type: record.outcomeType,
|
|
139
|
+
...(record.entityPath ? { entity_path: record.entityPath } : {}),
|
|
140
|
+
...(record.causalEntryKeys?.length ? { causal_entry_keys: record.causalEntryKeys } : {}),
|
|
130
141
|
}),
|
|
131
142
|
});
|
|
132
143
|
}
|
package/dist/memory.d.ts
CHANGED
|
@@ -134,6 +134,40 @@ export declare class AgentMemory {
|
|
|
134
134
|
tree(maxDepth?: number): string;
|
|
135
135
|
/** Reset the session read log. */
|
|
136
136
|
clearReadLog(): void;
|
|
137
|
+
/** Join a room. The user owning this agent must have an accepted invite. */
|
|
138
|
+
roomJoin(roomId: string): Promise<Record<string, unknown>>;
|
|
139
|
+
/** Leave a room. Knowledge snapshots are preserved in private memory. */
|
|
140
|
+
roomLeave(roomId: string): Promise<Record<string, unknown>>;
|
|
141
|
+
/** List rooms this agent's user owns or is invited to. */
|
|
142
|
+
myRooms(): Promise<Record<string, unknown>[]>;
|
|
143
|
+
/** Get room details including members, settings, and discussion status. */
|
|
144
|
+
roomInfo(roomId: string): Promise<Record<string, unknown>>;
|
|
145
|
+
/** Get recent room activity (writes, joins, discussions, negotiations). */
|
|
146
|
+
roomUpdates(roomId: string, options?: {
|
|
147
|
+
since?: string;
|
|
148
|
+
}): Promise<Record<string, unknown>>;
|
|
149
|
+
roomDiscuss(roomId: string, content: string, options?: {
|
|
150
|
+
messageType?: string;
|
|
151
|
+
addressedTo?: string;
|
|
152
|
+
}): Promise<Record<string, unknown>>;
|
|
153
|
+
roomDiscussions(roomId: string, options?: {
|
|
154
|
+
limit?: number;
|
|
155
|
+
since?: string;
|
|
156
|
+
}): Promise<Record<string, unknown>>;
|
|
157
|
+
negotiateCreate(roomId: string, title: string, options?: {
|
|
158
|
+
description?: string;
|
|
159
|
+
maxRounds?: number;
|
|
160
|
+
}): Promise<Record<string, unknown>>;
|
|
161
|
+
negotiatePropose(roomId: string, sessionId: string, options?: {
|
|
162
|
+
action?: string;
|
|
163
|
+
proposal?: Record<string, unknown>;
|
|
164
|
+
rationale?: string;
|
|
165
|
+
}): Promise<Record<string, unknown>>;
|
|
166
|
+
negotiateRespond(roomId: string, sessionId: string, action: string, options?: {
|
|
167
|
+
rationale?: string;
|
|
168
|
+
}): Promise<Record<string, unknown>>;
|
|
169
|
+
negotiateStatus(roomId: string, sessionId: string): Promise<Record<string, unknown>>;
|
|
170
|
+
private _roomRequest;
|
|
137
171
|
}
|
|
138
172
|
/**
|
|
139
173
|
* A scoped view of AgentMemory bound to a fixed entity path.
|
package/dist/memory.js
CHANGED
|
@@ -379,6 +379,97 @@ export class AgentMemory {
|
|
|
379
379
|
clearReadLog() {
|
|
380
380
|
this.readTracker.clear();
|
|
381
381
|
}
|
|
382
|
+
// ── Room operations (Pro — requires HTTP adapter with rooms backend) ──
|
|
383
|
+
/** Join a room. The user owning this agent must have an accepted invite. */
|
|
384
|
+
async roomJoin(roomId) {
|
|
385
|
+
return this._roomRequest("POST", `/api/v1/rooms/${roomId}/agents`, {
|
|
386
|
+
agent_id: this.agentId,
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
/** Leave a room. Knowledge snapshots are preserved in private memory. */
|
|
390
|
+
async roomLeave(roomId) {
|
|
391
|
+
return this._roomRequest("DELETE", `/api/v1/rooms/${roomId}/agents/${this.agentId}`);
|
|
392
|
+
}
|
|
393
|
+
/** List rooms this agent's user owns or is invited to. */
|
|
394
|
+
async myRooms() {
|
|
395
|
+
const result = await this._roomRequest("GET", "/api/v1/rooms");
|
|
396
|
+
return Array.isArray(result) ? result : result.rooms ?? [];
|
|
397
|
+
}
|
|
398
|
+
/** Get room details including members, settings, and discussion status. */
|
|
399
|
+
async roomInfo(roomId) {
|
|
400
|
+
return this._roomRequest("GET", `/api/v1/rooms/${roomId}`);
|
|
401
|
+
}
|
|
402
|
+
/** Get recent room activity (writes, joins, discussions, negotiations). */
|
|
403
|
+
async roomUpdates(roomId, options) {
|
|
404
|
+
const params = options?.since ? `?since=${options.since}` : "";
|
|
405
|
+
return this._roomRequest("GET", `/api/v1/rooms/${roomId}/activity${params}`);
|
|
406
|
+
}
|
|
407
|
+
// -- Discussions --
|
|
408
|
+
async roomDiscuss(roomId, content, options) {
|
|
409
|
+
return this._roomRequest("POST", `/api/v1/rooms/${roomId}/discussions`, {
|
|
410
|
+
agent_id: this.agentId,
|
|
411
|
+
content,
|
|
412
|
+
message_type: options?.messageType ?? "message",
|
|
413
|
+
addressed_to: options?.addressedTo ?? null,
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
async roomDiscussions(roomId, options) {
|
|
417
|
+
const params = new URLSearchParams();
|
|
418
|
+
if (options?.limit)
|
|
419
|
+
params.set("limit", String(options.limit));
|
|
420
|
+
if (options?.since)
|
|
421
|
+
params.set("since", options.since);
|
|
422
|
+
const qs = params.toString();
|
|
423
|
+
return this._roomRequest("GET", `/api/v1/rooms/${roomId}/discussions${qs ? `?${qs}` : ""}`);
|
|
424
|
+
}
|
|
425
|
+
// -- Negotiations --
|
|
426
|
+
async negotiateCreate(roomId, title, options) {
|
|
427
|
+
return this._roomRequest("POST", `/api/v1/rooms/${roomId}/negotiations`, {
|
|
428
|
+
title,
|
|
429
|
+
description: options?.description ?? null,
|
|
430
|
+
agent_id: this.agentId,
|
|
431
|
+
max_rounds: options?.maxRounds ?? 10,
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
async negotiatePropose(roomId, sessionId, options) {
|
|
435
|
+
return this._roomRequest("POST", `/api/v1/rooms/${roomId}/negotiations/${sessionId}/propose`, {
|
|
436
|
+
agent_id: this.agentId,
|
|
437
|
+
action: options?.action ?? "propose",
|
|
438
|
+
proposal: options?.proposal ?? {},
|
|
439
|
+
rationale: options?.rationale ?? null,
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
async negotiateRespond(roomId, sessionId, action, options) {
|
|
443
|
+
return this.negotiatePropose(roomId, sessionId, {
|
|
444
|
+
action,
|
|
445
|
+
rationale: options?.rationale,
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
async negotiateStatus(roomId, sessionId) {
|
|
449
|
+
return this._roomRequest("GET", `/api/v1/rooms/${roomId}/negotiations/${sessionId}`);
|
|
450
|
+
}
|
|
451
|
+
async _roomRequest(method, path, body) {
|
|
452
|
+
const adapter = this.adapter;
|
|
453
|
+
const baseUrl = adapter._baseUrl ?? adapter.baseUrl;
|
|
454
|
+
if (typeof baseUrl !== "string") {
|
|
455
|
+
throw new Error("Room operations require the HTTP adapter (set AMFS_HTTP_URL)");
|
|
456
|
+
}
|
|
457
|
+
const url = `${baseUrl.replace(/\/$/, "")}${path}`;
|
|
458
|
+
const headers = { "Content-Type": "application/json" };
|
|
459
|
+
const apiKey = adapter._apiKey ?? adapter.apiKey;
|
|
460
|
+
if (typeof apiKey === "string") {
|
|
461
|
+
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
462
|
+
}
|
|
463
|
+
const resp = await fetch(url, {
|
|
464
|
+
method,
|
|
465
|
+
headers,
|
|
466
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
467
|
+
});
|
|
468
|
+
if (!resp.ok) {
|
|
469
|
+
throw new Error(`Room API error: ${resp.status} ${resp.statusText}`);
|
|
470
|
+
}
|
|
471
|
+
return resp.json();
|
|
472
|
+
}
|
|
382
473
|
}
|
|
383
474
|
/**
|
|
384
475
|
* A scoped view of AgentMemory bound to a fixed entity path.
|