refactor(*): 稳定期治理 - 收敛核心架构、错误语义并修复跨项目数据竞态
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { getFeatureAvailability, type AuthSessionPayload } from "@/services/api/auth";
|
||||
import { getModelCatalog, listLogicalModels, type CapabilitySpec, type ModelCatalogResponse, type OptionConstraint, type PublicChannelCatalog, type PublicLogicalModel } from "@/services/api/logical-models";
|
||||
import { getModelCatalog, type CapabilitySpec, type ModelCatalogResponse, type OptionConstraint, type PublicChannelCatalog, type PublicLogicalModel } from "@/services/api/logical-models";
|
||||
import { localForageStorage } from "@/lib/localforage-storage";
|
||||
import { appQueryClient } from "@/lib/query-client";
|
||||
import { scopedLocalStorage, setActiveUserScope } from "@/lib/user-scope";
|
||||
@@ -61,17 +61,10 @@ export async function applyUserSession(payload: AuthSessionPayload) {
|
||||
if (!persistedCreationPreferences) useCreationPreferencesStore.setState({ preferences: {} });
|
||||
if (!persistedConfig) {
|
||||
// 只有首次配置缺失时才生成能力推荐;已有配置中的空数组代表用户明确清空。
|
||||
// 使用统一模型目录接口
|
||||
const catalog = await getModelCatalog();
|
||||
let channels: ModelChannel[] = [];
|
||||
if (catalog.source === "frontend" && catalog.models) {
|
||||
channels = managedModelChannels(catalog.models);
|
||||
} else if (catalog.source === "system" && catalog.channels) {
|
||||
channels = systemChannelModelChannels(catalog.channels);
|
||||
}
|
||||
const initialSystemConfig = {
|
||||
...defaultConfig,
|
||||
channels,
|
||||
channels: modelCatalogChannels(catalog),
|
||||
imageModels: undefined,
|
||||
videoModels: undefined,
|
||||
textModels: undefined,
|
||||
@@ -79,13 +72,8 @@ export async function applyUserSession(payload: AuthSessionPayload) {
|
||||
};
|
||||
useConfigStore.getState().replaceConfig(normalizeConfigSnapshot({ config: initialSystemConfig }).config);
|
||||
} else {
|
||||
// 已有配置时也需要合并最新的系统渠道
|
||||
const catalog = await getModelCatalog();
|
||||
if (catalog.source === "frontend" && catalog.models) {
|
||||
useConfigStore.getState().mergeSystemChannels(managedModelChannels(catalog.models));
|
||||
} else if (catalog.source === "system" && catalog.channels) {
|
||||
useConfigStore.getState().mergeSystemChannels(systemChannelModelChannels(catalog.channels));
|
||||
}
|
||||
useConfigStore.getState().mergeSystemChannels(modelCatalogChannels(catalog));
|
||||
}
|
||||
installRemoteUserDataAutoSync();
|
||||
if (payload.user?.id) {
|
||||
@@ -97,16 +85,21 @@ export async function applyUserSession(payload: AuthSessionPayload) {
|
||||
}
|
||||
|
||||
export async function refreshSystemChannels() {
|
||||
// 使用统一模型目录接口,根据 frontendModelsEnabled 自动返回前台模型或系统渠道模型
|
||||
const catalog = await getModelCatalog();
|
||||
useConfigStore.getState().mergeSystemChannels(modelCatalogChannels(catalog));
|
||||
}
|
||||
|
||||
if (catalog.source === "frontend" && catalog.models) {
|
||||
// 前台模型模式
|
||||
useConfigStore.getState().mergeSystemChannels(managedModelChannels(catalog.models));
|
||||
} else if (catalog.source === "system" && catalog.channels) {
|
||||
// 系统渠道模式
|
||||
useConfigStore.getState().mergeSystemChannels(systemChannelModelChannels(catalog.channels));
|
||||
// 模型目录来源决定数据形状;这里统一做运行时收口,避免畸形响应被当成“空目录”写入用户配置。
|
||||
function modelCatalogChannels(catalog: ModelCatalogResponse): ModelChannel[] {
|
||||
if (catalog.source === "frontend") {
|
||||
if (!Array.isArray(catalog.models)) throw new Error("模型目录响应缺少前台模型列表");
|
||||
return managedModelChannels(catalog.models);
|
||||
}
|
||||
if (catalog.source === "system") {
|
||||
if (!Array.isArray(catalog.channels)) throw new Error("模型目录响应缺少系统渠道列表");
|
||||
return systemChannelModelChannels(catalog.channels);
|
||||
}
|
||||
throw new Error("模型目录响应来源无效");
|
||||
}
|
||||
|
||||
function managedModelChannels(models: PublicLogicalModel[]) {
|
||||
|
||||
Reference in New Issue
Block a user