0791a4702d
The Artifacts badge counted every recorded turn document (input, memory, output, session.html) while the tab lists only deliverables, so a run whose visits recorded only debugging files (the Caplens ticket runs) badged dozens of artifacts and opened to an empty tab. The badge and the header now count deliverables only; the tab stays reachable when only debugging files exist and ends with a collapsed 'Show debugging files' entry naming their count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
121 lines
4.1 KiB
Dart
121 lines
4.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../../../core/transport/pipelines_client.dart';
|
|
import '../domain/artifact_chat_context.dart';
|
|
import '../domain/artifact_summary.dart';
|
|
import 'artifact_external_open.dart';
|
|
import 'artifact_gallery_page.dart';
|
|
|
|
/// The run detail's action label key, so a host can find the one action.
|
|
const ValueKey<String> runArtifactsButtonKey = ValueKey<String>(
|
|
'run-detail-artifacts',
|
|
);
|
|
|
|
const Set<String> _executingStatuses = {
|
|
'queued',
|
|
'running',
|
|
'waiting',
|
|
'waiting_quota',
|
|
};
|
|
|
|
/// The detail's `steps` exactly as returned by the server. The pushed page
|
|
/// snapshots the returned list once, so it never re-derives on each rebuild.
|
|
List<JsonMap> runDetailArtifactSteps(JsonMap run) {
|
|
final steps = run['steps'];
|
|
if (steps is List<JsonMap>) return steps;
|
|
if (steps is List) return steps.cast<JsonMap>();
|
|
return const <JsonMap>[];
|
|
}
|
|
|
|
/// Whether the run detail offers the gallery action at all: only once the
|
|
/// loaded detail actually carries steps. A run with no steps has nothing to
|
|
/// list, so the action is absent rather than opening a page that says so.
|
|
bool showRunArtifactsAction(JsonMap run) =>
|
|
runDetailArtifactSteps(run).isNotEmpty;
|
|
|
|
/// How many deliverables the run's gallery lists by default, as its header
|
|
/// counts them. Debugging files are not artifacts and are never badged.
|
|
int runArtifactCount(JsonMap run) =>
|
|
runDeliverableCount(runDetailArtifactSteps(run));
|
|
|
|
/// How many debugging files the gallery's secondary section holds.
|
|
int runDebugFileCount(JsonMap run) =>
|
|
debugFileCount(runDetailArtifactSteps(run));
|
|
|
|
/// Whether the run is still executing, so the page can say capture pending
|
|
/// instead of claiming nothing was recorded.
|
|
bool runDetailExecuting(JsonMap run) => _runExecuting(run);
|
|
|
|
bool _runExecuting(JsonMap run) =>
|
|
run['executing'] == true ||
|
|
_executingStatuses.contains('${run['status'] ?? ''}'.trim().toLowerCase());
|
|
|
|
/// The run detail's standard native action that opens the recorded artifact
|
|
/// groups. It is composed only when [showRunArtifactsAction] is true.
|
|
class RunArtifactsButton extends StatelessWidget {
|
|
const RunArtifactsButton({
|
|
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) {
|
|
final steps = runDetailArtifactSteps(run);
|
|
void open() => showArtifactGallery(
|
|
context,
|
|
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,
|
|
onPressed: open,
|
|
icon: const Icon(Icons.inventory_2_outlined),
|
|
label: const Text(artifactGalleryTitle),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Opens the recorded artifact groups on a native page. The steps are
|
|
/// snapshotted once; the page never re-fetches or re-derives them.
|
|
Future<void> showArtifactGallery(
|
|
BuildContext context, {
|
|
required List<JsonMap> steps,
|
|
int? focusIndex,
|
|
bool executing = false,
|
|
String configuredEndpoint = '',
|
|
ArtifactExternalOpen openExternal = openArtifactExternally,
|
|
ArtifactChatContext? artifactChatContext,
|
|
void Function(String draft)? onSendToChat,
|
|
}) {
|
|
final page = ArtifactGalleryPage(
|
|
steps: List<JsonMap>.unmodifiable(steps),
|
|
focusIndex: focusIndex,
|
|
executing: executing,
|
|
configuredEndpoint: configuredEndpoint,
|
|
openExternal: openExternal,
|
|
artifactChatContext: artifactChatContext,
|
|
onSendToChat: onSendToChat,
|
|
);
|
|
return Navigator.of(
|
|
context,
|
|
).push<void>(MaterialPageRoute<void>(builder: (_) => page));
|
|
}
|