Skip to content

运行面板 ​

它是什么 ​

一个可复用的内存内运行轨迹,供任何执行多步 LLM 任务的插件使用。插件把轮次、流式分节、工具调用和 token 用量写入 RunStore,再挂载到 Luker 共享的运行面板悬浮窗(attachDock),也可以通过 createRunPanel 创建独立面板。

共享悬浮窗在桌面端与窄屏移动端(<= 640px)均显示为可拖动、支持小窗/大窗切换的圆角浮动窗口(双端坐标独立记忆,空闲或收起时折叠为可拖动的状态胶囊),提供轮次卡片、流式内容、停止按钮、JSON 轨迹导出,以及跳转至工作台查看详情或 AI 诊断的钩子。

共享层位于 public/scripts/run-panel/,在 Luker context 上暴露为 runPanel。仓库内消费方:

  • 编排器 —— public/scripts/extensions/orchestrator/lens/index.js
  • 搜索工具 —— public/scripts/extensions/search-tools/run-panel.js

搜索 Agent 在共享面板中的运行

快速上手(共享运行面板) ​

js
const ctx = Luker.getContext();
const { createRunStore, attachDock, openRunDock } = ctx.runPanel;

const store = createRunStore();
attachDock(store, {
    source: 'my-plugin',
    getRunContext: () => ({ chatId: ctx.chatId, chatLabel: ctx.name2 }),
    onInspect: (runKey) => ctx.workbench?.open?.({ ws: 'my-ext', subview: 'run', runKey }),
});

通过写入 store 驱动面板:

js
const runId = store.startRun({ mode: 'myTask', stopFn: () => abortController.abort() });
const roundId = store.appendRound({ runId, round: { id: 'round-1', label: 'Round 1' } });
const sectionId = store.ensureSection({
    runId, roundId,
    section: { id: 'reasoning', kind: 'reasoning', title: 'Reasoning' },
});
store.appendToSection({ runId, roundId, sectionId, delta: 'thinking…' });
store.setSectionStatus({ runId, roundId, sectionId, status: 'done' });
store.finishRun({ runId, status: 'committed', finalText: 'Result' });

在菜单项或按钮中调用 await openRunDock() 或 await toggleRunDock() 即可按需打开。

存储 API ​

createRunStore() 返回一个隔离的 store。每次调用都会产生一个独立实例,因此两个插件不会共享运行状态或产生冲突。

方法用途
subscribe(listener)订阅事件;返回一个取消订阅函数。
getCurrentRun()当前运行对象,无则为 null。
startRun({ mode, chatKey, abortFn, stopFn, quiet })开始一次运行;返回 runId。若该 store 已有运行中的运行则抛出错误。
clearCurrentRun()丢弃当前运行并发出 run_cleared。
appendRound({ runId, round: { id, label } })添加一轮;返回 roundId。
setRoundStatus({ runId, roundId, status })更新轮次状态。
ensureSection({ runId, roundId, section: { id, kind, title, meta } })分节不存在时创建;返回 sectionId。
appendToSection({ runId, roundId, sectionId, delta })向分节正文追加流式文本。
setSectionStatus({ runId, roundId, sectionId, status, meta })更新分节状态。
finishRun({ runId, status, finalText, error })结束运行。
setRunMeta({ runId, tokensSpent, cost })设置运行级元数据。
addTokenUsage({ runId, usage })把 LLM 用量对象累加进运行中的 token 总数。

quiet: true 只填充 store 而不自动打开面板;之后调用 openRunDock()(或 panel.open())即可显示。

事件 ​

监听器接收 { type, ... } 负载。常量从 run-panel/events.js 导出(也可通过 context.runPanel.events 访问)。

事件负载
run_startedrunId、mode、quiet
round_appendedrunId、roundId
section_ensuredrunId、roundId、sectionId
section_appendedrunId、roundId、sectionId、delta
section_statusrunId、roundId、sectionId、status、meta
round_statusrunId、roundId、status
run_metarunId
run_finishedrunId、status
run_clearedrunId

