bridges: standalone third-party API bridges; isolate the command gateway
Split messaging UX (invite links, read, send) out of the command gateway into a
new `semif_agent.bridges` layer. Each bridge is its own process (`cli bridge`)
against its own service daemon/profile; the SimpleX bridge owns a second
simplex-chat daemon and buffers every inbound DM, so a message sent to the
connect-link address shows up in `simplex.next_message`.
- new: bridges/{base,inbox,registry,simplex}.py + neutral semif_agent/simplex_ws.py
- gateway: delete bridge.py; drop address/observer/pull-mode from the command path
- codegen: inject the bridge catalog (describe_bridges) into body + elicitation prompts
- seeds: repoint simplex.next_message/connect_link to top-level `simplex_bridge_url`
- config/bootstrap: new top-level `bridges` block + `simplex_bridge_url`; render
semif-simplex-forward + semif-bridge units; gateway config loses bridge/inbox
- docs: AGENTS.md gateway isolation is non-negotiable
This commit is contained in:
1 parent
d46fbdca19
commit
ddc5cb66c8
31 files changed
+1702
-1088
No files matched your search
@@ -0,0 +1,63 @@
|
||||
"""A bounded, thread-safe FIFO of buffered inbound messages + known contacts.
|
||||
|
||||
The bridge owns the read cursor so a read skill stays stateless. Generic over
|
||||
transports: entries are normalized message dicts (`contact_id`, `display_name`,
|
||||
`text`), which is exactly what `semif_agent.simplex_ws` yields.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import threading
|
||||
import time
|
||||
import uuid
|
||||
from collections import deque
|
||||
|
||||
|
||||
class MessagingInbox:
|
||||
def __init__(self, max_size: int = 100):
|
||||
self._lock = threading.Lock()
|
||||
self._items: deque[dict] = deque()
|
||||
self._max = max(1, int(max_size))
|
||||
self._contacts: dict[str, str] = {}
|
||||
|
||||
def record(self, message: dict) -> dict:
|
||||
contact_id = str(message.get("contact_id") or "")
|
||||
display_name = message.get("display_name") or ""
|
||||
entry = {
|
||||
"id": uuid.uuid4().hex[:12],
|
||||
"contact_id": contact_id,
|
||||
"display_name": display_name,
|
||||
"text": message.get("text") or "",
|
||||
"received_at": time.time(),
|
||||
}
|
||||
with self._lock:
|
||||
if display_name:
|
||||
self._contacts[contact_id] = display_name
|
||||
else:
|
||||
self._contacts.setdefault(contact_id, "")
|
||||
self._items.append(entry)
|
||||
while len(self._items) > self._max:
|
||||
self._items.popleft()
|
||||
return entry
|
||||
|
||||
def peek(self) -> list[dict]:
|
||||
with self._lock:
|
||||
return list(self._items)
|
||||
|
||||
def pop(self, contact_id: str | None = None) -> dict | None:
|
||||
with self._lock:
|
||||
if contact_id is None:
|
||||
return self._items.popleft() if self._items else None
|
||||
target = str(contact_id)
|
||||
for index, entry in enumerate(self._items):
|
||||
if entry["contact_id"] == target:
|
||||
del self._items[index]
|
||||
return entry
|
||||
return None
|
||||
|
||||
def contacts(self) -> list[dict]:
|
||||
with self._lock:
|
||||
return [
|
||||
{"id": contact_id, "display_name": name}
|
||||
for contact_id, name in self._contacts.items()
|
||||
]
|
||||
Reference in new issue
Block a user