Skip to content

Commit

Permalink
Remove cache of devchat client in BaseActionHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
pplam committed Sep 19, 2024
1 parent 9948ca4 commit 3a26e29
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 35 deletions.
1 change: 0 additions & 1 deletion src/main/kotlin/ai/devchat/core/BaseActionHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ abstract class BaseActionHandler(
var payload: JSONObject? = null
) : ActionHandler {
val devChatService: DevChatService = project.getService(DevChatService::class.java)
val client: DevChatClient? = devChatService.client
val wrapper: DevChatWrapper? = devChatService.wrapper
val browser: Browser? = devChatService.browser
val activeConversation: ActiveConversation? = devChatService.activeConversation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ai.devchat.core.handlers

import ai.devchat.core.BaseActionHandler
import ai.devchat.core.DevChatActions
import ai.devchat.plugin.DevChatService
import com.alibaba.fastjson.JSONObject
import com.intellij.openapi.project.Project

Expand All @@ -14,7 +15,7 @@ class DeleteLastConversationRequestHandler(project: Project, requestAction: Stri
override val actionName: String = DevChatActions.DELETE_LAST_CONVERSATION_RESPONSE
override fun action() {
val promptHash = payload!!.getString("promptHash")
client!!.deleteLog(promptHash)
project.getService(DevChatService::class.java).client!!.deleteLog(promptHash)
send(payload = mapOf("promptHash" to promptHash))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ai.devchat.core.handlers

import ai.devchat.core.BaseActionHandler
import ai.devchat.core.DevChatActions
import ai.devchat.plugin.DevChatService
import com.alibaba.fastjson.JSONObject
import com.intellij.openapi.project.Project

Expand All @@ -14,7 +15,7 @@ class DeleteTopicRequestHandler(project: Project, requestAction: String, metadat
override val actionName: String = DevChatActions.DELETE_TOPIC_RESPONSE
override fun action() {
val topicHash = payload!!.getString("topicHash")
client!!.deleteTopic(topicHash)
project.getService(DevChatService::class.java).client!!.deleteTopic(topicHash)
send(payload = mapOf("topicHash" to topicHash))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ai.devchat.core.handlers

import ai.devchat.core.BaseActionHandler
import ai.devchat.core.DevChatActions
import ai.devchat.plugin.DevChatService
import com.alibaba.fastjson.JSONObject
import com.intellij.openapi.project.Project

Expand All @@ -14,7 +15,7 @@ class ListTopicsRequestHandler(project: Project, requestAction: String, metadata
) {
override val actionName: String = DevChatActions.LIST_TOPICS_RESPONSE
override fun action() {
val topics = client!!.getTopics().map {
val topics = project.getService(DevChatService::class.java).client!!.getTopics().map {
val request = it.rootPromptRequest
val response = it.rootPromptResponse
mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ai.devchat.core.handlers

import ai.devchat.core.BaseActionHandler
import ai.devchat.core.DevChatActions
import ai.devchat.plugin.DevChatService
import com.alibaba.fastjson.JSONObject
import com.intellij.openapi.project.Project

Expand All @@ -20,7 +21,7 @@ class LoadConversationRequestHandler(project: Project, requestAction: String, me
topicHash.isNullOrEmpty() -> activeConversation!!.reset()
topicHash == activeConversation!!.topic -> res["reset"] = false
else -> {
val logs = client!!.getTopicLogs(topicHash)
val logs = project.getService(DevChatService::class.java).client!!.getTopicLogs(topicHash)
activeConversation.reset(topicHash, logs)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ai.devchat.core.handlers
import ai.devchat.common.Log
import ai.devchat.common.PathUtils
import ai.devchat.core.*
import ai.devchat.plugin.DevChatService
import ai.devchat.storage.CONFIG
import com.alibaba.fastjson.JSONObject
import com.intellij.openapi.project.Project
Expand Down Expand Up @@ -52,7 +53,7 @@ class SendMessageRequestHandler(project: Project, requestAction: String, metadat
contextContents = contextContents,
)

client!!.message(
project.getService(DevChatService::class.java).client!!.message(
chatRequest,
dataHandler(chatRequest),
::errorHandler,
Expand Down Expand Up @@ -99,10 +100,11 @@ class SendMessageRequestHandler(project: Project, requestAction: String, metadat
}
private fun finishHandler(chatRequest: ChatRequest): (Int) -> Unit {
val response = chatRequest.response!!
val devChatService = project.getService(DevChatService::class.java)
return { exitCode: Int ->
when(exitCode) {
0 -> {
val entry = client!!.insertLog(
val entry = devChatService.client!!.insertLog(
LogEntry(
chatRequest.modelName,
chatRequest.parent,
Expand All @@ -115,7 +117,7 @@ class SendMessageRequestHandler(project: Project, requestAction: String, metadat
promptCallback(response)

val currentTopic = activeConversation!!.topic ?: response.promptHash!!
val logs = client.getTopicLogs(currentTopic, 0, 1)
val logs = devChatService.client!!.getTopicLogs(currentTopic, 0, 1)

if (currentTopic == activeConversation.topic) {
activeConversation.addMessage(logs.first())
Expand Down
27 changes: 0 additions & 27 deletions src/main/kotlin/ai/devchat/storage/SensitiveDataStorage.kt

This file was deleted.

0 comments on commit 3a26e29

Please sign in to comment.