dsh-ask-form:在 DeepSeek Harness 裏用結構化表單向用戶提問

前言

在 DeepSeek Harness(DSH)裏,智能體常用內置的 ask_user_question 向用戶確認選項:一次一頁、扁平選項列表,多字段、帶條件或校驗時,往往要拆成多次調用,回傳結果也多是字符串,後續邏輯還要自己解析。

社區插件 dsh-ask-form(維護者 Zekilou,分類:工作流)提供工具 ask_form:一次調用呈現整表,支持 14 種字段類型、跨字段條件與校驗、校驗失敗時的定向重問,以及帶類型的 JSON 答案。在無法渲染表單的環境會自動退化爲內置問答流,與「一切皆插件」的 DSH 用法一致。目錄頁見 SkillHub,源碼見 GitHub。

這是什麼

dsh-ask-form 是面向 DeepSeek Harness 的社區插件包。Host 側註冊 ask_form,Client 側在 Web UI 渲染居中浮層表單;Bundle 爲 index.js 與 client.js 兩半,無需額外構建步驟。當前 package 版本爲 0.4.0,許可證 MIT。

與內置工具的對比如 README 所述:內置 ask_user_question 是逐題展示的選項列表;ask_form 增加字段類型、跨字段約束與一次提交,並在不支持渲染的界面上 degrade 到內置流程。

核心功能

字段類型與返回值

支持 14 種字段類型:confirm、single、multi、text、longtext、number、integer、date、tags、scale、slider、ranking、matrix、budget。

校驗與展示相關能力包括:

  • 條件顯示:visible_if
  • 校驗:validate(白名單表達式語言,不使用 eval)、pattern、max_length、min / max、sum_to
  • 定向重問:僅重問未通過校驗的字段,最多 max_rounds 輪

各類型結果在 Host 側解碼爲對應結構,例如 scale / slider / number → 數字,ranking → 有序數組,matrix → {row: choice},budget → {option: number},tags → 字符串數組。

訪談包與擴展

內置訪談包:requirement-intake、design-choice、release-gate、incident-intake,可通過 pack_args 調整。

single、multi、tags 默認允許自由文本「Other」;設置 allow_other: false 可關閉。mode: "script" 可在 Web UI 渲染自定義 React 元素,並應聲明 script.fallback 供其他界面使用;Script 模式失敗時會明確報錯,而不是靜默降級。

運行方式概要

Host 半部通過既有 ctx.userQuestions 接縫註冊工具:將表單編譯爲普通 AskUserQuestionItem[],任何 answerer 仍可作答;Client 半部在 conversation.composer 鏈上低優先級註冊,僅當問題攜帶本插件 intent.kind 時渲染整表並回傳 JSON 信封。無本插件渲染器的界面仍會把每個字段當作普通問題,結果中 renderer 爲 "generic"。

安裝與啓用

前提:Harness profile 需具備 plugin_manager 工具(web profile 已包含)。

  1. 在 Harness 中讓智能體安裝,或通過 plugin_manager 執行:
action: install_bundle
target: github:Zekilou/dsh-ask-form

若使用本地目錄,將 target 換爲該目錄的絕對路徑,例如 /absolute/path/to/dsh-ask-form。

  1. 重新加載 Harness Web 頁面一次,以便客戶端 bundle 註冊(client.js 負責表單界面)。
  2. 安裝完成後,ask_form 與 ask_user_question 並列可用。

插件在 當前 DSH 進程權限 下運行;安裝前請自行審閱 倉庫源碼 與許可證(MIT)。

典型用法

一次工具調用即一張表單;列表類字段中,第一項按慣例爲推薦選項。

自定義表單示例:

{
  "title": "Runtime decision",
  "intro": "Pick the runtime and weight the criteria.",
  "fields": [
    { "name": "runtime", "type": "single", "label": "Runtime",
      "options": ["Node 22 (Recommended)", "Bun", "Deno"] },
    { "name": "needs_wasm", "type": "confirm", "label": "Do you need WASM?",
      "visible_if": "runtime == 'Bun'" },
    { "name": "weights", "type": "budget", "label": "Criteria weights (sum 100)",
      "options": ["Performance", "Ecosystem", "Footprint"], "sum_to": 100 },
    { "name": "priority", "type": "ranking", "label": "Priority order",
      "options": ["Ship fast", "Stay small", "Be portable"] },
    { "name": "scores", "type": "matrix", "label": "Score each dimension",
      "rows": ["Performance", "Cost"], "options": ["High", "Medium", "Low"] }
  ],
  "notes": true
}

使用預製訪談包:

{ "pack": "requirement-intake", "pack_args": { "topic": "cache layer" }, "notes": true }

返回結構包含類型化值與來源信息,status 取值爲 answered、incomplete、cancelled、aborted、no_answerer、unavailable、script_error 之一。示例:

{ "status": "answered", "rounds": 1, "renderer": "form",
  "values": { "runtime": "Bun", "needs_wasm": true,
              "weights": { "Performance": 50, "Ecosystem": 30, "Footprint": 20 },
              "priority": ["Be portable", "Ship fast", "Stay small"],
              "scores": { "Performance": "High", "Cost": "Low" } },
  "notes": "…" }

適用場景與注意

適合:需求 intake、設計選型、發佈門禁、事故 intake 等需要多字段、條件分支、數值約束(如 budget 求和)且希望 Agent 直接消費 JSON 的工作流。

兼容性與 UI 行爲(摘自 README):

  • Host 需要 ctx.tools 與 ctx.userQuestions;Client 需要 conversation.composer 鏈及 shell 中的 react-dom。
  • 實現基於 @deepseek-ai/dsh-* 的 0.2.0-rc.2 時代 API,後續可能變動。
  • 表單爲居中模態層,點擊遮罩不關閉、Escape 不取消,避免誤觸丟失半填內容。
  • 10 秒內若答案未回到 Host,界面會重新啓用按鈕並提示,避免長時間掛起。

本地驗證(無需 monorepo 與瀏覽器):

node tests/host.test.mjs
node tests/client.test.mjs

SkillHub 等社區目錄爲獨立站點,與 DeepSeek / 幻方無官方從屬關係;星標等統計以目錄頁爲準(當前 GitHub 星標爲 0)。

小結

dsh-ask-form 把「向用戶問一組結構化問題」收斂爲單次 ask_form 調用:類型化字段、條件、校驗與 JSON 答案,Web 端有專用渲染,其它界面仍可走內置問答。需要時可從 SkillHub 目錄頁 進入說明,在 GitHub 查看 README、THIRD_PARTY_NOTICES 與 Issue。

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

小夜