Skip to content

Commit 88ed58b

Browse files
committed
chore: show message to user if building block requested is not supported yet
1 parent 3ce1358 commit 88ed58b

5 files changed

Lines changed: 90 additions & 6 deletions

File tree

src/codius/domain/model/intents/intent_type.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from enum import Enum
22

3+
from codius.infrastructure.services.code_scanner.model.building_block_type import \
4+
BuildingBlockType
5+
36

47
class IntentType(str, Enum):
58
ADD_AGGREGATE = "add_aggregate"
@@ -22,3 +25,17 @@ class IntentType(str, Enum):
2225
REMOVE_REPOSITORY_METHOD = "remove_repository_method"
2326

2427
UNSURE = "unsure"
28+
29+
@property
30+
def building_block(self) -> BuildingBlockType:
31+
if self.name.startswith("ADD_AGGREGATE") or self.name.startswith(
32+
"REMOVE_AGGREGATE"):
33+
return BuildingBlockType.AGGREGATE_ROOT
34+
elif self.name.startswith("ADD_VALUE_OBJECT") or self.name.startswith(
35+
"REMOVE_VALUE_OBJECT"):
36+
return BuildingBlockType.VALUE_OBJECT
37+
elif self.name.startswith("ADD_REPOSITORY") or self.name.startswith(
38+
"REMOVE_REPOSITORY"):
39+
return BuildingBlockType.REPOSITORY
40+
else:
41+
raise NotImplementedError(f"Building block not mapped for intent {self}")

src/codius/domain/model/prompts/distill_intent_prompt.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from codius.domain.model.intents.value_object.add_value_object_property_intent import AddValueObjectPropertyIntent
2323
from codius.domain.model.intents.value_object.remove_value_object_property_intent import RemoveValueObjectPropertyIntent
2424
from codius.domain.model.intents.repository.add_repository_intent import AddRepositoryIntent
25+
from codius.infrastructure.services.code_scanner.model.building_block_type import \
26+
BuildingBlockType
2527

2628

2729
@dataclass(frozen=True)
@@ -49,6 +51,14 @@ def as_prompt(self) -> str:
4951
RemoveRepositoryMethodIntent,
5052
]
5153

54+
all_blocks = {bb.value for bb in BuildingBlockType}
55+
supported_blocks = {intent.building_block.value for intent in IntentType if
56+
intent != IntentType.UNSURE}
57+
unsupported_blocks = all_blocks - supported_blocks
58+
59+
supported_blocks_text = "\n".join(f"- {b}" for b in sorted(supported_blocks))
60+
unsupported_blocks_text = "\n".join(f"- {b}" for b in sorted(unsupported_blocks))
61+
5262
example_blocks = "\n".join(
5363
f"### {cls.intent.value}\n```json\n{cls.to_example_json()}\n```"
5464
for cls in example_intents
@@ -88,6 +98,29 @@ def as_prompt(self) -> str:
8898
**Database Providers**:
8999
{database_text}
90100
101+
---
102+
103+
### Known DDD Building Blocks
104+
105+
These are the known building blocks in Domain-Driven Design:
106+
107+
**Supported:**
108+
{supported_blocks_text}
109+
110+
**Not yet supported:**
111+
{unsupported_blocks_text}
112+
113+
If the user refers to a known DDD building block that is **not yet supported**, return:
114+
115+
```json
116+
{{ "intent": "unsupported", "building_block": "<block_name>" }}
117+
```
118+
119+
If the user's intent is unclear or unsupported, respond only with:
120+
121+
```json
122+
{{ "intent": "unsure" }}
123+
91124
### Instructions
92125
93126
- Break complex modeling instructions into small, **granular intents**.
@@ -109,9 +142,4 @@ def as_prompt(self) -> str:
109142
### Examples:
110143
111144
{example_blocks}
112-
113-
If the user's intent is unclear or unsupported, respond only with:
114-
115-
```json
116-
{{ "intent": "unsure" }}
117145
"""
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from typing import cast
2+
3+
4+
def handle_unsupported_intent(state: dict) -> dict:
5+
from codius.domain.model.intents.intent_type import IntentType
6+
7+
unsupported_blocks = {
8+
intent.get("building_block")
9+
for intent in state.get("intent", [])
10+
if intent.get("intent") == "unsupported"
11+
}
12+
block_list = ", ".join(sorted(unsupported_blocks))
13+
14+
# Dynamically get supported building blocks
15+
supported_blocks = {
16+
intent.building_block.value
17+
for intent in IntentType
18+
if intent != IntentType.UNSURE
19+
}
20+
supported_blocks_list = "\n".join(f"- {b}" for b in sorted(supported_blocks))
21+
22+
state["final_output"] = (
23+
f"⚠️ The assistant understood your request, but the following building block(s) aren't supported yet:\n"
24+
f"- {block_list}\n\n"
25+
"We're shipping updates frequently, so it might already be available in a newer version.\n\n"
26+
"👉 Try updating Codius:\n"
27+
"```bash\npip install --upgrade codius\n```\n"
28+
"Then rerun your request.\n\n"
29+
"In the meantime, you can try working with one of the currently supported building blocks:\n"
30+
f"{supported_blocks_list}\n\n"
31+
"💡 Need help or want to request this feature? Let us know on GitHub!"
32+
)
33+
34+
return state

src/codius/graph/routers/intent_router.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def route_by_intent(state: dict) -> str:
1616

1717
if intent_type == "error":
1818
return "error"
19+
elif intent_type == "unsupported":
20+
return "unsupported"
1921
elif intent_type and intent_type not in {"none", "greeting", "unsure"}:
2022
return "valid"
2123

src/codius/infrastructure/services/graph_service.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from codius.graph.nodes.generate_code import generate_code
1010
from codius.graph.nodes.handle_intent_error import handle_intent_error
1111
from codius.graph.nodes.handle_unclear_intent import handle_unclear_intent
12+
from codius.graph.nodes.handle_unsupported_intent import handle_unsupported_intent
1213
from codius.graph.nodes.plan_changes import plan_changes
1314
from codius.graph.nodes.revise_intent import revise_intent
1415
from codius.graph.routers.approval_router import route_by_user_approval
@@ -69,6 +70,7 @@ def _build_graph(self):
6970
# Add nodes
7071
graph.add_node("DistillIntent", distill_intent)
7172
graph.add_node("HandleUnclearIntent", handle_unclear_intent)
73+
graph.add_node("HandleUnsupportedIntent", handle_unsupported_intent)
7274
graph.add_node("HandleIntentError", handle_intent_error)
7375
graph.add_node("ExtractProjectMetadata", extract_project_metadata)
7476
graph.add_node("ExtractBuildingBlocks", extract_building_blocks)
@@ -84,7 +86,8 @@ def _build_graph(self):
8486
graph.add_conditional_edges("DistillIntent", route_by_intent, {
8587
"valid": "ExtractProjectMetadata",
8688
"unclear": "HandleUnclearIntent",
87-
"error": "HandleIntentError"
89+
"error": "HandleIntentError",
90+
"unsupported": "HandleUnsupportedIntent",
8891
})
8992
graph.add_conditional_edges("Preview", route_by_user_approval, {
9093
"apply": "ApplyChanges",

0 commit comments

Comments
 (0)