{#
  What `/usage` shows.

  Two different numbers, deliberately kept apart. **Used** is how full the
  window is right now -- one reply's prompt plus its completion, which is what
  decides when compaction fires. **Spent** is everything this conversation has
  cost end to end, which is larger and grows forever: a three-round reply pays
  for its prompt three times but only ever occupies the window once.

  Anything derived from an estimate wears a `~`, because `services/tokens.py`
  counts four characters to a token when an endpoint reports nothing, and a
  precise-looking figure that is a guess is worse than an obvious guess.
#}
<table class="sheet">
  <tbody>
    <tr>
      <td>In the window now</td>
      <td>
        {% if metrics.context_tokens %}
          {{ '~' if metrics.estimated }}{{ '{:,}'.format(metrics.context_tokens) }} tokens
          {% if metrics.percent %}
            — {{ metrics.percent }}% of
            {{ '{:,}'.format(metrics.context_limit) }}
          {% endif %}
        {% else %}
          Nothing yet.
        {% endif %}
      </td>
    </tr>

    {% if not metrics.context_limit %}
    {# Unknown is not zero. Nobody has said how big this model's window is, so
       the percentage is omitted rather than computed, and automatic
       compaction never fires. #}
    <tr>
      <td>Window size</td>
      <td>
        Not recorded for {{ model.label if model else "this model" }}, so there is
        no percentage and this chat will never compact itself.
        {% if user.is_admin %}
          Set it under <a href="/admin/models">Models</a>.
        {% endif %}
      </td>
    </tr>
    {% endif %}

    <tr>
      <td>Spent in total</td>
      <td>
        {{ '~' if estimated }}{{ '{:,}'.format(totals.total) }} tokens
        across {{ replies }} repl{{ 'y' if replies == 1 else 'ies' }}
      </td>
    </tr>
    <tr>
      <td>Of which sent</td>
      <td>{{ '~' if estimated }}{{ '{:,}'.format(totals.prompt) }} tokens</td>
    </tr>
    <tr>
      <td>Of which written</td>
      <td>{{ '~' if estimated }}{{ '{:,}'.format(totals.completion) }} tokens</td>
    </tr>

    {% if metrics.tokens_per_second %}
    <tr>
      <td>Last reply</td>
      <td>{{ '%.1f'|format(metrics.tokens_per_second) }} tokens/second</td>
    </tr>
    {% endif %}

    {% if chat.compact_summary %}
    <tr>
      <td>Compacted</td>
      <td>
        Earlier turns are summarised. They are still in the transcript; they
        just stop being sent.
      </td>
    </tr>
    {% endif %}
  </tbody>
</table>
