forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_first_eligibility.py
More file actions
54 lines (43 loc) · 1.97 KB
/
Copy pathchat_first_eligibility.py
File metadata and controls
54 lines (43 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Fail-closed, reusable server authority for universal Chat-first access."""
from dataclasses import dataclass
from typing import Callable
import database.task_intelligence_control as task_control_db
from models.task_intelligence import TaskIntelligenceRolloutDecision, TaskWorkflowControl
from utils.observability.fallback import record_fallback
from utils.task_intelligence.rollout import resolve_chat_first_ui, resolve_task_intelligence_for_user
@dataclass(frozen=True)
class ChatFirstEligibility:
"""Fresh server-side capability resolution for one authenticated account."""
enabled: bool
account_generation: int | None = None
def resolve_chat_first_eligibility(
uid: str,
*,
load_control: Callable[[str], TaskWorkflowControl] = task_control_db.get_task_workflow_control,
resolve_rollout: Callable[..., TaskIntelligenceRolloutDecision] = resolve_task_intelligence_for_user,
) -> ChatFirstEligibility:
"""Resolve the generation-bound universal capability without fallback state.
This is intentionally the only reusable server authority for chat-first
ingress. Callers must invoke it before touching feature-specific stores,
metrics, or providers. Any task-control failure fails closed.
"""
try:
control = load_control(uid)
rollout = resolve_rollout(
uid=uid,
workflow_mode=control.workflow_mode,
account_generation=control.account_generation,
)
if not resolve_chat_first_ui(rollout):
return ChatFirstEligibility(enabled=False)
return ChatFirstEligibility(enabled=True, account_generation=control.account_generation)
except Exception:
record_fallback(
component='other',
from_mode='chat_first',
to_mode='capability_unavailable',
reason='other',
outcome='exhausted',
)
return ChatFirstEligibility(enabled=False)
__all__ = ['ChatFirstEligibility', 'resolve_chat_first_eligibility']