Repository navigation
feat(mobile): open a prefilled Create agent form from Builderlab agent cards #8912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ab51633
c313f8a
897bcaf
13a6b30
62546e5
025afcd
f1abca5
4dace12
a22a7b4
638f5ec
21b5001
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- A card link arriving while a form or sheet is open in Agents shows a snackbar instead of replacing the open work. - Reload the registry for the signed-in account before the unfinished setup check, so a link that needed sign-in still respects a saved setup. - Unexpected card responses show a retryable message. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Tom Brow <[email protected]>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,10 @@ import 'bestie_agent_action.dart'; | |
|
|
||
| Route<Channel>? _openAgentsRoute; | ||
|
|
||
| /// The open Agents stack's nested navigator, so a link can tell whether | ||
| /// anything is open above its list. | ||
| GlobalKey<NavigatorState>? _openAgentsNavigator; | ||
|
|
||
| /// Opens the active community's full-page Agents navigation stack. | ||
| /// | ||
| /// A [draft] from a `buzz://agent/new` link opens [CreateAgentPage] pre-filled | ||
|
|
@@ -47,23 +51,39 @@ Future<void> showAgents( | |
| }) async { | ||
| final container = ProviderScope.containerOf(context); | ||
| final controller = container.read(remoteAgentControllerProvider); | ||
| unawaited(controller.run(controller.refresh)); | ||
| final navigator = Navigator.of(context); | ||
| // A link replaces an Agents stack that is already open instead of stacking | ||
| // a second one on top of it. | ||
| // a second one on top of it, but only while it shows just its list: a form, | ||
| // profile or dialog above it may hold work the user hasn't finished. | ||
| final open = _openAgentsRoute; | ||
| if (draft != null && | ||
| open != null && | ||
| open.isActive && | ||
| open.navigator == navigator) { | ||
| if (!open.isCurrent || | ||
| (_openAgentsNavigator?.currentState?.canPop() ?? false)) { | ||
| ScaffoldMessenger.maybeOf(context)?.showFeedbackSnackBar( | ||
| const SnackBar( | ||
| content: Text( | ||
| 'Finish or close what’s open in Agents, then reopen the link.', | ||
| ), | ||
| ), | ||
| kind: ToastKind.error, | ||
| ); | ||
| return; | ||
| } | ||
| navigator.removeRoute(open); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Blocker: a link discards whatever is open in the Agents stack.
The journey's last step only covers an idle list with nothing above it. Fix: replace only when the nested navigator can't pop, no root modal covers the route, and |
||
| } | ||
| unawaited(controller.run(controller.refresh)); | ||
| final route = MaterialPageRoute<Channel>( | ||
| builder: (_) => _AgentsNavigation(controller: controller, draft: draft), | ||
| ); | ||
| _openAgentsRoute = route; | ||
| final channel = await navigator.push(route); | ||
| if (identical(_openAgentsRoute, route)) _openAgentsRoute = null; | ||
| if (identical(_openAgentsRoute, route)) { | ||
| _openAgentsRoute = null; | ||
| _openAgentsNavigator = null; | ||
| } | ||
| if (channel != null && context.mounted) { | ||
| await Navigator.of(context).push<void>( | ||
| MaterialPageRoute(builder: (_) => ChannelDetailPage(channel: channel)), | ||
|
|
@@ -84,6 +104,9 @@ class _AgentsNavigation extends HookConsumerWidget { | |
| final navigator = useMemoized(() => GlobalKey<NavigatorState>(), [ | ||
| communityId, | ||
| ]); | ||
| if (identical(ModalRoute.of(context), _openAgentsRoute)) { | ||
| _openAgentsNavigator = navigator; | ||
| } | ||
| return NavigatorPopHandler<Channel>( | ||
| onPopWithResult: (result) { | ||
| if (navigator.currentState?.canPop() ?? false) { | ||
|
|
@@ -288,6 +311,7 @@ class AgentsPage extends HookConsumerWidget { | |
| // Open a link's draft once: sign in first if needed, then wait for the | ||
| // registry so an unfinished setup is known before anything is offered. | ||
| final draftStep = useRef(draft == null ? _DraftStep.done : _DraftStep.wait); | ||
| final draftRefreshFor = useRef<String?>(null); | ||
| // Looked up during build: effects cannot read inherited widgets, and | ||
| // snack bars cannot show while a frame is building. | ||
| final messenger = ScaffoldMessenger.maybeOf(context); | ||
|
|
@@ -333,6 +357,18 @@ class AgentsPage extends HookConsumerWidget { | |
| } | ||
| return null; | ||
| } | ||
| // The setup check below needs this account's registry, which a | ||
| // sign-in started by the link doesn't reload by itself. | ||
| final subject = controller.account.account!.subject; | ||
| if (!controller.loadedForCurrentAccount) { | ||
| if (draftRefreshFor.value != subject) { | ||
| draftRefreshFor.value = subject; | ||
| unawaited(controller.run(controller.refresh)); | ||
| } else { | ||
| drop('Couldn’t load your agents. Reopen the link to retry.'); | ||
| } | ||
| return null; | ||
| } | ||
| if (controller.listingFailed) { | ||
| drop('Couldn’t load your agents. Reopen the link to retry.'); | ||
| return null; | ||
|
|
@@ -345,7 +381,6 @@ class AgentsPage extends HookConsumerWidget { | |
| } | ||
| draftStep.value = _DraftStep.done; | ||
| // The checks above hold for this account; the fetch can take minutes. | ||
| final subject = controller.account.account?.subject; | ||
| final client = ref.read(agentCardClientProvider)(); | ||
| unawaited(() async { | ||
| // Hold Create (+) off while the card loads, like an open form does. | ||
|
|
@@ -393,6 +428,7 @@ class AgentsPage extends HookConsumerWidget { | |
| flow.stage, | ||
| community?.id, | ||
| controller.account.account?.subject, | ||
| controller.loadedForCurrentAccount, | ||
| ], | ||
| ); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import 'dart:convert'; | ||
|
|
||
| import 'package:buzz/features/agents/agent_creation_draft.dart'; | ||
| import 'package:buzz/features/agents/agents_page.dart'; | ||
| import 'package:buzz/features/agents/create_agent_page.dart'; | ||
| import 'package:buzz/shared/deeplink/deep_link.dart'; | ||
| import 'package:buzz/shared/hosted/hosted_environment.dart'; | ||
| import 'package:buzz/shared/hosted/hosted_flow.dart'; | ||
| import 'package:buzz/shared/hosted/hosted_flow_provider.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:http/http.dart' as http; | ||
| import 'package:http/testing.dart'; | ||
| import 'package:shared_preferences/shared_preferences.dart'; | ||
|
|
||
| import '../../helpers/remote_agents_fixture.dart'; | ||
| import 'agents_harness.dart'; | ||
|
|
||
| /// Fakes only the browser sign-in. Like the real flow, completion clears | ||
| /// `reconnecting` in the same synchronous step that reports `complete`. | ||
| class _SignInFlow extends ChangeNotifier implements HostedFlow { | ||
| @override | ||
| HostedFlowStage stage = HostedFlowStage.idle; | ||
| @override | ||
| bool reconnecting = false; | ||
| int starts = 0; | ||
|
|
||
| @override | ||
| Future<void> reconnectAccount({bool changeAccount = false}) async { | ||
| starts++; | ||
| reconnecting = true; | ||
| stage = HostedFlowStage.signIn; | ||
| notifyListeners(); | ||
| } | ||
|
|
||
| void complete() { | ||
| stage = HostedFlowStage.complete; | ||
| reconnecting = false; | ||
| notifyListeners(); | ||
| } | ||
|
|
||
| @override | ||
| dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | ||
| } | ||
|
|
||
| void main() { | ||
| testWidgets( | ||
| 'a link that needs sign-in still respects a saved unfinished setup', | ||
| (tester) async { | ||
| final h = await AgentsHarness.create(); | ||
| // The login expired, but this account saved an unfinished setup. | ||
| h.registry.signedIn = false; | ||
| final prefs = await SharedPreferences.getInstance(); | ||
| await prefs.setString( | ||
| 'remote-agents:${HostedEnvironment.origin.host}:$fakeSubject:pending', | ||
| jsonEncode({ | ||
| 'name': 'Saved', | ||
| 'instructions': '', | ||
| 'community': h.community.relayUrl, | ||
| 'owner': fakeOwner.public, | ||
| 'request': 'saved-request', | ||
| }), | ||
| ); | ||
| final flow = _SignInFlow(); | ||
| var cardFetches = 0; | ||
| await h.open( | ||
| tester, | ||
| directory: const [], | ||
| overrides: [ | ||
| hostedFlowProvider.overrideWithValue(flow), | ||
| agentCardClientProvider.overrideWithValue( | ||
| () => MockClient((_) async { | ||
| cardFetches++; | ||
| return http.Response('{}', 404); | ||
| }), | ||
| ), | ||
| ], | ||
| home: Builder( | ||
| builder: (context) => Scaffold( | ||
| body: TextButton( | ||
| onPressed: () => showAgents( | ||
| context, | ||
| draft: const AgentCreationDeepLink('av_card'), | ||
| ), | ||
| child: const Text('Open link'), | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| await tester.tap(find.text('Open link')); | ||
| await tester.pumpAndSettle(); | ||
| expect(flow.starts, 1); | ||
|
|
||
| // Sign-in lands. The registry is reloaded for this account before the | ||
| // card is considered, so the saved setup blocks it. | ||
| h.registry.signedIn = true; | ||
| flow.complete(); | ||
| await tester.pumpAndSettle(); | ||
| expect(find.byType(CreateAgentPage), findsNothing); | ||
| expect(cardFetches, 0); | ||
| expect( | ||
| find.text( | ||
| 'Finish your unfinished agent setup first, then reopen the link.', | ||
| ), | ||
| findsOneWidget, | ||
| ); | ||
| expect(h.controller.pending?['name'], 'Saved'); | ||
| }, | ||
| skip: !HostedEnvironment.enabled, | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 Optional: this guard still lets a link replace the list while a model save that started on the list is in flight.
RemoteAgentModelControlpassescontext.mountedintoisCurrent(remote_agent_model_control.dart:107-115). If the route is swapped mid-save,updateModel's fences throw:/update-agent, the server keeps the new model but the list shows the old one, and "Model updated" never appears.remote_agents.dart:448,454), the change is never sent and no error is shown.The window is a few seconds and needs the user to leave the app, so this isn't blocking. A plain
controller.busycheck would be wrong here: it also blocks on the refresh every Agents open runs (:77,:208). Refusing only while a mutating operation is in flight would fix it, as would keeping the save's ownership when the route changes.Separately, removing
!open.isCurrent(the root-dialog case) fails no test, if you want a journey step for it.