chore: Enable more lint rules, disable some that trigger a lot. Will clean up later.

This commit is contained in:
cpojer
2026-01-31 16:03:28 +09:00
parent 481f696a87
commit 15792b153f
292 changed files with 643 additions and 699 deletions

View File

@@ -9,10 +9,10 @@ export async function readLatestAssistantReply(params: {
sessionKey: string;
limit?: number;
}): Promise<string | undefined> {
const history = (await callGateway({
const history = await callGateway({
method: "chat.history",
params: { sessionKey: params.sessionKey, limit: params.limit ?? 50 },
})) as { messages?: unknown[] };
});
const filtered = stripToolMessages(Array.isArray(history?.messages) ? history.messages : []);
const last = filtered.length > 0 ? filtered[filtered.length - 1] : undefined;
return last ? extractAssistantText(last) : undefined;
@@ -27,7 +27,7 @@ export async function runAgentStep(params: {
lane?: string;
}): Promise<string | undefined> {
const stepIdem = crypto.randomUUID();
const response = (await callGateway({
const response = await callGateway({
method: "agent",
params: {
message: params.message,
@@ -39,19 +39,19 @@ export async function runAgentStep(params: {
extraSystemPrompt: params.extraSystemPrompt,
},
timeoutMs: 10_000,
})) as { runId?: string; acceptedAt?: number };
});
const stepRunId = typeof response?.runId === "string" && response.runId ? response.runId : "";
const resolvedRunId = stepRunId || stepIdem;
const stepWaitMs = Math.min(params.timeoutMs, 60_000);
const wait = (await callGateway({
const wait = await callGateway({
method: "agent.wait",
params: {
runId: resolvedRunId,
timeoutMs: stepWaitMs,
},
timeoutMs: stepWaitMs + 2000,
})) as { status?: string };
});
if (wait?.status !== "ok") return undefined;
return await readLatestAssistantReply({ sessionKey: params.sessionKey });
}

View File

@@ -72,7 +72,9 @@ export function createAgentsListTool(opts?: {
}
const all = Array.from(allowed);
const rest = all.filter((id) => id !== requesterAgentId).sort((a, b) => a.localeCompare(b));
const rest = all
.filter((id) => id !== requesterAgentId)
.toSorted((a, b) => a.localeCompare(b));
const ordered = [requesterAgentId, ...rest];
const agents: AgentListEntry[] = ordered.map((id) => ({
id,

View File

@@ -93,7 +93,7 @@ async function resolveBrowserNodeTarget(params: {
if (params.target === "node") {
if (browserNodes.length === 1) {
const node = browserNodes[0]!;
const node = browserNodes[0];
return { nodeId: node.nodeId, label: node.displayName ?? node.remoteIp ?? node.nodeId };
}
throw new Error(
@@ -104,7 +104,7 @@ async function resolveBrowserNodeTarget(params: {
if (mode === "manual") return null;
if (browserNodes.length === 1) {
const node = browserNodes[0]!;
const node = browserNodes[0];
return { nodeId: node.nodeId, label: node.displayName ?? node.remoteIp ?? node.nodeId };
}
return null;
@@ -123,7 +123,7 @@ async function callBrowserProxy(params: {
typeof params.timeoutMs === "number" && Number.isFinite(params.timeoutMs)
? Math.max(1, Math.floor(params.timeoutMs))
: DEFAULT_BROWSER_PROXY_TIMEOUT_MS;
const payload = (await callGatewayTool(
const payload = await callGatewayTool(
"node.invoke",
{ timeoutMs: gatewayTimeoutMs },
{
@@ -139,11 +139,7 @@ async function callBrowserProxy(params: {
},
idempotencyKey: crypto.randomUUID(),
},
)) as {
ok?: boolean;
payload?: BrowserProxyResult;
payloadJSON?: string | null;
};
);
const parsed =
payload?.payload ??
(typeof payload?.payloadJSON === "string" && payload.payloadJSON
@@ -414,7 +410,7 @@ export function createBrowserTool(opts?: {
const snapshotDefaults = loadConfig().browser?.snapshotDefaults;
const format =
params.snapshotFormat === "ai" || params.snapshotFormat === "aria"
? (params.snapshotFormat as "ai" | "aria")
? params.snapshotFormat
: "ai";
const mode =
params.mode === "efficient"
@@ -697,10 +693,12 @@ export function createBrowserTool(opts?: {
if (!tabs.length) {
throw new Error(
"No Chrome tabs are attached via the OpenClaw Browser Relay extension. Click the toolbar icon on the tab you want to control (badge ON), then retry.",
{ cause: err },
);
}
throw new Error(
`Chrome tab not found (stale targetId?). Run action=tabs profile="chrome" and use one of the returned targetIds.`,
{ cause: err },
);
}
throw err;

View File

@@ -103,10 +103,10 @@ async function buildReminderContextLines(params: {
const { mainKey, alias } = resolveMainSessionAlias(cfg);
const resolvedKey = resolveInternalSessionKey({ key: sessionKey, alias, mainKey });
try {
const res = (await callGatewayTool("chat.history", params.gatewayOpts, {
const res = await callGatewayTool("chat.history", params.gatewayOpts, {
sessionKey: resolvedKey,
limit: maxMessages,
})) as { messages?: unknown[] };
});
const messages = Array.isArray(res?.messages) ? res.messages : [];
const parsed = messages
.map((msg) => extractMessageText(msg as ChatMessage))

View File

@@ -267,10 +267,10 @@ async function runImagePrompt(params: {
}
const context = buildImageContext(params.prompt, params.base64, params.mimeType);
const message = (await complete(model, context, {
const message = await complete(model, context, {
apiKey,
maxTokens: 512,
})) as AssistantMessage;
});
const text = coerceImageAssistantText({
message,
provider: model.provider,

View File

@@ -307,7 +307,7 @@ function buildMessageToolDescription(options?: {
if (channelActions.length > 0) {
// Always include "send" as a base action
const allActions = new Set(["send", ...channelActions]);
const actionList = Array.from(allActions).sort().join(", ");
const actionList = Array.from(allActions).toSorted().join(", ");
return `${baseDescription} Current channel (${options.currentChannel}) supports: ${actionList}.`;
}
}

View File

@@ -199,7 +199,7 @@ export function createNodesTool(options?: {
const details: Array<Record<string, unknown>> = [];
for (const facing of facings) {
const raw = (await callGatewayTool("node.invoke", gatewayOpts, {
const raw = await callGatewayTool("node.invoke", gatewayOpts, {
nodeId,
command: "camera.snap",
params: {
@@ -211,7 +211,7 @@ export function createNodesTool(options?: {
deviceId,
},
idempotencyKey: crypto.randomUUID(),
})) as { payload?: unknown };
});
const payload = parseCameraSnapPayload(raw?.payload);
const normalizedFormat = payload.format.toLowerCase();
if (
@@ -250,12 +250,12 @@ export function createNodesTool(options?: {
case "camera_list": {
const node = readStringParam(params, "node", { required: true });
const nodeId = await resolveNodeId(gatewayOpts, node);
const raw = (await callGatewayTool("node.invoke", gatewayOpts, {
const raw = await callGatewayTool("node.invoke", gatewayOpts, {
nodeId,
command: "camera.list",
params: {},
idempotencyKey: crypto.randomUUID(),
})) as { payload?: unknown };
});
const payload =
raw && typeof raw.payload === "object" && raw.payload !== null ? raw.payload : {};
return jsonResult(payload);
@@ -280,7 +280,7 @@ export function createNodesTool(options?: {
typeof params.deviceId === "string" && params.deviceId.trim()
? params.deviceId.trim()
: undefined;
const raw = (await callGatewayTool("node.invoke", gatewayOpts, {
const raw = await callGatewayTool("node.invoke", gatewayOpts, {
nodeId,
command: "camera.clip",
params: {
@@ -291,7 +291,7 @@ export function createNodesTool(options?: {
deviceId,
},
idempotencyKey: crypto.randomUUID(),
})) as { payload?: unknown };
});
const payload = parseCameraClipPayload(raw?.payload);
const filePath = cameraTempPath({
kind: "clip",
@@ -326,7 +326,7 @@ export function createNodesTool(options?: {
: 0;
const includeAudio =
typeof params.includeAudio === "boolean" ? params.includeAudio : true;
const raw = (await callGatewayTool("node.invoke", gatewayOpts, {
const raw = await callGatewayTool("node.invoke", gatewayOpts, {
nodeId,
command: "screen.record",
params: {
@@ -337,7 +337,7 @@ export function createNodesTool(options?: {
includeAudio,
},
idempotencyKey: crypto.randomUUID(),
})) as { payload?: unknown };
});
const payload = parseScreenRecordPayload(raw?.payload);
const filePath =
typeof params.outPath === "string" && params.outPath.trim()
@@ -373,7 +373,7 @@ export function createNodesTool(options?: {
Number.isFinite(params.locationTimeoutMs)
? params.locationTimeoutMs
: undefined;
const raw = (await callGatewayTool("node.invoke", gatewayOpts, {
const raw = await callGatewayTool("node.invoke", gatewayOpts, {
nodeId,
command: "location.get",
params: {
@@ -382,7 +382,7 @@ export function createNodesTool(options?: {
timeoutMs: locationTimeoutMs,
},
idempotencyKey: crypto.randomUUID(),
})) as { payload?: unknown };
});
return jsonResult(raw?.payload ?? {});
}
case "run": {
@@ -423,7 +423,7 @@ export function createNodesTool(options?: {
typeof params.needsScreenRecording === "boolean"
? params.needsScreenRecording
: undefined;
const raw = (await callGatewayTool("node.invoke", gatewayOpts, {
const raw = await callGatewayTool("node.invoke", gatewayOpts, {
nodeId,
command: "system.run",
params: {
@@ -437,7 +437,7 @@ export function createNodesTool(options?: {
},
timeoutMs: invokeTimeoutMs,
idempotencyKey: crypto.randomUUID(),
})) as { payload?: unknown };
});
return jsonResult(raw?.payload ?? {});
}
default:
@@ -454,6 +454,7 @@ export function createNodesTool(options?: {
const message = err instanceof Error ? err.message : String(err);
throw new Error(
`agent=${agentLabel} node=${nodeLabel} gateway=${gatewayLabel} action=${action}: ${message}`,
{ cause: err },
);
}
},

View File

@@ -71,10 +71,10 @@ function normalizeNodeKey(value: string) {
async function loadNodes(opts: GatewayCallOptions): Promise<NodeListNode[]> {
try {
const res = (await callGatewayTool("node.list", opts, {})) as unknown;
const res = await callGatewayTool("node.list", opts, {});
return parseNodeList(res);
} catch {
const res = (await callGatewayTool("node.pair.list", opts, {})) as unknown;
const res = await callGatewayTool("node.pair.list", opts, {});
const { paired } = parsePairingList(res);
return paired.map((n) => ({
nodeId: n.nodeId,

View File

@@ -20,14 +20,14 @@ export async function resolveAnnounceTarget(params: {
}
try {
const list = (await callGateway({
const list = await callGateway({
method: "sessions.list",
params: {
includeGlobal: true,
includeUnknown: true,
limit: 200,
},
})) as { sessions?: Array<Record<string, unknown>> };
});
const sessions = Array.isArray(list?.sessions) ? list.sessions : [];
const match =
sessions.find((entry) => entry?.key === params.sessionKey) ??

View File

@@ -135,7 +135,7 @@ async function resolveSessionKeyFromSessionId(params: {
}): Promise<SessionReferenceResolution> {
try {
// Resolve via gateway so we respect store routing and visibility rules.
const result = (await callGateway({
const result = await callGateway({
method: "sessions.resolve",
params: {
sessionId: params.sessionId,
@@ -143,7 +143,7 @@ async function resolveSessionKeyFromSessionId(params: {
includeGlobal: !params.restrictToSpawned,
includeUnknown: !params.restrictToSpawned,
},
})) as { key?: unknown };
});
const key = typeof result?.key === "string" ? result.key.trim() : "";
if (!key) {
throw new Error(
@@ -188,13 +188,13 @@ async function resolveSessionKeyFromKey(params: {
}): Promise<SessionReferenceResolution | null> {
try {
// Try key-based resolution first so non-standard keys keep working.
const result = (await callGateway({
const result = await callGateway({
method: "sessions.resolve",
params: {
key: params.key,
spawnedBy: params.restrictToSpawned ? params.requesterInternalKey : undefined,
},
})) as { key?: unknown };
});
const key = typeof result?.key === "string" ? result.key.trim() : "";
if (!key) return null;
return {

View File

@@ -28,7 +28,7 @@ async function isSpawnedSessionAllowed(params: {
targetSessionKey: string;
}): Promise<boolean> {
try {
const list = (await callGateway({
const list = await callGateway({
method: "sessions.list",
params: {
includeGlobal: false,
@@ -36,7 +36,7 @@ async function isSpawnedSessionAllowed(params: {
limit: 500,
spawnedBy: params.requesterSessionKey,
},
})) as { sessions?: Array<Record<string, unknown>> };
});
const sessions = Array.isArray(list?.sessions) ? list.sessions : [];
return sessions.some((entry) => entry?.key === params.targetSessionKey);
} catch {
@@ -126,10 +126,10 @@ export function createSessionsHistoryTool(opts?: {
? Math.max(1, Math.floor(params.limit))
: undefined;
const includeTools = Boolean(params.includeTools);
const result = (await callGateway({
const result = await callGateway({
method: "chat.history",
params: { sessionKey: resolvedKey, limit },
})) as { messages?: unknown[] };
});
const rawMessages = Array.isArray(result?.messages) ? result.messages : [];
const messages = includeTools ? rawMessages : stripToolMessages(rawMessages);
return jsonResult({

View File

@@ -79,7 +79,7 @@ export function createSessionsListTool(opts?: {
: 0;
const messageLimit = Math.min(messageLimitRaw, 20);
const list = (await callGateway({
const list = await callGateway({
method: "sessions.list",
params: {
limit,
@@ -88,10 +88,7 @@ export function createSessionsListTool(opts?: {
includeUnknown: !restrictToSpawned,
spawnedBy: restrictToSpawned ? requesterInternalKey : undefined,
},
})) as {
path?: string;
sessions?: Array<Record<string, unknown>>;
};
});
const sessions = Array.isArray(list?.sessions) ? list.sessions : [];
const storePath = typeof list?.path === "string" ? list.path : undefined;
@@ -187,10 +184,10 @@ export function createSessionsListTool(opts?: {
alias,
mainKey,
});
const history = (await callGateway({
const history = await callGateway({
method: "chat.history",
params: { sessionKey: resolvedKey, limit: messageLimit },
})) as { messages?: unknown[] };
});
const rawMessages = Array.isArray(history?.messages) ? history.messages : [];
const filtered = stripToolMessages(rawMessages);
row.messages = filtered.length > messageLimit ? filtered.slice(-messageLimit) : filtered;

View File

@@ -33,14 +33,14 @@ export async function runSessionsSendA2AFlow(params: {
let latestReply = params.roundOneReply;
if (!primaryReply && params.waitRunId) {
const waitMs = Math.min(params.announceTimeoutMs, 60_000);
const wait = (await callGateway({
const wait = await callGateway({
method: "agent.wait",
params: {
runId: params.waitRunId,
timeoutMs: waitMs,
},
timeoutMs: waitMs + 2000,
})) as { status?: string };
});
if (wait?.status === "ok") {
primaryReply = await readLatestAssistantReply({
sessionKey: params.targetSessionKey,

View File

@@ -81,11 +81,11 @@ export function createSessionsSendTool(opts?: {
}
const listSessions = async (listParams: Record<string, unknown>) => {
const result = (await callGateway({
const result = await callGateway({
method: "sessions.list",
params: listParams,
timeoutMs: 10_000,
})) as { sessions?: Array<Record<string, unknown>> };
});
return Array.isArray(result?.sessions) ? result.sessions : [];
};
@@ -136,11 +136,11 @@ export function createSessionsSendTool(opts?: {
};
let resolvedKey = "";
try {
const resolved = (await callGateway({
const resolved = await callGateway({
method: "sessions.resolve",
params: resolveParams,
timeoutMs: 10_000,
})) as { key?: unknown };
});
resolvedKey = typeof resolved?.key === "string" ? resolved.key.trim() : "";
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
@@ -283,11 +283,11 @@ export function createSessionsSendTool(opts?: {
if (timeoutSeconds === 0) {
try {
const response = (await callGateway({
const response = await callGateway({
method: "agent",
params: sendParams,
timeoutMs: 10_000,
})) as { runId?: string; acceptedAt?: number };
});
if (typeof response?.runId === "string" && response.runId) {
runId = response.runId;
}
@@ -311,11 +311,11 @@ export function createSessionsSendTool(opts?: {
}
try {
const response = (await callGateway({
const response = await callGateway({
method: "agent",
params: sendParams,
timeoutMs: 10_000,
})) as { runId?: string; acceptedAt?: number };
});
if (typeof response?.runId === "string" && response.runId) {
runId = response.runId;
}
@@ -333,14 +333,14 @@ export function createSessionsSendTool(opts?: {
let waitStatus: string | undefined;
let waitError: string | undefined;
try {
const wait = (await callGateway({
const wait = await callGateway({
method: "agent.wait",
params: {
runId,
timeoutMs,
},
timeoutMs: timeoutMs + 2000,
})) as { status?: string; error?: string };
});
waitStatus = typeof wait?.status === "string" ? wait.status : undefined;
waitError = typeof wait?.error === "string" ? wait.error : undefined;
} catch (err) {
@@ -371,10 +371,10 @@ export function createSessionsSendTool(opts?: {
});
}
const history = (await callGateway({
const history = await callGateway({
method: "chat.history",
params: { sessionKey: resolvedKey, limit: 50 },
})) as { messages?: unknown[] };
});
const filtered = stripToolMessages(Array.isArray(history?.messages) ? history.messages : []);
const last = filtered.length > 0 ? filtered[filtered.length - 1] : undefined;
const reply = last ? extractAssistantText(last) : undefined;

View File

@@ -84,9 +84,7 @@ export function createSessionsSpawnTool(opts?: {
const modelOverride = readStringParam(params, "model");
const thinkingOverrideRaw = readStringParam(params, "thinking");
const cleanup =
params.cleanup === "keep" || params.cleanup === "delete"
? (params.cleanup as "keep" | "delete")
: "keep";
params.cleanup === "keep" || params.cleanup === "delete" ? params.cleanup : "keep";
const requesterOrigin = normalizeDeliveryContext({
channel: opts?.agentChannel,
accountId: opts?.agentAccountId,
@@ -211,7 +209,7 @@ export function createSessionsSpawnTool(opts?: {
const childIdem = crypto.randomUUID();
let childRunId: string = childIdem;
try {
const response = (await callGateway({
const response = await callGateway({
method: "agent",
params: {
message: task,
@@ -230,7 +228,7 @@ export function createSessionsSpawnTool(opts?: {
groupSpace: opts?.agentGroupSpace ?? undefined,
},
timeoutMs: 10_000,
})) as { runId?: string };
});
if (typeof response?.runId === "string" && response.runId) {
childRunId = response.runId;
}