@senselab-ai/amfs 0.3.0 → 0.3.2

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.
@@ -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,16 +41,42 @@ export declare class HttpAdapter implements AmfsAdapter {
35
41
  query?: string;
36
42
  entityPath?: string;
37
43
  minConfidence?: number;
44
+ maxConfidence?: number;
45
+ agentId?: string;
46
+ since?: string;
47
+ patternRef?: string;
48
+ sortBy?: string;
38
49
  limit?: number;
50
+ depth?: number;
51
+ branch?: string;
39
52
  }): Promise<MemoryEntry[]>;
40
53
  watch(entityPath: string, callback: (entry: MemoryEntry) => void): WatchHandle;
41
54
  commitOutcome(record: OutcomeRecord): MemoryEntry[];
42
55
  commitOutcomeAsync(record: {
43
56
  outcomeRef: string;
44
57
  outcomeType: string;
58
+ entityPath?: string;
59
+ causalEntryKeys?: string[];
60
+ causalConfidence?: number;
61
+ agentId?: string;
45
62
  }): Promise<unknown>;
46
63
  statsAsync(): Promise<Record<string, unknown>>;
47
64
  healthAsync(): Promise<Record<string, unknown>>;
65
+ briefingAsync(options?: {
66
+ entityPath?: string;
67
+ limit?: number;
68
+ }): Promise<unknown>;
69
+ consolidationStatusAsync(): Promise<unknown>;
70
+ consolidationProposalsAsync(options?: {
71
+ status?: string;
72
+ limit?: number;
73
+ }): Promise<unknown>;
74
+ consolidationCandidatesAsync(options?: {
75
+ limit?: number;
76
+ }): Promise<unknown>;
77
+ consolidateAsync(options?: {
78
+ dryRun?: boolean;
79
+ }): Promise<unknown>;
48
80
  listTracesAsync(options?: {
49
81
  entityPath?: string;
50
82
  agentId?: string;
@@ -55,58 +87,58 @@ export declare class HttpAdapter implements AmfsAdapter {
55
87
  }
56
88
  export interface DecisionTraceSummary {
57
89
  id: string;
58
- agent_id: string;
59
- outcome_ref: string;
60
- outcome_type: string;
61
- decision_summary?: string;
62
- causal_entries: number;
63
- external_contexts: number;
64
- session_duration_ms?: number;
65
- created_at: string;
90
+ agentId: string;
91
+ outcomeRef: string;
92
+ outcomeType: string;
93
+ decisionSummary?: string;
94
+ causalEntries: number;
95
+ externalContexts: number;
96
+ sessionDurationMs?: number;
97
+ createdAt: string;
66
98
  }
67
99
  export interface DecisionTrace {
68
100
  id: string;
69
- agent_id: string;
70
- session_id: string;
71
- outcome_ref: string;
72
- outcome_type: string;
73
- decision_summary?: string;
74
- causal_entries: Array<{
75
- entity_path: string;
101
+ agentId: string;
102
+ sessionId: string;
103
+ outcomeRef: string;
104
+ outcomeType: string;
105
+ decisionSummary?: string;
106
+ causalEntries: Array<{
107
+ entityPath: string;
76
108
  key: string;
77
109
  version: number;
78
110
  confidence: number;
79
111
  value?: unknown;
80
- memory_type?: string;
81
- written_by?: string;
82
- read_at?: string;
112
+ memoryType?: string;
113
+ writtenBy?: string;
114
+ readAt?: string;
83
115
  }>;
84
- external_contexts: Array<{
116
+ externalContexts: Array<{
85
117
  label: string;
86
118
  summary: string;
87
119
  source?: string;
88
- recorded_at?: string;
120
+ recordedAt?: string;
89
121
  }>;
90
- query_events: Array<{
122
+ queryEvents: Array<{
91
123
  operation: string;
92
124
  parameters: Record<string, unknown>;
93
- result_count: number;
94
- duration_ms?: number;
95
- occurred_at?: string;
125
+ resultCount: number;
126
+ durationMs?: number;
127
+ occurredAt?: string;
96
128
  }>;
97
- error_events: Array<{
129
+ errorEvents: Array<{
98
130
  operation: string;
99
- error_type: string;
131
+ errorType: string;
100
132
  message: string;
101
- stack_trace?: string;
102
- occurred_at?: string;
133
+ stackTrace?: string;
134
+ occurredAt?: string;
103
135
  }>;
104
- state_diff?: {
105
- entries_created: number;
106
- entries_updated: number;
136
+ stateDiff?: {
137
+ entriesCreated: number;
138
+ entriesUpdated: number;
107
139
  };
108
- session_started_at?: string;
109
- session_ended_at?: string;
110
- session_duration_ms?: number;
111
- created_at: string;
140
+ sessionStartedAt?: string;
141
+ sessionEndedAt?: string;
142
+ sessionDurationMs?: number;
143
+ createdAt: string;
112
144
  }
@@ -2,11 +2,30 @@
2
2
  * HttpAdapter — connects the TS SDK to a remote AMFS HTTP API server.
3
3
  */
4
4
  import { createWatchHandle } from "../adapter.js";
5
+ function snakeToCamel(str) {
6
+ return str.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
7
+ }
8
+ function convertKeys(obj) {
9
+ if (obj === null || obj === undefined)
10
+ return obj;
11
+ if (Array.isArray(obj))
12
+ return obj.map(convertKeys);
13
+ if (typeof obj === "object") {
14
+ const result = {};
15
+ for (const [k, v] of Object.entries(obj)) {
16
+ result[snakeToCamel(k)] = convertKeys(v);
17
+ }
18
+ return result;
19
+ }
20
+ return obj;
21
+ }
5
22
  export class HttpAdapter {
6
23
  baseUrl;
7
24
  headers;
25
+ agentId;
8
26
  constructor(opts) {
9
27
  this.baseUrl = opts.url.replace(/\/+$/, "");
28
+ this.agentId = opts.agentId;
10
29
  this.headers = {
11
30
  "Content-Type": "application/json",
12
31
  ...opts.headers,
@@ -24,10 +43,10 @@ export class HttpAdapter {
24
43
  const body = await resp.text().catch(() => "");
25
44
  throw new Error(`AMFS API ${resp.status}: ${body}`);
26
45
  }
27
- return resp.json();
46
+ const raw = await resp.json();
47
+ return convertKeys(raw);
28
48
  }
29
49
  read(entityPath, key, options) {
30
- // Synchronous interface — return null and let callers use readAsync
31
50
  return null;
32
51
  }
33
52
  async readAsync(entityPath, key) {
@@ -39,10 +58,10 @@ export class HttpAdapter {
39
58
  }
40
59
  }
41
60
  write(entry) {
42
- // Synchronous interface — callers should use writeAsync for HTTP
43
61
  return entry;
44
62
  }
45
63
  async writeAsync(entry) {
64
+ const agentId = entry.agentId ?? this.agentId;
46
65
  return this.fetch("/api/v1/entries", {
47
66
  method: "POST",
48
67
  body: JSON.stringify({
@@ -51,11 +70,14 @@ export class HttpAdapter {
51
70
  value: entry.value,
52
71
  confidence: entry.confidence ?? 1.0,
53
72
  memory_type: entry.memoryType ?? "fact",
73
+ ...(agentId ? { agent_id: agentId } : {}),
74
+ ...(entry.shared != null ? { shared: entry.shared } : {}),
75
+ ...(entry.patternRefs?.length ? { pattern_refs: entry.patternRefs } : {}),
76
+ ...(entry.branch ? { branch: entry.branch } : {}),
54
77
  }),
55
78
  });
56
79
  }
57
80
  list(entityPath, options) {
58
- // Synchronous interface — return empty, callers should use listAsync
59
81
  return [];
60
82
  }
61
83
  async listAsync(entityPath, options) {
@@ -65,7 +87,10 @@ export class HttpAdapter {
65
87
  if (options?.includeSuperseded)
66
88
  params.set("include_superseded", "true");
67
89
  const qs = params.toString();
68
- return this.fetch(`/api/v1/entries${qs ? `?${qs}` : ""}`);
90
+ const data = await this.fetch(`/api/v1/entries${qs ? `?${qs}` : ""}`);
91
+ if (Array.isArray(data))
92
+ return data;
93
+ return data.entries ?? [];
69
94
  }
70
95
  async searchAsync(query) {
71
96
  return this.fetch("/api/v1/search", {
@@ -75,6 +100,13 @@ export class HttpAdapter {
75
100
  entity_path: query.entityPath,
76
101
  min_confidence: query.minConfidence ?? 0.0,
77
102
  limit: query.limit ?? 100,
103
+ ...(query.maxConfidence != null ? { max_confidence: query.maxConfidence } : {}),
104
+ ...(query.agentId ? { agent_id: query.agentId } : {}),
105
+ ...(query.since ? { since: query.since } : {}),
106
+ ...(query.patternRef ? { pattern_ref: query.patternRef } : {}),
107
+ ...(query.sortBy ? { sort_by: query.sortBy } : {}),
108
+ ...(query.depth != null ? { depth: query.depth } : {}),
109
+ ...(query.branch ? { branch: query.branch } : {}),
78
110
  }),
79
111
  });
80
112
  }
@@ -101,7 +133,7 @@ export class HttpAdapter {
101
133
  const raw = line.slice(5).trim();
102
134
  if (raw) {
103
135
  try {
104
- callback(JSON.parse(raw));
136
+ callback(convertKeys(JSON.parse(raw)));
105
137
  }
106
138
  catch { /* skip malformed */ }
107
139
  }
@@ -118,15 +150,19 @@ export class HttpAdapter {
118
150
  return createWatchHandle(() => controller.abort());
119
151
  }
120
152
  commitOutcome(record) {
121
- // Synchronous interface — return empty, callers should use commitOutcomeAsync
122
153
  return [];
123
154
  }
124
155
  async commitOutcomeAsync(record) {
156
+ const agentId = record.agentId ?? this.agentId;
125
157
  return this.fetch("/api/v1/outcomes", {
126
158
  method: "POST",
127
159
  body: JSON.stringify({
128
160
  outcome_ref: record.outcomeRef,
129
161
  outcome_type: record.outcomeType,
162
+ ...(record.entityPath ? { entity_path: record.entityPath } : {}),
163
+ ...(record.causalEntryKeys?.length ? { causal_entry_keys: record.causalEntryKeys } : {}),
164
+ ...(record.causalConfidence != null ? { causal_confidence: record.causalConfidence } : {}),
165
+ ...(agentId ? { agent_id: agentId } : {}),
130
166
  }),
131
167
  });
132
168
  }
@@ -136,6 +172,40 @@ export class HttpAdapter {
136
172
  async healthAsync() {
137
173
  return this.fetch("/api/v1/health");
138
174
  }
175
+ async briefingAsync(options) {
176
+ const params = new URLSearchParams();
177
+ if (options?.entityPath)
178
+ params.set("entity_path", options.entityPath);
179
+ if (options?.limit)
180
+ params.set("limit", String(options.limit));
181
+ const qs = params.toString();
182
+ return this.fetch(`/api/v1/briefing${qs ? `?${qs}` : ""}`);
183
+ }
184
+ async consolidationStatusAsync() {
185
+ return this.fetch("/api/v1/cortex/consolidation/status");
186
+ }
187
+ async consolidationProposalsAsync(options) {
188
+ const params = new URLSearchParams();
189
+ if (options?.status)
190
+ params.set("status", options.status);
191
+ if (options?.limit)
192
+ params.set("limit", String(options.limit));
193
+ const qs = params.toString();
194
+ return this.fetch(`/api/v1/cortex/consolidation/proposals${qs ? `?${qs}` : ""}`);
195
+ }
196
+ async consolidationCandidatesAsync(options) {
197
+ const params = new URLSearchParams();
198
+ if (options?.limit)
199
+ params.set("limit", String(options.limit));
200
+ const qs = params.toString();
201
+ return this.fetch(`/api/v1/cortex/consolidation/candidates${qs ? `?${qs}` : ""}`);
202
+ }
203
+ async consolidateAsync(options) {
204
+ return this.fetch("/api/v1/cortex/consolidate", {
205
+ method: "POST",
206
+ body: JSON.stringify({ dry_run: options?.dryRun ?? true }),
207
+ });
208
+ }
139
209
  async listTracesAsync(options) {
140
210
  const params = new URLSearchParams();
141
211
  if (options?.entityPath)
@@ -148,6 +218,8 @@ export class HttpAdapter {
148
218
  params.set("limit", String(options.limit));
149
219
  const qs = params.toString();
150
220
  const data = await this.fetch(`/api/v1/traces${qs ? `?${qs}` : ""}`);
221
+ if (Array.isArray(data))
222
+ return data;
151
223
  return data.traces ?? [];
152
224
  }
153
225
  async getTraceAsync(traceId) {
package/dist/memory.d.ts CHANGED
@@ -20,7 +20,7 @@ export interface SearchOptions {
20
20
  since?: string;
21
21
  patternRef?: string;
22
22
  limit?: number;
23
- sortBy?: "confidence" | "recency" | "version";
23
+ sortBy?: "confidence" | "recency" | "version" | "priority";
24
24
  recallConfig?: RecallConfig;
25
25
  }
26
26
  export interface MemoryStats {
package/dist/models.d.ts CHANGED
@@ -39,6 +39,11 @@ export interface MemoryEntry {
39
39
  contentHash: string | null;
40
40
  integrityChain: string | null;
41
41
  commitId: string | null;
42
+ memoryType?: string;
43
+ branch?: string;
44
+ recallCount?: number;
45
+ priorityScore?: number;
46
+ tier?: string;
42
47
  }
43
48
  export interface CommitEntry {
44
49
  entityPath: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@senselab-ai/amfs",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "AMFS TypeScript SDK — Agent Memory File System",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",