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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-v2.js","names":[],"sources":["../src/go-key-diagnostic.ts","../src/server-v2.ts"],"sourcesContent":["/** Deliberately excludes response bodies, provider messages, and credential data. */\nexport type GoKeyDiagnosticResult = {\n category:\n | 'not_run'\n | 'already_used'\n | 'success'\n | 'unauthorized'\n | 'redirect'\n | 'http_error'\n | 'timeout'\n | 'network_error'\n status?: number\n content_type?: 'application/json' | 'text/plain' | 'text/html' | 'other' | 'missing'\n error_structure?: 'present' | 'absent' | 'unavailable'\n}\n\n/** Parse at most 4 KiB; inspect only own top-level error presence, never its value. */\nasync function errorStructure(\n body: ReadableStream<Uint8Array> | null,\n signal: AbortSignal,\n): Promise<NonNullable<GoKeyDiagnosticResult['error_structure']>> {\n if (!body) return 'unavailable'\n let reader: ReadableStreamDefaultReader<Uint8Array> | undefined\n let abort: () => void = () => {}\n let complete = false\n try {\n reader = body.getReader()\n const aborted = new Promise<never>((_, reject) => {\n abort = () => reject(new Error('aborted'))\n signal.addEventListener('abort', abort, { once: true })\n })\n const bytes = new Uint8Array(4096)\n let length = 0\n while (true) {\n signal.throwIfAborted()\n const { done, value } = await Promise.race([reader.read(), aborted])\n if (done) {\n complete = true\n break\n }\n if (value.byteLength > bytes.length - length) return 'unavailable'\n bytes.set(value, length)\n length += value.byteLength\n }\n const parsed: unknown = JSON.parse(\n new TextDecoder('utf-8', { fatal: true }).decode(bytes.subarray(0, length)),\n )\n if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return 'unavailable'\n return Object.hasOwn(parsed, 'error') ? 'present' : 'absent'\n } catch {\n // Untrusted parse/stream errors may contain body text; never forward or log them.\n return 'unavailable'\n } finally {\n signal.removeEventListener('abort', abort)\n if (!complete) void (reader ? reader.cancel() : body.cancel()).catch(() => {})\n reader?.releaseLock()\n }\n}\n\n/** One explicit invocation per plugin runtime, including failed/no-credential attempts. */\nexport function createGoKeyDiagnostic() {\n let attempted = false\n return async (\n resolveKey: () => Promise<string | undefined>,\n signal: AbortSignal,\n ): Promise<GoKeyDiagnosticResult> => {\n if (attempted) return { category: 'already_used' }\n // Claim synchronously, before credential resolution or any other await.\n attempted = true\n let key: string | undefined\n try {\n key = await resolveKey()\n } catch {\n return { category: 'not_run' }\n }\n if (!key || signal.aborted) return { category: 'not_run' }\n\n const timeout = AbortSignal.timeout(5_000)\n const requestSignal = AbortSignal.any([signal, timeout])\n try {\n const response = await fetch('https://opencode.ai/zen/go/v1/usage', {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${key}`,\n 'x-opencode-session': 'pantheon-quota',\n 'user-agent': 'Pantheon-Quota/1.0',\n },\n redirect: 'manual',\n signal: requestSignal,\n })\n const mediaType = response.headers.get('content-type')?.split(';', 1)[0]?.trim().toLowerCase()\n const contentType = !mediaType\n ? 'missing'\n : mediaType === 'application/json' ||\n mediaType === 'text/plain' ||\n mediaType === 'text/html'\n ? mediaType\n : 'other'\n let structure: GoKeyDiagnosticResult['error_structure']\n if (response.status === 401 && contentType === 'application/json') {\n structure = await errorStructure(response.body, requestSignal)\n } else {\n // Cancel without reading and never inspect Location.\n void response.body?.cancel().catch(() => {})\n if (response.status === 401) structure = 'unavailable'\n }\n return {\n category:\n response.status === 401\n ? 'unauthorized'\n : response.status >= 300 && response.status < 400\n ? 'redirect'\n : response.ok\n ? 'success'\n : 'http_error',\n status: response.status,\n content_type: contentType,\n ...(structure ? { error_structure: structure } : {}),\n }\n } catch {\n // Fetch errors can include headers, URLs, or provider body text. Never forward/log them.\n return { category: timeout.aborted ? 'timeout' : 'network_error' }\n }\n }\n}\n","import { Worker } from 'node:worker_threads'\nimport { Plugin } from '@opencode/plugin'\nimport type { Context } from '@opencode/plugin/promise/plugin'\nimport type { RpcCallContext, RpcRegistration } from '@opencode/plugin/promise/rpc'\nimport { estimateActiveContextCost } from './cost-data'\nimport { createGoKeyDiagnostic } from './go-key-diagnostic'\nimport {\n isOpenAICodexOAuthMethod,\n isOpenCodeConsoleOAuthMethod,\n QUOTA_PROVIDER_CATALOG,\n type QuotaAdapterContext,\n type QuotaMetric,\n runQuotaAdapter,\n} from './quota-adapters'\nimport { queryAlibabaTokenPlanUsage } from './quota-cli'\nimport {\n type OpenCodeGoRouteKind,\n QUOTA_PROVIDER_IDS,\n type QuotaProviderId,\n quotaRpc,\n} from './quota-rpc'\nimport {\n isUsageHistoryPeriod,\n MAX_HISTORY_QUERY_MS,\n type UsageHistoryRpcResult,\n} from './usage-history-contract'\n\nconst CREDENTIAL_CACHE_TTL_MS = 30_000\nconst ADAPTER_CACHE_TTL_MS = 20_000\n\nfunction queryUsageHistoryInWorker(\n period: string,\n signal: AbortSignal,\n): Promise<UsageHistoryRpcResult> {\n if (!isUsageHistoryPeriod(period)) {\n return Promise.resolve({ status: 'unavailable', reason: 'invalid_period' })\n }\n return new Promise((resolve, reject) => {\n let settled = false\n let worker: Worker\n try {\n worker = new Worker(new URL('./usage-history-worker.js', import.meta.url), {\n workerData: { period },\n resourceLimits: { maxOldGenerationSizeMb: 64, stackSizeMb: 2 },\n })\n } catch {\n resolve({ status: 'unavailable', reason: 'history_unavailable' })\n return\n }\n let timer: ReturnType<typeof setTimeout>\n\n const onAbort = (): void => {\n if (settled) return\n settled = true\n clearTimeout(timer)\n signal.removeEventListener('abort', onAbort)\n void worker.terminate()\n reject(new DOMException('Usage history request aborted', 'AbortError'))\n }\n const finish = (result: UsageHistoryRpcResult): void => {\n if (settled) return\n settled = true\n clearTimeout(timer)\n signal.removeEventListener('abort', onAbort)\n void worker.terminate()\n resolve(result)\n }\n\n timer = setTimeout(() => {\n finish({ status: 'unavailable', reason: 'history_timeout' })\n }, MAX_HISTORY_QUERY_MS)\n signal.addEventListener('abort', onAbort, { once: true })\n worker.once('message', (message: unknown) => {\n if (\n typeof message === 'object' &&\n message !== null &&\n 'ok' in message &&\n message.ok === true &&\n 'result' in message &&\n typeof message.result === 'object' &&\n message.result !== null\n ) {\n finish(message.result as UsageHistoryRpcResult)\n return\n }\n finish({ status: 'unavailable', reason: 'history_unavailable' })\n })\n worker.once('error', () => finish({ status: 'unavailable', reason: 'history_unavailable' }))\n worker.once('exit', () => {\n if (!settled) finish({ status: 'unavailable', reason: 'history_unavailable' })\n })\n if (signal.aborted) onAbort()\n })\n}\n\ntype ResolvedCredential = {\n readonly method?: 'oauth' | 'key' | 'unsupported'\n readonly routeKind?: OpenCodeGoRouteKind\n /** Only adapters receive this secret; blocked sources retain only method status. */\n readonly secret?: string\n /** OpenCode Go's fixed API-key fallback after its Console OAuth request fails. */\n readonly fallbackSecret?: string\n /** A tiny, non-secret projection of OAuth metadata required by fixed adapters. */\n readonly adapterContext?: QuotaAdapterContext\n}\ntype CachedCredential = {\n readonly result: ResolvedCredential\n readonly expiresAt: number\n readonly expiryTimer: ReturnType<typeof setTimeout>\n}\ntype ProviderStatus = {\n provider: QuotaProviderId\n label: string\n scope: 'account' | 'selected_key' | 'team' | 'session'\n authentication: 'connected' | 'not_connected' | 'unavailable'\n state: 'available' | 'needs_setup' | 'unavailable'\n reason:\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 retry_after_ms?: number\n route_kind?: OpenCodeGoRouteKind\n metrics: QuotaMetric[]\n}\n\nconst PROVIDER_IDS = QUOTA_PROVIDER_IDS\n\nfunction safeMetadataValue(\n metadata: Record<string, unknown> | undefined,\n names: readonly string[],\n): string | undefined {\n if (!metadata) return undefined\n for (const name of names) {\n const value = metadata[name]\n if (typeof value === 'string' && value.length <= 128 && /^[A-Za-z0-9._:-]+$/.test(value)) {\n return value\n }\n }\n return undefined\n}\n\nfunction projectAdapterContext(\n provider: QuotaProviderId,\n metadata: unknown,\n methodID: unknown,\n): QuotaAdapterContext | undefined {\n if (provider === 'openai') {\n if (isOpenAICodexOAuthMethod(methodID)) return { methodID }\n return undefined\n }\n if (provider === 'opencode-go') {\n if (!isOpenCodeConsoleOAuthMethod(methodID)) return undefined\n if (typeof metadata !== 'object' || metadata === null || Array.isArray(metadata)) {\n return { methodID }\n }\n const record = metadata as Record<string, unknown>\n if (record.orgID === undefined || record.orgID === null) return { methodID }\n if (typeof record.orgID !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/.test(record.orgID)) {\n return undefined\n }\n return { methodID, orgId: record.orgID }\n }\n if (typeof metadata !== 'object' || metadata === null || Array.isArray(metadata)) return undefined\n const record = metadata as Record<string, unknown>\n const projectId = safeMetadataValue(record, ['projectID', 'projectId', 'quotaProjectId'])\n const accountId = safeMetadataValue(record, ['accountID', 'accountId'])\n const orgId = safeMetadataValue(record, ['orgID', 'orgId'])\n if (!projectId && !accountId && !orgId) return undefined\n return {\n ...(projectId ? { projectId } : {}),\n ...(accountId ? { accountId } : {}),\n ...(orgId ? { orgId } : {}),\n }\n}\n\n/**\n * Accept only the official OpenCode Console default and its retired alias.\n * The selected Console token is never sent to a credential-supplied host.\n */\nfunction isApprovedOpenCodeConsoleServer(metadata: unknown): boolean {\n if (typeof metadata !== 'object' || metadata === null || Array.isArray(metadata)) return true\n const record = metadata as Record<string, unknown>\n if (!Object.hasOwn(record, 'server')) return true\n const server = record.server\n if (typeof server !== 'string' || server.length === 0 || server.length > 2_048) return false\n if (server.trim() !== server) return false\n\n let url: URL\n try {\n url = new URL(server)\n } catch {\n return false\n }\n if (\n url.protocol !== 'https:' ||\n url.username !== '' ||\n url.password !== '' ||\n url.port !== '' ||\n url.search !== '' ||\n url.hash !== ''\n ) {\n return false\n }\n\n const path = url.pathname.replace(/\\/$/, '')\n if (url.hostname === 'opencode.ai') return path === '/console'\n return url.hostname === 'console.opencode.ai' && (path === '' || path === '/console')\n}\n\nfunction routeKindField(\n provider: QuotaProviderId,\n credential?: ResolvedCredential,\n effectiveRouteKind?: OpenCodeGoRouteKind,\n): { route_kind?: OpenCodeGoRouteKind } {\n return provider === 'opencode-go'\n ? { route_kind: effectiveRouteKind ?? credential?.routeKind ?? 'none' }\n : {}\n}\n\n/**\n * OpenCode Go follows the upstream quota plugin's key order: process environment, the\n * effective OpenCode provider settings, then a selected OpenCode API-key connection.\n * Provider settings are read through the host API; Pantheon never parses OpenCode files.\n */\nasync function configuredOpenCodeGoApiKey(context: Context): Promise<string | undefined> {\n const environmentKey = process.env.OPENCODE_API_KEY?.trim()\n if (environmentKey) return environmentKey\n\n for (const providerID of ['opencode-go', 'opencode']) {\n let value: unknown\n try {\n value = (await context.provider.get({ providerID })).data.settings?.apiKey\n } catch {\n continue\n }\n if (typeof value !== 'string') continue\n const configured = value.trim()\n if (!configured) continue\n\n const environmentTemplate = configured.match(/^\\{env:([A-Za-z_][A-Za-z0-9_]*)\\}$/)\n if (environmentTemplate) {\n if (environmentTemplate[1] !== 'OPENCODE_API_KEY') continue\n const resolved = process.env.OPENCODE_API_KEY?.trim()\n if (resolved) return resolved\n continue\n }\n if (configured.startsWith('{env:')) continue\n return configured\n }\n return undefined\n}\n\n/**\n * Resolve only listed, selected credential connections in the closed provider\n * catalog. Only the minimum access-token/key field is retained in memory.\n */\nfunction createCredentialResolver(context: Context) {\n const cache = new Map<QuotaProviderId, CachedCredential>()\n const pending = new Map<QuotaProviderId, Promise<ResolvedCredential>>()\n let integrations: Map<string, Set<string>> | undefined\n let integrationListPending: Promise<Map<string, Set<string>>> | undefined\n let generation = 0\n let disposed = false\n\n function clearCache(): void {\n for (const cached of cache.values()) clearTimeout(cached.expiryTimer)\n cache.clear()\n integrations = undefined\n integrationListPending = undefined\n }\n\n async function listCredentialConnections(): Promise<Map<string, Set<string>>> {\n if (integrations) return integrations\n if (integrationListPending) return integrationListPending\n const startedAtGeneration = generation\n let request: Promise<Map<string, Set<string>>>\n request = context.integration\n .list()\n .then((value) => {\n const connectionsByIntegration = new Map<string, Set<string>>()\n for (const integration of value.data) {\n const connections = new Set<string>()\n if (Array.isArray(integration.connections)) {\n for (const connection of integration.connections) {\n if (connection.type === 'credential') {\n connections.add(`${connection.id}\\0${connection.method}`)\n }\n }\n }\n connectionsByIntegration.set(integration.id, connections)\n }\n if (!disposed && generation === startedAtGeneration) integrations = connectionsByIntegration\n return connectionsByIntegration\n })\n .finally(() => {\n if (integrationListPending === request) integrationListPending = undefined\n })\n integrationListPending = request\n return request\n }\n\n async function load(provider: QuotaProviderId, goKeyOnly = false): Promise<ResolvedCredential> {\n const definition = QUOTA_PROVIDER_CATALOG[provider]\n // Quota visibility is tied to a selected OpenCode credential connection;\n // local CLI identity is outside that credential context.\n if (definition.source === 'local-cli') return {}\n const configuredGoKey =\n provider === 'opencode-go' ? await configuredOpenCodeGoApiKey(context) : undefined\n if (goKeyOnly && configuredGoKey) {\n return { method: 'key', secret: configuredGoKey, routeKind: 'api_key' }\n }\n try {\n let listedConnections: Map<string, Set<string>>\n try {\n listedConnections = await listCredentialConnections()\n } catch (error) {\n // A configured OpenCode Go key can still be used if integration discovery fails.\n // Without it, retain the normal selected-connection error behavior.\n if (provider !== 'opencode-go' || !configuredGoKey) throw error\n listedConnections = new Map()\n }\n if (provider === 'opencode-go') {\n const activeListed = async (integrationID: string) => {\n const connections = listedConnections.get(integrationID)\n if (!connections || connections.size === 0) return undefined\n const active = await context.integration.connection.active(integrationID)\n if (active?.type !== 'credential' || !connections.has(`${active.id}\\0${active.method}`)) {\n return undefined\n }\n return active\n }\n\n let consoleCredential: ResolvedCredential | undefined\n let unsupportedConsoleLogin = false\n if (!goKeyOnly) {\n let activeConsole: Awaited<ReturnType<typeof activeListed>>\n try {\n activeConsole = await activeListed('opencode')\n } catch {\n // A Console lookup failure must not prevent using a selected Go API key.\n }\n if (activeConsole?.method === 'oauth' && activeConsole.status?.status !== 'needs_auth') {\n try {\n const resolved = await context.integration.connection.resolve(activeConsole)\n if (\n resolved?.type === 'oauth' &&\n resolved.access.trim().length > 0 &&\n isOpenCodeConsoleOAuthMethod(resolved.methodID) &&\n isApprovedOpenCodeConsoleServer(resolved.metadata)\n ) {\n const adapterContext = projectAdapterContext(\n provider,\n resolved.metadata,\n resolved.methodID,\n )\n if (adapterContext) {\n consoleCredential = {\n method: 'oauth',\n secret: resolved.access.trim(),\n routeKind: 'console_oauth',\n adapterContext,\n }\n } else {\n unsupportedConsoleLogin = true\n }\n } else if (resolved?.type === 'oauth') {\n unsupportedConsoleLogin = true\n }\n } catch {\n // A failed Console sign-in is allowed to fall through to a listed API key.\n }\n } else if (activeConsole?.method === 'oauth') {\n unsupportedConsoleLogin = activeConsole.status?.status !== 'needs_auth'\n }\n }\n\n let activePrimary: Awaited<ReturnType<typeof activeListed>>\n if (!configuredGoKey) {\n try {\n activePrimary = await activeListed('opencode-go')\n } catch {\n // An API-key lookup failure must not discard an already resolved Console login.\n }\n }\n const unsupportedPrimaryLogin =\n !configuredGoKey && activePrimary !== undefined && activePrimary.method !== 'key'\n let apiKey = configuredGoKey\n for (const integrationID of configuredGoKey ? [] : ['opencode-go', 'opencode']) {\n let active: Awaited<ReturnType<typeof activeListed>>\n try {\n active =\n integrationID === 'opencode-go' ? activePrimary : await activeListed(integrationID)\n } catch {\n // A failed key lookup does not invalidate another selected credential.\n continue\n }\n if (!active) continue\n if (goKeyOnly && active.method !== 'key') return {}\n if (active.method !== 'key' || active.status?.status === 'needs_auth') continue\n try {\n const resolved = await context.integration.connection.resolve(active)\n if (resolved?.type === 'key' && resolved.key.trim().length > 0) {\n apiKey = resolved.key.trim()\n break\n }\n } catch {\n // Try the next explicitly selected OpenCode API-key integration.\n }\n }\n\n if (consoleCredential) {\n return {\n ...consoleCredential,\n ...(apiKey ? { fallbackSecret: apiKey } : {}),\n }\n }\n if (apiKey) return { method: 'key', secret: apiKey, routeKind: 'api_key' }\n if (unsupportedConsoleLogin || unsupportedPrimaryLogin) {\n return { method: 'unsupported', routeKind: 'unsupported' }\n }\n return {}\n }\n\n const integrationIDs = [\n definition.integrationID,\n ...(definition.fallbackIntegrationIDs ?? []),\n ]\n for (const integrationID of integrationIDs) {\n const integrationConnections = listedConnections.get(integrationID)\n if (!integrationConnections || integrationConnections.size === 0) continue\n\n const active = await context.integration.connection.active(integrationID)\n if (active?.type !== 'credential') continue\n const isListedActiveConnection = integrationConnections.has(\n `${active.id}\\0${active.method}`,\n )\n if (!isListedActiveConnection) continue\n // The manual diagnostic must not even resolve an OAuth connection.\n if (goKeyOnly && active.method !== 'key') return {}\n if (active.status?.status === 'needs_auth') continue\n\n if (active.method !== 'oauth' && active.method !== 'key') {\n continue\n }\n if (!definition.methods.includes(active.method)) continue\n\n const resolved = await context.integration.connection.resolve(active)\n if (\n active.method === 'oauth' &&\n resolved?.type === 'oauth' &&\n resolved.access.trim().length > 0\n ) {\n const accessToken = resolved.access\n if (!accessToken) return {}\n if (provider === 'opencode-zen' && !isApprovedOpenCodeConsoleServer(resolved.metadata)) {\n return { method: 'unsupported' }\n }\n const adapterContext = projectAdapterContext(\n provider,\n resolved.metadata,\n resolved.methodID,\n )\n return {\n method: 'oauth',\n ...(definition.adapter ? { secret: accessToken } : {}),\n ...(adapterContext ? { adapterContext } : {}),\n }\n }\n if (active.method === 'key' && resolved?.type === 'key') {\n if (resolved.key.trim().length === 0) return {}\n if (!definition.adapter) return { method: 'key' }\n if (resolved.key.length > 0) return { method: 'key', secret: resolved.key }\n }\n return {}\n }\n return {}\n } catch {\n // Host errors may contain credentials, provider data, or arbitrary thrown metadata.\n console.warn('[pantheon-tui quota] credential resolution failed (exception)')\n throw new Error('Credential resolution failed')\n }\n }\n\n return {\n async resolveActiveGoKey(): Promise<string | undefined> {\n if (disposed) return undefined\n // Fresh resolution avoids a stale selected key and never falls back to Console OAuth.\n const startedAtGeneration = generation\n const credential = await load('opencode-go', true)\n if (disposed || generation !== startedAtGeneration) return undefined\n return credential.method === 'key' && credential.routeKind === 'api_key'\n ? credential.secret\n : undefined\n },\n async resolve(provider: QuotaProviderId): Promise<ResolvedCredential> {\n if (disposed) return {}\n const now = Date.now()\n const cached = cache.get(provider)\n if (cached && cached.expiresAt > now) return cached.result\n if (cached) {\n clearTimeout(cached.expiryTimer)\n cache.delete(provider)\n }\n const existing = pending.get(provider)\n if (existing) return existing\n\n const startedAtGeneration = generation\n let resolution: Promise<ResolvedCredential>\n resolution = load(provider)\n .then((result) => {\n if (disposed || generation !== startedAtGeneration) return {}\n const expiresAt = Date.now() + CREDENTIAL_CACHE_TTL_MS\n const expiryTimer = setTimeout(() => {\n if (cache.get(provider)?.expiryTimer === expiryTimer) cache.delete(provider)\n }, CREDENTIAL_CACHE_TTL_MS)\n expiryTimer.unref()\n cache.set(provider, { result, expiresAt, expiryTimer })\n return result\n })\n .finally(() => {\n if (pending.get(provider) === resolution) pending.delete(provider)\n })\n pending.set(provider, resolution)\n return resolution\n },\n currentGeneration(): number {\n return generation\n },\n isCurrent(version: number): boolean {\n return !disposed && generation === version\n },\n invalidate(): void {\n generation += 1\n clearCache()\n pending.clear()\n },\n dispose(): void {\n disposed = true\n generation += 1\n clearCache()\n pending.clear()\n },\n }\n}\n\nfunction isQuotaSourceInvalidationEvent(type: string): boolean {\n return (\n type === 'credential.updated' ||\n type === 'credential.switched' ||\n type === 'integration.updated' ||\n type === 'provider.updated'\n )\n}\n\nfunction createAdapterExecutor(\n shutdownSignal: AbortSignal,\n queryCli: typeof queryAlibabaTokenPlanUsage,\n) {\n const MAX_CONCURRENCY = 3\n type AdapterOutcome = Awaited<ReturnType<typeof runQuotaAdapter>>\n type PendingAdapter = {\n controller: AbortController\n callers: Set<symbol>\n settled: boolean\n promise: Promise<AdapterOutcome>\n }\n const cache = new Map<QuotaProviderId, { expiresAt: number; result: AdapterOutcome }>()\n const pending = new Map<QuotaProviderId, PendingAdapter>()\n const cooldown = new Map<QuotaProviderId, number>()\n let activeRequests = 0\n let generation = 0\n const waiters: Array<{\n signal: AbortSignal\n resolve: (release: (() => void) | undefined) => void\n onAbort: () => void\n }> = []\n let invalidationController = new AbortController()\n\n function releaseRequest(): () => void {\n let released = false\n return () => {\n if (released) return\n released = true\n while (waiters.length > 0) {\n const waiter = waiters.shift()\n if (!waiter) break\n waiter.signal.removeEventListener('abort', waiter.onAbort)\n if (waiter.signal.aborted) {\n waiter.resolve(undefined)\n continue\n }\n waiter.resolve(releaseRequest())\n return\n }\n activeRequests -= 1\n }\n }\n\n function acquireRequest(signal: AbortSignal): Promise<(() => void) | undefined> {\n if (signal.aborted) return Promise.resolve(undefined)\n if (activeRequests < MAX_CONCURRENCY) {\n activeRequests += 1\n return Promise.resolve(releaseRequest())\n }\n return new Promise((resolve) => {\n const waiter = {\n signal,\n resolve,\n onAbort: () => {\n const index = waiters.indexOf(waiter)\n if (index >= 0) waiters.splice(index, 1)\n resolve(undefined)\n },\n }\n waiters.push(waiter)\n signal.addEventListener('abort', waiter.onAbort, { once: true })\n })\n }\n\n function subscribe(entry: PendingAdapter, requestSignal: AbortSignal): Promise<AdapterOutcome> {\n requestSignal.throwIfAborted()\n const caller = Symbol()\n entry.callers.add(caller)\n return new Promise((resolve, reject) => {\n let detached = false\n const detach = () => {\n if (detached) return\n detached = true\n requestSignal.removeEventListener('abort', onAbort)\n entry.callers.delete(caller)\n if (!entry.settled && entry.callers.size === 0) entry.controller.abort()\n }\n const onAbort = () => {\n detach()\n reject(requestSignal.reason)\n }\n requestSignal.addEventListener('abort', onAbort, { once: true })\n if (requestSignal.aborted) {\n onAbort()\n return\n }\n entry.promise.then(\n (result) => {\n detach()\n resolve(result)\n },\n (error: unknown) => {\n detach()\n reject(error)\n },\n )\n })\n }\n\n return {\n async run(\n provider: QuotaProviderId,\n secret: string | undefined,\n requestSignal: AbortSignal,\n adapterContext?: QuotaAdapterContext,\n fallbackSecret?: string,\n ) {\n requestSignal.throwIfAborted()\n const now = Date.now()\n const until = cooldown.get(provider)\n if (until !== undefined && until > now) {\n return { reason: 'rate_limited' as const, retryAfterMs: until - now }\n }\n const cached = cache.get(provider)\n if (cached && cached.expiresAt > now) return cached.result\n const existing = pending.get(provider)\n if (existing && !existing.controller.signal.aborted) return subscribe(existing, requestSignal)\n if (existing) pending.delete(provider)\n\n const startedAtGeneration = generation\n const controller = new AbortController()\n const signal = AbortSignal.any([\n shutdownSignal,\n invalidationController.signal,\n controller.signal,\n ])\n const entry: PendingAdapter = {\n controller,\n callers: new Set(),\n settled: false,\n promise: Promise.resolve({ reason: 'provider_error' }),\n }\n pending.set(provider, entry)\n entry.promise = acquireRequest(signal)\n .then(async (release) => {\n if (!release) return { reason: 'provider_error' as const }\n try {\n return await runQuotaAdapter(\n provider,\n secret,\n signal,\n queryCli,\n adapterContext,\n fallbackSecret,\n )\n } finally {\n release()\n }\n })\n .then((result) => {\n if (generation === startedAtGeneration && !signal.aborted && 'state' in result) {\n cache.set(provider, {\n expiresAt: Date.now() + ADAPTER_CACHE_TTL_MS,\n result,\n })\n } else if (\n generation === startedAtGeneration &&\n 'reason' in result &&\n result.reason === 'rate_limited' &&\n result.retryAfterMs !== undefined\n ) {\n cooldown.set(provider, Date.now() + result.retryAfterMs)\n }\n return result\n })\n .finally(() => {\n entry.settled = true\n if (pending.get(provider) === entry) pending.delete(provider)\n })\n return subscribe(entry, requestSignal)\n },\n invalidate(): void {\n generation += 1\n invalidationController.abort()\n invalidationController = new AbortController()\n cache.clear()\n pending.clear()\n cooldown.clear()\n },\n }\n}\n\nasync function getProviderStatus(\n resolver: ReturnType<typeof createCredentialResolver>,\n adapters: ReturnType<typeof createAdapterExecutor>,\n requestSignal: AbortSignal,\n): Promise<{ providers: ProviderStatus[]; credential_resolution_failed?: true }> {\n requestSignal.throwIfAborted()\n let credentialResolutionFailed = false\n const results = await Promise.all(\n PROVIDER_IDS.map(async (provider): Promise<ProviderStatus | undefined> => {\n const definition = QUOTA_PROVIDER_CATALOG[provider]\n try {\n requestSignal.throwIfAborted()\n const credentialGeneration = resolver.currentGeneration()\n let credential: ResolvedCredential\n try {\n credential = await resolver.resolve(provider)\n } catch {\n requestSignal.throwIfAborted()\n credentialResolutionFailed = true\n return undefined\n }\n requestSignal.throwIfAborted()\n if (!credential.method) return undefined\n if (!resolver.isCurrent(credentialGeneration)) {\n return {\n provider,\n label: definition.label,\n scope: definition.scope,\n authentication: 'unavailable',\n state: 'unavailable',\n reason: 'provider_error',\n ...routeKindField(provider, credential),\n metrics: [],\n }\n }\n if (\n credential.method === 'unsupported' ||\n !definition.methods.includes(credential.method)\n ) {\n return {\n provider,\n label: definition.label,\n scope: definition.scope,\n authentication: 'connected',\n state: 'unavailable',\n reason: 'unsupported_credential_method',\n ...routeKindField(provider, credential),\n metrics: [],\n }\n }\n if (!definition.adapter) {\n return {\n provider,\n label: definition.label,\n scope: definition.scope,\n authentication: 'connected',\n state: 'unavailable',\n reason: definition.blockedReason ?? 'unsupported',\n ...routeKindField(provider, credential),\n metrics: [],\n }\n }\n if (!credential.secret) {\n return {\n provider,\n label: definition.label,\n scope: definition.scope,\n authentication: 'unavailable',\n state: 'unavailable',\n reason: 'provider_error',\n ...routeKindField(provider, credential),\n metrics: [],\n }\n }\n const result = await adapters.run(\n provider,\n credential.secret,\n requestSignal,\n credential.adapterContext,\n credential.fallbackSecret,\n )\n requestSignal.throwIfAborted()\n if (!resolver.isCurrent(credentialGeneration)) {\n return {\n provider,\n label: definition.label,\n scope: definition.scope,\n authentication: 'unavailable',\n state: 'unavailable',\n reason: 'provider_error',\n ...routeKindField(provider, credential),\n metrics: [],\n }\n }\n if ('state' in result) {\n return {\n provider,\n label: definition.label,\n scope: definition.scope,\n authentication: 'connected',\n state: 'available',\n reason: 'none',\n ...routeKindField(provider, credential, result.routeKind),\n metrics: result.metrics,\n }\n }\n return {\n provider,\n label: definition.label,\n scope: definition.scope,\n authentication: 'connected',\n state: 'unavailable',\n reason: result.reason,\n ...routeKindField(provider, credential, result.routeKind),\n ...(result.retryAfterMs === undefined\n ? {}\n : { retry_after_ms: Math.ceil(result.retryAfterMs) }),\n metrics: [],\n }\n } catch {\n requestSignal.throwIfAborted()\n return {\n provider,\n label: definition.label,\n scope: definition.scope,\n authentication: 'unavailable',\n state: 'unavailable',\n reason: 'provider_error',\n ...routeKindField(provider),\n metrics: [],\n }\n }\n }),\n )\n const providers = results.filter((provider): provider is ProviderStatus => provider !== undefined)\n return {\n providers,\n ...(credentialResolutionFailed ? { credential_resolution_failed: true as const } : {}),\n }\n}\n\nexport function createQuotaPlugin(\n queryCli: typeof queryAlibabaTokenPlanUsage = queryAlibabaTokenPlanUsage,\n) {\n const goKeyDiagnostic = createGoKeyDiagnostic()\n return Plugin.define({\n id: 'pantheon.tui.server',\n async setup(context: Context) {\n const resolver = createCredentialResolver(context)\n const shutdownController = new AbortController()\n const adapters = createAdapterExecutor(shutdownController.signal, queryCli)\n const eventController = new AbortController()\n let registration: RpcRegistration<typeof quotaRpc> | undefined\n const eventTask = (async () => {\n try {\n for await (const event of context.event.subscribe({ signal: eventController.signal })) {\n if (isQuotaSourceInvalidationEvent(event.type)) {\n resolver.invalidate()\n adapters.invalidate()\n if (registration) {\n try {\n await registration.events.emit('credentials_changed', {})\n } catch {\n console.warn(\n 'Quota credential-change notification failed; periodic refresh remains active',\n )\n }\n }\n }\n }\n } catch {\n if (!eventController.signal.aborted) {\n resolver.invalidate()\n adapters.invalidate()\n }\n }\n })()\n\n try {\n registration = await context.rpc.register(quotaRpc, {\n go_key_diagnostic: async (_input, callContext) =>\n goKeyDiagnostic(\n () => resolver.resolveActiveGoKey(),\n AbortSignal.any([callContext.signal, shutdownController.signal]),\n ),\n status: async (_input, callContext: RpcCallContext<typeof quotaRpc.methods.status>) =>\n getProviderStatus(resolver, adapters, callContext.signal),\n usage_history: async (\n input,\n callContext: RpcCallContext<typeof quotaRpc.methods.usage_history>,\n ) => {\n callContext.signal.throwIfAborted()\n const period = (input as { period: string }).period\n return queryUsageHistoryInWorker(\n period,\n AbortSignal.any([callContext.signal, shutdownController.signal]),\n )\n },\n active_context_cost: async (\n input,\n callContext: RpcCallContext<typeof quotaRpc.methods.active_context_cost>,\n ) => {\n callContext.signal.throwIfAborted()\n return estimateActiveContextCost(\n input as {\n providerID: string | null\n modelID: string | null\n contextTokens: number | null\n },\n )\n },\n })\n } catch (error) {\n console.warn('[pantheon-tui quota] quota RPC registration failed:', error)\n eventController.abort()\n shutdownController.abort()\n resolver.dispose()\n adapters.invalidate()\n await eventTask\n throw error\n }\n\n return async () => {\n eventController.abort()\n shutdownController.abort()\n resolver.dispose()\n adapters.invalidate()\n await eventTask\n await registration?.dispose()\n }\n },\n })\n}\n\nexport default createQuotaPlugin()\n"],"mappings":";;;;;;;;;AAiBA,eAAe,eACb,MACA,QACgE;CAChE,IAAI,CAAC,MAAM,OAAO;CAClB,IAAI;CACJ,IAAI,cAA0B,CAAC;CAC/B,IAAI,WAAW;CACf,IAAI;EACF,SAAS,KAAK,UAAU;EACxB,MAAM,UAAU,IAAI,SAAgB,GAAG,WAAW;GAChD,cAAc,uBAAO,IAAI,MAAM,SAAS,CAAC;GACzC,OAAO,iBAAiB,SAAS,OAAO,EAAE,MAAM,KAAK,CAAC;EACxD,CAAC;EACD,MAAM,wBAAQ,IAAI,WAAW,IAAI;EACjC,IAAI,SAAS;EACb,OAAO,MAAM;GACX,OAAO,eAAe;GACtB,MAAM,EAAE,MAAM,UAAU,MAAM,QAAQ,KAAK,CAAC,OAAO,KAAK,GAAG,OAAO,CAAC;GACnE,IAAI,MAAM;IACR,WAAW;IACX;GACF;GACA,IAAI,MAAM,aAAa,MAAM,SAAS,QAAQ,OAAO;GACrD,MAAM,IAAI,OAAO,MAAM;GACvB,UAAU,MAAM;EAClB;EACA,MAAM,SAAkB,KAAK,MAC3B,IAAI,YAAY,SAAS,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,OAAO,MAAM,S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ACjB,gBAAgB,MAAM;IACtB,mBAAmB,MAAM;IACzB,SAAS,QAAQ;IACjB,SAAS,WAAW;IACpB,MAAM;IACN,MAAM,cAAc,QAAQ;GAC9B;EACF;CACF,CAAC;AACH;AAEA,IAAA,oBAAe,kBAAkB"}
|
|
1
|
+
{"version":3,"file":"server-v2.js","names":[],"sources":["../src/server-v2.ts"],"sourcesContent":["/**\n * No-op server stub for the OpenCode V2 plugin loader.\n *\n * The OpenCode plugin host requires every plugin (TUI included) to expose a\n * `server()` entry via `exports[\"./server\"]` (or package.json `main`) — for the\n * V2 copy this root `index-v2.ts` re-export resolves to this compiled entry —\n * and it loads that server half only from a `config.plugins` entry (see\n * `scripts/install/opencode.mjs`). When the entry is missing the host fails to\n * attach the plugin's server half and the TUI runtime never wires the reactive\n * channel — the initial JSX mounts but effects/refresh/events stay dead (the\n * \"mudo panel\" symptom; same contract as the V1 `server.ts` stub).\n *\n * This stub satisfies the loader contract. The native quota RPC that used to\n * live here was removed in 1.6.2 — provider quota/usage visibility is now the\n * community plugin's job (`@slkiser/opencode-quota`,\n * docs/tui-v2-quota-providers.md) — and pantheon-tui has no other background\n * server work of its own.\n */\nexport default function server() {\n return {}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,SAAwB,SAAS;CAC/B,OAAO,CAAC;AACV"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Accessor
|
|
2
|
-
import { Context,
|
|
1
|
+
import { Accessor } from "solid-js";
|
|
2
|
+
import { Context, KeymapLayer, PanelInput } from "@opencode/plugin/tui/context";
|
|
3
3
|
//#region src/context-gauge.d.ts
|
|
4
4
|
/** Shared, data-only formatting and visual helpers for compact context gauges. */
|
|
5
5
|
type ContextProgressTone = 'info' | 'success' | 'warning' | 'error';
|
|
@@ -16,235 +16,12 @@ export declare function contextBar(percent: number | null | undefined, cells?: n
|
|
|
16
16
|
} | null;
|
|
17
17
|
export declare function formatSpent(cost: number | null | undefined): string | null;
|
|
18
18
|
//#endregion
|
|
19
|
-
//#region src/quota-v2-model.d.ts
|
|
20
|
-
type QuotaDisplay = 'used' | 'remaining';
|
|
21
|
-
type QuotaPreferences = {
|
|
22
|
-
enabled: boolean;
|
|
23
|
-
display: QuotaDisplay;
|
|
24
|
-
};
|
|
25
|
-
export declare const DEFAULT_QUOTA_PREFERENCES: QuotaPreferences;
|
|
26
|
-
type QuotaMetric = {
|
|
27
|
-
kind: 'provider_quota';
|
|
28
|
-
used: number;
|
|
29
|
-
remaining: number;
|
|
30
|
-
unit: string;
|
|
31
|
-
label?: string;
|
|
32
|
-
period?: string;
|
|
33
|
-
resetsAt?: number;
|
|
34
|
-
} | {
|
|
35
|
-
kind: 'balance';
|
|
36
|
-
amount: number;
|
|
37
|
-
currency: string;
|
|
38
|
-
label?: string;
|
|
39
|
-
status?: string;
|
|
40
|
-
} | {
|
|
41
|
-
kind: 'estimate';
|
|
42
|
-
amount: number;
|
|
43
|
-
unit: string;
|
|
44
|
-
label?: string;
|
|
45
|
-
} | {
|
|
46
|
-
kind: 'key_usage';
|
|
47
|
-
amount: number;
|
|
48
|
-
currency: string;
|
|
49
|
-
label?: string;
|
|
50
|
-
period?: string;
|
|
51
|
-
} | {
|
|
52
|
-
kind: 'session_usage';
|
|
53
|
-
amount: number;
|
|
54
|
-
unit: string;
|
|
55
|
-
label?: string;
|
|
56
|
-
} | {
|
|
57
|
-
kind: 'provider_status';
|
|
58
|
-
status: 'available' | 'unavailable' | 'active' | 'inactive';
|
|
59
|
-
label: string;
|
|
60
|
-
};
|
|
61
|
-
type QuotaProviderView = {
|
|
62
|
-
id: string;
|
|
63
|
-
label: string;
|
|
64
|
-
quotaState: 'available' | 'unavailable';
|
|
65
|
-
message?: string;
|
|
66
|
-
metrics: QuotaMetric[];
|
|
67
|
-
};
|
|
68
|
-
type QuotaProviderDetail = {
|
|
69
|
-
id: string;
|
|
70
|
-
label: string;
|
|
71
|
-
authentication: 'connected' | 'not_connected' | 'unavailable';
|
|
72
|
-
state: 'available' | 'needs_setup' | 'unavailable';
|
|
73
|
-
message?: string;
|
|
74
|
-
metrics: QuotaMetric[];
|
|
75
|
-
};
|
|
76
|
-
type QuotaSnapshotStatus = 'loading' | 'ready' | 'partial' | 'connected_unavailable' | 'needs_setup' | 'unavailable' | 'stale' | 'disabled';
|
|
77
|
-
type QuotaSnapshot = {
|
|
78
|
-
status: QuotaSnapshotStatus;
|
|
79
|
-
providers: QuotaProviderView[];
|
|
80
|
-
details: QuotaProviderDetail[];
|
|
81
|
-
updatedAt: number | null;
|
|
82
|
-
/** Short diagnostic of the latest transport/RPC failure; absent after a successful refresh. */
|
|
83
|
-
error?: string | undefined;
|
|
84
|
-
};
|
|
85
|
-
export declare const QUOTA_CLOCK_INTERVAL_MS = 60000;
|
|
86
|
-
type QuotaClockOptions = {
|
|
87
|
-
now?: () => number;
|
|
88
|
-
setInterval?: typeof globalThis.setInterval;
|
|
89
|
-
clearInterval?: typeof globalThis.clearInterval;
|
|
90
|
-
};
|
|
91
|
-
type QuotaClock = {
|
|
92
|
-
subscribe: (listener: (now: number) => void) => () => void;
|
|
93
|
-
};
|
|
94
|
-
/** Create a shared local clock for countdown displays; it never refreshes quota data. */
|
|
95
|
-
export declare function createQuotaClock(options?: QuotaClockOptions): QuotaClock;
|
|
96
|
-
/** Module-local clock shared by all countdown consumers in the TUI bundle. */
|
|
97
|
-
export declare const quotaClock: QuotaClock;
|
|
98
|
-
/** Format a provider-reported reset timestamp using the caller's local clock. */
|
|
99
|
-
export declare function formatQuotaCountdown(resetsAt: number | undefined, now: number): string | null | undefined;
|
|
100
|
-
type QuotaSidebarEntry = {
|
|
101
|
-
kind: 'quota';
|
|
102
|
-
key: string;
|
|
103
|
-
providerID: string;
|
|
104
|
-
providerLabel: string;
|
|
105
|
-
metric: Extract<QuotaMetric, {
|
|
106
|
-
kind: 'provider_quota';
|
|
107
|
-
}>;
|
|
108
|
-
progress: {
|
|
109
|
-
usedPercent: number;
|
|
110
|
-
remainingPercent: number;
|
|
111
|
-
};
|
|
112
|
-
} | {
|
|
113
|
-
kind: 'status';
|
|
114
|
-
key: string;
|
|
115
|
-
providerID: string;
|
|
116
|
-
providerLabel: string;
|
|
117
|
-
message: string;
|
|
118
|
-
};
|
|
119
|
-
type ModelContextSnapshot = {
|
|
120
|
-
tokens: number;
|
|
121
|
-
percent: number;
|
|
122
|
-
limit: number;
|
|
123
|
-
};
|
|
124
|
-
type RecentModelUsageRow = {
|
|
125
|
-
providerID: string | null;
|
|
126
|
-
modelID: string | null;
|
|
127
|
-
label: string;
|
|
128
|
-
tokens: number | null;
|
|
129
|
-
cost: number | null;
|
|
130
|
-
context: ModelContextSnapshot | null;
|
|
131
|
-
active: boolean;
|
|
132
|
-
};
|
|
133
|
-
type CollectRecentModelUsageInput = {
|
|
134
|
-
activeModel: unknown;
|
|
135
|
-
activeMessages: readonly unknown[];
|
|
136
|
-
usageMessages: readonly unknown[];
|
|
137
|
-
usageSessions?: readonly {
|
|
138
|
-
messages: readonly unknown[];
|
|
139
|
-
revertMessageID?: string | null;
|
|
140
|
-
}[];
|
|
141
|
-
models: readonly unknown[];
|
|
142
|
-
revertMessageID?: string | null;
|
|
143
|
-
};
|
|
144
|
-
/** Snapshot for one exact model identity in the bounded active transcript. */
|
|
145
|
-
export declare function resolveModelContextSnapshot(messages: readonly unknown[], modelRef: unknown, models: readonly unknown[], revertMessageID?: string | null): ModelContextSnapshot | null;
|
|
146
|
-
/** Select the pinned chat model before transcript or configured-agent fallbacks. */
|
|
147
|
-
export declare function resolveActiveModelRef(sessionModel: unknown, activeMessages: readonly unknown[], fallbackModel?: unknown): unknown;
|
|
148
|
-
/** Pin the active chat first, then rank two distinct models by summed reported
|
|
149
|
-
* tokens from the already-cached, bounded session-family messages. */
|
|
150
|
-
export declare function collectRecentModelUsageRows(input: CollectRecentModelUsageInput): RecentModelUsageRow[];
|
|
151
|
-
export declare function normalizeQuotaPreferences(value: unknown): QuotaPreferences;
|
|
152
|
-
export declare function quotaSnapshotStatusLabel(status: QuotaSnapshotStatus, error?: string | undefined): string;
|
|
153
|
-
/** Map the current typed RPC status into a provider-neutral, data-only UI model. */
|
|
154
|
-
export declare function quotaSnapshotFromStatus(response: unknown, now?: number): QuotaSnapshot;
|
|
155
|
-
/** Return complementary whole percentages only when both quota values define a real range. */
|
|
156
|
-
export declare function quotaProgress(metric: Extract<QuotaMetric, {
|
|
157
|
-
kind: 'provider_quota';
|
|
158
|
-
}>): {
|
|
159
|
-
usedPercent: number;
|
|
160
|
-
remainingPercent: number;
|
|
161
|
-
} | undefined;
|
|
162
|
-
/** Connected-provider rows for the compact sidebar; only reported quota windows are shown. */
|
|
163
|
-
export declare function quotaSidebarEntries(snapshot: QuotaSnapshot): QuotaSidebarEntry[];
|
|
164
|
-
/** Render each measurement with its source/category label; no category is inferred. */
|
|
165
|
-
export declare function formatQuotaMetric(metric: QuotaMetric, display: QuotaDisplay): string | undefined;
|
|
166
|
-
/** Compact one-value summary for the footer; quota display follows the setting. */
|
|
167
|
-
export declare function compactQuotaMetric(metric: QuotaMetric, display: QuotaDisplay): string | undefined;
|
|
168
|
-
type QuotaRuntime = {
|
|
169
|
-
preferences: () => QuotaPreferences;
|
|
170
|
-
snapshot: () => QuotaSnapshot;
|
|
171
|
-
toggleEnabled: () => Promise<void>;
|
|
172
|
-
toggleDisplay: () => Promise<void>;
|
|
173
|
-
refresh: () => Promise<void>;
|
|
174
|
-
dispose: () => void;
|
|
175
|
-
};
|
|
176
|
-
/** One storage-backed source of truth for all quota TUI surfaces. */
|
|
177
|
-
export declare function createQuotaRuntime(context: Pick<Context, 'client' | 'data' | 'location' | 'storage'>): QuotaRuntime;
|
|
178
|
-
//#endregion
|
|
179
|
-
//#region src/go-key-diagnostic-ui.d.ts
|
|
180
|
-
/** Native keyboard-accessible dialogs; never invoked by quota refresh or panel mounting. */
|
|
181
|
-
export declare function quotaGoCheckCommand(context: Pick<Context, 'ui' | 'client' | 'location' | 'data'>): KeymapCommand;
|
|
182
|
-
//#endregion
|
|
183
19
|
//#region src/model-usage-limits.d.ts
|
|
184
20
|
/** Shared bounds for cached recent model-usage aggregation. */
|
|
185
21
|
export declare const MODEL_USAGE_VISIBLE_CEILING = 3;
|
|
186
22
|
export declare const MODEL_USAGE_MESSAGE_LIMIT = 400;
|
|
187
23
|
export declare const MODEL_USAGE_SESSION_LIMIT = 8;
|
|
188
24
|
//#endregion
|
|
189
|
-
//#region src/quota-v2.d.ts
|
|
190
|
-
export declare const QUOTA_PANEL_NAME = "pantheon.quota";
|
|
191
|
-
export declare const QUOTA_OPEN_COMMAND_ID = "pantheon.quota.open";
|
|
192
|
-
type QuotaIconMode = 'nerd' | 'unicode' | 'ascii';
|
|
193
|
-
type QuotaIconName = 'check' | 'close' | 'clock' | 'gauge' | 'plug' | 'refresh' | 'settings' | 'sliders' | 'warning';
|
|
194
|
-
export declare function quotaIcon(name: QuotaIconName, mode?: QuotaIconMode): string;
|
|
195
|
-
export declare const QUOTA_ICON: string;
|
|
196
|
-
type QuotaSurfaceProps = {
|
|
197
|
-
context: Context;
|
|
198
|
-
runtime: QuotaRuntime;
|
|
199
|
-
};
|
|
200
|
-
export declare function quotaUsageTone(usedPercent: number): 'success' | 'warning' | 'error';
|
|
201
|
-
type QuotaTone = 'info' | 'success' | 'warning' | 'error';
|
|
202
|
-
export declare function snapshotSummary(snapshot: QuotaSnapshot, display: 'used' | 'remaining'): string;
|
|
203
|
-
type FinanceMetric = Extract<QuotaMetric, {
|
|
204
|
-
kind: 'balance' | 'estimate' | 'key_usage';
|
|
205
|
-
}>;
|
|
206
|
-
type FinanceEntry = {
|
|
207
|
-
providerID: string;
|
|
208
|
-
metric: FinanceMetric;
|
|
209
|
-
};
|
|
210
|
-
export declare function sidebarFinanceEntries(snapshot: QuotaSnapshot): FinanceEntry[];
|
|
211
|
-
type QuotaWindowMetric = Extract<QuotaMetric, {
|
|
212
|
-
kind: 'provider_quota';
|
|
213
|
-
}>;
|
|
214
|
-
/** Wrap on grapheme boundaries, measuring terminal cells rather than code units. */
|
|
215
|
-
export declare function quotaTextLines(text: string, width: number, indent: number): string[];
|
|
216
|
-
/** Layout uses only a provider-reported reset; a local clock never refreshes data. */
|
|
217
|
-
export declare function quotaWindowLines(metric: QuotaWindowMetric, display: 'used' | 'remaining', width: number, now: number, sidebarPercent?: boolean): string[];
|
|
218
|
-
export declare function financeMetricLines(metric: FinanceMetric, width: number): string[];
|
|
219
|
-
export declare function quotaMetricLines(metric: Exclude<QuotaMetric, {
|
|
220
|
-
kind: 'provider_quota';
|
|
221
|
-
}>, width: number): string[];
|
|
222
|
-
export declare function providerState(provider: QuotaProviderDetail, mode?: QuotaIconMode): {
|
|
223
|
-
label: string;
|
|
224
|
-
tone: QuotaTone;
|
|
225
|
-
};
|
|
226
|
-
export declare function activeQuotaModelLabel(row: RecentModelUsageRow | undefined): string;
|
|
227
|
-
export declare function quotaPanelStatusMessage(snapshot: Pick<QuotaSnapshot, 'status' | 'error'>): string | undefined;
|
|
228
|
-
type QuotaPanelAction = 'toggle-enabled' | 'toggle-display' | 'refresh' | 'close';
|
|
229
|
-
export declare const QUOTA_TABS: readonly ['usage', 'limits', 'plugin', 'settings'];
|
|
230
|
-
type QuotaTab = (typeof QUOTA_TABS)[number];
|
|
231
|
-
export declare const DEFAULT_QUOTA_TAB: QuotaTab;
|
|
232
|
-
export declare function moveQuotaTab(current: QuotaTab, direction: -1 | 1): QuotaTab;
|
|
233
|
-
export declare const QUOTA_PANEL_COMMANDS: readonly {
|
|
234
|
-
action: QuotaPanelAction;
|
|
235
|
-
id: string;
|
|
236
|
-
title: string;
|
|
237
|
-
bind: string;
|
|
238
|
-
}[];
|
|
239
|
-
export declare function runQuotaPanelCommand(action: QuotaPanelAction, panel: Pick<PanelInput, 'focused' | 'close'>, runtime: QuotaRuntime): false | Promise<void> | undefined;
|
|
240
|
-
export declare function quotaPanelKeymapLayer(panel: Pick<PanelInput, 'focused' | 'close'>, runtime: QuotaRuntime, onTabChange?: (direction: -1 | 1) => void): KeymapLayer;
|
|
241
|
-
export declare function quotaOpenCommand(context: Pick<Context, 'ui'>): KeymapCommand;
|
|
242
|
-
export declare function openQuotaPanel(context: Pick<Context, 'ui'>): boolean;
|
|
243
|
-
export declare function quotaTabLabel(tab: QuotaTab, mode?: QuotaIconMode): string;
|
|
244
|
-
export declare function QuotaPanel(props: QuotaSurfaceProps & {
|
|
245
|
-
panel: PanelInput;
|
|
246
|
-
}): JSX.Element;
|
|
247
|
-
//#endregion
|
|
248
25
|
//#region src/sidebar-width.d.ts
|
|
249
26
|
/** Terminal cells `value` occupies — the unit every column in this plugin is
|
|
250
27
|
* measured in. Mirrors the host (that is how `@opentui/core` sizes a text
|
|
@@ -253,111 +30,6 @@ export declare function QuotaPanel(props: QuotaSurfaceProps & {
|
|
|
253
30
|
* Pure. */
|
|
254
31
|
export declare function cellWidth(value: string): number;
|
|
255
32
|
//#endregion
|
|
256
|
-
//#region src/usage-history-view.d.ts
|
|
257
|
-
export declare function UsageHistorySection(props: {
|
|
258
|
-
context: Context;
|
|
259
|
-
panel: PanelInput;
|
|
260
|
-
width: number;
|
|
261
|
-
}): JSX.Element;
|
|
262
|
-
//#endregion
|
|
263
|
-
//#region src/usage-history-contract.d.ts
|
|
264
|
-
type UsageHistoryRpcPeriod = '7d' | '15d' | '30d' | 'total';
|
|
265
|
-
interface UsageHistoryRpcTotals {
|
|
266
|
-
input: number;
|
|
267
|
-
output: number;
|
|
268
|
-
cacheRead: number;
|
|
269
|
-
cacheWrite: number;
|
|
270
|
-
total: number;
|
|
271
|
-
}
|
|
272
|
-
interface UsageHistoryRpcBucket extends UsageHistoryRpcTotals {
|
|
273
|
-
date: string;
|
|
274
|
-
estimatedUsd?: number;
|
|
275
|
-
pricingComplete: boolean;
|
|
276
|
-
}
|
|
277
|
-
interface UsageHistoryRpcModel {
|
|
278
|
-
providerID: string;
|
|
279
|
-
modelID: string;
|
|
280
|
-
totals: UsageHistoryRpcTotals;
|
|
281
|
-
estimatedUsd?: number;
|
|
282
|
-
pricingComplete: boolean;
|
|
283
|
-
}
|
|
284
|
-
interface UsageHistoryRpcAvailable {
|
|
285
|
-
status: 'available' | 'partial';
|
|
286
|
-
period: UsageHistoryRpcPeriod;
|
|
287
|
-
coverageStart: string | null;
|
|
288
|
-
partial: boolean;
|
|
289
|
-
truncated: boolean;
|
|
290
|
-
rows: number;
|
|
291
|
-
buckets: UsageHistoryRpcBucket[];
|
|
292
|
-
totals: UsageHistoryRpcTotals;
|
|
293
|
-
models: UsageHistoryRpcModel[];
|
|
294
|
-
pricing: {
|
|
295
|
-
status: 'empty' | 'unavailable' | 'partial' | 'complete';
|
|
296
|
-
complete: boolean;
|
|
297
|
-
billed: false;
|
|
298
|
-
estimatedUsd?: number;
|
|
299
|
-
unpricedModels: number;
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
interface UsageHistoryRpcUnavailable {
|
|
303
|
-
status: 'unavailable';
|
|
304
|
-
reason: 'invalid_period' | 'history_unavailable' | 'history_timeout';
|
|
305
|
-
}
|
|
306
|
-
type UsageHistoryRpcResult = UsageHistoryRpcAvailable | UsageHistoryRpcUnavailable;
|
|
307
|
-
//#endregion
|
|
308
|
-
//#region src/usage-view-model.d.ts
|
|
309
|
-
type ActiveContextCostResult = {
|
|
310
|
-
status: 'estimated';
|
|
311
|
-
estimatedUsd: number;
|
|
312
|
-
billed: false;
|
|
313
|
-
basis: 'pre-cache-context-tokens-times-input-price';
|
|
314
|
-
cacheDiscountApplied: false;
|
|
315
|
-
} | {
|
|
316
|
-
status: 'unavailable';
|
|
317
|
-
billed: false;
|
|
318
|
-
basis: 'pre-cache-context-tokens-times-input-price';
|
|
319
|
-
cacheDiscountApplied: false;
|
|
320
|
-
reason: 'invalid-context-token-count' | 'missing-model-identity' | 'no-pricing' | 'unknown-model' | 'ambiguous-model' | 'missing-cache-price';
|
|
321
|
-
};
|
|
322
|
-
export declare const USAGE_HISTORY_PERIOD_BINDINGS: readonly [{
|
|
323
|
-
readonly period: '7d';
|
|
324
|
-
readonly bind: '7';
|
|
325
|
-
readonly label: '7d';
|
|
326
|
-
}, {
|
|
327
|
-
readonly period: '15d';
|
|
328
|
-
readonly bind: '1';
|
|
329
|
-
readonly label: '15d';
|
|
330
|
-
}, {
|
|
331
|
-
readonly period: '30d';
|
|
332
|
-
readonly bind: '3';
|
|
333
|
-
readonly label: '30d';
|
|
334
|
-
}, {
|
|
335
|
-
readonly period: 'total';
|
|
336
|
-
readonly bind: 't';
|
|
337
|
-
readonly label: 'total';
|
|
338
|
-
}];
|
|
339
|
-
export declare function usageHistoryTextLines(value: string, width: number): string[];
|
|
340
|
-
export declare function usageHistorySelectorLabel(selected: UsageHistoryRpcPeriod): string;
|
|
341
|
-
export declare function usageHistorySelectorLines(selected: UsageHistoryRpcPeriod, width: number): string[];
|
|
342
|
-
export declare function usageHistoryPeriodForKey(key: string): UsageHistoryRpcPeriod | undefined;
|
|
343
|
-
export declare function usageHistoryControlsLines(width: number): string[];
|
|
344
|
-
export declare function usageHistoryCoverageLabel(result: UsageHistoryRpcAvailable): string;
|
|
345
|
-
export declare function usageHistoryPartialWarning(result: UsageHistoryRpcAvailable): string | null;
|
|
346
|
-
export declare function usageHistoryPricingLabel(result: UsageHistoryRpcAvailable): string;
|
|
347
|
-
export declare function usageHistoryUnavailableMessage(result: UsageHistoryRpcResult): string | null;
|
|
348
|
-
export declare function usageHistoryEmptyMessage(): string;
|
|
349
|
-
export declare function usageHistoryChartLines(result: UsageHistoryRpcAvailable, width: number): string[];
|
|
350
|
-
export declare function activeModelIdentity(model: {
|
|
351
|
-
providerID: string | null;
|
|
352
|
-
modelID: string | null;
|
|
353
|
-
label: string;
|
|
354
|
-
}): string;
|
|
355
|
-
export declare function sessionSpendLabel(cost: number): string | null;
|
|
356
|
-
export declare function activeContextEstimateLines(result: ActiveContextCostResult, width: number): string[];
|
|
357
|
-
export declare function activeContextEstimatePendingLines(width: number): string[];
|
|
358
|
-
export declare function activeContextEstimateMissingLines(width: number): string[];
|
|
359
|
-
export declare function activeContextEstimateErrorLines(width: number): string[];
|
|
360
|
-
//#endregion
|
|
361
33
|
//#region src/index-v2.d.ts
|
|
362
34
|
/** Sidebar body shown while the host has not published a session yet. */
|
|
363
35
|
export declare const SIDEBAR_WAITING_LABEL = "Aguardando sessão…";
|
|
@@ -426,6 +98,15 @@ export declare function providerIDFromModels(models: unknown, ref: unknown): str
|
|
|
426
98
|
* provider-qualified id, then the bare id (the host's `id`/`modelID` fields).
|
|
427
99
|
* Absent/ambiguous models degrade to null so the gauge is simply omitted. */
|
|
428
100
|
export declare function resolveContextLimit(models: readonly any[], ref: unknown): number | null;
|
|
101
|
+
export type ModelContextSnapshot = {
|
|
102
|
+
tokens: number;
|
|
103
|
+
percent: number;
|
|
104
|
+
limit: number;
|
|
105
|
+
};
|
|
106
|
+
/** Snapshot for one exact model identity in the bounded active transcript. */
|
|
107
|
+
export declare function resolveModelContextSnapshot(messages: readonly unknown[], modelRef: unknown, models: readonly unknown[], revertMessageID?: string | null): ModelContextSnapshot | null;
|
|
108
|
+
/** Select the pinned chat model before transcript or configured-agent fallbacks. */
|
|
109
|
+
export declare function resolveActiveModelRef(sessionModel: unknown, activeMessages: readonly unknown[], fallbackModel?: unknown): unknown;
|
|
429
110
|
/** Native token total: input + output + reasoning + cache read + cache write. */
|
|
430
111
|
export declare function messageTokensTotal(tokens: any): number;
|
|
431
112
|
export type ContextUsage = {
|
|
@@ -1354,5 +1035,5 @@ declare const plugin: {
|
|
|
1354
1035
|
setup(context: Context): (() => void) | undefined;
|
|
1355
1036
|
};
|
|
1356
1037
|
//#endregion
|
|
1357
|
-
export { type
|
|
1038
|
+
export { type ContextProgressTone, plugin as default };
|
|
1358
1039
|
//# sourceMappingURL=tui-v2.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tui-v2.d.ts","names":[],"sources":["../src/context-gauge.ts","../src/
|
|
1
|
+
{"version":3,"file":"tui-v2.d.ts","names":[],"sources":["../src/context-gauge.ts","../src/model-usage-limits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