OSS restructuring for open-core model: - Rename package from agentserver/ to xml_pipeline/ - Update all imports (44 Python files, 31 docs/configs) - Update pyproject.toml for OSS distribution (v0.3.0) - Move prompt_toolkit from core to optional [console] extra - Remove auth/server/lsp from core optional deps (-> Nextra) New console example in examples/console/: - Self-contained demo with handlers and config - Uses prompt_toolkit (optional, falls back to input()) - No password auth, no TUI, no LSP — just the basics - Shows how to use xml-pipeline as a library Import changes: - from agentserver.* -> from xml_pipeline.* - CLI entry points updated: xml_pipeline.cli:main Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
35 lines
No EOL
1 KiB
Python
35 lines
No EOL
1 KiB
Python
# 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)}>" |