teleton 0.8.1 → 0.8.2

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 (36) hide show
  1. package/dist/{chunk-5FNWBZ5K.js → chunk-2IZU3REP.js} +147 -82
  2. package/dist/chunk-3UFPFWYP.js +12 -0
  3. package/dist/{chunk-KVXV7EF7.js → chunk-55SKE6YH.js} +2 -2
  4. package/dist/{setup-server-32XGDPE6.js → chunk-57URFK6M.js} +7 -206
  5. package/dist/chunk-5SEMA47R.js +75 -0
  6. package/dist/{chunk-S6PHGKOC.js → chunk-7YKSXOQQ.js} +10 -2
  7. package/dist/{chunk-UP55PXFH.js → chunk-C4NKJT2Z.js} +8 -0
  8. package/dist/{chunk-CGOXE4WP.js → chunk-GGXJLMOH.js} +404 -730
  9. package/dist/{chunk-QBHRXLZS.js → chunk-H7MFXJZK.js} +2 -2
  10. package/dist/{chunk-3S4GGLLR.js → chunk-HEDJCLA6.js} +58 -19
  11. package/dist/{chunk-AYWEJCDB.js → chunk-J73TA3UM.js} +7 -7
  12. package/dist/{chunk-QV2GLOTK.js → chunk-LC4TV3KL.js} +1 -1
  13. package/dist/{chunk-RCMD3U65.js → chunk-NQ6FZKCE.js} +13 -0
  14. package/dist/{chunk-7U7BOHCL.js → chunk-VYKW7FMV.js} +147 -63
  15. package/dist/chunk-W25Z7CM6.js +487 -0
  16. package/dist/{chunk-OJCLKU5Z.js → chunk-WFTC3JJW.js} +16 -0
  17. package/dist/{server-3FHI2SEB.js → chunk-XBSCYMKM.js} +23 -369
  18. package/dist/{chunk-PHSAHTK4.js → chunk-YOSUPUAJ.js} +75 -7
  19. package/dist/cli/index.js +61 -17
  20. package/dist/{client-MPHPIZB6.js → client-YOOHI776.js} +4 -4
  21. package/dist/{get-my-gifts-CC6HAVWB.js → get-my-gifts-Y7EN7RK4.js} +3 -3
  22. package/dist/index.js +14 -13
  23. package/dist/{memory-UBHM7ILG.js → memory-Q6EWGK2S.js} +6 -4
  24. package/dist/memory-hook-WUXJNVT5.js +18 -0
  25. package/dist/{migrate-UBBEJ5BL.js → migrate-WFU6COBN.js} +4 -4
  26. package/dist/server-GYZXKIKU.js +787 -0
  27. package/dist/server-YODFBZKG.js +392 -0
  28. package/dist/setup-server-IZBUOJRU.js +215 -0
  29. package/dist/{store-M5IMUQCL.js → store-7M4XV6M5.js} +5 -5
  30. package/dist/{task-dependency-resolver-RR2O5S7B.js → task-dependency-resolver-L6UUMTHK.js} +2 -2
  31. package/dist/{task-executor-6W5HRX5C.js → task-executor-XBNJLUCS.js} +2 -2
  32. package/dist/{tool-adapter-IH5VGBOO.js → tool-adapter-IVX2XQJE.js} +1 -1
  33. package/dist/{tool-index-PMAOXWUA.js → tool-index-NYH57UWP.js} +3 -3
  34. package/dist/{transcript-NGDPSNIH.js → transcript-IM7G25OS.js} +2 -2
  35. package/package.json +4 -2
  36. package/dist/chunk-XBE4JB7C.js +0 -8
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  getErrorMessage
3
- } from "./chunk-XBE4JB7C.js";
3
+ } from "./chunk-3UFPFWYP.js";
4
4
  import {
5
5
  createLogger
6
- } from "./chunk-RCMD3U65.js";
6
+ } from "./chunk-NQ6FZKCE.js";
7
7
 
8
8
  // src/agent/tools/telegram/gifts/get-my-gifts.ts
9
9
  import { Type } from "@sinclair/typebox";
