Schedule a message for when the usage limit resets
When the open chat's account has an exhausted quota window, a banner above the composer reads "Usage limit reached · resets at HH:MM" and offers to send the last message (or the current draft) a minute after the reset, via chat_prompt send_at. Queued prompts with a future send_at read "Scheduled · sends at HH:MM" and keep Remove. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -44,6 +44,8 @@ import 'chat_composer_bar.dart';
|
||||
import 'chat_composer_controller.dart';
|
||||
import 'chat_escape_stop.dart';
|
||||
import 'chat_delivery_indicator.dart';
|
||||
import 'chat_usage_limit_banner.dart';
|
||||
import '../domain/chat_usage_limit.dart';
|
||||
import 'chat_draft_store.dart';
|
||||
import 'chat_effort_control.dart';
|
||||
import 'chat_efforts.dart';
|
||||
@@ -1238,6 +1240,11 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
pasteTarget: widget.pasteTarget,
|
||||
ownsPasteWhenFocused: widget.ownsPasteWhenFocused,
|
||||
runShell: _shellRuns.start,
|
||||
limitBanner: (sendDraft) => ChatUsageLimitBanner(
|
||||
thread: _controller,
|
||||
composer: _composer,
|
||||
sendDraft: sendDraft,
|
||||
),
|
||||
backgroundTasks: ChatBackgroundTasks(
|
||||
key: ValueKey('chat-background-tasks-${widget.sessionId}'),
|
||||
gateway: widget.gateway,
|
||||
@@ -1755,6 +1762,9 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
? _composer.deliveries.stateFor(message)
|
||||
: null;
|
||||
final onRemove = _removeAction('${message?['operation_id'] ?? ''}');
|
||||
final sendAt = delivery == ChatDelivery.queued
|
||||
? _scheduledAt(message!)
|
||||
: null;
|
||||
// An unchanged finished row hands back its previous widget, so a streamed
|
||||
// delta rebuilds only the live turn. Transcript snapshots are copied on
|
||||
// write, never mutated, so a deep-equal row is the same content. Permission
|
||||
@@ -1763,7 +1773,15 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
return _rowWidgets.widgetFor(
|
||||
key,
|
||||
row,
|
||||
[delivery, onRemove != null, _images, _controller, _composer, _shellRuns],
|
||||
[
|
||||
delivery,
|
||||
onRemove != null,
|
||||
sendAt,
|
||||
_images,
|
||||
_controller,
|
||||
_composer,
|
||||
_shellRuns,
|
||||
],
|
||||
() => ChatMessageView(
|
||||
row: row,
|
||||
speechScope: widget.sessionId,
|
||||
@@ -1779,7 +1797,11 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
footer: [
|
||||
...chips,
|
||||
if (delivery != null)
|
||||
ChatDeliveryIndicator(state: delivery, onRemove: onRemove),
|
||||
ChatDeliveryIndicator(
|
||||
state: delivery,
|
||||
onRemove: onRemove,
|
||||
sendAt: sendAt,
|
||||
),
|
||||
],
|
||||
images: _images,
|
||||
),
|
||||
@@ -1806,6 +1828,19 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
unawaited(_composer.unqueue(() => controller.unqueue(operationId)));
|
||||
}
|
||||
|
||||
/// When the server will send a queued [message]: its queue entry's
|
||||
/// `send_at`, else the one this device asked for; null once it has passed.
|
||||
DateTime? _scheduledAt(JsonMap message) {
|
||||
final operationId = '${message['operation_id'] ?? ''}';
|
||||
final now = DateTime.now();
|
||||
for (final prompt in _controller.queuedPrompts) {
|
||||
if (operationId.isNotEmpty && prompt['operation_id'] == operationId) {
|
||||
return chatScheduledSendAt(prompt['send_at'], now);
|
||||
}
|
||||
}
|
||||
return chatScheduledSendAt(message['send_at'], now);
|
||||
}
|
||||
|
||||
/// One prompt the server holds queued that the transcript does not show,
|
||||
/// as the sender's bubble with "Queued" and its Remove.
|
||||
Widget _queuedRow(JsonMap prompt) {
|
||||
@@ -1818,6 +1853,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
ChatDeliveryIndicator(
|
||||
state: ChatDelivery.queued,
|
||||
onRemove: _removeAction('${prompt['operation_id'] ?? ''}'),
|
||||
sendAt: chatScheduledSendAt(prompt['send_at'], DateTime.now()),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user