Revert "Rewrite extension management tools" (#5243)

This commit is contained in:
Will Pfleger
2025-10-17 20:25:44 -04:00
committed by GitHub
parent b8c3508178
commit c662039674
19 changed files with 353 additions and 925 deletions
@@ -313,31 +313,6 @@ describe('Agent API', () => {
}),
});
});
it('should not mutate the original extension config', async () => {
const originalConfig: ExtensionConfig = {
type: 'stdio',
name: 'Extension Manager',
description: 'Test description',
cmd: 'python',
args: ['script.py'],
};
const mockResponse = {
ok: true,
text: vi.fn().mockResolvedValue('{"error": false}'),
};
mockFetch.mockResolvedValue(mockResponse);
const { replaceWithShims } = await import('./utils');
vi.mocked(replaceWithShims).mockResolvedValue('/path/to/shim');
await addToAgent(originalConfig, {}, 'test-session');
// Verify the original config was not mutated
expect(originalConfig.name).toBe('Extension Manager');
expect(originalConfig.cmd).toBe('python');
});
});
describe('removeFromAgent', () => {
@@ -156,26 +156,21 @@ export async function addToAgent(
options: ToastServiceOptions = {},
sessionId: string
): Promise<Response> {
// Create a copy to avoid mutating the original extension object
const extensionCopy: ExtensionConfig = { ...extension };
try {
if (extensionCopy.type === 'stdio') {
extensionCopy.cmd = await replaceWithShims(extensionCopy.cmd);
if (extension.type === 'stdio') {
extension.cmd = await replaceWithShims(extension.cmd);
}
extensionCopy.name = sanitizeName(extensionCopy.name);
extension.name = sanitizeName(extension.name);
return await extensionApiCall('/extensions/add', extensionCopy, options, sessionId);
return await extensionApiCall('/extensions/add', extension, options, sessionId);
} catch (error) {
// Check if this is a 428 error and make the message more descriptive
if (error instanceof Error && error.message && error.message.includes('428')) {
const enhancedError = new Error(
'Failed to add extension. Goose Agent was still starting up. Please try again.'
);
console.error(
`Failed to add extension ${extensionCopy.name} to agent: ${enhancedError.message}`
);
console.error(`Failed to add extension ${extension.name} to agent: ${enhancedError.message}`);
throw enhancedError;
}
throw error;