Inline error paragraphs become destructive Alerts, divided record lists become Item rows, the redirect URI box uses CodeView, and icon-button title hints use Tooltip. Native titles remain on truncated values and on disabled controls.
148 lines
6.8 KiB
Vue
148 lines
6.8 KiB
Vue
<script setup lang="ts">
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
import { Label } from "@/components/ui/label";
|
|
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
import { computed, ref, onMounted } from "vue";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { Switch } from "@/components/ui/switch";
|
|
import { api } from "@/lib/api";
|
|
import type { Identity } from "@/stores/org";
|
|
import { useOrgStore } from "@/stores/org";
|
|
import { useSettingsStore } from "@/stores/settings";
|
|
import OptionSelect from "./OptionSelect.vue";
|
|
import SpecList from "./SpecList.vue";
|
|
import { setWorkflowField, workflowField } from "./workflow-edit";
|
|
|
|
const props = defineProps<{ yaml: string }>();
|
|
const emit = defineEmits<{ "update:yaml": [string] }>();
|
|
|
|
const text = (key: string) => {
|
|
const value = workflowField(props.yaml, key);
|
|
return typeof value === "string" ? value : "";
|
|
};
|
|
function set(key: string, value: unknown): void {
|
|
emit("update:yaml", setWorkflowField(props.yaml, key, value));
|
|
}
|
|
|
|
// The identity a run acts as must be an agent, never a person; a workflow
|
|
// naming none is refused when it runs, so it defaults to the agent identity
|
|
// every install seeds (identity.AgentID).
|
|
const SEEDED_AGENT_ID = "6f129e29-0e26-5246-99bd-74cb4496203b";
|
|
const identities = useOrgStore();
|
|
const agents = ref<Identity[]>([]);
|
|
const identitiesLoading = ref(true);
|
|
const identitiesError = ref("");
|
|
async function loadAgents(): Promise<void> {
|
|
identitiesLoading.value = true;
|
|
identitiesError.value = "";
|
|
agents.value = [];
|
|
try {
|
|
await identities.loadOrg();
|
|
const response = await api.orgAgents<{ agents: Identity[] }>(identities.homeOrg);
|
|
agents.value = response.agents.filter((agent) => agent.lifecycle === "active");
|
|
if (!text("identity") && agents.value.some((agent) => agent.id === SEEDED_AGENT_ID)) set("identity", SEEDED_AGENT_ID);
|
|
} catch (cause) {
|
|
identitiesError.value = String((cause as Error).message || cause);
|
|
} finally { identitiesLoading.value = false; }
|
|
}
|
|
onMounted(loadAgents);
|
|
const identityOptions = computed(() => {
|
|
const current = text("identity");
|
|
const options = agents.value.map((agent) => ({ value: agent.id, label: agent.display_name }));
|
|
return current && !identitiesLoading.value && !agents.value.some((agent) => agent.id === current) ? [{ value: current, label: `${current} (unknown)`, disabled: true }, ...options] : options;
|
|
});
|
|
|
|
const settings = useSettingsStore();
|
|
const profileOptions = computed(() => {
|
|
const names = Object.keys((settings.stateFor("agent-profiles").resource?.value ?? {}) as Record<string, unknown>).sort();
|
|
const current = text("profile");
|
|
if (current && !names.includes(current)) names.unshift(current);
|
|
return [{ value: "", label: "Default" }, ...names.map((name) => ({ value: name, label: name }))];
|
|
});
|
|
|
|
const MODES = [
|
|
{ value: "required", label: "Repository", hint: "Clones the task's repository" },
|
|
{ value: "optional", label: "If given", hint: "Clones one when the run names it" },
|
|
{ value: "none", label: "None", hint: "Scratch workspace, no clone" },
|
|
];
|
|
const repository = computed(() => text("repository") || "required");
|
|
|
|
// needs is the workflow's declared harness requirements: captures (a stage
|
|
// returns structured output through capture tools) and the largest gate-retry
|
|
// budget any stage declares.
|
|
const needs = computed<{ captures?: boolean; gate_retries?: number }>(() => {
|
|
const value = workflowField(props.yaml, "needs");
|
|
return value && typeof value === "object" ? (value as { captures?: boolean; gate_retries?: number }) : {};
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div class="space-y-4 px-3 py-3">
|
|
<div class="divide-y divide-border rounded-md border border-border">
|
|
<Label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
|
|
<span class="flex-1 text-label">Runs as</span>
|
|
<OptionSelect
|
|
:key="String(identitiesLoading)"
|
|
:model-value="text('identity')"
|
|
:options="identityOptions"
|
|
aria-label="Execution identity"
|
|
:placeholder="identitiesLoading ? 'Loading agents…' : 'Choose an agent'"
|
|
:disabled="identitiesLoading || !!identitiesError"
|
|
class="w-44"
|
|
@update:model-value="set('identity', $event)"
|
|
/>
|
|
</Label>
|
|
<Alert v-if="identitiesError" variant="destructive" class="m-3"><AlertDescription>{{ identitiesError }} <Button variant="link" size="xs" @click="loadAgents">Retry</Button></AlertDescription></Alert>
|
|
<p v-else-if="!identitiesLoading && !agents.length" class="px-3 py-2 text-xs text-fg-subtle">No active agents in your organisation.</p>
|
|
<Label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
|
|
<span class="flex-1 text-label">Container profile</span>
|
|
<OptionSelect :model-value="text('profile')" :options="profileOptions" aria-label="Container profile" class="w-44" @update:model-value="set('profile', $event || undefined)" />
|
|
</Label>
|
|
<div class="flex min-h-10 items-center gap-3 px-3 py-1.5">
|
|
<span class="flex-1 text-label">Works on</span>
|
|
<ToggleGroup
|
|
type="single"
|
|
variant="outline"
|
|
size="sm"
|
|
:model-value="repository"
|
|
aria-label="Works on"
|
|
@update:model-value="(value) => { if (value) set('repository', value === 'required' ? undefined : String(value)); }"
|
|
>
|
|
<ToggleGroupItem v-for="mode in MODES" :key="mode.value" :value="mode.value" :title="mode.hint">{{ mode.label }}</ToggleGroupItem>
|
|
</ToggleGroup>
|
|
</div>
|
|
<Label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
|
|
<span class="flex-1 text-label" title="Stages return structured output through capture tools">Captures</span>
|
|
<Switch :model-value="needs.captures === true" @update:model-value="set('needs', { ...needs, captures: $event || undefined })" />
|
|
</Label>
|
|
<Label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
|
|
<span class="flex-1 text-label">Gate retries</span>
|
|
<Input
|
|
type="number"
|
|
min="0"
|
|
placeholder="0"
|
|
class="h-8 w-20 text-right text-label"
|
|
:model-value="needs.gate_retries ?? ''"
|
|
@update:model-value="(value) => set('needs', { ...needs, gate_retries: String(value) === '' ? undefined : Number(String(value)) })"
|
|
/>
|
|
</Label>
|
|
</div>
|
|
|
|
<section class="space-y-1.5">
|
|
<Label for="workflow-instructions" class="text-xs font-medium text-fg-muted">Instructions</Label>
|
|
<Textarea
|
|
id="workflow-instructions"
|
|
:model-value="text('instructions')"
|
|
:rows="4"
|
|
class="font-mono text-label"
|
|
@change="set('instructions', ($event.target as HTMLTextAreaElement).value)"
|
|
/>
|
|
</section>
|
|
|
|
<SpecList :yaml="yaml" field="outputs" @update:yaml="emit('update:yaml', $event)" />
|
|
</div>
|
|
</template>
|