Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ To test your code changes with Gemini CLI you can run:

```bash
gemini extensions uninstall google-workspace
npm run build
npm install && npm run build
gemini extensions link .
gemini extensions list
gemini --debug
Expand Down
25 changes: 25 additions & 0 deletions workspace-server/src/__tests__/services/DriveService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,31 @@ describe('DriveService', () => {

expect(JSON.parse(result.content[0].text)).toEqual({ error: 'API request failed' });
});

describe('createFolder', () => {
it('should create a folder with the correct parameters', async () => {
const folderName = 'Test Folder';
const parentFolderId = 'parent-id';
const mockFilesCreate = jest.fn().mockResolvedValue({
data: { id: 'new-folder-id' }
} as never);
(google.drive as jest.Mock).mockReturnValue({
files: {
create: mockFilesCreate
}
});
const response = await driveService.createFolder({ folderName, parentFolderId });
expect(mockFilesCreate).toHaveBeenCalledWith({
requestBody: {
name: folderName,
mimeType: 'application/vnd.google-apps.folder',
parents: [parentFolderId]
},
fields: 'id'
});
expect(response.content[0].text).toEqual(JSON.stringify({ id: 'new-folder-id' }));
});
});
});

describe('search', () => {
Expand Down
12 changes: 12 additions & 0 deletions workspace-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ async function main() {
driveService.findFolder
);

server.registerTool(
"drive.createFolder",
{
description: 'Creates a new folder in Google Drive.',
inputSchema: {
folderName: z.string().describe('The name of the folder to create.'),
parentFolderId: z.string().optional().describe('The ID of the parent folder.'),
}
},
driveService.createFolder
);

server.registerTool(
"docs.move",
{
Expand Down
32 changes: 32 additions & 0 deletions workspace-server/src/services/DriveService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,38 @@ export class DriveService {
}
}

public createFolder = async ({ folderName, parentFolderId }: { folderName: string, parentFolderId?: string }) => {
logToFile(`Creating folder with name: ${folderName}`);
try {
const drive = await this.getDriveClient();
const fileMetadata = {
'name': folderName,
'mimeType': 'application/vnd.google-apps.folder',
parents: parentFolderId ? [parentFolderId] : []
};
const file = await drive.files.create({
requestBody: fileMetadata,
fields: 'id'
});
logToFile(`Created folder with ID: ${file.data.id}`);
return {
content: [{
type: "text" as const,
text: JSON.stringify(file.data)
}]
};
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
logToFile(`Error during drive.createFolder: ${errorMessage}`);
return {
content: [{
type: "text" as const,
text: JSON.stringify({ error: errorMessage })
}]
};
}
}

public search = async ({ query, pageSize = 10, pageToken, corpus, unreadOnly, sharedWithMe }: { query?: string, pageSize?: number, pageToken?: string, corpus?: string, unreadOnly?: boolean, sharedWithMe?: boolean }) => {
const drive = await this.getDriveClient();
let q = query;
Expand Down