Generic hooks the plugin builds on: the conversations.drawer, composer.send and app.modal slot places (openModal / modal.setResult / modal.close, ?modal= links), runs.start taking the composer's whole payload (auto routing, account, projects, cwd, meta.scheduled) and hub/runs/resolve, a turn's knobs on conversations.send, push buttons answered as the notify.action event, hub/changed (SSE plugin-data), hub/title (conversations.title), the runs.schedule provider behind /api/scheduled, the week's budget and the stopped-run card, providers in /api/plugins/ui, carryover.scheduled. backend/scheduled/ and frontend/src/business/scheduled/ are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
3.4 KiB
Python
89 lines
3.4 KiB
Python
"""The host's side of a conversation-labels plugin: ``provides`` keys the core
|
|
asks, as the owner, instead of calling Haiku itself (since 2026-11-26 — the
|
|
sidecar's ``/title`` and ``/look`` and the core's ``look_labeler.py`` thread
|
|
are gone).
|
|
|
|
* ``conversation.title`` — ``{text, kind, ref, account?, isolated?}`` →
|
|
``{title, summary?}``: a scheduled prompt's title (the scheduled-conversations
|
|
plugin, through ``hub/title`` — ``plugins/proxyroutes.py``)
|
|
and a long conversation title's short header stand-in
|
|
(``conversations/short_title.py``). No provider, a failure or an empty
|
|
answer → ``None``, and each caller falls back (the prompt's first words; no
|
|
short title).
|
|
* ``conversation.look`` — ``{sessionId?}`` → ``{labelled}``: label one
|
|
conversation (or whatever is pending) now. Optional; the plugin also
|
|
labels on ``conversation.started`` and on its own schedule.
|
|
|
|
The plugin books its spend itself through the ``complete.run`` bridge
|
|
(``plugins/hubcomplete.py``).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from plugins.store import OWNER_UID
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
TITLE = "conversation.title"
|
|
LOOK = "conversation.look"
|
|
|
|
|
|
def _provider(deps, key: str) -> tuple[dict[str, Any], dict[str, Any]] | None:
|
|
"""The owner's active plugin providing ``key`` → (rec, its action spec)."""
|
|
from plugins.waiting import _providers_for
|
|
try:
|
|
found = _providers_for(deps, OWNER_UID, key)
|
|
except Exception: # noqa: BLE001 — no plugin store (tests, early boot)
|
|
return None
|
|
for rec, _grant in found:
|
|
mf = rec.get("manifest") or {}
|
|
act = (mf.get("actions") or {}).get((mf.get("provides") or {}).get(key))
|
|
if act:
|
|
return rec, act
|
|
return None
|
|
|
|
|
|
def available(deps, key: str = TITLE) -> bool:
|
|
return _provider(deps, key) is not None
|
|
|
|
|
|
def run(deps, key: str, payload: dict[str, Any]) -> dict[str, Any] | None:
|
|
"""The provider's answer, or None (no provider, or it failed)."""
|
|
hit = _provider(deps, key)
|
|
if hit is None:
|
|
return None
|
|
rec, act = hit
|
|
from plugins.runner import run_script
|
|
try:
|
|
res = run_script(deps, deps.plugin_store, OWNER_UID, rec, act["script"],
|
|
payload=payload, timeout_sec=int(act.get("timeoutSec") or 60))
|
|
except Exception as e: # noqa: BLE001 — a broken plugin never breaks the hub
|
|
log.warning("%s via %s failed: %s", key, rec.get("id"), getattr(e, "message", e))
|
|
return None
|
|
if not isinstance(res, dict) or res.get("_error"):
|
|
return None
|
|
return res
|
|
|
|
|
|
def title(deps, text: str, kind: str, ref: str | None = None,
|
|
account: str | None = None) -> dict | None:
|
|
"""``{title, summary}`` from the provider, or None."""
|
|
import accounts as accounts_mod
|
|
payload = {"text": text[:6000], "kind": kind, "ref": ref}
|
|
if account:
|
|
payload.update(account=account, isolated=account != accounts_mod.DEFAULT)
|
|
res = run(deps, TITLE, payload)
|
|
t = str((res or {}).get("title") or "").strip().strip('"').strip()
|
|
if not t:
|
|
return None
|
|
return {"title": t[:120],
|
|
"summary": str(res.get("summary") or "").strip()[:300] or None}
|
|
|
|
|
|
def look(deps, session_id: str | None = None) -> bool:
|
|
"""Ask the provider to label (``session_id`` or what's pending)."""
|
|
return run(deps, LOOK, {"sessionId": session_id} if session_id else {}) is not None
|