opencode-multi-account-core 0.2.7 → 0.2.9

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,33 +0,0 @@
1
- import type { ManagedAccount } from "./types";
2
- import type { FailoverCandidate, FailoverSkip, PoolChainConfig, PoolConfig } from "./pool-types";
3
- interface PoolAwareAccountManager {
4
- getAccounts(): ManagedAccount[];
5
- isRateLimited(account: ManagedAccount): boolean;
6
- selectAccount(): Promise<ManagedAccount | null>;
7
- }
8
- export interface BuildFailoverPlanOptions {
9
- attemptedAccounts?: Set<string>;
10
- visitedChainIndexes?: Set<number>;
11
- }
12
- export interface FailoverPlan {
13
- candidates: FailoverCandidate[];
14
- skips: FailoverSkip[];
15
- }
16
- export declare class PoolManager {
17
- private poolsByName;
18
- private exhaustedUntilByAccount;
19
- private exhaustedCooldownMs;
20
- constructor(options?: {
21
- exhaustedCooldownMs?: number;
22
- });
23
- loadPools(configs: PoolConfig[]): void;
24
- getPoolForAccount(accountUuid: string): PoolConfig | null;
25
- getAvailableMembers(pool: PoolConfig, accountManager: PoolAwareAccountManager): string[];
26
- markExhausted(accountUuid: string): void;
27
- getNextMember(pool: PoolConfig, currentUuid: string | undefined, accountManager: PoolAwareAccountManager): Promise<string | null>;
28
- buildFailoverPlan(currentAccount: Pick<ManagedAccount, "uuid" | "accountId"> | null, config: PoolChainConfig, accountManager: PoolAwareAccountManager, options?: BuildFailoverPlanOptions): Promise<FailoverPlan>;
29
- private isExhausted;
30
- private clearExpiredExhausted;
31
- private selectPreferredMember;
32
- }
33
- export {};
@@ -1,59 +0,0 @@
1
- import * as v from "valibot";
2
- export declare const PoolConfigSchema: v.ObjectSchema<{
3
- readonly name: v.StringSchema<undefined>;
4
- readonly baseProvider: v.StringSchema<undefined>;
5
- readonly members: v.ArraySchema<v.StringSchema<undefined>, undefined>;
6
- readonly enabled: v.BooleanSchema<undefined>;
7
- }, undefined>;
8
- export declare const ChainEntryConfigSchema: v.ObjectSchema<{
9
- readonly pool: v.StringSchema<undefined>;
10
- readonly model: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
11
- readonly enabled: v.BooleanSchema<undefined>;
12
- }, undefined>;
13
- export declare const ChainConfigSchema: v.ObjectSchema<{
14
- readonly name: v.StringSchema<undefined>;
15
- readonly entries: v.ArraySchema<v.ObjectSchema<{
16
- readonly pool: v.StringSchema<undefined>;
17
- readonly model: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
18
- readonly enabled: v.BooleanSchema<undefined>;
19
- }, undefined>, undefined>;
20
- readonly enabled: v.BooleanSchema<undefined>;
21
- }, undefined>;
22
- export declare const PoolChainConfigSchema: v.ObjectSchema<{
23
- readonly pools: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
24
- readonly name: v.StringSchema<undefined>;
25
- readonly baseProvider: v.StringSchema<undefined>;
26
- readonly members: v.ArraySchema<v.StringSchema<undefined>, undefined>;
27
- readonly enabled: v.BooleanSchema<undefined>;
28
- }, undefined>, undefined>, readonly []>;
29
- readonly chains: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
30
- readonly name: v.StringSchema<undefined>;
31
- readonly entries: v.ArraySchema<v.ObjectSchema<{
32
- readonly pool: v.StringSchema<undefined>;
33
- readonly model: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
34
- readonly enabled: v.BooleanSchema<undefined>;
35
- }, undefined>, undefined>;
36
- readonly enabled: v.BooleanSchema<undefined>;
37
- }, undefined>, undefined>, readonly []>;
38
- }, undefined>;
39
- export type PoolConfig = v.InferOutput<typeof PoolConfigSchema>;
40
- export type ChainEntryConfig = v.InferOutput<typeof ChainEntryConfigSchema>;
41
- export type ChainConfig = v.InferOutput<typeof ChainConfigSchema>;
42
- export type PoolChainConfig = v.InferOutput<typeof PoolChainConfigSchema>;
43
- export interface CascadeState {
44
- prompt: string;
45
- attemptedAccounts: Set<string>;
46
- visitedChainIndexes: Set<number>;
47
- }
48
- export interface FailoverCandidate {
49
- poolName: string;
50
- accountUuid: string;
51
- source: "pool" | "chain";
52
- chainIndex?: number;
53
- }
54
- export interface FailoverSkip {
55
- type: "pool_exhausted" | "chain_disabled" | "account_attempted" | "account_unavailable";
56
- poolName: string;
57
- reason: string;
58
- detail?: string;
59
- }
@@ -1,17 +0,0 @@
1
- import { AccountStore } from "./account-store";
2
- import type { PluginClient, PluginConfig, StoredAccount, TokenRefreshResult } from "./types";
3
- export interface ProactiveRefreshDependencies {
4
- providerAuthId: string;
5
- getConfig: () => PluginConfig;
6
- refreshToken: (currentRefreshToken: string, accountId: string, client: PluginClient) => Promise<TokenRefreshResult>;
7
- isTokenExpired: (account: Pick<StoredAccount, "accessToken" | "expiresAt">) => boolean;
8
- debugLog: (client: PluginClient, message: string, extra?: Record<string, unknown>) => void;
9
- }
10
- export interface ProactiveRefreshQueueInstance {
11
- start(): void;
12
- stop(): Promise<void>;
13
- }
14
- export interface ProactiveRefreshQueueClass {
15
- new (client: PluginClient, store: AccountStore, onInvalidate?: (uuid: string) => void): ProactiveRefreshQueueInstance;
16
- }
17
- export declare function createProactiveRefreshQueueForProvider(dependencies: ProactiveRefreshDependencies): ProactiveRefreshQueueClass;
@@ -1,25 +0,0 @@
1
- import type { ManagedAccount, PluginClient, PluginConfig, UsageLimits } from "./types";
2
- export interface RateLimitDependencies {
3
- fetchUsage: (accessToken: string, accountId?: string) => Promise<{
4
- ok: true;
5
- data: UsageLimits;
6
- } | {
7
- ok: false;
8
- reason: string;
9
- }>;
10
- getConfig: () => Pick<PluginConfig, "default_retry_after_ms">;
11
- formatWaitTime: (ms: number) => string;
12
- getAccountLabel: (account: ManagedAccount) => string;
13
- showToast: (client: PluginClient, message: string, variant: "info" | "warning" | "success" | "error") => Promise<void>;
14
- }
15
- export interface RateLimitAccountManager {
16
- markRateLimited(uuid: string, backoffMs?: number): Promise<void>;
17
- applyUsageCache(uuid: string, usage: UsageLimits): Promise<void>;
18
- getAccountCount(): number;
19
- }
20
- export declare function createRateLimitHandlers(dependencies: RateLimitDependencies): {
21
- retryAfterMsFromResponse: (response: Response) => number;
22
- getResetMsFromUsage: (account: ManagedAccount) => number | null;
23
- fetchUsageLimits: (accessToken: string, accountId?: string) => Promise<UsageLimits | null>;
24
- handleRateLimitResponse: (manager: RateLimitAccountManager, client: PluginClient, account: ManagedAccount, response: Response) => Promise<void>;
25
- };
package/dist/storage.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { AccountStorage, StoredAccount } from "./types";
2
- export declare function readStorageFromDisk(targetPath: string, backupOnCorrupt: boolean): Promise<AccountStorage | null>;
3
- export declare function deduplicateAccounts(accounts: StoredAccount[]): StoredAccount[];
4
- export declare function loadAccounts(): Promise<AccountStorage | null>;
package/dist/types.d.ts DELETED
@@ -1,193 +0,0 @@
1
- import * as v from "valibot";
2
- export declare const OAuthCredentialsSchema: v.ObjectSchema<{
3
- readonly type: v.LiteralSchema<"oauth", undefined>;
4
- readonly refresh: v.StringSchema<undefined>;
5
- readonly access: v.StringSchema<undefined>;
6
- readonly expires: v.NumberSchema<undefined>;
7
- }, undefined>;
8
- export declare const UsageLimitEntrySchema: v.ObjectSchema<{
9
- readonly utilization: v.NumberSchema<undefined>;
10
- readonly resets_at: v.NullableSchema<v.StringSchema<undefined>, undefined>;
11
- }, undefined>;
12
- export declare const UsageLimitsSchema: v.ObjectSchema<{
13
- readonly five_hour: v.OptionalSchema<v.NullableSchema<v.ObjectSchema<{
14
- readonly utilization: v.NumberSchema<undefined>;
15
- readonly resets_at: v.NullableSchema<v.StringSchema<undefined>, undefined>;
16
- }, undefined>, undefined>, null>;
17
- readonly seven_day: v.OptionalSchema<v.NullableSchema<v.ObjectSchema<{
18
- readonly utilization: v.NumberSchema<undefined>;
19
- readonly resets_at: v.NullableSchema<v.StringSchema<undefined>, undefined>;
20
- }, undefined>, undefined>, null>;
21
- readonly seven_day_sonnet: v.OptionalSchema<v.NullableSchema<v.ObjectSchema<{
22
- readonly utilization: v.NumberSchema<undefined>;
23
- readonly resets_at: v.NullableSchema<v.StringSchema<undefined>, undefined>;
24
- }, undefined>, undefined>, null>;
25
- }, undefined>;
26
- export declare const CredentialRefreshPatchSchema: v.ObjectSchema<{
27
- readonly accessToken: v.StringSchema<undefined>;
28
- readonly expiresAt: v.NumberSchema<undefined>;
29
- readonly refreshToken: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
30
- readonly uuid: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
31
- readonly accountId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
32
- readonly email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
33
- }, undefined>;
34
- export declare const StoredAccountSchema: v.ObjectSchema<{
35
- readonly uuid: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
36
- readonly accountId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
37
- readonly label: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
38
- readonly email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
39
- readonly planTier: v.OptionalSchema<v.StringSchema<undefined>, "">;
40
- readonly refreshToken: v.StringSchema<undefined>;
41
- readonly accessToken: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
42
- readonly expiresAt: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
43
- readonly addedAt: v.NumberSchema<undefined>;
44
- readonly lastUsed: v.NumberSchema<undefined>;
45
- readonly enabled: v.OptionalSchema<v.BooleanSchema<undefined>, true>;
46
- readonly rateLimitResetAt: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
47
- readonly cachedUsage: v.OptionalSchema<v.ObjectSchema<{
48
- readonly five_hour: v.OptionalSchema<v.NullableSchema<v.ObjectSchema<{
49
- readonly utilization: v.NumberSchema<undefined>;
50
- readonly resets_at: v.NullableSchema<v.StringSchema<undefined>, undefined>;
51
- }, undefined>, undefined>, null>;
52
- readonly seven_day: v.OptionalSchema<v.NullableSchema<v.ObjectSchema<{
53
- readonly utilization: v.NumberSchema<undefined>;
54
- readonly resets_at: v.NullableSchema<v.StringSchema<undefined>, undefined>;
55
- }, undefined>, undefined>, null>;
56
- readonly seven_day_sonnet: v.OptionalSchema<v.NullableSchema<v.ObjectSchema<{
57
- readonly utilization: v.NumberSchema<undefined>;
58
- readonly resets_at: v.NullableSchema<v.StringSchema<undefined>, undefined>;
59
- }, undefined>, undefined>, null>;
60
- }, undefined>, undefined>;
61
- readonly cachedUsageAt: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
62
- readonly consecutiveAuthFailures: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
63
- readonly isAuthDisabled: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
64
- readonly authDisabledReason: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
65
- }, undefined>;
66
- export declare const AccountStorageSchema: v.ObjectSchema<{
67
- readonly version: v.LiteralSchema<1, undefined>;
68
- readonly accounts: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
69
- readonly uuid: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
70
- readonly accountId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
71
- readonly label: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
72
- readonly email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
73
- readonly planTier: v.OptionalSchema<v.StringSchema<undefined>, "">;
74
- readonly refreshToken: v.StringSchema<undefined>;
75
- readonly accessToken: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
76
- readonly expiresAt: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
77
- readonly addedAt: v.NumberSchema<undefined>;
78
- readonly lastUsed: v.NumberSchema<undefined>;
79
- readonly enabled: v.OptionalSchema<v.BooleanSchema<undefined>, true>;
80
- readonly rateLimitResetAt: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
81
- readonly cachedUsage: v.OptionalSchema<v.ObjectSchema<{
82
- readonly five_hour: v.OptionalSchema<v.NullableSchema<v.ObjectSchema<{
83
- readonly utilization: v.NumberSchema<undefined>;
84
- readonly resets_at: v.NullableSchema<v.StringSchema<undefined>, undefined>;
85
- }, undefined>, undefined>, null>;
86
- readonly seven_day: v.OptionalSchema<v.NullableSchema<v.ObjectSchema<{
87
- readonly utilization: v.NumberSchema<undefined>;
88
- readonly resets_at: v.NullableSchema<v.StringSchema<undefined>, undefined>;
89
- }, undefined>, undefined>, null>;
90
- readonly seven_day_sonnet: v.OptionalSchema<v.NullableSchema<v.ObjectSchema<{
91
- readonly utilization: v.NumberSchema<undefined>;
92
- readonly resets_at: v.NullableSchema<v.StringSchema<undefined>, undefined>;
93
- }, undefined>, undefined>, null>;
94
- }, undefined>, undefined>;
95
- readonly cachedUsageAt: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
96
- readonly consecutiveAuthFailures: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
97
- readonly isAuthDisabled: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
98
- readonly authDisabledReason: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
99
- }, undefined>, undefined>, readonly []>;
100
- readonly activeAccountUuid: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
101
- }, undefined>;
102
- export declare const AccountSelectionStrategySchema: v.PicklistSchema<["sticky", "round-robin", "hybrid"], undefined>;
103
- export declare const PluginConfigSchema: v.ObjectSchema<{
104
- readonly account_selection_strategy: v.OptionalSchema<v.PicklistSchema<["sticky", "round-robin", "hybrid"], undefined>, "sticky">;
105
- readonly cross_process_claims: v.OptionalSchema<v.BooleanSchema<undefined>, true>;
106
- readonly soft_quota_threshold_percent: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 100, undefined>]>, 100>;
107
- readonly rate_limit_min_backoff_ms: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>, 30000>;
108
- readonly default_retry_after_ms: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>, 60000>;
109
- readonly max_consecutive_auth_failures: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>, 3>;
110
- readonly token_failure_backoff_ms: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>, 30000>;
111
- readonly proactive_refresh: v.OptionalSchema<v.BooleanSchema<undefined>, true>;
112
- readonly proactive_refresh_buffer_seconds: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 60, undefined>]>, 1800>;
113
- readonly proactive_refresh_interval_seconds: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 30, undefined>]>, 300>;
114
- readonly quiet_mode: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
115
- readonly debug: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
116
- }, undefined>;
117
- export type OAuthCredentials = v.InferOutput<typeof OAuthCredentialsSchema>;
118
- export type UsageLimitEntry = v.InferOutput<typeof UsageLimitEntrySchema>;
119
- export type UsageLimits = v.InferOutput<typeof UsageLimitsSchema>;
120
- export type CredentialRefreshPatch = v.InferOutput<typeof CredentialRefreshPatchSchema>;
121
- export type StoredAccount = v.InferOutput<typeof StoredAccountSchema>;
122
- export type AccountStorage = v.InferOutput<typeof AccountStorageSchema>;
123
- export type AccountSelectionStrategy = v.InferOutput<typeof AccountSelectionStrategySchema>;
124
- export type PluginConfig = v.InferOutput<typeof PluginConfigSchema>;
125
- export type TokenRefreshResult = {
126
- ok: true;
127
- patch: CredentialRefreshPatch;
128
- } | {
129
- ok: false;
130
- permanent: boolean;
131
- status?: number;
132
- };
133
- export declare class TokenRefreshError extends Error {
134
- readonly status?: number;
135
- readonly permanent: boolean;
136
- constructor(permanent: boolean, status?: number);
137
- }
138
- export declare function isTokenRefreshError(error: unknown): error is TokenRefreshError;
139
- export interface ManagedAccount {
140
- index: number;
141
- uuid?: string;
142
- accountId?: string;
143
- label?: string;
144
- email?: string;
145
- planTier?: string;
146
- refreshToken: string;
147
- accessToken?: string;
148
- expiresAt?: number;
149
- addedAt: number;
150
- lastUsed: number;
151
- enabled: boolean;
152
- rateLimitResetAt?: number;
153
- last429At?: number;
154
- cachedUsage?: UsageLimits;
155
- cachedUsageAt?: number;
156
- consecutiveAuthFailures: number;
157
- isAuthDisabled: boolean;
158
- authDisabledReason?: string;
159
- }
160
- export interface PluginClient {
161
- auth: {
162
- set: (params: {
163
- path: {
164
- id: string;
165
- };
166
- body: {
167
- type: string;
168
- refresh: string;
169
- access: string;
170
- expires: number;
171
- };
172
- }) => Promise<void>;
173
- };
174
- tui: {
175
- showToast: (params: {
176
- body: {
177
- title?: string;
178
- message: string;
179
- variant: "info" | "warning" | "success" | "error";
180
- };
181
- }) => Promise<void>;
182
- };
183
- app: {
184
- log: (params: {
185
- body: {
186
- service: string;
187
- level: "debug" | "info" | "warn" | "error";
188
- message: string;
189
- extra?: Record<string, unknown>;
190
- };
191
- }) => Promise<void>;
192
- };
193
- }
package/dist/ui/ansi.d.ts DELETED
@@ -1,17 +0,0 @@
1
- export declare const ANSI: {
2
- readonly hide: "\u001B[?25l";
3
- readonly show: "\u001B[?25h";
4
- readonly up: (n?: number) => string;
5
- readonly down: (n?: number) => string;
6
- readonly clearLine: "\u001B[2K";
7
- readonly cyan: "\u001B[36m";
8
- readonly green: "\u001B[32m";
9
- readonly red: "\u001B[31m";
10
- readonly yellow: "\u001B[33m";
11
- readonly dim: "\u001B[2m";
12
- readonly bold: "\u001B[1m";
13
- readonly reset: "\u001B[0m";
14
- };
15
- export type KeyAction = "up" | "down" | "enter" | "escape" | "escape-start" | null;
16
- export declare function parseKey(data: Buffer): KeyAction;
17
- export declare function isTTY(): boolean;
@@ -1 +0,0 @@
1
- export declare function confirm(message: string, defaultYes?: boolean): Promise<boolean>;
@@ -1,13 +0,0 @@
1
- export interface MenuItem<T = string> {
2
- label: string;
3
- value: T;
4
- hint?: string;
5
- disabled?: boolean;
6
- separator?: boolean;
7
- color?: "red" | "green" | "yellow" | "cyan";
8
- }
9
- export interface SelectOptions {
10
- message: string;
11
- subtitle?: string;
12
- }
13
- export declare function select<T>(items: MenuItem<T>[], options: SelectOptions): Promise<T | null>;
package/dist/utils.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import type { ManagedAccount, PluginClient } from "./types";
2
- export declare function getConfigDir(): string;
3
- export declare function getErrorCode(error: unknown): string | undefined;
4
- export declare function formatWaitTime(ms: number): string;
5
- export declare function getAccountLabel(account: ManagedAccount): string;
6
- export declare function sleep(ms: number): Promise<void>;
7
- export declare function showToast(client: PluginClient, message: string, variant: "info" | "warning" | "success" | "error"): Promise<void>;
8
- export declare function debugLog(client: PluginClient, message: string, extra?: Record<string, unknown>): void;
9
- export declare function createMinimalClient(): PluginClient;
10
- export declare function getClearedOAuthBody(): {
11
- type: "oauth";
12
- refresh: string;
13
- access: string;
14
- expires: number;
15
- };