agent-relay 1.3.1 → 1.3.3
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/.trajectories/active/traj_3yx9dy148mge.json +42 -0
- package/.trajectories/completed/2026-01/traj_1g7yx6qtg4ai.json +49 -0
- package/.trajectories/completed/2026-01/traj_1g7yx6qtg4ai.md +31 -0
- package/.trajectories/completed/2026-01/traj_4qwd4zmhfwp4.json +49 -0
- package/.trajectories/completed/2026-01/traj_4qwd4zmhfwp4.md +31 -0
- package/.trajectories/completed/2026-01/traj_6unwwmgyj5sq.json +109 -0
- package/.trajectories/completed/2026-01/traj_a0tqx8biw9c4.json +49 -0
- package/.trajectories/completed/2026-01/traj_a0tqx8biw9c4.md +31 -0
- package/.trajectories/completed/2026-01/traj_ax8uungxz2qh.json +66 -0
- package/.trajectories/completed/2026-01/traj_ax8uungxz2qh.md +36 -0
- package/.trajectories/completed/2026-01/traj_c9izbh2snpzf.json +49 -0
- package/.trajectories/completed/2026-01/traj_c9izbh2snpzf.md +31 -0
- package/.trajectories/completed/2026-01/traj_cpn70dw066nt.json +65 -0
- package/.trajectories/completed/2026-01/traj_cpn70dw066nt.md +37 -0
- package/.trajectories/completed/2026-01/traj_erglv2f8t9eh.json +36 -0
- package/.trajectories/completed/2026-01/traj_erglv2f8t9eh.md +21 -0
- package/.trajectories/completed/2026-01/traj_he75f24d1xfm.json +101 -0
- package/.trajectories/completed/2026-01/traj_he75f24d1xfm.md +52 -0
- package/.trajectories/completed/2026-01/traj_lgtodco7dp1n.json +61 -0
- package/.trajectories/completed/2026-01/traj_lgtodco7dp1n.md +36 -0
- package/.trajectories/completed/2026-01/traj_oszg9flv74pk.json +73 -0
- package/.trajectories/completed/2026-01/traj_oszg9flv74pk.md +41 -0
- package/.trajectories/completed/2026-01/traj_pulomd3y8cvj.json +77 -0
- package/.trajectories/completed/2026-01/traj_pulomd3y8cvj.md +42 -0
- package/.trajectories/completed/2026-01/traj_rsavt0jipi3c.json +109 -0
- package/.trajectories/completed/2026-01/traj_rsavt0jipi3c.md +56 -0
- package/.trajectories/completed/2026-01/traj_x721m1j9rzup.json +113 -0
- package/.trajectories/completed/2026-01/traj_x721m1j9rzup.md +57 -0
- package/.trajectories/completed/2026-01/traj_xjqvmep5ed3h.json +61 -0
- package/.trajectories/completed/2026-01/traj_xjqvmep5ed3h.md +36 -0
- package/.trajectories/completed/2026-01/traj_y7n6hfbf7dmg.json +49 -0
- package/.trajectories/completed/2026-01/traj_y7n6hfbf7dmg.md +31 -0
- package/.trajectories/completed/2026-01/traj_yvfkwnkdiso2.json +49 -0
- package/.trajectories/completed/2026-01/traj_yvfkwnkdiso2.md +31 -0
- package/.trajectories/index.json +140 -1
- package/README.md +23 -9
- package/TRAIL_GIT_AUTH_FIX.md +113 -0
- package/deploy/workspace/codex.config.toml +1 -1
- package/deploy/workspace/entrypoint.sh +20 -79
- package/deploy/workspace/gh-relay +156 -0
- package/deploy/workspace/git-credential-relay +5 -1
- package/dist/bridge/multi-project-client.js +13 -10
- package/dist/bridge/spawner.d.ts +2 -0
- package/dist/bridge/spawner.js +58 -76
- package/dist/bridge/types.d.ts +2 -0
- package/dist/cli/index.d.ts +8 -6
- package/dist/cli/index.js +297 -30
- package/dist/cloud/api/admin.js +16 -3
- package/dist/cloud/api/codex-auth-helper.js +28 -8
- package/dist/cloud/api/consensus.d.ts +13 -0
- package/dist/cloud/api/consensus.js +259 -0
- package/dist/cloud/api/daemons.js +205 -1
- package/dist/cloud/api/git.js +37 -7
- package/dist/cloud/api/onboarding.js +4 -1
- package/dist/cloud/api/provider-env.d.ts +5 -0
- package/dist/cloud/api/provider-env.js +27 -0
- package/dist/cloud/api/providers.js +2 -0
- package/dist/cloud/api/test-helpers.js +130 -0
- package/dist/cloud/api/workspaces.js +38 -3
- package/dist/cloud/db/bulk-ingest.d.ts +88 -0
- package/dist/cloud/db/bulk-ingest.js +268 -0
- package/dist/cloud/db/drizzle.d.ts +33 -0
- package/dist/cloud/db/drizzle.js +174 -2
- package/dist/cloud/db/index.d.ts +24 -5
- package/dist/cloud/db/index.js +19 -4
- package/dist/cloud/db/schema.d.ts +397 -3
- package/dist/cloud/db/schema.js +75 -1
- package/dist/cloud/provisioner/index.d.ts +8 -0
- package/dist/cloud/provisioner/index.js +256 -50
- package/dist/cloud/server.js +47 -3
- package/dist/cloud/services/index.d.ts +1 -0
- package/dist/cloud/services/index.js +2 -0
- package/dist/cloud/services/nango.d.ts +3 -4
- package/dist/cloud/services/nango.js +11 -33
- package/dist/cloud/services/workspace-keepalive.d.ts +76 -0
- package/dist/cloud/services/workspace-keepalive.js +234 -0
- package/dist/config/relay-config.d.ts +23 -0
- package/dist/config/relay-config.js +23 -0
- package/dist/daemon/agent-manager.d.ts +20 -1
- package/dist/daemon/agent-manager.js +51 -0
- package/dist/daemon/agent-registry.js +4 -4
- package/dist/daemon/agent-signing.d.ts +158 -0
- package/dist/daemon/agent-signing.js +523 -0
- package/dist/daemon/api.js +18 -1
- package/dist/daemon/cli-auth.d.ts +4 -1
- package/dist/daemon/cli-auth.js +55 -11
- package/dist/daemon/cloud-sync.d.ts +47 -1
- package/dist/daemon/cloud-sync.js +152 -3
- package/dist/daemon/connection.d.ts +28 -0
- package/dist/daemon/connection.js +113 -22
- package/dist/daemon/consensus-integration.d.ts +167 -0
- package/dist/daemon/consensus-integration.js +371 -0
- package/dist/daemon/consensus.d.ts +271 -0
- package/dist/daemon/consensus.js +632 -0
- package/dist/daemon/delivery-tracker.d.ts +34 -0
- package/dist/daemon/delivery-tracker.js +104 -0
- package/dist/daemon/enhanced-features.d.ts +118 -0
- package/dist/daemon/enhanced-features.js +178 -0
- package/dist/daemon/index.d.ts +4 -0
- package/dist/daemon/index.js +5 -0
- package/dist/daemon/rate-limiter.d.ts +68 -0
- package/dist/daemon/rate-limiter.js +130 -0
- package/dist/daemon/router.d.ts +18 -11
- package/dist/daemon/router.js +57 -113
- package/dist/daemon/server.d.ts +13 -1
- package/dist/daemon/server.js +71 -9
- package/dist/daemon/sync-queue.d.ts +116 -0
- package/dist/daemon/sync-queue.js +361 -0
- package/dist/dashboard/out/404.html +1 -1
- package/dist/dashboard/out/_next/static/chunks/116-de2a4ac06e5000dc.js +1 -0
- package/dist/dashboard/out/_next/static/chunks/847-f1f467060f32afff.js +1 -0
- package/dist/dashboard/out/_next/static/chunks/919-87d604a5d76c1fbd.js +1 -0
- package/dist/dashboard/out/_next/static/chunks/app/app/{page-c617745b81344f4f.js → page-7f64824ae7d06707.js} +1 -1
- package/dist/dashboard/out/_next/static/chunks/app/cloud/link/page-3f559d393902aad2.js +1 -0
- package/dist/dashboard/out/_next/static/chunks/app/login/page-16d1715ddaa874ee.js +1 -0
- package/dist/dashboard/out/_next/static/chunks/app/{page-dc786c183425c2ac.js → page-814efc4d77b4191d.js} +1 -1
- package/dist/dashboard/out/_next/static/chunks/{main-2ee6beb2ae96d210.js → main-5a40a5ae29646e1b.js} +1 -1
- package/dist/dashboard/out/_next/static/css/44d2b52637b511bc.css +1 -0
- package/dist/dashboard/out/app/onboarding.html +1 -1
- package/dist/dashboard/out/app/onboarding.txt +1 -1
- package/dist/dashboard/out/app.html +1 -1
- package/dist/dashboard/out/app.txt +2 -2
- package/dist/dashboard/out/cloud/link.html +1 -0
- package/dist/dashboard/out/cloud/link.txt +7 -0
- package/dist/dashboard/out/connect-repos.html +1 -1
- package/dist/dashboard/out/connect-repos.txt +1 -1
- package/dist/dashboard/out/history.html +1 -1
- package/dist/dashboard/out/history.txt +2 -2
- package/dist/dashboard/out/index.html +1 -1
- package/dist/dashboard/out/index.txt +2 -2
- package/dist/dashboard/out/login.html +2 -3
- package/dist/dashboard/out/login.txt +2 -2
- package/dist/dashboard/out/metrics.html +1 -1
- package/dist/dashboard/out/metrics.txt +2 -2
- package/dist/dashboard/out/pricing.html +2 -2
- package/dist/dashboard/out/pricing.txt +1 -1
- package/dist/dashboard/out/providers/setup/claude.html +1 -1
- package/dist/dashboard/out/providers/setup/claude.txt +1 -1
- package/dist/dashboard/out/providers/setup/codex.html +1 -1
- package/dist/dashboard/out/providers/setup/codex.txt +1 -1
- package/dist/dashboard/out/providers.html +1 -1
- package/dist/dashboard/out/providers.txt +1 -1
- package/dist/dashboard/out/signup.html +2 -2
- package/dist/dashboard/out/signup.txt +1 -1
- package/dist/dashboard-server/server.js +244 -28
- package/dist/health-worker-manager.d.ts +62 -0
- package/dist/health-worker-manager.js +144 -0
- package/dist/health-worker.d.ts +9 -0
- package/dist/health-worker.js +79 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -1
- package/dist/memory/context-compaction.d.ts +156 -0
- package/dist/memory/context-compaction.js +453 -0
- package/dist/memory/index.d.ts +1 -0
- package/dist/memory/index.js +1 -0
- package/dist/protocol/channels.js +4 -4
- package/dist/protocol/framing.d.ts +72 -10
- package/dist/protocol/framing.js +194 -25
- package/dist/storage/adapter.d.ts +8 -1
- package/dist/storage/adapter.js +11 -0
- package/dist/storage/batched-sqlite-adapter.d.ts +71 -0
- package/dist/storage/batched-sqlite-adapter.js +183 -0
- package/dist/storage/dead-letter-queue.d.ts +196 -0
- package/dist/storage/dead-letter-queue.js +427 -0
- package/dist/storage/dlq-adapter.d.ts +195 -0
- package/dist/storage/dlq-adapter.js +664 -0
- package/dist/trajectory/config.d.ts +32 -14
- package/dist/trajectory/config.js +38 -16
- package/dist/trajectory/integration.js +217 -64
- package/dist/utils/git-remote.d.ts +47 -0
- package/dist/utils/git-remote.js +125 -0
- package/dist/utils/id-generator.d.ts +35 -0
- package/dist/utils/id-generator.js +60 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/precompiled-patterns.d.ts +110 -0
- package/dist/utils/precompiled-patterns.js +322 -0
- package/dist/wrapper/auth-detection.js +1 -1
- package/dist/wrapper/base-wrapper.d.ts +40 -0
- package/dist/wrapper/base-wrapper.js +60 -6
- package/dist/wrapper/client.d.ts +14 -4
- package/dist/wrapper/client.js +89 -31
- package/dist/wrapper/idle-detector.d.ts +102 -0
- package/dist/wrapper/idle-detector.js +279 -0
- package/dist/wrapper/parser.d.ts +4 -0
- package/dist/wrapper/parser.js +19 -1
- package/dist/wrapper/pty-wrapper.d.ts +14 -2
- package/dist/wrapper/pty-wrapper.js +132 -32
- package/dist/wrapper/shared.d.ts +1 -1
- package/dist/wrapper/shared.js +1 -1
- package/dist/wrapper/tmux-wrapper.d.ts +20 -2
- package/dist/wrapper/tmux-wrapper.js +163 -40
- package/package.json +3 -1
- package/scripts/run-migrations.js +43 -0
- package/scripts/verify-schema.js +134 -0
- package/tests/benchmarks/protocol.bench.ts +310 -0
- package/dist/dashboard/out/_next/static/chunks/116-2502180def231162.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/899-fc02ed79e3de4302.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/login/page-c22d080201cbd9fb.js +0 -1
- package/dist/dashboard/out/_next/static/css/48a8fbe3e659080e.css +0 -1
- /package/dist/dashboard/out/_next/static/{sDcbGRTYLcpPvyTs_rsNb → R-uQOUcOLINtsp6ACeZa9}/_buildManifest.js +0 -0
- /package/dist/dashboard/out/_next/static/{sDcbGRTYLcpPvyTs_rsNb → R-uQOUcOLINtsp6ACeZa9}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Health Check Worker Thread
|
|
3
|
+
*
|
|
4
|
+
* Runs a minimal HTTP server on a separate thread to handle health checks.
|
|
5
|
+
* This ensures health checks respond even when the main event loop is blocked
|
|
6
|
+
* by heavy compute tasks (builds, large file operations, etc.).
|
|
7
|
+
*/
|
|
8
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
9
|
+
import http from 'node:http';
|
|
10
|
+
// Default stats until we receive updates from main thread
|
|
11
|
+
let currentStats = {
|
|
12
|
+
uptime: 0,
|
|
13
|
+
memoryMB: 0,
|
|
14
|
+
relayConnected: false,
|
|
15
|
+
agentCount: 0,
|
|
16
|
+
status: 'healthy',
|
|
17
|
+
};
|
|
18
|
+
// Track when we last received stats from main thread
|
|
19
|
+
let lastStatsUpdate = Date.now();
|
|
20
|
+
const STATS_STALE_THRESHOLD_MS = 60_000; // 1 minute
|
|
21
|
+
// Listen for stats updates from main thread
|
|
22
|
+
if (parentPort) {
|
|
23
|
+
parentPort.on('message', (stats) => {
|
|
24
|
+
currentStats = stats;
|
|
25
|
+
lastStatsUpdate = Date.now();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const { port } = workerData;
|
|
29
|
+
const server = http.createServer((req, res) => {
|
|
30
|
+
// Only handle /health endpoint
|
|
31
|
+
if (req.url !== '/health' && req.url !== '/') {
|
|
32
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
33
|
+
res.end(JSON.stringify({ error: 'Not found' }));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
// Check if stats are stale (main thread might be blocked)
|
|
37
|
+
const statsAge = Date.now() - lastStatsUpdate;
|
|
38
|
+
const isStale = statsAge > STATS_STALE_THRESHOLD_MS;
|
|
39
|
+
// Determine status
|
|
40
|
+
let status = currentStats.status;
|
|
41
|
+
if (isStale) {
|
|
42
|
+
status = 'busy'; // Main thread is likely blocked
|
|
43
|
+
}
|
|
44
|
+
const response = {
|
|
45
|
+
status,
|
|
46
|
+
uptime: currentStats.uptime,
|
|
47
|
+
memoryMB: currentStats.memoryMB,
|
|
48
|
+
relayConnected: currentStats.relayConnected,
|
|
49
|
+
agentCount: currentStats.agentCount,
|
|
50
|
+
statsAgeMs: statsAge,
|
|
51
|
+
worker: true, // Indicates response is from worker thread
|
|
52
|
+
};
|
|
53
|
+
// Return 200 for healthy/busy, 503 for degraded
|
|
54
|
+
const statusCode = status === 'degraded' ? 503 : 200;
|
|
55
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
56
|
+
res.end(JSON.stringify(response));
|
|
57
|
+
});
|
|
58
|
+
server.listen(port, '0.0.0.0', () => {
|
|
59
|
+
console.log(`[health-worker] Health check server listening on port ${port}`);
|
|
60
|
+
// Notify main thread we're ready
|
|
61
|
+
if (parentPort) {
|
|
62
|
+
parentPort.postMessage({ type: 'ready', port });
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
// Handle errors gracefully
|
|
66
|
+
server.on('error', (err) => {
|
|
67
|
+
console.error('[health-worker] Server error:', err);
|
|
68
|
+
if (parentPort) {
|
|
69
|
+
parentPort.postMessage({ type: 'error', error: String(err) });
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
// Keep the worker alive
|
|
73
|
+
process.on('uncaughtException', (err) => {
|
|
74
|
+
console.error('[health-worker] Uncaught exception:', err);
|
|
75
|
+
});
|
|
76
|
+
process.on('unhandledRejection', (err) => {
|
|
77
|
+
console.error('[health-worker] Unhandled rejection:', err);
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=health-worker.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -8,5 +8,6 @@ export * from './wrapper/index.js';
|
|
|
8
8
|
export * from './utils/index.js';
|
|
9
9
|
export * from './hooks/index.js';
|
|
10
10
|
export { type StoredMessage, type MessageQuery, type StorageAdapter, type StorageConfig, } from './storage/adapter.js';
|
|
11
|
-
export { type MemoryAdapter, type MemoryEntry, type MemoryConfig, type MemoryService, type MemorySearchQuery, type AddMemoryOptions, type MemoryResult, createMemoryAdapter, createMemoryService, createMemoryHooks, getMemoryHooks, InMemoryAdapter, SupermemoryAdapter, } from './memory/index.js';
|
|
11
|
+
export { type MemoryAdapter, type MemoryEntry, type MemoryConfig, type MemoryService, type MemorySearchQuery, type AddMemoryOptions, type MemoryResult, createMemoryAdapter, createMemoryService, createMemoryHooks, getMemoryHooks, InMemoryAdapter, SupermemoryAdapter, ContextCompactor, createContextCompactor, estimateTokens, estimateContextTokens, type CompactionConfig, type CompactionResult, } from './memory/index.js';
|
|
12
|
+
export { type DLQStorageAdapter, type DeadLetter, type DLQConfig, type DLQStats, type DLQQuery, SQLiteDLQAdapter, PostgresDLQAdapter, InMemoryDLQAdapter, createDLQAdapter, DEFAULT_DLQ_CONFIG, } from './storage/dlq-adapter.js';
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -8,5 +8,9 @@ export * from './wrapper/index.js';
|
|
|
8
8
|
export * from './utils/index.js';
|
|
9
9
|
export * from './hooks/index.js';
|
|
10
10
|
// Memory types and adapters for external consumers
|
|
11
|
-
export { createMemoryAdapter, createMemoryService, createMemoryHooks, getMemoryHooks, InMemoryAdapter, SupermemoryAdapter,
|
|
11
|
+
export { createMemoryAdapter, createMemoryService, createMemoryHooks, getMemoryHooks, InMemoryAdapter, SupermemoryAdapter,
|
|
12
|
+
// Context compaction
|
|
13
|
+
ContextCompactor, createContextCompactor, estimateTokens, estimateContextTokens, } from './memory/index.js';
|
|
14
|
+
// Dead Letter Queue adapters
|
|
15
|
+
export { SQLiteDLQAdapter, PostgresDLQAdapter, InMemoryDLQAdapter, createDLQAdapter, DEFAULT_DLQ_CONFIG, } from './storage/dlq-adapter.js';
|
|
12
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Compaction for Long Agent Sessions
|
|
3
|
+
*
|
|
4
|
+
* Manages conversation context to prevent token limit exhaustion.
|
|
5
|
+
* Provides token counting, message summarization, and context pruning.
|
|
6
|
+
*
|
|
7
|
+
* Inspired by russian-code-ts context management targets:
|
|
8
|
+
* - Token estimation: <20ms
|
|
9
|
+
* - Embeddings-based semantic search for relevant context
|
|
10
|
+
*
|
|
11
|
+
* Strategies:
|
|
12
|
+
* 1. Fast token estimation (character-based heuristic)
|
|
13
|
+
* 2. Importance-weighted message retention
|
|
14
|
+
* 3. Sliding window with summary injection
|
|
15
|
+
* 4. Semantic deduplication of similar messages
|
|
16
|
+
*/
|
|
17
|
+
export interface Message {
|
|
18
|
+
id: string;
|
|
19
|
+
role: 'user' | 'assistant' | 'system';
|
|
20
|
+
content: string;
|
|
21
|
+
timestamp: number;
|
|
22
|
+
/** Message importance (0-100, higher = more important) */
|
|
23
|
+
importance?: number;
|
|
24
|
+
/** Whether this is a summary message */
|
|
25
|
+
isSummary?: boolean;
|
|
26
|
+
/** Original message IDs if this is a summary */
|
|
27
|
+
summarizes?: string[];
|
|
28
|
+
/** Thread ID for grouping */
|
|
29
|
+
thread?: string;
|
|
30
|
+
/** Token count (cached) */
|
|
31
|
+
tokenCount?: number;
|
|
32
|
+
}
|
|
33
|
+
export interface ContextWindow {
|
|
34
|
+
messages: Message[];
|
|
35
|
+
totalTokens: number;
|
|
36
|
+
maxTokens: number;
|
|
37
|
+
usagePercent: number;
|
|
38
|
+
}
|
|
39
|
+
export interface CompactionResult {
|
|
40
|
+
/** Messages after compaction */
|
|
41
|
+
messages: Message[];
|
|
42
|
+
/** Number of messages removed */
|
|
43
|
+
messagesRemoved: number;
|
|
44
|
+
/** Tokens saved */
|
|
45
|
+
tokensSaved: number;
|
|
46
|
+
/** Summary message added (if any) */
|
|
47
|
+
summaryAdded?: Message;
|
|
48
|
+
/** Compaction strategy used */
|
|
49
|
+
strategy: CompactionStrategy;
|
|
50
|
+
}
|
|
51
|
+
export type CompactionStrategy = 'none' | 'trim_old' | 'trim_low_importance' | 'summarize' | 'deduplicate' | 'aggressive';
|
|
52
|
+
export interface CompactionConfig {
|
|
53
|
+
/** Maximum tokens for context window */
|
|
54
|
+
maxTokens: number;
|
|
55
|
+
/** Target token usage after compaction (e.g., 0.7 = 70%) */
|
|
56
|
+
targetUsage: number;
|
|
57
|
+
/** Threshold to trigger compaction (e.g., 0.9 = 90%) */
|
|
58
|
+
compactionThreshold: number;
|
|
59
|
+
/** Minimum importance to retain during compaction */
|
|
60
|
+
minImportanceRetain: number;
|
|
61
|
+
/** Number of recent messages to always keep */
|
|
62
|
+
keepRecentCount: number;
|
|
63
|
+
/** Enable summarization */
|
|
64
|
+
enableSummarization: boolean;
|
|
65
|
+
/** Enable semantic deduplication */
|
|
66
|
+
enableDeduplication: boolean;
|
|
67
|
+
/** Similarity threshold for deduplication (0-1) */
|
|
68
|
+
deduplicationThreshold: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Fast token estimation using character-based heuristic.
|
|
72
|
+
* Targets <20ms latency for large texts.
|
|
73
|
+
*
|
|
74
|
+
* Heuristic: ~4 characters per token for English text.
|
|
75
|
+
* Adjusts for code (more tokens per char) and whitespace.
|
|
76
|
+
*/
|
|
77
|
+
export declare function estimateTokens(text: string): number;
|
|
78
|
+
/**
|
|
79
|
+
* Estimate tokens for a message (uses caching).
|
|
80
|
+
*/
|
|
81
|
+
export declare function estimateMessageTokens(message: Message): number;
|
|
82
|
+
/**
|
|
83
|
+
* Estimate tokens for entire context.
|
|
84
|
+
*/
|
|
85
|
+
export declare function estimateContextTokens(messages: Message[]): number;
|
|
86
|
+
/**
|
|
87
|
+
* Calculate importance score for a message.
|
|
88
|
+
* Higher scores = more important to retain.
|
|
89
|
+
*/
|
|
90
|
+
export declare function calculateImportance(message: Message, index: number, total: number): number;
|
|
91
|
+
/**
|
|
92
|
+
* Simple similarity score between two strings (Jaccard on word set).
|
|
93
|
+
* Returns 0-1 where 1 = identical.
|
|
94
|
+
*/
|
|
95
|
+
export declare function calculateSimilarity(a: string, b: string): number;
|
|
96
|
+
/**
|
|
97
|
+
* Find duplicate/similar messages.
|
|
98
|
+
*/
|
|
99
|
+
export declare function findDuplicates(messages: Message[], threshold?: number): Map<string, string[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Create a summary of multiple messages.
|
|
102
|
+
* This is a simple extractive summary - in production, use an LLM.
|
|
103
|
+
*/
|
|
104
|
+
export declare function createSummary(messages: Message[]): Message;
|
|
105
|
+
/**
|
|
106
|
+
* Context compaction manager.
|
|
107
|
+
*/
|
|
108
|
+
export declare class ContextCompactor {
|
|
109
|
+
private config;
|
|
110
|
+
constructor(config?: Partial<CompactionConfig>);
|
|
111
|
+
/**
|
|
112
|
+
* Get current context window status.
|
|
113
|
+
*/
|
|
114
|
+
getContextWindow(messages: Message[]): ContextWindow;
|
|
115
|
+
/**
|
|
116
|
+
* Check if compaction is needed.
|
|
117
|
+
*/
|
|
118
|
+
needsCompaction(messages: Message[]): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Perform context compaction.
|
|
121
|
+
*/
|
|
122
|
+
compact(messages: Message[]): CompactionResult;
|
|
123
|
+
/**
|
|
124
|
+
* Add a message to context with automatic compaction if needed.
|
|
125
|
+
*/
|
|
126
|
+
addMessage(messages: Message[], newMessage: Message): {
|
|
127
|
+
messages: Message[];
|
|
128
|
+
compacted: boolean;
|
|
129
|
+
result?: CompactionResult;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Get token budget remaining.
|
|
133
|
+
*/
|
|
134
|
+
getTokenBudget(messages: Message[]): {
|
|
135
|
+
used: number;
|
|
136
|
+
remaining: number;
|
|
137
|
+
percentUsed: number;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Create a context compactor with the given configuration.
|
|
142
|
+
*/
|
|
143
|
+
export declare function createContextCompactor(config?: Partial<CompactionConfig>): ContextCompactor;
|
|
144
|
+
/**
|
|
145
|
+
* Format token count for display.
|
|
146
|
+
*/
|
|
147
|
+
export declare function formatTokenCount(tokens: number): string;
|
|
148
|
+
/**
|
|
149
|
+
* Benchmark token estimation performance.
|
|
150
|
+
*/
|
|
151
|
+
export declare function benchmarkTokenEstimation(iterations?: number): {
|
|
152
|
+
avgNs: number;
|
|
153
|
+
maxNs: number;
|
|
154
|
+
tokensPerMs: number;
|
|
155
|
+
};
|
|
156
|
+
//# sourceMappingURL=context-compaction.d.ts.map
|