switchroom 0.16.12 → 0.16.13

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.
@@ -51674,8 +51674,8 @@ import { existsSync, readFileSync } from "node:fs";
51674
51674
  import { dirname, join } from "node:path";
51675
51675
 
51676
51676
  // src/build-info.ts
51677
- var VERSION = "0.16.12";
51678
- var COMMIT_SHA = "4cab85e1";
51677
+ var VERSION = "0.16.13";
51678
+ var COMMIT_SHA = "d4f3ac38";
51679
51679
 
51680
51680
  // src/cli/resolve-version.ts
51681
51681
  function readPackageVersion() {
@@ -22587,7 +22587,7 @@ import { existsSync as existsSync6, readFileSync as readFileSync4 } from "node:f
22587
22587
  import { dirname as dirname4, join as join2 } from "node:path";
22588
22588
 
22589
22589
  // src/build-info.ts
22590
- var VERSION = "0.16.12";
22590
+ var VERSION = "0.16.13";
22591
22591
 
22592
22592
  // src/cli/resolve-version.ts
22593
22593
  function readPackageVersion() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "switchroom",
3
- "version": "0.16.12",
3
+ "version": "0.16.13",
4
4
  "description": "Run Claude Code 24/7 on your Claude Pro/Max subscription over Telegram. Open-source alternative to OpenClaw and NanoClaw — no API keys.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -56064,11 +56064,11 @@ function readTurnActiveMarkerAgeMs(stateDir, now) {
56064
56064
  }
56065
56065
 
56066
56066
  // ../src/build-info.ts
56067
- var VERSION = "0.16.12";
56068
- var COMMIT_SHA = "4cab85e1";
56069
- var COMMIT_DATE = "2026-06-28T11:11:09Z";
56070
- var LATEST_PR = 2634;
56071
- var COMMITS_AHEAD_OF_TAG = 0;
56067
+ var VERSION = "0.16.13";
56068
+ var COMMIT_SHA = "d4f3ac38";
56069
+ var COMMIT_DATE = "2026-06-28T21:45:50+10:00";
56070
+ var LATEST_PR = null;
56071
+ var COMMITS_AHEAD_OF_TAG = 2;
56072
56072
 
56073
56073
  // gateway/boot-version.ts
