"backend/internal/pkg/vscode:/vscode.git/clone" did not exist on "2a5ef6d3f59e13d6c21e6333bde73a547f8f292c"
Commit 1f05d9f7 authored by QTom's avatar QTom
Browse files

fix(openai): buildCredentials 对齐后端 BuildAccountCredentials 字段



补齐前端 buildCredentials 缺失的 id_token、email、plan_type 字段,
与后端 BuildAccountCredentials 保持一致。修复手动 RT 创建的账号
缺少订阅类型等关键信息的问题。
Co-Authored-By: default avatarClaude Opus 4.6 (1M context) <noreply@anthropic.com>
parent 9f8cffe8
...@@ -13,6 +13,7 @@ export interface OpenAITokenInfo { ...@@ -13,6 +13,7 @@ export interface OpenAITokenInfo {
scope?: string scope?: string
email?: string email?: string
name?: string name?: string
plan_type?: string
// OpenAI specific IDs (extracted from ID Token) // OpenAI specific IDs (extracted from ID Token)
chatgpt_account_id?: string chatgpt_account_id?: string
chatgpt_user_id?: string chatgpt_user_id?: string
...@@ -185,22 +186,23 @@ export function useOpenAIOAuth(options?: UseOpenAIOAuthOptions) { ...@@ -185,22 +186,23 @@ export function useOpenAIOAuth(options?: UseOpenAIOAuthOptions) {
} }
} }
// Build credentials for OpenAI OAuth account // Build credentials for OpenAI OAuth account (aligned with backend BuildAccountCredentials)
const buildCredentials = (tokenInfo: OpenAITokenInfo): Record<string, unknown> => { const buildCredentials = (tokenInfo: OpenAITokenInfo): Record<string, unknown> => {
const creds: Record<string, unknown> = { const creds: Record<string, unknown> = {
access_token: tokenInfo.access_token, access_token: tokenInfo.access_token,
refresh_token: tokenInfo.refresh_token, expires_at: tokenInfo.expires_at
token_type: tokenInfo.token_type,
expires_in: tokenInfo.expires_in,
expires_at: tokenInfo.expires_at,
scope: tokenInfo.scope
} }
if (tokenInfo.client_id) { // 仅在返回了新的 refresh_token 时才写入,防止用空值覆盖已有令牌
creds.client_id = tokenInfo.client_id if (tokenInfo.refresh_token) {
creds.refresh_token = tokenInfo.refresh_token
}
if (tokenInfo.id_token) {
creds.id_token = tokenInfo.id_token
}
if (tokenInfo.email) {
creds.email = tokenInfo.email
} }
// Include OpenAI specific IDs (required for forwarding)
if (tokenInfo.chatgpt_account_id) { if (tokenInfo.chatgpt_account_id) {
creds.chatgpt_account_id = tokenInfo.chatgpt_account_id creds.chatgpt_account_id = tokenInfo.chatgpt_account_id
} }
...@@ -210,6 +212,12 @@ export function useOpenAIOAuth(options?: UseOpenAIOAuthOptions) { ...@@ -210,6 +212,12 @@ export function useOpenAIOAuth(options?: UseOpenAIOAuthOptions) {
if (tokenInfo.organization_id) { if (tokenInfo.organization_id) {
creds.organization_id = tokenInfo.organization_id creds.organization_id = tokenInfo.organization_id
} }
if (tokenInfo.plan_type) {
creds.plan_type = tokenInfo.plan_type
}
if (tokenInfo.client_id) {
creds.client_id = tokenInfo.client_id
}
return creds return creds
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment