switchroom 0.14.92 → 0.15.0
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/auth-broker/index.js +48 -12
- package/dist/cli/switchroom.js +935 -887
- package/dist/cli/ui/index.html +16 -5
- package/package.json +1 -1
- package/telegram-plugin/dist/gateway/gateway.js +49 -9
- package/telegram-plugin/gateway/gateway.ts +81 -4
- package/telegram-plugin/gateway/obligation-ledger.ts +47 -8
- package/telegram-plugin/gateway/turn-active-marker.ts +22 -0
- package/telegram-plugin/tests/obligation-determinism.test.ts +63 -3
- package/telegram-plugin/tests/obligation-ledger.test.ts +85 -0
- package/telegram-plugin/tests/turn-active-marker.test.ts +28 -0
|
@@ -13560,6 +13560,7 @@ class AuthBroker {
|
|
|
13560
13560
|
listeners = new Map;
|
|
13561
13561
|
refreshTimer = null;
|
|
13562
13562
|
consumerProbeTimer = null;
|
|
13563
|
+
fleetProbeTimer = null;
|
|
13563
13564
|
fetchQuotaImpl;
|
|
13564
13565
|
stateDir;
|
|
13565
13566
|
socketRoot;
|
|
@@ -13641,6 +13642,17 @@ class AuthBroker {
|
|
|
13641
13642
|
}, probeMs);
|
|
13642
13643
|
this.consumerProbeTimer.unref();
|
|
13643
13644
|
}
|
|
13645
|
+
if (probeMs > 0 && process.env.SWITCHROOM_DISABLE_FLEET_QUOTA_PROBE !== "1") {
|
|
13646
|
+
this.fleetQuotaProbeTick().catch((err) => {
|
|
13647
|
+
this.logErr(`fleet-quota-probe (boot) threw: ${err.message}`);
|
|
13648
|
+
});
|
|
13649
|
+
this.fleetProbeTimer = setInterval(() => {
|
|
13650
|
+
this.fleetQuotaProbeTick().catch((err) => {
|
|
13651
|
+
this.logErr(`fleet-quota-probe threw: ${err.message}`);
|
|
13652
|
+
});
|
|
13653
|
+
}, probeMs);
|
|
13654
|
+
this.fleetProbeTimer.unref();
|
|
13655
|
+
}
|
|
13644
13656
|
}
|
|
13645
13657
|
const fanned = this.fanoutAll();
|
|
13646
13658
|
if (fanned.length > 0) {
|
|
@@ -13671,6 +13683,10 @@ class AuthBroker {
|
|
|
13671
13683
|
clearInterval(this.consumerProbeTimer);
|
|
13672
13684
|
this.consumerProbeTimer = null;
|
|
13673
13685
|
}
|
|
13686
|
+
if (this.fleetProbeTimer) {
|
|
13687
|
+
clearInterval(this.fleetProbeTimer);
|
|
13688
|
+
this.fleetProbeTimer = null;
|
|
13689
|
+
}
|
|
13674
13690
|
for (const [sock, lis] of this.listeners) {
|
|
13675
13691
|
try {
|
|
13676
13692
|
lis.server.close();
|
|
@@ -14096,22 +14112,42 @@ class AuthBroker {
|
|
|
14096
14112
|
ok: result.ok,
|
|
14097
14113
|
error: result.ok ? undefined : result.reason
|
|
14098
14114
|
});
|
|
14099
|
-
if (result.ok)
|
|
14100
|
-
this.
|
|
14101
|
-
fiveHourUtilizationPct: result.data.fiveHourUtilizationPct,
|
|
14102
|
-
sevenDayUtilizationPct: result.data.sevenDayUtilizationPct,
|
|
14103
|
-
fiveHourResetAt: result.data.fiveHourResetAt?.toISOString() ?? null,
|
|
14104
|
-
sevenDayResetAt: result.data.sevenDayResetAt?.toISOString() ?? null,
|
|
14105
|
-
representativeClaim: result.data.representativeClaim,
|
|
14106
|
-
overageStatus: result.data.overageStatus,
|
|
14107
|
-
overageDisabledReason: result.data.overageDisabledReason,
|
|
14108
|
-
capturedAt: this.now()
|
|
14109
|
-
};
|
|
14110
|
-
}
|
|
14115
|
+
if (result.ok)
|
|
14116
|
+
this.cacheQuotaSnapshot(label, result);
|
|
14111
14117
|
return { label, result };
|
|
14112
14118
|
}));
|
|
14113
14119
|
socket.write(encodeSuccess(id, { results }));
|
|
14114
14120
|
}
|
|
14121
|
+
cacheQuotaSnapshot(label, result) {
|
|
14122
|
+
if (!result.ok)
|
|
14123
|
+
return;
|
|
14124
|
+
this.lastQuotaCache[label] = {
|
|
14125
|
+
fiveHourUtilizationPct: result.data.fiveHourUtilizationPct,
|
|
14126
|
+
sevenDayUtilizationPct: result.data.sevenDayUtilizationPct,
|
|
14127
|
+
fiveHourResetAt: result.data.fiveHourResetAt?.toISOString() ?? null,
|
|
14128
|
+
sevenDayResetAt: result.data.sevenDayResetAt?.toISOString() ?? null,
|
|
14129
|
+
representativeClaim: result.data.representativeClaim,
|
|
14130
|
+
overageStatus: result.data.overageStatus,
|
|
14131
|
+
overageDisabledReason: result.data.overageDisabledReason,
|
|
14132
|
+
capturedAt: this.now()
|
|
14133
|
+
};
|
|
14134
|
+
}
|
|
14135
|
+
async fleetQuotaProbeTick() {
|
|
14136
|
+
for (const label of listAccounts(this.home)) {
|
|
14137
|
+
const creds = readAccountCredentials(label, this.home);
|
|
14138
|
+
const token = creds?.claudeAiOauth?.accessToken;
|
|
14139
|
+
if (!token)
|
|
14140
|
+
continue;
|
|
14141
|
+
let result;
|
|
14142
|
+
try {
|
|
14143
|
+
result = await this.fetchQuotaImpl({ accessToken: token });
|
|
14144
|
+
} catch (err) {
|
|
14145
|
+
this.logErr(`fleet-quota-probe ${label}: ${err.message}`);
|
|
14146
|
+
continue;
|
|
14147
|
+
}
|
|
14148
|
+
this.cacheQuotaSnapshot(label, result);
|
|
14149
|
+
}
|
|
14150
|
+
}
|
|
14115
14151
|
async consumerQuotaProbeTick() {
|
|
14116
14152
|
const accounts = Array.from(new Set((this.config.auth?.consumers ?? []).map((c) => c.account)));
|
|
14117
14153
|
for (const label of accounts) {
|