style: 完成所有文件的lint

This commit is contained in:
claude-code-best
2026-05-01 21:39:30 +08:00
parent d136872cc9
commit 6182015005
1333 changed files with 68255 additions and 77882 deletions

View File

@@ -1,90 +1,102 @@
import type { Session, Environment, ControlResponse, SessionEvent } from "../types";
import { generateMessageUuid } from "../lib/utils";
import type {
Session,
Environment,
ControlResponse,
SessionEvent,
} from '../types'
import { generateMessageUuid } from '../lib/utils'
const BASE = "";
const BASE = ''
export function getUuid(): string {
let uuid = localStorage.getItem("rcs_uuid");
let uuid = localStorage.getItem('rcs_uuid')
if (!uuid) {
uuid = generateMessageUuid();
localStorage.setItem("rcs_uuid", uuid);
uuid = generateMessageUuid()
localStorage.setItem('rcs_uuid', uuid)
}
return uuid;
return uuid
}
export function setUuid(uuid: string): void {
localStorage.setItem("rcs_uuid", uuid);
localStorage.setItem('rcs_uuid', uuid)
}
/** Active API token for Authorization header (set by useTokens) */
let _activeToken: string | null = null;
let _activeToken: string | null = null
export function setActiveApiToken(token: string | null): void {
_activeToken = token;
_activeToken = token
}
export function getActiveApiToken(): string | null {
return _activeToken;
return _activeToken
}
async function api<T>(method: string, path: string, body?: unknown): Promise<T> {
const headers: Record<string, string> = { "Content-Type": "application/json" };
async function api<T>(
method: string,
path: string,
body?: unknown,
): Promise<T> {
const headers: Record<string, string> = { 'Content-Type': 'application/json' }
if (_activeToken) {
headers["Authorization"] = `Bearer ${_activeToken}`;
headers['Authorization'] = `Bearer ${_activeToken}`
}
const uuid = getUuid();
const sep = path.includes("?") ? "&" : "?";
const url = `${BASE}${path}${sep}uuid=${encodeURIComponent(uuid)}`;
const opts: RequestInit = { method, headers };
if (body !== undefined) opts.body = JSON.stringify(body);
const uuid = getUuid()
const sep = path.includes('?') ? '&' : '?'
const url = `${BASE}${path}${sep}uuid=${encodeURIComponent(uuid)}`
const opts: RequestInit = { method, headers }
if (body !== undefined) opts.body = JSON.stringify(body)
const res = await fetch(url, opts);
const data = await res.json();
const res = await fetch(url, opts)
const data = await res.json()
if (!res.ok) {
const err = data.error || { type: "unknown", message: res.statusText };
throw new Error(err.message || err.type);
const err = data.error || { type: 'unknown', message: res.statusText }
throw new Error(err.message || err.type)
}
return data as T;
return data as T
}
export function apiBind(sessionId: string) {
return api<void>("POST", "/web/bind", { sessionId });
return api<void>('POST', '/web/bind', { sessionId })
}
export function apiFetchSessions() {
return api<Session[]>("GET", "/web/sessions");
return api<Session[]>('GET', '/web/sessions')
}
export function apiFetchAllSessions() {
return api<Session[]>("GET", "/web/sessions/all");
return api<Session[]>('GET', '/web/sessions/all')
}
export function apiFetchSession(id: string) {
return api<Session>("GET", `/web/sessions/${id}`);
return api<Session>('GET', `/web/sessions/${id}`)
}
export function apiFetchSessionHistory(id: string) {
return api<{ events: SessionEvent[] }>("GET", `/web/sessions/${id}/history`);
return api<{ events: SessionEvent[] }>('GET', `/web/sessions/${id}/history`)
}
export function apiFetchEnvironments() {
return api<Environment[]>("GET", "/web/environments");
return api<Environment[]>('GET', '/web/environments')
}
export function apiSendEvent(sessionId: string, body: Record<string, unknown>) {
return api<void>("POST", `/web/sessions/${sessionId}/events`, body);
return api<void>('POST', `/web/sessions/${sessionId}/events`, body)
}
export function apiSendControl(sessionId: string, body: ControlResponse) {
return api<void>("POST", `/web/sessions/${sessionId}/control`, body);
return api<void>('POST', `/web/sessions/${sessionId}/control`, body)
}
export function apiInterrupt(sessionId: string) {
return api<void>("POST", `/web/sessions/${sessionId}/interrupt`);
return api<void>('POST', `/web/sessions/${sessionId}/interrupt`)
}
export function apiCreateSession(body: { title?: string; environment_id?: string }) {
return api<Session>("POST", "/web/sessions", body);
export function apiCreateSession(body: {
title?: string
environment_id?: string
}) {
return api<Session>('POST', '/web/sessions', body)
}

View File

@@ -1,41 +1,41 @@
import { getUuid } from "./client";
import type { SessionEvent } from "../types";
import { getUuid } from './client'
import type { SessionEvent } from '../types'
let currentEventSource: EventSource | null = null;
let currentEventSource: EventSource | null = null
export function connectSSE(
sessionId: string,
onEvent: (event: SessionEvent) => void,
fromSeqNum = 0,
): void {
disconnectSSE();
disconnectSSE()
const uuid = getUuid();
const url = `/web/sessions/${sessionId}/events?uuid=${encodeURIComponent(uuid)}`;
const es = new EventSource(url);
currentEventSource = es;
const uuid = getUuid()
const url = `/web/sessions/${sessionId}/events?uuid=${encodeURIComponent(uuid)}`
const es = new EventSource(url)
currentEventSource = es
let lastSeenSeq = fromSeqNum;
let lastSeenSeq = fromSeqNum
es.addEventListener("message", (e: MessageEvent) => {
es.addEventListener('message', (e: MessageEvent) => {
try {
const data = JSON.parse(e.data) as SessionEvent;
if (data.seqNum !== undefined && data.seqNum <= lastSeenSeq) return;
if (data.seqNum !== undefined) lastSeenSeq = data.seqNum;
onEvent(data);
const data = JSON.parse(e.data) as SessionEvent
if (data.seqNum !== undefined && data.seqNum <= lastSeenSeq) return
if (data.seqNum !== undefined) lastSeenSeq = data.seqNum
onEvent(data)
} catch {
// ignore parse errors
}
});
})
es.addEventListener("error", () => {
es.addEventListener('error', () => {
// EventSource auto-reconnects
});
})
}
export function disconnectSSE(): void {
if (currentEventSource) {
currentEventSource.close();
currentEventSource = null;
currentEventSource.close()
currentEventSource = null
}
}