teleton 0.8.2 → 0.8.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.
Files changed (30) hide show
  1. package/dist/bootstrap-DDFVEMYI.js +128 -0
  2. package/dist/{chunk-XBSCYMKM.js → chunk-2ERTYRHA.js} +6 -6
  3. package/dist/{chunk-2IZU3REP.js → chunk-33Z47EXI.js} +139 -214
  4. package/dist/{chunk-HEDJCLA6.js → chunk-35MX4ZUI.js} +2 -122
  5. package/dist/{chunk-YOSUPUAJ.js → chunk-6OOHHJ4N.js} +1 -174
  6. package/dist/{chunk-GGXJLMOH.js → chunk-7MWKT67G.js} +295 -416
  7. package/dist/chunk-AEHTQI3H.js +142 -0
  8. package/dist/{chunk-7YKSXOQQ.js → chunk-AERHOXGC.js} +78 -320
  9. package/dist/{chunk-W25Z7CM6.js → chunk-ALKAAG4O.js} +3 -3
  10. package/dist/chunk-CUE4UZXR.js +129 -0
  11. package/dist/chunk-FUNF6H4W.js +251 -0
  12. package/dist/{chunk-VYKW7FMV.js → chunk-GHMXWAXI.js} +1 -1
  13. package/dist/{chunk-J73TA3UM.js → chunk-LVTKJQ7O.js} +7 -5
  14. package/dist/chunk-NVKBBTI6.js +128 -0
  15. package/dist/{chunk-57URFK6M.js → chunk-OIMAE24Q.js} +51 -13
  16. package/dist/chunk-WTDAICGT.js +175 -0
  17. package/dist/{chunk-55SKE6YH.js → chunk-XDZDOKIF.js} +1 -1
  18. package/dist/cli/index.js +42 -22
  19. package/dist/{client-YOOHI776.js → client-5KD25NOP.js} +4 -3
  20. package/dist/index.js +15 -10
  21. package/dist/local-IHKJFQJS.js +9 -0
  22. package/dist/{memory-Q6EWGK2S.js → memory-QMJRM3XJ.js} +5 -3
  23. package/dist/{memory-hook-WUXJNVT5.js → memory-hook-VUNWZ3NY.js} +5 -4
  24. package/dist/{migrate-WFU6COBN.js → migrate-5VBAP52B.js} +3 -2
  25. package/dist/{server-GYZXKIKU.js → server-JF6FX772.js} +39 -13
  26. package/dist/{server-YODFBZKG.js → server-N4T7E25M.js} +14 -10
  27. package/dist/{setup-server-IZBUOJRU.js → setup-server-IX3BFPPH.js} +5 -3
  28. package/dist/{store-7M4XV6M5.js → store-BY7S6IFN.js} +4 -3
  29. package/dist/{tool-index-NYH57UWP.js → tool-index-FTERJSZK.js} +2 -1
  30. package/package.json +1 -1
@@ -1,3 +1,6 @@
1
+ import {
2
+ AgentLifecycle
3
+ } from "./chunk-NVKBBTI6.js";
1
4
  import {
2
5
  telegramGetMyGiftsExecutor,
3
6
  telegramGetMyGiftsTool
@@ -22,11 +25,9 @@ import {
22
25
  fromUnits,
23
26
  getBlocklistConfig,
24
27
  getDecimals,
25
- getDefaultConfigPath,
26
28
  getTriggersConfig,
27
29
  hasStyledButtons,
28
30
  listPluginSecretKeys,
29
- loadConfig,
30
31
  loadEnhancedPlugins,
31
32
  loadSoul,
32
33
  module_default,
@@ -50,7 +51,7 @@ import {
50
51
  withTxLock,
51
52
  writePluginSecret,
52
53
  writeRawConfig
53
- } from "./chunk-GGXJLMOH.js";
54
+ } from "./chunk-7MWKT67G.js";
54
55
  import {
55
56
  getCachedTonClient,
56
57
  getKeyPair,
@@ -58,20 +59,16 @@ import {
58
59
  getWalletAddress,
59
60
  getWalletBalance,
60
61
  invalidateTonClientCache,
61
- loadTemplate,
62
62
  loadWallet,
63
63
  setToncenterApiKey
64
- } from "./chunk-7YKSXOQQ.js";
65
- import {
66
- getErrorMessage
67
- } from "./chunk-3UFPFWYP.js";
64
+ } from "./chunk-FUNF6H4W.js";
68
65
  import {
69
- getEffectiveApiKey,
70
- getProviderModel
71
- } from "./chunk-J73TA3UM.js";
66
+ getDefaultConfigPath,
67
+ loadConfig
68
+ } from "./chunk-AEHTQI3H.js";
72
69
  import {
73
- getProviderMetadata
74
- } from "./chunk-YOSUPUAJ.js";
70
+ loadTemplate
71
+ } from "./chunk-AERHOXGC.js";
75
72
  import {
76
73
  ChatStore,
77
74
  JOURNAL_SCHEMA,
@@ -84,7 +81,10 @@ import {
84
81
  initializeMemory,
85
82
  migrateFromMainDb,
86
83
  openModuleDb
87
- } from "./chunk-VYKW7FMV.js";
84
+ } from "./chunk-GHMXWAXI.js";
85
+ import {
86
+ getErrorMessage
87
+ } from "./chunk-3UFPFWYP.js";
88
88
  import {
89
89
  ELEVENLABS_TTS_URL,
90
90
  GECKOTERMINAL_API_URL,
@@ -111,6 +111,13 @@ import {
111
111
  WEB_FETCH_MAX_TEXT_LENGTH,
112
112
  WEB_SEARCH_MAX_RESULTS
113
113
  } from "./chunk-C4NKJT2Z.js";
114
+ import {
115
+ getEffectiveApiKey,
116
+ getProviderModel
117
+ } from "./chunk-LVTKJQ7O.js";
118
+ import {
119
+ getProviderMetadata
120
+ } from "./chunk-6OOHHJ4N.js";
114
121
  import {
115
122
  fetchWithTimeout
116
123
  } from "./chunk-XQUHC3JZ.js";
@@ -18037,127 +18044,6 @@ var UserHookEvaluator = class {
18037
18044
  }
18038
18045
  };
