Send artifacts, runs and pipelines to a new or existing chat
One picker offers a new chat (the saved Open in chat harness and model) or any open chat. An existing chat gets the reference appended to its draft and focused, never sent. Artifacts gain the action in their viewer and gallery; the run and pipeline item becomes Send to chat.
This commit is contained in:
@@ -26,6 +26,7 @@ import '../features/attention/runtime/attention_controller.dart';
|
||||
import '../features/attention/runtime/attention_store.dart';
|
||||
import '../features/runs/ui/run_search_selection.dart';
|
||||
import '../features/artifacts/domain/artifact_groups.dart';
|
||||
import '../features/artifacts/domain/artifact_chat_context.dart';
|
||||
import '../features/artifacts/domain/artifact_record.dart';
|
||||
import '../features/artifacts/ui/artifact_viewer_page.dart';
|
||||
import '../features/artifacts/domain/gallery_navigation.dart';
|
||||
@@ -49,6 +50,7 @@ import 'app_terminals.dart';
|
||||
import '../features/chat/chat_runtime.dart';
|
||||
import '../features/chat/windows/chat_windows.dart';
|
||||
import 'open_in_chat.dart';
|
||||
import 'send_to_chat.dart';
|
||||
import '../features/pipelines/pipeline_models.dart';
|
||||
import '../features/chat/workspace/chat_float_store.dart';
|
||||
import '../features/terminal/terminal_layout.dart';
|
||||
@@ -153,7 +155,7 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
? await settingsWorkspace(serverIdentity(_session.gateway) ?? '')
|
||||
: directory;
|
||||
if (!context.mounted) return;
|
||||
await openReferenceInChat(
|
||||
await showSendToChatPicker(
|
||||
context: context,
|
||||
runtime: _chatRuntime,
|
||||
selectChat: (id) => _delegate.goTo(AppRoute.chatSession(id)),
|
||||
@@ -182,7 +184,7 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
? await settingsWorkspace(serverIdentity(_session.gateway) ?? '')
|
||||
: directory;
|
||||
if (!context.mounted) return;
|
||||
await openReferenceInChat(
|
||||
await showSendToChatPicker(
|
||||
context: context,
|
||||
runtime: _chatRuntime,
|
||||
selectChat: (id) => _delegate.goTo(AppRoute.chatSession(id)),
|
||||
@@ -203,6 +205,26 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _sendArtifactToChat(
|
||||
BuildContext context,
|
||||
JsonMap run,
|
||||
String draft,
|
||||
) async {
|
||||
final directory = '${run['workspace'] ?? run['directory'] ?? ''}'.trim();
|
||||
final fallback = directory.isEmpty
|
||||
? await settingsWorkspace(serverIdentity(_session.gateway) ?? '')
|
||||
: directory;
|
||||
if (!context.mounted) return;
|
||||
await showSendToChatPicker(
|
||||
context: context,
|
||||
runtime: _chatRuntime,
|
||||
selectChat: (id) => _delegate.goTo(AppRoute.chatSession(id)),
|
||||
directory: fallback,
|
||||
title: 'Artifact · Run #${run['id'] ?? ''}',
|
||||
draft: draft,
|
||||
);
|
||||
}
|
||||
|
||||
late final AppSession _session;
|
||||
late final AppRouterDelegate _delegate;
|
||||
late final ElevationPrompt _elevationPrompt = elevationDialogPrompt(
|
||||
@@ -947,6 +969,22 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
groups: <ArtifactGroup>[group],
|
||||
selectedIdentity: artifactVisitIdentityOf(group, record),
|
||||
configuredEndpoint: configuredGatewayEndpoint(_session.gateway),
|
||||
onSendToChat: (page) => _sendArtifactToChat(
|
||||
context,
|
||||
<String, dynamic>{'id': route.runId},
|
||||
artifactChatReference(
|
||||
ArtifactChatContext(
|
||||
runId: '${route.runId}',
|
||||
runTitle: 'Run ${route.runId}',
|
||||
pipelineName: 'Unknown',
|
||||
stageKey: 'notification',
|
||||
visit: route.artifactSequence,
|
||||
configuredEndpoint: configuredGatewayEndpoint(_session.gateway),
|
||||
),
|
||||
page.group,
|
||||
page.artifact,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1047,6 +1085,7 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
onOpenPipeline: (id, version) =>
|
||||
_delegate.goTo(AppRoute.pipeline(id, version: version)),
|
||||
onOpenInChat: _openRunInChat,
|
||||
onSendToChat: _sendArtifactToChat,
|
||||
),
|
||||
),
|
||||
AppDestination.chat: (_) => ChatDestination(
|
||||
|
||||
@@ -36,6 +36,7 @@ class RunsDestination extends StatelessWidget {
|
||||
this.notifications,
|
||||
this.attention,
|
||||
this.onOpenInChat,
|
||||
this.onSendToChat,
|
||||
});
|
||||
|
||||
final AppSession session;
|
||||
@@ -68,6 +69,7 @@ class RunsDestination extends StatelessWidget {
|
||||
/// The app-level attention controller the shell's Runs tab badge reads.
|
||||
final AttentionController? attention;
|
||||
final Future<void> Function(BuildContext, JsonMap)? onOpenInChat;
|
||||
final Future<void> Function(BuildContext, JsonMap, String)? onSendToChat;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AnimatedBuilder(
|
||||
@@ -113,5 +115,6 @@ class RunsDestination extends StatelessWidget {
|
||||
onPipelineFilterChanged: onPipelineFilterChanged,
|
||||
onOpenPipeline: onOpenPipeline,
|
||||
onOpenInChat: onOpenInChat,
|
||||
onSendToChat: onSendToChat,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../features/chat/chat_runtime.dart';
|
||||
import '../features/chat/domain/chat_sessions.dart';
|
||||
import '../features/chat/ui/sessions/chat_create_fields.dart';
|
||||
import '../ui/adaptive/app_popups.dart';
|
||||
import 'open_in_chat.dart';
|
||||
|
||||
/// Shows the common destination picker used by runs, pipelines and artifacts.
|
||||
/// The draft is always placed in the composer; no option sends it.
|
||||
Future<void> showSendToChatPicker({
|
||||
required BuildContext context,
|
||||
required ChatRuntime runtime,
|
||||
required ValueChanged<String> selectChat,
|
||||
required String directory,
|
||||
required String title,
|
||||
required String draft,
|
||||
}) async {
|
||||
if (runtime.sessions.loading && runtime.sessions.sessions.isEmpty) {
|
||||
unawaited(runtime.sessions.refresh());
|
||||
}
|
||||
final choice = await showAppDetails<_ChatChoice>(
|
||||
context,
|
||||
maxWidth: 600,
|
||||
builder: (context) => _SendToChatSheet(runtime: runtime, title: title),
|
||||
);
|
||||
if (!context.mounted || choice == null) return;
|
||||
if (choice.newChat) {
|
||||
await openReferenceInChat(
|
||||
context: context,
|
||||
runtime: runtime,
|
||||
selectChat: selectChat,
|
||||
directory: directory,
|
||||
title: title,
|
||||
draft: draft,
|
||||
);
|
||||
return;
|
||||
}
|
||||
final id = choice.id;
|
||||
if (id == null || id.isEmpty) return;
|
||||
await runtime.appendDraft(id, draft);
|
||||
selectChat(id);
|
||||
runtime.composerFocus.request(id);
|
||||
}
|
||||
|
||||
class _ChatChoice {
|
||||
const _ChatChoice.newChat() : newChat = true, id = null;
|
||||
const _ChatChoice.existing(this.id) : newChat = false;
|
||||
final bool newChat;
|
||||
final String? id;
|
||||
}
|
||||
|
||||
class _SendToChatSheet extends StatefulWidget {
|
||||
const _SendToChatSheet({required this.runtime, required this.title});
|
||||
final ChatRuntime runtime;
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<_SendToChatSheet> createState() => _SendToChatSheetState();
|
||||
}
|
||||
|
||||
class _SendToChatSheetState extends State<_SendToChatSheet> {
|
||||
final _search = TextEditingController();
|
||||
String _query = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_search.addListener(() => setState(() => _query = _search.text));
|
||||
widget.runtime.sessions.addListener(_changed);
|
||||
}
|
||||
|
||||
void _changed() {
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.runtime.sessions.removeListener(_changed);
|
||||
_search.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> get _rows {
|
||||
final rows = filterChatSessions(widget.runtime.sessions.sessions, _query)
|
||||
.where((row) {
|
||||
final id = '${row['id'] ?? ''}';
|
||||
return id.isNotEmpty &&
|
||||
row['closed_at'] == null &&
|
||||
row['closed'] != true;
|
||||
})
|
||||
.toList();
|
||||
final active = widget.runtime.sessions.activeSessionId;
|
||||
rows.sort((a, b) {
|
||||
int priority(Map<String, dynamic> row) {
|
||||
final id = '${row['id'] ?? ''}';
|
||||
if (id == active) return 0;
|
||||
if (widget.runtime.openedForWork.contains(id)) return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
final byPriority = priority(a).compareTo(priority(b));
|
||||
if (byPriority != 0) return byPriority;
|
||||
return chatSessionMillis(
|
||||
b['updated_at'],
|
||||
).compareTo(chatSessionMillis(a['updated_at']));
|
||||
});
|
||||
return rows;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final sessions = _rows;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text('Send to chat', style: Theme.of(context).textTheme.titleLarge),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _search,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Search chats',
|
||||
prefixIcon: Icon(Icons.search),
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.sizeOf(context).height * .55,
|
||||
),
|
||||
child: ListView(
|
||||
// As tall as its rows up to the cap, then it scrolls: a short
|
||||
// list leaves no empty space, a long one fits phone sheets and
|
||||
// desktop dialogs.
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.add_comment_outlined),
|
||||
title: const Text('New chat'),
|
||||
subtitle: const Text('Use the saved Open in chat settings'),
|
||||
onTap: () =>
|
||||
Navigator.of(context).pop(const _ChatChoice.newChat()),
|
||||
),
|
||||
if (sessions.isEmpty)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.forum_outlined),
|
||||
title: Text(
|
||||
widget.runtime.sessions.loading
|
||||
? 'Loading chats…'
|
||||
: _query.isEmpty
|
||||
? 'No existing chats'
|
||||
: 'No chats match this search',
|
||||
),
|
||||
),
|
||||
for (final row in sessions)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.chat_bubble_outline),
|
||||
title: Text(chatSessionTitle(row)),
|
||||
subtitle: Text(
|
||||
'${'${row['directory'] ?? ''}'.trim().isEmpty ? 'No folder' : row['directory']}'
|
||||
' · ${chatBackendLabel('${row['backend'] ?? row['harness'] ?? ''}')}',
|
||||
),
|
||||
onTap: () => Navigator.of(
|
||||
context,
|
||||
).pop(_ChatChoice.existing('${row['id']}')),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
import 'artifact_record.dart';
|
||||
import 'artifact_url.dart';
|
||||
import 'artifact_groups.dart';
|
||||
|
||||
/// Run provenance supplied by the owner of an artifact gallery.
|
||||
class ArtifactChatContext {
|
||||
const ArtifactChatContext({
|
||||
required this.runId,
|
||||
required this.runTitle,
|
||||
required this.pipelineName,
|
||||
this.pipelineVersion,
|
||||
this.stageKey,
|
||||
this.visit,
|
||||
this.configuredEndpoint = '',
|
||||
this.recordedSteps = const <String, dynamic>{},
|
||||
});
|
||||
|
||||
final String runId;
|
||||
final String runTitle;
|
||||
final String pipelineName;
|
||||
final String? pipelineVersion;
|
||||
final String? stageKey;
|
||||
final int? visit;
|
||||
final String configuredEndpoint;
|
||||
final JsonMap recordedSteps;
|
||||
}
|
||||
|
||||
String artifactChatReference(
|
||||
ArtifactChatContext context,
|
||||
ArtifactGroup group,
|
||||
ArtifactRecord artifact,
|
||||
) {
|
||||
final resolved = artifact.hasUrl
|
||||
? resolveArtifactUrl(context.configuredEndpoint, artifact.url)
|
||||
: null;
|
||||
final readable = resolved == null
|
||||
? 'The server did not provide a safe readable URL for this artifact; '
|
||||
'inspect the run to locate it.'
|
||||
: 'The chat agent can read it at ${resolved.url}';
|
||||
final version = context.pipelineVersion == null
|
||||
? ''
|
||||
: ' v${context.pipelineVersion}';
|
||||
return 'Artifact "${artifact.name}" from run ${context.runId} '
|
||||
'("${context.runTitle}"), pipeline "${context.pipelineName}"$version, '
|
||||
'stage "${context.stageKey ?? group.stageKey}", visit '
|
||||
'${context.visit ?? group.visit}. $readable. '
|
||||
'Use `pipelines inspect ${context.runId}` for the authoritative run '
|
||||
'and artifact metadata.';
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../core/transport/pipelines_client.dart';
|
||||
import '../domain/artifact_chat_context.dart';
|
||||
import 'artifact_external_open.dart';
|
||||
import 'artifact_gallery_page.dart';
|
||||
|
||||
@@ -42,10 +43,12 @@ class RunArtifactsButton extends StatelessWidget {
|
||||
super.key,
|
||||
required this.run,
|
||||
required this.gateway,
|
||||
this.onSendToChat,
|
||||
});
|
||||
|
||||
final JsonMap run;
|
||||
final ApiGateway gateway;
|
||||
final void Function(String draft)? onSendToChat;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -55,6 +58,16 @@ class RunArtifactsButton extends StatelessWidget {
|
||||
steps: steps,
|
||||
executing: _runExecuting(run),
|
||||
configuredEndpoint: configuredGatewayEndpoint(gateway),
|
||||
artifactChatContext: ArtifactChatContext(
|
||||
runId: '${run['id'] ?? ''}',
|
||||
runTitle: '${run['title'] ?? run['name'] ?? ''}',
|
||||
pipelineName: '${run['name'] ?? ''}',
|
||||
pipelineVersion: run['version'] is num
|
||||
? (run['version'] as num).toInt().toString()
|
||||
: null,
|
||||
configuredEndpoint: configuredGatewayEndpoint(gateway),
|
||||
),
|
||||
onSendToChat: onSendToChat,
|
||||
);
|
||||
return OutlinedButton.icon(
|
||||
key: runArtifactsButtonKey,
|
||||
@@ -74,6 +87,8 @@ Future<void> showArtifactGallery(
|
||||
bool executing = false,
|
||||
String configuredEndpoint = '',
|
||||
ArtifactExternalOpen openExternal = openArtifactExternally,
|
||||
ArtifactChatContext? artifactChatContext,
|
||||
void Function(String draft)? onSendToChat,
|
||||
}) {
|
||||
final page = ArtifactGalleryPage(
|
||||
steps: List<JsonMap>.unmodifiable(steps),
|
||||
@@ -81,6 +96,8 @@ Future<void> showArtifactGallery(
|
||||
executing: executing,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
openExternal: openExternal,
|
||||
artifactChatContext: artifactChatContext,
|
||||
onSendToChat: onSendToChat,
|
||||
);
|
||||
return Navigator.of(
|
||||
context,
|
||||
|
||||
@@ -15,6 +15,7 @@ import '../domain/artifact_record.dart';
|
||||
import '../domain/artifact_selection.dart';
|
||||
import '../domain/artifact_summary.dart';
|
||||
import '../domain/artifact_url.dart';
|
||||
import '../domain/artifact_chat_context.dart';
|
||||
import 'artifact_external_open.dart';
|
||||
import 'artifact_selection_facts.dart';
|
||||
import 'artifact_viewer_content.dart';
|
||||
@@ -56,6 +57,8 @@ class ArtifactGalleryPage extends StatefulWidget {
|
||||
this.initiallyCollapsed = false,
|
||||
this.openArtifactUrl,
|
||||
this.onOpenArtifactHandled,
|
||||
this.artifactChatContext,
|
||||
this.onSendToChat,
|
||||
});
|
||||
|
||||
final List<JsonMap> steps;
|
||||
@@ -83,6 +86,8 @@ class ArtifactGalleryPage extends StatefulWidget {
|
||||
/// [onOpenArtifactHandled] with whether its groups record that URL.
|
||||
final String? openArtifactUrl;
|
||||
final ValueChanged<bool>? onOpenArtifactHandled;
|
||||
final ArtifactChatContext? artifactChatContext;
|
||||
final void Function(String draft)? onSendToChat;
|
||||
|
||||
@override
|
||||
State<ArtifactGalleryPage> createState() => _ArtifactGalleryPageState();
|
||||
@@ -296,6 +301,16 @@ class _ArtifactGalleryPageState extends State<ArtifactGalleryPage> {
|
||||
fetch: widget.fetch,
|
||||
markdownBuilder: widget.markdownBuilder,
|
||||
fileBridge: widget.fileBridge,
|
||||
onSendToChat:
|
||||
widget.artifactChatContext == null || widget.onSendToChat == null
|
||||
? null
|
||||
: (page) => widget.onSendToChat!(
|
||||
artifactChatReference(
|
||||
widget.artifactChatContext!,
|
||||
page.group,
|
||||
page.artifact,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -356,6 +371,21 @@ class _ArtifactGalleryPageState extends State<ArtifactGalleryPage> {
|
||||
onPressed: () => _open(resolved, dialogContext),
|
||||
child: const Text('Open in browser'),
|
||||
),
|
||||
if (widget.artifactChatContext != null && widget.onSendToChat != null)
|
||||
TextButton(
|
||||
key: const Key('artifact-send-to-chat'),
|
||||
onPressed: () {
|
||||
Navigator.of(dialogContext).pop();
|
||||
widget.onSendToChat!(
|
||||
artifactChatReference(
|
||||
widget.artifactChatContext!,
|
||||
group,
|
||||
artifact,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Send to chat…'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -35,6 +35,7 @@ class ArtifactViewerBar extends StatelessWidget {
|
||||
required this.onNext,
|
||||
this.fullscreen = false,
|
||||
this.onFullscreen,
|
||||
this.onSendToChat,
|
||||
});
|
||||
|
||||
final PagedArtifact page;
|
||||
@@ -55,6 +56,7 @@ class ArtifactViewerBar extends StatelessWidget {
|
||||
/// Enters (inline) or leaves (in full screen) the full-screen view; absent,
|
||||
/// the control is not drawn.
|
||||
final VoidCallback? onFullscreen;
|
||||
final VoidCallback? onSendToChat;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -145,5 +147,12 @@ class ArtifactViewerBar extends StatelessWidget {
|
||||
icon: fullscreen ? Icons.fullscreen_exit : Icons.fullscreen,
|
||||
onPressed: toggle,
|
||||
),
|
||||
if (onSendToChat != null)
|
||||
ArtifactIconAction(
|
||||
key: const Key('artifact-send-to-chat'),
|
||||
label: 'Send to chat…',
|
||||
icon: Icons.chat_outlined,
|
||||
onPressed: onSendToChat!,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ class ArtifactViewerBody extends StatelessWidget {
|
||||
this.onFullscreen,
|
||||
this.onImageZoomChanged,
|
||||
this.imageZoomed = false,
|
||||
this.onSendToChat,
|
||||
});
|
||||
|
||||
/// The inert HTML renderer; tests inject a plain stand-in.
|
||||
@@ -64,6 +65,7 @@ class ArtifactViewerBody extends StatelessWidget {
|
||||
|
||||
final ValueChanged<bool>? onImageZoomChanged;
|
||||
final bool imageZoomed;
|
||||
final VoidCallback? onSendToChat;
|
||||
|
||||
/// Loads the current page's preview again after a failure.
|
||||
final VoidCallback? onRetry;
|
||||
@@ -156,6 +158,7 @@ class ArtifactViewerBody extends StatelessWidget {
|
||||
onNext: onNext,
|
||||
fullscreen: fullscreen,
|
||||
onFullscreen: onFullscreen,
|
||||
onSendToChat: onSendToChat,
|
||||
),
|
||||
child: swipe,
|
||||
);
|
||||
|
||||
@@ -51,6 +51,7 @@ class ArtifactViewerPage extends StatefulWidget {
|
||||
this.openExternal = openArtifactExternally,
|
||||
this.fileBridge = const ArtifactFileBridge(),
|
||||
this.htmlBuilder = defaultArtifactHtml,
|
||||
this.onSendToChat,
|
||||
});
|
||||
|
||||
final List<ArtifactGroup> groups;
|
||||
@@ -79,6 +80,7 @@ class ArtifactViewerPage extends StatefulWidget {
|
||||
|
||||
/// The inert HTML renderer; tests inject a plain stand-in.
|
||||
final ArtifactHtmlBuilder htmlBuilder;
|
||||
final ValueChanged<PagedArtifact>? onSendToChat;
|
||||
|
||||
@override
|
||||
State<ArtifactViewerPage> createState() => _ArtifactViewerPageState();
|
||||
@@ -305,6 +307,9 @@ class _ArtifactViewerPageState extends State<ArtifactViewerPage>
|
||||
onFullscreen: fullscreen
|
||||
? () => Navigator.of(context).maybePop()
|
||||
: enterFullscreen,
|
||||
onSendToChat: widget.onSendToChat == null
|
||||
? null
|
||||
: () => widget.onSendToChat!(page),
|
||||
);
|
||||
// Left/right arrows walk the same list as the Previous/Next buttons,
|
||||
// wherever focus is on the page, its top bar's controls included.
|
||||
|
||||
@@ -119,6 +119,10 @@ Widget buildChatPaneContent({
|
||||
paneControls: placement.paneControls?.call(context) ?? const [],
|
||||
paneCommands: placement.paneCommands,
|
||||
onComposerFocus: placement.onComposerFocus,
|
||||
onComposerReady: (composer) =>
|
||||
runtime.registerComposer(sessionId, composer),
|
||||
onComposerDisposed: (composer) =>
|
||||
runtime.unregisterComposer(sessionId, composer),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'conversation/chat_models.dart';
|
||||
import 'conversation/chat_row_widgets.dart';
|
||||
import 'conversation/chat_scroll.dart';
|
||||
import 'conversation/chat_transcript_cache.dart';
|
||||
import 'conversation/chat_composer_controller.dart';
|
||||
import 'conversation/composer_focus_request.dart';
|
||||
import 'data/chat_repository.dart';
|
||||
import 'ui/sessions/chat_sessions_body.dart';
|
||||
@@ -127,6 +128,32 @@ class ChatRuntime extends ChangeNotifier {
|
||||
/// Puts the keyboard in an opened chat's composer once it is built.
|
||||
final ChatComposerFocusRequests composerFocus = ChatComposerFocusRequests();
|
||||
|
||||
/// Mounted composers are registered so external actions can append without
|
||||
/// sending. A selection made before a pane mounts is queued here.
|
||||
final Map<String, ChatComposerController> composers = {};
|
||||
final Map<String, List<String>> _pendingAppends = {};
|
||||
|
||||
void registerComposer(String id, ChatComposerController composer) {
|
||||
composers[id] = composer;
|
||||
final pending = _pendingAppends.remove(id);
|
||||
if (pending != null) {
|
||||
for (final text in pending) {
|
||||
unawaited(composer.appendDraft(text));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void unregisterComposer(String id, ChatComposerController composer) {
|
||||
if (identical(composers[id], composer)) composers.remove(id);
|
||||
}
|
||||
|
||||
Future<void> appendDraft(String id, String text) {
|
||||
final composer = composers[id];
|
||||
if (composer != null) return composer.appendDraft(text);
|
||||
(_pendingAppends[id] ??= <String>[]).add(text);
|
||||
return Future<void>.value();
|
||||
}
|
||||
|
||||
/// The line a just-created conversation opens on, tied to the selection
|
||||
/// `/new` made. Leaving that conversation drops it, so a later reopen is
|
||||
/// an ordinary visit.
|
||||
@@ -251,6 +278,8 @@ class ChatRuntime extends ChangeNotifier {
|
||||
sessions.dispose();
|
||||
folds.dispose();
|
||||
composerFocus.dispose();
|
||||
composers.clear();
|
||||
_pendingAppends.clear();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +139,16 @@ class ChatComposerController extends ChangeNotifier {
|
||||
return _persistDraft(text);
|
||||
}
|
||||
|
||||
/// Appends external, unsent context to the current draft. This deliberately
|
||||
/// does not use [send], so selecting "Send to chat" can never create a
|
||||
/// prompt request.
|
||||
Future<void> appendDraft(String text) {
|
||||
if (_disposed || text.isEmpty) return Future<void>.value();
|
||||
final current = _draft.trimRight();
|
||||
final next = current.isEmpty ? text : '$current\n$text';
|
||||
return setDraft(next);
|
||||
}
|
||||
|
||||
/// Sends the non-blank draft as one plain message, carrying [attachments] in
|
||||
/// draft order. Only the wire text is trimmed. The intent is stored on the
|
||||
/// device until the server accepts it. A refusal restores the exact draft
|
||||
|
||||
@@ -129,6 +129,8 @@ class ChatThreadView extends StatefulWidget {
|
||||
this.useNativeBack = false,
|
||||
this.pasteTarget = true,
|
||||
this.ownsPasteWhenFocused = false,
|
||||
this.onComposerReady,
|
||||
this.onComposerDisposed,
|
||||
});
|
||||
|
||||
final ApiGateway gateway;
|
||||
@@ -147,6 +149,8 @@ class ChatThreadView extends StatefulWidget {
|
||||
|
||||
/// See [ChatComposerBar.ownsPasteWhenFocused].
|
||||
final bool ownsPasteWhenFocused;
|
||||
final void Function(ChatComposerController composer)? onComposerReady;
|
||||
final void Function(ChatComposerController composer)? onComposerDisposed;
|
||||
|
||||
/// Sets the chat's shared colour (a palette name, null for none) from the
|
||||
/// information sheet; null leaves the sheet without the Colour choice.
|
||||
@@ -532,6 +536,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
onAccepted: (send, queued) =>
|
||||
_controller.promptAccepted(send.operationId, queued: queued),
|
||||
);
|
||||
widget.onComposerReady?.call(composer);
|
||||
if (widget.initialDraft != null) {
|
||||
unawaited(composer.setDraft(widget.initialDraft!));
|
||||
}
|
||||
@@ -685,6 +690,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
_images = ChatAttachmentImages(widget.gateway);
|
||||
}
|
||||
_controller.dispose();
|
||||
oldWidget.onComposerDisposed?.call(_composer);
|
||||
_composer.dispose();
|
||||
_shellRuns.dispose();
|
||||
_shellRuns = _attachShellRuns();
|
||||
@@ -773,6 +779,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
widget.paneCommands?.removeListener(_takeCommands);
|
||||
widget.paneCommands?.setFinished(widget.sessionId, false);
|
||||
_scroll.dispose();
|
||||
widget.onComposerDisposed?.call(_composer);
|
||||
_composer.dispose();
|
||||
_controller.dispose();
|
||||
_shellRuns.dispose();
|
||||
|
||||
@@ -37,7 +37,7 @@ Widget pipelineActionsMenu(
|
||||
),
|
||||
if (onOpenInChat != null)
|
||||
SegmentedMenuChoice(
|
||||
label: 'Open in chat',
|
||||
label: 'Send to chat…',
|
||||
onSelected: () => onOpenInChat(context, detail, null),
|
||||
),
|
||||
],
|
||||
@@ -55,7 +55,7 @@ Widget pipelineActionsMenu(
|
||||
if (onOpenInChat != null)
|
||||
const AppMenuAction<bool>(
|
||||
value: false,
|
||||
label: 'Open in chat',
|
||||
label: 'Send to chat…',
|
||||
icon: Icons.chat_bubble_outline,
|
||||
),
|
||||
],
|
||||
|
||||
@@ -280,7 +280,7 @@ class PipelineListPanel extends StatelessWidget {
|
||||
actions: const [
|
||||
AppMenuAction<bool>(
|
||||
value: true,
|
||||
label: 'Open in chat',
|
||||
label: 'Send to chat…',
|
||||
icon: Icons.chat_bubble_outline,
|
||||
),
|
||||
],
|
||||
|
||||
@@ -54,6 +54,7 @@ class RunsScreen extends StatefulWidget {
|
||||
this.sortStore = const SharedPreferencesRunsSortStore(),
|
||||
this.pendingRunStore = const SharedPreferencesPendingRunStore(''),
|
||||
this.onOpenInChat,
|
||||
this.onSendToChat,
|
||||
});
|
||||
|
||||
final ApiGateway gateway;
|
||||
@@ -105,6 +106,7 @@ class RunsScreen extends StatefulWidget {
|
||||
/// scope the Pipelines tab uses. Tests inject a memory store.
|
||||
final PendingRunStore pendingRunStore;
|
||||
final Future<void> Function(BuildContext, JsonMap)? onOpenInChat;
|
||||
final Future<void> Function(BuildContext, JsonMap, String)? onSendToChat;
|
||||
|
||||
@override
|
||||
State<RunsScreen> createState() => _RunsScreenState();
|
||||
@@ -303,6 +305,9 @@ class _RunsScreenState extends State<RunsScreen> {
|
||||
onRunOpened: _select,
|
||||
onOpenPipeline: widget.onOpenPipeline,
|
||||
onOpenInChat: widget.onOpenInChat,
|
||||
onSendToChat: widget.onSendToChat == null
|
||||
? null
|
||||
: (context, run, draft) => widget.onSendToChat!(context, run, draft),
|
||||
initialStageKey: widget.initialStageKey,
|
||||
initialVisit: widget.initialVisit,
|
||||
);
|
||||
|
||||
@@ -25,6 +25,7 @@ Widget buildMaterialRunDetail({
|
||||
required String configuredEndpoint,
|
||||
String? initialStageKey,
|
||||
int? initialVisit,
|
||||
void Function(String draft)? onSendToChat,
|
||||
}) {
|
||||
return RunDetailTabs(
|
||||
run: run,
|
||||
@@ -36,6 +37,7 @@ Widget buildMaterialRunDetail({
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
initialStageKey: initialStageKey,
|
||||
initialVisit: initialVisit,
|
||||
onSendToChat: onSendToChat,
|
||||
// A glass strip under the top bar: as wide as its content.
|
||||
header: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@@ -12,6 +12,7 @@ import '../../../core/api_gateway.dart';
|
||||
import '../../graph/widgets/run_graph_view.dart';
|
||||
import '../../artifacts/ui/artifact_gallery_action.dart';
|
||||
import '../../artifacts/ui/artifact_gallery_page.dart';
|
||||
import '../../artifacts/domain/artifact_chat_context.dart';
|
||||
import '../../changes/changes.dart';
|
||||
import 'run_changes_action.dart';
|
||||
import 'run_detail_content.dart';
|
||||
@@ -54,6 +55,7 @@ class RunDetailTabs extends StatefulWidget {
|
||||
required this.configuredEndpoint,
|
||||
this.initialStageKey,
|
||||
this.initialVisit,
|
||||
this.onSendToChat,
|
||||
});
|
||||
|
||||
final JsonMap run;
|
||||
@@ -83,6 +85,7 @@ class RunDetailTabs extends StatefulWidget {
|
||||
/// The zero-based index among [initialStageKey]'s recorded visits. Null opens
|
||||
/// the stage's latest visit, exactly as a Graph node click does.
|
||||
final int? initialVisit;
|
||||
final void Function(String draft)? onSendToChat;
|
||||
|
||||
@override
|
||||
State<RunDetailTabs> createState() => _RunDetailTabsState();
|
||||
@@ -333,6 +336,7 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
gateway: widget.gateway,
|
||||
onRunChanged: widget.onRunChanged,
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
onSendToChat: widget.onSendToChat,
|
||||
onClose: () => Navigator.of(pageContext).pop(),
|
||||
)
|
||||
: const Center(child: Text('This visit is no longer recorded.'));
|
||||
@@ -493,6 +497,16 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
embedded: true,
|
||||
openArtifactUrl: _searchArtifactUrl,
|
||||
onOpenArtifactHandled: _searchArtifactHandled,
|
||||
artifactChatContext: ArtifactChatContext(
|
||||
runId: '${widget.run['id'] ?? ''}',
|
||||
runTitle: '${widget.run['title'] ?? widget.run['name'] ?? ''}',
|
||||
pipelineName: '${widget.run['name'] ?? ''}',
|
||||
pipelineVersion: widget.run['version'] is num
|
||||
? (widget.run['version'] as num).toInt().toString()
|
||||
: null,
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
),
|
||||
onSendToChat: widget.onSendToChat,
|
||||
);
|
||||
case RunDetailTab.changes:
|
||||
final viewer = ChangesViewer(
|
||||
|
||||
@@ -25,6 +25,7 @@ class RunDetailView extends StatefulWidget {
|
||||
this.initialStageKey,
|
||||
this.initialVisit,
|
||||
this.onOpenInChat,
|
||||
this.onSendToChat,
|
||||
});
|
||||
|
||||
final RunsController controller;
|
||||
@@ -46,6 +47,7 @@ class RunDetailView extends StatefulWidget {
|
||||
final String? initialStageKey;
|
||||
final int? initialVisit;
|
||||
final Future<void> Function(BuildContext, JsonMap)? onOpenInChat;
|
||||
final Future<void> Function(BuildContext, JsonMap, String)? onSendToChat;
|
||||
|
||||
@override
|
||||
State<RunDetailView> createState() => _RunDetailViewState();
|
||||
@@ -85,6 +87,9 @@ class _RunDetailViewState extends State<RunDetailView> {
|
||||
configuredEndpoint: endpoint,
|
||||
initialStageKey: widget.initialStageKey,
|
||||
initialVisit: widget.initialVisit,
|
||||
onSendToChat: widget.onSendToChat == null
|
||||
? null
|
||||
: (draft) => widget.onSendToChat!(context, run, draft),
|
||||
);
|
||||
// The top bar becomes the run's: Back to the list, its title over its
|
||||
// number, pipeline and version (a link to that pipeline when the host
|
||||
|
||||
@@ -22,6 +22,7 @@ class RunVisitPane extends StatefulWidget {
|
||||
required this.onRunChanged,
|
||||
required this.configuredEndpoint,
|
||||
required this.onClose,
|
||||
this.onSendToChat,
|
||||
});
|
||||
|
||||
final JsonMap run;
|
||||
@@ -41,6 +42,7 @@ class RunVisitPane extends StatefulWidget {
|
||||
|
||||
final String configuredEndpoint;
|
||||
final VoidCallback onClose;
|
||||
final void Function(String draft)? onSendToChat;
|
||||
|
||||
@override
|
||||
State<RunVisitPane> createState() => _RunVisitPaneState();
|
||||
@@ -86,6 +88,7 @@ class _RunVisitPaneState extends State<RunVisitPane> {
|
||||
gateway: widget.gateway,
|
||||
onRunChanged: widget.onRunChanged,
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
onSendToChat: widget.onSendToChat,
|
||||
facts: RunVisitFactsView(step: widget.step),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../artifacts/domain/artifact_chat_context.dart';
|
||||
import '../../artifacts/ui/artifact_gallery_page.dart';
|
||||
|
||||
/// The visit's recorded stage artifacts, in recorded order.
|
||||
@@ -20,6 +21,8 @@ class RunVisitArtifacts extends StatelessWidget {
|
||||
required this.visitIndex,
|
||||
required this.runSteps,
|
||||
required this.configuredEndpoint,
|
||||
required this.run,
|
||||
this.onSendToChat,
|
||||
});
|
||||
|
||||
final JsonMap step;
|
||||
@@ -29,6 +32,8 @@ class RunVisitArtifacts extends StatelessWidget {
|
||||
|
||||
final List<JsonMap> runSteps;
|
||||
final String configuredEndpoint;
|
||||
final JsonMap run;
|
||||
final void Function(String draft)? onSendToChat;
|
||||
|
||||
/// The same gallery as the run's Artifacts tab, focused on this visit.
|
||||
@override
|
||||
@@ -40,6 +45,19 @@ class RunVisitArtifacts extends StatelessWidget {
|
||||
focusIndex: runSteps.isEmpty ? 0 : visitIndex,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
embedded: true,
|
||||
artifactChatContext: ArtifactChatContext(
|
||||
runId: '${run['id'] ?? ''}',
|
||||
runTitle: '${run['title'] ?? run['name'] ?? ''}',
|
||||
pipelineName: '${run['name'] ?? ''}',
|
||||
pipelineVersion: run['version'] is num
|
||||
? (run['version'] as num).toInt().toString()
|
||||
: null,
|
||||
stageKey: '${step['stage'] ?? ''}',
|
||||
visit: visitIndex + 1,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
recordedSteps: step,
|
||||
),
|
||||
onSendToChat: onSendToChat,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../artifacts/domain/artifact_capture.dart';
|
||||
import '../../artifacts/domain/artifact_chat_context.dart';
|
||||
import '../../artifacts/domain/artifact_document.dart';
|
||||
import '../../artifacts/domain/artifact_groups.dart';
|
||||
import '../../artifacts/domain/artifact_record.dart';
|
||||
@@ -20,11 +21,13 @@ class RunVisitDocuments extends StatelessWidget {
|
||||
required this.step,
|
||||
required this.run,
|
||||
required this.configuredEndpoint,
|
||||
this.onSendToChat,
|
||||
});
|
||||
|
||||
final JsonMap step;
|
||||
final JsonMap run;
|
||||
final String configuredEndpoint;
|
||||
final void Function(String draft)? onSendToChat;
|
||||
|
||||
int _visitNumber() {
|
||||
final steps = run['steps'];
|
||||
@@ -80,6 +83,25 @@ class RunVisitDocuments extends StatelessWidget {
|
||||
groups: [group],
|
||||
selectedIdentity: artifactVisitIdentityOf(group, artifact),
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
onSendToChat: onSendToChat == null
|
||||
? null
|
||||
: (page) => onSendToChat!(
|
||||
artifactChatReference(
|
||||
ArtifactChatContext(
|
||||
runId: '${run['id'] ?? ''}',
|
||||
runTitle: '${run['title'] ?? run['name'] ?? ''}',
|
||||
pipelineName: '${run['name'] ?? ''}',
|
||||
pipelineVersion: run['version'] is num
|
||||
? (run['version'] as num).toInt().toString()
|
||||
: null,
|
||||
stageKey: '${step['stage'] ?? group.stageKey}',
|
||||
visit: _visitNumber(),
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
),
|
||||
page.group,
|
||||
page.artifact,
|
||||
),
|
||||
),
|
||||
);
|
||||
Navigator.of(
|
||||
context,
|
||||
|
||||
@@ -96,6 +96,7 @@ Widget runVisitSectionBody({
|
||||
required ApiGateway gateway,
|
||||
required ValueChanged<JsonMap> onRunChanged,
|
||||
required String configuredEndpoint,
|
||||
void Function(String draft)? onSendToChat,
|
||||
Widget? facts,
|
||||
}) {
|
||||
Widget body(RunVisitSection section) => runVisitSectionBody(
|
||||
@@ -108,6 +109,7 @@ Widget runVisitSectionBody({
|
||||
gateway: gateway,
|
||||
onRunChanged: onRunChanged,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
onSendToChat: onSendToChat,
|
||||
);
|
||||
switch (section) {
|
||||
case RunVisitSection.summary:
|
||||
@@ -139,6 +141,8 @@ Widget runVisitSectionBody({
|
||||
visitIndex: visitIndex,
|
||||
runSteps: runSteps,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
run: run,
|
||||
onSendToChat: onSendToChat,
|
||||
);
|
||||
case RunVisitSection.changes:
|
||||
// Only this visit's own capture; the run's final state is the run's
|
||||
@@ -157,6 +161,7 @@ Widget runVisitSectionBody({
|
||||
gateway: gateway,
|
||||
onRunChanged: onRunChanged,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
onSendToChat: onSendToChat,
|
||||
);
|
||||
case RunVisitSection.definition:
|
||||
return RunVisitDefinition(run: run, stageKey: stageKey);
|
||||
|
||||
@@ -33,6 +33,7 @@ class RunVisitSession extends StatefulWidget {
|
||||
required this.gateway,
|
||||
required this.onRunChanged,
|
||||
required this.configuredEndpoint,
|
||||
this.onSendToChat,
|
||||
this.openExternal = openArtifactExternally,
|
||||
});
|
||||
|
||||
@@ -42,6 +43,7 @@ class RunVisitSession extends StatefulWidget {
|
||||
final ValueChanged<JsonMap> onRunChanged;
|
||||
final String configuredEndpoint;
|
||||
final ArtifactExternalOpen openExternal;
|
||||
final void Function(String draft)? onSendToChat;
|
||||
|
||||
@override
|
||||
State<RunVisitSession> createState() => _RunVisitSessionState();
|
||||
@@ -108,6 +110,7 @@ class _RunVisitSessionState extends State<RunVisitSession> {
|
||||
step: widget.step,
|
||||
run: widget.run,
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
onSendToChat: widget.onSendToChat,
|
||||
),
|
||||
];
|
||||
// Flat on the page on both hosts; the turn documents below are a flat
|
||||
|
||||
@@ -16,8 +16,8 @@ import '../domain/run_models.dart' show runIdentity;
|
||||
const runMoreMenuKey = ValueKey<String>('run-more-menu');
|
||||
const deleteRunActionKey = ValueKey<String>('run-delete-action');
|
||||
const deleteRunActionLabel = 'Delete run';
|
||||
const openRunInChatActionKey = ValueKey<String>('run-open-in-chat-action');
|
||||
const openRunInChatActionLabel = 'Open in chat';
|
||||
const openRunInChatActionKey = ValueKey<String>('run-send-to-chat-action');
|
||||
const openRunInChatActionLabel = 'Send to chat…';
|
||||
|
||||
/// Whether the run has anything for its more menu. [deletable] says the host
|
||||
/// can apply a deletion, so a finished run offers Delete run.
|
||||
|
||||
@@ -4,8 +4,13 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/application/open_in_chat.dart';
|
||||
import 'package:pipelines_app/application/send_to_chat.dart';
|
||||
import 'package:pipelines_app/application/open_in_chat_preferences.dart';
|
||||
import 'package:pipelines_app/features/chat/chat_runtime.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_chat_context.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_create_fields.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_models.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_repository.dart';
|
||||
@@ -58,6 +63,96 @@ void main() {
|
||||
runtime.dispose();
|
||||
});
|
||||
|
||||
testWidgets('Send to chat lists and searches existing chats', (tester) async {
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [
|
||||
{
|
||||
'id': 'older',
|
||||
'title': 'Old notes',
|
||||
'directory': '/archive',
|
||||
'backend': 'codex',
|
||||
'updated_at': '2026-10-01T00:00:00Z',
|
||||
},
|
||||
{
|
||||
'id': 'release',
|
||||
'title': 'Release review',
|
||||
'directory': '/work',
|
||||
'backend': 'claude',
|
||||
'updated_at': '2026-10-20T00:00:00Z',
|
||||
},
|
||||
],
|
||||
};
|
||||
final runtime = ChatRuntime(gateway: gateway);
|
||||
await tester.pumpWidget(const MaterialApp(home: Scaffold()));
|
||||
final picker = showSendToChatPicker(
|
||||
context: tester.element(find.byType(Scaffold)),
|
||||
runtime: runtime,
|
||||
selectChat: (_) {},
|
||||
directory: '/work',
|
||||
title: 'Artifact',
|
||||
draft: 'artifact',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('New chat'), findsOneWidget);
|
||||
expect(find.text('Release review'), findsOneWidget);
|
||||
expect(find.text('Old notes'), findsOneWidget);
|
||||
// A short list is only as tall as its rows, with no empty space below.
|
||||
final rows = tester
|
||||
.widgetList<ListTile>(find.byType(ListTile))
|
||||
.map((tile) => tester.getSize(find.byWidget(tile)).height)
|
||||
.fold<double>(0, (sum, height) => sum + height);
|
||||
expect(tester.getSize(find.byType(ListView)).height, closeTo(rows, 1));
|
||||
await tester.enterText(find.byType(TextField), 'release');
|
||||
await tester.pump();
|
||||
expect(find.text('Release review'), findsOneWidget);
|
||||
expect(find.text('Old notes'), findsNothing);
|
||||
await tester.tap(find.text('New chat'));
|
||||
await picker;
|
||||
runtime.dispose();
|
||||
});
|
||||
|
||||
testWidgets('Send to chat appends an existing draft and focuses it', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [
|
||||
{
|
||||
'id': 'existing',
|
||||
'title': 'Existing chat',
|
||||
'directory': '/work',
|
||||
'backend': 'opencode',
|
||||
'updated_at': '2026-10-20T00:00:00Z',
|
||||
},
|
||||
],
|
||||
};
|
||||
final runtime = ChatRuntime(gateway: gateway);
|
||||
final composer = ChatComposerController(gateway, 'existing');
|
||||
await composer.setDraft('Before');
|
||||
runtime.registerComposer('existing', composer);
|
||||
var selected = '';
|
||||
await tester.pumpWidget(const MaterialApp(home: Scaffold()));
|
||||
final picker = showSendToChatPicker(
|
||||
context: tester.element(find.byType(Scaffold)),
|
||||
runtime: runtime,
|
||||
selectChat: (id) => selected = id,
|
||||
directory: '/work',
|
||||
title: 'Artifact',
|
||||
draft: 'Artifact details',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Existing chat'));
|
||||
await picker;
|
||||
await tester.pump();
|
||||
expect(selected, 'existing');
|
||||
expect(composer.draft, 'Before\nArtifact details');
|
||||
expect(runtime.composerFocus.take('existing'), isTrue);
|
||||
expect(gateway.calls.where((call) => call.type == 'chat_send'), isEmpty);
|
||||
composer.dispose();
|
||||
runtime.dispose();
|
||||
});
|
||||
|
||||
testWidgets('a harness the server no longer offers falls back to the '
|
||||
'default, without the saved model', (tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
@@ -140,6 +235,45 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('artifact references identify provenance and inspection', () {
|
||||
final reference = artifactChatReference(
|
||||
const ArtifactChatContext(
|
||||
runId: '42',
|
||||
runTitle: 'Build',
|
||||
pipelineName: 'Release',
|
||||
stageKey: 'test',
|
||||
visit: 2,
|
||||
configuredEndpoint: 'ws://server.example/connect',
|
||||
),
|
||||
const ArtifactGroup(
|
||||
stageKey: 'test',
|
||||
visit: 2,
|
||||
artifacts: [
|
||||
ArtifactRecord(
|
||||
name: 'report.txt',
|
||||
contentType: 'text/plain',
|
||||
sizeBytes: 12,
|
||||
url: '/artifacts/42/2/report.txt',
|
||||
raw: {},
|
||||
),
|
||||
],
|
||||
),
|
||||
const ArtifactRecord(
|
||||
name: 'report.txt',
|
||||
contentType: 'text/plain',
|
||||
sizeBytes: 12,
|
||||
url: '/artifacts/42/2/report.txt',
|
||||
raw: {},
|
||||
),
|
||||
);
|
||||
expect(reference, contains('report.txt'));
|
||||
expect(reference, contains('pipelines inspect 42'));
|
||||
expect(
|
||||
reference,
|
||||
contains('http://server.example/artifacts/42/2/report.txt'),
|
||||
);
|
||||
});
|
||||
|
||||
test('open in chat keeps the more menu available', () {
|
||||
expect(showRunMoreMenu({'id': 42}, canOpenInChat: true), isTrue);
|
||||
});
|
||||
@@ -226,7 +360,7 @@ void main() {
|
||||
runtime.dispose();
|
||||
});
|
||||
|
||||
testWidgets('run list More selects Open in chat on desktop', (tester) async {
|
||||
testWidgets('run list More selects Send to chat on desktop', (tester) async {
|
||||
final run = <String, dynamic>{
|
||||
'id': 42,
|
||||
'title': 'Build',
|
||||
@@ -256,12 +390,12 @@ void main() {
|
||||
|
||||
await tester.tap(find.byKey(const Key('run-list-more-menu-42')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Open in chat'), findsOneWidget);
|
||||
await tester.tap(find.text('Open in chat'));
|
||||
expect(find.text('Send to chat…'), findsOneWidget);
|
||||
await tester.tap(find.text('Send to chat…'));
|
||||
expect(selected, same(run));
|
||||
});
|
||||
|
||||
testWidgets('run detail More selects Open in chat from the phone sheet', (
|
||||
testWidgets('run detail More selects Send to chat from the phone sheet', (
|
||||
tester,
|
||||
) async {
|
||||
final run = <String, dynamic>{'id': 42, 'title': 'Build'};
|
||||
@@ -291,12 +425,12 @@ void main() {
|
||||
|
||||
await tester.tap(find.byTooltip('More actions'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Open in chat'), findsOneWidget);
|
||||
await tester.tap(find.text('Open in chat'));
|
||||
expect(find.text('Send to chat…'), findsOneWidget);
|
||||
await tester.tap(find.text('Send to chat…'));
|
||||
expect(selected, same(run));
|
||||
});
|
||||
|
||||
testWidgets('pipeline list row More selects Open in chat with latest run', (
|
||||
testWidgets('pipeline list row More selects Send to chat with latest run', (
|
||||
tester,
|
||||
) async {
|
||||
final fixture = PipelineFixture();
|
||||
@@ -328,14 +462,14 @@ void main() {
|
||||
|
||||
await tester.tap(find.byKey(const Key('pipeline-row-more-menu-1')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Open in chat'), findsOneWidget);
|
||||
await tester.tap(find.text('Open in chat'));
|
||||
expect(find.text('Send to chat…'), findsOneWidget);
|
||||
await tester.tap(find.text('Send to chat…'));
|
||||
expect(selected?.id, 1);
|
||||
expect(selectedRun?.id, 42);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'pipeline detail actions select Open in chat from phone overflow',
|
||||
'pipeline detail actions select Send to chat from phone overflow',
|
||||
(tester) async {
|
||||
final fixture = PipelineFixture();
|
||||
final gateway = gatewayFor(fixture);
|
||||
@@ -365,8 +499,8 @@ void main() {
|
||||
|
||||
await tester.tap(find.byTooltip('Pipeline actions'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Open in chat'), findsOneWidget);
|
||||
await tester.tap(find.text('Open in chat'));
|
||||
expect(find.text('Send to chat…'), findsOneWidget);
|
||||
await tester.tap(find.text('Send to chat…'));
|
||||
expect(selected?.id, detail.id);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_chat_context.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_gallery_page.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_visit_list.dart';
|
||||
|
||||
@@ -116,6 +117,98 @@ void main() {
|
||||
expect(_inDialog('Artifacts · 1 recorded'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('artifact details offer Send to chat and pass its reference', (
|
||||
tester,
|
||||
) async {
|
||||
String? draft;
|
||||
final steps = [
|
||||
step(
|
||||
stage: 'build',
|
||||
sequence: 1,
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
_recorded(
|
||||
'build.log',
|
||||
url: '/artifacts/42/1/build.log',
|
||||
contentType: 'text/plain',
|
||||
),
|
||||
],
|
||||
),
|
||||
];
|
||||
tester.view.physicalSize = const Size(800, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ArtifactGalleryPage(
|
||||
steps: steps,
|
||||
configuredEndpoint: 'http://server.example/connect',
|
||||
artifactChatContext: const ArtifactChatContext(
|
||||
runId: '42',
|
||||
runTitle: 'Build',
|
||||
pipelineName: 'Release',
|
||||
stageKey: 'build',
|
||||
visit: 1,
|
||||
configuredEndpoint: 'http://server.example/connect',
|
||||
),
|
||||
onSendToChat: (value) => draft = value,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('build.log'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('artifact-send-to-chat')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(draft, contains('build.log'));
|
||||
expect(draft, contains('pipelines inspect 42'));
|
||||
});
|
||||
|
||||
testWidgets('artifact viewer offers Send to chat', (tester) async {
|
||||
String? draft;
|
||||
final steps = [
|
||||
step(
|
||||
stage: 'build',
|
||||
sequence: 1,
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
_recorded(
|
||||
'build.log',
|
||||
url: '/artifacts/42/1/build.log',
|
||||
contentType: 'text/plain',
|
||||
),
|
||||
],
|
||||
),
|
||||
];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ArtifactGalleryPage(
|
||||
steps: steps,
|
||||
configuredEndpoint: 'http://server.example/connect',
|
||||
artifactChatContext: const ArtifactChatContext(
|
||||
runId: '42',
|
||||
runTitle: 'Build',
|
||||
pipelineName: 'Release',
|
||||
stageKey: 'build',
|
||||
visit: 1,
|
||||
configuredEndpoint: 'http://server.example/connect',
|
||||
),
|
||||
onSendToChat: (value) => draft = value,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('build.log'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('artifact-send-to-chat')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(draft, contains('build.log'));
|
||||
});
|
||||
|
||||
testWidgets('capture notes and partial label come from the visit step', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -9,11 +9,13 @@ import 'package:pipelines_app/features/artifacts/ui/artifact_video_player.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/gallery_navigation.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_external_open.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_gallery_page.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_content.dart'
|
||||
show ArtifactPreviewBody, artifactPreviewRetryKey;
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_fetch.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_bar.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_visit_list.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
@@ -44,6 +46,7 @@ Future<void> _pumpViewer(
|
||||
ArtifactFetch? fetch,
|
||||
Widget Function(BuildContext, String)? markdownBuilder,
|
||||
ArtifactExternalOpen? openExternal,
|
||||
ValueChanged<PagedArtifact>? onSendToChat,
|
||||
double bottomClearance = 0,
|
||||
}) async {
|
||||
final page = ArtifactViewerPage(
|
||||
@@ -54,6 +57,7 @@ Future<void> _pumpViewer(
|
||||
markdownBuilder:
|
||||
markdownBuilder ?? (context, value) => SelectableText(value),
|
||||
openExternal: openExternal ?? (_) async => true,
|
||||
onSendToChat: onSendToChat,
|
||||
);
|
||||
final child = MediaQuery(
|
||||
data: MediaQueryData(padding: EdgeInsets.only(bottom: bottomClearance)),
|
||||
@@ -393,10 +397,12 @@ void main() {
|
||||
_group([second], visit: 2),
|
||||
_group([third], visit: 3),
|
||||
];
|
||||
String? sent;
|
||||
await _pumpViewer(
|
||||
tester,
|
||||
groups: groups,
|
||||
selected: artifactVisitIdentity(groups[0], first),
|
||||
onSendToChat: (page) => sent = page.artifact.name,
|
||||
);
|
||||
|
||||
expect(find.text('1 of 3 · image/png'), findsOneWidget);
|
||||
@@ -413,6 +419,8 @@ void main() {
|
||||
await tester.tap(find.byKey(artifactNextKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('2 of 3 · image/png'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('artifact-send-to-chat')));
|
||||
expect(sent, 'b.png');
|
||||
await showFacts(tester);
|
||||
expect(find.text('review · visit 2'), findsOneWidget);
|
||||
await hideFacts(tester);
|
||||
|
||||
@@ -176,6 +176,26 @@ bool _turnFiles = false;
|
||||
/// into the same "unsupported request" error as an incomplete server.
|
||||
final _probeChats = <String, JsonMap>{};
|
||||
int _probeChatSequence = 0;
|
||||
|
||||
void _installUiReviewChats() {
|
||||
_probeChats
|
||||
..['ui-review'] = {
|
||||
'id': 'ui-review',
|
||||
'title': 'UI review',
|
||||
'directory': '/Users/fixture/workspace',
|
||||
'backend': 'opencode',
|
||||
'updated_at': '2026-10-20T09:05:00Z',
|
||||
'closed_at': null,
|
||||
}
|
||||
..['release-chat'] = {
|
||||
'id': 'release-chat',
|
||||
'title': 'Release train',
|
||||
'directory': '/Users/fixture/workspace',
|
||||
'backend': 'opencode',
|
||||
'updated_at': '2026-10-20T09:00:00Z',
|
||||
'closed_at': null,
|
||||
};
|
||||
}
|
||||
const List<String> _turnFileNames = [
|
||||
'input.md',
|
||||
'memory.md',
|
||||
@@ -852,6 +872,10 @@ class _FixtureSink implements WebSocketSink {
|
||||
/// fallback for `/runs/7`) can still open a deep location:
|
||||
///
|
||||
/// `?route=/runs/7/stage/build%3Fvisit%3D1` opens that app location;
|
||||
/// `?ui-review=1&route=/runs/7` exposes the run More menu's
|
||||
/// `Send to chat…` picker with existing chats at both desktop and phone
|
||||
/// capture sizes; opening the Artifacts tab and an artifact row exposes the
|
||||
/// equivalent artifact action;
|
||||
/// `?runs=200` / `?steps=60` append filler runs / run-7 steps for scroll
|
||||
/// performance captures;
|
||||
/// `?running=1` adds an executing run 8 whose duration ticks;
|
||||
@@ -878,6 +902,7 @@ Future<void> main() async {
|
||||
AnimationSpeedController.instance.restore(),
|
||||
]);
|
||||
final params = fixtureParams();
|
||||
if (params['ui-review'] == '1') _installUiReviewChats();
|
||||
if (params['liveRun'] == '1') _liveRunStatus = 'running';
|
||||
installHostProbes(params);
|
||||
// `?connect=1` (native only) opens the real launch flow with no saved
|
||||
|
||||
Reference in New Issue
Block a user