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.
43 lines
1.2 KiB
Vue
43 lines
1.2 KiB
Vue
<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>
|