pantheon-opencode 1.6.2-beta.9 → 1.6.3-beta.1

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.
Files changed (73) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/README.md +34 -60
  3. package/README.pt-BR.md +10 -12
  4. package/bin/pantheon-init.mjs +23 -33
  5. package/package.json +3 -3
  6. package/plugin.json +1 -1
  7. package/pyproject.toml +1 -1
  8. package/scripts/decision-router-budget.mjs +4 -1
  9. package/scripts/decision-router-v2-egress.mjs +11 -2
  10. package/scripts/decision-router.mjs +64 -56
  11. package/scripts/install/decision-router-config.mjs +110 -1
  12. package/scripts/install/npx-cache-sweep.mjs +103 -0
  13. package/scripts/install/opencode.mjs +7 -7
  14. package/scripts/install/plugin.mjs +4 -3
  15. package/scripts/install/strings.mjs +4 -0
  16. package/scripts/release-gates.mjs +6 -82
  17. package/scripts/secret-scan.mjs +1 -1
  18. package/scripts/sync-tui.mjs +3 -3
  19. package/src/agents/zeus.md +4 -2
  20. package/src/pantheon/jev-decision-tool.ts +455 -117
  21. package/src/pantheon/jev-decisions.ts +72 -25
  22. package/src/pantheon/jev-escalation.ts +639 -0
  23. package/src/pantheon/jev-quality-score.ts +432 -0
  24. package/src/pantheon/jev-risk-gate.ts +479 -0
  25. package/src/pantheon/local-decision-budget.ts +11 -1
  26. package/src/pantheon/local-decision-prompt.ts +12 -18
  27. package/src/pantheon/local-decision-provider-matrix.ts +3 -0
  28. package/src/pantheon/v2-decision-telemetry.ts +14 -4
  29. package/src/pantheon/v2-native-decisions.ts +1 -1
  30. package/src/plugin-v2.ts +204 -24
  31. package/src/plugins/tui/dist/server-v2.d.ts +19 -11
  32. package/src/plugins/tui/dist/server-v2.d.ts.map +1 -1
  33. package/src/plugins/tui/dist/server-v2.js +19 -789
  34. package/src/plugins/tui/dist/server-v2.js.map +1 -1
  35. package/src/plugins/tui/dist/tui-v2.d.ts +12 -331
  36. package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
  37. package/src/plugins/tui/dist/tui-v2.js +257 -5370
  38. package/src/plugins/tui/dist/tui-v2.js.map +1 -1
  39. package/src/plugins/tui/dist/tui.js +1 -1
  40. package/src/plugins/tui/package-lock.json +2 -2
  41. package/src/plugins/tui/package.json +1 -1
  42. package/src/plugins/tui/src/index-v2.tsx +213 -86
  43. package/src/plugins/tui/src/server-v2.ts +18 -982
  44. package/src/plugins/tui/tsconfig.typecheck.json +1 -6
  45. package/src/plugins/tui/tsdown.config.ts +1 -11
  46. package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js +0 -749
  47. package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js.map +0 -1
  48. package/src/plugins/tui/dist/quota-adapters.d.ts +0 -89
  49. package/src/plugins/tui/dist/quota-adapters.d.ts.map +0 -1
  50. package/src/plugins/tui/dist/quota-adapters.js +0 -1142
  51. package/src/plugins/tui/dist/quota-adapters.js.map +0 -1
  52. package/src/plugins/tui/dist/quota-cli.d.ts +0 -17
  53. package/src/plugins/tui/dist/quota-cli.d.ts.map +0 -1
  54. package/src/plugins/tui/dist/quota-cli.js +0 -184
  55. package/src/plugins/tui/dist/quota-cli.js.map +0 -1
  56. package/src/plugins/tui/dist/quota-rpc-DMmXBhBe.js +0 -684
  57. package/src/plugins/tui/dist/quota-rpc-DMmXBhBe.js.map +0 -1
  58. package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js +0 -118
  59. package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js.map +0 -1
  60. package/src/plugins/tui/dist/usage-history-worker.js +0 -25
  61. package/src/plugins/tui/dist/usage-history-worker.js.map +0 -1
  62. package/src/plugins/tui/src/go-key-diagnostic-ui.ts +0 -100
  63. package/src/plugins/tui/src/go-key-diagnostic.ts +0 -125
  64. package/src/plugins/tui/src/quota-adapters.ts +0 -1598
  65. package/src/plugins/tui/src/quota-cli.ts +0 -237
  66. package/src/plugins/tui/src/quota-rpc.ts +0 -373
  67. package/src/plugins/tui/src/quota-v2-model.ts +0 -1032
  68. package/src/plugins/tui/src/quota-v2.tsx +0 -1238
  69. package/src/plugins/tui/src/usage-history-contract.ts +0 -217
  70. package/src/plugins/tui/src/usage-history-validation.ts +0 -104
  71. package/src/plugins/tui/src/usage-history-view.tsx +0 -236
  72. package/src/plugins/tui/src/usage-history-worker.ts +0 -25
  73. package/src/plugins/tui/src/usage-view-model.ts +0 -272
