(gateway: GatewayClient, id: string, enable: boolean)
| 147 | id: graphId, |
| 148 | enable: input.enable ?? true, |
| 149 | uiType: 'graph', |
| 150 | userData: { |
| 151 | name: input.name, |
| 152 | lastUpdateTime: Date.now(), |
| 153 | transform: { x: 0, y: 0, scale: 1, rotate: 0 }, |
| 154 | }, |
| 155 | }, |
| 156 | }; |
| 157 | |
| 158 | const errors = validateGraph(graph); |
| 159 | const errorList = errors.filter((e: { level: string }) => e.level === 'error'); |
| 160 | if (errorList.length > 0) { |
| 161 | return { |
| 162 | success: false, |
| 163 | error: `规则校验失败(${errorList.length} 个错误):${errorList.map((item) => `[${item.nodeId}] ${item.message}`).join(';')}`, |
| 164 | }; |
| 165 | } |
| 166 | |
| 167 | let resumedShell = false; |
| 168 | if (input.graphId && existingIds.has(graphId)) { |
| 169 | const existing = await gateway.callApi<Graph>('getGraph', { id: graphId }, 10000); |
| 170 | if (JSON.stringify(comparableNodes(existing.nodes)) === JSON.stringify(comparableNodes(graph.nodes))) { |
| 171 | resumedExisting = true; |
| 172 | } else { |
| 173 | resumedShell = isSetupShell(existing); |
| 174 | if (!resumedShell) return { success: false, error: `指定的规则 ID ${graphId} 已被其他规则占用` }; |
| 175 | resumedExisting = true; |
| 176 | } |
| 177 | } else if (input.graphId && existingScopes.has(variableScope)) { |
no test coverage detected