From f1603acba00700bfba808e58184af6b538b3ec0d Mon Sep 17 00:00:00 2001 From: webbrain-one <295484252+webbrain-one@users.noreply.github.com> Date: Tue, 18 Aug 2026 07:01:45 +0300 Subject: [PATCH] Fix opencode-go quota parsing for shifted $R indices The upstream quota response added fields before the usage objects, changing the serialized $R registry indices. Stop hardcoding $R[1]/$R[2]/$R[3] and parse usage values by field association so quota fetching works again. Patch generated by qwen3.8-27b-nvfp4 via local API. --- src/quota/providers/opencode-go.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/quota/providers/opencode-go.ts b/src/quota/providers/opencode-go.ts index 74fa2bf..6e32cf2 100644 --- a/src/quota/providers/opencode-go.ts +++ b/src/quota/providers/opencode-go.ts @@ -56,10 +56,11 @@ export class OpenCodeGoQuotaProvider implements QuotaProvider { const text = await response.text(); // 从响应文本中用正则提取 rolling/weekly/monthly 额度数据 - // 响应格式如: rollingUsage:$R[1]={status:"active",resetInSec:3600,usagePercent:45} - const rollingMatch = text.match(/rollingUsage:\$R\[1\]=\{status:"([^"]+)",resetInSec:(\d+),usagePercent:(\d+)\}/); - const weeklyMatch = text.match(/weeklyUsage:\$R\[2\]=\{status:"([^"]+)",resetInSec:(\d+),usagePercent:(\d+)\}/); - const monthlyMatch = text.match(/monthlyUsage:\$R\[3\]=\{status:"([^"]+)",resetInSec:(\d+),usagePercent:(\d+)\}/); + // 响应格式如: rollingUsage:$R[N]={status:"active",resetInSec:3600,usagePercent:45} + // $R 索引由上游按字段首次出现顺序动态分配,字段增减会导致整体偏移,故用 \d+ 匹配任意索引 + const rollingMatch = text.match(/rollingUsage:\$R\[\d+\]=\{status:"([^"]+)",resetInSec:(\d+),usagePercent:(\d+)\}/); + const weeklyMatch = text.match(/weeklyUsage:\$R\[\d+\]=\{status:"([^"]+)",resetInSec:(\d+),usagePercent:(\d+)\}/); + const monthlyMatch = text.match(/monthlyUsage:\$R\[\d+\]=\{status:"([^"]+)",resetInSec:(\d+),usagePercent:(\d+)\}/); // 分别检查每个字段的解析结果,提供更详细的错误信息 if (!rollingMatch) {