@encoredigitalgroup/opencode 0.2.7 → 0.2.8
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/README.md +1 -1
- package/dist/lib/Quota/core/errors.d.ts +21 -0
- package/dist/lib/Quota/core/pace.d.ts +14 -0
- package/dist/lib/Quota/core/persist.d.ts +55 -0
- package/dist/lib/Quota/core/provider-source.d.ts +43 -0
- package/dist/lib/Quota/core/redact.d.ts +30 -0
- package/dist/lib/Quota/core/rows.d.ts +19 -0
- package/dist/lib/Quota/core/selection.d.ts +14 -0
- package/dist/lib/Quota/core/store.d.ts +99 -0
- package/dist/lib/Quota/core/types.d.ts +167 -0
- package/dist/lib/Quota/core/validate.d.ts +11 -0
- package/dist/lib/Quota/core/windows.d.ts +23 -0
- package/dist/lib/Quota/lib/accounting-format.d.ts +3 -0
- package/dist/lib/Quota/lib/anthropic.d.ts +113 -0
- package/dist/lib/Quota/lib/api-key-resolver.d.ts +124 -0
- package/dist/lib/Quota/lib/atomic-json.d.ts +13 -0
- package/dist/lib/Quota/lib/calendar-date.d.ts +14 -0
- package/dist/lib/Quota/lib/config-file-utils.d.ts +6 -0
- package/dist/lib/Quota/lib/config-write-target.d.ts +23 -0
- package/dist/lib/Quota/lib/cursor-pricing.d.ts +107 -0
- package/dist/lib/Quota/lib/display-sanitize.d.ts +11 -0
- package/dist/lib/Quota/lib/entries.d.ts +87 -0
- package/dist/lib/Quota/lib/env-template.d.ts +25 -0
- package/dist/lib/Quota/lib/file-lock.d.ts +20 -0
- package/dist/lib/Quota/lib/format-utils.d.ts +8 -0
- package/dist/lib/Quota/lib/home-dir-display.d.ts +6 -0
- package/dist/lib/Quota/lib/http.d.ts +95 -0
- package/dist/lib/Quota/lib/json-guards.d.ts +10 -0
- package/dist/lib/Quota/lib/modelsdev-pricing.d.ts +85 -0
- package/dist/lib/Quota/lib/openai.d.ts +65 -0
- package/dist/lib/Quota/lib/opencode-auth.d.ts +154 -0
- package/dist/lib/Quota/lib/opencode-config-files.d.ts +33 -0
- package/dist/lib/Quota/lib/opencode-db-path.d.ts +8 -0
- package/dist/lib/Quota/lib/opencode-runtime-paths.d.ts +16 -0
- package/dist/lib/Quota/lib/pricing-key.d.ts +55 -0
- package/dist/lib/Quota/lib/provider-availability.d.ts +12 -0
- package/dist/lib/Quota/lib/provider-metadata.d.ts +25 -0
- package/dist/lib/Quota/lib/provider-model-matching.d.ts +12 -0
- package/dist/lib/Quota/lib/provider-registration.d.ts +222 -0
- package/dist/lib/Quota/lib/quota-export-types.d.ts +101 -0
- package/dist/lib/Quota/lib/quota-export.d.ts +33 -0
- package/dist/lib/Quota/lib/quota-providers.d.ts +201 -0
- package/dist/lib/Quota/lib/resolved-auth-identity.d.ts +52 -0
- package/dist/lib/Quota/lib/runtime-provider-ids.d.ts +3 -0
- package/dist/lib/Quota/lib/token-buckets.d.ts +22 -0
- package/dist/lib/Quota/lib/types.d.ts +208 -0
- package/dist/lib/Quota/plugin.d.ts +8 -0
- package/dist/lib/Quota/providers/anthropic.d.ts +6 -0
- package/dist/lib/Quota/providers/contract.d.ts +104 -0
- package/dist/lib/Quota/providers/openai.d.ts +5 -0
- package/dist/lib/Quota/providers/registry.d.ts +6 -0
- package/dist/lib/Quota/providers/result-helpers.d.ts +37 -0
- package/dist/lib/Quota/providers/xai.d.ts +8 -0
- package/dist/lib/Quota/rpc.d.ts +50 -0
- package/dist/lib/Quota/settings/convert.d.ts +59 -0
- package/dist/lib/Quota/settings/file.d.ts +89 -0
- package/dist/lib/Quota/settings/index.d.ts +10 -0
- package/dist/lib/Quota/settings/live.d.ts +42 -0
- package/dist/lib/Quota/settings/schema.d.ts +638 -0
- package/dist/lib/Quota/tui/client.d.ts +56 -0
- package/dist/lib/Quota/tui/index.d.ts +5 -0
- package/dist/lib/Quota/tui/sidebar.d.ts +42 -0
- package/dist/lib/Quota/tui/theme.d.ts +43 -0
- package/dist/lib/Quota/view/columns.d.ts +14 -0
- package/dist/lib/Quota/view/format.d.ts +80 -0
- package/dist/lib/Quota/view/row-facts.d.ts +52 -0
- package/dist/lib/Quota/view/select.d.ts +68 -0
- package/dist/lib/Quota/view/text.d.ts +160 -0
- package/dist/server/index.js +9125 -35
- package/dist/tui/index.js +5926 -213
- package/package.json +7 -3
- package/dist/lib/FilePickerCommands.test.d.ts +0 -1
- package/dist/lib/TodoTracker.test.d.ts +0 -1
- package/dist/package.integration.test.d.ts +0 -1
- package/dist/server/index.test.d.ts +0 -1
- package/dist/tui/index.test.d.ts +0 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI (ChatGPT) quota fetcher
|
|
3
|
+
*
|
|
4
|
+
* Reads OpenCode's OpenAI OAuth logins and queries
|
|
5
|
+
* https://chatgpt.com/backend-api/wham/usage
|
|
6
|
+
*/
|
|
7
|
+
import type { FixedWindowProjectionEvidence } from "./entries.js";
|
|
8
|
+
import { type CredentialRow } from "./opencode-auth.js";
|
|
9
|
+
import { type ResolvedAuthIdentity } from "./resolved-auth-identity.js";
|
|
10
|
+
import type { QuotaError } from "./types.js";
|
|
11
|
+
type OpenAIWindowKind = "hourly" | "weekly" | "monthly";
|
|
12
|
+
type OpenAIWindowValue = {
|
|
13
|
+
percentRemaining: number;
|
|
14
|
+
resetTimeIso?: string;
|
|
15
|
+
fixedWindow?: FixedWindowProjectionEvidence;
|
|
16
|
+
};
|
|
17
|
+
type OpenAIWindows = Partial<Record<OpenAIWindowKind | "codeReview", OpenAIWindowValue>>;
|
|
18
|
+
export declare const OPENAI_AUTH_SOURCE_KEYS: readonly ["openai", "codex", "chatgpt"];
|
|
19
|
+
type OpenAIAuthSourceKey = (typeof OPENAI_AUTH_SOURCE_KEYS)[number];
|
|
20
|
+
export type OpenAIResult = {
|
|
21
|
+
success: true;
|
|
22
|
+
label: string;
|
|
23
|
+
windows: OpenAIWindows;
|
|
24
|
+
} | QuotaError;
|
|
25
|
+
/** A stored OpenAI login: one OpenCode could not return, or one with an access token. */
|
|
26
|
+
export type OpenAIOAuthLogin = {
|
|
27
|
+
state: "failed";
|
|
28
|
+
sourceKey: OpenAIAuthSourceKey;
|
|
29
|
+
error: string;
|
|
30
|
+
} | {
|
|
31
|
+
state: "configured";
|
|
32
|
+
sourceKey: OpenAIAuthSourceKey;
|
|
33
|
+
accessToken: string;
|
|
34
|
+
refreshToken?: string;
|
|
35
|
+
expiresAt?: number;
|
|
36
|
+
accountId?: string;
|
|
37
|
+
};
|
|
38
|
+
type ResolvedOpenAIOAuth = {
|
|
39
|
+
state: "none";
|
|
40
|
+
} | OpenAIOAuthLogin;
|
|
41
|
+
/** One row's OpenAI sign-in: `none` for a row that is not an OAuth login or has no token. */
|
|
42
|
+
export declare function resolveOpenAIOAuth(row: CredentialRow): ResolvedOpenAIOAuth;
|
|
43
|
+
/**
|
|
44
|
+
* The login OpenCode reports as active, the first of `openai`, `codex`, `chatgpt` with a token
|
|
45
|
+
* or a resolve error (cached briefly).
|
|
46
|
+
*/
|
|
47
|
+
export declare function readOpenAIAuthCached(): Promise<ResolvedOpenAIOAuth>;
|
|
48
|
+
/** A stored OpenAI login (OAuth or API key) with its OAuth sign-in, when it has one. */
|
|
49
|
+
export type OpenAILogin = {
|
|
50
|
+
row: CredentialRow;
|
|
51
|
+
oauth?: OpenAIOAuthLogin;
|
|
52
|
+
};
|
|
53
|
+
/** Every stored OpenAI login, OAuth and API key; a failed one stays so it shows as an error. */
|
|
54
|
+
export declare function readOpenAILogins(): Promise<OpenAILogin[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Who OpenAI is signed in as: each OAuth sign-in's account (or token), and each other login by
|
|
57
|
+
* its connection, since its rows do not depend on a secret. A failed login can't be told apart.
|
|
58
|
+
*/
|
|
59
|
+
export declare function openaiLoginsIdentity(logins: readonly OpenAILogin[]): Promise<ResolvedAuthIdentity | null>;
|
|
60
|
+
export declare function queryOpenAIQuota(options: {
|
|
61
|
+
auth: OpenAIOAuthLogin;
|
|
62
|
+
requestTimeoutMs?: number;
|
|
63
|
+
loginLabel?: string;
|
|
64
|
+
}): Promise<OpenAIResult>;
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode login reader
|
|
3
|
+
*
|
|
4
|
+
* Reads OpenCode 2 logins through the bound credential source. The server
|
|
5
|
+
* plugin binds its integration API (`ctx.integration`) in `setup`; the terminal
|
|
6
|
+
* command binds the read-only database reader in `opencode-auth-sqlite.ts`
|
|
7
|
+
* while one report runs; the TUI binds nothing, so a read there finds no login.
|
|
8
|
+
* Every read names the integration ids it needs, so OpenCode resolves (and may
|
|
9
|
+
* refresh) only those logins.
|
|
10
|
+
*/
|
|
11
|
+
import type { Plugin } from "@opencode/plugin";
|
|
12
|
+
export type CredentialRow = {
|
|
13
|
+
id: string;
|
|
14
|
+
integrationId: string;
|
|
15
|
+
label: string;
|
|
16
|
+
/**
|
|
17
|
+
* Whether OpenCode uses this login. The integration source marks, per
|
|
18
|
+
* integration id, the connection `connection.active(integrationId)` reports;
|
|
19
|
+
* the database reader marks the database's active row.
|
|
20
|
+
*/
|
|
21
|
+
active: boolean;
|
|
22
|
+
value: Record<string, unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* Why OpenCode could not return this login (for example a failed token
|
|
25
|
+
* refresh), as `<category>: <scrubbed detail>`. A failed row keeps its id,
|
|
26
|
+
* label and position, but its `value` is only `{ type: "api" | "oauth" | "external" }`;
|
|
27
|
+
* consumers show `resolveError` as a per-account error.
|
|
28
|
+
*/
|
|
29
|
+
resolveError?: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The OpenCode 2 connection methods a read can ask for: a stored API key or an OAuth
|
|
33
|
+
* sign-in. OpenCode's third method, `external` (an AWS profile, Azure CLI or gcloud
|
|
34
|
+
* login), keeps its secrets outside OpenCode, so no read asks for it.
|
|
35
|
+
*/
|
|
36
|
+
export type CredentialMethod = "key" | "oauth";
|
|
37
|
+
type ReadCredentialRowsOptions = {
|
|
38
|
+
/** Keep only connections using one of these methods; checked before OpenCode resolves them. */
|
|
39
|
+
methods?: readonly CredentialMethod[];
|
|
40
|
+
/** Read only the active connection of each integration id. */
|
|
41
|
+
firstOnly?: boolean;
|
|
42
|
+
};
|
|
43
|
+
type CredentialReadRequest = ReadCredentialRowsOptions & {
|
|
44
|
+
integrationIds: readonly string[];
|
|
45
|
+
};
|
|
46
|
+
export type CredentialSourceKind = "opencode-integration-api" | "sqlite";
|
|
47
|
+
/**
|
|
48
|
+
* Where logins come from. The two production sources: `ctx.integration` in the
|
|
49
|
+
* server plugin, and the terminal command's read-only reader of OpenCode's database.
|
|
50
|
+
*/
|
|
51
|
+
export type CredentialSource = {
|
|
52
|
+
kind: CredentialSourceKind;
|
|
53
|
+
readRows(request: CredentialReadRequest): Promise<CredentialRow[]>;
|
|
54
|
+
};
|
|
55
|
+
/** The parts of the server plugin's `ctx.integration` the reader uses. */
|
|
56
|
+
type CredentialIntegration = Pick<Plugin.Context["integration"], "list" | "connection">;
|
|
57
|
+
type CredentialFailureCategory = "refresh_failed" | "resolve_empty" | "active_failed";
|
|
58
|
+
type CredentialFailure = {
|
|
59
|
+
at: number;
|
|
60
|
+
category: CredentialFailureCategory;
|
|
61
|
+
detail: string;
|
|
62
|
+
integrationId: string;
|
|
63
|
+
label: string;
|
|
64
|
+
};
|
|
65
|
+
export type CredentialSourceDiagnostics = ({
|
|
66
|
+
state: "bound";
|
|
67
|
+
kind: CredentialSourceKind;
|
|
68
|
+
} | {
|
|
69
|
+
state: "unbound";
|
|
70
|
+
}) & {
|
|
71
|
+
lastListError?: {
|
|
72
|
+
at: number;
|
|
73
|
+
detail: string;
|
|
74
|
+
};
|
|
75
|
+
failures: Array<CredentialFailure & {
|
|
76
|
+
connectionId: string;
|
|
77
|
+
}>;
|
|
78
|
+
};
|
|
79
|
+
export declare function formatCredentialDisplayNames(providerName: string, credentials: ReadonlyArray<{
|
|
80
|
+
row: CredentialRow;
|
|
81
|
+
fallbackName: string;
|
|
82
|
+
numberUnnamed?: boolean;
|
|
83
|
+
}>): string[];
|
|
84
|
+
/**
|
|
85
|
+
* The database OpenCode keeps its logins in: the one resolved path, or none
|
|
86
|
+
* when `OPENCODE_DB` is `:memory:`. Inside OpenCode it is for diagnostics only
|
|
87
|
+
* (logins are read through OpenCode); the terminal command reads its logins
|
|
88
|
+
* from this file.
|
|
89
|
+
*/
|
|
90
|
+
export declare function getCredentialDatabasePaths(): string[];
|
|
91
|
+
/**
|
|
92
|
+
* Makes `source` the one reads use until the returned function unbinds it.
|
|
93
|
+
* Unbinding removes only this binding; the last binding still bound wins.
|
|
94
|
+
*/
|
|
95
|
+
export declare function bindCredentialSource(source: CredentialSource): () => void;
|
|
96
|
+
/** Drops cached logins, failed-login entries and the last `list()` error. */
|
|
97
|
+
export declare function notifyCredentialsChanged(): void;
|
|
98
|
+
export declare function getCredentialSourceDiagnostics(): CredentialSourceDiagnostics;
|
|
99
|
+
/** The credential source backed by the server plugin's `ctx.integration`. */
|
|
100
|
+
export declare function createIntegrationCredentialSource(integration: CredentialIntegration): CredentialSource;
|
|
101
|
+
/**
|
|
102
|
+
* The first row of each integration id, in order. Rows come active first, so these are the
|
|
103
|
+
* logins OpenCode uses.
|
|
104
|
+
*/
|
|
105
|
+
export declare function activeCredentialRows(rows: readonly CredentialRow[]): CredentialRow[];
|
|
106
|
+
/**
|
|
107
|
+
* An OAuth sign-in read from its credential row. `failed`: OpenCode could not return it (see
|
|
108
|
+
* `CredentialRow.resolveError`). Otherwise its tokens (trimmed; none when blank or not text),
|
|
109
|
+
* its expiry (a finite number), and every field as stored, for the fields one vendor knows.
|
|
110
|
+
*/
|
|
111
|
+
export type OAuthLogin = {
|
|
112
|
+
state: "failed";
|
|
113
|
+
error: string;
|
|
114
|
+
} | {
|
|
115
|
+
state: "signed-in";
|
|
116
|
+
accessToken?: string;
|
|
117
|
+
refreshToken?: string;
|
|
118
|
+
expiresAt?: number;
|
|
119
|
+
fields: Readonly<Record<string, unknown>>;
|
|
120
|
+
};
|
|
121
|
+
/** The OAuth sign-in a row holds; null for a row of another method. */
|
|
122
|
+
export declare function readOAuthLogin(row: CredentialRow): OAuthLogin | null;
|
|
123
|
+
/**
|
|
124
|
+
* Credential rows of the requested integration ids from the last bound source.
|
|
125
|
+
* Row order depends on the source: the integration API returns request-id
|
|
126
|
+
* order, then OpenCode's connection order (active first, then newest); the
|
|
127
|
+
* database reader returns database order. With no bound source (the TUI) there
|
|
128
|
+
* are none.
|
|
129
|
+
*/
|
|
130
|
+
export declare function readCredentialRows(integrationIds: readonly string[], options?: ReadCredentialRowsOptions): Promise<CredentialRow[]>;
|
|
131
|
+
/**
|
|
132
|
+
* Collapse credential rows that represent the same upstream connection.
|
|
133
|
+
*
|
|
134
|
+
* Rows holding identical credential values are the same connection (e.g. the
|
|
135
|
+
* same workspace key stored under the `opencode-go` integration and its legacy
|
|
136
|
+
* `opencode` alias), and rows under `primaryIntegrationId` take precedence over
|
|
137
|
+
* alias rows so a real credential for another integration that shares the key
|
|
138
|
+
* is not reported as an additional connection. A failed row holds only
|
|
139
|
+
* `{ type }`, so its connection id keeps each failed login a row of its own.
|
|
140
|
+
* Input order is preserved otherwise.
|
|
141
|
+
*/
|
|
142
|
+
export declare function selectConnectionCredentialRows(rows: readonly CredentialRow[], primaryIntegrationId: string): CredentialRow[];
|
|
143
|
+
/**
|
|
144
|
+
* The active login of each requested integration id (a `firstOnly` read), cached for
|
|
145
|
+
* `maxAgeMs`: per-question hooks read often, and login changes still show quickly.
|
|
146
|
+
*/
|
|
147
|
+
export declare function readActiveCredentialRowsCached(params: {
|
|
148
|
+
maxAgeMs: number;
|
|
149
|
+
integrationIds: readonly string[];
|
|
150
|
+
methods?: readonly CredentialMethod[];
|
|
151
|
+
}): Promise<CredentialRow[]>;
|
|
152
|
+
/** Test helper to clear cached logins between test cases. */
|
|
153
|
+
export declare function clearCredentialRowCacheForTests(): void;
|
|
154
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type ConfigFileFormat = "json" | "jsonc";
|
|
2
|
+
export interface EditableConfigPath {
|
|
3
|
+
path: string;
|
|
4
|
+
format: ConfigFileFormat;
|
|
5
|
+
existed: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** One config file that exists and parses to an object. */
|
|
8
|
+
export interface OpenCodeConfigDocument {
|
|
9
|
+
path: string;
|
|
10
|
+
config: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The OpenCode config files that count for a session in `directory`, lowest priority first.
|
|
14
|
+
* They may not exist.
|
|
15
|
+
*/
|
|
16
|
+
export declare function openCodeConfigFiles(directory: string): string[];
|
|
17
|
+
/** The config files that count for `directory` and exist, lowest priority first. */
|
|
18
|
+
export declare function existingOpenCodeConfigFiles(directory: string): string[];
|
|
19
|
+
/**
|
|
20
|
+
* OpenCode config text as OpenCode parses it: comments and trailing commas are allowed in both
|
|
21
|
+
* kinds. Null when it does not parse or is not an object; OpenCode then ignores the file.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseOpenCodeConfig(text: string): Record<string, unknown> | null;
|
|
24
|
+
/**
|
|
25
|
+
* The config files that count for `directory`, read and parsed, lowest priority first. A file
|
|
26
|
+
* that is missing, unreadable or does not parse is left out.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readOpenCodeConfigs(directory: string): Promise<OpenCodeConfigDocument[]>;
|
|
29
|
+
/**
|
|
30
|
+
* The global file OpenCode writes its own settings to: opencode.jsonc when it is a file, else
|
|
31
|
+
* opencode.json when it is one, else a new opencode.jsonc.
|
|
32
|
+
*/
|
|
33
|
+
export declare function globalConfigWriteTarget(): EditableConfigPath;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode's SQLite database path, resolved the way OpenCode 2 does
|
|
3
|
+
* (`packages/cli/src/database-path.ts`): `OPENCODE_DB` (absolute, or relative
|
|
4
|
+
* to the data dir; `:memory:` passes through), else `<data dir>/opencode.db`.
|
|
5
|
+
*
|
|
6
|
+
* Credentials, sessions, and messages all live in this one database.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getOpenCodeDbPath(): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface OpencodeRuntimeDirs {
|
|
2
|
+
dataDir: string;
|
|
3
|
+
configDir: string;
|
|
4
|
+
cacheDir: string;
|
|
5
|
+
stateDir: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* OpenCode 2's global dirs (oc2 packages/util/src/global-roots.ts): one dir per
|
|
9
|
+
* kind on every platform, `$XDG_<KIND>_HOME/opencode` or the XDG default under
|
|
10
|
+
* the home dir. `OPENCODE_CONFIG_DIR` replaces the config dir
|
|
11
|
+
* (oc2 packages/cli/src/index.ts `Global.layerWith({ config })`).
|
|
12
|
+
*/
|
|
13
|
+
export declare function getOpencodeRuntimeDirs(params?: {
|
|
14
|
+
env?: NodeJS.ProcessEnv;
|
|
15
|
+
homeDir?: string;
|
|
16
|
+
}): OpencodeRuntimeDirs;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { TokenBuckets } from "./token-buckets.js";
|
|
2
|
+
type PricedKey = {
|
|
3
|
+
provider: string;
|
|
4
|
+
model: string;
|
|
5
|
+
};
|
|
6
|
+
type UnknownKey = {
|
|
7
|
+
sourceProviderID: string;
|
|
8
|
+
sourceModelID: string;
|
|
9
|
+
mappedProvider?: string;
|
|
10
|
+
mappedModel?: string;
|
|
11
|
+
normalizedModelID?: string;
|
|
12
|
+
providerCandidates?: string[];
|
|
13
|
+
reason?: "missing_model" | "missing_provider" | "ambiguous_model";
|
|
14
|
+
};
|
|
15
|
+
type PricingResolution = {
|
|
16
|
+
ok: true;
|
|
17
|
+
key: PricedKey;
|
|
18
|
+
method: "source_provider" | "model_prefix" | "unique_model" | "alias_fallback" | "cursor_local" | "cursor_api_alias";
|
|
19
|
+
} | {
|
|
20
|
+
ok: false;
|
|
21
|
+
unknown: UnknownKey;
|
|
22
|
+
};
|
|
23
|
+
export declare function resolvePricingKey(source: {
|
|
24
|
+
providerID?: string;
|
|
25
|
+
modelID?: string;
|
|
26
|
+
}): PricingResolution;
|
|
27
|
+
/**
|
|
28
|
+
* What one message costs: in USD in all and per token kind, with what its cache reads saved
|
|
29
|
+
* against the plain input price. "unpriced" is a known model without a price for this message,
|
|
30
|
+
* "unknown" no usable match.
|
|
31
|
+
*/
|
|
32
|
+
export type MessagePrice = {
|
|
33
|
+
kind: "priced";
|
|
34
|
+
key: PricedKey;
|
|
35
|
+
usd: number;
|
|
36
|
+
byKind: TokenBuckets;
|
|
37
|
+
cacheSavingsUsd: number;
|
|
38
|
+
} | {
|
|
39
|
+
kind: "unpriced";
|
|
40
|
+
key: PricedKey;
|
|
41
|
+
} | {
|
|
42
|
+
kind: "unknown";
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* What one message of `source` costs. Automatic matching (models.dev, Cursor's own table)
|
|
46
|
+
* wins; `modelMap` (exact source model id → models.dev "provider/model") prices only a model
|
|
47
|
+
* automatic matching cannot.
|
|
48
|
+
*/
|
|
49
|
+
export declare function priceMessage(source: {
|
|
50
|
+
providerID?: string;
|
|
51
|
+
modelID?: string;
|
|
52
|
+
}, tokens: TokenBuckets, options?: {
|
|
53
|
+
modelMap?: Readonly<Record<string, string>>;
|
|
54
|
+
}): MessagePrice;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { QuotaProviderContext } from "./entries.js";
|
|
2
|
+
import { type CanonicalQuotaProviderId } from "./provider-metadata.js";
|
|
3
|
+
export declare function isAnyProviderIdAvailable(params: {
|
|
4
|
+
ctx: Pick<QuotaProviderContext, "resolveRuntimeProviderIds">;
|
|
5
|
+
candidateIds: readonly string[];
|
|
6
|
+
fallbackOnError: boolean;
|
|
7
|
+
}): Promise<boolean>;
|
|
8
|
+
export declare function isCanonicalProviderAvailable(params: {
|
|
9
|
+
ctx: Pick<QuotaProviderContext, "resolveRuntimeProviderIds">;
|
|
10
|
+
providerId: CanonicalQuotaProviderId;
|
|
11
|
+
fallbackOnError: boolean;
|
|
12
|
+
}): Promise<boolean>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type CanonicalQuotaProviderId } from "./provider-registration.js";
|
|
2
|
+
export type { CanonicalQuotaProviderId } from "./provider-registration.js";
|
|
3
|
+
interface QuotaProviderCatalogEntry {
|
|
4
|
+
label: string;
|
|
5
|
+
labelAliases: readonly string[];
|
|
6
|
+
runtimeIds: readonly string[];
|
|
7
|
+
synonyms: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
/** Every provider in registration order. */
|
|
10
|
+
export declare const QUOTA_PROVIDER_CATALOG: Readonly<Record<CanonicalQuotaProviderId, QuotaProviderCatalogEntry>>;
|
|
11
|
+
export declare const QUOTA_PROVIDER_RUNTIME_IDS: Readonly<Record<CanonicalQuotaProviderId, readonly string[]>>;
|
|
12
|
+
/** The v6 row keys each provider may emit; see `rowKeys` in provider-registration.ts. */
|
|
13
|
+
export declare const PROVIDER_ROW_KEYS: Readonly<Record<CanonicalQuotaProviderId, readonly string[]>>;
|
|
14
|
+
/** Trimmed, lowercase, and a synonym ("claude") turned into its provider id ("anthropic"). */
|
|
15
|
+
export declare function normalizeQuotaProviderId(id: string): string;
|
|
16
|
+
/** The provider id for an id or synonym ("claude" → "anthropic"); none for an unknown id. */
|
|
17
|
+
export declare function getCanonicalQuotaProviderId(id: string): CanonicalQuotaProviderId | undefined;
|
|
18
|
+
/** The provider's label; an unknown id is shown as given. */
|
|
19
|
+
export declare function getQuotaProviderDisplayLabel(id: string): string;
|
|
20
|
+
/** The OpenCode provider ids that count as this provider (narrower than its synonyms). */
|
|
21
|
+
export declare function getQuotaProviderRuntimeIds(id: string): readonly string[];
|
|
22
|
+
export declare function getQuotaProviderIdsForRuntimeId(id: string): readonly CanonicalQuotaProviderId[];
|
|
23
|
+
/** Brand words at the start of the provider's account names; none for an unknown id. */
|
|
24
|
+
export declare function getQuotaProviderGroupBrands(providerId: string): readonly string[];
|
|
25
|
+
export declare function isLiveLocalUsageProviderId(id: string): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CanonicalQuotaProviderId } from "./provider-metadata.js";
|
|
2
|
+
interface ProviderModelRef {
|
|
3
|
+
lower: string;
|
|
4
|
+
providerId: string;
|
|
5
|
+
modelId: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function parseProviderModelRef(model: string): ProviderModelRef;
|
|
8
|
+
export declare function providerIdIncludesAny(providerId: string, fragments: readonly string[]): boolean;
|
|
9
|
+
export declare function modelProviderIncludesAny(model: string, fragments: readonly string[]): boolean;
|
|
10
|
+
export declare function modelProviderMatchesRuntimeId(model: string, canonicalId: CanonicalQuotaProviderId): boolean;
|
|
11
|
+
export declare function modelIncludesAny(model: string, fragments: readonly string[]): boolean;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every surface knows about each built-in provider, in display order: its names, the
|
|
3
|
+
* OpenCode ids that count as it, its row keys and where its API key lives. No fetch code, so
|
|
4
|
+
* the TUI may import it. The provider itself is `src/providers/<vendor>.ts`, bound to its id in
|
|
5
|
+
* `src/providers/registry.ts`; the compiler checks that every id here has one.
|
|
6
|
+
*/
|
|
7
|
+
import type { ApiKeyLoginSpec } from "./api-key-resolver.js";
|
|
8
|
+
export interface QuotaProviderRegistrationSourceEntry {
|
|
9
|
+
id: string;
|
|
10
|
+
label: string;
|
|
11
|
+
labelAliases?: readonly string[];
|
|
12
|
+
runtimeIds: readonly string[];
|
|
13
|
+
synonyms: readonly string[];
|
|
14
|
+
liveLocalUsage?: true;
|
|
15
|
+
/** Brand words at the start of its account names ("Claude Work" → "Work"). Default: its label. */
|
|
16
|
+
groupBrands?: readonly string[];
|
|
17
|
+
/**
|
|
18
|
+
* The v6 row keys it may emit (`${id}.${key}` is the row id that hide, rename and order
|
|
19
|
+
* settings use). `*` stands for one segment taken from provider data, such as a model, a
|
|
20
|
+
* window family or a currency. Changing a key breaks users' settings.
|
|
21
|
+
*/
|
|
22
|
+
rowKeys: readonly string[];
|
|
23
|
+
/**
|
|
24
|
+
* Where its API key may live (see `API_KEY_VENDORS`). `displayName` defaults to its label,
|
|
25
|
+
* `authKeys` to its `providerKeys`.
|
|
26
|
+
*/
|
|
27
|
+
apiKey?: Omit<ApiKeyLoginSpec, "displayName" | "authKeys"> & Partial<Pick<ApiKeyLoginSpec, "displayName" | "authKeys">>;
|
|
28
|
+
}
|
|
29
|
+
export declare const QUOTA_PROVIDER_REGISTRATION_SOURCE: readonly [{
|
|
30
|
+
readonly id: "anthropic";
|
|
31
|
+
readonly label: "Anthropic";
|
|
32
|
+
readonly runtimeIds: readonly ["anthropic"];
|
|
33
|
+
readonly synonyms: readonly ["claude", "claude-code"];
|
|
34
|
+
readonly groupBrands: readonly ["Claude"];
|
|
35
|
+
readonly rowKeys: readonly ["five_hour", "weekly", "weekly_fable", "extra_usage"];
|
|
36
|
+
}, {
|
|
37
|
+
readonly id: "copilot";
|
|
38
|
+
readonly label: "Copilot";
|
|
39
|
+
readonly runtimeIds: readonly ["copilot", "github-copilot", "copilot-chat", "github-copilot-chat"];
|
|
40
|
+
readonly synonyms: readonly ["github-copilot", "copilot-chat", "github-copilot-chat"];
|
|
41
|
+
readonly rowKeys: readonly ["allowance", "additional_budget"];
|
|
42
|
+
}, {
|
|
43
|
+
readonly id: "openai";
|
|
44
|
+
readonly label: "OpenAI";
|
|
45
|
+
readonly runtimeIds: readonly ["openai", "chatgpt", "codex"];
|
|
46
|
+
readonly synonyms: readonly [];
|
|
47
|
+
readonly rowKeys: readonly ["five_hour", "weekly", "monthly", "code_review", "status"];
|
|
48
|
+
}, {
|
|
49
|
+
readonly id: "openrouter";
|
|
50
|
+
readonly label: "OpenRouter";
|
|
51
|
+
readonly runtimeIds: readonly ["openrouter"];
|
|
52
|
+
readonly synonyms: readonly [];
|
|
53
|
+
readonly rowKeys: readonly ["key"];
|
|
54
|
+
}, {
|
|
55
|
+
readonly id: "cursor";
|
|
56
|
+
readonly label: "Cursor";
|
|
57
|
+
readonly runtimeIds: readonly ["cursor", "cursor-acp"];
|
|
58
|
+
readonly synonyms: readonly ["cursor-acp", "open-cursor", "@rama_nigg/open-cursor"];
|
|
59
|
+
readonly liveLocalUsage: true;
|
|
60
|
+
readonly rowKeys: readonly ["api", "auto_composer"];
|
|
61
|
+
}, {
|
|
62
|
+
readonly id: "alibaba-coding-plan";
|
|
63
|
+
readonly label: "Alibaba Coding Plan";
|
|
64
|
+
readonly runtimeIds: readonly ["alibaba-coding-plan"];
|
|
65
|
+
readonly synonyms: readonly ["alibaba"];
|
|
66
|
+
readonly liveLocalUsage: true;
|
|
67
|
+
readonly rowKeys: readonly ["five_hour", "weekly", "monthly"];
|
|
68
|
+
readonly apiKey: {
|
|
69
|
+
readonly envVars: readonly ["ALIBABA_CODING_PLAN_API_KEY", "ALIBABA_API_KEY"];
|
|
70
|
+
readonly providerKeys: readonly ["alibaba-coding-plan", "alibaba"];
|
|
71
|
+
};
|
|
72
|
+
}, {
|
|
73
|
+
readonly id: "alibaba-token-plan";
|
|
74
|
+
readonly label: "Alibaba Personal Token Plan";
|
|
75
|
+
readonly runtimeIds: readonly ["alibaba-token-plan"];
|
|
76
|
+
readonly synonyms: readonly [];
|
|
77
|
+
readonly rowKeys: readonly ["five_hour", "weekly"];
|
|
78
|
+
}, {
|
|
79
|
+
readonly id: "google-gemini-cli";
|
|
80
|
+
readonly label: "Gemini CLI";
|
|
81
|
+
readonly runtimeIds: readonly ["google-gemini-cli", "gemini-cli", "gemini", "opencode-gemini-auth", "google"];
|
|
82
|
+
readonly synonyms: readonly ["gemini-cli", "google-gemini", "opencode-gemini-auth", "gemini"];
|
|
83
|
+
readonly rowKeys: readonly ["pro", "flash", "flash_lite", "model.*"];
|
|
84
|
+
}, {
|
|
85
|
+
readonly id: "google-agy";
|
|
86
|
+
readonly label: "Google AGY";
|
|
87
|
+
readonly runtimeIds: readonly ["google-agy", "opencode-agy-auth", "google-agy-auth"];
|
|
88
|
+
readonly synonyms: readonly ["opencode-agy-auth", "google-agy-auth"];
|
|
89
|
+
readonly groupBrands: readonly ["Google AGY", "AGY"];
|
|
90
|
+
readonly rowKeys: readonly ["gemini.weekly", "gemini.five_hour", "claude_gpt.weekly", "claude_gpt.five_hour", "*.weekly", "*.five_hour"];
|
|
91
|
+
}, {
|
|
92
|
+
readonly id: "zai";
|
|
93
|
+
readonly label: "Z.ai";
|
|
94
|
+
readonly runtimeIds: readonly ["zai", "glm", "zai-coding-plan"];
|
|
95
|
+
readonly synonyms: readonly [];
|
|
96
|
+
readonly rowKeys: readonly ["five_hour", "weekly", "mcp"];
|
|
97
|
+
readonly apiKey: {
|
|
98
|
+
readonly envVars: readonly ["ZAI_API_KEY", "ZAI_CODING_PLAN_API_KEY"];
|
|
99
|
+
readonly providerKeys: readonly ["zai", "zai-coding-plan", "glm"];
|
|
100
|
+
readonly authKeys: readonly ["zai-coding-plan"];
|
|
101
|
+
};
|
|
102
|
+
}, {
|
|
103
|
+
readonly id: "zhipu";
|
|
104
|
+
readonly label: "Zhipu";
|
|
105
|
+
readonly runtimeIds: readonly ["zhipu", "glm-coding-plan", "zhipu-coding-plan", "zhipuai-coding-plan"];
|
|
106
|
+
readonly synonyms: readonly ["glm-coding-plan", "zhipu-coding-plan", "zhipuai-coding-plan"];
|
|
107
|
+
readonly rowKeys: readonly ["five_hour", "weekly", "mcp"];
|
|
108
|
+
readonly apiKey: {
|
|
109
|
+
readonly envVars: readonly ["ZHIPU_API_KEY", "ZHIPU_CODING_PLAN_API_KEY"];
|
|
110
|
+
readonly providerKeys: readonly ["zhipu", "zhipu-coding-plan", "zhipuai-coding-plan", "glm-coding-plan"];
|
|
111
|
+
readonly authKeys: readonly ["zhipu-coding-plan", "zhipuai-coding-plan"];
|
|
112
|
+
};
|
|
113
|
+
}, {
|
|
114
|
+
readonly id: "minimax-coding-plan";
|
|
115
|
+
readonly label: "MiniMax Token Plan";
|
|
116
|
+
readonly runtimeIds: readonly ["minimax-coding-plan", "minimax"];
|
|
117
|
+
readonly synonyms: readonly ["minimax"];
|
|
118
|
+
readonly rowKeys: readonly ["five_hour", "weekly"];
|
|
119
|
+
readonly apiKey: {
|
|
120
|
+
readonly displayName: "MiniMax";
|
|
121
|
+
readonly envVars: readonly ["MINIMAX_CODING_PLAN_API_KEY", "MINIMAX_API_KEY"];
|
|
122
|
+
readonly providerKeys: readonly ["minimax-coding-plan", "minimax"];
|
|
123
|
+
readonly authKeys: readonly ["minimax-coding-plan"];
|
|
124
|
+
};
|
|
125
|
+
}, {
|
|
126
|
+
readonly id: "minimax-china-coding-plan";
|
|
127
|
+
readonly label: "MiniMax Token Plan (CN)";
|
|
128
|
+
readonly labelAliases: readonly ["minimax-cn-coding-plan"];
|
|
129
|
+
readonly runtimeIds: readonly ["minimax-china-coding-plan", "minimax-cn-coding-plan", "minimax-cn", "minimax-china"];
|
|
130
|
+
readonly synonyms: readonly ["minimax-cn", "minimax-china", "minimax-cn-coding-plan"];
|
|
131
|
+
readonly groupBrands: readonly ["MiniMax Token Plan (CN)", "MiniMax Token Plan"];
|
|
132
|
+
readonly rowKeys: readonly ["five_hour", "weekly"];
|
|
133
|
+
readonly apiKey: {
|
|
134
|
+
readonly displayName: "MiniMax";
|
|
135
|
+
readonly envVars: readonly ["MINIMAX_CHINA_CODING_PLAN_API_KEY"];
|
|
136
|
+
readonly providerKeys: readonly ["minimax-china-coding-plan", "minimax-cn-coding-plan", "minimax-cn", "minimax-china"];
|
|
137
|
+
readonly authKeys: readonly ["minimax-china-coding-plan", "minimax-cn-coding-plan"];
|
|
138
|
+
};
|
|
139
|
+
}, {
|
|
140
|
+
readonly id: "kimi-code-plan-global";
|
|
141
|
+
readonly label: "Kimi Code";
|
|
142
|
+
readonly runtimeIds: readonly ["kimi-code-plan-global"];
|
|
143
|
+
readonly synonyms: readonly [];
|
|
144
|
+
readonly rowKeys: readonly ["weekly", "limit.*"];
|
|
145
|
+
readonly apiKey: {
|
|
146
|
+
readonly displayName: "Kimi";
|
|
147
|
+
readonly envVars: readonly ["KIMI_GLOBAL_API_KEY"];
|
|
148
|
+
readonly providerKeys: readonly ["kimi-code-plan-global"];
|
|
149
|
+
};
|
|
150
|
+
}, {
|
|
151
|
+
readonly id: "kimi-code-plan-cn";
|
|
152
|
+
readonly label: "Kimi Code (CN)";
|
|
153
|
+
readonly labelAliases: readonly ["kimi-code"];
|
|
154
|
+
readonly runtimeIds: readonly ["kimi-code-plan-cn", "kimi-for-coding", "kimi", "kimi-code"];
|
|
155
|
+
readonly synonyms: readonly ["kimi", "kimi-for-code", "kimi-code", "kimi-for-coding"];
|
|
156
|
+
readonly groupBrands: readonly ["Kimi Code (CN)", "Kimi Code"];
|
|
157
|
+
readonly rowKeys: readonly ["weekly", "limit.*"];
|
|
158
|
+
readonly apiKey: {
|
|
159
|
+
readonly displayName: "Kimi";
|
|
160
|
+
readonly envVars: readonly ["KIMI_CN_API_KEY", "KIMI_API_KEY", "KIMI_CODE_API_KEY"];
|
|
161
|
+
readonly providerKeys: readonly ["kimi-code-plan-cn", "kimi-for-coding", "kimi-code", "kimi"];
|
|
162
|
+
};
|
|
163
|
+
}, {
|
|
164
|
+
readonly id: "deepseek";
|
|
165
|
+
readonly label: "DeepSeek";
|
|
166
|
+
readonly runtimeIds: readonly ["deepseek"];
|
|
167
|
+
readonly synonyms: readonly ["deep-seek"];
|
|
168
|
+
readonly rowKeys: readonly ["total_balance.*", "granted_balance.*", "topped_up_balance.*", "available"];
|
|
169
|
+
readonly apiKey: {
|
|
170
|
+
readonly envVars: readonly ["DEEPSEEK_API_KEY"];
|
|
171
|
+
readonly providerKeys: readonly ["deepseek"];
|
|
172
|
+
readonly skipBrokenLogins: true;
|
|
173
|
+
};
|
|
174
|
+
}, {
|
|
175
|
+
readonly id: "xai";
|
|
176
|
+
readonly label: "xAI";
|
|
177
|
+
readonly runtimeIds: readonly ["xai"];
|
|
178
|
+
readonly synonyms: readonly [];
|
|
179
|
+
readonly rowKeys: readonly ["credits"];
|
|
180
|
+
}, {
|
|
181
|
+
readonly id: "xiaomi";
|
|
182
|
+
readonly label: "Xiaomi MiMo";
|
|
183
|
+
readonly runtimeIds: readonly ["xiaomi", "xiaomi-token-plan-cn", "xiaomi-token-plan-ams", "xiaomi-token-plan-sgp"];
|
|
184
|
+
readonly synonyms: readonly ["xiaomi-token-plan-cn", "xiaomi-token-plan-ams", "xiaomi-token-plan-sgp"];
|
|
185
|
+
readonly rowKeys: readonly ["monthly_tokens", "total_balance", "cash_balance", "gift_balance"];
|
|
186
|
+
}, {
|
|
187
|
+
readonly id: "opencode-go";
|
|
188
|
+
readonly label: "OpenCode Go";
|
|
189
|
+
readonly runtimeIds: readonly ["opencode-go"];
|
|
190
|
+
readonly synonyms: readonly ["opencode-go-subscription"];
|
|
191
|
+
readonly rowKeys: readonly ["five_hour", "weekly", "monthly"];
|
|
192
|
+
readonly apiKey: {
|
|
193
|
+
readonly envVars: readonly ["OPENCODE_API_KEY"];
|
|
194
|
+
readonly providerKeys: readonly ["opencode-go", "opencode"];
|
|
195
|
+
readonly keyLoginsOnly: true;
|
|
196
|
+
readonly unsupportedTypeError: "OpenCode Go auth entry has unsupported type";
|
|
197
|
+
};
|
|
198
|
+
}, {
|
|
199
|
+
readonly id: "opencode";
|
|
200
|
+
readonly label: "OpenCode Zen";
|
|
201
|
+
readonly runtimeIds: readonly ["opencode", "opencode-zen"];
|
|
202
|
+
readonly synonyms: readonly ["opencode-zen"];
|
|
203
|
+
readonly rowKeys: readonly ["monthly", "balance", "auto_reload"];
|
|
204
|
+
}, {
|
|
205
|
+
readonly id: "ollama-cloud";
|
|
206
|
+
readonly label: "Ollama Cloud";
|
|
207
|
+
readonly runtimeIds: readonly ["ollama-cloud"];
|
|
208
|
+
readonly synonyms: readonly [];
|
|
209
|
+
readonly rowKeys: readonly ["session", "weekly", "monthly", "purchased"];
|
|
210
|
+
readonly apiKey: {
|
|
211
|
+
readonly envVars: readonly ["OLLAMA_API_KEY"];
|
|
212
|
+
readonly providerKeys: readonly ["ollama-cloud"];
|
|
213
|
+
readonly skipBrokenLogins: true;
|
|
214
|
+
};
|
|
215
|
+
}, {
|
|
216
|
+
readonly id: "quota-providers";
|
|
217
|
+
readonly label: "Custom providers";
|
|
218
|
+
readonly runtimeIds: readonly [];
|
|
219
|
+
readonly synonyms: readonly [];
|
|
220
|
+
readonly rowKeys: readonly ["custom.*.*"];
|
|
221
|
+
}];
|
|
222
|
+
export type CanonicalQuotaProviderId = (typeof QUOTA_PROVIDER_REGISTRATION_SOURCE)[number]["id"];
|