From b09b35c13c170387d2a8937d1d48a995ef633d40 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 21 Jun 2026 06:50:55 +0800 Subject: [PATCH] chore(deadcode): share ui helper predicates --- ui/src/ui/chat/stream-reconciliation.ts | 2 +- ui/src/ui/controllers/chat.ts | 24 ++++-------------------- ui/src/ui/controllers/dreaming.ts | 11 ++--------- ui/src/ui/gateway-methods.ts | 13 +++++++++++++ 4 files changed, 20 insertions(+), 30 deletions(-) create mode 100644 ui/src/ui/gateway-methods.ts diff --git a/ui/src/ui/chat/stream-reconciliation.ts b/ui/src/ui/chat/stream-reconciliation.ts index 0a3cde0c2f70..9cfd23f672f9 100644 --- a/ui/src/ui/chat/stream-reconciliation.ts +++ b/ui/src/ui/chat/stream-reconciliation.ts @@ -332,7 +332,7 @@ function insertMessageAtIndex(messages: unknown[], message: unknown, index: numb return [...messages.slice(0, index), message, ...messages.slice(index)]; } -function messageTimestampMs(message: unknown): number | null { +export function messageTimestampMs(message: unknown): number | null { if (!message || typeof message !== "object") { return null; } diff --git a/ui/src/ui/controllers/chat.ts b/ui/src/ui/controllers/chat.ts index 804046b058a5..103d0a9d30cd 100644 --- a/ui/src/ui/controllers/chat.ts +++ b/ui/src/ui/controllers/chat.ts @@ -19,6 +19,7 @@ import { hasVisibleStreamParts, historyReplacedVisibleStream, materializeVisibleStreamState, + messageTimestampMs, maybeResetToolStream, persistedCurrentToolStreamIds, prunePersistedToolStreamMessages, @@ -31,6 +32,7 @@ import { recordControlUiPerformanceEvent, roundedControlUiDurationMs, } from "../control-ui-performance.ts"; +import { isGatewayMethodAdvertised } from "../gateway-methods.ts"; import { GatewayRequestError, type GatewayBrowserClient, type GatewayHelloOk } from "../gateway.ts"; import { areUiSessionKeysEquivalent, @@ -52,6 +54,8 @@ import { isMissingOperatorReadScopeError, } from "./scope-errors.ts"; +export { isGatewayMethodAdvertised } from "../gateway-methods.ts"; + const SILENT_REPLY_PATTERN = /^\s*NO_REPLY\s*$/; const SYNTHETIC_TRANSCRIPT_REPAIR_RESULT = "[openclaw] missing tool result in session history; inserted synthetic error result for transcript repair."; @@ -241,18 +245,6 @@ function messageDisplaySignature(message: unknown): string | null { } } -function messageTimestampMs(message: unknown): number | null { - if (!message || typeof message !== "object") { - return null; - } - const timestamp = (message as { timestamp?: unknown; ts?: unknown }).timestamp; - if (typeof timestamp === "number" && Number.isFinite(timestamp)) { - return timestamp; - } - const ts = (message as { timestamp?: unknown; ts?: unknown }).ts; - return typeof ts === "number" && Number.isFinite(ts) ? ts : null; -} - function historyHasSameOrNewerDisplayMessage( historyMessages: unknown[], signature: string, @@ -375,14 +367,6 @@ function isUnknownGatewayMethodError(err: unknown, method: string): err is Gatew ); } -export function isGatewayMethodAdvertised(state: ChatState, method: string): boolean | null { - const methods = state.hello?.features?.methods; - if (!Array.isArray(methods)) { - return null; - } - return methods.includes(method); -} - function resolveStartupRetryDelayMs(err: GatewayRequestError): number { const retryAfterMs = typeof err.retryAfterMs === "number" ? err.retryAfterMs : STARTUP_CHAT_HISTORY_DEFAULT_RETRY_MS; diff --git a/ui/src/ui/controllers/dreaming.ts b/ui/src/ui/controllers/dreaming.ts index a150f099ed33..b1dc343dc61f 100644 --- a/ui/src/ui/controllers/dreaming.ts +++ b/ui/src/ui/controllers/dreaming.ts @@ -1,3 +1,4 @@ +import { isGatewayMethodAdvertised } from "../gateway-methods.ts"; // Control UI controller manages dreaming gateway state. import type { GatewayBrowserClient, GatewayHelloOk } from "../gateway.ts"; import { isPluginEnabledInConfigSnapshot } from "../plugin-activation.ts"; @@ -253,16 +254,8 @@ function isMemoryWikiEnabled(state: DreamingState): boolean { }); } -function hasGatewayMethod(state: DreamingState, method: string): boolean | null { - const methods = state.hello?.features?.methods; - if (!Array.isArray(methods)) { - return null; - } - return methods.includes(method); -} - function canCallMemoryWikiMethod(state: DreamingState, method: string): boolean { - const available = hasGatewayMethod(state, method); + const available = isGatewayMethodAdvertised(state, method); if (available !== null) { return available; } diff --git a/ui/src/ui/gateway-methods.ts b/ui/src/ui/gateway-methods.ts new file mode 100644 index 000000000000..3ae5ce0e5762 --- /dev/null +++ b/ui/src/ui/gateway-methods.ts @@ -0,0 +1,13 @@ +// Shared Gateway hello method lookup for feature-gated UI calls. +import type { GatewayHelloOk } from "./gateway.ts"; + +export function isGatewayMethodAdvertised( + host: { hello?: GatewayHelloOk | null }, + method: string, +): boolean | null { + const methods = host.hello?.features?.methods; + if (!Array.isArray(methods)) { + return null; + } + return methods.includes(method); +}