66import { CancellationToken } from '../../../../base/common/cancellation.js' ;
77import { Disposable } from '../../../../base/common/lifecycle.js' ;
88import { derived , IObservable , observableFromEvent , ObservableMap } from '../../../../base/common/observable.js' ;
9+ import { isObject } from '../../../../base/common/types.js' ;
910import { URI } from '../../../../base/common/uri.js' ;
1011import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js' ;
1112import { ObservableMemento , observableMemento } from '../../../../platform/observable/common/observableMemento.js' ;
@@ -18,8 +19,8 @@ import { PromptFileRewriter } from './promptSyntax/promptFileRewriter.js';
1819
1920
2021type ToolEnablementStates = {
21- readonly toolSets : Map < string , boolean > ;
22- readonly tools : Map < string , boolean > ;
22+ readonly toolSets : ReadonlyMap < string , boolean > ;
23+ readonly tools : ReadonlyMap < string , boolean > ;
2324} ;
2425
2526type StoredDataV2 = {
@@ -30,8 +31,8 @@ type StoredDataV2 = {
3031
3132type StoredDataV1 = {
3233 readonly version : undefined ;
33- readonly disabledToolSets ?: string [ ] ; // deprecated
34- readonly disabledTools ?: string [ ] ; // deprecated
34+ readonly disabledToolSets ?: string [ ] ;
35+ readonly disabledTools ?: string [ ] ;
3536} ;
3637
3738namespace ToolEnablementStates {
@@ -48,27 +49,30 @@ namespace ToolEnablementStates {
4849 }
4950
5051 function isStoredDataV1 ( data : StoredDataV1 | StoredDataV2 | undefined ) : data is StoredDataV1 {
51- return ! ! data && data . version === undefined
52+ return isObject ( data ) && data . version === undefined
5253 && ( data . disabledTools === undefined || Array . isArray ( data . disabledTools ) )
5354 && ( data . disabledToolSets === undefined || Array . isArray ( data . disabledToolSets ) ) ;
5455 }
5556
5657 function isStoredDataV2 ( data : StoredDataV1 | StoredDataV2 | undefined ) : data is StoredDataV2 {
57- return ! ! data && data . version === 2 && Array . isArray ( data . toolSetEntries ) && Array . isArray ( data . toolEntries ) ;
58+ return isObject ( data ) && data . version === 2 && Array . isArray ( data . toolSetEntries ) && Array . isArray ( data . toolEntries ) ;
5859 }
5960
6061 export function fromStorage ( storage : string ) : ToolEnablementStates {
61- const parsed = JSON . parse ( storage ) ;
62- if ( isStoredDataV2 ( parsed ) ) {
63- return { toolSets : new Map ( parsed . toolSetEntries ) , tools : new Map ( parsed . toolEntries ) } ;
64- } else if ( isStoredDataV1 ( parsed ) ) {
65- const toolSetEntries = parsed . disabledToolSets ?. map ( id => [ id , false ] as [ string , boolean ] ) ;
66- const toolEntries = parsed . disabledTools ?. map ( id => [ id , false ] as [ string , boolean ] ) ;
67- return { toolSets : new Map ( toolSetEntries ) , tools : new Map ( toolEntries ) } ;
68- } else {
69- // invalid data
70- return { toolSets : new Map ( ) , tools : new Map ( ) } ;
62+ try {
63+ const parsed = JSON . parse ( storage ) ;
64+ if ( isStoredDataV2 ( parsed ) ) {
65+ return { toolSets : new Map ( parsed . toolSetEntries ) , tools : new Map ( parsed . toolEntries ) } ;
66+ } else if ( isStoredDataV1 ( parsed ) ) {
67+ const toolSetEntries = parsed . disabledToolSets ?. map ( id => [ id , false ] as [ string , boolean ] ) ;
68+ const toolEntries = parsed . disabledTools ?. map ( id => [ id , false ] as [ string , boolean ] ) ;
69+ return { toolSets : new Map ( toolSetEntries ) , tools : new Map ( toolEntries ) } ;
70+ }
71+ } catch {
72+ // ignore
7173 }
74+ // invalid data
75+ return { toolSets : new Map ( ) , tools : new Map ( ) } ;
7276 }
7377
7478 export function toStorage ( state : ToolEnablementStates ) : string {
0 commit comments