18039
18046
 
18040
- // src/agent/lifecycle.ts
18041
- import { EventEmitter } from "events";
18042
- var log136 = createLogger("Lifecycle");
18043
- var AgentLifecycle = class extends EventEmitter {
18044
- state = "stopped";
18045
- error;
18046
- startPromise = null;
18047
- stopPromise = null;
18048
- runningSince = null;
18049
- registeredStartFn = null;
18050
- registeredStopFn = null;
18051
- getState() {
18052
- return this.state;
18053
- }
18054
- getError() {
18055
- return this.error;
18056
- }
18057
- getUptime() {
18058
- if (this.state !== "running" || this.runningSince === null) {
18059
- return null;
18060
- }
18061
- return Math.floor((Date.now() - this.runningSince) / 1e3);
18062
- }
18063
- /**
18064
- * Register the start/stop callbacks so start()/stop() can be called without args.
18065
- */
18066
- registerCallbacks(startFn, stopFn) {
18067
- this.registeredStartFn = startFn;
18068
- this.registeredStopFn = stopFn;
18069
- }
18070
- /**
18071
- * Start the agent. Uses the provided callback or falls back to registered one.
18072
- * - No-op if already running
18073
- * - Returns existing promise if already starting
18074
- * - Throws if currently stopping
18075
- */
18076
- async start(startFn) {
18077
- const fn = startFn ?? this.registeredStartFn;
18078
- if (!fn) {
18079
- throw new Error("No start function provided or registered");
18080
- }
18081
- if (this.state === "running") {
18082
- return;
18083
- }
18084
- if (this.state === "starting") {
18085
- return this.startPromise ?? Promise.resolve();
18086
- }
18087
- if (this.state === "stopping") {
18088
- throw new Error("Cannot start while agent is stopping");
18089
- }
18090
- this.transition("starting");
18091
- this.startPromise = (async () => {
18092
- try {
18093
- await fn();
18094
- this.error = void 0;
18095
- this.runningSince = Date.now();
18096
- this.transition("running");
18097
- } catch (err) {
18098
- const message = err instanceof Error ? err.message : String(err);
18099
- this.error = message;
18100
- this.runningSince = null;
18101
- this.transition("stopped", message);
18102
- throw err;
18103
- } finally {
18104
- this.startPromise = null;
18105
- }
18106
- })();
18107
- return this.startPromise;
18108
- }
18109
- /**
18110
- * Stop the agent. Uses the provided callback or falls back to registered one.
18111
- * - No-op if already stopped
18112
- * - Returns existing promise if already stopping
18113
- * - If starting, waits for start to complete then stops
18114
- */
18115
- async stop(stopFn) {
18116
- const fn = stopFn ?? this.registeredStopFn;
18117
- if (!fn) {
18118
- throw new Error("No stop function provided or registered");
18119
- }
18120
- if (this.state === "stopped") {
18121
- return;
18122
- }
18123
- if (this.state === "stopping") {
18124
- return this.stopPromise ?? Promise.resolve();
18125
- }
18126
- if (this.state === "starting" && this.startPromise) {
18127
- try {
18128
- await this.startPromise;
18129
- } catch {
18130
- return;
18131
- }
18132
- }
18133
- this.transition("stopping");
18134
- this.stopPromise = (async () => {
18135
- try {
18136
- await fn();
18137
- } catch (err) {
18138
- log136.error({ err }, "Error during agent stop");
18139
- } finally {
18140
- this.runningSince = null;
18141
- this.transition("stopped");
18142
- this.stopPromise = null;
18143
- }
18144
- })();
18145
- return this.stopPromise;
18146
- }
18147
- transition(newState, error) {
18148
- this.state = newState;
18149
- const event = {
18150
- state: newState,
18151
- timestamp: Date.now()
18152
- };
18153
- if (error !== void 0) {
18154
- event.error = error;
18155
- }
18156
- log136.info(`Agent state: ${newState}${error ? ` (${error})` : ""}`);
18157
- this.emit("stateChange", event);
18158
- }
18159
- };
18160
-
18161
18047
  // src/bot/rate-limiter.ts
