CmdcTui.Dialogs.AskUserDialog (cmdc_tui v0.1.1)

Copy Markdown View Source

Agent 提问弹窗 — Popup + TextInput + Enter 提交。

触发流程

  1. Agent 发出 {:ask_user, session_id, question, options, ref} 事件
  2. EventRouter 创建 ask_map(含新建 TextInput ref)存入 state.pending_ask
  3. App.render 检测到 pending_ask != nil 时叠加渲染此 Dialog
  4. KeyHandler 优先检测弹窗状态:
    • 普通字符 → 转发给 TextInput
    • Enter → 提交回答:向 Agent EventBus 发送 {:ask_user_response, ref, answer}
    • Esc → 提交空字符串(取消)
    • 其余 → 转发给 TextInput

带选项的提问

如果 options 非空,则在问题下方显示选项列表(1. option1 2. option2…), 用户可直接输入对应数字快速选择。

回答回传方式

通过 GenServer.cast(session_agent_pid, {:ask_user_reply, ref, answer}) 直接回调 Agent(session 持有对 CMDC Agent 进程的引用)。 实际调用 CMDC 公共 API 或 fallback 到 EventBus 回传。

Summary

Functions

从事件参数创建 ask_map,包含新建的 TextInput ref。

渲染提问弹窗。

Functions

new_ask_map(session_id, question, options, ref)

@spec new_ask_map(String.t(), String.t(), [map()], String.t()) ::
  CmdcTui.State.ask_map()

从事件参数创建 ask_map,包含新建的 TextInput ref。

render(map, area)

渲染提问弹窗。