Skip to content

Commit 27677dd

Browse files
committed
chore: Fix all TypeScript errors in ui.
1 parent be4f7ef commit 27677dd

25 files changed

Lines changed: 225 additions & 148 deletions

‎ui/src/ui/app-chat.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { loadSessions } from "./controllers/sessions";
1010
import { normalizeBasePath } from "./navigation";
1111
import { generateUUID } from "./uuid";
1212

13-
type ChatHost = {
13+
export type ChatHost = {
1414
connected: boolean;
1515
chatMessage: string;
1616
chatAttachments: ChatAttachment[];

‎ui/src/ui/app-render.helpers.ts‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import type { AppViewState } from "./app-view-state";
44
import type { ThemeMode } from "./theme";
55
import type { ThemeTransitionContext } from "./theme-transition";
66
import type { SessionsListResult } from "./types";
7+
import { OpenClawApp } from "./app";
78
import { refreshChat } from "./app-chat";
89
import { syncUrlWithSessionKey } from "./app-settings";
9-
import { loadChatHistory } from "./controllers/chat";
10+
import { ChatState, loadChatHistory } from "./controllers/chat";
1011
import { icons } from "./icons";
1112
import { iconForTab, pathForTab, titleForTab, type Tab } from "./navigation";
1213

@@ -94,18 +95,18 @@ export function renderChatControls(state: AppViewState) {
9495
state.sessionKey = next;
9596
state.chatMessage = "";
9697
state.chatStream = null;
97-
state.chatStreamStartedAt = null;
98+
(state as unknown as OpenClawApp).chatStreamStartedAt = null;
9899
state.chatRunId = null;
99-
state.resetToolStream();
100-
state.resetChatScroll();
100+
(state as unknown as OpenClawApp).resetToolStream();
101+
(state as unknown as OpenClawApp).resetChatScroll();
101102
state.applySettings({
102103
...state.settings,
103104
sessionKey: next,
104105
lastActiveSessionKey: next,
105106
});
106107
void state.loadAssistantIdentity();
107-
syncUrlWithSessionKey(state, next, true);
108-
void loadChatHistory(state);
108+
syncUrlWithSessionKey(next, true);
109+
void loadChatHistory(state as unknown as ChatState);
109110
}}
110111
>
111112
${repeat(
@@ -122,7 +123,7 @@ export function renderChatControls(state: AppViewState) {
122123
class="btn btn--sm btn--icon"
123124
?disabled=${state.chatLoading || !state.connected}
124125
@click=${() => {
125-
state.resetToolStream();
126+
(state as unknown as OpenClawApp).resetToolStream();
126127
void refreshChat(state as unknown as Parameters<typeof refreshChat>[0]);
127128
}}
128129
title="Refresh chat data"
@@ -228,7 +229,7 @@ function resolveSessionOptions(
228229
seen.add(mainSessionKey);
229230
options.push({
230231
key: mainSessionKey,
231-
displayName: resolveSessionDisplayName(mainSessionKey, resolvedMain),
232+
displayName: resolveSessionDisplayName(mainSessionKey, resolvedMain || undefined),
232233
});
233234
}
234235

‎ui/src/ui/app-render.ts‎

Lines changed: 118 additions & 67 deletions
Large diffs are not rendered by default.

‎ui/src/ui/app-settings.ts‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function applySettingsFromUrl(host: SettingsHost) {
9999
if (passwordRaw != null) {
100100
const password = passwordRaw.trim();
101101
if (password) {
102-
(host as { password: string }).password = password;
102+
(host as unknown as { password: string }).password = password;
103103
}
104104
params.delete("password");
105105
shouldCleanUrl = true;
@@ -189,23 +189,24 @@ export async function refreshActiveTab(host: SettingsHost) {
189189
await loadSkills(host as unknown as OpenClawApp);
190190
}
191191
if (host.tab === "agents") {
192-
await loadAgents(host as unknown as OpenClawApp);
193-
await loadConfig(host as unknown as OpenClawApp);
194-
const agentIds = host.agentsList?.agents?.map((entry) => entry.id) ?? [];
192+
const app = host as unknown as OpenClawApp;
193+
await loadAgents(app);
194+
await loadConfig(app);
195+
const agentIds = app.agentsList?.agents?.map((entry) => entry.id) ?? [];
195196
if (agentIds.length > 0) {
196-
void loadAgentIdentities(host as unknown as OpenClawApp, agentIds);
197+
void loadAgentIdentities(app, agentIds);
197198
}
198199
const agentId =
199-
host.agentsSelectedId ?? host.agentsList?.defaultId ?? host.agentsList?.agents?.[0]?.id;
200+
app.agentsSelectedId ?? app.agentsList?.defaultId ?? app.agentsList?.agents?.[0]?.id;
200201
if (agentId) {
201-
void loadAgentIdentity(host as unknown as OpenClawApp, agentId);
202-
if (host.agentsPanel === "skills") {
203-
void loadAgentSkills(host as unknown as OpenClawApp, agentId);
202+
void loadAgentIdentity(app, agentId);
203+
if (app.agentsPanel === "skills") {
204+
void loadAgentSkills(app, agentId);
204205
}
205-
if (host.agentsPanel === "channels") {
206-
void loadChannels(host as unknown as OpenClawApp, false);
206+
if (app.agentsPanel === "channels") {
207+
void loadChannels(app, false);
207208
}
208-
if (host.agentsPanel === "cron") {
209+
if (app.agentsPanel === "cron") {
209210
void loadCron(host);
210211
}
211212
}
@@ -380,7 +381,7 @@ export function syncUrlWithTab(host: SettingsHost, tab: Tab, replace: boolean) {
380381
}
381382
}
382383

383-
export function syncUrlWithSessionKey(host: SettingsHost, sessionKey: string, replace: boolean) {
384+
export function syncUrlWithSessionKey(sessionKey: string, replace: boolean) {
384385
if (typeof window === "undefined") {
385386
return;
386387
}

‎ui/src/ui/app-tool-stream.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export function handleAgentEvent(host: ToolStreamHost, payload?: AgentEventPaylo
257257
sessionKey,
258258
name,
259259
args,
260-
output,
260+
output: output || undefined,
261261
startedAt: typeof payload.ts === "number" ? payload.ts : now,
262262
updatedAt: now,
263263
message: {},
@@ -270,7 +270,7 @@ export function handleAgentEvent(host: ToolStreamHost, payload?: AgentEventPaylo
270270
entry.args = args;
271271
}
272272
if (output !== undefined) {
273-
entry.output = output;
273+
entry.output = output || undefined;
274274
}
275275
entry.updatedAt = now;
276276
}

‎ui/src/ui/config-form.browser.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe("config form renderer", () => {
5151
container,
5252
);
5353

54-
const tokenInput = container.querySelector("input[type='password']");
54+
const tokenInput: HTMLInputElement | null = container.querySelector("input[type='password']");
5555
expect(tokenInput).not.toBeNull();
5656
if (!tokenInput) {
5757
return;
@@ -67,7 +67,7 @@ describe("config form renderer", () => {
6767
tokenButton?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
6868
expect(onPatch).toHaveBeenCalledWith(["mode"], "token");
6969

70-
const checkbox = container.querySelector("input[type='checkbox']");
70+
const checkbox: HTMLInputElement | null = container.querySelector("input[type='checkbox']");
7171
expect(checkbox).not.toBeNull();
7272
if (!checkbox) {
7373
return;

‎ui/src/ui/controllers/agents.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function loadAgents(state: AgentsState) {
2020
state.agentsLoading = true;
2121
state.agentsError = null;
2222
try {
23-
const res = await state.client.request("agents.list", {});
23+
const res = await state.client.request<AgentsListResult>("agents.list", {});
2424
if (res) {
2525
state.agentsList = res;
2626
const selected = state.agentsSelectedId;

‎ui/src/ui/controllers/channels.ts‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ChannelsState } from "./channels.types";
2+
import { ChannelsStatusSnapshot } from "../types";
23

34
export type { ChannelsState };
45

@@ -12,7 +13,7 @@ export async function loadChannels(state: ChannelsState, probe: boolean) {
1213
state.channelsLoading = true;
1314
state.channelsError = null;
1415
try {
15-
const res = await state.client.request("channels.status", {
16+
const res = await state.client.request<ChannelsStatusSnapshot | null>("channels.status", {
1617
probe,
1718
timeoutMs: 8000,
1819
});
@@ -31,10 +32,13 @@ export async function startWhatsAppLogin(state: ChannelsState, force: boolean) {
3132
}
3233
state.whatsappBusy = true;
3334
try {
34-
const res = await state.client.request("web.login.start", {
35-
force,
36-
timeoutMs: 30000,
37-
});
35+
const res = await state.client.request<{ message?: string; qrDataUrl?: string }>(
36+
"web.login.start",
37+
{
38+
force,
39+
timeoutMs: 30000,
40+
},
41+
);
3842
state.whatsappLoginMessage = res.message ?? null;
3943
state.whatsappLoginQrDataUrl = res.qrDataUrl ?? null;
4044
state.whatsappLoginConnected = null;
@@ -53,9 +57,12 @@ export async function waitWhatsAppLogin(state: ChannelsState) {
5357
}
5458
state.whatsappBusy = true;
5559
try {
56-
const res = await state.client.request("web.login.wait", {
57-
timeoutMs: 120000,
58-
});
60+
const res = await state.client.request<{ message?: string; connected?: boolean }>(
61+
"web.login.wait",
62+
{
63+
timeoutMs: 120000,
64+
},
65+
);
5966
state.whatsappLoginMessage = res.message ?? null;
6067
state.whatsappLoginConnected = res.connected ?? null;
6168
if (res.connected) {

‎ui/src/ui/controllers/chat.test.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ import { handleChatEvent, type ChatEventPayload, type ChatState } from "./chat";
33

44
function createState(overrides: Partial<ChatState> = {}): ChatState {
55
return {
6-
client: null,
7-
connected: true,
8-
sessionKey: "main",
6+
chatAttachments: [],
97
chatLoading: false,
10-
chatMessages: [],
11-
chatThinkingLevel: null,
12-
chatSending: false,
138
chatMessage: "",
9+
chatMessages: [],
1410
chatRunId: null,
11+
chatSending: false,
1512
chatStream: null,
1613
chatStreamStartedAt: null,
14+
chatThinkingLevel: null,
15+
client: null,
16+
connected: true,
1717
lastError: null,
18+
sessionKey: "main",
1819
...overrides,
1920
};
2021
}

‎ui/src/ui/controllers/chat.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ export async function loadChatHistory(state: ChatState) {
3434
state.chatLoading = true;
3535
state.lastError = null;
3636
try {
37-
const res = await state.client.request("chat.history", {
38-
sessionKey: state.sessionKey,
39-
limit: 200,
40-
});
37+
const res = await state.client.request<{ messages?: Array<unknown>; thinkingLevel?: string }>(
38+
"chat.history",
39+
{
40+
sessionKey: state.sessionKey,
41+
limit: 200,
42+
},
43+
);
4144
state.chatMessages = Array.isArray(res.messages) ? res.messages : [];
4245
state.chatThinkingLevel = res.thinkingLevel ?? null;
4346
} catch (err) {

0 commit comments

Comments
 (0)