mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-08-24 07:45:42 +00:00
Add per-scope availability, duplication, active-profile status, and inline project selection while keeping the profile switcher synchronized with runtime state. Reconcile unavailable profiles at explicit disable, deletion, project-transition, and context-creation boundaries; polish validation, prompt layout, deletion, and completion states; and extend focused backend and WebUI coverage.
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
"""Shared context helper used by both ApiHandler and WsHandler."""
|
|
|
|
import threading
|
|
from typing import Union
|
|
|
|
ThreadLockType = Union[threading.Lock, threading.RLock]
|
|
|
|
|
|
def use_context(lock: ThreadLockType, ctxid: str, create_if_not_exists: bool = True):
|
|
from agent import AgentContext
|
|
from helpers import projects
|
|
from initialize import initialize_agent
|
|
|
|
with lock:
|
|
if not ctxid:
|
|
first = AgentContext.first()
|
|
if first:
|
|
AgentContext.use(first.id)
|
|
return first
|
|
context = AgentContext(config=initialize_agent(), set_current=True)
|
|
projects.reconcile_agent_profile(
|
|
context, projects.get_context_project_name(context)
|
|
)
|
|
return context
|
|
got = AgentContext.use(ctxid)
|
|
if got:
|
|
return got
|
|
if create_if_not_exists:
|
|
context = AgentContext(
|
|
config=initialize_agent(), id=ctxid, set_current=True
|
|
)
|
|
projects.reconcile_agent_profile(
|
|
context, projects.get_context_project_name(context)
|
|
)
|
|
return context
|
|
raise Exception(f"Context {ctxid} not found")
|