@@ -7,7 +7,7 @@ import {
7
7
  EMBEDDING_CACHE_MAX_ENTRIES,
8
8
  EMBEDDING_CACHE_TTL_DAYS,
9
9
  VOYAGE_BATCH_SIZE
10
- } from "./chunk-UP55PXFH.js";
10
+ } from "./chunk-C4NKJT2Z.js";
11
11
  import {
12
12
  fetchWithTimeout
13
13
  } from "./chunk-XQUHC3JZ.js";
@@ -16,7 +16,7 @@ import {
16
16
  } from "./chunk-EYWNOHMJ.js";
17
17
  import {
18
18
  createLogger
19
- } from "./chunk-RCMD3U65.js";
19
+ } from "./chunk-NQ6FZKCE.js";
20
20
 
21
21
  // src/memory/embeddings/provider.ts
22
22
  var NoopEmbeddingProvider = class {
@@ -52,7 +52,7 @@ var AnthropicEmbeddingProvider = class {
52
52
  this.dimensions = dims[this.model] ?? 512;
53
53
  }
54
54
  async embedQuery(text) {
55
- const result = await this.embed([text]);
55
+ const result = await this.embed([text], "query");
56
56
  return result[0] ?? [];
57
57
  }
58
58
  async embedBatch(texts) {
@@ -66,7 +66,7 @@ var AnthropicEmbeddingProvider = class {
66
66
  }
67
67
  return results;
68
68
  }
69
- async embed(texts) {
69
+ async embed(texts, inputType = "document") {
70
70
  const response = await fetchWithTimeout(`${this.baseUrl}/embeddings`, {
71
71
  method: "POST",
72
72
  headers: {
@@ -76,7 +76,7 @@ var AnthropicEmbeddingProvider = class {
76
76
  body: JSON.stringify({
77
77
  input: texts,
78
78
  model: this.model,
79
- input_type: "document"
79
+ input_type: inputType
80
80
  })
81
81
  });
82
82
  if (!response.ok) {
@@ -90,8 +90,8 @@ var AnthropicEmbeddingProvider = class {
90
90
 
91
91
  // src/memory/embeddings/local.ts
92
92
  import { pipeline, env } from "@huggingface/transformers";
93
- import { join } from "path";
94
- import { mkdirSync } from "fs";
93
+ import { join, dirname } from "path";
94
+ import { mkdirSync, writeFileSync, renameSync, statSync, unlinkSync } from "fs";
95
95
  var log = createLogger("Memory");
96
96
  var modelCacheDir = join(TELETON_ROOT, "models");
97
97
  try {
@@ -99,6 +99,36 @@ try {
99
99
  } catch {
100
100
  }
101
101
  env.cacheDir = modelCacheDir;
102
+ var MIN_FILE_SIZES = { "onnx/model.onnx": 1e6 };
103
+ function isCacheFileValid(filePath, fileName) {
104
+ try {
105
+ return statSync(filePath).size >= (MIN_FILE_SIZES[fileName] ?? 1);
106
+ } catch {
107
+ return false;
108
+ }
109
+ }
110
+ async function ensureModelCached(model) {
111
+ const files = ["config.json", "tokenizer_config.json", "tokenizer.json", "onnx/model.onnx"];
112
+ const baseUrl = `https://huggingface.co/${model}/resolve/main`;
113
+ for (const file of files) {
114
+ const localPath = join(modelCacheDir, model, file);
115
+ if (isCacheFileValid(localPath, file)) continue;
116
+ try {
117
+ unlinkSync(localPath);
118
+ } catch {
119
+ }
120
+ log.info(`Downloading ${model}/${file}...`);
121
+ mkdirSync(dirname(localPath), { recursive: true });
122
+ const res = await fetch(`${baseUrl}/${file}`, { redirect: "follow" });
123
+ if (!res.ok) {
124
+ throw new Error(`Failed to download ${model}/${file}: ${res.status} ${res.statusText}`);
125
+ }
126
+ const buffer = Buffer.from(await res.arrayBuffer());
127
+ const tmpPath = localPath + ".tmp";
128
+ writeFileSync(tmpPath, buffer);
129
+ renameSync(tmpPath, localPath);
130
+ }
131
+ }
102
132
  var extractorPromise = null;
103
133
  function getExtractor(model) {
104
134
  if (!extractorPromise) {
@@ -106,7 +136,10 @@ function getExtractor(model) {
106
136
  extractorPromise = pipeline("feature-extraction", model, {
107
137
  dtype: "fp32",
108
138
  // Explicit cache_dir to avoid any env race condition
109
- cache_dir: modelCacheDir
139
+ cache_dir: modelCacheDir,
140
+ // Prevent pthread_setaffinity_np EINVAL on VPS/containers with restricted CPU sets.
141
+ // ONNX Runtime skips thread affinity when thread counts are explicit.
142
+ session_options: { intraOpNumThreads: 1, interOpNumThreads: 1 }
110
143
  }).then((ext) => {
111
144
  log.info(`Local embedding model ready`);
112
145
  return ext;
@@ -131,11 +164,11 @@ var LocalEmbeddingProvider = class {
131
164
  * Pre-download and load the model at startup.
132
165
  * If loading fails, retries once then marks provider as disabled (FTS5-only).
133
166
  * Call this once during app init — avoids retry spam on every message.
134
- * @returns true if model loaded successfully, false if fallback to noop
135
167
  */
136
168
  async warmup() {
137
169
  for (let attempt = 1; attempt <= 2; attempt++) {
138
170
  try {
171
+ await ensureModelCached(this.model);
139
172
  await getExtractor(this.model);
140
173
  return true;
141
174
  } catch {
@@ -202,6 +235,16 @@ var CachedEmbeddingProvider = class _CachedEmbeddingProvider {
202
235
  this.id = inner.id;
203
236
  this.model = inner.model;
204
237
  this.dimensions = inner.dimensions;
238
+ this.stmtCacheGet = db.prepare(
239
+ `SELECT embedding FROM embedding_cache WHERE hash = ? AND model = ? AND provider = ?`
240
+ );
241
+ this.stmtCachePut = db.prepare(
242
+ `INSERT OR REPLACE INTO embedding_cache (hash, embedding, model, provider, dims, created_at, accessed_at)
243
+ VALUES (?, ?, ?, ?, ?, unixepoch(), unixepoch())`
244
+ );
245
+ this.stmtCacheTouch = db.prepare(
246
+ `UPDATE embedding_cache SET accessed_at = unixepoch() WHERE hash = ? AND model = ? AND provider = ?`
247
+ );
205
248
  }
206
249
  id;
207
250
  model;
@@ -210,21 +253,17 @@ var CachedEmbeddingProvider = class _CachedEmbeddingProvider {
210
253
  hits = 0;
211
254
  misses = 0;
212
255
  ops = 0;
256
+ stmtCacheGet;
257
+ stmtCachePut;
258
+ stmtCacheTouch;
213
259
  cacheGet(hash) {
214
- return this.db.prepare(
215
- `SELECT embedding FROM embedding_cache WHERE hash = ? AND model = ? AND provider = ?`
216
- ).get(hash, this.model, this.id);
260
+ return this.stmtCacheGet.get(hash, this.model, this.id);
217
261
  }
218
262
  cachePut(hash, blob) {
219
- this.db.prepare(
220
- `INSERT OR REPLACE INTO embedding_cache (hash, embedding, model, provider, dims, created_at, accessed_at)
221
- VALUES (?, ?, ?, ?, ?, unixepoch(), unixepoch())`
222
- ).run(hash, blob, this.model, this.id, this.dimensions);
263
+ this.stmtCachePut.run(hash, blob, this.model, this.id, this.dimensions);
223
264
  }
224
265
  cacheTouch(hash) {
225
- this.db.prepare(
226
- `UPDATE embedding_cache SET accessed_at = unixepoch() WHERE hash = ? AND model = ? AND provider = ?`
227
- ).run(hash, this.model, this.id);
266
+ this.stmtCacheTouch.run(hash, this.model, this.id);
228
267
  }
229
268
  async warmup() {
230
269
  return this.inner.warmup?.() ?? true;
@@ -2,17 +2,17 @@ import {
2
2
  getClaudeCodeApiKey,
3
3
  getProviderMetadata,
4
4
  refreshClaudeCodeApiKey
5
- } from "./chunk-PHSAHTK4.js";
5
+ } from "./chunk-YOSUPUAJ.js";
6
6
  import {
7
7
  appendToTranscript,
8
8
  readTranscript
9
- } from "./chunk-QV2GLOTK.js";
9
+ } from "./chunk-LC4TV3KL.js";
10
10
  import {
11
11
  fetchWithTimeout
12
12
  } from "./chunk-XQUHC3JZ.js";
13
13
  import {
14
14
  createLogger
15
- } from "./chunk-RCMD3U65.js";
15
+ } from "./chunk-NQ6FZKCE.js";
16
16
 
17
17
  // src/agent/client.ts
18
18
  import {
@@ -262,7 +262,7 @@ async function chatWithContext(config, options) {
262
262
  systemPrompt = "/no_think\n" + systemPrompt;
263
263
  if (tools && tools.length > 0) {
264
264
  cocoonAllowedTools = new Set(tools.map((t) => t.name));
265
- const { injectToolsIntoSystemPrompt } = await import("./tool-adapter-IH5VGBOO.js");
265
+ const { injectToolsIntoSystemPrompt } = await import("./tool-adapter-IVX2XQJE.js");
266
266
  systemPrompt = injectToolsIntoSystemPrompt(systemPrompt, tools);
267
267
  tools = void 0;
268
268
  }
@@ -281,13 +281,13 @@ async function chatWithContext(config, options) {
281
281
  cacheRetention: "long"
282
282
  };
283
283
  if (isCocoon) {
284
- const { stripCocoonPayload } = await import("./tool-adapter-IH5VGBOO.js");
284
+ const { stripCocoonPayload } = await import("./tool-adapter-IVX2XQJE.js");
285
285
  completeOptions.onPayload = stripCocoonPayload;
286
286
  }
287
287
  let response = await complete(model, context, completeOptions);
288
288
  if (provider === "claude-code" && response.stopReason === "error" && response.errorMessage && (response.errorMessage.includes("401") || response.errorMessage.toLowerCase().includes("unauthorized"))) {
289
289
  log.warn("Claude Code token rejected (401), refreshing credentials and retrying...");
290
- const refreshedKey = refreshClaudeCodeApiKey();
290
+ const refreshedKey = await refreshClaudeCodeApiKey();
291
291
  if (refreshedKey) {
292
292
  completeOptions.apiKey = refreshedKey;
293
293
  response = await complete(model, context, completeOptions);
@@ -296,7 +296,7 @@ async function chatWithContext(config, options) {
296
296
  if (isCocoon) {
297
297
  const textBlock = response.content.find((b) => b.type === "text");
298
298
  if (textBlock?.type === "text" && textBlock.text.includes("<tool_call>")) {
299
- const { parseToolCallsFromText, extractPlainText } = await import("./tool-adapter-IH5VGBOO.js");
299
+ const { parseToolCallsFromText, extractPlainText } = await import("./tool-adapter-IVX2XQJE.js");
300
300
  const syntheticCalls = parseToolCallsFromText(textBlock.text, cocoonAllowedTools);
301
301
  if (syntheticCalls.length > 0) {
302
302
  const plainText = extractPlainText(textBlock.text);
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-EYWNOHMJ.js";
4
4
  import {
5
5
  createLogger
6
- } from "./chunk-RCMD3U65.js";
6
+ } from "./chunk-NQ6FZKCE.js";
7
7
 
8
8
  // src/session/transcript.ts
9
9
  import {
@@ -88,12 +88,20 @@ var rootLogger = pino(
88
88
  paths: [
89
89
  "apiKey",
90
90
  "api_key",
91
+ "api_hash",
92
+ "accessToken",
93
+ "access_token",
94
+ "refresh_token",
91
95
  "password",
92
96
  "secret",
93
97
  "token",
94
98
  "mnemonic",
95
99
  "*.apiKey",
96
100
  "*.api_key",
101
+ "*.api_hash",
102
+ "*.accessToken",
103
+ "*.access_token",
104
+ "*.refresh_token",
97
105
  "*.password",
98
106
  "*.secret",
99
107
  "*.token",
@@ -120,6 +128,11 @@ function setLogLevel(level) {
120
128
  const streams = multiStream.streams;
121
129
  if (Array.isArray(streams) && streams[0]) {
122
130
  streams[0].level = pino.levels.values[level] ?? 30;
131
+ } else {
132
+ process.stderr.write(
133
+ `[Logger] setLogLevel: pino multistream internal API changed, stdout level not updated
134
+ `
135
+ );
123
136
  }
124
137
  _verbose = level === "debug" || level === "trace";
125
138
  }