teleton 0.7.5 → 0.8.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 (43) hide show
  1. package/README.md +35 -15
  2. package/dist/chunk-3RG5ZIWI.js +10 -0
  3. package/dist/{chunk-LCCVZ4D2.js → chunk-3S4GGLLR.js} +28 -26
  4. package/dist/{chunk-NUGDTPE4.js → chunk-4L66JHQE.js} +2 -1
  5. package/dist/{chunk-OGMVWDVU.js → chunk-5FNWBZ5K.js} +1826 -4992
  6. package/dist/{chunk-U7FQYCBQ.js → chunk-7TECSLJ4.js} +2 -2
  7. package/dist/{chunk-2GLHOJ5C.js → chunk-7U7BOHCL.js} +103 -36
  8. package/dist/{chunk-DMXTIRUW.js → chunk-AYWEJCDB.js} +20 -39
  9. package/dist/chunk-CGOXE4WP.js +11315 -0
  10. package/dist/{chunk-5UVXJMOX.js → chunk-KVXV7EF7.js} +4 -4
  11. package/dist/{chunk-QOQWUUA4.js → chunk-OJCLKU5Z.js} +68 -2
  12. package/dist/{chunk-CB2Y45HA.js → chunk-PHSAHTK4.js} +51 -3
  13. package/dist/{chunk-WIKM24GZ.js → chunk-QBHRXLZS.js} +5 -0
  14. package/dist/{chunk-OCLG5GKI.js → chunk-QV2GLOTK.js} +14 -3
  15. package/dist/{chunk-AVDWXYQ7.js → chunk-S6PHGKOC.js} +12 -1
  16. package/dist/{chunk-YP25WTQK.js → chunk-UP55PXFH.js} +6 -0
  17. package/dist/cli/index.js +21 -21
  18. package/dist/{client-O37XDCJB.js → client-MPHPIZB6.js} +4 -4
  19. package/dist/{get-my-gifts-TPVUGUWT.js → get-my-gifts-CC6HAVWB.js} +2 -2
  20. package/dist/index.js +14 -15
  21. package/dist/{memory-KQALFUV3.js → memory-UBHM7ILG.js} +5 -5
  22. package/dist/{migrate-UV3WEL5D.js → migrate-UBBEJ5BL.js} +5 -5
  23. package/dist/{multipart-parser-S3YC6NRJ.js → multipart-parser-UFQLJOV2.js} +2 -2
  24. package/dist/{paths-TMNTEDDD.js → paths-XA2RJH4S.js} +1 -1
  25. package/dist/{server-BHHJGUDF.js → server-3FHI2SEB.js} +398 -56
  26. package/dist/{setup-server-G7UG2DI3.js → setup-server-32XGDPE6.js} +161 -11
  27. package/dist/{store-H4XPNGC2.js → store-M5IMUQCL.js} +6 -6
  28. package/dist/{task-dependency-resolver-VMEVJRPO.js → task-dependency-resolver-RR2O5S7B.js} +3 -3
  29. package/dist/{task-executor-WWSPBJ4V.js → task-executor-6W5HRX5C.js} +3 -3
  30. package/dist/{tasks-QSCWSMPS.js → tasks-WQIKXDX5.js} +2 -2
  31. package/dist/{tool-adapter-Y3TCEQOC.js → tool-adapter-IH5VGBOO.js} +1 -1
  32. package/dist/{tool-index-2KH3OB6X.js → tool-index-PMAOXWUA.js} +9 -6
  33. package/dist/{transcript-UDJZP6NK.js → transcript-NGDPSNIH.js} +2 -2
  34. package/dist/web/assets/index-BfYCdwLI.js +80 -0
  35. package/dist/web/assets/{index-BrVqauzj.css → index-DmlyQVhR.css} +1 -1
  36. package/dist/web/assets/{index.es-Pet5-M13.js → index.es-DitvF-9H.js} +1 -1
  37. package/dist/web/index.html +2 -2
  38. package/package.json +12 -5
  39. package/dist/BigInteger-DQ33LTTE.js +0 -5
  40. package/dist/chunk-G2LLMJXJ.js +0 -5048
  41. package/dist/chunk-QGM4M3NI.js +0 -37
  42. package/dist/chunk-TSKJCWQQ.js +0 -1263
  43. package/dist/web/assets/index-Bx8JW3gV.js +0 -72
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __require
3
- } from "./chunk-QGM4M3NI.js";
3
+ } from "./chunk-3RG5ZIWI.js";
4
4
 
5
5
  // node_modules/node-fetch-native/dist/shared/node-fetch-native.DfbY2q-x.mjs