18162
18048
  var PluginRateLimiter = class {
18163
18049
  windows = /* @__PURE__ */ new Map();
@@ -18199,7 +18085,7 @@ var PluginRateLimiter = class {
18199
18085
  };
18200
18086
 
18201
18087
  // src/index.ts
18202
- var log137 = createLogger("App");
18088
+ var log136 = createLogger("App");
18203
18089
  var TeletonApp = class {
18204
18090
  config;
18205
18091
  agent;
@@ -18293,13 +18179,52 @@ var TeletonApp = class {
18293
18179
  getLifecycle() {
18294
18180
  return this.lifecycle;
18295
18181
  }
18182
+ // --- Public accessors for API-only bootstrap mode ---
18183
+ getAgent() {
18184
+ return this.agent;
18185
+ }
18186
+ getBridge() {
18187
+ return this.bridge;
18188
+ }
18189
+ getMemory() {
18190
+ return this.memory;
18191
+ }
18192
+ getToolRegistry() {
18193
+ return this.toolRegistry;
18194
+ }
18195
+ getPlugins() {
18196
+ return this.modules.filter((m) => this.toolRegistry.isPluginModule(m.name)).map((m) => ({ name: m.name, version: m.version ?? "0.0.0" }));
18197
+ }
18198
+ getWebuiConfig() {
18199
+ return this.config.webui;
18200
+ }
18201
+ getConfigPath() {
18202
+ return this.configPath;
18203
+ }
18204
+ /** Start agent subsystems without WebUI/API servers. For bootstrap mode. */
18205
+ async startAgentSubsystems() {
18206
+ this.lifecycle.registerCallbacks(
18207
+ () => this.startAgent(),
18208
+ () => this.stopAgent()
18209
+ );
18210
+ await this.lifecycle.start();
18211
+ }
18212
+ /** Stop agent subsystems and close database. For bootstrap mode. */
18213
+ async stopAgentSubsystems() {
18214
+ await this.lifecycle.stop();
18215
+ try {
18216
+ closeDatabase();
18217
+ } catch (e) {
18218
+ log136.error({ err: e }, "Database close failed");
18219
+ }
18220
+ }
18296
18221
  /**
18297
18222
  * Start the agent
18298
18223
  */
18299
18224
  async start() {
18300
18225
  const blue = "\x1B[34m";
18301
18226
  const reset = "\x1B[0m";
18302
- log137.info(`
18227
+ log136.info(`
18303
18228
  ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
18304
18229
  \u2502 \u2502
18305
18230
  \u2502 ______________ ________________ _ __ ___ _____________ ________ \u2502
@@ -18316,7 +18241,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18316
18241
  );
18317
18242
  if (this.config.webui.enabled) {
18318
18243
  try {
18319
- const { WebUIServer } = await import("./server-YODFBZKG.js");
18244
+ const { WebUIServer } = await import("./server-N4T7E25M.js");
18320
18245
  const mcpServers = () => Object.entries(this.config.mcp.servers).map(([name, serverConfig]) => {
18321
18246
  const type = serverConfig.command ? "stdio" : serverConfig.url ? "streamable-http" : "sse";
18322
18247
  const target = serverConfig.command ?? serverConfig.url ?? "";
@@ -18363,13 +18288,13 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18363
18288
  });
18364
18289
  await this.webuiServer.start();
18365
18290
  } catch (error) {
18366
- log137.error({ err: error }, "\u274C Failed to start WebUI server");
18367
- log137.warn("\u26A0\uFE0F Continuing without WebUI...");
18291
+ log136.error({ err: error }, "\u274C Failed to start WebUI server");
18292
+ log136.warn("\u26A0\uFE0F Continuing without WebUI...");
18368
18293
  }
18369
18294
  }
18370
18295
  if (this.config.api?.enabled) {
18371
18296
  try {
18372
- const { ApiServer: ApiServerClass } = await import("./server-GYZXKIKU.js");
18297
+ const { ApiServer: ApiServerClass } = await import("./server-JF6FX772.js");
18373
18298
  const mcpServers = () => Object.entries(this.config.mcp.servers).map(([name, serverConfig]) => {
18374
18299
  const type = serverConfig.command ? "stdio" : serverConfig.url ? "streamable-http" : "sse";
18375
18300
  const target = serverConfig.command ?? serverConfig.url ?? "";
@@ -18423,8 +18348,8 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18423
18348
  process.stdout.write(JSON.stringify(creds) + "\n");
18424
18349
  }
18425
18350
  } catch (error) {
18426
- log137.error({ err: error }, "Failed to start Management API server");
18427
- log137.warn("Continuing without Management API...");
18351
+ log136.error({ err: error }, "Failed to start Management API server");
18352
+ log136.warn("Continuing without Management API...");
18428
18353
  }
18429
18354
  }
18430
18355
  await this.lifecycle.start(() => this.startAgent());
@@ -18457,7 +18382,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18457
18382
  }
18458
18383
  this.modules.push(mod);
18459
18384
  } catch (error) {
18460
- log137.error(
18385
+ log136.error(
18461
18386
  `\u274C Plugin "${mod.name}" failed to load: ${error instanceof Error ? error.message : error}`
18462
18387
  );
18463
18388
  }
@@ -18473,7 +18398,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18473
18398
  if (mcp.count > 0) {
18474
18399
  this.toolCount = this.toolRegistry.count;
18475
18400
  mcpServerNames.push(...mcp.names);
18476
- log137.info(
18401
+ log136.info(
18477
18402
  `\u{1F50C} MCP: ${mcp.count} tools from ${mcp.names.length} server(s) (${mcp.names.join(", ")})`
18478
18403
  );
18479
18404
  }
@@ -18481,7 +18406,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18481
18406
  }
18482
18407
  this.toolRegistry.loadConfigFromDB(getDatabase().getDb());
18483
18408
  if (this.config.tool_rag.enabled) {
18484
- const { ToolIndex } = await import("./tool-index-NYH57UWP.js");
18409
+ const { ToolIndex } = await import("./tool-index-FTERJSZK.js");
18485
18410
  const toolIndex2 = new ToolIndex(
18486
18411
  getDatabase().getDb(),
18487
18412
  this.memory.embedder,
@@ -18501,19 +18426,19 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18501
18426
  const provider = this.config.agent.provider || "anthropic";
18502
18427
  const providerMeta = getProviderMetadata(provider);
18503
18428
  const allNames = [...moduleNames, ...pluginNames, ...mcpServerNames];
18504
- log137.info(
18429
+ log136.info(
18505
18430
  `\u{1F50C} ${this.toolCount} tools loaded (${allNames.join(", ")})${pluginToolCount > 0 ? ` \u2014 ${pluginToolCount} from plugins` : ""}`
18506
18431
  );
18507
18432
  if (providerMeta.toolLimit !== null && this.toolCount > providerMeta.toolLimit) {
18508
- log137.warn(
18433
+ log136.warn(
18509
18434
  `\u26A0\uFE0F Tool count (${this.toolCount}) exceeds ${providerMeta.displayName} limit (${providerMeta.toolLimit})`
18510
18435
  );
18511
18436
  }
18512
- const { migrateSessionsToDb } = await import("./migrate-WFU6COBN.js");
18437
+ const { migrateSessionsToDb } = await import("./migrate-5VBAP52B.js");
18513
18438
  migrateSessionsToDb();
18514
18439
  const { cleanupOldTranscripts } = await import("./transcript-IM7G25OS.js");
18515
18440
  cleanupOldTranscripts(30);
18516
- const { pruneOldSessions } = await import("./store-7M4XV6M5.js");
18441
+ const { pruneOldSessions } = await import("./store-BY7S6IFN.js");
18517
18442
  pruneOldSessions(30);
18518
18443
  if (this.memory.embedder.warmup) {
18519
18444
  await this.memory.embedder.warmup();
@@ -18525,7 +18450,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18525
18450
  if (indexResult.indexed > 0) {
18526
18451
  ftsResult = db2.rebuildFtsIndexes();
18527
18452
  }
18528
- import("./memory-hook-WUXJNVT5.js").then(
18453
+ import("./memory-hook-VUNWZ3NY.js").then(
18529
18454
  ({ consolidateOldMemoryFiles }) => consolidateOldMemoryFiles({
18530
18455
  apiKey: this.config.agent.api_key,
18531
18456
  provider: this.config.agent.provider,
@@ -18533,29 +18458,29 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18533
18458
  })
18534
18459
  ).then((r) => {
18535
18460
  if (r.consolidated > 0)
18536
- log137.info(`\u{1F9F9} Consolidated ${r.consolidated} old session memory files`);
18537
- }).catch((error) => log137.warn({ err: error }, "Memory consolidation skipped"));
18461
+ log136.info(`\u{1F9F9} Consolidated ${r.consolidated} old session memory files`);
18462
+ }).catch((error) => log136.warn({ err: error }, "Memory consolidation skipped"));
18538
18463
  const toolIndex = this.toolRegistry.getToolIndex();
18539
18464
  if (toolIndex) {
18540
18465
  const t0 = Date.now();
18541
18466
  const indexedCount = await toolIndex.indexAll(this.toolRegistry.getAll());
18542
- log137.info(`\u{1F50D} Tool RAG: ${indexedCount} tools indexed (${Date.now() - t0}ms)`);
18467
+ log136.info(`\u{1F50D} Tool RAG: ${indexedCount} tools indexed (${Date.now() - t0}ms)`);
18543
18468
  }
18544
18469
  this.agent.initializeContextBuilder(this.memory.embedder, db2.isVectorSearchReady());
18545
18470
  if (this.config.agent.provider === "cocoon") {
18546
18471
  try {
18547
- const { registerCocoonModels } = await import("./client-YOOHI776.js");
18472
+ const { registerCocoonModels } = await import("./client-5KD25NOP.js");
18548
18473
  const port = this.config.cocoon?.port ?? 1e4;
18549
18474
  const models = await registerCocoonModels(port);
18550
18475
  if (models.length === 0) {
18551
18476
  throw new Error(`No models found on port ${port}`);
18552
18477
  }
18553
- log137.info(`Cocoon Network ready \u2014 ${models.length} model(s) on port ${port}`);
18478
+ log136.info(`Cocoon Network ready \u2014 ${models.length} model(s) on port ${port}`);
18554
18479
  } catch (err) {
18555
- log137.error(
18480
+ log136.error(
18556
18481
  `Cocoon Network unavailable on port ${this.config.cocoon?.port ?? 1e4}: ${getErrorMessage(err)}`
18557
18482
  );
18558
- log137.error("Start the Cocoon client first: cocoon start");
18483
+ log136.error("Start the Cocoon client first: cocoon start");
18559
18484
  throw new Error(`Cocoon Network unavailable: ${getErrorMessage(err)}`);
18560
18485
  }
18561
18486
  }
@@ -18566,22 +18491,22 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18566
18491
  }
18567
18492
  if (this.config.agent.provider === "local" && this.config.agent.base_url) {
18568
18493
  try {
18569
- const { registerLocalModels } = await import("./client-YOOHI776.js");
18494
+ const { registerLocalModels } = await import("./client-5KD25NOP.js");
18570
18495
  const models = await registerLocalModels(this.config.agent.base_url);
18571
18496
  if (models.length > 0) {
18572
- log137.info(`Discovered ${models.length} local model(s): ${models.join(", ")}`);
18497
+ log136.info(`Discovered ${models.length} local model(s): ${models.join(", ")}`);
18573
18498
  if (!this.config.agent.model || this.config.agent.model === "auto") {
18574
18499
  this.config.agent.model = models[0];
18575
- log137.info(`Using local model: ${models[0]}`);
18500
+ log136.info(`Using local model: ${models[0]}`);
18576
18501
  }
18577
18502
  } else {
18578
- log137.warn("No models found on local LLM server \u2014 is it running?");
18503
+ log136.warn("No models found on local LLM server \u2014 is it running?");
18579
18504
  }
18580
18505
  } catch (err) {
18581
- log137.error(
18506
+ log136.error(
18582
18507
  `Local LLM server unavailable at ${this.config.agent.base_url}: ${getErrorMessage(err)}`
18583
18508
  );
18584
- log137.error("Start the LLM server first (e.g. ollama serve)");
18509
+ log136.error("Start the LLM server first (e.g. ollama serve)");
18585
18510
  throw new Error(`Local LLM server unavailable: ${getErrorMessage(err)}`);
18586
18511
  }
18587
18512
  }
@@ -18612,12 +18537,12 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18612
18537
  startedModules.push(mod);
18613
18538
  }
18614
18539
  } catch (error) {
18615
- log137.error({ err: error }, "\u274C Module start failed, cleaning up started modules");
18540
+ log136.error({ err: error }, "\u274C Module start failed, cleaning up started modules");
18616
18541
  for (const mod of startedModules.reverse()) {
18617
18542
  try {
18618
18543
  await mod.stop?.();
18619
18544
  } catch (e) {
18620
- log137.error({ err: e }, `\u26A0\uFE0F Module "${mod.name}" cleanup failed`);
18545
+ log136.error({ err: e }, `\u26A0\uFE0F Module "${mod.name}" cleanup failed`);
18621
18546
  }
18622
18547
  }
18623
18548
  throw error;
@@ -18629,10 +18554,10 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18629
18554
  this.sdkDeps.grammyBot = activeDealBot.getBot();
18630
18555
  this.sdkDeps.rateLimiter = rateLimiter;
18631
18556
  inlineRouter.setGramJSBot(activeDealBot.getGramJSBot());
18632
- log137.info("\u{1F50C} Bot SDK: inline router installed");
18557
+ log136.info("\u{1F50C} Bot SDK: inline router installed");
18633
18558
  }
18634
18559
  if (hookRegistry.hasAnyHooks()) {
18635
- const hookRunner = createHookRunner(hookRegistry, { logger: log137 });
18560
+ const hookRunner = createHookRunner(hookRegistry, { logger: log136 });
18636
18561
  this.agent.setHookRunner(hookRunner);
18637
18562
  this.hookRunner = hookRunner;
18638
18563
  const activeHooks = [
@@ -18651,7 +18576,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18651
18576
  "agent:stop"
18652
18577
  ];
18653
18578
  const active = activeHooks.filter((n) => hookRegistry.hasHooks(n));
18654
- log137.info(`\u{1FA9D} Hook runner created (${active.join(", ")})`);
18579
+ log136.info(`\u{1FA9D} Hook runner created (${active.join(", ")})`);
18655
18580
  }
18656
18581
  this.wirePluginEventHooks();
18657
18582
  if (this.config.dev.hot_reload) {
@@ -18665,22 +18590,22 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18665
18590
  });
18666
18591
  this.pluginWatcher.start();
18667
18592
  }
18668
- log137.info(`\u2705 SOUL.md loaded`);
18669
- log137.info(`\u2705 Knowledge: ${indexResult.indexed} files, ${ftsResult.knowledge} chunks indexed`);
18670
- log137.info(`\u2705 Telegram: @${username} connected`);
18671
- log137.info(`\u2705 TON Blockchain: connected`);
18593
+ log136.info(`\u2705 SOUL.md loaded`);
18594
+ log136.info(`\u2705 Knowledge: ${indexResult.indexed} files, ${ftsResult.knowledge} chunks indexed`);
18595
+ log136.info(`\u2705 Telegram: @${username} connected`);
18596
+ log136.info(`\u2705 TON Blockchain: connected`);
18672
18597
  if (this.config.tonapi_key) {
18673
- log137.info(`\u{1F511} TonAPI key configured`);
18598
+ log136.info(`\u{1F511} TonAPI key configured`);
18674
18599
  }
18675
- log137.info(`\u2705 DEXs: STON.fi, DeDust connected`);
18676
- log137.info(`\u2705 Wallet: ${walletAddress || "not configured"}`);
18677
- log137.info(`\u2705 Model: ${provider}/${this.config.agent.model}`);
18678
- log137.info(`\u2705 Admins: ${this.config.telegram.admin_ids.join(", ")}`);
18679
- log137.info(
18600
+ log136.info(`\u2705 DEXs: STON.fi, DeDust connected`);
18601
+ log136.info(`\u2705 Wallet: ${walletAddress || "not configured"}`);
18602
+ log136.info(`\u2705 Model: ${provider}/${this.config.agent.model}`);
18603
+ log136.info(`\u2705 Admins: ${this.config.telegram.admin_ids.join(", ")}`);
18604
+ log136.info(
18680
18605
  `\u2705 Policy: DM ${this.config.telegram.dm_policy}, Groups ${this.config.telegram.group_policy}, Debounce ${this.config.telegram.debounce_ms}ms
18681
18606
  `
18682
18607
  );
18683
- log137.info("Teleton Agent is running! Press Ctrl+C to stop.");
18608
+ log136.info("Teleton Agent is running! Press Ctrl+C to stop.");
18684
18609
  this.startTime = Date.now();
18685
18610
  this.messagesProcessed = 0;
18686
18611
  if (this.hookRunner) {
@@ -18721,7 +18646,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18721
18646
  }
18722
18647
  },
18723
18648
  (error, messages) => {
18724
- log137.error({ err: error }, `Error processing batch of ${messages.length} messages`);
18649
+ log136.error({ err: error }, `Error processing batch of ${messages.length} messages`);
18725
18650
  }
18726
18651
  );
18727
18652
  if (!this.messageHandlersRegistered) {
@@ -18729,14 +18654,14 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18729
18654
  try {
18730
18655
  await this.debouncer.enqueue(message);
18731
18656
  } catch (error) {
18732
- log137.error({ err: error }, "Error enqueueing message");
18657
+ log136.error({ err: error }, "Error enqueueing message");
18733
18658
  }
18734
18659
  });
18735
18660
  this.bridge.onServiceMessage(async (message) => {
18736
18661
  try {
18737
18662
  await this.debouncer.enqueue(message);
18738
18663
  } catch (error) {
18739
- log137.error({ err: error }, "Error enqueueing service message");
18664
+ log136.error({ err: error }, "Error enqueueing service message");
18740
18665
  }
18741
18666
  });
18742
18667
  this.messageHandlersRegistered = true;
@@ -18783,10 +18708,10 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18783
18708
  writeRawConfig(raw, this.configPath);
18784
18709
  const displayName = this.config.telegram.owner_name || "Unknown";
18785
18710
  const displayUsername = this.config.telegram.owner_username ? ` (@${this.config.telegram.owner_username})` : "";
18786
- log137.info(`\u{1F464} Owner resolved: ${displayName}${displayUsername}`);
18711
+ log136.info(`\u{1F464} Owner resolved: ${displayName}${displayUsername}`);
18787
18712
  }
18788
18713
  } catch (error) {
18789
- log137.warn(
18714
+ log136.warn(
18790
18715
  `\u26A0\uFE0F Could not resolve owner info: ${error instanceof Error ? error.message : error}`
18791
18716
  );
18792
18717
  }
@@ -18855,7 +18780,7 @@ Task: "${taskDescription}"`;
18855
18780
  if (this.adminHandler.isPaused()) return;
18856
18781
  await this.messageHandler.handleMessage(message);
18857
18782
  } catch (error) {
18858
- log137.error({ err: error }, "Error handling message");
18783
+ log136.error({ err: error }, "Error handling message");
18859
18784
  }
18860
18785
  }
18861
18786
  /**
@@ -18865,19 +18790,19 @@ Task: "${taskDescription}"`;
18865
18790
  const { getTaskStore } = await import("./tasks-WQIKXDX5.js");
18866
18791
  const { executeScheduledTask } = await import("./task-executor-XBNJLUCS.js");
18867
18792
  const { TaskDependencyResolver } = await import("./task-dependency-resolver-L6UUMTHK.js");
18868
- const { getDatabase: getDatabase2 } = await import("./memory-Q6EWGK2S.js");
18793
+ const { getDatabase: getDatabase2 } = await import("./memory-QMJRM3XJ.js");
18869
18794
  const db2 = getDatabase2().getDb();
18870
18795
  const taskStore = getTaskStore(db2);
18871
18796
  const match = message.text.match(/^\[TASK:([^\]]+)\]/);
18872
18797
  if (!match) {
18873
- log137.warn(`Invalid task format: ${message.text}`);
18798
+ log136.warn(`Invalid task format: ${message.text}`);
18874
18799
  return;
18875
18800
  }
18876
18801
  const taskId = match[1];
18877
18802
  try {
18878
18803
  const task = taskStore.getTask(taskId);
18879
18804
  if (!task) {
18880
- log137.warn(`Task ${taskId} not found in database`);
18805
+ log136.warn(`Task ${taskId} not found in database`);
18881
18806
  await this.bridge.sendMessage({
18882
18807
  chatId: message.chatId,
18883
18808
  text: `\u26A0\uFE0F Task ${taskId} not found. It may have been deleted.`,
@@ -18886,11 +18811,11 @@ Task: "${taskDescription}"`;
18886
18811
  return;
18887
18812
  }
18888
18813
  if (task.status === "cancelled" || task.status === "done" || task.status === "failed") {
18889
- log137.info(`\u23ED\uFE0F Task ${taskId} already ${task.status}, skipping`);
18814
+ log136.info(`\u23ED\uFE0F Task ${taskId} already ${task.status}, skipping`);
18890
18815
  return;
18891
18816
  }
18892
18817
  if (!taskStore.canExecute(taskId)) {
18893
- log137.warn(`Task ${taskId} cannot execute yet - dependencies not satisfied`);
18818
+ log136.warn(`Task ${taskId} cannot execute yet - dependencies not satisfied`);
18894
18819
  await this.bridge.sendMessage({
18895
18820
  chatId: message.chatId,
18896
18821
  text: `\u23F3 Task "${task.description}" is waiting for parent tasks to complete.`,
@@ -18933,13 +18858,13 @@ Task: "${taskDescription}"`;
18933
18858
  });
18934
18859
  }
18935
18860
  taskStore.completeTask(taskId, response.content);
18936
- log137.info(`\u2705 Executed scheduled task ${taskId}: ${task.description}`);
18861
+ log136.info(`\u2705 Executed scheduled task ${taskId}: ${task.description}`);
18937
18862
  if (!this.dependencyResolver) {
18938
18863
  this.dependencyResolver = new TaskDependencyResolver(taskStore, this.bridge);
18939
18864
  }
18940
18865
  await this.dependencyResolver.onTaskComplete(taskId);
18941
18866
  } catch (error) {
18942
- log137.error({ err: error }, "Error handling scheduled task");
18867
+ log136.error({ err: error }, "Error handling scheduled task");
18943
18868
  try {
18944
18869
  taskStore.failTask(taskId, getErrorMessage(error));
18945
18870
  if (!this.dependencyResolver) {
@@ -18964,7 +18889,7 @@ Task: "${taskDescription}"`;
18964
18889
  try {
18965
18890
  await withHooks.onMessage(event);
18966
18891
  } catch (err) {
18967
- log137.error(
18892
+ log136.error(
18968
18893
  `\u274C [${mod.name}] onMessage error: ${err instanceof Error ? err.message : err}`
18969
18894
  );
18970
18895
  }
@@ -18974,7 +18899,7 @@ Task: "${taskDescription}"`;
18974
18899
  ]);
18975
18900
  const hookCount = this.modules.filter((m) => m.onMessage).length;
18976
18901
  if (hookCount > 0) {
18977
- log137.info(`\u{1F517} ${hookCount} plugin onMessage hook(s) registered`);
18902
+ log136.info(`\u{1F517} ${hookCount} plugin onMessage hook(s) registered`);
18978
18903
  }
18979
18904
  if (!this.callbackHandlerRegistered) {
18980
18905
  this.bridge.getClient().addCallbackQueryHandler(async (update) => {
@@ -18994,7 +18919,7 @@ Task: "${taskDescription}"`;
18994
18919
  try {
18995
18920
  await this.bridge.getClient().answerCallbackQuery(queryId, { message: text, alert });
18996
18921
  } catch (err) {
18997
- log137.error(
18922
+ log136.error(
18998
18923
  `\u274C Failed to answer callback query: ${err instanceof Error ? err.message : err}`
18999
18924
  );
19000
18925
  }
@@ -19014,7 +18939,7 @@ Task: "${taskDescription}"`;
19014
18939
  try {
19015
18940
  await withHooks.onCallbackQuery(event);
19016
18941
  } catch (err) {
19017
- log137.error(
18942
+ log136.error(
19018
18943
  `\u274C [${mod.name}] onCallbackQuery error: ${err instanceof Error ? err.message : err}`
19019
18944
  );
19020
18945
  }
@@ -19026,7 +18951,7 @@ Task: "${taskDescription}"`;
19026
18951
  (m) => m.onCallbackQuery
19027
18952
  ).length;
19028
18953
  if (cbCount > 0) {
19029
- log137.info(`\u{1F517} ${cbCount} plugin onCallbackQuery hook(s) registered`);
18954
+ log136.info(`\u{1F517} ${cbCount} plugin onCallbackQuery hook(s) registered`);
19030
18955
  }
19031
18956
  }
19032
18957
  }
@@ -19034,26 +18959,26 @@ Task: "${taskDescription}"`;
19034
18959
  * Stop the agent
19035
18960
  */
19036
18961
  async stop() {
19037
- log137.info("\u{1F44B} Stopping Teleton AI...");
18962
+ log136.info("\u{1F44B} Stopping Teleton AI...");
19038
18963
  await this.lifecycle.stop(() => this.stopAgent());
19039
18964
  if (this.webuiServer) {
19040
18965
  try {
19041
18966
  await this.webuiServer.stop();
19042
18967
  } catch (e) {
19043
- log137.error({ err: e }, "\u26A0\uFE0F WebUI stop failed");
18968
+ log136.error({ err: e }, "\u26A0\uFE0F WebUI stop failed");
19044
18969
  }
19045
18970
  }
19046
18971
  if (this.apiServer) {
19047
18972
  try {
19048
18973
  await this.apiServer.stop();
19049
18974
  } catch (e) {
19050
- log137.error({ err: e }, "\u26A0\uFE0F Management API stop failed");
18975
+ log136.error({ err: e }, "\u26A0\uFE0F Management API stop failed");
19051
18976
  }
19052
18977
  }
19053
18978
  try {
19054
18979
  closeDatabase();
19055
18980
  } catch (e) {
19056
- log137.error({ err: e }, "\u26A0\uFE0F Database close failed");
18981
+ log136.error({ err: e }, "\u26A0\uFE0F Database close failed");
19057
18982
  }
19058
18983
  }
19059
18984
  /**
@@ -19071,46 +18996,46 @@ Task: "${taskDescription}"`;
19071
18996
  };
19072
18997
  await this.hookRunner.runObservingHook("agent:stop", agentStopEvent);
19073
18998
  } catch (e) {
19074
- log137.error({ err: e }, "\u26A0\uFE0F agent:stop hook failed");
18999
+ log136.error({ err: e }, "\u26A0\uFE0F agent:stop hook failed");
19075
19000
  }
19076
19001
  }
19077
19002
  if (this.pluginWatcher) {
19078
19003
  try {
19079
19004
  await this.pluginWatcher.stop();
19080
19005
  } catch (e) {
19081
- log137.error({ err: e }, "\u26A0\uFE0F Plugin watcher stop failed");
19006
+ log136.error({ err: e }, "\u26A0\uFE0F Plugin watcher stop failed");
19082
19007
  }
19083
19008
  }
19084
19009
  if (this.mcpConnections.length > 0) {
19085
19010
  try {
19086
19011
  await closeMcpServers(this.mcpConnections);
19087
19012
  } catch (e) {
19088
- log137.error({ err: e }, "\u26A0\uFE0F MCP close failed");
19013
+ log136.error({ err: e }, "\u26A0\uFE0F MCP close failed");
19089
19014
  }
19090
19015
  }
19091
19016
  if (this.debouncer) {
19092
19017
  try {
19093
19018
  await this.debouncer.flushAll();
19094
19019
  } catch (e) {
19095
- log137.error({ err: e }, "\u26A0\uFE0F Debouncer flush failed");
19020
+ log136.error({ err: e }, "\u26A0\uFE0F Debouncer flush failed");
19096
19021
  }
19097
19022
  }
19098
19023
  try {
19099
19024
  await this.messageHandler.drain();
19100
19025
  } catch (e) {
19101
- log137.error({ err: e }, "\u26A0\uFE0F Message queue drain failed");
19026
+ log136.error({ err: e }, "\u26A0\uFE0F Message queue drain failed");
19102
19027
  }
19103
19028
  for (const mod of this.modules) {
19104
19029
  try {
19105
19030
  await mod.stop?.();
19106
19031
  } catch (e) {
19107
- log137.error({ err: e }, `\u26A0\uFE0F Module "${mod.name}" stop failed`);
19032
+ log136.error({ err: e }, `\u26A0\uFE0F Module "${mod.name}" stop failed`);
19108
19033
  }
19109
19034
  }
19110
19035
  try {
19111
19036
  await this.bridge.disconnect();
19112
19037
  } catch (e) {
19113
- log137.error({ err: e }, "\u26A0\uFE0F Bridge disconnect failed");
19038
+ log136.error({ err: e }, "\u26A0\uFE0F Bridge disconnect failed");
19114
19039
  }
19115
19040
  }
19116
19041
  };
@@ -19119,14 +19044,14 @@ async function main(configPath) {
19119
19044
  try {
19120
19045
  app = new TeletonApp(configPath);
19121
19046
  } catch (error) {
19122
- log137.error(`Failed to initialize: ${error instanceof Error ? error.message : error}`);
19047
+ log136.error(`Failed to initialize: ${error instanceof Error ? error.message : error}`);
19123
19048
  process.exit(1);
19124
19049
  }
19125
19050
  process.on("unhandledRejection", (reason) => {
19126
- log137.error({ err: reason }, "\u26A0\uFE0F Unhandled promise rejection");
19051
+ log136.error({ err: reason }, "\u26A0\uFE0F Unhandled promise rejection");
19127
19052
  });
19128
19053
  process.on("uncaughtException", (error) => {
19129
- log137.error({ err: error }, "\u{1F4A5} Uncaught exception");
19054
+ log136.error({ err: error }, "\u{1F4A5} Uncaught exception");
19130
19055
  process.exit(1);
19131
19056
  });
19132
19057
  let shutdownInProgress = false;
@@ -19134,7 +19059,7 @@ async function main(configPath) {
19134
19059
  if (shutdownInProgress) return;
19135
19060
  shutdownInProgress = true;
19136
19061
  const forceExit = setTimeout(() => {
19137
- log137.error("\u26A0\uFE0F Shutdown timed out, forcing exit");
19062
+ log136.error("\u26A0\uFE0F Shutdown timed out, forcing exit");
19138
19063
  process.exit(1);
19139
19064
  }, SHUTDOWN_TIMEOUT_MS);
19140
19065
  forceExit.unref();
@@ -19148,7 +19073,7 @@ async function main(configPath) {
19148
19073
  }
19149
19074
  if (import.meta.url === `file://${process.argv[1]}`) {
19150
19075
  main().catch((error) => {
19151
- log137.fatal({ err: error }, "Fatal error");
19076
+ log136.fatal({ err: error }, "Fatal error");
19152
19077
  process.exit(1);
19153
19078
  });
19154
19079
  }