Skip to content

Commit 19a3820

Browse files
committed
feat: initialize VS Code Language Model client in constructor
1 parent b6ea9d1 commit 19a3820

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/api/providers/vscode-lm.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export class VsCodeLmHandler extends BaseProvider implements SingleCompletionHan
6161
}
6262
}
6363
})
64+
this.initializeClient()
6465
} catch (error) {
6566
// Ensure cleanup if constructor fails
6667
this.dispose()
@@ -70,7 +71,30 @@ export class VsCodeLmHandler extends BaseProvider implements SingleCompletionHan
7071
)
7172
}
7273
}
73-
74+
/**
75+
* Initializes the VS Code Language Model client.
76+
* This method is called during the constructor to set up the client.
77+
* This useful when the client is not created yet and call getModel() before the client is created.
78+
* @returns Promise<void>
79+
* @throws Error when client initialization fails
80+
*/
81+
async initializeClient(): Promise<void> {
82+
try {
83+
// Check if the client is already initialized
84+
if (this.client) {
85+
console.debug("Roo Code <Language Model API>: Client already initialized")
86+
return
87+
}
88+
// Create a new client instance
89+
this.client = await this.createClient(this.options.vsCodeLmModelSelector || {})
90+
console.debug("Roo Code <Language Model API>: Client initialized successfully")
91+
} catch (error) {
92+
// Handle errors during client initialization
93+
const errorMessage = error instanceof Error ? error.message : "Unknown error"
94+
console.error("Roo Code <Language Model API>: Client initialization failed:", errorMessage)
95+
throw new Error(`Roo Code <Language Model API>: Failed to initialize client: ${errorMessage}`)
96+
}
97+
}
7498
/**
7599
* Creates a language model chat client based on the provided selector.
76100
*

0 commit comments

Comments
 (0)