@encoredigitalgroup/opencode 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.
- 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 +102 -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 +9112 -35
- package/dist/tui/index.js +5916 -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,102 @@
|
|
|
1
|
+
import type { RowAuthority, RowMethod, RowType } from "../core/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Export types for external tool consumption.
|
|
4
|
+
*
|
|
5
|
+
* These types define the schema for the periodic JSON export file
|
|
6
|
+
* written when the `system.exportFile` setting is on, and for the
|
|
7
|
+
* `show --json` CLI output.
|
|
8
|
+
*/
|
|
9
|
+
interface QuotaExportEntryBase {
|
|
10
|
+
/**
|
|
11
|
+
* The row id, `${providerId}.${key}`, e.g. "copilot.allowance" or
|
|
12
|
+
* "quota-providers.custom.<definition id>.<key>". It never changes for a row; the rows of
|
|
13
|
+
* two accounts of one provider share it, and `account` tells them apart.
|
|
14
|
+
*/
|
|
15
|
+
id: string;
|
|
16
|
+
/** Provider label, account and row label, e.g. "Copilot (pro) Premium requests". */
|
|
17
|
+
name: string;
|
|
18
|
+
/** The row's account as the TUI shows it, e.g. "pro"; logins sharing one are "pro", "pro 2". */
|
|
19
|
+
account?: string;
|
|
20
|
+
/** What the number means (ADR 0001). */
|
|
21
|
+
resultType: RowType;
|
|
22
|
+
/** How the value was acquired (ADR 0001). */
|
|
23
|
+
acquisitionMethod: RowMethod;
|
|
24
|
+
/** Whether the source definition is maintained or user-configured. */
|
|
25
|
+
ownership: "maintained" | "user_configured";
|
|
26
|
+
/** Whether the value was provider-reported or locally derived. */
|
|
27
|
+
authority: RowAuthority;
|
|
28
|
+
/**
|
|
29
|
+
* Normalized window label when the entry has one: "Monthly", "Weekly", "5h", "RPM", etc.
|
|
30
|
+
* Absent when there is only one window for the provider.
|
|
31
|
+
*/
|
|
32
|
+
window?: string;
|
|
33
|
+
/** Unix seconds of the next source-backed reset. */
|
|
34
|
+
resetAt?: number;
|
|
35
|
+
}
|
|
36
|
+
/** One row in the version 4 export document. */
|
|
37
|
+
export type QuotaExportEntry = (QuotaExportEntryBase & {
|
|
38
|
+
renderType: "percent";
|
|
39
|
+
/** Consumed share of the quota, from 0 to 100. */
|
|
40
|
+
percentUsed: number;
|
|
41
|
+
}) | (QuotaExportEntryBase & {
|
|
42
|
+
renderType: "value";
|
|
43
|
+
value: string;
|
|
44
|
+
});
|
|
45
|
+
export type QuotaExportError = {
|
|
46
|
+
label: string;
|
|
47
|
+
message: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* A configured custom definition's identity and coarse status, in configured order. A
|
|
51
|
+
* switched-off definition is never checked, so it has `enabled: false` instead of a status.
|
|
52
|
+
*/
|
|
53
|
+
export type QuotaExportSource = {
|
|
54
|
+
id: string;
|
|
55
|
+
providerId: string;
|
|
56
|
+
status: "ok" | "error" | "unavailable";
|
|
57
|
+
entryCount: number;
|
|
58
|
+
} | {
|
|
59
|
+
id: string;
|
|
60
|
+
providerId: string;
|
|
61
|
+
entryCount: 0;
|
|
62
|
+
enabled: false;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Per-provider export status.
|
|
66
|
+
*
|
|
67
|
+
* One of three states: ok with entries, error with a message, or unavailable
|
|
68
|
+
* (provider not detected or no cache entry exists).
|
|
69
|
+
*/
|
|
70
|
+
export type QuotaExportProvider = ({
|
|
71
|
+
status: "ok";
|
|
72
|
+
fetchedAt: number;
|
|
73
|
+
entries: QuotaExportEntry[];
|
|
74
|
+
} | {
|
|
75
|
+
status: "partial";
|
|
76
|
+
fetchedAt: number;
|
|
77
|
+
entries: QuotaExportEntry[];
|
|
78
|
+
errors: QuotaExportError[];
|
|
79
|
+
} | {
|
|
80
|
+
status: "error";
|
|
81
|
+
fetchedAt: number;
|
|
82
|
+
error: string;
|
|
83
|
+
} | {
|
|
84
|
+
status: "unavailable";
|
|
85
|
+
}) & {
|
|
86
|
+
/** Present for aggregate providers; preserves configured source order. */
|
|
87
|
+
sources?: QuotaExportSource[];
|
|
88
|
+
};
|
|
89
|
+
/** The version 4 export document, assembled from all configured providers. */
|
|
90
|
+
export interface QuotaExport {
|
|
91
|
+
/** Schema version. */
|
|
92
|
+
version: 4;
|
|
93
|
+
/** Unix seconds when this document was assembled. */
|
|
94
|
+
exportedAt: number;
|
|
95
|
+
/** True when data was read from disk cache without a live fetch. */
|
|
96
|
+
fromCache: boolean;
|
|
97
|
+
/** Seconds since the oldest provider cache entry was written. */
|
|
98
|
+
cacheAgeSeconds: number;
|
|
99
|
+
/** Keyed by canonical provider id. */
|
|
100
|
+
providers: Record<string, QuotaExportProvider>;
|
|
101
|
+
}
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { CheckForExport } from "../core/store.js";
|
|
2
|
+
import type { QuotaSnapshot } from "../core/types.js";
|
|
3
|
+
import type { AccountResult } from "../providers/contract.js";
|
|
4
|
+
import type { QuotaExport, QuotaExportProvider } from "./quota-export-types.js";
|
|
5
|
+
import { type QuotaProviderDefinition } from "./quota-providers.js";
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the export file path from a configured value.
|
|
8
|
+
*
|
|
9
|
+
* - Empty string → XDG cache default: `$XDG_CACHE_HOME/opencode/quota-export.json`
|
|
10
|
+
* - Starts with `~/` → expands `~` to `homedir()`
|
|
11
|
+
* - Starts with `~\` → expands `~` and treats backslashes as path separators
|
|
12
|
+
* - Otherwise → returns as-is (caller is responsible for absolute paths)
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveExportPath(configured: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* A provider's part of the export file from one check: this check's rows as the snapshot
|
|
17
|
+
* shows them, or its error. The custom providers also list each definition, from this check's
|
|
18
|
+
* `accounts`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function exportProviderFromCheck(params: CheckForExport & {
|
|
21
|
+
providerId: string;
|
|
22
|
+
label: string;
|
|
23
|
+
customDefinitions: readonly QuotaProviderDefinition[];
|
|
24
|
+
accounts: readonly AccountResult[];
|
|
25
|
+
}): QuotaExportProvider;
|
|
26
|
+
/** Builds the export document from the quota snapshot; no provider is asked again. */
|
|
27
|
+
export declare function buildQuotaExportFromSnapshot(snapshot: QuotaSnapshot, nowMs?: number): QuotaExport;
|
|
28
|
+
/**
|
|
29
|
+
* Writes a `QuotaExport` document atomically to disk.
|
|
30
|
+
*
|
|
31
|
+
* Errors are re-thrown — callers are responsible for catching and logging them.
|
|
32
|
+
*/
|
|
33
|
+
export declare function writeQuotaExport(exportData: QuotaExport, resolvedPath: string): Promise<void>;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import type { ProviderRow } from "../providers/contract.js";
|
|
2
|
+
export declare const QUOTA_PROVIDER_REMOTE_FORMATS: readonly ["quota-v1", "openrouter-key-v1", "json-v1"];
|
|
3
|
+
export declare const QUOTA_PROVIDER_MODES: readonly ["remote-api", "local-estimate"];
|
|
4
|
+
export declare const QUOTA_PROVIDER_WINDOW_TYPES: readonly ["utc-day", "rolling"];
|
|
5
|
+
export declare const QUOTA_PROVIDERS_AGGREGATE_ID = "quota-providers";
|
|
6
|
+
export declare const MAINTAINED_LOCAL_ESTIMATE_IDS: readonly ["alibaba-coding-plan"];
|
|
7
|
+
export declare function isMaintainedQuotaProviderTuning(definition: QuotaProviderDefinition): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* The custom definitions that run: not maintained tunings, and not switched off. A switched-off
|
|
10
|
+
* definition is never fetched and its key is never sent.
|
|
11
|
+
*/
|
|
12
|
+
export declare function customQuotaProviderDefinitions(definitions: readonly QuotaProviderDefinition[]): QuotaProviderDefinition[];
|
|
13
|
+
/**
|
|
14
|
+
* Where a remote custom provider sends its key, for the user to check before switching it on:
|
|
15
|
+
* the URL's origin and path (the scheme shows http or https), and where the key comes from.
|
|
16
|
+
* Never the key itself. `insecure` is true for plain HTTP to any host but localhost, 127.0.0.1
|
|
17
|
+
* or ::1. Null for a local estimate, which sends nothing.
|
|
18
|
+
*/
|
|
19
|
+
export declare function describeQuotaProviderRequest(definition: QuotaProviderDefinition): {
|
|
20
|
+
url: string;
|
|
21
|
+
key: string;
|
|
22
|
+
insecure: boolean;
|
|
23
|
+
} | null;
|
|
24
|
+
export declare function resolveQuotaProviderSessionModelIdentity(params: {
|
|
25
|
+
currentModel: string;
|
|
26
|
+
currentProviderID?: string;
|
|
27
|
+
}): {
|
|
28
|
+
providerId: string;
|
|
29
|
+
modelId: string;
|
|
30
|
+
} | null;
|
|
31
|
+
/**
|
|
32
|
+
* The row key a custom source's mapping or entry name gets: spaces become "_", and the name
|
|
33
|
+
* stays as it is when that leaves only letters, digits, "_" and "-" ("Daily limit" →
|
|
34
|
+
* "Daily_limit", "Daily-limit" → "Daily-limit"). Other characters are dropped and a short hash
|
|
35
|
+
* of the exact name is added, so names stay apart ("日次" → 8 hex digits).
|
|
36
|
+
*/
|
|
37
|
+
export declare function customRowKey(name: string): string;
|
|
38
|
+
/** What a custom row means; custom configs may still say `rate_limit` and `spend` (ADR 0001). */
|
|
39
|
+
export type CustomResultType = "quota" | "rate_limit" | "usage" | "spend" | "budget" | "balance" | "status";
|
|
40
|
+
/**
|
|
41
|
+
* One custom row. `key` is the part of its id after `custom.<definition id>.`; its label is the
|
|
42
|
+
* configured label without a trailing colon, or else its name; its window is the one its name
|
|
43
|
+
* or label names ("Daily" → day).
|
|
44
|
+
*/
|
|
45
|
+
export declare function customRow(params: {
|
|
46
|
+
key: string;
|
|
47
|
+
name: string;
|
|
48
|
+
label?: string;
|
|
49
|
+
resultType: CustomResultType;
|
|
50
|
+
method: "remote_api" | "local_estimation";
|
|
51
|
+
value: {
|
|
52
|
+
percentRemaining: number;
|
|
53
|
+
} | {
|
|
54
|
+
text: string;
|
|
55
|
+
};
|
|
56
|
+
resetsAt?: string;
|
|
57
|
+
}): ProviderRow;
|
|
58
|
+
export declare function selectEligibleQuotaProviderDefinitions(params: {
|
|
59
|
+
definitions: readonly QuotaProviderDefinition[];
|
|
60
|
+
availableProviderIds: ReadonlySet<string>;
|
|
61
|
+
onlyCurrentModel?: boolean;
|
|
62
|
+
currentModel?: string;
|
|
63
|
+
currentProviderID?: string;
|
|
64
|
+
}): QuotaProviderDefinition[];
|
|
65
|
+
export type QuotaProviderRemoteFormat = (typeof QUOTA_PROVIDER_REMOTE_FORMATS)[number];
|
|
66
|
+
type QuotaProviderMode = (typeof QUOTA_PROVIDER_MODES)[number];
|
|
67
|
+
type QuotaProviderWindowType = (typeof QUOTA_PROVIDER_WINDOW_TYPES)[number];
|
|
68
|
+
export type JsonV1Path = string[];
|
|
69
|
+
export type JsonV1NumberSource = {
|
|
70
|
+
path: JsonV1Path;
|
|
71
|
+
divideBy?: 100 | 1_000 | 1_000_000;
|
|
72
|
+
} | {
|
|
73
|
+
literal: number;
|
|
74
|
+
};
|
|
75
|
+
export type JsonV1TextSource = {
|
|
76
|
+
path: JsonV1Path;
|
|
77
|
+
} | {
|
|
78
|
+
literal: string;
|
|
79
|
+
};
|
|
80
|
+
export type JsonV1TimestampEncoding = "iso-8601" | "unix-seconds" | "unix-milliseconds";
|
|
81
|
+
export type JsonV1TimestampSource = {
|
|
82
|
+
path: JsonV1Path;
|
|
83
|
+
encoding: JsonV1TimestampEncoding;
|
|
84
|
+
} | {
|
|
85
|
+
literal: string | number;
|
|
86
|
+
encoding: JsonV1TimestampEncoding;
|
|
87
|
+
};
|
|
88
|
+
export type JsonV1Metric = {
|
|
89
|
+
type: "percentage";
|
|
90
|
+
percentage: JsonV1NumberSource;
|
|
91
|
+
meaning: "remaining" | "used";
|
|
92
|
+
} | {
|
|
93
|
+
type: "used-limit";
|
|
94
|
+
used: JsonV1NumberSource;
|
|
95
|
+
limit: JsonV1NumberSource;
|
|
96
|
+
} | {
|
|
97
|
+
type: "remaining-limit";
|
|
98
|
+
remaining: JsonV1NumberSource;
|
|
99
|
+
limit: JsonV1NumberSource;
|
|
100
|
+
} | {
|
|
101
|
+
type: "spend-budget";
|
|
102
|
+
spend: JsonV1NumberSource;
|
|
103
|
+
budget: JsonV1NumberSource;
|
|
104
|
+
} | {
|
|
105
|
+
type: "remaining-budget";
|
|
106
|
+
remaining: JsonV1NumberSource;
|
|
107
|
+
budget: JsonV1NumberSource;
|
|
108
|
+
} | {
|
|
109
|
+
type: "value";
|
|
110
|
+
valueType: "used" | "limit" | "remaining" | "balance" | "spend" | "budget";
|
|
111
|
+
value: JsonV1NumberSource;
|
|
112
|
+
} | {
|
|
113
|
+
type: "status";
|
|
114
|
+
value: JsonV1TextSource;
|
|
115
|
+
};
|
|
116
|
+
export interface JsonV1Mapping {
|
|
117
|
+
resultType: CustomResultType;
|
|
118
|
+
name: string;
|
|
119
|
+
label?: string;
|
|
120
|
+
unit?: string;
|
|
121
|
+
unitPosition?: "prefix" | "suffix";
|
|
122
|
+
resetTime?: JsonV1TimestampSource;
|
|
123
|
+
observedTime?: JsonV1TimestampSource;
|
|
124
|
+
metric: JsonV1Metric;
|
|
125
|
+
}
|
|
126
|
+
export interface JsonV1Adapter {
|
|
127
|
+
rowsPath?: JsonV1Path;
|
|
128
|
+
mappings: JsonV1Mapping[];
|
|
129
|
+
}
|
|
130
|
+
interface QuotaProviderDefinitionBase {
|
|
131
|
+
id: string;
|
|
132
|
+
/** Effective OpenCode provider id. Input omits this when it is the same as id. */
|
|
133
|
+
providerId: string;
|
|
134
|
+
/** Normalized display label; omitted input defaults to id. */
|
|
135
|
+
label: string;
|
|
136
|
+
mode: QuotaProviderMode;
|
|
137
|
+
/** Exact OpenCode model ids, without a provider prefix. Omission covers the provider. */
|
|
138
|
+
modelIds?: string[];
|
|
139
|
+
/**
|
|
140
|
+
* `false` switches the definition off: it is never fetched and its key is never sent (a
|
|
141
|
+
* maintained tuning is not applied). Omission means on. Agents add definitions switched off;
|
|
142
|
+
* only the user switches them on.
|
|
143
|
+
*/
|
|
144
|
+
enabled?: boolean;
|
|
145
|
+
}
|
|
146
|
+
interface RemoteApiQuotaProviderDefinitionBase extends QuotaProviderDefinitionBase {
|
|
147
|
+
mode: "remote-api";
|
|
148
|
+
/** Canonical absolute HTTPS URL, or loopback HTTP URL. */
|
|
149
|
+
url: string;
|
|
150
|
+
apiKeyEnv?: string;
|
|
151
|
+
}
|
|
152
|
+
export type RemoteApiQuotaProviderDefinition = (RemoteApiQuotaProviderDefinitionBase & {
|
|
153
|
+
format: "quota-v1" | "openrouter-key-v1";
|
|
154
|
+
adapter?: never;
|
|
155
|
+
}) | (RemoteApiQuotaProviderDefinitionBase & {
|
|
156
|
+
format: "json-v1";
|
|
157
|
+
adapter: JsonV1Adapter;
|
|
158
|
+
});
|
|
159
|
+
export interface LocalEstimateWindow {
|
|
160
|
+
id: string;
|
|
161
|
+
label: string;
|
|
162
|
+
type: QuotaProviderWindowType;
|
|
163
|
+
/** Present only for rolling windows. */
|
|
164
|
+
durationMinutes?: number;
|
|
165
|
+
requestLimit: number;
|
|
166
|
+
usdBudget?: number;
|
|
167
|
+
}
|
|
168
|
+
export interface LocalEstimateQuotaProviderDefinition extends QuotaProviderDefinitionBase {
|
|
169
|
+
mode: "local-estimate";
|
|
170
|
+
windows: LocalEstimateWindow[];
|
|
171
|
+
/**
|
|
172
|
+
* Exact source model id -> models.dev provider/model fallback.
|
|
173
|
+
* Automatic models.dev matching always wins.
|
|
174
|
+
*/
|
|
175
|
+
pricingModelMap?: Record<string, string>;
|
|
176
|
+
}
|
|
177
|
+
export type QuotaProviderDefinition = RemoteApiQuotaProviderDefinition | LocalEstimateQuotaProviderDefinition;
|
|
178
|
+
interface QuotaProviderValidationIssue {
|
|
179
|
+
key: string;
|
|
180
|
+
message: string;
|
|
181
|
+
}
|
|
182
|
+
type QuotaProvidersValidationResult = {
|
|
183
|
+
value: QuotaProviderDefinition[];
|
|
184
|
+
issues: [];
|
|
185
|
+
} | {
|
|
186
|
+
value?: undefined;
|
|
187
|
+
issues: QuotaProviderValidationIssue[];
|
|
188
|
+
};
|
|
189
|
+
/** Every top-level field a definition can have, in either mode. */
|
|
190
|
+
export declare const QUOTA_PROVIDER_FIELDS: readonly string[];
|
|
191
|
+
export declare const JSON_V1_MAX_DISPLAY_CODE_POINTS = 160;
|
|
192
|
+
/** Most items a reply's list may hold; each becomes its own row. */
|
|
193
|
+
export declare const JSON_V1_MAX_ITEMS = 100;
|
|
194
|
+
export declare const JSON_V1_MAX_NUMBER_MAGNITUDE = 1000000000000000;
|
|
195
|
+
export declare const CUSTOM_RESULT_TYPES: ReadonlySet<string>;
|
|
196
|
+
export declare function normalizeJsonV1Timestamp(value: unknown, encoding: JsonV1TimestampEncoding): string | null;
|
|
197
|
+
/** Validate and normalize the complete global-only quotaProviders array atomically. */
|
|
198
|
+
export declare function validateQuotaProviders(value: unknown): QuotaProvidersValidationResult;
|
|
199
|
+
export declare function cloneQuotaProviders(definitions: readonly QuotaProviderDefinition[]): QuotaProviderDefinition[];
|
|
200
|
+
export declare function findQuotaProviderDefinition(definitions: readonly QuotaProviderDefinition[], id: string): QuotaProviderDefinition | undefined;
|
|
201
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
declare const resolvedAuthIdentityBrand: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* Provider-scoped opaque identity for one winning resolved-auth principal.
|
|
4
|
+
*
|
|
5
|
+
* The token is safe to use only as an internal derivation input. It must not be
|
|
6
|
+
* rendered, logged, diagnosed, telemetered, or included in JSON exports.
|
|
7
|
+
*/
|
|
8
|
+
export type ResolvedAuthIdentity = string & {
|
|
9
|
+
readonly [resolvedAuthIdentityBrand]: true;
|
|
10
|
+
};
|
|
11
|
+
type ResolvedAuthPrincipal = {
|
|
12
|
+
kind: "stable-id";
|
|
13
|
+
value: string;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "credential";
|
|
16
|
+
value: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function isProtectedResolvedAuthStorageSupported(params: {
|
|
19
|
+
platform: NodeJS.Platform;
|
|
20
|
+
hasOwnerIdentity: boolean;
|
|
21
|
+
}): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Whether identities stay the same after a reload: true where the key lives in the protected
|
|
24
|
+
* key file, false where it is held in memory only (Windows, or no owner uid).
|
|
25
|
+
*/
|
|
26
|
+
export declare function isResolvedAuthIdentityKeyDurable(): boolean;
|
|
27
|
+
export declare function getResolvedAuthIdentityKeyPath(): string;
|
|
28
|
+
export declare function deriveResolvedAuthIdentity(params: {
|
|
29
|
+
providerId: string;
|
|
30
|
+
principal: ResolvedAuthPrincipal;
|
|
31
|
+
qualifiers?: readonly string[];
|
|
32
|
+
}): Promise<ResolvedAuthIdentity | null>;
|
|
33
|
+
export declare function composeResolvedAuthIdentities(params: {
|
|
34
|
+
providerId: string;
|
|
35
|
+
identities: readonly ResolvedAuthIdentity[];
|
|
36
|
+
qualifiers?: readonly string[];
|
|
37
|
+
}): Promise<ResolvedAuthIdentity | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Who a provider is signed in as across every login it checks: each login's connection with its
|
|
40
|
+
* own identity and whether OpenCode uses it, in a stable order. Adding, removing, switching or
|
|
41
|
+
* swapping a login changes it. Null without logins, or when one of them can't be told apart
|
|
42
|
+
* safely.
|
|
43
|
+
*/
|
|
44
|
+
export declare function loginListIdentity(providerId: string, logins: ReadonlyArray<{
|
|
45
|
+
row: {
|
|
46
|
+
id: string;
|
|
47
|
+
active: boolean;
|
|
48
|
+
};
|
|
49
|
+
identity: ResolvedAuthIdentity | null;
|
|
50
|
+
}>): Promise<ResolvedAuthIdentity | null>;
|
|
51
|
+
export declare function __resetResolvedAuthIdentityForTests(): void;
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type TokenBuckets = {
|
|
2
|
+
input: number;
|
|
3
|
+
output: number;
|
|
4
|
+
reasoning: number;
|
|
5
|
+
cache_read: number;
|
|
6
|
+
cache_write: number;
|
|
7
|
+
};
|
|
8
|
+
type TokenCarrier = {
|
|
9
|
+
tokens?: {
|
|
10
|
+
input?: number;
|
|
11
|
+
output?: number;
|
|
12
|
+
reasoning?: number;
|
|
13
|
+
cache?: {
|
|
14
|
+
read?: number;
|
|
15
|
+
write?: number;
|
|
16
|
+
};
|
|
17
|
+
} | null;
|
|
18
|
+
};
|
|
19
|
+
export declare function emptyTokenBuckets(): TokenBuckets;
|
|
20
|
+
export declare function addTokenBuckets(a: TokenBuckets, b: TokenBuckets): TokenBuckets;
|
|
21
|
+
export declare function tokenBucketsFromMessage(message: TokenCarrier): TokenBuckets;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The legacy provider data types: the integration ids logins live under, and each provider's fetch
|
|
3
|
+
* result.
|
|
4
|
+
*/
|
|
5
|
+
import type { ErrorFacts } from "../core/errors.js";
|
|
6
|
+
export type GeminiCliAuthSourceKey = "google-gemini-cli" | "gemini-cli" | "opencode-gemini-auth" | "gemini" | "google";
|
|
7
|
+
export type GoogleAgyAuthSourceKey = "google-agy" | "opencode-agy-auth" | "google-agy-auth";
|
|
8
|
+
export type AlibabaCodingPlanTier = "lite" | "pro";
|
|
9
|
+
/**
|
|
10
|
+
* Copilot subscription tier.
|
|
11
|
+
* See: https://docs.github.com/en/copilot/get-started/plans
|
|
12
|
+
*/
|
|
13
|
+
export type CopilotTier = "free" | "student" | "pro" | "pro+" | "max" | "business" | "enterprise";
|
|
14
|
+
export type CopilotBillingModel = "ai_credits" | "legacy_premium_requests";
|
|
15
|
+
/**
|
|
16
|
+
* Copilot quota token configuration.
|
|
17
|
+
*
|
|
18
|
+
* Stored locally in:
|
|
19
|
+
* - OpenCode runtime config candidate directories as
|
|
20
|
+
* `.../opencode/copilot-quota-token.json`
|
|
21
|
+
* (for example `$XDG_CONFIG_HOME/opencode` or `~/.config/opencode`)
|
|
22
|
+
*
|
|
23
|
+
* Credential type and permission depend on whether GitHub bills the
|
|
24
|
+
* personal account, organization, or enterprise.
|
|
25
|
+
*/
|
|
26
|
+
export interface CopilotQuotaConfig {
|
|
27
|
+
/** GitHub token with the billing-report permission required by the selected scope. */
|
|
28
|
+
token: string;
|
|
29
|
+
/** Current AI Credits by default; legacy PRUs are limited to eligible Pro/Pro+ annual plans. */
|
|
30
|
+
billingModel?: CopilotBillingModel;
|
|
31
|
+
/** Optional user login override for user-scoped reports or org user filtering */
|
|
32
|
+
username?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Optional organization slug.
|
|
35
|
+
*
|
|
36
|
+
* In business mode, this selects
|
|
37
|
+
* `/organizations/{org}/settings/billing/ai_credit/usage`.
|
|
38
|
+
*
|
|
39
|
+
* In enterprise mode with an explicit `enterprise` slug, this becomes the
|
|
40
|
+
* optional `organization` query filter on the enterprise usage report.
|
|
41
|
+
*/
|
|
42
|
+
organization?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Optional enterprise slug for enterprise-scoped AI Credit reports.
|
|
45
|
+
*
|
|
46
|
+
* When present, the plugin queries
|
|
47
|
+
* `/enterprises/{enterprise}/settings/billing/ai_credit/usage`.
|
|
48
|
+
*/
|
|
49
|
+
enterprise?: string;
|
|
50
|
+
/** Optional GitHub Enterprise Cloud hostname or host-only HTTPS URL for this token. */
|
|
51
|
+
enterpriseUrl?: string;
|
|
52
|
+
/** Copilot subscription tier and billing scope. */
|
|
53
|
+
tier: CopilotTier;
|
|
54
|
+
}
|
|
55
|
+
type CopilotResultAuthority = "provider_reported" | "locally_derived";
|
|
56
|
+
export interface CopilotBudgetResult {
|
|
57
|
+
amountUsd: number;
|
|
58
|
+
spentUsd?: number;
|
|
59
|
+
scope: string;
|
|
60
|
+
percentRemaining?: number;
|
|
61
|
+
authority: CopilotResultAuthority;
|
|
62
|
+
}
|
|
63
|
+
/** Result from fetching per-user Copilot accounting. */
|
|
64
|
+
export interface CopilotQuotaResult {
|
|
65
|
+
success: true;
|
|
66
|
+
mode: "user_quota";
|
|
67
|
+
unit: "ai_credits" | "premium_interactions" | "premium_requests";
|
|
68
|
+
used: number;
|
|
69
|
+
authority: CopilotResultAuthority;
|
|
70
|
+
period?: {
|
|
71
|
+
year: number;
|
|
72
|
+
month: number;
|
|
73
|
+
};
|
|
74
|
+
total?: number;
|
|
75
|
+
percentRemaining?: number;
|
|
76
|
+
includedUsed?: number;
|
|
77
|
+
billedUsed?: number;
|
|
78
|
+
billedAmountUsd?: number;
|
|
79
|
+
budget?: CopilotBudgetResult;
|
|
80
|
+
plan?: string;
|
|
81
|
+
unlimited?: boolean;
|
|
82
|
+
warnings?: string[];
|
|
83
|
+
resetTimeIso?: string;
|
|
84
|
+
}
|
|
85
|
+
/** Plan-only result when Copilot returns token-billing placeholder quota data. */
|
|
86
|
+
export interface CopilotPlanResult {
|
|
87
|
+
success: true;
|
|
88
|
+
mode: "user_plan";
|
|
89
|
+
authority: CopilotResultAuthority;
|
|
90
|
+
plan?: string;
|
|
91
|
+
resetTimeIso?: string;
|
|
92
|
+
}
|
|
93
|
+
/** Result from fetching organization-scoped Copilot AI Credit usage. */
|
|
94
|
+
export interface CopilotOrganizationUsageResult {
|
|
95
|
+
success: true;
|
|
96
|
+
mode: "organization_usage";
|
|
97
|
+
organization: string;
|
|
98
|
+
username?: string;
|
|
99
|
+
period: {
|
|
100
|
+
year: number;
|
|
101
|
+
month: number;
|
|
102
|
+
};
|
|
103
|
+
unit: "ai_credits";
|
|
104
|
+
used: number;
|
|
105
|
+
authority: CopilotResultAuthority;
|
|
106
|
+
includedUsed: number;
|
|
107
|
+
billedUsed: number;
|
|
108
|
+
billedAmountUsd?: number;
|
|
109
|
+
budget?: CopilotBudgetResult;
|
|
110
|
+
warnings?: string[];
|
|
111
|
+
resetTimeIso?: string;
|
|
112
|
+
}
|
|
113
|
+
/** Result from fetching enterprise-scoped Copilot AI Credit usage. */
|
|
114
|
+
export interface CopilotEnterpriseUsageResult {
|
|
115
|
+
success: true;
|
|
116
|
+
mode: "enterprise_usage";
|
|
117
|
+
enterprise: string;
|
|
118
|
+
organization?: string;
|
|
119
|
+
username?: string;
|
|
120
|
+
period: {
|
|
121
|
+
year: number;
|
|
122
|
+
month: number;
|
|
123
|
+
};
|
|
124
|
+
unit: "ai_credits";
|
|
125
|
+
used: number;
|
|
126
|
+
authority: CopilotResultAuthority;
|
|
127
|
+
includedUsed: number;
|
|
128
|
+
billedUsed: number;
|
|
129
|
+
billedAmountUsd?: number;
|
|
130
|
+
budget?: CopilotBudgetResult;
|
|
131
|
+
warnings?: string[];
|
|
132
|
+
resetTimeIso?: string;
|
|
133
|
+
}
|
|
134
|
+
export interface GeminiCliQuotaBucket {
|
|
135
|
+
modelId: string;
|
|
136
|
+
displayName: string;
|
|
137
|
+
percentRemaining: number;
|
|
138
|
+
resetTimeIso?: string;
|
|
139
|
+
remainingAmount?: string;
|
|
140
|
+
tokenType?: string;
|
|
141
|
+
accountEmail?: string;
|
|
142
|
+
sourceKey?: GeminiCliAuthSourceKey;
|
|
143
|
+
}
|
|
144
|
+
export interface GoogleAgyQuotaSummaryBucket {
|
|
145
|
+
bucketId?: string;
|
|
146
|
+
displayName?: string;
|
|
147
|
+
description?: string;
|
|
148
|
+
window?: string;
|
|
149
|
+
remaining?: string;
|
|
150
|
+
remainingFraction?: number;
|
|
151
|
+
remainingAmount?: string;
|
|
152
|
+
disabled?: boolean;
|
|
153
|
+
resetTime?: string;
|
|
154
|
+
}
|
|
155
|
+
interface GoogleAgyQuotaSummaryGroup {
|
|
156
|
+
displayName?: string;
|
|
157
|
+
description?: string;
|
|
158
|
+
buckets?: GoogleAgyQuotaSummaryBucket[];
|
|
159
|
+
}
|
|
160
|
+
export interface GoogleAgyQuotaSummaryResponse {
|
|
161
|
+
groups?: GoogleAgyQuotaSummaryGroup[];
|
|
162
|
+
buckets?: GoogleAgyQuotaSummaryBucket[];
|
|
163
|
+
description?: string;
|
|
164
|
+
}
|
|
165
|
+
export interface GoogleAgyQuotaBucket {
|
|
166
|
+
family: string;
|
|
167
|
+
window: "weekly" | "five_hour";
|
|
168
|
+
windowLabel: "Weekly" | "5h";
|
|
169
|
+
bucketId?: string;
|
|
170
|
+
bucketLabel?: string;
|
|
171
|
+
remainingFraction: number;
|
|
172
|
+
percentRemaining: number;
|
|
173
|
+
resetTimeIso?: string;
|
|
174
|
+
remainingAmount?: string;
|
|
175
|
+
accountEmail?: string;
|
|
176
|
+
sourceKey: GoogleAgyAuthSourceKey;
|
|
177
|
+
}
|
|
178
|
+
/** Error result */
|
|
179
|
+
export interface QuotaError {
|
|
180
|
+
success: false;
|
|
181
|
+
error: string;
|
|
182
|
+
/** The facts of the request that failed, when it gave them. */
|
|
183
|
+
facts?: ErrorFacts;
|
|
184
|
+
}
|
|
185
|
+
/** Combined quota result */
|
|
186
|
+
export type CopilotResult = CopilotQuotaResult | CopilotPlanResult | CopilotOrganizationUsageResult | CopilotEnterpriseUsageResult | QuotaError | null;
|
|
187
|
+
export type OpenCodeGoWindowKey = "rolling" | "weekly" | "monthly";
|
|
188
|
+
/** Single normalized usage window from the OpenCode Go API. */
|
|
189
|
+
export interface OpenCodeGoWindow {
|
|
190
|
+
/** Raw API status after exact validation. */
|
|
191
|
+
status: "ok" | "rate-limited";
|
|
192
|
+
/** Usage percentage [0..100]. */
|
|
193
|
+
usagePercent: number;
|
|
194
|
+
/** Remaining percentage [0..100]. */
|
|
195
|
+
percentRemaining: number;
|
|
196
|
+
/** Canonical ISO reset timestamp. */
|
|
197
|
+
resetTimeIso: string;
|
|
198
|
+
}
|
|
199
|
+
/** Strictly validated result from the OpenCode Go usage API. */
|
|
200
|
+
export type OpenCodeGoResult = {
|
|
201
|
+
success: true;
|
|
202
|
+
rolling: OpenCodeGoWindow;
|
|
203
|
+
weekly: OpenCodeGoWindow;
|
|
204
|
+
monthly: OpenCodeGoWindow;
|
|
205
|
+
} | (QuotaError & {
|
|
206
|
+
notSubscribed?: true;
|
|
207
|
+
});
|
|
208
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Server support for the quota sidebar. */
|
|
2
|
+
import { Plugin } from "@opencode/plugin";
|
|
3
|
+
import { type ProviderSourceHost } from "./core/provider-source.js";
|
|
4
|
+
export declare function createQuotaServerPlugin(options?: {
|
|
5
|
+
providers?: ProviderSourceHost["providers"];
|
|
6
|
+
}): Plugin.Plugin;
|
|
7
|
+
declare const _default: Plugin.Plugin;
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic Claude: the 5h, weekly, Usage Credits and Fable weekly windows of each Claude login
|
|
3
|
+
* stored in OpenCode, or of the login the Claude CLI or its credentials file holds.
|
|
4
|
+
*/
|
|
5
|
+
import type { QuotaProvider } from "../lib/entries.js";
|
|
6
|
+
export declare const anthropicProvider: QuotaProvider;
|