fix: preserve input file whitespace

This commit is contained in:
Frank Yang
2026-04-05 00:39:46 +08:00
parent bfdb61b33a
commit b03520f81b
2 changed files with 37 additions and 3 deletions

View File

@@ -466,8 +466,42 @@ describe("OpenResponses HTTP API (e2e)", () => {
(optsInputFile as { extraSystemPrompt?: string } | undefined)?.extraSystemPrompt ?? "";
expect(inputFileMessage).toBe("read this");
expect(inputFilePrompt).toContain('<file name="hello.txt">');
expect(inputFilePrompt).toContain('<<<EXTERNAL_UNTRUSTED_CONTENT id="');
expect(inputFilePrompt).toContain("Source: External");
await ensureResponseConsumed(resInputFile);
mockAgentOnce([{ text: "ok" }]);
const resInputFileWhitespace = await postResponses(port, {
model: "openclaw",
input: [
{
type: "message",
role: "user",
content: [
{ type: "input_text", text: "read this" },
{
type: "input_file",
source: {
type: "base64",
media_type: "text/plain",
data: Buffer.from(" hello ").toString("base64"),
filename: "spaces.txt",
},
},
],
},
],
});
expect(resInputFileWhitespace.status).toBe(200);
const optsInputFileWhitespace = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
const inputFileWhitespacePrompt =
(optsInputFileWhitespace as { extraSystemPrompt?: string } | undefined)
?.extraSystemPrompt ?? "";
expect(inputFileWhitespacePrompt).toContain('<file name="spaces.txt">');
expect(inputFileWhitespacePrompt).toContain("\n hello \n");
expect(inputFileWhitespacePrompt).toContain('<<<EXTERNAL_UNTRUSTED_CONTENT id="');
await ensureResponseConsumed(resInputFileWhitespace);
mockAgentOnce([{ text: "ok" }]);
const resInputFileInjection = await postResponses(port, {
model: "openclaw",

View File

@@ -602,12 +602,12 @@ export async function handleOpenResponsesHttpRequest(
},
limits: limits.files,
});
const text = file.text?.trim();
if (text) {
const rawText = file.text;
if (rawText?.trim()) {
fileContexts.push(
renderFileContextBlock({
filename: file.filename,
content: wrapUntrustedFileContent(text),
content: wrapUntrustedFileContent(rawText),
}),
);
} else if (file.images && file.images.length > 0) {