-
Notifications
You must be signed in to change notification settings - Fork 17
feat: 채널 기반 비즈니스 용어 사전 (Semantic Federation) 구현 #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thrcle
wants to merge
1
commit into
CausalInferenceLab:master
Choose a base branch
from
thrcle:feat/semantic-federation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| """term_wizard.py — /term_custom 등록 폼 (2단계 UI). | ||
|
|
||
| Step 1: Select — 전사(guild) / 채널·팀(channel) / 개인(member) 선택 | ||
| Step 2: Modal — 용어명·정의·동의어 입력 | ||
|
|
||
| 채널이 팀 경계 역할을 하므로 entity 직접 입력 불필요. | ||
| setup_wizard.py 패턴 동일: Select 선택 → Modal 응답. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| import discord | ||
| from discord import ui | ||
|
|
||
| from .session_router import to_identity | ||
|
|
||
| if TYPE_CHECKING: | ||
| from .commands import CommandHandlers | ||
|
|
||
|
|
||
| _LAYER_OPTIONS = [ | ||
| discord.SelectOption( | ||
| label="전사 (Guild) — 회사 공통 정의", | ||
| value="guild", | ||
| description="모든 채널에서 기본값으로 사용", | ||
| ), | ||
| discord.SelectOption( | ||
| label="채널 (팀) — 이 채널 전용 정의", | ||
| value="channel", | ||
| description="다른 채널과 충돌 없이 이 채널에서만 유효", | ||
| ), | ||
| discord.SelectOption( | ||
| label="개인 — 나만 사용하는 정의", | ||
| value="member", | ||
| description="전사·채널 정의를 조용히 덮어씀", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| class _TermModal(ui.Modal, title="비즈니스 용어 등록"): | ||
| term = ui.TextInput( | ||
| label="용어명", | ||
| placeholder="예: 활성고객", | ||
| required=True, | ||
| max_length=100, | ||
| ) | ||
| definition = ui.TextInput( | ||
| label="정의", | ||
| placeholder="예: 최근 30일 내 로그인한 users", | ||
| required=True, | ||
| style=discord.TextStyle.paragraph, | ||
| max_length=500, | ||
| ) | ||
| synonyms = ui.TextInput( | ||
| label="동의어 (쉼표 구분, 선택)", | ||
| placeholder="예: active user, 활성화고객", | ||
| required=False, | ||
| max_length=200, | ||
| ) | ||
|
|
||
| def __init__(self, layer: str, handlers: "CommandHandlers", ctx_factory) -> None: | ||
| super().__init__() | ||
| self._layer = layer | ||
| self._handlers = handlers | ||
| self._ctx_factory = ctx_factory | ||
|
|
||
| async def on_submit(self, interaction: discord.Interaction) -> None: | ||
| await interaction.response.defer(ephemeral=True, thinking=True) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 nit — |
||
| try: | ||
| identity = to_identity(self._ctx_factory(interaction)) | ||
| result = await self._handlers.term_custom( | ||
| identity, | ||
| term=self.term.value.strip(), | ||
| definition=self.definition.value.strip(), | ||
| layer=self._layer, | ||
| synonyms=self.synonyms.value.strip(), | ||
| ) | ||
| await interaction.followup.send(result.text, ephemeral=True) | ||
| except Exception as exc: | ||
| await interaction.followup.send(f"❌ 오류: {exc}", ephemeral=True) | ||
|
|
||
|
|
||
| class _LayerSelect(ui.Select): | ||
| def __init__(self, handlers: "CommandHandlers", ctx_factory) -> None: | ||
| super().__init__( | ||
| placeholder="적용 범위를 선택하세요…", | ||
| options=_LAYER_OPTIONS, | ||
| min_values=1, | ||
| max_values=1, | ||
| ) | ||
| self._handlers = handlers | ||
| self._ctx_factory = ctx_factory | ||
|
|
||
| async def callback(self, interaction: discord.Interaction) -> None: | ||
| await interaction.response.send_modal( | ||
| _TermModal(self.values[0], self._handlers, self._ctx_factory) | ||
| ) | ||
|
|
||
|
|
||
| class _LayerSelectView(ui.View): | ||
| def __init__(self, handlers: "CommandHandlers", ctx_factory) -> None: | ||
| super().__init__(timeout=120.0) | ||
| self.add_item(_LayerSelect(handlers, ctx_factory)) | ||
|
|
||
|
|
||
| async def start_term_add_flow( | ||
| interaction: discord.Interaction, | ||
| handlers: "CommandHandlers", | ||
| ctx_factory, | ||
| ) -> None: | ||
| """bot.py의 /term_custom 커맨드에서 호출 — 범위 선택 → 용어 등록 모달.""" | ||
| await interaction.response.send_message( | ||
| "용어를 등록할 **범위**를 선택하세요.\n" | ||
| "- **전사**: 모든 채널에서 기본값\n" | ||
| "- **채널(팀)**: 이 채널에서만 유효 (다른 채널과 충돌 없음)\n" | ||
| "- **개인**: 나만 사용하는 정의 (전사·채널 정의를 덮어씀)", | ||
| view=_LayerSelectView(handlers, ctx_factory), | ||
| ephemeral=True, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 nit —
/term_custom remove에 layer 인자가 없어서 기본값 member만 삭제되는 것 같아요. wizard로 guild/channel 용어를 만들 수 있는데 슬래시로는 그 레이어를 못 지우는 비대칭이 있습니다.