Session status

Read session.status to show progress and decide when Send or Stop is available.

session.status has the sealed type SessionStatus, so a switch can cover every case:

final class const StatusLine({super.key}) extends StatelessWidget {
  @override
  Widget build(BuildContext context) =>
      switch (TandemSessionScope.of(context).status) {
        Idle() => const SizedBox.shrink(),
        Thinking(:final backendTool?) => Text('Using $backendTool…'),
        Thinking() => const LinearProgressIndicator(),
        Calling(:final tool) => Text('Running $tool…'),
        AwaitingApproval(:final request) => Text(
          'Waiting for you: ${request.tool}',
        ),
        Stopping() => const Text('Stopping…'),
      };
}

Thinking.backendTool identifies the latest backend tool call, such as find_customer. The name lasts from TOOL_CALL_START until its result or the agent's next text or call. When several backend tools run, it identifies the latest call. Use it to show progress during a long turn. The order desk's searchCatalog is a method of the screen, so it runs as Calling with tool set to OrderDeskCubitTool.searchCatalog. The generated enum prints the name the agent knows, so the status line shows Running search_catalog….

Thinking.drawing is true while the agent draws a view for TandemView, from its tandem_show_view call until its next text or call. Match Thinking(drawing: true) before the general Thinking() case to show a drawing status.

Send and Stop

Call session.send(text) to send a message. While a run is open, the message appears in the chat and waits for the next run.

Call session.stop() while the status is Thinking or Calling(approved: false). Stop hides later text and prevents the remaining calls from running. A method already running continues to completion.

An approved method runs as Calling(approved: true) and cannot be stopped. Disable Stop until it returns.

Stopping means Tandem is still reading the stopped run's stream to its end. A new message waits until that finishes. This keeps the backend's conversation consistent.

Statuses compare by value, so select and distinct can ignore repeated values that describe the same state.