Skip to content

Commit f5cd982

Browse files
committed
prettier
1 parent b2e75ea commit f5cd982

File tree

6 files changed

+79
-72
lines changed

6 files changed

+79
-72
lines changed

apps/sandbox-container/container/fileUtils.spec.ts

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import mime from "mime"
2-
import mock from "mock-fs"
1+
import mime from 'mime'
2+
import mock from 'mock-fs'
33
import { afterEach, describe, expect, it, vi } from 'vitest'
4+
45
import { get_file_name_from_path, get_mime_type, list_files_in_directory } from './fileUtils'
56

67
vi.mock('mime', () => {
7-
return{
8+
return {
89
default: {
9-
getType: vi.fn()
10-
}
10+
getType: vi.fn(),
11+
},
1112
}
1213
})
1314

1415
afterEach(async () => {
1516
mock.restore()
16-
vi.restoreAllMocks();
17+
vi.restoreAllMocks()
1718
})
1819

1920
describe('get_file_name_from_path', () => {
@@ -30,49 +31,49 @@ describe('get_file_name_from_path', () => {
3031
expect(path).toBe('/birds')
3132
})
3233
}),
33-
describe('list_files_in_directory', () => {
34-
it('lists the files in a directory', async () => {
35-
mock({
36-
testDir: {
37-
"cats": "aurora, luna",
38-
"dogs": "penny",
39-
}
40-
})
41-
const listFiles = await list_files_in_directory("testDir")
42-
expect(listFiles).toEqual(["file:///testDir/cats", "file:///testDir/dogs"])
34+
describe('list_files_in_directory', () => {
35+
it('lists the files in a directory', async () => {
36+
mock({
37+
testDir: {
38+
cats: 'aurora, luna',
39+
dogs: 'penny',
40+
},
41+
})
42+
const listFiles = await list_files_in_directory('testDir')
43+
expect(listFiles).toEqual(['file:///testDir/cats', 'file:///testDir/dogs'])
44+
}),
45+
it('throws an error if path is not a directory', async () => {
46+
mock({
47+
testDir: {
48+
cats: 'aurora, luna',
49+
dogs: 'penny',
50+
},
51+
})
52+
await expect(async () => await list_files_in_directory('testDir/cats')).rejects.toThrow(
53+
'Failed to read directory'
54+
)
55+
}),
56+
it('treats empty strings as cwd', async () => {
57+
mock({
58+
testDir: {
59+
cats: 'aurora, luna',
60+
dogs: 'penny',
61+
},
62+
})
63+
64+
const listFiles = await list_files_in_directory('')
65+
expect(listFiles).toEqual(['file:///../../../../../../testDir'])
66+
})
4367
}),
44-
it('throws an error if path is not a directory', async () => {
45-
mock({
46-
testDir: {
47-
"cats": "aurora, luna",
48-
"dogs": "penny",
49-
}
68+
describe('get_mime_type', async () => {
69+
it("provides the natural mime type when not 'inode/directory'", async () => {
70+
vi.mocked(mime.getType).mockReturnValueOnce('theType')
71+
const mimeType = await get_mime_type('someFile')
72+
expect(mimeType).toEqual('theType')
5073
})
51-
await expect(async () => await list_files_in_directory("testDir/cats")).rejects.toThrow("Failed to read directory")
52-
}),
53-
it('treats empty strings as cwd', async () => {
54-
mock({
55-
testDir: {
56-
"cats": "aurora, luna",
57-
"dogs": "penny",
58-
}
74+
it("overrides mime type for 'inode/directory'", async () => {
75+
vi.mocked(mime.getType).mockReturnValueOnce('inode/directory')
76+
const mimeType = await get_mime_type('someDirectory')
77+
expect(mimeType).toEqual('text/directory')
5978
})
60-
61-
const listFiles = await list_files_in_directory("")
62-
expect(listFiles).toEqual(["file:///../../../../../../testDir"])
63-
})
64-
}),
65-
describe("get_mime_type", async () => {
66-
it("provides the natural mime type when not 'inode/directory'", async () => {
67-
vi.mocked(mime.getType).mockReturnValueOnce("theType")
68-
const mimeType = await get_mime_type("someFile")
69-
expect(mimeType).toEqual("theType")
7079
})
71-
it("overrides mime type for 'inode/directory'", async () => {
72-
vi.mocked(mime.getType).mockReturnValueOnce("inode/directory")
73-
const mimeType = await get_mime_type("someDirectory")
74-
expect(mimeType).toEqual("text/directory")
75-
})
76-
}
77-
)
78-
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import mime from 'mime';
2-
import * as fs from 'node:fs/promises';
3-
import path from 'node:path';
1+
import * as fs from 'node:fs/promises'
2+
import path from 'node:path'
3+
import mime from 'mime'
44

55
// this is because there isn't a "real" directory mime type, so we're reusing the "text/directory" mime type
66
// so claude doesn't give an error
7-
export const DIRECTORY_CONTENT_TYPE = 'text/directory';
7+
export const DIRECTORY_CONTENT_TYPE = 'text/directory'
88

99
export async function get_file_name_from_path(path: string): Promise<string> {
1010
path = path.replace('/files/contents', '')
@@ -13,7 +13,7 @@ export async function get_file_name_from_path(path: string): Promise<string> {
1313
return path
1414
}
1515

16-
export async function list_files_in_directory(dirPath: string): Promise<string[]>{
16+
export async function list_files_in_directory(dirPath: string): Promise<string[]> {
1717
const files: string[] = []
1818
try {
1919
const dir = await fs.readdir(path.join(process.cwd(), dirPath), {
@@ -23,17 +23,17 @@ export async function list_files_in_directory(dirPath: string): Promise<string[]
2323
const relPath = path.relative(process.cwd(), `${dirPath}/${dirent.name}`)
2424
files.push(`file:///${relPath}`)
2525
}
26-
} catch(error) {
27-
throw new Error('Failed to read directory');
26+
} catch (error) {
27+
throw new Error('Failed to read directory')
2828
}
29-
29+
3030
return files
3131
}
3232

33-
export async function get_mime_type(path: string): Promise<string | null>{
33+
export async function get_mime_type(path: string): Promise<string | null> {
3434
let mimeType = mime.getType(path)
35-
if (mimeType && (mimeType === 'inode/directory')) {
35+
if (mimeType && mimeType === 'inode/directory') {
3636
mimeType = DIRECTORY_CONTENT_TYPE
3737
}
3838
return mimeType
39-
}
39+
}

apps/sandbox-container/container/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
import { exec } from 'node:child_process'
2+
import * as fs from 'node:fs/promises'
3+
import path from 'node:path'
14
import { serve } from '@hono/node-server'
25
import { zValidator } from '@hono/zod-validator'
36
import { Hono } from 'hono'
47
import { streamText } from 'hono/streaming'
58
import mime from 'mime'
6-
import { exec } from 'node:child_process'
7-
import * as fs from 'node:fs/promises'
8-
import path from 'node:path'
99

1010
import { ExecParams, FilesWrite } from '../shared/schema.ts'
11-
import { DIRECTORY_CONTENT_TYPE, get_file_name_from_path, get_mime_type, list_files_in_directory } from './fileUtils.ts'
11+
import {
12+
DIRECTORY_CONTENT_TYPE,
13+
get_file_name_from_path,
14+
get_mime_type,
15+
list_files_in_directory,
16+
} from './fileUtils.ts'
1217

1318
import type { FileList } from '../shared/schema.ts'
1419

@@ -65,7 +70,7 @@ app.get('/files/ls', async (c) => {
6570
app.get('/files/contents/*', async (c) => {
6671
const reqPath = await get_file_name_from_path(c.req.path)
6772
try {
68-
const mimeType = await get_mime_type(reqPath)
73+
const mimeType = await get_mime_type(reqPath)
6974
const headers = mimeType ? { 'Content-Type': mimeType } : undefined
7075
const contents = await fs.readFile(path.join(process.cwd(), reqPath))
7176
return c.newResponse(contents, 200, headers)

apps/sandbox-container/server/containerMcp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { getContainerManager } from './containerManager'
88
import { BASE_INSTRUCTIONS } from './prompts'
99
import { fileToBase64, stripProtocolFromFilePath } from './utils'
1010

11-
import type { Env, Props } from '.'
1211
import type { FileList } from '../shared/schema'
12+
import type { Env, Props } from '.'
1313

1414
export class ContainerMcpAgent extends McpAgent<Env, Props> {
1515
server = new McpServer(
@@ -124,7 +124,7 @@ export class ContainerMcpAgent extends McpAgent<Env, Props> {
124124
const path = await stripProtocolFromFilePath(args.path)
125125
const { blob, mimeType } = await this.container_file_read(path)
126126

127-
if (mimeType && (mimeType.startsWith('text'))) {
127+
if (mimeType && mimeType.startsWith('text')) {
128128
return {
129129
content: [
130130
{
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { describe, expect, it } from 'vitest'
2+
23
import { stripProtocolFromFilePath } from './utils'
34

45
describe('get_file_name_from_path', () => {
56
it('strips file:// protocol from path', async () => {
67
const path = await stripProtocolFromFilePath('file:///files/contents/cats')
78
expect(path).toBe('/files/contents/cats')
89
}),
9-
it('leaves protocol-less paths untouched', async () => {
10-
const path = await stripProtocolFromFilePath('/files/contents/cats')
11-
expect(path).toBe('/files/contents/cats')
12-
})
13-
})
10+
it('leaves protocol-less paths untouched', async () => {
11+
const path = await stripProtocolFromFilePath('/files/contents/cats')
12+
expect(path).toBe('/files/contents/cats')
13+
})
14+
})

apps/sandbox-container/shared/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const FilesWrite = z.object({
1515

1616
export type FilePathParam = z.infer<typeof FilePathParam>
1717
export const FilePathParam = z.object({
18-
path: z.string()
18+
path: z.string(),
1919
})
2020

2121
export type FileList = z.infer<typeof FileList>

0 commit comments

Comments
 (0)