From f25782b99fed3a884c898c6cfb1e713b7b09abe2 Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Mon, 8 Jun 2026 13:28:06 +0800 Subject: [PATCH] Add OpenCode assistant type and configuration form in AssistantPage --- src/components/pages/AssistantPage.tsx | 177 ++++++++++++++++++++++++- 1 file changed, 172 insertions(+), 5 deletions(-) diff --git a/src/components/pages/AssistantPage.tsx b/src/components/pages/AssistantPage.tsx index f8059d5..e328ff2 100644 --- a/src/components/pages/AssistantPage.tsx +++ b/src/components/pages/AssistantPage.tsx @@ -25,6 +25,7 @@ import { Waypoints, AudioLines, Square, + Terminal, } from "lucide-react"; import { Button } from "@/components/ui/button"; @@ -93,9 +94,25 @@ type DifyForm = { enableInterrupt: boolean; }; -type AssistantType = "提示词" | "工作流" | "Dify" | "FastGPT"; +type OpenCodeForm = { + name: string; + prompt: string; + apiUrl: string; + apiKey: string; + asr: string; + voice: string; + enableInterrupt: boolean; +}; -const assistantTypes: AssistantType[] = ["提示词", "工作流", "Dify", "FastGPT"]; +type AssistantType = "提示词" | "工作流" | "Dify" | "FastGPT" | "OpenCode"; + +const assistantTypes: AssistantType[] = [ + "提示词", + "工作流", + "Dify", + "FastGPT", + "OpenCode", +]; type AssistantTypeOption = { type: AssistantType; @@ -135,6 +152,13 @@ const assistantTypeOptions: AssistantTypeOption[] = [ icon: , available: true, }, + { + type: "OpenCode", + label: "使用 OpenCode 构建", + description: "对接 OpenCode 服务,通过提示词驱动代码助手并支持实时语音对话。", + icon: , + available: true, + }, ]; type AssistantListItem = { @@ -217,6 +241,12 @@ const mockAssistants: AssistantListItem[] = [ type: "FastGPT", updatedAt: "2026-04-28 19:34", }, + { + id: "asst_013", + name: "OpenCode 代码助手", + type: "OpenCode", + updatedAt: "2026-06-07 14:22", + }, ]; type DebugMode = "text" | "voice"; @@ -256,8 +286,24 @@ export function AssistantPage() { voice: "晓宁", enableInterrupt: true, }); + const [openCodeForm, setOpenCodeForm] = useState({ + name: "OpenCode 代码助手", + prompt: + "你是一个代码助手的语音交互界面,请用简洁、口语化的方式回答用户关于代码与工程的问题。", + apiUrl: "http://localhost:4096", + apiKey: "", + asr: "SenseVoice", + voice: "晓宁", + enableInterrupt: true, + }); const [view, setView] = useState< - "list" | "choose" | "create" | "create-dify" | "create-fastgpt" | "placeholder" + | "list" + | "choose" + | "create" + | "create-dify" + | "create-fastgpt" + | "create-opencode" + | "placeholder" >("list"); const [searchQuery, setSearchQuery] = useState(""); const [typeFilter, setTypeFilter] = useState("全部"); @@ -285,6 +331,9 @@ export function AssistantPage() { } else if (assistant.type === "Dify") { updateDifyForm("name", assistant.name); setView("create-dify"); + } else if (assistant.type === "OpenCode") { + updateOpenCodeForm("name", assistant.name); + setView("create-opencode"); } else { // 工作流:暂时显示占位页 setDraftName(assistant.name); @@ -310,6 +359,10 @@ export function AssistantPage() { // Dify 类型:进入 Dify 构建表单,并把已填的名称带过去 updateDifyForm("name", draftName.trim()); setView("create-dify"); + } else if (draftType === "OpenCode") { + // OpenCode 类型:进入 OpenCode 构建表单,并把已填的名称带过去 + updateOpenCodeForm("name", draftName.trim()); + setView("create-opencode"); } else { // 工作流:暂时显示占位页 setView("placeholder"); @@ -379,6 +432,16 @@ export function AssistantPage() { [key]: value, })); } + + function updateOpenCodeForm( + key: K, + value: OpenCodeForm[K], + ) { + setOpenCodeForm((prev) => ({ + ...prev, + [key]: value, + })); + } if (view === "list") { return (
@@ -593,7 +656,7 @@ export function AssistantPage() { ); return ( -
+

创建助手

@@ -631,7 +694,7 @@ export function AssistantPage() {
构建方式
-
+
{assistantTypeOptions.map((option) => { const selected = draftType === option.type; @@ -951,6 +1014,110 @@ export function AssistantPage() { ); } + if (view === "create-opencode") { + return ( +
+
+
+ updateOpenCodeForm("name", value)} + /> +
+ +
+ + + +
+
+ +
+
+ } + title="OpenCode 服务配置" + description="填写 OpenCode 服务地址与 API Key 以对接代码助手。" + > + updateOpenCodeForm("apiUrl", value)} + placeholder="http://localhost:4096" + /> + updateOpenCodeForm("apiKey", value)} + placeholder="请输入 OpenCode API Key" + type="password" + /> + + + } + title="提示词" + description="描述助手的角色、能力和回答要求" + > + updateOpenCodeForm("prompt", value)} + placeholder="请输入提示词,描述助手的角色、能力和回答要求" + rows={8} + /> + + + } + title="语音配置" + description="配置本平台的语音识别与播报音色。" + > + updateOpenCodeForm("asr", value)} + options={["SenseVoice", "Paraformer", "Whisper", "FunASR"]} + /> + updateOpenCodeForm("voice", value)} + options={["晓宁", "晓美", "晓宇", "晓晨"]} + /> + + + } + title="交互策略" + description="设置实时视频对话时的交互体验" + > + + updateOpenCodeForm("enableInterrupt", checked) + } + /> + +
+ + +
+
+ ); + } + return (