feat(01-03): Channel Gateway (Slack adapter) and Message Router

- gateway/normalize.py: normalize_slack_event -> KonstructMessage (strips bot mention)
- gateway/channels/slack.py: register_slack_handlers for app_mention + DM events
  - rate limit check -> ephemeral rejection on exceeded
  - idempotency dedup (Slack retry protection)
  - placeholder 'Thinking...' message posted in-thread before Celery dispatch
  - auto-follow engaged threads with 30-minute TTL
  - HTTP 200 returned immediately; all LLM work dispatched to Celery
- gateway/main.py: FastAPI on port 8001, /slack/events + /health
- router/tenant.py: resolve_tenant workspace_id -> tenant_id (RLS-bypass query)
- router/ratelimit.py: check_rate_limit Redis token bucket, RateLimitExceeded exception
- router/idempotency.py: is_duplicate + mark_processed (SET NX, 24h TTL)
- router/context.py: load_agent_for_tenant with RLS ContextVar setup
- orchestrator/tasks.py: handle_message now extracts placeholder_ts/channel_id,
  calls _update_slack_placeholder via chat.update after LLM response
- docker-compose.yml: gateway service on port 8001
- pyproject.toml: added redis, konstruct-router, konstruct-orchestrator deps
This commit is contained in:
2026-03-23 10:27:59 -06:00
parent dcd89cc8fd
commit 6f30705e1a
17 changed files with 1166 additions and 10 deletions

8
uv.lock generated
View File

@@ -1167,8 +1167,11 @@ source = { editable = "packages/gateway" }
dependencies = [
{ name = "fastapi", extra = ["standard"] },
{ name = "httpx" },
{ name = "konstruct-orchestrator" },
{ name = "konstruct-router" },
{ name = "konstruct-shared" },
{ name = "python-telegram-bot" },
{ name = "redis" },
{ name = "slack-bolt" },
]
@@ -1176,8 +1179,11 @@ dependencies = [
requires-dist = [
{ name = "fastapi", extras = ["standard"], specifier = ">=0.115.0" },
{ name = "httpx", specifier = ">=0.28.0" },
{ name = "konstruct-orchestrator", editable = "packages/orchestrator" },
{ name = "konstruct-router", editable = "packages/router" },
{ name = "konstruct-shared", editable = "packages/shared" },
{ name = "python-telegram-bot", specifier = ">=21.0" },
{ name = "redis", specifier = ">=5.0.0" },
{ name = "slack-bolt", specifier = ">=1.22.0" },
]
@@ -1227,6 +1233,7 @@ dependencies = [
{ name = "fastapi", extra = ["standard"] },
{ name = "httpx" },
{ name = "konstruct-shared" },
{ name = "redis" },
]
[package.metadata]
@@ -1234,6 +1241,7 @@ requires-dist = [
{ name = "fastapi", extras = ["standard"], specifier = ">=0.115.0" },
{ name = "httpx", specifier = ">=0.28.0" },
{ name = "konstruct-shared", editable = "packages/shared" },
{ name = "redis", specifier = ">=5.0.0" },
]
[[package]]