@@ -8,12 +8,13 @@ import { IJSONSchema } from 'vs/base/common/jsonSchema';
8
8
import { DisposableMap } from 'vs/base/common/lifecycle' ;
9
9
import { localize } from 'vs/nls' ;
10
10
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions' ;
11
+ import { ILogService } from 'vs/platform/log/common/log' ;
11
12
import { IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
12
13
import { ILanguageModelToolsService } from 'vs/workbench/contrib/chat/common/languageModelToolsService' ;
13
14
import * as extensionsRegistry from 'vs/workbench/services/extensions/common/extensionsRegistry' ;
14
15
15
16
interface IRawToolContribution {
16
- id : string ;
17
+ name : string ;
17
18
displayName ?: string ;
18
19
description : string ;
19
20
parametersSchema ?: IJSONSchema ;
@@ -23,7 +24,7 @@ const languageModelToolsExtensionPoint = extensionsRegistry.ExtensionsRegistry.r
23
24
extensionPoint : 'languageModelTools' ,
24
25
activationEventsGenerator : ( contributions : IRawToolContribution [ ] , result ) => {
25
26
for ( const contrib of contributions ) {
26
- result . push ( `onLanguageModelTool:${ contrib . id } ` ) ;
27
+ result . push ( `onLanguageModelTool:${ contrib . name } ` ) ;
27
28
}
28
29
} ,
29
30
jsonSchema : {
@@ -32,11 +33,11 @@ const languageModelToolsExtensionPoint = extensionsRegistry.ExtensionsRegistry.r
32
33
items : {
33
34
additionalProperties : false ,
34
35
type : 'object' ,
35
- defaultSnippets : [ { body : { id : '' , description : '' } } ] ,
36
- required : [ 'id ' , 'description' ] ,
36
+ defaultSnippets : [ { body : { name : '' , description : '' } } ] ,
37
+ required : [ 'name ' , 'description' ] ,
37
38
properties : {
38
- id : {
39
- description : localize ( 'toolId ' , "A unique id for this tool." ) ,
39
+ name : {
40
+ description : localize ( 'toolname ' , "A name for this tool which must be unique across all tools ." ) ,
40
41
type : 'string'
41
42
} ,
42
43
description : {
@@ -57,8 +58,8 @@ const languageModelToolsExtensionPoint = extensionsRegistry.ExtensionsRegistry.r
57
58
}
58
59
} ) ;
59
60
60
- function toToolKey ( extensionIdentifier : ExtensionIdentifier , toolId : string ) {
61
- return `${ extensionIdentifier . value } /${ toolId } ` ;
61
+ function toToolKey ( extensionIdentifier : ExtensionIdentifier , toolName : string ) {
62
+ return `${ extensionIdentifier . value } /${ toolName } ` ;
62
63
}
63
64
64
65
export class LanguageModelToolsExtensionPointHandler implements IWorkbenchContribution {
@@ -67,19 +68,25 @@ export class LanguageModelToolsExtensionPointHandler implements IWorkbenchContri
67
68
private _registrationDisposables = new DisposableMap < string > ( ) ;
68
69
69
70
constructor (
70
- @ILanguageModelToolsService languageModelToolsService : ILanguageModelToolsService
71
+ @ILanguageModelToolsService languageModelToolsService : ILanguageModelToolsService ,
72
+ @ILogService logService : ILogService ,
71
73
) {
72
74
languageModelToolsExtensionPoint . setHandler ( ( extensions , delta ) => {
73
75
for ( const extension of delta . added ) {
74
76
for ( const tool of extension . value ) {
77
+ if ( ! tool . name || ! tool . description ) {
78
+ logService . warn ( `Invalid tool contribution from ${ extension . description . identifier . value } : ${ JSON . stringify ( tool ) } ` ) ;
79
+ continue ;
80
+ }
81
+
75
82
const disposable = languageModelToolsService . registerToolData ( tool ) ;
76
- this . _registrationDisposables . set ( toToolKey ( extension . description . identifier , tool . id ) , disposable ) ;
83
+ this . _registrationDisposables . set ( toToolKey ( extension . description . identifier , tool . name ) , disposable ) ;
77
84
}
78
85
}
79
86
80
87
for ( const extension of delta . removed ) {
81
88
for ( const tool of extension . value ) {
82
- this . _registrationDisposables . deleteAndDispose ( toToolKey ( extension . description . identifier , tool . id ) ) ;
89
+ this . _registrationDisposables . deleteAndDispose ( toToolKey ( extension . description . identifier , tool . name ) ) ;
83
90
}
84
91
}
85
92
} ) ;
0 commit comments