mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-03 19:03:21 +00:00
fix: Better formatting of truncated output strings (#42)
* fix: Better formatting of truncated output strings * cr
This commit is contained in:
parent
2381e9f703
commit
0fbcaa3131
1 changed files with 15 additions and 1 deletions
|
|
@ -1,3 +1,7 @@
|
||||||
|
import { createLogger, LogLevel } from "./logger.js";
|
||||||
|
|
||||||
|
const logger = createLogger(LogLevel.INFO, "TruncateOutputs");
|
||||||
|
|
||||||
export function truncateOutput(
|
export function truncateOutput(
|
||||||
output: string,
|
output: string,
|
||||||
options?: {
|
options?: {
|
||||||
|
|
@ -28,9 +32,19 @@ export function truncateOutput(
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.warn(
|
||||||
|
`Truncating output due to its length exceeding the maximum allowed characters. Received ${output.length} characters, but only ${numStartCharacters + numEndCharacters} were allowed.`,
|
||||||
|
{
|
||||||
|
numAllowedStartCharacters: numStartCharacters,
|
||||||
|
numAllowedEndCharacters: numEndCharacters,
|
||||||
|
outputLength: output.length,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
`The following output was truncated due to its length exceeding the maximum allowed characters. Received ${output.length} characters, but only ${numStartCharacters + numEndCharacters} were allowed.\n\n` +
|
||||||
output.slice(0, numStartCharacters) +
|
output.slice(0, numStartCharacters) +
|
||||||
`\n... Output too long. Truncated the middle ${output.length - numStartCharacters - numEndCharacters} characters of the output ...\n` +
|
`\n\n... [content truncated] ...\n\n` +
|
||||||
output.slice(-numEndCharacters)
|
output.slice(-numEndCharacters)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue