-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathextensions.ts
More file actions
105 lines (97 loc) · 3.03 KB
/
extensions.ts
File metadata and controls
105 lines (97 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {zod} from '../third_party/index.js';
import {ToolCategory} from './categories.js';
import {defineTool} from './ToolDefinition.js';
const EXTENSIONS_CONDITION = 'experimentalExtensionSupport';
export const installExtension = defineTool({
name: 'install_extension',
description: 'Installs a Chrome extension from the given path.',
annotations: {
category: ToolCategory.EXTENSIONS,
readOnlyHint: false,
conditions: [EXTENSIONS_CONDITION],
},
schema: {
path: zod
.string()
.describe('Absolute path to the unpacked extension folder.'),
},
handler: async (request, response, context) => {
const {path} = request.params;
const id = await context.installExtension(path);
response.appendResponseLine(`Extension installed. Id: ${id}`);
},
});
export const uninstallExtension = defineTool({
name: 'uninstall_extension',
description: 'Uninstalls a Chrome extension by its ID.',
annotations: {
category: ToolCategory.EXTENSIONS,
readOnlyHint: false,
conditions: [EXTENSIONS_CONDITION],
},
schema: {
id: zod.string().describe('ID of the extension to uninstall.'),
},
handler: async (request, response, context) => {
const {id} = request.params;
await context.uninstallExtension(id);
response.appendResponseLine(`Extension uninstalled. Id: ${id}`);
},
});
export const listExtensions = defineTool({
name: 'list_extensions',
description:
'Lists all extensions via this server, including their name, ID, version, and enabled status.',
annotations: {
category: ToolCategory.EXTENSIONS,
readOnlyHint: true,
conditions: [EXTENSIONS_CONDITION],
},
schema: {},
handler: async (_request, response, _context) => {
response.setListExtensions();
},
});
export const reloadExtension = defineTool({
name: 'reload_extension',
description: 'Reloads an unpacked Chrome extension by its ID.',
annotations: {
category: ToolCategory.EXTENSIONS,
readOnlyHint: false,
conditions: [EXTENSIONS_CONDITION],
},
schema: {
id: zod.string().describe('ID of the extension to reload.'),
},
handler: async (request, response, context) => {
const {id} = request.params;
const extension = context.getExtension(id);
if (!extension) {
throw new Error(`Extension with ID ${id} not found.`);
}
await context.installExtension(extension.path);
response.appendResponseLine('Extension reloaded.');
},
});
export const triggerExtensionAction = defineTool({
name: 'trigger_extension_action',
description: 'Triggers an action in a Chrome extension.',
annotations: {
category: ToolCategory.EXTENSIONS,
readOnlyHint: false,
conditions: [EXTENSIONS_CONDITION],
},
schema: {
id: zod.string().describe('ID of the extension.'),
},
handler: async (request, response, context) => {
const {id} = request.params;
await context.triggerExtensionAction(id);
response.appendResponseLine(`Extension action triggered. Id: ${id}`);
},
});