feat(ui): workflow list shows triggers, steps, last run and delivery with an inline enabled switch; the workflow page header carries them too
This commit is contained in:
20 files changed
+427
-138
No files matched your search
@@ -6,23 +6,19 @@ const assert = require('node:assert/strict');
|
||||
|
||||
module.exports = async ({ page, go, shot, settled }) => {
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
// The list is a page at phone width: rows open the workflow, and Enable or
|
||||
// Disable is reachable from the row menu and from the workflow page.
|
||||
// The list is a page at phone width: rows open the workflow, and the
|
||||
// enabled switch is on the row and on the workflow page.
|
||||
await go('/workflows');
|
||||
const row = page.getByRole('link', { name: /^implement/ });
|
||||
await row.waitFor();
|
||||
const listWidth = await page.evaluate(() => ({ scrollWidth: document.documentElement.scrollWidth, width: innerWidth }));
|
||||
assert.equal(listWidth.scrollWidth, listWidth.width, 'workflow list scrolls horizontally');
|
||||
await shot('list');
|
||||
await page.getByRole('button', { name: 'implement actions' }).click();
|
||||
await page.getByRole('menuitem', { name: /^(Enable|Disable)$/ }).waitFor();
|
||||
await page.keyboard.press('Escape');
|
||||
await page.getByRole('switch', { name: 'implement enabled' }).waitFor();
|
||||
await row.click();
|
||||
await page.waitForURL(/\/workflows\/implement$/);
|
||||
await page.locator('.workflow-canvas').waitFor();
|
||||
await page.getByRole('button', { name: 'More', exact: true }).click();
|
||||
await page.getByRole('menuitem', { name: /^(Enable|Disable)$/ }).waitFor();
|
||||
await page.keyboard.press('Escape');
|
||||
await page.getByRole('switch', { name: 'implement enabled' }).waitFor();
|
||||
await go('/workflows?workflow=implement');
|
||||
assert.match(page.url(), /\/workflows\/implement$/, 'legacy ?workflow= link did not reach the workflow page');
|
||||
for (const workflow of ['implement', 'feasibility']) {
|
||||
|
||||
@@ -9,6 +9,7 @@ package statev1
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
unsafe "unsafe"
|
||||
@@ -35,8 +36,11 @@ type WorkflowStat struct {
|
||||
Completed int64 `protobuf:"varint,9,opt,name=completed,proto3" json:"completed,omitempty"`
|
||||
// running and last_status describe the newest runs, so a workflow whose
|
||||
// runs are older than a global task page still reports its real state.
|
||||
Running int64 `protobuf:"varint,10,opt,name=running,proto3" json:"running,omitempty"`
|
||||
LastStatus string `protobuf:"bytes,11,opt,name=last_status,json=lastStatus,proto3" json:"last_status,omitempty"`
|
||||
Running int64 `protobuf:"varint,10,opt,name=running,proto3" json:"running,omitempty"`
|
||||
LastStatus string `protobuf:"bytes,11,opt,name=last_status,json=lastStatus,proto3" json:"last_status,omitempty"`
|
||||
// last_run_id and last_run_at name the newest run and when it was created.
|
||||
LastRunId int64 `protobuf:"varint,12,opt,name=last_run_id,json=lastRunId,proto3" json:"last_run_id,omitempty"`
|
||||
LastRunAt *timestamppb.Timestamp `protobuf:"bytes,13,opt,name=last_run_at,json=lastRunAt,proto3" json:"last_run_at,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
@@ -148,6 +152,20 @@ func (x *WorkflowStat) GetLastStatus() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *WorkflowStat) GetLastRunId() int64 {
|
||||
if x != nil {
|
||||
return x.LastRunId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *WorkflowStat) GetLastRunAt() *timestamppb.Timestamp {
|
||||
if x != nil {
|
||||
return x.LastRunAt
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// StageStat mirrors storecontract.StageStat.
|
||||
type StageStat struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
@@ -812,7 +830,7 @@ var File_state_v1_stats_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_state_v1_stats_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"\x14state/v1/stats.proto\x12\bstate.v1\"\xbf\x02\n" +
|
||||
"\x14state/v1/stats.proto\x12\bstate.v1\x1a\x1fgoogle/protobuf/timestamp.proto\"\x9b\x03\n" +
|
||||
"\fWorkflowStat\x12\x1a\n" +
|
||||
"\bworkflow\x18\x01 \x01(\tR\bworkflow\x12\x12\n" +
|
||||
"\x04runs\x18\x02 \x01(\x03R\x04runs\x12\x16\n" +
|
||||
@@ -827,7 +845,9 @@ const file_state_v1_stats_proto_rawDesc = "" +
|
||||
"\arunning\x18\n" +
|
||||
" \x01(\x03R\arunning\x12\x1f\n" +
|
||||
"\vlast_status\x18\v \x01(\tR\n" +
|
||||
"lastStatus\"\x80\x01\n" +
|
||||
"lastStatus\x12\x1e\n" +
|
||||
"\vlast_run_id\x18\f \x01(\x03R\tlastRunId\x12:\n" +
|
||||
"\vlast_run_at\x18\r \x01(\v2\x1a.google.protobuf.TimestampR\tlastRunAt\"\x80\x01\n" +
|
||||
"\tStageStat\x12\x1a\n" +
|
||||
"\bworkflow\x18\x01 \x01(\tR\bworkflow\x12\x14\n" +
|
||||
"\x05stage\x18\x02 \x01(\tR\x05stage\x12\x12\n" +
|
||||
@@ -906,28 +926,30 @@ var file_state_v1_stats_proto_goTypes = []any{
|
||||
(*UsageTotalsRequest)(nil), // 12: state.v1.UsageTotalsRequest
|
||||
(*UsageTotalsResponse)(nil), // 13: state.v1.UsageTotalsResponse
|
||||
nil, // 14: state.v1.StatusCountsResponse.CountsEntry
|
||||
(*timestamppb.Timestamp)(nil), // 15: google.protobuf.Timestamp
|
||||
}
|
||||
var file_state_v1_stats_proto_depIdxs = []int32{
|
||||
14, // 0: state.v1.StatusCountsResponse.counts:type_name -> state.v1.StatusCountsResponse.CountsEntry
|
||||
0, // 1: state.v1.WorkflowStatsResponse.stats:type_name -> state.v1.WorkflowStat
|
||||
1, // 2: state.v1.StageStatsResponse.stats:type_name -> state.v1.StageStat
|
||||
2, // 3: state.v1.TokensByDayResponse.tokens:type_name -> state.v1.DayTokens
|
||||
11, // 4: state.v1.UsageTotalsResponse.rows:type_name -> state.v1.UsageTotalRow
|
||||
3, // 5: state.v1.StatsService.StatusCounts:input_type -> state.v1.StatusCountsRequest
|
||||
5, // 6: state.v1.StatsService.WorkflowStats:input_type -> state.v1.WorkflowStatsRequest
|
||||
7, // 7: state.v1.StatsService.StageStats:input_type -> state.v1.StageStatsRequest
|
||||
9, // 8: state.v1.StatsService.TokensByDay:input_type -> state.v1.TokensByDayRequest
|
||||
12, // 9: state.v1.StatsService.UsageTotals:input_type -> state.v1.UsageTotalsRequest
|
||||
4, // 10: state.v1.StatsService.StatusCounts:output_type -> state.v1.StatusCountsResponse
|
||||
6, // 11: state.v1.StatsService.WorkflowStats:output_type -> state.v1.WorkflowStatsResponse
|
||||
8, // 12: state.v1.StatsService.StageStats:output_type -> state.v1.StageStatsResponse
|
||||
10, // 13: state.v1.StatsService.TokensByDay:output_type -> state.v1.TokensByDayResponse
|
||||
13, // 14: state.v1.StatsService.UsageTotals:output_type -> state.v1.UsageTotalsResponse
|
||||
10, // [10:15] is the sub-list for method output_type
|
||||
5, // [5:10] is the sub-list for method input_type
|
||||
5, // [5:5] is the sub-list for extension type_name
|
||||
5, // [5:5] is the sub-list for extension extendee
|
||||
0, // [0:5] is the sub-list for field type_name
|
||||
15, // 0: state.v1.WorkflowStat.last_run_at:type_name -> google.protobuf.Timestamp
|
||||
14, // 1: state.v1.StatusCountsResponse.counts:type_name -> state.v1.StatusCountsResponse.CountsEntry
|
||||
0, // 2: state.v1.WorkflowStatsResponse.stats:type_name -> state.v1.WorkflowStat
|
||||
1, // 3: state.v1.StageStatsResponse.stats:type_name -> state.v1.StageStat
|
||||
2, // 4: state.v1.TokensByDayResponse.tokens:type_name -> state.v1.DayTokens
|
||||
11, // 5: state.v1.UsageTotalsResponse.rows:type_name -> state.v1.UsageTotalRow
|
||||
3, // 6: state.v1.StatsService.StatusCounts:input_type -> state.v1.StatusCountsRequest
|
||||
5, // 7: state.v1.StatsService.WorkflowStats:input_type -> state.v1.WorkflowStatsRequest
|
||||
7, // 8: state.v1.StatsService.StageStats:input_type -> state.v1.StageStatsRequest
|
||||
9, // 9: state.v1.StatsService.TokensByDay:input_type -> state.v1.TokensByDayRequest
|
||||
12, // 10: state.v1.StatsService.UsageTotals:input_type -> state.v1.UsageTotalsRequest
|
||||
4, // 11: state.v1.StatsService.StatusCounts:output_type -> state.v1.StatusCountsResponse
|
||||
6, // 12: state.v1.StatsService.WorkflowStats:output_type -> state.v1.WorkflowStatsResponse
|
||||
8, // 13: state.v1.StatsService.StageStats:output_type -> state.v1.StageStatsResponse
|
||||
10, // 14: state.v1.StatsService.TokensByDay:output_type -> state.v1.TokensByDayResponse
|
||||
13, // 15: state.v1.StatsService.UsageTotals:output_type -> state.v1.UsageTotalsResponse
|
||||
11, // [11:16] is the sub-list for method output_type
|
||||
6, // [6:11] is the sub-list for method input_type
|
||||
6, // [6:6] is the sub-list for extension type_name
|
||||
6, // [6:6] is the sub-list for extension extendee
|
||||
0, // [0:6] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_state_v1_stats_proto_init() }
|
||||
|
||||
@@ -191,6 +191,9 @@ type WorkflowStat struct {
|
||||
// are working, and how its newest one ended.
|
||||
Running int `json:"running"`
|
||||
LastStatus string `json:"last_status"`
|
||||
// LastRunID and LastRunAt identify the newest run and when it was created.
|
||||
LastRunID int64 `json:"last_run_id"`
|
||||
LastRunAt time.Time `json:"last_run_at"`
|
||||
}
|
||||
|
||||
// StageStat is average stage duration and failure counts per stage.
|
||||
|
||||
@@ -129,6 +129,8 @@ func (s *Store) WorkflowStats(ctx context.Context) ([]storecontract.WorkflowStat
|
||||
TotalToken: int(r.TotalTokens),
|
||||
Running: int(r.Running),
|
||||
LastStatus: r.LastStatus,
|
||||
LastRunID: r.LastRunID,
|
||||
LastRunAt: r.LastRunAt,
|
||||
})
|
||||
}
|
||||
return stats, nil
|
||||
|
||||
@@ -385,6 +385,8 @@ SELECT workflow,
|
||||
COUNT(*) FILTER (WHERE status = 'parked')::int AS parked,
|
||||
COUNT(*) FILTER (WHERE status = 'running')::int AS running,
|
||||
COALESCE((ARRAY_AGG(status ORDER BY id DESC))[1], '')::text AS last_status,
|
||||
MAX(id)::bigint AS last_run_id,
|
||||
MAX(created_at)::timestamptz AS last_run_at,
|
||||
CAST(AVG(tokens_used) AS bigint) AS avg_tokens,
|
||||
AVG(iterations)::float8 AS avg_steps,
|
||||
SUM(tokens_used)::bigint AS total_tokens
|
||||
@@ -403,6 +405,8 @@ type WorkflowStatsRow struct {
|
||||
Parked int32
|
||||
Running int32
|
||||
LastStatus string
|
||||
LastRunID int64
|
||||
LastRunAt time.Time
|
||||
AvgTokens int64
|
||||
AvgSteps float64
|
||||
TotalTokens int64
|
||||
@@ -429,6 +433,8 @@ func (q *Queries) WorkflowStats(ctx context.Context, scopeOrg pgtype.Text) ([]Wo
|
||||
&i.Parked,
|
||||
&i.Running,
|
||||
&i.LastStatus,
|
||||
&i.LastRunID,
|
||||
&i.LastRunAt,
|
||||
&i.AvgTokens,
|
||||
&i.AvgSteps,
|
||||
&i.TotalTokens,
|
||||
|
||||
@@ -56,6 +56,8 @@ SELECT workflow,
|
||||
COUNT(*) FILTER (WHERE status = 'parked')::int AS parked,
|
||||
COUNT(*) FILTER (WHERE status = 'running')::int AS running,
|
||||
COALESCE((ARRAY_AGG(status ORDER BY id DESC))[1], '')::text AS last_status,
|
||||
MAX(id)::bigint AS last_run_id,
|
||||
MAX(created_at)::timestamptz AS last_run_at,
|
||||
CAST(AVG(tokens_used) AS bigint) AS avg_tokens,
|
||||
AVG(iterations)::float8 AS avg_steps,
|
||||
SUM(tokens_used)::bigint AS total_tokens
|
||||
|
||||
@@ -328,6 +328,7 @@ func workflowStatProto(w storecontract.WorkflowStat) *pb.WorkflowStat {
|
||||
Completed: int64(w.Completed), PrOpen: int64(w.PROpen), Parked: int64(w.Parked),
|
||||
AvgTokens: int64(w.AvgTokens), AvgSteps: w.AvgSteps, TotalTokens: int64(w.TotalToken),
|
||||
Running: int64(w.Running), LastStatus: w.LastStatus,
|
||||
LastRunId: w.LastRunID, LastRunAt: timestamp(w.LastRunAt),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,6 +341,7 @@ func workflowStatValue(w *pb.WorkflowStat) storecontract.WorkflowStat {
|
||||
Completed: int(w.Completed), PROpen: int(w.PrOpen), Parked: int(w.Parked),
|
||||
AvgTokens: int(w.AvgTokens), AvgSteps: w.AvgSteps, TotalToken: int(w.TotalTokens),
|
||||
Running: int(w.Running), LastStatus: w.LastStatus,
|
||||
LastRunID: w.LastRunId, LastRunAt: timeValue(w.LastRunAt),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ syntax = "proto3";
|
||||
|
||||
package state.v1;
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
service StatsService {
|
||||
rpc StatusCounts(StatusCountsRequest) returns (StatusCountsResponse);
|
||||
rpc WorkflowStats(WorkflowStatsRequest) returns (WorkflowStatsResponse);
|
||||
@@ -25,6 +27,9 @@ message WorkflowStat {
|
||||
// runs are older than a global task page still reports its real state.
|
||||
int64 running = 10;
|
||||
string last_status = 11;
|
||||
// last_run_id and last_run_at name the newest run and when it was created.
|
||||
int64 last_run_id = 12;
|
||||
google.protobuf.Timestamp last_run_at = 13;
|
||||
}
|
||||
// StageStat mirrors storecontract.StageStat.
|
||||
message StageStat {
|
||||
|
||||
+4
-4
@@ -16,7 +16,7 @@ import SectionCrumb from "@/components/topbar/SectionCrumb.vue";
|
||||
import Brand from "@/components/topbar/Brand.vue";
|
||||
import Logo from "@/components/topbar/Logo.vue";
|
||||
import ConnectionPill from "@/components/topbar/ConnectionPill.vue";
|
||||
import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbSeparator } from "@/components/ui/breadcrumb";
|
||||
import { Breadcrumb, BreadcrumbItem, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from "@/components/ui/breadcrumb";
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar";
|
||||
@@ -107,10 +107,10 @@ watch(() => accounts.status?.user, (user) => {
|
||||
<BreadcrumbSeparator />
|
||||
<BreadcrumbItem><OrgCrumb /></BreadcrumbItem>
|
||||
<BreadcrumbSeparator />
|
||||
<BreadcrumbItem><SectionCrumb :hidden="hidden" /></BreadcrumbItem>
|
||||
<BreadcrumbItem><SectionCrumb :hidden="hidden" :link="route.name === 'workflow' ? '/workflows' : undefined" /></BreadcrumbItem>
|
||||
<template v-if="route.name === 'workflow'">
|
||||
<BreadcrumbSeparator />
|
||||
<BreadcrumbItem class="min-w-0"><BreadcrumbLink as-child><RouterLink to="/workflows" class="truncate">All workflows</RouterLink></BreadcrumbLink></BreadcrumbItem>
|
||||
<BreadcrumbSeparator class="max-md:hidden" />
|
||||
<BreadcrumbItem class="min-w-0 max-md:hidden"><BreadcrumbPage class="truncate">{{ route.params.id }}</BreadcrumbPage></BreadcrumbItem>
|
||||
</template>
|
||||
</BreadcrumbList>
|
||||
</Breadcrumb>
|
||||
|
||||
@@ -19,7 +19,7 @@ import { useLiveResource } from "@/stores/session";
|
||||
import { useTasksStore } from "@/stores/tasks";
|
||||
import { useHoverOpen } from "./hover-open";
|
||||
|
||||
const props = defineProps<{ hidden: string[] }>();
|
||||
const props = defineProps<{ hidden: string[]; link?: string }>();
|
||||
|
||||
const route = useRoute();
|
||||
const store = useTasksStore();
|
||||
@@ -44,7 +44,15 @@ const hover = useHoverOpen();
|
||||
|
||||
<template>
|
||||
<DropdownMenu :open="hover.open.value" :modal="false" @update:open="hover.update">
|
||||
<DropdownMenuTrigger as-child>
|
||||
<!-- On a page inside the section the label is the way back to it, and the
|
||||
chevron keeps the section menu. -->
|
||||
<div v-if="link" class="flex items-center">
|
||||
<Button as-child variant="ghost" size="sm" class="px-2"><RouterLink :to="link">{{ current?.label ?? route.meta.label }}</RouterLink></Button>
|
||||
<DropdownMenuTrigger as-child>
|
||||
<Button variant="ghost" size="icon-sm" aria-label="Sections" @pointerenter="hover.enterTrigger" @pointerleave="hover.leaveTrigger"><ChevronDown class="size-4" aria-hidden="true" /></Button>
|
||||
</DropdownMenuTrigger>
|
||||
</div>
|
||||
<DropdownMenuTrigger v-else as-child>
|
||||
<Button variant="ghost" size="sm" class="gap-1 px-2" aria-label="Sections" @pointerenter="hover.enterTrigger" @pointerleave="hover.leaveTrigger">
|
||||
<span>{{ current?.label ?? route.meta.label ?? "Sections" }}</span>
|
||||
<Badge v-if="activePath !== '/' && attention" variant="warn" class="tabular-nums" :aria-label="`${attention} need attention`">{{ attention }}</Badge>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { Progress } from "@/components/ui/progress";
|
||||
import { delivered, type DeliveredCounts } from "@/lib/delivered";
|
||||
|
||||
/** How many of a workflow's runs finished their work, in words and a bar. */
|
||||
const props = defineProps<{ counts: DeliveredCounts; runs?: number }>();
|
||||
const done = () => delivered(props.counts);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="runs" class="flex min-w-28 flex-col gap-1">
|
||||
<span class="text-label tabular-nums">{{ done() }} of {{ runs }} delivered</span>
|
||||
<Progress :model-value="Math.round((done() / runs) * 100)" aria-hidden="true" class="h-1" />
|
||||
</div>
|
||||
</template>
|
||||
@@ -9,8 +9,8 @@ import {
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { computed, onBeforeUnmount, onMounted, ref, toRef, watch } from "vue";
|
||||
import { CircleAlert, Copy, Power, RotateCcw, Trash2 } from "@lucide/vue";
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||
import { CircleAlert, Copy, RotateCcw, Trash2 } from "@lucide/vue";
|
||||
import { isSending, setTurnHooks } from "@/chat/state";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -39,7 +39,7 @@ import ChangeList from "@/components/ChangeList.vue";
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { useWorkflowRuns } from "./workflow-runs";
|
||||
import WorkflowRuns, { type StageStats } from "./WorkflowRuns.vue";
|
||||
import { useWorkflowTriggers } from "./workflow-triggers";
|
||||
import type { WorkflowTrigger } from "./workflow-triggers";
|
||||
import { useSettingsStore } from "@/stores/settings";
|
||||
import {
|
||||
removeWorkflowDefinition,
|
||||
@@ -66,9 +66,9 @@ const modelAliases = computed(() =>
|
||||
const collection = computed(() => workflows.collection);
|
||||
// Which definition is open belongs to the page, which also lists them.
|
||||
const selected = defineModel<string>("selected", { required: true });
|
||||
const emit = defineEmits<{ duplicate: [id: string]; setEnabled: [value: boolean] }>();
|
||||
const emit = defineEmits<{ duplicate: [id: string]; reloadTriggers: [] }>();
|
||||
// Stage statistics are read by the page with the rest of the workflow stats.
|
||||
const props = defineProps<{ stageStats: StageStats[]; statsKnown: boolean; statsError: string; startedBy: { workflow: string; via: string }[]; enabled?: boolean }>();
|
||||
const props = defineProps<{ stageStats: StageStats[]; statsKnown: boolean; statsError: string; triggers: WorkflowTrigger[]; triggersError: string }>();
|
||||
const id = ref("");
|
||||
const yaml = ref("");
|
||||
const loadedYaml = ref("");
|
||||
@@ -114,7 +114,7 @@ async function restartFrom(from: string): Promise<void> {
|
||||
restarting.value = false;
|
||||
}
|
||||
}
|
||||
const { triggers, reload: reloadTriggers, error: triggersError } = useWorkflowTriggers(selected, toRef(() => props.startedBy));
|
||||
const reloadTriggers = () => emit("reloadTriggers");
|
||||
|
||||
const { revisions, error: historyError, loaded: historyLoaded, reload: reloadHistory } = useWorkflowHistory(selected);
|
||||
const historyRevision = ref(0);
|
||||
@@ -475,7 +475,6 @@ const runOptions = computed(() => [
|
||||
<DropdownMenuItem v-if="watchedRevision" @select="openRevision(watchedRevision.version)">Version {{ watchedRevision.version }}</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="changes.length" @select="draftOpen = true">Draft changes <span class="ml-auto font-mono text-caption text-fg-subtle">{{ changes.length }}</span></DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="dirty" :disabled="archieWorking" @select="confirmDiscard = true"><RotateCcw />Discard changes</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="props.enabled !== undefined" @select="emit('setEnabled', !props.enabled)"><Power />{{ props.enabled ? "Disable" : "Enable" }}</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="stored !== undefined" @select="emit('duplicate', selected)"><Copy />Duplicate</DropdownMenuItem>
|
||||
<DropdownMenuItem variant="destructive" @select="confirmDelete = true"><Trash2 />Delete workflow</DropdownMenuItem>
|
||||
</MoreMenu>
|
||||
@@ -501,7 +500,7 @@ const runOptions = computed(() => [
|
||||
:yaml="canvasYaml"
|
||||
:stages="drawnStages"
|
||||
:open="open"
|
||||
:triggers="triggers"
|
||||
:triggers="props.triggers"
|
||||
:types="stepTypeNames"
|
||||
:readonly="!!pinnedYaml || archieWorking"
|
||||
:restartable="restartable"
|
||||
@@ -518,7 +517,7 @@ const runOptions = computed(() => [
|
||||
>
|
||||
<template #body="{ data }">
|
||||
<fieldset v-if="data.kind === 'workflow'" :disabled="!!pinnedYaml" class="min-w-0"><WorkflowSettings :yaml="canvasYaml" @update:yaml="yaml = $event" /></fieldset>
|
||||
<fieldset v-else-if="data.kind === 'start'" :disabled="!!pinnedYaml" class="min-w-0"><TriggerSettings :yaml="canvasYaml" :triggers="triggers" :error="triggersError" @update:yaml="yaml = $event" @bound="reloadTriggers" @reload="reloadTriggers" /></fieldset>
|
||||
<fieldset v-else-if="data.kind === 'start'" :disabled="!!pinnedYaml" class="min-w-0"><TriggerSettings :yaml="canvasYaml" :triggers="props.triggers" :error="props.triggersError" @update:yaml="yaml = $event" @bound="reloadTriggers" @reload="reloadTriggers" /></fieldset>
|
||||
<template v-else-if="data.path">
|
||||
<div v-if="data.run && watchedRun" class="flex items-center gap-2 border-b border-border px-3 py-2">
|
||||
<Tabs v-model="stepTab"><TabsList><TabsTrigger value="run">Run</TabsTrigger><TabsTrigger value="definition">Definition</TabsTrigger></TabsList></Tabs>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import { StatusDot } from "@/components/ui/status-dot";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { statusKind, statusLabel } from "@/lib/task-meta";
|
||||
|
||||
/** A workflow's newest run: how it stands, when it started, and a link to it. */
|
||||
defineProps<{ runId?: number; status?: string; at?: string; running?: number; known: boolean }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RouterLink v-if="runId" :to="{ name: 'task-detail', params: { id: runId } }" class="inline-flex min-w-0 flex-col gap-0.5 rounded-sm hover:underline focus-visible:outline-2 focus-visible:outline-ring" :aria-label="`Run #${runId}, ${statusLabel(status ?? '')}`" @click.stop>
|
||||
<span class="flex items-center gap-1.5 text-label">
|
||||
<StatusDot :tone="running ? 'info' : statusKind(status ?? '')" :live="!!running" />{{ running ? `${running} running` : statusLabel(status ?? "") }}
|
||||
</span>
|
||||
<Timestamp :at="at" class="text-caption text-fg-subtle" />
|
||||
</RouterLink>
|
||||
<span v-else-if="known" class="text-caption text-fg-subtle">Never run</span>
|
||||
</template>
|
||||
@@ -3,12 +3,14 @@ import { computed, onMounted, ref } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import ApplyStatusRows from "@/settings/ApplyStatusRows.vue";
|
||||
import WorkflowEditor from "./WorkflowEditor.vue";
|
||||
import { useWorkflowStats } from "./use-workflow-stats";
|
||||
import { triggerSummary, useWorkflowTriggers } from "./workflow-triggers";
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
@@ -48,6 +50,8 @@ const provenance = computed(() => {
|
||||
});
|
||||
const stages = computed(() => (data.value.stages ?? []).filter((s) => s.workflow === selected.value));
|
||||
const startedBy = computed(() => data.value.definitions?.find((d) => d.id === selected.value)?.started_by ?? []);
|
||||
const { triggers, reload: reloadTriggers, error: triggersError } = useWorkflowTriggers(selected, startedBy);
|
||||
const trigger = computed(() => triggerSummary(triggers.value));
|
||||
|
||||
async function copy(id: string) {
|
||||
const next = await duplicate(id);
|
||||
@@ -69,33 +73,40 @@ async function copy(id: string) {
|
||||
</Empty>
|
||||
<!-- No card around the editor: the canvas draws its own frame. -->
|
||||
<div v-else-if="known" class="min-w-0 max-md:flex max-md:h-full max-md:min-h-0 max-md:flex-col" role="region" aria-label="Workflow">
|
||||
<!-- The editor's toolbar carries the title from lg up; below it the title stands alone. -->
|
||||
<header class="mb-2 flex shrink-0 items-center gap-2 lg:hidden">
|
||||
<h1 class="min-w-0 flex-1 truncate text-title font-medium">{{ selected }}</h1>
|
||||
<header class="mb-2 flex shrink-0 flex-wrap items-center gap-x-3 gap-y-0.5 lg:hidden">
|
||||
<h1 class="min-w-0 truncate text-title font-medium">{{ selected }}</h1>
|
||||
<Switch v-if="enabled !== undefined" size="sm" :model-value="enabled" :aria-label="`${selected} enabled`" @update:model-value="setEnabled(selected, $event)" />
|
||||
<Badge v-if="draft" variant="outline" class="shrink-0">Draft</Badge>
|
||||
<Badge v-if="enabled === false" variant="secondary" class="shrink-0">Disabled</Badge>
|
||||
<Badge v-if="provenance" variant="outline" class="shrink-0">{{ provenance }}</Badge>
|
||||
<ApplyStatusRows kind="workflow-definitions" compact />
|
||||
<p v-if="trigger.text || (!triggersError && !triggers.length)" class="flex min-w-0 basis-full items-center gap-1.5 text-caption text-fg-muted lg:basis-0 lg:flex-1">
|
||||
<span class="truncate">{{ trigger.text || "Manual" }}</span>
|
||||
<Badge v-if="trigger.more.length" variant="secondary" :title="trigger.more.join('\n')">+{{ trigger.more.length }}</Badge>
|
||||
</p>
|
||||
</header>
|
||||
<WorkflowEditor
|
||||
v-model:selected="selected"
|
||||
v-model:view="view"
|
||||
v-model:run-open="runOpen"
|
||||
:stage-stats="stages"
|
||||
:started-by="startedBy"
|
||||
:triggers="triggers"
|
||||
:triggers-error="triggersError"
|
||||
:stats-known="statsKnown"
|
||||
:stats-error="error ?? ''"
|
||||
:enabled="enabled"
|
||||
@duplicate="copy"
|
||||
@set-enabled="setEnabled(selected, $event)"
|
||||
@reload-triggers="reloadTriggers"
|
||||
>
|
||||
<template #title>
|
||||
<h1 class="min-w-0 truncate text-title font-medium">{{ selected }}</h1>
|
||||
<Badge v-if="draft" variant="outline" class="shrink-0">Draft</Badge>
|
||||
<Badge v-if="enabled === false" variant="secondary" class="shrink-0">Disabled</Badge>
|
||||
<Badge v-if="provenance" variant="outline" class="shrink-0">{{ provenance }}</Badge>
|
||||
<ApplyStatusRows kind="workflow-definitions" compact />
|
||||
</template>
|
||||
<h1 class="min-w-0 truncate text-title font-medium">{{ selected }}</h1>
|
||||
<Switch v-if="enabled !== undefined" size="sm" :model-value="enabled" :aria-label="`${selected} enabled`" @update:model-value="setEnabled(selected, $event)" />
|
||||
<Badge v-if="draft" variant="outline" class="shrink-0">Draft</Badge>
|
||||
<Badge v-if="provenance" variant="outline" class="shrink-0">{{ provenance }}</Badge>
|
||||
<ApplyStatusRows kind="workflow-definitions" compact />
|
||||
<p v-if="trigger.text || (!triggersError && !triggers.length)" class="flex min-w-0 max-w-64 items-center gap-1.5 text-caption text-fg-muted">
|
||||
<span class="truncate">{{ trigger.text || "Manual" }}</span>
|
||||
<Badge v-if="trigger.more.length" variant="secondary" :title="trigger.more.join('\n')">+{{ trigger.more.length }}</Badge>
|
||||
</p>
|
||||
</template>
|
||||
</WorkflowEditor>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import { Copy, ListChecks, Play, Trash2 } from "@lucide/vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
||||
import { MoreMenu } from "@/components/ui/more-menu";
|
||||
|
||||
/** Run, and the overflow menu, for one workflow row. */
|
||||
defineProps<{ id: string; canRun: boolean; stored: boolean }>();
|
||||
const emit = defineEmits<{ run: []; runs: []; duplicate: []; remove: [] }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center gap-1" @click.stop @keydown.stop>
|
||||
<Button v-if="stored" type="button" size="sm" variant="outline" :disabled="!canRun" :aria-label="`Run ${id}`" :title="canRun ? undefined : 'Disabled'" @click="emit('run')">
|
||||
<Play data-icon="inline-start" />Run
|
||||
</Button>
|
||||
<MoreMenu :label="`${id} actions`">
|
||||
<DropdownMenuItem v-if="stored" @select="emit('runs')"><ListChecks />Open runs</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="stored" @select="emit('duplicate')"><Copy />Duplicate</DropdownMenuItem>
|
||||
<DropdownMenuItem variant="destructive" @select="emit('remove')"><Trash2 />Delete</DropdownMenuItem>
|
||||
</MoreMenu>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,63 +1,85 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { computed, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { Copy, ListChecks, Play, Plus, Power } from "@lucide/vue";
|
||||
import { useMediaQuery } from "@vueuse/core";
|
||||
import { Copy, ListChecks, Play, Plus, Search, Trash2 } from "@lucide/vue";
|
||||
import { toast } from "vue-sonner";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from "@/components/ui/context-menu";
|
||||
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { MoreMenu } from "@/components/ui/more-menu";
|
||||
import { Progress } from "@/components/ui/progress";
|
||||
import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { StatusDot } from "@/components/ui/status-dot";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { delivered } from "@/lib/delivered";
|
||||
import { compact } from "@/lib/format";
|
||||
import { statusLabel } from "@/lib/task-meta";
|
||||
import { SEEDED_AGENT_ID } from "./workflow-edit";
|
||||
import { workflowRows } from "./workflow-rows";
|
||||
import { workflowRows, type WorkflowRow } from "./workflow-rows";
|
||||
import { byActivity, stepCount } from "./workflow-summary";
|
||||
import { triggerSummary, useTriggerSources } from "./workflow-triggers";
|
||||
import { useWorkflowStats } from "./use-workflow-stats";
|
||||
import WorkflowDelivery from "./WorkflowDelivery.vue";
|
||||
import WorkflowLastRun from "./WorkflowLastRun.vue";
|
||||
import WorkflowRowActions from "./WorkflowRowActions.vue";
|
||||
|
||||
const router = useRouter();
|
||||
const { store, data, error, loading, statsKnown, load, enabledOf, setEnabled, duplicate } = useWorkflowStats();
|
||||
const { store, data, error, loading, statsKnown, load, enabledOf, setEnabled, duplicate, remove } = useWorkflowStats();
|
||||
const wide = useMediaQuery("(min-width: 1024px)");
|
||||
|
||||
const startedByOf = (id: string) => data.value.definitions?.find((d) => d.id === id)?.started_by ?? [];
|
||||
const { triggersOf, error: triggersError, known: triggersKnown, reload: reloadTriggers } = useTriggerSources(startedByOf);
|
||||
|
||||
interface ListRow extends WorkflowRow {
|
||||
draft: boolean;
|
||||
stored: boolean;
|
||||
steps?: number;
|
||||
trigger: { text: string; more: string[] };
|
||||
}
|
||||
|
||||
// Stored definitions are the source of truth for the list; statistics join
|
||||
// them by id, and a workflow seen only in statistics still gets a row.
|
||||
const stored = computed(() => store.collection.definitions);
|
||||
const rows = computed(() =>
|
||||
workflowRows(
|
||||
const rows = computed<ListRow[]>(() => {
|
||||
const drafts = store.drafts.filter((draft) => !stored.value.some((d) => d.id === draft.id));
|
||||
const sources = [...stored.value, ...drafts];
|
||||
return workflowRows(
|
||||
data.value.workflows,
|
||||
[...stored.value, ...store.drafts.filter((draft) => !stored.value.some((d) => d.id === draft.id))].map((d) => ({
|
||||
id: d.id,
|
||||
name: d.id,
|
||||
origin: data.value.definitions?.find((x) => x.id === d.id)?.origin,
|
||||
})),
|
||||
),
|
||||
);
|
||||
sources.map((d) => ({ id: d.id, name: d.id, origin: data.value.definitions?.find((x) => x.id === d.id)?.origin })),
|
||||
)
|
||||
.sort(byActivity)
|
||||
.map((row) => ({
|
||||
...row,
|
||||
draft: store.drafts.some((draft) => draft.id === row.id),
|
||||
stored: stored.value.some((d) => d.id === row.id),
|
||||
steps: stepCount((stored.value.find((d) => d.id === row.id) ?? store.drafts.find((d) => d.id === row.id))?.yaml ?? ""),
|
||||
trigger: triggerSummary(triggersOf(row.id)),
|
||||
}));
|
||||
});
|
||||
|
||||
// A filter earns its place once the list outgrows a glance.
|
||||
const FILTER_FROM = 8;
|
||||
const query = ref("");
|
||||
const shown = computed(() => {
|
||||
const needle = query.value.trim().toLowerCase();
|
||||
return needle ? rows.value.filter((row) => row.id.toLowerCase().includes(needle) || row.trigger.text.toLowerCase().includes(needle)) : rows.value;
|
||||
});
|
||||
|
||||
const open = (id: string, query?: Record<string, string>) => void router.push({ name: "workflow", params: { id }, query });
|
||||
const run = (id: string) => open(id, { run: "1" });
|
||||
const openRuns = (id: string) => open(id, { view: "runs" });
|
||||
const copy = (id: string) => void duplicate(id).then((next) => next && open(next));
|
||||
const canRun = (row: ListRow) => row.stored && enabledOf(row.id) !== false;
|
||||
|
||||
interface RowAction {
|
||||
label: string;
|
||||
icon: typeof Play;
|
||||
run: () => void;
|
||||
}
|
||||
function rowActions(id: string): RowAction[] {
|
||||
const enabled = enabledOf(id);
|
||||
const actions: RowAction[] = [];
|
||||
if (enabled !== undefined) actions.push({ label: enabled ? "Disable" : "Enable", icon: Power, run: () => void setEnabled(id, !enabled) });
|
||||
if (stored.value.some((d) => d.id === id)) {
|
||||
actions.push(
|
||||
{ label: "Run", icon: Play, run: () => open(id, { run: "1" }) },
|
||||
{ label: "Open runs", icon: ListChecks, run: () => open(id, { view: "runs" }) },
|
||||
{ label: "Duplicate", icon: Copy, run: () => void duplicate(id).then((copy) => copy && open(copy)) },
|
||||
);
|
||||
}
|
||||
return actions;
|
||||
const deleting = ref("");
|
||||
async function confirmRemove() {
|
||||
const id = deleting.value;
|
||||
deleting.value = "";
|
||||
await remove(id);
|
||||
}
|
||||
|
||||
// A new workflow starts as a draft, so it is in the list straight away and
|
||||
@@ -69,20 +91,30 @@ async function create() {
|
||||
if (await store.putDraft(id, `id: ${id}\nidentity: ${SEEDED_AGENT_ID}\nsteps: []\n`)) open(id);
|
||||
else toast.error(store.draftState.error || errors.workflows.editor.draftNotSaved);
|
||||
}
|
||||
// The share of a workflow's runs whose work is finished: merged, or ended
|
||||
// with nothing to merge (a no-change build, a no-code triage -- `completed`).
|
||||
const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total : 0);
|
||||
|
||||
const reload = () => {
|
||||
void load();
|
||||
void store.load();
|
||||
void reloadTriggers();
|
||||
};
|
||||
const anyTokens = computed(() => shown.value.some((row) => row.avg_tokens));
|
||||
const tokens = (row: ListRow) => (row.avg_tokens ? compact(row.avg_tokens) : "–");
|
||||
const stepsLabel = (row: ListRow) => (row.steps === undefined ? "" : `${row.steps} ${row.steps === 1 ? "step" : "steps"}`);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Workflows">
|
||||
<InputGroup v-if="rows.length > FILTER_FROM" class="w-56 max-sm:w-full">
|
||||
<InputGroupAddon><Search /></InputGroupAddon>
|
||||
<InputGroupInput v-model="query" type="search" aria-label="Filter workflows" placeholder="Filter" />
|
||||
</InputGroup>
|
||||
<Button size="icon-sm" variant="ghost" aria-label="New workflow" title="New workflow" @click="create"><Plus /></Button>
|
||||
</PageHeader>
|
||||
|
||||
<div v-if="error || store.error" class="mb-4 text-label text-danger" role="alert">
|
||||
<p>{{ error || store.error }}</p>
|
||||
<Button variant="outline" size="sm" @click="load(); store.load()">Retry</Button>
|
||||
<Button variant="outline" size="sm" @click="reload">Retry</Button>
|
||||
</div>
|
||||
<p v-if="loading || (!store.state.resource && !store.error)" class="flex items-center gap-2 text-label text-fg-muted"><Spinner />Loading workflows…</p>
|
||||
|
||||
@@ -91,39 +123,105 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
|
||||
<EmptyTitle>No workflows</EmptyTitle>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
<ul v-else class="flex max-w-3xl flex-col gap-0.5" aria-label="Workflows">
|
||||
<li v-for="row in rows" :key="row.id" class="relative min-w-0">
|
||||
<ContextMenu>
|
||||
<p v-else-if="!shown.length" class="text-label text-fg-muted">No workflow matches.</p>
|
||||
|
||||
<Table v-else-if="wide" class="table-fixed" aria-label="Workflows">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead class="w-[22%]">Workflow</TableHead>
|
||||
<TableHead class="w-[22%]">Starts from</TableHead>
|
||||
<TableHead class="w-16">Steps</TableHead>
|
||||
<TableHead class="w-20">Enabled</TableHead>
|
||||
<TableHead class="w-[13%]">Last run</TableHead>
|
||||
<TableHead class="w-[13%]">Runs</TableHead>
|
||||
<TableHead v-if="anyTokens" class="w-24 text-right">Tokens</TableHead>
|
||||
<TableHead class="w-40"><span class="sr-only">Actions</span></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<ContextMenu v-for="row in shown" :key="row.id">
|
||||
<ContextMenuTrigger as-child>
|
||||
<RouterLink :to="{ name: 'workflow', params: { id: row.id } }" class="block w-full rounded-md py-2.5 pr-10 pl-3 text-left transition-colors hover:bg-secondary">
|
||||
<span class="flex items-baseline gap-2">
|
||||
<span class="min-w-0 flex-1 truncate text-label">{{ row.id }}</span>
|
||||
<Badge v-if="store.drafts.some((draft) => draft.id === row.id)" variant="outline">Draft</Badge>
|
||||
<Badge v-if="enabledOf(row.id) === false" variant="secondary">Disabled</Badge>
|
||||
<span v-if="row.avg_tokens" class="font-mono text-caption text-fg-subtle" :title="`${row.avg_tokens.toLocaleString()} tokens per run on average`">{{ compact(row.avg_tokens) }} tok</span>
|
||||
</span>
|
||||
<span class="mt-1.5 flex items-center gap-2 text-caption text-fg-subtle">
|
||||
<span v-if="row.running" class="flex w-20 shrink-0 items-center gap-1.5 text-info">
|
||||
<StatusDot tone="info" live />{{ row.running }} running
|
||||
<TableRow class="cursor-pointer align-middle" @click="open(row.id)">
|
||||
<TableCell class="whitespace-normal">
|
||||
<span class="flex min-w-0 items-center gap-2">
|
||||
<RouterLink :to="{ name: 'workflow', params: { id: row.id } }" class="min-w-0 truncate font-medium hover:underline focus-visible:outline-2 focus-visible:outline-ring" @click.stop>{{ row.id }}</RouterLink>
|
||||
<Badge v-if="row.draft" variant="outline">Draft</Badge>
|
||||
</span>
|
||||
<span v-else-if="row.last_status" class="w-20 shrink-0 truncate" :title="`Latest run: ${statusLabel(row.last_status)}`">{{ statusLabel(row.last_status) }}</span>
|
||||
<span v-else-if="statsKnown" class="shrink-0">Never run</span>
|
||||
<Progress v-if="row.runs" :model-value="Math.round(rate(delivered(row), row.runs) * 100)" :aria-label="`${delivered(row)} of ${row.runs ?? 0} runs delivered`" class="h-1 flex-1" />
|
||||
<span v-if="row.runs" class="w-16 shrink-0 text-right font-mono" aria-hidden="true">{{ delivered(row) }}/{{ row.runs }}</span>
|
||||
</span>
|
||||
</RouterLink>
|
||||
</TableCell>
|
||||
<TableCell class="whitespace-normal">
|
||||
<span v-if="row.trigger.text" class="flex min-w-0 items-center gap-1.5">
|
||||
<span class="truncate">{{ row.trigger.text }}</span>
|
||||
<Badge v-if="row.trigger.more.length" variant="secondary" :title="row.trigger.more.join('\n')">+{{ row.trigger.more.length }}</Badge>
|
||||
</span>
|
||||
<span v-else-if="triggersKnown && !triggersError" class="text-fg-subtle">Manual</span>
|
||||
</TableCell>
|
||||
<TableCell class="tabular-nums">{{ row.steps ?? "–" }}</TableCell>
|
||||
<TableCell>
|
||||
<Switch v-if="enabledOf(row.id) !== undefined" size="sm" :model-value="enabledOf(row.id)" :aria-label="`${row.id} enabled`" @click.stop @update:model-value="setEnabled(row.id, $event)" />
|
||||
</TableCell>
|
||||
<TableCell><WorkflowLastRun :run-id="row.last_run_id" :status="row.last_status" :at="row.last_run_at" :running="row.running" :known="statsKnown" /></TableCell>
|
||||
<TableCell><WorkflowDelivery :counts="row" :runs="row.runs" /><span v-if="!row.runs && statsKnown" class="text-caption text-fg-subtle">No runs</span></TableCell>
|
||||
<TableCell v-if="anyTokens" class="text-right font-mono tabular-nums" :title="row.avg_tokens ? `${row.avg_tokens.toLocaleString()} tokens per run on average` : undefined">{{ tokens(row) }}</TableCell>
|
||||
<TableCell class="text-right">
|
||||
<WorkflowRowActions :id="row.id" :can-run="canRun(row)" :stored="row.stored" @run="run(row.id)" @runs="openRuns(row.id)" @duplicate="copy(row.id)" @remove="deleting = row.id" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</ContextMenuTrigger>
|
||||
<ContextMenuContent v-if="rowActions(row.id).length" class="min-w-40">
|
||||
<ContextMenuItem v-for="action in rowActions(row.id)" :key="action.label" @select="action.run"><component :is="action.icon" />{{ action.label }}</ContextMenuItem>
|
||||
<ContextMenuContent class="min-w-40">
|
||||
<ContextMenuItem v-if="canRun(row)" @select="run(row.id)"><Play />Run</ContextMenuItem>
|
||||
<ContextMenuItem v-if="row.stored" @select="openRuns(row.id)"><ListChecks />Open runs</ContextMenuItem>
|
||||
<ContextMenuItem v-if="row.stored" @select="copy(row.id)"><Copy />Duplicate</ContextMenuItem>
|
||||
<ContextMenuItem variant="destructive" @select="deleting = row.id"><Trash2 />Delete</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
<ul v-else class="flex flex-col gap-2" aria-label="Workflows">
|
||||
<li v-for="row in shown" :key="row.id">
|
||||
<ContextMenu>
|
||||
<ContextMenuTrigger as-child>
|
||||
<Card class="cursor-pointer gap-2.5 px-4 py-3 transition-colors hover:bg-secondary/60" @click="open(row.id)">
|
||||
<div class="flex items-center gap-2">
|
||||
<RouterLink :to="{ name: 'workflow', params: { id: row.id } }" class="min-w-0 truncate text-label font-medium focus-visible:outline-2 focus-visible:outline-ring" @click.stop>{{ row.id }}</RouterLink>
|
||||
<Badge v-if="row.draft" variant="outline">Draft</Badge>
|
||||
<Switch v-if="enabledOf(row.id) !== undefined" size="sm" class="ml-auto" :model-value="enabledOf(row.id)" :aria-label="`${row.id} enabled`" @click.stop @update:model-value="setEnabled(row.id, $event)" />
|
||||
<WorkflowRowActions :id="row.id" :can-run="canRun(row)" :stored="row.stored" @click.stop @run="run(row.id)" @runs="openRuns(row.id)" @duplicate="copy(row.id)" @remove="deleting = row.id" />
|
||||
</div>
|
||||
<p class="flex min-w-0 items-center gap-1.5 text-caption text-fg-muted">
|
||||
<span class="truncate">{{ row.trigger.text || (triggersKnown && !triggersError ? "Manual" : "") }}</span>
|
||||
<Badge v-if="row.trigger.more.length" variant="secondary" :title="row.trigger.more.join('\n')">+{{ row.trigger.more.length }}</Badge>
|
||||
<span v-if="stepsLabel(row)" class="ml-auto shrink-0">{{ stepsLabel(row) }}</span>
|
||||
</p>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<WorkflowLastRun :run-id="row.last_run_id" :status="row.last_status" :at="row.last_run_at" :running="row.running" :known="statsKnown" />
|
||||
<div class="flex flex-col items-end gap-1 text-caption text-fg-muted">
|
||||
<WorkflowDelivery :counts="row" :runs="row.runs" />
|
||||
<span v-if="row.avg_tokens" class="font-mono">{{ tokens(row) }} tok</span>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</ContextMenuTrigger>
|
||||
<ContextMenuContent class="min-w-40">
|
||||
<ContextMenuItem v-if="canRun(row)" @select="run(row.id)"><Play />Run</ContextMenuItem>
|
||||
<ContextMenuItem v-if="row.stored" @select="openRuns(row.id)"><ListChecks />Open runs</ContextMenuItem>
|
||||
<ContextMenuItem v-if="row.stored" @select="copy(row.id)"><Copy />Duplicate</ContextMenuItem>
|
||||
<ContextMenuItem variant="destructive" @select="deleting = row.id"><Trash2 />Delete</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
<!-- MoreMenu renders no element of its own, so the wrapper places it. -->
|
||||
<div v-if="rowActions(row.id).length" class="absolute top-1.5 right-1.5">
|
||||
<MoreMenu :label="`${row.id} actions`">
|
||||
<DropdownMenuItem v-for="action in rowActions(row.id)" :key="action.label" @select="action.run"><component :is="action.icon" />{{ action.label }}</DropdownMenuItem>
|
||||
</MoreMenu>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<AlertDialog :open="!!deleting" @update:open="(value: boolean) => !value && (deleting = '')">
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete the {{ deleting }} workflow?</AlertDialogTitle>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction variant="destructive" @click="confirmRemove">Delete</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -4,7 +4,7 @@ import { toast } from "vue-sonner";
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { keepValue } from "@/lib/keep-unchanged";
|
||||
import { upsertWorkflowDefinition, useWorkflowsStore } from "@/stores/workflows";
|
||||
import { removeWorkflowDefinition, upsertWorkflowDefinition, useWorkflowsStore } from "@/stores/workflows";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
import type { StageStats } from "./WorkflowRuns.vue";
|
||||
import { setWorkflowField } from "./workflow-edit";
|
||||
@@ -51,9 +51,13 @@ export function useWorkflowStats() {
|
||||
useLiveResource("tasks", () => void load(), 5000);
|
||||
onMounted(() => Promise.all([load(), store.load()]));
|
||||
|
||||
const enabledOf = (id: string) => data.value.definitions?.find((d) => d.id === id)?.enabled;
|
||||
// A switch shows the operator's choice at once; the server's answer replaces
|
||||
// it, or the switch falls back when the change is refused.
|
||||
const requested = ref<Record<string, boolean>>({});
|
||||
const enabledOf = (id: string) => requested.value[id] ?? data.value.definitions?.find((d) => d.id === id)?.enabled;
|
||||
|
||||
async function setEnabled(id: string, value: boolean) {
|
||||
requested.value = { ...requested.value, [id]: value };
|
||||
try {
|
||||
await api.workflowEnabled(id, value);
|
||||
toast.success(`${id} ${value ? "enabled" : "disabled"}`);
|
||||
@@ -61,6 +65,10 @@ export function useWorkflowStats() {
|
||||
} catch (err) {
|
||||
const reason = describeError(err, errors.common.unknown);
|
||||
toast.error(value ? errors.workflows.page.notEnabled(id, reason) : errors.workflows.page.notDisabled(id, reason));
|
||||
} finally {
|
||||
const rest = { ...requested.value };
|
||||
delete rest[id];
|
||||
requested.value = rest;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,5 +87,16 @@ export function useWorkflowStats() {
|
||||
return "";
|
||||
}
|
||||
|
||||
return { store, data, error, loading, statsKnown, load, enabledOf, setEnabled, duplicate };
|
||||
/** Deletes a workflow and its draft; true when it is gone. */
|
||||
async function remove(id: string): Promise<boolean> {
|
||||
if (!(await store.save(removeWorkflowDefinition(store.collection, id)))) {
|
||||
toast.error(store.error || errors.workflows.page.saveFailed);
|
||||
return false;
|
||||
}
|
||||
await store.putDraft(id, undefined);
|
||||
toast.success(`${id} deleted`);
|
||||
return true;
|
||||
}
|
||||
|
||||
return { store, data, error, loading, statsKnown, load, enabledOf, setEnabled, duplicate, remove };
|
||||
}
|
||||
@@ -17,6 +17,9 @@ export interface WorkflowStats {
|
||||
last_status?: string;
|
||||
avg_tokens?: number;
|
||||
avg_steps?: number;
|
||||
/** The newest run and when it was created. */
|
||||
last_run_id?: number;
|
||||
last_run_at?: string;
|
||||
origin?: string;
|
||||
}
|
||||
|
||||
@@ -47,6 +50,8 @@ export interface WorkflowRow {
|
||||
last_status?: string;
|
||||
avg_tokens?: number;
|
||||
avg_steps?: number;
|
||||
last_run_id?: number;
|
||||
last_run_at?: string;
|
||||
origin?: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { parse } from "yaml";
|
||||
|
||||
import type { WorkflowRow } from "./workflow-rows";
|
||||
|
||||
/** The steps a definition runs: parallel branches count their own steps, not
|
||||
* the step that fans out. Undefined when the YAML does not parse. */
|
||||
export function stepCount(source: string): number | undefined {
|
||||
let doc: unknown;
|
||||
try {
|
||||
doc = parse(source);
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
const count = (steps: unknown): number =>
|
||||
Array.isArray(steps)
|
||||
? steps.reduce<number>((total, step) => {
|
||||
const branches = step && typeof step === "object" ? (step as { parallel?: Record<string, unknown> }).parallel : undefined;
|
||||
return total + (branches && typeof branches === "object" ? Object.values(branches).reduce<number>((n, branch) => n + count(branch), 0) : 1);
|
||||
}, 0)
|
||||
: 0;
|
||||
return doc && typeof doc === "object" ? count((doc as { steps?: unknown }).steps) : undefined;
|
||||
}
|
||||
|
||||
/** Running workflows first, then by how recently they ran, then those that
|
||||
* never ran by name: what is happening or just happened is what an operator
|
||||
* opens this page to find. */
|
||||
export function byActivity(a: WorkflowRow, b: WorkflowRow): number {
|
||||
const live = (b.running ? 1 : 0) - (a.running ? 1 : 0);
|
||||
if (live) return live;
|
||||
const recent = (b.last_run_at ? Date.parse(b.last_run_at) : 0) - (a.last_run_at ? Date.parse(a.last_run_at) : 0);
|
||||
return recent || a.id.localeCompare(b.id);
|
||||
}
|
||||
@@ -98,15 +98,30 @@ const ROUTES = "intake-routes";
|
||||
|
||||
const STARTED_VIA: Record<string, string> = { call: "calls it", handoff: "hands off to it", approve: "runs it once approved" };
|
||||
|
||||
/** The triggers of the workflow named id, from the routes and definitions the
|
||||
* control plane serves, the stored playbooks, and the event bindings. */
|
||||
export function useWorkflowTriggers(id: Ref<string>, startedBy: Readonly<Ref<{ workflow: string; via: string }[]>>) {
|
||||
/** What starts the workflow, in a line: the first trigger, and how many more. */
|
||||
export function triggerSummary(triggers: WorkflowTrigger[]): { text: string; more: string[] } {
|
||||
const words = (t: WorkflowTrigger) => {
|
||||
switch (t.kind) {
|
||||
case "workflow": return `From ${t.label}`;
|
||||
case "schedule": return `Schedule ${t.label}`;
|
||||
case "playbook": return t.detail ? `${t.label}: ${t.detail}` : t.label;
|
||||
default: return t.label;
|
||||
}
|
||||
};
|
||||
const [first, ...rest] = triggers;
|
||||
return { text: first ? words(first) : "", more: rest.map(words) };
|
||||
}
|
||||
|
||||
/** Every trigger source the control plane serves, read once, so a list of
|
||||
* workflows asks for them once rather than per row. */
|
||||
export function useTriggerSources(startedByOf: (id: string) => { workflow: string; via: string }[]) {
|
||||
const store = useSettingsStore();
|
||||
const bindings = ref<TriggerSources["bindings"]>([]);
|
||||
const schedules = ref<TriggerSources["schedules"]>([]);
|
||||
// A failed read is an error, not an empty trigger list: "Manual runs only"
|
||||
// would be a lie while the server is unreachable.
|
||||
const error = ref("");
|
||||
const known = ref(false);
|
||||
async function reload(): Promise<void> {
|
||||
let readError = "";
|
||||
const [response, listed] = await Promise.all([
|
||||
@@ -121,16 +136,23 @@ export function useWorkflowTriggers(id: Ref<string>, startedBy: Readonly<Ref<{ w
|
||||
if (response) bindings.value = response.bindings ?? [];
|
||||
if (listed) schedules.value = listed.schedules ?? [];
|
||||
error.value = response === null || listed === null ? readError || errors.workflows.triggers.notLoaded : "";
|
||||
known.value = known.value || (response !== null && listed !== null);
|
||||
}
|
||||
onMounted(reload);
|
||||
const triggers = computed(() =>
|
||||
triggersFor(id.value, {
|
||||
const triggersOf = (id: string): WorkflowTrigger[] =>
|
||||
triggersFor(id, {
|
||||
routes: (store.stateFor(ROUTES).resource?.value as TriggerSources["routes"] | undefined) ?? { rules: [], default: "" },
|
||||
bindings: bindings.value,
|
||||
playbooks: (store.stateFor("eda-playbooks").resource?.value as { playbooks?: TriggerSources["playbooks"] } | undefined)?.playbooks ?? [],
|
||||
startedBy: startedBy.value,
|
||||
startedBy: startedByOf(id),
|
||||
schedules: schedules.value,
|
||||
}),
|
||||
);
|
||||
});
|
||||
return { triggersOf, reload, error, known };
|
||||
}
|
||||
|
||||
/** The triggers of the workflow named id. */
|
||||
export function useWorkflowTriggers(id: Ref<string>, startedBy: Readonly<Ref<{ workflow: string; via: string }[]>>) {
|
||||
const { triggersOf, reload, error } = useTriggerSources(() => startedBy.value);
|
||||
const triggers = computed(() => triggersOf(id.value));
|
||||
return { triggers, reload, error };
|
||||
}
|
||||
Reference in new issue
Block a user