Skip to content
Closed
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
58 changes: 58 additions & 0 deletions commands/people/index.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire file appears to be a hallucination. It shouldn't be here, only toml files should be in the command directory.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {
getUserProfile,
getMe,
getUserManager,
} from '../../workspace-server/src/services/PeopleService';

export const get_user_profile = {
name: 'get_user_profile',
description: 'Get a user\'s profile by ID, email, or name.',
parameters: {
type: 'object',
properties: {
userId: {
type: 'string',
description: 'The ID of the user.',
},
email: {
type: 'string',
description: 'The email address of the user.',
},
name: {
type: 'string',
description: 'The name of the user.',
},
},
},
function: getUserProfile,
};

export const get_me = {
name: 'get_me',
description: 'Get the user\'s profile.',
parameters: {
type: 'object',
properties: {},
},
function: getMe,
};

export const get_user_manager = {
name: 'get_user_manager',
description: 'Get the user\'s manager.',
parameters: {
type: 'object',
properties: {
userId: {
type: 'string',
description: 'The ID of the user.',
},
},
},
function: getUserManager,
};
31 changes: 31 additions & 0 deletions workspace-server/src/__tests__/services/PeopleService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,35 @@ describe('PeopleService', () => {
expect(JSON.parse(result.content[0].text)).toEqual({ error: 'API Error' });
});
});

describe('getUserManager', () => {
it('should return the manager of a user', async () => {
const mockManager = {
data: {
relations: [{
type: 'manager',
person: 'people/110001608645105799645',
}],
},
};
mockPeopleAPI.people.get.mockResolvedValue(mockManager);

const result = await peopleService.getUserManager({ userId: '110001608645105799644' });

expect(mockPeopleAPI.people.get).toHaveBeenCalledWith({
resourceName: 'people/110001608645105799644',
personFields: 'relations',
});
expect(JSON.parse(result.content[0].text)).toEqual({ manager: 'people/110001608645105799645' });
});

it('should handle errors during getUserManager', async () => {
const apiError = new Error('API Error');
mockPeopleAPI.people.get.mockRejectedValue(apiError);

const result = await peopleService.getUserManager({ userId: '110001608645105799644' });

expect(JSON.parse(result.content[0].text)).toEqual({ error: 'API Error' });
});
});
});
11 changes: 11 additions & 0 deletions workspace-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,17 @@ There are a list of system labels that can be modified on a message:
peopleService.getMe
);

server.registerTool(
"people.getUserManager",
{
description: 'Gets the manager for a given user.',
inputSchema: {
userId: z.string().describe('The ID of the user to get the manager for.'),
}
},
peopleService.getUserManager
);

// 4. Connect the transport layer and start listening
const transport = new StdioServerTransport();
await server.connect(transport);
Expand Down
31 changes: 30 additions & 1 deletion workspace-server/src/services/PeopleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,35 @@ export class PeopleService {
return google.people({ version: 'v1', ...options });
}

public getUserManager = async ({ userId }: { userId: string; }) => {
logToFile(`[PeopleService] Starting getUserManager with: userId=${userId}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than a specific function to get a manager, it would be better to have a function that interacts with the relations object overall. Where finding the manager could be one of many data items returned from that function.

See: https://developers.google.com/people/api/rest/v1/people#Person.Relation for the full details.

try {
const people = await this.getPeopleClient();
const resourceName = userId.startsWith('people/') ? userId : `people/${userId}`;
const res = await people.people.get({
resourceName,
personFields: 'relations',
});
const manager = res.data.relations?.find((r: { type: string; }) => r.type === 'manager')?.person || null;
logToFile(`[PeopleService] Finished getUserManager for user: ${userId}`);
return {
content: [{
type: "text" as const,
text: JSON.stringify({ manager })
}]
};
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
logToFile(`[PeopleService] Error during people.getUserManager: ${errorMessage}`);
return {
content: [{
type: "text" as const,
text: JSON.stringify({ error: errorMessage })
}]
};
}
}

public getUserProfile = async ({ userId, email, name }: { userId?: string, email?: string, name?: string }) => {
logToFile(`[PeopleService] Starting getUserProfile with: userId=${userId}, email=${email}, name=${name}`);
try {
Expand All @@ -30,7 +59,7 @@ export class PeopleService {
const resourceName = userId.startsWith('people/') ? userId : `people/${userId}`;
const res = await people.people.get({
resourceName,
personFields: 'names,emailAddresses',
personFields: 'names,emailAddresses,relations',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The getUserProfile method now requests relations in its personFields. However, the method's primary purpose, as indicated by its name and existing usage, is to retrieve basic profile information (names, email addresses). Fetching relations here, if not used or returned by getUserProfile, introduces unnecessary data retrieval, potentially increasing API call latency and resource consumption.
If relations data is not intended to be part of the getUserProfile's output, it should be removed from personFields to optimize the API call. If it is intended to be part of the output, then the method's return type and documentation should be updated, and tests should assert its presence.

Suggested change
personFields: 'names,emailAddresses,relations',
personFields: 'names,emailAddresses',

});
logToFile(`[PeopleService] Finished getUserProfile for user: ${userId}`);
return {
Expand Down