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,7 +1,7 @@
1
1
  import {
2
2
  telegramGetMyGiftsExecutor,
3
3
  telegramGetMyGiftsTool
4
- } from "./chunk-QBHRXLZS.js";
4
+ } from "./chunk-H7MFXJZK.js";
5
5
  import {
6
6
  AgentRuntime,
7
7
  DEDUST_API_URL,
@@ -50,7 +50,7 @@ import {
50
50
  withTxLock,
51
51
  writePluginSecret,
52
52
  writeRawConfig
53
- } from "./chunk-CGOXE4WP.js";
53
+ } from "./chunk-GGXJLMOH.js";
54
54
  import {
55
55
  getCachedTonClient,
56
56
  getKeyPair,
@@ -61,17 +61,17 @@ import {
61
61
  loadTemplate,
62
62
  loadWallet,
63
63
  setToncenterApiKey
64
- } from "./chunk-S6PHGKOC.js";
64
+ } from "./chunk-7YKSXOQQ.js";
65
65
  import {
66
66
  getErrorMessage
67
- } from "./chunk-XBE4JB7C.js";
67
+ } from "./chunk-3UFPFWYP.js";
68
68
  import {
69
69
  getEffectiveApiKey,
70
70
  getProviderModel
71
- } from "./chunk-AYWEJCDB.js";
71
+ } from "./chunk-J73TA3UM.js";
72
72
  import {
73
73
  getProviderMetadata
74
- } from "./chunk-PHSAHTK4.js";
74
+ } from "./chunk-YOSUPUAJ.js";
75
75
  import {
76
76
  ChatStore,
77
77
  JOURNAL_SCHEMA,
@@ -84,7 +84,7 @@ import {
84
84
  initializeMemory,
85
85
  migrateFromMainDb,
86
86
  openModuleDb
87
- } from "./chunk-7U7BOHCL.js";
87
+ } from "./chunk-VYKW7FMV.js";
88
88
  import {
89
89
  ELEVENLABS_TTS_URL,
90
90
  GECKOTERMINAL_API_URL,
@@ -110,7 +110,7 @@ import {
110
110
  TELEGRAM_MAX_MESSAGE_LENGTH,
111
111
  WEB_FETCH_MAX_TEXT_LENGTH,
112
112
  WEB_SEARCH_MAX_RESULTS
113
- } from "./chunk-UP55PXFH.js";
113
+ } from "./chunk-C4NKJT2Z.js";
114
114
  import {
115
115
  fetchWithTimeout
116
116
  } from "./chunk-XQUHC3JZ.js";
@@ -133,7 +133,7 @@ import {
133
133
  initLoggerFromConfig,
134
134
  isVerbose,
135
135
  setVerbose
136
- } from "./chunk-RCMD3U65.js";
136
+ } from "./chunk-NQ6FZKCE.js";
137
137
 
138
138
  // src/telegram/client.ts
139
139
  import { TelegramClient, Api } from "telegram";
@@ -435,13 +435,11 @@ var TelegramUserClient = class {
435
435
  }
