praisonai 1.2.1 → 1.2.2
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/cache/index.d.ts +78 -0
- package/dist/cache/index.js +235 -0
- package/dist/db/postgres.d.ts +84 -0
- package/dist/db/postgres.js +266 -0
- package/dist/db/redis.d.ts +109 -0
- package/dist/db/redis.js +307 -0
- package/dist/db/sqlite.d.ts +66 -0
- package/dist/db/sqlite.js +339 -0
- package/dist/events/index.d.ts +84 -0
- package/dist/events/index.js +153 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +84 -1
- package/dist/integrations/index.d.ts +7 -0
- package/dist/integrations/index.js +26 -0
- package/dist/integrations/observability/base.d.ts +123 -0
- package/dist/integrations/observability/base.js +183 -0
- package/dist/integrations/observability/index.d.ts +8 -0
- package/dist/integrations/observability/index.js +29 -0
- package/dist/integrations/observability/langfuse.d.ts +32 -0
- package/dist/integrations/observability/langfuse.js +174 -0
- package/dist/integrations/vector/base.d.ts +110 -0
- package/dist/integrations/vector/base.js +158 -0
- package/dist/integrations/vector/chroma.d.ts +25 -0
- package/dist/integrations/vector/chroma.js +143 -0
- package/dist/integrations/vector/index.d.ts +14 -0
- package/dist/integrations/vector/index.js +37 -0
- package/dist/integrations/vector/pinecone.d.ts +28 -0
- package/dist/integrations/vector/pinecone.js +172 -0
- package/dist/integrations/vector/qdrant.d.ts +25 -0
- package/dist/integrations/vector/qdrant.js +146 -0
- package/dist/integrations/vector/weaviate.d.ts +30 -0
- package/dist/integrations/vector/weaviate.js +206 -0
- package/dist/integrations/voice/base.d.ts +76 -0
- package/dist/integrations/voice/base.js +168 -0
- package/dist/integrations/voice/index.d.ts +6 -0
- package/dist/integrations/voice/index.js +26 -0
- package/dist/knowledge/graph-rag.d.ts +125 -0
- package/dist/knowledge/graph-rag.js +289 -0
- package/dist/knowledge/index.d.ts +2 -0
- package/dist/knowledge/index.js +18 -0
- package/dist/knowledge/reranker.d.ts +86 -0
- package/dist/knowledge/reranker.js +196 -0
- package/dist/workflows/yaml-parser.d.ts +48 -0
- package/dist/workflows/yaml-parser.js +304 -0
- package/package.json +1 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redis Database Adapter
|
|
3
|
+
* For session state, caching, and pub/sub
|
|
4
|
+
*/
|
|
5
|
+
export interface RedisConfig {
|
|
6
|
+
url?: string;
|
|
7
|
+
host?: string;
|
|
8
|
+
port?: number;
|
|
9
|
+
password?: string;
|
|
10
|
+
db?: number;
|
|
11
|
+
keyPrefix?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface RedisAdapter {
|
|
14
|
+
get<T = any>(key: string): Promise<T | null>;
|
|
15
|
+
set<T = any>(key: string, value: T, ttl?: number): Promise<void>;
|
|
16
|
+
delete(key: string): Promise<boolean>;
|
|
17
|
+
exists(key: string): Promise<boolean>;
|
|
18
|
+
keys(pattern: string): Promise<string[]>;
|
|
19
|
+
expire(key: string, seconds: number): Promise<boolean>;
|
|
20
|
+
ttl(key: string): Promise<number>;
|
|
21
|
+
hget<T = any>(key: string, field: string): Promise<T | null>;
|
|
22
|
+
hset<T = any>(key: string, field: string, value: T): Promise<void>;
|
|
23
|
+
hgetall<T = any>(key: string): Promise<Record<string, T>>;
|
|
24
|
+
hdel(key: string, ...fields: string[]): Promise<number>;
|
|
25
|
+
lpush<T = any>(key: string, ...values: T[]): Promise<number>;
|
|
26
|
+
rpush<T = any>(key: string, ...values: T[]): Promise<number>;
|
|
27
|
+
lrange<T = any>(key: string, start: number, stop: number): Promise<T[]>;
|
|
28
|
+
llen(key: string): Promise<number>;
|
|
29
|
+
publish(channel: string, message: string): Promise<number>;
|
|
30
|
+
subscribe(channel: string, callback: (message: string) => void): Promise<void>;
|
|
31
|
+
unsubscribe(channel: string): Promise<void>;
|
|
32
|
+
connect(): Promise<void>;
|
|
33
|
+
disconnect(): Promise<void>;
|
|
34
|
+
isConnected(): boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Redis Adapter using native fetch (for Upstash REST API)
|
|
38
|
+
*/
|
|
39
|
+
export declare class UpstashRedisAdapter implements RedisAdapter {
|
|
40
|
+
private url;
|
|
41
|
+
private token;
|
|
42
|
+
private keyPrefix;
|
|
43
|
+
private connected;
|
|
44
|
+
constructor(config: {
|
|
45
|
+
url: string;
|
|
46
|
+
token: string;
|
|
47
|
+
keyPrefix?: string;
|
|
48
|
+
});
|
|
49
|
+
private prefixKey;
|
|
50
|
+
private request;
|
|
51
|
+
get<T = any>(key: string): Promise<T | null>;
|
|
52
|
+
set<T = any>(key: string, value: T, ttl?: number): Promise<void>;
|
|
53
|
+
delete(key: string): Promise<boolean>;
|
|
54
|
+
exists(key: string): Promise<boolean>;
|
|
55
|
+
keys(pattern: string): Promise<string[]>;
|
|
56
|
+
expire(key: string, seconds: number): Promise<boolean>;
|
|
57
|
+
ttl(key: string): Promise<number>;
|
|
58
|
+
hget<T = any>(key: string, field: string): Promise<T | null>;
|
|
59
|
+
hset<T = any>(key: string, field: string, value: T): Promise<void>;
|
|
60
|
+
hgetall<T = any>(key: string): Promise<Record<string, T>>;
|
|
61
|
+
hdel(key: string, ...fields: string[]): Promise<number>;
|
|
62
|
+
lpush<T = any>(key: string, ...values: T[]): Promise<number>;
|
|
63
|
+
rpush<T = any>(key: string, ...values: T[]): Promise<number>;
|
|
64
|
+
lrange<T = any>(key: string, start: number, stop: number): Promise<T[]>;
|
|
65
|
+
llen(key: string): Promise<number>;
|
|
66
|
+
publish(channel: string, message: string): Promise<number>;
|
|
67
|
+
subscribe(_channel: string, _callback: (message: string) => void): Promise<void>;
|
|
68
|
+
unsubscribe(_channel: string): Promise<void>;
|
|
69
|
+
connect(): Promise<void>;
|
|
70
|
+
disconnect(): Promise<void>;
|
|
71
|
+
isConnected(): boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* In-memory Redis-like adapter for testing
|
|
75
|
+
*/
|
|
76
|
+
export declare class MemoryRedisAdapter implements RedisAdapter {
|
|
77
|
+
private store;
|
|
78
|
+
private hashes;
|
|
79
|
+
private lists;
|
|
80
|
+
private subscribers;
|
|
81
|
+
private connected;
|
|
82
|
+
get<T = any>(key: string): Promise<T | null>;
|
|
83
|
+
set<T = any>(key: string, value: T, ttl?: number): Promise<void>;
|
|
84
|
+
delete(key: string): Promise<boolean>;
|
|
85
|
+
exists(key: string): Promise<boolean>;
|
|
86
|
+
keys(pattern: string): Promise<string[]>;
|
|
87
|
+
expire(key: string, seconds: number): Promise<boolean>;
|
|
88
|
+
ttl(key: string): Promise<number>;
|
|
89
|
+
hget<T = any>(key: string, field: string): Promise<T | null>;
|
|
90
|
+
hset<T = any>(key: string, field: string, value: T): Promise<void>;
|
|
91
|
+
hgetall<T = any>(key: string): Promise<Record<string, T>>;
|
|
92
|
+
hdel(key: string, ...fields: string[]): Promise<number>;
|
|
93
|
+
lpush<T = any>(key: string, ...values: T[]): Promise<number>;
|
|
94
|
+
rpush<T = any>(key: string, ...values: T[]): Promise<number>;
|
|
95
|
+
lrange<T = any>(key: string, start: number, stop: number): Promise<T[]>;
|
|
96
|
+
llen(key: string): Promise<number>;
|
|
97
|
+
publish(channel: string, message: string): Promise<number>;
|
|
98
|
+
subscribe(channel: string, callback: (message: string) => void): Promise<void>;
|
|
99
|
+
unsubscribe(channel: string): Promise<void>;
|
|
100
|
+
connect(): Promise<void>;
|
|
101
|
+
disconnect(): Promise<void>;
|
|
102
|
+
isConnected(): boolean;
|
|
103
|
+
}
|
|
104
|
+
export declare function createUpstashRedis(config: {
|
|
105
|
+
url: string;
|
|
106
|
+
token: string;
|
|
107
|
+
keyPrefix?: string;
|
|
108
|
+
}): UpstashRedisAdapter;
|
|
109
|
+
export declare function createMemoryRedis(): MemoryRedisAdapter;
|
package/dist/db/redis.js
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Redis Database Adapter
|
|
4
|
+
* For session state, caching, and pub/sub
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.MemoryRedisAdapter = exports.UpstashRedisAdapter = void 0;
|
|
8
|
+
exports.createUpstashRedis = createUpstashRedis;
|
|
9
|
+
exports.createMemoryRedis = createMemoryRedis;
|
|
10
|
+
/**
|
|
11
|
+
* Redis Adapter using native fetch (for Upstash REST API)
|
|
12
|
+
*/
|
|
13
|
+
class UpstashRedisAdapter {
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.connected = false;
|
|
16
|
+
this.url = config.url;
|
|
17
|
+
this.token = config.token;
|
|
18
|
+
this.keyPrefix = config.keyPrefix || '';
|
|
19
|
+
}
|
|
20
|
+
prefixKey(key) {
|
|
21
|
+
return this.keyPrefix ? `${this.keyPrefix}:${key}` : key;
|
|
22
|
+
}
|
|
23
|
+
async request(command) {
|
|
24
|
+
const response = await fetch(this.url, {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers: {
|
|
27
|
+
'Authorization': `Bearer ${this.token}`,
|
|
28
|
+
'Content-Type': 'application/json'
|
|
29
|
+
},
|
|
30
|
+
body: JSON.stringify(command)
|
|
31
|
+
});
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
const error = await response.text();
|
|
34
|
+
throw new Error(`Upstash Redis error: ${response.status} - ${error}`);
|
|
35
|
+
}
|
|
36
|
+
const data = await response.json();
|
|
37
|
+
if (data.error) {
|
|
38
|
+
throw new Error(`Redis error: ${data.error}`);
|
|
39
|
+
}
|
|
40
|
+
return data.result;
|
|
41
|
+
}
|
|
42
|
+
async get(key) {
|
|
43
|
+
const result = await this.request(['GET', this.prefixKey(key)]);
|
|
44
|
+
if (result === null)
|
|
45
|
+
return null;
|
|
46
|
+
try {
|
|
47
|
+
return JSON.parse(result);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async set(key, value, ttl) {
|
|
54
|
+
const serialized = typeof value === 'string' ? value : JSON.stringify(value);
|
|
55
|
+
const command = ['SET', this.prefixKey(key), serialized];
|
|
56
|
+
if (ttl) {
|
|
57
|
+
command.push('EX', String(ttl));
|
|
58
|
+
}
|
|
59
|
+
await this.request(command);
|
|
60
|
+
}
|
|
61
|
+
async delete(key) {
|
|
62
|
+
const result = await this.request(['DEL', this.prefixKey(key)]);
|
|
63
|
+
return result > 0;
|
|
64
|
+
}
|
|
65
|
+
async exists(key) {
|
|
66
|
+
const result = await this.request(['EXISTS', this.prefixKey(key)]);
|
|
67
|
+
return result > 0;
|
|
68
|
+
}
|
|
69
|
+
async keys(pattern) {
|
|
70
|
+
const result = await this.request(['KEYS', this.prefixKey(pattern)]);
|
|
71
|
+
return (result || []).map((k) => this.keyPrefix ? k.replace(`${this.keyPrefix}:`, '') : k);
|
|
72
|
+
}
|
|
73
|
+
async expire(key, seconds) {
|
|
74
|
+
const result = await this.request(['EXPIRE', this.prefixKey(key), String(seconds)]);
|
|
75
|
+
return result === 1;
|
|
76
|
+
}
|
|
77
|
+
async ttl(key) {
|
|
78
|
+
return await this.request(['TTL', this.prefixKey(key)]);
|
|
79
|
+
}
|
|
80
|
+
async hget(key, field) {
|
|
81
|
+
const result = await this.request(['HGET', this.prefixKey(key), field]);
|
|
82
|
+
if (result === null)
|
|
83
|
+
return null;
|
|
84
|
+
try {
|
|
85
|
+
return JSON.parse(result);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async hset(key, field, value) {
|
|
92
|
+
const serialized = typeof value === 'string' ? value : JSON.stringify(value);
|
|
93
|
+
await this.request(['HSET', this.prefixKey(key), field, serialized]);
|
|
94
|
+
}
|
|
95
|
+
async hgetall(key) {
|
|
96
|
+
const result = await this.request(['HGETALL', this.prefixKey(key)]);
|
|
97
|
+
if (!result || !Array.isArray(result))
|
|
98
|
+
return {};
|
|
99
|
+
const obj = {};
|
|
100
|
+
for (let i = 0; i < result.length; i += 2) {
|
|
101
|
+
try {
|
|
102
|
+
obj[result[i]] = JSON.parse(result[i + 1]);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
obj[result[i]] = result[i + 1];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return obj;
|
|
109
|
+
}
|
|
110
|
+
async hdel(key, ...fields) {
|
|
111
|
+
return await this.request(['HDEL', this.prefixKey(key), ...fields]);
|
|
112
|
+
}
|
|
113
|
+
async lpush(key, ...values) {
|
|
114
|
+
const serialized = values.map(v => typeof v === 'string' ? v : JSON.stringify(v));
|
|
115
|
+
return await this.request(['LPUSH', this.prefixKey(key), ...serialized]);
|
|
116
|
+
}
|
|
117
|
+
async rpush(key, ...values) {
|
|
118
|
+
const serialized = values.map(v => typeof v === 'string' ? v : JSON.stringify(v));
|
|
119
|
+
return await this.request(['RPUSH', this.prefixKey(key), ...serialized]);
|
|
120
|
+
}
|
|
121
|
+
async lrange(key, start, stop) {
|
|
122
|
+
const result = await this.request(['LRANGE', this.prefixKey(key), String(start), String(stop)]);
|
|
123
|
+
return (result || []).map((item) => {
|
|
124
|
+
try {
|
|
125
|
+
return JSON.parse(item);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return item;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
async llen(key) {
|
|
133
|
+
return await this.request(['LLEN', this.prefixKey(key)]);
|
|
134
|
+
}
|
|
135
|
+
async publish(channel, message) {
|
|
136
|
+
return await this.request(['PUBLISH', channel, message]);
|
|
137
|
+
}
|
|
138
|
+
async subscribe(_channel, _callback) {
|
|
139
|
+
// Upstash REST API doesn't support true pub/sub subscriptions
|
|
140
|
+
throw new Error('Subscribe not supported in REST mode. Use ioredis for pub/sub.');
|
|
141
|
+
}
|
|
142
|
+
async unsubscribe(_channel) {
|
|
143
|
+
throw new Error('Unsubscribe not supported in REST mode.');
|
|
144
|
+
}
|
|
145
|
+
async connect() {
|
|
146
|
+
// Test connection
|
|
147
|
+
await this.request(['PING']);
|
|
148
|
+
this.connected = true;
|
|
149
|
+
}
|
|
150
|
+
async disconnect() {
|
|
151
|
+
this.connected = false;
|
|
152
|
+
}
|
|
153
|
+
isConnected() {
|
|
154
|
+
return this.connected;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.UpstashRedisAdapter = UpstashRedisAdapter;
|
|
158
|
+
/**
|
|
159
|
+
* In-memory Redis-like adapter for testing
|
|
160
|
+
*/
|
|
161
|
+
class MemoryRedisAdapter {
|
|
162
|
+
constructor() {
|
|
163
|
+
this.store = new Map();
|
|
164
|
+
this.hashes = new Map();
|
|
165
|
+
this.lists = new Map();
|
|
166
|
+
this.subscribers = new Map();
|
|
167
|
+
this.connected = false;
|
|
168
|
+
}
|
|
169
|
+
async get(key) {
|
|
170
|
+
const entry = this.store.get(key);
|
|
171
|
+
if (!entry)
|
|
172
|
+
return null;
|
|
173
|
+
if (entry.expiresAt && Date.now() > entry.expiresAt) {
|
|
174
|
+
this.store.delete(key);
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
return entry.value;
|
|
178
|
+
}
|
|
179
|
+
async set(key, value, ttl) {
|
|
180
|
+
this.store.set(key, {
|
|
181
|
+
value,
|
|
182
|
+
expiresAt: ttl ? Date.now() + ttl * 1000 : undefined
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
async delete(key) {
|
|
186
|
+
const existed = this.store.has(key);
|
|
187
|
+
this.store.delete(key);
|
|
188
|
+
this.hashes.delete(key);
|
|
189
|
+
this.lists.delete(key);
|
|
190
|
+
return existed;
|
|
191
|
+
}
|
|
192
|
+
async exists(key) {
|
|
193
|
+
const entry = this.store.get(key);
|
|
194
|
+
if (!entry)
|
|
195
|
+
return false;
|
|
196
|
+
if (entry.expiresAt && Date.now() > entry.expiresAt) {
|
|
197
|
+
this.store.delete(key);
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
async keys(pattern) {
|
|
203
|
+
const regex = new RegExp('^' + pattern.replace(/\*/g, '.*') + '$');
|
|
204
|
+
return Array.from(this.store.keys()).filter(k => regex.test(k));
|
|
205
|
+
}
|
|
206
|
+
async expire(key, seconds) {
|
|
207
|
+
const entry = this.store.get(key);
|
|
208
|
+
if (!entry)
|
|
209
|
+
return false;
|
|
210
|
+
entry.expiresAt = Date.now() + seconds * 1000;
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
async ttl(key) {
|
|
214
|
+
const entry = this.store.get(key);
|
|
215
|
+
if (!entry)
|
|
216
|
+
return -2;
|
|
217
|
+
if (!entry.expiresAt)
|
|
218
|
+
return -1;
|
|
219
|
+
const remaining = Math.ceil((entry.expiresAt - Date.now()) / 1000);
|
|
220
|
+
return remaining > 0 ? remaining : -2;
|
|
221
|
+
}
|
|
222
|
+
async hget(key, field) {
|
|
223
|
+
return this.hashes.get(key)?.get(field) ?? null;
|
|
224
|
+
}
|
|
225
|
+
async hset(key, field, value) {
|
|
226
|
+
if (!this.hashes.has(key)) {
|
|
227
|
+
this.hashes.set(key, new Map());
|
|
228
|
+
}
|
|
229
|
+
this.hashes.get(key).set(field, value);
|
|
230
|
+
}
|
|
231
|
+
async hgetall(key) {
|
|
232
|
+
const hash = this.hashes.get(key);
|
|
233
|
+
if (!hash)
|
|
234
|
+
return {};
|
|
235
|
+
return Object.fromEntries(hash.entries());
|
|
236
|
+
}
|
|
237
|
+
async hdel(key, ...fields) {
|
|
238
|
+
const hash = this.hashes.get(key);
|
|
239
|
+
if (!hash)
|
|
240
|
+
return 0;
|
|
241
|
+
let count = 0;
|
|
242
|
+
for (const field of fields) {
|
|
243
|
+
if (hash.delete(field))
|
|
244
|
+
count++;
|
|
245
|
+
}
|
|
246
|
+
return count;
|
|
247
|
+
}
|
|
248
|
+
async lpush(key, ...values) {
|
|
249
|
+
if (!this.lists.has(key)) {
|
|
250
|
+
this.lists.set(key, []);
|
|
251
|
+
}
|
|
252
|
+
this.lists.get(key).unshift(...values);
|
|
253
|
+
return this.lists.get(key).length;
|
|
254
|
+
}
|
|
255
|
+
async rpush(key, ...values) {
|
|
256
|
+
if (!this.lists.has(key)) {
|
|
257
|
+
this.lists.set(key, []);
|
|
258
|
+
}
|
|
259
|
+
this.lists.get(key).push(...values);
|
|
260
|
+
return this.lists.get(key).length;
|
|
261
|
+
}
|
|
262
|
+
async lrange(key, start, stop) {
|
|
263
|
+
const list = this.lists.get(key) || [];
|
|
264
|
+
const end = stop === -1 ? list.length : stop + 1;
|
|
265
|
+
return list.slice(start, end);
|
|
266
|
+
}
|
|
267
|
+
async llen(key) {
|
|
268
|
+
return this.lists.get(key)?.length ?? 0;
|
|
269
|
+
}
|
|
270
|
+
async publish(channel, message) {
|
|
271
|
+
const subs = this.subscribers.get(channel);
|
|
272
|
+
if (!subs)
|
|
273
|
+
return 0;
|
|
274
|
+
subs.forEach(cb => cb(message));
|
|
275
|
+
return subs.size;
|
|
276
|
+
}
|
|
277
|
+
async subscribe(channel, callback) {
|
|
278
|
+
if (!this.subscribers.has(channel)) {
|
|
279
|
+
this.subscribers.set(channel, new Set());
|
|
280
|
+
}
|
|
281
|
+
this.subscribers.get(channel).add(callback);
|
|
282
|
+
}
|
|
283
|
+
async unsubscribe(channel) {
|
|
284
|
+
this.subscribers.delete(channel);
|
|
285
|
+
}
|
|
286
|
+
async connect() {
|
|
287
|
+
this.connected = true;
|
|
288
|
+
}
|
|
289
|
+
async disconnect() {
|
|
290
|
+
this.connected = false;
|
|
291
|
+
this.store.clear();
|
|
292
|
+
this.hashes.clear();
|
|
293
|
+
this.lists.clear();
|
|
294
|
+
this.subscribers.clear();
|
|
295
|
+
}
|
|
296
|
+
isConnected() {
|
|
297
|
+
return this.connected;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
exports.MemoryRedisAdapter = MemoryRedisAdapter;
|
|
301
|
+
// Factory functions
|
|
302
|
+
function createUpstashRedis(config) {
|
|
303
|
+
return new UpstashRedisAdapter(config);
|
|
304
|
+
}
|
|
305
|
+
function createMemoryRedis() {
|
|
306
|
+
return new MemoryRedisAdapter();
|
|
307
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite Database Adapter
|
|
3
|
+
* Persistent storage using SQLite for sessions, messages, and runs
|
|
4
|
+
*/
|
|
5
|
+
export interface SQLiteConfig {
|
|
6
|
+
filename: string;
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface DbMessage {
|
|
10
|
+
id: string;
|
|
11
|
+
sessionId: string;
|
|
12
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
13
|
+
content: string;
|
|
14
|
+
toolCalls?: string;
|
|
15
|
+
createdAt: number;
|
|
16
|
+
metadata?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface DbRun {
|
|
19
|
+
id: string;
|
|
20
|
+
sessionId: string;
|
|
21
|
+
agentId?: string;
|
|
22
|
+
status: 'pending' | 'running' | 'completed' | 'failed';
|
|
23
|
+
input?: string;
|
|
24
|
+
output?: string;
|
|
25
|
+
error?: string;
|
|
26
|
+
startedAt: number;
|
|
27
|
+
completedAt?: number;
|
|
28
|
+
metadata?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface DbTrace {
|
|
31
|
+
id: string;
|
|
32
|
+
runId: string;
|
|
33
|
+
spanId: string;
|
|
34
|
+
parentSpanId?: string;
|
|
35
|
+
name: string;
|
|
36
|
+
type: string;
|
|
37
|
+
startedAt: number;
|
|
38
|
+
completedAt?: number;
|
|
39
|
+
attributes?: string;
|
|
40
|
+
status?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* SQLite Adapter - Uses better-sqlite3 for synchronous operations
|
|
44
|
+
* Falls back to sql.js for browser compatibility
|
|
45
|
+
*/
|
|
46
|
+
export declare class SQLiteAdapter {
|
|
47
|
+
private db;
|
|
48
|
+
private filename;
|
|
49
|
+
private verbose;
|
|
50
|
+
private initialized;
|
|
51
|
+
constructor(config: SQLiteConfig);
|
|
52
|
+
initialize(): Promise<void>;
|
|
53
|
+
private createTables;
|
|
54
|
+
createSession(id: string, metadata?: Record<string, any>): Promise<void>;
|
|
55
|
+
getSession(id: string): Promise<any | null>;
|
|
56
|
+
addMessage(message: DbMessage): Promise<void>;
|
|
57
|
+
getMessages(sessionId: string, limit?: number): Promise<DbMessage[]>;
|
|
58
|
+
createRun(run: DbRun): Promise<void>;
|
|
59
|
+
updateRun(id: string, updates: Partial<DbRun>): Promise<void>;
|
|
60
|
+
getRun(id: string): Promise<DbRun | null>;
|
|
61
|
+
addTrace(trace: DbTrace): Promise<void>;
|
|
62
|
+
getTraces(runId: string): Promise<DbTrace[]>;
|
|
63
|
+
close(): Promise<void>;
|
|
64
|
+
clear(): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
export declare function createSQLiteAdapter(config: SQLiteConfig): SQLiteAdapter;
|