mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 01:31:08 +00:00
style: apply formatter drift
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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", {
|
||||
|
||||
@@ -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<SavedMedia[]> {
|
||||
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<string, unknown> | undefined;
|
||||
if (combinedReply) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -44,11 +44,11 @@ type ChatRefreshHost = AppViewState & {
|
||||
updateComplete?: Promise<unknown>;
|
||||
};
|
||||
|
||||
export function resolveAssistantAttachmentAuthToken(state: Pick<AppViewState, "settings" | "password">) {
|
||||
export function resolveAssistantAttachmentAuthToken(
|
||||
state: Pick<AppViewState, "settings" | "password">,
|
||||
) {
|
||||
return (
|
||||
normalizeOptionalString(state.settings.token) ??
|
||||
normalizeOptionalString(state.password) ??
|
||||
null
|
||||
normalizeOptionalString(state.settings.token) ?? normalizeOptionalString(state.password) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 } : {}),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user