Prompt Input
通过自适应高度文本框、附件与键盘操作编写并提交提示词。
适用场景
- 当界面需要以下行为时使用 Prompt Input:通过自适应高度文本框、附件与键盘操作编写并提交提示词。
安装
选择安装方式,用法示例将同步更新导入路径。
$ bunx --bun shadcn-vue@2.8.2 add https://orvui.efu.me/r/prompt-input.json
首次使用时,将安装的 src/components/orvui/styles.css 导入项目样式入口。
示例
预览
packages/vue/src/agents/prompt-input/demo.vue
<script setup lang="ts">
import { defineComponent, h, onBeforeUnmount, onMounted, ref } from "vue";
import { Bot, FileText, ImagePlus, Puzzle } from "lucide-vue-next";
import { AnimatePresence, motion } from "motion-v";
import { PromptInput } from "@/components/orvui/agents/prompt-input";
const ModelLogo = defineComponent({
props: { url: { type: String, required: true } },
setup(props) {
const image = ref<HTMLImageElement>(),
failed = ref(false);
let alive = true;
onMounted(async () => {
try {
await image.value?.decode?.();
} catch {
if (alive) failed.value = true;
}
});
onBeforeUnmount(() => {
alive = false;
});
return () =>
failed.value
? h(Bot)
: h("img", {
ref: image,
src: new URL("/favicon.ico", props.url).href,
alt: "",
width: 16,
height: 16,
referrerpolicy: "no-referrer",
class: "size-4 rounded-sm object-contain",
onError: () => {
failed.value = true;
},
});
},
});
const modelData = [
["gpt-5.2", "GPT-5.2", "https://openai.com"],
["claude-sonnet-4", "Claude Sonnet 4", "https://www.anthropic.com"],
["gemini-3.6-flash", "Gemini 3.6 Flash", "https://deepmind.google"],
["grok-4.5", "Grok 4.5", "https://x.ai"],
["mistral-large-3", "Mistral Large 3", "https://mistral.ai"],
];
const models = modelData.map(([value, label, url]) => ({
value,
label,
icon: () => h(ModelLogo, { url }),
}));
const actions = [
{
value: "image",
label: "Attach image",
description: "Add a screenshot or visual reference.",
icon: ImagePlus,
},
{
value: "skill",
label: "Use a skill",
description: "Give the agent a specialized workflow.",
icon: Puzzle,
},
{
value: "context",
label: "Add context",
description: "Include a file with supporting details.",
icon: FileText,
},
];
const loading = ref(false),
sent = ref<string>(),
notice = ref<string>(),
reduce = ref(false);
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 submit(prompt: string) {
cancel();
sent.value = undefined;
notice.value = undefined;
loading.value = true;
later(900, () => {
loading.value = false;
sent.value = prompt;
});
}
function stop() {
cancel();
loading.value = false;
}
function action(value: string) {
const item = actions.find((candidate) => candidate.value === value);
notice.value = item ? `${item.label} selected.` : undefined;
}
onMounted(() => {
reduce.value = matchMedia("(prefers-reduced-motion: reduce)").matches;
});
</script>
<template>
<div class="flex h-[360px] w-full max-w-xl flex-col justify-center">
<PromptInput
:models="models"
:actions="actions"
default-model="gpt-5.2"
default-value="Review the current implementation and suggest the next improvement."
:loading="loading"
@submit="submit"
@stop="stop"
@action="action"
/>
<div class="h-8 px-2 pt-2 text-xs text-muted-foreground">
<AnimatePresence mode="wait"
><motion.p
v-if="sent || notice"
:key="sent ?? notice"
:initial="reduce ? { opacity: 1 } : { opacity: 0, y: 3 }"
:animate="{ opacity: 1, y: 0 }"
:exit="{ opacity: 0 }"
:transition="{ duration: reduce ? 0 : 0.18, ease: [0.16, 1, 0.3, 1] }"
>{{ sent ? "Prompt sent to the selected model." : notice }}</motion.p
></AnimatePresence
>
</div>
</div>
</template>
packages/vue/src/agents/prompt-input/src/PromptInput.vue
组合结构
使用公开部件 PromptInput 组合 Prompt Input,并从该组件的公开入口导入。
Chat
├── MessageScroller
│ └── MessageGroup
└── PromptInput说明: Message Scroller 在新消息加入时跟随内容,同时允许读者离开并返回最新位置。 Tool Approval 为待执行工具操作展示说明,并请求明确决策。 Approval Card 在助手继续工作前,引导用户完成一个或多个决策步骤。
工作方式
通过自适应高度文本框、附件与键盘操作编写并提交提示词。
状态与事件
需要由表单、路由或父组件管理时,绑定下列状态并接收对应更新。v-model 是属性与 update 事件的简写;值的类型应与 API 一致。
| 组件 | Vue 绑定 | 更新事件 |
|---|---|---|
PromptInput | v-modelstring | update:modelValue |
PromptInput | v-model:modelstring | update:model |
可选受控属性未传入时,按组件文档的默认行为工作;不要用固定的 false 或空值代替未传入。异步请求和持久化在应用中处理,再把结果传回组件。
API 参考
modelValue?string—defaultValue?string""models?PromptModel[]() => []model?string—defaultModel?stringprops.models[0]?.valueactions?PromptAction[]() => []loading?booleanfalseminRows?number2maxRows?number8disabled?booleanfalseplaceholder?string"Ask the agent to do something…"事件
update:modelValue[value: string]@update:modelValuevalueChange[value: string]@valueChangeupdate:model[value: string]@update:modelmodelChange[value: string]@modelChangeaction[action: string]@actionsubmit[value: string, model?: string | undefined]@submitstop[]@stop插槽
leading-action() => VNodeChild#leading-action无障碍
为交互控件提供明确的无障碍名称。保留文档中的键盘路径、可见焦点与减少动态效果状态;自定义插槽应继续保留所替代部件的语义。
常见问题
- 如何配置 Prompt Input?
- 通过 modelValue、defaultValue、models、model、defaultModel、actions、loading、minRows、maxRows、disabled、placeholder 配置 Prompt Input;API 表列出其类型与默认值。
- 如何连接到应用状态?
- 监听 update:modelValue、valueChange、update:model、modelChange、action、submit、stop,将组件连接到应用状态。
- 可以在服务端渲染吗?
- 可以在 Vue SSR 应用中正常渲染。服务端与客户端的初始 props 应保持一致;浏览器测量与交互资源在挂载后启动。
更新于
来源与许可 ↗MIT · 0.1.1