feat(workflow): render a PRD's generated view on the plan approval card
agent.run gains views: the agent may return an OpenUI Lang view of its answer through an optional view tool, read as steps.<id>.view. human.approve stores it as the task's plan_view, and the approval card renders it with the dashboard's own components, falling back to the plan text when there is no view or it does not parse. The feasibility prd step uses it.
This commit is contained in:
1 parent
cae19ca42e
commit
54a78175b4
34 files changed
+1035
-153
No files matched your search
@@ -0,0 +1,42 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { createParser, Renderer, type OpenUIError } from "@openuidev/vue-lang";
|
||||
|
||||
import ChatMarkdown from "@/chat/ChatMarkdown.vue";
|
||||
import { viewLibrary } from "./library";
|
||||
|
||||
/**
|
||||
* An agent's generated view, or its text when there is no view or the view
|
||||
* does not hold up: a parse that drops components or leaves references
|
||||
* dangling would show a partial answer as if it were whole.
|
||||
*/
|
||||
const props = defineProps<{ view?: string; text: string }>();
|
||||
|
||||
const parser = createParser(viewLibrary.toJSONSchema());
|
||||
const failed = ref(false);
|
||||
watch(
|
||||
() => props.view,
|
||||
() => (failed.value = false),
|
||||
);
|
||||
|
||||
const usable = computed(() => {
|
||||
const source = props.view?.trim();
|
||||
if (!source || failed.value) return false;
|
||||
const { root, meta } = parser.parse(source);
|
||||
return !!root && meta.errors.length === 0 && meta.unresolved.length === 0;
|
||||
});
|
||||
|
||||
function onError(errors: OpenUIError[]) {
|
||||
if (errors.length > 0) failed.value = true;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Renderer
|
||||
v-if="usable"
|
||||
:response="view ?? null"
|
||||
:library="viewLibrary"
|
||||
:on-error="onError"
|
||||
/>
|
||||
<ChatMarkdown v-else :text="text" />
|
||||
</template>
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { Library } from "@openuidev/vue-lang";
|
||||
|
||||
import { viewRenderers } from "./renderers";
|
||||
import { viewLibrary as defineViewLibrary } from "./view-library";
|
||||
|
||||
export const viewLibrary = defineViewLibrary(viewRenderers) as Library;
|
||||
@@ -0,0 +1,106 @@
|
||||
import { defineComponent, h, type Component, type PropType } from "vue";
|
||||
import type { ElementNode, RenderNodeResult } from "@openuidev/vue-lang";
|
||||
|
||||
import CodeView from "@/base/CodeView.vue";
|
||||
import ChatMarkdown from "@/chat/ChatMarkdown.vue";
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { MetadataList } from "@/components/ui/metadata-list";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import type { ViewRenderers } from "./view-library";
|
||||
|
||||
type Props = Record<string, any>;
|
||||
|
||||
// Every renderer receives the parsed props and renderNode. Props may be
|
||||
// partial while a view streams, so each reads them defensively.
|
||||
function renderer(
|
||||
name: string,
|
||||
render: (p: Props, renderNode: (v: unknown) => RenderNodeResult) => ReturnType<typeof h>,
|
||||
): Component {
|
||||
return defineComponent({
|
||||
name,
|
||||
props: {
|
||||
props: { type: Object as PropType<Props>, required: true },
|
||||
renderNode: { type: Function as PropType<(v: unknown) => RenderNodeResult>, required: true },
|
||||
},
|
||||
setup: (p) => () => render(p.props, p.renderNode),
|
||||
});
|
||||
}
|
||||
|
||||
// A list item's own props, read by the parent that lays the list out.
|
||||
function itemProps(items: unknown): Props[] {
|
||||
return Array.isArray(items)
|
||||
? items.filter((i): i is ElementNode => i?.type === "element").map((i) => i.props)
|
||||
: [];
|
||||
}
|
||||
|
||||
const strings = (v: unknown): string[] => (Array.isArray(v) ? v.map(String) : []);
|
||||
|
||||
const changeVariant = { added: "ok", modified: "info", deleted: "danger" } as const;
|
||||
|
||||
export const viewRenderers: ViewRenderers<Component> = {
|
||||
Stack: renderer("ViewStack", (p, r) =>
|
||||
h("div", { class: "flex min-w-0 flex-col gap-5" }, [r(p.children ?? [])]),
|
||||
),
|
||||
Section: renderer("ViewSection", (p, r) =>
|
||||
h("section", { class: "flex min-w-0 flex-col gap-2" }, [
|
||||
h("h3", { class: "text-title font-semibold" }, p.title),
|
||||
r(p.children ?? []),
|
||||
]),
|
||||
),
|
||||
Columns: renderer("ViewColumns", (p, r) =>
|
||||
h("div", { class: "grid gap-5 sm:grid-cols-[repeat(auto-fit,minmax(14rem,1fr))]" }, [r(p.children ?? [])]),
|
||||
),
|
||||
Heading: renderer("ViewHeading", (p) => h("h4", { class: "text-label font-semibold" }, p.text)),
|
||||
Text: renderer("ViewText", (p) =>
|
||||
h("div", { class: "text-sm leading-relaxed" }, h(ChatMarkdown, { text: p.markdown ?? "" })),
|
||||
),
|
||||
Callout: renderer("ViewCallout", (p) =>
|
||||
h(Alert, { variant: p.tone === "risk" ? "destructive" : p.tone === "warning" ? "warn" : "default" }, () => [
|
||||
h(AlertTitle, () => p.title),
|
||||
p.body ? h(AlertDescription, () => p.body) : null,
|
||||
]),
|
||||
),
|
||||
Facts: renderer("ViewFacts", (p) =>
|
||||
h(MetadataList, {
|
||||
rows: itemProps(p.items).map((f) => ({ label: String(f.label ?? ""), value: String(f.value ?? "") })),
|
||||
}),
|
||||
),
|
||||
Fact: renderer("ViewFact", (p) =>
|
||||
h(MetadataList, { rows: [{ label: String(p.label ?? ""), value: String(p.value ?? "") }] }),
|
||||
),
|
||||
Files: renderer("ViewFiles", (p) =>
|
||||
h("ul", { class: "flex flex-col gap-1.5 text-sm" }, itemProps(p.items).map((f) => fileRow(f))),
|
||||
),
|
||||
File: renderer("ViewFile", (p) => h("ul", { class: "text-sm" }, [fileRow(p)])),
|
||||
Checklist: renderer("ViewChecklist", (p) =>
|
||||
h("ul", { class: "list-disc space-y-1 pl-5 text-sm" }, strings(p.items).map((item) => h("li", item))),
|
||||
),
|
||||
Table: renderer("ViewTable", (p) =>
|
||||
h(Table, () => [
|
||||
h(TableHeader, () => h(TableRow, () => strings(p.columns).map((c) => h(TableHead, () => c)))),
|
||||
h(TableBody, () =>
|
||||
(Array.isArray(p.rows) ? p.rows : []).map((row: unknown) =>
|
||||
h(TableRow, () => strings(row).map((cell) => h(TableCell, () => cell))),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
Code: renderer("ViewCode", (p) => h(CodeView, { code: p.code ?? "", lang: p.language })),
|
||||
};
|
||||
|
||||
function fileRow(f: Props) {
|
||||
const change = String(f.change ?? "") as keyof typeof changeVariant;
|
||||
return h("li", { class: "flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5" }, [
|
||||
h(Badge, { variant: changeVariant[change] ?? "idle" }, () => change),
|
||||
h("code", { class: "font-mono text-xs [overflow-wrap:anywhere]" }, f.path),
|
||||
f.note ? h("span", { class: "text-fg-muted" }, f.note) : null,
|
||||
]);
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
import {
|
||||
createLibrary,
|
||||
defineComponent,
|
||||
type Library,
|
||||
type PromptOptions,
|
||||
} from "@openuidev/lang-core";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
/**
|
||||
* The components an agent may compose a view from. The schemas live here,
|
||||
* apart from the Vue renderers, so the agent prompt (generated in Node) and the
|
||||
* dashboard renderer are built from the same definitions.
|
||||
*/
|
||||
export interface ViewRenderers<C> {
|
||||
Stack: C;
|
||||
Section: C;
|
||||
Columns: C;
|
||||
Heading: C;
|
||||
Text: C;
|
||||
Callout: C;
|
||||
Facts: C;
|
||||
Fact: C;
|
||||
Files: C;
|
||||
File: C;
|
||||
Checklist: C;
|
||||
Table: C;
|
||||
Code: C;
|
||||
}
|
||||
|
||||
export function viewLibrary<C>(r: ViewRenderers<C>): Library<C> {
|
||||
const Heading = defineComponent({
|
||||
name: "Heading",
|
||||
description: "A short title for what follows.",
|
||||
props: z.object({ text: z.string() }),
|
||||
component: r.Heading,
|
||||
});
|
||||
const Text = defineComponent({
|
||||
name: "Text",
|
||||
description:
|
||||
"Prose in Markdown: paragraphs, lists, inline code, links. Use for explanation the other components cannot carry.",
|
||||
props: z.object({ markdown: z.string() }),
|
||||
component: r.Text,
|
||||
});
|
||||
const Callout = defineComponent({
|
||||
name: "Callout",
|
||||
description:
|
||||
"One point the reader must not miss: a risk, an open question, a caveat or a confirmation.",
|
||||
props: z.object({
|
||||
tone: z.enum(["info", "warning", "risk", "success"]),
|
||||
title: z.string(),
|
||||
body: z.string().optional(),
|
||||
}),
|
||||
component: r.Callout,
|
||||
});
|
||||
const Fact = defineComponent({
|
||||
name: "Fact",
|
||||
description: "One label and its short value.",
|
||||
props: z.object({ label: z.string(), value: z.string() }),
|
||||
component: r.Fact,
|
||||
});
|
||||
const Facts = defineComponent({
|
||||
name: "Facts",
|
||||
description:
|
||||
"Short label/value pairs read at a glance, e.g. estimated diff size, risk, scope.",
|
||||
props: z.object({ items: z.array(Fact.ref) }),
|
||||
component: r.Facts,
|
||||
});
|
||||
const File = defineComponent({
|
||||
name: "File",
|
||||
description: "One file and how the change touches it.",
|
||||
props: z.object({
|
||||
path: z.string(),
|
||||
change: z.enum(["added", "modified", "deleted"]),
|
||||
note: z.string().optional(),
|
||||
}),
|
||||
component: r.File,
|
||||
});
|
||||
const Files = defineComponent({
|
||||
name: "Files",
|
||||
description: "The files a change adds, modifies or deletes.",
|
||||
props: z.object({ items: z.array(File.ref) }),
|
||||
component: r.Files,
|
||||
});
|
||||
const Checklist = defineComponent({
|
||||
name: "Checklist",
|
||||
description: "Criteria or steps, each independently checkable.",
|
||||
props: z.object({ items: z.array(z.string()) }),
|
||||
component: r.Checklist,
|
||||
});
|
||||
const Table = defineComponent({
|
||||
name: "Table",
|
||||
description: "Rows that compare along the same columns.",
|
||||
props: z.object({
|
||||
columns: z.array(z.string()),
|
||||
rows: z.array(z.array(z.string())),
|
||||
}),
|
||||
component: r.Table,
|
||||
});
|
||||
const Code = defineComponent({
|
||||
name: "Code",
|
||||
description: "A code excerpt or proposed signature.",
|
||||
props: z.object({ code: z.string(), language: z.string().optional() }),
|
||||
component: r.Code,
|
||||
});
|
||||
|
||||
const block = z.union([
|
||||
Heading.ref,
|
||||
Text.ref,
|
||||
Callout.ref,
|
||||
Facts.ref,
|
||||
Files.ref,
|
||||
Checklist.ref,
|
||||
Table.ref,
|
||||
Code.ref,
|
||||
]);
|
||||
const Section = defineComponent({
|
||||
name: "Section",
|
||||
description: "A titled part of the view, e.g. Problem or Proposed solution.",
|
||||
props: z.object({ title: z.string(), children: z.array(block) }),
|
||||
component: r.Section,
|
||||
});
|
||||
const Columns = defineComponent({
|
||||
name: "Columns",
|
||||
description:
|
||||
"Two or three sections side by side, for content read in contrast, e.g. goals and non-goals.",
|
||||
props: z.object({ children: z.array(Section.ref) }),
|
||||
component: r.Columns,
|
||||
});
|
||||
const Stack = defineComponent({
|
||||
name: "Stack",
|
||||
description: "The view: its parts from top to bottom.",
|
||||
props: z.object({
|
||||
children: z.array(z.union([Section.ref, Columns.ref, block])),
|
||||
}),
|
||||
component: r.Stack,
|
||||
});
|
||||
|
||||
return createLibrary({
|
||||
root: "Stack",
|
||||
components: [
|
||||
Stack,
|
||||
Section,
|
||||
Columns,
|
||||
Heading,
|
||||
Text,
|
||||
Callout,
|
||||
Facts,
|
||||
Fact,
|
||||
Files,
|
||||
File,
|
||||
Checklist,
|
||||
Table,
|
||||
Code,
|
||||
],
|
||||
componentGroups: [
|
||||
{ name: "Layout", components: ["Stack", "Section", "Columns"] },
|
||||
{
|
||||
name: "Content",
|
||||
components: [
|
||||
"Heading",
|
||||
"Text",
|
||||
"Callout",
|
||||
"Facts",
|
||||
"Fact",
|
||||
"Files",
|
||||
"File",
|
||||
"Checklist",
|
||||
"Table",
|
||||
"Code",
|
||||
],
|
||||
notes: [
|
||||
"- Prefer Facts, Files, Checklist and Table to prose; use Text only for explanation.",
|
||||
"- Define each Section and each list item as its own line so the view streams.",
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
export const viewPromptOptions: PromptOptions = {
|
||||
preamble:
|
||||
"Besides your text answer, return a view of it with the `view` tool: an OpenUI Lang program the dashboard renders for the human reading your work. It presents the same content as the text, laid out for a quick decision; it never says anything the text does not.",
|
||||
additionalRules: [
|
||||
"The view holds only OpenUI Lang: no Markdown fences, no commentary.",
|
||||
"Lead with what the reader decides on; put supporting detail after it.",
|
||||
],
|
||||
examples: [
|
||||
`root = Stack([facts, problem, solution, scope, risk])
|
||||
facts = Facts([f1, f2])
|
||||
f1 = Fact("Estimated diff", "~40 lines")
|
||||
f2 = Fact("Risk", "Low")
|
||||
problem = Section("Problem", [problemText])
|
||||
problemText = Text("Callers compute percentages by hand; \`calc\` has no helper.")
|
||||
solution = Section("Proposed solution", [solutionText, sig, files])
|
||||
solutionText = Text("Add one exported function to \`calc/calc.go\`.")
|
||||
sig = Code("func Percent(part, whole int) (int, error)", "go")
|
||||
files = Files([file1, file2])
|
||||
file1 = File("calc/calc.go", "modified", "adds Percent")
|
||||
file2 = File("calc/calc_test.go", "modified")
|
||||
scope = Columns([accept, nongoals])
|
||||
accept = Section("Acceptance criteria", [acceptList])
|
||||
acceptList = Checklist(["Percent(1, 4) returns 25", "A zero whole returns an error"])
|
||||
nongoals = Section("Non-goals", [nongoalList])
|
||||
nongoalList = Checklist(["Floating-point percentages"])
|
||||
risk = Callout("info", "No existing callers change")`,
|
||||
],
|
||||
};
|
||||
@@ -4,7 +4,7 @@ import { ChevronDown } from "@lucide/vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import ChatMarkdown from "@/chat/ChatMarkdown.vue";
|
||||
import GeneratedView from "@/genui/GeneratedView.vue";
|
||||
import type { TaskRecord } from "./task-run";
|
||||
import type { Task } from "./task";
|
||||
import TaskRowActions from "./TaskRowActions.vue";
|
||||
@@ -62,7 +62,7 @@ const long = computed(() => body.value.length > 1200);
|
||||
long && !open && 'max-h-96',
|
||||
]"
|
||||
>
|
||||
<ChatMarkdown :text="body" />
|
||||
<GeneratedView :view="task.plan_view" :text="body" />
|
||||
</div>
|
||||
<div
|
||||
v-if="long && !open"
|
||||
|
||||
@@ -57,6 +57,8 @@ export interface TaskRecord {
|
||||
actions?: string[];
|
||||
review_gate?: string;
|
||||
plan?: string;
|
||||
/** An OpenUI Lang view of the plan; the plan text stands in when it does not render. */
|
||||
plan_view?: string;
|
||||
/** What a task waiting for approval asks: "plan" or "review". */
|
||||
approval?: string;
|
||||
rereview_rounds?: number;
|
||||
|
||||
Reference in new issue
Block a user