Skip to content

Commit abc80dc

Browse files
committed
docs: unify @author tag to @author <a href="https://github.com/loong10k">Loong Wan</a>
1 parent 478a8c8 commit abc80dc

2 files changed

Lines changed: 15 additions & 26 deletions

File tree

‎src/main/java/io/github/easy4j/hermes/api/HermesHttpClient.java‎

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
import static io.github.easy4j.hermes.api.HermesApiConstants.*;
1010
import io.github.easy4j.hermes.api.model.*;
1111
import io.github.easy4j.hermes.exception.HermesHttpException;
12+
import lombok.Getter;
1213
import lombok.extern.slf4j.Slf4j;
1314
import okhttp3.*;
1415

1516
import java.io.IOException;
17+
import java.nio.charset.StandardCharsets;
1618
import java.util.*;
1719
import java.util.concurrent.atomic.AtomicLong;
1820
import okio.Buffer;
@@ -22,12 +24,18 @@
2224
* <p>基于 OkHttp,支持外部传入 {@link OkHttpClient}(复用别的插件实例)。</p>
2325
*/
2426
@Slf4j
27+
@SuppressWarnings("unchecked")
2528
public class HermesHttpClient implements AutoCloseable {
2629

2730
private static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
2831
private static final AtomicLong REQUEST_SEQUENCE = new AtomicLong();
2932

3033
private final HermesHttpClientConfig config;
34+
/**
35+
* -- GETTER --
36+
* 暴露 ObjectMapper 供外部复用。
37+
*/
38+
@Getter
3139
private final ObjectMapper objectMapper;
3240
private final OkHttpClient httpClient;
3341
private final boolean ownsHttpClient;
@@ -108,11 +116,7 @@ public boolean deleteResponse(String responseId) {
108116
public ModelsResponse listModels() { return get(PATH_MODELS, ModelsResponse.class); }
109117

110118
private static String encodePathSegment(String value) {
111-
try {
112-
return java.net.URLEncoder.encode(value, "UTF-8");
113-
} catch (java.io.UnsupportedEncodingException e) {
114-
throw new IllegalStateException("UTF-8 is not supported", e);
115-
}
119+
return java.net.URLEncoder.encode(value, StandardCharsets.UTF_8);
116120
}
117121

118122
public ModelsResponse.ModelData getModel(String modelId) {
@@ -157,7 +161,6 @@ public void stopRun(String runId) {
157161
}
158162
}
159163

160-
@SuppressWarnings("unchecked")
161164
public Map<String, Object> approveRun(String runId, Map<String, Object> decision) {
162165
return postMap(PATH_RUNS + "/" + runId + "/approval", decision);
163166
}
@@ -227,7 +230,6 @@ public Map<String, Object> createJob(Map<String, Object> job) {
227230
return postMap(PATH_JOBS, job);
228231
}
229232

230-
@SuppressWarnings("unchecked")
231233
public Map<String, Object> getJob(String jobId) {
232234
Request request = authedRequest(url(PATH_JOBS + "/" + jobId)).get().build();
233235
try (Response response = httpClient.newCall(request).execute()) {
@@ -241,7 +243,6 @@ public Map<String, Object> getJob(String jobId) {
241243
}
242244
}
243245

244-
@SuppressWarnings("unchecked")
245246
public Map<String, Object> updateJob(String jobId, Map<String, Object> patch) {
246247
Request request = authedRequest(url(PATH_JOBS + "/" + jobId))
247248
.patch(RequestBody.create(toJson(patch), JSON)).build();
@@ -299,13 +300,6 @@ public OkHttpClient getOkHttpClient() {
299300
return httpClient;
300301
}
301302

302-
/**
303-
* 暴露 ObjectMapper 供外部复用。
304-
*/
305-
public ObjectMapper getObjectMapper() {
306-
return objectMapper;
307-
}
308-
309303
// ============================================================
310304
// Internal helpers
311305
// ============================================================

‎src/main/java/io/github/easy4j/hermes/api/HermesSseClient.java‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,13 @@ private void doSubscribePost(String url,
170170
sub.callRef.set(call);
171171
try (Response response = call.execute()) {
172172
if (!response.isSuccessful()) {
173-
String body = response.body() != null ? response.body().string() : "";
173+
String body = response.body().string();
174174
onError.accept(new HermesHttpException(response.code(), body));
175175
return;
176176
}
177177
log.info("SSE chat connected: url={}, status={}, elapsedMs={}", url, response.code(),
178178
(System.nanoTime() - startedAt) / 1_000_000L);
179-
if (response.body() != null) {
180-
parseSseSource(response.body().source(), consumer, completeOnce, sub);
181-
}
179+
parseSseSource(response.body().source(), consumer, completeOnce, sub);
182180
}
183181
completeOnce.run();
184182
} catch (Exception e) {
@@ -201,14 +199,12 @@ private void doSubscribeSessionStream(String sessionId, String input,
201199
sub.callRef.set(call);
202200
try (Response response = call.execute()) {
203201
if (!response.isSuccessful()) {
204-
String body = response.body() != null ? response.body().string() : "";
202+
String body = response.body().string();
205203
log.warn("SSE session stream failed status={}, retrying", response.code());
206204
Thread.sleep(DEFAULT_CONNECT_TIMEOUT_MS / 3);
207205
continue;
208206
}
209-
if (response.body() != null) {
210-
parseSseSource(response.body().source(), consumer, () -> {}, sub);
211-
}
207+
parseSseSource(response.body().source(), consumer, () -> {}, sub);
212208
}
213209
} catch (InterruptedException e) {
214210
Thread.currentThread().interrupt();
@@ -238,9 +234,8 @@ private void doSubscribeRun(String runId, Consumer<SseEvent> consumer, Subscript
238234
continue;
239235
}
240236
log.info("SSE connected to run events {}", runId);
241-
if (response.body() != null) {
242-
parseSseSource(response.body().source(), consumer, () -> {}, sub);
243-
}
237+
parseSseSource(response.body().source(), consumer, () -> {
238+
}, sub);
244239
}
245240
} catch (InterruptedException e) {
246241
Thread.currentThread().interrupt();

0 commit comments

Comments
 (0)