6
6
  var t = Object.defineProperty;
@@ -2722,7 +2722,7 @@ var Nn = class Nn2 {
2722
2722
  for (const [p, h] of l) f2.append(p, h);
2723
2723
  return f2;
2724
2724
  }
2725
- const { toFormData: a } = await import("./multipart-parser-S3YC6NRJ.js");
2725
+ const { toFormData: a } = await import("./multipart-parser-UFQLJOV2.js");
2726
2726
  return a(this.body, o2);
2727
2727
  }
2728
2728
  async blob() {
@@ -3,13 +3,14 @@ import {
3
3
  createEmbeddingProvider,
4
4
  hashText,
5
5
  serializeEmbedding
6
- } from "./chunk-LCCVZ4D2.js";
6
+ } from "./chunk-3S4GGLLR.js";
7
7
  import {
8
+ FEED_MESSAGE_MAX_CHARS,
8
9
  HYBRID_SEARCH_MIN_SCORE,
9
10
  KNOWLEDGE_CHUNK_SIZE,
10
11
  SQLITE_CACHE_SIZE_KB,
11
12
  SQLITE_MMAP_SIZE
12
- } from "./chunk-YP25WTQK.js";
13
+ } from "./chunk-UP55PXFH.js";
13
14
  import {
14
15
  TELETON_ROOT
15
16
  } from "./chunk-EYWNOHMJ.js";
@@ -132,11 +133,7 @@ function migrateFromMainDb(moduleDb, tables) {
132
133
  `INSERT OR IGNORE INTO ${table} (${cols}) SELECT ${cols} FROM main_db.${table}`
133
134
  );
134
135
  totalMigrated += src.c;
135
- try {
136
- moduleDb.exec(`DROP TABLE main_db.${table}`);
137
- } catch {
138
- }
139
- log.info(`Migrated ${src.c} rows from memory.db \u2192 ${table} (source dropped)`);
136
+ log.info(`Migrated ${src.c} rows from memory.db \u2192 ${table}`);
140
137
  } catch (e) {
141
138
  log.warn({ err: e }, `Could not migrate table ${table}`);
142
139
  }
