paseo-plugin-account-switcher 0.9.0 → 0.10.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/OVERVIEW.md +2 -2
- package/OVERVIEW.zh-CN.md +2 -2
- package/README.md +2 -2
- package/client/accounts.tsx +8 -6
- package/client/screens.ts +1 -1
- package/index.server.ts +4 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/paseo-plugin.json +1 -1
- package/server/controller.ts +27 -18
- package/server/launcher-artifact.ts +1 -1
- package/server/usage/index.ts +12 -5
- package/shared/contracts.ts +2 -2
package/server/usage/index.ts
CHANGED
|
@@ -11,7 +11,12 @@ export { readCredentialVersion } from "./credentials";
|
|
|
11
11
|
export type CollectedUsage = { identityKey: string | null; plan: string | null; windows: UsageWindow[]; models?: string[] | null; usageAllowed?: boolean | null };
|
|
12
12
|
export type FetchUsage = (account: QuotaAccount, signal?: AbortSignal) => Promise<CollectedUsage>;
|
|
13
13
|
export type AccountReadOptions = { verifyAccountId?: string };
|
|
14
|
-
export type UsageOptions = { getAccounts: (input?: AccountReadOptions) => Promise<QuotaAccount[]>; fetchUsage?: FetchUsage; cachePath?: string; now?: () => number };
|
|
14
|
+
export type UsageOptions = { getAccounts: (input?: AccountReadOptions) => Promise<QuotaAccount[]>; fetchUsage?: FetchUsage; cachePath?: string; now?: () => number; checksEnabled?: () => Promise<boolean> };
|
|
15
|
+
|
|
16
|
+
/** Paseo's Check usage host setting, from 0.15: only an explicit `false` turns it off, so a host that never wrote it stays on. */
|
|
17
|
+
export async function usageChecksEnabled(configPath: string): Promise<boolean> {
|
|
18
|
+
try {return JSON.parse(await readFile(configPath,"utf8"))?.daemon?.usage?.enabled!==false;} catch {return true;}
|
|
19
|
+
}
|
|
15
20
|
export class UsageError extends Error {
|
|
16
21
|
constructor(public readonly status: "needs_auth" | "unavailable", public readonly code: string, public readonly retryAfterMs?: number) {
|
|
17
22
|
super(status === "needs_auth" ? "Sign in again to retrieve limits." : "The limits service is temporarily unavailable.");
|
|
@@ -37,6 +42,7 @@ export function createUsageService(options: UsageOptions) {
|
|
|
37
42
|
const cached = new Map<string, {fingerprint: string; accountFingerprint?: string; snapshot: UsageSnapshot}>();
|
|
38
43
|
const now = options.now ?? Date.now;
|
|
39
44
|
const fetchUsage = options.fetchUsage ?? fetchProvider;
|
|
45
|
+
const checksEnabled = async () => {try {return await (options.checksEnabled?.() ?? true);} catch {return true;}};
|
|
40
46
|
let visibleUntil = -1;
|
|
41
47
|
let timer: ReturnType<typeof setInterval> | undefined;
|
|
42
48
|
let closed = false;
|
|
@@ -134,7 +140,8 @@ export function createUsageService(options: UsageOptions) {
|
|
|
134
140
|
const promise = (async () => {
|
|
135
141
|
await acquire();
|
|
136
142
|
try {
|
|
137
|
-
|
|
143
|
+
// A request that waited for its turn asks again: the setting may have been turned off since its round began.
|
|
144
|
+
if (closed || entries.get(account.id) !== entry || !await checksEnabled()) return;
|
|
138
145
|
entry.attemptedAt = now();
|
|
139
146
|
let result: CollectedUsage | undefined;
|
|
140
147
|
let failure: UsageError | undefined;
|
|
@@ -181,11 +188,11 @@ export function createUsageService(options: UsageOptions) {
|
|
|
181
188
|
const snapshots = (accounts: QuotaAccount[]) => accounts.map(a=>structuredClone(entries.get(a.id)?.snapshot??empty(a)));
|
|
182
189
|
async function refresh(accountId?: string): Promise<UsageSnapshot[]> {
|
|
183
190
|
const accounts=await sync();
|
|
184
|
-
await Promise.all(accounts.filter(account=>!accountId||account.id===accountId).map(refreshOne));
|
|
191
|
+
if(await checksEnabled())await Promise.all(accounts.filter(account=>!accountId||account.id===accountId).map(refreshOne));
|
|
185
192
|
return snapshots(await sync());
|
|
186
193
|
}
|
|
187
194
|
async function tick(): Promise<void> {
|
|
188
|
-
if(closed)return;
|
|
195
|
+
if(closed||!await checksEnabled())return;
|
|
189
196
|
const accounts=await sync();
|
|
190
197
|
const cadence=now()<visibleUntil?VISIBLE:BACKGROUND;
|
|
191
198
|
await Promise.all(accounts.filter(account=>{
|
|
@@ -221,5 +228,5 @@ export function createUsageService(options: UsageOptions) {
|
|
|
221
228
|
await Promise.allSettled([...flights.values()].map(flight=>flight.promise));
|
|
222
229
|
await writes;
|
|
223
230
|
}
|
|
224
|
-
return {list,refresh,start,close,invalidate};
|
|
231
|
+
return {list,refresh,start,close,invalidate,checksEnabled};
|
|
225
232
|
}
|
package/shared/contracts.ts
CHANGED
|
@@ -81,5 +81,5 @@ export const applySwitch = defineRpc({ name: "switch.apply", input: z.object({ a
|
|
|
81
81
|
// moves the agent from; the switch is refused when the agent no longer runs on it.
|
|
82
82
|
export const applyFailover = defineRpc({ name: "failover.apply", input: z.object({ agentId: z.string().min(1), accountId: z.string().min(1), rowId: z.string().min(1), fromId: z.string().min(1).optional() }), output: Empty });
|
|
83
83
|
export const setIntegration = defineRpc({ name: "integration.set", input: z.object({ enabled: z.boolean() }), output: StateSchema });
|
|
84
|
-
export const listUsage = defineRpc({ name: "usage.list", input: z.object({ visible: z.boolean().optional() }), output: z.object({ accounts: z.array(UsageSnapshotSchema) }) });
|
|
85
|
-
export const refreshUsage = defineRpc({ name: "usage.refresh", input: z.object({ accountId: z.string().optional() }), output: z.object({ accounts: z.array(UsageSnapshotSchema) }) });
|
|
84
|
+
export const listUsage = defineRpc({ name: "usage.list", input: z.object({ visible: z.boolean().optional() }), output: z.object({ accounts: z.array(UsageSnapshotSchema), checksOff: z.boolean().optional() }) });
|
|
85
|
+
export const refreshUsage = defineRpc({ name: "usage.refresh", input: z.object({ accountId: z.string().optional() }), output: z.object({ accounts: z.array(UsageSnapshotSchema), checksOff: z.boolean().optional() }) });
|