Files
openclaw/src/gateway/session-utils.types.ts
Val Alexander 4532e5d858 fix(control-ui): preserve Stop after reconnect
Fixes #70991.

Adds authenticated Gateway WebSocket protocol pings, exposes active session-run state to Control UI, and keeps session-scoped Stop available after reconnect or reload when the browser lost the local run id.

Validation:
- pnpm test ui/src/ui/app-chat.test.ts ui/src/ui/app-gateway.node.test.ts src/gateway/server.sessions.list-changed.test.ts src/gateway/server/ws-connection.test.ts
- OPENCLAW_LOCAL_CHECK=1 OPENCLAW_LOCAL_CHECK_MODE=throttled pnpm check:changed
- GitHub CI and high-signal security checks passed on head 1f4c8728c8
2026-05-02 10:41:27 -05:00

125 lines
3.5 KiB
TypeScript

import type { ChatType } from "../channels/chat-type.js";
import type { SessionCompactionCheckpoint, SessionEntry } from "../config/sessions/types.js";
import type { PluginSessionExtensionProjection } from "../plugins/host-hooks.js";
import type {
GatewayAgentRuntime,
GatewayAgentRow as SharedGatewayAgentRow,
SessionsListResultBase,
SessionsPatchResultBase,
} from "../shared/session-types.js";
import type { DeliveryContext } from "../utils/delivery-context.types.js";
export type GatewaySessionsDefaults = {
modelProvider: string | null;
model: string | null;
contextTokens: number | null;
thinkingLevels?: GatewayThinkingLevelOption[];
thinkingOptions?: string[];
thinkingDefault?: string;
};
type GatewayThinkingLevelOption = {
id: string;
label: string;
};
export type SessionRunStatus = "running" | "done" | "failed" | "killed" | "timeout";
type SubagentRunState = "active" | "interrupted" | "historical";
export type SessionCompactionCheckpointPreview = Pick<
SessionCompactionCheckpoint,
"checkpointId" | "createdAt" | "reason"
>;
export type GatewaySessionRow = {
key: string;
spawnedBy?: string;
spawnedWorkspaceDir?: string;
forkedFromParent?: boolean;
spawnDepth?: number;
subagentRole?: SessionEntry["subagentRole"];
subagentControlScope?: SessionEntry["subagentControlScope"];
kind: "direct" | "group" | "global" | "unknown";
label?: string;
displayName?: string;
derivedTitle?: string;
lastMessagePreview?: string;
channel?: string;
subject?: string;
groupChannel?: string;
space?: string;
chatType?: ChatType;
origin?: SessionEntry["origin"];
updatedAt: number | null;
sessionId?: string;
systemSent?: boolean;
abortedLastRun?: boolean;
thinkingLevel?: string;
thinkingLevels?: GatewayThinkingLevelOption[];
thinkingOptions?: string[];
thinkingDefault?: string;
fastMode?: boolean;
verboseLevel?: string;
traceLevel?: string;
reasoningLevel?: string;
elevatedLevel?: string;
sendPolicy?: "allow" | "deny";
inputTokens?: number;
outputTokens?: number;
totalTokens?: number;
totalTokensFresh?: boolean;
estimatedCostUsd?: number;
status?: SessionRunStatus;
hasActiveRun?: boolean;
subagentRunState?: SubagentRunState;
hasActiveSubagentRun?: boolean;
startedAt?: number;
endedAt?: number;
runtimeMs?: number;
parentSessionKey?: string;
childSessions?: string[];
responseUsage?: "on" | "off" | "tokens" | "full";
modelProvider?: string;
model?: string;
agentRuntime?: GatewayAgentRuntime;
contextTokens?: number;
deliveryContext?: DeliveryContext;
lastChannel?: SessionEntry["lastChannel"];
lastTo?: string;
lastAccountId?: string;
lastThreadId?: SessionEntry["lastThreadId"];
compactionCheckpointCount?: number;
latestCompactionCheckpoint?: SessionCompactionCheckpointPreview;
pluginExtensions?: PluginSessionExtensionProjection[];
};
export type GatewayAgentRow = SharedGatewayAgentRow;
export type SessionPreviewItem = {
role: "user" | "assistant" | "tool" | "system" | "other";
text: string;
};
export type SessionsPreviewEntry = {
key: string;
status: "ok" | "empty" | "missing" | "error";
items: SessionPreviewItem[];
};
export type SessionsPreviewResult = {
ts: number;
previews: SessionsPreviewEntry[];
};
export type SessionsListResult = SessionsListResultBase<GatewaySessionsDefaults, GatewaySessionRow>;
export type SessionsPatchResult = SessionsPatchResultBase<SessionEntry> & {
entry: SessionEntry;
resolved?: {
modelProvider?: string;
model?: string;
agentRuntime?: GatewayAgentRuntime;
};
};