Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

2.0 KB
Raw Blame
from __future__ import annotations

from typing import Literal, cast


DeliveryIntent = Literal["replace", "steer", "queue"]
DeliveryPriority = Literal["p0", "p1", "p3"]

_PRIORITY_BY_INTENT: dict[DeliveryIntent, DeliveryPriority] = {
    "replace": "p0",
    "steer": "p1",
    "queue": "p3",
}
_INTENT_BY_PRIORITY: dict[DeliveryPriority, DeliveryIntent] = {
    priority: intent for intent, priority in _PRIORITY_BY_INTENT.items()
}
_INTENT_BY_TRIGGER: dict[str, DeliveryIntent] = {
    "im": "steer",
    "scheduled": "queue",
    "task_run": "queue",
    "watch": "steer",
    "hook": "steer",
    "webhook": "steer",
    "agent_run": "steer",
    "show_annotation": "steer",
    "callback": "steer",
}

_LEGACY_INTENT_ALIASES = {
    # Agent Run once used this as a separate "queue then promote" policy.
    # A content-bearing send-now is P1 steering; only content-free P1 promotes
    # an existing queue head.
    "send_now": "steer",
}


def normalize_delivery_intent(intent: str) -> DeliveryIntent:
    normalized = str(intent or "").strip().lower()
    normalized = _LEGACY_INTENT_ALIASES.get(normalized, normalized)
    if normalized not in _PRIORITY_BY_INTENT:
        raise ValueError(f"unsupported delivery intent: {intent}")
    return cast(DeliveryIntent, normalized)


def priority_for_delivery_intent(intent: str) -> DeliveryPriority:
    return _PRIORITY_BY_INTENT[normalize_delivery_intent(intent)]


def delivery_intent_for_priority(priority: str) -> DeliveryIntent:
    normalized = cast(DeliveryPriority, str(priority or "").strip())
    try:
        return _INTENT_BY_PRIORITY[normalized]
    except KeyError as exc:
        raise ValueError(f"unsupported delivery priority: {priority}") from exc


def delivery_intent_for_trigger(trigger_kind: str) -> DeliveryIntent:
    """Map a producer class to its one public delivery policy."""

    normalized = str(trigger_kind or "").strip()
    try:
        return _INTENT_BY_TRIGGER[normalized]
    except KeyError as exc:
        raise ValueError(f"unsupported delivery trigger: {trigger_kind}") from exc