chore: commit pending gateway changes
This commit is contained in:
@@ -10,6 +10,8 @@ import {
|
||||
createCatalogProvider,
|
||||
deleteBaseModel,
|
||||
deleteCatalogProvider,
|
||||
resetAllBaseModels,
|
||||
resetBaseModel,
|
||||
updateBaseModel,
|
||||
updateCatalogProvider,
|
||||
} from '../api';
|
||||
@@ -90,9 +92,44 @@ export function useCatalogOperations(input: {
|
||||
}
|
||||
}
|
||||
|
||||
async function resetBaseModelToDefault(baseModelId: string) {
|
||||
if (!input.token) throw new Error('请先登录后再维护基准模型');
|
||||
input.setCoreState('loading');
|
||||
input.setCoreMessage('');
|
||||
try {
|
||||
const model = await resetBaseModel(input.token, baseModelId);
|
||||
input.setBaseModels((current) => current.map((item) => (item.id === model.id ? model : item)));
|
||||
input.setCoreState('ready');
|
||||
input.setCoreMessage('基准模型已重置为系统默认。');
|
||||
} catch (err) {
|
||||
input.setCoreState('error');
|
||||
input.setCoreMessage(err instanceof Error ? err.message : '基准模型重置失败');
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async function resetAllBaseModelsToDefault() {
|
||||
if (!input.token) throw new Error('请先登录后再维护基准模型');
|
||||
input.setCoreState('loading');
|
||||
input.setCoreMessage('');
|
||||
try {
|
||||
const response = await resetAllBaseModels(input.token);
|
||||
const resetModels = new Map(response.items.map((item) => [item.id, item]));
|
||||
input.setBaseModels((current) => current.map((item) => resetModels.get(item.id) ?? item));
|
||||
input.setCoreState('ready');
|
||||
input.setCoreMessage(`已重置 ${response.items.length} 个系统内置基准模型。`);
|
||||
} catch (err) {
|
||||
input.setCoreState('error');
|
||||
input.setCoreMessage(err instanceof Error ? err.message : '基准模型批量重置失败');
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
removeBaseModel,
|
||||
removeProvider,
|
||||
resetAllBaseModelsToDefault,
|
||||
resetBaseModelToDefault,
|
||||
saveBaseModel,
|
||||
saveProvider,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import type { Dispatch, SetStateAction } from 'react';
|
||||
import type { RuntimePolicySet, RuntimePolicySetUpsertRequest } from '@easyai-ai-gateway/contracts';
|
||||
import { createRuntimePolicySet, deleteRuntimePolicySet, updateRuntimePolicySet } from '../api';
|
||||
import type { LoadState } from '../types';
|
||||
|
||||
export function useRuntimePolicySetOperations(input: {
|
||||
setCoreMessage: Dispatch<SetStateAction<string>>;
|
||||
setCoreState: Dispatch<SetStateAction<LoadState>>;
|
||||
setRuntimePolicySets: Dispatch<SetStateAction<RuntimePolicySet[]>>;
|
||||
token: string;
|
||||
}) {
|
||||
async function saveRuntimePolicySet(payload: RuntimePolicySetUpsertRequest, policySetId?: string) {
|
||||
if (!input.token) throw new Error('请先登录后再维护运行策略');
|
||||
input.setCoreState('loading');
|
||||
input.setCoreMessage('');
|
||||
try {
|
||||
const policySet = policySetId
|
||||
? await updateRuntimePolicySet(input.token, policySetId, payload)
|
||||
: await createRuntimePolicySet(input.token, payload);
|
||||
input.setRuntimePolicySets((current) => [policySet, ...current.filter((item) => item.id !== policySet.id)]);
|
||||
input.setCoreState('ready');
|
||||
input.setCoreMessage(policySetId ? '运行策略已更新。' : '运行策略已新增。');
|
||||
} catch (err) {
|
||||
input.setCoreState('error');
|
||||
input.setCoreMessage(err instanceof Error ? err.message : '运行策略保存失败');
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async function removeRuntimePolicySet(policySetId: string) {
|
||||
if (!input.token) throw new Error('请先登录后再维护运行策略');
|
||||
input.setCoreState('loading');
|
||||
input.setCoreMessage('');
|
||||
try {
|
||||
await deleteRuntimePolicySet(input.token, policySetId);
|
||||
input.setRuntimePolicySets((current) => current.filter((item) => item.id !== policySetId));
|
||||
input.setCoreState('ready');
|
||||
input.setCoreMessage('运行策略已删除。');
|
||||
} catch (err) {
|
||||
input.setCoreState('error');
|
||||
input.setCoreMessage(err instanceof Error ? err.message : '运行策略删除失败');
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
return { removeRuntimePolicySet, saveRuntimePolicySet };
|
||||
}
|
||||
Reference in New Issue
Block a user