@kuralle-agents/redis-store 0.5.0 → 0.6.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/README.md +20 -0
- package/dist/RedisPersistentMemoryStore.d.ts +17 -0
- package/dist/RedisPersistentMemoryStore.js +51 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ Three backend implementations — sessions, long-term memory, and vector search
|
|
|
18
18
|
|
|
19
19
|
- **`RedisSessionStore`** — `SessionStore` implementation for durable session persistence.
|
|
20
20
|
- **`RedisMemoryService`** — `MemoryService` implementation for cross-session long-term memory.
|
|
21
|
+
- **`RedisPersistentMemoryStore`** — `PersistentMemoryStore` for durable USER/MEMORY markdown blocks.
|
|
21
22
|
- **`RedisVectorStore`** — `VectorStoreCore` implementation for vector similarity search.
|
|
22
23
|
- **`fromUpstash` / `fromNodeRedis` / `fromIORedis`** — client adapters.
|
|
23
24
|
|
|
@@ -92,6 +93,25 @@ const runtime = createRuntime({
|
|
|
92
93
|
});
|
|
93
94
|
```
|
|
94
95
|
|
|
96
|
+
## Working memory blocks
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { createRuntime } from '@kuralle-agents/core';
|
|
100
|
+
import { RedisPersistentMemoryStore, fromUpstash } from '@kuralle-agents/redis-store';
|
|
101
|
+
import { Redis } from '@upstash/redis';
|
|
102
|
+
|
|
103
|
+
const client = Redis.fromEnv();
|
|
104
|
+
const workingMemoryStore = new RedisPersistentMemoryStore({ client, prefix: 'kuralle' });
|
|
105
|
+
|
|
106
|
+
const runtime = createRuntime({
|
|
107
|
+
agents: [agent],
|
|
108
|
+
defaultAgentId: 'support',
|
|
109
|
+
defaultWorkingMemoryStore: workingMemoryStore,
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
On Cloudflare Workers, use `fromUpstash` with the REST client — no TCP socket required.
|
|
114
|
+
|
|
95
115
|
## Related
|
|
96
116
|
|
|
97
117
|
- [`@kuralle-agents/core`](https://www.npmjs.com/package/@kuralle-agents/core) — `SessionStore` interface and runtime.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MemoryBlockScope, PersistentMemoryBlock, PersistentMemoryStore } from '@kuralle-agents/core';
|
|
2
|
+
import type { RedisClientLike } from './RedisSessionStore.js';
|
|
3
|
+
export type RedisPersistentMemoryStoreOptions = {
|
|
4
|
+
client: RedisClientLike;
|
|
5
|
+
prefix?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class RedisPersistentMemoryStore implements PersistentMemoryStore {
|
|
8
|
+
private client;
|
|
9
|
+
private prefix;
|
|
10
|
+
constructor(options: RedisPersistentMemoryStoreOptions);
|
|
11
|
+
private blockKey;
|
|
12
|
+
private indexKey;
|
|
13
|
+
loadBlock(scope: MemoryBlockScope, owner: string, key: string): Promise<PersistentMemoryBlock | null>;
|
|
14
|
+
saveBlock(block: PersistentMemoryBlock, owner: string): Promise<void>;
|
|
15
|
+
deleteBlock(scope: MemoryBlockScope, owner: string, key: string): Promise<void>;
|
|
16
|
+
listBlocks(scope: MemoryBlockScope, owner: string): Promise<string[]>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { addMembers, callCommand, getMembers, removeMembers, } from './redisHelpers.js';
|
|
2
|
+
export class RedisPersistentMemoryStore {
|
|
3
|
+
client;
|
|
4
|
+
prefix;
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.client = options.client;
|
|
7
|
+
this.prefix = options.prefix ?? 'kuralle';
|
|
8
|
+
}
|
|
9
|
+
blockKey(scope, owner, key) {
|
|
10
|
+
return `${this.prefix}:wm:${scope}:${owner}:${key}`;
|
|
11
|
+
}
|
|
12
|
+
indexKey(scope, owner) {
|
|
13
|
+
return `${this.prefix}:wm:${scope}:${owner}:__index`;
|
|
14
|
+
}
|
|
15
|
+
async loadBlock(scope, owner, key) {
|
|
16
|
+
const raw = await callCommand(this.client, ['get'], this.blockKey(scope, owner, key));
|
|
17
|
+
if (!raw) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const parsed = JSON.parse(raw);
|
|
22
|
+
return {
|
|
23
|
+
key,
|
|
24
|
+
scope,
|
|
25
|
+
content: parsed.content,
|
|
26
|
+
charLimit: parsed.charLimit,
|
|
27
|
+
updatedAt: parsed.updatedAt,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async saveBlock(block, owner) {
|
|
35
|
+
const payload = {
|
|
36
|
+
...block,
|
|
37
|
+
updatedAt: block.updatedAt ?? new Date().toISOString(),
|
|
38
|
+
};
|
|
39
|
+
const redisKey = this.blockKey(block.scope, owner, block.key);
|
|
40
|
+
await callCommand(this.client, ['set'], redisKey, JSON.stringify(payload));
|
|
41
|
+
await addMembers(this.client, this.indexKey(block.scope, owner), block.key);
|
|
42
|
+
}
|
|
43
|
+
async deleteBlock(scope, owner, key) {
|
|
44
|
+
await callCommand(this.client, ['del'], this.blockKey(scope, owner, key));
|
|
45
|
+
await removeMembers(this.client, this.indexKey(scope, owner), key);
|
|
46
|
+
}
|
|
47
|
+
async listBlocks(scope, owner) {
|
|
48
|
+
const keys = await getMembers(this.client, this.indexKey(scope, owner));
|
|
49
|
+
return keys.sort();
|
|
50
|
+
}
|
|
51
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { RedisSessionStore } from './RedisSessionStore.js';
|
|
|
2
2
|
export type { RedisClientLike, RedisStoreOptions } from './RedisSessionStore.js';
|
|
3
3
|
export { RedisMemoryService } from './RedisMemoryService.js';
|
|
4
4
|
export type { RedisMemoryStoreOptions } from './RedisMemoryService.js';
|
|
5
|
+
export { RedisPersistentMemoryStore } from './RedisPersistentMemoryStore.js';
|
|
6
|
+
export type { RedisPersistentMemoryStoreOptions } from './RedisPersistentMemoryStore.js';
|
|
5
7
|
export { fromUpstash, fromNodeRedis, fromIORedis } from './adapters.js';
|
|
6
8
|
export type { RedisAdapterOptions } from './adapters.js';
|
|
7
9
|
export { RedisVectorStore } from './RedisVectorStore.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { RedisSessionStore } from './RedisSessionStore.js';
|
|
2
2
|
export { RedisMemoryService } from './RedisMemoryService.js';
|
|
3
|
+
export { RedisPersistentMemoryStore } from './RedisPersistentMemoryStore.js';
|
|
3
4
|
export { fromUpstash, fromNodeRedis, fromIORedis } from './adapters.js';
|
|
4
5
|
export { RedisVectorStore } from './RedisVectorStore.js';
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"url": "git+https://github.com/kuralle/kuralle-agents.git",
|
|
7
7
|
"directory": "packages/kuralle-redis-store"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.6.0",
|
|
10
10
|
"description": "Redis-backed SessionStore for Kuralle (supports Upstash and common Redis clients)",
|
|
11
11
|
"type": "module",
|
|
12
12
|
"main": "dist/index.js",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@kuralle-agents/core": "0.
|
|
21
|
+
"@kuralle-agents/core": "0.6.0"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@kuralle-agents/core": "0.
|
|
25
|
-
"@kuralle-agents/rag": "0.
|
|
24
|
+
"@kuralle-agents/core": "0.6.0",
|
|
25
|
+
"@kuralle-agents/rag": "0.6.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@ai-sdk/openai": "^3.0.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"tsx": "^4.7.0",
|
|
34
34
|
"typescript": "^5.3.0",
|
|
35
35
|
"zod": "^3.22.0",
|
|
36
|
-
"@kuralle-agents/rag": "0.
|
|
36
|
+
"@kuralle-agents/rag": "0.6.0"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|