@sapiom/tools 0.12.0 → 0.14.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/CHANGELOG.md +12 -0
- package/README.md +5 -3
- package/dist/cjs/client.d.ts +47 -0
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +24 -0
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/domains/errors.d.ts +16 -0
- package/dist/cjs/domains/errors.d.ts.map +1 -0
- package/dist/cjs/domains/errors.js +36 -0
- package/dist/cjs/domains/errors.js.map +1 -0
- package/dist/cjs/domains/index.d.ts +297 -0
- package/dist/cjs/domains/index.d.ts.map +1 -0
- package/dist/cjs/domains/index.js +348 -0
- package/dist/cjs/domains/index.js.map +1 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +7 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/memory/errors.d.ts +20 -0
- package/dist/cjs/memory/errors.d.ts.map +1 -0
- package/dist/cjs/memory/errors.js +40 -0
- package/dist/cjs/memory/errors.js.map +1 -0
- package/dist/cjs/memory/index.d.ts +318 -0
- package/dist/cjs/memory/index.d.ts.map +1 -0
- package/dist/cjs/memory/index.js +181 -0
- package/dist/cjs/memory/index.js.map +1 -0
- package/dist/cjs/stub/index.d.ts.map +1 -1
- package/dist/cjs/stub/index.js +102 -0
- package/dist/cjs/stub/index.js.map +1 -1
- package/dist/esm/client.d.ts +47 -0
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +24 -0
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/domains/errors.d.ts +16 -0
- package/dist/esm/domains/errors.d.ts.map +1 -0
- package/dist/esm/domains/errors.js +31 -0
- package/dist/esm/domains/errors.js.map +1 -0
- package/dist/esm/domains/index.d.ts +297 -0
- package/dist/esm/domains/index.d.ts.map +1 -0
- package/dist/esm/domains/index.js +335 -0
- package/dist/esm/domains/index.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/memory/errors.d.ts +20 -0
- package/dist/esm/memory/errors.d.ts.map +1 -0
- package/dist/esm/memory/errors.js +35 -0
- package/dist/esm/memory/errors.js.map +1 -0
- package/dist/esm/memory/index.d.ts +318 -0
- package/dist/esm/memory/index.d.ts.map +1 -0
- package/dist/esm/memory/index.js +173 -0
- package/dist/esm/memory/index.js.map +1 -0
- package/dist/esm/stub/index.d.ts.map +1 -1
- package/dist/esm/stub/index.js +102 -0
- package/dist/esm/stub/index.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +11 -1
- package/src/domains/README.md +76 -0
- package/src/memory/README.md +70 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tenant-scoped long-term memory on the Sapiom memory gateway.
|
|
3
|
+
*
|
|
4
|
+
* import { memory } from "@sapiom/tools"; // ambient auth
|
|
5
|
+
* const { id } = await memory.append({ content: "User prefers dark mode.", scope: "user" });
|
|
6
|
+
* const { results } = await memory.recall({ query: "ui preferences", topK: 5 });
|
|
7
|
+
* const record = await memory.get(id);
|
|
8
|
+
* await memory.forget(id);
|
|
9
|
+
*
|
|
10
|
+
* Or via an explicit client: `createClient({ apiKey }).memory.append(...)`.
|
|
11
|
+
*
|
|
12
|
+
* The gateway speaks camelCase JSON, so this client keeps request and response
|
|
13
|
+
* objects 1:1 with the wire contract.
|
|
14
|
+
*/
|
|
15
|
+
import { Transport } from "../_client/index.js";
|
|
16
|
+
import { MemoryHttpError } from "./errors.js";
|
|
17
|
+
export { MemoryHttpError };
|
|
18
|
+
/** Storage backend selector. Omit for the v0 default `"neon-pgvector"`. */
|
|
19
|
+
export declare const MEMORY_BACKENDS: readonly ["neon-pgvector", "upstash-vector"];
|
|
20
|
+
export type MemoryBackend = (typeof MEMORY_BACKENDS)[number];
|
|
21
|
+
/** Embedding model selector. Omit for the default OpenRouter text-embedding-3-small embedder. */
|
|
22
|
+
export interface MemoryEmbedder {
|
|
23
|
+
/**
|
|
24
|
+
* Embedding provider. The gateway is authoritative for provider support and
|
|
25
|
+
* returns 400 for unknown providers; v0 currently supports `"openrouter"`.
|
|
26
|
+
*/
|
|
27
|
+
provider: string;
|
|
28
|
+
/**
|
|
29
|
+
* Embedding model. A model is part of the store identity, so a write and all
|
|
30
|
+
* later reads must use the same model. The gateway is authoritative for model
|
|
31
|
+
* support and returns 400 for unknown models.
|
|
32
|
+
*/
|
|
33
|
+
model: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Optional store selector. Omit for the default Neon store.
|
|
37
|
+
*
|
|
38
|
+
* A memory is only visible from the store it was written to. If you set any of
|
|
39
|
+
* these fields on append, pass the same `store` to recall/get/forget/sweep.
|
|
40
|
+
*/
|
|
41
|
+
export interface MemoryStore {
|
|
42
|
+
/**
|
|
43
|
+
* Storage backend. Default: `"neon-pgvector"`. `"upstash-vector"` is experimental
|
|
44
|
+
* and does not support keyword recall or sweep.
|
|
45
|
+
*/
|
|
46
|
+
backend?: MemoryBackend;
|
|
47
|
+
/**
|
|
48
|
+
* Embedding model. Default: OpenRouter `"openai/text-embedding-3-small"`.
|
|
49
|
+
*/
|
|
50
|
+
embedder?: MemoryEmbedder;
|
|
51
|
+
/**
|
|
52
|
+
* Physical isolation namespace. Use to separate projects/tenants under one
|
|
53
|
+
* owner. 1-100 chars, `[a-zA-Z0-9_-]`.
|
|
54
|
+
*/
|
|
55
|
+
namespace?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface AppendInput {
|
|
58
|
+
/**
|
|
59
|
+
* Text to store as a memory (1–32,000 chars). Must not contain secrets — the
|
|
60
|
+
* gateway runs an admission gate and rejects API keys / tokens / passwords with
|
|
61
|
+
* a 400 (`error: "SecretDetected"`, `decision: "REJECTED"`) before anything is
|
|
62
|
+
* embedded or stored.
|
|
63
|
+
*/
|
|
64
|
+
content: string;
|
|
65
|
+
/**
|
|
66
|
+
* Scope label grouping related memories (e.g. "session", "user", "project").
|
|
67
|
+
* Alphanumeric plus hyphens/underscores, 1–100 chars. Defaults to "default".
|
|
68
|
+
*/
|
|
69
|
+
scope?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Arbitrary JSON stored alongside the memory and returned on read. Opaque to
|
|
72
|
+
* ranking (not embedded), but usable as a hard `filter` on recall. Max 10 KB when
|
|
73
|
+
* JSON-serialized.
|
|
74
|
+
*/
|
|
75
|
+
metadata?: Record<string, unknown>;
|
|
76
|
+
/**
|
|
77
|
+
* Event-time this memory is *about* (ISO-8601), distinct from `createdAt` (the
|
|
78
|
+
* server ingestion time). Drives temporal recall weighting. When omitted, the
|
|
79
|
+
* gateway stores `null` and temporal recall falls back to `createdAt`.
|
|
80
|
+
*/
|
|
81
|
+
occurredAt?: string;
|
|
82
|
+
/** Optional store selector. Omit for the default store. See {@link MemoryStore}. */
|
|
83
|
+
store?: MemoryStore;
|
|
84
|
+
}
|
|
85
|
+
export interface AppendResult {
|
|
86
|
+
/**
|
|
87
|
+
* UUID of the memory. For `decision: "ADDED"` this is the newly created record;
|
|
88
|
+
* for `decision: "NOOP"` it is the existing memory that was echoed (nothing was
|
|
89
|
+
* written).
|
|
90
|
+
*/
|
|
91
|
+
id: string;
|
|
92
|
+
/** The stored content, echoed back. */
|
|
93
|
+
content: string;
|
|
94
|
+
/** The resolved scope label ("default" when you omitted it). */
|
|
95
|
+
scope: string;
|
|
96
|
+
/**
|
|
97
|
+
* What the gateway did, made legible (never a silent write):
|
|
98
|
+
* - `"ADDED"` — a new memory was written to the append-log.
|
|
99
|
+
* - `"NOOP"` — byte-identical content or a near-exact semantic duplicate in the
|
|
100
|
+
* same owner + scope; the existing memory is echoed and nothing is written.
|
|
101
|
+
*
|
|
102
|
+
* A secret caught by the admission gate is *not* a decision here — it surfaces as
|
|
103
|
+
* a 400 {@link MemoryHttpError} whose body carries `decision: "REJECTED"`.
|
|
104
|
+
*/
|
|
105
|
+
decision: "ADDED" | "NOOP";
|
|
106
|
+
/** ISO-8601 timestamp when the memory was created (server ingestion time). */
|
|
107
|
+
createdAt: string;
|
|
108
|
+
/**
|
|
109
|
+
* ISO-8601 event-time this memory is *about*, or `null` when none was supplied on
|
|
110
|
+
* append (the gateway does not backfill it with `createdAt`).
|
|
111
|
+
*/
|
|
112
|
+
occurredAt: string | null;
|
|
113
|
+
/** The stored metadata (`{}` when none was provided). */
|
|
114
|
+
metadata: Record<string, unknown>;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Retrieval strategy for {@link recall}:
|
|
118
|
+
* - `"cosine"` — dense vector similarity (default; supported on every backend).
|
|
119
|
+
* - `"keyword"` — full-text / BM25 ranking. Neon-only; requesting it on a backend
|
|
120
|
+
* that doesn't support it is a 400 {@link MemoryHttpError} (never degraded).
|
|
121
|
+
*/
|
|
122
|
+
export type RetrievalStrategy = "cosine" | "keyword";
|
|
123
|
+
/** Time-decay weighting for {@link RecallInput.weight}. Optional; omit for pure relevance. */
|
|
124
|
+
export interface TemporalWeight {
|
|
125
|
+
/**
|
|
126
|
+
* ISO-8601 anchor the decay is measured from. Defaults to "now" at recall time.
|
|
127
|
+
* (A Unix-epoch integer is not accepted — pass an ISO-8601 string.)
|
|
128
|
+
*/
|
|
129
|
+
center?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Half-life in days (1–365, default 30): a memory whose `occurredAt` is this far
|
|
132
|
+
* from `center` keeps half its relevance. Smaller = sharper recency preference.
|
|
133
|
+
*/
|
|
134
|
+
halfLifeDays?: number;
|
|
135
|
+
}
|
|
136
|
+
/** Optional scoring weights for {@link recall}. Extensible; only `temporal` is supported today. */
|
|
137
|
+
export interface RecallWeight {
|
|
138
|
+
/** Multiplicative time-decay applied to each match's base similarity. */
|
|
139
|
+
temporal?: TemporalWeight;
|
|
140
|
+
}
|
|
141
|
+
export interface RecallInput {
|
|
142
|
+
/** Natural-language search text (1–4,096 chars). Embedded and compared against stored memories. */
|
|
143
|
+
query: string;
|
|
144
|
+
/** Restrict the search to this scope label. Omit to search every scope for your owner. */
|
|
145
|
+
scope?: string;
|
|
146
|
+
/** Maximum number of results to return (1–50). Defaults to 5. */
|
|
147
|
+
topK?: number;
|
|
148
|
+
/** Minimum score [0–1]; matches below it are dropped. Defaults to 0. */
|
|
149
|
+
minSimilarity?: number;
|
|
150
|
+
/**
|
|
151
|
+
* Retrieval strategy — `"cosine"` (default) or `"keyword"` (Neon-only). See
|
|
152
|
+
* {@link RetrievalStrategy}.
|
|
153
|
+
*/
|
|
154
|
+
strategy?: RetrievalStrategy;
|
|
155
|
+
/**
|
|
156
|
+
* Optional scoring weights. Today only `weight.temporal` is honored — it applies
|
|
157
|
+
* a time-decay against each memory's `occurredAt`. Omit for pure relevance.
|
|
158
|
+
*/
|
|
159
|
+
weight?: RecallWeight;
|
|
160
|
+
/**
|
|
161
|
+
* Hard metadata filter. Neon uses JSONB containment; Upstash supports scalar
|
|
162
|
+
* equality filters. Applied before ranking; max 4 KB serialized.
|
|
163
|
+
*/
|
|
164
|
+
filter?: Record<string, unknown>;
|
|
165
|
+
/** Optional store selector. Pass the same store used at write time. See {@link MemoryStore}. */
|
|
166
|
+
store?: MemoryStore;
|
|
167
|
+
}
|
|
168
|
+
export interface RecallMatch {
|
|
169
|
+
/** UUID of the memory. */
|
|
170
|
+
id: string;
|
|
171
|
+
/** The stored content. */
|
|
172
|
+
content: string;
|
|
173
|
+
/** The scope label. */
|
|
174
|
+
scope: string;
|
|
175
|
+
/**
|
|
176
|
+
* Canonical [0–1] relevance the matches are ranked and thresholded on (highest
|
|
177
|
+
* first). Provider-neutral: an opaque backend reports only this single score.
|
|
178
|
+
*/
|
|
179
|
+
score: number;
|
|
180
|
+
/**
|
|
181
|
+
* Optional backend-specific score legs. A backend may fill this with its own
|
|
182
|
+
* components; most dense-only paths omit it entirely. This is an open map —
|
|
183
|
+
* don't assume a fixed set of keys.
|
|
184
|
+
*/
|
|
185
|
+
scoreBreakdown?: Record<string, number>;
|
|
186
|
+
/** ISO-8601 timestamp when the memory was created. */
|
|
187
|
+
createdAt: string;
|
|
188
|
+
/** ISO-8601 event-time this memory is *about*, or `null` when none was supplied. */
|
|
189
|
+
occurredAt: string | null;
|
|
190
|
+
/** ISO-8601 timestamp this memory was last read, or `null` if never recalled since creation. */
|
|
191
|
+
lastAccessedAt: string | null;
|
|
192
|
+
/** The stored metadata. */
|
|
193
|
+
metadata: Record<string, unknown>;
|
|
194
|
+
}
|
|
195
|
+
export interface RecallResponse {
|
|
196
|
+
/** Matches ranked by `score` (highest first). Empty when nothing matched or no store exists yet. */
|
|
197
|
+
results: RecallMatch[];
|
|
198
|
+
/** The query, echoed back. */
|
|
199
|
+
query: string;
|
|
200
|
+
/** The effective top-K used by the gateway. */
|
|
201
|
+
topK: number;
|
|
202
|
+
/** Number of results returned (≤ `topK`). */
|
|
203
|
+
count: number;
|
|
204
|
+
}
|
|
205
|
+
export interface Memory {
|
|
206
|
+
/** UUID of the memory. */
|
|
207
|
+
id: string;
|
|
208
|
+
/** The stored content. */
|
|
209
|
+
content: string;
|
|
210
|
+
/** The scope label. */
|
|
211
|
+
scope: string;
|
|
212
|
+
/** ISO-8601 timestamp when the memory was created (server ingestion time). */
|
|
213
|
+
createdAt: string;
|
|
214
|
+
/** ISO-8601 event-time this memory is *about*, or `null` when none was supplied. */
|
|
215
|
+
occurredAt: string | null;
|
|
216
|
+
/** ISO-8601 timestamp this memory was last read, or `null` if never recalled since creation. */
|
|
217
|
+
lastAccessedAt: string | null;
|
|
218
|
+
/** The stored metadata. */
|
|
219
|
+
metadata: Record<string, unknown>;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Eviction order for {@link sweep}:
|
|
223
|
+
* - `"lru"` — least-recently-accessed first (`lastAccessedAt` ascending). Default.
|
|
224
|
+
* - `"oldest"` — oldest-inserted first (`createdAt` ascending).
|
|
225
|
+
*/
|
|
226
|
+
export type SweepStrategy = "lru" | "oldest";
|
|
227
|
+
export interface SweepInput {
|
|
228
|
+
/**
|
|
229
|
+
* Maximum number of memories to preview/delete (1–10,000). Omit to use the
|
|
230
|
+
* gateway's default sweep batch (100 rows).
|
|
231
|
+
*/
|
|
232
|
+
count?: number;
|
|
233
|
+
/** Eviction order — `"lru"` (default) or `"oldest"`. See {@link SweepStrategy}. */
|
|
234
|
+
strategy?: SweepStrategy;
|
|
235
|
+
/**
|
|
236
|
+
* Preview vs delete. **Defaults to `true`** (a safe preview): the gateway returns
|
|
237
|
+
* the `candidates` it would evict without deleting anything (`evicted: 0`). Pass
|
|
238
|
+
* `false` to actually evict.
|
|
239
|
+
*/
|
|
240
|
+
dryRun?: boolean;
|
|
241
|
+
/** Optional store selector. Sweep is Neon-only. See {@link MemoryStore}. */
|
|
242
|
+
store?: MemoryStore;
|
|
243
|
+
}
|
|
244
|
+
/** A memory that a `sweep` would evict. */
|
|
245
|
+
export interface MemorySweepCandidate {
|
|
246
|
+
/** UUID of the memory. */
|
|
247
|
+
id: string;
|
|
248
|
+
/** The stored content. */
|
|
249
|
+
content: string;
|
|
250
|
+
/** The scope label. */
|
|
251
|
+
scope: string;
|
|
252
|
+
/** ISO-8601 timestamp when the memory was created. */
|
|
253
|
+
createdAt: string;
|
|
254
|
+
/** ISO-8601 timestamp this memory was last read, or `null` if never recalled since creation. */
|
|
255
|
+
lastAccessedAt: string | null;
|
|
256
|
+
}
|
|
257
|
+
export interface MemorySweepResponse {
|
|
258
|
+
/** Number of memories evicted (`0` on a `dryRun`). */
|
|
259
|
+
evicted: number;
|
|
260
|
+
/**
|
|
261
|
+
* The memories that *would* be evicted — present on a `dryRun` (the default).
|
|
262
|
+
* Review them, then {@link forget} specific ids or re-run `sweep` with
|
|
263
|
+
* `dryRun: false`.
|
|
264
|
+
*/
|
|
265
|
+
candidates?: MemorySweepCandidate[];
|
|
266
|
+
}
|
|
267
|
+
/** Per-call options for {@link get} and {@link forget}. */
|
|
268
|
+
export interface MemoryCallOptions {
|
|
269
|
+
/** Optional store selector. Pass the same store used at write time. See {@link MemoryStore}. */
|
|
270
|
+
store?: MemoryStore;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Append a memory to the store (an append-log — no prior memory is mutated). The
|
|
274
|
+
* gateway runs a secret-detection gate first (a detected secret is rejected with a
|
|
275
|
+
* 400 {@link MemoryHttpError}, body `decision: "REJECTED"`), then embeds the
|
|
276
|
+
* content and writes it, returning `decision: "ADDED"`.
|
|
277
|
+
*
|
|
278
|
+
* Byte-identical content, or a near-exact semantic duplicate, in the same owner +
|
|
279
|
+
* scope is a no-op that echoes the existing memory unchanged (`decision: "NOOP"`);
|
|
280
|
+
* nothing new is written.
|
|
281
|
+
*
|
|
282
|
+
* On a full Neon store the gateway returns `507` ({@link MemoryHttpError}); call
|
|
283
|
+
* {@link sweep} (or {@link forget}) to free space, then retry. On Upstash, first
|
|
284
|
+
* provisioning can return `422` when the account/index limit is reached.
|
|
285
|
+
*/
|
|
286
|
+
export declare function append(input: AppendInput, transport?: Transport, baseUrl?: string): Promise<AppendResult>;
|
|
287
|
+
/**
|
|
288
|
+
* Recall memories by natural-language query. Returns the top-K matches ranked by
|
|
289
|
+
* score; an empty list when nothing matches or no memory store has been provisioned
|
|
290
|
+
* yet (not an error).
|
|
291
|
+
*
|
|
292
|
+
* After the route gate succeeds, infra, child billing, rate-limit, and timeout
|
|
293
|
+
* failures degrade to an empty result set. Bad requests, missing identity, and
|
|
294
|
+
* ownership failures (`400`/`401`/`403`) surface as {@link MemoryHttpError}.
|
|
295
|
+
*/
|
|
296
|
+
export declare function recall(input: RecallInput, transport?: Transport, baseUrl?: string): Promise<RecallResponse>;
|
|
297
|
+
/**
|
|
298
|
+
* Sweep (evict) memories to reclaim space — consumer-triggered, never automatic.
|
|
299
|
+
* Call it after a `507` on {@link append}, or proactively to compact the store.
|
|
300
|
+
* Eviction is Neon-only today; a store with nothing to sweep returns `{ evicted: 0 }`.
|
|
301
|
+
*
|
|
302
|
+
* `dryRun` **defaults to `true`**: the gateway returns the `candidates` it would
|
|
303
|
+
* evict without deleting anything — review them, then {@link forget} specific ids
|
|
304
|
+
* or re-run with `dryRun: false` to actually evict.
|
|
305
|
+
*/
|
|
306
|
+
export declare function sweep(input?: SweepInput, transport?: Transport, baseUrl?: string): Promise<MemorySweepResponse>;
|
|
307
|
+
/**
|
|
308
|
+
* Fetch a single memory by id. Throws {@link MemoryHttpError} with `status: 404`
|
|
309
|
+
* when the memory doesn't exist or belongs to another owner (existence is not
|
|
310
|
+
* leaked across owners).
|
|
311
|
+
*/
|
|
312
|
+
export declare function get(id: string, transport?: Transport, baseUrl?: string, options?: MemoryCallOptions): Promise<Memory>;
|
|
313
|
+
/**
|
|
314
|
+
* Forget (hard-delete) a memory by id. Idempotent: a missing or already-deleted
|
|
315
|
+
* id is treated as success by the gateway.
|
|
316
|
+
*/
|
|
317
|
+
export declare function forget(id: string, transport?: Transport, baseUrl?: string, options?: MemoryCallOptions): Promise<void>;
|
|
318
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/memory/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,SAAS,EAAoB,MAAM,qBAAqB,CAAC;AAElE,OAAO,EAAY,eAAe,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAAE,eAAe,EAAE,CAAC;AAiB3B,2EAA2E;AAC3E,eAAO,MAAM,eAAe,8CAA+C,CAAC;AAC5E,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7D,iGAAiG;AACjG,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,KAAK,EAAE,MAAM,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AAK,EAAE,WAAW,EAClB,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,GACzB,OAAO,CAAC,YAAY,CAAC,CAgBvB;AAED;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAC1B,KAAK,EAAE,WAAW,EAClB,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,GACzB,OAAO,CAAC,cAAc,CAAC,CAoBzB;AAED;;;;;;;;GAQG;AACH,wBAAsB,KAAK,CACzB,KAAK,GAAE,UAAe,EACtB,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,GACzB,OAAO,CAAC,mBAAmB,CAAC,CAgB9B;AA6BD;;;;GAIG;AACH,wBAAsB,GAAG,CACvB,EAAE,EAAE,MAAM,EACV,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,EAC1B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,MAAM,CAAC,CAMjB;AAED;;;GAGG;AACH,wBAAsB,MAAM,CAC1B,EAAE,EAAE,MAAM,EACV,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,EAC1B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAmBf"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MEMORY_BACKENDS = exports.MemoryHttpError = void 0;
|
|
4
|
+
exports.append = append;
|
|
5
|
+
exports.recall = recall;
|
|
6
|
+
exports.sweep = sweep;
|
|
7
|
+
exports.get = get;
|
|
8
|
+
exports.forget = forget;
|
|
9
|
+
/**
|
|
10
|
+
* Tenant-scoped long-term memory on the Sapiom memory gateway.
|
|
11
|
+
*
|
|
12
|
+
* import { memory } from "@sapiom/tools"; // ambient auth
|
|
13
|
+
* const { id } = await memory.append({ content: "User prefers dark mode.", scope: "user" });
|
|
14
|
+
* const { results } = await memory.recall({ query: "ui preferences", topK: 5 });
|
|
15
|
+
* const record = await memory.get(id);
|
|
16
|
+
* await memory.forget(id);
|
|
17
|
+
*
|
|
18
|
+
* Or via an explicit client: `createClient({ apiKey }).memory.append(...)`.
|
|
19
|
+
*
|
|
20
|
+
* The gateway speaks camelCase JSON, so this client keeps request and response
|
|
21
|
+
* objects 1:1 with the wire contract.
|
|
22
|
+
*/
|
|
23
|
+
const index_js_1 = require("../_client/index.js");
|
|
24
|
+
const service_url_js_1 = require("../_client/service-url.js");
|
|
25
|
+
const errors_js_1 = require("./errors.js");
|
|
26
|
+
Object.defineProperty(exports, "MemoryHttpError", { enumerable: true, get: function () { return errors_js_1.MemoryHttpError; } });
|
|
27
|
+
/**
|
|
28
|
+
* Memory service ORIGIN. Resolves like every other @sapiom/tools capability: an
|
|
29
|
+
* explicit `SAPIOM_MEMORY_URL` override wins, else the `SAPIOM_SERVICES_BASE` knob
|
|
30
|
+
* re-homes it (subdomain preserved), else the production
|
|
31
|
+
* `https://memory.services.sapiom.ai`. This is the bare origin; the `/v1/memory`
|
|
32
|
+
* path prefix is appended per-method below (a local override is just the gateway
|
|
33
|
+
* origin, e.g. `http://memory.services.localhost:3100`).
|
|
34
|
+
*/
|
|
35
|
+
const DEFAULT_BASE_URL = (0, service_url_js_1.resolveServiceUrl)("memory", process.env.SAPIOM_MEMORY_URL);
|
|
36
|
+
// ----- SDK-facing types (identical to the wire; camelCase end to end) -----
|
|
37
|
+
/** Storage backend selector. Omit for the v0 default `"neon-pgvector"`. */
|
|
38
|
+
exports.MEMORY_BACKENDS = ["neon-pgvector", "upstash-vector"];
|
|
39
|
+
// ----- capability operations -----
|
|
40
|
+
/**
|
|
41
|
+
* Append a memory to the store (an append-log — no prior memory is mutated). The
|
|
42
|
+
* gateway runs a secret-detection gate first (a detected secret is rejected with a
|
|
43
|
+
* 400 {@link MemoryHttpError}, body `decision: "REJECTED"`), then embeds the
|
|
44
|
+
* content and writes it, returning `decision: "ADDED"`.
|
|
45
|
+
*
|
|
46
|
+
* Byte-identical content, or a near-exact semantic duplicate, in the same owner +
|
|
47
|
+
* scope is a no-op that echoes the existing memory unchanged (`decision: "NOOP"`);
|
|
48
|
+
* nothing new is written.
|
|
49
|
+
*
|
|
50
|
+
* On a full Neon store the gateway returns `507` ({@link MemoryHttpError}); call
|
|
51
|
+
* {@link sweep} (or {@link forget}) to free space, then retry. On Upstash, first
|
|
52
|
+
* provisioning can return `422` when the account/index limit is reached.
|
|
53
|
+
*/
|
|
54
|
+
async function append(input, transport = (0, index_js_1.defaultTransport)(), baseUrl = DEFAULT_BASE_URL) {
|
|
55
|
+
const body = { content: input.content };
|
|
56
|
+
if (input.scope !== undefined)
|
|
57
|
+
body.scope = input.scope;
|
|
58
|
+
if (input.metadata !== undefined)
|
|
59
|
+
body.metadata = input.metadata;
|
|
60
|
+
if (input.occurredAt !== undefined)
|
|
61
|
+
body.occurredAt = input.occurredAt;
|
|
62
|
+
if (input.store !== undefined)
|
|
63
|
+
body.store = input.store;
|
|
64
|
+
const res = await (0, errors_js_1.ensureOk)(await transport.fetch(`${baseUrl}/v1/memory/append`, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
headers: { "content-type": "application/json" },
|
|
67
|
+
body: JSON.stringify(body),
|
|
68
|
+
}), "Failed to append memory");
|
|
69
|
+
return (await res.json());
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Recall memories by natural-language query. Returns the top-K matches ranked by
|
|
73
|
+
* score; an empty list when nothing matches or no memory store has been provisioned
|
|
74
|
+
* yet (not an error).
|
|
75
|
+
*
|
|
76
|
+
* After the route gate succeeds, infra, child billing, rate-limit, and timeout
|
|
77
|
+
* failures degrade to an empty result set. Bad requests, missing identity, and
|
|
78
|
+
* ownership failures (`400`/`401`/`403`) surface as {@link MemoryHttpError}.
|
|
79
|
+
*/
|
|
80
|
+
async function recall(input, transport = (0, index_js_1.defaultTransport)(), baseUrl = DEFAULT_BASE_URL) {
|
|
81
|
+
const body = { query: input.query };
|
|
82
|
+
if (input.scope !== undefined)
|
|
83
|
+
body.scope = input.scope;
|
|
84
|
+
if (input.topK !== undefined)
|
|
85
|
+
body.topK = input.topK;
|
|
86
|
+
if (input.minSimilarity !== undefined)
|
|
87
|
+
body.minSimilarity = input.minSimilarity;
|
|
88
|
+
if (input.strategy !== undefined)
|
|
89
|
+
body.strategy = input.strategy;
|
|
90
|
+
if (input.weight !== undefined)
|
|
91
|
+
body.weight = input.weight;
|
|
92
|
+
if (input.filter !== undefined)
|
|
93
|
+
body.filter = input.filter;
|
|
94
|
+
if (input.store !== undefined)
|
|
95
|
+
body.store = input.store;
|
|
96
|
+
const res = await (0, errors_js_1.ensureOk)(await transport.fetch(`${baseUrl}/v1/memory/recall`, {
|
|
97
|
+
method: "POST",
|
|
98
|
+
headers: { "content-type": "application/json" },
|
|
99
|
+
body: JSON.stringify(body),
|
|
100
|
+
}), "Failed to recall memories");
|
|
101
|
+
return (await res.json());
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Sweep (evict) memories to reclaim space — consumer-triggered, never automatic.
|
|
105
|
+
* Call it after a `507` on {@link append}, or proactively to compact the store.
|
|
106
|
+
* Eviction is Neon-only today; a store with nothing to sweep returns `{ evicted: 0 }`.
|
|
107
|
+
*
|
|
108
|
+
* `dryRun` **defaults to `true`**: the gateway returns the `candidates` it would
|
|
109
|
+
* evict without deleting anything — review them, then {@link forget} specific ids
|
|
110
|
+
* or re-run with `dryRun: false` to actually evict.
|
|
111
|
+
*/
|
|
112
|
+
async function sweep(input = {}, transport = (0, index_js_1.defaultTransport)(), baseUrl = DEFAULT_BASE_URL) {
|
|
113
|
+
const body = {};
|
|
114
|
+
if (input.count !== undefined)
|
|
115
|
+
body.count = input.count;
|
|
116
|
+
if (input.strategy !== undefined)
|
|
117
|
+
body.strategy = input.strategy;
|
|
118
|
+
if (input.dryRun !== undefined)
|
|
119
|
+
body.dryRun = input.dryRun;
|
|
120
|
+
if (input.store !== undefined)
|
|
121
|
+
body.store = input.store;
|
|
122
|
+
const res = await (0, errors_js_1.ensureOk)(await transport.fetch(`${baseUrl}/v1/memory/sweep`, {
|
|
123
|
+
method: "POST",
|
|
124
|
+
headers: { "content-type": "application/json" },
|
|
125
|
+
body: JSON.stringify(body),
|
|
126
|
+
}), "Failed to sweep memories");
|
|
127
|
+
return (await res.json());
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Build the `/v1/memory/:id` URL for get/forget, including any store selector.
|
|
131
|
+
*/
|
|
132
|
+
function memoryItemUrl(baseUrl, id, options) {
|
|
133
|
+
const path = `${baseUrl}/v1/memory/${encodeURIComponent(id)}`;
|
|
134
|
+
const params = new URLSearchParams();
|
|
135
|
+
const store = options?.store;
|
|
136
|
+
if (store) {
|
|
137
|
+
if (store.backend !== undefined) {
|
|
138
|
+
params.set("storeBackend", store.backend);
|
|
139
|
+
}
|
|
140
|
+
if (store.namespace !== undefined) {
|
|
141
|
+
params.set("storeNamespace", store.namespace);
|
|
142
|
+
}
|
|
143
|
+
if (store.embedder !== undefined) {
|
|
144
|
+
params.set("storeEmbedderProvider", store.embedder.provider);
|
|
145
|
+
params.set("storeEmbedderModel", store.embedder.model);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const query = params.toString();
|
|
149
|
+
return query ? `${path}?${query}` : path;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Fetch a single memory by id. Throws {@link MemoryHttpError} with `status: 404`
|
|
153
|
+
* when the memory doesn't exist or belongs to another owner (existence is not
|
|
154
|
+
* leaked across owners).
|
|
155
|
+
*/
|
|
156
|
+
async function get(id, transport = (0, index_js_1.defaultTransport)(), baseUrl = DEFAULT_BASE_URL, options) {
|
|
157
|
+
const res = await (0, errors_js_1.ensureOk)(await transport.fetch(memoryItemUrl(baseUrl, id, options)), `Failed to get memory '${id}'`);
|
|
158
|
+
return (await res.json());
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Forget (hard-delete) a memory by id. Idempotent: a missing or already-deleted
|
|
162
|
+
* id is treated as success by the gateway.
|
|
163
|
+
*/
|
|
164
|
+
async function forget(id, transport = (0, index_js_1.defaultTransport)(), baseUrl = DEFAULT_BASE_URL, options) {
|
|
165
|
+
const res = await transport.fetch(memoryItemUrl(baseUrl, id, options), {
|
|
166
|
+
method: "DELETE",
|
|
167
|
+
});
|
|
168
|
+
if (!res.ok) {
|
|
169
|
+
const text = await res.text().catch(() => "");
|
|
170
|
+
let parsed;
|
|
171
|
+
try {
|
|
172
|
+
parsed = JSON.parse(text);
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
parsed = text;
|
|
176
|
+
}
|
|
177
|
+
throw new errors_js_1.MemoryHttpError(`Failed to forget memory '${id}': ${res.status} ${text}`, res.status, parsed);
|
|
178
|
+
}
|
|
179
|
+
// 204 No Content — nothing to parse.
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/memory/index.ts"],"names":[],"mappings":";;;AAkUA,wBAoBC;AAWD,wBAwBC;AAWD,sBAoBC;AAkCD,kBAWC;AAMD,wBAwBC;AAneD;;;;;;;;;;;;;GAaG;AACH,kDAAkE;AAClE,8DAA8D;AAC9D,2CAAwD;AAE/C,gGAFU,2BAAe,OAEV;AAExB;;;;;;;GAOG;AACH,MAAM,gBAAgB,GAAG,IAAA,kCAAiB,EACxC,QAAQ,EACR,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAC9B,CAAC;AAEF,6EAA6E;AAE7E,2EAA2E;AAC9D,QAAA,eAAe,GAAG,CAAC,eAAe,EAAE,gBAAgB,CAAU,CAAC;AA8Q5E,oCAAoC;AAEpC;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,MAAM,CAC1B,KAAkB,EAClB,YAAuB,IAAA,2BAAgB,GAAE,EACzC,OAAO,GAAG,gBAAgB;IAE1B,MAAM,IAAI,GAA4B,EAAE,OAAO,EAAE,KAAK,CAA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,MAAM,EACV,MAAM,CACP,CAAC;IACJ,CAAC;IACD,qCAAqC;AACvC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stub/index.ts"],"names":[],"mappings":"AAqCA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stub/index.ts"],"names":[],"mappings":"AAqCA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAqD3C,4EAA4E;AAC5E,MAAM,MAAM,aAAa,GAAG,MAAM,CAChC,MAAM,EACN,OAAO,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAC5C,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACvB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACxB;AAqXD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,GAAE,iBAAsB,GAAG,MAAM,CA0uBrE"}
|
package/dist/cjs/stub/index.js
CHANGED
|
@@ -706,6 +706,108 @@ function createStubClient(opts = {}) {
|
|
|
706
706
|
delete: (id) => Promise.resolve(r("email.webhooks.delete", [id], () => undefined)),
|
|
707
707
|
},
|
|
708
708
|
},
|
|
709
|
+
domains: {
|
|
710
|
+
check: (input) => Promise.resolve(r("domains.check", [input], () => (input.domainNames ?? []).map((domainName) => ({
|
|
711
|
+
domainName,
|
|
712
|
+
available: true,
|
|
713
|
+
purchasePrice: "12.99",
|
|
714
|
+
renewalPrice: "12.99",
|
|
715
|
+
premium: false,
|
|
716
|
+
})))),
|
|
717
|
+
register: (input) => Promise.resolve(r("domains.register", [input], () => ({
|
|
718
|
+
domainName: input.domainName,
|
|
719
|
+
status: "active",
|
|
720
|
+
expiresAt: "2099-01-01T00:00:00Z",
|
|
721
|
+
registeredAt: "2099-01-01T00:00:00Z",
|
|
722
|
+
purchasePrice: "12.99",
|
|
723
|
+
}))),
|
|
724
|
+
renew: (input) => Promise.resolve(r("domains.renew", [input], () => ({
|
|
725
|
+
domainName: input.domainName,
|
|
726
|
+
expiresAt: "2099-01-01T00:00:00Z",
|
|
727
|
+
renewalPrice: "12.99",
|
|
728
|
+
}))),
|
|
729
|
+
list: () => Promise.resolve(r("domains.list", [], () => [])),
|
|
730
|
+
get: (input) => Promise.resolve(r("domains.get", [input], () => ({
|
|
731
|
+
domainName: input.domainName,
|
|
732
|
+
status: "active",
|
|
733
|
+
expiresAt: "2099-01-01T00:00:00Z",
|
|
734
|
+
registeredAt: "2099-01-01T00:00:00Z",
|
|
735
|
+
nameservers: ["ns1.example.com", "ns2.example.com"],
|
|
736
|
+
locked: true,
|
|
737
|
+
transferEligibleAt: null,
|
|
738
|
+
}))),
|
|
739
|
+
transferOut: (input) => Promise.resolve(r("domains.transferOut", [input], () => ({
|
|
740
|
+
domainName: input.domainName,
|
|
741
|
+
authCode: "stub-auth-code",
|
|
742
|
+
transferInstructions: "(stub) provide this auth code to the new registrar.",
|
|
743
|
+
}))),
|
|
744
|
+
dns: {
|
|
745
|
+
create: (input) => Promise.resolve(r("domains.dns.create", [input], () => ({
|
|
746
|
+
recordId: `stub-record-${++launchSeq}`,
|
|
747
|
+
domainName: input.domainName,
|
|
748
|
+
type: input.type,
|
|
749
|
+
host: input.host,
|
|
750
|
+
fqdn: input.host
|
|
751
|
+
? `${input.host}.${input.domainName}`
|
|
752
|
+
: input.domainName,
|
|
753
|
+
value: input.value,
|
|
754
|
+
ttl: input.ttl ?? 300,
|
|
755
|
+
...(input.priority !== undefined && { priority: input.priority }),
|
|
756
|
+
createdAt: "2099-01-01T00:00:00Z",
|
|
757
|
+
}))),
|
|
758
|
+
list: (input) => Promise.resolve(r("domains.dns.list", [input], () => [])),
|
|
759
|
+
get: (input) => Promise.resolve(r("domains.dns.get", [input], () => ({
|
|
760
|
+
recordId: input.recordId,
|
|
761
|
+
domainName: input.domainName,
|
|
762
|
+
type: "A",
|
|
763
|
+
host: "",
|
|
764
|
+
fqdn: input.domainName,
|
|
765
|
+
value: "203.0.113.10",
|
|
766
|
+
ttl: 300,
|
|
767
|
+
}))),
|
|
768
|
+
update: (input) => Promise.resolve(r("domains.dns.update", [input], () => ({
|
|
769
|
+
recordId: input.recordId,
|
|
770
|
+
domainName: input.domainName,
|
|
771
|
+
type: input.type ?? "A",
|
|
772
|
+
host: input.host ?? "",
|
|
773
|
+
fqdn: input.domainName,
|
|
774
|
+
value: input.value ?? "203.0.113.10",
|
|
775
|
+
ttl: input.ttl ?? 300,
|
|
776
|
+
...(input.priority !== undefined && { priority: input.priority }),
|
|
777
|
+
}))),
|
|
778
|
+
delete: (input) => Promise.resolve(r("domains.dns.delete", [input], () => undefined)),
|
|
779
|
+
},
|
|
780
|
+
},
|
|
781
|
+
memory: {
|
|
782
|
+
append: (input) => Promise.resolve(r("memory.append", [input], () => ({
|
|
783
|
+
id: "stub-memory",
|
|
784
|
+
content: input.content,
|
|
785
|
+
scope: input.scope ?? "default",
|
|
786
|
+
decision: "ADDED",
|
|
787
|
+
createdAt: "2099-01-01T00:00:00Z",
|
|
788
|
+
occurredAt: input.occurredAt ?? null,
|
|
789
|
+
metadata: input.metadata ?? {},
|
|
790
|
+
}))),
|
|
791
|
+
recall: (input) => Promise.resolve(r("memory.recall", [input], () => ({
|
|
792
|
+
results: [],
|
|
793
|
+
query: input.query,
|
|
794
|
+
topK: input.topK ?? 5,
|
|
795
|
+
count: 0,
|
|
796
|
+
}))),
|
|
797
|
+
sweep: (input) => Promise.resolve(r("memory.sweep", [input], () => input?.dryRun === false
|
|
798
|
+
? { evicted: 0 }
|
|
799
|
+
: { evicted: 0, candidates: [] })),
|
|
800
|
+
get: (id, options) => Promise.resolve(r("memory.get", [id, options], () => ({
|
|
801
|
+
id,
|
|
802
|
+
content: "(stub) memory content",
|
|
803
|
+
scope: "default",
|
|
804
|
+
createdAt: "2099-01-01T00:00:00Z",
|
|
805
|
+
occurredAt: null,
|
|
806
|
+
lastAccessedAt: null,
|
|
807
|
+
metadata: {},
|
|
808
|
+
}))),
|
|
809
|
+
forget: (id, options) => Promise.resolve(r("memory.forget", [id, options], () => undefined)),
|
|
810
|
+
},
|
|
709
811
|
withAttribution: () => client,
|
|
710
812
|
};
|
|
711
813
|
return client;
|