lynkr 7.2.5 → 8.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.
Files changed (124) hide show
  1. package/README.md +3 -3
  2. package/config/model-tiers.json +89 -0
  3. package/install.sh +6 -1
  4. package/package.json +4 -2
  5. package/scripts/setup.js +0 -1
  6. package/src/agents/executor.js +14 -6
  7. package/src/api/middleware/session.js +15 -2
  8. package/src/api/openai-router.js +162 -37
  9. package/src/api/providers-handler.js +15 -1
  10. package/src/api/router.js +107 -2
  11. package/src/budget/index.js +4 -3
  12. package/src/clients/databricks.js +431 -234
  13. package/src/clients/gpt-utils.js +181 -0
  14. package/src/clients/ollama-utils.js +66 -140
  15. package/src/clients/routing.js +0 -1
  16. package/src/clients/standard-tools.js +99 -3
  17. package/src/config/index.js +133 -35
  18. package/src/context/toon.js +173 -0
  19. package/src/logger/index.js +23 -0
  20. package/src/orchestrator/index.js +688 -213
  21. package/src/routing/agentic-detector.js +320 -0
  22. package/src/routing/complexity-analyzer.js +202 -2
  23. package/src/routing/cost-optimizer.js +305 -0
  24. package/src/routing/index.js +168 -159
  25. package/src/routing/model-tiers.js +365 -0
  26. package/src/server.js +4 -14
  27. package/src/sessions/cleanup.js +3 -3
  28. package/src/sessions/record.js +10 -1
  29. package/src/sessions/store.js +7 -2
  30. package/src/tools/agent-task.js +48 -1
  31. package/src/tools/index.js +19 -2
  32. package/src/tools/lazy-loader.js +7 -0
  33. package/src/tools/tinyfish.js +358 -0
  34. package/src/tools/truncate.js +1 -0
  35. package/.github/FUNDING.yml +0 -15
  36. package/.github/workflows/README.md +0 -215
  37. package/.github/workflows/ci.yml +0 -69
  38. package/.github/workflows/index.yml +0 -62
  39. package/.github/workflows/web-tools-tests.yml +0 -56
  40. package/CITATIONS.bib +0 -6
  41. package/CLAWROUTER_ROUTING_PLAN.md +0 -910
  42. package/DEPLOYMENT.md +0 -1001
  43. package/LYNKR-TUI-PLAN.md +0 -984
  44. package/PERFORMANCE-REPORT.md +0 -866
  45. package/PLAN-per-client-model-routing.md +0 -252
  46. package/ROUTER_COMPARISON.md +0 -173
  47. package/TIER_ROUTING_PLAN.md +0 -771
  48. package/docs/42642f749da6234f41b6b425c3bb07c9.txt +0 -1
  49. package/docs/BingSiteAuth.xml +0 -4
  50. package/docs/docs-style.css +0 -478
  51. package/docs/docs.html +0 -197
  52. package/docs/google5be250e608e6da39.html +0 -1
  53. package/docs/index.html +0 -577
  54. package/docs/index.md +0 -577
  55. package/docs/robots.txt +0 -4
  56. package/docs/sitemap.xml +0 -44
  57. package/docs/style.css +0 -1223
  58. package/documentation/README.md +0 -100
  59. package/documentation/api.md +0 -806
  60. package/documentation/claude-code-cli.md +0 -672
  61. package/documentation/codex-cli.md +0 -397
  62. package/documentation/contributing.md +0 -571
  63. package/documentation/cursor-integration.md +0 -731
  64. package/documentation/docker.md +0 -867
  65. package/documentation/embeddings.md +0 -760
  66. package/documentation/faq.md +0 -659
  67. package/documentation/features.md +0 -396
  68. package/documentation/headroom.md +0 -519
  69. package/documentation/installation.md +0 -706
  70. package/documentation/memory-system.md +0 -476
  71. package/documentation/production.md +0 -601
  72. package/documentation/providers.md +0 -906
  73. package/documentation/testing.md +0 -629
  74. package/documentation/token-optimization.md +0 -323
  75. package/documentation/tools.md +0 -697
  76. package/documentation/troubleshooting.md +0 -893
  77. package/final-test.js +0 -33
  78. package/headroom-sidecar/config.py +0 -93
  79. package/headroom-sidecar/requirements.txt +0 -14
  80. package/headroom-sidecar/server.py +0 -451
  81. package/monitor-agents.sh +0 -31
  82. package/scripts/audit-log-reader.js +0 -399
  83. package/scripts/compact-dictionary.js +0 -204
  84. package/scripts/test-deduplication.js +0 -448
  85. package/src/db/database.sqlite +0 -0
  86. package/test/README.md +0 -212
  87. package/test/azure-openai-config.test.js +0 -204
  88. package/test/azure-openai-error-resilience.test.js +0 -238
  89. package/test/azure-openai-format-conversion.test.js +0 -354
  90. package/test/azure-openai-integration.test.js +0 -281
  91. package/test/azure-openai-routing.test.js +0 -177
  92. package/test/azure-openai-streaming.test.js +0 -171
  93. package/test/bedrock-integration.test.js +0 -471
  94. package/test/comprehensive-test-suite.js +0 -928
  95. package/test/config-validation.test.js +0 -207
  96. package/test/cursor-integration.test.js +0 -484
  97. package/test/format-conversion.test.js +0 -578
  98. package/test/hybrid-routing-integration.test.js +0 -254
  99. package/test/hybrid-routing-performance.test.js +0 -418
  100. package/test/llamacpp-integration.test.js +0 -863
  101. package/test/lmstudio-integration.test.js +0 -335
  102. package/test/memory/extractor.test.js +0 -398
  103. package/test/memory/retriever.test.js +0 -613
  104. package/test/memory/retriever.test.js.bak +0 -585
  105. package/test/memory/search.test.js +0 -537
  106. package/test/memory/search.test.js.bak +0 -389
  107. package/test/memory/store.test.js +0 -344
  108. package/test/memory/store.test.js.bak +0 -312
  109. package/test/memory/surprise.test.js +0 -300
  110. package/test/memory-performance.test.js +0 -472
  111. package/test/openai-integration.test.js +0 -686
  112. package/test/openrouter-error-resilience.test.js +0 -418
  113. package/test/passthrough-mode.test.js +0 -385
  114. package/test/performance-benchmark.js +0 -351
  115. package/test/performance-tests.js +0 -528
  116. package/test/routing.test.js +0 -219
  117. package/test/web-tools.test.js +0 -329
  118. package/test-agents-simple.js +0 -43
  119. package/test-cli-connection.sh +0 -33
  120. package/test-learning-unit.js +0 -126
  121. package/test-learning.js +0 -112
  122. package/test-parallel-agents.sh +0 -124
  123. package/test-parallel-direct.js +0 -155
  124. package/test-subagents.sh +0 -117
