Add labelled run entry points
Make starting runs discoverable from pipeline details and the Runs tab. Share the existing launch flow, add an active-pipeline picker, and update walkthrough guidance with focused widget coverage.
This commit is contained in:
@@ -1,21 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../core/transport/connection_state.dart';
|
||||
import '../../runs/data/runs_repository.dart';
|
||||
import '../../../ui/adaptive/segmented_bar_overflow.dart';
|
||||
import '../pipeline_models.dart';
|
||||
import '../pipelines_controller.dart';
|
||||
import '../run_pipeline_intent.dart';
|
||||
import '../widgets/pipeline_bar_buttons.dart';
|
||||
import 'run_pipeline_dialog.dart';
|
||||
import 'run_pipeline_flow.dart';
|
||||
import 'run_pipeline_wording.dart';
|
||||
|
||||
/// The pipeline detail's Run action.
|
||||
///
|
||||
/// Nothing is requested until the dialog's confirm. A confirmed attempt sends
|
||||
/// the web's exact `run_pipeline` body against the pinned resolved version; a
|
||||
/// lost reply keeps the intent so the next deliberate press checks by the same
|
||||
/// request key before resending. Only the id the server names is opened.
|
||||
const _runIcon = Icons.play_arrow_rounded;
|
||||
|
||||
/// The pipeline detail's Run action: a labelled button that opens the shared
|
||||
/// start flow ([openRunPipelineFlow]).
|
||||
class RunPipelineAction extends StatefulWidget {
|
||||
const RunPipelineAction({
|
||||
super.key,
|
||||
@@ -26,8 +21,8 @@ class RunPipelineAction extends StatefulWidget {
|
||||
this.inBar = false,
|
||||
});
|
||||
|
||||
/// The compact icon-and-word button of a top bar's actions pill instead
|
||||
/// of an inline button.
|
||||
/// The compact button of a top bar's actions pill instead of an inline
|
||||
/// button. A narrow bar moves it into its More menu, labelled.
|
||||
final bool inBar;
|
||||
|
||||
final PipelinesController controller;
|
||||
@@ -45,143 +40,38 @@ class RunPipelineAction extends StatefulWidget {
|
||||
class _RunPipelineActionState extends State<RunPipelineAction> {
|
||||
bool _dialogOpen = false;
|
||||
|
||||
int get _pipelineId => widget.detail.id;
|
||||
int get _version => widget.detail.resolvedVersion;
|
||||
|
||||
Future<void> _open() async {
|
||||
if (_dialogOpen) return;
|
||||
_dialogOpen = true;
|
||||
try {
|
||||
final pending = await widget.controller.loadPendingRun(
|
||||
_pipelineId,
|
||||
_version,
|
||||
);
|
||||
if (!mounted) return;
|
||||
await showRunPipelineDialog(
|
||||
await openRunPipelineFlow(
|
||||
context: context,
|
||||
controller: widget.controller,
|
||||
detail: widget.detail,
|
||||
gateway: widget.gateway,
|
||||
pending: pending,
|
||||
onSubmit: _submit,
|
||||
onPendingChanged: (intent) {
|
||||
if (intent == null) {
|
||||
widget.controller.clearPendingRun(_pipelineId, _version);
|
||||
} else {
|
||||
widget.controller.rememberPendingRun(intent);
|
||||
}
|
||||
},
|
||||
onAccepted: _accepted,
|
||||
onRunStarted: widget.onRunStarted,
|
||||
);
|
||||
} finally {
|
||||
_dialogOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
void _accepted(JsonMap run) {
|
||||
final id = runPipelineRunId(run);
|
||||
if (id == null) return;
|
||||
widget.controller.clearPendingRun(_pipelineId, _version);
|
||||
widget.onRunStarted?.call(id);
|
||||
}
|
||||
|
||||
Future<RunPipelineOutcome> _submit(RunPipelineIntent intent) async {
|
||||
final repository = RunsRepository(widget.gateway);
|
||||
final pending = widget.controller.pendingRunFor(
|
||||
intent.pipelineId,
|
||||
intent.version,
|
||||
);
|
||||
if (pending?.requestKey == intent.requestKey) {
|
||||
// A previous send may have been admitted even though its reply was lost.
|
||||
// Check before resending the same key; the server dedupes either way.
|
||||
try {
|
||||
final existing = await repository.runByRequestKey(intent.requestKey);
|
||||
if (existing != null) return _accept(existing);
|
||||
} catch (error) {
|
||||
widget.controller.rememberPendingRun(intent);
|
||||
return RunPipelineRefused(
|
||||
'${describeRunPipelineError(error)}$runPipelineUnknownSuffix',
|
||||
admissionUnknown: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
try {
|
||||
final run = await repository.startRun(
|
||||
pipelineId: intent.pipelineId,
|
||||
version: intent.version,
|
||||
prompt: intent.prompt,
|
||||
workspace: intent.workspace,
|
||||
requestKey: intent.requestKey,
|
||||
notifyMode: intent.notifyMode.wireValue,
|
||||
outputFormat: intent.outputFormat.wireValue,
|
||||
);
|
||||
final accepted = _accept(run);
|
||||
if (accepted is RunPipelineAccepted) return accepted;
|
||||
// A reply without a usable run id is not navigable: read the admitted run
|
||||
// by key rather than inventing an id or starting another run.
|
||||
return _refuse(repository, intent, 'The server returned no run id.');
|
||||
} on ProtocolError catch (error) {
|
||||
return _refuse(repository, intent, describeRunPipelineError(error));
|
||||
} on RunsRepositoryException catch (error) {
|
||||
return _refuse(repository, intent, describeRunPipelineError(error));
|
||||
} catch (error) {
|
||||
widget.controller.rememberPendingRun(intent);
|
||||
return RunPipelineRefused(
|
||||
'${describeRunPipelineError(error)}$runPipelineUnknownSuffix',
|
||||
admissionUnknown: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A reply is only accepted when it names a usable run id.
|
||||
RunPipelineOutcome _accept(JsonMap run) {
|
||||
if (runPipelineRunId(run) == null) {
|
||||
return const RunPipelineRefused(
|
||||
'The server returned no run id.',
|
||||
admissionUnknown: false,
|
||||
);
|
||||
}
|
||||
widget.controller.clearPendingRun(widget.detail.id, _version);
|
||||
return RunPipelineAccepted(run);
|
||||
}
|
||||
|
||||
/// A confirmed refusal: prove by key that no run was admitted before letting
|
||||
/// the operator correct the fields and try with a fresh key.
|
||||
Future<RunPipelineOutcome> _refuse(
|
||||
RunsRepository repository,
|
||||
RunPipelineIntent intent,
|
||||
String message,
|
||||
) async {
|
||||
try {
|
||||
final existing = await repository.runByRequestKey(intent.requestKey);
|
||||
if (existing != null) return _accept(existing);
|
||||
widget.controller.clearPendingRun(intent.pipelineId, intent.version);
|
||||
return RunPipelineRefused(message, admissionUnknown: false);
|
||||
} catch (_) {
|
||||
// Admission cannot be proven either way: keep the intent immutable.
|
||||
widget.controller.rememberPendingRun(intent);
|
||||
return RunPipelineRefused(
|
||||
'$message$runPipelineUnknownSuffix',
|
||||
admissionUnknown: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final label = const Text(runPipelineActionLabel);
|
||||
if (widget.inBar) {
|
||||
return pipelineBarIconButton(
|
||||
context,
|
||||
key: runPipelineActionKey,
|
||||
label: 'Run ${widget.detail.displayName}',
|
||||
icon: Icons.play_arrow_rounded,
|
||||
onPressed: _open,
|
||||
);
|
||||
}
|
||||
return FilledButton(
|
||||
final button = FilledButton.icon(
|
||||
key: runPipelineActionKey,
|
||||
onPressed: _open,
|
||||
child: label,
|
||||
icon: const Icon(_runIcon),
|
||||
label: const Text(runPipelineActionLabel),
|
||||
);
|
||||
if (!widget.inBar) return button;
|
||||
return SegmentedOverflowAction(
|
||||
overflowEntry: SegmentedOverflowEntry(
|
||||
label: runPipelineActionLabel,
|
||||
icon: _runIcon,
|
||||
onPressed: _open,
|
||||
),
|
||||
child: button,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../core/transport/connection_state.dart';
|
||||
import '../../runs/data/runs_repository.dart';
|
||||
import '../pipeline_models.dart';
|
||||
import '../pipelines_controller.dart';
|
||||
import '../run_pipeline_intent.dart';
|
||||
import 'run_pipeline_dialog.dart';
|
||||
import 'run_pipeline_wording.dart';
|
||||
|
||||
/// The one Run start flow, shared by a pipeline's Run action and the Runs
|
||||
/// tab's New run picker.
|
||||
///
|
||||
/// Nothing is requested until the dialog's confirm. A confirmed attempt sends
|
||||
/// the web's exact `run_pipeline` body against the pinned resolved version; a
|
||||
/// lost reply keeps the intent so the next deliberate press checks by the same
|
||||
/// request key before resending. Only the id the server names is reported.
|
||||
Future<void> openRunPipelineFlow({
|
||||
required BuildContext context,
|
||||
required PipelinesController controller,
|
||||
required PipelineDetail detail,
|
||||
required ApiGateway gateway,
|
||||
ValueChanged<int>? onRunStarted,
|
||||
}) async {
|
||||
final pipelineId = detail.id;
|
||||
final version = detail.resolvedVersion;
|
||||
final pending = await controller.loadPendingRun(pipelineId, version);
|
||||
if (!context.mounted) return;
|
||||
await showRunPipelineDialog(
|
||||
context: context,
|
||||
detail: detail,
|
||||
gateway: gateway,
|
||||
pending: pending,
|
||||
onSubmit: (intent) => _submit(controller, gateway, intent),
|
||||
onPendingChanged: (intent) {
|
||||
if (intent == null) {
|
||||
controller.clearPendingRun(pipelineId, version);
|
||||
} else {
|
||||
controller.rememberPendingRun(intent);
|
||||
}
|
||||
},
|
||||
onAccepted: (run) {
|
||||
final id = runPipelineRunId(run);
|
||||
if (id == null) return;
|
||||
controller.clearPendingRun(pipelineId, version);
|
||||
onRunStarted?.call(id);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<RunPipelineOutcome> _submit(
|
||||
PipelinesController controller,
|
||||
ApiGateway gateway,
|
||||
RunPipelineIntent intent,
|
||||
) async {
|
||||
final repository = RunsRepository(gateway);
|
||||
final pending = controller.pendingRunFor(intent.pipelineId, intent.version);
|
||||
if (pending?.requestKey == intent.requestKey) {
|
||||
// A previous send may have been admitted even though its reply was lost.
|
||||
// Check before resending the same key; the server dedupes either way.
|
||||
try {
|
||||
final existing = await repository.runByRequestKey(intent.requestKey);
|
||||
if (existing != null) {
|
||||
return _accept(controller, intent, existing);
|
||||
}
|
||||
} catch (error) {
|
||||
controller.rememberPendingRun(intent);
|
||||
return RunPipelineRefused(
|
||||
'${describeRunPipelineError(error)}$runPipelineUnknownSuffix',
|
||||
admissionUnknown: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
try {
|
||||
final run = await repository.startRun(
|
||||
pipelineId: intent.pipelineId,
|
||||
version: intent.version,
|
||||
prompt: intent.prompt,
|
||||
workspace: intent.workspace,
|
||||
requestKey: intent.requestKey,
|
||||
notifyMode: intent.notifyMode.wireValue,
|
||||
outputFormat: intent.outputFormat.wireValue,
|
||||
);
|
||||
final accepted = _accept(controller, intent, run);
|
||||
if (accepted is RunPipelineAccepted) return accepted;
|
||||
// A reply without a usable run id is not navigable: read the admitted run
|
||||
// by key rather than inventing an id or starting another run.
|
||||
return _refuse(
|
||||
controller,
|
||||
repository,
|
||||
intent,
|
||||
'The server returned no run id.',
|
||||
);
|
||||
} on ProtocolError catch (error) {
|
||||
return _refuse(
|
||||
controller,
|
||||
repository,
|
||||
intent,
|
||||
describeRunPipelineError(error),
|
||||
);
|
||||
} on RunsRepositoryException catch (error) {
|
||||
return _refuse(
|
||||
controller,
|
||||
repository,
|
||||
intent,
|
||||
describeRunPipelineError(error),
|
||||
);
|
||||
} catch (error) {
|
||||
controller.rememberPendingRun(intent);
|
||||
return RunPipelineRefused(
|
||||
'${describeRunPipelineError(error)}$runPipelineUnknownSuffix',
|
||||
admissionUnknown: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A reply is only accepted when it names a usable run id.
|
||||
RunPipelineOutcome _accept(
|
||||
PipelinesController controller,
|
||||
RunPipelineIntent intent,
|
||||
JsonMap run,
|
||||
) {
|
||||
if (runPipelineRunId(run) == null) {
|
||||
return const RunPipelineRefused(
|
||||
'The server returned no run id.',
|
||||
admissionUnknown: false,
|
||||
);
|
||||
}
|
||||
controller.clearPendingRun(intent.pipelineId, intent.version);
|
||||
return RunPipelineAccepted(run);
|
||||
}
|
||||
|
||||
/// A confirmed refusal: prove by key that no run was admitted before letting
|
||||
/// the operator correct the fields and try with a fresh key.
|
||||
Future<RunPipelineOutcome> _refuse(
|
||||
PipelinesController controller,
|
||||
RunsRepository repository,
|
||||
RunPipelineIntent intent,
|
||||
String message,
|
||||
) async {
|
||||
try {
|
||||
final existing = await repository.runByRequestKey(intent.requestKey);
|
||||
if (existing != null) return _accept(controller, intent, existing);
|
||||
controller.clearPendingRun(intent.pipelineId, intent.version);
|
||||
return RunPipelineRefused(message, admissionUnknown: false);
|
||||
} catch (_) {
|
||||
// Admission cannot be proven either way: keep the intent immutable.
|
||||
controller.rememberPendingRun(intent);
|
||||
return RunPipelineRefused(
|
||||
'$message$runPipelineUnknownSuffix',
|
||||
admissionUnknown: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user