Skip to content

Commit

Permalink
feat(custom-agent): add support for authentication types in custom ag…
Browse files Browse the repository at this point in the history
…ent execution #51

The commit adds support for different authentication types when executing custom agents, including Bearer tokens.
  • Loading branch information
phodal committed Mar 5, 2024
1 parent 60f77c7 commit 59f54c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/main/kotlin/cc/unitmesh/devti/counit/CustomAgentExecutor.kt
@@ -1,6 +1,7 @@
package cc.unitmesh.devti.counit

import cc.unitmesh.devti.counit.configurable.customAgentSetting
import cc.unitmesh.devti.counit.model.AuthType
import cc.unitmesh.devti.counit.model.CustomAgentConfig
import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project
Expand All @@ -13,11 +14,21 @@ import okhttp3.RequestBody
class CustomAgentExecutor(val project: Project) {
private var client = OkHttpClient()

fun execute(input: String, selectedAgent: CustomAgentConfig): String? {
fun execute(input: String, agent: CustomAgentConfig): String? {
val serverAddress = project.customAgentSetting.serverAddress ?: return null
val body = RequestBody.create("application/json; charset=utf-8".toMediaTypeOrNull(), input)
val builder = Request.Builder()

val auth = agent.auth
when (auth?.type) {
AuthType.Bearer -> {
builder.addHeader("Authorization", "Bearer ${auth.token}")
builder.addHeader("Content-Type", "application/json")
}

null -> TODO()
}

client = client.newBuilder().build()
val call = client.newCall(builder.url(serverAddress).post(body).build())

Expand Down
Expand Up @@ -53,11 +53,16 @@ data class CustomAgentConfig(
val responseAction: ResponseAction = ResponseAction.Direct,
val customFlowTransition: List<CustomFlowTransition> = emptyList(),
val interactive: InteractionType = InteractionType.ChatPanel,
val auth: CustomAgentAuth = CustomAgentAuth()
val auth: CustomAgentAuth? = null
)

@Serializable
data class CustomAgentAuth(
val type: String = "",
val type: AuthType = AuthType.Bearer,
val token: String = "",
)

@Serializable
enum class AuthType {
Bearer,
}

0 comments on commit 59f54c9

Please sign in to comment.