@@ -426,6 +423,26 @@ function ensureSchema(db) {
426
423
  CREATE INDEX IF NOT EXISTS idx_exec_audit_timestamp ON exec_audit(timestamp DESC);
427
424
  CREATE INDEX IF NOT EXISTS idx_exec_audit_user ON exec_audit(user_id);
428
425
 
426
+ -- =====================================================
427
+ -- PLUGIN CONFIG (Plugin Priority Order)
428
+ -- =====================================================
429
+
430
+ CREATE TABLE IF NOT EXISTS plugin_config (
431
+ plugin_name TEXT PRIMARY KEY,
432
+ priority INTEGER NOT NULL DEFAULT 0,
433
+ updated_at TEXT NOT NULL DEFAULT (datetime('now'))
434
+ );
435
+
436
+ -- =====================================================
437
+ -- USER HOOK CONFIG (Keyword Blocklist + Context Triggers)
438
+ -- =====================================================
439
+
440
+ CREATE TABLE IF NOT EXISTS user_hook_config (
441
+ key TEXT PRIMARY KEY,
442
+ value TEXT NOT NULL,
443
+ updated_at TEXT NOT NULL DEFAULT (datetime('now'))
444
+ );
445
+
429
446
  -- =====================================================
430
447
  -- JOURNAL (Trading & Business Operations)
431
448
  -- =====================================================
@@ -468,7 +485,7 @@ function setSchemaVersion(db, version) {
468
485
  `
469
486
  ).run(version);
470
487
  }
471
- var CURRENT_SCHEMA_VERSION = "1.13.0";
488
+ var CURRENT_SCHEMA_VERSION = "1.15.0";
472
489
  function runMigrations(db) {
473
490
  const currentVersion = getSchemaVersion(db);
474
491
  if (!currentVersion || versionLessThan(currentVersion, "1.1.0")) {
@@ -522,7 +539,7 @@ function runMigrations(db) {
522
539
  try {
523
540
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${type}`);
524
541
  } catch (e) {
525
- if (!e.message.includes("duplicate column name")) {
542
+ if (!(e instanceof Error) || !e.message.includes("duplicate column name")) {
526
543
  throw e;
527
544
  }
528
545
  }
@@ -691,7 +708,7 @@ function runMigrations(db) {
691
708
  try {
692
709
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${type}`);
693
710
  } catch (e) {
694
- if (!e.message.includes("duplicate column name")) {
711
+ if (!(e instanceof Error) || !e.message.includes("duplicate column name")) {
695
712
  throw e;
696
713
  }
697
714
  }
@@ -704,6 +721,38 @@ function runMigrations(db) {
704
721
  throw error;
705
722
  }
706
723
  }
724
+ if (!currentVersion || versionLessThan(currentVersion, "1.14.0")) {
725
+ log2.info("Running migration 1.14.0: Add plugin_config table for plugin priority");
726
+ try {
727
+ db.exec(`
728
+ CREATE TABLE IF NOT EXISTS plugin_config (
729
+ plugin_name TEXT PRIMARY KEY,
730
+ priority INTEGER NOT NULL DEFAULT 0,
731
+ updated_at TEXT NOT NULL DEFAULT (datetime('now'))
732
+ );
733
+ `);
734
+ log2.info("Migration 1.14.0 complete: plugin_config table created");
735
+ } catch (error) {
736
+ log2.error({ err: error }, "Migration 1.14.0 failed");
737
+ throw error;
738
+ }
739
+ }
740
+ if (!currentVersion || versionLessThan(currentVersion, "1.15.0")) {
741
+ log2.info("Running migration 1.15.0: Add user_hook_config table");
742
+ try {
743
+ db.exec(`
744
+ CREATE TABLE IF NOT EXISTS user_hook_config (
745
+ key TEXT PRIMARY KEY,
746
+ value TEXT NOT NULL,
747
+ updated_at TEXT NOT NULL DEFAULT (datetime('now'))
748
+ );
749
+ `);
750
+ log2.info("Migration 1.15.0 complete: user_hook_config table created");
751
+ } catch (error) {
752
+ log2.error({ err: error }, "Migration 1.15.0 failed");
753
+ throw error;
754
+ }
755
+ }
707
756
  setSchemaVersion(db, CURRENT_SCHEMA_VERSION);
708
757
  }
709
758
 
@@ -1676,6 +1725,24 @@ var HybridSearch = class {
1676
1725
 
1677
1726
  // src/memory/search/context.ts
1678
1727
  var log6 = createLogger("Memory");
1728
+ function reorderForEdges(items) {
1729
+ if (items.length <= 2) return items;
1730
+ const result = new Array(items.length);
1731
+ let left = 0;
1732
+ let right = items.length - 1;
1733
+ for (let i = 0; i < items.length; i++) {
1734
+ if (i % 2 === 0) {
1735
+ result[left++] = items[i];
1736
+ } else {
1737
+ result[right--] = items[i];
1738
+ }
1739
+ }
1740
+ return result;
1741
+ }
1742
+ function truncateFeedMessage(text) {
1743
+ if (text.length <= FEED_MESSAGE_MAX_CHARS) return text;
1744
+ return text.slice(0, FEED_MESSAGE_MAX_CHARS) + "... [truncated]";
1745
+ }
1679
1746
  var ContextBuilder = class {
1680
1747
  constructor(db, embedder, vectorEnabled) {
1681
1748
  this.db = db;
@@ -1695,51 +1762,51 @@ var ContextBuilder = class {
1695
1762
  maxRecentMessages = 20,
1696
1763
  maxRelevantChunks = 5
1697
1764
  } = options;
1698
- const queryEmbedding = await this.embedder.embedQuery(query);
1765
+ const queryEmbedding = options.queryEmbedding ?? await this.embedder.embedQuery(query);
1699
1766
  const recentTgMessages = this.messageStore.getRecentMessages(chatId, maxRecentMessages);
1700
1767
  const recentMessages = recentTgMessages.map((m) => ({
1701
1768
  role: m.isFromAgent ? "assistant" : "user",
1702
1769
  content: m.text ?? ""
1703
1770
  }));
1704
- const relevantKnowledge = [];
1705
- if (includeAgentMemory) {
1706
- try {
1707
- const knowledgeResults = await this.hybridSearch.searchKnowledge(query, queryEmbedding, {
1708
- limit: maxRelevantChunks
1709
- });
1710
- relevantKnowledge.push(...knowledgeResults.map((r) => r.text));
1711
- } catch (error) {
1712
- log6.warn({ err: error }, "Knowledge search failed");
1713
- }
1714
- }
1715
1771
  const recentTextsSet = new Set(
1772
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- filtered for non-null text above
1716
1773
  recentTgMessages.filter((m) => m.text && m.text.length > 0).map((m) => m.text)
1717
1774
  );
1775
+ const knowledgePromise = includeAgentMemory ? this.hybridSearch.searchKnowledge(query, queryEmbedding, { limit: maxRelevantChunks }).catch((error) => {
1776
+ log6.warn({ err: error }, "Knowledge search failed");
1777
+ return [];
1778
+ }) : Promise.resolve([]);
1779
+ const feedPromise = includeFeedHistory ? this.hybridSearch.searchMessages(query, queryEmbedding, { chatId, limit: maxRelevantChunks }).catch((error) => {
1780
+ log6.warn({ err: error }, "Feed search failed");
1781
+ return [];
1782
+ }) : Promise.resolve([]);
1783
+ const [knowledgeResults, feedResults] = await Promise.all([knowledgePromise, feedPromise]);
1784
+ const relevantKnowledge = [];
1785
+ if (knowledgeResults.length > 0) {
1786
+ relevantKnowledge.push(...reorderForEdges(knowledgeResults.map((r) => r.text)));
1787
+ }
1718
1788
  const relevantFeed = [];
1719
1789
  if (includeFeedHistory) {
1720
- try {
1721
- const feedResults = await this.hybridSearch.searchMessages(query, queryEmbedding, {
1722
- chatId,
1723
- limit: maxRelevantChunks
1724
- });
1725
- for (const r of feedResults) {
1726
- if (!recentTextsSet.has(r.text)) {
1727
- relevantFeed.push(r.text);
1728
- }
1790
+ for (const r of feedResults) {
1791
+ if (!recentTextsSet.has(r.text)) {
1792
+ relevantFeed.push(truncateFeedMessage(r.text));
1729
1793
  }
1730
- if (searchAllChats) {
1794
+ }
1795
+ if (searchAllChats) {
1796
+ try {
1731
1797
  const globalResults = await this.hybridSearch.searchMessages(query, queryEmbedding, {
1732
1798
  limit: maxRelevantChunks
1733
1799
  });
1734
1800
  const existingTexts = new Set(relevantFeed);
1735
1801
  for (const r of globalResults) {
1736
- if (!existingTexts.has(r.text)) {
1737
- relevantFeed.push(`[From chat ${r.source}]: ${r.text}`);
1802
+ const truncated = truncateFeedMessage(r.text);
1803
+ if (!existingTexts.has(truncated)) {
1804
+ relevantFeed.push(`[From chat ${r.source}]: ${truncated}`);
1738
1805
  }
1739
1806
  }
1807
+ } catch (error) {
1808
+ log6.warn({ err: error }, "Global feed search failed");
1740
1809
  }
1741
- } catch (error) {
1742
- log6.warn({ err: error }, "Feed search failed");
1743
1810
  }
1744
1811
  if (relevantFeed.length === 0 && recentTgMessages.length > 0) {
1745
1812
  const recentTexts = recentTgMessages.filter((m) => m.text && m.text.length > 0).slice(-maxRelevantChunks).map((m) => {
@@ -2,11 +2,11 @@ import {
2
2
  getClaudeCodeApiKey,
3
3
  getProviderMetadata,
4
4
  refreshClaudeCodeApiKey
5
- } from "./chunk-CB2Y45HA.js";
5
+ } from "./chunk-PHSAHTK4.js";
6
6
  import {
7
7
  appendToTranscript,
8
8
  readTranscript
9
- } from "./chunk-OCLG5GKI.js";
9
+ } from "./chunk-QV2GLOTK.js";
10
10
  import {
11
11
  fetchWithTimeout
12
12
  } from "./chunk-XQUHC3JZ.js";
@@ -183,31 +183,8 @@ async function registerLocalModels(baseUrl) {
183
183
  return [];
184
184
  }
185
185
  }
186
- var MOONSHOT_MODELS = {
187
- "kimi-k2.5": {
188
- id: "kimi-k2.5",
189
- name: "Kimi K2.5",
190
- api: "openai-completions",
191
- provider: "moonshot",
192
- baseUrl: "https://api.moonshot.ai/v1",
193
- reasoning: false,
194
- input: ["text", "image"],
195
- cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
196
- contextWindow: 256e3,
197
- maxTokens: 8192
198
- },
199
- "kimi-k2-thinking": {
200
- id: "kimi-k2-thinking",
201
- name: "Kimi K2 Thinking",
202
- api: "openai-completions",
203
- provider: "moonshot",
204
- baseUrl: "https://api.moonshot.ai/v1",
205
- reasoning: true,
206
- input: ["text"],
207
- cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
208
- contextWindow: 256e3,
209
- maxTokens: 8192
210
- }
186
+ var MOONSHOT_MODEL_ALIASES = {
187
+ "kimi-k2.5": "k2p5"
211
188
  };
212
189
  function getProviderModel(provider, modelId) {
213
190
  const cacheKey = `${provider}:${modelId}`;
@@ -238,12 +215,8 @@ function getProviderModel(provider, modelId) {
238
215
  }
239
216
  throw new Error("No local models available. Is the LLM server running?");
240
217
  }
241
- if (meta.piAiProvider === "moonshot") {
242
- const model = MOONSHOT_MODELS[modelId] ?? MOONSHOT_MODELS[meta.defaultModel];
243
- if (model) {
244
- modelCache.set(cacheKey, model);
245
- return model;
246
- }
218
+ if (provider === "moonshot" && MOONSHOT_MODEL_ALIASES[modelId]) {
219
+ modelId = MOONSHOT_MODEL_ALIASES[modelId];
247
220
  }
248
221
  try {
249
222
  const model = getModel(meta.piAiProvider, modelId);
@@ -252,7 +225,7 @@ function getProviderModel(provider, modelId) {
252
225
  }
253
226
  modelCache.set(cacheKey, model);
254
227
  return model;
255
- } catch (e) {
228
+ } catch {
256
229
  log.warn(`Model ${modelId} not found for ${provider}, falling back to ${meta.defaultModel}`);
257
230
  const fallbackKey = `${provider}:${meta.defaultModel}`;
258
231
  const fallbackCached = modelCache.get(fallbackKey);
@@ -289,7 +262,7 @@ async function chatWithContext(config, options) {
289
262
  systemPrompt = "/no_think\n" + systemPrompt;
290
263
  if (tools && tools.length > 0) {
291
264
  cocoonAllowedTools = new Set(tools.map((t) => t.name));
292
- const { injectToolsIntoSystemPrompt } = await import("./tool-adapter-Y3TCEQOC.js");
265
+ const { injectToolsIntoSystemPrompt } = await import("./tool-adapter-IH5VGBOO.js");
293
266
  systemPrompt = injectToolsIntoSystemPrompt(systemPrompt, tools);
294
267
  tools = void 0;
295
268
  }
@@ -299,7 +272,7 @@ async function chatWithContext(config, options) {
299
272
  systemPrompt,
300
273
  tools
301
274
  };
302
- const temperature = provider === "moonshot" ? 1 : options.temperature ?? config.temperature;
275
+ const temperature = options.temperature ?? config.temperature;
303
276
  const completeOptions = {
304
277
  apiKey: getEffectiveApiKey(provider, config.api_key),
305
278
  maxTokens: options.maxTokens ?? config.max_tokens,
@@ -308,7 +281,7 @@ async function chatWithContext(config, options) {
308
281
  cacheRetention: "long"
309
282
  };
310
283
  if (isCocoon) {
311
- const { stripCocoonPayload } = await import("./tool-adapter-Y3TCEQOC.js");
284
+ const { stripCocoonPayload } = await import("./tool-adapter-IH5VGBOO.js");
312
285
  completeOptions.onPayload = stripCocoonPayload;
313
286
  }
314
287
  let response = await complete(model, context, completeOptions);
@@ -323,7 +296,7 @@ async function chatWithContext(config, options) {
323
296
  if (isCocoon) {
324
297
  const textBlock = response.content.find((b) => b.type === "text");
325
298
  if (textBlock?.type === "text" && textBlock.text.includes("<tool_call>")) {
326
- const { parseToolCallsFromText, extractPlainText } = await import("./tool-adapter-Y3TCEQOC.js");
299
+ const { parseToolCallsFromText, extractPlainText } = await import("./tool-adapter-IH5VGBOO.js");
327
300
  const syntheticCalls = parseToolCallsFromText(textBlock.text, cocoonAllowedTools);
328
301
  if (syntheticCalls.length > 0) {
329
302
  const plainText = extractPlainText(textBlock.text);
@@ -358,9 +331,17 @@ async function chatWithContext(config, options) {
358
331
  }
359
332
  function loadContextFromTranscript(sessionId, systemPrompt) {
360
333
  const messages = readTranscript(sessionId);
334
+ const seenToolCallIds = /* @__PURE__ */ new Set();
335
+ const deduped = messages.filter((msg) => {
336
+ if (msg.role !== "toolResult") return true;
337
+ const id = msg.toolCallId;
338
+ if (seenToolCallIds.has(id)) return false;
339
+ seenToolCallIds.add(id);
340
+ return true;
341
+ });
361
342
  return {
362
343
  systemPrompt,
363
- messages
344
+ messages: deduped
364
345
  };
365
346
  }
366
347
  function createClient(_config) {