feat(workspace): 桌面工作区、主题与交互更新,发布 0.1.2
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

This commit was merged in pull request #13.
This commit is contained in:
lingjhf committed 2026-10-08 18:17:12 +00:00
1 parent aa5255d1e4
commit abc1868550
260 files changed
+43964 -5591

No files matched your search

+80 -201
View File
@@ -1,3 +1,5 @@
import 'agent_reply_region.dart';
import 'package:cutdex/shared/widgets/error_notification_host.dart';
import '../../shared/layout/composer_layout.dart';
@@ -9,6 +11,8 @@ import 'package:cutdex_sdk/project.dart';
import '../../integrations/platform/platform_capabilities.dart';
import 'agent_composer_controller.dart';
import 'agent_attachment_drop_region.dart';
import 'agent_chat_actions.dart';
import 'agent_composer_store.dart';
import 'package:flutter/material.dart';
@@ -16,21 +20,17 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../integrations/agent/agent_provider.dart';
import 'package:cutdex_ui/icons.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import '../../shared/widgets/drop_to_add_overlay.dart';
import '../settings/settings_page.dart';
import 'chat_controller.dart';
import 'chat_state.dart';
import '../../integrations/agent/conversation_repository.dart';
import '../../integrations/platform/native_project_drop_region.dart';
import '../../integrations/platform/native_file_drop_policy.dart';
import '../../workspace/media_import.dart';
import '../../workspace/external_media_import.dart';
import '../../settings/settings_operation.dart';
import '../../workspace/projects.dart';
import '../media/media_asset_drag.dart';
import '../media/media_browser_feedback.dart';
import 'agent_attachment_card.dart';
import 'agent_media_attachments.dart';
@@ -97,8 +97,7 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
'agent-model-${widget.projectId}-${widget.conversationId ?? widget.draftKey ?? 'new'}';
bool get _choosingModel =>
ref.read(settingsOperationProvider(_modelOperation)).isLoading;
bool _usingDraftModel = false;
bool _dropHovering = false;
bool get _usingDraftModel => _composer.usingDraftModel;
bool get _importingAttachments =>
_composer.busy ||
widget.projectId != null &&
@@ -143,33 +142,12 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
if (oldWidget.conversationId != widget.conversationId ||
oldWidget.projectId != widget.projectId ||
oldWidget.draftKey != widget.draftKey) {
_usingDraftModel = false;
_composer.removeListener(_composerChanged);
_composer = _resolveComposer();
_composer.addListener(_composerChanged);
}
}
String _errorMessage(BuildContext context, AgentChatError error) =>
switch (error) {
AgentChatError.configurationReadFailed =>
context.l10n.agentConfigurationReadFailed,
AgentChatError.configurationRequired =>
context.l10n.agentConfigurationRequired,
AgentChatError.sessionRestoreFailed =>
context.l10n.agentSessionRestoreFailed,
AgentChatError.contextBudget => context.l10n.agentContextBudgetExceeded,
AgentChatError.authentication => context.l10n.agentAuthenticationFailed,
AgentChatError.exportReplyFailed => context.l10n.agentExportReplyFailed,
AgentChatError.connection => context.l10n.agentConnectionFailed,
AgentChatError.protocol => context.l10n.agentProtocolFailed,
AgentChatError.turnLimit => context.l10n.agentTurnLimitReached,
AgentChatError.interrupted => context.l10n.agentTaskInterrupted,
AgentChatError.recoveryRequired => context.l10n.agentRecoveryRequired,
AgentChatError.replyFailed => context.l10n.replyFailed,
AgentChatError.requestFailed => context.l10n.chatFailed,
};
@override
void initState() {
super.initState();
@@ -189,41 +167,6 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
super.dispose();
}
bool _canAttach(MediaAssetDrag drag) {
final workspace = ref.read(projectsProvider).asData?.value;
return widget.projectId == drag.projectId &&
workspace?.activeProject?.id == drag.projectId &&
!_attachments.any((item) => item.id == drag.assetId) &&
workspace!.assets.any((asset) => asset.id == drag.assetId);
}
bool _canAttachExternalFiles(List<ExternalMediaFile> files) {
if (files.isEmpty) return true;
final assets = ref.read(projectsProvider).asData?.value.assets;
if (assets == null) return false;
final attachedIds = {for (final item in _attachments) item.id};
final attachedLocations = {
for (final asset in assets)
if (attachedIds.contains(asset.id)) ?mediaSourceLocation(asset),
};
return files.any(
(file) => !attachedLocations.contains(file.sourceUri.toString()),
);
}
void _attachAsset(AssetDocument asset) => _composer.attach(asset);
bool get _desktop => ref.read(platformCapabilitiesProvider).nativeFileDrop;
Future<void> _dropExternalFiles(List<ExternalMediaFile> files) async {
setState(() => _dropHovering = false);
try {
await _composer.importAttachments(files);
} catch (_) {
// Feedback belongs to the composer even if this panel is hidden.
}
}
Future<void> _pickAttachments() async {
try {
await _composer.pickAttachments();
@@ -232,64 +175,27 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
}
}
Widget _agentDropRegion(Widget child) {
final workspace = ref.watch(projectsProvider).asData?.value;
final enabled =
_desktop &&
widget.projectId != null &&
workspace?.activeProject?.id == widget.projectId &&
(workspace?.projectBusy == false || _importingAttachments);
final internal = DragTarget<MediaAssetDrag>(
key: const Key('agent-panel-drop-target'),
hitTestBehavior: HitTestBehavior.opaque,
onWillAcceptWithDetails: (details) => _canAttach(details.data),
onAcceptWithDetails: (details) {
final drag = details.data;
if (!_canAttach(drag)) return;
final asset = ref
.read(projectsProvider)
.asData!
.value
.assets
.firstWhere((item) => item.id == drag.assetId);
_attachAsset(asset);
},
builder: (context, candidates, rejected) => Stack(
fit: StackFit.expand,
children: [
child,
if (candidates.isNotEmpty || _dropHovering)
const Positioned.fill(
child: DropToAddOverlay(key: Key('agent-drop-overlay')),
),
],
),
);
if (!_desktop) return internal;
return NativeProjectDropRegion(
regionId: 'attachments',
policy: NativeFileDropPolicy.attachments,
enabled: enabled,
onEnter: (files) {
if (!_importingAttachments && _canAttachExternalFiles(files)) {
setState(() => _dropHovering = true);
}
},
onExit: () {
if (mounted && _dropHovering) setState(() => _dropHovering = false);
},
onDrop: _dropExternalFiles,
child: internal,
);
}
@override
Widget build(BuildContext context) {
ref.watch(settingsOperationProvider(_modelOperation));
ref.watch(
settingsOperationProvider(_modelOperation)
.select((value) => value.isLoading),
);
if (widget.projectId != null) {
ref.watch(externalMediaImportProvider(widget.projectId!));
ref.watch(
externalMediaImportProvider(widget.projectId!)
.select((value) => value.isLoading),
);
}
final workspace = ref.watch(projectsProvider).asData?.value;
final workspace = ref.watch(
projectsProvider.select(
(value) => value.asData?.value.copyWith(
recent: const [],
error: null,
creatingTimeline: false,
),
),
);
final referenceValidator = ComposerReferenceValidator(
workspace: workspace,
projectId: widget.projectId,
@@ -305,7 +211,9 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
draftKey: widget.draftKey,
)
: null;
final state = provider == null ? const ChatState() : ref.watch(provider);
final state = provider == null
? const ChatState()
: ref.watch(provider.select(chatChrome));
final settings = ref.watch(agentSettingsProvider).asData?.value;
final available =
settings?.providers
@@ -360,7 +268,7 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
});
if (!mounted || !context.mounted) return;
if (saved) {
setState(() => _usingDraftModel = true);
_composer.useDraftModel();
} else {
ErrorNotificationHost.of(context).show(
ErrorNotification(
@@ -379,7 +287,7 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
key: const Key('agent-configure-model'),
style: compactButtonStyle,
onPressed: () => showSettingsPage(context, initialTab: 1),
icon: const Icon(Icons.tune, size: 16),
icon: const Icon(AppIcons.tune, size: 16),
label: Text(context.l10n.agentConfigureModel),
);
}
@@ -423,14 +331,14 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
),
),
const SizedBox(width: 4),
const Icon(Icons.expand_more, size: 14),
const Icon(AppIcons.expandMore, size: 14),
],
),
),
);
}
if (provider != null) {
if (provider != null && TickerMode.valuesOf(context).enabled) {
ref.listen(provider, (previous, next) {
if (_follow) {
WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -453,12 +361,7 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
(_input.text.trim().isEmpty && _attachments.isEmpty)) {
return;
}
final text = AgentComposerMessage.encodeDocument(
_input.segments,
_attachments,
);
_input.clearDocument();
_composer.clear();
final text = takeAgentDraft(_input, _composer);
_follow = true;
ref
.read(provider.notifier)
@@ -471,8 +374,10 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
}
final theme = Theme.of(context);
final content = _agentDropRegion(
LayoutBuilder(
final content = AgentAttachmentDropRegion(
projectId: widget.projectId,
composer: _composer,
child: LayoutBuilder(
builder: (context, constraints) {
final panelWidth =
(constraints.maxWidth - ComposerLayout.horizontalInset * 2)
@@ -562,8 +467,8 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
),
),
Icon(
Icons
.chevron_right,
AppIcons
.chevronRight,
size: 14,
color:
AppTheme.chatMetaTextStyle(
@@ -575,7 +480,6 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
),
Divider(
height: 1,
thickness: 1,
color:
theme.dividerColor,
),
@@ -640,32 +544,39 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
in AgentComposerMessage.decode(
message.text,
).attachments)
if (ref
.watch(
projectsProvider,
)
.asData
?.value
.assets
.where(
(
asset,
) =>
asset.id ==
attachment.id,
)
.firstOrNull
case final asset?)
AgentAttachmentCard(
asset: asset,
)
else
Chip(
label: Text(
attachment
.name,
),
),
Consumer(
builder: (context, ref, _) {
final asset = ref.watch(
projectsProvider.select(
(
value,
) => value
.asData
?.value
.assets
.where(
(
asset,
) =>
asset.id ==
attachment.id,
)
.firstOrNull,
),
);
return asset ==
null
? Chip(
label: Text(
attachment.name,
),
)
: AgentAttachmentCard(
asset:
asset,
);
},
),
],
),
),
@@ -681,44 +592,12 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
],
),
),
if (state.busy) ...[
if (state
.partialResponse
.isNotEmpty)
SelectableText(
state.partialResponse,
style:
AppTheme.chatMessageTextStyle(
context,
),
),
Text(
state.stopping
? context.l10n.stopping
: switch (state.activity) {
AgentChatActivity
.compacting =>
context
.l10n
.agentCompacting,
AgentChatActivity
.editing =>
context
.l10n
.agentEditing,
AgentChatActivity
.verifying =>
context
.l10n
.agentVerifying,
AgentChatActivity
.replying =>
context.l10n.replying,
},
style:
theme.textTheme.bodySmall,
),
],
AgentReplyRegion(
projectId: widget.projectId,
conversationId:
widget.conversationId,
draftKey: widget.draftKey,
),
],
),
),
@@ -751,7 +630,7 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
horizontal: AppSpacing.compact,
),
child: Text(
_errorMessage(context, error),
agentChatErrorMessage(context, error),
style: theme.textTheme.bodySmall,
),
),
@@ -1045,7 +924,7 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
? _pickAttachments
: null,
icon: const Icon(
Icons.add,
AppIcons.add,
),
),
const SizedBox(
@@ -1085,7 +964,7 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
)
.stop,
icon: const Icon(
Icons.stop,
AppIcons.stop,
),
)
else
@@ -1120,7 +999,7 @@ class _AgentChatPanelState extends ConsumerState<AgentChatPanel> {
? send
: null,
icon: const Icon(
Icons.arrow_upward,
AppIcons.arrowUp,
),
),
),