The hub's own small model calls (action badges, short header titles, Send-later titles) leave the core for a plugin, on any model: - sidecar POST /complete (host only): one short answer, no transcript — a harness driver's optional complete() (claude / agy / opencode / pi), or the EVOX2 / OpenRouter over HTTP; wakeLocal:false never wakes the box or loads a model (asleep → fallback at once); fallback model/harness/account; usage returned in Anthropic's shape. - complete.run bridge (hub/complete): calls /complete, books the spend in the side-call ledger. conversations.label bridge: hub/labels/pending (look_pending.py), hub/labels/look (meta.lookAuto), hub/labels/short-title. - provides conversation.title (scheduled/title.py, short_title.py — no plugin: first words / no short title) and conversation.look. - removed: sidecar/title.py, sidecar/look.py, conversations/look_labeler.py and its thread; /api/look/pending rebuilt on look_pending. - docs/plugins.md, CLAUDE.md, sidecar README updated; tests: test_hubcomplete, test_complete, test_look, test_short_title. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
3.3 KiB
Python
88 lines
3.3 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 (``scheduled/title.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
|