@tractorscorch/clank 1.2.0 → 1.2.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.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
6
6
 
7
7
  ---
8
8
 
9
+ ## [1.2.1] — 2026-03-23
10
+
11
+ ### Fixed
12
+ - **Gateway crash on restart** — stale Telegram messages queued while offline no longer flood the model. Messages older than 30s before startup are dropped.
13
+ - **Parallel model overload** — Telegram messages from the same chat are now processed sequentially (per-chat queue) instead of all at once.
14
+
15
+ ---
16
+
9
17
  ## [1.2.0] — 2026-03-22
10
18
 
11
19
  ### Added
package/dist/index.js CHANGED
@@ -4732,11 +4732,17 @@ var init_telegram = __esm({
4732
4732
  try {
4733
4733
  this.bot = new Bot(telegramConfig.botToken);
4734
4734
  const bot = this.bot;
4735
+ const startupTime = Math.floor(Date.now() / 1e3);
4736
+ const chatLocks = /* @__PURE__ */ new Map();
4735
4737
  bot.on("message:text", async (ctx) => {
4736
4738
  const msg = ctx.message;
4737
4739
  const chatId = msg.chat.id;
4738
4740
  const userId = msg.from?.id;
4739
4741
  const isGroup = msg.chat.type === "group" || msg.chat.type === "supergroup";
4742
+ if (msg.date < startupTime - 30) {
4743
+ console.log(` Telegram: dropping stale message from ${userId} (${startupTime - msg.date}s old)`);
4744
+ return;
4745
+ }
4740
4746
  if (telegramConfig.allowFrom && telegramConfig.allowFrom.length > 0) {
4741
4747
  const username = msg.from?.username ? `@${msg.from.username}` : "";
4742
4748
  const userIdStr = String(userId || "");
@@ -4760,27 +4766,33 @@ var init_telegram = __esm({
4760
4766
  }
4761
4767
  return;
4762
4768
  }
4763
- if (!this.gateway) return;
4764
- try {
4765
- await ctx.api.sendChatAction(chatId, "typing");
4766
- const response = await this.gateway.handleInboundMessage(
4767
- {
4768
- channel: "telegram",
4769
- peerId: chatId,
4770
- peerKind: isGroup ? "group" : "dm"
4771
- },
4772
- msg.text
4773
- );
4774
- if (response) {
4775
- const chunks = splitMessage(response, 4e3);
4776
- for (const chunk of chunks) {
4777
- await ctx.api.sendMessage(chatId, chunk);
4769
+ const processMessage = async () => {
4770
+ if (!this.gateway) return;
4771
+ try {
4772
+ await ctx.api.sendChatAction(chatId, "typing");
4773
+ const response = await this.gateway.handleInboundMessage(
4774
+ {
4775
+ channel: "telegram",
4776
+ peerId: chatId,
4777
+ peerKind: isGroup ? "group" : "dm"
4778
+ },
4779
+ msg.text
4780
+ );
4781
+ if (response) {
4782
+ const chunks = splitMessage(response, 4e3);
4783
+ for (const chunk of chunks) {
4784
+ await ctx.api.sendMessage(chatId, chunk);
4785
+ }
4778
4786
  }
4787
+ } catch (err) {
4788
+ const errMsg = err instanceof Error ? err.message : String(err);
4789
+ await ctx.api.sendMessage(chatId, `Error: ${errMsg.slice(0, 200)}`);
4779
4790
  }
4780
- } catch (err) {
4781
- const errMsg = err instanceof Error ? err.message : String(err);
4782
- await ctx.api.sendMessage(chatId, `Error: ${errMsg.slice(0, 200)}`);
4783
- }
4791
+ };
4792
+ const prev = chatLocks.get(chatId) || Promise.resolve();
4793
+ const next = prev.then(processMessage).catch(() => {
4794
+ });
4795
+ chatLocks.set(chatId, next);
4784
4796
  });
4785
4797
  bot.start({
4786
4798
  onStart: () => {
@@ -5327,7 +5339,7 @@ var init_server = __esm({
5327
5339
  res.writeHead(200, { "Content-Type": "application/json" });
5328
5340
  res.end(JSON.stringify({
5329
5341
  status: "ok",
5330
- version: "1.2.0",
5342
+ version: "1.2.1",
5331
5343
  uptime: process.uptime(),
5332
5344
  clients: this.clients.size,
5333
5345
  agents: this.engines.size
@@ -5435,7 +5447,7 @@ var init_server = __esm({
5435
5447
  const hello = {
5436
5448
  type: "hello",
5437
5449
  protocol: PROTOCOL_VERSION,
5438
- version: "1.2.0",
5450
+ version: "1.2.1",
5439
5451
  agents: this.config.agents.list.map((a) => ({
5440
5452
  id: a.id,
5441
5453
  name: a.name || a.id,
@@ -6769,7 +6781,7 @@ async function runTui(opts) {
6769
6781
  ws.on("open", () => {
6770
6782
  ws.send(JSON.stringify({
6771
6783
  type: "connect",
6772
- params: { auth: { token }, mode: "tui", version: "1.2.0" }
6784
+ params: { auth: { token }, mode: "tui", version: "1.2.1" }
6773
6785
  }));
6774
6786
  });
6775
6787
  ws.on("message", (data) => {
@@ -7198,7 +7210,7 @@ import { fileURLToPath as fileURLToPath5 } from "url";
7198
7210
  import { dirname as dirname5, join as join18 } from "path";
7199
7211
  var __filename3 = fileURLToPath5(import.meta.url);
7200
7212
  var __dirname3 = dirname5(__filename3);
7201
- var version = "1.2.0";
7213
+ var version = "1.2.1";
7202
7214
  try {
7203
7215
  const pkg = JSON.parse(readFileSync(join18(__dirname3, "..", "package.json"), "utf-8"));
7204
7216
  version = pkg.version;