From 85a8f47c31706d5484171c123f9f68e4f472d533 Mon Sep 17 00:00:00 2001 From: QQ Date: Thu, 12 Nov 2026 00:02:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20src/api.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/api.ts b/src/api.ts index ae844a1..557a100 100644 --- a/src/api.ts +++ b/src/api.ts @@ -301,6 +301,25 @@ export class CloudClient { return this.request('POST', '/activity/turn', payload, token) } + /** + * Read-only reachability probe: any HTTP answer (even 401 or 404) proves the + * host is up. This is what separates "服务不可达" from "令牌无效" in the card, + * and it never sends a credential. + */ + async reach(): Promise<{ ok: boolean; status: number; message: string }> { + try { + const response = await fetch(`${this.options.baseUrl()}/status`, { + method: 'GET', + headers: { Accept: 'application/json' }, + signal: AbortSignal.timeout(this.options.timeoutMs()), + }) + return { ok: true, status: response.status, message: `服务可达(HTTP ${response.status})` } + } catch (error) { + const reason = error instanceof Error ? error.message : String(error) + return { ok: false, status: 0, message: `服务不可达:${reason}` } + } + } + /** Stage one turn summary as pending proposals (summary:write token). */ submitSummary(payload: SummaryPayload, token: string): Promise> { return this.request('POST', '/activity/summary', payload, token)