Merge main into macos-self-update
This commit is contained in:
@@ -156,10 +156,10 @@ class KeyboardShortcutRegistry {
|
||||
if (!web)
|
||||
const KeyboardShortcutEntry(
|
||||
group: KeyboardShortcutGroup.chat,
|
||||
action: 'Cycle chat panes and floating chats',
|
||||
action: 'Cycle chats and floating chat panes',
|
||||
keys: 'Ctrl+Tab, Ctrl+Shift+Tab',
|
||||
caveat:
|
||||
'While the terminal is shown, Ctrl+Tab moves between its tabs instead.',
|
||||
'With one tiled pane, cycles open sidebar chats (excluding closed, hidden and floating chats); with multiple panes, cycles panes. While the terminal is shown, Ctrl+Tab moves between its tabs instead.',
|
||||
),
|
||||
const KeyboardShortcutEntry(
|
||||
group: KeyboardShortcutGroup.chat,
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../application/open_in_chat_preferences.dart';
|
||||
import '../../core/api_gateway.dart';
|
||||
import '../chat/data/chat_repository.dart';
|
||||
import 'settings_group.dart';
|
||||
|
||||
/// The harness and model Open in chat (a run's or pipeline's More menu)
|
||||
/// starts its chats with. The server lists models only for an existing chat,
|
||||
/// so a harness's models come from its most recent chat; with none, only the
|
||||
/// harness default is offered.
|
||||
class SettingsOpenInChatSection extends StatefulWidget {
|
||||
const SettingsOpenInChatSection({super.key, required this.gateway});
|
||||
|
||||
final ApiGateway gateway;
|
||||
|
||||
@override
|
||||
State<SettingsOpenInChatSection> createState() =>
|
||||
_SettingsOpenInChatSectionState();
|
||||
}
|
||||
|
||||
class _SettingsOpenInChatSectionState extends State<SettingsOpenInChatSection> {
|
||||
late final ChatRepository _chats = ChatRepository(widget.gateway);
|
||||
OpenInChatPreferences _chosen = const OpenInChatPreferences();
|
||||
List<String>? _harnesses;
|
||||
List<JsonMap> _models = const [];
|
||||
bool _loadingModels = false;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_load();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
try {
|
||||
final chosen = await OpenInChatPreferences.load(widget.gateway);
|
||||
final harnesses = await _chats.backends();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_chosen = chosen;
|
||||
_harnesses = harnesses;
|
||||
});
|
||||
await _loadModels(chosen.harness);
|
||||
} catch (error) {
|
||||
if (mounted) setState(() => _error = '$error');
|
||||
}
|
||||
}
|
||||
|
||||
/// The models of [harness]'s most recent chat, or none.
|
||||
Future<void> _loadModels(String harness) async {
|
||||
setState(() {
|
||||
_models = const [];
|
||||
_loadingModels = harness.isNotEmpty;
|
||||
});
|
||||
if (harness.isEmpty) return;
|
||||
try {
|
||||
final sessions = await _chats.sessions();
|
||||
final latest =
|
||||
sessions.where((session) => session['backend'] == harness).toList()
|
||||
..sort(
|
||||
(a, b) => '${b['updated_at'] ?? ''}'.compareTo(
|
||||
'${a['updated_at'] ?? ''}',
|
||||
),
|
||||
);
|
||||
final models = latest.isEmpty
|
||||
? const <JsonMap>[]
|
||||
: await _chats.models('${latest.first['id']}');
|
||||
if (mounted && _chosen.harness == harness) {
|
||||
setState(() {
|
||||
_models = models;
|
||||
_loadingModels = false;
|
||||
});
|
||||
}
|
||||
} catch (_) {
|
||||
if (mounted) setState(() => _loadingModels = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _save(OpenInChatPreferences next) async {
|
||||
setState(() => _chosen = next);
|
||||
await next.save(widget.gateway);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final harnesses = _harnesses;
|
||||
final error = _error;
|
||||
return SettingsGroup(
|
||||
title: 'Open in chat',
|
||||
footer: Text(
|
||||
'Used when a run or pipeline is opened in a new chat. Models come '
|
||||
"from this harness's most recent chat.",
|
||||
),
|
||||
children: [
|
||||
if (error != null)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.error_outline),
|
||||
title: const Text('Could not load the harnesses'),
|
||||
subtitle: Text(error),
|
||||
trailing: TextButton(
|
||||
onPressed: () {
|
||||
setState(() => _error = null);
|
||||
_load();
|
||||
},
|
||||
child: const Text('Retry'),
|
||||
),
|
||||
)
|
||||
else if (harnesses == null)
|
||||
const ListTile(
|
||||
leading: SizedBox.square(
|
||||
dimension: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
title: Text('Loading harnesses…'),
|
||||
)
|
||||
else ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 8),
|
||||
child: DropdownMenu<String>(
|
||||
key: const Key('open-in-chat-harness'),
|
||||
expandedInsets: EdgeInsets.zero,
|
||||
label: const Text('Harness'),
|
||||
initialSelection: harnesses.contains(_chosen.harness)
|
||||
? _chosen.harness
|
||||
: '',
|
||||
dropdownMenuEntries: [
|
||||
const DropdownMenuEntry(value: '', label: 'Default'),
|
||||
for (final harness in harnesses)
|
||||
DropdownMenuEntry(value: harness, label: harness),
|
||||
],
|
||||
onSelected: (harness) async {
|
||||
final value = harness ?? '';
|
||||
if (value == _chosen.harness) return;
|
||||
await _save(OpenInChatPreferences(harness: value));
|
||||
await _loadModels(value);
|
||||
},
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 12),
|
||||
child: DropdownMenu<String>(
|
||||
key: ValueKey('open-in-chat-model-${_chosen.harness}'),
|
||||
expandedInsets: EdgeInsets.zero,
|
||||
enabled: _chosen.harness.isNotEmpty && !_loadingModels,
|
||||
label: Text(_loadingModels ? 'Loading models…' : 'Model'),
|
||||
initialSelection: _chosen.hasModel
|
||||
? '${_chosen.provider}/${_chosen.model}'
|
||||
: '',
|
||||
dropdownMenuEntries: [
|
||||
const DropdownMenuEntry(value: '', label: 'Harness default'),
|
||||
if (_chosen.hasModel &&
|
||||
!_models.any(
|
||||
(m) =>
|
||||
'${m['provider']}/${m['id']}' ==
|
||||
'${_chosen.provider}/${_chosen.model}',
|
||||
))
|
||||
DropdownMenuEntry(
|
||||
value: '${_chosen.provider}/${_chosen.model}',
|
||||
label: _chosen.model,
|
||||
),
|
||||
for (final model in _models)
|
||||
DropdownMenuEntry(
|
||||
value: '${model['provider']}/${model['id']}',
|
||||
label: '${model['name'] ?? model['id']}',
|
||||
),
|
||||
],
|
||||
onSelected: (value) {
|
||||
final picked = value ?? '';
|
||||
final slash = picked.indexOf('/');
|
||||
_save(
|
||||
OpenInChatPreferences(
|
||||
harness: _chosen.harness,
|
||||
provider: slash < 0 ? '' : picked.substring(0, slash),
|
||||
model: slash < 0 ? '' : picked.substring(slash + 1),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -106,6 +106,13 @@ extension _SettingsPageSections on _SettingsScreenState {
|
||||
workspaceField: _workspaceField,
|
||||
),
|
||||
),
|
||||
SettingsSection(
|
||||
id: 'open-in-chat',
|
||||
title: 'Open in chat',
|
||||
keywords: 'open in chat run pipeline harness model default new chat',
|
||||
lazy: true,
|
||||
builder: (_) => SettingsOpenInChatSection(gateway: widget.client),
|
||||
),
|
||||
if (widget.notifications case final notifications?)
|
||||
SettingsSection(
|
||||
id: 'notifications',
|
||||
|
||||
@@ -43,6 +43,7 @@ import 'settings_row.dart';
|
||||
import 'settings_read_aloud_section.dart';
|
||||
import '../chat/speech/speech_controller.dart';
|
||||
|
||||
import 'settings_open_in_chat_section.dart';
|
||||
part 'settings_page_sections.dart';
|
||||
|
||||
/// The Settings destination: one searchable page of grouped Material sections.
|
||||
|
||||
Reference in New Issue
Block a user