Automation API 最后一公里:HTTP Route CRUD + Client SDK 扩展 + 执行历史接入
衔接: #741(✅ 已完成 — 核心引擎 + 插件体系)
Parent: #753(Spec 优先 Roadmap 2026.02)
阻塞: ObjectUI Roadmap P1.6(Automation Builder)
📊 现状(#741 交付物确认)
以下 已完成 ✅,不在本 Issue 范围内:
| 已完成 |
文件 |
测试 |
IAutomationService contract |
spec/src/contracts/automation-service.ts |
3 tests |
AutomationEngine (DAG 引擎) |
services/service-automation/src/engine.ts |
27 tests |
AutomationServicePlugin (Kernel 插件) |
services/service-automation/src/plugin.ts |
✅ |
CrudNodesPlugin (get/create/update/delete_record) |
plugins/crud-nodes-plugin.ts |
✅ |
LogicNodesPlugin (decision/assignment/loop) |
plugins/logic-nodes-plugin.ts |
✅ |
HttpConnectorPlugin (http_request/connector_action) |
plugins/http-connector-plugin.ts |
✅ |
| 热插拔 (registerNodeExecutor/unregisterNodeExecutor) |
engine.ts |
✅ |
| Execution 协议 Schema (Log/StepLog/Error/Checkpoint/ConcurrencyPolicy/ScheduleState) |
automation/execution.zod.ts |
✅ |
🎯 本 Issue 目标
打通 Automation Service → HTTP API → Client SDK 的完整链路。
Task 1: Automation API Protocol Schema ⏱️ 0.5d
在 packages/spec/src/api/ 新增 automation-api.zod.ts:
// 定义 REST CRUD 端点的 Request/Response schemas
export const AutomationApiContracts = {
listFlows: { method: 'GET', path: '/api/automation' },
getFlow: { method: 'GET', path: '/api/automation/:name' },
createFlow: { method: 'POST', path: '/api/automation' },
updateFlow: { method: 'PUT', path: '/api/automation/:name' },
deleteFlow: { method: 'DELETE', path: '/api/automation/:name' },
triggerFlow: { method: 'POST', path: '/api/automation/:name/trigger' }, // 已有
toggleFlow: { method: 'POST', path: '/api/automation/:name/toggle' },
listRuns: { method: 'GET', path: '/api/automation/:name/runs' },
getRun: { method: 'GET', path: '/api/automation/:name/runs/:runId' },
};
Task 2: IAutomationService Contract 扩展 ⏱️ 0.5d
扩展 contracts/automation-service.ts 中的 IAutomationService:
export interface IAutomationService {
// 已有 ✅
execute(flowName: string, context?: AutomationContext): Promise<AutomationResult>;
listFlows(): Promise<string[]>;
registerFlow?(name: string, definition: unknown): void;
unregisterFlow?(name: string): void;
// 新增 🆕
getFlow?(name: string): Promise<FlowDefinition | null>;
toggleFlow?(name: string, enabled: boolean): Promise<void>;
listRuns?(flowName: string, options?: { limit?: number; cursor?: string }): Promise<ExecutionLog[]>;
getRun?(runId: string): Promise<ExecutionLog | null>;
}
Task 3: AutomationEngine 执行历史 ⏱️ 1d
在 AutomationEngine 中新增 executionLog 存储:
Task 4: HTTP Route Handler 扩展 ⏱️ 1d
在 runtime/src/http-dispatcher.ts 的 handleAutomation() 和 createDispatcherPlugin() 中新增 CRUD 路由:
当前(仅 1 个路由):
// POST /automation/trigger/:name ← 已有
目标(9 个路由):
GET /automation → listFlows
GET /automation/:name → getFlow
POST /automation → createFlow (registerFlow)
PUT /automation/:name → updateFlow
DELETE /automation/:name → deleteFlow (unregisterFlow)
POST /automation/:name/trigger → execute (已有)
POST /automation/:name/toggle → toggleFlow
GET /automation/:name/runs → listRuns
GET /automation/:name/runs/:runId → getRun
Task 5: Client SDK automation namespace 扩展 ⏱️ 1d
扩展 packages/client/src/index.ts 中的 client.automation:
当前(仅 1 个方法):
automation = {
trigger: async (name, data) => { ... }
}
目标:
automation = {
// 已有
trigger: async (name, data) => { ... },
// 新增
list: async () => { ... },
get: async (name) => { ... },
create: async (name, definition) => { ... },
update: async (name, definition) => { ... },
delete: async (name) => { ... },
toggle: async (name, enabled) => { ... },
runs: {
list: async (flowName, options?) => { ... },
get: async (flowName, runId) => { ... },
},
}
Task 6: 测试 + Roadmap 更新 ⏱️ 0.5d
📐 工作量估算
| Task |
估时 |
| Task 1: API Protocol Schema |
0.5d |
| Task 2: Contract 扩展 |
0.5d |
| Task 3: Engine 执行历史 |
1d |
| Task 4: HTTP Route CRUD |
1d |
| Task 5: Client SDK |
1d |
| Task 6: 测试 + Roadmap |
0.5d |
| 总计 |
4.5d |
🔗 关联
备注:开发任务完成后需运行 test,并及时更新 roadmap。
Automation API 最后一公里:HTTP Route CRUD + Client SDK 扩展 + 执行历史接入
📊 现状(#741 交付物确认)
以下 已完成 ✅,不在本 Issue 范围内:
IAutomationServicecontractspec/src/contracts/automation-service.tsAutomationEngine(DAG 引擎)services/service-automation/src/engine.tsAutomationServicePlugin(Kernel 插件)services/service-automation/src/plugin.tsCrudNodesPlugin(get/create/update/delete_record)plugins/crud-nodes-plugin.tsLogicNodesPlugin(decision/assignment/loop)plugins/logic-nodes-plugin.tsHttpConnectorPlugin(http_request/connector_action)plugins/http-connector-plugin.tsautomation/execution.zod.ts🎯 本 Issue 目标
打通 Automation Service → HTTP API → Client SDK 的完整链路。
Task 1: Automation API Protocol Schema ⏱️ 0.5d
在
packages/spec/src/api/新增automation-api.zod.ts:ListFlowsRequest/ResponseGetFlowRequest/ResponseCreateFlowRequest/ResponseUpdateFlowRequest/ResponseDeleteFlowRequest/ResponseToggleFlowRequest/Response(enable/disable)ListRunsRequest/Response(复用ExecutionLogSchema)GetRunRequest/Response(复用ExecutionLogSchema+ExecutionStepLogSchema)Task 2: IAutomationService Contract 扩展 ⏱️ 0.5d
扩展
contracts/automation-service.ts中的IAutomationService:getFlow、toggleFlow、listRuns、getRun可选方法Task 3: AutomationEngine 执行历史 ⏱️ 1d
在
AutomationEngine中新增 executionLog 存储:execute()完成后记录ExecutionLog(runId、flowName、input、output、durationMs、status、steps)getFlow(name)— 返回 flow 定义toggleFlow(name, enabled)— enable/disable 标记listRuns(flowName)— 返回执行历史getRun(runId)— 返回单次执行详情Task 4: HTTP Route Handler 扩展 ⏱️ 1d
在
runtime/src/http-dispatcher.ts的handleAutomation()和createDispatcherPlugin()中新增 CRUD 路由:当前(仅 1 个路由):
// POST /automation/trigger/:name ← 已有目标(9 个路由):
handleAutomation()中新增 8 个路由分支createDispatcherPlugin()中注册对应的 server 路由Task 5: Client SDK
automationnamespace 扩展 ⏱️ 1d扩展
packages/client/src/index.ts中的client.automation:当前(仅 1 个方法):
目标:
getRoute()中已有'automation'路由,确认路径正确list(),get(),create(),update(),delete(),toggle()runs.list(),runs.get()Task 6: 测试 + Roadmap 更新 ⏱️ 0.5d
pnpm test,确保全部测试通过ROADMAP.md中 Automation 相关 checklistservice-automation的 completenessservice-automation的 test count📐 工作量估算
🔗 关联
client.automation.list/create/update才能渲染 AutomationBuilder UI)automation/execution.zod.ts已定义完整的 ExecutionLog/StepLog/Checkpoint schema备注:开发任务完成后需运行 test,并及时更新 roadmap。