[feat] solution/backend: 에이전트가 페이지 구성을 바꾼다 — 섹션 on/off·순서

"문구 변경밖에 안 된다" 는 지적에서 시작했다. 페이지 구성은 sites.theme.sections
배열 하나이고 배열 순서가 곧 발행본의 순서라, 그 JSON 을 만지는 도구 셋을 붙였다.

- list_sections(READ) · toggle_section(REVERSIBLE) · move_section(REVERSIBLE)
- 목록은 site_payload._sections 를 그대로 쓴다 — 발행본이 쓰는 그 함수다.
  표를 따로 만들면 에디터·발행본·대화 셋이 갈라지고 "껐는데 나온다" 가 된다
- 잠긴 섹션은 못 끈다. _sections 가 어차피 켜서 내보내므로 끌 수 있게 두면
  화면만 거짓말한다
- 이름이 둘 이상 걸리면 고르지 않는다 — 추측으로 고르면 발행하고 나서야 안다
- sections 만 갈아끼운다 — theme 을 통째로 쓰면 고른 색·서체가 말없이 사라진다

★ 템플릿·색은 넣지 않았다. templatesFor() 가 색·look·기본 섹션·배리에이션을 함께
계산해서, 백엔드가 template_id 만 바꾸면 "레이아웃은 새것, 색은 옛것" 이 된다 —
레지스트리를 공유 단일 출처로 옮기는 작업이 먼저다(docs/AGENT.md).

test_agent_runtime 26 passed(구성 7건 추가).
전체 864 passed / 53 failed — 53 은 이번 변경 전과 동일. npm run lint 통과

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
HyeongBaeYangandClaude Opus 5 committed 2026-09-28 11:50:38 +09:00
1 parent e35ce311d3
commit ea9ae1ac2a
6 files changed
+276 -6

No files matched your search

