chore(deadcode): share ui helper predicates

This commit is contained in:
Vincent Koc
2026-06-21 06:50:55 +08:00
parent 15f2a56590
commit b09b35c13c
4 changed files with 20 additions and 30 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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);
}