Skip to content

Commit eba404c

Browse files
Update to newer sessionFs APIs
1 parent 57d2b87 commit eba404c

1 file changed

Lines changed: 22 additions & 16 deletions

File tree

app/src/api/sandbox.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CopilotSession, SessionConfig, SessionFsConfig, SessionFsHandler } from "@github/copilot-sdk";
1+
import { CopilotSession, SessionConfig, SessionFsConfig, SessionFsProvider } from "@github/copilot-sdk";
22
import { Bash, IFileSystem } from "just-bash";
33
import { createBash } from "./bash";
44
import { StorageProvider } from "./storage/storageProvider";
@@ -13,7 +13,7 @@ export function createSandbox(sessionId: string, storage: StorageProvider): { ba
1313
const sessionConfig: Partial<SessionConfig> = {
1414
availableTools: ["report_intent", "list_agents", "read_agent", "write_agent", "multi_tool_use.parallel", "web_fetch", ...bashTools.map(t => t.name)],
1515
tools: [...bashTools],
16-
createSessionFsHandler: session => createSessionFsHandler(session, fs),
16+
createSessionFsHandler: session => createSessionFsProvider(session, fs),
1717
systemMessage: {
1818
mode: "customize",
1919
sections: {
@@ -62,15 +62,22 @@ export const sessionFsConfig: SessionFsConfig = {
6262
};
6363

6464
// An adapter from a just-bash IFileSystem to the Copilot runtime SessionFsConfig interface
65-
function createSessionFsHandler(session: CopilotSession, fileSystem: IFileSystem): SessionFsHandler {
65+
function createSessionFsProvider(session: CopilotSession, fileSystem: IFileSystem): SessionFsProvider {
6666
return {
67-
readFile: async ({ path }) => ({ content: await fileSystem.readFile(path) }),
68-
writeFile: ({ path, content }) => fileSystem.writeFile(path, content),
69-
appendFile: ({ path, content }) => {
70-
return fileSystem.appendFile(path, content);
67+
readFile: async (path) => {
68+
// The just-bash fs doesn't throw Node-style exceptions so we need to do that manually
69+
if (!await fileSystem.exists(path)) {
70+
const ex = new Error(`ENOENT: no such file or directory, open '${path}'`) as NodeJS.ErrnoException;
71+
ex.code = "ENOENT";
72+
ex.path = path;
73+
throw ex;
74+
}
75+
return fileSystem.readFile(path);
7176
},
72-
exists: async ({ path }) => ({ exists: await fileSystem.exists(path) }),
73-
stat: async ({ path }) => {
77+
writeFile: (path, content) => fileSystem.writeFile(path, content),
78+
appendFile: (path, content) => fileSystem.appendFile(path, content),
79+
exists: (path) => fileSystem.exists(path),
80+
stat: async (path) => {
7481
const st = await fileSystem.stat(path);
7582
return {
7683
isFile: st.isFile,
@@ -80,19 +87,18 @@ function createSessionFsHandler(session: CopilotSession, fileSystem: IFileSystem
8087
birthtime: st.mtime.toISOString(),
8188
};
8289
},
83-
mkdir: ({ path, recursive }) => fileSystem.mkdir(path, { recursive }),
84-
readdir: async ({ path }) => ({ entries: await fileSystem.readdir(path), }),
85-
readdirWithTypes: async ({ path }) => {
90+
mkdir: (path, recursive) => fileSystem.mkdir(path, { recursive }),
91+
readdir: (path) => fileSystem.readdir(path),
92+
readdirWithTypes: async (path) => {
8693
const names = await fileSystem.readdir(path);
87-
const entries = await Promise.all(
94+
return await Promise.all(
8895
names.map(async (name) => {
8996
const st = await fileSystem.stat(`${path}/${name}`);
9097
return { name, type: st.isDirectory ? "directory" as const : "file" as const };
9198
}),
9299
);
93-
return { entries };
94100
},
95-
rm: ({ path, recursive, force }) => fileSystem.rm(path, { recursive, force }),
96-
rename: ({ src, dest }) => fileSystem.mv(src, dest),
101+
rm: (path, recursive, force) => fileSystem.rm(path, { recursive, force }),
102+
rename: (src, dest) => fileSystem.mv(src, dest),
97103
};
98104
}

0 commit comments

Comments
 (0)