fix(api): allow canvas_type in agent create and update APIs (#15201)

### What problem does this PR solve?

Creating or updating an agent via `POST /api/v1/agents` and `PUT
/api/v1/agents/{agent_id}` did not persist `canvas_type` because the
handler `req` dict never assigned the field before
`UserCanvasService.save` / `update_by_id`.


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
- [ ] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
天海蒼灆
2026-05-26 11:31:46 +08:00
committed by GitHub
parent 3dbd874a79
commit 0d2a17254c
3 changed files with 27 additions and 2 deletions

View File

@@ -80,6 +80,9 @@ def test_create_agent_payload_and_error(monkeypatch):
client.create_agent("agent-title", {"graph": {}}, description="desc")
assert calls[-1][1] == {"title": "agent-title", "dsl": {"graph": {}}, "description": "desc"}
client.create_agent("agent-title", {"graph": {}}, canvas_type="Marketing")
assert calls[-1][1] == {"title": "agent-title", "dsl": {"graph": {}}, "canvas_type": "Marketing"}
monkeypatch.setattr(client, "post", lambda *_args, **_kwargs: _DummyResponse({"code": 1, "message": "create boom"}))
with pytest.raises(Exception) as exception_info:
client.create_agent("agent-title", {"graph": {}})
@@ -104,6 +107,7 @@ def test_update_agent_payload_matrix_and_error(monkeypatch):
{"title": "new-title", "description": "new-description", "dsl": {"nodes": []}},
{"title": "new-title", "description": "new-description", "dsl": {"nodes": []}},
),
({"canvas_type": "Agent"}, {"canvas_type": "Agent"}),
]
for kwargs, expected_payload in cases:
client.update_agent("agent-1", **kwargs)