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,335 +0,0 @@
1
- const assert = require("assert");
2
- const { describe, it, beforeEach, afterEach } = require("node:test");
3
-
4
- describe("LM Studio Integration", () => {
5
- let originalEnv;
6
-
7
- beforeEach(() => {
8
- originalEnv = { ...process.env };
9
-
10
- // Clear module cache
11
- delete require.cache[require.resolve("../src/config")];
12
- delete require.cache[require.resolve("../src/clients/routing")];
13
- delete require.cache[require.resolve("../src/clients/openrouter-utils")];
14
- });
15
-
16
- afterEach(() => {
17
- process.env = originalEnv;
18
- });
19
-
20
- describe("Configuration", () => {
21
- it("should accept lmstudio as a valid MODEL_PROVIDER", () => {
22
- process.env.MODEL_PROVIDER = "lmstudio";
23
- process.env.LMSTUDIO_ENDPOINT = "http://localhost:1234";
24
-
25
- const config = require("../src/config");
26
- assert.strictEqual(config.modelProvider.type, "lmstudio");
27
- });
28
-
29
- it("should use default endpoint when LMSTUDIO_ENDPOINT is not set", () => {
30
- process.env.MODEL_PROVIDER = "lmstudio";
31
- delete process.env.LMSTUDIO_ENDPOINT;
32
-
33
- const config = require("../src/config");
34
- assert.strictEqual(config.lmstudio.endpoint, "http://localhost:1234");
35
- });
36
-
37
- it("should use custom endpoint when LMSTUDIO_ENDPOINT is set", () => {
38
- process.env.MODEL_PROVIDER = "lmstudio";
39
- process.env.LMSTUDIO_ENDPOINT = "http://192.168.1.100:9000";
40
-
41
- const config = require("../src/config");
42
- assert.strictEqual(config.lmstudio.endpoint, "http://192.168.1.100:9000");
43
- });
44
-
45
- it("should throw error when LMSTUDIO_ENDPOINT is invalid URL", () => {
46
- process.env.MODEL_PROVIDER = "lmstudio";
47
- process.env.LMSTUDIO_ENDPOINT = "not-a-valid-url";
48
-
49
- assert.throws(
50
- () => require("../src/config"),
51
- /LMSTUDIO_ENDPOINT must be a valid URL/
52
- );
53
- });
54
-
55
- it("should use default model when LMSTUDIO_MODEL is not set", () => {
56
- process.env.MODEL_PROVIDER = "lmstudio";
57
- delete process.env.LMSTUDIO_MODEL;
58
-
59
- const config = require("../src/config");
60
- assert.strictEqual(config.lmstudio.model, "default");
61
- });
62
-
63
- it("should use custom model when LMSTUDIO_MODEL is set", () => {
64
- process.env.MODEL_PROVIDER = "lmstudio";
65
- process.env.LMSTUDIO_MODEL = "hermes-2-pro-llama-3-8b";
66
-
67
- const config = require("../src/config");
68
- assert.strictEqual(config.lmstudio.model, "hermes-2-pro-llama-3-8b");
69
- });
70
-
71
- it("should use default timeout when LMSTUDIO_TIMEOUT_MS is not set", () => {
72
- process.env.MODEL_PROVIDER = "lmstudio";
73
- delete process.env.LMSTUDIO_TIMEOUT_MS;
74
-
75
- const config = require("../src/config");
76
- assert.strictEqual(config.lmstudio.timeout, 120000);
77
- });
78
-
79
- it("should use custom timeout when LMSTUDIO_TIMEOUT_MS is set", () => {
80
- process.env.MODEL_PROVIDER = "lmstudio";
81
- process.env.LMSTUDIO_TIMEOUT_MS = "300000";
82
-
83
- const config = require("../src/config");
84
- assert.strictEqual(config.lmstudio.timeout, 300000);
85
- });
86
-
87
- it("should have null apiKey when LMSTUDIO_API_KEY is not set", () => {
88
- process.env.MODEL_PROVIDER = "lmstudio";
89
- delete process.env.LMSTUDIO_API_KEY;
90
-
91
- const config = require("../src/config");
92
- assert.strictEqual(config.lmstudio.apiKey, null);
93
- });
94
-
95
- it("should store apiKey when LMSTUDIO_API_KEY is set", () => {
96
- process.env.MODEL_PROVIDER = "lmstudio";
97
- process.env.LMSTUDIO_API_KEY = "my-secret-key";
98
-
99
- const config = require("../src/config");
100
- assert.strictEqual(config.lmstudio.apiKey, "my-secret-key");
101
- });
102
- });
103
-
104
- describe("Routing", () => {
105
- it("should route to lmstudio when MODEL_PROVIDER is lmstudio", () => {
106
- process.env.MODEL_PROVIDER = "lmstudio";
107
- process.env.LMSTUDIO_ENDPOINT = "http://localhost:1234";
108
- process.env.PREFER_OLLAMA = "false";
109
-
110
- const config = require("../src/config");
111
- const routing = require("../src/clients/routing");
112
-
113
- const payload = { messages: [{ role: "user", content: "test" }] };
114
- const provider = routing.determineProvider(payload);
115
-
116
- assert.strictEqual(provider, "lmstudio");
117
- });
118
-
119
- it("should route to lmstudio for moderate tool count when other providers not configured", () => {
120
- // This test is skipped because lmstudio is the LAST option in routing
121
- // and other providers (openrouter, openai, azure, llamacpp) take precedence
122
- // LM Studio will be used when it's the PRIMARY provider, not in routing fallback
123
- });
124
-
125
- it("should throw error when lmstudio is set as FALLBACK_PROVIDER", () => {
126
- process.env.MODEL_PROVIDER = "ollama";
127
- process.env.PREFER_OLLAMA = "true";
128
- process.env.OLLAMA_MODEL = "qwen2.5-coder:latest";
129
- process.env.FALLBACK_PROVIDER = "lmstudio";
130
- process.env.LMSTUDIO_ENDPOINT = "http://localhost:1234";
131
- process.env.FALLBACK_ENABLED = "true";
132
-
133
- assert.throws(
134
- () => require("../src/config"),
135
- /FALLBACK_PROVIDER cannot be 'lmstudio'/
136
- );
137
- });
138
- });
139
-
140
- describe("Response Conversion", () => {
141
- // LM Studio uses OpenAI-compatible format, so we reuse the same converter
142
-
143
- it("should convert LM Studio text response to Anthropic format", () => {
144
- process.env.MODEL_PROVIDER = "databricks";
145
- process.env.DATABRICKS_API_KEY = "test-key";
146
- process.env.DATABRICKS_API_BASE = "http://test.com";
147
-
148
- const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
149
-
150
- const lmstudioResponse = {
151
- id: "chatcmpl-123",
152
- object: "chat.completion",
153
- created: 1677652288,
154
- model: "hermes-2-pro-llama-3-8b",
155
- choices: [
156
- {
157
- index: 0,
158
- message: {
159
- role: "assistant",
160
- content: "Hello! I'm running on LM Studio."
161
- },
162
- finish_reason: "stop"
163
- }
164
- ],
165
- usage: {
166
- prompt_tokens: 9,
167
- completion_tokens: 12,
168
- total_tokens: 21
169
- }
170
- };
171
-
172
- const result = convertOpenRouterResponseToAnthropic(lmstudioResponse, "claude-sonnet-4-5");
173
-
174
- assert.strictEqual(result.role, "assistant");
175
- assert.strictEqual(result.model, "claude-sonnet-4-5");
176
- assert.strictEqual(Array.isArray(result.content), true);
177
- assert.strictEqual(result.content.length, 1);
178
- assert.strictEqual(result.content[0].type, "text");
179
- assert.strictEqual(result.content[0].text, "Hello! I'm running on LM Studio.");
180
- assert.strictEqual(result.stop_reason, "end_turn");
181
- assert.strictEqual(result.usage.input_tokens, 9);
182
- assert.strictEqual(result.usage.output_tokens, 12);
183
- });
184
-
185
- it("should convert LM Studio tool call response to Anthropic format", () => {
186
- process.env.MODEL_PROVIDER = "databricks";
187
- process.env.DATABRICKS_API_KEY = "test-key";
188
- process.env.DATABRICKS_API_BASE = "http://test.com";
189
-
190
- const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
191
-
192
- const lmstudioResponse = {
193
- id: "chatcmpl-123",
194
- object: "chat.completion",
195
- model: "hermes-2-pro-llama-3-8b",
196
- choices: [
197
- {
198
- index: 0,
199
- message: {
200
- role: "assistant",
201
- content: "I'll read that file for you.",
202
- tool_calls: [
203
- {
204
- id: "call_abc123",
205
- type: "function",
206
- function: {
207
- name: "Read",
208
- arguments: JSON.stringify({
209
- file_path: "/tmp/example.txt"
210
- })
211
- }
212
- }
213
- ]
214
- },
215
- finish_reason: "tool_calls"
216
- }
217
- ],
218
- usage: {
219
- prompt_tokens: 50,
220
- completion_tokens: 30,
221
- total_tokens: 80
222
- }
223
- };
224
-
225
- const result = convertOpenRouterResponseToAnthropic(lmstudioResponse, "claude-sonnet-4-5");
226
-
227
- assert.strictEqual(result.role, "assistant");
228
- assert.strictEqual(result.content.length, 2); // text + tool_use
229
- assert.strictEqual(result.content[0].type, "text");
230
- assert.strictEqual(result.content[0].text, "I'll read that file for you.");
231
- assert.strictEqual(result.content[1].type, "tool_use");
232
- assert.strictEqual(result.content[1].name, "Read");
233
- assert.strictEqual(result.content[1].id, "call_abc123");
234
- assert.deepStrictEqual(result.content[1].input, {
235
- file_path: "/tmp/example.txt"
236
- });
237
- assert.strictEqual(result.stop_reason, "tool_use");
238
- });
239
- });
240
-
241
- describe("Message Conversion", () => {
242
- it("should convert Anthropic messages to LM Studio (OpenAI) format", () => {
243
- process.env.MODEL_PROVIDER = "databricks";
244
- process.env.DATABRICKS_API_KEY = "test-key";
245
- process.env.DATABRICKS_API_BASE = "http://test.com";
246
-
247
- const { convertAnthropicMessagesToOpenRouter } = require("../src/clients/openrouter-utils");
248
-
249
- const anthropicMessages = [
250
- {
251
- role: "user",
252
- content: [
253
- { type: "text", text: "What is 2 + 2?" }
254
- ]
255
- },
256
- {
257
- role: "assistant",
258
- content: [
259
- { type: "text", text: "2 + 2 equals 4." }
260
- ]
261
- }
262
- ];
263
-
264
- const result = convertAnthropicMessagesToOpenRouter(anthropicMessages);
265
-
266
- assert.strictEqual(result.length, 2);
267
- assert.strictEqual(result[0].role, "user");
268
- assert.strictEqual(result[0].content, "What is 2 + 2?");
269
- assert.strictEqual(result[1].role, "assistant");
270
- assert.strictEqual(result[1].content, "2 + 2 equals 4.");
271
- });
272
- });
273
-
274
- describe("Tool Conversion", () => {
275
- it("should convert Anthropic tools to LM Studio (OpenAI) format", () => {
276
- process.env.MODEL_PROVIDER = "databricks";
277
- process.env.DATABRICKS_API_KEY = "test-key";
278
- process.env.DATABRICKS_API_BASE = "http://test.com";
279
-
280
- const { convertAnthropicToolsToOpenRouter } = require("../src/clients/openrouter-utils");
281
-
282
- const anthropicTools = [
283
- {
284
- name: "Read",
285
- description: "Read a file from disk",
286
- input_schema: {
287
- type: "object",
288
- properties: {
289
- file_path: { type: "string", description: "Path to the file" }
290
- },
291
- required: ["file_path"]
292
- }
293
- }
294
- ];
295
-
296
- const result = convertAnthropicToolsToOpenRouter(anthropicTools);
297
-
298
- assert.strictEqual(result.length, 1);
299
- assert.strictEqual(result[0].type, "function");
300
- assert.strictEqual(result[0].function.name, "Read");
301
- assert.strictEqual(result[0].function.description, "Read a file from disk");
302
- assert.deepStrictEqual(result[0].function.parameters, {
303
- type: "object",
304
- properties: {
305
- file_path: { type: "string", description: "Path to the file" }
306
- },
307
- required: ["file_path"]
308
- });
309
- });
310
- });
311
-
312
- describe("Fallback Prevention", () => {
313
- it("should prevent lmstudio from being used as fallback provider", () => {
314
- process.env.MODEL_PROVIDER = "ollama";
315
- process.env.PREFER_OLLAMA = "true";
316
- process.env.OLLAMA_MODEL = "qwen2.5-coder:latest";
317
- process.env.FALLBACK_PROVIDER = "lmstudio";
318
- process.env.LMSTUDIO_ENDPOINT = "http://localhost:1234";
319
- process.env.FALLBACK_ENABLED = "true";
320
-
321
- assert.throws(
322
- () => require("../src/config"),
323
- /FALLBACK_PROVIDER cannot be 'lmstudio' \(local providers should not be fallbacks\)/
324
- );
325
- });
326
-
327
- it("should allow lmstudio as primary provider", () => {
328
- process.env.MODEL_PROVIDER = "lmstudio";
329
- process.env.LMSTUDIO_ENDPOINT = "http://localhost:1234";
330
-
331
- const config = require("../src/config");
332
- assert.strictEqual(config.modelProvider.type, "lmstudio");
333
- });
334
- });
335
- });