Merge branch 'main' into feat/1861-task-context-picker
This commit is contained in:
commit
1730938e03
7 files changed
+311
-8
No files matched your search
+1
-1
@@ -96,7 +96,7 @@ watch(() => accounts.status?.user, (user) => {
|
||||
<SidebarProvider class="bg-[var(--workspace)]">
|
||||
<a href="#main-content" class="sr-only focus:not-sr-only focus:fixed focus:top-2 focus:left-4 focus:z-[60] focus:rounded-md focus:bg-card focus:px-3 focus:py-2">Skip to main content</a>
|
||||
<AppSidebar :hidden="hidden" />
|
||||
<SidebarInset class="min-w-0 bg-[var(--workspace)]" :class="workflowsPage && 'max-md:h-dvh'">
|
||||
<SidebarInset class="min-w-0 bg-[var(--workspace)] md:ml-[var(--chat-pin-l,0px)] md:mr-[var(--chat-pin-r,0px)]" :class="workflowsPage && 'max-md:h-dvh'">
|
||||
<header class="bg-card border-border-strong sticky top-0 z-30 flex h-14 shrink-0 items-center gap-2 border-b px-3 shadow-[var(--shadow-sm)] sm:px-4">
|
||||
<SidebarTrigger class="-ml-1 md:hidden" />
|
||||
<Brand />
|
||||
|
||||
+144
-5
@@ -1,9 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { ChevronDown, ChevronUp } from "@lucide/vue";
|
||||
import { nextTick, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
import { useMediaQuery, useStorage, useWindowSize } from "@vueuse/core";
|
||||
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
import ChatBar from "./ChatBar.vue";
|
||||
import ChatComposer from "./ChatComposer.vue";
|
||||
import ChatTranscript from "./ChatTranscript.vue";
|
||||
@@ -19,6 +21,11 @@ import { composerText, escapeOwnedByLayer, isSending, useChat } from "./state";
|
||||
* the conversation opens above it. Hiding the conversation leaves the bar. It is
|
||||
* deliberately not a modal: no scrim, no scroll lock, no focus trap.
|
||||
*
|
||||
* On a desktop-width screen the expanded conversation can be pinned to the left
|
||||
* or right edge, where the page reflows beside it instead of sitting under it.
|
||||
* Dragging the header to an edge pins it; dragging it away, or double-clicking
|
||||
* the header, unpins it. The side and width are remembered per browser.
|
||||
*
|
||||
* It stays mounted, so the session and any turn in flight survive a navigation.
|
||||
* It is mounted outside the app shell: `.shell`'s backdrop-filter makes it a
|
||||
* containing block for `position: fixed`, so a bar nested inside would anchor to
|
||||
@@ -27,6 +34,21 @@ import { composerText, escapeOwnedByLayer, isSending, useChat } from "./state";
|
||||
useChat();
|
||||
|
||||
const expanded = ref(false);
|
||||
const MIN_WIDTH = 320;
|
||||
const EDGE = 64;
|
||||
type Side = "left" | "right";
|
||||
const saved = useStorage<{ side: Side | null; width: number }>(
|
||||
"archie.chat.dock",
|
||||
{ side: null, width: 420 },
|
||||
localStorage,
|
||||
{ mergeDefaults: true },
|
||||
);
|
||||
const desktop = useMediaQuery("(min-width: 768px)");
|
||||
const { width: viewport } = useWindowSize();
|
||||
const width = computed(() =>
|
||||
Math.round(Math.min(Math.max(saved.value.width, MIN_WIDTH), Math.max(MIN_WIDTH, Math.min(720, viewport.value - 480)))),
|
||||
);
|
||||
const side = computed(() => (desktop.value && expanded.value ? saved.value.side : null));
|
||||
const composer = ref<InstanceType<typeof ChatComposer> | null>(null);
|
||||
|
||||
// Nothing outside the dock closes it: every navigation control is outside it,
|
||||
@@ -72,6 +94,81 @@ onUnmounted(() => {
|
||||
document.documentElement.style.removeProperty("--chat-dock-clear");
|
||||
});
|
||||
|
||||
// The page makes room for a pinned dock through these two variables.
|
||||
watch([side, width], ([s, w]) => {
|
||||
const root = document.documentElement.style;
|
||||
root.setProperty("--chat-pin-l", s === "left" ? `${w}px` : "0px");
|
||||
root.setProperty("--chat-pin-r", s === "right" ? `${w}px` : "0px");
|
||||
}, { immediate: true });
|
||||
onUnmounted(() => {
|
||||
document.documentElement.style.removeProperty("--chat-pin-l");
|
||||
document.documentElement.style.removeProperty("--chat-pin-r");
|
||||
});
|
||||
|
||||
function edgeAt(x: number): Side | null {
|
||||
if (x <= EDGE) return "left";
|
||||
if (x >= window.innerWidth - EDGE) return "right";
|
||||
return null;
|
||||
}
|
||||
|
||||
// Pointer travel before a press on the header becomes a drag, so a click or a
|
||||
// double-click on it never moves the dock.
|
||||
const DRAG_START = 4;
|
||||
const offset = ref<{ x: number; y: number } | null>(null);
|
||||
const target = ref<Side | null>(null);
|
||||
function startDrag(event: PointerEvent): void {
|
||||
if (!desktop.value || event.button !== 0) return;
|
||||
if ((event.target as HTMLElement).closest("button, a, input, select, textarea, [role=combobox]")) return;
|
||||
const grip = event.currentTarget as HTMLElement;
|
||||
const { clientX: x0, clientY: y0 } = event;
|
||||
grip.setPointerCapture(event.pointerId);
|
||||
const move = (e: PointerEvent): void => {
|
||||
const dx = e.clientX - x0;
|
||||
const dy = e.clientY - y0;
|
||||
if (!offset.value && Math.hypot(dx, dy) < DRAG_START) return;
|
||||
offset.value = { x: dx, y: dy };
|
||||
target.value = edgeAt(e.clientX);
|
||||
};
|
||||
const end = (e: PointerEvent): void => {
|
||||
grip.removeEventListener("pointermove", move);
|
||||
grip.removeEventListener("pointerup", end);
|
||||
grip.removeEventListener("pointercancel", end);
|
||||
if (offset.value && e.type === "pointerup") saved.value.side = edgeAt(e.clientX);
|
||||
offset.value = null;
|
||||
target.value = null;
|
||||
};
|
||||
grip.addEventListener("pointermove", move);
|
||||
grip.addEventListener("pointerup", end);
|
||||
grip.addEventListener("pointercancel", end);
|
||||
}
|
||||
function togglePin(event: MouseEvent): void {
|
||||
if (!desktop.value || (event.target as HTMLElement).closest("button, a, input, select, textarea, [role=combobox]")) return;
|
||||
saved.value.side = saved.value.side ? null : "right";
|
||||
}
|
||||
|
||||
function resize(event: PointerEvent): void {
|
||||
const handle = event.currentTarget as HTMLElement;
|
||||
handle.setPointerCapture(event.pointerId);
|
||||
const move = (e: PointerEvent): void => {
|
||||
saved.value.width = side.value === "right" ? window.innerWidth - e.clientX : e.clientX;
|
||||
};
|
||||
const end = (): void => {
|
||||
handle.removeEventListener("pointermove", move);
|
||||
handle.removeEventListener("pointerup", end);
|
||||
handle.removeEventListener("pointercancel", end);
|
||||
};
|
||||
handle.addEventListener("pointermove", move);
|
||||
handle.addEventListener("pointerup", end);
|
||||
handle.addEventListener("pointercancel", end);
|
||||
}
|
||||
function resizeByKey(event: KeyboardEvent): void {
|
||||
const grow = event.key === (side.value === "right" ? "ArrowLeft" : "ArrowRight");
|
||||
const shrink = event.key === (side.value === "right" ? "ArrowRight" : "ArrowLeft");
|
||||
if (!grow && !shrink) return;
|
||||
event.preventDefault();
|
||||
saved.value.width = width.value + (grow ? 16 : -16);
|
||||
}
|
||||
|
||||
function usePrompt(text: string): void {
|
||||
composerText.value = text;
|
||||
composer.value?.focus();
|
||||
@@ -79,13 +176,54 @@ function usePrompt(text: string): void {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="pointer-events-none fixed inset-x-0 bottom-4 z-40 flex justify-center px-3 max-md:bottom-2">
|
||||
<div
|
||||
v-if="target"
|
||||
aria-hidden="true"
|
||||
:class="cn('pointer-events-none fixed inset-y-0 z-40 border-primary/40 bg-primary/10', target === 'left' ? 'left-0 border-r-2' : 'right-0 border-l-2')"
|
||||
:style="{ width: `${width}px` }"
|
||||
/>
|
||||
<div
|
||||
:class="cn(
|
||||
'pointer-events-none fixed z-40',
|
||||
side ? cn('inset-y-0', side === 'left' ? 'left-0' : 'right-0') : 'inset-x-0 bottom-4 flex justify-center px-3 max-md:bottom-2',
|
||||
)"
|
||||
:style="side ? { width: `${width}px` } : undefined"
|
||||
>
|
||||
<aside
|
||||
ref="dock"
|
||||
aria-label="Chat with Archie"
|
||||
class="pointer-events-auto flex w-full max-w-xl flex-col rounded-lg border border-border-strong bg-popover shadow-[var(--shadow-md)]"
|
||||
:class="cn(
|
||||
'pointer-events-auto relative flex flex-col border-border-strong bg-popover shadow-[var(--shadow-md)]',
|
||||
side
|
||||
? cn('h-full w-full', side === 'left' ? 'border-r' : 'border-l')
|
||||
: 'w-full max-w-xl rounded-lg border',
|
||||
offset && 'z-50 opacity-90',
|
||||
)"
|
||||
:style="offset ? { transform: `translate(${offset.x}px, ${offset.y}px)` } : undefined"
|
||||
>
|
||||
<ChatBar v-if="expanded">
|
||||
<div
|
||||
v-if="side"
|
||||
role="separator"
|
||||
aria-orientation="vertical"
|
||||
aria-label="Resize chat"
|
||||
tabindex="0"
|
||||
:aria-valuenow="width"
|
||||
:aria-valuemin="MIN_WIDTH"
|
||||
class="absolute inset-y-0 z-10 w-1.5 cursor-col-resize hover:bg-primary/30 focus-visible:bg-primary/30 focus-visible:outline-none"
|
||||
:class="side === 'left' ? '-right-0.5' : '-left-0.5'"
|
||||
@pointerdown.prevent="resize"
|
||||
@keydown="resizeByKey"
|
||||
/>
|
||||
<div
|
||||
v-if="expanded"
|
||||
:class="desktop && 'cursor-grab select-none active:cursor-grabbing'"
|
||||
@pointerdown="startDrag"
|
||||
@dblclick="togglePin"
|
||||
>
|
||||
<div v-if="desktop" class="flex justify-center pt-1.5" aria-hidden="true">
|
||||
<span class="h-1 w-8 rounded-full bg-border-strong" />
|
||||
</div>
|
||||
<ChatBar>
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<Button
|
||||
@@ -101,7 +239,8 @@ function usePrompt(text: string): void {
|
||||
<TooltipContent>Hide conversation</TooltipContent>
|
||||
</Tooltip>
|
||||
</ChatBar>
|
||||
<div v-if="expanded" class="flex h-[min(28rem,55dvh)] min-h-0 flex-col">
|
||||
</div>
|
||||
<div v-if="expanded" :class="cn('flex min-h-0 flex-col', side ? 'flex-1' : 'h-[min(28rem,55dvh)]')">
|
||||
<ChatTranscript @prompt="usePrompt" />
|
||||
</div>
|
||||
<div @focusin="expanded = true">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import ChatTaskRef from "./ChatTaskRef.vue";
|
||||
import type { ChatInline } from "./markdown";
|
||||
|
||||
/** One inline run: the spans of a paragraph, a heading or a table cell. */
|
||||
@@ -29,6 +30,7 @@ defineProps<{ inline: ChatInline[] }>();
|
||||
class="text-link underline-offset-4 hover:underline"
|
||||
>{{ span.text }}</a
|
||||
>
|
||||
<ChatTaskRef v-else-if="span.kind === 'taskref'" :id="span.id" />
|
||||
<em v-else-if="span.kind === 'em'">{{ span.text }}</em>
|
||||
<template v-else>{{ span.text }}</template>
|
||||
</template>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import {
|
||||
Copy,
|
||||
Ellipsis,
|
||||
GitBranch,
|
||||
Pencil,
|
||||
@@ -9,6 +10,7 @@ import {
|
||||
Undo2,
|
||||
} from "@lucide/vue";
|
||||
import { ref } from "vue";
|
||||
import { toast } from "vue-sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
@@ -28,6 +30,7 @@ import { Input } from "@/components/ui/input";
|
||||
import ChatSettings from "./ChatSettings.vue";
|
||||
import {
|
||||
currentSession,
|
||||
messages,
|
||||
runSessionCommand,
|
||||
useEscapeLayer,
|
||||
} from "./state";
|
||||
@@ -51,6 +54,31 @@ function run(command: string): void {
|
||||
void runSessionCommand(command);
|
||||
}
|
||||
|
||||
// Reply text is already Markdown, so the transcript is the messages under a
|
||||
// heading per speaker. Empty turns (tool-only replies) have nothing to paste.
|
||||
async function copyMarkdown(): Promise<void> {
|
||||
open.value = false;
|
||||
const text = messages.value
|
||||
.map((m) => {
|
||||
const body = (m.text ?? m.Text ?? "").trim();
|
||||
if (!body) return "";
|
||||
return `### ${(m.from ?? m.From) === "web" ? "You" : "Archie"}\n\n${body}`;
|
||||
})
|
||||
.filter(Boolean)
|
||||
.join("\n\n");
|
||||
if (!text) {
|
||||
toast.error("Nothing to copy");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
} catch (err) {
|
||||
toast.error(`Not copied: ${(err as Error).message || "clipboard unavailable"}`);
|
||||
return;
|
||||
}
|
||||
toast.success("Copied as Markdown");
|
||||
}
|
||||
|
||||
// Rename and branch ask for a value in a labelled dialog, not window.prompt.
|
||||
const promptOpen = ref(false);
|
||||
const promptCommand = ref("");
|
||||
@@ -124,6 +152,13 @@ function submitPrompt(): void {
|
||||
@click="run('/compress --preview')"
|
||||
><Shrink data-icon="inline-start" />Preview compression</Button
|
||||
>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="justify-start"
|
||||
@click="copyMarkdown"
|
||||
><Copy data-icon="inline-start" />Copy as Markdown</Button
|
||||
>
|
||||
<Separator class="my-1" />
|
||||
</template>
|
||||
<ChatSettings />
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, ref, watch } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
|
||||
import { revealTaskRow, taskExists } from "./task-ref";
|
||||
|
||||
/**
|
||||
* A #N in a reply. It becomes a link only once the tasks API confirms the
|
||||
* task exists, so an issue number or a stray count stays plain text. On the
|
||||
* Tasks page, where the row is already listed, it scrolls there instead of
|
||||
* leaving the page.
|
||||
*/
|
||||
const props = defineProps<{ id: number }>();
|
||||
|
||||
const route = useRoute();
|
||||
const exists = ref(false);
|
||||
|
||||
// A streaming reply shows #1 before #12; the short wait skips the partial one.
|
||||
let timer = 0;
|
||||
watch(
|
||||
() => props.id,
|
||||
(id) => {
|
||||
exists.value = false;
|
||||
window.clearTimeout(timer);
|
||||
timer = window.setTimeout(async () => {
|
||||
const found = await taskExists(id);
|
||||
if (id === props.id) exists.value = found === true;
|
||||
}, 250);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
onBeforeUnmount(() => window.clearTimeout(timer));
|
||||
|
||||
function onClick(event: MouseEvent, navigate: (e: MouseEvent) => void) {
|
||||
if (route.path === "/tasks" && revealTaskRow(props.id)) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
navigate(event);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RouterLink
|
||||
v-if="exists"
|
||||
v-slot="{ href, navigate }"
|
||||
:to="`/tasks/${id}`"
|
||||
custom
|
||||
>
|
||||
<a
|
||||
:href="href"
|
||||
:title="`Task ${id}`"
|
||||
class="rounded bg-primary-soft px-1 py-0.5 font-mono text-[0.9em] text-link hover:underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
|
||||
@click="onClick($event, navigate)"
|
||||
>#{{ id }}</a
|
||||
>
|
||||
</RouterLink>
|
||||
<template v-else>#{{ id }}</template>
|
||||
</template>
|
||||
+20
-2
@@ -15,6 +15,7 @@ export type ChatInline =
|
||||
| { kind: "del"; text: string }
|
||||
| { kind: "code"; text: string }
|
||||
| { kind: "link"; text: string; href: string }
|
||||
| { kind: "taskref"; id: number }
|
||||
| { kind: "image"; alt: string; src: string };
|
||||
|
||||
/** One block of the document. Lists carry their items as inline runs. */
|
||||
@@ -27,6 +28,23 @@ export type ChatBlock =
|
||||
const INLINE =
|
||||
/(!\[[^\]]*\]\((?:https?:\/\/[^\s)]+|data:image\/[^\s)]+|\/[^\s)]+)\)|~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\((?:https?:\/\/[^\s)]+|\/[^\s)]+)\)|\*[^*]+\*|_[^_]+_)/g;
|
||||
|
||||
// A #N the model wrote about a task. Not part of a word, entity or path.
|
||||
const TASK_REF = /(?<![\w&#/])#(\d{1,9})(?!\w)/g;
|
||||
|
||||
// plainText splits a run of plain text around its task references.
|
||||
function plainText(text: string): ChatInline[] {
|
||||
const out: ChatInline[] = [];
|
||||
let cursor = 0;
|
||||
for (const match of text.matchAll(TASK_REF)) {
|
||||
if (match.index > cursor)
|
||||
out.push({ kind: "text", text: text.slice(cursor, match.index) });
|
||||
out.push({ kind: "taskref", id: Number(match[1]) });
|
||||
cursor = match.index + match[0].length;
|
||||
}
|
||||
if (cursor < text.length) out.push({ kind: "text", text: text.slice(cursor) });
|
||||
return out;
|
||||
}
|
||||
|
||||
// inlineMarkdown returns the children of one line: plain text and the element
|
||||
// each matched span becomes, in order.
|
||||
function inlineMarkdown(text: string): ChatInline[] {
|
||||
@@ -34,7 +52,7 @@ function inlineMarkdown(text: string): ChatInline[] {
|
||||
let cursor = 0;
|
||||
for (const match of String(text).matchAll(INLINE)) {
|
||||
if (match.index > cursor)
|
||||
children.push({ kind: "text", text: text.slice(cursor, match.index) });
|
||||
children.push(...plainText(text.slice(cursor, match.index)));
|
||||
const value = match[0];
|
||||
if (value.startsWith("![")) {
|
||||
const img = value.match(/^!\[([^\]]*)\]\((.+)\)$/);
|
||||
@@ -57,7 +75,7 @@ function inlineMarkdown(text: string): ChatInline[] {
|
||||
cursor = match.index + value.length;
|
||||
}
|
||||
if (cursor < text.length)
|
||||
children.push({ kind: "text", text: text.slice(cursor) });
|
||||
children.push(...plainText(text.slice(cursor)));
|
||||
return children;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { api, ApiError } from "@/lib/api";
|
||||
|
||||
const FOUND_TTL_MS = 10 * 60_000;
|
||||
const MISSING_TTL_MS = 30_000;
|
||||
|
||||
const lookups = new Map<number, { at: number; found: boolean }>();
|
||||
const inflight = new Map<number, Promise<boolean | null>>();
|
||||
|
||||
/**
|
||||
* Whether task `id` exists, asked of the tasks API. Answers are kept briefly
|
||||
* so a reply that re-renders every frame asks once. A task that was missing a
|
||||
* moment ago may have been created since, so that answer expires quickly. A
|
||||
* failed lookup is null and is not kept: the reference stays plain text.
|
||||
*/
|
||||
export function taskExists(id: number): Promise<boolean | null> {
|
||||
const known = lookups.get(id);
|
||||
if (known && Date.now() - known.at < (known.found ? FOUND_TTL_MS : MISSING_TTL_MS))
|
||||
return Promise.resolve(known.found);
|
||||
let pending = inflight.get(id);
|
||||
if (!pending) {
|
||||
pending = api
|
||||
.task(String(id))
|
||||
.then(() => true)
|
||||
.catch((err) => (err instanceof ApiError && err.status === 404 ? false : null))
|
||||
.then((found) => {
|
||||
if (found !== null) lookups.set(id, { at: Date.now(), found });
|
||||
inflight.delete(id);
|
||||
return found;
|
||||
});
|
||||
inflight.set(id, pending);
|
||||
}
|
||||
return pending;
|
||||
}
|
||||
|
||||
const HIGHLIGHT = ["bg-primary-soft", "motion-safe:transition-colors", "motion-safe:duration-700"];
|
||||
|
||||
/**
|
||||
* Scrolls to task `id`'s row when the page lists it and marks it once.
|
||||
* Returns false when no such row is on screen.
|
||||
*/
|
||||
export function revealTaskRow(id: number): boolean {
|
||||
const row = document.querySelector<HTMLElement>(`tr[data-row-key="${id}"]`);
|
||||
if (!row) return false;
|
||||
const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||
row.scrollIntoView({ block: "center", behavior: still ? "auto" : "smooth" });
|
||||
row.classList.add(...HIGHLIGHT);
|
||||
window.setTimeout(() => row.classList.remove("bg-primary-soft"), 1600);
|
||||
window.setTimeout(() => row.classList.remove(...HIGHLIGHT), 2400);
|
||||
return true;
|
||||
}
|
||||
Reference in new issue
Block a user