Skip to content

Commit bf3d97a

Browse files
committed
fix(ClineProvider): add type-safe handling of API key properties
- Added ApiKeyProperty type to ensure type safety when accessing API key properties - Added runtime validation to ensure keys exist in apiConfiguration - Fixed TypeScript error with string indexing of ApiConfiguration - Ensures all API keys are initialized before buildApiHandler
1 parent fa80f4e commit bf3d97a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,20 @@ export class ClineProvider implements vscode.WebviewViewProvider {
15221522
await this.storeSecret("mistralApiKey", mistralApiKey)
15231523
await this.storeSecret("unboundApiKey", unboundApiKey)
15241524
await this.updateGlobalState("unboundModelId", unboundModelId)
1525+
1526+
type ApiKeyProperty = keyof ApiConfiguration & `${string}ApiKey`
1527+
1528+
// this is to ensure that all api key before goto buildApiHandler are not undefined
1529+
for (const key in apiConfiguration) {
1530+
if (
1531+
key.endsWith("Key") &&
1532+
(key as ApiKeyProperty) in apiConfiguration &&
1533+
apiConfiguration[key as ApiKeyProperty] === undefined
1534+
) {
1535+
apiConfiguration[key as ApiKeyProperty] = ""
1536+
}
1537+
}
1538+
15251539
if (this.cline) {
15261540
this.cline.api = buildApiHandler(apiConfiguration)
15271541
}

0 commit comments

Comments
 (0)