Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Swarm Manage models: Set up instead of a switch, and a redesigned window

bitcoinbuilderdf30c4d3eade
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index ccb338eb2..0ede9a98d 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -11294,6 +11294,19 @@ class AppNotifier extends ChangeNotifier {
timeout: const Duration(seconds: 12),
);
+ /// Sets a Swarm's grid up on [machineId], this computer of the Swarm owner's (CLI `lib/swarmGrid.ts`): `grid`
+ /// installed and signed in with the Harness account when it is not, the grid created, [members] added and anyone
+ /// else removed. Minutes on a computer that has never run grid.
+ Future<Map<String, dynamic>> swarmGridSync(
+ String machineId,
+ String grid,
+ List<String> members,
+ ) => _conn(machineId).request(
+ 'grid_swarm_sync',
+ payload: {'grid': grid, 'members': members},
+ timeout: const Duration(minutes: 5),
+ );
+
/// The models shared with this person that [machineId] offers to the Swarm whose grid is [grid] (CLI `lib/swarmOffers.ts`).
Future<Map<String, dynamic>> swarmOffers(String machineId, String grid) =>
_conn(machineId).request(
diff --git a/desktop/lib/state/swarm_search.dart b/desktop/lib/state/swarm_search.dart
index 72bddd8c8..e06556050 100644
--- a/desktop/lib/state/swarm_search.dart
+++ b/desktop/lib/state/swarm_search.dart
@@ -112,7 +112,10 @@ class SwarmSearchController extends ChangeNotifier {
_locations = locations ?? SwarmLocationCatalog(),
targetId = app.activeSwarmId,
targetName = app.activeSwarm.name {
- if (activityFirst && history == null && !navigating && harnessContext == null) {
+ if (activityFirst &&
+ history == null &&
+ !navigating &&
+ harnessContext == null) {
_content = SessionContentSearch(
machines: () => app.searchableMachineIds,
ask: (machineId, words, when) =>
@@ -325,10 +328,8 @@ class SwarmSearchController extends ChangeNotifier {
if (entry.apiModel case final model?) {
return swarm.shared(entry.api!.id, model.id) ? 'Shared' : null;
}
- if (entry.gridModel case GridModel(
- :final id,
- grid: final sharedGrid?,
- ) when local == null) {
+ if (entry.gridModel case GridModel(:final id, grid: final sharedGrid?)
+ when local == null) {
return swarm.offered(sharedGrid, id) ? 'Offered' : null;
}
}
@@ -523,10 +524,8 @@ class SwarmSearchController extends ChangeNotifier {
}
// A model shared with the person, on someone else's grid: offering it lets the Lead start Builders on their
// machines on it (owner, 2026-10-23: a choice, as running a model or sharing an API is).
- if (entry.gridModel case GridModel(
- :final id,
- grid: final sharedGrid?,
- ) when entry.api == null) {
+ if (entry.gridModel case GridModel(:final id, grid: final sharedGrid?)
+ when entry.api == null) {
final on = swarm.offered(sharedGrid, id);
return (
label: on ? 'Stop offering' : 'Offer to Swarm',
@@ -1278,7 +1277,8 @@ class SwarmSearchController extends ChangeNotifier {
bool get previewVisible => _previewVisible;
bool get supportsPreview =>
harnessContext == null &&
- history == null && (setupLayout || !isCommandMode && !isHelpMode);
+ history == null &&
+ (setupLayout || !isCommandMode && !isHelpMode);
bool get canPreview =>
supportsPreview &&
selected != null &&
@@ -2308,6 +2308,9 @@ class SwarmSearchController extends ChangeNotifier {
? installed
: order[a.id]!.compareTo(order[b.id]!);
});
+ if (modelScope case final scope?) {
+ rows = rows.where((row) => modelSection(row) == scope).toList();
+ }
}
if (!isCommandMode && !isHelpMode) {
if (noteFor?.call(query) case final note?) {
@@ -2355,7 +2358,9 @@ class SwarmSearchController extends ChangeNotifier {
? 1
: cursor.clamp(0, rows.length - 1);
if (harnessContext != null && preferred == null) {
- final agent = rows.indexWhere((row) => row.agentId != null && canSubmit(row));
+ final agent = rows.indexWhere(
+ (row) => row.agentId != null && canSubmit(row),
+ );
if (agent >= 0) cursor = agent;
}
// Nor on a row Return cannot take: "Already added", dimmed, with its
@@ -2413,6 +2418,29 @@ class SwarmSearchController extends ChangeNotifier {
notifyListeners();
}
+ /// The models list of a Swarm's Manage models, drawn in its own way (`super_tabs/local_models.dart`).
+ bool get isSwarmModels => isModelMode && swarmModels != null;
+
+ /// How many of the Swarm's APIs' models [row]'s API shares with the Swarm. Null for any row but an API's own.
+ int? swarmApiShareCount(SwarmDestination row) {
+ final swarm = swarmModels;
+ if (swarm == null || !isApiRow(row)) return null;
+ final id = models!.entries[row.modelId]!.api!.id;
+ return swarm.shares.where((key) => key.startsWith('$id\u0000')).length;
+ }
+
+ /// The one model section the list shows, or every section: the scope buttons of a Swarm's Manage models.
+ ModelSearchSection? modelScope;
+
+ void setModelScope(ModelSearchSection? section) {
+ if (modelScope == section) return;
+ modelScope = section;
+ cursor = 0;
+ _selectedId = null;
+ _filter();
+ notifyListeners();
+ }
+
void setQuery(String value) {
if (query == value) return;
if (_quickAccessPrefix.hasMatch(value.trimLeft())) _groupScope = null;
@@ -2635,7 +2663,9 @@ class SwarmSearchController extends ChangeNotifier {
bool alreadyHere(SwarmDestination row) =>
harnessContext == null &&
- adding && row.agentId != null && _presentIds.contains(row.id);
+ adding &&
+ row.agentId != null &&
+ _presentIds.contains(row.id);
bool canAdd(SwarmDestination? row) => harnessContext != null
? adding && row?.agentId != null && sessionUnavailable(row) == null
diff --git a/desktop/lib/super_tabs/local_models.dart b/desktop/lib/super_tabs/local_models.dart
index e518acb65..1db1bcab1 100644
--- a/desktop/lib/super_tabs/local_models.dart
+++ b/desktop/lib/super_tabs/local_models.dart
@@ -5,22 +5,23 @@ import 'package:flutter/material.dart';
import '../models/model_search_catalog.dart';
import '../models/swarm_models_target.dart';
import '../shared/theme/app_icons.dart';
+import '../shared/theme/app_theme.dart' as grid;
import '../shared/widgets/app_dialog.dart';
import '../shared/widgets/app_icon_button.dart';
import '../state/app_state.dart';
import '../state/swarm_navigation.dart';
import '../state/swarm_search.dart';
import '../widgets/desktop_chrome.dart';
+import '../widgets/key_hints.dart';
import '../widgets/swarm_resource_preview.dart';
import '../widgets/swarm_switcher.dart';
import 'controller.dart';
import 'dialog_scope.dart';
import 'model.dart';
-/// The Swarm's Local models (docs/plans/2026-10-23-swarm-local-models.md): the owner's switch for the add-on, off until
-/// they turn it on since it is the only thing here that asks grid for anything, and, once it is ready, the Models picker
-/// of ⌘I made for the Swarm ([SwarmModelsTarget]): your models to run for it, models to get, your APIs to share with it,
-/// and the models shared with you that agents on your machines can use.
+/// The Swarm's models (docs/plans/2026-10-23-swarm-local-models.md). Until the owner sets them up there is only a
+/// Set up panel, since it is the only thing here that asks grid for anything; set up, it is the Models picker of ⌘I made
+/// for the Swarm ([SwarmModelsTarget]): your models to run for it, models to get, and your APIs to share with it.
Future<void> showSwarmLocalModels(
BuildContext context,
SuperTabController c, {
@@ -35,7 +36,7 @@ Future<void> showSwarmLocalModels(
),
);
-class _SwarmModelsWindow extends StatelessWidget {
+class _SwarmModelsWindow extends StatefulWidget {
const _SwarmModelsWindow({
required this.controller,
required this.app,
@@ -46,9 +47,81 @@ class _SwarmModelsWindow extends StatelessWidget {
final AppNotifier? app;
final DateTime Function() now;
+ @override
+ State<_SwarmModelsWindow> createState() => _SwarmModelsWindowState();
+}
+
+class _SwarmModelsWindowState extends State<_SwarmModelsWindow> {
+ /// A Set up (or Try again) under way on this computer, and why the last one failed.
+ bool _settingUp = false;
+ String? _error;
+
+ /// Sets the Swarm's models up from this computer, at once: turns them on (the backend names the Swarm's grid),
+ /// then has this computer's Harness set grid up — installed and signed in with the Harness account if it is not —
+ /// create the grid and add the Swarm's people, and tells the Swarm how that went. The owner's computers keep the
+ /// members in step afterwards (CLI `superTabs/swarmGrids.ts`).
+ Future<void> _setUp() async {
+ final c = widget.controller, app = widget.app;
+ setState(() {
+ _settingUp = true;
+ _error = null;
+ });
+ try {
+ final snapshot = c.snapshot;
+ var grid = snapshot?.localModels?.enabled == true
+ ? snapshot!.localModels!.grid
+ : null;
+ if (grid == null) {
+ final result = await c.command({
+ 'type': 'localModels.set',
+ 'enabled': true,
+ });
+ grid = result?['grid'] as String? ?? c.snapshot?.localModels?.grid;
+ }
+ if (grid == null) {
+ _error =
+ c.operationError ?? 'The Swarm could not be reached. Try again.';
+ return;
+ }
+ final machineId = app?.modelManager.machine?.machine.machineId;
+ if (app == null || machineId == null) {
+ // Nothing here can run grid: the owner's other computers finish it in the background.
+ return;
+ }
+ final members = [
+ for (final person in c.snapshot?.people ?? const <SuperTabPerson>[])
+ if (person.role != 'viewer' && person.id != c.snapshot?.ownerId)
+ person.email,
+ ];
+ Map<String, dynamic> answer;
+ try {
+ answer = await app.swarmGridSync(machineId, grid, members);
+ } catch (_) {
+ answer = {
+ 'ready': false,
+ 'error': 'This computer could not be reached. Try again.',
+ };
+ }
+ final ready = answer['ready'] == true;
+ final error = answer['error'] is String
+ ? answer['error'] as String
+ : null;
+ await c.command({
+ 'type': 'localModels.status',
+ 'grid': grid,
+ 'ready': ready,
+ if (error != null)
+ 'error': error.length > 500 ? error.substring(0, 500) : error,
+ });
+ if (!ready) _error = error ?? 'Grid could not be set up. Try again.';
+ } finally {
+ if (mounted) setState(() => _settingUp = false);
+ }
+ }
+
@override
Widget build(BuildContext context) {
- final c = controller;
+ final c = widget.controller, app = widget.app;
final size = MediaQuery.sizeOf(context);
return ListenableBuilder(
listenable: c,
@@ -56,59 +129,119 @@ class _SwarmModelsWindow extends StatelessWidget {
final local = c.snapshot?.localModels;
final on = local?.enabled == true;
final picker = on && local?.ready == true && app != null;
+ final String? failed = _settingUp
+ ? null
+ : _error ??
+ (on && local?.ready == false
+ ? local?.error ?? 'grid refused the request'
+ : null);
final header = Padding(
- padding: const EdgeInsets.fromLTRB(24, 20, 16, 12),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisSize: MainAxisSize.min,
+ padding: EdgeInsets.fromLTRB(24, 18, 16, picker ? 14 : 4),
+ child: Row(
children: [
- Row(
- children: [
- Expanded(
- child: Text(
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
'Manage models',
- style: DesktopChrome.text(size: 15, medium: true),
+ style: DesktopChrome.text(
+ size: 15,
+ medium: true,
+ height: 1.35,
+ ).copyWith(fontWeight: FontWeight.w600),
),
- ),
- Text('Use local models', style: DesktopChrome.control()),
- const SizedBox(width: 8),
- Switch(
- key: const ValueKey('super-local-models-switch'),
- value: on,
- onChanged: !c.isOwner || !c.canWrite || c.saving
- ? null
- : (value) => unawaited(
- c.command({
- 'type': 'localModels.set',
- 'enabled': value,
- }),
+ if (picker) ...[
+ const SizedBox(height: 2),
+ Row(
+ key: const ValueKey('super-local-models-ready'),
+ children: [
+ Container(
+ width: 6,
+ height: 6,
+ decoration: BoxDecoration(
+ color: grid.AppPalette.online,
+ shape: BoxShape.circle,
+ ),
),
- ),
- const SizedBox(width: 4),
- AppIconButton(
- key: const ValueKey('super-local-models-close'),
- tooltip: 'Close',
- icon: AppIcons.close,
- onPressed: () => Navigator.pop(context),
- ),
- ],
+ const SizedBox(width: 6),
+ Text(
+ 'Swarm grid ready · ${_capitalized(thisComputerName())}',
+ style: DesktopChrome.metadata(),
+ ),
+ ],
+ ),
+ ],
+ ],
+ ),
+ ),
+ AppIconButton(
+ key: const ValueKey('super-local-models-close'),
+ tooltip: 'Close',
+ icon: AppIcons.close,
+ onPressed: () => Navigator.pop(context),
),
- const SizedBox(height: 4),
+ ],
+ ),
+ );
+ // Before it is set up, and while it is being set up or has failed: one panel, as ⌘I's Set up is.
+ final setup = Padding(
+ padding: const EdgeInsets.fromLTRB(24, 4, 24, 20),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
Text(
- 'People in this Swarm can run AI models on their own machines and share their APIs. '
- 'The product manager can give simple tasks to them, at no subscription cost.',
+ 'Run models on your own machines for this Swarm, and share your APIs with it. '
+ 'The product manager can then give simple tasks to them, at no subscription cost.',
style: DesktopChrome.text(),
),
- const SizedBox(height: 8),
+ const SizedBox(height: 12),
Text(
key: const ValueKey('super-local-models-status'),
- _status(local, owner: c.isOwner),
+ _settingUp || (on && local?.ready == null)
+ ? (c.isOwner
+ ? 'Setting up… The first time can take a few minutes.'
+ : 'Being set up on the owner\'s computer.')
+ : failed != null
+ ? 'Could not set up: ${_sentence(failed)}'
+ : c.isOwner
+ ? 'Set up gets this computer ready with your Harness account and creates the Swarm\'s grid. '
+ 'People in the Swarm are added to it, now and as they join.'
+ : 'The Swarm owner has not set up models yet.',
style: DesktopChrome.metadata(
- color: on && local?.ready == false
+ color: failed != null
? Theme.of(context).colorScheme.error
: null,
),
),
+ if (c.isOwner) ...[
+ const SizedBox(height: 16),
+ Row(
+ children: [
+ FilledButton(
+ key: const ValueKey('super-local-models-setup'),
+ onPressed: _settingUp || !c.canWrite || c.saving
+ ? null
+ : () => unawaited(_setUp()),
+ child: Text(
+ _settingUp
+ ? 'Setting up…'
+ : failed != null
+ ? 'Try again'
+ : 'Set up',
+ ),
+ ),
+ if (_settingUp) ...[
+ const SizedBox(width: 12),
+ const SizedBox.square(
+ dimension: 14,
+ child: CircularProgressIndicator(strokeWidth: 2),
+ ),
+ ],
+ ],
+ ),
+ ],
],
),
);
@@ -125,12 +258,11 @@ class _SwarmModelsWindow extends StatelessWidget {
children: [
header,
if (picker) ...[
- Divider(height: 1, color: DesktopChrome.rim),
Expanded(
- child: _SwarmModelsPicker(app: app!, grid: local!.grid),
+ child: _SwarmModelsPicker(app: app, grid: local!.grid),
),
] else
- const SizedBox(height: 12),
+ setup,
],
),
),
@@ -214,85 +346,201 @@ class _SwarmModelsPickerState extends State<_SwarmModelsPicker> {
@override
Widget build(BuildContext context) {
+ final hints = KeyHints.visibleOf(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
- padding: const EdgeInsets.fromLTRB(24, 12, 16, 8),
+ padding: const EdgeInsets.fromLTRB(24, 0, 24, 14),
child: Row(
children: [
- Icon(AppIcons.search, size: 18, color: DesktopChrome.muted),
+ Expanded(child: _searchField()),
const SizedBox(width: 12),
- Expanded(
- child: TextField(
- key: const ValueKey('super-local-models-search'),
- controller: _editing,
- focusNode: _focus,
- autofocus: true,
- onChanged: _query,
- onSubmitted: (_) {
- _choose(_search.submit());
- _focus.requestFocus();
- },
- // As ⌘I's search field: no box of its own, the panel's divider is its edge.
- decoration: InputDecoration(
- hintText: 'Search models',
- hintStyle: DesktopChrome.text(color: DesktopChrome.muted),
- isDense: true,
- contentPadding: EdgeInsets.zero,
- border: InputBorder.none,
- enabledBorder: InputBorder.none,
- focusedBorder: InputBorder.none,
- filled: false,
- ),
- style: DesktopChrome.text(),
- ),
+ ListenableBuilder(
+ listenable: _search,
+ builder: (context, _) => _SwarmModelScopes(search: _search),
),
],
),
),
+ Divider(height: 1, color: DesktopChrome.rim),
Expanded(
- child: ListenableBuilder(
- listenable: Listenable.merge([_search, _target]),
- builder: (context, _) => SwarmSearchResults(
- search: _search,
- onChoose: _choose,
- onRefocus: _focus.requestFocus,
- sideBySideMinWidth: 700,
- previewBuilder: () => SwarmResourcePreview(
+ // The rows are the preview's to act on; the hints for both are this window's footer.
+ child: KeyHints(
+ visible: false,
+ child: ListenableBuilder(
+ listenable: Listenable.merge([_search, _target]),
+ builder: (context, _) => SwarmSearchResults(
search: _search,
- controls: _controls,
onChoose: _choose,
onRefocus: _focus.requestFocus,
- onModalChanged: (_) {},
- onCommands: () {},
+ sideBySideMinWidth: 700,
+ previewBuilder: () => SwarmResourcePreview(
+ search: _search,
+ controls: _controls,
+ onChoose: _choose,
+ onRefocus: _focus.requestFocus,
+ onModalChanged: (_) {},
+ onCommands: () {},
+ ),
),
),
),
),
+ if (hints)
+ ListenableBuilder(
+ listenable: Listenable.merge([_search, _target]),
+ builder: (context, _) => _SwarmModelsHints(search: _search),
+ ),
],
);
}
+
+ /// The app's own search field, as Settings' is: the theme frames it and centres the magnifier on its line.
+ Widget _searchField() => TextField(
+ key: const ValueKey('super-local-models-search'),
+ controller: _editing,
+ focusNode: _focus,
+ autofocus: true,
+ onChanged: _query,
+ onSubmitted: (_) {
+ _choose(_search.submit());
+ _focus.requestFocus();
+ },
+ textInputAction: TextInputAction.search,
+ style: grid.kFieldTextStyle,
+ decoration: InputDecoration(
+ hintText: 'Search models and APIs',
+ prefixIcon: Icon(
+ AppIcons.search,
+ size: grid.kFieldIconSize,
+ color: grid.AppPalette.textFaint,
+ ),
+ ),
+ );
}
-String _status(SuperTabLocalModels? local, {required bool owner}) {
- if (local == null || !local.enabled) {
- return owner
- ? 'Off. Only you can turn it on.'
- : 'Off. The Swarm owner can turn it on.';
+/// All, or one section: APIs, your models, the models to get.
+class _SwarmModelScopes extends StatelessWidget {
+ const _SwarmModelScopes({required this.search});
+
+ final SwarmSearchController search;
+
+ @override
+ Widget build(BuildContext context) {
+ Widget scope(String label, ModelSearchSection? section) {
+ final on = search.modelScope == section;
+ return Semantics(
+ button: true,
+ selected: on,
+ child: Material(
+ color: on
+ ? DesktopChrome.foreground.withValues(alpha: .10)
+ : Colors.transparent,
+ borderRadius: BorderRadius.circular(6),
+ child: InkWell(
+ key: ValueKey('super-local-models-scope:${section?.name ?? 'all'}'),
+ borderRadius: BorderRadius.circular(6),
+ onTap: () => search.setModelScope(section),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
+ child: Text(
+ label,
+ style: DesktopChrome.text(
+ size: 12,
+ medium: true,
+ height: 1.3,
+ color: on ? DesktopChrome.foreground : DesktopChrome.muted,
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ return Container(
+ height: 36,
+ padding: const EdgeInsets.all(3),
+ decoration: BoxDecoration(
+ color: DesktopChrome.field,
+ borderRadius: BorderRadius.circular(9),
+ border: Border.all(color: DesktopChrome.rim),
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ scope('All', null),
+ scope('APIs', ModelSearchSection.apis),
+ scope('Yours', ModelSearchSection.local),
+ scope('Get', ModelSearchSection.catalog),
+ ],
+ ),
+ );
+ }
+}
+
+/// The window's keys, along its foot: Return says what it does on the chosen row.
+class _SwarmModelsHints extends StatelessWidget {
+ const _SwarmModelsHints({required this.search});
+
+ final SwarmSearchController search;
+
+ @override
+ Widget build(BuildContext context) {
+ final row = search.selected;
+ final enter = row == null
+ ? null
+ : row.isCreate
+ ? 'Add API connection'
+ : search.swarmModelAction(row)?.label ??
+ (search.canExpandApi(row) ||
+ search.isModelDownloadsRow(row) ||
+ search.canGetModel(row)
+ ? search.actionLabel(row)
+ : null);
+ Widget hint(String key, String label) => Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Container(
+ padding: const EdgeInsets.symmetric(horizontal: 5),
+ decoration: BoxDecoration(
+ color: DesktopChrome.foreground.withValues(alpha: .07),
+ borderRadius: BorderRadius.circular(4),
+ ),
+ child: Text(key, style: DesktopChrome.text(size: 11, height: 1.45)),
+ ),
+ const SizedBox(width: 6),
+ Text(
+ label,
+ style: DesktopChrome.text(size: 11, color: DesktopChrome.muted),
+ ),
+ ],
+ );
+ return Container(
+ key: const ValueKey('super-local-models-hints'),
+ height: 36,
+ padding: const EdgeInsets.symmetric(horizontal: 20),
+ decoration: BoxDecoration(
+ border: Border(top: BorderSide(color: DesktopChrome.rim)),
+ ),
+ child: Row(
+ children: [
+ hint('↑↓', 'Select'),
+ if (enter != null) ...[const SizedBox(width: 16), hint('↵', enter)],
+ const SizedBox(width: 16),
+ hint('⇥', 'Actions'),
+ const Spacer(),
+ hint('esc', 'Close'),
+ ],
+ ),
+ );
}
- return switch (local.ready) {
- true =>
- 'On. Run your models for the Swarm, or share an API with it, below.',
- false =>
- 'Could not finish setting up: ${_sentence(local.error ?? 'try again later')}',
- null =>
- owner
- ? 'Setting up. Keep Harness open on one of your computers for a minute.'
- : 'Setting up on the owner\'s computer.',
- };
}
+String _capitalized(String text) =>
+ text.isEmpty ? text : '${text[0].toUpperCase()}${text.substring(1)}';
+
/// [text] as a sentence: grid's own words often end without a full stop.
String _sentence(String text) {
final t = text.trim();
diff --git a/desktop/lib/super_tabs/project_sidebar.dart b/desktop/lib/super_tabs/project_sidebar.dart
index 255bdf9db..2770e7c61 100644
--- a/desktop/lib/super_tabs/project_sidebar.dart
+++ b/desktop/lib/super_tabs/project_sidebar.dart
@@ -366,9 +366,9 @@ class ProjectSidebar extends StatelessWidget {
icon: AppIcons.plus,
onTap: controller.canWrite ? onNewProject : null,
),
- // The Local models add-on (docs/plans/2026-10-23-swarm-local-models.md): the owner turns it on here, and
- // everyone manages their models for the Swarm here once it is on. What each machine offers is on the machine.
- if (controller.isOwner || snapshot?.localModels?.enabled == true)
+ // The Swarm's models (docs/plans/2026-10-23-swarm-local-models.md), for everyone: the owner sets them up here,
+ // and everyone runs and shares models here once they are. What each machine offers is on the machine.
+ if (snapshot != null)
_navigationRow(
key: 'super-local-models',
label: 'Manage models',
diff --git a/desktop/lib/widgets/swarm_model_tile.dart b/desktop/lib/widgets/swarm_model_tile.dart
new file mode 100644
index 000000000..cbc478b08
--- /dev/null
+++ b/desktop/lib/widgets/swarm_model_tile.dart
@@ -0,0 +1,162 @@
+import 'package:flutter/material.dart';
+
+import '../models/model_search_catalog.dart';
+import '../shared/theme/app_icons.dart';
+import '../shared/theme/app_theme.dart' as grid;
+import '../state/swarm_navigation.dart';
+import '../state/swarm_search.dart';
+import 'desktop_chrome.dart';
+
+/// What a row of a Swarm's Manage models is, which its mark says at a glance.
+enum SwarmModelKind { api, apiModel, local, live, get, add, more, shared }
+
+SwarmModelKind swarmModelKind(
+ SwarmSearchController search,
+ SwarmDestination row,
+) {
+ if (row.isCreate) return SwarmModelKind.add;
+ if (search.isModelDownloadsRow(row)) return SwarmModelKind.more;
+ if (search.isApiRow(row)) return SwarmModelKind.api;
+ if (search.isApiModelRow(row)) return SwarmModelKind.apiModel;
+ final entry = search.models?.entries[row.modelId];
+ final local = entry?.local;
+ if (local == null) return SwarmModelKind.shared;
+ if (entry?.needsDownload == true || !local.downloaded) {
+ return SwarmModelKind.get;
+ }
+ final swarm = search.swarmModels;
+ return search.modelRowLive(row) ||
+ (swarm != null && local.servedOn(swarm.grid))
+ ? SwarmModelKind.live
+ : SwarmModelKind.local;
+}
+
+/// Green while something is live, as every status dot in the app is.
+Color get swarmModelLive =>
+ grid.AppTheme.pick(const Color(0xFF246C3F), const Color(0xFF86E6A3));
+
+/// A rounded square holding the kind's mark: neutral, green while it serves, the accent for adding.
+class SwarmModelTile extends StatelessWidget {
+ const SwarmModelTile({super.key, required this.kind, this.size = 30});
+
+ final SwarmModelKind kind;
+ final double size;
+
+ @override
+ Widget build(BuildContext context) {
+ final tone = switch (kind) {
+ SwarmModelKind.add => DesktopChrome.accent,
+ SwarmModelKind.live => grid.AppPalette.online,
+ _ => null,
+ };
+ final ink = switch (kind) {
+ SwarmModelKind.add => DesktopChrome.accent,
+ SwarmModelKind.live => swarmModelLive,
+ _ => DesktopChrome.muted,
+ };
+ return Container(
+ width: size,
+ height: size,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(
+ color:
+ tone?.withValues(alpha: .13) ??
+ DesktopChrome.foreground.withValues(alpha: .06),
+ borderRadius: BorderRadius.circular(size * .27),
+ border: Border.all(
+ color:
+ tone?.withValues(alpha: .32) ??
+ DesktopChrome.foreground.withValues(alpha: .09),
+ ),
+ ),
+ child: Icon(
+ switch (kind) {
+ SwarmModelKind.api => AppIcons.cloud,
+ SwarmModelKind.apiModel => AppIcons.sparkles,
+ SwarmModelKind.local || SwarmModelKind.live => AppIcons.cpu,
+ SwarmModelKind.get => AppIcons.download,
+ SwarmModelKind.add => AppIcons.plus,
+ SwarmModelKind.more => AppIcons.chevronDown,
+ SwarmModelKind.shared => AppIcons.server,
+ },
+ size: size * .5,
+ color: ink,
+ ),
+ );
+ }
+}
+
+/// A small rounded label at a row's end: green while live, the error colour when it failed, else quiet.
+class SwarmModelPill extends StatelessWidget {
+ const SwarmModelPill(
+ this.label, {
+ super.key,
+ this.live = false,
+ this.failed = false,
+ this.textKey,
+ });
+
+ final String label;
+ final bool live, failed;
+ final Key? textKey;
+
+ @override
+ Widget build(BuildContext context) {
+ final color = failed
+ ? Theme.of(context).colorScheme.error
+ : live
+ ? swarmModelLive
+ : DesktopChrome.muted;
+ return Container(
+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
+ decoration: BoxDecoration(
+ color: live
+ ? grid.AppPalette.online.withValues(alpha: .13)
+ : DesktopChrome.foreground.withValues(alpha: .06),
+ borderRadius: BorderRadius.circular(10),
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ if (live) ...[
+ Container(
+ width: 6,
+ height: 6,
+ decoration: BoxDecoration(
+ color: grid.AppPalette.online,
+ shape: BoxShape.circle,
+ ),
+ ),
+ const SizedBox(width: 5),
+ ],
+ Text(
+ label,
+ key: textKey,
+ maxLines: 1,
+ style: DesktopChrome.text(size: 11, medium: true, color: color),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+/// A section's heading's two halves: `Get for this Mac · 64 GB` is the title `Get for this Mac` and the note `64 GB`.
+({String title, String? note}) swarmModelHeading(
+ ModelSearchSection? section,
+ String heading,
+) {
+ final parts = heading.split(' · ');
+ final title = parts.first;
+ final rest = parts.skip(1).join(' · ');
+ return (
+ title: title,
+ note: rest.isNotEmpty
+ ? rest
+ : switch (section) {
+ ModelSearchSection.apis => 'Shared on your key',
+ ModelSearchSection.local => 'On ${thisComputerName()}',
+ _ => null,
+ },
+ );
+}
diff --git a/desktop/lib/widgets/swarm_resource_preview.dart b/desktop/lib/widgets/swarm_resource_preview.dart
index eeecb052b..8288cb546 100644
--- a/desktop/lib/widgets/swarm_resource_preview.dart
+++ b/desktop/lib/widgets/swarm_resource_preview.dart
@@ -9,10 +9,11 @@ import '../core/test_run.dart';
import '../shortcuts/app_keymap.dart';
import '../shortcuts/keymap.dart';
import '../models/api_connections_controller.dart'
- show ApiModels, contextWindowLabel;
+ show ApiConnection, ApiModels, contextWindowLabel;
import '../models/local_model.dart';
import '../models/model_search_catalog.dart';
import '../core/relative_time.dart';
+import '../shared/theme/app_icons.dart';
import '../shared/theme/app_theme.dart' as grid;
import '../shared/widgets/fingerprint_text.dart';
import '../state/account_devices.dart';
@@ -34,6 +35,7 @@ import 'swarm_search_preview.dart';
import 'swarm_preview_scroll.dart';
import 'terminal_text_action.dart';
import 'desktop_chrome.dart';
+import 'swarm_model_tile.dart';
import 'key_hints.dart';
const resourcePickerCommands = {
@@ -684,7 +686,17 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {
List<_ResourceAction> _visibleActions() => [
..._actions(),
- if (!_isManagement && row?.isCreate != true && _commands().isNotEmpty)
+ // A Swarm's Manage models has no Actions menu: an API's one other action, Edit, is beside its button.
+ if (_swarmCards) ...[
+ if (model?.api case final api? when model?.apiModel == null)
+ _ResourceAction(
+ 'Edit connection',
+ _pending.contains(row?.id) ? null : () => _editApi(api.id),
+ command: 'picker.resource_settings',
+ ),
+ ] else if (!_isManagement &&
+ row?.isCreate != true &&
+ _commands().isNotEmpty)
_ResourceAction(
'Actions…',
widget.onCommands,
@@ -717,6 +729,30 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {
action.command,
contextKind: KeymapContext.picker,
);
+ if (_swarmCards) {
+ // The one action that does what the row is for is filled; a stop is quiet, in the error colour.
+ final primary = action.command == _actions().firstOrNull?.command;
+ final stop = action.label.startsWith('Stop');
+ return Semantics(
+ liveRegion: action.label == 'Working…',
+ child: DesktopPill(
+ key: ValueKey('resource-action:${action.command}'),
+ focusNode: node,
+ label: row?.isCreate == true && primary
+ ? 'Add connection'
+ : action.label,
+ capsule: false,
+ onPressed: invoke,
+ surfaceColor: primary && !stop ? grid.AppPalette.accent : null,
+ foregroundColor: primary && !stop
+ ? DesktopChrome.onSelection
+ : stop
+ ? Theme.of(context).colorScheme.error
+ : null,
+ tooltip: [action.label, ?shortcut].join(' · '),
+ ),
+ );
+ }
return Semantics(
liveRegion: action.label == 'Working…',
child: DesktopPill(
@@ -749,9 +785,17 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {
},
child: Wrap(
key: const ValueKey('swarm-search-resource-actions'),
+ alignment: _swarmCards ? WrapAlignment.end : WrapAlignment.start,
spacing: desktop ? 8 : cell.width * 2,
runSpacing: desktop ? 8 : cell.height,
- children: [for (final action in _visibleActions()) button(action)],
+ children: [
+ // A Swarm's bar ends in its main action, at the right, as a dialog's does.
+ for (final action
+ in _swarmCards
+ ? [..._visibleActions().skip(1), ..._visibleActions().take(1)]
+ : _visibleActions())
+ button(action),
+ ],
),
);
void next() => _traverseActions(true);
@@ -1307,6 +1351,279 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {
];
}
+ /// The preview is a Swarm's Manage models, drawn as a card of its own rather than ⌘I's lines.
+ bool get _swarmCards =>
+ widget.search.isSwarmModels && DesktopChrome.of(context);
+
+ /// A Swarm's model or API: its mark and kind over its name and status, a sentence on what it is to the Swarm,
+ /// its facts in one framed list, then whatever else it has (the models an API shares), and a warning last.
+ Widget _swarmCard({
+ required SwarmModelKind kind,
+ required String kicker,
+ required String title,
+ String? status,
+ bool live = false,
+ String? blurb,
+ List<(String, String)> facts = const [],
+ Set<String> monospace = const {},
+ List<Widget> extra = const [],
+ String? note,
+ List<String> errors = const [],
+ }) {
+ final error = Theme.of(context).colorScheme.error;
+ return ListView(
+ key: const ValueKey('swarm-model-card'),
+ controller: _scroll,
+ padding: const EdgeInsets.fromLTRB(24, 24, 24, 16),
+ children: [
+ Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SwarmModelTile(kind: kind, size: 44),
+ const SizedBox(width: 14),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ kicker.toUpperCase(),
+ style: DesktopChrome.text(
+ size: 11,
+ medium: true,
+ height: 1.3,
+ color: DesktopChrome.muted,
+ ).copyWith(letterSpacing: .6),
+ ),
+ const SizedBox(height: 3),
+ Text(
+ title,
+ style: DesktopChrome.text(
+ size: 18,
+ medium: true,
+ height: 1.3,
+ ).copyWith(fontWeight: FontWeight.w600),
+ ),
+ if (status != null) ...[
+ const SizedBox(height: 4),
+ Row(
+ children: [
+ if (live) ...[
+ Container(
+ width: 6,
+ height: 6,
+ decoration: BoxDecoration(
+ color: grid.AppPalette.online,
+ shape: BoxShape.circle,
+ ),
+ ),
+ const SizedBox(width: 6),
+ ],
+ Flexible(
+ child: Text(
+ status,
+ key: const ValueKey('swarm-model-card-status'),
+ style: DesktopChrome.metadata(),
+ ),
+ ),
+ ],
+ ),
+ ],
+ ],
+ ),
+ ),
+ ],
+ ),
+ if (blurb != null) ...[
+ const SizedBox(height: 18),
+ ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 460),
+ child: Text(
+ blurb,
+ style: DesktopChrome.text(size: 13, height: 1.5),
+ ),
+ ),
+ ],
+ for (final line in errors) ...[
+ const SizedBox(height: 10),
+ Text(line, style: DesktopChrome.text(size: 12, color: error)),
+ ],
+ if (facts.isNotEmpty) ...[
+ const SizedBox(height: 18),
+ DecoratedBox(
+ decoration: BoxDecoration(
+ color: DesktopChrome.foreground.withValues(alpha: .03),
+ borderRadius: BorderRadius.circular(10),
+ border: Border.all(color: DesktopChrome.rim),
+ ),
+ child: Column(
+ children: [
+ for (final (index, (label, value)) in facts.indexed) ...[
+ if (index > 0) Divider(height: 1, color: DesktopChrome.rim),
+ Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 14,
+ vertical: 9,
+ ),
+ child: LayoutBuilder(
+ builder: (context, constraints) {
+ final labelText = Text(
+ label,
+ style: DesktopChrome.text(
+ size: 12,
+ color: DesktopChrome.muted,
+ ),
+ );
+ final valueText = Text(
+ monospace.contains(label) || value.isEmpty
+ ? value
+ : '${value[0].toUpperCase()}${value.substring(1)}',
+ style: monospace.contains(label)
+ ? grid.AppType.monoMeta(
+ color: DesktopChrome.foreground,
+ )
+ : DesktopChrome.text(size: 13, height: 1.4),
+ );
+ final scale =
+ MediaQuery.textScalerOf(context).scale(12) / 12;
+ return constraints.maxWidth < 280 * scale
+ ? Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [labelText, valueText],
+ )
+ : Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SizedBox(
+ width: 104 * scale,
+ child: labelText,
+ ),
+ Expanded(child: valueText),
+ ],
+ );
+ },
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ ],
+ ...extra,
+ if (note != null) ...[
+ const SizedBox(height: 18),
+ Container(
+ key: const ValueKey('swarm-model-card-note'),
+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
+ decoration: BoxDecoration(
+ color: grid.AppPalette.warn.withValues(alpha: .10),
+ borderRadius: BorderRadius.circular(10),
+ border: Border.all(
+ color: grid.AppPalette.warn.withValues(alpha: .30),
+ ),
+ ),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Padding(
+ padding: const EdgeInsets.only(top: 1),
+ child: Icon(
+ AppIcons.triangleAlert,
+ size: 15,
+ color: grid.AppPalette.warn,
+ ),
+ ),
+ const SizedBox(width: 10),
+ Expanded(
+ child: Text(
+ note,
+ style: DesktopChrome.text(size: 12, height: 1.5),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ],
+ );
+ }
+
+ /// The models of the saved API [api] this computer shares with the Swarm, each with Stop sharing.
+ List<Widget> _swarmSharedModels(ApiConnection api) {
+ final swarm = widget.search.swarmModels!;
+ final shared = [
+ for (final key in swarm.shares)
+ if (key.startsWith('${api.id}\u0000')) key.substring(api.id.length + 1),
+ ]..sort();
+ if (shared.isEmpty) return const [];
+ final busy = _pending.contains(row?.id);
+ return [
+ const SizedBox(height: 22),
+ Row(
+ children: [
+ Text(
+ 'Shared with this Swarm',
+ style: DesktopChrome.text(
+ size: 12,
+ medium: true,
+ ).copyWith(fontWeight: FontWeight.w600),
+ ),
+ const SizedBox(width: 8),
+ SwarmModelPill('${shared.length}'),
+ ],
+ ),
+ const SizedBox(height: 8),
+ for (final model in shared)
+ Padding(
+ padding: const EdgeInsets.only(bottom: 6),
+ child: Container(
+ key: ValueKey('swarm-shared-model:$model'),
+ padding: const EdgeInsets.fromLTRB(12, 6, 6, 6),
+ decoration: BoxDecoration(
+ color: DesktopChrome.foreground.withValues(alpha: .03),
+ borderRadius: BorderRadius.circular(8),
+ border: Border.all(color: DesktopChrome.rim),
+ ),
+ child: Row(
+ children: [
+ Container(
+ width: 6,
+ height: 6,
+ decoration: BoxDecoration(
+ color: grid.AppPalette.online,
+ shape: BoxShape.circle,
+ ),
+ ),
+ const SizedBox(width: 10),
+ Expanded(
+ child: Text(
+ model,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: grid.AppType.monoMeta(
+ color: DesktopChrome.foreground,
+ ),
+ ),
+ ),
+ const SizedBox(width: 8),
+ DesktopPill(
+ key: ValueKey('swarm-stop-sharing:$model'),
+ label: 'Stop sharing',
+ compact: true,
+ capsule: false,
+ textSize: 12,
+ onPressed: busy
+ ? null
+ : () => unawaited(
+ _run(() => swarm.share(api.id, model, start: false)),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ];
+ }
+
Widget _modelPreview() {
final catalog = widget.search.models;
if (catalog == null) return _details(['No matching models']);
@@ -1412,7 +1729,17 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {
? catalog.localStatus(local, controller: owner)
: entry.status;
+ // A Swarm's card collects the facts and warnings below rather than drawing them as lines.
+ final swarmCard = _swarmCards && entry.local != null;
+ final facts = <(String, String)>[];
+ final errors = <String>[];
+ String? swarmBlurb;
+
Widget labelValue(String label, String value) {
+ if (swarmCard) {
+ label == 'Swarm' ? swarmBlurb = value : facts.add((label, value));
+ return const SizedBox.shrink();
+ }
if (desktop) return _desktopDetail(label, value);
return Padding(
padding: EdgeInsets.only(bottom: cell.height * .6),
@@ -1439,6 +1766,10 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {
}
Widget errorLine(String text) {
+ if (swarmCard) {
+ errors.add(text);
+ return const SizedBox.shrink();
+ }
return Padding(
padding: EdgeInsets.only(top: cell.height),
child: Text(
@@ -1453,7 +1784,7 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {
);
}
- return ListView(
+ final lines = ListView(
controller: _scroll,
padding: EdgeInsets.symmetric(
horizontal: cell.width * 2,
@@ -1489,8 +1820,8 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {
? 'Offered: the PM can start Builders on your machines on it'
: 'Offer to Swarm lets the PM start Builders on your machines on it'
: local.servedOn(swarm.grid)
- ? 'Running for this Swarm'
- : 'Run for Swarm lets agents on any machine in the Swarm use it',
+ ? 'Running for this Swarm: the Lead can route Builders on any machine in it onto this model.'
+ : 'Run for Swarm lets the Lead route Builders on any machine in the Swarm onto this model.',
),
if (local != null) ...[
// A model another app downloaded starts in that app, joined to the grid from there.
@@ -1616,6 +1947,27 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {
if (!desktop) ...[SizedBox(height: cell.height), _actionButtons()],
],
);
+ if (!swarmCard) return lines;
+ final kind = swarmModelKind(widget.search, row!);
+ final swarmStatus = widget.search.modelRowStatus(row!);
+ return _swarmCard(
+ kind: kind,
+ kicker: kind == SwarmModelKind.get
+ ? 'Get for $machineName'
+ : 'Model on $machineName',
+ title: entry.name,
+ status:
+ swarmStatus != null &&
+ swarmStatus != widget.search.modelRowAction(row!)
+ ? swarmStatus
+ : statusWord,
+ live: kind == SwarmModelKind.live,
+ blurb: kind == SwarmModelKind.get
+ ? 'Get downloads it to $machineName. Then run it for the Swarm, and the Lead can route Builders onto it.'
+ : swarmBlurb,
+ facts: facts,
+ errors: errors,
+ );
}
static const _kGiB = 1024 * 1024 * 1024;
@@ -1654,6 +2006,65 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {
final api = entry.api!;
final listed = widget.search.models!.manager.apis.models[api.id];
final model = entry.apiModel;
+ final hostLabel = widget.search.models!.manager.apis.hostLabel;
+ if (widget.search.swarmModels case final swarm? when _swarmCards) {
+ const charged =
+ 'Builders who use a shared model run on this key, and every request they send is charged to it.';
+ if (model != null) {
+ final shared = swarm.shared(api.id, model.id);
+ return _swarmCard(
+ kind: SwarmModelKind.apiModel,
+ kicker: '${api.name} model',
+ title: entry.name,
+ status: shared ? 'Shared with this Swarm' : 'Not shared',
+ live: shared,
+ blurb: shared
+ ? 'Agents on any machine in this Swarm can run on it, through $hostLabel.'
+ : 'Share with Swarm lets agents on any machine in this Swarm run on it, through $hostLabel.',
+ facts: [
+ if (model.name case final name?) ('Name', name),
+ ('Model', model.id),
+ if (model.contextWindow case final window?)
+ ('Context', contextWindowLabel(window)),
+ ('Via', '${api.name} · ${api.host}'),
+ ],
+ monospace: const {'Model'},
+ note: charged,
+ );
+ }
+ final count = listed?.models.length ?? 0;
+ final shares = widget.search.swarmApiShareCount(row!) ?? 0;
+ return _swarmCard(
+ kind: SwarmModelKind.api,
+ kicker: 'API connection',
+ title: entry.name,
+ status: shares > 0
+ ? '$shares ${shares == 1 ? 'model' : 'models'} shared with the Swarm'
+ : 'Not shared',
+ live: shares > 0,
+ blurb: !api.servesModels
+ ? 'Harness agents on this computer can call it as a tool. It has no models to share with the Swarm.'
+ : shares > 0
+ ? 'Builders anywhere in the Swarm can run on what it shares, through $hostLabel. Show its models to share another.'
+ : 'Show its models to share one with the Swarm. Builders anywhere in it can then run on it, through $hostLabel.',
+ facts: [
+ ('Endpoint', api.baseUrl),
+ ('Key', 'Saved on $hostLabel'),
+ (
+ 'Models',
+ switch (listed) {
+ ApiModels(loading: true) when count == 0 => 'Loading…',
+ ApiModels(error: _?) when count == 0 => 'Unavailable',
+ _ => '$count',
+ },
+ ),
+ ],
+ monospace: const {'Endpoint'},
+ extra: _swarmSharedModels(api),
+ errors: [?listed?.error],
+ note: api.servesModels ? charged : null,
+ );
+ }
if (model != null) {
final reason = widget.search.modelUseReason(row);
return _details([
@@ -1668,9 +2079,7 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {
('Via', '${api.name} · ${api.host}'),
'',
if (widget.search.swarmModels case final swarm?) ...[
- swarm.shared(api.id, model.id)
- ? 'Shared with this Swarm.'
- : 'Share with Swarm lets agents on any machine in this Swarm run on it.',
+ swarm.shared(api.id, model.id) ? 'Shared with this Swarm.' : 'Share with Swarm lets agents on any machine in this Swarm run on it.',
'They use the key saved on ${widget.search.models!.manager.apis.hostLabel}, '
'and every request they send is charged to that key.',
] else if (reason == null)
@@ -2034,20 +2443,30 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {
grid.AppTheme.palette.value,
terminalThemeStore.value,
);
- final showsHints = KeyHints.visibleOf(context);
+ final showsHints = KeyHints.visibleOf(context) && !_swarmCards;
final actions = [
- if (desktop || !_isManagement)
- Padding(
- padding: EdgeInsets.fromLTRB(
- cell.width * 2,
- cell.height,
- cell.width * 2,
- // The hints line is the gap under the buttons; without it
- // they would sit on the panel's edge.
- showsHints ? 0 : cell.height,
+ if (_swarmCards)
+ Container(
+ padding: const EdgeInsets.fromLTRB(24, 14, 24, 14),
+ decoration: BoxDecoration(
+ border: Border(top: BorderSide(color: DesktopChrome.rim)),
),
child: _actionButtons(),
- ),
+ )
+ else ...[
+ if (desktop || !_isManagement)
+ Padding(
+ padding: EdgeInsets.fromLTRB(
+ cell.width * 2,
+ cell.height,
+ cell.width * 2,
+ // The hints line is the gap under the buttons; without it
+ // they would sit on the panel's edge.
+ showsHints ? 0 : cell.height,
+ ),
+ child: _actionButtons(),
+ ),
+ ],
if (showsHints) _controlHints(),
];
return LayoutBuilder(
@@ -2162,6 +2581,16 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {
'Saves the current conversation, then starts a new one in the same folder. Your panes stay in place.',
],
])
+ : row?.isCreate == true && _swarmCards
+ ? _swarmCard(
+ kind: SwarmModelKind.add,
+ kicker: 'New',
+ title: 'Add API connection',
+ blurb:
+ 'Connect OpenRouter or any OpenAI-compatible API with its base URL and key. '
+ 'The key stays on this computer, and nothing is shared with the Swarm until you '
+ 'share one of its models.',
+ )
: row?.isCreate == true
? _details([
...widget.search.createDescription.split('\n'),
diff --git a/desktop/lib/widgets/swarm_switcher.dart b/desktop/lib/widgets/swarm_switcher.dart
index 68bd40e06..fd4e04577 100644
--- a/desktop/lib/widgets/swarm_switcher.dart
+++ b/desktop/lib/widgets/swarm_switcher.dart
@@ -28,6 +28,7 @@ import '../state/swarm_navigation.dart';
import '../state/session_content_search.dart';
import '../state/session_activity.dart';
import '../state/swarm_search.dart';
+import '../models/api_connections_controller.dart' show contextWindowLabel;
import '../models/model_search_catalog.dart';
import '../models/swarm_models_target.dart' show swarmSharedWithYouShown;
import '../state/harness_sessions.dart'
@@ -36,6 +37,7 @@ import '../store/store_mark.dart';
import 'engine_identity.dart';
import 'session_activity_label.dart';
import 'swarm_icon.dart';
+import 'swarm_model_tile.dart';
import 'swarm_search_preview.dart';
import 'swarm_resource_preview.dart';
import 'key_hints.dart';
@@ -652,6 +654,7 @@ class _SwarmSearchResultsState extends State<SwarmSearchResults> {
}
if (indices.isEmpty &&
(search.matchQuery.trim().isNotEmpty ||
+ search.modelScope != null ||
section == ModelSearchSection.catalog ||
(section == ModelSearchSection.shared &&
search.gridSetupOffered))) {
@@ -673,9 +676,16 @@ class _SwarmSearchResultsState extends State<SwarmSearchResults> {
double _modelItemHeight(({int? index, String? heading, String? key}) item) {
if (!_desktopRows) return _rowHeight;
final index = item.index;
- if (index == null) return item.heading == null ? 8 : _modelHeadingHeight;
+ if (index == null) {
+ return item.heading != null
+ ? _modelHeadingHeight
+ : search.isSwarmModels
+ ? 0
+ : 8;
+ }
// A shared model's row is two lines: its name, and the machine serving it under it.
- return search.modelRowNameEnd(search.rows[index]) != null
+ return !search.isSwarmModels &&
+ search.modelRowNameEnd(search.rows[index]) != null
? _twoLineRowHeight
: _rowHeight;
}
@@ -960,8 +970,18 @@ class _SwarmSearchResultsState extends State<SwarmSearchResults> {
? oneLine.clamp(48, double.infinity)
: _twoLineRowHeight;
}
+ // A Swarm's Manage models: two lines a row (its name, then what it is), under headings that read as headings.
+ final swarmRows = desktop && search.isSwarmModels;
+ if (swarmRows) {
+ _rowHeight = math.max(
+ 58,
+ scale.scale(13) * 1.4 + scale.scale(12) * 1.4 + 26,
+ );
+ }
_desktopRows = desktop;
- _modelHeadingHeight = scale.scale(12) * 1.45 + 12;
+ _modelHeadingHeight = swarmRows
+ ? scale.scale(12) * 1.4 + 26
+ : scale.scale(12) * 1.45 + 12;
final height = widget.fitRows
? _fittedHeight(
constraints,
@@ -1019,6 +1039,16 @@ class _SwarmSearchResultsState extends State<SwarmSearchResults> {
row.isModel ? search.modelRowAction(row) : null,
row.isModel ? search.canSelectModel(row) : null,
row.isModel ? search.canGetModel(row) : null,
+ // A Swarm's row says what it is to the Swarm, which changes with nothing above: a share, a run.
+ swarmRows
+ ? (
+ search.modelRowStatus(row),
+ search.modelRowLive(row),
+ search.swarmApiShareCount(row),
+ search.apiRowState(row),
+ search.wordsQuery,
+ )
+ : null,
);
final previous = _rowWidgets.remove(row.id);
if (previous?.presentation == presentation) {
@@ -1028,7 +1058,32 @@ class _SwarmSearchResultsState extends State<SwarmSearchResults> {
child: previous.child,
);
}
- final tile = widget.bios
+ final tile = swarmRows
+ ? Semantics(
+ selected: selected,
+ enabled: canSubmit,
+ button: true,
+ child: InkWell(
+ key: ValueKey(row.id),
+ onFocusChange: (focused) {
+ if (focused) _focusResult(row.id);
+ },
+ onTap: canSubmit ? () => _submit(row) : null,
+ borderRadius: BorderRadius.circular(9),
+ hoverColor: DesktopChrome.foreground.withValues(
+ alpha: .045,
+ ),
+ focusColor: Colors.transparent,
+ highlightColor: Colors.transparent,
+ splashFactory: NoSplash.splashFactory,
+ child: _SwarmModelRow(
+ search: search,
+ row: row,
+ enabled: canSubmit,
+ ),
+ ),
+ )
+ : widget.bios
? Semantics(
selected: selected,
enabled: canSubmit,
@@ -1267,7 +1322,32 @@ class _SwarmSearchResultsState extends State<SwarmSearchResults> {
_focusResult(row.id);
}
},
- child: desktop
+ child: swarmRows
+ ? Padding(
+ padding: const EdgeInsets.symmetric(vertical: 2),
+ child: Material(
+ key: ValueKey('swarm-search-line:${row.id}'),
+ // A tint and an edge in the accent, not a solid bar: the row keeps its own colours,
+ // so its status still reads while it is chosen.
+ color: highlighted
+ ? DesktopChrome.accent.withValues(alpha: .16)
+ : selected && search.managing
+ ? grid.AppSurface.selectedFill
+ : Colors.transparent,
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(9),
+ side: highlighted
+ ? BorderSide(
+ color: DesktopChrome.accent.withValues(
+ alpha: .55,
+ ),
+ )
+ : BorderSide.none,
+ ),
+ child: tile,
+ ),
+ )
+ : desktop
? Padding(
padding: const EdgeInsets.symmetric(vertical: 2),
child: Material(
@@ -1415,6 +1495,14 @@ class _SwarmSearchResultsState extends State<SwarmSearchResults> {
if (item.heading == null) {
return const SizedBox();
}
+ if (swarmRows) {
+ return _SwarmModelHeading(
+ key: ValueKey<String>(item.key!),
+ search: search,
+ heading: item.heading!,
+ sectionKey: item.key!,
+ );
+ }
return Semantics(
header: true,
child: Padding(
@@ -2548,3 +2636,233 @@ class SwarmSearchCount extends StatelessWidget {
);
}
}
+
+/// A section heading of a Swarm's Manage models: its title, how many it holds, a rule, and a note at the right.
+class _SwarmModelHeading extends StatelessWidget {
+ const _SwarmModelHeading({
+ super.key,
+ required this.search,
+ required this.heading,
+ required this.sectionKey,
+ });
+
+ final SwarmSearchController search;
+ final String heading;
+ final String sectionKey;
+
+ @override
+ Widget build(BuildContext context) {
+ final section = ModelSearchSection.values
+ .where((s) => 'model-section:${s.label}' == sectionKey)
+ .firstOrNull;
+ final count = section == null
+ ? 0
+ : search.rows
+ .where(
+ (row) =>
+ search.modelSection(row) == section &&
+ !row.isCreate &&
+ !search.isModelDownloadsRow(row) &&
+ !search.isApiModelRow(row) &&
+ !search.isGridSetupRow(row),
+ )
+ .length;
+ final (:title, :note) = swarmModelHeading(section, heading);
+ return Semantics(
+ header: true,
+ label: '$title, $count',
+ excludeSemantics: true,
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(10, 18, 10, 8),
+ child: Row(
+ children: [
+ Text(
+ title,
+ maxLines: 1,
+ style: DesktopChrome.text(
+ size: 12,
+ medium: true,
+ height: 1.4,
+ ).copyWith(fontWeight: FontWeight.w600),
+ ),
+ const SizedBox(width: 8),
+ Container(
+ padding: const EdgeInsets.symmetric(horizontal: 6),
+ decoration: BoxDecoration(
+ color: DesktopChrome.foreground.withValues(alpha: .07),
+ borderRadius: BorderRadius.circular(8),
+ ),
+ child: Text(
+ '$count',
+ style: DesktopChrome.text(
+ size: 11,
+ medium: true,
+ height: 1.45,
+ color: DesktopChrome.muted,
+ ).copyWith(fontFeatures: const [FontFeature.tabularFigures()]),
+ ),
+ ),
+ const SizedBox(width: 10),
+ Expanded(child: Divider(height: 1, color: DesktopChrome.rim)),
+ if (note != null) ...[
+ const SizedBox(width: 10),
+ Text(
+ note,
+ maxLines: 1,
+ style: DesktopChrome.text(
+ size: 11,
+ height: 1.4,
+ color: DesktopChrome.muted,
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ );
+ }
+}
+
+/// A row of a Swarm's Manage models: its mark, its name over what it is, and what it is to the Swarm.
+class _SwarmModelRow extends StatelessWidget {
+ const _SwarmModelRow({
+ required this.search,
+ required this.row,
+ required this.enabled,
+ });
+
+ final SwarmSearchController search;
+ final SwarmDestination row;
+ final bool enabled;
+
+ /// The row's second line: where an API is and what it holds; a model's size and the app it runs in.
+ String? _detail(SwarmModelKind kind) {
+ final entry = search.models?.entries[row.modelId];
+ switch (kind) {
+ case SwarmModelKind.add:
+ return 'Any OpenAI-compatible API, with its key';
+ case SwarmModelKind.more:
+ return null;
+ case SwarmModelKind.api:
+ return entry?.api?.host;
+ case SwarmModelKind.apiModel:
+ return [
+ if (entry?.apiModel?.contextWindow case final window?)
+ '${contextWindowLabel(window)} context',
+ ?entry?.api?.name,
+ ].join(' · ');
+ case SwarmModelKind.shared:
+ return entry?.sharedBy ?? entry?.source;
+ default:
+ final local = entry?.local;
+ return [
+ if (local?.sizeBytes case final size?) gigabytesLabel(size),
+ ?local?.app,
+ ].join(' · ');
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ grid.AppTheme.watch(context);
+ final kind = swarmModelKind(search, row);
+ final entry = search.models?.entries[row.modelId];
+ final title = row.isCreate
+ ? 'Add API connection'
+ : kind == SwarmModelKind.shared
+ ? entry?.name ?? row.title
+ : search.modelRowTitle(row);
+ final api = search.apiRowState(row);
+ final shares = search.swarmApiShareCount(row);
+ var status = search.modelRowStatus(row);
+ // An action word (Get) is the preview's button, not a state: the row says nothing then.
+ if (status != null && status == search.modelRowAction(row)) status = null;
+ if (shares != null) status = shares > 0 ? '$shares shared' : null;
+ final live =
+ (shares ?? 0) > 0 ||
+ search.modelRowLive(row) ||
+ const {'In Swarm', 'Shared', 'Offered'}.contains(status);
+ final detail = [
+ ?_detail(kind),
+ ?api?.hint,
+ ].where((part) => part.isNotEmpty).join(' · ');
+ final terms = swarmQueryTerms(search.wordsQuery);
+ final ink = enabled ? DesktopChrome.foreground : DesktopChrome.muted;
+ return Semantics(
+ label: [title, if (detail.isNotEmpty) detail, ?status].join(', '),
+ excludeSemantics: true,
+ child: Padding(
+ padding: EdgeInsets.fromLTRB(
+ kind == SwarmModelKind.apiModel ? 28 : 10,
+ 8,
+ 10,
+ 8,
+ ),
+ child: Row(
+ children: [
+ SwarmModelTile(
+ kind: kind,
+ size: kind == SwarmModelKind.apiModel ? 24 : 30,
+ ),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SearchResultText(
+ title,
+ matches: searchResultMatches(
+ row,
+ terms,
+ ).where((match) => match.title),
+ style: DesktopChrome.text(
+ size: 13,
+ medium: true,
+ height: 1.4,
+ color: kind == SwarmModelKind.add
+ ? DesktopChrome.accent
+ : ink,
+ ),
+ ),
+ if (detail.isNotEmpty)
+ Text(
+ detail,
+ key: api != null
+ ? ValueKey('api-row-hint:${row.id}')
+ : null,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: DesktopChrome.text(
+ size: 12,
+ height: 1.4,
+ color: DesktopChrome.muted,
+ ),
+ ),
+ ],
+ ),
+ ),
+ if (status != null) ...[
+ const SizedBox(width: 10),
+ SwarmModelPill(
+ status,
+ live: live,
+ failed: search.modelRowFailed(row),
+ textKey: ValueKey('model-row-status:${row.id}'),
+ ),
+ ],
+ if (api != null) ...[
+ const SizedBox(width: 6),
+ Icon(
+ key: ValueKey('api-row-marker:${row.id}'),
+ api.open ? AppIcons.chevronDown : AppIcons.chevronRight,
+ size: 16,
+ color: DesktopChrome.muted,
+ ),
+ ],
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/desktop/test/super_tab_sidebar_test.dart b/desktop/test/super_tab_sidebar_test.dart
index 1efaa32b4..2b9753966 100644
--- a/desktop/test/super_tab_sidebar_test.dart
+++ b/desktop/test/super_tab_sidebar_test.dart
@@ -466,10 +466,10 @@ void main() {
}
final open = find.byKey(const ValueKey('super-local-models'));
- final toggle = find.byKey(const ValueKey('super-local-models-switch'));
+ final setUp = find.byKey(const ValueKey('super-local-models-setup'));
testWidgets(
- 'the owner turns them on from the sidebar; it is off until then',
+ 'the owner sets models up from Manage models; there is no switch',
(tester) async {
final server = ConversationServer();
server.state['machines'] = [machine()];
@@ -479,9 +479,12 @@ void main() {
expect(find.text('Manage models'), findsOneWidget);
await tester.tap(open);
await tester.pumpAndSettle();
- expect(tester.widget<Switch>(toggle).value, isFalse);
- expect(find.text('Off. Only you can turn it on.'), findsOneWidget);
- await tester.tap(toggle);
+ expect(find.byType(Switch), findsNothing);
+ expect(
+ find.textContaining('Set up gets this computer ready'),
+ findsOneWidget,
+ );
+ await tester.tap(setUp);
await tester.pumpAndSettle();
expect(
server.posts
@@ -501,7 +504,7 @@ void main() {
);
testWidgets(
- 'others see Manage models once it is on, and cannot switch it',
+ 'everyone sees Manage models; before it is set up a member is told the owner sets it up',
(tester) async {
final server = ConversationServer();
(server.state['people'] as List).add({
@@ -513,35 +516,60 @@ void main() {
final c = server.controller(account: 'peer');
await c.refresh();
await mount(tester, c);
- expect(open, findsNothing);
+ await tester.tap(open);
+ await tester.pumpAndSettle();
+ expect(
+ find.text('The Swarm owner has not set up models yet.'),
+ findsOneWidget,
+ );
+ expect(setUp, findsNothing);
+ await tester.tap(
+ find.byKey(const ValueKey('super-local-models-close')),
+ );
+ await tester.pumpAndSettle();
+ // Being set up: it says so, and still offers nothing to press.
server.state['localModels'] = {'grid': swarmGrid, 'enabled': true};
- server.state['machines'] = [
- machine(
- served: [
- {'grid': swarmGrid, 'model': 'qwen3', 'name': 'Qwen 3'},
- {
- 'grid': swarmGrid,
- 'model': 'deepseek/v4',
- 'name': 'deepseek/v4 · OpenRouter',
- 'kind': 'api',
- },
- {'grid': 'team', 'model': 'muse', 'kind': 'shared'},
- {'grid': swarmGrid, 'model': 'qwen3'},
- ],
- ),
- ];
server.revision++;
await c.refresh();
await tester.pumpAndSettle();
- expect(open, findsOneWidget);
- // What each machine offers is on the machine now, not listed here.
- expect(find.text('Qwen 3'), findsNothing);
+ await tester.tap(open);
+ await tester.pumpAndSettle();
+ expect(
+ find.text('Being set up on the owner\'s computer.'),
+ findsOneWidget,
+ );
+ expect(setUp, findsNothing);
+ await tester.tap(
+ find.byKey(const ValueKey('super-local-models-close')),
+ );
+ await tester.pumpAndSettle();
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ c.dispose();
+ },
+ );
- // A model's row opens the same window, where the switch is the owner's alone.
+ testWidgets(
+ 'a failed set up says grid\'s words and offers Try again to the owner',
+ (tester) async {
+ final server = ConversationServer();
+ server.state['localModels'] = {
+ 'grid': swarmGrid,
+ 'enabled': true,
+ 'ready': false,
+ 'error': 'Free plan allows one network',
+ };
+ final c = server.controller();
+ await c.refresh();
+ await mount(tester, c);
await tester.tap(open);
await tester.pumpAndSettle();
- expect(tester.widget<Switch>(toggle).onChanged, isNull);
+ expect(
+ find.text('Could not set up: Free plan allows one network.'),
+ findsOneWidget,
+ );
+ expect(find.text('Try again'), findsOneWidget);
await tester.tap(
find.byKey(const ValueKey('super-local-models-close')),
);
diff --git a/desktop/test/swarm_local_models_picker_test.dart b/desktop/test/swarm_local_models_picker_test.dart
index 20aa2535a..dec9cba0a 100644
--- a/desktop/test/swarm_local_models_picker_test.dart
+++ b/desktop/test/swarm_local_models_picker_test.dart
@@ -245,6 +245,20 @@ void main() {
expect(plain.swarmModelAction(row('downloaded')), isNull);
});
+ test('a scope shows one section, and All every one again', () {
+ final sections = search.rows.map(search.modelSection).toSet();
+ expect(sections, contains(ModelSearchSection.catalog));
+ expect(sections, contains(ModelSearchSection.local));
+ search.setModelScope(ModelSearchSection.catalog);
+ expect(search.rows, isNotEmpty);
+ expect(
+ search.rows.map(search.modelSection).toSet(),
+ {ModelSearchSection.catalog},
+ );
+ search.setModelScope(null);
+ expect(search.rows.map(search.modelSection).toSet(), sections);
+ });
+
test('stops a model running for the Swarm on the Swarm\'s grid', () async {
await search.swarmModelAction(row('served'))!.run!();
expect(app.actions.last, (machine: 'm', model: 'served', start: false));