Class PhaseAwareStreamCallback

java.lang.Object
org.codelibs.fess.chat.PhaseAwareStreamCallback
All Implemented Interfaces:
LlmStreamCallback

public class PhaseAwareStreamCallback extends Object implements LlmStreamCallback
Bridges LlmStreamCallback events from the LLM layer to a phase-aware ChatPhaseCallback. Forwards onChunk/onError to an inner LlmStreamCallback and forwards onRetry/onWaiting/onWarning to the phase callback together with the phase name supplied at construction.
  • Constructor Details

    • PhaseAwareStreamCallback

      public PhaseAwareStreamCallback(String phase, ChatPhaseCallback phaseCallback, LlmStreamCallback inner)
      Creates a callback that forwards chunk/error events to inner and retry/waiting/warning events to phaseCallback tagged with phase.
      Parameters:
      phase - the phase name to attach to phase callback events
      phaseCallback - the phase callback to forward retry/waiting/warning events to (may be null)
      inner - the LlmStreamCallback to forward chunk/error events to (never null)
  • Method Details

    • onChunk

      public void onChunk(String chunk, boolean done)
      Description copied from interface: LlmStreamCallback
      Called for each chunk of the streaming response.
      Specified by:
      onChunk in interface LlmStreamCallback
      Parameters:
      chunk - the text chunk from the LLM response
      done - true if this is the final chunk
    • onError

      public void onError(Throwable error)
      Description copied from interface: LlmStreamCallback
      Called when an error occurs during streaming.
      Specified by:
      onError in interface LlmStreamCallback
      Parameters:
      error - the error that occurred
    • onRetry

      public void onRetry(String operation, int attempt, int maxAttempts, long sleepMs, Throwable cause)
      Description copied from interface: LlmStreamCallback
      Called when the LLM HTTP call is being retried.
      Specified by:
      onRetry in interface LlmStreamCallback
      Parameters:
      operation - log label for the operation (e.g., "chat", "streamChat")
      attempt - 1-based current attempt index that just failed
      maxAttempts - total attempts including the first
      sleepMs - milliseconds the client will sleep before the next attempt
      cause - the cause of the retry (RetryableHttpException or IOException)
    • onWaiting

      public void onWaiting(String reason, long elapsedMs, long timeoutMs)
      Description copied from interface: LlmStreamCallback
      Called when the request is waiting for a concurrency permit.
      Specified by:
      onWaiting in interface LlmStreamCallback
      Parameters:
      reason - short reason code, currently always "concurrency_limit"
      elapsedMs - milliseconds already spent waiting (0 on the first call)
      timeoutMs - maximum milliseconds the client will wait before giving up
    • onWarning

      public void onWarning(String code, String detail)
      Description copied from interface: LlmStreamCallback
      Called when an internal silent fallback occurs (e.g., reasoning model token exhaustion).
      Specified by:
      onWarning in interface LlmStreamCallback
      Parameters:
      code - short machine-readable warning code (e.g., "reasoning_token_exhausted")
      detail - human-readable detail (free-form)