Files
buzz/mobile/lib/features/agents/agent_model_picker.dart
Tom Brow a7e65c91da feat(mobile): choose remote agent models and gate agents on Builderlab sign-in (#8650)
Follow-up to [#8626](https://github.com/block/buzz/pull/8626). Mobile
remote-agent creation now matches desktop.

- **Model and reasoning effort:** Create agent has Model and Reasoning
effort menus. Their options come from the remote service's catalog, and
nothing is preselected (same as desktop). The server checks the
selection against the catalog again before registering, and saves it on
the agent.
- **Builderlab gate:** creating a remote agent requires a hosted
community and Builderlab sign-in. The Agents directory, community bots
and the Bestie chooser stay available without it. Signing out closes an
open Create agent sheet; the Agents sheet stays open.
- **Enrollment:** `attest-agent` enrolls the agent in the requested
community, as on desktop, so the separate `add-buzz-subscription` call
is gone.
- **Quieter progress:** spinners replace the progress bars and the
"Working…" label. Status and success text ("is ready", "Remote agent
deleted.", setup steps) is gone, and only failures show text. Refreshing
an already-loaded agent list no longer blanks it.
- **Shared setting menu:** `BuzzSettingMenu` is a bordered setting row
that opens a Material 3 menu spanning the row's width. Opening it
dismisses the keyboard. The channel-TTL setting in Create channel uses
it too.

Agent avatars and QR/link-based creation follow in stacked PRs. Editing
existing agents comes later.

| Agents | Create | Model menu |
| --- | --- | --- |
| <img
src="https://raw.githubusercontent.com/block/buzz/d0bee87c45d30b9bdd2163a75966ccd5d64f322a/pr-8650--1-agents.png"
width="240"> | <img
src="https://raw.githubusercontent.com/block/buzz/d0bee87c45d30b9bdd2163a75966ccd5d64f322a/pr-8650--2-create.png"
width="240"> | <img
src="https://raw.githubusercontent.com/block/buzz/d0bee87c45d30b9bdd2163a75966ccd5d64f322a/pr-8650--3-model-menu.png"
width="240"> |

### Validation

- Checked on the staging iOS simulator with a Builderlab account: the
Agents list, the Create sheet, and the model and effort menus (including
with the keyboard open).
- Added tests: catalog-gated model selection (including switching models
clears an unsupported effort), the Builderlab sign-in gate, controller
creation and resume with a model, a failed listing reported instead of
an empty registry, and create sheet busy and failure states (including
the catalog reload after a rejected create).
- The hosted-only agent tests are skipped without Builderlab defines,
which `mobile-test` doesn't pass. They pass locally with the staging
defines (20/20).
- Not covered: Android.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: george <973be878edd6d4f79692a3827f20a6f7fe0ed0362f269ff6b6ba8867033d7d8e@sprout-oss.stage.blox.sqprod.co>
2026-10-29 08:43:45 -07:00

109 lines
3.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import '../../shared/agents/remote_agents.dart';
import '../../shared/theme/theme.dart';
import '../../shared/widgets/buzz_setting_menu.dart';
/// Uses the server catalog for both menus, including model-specific efforts.
class AgentModelPicker extends StatelessWidget {
const AgentModelPicker({
required this.controller,
required this.catalog,
required this.onRetry,
required this.onChanged,
this.modelId,
this.effort,
super.key,
});
final RemoteAgentController controller;
final AsyncSnapshot<List<RemoteAgentModel>> catalog;
final VoidCallback onRetry;
final String? modelId;
final String? effort;
final void Function(String?, String?) onChanged;
@override
Widget build(BuildContext context) {
// While loading, show the same rows disabled so nothing shifts.
final loading = catalog.connectionState != ConnectionState.done;
if (!loading && (catalog.hasError || catalog.data!.isEmpty)) {
return Column(
children: [
Text(
catalog.hasError
? 'Could not load available models.'
: 'No models are available.',
),
TextButton(onPressed: onRetry, child: const Text('Retry models')),
],
);
}
final models = loading ? const <RemoteAgentModel>[] : catalog.data!;
final selected = models.where((model) => model.id == modelId).firstOrNull;
final validEffort = selected?.efforts.contains(effort) == true
? effort
: null;
final enabled = !loading && !controller.busy;
return Column(
children: [
BuzzSettingMenu<String>(
controlKey: const Key('agent-model'),
enabled: enabled,
label: 'Model',
onSelected: (value) => onChanged(value, null),
options: [
for (final model in models)
BuzzSettingMenuOption(label: model.name, value: model.id),
],
value: selected?.id,
valueLabel: loading ? 'Loading…' : selected?.name ?? 'Choose',
),
const SizedBox(height: Grid.xs),
BuzzSettingMenu<String>(
controlKey: const Key('agent-effort'),
enabled: enabled && selected != null,
label: 'Reasoning effort',
onSelected: (value) => onChanged(selected!.id, value),
options: [
for (final value in selected?.efforts ?? <String>[])
BuzzSettingMenuOption(label: value, value: value),
],
value: validEffort,
valueLabel: loading ? 'Loading…' : validEffort ?? 'Choose',
),
if (modelId != null && selected == null ||
effort != null && validEffort == null)
const Text(
'Choose an available model and supported reasoning effort.',
),
],
);
}
}
/// Shares catalog loading with the submit action so stale selections cannot save.
(AsyncSnapshot<List<RemoteAgentModel>>, VoidCallback) useAgentModelCatalog(
RemoteAgentController controller,
) {
final retry = useState(0);
final future = useMemoized(controller.modelCatalog, [
controller,
retry.value,
]);
return (useFuture(future, preserveState: false), () => retry.value++);
}
/// True only after the loaded catalog confirms this exact pair.
bool validAgentModelSelection(
AsyncSnapshot<List<RemoteAgentModel>> catalog,
String? model,
String? effort,
) =>
catalog.connectionState == ConnectionState.done &&
!catalog.hasError &&
catalog.data?.any(
(entry) => entry.id == model && entry.efforts.contains(effort),
) ==
true;