pantheon-opencode 1.6.2-beta.8 → 1.6.2
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 +121 -3
- package/README.md +34 -60
- package/README.pt-BR.md +10 -12
- package/bin/pantheon-init.mjs +30 -32
- package/package.json +3 -3
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/decision-router.mjs +41 -56
- package/scripts/install/decision-router-config.mjs +67 -1
- package/scripts/install/npx-cache-sweep.mjs +103 -0
- package/scripts/install/opencode.mjs +7 -7
- package/scripts/install/plugin.mjs +4 -3
- package/scripts/install/strings.mjs +4 -0
- package/scripts/release-gates.mjs +6 -82
- package/scripts/sync-tui.mjs +3 -3
- package/src/agents/aphrodite.md +1 -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 +1 -1
- 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 +1 -1
- package/src/agents/themis.md +1 -1
- package/src/agents/zeus.md +5 -2
- package/src/pantheon/jev-decision-tool.ts +366 -114
- package/src/pantheon/jev-decisions.ts +11 -13
- package/src/pantheon/jev-escalation.ts +639 -0
- package/src/pantheon/jev-quality-score.ts +432 -0
- package/src/pantheon/jev-risk-gate.ts +479 -0
- package/src/pantheon/local-decision-prompt.ts +12 -18
- package/src/pantheon/v2-decision-telemetry.ts +14 -4
- package/src/pantheon/v2-native-decisions.ts +1 -1
- package/src/plugin-v2.ts +201 -24
- 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 -789
- package/src/plugins/tui/dist/server-v2.js.map +1 -1
- package/src/plugins/tui/dist/tui-v2.d.ts +12 -331
- package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui-v2.js +257 -5370
- 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 +2 -2
- package/src/plugins/tui/package.json +1 -1
- package/src/plugins/tui/src/index-v2.tsx +213 -86
- package/src/plugins/tui/src/server-v2.ts +18 -982
- package/src/plugins/tui/tsconfig.typecheck.json +1 -6
- package/src/plugins/tui/tsdown.config.ts +1 -11
- package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js +0 -749
- package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js.map +0 -1
- 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-DMmXBhBe.js +0 -684
- package/src/plugins/tui/dist/quota-rpc-DMmXBhBe.js.map +0 -1
- package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js +0 -118
- package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js.map +0 -1
- package/src/plugins/tui/dist/usage-history-worker.js +0 -25
- package/src/plugins/tui/dist/usage-history-worker.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 -373
- package/src/plugins/tui/src/quota-v2-model.ts +0 -1032
- package/src/plugins/tui/src/quota-v2.tsx +0 -1238
- package/src/plugins/tui/src/usage-history-contract.ts +0 -217
- package/src/plugins/tui/src/usage-history-validation.ts +0 -104
- package/src/plugins/tui/src/usage-history-view.tsx +0 -236
- package/src/plugins/tui/src/usage-history-worker.ts +0 -25
- package/src/plugins/tui/src/usage-view-model.ts +0 -272
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"quota-rpc-DMmXBhBe.js","names":[],"sources":["../src/quota-rpc.ts"],"sourcesContent":["import { Rpc } from '@opencode/plugin/promise/index'\nimport {\n MAX_HISTORY_BUCKETS,\n MAX_HISTORY_MODELS,\n USAGE_HISTORY_PERIODS,\n} from './usage-history-contract'\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\nconst usageHistoryTotalsSchema = {\n type: 'object',\n properties: {\n input: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },\n output: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },\n cacheRead: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },\n cacheWrite: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },\n total: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },\n },\n required: ['input', 'output', 'cacheRead', 'cacheWrite', 'total'],\n additionalProperties: false,\n} as const\n\nconst usageHistoryBucketSchema = {\n type: 'object',\n properties: {\n date: { type: 'string', pattern: '^\\\\d{4}-\\\\d{2}-\\\\d{2}$' },\n input: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },\n output: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },\n cacheRead: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },\n cacheWrite: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },\n total: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },\n estimatedUsd: { type: 'number', minimum: 0 },\n pricingComplete: { type: 'boolean' },\n },\n required: ['date', 'input', 'output', 'cacheRead', 'cacheWrite', 'total', 'pricingComplete'],\n additionalProperties: false,\n} as const\n\nconst usageHistoryAvailableSchema = {\n type: 'object',\n properties: {\n status: { type: 'string', enum: ['available', 'partial'] },\n period: { type: 'string', enum: USAGE_HISTORY_PERIODS },\n coverageStart: { type: ['string', 'null'], pattern: '^\\\\d{4}-\\\\d{2}-\\\\d{2}$' },\n partial: { type: 'boolean' },\n truncated: { type: 'boolean' },\n rows: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },\n buckets: { type: 'array', items: usageHistoryBucketSchema, maxItems: MAX_HISTORY_BUCKETS },\n totals: usageHistoryTotalsSchema,\n models: {\n type: 'array',\n maxItems: MAX_HISTORY_MODELS,\n items: {\n type: 'object',\n properties: {\n providerID: { type: 'string', minLength: 1, maxLength: 128 },\n modelID: { type: 'string', minLength: 1, maxLength: 128 },\n totals: usageHistoryTotalsSchema,\n estimatedUsd: { type: 'number', minimum: 0 },\n pricingComplete: { type: 'boolean' },\n },\n required: ['providerID', 'modelID', 'totals', 'pricingComplete'],\n additionalProperties: false,\n },\n },\n pricing: {\n type: 'object',\n properties: {\n status: { type: 'string', enum: ['empty', 'unavailable', 'partial', 'complete'] },\n complete: { type: 'boolean' },\n billed: { const: false },\n estimatedUsd: { type: 'number', minimum: 0 },\n unpricedModels: { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER },\n },\n required: ['status', 'complete', 'billed', 'unpricedModels'],\n additionalProperties: false,\n },\n },\n required: [\n 'status',\n 'period',\n 'coverageStart',\n 'partial',\n 'truncated',\n 'rows',\n 'buckets',\n 'totals',\n 'models',\n 'pricing',\n ],\n additionalProperties: false,\n} as const\n\nconst usageHistoryUnavailableSchema = {\n type: 'object',\n properties: {\n status: { const: 'unavailable' },\n reason: { type: 'string', enum: ['invalid_period', 'history_unavailable', 'history_timeout'] },\n },\n required: ['status', 'reason'],\n additionalProperties: false,\n} as const\n\nconst activeContextCostInputSchema = {\n type: 'object',\n properties: {\n providerID: { type: ['string', 'null'], minLength: 1, maxLength: 128 },\n modelID: { type: ['string', 'null'], minLength: 1, maxLength: 128 },\n contextTokens: { type: ['number', 'null'] },\n },\n required: ['providerID', 'modelID', 'contextTokens'],\n additionalProperties: false,\n} as const\n\nconst activeContextCostSchema = {\n oneOf: [\n {\n type: 'object',\n properties: {\n status: { const: 'estimated' },\n estimatedUsd: { type: 'number', minimum: 0 },\n billed: { const: false },\n basis: { const: 'pre-cache-context-tokens-times-input-price' },\n cacheDiscountApplied: { const: false },\n },\n required: ['status', 'estimatedUsd', 'billed', 'basis', 'cacheDiscountApplied'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n status: { const: 'unavailable' },\n billed: { const: false },\n basis: { const: 'pre-cache-context-tokens-times-input-price' },\n cacheDiscountApplied: { const: false },\n reason: {\n type: 'string',\n enum: [\n 'invalid-context-token-count',\n 'missing-model-identity',\n 'no-pricing',\n 'unknown-model',\n 'ambiguous-model',\n 'missing-cache-price',\n ],\n },\n },\n required: ['status', 'billed', 'basis', 'cacheDiscountApplied', 'reason'],\n additionalProperties: false,\n },\n ],\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 usage_history: {\n input: {\n type: 'object',\n properties: { period: { type: 'string', enum: USAGE_HISTORY_PERIODS } },\n required: ['period'],\n additionalProperties: false,\n },\n output: {\n oneOf: [usageHistoryAvailableSchema, usageHistoryUnavailableSchema],\n },\n },\n active_context_cost: {\n input: activeContextCostInputSchema,\n output: activeContextCostSchema,\n },\n },\n events: {\n credentials_changed: {\n schema: { type: 'object', properties: {}, additionalProperties: false },\n },\n },\n})\n"],"mappings":";;;;AAQA,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAqFA,MAAM,uBAAuB;CAC3B,MAAM;CACN,YAAY;EACV,UAAU;GAAE,MAAM;GAAU,MAAM;EAAmB;EACrD,OAAO;GAAE,MAAM;GAAU,WAAW;GAAG,WAAW;EAAG;EACrD,OAAO;GAAE,MAAM;GAAU,MAAM;IAAC;IAAW;IAAgB;IAAQ;GAAS;EAAE;EAC9E,gBAAgB;GAAE,MAAM;GAAU,MAAM;IAAC;IAAa;IAAiB;GAAa;EAAE;EACtF,OAAO;GAAE,MAAM;GAAU,MAAM;IAAC;IAAa;IAAe;GAAa;EAAE;EAC3E,QAAQ;GACN,MAAM;GACN,MAAM;IACJ;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;GACF;EACF;EACA,YAAY;GACV,MAAM;GACN,MAAM;IAAC;IAAW;IAAiB;IAAQ;GAAa;EAC1D;EACA,gBAAgB;GAAE,MAAM;GAAW,SAAS;GAAG,SAAS;EAAU;EAClE,SAAS;GAAE,MAAM;GAAS,OAAO,EA5GnC,OAA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;IACF;IACA,UAAU;KAAC;KAAU;KAAU;KAAS;KAAwB;IAAQ;IACxE,sBAAsB;GACxB,CACF,EAgEY;EACV;CACF;CACA,QAAQ,EACN,qBAAqB,EACnB,QAAQ;EAAE,MAAM;EAAU,YAAY,CAAC;EAAG,sBAAsB;CAAM,EACxE,EACF;AACF,CAAC"}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
const MAX_HISTORY_QUERY_MS = 5e3;
|
|
2
|
-
const USAGE_HISTORY_PERIODS = [
|
|
3
|
-
"7d",
|
|
4
|
-
"15d",
|
|
5
|
-
"30d",
|
|
6
|
-
"total"
|
|
7
|
-
];
|
|
8
|
-
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
9
|
-
const SAFE_LABEL = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/;
|
|
10
|
-
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
11
|
-
function safeCount(value, markTruncated) {
|
|
12
|
-
if (!Number.isFinite(value) || value < 0) {
|
|
13
|
-
markTruncated();
|
|
14
|
-
return 0;
|
|
15
|
-
}
|
|
16
|
-
if (!Number.isSafeInteger(value)) {
|
|
17
|
-
markTruncated();
|
|
18
|
-
return Math.min(Math.floor(value), MAX_SAFE_INTEGER);
|
|
19
|
-
}
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
22
|
-
function safeEstimate(value, markTruncated) {
|
|
23
|
-
if (value === void 0) return void 0;
|
|
24
|
-
if (!Number.isFinite(value) || value < 0) {
|
|
25
|
-
markTruncated();
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const rounded = Math.round(value * 1e8) / 1e8;
|
|
29
|
-
if (!Number.isFinite(rounded)) {
|
|
30
|
-
markTruncated();
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
return rounded;
|
|
34
|
-
}
|
|
35
|
-
function safeLabel(value, markTruncated) {
|
|
36
|
-
if (!SAFE_LABEL.test(value)) {
|
|
37
|
-
markTruncated();
|
|
38
|
-
return "unknown";
|
|
39
|
-
}
|
|
40
|
-
return value;
|
|
41
|
-
}
|
|
42
|
-
function projectTotals(value, markTruncated) {
|
|
43
|
-
return {
|
|
44
|
-
input: safeCount(value.input, markTruncated),
|
|
45
|
-
output: safeCount(value.output, markTruncated),
|
|
46
|
-
cacheRead: safeCount(value.cacheRead, markTruncated),
|
|
47
|
-
cacheWrite: safeCount(value.cacheWrite, markTruncated),
|
|
48
|
-
total: safeCount(value.total, markTruncated)
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
/** Project cost-command output to a bounded, non-identifying TUI contract. */
|
|
52
|
-
function projectUsageHistoryResult(result) {
|
|
53
|
-
let unsafeOrTruncated = false;
|
|
54
|
-
const markTruncated = () => {
|
|
55
|
-
unsafeOrTruncated = true;
|
|
56
|
-
};
|
|
57
|
-
const sourceBuckets = result.buckets;
|
|
58
|
-
const sourceModels = result.models;
|
|
59
|
-
if (sourceBuckets.length > 366 || sourceModels.length > 64) markTruncated();
|
|
60
|
-
const buckets = sourceBuckets.slice(-366).flatMap((bucket) => {
|
|
61
|
-
if (!ISO_DATE.test(bucket.date)) {
|
|
62
|
-
markTruncated();
|
|
63
|
-
return [];
|
|
64
|
-
}
|
|
65
|
-
const estimatedUsd = safeEstimate(bucket.estimatedUsd, markTruncated);
|
|
66
|
-
return [{
|
|
67
|
-
date: bucket.date,
|
|
68
|
-
...projectTotals(bucket, markTruncated),
|
|
69
|
-
...estimatedUsd === void 0 ? {} : { estimatedUsd },
|
|
70
|
-
pricingComplete: bucket.pricingComplete === true
|
|
71
|
-
}];
|
|
72
|
-
});
|
|
73
|
-
const models = sourceModels.slice(0, 64).map((model) => {
|
|
74
|
-
const estimatedUsd = safeEstimate(model.estimatedUsd, markTruncated);
|
|
75
|
-
return {
|
|
76
|
-
providerID: safeLabel(model.providerID, markTruncated),
|
|
77
|
-
modelID: safeLabel(model.modelID, markTruncated),
|
|
78
|
-
totals: projectTotals(model.totals, markTruncated),
|
|
79
|
-
...estimatedUsd === void 0 ? {} : { estimatedUsd },
|
|
80
|
-
pricingComplete: model.pricingComplete === true
|
|
81
|
-
};
|
|
82
|
-
});
|
|
83
|
-
let coverageStart = result.coverageStart;
|
|
84
|
-
if (coverageStart !== null && !ISO_DATE.test(coverageStart)) {
|
|
85
|
-
markTruncated();
|
|
86
|
-
coverageStart = null;
|
|
87
|
-
}
|
|
88
|
-
const pricingEstimate = safeEstimate(result.pricing.estimatedUsd, markTruncated);
|
|
89
|
-
const rows = safeCount(result.rows, markTruncated);
|
|
90
|
-
const totals = projectTotals(result.totals, markTruncated);
|
|
91
|
-
const unpricedModels = safeCount(result.pricing.unpricedModels, markTruncated);
|
|
92
|
-
const truncated = unsafeOrTruncated;
|
|
93
|
-
return {
|
|
94
|
-
status: result.partial || truncated ? "partial" : "available",
|
|
95
|
-
period: result.period,
|
|
96
|
-
coverageStart,
|
|
97
|
-
partial: result.partial,
|
|
98
|
-
truncated,
|
|
99
|
-
rows,
|
|
100
|
-
buckets,
|
|
101
|
-
totals,
|
|
102
|
-
models,
|
|
103
|
-
pricing: {
|
|
104
|
-
status: result.pricing.status,
|
|
105
|
-
complete: result.pricing.complete === true,
|
|
106
|
-
billed: false,
|
|
107
|
-
...pricingEstimate === void 0 ? {} : { estimatedUsd: pricingEstimate },
|
|
108
|
-
unpricedModels
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function isUsageHistoryPeriod(value) {
|
|
113
|
-
return typeof value === "string" && USAGE_HISTORY_PERIODS.includes(value);
|
|
114
|
-
}
|
|
115
|
-
//#endregion
|
|
116
|
-
export { projectUsageHistoryResult as i, USAGE_HISTORY_PERIODS as n, isUsageHistoryPeriod as r, MAX_HISTORY_QUERY_MS as t };
|
|
117
|
-
|
|
118
|
-
//# sourceMappingURL=usage-history-contract-nt1rnBPE.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usage-history-contract-nt1rnBPE.js","names":[],"sources":["../src/usage-history-contract.ts"],"sourcesContent":["export const MAX_HISTORY_BUCKETS = 366\nexport const MAX_HISTORY_MODELS = 64\nexport const MAX_HISTORY_QUERY_MS = 5_000\n\nexport type UsageHistoryRpcPeriod = '7d' | '15d' | '30d' | 'total'\n\ninterface UsageHistorySourceTotals {\n input: number\n output: number\n cacheRead: number\n cacheWrite: number\n total: number\n}\n\ninterface UsageHistorySourceBucket extends UsageHistorySourceTotals {\n date: string\n estimatedUsd?: number\n pricingComplete: boolean\n}\n\ninterface UsageHistorySourceModel {\n providerID: string\n modelID: string\n totals: UsageHistorySourceTotals\n buckets: UsageHistorySourceBucket[]\n estimatedUsd?: number\n pricingComplete: boolean\n}\n\ninterface UsageHistorySourceResult {\n period: UsageHistoryRpcPeriod\n coverageStart: string | null\n partial: boolean\n rows: number\n buckets: UsageHistorySourceBucket[]\n totals: UsageHistorySourceTotals\n models: UsageHistorySourceModel[]\n pricing: {\n status: 'empty' | 'unavailable' | 'partial' | 'complete'\n complete: boolean\n estimatedUsd?: number\n unpricedModels: number\n }\n}\n\nexport interface UsageHistoryRpcTotals {\n input: number\n output: number\n cacheRead: number\n cacheWrite: number\n total: number\n}\n\nexport interface UsageHistoryRpcBucket extends UsageHistoryRpcTotals {\n date: string\n estimatedUsd?: number\n pricingComplete: boolean\n}\n\nexport interface UsageHistoryRpcModel {\n providerID: string\n modelID: string\n totals: UsageHistoryRpcTotals\n estimatedUsd?: number\n pricingComplete: boolean\n}\n\nexport interface UsageHistoryRpcAvailable {\n status: 'available' | 'partial'\n period: UsageHistoryRpcPeriod\n coverageStart: string | null\n partial: boolean\n truncated: boolean\n rows: number\n buckets: UsageHistoryRpcBucket[]\n totals: UsageHistoryRpcTotals\n models: UsageHistoryRpcModel[]\n pricing: {\n status: 'empty' | 'unavailable' | 'partial' | 'complete'\n complete: boolean\n billed: false\n estimatedUsd?: number\n unpricedModels: number\n }\n}\n\nexport interface UsageHistoryRpcUnavailable {\n status: 'unavailable'\n reason: 'invalid_period' | 'history_unavailable' | 'history_timeout'\n}\n\nexport type UsageHistoryRpcResult = UsageHistoryRpcAvailable | UsageHistoryRpcUnavailable\n\nexport const USAGE_HISTORY_PERIODS: readonly UsageHistoryRpcPeriod[] = ['7d', '15d', '30d', 'total']\n\nconst MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER\nconst SAFE_LABEL = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/\nconst ISO_DATE = /^\\d{4}-\\d{2}-\\d{2}$/\n\nfunction safeCount(value: number, markTruncated: () => void): number {\n if (!Number.isFinite(value) || value < 0) {\n markTruncated()\n return 0\n }\n if (!Number.isSafeInteger(value)) {\n markTruncated()\n return Math.min(Math.floor(value), MAX_SAFE_INTEGER)\n }\n return value\n}\n\nfunction safeEstimate(value: number | undefined, markTruncated: () => void): number | undefined {\n if (value === undefined) return undefined\n if (!Number.isFinite(value) || value < 0) {\n markTruncated()\n return undefined\n }\n const rounded = Math.round(value * 1e8) / 1e8\n if (!Number.isFinite(rounded)) {\n markTruncated()\n return undefined\n }\n return rounded\n}\n\nfunction safeLabel(value: string, markTruncated: () => void): string {\n if (!SAFE_LABEL.test(value)) {\n markTruncated()\n return 'unknown'\n }\n return value\n}\n\nfunction projectTotals(\n value: UsageHistorySourceTotals,\n markTruncated: () => void,\n): UsageHistoryRpcTotals {\n return {\n input: safeCount(value.input, markTruncated),\n output: safeCount(value.output, markTruncated),\n cacheRead: safeCount(value.cacheRead, markTruncated),\n cacheWrite: safeCount(value.cacheWrite, markTruncated),\n total: safeCount(value.total, markTruncated),\n }\n}\n\n/** Project cost-command output to a bounded, non-identifying TUI contract. */\nexport function projectUsageHistoryResult(\n result: UsageHistorySourceResult,\n): UsageHistoryRpcAvailable {\n let unsafeOrTruncated = false\n const markTruncated = (): void => {\n unsafeOrTruncated = true\n }\n const sourceBuckets = result.buckets\n const sourceModels = result.models\n if (sourceBuckets.length > MAX_HISTORY_BUCKETS || sourceModels.length > MAX_HISTORY_MODELS) {\n markTruncated()\n }\n const buckets = sourceBuckets.slice(-MAX_HISTORY_BUCKETS).flatMap((bucket) => {\n if (!ISO_DATE.test(bucket.date)) {\n markTruncated()\n return []\n }\n const estimatedUsd = safeEstimate(bucket.estimatedUsd, markTruncated)\n return [\n {\n date: bucket.date,\n ...projectTotals(bucket, markTruncated),\n ...(estimatedUsd === undefined ? {} : { estimatedUsd }),\n pricingComplete: bucket.pricingComplete === true,\n },\n ]\n })\n const models = sourceModels.slice(0, MAX_HISTORY_MODELS).map((model) => {\n const estimatedUsd = safeEstimate(model.estimatedUsd, markTruncated)\n return {\n providerID: safeLabel(model.providerID, markTruncated),\n modelID: safeLabel(model.modelID, markTruncated),\n totals: projectTotals(model.totals, markTruncated),\n ...(estimatedUsd === undefined ? {} : { estimatedUsd }),\n pricingComplete: model.pricingComplete === true,\n }\n })\n let coverageStart = result.coverageStart\n if (coverageStart !== null && !ISO_DATE.test(coverageStart)) {\n markTruncated()\n coverageStart = null\n }\n const pricingEstimate = safeEstimate(result.pricing.estimatedUsd, markTruncated)\n const rows = safeCount(result.rows, markTruncated)\n const totals = projectTotals(result.totals, markTruncated)\n const unpricedModels = safeCount(result.pricing.unpricedModels, markTruncated)\n const truncated = unsafeOrTruncated\n return {\n status: result.partial || truncated ? 'partial' : 'available',\n period: result.period,\n coverageStart,\n partial: result.partial,\n truncated,\n rows,\n buckets,\n totals,\n models,\n pricing: {\n status: result.pricing.status,\n complete: result.pricing.complete === true,\n billed: false,\n ...(pricingEstimate === undefined ? {} : { estimatedUsd: pricingEstimate }),\n unpricedModels,\n },\n }\n}\n\nexport function isUsageHistoryPeriod(value: unknown): value is UsageHistoryRpcPeriod {\n return typeof value === 'string' && USAGE_HISTORY_PERIODS.includes(value as UsageHistoryRpcPeriod)\n}\n"],"mappings":"AAEA,MAAa,uBAAuB;AA2FpC,MAAa,wBAA0D;CAAC;CAAM;CAAO;CAAO;AAAO;AAEnG,MAAM,mBAAmB,OAAO;AAChC,MAAM,aAAa;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B,SAAS,KAA8B;AACnG"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { i as projectUsageHistoryResult, r as isUsageHistoryPeriod } from "./usage-history-contract-nt1rnBPE.js";
|
|
2
|
-
import { n as queryUsageHistory, r as resolveCostDbPath } from "./cost-data-CCZUs1aJ.js";
|
|
3
|
-
import { parentPort, workerData } from "node:worker_threads";
|
|
4
|
-
//#region src/usage-history-worker.ts
|
|
5
|
-
const port = parentPort;
|
|
6
|
-
if (port) (async () => {
|
|
7
|
-
try {
|
|
8
|
-
const input = workerData;
|
|
9
|
-
if (!isUsageHistoryPeriod(input.period)) {
|
|
10
|
-
port.postMessage({ ok: false });
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const result = await queryUsageHistory(resolveCostDbPath(), input.period);
|
|
14
|
-
port.postMessage({
|
|
15
|
-
ok: true,
|
|
16
|
-
result: projectUsageHistoryResult(result)
|
|
17
|
-
});
|
|
18
|
-
} catch {
|
|
19
|
-
port.postMessage({ ok: false });
|
|
20
|
-
}
|
|
21
|
-
})();
|
|
22
|
-
//#endregion
|
|
23
|
-
export {};
|
|
24
|
-
|
|
25
|
-
//# sourceMappingURL=usage-history-worker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usage-history-worker.js","names":[],"sources":["../src/usage-history-worker.ts"],"sourcesContent":["import { parentPort, workerData } from 'node:worker_threads'\nimport { queryUsageHistory, resolveCostDbPath } from './cost-data'\nimport { isUsageHistoryPeriod, projectUsageHistoryResult } from './usage-history-contract'\n\ninterface UsageHistoryWorkerInput {\n period?: unknown\n}\n\nconst port = parentPort\nif (port) {\n void (async () => {\n try {\n const input = workerData as UsageHistoryWorkerInput\n if (!isUsageHistoryPeriod(input.period)) {\n port.postMessage({ ok: false })\n return\n }\n const result = await queryUsageHistory(resolveCostDbPath(), input.period)\n port.postMessage({ ok: true, result: projectUsageHistoryResult(result) })\n } catch {\n // Database errors may contain the local path, SQL, or private ledger data.\n port.postMessage({ ok: false })\n }\n })()\n}\n"],"mappings":";;;;AAQA,MAAM,OAAO;AACb,IAAI,MACF,CAAM,YAAY;CAChB,IAAI;EACF,MAAM,QAAQ;EACd,IAAI,CAAC,qBAAqB,MAAM,MAAM,GAAG;GACvC,KAAK,YAAY,EAAE,IAAI,MAAM,CAAC;GAC9B;EACF;EACA,MAAM,SAAS,MAAM,kBAAkB,kBAAkB,GAAG,MAAM,MAAM;EACxE,KAAK,YAAY;GAAE,IAAI;GAAM,QAAQ,0BAA0B,MAAM;EAAE,CAAC;CAC1E,QAAQ;EAEN,KAAK,YAAY,EAAE,IAAI,MAAM,CAAC;CAChC;AACF,EAAA,CAAG"}
|
|
@@ -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
|
-
}
|