Tool Result
在同一表面呈现工具调用状态、摘要与可展开结果。
适用场景
- 当界面需要以下行为时使用 Tool Result:在同一表面呈现工具调用状态、摘要与可展开结果。
安装
选择安装方式,用法示例将同步更新导入路径。
$ bunx --bun shadcn-vue@2.8.2 add https://orvui.efu.me/r/tool-result.json https://orvui.efu.me/r/code-block.json
首次使用时,将安装的 src/components/orvui/styles.css 导入项目样式入口。
示例
Terminal Output
terminal-output.vue结合终端外观与执行状态显示命令输出。
Running
packages/vue/src/agents/tool-result/examples/terminal-output.vue
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref, computed } from "vue";
import { RotateCcw } from "lucide-vue-next";
import { ToolResult, ToolResultOutput } from "@/components/orvui/agents/tool-result";
const lines = [
"$ pnpm exec vitest run tests/a11y.test.ts",
"Vitest · Vue accessibility tests",
"✓ StreamingResponse complete",
"✓ ToolApproval pending",
"✓ Citations expanded",
"49 pass · 0 fail",
];
const visible = ref(0),
run = ref(0),
status = ref<"running" | "success" | "error">("running");
const output = computed(() => lines.slice(0, visible.value).join("\n"));
let epoch = 0;
const scheduledTasks = new Set<ReturnType<typeof setTimeout>>();
function cancel() {
epoch++;
scheduledTasks.forEach(clearTimeout);
scheduledTasks.clear();
}
function later(milliseconds: number, task: () => void) {
const version = epoch;
const handle = setTimeout(() => {
scheduledTasks.delete(handle);
if (version === epoch) task();
}, milliseconds);
scheduledTasks.add(handle);
}
onBeforeUnmount(cancel);
function replay() {
cancel();
run.value++;
visible.value = 0;
status.value = "running";
lines.forEach((_, index) =>
later(180 + index * 420, () => {
visible.value = index + 1;
}),
);
later(3000, () => {
status.value = "success";
});
}
onMounted(replay);
</script>
<template>
<div class="relative h-[330px] w-full max-w-lg">
<ToolResult
:key="run"
tool="terminal.run"
:title="
status === 'running' ? 'Running accessibility tests' : 'Tests passed'
"
kind="terminal"
:status="status"
:meta="status === 'success' ? '2.9s' : undefined"
:copy-text="output"
@retry="replay"
:max-height="150"
><ToolResultOutput :code="output" /></ToolResult
><button
type="button"
@click="replay"
class="absolute bottom-0 left-0 inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
>
<RotateCcw class="size-3" />Replay
</button>
</div>
</template>
packages/vue/src/agents/tool-result/src/ToolResult.vue
Request Result
request-result.vue将请求元数据及返回内容组合为可检查的结果。
Running
packages/vue/src/agents/tool-result/examples/request-result.vue
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from "vue";
import { RotateCcw } from "lucide-vue-next";
import { ToolResult, ToolResultOutput } from "@/components/orvui/agents/tool-result";
import { AgentCode } from "@/components/orvui/agents/code-block";
const response = JSON.stringify(
{ error: "rate_limit_exceeded", retryAfter: 30, requestId: "req_8f21" },
null,
2,
);
const visible = ref(0),
run = ref(0),
status = ref<"running" | "success" | "error">("running");
let epoch = 0;
const scheduledTasks = new Set<ReturnType<typeof setTimeout>>();
function cancel() {
epoch++;
scheduledTasks.forEach(clearTimeout);
scheduledTasks.clear();
}
function later(milliseconds: number, task: () => void) {
const version = epoch;
const handle = setTimeout(() => {
scheduledTasks.delete(handle);
if (version === epoch) task();
}, milliseconds);
scheduledTasks.add(handle);
}
onBeforeUnmount(cancel);
function replay() {
cancel();
run.value++;
visible.value = 0;
status.value = "running";
for (let index = 1; index <= 3; index++)
later(180 + (index - 1) * 600, () => {
visible.value = index;
});
later(2280, () => {
status.value = "error";
});
}
onMounted(replay);
</script>
<template>
<div class="relative h-[330px] w-full max-w-lg">
<ToolResult
:key="run"
tool="http.request"
:title="
status === 'running' ? 'Fetching project activity' : 'Request failed'
"
kind="request"
:status="status"
:meta="status === 'error' ? '429' : 'GET /v1/activity'"
:copy-text="response"
@retry="replay"
:collapse-on-complete="false"
:max-height="150"
><ToolResultOutput
v-if="visible < 3"
:code="
[
'Preparing request…',
'GET /v1/activity\nConnecting…',
'GET /v1/activity\nWaiting for response…',
][visible]
" /><AgentCode v-else :code="response" language="json" /></ToolResult
><button
type="button"
@click="replay"
class="absolute bottom-0 left-0 inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
>
<RotateCcw class="size-3" />Replay
</button>
</div>
</template>
packages/vue/src/agents/tool-result/src/ToolResult.vue
组合结构
使用公开部件 ToolResult, ToolResultOutput 组合 Tool Result,并从该组件的公开入口导入。
ToolResult
└── ToolResultOutput说明: Tool Approval 为待执行工具操作展示说明,并请求明确决策。 Code Block 呈现带高亮的代码,并支持行控件、文件标签与复制操作。 Agent Activity 将持续变化的助手活动组织为可展开步骤与完成摘要。
工作方式
在同一表面呈现工具调用状态、摘要与可展开结果。
状态与事件
需要由表单、路由或父组件管理时,绑定下列状态并接收对应更新。v-model 是属性与 update 事件的简写;值的类型应与 API 一致。
| 组件 | Vue 绑定 | 更新事件 |
|---|---|---|
ToolResult | v-model:openboolean | update:open |
可选受控属性未传入时,按组件文档的默认行为工作;不要用固定的 false 或空值代替未传入。异步请求和持久化在应用中处理,再把结果传回组件。
API 参考
Terminal Output
ToolResult
toolContent—titleContent—status?"success" | "error" | "running" | "cancelled""running"kind?"terminal" | "request" | "custom""custom"meta?boolean | null | string | number | void | VNode<RendererNode, RendererElement, { [key: string]: any; }> | VNodeArrayChildren | ComponentOptions<any, any, any, ComputedOptions, MethodOptions, any, any, any, string, {}, {}, string, {}, {}, {}, string, ComponentProvideOptions> | FunctionalComponent<any, {}, any, {}> | ComponentPublicInstanceConstructor<any, any, any, any, ComputedOptions, MethodOptions>—icon?boolean | null | string | number | void | VNode<RendererNode, RendererElement, { [key: string]: any; }> | VNodeArrayChildren | ComponentOptions<any, any, any, ComputedOptions, MethodOptions, any, any, any, string, {}, {}, string, {}, {}, {}, string, ComponentProvideOptions> | FunctionalComponent<any, {}, any, {}> | ComponentPublicInstanceConstructor<any, any, any, any, ComputedOptions, MethodOptions>—open?booleanundefineddefaultOpen?booleantruecollapseOnComplete?booleantruemaxHeight?number220copyText?string""onCopy?() => void | Promise<void>—contentClassName?string—事件
update:open[open: boolean]@update:openopenChange[open: boolean]@openChangeretry[]@retry插槽
default() => VNodeChild#defaultToolResultOutput
code?string(slots.default?.() ?? []).reduce(
(text, node) =>
text + (typeof node.children === "string" ? node.children : ""),
"",
)language?"text" | "bash" | "diff" | "json" | "tsx" | "typescript" | "javascript" | "vue" | "css" | "html""bash"Request Result
ToolResult
toolContent—titleContent—status?"success" | "error" | "running" | "cancelled""running"kind?"terminal" | "request" | "custom""custom"meta?boolean | null | string | number | void | VNode<RendererNode, RendererElement, { [key: string]: any; }> | VNodeArrayChildren | ComponentOptions<any, any, any, ComputedOptions, MethodOptions, any, any, any, string, {}, {}, string, {}, {}, {}, string, ComponentProvideOptions> | FunctionalComponent<any, {}, any, {}> | ComponentPublicInstanceConstructor<any, any, any, any, ComputedOptions, MethodOptions>—icon?boolean | null | string | number | void | VNode<RendererNode, RendererElement, { [key: string]: any; }> | VNodeArrayChildren | ComponentOptions<any, any, any, ComputedOptions, MethodOptions, any, any, any, string, {}, {}, string, {}, {}, {}, string, ComponentProvideOptions> | FunctionalComponent<any, {}, any, {}> | ComponentPublicInstanceConstructor<any, any, any, any, ComputedOptions, MethodOptions>—open?booleanundefineddefaultOpen?booleantruecollapseOnComplete?booleantruemaxHeight?number220copyText?string""onCopy?() => void | Promise<void>—contentClassName?string—事件
update:open[open: boolean]@update:openopenChange[open: boolean]@openChangeretry[]@retry插槽
default() => VNodeChild#defaultToolResultOutput
code?string(slots.default?.() ?? []).reduce(
(text, node) =>
text + (typeof node.children === "string" ? node.children : ""),
"",
)language?"text" | "bash" | "diff" | "json" | "tsx" | "typescript" | "javascript" | "vue" | "css" | "html""bash"无障碍
为交互控件提供明确的无障碍名称。保留文档中的键盘路径、可见焦点与减少动态效果状态;自定义插槽应继续保留所替代部件的语义。
常见问题
- 如何配置 Tool Result?
- 通过 tool、title、status、kind、meta、icon、open、defaultOpen、collapseOnComplete、maxHeight、copyText、onCopy、contentClassName 配置 Tool Result;API 表列出其类型与默认值。
- 如何连接到应用状态?
- 监听 update:open、openChange、retry,将组件连接到应用状态。
- 可以在服务端渲染吗?
- 可以在 Vue SSR 应用中正常渲染。服务端与客户端的初始 props 应保持一致;浏览器测量与交互资源在挂载后启动。
更新于
来源与许可 ↗MIT · 0.1.1