Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
107 lines
3.8 KiB
Dart
107 lines
3.8 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../integrations/platform/file_picker.dart';
|
|
import '../../integrations/platform/platform_capabilities.dart';
|
|
import '../../workspace/media_file_extensions.dart';
|
|
import '../../workspace/external_media_import.dart';
|
|
import '../../workspace/projects.dart';
|
|
import 'agent_composer_controller.dart';
|
|
import 'agent_media_attachments.dart';
|
|
import 'composer_document.dart';
|
|
|
|
/// Composition survives presentation changes, including temporarily hidden chat.
|
|
final agentComposerStoreProvider = Provider<AgentComposerStore>((ref) {
|
|
final store = AgentComposerStore(
|
|
createComposer: (projectId) => AgentComposerController(
|
|
canImport: () =>
|
|
ref.mounted &&
|
|
projectId != null &&
|
|
ref.read(platformCapabilitiesProvider).localFileSelection &&
|
|
ref.read(projectsProvider).value?.activeProject?.id == projectId &&
|
|
ref.read(projectsProvider).value?.projectBusy == false &&
|
|
!ref.read(externalMediaImportProvider(projectId)).isLoading,
|
|
pickFiles: () => ref
|
|
.read(filePickerProvider)
|
|
.pickFiles(allowedExtensions: selectableMediaFileExtensions),
|
|
importMedia: (files) => ref
|
|
.read(externalMediaImportProvider(projectId!).notifier)
|
|
.importFiles(files),
|
|
),
|
|
);
|
|
ref.onDispose(store.dispose);
|
|
return store;
|
|
});
|
|
|
|
final class AgentComposerStore {
|
|
AgentComposerStore({required this.createComposer});
|
|
final AgentComposerController Function(String?) createComposer;
|
|
ComposerDocumentController _draft = ComposerDocumentController();
|
|
ComposerDocumentController get draft => _draft;
|
|
final _projectDrafts = <String?, ComposerDocumentController>{};
|
|
final _inputs = <(String?, String), ComposerDocumentController>{};
|
|
final _composers = <(String?, String), AgentComposerController>{};
|
|
|
|
ComposerDocumentController input(
|
|
String? projectId,
|
|
String? conversationId, {
|
|
bool projectScoped = false,
|
|
}) => conversationId == null
|
|
? projectScoped
|
|
? _projectDrafts.putIfAbsent(
|
|
projectId,
|
|
() => projectId == null
|
|
? ComposerDocumentController()
|
|
: _projectDrafts.remove(null) ??
|
|
ComposerDocumentController(),
|
|
)
|
|
: draft
|
|
: _inputs.putIfAbsent((
|
|
projectId,
|
|
conversationId,
|
|
), ComposerDocumentController.new);
|
|
|
|
List<AgentMediaAttachment> attachments(String? projectId, String key) =>
|
|
composer(projectId, key).attachments;
|
|
|
|
AgentComposerController composer(String? projectId, String key) =>
|
|
_composers.putIfAbsent((projectId, key), () => createComposer(projectId));
|
|
|
|
void promoteDraft(String projectId, String draftKey, String conversationId) {
|
|
final destination = (projectId, conversationId);
|
|
_inputs.remove(destination)?.dispose();
|
|
final scoped = _projectDrafts.remove(projectId);
|
|
_inputs[destination] = scoped ?? _draft;
|
|
if (scoped == null) _draft = ComposerDocumentController();
|
|
final composer = _composers.remove((projectId, draftKey));
|
|
if (composer != null) {
|
|
_composers.remove(destination)?.dispose();
|
|
_composers[destination] = composer;
|
|
}
|
|
}
|
|
|
|
void removeConversation(String projectId, String conversationId) {
|
|
_inputs.remove((projectId, conversationId))?.dispose();
|
|
_composers.remove((projectId, conversationId))?.dispose();
|
|
}
|
|
|
|
void removeDraft(String? projectId, String draftKey) {
|
|
_composers.remove((projectId, draftKey))?.dispose();
|
|
}
|
|
|
|
void dispose() {
|
|
draft.dispose();
|
|
for (final input in _projectDrafts.values) {
|
|
input.dispose();
|
|
}
|
|
_projectDrafts.clear();
|
|
for (final input in _inputs.values) {
|
|
input.dispose();
|
|
}
|
|
_inputs.clear();
|
|
for (final composer in _composers.values) {
|
|
composer.dispose();
|
|
}
|
|
_composers.clear();
|
|
}
|
|
}
|