File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
src/main/kotlin/cc/unitmesh/devti/counit Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 1
1
package cc.unitmesh.devti.counit
2
2
3
3
import cc.unitmesh.devti.counit.configurable.customAgentSetting
4
+ import cc.unitmesh.devti.counit.model.AuthType
4
5
import cc.unitmesh.devti.counit.model.CustomAgentConfig
5
6
import com.intellij.openapi.components.Service
6
7
import com.intellij.openapi.project.Project
@@ -13,11 +14,21 @@ import okhttp3.RequestBody
13
14
class CustomAgentExecutor (val project : Project ) {
14
15
private var client = OkHttpClient ()
15
16
16
- fun execute (input : String , selectedAgent : CustomAgentConfig ): String? {
17
+ fun execute (input : String , agent : CustomAgentConfig ): String? {
17
18
val serverAddress = project.customAgentSetting.serverAddress ? : return null
18
19
val body = RequestBody .create(" application/json; charset=utf-8" .toMediaTypeOrNull(), input)
19
20
val builder = Request .Builder ()
20
21
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
+
21
32
client = client.newBuilder().build()
22
33
val call = client.newCall(builder.url(serverAddress).post(body).build())
23
34
Original file line number Diff line number Diff line change @@ -53,11 +53,16 @@ data class CustomAgentConfig(
53
53
val responseAction : ResponseAction = ResponseAction .Direct ,
54
54
val customFlowTransition : List <CustomFlowTransition > = emptyList(),
55
55
val interactive : InteractionType = InteractionType .ChatPanel ,
56
- val auth : CustomAgentAuth = CustomAgentAuth ()
56
+ val auth : CustomAgentAuth ? = null
57
57
)
58
58
59
59
@Serializable
60
60
data class CustomAgentAuth (
61
- val type : String = " " ,
61
+ val type : AuthType = AuthType . Bearer ,
62
62
val token : String = " " ,
63
63
)
64
+
65
+ @Serializable
66
+ enum class AuthType {
67
+ Bearer ,
68
+ }
You can’t perform that action at this time.
0 commit comments