@axiom-lattice/core 1.0.50 → 2.0.1
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.mts +7 -40
- package/dist/index.d.ts +7 -40
- package/dist/index.js +73 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -73
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -1377,12 +1377,13 @@ var DeepAgentGraphBuilder = class {
|
|
|
1377
1377
|
return createDeepAgent({
|
|
1378
1378
|
tools,
|
|
1379
1379
|
model: params.model,
|
|
1380
|
+
stateSchema: params.stateSchema,
|
|
1380
1381
|
instructions: params.prompt,
|
|
1381
1382
|
subagents: params.subAgents.map((sa) => ({
|
|
1382
1383
|
name: sa.key,
|
|
1383
1384
|
description: sa.config.description,
|
|
1384
1385
|
prompt: sa.config.prompt,
|
|
1385
|
-
tools: sa.config.tools
|
|
1386
|
+
tools: sa.config.tools
|
|
1386
1387
|
}))
|
|
1387
1388
|
});
|
|
1388
1389
|
}
|
|
@@ -2205,13 +2206,16 @@ var ThreadStatus = /* @__PURE__ */ ((ThreadStatus2) => {
|
|
|
2205
2206
|
})(ThreadStatus || {});
|
|
2206
2207
|
|
|
2207
2208
|
// src/chunk_buffer_lattice/InMemoryChunkBuffer.ts
|
|
2209
|
+
import { ReplaySubject } from "rxjs";
|
|
2208
2210
|
var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
2209
2211
|
constructor(config) {
|
|
2210
2212
|
super();
|
|
2211
2213
|
this.buffers = /* @__PURE__ */ new Map();
|
|
2212
2214
|
this.config = {
|
|
2213
2215
|
ttl: config?.ttl ?? 60 * 60 * 1e3,
|
|
2214
|
-
cleanupInterval: config?.cleanupInterval ?? 0
|
|
2216
|
+
cleanupInterval: config?.cleanupInterval ?? 0,
|
|
2217
|
+
maxChunks: config?.maxChunks ?? 1e3
|
|
2218
|
+
// Default max chunks per thread
|
|
2215
2219
|
};
|
|
2216
2220
|
if (this.config.cleanupInterval > 0) {
|
|
2217
2221
|
this.startCleanupTimer();
|
|
@@ -2260,11 +2264,14 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
2260
2264
|
*/
|
|
2261
2265
|
getOrCreateBuffer(threadId) {
|
|
2262
2266
|
let buffer = this.getBufferIfValid(threadId);
|
|
2267
|
+
4;
|
|
2263
2268
|
if (!buffer) {
|
|
2264
2269
|
const now = Date.now();
|
|
2265
2270
|
buffer = {
|
|
2266
2271
|
threadId,
|
|
2267
|
-
chunks
|
|
2272
|
+
chunks$: new ReplaySubject(
|
|
2273
|
+
this.config.maxChunks ?? 1e4
|
|
2274
|
+
),
|
|
2268
2275
|
status: "active" /* ACTIVE */,
|
|
2269
2276
|
createdAt: now,
|
|
2270
2277
|
updatedAt: now,
|
|
@@ -2272,34 +2279,30 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
2272
2279
|
};
|
|
2273
2280
|
this.buffers.set(threadId, buffer);
|
|
2274
2281
|
}
|
|
2282
|
+
if (buffer.status !== "active" /* ACTIVE */) {
|
|
2283
|
+
buffer.status = "active" /* ACTIVE */;
|
|
2284
|
+
buffer.chunks$ = new ReplaySubject(
|
|
2285
|
+
this.config.maxChunks ?? 1e4
|
|
2286
|
+
);
|
|
2287
|
+
buffer.updatedAt = Date.now();
|
|
2288
|
+
buffer.expiresAt = Date.now() + this.config.ttl;
|
|
2289
|
+
}
|
|
2275
2290
|
return buffer;
|
|
2276
2291
|
}
|
|
2277
2292
|
async addChunk(threadId, content) {
|
|
2278
2293
|
const buffer = this.getOrCreateBuffer(threadId);
|
|
2279
2294
|
const chunk = content;
|
|
2280
|
-
buffer.chunks
|
|
2295
|
+
buffer.chunks$.next(chunk);
|
|
2281
2296
|
buffer.updatedAt = Date.now();
|
|
2282
2297
|
buffer.expiresAt = Date.now() + this.config.ttl;
|
|
2283
|
-
|
|
2284
|
-
async getChunks(threadId) {
|
|
2285
|
-
const buffer = this.getBufferIfValid(threadId);
|
|
2286
|
-
return buffer ? [...buffer.chunks] : [];
|
|
2287
|
-
}
|
|
2288
|
-
async getAccumulatedContent(threadId) {
|
|
2289
|
-
const buffer = this.getBufferIfValid(threadId);
|
|
2290
|
-
if (!buffer) return "";
|
|
2291
|
-
return buffer.chunks.map((chunk) => chunk.data?.content).join("");
|
|
2292
|
-
}
|
|
2293
|
-
async getChunksByMessageId(threadId, messageId) {
|
|
2294
|
-
const buffer = this.getBufferIfValid(threadId);
|
|
2295
|
-
if (!buffer) return [];
|
|
2296
|
-
return buffer.chunks.filter((chunk) => chunk.data?.id === messageId);
|
|
2298
|
+
buffer.status = "active" /* ACTIVE */;
|
|
2297
2299
|
}
|
|
2298
2300
|
async completeThread(threadId) {
|
|
2299
2301
|
const buffer = this.getBufferIfValid(threadId);
|
|
2300
2302
|
if (buffer) {
|
|
2301
2303
|
buffer.status = "completed" /* COMPLETED */;
|
|
2302
2304
|
buffer.updatedAt = Date.now();
|
|
2305
|
+
buffer.chunks$.complete();
|
|
2303
2306
|
}
|
|
2304
2307
|
}
|
|
2305
2308
|
async abortThread(threadId) {
|
|
@@ -2307,6 +2310,7 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
2307
2310
|
if (buffer) {
|
|
2308
2311
|
buffer.status = "aborted" /* ABORTED */;
|
|
2309
2312
|
buffer.updatedAt = Date.now();
|
|
2313
|
+
buffer.chunks$.error(new Error("Thread aborted"));
|
|
2310
2314
|
}
|
|
2311
2315
|
}
|
|
2312
2316
|
async isThreadActive(threadId) {
|
|
@@ -2319,10 +2323,7 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
2319
2323
|
async getThreadBuffer(threadId) {
|
|
2320
2324
|
const buffer = this.getBufferIfValid(threadId);
|
|
2321
2325
|
if (!buffer) return void 0;
|
|
2322
|
-
return
|
|
2323
|
-
...buffer,
|
|
2324
|
-
chunks: [...buffer.chunks]
|
|
2325
|
-
};
|
|
2326
|
+
return buffer;
|
|
2326
2327
|
}
|
|
2327
2328
|
async clearThread(threadId) {
|
|
2328
2329
|
this.buffers.delete(threadId);
|
|
@@ -2369,9 +2370,6 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
2369
2370
|
}
|
|
2370
2371
|
return cleanedCount;
|
|
2371
2372
|
}
|
|
2372
|
-
/**
|
|
2373
|
-
* Extend thread TTL
|
|
2374
|
-
*/
|
|
2375
2373
|
async extendThreadTTL(threadId, additionalMs) {
|
|
2376
2374
|
const buffer = this.getBufferIfValid(threadId);
|
|
2377
2375
|
if (buffer) {
|
|
@@ -2380,62 +2378,69 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
2380
2378
|
buffer.updatedAt = Date.now();
|
|
2381
2379
|
}
|
|
2382
2380
|
}
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
* Used for resuming streams from a known position
|
|
2386
|
-
* Matches the known content and returns chunks after that position
|
|
2387
|
-
* Continues to yield new chunks as they are added until thread completes/aborts
|
|
2388
|
-
*/
|
|
2389
|
-
async *getNewChunksSinceContent(threadId, messageId, knownContent) {
|
|
2390
|
-
let buffer = this.getBufferIfValid(threadId);
|
|
2381
|
+
async *getNewChunksSinceContentIterator(threadId, messageId, knownContent) {
|
|
2382
|
+
const buffer = this.getBufferIfValid(threadId);
|
|
2391
2383
|
if (!buffer) return;
|
|
2392
|
-
let lastYieldedIndex = -1;
|
|
2393
2384
|
let accumulatedContent = "";
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2385
|
+
const queue = [];
|
|
2386
|
+
let resolveNext = null;
|
|
2387
|
+
let errorNext = null;
|
|
2388
|
+
let isCompleted = false;
|
|
2389
|
+
const subscription = buffer.chunks$.subscribe({
|
|
2390
|
+
next: (chunk) => {
|
|
2391
|
+
queue.push(chunk);
|
|
2392
|
+
if (resolveNext) {
|
|
2393
|
+
const resolve = resolveNext;
|
|
2394
|
+
resolveNext = null;
|
|
2395
|
+
resolve();
|
|
2401
2396
|
}
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2397
|
+
},
|
|
2398
|
+
error: (err) => {
|
|
2399
|
+
if (errorNext) {
|
|
2400
|
+
const reject = errorNext;
|
|
2401
|
+
errorNext = null;
|
|
2402
|
+
reject(err);
|
|
2407
2403
|
}
|
|
2408
|
-
}
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
for (let i = lastYieldedIndex + 1; i < buffer.chunks.length; i++) {
|
|
2416
|
-
const chunk = buffer.chunks[i];
|
|
2417
|
-
if (chunk.data?.id === messageId) {
|
|
2418
|
-
yield chunk;
|
|
2419
|
-
lastYieldedIndex = i;
|
|
2420
|
-
hasNewChunks = true;
|
|
2404
|
+
},
|
|
2405
|
+
complete: () => {
|
|
2406
|
+
isCompleted = true;
|
|
2407
|
+
if (resolveNext) {
|
|
2408
|
+
const resolve = resolveNext;
|
|
2409
|
+
resolveNext = null;
|
|
2410
|
+
resolve();
|
|
2421
2411
|
}
|
|
2422
2412
|
}
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2413
|
+
});
|
|
2414
|
+
try {
|
|
2415
|
+
while (true) {
|
|
2416
|
+
if (queue.length === 0) {
|
|
2417
|
+
if (isCompleted) break;
|
|
2418
|
+
await new Promise((resolve, reject) => {
|
|
2419
|
+
resolveNext = resolve;
|
|
2420
|
+
errorNext = reject;
|
|
2421
|
+
});
|
|
2422
|
+
}
|
|
2423
|
+
while (queue.length > 0) {
|
|
2424
|
+
const chunk = queue.shift();
|
|
2425
|
+
if (!chunk) continue;
|
|
2426
|
+
if (chunk.data?.id === messageId) {
|
|
2427
|
+
accumulatedContent += chunk.data?.content || "";
|
|
2428
|
+
}
|
|
2429
|
+
if (accumulatedContent.length > knownContent.length) {
|
|
2430
|
+
if (accumulatedContent.startsWith(knownContent)) {
|
|
2431
|
+
yield chunk;
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2428
2435
|
}
|
|
2436
|
+
} finally {
|
|
2437
|
+
subscription.unsubscribe();
|
|
2429
2438
|
}
|
|
2430
2439
|
}
|
|
2431
|
-
/**
|
|
2432
|
-
* Get statistics about the buffer
|
|
2433
|
-
*/
|
|
2434
2440
|
getStats() {
|
|
2435
2441
|
let activeCount = 0;
|
|
2436
2442
|
let completedCount = 0;
|
|
2437
2443
|
let abortedCount = 0;
|
|
2438
|
-
let totalChunks = 0;
|
|
2439
2444
|
const validBuffers = [];
|
|
2440
2445
|
for (const [threadId, buffer] of this.buffers.entries()) {
|
|
2441
2446
|
if (this.isExpired(buffer)) {
|
|
@@ -2445,7 +2450,6 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
2445
2450
|
}
|
|
2446
2451
|
}
|
|
2447
2452
|
for (const buffer of validBuffers) {
|
|
2448
|
-
totalChunks += buffer.chunks.length;
|
|
2449
2453
|
switch (buffer.status) {
|
|
2450
2454
|
case "active" /* ACTIVE */:
|
|
2451
2455
|
activeCount++;
|
|
@@ -2463,13 +2467,9 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
2463
2467
|
activeThreads: activeCount,
|
|
2464
2468
|
completedThreads: completedCount,
|
|
2465
2469
|
abortedThreads: abortedCount,
|
|
2466
|
-
totalChunks,
|
|
2467
2470
|
config: this.config
|
|
2468
2471
|
};
|
|
2469
2472
|
}
|
|
2470
|
-
/**
|
|
2471
|
-
* Cleanup method for graceful shutdown
|
|
2472
|
-
*/
|
|
2473
2473
|
dispose() {
|
|
2474
2474
|
this.stopCleanupTimer();
|
|
2475
2475
|
this.buffers.clear();
|