@agentskit/memory 0.8.3 → 0.10.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/chunk-G5S2A3MJ.js +48 -0
- package/dist/chunk-G5S2A3MJ.js.map +1 -0
- package/dist/index.cjs +563 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +246 -32
- package/dist/index.d.ts +246 -32
- package/dist/index.js +548 -53
- package/dist/index.js.map +1 -1
- package/dist/personalization.cjs +44 -0
- package/dist/personalization.cjs.map +1 -0
- package/dist/personalization.d.cts +32 -0
- package/dist/personalization.d.ts +32 -0
- package/dist/personalization.js +3 -0
- package/dist/personalization.js.map +1 -0
- package/package.json +15 -9
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ChatMemory, VectorMemory, VectorFilter, Message } from '@agentskit/core';
|
|
2
|
+
export { PersonalizationProfile, PersonalizationStore, createInMemoryPersonalization, renderProfileContext } from './personalization.cjs';
|
|
3
|
+
import { PIIRule, RedactionVault, RedactionAuditSink } from '@agentskit/core/security';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* ChatMemory backed by a JSON file on disk. Node-only.
|
|
@@ -86,37 +88,6 @@ interface FileVectorMemoryConfig {
|
|
|
86
88
|
}
|
|
87
89
|
declare function fileVectorMemory(config: FileVectorMemoryConfig): VectorMemory;
|
|
88
90
|
|
|
89
|
-
/**
|
|
90
|
-
* Personalization — a persisted profile per subject (user id,
|
|
91
|
-
* account id, device). The agent reads it on every run to
|
|
92
|
-
* condition responses; the runtime updates it when new facts
|
|
93
|
-
* appear.
|
|
94
|
-
*/
|
|
95
|
-
interface PersonalizationProfile {
|
|
96
|
-
subjectId: string;
|
|
97
|
-
/** Human-editable notes, facts, preferences. */
|
|
98
|
-
traits: Record<string, unknown>;
|
|
99
|
-
/** ISO timestamp of the latest update. */
|
|
100
|
-
updatedAt: string;
|
|
101
|
-
}
|
|
102
|
-
interface PersonalizationStore {
|
|
103
|
-
get: (subjectId: string) => Promise<PersonalizationProfile | null>;
|
|
104
|
-
set: (profile: PersonalizationProfile) => Promise<void>;
|
|
105
|
-
merge: (subjectId: string, traits: Record<string, unknown>) => Promise<PersonalizationProfile>;
|
|
106
|
-
delete?: (subjectId: string) => Promise<void>;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* In-memory personalization store — tests, single-process demos.
|
|
110
|
-
* Bring your own for production (Postgres, Redis, DynamoDB).
|
|
111
|
-
*/
|
|
112
|
-
declare function createInMemoryPersonalization(): PersonalizationStore;
|
|
113
|
-
/**
|
|
114
|
-
* Render a profile into a system-prompt fragment the runtime can
|
|
115
|
-
* prepend. Kept intentionally short — full profile dumps bloat
|
|
116
|
-
* context and leak unnecessary detail to the model.
|
|
117
|
-
*/
|
|
118
|
-
declare function renderProfileContext(profile: PersonalizationProfile | null): string;
|
|
119
|
-
|
|
120
91
|
/**
|
|
121
92
|
* Non-linear memory: a typed knowledge graph. Use for facts the
|
|
122
93
|
* agent should remember beyond a single conversation — entities,
|
|
@@ -412,4 +383,247 @@ interface HierarchicalMemory extends ChatMemory {
|
|
|
412
383
|
*/
|
|
413
384
|
declare function createHierarchicalMemory(options: HierarchicalMemoryOptions): HierarchicalMemory;
|
|
414
385
|
|
|
415
|
-
|
|
386
|
+
/**
|
|
387
|
+
* GDPR / LGPD / CCPA data-subject deletion. ADR-0003 deferred
|
|
388
|
+
* retention; this module is the "forget the user" half.
|
|
389
|
+
*
|
|
390
|
+
* Design: rather than mutate every memory contract (and break the
|
|
391
|
+
* public API freeze, RFC-0007), we attach `forgetSubject` as a
|
|
392
|
+
* **capability** on a memory instance. Backends that can implement it
|
|
393
|
+
* declare a `subjectFilter` (how to recognise records belonging to a
|
|
394
|
+
* subject) and `deleteFn` (how to remove them). `forgetSubject(memory,
|
|
395
|
+
* subjectId)` walks every backend the runtime is configured with and
|
|
396
|
+
* runs the deletion, returning a per-backend report you can sign into
|
|
397
|
+
* the audit log (#162).
|
|
398
|
+
*
|
|
399
|
+
* Closes issue #798.
|
|
400
|
+
*/
|
|
401
|
+
interface ForgettableMemory {
|
|
402
|
+
/**
|
|
403
|
+
* Backend identifier (`'pgvector'`, `'pinecone'`, `'sqlite'`, etc.).
|
|
404
|
+
* Used for the audit-log entry and for the per-backend report.
|
|
405
|
+
*/
|
|
406
|
+
__agentskitBackend: string;
|
|
407
|
+
/** Delete every record where `metadata.subjectId === subjectId`. */
|
|
408
|
+
forgetSubject: (subjectId: string) => Promise<ForgetReport>;
|
|
409
|
+
}
|
|
410
|
+
interface ForgetReport {
|
|
411
|
+
backend: string;
|
|
412
|
+
deletedCount: number;
|
|
413
|
+
/** ISO timestamp of the deletion. */
|
|
414
|
+
at: string;
|
|
415
|
+
/** Records the deletion couldn't reach (offline replica, missing index). */
|
|
416
|
+
failures?: Array<{
|
|
417
|
+
id: string;
|
|
418
|
+
reason: string;
|
|
419
|
+
}>;
|
|
420
|
+
}
|
|
421
|
+
interface ForgetSubjectResult {
|
|
422
|
+
subjectId: string;
|
|
423
|
+
reports: ForgetReport[];
|
|
424
|
+
totalDeleted: number;
|
|
425
|
+
/** Hash you can sign into the audit log to prove the deletion ran. */
|
|
426
|
+
evidenceHash: string;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Walk every memory passed in and run `forgetSubject(subjectId)` on
|
|
430
|
+
* any that implement it. Memories that don't implement it are
|
|
431
|
+
* silently skipped — they hold no subject-scoped data, or you must
|
|
432
|
+
* delete out-of-band (e.g. log retention).
|
|
433
|
+
*/
|
|
434
|
+
declare function forgetSubject(memories: Array<ChatMemory | VectorMemory | unknown>, subjectId: string): Promise<ForgetSubjectResult>;
|
|
435
|
+
/**
|
|
436
|
+
* Helper for backends that key records by `metadata.subjectId`. Wraps
|
|
437
|
+
* any `delete(ids)`-style API into a `ForgettableMemory`.
|
|
438
|
+
*/
|
|
439
|
+
declare function makeForgettable<M extends object>(memory: M, options: {
|
|
440
|
+
backend: string;
|
|
441
|
+
listIds: (subjectId: string) => Promise<string[]>;
|
|
442
|
+
deleteIds: (ids: string[]) => Promise<void>;
|
|
443
|
+
}): M & ForgettableMemory;
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Wrap any `ChatMemory` so PII is redacted (or tokenized) on every
|
|
447
|
+
* `save()`. Works with the in-memory, file, sqlite, turso, and redis
|
|
448
|
+
* chat memories. `load()` and `clear()` are passthrough — reveal
|
|
449
|
+
* happens at read time via `@agentskit/core/security` `reveal()`,
|
|
450
|
+
* not inside the memory.
|
|
451
|
+
*
|
|
452
|
+
* `mode: 'redact'` (default) replaces matches with the rules' bracket
|
|
453
|
+
* markers — irreversible. `mode: 'tokenize'` replaces matches with
|
|
454
|
+
* opaque `<<piitoken:…>>` markers and stores originals in the vault
|
|
455
|
+
* so role-gated `reveal()` can recover them.
|
|
456
|
+
*
|
|
457
|
+
* Closes the memory-write half of issue #791.
|
|
458
|
+
*/
|
|
459
|
+
type RedactionMode = 'redact' | 'tokenize';
|
|
460
|
+
interface ChatMemoryRedactionOptions {
|
|
461
|
+
/**
|
|
462
|
+
* Rules to apply. Pass `DEFAULT_PII_RULES` for the baseline set,
|
|
463
|
+
* `compilePIITaxonomy(json)` for a custom JSON taxonomy, or any
|
|
464
|
+
* hand-rolled `PIIRule[]`. Same shape as `createPIIRedactor`.
|
|
465
|
+
*/
|
|
466
|
+
rules: PIIRule[];
|
|
467
|
+
mode?: RedactionMode;
|
|
468
|
+
/** Required when `mode === 'tokenize'`. */
|
|
469
|
+
vault?: RedactionVault;
|
|
470
|
+
/** Roles allowed to reveal — required when `mode === 'tokenize'`. */
|
|
471
|
+
allowedRoles?: string[];
|
|
472
|
+
/** Optional audit sink threaded into the vault `tokenize()` calls. */
|
|
473
|
+
audit?: RedactionAuditSink;
|
|
474
|
+
}
|
|
475
|
+
interface VectorMemoryRedactionOptions extends ChatMemoryRedactionOptions {
|
|
476
|
+
}
|
|
477
|
+
declare function wrapChatMemoryWithRedaction(inner: ChatMemory, options: ChatMemoryRedactionOptions): ChatMemory;
|
|
478
|
+
/**
|
|
479
|
+
* Wrap any `VectorMemory` so each document's `content` is redacted (or
|
|
480
|
+
* tokenized) before `store()`. `search()` and `delete()` pass through.
|
|
481
|
+
*
|
|
482
|
+
* Note: embeddings pass through verbatim. Customers who embed
|
|
483
|
+
* plaintext PII separately (e.g. via a hosted embedding provider)
|
|
484
|
+
* must redact the input to their embedder, not just to this wrapper.
|
|
485
|
+
*/
|
|
486
|
+
declare function wrapVectorMemoryWithRedaction(inner: VectorMemory, options: VectorMemoryRedactionOptions): VectorMemory;
|
|
487
|
+
|
|
488
|
+
/** Minimal KV store contract. */
|
|
489
|
+
interface AgentskitMemoryStore {
|
|
490
|
+
readonly id: string | undefined;
|
|
491
|
+
get(key: string): Promise<unknown>;
|
|
492
|
+
set(key: string, value: unknown): Promise<void>;
|
|
493
|
+
}
|
|
494
|
+
interface KvEntry {
|
|
495
|
+
readonly value: unknown;
|
|
496
|
+
readonly insertedAt: number;
|
|
497
|
+
}
|
|
498
|
+
interface CommonKvConfig {
|
|
499
|
+
readonly maxMessages?: number;
|
|
500
|
+
readonly ttlSeconds?: number;
|
|
501
|
+
}
|
|
502
|
+
interface InMemoryKvConfig extends CommonKvConfig {
|
|
503
|
+
readonly backend: 'in-memory';
|
|
504
|
+
}
|
|
505
|
+
interface FileKvConfig extends CommonKvConfig {
|
|
506
|
+
readonly backend: 'file';
|
|
507
|
+
readonly path: string;
|
|
508
|
+
}
|
|
509
|
+
interface SqliteKvConfig extends CommonKvConfig {
|
|
510
|
+
readonly backend: 'sqlite';
|
|
511
|
+
readonly path: string;
|
|
512
|
+
}
|
|
513
|
+
interface RedisKvConfig extends CommonKvConfig {
|
|
514
|
+
readonly backend: 'redis';
|
|
515
|
+
readonly url: string;
|
|
516
|
+
readonly prefix: string;
|
|
517
|
+
}
|
|
518
|
+
interface VectorKvConfig extends CommonKvConfig {
|
|
519
|
+
readonly backend: 'vector';
|
|
520
|
+
readonly provider: string;
|
|
521
|
+
readonly collection: string;
|
|
522
|
+
}
|
|
523
|
+
interface LocalStorageKvConfig extends CommonKvConfig {
|
|
524
|
+
readonly backend: 'localstorage';
|
|
525
|
+
readonly key: string;
|
|
526
|
+
}
|
|
527
|
+
type KvMemoryConfig = InMemoryKvConfig | FileKvConfig | SqliteKvConfig | RedisKvConfig | VectorKvConfig | LocalStorageKvConfig;
|
|
528
|
+
interface RedisLike {
|
|
529
|
+
get(key: string): Promise<string | null>;
|
|
530
|
+
set(key: string, value: string, options?: {
|
|
531
|
+
readonly EX?: number;
|
|
532
|
+
}): Promise<unknown>;
|
|
533
|
+
del(key: string): Promise<unknown>;
|
|
534
|
+
keys(pattern: string): Promise<readonly string[]>;
|
|
535
|
+
}
|
|
536
|
+
interface SqliteStmt {
|
|
537
|
+
run(...params: unknown[]): void;
|
|
538
|
+
get(...params: unknown[]): unknown;
|
|
539
|
+
all(...params: unknown[]): unknown[];
|
|
540
|
+
}
|
|
541
|
+
interface SqliteLike {
|
|
542
|
+
exec(sql: string): void;
|
|
543
|
+
prepare(sql: string): SqliteStmt;
|
|
544
|
+
}
|
|
545
|
+
type SqliteOpener = (path: string) => SqliteLike;
|
|
546
|
+
interface MemoryVectorStoreLike {
|
|
547
|
+
upsert(rows: readonly {
|
|
548
|
+
readonly chunkId: string;
|
|
549
|
+
readonly vec: readonly number[];
|
|
550
|
+
readonly metadata: Record<string, unknown>;
|
|
551
|
+
}[]): Promise<void>;
|
|
552
|
+
query(vec: readonly number[], k: number, filter?: Record<string, unknown>): Promise<readonly {
|
|
553
|
+
readonly chunkId: string;
|
|
554
|
+
readonly score: number;
|
|
555
|
+
readonly metadata: Record<string, unknown>;
|
|
556
|
+
}[]>;
|
|
557
|
+
}
|
|
558
|
+
interface MemoryEmbedderLike {
|
|
559
|
+
embed(texts: readonly string[]): Promise<number[][]>;
|
|
560
|
+
}
|
|
561
|
+
interface LocalStorageLike {
|
|
562
|
+
getItem(key: string): string | null;
|
|
563
|
+
setItem(key: string, value: string): void;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
declare const createInMemoryStore: (config: InMemoryKvConfig) => AgentskitMemoryStore;
|
|
567
|
+
declare const createFileStore: (config: FileKvConfig) => AgentskitMemoryStore;
|
|
568
|
+
interface CreateLocalStorageStoreOpts {
|
|
569
|
+
readonly config: LocalStorageKvConfig;
|
|
570
|
+
readonly storage?: LocalStorageLike;
|
|
571
|
+
readonly filePath?: string;
|
|
572
|
+
}
|
|
573
|
+
declare const createLocalStorageStore: ({ config, storage, filePath, }: CreateLocalStorageStoreOpts) => AgentskitMemoryStore;
|
|
574
|
+
|
|
575
|
+
interface CreateSqliteStoreOpts {
|
|
576
|
+
readonly config: SqliteKvConfig;
|
|
577
|
+
readonly open: SqliteOpener;
|
|
578
|
+
}
|
|
579
|
+
declare const createSqliteStore: ({ config, open }: CreateSqliteStoreOpts) => AgentskitMemoryStore;
|
|
580
|
+
/**
|
|
581
|
+
* Lazy-import `better-sqlite3` and return an opener, or `undefined` when the
|
|
582
|
+
* optional peer dep is absent (caller surfaces AK_MEMORY_PEER_MISSING).
|
|
583
|
+
*/
|
|
584
|
+
declare const tryDefaultSqliteOpener: () => Promise<SqliteOpener | undefined>;
|
|
585
|
+
|
|
586
|
+
interface CreateRedisStoreOpts {
|
|
587
|
+
readonly config: RedisKvConfig;
|
|
588
|
+
readonly client: RedisLike;
|
|
589
|
+
}
|
|
590
|
+
declare const createRedisStore: ({ config, client }: CreateRedisStoreOpts) => AgentskitMemoryStore;
|
|
591
|
+
/** Bridge an `ioredis`-style client to the {@link RedisLike} options-object shape. */
|
|
592
|
+
declare const adaptIoredis: (io: {
|
|
593
|
+
get(key: string): Promise<string | null>;
|
|
594
|
+
set(key: string, value: string, mode?: string, ttl?: number): Promise<unknown>;
|
|
595
|
+
del(key: string): Promise<unknown>;
|
|
596
|
+
keys(pattern: string): Promise<string[]>;
|
|
597
|
+
}) => RedisLike;
|
|
598
|
+
/** Lazy-import `redis` (node-redis v4), connect, and return a client; `undefined` if absent. */
|
|
599
|
+
declare const tryDefaultRedisClient: (url: string) => Promise<RedisLike | undefined>;
|
|
600
|
+
|
|
601
|
+
interface CreateVectorStoreOpts {
|
|
602
|
+
readonly config: VectorKvConfig;
|
|
603
|
+
readonly vectorStore: MemoryVectorStoreLike;
|
|
604
|
+
readonly embedder: MemoryEmbedderLike;
|
|
605
|
+
}
|
|
606
|
+
declare const createVectorStore: ({ config, vectorStore, embedder, }: CreateVectorStoreOpts) => AgentskitMemoryStore & {
|
|
607
|
+
recall(query: string, k?: number): Promise<readonly unknown[]>;
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
declare class MemoryBackendNotImplementedError extends Error {
|
|
611
|
+
readonly code = "MEMORY_BACKEND_NOT_IMPLEMENTED";
|
|
612
|
+
readonly backend: KvMemoryConfig['backend'];
|
|
613
|
+
constructor(backend: KvMemoryConfig['backend']);
|
|
614
|
+
}
|
|
615
|
+
type MemoryBackendStatus = 'supported' | 'planned';
|
|
616
|
+
declare const MEMORY_BACKEND_SUPPORT: Readonly<Record<KvMemoryConfig['backend'], MemoryBackendStatus>>;
|
|
617
|
+
declare const isMemoryBackendSupported: (backend: KvMemoryConfig["backend"]) => boolean;
|
|
618
|
+
interface CreateKvMemoryFromConfigOpts {
|
|
619
|
+
readonly config: KvMemoryConfig;
|
|
620
|
+
readonly sqlite?: SqliteOpener;
|
|
621
|
+
readonly localStorageFilePath?: string;
|
|
622
|
+
readonly redis?: RedisLike;
|
|
623
|
+
readonly vectorStore?: MemoryVectorStoreLike;
|
|
624
|
+
readonly embedder?: MemoryEmbedderLike;
|
|
625
|
+
}
|
|
626
|
+
declare const createKvMemoryFromConfig: ({ config, sqlite, localStorageFilePath, redis, vectorStore, embedder, }: CreateKvMemoryFromConfigOpts) => AgentskitMemoryStore;
|
|
627
|
+
declare const createKvMemoryFromConfigAuto: (config: KvMemoryConfig) => Promise<AgentskitMemoryStore>;
|
|
628
|
+
|
|
629
|
+
export { type AgentskitMemoryStore, type ChatMemoryRedactionOptions, type ChromaConfig, type CreateKvMemoryFromConfigOpts, type CreateLocalStorageStoreOpts, type CreateRedisStoreOpts, type CreateSqliteStoreOpts, type CreateVectorStoreOpts, type EncryptedEnvelope, type EncryptedMemoryOptions, type FileKvConfig, type FileVectorMemoryConfig, type ForgetReport, type ForgetSubjectResult, type ForgettableMemory, type GraphEdge, type GraphMemory, type GraphNode, type GraphQuery, type HierarchicalMemory, type HierarchicalMemoryOptions, type HierarchicalRecall, type InMemoryKvConfig, type KvEntry, type KvMemoryConfig, type LocalStorageKvConfig, type LocalStorageLike, MEMORY_BACKEND_SUPPORT, MemoryBackendNotImplementedError, type MemoryBackendStatus, type MemoryEmbedderLike, type MemoryVectorStoreLike, type MilvusConfig, type MongoAtlasVectorConfig, type MongoCollectionLike, type PgVectorConfig, type PgVectorRunner, type PineconeConfig, type QdrantConfig, type RedactionMode, type RedisChatMemoryConfig, type RedisClientAdapter, type RedisConnectionConfig, type RedisKvConfig, type RedisLike, type RedisVectorMemoryConfig, type SqliteChatMemoryConfig, type SqliteKvConfig, type SqliteLike, type SqliteOpener, type SqliteStmt, type SupabaseVectorStoreConfig, type TursoChatMemoryConfig, type UpstashVectorConfig, type VectorKvConfig, type VectorMemoryRedactionOptions, type VectorStore, type VectorStoreDocument, type VectorStoreResult, type WeaviateConfig, adaptIoredis, chroma, createEncryptedMemory, createFileStore, createHierarchicalMemory, createInMemoryGraph, createInMemoryStore, createKvMemoryFromConfig, createKvMemoryFromConfigAuto, createLocalStorageStore, createRedisStore, createSqliteStore, createVectorStore, fileChatMemory, fileVectorMemory, forgetSubject, isMemoryBackendSupported, makeForgettable, matchesFilter, milvusVectorStore, mongoAtlasVectorStore, pgvector, pinecone, qdrant, redisChatMemory, redisVectorMemory, sqliteChatMemory, supabaseVectorStore, tryDefaultRedisClient, tryDefaultSqliteOpener, tursoChatMemory, upstashVector, weaviateVectorStore, wrapChatMemoryWithRedaction, wrapVectorMemoryWithRedaction };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ChatMemory, VectorMemory, VectorFilter, Message } from '@agentskit/core';
|
|
2
|
+
export { PersonalizationProfile, PersonalizationStore, createInMemoryPersonalization, renderProfileContext } from './personalization.js';
|
|
3
|
+
import { PIIRule, RedactionVault, RedactionAuditSink } from '@agentskit/core/security';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* ChatMemory backed by a JSON file on disk. Node-only.
|
|
@@ -86,37 +88,6 @@ interface FileVectorMemoryConfig {
|
|
|
86
88
|
}
|
|
87
89
|
declare function fileVectorMemory(config: FileVectorMemoryConfig): VectorMemory;
|
|
88
90
|
|
|
89
|
-
/**
|
|
90
|
-
* Personalization — a persisted profile per subject (user id,
|
|
91
|
-
* account id, device). The agent reads it on every run to
|
|
92
|
-
* condition responses; the runtime updates it when new facts
|
|
93
|
-
* appear.
|
|
94
|
-
*/
|
|
95
|
-
interface PersonalizationProfile {
|
|
96
|
-
subjectId: string;
|
|
97
|
-
/** Human-editable notes, facts, preferences. */
|
|
98
|
-
traits: Record<string, unknown>;
|
|
99
|
-
/** ISO timestamp of the latest update. */
|
|
100
|
-
updatedAt: string;
|
|
101
|
-
}
|
|
102
|
-
interface PersonalizationStore {
|
|
103
|
-
get: (subjectId: string) => Promise<PersonalizationProfile | null>;
|
|
104
|
-
set: (profile: PersonalizationProfile) => Promise<void>;
|
|
105
|
-
merge: (subjectId: string, traits: Record<string, unknown>) => Promise<PersonalizationProfile>;
|
|
106
|
-
delete?: (subjectId: string) => Promise<void>;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* In-memory personalization store — tests, single-process demos.
|
|
110
|
-
* Bring your own for production (Postgres, Redis, DynamoDB).
|
|
111
|
-
*/
|
|
112
|
-
declare function createInMemoryPersonalization(): PersonalizationStore;
|
|
113
|
-
/**
|
|
114
|
-
* Render a profile into a system-prompt fragment the runtime can
|
|
115
|
-
* prepend. Kept intentionally short — full profile dumps bloat
|
|
116
|
-
* context and leak unnecessary detail to the model.
|
|
117
|
-
*/
|
|
118
|
-
declare function renderProfileContext(profile: PersonalizationProfile | null): string;
|
|
119
|
-
|
|
120
91
|
/**
|
|
121
92
|
* Non-linear memory: a typed knowledge graph. Use for facts the
|
|
122
93
|
* agent should remember beyond a single conversation — entities,
|
|
@@ -412,4 +383,247 @@ interface HierarchicalMemory extends ChatMemory {
|
|
|
412
383
|
*/
|
|
413
384
|
declare function createHierarchicalMemory(options: HierarchicalMemoryOptions): HierarchicalMemory;
|
|
414
385
|
|
|
415
|
-
|
|
386
|
+
/**
|
|
387
|
+
* GDPR / LGPD / CCPA data-subject deletion. ADR-0003 deferred
|
|
388
|
+
* retention; this module is the "forget the user" half.
|
|
389
|
+
*
|
|
390
|
+
* Design: rather than mutate every memory contract (and break the
|
|
391
|
+
* public API freeze, RFC-0007), we attach `forgetSubject` as a
|
|
392
|
+
* **capability** on a memory instance. Backends that can implement it
|
|
393
|
+
* declare a `subjectFilter` (how to recognise records belonging to a
|
|
394
|
+
* subject) and `deleteFn` (how to remove them). `forgetSubject(memory,
|
|
395
|
+
* subjectId)` walks every backend the runtime is configured with and
|
|
396
|
+
* runs the deletion, returning a per-backend report you can sign into
|
|
397
|
+
* the audit log (#162).
|
|
398
|
+
*
|
|
399
|
+
* Closes issue #798.
|
|
400
|
+
*/
|
|
401
|
+
interface ForgettableMemory {
|
|
402
|
+
/**
|
|
403
|
+
* Backend identifier (`'pgvector'`, `'pinecone'`, `'sqlite'`, etc.).
|
|
404
|
+
* Used for the audit-log entry and for the per-backend report.
|
|
405
|
+
*/
|
|
406
|
+
__agentskitBackend: string;
|
|
407
|
+
/** Delete every record where `metadata.subjectId === subjectId`. */
|
|
408
|
+
forgetSubject: (subjectId: string) => Promise<ForgetReport>;
|
|
409
|
+
}
|
|
410
|
+
interface ForgetReport {
|
|
411
|
+
backend: string;
|
|
412
|
+
deletedCount: number;
|
|
413
|
+
/** ISO timestamp of the deletion. */
|
|
414
|
+
at: string;
|
|
415
|
+
/** Records the deletion couldn't reach (offline replica, missing index). */
|
|
416
|
+
failures?: Array<{
|
|
417
|
+
id: string;
|
|
418
|
+
reason: string;
|
|
419
|
+
}>;
|
|
420
|
+
}
|
|
421
|
+
interface ForgetSubjectResult {
|
|
422
|
+
subjectId: string;
|
|
423
|
+
reports: ForgetReport[];
|
|
424
|
+
totalDeleted: number;
|
|
425
|
+
/** Hash you can sign into the audit log to prove the deletion ran. */
|
|
426
|
+
evidenceHash: string;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Walk every memory passed in and run `forgetSubject(subjectId)` on
|
|
430
|
+
* any that implement it. Memories that don't implement it are
|
|
431
|
+
* silently skipped — they hold no subject-scoped data, or you must
|
|
432
|
+
* delete out-of-band (e.g. log retention).
|
|
433
|
+
*/
|
|
434
|
+
declare function forgetSubject(memories: Array<ChatMemory | VectorMemory | unknown>, subjectId: string): Promise<ForgetSubjectResult>;
|
|
435
|
+
/**
|
|
436
|
+
* Helper for backends that key records by `metadata.subjectId`. Wraps
|
|
437
|
+
* any `delete(ids)`-style API into a `ForgettableMemory`.
|
|
438
|
+
*/
|
|
439
|
+
declare function makeForgettable<M extends object>(memory: M, options: {
|
|
440
|
+
backend: string;
|
|
441
|
+
listIds: (subjectId: string) => Promise<string[]>;
|
|
442
|
+
deleteIds: (ids: string[]) => Promise<void>;
|
|
443
|
+
}): M & ForgettableMemory;
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Wrap any `ChatMemory` so PII is redacted (or tokenized) on every
|
|
447
|
+
* `save()`. Works with the in-memory, file, sqlite, turso, and redis
|
|
448
|
+
* chat memories. `load()` and `clear()` are passthrough — reveal
|
|
449
|
+
* happens at read time via `@agentskit/core/security` `reveal()`,
|
|
450
|
+
* not inside the memory.
|
|
451
|
+
*
|
|
452
|
+
* `mode: 'redact'` (default) replaces matches with the rules' bracket
|
|
453
|
+
* markers — irreversible. `mode: 'tokenize'` replaces matches with
|
|
454
|
+
* opaque `<<piitoken:…>>` markers and stores originals in the vault
|
|
455
|
+
* so role-gated `reveal()` can recover them.
|
|
456
|
+
*
|
|
457
|
+
* Closes the memory-write half of issue #791.
|
|
458
|
+
*/
|
|
459
|
+
type RedactionMode = 'redact' | 'tokenize';
|
|
460
|
+
interface ChatMemoryRedactionOptions {
|
|
461
|
+
/**
|
|
462
|
+
* Rules to apply. Pass `DEFAULT_PII_RULES` for the baseline set,
|
|
463
|
+
* `compilePIITaxonomy(json)` for a custom JSON taxonomy, or any
|
|
464
|
+
* hand-rolled `PIIRule[]`. Same shape as `createPIIRedactor`.
|
|
465
|
+
*/
|
|
466
|
+
rules: PIIRule[];
|
|
467
|
+
mode?: RedactionMode;
|
|
468
|
+
/** Required when `mode === 'tokenize'`. */
|
|
469
|
+
vault?: RedactionVault;
|
|
470
|
+
/** Roles allowed to reveal — required when `mode === 'tokenize'`. */
|
|
471
|
+
allowedRoles?: string[];
|
|
472
|
+
/** Optional audit sink threaded into the vault `tokenize()` calls. */
|
|
473
|
+
audit?: RedactionAuditSink;
|
|
474
|
+
}
|
|
475
|
+
interface VectorMemoryRedactionOptions extends ChatMemoryRedactionOptions {
|
|
476
|
+
}
|
|
477
|
+
declare function wrapChatMemoryWithRedaction(inner: ChatMemory, options: ChatMemoryRedactionOptions): ChatMemory;
|
|
478
|
+
/**
|
|
479
|
+
* Wrap any `VectorMemory` so each document's `content` is redacted (or
|
|
480
|
+
* tokenized) before `store()`. `search()` and `delete()` pass through.
|
|
481
|
+
*
|
|
482
|
+
* Note: embeddings pass through verbatim. Customers who embed
|
|
483
|
+
* plaintext PII separately (e.g. via a hosted embedding provider)
|
|
484
|
+
* must redact the input to their embedder, not just to this wrapper.
|
|
485
|
+
*/
|
|
486
|
+
declare function wrapVectorMemoryWithRedaction(inner: VectorMemory, options: VectorMemoryRedactionOptions): VectorMemory;
|
|
487
|
+
|
|
488
|
+
/** Minimal KV store contract. */
|
|
489
|
+
interface AgentskitMemoryStore {
|
|
490
|
+
readonly id: string | undefined;
|
|
491
|
+
get(key: string): Promise<unknown>;
|
|
492
|
+
set(key: string, value: unknown): Promise<void>;
|
|
493
|
+
}
|
|
494
|
+
interface KvEntry {
|
|
495
|
+
readonly value: unknown;
|
|
496
|
+
readonly insertedAt: number;
|
|
497
|
+
}
|
|
498
|
+
interface CommonKvConfig {
|
|
499
|
+
readonly maxMessages?: number;
|
|
500
|
+
readonly ttlSeconds?: number;
|
|
501
|
+
}
|
|
502
|
+
interface InMemoryKvConfig extends CommonKvConfig {
|
|
503
|
+
readonly backend: 'in-memory';
|
|
504
|
+
}
|
|
505
|
+
interface FileKvConfig extends CommonKvConfig {
|
|
506
|
+
readonly backend: 'file';
|
|
507
|
+
readonly path: string;
|
|
508
|
+
}
|
|
509
|
+
interface SqliteKvConfig extends CommonKvConfig {
|
|
510
|
+
readonly backend: 'sqlite';
|
|
511
|
+
readonly path: string;
|
|
512
|
+
}
|
|
513
|
+
interface RedisKvConfig extends CommonKvConfig {
|
|
514
|
+
readonly backend: 'redis';
|
|
515
|
+
readonly url: string;
|
|
516
|
+
readonly prefix: string;
|
|
517
|
+
}
|
|
518
|
+
interface VectorKvConfig extends CommonKvConfig {
|
|
519
|
+
readonly backend: 'vector';
|
|
520
|
+
readonly provider: string;
|
|
521
|
+
readonly collection: string;
|
|
522
|
+
}
|
|
523
|
+
interface LocalStorageKvConfig extends CommonKvConfig {
|
|
524
|
+
readonly backend: 'localstorage';
|
|
525
|
+
readonly key: string;
|
|
526
|
+
}
|
|
527
|
+
type KvMemoryConfig = InMemoryKvConfig | FileKvConfig | SqliteKvConfig | RedisKvConfig | VectorKvConfig | LocalStorageKvConfig;
|
|
528
|
+
interface RedisLike {
|
|
529
|
+
get(key: string): Promise<string | null>;
|
|
530
|
+
set(key: string, value: string, options?: {
|
|
531
|
+
readonly EX?: number;
|
|
532
|
+
}): Promise<unknown>;
|
|
533
|
+
del(key: string): Promise<unknown>;
|
|
534
|
+
keys(pattern: string): Promise<readonly string[]>;
|
|
535
|
+
}
|
|
536
|
+
interface SqliteStmt {
|
|
537
|
+
run(...params: unknown[]): void;
|
|
538
|
+
get(...params: unknown[]): unknown;
|
|
539
|
+
all(...params: unknown[]): unknown[];
|
|
540
|
+
}
|
|
541
|
+
interface SqliteLike {
|
|
542
|
+
exec(sql: string): void;
|
|
543
|
+
prepare(sql: string): SqliteStmt;
|
|
544
|
+
}
|
|
545
|
+
type SqliteOpener = (path: string) => SqliteLike;
|
|
546
|
+
interface MemoryVectorStoreLike {
|
|
547
|
+
upsert(rows: readonly {
|
|
548
|
+
readonly chunkId: string;
|
|
549
|
+
readonly vec: readonly number[];
|
|
550
|
+
readonly metadata: Record<string, unknown>;
|
|
551
|
+
}[]): Promise<void>;
|
|
552
|
+
query(vec: readonly number[], k: number, filter?: Record<string, unknown>): Promise<readonly {
|
|
553
|
+
readonly chunkId: string;
|
|
554
|
+
readonly score: number;
|
|
555
|
+
readonly metadata: Record<string, unknown>;
|
|
556
|
+
}[]>;
|
|
557
|
+
}
|
|
558
|
+
interface MemoryEmbedderLike {
|
|
559
|
+
embed(texts: readonly string[]): Promise<number[][]>;
|
|
560
|
+
}
|
|
561
|
+
interface LocalStorageLike {
|
|
562
|
+
getItem(key: string): string | null;
|
|
563
|
+
setItem(key: string, value: string): void;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
declare const createInMemoryStore: (config: InMemoryKvConfig) => AgentskitMemoryStore;
|
|
567
|
+
declare const createFileStore: (config: FileKvConfig) => AgentskitMemoryStore;
|
|
568
|
+
interface CreateLocalStorageStoreOpts {
|
|
569
|
+
readonly config: LocalStorageKvConfig;
|
|
570
|
+
readonly storage?: LocalStorageLike;
|
|
571
|
+
readonly filePath?: string;
|
|
572
|
+
}
|
|
573
|
+
declare const createLocalStorageStore: ({ config, storage, filePath, }: CreateLocalStorageStoreOpts) => AgentskitMemoryStore;
|
|
574
|
+
|
|
575
|
+
interface CreateSqliteStoreOpts {
|
|
576
|
+
readonly config: SqliteKvConfig;
|
|
577
|
+
readonly open: SqliteOpener;
|
|
578
|
+
}
|
|
579
|
+
declare const createSqliteStore: ({ config, open }: CreateSqliteStoreOpts) => AgentskitMemoryStore;
|
|
580
|
+
/**
|
|
581
|
+
* Lazy-import `better-sqlite3` and return an opener, or `undefined` when the
|
|
582
|
+
* optional peer dep is absent (caller surfaces AK_MEMORY_PEER_MISSING).
|
|
583
|
+
*/
|
|
584
|
+
declare const tryDefaultSqliteOpener: () => Promise<SqliteOpener | undefined>;
|
|
585
|
+
|
|
586
|
+
interface CreateRedisStoreOpts {
|
|
587
|
+
readonly config: RedisKvConfig;
|
|
588
|
+
readonly client: RedisLike;
|
|
589
|
+
}
|
|
590
|
+
declare const createRedisStore: ({ config, client }: CreateRedisStoreOpts) => AgentskitMemoryStore;
|
|
591
|
+
/** Bridge an `ioredis`-style client to the {@link RedisLike} options-object shape. */
|
|
592
|
+
declare const adaptIoredis: (io: {
|
|
593
|
+
get(key: string): Promise<string | null>;
|
|
594
|
+
set(key: string, value: string, mode?: string, ttl?: number): Promise<unknown>;
|
|
595
|
+
del(key: string): Promise<unknown>;
|
|
596
|
+
keys(pattern: string): Promise<string[]>;
|
|
597
|
+
}) => RedisLike;
|
|
598
|
+
/** Lazy-import `redis` (node-redis v4), connect, and return a client; `undefined` if absent. */
|
|
599
|
+
declare const tryDefaultRedisClient: (url: string) => Promise<RedisLike | undefined>;
|
|
600
|
+
|
|
601
|
+
interface CreateVectorStoreOpts {
|
|
602
|
+
readonly config: VectorKvConfig;
|
|
603
|
+
readonly vectorStore: MemoryVectorStoreLike;
|
|
604
|
+
readonly embedder: MemoryEmbedderLike;
|
|
605
|
+
}
|
|
606
|
+
declare const createVectorStore: ({ config, vectorStore, embedder, }: CreateVectorStoreOpts) => AgentskitMemoryStore & {
|
|
607
|
+
recall(query: string, k?: number): Promise<readonly unknown[]>;
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
declare class MemoryBackendNotImplementedError extends Error {
|
|
611
|
+
readonly code = "MEMORY_BACKEND_NOT_IMPLEMENTED";
|
|
612
|
+
readonly backend: KvMemoryConfig['backend'];
|
|
613
|
+
constructor(backend: KvMemoryConfig['backend']);
|
|
614
|
+
}
|
|
615
|
+
type MemoryBackendStatus = 'supported' | 'planned';
|
|
616
|
+
declare const MEMORY_BACKEND_SUPPORT: Readonly<Record<KvMemoryConfig['backend'], MemoryBackendStatus>>;
|
|
617
|
+
declare const isMemoryBackendSupported: (backend: KvMemoryConfig["backend"]) => boolean;
|
|
618
|
+
interface CreateKvMemoryFromConfigOpts {
|
|
619
|
+
readonly config: KvMemoryConfig;
|
|
620
|
+
readonly sqlite?: SqliteOpener;
|
|
621
|
+
readonly localStorageFilePath?: string;
|
|
622
|
+
readonly redis?: RedisLike;
|
|
623
|
+
readonly vectorStore?: MemoryVectorStoreLike;
|
|
624
|
+
readonly embedder?: MemoryEmbedderLike;
|
|
625
|
+
}
|
|
626
|
+
declare const createKvMemoryFromConfig: ({ config, sqlite, localStorageFilePath, redis, vectorStore, embedder, }: CreateKvMemoryFromConfigOpts) => AgentskitMemoryStore;
|
|
627
|
+
declare const createKvMemoryFromConfigAuto: (config: KvMemoryConfig) => Promise<AgentskitMemoryStore>;
|
|
628
|
+
|
|
629
|
+
export { type AgentskitMemoryStore, type ChatMemoryRedactionOptions, type ChromaConfig, type CreateKvMemoryFromConfigOpts, type CreateLocalStorageStoreOpts, type CreateRedisStoreOpts, type CreateSqliteStoreOpts, type CreateVectorStoreOpts, type EncryptedEnvelope, type EncryptedMemoryOptions, type FileKvConfig, type FileVectorMemoryConfig, type ForgetReport, type ForgetSubjectResult, type ForgettableMemory, type GraphEdge, type GraphMemory, type GraphNode, type GraphQuery, type HierarchicalMemory, type HierarchicalMemoryOptions, type HierarchicalRecall, type InMemoryKvConfig, type KvEntry, type KvMemoryConfig, type LocalStorageKvConfig, type LocalStorageLike, MEMORY_BACKEND_SUPPORT, MemoryBackendNotImplementedError, type MemoryBackendStatus, type MemoryEmbedderLike, type MemoryVectorStoreLike, type MilvusConfig, type MongoAtlasVectorConfig, type MongoCollectionLike, type PgVectorConfig, type PgVectorRunner, type PineconeConfig, type QdrantConfig, type RedactionMode, type RedisChatMemoryConfig, type RedisClientAdapter, type RedisConnectionConfig, type RedisKvConfig, type RedisLike, type RedisVectorMemoryConfig, type SqliteChatMemoryConfig, type SqliteKvConfig, type SqliteLike, type SqliteOpener, type SqliteStmt, type SupabaseVectorStoreConfig, type TursoChatMemoryConfig, type UpstashVectorConfig, type VectorKvConfig, type VectorMemoryRedactionOptions, type VectorStore, type VectorStoreDocument, type VectorStoreResult, type WeaviateConfig, adaptIoredis, chroma, createEncryptedMemory, createFileStore, createHierarchicalMemory, createInMemoryGraph, createInMemoryStore, createKvMemoryFromConfig, createKvMemoryFromConfigAuto, createLocalStorageStore, createRedisStore, createSqliteStore, createVectorStore, fileChatMemory, fileVectorMemory, forgetSubject, isMemoryBackendSupported, makeForgettable, matchesFilter, milvusVectorStore, mongoAtlasVectorStore, pgvector, pinecone, qdrant, redisChatMemory, redisVectorMemory, sqliteChatMemory, supabaseVectorStore, tryDefaultRedisClient, tryDefaultSqliteOpener, tursoChatMemory, upstashVector, weaviateVectorStore, wrapChatMemoryWithRedaction, wrapVectorMemoryWithRedaction };
|