293474ac3c
- The usage-limit banner now reads 'Out of usage credits' (or the refusal's own 'You've hit your 5-hour limit'), 'Auto-resuming at <time>', an 'Auto-continue when limits reset' checkbox and Try again, keeping the account switcher's 'Switch to <account>'. - Auto-continue (a shared, persisted preference, on by default) hands the server a durable scheduled prompt (send_at = reset + 1 min) with an idempotent auto-continue-<refusal id> operation id: the refused operator message again, or 'continue' when the refused turn had already worked. Unchecking unqueues it; Try again unqueues it and sends now. - Remove the approaching-limit banner, its SnackBar announcements and their marks; the send-button usage ring replaces them. - Claude Code's rate_limit_event overage fields (overageStatus, isUsingOverage/overageInUse, overageDisabledReason, overageResetsAt) reach clients as usage.account.extra_usage; the ring tooltip and the banner say 'Extra usage available' or 'Using extra usage'. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
2.1 KiB
Dart
71 lines
2.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
const chatAutoContinuePreferenceKey = 'pipelines.chatAutoContinue.v1';
|
|
|
|
/// The usage-limit banner's "Auto-continue when limits reset" choice: one
|
|
/// preference for every chat, on by default, kept in shared preferences so a
|
|
/// reload remembers it.
|
|
class ChatAutoContinue extends ChangeNotifier {
|
|
ChatAutoContinue({this.preferences});
|
|
|
|
/// The instance chats use unless a test hands them their own.
|
|
static final ChatAutoContinue shared = ChatAutoContinue(
|
|
preferences: SharedPreferences.getInstance,
|
|
);
|
|
|
|
/// Where the choice is kept; null keeps it in memory.
|
|
final Future<SharedPreferences> Function()? preferences;
|
|
|
|
bool _enabled = true;
|
|
bool _loaded = false;
|
|
Future<void>? _loading;
|
|
|
|
bool get enabled => _enabled;
|
|
|
|
/// Whether the stored choice has been read, so nothing is scheduled on the
|
|
/// default before an operator's "off" is known.
|
|
bool get loaded => _loaded;
|
|
|
|
/// Reads the stored choice once.
|
|
Future<void> load() => _loading ??= _read();
|
|
|
|
Future<void> _read() async {
|
|
final preferences = this.preferences;
|
|
try {
|
|
if (preferences != null) {
|
|
final stored = (await preferences()).getBool(
|
|
chatAutoContinuePreferenceKey,
|
|
);
|
|
// A choice made while reading wins.
|
|
if (stored != null && !_loaded) _enabled = stored;
|
|
}
|
|
} on Object catch (error) {
|
|
// Without storage the default holds for this app session.
|
|
debugPrint('Auto-continue: could not read preferences: $error');
|
|
}
|
|
_loaded = true;
|
|
notifyListeners();
|
|
}
|
|
|
|
/// Records the operator's choice.
|
|
Future<void> set(bool enabled) async {
|
|
_loaded = true;
|
|
if (enabled == _enabled) return;
|
|
_enabled = enabled;
|
|
notifyListeners();
|
|
final preferences = this.preferences;
|
|
if (preferences == null) return;
|
|
try {
|
|
await (await preferences()).setBool(
|
|
chatAutoContinuePreferenceKey,
|
|
enabled,
|
|
);
|
|
} on Object catch (error) {
|
|
debugPrint('Auto-continue: could not save preferences: $error');
|
|
}
|
|
}
|
|
}
|