mirror of
https://github.com/langgenius/dify.git
synced 2026-10-04 13:47:55 +08:00
feat(dify-builder): name apps from their prompt, and turn gate actions into card options
Two App Builder spec changes that share the Builder session contract.
Naming (spec N1-N3): an app created from the homepage prompt is no longer named
by the user. core/dify_builder/naming.py cuts the prompt's opening clause at
create time -- instant and infallible, since it runs inside POST /apps -- and
CreateAppPayload.name becomes optional alongside a new prompt field. The Builder
then refines that name once during goal analysis, where a model and the detected
reply language are already in hand, so the judgement calls that are
English-shaped in pure Python (dropping an imperative lead-in, spotting a
contentless prompt) work in any language. Plan approval freezes the name.
Card options: SessionView gains a Decision carrying the gate's choice as options
inside the card plus a fixed confirm/cancel pair, replacing a button row whose
shape changed at every state. Option ids are the old action ids untouched, so
resolve_action_kind and the per-state legality check are unchanged, and
SessionView.actions keeps being populated -- the deployed web client goes on
working until it reads decision instead.
The regenerated console OpenAPI doc also picks up ErrorCard.diagnostics, missed
when cc9ca8b1dd landed.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
cc9ca8b1dd
commit
aa2b4fe4ab
30 files changed
+1163
-18
No files matched your search
@@ -22,3 +22,24 @@ class TestCreateAppPayloadMode:
|
||||
def test_rejects_unknown_mode(self):
|
||||
with pytest.raises(ValidationError):
|
||||
CreateAppPayload.model_validate({"name": "X", "mode": "not-a-mode"})
|
||||
|
||||
|
||||
class TestCreateAppPayloadNaming:
|
||||
"""App Builder creates from a prompt, so the client may send no name."""
|
||||
|
||||
def test_accepts_a_prompt_without_a_name(self):
|
||||
payload = CreateAppPayload.model_validate(
|
||||
{"mode": "workflow", "prompt": "Refund approval for ecommerce orders"}
|
||||
)
|
||||
assert payload.name is None
|
||||
assert payload.prompt == "Refund approval for ecommerce orders"
|
||||
|
||||
def test_accepts_neither_name_nor_prompt(self):
|
||||
payload = CreateAppPayload.model_validate({"mode": "workflow"})
|
||||
assert payload.name is None
|
||||
assert payload.prompt is None
|
||||
|
||||
def test_still_rejects_an_empty_name(self):
|
||||
# Omitting the name asks the server to derive one; sending "" is a bug.
|
||||
with pytest.raises(ValidationError):
|
||||
CreateAppPayload.model_validate({"name": "", "mode": "workflow"})
|
||||
@@ -127,7 +127,7 @@ def test_conversation_get_rejects_competing_cursors(monkeypatch):
|
||||
(
|
||||
{"scenario": "build", "app_id": "a1", "goal_text": "Build it"},
|
||||
"create_build_session_stream",
|
||||
{"app_id": "a1", "goal_text": "Build it", "model_config": None},
|
||||
{"app_id": "a1", "goal_text": "Build it", "model_config": None, "derive_app_name": False},
|
||||
),
|
||||
(
|
||||
{"scenario": "edit", "app_id": "a1", "goal_text": "Tighten risk"},
|
||||
@@ -543,3 +543,64 @@ def test_decorator_stack_gate_blocks_when_feature_off(monkeypatch):
|
||||
def test_session_routes_require_legacy_edit_permission(method):
|
||||
gate = unwrap(method, stop=lambda wrapper: "edit_permission_required" in wrapper.__code__.co_qualname)
|
||||
assert "edit_permission_required" in gate.__code__.co_qualname
|
||||
|
||||
|
||||
def test_create_build_defaults_to_not_renaming_the_app(monkeypatch):
|
||||
service = MagicMock()
|
||||
service.create_build_session_stream.return_value = _frames()
|
||||
monkeypatch.setattr(mod, "build_service", lambda: service)
|
||||
|
||||
mod._create({"scenario": "build", "app_id": "a1", "goal_text": "Build it"}, _actor())
|
||||
|
||||
assert service.create_build_session_stream.call_args.kwargs["derive_app_name"] is False
|
||||
|
||||
|
||||
def test_create_build_forwards_the_rename_opt_in(monkeypatch):
|
||||
service = MagicMock()
|
||||
service.create_build_session_stream.return_value = _frames()
|
||||
monkeypatch.setattr(mod, "build_service", lambda: service)
|
||||
|
||||
mod._create(
|
||||
{"scenario": "build", "app_id": "a1", "goal_text": "Build it", "derive_app_name": True},
|
||||
_actor(),
|
||||
)
|
||||
|
||||
assert service.create_build_session_stream.call_args.kwargs["derive_app_name"] is True
|
||||
|
||||
|
||||
def test_action_resolves_confirm_through_the_option_the_client_chose(monkeypatch):
|
||||
service = MagicMock()
|
||||
service.submit_action_stream.return_value = _frames()
|
||||
monkeypatch.setattr(mod, "build_service", lambda: service)
|
||||
|
||||
response = mod._action(
|
||||
"s1",
|
||||
{
|
||||
"action_id": "confirm",
|
||||
"payload": {"option_id": "run_validation", "free_text": ""},
|
||||
"base_version": 1,
|
||||
"base_app_revision": "hash-1",
|
||||
},
|
||||
_actor(),
|
||||
)
|
||||
|
||||
_assert_event_stream(response)
|
||||
|
||||
action = service.submit_action_stream.call_args.args[2]
|
||||
assert action.kind == "run_verify"
|
||||
# The chosen option and any free text travel on to the handler untouched.
|
||||
assert action.payload == {"option_id": "run_validation", "free_text": ""}
|
||||
|
||||
|
||||
def test_action_still_accepts_a_client_posting_the_bare_action_id(monkeypatch):
|
||||
service = MagicMock()
|
||||
service.submit_action_stream.return_value = _frames()
|
||||
monkeypatch.setattr(mod, "build_service", lambda: service)
|
||||
|
||||
mod._action(
|
||||
"s1",
|
||||
{"action_id": "run_validation", "payload": {}, "base_version": 1, "base_app_revision": "hash-1"},
|
||||
_actor(),
|
||||
)
|
||||
|
||||
assert service.submit_action_stream.call_args.args[2].kind == "run_verify"
|
||||
Reference in new issue
Block a user