Repository navigation
Expand file tree
/
Copy pathOpenCodeHttpClientConfig.java
More file actions
161 lines (130 loc) · 4.46 KB
/
Copy pathOpenCodeHttpClientConfig.java
File metadata and controls
161 lines (130 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package io.github.easy4j.opencode;
import lombok.Data;
/**
* Configuration for the OpenCode HTTP Server client.
*
* <p>Covers server base URL, Basic Auth, TLS, HTTP timeouts, connection pool sizing,
* streaming thread pool, and default model/agent settings.</p>
*
* @author <a href="https://github.com/loong10k">Loong Wan</a>
* @since 3.0.0
* @see OpenCodeHttpClient
* @see OpenCodeOkHttpClientFactory
*/
@Data
public class OpenCodeHttpClientConfig {
/** 对话响应模式,默认保持兼容的完整响应模式。 */
private HttpResponseMode mode = HttpResponseMode.BLOCKING;
/**
* 是否启用 HTTP 子系统。
* <p>为 false 时跳过 HTTP 客户端初始化和检查。</p>
*/
private boolean enabled = true;
/**
* 启动时是否探测 HTTP 服务可用性({@code GET /global/health})。
*/
private boolean startupCheckEnabled = false;
/**
* HTTP 服务不可用时是否快速失败(中断构造)。
* <p>默认 false 仅打 WARN;生产环境建议设为 true。</p>
*/
private boolean failFastOnUnavailable = false;
/**
* OpenCode Server 根地址,例如 {@code http://localhost:4096}。
*/
private String baseUrl = "http://localhost:4096";
/**
* HTTP Basic Auth 用户名(对应 {@code OPENCODE_SERVER_USERNAME},默认 {@code opencode})。
*/
private String username = "opencode";
/**
* HTTP Basic Auth 密码(对应 {@code OPENCODE_SERVER_PASSWORD})。
* <p>为空时不使用 Basic Auth。</p>
*/
private String password;
/**
* 连接超时(毫秒)。
*/
private int connectTimeoutMillis = 15_000;
/**
* 读取超时(毫秒)。
* <p>opencode 的 prompt 请求可能耗时较长,建议设置较大值。</p>
*/
private int readTimeoutMillis = 300_000;
/**
* 写入超时(毫秒)。
*/
private int writeTimeoutMillis = 120_000;
/**
* 整个调用超时(毫秒);0 表示不额外限制。
*/
private int callTimeoutMillis;
/**
* 连接池最大空闲连接数。
*/
private int maxIdleConnections = 32;
/**
* 空闲连接保活时间(毫秒)。
*/
private long keepAliveDurationMillis = 300_000L;
/**
* 异步请求最大并发数。
*/
private int maxRequests = 128;
/**
* 单主机异步请求最大并发数。
*/
private int maxRequestsPerHost = 128;
/** 流式事件处理线程数。 */
private int streamCorePoolSize = 32;
/** 流式事件处理最大线程数。 */
private int streamMaxPoolSize = 32;
/** 流式事件处理有界队列容量。 */
private int streamQueueCapacity = 128;
/** 流式事件处理线程空闲保活时间(毫秒)。 */
private long streamKeepAliveMillis = 60_000L;
/** 单个流式订阅的事件缓存上限。 */
private int streamEventQueueCapacity = 1_024;
/**
* 遇到失效连接等传输故障时是否允许 OkHttp 自动恢复。
*/
private boolean retryOnConnectionFailure = true;
/**
* 是否校验 HTTPS 证书;为 false 时关闭校验(仅建议开发环境)。
*/
private boolean verifySsl = true;
/**
* 默认使用的模型,格式 {@code provider/model},例如 {@code anthropic/claude-sonnet-4-5}。
* <p>为空时使用 opencode 服务端配置的默认模型。</p>
*/
private String defaultModel;
/**
* 默认使用的 agent 名称。
* <p>为空时使用 opencode 服务端配置的默认 agent。</p>
*/
private String defaultAgent;
/** Legacy bean alias for {@link #getBaseUrl()}. */
public String getServerUrl() {
return baseUrl;
}
/** Sets the server URL through the legacy bean property. */
public void setServerUrl(String serverUrl) {
this.baseUrl = serverUrl;
}
/** Legacy bean alias for {@link #getStreamEventQueueCapacity()}. */
public int getSseEventQueueCapacity() {
return streamEventQueueCapacity;
}
/** Sets the event queue capacity through the legacy bean property. */
public void setSseEventQueueCapacity(int capacity) {
this.streamEventQueueCapacity = capacity;
}
/**
* 解析用于 HTTP Basic Auth 的密码。
*
* @return password 非空则用之,否则空字符串
*/
public String resolvePassword() {
return password != null ? password : "";
}
}