Files
buzz/mobile/lib/features/channels/default_agent_launcher.dart
klopez4212 5bd9d2c5d2 Transcribe Bestie hold recordings into text on device (#9645)
Hold Bestie to record with the waveform and slide-up cancel interaction
from #8665, then release to send an on-device transcript as a normal
text message. Stay on Home with a loader inside Bestie until delivery
succeeds, then open chat. Failures expose Retry/Discard; saved
recordings and signed messages remain recoverable without duplicate
sends. Saved audio is excluded from OS backup. Existing composer voice
notes are unchanged.

Separate exploration from #8665. Transcription requires iOS 26 and a
supported language. Android reports unavailable before capture because
its generic recognizer cannot guarantee saved-file input.

Validation: at `b5dc83bbf5`, 5,046 Flutter tests (71 skipped), 27 crypto
tests, analysis and required push checks pass. Prior native changes at
`30a397f83c`: Android build and 33 tests pass; iOS simulator compilation
and backup-exclusion test pass, with one unchanged document-picker
timeout passing on isolated rerun. Earlier iPhone preview was tested
with saved profile preserved; these latest fixes have not been installed
on the physical phone.

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
Co-authored-by: Tom Brow <tomb@block.xyz>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>
Co-authored-by: corey <2dafccf60ea6d431a568f6d67fc600160d92a51e415e09dc8b213b8e360663d5@buzz.block.builderlab.xyz>
2026-11-19 10:32:12 +00:00

168 lines
5.9 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import '../../shared/agents/owned_agent_directory.dart';
import '../../shared/agents/remote_agents.dart';
import '../../shared/me/default_agent.dart';
import '../../shared/animated_avatar.dart';
import '../../shared/me/me_sync.dart';
import '../../shared/profile/user_cache_provider.dart';
import '../../shared/theme/theme.dart';
import '../../shared/widgets/agent_navigation_icon.dart';
import '../../shared/widgets/avatar_image.dart';
import '../../shared/widgets/preset_agent_avatar.dart';
import '../../shared/widgets/buzz_callout.dart';
import 'first_agent_callout.dart';
import 'empty_bestie_avatar.dart';
import 'bestie_conversation.dart';
import 'bestie_transcription_control.dart';
/// Persistent shortcut to the agent chosen in Agents.
class DefaultAgentLauncher extends HookConsumerWidget {
const DefaultAgentLauncher({required this.onChooseAgent, super.key});
final VoidCallback onChooseAgent;
@override
Widget build(BuildContext context, WidgetRef ref) {
final preference = ref.watch(defaultAgentProvider);
final scope = ref.watch(meSyncProvider);
final pubkey = preference.isLoading ? null : preference.value;
final profiles = ref.watch(userCacheProvider);
final profile = profiles[pubkey];
final opening = useState(false);
final resolving = useState(false);
final remoteAgents = ref.watch(remoteAgentsEnabledProvider);
// Only someone with no agents at all is invited to make a first one.
// Cheap checks come first, so the rest are watched only when relevant.
final showCallout =
remoteAgents &&
pubkey == null &&
!preference.isLoading &&
!preference.hasError &&
!ref.watch(firstAgentCalloutSeenProvider) &&
ref
.watch(ownedAgentDirectoryProvider)
.unwrapPrevious()
.value
?.isEmpty ==
true;
useEffect(() {
if (pubkey != null) {
ref.read(userCacheProvider.notifier).preload([pubkey]);
}
// Having a Bestie, however it was chosen, retires the tip for good. A
// failed read can still hold the previous community's Bestie, so only
// current data counts.
if (pubkey != null &&
!preference.hasError &&
remoteAgents &&
!ref.read(firstAgentCalloutSeenProvider)) {
dismissFirstAgentCallout(ref);
}
return null;
}, [pubkey, preference.hasError, remoteAgents]);
final label = pubkey != null
? 'Chat with ${profile?.label ?? 'your Bestie'}'
: preference.hasError
? 'Retry Bestie'
: 'Bestie';
Future<void> open() async {
final currentPreference = ref.read(defaultAgentProvider);
if (opening.value ||
currentPreference.isLoading ||
ref.read(meSyncProvider) != scope ||
currentPreference.value != pubkey) {
return;
}
unawaited(HapticFeedback.lightImpact());
if (preference.hasError) {
ref.invalidate(defaultAgentProvider);
return;
}
if (pubkey == null) {
if (remoteAgents) dismissFirstAgentCallout(ref);
onChooseAgent();
return;
}
opening.value = true;
try {
await openBestieConversation(
context,
ref,
pubkey,
onResolving: (value) => resolving.value = value,
);
} finally {
if (context.mounted) opening.value = false;
}
}
Widget withTranscription(Widget child) {
if (scope.config.nsec?.isNotEmpty != true) return child;
return BestieTranscriptionControl(
key: ValueKey('transcription:${scope.cacheKey}'),
scope: scope.cacheKey,
recipient: preference.isLoading || preference.hasError ? null : pubkey,
child: child,
);
}
return BuzzCallout(
message: 'Create your first agent',
visible: showCallout,
// Give people a moment with Home before inviting them.
delay: const Duration(seconds: 3),
onTap: open,
onDismiss: () => dismissFirstAgentCallout(ref),
artwork: [
for (final character in emptyBestieCharacters.take(6))
AvatarImageContent(
imageUrl: character.url,
preferThumbnail: true,
fit: BoxFit.contain,
fallback: const AgentNavigationIcon(size: 24),
),
],
child: withTranscription(
SizedBox(
child: SizedBox.square(
dimension: 56,
child: IconButton(
tooltip: label,
padding: EdgeInsets.zero,
onPressed: opening.value || preference.isLoading ? null : open,
icon: ExcludeSemantics(
child: resolving.value
? const SizedBox.square(
dimension: 22,
child: CircularProgressIndicator(strokeWidth: 2),
)
: pubkey == null
? preference.isLoading || preference.hasError
? const AgentNavigationIcon(size: 24)
: const EmptyBestieAvatar()
: usesInsetAgentArtwork(profile?.avatarUrl)
? PresetAgentAvatar(
imageUrl: profile!.avatarUrl!,
size: 47.88,
fallback: Center(child: Text(profile.initial)),
)
: AvatarImage(
imageUrl: profile?.avatarUrl,
radius: 18,
isAgent: true,
backgroundColor: context.controlSurface,
fallback: Center(child: Text(profile?.initial ?? 'A')),
),
),
),
),
),
),
);
}
}