Skip to content

Commit b09b35c

Browse files
committed
chore(deadcode): share ui helper predicates
1 parent 15f2a56 commit b09b35c

4 files changed

Lines changed: 20 additions & 30 deletions

File tree

ui/src/ui/chat/stream-reconciliation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ function insertMessageAtIndex(messages: unknown[], message: unknown, index: numb
332332
return [...messages.slice(0, index), message, ...messages.slice(index)];
333333
}
334334

335-
function messageTimestampMs(message: unknown): number | null {
335+
export function messageTimestampMs(message: unknown): number | null {
336336
if (!message || typeof message !== "object") {
337337
return null;
338338
}

ui/src/ui/controllers/chat.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
hasVisibleStreamParts,
2020
historyReplacedVisibleStream,
2121
materializeVisibleStreamState,
22+
messageTimestampMs,
2223
maybeResetToolStream,
2324
persistedCurrentToolStreamIds,
2425
prunePersistedToolStreamMessages,
@@ -31,6 +32,7 @@ import {
3132
recordControlUiPerformanceEvent,
3233
roundedControlUiDurationMs,
3334
} from "../control-ui-performance.ts";
35+
import { isGatewayMethodAdvertised } from "../gateway-methods.ts";
3436
import { GatewayRequestError, type GatewayBrowserClient, type GatewayHelloOk } from "../gateway.ts";
3537
import {
3638
areUiSessionKeysEquivalent,
@@ -52,6 +54,8 @@ import {
5254
isMissingOperatorReadScopeError,
5355
} from "./scope-errors.ts";
5456

57+
export { isGatewayMethodAdvertised } from "../gateway-methods.ts";
58+
5559
const SILENT_REPLY_PATTERN = /^\s*NO_REPLY\s*$/;
5660
const SYNTHETIC_TRANSCRIPT_REPAIR_RESULT =
5761
"[openclaw] missing tool result in session history; inserted synthetic error result for transcript repair.";
@@ -241,18 +245,6 @@ function messageDisplaySignature(message: unknown): string | null {
241245
}
242246
}
243247

244-
function messageTimestampMs(message: unknown): number | null {
245-
if (!message || typeof message !== "object") {
246-
return null;
247-
}
248-
const timestamp = (message as { timestamp?: unknown; ts?: unknown }).timestamp;
249-
if (typeof timestamp === "number" && Number.isFinite(timestamp)) {
250-
return timestamp;
251-
}
252-
const ts = (message as { timestamp?: unknown; ts?: unknown }).ts;
253-
return typeof ts === "number" && Number.isFinite(ts) ? ts : null;
254-
}
255-
256248
function historyHasSameOrNewerDisplayMessage(
257249
historyMessages: unknown[],
258250
signature: string,
@@ -375,14 +367,6 @@ function isUnknownGatewayMethodError(err: unknown, method: string): err is Gatew
375367
);
376368
}
377369

378-
export function isGatewayMethodAdvertised(state: ChatState, method: string): boolean | null {
379-
const methods = state.hello?.features?.methods;
380-
if (!Array.isArray(methods)) {
381-
return null;
382-
}
383-
return methods.includes(method);
384-
}
385-
386370
function resolveStartupRetryDelayMs(err: GatewayRequestError): number {
387371
const retryAfterMs =
388372
typeof err.retryAfterMs === "number" ? err.retryAfterMs : STARTUP_CHAT_HISTORY_DEFAULT_RETRY_MS;

ui/src/ui/controllers/dreaming.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isGatewayMethodAdvertised } from "../gateway-methods.ts";
12
// Control UI controller manages dreaming gateway state.
23
import type { GatewayBrowserClient, GatewayHelloOk } from "../gateway.ts";
34
import { isPluginEnabledInConfigSnapshot } from "../plugin-activation.ts";
@@ -253,16 +254,8 @@ function isMemoryWikiEnabled(state: DreamingState): boolean {
253254
});
254255
}
255256

256-
function hasGatewayMethod(state: DreamingState, method: string): boolean | null {
257-
const methods = state.hello?.features?.methods;
258-
if (!Array.isArray(methods)) {
259-
return null;
260-
}
261-
return methods.includes(method);
262-
}
263-
264257
function canCallMemoryWikiMethod(state: DreamingState, method: string): boolean {
265-
const available = hasGatewayMethod(state, method);
258+
const available = isGatewayMethodAdvertised(state, method);
266259
if (available !== null) {
267260
return available;
268261
}

ui/src/ui/gateway-methods.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Shared Gateway hello method lookup for feature-gated UI calls.
2+
import type { GatewayHelloOk } from "./gateway.ts";
3+
4+
export function isGatewayMethodAdvertised(
5+
host: { hello?: GatewayHelloOk | null },
6+
method: string,
7+
): boolean | null {
8+
const methods = host.hello?.features?.methods;
9+
if (!Array.isArray(methods)) {
10+
return null;
11+
}
12+
return methods.includes(method);
13+
}

0 commit comments

Comments
 (0)