Remove pre-1.0 audit and protected request scaffolding
This commit is contained in:
@@ -2,8 +2,8 @@ import { History, ListChecks, Send, Sparkles, Terminal, Trash2, X } from "lucide
|
||||
import { type FormEvent, type KeyboardEvent as ReactKeyboardEvent, type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
import { platformApiClient } from "../api/client";
|
||||
import type { GameClientBridgeCommandResponse, LogEntryBody, LogStreamResponse } from "../api/types";
|
||||
import { scumManagementRCONCommandRequest } from "../schemas/scumManagementRcon";
|
||||
import type { JobResponse, LogEntryBody, LogStreamResponse } from "../api/types";
|
||||
import { scumSourceRCONCommandRequest } from "../schemas/scumManagementRcon";
|
||||
import { cx } from "../utils/classes";
|
||||
import { mergeLogStreams, parseLogSessionEvent, parseLogStreamEvent, parseServerLogEvent, streamFromServerLogEvent } from "../utils/logEvents";
|
||||
import { EmptyState, ResultBadge } from "./StateViews";
|
||||
@@ -13,8 +13,8 @@ type HistoryLineState = { status: "idle" } | LoadState<TerminalLine[]>;
|
||||
type TerminalLine = { id: string; tone: "input" | "info" | "success" | "warn" | "error"; text: string; at: string; sortKey: number; streamKey?: string; level?: string; seq?: number };
|
||||
type TerminalQuickCommand = { label: string; command: string; hint: string };
|
||||
|
||||
const terminalBridgeResultPollMs = 1000;
|
||||
const terminalBridgeResultPollAttempts = 30;
|
||||
const terminalJobResultPollMs = 1000;
|
||||
const terminalJobResultPollAttempts = 30;
|
||||
const terminalInitialHistoryWindow = 500;
|
||||
const maxTerminalLines = 10000;
|
||||
const terminalQuickCommandCatalog: Record<string, TerminalQuickCommand[]> = {
|
||||
@@ -285,17 +285,17 @@ export function ServerManagementTerminalDrawer({ open, serverId, serverName, plu
|
||||
setResult({ status: "pending", label: "正在提交命令" });
|
||||
appendLines([terminalSystemLine("input", `> ${submitted}`, "COMMAND")]);
|
||||
try {
|
||||
const response = await platformApiClient.queueGameClientBridgeCommand(serverId, scumManagementRCONCommandRequest(serverId, submitted));
|
||||
const label = bridgeCommandDispatchLabel(response.state, response.id);
|
||||
const response = await platformApiClient.dispatchSourceRCONCommand(serverId, scumSourceRCONCommandRequest(serverId, submitted));
|
||||
const label = rconJobDispatchLabel(response.status, response.jobId);
|
||||
setResult({ status: "pending", label: `${label} · 等待 Run 返回结果` });
|
||||
appendLines([terminalSystemLine("success", `${label} · protected RCON`, "PLATFORM", `ok-${response.id}`)]);
|
||||
const finalCommand = await waitForBridgeCommandTerminal(response.id);
|
||||
if (finalCommand) {
|
||||
const outcome = terminalLineFromBridgeCommand(finalCommand);
|
||||
appendLines([terminalSystemLine("success", `${label} · Source RCON`, "PLATFORM", `ok-${response.jobId}`)]);
|
||||
const finalJob = await waitForRCONJobTerminal(response.jobId);
|
||||
if (finalJob) {
|
||||
const outcome = terminalLineFromJob(finalJob);
|
||||
setResult({ status: outcome.tone === "success" ? "succeeded" : "failed", label: outcome.text });
|
||||
appendLines([outcome]);
|
||||
} else {
|
||||
const timeoutLine = terminalSystemLine("warn", `桥接命令 ${response.id} 已排队,但尚未返回终态;继续观察实时日志。`, "PLATFORM", `pending-${response.id}`);
|
||||
const timeoutLine = terminalSystemLine("warn", `RCON 任务 ${response.jobId} 已排队,但尚未返回终态;继续观察实时日志。`, "PLATFORM", `pending-${response.jobId}`);
|
||||
setResult({ status: "pending", label: "等待 Run 返回结果" });
|
||||
appendLines([timeoutLine]);
|
||||
}
|
||||
@@ -308,11 +308,11 @@ export function ServerManagementTerminalDrawer({ open, serverId, serverName, plu
|
||||
}
|
||||
}
|
||||
|
||||
async function waitForBridgeCommandTerminal(commandId: string): Promise<GameClientBridgeCommandResponse | null> {
|
||||
for (let attempt = 0; attempt < terminalBridgeResultPollAttempts; attempt += 1) {
|
||||
const current = await platformApiClient.getGameClientBridgeCommand(serverId, commandId);
|
||||
if (isTerminalBridgeCommandState(current.state)) return current;
|
||||
await delay(terminalBridgeResultPollMs);
|
||||
async function waitForRCONJobTerminal(jobId: string): Promise<JobResponse | null> {
|
||||
for (let attempt = 0; attempt < terminalJobResultPollAttempts; attempt += 1) {
|
||||
const current = await platformApiClient.getJob(jobId);
|
||||
if (isTerminalJobState(current.state)) return current;
|
||||
await delay(terminalJobResultPollMs);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -401,8 +401,8 @@ function terminalQuickCommandsForPlugin(pluginId: string): TerminalQuickCommand[
|
||||
return terminalQuickCommandCatalog[pluginId] ?? [];
|
||||
}
|
||||
|
||||
function bridgeCommandDispatchLabel(state: string, commandId: string): string {
|
||||
return `已${state === "pending" ? "排队" : "提交"} · 桥接命令 ${commandId}`;
|
||||
function rconJobDispatchLabel(state: string, jobId: string): string {
|
||||
return `已${state === "queued" ? "排队" : "提交"} · RCON 任务 ${jobId}`;
|
||||
}
|
||||
|
||||
function terminalLineFromLog(stream: LogStreamResponse, entry: LogEntryBody): TerminalLine {
|
||||
@@ -433,7 +433,6 @@ function terminalSourceClass(value?: string): string {
|
||||
if (key.includes("stdout")) return "stdout";
|
||||
if (key.includes("command")) return "command";
|
||||
if (key.includes("platform")) return "platform";
|
||||
if (key.includes("bridge")) return "bridge";
|
||||
if (key.includes("system")) return "system";
|
||||
return "log";
|
||||
}
|
||||
@@ -448,27 +447,27 @@ function eventBelongsToLiveSession(eventSessionId: string | undefined, liveSessi
|
||||
return Boolean(normalizedEventSessionId && normalizedEventSessionId === liveSessionId);
|
||||
}
|
||||
|
||||
function isTerminalBridgeCommandState(state: GameClientBridgeCommandResponse["state"]): boolean {
|
||||
return state === "succeeded" || state === "failed" || state === "cancelled" || state === "expired" || state === "unknown";
|
||||
function isTerminalJobState(state: JobResponse["state"]): boolean {
|
||||
return state === "succeeded" || state === "failed" || state === "cancelled";
|
||||
}
|
||||
|
||||
function terminalLineFromBridgeCommand(command: GameClientBridgeCommandResponse): TerminalLine {
|
||||
const summary = command.result?.summary || command.resultSummary || command.cancellation?.reason || bridgeCommandStateLabel(command.state);
|
||||
const completed = command.completedAt || command.result?.completedAt || command.cancellation?.cancelledAt || command.updatedAt;
|
||||
function terminalLineFromJob(job: JobResponse): TerminalLine {
|
||||
const summary = job.progress.message || job.executionResult?.summary || job.cancelReason || jobStateLabel(job.state);
|
||||
const completed = job.updatedAt;
|
||||
const sortKey = Date.parse(completed) || Date.now();
|
||||
const tone: TerminalLine["tone"] = command.state === "succeeded" ? "success" : command.state === "failed" ? "error" : "warn";
|
||||
return { id: `bridge-${command.id}-${command.state}`, tone, text: `桥接命令 ${command.id} · ${bridgeCommandStateLabel(command.state)} · ${summary}`, at: new Date(sortKey).toLocaleTimeString(), sortKey, streamKey: "BRIDGE" };
|
||||
const tone: TerminalLine["tone"] = job.state === "succeeded" ? "success" : job.state === "failed" ? "error" : "warn";
|
||||
return { id: `rcon-job-${job.id}-${job.state}`, tone, text: `RCON 任务 ${job.id} · ${jobStateLabel(job.state)} · ${summary}`, at: new Date(sortKey).toLocaleTimeString(), sortKey, streamKey: "PLATFORM" };
|
||||
}
|
||||
|
||||
function bridgeCommandStateLabel(state: GameClientBridgeCommandResponse["state"]): string {
|
||||
function jobStateLabel(state: JobResponse["state"]): string {
|
||||
switch (state) {
|
||||
case "succeeded": return "已成功";
|
||||
case "failed": return "已失败";
|
||||
case "cancelled": return "已取消";
|
||||
case "expired": return "已过期";
|
||||
case "unknown": return "状态未知";
|
||||
case "claimed": return "Run 已领取";
|
||||
case "pending": return "已排队";
|
||||
case "accepted": return "Run 已领取";
|
||||
case "running": return "运行中";
|
||||
case "retrying": return "等待重试";
|
||||
case "queued": return "已排队";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user