Skip to content

Commit e390585

Browse files
committed
refactor: standardize chat streaming API
1 parent 5cce9ef commit e390585

9 files changed

Lines changed: 17 additions & 65 deletions

src/main/java/io/github/easy4j/openclaw/OpenClawClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,10 @@ public OpenClawClient(OpenClawHttpClientConfig httpConfig,
239239
*/
240240
private void runStartupChecks(OpenClawHttpClientConfig httpConfig, OpenClawCliConfig cliConfig) {
241241
if (httpConfig.isEnabled() && httpConfig.isStartupCheckEnabled()
242-
&& OpenClawStrings.isNotBlank(httpConfig.getGatewayBaseUrl())) {
242+
&& OpenClawStrings.isNotBlank(httpConfig.getBaseUrl())) {
243243
try {
244244
chatClient.health();
245-
log.info("OpenClaw HTTP health check passed: {}", httpConfig.getGatewayBaseUrl());
245+
log.info("OpenClaw HTTP health check passed: {}", httpConfig.getBaseUrl());
246246
} catch (Exception e) {
247247
if (httpConfig.isFailFastOnUnavailable()) {
248248
throw new IllegalStateException(

src/main/java/io/github/easy4j/openclaw/OpenClawHttpClientConfig.java

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class OpenClawHttpClientConfig {
5151
/**
5252
* Gateway HTTP root URL(Webhooks HTTP ), {@code http://localhost:18789}.
5353
*/
54-
private String gatewayBaseUrl = "http://localhost:18789";
54+
private String baseUrl = "http://localhost:18789";
5555

5656
/**
5757
* Gateway control planetoken( {@code gateway.auth.token} {@code OPENCLAW_GATEWAY_TOKEN}).
@@ -107,54 +107,6 @@ public class OpenClawHttpClientConfig {
107107
/** 遇到失效连接等传输故障时是否允许 OkHttp 自动恢复 */
108108
private boolean retryOnConnectionFailure = true;
109109

110-
/** @deprecated 使用 {@link #getStreamCorePoolSize()}。 */
111-
@Deprecated
112-
public int getSseCorePoolSize() {
113-
return streamCorePoolSize;
114-
}
115-
116-
/** @deprecated 使用 {@link #setStreamCorePoolSize(int)}。 */
117-
@Deprecated
118-
public void setSseCorePoolSize(int value) {
119-
this.streamCorePoolSize = value;
120-
}
121-
122-
/** @deprecated 使用 {@link #getStreamMaxPoolSize()}。 */
123-
@Deprecated
124-
public int getSseMaxPoolSize() {
125-
return streamMaxPoolSize;
126-
}
127-
128-
/** @deprecated 使用 {@link #setStreamMaxPoolSize(int)}。 */
129-
@Deprecated
130-
public void setSseMaxPoolSize(int value) {
131-
this.streamMaxPoolSize = value;
132-
}
133-
134-
/** @deprecated 使用 {@link #getStreamQueueCapacity()}。 */
135-
@Deprecated
136-
public int getSseQueueCapacity() {
137-
return streamQueueCapacity;
138-
}
139-
140-
/** @deprecated 使用 {@link #setStreamQueueCapacity(int)}。 */
141-
@Deprecated
142-
public void setSseQueueCapacity(int value) {
143-
this.streamQueueCapacity = value;
144-
}
145-
146-
/** @deprecated 使用 {@link #getStreamKeepAliveMillis()}。 */
147-
@Deprecated
148-
public long getSseKeepAliveMillis() {
149-
return streamKeepAliveMillis;
150-
}
151-
152-
/** @deprecated 使用 {@link #setStreamKeepAliveMillis(long)}。 */
153-
@Deprecated
154-
public void setSseKeepAliveMillis(long value) {
155-
this.streamKeepAliveMillis = value;
156-
}
157-
158110
/**
159111
* Gateway HTTP Webhooks base path,Corresponds to {@code hooks.path}, {@code /hooks}.
160112
*/

src/main/java/io/github/easy4j/openclaw/api/OpenClawHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ protected <T> T parse(String json, Class<T> type, String label) {
225225
* Resolves the URL.
226226
*/
227227
protected String resolveUrl(String path) {
228-
String base = config.getGatewayBaseUrl();
228+
String base = config.getBaseUrl();
229229
if (OpenClawStrings.isBlank(base)) {
230230
throw new OpenClawHttpException("gatewayBaseUrl is empty", null);
231231
}

src/main/java/io/github/easy4j/openclaw/api/OpenClawWebhookClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private String resolveHooksSubPath(String subPath) {
115115
}
116116

117117
private HttpResult postWebhook(String hookPath, Map<String, Object> body) {
118-
String base = config.getGatewayBaseUrl();
118+
String base = config.getBaseUrl();
119119
if (OpenClawStrings.isBlank(base)) throw new OpenClawHttpException("OpenClaw gatewayBaseUrl is empty", null);
120120
String url = base.replaceAll("/+$", "") + hookPath;
121121
String token = config.resolveHooksBearerToken();

src/main/java/io/github/easy4j/openclaw/ws/OpenClawGatewayWsClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* <h3>example</h3>
3434
* <pre>{@code
3535
* OpenClawClientConfig config = new OpenClawClientConfig();
36-
* config.setGatewayBaseUrl("http://localhost:18789");
36+
* config.setBaseUrl("http://localhost:18789");
3737
* config.setGatewayAuthToken("my-gateway-token");
3838
*
3939
* OpenClawGatewayWsClient ws = new OpenClawGatewayWsClient(config);
@@ -114,7 +114,7 @@ public OpenClawGatewayWsClient(OpenClawHttpClientConfig config, URI serverUri) {
114114
}
115115

116116
private static URI buildWsUri(OpenClawHttpClientConfig config) {
117-
String base = config.getGatewayBaseUrl();
117+
String base = config.getBaseUrl();
118118
if (OpenClawStrings.isBlank(base)) {
119119
throw new IllegalArgumentException("gatewayBaseUrl is required for WebSocket connection");
120120
}

src/test/java/io/github/easy4j/openclaw/OpenClawHttpApiCoverageTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class OpenClawHttpApiCoverageTest {
5252
@BeforeEach
5353
void setUp() {
5454
config = new OpenClawHttpClientConfig();
55-
config.setGatewayBaseUrl("http://localhost:18789");
55+
config.setBaseUrl("http://localhost:18789");
5656
config.setGatewayAuthToken("gateway-token");
5757
config.setHooksToken("hook-token");
5858
client = new OkHttpClient.Builder().addInterceptor(chain -> {
@@ -154,7 +154,7 @@ void shouldCoverResponsesEmbeddingsToolsAndBaseHttpErrors() {
154154
}
155155

156156
OpenClawHttpClientConfig empty = new OpenClawHttpClientConfig();
157-
empty.setGatewayBaseUrl(" ");
157+
empty.setBaseUrl(" ");
158158
try (OpenClawChatClient chat = new OpenClawChatClient(empty, null, client)) {
159159
assertThrows(OpenClawHttpException.class, chat::health);
160160
}

src/test/java/io/github/easy4j/openclaw/OpenClawHttpClientConfigTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ void shouldExposeUnifiedStreamPropertiesAndLegacyAliases() {
1111
OpenClawHttpClientConfig config = new OpenClawHttpClientConfig();
1212
assertEquals(HttpResponseMode.BLOCKING, config.getMode());
1313

14-
config.setSseCorePoolSize(7);
15-
config.setSseMaxPoolSize(9);
16-
config.setSseQueueCapacity(11);
17-
config.setSseKeepAliveMillis(13L);
14+
config.setStreamCorePoolSize(7);
15+
config.setStreamMaxPoolSize(9);
16+
config.setStreamQueueCapacity(11);
17+
config.setStreamKeepAliveMillis(13L);
1818

1919
assertEquals(7, config.getStreamCorePoolSize());
2020
assertEquals(9, config.getStreamMaxPoolSize());

src/test/java/io/github/easy4j/openclaw/ws/OpenClawGatewayWsClientIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void setUp() throws Exception {
4646
gateway.start();
4747
assertTrue(gateway.started.await(3, TimeUnit.SECONDS));
4848
OpenClawHttpClientConfig config = new OpenClawHttpClientConfig();
49-
config.setGatewayBaseUrl("http://127.0.0.1:" + gateway.getPort());
49+
config.setBaseUrl("http://127.0.0.1:" + gateway.getPort());
5050
config.setGatewayAuthToken("token");
5151
client = new OpenClawGatewayWsClient(config, URI.create("ws://127.0.0.1:" + gateway.getPort()));
5252
}

src/test/java/io/github/easy4j/openclaw/ws/OpenClawWsProtocolTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void testSessionsListResultDeserialization() throws Exception {
186186
@Test
187187
void testWsUriBuilding() {
188188
OpenClawHttpClientConfig config = new OpenClawHttpClientConfig();
189-
config.setGatewayBaseUrl("http://localhost:18789");
189+
config.setBaseUrl("http://localhost:18789");
190190

191191
OpenClawGatewayWsClient client = new OpenClawGatewayWsClient(config);
192192
assertEquals("ws://localhost:18789", client.getURI().toString());
@@ -195,7 +195,7 @@ void testWsUriBuilding() {
195195
@Test
196196
void testWsUriBuildingHttps() {
197197
OpenClawHttpClientConfig config = new OpenClawHttpClientConfig();
198-
config.setGatewayBaseUrl("https://my-gateway.example.com");
198+
config.setBaseUrl("https://my-gateway.example.com");
199199

200200
OpenClawGatewayWsClient client = new OpenClawGatewayWsClient(config);
201201
assertEquals("wss://my-gateway.example.com", client.getURI().toString());
@@ -204,7 +204,7 @@ void testWsUriBuildingHttps() {
204204
@Test
205205
void testWsUriBuildingTrailingSlash() {
206206
OpenClawHttpClientConfig config = new OpenClawHttpClientConfig();
207-
config.setGatewayBaseUrl("http://localhost:18789/");
207+
config.setBaseUrl("http://localhost:18789/");
208208

209209
OpenClawGatewayWsClient client = new OpenClawGatewayWsClient(config);
210210
assertEquals("ws://localhost:18789", client.getURI().toString());

0 commit comments

Comments
 (0)