From 3ffe133c84dff2230a08fa5564b56dce6f29bd95 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 18 Apr 2025 12:50:31 -0700 Subject: [PATCH] update session logic --- core/core.ts | 106 ++++++++++-------- .../auth/ContinueAuthService.kt | 3 + .../continue/IdeProtocolClient.kt | 2 - gui/src/context/Auth.tsx | 1 + 4 files changed, 61 insertions(+), 51 deletions(-) diff --git a/core/core.ts b/core/core.ts index 7f68ddb65..91e228946 100644 --- a/core/core.ts +++ b/core/core.ts @@ -26,7 +26,10 @@ import { GlobalContext } from "./util/GlobalContext"; import historyManager from "./util/history"; import { editConfigFile, migrateV1DevDataFiles } from "./util/paths"; import { Telemetry } from "./util/posthog"; -import { isProcessBackgrounded, markProcessAsBackgrounded } from "./util/processTerminalBackgroundStates"; +import { + isProcessBackgrounded, + markProcessAsBackgrounded, +} from "./util/processTerminalBackgroundStates"; import { getSymbolsForManyFiles } from "./util/treeSitter"; import { TTS } from "./util/tts"; @@ -644,12 +647,12 @@ export class Core { }); on("didChangeControlPlaneSessionInfo", async (msg) => { - await this.configHandler.updateControlPlaneSessionInfo( - msg.data.sessionInfo, - ); this.messenger.send("sessionUpdate", { sessionInfo: msg.data.sessionInfo, }); + await this.configHandler.updateControlPlaneSessionInfo( + msg.data.sessionInfo, + ); }); on("auth/getAuthUrl", async (msg) => { @@ -673,54 +676,57 @@ export class Core { } }); - on("tools/call", async ({ data: { toolCall, selectedModelTitle }, messageId }) => { - const { config } = await this.configHandler.loadConfig(); - if (!config) { - throw new Error("Config not loaded"); - } + on( + "tools/call", + async ({ data: { toolCall, selectedModelTitle }, messageId }) => { + const { config } = await this.configHandler.loadConfig(); + if (!config) { + throw new Error("Config not loaded"); + } - const tool = config.tools.find( - (t) => t.function.name === toolCall.function.name, - ); + const tool = config.tools.find( + (t) => t.function.name === toolCall.function.name, + ); - if (!tool) { - throw new Error(`Tool ${toolCall.function.name} not found`); - } + if (!tool) { + throw new Error(`Tool ${toolCall.function.name} not found`); + } - if (!config.selectedModelByRole.chat) { - throw new Error("No chat model selected"); - } + if (!config.selectedModelByRole.chat) { + throw new Error("No chat model selected"); + } - // Define a callback for streaming output updates - const onPartialOutput = (params: { - toolCallId: string, - contextItems: ContextItem[]; - }) => { - this.messenger.send("toolCallPartialOutput", params); - }; + // Define a callback for streaming output updates + const onPartialOutput = (params: { + toolCallId: string; + contextItems: ContextItem[]; + }) => { + this.messenger.send("toolCallPartialOutput", params); + }; - const contextItems = await callTool( - tool, - JSON.parse(toolCall.function.arguments || "{}"), - { - ide: this.ide, - llm: config.selectedModelByRole.chat, - fetch: (url, init) => - fetchwithRequestOptions(url, init, config.requestOptions), + const contextItems = await callTool( tool, - toolCallId: toolCall.id, - onPartialOutput, - }, - ); + JSON.parse(toolCall.function.arguments || "{}"), + { + ide: this.ide, + llm: config.selectedModelByRole.chat, + fetch: (url, init) => + fetchwithRequestOptions(url, init, config.requestOptions), + tool, + toolCallId: toolCall.id, + onPartialOutput, + }, + ); - if (tool.faviconUrl) { - contextItems.forEach((item) => { - item.icon = tool.faviconUrl; - }); - } + if (tool.faviconUrl) { + contextItems.forEach((item) => { + item.icon = tool.faviconUrl; + }); + } - return { contextItems }; - }); + return { contextItems }; + }, + ); on("isItemTooBig", async ({ data: { item, selectedModelTitle } }) => { return this.isItemTooBig(item); @@ -731,11 +737,13 @@ export class Core { markProcessAsBackgrounded(toolCallId); }); - on("process/isBackgrounded", async ({ data: { toolCallId }, messageId }) => { - const isBackgrounded = isProcessBackgrounded(toolCallId); - return isBackgrounded; // Return true to indicate the message was handled successfully - }); - + on( + "process/isBackgrounded", + async ({ data: { toolCallId }, messageId }) => { + const isBackgrounded = isProcessBackgrounded(toolCallId); + return isBackgrounded; // Return true to indicate the message was handled successfully + }, + ); } private async isItemTooBig(item: ContextItemWithId) { diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/auth/ContinueAuthService.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/auth/ContinueAuthService.kt index 51ae45278..9908daa55 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/auth/ContinueAuthService.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/auth/ContinueAuthService.kt @@ -71,6 +71,9 @@ class ContinueAuthService { setRefreshToken("") setAccountId("") setAccountLabel("") + + ApplicationManager.getApplication().messageBus.syncPublisher(AuthListener.TOPIC) + .handleUpdatedSessionInfo(null) } private fun updateRefreshToken(token: String) { diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt index 8b49d39ad..f76a41574 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt @@ -111,8 +111,6 @@ class IdeProtocolClient( "logoutOfControlPlane" -> { val authService = service() authService.signOut() - ApplicationManager.getApplication().messageBus.syncPublisher(AuthListener.TOPIC) - .handleUpdatedSessionInfo(null) respond(null) } diff --git a/gui/src/context/Auth.tsx b/gui/src/context/Auth.tsx index dde89ba09..98de70828 100644 --- a/gui/src/context/Auth.tsx +++ b/gui/src/context/Auth.tsx @@ -111,6 +111,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ useWebviewListener( "sessionUpdate", async (data) => { + debugger; setSession(data.sessionInfo); }, [],