sendMessage

fun sendMessage(text: String, locale: String? = null): Flow<A2aEvent>

Sends text as one turn and streams the server's responses as A2aEvents. Text typed or spoken in another language is translated to English first when SessionConfig.autoTranslate is on; pass the language as locale when it is known (for example the voice recognition locale), or leave it null to let the translator detect it. If translation fails the original text is sent. The returned flow is cold: the turn starts when it is collected.

Collecting throws A2aSessionException when the session is stopped (SessionError.Code.SESSION_CLOSED) or another turn is running (SessionError.Code.TURN_IN_PROGRESS). A device action leaves the task paused in INPUT_REQUIRED; report it with sendActionResult. A turn whose stream ends there is finished like any other; the next message may follow.

Failures: a transport or auth failure is published on errors as a classified SessionError and rethrown unchanged from the flow. An artifact with an action the SDK does not know is ignored and the turn continues. When the server ends a turn as failed, rejected or auth-required, the status event is delivered, the error is published on errors (SessionError.Code.TASK_FAILED or SessionError.Code.AUTH_FAILED) and the flow completes normally. After any failure the session is SessionState.ACTIVE again and the next message may be sent (after logging in again for auth failures). Calling stop completes the flow.