@agentskit/memory 0.8.1 → 0.9.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/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,106 @@ interface HierarchicalMemory extends ChatMemory {
412
383
  */
413
384
  declare function createHierarchicalMemory(options: HierarchicalMemoryOptions): HierarchicalMemory;
414
385
 
415
- export { type ChromaConfig, type EncryptedEnvelope, type EncryptedMemoryOptions, type FileVectorMemoryConfig, type GraphEdge, type GraphMemory, type GraphNode, type GraphQuery, type HierarchicalMemory, type HierarchicalMemoryOptions, type HierarchicalRecall, type MilvusConfig, type MongoAtlasVectorConfig, type MongoCollectionLike, type PersonalizationProfile, type PersonalizationStore, type PgVectorConfig, type PgVectorRunner, type PineconeConfig, type QdrantConfig, type RedisChatMemoryConfig, type RedisClientAdapter, type RedisConnectionConfig, type RedisVectorMemoryConfig, type SqliteChatMemoryConfig, type SupabaseVectorStoreConfig, type TursoChatMemoryConfig, type UpstashVectorConfig, type VectorStore, type VectorStoreDocument, type VectorStoreResult, type WeaviateConfig, chroma, createEncryptedMemory, createHierarchicalMemory, createInMemoryGraph, createInMemoryPersonalization, fileChatMemory, fileVectorMemory, matchesFilter, milvusVectorStore, mongoAtlasVectorStore, pgvector, pinecone, qdrant, redisChatMemory, redisVectorMemory, renderProfileContext, sqliteChatMemory, supabaseVectorStore, tursoChatMemory, upstashVector, weaviateVectorStore };
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
+ export { type ChatMemoryRedactionOptions, type ChromaConfig, type EncryptedEnvelope, type EncryptedMemoryOptions, type FileVectorMemoryConfig, type ForgetReport, type ForgetSubjectResult, type ForgettableMemory, type GraphEdge, type GraphMemory, type GraphNode, type GraphQuery, type HierarchicalMemory, type HierarchicalMemoryOptions, type HierarchicalRecall, type MilvusConfig, type MongoAtlasVectorConfig, type MongoCollectionLike, type PgVectorConfig, type PgVectorRunner, type PineconeConfig, type QdrantConfig, type RedactionMode, type RedisChatMemoryConfig, type RedisClientAdapter, type RedisConnectionConfig, type RedisVectorMemoryConfig, type SqliteChatMemoryConfig, type SupabaseVectorStoreConfig, type TursoChatMemoryConfig, type UpstashVectorConfig, type VectorMemoryRedactionOptions, type VectorStore, type VectorStoreDocument, type VectorStoreResult, type WeaviateConfig, chroma, createEncryptedMemory, createHierarchicalMemory, createInMemoryGraph, fileChatMemory, fileVectorMemory, forgetSubject, makeForgettable, matchesFilter, milvusVectorStore, mongoAtlasVectorStore, pgvector, pinecone, qdrant, redisChatMemory, redisVectorMemory, sqliteChatMemory, supabaseVectorStore, 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,106 @@ interface HierarchicalMemory extends ChatMemory {
412
383
  */
413
384
  declare function createHierarchicalMemory(options: HierarchicalMemoryOptions): HierarchicalMemory;
414
385
 
415
- export { type ChromaConfig, type EncryptedEnvelope, type EncryptedMemoryOptions, type FileVectorMemoryConfig, type GraphEdge, type GraphMemory, type GraphNode, type GraphQuery, type HierarchicalMemory, type HierarchicalMemoryOptions, type HierarchicalRecall, type MilvusConfig, type MongoAtlasVectorConfig, type MongoCollectionLike, type PersonalizationProfile, type PersonalizationStore, type PgVectorConfig, type PgVectorRunner, type PineconeConfig, type QdrantConfig, type RedisChatMemoryConfig, type RedisClientAdapter, type RedisConnectionConfig, type RedisVectorMemoryConfig, type SqliteChatMemoryConfig, type SupabaseVectorStoreConfig, type TursoChatMemoryConfig, type UpstashVectorConfig, type VectorStore, type VectorStoreDocument, type VectorStoreResult, type WeaviateConfig, chroma, createEncryptedMemory, createHierarchicalMemory, createInMemoryGraph, createInMemoryPersonalization, fileChatMemory, fileVectorMemory, matchesFilter, milvusVectorStore, mongoAtlasVectorStore, pgvector, pinecone, qdrant, redisChatMemory, redisVectorMemory, renderProfileContext, sqliteChatMemory, supabaseVectorStore, tursoChatMemory, upstashVector, weaviateVectorStore };
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
+ export { type ChatMemoryRedactionOptions, type ChromaConfig, type EncryptedEnvelope, type EncryptedMemoryOptions, type FileVectorMemoryConfig, type ForgetReport, type ForgetSubjectResult, type ForgettableMemory, type GraphEdge, type GraphMemory, type GraphNode, type GraphQuery, type HierarchicalMemory, type HierarchicalMemoryOptions, type HierarchicalRecall, type MilvusConfig, type MongoAtlasVectorConfig, type MongoCollectionLike, type PgVectorConfig, type PgVectorRunner, type PineconeConfig, type QdrantConfig, type RedactionMode, type RedisChatMemoryConfig, type RedisClientAdapter, type RedisConnectionConfig, type RedisVectorMemoryConfig, type SqliteChatMemoryConfig, type SupabaseVectorStoreConfig, type TursoChatMemoryConfig, type UpstashVectorConfig, type VectorMemoryRedactionOptions, type VectorStore, type VectorStoreDocument, type VectorStoreResult, type WeaviateConfig, chroma, createEncryptedMemory, createHierarchicalMemory, createInMemoryGraph, fileChatMemory, fileVectorMemory, forgetSubject, makeForgettable, matchesFilter, milvusVectorStore, mongoAtlasVectorStore, pgvector, pinecone, qdrant, redisChatMemory, redisVectorMemory, sqliteChatMemory, supabaseVectorStore, tursoChatMemory, upstashVector, weaviateVectorStore, wrapChatMemoryWithRedaction, wrapVectorMemoryWithRedaction };