@@ -7,6 +7,7 @@ import * as l10n from '@vscode/l10n';
7
7
import type * as vscode from 'vscode' ;
8
8
import { IRunCommandExecutionService } from '../../../platform/commands/common/runCommandExecutionService' ;
9
9
import { ResourceSet } from '../../../util/vs/base/common/map' ;
10
+ import { Schemas } from '../../../util/vs/base/common/network' ;
10
11
import { URI } from '../../../util/vs/base/common/uri' ;
11
12
import { LanguageModelTextPart , LanguageModelToolResult , MarkdownString } from '../../../vscodeTypes' ;
12
13
import { IBuildPromptContext } from '../../prompt/common/intents' ;
@@ -27,7 +28,8 @@ export class SimpleBrowserTool implements ICopilotTool<ISimpleBrowserParams> {
27
28
) { }
28
29
29
30
async invoke ( options : vscode . LanguageModelToolInvocationOptions < ISimpleBrowserParams > , token : vscode . CancellationToken ) {
30
- this . _alreadyApprovedDomains . add ( URI . parse ( options . input . url ) ) ;
31
+ const uri = URI . parse ( options . input . url ) ;
32
+ this . _alreadyApprovedDomains . add ( uri ) ;
31
33
this . commandService . executeCommand ( 'simpleBrowser.show' , options . input . url ) ;
32
34
return new LanguageModelToolResult ( [
33
35
new LanguageModelTextPart (
@@ -41,7 +43,12 @@ export class SimpleBrowserTool implements ICopilotTool<ISimpleBrowserParams> {
41
43
}
42
44
43
45
prepareInvocation ( options : vscode . LanguageModelToolInvocationPrepareOptions < ISimpleBrowserParams > , token : vscode . CancellationToken ) : vscode . ProviderResult < vscode . PreparedToolInvocation > {
44
- const urlsNeedingConfirmation = ! this . _alreadyApprovedDomains . has ( URI . parse ( options . input . url ) ) ;
46
+ const uri = URI . parse ( options . input . url ) ;
47
+ if ( uri . scheme !== Schemas . http && uri . scheme !== Schemas . https ) {
48
+ throw new Error ( l10n . t ( 'Invalid URL scheme. Only HTTP and HTTPS are supported.' ) ) ;
49
+ }
50
+
51
+ const urlsNeedingConfirmation = ! this . _alreadyApprovedDomains . has ( uri ) ;
45
52
let confirmationMessages : vscode . LanguageModelToolConfirmationMessages | undefined ;
46
53
if ( urlsNeedingConfirmation ) {
47
54
confirmationMessages = { title : l10n . t `Open untrusted web page?` , message : new MarkdownString ( l10n . t `${ options . input . url } ` ) } ;
0 commit comments