DinoxDinox AI笔记

视图

插件用 JSON 描述侧边栏内容,atomd 用自己的样式绘制:可用的元素、按钮与输入框的交互、图标列表。

插件不直接画界面,而是把「要显示什么」作为数据发给 atomd:

host.post("atomd.ui.render", {
  view: "sidebar",
  content: {
    actions: [{ id: "new-chat", icon: "rotate", label: "New chat" }],
    body: [ /* 元素,可滚动 */ ],
    footer: [ /* 元素,固定在底部 */ ],
    follow: true,
  },
});
字段说明
actions侧边栏标题栏右侧的图标按钮,按下时发送 press 事件
body主体内容,超出时滚动
footer固定在底部的内容,通常放输入框
follow为 true 时,每次渲染后滚动到底部,适合聊天类插件

每次 render 都会整体替换视图内容。状态由插件自己保存,变化后重新渲染整份内容即可,不用担心性能。

元素

元素是带 type 的对象。atomd 不认识的 type 会被跳过,不会报错。带 id 的元素在事件里报告这个 id,同时获得测试 ID <type>-<id>。

type字段说明
column、rowchildren、gap;row 还有 justify(start/center/end/between)纵向、横向排列
cardchildren带边框的卡片
bubblechildren靠右的消息气泡,适合显示用户说的话
composerchildren输入区域的外框
texttext、tone(muted/faint/danger/accent)、size(xs/sm/lg)、weight(medium/semibold)、mono、strike、center文字
iconname、size、tone图标
chiptext、icon小标签
statustext一行带动画的进行中状态,例如「正在思考…」
emptyicon、title、text空状态
diffbefore、after修改前后对比,配合 atomd.note.applyEdits 使用
divider分隔线
buttonid、label、variant(primary)、submits按钮
icon_buttonid、icon、label、variant(round)图标按钮,label 用于无障碍和提示
inputid、placeholder、multiline、autofocus输入框

按钮与输入框

  • 按下 button 或 icon_button,插件收到 { action: "press", id }。
  • 在 input 里按回车,插件收到 { action: "submit", id, value },atomd 同时清空输入框。
  • 按钮带上 "submits": "<input id>" 时,按下它等同于在那个输入框里按回车,适合「发送」按钮。
  • 用户已经输入但还没提交的文字,在重新渲染后会保留。

一个最小的输入框:

footer: [{
  type: "composer",
  children: [
    { type: "input", id: "ask", placeholder: "Ask about this note", multiline: true },
    { type: "row", justify: "end", children: [
      { type: "icon_button", id: "send", icon: "arrow-up", label: "Send", variant: "round", submits: "ask" },
    ]},
  ],
}]

图标

sparkles、rotate、x、arrow-up、stop、note、check、plus、search、copy、trash、link、list、todo、settings、folder。

其他名称会显示成拼图图标。

以后会有什么

API 1 的视图只支持数据描述的侧边栏。由插件自己用 TSX 绘制的完整面板正在规划中,需要 NSH 支持把插件视图嵌进宿主窗口后才会推出。

On this page