feat: initial Cutdex application
Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
This commit is contained in:
commit
27e77fff39
718 files changed
+183958
No files matched your search
@@ -0,0 +1,760 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../integrations/agent/agent_settings.dart';
|
||||
import '../../integrations/agent/agent_models.dart';
|
||||
import '../../l10n/l10n.dart';
|
||||
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
|
||||
import 'settings_layout.dart';
|
||||
import '../../settings/settings_operation.dart';
|
||||
|
||||
part 'agent_settings_panel.freezed.dart';
|
||||
|
||||
class AgentSettingsPanel extends ConsumerStatefulWidget {
|
||||
const AgentSettingsPanel({super.key, this.contentPadding = EdgeInsets.zero});
|
||||
|
||||
final EdgeInsets contentPadding;
|
||||
|
||||
@override
|
||||
ConsumerState<AgentSettingsPanel> createState() => _AgentSettingsPanelState();
|
||||
}
|
||||
|
||||
class _AgentSettingsPanelState extends ConsumerState<AgentSettingsPanel>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _pageFade = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 140),
|
||||
value: 1,
|
||||
);
|
||||
bool _showingProviderEditor = false;
|
||||
AgentProviderSettings? _editingProvider;
|
||||
bool _transitioning = false;
|
||||
bool get _saving =>
|
||||
ref.read(settingsOperationProvider('agent-save')).isLoading;
|
||||
final _scroll = ScrollController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pageFade.dispose();
|
||||
_scroll.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _showProviderForm(
|
||||
bool adding, {
|
||||
AgentProviderSettings? provider,
|
||||
}) async {
|
||||
if (_transitioning || _saving || _showingProviderEditor == adding) return;
|
||||
setState(() => _transitioning = true);
|
||||
await _pageFade.reverse();
|
||||
if (!mounted) return;
|
||||
if (_scroll.hasClients) _scroll.jumpTo(0);
|
||||
setState(() {
|
||||
_showingProviderEditor = adding;
|
||||
_editingProvider = adding ? provider : null;
|
||||
});
|
||||
await _pageFade.forward();
|
||||
if (mounted) setState(() => _transitioning = false);
|
||||
}
|
||||
|
||||
Future<void> _saveProvider(_ProviderFormValue result) async {
|
||||
if (_saving) return;
|
||||
final saved = await ref
|
||||
.read(settingsOperationProvider('agent-save').notifier)
|
||||
.run(
|
||||
() => ref
|
||||
.read(agentSettingsProvider.notifier)
|
||||
.upsertProvider(
|
||||
id: _editingProvider?.id,
|
||||
name: result.name,
|
||||
apiType: result.apiType,
|
||||
baseUrl: result.baseUrl,
|
||||
models: result.models,
|
||||
apiKey: result.apiKey,
|
||||
clearApiKey: result.clearApiKey,
|
||||
),
|
||||
);
|
||||
if (!mounted) return;
|
||||
if (saved) {
|
||||
await _showProviderForm(false);
|
||||
} else {
|
||||
_showSaveError();
|
||||
}
|
||||
}
|
||||
|
||||
void _showSaveError() => ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(context.l10n.agentSaveSettingsFailed)));
|
||||
|
||||
Future<void> _setProviderEnabled(
|
||||
AgentProviderSettings provider,
|
||||
bool enabled,
|
||||
) async {
|
||||
if (_transitioning) return;
|
||||
final operation = settingsOperationProvider('agent-enable-${provider.id}');
|
||||
if (ref.read(operation).isLoading) return;
|
||||
final saved = await ref
|
||||
.read(operation.notifier)
|
||||
.run(
|
||||
() => ref
|
||||
.read(agentSettingsProvider.notifier)
|
||||
.setProviderEnabled(provider.id, enabled),
|
||||
);
|
||||
if (!saved && mounted) _showSaveError();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Theme(
|
||||
data: AppTheme.settingsContentTheme(Theme.of(context)),
|
||||
child: Builder(builder: _buildContent),
|
||||
);
|
||||
|
||||
Widget _buildContent(BuildContext context) {
|
||||
ref.watch(settingsOperationProvider('agent-save'));
|
||||
final settings = ref.watch(agentSettingsProvider);
|
||||
return ScrollConfiguration(
|
||||
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
|
||||
child: Scrollbar(
|
||||
controller: _scroll,
|
||||
thumbVisibility: true,
|
||||
child: SingleChildScrollView(
|
||||
key: const Key('agent-settings-scroll'),
|
||||
controller: _scroll,
|
||||
primary: false,
|
||||
padding: widget.contentPadding,
|
||||
physics: const ClampingScrollPhysics(),
|
||||
child: FadeTransition(
|
||||
key: const Key('agent-provider-page-transition'),
|
||||
opacity: _pageFade,
|
||||
child: IgnorePointer(
|
||||
ignoring: _transitioning,
|
||||
child: _showingProviderEditor
|
||||
? _ProviderEditor(
|
||||
key: const Key('agent-provider-editor'),
|
||||
saving: _saving,
|
||||
provider: _editingProvider,
|
||||
onBack: () => _showProviderForm(false),
|
||||
onSave: _saveProvider,
|
||||
)
|
||||
: SettingsPageSection(
|
||||
key: const Key('agent-provider-list'),
|
||||
title: context.l10n.agentSettings,
|
||||
icon: Icons.auto_awesome_outlined,
|
||||
action: OutlinedButton.icon(
|
||||
onPressed: settings.asData == null
|
||||
? null
|
||||
: () => _showProviderForm(true),
|
||||
icon: const Icon(Icons.add),
|
||||
label: Text(context.l10n.agentAddProvider),
|
||||
),
|
||||
children: [
|
||||
for (final provider
|
||||
in settings.asData?.value.providers ??
|
||||
const <AgentProviderSettings>[])
|
||||
_ProviderCard(
|
||||
key: ValueKey('agent-provider-${provider.id}'),
|
||||
provider: provider,
|
||||
onEdit: () =>
|
||||
_showProviderForm(true, provider: provider),
|
||||
onEnabledChanged: (value) =>
|
||||
_setProviderEnabled(provider, value),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ProviderCard extends StatelessWidget {
|
||||
const _ProviderCard({
|
||||
super.key,
|
||||
required this.provider,
|
||||
required this.onEdit,
|
||||
required this.onEnabledChanged,
|
||||
});
|
||||
|
||||
final AgentProviderSettings provider;
|
||||
final VoidCallback onEdit;
|
||||
final ValueChanged<bool> onEnabledChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final icon = switch (provider.apiType) {
|
||||
'anthropicMessages' => Icons.auto_awesome_outlined,
|
||||
'openAiResponses' => Icons.bolt_outlined,
|
||||
_ => Icons.forum_outlined,
|
||||
};
|
||||
return Container(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: AppIconSize.header, color: colors.onSurfaceVariant),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
provider.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
provider.models.map((model) => model.id).join(' · '),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
IconButton(
|
||||
key: ValueKey('agent-provider-edit-${provider.id}'),
|
||||
tooltip: context.l10n.agentEditProvider,
|
||||
onPressed: onEdit,
|
||||
icon: const Icon(Icons.edit_outlined, size: AppIconSize.header),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
AppSwitch(
|
||||
key: ValueKey('agent-provider-enabled-${provider.id}'),
|
||||
value: provider.enabled,
|
||||
semanticLabel: context.l10n.agentEnableProvider,
|
||||
onChanged: onEnabledChanged,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
TextStyle _providerInputStyle(BuildContext context) =>
|
||||
Theme.of(context).textTheme.bodyMedium!;
|
||||
|
||||
InputDecoration _providerInputDecoration(
|
||||
BuildContext context, {
|
||||
String? hintText,
|
||||
}) => InputDecoration(
|
||||
hintText: hintText,
|
||||
hintStyle: _providerInputStyle(context)
|
||||
.copyWith(color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
);
|
||||
|
||||
class _ProviderEditor extends StatefulWidget {
|
||||
const _ProviderEditor({
|
||||
super.key,
|
||||
required this.onBack,
|
||||
required this.onSave,
|
||||
required this.saving,
|
||||
this.provider,
|
||||
});
|
||||
|
||||
final VoidCallback onBack;
|
||||
final ValueChanged<_ProviderFormValue> onSave;
|
||||
final bool saving;
|
||||
final AgentProviderSettings? provider;
|
||||
|
||||
@override
|
||||
State<_ProviderEditor> createState() => _ProviderEditorState();
|
||||
}
|
||||
|
||||
class _ProviderEditorState extends State<_ProviderEditor> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
late final TextEditingController _name;
|
||||
late final TextEditingController _baseUrl;
|
||||
late final TextEditingController _apiKey;
|
||||
late List<_ModelControllers> _models;
|
||||
AgentApiType _apiType = AgentApiType.openAiChatCompletions;
|
||||
String? _formError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final provider = widget.provider;
|
||||
_name = TextEditingController(text: provider?.name);
|
||||
_baseUrl = TextEditingController(text: provider?.baseUrl);
|
||||
_apiKey = TextEditingController();
|
||||
_apiType =
|
||||
AgentApiType.values
|
||||
.where((type) => type.name == provider?.apiType)
|
||||
.firstOrNull ??
|
||||
AgentApiType.openAiChatCompletions;
|
||||
_models = provider == null || provider.models.isEmpty
|
||||
? [_ModelControllers()]
|
||||
: [for (final model in provider.models) _ModelControllers(model)];
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_name.dispose();
|
||||
_baseUrl.dispose();
|
||||
_apiKey.dispose();
|
||||
for (final model in _models) {
|
||||
model.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
final modelIds = _models.map((model) => model.id.text.trim()).toList();
|
||||
if (modelIds.toSet().length != modelIds.length) {
|
||||
setState(() => _formError = context.l10n.agentModelIdsUnique);
|
||||
return;
|
||||
}
|
||||
widget.onSave(
|
||||
_ProviderFormValue(
|
||||
name: _name.text.trim(),
|
||||
apiType: _apiType,
|
||||
baseUrl: _baseUrl.text.trim(),
|
||||
apiKey: _apiKey.text.isEmpty ? null : _apiKey.text,
|
||||
clearApiKey: false,
|
||||
models: [for (final model in _models) model.toData()],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
TextButton.icon(
|
||||
key: const Key('agent-provider-back'),
|
||||
onPressed: widget.saving ? null : widget.onBack,
|
||||
icon: const Icon(Icons.arrow_back, size: 16),
|
||||
label: Text(context.l10n.agentBackToProviders),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.large),
|
||||
Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_ConfigurationCard(
|
||||
title: context.l10n.agentProviderConfiguration,
|
||||
child: AppFieldGroup(
|
||||
children: [
|
||||
_ProviderIdentityRow(
|
||||
children: [
|
||||
AppField(
|
||||
label: context.l10n.name,
|
||||
child: TextFormField(
|
||||
style: _providerInputStyle(context),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
cursorHeight: 18,
|
||||
cursorWidth: 1.5,
|
||||
strutStyle: StrutStyle.fromTextStyle(
|
||||
_providerInputStyle(context),
|
||||
),
|
||||
key: const Key('agent-provider-name'),
|
||||
controller: _name,
|
||||
decoration: _providerInputDecoration(
|
||||
context,
|
||||
hintText: context.l10n.agentProviderNameHint,
|
||||
),
|
||||
validator: (value) => _required(context, value),
|
||||
),
|
||||
),
|
||||
AppField(
|
||||
label: context.l10n.agentApiType,
|
||||
child: AppSelect<AgentApiType>(
|
||||
emptyLabel: context.l10n.noMatchingOptions,
|
||||
controlHeight: AppSettingsMetrics.inputHeight,
|
||||
textStyle: _providerInputStyle(context),
|
||||
value: _apiType,
|
||||
label: context.l10n.agentApiType,
|
||||
options: [
|
||||
for (final value in AgentApiType.values)
|
||||
AppSelectOption(
|
||||
value,
|
||||
_apiTypeLabel(context, value),
|
||||
),
|
||||
],
|
||||
onChanged: (value) =>
|
||||
setState(() => _apiType = value),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
AppField(
|
||||
label: context.l10n.agentBaseUrl,
|
||||
child: TextFormField(
|
||||
style: _providerInputStyle(context),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
cursorHeight: 18,
|
||||
cursorWidth: 1.5,
|
||||
strutStyle: StrutStyle.fromTextStyle(
|
||||
_providerInputStyle(context),
|
||||
),
|
||||
key: const Key('agent-provider-base-url'),
|
||||
controller: _baseUrl,
|
||||
keyboardType: TextInputType.url,
|
||||
decoration: _providerInputDecoration(
|
||||
context,
|
||||
hintText: _apiType == AgentApiType.anthropicMessages
|
||||
? 'https://api.anthropic.com/v1'
|
||||
: 'https://api.openai.com/v1',
|
||||
),
|
||||
validator: (value) => _validateUrl(context, value),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.large),
|
||||
_ConfigurationCard(
|
||||
title: context.l10n.agentAuthenticationAndModels,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
AppField(
|
||||
label: context.l10n.agentApiKey,
|
||||
child: TextFormField(
|
||||
style: _providerInputStyle(context),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
cursorHeight: 18,
|
||||
cursorWidth: 1.5,
|
||||
strutStyle: StrutStyle.fromTextStyle(
|
||||
_providerInputStyle(context),
|
||||
),
|
||||
key: const Key('agent-provider-api-key'),
|
||||
controller: _apiKey,
|
||||
obscureText: true,
|
||||
decoration: _providerInputDecoration(
|
||||
context,
|
||||
hintText: context.l10n.agentOptional,
|
||||
),
|
||||
validator: (value) =>
|
||||
value != null &&
|
||||
(value.contains('\n') || value.contains('\r'))
|
||||
? context.l10n.agentApiKeyOneLine
|
||||
: null,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.small),
|
||||
Text(
|
||||
widget.provider?.credentialId != null
|
||||
? context.l10n.agentApiKeyKeep
|
||||
: context.l10n.agentApiKeyOptional,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.extraLarge),
|
||||
if (_formError != null) ...[
|
||||
const SizedBox(height: AppSpacing.small),
|
||||
Text(
|
||||
_formError!,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: AppSpacing.small),
|
||||
for (var index = 0; index < _models.length; index++)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: AppSpacing.medium),
|
||||
child: _ModelFields(
|
||||
index: index,
|
||||
controllers: _models[index],
|
||||
canDelete: _models.length > 1,
|
||||
onDelete: () {
|
||||
final removed = _models[index];
|
||||
setState(
|
||||
() => _models = [..._models]..removeAt(index),
|
||||
);
|
||||
removed.dispose();
|
||||
},
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => setState(
|
||||
() => _models = [..._models, _ModelControllers()],
|
||||
),
|
||||
icon: const Icon(Icons.add, size: AppIconSize.header),
|
||||
label: Text(context.l10n.agentAddModel),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.large),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: FilledButton(
|
||||
onPressed: widget.saving ? null : _submit,
|
||||
child: Text(context.l10n.agentSaveProvider),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
static String? _required(BuildContext context, String? value) =>
|
||||
value == null || value.trim().isEmpty
|
||||
? context.l10n.agentRequiredField
|
||||
: null;
|
||||
|
||||
static String? _validateUrl(BuildContext context, String? value) {
|
||||
final uri = Uri.tryParse(value?.trim() ?? '');
|
||||
return uri == null ||
|
||||
!uri.hasAuthority ||
|
||||
!['http', 'https'].contains(uri.scheme) ||
|
||||
uri.userInfo.isNotEmpty ||
|
||||
uri.hasQuery ||
|
||||
uri.hasFragment
|
||||
? context.l10n.agentInvalidBaseUrl
|
||||
: null;
|
||||
}
|
||||
|
||||
static String _apiTypeLabel(BuildContext context, AgentApiType value) =>
|
||||
switch (value) {
|
||||
AgentApiType.openAiChatCompletions =>
|
||||
context.l10n.agentOpenAiChatCompletions,
|
||||
AgentApiType.openAiResponses => 'OpenAI Responses',
|
||||
AgentApiType.anthropicMessages => 'Anthropic Messages',
|
||||
};
|
||||
}
|
||||
|
||||
class _ConfigurationCard extends StatelessWidget {
|
||||
const _ConfigurationCard({required this.title, required this.child});
|
||||
|
||||
final String title;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(title, style: theme.textTheme.labelLarge),
|
||||
const SizedBox(height: AppSpacing.medium),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.medium),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainer,
|
||||
borderRadius: BorderRadius.circular(AppSettingsMetrics.cardRadius),
|
||||
border: Border.all(color: theme.colorScheme.outlineVariant),
|
||||
),
|
||||
child: child,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ProviderIdentityRow extends StatelessWidget {
|
||||
const _ProviderIdentityRow({required this.children});
|
||||
final List<Widget> children;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => LayoutBuilder(
|
||||
builder: (context, constraints) => constraints.maxWidth < 520
|
||||
? AppFieldGroup(children: children)
|
||||
: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(child: children[0]),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(child: children[1]),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _ModelFields extends StatelessWidget {
|
||||
const _ModelFields({
|
||||
required this.index,
|
||||
required this.controllers,
|
||||
required this.canDelete,
|
||||
required this.onDelete,
|
||||
});
|
||||
|
||||
final int index;
|
||||
final _ModelControllers controllers;
|
||||
final bool canDelete;
|
||||
final VoidCallback onDelete;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final fields = <Widget>[
|
||||
AppField(
|
||||
label: context.l10n.agentModelId,
|
||||
child: TextFormField(
|
||||
style: _providerInputStyle(context),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
cursorHeight: 18,
|
||||
cursorWidth: 1.5,
|
||||
strutStyle: StrutStyle.fromTextStyle(_providerInputStyle(context)),
|
||||
key: Key('agent-model-id-$index'),
|
||||
controller: controllers.id,
|
||||
decoration: _providerInputDecoration(
|
||||
context,
|
||||
hintText: 'my-model-id',
|
||||
),
|
||||
validator: (value) => _ProviderEditorState._required(context, value),
|
||||
),
|
||||
),
|
||||
AppField(
|
||||
label: context.l10n.agentContextWindow,
|
||||
child: TextFormField(
|
||||
style: _providerInputStyle(context),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
cursorHeight: 18,
|
||||
cursorWidth: 1.5,
|
||||
strutStyle: StrutStyle.fromTextStyle(_providerInputStyle(context)),
|
||||
key: Key('agent-model-context-$index'),
|
||||
controller: controllers.contextWindow,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: _providerInputDecoration(context, hintText: '512000'),
|
||||
validator: (value) => _optionalPositiveInteger(context, value),
|
||||
),
|
||||
),
|
||||
AppField(
|
||||
label: context.l10n.agentMaxOutputTokens,
|
||||
child: TextFormField(
|
||||
style: _providerInputStyle(context),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
cursorHeight: 18,
|
||||
cursorWidth: 1.5,
|
||||
strutStyle: StrutStyle.fromTextStyle(_providerInputStyle(context)),
|
||||
key: Key('agent-model-output-$index'),
|
||||
controller: controllers.maxOutputTokens,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: _providerInputDecoration(context, hintText: '4096'),
|
||||
validator: (value) {
|
||||
final basic = _optionalPositiveInteger(context, value);
|
||||
if (basic != null) return basic;
|
||||
final contextWindow = int.tryParse(controllers.contextWindow.text);
|
||||
final model = AgentModelSettings(
|
||||
id: controllers.id.text,
|
||||
contextWindow: contextWindow,
|
||||
maxOutputTokens: int.tryParse(value ?? ''),
|
||||
);
|
||||
if (!model.hasValidTokenBudget) {
|
||||
return context.l10n.agentMaxOutputBelowContext;
|
||||
}
|
||||
return model.hasInstructionBudget
|
||||
? null
|
||||
: context.l10n.agentContextBudgetTooSmall;
|
||||
},
|
||||
),
|
||||
),
|
||||
];
|
||||
final removeButton = SizedBox.square(
|
||||
dimension: AppSettingsMetrics.inputHeight,
|
||||
child: IconButton(
|
||||
style: IconButton.styleFrom(
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: const Size.square(AppSettingsMetrics.inputHeight),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
tooltip: context.l10n.agentDeleteModel,
|
||||
onPressed: canDelete ? onDelete : null,
|
||||
icon: const Icon(Icons.delete_outline, size: AppIconSize.header),
|
||||
),
|
||||
);
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
if (constraints.maxWidth < 520) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
spacing: AppSpacing.compact,
|
||||
children: [
|
||||
...fields,
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: removeButton,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: AppSpacing.small,
|
||||
children: [
|
||||
for (var i = 0; i < fields.length; i++)
|
||||
Expanded(flex: i == 0 ? 2 : 1, child: fields[i]),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 26),
|
||||
child: removeButton,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
static String? _optionalPositiveInteger(BuildContext context, String? value) {
|
||||
if (value == null || value.trim().isEmpty) return null;
|
||||
final parsed = int.tryParse(value);
|
||||
return parsed == null || parsed <= 0
|
||||
? context.l10n.agentPositiveInteger
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
class _ModelControllers {
|
||||
_ModelControllers([AgentModelSettings? model])
|
||||
: id = TextEditingController(text: model?.id),
|
||||
contextWindow = TextEditingController(
|
||||
text: model?.contextWindow?.toString(),
|
||||
),
|
||||
maxOutputTokens = TextEditingController(
|
||||
text: model?.maxOutputTokens?.toString(),
|
||||
);
|
||||
|
||||
final TextEditingController id;
|
||||
final TextEditingController contextWindow;
|
||||
final TextEditingController maxOutputTokens;
|
||||
|
||||
AgentModelSettings toData() => AgentModelSettings(
|
||||
id: id.text.trim(),
|
||||
contextWindow: int.tryParse(contextWindow.text),
|
||||
maxOutputTokens: int.tryParse(maxOutputTokens.text),
|
||||
);
|
||||
|
||||
void dispose() {
|
||||
id.dispose();
|
||||
contextWindow.dispose();
|
||||
maxOutputTokens.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class _ProviderFormValue with _$ProviderFormValue {
|
||||
const factory _ProviderFormValue({
|
||||
required String name,
|
||||
required AgentApiType apiType,
|
||||
required String baseUrl,
|
||||
required List<AgentModelSettings> models,
|
||||
required String? apiKey,
|
||||
required bool clearApiKey,
|
||||
}) = _ProviderFormData;
|
||||
}
|
||||
Reference in new issue
Block a user