From 85fa33d9d7e132dd51d36db4e2a6a8d2acf62621 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 11 Apr 2026 14:05:51 +0100 Subject: [PATCH] style: apply formatter drift --- src/commands/health.ts | 2 +- src/gateway/control-ui.http.test.ts | 106 +++++++++--------- .../chat.directive-tags.test.ts | 11 +- src/gateway/server-methods/chat.ts | 19 ++-- .../server/ws-connection/message-handler.ts | 2 +- ui/src/ui/app-render.helpers.ts | 8 +- ui/src/ui/chat/message-normalizer.ts | 10 +- ui/src/ui/views/chat.test.ts | 2 +- 8 files changed, 79 insertions(+), 81 deletions(-) diff --git a/src/commands/health.ts b/src/commands/health.ts index 2444888cbfa..5f51d8c51d6 100644 --- a/src/commands/health.ts +++ b/src/commands/health.ts @@ -5,8 +5,8 @@ import type { ChannelPlugin } from "../channels/plugins/types.plugin.js"; import type { ChannelAccountSnapshot } from "../channels/plugins/types.public.js"; import { inspectReadOnlyChannelAccount } from "../channels/read-only-account-inspect.js"; import { withProgress } from "../cli/progress.js"; -import type { OpenClawConfig } from "../config/types.openclaw.js"; import { resolveStorePath } from "../config/sessions/paths.js"; +import type { OpenClawConfig } from "../config/types.openclaw.js"; import { buildGatewayConnectionDetails, callGateway } from "../gateway/call.js"; import { info } from "../globals.js"; import { isTruthyEnvValue } from "../infra/env.js"; diff --git a/src/gateway/control-ui.http.test.ts b/src/gateway/control-ui.http.test.ts index 925339f822f..c48a0d7134b 100644 --- a/src/gateway/control-ui.http.test.ts +++ b/src/gateway/control-ui.http.test.ts @@ -4,6 +4,7 @@ import type { IncomingMessage } from "node:http"; import os from "node:os"; import path from "node:path"; import { describe, expect, it } from "vitest"; +import { resolvePreferredOpenClawTmpDir } from "../infra/tmp-openclaw-dir.js"; import type { ResolvedGatewayAuth } from "./auth.js"; import { CONTROL_UI_BOOTSTRAP_CONFIG_PATH } from "./control-ui-contract.js"; import { @@ -11,7 +12,6 @@ import { handleControlUiAvatarRequest, handleControlUiHttpRequest, } from "./control-ui.js"; -import { resolvePreferredOpenClawTmpDir } from "../infra/tmp-openclaw-dir.js"; import { makeMockHttpResponse } from "./test-http-response.js"; describe("handleControlUiHttpRequest", () => { @@ -182,15 +182,15 @@ describe("handleControlUiHttpRequest", () => { await withAllowedAssistantMediaRoot({ prefix: "ui-media-", fn: async (tmpRoot) => { - const filePath = path.join(tmpRoot, "photo.png"); - await fs.writeFile(filePath, Buffer.from("not-a-real-png")); - const { res, handled } = await runAssistantMediaRequest({ - url: `/__openclaw__/assistant-media?source=${encodeURIComponent(filePath)}&token=test-token`, - method: "GET", - auth: { mode: "token", token: "test-token", allowTailscale: false }, - }); - expect(handled).toBe(true); - expect(res.statusCode).toBe(200); + const filePath = path.join(tmpRoot, "photo.png"); + await fs.writeFile(filePath, Buffer.from("not-a-real-png")); + const { res, handled } = await runAssistantMediaRequest({ + url: `/__openclaw__/assistant-media?source=${encodeURIComponent(filePath)}&token=test-token`, + method: "GET", + auth: { mode: "token", token: "test-token", allowTailscale: false }, + }); + expect(handled).toBe(true); + expect(res.statusCode).toBe(200); }, }); }); @@ -215,16 +215,16 @@ describe("handleControlUiHttpRequest", () => { await withAllowedAssistantMediaRoot({ prefix: "ui-media-meta-", fn: async (tmpRoot) => { - const filePath = path.join(tmpRoot, "photo.png"); - await fs.writeFile(filePath, Buffer.from("not-a-real-png")); - const { res, handled, end } = await runAssistantMediaRequest({ - url: `/__openclaw__/assistant-media?meta=1&source=${encodeURIComponent(filePath)}&token=test-token`, - method: "GET", - auth: { mode: "token", token: "test-token", allowTailscale: false }, - }); - expect(handled).toBe(true); - expect(res.statusCode).toBe(200); - expect(JSON.parse(String(end.mock.calls[0]?.[0] ?? ""))).toEqual({ available: true }); + const filePath = path.join(tmpRoot, "photo.png"); + await fs.writeFile(filePath, Buffer.from("not-a-real-png")); + const { res, handled, end } = await runAssistantMediaRequest({ + url: `/__openclaw__/assistant-media?meta=1&source=${encodeURIComponent(filePath)}&token=test-token`, + method: "GET", + auth: { mode: "token", token: "test-token", allowTailscale: false }, + }); + expect(handled).toBe(true); + expect(res.statusCode).toBe(200); + expect(JSON.parse(String(end.mock.calls[0]?.[0] ?? ""))).toEqual({ available: true }); }, }); }); @@ -248,16 +248,16 @@ describe("handleControlUiHttpRequest", () => { await withAllowedAssistantMediaRoot({ prefix: "ui-media-auth-", fn: async (tmpRoot) => { - const filePath = path.join(tmpRoot, "photo.png"); - await fs.writeFile(filePath, Buffer.from("not-a-real-png")); - const { res, handled, end } = await runAssistantMediaRequest({ - url: `/__openclaw__/assistant-media?source=${encodeURIComponent(filePath)}`, - method: "GET", - auth: { mode: "token", token: "test-token", allowTailscale: false }, - }); - expect(handled).toBe(true); - expect(res.statusCode).toBe(401); - expect(String(end.mock.calls[0]?.[0] ?? "")).toContain("Unauthorized"); + const filePath = path.join(tmpRoot, "photo.png"); + await fs.writeFile(filePath, Buffer.from("not-a-real-png")); + const { res, handled, end } = await runAssistantMediaRequest({ + url: `/__openclaw__/assistant-media?source=${encodeURIComponent(filePath)}`, + method: "GET", + auth: { mode: "token", token: "test-token", allowTailscale: false }, + }); + expect(handled).toBe(true); + expect(res.statusCode).toBe(401); + expect(String(end.mock.calls[0]?.[0] ?? "")).toContain("Unauthorized"); }, }); }); @@ -266,30 +266,30 @@ describe("handleControlUiHttpRequest", () => { await withAllowedAssistantMediaRoot({ prefix: "ui-media-proxy-", fn: async (tmpRoot) => { - const filePath = path.join(tmpRoot, "photo.png"); - await fs.writeFile(filePath, Buffer.from("not-a-real-png")); - const { res, handled, end } = await runAssistantMediaRequest({ - url: `/__openclaw__/assistant-media?source=${encodeURIComponent(filePath)}`, - method: "GET", - auth: { - mode: "trusted-proxy", - allowTailscale: false, - trustedProxy: { - userHeader: "x-forwarded-user", + const filePath = path.join(tmpRoot, "photo.png"); + await fs.writeFile(filePath, Buffer.from("not-a-real-png")); + const { res, handled, end } = await runAssistantMediaRequest({ + url: `/__openclaw__/assistant-media?source=${encodeURIComponent(filePath)}`, + method: "GET", + auth: { + mode: "trusted-proxy", + allowTailscale: false, + trustedProxy: { + userHeader: "x-forwarded-user", + }, }, - }, - trustedProxies: ["10.0.0.1"], - remoteAddress: "10.0.0.1", - headers: { - host: "gateway.example.com", - origin: "https://evil.example", - "x-forwarded-user": "nick@example.com", - "x-forwarded-proto": "https", - }, - }); - expect(handled).toBe(true); - expect(res.statusCode).toBe(401); - expect(String(end.mock.calls[0]?.[0] ?? "")).toContain("Unauthorized"); + trustedProxies: ["10.0.0.1"], + remoteAddress: "10.0.0.1", + headers: { + host: "gateway.example.com", + origin: "https://evil.example", + "x-forwarded-user": "nick@example.com", + "x-forwarded-proto": "https", + }, + }); + expect(handled).toBe(true); + expect(res.statusCode).toBe(401); + expect(String(end.mock.calls[0]?.[0] ?? "")).toContain("Unauthorized"); }, }); }); diff --git a/src/gateway/server-methods/chat.directive-tags.test.ts b/src/gateway/server-methods/chat.directive-tags.test.ts index a4c8166c7e7..5949d96b1ba 100644 --- a/src/gateway/server-methods/chat.directive-tags.test.ts +++ b/src/gateway/server-methods/chat.directive-tags.test.ts @@ -3,13 +3,13 @@ import os from "node:os"; import path from "node:path"; import { CURRENT_SESSION_VERSION } from "@mariozechner/pi-coding-agent"; import { afterEach, describe, expect, it, vi } from "vitest"; +import type { ModelCatalogEntry } from "../../agents/model-catalog.types.js"; import type { MsgContext } from "../../auto-reply/templating.js"; import { GATEWAY_CLIENT_CAPS, GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES, } from "../protocol/client-info.js"; -import type { ModelCatalogEntry } from "../../agents/model-catalog.types.js"; import { ErrorCodes } from "../protocol/index.js"; import { CHAT_SEND_SESSION_KEY_MAX_LENGTH } from "../protocol/schema/primitives.js"; import type { GatewayRequestContext } from "./types.js"; @@ -1754,10 +1754,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () => } | undefined; expect(message?.MediaPath).toBe("/tmp/chat-send-inline.png"); - expect(message?.MediaPaths).toEqual([ - "/tmp/chat-send-inline.png", - "/tmp/offloaded-big.png", - ]); + expect(message?.MediaPaths).toEqual(["/tmp/chat-send-inline.png", "/tmp/offloaded-big.png"]); expect(message?.MediaType).toBe("image/png"); expect(message?.MediaTypes).toEqual(["image/png", "image/png"]); }); @@ -2127,9 +2124,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () => it("does not parse or offload attachments for stop commands", async () => { createTranscriptFixture("openclaw-chat-send-stop-command-attachments-"); - mockState.savedMediaResults = [ - { path: "/tmp/should-not-exist.png", contentType: "image/png" }, - ]; + mockState.savedMediaResults = [{ path: "/tmp/should-not-exist.png", contentType: "image/png" }]; const respond = vi.fn(); const context = createChatContext(); context.chatAbortControllers.set("run-same-session", { diff --git a/src/gateway/server-methods/chat.ts b/src/gateway/server-methods/chat.ts index a6e106ece8d..717e588df75 100644 --- a/src/gateway/server-methods/chat.ts +++ b/src/gateway/server-methods/chat.ts @@ -17,12 +17,11 @@ import { isAudioFileName } from "../../media/mime.js"; import type { PromptImageOrderEntry } from "../../media/prompt-image-order.js"; import { type SavedMedia, saveMediaBuffer } from "../../media/store.js"; import { createChannelReplyPipeline } from "../../plugin-sdk/channel-reply-pipeline.js"; -import { resolveAssistantMessagePhase } from "../../shared/chat-message-content.js"; import { normalizeInputProvenance, type InputProvenance } from "../../sessions/input-provenance.js"; import { resolveSendPolicy } from "../../sessions/send-policy.js"; import { parseAgentSessionKey } from "../../sessions/session-key-utils.js"; import { emitSessionTranscriptUpdate } from "../../sessions/transcript-events.js"; -import { isSuppressedControlReplyText } from "../control-reply-text.js"; +import { resolveAssistantMessagePhase } from "../../shared/chat-message-content.js"; import { stripInlineDirectiveTagsForDisplay, stripInlineDirectiveTagsFromMessageForDisplay, @@ -45,8 +44,10 @@ import { type OffloadedRef, parseMessageWithAttachments, } from "../chat-attachments.js"; +import { MediaOffloadError } from "../chat-attachments.js"; import { stripEnvelopeFromMessage, stripEnvelopeFromMessages } from "../chat-sanitize.js"; import { augmentChatHistoryWithCliSessionImports } from "../cli-session-history.js"; +import { isSuppressedControlReplyText } from "../control-reply-text.js"; import { ADMIN_SCOPE } from "../method-scopes.js"; import { GATEWAY_CLIENT_CAPS, @@ -83,7 +84,6 @@ import type { GatewayRequestHandlerOptions, GatewayRequestHandlers, } from "./types.js"; -import { MediaOffloadError } from "../chat-attachments.js"; type TranscriptAppendResult = { ok: boolean; @@ -411,13 +411,18 @@ async function persistChatSendImages(params: { client: GatewayRequestHandlerOptions["client"]; logGateway: GatewayRequestContext["logGateway"]; }): Promise { - if ((params.images.length === 0 && params.offloadedRefs.length === 0) || isAcpBridgeClient(params.client)) { + if ( + (params.images.length === 0 && params.offloadedRefs.length === 0) || + isAcpBridgeClient(params.client) + ) { return []; } const inlineSaved: SavedMedia[] = []; for (const img of params.images) { try { - inlineSaved.push(await saveMediaBuffer(Buffer.from(img.data, "base64"), img.mimeType, "inbound")); + inlineSaved.push( + await saveMediaBuffer(Buffer.from(img.data, "base64"), img.mimeType, "inbound"), + ); } catch (err) { params.logGateway.warn( `chat.send: failed to persist inbound image (${img.mimeType}): ${formatForLog(err)}`, @@ -2158,8 +2163,8 @@ export const chatHandlers: GatewayRequestHandlers = { } else { const combinedReply = buildTranscriptReplyText( deliveredReplies - .filter((entry) => entry.kind === "final") - .map((entry) => entry.payload) + .filter((entry) => entry.kind === "final") + .map((entry) => entry.payload), ); let message: Record | undefined; if (combinedReply) { diff --git a/src/gateway/server/ws-connection/message-handler.ts b/src/gateway/server/ws-connection/message-handler.ts index 2f6e3dbe73b..2d20756f65e 100644 --- a/src/gateway/server/ws-connection/message-handler.ts +++ b/src/gateway/server/ws-connection/message-handler.ts @@ -2,7 +2,6 @@ import type { IncomingMessage } from "node:http"; import os from "node:os"; import type { WebSocket } from "ws"; import { loadConfig } from "../../../config/config.js"; -import type { ResolvedGatewayAuth } from "../../auth.js"; import { getBoundDeviceBootstrapProfile, getDeviceBootstrapTokenProfile, @@ -49,6 +48,7 @@ import { } from "../../../utils/message-channel.js"; import { resolveRuntimeServiceVersion } from "../../../version.js"; import type { AuthRateLimiter } from "../../auth-rate-limit.js"; +import type { ResolvedGatewayAuth } from "../../auth.js"; import type { GatewayAuthResult } from "../../auth.js"; import { isLocalDirectRequest } from "../../auth.js"; import { diff --git a/ui/src/ui/app-render.helpers.ts b/ui/src/ui/app-render.helpers.ts index 1f0ef24c4ef..6b713cec9e7 100644 --- a/ui/src/ui/app-render.helpers.ts +++ b/ui/src/ui/app-render.helpers.ts @@ -44,11 +44,11 @@ type ChatRefreshHost = AppViewState & { updateComplete?: Promise; }; -export function resolveAssistantAttachmentAuthToken(state: Pick) { +export function resolveAssistantAttachmentAuthToken( + state: Pick, +) { return ( - normalizeOptionalString(state.settings.token) ?? - normalizeOptionalString(state.password) ?? - null + normalizeOptionalString(state.settings.token) ?? normalizeOptionalString(state.password) ?? null ); } diff --git a/ui/src/ui/chat/message-normalizer.ts b/ui/src/ui/chat/message-normalizer.ts index 58c93da5952..eb712ddfcea 100644 --- a/ui/src/ui/chat/message-normalizer.ts +++ b/ui/src/ui/chat/message-normalizer.ts @@ -231,9 +231,9 @@ function expandTextContent(text: string): { ? (parsed.mediaUrls ?? []) .filter((url) => shouldPreserveRelativeAssistantAttachment(url)) .map((url) => ({ type: "text" as const, text: `MEDIA:${url}` })) - : replyTarget === null && !audioAsVoice && parsed.text.trim().length > 0 - ? [{ type: "text", text: parsed.text }] - : [], + : replyTarget === null && !audioAsVoice && parsed.text.trim().length > 0 + ? [{ type: "text", text: parsed.text }] + : [], audioAsVoice, replyTarget, }; @@ -312,9 +312,7 @@ export function normalizeMessage(message: unknown): NormalizedMessage { url: attachment.url, kind: attachment.kind, label: attachment.label, - ...(typeof attachment.mimeType === "string" - ? { mimeType: attachment.mimeType } - : {}), + ...(typeof attachment.mimeType === "string" ? { mimeType: attachment.mimeType } : {}), ...(attachment.isVoiceNote === true ? { isVoiceNote: true } : {}), }, }, diff --git a/ui/src/ui/views/chat.test.ts b/ui/src/ui/views/chat.test.ts index 0f75ebcd2b8..126b879b4a5 100644 --- a/ui/src/ui/views/chat.test.ts +++ b/ui/src/ui/views/chat.test.ts @@ -12,8 +12,8 @@ import { DEEPSEEK_CHAT_MODEL, DEFAULT_CHAT_MODEL_CATALOG, } from "../chat-model.test-helpers.ts"; -import { normalizeMessage } from "../chat/message-normalizer.ts"; import { resetAssistantAttachmentAvailabilityCacheForTest } from "../chat/grouped-render.ts"; +import { normalizeMessage } from "../chat/message-normalizer.ts"; import type { GatewayBrowserClient } from "../gateway.ts"; import type { ModelCatalogEntry } from "../types.ts"; import type { SessionsListResult } from "../types.ts";