Skip to content

Commit 02795f6

Browse files
committed
Added login working
1 parent 40ade36 commit 02795f6

3 files changed

Lines changed: 56 additions & 2 deletions

File tree

src/extension.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ export function activate(context: vscode.ExtensionContext) {
6767
console.dir(data)
6868
context.secrets.store("pearai-token", data.accessToken)
6969
context.secrets.store("pearai-refresh", data.refreshToken)
70+
// Update MCP server with new token
71+
const provider = await ClineProvider.getInstance()
72+
if (provider) {
73+
const mcpHub = provider.getMcpHub()
74+
if (mcpHub) {
75+
await mcpHub.updatePearAiApiKey(data.accessToken)
76+
}
77+
}
7078
vscode.commands.executeCommand("roo-cline.plusButtonClicked")
7179
}),
7280
)

src/services/mcp/McpHub.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ export class McpHub {
5656
private disposables: vscode.Disposable[] = []
5757
private settingsWatcher?: vscode.FileSystemWatcher
5858
private fileWatchers: Map<string, FSWatcher> = new Map()
59+
private context: vscode.ExtensionContext
5960
connections: McpConnection[] = []
6061
isConnecting: boolean = false
6162

62-
constructor(provider: ClineProvider) {
63+
constructor(provider: ClineProvider, context: vscode.ExtensionContext) {
6364
this.providerRef = new WeakRef(provider)
65+
this.context = context
6466
this.watchMcpSettingsFile()
6567
this.initializeMcpServers()
6668
}
@@ -154,6 +156,16 @@ export class McpHub {
154156
}
155157
}
156158

159+
private async getPearAiApiKey(): Promise<string | null> {
160+
try {
161+
const token = await this.context.secrets.get("pearai-token")
162+
return token || null
163+
} catch (error) {
164+
console.error("Failed to get PearAI token from secrets:", error)
165+
return null
166+
}
167+
}
168+
157169
private async initializeMcpServers(): Promise<void> {
158170
try {
159171
const settingsPath = await this.getMcpSettingsFilePath()
@@ -168,6 +180,17 @@ export class McpHub {
168180
if (!mergedServers[serverName]) {
169181
mergedServers[serverName] = serverConfig
170182
}
183+
184+
// If this is the pearai server, check login status and update API key
185+
if (serverName === "pearai") {
186+
const apiKey = await this.getPearAiApiKey()
187+
if (apiKey) {
188+
mergedServers[serverName] = {
189+
...serverConfig,
190+
args: ["pearai-mcp", apiKey],
191+
}
192+
}
193+
}
171194
}
172195

173196
// Update the settings file with merged settings
@@ -482,6 +505,29 @@ export class McpHub {
482505
})
483506
}
484507

508+
public async updatePearAiApiKey(apiKey: string): Promise<void> {
509+
try {
510+
const settingsPath = await this.getMcpSettingsFilePath()
511+
const content = await fs.readFile(settingsPath, "utf-8")
512+
const config = JSON.parse(content)
513+
514+
if (config.mcpServers?.pearai) {
515+
config.mcpServers.pearai = {
516+
...config.mcpServers.pearai,
517+
args: ["pearai-mcp", apiKey],
518+
}
519+
520+
await fs.writeFile(settingsPath, JSON.stringify(config, null, 2))
521+
await this.updateServerConnections(config.mcpServers)
522+
vscode.window.showInformationMessage("PearAI API key updated successfully")
523+
}
524+
} catch (error) {
525+
console.error("Failed to update PearAI API key:", error)
526+
vscode.window.showErrorMessage("Failed to update PearAI API key")
527+
throw error
528+
}
529+
}
530+
485531
public async toggleServerDisabled(serverName: string, disabled: boolean): Promise<void> {
486532
let settingsPath: string
487533
try {

src/services/mcp/McpServerManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class McpServerManager {
3636
try {
3737
// Double-check instance in case it was created while we were waiting
3838
if (!this.instance) {
39-
this.instance = new McpHub(provider)
39+
this.instance = new McpHub(provider, context)
4040
// Store a unique identifier in global state to track the primary instance
4141
await context.globalState.update(this.GLOBAL_STATE_KEY, Date.now().toString())
4242
}

0 commit comments

Comments
 (0)