+5 -2
View File
@@ -82,7 +82,7 @@ async def _context_facts(user: UserInfo, place_id: str, place) -> list[dict]:
return out[:30]
async def _choose(place, fields, facts, message) -> dict:
async def _choose(place, fields, facts, sections, message) -> dict:
"""LLM 한 번. 고른 도구 이름과 인자만 받는다."""
active = provider.active()
async with httpx.AsyncClient(timeout=REQUEST_TIMEOUT) as client:
@@ -94,6 +94,7 @@ async def _choose(place, fields, facts, message) -> dict:
tools=registry.describe(),
fields=fields,
facts=facts,
sections=sections,
message=message,
),
response_schema=prompt.RESPONSE_SCHEMA,
@@ -129,11 +130,13 @@ async def chat(user: UserInfo, place_id: str, message: str, confirm: dict | None
fields = registry.fields_of(place)
facts = await _context_facts(user, place_id, place)
# ★ 섹션은 이름으로 지목한다("후기 빼줘"). 목록을 안 실으면 모델이 이름을 지어낸다.
sections, _theme = await registry.sections_of(ctx)
# ★ 사이트 상태는 프롬프트에 싣지 않는다. 그 한 줄 때문에 매 턴 사이트 조회 + 슬러그 계산이
# 돌았고, 정작 모델이 필요할 때는 `get_site_status` 도구를 부르면 된다.
try:
choice = await _choose(place, fields, facts, message)
choice = await _choose(place, fields, facts, sections, message)
except LlmError as ex:
LOG.w(f"[agent] 도구 선택 실패: {type(ex).__name__}")
raise AgentError("AGENT_CALL_FAILED") from ex
+125 -1
View File
@@ -26,7 +26,7 @@ from crud.job_crud import JobQueue
from crud.place_crud import PlaceCRUD
from crud.site_crud import SiteCRUD
from router.v1.fact.protocol import Req_UpsertFact
from router.v1.site.protocol import Req_StartBuild
from router.v1.site.protocol import Req_SiteTheme, Req_StartBuild
from services import site_payload
from services.fact_service import FactService
from services.site_service import SiteService
@@ -129,6 +129,104 @@ async def _set_fact(ctx: ToolContext, args: dict) -> str:
return f"{spec.label} 을(를) {value} 로 바꿨습니다. 사이트에 반영하려면 다시 발행해야 해요 — 지금 할까요?"
# ── 페이지 구성 ──────────────────────────────────────────────────────────
async def _sections_of(ctx: ToolContext) -> tuple[list, dict]:
"""지금 발행본에 서는 섹션 목록(해석된 결과)과 저장된 theme.
★ `site_payload._sections` 를 그대로 쓴다 — 발행본이 쓰는 바로 그 함수다. 표를 따로
만들면 에디터·발행본·대화 셋이 갈라지고, 사장님은 "껐는데 나온다" 를 겪는다.
★ 저장값이 없어도 업종 기본이 선다. 그래서 아직 한 번도 디자인을 만지지 않은
사업장에서도 대화가 바로 통한다."""
_fact, site_service = _services()
res = await site_service.get_site(ctx.user, ctx.place_id)
theme = dict((res.site.theme if res.site and res.site.theme else {}) or {})
spec = site_payload._DEFAULT_THEME[PlaceCategory(ctx.place.category).value]["sections"]
return site_payload._sections(theme.get("sections"), spec), theme
def _find_section(rows: list, wanted: str):
"""이름이나 id 로 찾는다. 사장님은 '후기' 처럼 줄여 말한다 — 부분 일치도 받는다.
★ 둘 이상 걸리면 **고르지 않는다**(None). 추측으로 고르면 엉뚱한 섹션을 끄고,
사장님은 그 사실을 발행하고 나서야 안다."""
wanted = (wanted or "").strip()
if not wanted:
return None
exact = [r for r in rows if r["id"] == wanted or r["name"] == wanted]
if len(exact) == 1:
return exact[0]
partial = [r for r in rows if wanted in r["name"]]
return partial[0] if len(partial) == 1 else None
async def _save_sections(ctx: ToolContext, theme: dict, rows: list) -> None:
"""★ theme 의 나머지 칸(colors·fontStyle·look…)을 그대로 들고 간다. sections 만 갈아끼운다 —
통째로 새로 쓰면 사장님이 고른 색과 서체가 말없이 사라진다."""
_fact, site_service = _services()
theme["sections"] = rows
res = await site_service.set_theme(ctx.user, ctx.place_id, Req_SiteTheme(theme=theme))
if not res.result.success:
raise ToolRejected("화면 구성을 저장하지 못했습니다. 빌더 화면에서 확인해 주세요.")
def _layout_line(row: dict) -> str:
mark = "켜짐" if row["enabled"] else "꺼짐"
lock = " (항상 켜짐)" if row["locked"] else ""
return f"· {row['name']} — {mark}{lock}"
async def _list_sections(ctx: ToolContext, args: dict) -> str:
rows, _theme = await _sections_of(ctx)
body = "\n".join(_layout_line(r) for r in rows)
return f"지금 홈페이지는 위에서부터 이 순서입니다.\n{body}"
async def _toggle_section(ctx: ToolContext, args: dict) -> str:
rows, theme = await _sections_of(ctx)
row = _find_section(rows, args.get("name"))
if row is None:
raise ToolRejected("어느 부분을 말씀하시는지 못 찾았어요. '목록' 이라고 하시면 보여드릴게요.")
on = (args.get("enabled") or "").strip().lower() in ("true", "1", "켜", "켜기", "on", "yes")
# ★ 잠긴 섹션은 끌 수 없다. SEO·필수 마크업 때문에 잠긴 것이라, 끄면 발행 게이트에 걸린다
# (site_payload._sections 가 어차피 켜서 내보낸다 — 화면만 거짓말하게 된다).
if row["locked"] and not on:
raise ToolRejected(f"{row['name']} 은(는) 홈페이지에 꼭 있어야 하는 부분이라 끌 수 없어요.")
if row["enabled"] == on:
return f"{row['name']} 은(는) 이미 {'켜져' if on else '꺼져'} 있어요."
row["enabled"] = on
await _save_sections(ctx, theme, rows)
return (f"{row['name']} 을(를) {'켰습니다' if on else '껐습니다'}. "
f"사이트에 반영하려면 다시 발행해야 해요 — 지금 할까요?")
async def _move_section(ctx: ToolContext, args: dict) -> str:
"""★ 배열 순서가 곧 발행본의 섹션 순서다(site_payload._sections)."""
rows, theme = await _sections_of(ctx)
row = _find_section(rows, args.get("name"))
if row is None:
raise ToolRejected("어느 부분을 말씀하시는지 못 찾았어요. '목록' 이라고 하시면 보여드릴게요.")
to = (args.get("to") or "").strip()
rest = [r for r in rows if r["id"] != row["id"]]
if to in ("맨 위", "처음", "위", "top", "first"):
moved, where = [row] + rest, "맨 위로"
elif to in ("맨 아래", "마지막", "아래", "bottom", "last"):
moved, where = rest + [row], "맨 아래로"
else:
anchor = _find_section(rest, to)
if anchor is None:
raise ToolRejected("어디로 옮길지 못 찾았어요. '소개 다음으로' 처럼 말씀해 주세요.")
at = rest.index(anchor) + 1
moved, where = rest[:at] + [row] + rest[at:], f"{anchor['name']} 다음으로"
await _save_sections(ctx, theme, moved)
return (f"{row['name']} 을(를) {where} 옮겼습니다. "
f"사이트에 반영하려면 다시 발행해야 해요 — 지금 할까요?")
# ── 반쯤 되돌릴 수 있는 것 ───────────────────────────────────────────────
async def _publish(ctx: ToolContext, args: dict) -> str:
@@ -168,6 +266,26 @@ REGISTRY: dict[str, Tool] = {
args={"key": "아래 항목 목록의 key", "value": "바꿀 값"},
run=_set_fact,
),
Tool(
name="list_sections",
grade=ToolGrade.READ,
summary="홈페이지가 어떤 부분들로 어떤 순서로 되어 있는지 보여준다.",
run=_list_sections,
),
Tool(
name="toggle_section",
grade=ToolGrade.REVERSIBLE,
summary="홈페이지의 한 부분을 켜거나 끈다(예: 후기, 사진 갤러리, 예약 안내).",
args={"name": "그 부분의 이름", "enabled": "켜면 true, 끄면 false"},
run=_toggle_section,
),
Tool(
name="move_section",
grade=ToolGrade.REVERSIBLE,
summary="홈페이지에서 한 부분의 위치(순서)를 바꾼다.",
args={"name": "옮길 부분의 이름", "to": "'맨 위' · '맨 아래' · 또는 그 뒤에 올 부분의 이름"},
run=_move_section,
),
Tool(
name="publish",
grade=ToolGrade.SEMI,
@@ -179,6 +297,12 @@ REGISTRY: dict[str, Tool] = {
}
async def sections_of(ctx: ToolContext):
"""런타임이 프롬프트에 실을 섹션 목록. 도구가 쓰는 것과 같은 함수여야 한다 —
다르면 모델이 본 이름과 도구가 찾는 이름이 갈린다."""
return await _sections_of(ctx)
def describe() -> list[dict]:
"""프롬프트에 실을 도구 목록. ★ 등급은 싣지 않는다 — 모델이 알 필요도, 정할 이유도 없다."""
return [{"name": t.name, "설명": t.summary, "args": t.args} for t in REGISTRY.values()]