HTTP 出站链:Configuration → SPI 装配 → 拦截器 → Provider

HTTP 出站链:Configuration → SPI 装配 → 拦截器 → Provider 由 Archify 生成的时序图。 ① getOkHttpClient() / createRequestFactory() ② SPI 覆盖 Pool/Dispatcher + 挂拦截器 ③ Request.Builder → newCall().execute() ④ ContentType→Error→Logging 依次过链 ⑤ HTTPS 请求(鉴权头+JSON 体) ⑥ 200 JSON 体 / 非 2xx ⑦ mapper.readValue → 响应实体 ⑧ 非 2xx → HttpErrorDecoder → AiHttpException ⑨ 流式:factory.newEventSource(req, sseListener) ⑩ data: 帧 → onEvent 增量 ×N → 收尾 服务实现 · 如 OpenAiChatService · 时序参与者 服务实现 如 OpenAiChatService Configuration · client+SPI 装配 · 时序参与者 Configuration client+SPI 装配 OkHttpClient · 连接池/调度器 · 时序参与者 OkHttpClient 连接池/调度器 拦截器链 · ContentType/Error · 时序参与者 拦截器链 ContentType/Error Provider · JSON / SSE 帧 · 时序参与者 Provider JSON / SSE 帧 SseListener · 逐帧回调 · 时序参与者 SseListener 逐帧回调 图例 默认消息

统一客户端底座

  • • Configuration 内置 OkHttpClient(连接 10s / 读 300s / 写 60s);可整体替换,也可注入 OkHttpConfig 日志级别
  • • createRequestFactory() 把同一 client 包成 EventSource.Factory,供 SSE 流式复用

SPI 扩展点

  • • META-INF/services 注册 ConnectionPoolProvider / DispatcherProvider 即可替换连接池与调度器
  • • ContentType/ErrorInterceptor 是 OkHttp Interceptor:可在自定义 client 上按顺序挂载

错误与流式出口

  • • 非 2xx 统一 HttpErrorDecoder.decode → AiHttpException;所有平台服务共用此出口
  • • 流式经 StreamExecutionSupport.execute:首帧/空闲超时、可配重试(ai4j.stream.* 属性),SseListener 回调增量与收尾