@@ -1,237 +0,0 @@
1
- import { spawn } from 'node:child_process'
2
- import { constants } from 'node:fs'
3
- import { access, lstat, realpath } from 'node:fs/promises'
4
- import { basename, isAbsolute, join, parse, resolve, sep } from 'node:path'
5
-
6
- const CLI_TIMEOUT_MS = 5_000
7
- const MAX_STDOUT_BYTES = 16 * 1024
8
- const MAX_STDERR_BYTES = 4 * 1024
9
- const CLI_ARGS = ['usage', 'token-plan', '--output', 'json'] as const
10
- const TRUSTED_EXECUTABLE_ENV = 'PANTHEON_TRUSTED_BL_EXECUTABLE'
11
- const SAFE_ENV_NAMES = ['HOME', 'LANG', 'LC_ALL', 'LC_MESSAGES', 'TZ'] as const
12
-
13
- export type AlibabaTokenPlanUsageResult =
14
- | { readonly percentage: number }
15
- | { readonly reason: 'cli_identity_unavailable' | 'provider_error' }
16
-
17
- function isRecord(value: unknown): value is Record<string, unknown> {
18
- return typeof value === 'object' && value !== null && !Array.isArray(value)
19
- }
20
-
21
- /** Parse only the documented Bailian CLI JSON fields for Personal Token Plan. */
22
- export function parseAlibabaTokenPlanPercentage(output: string): number | undefined {
23
- try {
24
- const value: unknown = JSON.parse(output)
25
- if (!isRecord(value)) return undefined
26
- if (
27
- Object.keys(value).some((key) => !['per1MonthPercentage', 'per1MonthResetTime'].includes(key))
28
- ) {
29
- return undefined
30
- }
31
- if (
32
- 'per1MonthResetTime' in value &&
33
- (typeof value.per1MonthResetTime !== 'number' ||
34
- !Number.isSafeInteger(value.per1MonthResetTime) ||
35
- value.per1MonthResetTime < 0)
36
- ) {
37
- return undefined
38
- }
39
- const percentage = value.per1MonthPercentage
40
- return typeof percentage === 'number' &&
41
- Number.isFinite(percentage) &&
42
- percentage >= 0 &&
43
- percentage <= 1
44
- ? percentage
45
- : undefined
46
- } catch {
47
- return undefined
48
- }
49
- }
50
-
51
- function safeCliEnvironment(environment: NodeJS.ProcessEnv): NodeJS.ProcessEnv | undefined {
52
- if (typeof environment.HOME !== 'string' || environment.HOME.length === 0) return undefined
53
- const result: NodeJS.ProcessEnv = {}
54
- for (const name of SAFE_ENV_NAMES) {
55
- const value = environment[name]
56
- if (typeof value === 'string' && value.length <= 4096) result[name] = value
57
- }
58
- return result
59
- }
60
-
61
- async function trustedExecutable(environment: NodeJS.ProcessEnv): Promise<string | undefined> {
62
- const path = environment[TRUSTED_EXECUTABLE_ENV]
63
- if (
64
- typeof path !== 'string' ||
65
- path.length > 4096 ||
66
- !isAbsolute(path) ||
67
- resolve(path) !== path ||
68
- basename(path) !== 'bl' ||
69
- // Node's Windows mode bits do not prove ACL write restrictions.
70
- process.platform === 'win32'
71
- ) {
72
- return undefined
73
- }
74
-
75
- try {
76
- const resolvedPath = await realpath(path)
77
- if (resolvedPath !== path) return undefined
78
-
79
- const root = parse(resolvedPath).root
80
- const components = resolvedPath.slice(root.length).split(sep)
81
- let currentPath = root
82
- let executable: Awaited<ReturnType<typeof lstat>> | undefined
83
- for (const [index, component] of components.entries()) {
84
- if (!component) continue
85
- currentPath = join(currentPath, component)
86
- const metadata = await lstat(currentPath)
87
- if (metadata.isSymbolicLink()) return undefined
88
- if (index === components.length - 1) {
89
- executable = metadata
90
- continue
91
- }
92
- if (!metadata.isDirectory()) return undefined
93
- const permissions = metadata.mode & 0o7777
94
- const isSticky = (permissions & 0o1000) !== 0
95
- // A sticky shared directory prevents other users replacing another owner's entry.
96
- if ((permissions & 0o222) !== 0 && !isSticky) return undefined
97
- }
98
-
99
- if (
100
- !executable?.isFile() ||
101
- (Number(executable.mode) & 0o111) === 0 ||
102
- (Number(executable.mode) & 0o222) !== 0
103
- ) {
104
- return undefined
105
- }
106
- await access(resolvedPath, constants.X_OK)
107
- if ((await realpath(path)) !== resolvedPath) return undefined
108
-
109
- const verifiedExecutable = await lstat(resolvedPath)
110
- if (
111
- verifiedExecutable.isSymbolicLink() ||
112
- !verifiedExecutable.isFile() ||
113
- (Number(verifiedExecutable.mode) & 0o111) === 0 ||
114
- (Number(verifiedExecutable.mode) & 0o222) !== 0
115
- ) {
116
- return undefined
117
- }
118
- return resolvedPath
119
- } catch {
120
- return undefined
121
- }
122
- }
123
-
124
- function isMissingExecutable(error: unknown): boolean {
125
- if (typeof error !== 'object' || error === null || !('code' in error)) return false
126
- return error.code === 'ENOENT' || error.code === 'EACCES'
127
- }
128
-
129
- /**
130
- * Run the fixed Bailian command only through an explicitly trusted absolute
131
- * executable path. Credentials remain in the CLI's own login store; Pantheon
132
- * passes no provider secrets or arbitrary arguments.
133
- */
134
- export async function queryAlibabaTokenPlanUsage(
135
- signal: AbortSignal,
136
- spawnProcess: typeof spawn = spawn,
137
- environment: NodeJS.ProcessEnv = process.env,
138
- ): Promise<AlibabaTokenPlanUsageResult> {
139
- if (signal.aborted) return { reason: 'provider_error' }
140
- const env = safeCliEnvironment(environment)
141
- if (!env?.HOME) return { reason: 'cli_identity_unavailable' }
142
- const executable = await trustedExecutable(environment)
143
- if (!executable) return { reason: 'cli_identity_unavailable' }
144
- if (signal.aborted) return { reason: 'provider_error' }
145
-
146
- return new Promise((resolve) => {
147
- let child: ReturnType<typeof spawn>
148
- try {
149
- child = spawnProcess(executable, [...CLI_ARGS], {
150
- shell: false,
151
- windowsHide: true,
152
- cwd: env.HOME,
153
- env,
154
- stdio: ['ignore', 'pipe', 'pipe'],
155
- })
156
- } catch (error) {
157
- resolve({
158
- reason: isMissingExecutable(error) ? 'cli_identity_unavailable' : 'provider_error',
159
- })
160
- return
161
- }
162
- if (!child.stdout || !child.stderr) {
163
- child.kill()
164
- resolve({ reason: 'provider_error' })
165
- return
166
- }
167
-
168
- let settled = false
169
- let stdoutBytes = 0
170
- let stderrBytes = 0
171
- const chunks: Buffer[] = []
172
- let forceKillTimer: ReturnType<typeof setTimeout> | undefined
173
- const timeout = setTimeout(() => fail('provider_error', true), CLI_TIMEOUT_MS)
174
- timeout.unref()
175
-
176
- const terminate = () => {
177
- try {
178
- child.kill('SIGTERM')
179
- } catch {
180
- // The child may have exited between the event and the signal.
181
- }
182
- forceKillTimer = setTimeout(() => {
183
- try {
184
- child.kill('SIGKILL')
185
- } catch {
186
- // The child may have exited between the signals.
187
- }
188
- }, 250)
189
- forceKillTimer.unref()
190
- }
191
-
192
- const finish = (result: AlibabaTokenPlanUsageResult) => {
193
- if (settled) return
194
- settled = true
195
- clearTimeout(timeout)
196
- signal.removeEventListener('abort', onAbort)
197
- resolve(result)
198
- }
199
-
200
- const fail = (reason: 'cli_identity_unavailable' | 'provider_error', kill = false) => {
201
- if (kill) terminate()
202
- finish({ reason })
203
- }
204
-
205
- const onAbort = () => fail('provider_error', true)
206
- child.stdout.on('data', (chunk: Buffer | Uint8Array) => {
207
- if (settled) return
208
- const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)
209
- stdoutBytes += bytes.byteLength
210
- if (stdoutBytes > MAX_STDOUT_BYTES) {
211
- fail('provider_error', true)
212
- return
213
- }
214
- chunks.push(bytes)
215
- })
216
- child.stderr.on('data', (chunk: Buffer | Uint8Array) => {
217
- if (settled) return
218
- stderrBytes += chunk.byteLength
219
- if (stderrBytes > MAX_STDERR_BYTES) fail('provider_error', true)
220
- })
221
- child.on('error', (error) =>
222
- fail(isMissingExecutable(error) ? 'cli_identity_unavailable' : 'provider_error'),
223
- )
224
- child.on('close', (code) => {
225
- if (forceKillTimer) clearTimeout(forceKillTimer)
226
- if (settled) return
227
- if (code !== 0) {
228
- fail('provider_error')
229
- return
230
- }
231
- const percentage = parseAlibabaTokenPlanPercentage(Buffer.concat(chunks).toString('utf8'))
232
- finish(percentage === undefined ? { reason: 'provider_error' } : { percentage })
233
- })
234
- signal.addEventListener('abort', onAbort, { once: true })
235
- if (signal.aborted) onAbort()
236
- })
237
- }
@@ -1,373 +0,0 @@
1
- import { Rpc } from '@opencode/plugin/promise/index'
2
- import {
3
- MAX_HISTORY_BUCKETS,
4
- MAX_HISTORY_MODELS,
5
- USAGE_HISTORY_PERIODS,
6
- } from './usage-history-contract'
7
-
8
- /** Full provider matrix approved for the V2 quota surface. */
9
- export const QUOTA_PROVIDER_IDS = [
10
- 'anthropic',
11
- 'chutes',
12
- 'cursor',
13
- 'github-copilot',
14
- 'google-agy',
15
- 'kilo-gateway',
16
- 'nanogpt',
17
- 'ollama-cloud',
18
- 'openai',
19
- 'opencode-go',
20
- 'opencode-zen',
21
- 'openrouter',
22
- 'synthetic',
23
- 'xai-supergrok',
24
- 'gemini-cli',
25
- 'alibaba-coding-plan',
26
- 'alibaba-token-plan',
27
- 'deepseek',
28
- 'kimi-code-global',
29
- 'kimi-code-cn',
30
- 'minimax-plan-global',
31
- 'minimax-plan-cn',
32
- 'xiaomi-mimo',
33
- 'zai-coding-plan',
34
- 'zhipu-coding-plan',
35
- ] as const
36
-
37
- export type QuotaProviderId = (typeof QUOTA_PROVIDER_IDS)[number]
38
-
39
- /** Safe route labels are limited to OpenCode Go and never contain request data. */
40
- export type OpenCodeGoRouteKind = 'api_key' | 'console_oauth' | 'none' | 'unsupported'
41
-
42
- /** GLM plans may report up to 16 distinct quota windows in one response. */
43
- export const MAX_PROVIDER_METRICS = 16
44
-
45
- const metricSchema = {
46
- oneOf: [
47
- {
48
- type: 'object',
49
- properties: {
50
- kind: { const: 'provider_quota' },
51
- used: { type: 'number', minimum: 0 },
52
- remaining: { type: 'number', minimum: 0 },
53
- unit: { type: 'string', minLength: 1, maxLength: 16 },
54
- label: { type: 'string', minLength: 1, maxLength: 48 },
55
- period: { type: 'string', maxLength: 32 },
56
- resetsAt: { type: 'number', minimum: 0, maximum: 8_640_000_000_000_000 },
57
- },
58
- required: ['kind', 'used', 'remaining', 'unit', 'label'],
59
- additionalProperties: false,
60
- },
61
- {
62
- type: 'object',
63
- properties: {
64
- kind: { const: 'balance' },
65
- amount: { type: 'number', minimum: 0 },
66
- currency: { type: 'string', enum: ['USD', 'CNY'] },
67
- label: { type: 'string', minLength: 1, maxLength: 48 },
68
- status: { type: 'string', enum: ['available', 'unavailable', 'active', 'inactive'] },
69
- },
70
- required: ['kind', 'amount', 'currency', 'label'],
71
- additionalProperties: false,
72
- },
73
- {
74
- type: 'object',
75
- properties: {
76
- kind: { const: 'estimate' },
77
- amount: { type: 'number', minimum: 0 },
78
- unit: { type: 'string', minLength: 1, maxLength: 16 },
79
- label: { type: 'string', minLength: 1, maxLength: 48 },
80
- },
81
- required: ['kind', 'amount', 'unit', 'label'],
82
- additionalProperties: false,
83
- },
84
- {
85
- type: 'object',
86
- properties: {
87
- kind: { const: 'key_usage' },
88
- amount: { type: 'number', minimum: 0 },
89
- currency: { type: 'string', enum: ['USD', 'CNY'] },
90
- label: { type: 'string', minLength: 1, maxLength: 48 },
91
- period: { type: 'string', maxLength: 32 },
92
- },
93
- required: ['kind', 'amount', 'currency', 'label'],
94
- additionalProperties: false,
95
- },
96
- {
97
- type: 'object',
98
- properties: {
99
- kind: { const: 'session_usage' },
100
- amount: { type: 'number', minimum: 0 },
101
- unit: { type: 'string', minLength: 1, maxLength: 16 },
102
- label: { type: 'string', minLength: 1, maxLength: 48 },
103
- },
104
- required: ['kind', 'amount', 'unit', 'label'],
105
- additionalProperties: false,
106
- },
107
- {
108
- type: 'object',
109
- properties: {
110
- kind: { const: 'provider_status' },
111
- status: { type: 'string', enum: ['available', 'unavailable', 'active', 'inactive'] },
112
- label: { type: 'string', minLength: 1, maxLength: 48 },
113
- },
114
- required: ['kind', 'status', 'label'],
115
- additionalProperties: false,
116
- },
117
- ],
118
- } as const
119
-
120
- const providerStatusSchema = {
121
- type: 'object',
122
- properties: {
123
- provider: { type: 'string', enum: QUOTA_PROVIDER_IDS },
124
- label: { type: 'string', minLength: 1, maxLength: 48 },
125
- scope: { type: 'string', enum: ['account', 'selected_key', 'team', 'session'] },
126
- authentication: { type: 'string', enum: ['connected', 'not_connected', 'unavailable'] },
127
- state: { type: 'string', enum: ['available', 'needs_setup', 'unavailable'] },
128
- reason: {
129
- type: 'string',
130
- enum: [
131
- 'none',
132
- 'not_connected',
133
- 'unsupported',
134
- 'private_endpoint',
135
- 'eligibility_unverified',
136
- 'runtime_accounting_unavailable',
137
- 'cli_identity_unavailable',
138
- 'unsupported_credential_method',
139
- 'provider_error',
140
- 'not_subscribed',
141
- 'rate_limited',
142
- 'unauthorized',
143
- 'forbidden',
144
- 'timeout',
145
- 'network_error',
146
- 'invalid_response',
147
- ],
148
- },
149
- route_kind: {
150
- type: 'string',
151
- enum: ['api_key', 'console_oauth', 'none', 'unsupported'],
152
- },
153
- retry_after_ms: { type: 'integer', minimum: 0, maximum: 3_600_000 },
154
- metrics: { type: 'array', items: metricSchema, maxItems: MAX_PROVIDER_METRICS },
155
- },
156
- required: ['provider', 'label', 'scope', 'authentication', 'state', 'reason', 'metrics'],
157
- additionalProperties: false,
158
- } as const
159
-
160
- const usageHistoryTotalsSchema = {
161
- type: 'object',
162
- properties: {
163
- input: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },
164
- output: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },
165
- cacheRead: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },
166
- cacheWrite: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },
167
- total: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },
168
- },
169
- required: ['input', 'output', 'cacheRead', 'cacheWrite', 'total'],
170
- additionalProperties: false,
171
- } as const
172
-
173
- const usageHistoryBucketSchema = {
174
- type: 'object',
175
- properties: {
176
- date: { type: 'string', pattern: '^\\d{4}-\\d{2}-\\d{2}$' },
177
- input: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },
178
- output: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },
179
- cacheRead: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },
180
- cacheWrite: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },
181
- total: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },
182
- estimatedUsd: { type: 'number', minimum: 0 },
183
- pricingComplete: { type: 'boolean' },
184
- },
185
- required: ['date', 'input', 'output', 'cacheRead', 'cacheWrite', 'total', 'pricingComplete'],
186
- additionalProperties: false,
187
- } as const
188
-
189
- const usageHistoryAvailableSchema = {
190
- type: 'object',
191
- properties: {
192
- status: { type: 'string', enum: ['available', 'partial'] },
193
- period: { type: 'string', enum: USAGE_HISTORY_PERIODS },
194
- coverageStart: { type: ['string', 'null'], pattern: '^\\d{4}-\\d{2}-\\d{2}$' },
195
- partial: { type: 'boolean' },
196
- truncated: { type: 'boolean' },
197
- rows: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },
198
- buckets: { type: 'array', items: usageHistoryBucketSchema, maxItems: MAX_HISTORY_BUCKETS },
199
- totals: usageHistoryTotalsSchema,
200
- models: {
201
- type: 'array',
202
- maxItems: MAX_HISTORY_MODELS,
203
- items: {
204
- type: 'object',
205
- properties: {
206
- providerID: { type: 'string', minLength: 1, maxLength: 128 },
207
- modelID: { type: 'string', minLength: 1, maxLength: 128 },
208
- totals: usageHistoryTotalsSchema,
209
- estimatedUsd: { type: 'number', minimum: 0 },
210
- pricingComplete: { type: 'boolean' },
211
- },
212
- required: ['providerID', 'modelID', 'totals', 'pricingComplete'],
213
- additionalProperties: false,
214
- },
215
- },
216
- pricing: {
217
- type: 'object',
218
- properties: {
219
- status: { type: 'string', enum: ['empty', 'unavailable', 'partial', 'complete'] },
220
- complete: { type: 'boolean' },
221
- billed: { const: false },
222
- estimatedUsd: { type: 'number', minimum: 0 },
223
- unpricedModels: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },
224
- },
225
- required: ['status', 'complete', 'billed', 'unpricedModels'],
226
- additionalProperties: false,
227
- },
228
- },
229
- required: [
230
- 'status',
231
- 'period',
232
- 'coverageStart',
233
- 'partial',
234
- 'truncated',
235
- 'rows',
236
- 'buckets',
237
- 'totals',
238
- 'models',
239
- 'pricing',
240
- ],
241
- additionalProperties: false,
242
- } as const
243
-
244
- const usageHistoryUnavailableSchema = {
245
- type: 'object',
246
- properties: {
247
- status: { const: 'unavailable' },
248
- reason: { type: 'string', enum: ['invalid_period', 'history_unavailable', 'history_timeout'] },
249
- },
250
- required: ['status', 'reason'],
251
- additionalProperties: false,
252
- } as const
253
-
254
- const activeContextCostInputSchema = {
255
- type: 'object',
256
- properties: {
257
- providerID: { type: ['string', 'null'], minLength: 1, maxLength: 128 },
258
- modelID: { type: ['string', 'null'], minLength: 1, maxLength: 128 },
259
- contextTokens: { type: ['number', 'null'] },
260
- },
261
- required: ['providerID', 'modelID', 'contextTokens'],
262
- additionalProperties: false,
263
- } as const
264
-
265
- const activeContextCostSchema = {
266
- oneOf: [
267
- {
268
- type: 'object',
269
- properties: {
270
- status: { const: 'estimated' },
271
- estimatedUsd: { type: 'number', minimum: 0 },
272
- billed: { const: false },
273
- basis: { const: 'pre-cache-context-tokens-times-input-price' },
274
- cacheDiscountApplied: { const: false },
275
- },
276
- required: ['status', 'estimatedUsd', 'billed', 'basis', 'cacheDiscountApplied'],
277
- additionalProperties: false,
278
- },
279
- {
280
- type: 'object',
281
- properties: {
282
- status: { const: 'unavailable' },
283
- billed: { const: false },
284
- basis: { const: 'pre-cache-context-tokens-times-input-price' },
285
- cacheDiscountApplied: { const: false },
286
- reason: {
287
- type: 'string',
288
- enum: [
289
- 'invalid-context-token-count',
290
- 'missing-model-identity',
291
- 'no-pricing',
292
- 'unknown-model',
293
- 'ambiguous-model',
294
- 'missing-cache-price',
295
- ],
296
- },
297
- },
298
- required: ['status', 'billed', 'basis', 'cacheDiscountApplied', 'reason'],
299
- additionalProperties: false,
300
- },
301
- ],
302
- } as const
303
-
304
- /** Shared definition keeps the TUI RPC client aligned with the server contract. */
305
- export const quotaRpc = Rpc.define({
306
- id: 'pantheon.quota',
307
- methods: {
308
- go_key_diagnostic: {
309
- input: { type: 'object', properties: {}, additionalProperties: false },
310
- output: {
311
- type: 'object',
312
- properties: {
313
- category: {
314
- type: 'string',
315
- enum: [
316
- 'not_run',
317
- 'already_used',
318
- 'success',
319
- 'unauthorized',
320
- 'redirect',
321
- 'http_error',
322
- 'timeout',
323
- 'network_error',
324
- ],
325
- },
326
- status: { type: 'integer', minimum: 100, maximum: 599 },
327
- content_type: {
328
- type: 'string',
329
- enum: ['application/json', 'text/plain', 'text/html', 'other', 'missing'],
330
- },
331
- error_structure: {
332
- type: 'string',
333
- enum: ['present', 'absent', 'unavailable'],
334
- },
335
- },
336
- required: ['category'],
337
- additionalProperties: false,
338
- },
339
- },
340
- status: {
341
- input: { type: 'object', properties: {}, additionalProperties: false },
342
- output: {
343
- type: 'object',
344
- properties: {
345
- providers: { type: 'array', items: providerStatusSchema },
346
- credential_resolution_failed: { const: true },
347
- },
348
- required: ['providers'],
349
- additionalProperties: false,
350
- },
351
- },
352
- usage_history: {
353
- input: {
354
- type: 'object',
355
- properties: { period: { type: 'string', enum: USAGE_HISTORY_PERIODS } },
356
- required: ['period'],
357
- additionalProperties: false,
358
- },
359
- output: {
360
- oneOf: [usageHistoryAvailableSchema, usageHistoryUnavailableSchema],
361
- },
362
- },
363
- active_context_cost: {
364
- input: activeContextCostInputSchema,
365
- output: activeContextCostSchema,
366
- },
367
- },
368
- events: {
369
- credentials_changed: {
370
- schema: { type: 'object', properties: {}, additionalProperties: false },
371
- },
372
- },
373
- })