mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-02 17:53:15 +00:00
fix: process inputs of traceable with circular json (#343)
This commit is contained in:
parent
942bc5ca1d
commit
d7b48c1179
3 changed files with 36 additions and 22 deletions
|
|
@ -216,7 +216,8 @@ export async function initializeSandbox(
|
||||||
try {
|
try {
|
||||||
sandbox = await daytonaClient().create(DEFAULT_SANDBOX_CREATE_PARAMS);
|
sandbox = await daytonaClient().create(DEFAULT_SANDBOX_CREATE_PARAMS);
|
||||||
emitStepEvent(baseCreateSandboxAction, "success");
|
emitStepEvent(baseCreateSandboxAction, "success");
|
||||||
} catch {
|
} catch (e) {
|
||||||
|
logger.error("Failed to create sandbox environment", { e });
|
||||||
emitStepEvent(
|
emitStepEvent(
|
||||||
baseCreateSandboxAction,
|
baseCreateSandboxAction,
|
||||||
"error",
|
"error",
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,9 @@ export function createApplyPatchTool(state: GraphState) {
|
||||||
const sandbox = await daytonaClient().get(sandboxSessionId);
|
const sandbox = await daytonaClient().get(sandboxSessionId);
|
||||||
|
|
||||||
const { success: readFileSuccess, output: readFileOutput } =
|
const { success: readFileSuccess, output: readFileOutput } =
|
||||||
await readFile(sandbox, file_path, {
|
await readFile({
|
||||||
|
sandbox,
|
||||||
|
filePath: file_path,
|
||||||
workDir,
|
workDir,
|
||||||
});
|
});
|
||||||
if (!readFileSuccess) {
|
if (!readFileSuccess) {
|
||||||
|
|
@ -84,7 +86,10 @@ export function createApplyPatchTool(state: GraphState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { success: writeFileSuccess, output: writeFileOutput } =
|
const { success: writeFileSuccess, output: writeFileOutput } =
|
||||||
await writeFile(sandbox, file_path, patchedContent, {
|
await writeFile({
|
||||||
|
sandbox,
|
||||||
|
filePath: file_path,
|
||||||
|
content: patchedContent,
|
||||||
workDir,
|
workDir,
|
||||||
});
|
});
|
||||||
if (!writeFileSuccess) {
|
if (!writeFileSuccess) {
|
||||||
|
|
|
||||||
|
|
@ -33,20 +33,19 @@ async function handleCreateFile(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function readFileFunc(
|
async function readFileFunc(inputs: {
|
||||||
sandbox: Sandbox,
|
sandbox: Sandbox;
|
||||||
filePath: string,
|
filePath: string;
|
||||||
args?: {
|
workDir?: string;
|
||||||
workDir?: string;
|
}): Promise<{
|
||||||
},
|
|
||||||
): Promise<{
|
|
||||||
success: boolean;
|
success: boolean;
|
||||||
output: string;
|
output: string;
|
||||||
}> {
|
}> {
|
||||||
|
const { sandbox, filePath, workDir } = inputs;
|
||||||
try {
|
try {
|
||||||
const readOutput = await sandbox.process.executeCommand(
|
const readOutput = await sandbox.process.executeCommand(
|
||||||
`cat "${filePath}"`,
|
`cat "${filePath}"`,
|
||||||
args?.workDir,
|
workDir,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (readOutput.exitCode !== 0) {
|
if (readOutput.exitCode !== 0) {
|
||||||
|
|
@ -65,7 +64,9 @@ async function readFileFunc(
|
||||||
};
|
};
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (e instanceof Error && e.message.includes("No such file or directory")) {
|
if (e instanceof Error && e.message.includes("No such file or directory")) {
|
||||||
const createOutput = await handleCreateFile(sandbox, filePath, args);
|
const createOutput = await handleCreateFile(sandbox, filePath, {
|
||||||
|
workDir,
|
||||||
|
});
|
||||||
if (createOutput.exitCode !== 0) {
|
if (createOutput.exitCode !== 0) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
|
|
@ -73,7 +74,7 @@ async function readFileFunc(
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// If the file was created successfully, try reading it again.
|
// If the file was created successfully, try reading it again.
|
||||||
return readFile(sandbox, filePath, args);
|
return readFile(inputs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,19 +107,22 @@ async function readFileFunc(
|
||||||
|
|
||||||
export const readFile = traceable(readFileFunc, {
|
export const readFile = traceable(readFileFunc, {
|
||||||
name: "read_file",
|
name: "read_file",
|
||||||
|
processInputs: (inputs) => {
|
||||||
|
const { sandbox: _sandbox, ...rest } = inputs;
|
||||||
|
return rest;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
async function writeFileFunc(
|
async function writeFileFunc(inputs: {
|
||||||
sandbox: Sandbox,
|
sandbox: Sandbox;
|
||||||
filePath: string,
|
filePath: string;
|
||||||
content: string,
|
content: string;
|
||||||
args?: {
|
workDir?: string;
|
||||||
workDir?: string;
|
}): Promise<{
|
||||||
},
|
|
||||||
): Promise<{
|
|
||||||
success: boolean;
|
success: boolean;
|
||||||
output: string;
|
output: string;
|
||||||
}> {
|
}> {
|
||||||
|
const { sandbox, filePath, content, workDir } = inputs;
|
||||||
try {
|
try {
|
||||||
const delimiter = "EOF_" + Date.now() + "_" + Math.random().toString(36);
|
const delimiter = "EOF_" + Date.now() + "_" + Math.random().toString(36);
|
||||||
const writeCommand = `cat > "${filePath}" << '${delimiter}'
|
const writeCommand = `cat > "${filePath}" << '${delimiter}'
|
||||||
|
|
@ -126,7 +130,7 @@ ${content}
|
||||||
${delimiter}`;
|
${delimiter}`;
|
||||||
const writeOutput = await sandbox.process.executeCommand(
|
const writeOutput = await sandbox.process.executeCommand(
|
||||||
writeCommand,
|
writeCommand,
|
||||||
args?.workDir,
|
workDir,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (writeOutput.exitCode !== 0) {
|
if (writeOutput.exitCode !== 0) {
|
||||||
|
|
@ -169,4 +173,8 @@ ${delimiter}`;
|
||||||
|
|
||||||
export const writeFile = traceable(writeFileFunc, {
|
export const writeFile = traceable(writeFileFunc, {
|
||||||
name: "write_file",
|
name: "write_file",
|
||||||
|
processInputs: (inputs) => {
|
||||||
|
const { sandbox: _sandbox, ...rest } = inputs;
|
||||||
|
return rest;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue