| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <!-- 组件:AgentView;功能:五节点统计、配置版本与真实连接测试;props:无;emit:无。管理员改配置,审计员可查看与测试。 -->
- <script setup lang="ts">
- import { onMounted, ref } from "vue";
- import { ElMessage } from "element-plus";
- import { Cpu } from "@element-plus/icons-vue";
- import { api, jsonObject, pretty, type Row } from "../api";
- import { useSession } from "../store";
- import PageHeading from "../components/PageHeading.vue";
- import JsonEvidence from "../components/JsonEvidence.vue";
- const session = useSession();
- const rows = ref<Row[]>([]),
- busy = ref(false),
- dialog = ref(false),
- saving = ref(false),
- current = ref<Row>({}),
- config = ref("{}"),
- enabled = ref(true),
- history = ref<Row[]>([]),
- testing = ref("");
- async function load() {
- busy.value = true;
- try {
- rows.value = await api<Row[]>("/agents");
- } catch (error) {
- ElMessage.error((error as Error).message);
- } finally {
- busy.value = false;
- }
- }
- async function edit(row: Row) {
- try {
- const data = await api(`/agents/${row.node_name}`);
- current.value = data.current;
- history.value = data.history;
- config.value = pretty(data.current.config);
- enabled.value = data.current.enabled;
- dialog.value = true;
- } catch (error) {
- ElMessage.error((error as Error).message);
- }
- }
- async function save() {
- saving.value = true;
- try {
- await api(`/agents/${current.value.node_name}`, "PATCH", {
- expected_version: current.value.version,
- enabled: enabled.value,
- config: jsonObject(config.value),
- });
- dialog.value = false;
- await load();
- ElMessage.success("已生成新配置版本,历史审核继续使用原版本");
- } catch (error) {
- ElMessage.error((error as Error).message);
- } finally {
- saving.value = false;
- }
- }
- async function test(row: Row) {
- testing.value = row.node_name;
- try {
- const data = await api(`/agents/${row.node_name}/test`, "POST");
- data.status === "success"
- ? ElMessage.success(data.message)
- : ElMessage.warning(data.message);
- } catch (error) {
- ElMessage.error((error as Error).message);
- } finally {
- testing.value = "";
- }
- }
- onMounted(load);
- </script>
- <template>
- <PageHeading
- title="Agent 管理"
- description="四个自动审核节点与一个人工反馈节点,执行数据来自真实审核记录。"
- ><el-button @click="load">刷新</el-button></PageHeading
- ><el-alert
- type="info"
- :closable="false"
- title="节点超时、并发、重试和阈值在此配置;模型地址与密钥集中放在后端 .env,不能由浏览器任意指定。"
- />
- <div class="agent-grid" v-loading="busy">
- <section v-for="row in rows" :key="row.node_name" class="card agent-card">
- <div class="agent-top">
- <span class="agent-icon"
- ><el-icon><Cpu /></el-icon
- ></span>
- <div>
- <h2>{{ row.name }}</h2>
- <span class="muted mono"
- >{{ row.node_name }} · v{{ row.version }}</span
- >
- </div>
- </div>
- <el-tag :type="row.enabled ? 'success' : 'info'" round>{{
- row.enabled ? "已启用" : "已停用可选能力"
- }}</el-tag>
- <div class="agent-stats">
- <span class="muted"
- >执行次数<strong>{{ row.executions }}</strong></span
- ><span class="muted"
- >降级次数<strong>{{ row.degraded_count }}</strong></span
- ><span class="muted"
- >平均耗时<strong style="font-size: 18px">{{
- row.average_ms == null ? "—" : `${row.average_ms} ms`
- }}</strong></span
- >
- </div>
- <JsonEvidence :value="row.config" title="运行参数" />
- <div class="agent-actions">
- <el-button @click="edit(row)">{{
- session.level >= 4 ? "编辑配置" : "查看版本"
- }}</el-button
- ><el-button
- plain
- type="primary"
- :loading="testing === row.node_name"
- @click="test(row)"
- >测试节点</el-button
- >
- </div>
- </section>
- </div>
- <el-dialog
- v-model="dialog"
- :title="`${current.name || ''} · 配置 v${current.version || ''}`"
- width="min(670px,94vw)"
- ><el-form label-position="top"
- ><el-form-item label="启用可选能力"
- ><el-switch
- v-model="enabled"
- :disabled="session.level < 4" /></el-form-item
- ><el-form-item label="节点参数(JSON 白名单)"
- ><el-input
- v-model="config"
- class="json-editor"
- type="textarea"
- :rows="12"
- :readonly="session.level < 4" /></el-form-item></el-form
- ><JsonEvidence :value="history" title="历史不可变配置版本" /><template
- #footer
- ><el-button @click="dialog = false">关闭</el-button
- ><el-button
- v-if="session.level >= 4"
- type="primary"
- :loading="saving"
- @click="save"
- >发布新版本</el-button
- ></template
- ></el-dialog
- >
- </template>
|