creating new file for thread context

This commit is contained in:
dullfig 2026-01-02 00:01:20 -08:00
parent 8c4ee6f20f
commit df7d02b5c8
7 changed files with 38 additions and 3 deletions

View file

View file

@ -1,4 +1,4 @@
# agentserver/message_bus.py # agentserver/bus.py
# Refactored January 01, 2026 MessageBus with run() pump and out-of-band shutdown # Refactored January 01, 2026 MessageBus with run() pump and out-of-band shutdown
import asyncio import asyncio
@ -7,8 +7,8 @@ from typing import AsyncIterator, Callable, Dict, Optional, Awaitable
from lxml import etree from lxml import etree
from .xml_listener import XMLListener from agentserver.xml_listener import XMLListener
from .utils.message import repair_and_canonicalize, XmlTamperError from agentserver.utils.message import repair_and_canonicalize, XmlTamperError
# Constants for Internal Physics # Constants for Internal Physics
ENV_NS = "https://xml-pipeline.org/ns/envelope/1" ENV_NS = "https://xml-pipeline.org/ns/envelope/1"

View file

View file

View file

View file

View file

@ -0,0 +1,35 @@
# message_bus/thread.py
from __future__ import annotations
from typing import Optional
from lxml import etree
import uuid
class Thread:
"""
Internal thread context used by MessageBus.
Not part of the public API do not import or instantiate directly.
Exists in its own module only to keep MessageBus readable.
"""
def __init__(
self,
parent: Optional['Thread'] = None,
thread_id: Optional[str] = None,
metadata: Optional[dict] = None,
):
self.id = thread_id or str(uuid.uuid4())
self.parent = parent
self.depth = parent.depth + 1 if parent else 0
self.buffer = bytearray()
# noinspection PyTypeChecker
self.parser = etree.XMLPullParser(events=("end",))
self.active = True
self.metadata = metadata or (parent.metadata.copy() if parent else {})
# Optional: add __repr__ for debugging
def __repr__(self) -> str:
return f"<Thread {self.id[:8]} depth={self.depth} buf={len(self.buffer)}>"