Files
archie/ui/src/workflows/ArchieBuilder.vue
T

71 lines
2.8 KiB
Vue

<script setup lang="ts">
import { computed, onBeforeUnmount, ref, watch } from "vue";
import { ChevronDown, ChevronUp, MessageCirclePlus, Sparkles } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { channelID, workflowChannel } from "@/chat/channel";
import ChatComposer from "@/chat/ChatComposer.vue";
import ChatSessionList from "@/chat/ChatSessionList.vue";
import ChatTranscript from "@/chat/ChatTranscript.vue";
import { bindChannel, isSending, messages, newChat, setTurnHooks, streamingTurn } from "@/chat/state";
/**
* Archie edits the workflow with the operator, on the same conversation system
* as the chat panel. Each workflow has its own conversation, so it opens on that
* workflow's history rather than on whatever the operator last asked the panel.
* Archie writes the draft; the operator keeps or reverts each change in the
* draft review and publishes.
*/
const props = defineProps<{ workflow: string; beforeSend: () => Promise<void> }>();
const emit = defineEmits<{ proposed: []; working: [boolean] }>();
const expanded = ref(false);
const hasConversation = computed(() => messages.value.length > 0 || !!streamingTurn.value);
watch(
() => props.workflow,
(workflow) => bindChannel(workflowChannel(workflow)),
{ immediate: true },
);
// Archie works from the saved draft, so pending edits are written first; it may
// have written the draft even on a turn that failed later, so it is read after
// every turn.
setTurnHooks({ before: () => props.beforeSend(), after: () => emit("proposed") });
watch(isSending, (value) => {
emit("working", value);
if (value) expanded.value = true;
});
onBeforeUnmount(() => {
setTurnHooks({});
bindChannel(channelID());
});
</script>
<template>
<div class="pointer-events-auto flex w-full max-w-xl flex-col rounded-lg border border-border bg-popover shadow-[var(--shadow-md)]">
<div v-if="hasConversation" class="flex items-center gap-1 border-b px-3 py-2">
<Sparkles class="size-4 shrink-0 text-primary" aria-hidden="true" />
<ChatSessionList />
<Button variant="ghost" size="icon-sm" class="flex-none" title="New chat" aria-label="New chat" @click="newChat">
<MessageCirclePlus />
</Button>
<Button
variant="ghost"
size="icon-sm"
class="flex-none"
:aria-label="expanded ? 'Hide conversation' : 'Show conversation'"
:title="expanded ? 'Hide conversation' : 'Show conversation'"
:aria-expanded="expanded"
@click="expanded = !expanded"
>
<ChevronDown v-if="expanded" />
<ChevronUp v-else />
</Button>
</div>
<div v-if="hasConversation && expanded" class="flex h-[min(20rem,40vh)] min-h-0 flex-col">
<ChatTranscript />
</div>
<ChatComposer :open="false" placeholder="Build with Archie" :class="!hasConversation && 'border-t-0!'" />
</div>
</template>