@0xmaxma/claude-gateway 2.1.11 → 2.1.12
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"packageVersion": "2.1.
|
|
4
|
-
"builtAt": "2026-11-
|
|
5
|
-
"commit": "
|
|
6
|
-
"tag": "v2.1.
|
|
3
|
+
"packageVersion": "2.1.12",
|
|
4
|
+
"builtAt": "2026-11-06T02:27:53.811Z",
|
|
5
|
+
"commit": "fbb89d960eda196958b4e731cd802ece02bf83a5",
|
|
6
|
+
"tag": "v2.1.12",
|
|
7
7
|
"dirty": false
|
|
8
8
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export async function fetchModelMenuResponses(
|
|
2
|
+
callbackUrl: string,
|
|
3
|
+
chatId: string,
|
|
4
|
+
request: typeof fetch = fetch,
|
|
5
|
+
timeoutMs = 10_000,
|
|
6
|
+
): Promise<{ modelData: { model?: string }; modelsData: { models?: unknown; configuredModels?: unknown; liveModels?: unknown } }> {
|
|
7
|
+
const signal = AbortSignal.timeout(timeoutMs)
|
|
8
|
+
const [modelRes, modelsRes] = await Promise.all([
|
|
9
|
+
request(callbackUrl + '/command', {
|
|
10
|
+
method: 'POST',
|
|
11
|
+
headers: { 'Content-Type': 'application/json' },
|
|
12
|
+
body: JSON.stringify({ command: 'get_model', chat_id: chatId }),
|
|
13
|
+
signal,
|
|
14
|
+
}),
|
|
15
|
+
request(callbackUrl + '/command', {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: { 'Content-Type': 'application/json' },
|
|
18
|
+
body: JSON.stringify({ command: 'get_models' }),
|
|
19
|
+
signal,
|
|
20
|
+
}),
|
|
21
|
+
])
|
|
22
|
+
if (!modelRes.ok || !modelsRes.ok) throw new Error('model request failed')
|
|
23
|
+
return {
|
|
24
|
+
modelData: await modelRes.json() as { model?: string },
|
|
25
|
+
modelsData: await modelsRes.json() as { models?: unknown; configuredModels?: unknown; liveModels?: unknown },
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function sendModelMenuReply<T>(
|
|
30
|
+
send: (signal: AbortSignal) => Promise<T>,
|
|
31
|
+
timeoutMs = 10_000,
|
|
32
|
+
): Promise<T> {
|
|
33
|
+
const controller = new AbortController()
|
|
34
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
35
|
+
const deadline = new Promise<never>((_, reject) => {
|
|
36
|
+
timer = setTimeout(() => {
|
|
37
|
+
controller.abort()
|
|
38
|
+
const error = new Error('Telegram model menu request timed out')
|
|
39
|
+
error.name = 'TimeoutError'
|
|
40
|
+
reject(error)
|
|
41
|
+
}, timeoutMs)
|
|
42
|
+
})
|
|
43
|
+
try {
|
|
44
|
+
return await Promise.race([send(controller.signal), deadline])
|
|
45
|
+
} finally {
|
|
46
|
+
clearTimeout(timer)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { commandHelp } from '../../../dist/agent/command-help.js';
|
|
3
3
|
import { parseSessionInfo } from './session-browser';
|
|
4
|
+
import { fetchModelMenuResponses, sendModelMenuReply } from './model-menu-request';
|
|
4
5
|
/**
|
|
5
6
|
* Telegram channel for Claude Gateway.
|
|
6
7
|
*
|
|
@@ -1266,25 +1267,7 @@ async function fetchModelMenuData(chatId: string): Promise<{
|
|
|
1266
1267
|
liveModels: Array<{ id: string; label: string }>
|
|
1267
1268
|
} | null> {
|
|
1268
1269
|
if (!CALLBACK_URL_BASE) return null
|
|
1269
|
-
const
|
|
1270
|
-
fetch(CALLBACK_URL_BASE + '/command', {
|
|
1271
|
-
method: 'POST',
|
|
1272
|
-
headers: { 'Content-Type': 'application/json' },
|
|
1273
|
-
body: JSON.stringify({ command: 'get_model', chat_id: chatId }),
|
|
1274
|
-
}),
|
|
1275
|
-
fetch(CALLBACK_URL_BASE + '/command', {
|
|
1276
|
-
method: 'POST',
|
|
1277
|
-
headers: { 'Content-Type': 'application/json' },
|
|
1278
|
-
body: JSON.stringify({ command: 'get_models' }),
|
|
1279
|
-
}),
|
|
1280
|
-
])
|
|
1281
|
-
if (!modelRes.ok || !modelsRes.ok) throw new Error('model request failed')
|
|
1282
|
-
const modelData = (await modelRes.json()) as { model?: string }
|
|
1283
|
-
const modelsData = (await modelsRes.json()) as {
|
|
1284
|
-
models?: unknown
|
|
1285
|
-
configuredModels?: unknown
|
|
1286
|
-
liveModels?: unknown
|
|
1287
|
-
}
|
|
1270
|
+
const { modelData, modelsData } = await fetchModelMenuResponses(CALLBACK_URL_BASE, chatId)
|
|
1288
1271
|
const currentModel = typeof modelData.model === 'string' ? modelData.model : ''
|
|
1289
1272
|
const availableRaw = validModelRows(modelsData.models)
|
|
1290
1273
|
const availableModels = availableRaw.length ? availableRaw : validModelRows(AVAILABLE_MODELS)
|
|
@@ -1322,15 +1305,27 @@ bot.command('models', async ctx => {
|
|
|
1322
1305
|
if (!access.allowFrom.includes(String(ctx.from!.id))) return
|
|
1323
1306
|
if (!CALLBACK_URL_BASE) return
|
|
1324
1307
|
|
|
1308
|
+
let stage: 'callback' | 'send' = 'callback'
|
|
1325
1309
|
try {
|
|
1326
1310
|
const menu = await fetchModelMenuData(String(ctx.chat.id))
|
|
1327
1311
|
if (!menu) return
|
|
1328
1312
|
const keyboard = buildModelsRootKeyboard(menu.currentModel, menu.configuredModels, menu.liveModels)
|
|
1329
|
-
|
|
1313
|
+
stage = 'send'
|
|
1314
|
+
await sendModelMenuReply(signal => ctx.reply(`Current model: ${menu.currentModel}\nSelect a model:`, {
|
|
1330
1315
|
reply_markup: keyboard,
|
|
1331
|
-
})
|
|
1316
|
+
}, signal as Parameters<Context['reply']>[2]))
|
|
1332
1317
|
} catch (err) {
|
|
1333
|
-
|
|
1318
|
+
const errorName = err instanceof Error ? err.name : 'UnknownError'
|
|
1319
|
+
process.stderr.write(`telegram channel: /models ${stage} failed (${errorName})\n`)
|
|
1320
|
+
// A failed send may already have reached Telegram. Only a callback failure
|
|
1321
|
+
// is known to have occurred before any menu message was sent.
|
|
1322
|
+
if (stage !== 'callback') return
|
|
1323
|
+
try {
|
|
1324
|
+
await sendModelMenuReply(signal => ctx.reply('Failed to get model info.', {}, signal as Parameters<Context['reply']>[2]))
|
|
1325
|
+
} catch (replyErr) {
|
|
1326
|
+
const replyErrorName = replyErr instanceof Error ? replyErr.name : 'UnknownError'
|
|
1327
|
+
process.stderr.write(`telegram channel: /models fallback send failed (${replyErrorName})\n`)
|
|
1328
|
+
}
|
|
1334
1329
|
}
|
|
1335
1330
|
})
|
|
1336
1331
|
|
|
@@ -1912,6 +1907,7 @@ bot.on('callback_query:data', async ctx => {
|
|
|
1912
1907
|
await ctx.answerCallbackQuery({ text: 'Not available.' }).catch(() => {})
|
|
1913
1908
|
return
|
|
1914
1909
|
}
|
|
1910
|
+
let answered = false
|
|
1915
1911
|
try {
|
|
1916
1912
|
const chatId = String(ctx.callbackQuery.message?.chat.id ?? ctx.from.id)
|
|
1917
1913
|
const menu = await fetchModelMenuData(chatId)
|
|
@@ -1936,9 +1932,12 @@ bot.on('callback_query:data', async ctx => {
|
|
|
1936
1932
|
if (safePage < totalPages - 1) keyboard.text('»', `models:more:${safePage + 1}`)
|
|
1937
1933
|
keyboard.row().text('Dismiss', 'models:dismiss')
|
|
1938
1934
|
await ctx.answerCallbackQuery().catch(() => {})
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1935
|
+
answered = true
|
|
1936
|
+
await sendModelMenuReply(signal => ctx.editMessageText(`More models (live) — page ${safePage + 1}/${totalPages}:`, { reply_markup: keyboard }, signal as Parameters<Context['editMessageText']>[2]))
|
|
1937
|
+
} catch (err) {
|
|
1938
|
+
const errorName = err instanceof Error ? err.name : 'UnknownError'
|
|
1939
|
+
process.stderr.write(`telegram channel: models:more failed (${errorName})\n`)
|
|
1940
|
+
if (!answered) await ctx.answerCallbackQuery({ text: 'Request failed' }).catch(() => {})
|
|
1942
1941
|
}
|
|
1943
1942
|
return
|
|
1944
1943
|
}
|
|
@@ -1952,6 +1951,7 @@ bot.on('callback_query:data', async ctx => {
|
|
|
1952
1951
|
await ctx.answerCallbackQuery({ text: 'Not available.' }).catch(() => {})
|
|
1953
1952
|
return
|
|
1954
1953
|
}
|
|
1954
|
+
let answered = false
|
|
1955
1955
|
try {
|
|
1956
1956
|
const chatId = String(ctx.callbackQuery.message?.chat.id ?? ctx.from.id)
|
|
1957
1957
|
const menu = await fetchModelMenuData(chatId)
|
|
@@ -1961,9 +1961,12 @@ bot.on('callback_query:data', async ctx => {
|
|
|
1961
1961
|
}
|
|
1962
1962
|
const keyboard = buildModelsRootKeyboard(menu.currentModel, menu.configuredModels, menu.liveModels)
|
|
1963
1963
|
await ctx.answerCallbackQuery().catch(() => {})
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1964
|
+
answered = true
|
|
1965
|
+
await sendModelMenuReply(signal => ctx.editMessageText(`Current model: ${menu.currentModel}\nSelect a model:`, { reply_markup: keyboard }, signal as Parameters<Context['editMessageText']>[2]))
|
|
1966
|
+
} catch (err) {
|
|
1967
|
+
const errorName = err instanceof Error ? err.name : 'UnknownError'
|
|
1968
|
+
process.stderr.write(`telegram channel: models:back failed (${errorName})\n`)
|
|
1969
|
+
if (!answered) await ctx.answerCallbackQuery({ text: 'Request failed' }).catch(() => {})
|
|
1967
1970
|
}
|
|
1968
1971
|
return
|
|
1969
1972
|
}
|