Repository navigation
fix(cli-tools): resolve API key resolution and model mapping bugs #1263
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,6 +163,11 @@ export async function POST(request: Request) { | |
| return NextResponse.json({ error: writeGuard }, { status: 403 }); | ||
| } | ||
|
|
||
| // (#549) Extract keyId BEFORE validation — Zod strips unknown fields! | ||
| // The dashboard sends masked key strings — resolving by ID guarantees | ||
| // we always write the full key value to the config file. | ||
| const keyId = typeof rawBody?.keyId === "string" ? rawBody.keyId.trim() : null; | ||
|
|
||
| const validation = validateBody(cliModelConfigSchema, rawBody); | ||
| if (isValidationFailure(validation)) { | ||
| return NextResponse.json({ error: validation.error }, { status: 400 }); | ||
|
|
@@ -176,10 +181,7 @@ export async function POST(request: Request) { | |
| ); | ||
| } | ||
|
|
||
| // (#549) Resolve real key from DB if keyId was provided. | ||
| // The dashboard sends masked key strings — resolving by ID guarantees | ||
| // we always write the full key value to the config file. | ||
| const keyId = typeof rawBody?.keyId === "string" ? rawBody.keyId.trim() : null; | ||
| // Resolve real key from DB by ID | ||
|
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. The |
||
| if (keyId) { | ||
| try { | ||
| const keyRecord = await getApiKeyById(keyId); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -623,7 +623,10 @@ export async function GET( | |||||
| baseUrl = baseUrl.slice(0, -9); | ||||||
| } | ||||||
|
|
||||||
| const url = `${baseUrl}/models`; | ||||||
| // Use modelsPath from provider node if available, otherwise default to /models | ||||||
| const psd = asRecord(connection.providerSpecificData); | ||||||
| const modelsPath = toNonEmptyString(psd.modelsPath) || "/models"; | ||||||
|
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. The function
Suggested change
|
||||||
| const url = `${baseUrl}${modelsPath}`; | ||||||
| const token = accessToken || apiKey; | ||||||
| const response = await runWithProxyContext(proxy, () => | ||||||
| fetch(url, { | ||||||
|
|
||||||
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.
This masking logic is hardcoded and assumes the token is at least 12 characters long. It is also fragile as it depends on the exact masking format (first 8 + last 4) used by the
/api/keysendpoint. If the backend masking logic changes or if a shorter token is encountered, this comparison will fail to match correctly.