fix(server): read OpenCode Go limits key from OpenCode 2's credential database #16605
main fromrefs/pull/16605/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/provider/openCodeUsageLimits.ts lines 45 to 45OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -29,3 +30,16 @@2930 usage: Schema.Struct({ rolling: UsageWindow, weekly: UsageWindow, monthly: UsageWindow }),3031 });313233+/**34+ * OpenCode 2 stores credentials in its SQLite database instead of auth.json. A35+ * Console login is a separate OAuth row under another integration, so only a36+ * Go API key row is usable here.37+ */38+const readStoredGoApiKey = (databasePath: string) =>39+ Effect.try(() => {40+ const database = new NodeSqlite.DatabaseSync(databasePath, { readOnly: true });41+ try {42+ database.exec("PRAGMA busy_timeout = 100");43+ const row = database44+ .prepare(45+ "SELECT value FROM credential WHERE integration_id = 'opencode-go' ORDER BY active DESC, time_updated DESC LIMIT 1",
coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
apps/server/src/provider/openCodeUsageLimits.ts line 45OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -29,3 +30,16 @@2930 usage: Schema.Struct({ rolling: UsageWindow, weekly: UsageWindow, monthly: UsageWindow }),3031 });313233+/**34+ * OpenCode 2 stores credentials in its SQLite database instead of auth.json. A35+ * Console login is a separate OAuth row under another integration, so only a36+ * Go API key row is usable here.37+ */38+const readStoredGoApiKey = (databasePath: string) =>39+ Effect.try(() => {40+ const database = new NodeSqlite.DatabaseSync(databasePath, { readOnly: true });41+ try {42+ database.exec("PRAGMA busy_timeout = 100");43+ const row = database44+ .prepare(45+ "SELECT value FROM credential WHERE integration_id = 'opencode-go' ORDER BY active DESC, time_updated DESC LIMIT 1",apps/server/src/provider/openCodeUsageLimits.ts lines 48 to 50OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -29,3 +30,21 @@2930 usage: Schema.Struct({ rolling: UsageWindow, weekly: UsageWindow, monthly: UsageWindow }),3031 });313233+/**34+ * OpenCode 2 stores credentials in its SQLite database instead of auth.json. A35+ * Console login is a separate OAuth row under another integration, so only a36+ * Go API key row is usable here.37+ */38+const readStoredGoApiKey = (databasePath: string) =>39+ Effect.try(() => {40+ const database = new NodeSqlite.DatabaseSync(databasePath, { readOnly: true });41+ try {42+ database.exec("PRAGMA busy_timeout = 100");43+ const row = database44+ .prepare(45+ "SELECT value FROM credential WHERE integration_id = 'opencode-go' ORDER BY active DESC, time_updated DESC LIMIT 1",46+ )47+ .get();48+ return typeof row?.value === "string"49+ ? decodeApiAuth(JSON.parse(row.value) as unknown)50+ : Option.none();coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
apps/server/src/provider/openCodeUsageLimits.ts line 51OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -29,3 +36,16 @@2936 usage: Schema.Struct({ rolling: UsageWindow, weekly: UsageWindow, monthly: UsageWindow }),3037 });313839+/**40+ * OpenCode 2 stores credentials in its SQLite database instead of auth.json. A41+ * Console login is a separate OAuth row under another integration, so only a42+ * Go API key row is usable here.43+ */44+const readStoredGoApiKey = (databasePath: string) =>45+ Effect.try(() => {46+ const database = new NodeSqlite.DatabaseSync(databasePath, { readOnly: true });47+ try {48+ database.exec("PRAGMA busy_timeout = 100");49+ const row = database50+ .prepare(51+ "SELECT value FROM credential WHERE integration_id = 'opencode-go' AND active = 1 ORDER BY time_updated DESC LIMIT 1",coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge added labelsmacroscope-review
juliusmarminge assignedjuliusmarminge
juliusmarminge added labelstakeover
juliusmarminge added labelspr:in-progress
juliusmarminge added labelspr:needs-julius
juliusmarminge removed labelspr:in-progress
juliusmarminge closed this
juliusmarminge removed labelspr:needs-julius
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed