dsh-tg-bridge 1.25.1 → 1.25.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.
- package/control/cmd-fallback.mjs +10 -6
- package/model-probe.mjs +15 -3
- package/package.json +1 -1
package/control/cmd-fallback.mjs
CHANGED
|
@@ -22,7 +22,7 @@ function providerIds(profile) {
|
|
|
22
22
|
return providerRows(read(patchPath(profile))).map((row) => row.id).filter(Boolean);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/** `
|
|
25
|
+
/** `router-a/kimi-k3:free` → `{provider, model}`; a bare id keeps the given provider. */
|
|
26
26
|
export function splitRoute(wanted, fallbackProvider = '') {
|
|
27
27
|
const text = String(wanted || '').trim();
|
|
28
28
|
const at = text.indexOf('/');
|
|
@@ -192,6 +192,10 @@ export async function handleFallbackCommands(ctx) {
|
|
|
192
192
|
|
|
193
193
|
// A probe proves the key works, not that this conversation is acceptable: the
|
|
194
194
|
// hint says so, because "route is fine" beside a 400 would be a lie.
|
|
195
|
+
//
|
|
196
|
+
// The probes run together, not one after another: seven routes at a 15-second
|
|
197
|
+
// timeout each is nearly two minutes of a command that looks frozen, and the
|
|
198
|
+
// poller waits behind it. One round answers in the time of the slowest route.
|
|
195
199
|
case 'test':
|
|
196
200
|
case 'x': {
|
|
197
201
|
const targets = entry ? [entry] : chain;
|
|
@@ -199,12 +203,12 @@ export async function handleFallbackCommands(ctx) {
|
|
|
199
203
|
say(t(lang, 'ctrl.fallback.empty'));
|
|
200
204
|
return true;
|
|
201
205
|
}
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
const verdict =
|
|
205
|
-
rows.push({ n: chain.indexOf(item) + 1, route: labelOf(item), kind: VERDICT[verdict.kind] || 'other' });
|
|
206
|
+
const verdicts = await Promise.all(targets.map((item) => probeModel(item.model, { provider: item.provider })));
|
|
207
|
+
const rows = targets.map((item, index) => {
|
|
208
|
+
const verdict = verdicts[index];
|
|
206
209
|
log(`fallback probe ${labelOf(item)}: ${verdict.kind}${verdict.detail ? ` (${String(verdict.detail).slice(0, 80)})` : ''}`);
|
|
207
|
-
|
|
210
|
+
return { n: chain.indexOf(item) + 1, route: labelOf(item), kind: VERDICT[verdict.kind] || 'other' };
|
|
211
|
+
});
|
|
208
212
|
// One way back to the card: the probe answer is long, and the person who
|
|
209
213
|
// just learned route 4 is dead wants the list, not a typed command.
|
|
210
214
|
say(renderProbe({ t: tr, rows }), { keyboard: [[{ text: t(lang, 'ctrl.fallback.back'), data: 'fb:s' }]] });
|
package/model-probe.mjs
CHANGED
|
@@ -120,14 +120,26 @@ export function firstProvider() {
|
|
|
120
120
|
return providerFor('');
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
/**
|
|
124
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Classify a provider answer into something the chat can act on.
|
|
125
|
+
*
|
|
126
|
+
* The order is the whole point, and it was wrong in a way a live probe caught:
|
|
127
|
+
* one router answers a per-minute limit with **403** and the sentence "This
|
|
128
|
+
* model is at its provider's per minute limit right now". The status was read
|
|
129
|
+
* first, so the card called it "key refused" — the one verdict that sends a
|
|
130
|
+
* person to re-enter a key that works, while the route was merely throttled.
|
|
131
|
+
* Words about a limit therefore win over the status, and a bare 403 stays auth.
|
|
132
|
+
*/
|
|
133
|
+
export function classify(status, body) {
|
|
125
134
|
const text = String(body || '');
|
|
126
135
|
if (status === 200) return 'ok';
|
|
127
136
|
if (/insufficient_user_quota|balance|billing|payment/i.test(text)) return 'balance';
|
|
128
|
-
|
|
137
|
+
// "per minute limit", "rate limit", "too many requests", "busy" — one family,
|
|
138
|
+
// whatever status the router chose to attach to it.
|
|
139
|
+
if (/\b429\b|rate.?limit|per.?minute limit|requests? per minute|too many requests|get_channel_failed|all providers|busy|overloaded/i.test(text)) return 'busy';
|
|
129
140
|
if (status === 401 || status === 403) return 'auth';
|
|
130
141
|
if (status === 404) return 'missing';
|
|
142
|
+
if (status >= 500) return 'busy';
|
|
131
143
|
return 'other';
|
|
132
144
|
}
|
|
133
145
|
|
package/package.json
CHANGED