teleton 0.8.2 → 0.8.4
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 +230 -294
- package/dist/bootstrap-NNEI3Z5H.js +126 -0
- package/dist/{chunk-HEDJCLA6.js → chunk-35MX4ZUI.js} +2 -122
- package/dist/{chunk-57URFK6M.js → chunk-5LOHRZYY.js} +64 -15
- package/dist/{chunk-YOSUPUAJ.js → chunk-6OOHHJ4N.js} +1 -174
- package/dist/{chunk-W25Z7CM6.js → chunk-ALKAAG4O.js} +3 -3
- package/dist/chunk-CUE4UZXR.js +129 -0
- package/dist/{chunk-XBSCYMKM.js → chunk-G7PCW63M.js} +14 -14
- package/dist/{chunk-VYKW7FMV.js → chunk-GHMXWAXI.js} +1 -1
- package/dist/chunk-JROBTXWY.js +908 -0
- package/dist/{chunk-J73TA3UM.js → chunk-LVTKJQ7O.js} +7 -5
- package/dist/{chunk-GGXJLMOH.js → chunk-LZQOX6YY.js} +283 -1061
- package/dist/{chunk-7YKSXOQQ.js → chunk-NH2CNRKJ.js} +131 -241
- package/dist/chunk-NVKBBTI6.js +128 -0
- package/dist/{chunk-2IZU3REP.js → chunk-UMUONAD6.js} +143 -220
- package/dist/chunk-WTDAICGT.js +175 -0
- package/dist/{chunk-55SKE6YH.js → chunk-XDZDOKIF.js} +1 -1
- package/dist/cli/index.js +41 -24
- package/dist/{client-YOOHI776.js → client-5KD25NOP.js} +4 -3
- package/dist/index.js +14 -10
- package/dist/local-IHKJFQJS.js +9 -0
- package/dist/{memory-Q6EWGK2S.js → memory-QMJRM3XJ.js} +5 -3
- package/dist/{memory-hook-WUXJNVT5.js → memory-hook-VUNWZ3NY.js} +5 -4
- package/dist/{migrate-WFU6COBN.js → migrate-5VBAP52B.js} +3 -2
- package/dist/{server-YODFBZKG.js → server-AJCOURH7.js} +13 -10
- package/dist/{server-GYZXKIKU.js → server-WWGVDFPW.js} +38 -13
- package/dist/{setup-server-IZBUOJRU.js → setup-server-VDY64CWW.js} +5 -3
- package/dist/{store-7M4XV6M5.js → store-BY7S6IFN.js} +4 -3
- package/dist/{tool-index-NYH57UWP.js → tool-index-FTERJSZK.js} +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TELETON_ROOT
|
|
3
|
+
} from "./chunk-EYWNOHMJ.js";
|
|
4
|
+
import {
|
|
5
|
+
createLogger
|
|
6
|
+
} from "./chunk-NQ6FZKCE.js";
|
|
7
|
+
|
|
8
|
+
// src/memory/embeddings/local.ts
|
|
9
|
+
import { pipeline, env } from "@huggingface/transformers";
|
|
10
|
+
import { join, dirname } from "path";
|
|
11
|
+
import { mkdirSync, writeFileSync, renameSync, statSync, unlinkSync } from "fs";
|
|
12
|
+
var log = createLogger("Memory");
|
|
13
|
+
var modelCacheDir = join(TELETON_ROOT, "models");
|
|
14
|
+
try {
|
|
15
|
+
mkdirSync(modelCacheDir, { recursive: true });
|
|
16
|
+
} catch {
|
|
17
|
+
}
|
|
18
|
+
env.cacheDir = modelCacheDir;
|
|
19
|
+
var MIN_FILE_SIZES = { "onnx/model.onnx": 1e6 };
|
|
20
|
+
function isCacheFileValid(filePath, fileName) {
|
|
21
|
+
try {
|
|
22
|
+
return statSync(filePath).size >= (MIN_FILE_SIZES[fileName] ?? 1);
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function ensureModelCached(model) {
|
|
28
|
+
const files = ["config.json", "tokenizer_config.json", "tokenizer.json", "onnx/model.onnx"];
|
|
29
|
+
const baseUrl = `https://huggingface.co/${model}/resolve/main`;
|
|
30
|
+
for (const file of files) {
|
|
31
|
+
const localPath = join(modelCacheDir, model, file);
|
|
32
|
+
if (isCacheFileValid(localPath, file)) continue;
|
|
33
|
+
try {
|
|
34
|
+
unlinkSync(localPath);
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
log.info(`Downloading ${model}/${file}...`);
|
|
38
|
+
mkdirSync(dirname(localPath), { recursive: true });
|
|
39
|
+
const res = await fetch(`${baseUrl}/${file}`, { redirect: "follow" });
|
|
40
|
+
if (!res.ok) {
|
|
41
|
+
throw new Error(`Failed to download ${model}/${file}: ${res.status} ${res.statusText}`);
|
|
42
|
+
}
|
|
43
|
+
const buffer = Buffer.from(await res.arrayBuffer());
|
|
44
|
+
const tmpPath = localPath + ".tmp";
|
|
45
|
+
writeFileSync(tmpPath, buffer);
|
|
46
|
+
renameSync(tmpPath, localPath);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
var extractorPromise = null;
|
|
50
|
+
function getExtractor(model) {
|
|
51
|
+
if (!extractorPromise) {
|
|
52
|
+
log.info(`Loading local embedding model: ${model} (cache: ${modelCacheDir})`);
|
|
53
|
+
extractorPromise = pipeline("feature-extraction", model, {
|
|
54
|
+
dtype: "fp32",
|
|
55
|
+
// Explicit cache_dir to avoid any env race condition
|
|
56
|
+
cache_dir: modelCacheDir,
|
|
57
|
+
// Prevent pthread_setaffinity_np EINVAL on VPS/containers with restricted CPU sets.
|
|
58
|
+
// ONNX Runtime skips thread affinity when thread counts are explicit.
|
|
59
|
+
session_options: { intraOpNumThreads: 1, interOpNumThreads: 1 }
|
|
60
|
+
}).then((ext) => {
|
|
61
|
+
log.info(`Local embedding model ready`);
|
|
62
|
+
return ext;
|
|
63
|
+
}).catch((err) => {
|
|
64
|
+
log.error(`Failed to load embedding model: ${err.message}`);
|
|
65
|
+
extractorPromise = null;
|
|
66
|
+
throw err;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return extractorPromise;
|
|
70
|
+
}
|
|
71
|
+
var LocalEmbeddingProvider = class {
|
|
72
|
+
id = "local";
|
|
73
|
+
model;
|
|
74
|
+
dimensions;
|
|
75
|
+
_disabled = false;
|
|
76
|
+
constructor(config) {
|
|
77
|
+
this.model = config.model || "Xenova/all-MiniLM-L6-v2";
|
|
78
|
+
this.dimensions = 384;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Pre-download and load the model at startup.
|
|
82
|
+
* If loading fails, retries once then marks provider as disabled (FTS5-only).
|
|
83
|
+
* Call this once during app init — avoids retry spam on every message.
|
|
84
|
+
*/
|
|
85
|
+
async warmup() {
|
|
86
|
+
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
87
|
+
try {
|
|
88
|
+
await ensureModelCached(this.model);
|
|
89
|
+
await getExtractor(this.model);
|
|
90
|
+
return true;
|
|
91
|
+
} catch {
|
|
92
|
+
if (attempt === 1) {
|
|
93
|
+
log.warn(`Embedding model load failed (attempt 1), retrying...`);
|
|
94
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
95
|
+
} else {
|
|
96
|
+
log.warn(
|
|
97
|
+
`Local embedding model unavailable \u2014 falling back to FTS5-only search (no vector embeddings)`
|
|
98
|
+
);
|
|
99
|
+
this._disabled = true;
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
async embedQuery(text) {
|
|
107
|
+
if (this._disabled) return [];
|
|
108
|
+
const extractor = await getExtractor(this.model);
|
|
109
|
+
const output = await extractor(text, { pooling: "mean", normalize: true });
|
|
110
|
+
return Array.from(output.data);
|
|
111
|
+
}
|
|
112
|
+
async embedBatch(texts) {
|
|
113
|
+
if (this._disabled) return [];
|
|
114
|
+
if (texts.length === 0) return [];
|
|
115
|
+
const extractor = await getExtractor(this.model);
|
|
116
|
+
const output = await extractor(texts, { pooling: "mean", normalize: true });
|
|
117
|
+
const data = output.data;
|
|
118
|
+
const dims = this.dimensions;
|
|
119
|
+
const results = [];
|
|
120
|
+
for (let i = 0; i < texts.length; i++) {
|
|
121
|
+
results.push(Array.from(data.slice(i * dims, (i + 1) * dims)));
|
|
122
|
+
}
|
|
123
|
+
return results;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export {
|
|
128
|
+
LocalEmbeddingProvider
|
|
129
|
+
};
|
|
@@ -2,25 +2,20 @@ import {
|
|
|
2
2
|
getModelsForProvider
|
|
3
3
|
} from "./chunk-WFTC3JJW.js";
|
|
4
4
|
import {
|
|
5
|
-
CONFIGURABLE_KEYS,
|
|
6
5
|
TonProxyManager,
|
|
7
6
|
WorkspaceSecurityError,
|
|
8
7
|
adaptPlugin,
|
|
9
8
|
clearPromptCache,
|
|
10
|
-
deleteNestedValue,
|
|
11
9
|
deletePluginSecret,
|
|
12
10
|
ensurePluginDeps,
|
|
13
11
|
getBlocklistConfig,
|
|
14
|
-
getNestedValue,
|
|
15
12
|
getPluginPriorities,
|
|
16
13
|
getTokenUsage,
|
|
17
14
|
getTonProxyManager,
|
|
18
15
|
getTriggersConfig,
|
|
19
16
|
listPluginSecretKeys,
|
|
20
|
-
readRawConfig,
|
|
21
17
|
resetPluginPriority,
|
|
22
18
|
setBlocklistConfig,
|
|
23
|
-
setNestedValue,
|
|
24
19
|
setPluginPriority,
|
|
25
20
|
setTonProxyManager,
|
|
26
21
|
setTriggersConfig,
|
|
@@ -28,24 +23,29 @@ import {
|
|
|
28
23
|
validatePath,
|
|
29
24
|
validateReadPath,
|
|
30
25
|
validateWritePath,
|
|
31
|
-
writePluginSecret
|
|
32
|
-
|
|
33
|
-
} from "./chunk-GGXJLMOH.js";
|
|
26
|
+
writePluginSecret
|
|
27
|
+
} from "./chunk-LZQOX6YY.js";
|
|
34
28
|
import {
|
|
29
|
+
CONFIGURABLE_KEYS,
|
|
30
|
+
deleteNestedValue,
|
|
31
|
+
getNestedValue,
|
|
35
32
|
invalidateEndpointCache,
|
|
36
33
|
invalidateTonClientCache,
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
readRawConfig,
|
|
35
|
+
setNestedValue,
|
|
36
|
+
setToncenterApiKey,
|
|
37
|
+
writeRawConfig
|
|
38
|
+
} from "./chunk-JROBTXWY.js";
|
|
39
39
|
import {
|
|
40
40
|
getErrorMessage
|
|
41
41
|
} from "./chunk-3UFPFWYP.js";
|
|
42
|
-
import {
|
|
43
|
-
getProviderMetadata,
|
|
44
|
-
validateApiKeyFormat
|
|
45
|
-
} from "./chunk-YOSUPUAJ.js";
|
|
46
42
|
import {
|
|
47
43
|
setTonapiKey
|
|
48
44
|
} from "./chunk-VFA7QMCZ.js";
|
|
45
|
+
import {
|
|
46
|
+
getProviderMetadata,
|
|
47
|
+
validateApiKeyFormat
|
|
48
|
+
} from "./chunk-6OOHHJ4N.js";
|
|
49
49
|
import {
|
|
50
50
|
WORKSPACE_PATHS,
|
|
51
51
|
WORKSPACE_ROOT
|