- screenView tool (screen_view.spec.md): whole screen, monitor by number, window by part of its title or program, or the list of monitors and windows; fast, normal or detailed pictures. - The app captures with Windows Graphics Capture (app/src/screen.rs, admin.spec.md "Screen viewing"), decides for the asker (only people registered for PC control), never picks, lists or shows excluded programs (pcControl.screenExclude, password managers by default), refuses minimised windows and black pictures, and records screen.view in the activity log. - Pictures ride on the tool message (ToolExecutionResult.images); llm.py sends them to OpenAI-compatible servers as image parts after the tool messages. They stay in that reply only: not in the tool carryover, logs or prompt dumps. - The LLM reads pictures only when screen viewing is available (--vision gpu normally, cpu in a game), measured apart for the placement; otherwise screenView is a disabled tool. - Worker: screen_action / screen_action_result, 4 MiB messages. - Eval evals/test_screen_view_tool.py; Windows check tests/screen_windows.rs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
110 lines
3.2 KiB
Python
110 lines
3.2 KiB
Python
"""Per-turn, request-scoped state shared between the bridge, the reply engine
|
|
and tools — without threading extra parameters through the whole engine call
|
|
chain (run_reply_engine -> run_tool_with_retries -> execute_tool -> execute).
|
|
|
|
Flask serves each HTTP request on its own thread and the reply engine + tools
|
|
run synchronously on that thread, so a ``threading.local`` cleanly scopes a
|
|
single turn. Anything that can't see the thread-local (a worker thread, an eval,
|
|
a unit test) just reads ``None`` and the caller falls back to its default.
|
|
|
|
Fields
|
|
------
|
|
broadcasting : Optional[bool]
|
|
The live screen-share (Go-Live) state the bot sends with the request. The
|
|
webSearch routing reads it to pick on-screen Chrome (live) vs Gemini (off).
|
|
broadcast_action : Optional[str]
|
|
A directive ("start"/"stop") recorded by the setBroadcast tool for the
|
|
bridge to return to the bot, which owns the actual broadcast.
|
|
user : Optional[str]
|
|
v2: the Discord user ID of the person asking, set by the voice worker's
|
|
brain. Tools that keep personal data (meals) store and read it under this
|
|
person. None is v1's single user.
|
|
chat : Optional[object]
|
|
v2: the chat channel backend for this turn (chat_channels.spec.md). None
|
|
means the chatChannels tool is not offered.
|
|
schedule : Optional[object]
|
|
v2: the asker's reminders and scheduled tasks for this turn (schedule.spec.md). None means the
|
|
schedule tool is not offered (v1, evals, and scheduled tasks themselves).
|
|
notes : Optional[object]
|
|
v2: the asker's standing instructions backend (personal_notes.spec.md). None means the
|
|
personalNotes tool is not offered.
|
|
screen : Optional[object]
|
|
v2: the app's screen backend for the asker (screen_view.spec.md). None means the screenView
|
|
tool is not offered.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import threading
|
|
from typing import Optional
|
|
|
|
_state = threading.local()
|
|
|
|
|
|
def reset() -> None:
|
|
"""Clear per-turn state. Call at the start of each request."""
|
|
_state.broadcasting = None
|
|
_state.broadcast_action = None
|
|
_state.user = None
|
|
_state.chat = None
|
|
_state.schedule = None
|
|
_state.notes = None
|
|
_state.screen = None
|
|
|
|
|
|
def set_screen(backend) -> None:
|
|
_state.screen = backend
|
|
|
|
|
|
def get_screen():
|
|
return getattr(_state, "screen", None)
|
|
|
|
|
|
def set_notes(backend) -> None:
|
|
_state.notes = backend
|
|
|
|
|
|
def get_notes():
|
|
return getattr(_state, "notes", None)
|
|
|
|
|
|
def set_schedule(backend) -> None:
|
|
_state.schedule = backend
|
|
|
|
|
|
def get_schedule():
|
|
return getattr(_state, "schedule", None)
|
|
|
|
|
|
def set_chat(backend) -> None:
|
|
_state.chat = backend
|
|
|
|
|
|
def get_chat():
|
|
return getattr(_state, "chat", None)
|
|
|
|
|
|
def set_user(user_id: Optional[str]) -> None:
|
|
_state.user = user_id
|
|
|
|
|
|
def get_user() -> Optional[str]:
|
|
return getattr(_state, "user", None)
|
|
|
|
|
|
def set_broadcasting(value: Optional[bool]) -> None:
|
|
_state.broadcasting = value
|
|
|
|
|
|
def get_broadcasting() -> Optional[bool]:
|
|
return getattr(_state, "broadcasting", None)
|
|
|
|
|
|
def request_broadcast(action: str) -> None:
|
|
"""Record a broadcast directive. ``action`` is "start" or "stop"."""
|
|
_state.broadcast_action = action
|
|
|
|
|
|
def get_broadcast_action() -> Optional[str]:
|
|
return getattr(_state, "broadcast_action", None)
|