feat: add runner failover policies and traces

This commit is contained in:
2026-05-12 02:16:42 +08:00
parent be31923e74
commit 05632172d0
26 changed files with 2033 additions and 140 deletions
@@ -1,14 +1,31 @@
import type { Dispatch, SetStateAction } from 'react';
import type { RuntimePolicySet, RuntimePolicySetUpsertRequest } from '@easyai-ai-gateway/contracts';
import { createRuntimePolicySet, deleteRuntimePolicySet, updateRuntimePolicySet } from '../api';
import type { GatewayRunnerPolicy, GatewayRunnerPolicyUpsertRequest, RuntimePolicySet, RuntimePolicySetUpsertRequest } from '@easyai-ai-gateway/contracts';
import { createRuntimePolicySet, deleteRuntimePolicySet, updateRunnerPolicy, updateRuntimePolicySet } from '../api';
import type { LoadState } from '../types';
export function useRuntimePolicySetOperations(input: {
setCoreMessage: Dispatch<SetStateAction<string>>;
setCoreState: Dispatch<SetStateAction<LoadState>>;
setRunnerPolicy: Dispatch<SetStateAction<GatewayRunnerPolicy | null>>;
setRuntimePolicySets: Dispatch<SetStateAction<RuntimePolicySet[]>>;
token: string;
}) {
async function saveRunnerPolicy(payload: GatewayRunnerPolicyUpsertRequest) {
if (!input.token) throw new Error('请先登录后再维护调度策略');
input.setCoreState('loading');
input.setCoreMessage('');
try {
const policy = await updateRunnerPolicy(input.token, payload);
input.setRunnerPolicy(policy);
input.setCoreState('ready');
input.setCoreMessage('全局调度策略已更新。');
} catch (err) {
input.setCoreState('error');
input.setCoreMessage(err instanceof Error ? err.message : '全局调度策略保存失败');
throw err;
}
}
async function saveRuntimePolicySet(payload: RuntimePolicySetUpsertRequest, policySetId?: string) {
if (!input.token) throw new Error('请先登录后再维护运行策略');
input.setCoreState('loading');
@@ -43,5 +60,5 @@ export function useRuntimePolicySetOperations(input: {
}
}
return { removeRuntimePolicySet, saveRuntimePolicySet };
return { removeRuntimePolicySet, saveRunnerPolicy, saveRuntimePolicySet };
}