Skip to content

Commit 59f54c9

Browse files
committed
feat(custom-agent): add support for authentication types in custom agent execution #51
The commit adds support for different authentication types when executing custom agents, including Bearer tokens.
1 parent 60f77c7 commit 59f54c9

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/main/kotlin/cc/unitmesh/devti/counit/CustomAgentExecutor.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cc.unitmesh.devti.counit
22

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

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

22+
val auth = agent.auth
23+
when (auth?.type) {
24+
AuthType.Bearer -> {
25+
builder.addHeader("Authorization", "Bearer ${auth.token}")
26+
builder.addHeader("Content-Type", "application/json")
27+
}
28+
29+
null -> TODO()
30+
}
31+
2132
client = client.newBuilder().build()
2233
val call = client.newCall(builder.url(serverAddress).post(body).build())
2334

src/main/kotlin/cc/unitmesh/devti/counit/model/CustomAgentConfig.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,16 @@ data class CustomAgentConfig(
5353
val responseAction: ResponseAction = ResponseAction.Direct,
5454
val customFlowTransition: List<CustomFlowTransition> = emptyList(),
5555
val interactive: InteractionType = InteractionType.ChatPanel,
56-
val auth: CustomAgentAuth = CustomAgentAuth()
56+
val auth: CustomAgentAuth? = null
5757
)
5858

5959
@Serializable
6060
data class CustomAgentAuth(
61-
val type: String = "",
61+
val type: AuthType = AuthType.Bearer,
6262
val token: String = "",
6363
)
64+
65+
@Serializable
66+
enum class AuthType {
67+
Bearer,
68+
}

0 commit comments

Comments
 (0)