Repository navigation
fix: [AI-Generated Earnings] The AI-generated earnings feature modifies earnings directly, without first presenting the proposed adjustments to the user for their review and confirmation. - #7744
Conversation
…es earnings directly, without first presenting the proposed adjustments to the user for their review and confirmation.
| if (!canvasChanged) return | ||
| await layoutCanvas(lf) | ||
| lf.fitView() | ||
| MsgSuccess('工作流已生成,请检查后保存') |
There was a problem hiding this comment.
Review
Correctness / potential bugs
-
Early
returnmay skip cleanup code inrun()if (result.status === 'done') { status.value = 'done' if (!canvasChanged) return // <-- leaves the function entirely }
Anything that follows in
run()(agent disposal,clearDebugLog, status reset, counters,finally-less cleanup, logging) will now be skipped on the "planning only" path. Prefer disabling only the block instead of returning:if (result.status === 'done') { status.value = 'done' if (canvasChanged) { await layoutCanvas(lf) lf.fitView() MsgSuccess('工作流已生成,请检查后保存') } }
If you keep the
return, make surerun()has no post-processing and ideally wrap the body intry/finally. -
event.position.lengthcan throw ifpositionis optional
!event.position.lengthblows up onundefined. Use!(event.position?.length)(or!event.position?.length) unless the type guarantees a non-nullable array. Also consider a small helper (isTopLevelEvent(event)) instead of the inline magic check, since the semantics ("depth 0 = top-level agent") is not obvious. -
Concurrency / re-entrancy of
canvasChanged
It is a single component-scoped flag mutated fromonEvent. Ifrun()can be triggered again while a previous run is still in flight (double click, retry button, queued prompts), the second run resets the flag and the first run's result will read stale state. Either guard with anisRunningcheck / abort previous run, or make it a local value returned by the run session (e.g. pass a small session object into the agent, or trackSet<toolName>in a per-run ref). -
Flag is set on
tool_start, not on success
A failingadd_node/delete_edgeetc. still setscanvasChanged = true, so you calllayoutCanvas+fitViewand show "工作流已生成" even when nothing was actually mutated. Consider setting the flag on the corresponding successfultool_endevent instead (or clear it when the tool errors). -
Nested agents are ignored
Because of!event.position.length, tool calls from sub-agents never set the flag. If a sub-agent can mutate the canvas, the success message/layout will be skipped incorrectly. Confirm this is intentional and document it. -
Silent path for the user
When!canvasChangedyou return without any feedback. The comment explains why, but from the UI the run just "stops" withstatus = 'done'. Consider a neutralMsgInfo/inline hint (e.g. "方案已生成,等待确认") so the user knows the run finished. -
provideplacement and semanticsprovide(VIEW_KEY, VIEW_TYPE.DEBUG)at the top of<script setup>is technically valid (synchronous, before anyawait), but it sits between the imports anddefineOptions, which reads like a stray side effect. Move it next to the other setup logic (afterdefineOptions/useRoute/inject) or add a comment explaining the override.- It silently overrides
VIEW_KEYfor all descendants of this panel. If a child already provides/injects its own view type, this changes behavior implicitly. If it's only meant for a specific child, prefer a prop orprovideat a narrower wrapper. - The provided value is a static constant; if anything downstream should react to it changing, wrap it in
ref/computed.
-
Possible circular import
@/conversation-panel/viewis imported into a workflow panel. If that module ever imports from the workflow panel tree, you get a cycle at module-evaluation time. If it only exports the key/enum, consider moving them to a leafconstants/keysmodule.
Style / consistency
import { computed, inject, nextTick, onBeforeUnmount, ref, useTemplateRef ,provide } from 'vue'— extra space before the comma, andprovidebreaks alphabetical ordering used elsewhere. Should be:import { computed, inject, nextTick, onBeforeUnmount, provide, ref, useTemplateRef } from 'vue'
import { VIEW_KEY,VIEW_TYPE }— missing space after the comma (inconsistent with the rest of the file).CANVAS_MUTATING_TOOLSis defined inside<script setup>, so a newSetis allocated per component instance. Hoist it to a plain<script lang="ts">block or a shared constants module (that also makes it unit-testable):Whether// <script lang="ts"> (module scope) export const CANVAS_MUTATING_TOOLS: ReadonlySet<string> = new Set([...])
layoutbelongs in this list is worth double-checking — if thelayouttool already lays out the canvas, the subsequentlayoutCanvas(lf)is redundant.
Optimization / maintainability
- Prefer the
if (canvasChanged) { ... }form (point 1) — clearer intent than an early return and future-proof against added code. - Consider resetting the flag in a
finallyofrun()so a rejectedagent.run()(which currently leavesstatus = 'running') doesn't leave stale state behind. - Add a short type for the tool names (e.g.
type CanvasTool = 'add_node' | ...) so a typo in the string literal becomes a compile error rather than a silently missed flag. - The comment on
CANVAS_MUTATING_TOOLSis good; mirror it at theif (!canvasChanged)branch so future readers don't "fix" it into an unconditional layout.
| submit_plan: '提交规划', | ||
| get_field_options: '查看可引用变量', | ||
| get_models: '查询模型', | ||
| get_knowledge_list: '查询知识库', |
There was a problem hiding this comment.
Here is the analysis of the provided code diff:
1. Irregularities & Potential Issues
- Removal of Key (Functional Regression): The most critical issue is the potential removal of a valid functionality. If
submit_planwas actively used elsewhere in the codebase (e.g., in tool definitions, UI components, or execution logic), removing its label here does not remove the tool itself, but may result in missing UI text (fallback to raw key) or undefined behavior if strict typing relies on all keys being present. - Unused Import/Definition Warning: If no code references
TOOL_LABELS['submit_plan']anymore, this change is correct cleanup. However, static analysis tools might flag the original definition as unused before this diff if it was already orphaned.
2. Optimization Suggestions
- No Performance Issue: Removing a single entry from a static
Record<string, string>map has negligible impact on performance or bundle size. - Recommendation: Ensure that the corresponding tool implementation for
submit_planis also removed or deprecated consistently to avoid mismatch between available tools and their labels/tooltips.
fix: [AI-Generated Earnings] The AI-generated earnings feature modifies earnings directly, without first presenting the proposed adjustments to the user for their review and confirmation.