LokvisRuntimeImpl
Defined in: packages/runtime/src/runtime-impl.ts:40
Runtime 实现类,持有 5 个 managers 并委托方法
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new LokvisRuntimeImpl(
config?):LokvisRuntimeImpl
Defined in: packages/runtime/src/runtime-impl.ts:81
Parameters
Section titled “Parameters”config?
Section titled “config?”RuntimeConfig & InternalRuntimeInit = {}
Returns
Section titled “Returns”LokvisRuntimeImpl
Properties
Section titled “Properties”version
Section titled “version”
readonlyversion:"0.1.0"=RUNTIME_VERSION
Defined in: packages/runtime/src/runtime-impl.ts:41
Runtime 版本
Implementation of
Section titled “Implementation of”eventBus
Section titled “eventBus”
readonlyeventBus:EventBus
Defined in: packages/runtime/src/runtime-impl.ts:42
事件总线
Implementation of
Section titled “Implementation of”Accessors
Section titled “Accessors”status
Section titled “status”Get Signature
Section titled “Get Signature”get status():
RuntimeStatus
Defined in: packages/runtime/src/runtime-impl.ts:140
当前状态
Returns
Section titled “Returns”当前状态
Implementation of
Section titled “Implementation of”Get Signature
Section titled “Get Signature”get isPro():
boolean
Defined in: packages/runtime/src/runtime-impl.ts:141
是否为 Pro 模式(影响批量上限/并发槽位/workflow 数,W6.2)
Returns
Section titled “Returns”boolean
是否为 Pro 模式(影响批量上限/并发槽位/workflow 数,W6.2)
Implementation of
Section titled “Implementation of”Get Signature
Section titled “Get Signature”get plan():
Plan
Defined in: packages/runtime/src/runtime-impl.ts:142
用户订阅计划(G1)。比 isPro 更细粒度,用于 AI 调用计费判定。
isPro === (plan !== 'free'),二者保持一致。
Returns
Section titled “Returns”用户订阅计划(G1)。比 isPro 更细粒度,用于 AI 调用计费判定。
isPro === (plan !== 'free'),二者保持一致。
Implementation of
Section titled “Implementation of”Get Signature
Section titled “Get Signature”get batch():
BatchProcessor
Defined in: packages/runtime/src/runtime-impl.ts:143
批量处理器(W6.1:并发控制 + 进度 + 失败重试)
Returns
Section titled “Returns”批量处理器(W6.1:并发控制 + 进度 + 失败重试)
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”_registerMetadataReader()
Section titled “_registerMetadataReader()”_registerMetadataReader(
name,reader):void
Defined in: packages/runtime/src/runtime-impl.ts:67
注册元数据读取器(由 PluginContext.registerMetadataReader 转发,内部 API)
Parameters
Section titled “Parameters”string
reader
Section titled “reader”Returns
Section titled “Returns”void
_registerPanel()
Section titled “_registerPanel()”_registerPanel(
panel):void
Defined in: packages/runtime/src/runtime-impl.ts:76
注册 UI Panel 定义(由 PluginContext.registerPanel 转发,内部 API)。 同 id 重复注册覆盖前者(与 registerMetadataReader 语义一致,支持热更新), 并同步发射 panel:registered 事件,UI 层订阅后刷新面板列表。
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
run(
workflow,inputs,options?):Promise<WorkflowResult>
Defined in: packages/runtime/src/runtime-impl.ts:146
运行工作流
Parameters
Section titled “Parameters”workflow
Section titled “workflow”inputs
Section titled “inputs”string[] | Asset[]
options?
Section titled “options?”Returns
Section titled “Returns”Promise<WorkflowResult>
Implementation of
Section titled “Implementation of”cancel()
Section titled “cancel()”cancel(
workflowId):Promise<void>
Defined in: packages/runtime/src/runtime-impl.ts:150
取消运行
Parameters
Section titled “Parameters”workflowId
Section titled “workflowId”string
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”pause()
Section titled “pause()”pause(
workflowId):Promise<void>
Defined in: packages/runtime/src/runtime-impl.ts:154
暂停运行
Parameters
Section titled “Parameters”workflowId
Section titled “workflowId”string
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”resume()
Section titled “resume()”resume(
workflowId):Promise<void>
Defined in: packages/runtime/src/runtime-impl.ts:158
恢复运行
Parameters
Section titled “Parameters”workflowId
Section titled “workflowId”string
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”disposeWorkflow()
Section titled “disposeWorkflow()”disposeWorkflow(
workflowId):Promise<void>
Defined in: packages/runtime/src/runtime-impl.ts:162
销毁工作流的运行时状态(取消运行 + 清空历史栈 + 回收历史 outputs 资产)。
修复 review 报告:原接口无清理入口,长会话累积导致 historyStacks Map 与 AssetStore 中孤儿资产泄漏。ui-react 应在 Workspace 卸载时调用。
Parameters
Section titled “Parameters”workflowId
Section titled “workflowId”string
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”dispose()
Section titled “dispose()”dispose():
Promise<void>
Defined in: packages/runtime/src/runtime-impl.ts:188
销毁整个 Runtime(W21.6)。
顺序:
- 标记 disposed(阻止后续 run/cancel,防止清理期间新请求进入)
- executor.cancelAll() —— 取消所有运行中 workflow 的 AbortController
- batchProcessor.dispose() —— 标记所有非终态 job 为 cancelled + 清理订阅
- historyManager.disposeAll() —— 清空所有历史栈(reset 触发 onEvict → assetStore.remove 回收 outputs 资产);TD-2.1 改为 await 等待 persistHistory 删除 IDB 记录落地
- 清理 metadataReaders 与 panels(释放插件注册的引用)
- 若 ownsAssetStore(工厂创建而非注入):调用 assetStore.dispose?.() 关闭 Dexie 连接 / 清空内存 Map。注入路径由消费方自行管理。
不清理:
- historyStore(由消费方注入或工厂创建,Dexie 连接由浏览器 GC 处理)
- eventBus listeners(允许外部已订阅的 listener 仍收到最后一批 workflow:cancelled 等事件;若需要清空可单独调 eventBus.clear)
幂等:重复调用为 no-op。
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”history()
Section titled “history()”history(
workflowId):Promise<HistoryEntry[]>
Defined in: packages/runtime/src/runtime-impl.ts:209
获取工作流的执行历史
Parameters
Section titled “Parameters”workflowId
Section titled “workflowId”string
Returns
Section titled “Returns”Promise<HistoryEntry[]>
Implementation of
Section titled “Implementation of”getHistoryState()
Section titled “getHistoryState()”getHistoryState(
workflowId):Promise<{entries:HistoryEntry[];cursor:number; }>
Defined in: packages/runtime/src/runtime-impl.ts:210
获取工作流历史状态(条目 + 当前游标)。 游标 -1 表示无已应用条目(初始状态);i 表示第 i 条已应用。 比 history() 多返回 cursor,UI 据此高亮当前步骤。
Parameters
Section titled “Parameters”workflowId
Section titled “workflowId”string
Returns
Section titled “Returns”Promise<{ entries: HistoryEntry[]; cursor: number; }>
Implementation of
Section titled “Implementation of”undo()
Section titled “undo()”undo(
workflowId):Promise<void>
Defined in: packages/runtime/src/runtime-impl.ts:213
撤销一步
Parameters
Section titled “Parameters”workflowId
Section titled “workflowId”string
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”redo()
Section titled “redo()”redo(
workflowId):Promise<void>
Defined in: packages/runtime/src/runtime-impl.ts:214
重做一步
Parameters
Section titled “Parameters”workflowId
Section titled “workflowId”string
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”jumpTo()
Section titled “jumpTo()”jumpTo(
workflowId,index):Promise<void>
Defined in: packages/runtime/src/runtime-impl.ts:215
跳转到指定历史条目(按时间顺序的索引,-1 表示回到初始)。 用于 HistoryPanel 点击条目直接跳转,等价于连续 undo/redo 到目标位置。 越界或游标未变时为 no-op。
Parameters
Section titled “Parameters”workflowId
Section titled “workflowId”string
number
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”importAsset()
Section titled “importAsset()”importAsset(
source):Promise<string>
Defined in: packages/runtime/src/runtime-impl.ts:218
导入资产
Parameters
Section titled “Parameters”source
Section titled “source”Returns
Section titled “Returns”Promise<string>
Implementation of
Section titled “Implementation of”getAsset()
Section titled “getAsset()”getAsset(
id):Promise<Asset>
Defined in: packages/runtime/src/runtime-impl.ts:219
获取资产
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<Asset>
Implementation of
Section titled “Implementation of”exportAsset()
Section titled “exportAsset()”exportAsset(
id,format?):Promise<Blob>
Defined in: packages/runtime/src/runtime-impl.ts:220
导出资产为 Blob
Parameters
Section titled “Parameters”string
format?
Section titled “format?”string
Returns
Section titled “Returns”Promise<Blob>
Implementation of
Section titled “Implementation of”readAssetExif()
Section titled “readAssetExif()”readAssetExif(
id):Promise<ExifData|null>
Defined in: packages/runtime/src/runtime-impl.ts:221
读取 image 资产的 EXIF 元数据(W7.3/7.4)。
长期方案(MetadataReader 依赖反转):Runtime 持有 plugin-image 通过
ctx.registerMetadataReader('image.read-exif', fn) 注册的读取器引用,
按名调用。Plugin 未安装时优雅降级返回 null。
readExif 实现位于 plugin-image(Capability 层),不进 engine-image
(不符合 Engine 层 Blob↔Blob 纯函数约束)。
UI 通过此方法访问 EXIF,不直接依赖 Engine/Plugin 包(五层架构单向依赖)。
Parameters
Section titled “Parameters”string
资产 ID(须为 image 类型)
Returns
Section titled “Returns”Promise<ExifData | null>
ExifData;非 image / 无 EXIF / 解析失败 / reader 未注册返回 null
Implementation of
Section titled “Implementation of”readAssetImageMetadata()
Section titled “readAssetImageMetadata()”readAssetImageMetadata(
id):Promise<ImageMetadata|null>
Defined in: packages/runtime/src/runtime-impl.ts:222
读取 image 资产的 dimensions/format 元数据。
走 MetadataReader 机制(与 readAssetExif 同一设计):Runtime 持有
plugin-image 通过 ctx.registerMetadataReader('image.read-metadata', fn)
注册的 reader 引用,按名调用。reader 内部调 engine-image/node 的
getMetadata(sharp .metadata())。
用途:mcp-server 在 image tool 处理完成后,读取输出 Blob 的精确尺寸 用于结果文本报告。Plugin 未安装时优雅降级返回 null。
架构意义:使 mcp-server 不再直接 import @lokvis/engine-image(违反 五层架构单向依赖),改为通过 Runtime 间接调用(见 A1 修复)。
Parameters
Section titled “Parameters”string
资产 ID(须为 image 类型)
Returns
Section titled “Returns”Promise<ImageMetadata | null>
ImageMetadata;非 image / reader 未注册 / 解析失败返回 null
Implementation of
Section titled “Implementation of”LokvisRuntime.readAssetImageMetadata
readAssetPdfInfo()
Section titled “readAssetPdfInfo()”readAssetPdfInfo(
id):Promise<PdfInfo|null>
Defined in: packages/runtime/src/runtime-impl.ts:223
读取 pdf 资产的页数。
走 MetadataReader 机制:Runtime 持有 plugin-pdf 通过
ctx.registerMetadataReader('pdf.read-info', fn) 注册的 reader 引用,
按名调用。reader 内部调 engine-pdf 的 getPdfInfo(pdf-lib getPageCount)。
用途:mcp-server 在 pdf tool 处理完成后,读取输出 Blob 的页数用于结果 文本报告。Plugin 未安装时优雅降级返回 null。
架构意义:使 mcp-server 不再直接 import @lokvis/engine-pdf(违反 五层架构单向依赖),改为通过 Runtime 间接调用(见 A1 修复)。
Parameters
Section titled “Parameters”string
资产 ID(须为 pdf 类型)
Returns
Section titled “Returns”Promise<PdfInfo | null>
PdfInfo;非 pdf / reader 未注册 / 解析失败返回 null
Implementation of
Section titled “Implementation of”LokvisRuntime.readAssetPdfInfo
removeAsset()
Section titled “removeAsset()”removeAsset(
id):Promise<void>
Defined in: packages/runtime/src/runtime-impl.ts:224
删除资产
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”listAssets()
Section titled “listAssets()”listAssets():
Promise<Asset[]>
Defined in: packages/runtime/src/runtime-impl.ts:225
列出所有资产
Returns
Section titled “Returns”Promise<Asset[]>
Implementation of
Section titled “Implementation of”getStorageUsage()
Section titled “getStorageUsage()”getStorageUsage():
Promise<{usage:number;quota:number; }>
Defined in: packages/runtime/src/runtime-impl.ts:226
查询存储配额使用情况(W6.7)。
返回 { usage, quota }:
usage:当前已用字节数(所有资产 metadata.size 之和)quota:配置的存储配额上限(RuntimeConfig.storageQuota,默认 1GB)
UI 据此展示“已用/总额”进度条,接近上限(>=80%)时警告。
注意:usage 基于 listAssets 实时计算,反映 runtime 实际占用,
与浏览器 navigator.storage.estimate()(origin 整体 OPFS)不同。
Returns
Section titled “Returns”Promise<{ usage: number; quota: number; }>
Implementation of
Section titled “Implementation of”capabilities()
Section titled “capabilities()”capabilities():
Promise<Capability[]>
Defined in: packages/runtime/src/runtime-impl.ts:229
列出所有已注册能力
Returns
Section titled “Returns”Promise<Capability[]>
Implementation of
Section titled “Implementation of”hasCapability()
Section titled “hasCapability()”hasCapability(
name):Promise<boolean>
Defined in: packages/runtime/src/runtime-impl.ts:230
检查能力是否可用
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<boolean>
Implementation of
Section titled “Implementation of”isStubOnly()
Section titled “isStubOnly()”isStubOnly(
name):Promise<boolean>
Defined in: packages/runtime/src/runtime-impl.ts:231
检查能力是否仅有 stub 实现(无可用引擎)。
UI 层据此为 stub-only 能力显示 “Coming Soon” 标记(A7), 避免用户选择后在工作流执行阶段才收到 stub error。 返回 true 表示该能力已声明但仅有占位实现,resolve() 会跳过。
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<boolean>
Implementation of
Section titled “Implementation of”listPanels()
Section titled “listPanels()”listPanels():
PanelDefinition[]
Defined in: packages/runtime/src/runtime-impl.ts:234
列出插件通过 ctx.registerPanel() 注册的全部 UI Panel。
Panel 注册时同步发射 panel:registered 事件;UI 层(ui-react)
订阅该事件并调用本方法刷新面板列表,按 PanelDefinition.location
挂载到 Workspace 对应区域。component 字段为渲染器标识,由 UI 层
的 panel renderer 注册表解析(依赖反转:runtime 只持有定义,
不持有 React 组件)。
同步方法:panel 列表是纯内存状态,无 I/O。
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”toMcpManifest()
Section titled “toMcpManifest()”toMcpManifest(
options?):McpManifest
Defined in: packages/runtime/src/runtime-impl.ts:237
生成 MCP server manifest(不启动 server,仅描述当前可被 MCP 暴露的能力)。 用于:
- @lokvis/mcp-server 注册 tools 前的能力探测
- Dashboard 展示“可被 AI 调用的能力”
- 文档站自动生成 MCP tools 列表
options.batchMode 控制是否暴露 mcpExposure='batch-only' 的能力:
- 默认 false(单文件模式):不暴露 batch-only 能力
- true(batch 模式):暴露 batch-only 能力
mcpExposure='private'的能力在任何模式下都不暴露。
注:本方法同步返回 —— manifest 是对 capabilityRegistry.list()
(同步)的纯计算,无 I/O,故无需 async。capabilities() 仍为 async
仅为接口对称性(未来可能涉及异步加载)。
Parameters
Section titled “Parameters”options?
Section titled “options?”ToMcpManifestOptions = {}
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”installPlugin()
Section titled “installPlugin()”installPlugin(
plugin):Promise<void>
Defined in: packages/runtime/src/runtime-impl.ts:252
安装插件:① 注册能力声明 → ② 构造权限沙箱 → ③ 构造受限 PluginContext → ④ 应用 network guard(声明 network:none 时 monkey-patch 全局 fetch/XHR/WebSocket/EventSource)→ ⑤ 调用 plugin.install(ctx) → ⑥ restore 全局 API → ⑦ 发射 plugin:loaded 事件。不吞错。
network guard 仅在 plugin.install() 期间生效;install 后插件若异步调用 网络 API(如 setTimeout 回调)无法覆盖 —— plugin 作者应据 ctx.sandbox 主动断言(best-effort 守卫,见 docs/PROJECT_PLAN.md W18.6)。
Parameters
Section titled “Parameters”plugin
Section titled “plugin”Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”_getAssetStore()
Section titled “_getAssetStore()”_getAssetStore():
AssetStore
Defined in: packages/runtime/src/runtime-impl.ts:278
Returns
Section titled “Returns”_getCapabilityRegistry()
Section titled “_getCapabilityRegistry()”_getCapabilityRegistry():
CapabilityRegistry
Defined in: packages/runtime/src/runtime-impl.ts:279
Returns
Section titled “Returns”CapabilityRegistry
_getMemoryGuard()
Section titled “_getMemoryGuard()”_getMemoryGuard():
MemoryGuard
Defined in: packages/runtime/src/runtime-impl.ts:280
Returns
Section titled “Returns”MemoryGuard
_getCurrentOutputs()
Section titled “_getCurrentOutputs()”_getCurrentOutputs(
workflowId):string[]
Defined in: packages/runtime/src/runtime-impl.ts:281
Parameters
Section titled “Parameters”workflowId
Section titled “workflowId”string
Returns
Section titled “Returns”string[]
getCurrentOutputs()
Section titled “getCurrentOutputs()”getCurrentOutputs(
workflowId):Promise<string[]>
Defined in: packages/runtime/src/runtime-impl.ts:282
获取工作流当前输出 AssetId(undo/redo 后的“当前”状态)。
用途:
- UI 实时展示工作流中间结果
- MCP server 查询当前工作流产物
- 暂停时检查中间输出
Parameters
Section titled “Parameters”workflowId
Section titled “workflowId”string
Returns
Section titled “Returns”Promise<string[]>
Implementation of
Section titled “Implementation of”LokvisRuntime.getCurrentOutputs
loadPersistedHistory()
Section titled “loadPersistedHistory()”loadPersistedHistory():
Promise<void>
Defined in: packages/runtime/src/runtime-impl.ts:285
从 historyStore 预加载持久化历史快照(由 createRuntime 工厂在构造后调用一次,impl 初始化钩子)。
Returns
Section titled “Returns”Promise<void>