Repository navigation
Feat/features batch v3.8.0 #2431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3355920
feat(installer): detect Termux and skip incompatible setup steps (#1764)
diegosouzapw 6756006
feat(errors): expose sanitized upstream error details in client respo…
diegosouzapw e57cf43
feat(kiro): isolate OAuth sessions per connection for multi-account s…
diegosouzapw 8b8bb3d
feat(cli): add providers rotate command for upstream key rotation (#1…
diegosouzapw e7eb777
feat(providers): add t3.chat web provider skeleton (#1909)
diegosouzapw 3b9cb7d
feat(zed): complete Docker integration with manual import endpoint + …
diegosouzapw 4bc6b33
fix(combo): blend output token cost into auto-combo scoring (#1812)
diegosouzapw bfe90c0
feat(combo): filter auto-combo candidates by context window (#1808)
diegosouzapw 5040c8b
feat(combo): track provider-level exhaustion across combo targets (#1…
diegosouzapw db674c8
chore(tests): move #1731 integration test to tests/integration/
diegosouzapw 61683e0
chore(privacy): untrack implement-features workflow/skill/command (ke…
diegosouzapw b9af455
docs: fix audit gaps — CHANGELOG entry for #2306 + AUTO-COMBO blended…
diegosouzapw a9cef6d
chore(merge): resolve combo.ts conflict — preserve exhaustedProviders…
diegosouzapw b50dfb9
fix: restore v3.8.0 state for regressive files — prevent auth/gamific…
diegosouzapw 460e4e7
chore: merge release/v3.8.0 into feat/features-batch — resolve all co…
diegosouzapw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { apiFetch } from "../api.mjs"; | ||
| import { apiFetch, isServerUp } from "../api.mjs"; | ||
| import { emit } from "../output.mjs"; | ||
| import { printHeading } from "../io.mjs"; | ||
| import { getAvailableProviderCategories, loadAvailableProviders } from "../provider-catalog.mjs"; | ||
|
|
@@ -7,8 +7,10 @@ import { | |
| findProviderConnection, | ||
| getProviderApiKey, | ||
| listProviderConnections, | ||
| updateProviderApiKey, | ||
| updateProviderTestResult, | ||
| } from "../provider-store.mjs"; | ||
| import { encryptCredential } from "../encryption.mjs"; | ||
| import { openOmniRouteDb } from "../sqlite.mjs"; | ||
| import { t } from "../i18n.mjs"; | ||
|
|
||
|
|
@@ -301,6 +303,179 @@ export async function runValidateCommand(opts = {}) { | |
| } | ||
| } | ||
|
|
||
| export async function runProvidersRotateCommand(selector, opts = {}) { | ||
| if (!selector) { | ||
| console.error("Provider connection id or name is required."); | ||
| return 2; | ||
| } | ||
|
|
||
| // --- Resolve connection --- | ||
| const { db } = await openOmniRouteDb(); | ||
| let connection; | ||
| try { | ||
| connection = findProviderConnection(db, selector); | ||
| } finally { | ||
| db.close(); | ||
| } | ||
|
|
||
| if (!connection) { | ||
| console.error(`Provider connection not found: ${selector}`); | ||
| return 2; | ||
| } | ||
|
|
||
| // --- OAuth short-circuit --- | ||
| if (opts.oauth || connection.authType !== "apikey") { | ||
| console.log(t("providers.rotate.oauthHint", { provider: connection.provider })); | ||
| return 0; | ||
| } | ||
|
|
||
| // --- Source new key --- | ||
| let newKey; | ||
| if (opts.fromEnv) { | ||
| newKey = process.env[opts.fromEnv]; | ||
| if (!newKey) { | ||
| console.error(t("providers.rotate.envVarEmpty", { var: opts.fromEnv })); | ||
| return 2; | ||
| } | ||
| } else if (opts.newKey) { | ||
| newKey = opts.newKey; | ||
| } else { | ||
| // Interactive prompt (echo-off not strictly needed for a key value, but best practice) | ||
| const readline = await import("node:readline"); | ||
| const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); | ||
| newKey = await new Promise((resolve) => | ||
| rl.question(`New API key for ${connection.name}: `, (a) => { rl.close(); resolve(a.trim()); }) | ||
| ); | ||
| if (!newKey) { | ||
| console.error("No key provided."); | ||
| return 2; | ||
| } | ||
| } | ||
|
|
||
| // --- Dry-run --- | ||
| if (opts.dryRun) { | ||
| console.log(t("providers.rotate.dryRunResult", { name: connection.name, id: connection.id.slice(0, 8) })); | ||
| return 0; | ||
| } | ||
|
|
||
| // --- Confirm --- | ||
| if (!opts.yes) { | ||
| const readline = await import("node:readline"); | ||
| const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); | ||
| const answer = await new Promise((resolve) => | ||
| rl.question(t("providers.rotate.confirmPrompt", { name: connection.name, id: connection.id.slice(0, 8) }), resolve) | ||
| ); | ||
| rl.close(); | ||
| if (!/^y(es|s)?$/i.test(answer)) { | ||
| console.log(t("common.cancelled")); | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| // --- Write --- | ||
| const serverUp = await isServerUp(); | ||
| if (serverUp) { | ||
| try { | ||
| const res = await apiFetch(`/api/providers/${encodeURIComponent(connection.id)}`, { | ||
| method: "PATCH", | ||
| body: { apiKey: newKey, testStatus: "unknown", lastError: null, rateLimitedUntil: null, backoffLevel: 0 }, | ||
| retry: false, | ||
| acceptNotOk: true, | ||
| }); | ||
| if (!res.ok) { | ||
| console.error(t("common.error", { message: `HTTP ${res.status}` })); | ||
| return 1; | ||
| } | ||
| } catch { | ||
| // Fall through to direct DB write | ||
| const { db: db2 } = await openOmniRouteDb(); | ||
| try { | ||
| updateProviderApiKey(db2, connection.id, encryptCredential(newKey)); | ||
| } finally { | ||
| db2.close(); | ||
| } | ||
| } | ||
| } else { | ||
| const { db: db2 } = await openOmniRouteDb(); | ||
| try { | ||
| updateProviderApiKey(db2, connection.id, encryptCredential(newKey)); | ||
| } finally { | ||
| db2.close(); | ||
| } | ||
| } | ||
|
|
||
| console.log(t("providers.rotate.success", { name: connection.name, id: connection.id.slice(0, 8) })); | ||
|
|
||
| // --- Post-rotation test --- | ||
| if (!opts.skipTest) { | ||
| const { db: db3 } = await openOmniRouteDb(); | ||
| try { | ||
| const fresh = findProviderConnection(db3, connection.id); | ||
| if (fresh) { | ||
| const result = await runProviderTest(db3, fresh); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if (result.valid) { | ||
| console.log(t("providers.rotate.testPassed")); | ||
| } else { | ||
| console.error(t("providers.rotate.testFailed", { error: result.error })); | ||
| } | ||
| } | ||
| } finally { | ||
| db3.close(); | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| export async function runProvidersStatusCommand(opts = {}) { | ||
| const serverUp = await isServerUp(); | ||
| if (!serverUp) { | ||
| console.error(t("providers.status.requiresServer")); | ||
| return 3; | ||
| } | ||
|
|
||
| const res = await apiFetch("/api/providers/expiration", { acceptNotOk: true, retry: false }); | ||
| if (!res.ok) { | ||
| console.error(t("common.error", { message: `HTTP ${res.status}` })); | ||
| return 1; | ||
| } | ||
|
|
||
| const data = await res.json(); | ||
| const list = data.list || []; | ||
|
|
||
| // Optional provider filter | ||
| const filter = opts.provider ? String(opts.provider).toLowerCase() : null; | ||
| const rows = filter ? list.filter((item) => item.provider?.toLowerCase().includes(filter)) : list; | ||
|
|
||
| if (opts.json || opts.output === "json") { | ||
| console.log(JSON.stringify({ count: rows.length, connections: rows }, null, 2)); | ||
| return 0; | ||
| } | ||
|
|
||
| if (rows.length === 0) { | ||
| console.log(t("providers.status.noData")); | ||
| return 0; | ||
| } | ||
|
|
||
| console.log(t("providers.status.header")); | ||
| for (const item of rows) { | ||
| const shortId = (item.connectionId || item.id || "").slice(0, 8); | ||
| const expiry = item.expiresAt ? new Date(item.expiresAt).toLocaleDateString() : "-"; | ||
| const expiryStatus = item.status || "unknown"; | ||
| const testStatus = item.testStatus || "unknown"; | ||
| const cooldown = item.rateLimitedUntil ? new Date(item.rateLimitedUntil).toLocaleString() : "-"; | ||
| const expiryColor = statusColor(expiryStatus); | ||
| const testColor = statusColor(testStatus); | ||
|
Comment on lines
+486
to
+487
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| console.log( | ||
| `${shortId.padEnd(10)} ${String(item.provider || "").padEnd(14)} ${String(item.name || "").padEnd(24)} ` + | ||
| `${expiry.padEnd(12)} ${expiryColor}${expiryStatus.padEnd(8)}\x1b[0m ` + | ||
| `${testColor}${testStatus.padEnd(12)}\x1b[0m ${cooldown}` | ||
| ); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| export function registerProviders(program) { | ||
| const providers = program.command("providers").description(t("providers.title")); | ||
|
|
||
|
|
@@ -357,6 +532,32 @@ export function registerProviders(program) { | |
| if (exitCode !== 0) process.exit(exitCode); | ||
| }); | ||
|
|
||
| providers | ||
| .command("rotate <idOrName>") | ||
| .description(t("providers.rotate.description")) | ||
| .option("--new-key <key>", t("providers.rotate.newKeyOpt")) | ||
| .option("--from-env <VAR>", t("providers.rotate.fromEnvOpt")) | ||
| .option("--oauth", t("providers.rotate.oauthOpt")) | ||
| .option("--yes", t("common.yesOpt")) | ||
| .option("--skip-test", t("providers.rotate.skipTestOpt")) | ||
| .option("--dry-run", t("providers.rotate.dryRunOpt")) | ||
| .action(async (idOrName, opts, cmd) => { | ||
| const globalOpts = cmd.parent.optsWithGlobals(); | ||
| const exitCode = await runProvidersRotateCommand(idOrName, { ...opts, output: globalOpts.output }); | ||
| if (exitCode !== 0) process.exit(exitCode); | ||
| }); | ||
|
|
||
| providers | ||
| .command("status") | ||
| .description(t("providers.status.description")) | ||
| .option("--provider <name>", t("providers.status.providerOpt")) | ||
| .option("--json", "Print machine-readable JSON") | ||
| .action(async (opts, cmd) => { | ||
| const globalOpts = cmd.parent.optsWithGlobals(); | ||
| const exitCode = await runProvidersStatusCommand({ ...opts, output: globalOpts.output }); | ||
| if (exitCode !== 0) process.exit(exitCode); | ||
| }); | ||
|
|
||
| extendProvidersMetrics(providers); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for updating the provider API key in the database is duplicated across the
try-catchandelseblocks. Additionally, the database is opened and closed multiple times (openOmniRouteDb). Consider refactoring the database write into a single block and keeping the connection open if multiple operations are needed to improve efficiency.