120 lines
5.4 KiB
Vue
120 lines
5.4 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 { Textarea } from "@/components/ui/textarea";
|
|
import { computed, ref, onMounted } from "vue";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
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 { SEEDED_AGENT_ID, 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.
|
|
const seededAgentId: string = SEEDED_AGENT_ID;
|
|
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");
|
|
} 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");
|
|
</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') || (agents.some((agent) => agent.id === seededAgentId) ? seededAgentId : '')"
|
|
: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-caption 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>
|
|
</div>
|
|
|
|
<section class="space-y-1.5">
|
|
<Label for="workflow-instructions" class="text-caption 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>
|