echo-t3-bridge 0.1.6 → 0.1.7

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/dist/cli.mjs CHANGED
@@ -834,11 +834,12 @@ async function probeDriverUsage(driver, force = false) {
834
834
  inflightMap.set(driver, task);
835
835
  return task;
836
836
  }
837
- async function enrichProvidersWithQuotas(providers, forceQuota = false) {
837
+ async function enrichProvidersWithQuotas(providers, forceQuota = false, providerId) {
838
838
  const neededDrivers = /* @__PURE__ */ new Set();
839
839
  for (const p of providers) {
840
840
  if (!p || typeof p !== "object") continue;
841
841
  const rec = p;
842
+ if (providerId && String(rec.instanceId ?? "").toLowerCase() !== providerId.toLowerCase()) continue;
842
843
  if (rec.installed === false) continue;
843
844
  const driver = resolveQuotaDriver(rec);
844
845
  if (!driver) continue;
@@ -848,7 +849,10 @@ async function enrichProvidersWithQuotas(providers, forceQuota = false) {
848
849
  neededDrivers.add(driver);
849
850
  }
850
851
  }
851
- if (neededDrivers.size === 0) return providers;
852
+ if (neededDrivers.size === 0) {
853
+ if (providerId) throw new Error("\u672A\u627E\u5230\u53EF\u540C\u6B65\u989D\u5EA6\u7684 CLI");
854
+ return providers;
855
+ }
852
856
  const probed = /* @__PURE__ */ new Map();
853
857
  await Promise.all(
854
858
  [...neededDrivers].map(async (driver) => {
@@ -858,7 +862,10 @@ async function enrichProvidersWithQuotas(providers, forceQuota = false) {
858
862
  }
859
863
  })
860
864
  );
861
- if (probed.size === 0) return providers;
865
+ if (probed.size === 0) {
866
+ if (providerId) throw new Error("\u8BE5 CLI \u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6\u989D\u5EA6");
867
+ return providers;
868
+ }
862
869
  return providers.map((p) => {
863
870
  if (!p || typeof p !== "object") return p;
864
871
  const rec = p;
@@ -1409,7 +1416,13 @@ var LocalT3Client = class {
1409
1416
  this.ensureThreadSubscribed(threadId, 0);
1410
1417
  }
1411
1418
  }
1412
- async refreshProviders(includeQuota = false) {
1419
+ async refreshProviders(includeQuota = false, providerId) {
1420
+ if (providerId) {
1421
+ const finalList2 = await enrichProvidersWithQuotas(this.lastProviders, true, providerId);
1422
+ this.lastProviders = finalList2;
1423
+ this.callbacks.onProviders(finalList2);
1424
+ return { providers: finalList2 };
1425
+ }
1413
1426
  const payload = includeQuota ? { fresh: true, refreshModels: true, usageLimitsCommand: true } : { fresh: true };
1414
1427
  const raw = await this.callRpc("server.refreshProviders", payload, 45e3);
1415
1428
  const list = Array.isArray(raw) ? raw : Array.isArray(raw?.providers) ? raw.providers : this.lastProviders;
@@ -2342,8 +2355,9 @@ var EchoT3Bridge = class {
2342
2355
  }
2343
2356
  case "providers.refresh": {
2344
2357
  try {
2345
- const result = await this.localT3.refreshProviders(true);
2346
- this.replyHub(frame.type, frame.id, { ok: true, result });
2358
+ const providerId = frame.data?.providerId;
2359
+ const result = await this.localT3.refreshProviders(true, typeof providerId === "string" ? providerId : void 0);
2360
+ this.replyHub(frame.type, frame.id, { ok: true, result: typeof providerId === "string" ? { ...result, quotaProviderId: providerId } : result });
2347
2361
  } catch (err) {
2348
2362
  this.replyHub(frame.type, frame.id, { ok: false, error: this.toRpcError(err) });
2349
2363
  }
@@ -389,8 +389,9 @@ export class EchoT3Bridge {
389
389
  }
390
390
  case 'providers.refresh': {
391
391
  try {
392
- const result = await this.localT3.refreshProviders(true);
393
- this.replyHub(frame.type, frame.id, { ok: true, result });
392
+ const providerId = frame.data?.providerId;
393
+ const result = await this.localT3.refreshProviders(true, typeof providerId === 'string' ? providerId : undefined);
394
+ this.replyHub(frame.type, frame.id, { ok: true, result: typeof providerId === 'string' ? { ...result, quotaProviderId: providerId } : result });
394
395
  }
395
396
  catch (err) {
396
397
  this.replyHub(frame.type, frame.id, { ok: false, error: this.toRpcError(err) });
@@ -604,7 +604,13 @@ export class LocalT3Client {
604
604
  this.ensureThreadSubscribed(threadId, 0);
605
605
  }
606
606
  }
607
- async refreshProviders(includeQuota = false) {
607
+ async refreshProviders(includeQuota = false, providerId) {
608
+ if (providerId) {
609
+ const finalList = await enrichProvidersWithQuotas(this.lastProviders, true, providerId);
610
+ this.lastProviders = finalList;
611
+ this.callbacks.onProviders(finalList);
612
+ return { providers: finalList };
613
+ }
608
614
  const payload = includeQuota
609
615
  ? { fresh: true, refreshModels: true, usageLimitsCommand: true }
610
616
  : { fresh: true };
@@ -375,12 +375,14 @@ async function probeDriverUsage(driver, force = false) {
375
375
  * Enriches all installed/enabled providers reported by the unmodified local T3
376
376
  * server using toc-ocra's proven quota readers (`agy`, `codex`, `claude`, `kiro`).
377
377
  */
378
- export async function enrichProvidersWithQuotas(providers, forceQuota = false) {
378
+ export async function enrichProvidersWithQuotas(providers, forceQuota = false, providerId) {
379
379
  const neededDrivers = new Set();
380
380
  for (const p of providers) {
381
381
  if (!p || typeof p !== 'object')
382
382
  continue;
383
383
  const rec = p;
384
+ if (providerId && String(rec.instanceId ?? '').toLowerCase() !== providerId.toLowerCase())
385
+ continue;
384
386
  if (rec.installed === false)
385
387
  continue;
386
388
  const driver = resolveQuotaDriver(rec);
@@ -393,8 +395,11 @@ export async function enrichProvidersWithQuotas(providers, forceQuota = false) {
393
395
  neededDrivers.add(driver);
394
396
  }
395
397
  }
396
- if (neededDrivers.size === 0)
398
+ if (neededDrivers.size === 0) {
399
+ if (providerId)
400
+ throw new Error('未找到可同步额度的 CLI');
397
401
  return providers;
402
+ }
398
403
  const probed = new Map();
399
404
  await Promise.all([...neededDrivers].map(async (driver) => {
400
405
  const limits = await probeDriverUsage(driver, forceQuota).catch(() => null);
@@ -402,8 +407,11 @@ export async function enrichProvidersWithQuotas(providers, forceQuota = false) {
402
407
  probed.set(driver, limits);
403
408
  }
404
409
  }));
405
- if (probed.size === 0)
410
+ if (probed.size === 0) {
411
+ if (providerId)
412
+ throw new Error('该 CLI 暂时无法读取额度');
406
413
  return providers;
414
+ }
407
415
  return providers.map((p) => {
408
416
  if (!p || typeof p !== 'object')
409
417
  return p;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echo-t3-bridge",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Zero-fork bridge connecting an unmodified local T3 Code server to Echo Hub over a reverse WebSocket tunnel.",
5
5
  "type": "module",
6
6
  "bin": {