opencode-quota-gui 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +243 -2
- package/dist/bin/opencode-quota-gui.d.ts +4 -0
- package/dist/bin/opencode-quota-gui.d.ts.map +1 -0
- package/dist/bin/opencode-quota-gui.js +75 -0
- package/dist/bin/opencode-quota-gui.js.map +1 -0
- package/dist/contracts/build-identity.d.ts +8 -0
- package/dist/contracts/build-identity.d.ts.map +1 -0
- package/dist/contracts/build-identity.js +1 -0
- package/dist/contracts/card-order.d.ts +25 -0
- package/dist/contracts/card-order.d.ts.map +1 -0
- package/dist/contracts/card-order.js +50 -0
- package/dist/contracts/card-order.js.map +1 -0
- package/dist/contracts/dashboard.d.ts +368 -0
- package/dist/contracts/dashboard.d.ts.map +1 -0
- package/dist/contracts/dashboard.js +3 -0
- package/dist/contracts/dashboard.js.map +1 -0
- package/dist/contracts/guards.d.ts +14 -0
- package/dist/contracts/guards.d.ts.map +1 -0
- package/dist/contracts/guards.js +56 -0
- package/dist/contracts/guards.js.map +1 -0
- package/dist/contracts/identity.d.ts +41 -0
- package/dist/contracts/identity.d.ts.map +1 -0
- package/dist/contracts/identity.js +27 -0
- package/dist/contracts/identity.js.map +1 -0
- package/dist/contracts/openai-quota.d.ts +34 -0
- package/dist/contracts/openai-quota.d.ts.map +1 -0
- package/dist/contracts/openai-quota.js +19 -0
- package/dist/contracts/openai-quota.js.map +1 -0
- package/dist/contracts/ranges.d.ts +48 -0
- package/dist/contracts/ranges.d.ts.map +1 -0
- package/dist/contracts/ranges.js +84 -0
- package/dist/contracts/ranges.js.map +1 -0
- package/dist/contracts/settings.d.ts +4 -0
- package/dist/contracts/settings.d.ts.map +1 -0
- package/dist/contracts/settings.js +14 -0
- package/dist/contracts/settings.js.map +1 -0
- package/dist/contracts/time-zone.d.ts +33 -0
- package/dist/contracts/time-zone.d.ts.map +1 -0
- package/dist/contracts/time-zone.js +217 -0
- package/dist/contracts/time-zone.js.map +1 -0
- package/dist/data/modelsdev-pricing.min.json +1064 -0
- package/dist/gui/aggregation.d.ts +55 -0
- package/dist/gui/aggregation.d.ts.map +1 -0
- package/dist/gui/aggregation.js +792 -0
- package/dist/gui/aggregation.js.map +1 -0
- package/dist/gui/analytics-bridge.d.ts +50 -0
- package/dist/gui/analytics-bridge.d.ts.map +1 -0
- package/dist/gui/analytics-bridge.js +382 -0
- package/dist/gui/analytics-bridge.js.map +1 -0
- package/dist/gui/analytics-engine.d.ts +61 -0
- package/dist/gui/analytics-engine.d.ts.map +1 -0
- package/dist/gui/analytics-engine.js +2381 -0
- package/dist/gui/analytics-engine.js.map +1 -0
- package/dist/gui/analytics-indexes.d.ts +34 -0
- package/dist/gui/analytics-indexes.d.ts.map +1 -0
- package/dist/gui/analytics-indexes.js +142 -0
- package/dist/gui/analytics-indexes.js.map +1 -0
- package/dist/gui/analytics-model.d.ts +48 -0
- package/dist/gui/analytics-model.d.ts.map +1 -0
- package/dist/gui/analytics-model.js +824 -0
- package/dist/gui/analytics-model.js.map +1 -0
- package/dist/gui/analytics-protocol.d.ts +102 -0
- package/dist/gui/analytics-protocol.d.ts.map +1 -0
- package/dist/gui/analytics-protocol.js +11 -0
- package/dist/gui/analytics-protocol.js.map +1 -0
- package/dist/gui/analytics-reader.d.ts +14 -0
- package/dist/gui/analytics-reader.d.ts.map +1 -0
- package/dist/gui/analytics-reader.js +15 -0
- package/dist/gui/analytics-reader.js.map +1 -0
- package/dist/gui/analytics-service.d.ts +49 -0
- package/dist/gui/analytics-service.d.ts.map +1 -0
- package/dist/gui/analytics-service.js +187 -0
- package/dist/gui/analytics-service.js.map +1 -0
- package/dist/gui/analytics-state.d.ts +183 -0
- package/dist/gui/analytics-state.d.ts.map +1 -0
- package/dist/gui/analytics-state.js +692 -0
- package/dist/gui/analytics-state.js.map +1 -0
- package/dist/gui/analytics-worker-runtime.d.ts +11 -0
- package/dist/gui/analytics-worker-runtime.d.ts.map +1 -0
- package/dist/gui/analytics-worker-runtime.js +98 -0
- package/dist/gui/analytics-worker-runtime.js.map +1 -0
- package/dist/gui/analytics-worker.d.ts +2 -0
- package/dist/gui/analytics-worker.d.ts.map +1 -0
- package/dist/gui/analytics-worker.js +64 -0
- package/dist/gui/analytics-worker.js.map +1 -0
- package/dist/gui/config.d.ts +56 -0
- package/dist/gui/config.d.ts.map +1 -0
- package/dist/gui/config.js +701 -0
- package/dist/gui/config.js.map +1 -0
- package/dist/gui/identity.d.ts +23 -0
- package/dist/gui/identity.d.ts.map +1 -0
- package/dist/gui/identity.js +57 -0
- package/dist/gui/identity.js.map +1 -0
- package/dist/gui/lifecycle.d.ts +82 -0
- package/dist/gui/lifecycle.d.ts.map +1 -0
- package/dist/gui/lifecycle.js +402 -0
- package/dist/gui/lifecycle.js.map +1 -0
- package/dist/gui/log.d.ts +23 -0
- package/dist/gui/log.d.ts.map +1 -0
- package/dist/gui/log.js +37 -0
- package/dist/gui/log.js.map +1 -0
- package/dist/gui/provider-cards.d.ts +55 -0
- package/dist/gui/provider-cards.d.ts.map +1 -0
- package/dist/gui/provider-cards.js +417 -0
- package/dist/gui/provider-cards.js.map +1 -0
- package/dist/gui/server.d.ts +60 -0
- package/dist/gui/server.d.ts.map +1 -0
- package/dist/gui/server.js +815 -0
- package/dist/gui/server.js.map +1 -0
- package/dist/gui/settings-file-opener.d.ts +34 -0
- package/dist/gui/settings-file-opener.d.ts.map +1 -0
- package/dist/gui/settings-file-opener.js +110 -0
- package/dist/gui/settings-file-opener.js.map +1 -0
- package/dist/gui/snapshot-service.d.ts +128 -0
- package/dist/gui/snapshot-service.d.ts.map +1 -0
- package/dist/gui/snapshot-service.js +591 -0
- package/dist/gui/snapshot-service.js.map +1 -0
- package/dist/gui/sources.d.ts +99 -0
- package/dist/gui/sources.d.ts.map +1 -0
- package/dist/gui/sources.js +410 -0
- package/dist/gui/sources.js.map +1 -0
- package/dist/gui/sse.d.ts +32 -0
- package/dist/gui/sse.d.ts.map +1 -0
- package/dist/gui/sse.js +100 -0
- package/dist/gui/sse.js.map +1 -0
- package/dist/gui/time-zone.d.ts +10 -0
- package/dist/gui/time-zone.d.ts.map +1 -0
- package/dist/gui/time-zone.js +21 -0
- package/dist/gui/time-zone.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/accounting-format.d.ts +54 -0
- package/dist/lib/accounting-format.d.ts.map +1 -0
- package/dist/lib/accounting-format.js +271 -0
- package/dist/lib/accounting-format.js.map +1 -0
- package/dist/lib/alibaba-auth.d.ts +46 -0
- package/dist/lib/alibaba-auth.d.ts.map +1 -0
- package/dist/lib/alibaba-auth.js +193 -0
- package/dist/lib/alibaba-auth.js.map +1 -0
- package/dist/lib/alibaba-coding-plan-local-quota.d.ts +47 -0
- package/dist/lib/alibaba-coding-plan-local-quota.d.ts.map +1 -0
- package/dist/lib/alibaba-coding-plan-local-quota.js +146 -0
- package/dist/lib/alibaba-coding-plan-local-quota.js.map +1 -0
- package/dist/lib/alibaba-token-plan.d.ts +91 -0
- package/dist/lib/alibaba-token-plan.d.ts.map +1 -0
- package/dist/lib/alibaba-token-plan.js +527 -0
- package/dist/lib/alibaba-token-plan.js.map +1 -0
- package/dist/lib/anthropic-auth.d.ts +29 -0
- package/dist/lib/anthropic-auth.d.ts.map +1 -0
- package/dist/lib/anthropic-auth.js +37 -0
- package/dist/lib/anthropic-auth.js.map +1 -0
- package/dist/lib/anthropic.d.ts +104 -0
- package/dist/lib/anthropic.d.ts.map +1 -0
- package/dist/lib/anthropic.js +1134 -0
- package/dist/lib/anthropic.js.map +1 -0
- package/dist/lib/api-key-resolver.d.ts +227 -0
- package/dist/lib/api-key-resolver.d.ts.map +1 -0
- package/dist/lib/api-key-resolver.js +336 -0
- package/dist/lib/api-key-resolver.js.map +1 -0
- package/dist/lib/atomic-json.d.ts +11 -0
- package/dist/lib/atomic-json.d.ts.map +1 -0
- package/dist/lib/atomic-json.js +64 -0
- package/dist/lib/atomic-json.js.map +1 -0
- package/dist/lib/chutes-config.d.ts +15 -0
- package/dist/lib/chutes-config.d.ts.map +1 -0
- package/dist/lib/chutes-config.js +28 -0
- package/dist/lib/chutes-config.js.map +1 -0
- package/dist/lib/chutes.d.ts +12 -0
- package/dist/lib/chutes.d.ts.map +1 -0
- package/dist/lib/chutes.js +60 -0
- package/dist/lib/chutes.js.map +1 -0
- package/dist/lib/cli-reports.d.ts +30 -0
- package/dist/lib/cli-reports.d.ts.map +1 -0
- package/dist/lib/cli-reports.js +172 -0
- package/dist/lib/cli-reports.js.map +1 -0
- package/dist/lib/cli-show.d.ts +30 -0
- package/dist/lib/cli-show.d.ts.map +1 -0
- package/dist/lib/cli-show.js +213 -0
- package/dist/lib/cli-show.js.map +1 -0
- package/dist/lib/cli-status.d.ts +8 -0
- package/dist/lib/cli-status.d.ts.map +1 -0
- package/dist/lib/cli-status.js +98 -0
- package/dist/lib/cli-status.js.map +1 -0
- package/dist/lib/command-parsing.d.ts +43 -0
- package/dist/lib/command-parsing.d.ts.map +1 -0
- package/dist/lib/command-parsing.js +103 -0
- package/dist/lib/command-parsing.js.map +1 -0
- package/dist/lib/config-file-utils.d.ts +46 -0
- package/dist/lib/config-file-utils.d.ts.map +1 -0
- package/dist/lib/config-file-utils.js +194 -0
- package/dist/lib/config-file-utils.js.map +1 -0
- package/dist/lib/config-write-target.d.ts +28 -0
- package/dist/lib/config-write-target.d.ts.map +1 -0
- package/dist/lib/config-write-target.js +159 -0
- package/dist/lib/config-write-target.js.map +1 -0
- package/dist/lib/config.d.ts +119 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +1352 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/copilot.d.ts +78 -0
- package/dist/lib/copilot.d.ts.map +1 -0
- package/dist/lib/copilot.js +1111 -0
- package/dist/lib/copilot.js.map +1 -0
- package/dist/lib/cursor-detection.d.ts +18 -0
- package/dist/lib/cursor-detection.d.ts.map +1 -0
- package/dist/lib/cursor-detection.js +189 -0
- package/dist/lib/cursor-detection.js.map +1 -0
- package/dist/lib/cursor-pricing.d.ts +34 -0
- package/dist/lib/cursor-pricing.d.ts.map +1 -0
- package/dist/lib/cursor-pricing.js +235 -0
- package/dist/lib/cursor-pricing.js.map +1 -0
- package/dist/lib/cursor-usage.d.ts +33 -0
- package/dist/lib/cursor-usage.d.ts.map +1 -0
- package/dist/lib/cursor-usage.js +109 -0
- package/dist/lib/cursor-usage.js.map +1 -0
- package/dist/lib/dashboard-visibility.d.ts +13 -0
- package/dist/lib/dashboard-visibility.d.ts.map +1 -0
- package/dist/lib/dashboard-visibility.js +51 -0
- package/dist/lib/dashboard-visibility.js.map +1 -0
- package/dist/lib/deepseek-auth.d.ts +15 -0
- package/dist/lib/deepseek-auth.d.ts.map +1 -0
- package/dist/lib/deepseek-auth.js +28 -0
- package/dist/lib/deepseek-auth.js.map +1 -0
- package/dist/lib/deepseek.d.ts +40 -0
- package/dist/lib/deepseek.d.ts.map +1 -0
- package/dist/lib/deepseek.js +118 -0
- package/dist/lib/deepseek.js.map +1 -0
- package/dist/lib/display-sanitize.d.ts +20 -0
- package/dist/lib/display-sanitize.d.ts.map +1 -0
- package/dist/lib/display-sanitize.js +178 -0
- package/dist/lib/display-sanitize.js.map +1 -0
- package/dist/lib/entries.d.ts +367 -0
- package/dist/lib/entries.d.ts.map +1 -0
- package/dist/lib/entries.js +69 -0
- package/dist/lib/entries.js.map +1 -0
- package/dist/lib/env-template.d.ts +26 -0
- package/dist/lib/env-template.d.ts.map +1 -0
- package/dist/lib/env-template.js +36 -0
- package/dist/lib/env-template.js.map +1 -0
- package/dist/lib/format-utils.d.ts +89 -0
- package/dist/lib/format-utils.d.ts.map +1 -0
- package/dist/lib/format-utils.js +206 -0
- package/dist/lib/format-utils.js.map +1 -0
- package/dist/lib/format.d.ts +25 -0
- package/dist/lib/format.d.ts.map +1 -0
- package/dist/lib/format.js +300 -0
- package/dist/lib/format.js.map +1 -0
- package/dist/lib/glm-coding-plan.d.ts +19 -0
- package/dist/lib/glm-coding-plan.d.ts.map +1 -0
- package/dist/lib/glm-coding-plan.js +81 -0
- package/dist/lib/glm-coding-plan.js.map +1 -0
- package/dist/lib/google-agy-companion.d.ts +8 -0
- package/dist/lib/google-agy-companion.d.ts.map +1 -0
- package/dist/lib/google-agy-companion.js +64 -0
- package/dist/lib/google-agy-companion.js.map +1 -0
- package/dist/lib/google-agy.d.ts +48 -0
- package/dist/lib/google-agy.d.ts.map +1 -0
- package/dist/lib/google-agy.js +572 -0
- package/dist/lib/google-agy.js.map +1 -0
- package/dist/lib/google-companion-credentials.d.ts +70 -0
- package/dist/lib/google-companion-credentials.d.ts.map +1 -0
- package/dist/lib/google-companion-credentials.js +315 -0
- package/dist/lib/google-companion-credentials.js.map +1 -0
- package/dist/lib/google-gemini-cli-companion.d.ts +8 -0
- package/dist/lib/google-gemini-cli-companion.d.ts.map +1 -0
- package/dist/lib/google-gemini-cli-companion.js +64 -0
- package/dist/lib/google-gemini-cli-companion.js.map +1 -0
- package/dist/lib/google-gemini-cli.d.ts +47 -0
- package/dist/lib/google-gemini-cli.d.ts.map +1 -0
- package/dist/lib/google-gemini-cli.js +481 -0
- package/dist/lib/google-gemini-cli.js.map +1 -0
- package/dist/lib/google-token-cache.d.ts +27 -0
- package/dist/lib/google-token-cache.d.ts.map +1 -0
- package/dist/lib/google-token-cache.js +52 -0
- package/dist/lib/google-token-cache.js.map +1 -0
- package/dist/lib/grouped-entry-normalization.d.ts +12 -0
- package/dist/lib/grouped-entry-normalization.d.ts.map +1 -0
- package/dist/lib/grouped-entry-normalization.js +124 -0
- package/dist/lib/grouped-entry-normalization.js.map +1 -0
- package/dist/lib/grouped-header-format.d.ts +5 -0
- package/dist/lib/grouped-header-format.d.ts.map +1 -0
- package/dist/lib/grouped-header-format.js +16 -0
- package/dist/lib/grouped-header-format.js.map +1 -0
- package/dist/lib/gui-config-target.d.ts +12 -0
- package/dist/lib/gui-config-target.d.ts.map +1 -0
- package/dist/lib/gui-config-target.js +88 -0
- package/dist/lib/gui-config-target.js.map +1 -0
- package/dist/lib/home-dir-display.d.ts +10 -0
- package/dist/lib/home-dir-display.d.ts.map +1 -0
- package/dist/lib/home-dir-display.js +108 -0
- package/dist/lib/home-dir-display.js.map +1 -0
- package/dist/lib/http.d.ts +19 -0
- package/dist/lib/http.d.ts.map +1 -0
- package/dist/lib/http.js +47 -0
- package/dist/lib/http.js.map +1 -0
- package/dist/lib/init-installer.d.ts +146 -0
- package/dist/lib/init-installer.d.ts.map +1 -0
- package/dist/lib/init-installer.js +1056 -0
- package/dist/lib/init-installer.js.map +1 -0
- package/dist/lib/jsonc.d.ts +17 -0
- package/dist/lib/jsonc.d.ts.map +1 -0
- package/dist/lib/jsonc.js +23 -0
- package/dist/lib/jsonc.js.map +1 -0
- package/dist/lib/kilo-config.d.ts +15 -0
- package/dist/lib/kilo-config.d.ts.map +1 -0
- package/dist/lib/kilo-config.js +27 -0
- package/dist/lib/kilo-config.js.map +1 -0
- package/dist/lib/kilo.d.ts +32 -0
- package/dist/lib/kilo.d.ts.map +1 -0
- package/dist/lib/kilo.js +265 -0
- package/dist/lib/kilo.js.map +1 -0
- package/dist/lib/kimi-auth.d.ts +49 -0
- package/dist/lib/kimi-auth.d.ts.map +1 -0
- package/dist/lib/kimi-auth.js +82 -0
- package/dist/lib/kimi-auth.js.map +1 -0
- package/dist/lib/kimi-endpoints.d.ts +10 -0
- package/dist/lib/kimi-endpoints.d.ts.map +1 -0
- package/dist/lib/kimi-endpoints.js +18 -0
- package/dist/lib/kimi-endpoints.js.map +1 -0
- package/dist/lib/kimi.d.ts +26 -0
- package/dist/lib/kimi.d.ts.map +1 -0
- package/dist/lib/kimi.js +230 -0
- package/dist/lib/kimi.js.map +1 -0
- package/dist/lib/maintainer-announcements.d.ts +46 -0
- package/dist/lib/maintainer-announcements.d.ts.map +1 -0
- package/dist/lib/maintainer-announcements.js +155 -0
- package/dist/lib/maintainer-announcements.js.map +1 -0
- package/dist/lib/map-with-concurrency.d.ts +2 -0
- package/dist/lib/map-with-concurrency.d.ts.map +1 -0
- package/dist/lib/map-with-concurrency.js +17 -0
- package/dist/lib/map-with-concurrency.js.map +1 -0
- package/dist/lib/markdown-table.d.ts +51 -0
- package/dist/lib/markdown-table.d.ts.map +1 -0
- package/dist/lib/markdown-table.js +179 -0
- package/dist/lib/markdown-table.js.map +1 -0
- package/dist/lib/mimo-config.d.ts +29 -0
- package/dist/lib/mimo-config.d.ts.map +1 -0
- package/dist/lib/mimo-config.js +146 -0
- package/dist/lib/mimo-config.js.map +1 -0
- package/dist/lib/mimo.d.ts +35 -0
- package/dist/lib/mimo.d.ts.map +1 -0
- package/dist/lib/mimo.js +236 -0
- package/dist/lib/mimo.js.map +1 -0
- package/dist/lib/minimax-auth.d.ts +62 -0
- package/dist/lib/minimax-auth.d.ts.map +1 -0
- package/dist/lib/minimax-auth.js +206 -0
- package/dist/lib/minimax-auth.js.map +1 -0
- package/dist/lib/minimax-endpoints.d.ts +10 -0
- package/dist/lib/minimax-endpoints.d.ts.map +1 -0
- package/dist/lib/minimax-endpoints.js +19 -0
- package/dist/lib/minimax-endpoints.js.map +1 -0
- package/dist/lib/modelsdev-pricing.d.ts +93 -0
- package/dist/lib/modelsdev-pricing.d.ts.map +1 -0
- package/dist/lib/modelsdev-pricing.js +674 -0
- package/dist/lib/modelsdev-pricing.js.map +1 -0
- package/dist/lib/nanogpt-config.d.ts +15 -0
- package/dist/lib/nanogpt-config.d.ts.map +1 -0
- package/dist/lib/nanogpt-config.js +31 -0
- package/dist/lib/nanogpt-config.js.map +1 -0
- package/dist/lib/nanogpt.d.ts +48 -0
- package/dist/lib/nanogpt.d.ts.map +1 -0
- package/dist/lib/nanogpt.js +251 -0
- package/dist/lib/nanogpt.js.map +1 -0
- package/dist/lib/ollama-cloud-config.d.ts +15 -0
- package/dist/lib/ollama-cloud-config.d.ts.map +1 -0
- package/dist/lib/ollama-cloud-config.js +27 -0
- package/dist/lib/ollama-cloud-config.js.map +1 -0
- package/dist/lib/ollama-cloud.d.ts +14 -0
- package/dist/lib/ollama-cloud.d.ts.map +1 -0
- package/dist/lib/ollama-cloud.js +186 -0
- package/dist/lib/ollama-cloud.js.map +1 -0
- package/dist/lib/openai.d.ts +68 -0
- package/dist/lib/openai.d.ts.map +1 -0
- package/dist/lib/openai.js +394 -0
- package/dist/lib/openai.js.map +1 -0
- package/dist/lib/opencode-auth-sqlite.d.ts +17 -0
- package/dist/lib/opencode-auth-sqlite.d.ts.map +1 -0
- package/dist/lib/opencode-auth-sqlite.js +105 -0
- package/dist/lib/opencode-auth-sqlite.js.map +1 -0
- package/dist/lib/opencode-auth.d.ts +146 -0
- package/dist/lib/opencode-auth.d.ts.map +1 -0
- package/dist/lib/opencode-auth.js +465 -0
- package/dist/lib/opencode-auth.js.map +1 -0
- package/dist/lib/opencode-config-editor.d.ts +62 -0
- package/dist/lib/opencode-config-editor.d.ts.map +1 -0
- package/dist/lib/opencode-config-editor.js +387 -0
- package/dist/lib/opencode-config-editor.js.map +1 -0
- package/dist/lib/opencode-config-providers.d.ts +24 -0
- package/dist/lib/opencode-config-providers.d.ts.map +1 -0
- package/dist/lib/opencode-config-providers.js +144 -0
- package/dist/lib/opencode-config-providers.js.map +1 -0
- package/dist/lib/opencode-config-read.d.ts +23 -0
- package/dist/lib/opencode-config-read.d.ts.map +1 -0
- package/dist/lib/opencode-config-read.js +30 -0
- package/dist/lib/opencode-config-read.js.map +1 -0
- package/dist/lib/opencode-console-auth.d.ts +96 -0
- package/dist/lib/opencode-console-auth.d.ts.map +1 -0
- package/dist/lib/opencode-console-auth.js +213 -0
- package/dist/lib/opencode-console-auth.js.map +1 -0
- package/dist/lib/opencode-db-path.d.ts +9 -0
- package/dist/lib/opencode-db-path.d.ts.map +1 -0
- package/dist/lib/opencode-db-path.js +16 -0
- package/dist/lib/opencode-db-path.js.map +1 -0
- package/dist/lib/opencode-go-auth.d.ts +16 -0
- package/dist/lib/opencode-go-auth.d.ts.map +1 -0
- package/dist/lib/opencode-go-auth.js +42 -0
- package/dist/lib/opencode-go-auth.js.map +1 -0
- package/dist/lib/opencode-go.d.ts +17 -0
- package/dist/lib/opencode-go.d.ts.map +1 -0
- package/dist/lib/opencode-go.js +284 -0
- package/dist/lib/opencode-go.js.map +1 -0
- package/dist/lib/opencode-runtime-paths.d.ts +17 -0
- package/dist/lib/opencode-runtime-paths.d.ts.map +1 -0
- package/dist/lib/opencode-runtime-paths.js +24 -0
- package/dist/lib/opencode-runtime-paths.js.map +1 -0
- package/dist/lib/opencode-sqlite.d.ts +11 -0
- package/dist/lib/opencode-sqlite.d.ts.map +1 -0
- package/dist/lib/opencode-sqlite.js +88 -0
- package/dist/lib/opencode-sqlite.js.map +1 -0
- package/dist/lib/opencode-storage.d.ts +306 -0
- package/dist/lib/opencode-storage.d.ts.map +1 -0
- package/dist/lib/opencode-storage.js +1269 -0
- package/dist/lib/opencode-storage.js.map +1 -0
- package/dist/lib/opencode-version.d.ts +6 -0
- package/dist/lib/opencode-version.d.ts.map +1 -0
- package/dist/lib/opencode-version.js +26 -0
- package/dist/lib/opencode-version.js.map +1 -0
- package/dist/lib/opencode-zen.d.ts +55 -0
- package/dist/lib/opencode-zen.d.ts.map +1 -0
- package/dist/lib/opencode-zen.js +348 -0
- package/dist/lib/opencode-zen.js.map +1 -0
- package/dist/lib/openrouter.d.ts +60 -0
- package/dist/lib/openrouter.d.ts.map +1 -0
- package/dist/lib/openrouter.js +215 -0
- package/dist/lib/openrouter.js.map +1 -0
- package/dist/lib/private-state-paths.d.ts +10 -0
- package/dist/lib/private-state-paths.d.ts.map +1 -0
- package/dist/lib/private-state-paths.js +28 -0
- package/dist/lib/private-state-paths.js.map +1 -0
- package/dist/lib/provider-add-command.d.ts +35 -0
- package/dist/lib/provider-add-command.d.ts.map +1 -0
- package/dist/lib/provider-add-command.js +204 -0
- package/dist/lib/provider-add-command.js.map +1 -0
- package/dist/lib/provider-add-json-v1-questionnaire.d.ts +32 -0
- package/dist/lib/provider-add-json-v1-questionnaire.d.ts.map +1 -0
- package/dist/lib/provider-add-json-v1-questionnaire.js +336 -0
- package/dist/lib/provider-add-json-v1-questionnaire.js.map +1 -0
- package/dist/lib/provider-add.d.ts +21 -0
- package/dist/lib/provider-add.d.ts.map +1 -0
- package/dist/lib/provider-add.js +219 -0
- package/dist/lib/provider-add.js.map +1 -0
- package/dist/lib/provider-availability.d.ts +13 -0
- package/dist/lib/provider-availability.d.ts.map +1 -0
- package/dist/lib/provider-availability.js +20 -0
- package/dist/lib/provider-availability.js.map +1 -0
- package/dist/lib/provider-metadata.d.ts +32 -0
- package/dist/lib/provider-metadata.d.ts.map +1 -0
- package/dist/lib/provider-metadata.js +90 -0
- package/dist/lib/provider-metadata.js.map +1 -0
- package/dist/lib/provider-model-matching.d.ts +12 -0
- package/dist/lib/provider-model-matching.d.ts.map +1 -0
- package/dist/lib/provider-model-matching.js +23 -0
- package/dist/lib/provider-model-matching.js.map +1 -0
- package/dist/lib/provider-registration.d.ts +321 -0
- package/dist/lib/provider-registration.d.ts.map +1 -0
- package/dist/lib/provider-registration.js +335 -0
- package/dist/lib/provider-registration.js.map +1 -0
- package/dist/lib/quota-accounting-projection.d.ts +9 -0
- package/dist/lib/quota-accounting-projection.d.ts.map +1 -0
- package/dist/lib/quota-accounting-projection.js +254 -0
- package/dist/lib/quota-accounting-projection.js.map +1 -0
- package/dist/lib/quota-columns.d.ts +38 -0
- package/dist/lib/quota-columns.d.ts.map +1 -0
- package/dist/lib/quota-columns.js +129 -0
- package/dist/lib/quota-columns.js.map +1 -0
- package/dist/lib/quota-command-format.d.ts +34 -0
- package/dist/lib/quota-command-format.d.ts.map +1 -0
- package/dist/lib/quota-command-format.js +240 -0
- package/dist/lib/quota-command-format.js.map +1 -0
- package/dist/lib/quota-dialog-command-specs.d.ts +63 -0
- package/dist/lib/quota-dialog-command-specs.d.ts.map +1 -0
- package/dist/lib/quota-dialog-command-specs.js +145 -0
- package/dist/lib/quota-dialog-command-specs.js.map +1 -0
- package/dist/lib/quota-dialog-commands.d.ts +75 -0
- package/dist/lib/quota-dialog-commands.d.ts.map +1 -0
- package/dist/lib/quota-dialog-commands.js +586 -0
- package/dist/lib/quota-dialog-commands.js.map +1 -0
- package/dist/lib/quota-entry-display.d.ts +7 -0
- package/dist/lib/quota-entry-display.d.ts.map +1 -0
- package/dist/lib/quota-entry-display.js +59 -0
- package/dist/lib/quota-entry-display.js.map +1 -0
- package/dist/lib/quota-exhaustion-projection.d.ts +11 -0
- package/dist/lib/quota-exhaustion-projection.d.ts.map +1 -0
- package/dist/lib/quota-exhaustion-projection.js +105 -0
- package/dist/lib/quota-exhaustion-projection.js.map +1 -0
- package/dist/lib/quota-export-types.d.ts +96 -0
- package/dist/lib/quota-export-types.d.ts.map +1 -0
- package/dist/lib/quota-export-types.js +2 -0
- package/dist/lib/quota-export-types.js.map +1 -0
- package/dist/lib/quota-export.d.ts +44 -0
- package/dist/lib/quota-export.d.ts.map +1 -0
- package/dist/lib/quota-export.js +221 -0
- package/dist/lib/quota-export.js.map +1 -0
- package/dist/lib/quota-format-style.d.ts +21 -0
- package/dist/lib/quota-format-style.d.ts.map +1 -0
- package/dist/lib/quota-format-style.js +38 -0
- package/dist/lib/quota-format-style.js.map +1 -0
- package/dist/lib/quota-providers-local.d.ts +55 -0
- package/dist/lib/quota-providers-local.d.ts.map +1 -0
- package/dist/lib/quota-providers-local.js +327 -0
- package/dist/lib/quota-providers-local.js.map +1 -0
- package/dist/lib/quota-providers-remote.d.ts +27 -0
- package/dist/lib/quota-providers-remote.d.ts.map +1 -0
- package/dist/lib/quota-providers-remote.js +757 -0
- package/dist/lib/quota-providers-remote.js.map +1 -0
- package/dist/lib/quota-providers.d.ts +158 -0
- package/dist/lib/quota-providers.d.ts.map +1 -0
- package/dist/lib/quota-providers.js +1160 -0
- package/dist/lib/quota-providers.js.map +1 -0
- package/dist/lib/quota-render-data.d.ts +135 -0
- package/dist/lib/quota-render-data.d.ts.map +1 -0
- package/dist/lib/quota-render-data.js +462 -0
- package/dist/lib/quota-render-data.js.map +1 -0
- package/dist/lib/quota-report-message.d.ts +22 -0
- package/dist/lib/quota-report-message.d.ts.map +1 -0
- package/dist/lib/quota-report-message.js +36 -0
- package/dist/lib/quota-report-message.js.map +1 -0
- package/dist/lib/quota-reset-notifications.d.ts +20 -0
- package/dist/lib/quota-reset-notifications.d.ts.map +1 -0
- package/dist/lib/quota-reset-notifications.js +331 -0
- package/dist/lib/quota-reset-notifications.js.map +1 -0
- package/dist/lib/quota-retry-wait.d.ts +36 -0
- package/dist/lib/quota-retry-wait.d.ts.map +1 -0
- package/dist/lib/quota-retry-wait.js +67 -0
- package/dist/lib/quota-retry-wait.js.map +1 -0
- package/dist/lib/quota-runtime-context.d.ts +56 -0
- package/dist/lib/quota-runtime-context.d.ts.map +1 -0
- package/dist/lib/quota-runtime-context.js +113 -0
- package/dist/lib/quota-runtime-context.js.map +1 -0
- package/dist/lib/quota-state-codec.d.ts +16 -0
- package/dist/lib/quota-state-codec.d.ts.map +1 -0
- package/dist/lib/quota-state-codec.js +479 -0
- package/dist/lib/quota-state-codec.js.map +1 -0
- package/dist/lib/quota-state.d.ts +28 -0
- package/dist/lib/quota-state.d.ts.map +1 -0
- package/dist/lib/quota-state.js +473 -0
- package/dist/lib/quota-state.js.map +1 -0
- package/dist/lib/quota-stats-format.d.ts +29 -0
- package/dist/lib/quota-stats-format.d.ts.map +1 -0
- package/dist/lib/quota-stats-format.js +459 -0
- package/dist/lib/quota-stats-format.js.map +1 -0
- package/dist/lib/quota-stats.d.ts +174 -0
- package/dist/lib/quota-stats.d.ts.map +1 -0
- package/dist/lib/quota-stats.js +713 -0
- package/dist/lib/quota-stats.js.map +1 -0
- package/dist/lib/quota-status.d.ts +58 -0
- package/dist/lib/quota-status.d.ts.map +1 -0
- package/dist/lib/quota-status.js +865 -0
- package/dist/lib/quota-status.js.map +1 -0
- package/dist/lib/quota-surface-data.d.ts +21 -0
- package/dist/lib/quota-surface-data.d.ts.map +1 -0
- package/dist/lib/quota-surface-data.js +361 -0
- package/dist/lib/quota-surface-data.js.map +1 -0
- package/dist/lib/quota-telemetry.d.ts +45 -0
- package/dist/lib/quota-telemetry.d.ts.map +1 -0
- package/dist/lib/quota-telemetry.js +304 -0
- package/dist/lib/quota-telemetry.js.map +1 -0
- package/dist/lib/report-document.d.ts +90 -0
- package/dist/lib/report-document.d.ts.map +1 -0
- package/dist/lib/report-document.js +190 -0
- package/dist/lib/report-document.js.map +1 -0
- package/dist/lib/resolved-auth-identity.d.ts +36 -0
- package/dist/lib/resolved-auth-identity.d.ts.map +1 -0
- package/dist/lib/resolved-auth-identity.js +192 -0
- package/dist/lib/resolved-auth-identity.js.map +1 -0
- package/dist/lib/runtime-provider-ids.d.ts +4 -0
- package/dist/lib/runtime-provider-ids.d.ts.map +1 -0
- package/dist/lib/runtime-provider-ids.js +10 -0
- package/dist/lib/runtime-provider-ids.js.map +1 -0
- package/dist/lib/scoped-update-migration.d.ts +103 -0
- package/dist/lib/scoped-update-migration.d.ts.map +1 -0
- package/dist/lib/scoped-update-migration.js +348 -0
- package/dist/lib/scoped-update-migration.js.map +1 -0
- package/dist/lib/scoped-update.d.ts +78 -0
- package/dist/lib/scoped-update.d.ts.map +1 -0
- package/dist/lib/scoped-update.js +640 -0
- package/dist/lib/scoped-update.js.map +1 -0
- package/dist/lib/session-tokens-format.d.ts +36 -0
- package/dist/lib/session-tokens-format.d.ts.map +1 -0
- package/dist/lib/session-tokens-format.js +111 -0
- package/dist/lib/session-tokens-format.js.map +1 -0
- package/dist/lib/session-tokens.d.ts +27 -0
- package/dist/lib/session-tokens.d.ts.map +1 -0
- package/dist/lib/session-tokens.js +55 -0
- package/dist/lib/session-tokens.js.map +1 -0
- package/dist/lib/synthetic-config.d.ts +15 -0
- package/dist/lib/synthetic-config.d.ts.map +1 -0
- package/dist/lib/synthetic-config.js +28 -0
- package/dist/lib/synthetic-config.js.map +1 -0
- package/dist/lib/synthetic.d.ts +12 -0
- package/dist/lib/synthetic.d.ts.map +1 -0
- package/dist/lib/synthetic.js +173 -0
- package/dist/lib/synthetic.js.map +1 -0
- package/dist/lib/toast-format-grouped.d.ts +25 -0
- package/dist/lib/toast-format-grouped.d.ts.map +1 -0
- package/dist/lib/toast-format-grouped.js +296 -0
- package/dist/lib/toast-format-grouped.js.map +1 -0
- package/dist/lib/token-buckets.d.ts +24 -0
- package/dist/lib/token-buckets.d.ts.map +1 -0
- package/dist/lib/token-buckets.js +28 -0
- package/dist/lib/token-buckets.js.map +1 -0
- package/dist/lib/token-cost.d.ts +10 -0
- package/dist/lib/token-cost.d.ts.map +1 -0
- package/dist/lib/token-cost.js +16 -0
- package/dist/lib/token-cost.js.map +1 -0
- package/dist/lib/tui-compact-format.d.ts +10 -0
- package/dist/lib/tui-compact-format.d.ts.map +1 -0
- package/dist/lib/tui-compact-format.js +460 -0
- package/dist/lib/tui-compact-format.js.map +1 -0
- package/dist/lib/tui-panel-state.d.ts +15 -0
- package/dist/lib/tui-panel-state.d.ts.map +1 -0
- package/dist/lib/tui-panel-state.js +2 -0
- package/dist/lib/tui-panel-state.js.map +1 -0
- package/dist/lib/tui-prompt-bar-format.d.ts +25 -0
- package/dist/lib/tui-prompt-bar-format.d.ts.map +1 -0
- package/dist/lib/tui-prompt-bar-format.js +206 -0
- package/dist/lib/tui-prompt-bar-format.js.map +1 -0
- package/dist/lib/tui-sidebar-format.d.ts +13 -0
- package/dist/lib/tui-sidebar-format.d.ts.map +1 -0
- package/dist/lib/tui-sidebar-format.js +34 -0
- package/dist/lib/tui-sidebar-format.js.map +1 -0
- package/dist/lib/types.d.ts +738 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +85 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/usage-ownership.d.ts +47 -0
- package/dist/lib/usage-ownership.d.ts.map +1 -0
- package/dist/lib/usage-ownership.js +98 -0
- package/dist/lib/usage-ownership.js.map +1 -0
- package/dist/lib/version.d.ts +2 -0
- package/dist/lib/version.d.ts.map +1 -0
- package/dist/lib/version.js +33 -0
- package/dist/lib/version.js.map +1 -0
- package/dist/lib/xai.d.ts +52 -0
- package/dist/lib/xai.d.ts.map +1 -0
- package/dist/lib/xai.js +253 -0
- package/dist/lib/xai.js.map +1 -0
- package/dist/lib/zai-auth.d.ts +15 -0
- package/dist/lib/zai-auth.d.ts.map +1 -0
- package/dist/lib/zai-auth.js +37 -0
- package/dist/lib/zai-auth.js.map +1 -0
- package/dist/lib/zai.d.ts +5 -0
- package/dist/lib/zai.d.ts.map +1 -0
- package/dist/lib/zai.js +14 -0
- package/dist/lib/zai.js.map +1 -0
- package/dist/lib/zhipu-auth.d.ts +15 -0
- package/dist/lib/zhipu-auth.d.ts.map +1 -0
- package/dist/lib/zhipu-auth.js +42 -0
- package/dist/lib/zhipu-auth.js.map +1 -0
- package/dist/lib/zhipu.d.ts +5 -0
- package/dist/lib/zhipu.d.ts.map +1 -0
- package/dist/lib/zhipu.js +13 -0
- package/dist/lib/zhipu.js.map +1 -0
- package/dist/plugin.d.ts +10 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +95 -0
- package/dist/plugin.js.map +1 -0
- package/dist/providers/accounting-decimal.d.ts +2 -0
- package/dist/providers/accounting-decimal.d.ts.map +1 -0
- package/dist/providers/accounting-decimal.js +23 -0
- package/dist/providers/accounting-decimal.js.map +1 -0
- package/dist/providers/alibaba-coding-plan.d.ts +3 -0
- package/dist/providers/alibaba-coding-plan.d.ts.map +1 -0
- package/dist/providers/alibaba-coding-plan.js +122 -0
- package/dist/providers/alibaba-coding-plan.js.map +1 -0
- package/dist/providers/alibaba-token-plan.d.ts +3 -0
- package/dist/providers/alibaba-token-plan.d.ts.map +1 -0
- package/dist/providers/alibaba-token-plan.js +90 -0
- package/dist/providers/alibaba-token-plan.js.map +1 -0
- package/dist/providers/anthropic.d.ts +9 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +236 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/cache-policies.d.ts +67 -0
- package/dist/providers/cache-policies.d.ts.map +1 -0
- package/dist/providers/cache-policies.js +263 -0
- package/dist/providers/cache-policies.js.map +1 -0
- package/dist/providers/chutes.d.ts +6 -0
- package/dist/providers/chutes.d.ts.map +1 -0
- package/dist/providers/chutes.js +50 -0
- package/dist/providers/chutes.js.map +1 -0
- package/dist/providers/copilot.d.ts +9 -0
- package/dist/providers/copilot.d.ts.map +1 -0
- package/dist/providers/copilot.js +323 -0
- package/dist/providers/copilot.js.map +1 -0
- package/dist/providers/cursor.d.ts +3 -0
- package/dist/providers/cursor.d.ts.map +1 -0
- package/dist/providers/cursor.js +182 -0
- package/dist/providers/cursor.js.map +1 -0
- package/dist/providers/deepseek.d.ts +9 -0
- package/dist/providers/deepseek.d.ts.map +1 -0
- package/dist/providers/deepseek.js +111 -0
- package/dist/providers/deepseek.js.map +1 -0
- package/dist/providers/glm-coding-plan-provider.d.ts +56 -0
- package/dist/providers/glm-coding-plan-provider.d.ts.map +1 -0
- package/dist/providers/glm-coding-plan-provider.js +146 -0
- package/dist/providers/glm-coding-plan-provider.js.map +1 -0
- package/dist/providers/google-account-format.d.ts +7 -0
- package/dist/providers/google-account-format.d.ts.map +1 -0
- package/dist/providers/google-account-format.js +52 -0
- package/dist/providers/google-account-format.js.map +1 -0
- package/dist/providers/google-agy.d.ts +17 -0
- package/dist/providers/google-agy.d.ts.map +1 -0
- package/dist/providers/google-agy.js +256 -0
- package/dist/providers/google-agy.js.map +1 -0
- package/dist/providers/google-gemini-cli.d.ts +17 -0
- package/dist/providers/google-gemini-cli.d.ts.map +1 -0
- package/dist/providers/google-gemini-cli.js +228 -0
- package/dist/providers/google-gemini-cli.js.map +1 -0
- package/dist/providers/kilo.d.ts +6 -0
- package/dist/providers/kilo.d.ts.map +1 -0
- package/dist/providers/kilo.js +145 -0
- package/dist/providers/kilo.js.map +1 -0
- package/dist/providers/kimi-code.d.ts +4 -0
- package/dist/providers/kimi-code.d.ts.map +1 -0
- package/dist/providers/kimi-code.js +175 -0
- package/dist/providers/kimi-code.js.map +1 -0
- package/dist/providers/mimo.d.ts +3 -0
- package/dist/providers/mimo.d.ts.map +1 -0
- package/dist/providers/mimo.js +149 -0
- package/dist/providers/mimo.js.map +1 -0
- package/dist/providers/minimax-coding-plan.d.ts +26 -0
- package/dist/providers/minimax-coding-plan.d.ts.map +1 -0
- package/dist/providers/minimax-coding-plan.js +391 -0
- package/dist/providers/minimax-coding-plan.js.map +1 -0
- package/dist/providers/nanogpt.d.ts +6 -0
- package/dist/providers/nanogpt.d.ts.map +1 -0
- package/dist/providers/nanogpt.js +160 -0
- package/dist/providers/nanogpt.js.map +1 -0
- package/dist/providers/ollama-cloud.d.ts +9 -0
- package/dist/providers/ollama-cloud.d.ts.map +1 -0
- package/dist/providers/ollama-cloud.js +129 -0
- package/dist/providers/ollama-cloud.js.map +1 -0
- package/dist/providers/openai.d.ts +6 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +313 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/opencode-go.d.ts +4 -0
- package/dist/providers/opencode-go.d.ts.map +1 -0
- package/dist/providers/opencode-go.js +409 -0
- package/dist/providers/opencode-go.js.map +1 -0
- package/dist/providers/opencode-zen.d.ts +3 -0
- package/dist/providers/opencode-zen.d.ts.map +1 -0
- package/dist/providers/opencode-zen.js +288 -0
- package/dist/providers/opencode-zen.js.map +1 -0
- package/dist/providers/openrouter.d.ts +6 -0
- package/dist/providers/openrouter.d.ts.map +1 -0
- package/dist/providers/openrouter.js +94 -0
- package/dist/providers/openrouter.js.map +1 -0
- package/dist/providers/quota-providers.d.ts +6 -0
- package/dist/providers/quota-providers.d.ts.map +1 -0
- package/dist/providers/quota-providers.js +287 -0
- package/dist/providers/quota-providers.js.map +1 -0
- package/dist/providers/registry.d.ts +9 -0
- package/dist/providers/registry.d.ts.map +1 -0
- package/dist/providers/registry.js +71 -0
- package/dist/providers/registry.js.map +1 -0
- package/dist/providers/result-helpers.d.ts +61 -0
- package/dist/providers/result-helpers.d.ts.map +1 -0
- package/dist/providers/result-helpers.js +117 -0
- package/dist/providers/result-helpers.js.map +1 -0
- package/dist/providers/synthetic.d.ts +6 -0
- package/dist/providers/synthetic.d.ts.map +1 -0
- package/dist/providers/synthetic.js +79 -0
- package/dist/providers/synthetic.js.map +1 -0
- package/dist/providers/xai.d.ts +6 -0
- package/dist/providers/xai.d.ts.map +1 -0
- package/dist/providers/xai.js +122 -0
- package/dist/providers/xai.js.map +1 -0
- package/dist/providers/zai.d.ts +2 -0
- package/dist/providers/zai.d.ts.map +1 -0
- package/dist/providers/zai.js +24 -0
- package/dist/providers/zai.js.map +1 -0
- package/dist/providers/zhipu.d.ts +2 -0
- package/dist/providers/zhipu.d.ts.map +1 -0
- package/dist/providers/zhipu.js +21 -0
- package/dist/providers/zhipu.js.map +1 -0
- package/dist/rpc.d.ts +72 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +77 -0
- package/dist/rpc.js.map +1 -0
- package/dist/ui/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/ui/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/ui/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/ui/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/ui/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/ui/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/ui/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/ui/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/ui/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/ui/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/ui/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/ui/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/ui/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/ui/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/ui/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/ui/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/ui/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/ui/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/ui/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/ui/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/ui/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/ui/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/ui/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/ui/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/ui/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/ui/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/ui/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/ui/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/ui/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/ui/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/ui/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/ui/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/ui/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/ui/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/ui/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/ui/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/ui/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/ui/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/ui/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/ui/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/ui/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/ui/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/ui/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/ui/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/ui/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/ui/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/ui/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/ui/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/ui/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/ui/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/ui/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/ui/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/ui/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/ui/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/ui/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/ui/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/ui/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/ui/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/ui/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/ui/assets/index-CPEiQt-C.js +8 -0
- package/dist/ui/assets/index-D3-Yn_WA.css +1 -0
- package/dist/ui/index.html +13 -0
- package/package.json +123 -3
|
@@ -0,0 +1,1269 @@
|
|
|
1
|
+
import { existsSync, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { getOpenCodeDbPath } from "./opencode-db-path.js";
|
|
3
|
+
import { openOpenCodeSqliteReadOnly } from "./opencode-sqlite.js";
|
|
4
|
+
import { selectForkOwners } from "./usage-ownership.js";
|
|
5
|
+
/**
|
|
6
|
+
* Error thrown when a session is not found.
|
|
7
|
+
*
|
|
8
|
+
* OpenCode 2 stores sessions and messages in SQLite (`opencode.db`) under the
|
|
9
|
+
* `session_v2` and `session_message` tables. This is thrown by
|
|
10
|
+
* iterAssistantMessagesForSession when the database is missing/unreadable, the
|
|
11
|
+
* session id is invalid, or the session row does not exist.
|
|
12
|
+
*/
|
|
13
|
+
export class SessionNotFoundError extends Error {
|
|
14
|
+
sessionID;
|
|
15
|
+
checkedPath;
|
|
16
|
+
constructor(sessionID, checkedPath) {
|
|
17
|
+
super(`Session not found: ${sessionID}`);
|
|
18
|
+
this.sessionID = sessionID;
|
|
19
|
+
this.checkedPath = checkedPath;
|
|
20
|
+
this.name = "SessionNotFoundError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Stay comfortably below SQLite's default host-parameter cap once optional
|
|
24
|
+
// time filters are included in the query.
|
|
25
|
+
const SQLITE_MAX_MESSAGE_QUERY_ARGS = 900;
|
|
26
|
+
function normalizeNumber(n) {
|
|
27
|
+
return typeof n === "number" && Number.isFinite(n) ? n : undefined;
|
|
28
|
+
}
|
|
29
|
+
function normalizeString(s) {
|
|
30
|
+
return typeof s === "string" ? s : undefined;
|
|
31
|
+
}
|
|
32
|
+
function mapRowToOpenCodeMessage(row) {
|
|
33
|
+
if (!row || typeof row !== "object")
|
|
34
|
+
return null;
|
|
35
|
+
if (typeof row.id !== "string" || typeof row.session_id !== "string")
|
|
36
|
+
return null;
|
|
37
|
+
if (typeof row.time_created !== "number")
|
|
38
|
+
return null;
|
|
39
|
+
const input = normalizeNumber(row.tokens_input);
|
|
40
|
+
const output = normalizeNumber(row.tokens_output);
|
|
41
|
+
const reasoning = normalizeNumber(row.tokens_reasoning);
|
|
42
|
+
const cacheRead = normalizeNumber(row.tokens_cache_read);
|
|
43
|
+
const cacheWrite = normalizeNumber(row.tokens_cache_write);
|
|
44
|
+
const hasTokens = [input, output, reasoning, cacheRead, cacheWrite].some((value) => value !== undefined);
|
|
45
|
+
return {
|
|
46
|
+
id: row.id,
|
|
47
|
+
sessionID: row.session_id,
|
|
48
|
+
role: normalizeString(row.role) ?? "unknown",
|
|
49
|
+
providerID: normalizeString(row.provider_id),
|
|
50
|
+
modelID: normalizeString(row.model_id),
|
|
51
|
+
tokens: hasTokens
|
|
52
|
+
? {
|
|
53
|
+
input: input ?? 0,
|
|
54
|
+
output: output ?? 0,
|
|
55
|
+
...(reasoning === undefined ? {} : { reasoning }),
|
|
56
|
+
cache: { read: cacheRead ?? 0, write: cacheWrite ?? 0 },
|
|
57
|
+
}
|
|
58
|
+
: undefined,
|
|
59
|
+
cost: normalizeNumber(row.cost),
|
|
60
|
+
time: {
|
|
61
|
+
created: row.time_created,
|
|
62
|
+
completed: normalizeNumber(row.time_completed),
|
|
63
|
+
},
|
|
64
|
+
agent: normalizeString(row.agent),
|
|
65
|
+
mode: normalizeString(row.mode),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function openDbOrNull() {
|
|
69
|
+
const dbPath = getOpenCodeDbPath();
|
|
70
|
+
if (dbPath === ":memory:" || !existsSync(dbPath))
|
|
71
|
+
return null;
|
|
72
|
+
return {
|
|
73
|
+
dbPath,
|
|
74
|
+
open: () => openOpenCodeSqliteReadOnly(dbPath),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function validateSessionIdOrThrow(sessionID) {
|
|
78
|
+
if (!sessionID.startsWith("ses_")) {
|
|
79
|
+
throw new SessionNotFoundError(sessionID, "(invalid session ID format)");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function normalizeSessionIdsOrThrow(sessionIDs) {
|
|
83
|
+
const unique = [];
|
|
84
|
+
const seen = new Set();
|
|
85
|
+
for (const sessionID of sessionIDs) {
|
|
86
|
+
validateSessionIdOrThrow(sessionID);
|
|
87
|
+
if (seen.has(sessionID))
|
|
88
|
+
continue;
|
|
89
|
+
seen.add(sessionID);
|
|
90
|
+
unique.push(sessionID);
|
|
91
|
+
}
|
|
92
|
+
return unique;
|
|
93
|
+
}
|
|
94
|
+
function chunkArray(items, chunkSize) {
|
|
95
|
+
const chunks = [];
|
|
96
|
+
for (let i = 0; i < items.length; i += chunkSize) {
|
|
97
|
+
chunks.push(items.slice(i, i + chunkSize));
|
|
98
|
+
}
|
|
99
|
+
return chunks;
|
|
100
|
+
}
|
|
101
|
+
function guardedJsonScalar(path) {
|
|
102
|
+
return `CASE WHEN json_valid(data) THEN json_extract(data, '${path}') END`;
|
|
103
|
+
}
|
|
104
|
+
const PROJECTED_MESSAGE_COLUMNS = [
|
|
105
|
+
"id",
|
|
106
|
+
"session_id",
|
|
107
|
+
"time_created",
|
|
108
|
+
"type AS role",
|
|
109
|
+
`${guardedJsonScalar("$.model.providerID")} AS provider_id`,
|
|
110
|
+
`${guardedJsonScalar("$.model.id")} AS model_id`,
|
|
111
|
+
`${guardedJsonScalar("$.tokens.input")} AS tokens_input`,
|
|
112
|
+
`${guardedJsonScalar("$.tokens.output")} AS tokens_output`,
|
|
113
|
+
`${guardedJsonScalar("$.tokens.reasoning")} AS tokens_reasoning`,
|
|
114
|
+
`${guardedJsonScalar("$.tokens.cache.read")} AS tokens_cache_read`,
|
|
115
|
+
`${guardedJsonScalar("$.tokens.cache.write")} AS tokens_cache_write`,
|
|
116
|
+
`${guardedJsonScalar("$.cost")} AS cost`,
|
|
117
|
+
`${guardedJsonScalar("$.time.completed")} AS time_completed`,
|
|
118
|
+
`${guardedJsonScalar("$.agent")} AS agent`,
|
|
119
|
+
].join(", ");
|
|
120
|
+
const ASSISTANT_FILTER = `type = 'assistant'`;
|
|
121
|
+
function buildMessageQuery(params) {
|
|
122
|
+
if (params.sessionID && params.sessionIDs?.length) {
|
|
123
|
+
throw new Error("buildMessageQuery received both sessionID and sessionIDs");
|
|
124
|
+
}
|
|
125
|
+
const where = [];
|
|
126
|
+
const args = [];
|
|
127
|
+
if (params.sessionID) {
|
|
128
|
+
where.push(`session_id = ?`);
|
|
129
|
+
args.push(params.sessionID);
|
|
130
|
+
}
|
|
131
|
+
else if (params.sessionIDs) {
|
|
132
|
+
if (params.sessionIDs.length === 0) {
|
|
133
|
+
where.push(`1 = 0`);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
where.push(`session_id IN (${params.sessionIDs.map(() => "?").join(", ")})`);
|
|
137
|
+
args.push(...params.sessionIDs);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (typeof params.sinceMs === "number") {
|
|
141
|
+
where.push(`time_created >= ?`);
|
|
142
|
+
args.push(params.sinceMs);
|
|
143
|
+
}
|
|
144
|
+
if (typeof params.untilMs === "number") {
|
|
145
|
+
where.push(`time_created <= ?`);
|
|
146
|
+
args.push(params.untilMs);
|
|
147
|
+
}
|
|
148
|
+
where.push(ASSISTANT_FILTER);
|
|
149
|
+
const sql = `SELECT ${PROJECTED_MESSAGE_COLUMNS} FROM "session_message"` +
|
|
150
|
+
(where.length ? ` WHERE ${where.join(" AND ")}` : "") +
|
|
151
|
+
` ORDER BY time_created ASC, id ASC`;
|
|
152
|
+
return { sql, args };
|
|
153
|
+
}
|
|
154
|
+
function hasJsonExtract(conn) {
|
|
155
|
+
try {
|
|
156
|
+
const row = conn.get("SELECT json_extract('{\"role\":\"assistant\"}', '$.role') as r");
|
|
157
|
+
return row?.r === "assistant";
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The columns a table ships with, or `null` when the table is absent or
|
|
165
|
+
* unreadable. R46 schema drift degrades to "unknown project" instead of
|
|
166
|
+
* failing; table names here are fixed literals, never user input.
|
|
167
|
+
*/
|
|
168
|
+
function readTableColumns(conn, table) {
|
|
169
|
+
try {
|
|
170
|
+
const rows = conn.all(`PRAGMA table_info("${table}")`);
|
|
171
|
+
const columns = new Set();
|
|
172
|
+
for (const row of rows) {
|
|
173
|
+
if (row && typeof row.name === "string")
|
|
174
|
+
columns.add(row.name);
|
|
175
|
+
}
|
|
176
|
+
return columns.size > 0 ? columns : null;
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function mapAssistantMessages(rows) {
|
|
183
|
+
const out = [];
|
|
184
|
+
for (const row of rows) {
|
|
185
|
+
const msg = mapRowToOpenCodeMessage(row);
|
|
186
|
+
if (!msg)
|
|
187
|
+
continue;
|
|
188
|
+
if (String(msg.role).toLowerCase() !== "assistant")
|
|
189
|
+
continue;
|
|
190
|
+
out.push(msg);
|
|
191
|
+
}
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
function completedAt(message) {
|
|
195
|
+
const value = message.time?.completed;
|
|
196
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0
|
|
197
|
+
? Math.trunc(value)
|
|
198
|
+
: null;
|
|
199
|
+
}
|
|
200
|
+
function mapCompletedAssistantMessages(rows) {
|
|
201
|
+
return mapAssistantMessages(rows).filter((message) => completedAt(message) !== null);
|
|
202
|
+
}
|
|
203
|
+
function buildCompletedAssistantQuery(params, includeUpdatedAt = false) {
|
|
204
|
+
const completedScalar = guardedJsonScalar("$.time.completed");
|
|
205
|
+
const completedExpression = `CAST(${completedScalar} AS REAL)`;
|
|
206
|
+
const projectedColumns = includeUpdatedAt
|
|
207
|
+
? `${PROJECTED_MESSAGE_COLUMNS}, time_updated`
|
|
208
|
+
: PROJECTED_MESSAGE_COLUMNS;
|
|
209
|
+
const where = [
|
|
210
|
+
ASSISTANT_FILTER,
|
|
211
|
+
`CASE WHEN json_valid(data) THEN json_type(data, '$.time.completed') END IN ('integer', 'real')`,
|
|
212
|
+
`${completedExpression} > 0`,
|
|
213
|
+
];
|
|
214
|
+
const args = [];
|
|
215
|
+
if (typeof params.completedSinceMs === "number") {
|
|
216
|
+
where.push(`${completedExpression} >= ?`);
|
|
217
|
+
args.push(params.completedSinceMs);
|
|
218
|
+
}
|
|
219
|
+
if (typeof params.completedUntilMs === "number") {
|
|
220
|
+
where.push(`${completedExpression} <= ?`);
|
|
221
|
+
args.push(params.completedUntilMs);
|
|
222
|
+
}
|
|
223
|
+
if (params.completedAtTimes !== undefined) {
|
|
224
|
+
const times = [...new Set(params.completedAtTimes)]
|
|
225
|
+
.filter((time) => Number.isFinite(time))
|
|
226
|
+
.sort((a, b) => a - b);
|
|
227
|
+
if (times.length === 0) {
|
|
228
|
+
where.push(`1 = 0`);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
// One JSON-array bind keeps the exact-time candidate projection to a
|
|
232
|
+
// single SQLite scan instead of one scan per completion timestamp.
|
|
233
|
+
where.push(`${completedExpression} IN (SELECT value FROM json_each(?))`);
|
|
234
|
+
args.push(JSON.stringify(times));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (params.sessionID !== undefined) {
|
|
238
|
+
where.push(`session_id = ?`);
|
|
239
|
+
args.push(params.sessionID);
|
|
240
|
+
}
|
|
241
|
+
else if (params.sessionIDs !== undefined) {
|
|
242
|
+
if (params.sessionIDs.length === 0) {
|
|
243
|
+
where.push(`1 = 0`);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
where.push(`session_id IN (${params.sessionIDs.map(() => "?").join(", ")})`);
|
|
247
|
+
args.push(...params.sessionIDs);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (params.messageIDs !== undefined) {
|
|
251
|
+
if (params.messageIDs.length === 0) {
|
|
252
|
+
where.push(`1 = 0`);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
where.push(`id IN (${params.messageIDs.map(() => "?").join(", ")})`);
|
|
256
|
+
args.push(...params.messageIDs);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
// `readCompletedAssistantRowsFrom` sorts the projected rows itself
|
|
261
|
+
// (`completedAtMs ASC, messageID ASC`), so a SQL ORDER BY here only adds a
|
|
262
|
+
// temp B-tree over every matched row. Keep the scan unsorted and let the
|
|
263
|
+
// single deterministic in-memory sort define the result order.
|
|
264
|
+
sql: `SELECT ${projectedColumns} FROM "session_message"` + ` WHERE ${where.join(" AND ")}`,
|
|
265
|
+
args,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/** Deterministic code-unit comparison used for raw message ids. */
|
|
269
|
+
function compareStringIds(a, b) {
|
|
270
|
+
if (a < b)
|
|
271
|
+
return -1;
|
|
272
|
+
if (a > b)
|
|
273
|
+
return 1;
|
|
274
|
+
return 0;
|
|
275
|
+
}
|
|
276
|
+
function compareRawCompletedRows(a, b) {
|
|
277
|
+
if (a.completedAtMs !== b.completedAtMs)
|
|
278
|
+
return a.completedAtMs - b.completedAtMs;
|
|
279
|
+
return compareStringIds(a.messageID, b.messageID);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Completion-time order for the public message iterator. The SQL builder no
|
|
283
|
+
* longer sorts (the analytics reader sorts its own projection), so this path
|
|
284
|
+
* applies the same `CAST(completed AS REAL), id` order in memory.
|
|
285
|
+
*/
|
|
286
|
+
function compareCompletedMessageOrder(a, b) {
|
|
287
|
+
const aCompleted = a.time?.completed;
|
|
288
|
+
const bCompleted = b.time?.completed;
|
|
289
|
+
const aValue = typeof aCompleted === "number" && Number.isFinite(aCompleted)
|
|
290
|
+
? aCompleted
|
|
291
|
+
: Number.NEGATIVE_INFINITY;
|
|
292
|
+
const bValue = typeof bCompleted === "number" && Number.isFinite(bCompleted)
|
|
293
|
+
? bCompleted
|
|
294
|
+
: Number.NEGATIVE_INFINITY;
|
|
295
|
+
if (aValue !== bValue)
|
|
296
|
+
return aValue - bValue;
|
|
297
|
+
return compareStringIds(a.id, b.id);
|
|
298
|
+
}
|
|
299
|
+
function dedupeStrings(values) {
|
|
300
|
+
const out = [];
|
|
301
|
+
const seen = new Set();
|
|
302
|
+
for (const value of values) {
|
|
303
|
+
if (seen.has(value))
|
|
304
|
+
continue;
|
|
305
|
+
seen.add(value);
|
|
306
|
+
out.push(value);
|
|
307
|
+
}
|
|
308
|
+
return out;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Resolve the id scope shared by the raw completed reader, the compaction
|
|
312
|
+
* reader, and the revision snapshot. `messageIDs` combines with a session
|
|
313
|
+
* scope (AND); `sessionID` and `sessionIDs` are mutually exclusive. Any empty
|
|
314
|
+
* id list resolves to `empty` so no SQLite connection is opened.
|
|
315
|
+
*/
|
|
316
|
+
function normalizeStorageScope(params) {
|
|
317
|
+
if (params.sessionID !== undefined && params.sessionIDs !== undefined) {
|
|
318
|
+
throw new Error("received both sessionID and sessionIDs");
|
|
319
|
+
}
|
|
320
|
+
if (params.sessionID === "")
|
|
321
|
+
return { kind: "empty" };
|
|
322
|
+
if (params.sessionIDs !== undefined && params.sessionIDs.length === 0)
|
|
323
|
+
return { kind: "empty" };
|
|
324
|
+
if (params.messageIDs !== undefined && params.messageIDs.length === 0)
|
|
325
|
+
return { kind: "empty" };
|
|
326
|
+
const ids = {};
|
|
327
|
+
if (params.sessionID !== undefined)
|
|
328
|
+
ids.sessionID = params.sessionID;
|
|
329
|
+
if (params.sessionIDs !== undefined)
|
|
330
|
+
ids.sessionIDs = dedupeStrings(params.sessionIDs);
|
|
331
|
+
if (params.messageIDs !== undefined)
|
|
332
|
+
ids.messageIDs = dedupeStrings(params.messageIDs);
|
|
333
|
+
if (ids.sessionID === undefined && ids.sessionIDs === undefined && ids.messageIDs === undefined) {
|
|
334
|
+
return { kind: "all" };
|
|
335
|
+
}
|
|
336
|
+
return { kind: "scope", ids };
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Chunk one scope into queries under a bind-argument budget. `messageIDs` and
|
|
340
|
+
* session ids combine with AND semantics; when both lists are present they are
|
|
341
|
+
* chunked together so every emitted query stays within the budget.
|
|
342
|
+
*/
|
|
343
|
+
function scopedIdQueries(ids, budget, build) {
|
|
344
|
+
const queries = [];
|
|
345
|
+
const { sessionID, sessionIDs, messageIDs } = ids;
|
|
346
|
+
if (messageIDs === undefined) {
|
|
347
|
+
if (sessionID !== undefined)
|
|
348
|
+
return [build({ sessionID })];
|
|
349
|
+
if (sessionIDs !== undefined) {
|
|
350
|
+
for (const chunk of chunkArray(sessionIDs, budget)) {
|
|
351
|
+
queries.push(build({ sessionIDs: chunk }));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return queries;
|
|
355
|
+
}
|
|
356
|
+
if (sessionID !== undefined) {
|
|
357
|
+
for (const chunk of chunkArray(messageIDs, Math.max(1, budget - 1))) {
|
|
358
|
+
queries.push(build({ sessionID, messageIDs: chunk }));
|
|
359
|
+
}
|
|
360
|
+
return queries;
|
|
361
|
+
}
|
|
362
|
+
if (sessionIDs === undefined) {
|
|
363
|
+
for (const chunk of chunkArray(messageIDs, budget))
|
|
364
|
+
queries.push(build({ messageIDs: chunk }));
|
|
365
|
+
return queries;
|
|
366
|
+
}
|
|
367
|
+
for (const messageChunk of chunkArray(messageIDs, Math.max(1, budget - 1))) {
|
|
368
|
+
const remaining = Math.max(1, budget - messageChunk.length);
|
|
369
|
+
for (const sessionChunk of chunkArray(sessionIDs, remaining)) {
|
|
370
|
+
queries.push(build({ sessionIDs: sessionChunk, messageIDs: messageChunk }));
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return queries;
|
|
374
|
+
}
|
|
375
|
+
function countDefined(values) {
|
|
376
|
+
let count = 0;
|
|
377
|
+
for (const value of values)
|
|
378
|
+
if (value !== undefined)
|
|
379
|
+
count += 1;
|
|
380
|
+
return count;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Fingerprint shared by the upstream fork-copy dedup and the GUI owner set
|
|
384
|
+
* (R50). Exported so P3 groups raw rows by the exact upstream formula.
|
|
385
|
+
*/
|
|
386
|
+
export function forkCopyFingerprint(message, completed) {
|
|
387
|
+
const tokens = message.tokens;
|
|
388
|
+
return JSON.stringify([
|
|
389
|
+
message.time?.created,
|
|
390
|
+
completed,
|
|
391
|
+
message.providerID,
|
|
392
|
+
message.modelID,
|
|
393
|
+
tokens?.input,
|
|
394
|
+
tokens?.output,
|
|
395
|
+
tokens?.reasoning,
|
|
396
|
+
tokens?.cache.read,
|
|
397
|
+
tokens?.cache.write,
|
|
398
|
+
message.cost,
|
|
399
|
+
]);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* The same upstream fingerprint derived from a raw completed row, for the
|
|
403
|
+
* shared deterministic ownership primitive. Exported so the GUI aggregation
|
|
404
|
+
* and the analytics worker use one formula.
|
|
405
|
+
*/
|
|
406
|
+
export function rawAssistantRowFingerprint(row) {
|
|
407
|
+
return forkCopyFingerprint({
|
|
408
|
+
id: row.messageID,
|
|
409
|
+
sessionID: row.sessionID,
|
|
410
|
+
role: "assistant",
|
|
411
|
+
providerID: row.providerID,
|
|
412
|
+
modelID: row.modelID,
|
|
413
|
+
tokens: {
|
|
414
|
+
input: row.tokens.input,
|
|
415
|
+
output: row.tokens.output,
|
|
416
|
+
reasoning: row.tokens.reasoning,
|
|
417
|
+
cache: { read: row.tokens.cacheRead, write: row.tokens.cacheWrite },
|
|
418
|
+
},
|
|
419
|
+
cost: row.cost,
|
|
420
|
+
time: { created: row.createdAtMs, completed: row.completedAtMs },
|
|
421
|
+
}, row.completedAtMs);
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* OpenCode copies a parent's finished messages into each fork with new ids but
|
|
425
|
+
* identical times, model, tokens, and cost. Each finished fingerprint is owned
|
|
426
|
+
* as many times as the session that has it most often; unfinished rows are
|
|
427
|
+
* always kept. Shared deterministic selection lives in `usage-ownership.ts`.
|
|
428
|
+
*/
|
|
429
|
+
function dropForkCopies(messages) {
|
|
430
|
+
const candidates = [];
|
|
431
|
+
for (const message of messages) {
|
|
432
|
+
const candidate = {
|
|
433
|
+
item: message,
|
|
434
|
+
sessionID: message.sessionID,
|
|
435
|
+
messageID: message.id,
|
|
436
|
+
};
|
|
437
|
+
const completed = completedAt(message);
|
|
438
|
+
if (completed !== null)
|
|
439
|
+
candidate.fingerprint = forkCopyFingerprint(message, completed);
|
|
440
|
+
const created = message.time?.created;
|
|
441
|
+
if (typeof created === "number" && Number.isFinite(created))
|
|
442
|
+
candidate.createdAtMs = created;
|
|
443
|
+
candidates.push(candidate);
|
|
444
|
+
}
|
|
445
|
+
return selectForkOwners(candidates);
|
|
446
|
+
}
|
|
447
|
+
function compareMessageOrder(a, b) {
|
|
448
|
+
const aCreated = typeof a.time?.created === "number" ? a.time.created : Number.MAX_SAFE_INTEGER;
|
|
449
|
+
const bCreated = typeof b.time?.created === "number" ? b.time.created : Number.MAX_SAFE_INTEGER;
|
|
450
|
+
if (aCreated !== bCreated)
|
|
451
|
+
return aCreated - bCreated;
|
|
452
|
+
return a.id.localeCompare(b.id);
|
|
453
|
+
}
|
|
454
|
+
export async function getOpenCodeDbStats() {
|
|
455
|
+
const db = openDbOrNull();
|
|
456
|
+
if (!db) {
|
|
457
|
+
return {
|
|
458
|
+
dbPath: getOpenCodeDbPath(),
|
|
459
|
+
sessionCount: 0,
|
|
460
|
+
messageCount: 0,
|
|
461
|
+
assistantMessageCount: 0,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
const conn = await db.open();
|
|
465
|
+
try {
|
|
466
|
+
const sessionRow = conn.get(`SELECT count(*) as c FROM "session_v2"`);
|
|
467
|
+
const messageRow = conn.get(`SELECT count(*) as c FROM "session_message"`);
|
|
468
|
+
let assistantCount = 0;
|
|
469
|
+
if (await hasJsonExtract(conn)) {
|
|
470
|
+
const a = conn.get(`SELECT count(*) as c FROM "session_message" WHERE type = 'assistant'`);
|
|
471
|
+
assistantCount = typeof a?.c === "number" ? a.c : 0;
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
dbPath: db.dbPath,
|
|
475
|
+
sessionCount: typeof sessionRow?.c === "number" ? sessionRow.c : 0,
|
|
476
|
+
messageCount: typeof messageRow?.c === "number" ? messageRow.c : 0,
|
|
477
|
+
assistantMessageCount: assistantCount,
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
finally {
|
|
481
|
+
conn.close();
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
export async function iterAssistantMessages(params) {
|
|
485
|
+
const db = openDbOrNull();
|
|
486
|
+
if (!db)
|
|
487
|
+
return [];
|
|
488
|
+
const conn = await db.open();
|
|
489
|
+
try {
|
|
490
|
+
if (!(await hasJsonExtract(conn)))
|
|
491
|
+
return [];
|
|
492
|
+
const q = buildMessageQuery({ sinceMs: params.sinceMs, untilMs: params.untilMs });
|
|
493
|
+
const rows = conn.all(q.sql, q.args);
|
|
494
|
+
return dropForkCopies(mapAssistantMessages(rows));
|
|
495
|
+
}
|
|
496
|
+
finally {
|
|
497
|
+
conn.close();
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Read authoritative completed assistant/model-loop rows by completion time.
|
|
502
|
+
*
|
|
503
|
+
* This path intentionally does not share the creation-time filters used by token
|
|
504
|
+
* history. A request may be created before a window cutoff and complete inside it.
|
|
505
|
+
*/
|
|
506
|
+
export async function iterCompletedAssistantMessages(params) {
|
|
507
|
+
const db = openDbOrNull();
|
|
508
|
+
if (!db)
|
|
509
|
+
return [];
|
|
510
|
+
const conn = await db.open();
|
|
511
|
+
try {
|
|
512
|
+
if (await hasJsonExtract(conn)) {
|
|
513
|
+
const query = buildCompletedAssistantQuery(params);
|
|
514
|
+
const messages = mapCompletedAssistantMessages(conn.all(query.sql, query.args));
|
|
515
|
+
messages.sort(compareCompletedMessageOrder);
|
|
516
|
+
return dropForkCopies(messages);
|
|
517
|
+
}
|
|
518
|
+
return [];
|
|
519
|
+
}
|
|
520
|
+
finally {
|
|
521
|
+
conn.close();
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Read assistant messages for a specific session only.
|
|
526
|
+
*/
|
|
527
|
+
export async function iterAssistantMessagesForSession(params) {
|
|
528
|
+
const { sessionID, sinceMs, untilMs } = params;
|
|
529
|
+
validateSessionIdOrThrow(sessionID);
|
|
530
|
+
const db = openDbOrNull();
|
|
531
|
+
if (!db) {
|
|
532
|
+
throw new SessionNotFoundError(sessionID, getOpenCodeDbPath());
|
|
533
|
+
}
|
|
534
|
+
const conn = await db.open();
|
|
535
|
+
try {
|
|
536
|
+
const exists = conn.get(`SELECT 1 as ok FROM "session_v2" WHERE id = ? LIMIT 1`, [sessionID]);
|
|
537
|
+
if (!exists) {
|
|
538
|
+
throw new SessionNotFoundError(sessionID, db.dbPath);
|
|
539
|
+
}
|
|
540
|
+
if (!(await hasJsonExtract(conn)))
|
|
541
|
+
return [];
|
|
542
|
+
const q = buildMessageQuery({ sessionID, sinceMs, untilMs });
|
|
543
|
+
const rows = conn.all(q.sql, q.args);
|
|
544
|
+
return mapAssistantMessages(rows);
|
|
545
|
+
}
|
|
546
|
+
finally {
|
|
547
|
+
conn.close();
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Read assistant messages for a specific set of sessions.
|
|
552
|
+
*/
|
|
553
|
+
export async function iterAssistantMessagesForSessions(params) {
|
|
554
|
+
const sessionIDs = normalizeSessionIdsOrThrow(params.sessionIDs);
|
|
555
|
+
const [firstSessionID] = sessionIDs;
|
|
556
|
+
if (firstSessionID === undefined)
|
|
557
|
+
return [];
|
|
558
|
+
const db = openDbOrNull();
|
|
559
|
+
if (!db) {
|
|
560
|
+
throw new SessionNotFoundError(firstSessionID, getOpenCodeDbPath());
|
|
561
|
+
}
|
|
562
|
+
const conn = await db.open();
|
|
563
|
+
try {
|
|
564
|
+
if (!(await hasJsonExtract(conn)))
|
|
565
|
+
return [];
|
|
566
|
+
const reservedArgs = (typeof params.sinceMs === "number" ? 1 : 0) + (typeof params.untilMs === "number" ? 1 : 0);
|
|
567
|
+
const maxSessionIdsPerQuery = Math.max(1, SQLITE_MAX_MESSAGE_QUERY_ARGS - reservedArgs);
|
|
568
|
+
const messages = [];
|
|
569
|
+
for (const sessionIdChunk of chunkArray(sessionIDs, maxSessionIdsPerQuery)) {
|
|
570
|
+
const q = buildMessageQuery({
|
|
571
|
+
sessionIDs: sessionIdChunk,
|
|
572
|
+
sinceMs: params.sinceMs,
|
|
573
|
+
untilMs: params.untilMs,
|
|
574
|
+
});
|
|
575
|
+
const rows = conn.all(q.sql, q.args);
|
|
576
|
+
messages.push(...mapAssistantMessages(rows));
|
|
577
|
+
}
|
|
578
|
+
messages.sort(compareMessageOrder);
|
|
579
|
+
return dropForkCopies(messages);
|
|
580
|
+
}
|
|
581
|
+
finally {
|
|
582
|
+
conn.close();
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
function readAllSessionsIndexFrom(conn) {
|
|
586
|
+
const idx = {};
|
|
587
|
+
const columns = readTableColumns(conn, "session_v2");
|
|
588
|
+
const metadataColumns = [
|
|
589
|
+
columns?.has("agent") ? "agent" : null,
|
|
590
|
+
columns?.has("project_id") ? "project_id" : null,
|
|
591
|
+
columns?.has("directory") ? "directory" : null,
|
|
592
|
+
].filter((column) => column !== null);
|
|
593
|
+
const rows = conn.all(`SELECT id, title, parent_id, time_created, time_updated${metadataColumns.length ? `, ${metadataColumns.join(", ")}` : ""} FROM "session_v2" ORDER BY time_created ASC, id ASC`);
|
|
594
|
+
for (const row of rows) {
|
|
595
|
+
if (!row || typeof row.id !== "string" || !row.id.startsWith("ses_"))
|
|
596
|
+
continue;
|
|
597
|
+
idx[row.id] = {
|
|
598
|
+
id: row.id,
|
|
599
|
+
title: typeof row.title === "string" && row.title.trim() ? row.title : undefined,
|
|
600
|
+
agent: normalizeString(row.agent)?.trim() || undefined,
|
|
601
|
+
parentID: typeof row.parent_id === "string" ? row.parent_id : undefined,
|
|
602
|
+
projectID: normalizeString(row.project_id),
|
|
603
|
+
directory: normalizeString(row.directory),
|
|
604
|
+
time: {
|
|
605
|
+
created: typeof row.time_created === "number" ? row.time_created : undefined,
|
|
606
|
+
updated: typeof row.time_updated === "number" ? row.time_updated : undefined,
|
|
607
|
+
},
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
return idx;
|
|
611
|
+
}
|
|
612
|
+
export async function readAllSessionsIndex() {
|
|
613
|
+
const db = openDbOrNull();
|
|
614
|
+
if (!db)
|
|
615
|
+
return {};
|
|
616
|
+
const conn = await db.open();
|
|
617
|
+
try {
|
|
618
|
+
return readAllSessionsIndexFrom(conn);
|
|
619
|
+
}
|
|
620
|
+
finally {
|
|
621
|
+
conn.close();
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
function mapRawCompletedAssistantRow(row) {
|
|
625
|
+
const message = mapRowToOpenCodeMessage(row);
|
|
626
|
+
if (!message)
|
|
627
|
+
return null;
|
|
628
|
+
if (String(message.role).toLowerCase() !== "assistant")
|
|
629
|
+
return null;
|
|
630
|
+
const completed = completedAt(message);
|
|
631
|
+
if (completed === null)
|
|
632
|
+
return null;
|
|
633
|
+
return {
|
|
634
|
+
sessionID: message.sessionID,
|
|
635
|
+
messageID: message.id,
|
|
636
|
+
createdAtMs: message.time?.created ?? 0,
|
|
637
|
+
completedAtMs: completed,
|
|
638
|
+
tokens: {
|
|
639
|
+
input: message.tokens?.input ?? 0,
|
|
640
|
+
output: message.tokens?.output ?? 0,
|
|
641
|
+
reasoning: message.tokens?.reasoning ?? 0,
|
|
642
|
+
cacheRead: message.tokens?.cache.read ?? 0,
|
|
643
|
+
cacheWrite: message.tokens?.cache.write ?? 0,
|
|
644
|
+
},
|
|
645
|
+
cost: message.cost,
|
|
646
|
+
providerID: message.providerID,
|
|
647
|
+
modelID: message.modelID,
|
|
648
|
+
agent: message.agent,
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Read physical completed assistant rows without fork dedup (R46, R50).
|
|
653
|
+
*
|
|
654
|
+
* Completed-only matches the dashboard step rule: an assistant row counts once
|
|
655
|
+
* `$.time.completed` is a positive number. The optional completed window is
|
|
656
|
+
* inclusive on both ends, so P3 aggregation can request a range directly.
|
|
657
|
+
*
|
|
658
|
+
* `sessionID`, `sessionIDs`, and `messageIDs` are mutually exclusive scopes;
|
|
659
|
+
* empty `sessionIDs`/`messageIDs` resolve to an empty read without opening the
|
|
660
|
+
* database. Large scopes are chunked under the SQLite bind-argument bound and
|
|
661
|
+
* merged back into completion-time order. `messageIDs` is the incremental
|
|
662
|
+
* reconciliation fetch after a `readMessageRevisions` diff. Schema drift (no
|
|
663
|
+
* message table or no JSON support) degrades to an empty read.
|
|
664
|
+
*/
|
|
665
|
+
function readCompletedAssistantRowsFrom(conn, params) {
|
|
666
|
+
const scope = normalizeStorageScope(params);
|
|
667
|
+
if (scope.kind === "empty")
|
|
668
|
+
return [];
|
|
669
|
+
const columns = readTableColumns(conn, "session_message");
|
|
670
|
+
if (!columns?.has("type") || !columns.has("data"))
|
|
671
|
+
return [];
|
|
672
|
+
if (!hasJsonExtract(conn))
|
|
673
|
+
return [];
|
|
674
|
+
const hasUpdatedAt = columns.has("time_updated");
|
|
675
|
+
const reservedArgs = countDefined([
|
|
676
|
+
params.completedSinceMs,
|
|
677
|
+
params.completedUntilMs,
|
|
678
|
+
params.completedAtTimes,
|
|
679
|
+
]);
|
|
680
|
+
const maxIdsPerQuery = Math.max(1, SQLITE_MAX_MESSAGE_QUERY_ARGS - reservedArgs);
|
|
681
|
+
const out = [];
|
|
682
|
+
const collect = (query) => {
|
|
683
|
+
for (const row of conn.all(query.sql, query.args)) {
|
|
684
|
+
const mapped = mapRawCompletedAssistantRow(row);
|
|
685
|
+
if (!mapped)
|
|
686
|
+
continue;
|
|
687
|
+
if (hasUpdatedAt)
|
|
688
|
+
mapped.updatedAtMs = normalizeNumber(row.time_updated) ?? null;
|
|
689
|
+
out.push(mapped);
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
if (scope.kind === "all") {
|
|
693
|
+
collect(buildCompletedAssistantQuery(params, hasUpdatedAt));
|
|
694
|
+
}
|
|
695
|
+
else {
|
|
696
|
+
const queries = scopedIdQueries(scope.ids, maxIdsPerQuery, (clause) => buildCompletedAssistantQuery({
|
|
697
|
+
completedSinceMs: params.completedSinceMs,
|
|
698
|
+
completedUntilMs: params.completedUntilMs,
|
|
699
|
+
completedAtTimes: params.completedAtTimes,
|
|
700
|
+
...clause,
|
|
701
|
+
}, hasUpdatedAt));
|
|
702
|
+
for (const query of queries)
|
|
703
|
+
collect(query);
|
|
704
|
+
}
|
|
705
|
+
out.sort(compareRawCompletedRows);
|
|
706
|
+
return out;
|
|
707
|
+
}
|
|
708
|
+
export async function readCompletedAssistantRows(params = {}) {
|
|
709
|
+
if (normalizeStorageScope(params).kind === "empty")
|
|
710
|
+
return [];
|
|
711
|
+
const db = openDbOrNull();
|
|
712
|
+
if (!db)
|
|
713
|
+
return [];
|
|
714
|
+
const conn = await db.open();
|
|
715
|
+
try {
|
|
716
|
+
return readCompletedAssistantRowsFrom(conn, params);
|
|
717
|
+
}
|
|
718
|
+
finally {
|
|
719
|
+
conn.close();
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Read project/worktree display metadata: `project.name`, registered
|
|
724
|
+
* `project_directory` directories, and `worktree` directories with
|
|
725
|
+
* `strategy = 'git_worktree'` (R46). Missing tables or columns degrade to an
|
|
726
|
+
* empty index, which P3 reports as the unknown project instead of failing.
|
|
727
|
+
*/
|
|
728
|
+
function readProjectsIndexFrom(conn) {
|
|
729
|
+
const index = {};
|
|
730
|
+
const projectColumns = readTableColumns(conn, "project");
|
|
731
|
+
if (!projectColumns?.has("id"))
|
|
732
|
+
return index;
|
|
733
|
+
const projectProjection = [
|
|
734
|
+
"id",
|
|
735
|
+
projectColumns.has("name") ? "name" : null,
|
|
736
|
+
// `project.worktree` is the canonical root in the shipped schema. It takes
|
|
737
|
+
// precedence over registered/linked directories for name/root display.
|
|
738
|
+
projectColumns.has("worktree") ? "worktree" : null,
|
|
739
|
+
].filter((column) => column !== null);
|
|
740
|
+
const projectRows = conn.all(`SELECT ${projectProjection.join(", ")} FROM "project" ORDER BY id ASC`);
|
|
741
|
+
for (const row of projectRows) {
|
|
742
|
+
if (typeof row.id !== "string" || !row.id)
|
|
743
|
+
continue;
|
|
744
|
+
const name = normalizeString(row.name);
|
|
745
|
+
const canonicalRoot = normalizeString(row.worktree)?.trim();
|
|
746
|
+
index[row.id] = {
|
|
747
|
+
id: row.id,
|
|
748
|
+
name: name?.trim() ? name : undefined,
|
|
749
|
+
directories: canonicalRoot ? [canonicalRoot] : [],
|
|
750
|
+
worktrees: [],
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
const directoryColumns = readTableColumns(conn, "project_directory");
|
|
754
|
+
if (directoryColumns?.has("project_id") && directoryColumns.has("directory")) {
|
|
755
|
+
const rows = conn.all(`SELECT project_id, directory FROM "project_directory" ORDER BY project_id ASC, directory ASC`);
|
|
756
|
+
for (const row of rows) {
|
|
757
|
+
const info = typeof row.project_id === "string" ? index[row.project_id] : undefined;
|
|
758
|
+
if (!info || typeof row.directory !== "string" || !row.directory)
|
|
759
|
+
continue;
|
|
760
|
+
// Canonical root first, then registered directories without duplicates.
|
|
761
|
+
if (info.directories.includes(row.directory))
|
|
762
|
+
continue;
|
|
763
|
+
info.directories.push(row.directory);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
const worktreeColumns = readTableColumns(conn, "worktree");
|
|
767
|
+
if (worktreeColumns?.has("project_id") && worktreeColumns.has("directory")) {
|
|
768
|
+
// Shipped rows use `'git'` for linked worktrees and may also carry the
|
|
769
|
+
// historical `'git_worktree'`; NULL marks canonical roots, not linked ones.
|
|
770
|
+
// Missing strategy column degrades to the previous include-all behavior.
|
|
771
|
+
const strategyFilter = worktreeColumns.has("strategy")
|
|
772
|
+
? ` WHERE strategy IN ('git', 'git_worktree')`
|
|
773
|
+
: "";
|
|
774
|
+
const rows = conn.all(`SELECT project_id, directory FROM "worktree"${strategyFilter} ORDER BY project_id ASC, directory ASC`);
|
|
775
|
+
for (const row of rows) {
|
|
776
|
+
const info = typeof row.project_id === "string" ? index[row.project_id] : undefined;
|
|
777
|
+
if (info && typeof row.directory === "string" && row.directory) {
|
|
778
|
+
info.worktrees.push(row.directory);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
return index;
|
|
783
|
+
}
|
|
784
|
+
export async function readProjectsIndex() {
|
|
785
|
+
const db = openDbOrNull();
|
|
786
|
+
if (!db)
|
|
787
|
+
return {};
|
|
788
|
+
const conn = await db.open();
|
|
789
|
+
try {
|
|
790
|
+
return readProjectsIndexFrom(conn);
|
|
791
|
+
}
|
|
792
|
+
finally {
|
|
793
|
+
conn.close();
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Read compaction message rows as ordered markers (R26, R46): ordered at the
|
|
798
|
+
* source by timestamp, then message id. The assistant readers cannot return
|
|
799
|
+
* these rows (`type = 'compaction'`), and this reader projects physical
|
|
800
|
+
* columns only — it never touches the JSON payload. `sessionID`/`sessionIDs`
|
|
801
|
+
* scope the read; empty id lists return no markers without opening the
|
|
802
|
+
* database. Missing tables degrade to no markers.
|
|
803
|
+
*/
|
|
804
|
+
function readCompactionMarkersFrom(conn, params) {
|
|
805
|
+
const scope = normalizeStorageScope(params);
|
|
806
|
+
if (scope.kind === "empty")
|
|
807
|
+
return [];
|
|
808
|
+
const columns = readTableColumns(conn, "session_message");
|
|
809
|
+
if (!columns?.has("type"))
|
|
810
|
+
return [];
|
|
811
|
+
const markers = [];
|
|
812
|
+
const maxIdsPerQuery = Math.max(1, SQLITE_MAX_MESSAGE_QUERY_ARGS - countDefined([params.sinceMs, params.untilMs]));
|
|
813
|
+
const collect = (query) => {
|
|
814
|
+
for (const row of conn.all(query.sql, query.args)) {
|
|
815
|
+
if (typeof row.id !== "string" || typeof row.session_id !== "string")
|
|
816
|
+
continue;
|
|
817
|
+
if (typeof row.time_created !== "number" || !Number.isFinite(row.time_created))
|
|
818
|
+
continue;
|
|
819
|
+
markers.push({ sessionId: row.session_id, atMs: row.time_created, messageId: row.id });
|
|
820
|
+
}
|
|
821
|
+
};
|
|
822
|
+
const build = (scopeClause) => {
|
|
823
|
+
const where = [`type = 'compaction'`];
|
|
824
|
+
const args = [];
|
|
825
|
+
if (scopeClause?.sessionID !== undefined) {
|
|
826
|
+
where.push(`session_id = ?`);
|
|
827
|
+
args.push(scopeClause.sessionID);
|
|
828
|
+
}
|
|
829
|
+
else if (scopeClause?.sessionIDs !== undefined) {
|
|
830
|
+
where.push(`session_id IN (${scopeClause.sessionIDs.map(() => "?").join(", ")})`);
|
|
831
|
+
args.push(...scopeClause.sessionIDs);
|
|
832
|
+
}
|
|
833
|
+
if (typeof params.sinceMs === "number") {
|
|
834
|
+
where.push(`time_created >= ?`);
|
|
835
|
+
args.push(params.sinceMs);
|
|
836
|
+
}
|
|
837
|
+
if (typeof params.untilMs === "number") {
|
|
838
|
+
where.push(`time_created <= ?`);
|
|
839
|
+
args.push(params.untilMs);
|
|
840
|
+
}
|
|
841
|
+
return {
|
|
842
|
+
sql: `SELECT id, session_id, time_created FROM "session_message"` +
|
|
843
|
+
` WHERE ${where.join(" AND ")} ORDER BY time_created ASC, id ASC`,
|
|
844
|
+
args,
|
|
845
|
+
};
|
|
846
|
+
};
|
|
847
|
+
if (scope.kind === "all") {
|
|
848
|
+
collect(build());
|
|
849
|
+
}
|
|
850
|
+
else {
|
|
851
|
+
const queries = scopedIdQueries(scope.ids, maxIdsPerQuery, (clause) => build(clause));
|
|
852
|
+
for (const query of queries)
|
|
853
|
+
collect(query);
|
|
854
|
+
}
|
|
855
|
+
markers.sort((a, b) => a.atMs - b.atMs || compareStringIds(a.messageId, b.messageId));
|
|
856
|
+
return markers;
|
|
857
|
+
}
|
|
858
|
+
export async function readCompactionMarkers(params = {}) {
|
|
859
|
+
if (normalizeStorageScope(params).kind === "empty")
|
|
860
|
+
return [];
|
|
861
|
+
const db = openDbOrNull();
|
|
862
|
+
if (!db)
|
|
863
|
+
return [];
|
|
864
|
+
const conn = await db.open();
|
|
865
|
+
try {
|
|
866
|
+
return readCompactionMarkersFrom(conn, params);
|
|
867
|
+
}
|
|
868
|
+
finally {
|
|
869
|
+
conn.close();
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
const UNAVAILABLE_REVISION_SNAPSHOT = {
|
|
873
|
+
available: false,
|
|
874
|
+
updatedAtAvailable: false,
|
|
875
|
+
completedAtAvailable: false,
|
|
876
|
+
revisions: [],
|
|
877
|
+
};
|
|
878
|
+
function revisionSnapshot(updatedAtAvailable, completedAtAvailable, revisions) {
|
|
879
|
+
return { available: true, updatedAtAvailable, completedAtAvailable, revisions };
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Read every physical message identity in scope for worker reconciliation.
|
|
883
|
+
*
|
|
884
|
+
* The snapshot deliberately includes unfinished, non-assistant, and compaction
|
|
885
|
+
* rows: diffing message-id sets detects deletions, and per-row `type`,
|
|
886
|
+
* `updatedAtMs`, and `completedAtMs` detect edits, type transitions, and
|
|
887
|
+
* completion/uncompletion. Fetch changed completed assistant rows with
|
|
888
|
+
* `readCompletedAssistantRows({ messageIDs })`. Empty scopes return an empty
|
|
889
|
+
* snapshot without opening the database.
|
|
890
|
+
*/
|
|
891
|
+
function readMessageRevisionsFrom(conn, params) {
|
|
892
|
+
const scope = normalizeStorageScope(params);
|
|
893
|
+
if (scope.kind === "empty")
|
|
894
|
+
return UNAVAILABLE_REVISION_SNAPSHOT;
|
|
895
|
+
const columns = readTableColumns(conn, "session_message");
|
|
896
|
+
if (!columns?.has("id") || !columns.has("session_id")) {
|
|
897
|
+
return UNAVAILABLE_REVISION_SNAPSHOT;
|
|
898
|
+
}
|
|
899
|
+
const updatedAtAvailable = columns.has("time_updated");
|
|
900
|
+
const completedAtAvailable = columns.has("data") && hasJsonExtract(conn);
|
|
901
|
+
const projection = [
|
|
902
|
+
"id",
|
|
903
|
+
"session_id",
|
|
904
|
+
columns.has("type") ? "type" : "NULL AS type",
|
|
905
|
+
columns.has("time_created") ? "time_created" : "NULL AS time_created",
|
|
906
|
+
updatedAtAvailable ? "time_updated" : "NULL AS time_updated",
|
|
907
|
+
completedAtAvailable
|
|
908
|
+
? `${guardedJsonScalar("$.time.completed")} AS completed`
|
|
909
|
+
: "NULL AS completed",
|
|
910
|
+
].join(", ");
|
|
911
|
+
const revisions = [];
|
|
912
|
+
const updatedDelta = updatedAtAvailable && typeof params.updatedSinceMs === "number"
|
|
913
|
+
? params.updatedSinceMs
|
|
914
|
+
: undefined;
|
|
915
|
+
const maxIdsPerQuery = Math.max(1, SQLITE_MAX_MESSAGE_QUERY_ARGS - (updatedDelta === undefined ? 0 : 1));
|
|
916
|
+
const build = (scopeClause) => {
|
|
917
|
+
const where = [];
|
|
918
|
+
const args = [];
|
|
919
|
+
if (scopeClause?.sessionID !== undefined) {
|
|
920
|
+
where.push(`session_id = ?`);
|
|
921
|
+
args.push(scopeClause.sessionID);
|
|
922
|
+
}
|
|
923
|
+
else if (scopeClause?.sessionIDs !== undefined) {
|
|
924
|
+
where.push(`session_id IN (${scopeClause.sessionIDs.map(() => "?").join(", ")})`);
|
|
925
|
+
args.push(...scopeClause.sessionIDs);
|
|
926
|
+
}
|
|
927
|
+
if (scopeClause?.messageIDs !== undefined) {
|
|
928
|
+
where.push(`id IN (${scopeClause.messageIDs.map(() => "?").join(", ")})`);
|
|
929
|
+
args.push(...scopeClause.messageIDs);
|
|
930
|
+
}
|
|
931
|
+
if (updatedDelta !== undefined) {
|
|
932
|
+
// NULL timestamps are replayed rather than silently skipped; a new legacy
|
|
933
|
+
// row must remain visible even when it cannot advance the cursor.
|
|
934
|
+
where.push(`(time_updated IS NULL OR time_updated >= ?)`);
|
|
935
|
+
args.push(updatedDelta);
|
|
936
|
+
}
|
|
937
|
+
return {
|
|
938
|
+
// The reader sorts the collected revisions by message id, and the
|
|
939
|
+
// incremental engine re-sorts a delta by `(updatedAtMs, messageId)`
|
|
940
|
+
// before replay. A SQL ORDER BY would add a second temp B-tree (notably
|
|
941
|
+
// over a full identity projection) without changing the final order.
|
|
942
|
+
sql: `SELECT ${projection} FROM "session_message"` +
|
|
943
|
+
(where.length ? ` WHERE ${where.join(" AND ")}` : ""),
|
|
944
|
+
args,
|
|
945
|
+
};
|
|
946
|
+
};
|
|
947
|
+
const collect = (query) => {
|
|
948
|
+
for (const row of conn.all(query.sql, query.args)) {
|
|
949
|
+
if (typeof row.id !== "string" || typeof row.session_id !== "string")
|
|
950
|
+
continue;
|
|
951
|
+
const createdAt = normalizeNumber(row.time_created);
|
|
952
|
+
const updatedAt = normalizeNumber(row.time_updated);
|
|
953
|
+
const completed = normalizeNumber(row.completed);
|
|
954
|
+
revisions.push({
|
|
955
|
+
messageID: row.id,
|
|
956
|
+
sessionID: row.session_id,
|
|
957
|
+
type: normalizeString(row.type) ?? "unknown",
|
|
958
|
+
createdAtMs: createdAt ?? 0,
|
|
959
|
+
updatedAtMs: updatedAt ?? null,
|
|
960
|
+
completedAtMs: completed !== undefined && completed > 0 ? Math.trunc(completed) : null,
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
};
|
|
964
|
+
if (scope.kind === "all") {
|
|
965
|
+
collect(build());
|
|
966
|
+
}
|
|
967
|
+
else {
|
|
968
|
+
const queries = scopedIdQueries(scope.ids, maxIdsPerQuery, (clause) => build(clause));
|
|
969
|
+
for (const query of queries)
|
|
970
|
+
collect(query);
|
|
971
|
+
}
|
|
972
|
+
revisions.sort((a, b) => compareStringIds(a.messageID, b.messageID));
|
|
973
|
+
return revisionSnapshot(updatedAtAvailable, completedAtAvailable, revisions);
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Read only the source `time_updated` frontier. This is the first-baseline
|
|
977
|
+
* establishment path: it scans the physical column but never projects JSON, so
|
|
978
|
+
* it cannot accidentally turn a cold start into a lifetime completion read.
|
|
979
|
+
*/
|
|
980
|
+
function readMessageRevisionFrontierFrom(conn) {
|
|
981
|
+
const columns = readTableColumns(conn, "session_message");
|
|
982
|
+
if (!columns?.has("id")) {
|
|
983
|
+
return { available: false, updatedAtAvailable: false, maxUpdatedAtMs: null };
|
|
984
|
+
}
|
|
985
|
+
if (!columns.has("time_updated")) {
|
|
986
|
+
return { available: true, updatedAtAvailable: false, maxUpdatedAtMs: null };
|
|
987
|
+
}
|
|
988
|
+
const row = conn.get(`SELECT MAX(time_updated) AS max_updated FROM "session_message"`);
|
|
989
|
+
const maxUpdatedAtMs = normalizeNumber(row?.max_updated);
|
|
990
|
+
return {
|
|
991
|
+
available: true,
|
|
992
|
+
updatedAtAvailable: true,
|
|
993
|
+
maxUpdatedAtMs: maxUpdatedAtMs ?? null,
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
export async function readMessageRevisionFrontier() {
|
|
997
|
+
const db = openDbOrNull();
|
|
998
|
+
if (!db)
|
|
999
|
+
return { available: false, updatedAtAvailable: false, maxUpdatedAtMs: null };
|
|
1000
|
+
const conn = await db.open();
|
|
1001
|
+
try {
|
|
1002
|
+
return readMessageRevisionFrontierFrom(conn);
|
|
1003
|
+
}
|
|
1004
|
+
finally {
|
|
1005
|
+
conn.close();
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
export async function readMessageRevisions(params = {}) {
|
|
1009
|
+
if (normalizeStorageScope(params).kind === "empty")
|
|
1010
|
+
return UNAVAILABLE_REVISION_SNAPSHOT;
|
|
1011
|
+
const db = openDbOrNull();
|
|
1012
|
+
if (!db)
|
|
1013
|
+
return UNAVAILABLE_REVISION_SNAPSHOT;
|
|
1014
|
+
const conn = await db.open();
|
|
1015
|
+
try {
|
|
1016
|
+
return readMessageRevisionsFrom(conn, params);
|
|
1017
|
+
}
|
|
1018
|
+
finally {
|
|
1019
|
+
conn.close();
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
function fileIdentityKey(identity) {
|
|
1023
|
+
if (identity.device !== undefined && identity.inode !== undefined && identity.inode !== "0") {
|
|
1024
|
+
return `d:${identity.device}:${identity.inode}`;
|
|
1025
|
+
}
|
|
1026
|
+
if (identity.birthtimeMs !== undefined) {
|
|
1027
|
+
return `b:${identity.realPath ?? identity.dbPath}:${identity.birthtimeMs}`;
|
|
1028
|
+
}
|
|
1029
|
+
return undefined;
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* Compare a previously accepted good identity with the latest read.
|
|
1033
|
+
*
|
|
1034
|
+
* - `unavailable`: the latest read could not reach a readable file. Keep the
|
|
1035
|
+
* current good state (and the last good identity) untouched.
|
|
1036
|
+
* - `changed`: stable file identity or schema layout changed (reset,
|
|
1037
|
+
* replacement, deletion+recreate). Rebuild from scratch.
|
|
1038
|
+
* - `unknown`: the platform did not expose a stable file key. Callers should
|
|
1039
|
+
* treat this as unchanged to avoid rebuild churn on content writes.
|
|
1040
|
+
* - `same`: content may have changed; reconcile through the revision diff.
|
|
1041
|
+
*/
|
|
1042
|
+
export function compareOpenCodeSourceIdentity(previous, next) {
|
|
1043
|
+
if (next.status !== "ok")
|
|
1044
|
+
return "unavailable";
|
|
1045
|
+
if (previous === undefined || previous.status !== "ok")
|
|
1046
|
+
return "changed";
|
|
1047
|
+
if ((previous.realPath ?? previous.dbPath) !== (next.realPath ?? next.dbPath))
|
|
1048
|
+
return "changed";
|
|
1049
|
+
const previousKey = fileIdentityKey(previous);
|
|
1050
|
+
const nextKey = fileIdentityKey(next);
|
|
1051
|
+
if (previousKey === undefined || nextKey === undefined)
|
|
1052
|
+
return "unknown";
|
|
1053
|
+
if (previousKey !== nextKey)
|
|
1054
|
+
return "changed";
|
|
1055
|
+
if (previous.schemaToken !== undefined &&
|
|
1056
|
+
next.schemaToken !== undefined &&
|
|
1057
|
+
previous.schemaToken !== next.schemaToken) {
|
|
1058
|
+
return "changed";
|
|
1059
|
+
}
|
|
1060
|
+
return "same";
|
|
1061
|
+
}
|
|
1062
|
+
const SCHEMA_TOKEN_TABLES = [
|
|
1063
|
+
"session_v2",
|
|
1064
|
+
"session_message",
|
|
1065
|
+
"project",
|
|
1066
|
+
"project_directory",
|
|
1067
|
+
"worktree",
|
|
1068
|
+
];
|
|
1069
|
+
function readSchemaToken(conn) {
|
|
1070
|
+
// Force a header read: a file that is not a database throws here, so the
|
|
1071
|
+
// identity/snapshot seams report "unreadable" instead of an empty DB.
|
|
1072
|
+
conn.get("SELECT count(*) AS c FROM sqlite_master");
|
|
1073
|
+
const parts = [];
|
|
1074
|
+
for (const table of SCHEMA_TOKEN_TABLES) {
|
|
1075
|
+
const columns = readTableColumns(conn, table);
|
|
1076
|
+
parts.push(columns ? `${table}(${[...columns].sort().join(",")})` : `${table}()`);
|
|
1077
|
+
}
|
|
1078
|
+
return parts.join("|");
|
|
1079
|
+
}
|
|
1080
|
+
function readSourceIdentityStat() {
|
|
1081
|
+
const dbPath = getOpenCodeDbPath();
|
|
1082
|
+
if (dbPath === ":memory:")
|
|
1083
|
+
return { dbPath, exists: false, status: "missing" };
|
|
1084
|
+
let stat;
|
|
1085
|
+
try {
|
|
1086
|
+
stat = statSync(dbPath);
|
|
1087
|
+
}
|
|
1088
|
+
catch {
|
|
1089
|
+
return { dbPath, exists: false, status: "missing" };
|
|
1090
|
+
}
|
|
1091
|
+
if (!stat.isFile()) {
|
|
1092
|
+
return {
|
|
1093
|
+
dbPath,
|
|
1094
|
+
exists: false,
|
|
1095
|
+
status: "unreadable",
|
|
1096
|
+
sizeBytes: stat.size,
|
|
1097
|
+
mtimeMs: stat.mtimeMs,
|
|
1098
|
+
birthtimeMs: stat.birthtimeMs,
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
const identity = {
|
|
1102
|
+
dbPath,
|
|
1103
|
+
exists: true,
|
|
1104
|
+
status: "ok",
|
|
1105
|
+
sizeBytes: stat.size,
|
|
1106
|
+
mtimeMs: stat.mtimeMs,
|
|
1107
|
+
birthtimeMs: stat.birthtimeMs,
|
|
1108
|
+
};
|
|
1109
|
+
try {
|
|
1110
|
+
identity.realPath = realpathSync(dbPath);
|
|
1111
|
+
}
|
|
1112
|
+
catch {
|
|
1113
|
+
// Keep dbPath as the path component of the fallback key.
|
|
1114
|
+
}
|
|
1115
|
+
try {
|
|
1116
|
+
// BigInt stat keeps 64-bit file ids exact across platforms.
|
|
1117
|
+
const big = statSync(dbPath, { bigint: true });
|
|
1118
|
+
identity.device = big.dev.toString();
|
|
1119
|
+
identity.inode = big.ino.toString();
|
|
1120
|
+
identity.birthtimeMs = Number(big.birthtimeMs);
|
|
1121
|
+
}
|
|
1122
|
+
catch {
|
|
1123
|
+
// Fall back to the birthtime from the regular stat.
|
|
1124
|
+
}
|
|
1125
|
+
return identity;
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* Read the local source identity. `status: "ok"` means the file exists and the
|
|
1129
|
+
* schema was readable (including a successfully opened, empty database);
|
|
1130
|
+
* `"missing"` and `"unreadable"` are explicit so callers can preserve the last
|
|
1131
|
+
* good state instead of replacing it with an empty generation.
|
|
1132
|
+
*/
|
|
1133
|
+
export async function readOpenCodeSourceIdentity() {
|
|
1134
|
+
const identity = readSourceIdentityStat();
|
|
1135
|
+
if (identity.status !== "ok")
|
|
1136
|
+
return identity;
|
|
1137
|
+
let conn;
|
|
1138
|
+
try {
|
|
1139
|
+
conn = await openOpenCodeSqliteReadOnly(identity.dbPath);
|
|
1140
|
+
}
|
|
1141
|
+
catch {
|
|
1142
|
+
return { ...identity, status: "unreadable", schemaToken: undefined };
|
|
1143
|
+
}
|
|
1144
|
+
try {
|
|
1145
|
+
return { ...identity, schemaToken: readSchemaToken(conn) };
|
|
1146
|
+
}
|
|
1147
|
+
catch {
|
|
1148
|
+
return { ...identity, status: "unreadable", schemaToken: undefined };
|
|
1149
|
+
}
|
|
1150
|
+
finally {
|
|
1151
|
+
conn.close();
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
function createStorageSnapshot(conn, identity) {
|
|
1155
|
+
return {
|
|
1156
|
+
dbPath: identity.dbPath,
|
|
1157
|
+
identity,
|
|
1158
|
+
readAllSessionsIndex: () => readAllSessionsIndexFrom(conn),
|
|
1159
|
+
readProjectsIndex: () => readProjectsIndexFrom(conn),
|
|
1160
|
+
readCompletedAssistantRows: (params = {}) => readCompletedAssistantRowsFrom(conn, params),
|
|
1161
|
+
readCompactionMarkers: (params = {}) => readCompactionMarkersFrom(conn, params),
|
|
1162
|
+
readMessageRevisions: (params = {}) => readMessageRevisionsFrom(conn, params),
|
|
1163
|
+
readMessageRevisionFrontier: () => readMessageRevisionFrontierFrom(conn),
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* The stable path identity observed before opening must still describe the
|
|
1168
|
+
* path while the transaction runs. A replacement between `stat` and `open`
|
|
1169
|
+
* otherwise pairs one file's identity with another file's rows.
|
|
1170
|
+
*/
|
|
1171
|
+
function sameStablePathIdentity(before, after) {
|
|
1172
|
+
if (before.status !== "ok" || after.status !== "ok")
|
|
1173
|
+
return false;
|
|
1174
|
+
if ((before.realPath ?? before.dbPath) !== (after.realPath ?? after.dbPath))
|
|
1175
|
+
return false;
|
|
1176
|
+
if (before.birthtimeMs !== undefined &&
|
|
1177
|
+
after.birthtimeMs !== undefined &&
|
|
1178
|
+
before.birthtimeMs !== after.birthtimeMs) {
|
|
1179
|
+
return false;
|
|
1180
|
+
}
|
|
1181
|
+
const beforeKey = fileIdentityKey(before);
|
|
1182
|
+
const afterKey = fileIdentityKey(after);
|
|
1183
|
+
if (beforeKey !== undefined && afterKey !== undefined)
|
|
1184
|
+
return beforeKey === afterKey;
|
|
1185
|
+
if (before.birthtimeMs !== undefined && after.birthtimeMs !== undefined) {
|
|
1186
|
+
return before.birthtimeMs === after.birthtimeMs;
|
|
1187
|
+
}
|
|
1188
|
+
// No stable key is exposed on this platform; keep the existing "unknown"
|
|
1189
|
+
// policy rather than inventing a stronger generation guarantee.
|
|
1190
|
+
return true;
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* Run `read` against one transaction-bound snapshot of the OpenCode database.
|
|
1194
|
+
*
|
|
1195
|
+
* The first `SELECT` after `BEGIN` establishes the read snapshot, so changed
|
|
1196
|
+
* payload reads and the membership/revision read inside the callback cannot
|
|
1197
|
+
* observe a concurrently committed generation. The same stable path identity
|
|
1198
|
+
* is rechecked after opening and before commit; a path replacement maps to
|
|
1199
|
+
* `unreadable` so the caller keeps its last good state. Callback errors
|
|
1200
|
+
* propagate after a rollback; only opening/transaction/schema/path-identity
|
|
1201
|
+
* failures map to `missing` or `unreadable`.
|
|
1202
|
+
*/
|
|
1203
|
+
export async function withOpenCodeStorageSnapshot(read) {
|
|
1204
|
+
const statIdentity = readSourceIdentityStat();
|
|
1205
|
+
if (statIdentity.status === "missing")
|
|
1206
|
+
return { status: "missing" };
|
|
1207
|
+
if (statIdentity.status === "unreadable")
|
|
1208
|
+
return { status: "unreadable" };
|
|
1209
|
+
let conn;
|
|
1210
|
+
try {
|
|
1211
|
+
conn = await openOpenCodeSqliteReadOnly(statIdentity.dbPath);
|
|
1212
|
+
}
|
|
1213
|
+
catch {
|
|
1214
|
+
return { status: "unreadable" };
|
|
1215
|
+
}
|
|
1216
|
+
let began = false;
|
|
1217
|
+
try {
|
|
1218
|
+
try {
|
|
1219
|
+
conn.get("BEGIN");
|
|
1220
|
+
began = true;
|
|
1221
|
+
conn.get("SELECT 1");
|
|
1222
|
+
}
|
|
1223
|
+
catch {
|
|
1224
|
+
return { status: "unreadable" };
|
|
1225
|
+
}
|
|
1226
|
+
if (!sameStablePathIdentity(statIdentity, readSourceIdentityStat())) {
|
|
1227
|
+
return { status: "unreadable" };
|
|
1228
|
+
}
|
|
1229
|
+
let identity;
|
|
1230
|
+
try {
|
|
1231
|
+
identity = { ...statIdentity, schemaToken: readSchemaToken(conn) };
|
|
1232
|
+
}
|
|
1233
|
+
catch {
|
|
1234
|
+
return { status: "unreadable" };
|
|
1235
|
+
}
|
|
1236
|
+
const value = await read(createStorageSnapshot(conn, identity));
|
|
1237
|
+
// Do not publish a generation if the path was replaced during the read;
|
|
1238
|
+
// the connection remains the old file while the path already points at a
|
|
1239
|
+
// different generation.
|
|
1240
|
+
if (!sameStablePathIdentity(statIdentity, readSourceIdentityStat())) {
|
|
1241
|
+
return { status: "unreadable" };
|
|
1242
|
+
}
|
|
1243
|
+
if (began) {
|
|
1244
|
+
try {
|
|
1245
|
+
conn.get("COMMIT");
|
|
1246
|
+
}
|
|
1247
|
+
catch {
|
|
1248
|
+
// A read-only transaction commit has no observable effect.
|
|
1249
|
+
}
|
|
1250
|
+
began = false;
|
|
1251
|
+
}
|
|
1252
|
+
return { status: "ok", value };
|
|
1253
|
+
}
|
|
1254
|
+
catch (error) {
|
|
1255
|
+
if (began) {
|
|
1256
|
+
try {
|
|
1257
|
+
conn.get("ROLLBACK");
|
|
1258
|
+
}
|
|
1259
|
+
catch {
|
|
1260
|
+
// The connection is closed in `finally` regardless.
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
throw error;
|
|
1264
|
+
}
|
|
1265
|
+
finally {
|
|
1266
|
+
conn.close();
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
//# sourceMappingURL=opencode-storage.js.map
|