56074
56074
  function formatRelativeAgo(iso) {
@@ -58112,9 +58112,11 @@ var progressUpdateLastSent = new Map;
58112
58112
  var progressUpdateTurnCount = new Map;
58113
58113
  var currentTurn = null;
58114
58114
  var currentTurnMap = new CurrentTurnMap;
58115
+ var lastActiveTurnChatId;
58115
58116
  function setCurrentTurn(turn, key) {
58116
58117
  currentTurnMap.set(turn, key);
58117
58118
  currentTurn = currentTurnMap.get();
58119
+ lastActiveTurnChatId = turn.sessionChatId;
58118
58120
  }
58119
58121
  function endCurrentTurnForKey(turn, key) {
58120
58122
  const ended = currentTurnMap.endTurnForKey(turn, key);
@@ -60803,10 +60805,12 @@ async function executeReply(args) {
60803
60805
  const _a = loadAccess();
60804
60806
  if (_a.allowFrom.includes(_rawChatId) || _rawChatId in _a.groups)
60805
60807
  return _rawChatId;
60806
- if (turn?.sessionChatId && (_a.allowFrom.includes(turn.sessionChatId) || (turn.sessionChatId in _a.groups))) {
60807
- process.stderr.write(`telegram gateway: reply: model passed chat_id "${_rawChatId}" (not allowlisted) \u2014 ` + `routing to active turn chat "${turn.sessionChatId}"
60808
+ const fallbackChatId = turn?.sessionChatId ?? lastActiveTurnChatId;
60809
+ if (fallbackChatId && (_a.allowFrom.includes(fallbackChatId) || (fallbackChatId in _a.groups))) {
60810
+ const tier = turn == null ? "last-known" : "active";
60811
+ process.stderr.write(`telegram gateway: reply: model passed chat_id "${_rawChatId}" (not allowlisted) \u2014 ` + `routing to ${tier} turn chat "${fallbackChatId}"
60808
60812
  `);
60809
- return turn.sessionChatId;
60813
+ return fallbackChatId;
60810
60814
  }
60811
60815
  return _rawChatId;
60812
60816
  })();
@@ -2216,6 +2216,13 @@ type CurrentTurn = {
2216
2216
  // is never written and this is exactly the old singleton.
2217
2217
  let currentTurn: CurrentTurn | null = null
2218
2218
  const currentTurnMap = new CurrentTurnMap<CurrentTurn>()
2219
+ // Captures the most-recently-started turn's sessionChatId. Unlike currentTurn,
2220
+ // this is NOT cleared by the silence poke (firePoke/clearTurnStarted). It lets
2221
+ // the Bug B fallback in executeReply route to the correct chat even when the
2222
+ // model calls reply AFTER the silence poke has nulled currentTurn (Bug D).
2223
+ // Safe in single-tenant gateways: the fallback only fires when the raw chat_id
2224
+ // fails the allowlist, and this value was itself validated at inbound receipt.
2225
+ let lastActiveTurnChatId: string | undefined
2219
2226
 
2220
2227
  /**
2221
2228
  * Set the live turn for `key`. Flag-branches in ONE place (inside the map):
@@ -2227,6 +2234,7 @@ const currentTurnMap = new CurrentTurnMap<CurrentTurn>()
2227
2234
  function setCurrentTurn(turn: CurrentTurn, key: string): void {
2228
2235
  currentTurnMap.set(turn, key)
2229
2236
  currentTurn = currentTurnMap.get() // mirror most-recent-set (== `turn`)
2237
+ lastActiveTurnChatId = turn.sessionChatId
2230
2238
  }
2231
2239
 
2232
2240
  /**
@@ -7977,17 +7985,23 @@ async function executeReply(args: Record<string, unknown>): Promise<{ content: A
7977
7985
  // Non-Claude models (e.g. Gemini via LiteLLM sr-* routing) sometimes pass a
7978
7986
  // chat_id that is not in the allowlist — either an int/string mismatch, or
7979
7987
  // the model echoing the wrong identifier from context. When the raw value
7980
- // fails the allowlist check and the active turn has a validated sessionChatId,
7981
- // fall back to the turn's origin chat so the reply still lands correctly.
7988
+ // fails the allowlist check, fall back to the active (or last-known) turn's
7989
+ // validated sessionChatId so the reply still lands correctly.
7990
+ // Tier 1: live turn (currentTurn was non-null at reply entry).
7991
+ // Tier 2: last-known turn (survives silence poke — Bug D fix; currentTurn is
7992
+ // null because clearTurnStarted fired ≥5 min of model silence, but the model
7993
+ // finally called reply after the poke).
7982
7994
  const chat_id = (() => {
7983
7995
  const _a = loadAccess()
7984
7996
  if (_a.allowFrom.includes(_rawChatId) || _rawChatId in _a.groups) return _rawChatId
7985
- if (turn?.sessionChatId && (_a.allowFrom.includes(turn.sessionChatId) || turn.sessionChatId in _a.groups)) {
7997
+ const fallbackChatId = turn?.sessionChatId ?? lastActiveTurnChatId
7998
+ if (fallbackChatId && (_a.allowFrom.includes(fallbackChatId) || fallbackChatId in _a.groups)) {
7999
+ const tier = turn == null ? 'last-known' : 'active'
7986
8000
  process.stderr.write(
7987
8001
  `telegram gateway: reply: model passed chat_id "${_rawChatId}" (not allowlisted) — ` +
7988
- `routing to active turn chat "${turn.sessionChatId}"\n`,
8002
+ `routing to ${tier} turn chat "${fallbackChatId}"\n`,
7989
8003
  )
7990
- return turn.sessionChatId
8004
+ return fallbackChatId
7991
8005
  }
7992
8006
  return _rawChatId // let assertAllowedChat below throw the human-readable error
7993
8007
  })()
@@ -59,10 +59,13 @@ describe("uat: /model sr-* LiteLLM routing — section headers + session switch
59
59
  const openrouterHeader = flat.find(
60
60
  (b) => b.text.includes("OpenRouter") && b.callbackData === "mdl:h",
61
61
  );
62
- // Prefer a fast non-reasoning model for the E2E test; reasoning models
63
- // (deepseek-r1, o1, o3) take 2-5 min per response and hit the silence poke.
62
+ // Prefer deepseek-v3 (non-thinking, consistently fast) for the E2E test.
63
+ // gemini-2.5-flash may run in thinking mode via OpenRouter (5+ min latency),
64
+ // reasoning models (deepseek-r1, o1, o3) also take 2-5 min and hit the
65
+ // silence poke — both are OK now (Bug D fallback), but slow tests are painful.
64
66
  const srButton =
65
- flat.find((b) => b.callbackData?.startsWith("mdl:sr:") && /flash/.test(b.callbackData)) ??
67
+ flat.find((b) => b.callbackData?.startsWith("mdl:sr:") && /deepseek-v3/.test(b.callbackData)) ??
68
+ flat.find((b) => b.callbackData?.startsWith("mdl:sr:") && /flash/.test(b.callbackData) && !/thinking/.test(b.callbackData)) ??
66
69
  flat.find((b) => b.callbackData?.startsWith("mdl:sr:") && !/r1|o1|o3|thinking/.test(b.callbackData)) ??
67
70
  flat.find((b) => b.callbackData?.startsWith("mdl:sr:"));
68
71
 
@@ -93,10 +96,12 @@ describe("uat: /model sr-* LiteLLM routing — section headers + session switch
93
96
  expect((kbAfter ?? []).flat().length, "menu keeps buttons after sr-* tap").toBeGreaterThan(0);
94
97
 
95
98
  // ── 3. Send a quick message to generate a LiteLLM-routed turn ──
96
- // Use 120s fast models (gemini-flash, deepseek-v3) respond in <10s,
97
- // but the request still has to go through the model switch inject + proxy.
99
+ // 480s budget: fast models (deepseek-v3) reply in <10s; Gemini 2.5 Flash
100
+ // may run thinking mode via OpenRouter and take 5+ min. The silence poke
101
+ // fires at 300s, which is OK — the Bug D fallback (lastActiveTurnChatId)
102
+ // routes the reply even when currentTurn was nulled by the poke.
98
103
  await sc.sendDM("Just reply with the word OK.");
99
- await sc.expectMessage(/ok/i, { from: "bot", timeout: 120_000 });
104
+ await sc.expectMessage(/ok/i, { from: "bot", timeout: 480_000 });
100
105
 
101
106
  // ── 4. LiteLLM spend attribution ────────────────────────────────
102
107
  if (spendBefore >= 0) {
@@ -126,7 +131,7 @@ describe("uat: /model sr-* LiteLLM routing — section headers + session switch
126
131
  await sc.tearDown();
127
132
  }
128
133
  },
129
- 210_000,
134
+ 660_000,
130
135
  );
131
136
 
132
137
  it(