99import static io .github .easy4j .hermes .api .HermesApiConstants .*;
1010import io .github .easy4j .hermes .api .model .*;
1111import io .github .easy4j .hermes .exception .HermesHttpException ;
12+ import lombok .Getter ;
1213import lombok .extern .slf4j .Slf4j ;
1314import okhttp3 .*;
1415
1516import java .io .IOException ;
17+ import java .nio .charset .StandardCharsets ;
1618import java .util .*;
1719import java .util .concurrent .atomic .AtomicLong ;
1820import okio .Buffer ;
2224 * <p>基于 OkHttp,支持外部传入 {@link OkHttpClient}(复用别的插件实例)。</p>
2325 */
2426@ Slf4j
27+ @ SuppressWarnings ("unchecked" )
2528public 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 // ============================================================
0 commit comments