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.
- package/README.md +3 -3
- package/config/model-tiers.json +89 -0
- package/install.sh +6 -1
- package/package.json +4 -2
- package/scripts/setup.js +0 -1
- package/src/agents/executor.js +14 -6
- package/src/api/middleware/session.js +15 -2
- package/src/api/openai-router.js +162 -37
- package/src/api/providers-handler.js +15 -1
- package/src/api/router.js +107 -2
- package/src/budget/index.js +4 -3
- package/src/clients/databricks.js +431 -234
- package/src/clients/gpt-utils.js +181 -0
- package/src/clients/ollama-utils.js +66 -140
- package/src/clients/routing.js +0 -1
- package/src/clients/standard-tools.js +99 -3
- package/src/config/index.js +133 -35
- package/src/context/toon.js +173 -0
- package/src/logger/index.js +23 -0
- package/src/orchestrator/index.js +688 -213
- package/src/routing/agentic-detector.js +320 -0
- package/src/routing/complexity-analyzer.js +202 -2
- package/src/routing/cost-optimizer.js +305 -0
- package/src/routing/index.js +168 -159
- package/src/routing/model-tiers.js +365 -0
- package/src/server.js +4 -14
- package/src/sessions/cleanup.js +3 -3
- package/src/sessions/record.js +10 -1
- package/src/sessions/store.js +7 -2
- package/src/tools/agent-task.js +48 -1
- package/src/tools/index.js +19 -2
- package/src/tools/lazy-loader.js +7 -0
- package/src/tools/tinyfish.js +358 -0
- package/src/tools/truncate.js +1 -0
- package/.github/FUNDING.yml +0 -15
- package/.github/workflows/README.md +0 -215
- package/.github/workflows/ci.yml +0 -69
- package/.github/workflows/index.yml +0 -62
- package/.github/workflows/web-tools-tests.yml +0 -56
- package/CITATIONS.bib +0 -6
- package/CLAWROUTER_ROUTING_PLAN.md +0 -910
- package/DEPLOYMENT.md +0 -1001
- package/LYNKR-TUI-PLAN.md +0 -984
- package/PERFORMANCE-REPORT.md +0 -866
- package/PLAN-per-client-model-routing.md +0 -252
- package/ROUTER_COMPARISON.md +0 -173
- package/TIER_ROUTING_PLAN.md +0 -771
- package/docs/42642f749da6234f41b6b425c3bb07c9.txt +0 -1
- package/docs/BingSiteAuth.xml +0 -4
- package/docs/docs-style.css +0 -478
- package/docs/docs.html +0 -197
- package/docs/google5be250e608e6da39.html +0 -1
- package/docs/index.html +0 -577
- package/docs/index.md +0 -577
- package/docs/robots.txt +0 -4
- package/docs/sitemap.xml +0 -44
- package/docs/style.css +0 -1223
- package/documentation/README.md +0 -100
- package/documentation/api.md +0 -806
- package/documentation/claude-code-cli.md +0 -672
- package/documentation/codex-cli.md +0 -397
- package/documentation/contributing.md +0 -571
- package/documentation/cursor-integration.md +0 -731
- package/documentation/docker.md +0 -867
- package/documentation/embeddings.md +0 -760
- package/documentation/faq.md +0 -659
- package/documentation/features.md +0 -396
- package/documentation/headroom.md +0 -519
- package/documentation/installation.md +0 -706
- package/documentation/memory-system.md +0 -476
- package/documentation/production.md +0 -601
- package/documentation/providers.md +0 -906
- package/documentation/testing.md +0 -629
- package/documentation/token-optimization.md +0 -323
- package/documentation/tools.md +0 -697
- package/documentation/troubleshooting.md +0 -893
- package/final-test.js +0 -33
- package/headroom-sidecar/config.py +0 -93
- package/headroom-sidecar/requirements.txt +0 -14
- package/headroom-sidecar/server.py +0 -451
- package/monitor-agents.sh +0 -31
- package/scripts/audit-log-reader.js +0 -399
- package/scripts/compact-dictionary.js +0 -204
- package/scripts/test-deduplication.js +0 -448
- package/src/db/database.sqlite +0 -0
- package/test/README.md +0 -212
- package/test/azure-openai-config.test.js +0 -204
- package/test/azure-openai-error-resilience.test.js +0 -238
- package/test/azure-openai-format-conversion.test.js +0 -354
- package/test/azure-openai-integration.test.js +0 -281
- package/test/azure-openai-routing.test.js +0 -177
- package/test/azure-openai-streaming.test.js +0 -171
- package/test/bedrock-integration.test.js +0 -471
- package/test/comprehensive-test-suite.js +0 -928
- package/test/config-validation.test.js +0 -207
- package/test/cursor-integration.test.js +0 -484
- package/test/format-conversion.test.js +0 -578
- package/test/hybrid-routing-integration.test.js +0 -254
- package/test/hybrid-routing-performance.test.js +0 -418
- package/test/llamacpp-integration.test.js +0 -863
- package/test/lmstudio-integration.test.js +0 -335
- package/test/memory/extractor.test.js +0 -398
- package/test/memory/retriever.test.js +0 -613
- package/test/memory/retriever.test.js.bak +0 -585
- package/test/memory/search.test.js +0 -537
- package/test/memory/search.test.js.bak +0 -389
- package/test/memory/store.test.js +0 -344
- package/test/memory/store.test.js.bak +0 -312
- package/test/memory/surprise.test.js +0 -300
- package/test/memory-performance.test.js +0 -472
- package/test/openai-integration.test.js +0 -686
- package/test/openrouter-error-resilience.test.js +0 -418
- package/test/passthrough-mode.test.js +0 -385
- package/test/performance-benchmark.js +0 -351
- package/test/performance-tests.js +0 -528
- package/test/routing.test.js +0 -219
- package/test/web-tools.test.js +0 -329
- package/test-agents-simple.js +0 -43
- package/test-cli-connection.sh +0 -33
- package/test-learning-unit.js +0 -126
- package/test-learning.js +0 -112
- package/test-parallel-agents.sh +0 -124
- package/test-parallel-direct.js +0 -155
- package/test-subagents.sh +0 -117
package/test/routing.test.js
DELETED
|
@@ -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
|
-
});
|
package/test/web-tools.test.js
DELETED
|
@@ -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(/ /g, " ")
|
|
35
|
-
.replace(/&/g, "&")
|
|
36
|
-
.replace(/</g, "<")
|
|
37
|
-
.replace(/>/g, ">")
|
|
38
|
-
.replace(/"/g, '"')
|
|
39
|
-
.replace(/'/g, "'")
|
|
40
|
-
.replace(/'/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> &<>"'</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
|
-
});
|
package/test-agents-simple.js
DELETED
|
@@ -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');
|
package/test-cli-connection.sh
DELETED
|
@@ -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!"
|