|
| 1 | +import '../../shared/widgets/android_page_header.dart'; |
1 | 2 | import '../../shared/widgets/ios_glass_navigation_button.dart'; |
| 3 | + |
2 | 4 | import 'dart:async'; |
| 5 | + |
3 | 6 | import 'package:duo_kit/duo_kit.dart'; |
4 | 7 |
|
5 | 8 | import 'package:flutter/material.dart'; |
6 | 9 | import 'package:flutter/foundation.dart'; |
| 10 | + |
7 | 11 | import '../../shared/diagnostics/diagnostic_navigation_observer.dart'; |
8 | 12 | import '../../shared/widgets/adaptive_conversation_pane.dart'; |
9 | 13 | import '../../shared/widgets/duo_toolbar.dart'; |
| 14 | + |
10 | 15 | import 'package:flutter_hooks/flutter_hooks.dart'; |
11 | 16 | import 'package:hooks_riverpod/hooks_riverpod.dart'; |
12 | 17 |
|
@@ -658,14 +663,164 @@ class AgentsPage extends HookConsumerWidget { |
658 | 663 | fontWeight: FontWeight.w600, |
659 | 664 | color: navigationPrimaryForeground(context), |
660 | 665 | ); |
661 | | - final topHeight = frostedAppBarHeight( |
662 | | - context, |
663 | | - nativeLargeTitle: !portrait, |
664 | | - useNativeNavigation: !portrait, |
665 | | - alignWithStatusRegion: portrait, |
666 | | - titleStyle: headerStyle, |
667 | | - bottomHeight: portrait ? 0 : Grid.xxs, |
| 666 | + final android = defaultTargetPlatform == TargetPlatform.android; |
| 667 | + final topHeight = android |
| 668 | + ? 0.0 |
| 669 | + : frostedAppBarHeight( |
| 670 | + context, |
| 671 | + nativeLargeTitle: !portrait, |
| 672 | + useNativeNavigation: !portrait, |
| 673 | + alignWithStatusRegion: portrait, |
| 674 | + titleStyle: headerStyle, |
| 675 | + bottomHeight: portrait ? 0 : Grid.xxs, |
| 676 | + ); |
| 677 | + final body = SafeArea( |
| 678 | + top: false, |
| 679 | + child: Material( |
| 680 | + color: Colors.transparent, |
| 681 | + child: BeeRefreshIndicator( |
| 682 | + edgeOffset: topHeight, |
| 683 | + onRefresh: refresh, |
| 684 | + child: CustomScrollView( |
| 685 | + physics: const AlwaysScrollableScrollPhysics(), |
| 686 | + slivers: [ |
| 687 | + SliverToBoxAdapter(child: SizedBox(height: topHeight)), |
| 688 | + if (signInNeeded) |
| 689 | + SliverToBoxAdapter( |
| 690 | + child: ReconnectCapsule( |
| 691 | + inline: true, |
| 692 | + message: signingIn |
| 693 | + ? 'Finish sign-in in browser' |
| 694 | + : 'Reconnect to Builderlab', |
| 695 | + actionLabel: signingIn ? 'Cancel' : 'Sign in', |
| 696 | + destructiveAction: signingIn, |
| 697 | + onSignIn: () => unawaited( |
| 698 | + signingIn ? flow.leave() : flow.reconnectAccount(), |
| 699 | + ), |
| 700 | + ), |
| 701 | + ), |
| 702 | + SliverToBoxAdapter( |
| 703 | + child: Column( |
| 704 | + children: [ |
| 705 | + if (createOnOpen && (loading || signingIn)) |
| 706 | + const LinearProgressIndicator(), |
| 707 | + if (createOnOpen && |
| 708 | + supportsRemoteAgents(community) && |
| 709 | + controller.failure.isNotEmpty) |
| 710 | + Padding( |
| 711 | + padding: const EdgeInsets.all(Grid.sm), |
| 712 | + child: Text(controller.failure), |
| 713 | + ), |
| 714 | + if (failed && keys.isEmpty) |
| 715 | + ListTile( |
| 716 | + title: const Text('Could not load agents'), |
| 717 | + trailing: TextButton( |
| 718 | + onPressed: refresh, |
| 719 | + child: const Text('Retry'), |
| 720 | + ), |
| 721 | + ), |
| 722 | + if (!loading && !failed && !needsSignIn && keys.isEmpty) |
| 723 | + const Padding( |
| 724 | + padding: EdgeInsets.all(Grid.sm), |
| 725 | + child: Text( |
| 726 | + 'You haven’t added any agents yet.', |
| 727 | + textAlign: TextAlign.center, |
| 728 | + ), |
| 729 | + ), |
| 730 | + ], |
| 731 | + ), |
| 732 | + ), |
| 733 | + AgentCardGrid( |
| 734 | + itemCount: keys.length, |
| 735 | + itemBuilder: (context, index) { |
| 736 | + final key = keys[index]; |
| 737 | + final remote = controller.agents |
| 738 | + .where((row) => row['agent_pubkey'] == key) |
| 739 | + .firstOrNull; |
| 740 | + final editable = |
| 741 | + community != null && |
| 742 | + supportsRemoteAgents(community) && |
| 743 | + controller.owner == community.pubkey && |
| 744 | + owned?.contains(key) == true && |
| 745 | + controller.activeAgents.contains(key) && |
| 746 | + remote != null; |
| 747 | + return AgentCard( |
| 748 | + key: ValueKey(key), |
| 749 | + name: names.labelFor(key), |
| 750 | + isBestie: key == bestie, |
| 751 | + imageUrl: |
| 752 | + profiles[key]?.avatarUrl ?? |
| 753 | + ownedDirectory.asData?.value |
| 754 | + .where((entry) => entry.pubkey == key) |
| 755 | + .firstOrNull |
| 756 | + ?.avatarUrl, |
| 757 | + location: remote != null ? 'Remote' : null, |
| 758 | + onOpen: () => onSelect(key), |
| 759 | + footer: editable |
| 760 | + ? RemoteAgentModelControl( |
| 761 | + key: ValueKey('model-$key'), |
| 762 | + controller: controller, |
| 763 | + agent: remote, |
| 764 | + community: community, |
| 765 | + isCurrent: () => |
| 766 | + ref |
| 767 | + .read(activeCommunityProvider) |
| 768 | + .asData |
| 769 | + ?.value |
| 770 | + ?.id == |
| 771 | + community.id, |
| 772 | + ) |
| 773 | + : null, |
| 774 | + subtitle: editable |
| 775 | + ? null |
| 776 | + : remote != null |
| 777 | + ? 'Builderbot agent' |
| 778 | + : needsSignIn |
| 779 | + ? null |
| 780 | + : 'Manage on desktop', |
| 781 | + ); |
| 782 | + }, |
| 783 | + ), |
| 784 | + ], |
| 785 | + ), |
| 786 | + ), |
| 787 | + ), |
668 | 788 | ); |
| 789 | + if (android) { |
| 790 | + return Scaffold( |
| 791 | + body: SafeArea( |
| 792 | + top: true, |
| 793 | + bottom: false, |
| 794 | + child: Column( |
| 795 | + children: [ |
| 796 | + SizedBox( |
| 797 | + height: kToolbarHeight, |
| 798 | + child: androidPageHeader( |
| 799 | + context, |
| 800 | + title: 'Agents', |
| 801 | + leading: IconButton( |
| 802 | + tooltip: 'Close agents', |
| 803 | + icon: const Icon(BuzzIcons.x), |
| 804 | + onPressed: onClose, |
| 805 | + style: androidNavigationButtonStyle(context), |
| 806 | + ), |
| 807 | + actions: [ |
| 808 | + if (supportsRemoteAgents(community)) |
| 809 | + IconButton( |
| 810 | + tooltip: 'Add agent', |
| 811 | + onPressed: addAgent, |
| 812 | + icon: const Icon(Icons.add), |
| 813 | + style: androidNavigationButtonStyle(context), |
| 814 | + ), |
| 815 | + ], |
| 816 | + ), |
| 817 | + ), |
| 818 | + Expanded(child: body), |
| 819 | + ], |
| 820 | + ), |
| 821 | + ), |
| 822 | + ); |
| 823 | + } |
669 | 824 | return FrostedScaffold( |
670 | 825 | backgroundColor: context.colors.surface, |
671 | 826 | appBar: FrostedAppBar( |
@@ -720,118 +875,7 @@ class AgentsPage extends HookConsumerWidget { |
720 | 875 | ), |
721 | 876 | ], |
722 | 877 | ), |
723 | | - body: SafeArea( |
724 | | - top: false, |
725 | | - child: Material( |
726 | | - color: Colors.transparent, |
727 | | - child: BeeRefreshIndicator( |
728 | | - edgeOffset: topHeight, |
729 | | - onRefresh: refresh, |
730 | | - child: CustomScrollView( |
731 | | - physics: const AlwaysScrollableScrollPhysics(), |
732 | | - slivers: [ |
733 | | - SliverToBoxAdapter(child: SizedBox(height: topHeight)), |
734 | | - if (signInNeeded) |
735 | | - SliverToBoxAdapter( |
736 | | - child: ReconnectCapsule( |
737 | | - inline: true, |
738 | | - message: signingIn |
739 | | - ? 'Finish sign-in in browser' |
740 | | - : 'Reconnect to Builderlab', |
741 | | - actionLabel: signingIn ? 'Cancel' : 'Sign in', |
742 | | - destructiveAction: signingIn, |
743 | | - onSignIn: () => unawaited( |
744 | | - signingIn ? flow.leave() : flow.reconnectAccount(), |
745 | | - ), |
746 | | - ), |
747 | | - ), |
748 | | - SliverToBoxAdapter( |
749 | | - child: Column( |
750 | | - children: [ |
751 | | - if (createOnOpen && (loading || signingIn)) |
752 | | - const LinearProgressIndicator(), |
753 | | - if (createOnOpen && |
754 | | - supportsRemoteAgents(community) && |
755 | | - controller.failure.isNotEmpty) |
756 | | - Padding( |
757 | | - padding: const EdgeInsets.all(Grid.sm), |
758 | | - child: Text(controller.failure), |
759 | | - ), |
760 | | - if (failed && keys.isEmpty) |
761 | | - ListTile( |
762 | | - title: const Text('Could not load agents'), |
763 | | - trailing: TextButton( |
764 | | - onPressed: refresh, |
765 | | - child: const Text('Retry'), |
766 | | - ), |
767 | | - ), |
768 | | - if (!loading && !failed && !needsSignIn && keys.isEmpty) |
769 | | - const Padding( |
770 | | - padding: EdgeInsets.all(Grid.sm), |
771 | | - child: Text( |
772 | | - 'You haven’t added any agents yet.', |
773 | | - textAlign: TextAlign.center, |
774 | | - ), |
775 | | - ), |
776 | | - ], |
777 | | - ), |
778 | | - ), |
779 | | - AgentCardGrid( |
780 | | - itemCount: keys.length, |
781 | | - itemBuilder: (context, index) { |
782 | | - final key = keys[index]; |
783 | | - final remote = controller.agents |
784 | | - .where((row) => row['agent_pubkey'] == key) |
785 | | - .firstOrNull; |
786 | | - final editable = |
787 | | - community != null && |
788 | | - supportsRemoteAgents(community) && |
789 | | - controller.owner == community.pubkey && |
790 | | - owned?.contains(key) == true && |
791 | | - controller.activeAgents.contains(key) && |
792 | | - remote != null; |
793 | | - return AgentCard( |
794 | | - key: ValueKey(key), |
795 | | - name: names.labelFor(key), |
796 | | - isBestie: key == bestie, |
797 | | - imageUrl: |
798 | | - profiles[key]?.avatarUrl ?? |
799 | | - ownedDirectory.asData?.value |
800 | | - .where((entry) => entry.pubkey == key) |
801 | | - .firstOrNull |
802 | | - ?.avatarUrl, |
803 | | - location: remote != null ? 'Remote' : null, |
804 | | - onOpen: () => onSelect(key), |
805 | | - footer: editable |
806 | | - ? RemoteAgentModelControl( |
807 | | - key: ValueKey('model-$key'), |
808 | | - controller: controller, |
809 | | - agent: remote, |
810 | | - community: community, |
811 | | - isCurrent: () => |
812 | | - ref |
813 | | - .read(activeCommunityProvider) |
814 | | - .asData |
815 | | - ?.value |
816 | | - ?.id == |
817 | | - community.id, |
818 | | - ) |
819 | | - : null, |
820 | | - subtitle: editable |
821 | | - ? null |
822 | | - : remote != null |
823 | | - ? 'Builderbot agent' |
824 | | - : needsSignIn |
825 | | - ? null |
826 | | - : 'Manage on desktop', |
827 | | - ); |
828 | | - }, |
829 | | - ), |
830 | | - ], |
831 | | - ), |
832 | | - ), |
833 | | - ), |
834 | | - ), |
| 878 | + body: body, |
835 | 879 | ); |
836 | 880 | } |
837 | 881 | } |
|
0 commit comments