agents-over-telegram 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +141 -0
- package/docs/BOT_EXCHANGES.md +121 -0
- package/docs/COMPATIBILITY.md +110 -0
- package/docs/DIRECT_DISPATCH.md +155 -0
- package/docs/HOSTS.md +244 -0
- package/docs/IMPLEMENTATION_STATUS.md +205 -0
- package/docs/LIVE_VALIDATION.md +35 -0
- package/docs/MACOS_SERVICE.md +89 -0
- package/docs/OPERATIONS.md +568 -0
- package/docs/REACTIONS.md +51 -0
- package/docs/RELAY.md +115 -0
- package/docs/RELEASING.md +45 -0
- package/docs/schemas/mcp.schema.json +120 -0
- package/docs/schemas/sources.json +9 -0
- package/integrations/pi/agents-over-telegram.ts +154 -0
- package/package.json +41 -0
- package/pyproject.toml +37 -0
- package/requirements/build.txt +18 -0
- package/requirements/runtime.txt +532 -0
- package/scripts/bootstrap_runtime.py +402 -0
- package/skills/telegram-coordinate/SKILL.md +67 -0
- package/skills/telegram-setup/SKILL.md +81 -0
- package/src/agents_over_telegram/__init__.py +2 -0
- package/src/agents_over_telegram/__main__.py +2 -0
- package/src/agents_over_telegram/appserver_client.py +400 -0
- package/src/agents_over_telegram/cli.py +851 -0
- package/src/agents_over_telegram/codex_trust.py +206 -0
- package/src/agents_over_telegram/compat.py +207 -0
- package/src/agents_over_telegram/core.py +4253 -0
- package/src/agents_over_telegram/credentials.py +108 -0
- package/src/agents_over_telegram/demo.py +85 -0
- package/src/agents_over_telegram/desktop_bridge.py +537 -0
- package/src/agents_over_telegram/desktop_dispatcher.py +680 -0
- package/src/agents_over_telegram/dispatcher.py +260 -0
- package/src/agents_over_telegram/host_config.py +125 -0
- package/src/agents_over_telegram/hosts.py +590 -0
- package/src/agents_over_telegram/judge.py +230 -0
- package/src/agents_over_telegram/macos_process.py +133 -0
- package/src/agents_over_telegram/markdown.py +127 -0
- package/src/agents_over_telegram/mcp_server.py +652 -0
- package/src/agents_over_telegram/net.py +130 -0
- package/src/agents_over_telegram/onboarding.py +719 -0
- package/src/agents_over_telegram/push.py +421 -0
- package/src/agents_over_telegram/relay.py +380 -0
- package/src/agents_over_telegram/relay_api.py +591 -0
- package/src/agents_over_telegram/relay_watch.py +171 -0
- package/src/agents_over_telegram/serve.py +626 -0
- package/src/agents_over_telegram/settings_panel.py +216 -0
- package/src/agents_over_telegram/transport.py +720 -0
- package/src/agents_over_telegram/webhook.py +219 -0
- package/uv.lock +1011 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""Bounded local event waiting; the owning Codex chat performs host handoff.
|
|
2
|
+
|
|
3
|
+
This process never calls Codex or sends Telegram replies. A quiet watcher is not
|
|
4
|
+
an unsolicited host notification: its owner must still be waiting on its output.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import math
|
|
10
|
+
import os
|
|
11
|
+
import queue
|
|
12
|
+
import re
|
|
13
|
+
import selectors
|
|
14
|
+
import signal
|
|
15
|
+
import sys
|
|
16
|
+
import termios
|
|
17
|
+
import threading
|
|
18
|
+
import time
|
|
19
|
+
|
|
20
|
+
from .core import CoreError
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _code(error):
|
|
24
|
+
code = str(getattr(error, 'code', 'relay_collection_failed'))
|
|
25
|
+
return code if re.fullmatch(r'[a-z0-9_]{1,64}', code) else 'relay_collection_failed'
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def watch(core, store, *, once=False, duration=55, interval=1.5, collect=False,
|
|
29
|
+
input_stream=None, output_stream=None):
|
|
30
|
+
"""Wait for metadata-only events, without claiming inbox processing leases.
|
|
31
|
+
|
|
32
|
+
--once is intended for bounded shell tools: completion returns promptly on
|
|
33
|
+
an event. Persistent mode accepts JSONL receipts on attached stdin. The
|
|
34
|
+
duration is always bounded because a shell child cannot observe chat end.
|
|
35
|
+
"""
|
|
36
|
+
if (type(once) is not bool or type(collect) is not bool
|
|
37
|
+
or isinstance(duration, bool) or not isinstance(duration, (int, float))
|
|
38
|
+
or not math.isfinite(duration) or not 0 < duration <= 3600
|
|
39
|
+
or isinstance(interval, bool) or not isinstance(interval, (int, float))
|
|
40
|
+
or not math.isfinite(interval) or not .1 <= interval <= 60):
|
|
41
|
+
raise CoreError('invalid_relay_watch_options')
|
|
42
|
+
input_stream = sys.stdin if input_stream is None else input_stream
|
|
43
|
+
output_stream = sys.stdout if output_stream is None else output_stream
|
|
44
|
+
stop = threading.Event()
|
|
45
|
+
errors = queue.Queue(maxsize=1)
|
|
46
|
+
deadline = time.monotonic() + duration
|
|
47
|
+
worker = None
|
|
48
|
+
selector = None
|
|
49
|
+
terminal = None
|
|
50
|
+
old_handlers = {}
|
|
51
|
+
reason = 'timeout'
|
|
52
|
+
emitted_once = False
|
|
53
|
+
|
|
54
|
+
def emit(value):
|
|
55
|
+
output_stream.write(json.dumps(value, separators=(',', ':'), ensure_ascii=True) + '\n')
|
|
56
|
+
output_stream.flush()
|
|
57
|
+
|
|
58
|
+
def collect_loop():
|
|
59
|
+
backoff = interval
|
|
60
|
+
last_error = None
|
|
61
|
+
while not stop.is_set():
|
|
62
|
+
try:
|
|
63
|
+
core.collect(timeout=10, judge=True)
|
|
64
|
+
backoff, last_error = interval, None
|
|
65
|
+
except Exception as error:
|
|
66
|
+
code = _code(error)
|
|
67
|
+
if code != last_error:
|
|
68
|
+
try:
|
|
69
|
+
errors.put_nowait(code)
|
|
70
|
+
except queue.Full:
|
|
71
|
+
pass
|
|
72
|
+
last_error = code
|
|
73
|
+
backoff = min(60, max(interval, backoff * 2))
|
|
74
|
+
stop.wait(backoff)
|
|
75
|
+
|
|
76
|
+
def signal_stop(signum, frame):
|
|
77
|
+
stop.set()
|
|
78
|
+
|
|
79
|
+
with core._lock('relay-watcher') as acquired:
|
|
80
|
+
if not acquired:
|
|
81
|
+
raise CoreError('relay_watcher_busy')
|
|
82
|
+
try:
|
|
83
|
+
if not once:
|
|
84
|
+
# select() also handles closed/default stdin and regular files;
|
|
85
|
+
# Linux epoll refuses those before we can observe EOF.
|
|
86
|
+
selector = selectors.SelectSelector()
|
|
87
|
+
fd = input_stream.fileno()
|
|
88
|
+
selector.register(fd, selectors.EVENT_READ)
|
|
89
|
+
if os.isatty(fd):
|
|
90
|
+
terminal = (fd, termios.tcgetattr(fd))
|
|
91
|
+
settings = termios.tcgetattr(fd)
|
|
92
|
+
settings[3] &= ~termios.ECHO
|
|
93
|
+
termios.tcsetattr(fd, termios.TCSANOW, settings)
|
|
94
|
+
if threading.current_thread() is threading.main_thread():
|
|
95
|
+
for signum in (signal.SIGTERM, signal.SIGINT):
|
|
96
|
+
old_handlers[signum] = signal.signal(signum, signal_stop)
|
|
97
|
+
recovered = store.recover_inflight()
|
|
98
|
+
emit({'type': 'relay_ready', 'once': once, 'duration': duration,
|
|
99
|
+
'collect': collect, 'recovered': recovered})
|
|
100
|
+
buffer = b''
|
|
101
|
+
next_scan = 0.0
|
|
102
|
+
while not stop.is_set() and time.monotonic() < deadline:
|
|
103
|
+
# Read shutdown/receipts before emitting any more work.
|
|
104
|
+
if selector is not None:
|
|
105
|
+
for key, _ in selector.select(timeout=0):
|
|
106
|
+
data = os.read(key.fd, 4096)
|
|
107
|
+
if not data:
|
|
108
|
+
reason = 'stdin_closed'
|
|
109
|
+
stop.set()
|
|
110
|
+
break
|
|
111
|
+
buffer += data
|
|
112
|
+
if len(buffer) > 16384:
|
|
113
|
+
raise CoreError('invalid_relay_control')
|
|
114
|
+
while b'\n' in buffer:
|
|
115
|
+
line, buffer = buffer.split(b'\n', 1)
|
|
116
|
+
try:
|
|
117
|
+
command = json.loads(line)
|
|
118
|
+
if not isinstance(command, dict):
|
|
119
|
+
raise ValueError()
|
|
120
|
+
if command == {'command': 'stop'}:
|
|
121
|
+
reason = 'requested'
|
|
122
|
+
stop.set()
|
|
123
|
+
break
|
|
124
|
+
if (set(command) != {'command', 'notification_id', 'outcome'}
|
|
125
|
+
or command['command'] != 'resolve'):
|
|
126
|
+
raise ValueError()
|
|
127
|
+
receipt = store.resolve(command['notification_id'], command['outcome'])
|
|
128
|
+
emit({'type': 'relay_receipt', **receipt})
|
|
129
|
+
except (ValueError, TypeError, UnicodeError, CoreError) as error:
|
|
130
|
+
emit({'type': 'relay_error', 'error': _code(error) if isinstance(error, CoreError)
|
|
131
|
+
else 'invalid_relay_control'})
|
|
132
|
+
if stop.is_set():
|
|
133
|
+
break
|
|
134
|
+
if collect and worker is None:
|
|
135
|
+
worker = threading.Thread(target=collect_loop, name='aot-relay-collector', daemon=True)
|
|
136
|
+
worker.start()
|
|
137
|
+
try:
|
|
138
|
+
error = errors.get_nowait()
|
|
139
|
+
except queue.Empty:
|
|
140
|
+
pass
|
|
141
|
+
else:
|
|
142
|
+
emit({'type': 'relay_error', 'error': error})
|
|
143
|
+
now = time.monotonic()
|
|
144
|
+
if now >= next_scan:
|
|
145
|
+
event = store.next_event()
|
|
146
|
+
if event is not None:
|
|
147
|
+
emit(event)
|
|
148
|
+
if once:
|
|
149
|
+
emitted_once = True
|
|
150
|
+
reason = 'event'
|
|
151
|
+
break
|
|
152
|
+
next_scan = now + min(interval, .5)
|
|
153
|
+
stop.wait(min(.1, max(0, deadline - time.monotonic())))
|
|
154
|
+
if stop.is_set() and reason == 'timeout':
|
|
155
|
+
reason = 'signal'
|
|
156
|
+
finally:
|
|
157
|
+
stop.set()
|
|
158
|
+
# Network intake is a daemon thread with no sending operations. The
|
|
159
|
+
# CLI exits after this call; a pending read cannot keep it alive.
|
|
160
|
+
if worker is not None:
|
|
161
|
+
worker.join(timeout=.2)
|
|
162
|
+
if not emitted_once:
|
|
163
|
+
store.recover_inflight()
|
|
164
|
+
if selector is not None:
|
|
165
|
+
selector.close()
|
|
166
|
+
if terminal is not None:
|
|
167
|
+
termios.tcsetattr(terminal[0], termios.TCSANOW, terminal[1])
|
|
168
|
+
for signum, handler in old_handlers.items():
|
|
169
|
+
signal.signal(signum, handler)
|
|
170
|
+
emit({'type': 'relay_stopped', 'reason': reason})
|
|
171
|
+
|