zeitlich 0.2.44 → 0.2.46
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 +78 -10
- package/dist/{activities-CPIB2v2C.d.ts → activities-Bm4TLTid.d.ts} +24 -4
- package/dist/{activities-DnmNOnq4.d.cts → activities-CyeiqK_f.d.cts} +24 -4
- package/dist/adapters/sandbox/daytona/index.d.cts +2 -2
- package/dist/adapters/sandbox/daytona/index.d.ts +2 -2
- package/dist/adapters/sandbox/daytona/workflow.d.cts +1 -1
- package/dist/adapters/sandbox/daytona/workflow.d.ts +1 -1
- package/dist/adapters/sandbox/e2b/index.d.cts +1 -1
- package/dist/adapters/sandbox/e2b/index.d.ts +1 -1
- package/dist/adapters/thread/anthropic/index.cjs +171 -65
- package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/index.d.cts +19 -4
- package/dist/adapters/thread/anthropic/index.d.ts +19 -4
- package/dist/adapters/thread/anthropic/index.js +171 -65
- package/dist/adapters/thread/anthropic/index.js.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.cjs +3 -1
- package/dist/adapters/thread/anthropic/workflow.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.d.cts +4 -4
- package/dist/adapters/thread/anthropic/workflow.d.ts +4 -4
- package/dist/adapters/thread/anthropic/workflow.js +3 -1
- package/dist/adapters/thread/anthropic/workflow.js.map +1 -1
- package/dist/adapters/thread/google-genai/index.cjs +171 -69
- package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +5 -4
- package/dist/adapters/thread/google-genai/index.d.ts +5 -4
- package/dist/adapters/thread/google-genai/index.js +171 -69
- package/dist/adapters/thread/google-genai/index.js.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.cjs +3 -1
- package/dist/adapters/thread/google-genai/workflow.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.d.cts +5 -4
- package/dist/adapters/thread/google-genai/workflow.d.ts +5 -4
- package/dist/adapters/thread/google-genai/workflow.js +3 -1
- package/dist/adapters/thread/google-genai/workflow.js.map +1 -1
- package/dist/adapters/thread/langchain/index.cjs +181 -77
- package/dist/adapters/thread/langchain/index.cjs.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +18 -4
- package/dist/adapters/thread/langchain/index.d.ts +18 -4
- package/dist/adapters/thread/langchain/index.js +182 -74
- package/dist/adapters/thread/langchain/index.js.map +1 -1
- package/dist/adapters/thread/langchain/workflow.cjs +3 -1
- package/dist/adapters/thread/langchain/workflow.cjs.map +1 -1
- package/dist/adapters/thread/langchain/workflow.d.cts +4 -4
- package/dist/adapters/thread/langchain/workflow.d.ts +4 -4
- package/dist/adapters/thread/langchain/workflow.js +3 -1
- package/dist/adapters/thread/langchain/workflow.js.map +1 -1
- package/dist/cold-store-BC5L5Z8A.d.cts +117 -0
- package/dist/cold-store-CFHwemBJ.d.ts +117 -0
- package/dist/index.cjs +252 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +138 -8
- package/dist/index.d.ts +138 -8
- package/dist/index.js +247 -54
- package/dist/index.js.map +1 -1
- package/dist/{proxy-DTnc5rqT.d.cts → proxy-BxFyd6cg.d.cts} +1 -1
- package/dist/{proxy-B7Xi1znZ.d.ts → proxy-Cskmj4Yx.d.ts} +1 -1
- package/dist/{thread-manager-BlX2TwRN.d.cts → thread-manager-9tezUcLW.d.cts} +9 -3
- package/dist/{thread-manager-BAv340mi.d.ts → thread-manager-B-zy3xrs.d.ts} +9 -3
- package/dist/{thread-manager-D2xorI-J.d.ts → thread-manager-D33SUmZa.d.cts} +10 -4
- package/dist/{thread-manager-BWv6ZXI3.d.cts → thread-manager-DduoSkvJ.d.ts} +10 -4
- package/dist/{types-C90VoEpt.d.cts → types-CjY93AWZ.d.cts} +1 -1
- package/dist/{types-4Wmk-wRq.d.cts → types-CnuN9T6t.d.cts} +23 -1
- package/dist/{types-DKsCdAtQ.d.ts → types-CwN6_tAL.d.ts} +23 -1
- package/dist/{types-Clhqautb.d.ts → types-L5bvbF-n.d.ts} +17 -1
- package/dist/{types-DpFD8ofR.d.ts → types-gVa5XCWD.d.ts} +1 -1
- package/dist/{types-DRJt1TMi.d.cts → types-oxt8GN97.d.cts} +17 -1
- package/dist/{workflow-D32TRMr-.d.ts → workflow-B1TOcHbt.d.ts} +33 -2
- package/dist/{workflow-XVt0ww8K.d.cts → workflow-DIaIV7L2.d.cts} +33 -2
- package/dist/workflow.cjs +29 -19
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +2 -2
- package/dist/workflow.d.ts +2 -2
- package/dist/workflow.js +29 -19
- package/dist/workflow.js.map +1 -1
- package/package.json +6 -1
- package/src/adapters/thread/anthropic/activities.ts +72 -36
- package/src/adapters/thread/anthropic/thread-manager.ts +9 -1
- package/src/adapters/thread/google-genai/activities.ts +64 -40
- package/src/adapters/thread/google-genai/thread-manager.ts +9 -1
- package/src/adapters/thread/langchain/activities.ts +63 -36
- package/src/adapters/thread/langchain/thread-manager.ts +9 -1
- package/src/index.ts +20 -1
- package/src/lib/session/session-edge-cases.integration.test.ts +12 -0
- package/src/lib/session/session.integration.test.ts +138 -0
- package/src/lib/session/session.ts +47 -22
- package/src/lib/session/types.ts +22 -0
- package/src/lib/thread/cold-store.test.ts +193 -0
- package/src/lib/thread/cold-store.ts +250 -0
- package/src/lib/thread/index.ts +32 -0
- package/src/lib/thread/keys.ts +20 -0
- package/src/lib/thread/manager.ts +16 -27
- package/src/lib/thread/proxy.ts +2 -0
- package/src/lib/thread/snapshot.test.ts +443 -0
- package/src/lib/thread/snapshot.ts +163 -0
- package/src/lib/thread/test-utils.ts +228 -0
- package/src/lib/thread/tiered.test.ts +281 -0
- package/src/lib/thread/tiered.ts +135 -0
- package/src/lib/thread/types.ts +16 -0
- package/src/lib/.env +0 -1
- package/src/tools/bash/.env +0 -1
|
@@ -4,10 +4,6 @@ var messages = require('@langchain/core/messages');
|
|
|
4
4
|
var crypto = require('crypto');
|
|
5
5
|
var activity = require('@temporalio/activity');
|
|
6
6
|
|
|
7
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
-
|
|
9
|
-
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
10
|
-
|
|
11
7
|
// src/adapters/thread/langchain/adapter-id.ts
|
|
12
8
|
var ADAPTER_ID = "langChain";
|
|
13
9
|
|
|
@@ -22,6 +18,9 @@ function getThreadMetaKey(threadKey, threadId) {
|
|
|
22
18
|
function getThreadStateKey(threadKey, threadId) {
|
|
23
19
|
return `${threadKey}:state:thread:${threadId}`;
|
|
24
20
|
}
|
|
21
|
+
function getThreadDedupKey(threadId, dedupId) {
|
|
22
|
+
return `dedup:${dedupId}:thread:${threadId}`;
|
|
23
|
+
}
|
|
25
24
|
|
|
26
25
|
// src/lib/thread/manager.ts
|
|
27
26
|
var APPEND_IDEMPOTENT_SCRIPT = `
|
|
@@ -35,9 +34,6 @@ redis.call('EXPIRE', KEYS[2], tonumber(ARGV[1]))
|
|
|
35
34
|
redis.call('SET', KEYS[1], '1', 'EX', tonumber(ARGV[1]))
|
|
36
35
|
return 1
|
|
37
36
|
`;
|
|
38
|
-
function getDedupKey(threadId, id) {
|
|
39
|
-
return `dedup:${id}:thread:${threadId}`;
|
|
40
|
-
}
|
|
41
37
|
function createThreadManager(config) {
|
|
42
38
|
const {
|
|
43
39
|
redis,
|
|
@@ -45,11 +41,13 @@ function createThreadManager(config) {
|
|
|
45
41
|
key = "messages",
|
|
46
42
|
serialize = (m) => JSON.stringify(m),
|
|
47
43
|
deserialize = (raw) => JSON.parse(raw),
|
|
48
|
-
idOf
|
|
44
|
+
idOf,
|
|
45
|
+
ttlSeconds = THREAD_TTL_SECONDS
|
|
49
46
|
} = config;
|
|
50
47
|
const redisKey = getThreadListKey(key, threadId);
|
|
51
48
|
const metaKey = getThreadMetaKey(key, threadId);
|
|
52
49
|
const stateKey = getThreadStateKey(key, threadId);
|
|
50
|
+
const dedupKey = (id) => getThreadDedupKey(threadId, id);
|
|
53
51
|
async function assertThreadExists() {
|
|
54
52
|
const exists = await redis.exists(metaKey);
|
|
55
53
|
if (!exists) {
|
|
@@ -59,7 +57,7 @@ function createThreadManager(config) {
|
|
|
59
57
|
return {
|
|
60
58
|
async initialize() {
|
|
61
59
|
await redis.del(redisKey);
|
|
62
|
-
await redis.set(metaKey, "1", "EX",
|
|
60
|
+
await redis.set(metaKey, "1", "EX", ttlSeconds);
|
|
63
61
|
},
|
|
64
62
|
async load() {
|
|
65
63
|
await assertThreadExists();
|
|
@@ -71,18 +69,17 @@ function createThreadManager(config) {
|
|
|
71
69
|
await assertThreadExists();
|
|
72
70
|
if (idOf) {
|
|
73
71
|
const dedupId = messages.map(idOf).join(":");
|
|
74
|
-
const dedupKey = getDedupKey(threadId, dedupId);
|
|
75
72
|
await redis.eval(
|
|
76
73
|
APPEND_IDEMPOTENT_SCRIPT,
|
|
77
74
|
2,
|
|
78
|
-
dedupKey,
|
|
75
|
+
dedupKey(dedupId),
|
|
79
76
|
redisKey,
|
|
80
|
-
String(
|
|
77
|
+
String(ttlSeconds),
|
|
81
78
|
...messages.map(serialize)
|
|
82
79
|
);
|
|
83
80
|
} else {
|
|
84
81
|
await redis.rpush(redisKey, ...messages.map(serialize));
|
|
85
|
-
await redis.expire(redisKey,
|
|
82
|
+
await redis.expire(redisKey, ttlSeconds);
|
|
86
83
|
}
|
|
87
84
|
},
|
|
88
85
|
async fork(newThreadId) {
|
|
@@ -97,11 +94,11 @@ function createThreadManager(config) {
|
|
|
97
94
|
if (data.length > 0) {
|
|
98
95
|
const newKey = getThreadListKey(key, newThreadId);
|
|
99
96
|
await redis.rpush(newKey, ...data);
|
|
100
|
-
await redis.expire(newKey,
|
|
97
|
+
await redis.expire(newKey, ttlSeconds);
|
|
101
98
|
}
|
|
102
99
|
if (stateRaw != null) {
|
|
103
100
|
const newStateKey = getThreadStateKey(key, newThreadId);
|
|
104
|
-
await redis.set(newStateKey, stateRaw, "EX",
|
|
101
|
+
await redis.set(newStateKey, stateRaw, "EX", ttlSeconds);
|
|
105
102
|
}
|
|
106
103
|
return forked;
|
|
107
104
|
},
|
|
@@ -116,15 +113,13 @@ function createThreadManager(config) {
|
|
|
116
113
|
const existingIds = existing.map((raw) => idOf(deserialize(raw))).filter((id) => typeof id === "string");
|
|
117
114
|
await redis.del(redisKey);
|
|
118
115
|
if (existingIds.length > 0) {
|
|
119
|
-
await redis.del(
|
|
120
|
-
...existingIds.map((id) => getDedupKey(threadId, id))
|
|
121
|
-
);
|
|
116
|
+
await redis.del(...existingIds.map(dedupKey));
|
|
122
117
|
}
|
|
123
118
|
if (messages.length > 0) {
|
|
124
119
|
await redis.rpush(redisKey, ...messages.map(serialize));
|
|
125
|
-
await redis.expire(redisKey,
|
|
120
|
+
await redis.expire(redisKey, ttlSeconds);
|
|
126
121
|
}
|
|
127
|
-
await redis.expire(metaKey,
|
|
122
|
+
await redis.expire(metaKey, ttlSeconds);
|
|
128
123
|
},
|
|
129
124
|
async delete() {
|
|
130
125
|
await redis.del(redisKey, metaKey, stateKey);
|
|
@@ -136,12 +131,7 @@ function createThreadManager(config) {
|
|
|
136
131
|
},
|
|
137
132
|
async saveState(state) {
|
|
138
133
|
await assertThreadExists();
|
|
139
|
-
await redis.set(
|
|
140
|
-
stateKey,
|
|
141
|
-
JSON.stringify(state),
|
|
142
|
-
"EX",
|
|
143
|
-
THREAD_TTL_SECONDS
|
|
144
|
-
);
|
|
134
|
+
await redis.set(stateKey, JSON.stringify(state), "EX", ttlSeconds);
|
|
145
135
|
},
|
|
146
136
|
async deleteState() {
|
|
147
137
|
await redis.del(stateKey);
|
|
@@ -170,21 +160,132 @@ function createThreadManager(config) {
|
|
|
170
160
|
if (idx === -1) return;
|
|
171
161
|
if (idx === 0) {
|
|
172
162
|
await redis.del(redisKey);
|
|
173
|
-
await redis.expire(metaKey,
|
|
163
|
+
await redis.expire(metaKey, ttlSeconds);
|
|
174
164
|
} else {
|
|
175
165
|
await redis.ltrim(redisKey, 0, idx - 1);
|
|
176
|
-
await redis.expire(redisKey,
|
|
166
|
+
await redis.expire(redisKey, ttlSeconds);
|
|
177
167
|
}
|
|
178
168
|
if (removedIds.length > 0) {
|
|
179
|
-
await redis.del(
|
|
180
|
-
...removedIds.map((id) => getDedupKey(threadId, id))
|
|
181
|
-
);
|
|
169
|
+
await redis.del(...removedIds.map(dedupKey));
|
|
182
170
|
}
|
|
183
171
|
}
|
|
184
172
|
};
|
|
185
173
|
}
|
|
186
174
|
|
|
187
|
-
// src/
|
|
175
|
+
// src/lib/thread/snapshot.ts
|
|
176
|
+
async function encodeSnapshot(config) {
|
|
177
|
+
const { redis, threadKey, threadId, idOf } = config;
|
|
178
|
+
const metaKey = getThreadMetaKey(threadKey, threadId);
|
|
179
|
+
if (await redis.exists(metaKey) === 0) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
const listKey = getThreadListKey(threadKey, threadId);
|
|
183
|
+
const stateKey = getThreadStateKey(threadKey, threadId);
|
|
184
|
+
const messages = await redis.lrange(listKey, 0, -1);
|
|
185
|
+
const stateRaw = await redis.get(stateKey);
|
|
186
|
+
const state = stateRaw == null ? null : JSON.parse(stateRaw);
|
|
187
|
+
const dedupIds = idOf ? messages.map(idOf) : [];
|
|
188
|
+
return { v: 1, messages, state, dedupIds };
|
|
189
|
+
}
|
|
190
|
+
async function applySnapshot(config) {
|
|
191
|
+
const {
|
|
192
|
+
redis,
|
|
193
|
+
threadKey,
|
|
194
|
+
threadId,
|
|
195
|
+
snapshot,
|
|
196
|
+
ttlSeconds = THREAD_TTL_SECONDS
|
|
197
|
+
} = config;
|
|
198
|
+
const metaKey = getThreadMetaKey(threadKey, threadId);
|
|
199
|
+
if (await redis.exists(metaKey) === 1) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const listKey = getThreadListKey(threadKey, threadId);
|
|
203
|
+
const stateKey = getThreadStateKey(threadKey, threadId);
|
|
204
|
+
await redis.del(listKey, stateKey);
|
|
205
|
+
const pipeline = redis.pipeline();
|
|
206
|
+
if (snapshot.messages.length > 0) {
|
|
207
|
+
pipeline.rpush(listKey, ...snapshot.messages);
|
|
208
|
+
pipeline.expire(listKey, ttlSeconds);
|
|
209
|
+
}
|
|
210
|
+
if (snapshot.state != null) {
|
|
211
|
+
pipeline.set(stateKey, JSON.stringify(snapshot.state), "EX", ttlSeconds);
|
|
212
|
+
}
|
|
213
|
+
for (const id of snapshot.dedupIds) {
|
|
214
|
+
pipeline.set(getThreadDedupKey(threadId, id), "1", "EX", ttlSeconds);
|
|
215
|
+
}
|
|
216
|
+
const results = await pipeline.exec();
|
|
217
|
+
if (results) {
|
|
218
|
+
const firstErr = results.find(([err]) => err)?.[0] ?? null;
|
|
219
|
+
if (firstErr) {
|
|
220
|
+
await redis.del(
|
|
221
|
+
listKey,
|
|
222
|
+
stateKey,
|
|
223
|
+
...snapshot.dedupIds.map((id) => getThreadDedupKey(threadId, id))
|
|
224
|
+
).catch(() => void 0);
|
|
225
|
+
throw firstErr;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
await redis.set(metaKey, "1", "EX", ttlSeconds);
|
|
229
|
+
}
|
|
230
|
+
async function clearHotTier(config) {
|
|
231
|
+
const { redis, threadKey, threadId, dedupIds = [] } = config;
|
|
232
|
+
const keys = [
|
|
233
|
+
getThreadListKey(threadKey, threadId),
|
|
234
|
+
getThreadMetaKey(threadKey, threadId),
|
|
235
|
+
getThreadStateKey(threadKey, threadId),
|
|
236
|
+
...dedupIds.map((id) => getThreadDedupKey(threadId, id))
|
|
237
|
+
];
|
|
238
|
+
await redis.del(...keys);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/lib/thread/tiered.ts
|
|
242
|
+
function createTieredThreadManager(config) {
|
|
243
|
+
const {
|
|
244
|
+
redis,
|
|
245
|
+
threadId,
|
|
246
|
+
key = "messages",
|
|
247
|
+
coldStore,
|
|
248
|
+
idOf,
|
|
249
|
+
deserialize = (raw) => JSON.parse(raw),
|
|
250
|
+
ttlSeconds = THREAD_TTL_SECONDS
|
|
251
|
+
} = config;
|
|
252
|
+
const base = createThreadManager(config);
|
|
253
|
+
const rawIdOf = idOf ? (raw) => idOf(deserialize(raw)) : void 0;
|
|
254
|
+
return Object.assign(base, {
|
|
255
|
+
async hydrate() {
|
|
256
|
+
if (!coldStore) return;
|
|
257
|
+
const snapshot = await coldStore.read(key, threadId);
|
|
258
|
+
if (!snapshot) return;
|
|
259
|
+
await applySnapshot({
|
|
260
|
+
redis,
|
|
261
|
+
threadKey: key,
|
|
262
|
+
threadId,
|
|
263
|
+
snapshot,
|
|
264
|
+
ttlSeconds
|
|
265
|
+
});
|
|
266
|
+
},
|
|
267
|
+
async flush(opts) {
|
|
268
|
+
if (!coldStore) return;
|
|
269
|
+
const snapshot = await encodeSnapshot({
|
|
270
|
+
redis,
|
|
271
|
+
threadKey: key,
|
|
272
|
+
threadId,
|
|
273
|
+
...rawIdOf ? { idOf: rawIdOf } : {}
|
|
274
|
+
});
|
|
275
|
+
if (!snapshot) return;
|
|
276
|
+
await coldStore.write(key, threadId, snapshot);
|
|
277
|
+
const deleteHot = opts?.deleteHot ?? true;
|
|
278
|
+
if (deleteHot) {
|
|
279
|
+
await clearHotTier({
|
|
280
|
+
redis,
|
|
281
|
+
threadKey: key,
|
|
282
|
+
threadId,
|
|
283
|
+
dedupIds: snapshot.dedupIds
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}
|
|
188
289
|
function storedMessageId(msg) {
|
|
189
290
|
if (msg.type === "tool" && msg.data.tool_call_id) {
|
|
190
291
|
return msg.data.tool_call_id;
|
|
@@ -199,7 +300,8 @@ function createLangChainThreadManager(config) {
|
|
|
199
300
|
redis: config.redis,
|
|
200
301
|
threadId: config.threadId,
|
|
201
302
|
key: config.key,
|
|
202
|
-
idOf: storedMessageId
|
|
303
|
+
idOf: storedMessageId,
|
|
304
|
+
...config.ttlSeconds !== void 0 && { ttlSeconds: config.ttlSeconds }
|
|
203
305
|
};
|
|
204
306
|
const base = createThreadManager(baseConfig);
|
|
205
307
|
const helpers = {
|
|
@@ -266,7 +368,7 @@ function createLangChainThreadManager(config) {
|
|
|
266
368
|
return manager;
|
|
267
369
|
}
|
|
268
370
|
|
|
269
|
-
//
|
|
371
|
+
// node_modules/uuid/dist/esm/stringify.js
|
|
270
372
|
var byteToHex = [];
|
|
271
373
|
for (let i = 0; i < 256; ++i) {
|
|
272
374
|
byteToHex.push((i + 256).toString(16).slice(1));
|
|
@@ -278,26 +380,30 @@ var rnds8Pool = new Uint8Array(256);
|
|
|
278
380
|
var poolPtr = rnds8Pool.length;
|
|
279
381
|
function rng() {
|
|
280
382
|
if (poolPtr > rnds8Pool.length - 16) {
|
|
281
|
-
|
|
383
|
+
crypto.randomFillSync(rnds8Pool);
|
|
282
384
|
poolPtr = 0;
|
|
283
385
|
}
|
|
284
386
|
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
285
387
|
}
|
|
286
|
-
var native_default = {
|
|
287
|
-
randomUUID: crypto__default.default.randomUUID
|
|
288
|
-
};
|
|
388
|
+
var native_default = { randomUUID: crypto.randomUUID };
|
|
289
389
|
|
|
290
|
-
//
|
|
390
|
+
// node_modules/uuid/dist/esm/v4.js
|
|
291
391
|
function v4(options, buf, offset) {
|
|
292
392
|
if (native_default.randomUUID && !buf && !options) {
|
|
293
393
|
return native_default.randomUUID();
|
|
294
394
|
}
|
|
295
395
|
options = options || {};
|
|
296
|
-
const rnds = options.random
|
|
396
|
+
const rnds = options.random ?? options.rng?.() ?? rng();
|
|
397
|
+
if (rnds.length < 16) {
|
|
398
|
+
throw new Error("Random bytes length must be >= 16");
|
|
399
|
+
}
|
|
297
400
|
rnds[6] = rnds[6] & 15 | 64;
|
|
298
401
|
rnds[8] = rnds[8] & 63 | 128;
|
|
299
402
|
if (buf) {
|
|
300
403
|
offset = offset || 0;
|
|
404
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
405
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
406
|
+
}
|
|
301
407
|
for (let i = 0; i < 16; ++i) {
|
|
302
408
|
buf[offset + i] = rnds[i];
|
|
303
409
|
}
|
|
@@ -373,46 +479,43 @@ async function invokeLangChainModel({
|
|
|
373
479
|
// src/adapters/thread/langchain/activities.ts
|
|
374
480
|
function createLangChainAdapter(config) {
|
|
375
481
|
const { redis } = config;
|
|
482
|
+
const baseExtras = {
|
|
483
|
+
...config.ttlSeconds !== void 0 && { ttlSeconds: config.ttlSeconds }
|
|
484
|
+
};
|
|
485
|
+
const makeProviderThread = (threadId, threadKey) => createLangChainThreadManager({
|
|
486
|
+
redis,
|
|
487
|
+
threadId,
|
|
488
|
+
key: threadKey,
|
|
489
|
+
...baseExtras
|
|
490
|
+
});
|
|
491
|
+
const makeTieredBase = (threadId, threadKey) => createTieredThreadManager({
|
|
492
|
+
redis,
|
|
493
|
+
threadId,
|
|
494
|
+
key: threadKey,
|
|
495
|
+
idOf: storedMessageId,
|
|
496
|
+
...baseExtras,
|
|
497
|
+
...config.coldStore && { coldStore: config.coldStore }
|
|
498
|
+
});
|
|
376
499
|
const threadOps = {
|
|
377
500
|
async initializeThread(threadId, threadKey) {
|
|
378
|
-
const thread =
|
|
379
|
-
redis,
|
|
380
|
-
threadId,
|
|
381
|
-
key: threadKey
|
|
382
|
-
});
|
|
501
|
+
const thread = makeProviderThread(threadId, threadKey);
|
|
383
502
|
await thread.initialize();
|
|
384
503
|
},
|
|
385
504
|
async appendHumanMessage(threadId, id, content, threadKey) {
|
|
386
|
-
const thread =
|
|
387
|
-
redis,
|
|
388
|
-
threadId,
|
|
389
|
-
key: threadKey
|
|
390
|
-
});
|
|
505
|
+
const thread = makeProviderThread(threadId, threadKey);
|
|
391
506
|
await thread.appendUserMessage(id, content);
|
|
392
507
|
},
|
|
393
508
|
async appendSystemMessage(threadId, id, content, threadKey) {
|
|
394
|
-
const thread =
|
|
395
|
-
redis,
|
|
396
|
-
threadId,
|
|
397
|
-
key: threadKey
|
|
398
|
-
});
|
|
509
|
+
const thread = makeProviderThread(threadId, threadKey);
|
|
399
510
|
await thread.appendSystemMessage(id, content);
|
|
400
511
|
},
|
|
401
512
|
async appendToolResult(id, cfg) {
|
|
402
513
|
const { threadId, threadKey, toolCallId, content } = cfg;
|
|
403
|
-
const thread =
|
|
404
|
-
redis,
|
|
405
|
-
threadId,
|
|
406
|
-
key: threadKey
|
|
407
|
-
});
|
|
514
|
+
const thread = makeProviderThread(threadId, threadKey);
|
|
408
515
|
await thread.appendToolResult(id, toolCallId, "", content);
|
|
409
516
|
},
|
|
410
517
|
async appendAgentMessage(threadId, id, message, threadKey) {
|
|
411
|
-
const thread =
|
|
412
|
-
redis,
|
|
413
|
-
threadId,
|
|
414
|
-
key: threadKey
|
|
415
|
-
});
|
|
518
|
+
const thread = makeProviderThread(threadId, threadKey);
|
|
416
519
|
const patched = { ...message, data: { ...message.data, id } };
|
|
417
520
|
await thread.append([patched]);
|
|
418
521
|
},
|
|
@@ -421,29 +524,30 @@ function createLangChainAdapter(config) {
|
|
|
421
524
|
redis,
|
|
422
525
|
threadId: sourceThreadId,
|
|
423
526
|
key: threadKey,
|
|
424
|
-
hooks: config.hooks
|
|
527
|
+
hooks: config.hooks,
|
|
528
|
+
...baseExtras
|
|
425
529
|
});
|
|
426
530
|
await thread.fork(targetThreadId);
|
|
427
531
|
},
|
|
428
532
|
async truncateThread(threadId, messageId, threadKey) {
|
|
429
|
-
const thread =
|
|
533
|
+
const thread = makeProviderThread(threadId, threadKey);
|
|
430
534
|
await thread.truncateFromId(messageId);
|
|
431
535
|
},
|
|
432
536
|
async loadThreadState(threadId, threadKey) {
|
|
433
|
-
const thread =
|
|
434
|
-
redis,
|
|
435
|
-
threadId,
|
|
436
|
-
key: threadKey
|
|
437
|
-
});
|
|
537
|
+
const thread = makeProviderThread(threadId, threadKey);
|
|
438
538
|
return thread.loadState();
|
|
439
539
|
},
|
|
440
540
|
async saveThreadState(threadId, state, threadKey) {
|
|
441
|
-
const thread =
|
|
442
|
-
redis,
|
|
443
|
-
threadId,
|
|
444
|
-
key: threadKey
|
|
445
|
-
});
|
|
541
|
+
const thread = makeProviderThread(threadId, threadKey);
|
|
446
542
|
await thread.saveState(state);
|
|
543
|
+
},
|
|
544
|
+
async hydrateThread(threadId, threadKey) {
|
|
545
|
+
if (!config.coldStore) return;
|
|
546
|
+
await makeTieredBase(threadId, threadKey).hydrate();
|
|
547
|
+
},
|
|
548
|
+
async flushThread(threadId, threadKey) {
|
|
549
|
+
if (!config.coldStore) return;
|
|
550
|
+
await makeTieredBase(threadId, threadKey).flush();
|
|
447
551
|
}
|
|
448
552
|
};
|
|
449
553
|
function createActivities(scope) {
|