lynkr 8.0.0 → 9.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/.lynkr/telemetry.db +0 -0
- package/.lynkr/telemetry.db-shm +0 -0
- package/.lynkr/telemetry.db-wal +0 -0
- package/README.md +196 -322
- package/lynkr-skill.tar.gz +0 -0
- package/package.json +4 -3
- package/src/api/openai-router.js +64 -13
- package/src/api/providers-handler.js +171 -3
- package/src/api/router.js +9 -2
- package/src/clients/circuit-breaker.js +10 -247
- package/src/clients/codex-process.js +342 -0
- package/src/clients/codex-utils.js +143 -0
- package/src/clients/databricks.js +210 -63
- package/src/clients/resilience.js +540 -0
- package/src/clients/retry.js +22 -167
- package/src/clients/standard-tools.js +23 -0
- package/src/config/index.js +77 -0
- package/src/context/compression.js +42 -9
- package/src/context/distill.js +492 -0
- package/src/orchestrator/index.js +48 -8
- package/src/routing/complexity-analyzer.js +258 -5
- package/src/routing/index.js +12 -2
- package/src/routing/latency-tracker.js +148 -0
- package/src/routing/model-tiers.js +2 -0
- package/src/routing/quality-scorer.js +113 -0
- package/src/routing/telemetry.js +464 -0
- package/src/server.js +13 -12
- package/src/tools/code-graph.js +538 -0
- package/src/tools/code-mode.js +304 -0
- package/src/tools/index.js +4 -0
- package/src/tools/lazy-loader.js +18 -0
- package/src/tools/mcp-remote.js +7 -0
- package/src/tools/smart-selection.js +11 -0
- package/src/tools/tinyfish.js +358 -0
- package/src/tools/truncate.js +1 -0
- package/src/utils/payload.js +206 -0
- package/src/utils/perf-timer.js +80 -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/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/docs/42642f749da6234f41b6b425c3bb07c9.txt +0 -1
- package/docs/BingSiteAuth.xml +0 -4
- package/docs/docs-style.css +0 -478
- package/docs/docs.html +0 -198
- package/docs/google5be250e608e6da39.html +0 -1
- package/docs/index.html +0 -577
- package/docs/index.md +0 -584
- package/docs/robots.txt +0 -4
- package/docs/sitemap.xml +0 -44
- package/docs/style.css +0 -1223
- package/docs/toon-integration-spec.md +0 -130
- package/documentation/README.md +0 -101
- package/documentation/api.md +0 -806
- package/documentation/claude-code-cli.md +0 -679
- package/documentation/codex-cli.md +0 -397
- package/documentation/contributing.md +0 -571
- package/documentation/cursor-integration.md +0 -734
- package/documentation/docker.md +0 -874
- package/documentation/embeddings.md +0 -762
- package/documentation/faq.md +0 -713
- package/documentation/features.md +0 -403
- package/documentation/headroom.md +0 -519
- package/documentation/installation.md +0 -758
- package/documentation/memory-system.md +0 -476
- package/documentation/production.md +0 -636
- package/documentation/providers.md +0 -1009
- package/documentation/routing.md +0 -476
- package/documentation/testing.md +0 -629
- package/documentation/token-optimization.md +0 -325
- package/documentation/tools.md +0 -697
- package/documentation/troubleshooting.md +0 -969
- 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/te +0 -11622
- package/test/README.md +0 -212
- package/test/azure-openai-config.test.js +0 -213
- 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 -287
- package/test/azure-openai-routing.test.js +0 -175
- package/test/azure-openai-streaming.test.js +0 -171
- package/test/bedrock-integration.test.js +0 -457
- 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 -269
- package/test/hybrid-routing-performance.test.js +0 -428
- package/test/llamacpp-integration.test.js +0 -882
- package/test/lmstudio-integration.test.js +0 -347
- 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 -683
- 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 -225
- package/test/toon-compression.test.js +0 -131
- 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
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
# Per-Client Model Routing Implementation Plan
|
|
2
|
-
|
|
3
|
-
## Current State
|
|
4
|
-
|
|
5
|
-
### How Model Routing Works Now
|
|
6
|
-
|
|
7
|
-
1. **Global Provider**: Set via `MODEL_PROVIDER` in `.env`
|
|
8
|
-
2. **No Per-Client Routing**: All clients use the same provider
|
|
9
|
-
3. **Smart Routing**: Only when `PREFER_OLLAMA=true` (routes based on tool count/complexity)
|
|
10
|
-
4. **No Client-Side Indication**: Clients don't know which model was used
|
|
11
|
-
|
|
12
|
-
### Current Configuration Options
|
|
13
|
-
|
|
14
|
-
| Config | Purpose | Example Values |
|
|
15
|
-
|--------|---------|-----------------|
|
|
16
|
-
| `MODEL_PROVIDER` | Primary provider | databricks, ollama, openrouter, azure-openai, bedrock |
|
|
17
|
-
| `PREFER_OLLAMA` | Enable smart routing | true/false |
|
|
18
|
-
| `FALLBACK_ENABLED` | Allow fallback to cloud | true/false (default: true) |
|
|
19
|
-
| `FALLBACK_PROVIDER` | Cloud fallback provider | databricks, azure-anthropic, bedrock |
|
|
20
|
-
| `OLLAMA_MAX_TOOLS_FOR_ROUTING` | Tool threshold for Ollama | 3 (default) |
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## Implementation Plan
|
|
25
|
-
|
|
26
|
-
### Phase 1: Add Client-to-Provider Mapping Config
|
|
27
|
-
|
|
28
|
-
**File**: `.env`
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
# Per-client provider mapping (new)
|
|
32
|
-
CLIENT_PROVIDER_MAP=claude-code:ollama,codex:azure-openai,cline:openrouter,kilo:zai
|
|
33
|
-
CLIENT_PROVIDER_DEFAULT=azure-openai
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
**File**: `src/config/index.js`
|
|
37
|
-
|
|
38
|
-
```javascript
|
|
39
|
-
// Add helper function
|
|
40
|
-
function parseClientProviderMap(envValue) {
|
|
41
|
-
if (!envValue) return {};
|
|
42
|
-
const map = {};
|
|
43
|
-
envValue.split(',').forEach(pair => {
|
|
44
|
-
const [client, provider] = pair.split(':').map(s => s.trim().toLowerCase());
|
|
45
|
-
if (client && provider) {
|
|
46
|
-
map[client] = provider;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
return map;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Add to config object
|
|
53
|
-
clientProviderMap: parseClientProviderMap(process.env.CLIENT_PROVIDER_MAP),
|
|
54
|
-
clientProviderDefault: process.env.CLIENT_PROVIDER_DEFAULT || process.env.MODEL_PROVIDER || 'azure-openai',
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
---
|
|
58
|
-
|
|
59
|
-
### Phase 2: Detect Client & Override Provider
|
|
60
|
-
|
|
61
|
-
**File**: `src/orchestrator/index.js` (around line 769)
|
|
62
|
-
|
|
63
|
-
```javascript
|
|
64
|
-
// Add at top of file
|
|
65
|
-
const VALID_PROVIDERS = new Set([
|
|
66
|
-
'databricks', 'azure-anthropic', 'azure-openai', 'openrouter',
|
|
67
|
-
'openai', 'ollama', 'llamacpp', 'lmstudio', 'bedrock', 'zai', 'vertex'
|
|
68
|
-
]);
|
|
69
|
-
|
|
70
|
-
// Add helper function
|
|
71
|
-
function detectClientType(headers) {
|
|
72
|
-
const userAgent = (headers?.["user-agent"] || "").toLowerCase();
|
|
73
|
-
const clientHeader = (headers?.["x-client"] || headers?.["x-client-name"] || "").toLowerCase();
|
|
74
|
-
|
|
75
|
-
if (userAgent.includes("claude") || clientHeader.includes("claude")) return "claude-code";
|
|
76
|
-
if (userAgent.includes("codex") || clientHeader.includes("codex")) return "codex";
|
|
77
|
-
if (userAgent.includes("kilo") || clientHeader.includes("kilo")) return "kilo";
|
|
78
|
-
if (userAgent.includes("cline") || clientHeader.includes("cline")) return "cline";
|
|
79
|
-
if (userAgent.includes("continue") || clientHeader.includes("continue")) return "continue";
|
|
80
|
-
if (userAgent.includes("cursor") || clientHeader.includes("cursor")) return "cursor";
|
|
81
|
-
if (userAgent.includes("windsurf") || clientHeader.includes("windsurf")) return "windsurf";
|
|
82
|
-
|
|
83
|
-
return "unknown";
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function getProviderForClient(headers, defaultProvider) {
|
|
87
|
-
const clientType = detectClientType(headers);
|
|
88
|
-
const clientMap = config.clientProviderMap || {};
|
|
89
|
-
|
|
90
|
-
// 1. Check for explicit header override
|
|
91
|
-
const headerOverride = headers?.["x-model-provider"]?.toLowerCase();
|
|
92
|
-
if (headerOverride && VALID_PROVIDERS.has(headerOverride)) {
|
|
93
|
-
logger.info({ clientType, headerOverride }, "Using header-specified provider");
|
|
94
|
-
return headerOverride;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// 2. Check client-specific mapping from config
|
|
98
|
-
if (clientMap[clientType]) {
|
|
99
|
-
logger.info({ clientType, provider: clientMap[clientType] }, "Using client-mapped provider");
|
|
100
|
-
return clientMap[clientType];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// 3. Fall back to default
|
|
104
|
-
logger.debug({ clientType, defaultProvider }, "Using default provider");
|
|
105
|
-
return config.clientProviderDefault || defaultProvider;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Replace current static provider selection:
|
|
109
|
-
// OLD: const providerType = config.modelProvider?.type ?? "databricks";
|
|
110
|
-
// NEW:
|
|
111
|
-
const providerType = getProviderForClient(headers, config.modelProvider?.type ?? "databricks");
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
---
|
|
115
|
-
|
|
116
|
-
### Phase 3: Add Response Header for Model Indication
|
|
117
|
-
|
|
118
|
-
**File**: `src/api/openai-router.js`
|
|
119
|
-
|
|
120
|
-
In the streaming response section, add headers:
|
|
121
|
-
|
|
122
|
-
```javascript
|
|
123
|
-
// After res.setHeader("Content-Type", "text/event-stream");
|
|
124
|
-
res.setHeader("X-Lynkr-Provider", providerType);
|
|
125
|
-
res.setHeader("X-Lynkr-Client-Detected", clientType);
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
**File**: `src/api/openai-router.js` (in /v1/responses endpoint)
|
|
129
|
-
|
|
130
|
-
In the response.completed event, add metadata:
|
|
131
|
-
|
|
132
|
-
```javascript
|
|
133
|
-
const completedEvent = {
|
|
134
|
-
type: "response.completed",
|
|
135
|
-
response: {
|
|
136
|
-
id: responseId,
|
|
137
|
-
object: "response",
|
|
138
|
-
status: "completed",
|
|
139
|
-
// ... existing fields
|
|
140
|
-
|
|
141
|
-
// NEW: Add provider metadata
|
|
142
|
-
_lynkr: {
|
|
143
|
-
provider: providerType,
|
|
144
|
-
client_detected: clientType,
|
|
145
|
-
model_actual: actualModelUsed
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
sequence_number: sequenceNumber++
|
|
149
|
-
};
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
---
|
|
153
|
-
|
|
154
|
-
### Phase 4: Hot Reload Support
|
|
155
|
-
|
|
156
|
-
**File**: `src/config/index.js`
|
|
157
|
-
|
|
158
|
-
```javascript
|
|
159
|
-
reloadConfig() {
|
|
160
|
-
// ... existing reload logic
|
|
161
|
-
|
|
162
|
-
// Add client provider map reload
|
|
163
|
-
this.clientProviderMap = parseClientProviderMap(process.env.CLIENT_PROVIDER_MAP);
|
|
164
|
-
this.clientProviderDefault = process.env.CLIENT_PROVIDER_DEFAULT || process.env.MODEL_PROVIDER;
|
|
165
|
-
|
|
166
|
-
logger.info({
|
|
167
|
-
clientProviderMap: this.clientProviderMap,
|
|
168
|
-
clientProviderDefault: this.clientProviderDefault
|
|
169
|
-
}, "Client provider mapping reloaded");
|
|
170
|
-
}
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
---
|
|
174
|
-
|
|
175
|
-
### Phase 5: Logging & Observability
|
|
176
|
-
|
|
177
|
-
**File**: `src/orchestrator/index.js`
|
|
178
|
-
|
|
179
|
-
Add logging for routing decisions:
|
|
180
|
-
|
|
181
|
-
```javascript
|
|
182
|
-
logger.info({
|
|
183
|
-
sessionId: session?.id,
|
|
184
|
-
clientType,
|
|
185
|
-
requestedModel: payload.model,
|
|
186
|
-
resolvedProvider: providerType,
|
|
187
|
-
headerOverride: headers?.["x-model-provider"],
|
|
188
|
-
configuredMapping: config.clientProviderMap[clientType]
|
|
189
|
-
}, "Model routing decision");
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
---
|
|
193
|
-
|
|
194
|
-
## Files to Modify
|
|
195
|
-
|
|
196
|
-
| File | Changes |
|
|
197
|
-
|------|---------|
|
|
198
|
-
| `.env` | Add `CLIENT_PROVIDER_MAP`, `CLIENT_PROVIDER_DEFAULT` |
|
|
199
|
-
| `src/config/index.js` | Parse new config, add helper function, add to exports |
|
|
200
|
-
| `src/orchestrator/index.js` | Add `getProviderForClient()`, `detectClientType()`, use headers |
|
|
201
|
-
| `src/api/openai-router.js` | Add `X-Lynkr-Provider` response header, add `_lynkr` metadata |
|
|
202
|
-
|
|
203
|
-
---
|
|
204
|
-
|
|
205
|
-
## Example Configuration
|
|
206
|
-
|
|
207
|
-
```bash
|
|
208
|
-
# .env
|
|
209
|
-
|
|
210
|
-
# Default provider (used if no client mapping matches)
|
|
211
|
-
MODEL_PROVIDER=azure-openai
|
|
212
|
-
CLIENT_PROVIDER_DEFAULT=azure-openai
|
|
213
|
-
|
|
214
|
-
# Per-client provider mapping
|
|
215
|
-
# Format: client1:provider1,client2:provider2,...
|
|
216
|
-
CLIENT_PROVIDER_MAP=claude-code:ollama,codex:azure-openai,cline:openrouter,kilo:zai,cursor:databricks
|
|
217
|
-
|
|
218
|
-
# Individual provider configs
|
|
219
|
-
OLLAMA_MODEL=qwen2.5-coder:7b
|
|
220
|
-
AZURE_OPENAI_DEPLOYMENT=gpt-4o
|
|
221
|
-
OPENROUTER_MODEL=anthropic/claude-3.5-sonnet
|
|
222
|
-
ZAI_MODEL=GLM-4.7
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
**Result**:
|
|
226
|
-
- Claude Code → Ollama (local, fast, free)
|
|
227
|
-
- Codex CLI → Azure OpenAI (GPT-4o/GPT-5)
|
|
228
|
-
- Cline → OpenRouter (Claude 3.5 Sonnet)
|
|
229
|
-
- Kilo Code → Z.AI (GLM-4.7, cheap)
|
|
230
|
-
- Cursor → Databricks (Claude via Databricks)
|
|
231
|
-
- Unknown → Azure OpenAI (default)
|
|
232
|
-
|
|
233
|
-
---
|
|
234
|
-
|
|
235
|
-
## Testing
|
|
236
|
-
|
|
237
|
-
1. Start server with new config
|
|
238
|
-
2. Make request from Claude Code → should route to Ollama
|
|
239
|
-
3. Check logs for "Model routing decision"
|
|
240
|
-
4. Check response header `X-Lynkr-Provider`
|
|
241
|
-
5. Make request from Codex → should route to Azure OpenAI
|
|
242
|
-
6. Test header override: `curl -H "X-Model-Provider: ollama" ...`
|
|
243
|
-
|
|
244
|
-
---
|
|
245
|
-
|
|
246
|
-
## Future Enhancements
|
|
247
|
-
|
|
248
|
-
1. **Per-Model Routing**: Route based on requested model name, not just client
|
|
249
|
-
2. **Cost-Based Routing**: Route to cheapest provider that supports the request
|
|
250
|
-
3. **Latency-Based Routing**: Route to fastest available provider
|
|
251
|
-
4. **Load Balancing**: Distribute across multiple providers
|
|
252
|
-
5. **UI Dashboard**: Visual config for routing rules
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
42642f749da6234f41b6b425c3bb07c9
|
package/docs/BingSiteAuth.xml
DELETED