Open a run or pipeline in a new chat
The run and pipeline More menus offer Open in chat: a new chat in the run's (or the pipeline's latest run's) workspace opens on the Chat tab with a draft naming the run or pipeline and how to inspect or change it.
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../core/api_gateway.dart';
|
||||
import '../features/chat/chat_runtime.dart';
|
||||
import '../features/chat/ui/sessions/chat_create_fields.dart';
|
||||
import '../features/settings/settings_store.dart';
|
||||
|
||||
typedef OpenInChat = Future<void> Function(BuildContext context);
|
||||
|
||||
String runChatReference(JsonMap run) {
|
||||
final id = run['id'];
|
||||
// A run summary names its pipeline in `name`; `title` is the run's own
|
||||
// title, empty for an untitled run.
|
||||
final title = '${run['title'] ?? ''}'.trim();
|
||||
final pipeline =
|
||||
'${run['pipeline_name'] ?? run['pipeline'] ?? run['name'] ?? ''}'.trim();
|
||||
final version = '${run['pipeline_version'] ?? run['version'] ?? ''}'.trim();
|
||||
final status = '${run['status'] ?? ''}'.trim();
|
||||
return 'About Pipelines run #$id "${title.isEmpty ? 'Run $id' : title}" '
|
||||
'(pipeline "${pipeline.isEmpty ? 'unknown' : pipeline}" '
|
||||
'v${version.isEmpty ? '?' : version}, status $status). '
|
||||
'Inspect it with `pipelines inspect $id`.';
|
||||
}
|
||||
|
||||
String pipelineChatReference(int id, String name, int version) =>
|
||||
'About pipeline "$name" (id $id, version $version). '
|
||||
'Show it with `pipelines show "$name"`; to change it, draft with '
|
||||
'`pipelines edit` and publish with `pipelines submit`.';
|
||||
|
||||
/// Creates and opens a chat without showing the general-purpose create dialog.
|
||||
/// The caller supplies the already-resolved directory so run and pipeline
|
||||
/// screens can apply their own workspace provenance rules.
|
||||
Future<void> openReferenceInChat({
|
||||
required BuildContext context,
|
||||
required ChatRuntime runtime,
|
||||
required ValueChanged<String> selectChat,
|
||||
required String directory,
|
||||
required String title,
|
||||
required String draft,
|
||||
}) async {
|
||||
try {
|
||||
// Match the New chat dialog: prefer OpenCode when it is available, but
|
||||
// use the first server-advertised harness on installations where it is
|
||||
// not. Do not invent a backend when the catalog cannot be read.
|
||||
final backends = await runtime.sessions.repository.backends();
|
||||
final backend = backends.contains('opencode') ? 'opencode' : backends.first;
|
||||
final session = await runtime.sessions.createOrThrow(
|
||||
title: title,
|
||||
directory: directory.trim().isEmpty ? chatHomeDirectory : directory,
|
||||
backend: backend,
|
||||
instructions: '',
|
||||
operationId: 'open-in-chat-${DateTime.now().microsecondsSinceEpoch}',
|
||||
);
|
||||
final id = '${session['id'] ?? ''}';
|
||||
if (id.isEmpty) throw StateError('The new chat has no id.');
|
||||
runtime.opened[id] = session;
|
||||
runtime.pendingDrafts[id] = draft;
|
||||
selectChat(id);
|
||||
runtime.composerFocus.request(id);
|
||||
} catch (error) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('Could not open in chat: $error')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> settingsWorkspace(String serverId) async {
|
||||
final values = await SharedPreferencesSettingsStore(
|
||||
serverId: serverId,
|
||||
).load();
|
||||
return values.workspace.trim();
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import '../features/runs/domain/run_tab_counts.dart';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../core/api_gateway.dart';
|
||||
import '../core/servers/server_scope.dart';
|
||||
@@ -48,6 +48,8 @@ import '../shell/windows/window_store.dart';
|
||||
import 'app_terminals.dart';
|
||||
import '../features/chat/chat_runtime.dart';
|
||||
import '../features/chat/windows/chat_windows.dart';
|
||||
import 'open_in_chat.dart';
|
||||
import '../features/pipelines/pipeline_models.dart';
|
||||
import '../features/chat/workspace/chat_float_store.dart';
|
||||
import '../features/terminal/terminal_layout.dart';
|
||||
import 'app_route.dart';
|
||||
@@ -144,6 +146,63 @@ class PipelinesApp extends StatefulWidget {
|
||||
|
||||
class _PipelinesAppState extends State<PipelinesApp>
|
||||
with WidgetsBindingObserver {
|
||||
Future<void> _openRunInChat(BuildContext context, JsonMap run) async {
|
||||
try {
|
||||
final directory = '${run['workspace'] ?? run['directory'] ?? ''}'.trim();
|
||||
final fallback = directory.isEmpty
|
||||
? await settingsWorkspace(serverIdentity(_session.gateway) ?? '')
|
||||
: directory;
|
||||
if (!context.mounted) return;
|
||||
await openReferenceInChat(
|
||||
context: context,
|
||||
runtime: _chatRuntime,
|
||||
selectChat: (id) => _delegate.goTo(AppRoute.chatSession(id)),
|
||||
directory: fallback,
|
||||
title:
|
||||
'Run #${run['id']}: ${'${run['title'] ?? run['name'] ?? ''}'.trim()}',
|
||||
draft: runChatReference(run),
|
||||
);
|
||||
} catch (error) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Could not open in chat: $error')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openPipelineInChat(
|
||||
BuildContext context,
|
||||
PipelineSummary pipeline,
|
||||
PipelineRun? latestRun,
|
||||
) async {
|
||||
try {
|
||||
final directory = latestRun?.workspace.trim() ?? '';
|
||||
final fallback = directory.isEmpty
|
||||
? await settingsWorkspace(serverIdentity(_session.gateway) ?? '')
|
||||
: directory;
|
||||
if (!context.mounted) return;
|
||||
await openReferenceInChat(
|
||||
context: context,
|
||||
runtime: _chatRuntime,
|
||||
selectChat: (id) => _delegate.goTo(AppRoute.chatSession(id)),
|
||||
directory: fallback,
|
||||
title: 'Pipeline: ${pipeline.displayName}',
|
||||
draft: pipelineChatReference(
|
||||
pipeline.id,
|
||||
pipeline.displayName,
|
||||
pipeline.version,
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Could not open in chat: $error')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
late final AppSession _session;
|
||||
late final AppRouterDelegate _delegate;
|
||||
late final ElevationPrompt _elevationPrompt = elevationDialogPrompt(
|
||||
@@ -941,6 +1000,10 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
_delegate.goTo(AppRoute.runsForPipeline(id)),
|
||||
onOpenSchedules: _delegate.openSchedules,
|
||||
onOpenSettings: () => _delegate.goTo(AppRoute.settings),
|
||||
onOpenInChat: (context, detail, run) =>
|
||||
_openPipelineInChat(context, detail, run),
|
||||
onOpenPipelineInChat: (context, summary, run) =>
|
||||
_openPipelineInChat(context, summary, run),
|
||||
// The open pipeline is part of the route, so Back steps out of it.
|
||||
onSelectionChanged: (id) {
|
||||
final current = _delegate.route;
|
||||
@@ -983,6 +1046,7 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
),
|
||||
onOpenPipeline: (id, version) =>
|
||||
_delegate.goTo(AppRoute.pipeline(id, version: version)),
|
||||
onOpenInChat: _openRunInChat,
|
||||
),
|
||||
),
|
||||
AppDestination.chat: (_) => ChatDestination(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../features/pipelines/screen.dart';
|
||||
import '../features/pipelines/pipeline_models.dart';
|
||||
import '../ui/adaptive/top_bar_notices.dart';
|
||||
import 'app_session.dart';
|
||||
import 'connection_status.dart';
|
||||
@@ -29,6 +30,8 @@ class PipelinesDestination extends StatelessWidget {
|
||||
this.initialVersion = 0,
|
||||
this.initialStageKey,
|
||||
this.legacyPendingEndpoints = const [],
|
||||
this.onOpenInChat,
|
||||
this.onOpenPipelineInChat,
|
||||
});
|
||||
|
||||
final AppSession session;
|
||||
@@ -58,6 +61,10 @@ class PipelinesDestination extends StatelessWidget {
|
||||
/// The definition stage a deep link names, or null for no stage request.
|
||||
final String? initialStageKey;
|
||||
final List<String> legacyPendingEndpoints;
|
||||
final Future<void> Function(BuildContext, PipelineDetail, PipelineRun?)?
|
||||
onOpenInChat;
|
||||
final Future<void> Function(BuildContext, PipelineSummary, PipelineRun?)?
|
||||
onOpenPipelineInChat;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AnimatedBuilder(
|
||||
@@ -91,6 +98,8 @@ class PipelinesDestination extends StatelessWidget {
|
||||
onOpenSchedules: onOpenSchedules,
|
||||
onOpenSettings: onOpenSettings,
|
||||
onSelectionChanged: onSelectionChanged,
|
||||
onOpenInChat: onOpenInChat,
|
||||
onOpenPipelineInChat: onOpenPipelineInChat,
|
||||
initialPipelineId: initialPipelineId,
|
||||
initialVersion: initialVersion,
|
||||
initialStageKey: initialStageKey,
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'app_session.dart';
|
||||
import 'connection_status.dart';
|
||||
import 'pending_run_scope.dart';
|
||||
import 'server_endpoint.dart';
|
||||
import '../core/api_gateway.dart';
|
||||
|
||||
/// The Runs destination: the loaded screen plus an honest connection status.
|
||||
///
|
||||
@@ -34,6 +35,7 @@ class RunsDestination extends StatelessWidget {
|
||||
this.listRefreshToken = 0,
|
||||
this.notifications,
|
||||
this.attention,
|
||||
this.onOpenInChat,
|
||||
});
|
||||
|
||||
final AppSession session;
|
||||
@@ -65,6 +67,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;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AnimatedBuilder(
|
||||
@@ -109,5 +112,6 @@ class RunsDestination extends StatelessWidget {
|
||||
onBack: onBack,
|
||||
onPipelineFilterChanged: onPipelineFilterChanged,
|
||||
onOpenPipeline: onOpenPipeline,
|
||||
onOpenInChat: onOpenInChat,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user