@@ -1,351 +0,0 @@
1
- /**
2
- * Comprehensive Performance Benchmark
3
- *
4
- * Measures performance impact of all production hardening features:
5
- * - Option 1: Retries, budgets, rate limits, path allowlisting, sandboxing, safe commands
6
- * - Option 2 & 3: Metrics, health checks, logging, error handling, validation, load shedding, circuit breakers
7
- *
8
- * Key Metrics:
9
- * - Request throughput (req/s)
10
- * - Latency (p50, p95, p99)
11
- * - Memory usage
12
- * - CPU usage
13
- * - Overhead per middleware
14
- */
15
-
16
- const { performance } = require("perf_hooks");
17
- const { MetricsCollector } = require("../src/observability/metrics");
18
- const { LoadShedder } = require("../src/api/middleware/load-shedding");
19
- const { CircuitBreaker } = require("../src/clients/circuit-breaker");
20
- const { validateObject } = require("../src/api/middleware/validation");
21
-
22
- // Color utilities
23
- function colorize(text, color) {
24
- const colors = {
25
- green: "\x1b[32m",
26
- red: "\x1b[31m",
27
- yellow: "\x1b[33m",
28
- blue: "\x1b[34m",
29
- cyan: "\x1b[36m",
30
- reset: "\x1b[0m",
31
- };
32
- return `${colors[color] || ""}${text}${colors.reset}`;
33
- }
34
-
35
- // =============================================================================
36
- // Benchmark Utilities
37
- // =============================================================================
38
-
39
- async function benchmark(name, iterations, fn) {
40
- console.log(colorize(`\n📊 ${name}`, "cyan"));
41
- console.log(` Iterations: ${iterations.toLocaleString()}`);
42
-
43
- // Warmup
44
- for (let i = 0; i < Math.min(iterations / 10, 1000); i++) {
45
- await fn();
46
- }
47
-
48
- // Force GC if available
49
- if (global.gc) {
50
- global.gc();
51
- }
52
-
53
- const memBefore = process.memoryUsage();
54
- const cpuBefore = process.cpuUsage();
55
- const startTime = performance.now();
56
-
57
- // Run benchmark
58
- for (let i = 0; i < iterations; i++) {
59
- await fn();
60
- }
61
-
62
- const endTime = performance.now();
63
- const cpuAfter = process.cpuUsage();
64
- const memAfter = process.memoryUsage();
65
-
66
- // Calculate metrics
67
- const totalTime = endTime - startTime;
68
- const avgTime = totalTime / iterations;
69
- const throughput = (iterations / totalTime) * 1000; // ops/sec
70
-
71
- const cpuUser = (cpuAfter.user - cpuBefore.user) / 1000; // ms
72
- const cpuSystem = (cpuAfter.system - cpuBefore.system) / 1000; // ms
73
- const cpuTotal = cpuUser + cpuSystem;
74
-
75
- const memUsed = (memAfter.heapUsed - memBefore.heapUsed) / 1024 / 1024; // MB
76
-
77
- // Results
78
- console.log(` ${colorize("Duration:", "blue")} ${totalTime.toFixed(2)}ms`);
79
- console.log(` ${colorize("Avg/op:", "blue")} ${avgTime.toFixed(4)}ms`);
80
- console.log(` ${colorize("Throughput:", "green")} ${throughput.toLocaleString("en-US", { maximumFractionDigits: 0 })} ops/sec`);
81
- console.log(` ${colorize("CPU:", "yellow")} ${cpuTotal.toFixed(2)}ms (user: ${cpuUser.toFixed(2)}ms, system: ${cpuSystem.toFixed(2)}ms)`);
82
- console.log(` ${colorize("Memory:", "yellow")} ${memUsed >= 0 ? "+" : ""}${memUsed.toFixed(2)}MB`);
83
-
84
- return {
85
- name,
86
- iterations,
87
- totalTime,
88
- avgTime,
89
- throughput,
90
- cpu: {
91
- user: cpuUser,
92
- system: cpuSystem,
93
- total: cpuTotal,
94
- },
95
- memory: memUsed,
96
- };
97
- }
98
-
99
- // =============================================================================
100
- // Benchmarks
101
- // =============================================================================
102
-
103
- async function runBenchmarks() {
104
- console.log(colorize("\n╔═══════════════════════════════════════════════════╗", "blue"));
105
- console.log(colorize("║ Performance Benchmark Suite ║", "blue"));
106
- console.log(colorize("╚═══════════════════════════════════════════════════╝", "blue"));
107
-
108
- const results = [];
109
-
110
- // Baseline: No-op function
111
- results.push(
112
- await benchmark("Baseline (no-op)", 1000000, async () => {
113
- return true;
114
- })
115
- );
116
-
117
- // Metrics Collection
118
- results.push(
119
- await benchmark("Metrics Collection", 100000, async () => {
120
- const metrics = new MetricsCollector();
121
- metrics.recordRequest("GET", "/test", 200, 100);
122
- metrics.recordTokens(100, 50);
123
- metrics.recordCost(0.01);
124
- })
125
- );
126
-
127
- // Metrics Snapshot (lazy calculation)
128
- results.push(
129
- await benchmark("Metrics Snapshot", 10000, async () => {
130
- const metrics = new MetricsCollector();
131
- for (let i = 0; i < 100; i++) {
132
- metrics.recordRequest("GET", "/test", 200, Math.random() * 200);
133
- }
134
- metrics.getMetrics();
135
- })
136
- );
137
-
138
- // Prometheus Export
139
- results.push(
140
- await benchmark("Prometheus Export", 10000, async () => {
141
- const metrics = new MetricsCollector();
142
- for (let i = 0; i < 100; i++) {
143
- metrics.recordRequest("GET", "/test", 200, Math.random() * 200);
144
- }
145
- metrics.toPrometheus();
146
- })
147
- );
148
-
149
- // Load Shedding Check (not overloaded)
150
- results.push(
151
- await benchmark("Load Shedding Check", 100000, async () => {
152
- const shedder = new LoadShedder();
153
- shedder.isOverloaded();
154
- })
155
- );
156
-
157
- // Circuit Breaker (closed state)
158
- results.push(
159
- await benchmark("Circuit Breaker (closed)", 100000, async () => {
160
- const breaker = new CircuitBreaker("test");
161
- await breaker.execute(async () => "success");
162
- })
163
- );
164
-
165
- // Input Validation (simple)
166
- results.push(
167
- await benchmark("Input Validation (simple)", 100000, async () => {
168
- const schema = {
169
- required: ["name"],
170
- properties: {
171
- name: { type: "string", minLength: 1, maxLength: 100 },
172
- },
173
- };
174
- validateObject({ name: "test" }, schema);
175
- })
176
- );
177
-
178
- // Input Validation (complex)
179
- results.push(
180
- await benchmark("Input Validation (complex)", 10000, async () => {
181
- const schema = {
182
- required: ["model", "messages"],
183
- properties: {
184
- model: { type: "string", minLength: 1 },
185
- messages: {
186
- type: "array",
187
- minItems: 1,
188
- items: {
189
- type: "object",
190
- required: ["role", "content"],
191
- properties: {
192
- role: { type: "string", enum: ["user", "assistant", "system"] },
193
- content: { type: "string", minLength: 1 },
194
- },
195
- },
196
- },
197
- temperature: { type: "number", minimum: 0, maximum: 2 },
198
- },
199
- };
200
-
201
- validateObject(
202
- {
203
- model: "test-model",
204
- messages: [
205
- { role: "user", content: "Hello" },
206
- { role: "assistant", content: "Hi there" },
207
- ],
208
- temperature: 0.7,
209
- },
210
- schema
211
- );
212
- })
213
- );
214
-
215
- // Request ID Generation
216
- results.push(
217
- await benchmark("Request ID Generation", 100000, async () => {
218
- const crypto = require("crypto");
219
- crypto.randomBytes(16).toString("hex");
220
- })
221
- );
222
-
223
- // Combined middleware stack simulation
224
- results.push(
225
- await benchmark("Combined Middleware Stack", 10000, async () => {
226
- // Simulate request flowing through all middleware
227
- const requestId = require("crypto").randomBytes(16).toString("hex");
228
-
229
- const metrics = new MetricsCollector();
230
- const shedder = new LoadShedder();
231
-
232
- // Load shedding check
233
- if (!shedder.isOverloaded()) {
234
- // Metrics collection
235
- const start = performance.now();
236
- metrics.recordRequest("POST", "/v1/messages", 200, 0);
237
-
238
- // Validation
239
- const schema = {
240
- required: ["model"],
241
- properties: {
242
- model: { type: "string" },
243
- },
244
- };
245
- validateObject({ model: "test" }, schema);
246
-
247
- // Record latency
248
- const latency = performance.now() - start;
249
- metrics.recordRequest("POST", "/v1/messages", 200, latency);
250
- }
251
- })
252
- );
253
-
254
- // =============================================================================
255
- // Summary
256
- // =============================================================================
257
-
258
- console.log(colorize("\n╔═══════════════════════════════════════════════════╗", "blue"));
259
- console.log(colorize("║ Performance Summary ║", "blue"));
260
- console.log(colorize("╚═══════════════════════════════════════════════════╝", "blue"));
261
-
262
- const baseline = results[0];
263
-
264
- console.log(colorize("\n📈 Throughput Comparison", "cyan"));
265
- console.log(colorize("─".repeat(80), "blue"));
266
- console.log(
267
- `${"Benchmark".padEnd(40)} ${"Throughput".padEnd(20)} ${"Overhead".padEnd(20)}`
268
- );
269
- console.log(colorize("─".repeat(80), "blue"));
270
-
271
- for (const result of results) {
272
- const overhead =
273
- result.name === baseline.name
274
- ? "-"
275
- : `${((baseline.throughput / result.throughput - 1) * 100).toFixed(1)}%`;
276
-
277
- const throughputStr = `${result.throughput.toLocaleString("en-US", { maximumFractionDigits: 0 })} ops/s`;
278
-
279
- console.log(`${result.name.padEnd(40)} ${throughputStr.padEnd(20)} ${overhead.padEnd(20)}`);
280
- }
281
-
282
- console.log(colorize("\n⏱️ Latency Comparison", "cyan"));
283
- console.log(colorize("─".repeat(80), "blue"));
284
- console.log(
285
- `${"Benchmark".padEnd(40)} ${"Avg Latency".padEnd(20)} ${"vs Baseline".padEnd(20)}`
286
- );
287
- console.log(colorize("─".repeat(80), "blue"));
288
-
289
- for (const result of results) {
290
- const vsBaseline =
291
- result.name === baseline.name
292
- ? "-"
293
- : `+${(result.avgTime - baseline.avgTime).toFixed(4)}ms`;
294
-
295
- console.log(
296
- `${result.name.padEnd(40)} ${result.avgTime.toFixed(4)}ms${"".padEnd(12)} ${vsBaseline.padEnd(20)}`
297
- );
298
- }
299
-
300
- console.log(colorize("\n💾 Memory Impact", "cyan"));
301
- console.log(colorize("─".repeat(60), "blue"));
302
- for (const result of results) {
303
- const memStr = result.memory >= 0 ? `+${result.memory.toFixed(2)}MB` : `${result.memory.toFixed(2)}MB`;
304
- console.log(`${result.name.padEnd(40)} ${memStr}`);
305
- }
306
-
307
- console.log(colorize("\n🔥 Key Insights", "yellow"));
308
- console.log(colorize("─".repeat(60), "blue"));
309
-
310
- const metricsResult = results.find((r) => r.name === "Metrics Collection");
311
- const stackResult = results.find((r) => r.name === "Combined Middleware Stack");
312
-
313
- console.log(
314
- `✓ Metrics collection: ${colorize(metricsResult.throughput.toLocaleString() + " ops/sec", "green")} (${((baseline.throughput / metricsResult.throughput - 1) * 100).toFixed(1)}% overhead)`
315
- );
316
- console.log(
317
- `✓ Full middleware stack: ${colorize(stackResult.throughput.toLocaleString() + " ops/sec", "green")} (${((baseline.throughput / stackResult.throughput - 1) * 100).toFixed(1)}% overhead)`
318
- );
319
- console.log(
320
- `✓ Average latency added: ${colorize((stackResult.avgTime - baseline.avgTime).toFixed(4) + "ms", "cyan")}`
321
- );
322
-
323
- // Performance rating
324
- const totalOverhead = ((baseline.throughput / stackResult.throughput - 1) * 100);
325
- let rating, color;
326
- if (totalOverhead < 5) {
327
- rating = "EXCELLENT";
328
- color = "green";
329
- } else if (totalOverhead < 15) {
330
- rating = "GOOD";
331
- color = "green";
332
- } else if (totalOverhead < 30) {
333
- rating = "ACCEPTABLE";
334
- color = "yellow";
335
- } else {
336
- rating = "NEEDS OPTIMIZATION";
337
- color = "red";
338
- }
339
-
340
- console.log(
341
- `\n🏆 Overall Performance Rating: ${colorize(rating, color)} (${totalOverhead.toFixed(1)}% total overhead)`
342
- );
343
-
344
- console.log(colorize("\n" + "=".repeat(60), "blue"));
345
- }
346
-
347
- // Run benchmarks
348
- runBenchmarks().catch((err) => {
349
- console.error("Benchmark error:", err);
350
- process.exit(1);
351
- });