simbiot-harness/venv/lib/python3.12/site-packages/sse_starlette/_utils.py
Simbiot Harness b60439152b Simbiot Harness v0.1: тактовая лестница на Strands + CQRS/ES-спина
- harness/es.py: append-only event store + проекции (образец — кооп-портал)
- harness/levels.py: уровни 1с/1м/1ч/1д, контекст ∝ масштабу
- harness/scheduler.py: уровневые потоки, идемпотентные тики, absorbed-стабы
- harness/isolated_runner.py + _llm_worker.py: LLM-тик в сабпроцессе
  (глобальный asyncio-рантайм Strands не переживает 2+ create_harness)
- cli.py: init/task/tasks/status/events + requeue (написан самим минутным агентом)
- 9router: отдельный ключ sk-simbiot, модель auto (glm-5.3 первым)
2026-09-29 15:28:50 +00:00

37 lines
1.4 KiB
Python

import sys
from contextlib import contextmanager
from typing import Generator
# Divergence #3 (see sse_starlette/sse.py module docstring): vendored copy of
# starlette._utils.collapse_excgroups. We do not import the upstream version
# because it lives in a private (underscore-prefixed) Starlette module, and
# the pinned floor (starlette>=0.41.3) makes that import surface unstable.
#
# Behaviour: AnyIO v4 wraps task-group failures in an ExceptionGroup; this
# helper unwraps single-exception groups so user middleware sees the bare
# exception (matching pre-v4 anyio and Starlette's StreamingResponse).
# Solution per https://anyio.readthedocs.io/en/stable/migration.html
has_exceptiongroups = True
if sys.version_info < (3, 11):
try:
from exceptiongroup import BaseExceptionGroup # noqa: F401
except ImportError:
has_exceptiongroups = False
@contextmanager
def collapse_excgroups() -> Generator[None, None, None]:
try:
yield
except BaseException as exc:
if has_exceptiongroups:
# `ty` does not narrow BaseExceptionGroup.exceptions; the runtime
# contract is identical to starlette._utils.collapse_excgroups.
while isinstance(exc, BaseExceptionGroup) and len(exc.exceptions) == 1: # ty: ignore[unresolved-attribute]
exc = exc.exceptions[0] # ty: ignore[unresolved-attribute]
raise exc
__all__ = ["collapse_excgroups"]