436
436
  addServiceMessageHandler(handler) {
437
437
  this.client.addEventHandler(async (update) => {
438
- if ((update instanceof Api.UpdateNewMessage || update instanceof Api.UpdateNewChannelMessage) && // eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS update.message lacks proper typing
439
- update.message instanceof Api.MessageService) {
438
+ if ((update instanceof Api.UpdateNewMessage || update instanceof Api.UpdateNewChannelMessage) && update.message instanceof Api.MessageService) {
440
439
  await handler(update.message);
441
440
  }
442
441
  });
443
442
  }
444
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS raw update event
445
443
  addCallbackQueryHandler(handler) {
446
444
  this.client.addEventHandler(async (update) => {
447
445
  if (update.className === "UpdateBotCallbackQuery" || update.className === "UpdateInlineBotCallbackQuery") {
@@ -469,16 +467,13 @@ var TelegramUserClient = class {
469
467
  const parseMode = options.parseMode ?? "html";
470
468
  const formattedMessage = parseMode === "html" ? markdownToTelegramHtml(options.message) : options.message;
471
469
  return withFloodRetry(
472
- () => (
473
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS sendMessage accepts string | Entity
474
- this.client.sendMessage(entity, {
475
- message: formattedMessage,
476
- replyTo: options.replyTo,
477
- silent: options.silent,
478
- parseMode: parseMode === "none" ? void 0 : parseMode,
479
- linkPreview: false
480
- })
481
- )
470
+ () => this.client.sendMessage(entity, {
471
+ message: formattedMessage,
472
+ replyTo: options.replyTo,
473
+ silent: options.silent,
474
+ parseMode: parseMode === "none" ? void 0 : parseMode,
475
+ linkPreview: false
476
+ })
482
477
  );
483
478
  }
484
479
  async getMessages(entity, options) {
@@ -823,12 +818,11 @@ var TelegramBridge = class {
823
818
  let text = "";
824
819
  if (action instanceof Api2.MessageActionStarGiftPurchaseOffer) {
825
820
  const gift = action.gift;
826
- const price = action.price;
827
- const isUnique = gift.className === "StarGiftUnique";
821
+ const isUnique = gift instanceof Api2.StarGiftUnique;
828
822
  const title = gift.title || "Unknown Gift";
829
823
  const slug = isUnique ? gift.slug : void 0;
830
824
  const num = isUnique ? gift.num : void 0;
831
- const priceStars = price?.amount?.toString() || "?";
825
+ const priceStars = action.price.amount?.toString() || "?";
832
826
  const status = action.accepted ? "accepted" : action.declined ? "declined" : "pending";
833
827
  const expires = action.expiresAt ? new Date(action.expiresAt * 1e3).toISOString() : "unknown";
834
828
  text = `[Gift Offer Received]
@@ -847,12 +841,11 @@ var TelegramBridge = class {
847
841
  );
848
842
  } else if (action instanceof Api2.MessageActionStarGiftPurchaseOfferDeclined) {
849
843
  const gift = action.gift;
850
- const price = action.price;
851
- const isUnique = gift.className === "StarGiftUnique";
844
+ const isUnique = gift instanceof Api2.StarGiftUnique;
852
845
  const title = gift.title || "Unknown Gift";
853
846
  const slug = isUnique ? gift.slug : void 0;
854
847
  const num = isUnique ? gift.num : void 0;
855
- const priceStars = price?.amount?.toString() || "?";
848
+ const priceStars = action.price.amount?.toString() || "?";
856
849
  const reason = action.expired ? "expired" : "declined";
857
850
  text = `[Gift Offer ${action.expired ? "Expired" : "Declined"}]
858
851
  `;
@@ -861,7 +854,7 @@ var TelegramBridge = class {
861
854
  } else if (action instanceof Api2.MessageActionStarGift) {
862
855
  const gift = action.gift;
863
856
  const title = gift.title || "Unknown Gift";
864
- const stars = gift.stars?.toString() || "?";
857
+ const stars = gift instanceof Api2.StarGift ? gift.stars?.toString() || "?" : "?";
865
858
  const giftMessage = action.message?.text || "";
866
859
  const fromAnonymous = action.nameHidden;
867
860
  text = `[Gift Received]
@@ -3285,8 +3278,7 @@ var telegramGetRepliesExecutor = async (params, context) => {
3285
3278
  limit,
3286
3279
  maxId: 0,
3287
3280
  minId: 0,
3288
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS API response is untyped
3289
- hash: 0n
3281
+ hash: toLong(0n)
3290
3282
  })
3291
3283
  );
3292
3284
  const messages = [];
@@ -3381,8 +3373,7 @@ var telegramGetScheduledMessagesExecutor = async (params, context) => {
3381
3373
  const result = await gramJsClient.invoke(
3382
3374
  new Api11.messages.GetScheduledHistory({
3383
3375
  peer: entity,
3384
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS API response is untyped
3385
- hash: 0n
3376
+ hash: toLong(0n)
3386
3377
  })
3387
3378
  );
3388
3379
  const messages = "messages" in result ? result.messages : [];
@@ -7065,8 +7056,7 @@ var telegramGetFoldersExecutor = async (_params, context) => {
7065
7056
  const filterList = dialogFilters.filters ?? [];
7066
7057
  const folders = filterList.filter((filter) => filter.className === "DialogFilter").map((filter) => ({
7067
7058
  id: filter.id,
7068
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS API response is untyped
7069
- title: filter.title?.text ?? filter.title,
7059
+ title: filter.title.text,
7070
7060
  emoji: filter.emoticon || null,
7071
7061
  pinnedPeersCount: filter.pinnedPeers?.length || 0,
7072
7062
  includedPeersCount: filter.includePeers?.length || 0,
@@ -8092,19 +8082,15 @@ function decodeInlineMessageId(encoded) {
8092
8082
  if (buf.length === 20) {
8093
8083
  return new Api49.InputBotInlineMessageID({
8094
8084
  dcId: buf.readInt32LE(0),
8095
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS BigInteger compat
8096
- id: buf.readBigInt64LE(4),
8097
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS BigInteger compat
8098
- accessHash: buf.readBigInt64LE(12)
8085
+ id: toLong(buf.readBigInt64LE(4)),
8086
+ accessHash: toLong(buf.readBigInt64LE(12))
8099
8087
  });
8100
8088
  } else if (buf.length === 24) {
8101
8089
  return new Api49.InputBotInlineMessageID64({
8102
8090
  dcId: buf.readInt32LE(0),
8103
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS BigInteger compat
8104
- ownerId: buf.readBigInt64LE(4),
8091
+ ownerId: toLong(buf.readBigInt64LE(4)),
8105
8092
  id: buf.readInt32LE(12),
8106
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS BigInteger compat
8107
- accessHash: buf.readBigInt64LE(16)
8093
+ accessHash: toLong(buf.readBigInt64LE(16))
8108
8094
  });
8109
8095
  }
8110
8096
  throw new Error(`Unknown inline_message_id format (${buf.length} bytes)`);
@@ -8863,7 +8849,7 @@ var VerificationPoller = class {
8863
8849
  const me = this.bridge.getClient().getMe();
8864
8850
  if (!me) return { verified: false };
8865
8851
  const botUserId = Number(me.id);
8866
- const { telegramGetMyGiftsExecutor: telegramGetMyGiftsExecutor2 } = await import("./get-my-gifts-CC6HAVWB.js");
8852
+ const { telegramGetMyGiftsExecutor: telegramGetMyGiftsExecutor2 } = await import("./get-my-gifts-Y7EN7RK4.js");
8867
8853
  const toolContext = {
8868
8854
  bridge: this.bridge,
8869
8855
  db: this.db,
@@ -8878,7 +8864,8 @@ var VerificationPoller = class {
8878
8864
  if (!result.success || !result.data) {
8879
8865
  return { verified: false };
8880
8866
  }
8881
- const gifts = result.data.gifts || [];
8867
+ const verifyData = result.data;
8868
+ const gifts = verifyData.gifts || [];
8882
8869
  const matchingGift = gifts.find(
8883
8870
  (g) => g.slug === deal.userGivesGiftSlug && Number(g.fromId) === deal.userId && g.date && g.date >= deal.createdAt
8884
8871
  );
@@ -9759,7 +9746,8 @@ var GiftDetector = class {
9759
9746
  if (!result.success || !result.data) {
9760
9747
  return [];
9761
9748
  }
9762
- const gifts = result.data.gifts || [];
9749
+ const data = result.data;
9750
+ const gifts = data.gifts || [];
9763
9751
  const seenSet = this.seenGifts.get(userId) || /* @__PURE__ */ new Set();
9764
9752
  const newGifts = [];
9765
9753
  const currentMsgIds = /* @__PURE__ */ new Set();
@@ -10444,8 +10432,7 @@ var telegramSendGiftExecutor = async (params, context) => {
10444
10432
  const user = await gramJsClient.getInputEntity(userId);
10445
10433
  const invoiceData = {
10446
10434
  peer: user,
10447
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS API response is untyped
10448
- giftId: BigInt(giftId),
10435
+ giftId: toLong(giftId),
10449
10436
  hideName: anonymous,
10450
10437
  message: message ? new Api51.TextWithEntities({ text: message, entities: [] }) : void 0
10451
10438
  };
@@ -10631,8 +10618,7 @@ var telegramSetCollectiblePriceExecutor = async (params, context) => {
10631
10618
  new Api53.payments.UpdateStarGiftPrice({
10632
10619
  stargift: new Api53.InputSavedStarGiftUser({ msgId }),
10633
10620
  resellAmount: new Api53.StarsAmount({
10634
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS API response is untyped
10635
- amount: BigInt(isListing ? price : 0),
10621
+ amount: toLong(isListing ? price : 0),
10636
10622
  nanos: 0
10637
10623
  })
10638
10624
  })
@@ -10710,8 +10696,7 @@ var telegramGetResaleGiftsExecutor = async (params, context) => {
10710
10696
  }
10711
10697
  const result = await gramJsClient.invoke(
10712
10698
  new Api54.payments.GetResaleStarGifts({
10713
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS API response is untyped
10714
- giftId: BigInt(giftId),
10699
+ giftId: toLong(giftId),
10715
10700
  offset: "",
10716
10701
  limit,
10717
10702
  sortByPrice
@@ -10866,8 +10851,7 @@ var telegramSetGiftStatusExecutor = async (params, context) => {
10866
10851
  emojiStatus = new Api56.EmojiStatusEmpty();
10867
10852
  } else {
10868
10853
  emojiStatus = new Api56.InputEmojiStatusCollectible({
10869
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS API response is untyped
10870
- collectibleId: BigInt(collectibleId)
10854
+ collectibleId: toLong(collectibleId)
10871
10855
  });
10872
10856
  }
10873
10857
  await gramJsClient.invoke(
@@ -11104,8 +11088,7 @@ var telegramSendGiftOfferExecutor = async (params, context) => {
11104
11088
  new Api60.payments.SendStarGiftOffer({
11105
11089
  peer,
11106
11090
  slug,
11107
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- GramJS API response is untyped
11108
- price: new Api60.StarsAmount({ amount: BigInt(price), nanos: 0 }),
11091
+ price: new Api60.StarsAmount({ amount: toLong(price), nanos: 0 }),
11109
11092
  duration,
11110
11093
  randomId: randomLong()
11111
11094
  })
@@ -17052,7 +17035,6 @@ function runCommand(command, options) {
17052
17035
  detached: true,
17053
17036
  stdio: ["ignore", "pipe", "pipe"],
17054
17037
  encoding: "utf8"
17055
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Node.js spawn options type doesn't include encoding
17056
17038
  });
17057
17039
  const finish = (exitCode, signal) => {
17058
17040
  if (resolved) return;
@@ -18232,9 +18214,11 @@ var TeletonApp = class {
18232
18214
  memory;
18233
18215
  sdkDeps;
18234
18216
  webuiServer = null;
18217
+ apiServer = null;
18235
18218
  pluginWatcher = null;
18236
18219
  mcpConnections = [];
18237
18220
  callbackHandlerRegistered = false;
18221
+ messageHandlersRegistered = false;
18238
18222
  lifecycle = new AgentLifecycle();
18239
18223
  hookRunner;
18240
18224
  userHookEvaluator = null;
@@ -18332,7 +18316,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18332
18316
  );
18333
18317
  if (this.config.webui.enabled) {
18334
18318
  try {
18335
- const { WebUIServer } = await import("./server-3FHI2SEB.js");
18319
+ const { WebUIServer } = await import("./server-YODFBZKG.js");
18336
18320
  const mcpServers = () => Object.entries(this.config.mcp.servers).map(([name, serverConfig]) => {
18337
18321
  const type = serverConfig.command ? "stdio" : serverConfig.url ? "streamable-http" : "sse";
18338
18322
  const target = serverConfig.command ?? serverConfig.url ?? "";
@@ -18383,6 +18367,66 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18383
18367
  log137.warn("\u26A0\uFE0F Continuing without WebUI...");
18384
18368
  }
18385
18369
  }
18370
+ if (this.config.api?.enabled) {
18371
+ try {
18372
+ const { ApiServer: ApiServerClass } = await import("./server-GYZXKIKU.js");
18373
+ const mcpServers = () => Object.entries(this.config.mcp.servers).map(([name, serverConfig]) => {
18374
+ const type = serverConfig.command ? "stdio" : serverConfig.url ? "streamable-http" : "sse";
18375
+ const target = serverConfig.command ?? serverConfig.url ?? "";
18376
+ const connected = this.mcpConnections.some((c) => c.serverName === name);
18377
+ const moduleName = `mcp_${name}`;
18378
+ const moduleTools = this.toolRegistry.getModuleTools(moduleName);
18379
+ return {
18380
+ name,
18381
+ type,
18382
+ target,
18383
+ scope: serverConfig.scope ?? "always",
18384
+ enabled: serverConfig.enabled ?? true,
18385
+ connected,
18386
+ toolCount: moduleTools.length,
18387
+ tools: moduleTools.map((t) => t.name),
18388
+ envKeys: Object.keys(serverConfig.env ?? {})
18389
+ };
18390
+ });
18391
+ const builtinNames = this.modules.map((m) => m.name);
18392
+ const pluginContext = {
18393
+ bridge: this.bridge,
18394
+ db: getDatabase().getDb(),
18395
+ config: this.config
18396
+ };
18397
+ this.apiServer = new ApiServerClass(
18398
+ {
18399
+ agent: this.agent,
18400
+ bridge: this.bridge,
18401
+ memory: this.memory,
18402
+ toolRegistry: this.toolRegistry,
18403
+ plugins: this.modules.filter((m) => this.toolRegistry.isPluginModule(m.name)).map((m) => ({ name: m.name, version: m.version ?? "0.0.0" })),
18404
+ mcpServers,
18405
+ config: this.config.webui,
18406
+ configPath: this.configPath,
18407
+ lifecycle: this.lifecycle,
18408
+ marketplace: {
18409
+ modules: this.modules,
18410
+ config: this.config,
18411
+ sdkDeps: this.sdkDeps,
18412
+ pluginContext,
18413
+ loadedModuleNames: builtinNames,
18414
+ rewireHooks: () => this.wirePluginEventHooks()
18415
+ },
18416
+ userHookEvaluator: this.userHookEvaluator
18417
+ },
18418
+ this.config.api
18419
+ );
18420
+ await this.apiServer.start();
18421
+ if (process.env.TELETON_JSON_CREDENTIALS === "true") {
18422
+ const creds = this.apiServer.getCredentials();
18423
+ process.stdout.write(JSON.stringify(creds) + "\n");
18424
+ }
18425
+ } catch (error) {
18426
+ log137.error({ err: error }, "Failed to start Management API server");
18427
+ log137.warn("Continuing without Management API...");
18428
+ }
18429
+ }
18386
18430
  await this.lifecycle.start(() => this.startAgent());
18387
18431
  await new Promise(() => {
18388
18432
  });
@@ -18437,7 +18481,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18437
18481
  }
18438
18482
  this.toolRegistry.loadConfigFromDB(getDatabase().getDb());
18439
18483
  if (this.config.tool_rag.enabled) {
18440
- const { ToolIndex } = await import("./tool-index-PMAOXWUA.js");
18484
+ const { ToolIndex } = await import("./tool-index-NYH57UWP.js");
18441
18485
  const toolIndex2 = new ToolIndex(
18442
18486
  getDatabase().getDb(),
18443
18487
  this.memory.embedder,
@@ -18465,21 +18509,32 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18465
18509
  `\u26A0\uFE0F Tool count (${this.toolCount}) exceeds ${providerMeta.displayName} limit (${providerMeta.toolLimit})`
18466
18510
  );
18467
18511
  }
18468
- const { migrateSessionsToDb } = await import("./migrate-UBBEJ5BL.js");
18512
+ const { migrateSessionsToDb } = await import("./migrate-WFU6COBN.js");
18469
18513
  migrateSessionsToDb();
18470
- const { cleanupOldTranscripts } = await import("./transcript-NGDPSNIH.js");
18514
+ const { cleanupOldTranscripts } = await import("./transcript-IM7G25OS.js");
18471
18515
  cleanupOldTranscripts(30);
18472
- const { pruneOldSessions } = await import("./store-M5IMUQCL.js");
18516
+ const { pruneOldSessions } = await import("./store-7M4XV6M5.js");
18473
18517
  pruneOldSessions(30);
18474
18518
  if (this.memory.embedder.warmup) {
18475
18519
  await this.memory.embedder.warmup();
18476
18520
  }
18477
- const indexResult = await this.memory.knowledge.indexAll();
18478
18521
  const db2 = getDatabase();
18522
+ const forceReindex = db2.didDimensionsChange();
18523
+ const indexResult = await this.memory.knowledge.indexAll({ force: forceReindex });
18479
18524
  let ftsResult = { knowledge: 0, messages: 0 };
18480
18525
  if (indexResult.indexed > 0) {
18481
18526
  ftsResult = db2.rebuildFtsIndexes();
18482
18527
  }
18528
+ import("./memory-hook-WUXJNVT5.js").then(
18529
+ ({ consolidateOldMemoryFiles }) => consolidateOldMemoryFiles({
18530
+ apiKey: this.config.agent.api_key,
18531
+ provider: this.config.agent.provider,
18532
+ utilityModel: this.config.agent.utility_model
18533
+ })
18534
+ ).then((r) => {
18535
+ 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"));
18483
18538
  const toolIndex = this.toolRegistry.getToolIndex();
18484
18539
  if (toolIndex) {
18485
18540
  const t0 = Date.now();
@@ -18489,7 +18544,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18489
18544
  this.agent.initializeContextBuilder(this.memory.embedder, db2.isVectorSearchReady());
18490
18545
  if (this.config.agent.provider === "cocoon") {
18491
18546
  try {
18492
- const { registerCocoonModels } = await import("./client-MPHPIZB6.js");
18547
+ const { registerCocoonModels } = await import("./client-YOOHI776.js");
18493
18548
  const port = this.config.cocoon?.port ?? 1e4;
18494
18549
  const models = await registerCocoonModels(port);
18495
18550
  if (models.length === 0) {
@@ -18511,7 +18566,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18511
18566
  }
18512
18567
  if (this.config.agent.provider === "local" && this.config.agent.base_url) {
18513
18568
  try {
18514
- const { registerLocalModels } = await import("./client-MPHPIZB6.js");
18569
+ const { registerLocalModels } = await import("./client-YOOHI776.js");
18515
18570
  const models = await registerLocalModels(this.config.agent.base_url);
18516
18571
  if (models.length > 0) {
18517
18572
  log137.info(`Discovered ${models.length} local model(s): ${models.join(", ")}`);
@@ -18669,20 +18724,23 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18669
18724
  log137.error({ err: error }, `Error processing batch of ${messages.length} messages`);
18670
18725
  }
18671
18726
  );
18672
- this.bridge.onNewMessage(async (message) => {
18673
- try {
18674
- await this.debouncer.enqueue(message);
18675
- } catch (error) {
18676
- log137.error({ err: error }, "Error enqueueing message");
18677
- }
18678
- });
18679
- this.bridge.onServiceMessage(async (message) => {
18680
- try {
18681
- await this.debouncer.enqueue(message);
18682
- } catch (error) {
18683
- log137.error({ err: error }, "Error enqueueing service message");
18684
- }
18685
- });
18727
+ if (!this.messageHandlersRegistered) {
18728
+ this.bridge.onNewMessage(async (message) => {
18729
+ try {
18730
+ await this.debouncer.enqueue(message);
18731
+ } catch (error) {
18732
+ log137.error({ err: error }, "Error enqueueing message");
18733
+ }
18734
+ });
18735
+ this.bridge.onServiceMessage(async (message) => {
18736
+ try {
18737
+ await this.debouncer.enqueue(message);
18738
+ } catch (error) {
18739
+ log137.error({ err: error }, "Error enqueueing service message");
18740
+ }
18741
+ });
18742
+ this.messageHandlersRegistered = true;
18743
+ }
18686
18744
  }
18687
18745
  /**
18688
18746
  * Resolve owner name and username from Telegram API if not already configured.
@@ -18805,9 +18863,9 @@ Task: "${taskDescription}"`;
18805
18863
  */
18806
18864
  async handleScheduledTask(message) {
18807
18865
  const { getTaskStore } = await import("./tasks-WQIKXDX5.js");
18808
- const { executeScheduledTask } = await import("./task-executor-6W5HRX5C.js");
18809
- const { TaskDependencyResolver } = await import("./task-dependency-resolver-RR2O5S7B.js");
18810
- const { getDatabase: getDatabase2 } = await import("./memory-UBHM7ILG.js");
18866
+ const { executeScheduledTask } = await import("./task-executor-XBNJLUCS.js");
18867
+ const { TaskDependencyResolver } = await import("./task-dependency-resolver-L6UUMTHK.js");
18868
+ const { getDatabase: getDatabase2 } = await import("./memory-Q6EWGK2S.js");
18811
18869
  const db2 = getDatabase2().getDb();
18812
18870
  const taskStore = getTaskStore(db2);
18813
18871
  const match = message.text.match(/^\[TASK:([^\]]+)\]/);
@@ -18985,6 +19043,13 @@ Task: "${taskDescription}"`;
18985
19043
  log137.error({ err: e }, "\u26A0\uFE0F WebUI stop failed");
18986
19044
  }
18987
19045
  }
19046
+ if (this.apiServer) {
19047
+ try {
19048
+ await this.apiServer.stop();
19049
+ } catch (e) {
19050
+ log137.error({ err: e }, "\u26A0\uFE0F Management API stop failed");
19051
+ }
19052
+ }
18988
19053
  try {
18989
19054
  closeDatabase();
18990
19055
  } catch (e) {
@@ -0,0 +1,12 @@
1
+ // src/utils/errors.ts
2
+ function getErrorMessage(error) {
3
+ return error instanceof Error ? error.message : String(error);
4
+ }
5
+ function isHttpError(err) {
6
+ return typeof err === "object" && err !== null && ("status" in err || "response" in err);
7
+ }
8
+
9
+ export {
10
+ getErrorMessage,
11
+ isHttpError
12
+ };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  getDatabase
3
- } from "./chunk-7U7BOHCL.js";
3
+ } from "./chunk-VYKW7FMV.js";
4
4
  import {
5
5
  createLogger
6
- } from "./chunk-RCMD3U65.js";
6
+ } from "./chunk-NQ6FZKCE.js";
7
7
 
8
8
  // src/session/store.ts
9
9
  import { randomUUID } from "crypto";