pantheon-opencode 1.6.2-beta.1 → 1.6.2-beta.10
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/CHANGELOG.md +163 -0
- package/README.md +236 -60
- package/README.pt-BR.md +19 -1
- package/bin/pantheon-init.mjs +195 -13
- package/package.json +11 -3
- package/plugin.json +1 -1
- package/prompts/README.md +58 -0
- package/prompts/debug-issue.prompt.md +46 -0
- package/prompts/dynamic/agora-generated.txt +38 -0
- package/prompts/dynamic/orchestrate-generated.txt +51 -0
- package/prompts/focus.prompt.md +42 -0
- package/prompts/implement-feature.prompt.md +39 -0
- package/prompts/optimize-database.prompt.md +58 -0
- package/prompts/orchestrate-with-zeus.prompt.md +441 -0
- package/prompts/plan-architecture.prompt.md +59 -0
- package/prompts/quick-discovery-large-codebase.prompt.md +294 -0
- package/prompts/quick-plan-large-feature.prompt.md +197 -0
- package/prompts/semantic-summarize.md +50 -0
- package/prompts/sketch.prompt.md +91 -0
- package/prompts/subtask.prompt.md +131 -0
- package/pyproject.toml +1 -1
- package/scripts/decision-router-budget.mjs +780 -0
- package/scripts/decision-router-v2-budget.mjs +218 -0
- package/scripts/decision-router-v2-egress.mjs +272 -0
- package/scripts/decision-router.mjs +758 -0
- package/scripts/docs-check-changelog.mjs +5 -3
- package/scripts/install/component-selection.mjs +9 -4
- package/scripts/install/decision-layer-preview.mjs +376 -0
- package/scripts/install/decision-router-config.mjs +560 -0
- package/scripts/install/health-check.mjs +20 -11
- package/scripts/install/interactive.mjs +103 -14
- package/scripts/install/interrupt.mjs +4 -3
- package/scripts/install/migrate.mjs +123 -72
- package/scripts/install/opencode.mjs +178 -122
- package/scripts/install/plan.mjs +8 -1
- package/scripts/install/plugin.mjs +4 -3
- package/scripts/install/state.mjs +12 -0
- package/scripts/install/strings.mjs +22 -0
- package/scripts/install/venv.mjs +34 -17
- package/scripts/mcp_resources.py +11 -9
- package/scripts/release-notes.mjs +30 -7
- package/scripts/restore.mjs +22 -10
- package/scripts/sync-tui.mjs +3 -3
- package/scripts/test-opencode-v2-sandbox.sh +10 -6
- package/scripts/versioning.mjs +41 -5
- package/src/agents/aphrodite.md +6 -1
- package/src/agents/apollo.md +1 -0
- package/src/agents/athena.md +1 -0
- package/src/agents/demeter.md +1 -1
- package/src/agents/gaia.md +1 -0
- package/src/agents/hephaestus.md +1 -1
- package/src/agents/hermes.md +8 -10
- package/src/agents/iris.md +1 -1
- package/src/agents/mnemosyne.md +1 -0
- package/src/agents/nyx.md +1 -1
- package/src/agents/prometheus.md +1 -1
- package/src/agents/talos.md +6 -1
- package/src/agents/themis.md +1 -1
- package/src/agents/zeus.md +52 -62
- package/src/mcp/eval_store.py +11 -4
- package/src/mcp/mcp_resources.py +11 -9
- package/src/mcp/memory_mcp.py +293 -150
- package/src/pantheon/cost-command.ts +30 -133
- package/src/pantheon/jev-decision-tool.ts +347 -0
- package/src/pantheon/jev-decisions.ts +625 -0
- package/src/pantheon/local-decision-agents.ts +170 -0
- package/src/pantheon/local-decision-budget.ts +1046 -0
- package/src/pantheon/local-decision-egress-gate.ts +144 -0
- package/src/pantheon/local-decision-prompt.ts +256 -0
- package/src/pantheon/local-decision-provider-matrix.ts +44 -0
- package/src/pantheon/local-decision-router.ts +225 -0
- package/src/pantheon/local-decision-skills.ts +281 -0
- package/src/pantheon/local-decision-tool.ts +160 -0
- package/src/pantheon/local-decision-turn.ts +101 -0
- package/src/pantheon/local-decision-usage-evidence.internal.ts +168 -0
- package/src/pantheon/local-orchestration.ts +322 -0
- package/src/pantheon/model-pricing.ts +1 -536
- package/src/pantheon/pantheon-decision-catalog.ts +101 -0
- package/src/pantheon/v2-decision-budget.ts +456 -0
- package/src/pantheon/v2-decision-contracts.ts +300 -0
- package/src/pantheon/v2-decision-egress.ts +203 -0
- package/src/pantheon/v2-decision-events.ts +180 -0
- package/src/pantheon/v2-decision-heuristic.ts +121 -0
- package/src/pantheon/v2-decision-points/p1-agent.ts +91 -0
- package/src/pantheon/v2-decision-points/p10-claims.ts +243 -0
- package/src/pantheon/v2-decision-points/p11-catalog.ts +220 -0
- package/src/pantheon/v2-decision-points/p2-skill.ts +83 -0
- package/src/pantheon/v2-decision-points/p3-complexity.ts +108 -0
- package/src/pantheon/v2-decision-points/p4-memory.ts +137 -0
- package/src/pantheon/v2-decision-points/p5-themis-verify.ts +190 -0
- package/src/pantheon/v2-decision-points/p6-council.ts +161 -0
- package/src/pantheon/v2-decision-points/p7-loop.ts +263 -0
- package/src/pantheon/v2-decision-points/p8-guardrail.ts +367 -0
- package/src/pantheon/v2-decision-points/p9-memory-compaction.ts +304 -0
- package/src/pantheon/v2-decision-points.ts +242 -0
- package/src/pantheon/v2-decision-policy.ts +166 -0
- package/src/pantheon/v2-decision-premises.ts +146 -0
- package/src/pantheon/v2-decision-prompt-surface.ts +115 -0
- package/src/pantheon/v2-decision-rank.ts +91 -0
- package/src/pantheon/v2-decision-registry.ts +391 -0
- package/src/pantheon/v2-decision-resource-ids.ts +127 -0
- package/src/pantheon/v2-decision-shadow.ts +123 -0
- package/src/pantheon/v2-decision-telemetry.ts +214 -0
- package/src/pantheon/v2-decision-verify.ts +51 -0
- package/src/pantheon/v2-hook-engine.ts +307 -0
- package/src/pantheon/v2-native-decisions.ts +365 -0
- package/src/pantheon/v2-shell-hooks.ts +66 -2
- package/src/pantheon/v2-tools.ts +38 -15
- package/src/plugin-v2.ts +419 -26
- package/src/plugin.ts +4 -0
- package/src/plugins/tui/THIRD_PARTY_NOTICES.md +24 -0
- package/src/plugins/tui/dist/server-v2.d.ts +19 -11
- package/src/plugins/tui/dist/server-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/server-v2.js +19 -666
- package/src/plugins/tui/dist/server-v2.js.map +1 -1
- package/src/plugins/tui/dist/tui-v2.d.ts +11 -203
- package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui-v2.js +187 -1917
- package/src/plugins/tui/dist/tui-v2.js.map +1 -1
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/package-lock.json +17 -2
- package/src/plugins/tui/package.json +4 -2
- package/src/plugins/tui/src/cost-data.ts +607 -0
- package/src/plugins/tui/src/index-v2.tsx +213 -54
- package/src/plugins/tui/src/model-pricing.ts +536 -0
- package/src/plugins/tui/src/server-v2.ts +18 -838
- package/src/plugins/tui/tsdown.config.ts +28 -6
- package/src/plugins/tui/dist/quota-adapters.d.ts +0 -89
- package/src/plugins/tui/dist/quota-adapters.d.ts.map +0 -1
- package/src/plugins/tui/dist/quota-adapters.js +0 -1142
- package/src/plugins/tui/dist/quota-adapters.js.map +0 -1
- package/src/plugins/tui/dist/quota-cli.d.ts +0 -17
- package/src/plugins/tui/dist/quota-cli.d.ts.map +0 -1
- package/src/plugins/tui/dist/quota-cli.js +0 -184
- package/src/plugins/tui/dist/quota-cli.js.map +0 -1
- package/src/plugins/tui/dist/quota-rpc-UL2HuFRJ.js +0 -390
- package/src/plugins/tui/dist/quota-rpc-UL2HuFRJ.js.map +0 -1
- package/src/plugins/tui/src/go-key-diagnostic-ui.ts +0 -100
- package/src/plugins/tui/src/go-key-diagnostic.ts +0 -125
- package/src/plugins/tui/src/quota-adapters.ts +0 -1598
- package/src/plugins/tui/src/quota-cli.ts +0 -237
- package/src/plugins/tui/src/quota-rpc.ts +0 -209
- package/src/plugins/tui/src/quota-v2-model.ts +0 -1032
- package/src/plugins/tui/src/quota-v2.tsx +0 -986
|
@@ -1,390 +0,0 @@
|
|
|
1
|
-
import { Rpc } from "@opencode/plugin/promise/index";
|
|
2
|
-
//#region src/quota-rpc.ts
|
|
3
|
-
/** Full provider matrix approved for the V2 quota surface. */
|
|
4
|
-
const QUOTA_PROVIDER_IDS = [
|
|
5
|
-
"anthropic",
|
|
6
|
-
"chutes",
|
|
7
|
-
"cursor",
|
|
8
|
-
"github-copilot",
|
|
9
|
-
"google-agy",
|
|
10
|
-
"kilo-gateway",
|
|
11
|
-
"nanogpt",
|
|
12
|
-
"ollama-cloud",
|
|
13
|
-
"openai",
|
|
14
|
-
"opencode-go",
|
|
15
|
-
"opencode-zen",
|
|
16
|
-
"openrouter",
|
|
17
|
-
"synthetic",
|
|
18
|
-
"xai-supergrok",
|
|
19
|
-
"gemini-cli",
|
|
20
|
-
"alibaba-coding-plan",
|
|
21
|
-
"alibaba-token-plan",
|
|
22
|
-
"deepseek",
|
|
23
|
-
"kimi-code-global",
|
|
24
|
-
"kimi-code-cn",
|
|
25
|
-
"minimax-plan-global",
|
|
26
|
-
"minimax-plan-cn",
|
|
27
|
-
"xiaomi-mimo",
|
|
28
|
-
"zai-coding-plan",
|
|
29
|
-
"zhipu-coding-plan"
|
|
30
|
-
];
|
|
31
|
-
const providerStatusSchema = {
|
|
32
|
-
type: "object",
|
|
33
|
-
properties: {
|
|
34
|
-
provider: {
|
|
35
|
-
type: "string",
|
|
36
|
-
enum: QUOTA_PROVIDER_IDS
|
|
37
|
-
},
|
|
38
|
-
label: {
|
|
39
|
-
type: "string",
|
|
40
|
-
minLength: 1,
|
|
41
|
-
maxLength: 48
|
|
42
|
-
},
|
|
43
|
-
scope: {
|
|
44
|
-
type: "string",
|
|
45
|
-
enum: [
|
|
46
|
-
"account",
|
|
47
|
-
"selected_key",
|
|
48
|
-
"team",
|
|
49
|
-
"session"
|
|
50
|
-
]
|
|
51
|
-
},
|
|
52
|
-
authentication: {
|
|
53
|
-
type: "string",
|
|
54
|
-
enum: [
|
|
55
|
-
"connected",
|
|
56
|
-
"not_connected",
|
|
57
|
-
"unavailable"
|
|
58
|
-
]
|
|
59
|
-
},
|
|
60
|
-
state: {
|
|
61
|
-
type: "string",
|
|
62
|
-
enum: [
|
|
63
|
-
"available",
|
|
64
|
-
"needs_setup",
|
|
65
|
-
"unavailable"
|
|
66
|
-
]
|
|
67
|
-
},
|
|
68
|
-
reason: {
|
|
69
|
-
type: "string",
|
|
70
|
-
enum: [
|
|
71
|
-
"none",
|
|
72
|
-
"not_connected",
|
|
73
|
-
"unsupported",
|
|
74
|
-
"private_endpoint",
|
|
75
|
-
"eligibility_unverified",
|
|
76
|
-
"runtime_accounting_unavailable",
|
|
77
|
-
"cli_identity_unavailable",
|
|
78
|
-
"unsupported_credential_method",
|
|
79
|
-
"provider_error",
|
|
80
|
-
"not_subscribed",
|
|
81
|
-
"rate_limited",
|
|
82
|
-
"unauthorized",
|
|
83
|
-
"forbidden",
|
|
84
|
-
"timeout",
|
|
85
|
-
"network_error",
|
|
86
|
-
"invalid_response"
|
|
87
|
-
]
|
|
88
|
-
},
|
|
89
|
-
route_kind: {
|
|
90
|
-
type: "string",
|
|
91
|
-
enum: [
|
|
92
|
-
"api_key",
|
|
93
|
-
"console_oauth",
|
|
94
|
-
"none",
|
|
95
|
-
"unsupported"
|
|
96
|
-
]
|
|
97
|
-
},
|
|
98
|
-
retry_after_ms: {
|
|
99
|
-
type: "integer",
|
|
100
|
-
minimum: 0,
|
|
101
|
-
maximum: 36e5
|
|
102
|
-
},
|
|
103
|
-
metrics: {
|
|
104
|
-
type: "array",
|
|
105
|
-
items: { oneOf: [
|
|
106
|
-
{
|
|
107
|
-
type: "object",
|
|
108
|
-
properties: {
|
|
109
|
-
kind: { const: "provider_quota" },
|
|
110
|
-
used: {
|
|
111
|
-
type: "number",
|
|
112
|
-
minimum: 0
|
|
113
|
-
},
|
|
114
|
-
remaining: {
|
|
115
|
-
type: "number",
|
|
116
|
-
minimum: 0
|
|
117
|
-
},
|
|
118
|
-
unit: {
|
|
119
|
-
type: "string",
|
|
120
|
-
minLength: 1,
|
|
121
|
-
maxLength: 16
|
|
122
|
-
},
|
|
123
|
-
label: {
|
|
124
|
-
type: "string",
|
|
125
|
-
minLength: 1,
|
|
126
|
-
maxLength: 48
|
|
127
|
-
},
|
|
128
|
-
period: {
|
|
129
|
-
type: "string",
|
|
130
|
-
maxLength: 32
|
|
131
|
-
},
|
|
132
|
-
resetsAt: {
|
|
133
|
-
type: "number",
|
|
134
|
-
minimum: 0,
|
|
135
|
-
maximum: 864e13
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
required: [
|
|
139
|
-
"kind",
|
|
140
|
-
"used",
|
|
141
|
-
"remaining",
|
|
142
|
-
"unit",
|
|
143
|
-
"label"
|
|
144
|
-
],
|
|
145
|
-
additionalProperties: false
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
type: "object",
|
|
149
|
-
properties: {
|
|
150
|
-
kind: { const: "balance" },
|
|
151
|
-
amount: {
|
|
152
|
-
type: "number",
|
|
153
|
-
minimum: 0
|
|
154
|
-
},
|
|
155
|
-
currency: {
|
|
156
|
-
type: "string",
|
|
157
|
-
enum: ["USD", "CNY"]
|
|
158
|
-
},
|
|
159
|
-
label: {
|
|
160
|
-
type: "string",
|
|
161
|
-
minLength: 1,
|
|
162
|
-
maxLength: 48
|
|
163
|
-
},
|
|
164
|
-
status: {
|
|
165
|
-
type: "string",
|
|
166
|
-
enum: [
|
|
167
|
-
"available",
|
|
168
|
-
"unavailable",
|
|
169
|
-
"active",
|
|
170
|
-
"inactive"
|
|
171
|
-
]
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
required: [
|
|
175
|
-
"kind",
|
|
176
|
-
"amount",
|
|
177
|
-
"currency",
|
|
178
|
-
"label"
|
|
179
|
-
],
|
|
180
|
-
additionalProperties: false
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
type: "object",
|
|
184
|
-
properties: {
|
|
185
|
-
kind: { const: "estimate" },
|
|
186
|
-
amount: {
|
|
187
|
-
type: "number",
|
|
188
|
-
minimum: 0
|
|
189
|
-
},
|
|
190
|
-
unit: {
|
|
191
|
-
type: "string",
|
|
192
|
-
minLength: 1,
|
|
193
|
-
maxLength: 16
|
|
194
|
-
},
|
|
195
|
-
label: {
|
|
196
|
-
type: "string",
|
|
197
|
-
minLength: 1,
|
|
198
|
-
maxLength: 48
|
|
199
|
-
}
|
|
200
|
-
},
|
|
201
|
-
required: [
|
|
202
|
-
"kind",
|
|
203
|
-
"amount",
|
|
204
|
-
"unit",
|
|
205
|
-
"label"
|
|
206
|
-
],
|
|
207
|
-
additionalProperties: false
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
type: "object",
|
|
211
|
-
properties: {
|
|
212
|
-
kind: { const: "key_usage" },
|
|
213
|
-
amount: {
|
|
214
|
-
type: "number",
|
|
215
|
-
minimum: 0
|
|
216
|
-
},
|
|
217
|
-
currency: {
|
|
218
|
-
type: "string",
|
|
219
|
-
enum: ["USD", "CNY"]
|
|
220
|
-
},
|
|
221
|
-
label: {
|
|
222
|
-
type: "string",
|
|
223
|
-
minLength: 1,
|
|
224
|
-
maxLength: 48
|
|
225
|
-
},
|
|
226
|
-
period: {
|
|
227
|
-
type: "string",
|
|
228
|
-
maxLength: 32
|
|
229
|
-
}
|
|
230
|
-
},
|
|
231
|
-
required: [
|
|
232
|
-
"kind",
|
|
233
|
-
"amount",
|
|
234
|
-
"currency",
|
|
235
|
-
"label"
|
|
236
|
-
],
|
|
237
|
-
additionalProperties: false
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
type: "object",
|
|
241
|
-
properties: {
|
|
242
|
-
kind: { const: "session_usage" },
|
|
243
|
-
amount: {
|
|
244
|
-
type: "number",
|
|
245
|
-
minimum: 0
|
|
246
|
-
},
|
|
247
|
-
unit: {
|
|
248
|
-
type: "string",
|
|
249
|
-
minLength: 1,
|
|
250
|
-
maxLength: 16
|
|
251
|
-
},
|
|
252
|
-
label: {
|
|
253
|
-
type: "string",
|
|
254
|
-
minLength: 1,
|
|
255
|
-
maxLength: 48
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
required: [
|
|
259
|
-
"kind",
|
|
260
|
-
"amount",
|
|
261
|
-
"unit",
|
|
262
|
-
"label"
|
|
263
|
-
],
|
|
264
|
-
additionalProperties: false
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
type: "object",
|
|
268
|
-
properties: {
|
|
269
|
-
kind: { const: "provider_status" },
|
|
270
|
-
status: {
|
|
271
|
-
type: "string",
|
|
272
|
-
enum: [
|
|
273
|
-
"available",
|
|
274
|
-
"unavailable",
|
|
275
|
-
"active",
|
|
276
|
-
"inactive"
|
|
277
|
-
]
|
|
278
|
-
},
|
|
279
|
-
label: {
|
|
280
|
-
type: "string",
|
|
281
|
-
minLength: 1,
|
|
282
|
-
maxLength: 48
|
|
283
|
-
}
|
|
284
|
-
},
|
|
285
|
-
required: [
|
|
286
|
-
"kind",
|
|
287
|
-
"status",
|
|
288
|
-
"label"
|
|
289
|
-
],
|
|
290
|
-
additionalProperties: false
|
|
291
|
-
}
|
|
292
|
-
] },
|
|
293
|
-
maxItems: 16
|
|
294
|
-
}
|
|
295
|
-
},
|
|
296
|
-
required: [
|
|
297
|
-
"provider",
|
|
298
|
-
"label",
|
|
299
|
-
"scope",
|
|
300
|
-
"authentication",
|
|
301
|
-
"state",
|
|
302
|
-
"reason",
|
|
303
|
-
"metrics"
|
|
304
|
-
],
|
|
305
|
-
additionalProperties: false
|
|
306
|
-
};
|
|
307
|
-
/** Shared definition keeps the TUI RPC client aligned with the server contract. */
|
|
308
|
-
const quotaRpc = Rpc.define({
|
|
309
|
-
id: "pantheon.quota",
|
|
310
|
-
methods: {
|
|
311
|
-
go_key_diagnostic: {
|
|
312
|
-
input: {
|
|
313
|
-
type: "object",
|
|
314
|
-
properties: {},
|
|
315
|
-
additionalProperties: false
|
|
316
|
-
},
|
|
317
|
-
output: {
|
|
318
|
-
type: "object",
|
|
319
|
-
properties: {
|
|
320
|
-
category: {
|
|
321
|
-
type: "string",
|
|
322
|
-
enum: [
|
|
323
|
-
"not_run",
|
|
324
|
-
"already_used",
|
|
325
|
-
"success",
|
|
326
|
-
"unauthorized",
|
|
327
|
-
"redirect",
|
|
328
|
-
"http_error",
|
|
329
|
-
"timeout",
|
|
330
|
-
"network_error"
|
|
331
|
-
]
|
|
332
|
-
},
|
|
333
|
-
status: {
|
|
334
|
-
type: "integer",
|
|
335
|
-
minimum: 100,
|
|
336
|
-
maximum: 599
|
|
337
|
-
},
|
|
338
|
-
content_type: {
|
|
339
|
-
type: "string",
|
|
340
|
-
enum: [
|
|
341
|
-
"application/json",
|
|
342
|
-
"text/plain",
|
|
343
|
-
"text/html",
|
|
344
|
-
"other",
|
|
345
|
-
"missing"
|
|
346
|
-
]
|
|
347
|
-
},
|
|
348
|
-
error_structure: {
|
|
349
|
-
type: "string",
|
|
350
|
-
enum: [
|
|
351
|
-
"present",
|
|
352
|
-
"absent",
|
|
353
|
-
"unavailable"
|
|
354
|
-
]
|
|
355
|
-
}
|
|
356
|
-
},
|
|
357
|
-
required: ["category"],
|
|
358
|
-
additionalProperties: false
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
|
-
status: {
|
|
362
|
-
input: {
|
|
363
|
-
type: "object",
|
|
364
|
-
properties: {},
|
|
365
|
-
additionalProperties: false
|
|
366
|
-
},
|
|
367
|
-
output: {
|
|
368
|
-
type: "object",
|
|
369
|
-
properties: {
|
|
370
|
-
providers: {
|
|
371
|
-
type: "array",
|
|
372
|
-
items: providerStatusSchema
|
|
373
|
-
},
|
|
374
|
-
credential_resolution_failed: { const: true }
|
|
375
|
-
},
|
|
376
|
-
required: ["providers"],
|
|
377
|
-
additionalProperties: false
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
},
|
|
381
|
-
events: { credentials_changed: { schema: {
|
|
382
|
-
type: "object",
|
|
383
|
-
properties: {},
|
|
384
|
-
additionalProperties: false
|
|
385
|
-
} } }
|
|
386
|
-
});
|
|
387
|
-
//#endregion
|
|
388
|
-
export { quotaRpc as n, QUOTA_PROVIDER_IDS as t };
|
|
389
|
-
|
|
390
|
-
//# sourceMappingURL=quota-rpc-UL2HuFRJ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"quota-rpc-UL2HuFRJ.js","names":[],"sources":["../src/quota-rpc.ts"],"sourcesContent":["import { Rpc } from '@opencode/plugin/promise/index'\n\n/** Full provider matrix approved for the V2 quota surface. */\nexport const QUOTA_PROVIDER_IDS = [\n 'anthropic',\n 'chutes',\n 'cursor',\n 'github-copilot',\n 'google-agy',\n 'kilo-gateway',\n 'nanogpt',\n 'ollama-cloud',\n 'openai',\n 'opencode-go',\n 'opencode-zen',\n 'openrouter',\n 'synthetic',\n 'xai-supergrok',\n 'gemini-cli',\n 'alibaba-coding-plan',\n 'alibaba-token-plan',\n 'deepseek',\n 'kimi-code-global',\n 'kimi-code-cn',\n 'minimax-plan-global',\n 'minimax-plan-cn',\n 'xiaomi-mimo',\n 'zai-coding-plan',\n 'zhipu-coding-plan',\n] as const\n\nexport type QuotaProviderId = (typeof QUOTA_PROVIDER_IDS)[number]\n\n/** Safe route labels are limited to OpenCode Go and never contain request data. */\nexport type OpenCodeGoRouteKind = 'api_key' | 'console_oauth' | 'none' | 'unsupported'\n\n/** GLM plans may report up to 16 distinct quota windows in one response. */\nexport const MAX_PROVIDER_METRICS = 16\n\nconst metricSchema = {\n oneOf: [\n {\n type: 'object',\n properties: {\n kind: { const: 'provider_quota' },\n used: { type: 'number', minimum: 0 },\n remaining: { type: 'number', minimum: 0 },\n unit: { type: 'string', minLength: 1, maxLength: 16 },\n label: { type: 'string', minLength: 1, maxLength: 48 },\n period: { type: 'string', maxLength: 32 },\n resetsAt: { type: 'number', minimum: 0, maximum: 8_640_000_000_000_000 },\n },\n required: ['kind', 'used', 'remaining', 'unit', 'label'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n kind: { const: 'balance' },\n amount: { type: 'number', minimum: 0 },\n currency: { type: 'string', enum: ['USD', 'CNY'] },\n label: { type: 'string', minLength: 1, maxLength: 48 },\n status: { type: 'string', enum: ['available', 'unavailable', 'active', 'inactive'] },\n },\n required: ['kind', 'amount', 'currency', 'label'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n kind: { const: 'estimate' },\n amount: { type: 'number', minimum: 0 },\n unit: { type: 'string', minLength: 1, maxLength: 16 },\n label: { type: 'string', minLength: 1, maxLength: 48 },\n },\n required: ['kind', 'amount', 'unit', 'label'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n kind: { const: 'key_usage' },\n amount: { type: 'number', minimum: 0 },\n currency: { type: 'string', enum: ['USD', 'CNY'] },\n label: { type: 'string', minLength: 1, maxLength: 48 },\n period: { type: 'string', maxLength: 32 },\n },\n required: ['kind', 'amount', 'currency', 'label'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n kind: { const: 'session_usage' },\n amount: { type: 'number', minimum: 0 },\n unit: { type: 'string', minLength: 1, maxLength: 16 },\n label: { type: 'string', minLength: 1, maxLength: 48 },\n },\n required: ['kind', 'amount', 'unit', 'label'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n kind: { const: 'provider_status' },\n status: { type: 'string', enum: ['available', 'unavailable', 'active', 'inactive'] },\n label: { type: 'string', minLength: 1, maxLength: 48 },\n },\n required: ['kind', 'status', 'label'],\n additionalProperties: false,\n },\n ],\n} as const\n\nconst providerStatusSchema = {\n type: 'object',\n properties: {\n provider: { type: 'string', enum: QUOTA_PROVIDER_IDS },\n label: { type: 'string', minLength: 1, maxLength: 48 },\n scope: { type: 'string', enum: ['account', 'selected_key', 'team', 'session'] },\n authentication: { type: 'string', enum: ['connected', 'not_connected', 'unavailable'] },\n state: { type: 'string', enum: ['available', 'needs_setup', 'unavailable'] },\n reason: {\n type: 'string',\n enum: [\n 'none',\n 'not_connected',\n 'unsupported',\n 'private_endpoint',\n 'eligibility_unverified',\n 'runtime_accounting_unavailable',\n 'cli_identity_unavailable',\n 'unsupported_credential_method',\n 'provider_error',\n 'not_subscribed',\n 'rate_limited',\n 'unauthorized',\n 'forbidden',\n 'timeout',\n 'network_error',\n 'invalid_response',\n ],\n },\n route_kind: {\n type: 'string',\n enum: ['api_key', 'console_oauth', 'none', 'unsupported'],\n },\n retry_after_ms: { type: 'integer', minimum: 0, maximum: 3_600_000 },\n metrics: { type: 'array', items: metricSchema, maxItems: MAX_PROVIDER_METRICS },\n },\n required: ['provider', 'label', 'scope', 'authentication', 'state', 'reason', 'metrics'],\n additionalProperties: false,\n} as const\n\n/** Shared definition keeps the TUI RPC client aligned with the server contract. */\nexport const quotaRpc = Rpc.define({\n id: 'pantheon.quota',\n methods: {\n go_key_diagnostic: {\n input: { type: 'object', properties: {}, additionalProperties: false },\n output: {\n type: 'object',\n properties: {\n category: {\n type: 'string',\n enum: [\n 'not_run',\n 'already_used',\n 'success',\n 'unauthorized',\n 'redirect',\n 'http_error',\n 'timeout',\n 'network_error',\n ],\n },\n status: { type: 'integer', minimum: 100, maximum: 599 },\n content_type: {\n type: 'string',\n enum: ['application/json', 'text/plain', 'text/html', 'other', 'missing'],\n },\n error_structure: {\n type: 'string',\n enum: ['present', 'absent', 'unavailable'],\n },\n },\n required: ['category'],\n additionalProperties: false,\n },\n },\n status: {\n input: { type: 'object', properties: {}, additionalProperties: false },\n output: {\n type: 'object',\n properties: {\n providers: { type: 'array', items: providerStatusSchema },\n credential_resolution_failed: { const: true },\n },\n required: ['providers'],\n additionalProperties: false,\n },\n },\n },\n events: {\n credentials_changed: {\n schema: { type: 'object', properties: {}, additionalProperties: false },\n },\n },\n})\n"],"mappings":"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"}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import type { Context, KeymapCommand } from '@opencode/plugin/tui/context'
|
|
2
|
-
import type { GoKeyDiagnosticResult } from './go-key-diagnostic'
|
|
3
|
-
import { quotaRpc } from './quota-rpc'
|
|
4
|
-
|
|
5
|
-
const EXPLANATIONS: Record<GoKeyDiagnosticResult['category'], string> = {
|
|
6
|
-
not_run: 'No request was sent. No eligible Go API key was available or the attempt was canceled.',
|
|
7
|
-
already_used:
|
|
8
|
-
'No request was sent. The one-shot diagnostic was already used in this plugin runtime.',
|
|
9
|
-
success: 'HTTP success only; not proof of a stable quota contract or parsed quota correctness.',
|
|
10
|
-
unauthorized: 'Request rejected; cause unknown.',
|
|
11
|
-
redirect: 'Redirect was not followed.',
|
|
12
|
-
http_error: 'HTTP error; cause unknown.',
|
|
13
|
-
timeout: 'Request timed out; no retry was made.',
|
|
14
|
-
network_error: 'Network error; no retry was made.',
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const ERROR_STRUCTURE_EXPLANATIONS = {
|
|
18
|
-
present: 'erro estruturado presente',
|
|
19
|
-
absent: 'erro estruturado não detectado',
|
|
20
|
-
unavailable: 'não foi possível inspecionar',
|
|
21
|
-
} satisfies Record<NonNullable<GoKeyDiagnosticResult['error_structure']>, string>
|
|
22
|
-
|
|
23
|
-
/** Treat RPC data as untrusted: only render allowlisted categories and coarse metadata. */
|
|
24
|
-
function resultMessage(value: unknown): string {
|
|
25
|
-
if (!value || typeof value !== 'object' || !('category' in value)) {
|
|
26
|
-
return 'Diagnostic result unavailable. Request outcome unknown; no automatic retry.'
|
|
27
|
-
}
|
|
28
|
-
const category = value.category
|
|
29
|
-
if (typeof category !== 'string' || !Object.hasOwn(EXPLANATIONS, category)) {
|
|
30
|
-
return 'Diagnostic result unavailable. Request outcome unknown; no automatic retry.'
|
|
31
|
-
}
|
|
32
|
-
const status =
|
|
33
|
-
'status' in value &&
|
|
34
|
-
typeof value.status === 'number' &&
|
|
35
|
-
Number.isInteger(value.status) &&
|
|
36
|
-
value.status >= 100 &&
|
|
37
|
-
value.status <= 599
|
|
38
|
-
? ` · HTTP ${value.status}`
|
|
39
|
-
: ''
|
|
40
|
-
const contentType =
|
|
41
|
-
'content_type' in value &&
|
|
42
|
-
typeof value.content_type === 'string' &&
|
|
43
|
-
['application/json', 'text/plain', 'text/html', 'other', 'missing'].includes(value.content_type)
|
|
44
|
-
? ` · content type: ${value.content_type}`
|
|
45
|
-
: ''
|
|
46
|
-
const errorStructure =
|
|
47
|
-
category === 'unauthorized' &&
|
|
48
|
-
'status' in value &&
|
|
49
|
-
value.status === 401 &&
|
|
50
|
-
'error_structure' in value &&
|
|
51
|
-
typeof value.error_structure === 'string' &&
|
|
52
|
-
Object.hasOwn(ERROR_STRUCTURE_EXPLANATIONS, value.error_structure)
|
|
53
|
-
? ` · ${ERROR_STRUCTURE_EXPLANATIONS[value.error_structure as keyof typeof ERROR_STRUCTURE_EXPLANATIONS]}`
|
|
54
|
-
: ''
|
|
55
|
-
return `${category}${status}${contentType}${errorStructure}\n${EXPLANATIONS[category as GoKeyDiagnosticResult['category']]}`
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Native keyboard-accessible dialogs; never invoked by quota refresh or panel mounting. */
|
|
59
|
-
export function quotaGoCheckCommand(
|
|
60
|
-
context: Pick<Context, 'ui' | 'client' | 'location' | 'data'>,
|
|
61
|
-
): KeymapCommand {
|
|
62
|
-
let active = false
|
|
63
|
-
return {
|
|
64
|
-
id: 'pantheon.quota.go-check',
|
|
65
|
-
title: 'Pantheon: Go API-key check (one-shot)',
|
|
66
|
-
description: 'Manual diagnostic with confirmation; not a quota refresh',
|
|
67
|
-
group: 'Pantheon',
|
|
68
|
-
palette: true,
|
|
69
|
-
slash: { name: 'quota-go-check' },
|
|
70
|
-
run: async (): Promise<void> => {
|
|
71
|
-
if (active) return
|
|
72
|
-
active = true
|
|
73
|
-
try {
|
|
74
|
-
const confirmed = await context.ui.dialog.confirm({
|
|
75
|
-
title: 'Go API-key diagnostic — send once?',
|
|
76
|
-
message:
|
|
77
|
-
'Send one GET to https://opencode.ai/zen/go/v1/usage using the configured Go API key once? OAuth is not used. No request body, redirects, or retries. Only HTTP 401 bodies are inspected (up to 4096 bytes) for a top-level JSON error property; no error values or response details are shown. Rejection cause remains unknown. 5-second timeout. One attempt per plugin runtime, including failed or unavailable-key attempts. This does not refresh quota.',
|
|
78
|
-
label: { confirm: 'Send once', cancel: 'Cancel (no request)' },
|
|
79
|
-
})
|
|
80
|
-
if (confirmed !== true) return
|
|
81
|
-
let message: string
|
|
82
|
-
try {
|
|
83
|
-
const result = await context.client.rpc(quotaRpc).go_key_diagnostic(
|
|
84
|
-
{},
|
|
85
|
-
{
|
|
86
|
-
location: context.location ?? context.data.location.default(),
|
|
87
|
-
},
|
|
88
|
-
)
|
|
89
|
-
message = resultMessage(result)
|
|
90
|
-
} catch {
|
|
91
|
-
// Transport errors may contain credentials or provider text. Never render/log them.
|
|
92
|
-
message = 'Diagnostic result unavailable. Request outcome unknown; no automatic retry.'
|
|
93
|
-
}
|
|
94
|
-
await context.ui.dialog.alert({ title: 'Go API-key diagnostic', message })
|
|
95
|
-
} finally {
|
|
96
|
-
active = false
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
}
|
|
100
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/** Deliberately excludes response bodies, provider messages, and credential data. */
|
|
2
|
-
export type GoKeyDiagnosticResult = {
|
|
3
|
-
category:
|
|
4
|
-
| 'not_run'
|
|
5
|
-
| 'already_used'
|
|
6
|
-
| 'success'
|
|
7
|
-
| 'unauthorized'
|
|
8
|
-
| 'redirect'
|
|
9
|
-
| 'http_error'
|
|
10
|
-
| 'timeout'
|
|
11
|
-
| 'network_error'
|
|
12
|
-
status?: number
|
|
13
|
-
content_type?: 'application/json' | 'text/plain' | 'text/html' | 'other' | 'missing'
|
|
14
|
-
error_structure?: 'present' | 'absent' | 'unavailable'
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Parse at most 4 KiB; inspect only own top-level error presence, never its value. */
|
|
18
|
-
async function errorStructure(
|
|
19
|
-
body: ReadableStream<Uint8Array> | null,
|
|
20
|
-
signal: AbortSignal,
|
|
21
|
-
): Promise<NonNullable<GoKeyDiagnosticResult['error_structure']>> {
|
|
22
|
-
if (!body) return 'unavailable'
|
|
23
|
-
let reader: ReadableStreamDefaultReader<Uint8Array> | undefined
|
|
24
|
-
let abort: () => void = () => {}
|
|
25
|
-
let complete = false
|
|
26
|
-
try {
|
|
27
|
-
reader = body.getReader()
|
|
28
|
-
const aborted = new Promise<never>((_, reject) => {
|
|
29
|
-
abort = () => reject(new Error('aborted'))
|
|
30
|
-
signal.addEventListener('abort', abort, { once: true })
|
|
31
|
-
})
|
|
32
|
-
const bytes = new Uint8Array(4096)
|
|
33
|
-
let length = 0
|
|
34
|
-
while (true) {
|
|
35
|
-
signal.throwIfAborted()
|
|
36
|
-
const { done, value } = await Promise.race([reader.read(), aborted])
|
|
37
|
-
if (done) {
|
|
38
|
-
complete = true
|
|
39
|
-
break
|
|
40
|
-
}
|
|
41
|
-
if (value.byteLength > bytes.length - length) return 'unavailable'
|
|
42
|
-
bytes.set(value, length)
|
|
43
|
-
length += value.byteLength
|
|
44
|
-
}
|
|
45
|
-
const parsed: unknown = JSON.parse(
|
|
46
|
-
new TextDecoder('utf-8', { fatal: true }).decode(bytes.subarray(0, length)),
|
|
47
|
-
)
|
|
48
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return 'unavailable'
|
|
49
|
-
return Object.hasOwn(parsed, 'error') ? 'present' : 'absent'
|
|
50
|
-
} catch {
|
|
51
|
-
// Untrusted parse/stream errors may contain body text; never forward or log them.
|
|
52
|
-
return 'unavailable'
|
|
53
|
-
} finally {
|
|
54
|
-
signal.removeEventListener('abort', abort)
|
|
55
|
-
if (!complete) void (reader ? reader.cancel() : body.cancel()).catch(() => {})
|
|
56
|
-
reader?.releaseLock()
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** One explicit invocation per plugin runtime, including failed/no-credential attempts. */
|
|
61
|
-
export function createGoKeyDiagnostic() {
|
|
62
|
-
let attempted = false
|
|
63
|
-
return async (
|
|
64
|
-
resolveKey: () => Promise<string | undefined>,
|
|
65
|
-
signal: AbortSignal,
|
|
66
|
-
): Promise<GoKeyDiagnosticResult> => {
|
|
67
|
-
if (attempted) return { category: 'already_used' }
|
|
68
|
-
// Claim synchronously, before credential resolution or any other await.
|
|
69
|
-
attempted = true
|
|
70
|
-
let key: string | undefined
|
|
71
|
-
try {
|
|
72
|
-
key = await resolveKey()
|
|
73
|
-
} catch {
|
|
74
|
-
return { category: 'not_run' }
|
|
75
|
-
}
|
|
76
|
-
if (!key || signal.aborted) return { category: 'not_run' }
|
|
77
|
-
|
|
78
|
-
const timeout = AbortSignal.timeout(5_000)
|
|
79
|
-
const requestSignal = AbortSignal.any([signal, timeout])
|
|
80
|
-
try {
|
|
81
|
-
const response = await fetch('https://opencode.ai/zen/go/v1/usage', {
|
|
82
|
-
method: 'GET',
|
|
83
|
-
headers: {
|
|
84
|
-
Authorization: `Bearer ${key}`,
|
|
85
|
-
'x-opencode-session': 'pantheon-quota',
|
|
86
|
-
'user-agent': 'Pantheon-Quota/1.0',
|
|
87
|
-
},
|
|
88
|
-
redirect: 'manual',
|
|
89
|
-
signal: requestSignal,
|
|
90
|
-
})
|
|
91
|
-
const mediaType = response.headers.get('content-type')?.split(';', 1)[0]?.trim().toLowerCase()
|
|
92
|
-
const contentType = !mediaType
|
|
93
|
-
? 'missing'
|
|
94
|
-
: mediaType === 'application/json' ||
|
|
95
|
-
mediaType === 'text/plain' ||
|
|
96
|
-
mediaType === 'text/html'
|
|
97
|
-
? mediaType
|
|
98
|
-
: 'other'
|
|
99
|
-
let structure: GoKeyDiagnosticResult['error_structure']
|
|
100
|
-
if (response.status === 401 && contentType === 'application/json') {
|
|
101
|
-
structure = await errorStructure(response.body, requestSignal)
|
|
102
|
-
} else {
|
|
103
|
-
// Cancel without reading and never inspect Location.
|
|
104
|
-
void response.body?.cancel().catch(() => {})
|
|
105
|
-
if (response.status === 401) structure = 'unavailable'
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
category:
|
|
109
|
-
response.status === 401
|
|
110
|
-
? 'unauthorized'
|
|
111
|
-
: response.status >= 300 && response.status < 400
|
|
112
|
-
? 'redirect'
|
|
113
|
-
: response.ok
|
|
114
|
-
? 'success'
|
|
115
|
-
: 'http_error',
|
|
116
|
-
status: response.status,
|
|
117
|
-
content_type: contentType,
|
|
118
|
-
...(structure ? { error_structure: structure } : {}),
|
|
119
|
-
}
|
|
120
|
-
} catch {
|
|
121
|
-
// Fetch errors can include headers, URLs, or provider body text. Never forward/log them.
|
|
122
|
-
return { category: timeout.aborted ? 'timeout' : 'network_error' }
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|