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,282 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../../integrations/agent/conversation_repository.dart';
|
||||
import '../../workspace/project_state.dart';
|
||||
import '../../workspace/projects.dart';
|
||||
import '../assistant/agent_conversation_service.dart';
|
||||
import '../assistant/agent_composer_store.dart';
|
||||
|
||||
part 'conversation_sidebar.g.dart';
|
||||
part 'conversation_sidebar.freezed.dart';
|
||||
|
||||
@freezed
|
||||
abstract class ConversationSnapshot with _$ConversationSnapshot {
|
||||
const factory ConversationSnapshot({
|
||||
String? projectId,
|
||||
@Default({}) Map<String, List<ConversationMetadata>> groups,
|
||||
@Default([]) List<ConversationMetadata> trashed,
|
||||
String? selectedId,
|
||||
@Default(false) bool reloadFailed,
|
||||
}) = _ConversationSnapshot;
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class ConversationWorkspaceKey with _$ConversationWorkspaceKey {
|
||||
const factory ConversationWorkspaceKey({
|
||||
String? projectId,
|
||||
required List<String> projectIds,
|
||||
}) = _ConversationWorkspaceKey;
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class ConversationSelectionState with _$ConversationSelectionState {
|
||||
const factory ConversationSelectionState({
|
||||
String? selectedId,
|
||||
required String draftKey,
|
||||
@Default(false) bool initialized,
|
||||
}) = _ConversationSelectionState;
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
Future<String?> savedConversationSelection(Ref ref, String? projectId) async {
|
||||
if (projectId == null) return null;
|
||||
ref.watch(projectsProvider.select((value) => value.value?.activeProject?.id));
|
||||
final repository = await ref.watch(conversationRepositoryProvider.future);
|
||||
return repository.selected(projectId);
|
||||
}
|
||||
|
||||
/// Keeps a draft or explicit selection stable while the list refreshes.
|
||||
@Riverpod(keepAlive: true)
|
||||
class ConversationSelection extends _$ConversationSelection {
|
||||
String? _draftKey;
|
||||
@override
|
||||
ConversationSelectionState build(String? projectId) {
|
||||
final composers = ref.read(agentComposerStoreProvider);
|
||||
ref.onDispose(() {
|
||||
if (_draftKey case final key?) composers.removeDraft(projectId, key);
|
||||
});
|
||||
ref.watch(
|
||||
projectsProvider.select((value) => value.value?.activeProject?.id),
|
||||
);
|
||||
final saved = savedConversationSelectionProvider(projectId);
|
||||
ref.listen(saved, (_, next) {
|
||||
if (!state.initialized &&
|
||||
next.hasValue &&
|
||||
!next.isLoading &&
|
||||
!next.hasError) {
|
||||
state = state.copyWith(selectedId: next.value, initialized: true);
|
||||
}
|
||||
});
|
||||
final selected = ref.read(saved);
|
||||
final initialized =
|
||||
selected.hasValue && !selected.isLoading && !selected.hasError;
|
||||
_draftKey = const Uuid().v4();
|
||||
return ConversationSelectionState(
|
||||
draftKey: _draftKey!,
|
||||
selectedId: initialized ? selected.value : null,
|
||||
initialized: initialized,
|
||||
);
|
||||
}
|
||||
|
||||
void newConversation() {
|
||||
ref.read(agentComposerStoreProvider).removeDraft(projectId, state.draftKey);
|
||||
_draftKey = const Uuid().v4();
|
||||
state = ConversationSelectionState(draftKey: _draftKey!, initialized: true);
|
||||
}
|
||||
|
||||
void select(String id) =>
|
||||
state = state.copyWith(selectedId: id, initialized: true);
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class ConversationSidebar extends _$ConversationSidebar {
|
||||
int _revision = 0;
|
||||
|
||||
@override
|
||||
Future<ConversationSnapshot> build() async {
|
||||
await ref.watch(
|
||||
projectsProvider.selectAsync(
|
||||
(workspace) => ConversationWorkspaceKey(
|
||||
projectId: workspace.activeProject?.id,
|
||||
projectIds: [for (final project in workspace.recent) project.id],
|
||||
),
|
||||
),
|
||||
);
|
||||
_revision++;
|
||||
final workspace = ref.read(projectsProvider).requireValue;
|
||||
return _load(workspace);
|
||||
}
|
||||
|
||||
Future<ConversationSnapshot> _load(ProjectState workspace) async {
|
||||
final projectId = workspace.activeProject?.id;
|
||||
if (projectId == null && workspace.recent.isEmpty) {
|
||||
return const ConversationSnapshot();
|
||||
}
|
||||
final repository = await ref.read(conversationRepositoryProvider.future);
|
||||
final lists = await Future.wait([
|
||||
for (final project in workspace.recent) repository.list(project.id),
|
||||
]);
|
||||
return ConversationSnapshot(
|
||||
projectId: projectId,
|
||||
groups: {
|
||||
for (var index = 0; index < workspace.recent.length; index++)
|
||||
workspace.recent[index].id: List.unmodifiable(lists[index]),
|
||||
},
|
||||
trashed: projectId == null
|
||||
? const []
|
||||
: List.unmodifiable(await repository.list(projectId, trash: true)),
|
||||
selectedId: await ref.read(
|
||||
savedConversationSelectionProvider(projectId).future,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> reload() async {
|
||||
final revision = ++_revision;
|
||||
final workspace = ref.read(projectsProvider).requireValue;
|
||||
try {
|
||||
final next = await _load(workspace);
|
||||
if (!ref.mounted ||
|
||||
revision != _revision ||
|
||||
ref.read(projectsProvider).value?.activeProject?.id !=
|
||||
next.projectId) {
|
||||
return;
|
||||
}
|
||||
state = AsyncData(next);
|
||||
} catch (error, stack) {
|
||||
if (ref.mounted && revision == _revision) {
|
||||
state = state.value == null
|
||||
? AsyncError(error, stack)
|
||||
: AsyncData(state.requireValue.copyWith(reloadFailed: true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void newConversation() => ref
|
||||
.read(
|
||||
conversationSelectionProvider(
|
||||
ref.read(projectsProvider).value?.activeProject?.id,
|
||||
).notifier,
|
||||
)
|
||||
.newConversation();
|
||||
|
||||
Future<void> rememberSelection(ConversationMetadata item) async {
|
||||
final repository = await ref.read(conversationRepositoryProvider.future);
|
||||
await repository.select(item.projectId, item.id);
|
||||
if (ref.mounted) {
|
||||
ref.invalidate(savedConversationSelectionProvider(item.projectId));
|
||||
}
|
||||
}
|
||||
|
||||
void activate(ConversationMetadata item) => ref
|
||||
.read(conversationSelectionProvider(item.projectId).notifier)
|
||||
.select(item.id);
|
||||
|
||||
Future<void> updateListing(
|
||||
ConversationMetadata item, {
|
||||
String? selectIfDraftKey,
|
||||
}) async {
|
||||
if (ref.read(projectsProvider).value?.activeProject?.id != item.projectId) {
|
||||
return;
|
||||
}
|
||||
final current = state.value ?? await future;
|
||||
if (!ref.mounted) return;
|
||||
_revision++;
|
||||
if (ref.read(projectsProvider).value?.activeProject?.id != item.projectId) {
|
||||
return;
|
||||
}
|
||||
final selection = ref.read(conversationSelectionProvider(item.projectId));
|
||||
final selectCreated =
|
||||
selectIfDraftKey != null &&
|
||||
selection.selectedId == null &&
|
||||
selection.draftKey == selectIfDraftKey;
|
||||
state = AsyncData(
|
||||
current.copyWith(
|
||||
groups: {
|
||||
...current.groups,
|
||||
item.projectId: [
|
||||
item,
|
||||
...?current.groups[item.projectId]?.where(
|
||||
(existing) => existing.id != item.id,
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
);
|
||||
if (selectCreated) {
|
||||
ref
|
||||
.read(agentComposerStoreProvider)
|
||||
.promoteDraft(item.projectId, selectIfDraftKey, item.id);
|
||||
activate(item);
|
||||
await rememberSelection(item);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> rename(ConversationMetadata item, String title) =>
|
||||
updateMetadata(item.copyWith(title: title));
|
||||
Future<void> updateMetadata(ConversationMetadata item) async {
|
||||
final repository = await ref.read(conversationRepositoryProvider.future);
|
||||
await repository.update(item);
|
||||
if (ref.mounted) await reload();
|
||||
}
|
||||
|
||||
Future<void> trash(ConversationMetadata item) async {
|
||||
await ref
|
||||
.read(agentConversationRegistryProvider)
|
||||
.cancel(item.projectId, item.id);
|
||||
final repository = await ref.read(conversationRepositoryProvider.future);
|
||||
await repository.trash(item.projectId, item.id);
|
||||
if (!ref.mounted) return;
|
||||
_forgetRemovedSelection(item);
|
||||
await reload();
|
||||
}
|
||||
|
||||
Future<void> restore(ConversationMetadata item) async {
|
||||
final repository = await ref.read(conversationRepositoryProvider.future);
|
||||
await repository.restore(item.projectId, item.id);
|
||||
if (ref.mounted) {
|
||||
ref.invalidate(savedConversationSelectionProvider(item.projectId));
|
||||
await reload();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> delete(ConversationMetadata item) async {
|
||||
await ref
|
||||
.read(agentConversationRegistryProvider)
|
||||
.cancel(item.projectId, item.id);
|
||||
final repository = await ref.read(conversationRepositoryProvider.future);
|
||||
await repository.deletePermanently(item.projectId, item.id);
|
||||
if (!ref.mounted) return;
|
||||
_forgetRemovedSelection(item);
|
||||
ref
|
||||
.read(agentComposerStoreProvider)
|
||||
.removeConversation(item.projectId, item.id);
|
||||
await reload();
|
||||
}
|
||||
|
||||
void _forgetRemovedSelection(ConversationMetadata item) {
|
||||
ref.invalidate(savedConversationSelectionProvider(item.projectId));
|
||||
if (ref.read(projectsProvider).value?.activeProject?.id == item.projectId &&
|
||||
ref.read(conversationSelectionProvider(item.projectId)).selectedId ==
|
||||
item.id) {
|
||||
newConversation();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> emptyTrash() async {
|
||||
final items = state.value?.trashed ?? const <ConversationMetadata>[];
|
||||
final repository = await ref.read(conversationRepositoryProvider.future);
|
||||
for (final item in items) {
|
||||
await repository.deletePermanently(item.projectId, item.id);
|
||||
if (!ref.mounted) return;
|
||||
_forgetRemovedSelection(item);
|
||||
ref
|
||||
.read(agentComposerStoreProvider)
|
||||
.removeConversation(item.projectId, item.id);
|
||||
}
|
||||
if (ref.mounted) await reload();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user