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,219 +0,0 @@
1
- const assert = require("assert");
2
- const { describe, it, beforeEach, afterEach } = require("node:test");
3
-
4
- describe("Routing Logic", () => {
5
- let config;
6
- let routing;
7
- let originalConfig;
8
-
9
- beforeEach(() => {
10
- // Clear module cache to get fresh instances
11
- delete require.cache[require.resolve("../src/config/index.js")];
12
- delete require.cache[require.resolve("../src/clients/routing")];
13
- delete require.cache[require.resolve("../src/routing/index.js")];
14
- delete require.cache[require.resolve("../src/clients/ollama-utils")];
15
-
16
- // Store original config
17
- originalConfig = { ...process.env };
18
-
19
- // Explicitly set valid fallback to override any local .env pollution (e.g. lmstudio)
20
- process.env.FALLBACK_PROVIDER = "databricks";
21
- });
22
-
23
- afterEach(() => {
24
- // Restore original environment
25
- process.env = originalConfig;
26
- });
27
-
28
- describe("determineProvider()", () => {
29
- it("should return configured provider when PREFER_OLLAMA is false", () => {
30
- process.env.MODEL_PROVIDER = "databricks";
31
- process.env.PREFER_OLLAMA = "false";
32
-
33
- config = require("../src/config");
34
- routing = require("../src/clients/routing");
35
-
36
- const payload = { messages: [{ role: "user", content: "test" }] };
37
- const provider = routing.determineProvider(payload);
38
-
39
- assert.strictEqual(provider, "databricks");
40
- });
41
-
42
- it("should route to ollama when no tools and PREFER_OLLAMA is true", () => {
43
- process.env.MODEL_PROVIDER = "ollama";
44
- process.env.PREFER_OLLAMA = "true";
45
- process.env.OLLAMA_MODEL = "qwen2.5-coder:latest";
46
-
47
- config = require("../src/config");
48
- routing = require("../src/clients/routing");
49
-
50
- const payload = {
51
- messages: [{ role: "user", content: "test" }],
52
- tools: [],
53
- };
54
-
55
- const provider = routing.determineProvider(payload);
56
- assert.strictEqual(provider, "ollama");
57
- });
58
-
59
- it("should route to ollama when tool count < threshold", () => {
60
- process.env.MODEL_PROVIDER = "ollama";
61
- process.env.PREFER_OLLAMA = "true";
62
- process.env.OLLAMA_MODEL = "qwen2.5-coder:latest";
63
- process.env.OLLAMA_MAX_TOOLS_FOR_ROUTING = "3";
64
-
65
- config = require("../src/config");
66
- routing = require("../src/clients/routing");
67
-
68
- const payload = {
69
- messages: [{ role: "user", content: "test" }],
70
- tools: [
71
- { name: "tool1", description: "test" },
72
- { name: "tool2", description: "test" },
73
- ],
74
- };
75
-
76
- const provider = routing.determineProvider(payload);
77
- assert.strictEqual(provider, "ollama");
78
- });
79
-
80
- it("should route to cloud when tool count >= threshold", () => {
81
- process.env.MODEL_PROVIDER = "ollama";
82
- process.env.PREFER_OLLAMA = "true";
83
- process.env.OLLAMA_MODEL = "qwen2.5-coder:latest";
84
- process.env.OLLAMA_MAX_TOOLS_FOR_ROUTING = "3";
85
- process.env.OPENROUTER_MAX_TOOLS_FOR_ROUTING = "3"; // Set same as ollama to skip openrouter tier
86
- process.env.FALLBACK_PROVIDER = "databricks";
87
- process.env.FALLBACK_ENABLED = "true"; // Ensure fallback is enabled
88
- process.env.DATABRICKS_API_KEY = "test-key";
89
- process.env.DATABRICKS_API_BASE = "http://test.com";
90
- // Set Azure OpenAI to empty to prevent dotenv from loading .env values
91
- // dotenv won't override existing vars, even if empty
92
- process.env.AZURE_OPENAI_ENDPOINT = "";
93
- process.env.AZURE_OPENAI_API_KEY = "";
94
- process.env.OPENROUTER_API_KEY = "";
95
-
96
- config = require("../src/config");
97
- routing = require("../src/clients/routing");
98
-
99
- const payload = {
100
- messages: [{ role: "user", content: "test" }],
101
- tools: [
102
- { name: "tool1", description: "test" },
103
- { name: "tool2", description: "test" },
104
- { name: "tool3", description: "test" },
105
- { name: "tool4", description: "test" },
106
- { name: "tool5", description: "test" },
107
- ],
108
- };
109
-
110
- const provider = routing.determineProvider(payload);
111
- assert.strictEqual(provider, "databricks");
112
- });
113
-
114
- it("should route to cloud when model doesn't support tools", () => {
115
- process.env.MODEL_PROVIDER = "ollama";
116
- process.env.PREFER_OLLAMA = "true";
117
- process.env.OLLAMA_MODEL = "llama3:latest"; // Non-tool-capable model
118
- process.env.OLLAMA_FALLBACK_PROVIDER = "databricks";
119
- process.env.FALLBACK_ENABLED = "true"; // Ensure fallback is enabled
120
- process.env.DATABRICKS_API_KEY = "test-key";
121
- process.env.DATABRICKS_API_BASE = "http://test.com";
122
-
123
- config = require("../src/config");
124
- routing = require("../src/clients/routing");
125
-
126
- const payload = {
127
- messages: [{ role: "user", content: "test" }],
128
- tools: [{ name: "tool1", description: "test" }],
129
- };
130
-
131
- const provider = routing.determineProvider(payload);
132
- assert.strictEqual(provider, "databricks");
133
- });
134
-
135
- it("should use custom max tools threshold", () => {
136
- process.env.MODEL_PROVIDER = "ollama";
137
- process.env.PREFER_OLLAMA = "true";
138
- process.env.OLLAMA_MODEL = "qwen2.5-coder:latest";
139
- process.env.OLLAMA_MAX_TOOLS_FOR_ROUTING = "5";
140
- process.env.OLLAMA_FALLBACK_PROVIDER = "databricks";
141
- process.env.DATABRICKS_API_KEY = "test-key";
142
- process.env.DATABRICKS_API_BASE = "http://test.com";
143
-
144
- config = require("../src/config");
145
- routing = require("../src/clients/routing");
146
-
147
- const payload = {
148
- messages: [{ role: "user", content: "test" }],
149
- tools: [
150
- { name: "tool1", description: "test" },
151
- { name: "tool2", description: "test" },
152
- { name: "tool3", description: "test" },
153
- { name: "tool4", description: "test" },
154
- ],
155
- };
156
-
157
- // 4 tools < 5, should route to ollama
158
- const provider = routing.determineProvider(payload);
159
- assert.strictEqual(provider, "ollama");
160
- });
161
- });
162
-
163
- describe("isFallbackEnabled()", () => {
164
- it("should return true by default", () => {
165
- process.env.MODEL_PROVIDER = "ollama";
166
- process.env.PREFER_OLLAMA = "true";
167
- process.env.OLLAMA_MODEL = "qwen2.5-coder:latest";
168
- // Override .env file which sets FALLBACK_ENABLED=false
169
- // Test default behavior when not set to "false"
170
- process.env.FALLBACK_ENABLED = "true";
171
-
172
- config = require("../src/config");
173
- routing = require("../src/clients/routing");
174
-
175
- assert.strictEqual(routing.isFallbackEnabled(), true);
176
- });
177
-
178
- it("should return false when explicitly disabled", () => {
179
- process.env.MODEL_PROVIDER = "ollama";
180
- process.env.PREFER_OLLAMA = "true";
181
- process.env.OLLAMA_MODEL = "qwen2.5-coder:latest";
182
- process.env.FALLBACK_ENABLED = "false";
183
-
184
- config = require("../src/config");
185
- routing = require("../src/clients/routing");
186
-
187
- assert.strictEqual(routing.isFallbackEnabled(), false);
188
- });
189
- });
190
-
191
- describe("getFallbackProvider()", () => {
192
- it("should return databricks by default", () => {
193
- process.env.MODEL_PROVIDER = "ollama";
194
- process.env.PREFER_OLLAMA = "true";
195
- process.env.OLLAMA_MODEL = "qwen2.5-coder:latest";
196
- process.env.DATABRICKS_API_KEY = "test-key";
197
- process.env.DATABRICKS_API_BASE = "http://test.com";
198
-
199
- config = require("../src/config");
200
- routing = require("../src/clients/routing");
201
-
202
- assert.strictEqual(routing.getFallbackProvider(), "databricks");
203
- });
204
-
205
- it("should return configured fallback provider", () => {
206
- process.env.MODEL_PROVIDER = "ollama";
207
- process.env.PREFER_OLLAMA = "true";
208
- process.env.OLLAMA_MODEL = "qwen2.5-coder:latest";
209
- process.env.FALLBACK_PROVIDER = "azure-anthropic";
210
- process.env.AZURE_ANTHROPIC_ENDPOINT = "http://test.com";
211
- process.env.AZURE_ANTHROPIC_API_KEY = "test-key";
212
-
213
- config = require("../src/config");
214
- routing = require("../src/clients/routing");
215
-
216
- assert.strictEqual(routing.getFallbackProvider(), "azure-anthropic");
217
- });
218
- });
219
- });
@@ -1,329 +0,0 @@
1
- const { describe, it, before, after } = require("node:test");
2
- const assert = require("node:assert");
3
- const http = require("http");
4
-
5
- // Mock configuration
6
- process.env.MODEL_PROVIDER = "databricks"; // Override any .env settings
7
- process.env.DATABRICKS_API_KEY = "test-key";
8
- process.env.DATABRICKS_API_BASE = "http://test.com";
9
- process.env.WEB_SEARCH_ENDPOINT = "http://localhost:9999/search";
10
- process.env.WEB_SEARCH_TIMEOUT_MS = "5000";
11
- process.env.WEB_FETCH_BODY_PREVIEW_MAX = "1000";
12
- process.env.WEB_SEARCH_RETRY_ENABLED = "true";
13
- process.env.WEB_SEARCH_MAX_RETRIES = "2";
14
-
15
- const config = require("../src/config");
16
- const { webAgent, getAgentStats, fetchWithAgent } = require("../src/tools/web-client");
17
-
18
- describe("Web Tools Tests", () => {
19
- describe("HTML Extraction", () => {
20
- // Import the extraction function by loading the module
21
- let extractTextFromHtml;
22
-
23
- before(() => {
24
- // Recreate the HTML extraction function for testing
25
- extractTextFromHtml = function(html) {
26
- if (typeof html !== "string") return "";
27
- let text = html;
28
- text = text.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, " ");
29
- text = text.replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, " ");
30
- text = text.replace(/<!--[\s\S]*?-->/g, " ");
31
- text = text.replace(/<\/(div|p|br|h[1-6]|li|tr|section|article|header|footer|nav)>/gi, "\n");
32
- text = text.replace(/<[^>]+>/g, " ");
33
- text = text
34
- .replace(/&nbsp;/g, " ")
35
- .replace(/&amp;/g, "&")
36
- .replace(/&lt;/g, "<")
37
- .replace(/&gt;/g, ">")
38
- .replace(/&quot;/g, '"')
39
- .replace(/&#39;/g, "'")
40
- .replace(/&apos;/g, "'");
41
- text = text.replace(/\r\n/g, "\n");
42
- text = text.replace(/\r/g, "\n");
43
- text = text.replace(/[ \t]+/g, " ");
44
- text = text.replace(/\n\s+/g, "\n");
45
- text = text.replace(/\n{3,}/g, "\n\n");
46
- return text.trim();
47
- };
48
- });
49
-
50
- it("should extract text from simple HTML", () => {
51
- const html = "<p>Hello World</p>";
52
- const result = extractTextFromHtml(html);
53
- assert.strictEqual(result, "Hello World");
54
- });
55
-
56
- it("should remove script tags and content", () => {
57
- const html = "<div>Content<script>alert('test')</script>More</div>";
58
- const result = extractTextFromHtml(html);
59
- assert.ok(!result.includes("alert"));
60
- assert.ok(result.includes("Content"));
61
- assert.ok(result.includes("More"));
62
- });
63
-
64
- it("should remove style tags and content", () => {
65
- const html = "<div>Text<style>body { color: red; }</style>More</div>";
66
- const result = extractTextFromHtml(html);
67
- assert.ok(!result.includes("color"));
68
- assert.ok(result.includes("Text"));
69
- assert.ok(result.includes("More"));
70
- });
71
-
72
- it("should decode HTML entities", () => {
73
- const html = "<p>&nbsp;&amp;&lt;&gt;&quot;&#39;</p>";
74
- const result = extractTextFromHtml(html);
75
- assert.ok(result.includes("&"));
76
- assert.ok(result.includes("<"));
77
- assert.ok(result.includes(">"));
78
- assert.ok(result.includes('"'));
79
- assert.ok(result.includes("'"));
80
- });
81
-
82
- it("should convert block elements to newlines", () => {
83
- const html = "<div>Line 1</div><p>Line 2</p><h1>Line 3</h1>";
84
- const result = extractTextFromHtml(html);
85
- const lines = result.split("\n").filter(l => l.trim());
86
- assert.strictEqual(lines.length, 3);
87
- });
88
-
89
- it("should normalize whitespace", () => {
90
- const html = "<p>Text with spaces</p>";
91
- const result = extractTextFromHtml(html);
92
- assert.strictEqual(result, "Text with spaces");
93
- });
94
-
95
- it("should handle empty or non-string input", () => {
96
- assert.strictEqual(extractTextFromHtml(""), "");
97
- assert.strictEqual(extractTextFromHtml(null), "");
98
- assert.strictEqual(extractTextFromHtml(undefined), "");
99
- assert.strictEqual(extractTextFromHtml(123), "");
100
- });
101
-
102
- it("should remove HTML comments", () => {
103
- const html = "<div>Text<!-- comment here -->More</div>";
104
- const result = extractTextFromHtml(html);
105
- assert.ok(!result.includes("comment"));
106
- assert.ok(result.includes("Text"));
107
- assert.ok(result.includes("More"));
108
- });
109
-
110
- it("should handle complex nested HTML", () => {
111
- const html = `
112
- <html>
113
- <head><title>Test</title></head>
114
- <body>
115
- <header><h1>Title</h1></header>
116
- <div class="content">
117
- <p>Paragraph 1</p>
118
- <ul>
119
- <li>Item 1</li>
120
- <li>Item 2</li>
121
- </ul>
122
- </div>
123
- <footer>Footer</footer>
124
- </body>
125
- </html>
126
- `;
127
- const result = extractTextFromHtml(html);
128
- assert.ok(result.includes("Test"));
129
- assert.ok(result.includes("Title"));
130
- assert.ok(result.includes("Paragraph 1"));
131
- assert.ok(result.includes("Item 1"));
132
- assert.ok(result.includes("Footer"));
133
- });
134
- });
135
-
136
- describe("Web Client Agent", () => {
137
- it("should create agent with correct configuration", () => {
138
- assert.ok(webAgent, "Agent should be created");
139
- const stats = getAgentStats();
140
- assert.strictEqual(stats.agent, "undici");
141
- assert.strictEqual(stats.keepAlive, true);
142
- assert.strictEqual(stats.maxConnections, 50);
143
- assert.strictEqual(stats.pipelining, 10);
144
- });
145
-
146
- it("should have fetchWithAgent function", () => {
147
- assert.strictEqual(typeof fetchWithAgent, "function");
148
- });
149
- });
150
-
151
- describe("Configuration", () => {
152
- it("should load web search configuration correctly", () => {
153
- assert.ok(config.webSearch, "webSearch config should exist");
154
- assert.strictEqual(config.webSearch.enabled, true);
155
- assert.strictEqual(config.webSearch.endpoint, "http://localhost:9999/search");
156
- assert.strictEqual(config.webSearch.timeoutMs, 5000);
157
- assert.strictEqual(config.webSearch.bodyPreviewMax, 1000);
158
- assert.strictEqual(config.webSearch.retryEnabled, true);
159
- assert.strictEqual(config.webSearch.maxRetries, 2);
160
- });
161
-
162
- it("should have retry configuration", () => {
163
- assert.strictEqual(config.webSearch.retryEnabled, true);
164
- assert.strictEqual(config.webSearch.maxRetries, 2);
165
- });
166
-
167
- it("should have configurable body preview max", () => {
168
- assert.strictEqual(config.webSearch.bodyPreviewMax, 1000);
169
- });
170
- });
171
-
172
- describe("Retry Logic Integration", () => {
173
- let mockServer;
174
- let requestCounts;
175
-
176
- before((done) => {
177
- requestCounts = {};
178
- mockServer = http.createServer((req, res) => {
179
- const url = req.url;
180
- requestCounts[url] = (requestCounts[url] || 0) + 1;
181
-
182
- if (url === "/fail-twice") {
183
- if (requestCounts[url] <= 2) {
184
- res.writeHead(500, { "Content-Type": "application/json" });
185
- res.end(JSON.stringify({ error: "Server error" }));
186
- } else {
187
- res.writeHead(200, { "Content-Type": "application/json" });
188
- res.end(JSON.stringify({ success: true }));
189
- }
190
- } else if (url === "/timeout") {
191
- // Don't respond to simulate timeout
192
- setTimeout(() => {
193
- res.writeHead(200);
194
- res.end("OK");
195
- }, 10000);
196
- } else if (url === "/rate-limit") {
197
- if (requestCounts[url] <= 2) {
198
- res.writeHead(429, {
199
- "Content-Type": "application/json",
200
- "Retry-After": "1"
201
- });
202
- res.end(JSON.stringify({ error: "Rate limited" }));
203
- } else {
204
- res.writeHead(200, { "Content-Type": "application/json" });
205
- res.end(JSON.stringify({ success: true }));
206
- }
207
- } else {
208
- res.writeHead(200, { "Content-Type": "application/json" });
209
- res.end(JSON.stringify({ data: "ok" }));
210
- }
211
- });
212
-
213
- mockServer.listen(9999, done);
214
- });
215
-
216
- after((done) => {
217
- if (mockServer) {
218
- mockServer.close(done);
219
- } else {
220
- done();
221
- }
222
- });
223
-
224
- it("should retry on server errors and eventually succeed", async () => {
225
- const { withRetry } = require("../src/clients/retry");
226
-
227
- const response = await withRetry(async () => {
228
- return await fetchWithAgent("http://localhost:9999/fail-twice");
229
- }, {
230
- maxRetries: 3,
231
- initialDelay: 50,
232
- maxDelay: 200,
233
- });
234
-
235
- // After retries, should get successful response
236
- assert.ok(response.ok, "Response should be ok after retries");
237
- const result = await response.json();
238
- assert.ok(result.success);
239
- assert.ok(requestCounts["/fail-twice"] >= 3, `Expected at least 3 requests, got ${requestCounts["/fail-twice"]}`);
240
- });
241
-
242
- it("should handle 429 rate limiting with retry", async () => {
243
- const { withRetry } = require("../src/clients/retry");
244
-
245
- const response = await withRetry(async () => {
246
- return await fetchWithAgent("http://localhost:9999/rate-limit");
247
- }, {
248
- maxRetries: 3,
249
- initialDelay: 50,
250
- maxDelay: 200,
251
- });
252
-
253
- assert.ok(response.ok, "Should eventually succeed after retries");
254
- const result = await response.json();
255
- assert.ok(result.success, "Result should indicate success");
256
- assert.ok(requestCounts["/rate-limit"] >= 2, "Should have retried at least once");
257
- });
258
- });
259
-
260
- describe("Error Handling", () => {
261
- it("should categorize error codes correctly", () => {
262
- // Test that error codes are properly set
263
- const testError = (status, expectedCode) => {
264
- const error = new Error("Test error");
265
- error.status = status;
266
- error.code = status === 429 ? "RATE_LIMITED" :
267
- status >= 500 ? "SERVER_ERROR" : "REQUEST_ERROR";
268
-
269
- assert.strictEqual(error.code, expectedCode);
270
- };
271
-
272
- testError(429, "RATE_LIMITED");
273
- testError(500, "SERVER_ERROR");
274
- testError(502, "SERVER_ERROR");
275
- testError(503, "SERVER_ERROR");
276
- testError(400, "REQUEST_ERROR");
277
- testError(404, "REQUEST_ERROR");
278
- });
279
- });
280
-
281
- describe("Performance", () => {
282
- let testServer;
283
-
284
- before((done) => {
285
- testServer = http.createServer((req, res) => {
286
- res.writeHead(200, { "Content-Type": "text/plain" });
287
- res.end("OK");
288
- });
289
- testServer.listen(9998, done);
290
- });
291
-
292
- after((done) => {
293
- if (testServer) {
294
- testServer.close(done);
295
- } else {
296
- done();
297
- }
298
- });
299
-
300
- it("should reuse connections with keep-alive", async () => {
301
- const times = [];
302
-
303
- // Make 5 sequential requests
304
- for (let i = 0; i < 5; i++) {
305
- const start = Date.now();
306
- await fetchWithAgent("http://localhost:9998/");
307
- times.push(Date.now() - start);
308
- }
309
-
310
- // First request typically slower (connection setup)
311
- // Subsequent requests should be faster (reused connection)
312
- const avgSubsequent = times.slice(1).reduce((a, b) => a + b, 0) / (times.length - 1);
313
-
314
- // Subsequent requests should be reasonably fast
315
- assert.ok(avgSubsequent < 100, `Subsequent requests too slow: ${avgSubsequent}ms`);
316
- });
317
- });
318
-
319
- describe("Body Preview Configuration", () => {
320
- it("should limit body preview to configured max", () => {
321
- const maxLength = config.webSearch.bodyPreviewMax;
322
- const longContent = "x".repeat(maxLength * 2);
323
- const preview = longContent.slice(0, maxLength);
324
-
325
- assert.strictEqual(preview.length, maxLength);
326
- assert.ok(preview.length < longContent.length);
327
- });
328
- });
329
- });
@@ -1,43 +0,0 @@
1
- // Simple test to verify agent system is working
2
- // Run: AGENTS_ENABLED=true node test-agents-simple.js
3
-
4
- const config = require('./src/config');
5
- const { listAgents, getAgentStats } = require('./src/agents');
6
-
7
- console.log('๐Ÿงช Testing Agent System\n');
8
-
9
- // Test 1: Check configuration
10
- console.log('1. Configuration:');
11
- console.log(` Agents enabled: ${config.agents?.enabled}`);
12
- console.log(` Max concurrent: ${config.agents?.maxConcurrent}`);
13
- console.log(` Default model: ${config.agents?.defaultModel}`);
14
- console.log(` Max steps: ${config.agents?.maxSteps}`);
15
- console.log(` Timeout: ${config.agents?.timeout}ms`);
16
-
17
- // Test 2: List available agents
18
- console.log('\n2. Available Agents:');
19
- const agents = listAgents();
20
- agents.forEach(agent => {
21
- console.log(` - ${agent.name} (${agent.model})`);
22
- console.log(` ${agent.description.substring(0, 80)}...`);
23
- console.log(` Tools: ${agent.allowedTools.length === 0 ? 'ALL' : agent.allowedTools.join(', ')}`);
24
- console.log(` Max steps: ${agent.maxSteps}`);
25
- });
26
-
27
- // Test 3: Check stats
28
- console.log('\n3. Execution Stats:');
29
- const stats = getAgentStats();
30
- if (stats.length === 0) {
31
- console.log(' No executions yet');
32
- } else {
33
- stats.forEach(stat => {
34
- console.log(` - ${stat.agent_type}:`);
35
- console.log(` Total: ${stat.total_executions}, Completed: ${stat.completed}, Failed: ${stat.failed}`);
36
- });
37
- }
38
-
39
- console.log('\nโœ… Agent system is operational!\n');
40
- console.log('Next steps:');
41
- console.log('1. Start server: AGENTS_ENABLED=true npm start');
42
- console.log('2. Test with curl (see README)');
43
- console.log('3. Or run: ./test-subagents.sh\n');
@@ -1,33 +0,0 @@
1
- #!/bin/bash
2
-
3
- echo "๐Ÿ” Claude Code CLI Connection Test"
4
- echo "===================================="
5
- echo ""
6
-
7
- echo "1. Environment Variables:"
8
- env | grep -i anthropic | sed 's/^/ /'
9
-
10
- echo ""
11
- echo "2. Testing ngrok endpoint:"
12
- curl -s https://ae619b9fdba2.ngrok-free.app/health -H "ngrok-skip-browser-warning: true" | jq .
13
-
14
- echo ""
15
- echo "3. Testing direct localhost:"
16
- curl -s http://localhost:8080/health | jq .
17
-
18
- echo ""
19
- echo "4. Checking Claude config file:"
20
- if [ -f ~/.config/claude/config.json ]; then
21
- echo " Config exists:"
22
- cat ~/.config/claude/config.json | jq .api 2>/dev/null || cat ~/.config/claude/config.json
23
- else
24
- echo " No config file found"
25
- fi
26
-
27
- echo ""
28
- echo "5. Last 5 requests in server log:"
29
- tail -100 /tmp/lynkr.log | grep "Request started" | tail -5 | sed 's/^/ /'
30
-
31
- echo ""
32
- echo "======================================"
33
- echo "Please share this output!"