Skip to content

Commit 0b6b66c

Browse files
refactor: convert QuickJSSandbox.create, SandboxManager methods to use object parameters
🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 245a988 commit 0b6b66c

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

backend/src/util/messages.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ export function castAssistantMessage(message: Message): Message | null {
9595
// Number of terminal command outputs to keep in full form before simplifying
9696
const numTerminalCommandsToKeep = 5
9797

98-
function simplifyTerminalHelper(
99-
toolResult: CodebuffToolOutput<'run_terminal_command'>,
100-
numKept: number,
101-
): { result: CodebuffToolOutput<'run_terminal_command'>; numKept: number } {
98+
function simplifyTerminalHelper(params: {
99+
toolResult: CodebuffToolOutput<'run_terminal_command'>
100+
numKept: number
101+
}): { result: CodebuffToolOutput<'run_terminal_command'>; numKept: number } {
102+
const { toolResult, numKept } = params
102103
const simplified = simplifyTerminalCommandResults(toolResult)
103104

104105
// Keep the full output for the N most recent commands
@@ -165,10 +166,10 @@ export function trimMessagesToFitTokenLimit(
165166
m,
166167
) as CodebuffToolMessage<'run_terminal_command'>
167168

168-
const result = simplifyTerminalHelper(
169-
terminalResultMessage.content.output,
169+
const result = simplifyTerminalHelper({
170+
toolResult: terminalResultMessage.content.output,
170171
numKept,
171-
)
172+
})
172173
terminalResultMessage.content.output = result.result
173174
numKept = result.numKept
174175

backend/src/util/quickjs-sandbox.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,18 @@ export class QuickJSSandbox {
4848
/**
4949
* Create a new QuickJS sandbox with the specified configuration
5050
*/
51-
static async create(
52-
generatorCode: string,
53-
initialInput: any,
54-
config: SandboxConfig = {},
51+
static async create(params: {
52+
generatorCode: string
53+
initialInput: any
54+
config?: SandboxConfig
5555
logger?: {
5656
debug: (data: any, msg?: string) => void
5757
info: (data: any, msg?: string) => void
5858
warn: (data: any, msg?: string) => void
5959
error: (data: any, msg?: string) => void
60-
},
61-
): Promise<QuickJSSandbox> {
60+
}
61+
}): Promise<QuickJSSandbox> {
62+
const { generatorCode, initialInput, config = {}, logger } = params
6263
const {
6364
memoryLimit = 1024 * 1024 * 20, // 20MB
6465
maxStackSize = 1024 * 512, // 512KB
@@ -285,12 +286,12 @@ export class SandboxManager {
285286
}
286287

287288
// Create new sandbox
288-
const sandbox = await QuickJSSandbox.create(
289+
const sandbox = await QuickJSSandbox.create({
289290
generatorCode,
290291
initialInput,
291292
config,
292293
logger,
293-
)
294+
})
294295
this.sandboxes.set(runId, sandbox)
295296
return sandbox
296297
}

0 commit comments

Comments
 (0)