feat(agent): add Duplicate option to agent dropdown menu#14840
feat(agent): add Duplicate option to agent dropdown menu#14840plind-junior wants to merge 2 commits into
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughImplements agent duplication: adds ChangesAgent Duplication Feature
Sequence Diagram(s)sequenceDiagram
participant UI as Agent Dropdown
participant Hook as useDuplicateAgent
participant AgentService as agentService
participant Storage as setAgent
UI->>Hook: duplicateAgent(id, title, canvas_category)
Hook->>AgentService: getAgent(id)
AgentService-->>Hook: agent details (incl. dsl)
Hook->>AgentService: listAgents(canvas_category?)
AgentService-->>Hook: existing agent titles
Hook->>Hook: buildCopyTitle(base, taken)
Hook->>Storage: setAgent(duplicated agent data)
Storage-->>Hook: success
Hook->>UI: show flow.duplicated ({{title}})
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Closes infiniflow#14769. Adds a "Duplicate" entry to the agent list dropdown that clones an agent's full DSL into a new one titled "Copy of <name>", with collision-safe numeric suffixes resolved client-side via the existing listAgents keyword search. No backend changes; reuses POST /agents.
b23de6c to
7493009
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/src/pages/agents/use-duplicate-agent.ts`:
- Around line 58-60: The code only shows success when result?.code === 0 and
ignores non-zero responses; update the duplicate flow in use-duplicate-agent.ts
to handle non-success responses from setAgent: after calling setAgent (the
variable `result`), if result?.code !== 0 show an error (e.g., message.error)
using result?.message or a translated fallback, and optionally log the result
and return early; keep the existing message.success path for result?.code === 0
so both success and failure paths provide user feedback.
- Line 53: When constructing the duplicate agent payload in
use-duplicate-agent.ts, replace the caller-supplied agent.canvas_category with
the canonical value fetched from getAgent (detail.canvas_category) so the
duplicate uses the authoritative category; update the object property assignment
where canvas_category is set (the place referencing agent.canvas_category) to
use detail.canvas_category instead and ensure detail is the fetched agent
returned by getAgent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 86f5c373-cdfb-4e5a-9af2-7d7391c1fda9
📒 Files selected for processing (4)
web/src/locales/en.tsweb/src/locales/zh.tsweb/src/pages/agents/agent-dropdown.tsxweb/src/pages/agents/use-duplicate-agent.ts
- Use detail.canvas_category from getAgent as canonical source, falling back to the caller-supplied value. - Surface setAgent failures via message.error when code !== 0 so the duplicate flow no longer fails silently. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Use detail.canvas_category from getAgent as canonical source, falling back to the caller-supplied value. - Surface setAgent failures via message.error when code !== 0 so the duplicate flow no longer fails silently.
050f9d6 to
1eba8b1
Compare
What problem does this PR solve?
Closes #14769.
Currently the agents list dropdown only exposes Rename and Delete. Users
who want to create a variation of an existing agent have to either rebuild
from scratch or use the Export JSON → Import JSON workaround, which is a
two-step manual flow that is not discoverable.
This PR adds a Duplicate entry to the dropdown that clones the agent
in one click:
GET /agents/<id>.Copy of <name>, then(2),(3), …)client-side using the existing
listAgentskeyword search, so thebackend's unique-title check at
agent_api.py:449-454is never hiton the happy path.
POST /agentswith the same DSL +canvas_categoryFiles changed
web/src/pages/agents/use-duplicate-agent.ts— new hookweb/src/pages/agents/agent-dropdown.tsx— dropdown entry,Copyicon,disabled while the create is in flight
web/src/locales/en.ts,web/src/locales/zh.ts— addsflow.duplicate,flow.copyOf,flow.duplicated,flow.duplicateFailedOther locales fall back to the literal i18n key, matching the repo's
existing convention.
Test plan
/agents, click ⋯ on any agent → DuplicateCopy of <name>with the same DSLCopy of <name> (2)canvas_category = dataflow_canvasType of change