@agentskit/memory 0.9.0 → 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/index.cjs +443 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +142 -1
- package/dist/index.d.ts +142 -1
- package/dist/index.js +430 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -485,4 +485,145 @@ declare function wrapChatMemoryWithRedaction(inner: ChatMemory, options: ChatMem
|
|
|
485
485
|
*/
|
|
486
486
|
declare function wrapVectorMemoryWithRedaction(inner: VectorMemory, options: VectorMemoryRedactionOptions): VectorMemory;
|
|
487
487
|
|
|
488
|
-
|
|
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
|
@@ -485,4 +485,145 @@ declare function wrapChatMemoryWithRedaction(inner: ChatMemory, options: ChatMem
|
|
|
485
485
|
*/
|
|
486
486
|
declare function wrapVectorMemoryWithRedaction(inner: VectorMemory, options: VectorMemoryRedactionOptions): VectorMemory;
|
|
487
487
|
|
|
488
|
-
|
|
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 };
|