共享悬浮窗与记录器 API ​

函数用途
attachDock(store, opts)把 RunStore 挂载到共享记录器与悬浮运行面板({ source, getRunContext, getFlow, onInspect, onDiagnose })。
openRunDock()确保并打开共享运行面板。
toggleRunDock()切换共享运行面板的打开与关闭状态。
getRunRecorder()返回按账号保存近期运行历史的共享记录器。
getRunDockPrefs()读取当前登录账号的运行面板偏好({ autoOpen: boolean, defaultSize: 'small' | 'large' })。
setRunDockPrefs(patch)更新运行面板偏好({ autoOpen?, defaultSize?, resetPosition? }),同步存活面板实例并通知订阅者。
resetRunDockPosition()清除当前账号在桌面端与移动端保存的面板及胶囊位置,以及桌面端已保存的窗口尺寸。
subscribeRunDockPrefs(listener)订阅运行面板偏好变更;返回取消订阅函数。

用户可以在悬浮窗菜单、搜索工具设置、编排设置或工作台设置 → 窗口中同步切换运行时自动打开与运行面板默认大小(小窗 / 大窗;自动打开默认开启,关闭后非 quiet 运行仅显示状态胶囊,不会自动展开)。

独立 createRunPanel 选项 ​

若需要独立于共享悬浮窗的自定义面板,createRunPanel(options) 返回 { init, open, destroy }:

选项默认值用途
store必需来自 createRunStore() 的 store。
t恒等函数翻译函数 (template, ...args) => string。
idPrefixluker-run-panelDOM id 前缀;面板根为 #<idPrefix>,悬浮胶囊为 #<idPrefix>-pill。
stylesheetUrl共享的 panel.css要注入的样式表。
kindIconsDEFAULT_KIND_ICONS分节类型到图标的映射。
defaultCollapsedKinds[]默认折叠渲染的分节类型。
modeLabels{}mode 到徽标文字的映射;缺失时回退为原始 mode。
exportFilenamerun-<runId>-<mode>.json导出动作的文件名。
autoOpentrue非 quiet 的 run_started 时自动打开。
emptyStateText一段默认提示无运行时 open() 显示的文案。
onStopnull覆盖停止处理器。

辅助函数 ​

以下便捷封装层用于终结轮次与分节状态。首个参数为 store 实例,因此可用于任意 store。

辅助函数用途
withRound(store, runId, { id, label }, fn)追加轮次、执行 fn(roundId),随后将轮次标记为 done;抛出错误时标记为 failed。返回 fn 的结果;返回 Promise 时,在其落定后终结该轮次。
withStreamingSection(store, runId, roundId, { id, kind, title }, asyncFn)确保分节存在,将 append(delta) 函数与分节 id 传给 asyncFn,随后将分节标记为 done;抛出错误时标记为 failed。

三层 API 暴露 ​

js
// Layer 1 —— 直接 ESM import(仓库内扩展)
import { createRunStore, attachDock, openRunDock } from '/scripts/run-panel/index.js';

// Layer 2 —— lukerContext 属性
const { createRunStore, attachDock, openRunDock } = lukerContext.runPanel;

// Layer 3 —— getContext(第三方扩展)
const { createRunStore, attachDock, openRunDock } = Luker.getContext().runPanel;

参考消费方 ​

  • 编排器在 public/scripts/extensions/orchestrator/lens/index.js 将其 RunStore 挂载到共享运行面板,将查看运行详情接入工作台(ws: 'orch', subview: 'run'),将 AI 诊断接入工作台(page: 'ai', ws: 'orch')。
  • 搜索工具在 public/scripts/extensions/search-tools/run-panel.js 将其 RunStore 挂载到共享运行面板(source: 'search')。

基于 SillyTavern 构建