8701f43f75
- 删除渲染层传输层:services/clientApi.ts、clientHttp 的 fetchClientHttp 与超时封装整体退场,账户、认证、素材直传、错误上报与游戏分发发布改走 Rust typed command。 - 新增宿主封装:accountHost、editorAssetHost、platformSessionRetry、agentRuntimeErrorDetail 与 features/app-shell/workspacePreferences;渲染层不再读写 access token / refresh cookie,localStorage 只剩测试态旧键迁移 shim。 - 修复 DirectProject 失败文案 v2 映射与「查看详情」按需读取,画布标签面板高度夹紧、框选每帧重算、文档预览入口与场景标题栏 key、资源筛选面板样式。 - 补齐与调整回归:accountHost、agentRuntimeErrorDetail、clientAuthHost、clientHttp、platformSession、platformSessionRetry、resourceFilterPanelStyle、directThreadChatSubscription 等定向用例,并清理测试 harness 中无调用方的残留。
49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
import {
|
|
currentPlatformSessionGeneration,
|
|
requestPlatformSessionRefresh,
|
|
} from './platformSession';
|
|
|
|
/**
|
|
* 服务端明确否认当前身份时的稳定分类。
|
|
*
|
|
* Rust typed command 与 Direct Codex app-server 都会把登录失效投影成
|
|
* `authentication-required`(或 provider 侧的 unauthorized 分类);只有这类错误才值得
|
|
* 续期后重试一次,网络抖动、5xx 和业务拒绝必须原样抛出。
|
|
*/
|
|
export function isPlatformAuthenticationRequiredError(error: unknown) {
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
return (
|
|
message.includes('authentication-required') ||
|
|
message.includes('codex-app-server-error:unauthorized') ||
|
|
/kind=codex-app-server-unauthorized(?=\s|$)/.test(message) ||
|
|
message.includes('登录已失效')
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 平台会话续期后重试一次。
|
|
*
|
|
* 刷新期间账号代际变化(换号、登出)时必须放弃重试:带着旧身份的请求重放会把上一个
|
|
* 账号的副作用打进新账号。只有 `authentication-required` 才触发续期,其它错误直接抛出。
|
|
*/
|
|
export async function withPlatformSessionRefreshRetry<T>(
|
|
operation: () => Promise<T>,
|
|
): Promise<T> {
|
|
const generation = currentPlatformSessionGeneration();
|
|
try {
|
|
return await operation();
|
|
} catch (error) {
|
|
if (!isPlatformAuthenticationRequiredError(error)) throw error;
|
|
if (currentPlatformSessionGeneration() !== generation) throw error;
|
|
const refresh = await requestPlatformSessionRefresh();
|
|
if (refresh.status === 'failed') throw error;
|
|
if (
|
|
refresh.status !== 'refreshed' ||
|
|
currentPlatformSessionGeneration() !== refresh.generation
|
|
) {
|
|
throw new Error('登录账号已变化,原请求已停止');
|
|
}
|
|
return operation();
|
|
}
|
|
}
|