lynkr 9.14.1 → 9.14.3
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 +5 -1
- package/bin/cli.js +14 -6
- package/bin/lynkr-desktop-token.js +108 -0
- package/bin/lynkr-init.js +13 -1
- package/bin/lynkr-restart.js +125 -0
- package/bin/opencode-setup.js +175 -0
- package/bin/run.js +92 -0
- package/config/model-capabilities.json +20 -0
- package/config/model-capability-seeds.json +75 -0
- package/config/model-tiers.json +13 -1
- package/package.json +16 -22
- package/scripts/claude-desktop.js +212 -0
- package/scripts/ope-report.js +78 -0
- package/scripts/seed-capabilities.js +230 -0
- package/src/api/claude-desktop-gateway.js +123 -0
- package/src/api/health.js +0 -1
- package/src/api/mcp-broker.js +149 -0
- package/src/api/middleware/budget-enforcer.js +77 -7
- package/src/api/middleware/budget.js +36 -2
- package/src/api/middleware/session.js +0 -0
- package/src/api/openai-router.js +210 -15
- package/src/api/providers-handler.js +16 -1
- package/src/api/router.js +73 -106
- package/src/auth-mode.js +40 -4
- package/src/budget/index.js +86 -0
- package/src/cache/embeddings.js +125 -35
- package/src/cache/onnx-embedder.js +92 -0
- package/src/cache/prompt.js +0 -7
- package/src/clients/bedrock-utils.js +2 -1
- package/src/clients/codex-process.js +1 -1
- package/src/clients/codex-utils.js +0 -2
- package/src/clients/databricks.js +337 -46
- package/src/clients/gpt-utils.js +84 -8
- package/src/clients/health-probe.js +157 -0
- package/src/clients/openai-format.js +73 -23
- package/src/clients/provider-capabilities.js +27 -2
- package/src/clients/resilience.js +0 -1
- package/src/clients/responses-format.js +0 -56
- package/src/clients/routing.js +1 -1
- package/src/config/index.js +13 -2
- package/src/context/budget.js +1 -1
- package/src/context/compression.js +127 -19
- package/src/context/tool-result-compressor.js +3 -5
- package/src/dashboard/api.js +1 -1
- package/src/logger/oversized-error-stream.js +1 -1
- package/src/memory/extractor.js +3 -3
- package/src/memory/search.js +2 -2
- package/src/memory/store.js +9 -24
- package/src/memory/tools.js +14 -0
- package/src/observability/metrics.js +52 -3
- package/src/observability/otel.js +180 -0
- package/src/orchestrator/azure-responses-sse.js +223 -0
- package/src/orchestrator/index.js +216 -212
- package/src/orchestrator/passthrough-stream.js +7 -1
- package/src/orchestrator/sse-transformer.js +130 -13
- package/src/policy/safe-commands.js +0 -1
- package/src/routing/bandit.js +39 -0
- package/src/routing/calibration.js +21 -1
- package/src/routing/capabilities.js +88 -0
- package/src/routing/capability-seeds/benchmarks-dir.js +58 -0
- package/src/routing/capability-seeds/family-heuristics.js +77 -0
- package/src/routing/capability-seeds/family.js +105 -0
- package/src/routing/capability-seeds/models-dev.js +64 -0
- package/src/routing/capability-seeds/normalize.js +160 -0
- package/src/routing/capability-seeds/registry.js +125 -0
- package/src/routing/capability-seeds/sources.js +69 -0
- package/src/routing/capability-seeds/swebench.js +66 -0
- package/src/routing/client-profiles.js +26 -0
- package/src/routing/complexity-analyzer.js +5 -8
- package/src/routing/confidence-scorer.js +2 -2
- package/src/routing/cost-optimizer.js +1 -2
- package/src/routing/decide.js +149 -0
- package/src/routing/deescalator.js +38 -1
- package/src/routing/embedding-cache.js +0 -1
- package/src/routing/index.js +202 -86
- package/src/routing/intent-score.js +0 -1
- package/src/routing/knn-router.js +27 -5
- package/src/routing/latency-tracker.js +1 -1
- package/src/routing/model-registry.js +25 -0
- package/src/routing/model-slots.js +65 -0
- package/src/routing/model-tiers.js +2 -0
- package/src/routing/ope.js +255 -0
- package/src/routing/openai-model-slots.js +82 -0
- package/src/routing/regret-estimator.js +1 -1
- package/src/routing/shortfall.js +290 -0
- package/src/routing/stuck-detector.js +127 -0
- package/src/routing/telemetry.js +11 -2
- package/src/server.js +41 -3
- package/src/stores/file-store.js +5 -1
- package/src/tools/web-search-exec.js +182 -0
- package/src/training/trajectory-compressor.js +1 -1
- package/src/workers/pool.js +1 -1
- package/src/workers/worker.js +1 -1
- package/scripts/convert-routellm.py +0 -105
- package/src/diff/comments.js +0 -153
- package/src/policy/web-fallback.js +0 -33
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-process ONNX embedder (ROUTING-NOTES §4.10.2).
|
|
3
|
+
*
|
|
4
|
+
* Runs the embedding model inside the Lynkr process via transformers.js
|
|
5
|
+
* (@huggingface/transformers, an optionalDependency), removing the external
|
|
6
|
+
* Ollama/llama.cpp server from the semantic-cache and kNN hot path — no
|
|
7
|
+
* network hop, no "is the server up" failure mode, no contention with
|
|
8
|
+
* completion traffic on the same local runtime.
|
|
9
|
+
*
|
|
10
|
+
* Model choice is deliberate: the ONNX build of the SAME model the Ollama
|
|
11
|
+
* path defaults to (nomic-embed-text, 768-dim). Same model = same embedding
|
|
12
|
+
* space = existing kNN index entries and semantic-cache vectors stay valid.
|
|
13
|
+
* (INT8 quantization introduces small numeric differences vs Ollama's
|
|
14
|
+
* serving precision, but cosine similarity is preserved far above the 0.92
|
|
15
|
+
* cache threshold.)
|
|
16
|
+
*
|
|
17
|
+
* Weights are downloaded once from the HuggingFace hub into
|
|
18
|
+
* ~/.lynkr/models (override: LYNKR_ONNX_CACHE_DIR) and verified by
|
|
19
|
+
* transformers.js's own integrity checks. Nothing is bundled in the npm
|
|
20
|
+
* package.
|
|
21
|
+
*
|
|
22
|
+
* Opt-in via LYNKR_EMBEDDINGS_PROVIDER=onnx. If the optional dependency is
|
|
23
|
+
* missing or the model fails to load, the caller's degradation machinery
|
|
24
|
+
* (cache/embeddings.js) takes over — loud, observable, recoverable.
|
|
25
|
+
*
|
|
26
|
+
* @module cache/onnx-embedder
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
const os = require('os');
|
|
30
|
+
const path = require('path');
|
|
31
|
+
const logger = require('../logger');
|
|
32
|
+
|
|
33
|
+
const MODEL_ID = process.env.LYNKR_ONNX_EMBEDDING_MODEL || 'Xenova/nomic-embed-text-v1';
|
|
34
|
+
const CACHE_DIR = process.env.LYNKR_ONNX_CACHE_DIR
|
|
35
|
+
|| path.join(os.homedir(), '.lynkr', 'models');
|
|
36
|
+
// q8 keeps the download ~25–35MB and inference CPU-friendly.
|
|
37
|
+
const DTYPE = process.env.LYNKR_ONNX_DTYPE || 'q8';
|
|
38
|
+
|
|
39
|
+
/** @type {Promise<Function>|null} memoized pipeline load (single flight) */
|
|
40
|
+
let pipelinePromise = null;
|
|
41
|
+
|
|
42
|
+
async function _loadPipeline() {
|
|
43
|
+
// Lazy, inside the function: @huggingface/transformers is an
|
|
44
|
+
// optionalDependency and an ESM-only package — import() from CJS.
|
|
45
|
+
const { pipeline, env } = await import('@huggingface/transformers');
|
|
46
|
+
env.cacheDir = CACHE_DIR;
|
|
47
|
+
const started = Date.now();
|
|
48
|
+
logger.info({ model: MODEL_ID, cacheDir: CACHE_DIR, dtype: DTYPE },
|
|
49
|
+
'[OnnxEmbedder] Loading embedding model (first run downloads weights)');
|
|
50
|
+
const extractor = await pipeline('feature-extraction', MODEL_ID, { dtype: DTYPE });
|
|
51
|
+
logger.info({ model: MODEL_ID, loadMs: Date.now() - started },
|
|
52
|
+
'[OnnxEmbedder] Embedding model ready');
|
|
53
|
+
return extractor;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Generate an embedding fully in-process.
|
|
58
|
+
* @param {string} text
|
|
59
|
+
* @returns {Promise<number[]>} mean-pooled, L2-normalized vector (768-dim
|
|
60
|
+
* for the default model)
|
|
61
|
+
*/
|
|
62
|
+
async function generateOnnxEmbedding(text) {
|
|
63
|
+
if (!pipelinePromise) {
|
|
64
|
+
pipelinePromise = _loadPipeline().catch((err) => {
|
|
65
|
+
// Reset so a later call can retry (e.g. transient download failure) —
|
|
66
|
+
// a failed load must not latch permanently, same principle as the
|
|
67
|
+
// provider degradation fix in cache/embeddings.js.
|
|
68
|
+
pipelinePromise = null;
|
|
69
|
+
throw err;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const extractor = await pipelinePromise;
|
|
73
|
+
const output = await extractor(text, { pooling: 'mean', normalize: true });
|
|
74
|
+
return Array.from(output.data);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** True when the optional dependency is installed (cheap resolve check). */
|
|
78
|
+
function isOnnxAvailable() {
|
|
79
|
+
try {
|
|
80
|
+
require.resolve('@huggingface/transformers');
|
|
81
|
+
return true;
|
|
82
|
+
} catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Test helper — drop the memoized pipeline. */
|
|
88
|
+
function _resetPipeline() {
|
|
89
|
+
pipelinePromise = null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = { generateOnnxEmbedding, isOnnxAvailable, _resetPipeline, MODEL_ID };
|
package/src/cache/prompt.js
CHANGED
|
@@ -19,13 +19,6 @@ const fs = require("fs");
|
|
|
19
19
|
const config = require("../config");
|
|
20
20
|
const logger = require("../logger");
|
|
21
21
|
|
|
22
|
-
function cloneValue(value) {
|
|
23
|
-
if (typeof structuredClone === "function") {
|
|
24
|
-
return structuredClone(value);
|
|
25
|
-
}
|
|
26
|
-
return JSON.parse(JSON.stringify(value));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
22
|
function normaliseObject(value) {
|
|
30
23
|
if (value === null || typeof value !== "object") return value;
|
|
31
24
|
if (Array.isArray(value)) {
|
|
@@ -116,7 +116,7 @@ function convertAnthropicToBedrockFormat(body, modelFamily) {
|
|
|
116
116
|
},
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
-
case "llama":
|
|
119
|
+
case "llama": {
|
|
120
120
|
// Meta Llama format
|
|
121
121
|
const llamaPrompt = messagesToPrompt(body.messages);
|
|
122
122
|
return {
|
|
@@ -125,6 +125,7 @@ function convertAnthropicToBedrockFormat(body, modelFamily) {
|
|
|
125
125
|
temperature: body.temperature || 0.7,
|
|
126
126
|
top_p: body.top_p || 0.9,
|
|
127
127
|
};
|
|
128
|
+
}
|
|
128
129
|
|
|
129
130
|
case "jurassic":
|
|
130
131
|
// AI21 Jurassic format
|
|
@@ -279,7 +279,7 @@ class CodexProcess {
|
|
|
279
279
|
* Reject all pending requests
|
|
280
280
|
*/
|
|
281
281
|
_rejectAllPending(error) {
|
|
282
|
-
for (const [
|
|
282
|
+
for (const [_id, pending] of this.pendingRequests) {
|
|
283
283
|
clearTimeout(pending.timeout);
|
|
284
284
|
pending.reject(error);
|
|
285
285
|
}
|